-
Notifications
You must be signed in to change notification settings - Fork 529
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: centralize validation schemas (#2669)
* feat: centralize validation schemas * Fix code scanning alert no. 12: Overly permissive regular expression range Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com> --------- Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
- Loading branch information
1 parent
ae32930
commit 66c4cd5
Showing
13 changed files
with
386 additions
and
295 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
`@unkey/validation` contains various shared schema or validation utils. | ||
|
||
For example user-chosen identifiers. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"name": "@unkey/validation", | ||
"version": "1.0.0", | ||
"description": "", | ||
"main": "src/index.ts", | ||
"types": "src/index.ts", | ||
"keywords": [], | ||
"author": "Andreas Thomas", | ||
"license": "AGPL-3.0", | ||
"devDependencies": { | ||
"@types/node": "^20.14.9", | ||
"@unkey/tsconfig": "workspace:*", | ||
"typescript": "^5.5.3" | ||
}, | ||
"dependencies": { | ||
"zod": "^3.23.5" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { z } from "zod"; | ||
|
||
/* | ||
* An identifier is any string the user gives us to be used as a lookup key. | ||
* It must be URL safe and fit into our database (varchar 256) | ||
*/ | ||
const identifier = z | ||
.string() | ||
.min(3) | ||
.max(256) | ||
.regex( | ||
/^[a-zA-Z0-9_\.:\-]*$/, | ||
"Only alphanumeric, underscores, periods, colons and hyphens are allowed", | ||
); | ||
|
||
/** | ||
* A name is a user given human-readable string. | ||
* | ||
* It must not be used in URLs. | ||
* | ||
* @example the name of a key | ||
*/ | ||
const name = z.string().min(3).max(256); | ||
|
||
/** | ||
* A description is a user given human-readable string. | ||
* | ||
* It must not be used in URLs. | ||
* | ||
* @example The description of a permission | ||
*/ | ||
const description = z.string().min(3).max(256); | ||
|
||
const unkeyId = z | ||
.string() | ||
.regex( | ||
/^[a-z]{3,4}_[a-zA-Z0-9]{8,}$/, | ||
"Unkey IDs must include a prefix, separated by an underscore: key_abcdefg123", | ||
); | ||
|
||
export const validation = { | ||
identifier, | ||
name, | ||
description, | ||
unkeyId, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"$schema": "https://json.schemastore.org/tsconfig", | ||
"extends": "@unkey/tsconfig/base.json", | ||
"exclude": ["dist"], | ||
"compilerOptions": { | ||
"outDir": "dist" | ||
} | ||
} |
Oops, something went wrong.