From 25bdae9c519c8b97559c64c7ca97272bb9e6b5d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=9C=A8=20Audrey=20=E2=9C=A8?= Date: Wed, 15 Jan 2025 14:23:44 -0500 Subject: [PATCH] resolve strict typecheck errors --- libs/common/src/tools/extension.ts | 9 --------- .../tools/generator/core/src/metadata/data.ts | 2 +- .../core/src/metadata/email/catchall.ts | 4 ++-- .../core/src/metadata/email/plus-address.ts | 2 +- .../src/metadata/password/random-password.ts | 10 +++++----- .../src/metadata/username/eff-word-list.ts | 2 +- .../src/types/password-generation-options.ts | 20 +++++++++---------- libs/tools/generator/core/src/util.ts | 20 ------------------- 8 files changed, 20 insertions(+), 49 deletions(-) delete mode 100644 libs/common/src/tools/extension.ts diff --git a/libs/common/src/tools/extension.ts b/libs/common/src/tools/extension.ts deleted file mode 100644 index f7eb96e43c8..00000000000 --- a/libs/common/src/tools/extension.ts +++ /dev/null @@ -1,9 +0,0 @@ -// FIXME: delete this file once extension types merge into `main` - -import { Opaque } from "type-fest"; - -/** @deprecated this is a stub for the real SiteId type */ -export type SiteId = "forwarder"; - -/** @deprecated this is a stub for the real VendorId type */ -export type VendorId = Opaque<"vendorId", string>; diff --git a/libs/tools/generator/core/src/metadata/data.ts b/libs/tools/generator/core/src/metadata/data.ts index c84fce271ad..2b9dad50557 100644 --- a/libs/tools/generator/core/src/metadata/data.ts +++ b/libs/tools/generator/core/src/metadata/data.ts @@ -1,4 +1,4 @@ -import { deepFreeze } from "../util"; +import { deepFreeze } from "@bitwarden/common/tools/util"; /** algorithms for generating credentials */ export const Algorithm = Object.freeze({ diff --git a/libs/tools/generator/core/src/metadata/email/catchall.ts b/libs/tools/generator/core/src/metadata/email/catchall.ts index bd018a54dc3..2005651ddc0 100644 --- a/libs/tools/generator/core/src/metadata/email/catchall.ts +++ b/libs/tools/generator/core/src/metadata/email/catchall.ts @@ -1,5 +1,6 @@ import { GENERATOR_DISK } from "@bitwarden/common/platform/state"; import { PublicClassifier } from "@bitwarden/common/tools/public-classifier"; +import { deepFreeze } from "@bitwarden/common/tools/util"; import { EmailRandomizer } from "../../engine"; import { CatchallConstraints } from "../../policies/catchall-constraints"; @@ -8,7 +9,6 @@ import { CredentialGenerator, GeneratorDependencyProvider, } from "../../types"; -import { deepFreeze } from "../../util"; import { Algorithm, Type, Profile } from "../data"; import { GeneratorMetadata } from "../generator-metadata"; @@ -58,7 +58,7 @@ const catchall: GeneratorMetadata = deepFreeze({ constraints: { default: { catchallDomain: { minLength: 1 } }, create(_policies, context) { - return new CatchallConstraints(context.email); + return new CatchallConstraints(context.email ?? ""); }, }, }, diff --git a/libs/tools/generator/core/src/metadata/email/plus-address.ts b/libs/tools/generator/core/src/metadata/email/plus-address.ts index 8895c747fb9..98c04e1b8f8 100644 --- a/libs/tools/generator/core/src/metadata/email/plus-address.ts +++ b/libs/tools/generator/core/src/metadata/email/plus-address.ts @@ -1,5 +1,6 @@ import { GENERATOR_DISK } from "@bitwarden/common/platform/state"; import { PublicClassifier } from "@bitwarden/common/tools/public-classifier"; +import { deepFreeze } from "@bitwarden/common/tools/util"; import { EmailRandomizer } from "../../engine"; import { SubaddressConstraints } from "../../policies/subaddress-constraints"; @@ -8,7 +9,6 @@ import { GeneratorDependencyProvider, SubaddressGenerationOptions, } from "../../types"; -import { deepFreeze } from "../../util"; import { Algorithm, Profile, Type } from "../data"; import { GeneratorMetadata } from "../generator-metadata"; diff --git a/libs/tools/generator/core/src/metadata/password/random-password.ts b/libs/tools/generator/core/src/metadata/password/random-password.ts index fb02c13949d..a154e687f99 100644 --- a/libs/tools/generator/core/src/metadata/password/random-password.ts +++ b/libs/tools/generator/core/src/metadata/password/random-password.ts @@ -1,19 +1,19 @@ import { PolicyType } from "@bitwarden/common/admin-console/enums"; import { GENERATOR_DISK } from "@bitwarden/common/platform/state"; import { PublicClassifier } from "@bitwarden/common/tools/public-classifier"; +import { deepFreeze } from "@bitwarden/common/tools/util"; import { PasswordRandomizer } from "../../engine"; import { DynamicPasswordPolicyConstraints, passwordLeastPrivilege } from "../../policies"; import { CredentialGenerator, GeneratorDependencyProvider, - PasswordGenerationOptions, + PasswordGeneratorSettings, } from "../../types"; -import { deepFreeze } from "../../util"; import { Algorithm, Profile, Type } from "../data"; import { GeneratorMetadata } from "../generator-metadata"; -const password: GeneratorMetadata = deepFreeze({ +const password: GeneratorMetadata = deepFreeze({ id: Algorithm.password, category: Type.password, weight: 100, @@ -30,7 +30,7 @@ const password: GeneratorMetadata = deepFreeze({ engine: { create( dependencies: GeneratorDependencyProvider, - ): CredentialGenerator { + ): CredentialGenerator { return new PasswordRandomizer(dependencies.randomizer); }, }, @@ -41,7 +41,7 @@ const password: GeneratorMetadata = deepFreeze({ key: "passwordGeneratorSettings", target: "object", format: "plain", - classifier: new PublicClassifier([ + classifier: new PublicClassifier([ "length", "ambiguous", "uppercase", diff --git a/libs/tools/generator/core/src/metadata/username/eff-word-list.ts b/libs/tools/generator/core/src/metadata/username/eff-word-list.ts index 50dabc966fb..f8cb1432f10 100644 --- a/libs/tools/generator/core/src/metadata/username/eff-word-list.ts +++ b/libs/tools/generator/core/src/metadata/username/eff-word-list.ts @@ -1,6 +1,7 @@ import { GENERATOR_DISK } from "@bitwarden/common/platform/state"; import { PublicClassifier } from "@bitwarden/common/tools/public-classifier"; import { IdentityConstraint } from "@bitwarden/common/tools/state/identity-state-constraint"; +import { deepFreeze } from "@bitwarden/common/tools/util"; import { UsernameRandomizer } from "../../engine"; import { @@ -8,7 +9,6 @@ import { EffUsernameGenerationOptions, GeneratorDependencyProvider, } from "../../types"; -import { deepFreeze } from "../../util"; import { Algorithm, Profile, Type } from "../data"; import { GeneratorMetadata } from "../generator-metadata"; diff --git a/libs/tools/generator/core/src/types/password-generation-options.ts b/libs/tools/generator/core/src/types/password-generation-options.ts index 76e8827d4de..7a8a538c409 100644 --- a/libs/tools/generator/core/src/types/password-generation-options.ts +++ b/libs/tools/generator/core/src/types/password-generation-options.ts @@ -2,58 +2,58 @@ */ export type PasswordGeneratorSettings = { /** The length of the password selected by the user */ - length: number; + length?: number; /** `true` when ambiguous characters may be included in the output. * `false` when ambiguous characters should not be included in the output. */ - ambiguous: boolean; + ambiguous?: boolean; /** `true` when uppercase ASCII characters should be included in the output * This value defaults to `false. */ - uppercase: boolean; + uppercase?: boolean; /** The minimum number of uppercase characters to include in the output. * The value is ignored when `uppercase` is `false`. * The value defaults to 1 when `uppercase` is `true`. */ - minUppercase: number; + minUppercase?: number; /** `true` when lowercase ASCII characters should be included in the output. * This value defaults to `false`. */ - lowercase: boolean; + lowercase?: boolean; /** The minimum number of lowercase characters to include in the output. * The value defaults to 1 when `lowercase` is `true`. * The value defaults to 0 when `lowercase` is `false`. */ - minLowercase: number; + minLowercase?: number; /** Whether or not to include ASCII digits in the output * This value defaults to `true` when `minNumber` is at least 1. * This value defaults to `false` when `minNumber` is less than 1. */ - number: boolean; + number?: boolean; /** The minimum number of digits to include in the output. * The value defaults to 1 when `number` is `true`. * The value defaults to 0 when `number` is `false`. */ - minNumber: number; + minNumber?: number; /** Whether or not to include special characters in the output. * This value defaults to `true` when `minSpecial` is at least 1. * This value defaults to `false` when `minSpecial` is less than 1. */ - special: boolean; + special?: boolean; /** The minimum number of special characters to include in the output. * This value defaults to 1 when `special` is `true`. * This value defaults to 0 when `special` is `false`. */ - minSpecial: number; + minSpecial?: number; }; /** Request format for password credential generation. diff --git a/libs/tools/generator/core/src/util.ts b/libs/tools/generator/core/src/util.ts index 588a6e00134..98c2e8ab283 100644 --- a/libs/tools/generator/core/src/util.ts +++ b/libs/tools/generator/core/src/util.ts @@ -135,23 +135,3 @@ export function optionsToEffWordListRequest(options: PassphraseGenerationOptions return request; } - -/** Recursively freeze an object's own keys - * @param value the value to freeze - * @returns `value` - * @remarks this function is derived from MDN's `deepFreeze`, which - * has been committed to the public domain. - */ -export function deepFreeze(value: T): Readonly { - const keys = Reflect.ownKeys(value) as (keyof T)[]; - - for (const key of keys) { - const own = value[key]; - - if ((own && typeof own === "object") || typeof own === "function") { - deepFreeze(own); - } - } - - return Object.freeze(value); -}