Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Regtech Regex Support to Node Environments #22

Merged
merged 8 commits into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

## Checklist

- [ ] If changes were made to validations.yaml, make sure that yarn build has been run and the results committed
tanner-ricks marked this conversation as resolved.
Show resolved Hide resolved
- [ ] PR has an informative and human-readable title
- [ ] Changes are limited to a single goal (no scope creep)
- [ ] Code can be automatically merged (no conflicts)
tanner-ricks marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,5 @@ node_modules/
bower_components/
.grunt/
src/vendor/
dist/
dist/
!node/dist/
15 changes: 15 additions & 0 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
compressionLevel: mixed

enableGlobalCache: false

enableHardenedMode: true

enableMirror: true

enableOfflineMode: true

enableTelemetry: false

nodeLinker: node-modules

yarnPath: .yarn/releases/yarn-4.2.1.cjs
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,10 @@ We follow the [Semantic Versioning 2.0.0](http://semver.org/) format.
### Added

- Initial release of validations.yaml

## 1.1.0 - 2024-12-12

### Added

- Added yaml to json parsing and conversion
- Added support for being a dependency in other node based projects
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,21 @@ which is then converted into a data class for use by clients of the library.

See the src/python/README.md for information on dependencies, installation and usage.

### Node
A Node project has been defined in package.json, as well as the source under src/node.

See the src/node/README.md for information on dependencies, installation and usage.

## Installation

Import the `validations.yaml` file using the URL or via a package manager.

### Python
See the src/python/README.md for information on dependencies, installation and usage.

### Node
See the src/node/README.md for information on dependencies, installation and usage.

## Usage

Here's an example of an entry in the `validations.yaml` file:
Expand Down Expand Up @@ -52,6 +60,9 @@ Each entry should have the following properties:
### Python
See the src/python/README.md for information on dependencies, installation and usage.

### Node
See the src/node/README.md for information on dependencies, installation and usage.

## Getting help

If you have questions, concerns, bug reports, etc, please file an issue in this repository's Issue Tracker.
Expand Down
40 changes: 39 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,43 @@
"name": "regtech-regex",
"license": "MIT",
"private": true,
"version": "1.0.0"
"version": "1.1.0",
"types": "./src/node/dist/index.d.ts",
"type": "module",
"exports": {
".": {
"require": "./src/node/dist/regtech-regex.cjs",
"import": "./src/node/dist/regtech-regex.es.js"
},
"./validations.yaml": {
"require": "./src/validations.yaml",
"import": "./src/validations.yaml"
},
"./validations.json": {
"require": "./src/validations.json",
"import": "./src/validations.json"
}
},
"files": [
"src/node/dist",
"src/validations.yaml",
"src/validations.json"
],
"engines": {
"node": ">=22"
},
"scripts": {
"build": "node src/node/build.js ; vite build"
},
"dependencies": {
"typescript": "^5.7.2",
"yaml": "^2.6.1"
},
"devDependencies": {
"@types/node": "^20.10.1",
"vite": "3.2.10",
"vite-plugin-dts": "^2.2.0",
"vite-tsconfig-paths": "3.5.2"
},
"packageManager": "yarn@4.2.1"
}
40 changes: 40 additions & 0 deletions src/node/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# regtech_regex

Node project to provide a reusable node module to other node projects dependent on these regex's for validation of data.

## Installation

Until we start publishing to npm, install this github repo:

```
yarn add cfpb/design-system-react
```

If you're using yarn v2 or greater, [`yarn pack`](https://yarnpkg.com/advanced/lifecycle-scripts) will automatically build the package for you after it's installed.

## Usage

```ts
import type { RegtechRegexConfigs } from 'regtech-regex';
import validations from 'regtech-regex';

console.log(validations as RegtechRegexConfigs);

```

## Development

To persist changes made to validations.yaml:

