1
0
mirror of https://github.com/bitwarden/browser synced 2026-02-09 13:10:17 +00:00

updated localdata sdk type change

This commit is contained in:
gbubemismith
2025-04-17 17:03:05 -04:00
parent 55a701befd
commit 97e1c4ad94
4 changed files with 27 additions and 5 deletions

View File

@@ -770,6 +770,9 @@ describe("Cipher DTO", () => {
describe("toSdkCipher", () => {
it("should map to SDK Cipher", () => {
const lastUsedDate = new Date("2025-04-15T12:00:00.000Z").getTime();
const lastLaunched = new Date("2025-04-15T12:00:00.000Z").getTime();
const cipherData: CipherData = {
id: "id",
organizationId: "orgId",
@@ -838,7 +841,7 @@ describe("Cipher DTO", () => {
],
};
const cipher = new Cipher(cipherData);
const cipher = new Cipher(cipherData, { lastUsedDate, lastLaunched });
const sdkCipher = cipher.toSdkCipher();
expect(sdkCipher).toEqual({
@@ -875,7 +878,10 @@ describe("Cipher DTO", () => {
edit: true,
permissions: new CipherPermissionsApi(),
viewPassword: true,
localData: undefined,
localData: {
lastUsedDate: "2025-04-15T12:00:00.000Z",
lastLaunched: "2025-04-15T12:00:00.000Z",
},
attachments: [
{
id: "a1",

View File

@@ -358,7 +358,14 @@ export class Cipher extends Domain implements Decryptable<CipherView> {
permissions: this.permissions,
viewPassword: this.viewPassword,
localData: this.localData
? { lastUsedDate: this.localData.lastUsedDate, lastLaunched: this.localData.lastLaunched }
? {
lastUsedDate: this.localData.lastUsedDate
? new Date(this.localData.lastUsedDate).toISOString()
: undefined,
lastLaunched: this.localData.lastLaunched
? new Date(this.localData.lastLaunched).toISOString()
: undefined,
}
: undefined,
attachments: this.attachments?.map((a) => a.toSdkAttachment()),
fields: this.fields?.map((f) => f.toSdkField()),

View File

@@ -245,7 +245,16 @@ export class CipherView implements View, InitializerMetadata {
cipherView.permissions = CipherPermissionsApi.fromSdkCipherPermissions(obj.permissions);
cipherView.edit = obj.edit;
cipherView.viewPassword = obj.viewPassword;
cipherView.localData = obj.localData;
cipherView.localData = obj.localData
? {
lastUsedDate: obj.localData.lastUsedDate
? new Date(obj.localData.lastUsedDate).getTime()
: undefined,
lastLaunched: obj.localData.lastLaunched
? new Date(obj.localData.lastLaunched).getTime()
: undefined,
}
: undefined;
cipherView.attachments = obj.attachments?.map((a) => AttachmentView.fromSdkAttachmentView(a));
cipherView.fields = obj.fields?.map((f) => FieldView.fromSdkFieldView(f));
cipherView.passwordHistory = obj.passwordHistory?.map((ph) =>

View File

@@ -30,7 +30,7 @@ export class DefaultCipherEncryptionService implements CipherEncryptionService {
using ref = sdk.take();
const sdkCipherView = ref.value.vault().ciphers().decrypt(cipher.toSdkCipher());
// The SDK returns a cipherView or throws an error if decryption fails.
const clientCipherView = CipherView.fromSdkCipherView(sdkCipherView)!;
// Decrypt Fido2 credentials if available