mirror of
https://github.com/bitwarden/browser
synced 2026-02-22 12:24:01 +00:00
Prefer static classes for pure functions
This commit is contained in:
@@ -92,7 +92,6 @@ import { I18nService as I18nServiceAbstraction } from "@bitwarden/common/platfor
|
||||
import { KeyGenerationService as KeyGenerationServiceAbstraction } from "@bitwarden/common/platform/abstractions/key-generation.service";
|
||||
import { LogService as LogServiceAbstraction } from "@bitwarden/common/platform/abstractions/log.service";
|
||||
import { PlatformUtilsService as PlatformUtilsServiceAbstraction } from "@bitwarden/common/platform/abstractions/platform-utils.service";
|
||||
import { SdkPureClientFactory } from "@bitwarden/common/platform/abstractions/sdk/sdk-client-factory";
|
||||
import { SdkLoadService } from "@bitwarden/common/platform/abstractions/sdk/sdk-load.service";
|
||||
import { SdkService } from "@bitwarden/common/platform/abstractions/sdk/sdk.service";
|
||||
import { StateService as StateServiceAbstraction } from "@bitwarden/common/platform/abstractions/state.service";
|
||||
@@ -259,10 +258,7 @@ import { LocalBackedSessionStorageService } from "../platform/services/local-bac
|
||||
import { BackgroundPlatformUtilsService } from "../platform/services/platform-utils/background-platform-utils.service";
|
||||
import { BrowserPlatformUtilsService } from "../platform/services/platform-utils/browser-platform-utils.service";
|
||||
import { PopupViewCacheBackgroundService } from "../platform/services/popup-view-cache-background.service";
|
||||
import {
|
||||
BrowserSdkClientFactory,
|
||||
BrowserSdkPureClientFactory,
|
||||
} from "../platform/services/sdk/browser-sdk-client-factory";
|
||||
import { BrowserSdkClientFactory } from "../platform/services/sdk/browser-sdk-client-factory";
|
||||
import { BrowserSdkLoadService } from "../platform/services/sdk/browser-sdk-load.service";
|
||||
import { BackgroundTaskSchedulerService } from "../platform/services/task-scheduler/background-task-scheduler.service";
|
||||
import { BackgroundMemoryStorageService } from "../platform/storage/background-memory-storage.service";
|
||||
@@ -384,7 +380,6 @@ export default class MainBackground {
|
||||
autoSubmitLoginBackground: AutoSubmitLoginBackground;
|
||||
sdkService: SdkService;
|
||||
sdkLoadService: SdkLoadService;
|
||||
pureSdkClientFactory: SdkPureClientFactory;
|
||||
cipherAuthorizationService: CipherAuthorizationService;
|
||||
inlineMenuFieldQualificationService: InlineMenuFieldQualificationService;
|
||||
|
||||
@@ -502,19 +497,13 @@ export default class MainBackground {
|
||||
return derivedKey;
|
||||
});
|
||||
|
||||
this.pureSdkClientFactory = new BrowserSdkPureClientFactory();
|
||||
this.largeObjectMemoryStorageForStateProviders = new LocalBackedSessionStorageService(
|
||||
sessionKey,
|
||||
this.storageService,
|
||||
// For local backed session storage, we expect that the encrypted data on disk will persist longer than the encryption key in memory
|
||||
// and failures to decrypt because of that are completely expected. For this reason, we pass in `false` to the `EncryptServiceImplementation`
|
||||
// so that MAC failures are not logged.
|
||||
new EncryptServiceImplementation(
|
||||
this.pureSdkClientFactory,
|
||||
this.cryptoFunctionService,
|
||||
this.logService,
|
||||
false,
|
||||
),
|
||||
new EncryptServiceImplementation(this.cryptoFunctionService, this.logService, false),
|
||||
this.platformUtilsService,
|
||||
this.logService,
|
||||
);
|
||||
@@ -550,18 +539,8 @@ export default class MainBackground {
|
||||
);
|
||||
|
||||
this.encryptService = BrowserApi.isManifestVersion(2)
|
||||
? new EncryptServiceImplementation(
|
||||
this.pureSdkClientFactory,
|
||||
this.cryptoFunctionService,
|
||||
this.logService,
|
||||
true,
|
||||
)
|
||||
: new EncryptServiceImplementation(
|
||||
this.pureSdkClientFactory,
|
||||
this.cryptoFunctionService,
|
||||
this.logService,
|
||||
true,
|
||||
);
|
||||
? new EncryptServiceImplementation(this.cryptoFunctionService, this.logService, true)
|
||||
: new EncryptServiceImplementation(this.cryptoFunctionService, this.logService, true);
|
||||
|
||||
this.singleUserStateProvider = new DefaultSingleUserStateProvider(
|
||||
storageServiceProvider,
|
||||
|
||||
@@ -1,16 +1,5 @@
|
||||
import {
|
||||
SdkClientFactory,
|
||||
SdkPureClientFactory,
|
||||
} from "@bitwarden/common/platform/abstractions/sdk/sdk-client-factory";
|
||||
import type { BitwardenClient, BitwardenPure } from "@bitwarden/sdk-internal";
|
||||
|
||||
export class BrowserSdkPureClientFactory implements SdkPureClientFactory {
|
||||
async createPureSdkClient(): Promise<BitwardenPure> {
|
||||
const instance = (globalThis as any).init_pure();
|
||||
|
||||
return instance;
|
||||
}
|
||||
}
|
||||
import { SdkClientFactory } from "@bitwarden/common/platform/abstractions/sdk/sdk-client-factory";
|
||||
import type { BitwardenClient } from "@bitwarden/sdk-internal";
|
||||
|
||||
/**
|
||||
* SDK client factory with a js fallback for when WASM is not supported.
|
||||
|
||||
@@ -1,11 +1,6 @@
|
||||
import * as sdk from "@bitwarden/sdk-internal";
|
||||
import * as wasm from "@bitwarden/sdk-internal/bitwarden_wasm_internal_bg.wasm.js";
|
||||
|
||||
(globalThis as any).init_pure = () => {
|
||||
(sdk as any).init(wasm);
|
||||
|
||||
return new sdk.BitwardenPure();
|
||||
};
|
||||
(globalThis as any).init_sdk = (...args: ConstructorParameters<typeof sdk.BitwardenClient>) => {
|
||||
(sdk as any).init(wasm);
|
||||
|
||||
|
||||
@@ -1,11 +1,6 @@
|
||||
import * as sdk from "@bitwarden/sdk-internal";
|
||||
import * as wasm from "@bitwarden/sdk-internal/bitwarden_wasm_internal_bg.wasm";
|
||||
|
||||
(globalThis as any).init_pure = () => {
|
||||
(sdk as any).init(wasm);
|
||||
|
||||
return new sdk.BitwardenPure();
|
||||
};
|
||||
(globalThis as any).init_sdk = (...args: ConstructorParameters<typeof sdk.BitwardenClient>) => {
|
||||
(sdk as any).init(wasm);
|
||||
|
||||
|
||||
@@ -70,10 +70,7 @@ import { KeyGenerationService } from "@bitwarden/common/platform/abstractions/ke
|
||||
import { LogService } from "@bitwarden/common/platform/abstractions/log.service";
|
||||
import { MessagingService as MessagingServiceAbstraction } from "@bitwarden/common/platform/abstractions/messaging.service";
|
||||
import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service";
|
||||
import {
|
||||
SdkClientFactory,
|
||||
SdkPureClientFactory,
|
||||
} from "@bitwarden/common/platform/abstractions/sdk/sdk-client-factory";
|
||||
import { SdkClientFactory } from "@bitwarden/common/platform/abstractions/sdk/sdk-client-factory";
|
||||
import { SdkLoadService } from "@bitwarden/common/platform/abstractions/sdk/sdk-load.service";
|
||||
import { StateService } from "@bitwarden/common/platform/abstractions/state.service";
|
||||
import {
|
||||
@@ -87,10 +84,7 @@ import { flagEnabled } from "@bitwarden/common/platform/misc/flags";
|
||||
import { TaskSchedulerService } from "@bitwarden/common/platform/scheduling";
|
||||
import { ConsoleLogService } from "@bitwarden/common/platform/services/console-log.service";
|
||||
import { ContainerService } from "@bitwarden/common/platform/services/container.service";
|
||||
import {
|
||||
NoopSdkClientFactory,
|
||||
NoopSdkPureClientFactory,
|
||||
} from "@bitwarden/common/platform/services/sdk/noop-sdk-client-factory";
|
||||
import { NoopSdkClientFactory } from "@bitwarden/common/platform/services/sdk/noop-sdk-client-factory";
|
||||
import { StorageServiceProvider } from "@bitwarden/common/platform/services/storage-service.provider";
|
||||
import { WebCryptoFunctionService } from "@bitwarden/common/platform/services/web-crypto-function.service";
|
||||
import {
|
||||
@@ -151,10 +145,7 @@ import BrowserMemoryStorageService from "../../platform/services/browser-memory-
|
||||
import { BrowserScriptInjectorService } from "../../platform/services/browser-script-injector.service";
|
||||
import I18nService from "../../platform/services/i18n.service";
|
||||
import { ForegroundPlatformUtilsService } from "../../platform/services/platform-utils/foreground-platform-utils.service";
|
||||
import {
|
||||
BrowserSdkClientFactory,
|
||||
BrowserSdkPureClientFactory,
|
||||
} from "../../platform/services/sdk/browser-sdk-client-factory";
|
||||
import { BrowserSdkClientFactory } from "../../platform/services/sdk/browser-sdk-client-factory";
|
||||
import { BrowserSdkLoadService } from "../../platform/services/sdk/browser-sdk-load.service";
|
||||
import { ForegroundTaskSchedulerService } from "../../platform/services/task-scheduler/foreground-task-scheduler.service";
|
||||
import { BrowserStorageServiceProvider } from "../../platform/storage/browser-storage-service.provider";
|
||||
@@ -600,12 +591,6 @@ const safeProviders: SafeProvider[] = [
|
||||
flagEnabled("sdk") ? new BrowserSdkClientFactory() : new NoopSdkClientFactory(),
|
||||
deps: [],
|
||||
}),
|
||||
safeProvider({
|
||||
provide: SdkPureClientFactory,
|
||||
useFactory: (logService) =>
|
||||
flagEnabled("sdk") ? new BrowserSdkPureClientFactory() : new NoopSdkPureClientFactory(),
|
||||
deps: [LogService],
|
||||
}),
|
||||
safeProvider({
|
||||
provide: LoginEmailService,
|
||||
useClass: LoginEmailService,
|
||||
|
||||
@@ -66,10 +66,7 @@ import { I18nService as I18nServiceAbstraction } from "@bitwarden/common/platfor
|
||||
import { LogService } from "@bitwarden/common/platform/abstractions/log.service";
|
||||
import { MessagingService } from "@bitwarden/common/platform/abstractions/messaging.service";
|
||||
import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service";
|
||||
import {
|
||||
SdkClientFactory,
|
||||
SdkPureClientFactory,
|
||||
} from "@bitwarden/common/platform/abstractions/sdk/sdk-client-factory";
|
||||
import { SdkClientFactory } from "@bitwarden/common/platform/abstractions/sdk/sdk-client-factory";
|
||||
import { SdkLoadService } from "@bitwarden/common/platform/abstractions/sdk/sdk-load.service";
|
||||
import { AbstractStorageService } from "@bitwarden/common/platform/abstractions/storage.service";
|
||||
import { ThemeType } from "@bitwarden/common/platform/enums";
|
||||
@@ -78,10 +75,7 @@ import { MemoryStorageService } from "@bitwarden/common/platform/services/memory
|
||||
// eslint-disable-next-line import/no-restricted-paths -- Implementation for memory storage
|
||||
import { MigrationBuilderService } from "@bitwarden/common/platform/services/migration-builder.service";
|
||||
import { MigrationRunner } from "@bitwarden/common/platform/services/migration-runner";
|
||||
import {
|
||||
NoopSdkClientFactory,
|
||||
NoopSdkPureClientFactory,
|
||||
} from "@bitwarden/common/platform/services/sdk/noop-sdk-client-factory";
|
||||
import { NoopSdkClientFactory } from "@bitwarden/common/platform/services/sdk/noop-sdk-client-factory";
|
||||
import { NoopSdkLoadService } from "@bitwarden/common/platform/services/sdk/noop-sdk-load.service";
|
||||
import { StorageServiceProvider } from "@bitwarden/common/platform/services/storage-service.provider";
|
||||
/* eslint-disable import/no-restricted-paths -- Implementation for memory storage */
|
||||
@@ -118,7 +112,7 @@ import { WebProcessReloadService } from "../key-management/services/web-process-
|
||||
import { WebBiometricsService } from "../key-management/web-biometric.service";
|
||||
import { WebEnvironmentService } from "../platform/web-environment.service";
|
||||
import { WebMigrationRunner } from "../platform/web-migration-runner";
|
||||
import { WebSdkClientFactory, WebSdkPureClientFactory } from "../platform/web-sdk-client-factory";
|
||||
import { WebSdkClientFactory } from "../platform/web-sdk-client-factory";
|
||||
import { WebSdkLoadService } from "../platform/web-sdk-load.service";
|
||||
import { WebStorageServiceProvider } from "../platform/web-storage-service.provider";
|
||||
|
||||
@@ -307,11 +301,6 @@ const safeProviders: SafeProvider[] = [
|
||||
useClass: flagEnabled("sdk") ? WebSdkClientFactory : NoopSdkClientFactory,
|
||||
deps: [],
|
||||
}),
|
||||
safeProvider({
|
||||
provide: SdkPureClientFactory,
|
||||
useClass: flagEnabled("sdk") ? WebSdkPureClientFactory : NoopSdkPureClientFactory,
|
||||
deps: [],
|
||||
}),
|
||||
safeProvider({
|
||||
provide: ProcessReloadServiceAbstraction,
|
||||
useClass: WebProcessReloadService,
|
||||
|
||||
@@ -1,15 +1,6 @@
|
||||
import {
|
||||
SdkClientFactory,
|
||||
SdkPureClientFactory,
|
||||
} from "@bitwarden/common/platform/abstractions/sdk/sdk-client-factory";
|
||||
import { SdkClientFactory } from "@bitwarden/common/platform/abstractions/sdk/sdk-client-factory";
|
||||
import * as sdk from "@bitwarden/sdk-internal";
|
||||
|
||||
export class WebSdkPureClientFactory implements SdkPureClientFactory {
|
||||
async createPureSdkClient(): Promise<sdk.BitwardenPure> {
|
||||
return Promise.resolve(new sdk.BitwardenPure());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* SDK client factory with a js fallback for when WASM is not supported.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user