mirror of
https://github.com/logto-io/logto.git
synced 2024-12-16 20:26:19 -05:00
feat(schemas): zod type guards of sign-in experience jsonb fields (#473)
* feat(schemas): guard branding logo url and terms-of-use content url * feat(schemas): guard branding logo url non-optional * feat(schemas): guard branding colors and slogan nonempty * chore(core,schemas): upgrade zod dependency version from 3.8.1 to 3.14.3 * feat(schemas): jsonb types guard hex color values * feat(core): hex color regex
This commit is contained in:
parent
6a61ea29f5
commit
cd63388ab1
5 changed files with 18 additions and 15 deletions
|
@ -44,7 +44,7 @@
|
|||
"slonik": "^23.8.3",
|
||||
"slonik-interceptor-preset": "^1.2.10",
|
||||
"snakecase-keys": "^5.1.0",
|
||||
"zod": "^3.8.1"
|
||||
"zod": "^3.14.3"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@shopify/jest-koa-mocks": "^3.0.8",
|
||||
|
|
|
@ -3,3 +3,4 @@ export const phoneRegEx = /^[1-9]\d{10}$/;
|
|||
export const usernameRegEx = /^.{3,}$/;
|
||||
export const nameRegEx = /^.{3,}$/;
|
||||
export const passwordRegEx = /^.{6,}$/;
|
||||
export { hexColorRegEx } from '@logto/schemas';
|
||||
|
|
|
@ -45,6 +45,6 @@
|
|||
"prettier": "@silverhand/eslint-config/.prettierrc",
|
||||
"dependencies": {
|
||||
"@logto/phrases": "^0.1.0",
|
||||
"zod": "^3.8.1"
|
||||
"zod": "^3.14.3"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -87,22 +87,24 @@ export enum BrandingStyle {
|
|||
Logo_Slogan = 'Logo_Slogan',
|
||||
}
|
||||
|
||||
export const hexColorRegEx = /^#[\da-f]{3}([\da-f]{3})?$/i;
|
||||
|
||||
export const brandingGuard = z.object({
|
||||
primaryColor: z.string(),
|
||||
backgroundColor: z.string(),
|
||||
primaryColor: z.string().regex(hexColorRegEx),
|
||||
backgroundColor: z.string().regex(hexColorRegEx),
|
||||
darkMode: z.boolean(),
|
||||
darkPrimaryColor: z.string(),
|
||||
darkBackgroundColor: z.string(),
|
||||
darkPrimaryColor: z.string().regex(hexColorRegEx),
|
||||
darkBackgroundColor: z.string().regex(hexColorRegEx),
|
||||
style: z.nativeEnum(BrandingStyle),
|
||||
logoUrl: z.string().optional(),
|
||||
slogan: z.string().optional(),
|
||||
logoUrl: z.string().url(),
|
||||
slogan: z.string().nonempty().optional(),
|
||||
});
|
||||
|
||||
export type Branding = z.infer<typeof brandingGuard>;
|
||||
|
||||
export const termsOfUseGuard = z.object({
|
||||
enabled: z.boolean(),
|
||||
contentUrl: z.string().optional(),
|
||||
contentUrl: z.string().url().optional(),
|
||||
});
|
||||
|
||||
export type TermsOfUse = z.infer<typeof termsOfUseGuard>;
|
||||
|
|
|
@ -161,7 +161,7 @@ importers:
|
|||
ts-jest: ^27.0.5
|
||||
tsc-watch: ^4.4.0
|
||||
typescript: ^4.6.2
|
||||
zod: ^3.8.1
|
||||
zod: ^3.14.3
|
||||
dependencies:
|
||||
'@logto/phrases': link:../phrases
|
||||
'@logto/schemas': link:../schemas
|
||||
|
@ -188,7 +188,7 @@ importers:
|
|||
slonik: 23.9.0
|
||||
slonik-interceptor-preset: 1.2.10
|
||||
snakecase-keys: 5.1.2
|
||||
zod: 3.11.6
|
||||
zod: 3.14.3
|
||||
devDependencies:
|
||||
'@shopify/jest-koa-mocks': 3.0.8
|
||||
'@silverhand/eslint-config': 0.9.4_3a533fa6cc3da0cf8525ef55d41c4384
|
||||
|
@ -252,10 +252,10 @@ importers:
|
|||
prettier: ^2.3.2
|
||||
ts-node: ^10.0.0
|
||||
typescript: ^4.6.2
|
||||
zod: ^3.8.1
|
||||
zod: ^3.14.3
|
||||
dependencies:
|
||||
'@logto/phrases': link:../phrases
|
||||
zod: 3.11.6
|
||||
zod: 3.14.3
|
||||
devDependencies:
|
||||
'@silverhand/eslint-config': 0.9.4_3a533fa6cc3da0cf8525ef55d41c4384
|
||||
'@silverhand/essentials': 1.1.2
|
||||
|
@ -14446,8 +14446,8 @@ packages:
|
|||
engines: {node: '>=10'}
|
||||
dev: true
|
||||
|
||||
/zod/3.11.6:
|
||||
resolution: {integrity: sha512-daZ80A81I3/9lIydI44motWe6n59kRBfNzTuS2bfzVh1nAXi667TOTWWtatxyG+fwgNUiagSj/CWZwRRbevJIg==}
|
||||
/zod/3.14.3:
|
||||
resolution: {integrity: sha512-OzwRCSXB1+/8F6w6HkYHdbuWysYWnAF4fkRgKDcSFc54CE+Sv0rHXKfeNUReGCrHukm1LNpi6AYeXotznhYJbQ==}
|
||||
dev: false
|
||||
|
||||
/zwitch/1.0.5:
|
||||
|
|
Loading…
Reference in a new issue