1
0
mirror of https://github.com/bitwarden/browser synced 2026-02-05 11:13:44 +00:00

Remove node-fetch

This commit is contained in:
Daniel García
2025-08-18 19:00:02 +02:00
parent f2d2d0a767
commit faa5e1f199
7 changed files with 4 additions and 119 deletions

View File

@@ -375,7 +375,6 @@
"@types/koa-bodyparser",
"@types/koa-json",
"@types/lunr",
"@types/node-fetch",
"@types/proper-lockfile",
"@types/retry",
"chalk",
@@ -388,7 +387,6 @@
"koa-json",
"lunr",
"multer",
"node-fetch",
"open",
"proper-lockfile",
"qrcode-parser",

View File

@@ -81,7 +81,6 @@
"lowdb": "1.0.0",
"lunr": "2.3.9",
"multer": "1.4.5-lts.2",
"node-fetch": "2.6.12",
"node-forge": "1.3.1",
"open": "10.1.2",
"papaparse": "5.5.3",

View File

@@ -1,54 +0,0 @@
// FIXME: Update this file to be type safe and remove this and next line
// @ts-strict-ignore
import * as FormData from "form-data";
import { HttpsProxyAgent } from "https-proxy-agent";
import * as fe from "node-fetch";
import { TokenService } from "@bitwarden/common/auth/abstractions/token.service";
import { VaultTimeoutSettingsService } from "@bitwarden/common/key-management/vault-timeout";
import { AppIdService } from "@bitwarden/common/platform/abstractions/app-id.service";
import { EnvironmentService } from "@bitwarden/common/platform/abstractions/environment.service";
import { LogService } from "@bitwarden/common/platform/abstractions/log.service";
import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service";
import { ApiService } from "@bitwarden/common/services/api.service";
(global as any).fetch = fe.default;
(global as any).Request = fe.Request;
(global as any).Response = fe.Response;
(global as any).Headers = fe.Headers;
(global as any).FormData = FormData;
export class NodeApiService extends ApiService {
constructor(
tokenService: TokenService,
platformUtilsService: PlatformUtilsService,
environmentService: EnvironmentService,
appIdService: AppIdService,
refreshAccessTokenErrorCallback: () => Promise<void>,
logService: LogService,
logoutCallback: () => Promise<void>,
vaultTimeoutSettingsService: VaultTimeoutSettingsService,
customUserAgent: string = null,
) {
super(
tokenService,
platformUtilsService,
environmentService,
appIdService,
refreshAccessTokenErrorCallback,
logService,
logoutCallback,
vaultTimeoutSettingsService,
{ createRequest: (url, request) => new Request(url, request) },
customUserAgent,
);
}
nativeFetch(request: Request): Promise<Response> {
const proxy = process.env.http_proxy || process.env.https_proxy;
if (proxy) {
(request as any).agent = new HttpsProxyAgent(proxy);
}
return fetch(request);
}
}

View File

