1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-10 21:33:27 +00:00

[PM-27530] Rename BitwardenClient to PasswordManagerClient (#17578)

* fix: compilation issues with PM client rename

* fix: jest compilation

* feat: rename all non-breaking platform instances

* feat: update SDK
This commit is contained in:
Andreas Coroiu
2025-11-25 14:48:25 +01:00
committed by GitHub
parent 86a757119c
commit 9e90e72961
10 changed files with 58 additions and 58 deletions

View File

@@ -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"; import { SdkClientFactory } from "../src/platform/abstractions/sdk/sdk-client-factory";
export class DefaultSdkClientFactory implements SdkClientFactory { export class DefaultSdkClientFactory implements SdkClientFactory {
createSdkClient( createSdkClient(
...args: ConstructorParameters<typeof BitwardenClient> ...args: ConstructorParameters<typeof PasswordManagerClient>
): Promise<BitwardenClient> { ): Promise<PasswordManagerClient> {
throw new Error("Method not implemented."); throw new Error("Method not implemented.");
} }
} }

View File

@@ -1,14 +1,14 @@
import type { BitwardenClient } from "@bitwarden/sdk-internal"; import type { PasswordManagerClient } from "@bitwarden/sdk-internal";
/** /**
* Factory for creating SDK clients. * Factory for creating SDK clients.
*/ */
export abstract class SdkClientFactory { export abstract class SdkClientFactory {
/** /**
* Creates a new BitwardenClient. Assumes the SDK is already loaded. * Creates a new Password Manager client. Assumes the SDK is already loaded.
* @param args Bitwarden client constructor parameters * @param args Password Manager client constructor parameters
*/ */
abstract createSdkClient( abstract createSdkClient(
...args: ConstructorParameters<typeof BitwardenClient> ...args: ConstructorParameters<typeof PasswordManagerClient>
): Promise<BitwardenClient>; ): Promise<PasswordManagerClient>;
} }

View File

@@ -1,6 +1,6 @@
import { Observable } from "rxjs"; import { Observable } from "rxjs";
import { BitwardenClient, Uuid } from "@bitwarden/sdk-internal"; import { PasswordManagerClient, Uuid } from "@bitwarden/sdk-internal";
import { UserId } from "../../../types/guid"; import { UserId } from "../../../types/guid";
import { Rc } from "../../misc/reference-counting/rc"; import { Rc } from "../../misc/reference-counting/rc";
@@ -46,7 +46,7 @@ export abstract class SdkService {
* Retrieve a client initialized without a user. * Retrieve a client initialized without a user.
* This client can only be used for operations that don't require a user context. * This client can only be used for operations that don't require a user context.
*/ */
abstract client$: Observable<BitwardenClient>; abstract client$: Observable<PasswordManagerClient>;
/** /**
* Retrieve a client initialized for a specific user. * 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 * @param userId The user id for which to retrieve the client
*/ */
abstract userClient$(userId: UserId): Observable<Rc<BitwardenClient>>; abstract userClient$(userId: UserId): Observable<Rc<PasswordManagerClient>>;
/** /**
* This method is used during/after an authentication procedure to set a new client for a specific user. * 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 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. * @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;
} }

View File

@@ -7,13 +7,13 @@ import { SdkClientFactory } from "../../abstractions/sdk/sdk-client-factory";
*/ */
export class DefaultSdkClientFactory implements SdkClientFactory { export class DefaultSdkClientFactory implements SdkClientFactory {
/** /**
* Initializes a Bitwarden client. Assumes the SDK is already loaded. * Initializes a Password Manager client. Assumes the SDK is already loaded.
* @param args Bitwarden client constructor parameters * @param args Password Manager client constructor parameters
* @returns A BitwardenClient * @returns A PasswordManagerClient
*/ */
async createSdkClient( async createSdkClient(
...args: ConstructorParameters<typeof sdk.BitwardenClient> ...args: ConstructorParameters<typeof sdk.PasswordManagerClient>
): Promise<sdk.BitwardenClient> { ): Promise<sdk.PasswordManagerClient> {
return Promise.resolve(new sdk.BitwardenClient(...args)); return Promise.resolve(new sdk.PasswordManagerClient(...args));
} }
} }

View File

@@ -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. // 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 // eslint-disable-next-line no-restricted-imports
import { KdfConfigService, KeyService, PBKDF2KdfConfig } from "@bitwarden/key-management"; import { KdfConfigService, KeyService, PBKDF2KdfConfig } from "@bitwarden/key-management";
import { BitwardenClient } from "@bitwarden/sdk-internal"; import { PasswordManagerClient } from "@bitwarden/sdk-internal";
import { import {
ObservableTracker, ObservableTracker,
@@ -109,7 +109,7 @@ describe("DefaultSdkService", () => {
}); });
describe("given no client override has been set for the user", () => { describe("given no client override has been set for the user", () => {
let mockClient!: MockProxy<BitwardenClient>; let mockClient!: MockProxy<PasswordManagerClient>;
beforeEach(() => { beforeEach(() => {
mockClient = createMockClient(); mockClient = createMockClient();
@@ -123,8 +123,8 @@ describe("DefaultSdkService", () => {
}); });
it("does not create an SDK client when called the second time with same userId", async () => { it("does not create an SDK client when called the second time with same userId", async () => {
const subject_1 = new BehaviorSubject<Rc<BitwardenClient> | undefined>(undefined); const subject_1 = new BehaviorSubject<Rc<PasswordManagerClient> | undefined>(undefined);
const subject_2 = new BehaviorSubject<Rc<BitwardenClient> | undefined>(undefined); const subject_2 = new BehaviorSubject<Rc<PasswordManagerClient> | undefined>(undefined);
// Use subjects to ensure the subscription is kept alive // Use subjects to ensure the subscription is kept alive
service.userClient$(userId).subscribe(subject_1); service.userClient$(userId).subscribe(subject_1);
@@ -139,8 +139,8 @@ describe("DefaultSdkService", () => {
}); });
it("destroys the internal SDK client when all subscriptions are closed", async () => { it("destroys the internal SDK client when all subscriptions are closed", async () => {
const subject_1 = new BehaviorSubject<Rc<BitwardenClient> | undefined>(undefined); const subject_1 = new BehaviorSubject<Rc<PasswordManagerClient> | undefined>(undefined);
const subject_2 = new BehaviorSubject<Rc<BitwardenClient> | undefined>(undefined); const subject_2 = new BehaviorSubject<Rc<PasswordManagerClient> | undefined>(undefined);
const subscription_1 = service.userClient$(userId).subscribe(subject_1); const subscription_1 = service.userClient$(userId).subscribe(subject_1);
const subscription_2 = service.userClient$(userId).subscribe(subject_2); const subscription_2 = service.userClient$(userId).subscribe(subject_2);
await new Promise(process.nextTick); await new Promise(process.nextTick);
@@ -170,7 +170,7 @@ describe("DefaultSdkService", () => {
describe("given overrides are used", () => { 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 () => { it("does not create a new client and emits the override client when a client override has already been set ", async () => {
const mockClient = mock<BitwardenClient>(); const mockClient = mock<PasswordManagerClient>();
service.setClient(userId, mockClient); service.setClient(userId, mockClient);
const userClientTracker = new ObservableTracker(service.userClient$(userId), false); const userClientTracker = new ObservableTracker(service.userClient$(userId), false);
await userClientTracker.pauseUntilReceived(1); await userClientTracker.pauseUntilReceived(1);
@@ -242,8 +242,8 @@ describe("DefaultSdkService", () => {
}); });
}); });
function createMockClient(): MockProxy<BitwardenClient> { function createMockClient(): MockProxy<PasswordManagerClient> {
const client = mock<BitwardenClient>(); const client = mock<PasswordManagerClient>();
client.crypto.mockReturnValue(mock()); client.crypto.mockReturnValue(mock());
client.platform.mockReturnValue({ client.platform.mockReturnValue({
state: jest.fn().mockReturnValue(mock()), state: jest.fn().mockReturnValue(mock()),

View File

@@ -20,7 +20,7 @@ import { ConfigService } from "@bitwarden/common/platform/abstractions/config/co
// eslint-disable-next-line no-restricted-imports // eslint-disable-next-line no-restricted-imports
import { KeyService, KdfConfigService, KdfConfig, KdfType } from "@bitwarden/key-management"; import { KeyService, KdfConfigService, KdfConfig, KdfType } from "@bitwarden/key-management";
import { import {
BitwardenClient, PasswordManagerClient,
ClientSettings, ClientSettings,
DeviceType as SdkDeviceType, DeviceType as SdkDeviceType,
TokenProvider, TokenProvider,
@@ -70,9 +70,9 @@ class JsTokenProvider implements TokenProvider {
export class DefaultSdkService implements SdkService { export class DefaultSdkService implements SdkService {
private sdkClientOverrides = new BehaviorSubject<{ private sdkClientOverrides = new BehaviorSubject<{
[userId: UserId]: Rc<BitwardenClient> | typeof UnsetClient; [userId: UserId]: Rc<PasswordManagerClient> | typeof UnsetClient;
}>({}); }>({});
private sdkClientCache = new Map<UserId, Observable<Rc<BitwardenClient>>>(); private sdkClientCache = new Map<UserId, Observable<Rc<PasswordManagerClient>>>();
client$ = this.environmentService.environment$.pipe( client$ = this.environmentService.environment$.pipe(
concatMap(async (env) => { concatMap(async (env) => {
@@ -107,14 +107,14 @@ export class DefaultSdkService implements SdkService {
private userAgent: string | null = null, private userAgent: string | null = null,
) {} ) {}
userClient$(userId: UserId): Observable<Rc<BitwardenClient>> { userClient$(userId: UserId): Observable<Rc<PasswordManagerClient>> {
return this.sdkClientOverrides.pipe( return this.sdkClientOverrides.pipe(
takeWhile((clients) => clients[userId] !== UnsetClient, false), takeWhile((clients) => clients[userId] !== UnsetClient, false),
map((clients) => { map((clients) => {
if (clients[userId] === UnsetClient) { if (clients[userId] === UnsetClient) {
throw new Error("Encountered UnsetClient even though it should have been filtered out"); throw new Error("Encountered UnsetClient even though it should have been filtered out");
} }
return clients[userId] as Rc<BitwardenClient>; return clients[userId] as Rc<PasswordManagerClient>;
}), }),
distinctUntilChanged(), distinctUntilChanged(),
switchMap((clientOverride) => { 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]; const previousValue = this.sdkClientOverrides.value[userId];
this.sdkClientOverrides.next({ this.sdkClientOverrides.next({
@@ -149,7 +149,7 @@ export class DefaultSdkService implements SdkService {
* @param userId The user id for which to create the client * @param userId The user id for which to create the client
* @returns An observable that emits the client for the user * @returns An observable that emits the client for the user
*/ */
private internalClient$(userId: UserId): Observable<Rc<BitwardenClient>> { private internalClient$(userId: UserId): Observable<Rc<PasswordManagerClient>> {
const cached = this.sdkClientCache.get(userId); const cached = this.sdkClientCache.get(userId);
if (cached !== undefined) { if (cached !== undefined) {
return cached; return cached;
@@ -187,7 +187,7 @@ export class DefaultSdkService implements SdkService {
switchMap( switchMap(
([env, account, kdfParams, privateKey, userKey, signingKey, orgKeys, securityState]) => { ([env, account, kdfParams, privateKey, userKey, signingKey, orgKeys, securityState]) => {
// Create our own observable to be able to implement clean-up logic // Create our own observable to be able to implement clean-up logic
return new Observable<Rc<BitwardenClient>>((subscriber) => { return new Observable<Rc<PasswordManagerClient>>((subscriber) => {
const createAndInitializeClient = async () => { const createAndInitializeClient = async () => {
if (env == null || kdfParams == null || privateKey == null || userKey == null) { if (env == null || kdfParams == null || privateKey == null || userKey == null) {
return undefined; return undefined;
@@ -214,7 +214,7 @@ export class DefaultSdkService implements SdkService {
return client; return client;
}; };
let client: Rc<BitwardenClient> | undefined; let client: Rc<PasswordManagerClient> | undefined;
createAndInitializeClient() createAndInitializeClient()
.then((c) => { .then((c) => {
client = c === undefined ? undefined : new Rc(c); client = c === undefined ? undefined : new Rc(c);
@@ -239,7 +239,7 @@ export class DefaultSdkService implements SdkService {
private async initializeClient( private async initializeClient(
userId: UserId, userId: UserId,
client: BitwardenClient, client: PasswordManagerClient,
account: AccountInfo, account: AccountInfo,
kdfParams: KdfConfig, kdfParams: KdfConfig,
privateKey: EncryptedString, privateKey: EncryptedString,
@@ -281,7 +281,7 @@ export class DefaultSdkService implements SdkService {
await this.loadFeatureFlags(client); await this.loadFeatureFlags(client);
} }
private async loadFeatureFlags(client: BitwardenClient) { private async loadFeatureFlags(client: PasswordManagerClient) {
const serverConfig = await firstValueFrom(this.configService.serverConfig$); const serverConfig = await firstValueFrom(this.configService.serverConfig$);
const featureFlagMap = new Map( const featureFlagMap = new Map(

View File

@@ -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"; 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 { export class NoopSdkClientFactory implements SdkClientFactory {
createSdkClient( createSdkClient(
...args: ConstructorParameters<typeof BitwardenClient> ...args: ConstructorParameters<typeof PasswordManagerClient>
): Promise<BitwardenClient> { ): Promise<PasswordManagerClient> {
return Promise.reject(new Error("SDK not available")); return Promise.reject(new Error("SDK not available"));
} }
} }

View File

@@ -7,7 +7,7 @@ import {
throwIfEmpty, throwIfEmpty,
} from "rxjs"; } from "rxjs";
import { BitwardenClient } from "@bitwarden/sdk-internal"; import { PasswordManagerClient } from "@bitwarden/sdk-internal";
import { UserId } from "../../types/guid"; import { UserId } from "../../types/guid";
import { SdkService, UserNotLoggedInError } from "../abstractions/sdk/sdk.service"; import { SdkService, UserNotLoggedInError } from "../abstractions/sdk/sdk.service";
@@ -17,18 +17,18 @@ import { DeepMockProxy, mockDeep } from "./mock-deep";
export class MockSdkService implements SdkService { export class MockSdkService implements SdkService {
private userClients$ = new BehaviorSubject<{ private userClients$ = new BehaviorSubject<{
[userId: UserId]: Rc<BitwardenClient> | undefined; [userId: UserId]: Rc<PasswordManagerClient> | undefined;
}>({}); }>({});
private _client$ = new BehaviorSubject(mockDeep<BitwardenClient>()); private _client$ = new BehaviorSubject(mockDeep<PasswordManagerClient>());
client$ = this._client$.asObservable(); client$ = this._client$.asObservable();
version$ = new BehaviorSubject("0.0.1-test").asObservable(); version$ = new BehaviorSubject("0.0.1-test").asObservable();
userClient$(userId: UserId): Observable<Rc<BitwardenClient>> { userClient$(userId: UserId): Observable<Rc<PasswordManagerClient>> {
return this.userClients$.pipe( return this.userClients$.pipe(
takeWhile((clients) => clients[userId] !== undefined, false), takeWhile((clients) => clients[userId] !== undefined, false),
map((clients) => clients[userId] as Rc<BitwardenClient>), map((clients) => clients[userId] as Rc<PasswordManagerClient>),
distinctUntilChanged(), distinctUntilChanged(),
throwIfEmpty(() => new UserNotLoggedInError(userId)), throwIfEmpty(() => new UserNotLoggedInError(userId)),
); );
@@ -42,7 +42,7 @@ export class MockSdkService implements SdkService {
* Returns the non-user scoped client mock. * Returns the non-user scoped client mock.
* This is what is returned by the `client$` observable. * This is what is returned by the `client$` observable.
*/ */
get client(): DeepMockProxy<BitwardenClient> { get client(): DeepMockProxy<PasswordManagerClient> {
return this._client$.value; return this._client$.value;
} }
@@ -55,7 +55,7 @@ export class MockSdkService implements SdkService {
* @returns A user-scoped mock for the user. * @returns A user-scoped mock for the user.
*/ */
userLogin: (userId: UserId) => { userLogin: (userId: UserId) => {
const client = mockDeep<BitwardenClient>(); const client = mockDeep<PasswordManagerClient>();
this.userClients$.next({ this.userClients$.next({
...this.userClients$.getValue(), ...this.userClients$.getValue(),
[userId]: new Rc(client), [userId]: new Rc(client),

16
package-lock.json generated
View File

@@ -23,8 +23,8 @@
"@angular/platform-browser": "19.2.14", "@angular/platform-browser": "19.2.14",
"@angular/platform-browser-dynamic": "19.2.14", "@angular/platform-browser-dynamic": "19.2.14",
"@angular/router": "19.2.14", "@angular/router": "19.2.14",
"@bitwarden/commercial-sdk-internal": "0.2.0-main.375", "@bitwarden/commercial-sdk-internal": "0.2.0-main.395",
"@bitwarden/sdk-internal": "0.2.0-main.375", "@bitwarden/sdk-internal": "0.2.0-main.395",
"@electron/fuses": "1.8.0", "@electron/fuses": "1.8.0",
"@emotion/css": "11.13.5", "@emotion/css": "11.13.5",
"@koa/multer": "4.0.0", "@koa/multer": "4.0.0",
@@ -4620,9 +4620,9 @@
"link": true "link": true
}, },
"node_modules/@bitwarden/commercial-sdk-internal": { "node_modules/@bitwarden/commercial-sdk-internal": {
"version": "0.2.0-main.375", "version": "0.2.0-main.395",
"resolved": "https://registry.npmjs.org/@bitwarden/commercial-sdk-internal/-/commercial-sdk-internal-0.2.0-main.375.tgz", "resolved": "https://registry.npmjs.org/@bitwarden/commercial-sdk-internal/-/commercial-sdk-internal-0.2.0-main.395.tgz",
"integrity": "sha512-UMVfLjMh79+5et1if7qqOi+pSGP5Ay3AcGp4E5oLZ0p0yFsN2Q54UFv+SLju0/oI0qTvVZP1RkEtTJXHdNrpTg==", "integrity": "sha512-DrxL3iA29hzWpyxPyZjiXx0m+EHOgk4CVb+BAi2SoxsacmyHYuTgXuASFMieRz2rv85wS3UR0N64Ok9lC+xNYA==",
"license": "BITWARDEN SOFTWARE DEVELOPMENT KIT LICENSE AGREEMENT", "license": "BITWARDEN SOFTWARE DEVELOPMENT KIT LICENSE AGREEMENT",
"dependencies": { "dependencies": {
"type-fest": "^4.41.0" "type-fest": "^4.41.0"
@@ -4725,9 +4725,9 @@
"link": true "link": true
}, },
"node_modules/@bitwarden/sdk-internal": { "node_modules/@bitwarden/sdk-internal": {
"version": "0.2.0-main.375", "version": "0.2.0-main.395",
"resolved": "https://registry.npmjs.org/@bitwarden/sdk-internal/-/sdk-internal-0.2.0-main.375.tgz", "resolved": "https://registry.npmjs.org/@bitwarden/sdk-internal/-/sdk-internal-0.2.0-main.395.tgz",
"integrity": "sha512-kf2SKFkAdSmV2/ORo6u1eegwYW2ha62NHUsx2ij2uPWmm7mzXUoNa7z8mqhJV1ozg5o7yBqBuXd6Wqo9Ww+/RA==", "integrity": "sha512-biExeL2Grp11VQjjK6QM16+WOYk87mTgUhYKFm+Bu/A0zZBzhL/6AocpA9h2T5M8rLCGVVJVUMaXUW3YrSTqEA==",
"license": "GPL-3.0", "license": "GPL-3.0",
"dependencies": { "dependencies": {
"type-fest": "^4.41.0" "type-fest": "^4.41.0"

View File

@@ -160,8 +160,8 @@
"@angular/platform-browser": "19.2.14", "@angular/platform-browser": "19.2.14",
"@angular/platform-browser-dynamic": "19.2.14", "@angular/platform-browser-dynamic": "19.2.14",
"@angular/router": "19.2.14", "@angular/router": "19.2.14",
"@bitwarden/sdk-internal": "0.2.0-main.375", "@bitwarden/sdk-internal": "0.2.0-main.395",
"@bitwarden/commercial-sdk-internal": "0.2.0-main.375", "@bitwarden/commercial-sdk-internal": "0.2.0-main.395",
"@electron/fuses": "1.8.0", "@electron/fuses": "1.8.0",
"@emotion/css": "11.13.5", "@emotion/css": "11.13.5",
"@koa/multer": "4.0.0", "@koa/multer": "4.0.0",