From 59a5b6024d66a3b3ecfaae52eb145dd3358fd9d5 Mon Sep 17 00:00:00 2001 From: Nik Gilmore Date: Thu, 11 Sep 2025 17:54:37 -0700 Subject: [PATCH] Consume SDK migration changes --- libs/common/src/vault/models/domain/cipher.ts | 2 -- libs/common/src/vault/models/domain/login.ts | 1 + .../src/vault/services/cipher.service.ts | 19 +++++++++---------- .../default-cipher-encryption.service.ts | 3 ++- 4 files changed, 12 insertions(+), 13 deletions(-) diff --git a/libs/common/src/vault/models/domain/cipher.ts b/libs/common/src/vault/models/domain/cipher.ts index 8a16a5e6f4b..6c68e62a25c 100644 --- a/libs/common/src/vault/models/domain/cipher.ts +++ b/libs/common/src/vault/models/domain/cipher.ts @@ -384,8 +384,6 @@ export class Cipher extends Domain implements Decryptable { // version: 1, data: typeof this.data === "string" ? this.data : JSON.stringify(this.data), }; - console.log("Cipher toSdkCipher data:", sdkCipher.data, ". \n\n\nIt is of type ", typeof this.data); - switch (this.type) { case CipherType.Login: diff --git a/libs/common/src/vault/models/domain/login.ts b/libs/common/src/vault/models/domain/login.ts index 723478b10a8..088cb4becc7 100644 --- a/libs/common/src/vault/models/domain/login.ts +++ b/libs/common/src/vault/models/domain/login.ts @@ -100,6 +100,7 @@ export class Login extends Domain { toLoginData(): LoginData { const l = new LoginData(); + l.passwordRevisionDate = this.passwordRevisionDate != null ? this.passwordRevisionDate.toISOString() : null; l.autofillOnPageLoad = this.autofillOnPageLoad; diff --git a/libs/common/src/vault/services/cipher.service.ts b/libs/common/src/vault/services/cipher.service.ts index 4b7581aab13..c6a6a017f30 100644 --- a/libs/common/src/vault/services/cipher.service.ts +++ b/libs/common/src/vault/services/cipher.service.ts @@ -1091,7 +1091,6 @@ export class CipherService implements CipherServiceAbstraction { await this.apiService.send("POST", "/ciphers/bulk-collections", request, true, false); - console.log("Replacing all ciphers for user", userId); // Update the local state const ciphers = await firstValueFrom(this.ciphers$(userId)); @@ -1125,22 +1124,22 @@ export class CipherService implements CipherServiceAbstraction { return res; } - async replace(ciphers: { [id: string]: CipherData }, userId: UserId): Promise { + async replace(ciphers: { [id: string]: CipherData }, userId: UserId): Promise { // use cipher from the sdk and convert to cipher data to store in the state // uncomment to test migration const cipherObjects = Object.values(ciphers).map((cipherData) => new Cipher(cipherData)); - const migratedCiphers = (await this.cipherEncryptionService.migrateCiphers( + + const migratedCiphers = await this.cipherEncryptionService.migrateCiphers( cipherObjects, userId, - )); - // TODO: Something here broke loading my ciphers... need to investigate. - const res = await this.updateEncryptedCipherState((current) => { - migratedCiphers.forEach((c) => (current[c.id as CipherId] = c.toCipherData())); - return current; - }, userId); + ); - console.log("== Replacing all ciphers for user", userId); + const resultCiphers: Record = migratedCiphers.reduce( + (acc, c) => ({ ...acc, [c.id as CipherId]: c.toCipherData() }), + {} as Record, + ); + await this.updateEncryptedCipherState(() => resultCiphers, userId); } /** diff --git a/libs/common/src/vault/services/default-cipher-encryption.service.ts b/libs/common/src/vault/services/default-cipher-encryption.service.ts index 3f82766d4a7..16ed2247ba0 100644 --- a/libs/common/src/vault/services/default-cipher-encryption.service.ts +++ b/libs/common/src/vault/services/default-cipher-encryption.service.ts @@ -296,6 +296,7 @@ export class DefaultCipherEncryptionService implements CipherEncryptionService { try { using ref = sdk.take(); + const migratedSdkCiphers = ref.value .vault() .ciphers() @@ -305,7 +306,7 @@ export class DefaultCipherEncryptionService implements CipherEncryptionService { (sdkCipher) => Cipher.fromSdkCipher(sdkCipher)!, ); - this.logService.info(`Successfully migrated ${ciphers.length} ciphers`); + this.logService.info(`Successfully migrated ${migratedCiphers.length} ciphers`); return migratedCiphers; } catch (error) { this.logService.error(`Cipher migration failed: ${error}`);