mirror of
https://github.com/bitwarden/browser.git
synced 2025-03-01 03:31:15 +01:00
[PM-14838] upgrade generator account storage to ObjectKey storage (#11975)
This commit is contained in:
parent
a08c9776cb
commit
642b8d2e6b
@ -24,11 +24,6 @@ import {
|
||||
} from "../policies";
|
||||
import { CatchallConstraints } from "../policies/catchall-constraints";
|
||||
import { SubaddressConstraints } from "../policies/subaddress-constraints";
|
||||
import {
|
||||
EFF_USERNAME_SETTINGS,
|
||||
PASSPHRASE_SETTINGS,
|
||||
PASSWORD_SETTINGS,
|
||||
} from "../strategies/storage";
|
||||
import {
|
||||
CatchallGenerationOptions,
|
||||
CredentialGenerator,
|
||||
@ -51,7 +46,10 @@ import { DefaultPasswordBoundaries } from "./default-password-boundaries";
|
||||
import { DefaultPasswordGenerationOptions } from "./default-password-generation-options";
|
||||
import { DefaultSubaddressOptions } from "./default-subaddress-generator-options";
|
||||
|
||||
const PASSPHRASE = Object.freeze({
|
||||
const PASSPHRASE: CredentialGeneratorConfiguration<
|
||||
PassphraseGenerationOptions,
|
||||
PassphraseGeneratorPolicy
|
||||
> = Object.freeze({
|
||||
id: "passphrase",
|
||||
category: "password",
|
||||
nameKey: "passphrase",
|
||||
@ -76,7 +74,23 @@ const PASSPHRASE = Object.freeze({
|
||||
},
|
||||
wordSeparator: { maxLength: 1 },
|
||||
},
|
||||
account: PASSPHRASE_SETTINGS,
|
||||
account: {
|
||||
key: "passphraseGeneratorSettings",
|
||||
target: "object",
|
||||
format: "plain",
|
||||
classifier: new PublicClassifier<PassphraseGenerationOptions>([
|
||||
"numWords",
|
||||
"wordSeparator",
|
||||
"capitalize",
|
||||
"includeNumber",
|
||||
]),
|
||||
state: GENERATOR_DISK,
|
||||
initial: DefaultPassphraseGenerationOptions,
|
||||
options: {
|
||||
deserializer: (value) => value,
|
||||
clearOn: ["logout"],
|
||||
},
|
||||
} satisfies ObjectKey<PassphraseGenerationOptions>,
|
||||
},
|
||||
policy: {
|
||||
type: PolicyType.PasswordGenerator,
|
||||
@ -89,12 +103,12 @@ const PASSPHRASE = Object.freeze({
|
||||
createEvaluator: (policy) => new PassphraseGeneratorOptionsEvaluator(policy),
|
||||
toConstraints: (policy) => new PassphrasePolicyConstraints(policy),
|
||||
},
|
||||
} satisfies CredentialGeneratorConfiguration<
|
||||
PassphraseGenerationOptions,
|
||||
PassphraseGeneratorPolicy
|
||||
>);
|
||||
});
|
||||
|
||||
const PASSWORD = Object.freeze({
|
||||
const PASSWORD: CredentialGeneratorConfiguration<
|
||||
PasswordGenerationOptions,
|
||||
PasswordGeneratorPolicy
|
||||
> = Object.freeze({
|
||||
id: "password",
|
||||
category: "password",
|
||||
nameKey: "password",
|
||||
@ -126,7 +140,29 @@ const PASSWORD = Object.freeze({
|
||||
max: DefaultPasswordBoundaries.minSpecialCharacters.max,
|
||||
},
|
||||
},
|
||||
account: PASSWORD_SETTINGS,
|
||||
account: {
|
||||
key: "passwordGeneratorSettings",
|
||||
target: "object",
|
||||
format: "plain",
|
||||
classifier: new PublicClassifier<PasswordGenerationOptions>([
|
||||
"length",
|
||||
"ambiguous",
|
||||
"uppercase",
|
||||
"minUppercase",
|
||||
"lowercase",
|
||||
"minLowercase",
|
||||
"number",
|
||||
"minNumber",
|
||||
"special",
|
||||
"minSpecial",
|
||||
]),
|
||||
state: GENERATOR_DISK,
|
||||
initial: DefaultPasswordGenerationOptions,
|
||||
options: {
|
||||
deserializer: (value) => value,
|
||||
clearOn: ["logout"],
|
||||
},
|
||||
} satisfies ObjectKey<PasswordGenerationOptions>,
|
||||
},
|
||||
policy: {
|
||||
type: PolicyType.PasswordGenerator,
|
||||
@ -143,43 +179,58 @@ const PASSWORD = Object.freeze({
|
||||
createEvaluator: (policy) => new PasswordGeneratorOptionsEvaluator(policy),
|
||||
toConstraints: (policy) => new DynamicPasswordPolicyConstraints(policy),
|
||||
},
|
||||
} satisfies CredentialGeneratorConfiguration<PasswordGenerationOptions, PasswordGeneratorPolicy>);
|
||||
});
|
||||
|
||||
const USERNAME = Object.freeze({
|
||||
id: "username",
|
||||
category: "username",
|
||||
nameKey: "randomWord",
|
||||
generateKey: "generateUsername",
|
||||
generatedValueKey: "username",
|
||||
copyKey: "copyUsername",
|
||||
onlyOnRequest: false,
|
||||
request: [],
|
||||
engine: {
|
||||
create(
|
||||
dependencies: GeneratorDependencyProvider,
|
||||
): CredentialGenerator<EffUsernameGenerationOptions> {
|
||||
return new UsernameRandomizer(dependencies.randomizer);
|
||||
const USERNAME: CredentialGeneratorConfiguration<EffUsernameGenerationOptions, NoPolicy> =
|
||||
Object.freeze({
|
||||
id: "username",
|
||||
category: "username",
|
||||
nameKey: "randomWord",
|
||||
generateKey: "generateUsername",
|
||||
generatedValueKey: "username",
|
||||
copyKey: "copyUsername",
|
||||
onlyOnRequest: false,
|
||||
request: [],
|
||||
engine: {
|
||||
create(
|
||||
dependencies: GeneratorDependencyProvider,
|
||||
): CredentialGenerator<EffUsernameGenerationOptions> {
|
||||
return new UsernameRandomizer(dependencies.randomizer);
|
||||
},
|
||||
},
|
||||
},
|
||||
settings: {
|
||||
initial: DefaultEffUsernameOptions,
|
||||
constraints: {},
|
||||
account: EFF_USERNAME_SETTINGS,
|
||||
},
|
||||
policy: {
|
||||
type: PolicyType.PasswordGenerator,
|
||||
disabledValue: {},
|
||||
combine(_acc: NoPolicy, _policy: Policy) {
|
||||
return {};
|
||||
settings: {
|
||||
initial: DefaultEffUsernameOptions,
|
||||
constraints: {},
|
||||
account: {
|
||||
key: "effUsernameGeneratorSettings",
|
||||
target: "object",
|
||||
format: "plain",
|
||||
classifier: new PublicClassifier<EffUsernameGenerationOptions>([
|
||||
"wordCapitalize",
|
||||
"wordIncludeNumber",
|
||||
]),
|
||||
state: GENERATOR_DISK,
|
||||
initial: DefaultEffUsernameOptions,
|
||||
options: {
|
||||
deserializer: (value) => value,
|
||||
clearOn: ["logout"],
|
||||
},
|
||||
} satisfies ObjectKey<EffUsernameGenerationOptions>,
|
||||
},
|
||||
createEvaluator(_policy: NoPolicy) {
|
||||
return new DefaultPolicyEvaluator<EffUsernameGenerationOptions>();
|
||||
policy: {
|
||||
type: PolicyType.PasswordGenerator,
|
||||
disabledValue: {},
|
||||
combine(_acc: NoPolicy, _policy: Policy) {
|
||||
return {};
|
||||
},
|
||||
createEvaluator(_policy: NoPolicy) {
|
||||
return new DefaultPolicyEvaluator<EffUsernameGenerationOptions>();
|
||||
},
|
||||
toConstraints(_policy: NoPolicy) {
|
||||
return new IdentityConstraint<EffUsernameGenerationOptions>();
|
||||
},
|
||||
},
|
||||
toConstraints(_policy: NoPolicy) {
|
||||
return new IdentityConstraint<EffUsernameGenerationOptions>();
|
||||
},
|
||||
},
|
||||
} satisfies CredentialGeneratorConfiguration<EffUsernameGenerationOptions, NoPolicy>);
|
||||
});
|
||||
|
||||
const CATCHALL: CredentialGeneratorConfiguration<CatchallGenerationOptions, NoPolicy> =
|
||||
Object.freeze({
|
||||
|
Loading…
Reference in New Issue
Block a user