mirror of
https://github.com/bitwarden/browser
synced 2026-02-04 10:43:47 +00:00
Consume SDK migration changes
This commit is contained in:
@@ -384,8 +384,6 @@ export class Cipher extends Domain implements Decryptable<CipherView> {
|
||||
// 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:
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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<any> {
|
||||
async replace(ciphers: { [id: string]: CipherData }, userId: UserId): Promise<void> {
|
||||
// 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<CipherId, CipherData> = migratedCiphers.reduce(
|
||||
(acc, c) => ({ ...acc, [c.id as CipherId]: c.toCipherData() }),
|
||||
{} as Record<CipherId, CipherData>,
|
||||
);
|
||||
|
||||
await this.updateEncryptedCipherState(() => resultCiphers, userId);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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}`);
|
||||
|
||||
Reference in New Issue
Block a user