diff --git a/.yarn/cache/regtech-regex-https-a164486eab-3af6fd0028.zip b/.yarn/cache/regtech-regex-https-a164486eab-3af6fd0028.zip new file mode 100644 index 000000000..d140f33c9 Binary files /dev/null and b/.yarn/cache/regtech-regex-https-a164486eab-3af6fd0028.zip differ diff --git a/.yarn/cache/typescript-npm-5.7.2-b1f84a8b28-b55300c4ce.zip b/.yarn/cache/typescript-npm-5.7.2-b1f84a8b28-b55300c4ce.zip new file mode 100644 index 000000000..6ecfd3c30 Binary files /dev/null and b/.yarn/cache/typescript-npm-5.7.2-b1f84a8b28-b55300c4ce.zip differ diff --git a/.yarn/cache/typescript-patch-03f44d9cea-803430c6da.zip b/.yarn/cache/typescript-patch-03f44d9cea-803430c6da.zip new file mode 100644 index 000000000..37d7d6998 Binary files /dev/null and b/.yarn/cache/typescript-patch-03f44d9cea-803430c6da.zip differ diff --git a/.yarn/cache/yaml-npm-2.6.1-eb747069e9-5cf2627f12.zip b/.yarn/cache/yaml-npm-2.6.1-eb747069e9-5cf2627f12.zip new file mode 100644 index 000000000..ef5bea162 Binary files /dev/null and b/.yarn/cache/yaml-npm-2.6.1-eb747069e9-5cf2627f12.zip differ diff --git a/package.json b/package.json index bc01e1863..b5b7aa89f 100644 --- a/package.json +++ b/package.json @@ -58,6 +58,7 @@ "react-router-dom": "^6.11.1", "react-scroll": "^1.8.9", "react-select": "^5.7.4", + "regtech-regex": "https://github.com/cfpb/regtech-regex", "vite-plugin-svgr": "^3.2.0", "zod": "^3.22.0", "zustand": "^4.4.1" diff --git a/src/types/formTypes.ts b/src/types/formTypes.ts index 2b6592791..c9e8bfb55 100644 --- a/src/types/formTypes.ts +++ b/src/types/formTypes.ts @@ -12,6 +12,8 @@ import { } from 'utils/constants'; import { z } from 'zod'; +import RegtechRegex from 'regtech-regex'; + // Used in react-select format (potentially can be removed) const financialInstitutionsSchema = z.object({ label: z.string(), @@ -31,7 +33,7 @@ export const domainSchema = z.object({ export const taxIdSchema = z .string() .trim() - .regex(/^(\d{2}-\d{7})$/, { + .regex(new RegExp(RegtechRegex.tin.regex), { message: IdZodSchemaErrors.taxIdSchemaRegex, }); @@ -49,7 +51,7 @@ export const institutionDetailsApiTypeSchema = z.object({ .min(One, { message: IdZodSchemaErrors.financialInstitutionLeiMin, }) - .regex(/([\dA-Z]{20})/, { + .regex(new RegExp(RegtechRegex.lei.regex), { message: IdZodSchemaErrors.financialInstitutionLeiRegex, }), name: z.string().trim(), @@ -58,10 +60,15 @@ export const institutionDetailsApiTypeSchema = z.object({ tax_id: taxIdSchema, rssd_id: z .union([ + z.string().trim().regex(/^$/, { + message: IdZodSchemaErrors.rssd_idRegex, + }), z.number({ invalid_type_error: IdZodSchemaErrors.rssd_idNumber, }), - z.string().regex(/^\d+$|^$/, { message: IdZodSchemaErrors.rssd_idRegex }), + z.string().regex(new RegExp(RegtechRegex.rssd_id.regex), { + message: IdZodSchemaErrors.rssd_idRegex, + }), ]) .optional(), primary_federal_regulator: z.object({ @@ -98,7 +105,7 @@ export const institutionDetailsApiTypeSchema = z.object({ parent_lei: z .string() .trim() - .regex(/([\dA-Z]{20})/, { + .regex(new RegExp(RegtechRegex.lei.regex), { message: IdZodSchemaErrors.financialInstitutionParentLeiRegex, }) .nullable() @@ -106,18 +113,21 @@ export const institutionDetailsApiTypeSchema = z.object({ parent_legal_name: z.string().nullable(), parent_rssd_id: z .union([ + z.string().trim().regex(/^$/, { + message: IdZodSchemaErrors.parent_rssd_idRegex, + }), z.number({ invalid_type_error: IdZodSchemaErrors.parent_rssd_idNumber, }), - z - .string() - .regex(/^\d+$|^$/, { message: IdZodSchemaErrors.parent_rssd_idRegex }), + z.string().regex(new RegExp(RegtechRegex.rssd_id.regex), { + message: IdZodSchemaErrors.parent_rssd_idRegex, + }), ]) .optional(), top_holder_lei: z .string() .trim() - .regex(/([\dA-Z]{20})/, { + .regex(new RegExp(RegtechRegex.lei.regex), { message: IdZodSchemaErrors.financialInstitutionTopHolderLeiRegex, }) .nullable() @@ -125,10 +135,13 @@ export const institutionDetailsApiTypeSchema = z.object({ top_holder_legal_name: z.string().nullable(), top_holder_rssd_id: z .union([ + z.string().trim().regex(/^$/, { + message: IdZodSchemaErrors.top_holder_rssd_idRegex, + }), z.number({ invalid_type_error: IdZodSchemaErrors.top_holder_rssd_idNumber, }), - z.string().regex(/^\d+$|^$/, { + z.string().regex(new RegExp(RegtechRegex.rssd_id.regex), { message: IdZodSchemaErrors.top_holder_rssd_idRegex, }), ]) @@ -325,16 +338,6 @@ const internationalPhoneNumberRegex = // "Must in '+(999)-999-9999' format", -// eslint-disable-next-line unicorn/no-unsafe-regex -const usPhoneNumberRegex = /^(\+\d{1,2}\s)?\(?\d{3}\)?[\s.-]\d{3}[\s.-]\d{4}$/; - -/* US Phone Number - Matches the following regex patterns */ -// 123-456-7890 -// (123) 456-7890 -// 123 456 7890 -// 123.456.7890 -// +91 (123) 456-7890 - // Regular ZIP code regex // eslint-disable-next-line unicorn/no-unsafe-regex, @typescript-eslint/no-unused-vars const zipCodeRegex = /^\d{5}(?:[\s-]\d{4})?$/; @@ -375,7 +378,7 @@ export const pointOfContactSchema = z.object({ .min(One, { message: PocZodSchemaErrors.phoneMin, }) - .regex(usPhoneNumberRegex, { + .regex(new RegExp(RegtechRegex.simple_us_phone_number.regex), { message: PocZodSchemaErrors.phoneRegex, }), phoneExtension: z diff --git a/yarn.lock b/yarn.lock index 839d40b95..c64e3c335 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4653,6 +4653,7 @@ __metadata: react-router-dom: ^6.11.1 react-scroll: ^1.8.9 react-select: ^5.7.4 + regtech-regex: "https://github.com/cfpb/regtech-regex" start-server-and-test: ^2.0.3 stylelint: 15.6.1 stylelint-config-prettier: 9.0.5 @@ -10993,6 +10994,16 @@ display-element-css@cfpb/storybook-addon-display-element-css: languageName: node linkType: hard +"regtech-regex@https://github.com/cfpb/regtech-regex": + version: 1.1.0 + resolution: "regtech-regex@https://github.com/cfpb/regtech-regex.git#commit=311d50161292d3443a63e25b79c4be2e4a4e77fd" + dependencies: + typescript: ^5.7.2 + yaml: ^2.6.1 + checksum: 3af6fd00288a4392373a0f225df2c9c909401ca221e959970bd5511f0fbdd72665caf4296632f85d1032234366810fda1ef33e4bb57a271792a2bf889c3d5f1c + languageName: node + linkType: hard + "remark-parse@npm:^11.0.0": version: 11.0.0 resolution: "remark-parse@npm:11.0.0" @@ -12614,6 +12625,16 @@ display-element-css@cfpb/storybook-addon-display-element-css: languageName: node linkType: hard +"typescript@npm:^5.7.2": + version: 5.7.2 + resolution: "typescript@npm:5.7.2" + bin: + tsc: bin/tsc + tsserver: bin/tsserver + checksum: b55300c4cefee8ee380d14fa9359ccb41ff8b54c719f6bc49b424899d662a5ce62ece390ce769568c7f4d14af844085255e63788740084444eb12ef423b13433 + languageName: node + linkType: hard + "typescript@patch:typescript@5.0.4#~builtin": version: 5.0.4 resolution: "typescript@patch:typescript@npm%3A5.0.4#~builtin::version=5.0.4&hash=b5f058" @@ -12624,6 +12645,16 @@ display-element-css@cfpb/storybook-addon-display-element-css: languageName: node linkType: hard +"typescript@patch:typescript@^5.7.2#~builtin": + version: 5.7.2 + resolution: "typescript@patch:typescript@npm%3A5.7.2#~builtin::version=5.7.2&hash=14eedb" + bin: + tsc: bin/tsc + tsserver: bin/tsserver + checksum: 803430c6da2ba73c25a21880d8d4f08a56d9d2444e6db2ea949ac4abceeece8e4a442b7b9b585db7d8a0b47ebda2060e45fe8ee8b8aca23e27ec1d4844987ee6 + languageName: node + linkType: hard + "ufo@npm:^1.3.0": version: 1.3.2 resolution: "ufo@npm:1.3.2" @@ -13890,6 +13921,15 @@ display-element-css@cfpb/storybook-addon-display-element-css: languageName: node linkType: hard +"yaml@npm:^2.6.1": + version: 2.6.1 + resolution: "yaml@npm:2.6.1" + bin: + yaml: bin.mjs + checksum: 5cf2627f121dcf04ccdebce8e6cbac7c9983d465c4eab314f6fbdc13cda8a07f4e8f9c2252a382b30bcabe05ee3c683647293afd52eb37cbcefbdc7b6ebde9ee + languageName: node + linkType: hard + "yargs-parser@npm:^20.2.3": version: 20.2.9 resolution: "yargs-parser@npm:20.2.9"