mirror of
https://github.com/bitwarden/browser
synced 2025-12-15 07:43:35 +00:00
* introduce extension service * deprecate legacy forwarder types * eliminate repeat algorithm emissions * extend logging to preference management * align forwarder ids with vendor ids * fix duplicate policy emissions; debugging required logger enhancements ----- Co-authored-by: Daniel James Smith <2670567+djsmith85@users.noreply.github.com>
44 lines
1.5 KiB
TypeScript
44 lines
1.5 KiB
TypeScript
// FIXME: Update this file to be type safe and remove this and next line
|
|
// @ts-strict-ignore
|
|
import { PolicyType } from "@bitwarden/common/admin-console/enums";
|
|
// FIXME: use index.ts imports once policy abstractions and models
|
|
// implement ADR-0002
|
|
import { Policy } from "@bitwarden/common/admin-console/models/domain/policy";
|
|
import { PasswordAlgorithm } from "@bitwarden/generator-core";
|
|
|
|
/** Policy settings affecting password generator navigation */
|
|
export type GeneratorNavigationPolicy = {
|
|
/** The type of generator that should be shown by default when opening
|
|
* the password generator.
|
|
*/
|
|
overridePasswordType?: PasswordAlgorithm;
|
|
};
|
|
|
|
/** Reduces a policy into an accumulator by preferring the password generator
|
|
* type to other generator types.
|
|
* @param acc the accumulator
|
|
* @param policy the policy to reduce
|
|
* @returns the resulting `GeneratorNavigationPolicy`
|
|
*/
|
|
export function preferPassword(
|
|
acc: GeneratorNavigationPolicy,
|
|
policy: Policy,
|
|
): GeneratorNavigationPolicy {
|
|
const isEnabled = policy.type === PolicyType.PasswordGenerator && policy.enabled;
|
|
if (!isEnabled) {
|
|
return acc;
|
|
}
|
|
|
|
const isOverridable = acc.overridePasswordType !== "password" && policy.data.overridePasswordType;
|
|
const result = isOverridable
|
|
? { ...acc, overridePasswordType: policy.data.overridePasswordType }
|
|
: acc;
|
|
|
|
return result;
|
|
}
|
|
|
|
/** The default options for password generation policy. */
|
|
export const DisabledGeneratorNavigationPolicy: GeneratorNavigationPolicy = Object.freeze({
|
|
overridePasswordType: null,
|
|
});
|