1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-06 00:13:28 +00:00

Resolve breaking changes in the SDK (#15472)

This commit is contained in:
Oscar Hinton
2025-07-07 17:49:29 +02:00
committed by GitHub
parent a6ae7d23f7
commit 71bef25a96
9 changed files with 34 additions and 13 deletions

View File

@@ -1,9 +1,11 @@
import { ClientSettings, LogLevel, BitwardenClient } from "@bitwarden/sdk-internal";
import { BitwardenClient } from "@bitwarden/sdk-internal";
import { SdkClientFactory } from "../src/platform/abstractions/sdk/sdk-client-factory";
export class DefaultSdkClientFactory implements SdkClientFactory {
createSdkClient(settings?: ClientSettings, log_level?: LogLevel): Promise<BitwardenClient> {
createSdkClient(
...args: ConstructorParameters<typeof BitwardenClient>
): Promise<BitwardenClient> {
throw new Error("Method not implemented.");
}
}

View File

@@ -21,6 +21,7 @@ import {
BitwardenClient,
ClientSettings,
DeviceType as SdkDeviceType,
TokenProvider,
} from "@bitwarden/sdk-internal";
import { EncryptedOrganizationKeyData } from "../../../admin-console/models/data/encrypted-organization-key.data";
@@ -41,6 +42,17 @@ import { EncryptedString } from "../../models/domain/enc-string";
// blocking the creation of an internal client for that user.
const UnsetClient = Symbol("UnsetClient");
/**
* A token provider that exposes the access token to the SDK.
*/
class JsTokenProvider implements TokenProvider {
constructor() {}
async get_access_token(): Promise<string | undefined> {
return undefined;
}
}
export class DefaultSdkService implements SdkService {
private sdkClientOverrides = new BehaviorSubject<{
[userId: UserId]: Rc<BitwardenClient> | typeof UnsetClient;
@@ -51,7 +63,7 @@ export class DefaultSdkService implements SdkService {
concatMap(async (env) => {
await SdkLoadService.Ready;
const settings = this.toSettings(env);
return await this.sdkClientFactory.createSdkClient(settings);
return await this.sdkClientFactory.createSdkClient(new JsTokenProvider(), settings);
}),
shareReplay({ refCount: true, bufferSize: 1 }),
);
@@ -151,7 +163,10 @@ export class DefaultSdkService implements SdkService {
}
const settings = this.toSettings(env);
const client = await this.sdkClientFactory.createSdkClient(settings);
const client = await this.sdkClientFactory.createSdkClient(
new JsTokenProvider(),
settings,
);
await this.initializeClient(
userId,

View File

@@ -67,6 +67,7 @@ describe("AttachmentView", () => {
sizeName: "sizeName",
fileName: "fileName",
key: "encKeyB64",
decryptedKey: null,
});
});
});

View File

@@ -59,6 +59,7 @@ export class AttachmentView implements View {
sizeName: this.sizeName,
fileName: this.fileName,
key: this.encryptedKey?.toJSON(),
decryptedKey: null,
};
}

View File

@@ -7,7 +7,7 @@ import {
CipherType as SdkCipherType,
CipherView as SdkCipherView,
CipherListView,
Attachment as SdkAttachment,
AttachmentView as SdkAttachmentView,
} from "@bitwarden/sdk-internal";
import { mockEnc } from "../../../spec";
@@ -311,7 +311,9 @@ describe("DefaultCipherEncryptionService", () => {
const expectedDecryptedContent = new Uint8Array([5, 6, 7, 8]);
jest.spyOn(cipher, "toSdkCipher").mockReturnValue({ id: "id" } as SdkCipher);
jest.spyOn(attachment, "toSdkAttachmentView").mockReturnValue({ id: "a1" } as SdkAttachment);
jest
.spyOn(attachment, "toSdkAttachmentView")
.mockReturnValue({ id: "a1" } as SdkAttachmentView);
mockSdkClient.vault().attachments().decrypt_buffer.mockReturnValue(expectedDecryptedContent);
const result = await cipherEncryptionService.decryptAttachmentContent(

View File

@@ -31,7 +31,7 @@ const sdkPassphrase: GeneratorMetadata<PassphraseGenerationOptions> = {
create(
dependencies: GeneratorDependencyProvider,
): CredentialGenerator<PassphraseGenerationOptions> {
return new SdkPasswordRandomizer(new BitwardenClient(), Date.now); // @TODO hook up a real SDK client
return new SdkPasswordRandomizer(new BitwardenClient(null), Date.now); // @TODO hook up a real SDK client
},
},
profiles: {

View File

@@ -31,7 +31,7 @@ const sdkPassword: GeneratorMetadata<PasswordGeneratorSettings> = deepFreeze({
create(
dependencies: GeneratorDependencyProvider,
): CredentialGenerator<PasswordGeneratorSettings> {
return new SdkPasswordRandomizer(new BitwardenClient(), Date.now); // @TODO hook up a real SDK client
return new SdkPasswordRandomizer(new BitwardenClient(null), Date.now); // @TODO hook up a real SDK client
},
},
profiles: {

8
package-lock.json generated
View File

@@ -24,7 +24,7 @@
"@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.213",
"@bitwarden/sdk-internal": "0.2.0-main.225",
"@electron/fuses": "1.8.0",
"@emotion/css": "11.13.5",
"@koa/multer": "3.1.0",
@@ -4610,9 +4610,9 @@
"link": true
},
"node_modules/@bitwarden/sdk-internal": {
"version": "0.2.0-main.213",
"resolved": "https://registry.npmjs.org/@bitwarden/sdk-internal/-/sdk-internal-0.2.0-main.213.tgz",
"integrity": "sha512-/AUpdQQ++tLsH9dJDFQcIDihCpsI+ikdZuYwbztSXPp7piCnLk71f7r10yMPGQ8OEOF49mMEbLCG+dJKpBqeRg==",
"version": "0.2.0-main.225",
"resolved": "https://registry.npmjs.org/@bitwarden/sdk-internal/-/sdk-internal-0.2.0-main.225.tgz",
"integrity": "sha512-bhSFNX584GPJ9wMBYff1d18/Hfj+o+D4E1l3uDLZNXRI9s7w919AQWqJ0xUy1vh8gpkLJovkf64HQGqs0OiQQA==",
"license": "GPL-3.0",
"dependencies": {
"type-fest": "^4.41.0"

View File

@@ -160,7 +160,7 @@
"@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.213",
"@bitwarden/sdk-internal": "0.2.0-main.225",
"@electron/fuses": "1.8.0",
"@emotion/css": "11.13.5",
"@koa/multer": "3.1.0",