1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-06 00:13:28 +00:00
Files
browser/libs/common/src/state-migrations/migrations/64-migrate-generator-history.ts
✨ Audrey ✨ a16dc84a0a [PM-6819] Credential generator MV3 integration (#8998)
* replace `PasswordGeneratorService` with `legacyPasswordGenerationServiceFactory`
* replace `UsernameGeneratorService` with `legacyUsernameGenerationServiceFactory`
* migrate generator options and history
* apply policy immediately once available
* suppress duplicate policy emissions
* run password generation response code in `ngZone`
2024-05-20 18:08:49 +01:00

43 lines
1.2 KiB
TypeScript

import { KeyDefinitionLike, MigrationHelper } from "../migration-helper";
import { Migrator } from "../migrator";
/** settings targeted by migrator */
export type AccountType = {
data?: {
passwordGenerationHistory?: {
encrypted: EncryptedHistory;
};
};
};
/** the actual data stored in the history is opaque to the migrator */
export type EncryptedHistory = Array<unknown>;
export const HISTORY: KeyDefinitionLike = {
stateDefinition: {
name: "generator",
},
key: "localGeneratorHistoryBuffer",
};
export class GeneratorHistoryMigrator extends Migrator<63, 64> {
async migrate(helper: MigrationHelper): Promise<void> {
const accounts = await helper.getAccounts<AccountType>();
async function migrateAccount(userId: string, account: AccountType) {
const data = account?.data?.passwordGenerationHistory;
if (data && data.encrypted) {
await helper.setToUser(userId, HISTORY, data.encrypted);
delete account.data.passwordGenerationHistory;
await helper.set(userId, account);
}
}
await Promise.all([...accounts.map(({ userId, account }) => migrateAccount(userId, account))]);
}
async rollback(helper: MigrationHelper): Promise<void> {
// not supported
}
}