diff --git a/apps/browser/src/background/main.background.ts b/apps/browser/src/background/main.background.ts index ba9776b80c5..747a05943a5 100644 --- a/apps/browser/src/background/main.background.ts +++ b/apps/browser/src/background/main.background.ts @@ -736,7 +736,6 @@ export default class MainBackground { this.accountService, this.kdfConfigService, this.keyService, - this.apiService, ); this.passwordStrengthService = new PasswordStrengthService(); @@ -1310,23 +1309,6 @@ export default class MainBackground { await this.initOverlayAndTabsBackground(); - if (flagEnabled("sdk")) { - // Warn if the SDK for some reason can't be initialized - let supported = false; - let error: Error; - try { - supported = await firstValueFrom(this.sdkService.supported$); - } catch (e) { - error = e; - } - - if (!supported) { - this.sdkService - .failedToInitialize("background", error) - .catch((e) => this.logService.error(e)); - } - } - return new Promise((resolve) => { setTimeout(async () => { await this.refreshBadge(); diff --git a/apps/browser/src/platform/services/sdk/browser-sdk-client-factory.ts b/apps/browser/src/platform/services/sdk/browser-sdk-client-factory.ts index c9d5d726a6a..a2f0c78cd52 100644 --- a/apps/browser/src/platform/services/sdk/browser-sdk-client-factory.ts +++ b/apps/browser/src/platform/services/sdk/browser-sdk-client-factory.ts @@ -2,7 +2,6 @@ // @ts-strict-ignore import { LogService } from "@bitwarden/common/platform/abstractions/log.service"; import { SdkClientFactory } from "@bitwarden/common/platform/abstractions/sdk/sdk-client-factory"; -import { RecoverableSDKError } from "@bitwarden/common/platform/services/sdk/default-sdk.service"; import type { BitwardenClient } from "@bitwarden/sdk-internal"; import { BrowserApi } from "../../browser/browser-api"; @@ -72,42 +71,14 @@ export class BrowserSdkClientFactory implements SdkClientFactory { ...args: ConstructorParameters ): Promise { const startTime = performance.now(); - try { - await loadWithTimeout(); - } catch (error) { - throw new Error(`Failed to load: ${error.message}`); - } + await load(); const endTime = performance.now(); - const elapsed = Math.round((endTime - startTime) / 1000); const instance = (globalThis as any).init_sdk(...args); this.logService.info("WASM SDK loaded in", Math.round(endTime - startTime), "ms"); - // If it takes 3 seconds or more to load, we want to capture it. - if (elapsed >= 3) { - throw new RecoverableSDKError(instance, elapsed); - } - return instance; } } - -const loadWithTimeout = async () => { - return new Promise((resolve, reject) => { - const timer = setTimeout(() => { - reject(new Error("Operation timed out after 10 second")); - }, 10000); - - load() - .then(() => { - clearTimeout(timer); - resolve(); - }) - .catch((error) => { - clearTimeout(timer); - reject(error); - }); - }); -}; diff --git a/apps/browser/src/popup/app.component.ts b/apps/browser/src/popup/app.component.ts index cbdbed51db7..248050ed61c 100644 --- a/apps/browser/src/popup/app.component.ts +++ b/apps/browser/src/popup/app.component.ts @@ -1,7 +1,6 @@ // FIXME: Update this file to be type safe and remove this and next line // @ts-strict-ignore import { ChangeDetectorRef, Component, NgZone, OnDestroy, OnInit, inject } from "@angular/core"; -import { takeUntilDestroyed } from "@angular/core/rxjs-interop"; import { NavigationEnd, Router, RouterOutlet } from "@angular/router"; import { Subject, takeUntil, firstValueFrom, concatMap, filter, tap } from "rxjs"; @@ -11,9 +10,7 @@ import { AuthService } from "@bitwarden/common/auth/abstractions/auth.service"; import { AuthenticationStatus } from "@bitwarden/common/auth/enums/authentication-status"; import { AnimationControlService } from "@bitwarden/common/platform/abstractions/animation-control.service"; import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service"; -import { LogService } from "@bitwarden/common/platform/abstractions/log.service"; import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service"; -import { SdkService } from "@bitwarden/common/platform/abstractions/sdk/sdk.service"; import { StateService } from "@bitwarden/common/platform/abstractions/state.service"; import { MessageListener } from "@bitwarden/common/platform/messaging"; import { UserId } from "@bitwarden/common/types/guid"; @@ -25,7 +22,6 @@ import { ToastService, } from "@bitwarden/components"; -import { flagEnabled } from "../platform/flags"; import { PopupCompactModeService } from "../platform/popup/layout/popup-compact-mode.service"; import { PopupWidthService } from "../platform/popup/layout/popup-width.service"; import { PopupViewCacheService } from "../platform/popup/view-cache/popup-view-cache.service"; @@ -72,31 +68,7 @@ export class AppComponent implements OnInit, OnDestroy { private toastService: ToastService, private accountService: AccountService, private animationControlService: AnimationControlService, - private logService: LogService, - private sdkService: SdkService, - ) { - if (flagEnabled("sdk")) { - // Warn if the SDK for some reason can't be initialized - this.sdkService.supported$.pipe(takeUntilDestroyed()).subscribe({ - next: (supported) => { - if (!supported) { - this.logService.debug("SDK is not supported"); - this.sdkService - .failedToInitialize("popup", undefined) - .catch((e) => this.logService.error(e)); - } else { - this.logService.debug("SDK is supported"); - } - }, - error: (e: unknown) => { - this.sdkService - .failedToInitialize("popup", e as Error) - .catch((e) => this.logService.error(e)); - this.logService.error(e); - }, - }); - } - } + ) {} async ngOnInit() { initPopupClosedListener(); diff --git a/apps/cli/src/service-container/service-container.ts b/apps/cli/src/service-container/service-container.ts index 91b75a14ff6..2afbae0782f 100644 --- a/apps/cli/src/service-container/service-container.ts +++ b/apps/cli/src/service-container/service-container.ts @@ -550,7 +550,6 @@ export class ServiceContainer { this.accountService, this.kdfConfigService, this.keyService, - this.apiService, customUserAgent, ); @@ -864,19 +863,5 @@ export class ServiceContainer { } this.inited = true; - - if (flagEnabled("sdk")) { - // Warn if the SDK for some reason can't be initialized - let supported = false; - try { - supported = await firstValueFrom(this.sdkService.supported$); - } catch (e) { - // Do nothing. - } - - if (!supported) { - this.sdkService.failedToInitialize("cli").catch((e) => this.logService.error(e)); - } - } } } diff --git a/apps/desktop/src/app/app.component.ts b/apps/desktop/src/app/app.component.ts index 5443285da25..5fefbf9ddff 100644 --- a/apps/desktop/src/app/app.component.ts +++ b/apps/desktop/src/app/app.component.ts @@ -10,19 +10,8 @@ import { ViewChild, ViewContainerRef, } from "@angular/core"; -import { takeUntilDestroyed } from "@angular/core/rxjs-interop"; import { Router } from "@angular/router"; -import { - catchError, - filter, - firstValueFrom, - map, - of, - Subject, - takeUntil, - timeout, - withLatestFrom, -} from "rxjs"; +import { filter, firstValueFrom, map, Subject, takeUntil, timeout, withLatestFrom } from "rxjs"; import { CollectionService } from "@bitwarden/admin-console/common"; import { ModalRef } from "@bitwarden/angular/components/modal/modal.ref"; @@ -52,7 +41,6 @@ import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.servic 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 { SdkService } from "@bitwarden/common/platform/abstractions/sdk/sdk.service"; import { StateService } from "@bitwarden/common/platform/abstractions/state.service"; import { SystemService } from "@bitwarden/common/platform/abstractions/system.service"; import { clearCaches } from "@bitwarden/common/platform/misc/sequentialize"; @@ -70,7 +58,6 @@ import { KeyService, BiometricStateService } from "@bitwarden/key-management"; import { DeleteAccountComponent } from "../auth/delete-account.component"; import { MenuAccount, MenuUpdateRequest } from "../main/menu/menu.updater"; -import { flagEnabled } from "../platform/flags"; import { PremiumComponent } from "../vault/app/accounts/premium.component"; import { FolderAddEditComponent } from "../vault/app/vault/folder-add-edit.component"; @@ -167,28 +154,8 @@ export class AppComponent implements OnInit, OnDestroy { private biometricStateService: BiometricStateService, private stateEventRunnerService: StateEventRunnerService, private accountService: AccountService, - private sdkService: SdkService, private organizationService: OrganizationService, - ) { - if (flagEnabled("sdk")) { - // Warn if the SDK for some reason can't be initialized - this.sdkService.supported$ - .pipe( - takeUntilDestroyed(), - catchError(() => { - return of(false); - }), - ) - .subscribe((supported) => { - if (!supported) { - this.logService.debug("SDK is not supported"); - this.sdkService.failedToInitialize("desktop").catch((e) => this.logService.error(e)); - } else { - this.logService.debug("SDK is supported"); - } - }); - } - } + ) {} ngOnInit() { this.accountService.activeAccount$.pipe(takeUntil(this.destroy$)).subscribe((account) => { diff --git a/apps/web/src/app/app.component.ts b/apps/web/src/app/app.component.ts index 1075655af9e..16c783f3a5a 100644 --- a/apps/web/src/app/app.component.ts +++ b/apps/web/src/app/app.component.ts @@ -2,10 +2,9 @@ // @ts-strict-ignore import { DOCUMENT } from "@angular/common"; import { Component, Inject, NgZone, OnDestroy, OnInit } from "@angular/core"; -import { takeUntilDestroyed } from "@angular/core/rxjs-interop"; import { NavigationEnd, Router } from "@angular/router"; import * as jq from "jquery"; -import { Subject, filter, firstValueFrom, map, takeUntil, timeout, catchError, of } from "rxjs"; +import { Subject, filter, firstValueFrom, map, takeUntil, timeout } from "rxjs"; import { CollectionService } from "@bitwarden/admin-console/common"; import { EventUploadService } from "@bitwarden/common/abstractions/event/event-upload.service"; @@ -22,9 +21,7 @@ import { ProcessReloadServiceAbstraction } from "@bitwarden/common/key-managemen import { BroadcasterService } from "@bitwarden/common/platform/abstractions/broadcaster.service"; import { ConfigService } from "@bitwarden/common/platform/abstractions/config/config.service"; import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service"; -import { LogService } from "@bitwarden/common/platform/abstractions/log.service"; import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service"; -import { SdkService } from "@bitwarden/common/platform/abstractions/sdk/sdk.service"; import { StateService } from "@bitwarden/common/platform/abstractions/state.service"; import { StateEventRunnerService } from "@bitwarden/common/platform/state"; import { SyncService } from "@bitwarden/common/platform/sync"; @@ -34,8 +31,6 @@ import { DialogService, ToastService } from "@bitwarden/components"; import { PasswordGenerationServiceAbstraction } from "@bitwarden/generator-legacy"; import { KeyService, BiometricStateService } from "@bitwarden/key-management"; -import { flagEnabled } from "../utils/flags"; - import { PolicyListService } from "./admin-console/core/policy-list.service"; import { DisableSendPolicy, @@ -93,29 +88,8 @@ export class AppComponent implements OnDestroy, OnInit { private stateEventRunnerService: StateEventRunnerService, private organizationService: InternalOrganizationServiceAbstraction, private accountService: AccountService, - private logService: LogService, - private sdkService: SdkService, private processReloadService: ProcessReloadServiceAbstraction, - ) { - if (flagEnabled("sdk")) { - // Warn if the SDK for some reason can't be initialized - this.sdkService.supported$ - .pipe( - takeUntilDestroyed(), - catchError(() => { - return of(false); - }), - ) - .subscribe((supported) => { - if (!supported) { - this.logService.debug("SDK is not supported"); - this.sdkService.failedToInitialize("web").catch((e) => this.logService.error(e)); - } else { - this.logService.debug("SDK is supported"); - } - }); - } - } + ) {} ngOnInit() { this.i18nService.locale$.pipe(takeUntil(this.destroy$)).subscribe((locale) => { diff --git a/libs/angular/src/services/jslib-services.module.ts b/libs/angular/src/services/jslib-services.module.ts index 0e50cec1b64..a8fc5a73ec5 100644 --- a/libs/angular/src/services/jslib-services.module.ts +++ b/libs/angular/src/services/jslib-services.module.ts @@ -1383,7 +1383,6 @@ const safeProviders: SafeProvider[] = [ AccountServiceAbstraction, KdfConfigService, KeyServiceAbstraction, - ApiServiceAbstraction, ], }), safeProvider({ diff --git a/libs/common/src/platform/abstractions/sdk/sdk.service.ts b/libs/common/src/platform/abstractions/sdk/sdk.service.ts index ec606896408..d44d38c36ab 100644 --- a/libs/common/src/platform/abstractions/sdk/sdk.service.ts +++ b/libs/common/src/platform/abstractions/sdk/sdk.service.ts @@ -7,11 +7,6 @@ import { BitwardenClient } from "@bitwarden/sdk-internal"; import { UserId } from "../../../types/guid"; export abstract class SdkService { - /** - * Check if the SDK is supported in the current environment. - */ - supported$: Observable; - /** * Retrieve the version of the SDK. */ @@ -35,6 +30,4 @@ export abstract class SdkService { * @param userId */ abstract userClient$(userId: UserId): Observable; - - abstract failedToInitialize(category: string, error?: Error): Promise; } diff --git a/libs/common/src/platform/services/sdk/default-sdk.service.spec.ts b/libs/common/src/platform/services/sdk/default-sdk.service.spec.ts index de8b079621a..6593095b325 100644 --- a/libs/common/src/platform/services/sdk/default-sdk.service.spec.ts +++ b/libs/common/src/platform/services/sdk/default-sdk.service.spec.ts @@ -4,7 +4,6 @@ import { BehaviorSubject, firstValueFrom, of } from "rxjs"; import { KdfConfigService, KeyService, PBKDF2KdfConfig } from "@bitwarden/key-management"; import { BitwardenClient } from "@bitwarden/sdk-internal"; -import { ApiService } from "../../../abstractions/api.service"; import { AccountInfo, AccountService } from "../../../auth/abstractions/account.service"; import { UserId } from "../../../types/guid"; import { UserKey } from "../../../types/key"; @@ -24,7 +23,6 @@ describe("DefaultSdkService", () => { let accountService!: MockProxy; let kdfConfigService!: MockProxy; let keyService!: MockProxy; - let apiService!: MockProxy; let service!: DefaultSdkService; let mockClient!: MockProxy; @@ -36,7 +34,6 @@ describe("DefaultSdkService", () => { accountService = mock(); kdfConfigService = mock(); keyService = mock(); - apiService = mock(); // Can't use `of(mock())` for some reason environmentService.environment$ = new BehaviorSubject(mock()); @@ -48,7 +45,6 @@ describe("DefaultSdkService", () => { accountService, kdfConfigService, keyService, - apiService, ); mockClient = mock(); diff --git a/libs/common/src/platform/services/sdk/default-sdk.service.ts b/libs/common/src/platform/services/sdk/default-sdk.service.ts index be6f99ab040..bf593aecf7d 100644 --- a/libs/common/src/platform/services/sdk/default-sdk.service.ts +++ b/libs/common/src/platform/services/sdk/default-sdk.service.ts @@ -3,7 +3,6 @@ import { combineLatest, concatMap, - firstValueFrom, Observable, shareReplay, map, @@ -21,7 +20,6 @@ import { DeviceType as SdkDeviceType, } from "@bitwarden/sdk-internal"; -import { ApiService } from "../../../abstractions/api.service"; import { EncryptedOrganizationKeyData } from "../../../admin-console/models/data/encrypted-organization-key.data"; import { AccountInfo, AccountService } from "../../../auth/abstractions/account.service"; import { DeviceType } from "../../../enums/device-type.enum"; @@ -34,43 +32,17 @@ import { SdkService } from "../../abstractions/sdk/sdk.service"; import { compareValues } from "../../misc/compare-values"; import { EncryptedString } from "../../models/domain/enc-string"; -export class RecoverableSDKError extends Error { - sdk: BitwardenClient; - timeout: number; - - constructor(sdk: BitwardenClient, timeout: number) { - super(`SDK took ${timeout}s to initialize`); - - this.sdk = sdk; - this.timeout = timeout; - } -} - export class DefaultSdkService implements SdkService { private sdkClientCache = new Map>(); client$ = this.environmentService.environment$.pipe( concatMap(async (env) => { const settings = this.toSettings(env); - try { - return await this.sdkClientFactory.createSdkClient(settings, LogLevel.Info); - } catch (e) { - if (e instanceof RecoverableSDKError) { - await this.failedToInitialize("sdk", e); - return e.sdk; - } - throw e; - } + return await this.sdkClientFactory.createSdkClient(settings, LogLevel.Info); }), shareReplay({ refCount: true, bufferSize: 1 }), ); - supported$ = this.client$.pipe( - concatMap(async (client) => { - return client.echo("bitwarden wasm!") === "bitwarden wasm!"; - }), - ); - version$ = this.client$.pipe( map((client) => client.version()), catchError(() => "Unsupported"), @@ -83,7 +55,6 @@ export class DefaultSdkService implements SdkService { private accountService: AccountService, private kdfConfigService: KdfConfigService, private keyService: KeyService, - private apiService: ApiService, // Yes we shouldn't import ApiService, but it's temporary private userAgent: string = null, ) {} @@ -155,31 +126,6 @@ export class DefaultSdkService implements SdkService { return client$; } - async failedToInitialize(category: string, error?: Error): Promise { - // Only log on cloud instances - if ( - this.platformUtilsService.isDev() || - !(await firstValueFrom(this.environmentService.environment$)).isCloud - ) { - return; - } - - return this.apiService.send( - "POST", - "/wasm-debug", - { - category: category, - error: error?.message, - }, - false, - false, - null, - (headers) => { - headers.append("SDK-Version", "1.0.0"); - }, - ); - } - private async initializeClient( client: BitwardenClient, account: AccountInfo,