1. Install Node v22+.
1. Enable [corepack](https://yarnpkg.com/getting-started/install): `corepack enable`.
1. `yarn`
1. `yarn build`

Note: This project uses yarn v3.5 in "plug n play" mode. There is no `node_modules/` directory. Packages are stored in `.yarn/cache/`.

## Open source licensing info

1. [TERMS](TERMS.md)
2. [LICENSE](LICENSE)
3. [CFPB Source Code Policy](https://github.com/cfpb/source-code-policy/)
8 changes: 8 additions & 0 deletions src/node/build.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { parse as yamlParse } from "yaml";
import * as fs from 'fs';
import * as path from "path";

const __dirname = path.dirname(path.resolve('./package.json'));
const content = fs.readFileSync(path.resolve('src/validations.yaml'), {encoding: "utf8"});
const configs = yamlParse(content);
fs.writeFileSync(path.join(__dirname, '/src/validations.json'), JSON.stringify(configs, null, "\t"));
13 changes: 13 additions & 0 deletions src/node/dist/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
export type RegtechRegexNames = "email" | "lei" | "rssd_id" | "simple_us_phone_number" | "tin";
export type RegtechRegexConfigs = Record<RegtechRegexNames, RegtechRegexConfig>;
export type RegtechRegexConfig = {
description: string;
error_text: string;
regex: string;
examples?: string[];
link?: string;
references?: string[];
};
export declare const RegtechRegex: RegtechRegexConfigs;
declare const _default: RegtechRegexConfigs;
export default _default;
1 change: 1 addition & 0 deletions src/node/dist/regtech-regex.cjs.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

62 changes: 62 additions & 0 deletions src/node/dist/regtech-regex.es.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
const e = {
description: "must conform to common email conventions using the W3C method of email validation which is only a subset of full RFC 5322 compliance",
error_text: "Must be a valid email address.",
examples: [
"a-test-email-account@cfpb.gov",
"ASuperCoolEmailAccount@cfpb.gov"
],
link: "https://regex101.com/r/bUsmeo/2",
references: [
"https://html.spec.whatwg.org/multipage/input.html#email-state-(type=email)"
],
regex: "^[a-zA-Z0-9.!#$%&'*+\\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$"
}, t = {
description: "must be 18 characters that only contain A-Z and 0-9 followed by 2 digits",
error_text: "Must be a valid LEI of 20 characters that only contain A-Z and 0-9 (no special characters).",
examples: [
"123400TESTBANK000192",
"123400TESTBANK000289",
"123400TESTSUBBANK147",
"123400TESTSUBBANK244",
"TESTBANK123456789012"
],
link: "https://regex101.com/r/ItOdOj/3",
regex: "^[A-Z0-9]{18}\\d{2}$"
}, o = {
description: "must be an integer",
error_text: "Must be a number.",
examples: [
"9999",
"1"
],
link: "https://regex101.com/r/l3SyQi/3",
regex: "^\\d+$"
}, s = {
description: "must be a simple United States phone number pattern of 3 digits, followed by a hyphen, followed by 3 digits, followed by a hyphen, followed by 4 digits",
error_text: "Must be a valid phone number in the format of 555-555-5555.",
examples: [
"555-555-5555",
"555-123-4567"
],
link: "https://regex101.com/r/jt6ujJ/5",
regex: "^\\d{3}-\\d{3}-\\d{4}$"
}, i = {
description: "must be 2 digits, followed by a hyphen, followed by 7 digits",
error_text: "Must be a valid TIN in the format of 12-3456789.",
examples: [
"12-3456789",
"98-7654321"
],
link: "https://regex101.com/r/7op0LA/3",
regex: "^\\d{2}-\\d{7}$"
}, a = {
email: e,
lei: t,
rssd_id: o,
simple_us_phone_number: s,
tin: i
}, r = a;
export {
r as RegtechRegex,
a as default
};
18 changes: 18 additions & 0 deletions src/node/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import regexs from '@/validations.json';

export type RegtechRegexNames = "email" | "lei" | "rssd_id" | "simple_us_phone_number" | "tin";

export type RegtechRegexConfigs = Record<RegtechRegexNames, RegtechRegexConfig>;

export type RegtechRegexConfig = {
description: string;
error_text: string;
regex: string;
examples?: string[];
link?: string;
references?: string[];
};

export const RegtechRegex: RegtechRegexConfigs = regexs as RegtechRegexConfigs;

export default regexs as RegtechRegexConfigs;
58 changes: 58 additions & 0 deletions src/validations.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
{
"email": {
"description": "must conform to common email conventions using the W3C method of email validation which is only a subset of full RFC 5322 compliance",
"error_text": "Must be a valid email address.",
"examples": [
"a-test-email-account@cfpb.gov",
"ASuperCoolEmailAccount@cfpb.gov"
],
"link": "https://regex101.com/r/bUsmeo/2",
"references": [
"https://html.spec.whatwg.org/multipage/input.html#email-state-(type=email)"
],
"regex": "^[a-zA-Z0-9.!#$%&'*+\\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$"
},
"lei": {
"description": "must be 18 characters that only contain A-Z and 0-9 followed by 2 digits",
"error_text": "Must be a valid LEI of 20 characters that only contain A-Z and 0-9 (no special characters).",
"examples": [
"123400TESTBANK000192",
"123400TESTBANK000289",
"123400TESTSUBBANK147",
"123400TESTSUBBANK244",
"TESTBANK123456789012"
],
"link": "https://regex101.com/r/ItOdOj/3",
"regex": "^[A-Z0-9]{18}\\d{2}$"
},
"rssd_id": {
"description": "must be an integer",
"error_text": "Must be a number.",
"examples": [
"9999",
"1"
],
"link": "https://regex101.com/r/l3SyQi/3",
"regex": "^\\d+$"
},
"simple_us_phone_number": {
"description": "must be a simple United States phone number pattern of 3 digits, followed by a hyphen, followed by 3 digits, followed by a hyphen, followed by 4 digits",
"error_text": "Must be a valid phone number in the format of 555-555-5555.",
"examples": [
"555-555-5555",
"555-123-4567"
],
"link": "https://regex101.com/r/jt6ujJ/5",
"regex": "^\\d{3}-\\d{3}-\\d{4}$"
},
"tin": {
"description": "must be 2 digits, followed by a hyphen, followed by 7 digits",
"error_text": "Must be a valid TIN in the format of 12-3456789.",
"examples": [
"12-3456789",
"98-7654321"
],
"link": "https://regex101.com/r/7op0LA/3",
"regex": "^\\d{2}-\\d{7}$"
}
}
19 changes: 19 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"compilerOptions": {
"target": "ESNext",
"allowJs": false,
"skipLibCheck": true,
"esModuleInterop": false,
"allowSyntheticDefaultImports": true,
"strict": true,
"module": "ESNext",
"moduleResolution": "Node",
"resolveJsonModule": true,
"isolatedModules": true,
"outDir": "./src/node/dist/",
"baseUrl": "./src/",
"paths": {
"@/*": ["./*"]
},
},
}
32 changes: 32 additions & 0 deletions vite.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { resolve } from 'node:path';
import { defineConfig } from 'vite';
import dts from 'vite-plugin-dts';
import tsConfigPaths from 'vite-tsconfig-paths';
import { name } from './package.json';

export default defineConfig(() => ({
resolve: {
alias: {
'~': resolve(__dirname),
'@': resolve(__dirname, "./src")
}
},
plugins: [
tsConfigPaths(),
dts({
insertTypesEntry: true
}),
],
build: {
outDir: 'src/node/dist',
lib: {
entry: resolve('src', 'node', 'index.ts'),
name,
formats: ['es', 'cjs'],
fileName: (format): string => `${name}.${format}.js`
},
esbuild: {
minify: true
}
}
}));
Loading
Loading