@@ -129,6 +129,7 @@ import { MemoryStorageService as MemoryStorageServiceForStateProviders } from "@
import { SyncService } from "@bitwarden/common/platform/sync";
// eslint-disable-next-line no-restricted-imports -- Needed for service construction
import { DefaultSyncService } from "@bitwarden/common/platform/sync/internal";
import { ApiService } from "@bitwarden/common/services/api.service";
import { AuditService } from "@bitwarden/common/services/audit.service";
import { EventCollectionService } from "@bitwarden/common/services/event/event-collection.service";
import { EventUploadService } from "@bitwarden/common/services/event/event-upload.service";
@@ -188,7 +189,6 @@ import { CliSdkLoadService } from "../platform/services/cli-sdk-load.service";
import { ConsoleLogService } from "../platform/services/console-log.service";
import { I18nService } from "../platform/services/i18n.service";
import { LowdbStorageService } from "../platform/services/lowdb-storage.service";
import { NodeApiService } from "../platform/services/node-api.service";
import { NodeEnvSecureStorageService } from "../platform/services/node-env-secure-storage.service";
import { CliRestrictedItemTypesService } from "../vault/services/cli-restricted-item-types.service";
@@ -216,7 +216,7 @@ export class ServiceContainer {
keyService: KeyService;
tokenService: TokenService;
appIdService: AppIdService;
apiService: NodeApiService;
apiService: ApiService;
environmentService: EnvironmentService;
cipherService: CipherService;
folderService: InternalFolderService;
@@ -494,7 +494,7 @@ export class ServiceContainer {
throw new Error("Refresh Access token error");
};
this.apiService = new NodeApiService(
this.apiService = new ApiService(
this.tokenService,
this.platformUtilsService,
this.environmentService,
@@ -503,6 +503,7 @@ export class ServiceContainer {
this.logService,
logoutCallback,
this.vaultTimeoutSettingsService,
{ createRequest: (url, request) => new Request(url, request) },
customUserAgent,
);

View File

@@ -32,10 +32,6 @@ const plugins = [
banner: "#!/usr/bin/env node",
raw: true,
}),
new webpack.IgnorePlugin({
resourceRegExp: /^encoding$/,
contextRegExp: /node-fetch/,
}),
new webpack.EnvironmentPlugin({
ENV: ENV,
BWCLI_ENV: ENV,

53
package-lock.json generated
View File

@@ -55,7 +55,6 @@
"lunr": "2.3.9",
"multer": "1.4.5-lts.2",
"ngx-toastr": "19.0.0",
"node-fetch": "2.6.12",
"node-forge": "1.3.1",
"oidc-client-ts": "2.4.1",
"open": "10.1.2",
@@ -110,7 +109,6 @@
"@types/lowdb": "1.0.15",
"@types/lunr": "2.3.7",
"@types/node": "22.15.3",
"@types/node-fetch": "2.6.4",
"@types/node-forge": "1.3.11",
"@types/papaparse": "5.3.16",
"@types/proper-lockfile": "4.1.4",
@@ -216,7 +214,6 @@
"lowdb": "1.0.0",
"lunr": "2.3.9",
"multer": "1.4.5-lts.2",
"node-fetch": "2.6.12",
"node-forge": "1.3.1",
"open": "10.1.2",
"papaparse": "5.5.3",
@@ -13809,56 +13806,6 @@
"undici-types": "~6.21.0"
}
},
"node_modules/@types/node-fetch": {
"version": "2.6.4",
"resolved": "https://registry.npmjs.org/@types/node-fetch/-/node-fetch-2.6.4.tgz",
"integrity": "sha512-1ZX9fcN4Rvkvgv4E6PAY5WXUFWFcRWxZa3EW83UjycOB9ljJCedb2CupIP4RZMEwF/M3eTcCihbBRgwtGbg5Rg==",
"dev": true,
"license": "MIT",
"dependencies": {
"@types/node": "*",
"form-data": "^3.0.0"
}
},
"node_modules/@types/node-fetch/node_modules/form-data": {
"version": "3.0.3",
"resolved": "https://registry.npmjs.org/form-data/-/form-data-3.0.3.tgz",
"integrity": "sha512-q5YBMeWy6E2Un0nMGWMgI65MAKtaylxfNJGJxpGh45YDciZB4epbWpaAfImil6CPAPTYB4sh0URQNDRIZG5F2w==",
"dev": true,
"license": "MIT",
"dependencies": {
"asynckit": "^0.4.0",
"combined-stream": "^1.0.8",
"es-set-tostringtag": "^2.1.0",
"mime-types": "^2.1.35"
},
"engines": {
"node": ">= 6"
}
},
"node_modules/@types/node-fetch/node_modules/mime-db": {
"version": "1.52.0",
"resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz",
"integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==",
"dev": true,
"license": "MIT",
"engines": {
"node": ">= 0.6"
}
},
"node_modules/@types/node-fetch/node_modules/mime-types": {
"version": "2.1.35",
"resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.35.tgz",
"integrity": "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==",
"dev": true,
"license": "MIT",
"dependencies": {
"mime-db": "1.52.0"
},
"engines": {
"node": ">= 0.6"
}
},
"node_modules/@types/node-forge": {
"version": "1.3.11",
"resolved": "https://registry.npmjs.org/@types/node-forge/-/node-forge-1.3.11.tgz",

View File

@@ -74,7 +74,6 @@
"@types/lowdb": "1.0.15",
"@types/lunr": "2.3.7",
"@types/node": "22.15.3",
"@types/node-fetch": "2.6.4",
"@types/node-forge": "1.3.11",
"@types/papaparse": "5.3.16",
"@types/proper-lockfile": "4.1.4",
@@ -190,7 +189,6 @@
"lunr": "2.3.9",
"multer": "1.4.5-lts.2",
"ngx-toastr": "19.0.0",
"node-fetch": "2.6.12",
"node-forge": "1.3.1",
"oidc-client-ts": "2.4.1",
"open": "10.1.2",