mirror of
https://github.com/bitwarden/browser
synced 2025-12-06 00:13:28 +00:00
[PM-16217] Remove wasm timeout (#12476)
Remove the WASM timeout logic and supported$.
This commit is contained in:
@@ -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<boolean>;
|
||||
|
||||
/**
|
||||
* Retrieve the version of the SDK.
|
||||
*/
|
||||
@@ -35,6 +30,4 @@ export abstract class SdkService {
|
||||
* @param userId
|
||||
*/
|
||||
abstract userClient$(userId: UserId): Observable<BitwardenClient>;
|
||||
|
||||
abstract failedToInitialize(category: string, error?: Error): Promise<void>;
|
||||
}
|
||||
|
||||
@@ -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<AccountService>;
|
||||
let kdfConfigService!: MockProxy<KdfConfigService>;
|
||||
let keyService!: MockProxy<KeyService>;
|
||||
let apiService!: MockProxy<ApiService>;
|
||||
let service!: DefaultSdkService;
|
||||
|
||||
let mockClient!: MockProxy<BitwardenClient>;
|
||||
@@ -36,7 +34,6 @@ describe("DefaultSdkService", () => {
|
||||
accountService = mock<AccountService>();
|
||||
kdfConfigService = mock<KdfConfigService>();
|
||||
keyService = mock<KeyService>();
|
||||
apiService = mock<ApiService>();
|
||||
|
||||
// Can't use `of(mock<Environment>())` for some reason
|
||||
environmentService.environment$ = new BehaviorSubject(mock<Environment>());
|
||||
@@ -48,7 +45,6 @@ describe("DefaultSdkService", () => {
|
||||
accountService,
|
||||
kdfConfigService,
|
||||
keyService,
|
||||
apiService,
|
||||
);
|
||||
|
||||
mockClient = mock<BitwardenClient>();
|
||||
|
||||
@@ -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<UserId, Observable<BitwardenClient>>();
|
||||
|
||||
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<void> {
|
||||
// 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,
|
||||
|
||||
Reference in New Issue
Block a user