mirror of
https://github.com/bitwarden/browser
synced 2025-12-06 00:13:28 +00:00
* 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`
43 lines
1.2 KiB
TypeScript
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
|
|
}
|
|
}
|