mirror of
https://github.com/bitwarden/browser
synced 2025-12-13 14:53:33 +00:00
[PM-17479] Load-sdk-once (#12764)
* create service to load sdk on application init * Eagerly load CLI SDK * Remove wasm logging to api * Fix imports * Eagerly load Desktop renderer SDK Note: If the main process ever requires an SDK, we'll need to load it there, too. In that event, it's probably a good idea to move to IPC for all SDK functions to avoid loading the SDK for every window. * init wasm module from sdk load service * Use default client factory * Fix type imports * Resolve jest module import errors A CLI sdk load service that async imports our wasm binary doesn't seem to be needed to run, but jest isn't dealing with the ESM import properly. * Fix linting * remove example code
This commit is contained in:
9
apps/cli/src/platform/services/cli-sdk-load.service.ts
Normal file
9
apps/cli/src/platform/services/cli-sdk-load.service.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
import { SdkLoadService } from "@bitwarden/common/platform/abstractions/sdk/sdk-load.service";
|
||||
import * as sdk from "@bitwarden/sdk-internal";
|
||||
|
||||
export class CliSdkLoadService implements SdkLoadService {
|
||||
async load(): Promise<void> {
|
||||
const module = await import("@bitwarden/sdk-internal/bitwarden_wasm_internal_bg.wasm");
|
||||
(sdk as any).init(module);
|
||||
}
|
||||
}
|
||||
@@ -68,6 +68,7 @@ import {
|
||||
RegionConfig,
|
||||
} from "@bitwarden/common/platform/abstractions/environment.service";
|
||||
import { KeyGenerationService as KeyGenerationServiceAbstraction } from "@bitwarden/common/platform/abstractions/key-generation.service";
|
||||
import { SdkLoadService } from "@bitwarden/common/platform/abstractions/sdk/sdk-load.service";
|
||||
import { SdkService } from "@bitwarden/common/platform/abstractions/sdk/sdk.service";
|
||||
import { KeySuffixOptions, LogLevelType } from "@bitwarden/common/platform/enums";
|
||||
import { StateFactory } from "@bitwarden/common/platform/factories/state-factory";
|
||||
@@ -171,6 +172,7 @@ import {
|
||||
import { CliBiometricsService } from "../key-management/cli-biometrics-service";
|
||||
import { flagEnabled } from "../platform/flags";
|
||||
import { CliPlatformUtilsService } from "../platform/services/cli-platform-utils.service";
|
||||
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";
|
||||
@@ -270,6 +272,7 @@ export class ServiceContainer {
|
||||
kdfConfigService: KdfConfigService;
|
||||
taskSchedulerService: TaskSchedulerService;
|
||||
sdkService: SdkService;
|
||||
sdkLoadService: SdkLoadService;
|
||||
cipherAuthorizationService: CipherAuthorizationService;
|
||||
|
||||
constructor() {
|
||||
@@ -570,6 +573,7 @@ export class ServiceContainer {
|
||||
const sdkClientFactory = flagEnabled("sdk")
|
||||
? new DefaultSdkClientFactory()
|
||||
: new NoopSdkClientFactory();
|
||||
this.sdkLoadService = new CliSdkLoadService();
|
||||
this.sdkService = new DefaultSdkService(
|
||||
sdkClientFactory,
|
||||
this.environmentService,
|
||||
@@ -859,6 +863,7 @@ export class ServiceContainer {
|
||||
return;
|
||||
}
|
||||
|
||||
await this.sdkLoadService.load();
|
||||
await this.storageService.init();
|
||||
await this.stateService.init();
|
||||
this.containerService.attachToGlobal(global);
|
||||
|
||||
Reference in New Issue
Block a user