1
0
mirror of https://github.com/bitwarden/browser synced 2026-01-01 08:03:20 +00:00

[PM-13723] track history in generator components (#11673)

* add history support to generator components
* increase generator history length
This commit is contained in:
✨ Audrey ✨
2024-10-23 15:38:26 -04:00
committed by GitHub
parent a2a15d42d5
commit d5643f42b3
6 changed files with 63 additions and 10 deletions

View File

@@ -1,6 +1,6 @@
import { Jsonify } from "type-fest";
import { GeneratorCategory } from "./options";
import { CredentialAlgorithm } from "@bitwarden/generator-core";
/** A credential generation result */
export class GeneratedCredential {
@@ -14,7 +14,7 @@ export class GeneratedCredential {
*/
constructor(
readonly credential: string,
readonly category: GeneratorCategory,
readonly category: CredentialAlgorithm,
generationDate: Date | number,
) {
if (typeof generationDate === "number") {

View File

@@ -1,9 +1,9 @@
import { Observable } from "rxjs";
import { UserId } from "@bitwarden/common/types/guid";
import { CredentialAlgorithm } from "@bitwarden/generator-core";
import { GeneratedCredential } from "./generated-credential";
import { GeneratorCategory } from "./options";
/** Tracks the history of password generations.
* Each user gets their own store.
@@ -27,7 +27,7 @@ export abstract class GeneratorHistoryService {
track: (
userId: UserId,
credential: string,
category: GeneratorCategory,
category: CredentialAlgorithm,
date?: Date,
) => Promise<GeneratedCredential | null>;

View File

@@ -8,12 +8,13 @@ import { PaddedDataPacker } from "@bitwarden/common/tools/state/padded-data-pack
import { SecretState } from "@bitwarden/common/tools/state/secret-state";
import { UserKeyEncryptor } from "@bitwarden/common/tools/state/user-key-encryptor";
import { UserId } from "@bitwarden/common/types/guid";
import { CredentialAlgorithm } from "@bitwarden/generator-core";
import { GeneratedCredential } from "./generated-credential";
import { GeneratorHistoryService } from "./generator-history.abstraction";
import { GENERATOR_HISTORY, GENERATOR_HISTORY_BUFFER } from "./key-definitions";
import { LegacyPasswordHistoryDecryptor } from "./legacy-password-history-decryptor";
import { GeneratorCategory, HistoryServiceOptions } from "./options";
import { HistoryServiceOptions } from "./options";
const OPTIONS_FRAME_SIZE = 2048;
@@ -25,7 +26,7 @@ export class LocalGeneratorHistoryService extends GeneratorHistoryService {
private readonly encryptService: EncryptService,
private readonly keyService: CryptoService,
private readonly stateProvider: StateProvider,
private readonly options: HistoryServiceOptions = { maxTotal: 100 },
private readonly options: HistoryServiceOptions = { maxTotal: 200 },
) {
super();
}
@@ -33,7 +34,12 @@ export class LocalGeneratorHistoryService extends GeneratorHistoryService {
private _credentialStates = new Map<UserId, SingleUserState<GeneratedCredential[]>>();
/** {@link GeneratorHistoryService.track} */
track = async (userId: UserId, credential: string, category: GeneratorCategory, date?: Date) => {
track = async (
userId: UserId,
credential: string,
category: CredentialAlgorithm,
date?: Date,
) => {
const state = this.getCredentialState(userId);
let result: GeneratedCredential = null;