diff --git a/libs/common/spec/jest-sdk-client-factory.ts b/libs/common/spec/jest-sdk-client-factory.ts index 8e5e1c9d3f..8b93ba791b 100644 --- a/libs/common/spec/jest-sdk-client-factory.ts +++ b/libs/common/spec/jest-sdk-client-factory.ts @@ -1,11 +1,11 @@ -import { BitwardenClient } from "@bitwarden/sdk-internal"; +import { PasswordManagerClient } from "@bitwarden/sdk-internal"; import { SdkClientFactory } from "../src/platform/abstractions/sdk/sdk-client-factory"; export class DefaultSdkClientFactory implements SdkClientFactory { createSdkClient( - ...args: ConstructorParameters - ): Promise { + ...args: ConstructorParameters + ): Promise { throw new Error("Method not implemented."); } } diff --git a/libs/common/src/platform/abstractions/sdk/sdk-client-factory.ts b/libs/common/src/platform/abstractions/sdk/sdk-client-factory.ts index 6a1b7b67b4..35830e42f1 100644 --- a/libs/common/src/platform/abstractions/sdk/sdk-client-factory.ts +++ b/libs/common/src/platform/abstractions/sdk/sdk-client-factory.ts @@ -1,14 +1,14 @@ -import type { BitwardenClient } from "@bitwarden/sdk-internal"; +import type { PasswordManagerClient } from "@bitwarden/sdk-internal"; /** * Factory for creating SDK clients. */ export abstract class SdkClientFactory { /** - * Creates a new BitwardenClient. Assumes the SDK is already loaded. - * @param args Bitwarden client constructor parameters + * Creates a new Password Manager client. Assumes the SDK is already loaded. + * @param args Password Manager client constructor parameters */ abstract createSdkClient( - ...args: ConstructorParameters - ): Promise; + ...args: ConstructorParameters + ): Promise; } diff --git a/libs/common/src/platform/abstractions/sdk/sdk.service.ts b/libs/common/src/platform/abstractions/sdk/sdk.service.ts index 03baec5cc3..9b7f32a8a0 100644 --- a/libs/common/src/platform/abstractions/sdk/sdk.service.ts +++ b/libs/common/src/platform/abstractions/sdk/sdk.service.ts @@ -1,6 +1,6 @@ import { Observable } from "rxjs"; -import { BitwardenClient, Uuid } from "@bitwarden/sdk-internal"; +import { PasswordManagerClient, Uuid } from "@bitwarden/sdk-internal"; import { UserId } from "../../../types/guid"; import { Rc } from "../../misc/reference-counting/rc"; @@ -46,7 +46,7 @@ export abstract class SdkService { * Retrieve a client initialized without a user. * This client can only be used for operations that don't require a user context. */ - abstract client$: Observable; + abstract client$: Observable; /** * Retrieve a client initialized for a specific user. @@ -64,7 +64,7 @@ export abstract class SdkService { * * @param userId The user id for which to retrieve the client */ - abstract userClient$(userId: UserId): Observable>; + abstract userClient$(userId: UserId): Observable>; /** * This method is used during/after an authentication procedure to set a new client for a specific user. @@ -75,5 +75,5 @@ export abstract class SdkService { * @param userId The user id for which to set the client * @param client The client to set for the user. If undefined, the client will be unset. */ - abstract setClient(userId: UserId, client: BitwardenClient | undefined): void; + abstract setClient(userId: UserId, client: PasswordManagerClient | undefined): void; } diff --git a/libs/common/src/platform/services/sdk/default-sdk-client-factory.ts b/libs/common/src/platform/services/sdk/default-sdk-client-factory.ts index fc55cc83ac..d0e4b96ba8 100644 --- a/libs/common/src/platform/services/sdk/default-sdk-client-factory.ts +++ b/libs/common/src/platform/services/sdk/default-sdk-client-factory.ts @@ -7,13 +7,13 @@ import { SdkClientFactory } from "../../abstractions/sdk/sdk-client-factory"; */ export class DefaultSdkClientFactory implements SdkClientFactory { /** - * Initializes a Bitwarden client. Assumes the SDK is already loaded. - * @param args Bitwarden client constructor parameters - * @returns A BitwardenClient + * Initializes a Password Manager client. Assumes the SDK is already loaded. + * @param args Password Manager client constructor parameters + * @returns A PasswordManagerClient */ async createSdkClient( - ...args: ConstructorParameters - ): Promise { - return Promise.resolve(new sdk.BitwardenClient(...args)); + ...args: ConstructorParameters + ): Promise { + return Promise.resolve(new sdk.PasswordManagerClient(...args)); } } 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 769e8521d8..dc94559407 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 @@ -5,7 +5,7 @@ import { SecurityStateService } from "@bitwarden/common/key-management/security- // This import has been flagged as unallowed for this class. It may be involved in a circular dependency loop. // eslint-disable-next-line no-restricted-imports import { KdfConfigService, KeyService, PBKDF2KdfConfig } from "@bitwarden/key-management"; -import { BitwardenClient } from "@bitwarden/sdk-internal"; +import { PasswordManagerClient } from "@bitwarden/sdk-internal"; import { ObservableTracker, @@ -109,7 +109,7 @@ describe("DefaultSdkService", () => { }); describe("given no client override has been set for the user", () => { - let mockClient!: MockProxy; + let mockClient!: MockProxy; beforeEach(() => { mockClient = createMockClient(); @@ -123,8 +123,8 @@ describe("DefaultSdkService", () => { }); it("does not create an SDK client when called the second time with same userId", async () => { - const subject_1 = new BehaviorSubject | undefined>(undefined); - const subject_2 = new BehaviorSubject | undefined>(undefined); + const subject_1 = new BehaviorSubject | undefined>(undefined); + const subject_2 = new BehaviorSubject | undefined>(undefined); // Use subjects to ensure the subscription is kept alive service.userClient$(userId).subscribe(subject_1); @@ -139,8 +139,8 @@ describe("DefaultSdkService", () => { }); it("destroys the internal SDK client when all subscriptions are closed", async () => { - const subject_1 = new BehaviorSubject | undefined>(undefined); - const subject_2 = new BehaviorSubject | undefined>(undefined); + const subject_1 = new BehaviorSubject | undefined>(undefined); + const subject_2 = new BehaviorSubject | undefined>(undefined); const subscription_1 = service.userClient$(userId).subscribe(subject_1); const subscription_2 = service.userClient$(userId).subscribe(subject_2); await new Promise(process.nextTick); @@ -170,7 +170,7 @@ describe("DefaultSdkService", () => { describe("given overrides are used", () => { it("does not create a new client and emits the override client when a client override has already been set ", async () => { - const mockClient = mock(); + const mockClient = mock(); service.setClient(userId, mockClient); const userClientTracker = new ObservableTracker(service.userClient$(userId), false); await userClientTracker.pauseUntilReceived(1); @@ -242,8 +242,8 @@ describe("DefaultSdkService", () => { }); }); -function createMockClient(): MockProxy { - const client = mock(); +function createMockClient(): MockProxy { + const client = mock(); client.crypto.mockReturnValue(mock()); client.platform.mockReturnValue({ state: jest.fn().mockReturnValue(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 6f9c9df761..eb663c6f92 100644 --- a/libs/common/src/platform/services/sdk/default-sdk.service.ts +++ b/libs/common/src/platform/services/sdk/default-sdk.service.ts @@ -20,7 +20,7 @@ import { ConfigService } from "@bitwarden/common/platform/abstractions/config/co // eslint-disable-next-line no-restricted-imports import { KeyService, KdfConfigService, KdfConfig, KdfType } from "@bitwarden/key-management"; import { - BitwardenClient, + PasswordManagerClient, ClientSettings, DeviceType as SdkDeviceType, TokenProvider, @@ -70,9 +70,9 @@ class JsTokenProvider implements TokenProvider { export class DefaultSdkService implements SdkService { private sdkClientOverrides = new BehaviorSubject<{ - [userId: UserId]: Rc | typeof UnsetClient; + [userId: UserId]: Rc | typeof UnsetClient; }>({}); - private sdkClientCache = new Map>>(); + private sdkClientCache = new Map>>(); client$ = this.environmentService.environment$.pipe( concatMap(async (env) => { @@ -107,14 +107,14 @@ export class DefaultSdkService implements SdkService { private userAgent: string | null = null, ) {} - userClient$(userId: UserId): Observable> { + userClient$(userId: UserId): Observable> { return this.sdkClientOverrides.pipe( takeWhile((clients) => clients[userId] !== UnsetClient, false), map((clients) => { if (clients[userId] === UnsetClient) { throw new Error("Encountered UnsetClient even though it should have been filtered out"); } - return clients[userId] as Rc; + return clients[userId] as Rc; }), distinctUntilChanged(), switchMap((clientOverride) => { @@ -129,7 +129,7 @@ export class DefaultSdkService implements SdkService { ); } - setClient(userId: UserId, client: BitwardenClient | undefined) { + setClient(userId: UserId, client: PasswordManagerClient | undefined) { const previousValue = this.sdkClientOverrides.value[userId]; this.sdkClientOverrides.next({ @@ -149,7 +149,7 @@ export class DefaultSdkService implements SdkService { * @param userId The user id for which to create the client * @returns An observable that emits the client for the user */ - private internalClient$(userId: UserId): Observable> { + private internalClient$(userId: UserId): Observable> { const cached = this.sdkClientCache.get(userId); if (cached !== undefined) { return cached; @@ -187,7 +187,7 @@ export class DefaultSdkService implements SdkService { switchMap( ([env, account, kdfParams, privateKey, userKey, signingKey, orgKeys, securityState]) => { // Create our own observable to be able to implement clean-up logic - return new Observable>((subscriber) => { + return new Observable>((subscriber) => { const createAndInitializeClient = async () => { if (env == null || kdfParams == null || privateKey == null || userKey == null) { return undefined; @@ -214,7 +214,7 @@ export class DefaultSdkService implements SdkService { return client; }; - let client: Rc | undefined; + let client: Rc | undefined; createAndInitializeClient() .then((c) => { client = c === undefined ? undefined : new Rc(c); @@ -239,7 +239,7 @@ export class DefaultSdkService implements SdkService { private async initializeClient( userId: UserId, - client: BitwardenClient, + client: PasswordManagerClient, account: AccountInfo, kdfParams: KdfConfig, privateKey: EncryptedString, @@ -281,7 +281,7 @@ export class DefaultSdkService implements SdkService { await this.loadFeatureFlags(client); } - private async loadFeatureFlags(client: BitwardenClient) { + private async loadFeatureFlags(client: PasswordManagerClient) { const serverConfig = await firstValueFrom(this.configService.serverConfig$); const featureFlagMap = new Map( diff --git a/libs/common/src/platform/services/sdk/noop-sdk-client-factory.ts b/libs/common/src/platform/services/sdk/noop-sdk-client-factory.ts index d7eab7e8dc..8ed0bc276c 100644 --- a/libs/common/src/platform/services/sdk/noop-sdk-client-factory.ts +++ b/libs/common/src/platform/services/sdk/noop-sdk-client-factory.ts @@ -1,4 +1,4 @@ -import type { BitwardenClient } from "@bitwarden/sdk-internal"; +import type { PasswordManagerClient } from "@bitwarden/sdk-internal"; import { SdkClientFactory } from "../../abstractions/sdk/sdk-client-factory"; @@ -9,8 +9,8 @@ import { SdkClientFactory } from "../../abstractions/sdk/sdk-client-factory"; */ export class NoopSdkClientFactory implements SdkClientFactory { createSdkClient( - ...args: ConstructorParameters - ): Promise { + ...args: ConstructorParameters + ): Promise { return Promise.reject(new Error("SDK not available")); } } diff --git a/libs/common/src/platform/spec/mock-sdk.service.ts b/libs/common/src/platform/spec/mock-sdk.service.ts index 66a6ab3ec8..aec2438c85 100644 --- a/libs/common/src/platform/spec/mock-sdk.service.ts +++ b/libs/common/src/platform/spec/mock-sdk.service.ts @@ -7,7 +7,7 @@ import { throwIfEmpty, } from "rxjs"; -import { BitwardenClient } from "@bitwarden/sdk-internal"; +import { PasswordManagerClient } from "@bitwarden/sdk-internal"; import { UserId } from "../../types/guid"; import { SdkService, UserNotLoggedInError } from "../abstractions/sdk/sdk.service"; @@ -17,18 +17,18 @@ import { DeepMockProxy, mockDeep } from "./mock-deep"; export class MockSdkService implements SdkService { private userClients$ = new BehaviorSubject<{ - [userId: UserId]: Rc | undefined; + [userId: UserId]: Rc | undefined; }>({}); - private _client$ = new BehaviorSubject(mockDeep()); + private _client$ = new BehaviorSubject(mockDeep()); client$ = this._client$.asObservable(); version$ = new BehaviorSubject("0.0.1-test").asObservable(); - userClient$(userId: UserId): Observable> { + userClient$(userId: UserId): Observable> { return this.userClients$.pipe( takeWhile((clients) => clients[userId] !== undefined, false), - map((clients) => clients[userId] as Rc), + map((clients) => clients[userId] as Rc), distinctUntilChanged(), throwIfEmpty(() => new UserNotLoggedInError(userId)), ); @@ -42,7 +42,7 @@ export class MockSdkService implements SdkService { * Returns the non-user scoped client mock. * This is what is returned by the `client$` observable. */ - get client(): DeepMockProxy { + get client(): DeepMockProxy { return this._client$.value; } @@ -55,7 +55,7 @@ export class MockSdkService implements SdkService { * @returns A user-scoped mock for the user. */ userLogin: (userId: UserId) => { - const client = mockDeep(); + const client = mockDeep(); this.userClients$.next({ ...this.userClients$.getValue(), [userId]: new Rc(client), diff --git a/package-lock.json b/package-lock.json index 39256cdbb9..1e2b8119a9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -23,8 +23,8 @@ "@angular/platform-browser": "19.2.14", "@angular/platform-browser-dynamic": "19.2.14", "@angular/router": "19.2.14", - "@bitwarden/commercial-sdk-internal": "0.2.0-main.375", - "@bitwarden/sdk-internal": "0.2.0-main.375", + "@bitwarden/commercial-sdk-internal": "0.2.0-main.395", + "@bitwarden/sdk-internal": "0.2.0-main.395", "@electron/fuses": "1.8.0", "@emotion/css": "11.13.5", "@koa/multer": "4.0.0", @@ -4620,9 +4620,9 @@ "link": true }, "node_modules/@bitwarden/commercial-sdk-internal": { - "version": "0.2.0-main.375", - "resolved": "https://registry.npmjs.org/@bitwarden/commercial-sdk-internal/-/commercial-sdk-internal-0.2.0-main.375.tgz", - "integrity": "sha512-UMVfLjMh79+5et1if7qqOi+pSGP5Ay3AcGp4E5oLZ0p0yFsN2Q54UFv+SLju0/oI0qTvVZP1RkEtTJXHdNrpTg==", + "version": "0.2.0-main.395", + "resolved": "https://registry.npmjs.org/@bitwarden/commercial-sdk-internal/-/commercial-sdk-internal-0.2.0-main.395.tgz", + "integrity": "sha512-DrxL3iA29hzWpyxPyZjiXx0m+EHOgk4CVb+BAi2SoxsacmyHYuTgXuASFMieRz2rv85wS3UR0N64Ok9lC+xNYA==", "license": "BITWARDEN SOFTWARE DEVELOPMENT KIT LICENSE AGREEMENT", "dependencies": { "type-fest": "^4.41.0" @@ -4725,9 +4725,9 @@ "link": true }, "node_modules/@bitwarden/sdk-internal": { - "version": "0.2.0-main.375", - "resolved": "https://registry.npmjs.org/@bitwarden/sdk-internal/-/sdk-internal-0.2.0-main.375.tgz", - "integrity": "sha512-kf2SKFkAdSmV2/ORo6u1eegwYW2ha62NHUsx2ij2uPWmm7mzXUoNa7z8mqhJV1ozg5o7yBqBuXd6Wqo9Ww+/RA==", + "version": "0.2.0-main.395", + "resolved": "https://registry.npmjs.org/@bitwarden/sdk-internal/-/sdk-internal-0.2.0-main.395.tgz", + "integrity": "sha512-biExeL2Grp11VQjjK6QM16+WOYk87mTgUhYKFm+Bu/A0zZBzhL/6AocpA9h2T5M8rLCGVVJVUMaXUW3YrSTqEA==", "license": "GPL-3.0", "dependencies": { "type-fest": "^4.41.0" diff --git a/package.json b/package.json index 337a3caa3b..2a06b80f00 100644 --- a/package.json +++ b/package.json @@ -160,8 +160,8 @@ "@angular/platform-browser": "19.2.14", "@angular/platform-browser-dynamic": "19.2.14", "@angular/router": "19.2.14", - "@bitwarden/sdk-internal": "0.2.0-main.375", - "@bitwarden/commercial-sdk-internal": "0.2.0-main.375", + "@bitwarden/sdk-internal": "0.2.0-main.395", + "@bitwarden/commercial-sdk-internal": "0.2.0-main.395", "@electron/fuses": "1.8.0", "@emotion/css": "11.13.5", "@koa/multer": "4.0.0",