Skip to content

Commit

Permalink
Replace Applicable Zod validations with those from Regtech-Regex (#1096)
Browse files Browse the repository at this point in the history
Added dependency to regtech-regex and updated the zod stuff to use the
regexs held within.

## Changes

- Updated dependencies
- Added dependency to regtech-regex
- Updated zod validations with the regexes from regtech-regex

## How to test this PR

1. Validate that the pipeline is green
2. Pull the branch
3. Run yarn install
4. Launch the app
5. Create a new filing and validate that you are able to reach the
submission page
  • Loading branch information
tanner-ricks authored Dec 20, 2024
1 parent 367f3dd commit 806d72d
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 20 deletions.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
43 changes: 23 additions & 20 deletions src/types/formTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand All @@ -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,
});

Expand All @@ -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(),
Expand All @@ -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({
Expand Down Expand Up @@ -98,37 +105,43 @@ export const institutionDetailsApiTypeSchema = z.object({
parent_lei: z
.string()
.trim()
.regex(/([\dA-Z]{20})/, {
.regex(new RegExp(RegtechRegex.lei.regex), {
message: IdZodSchemaErrors.financialInstitutionParentLeiRegex,
})
.nullable()
.or(z.literal('')),
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()
.or(z.literal('')),
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,
}),
])
Expand Down Expand Up @@ -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})?$/;
Expand Down Expand Up @@ -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
Expand Down
40 changes: 40 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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:[email protected]#~builtin<compat/typescript>":
version: 5.0.4
resolution: "typescript@patch:typescript@npm%3A5.0.4#~builtin<compat/typescript>::version=5.0.4&hash=b5f058"
Expand All @@ -12624,6 +12645,16 @@ display-element-css@cfpb/storybook-addon-display-element-css:
languageName: node
linkType: hard

"typescript@patch:typescript@^5.7.2#~builtin<compat/typescript>":
version: 5.7.2
resolution: "typescript@patch:typescript@npm%3A5.7.2#~builtin<compat/typescript>::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"
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit 806d72d

Please sign in to comment.