2023-06-09 18:21:18 +10:00
|
|
|
import { z } from 'zod';
|
|
|
|
|
|
2024-12-11 19:39:50 +09:00
|
|
|
import { ZFindSearchParamsSchema } from '@documenso/lib/types/search-params';
|
2024-03-26 21:11:59 +08:00
|
|
|
import { ZRegistrationResponseJSONSchema } from '@documenso/lib/types/webauthn';
|
|
|
|
|
|
2024-01-30 06:12:52 +05:30
|
|
|
export const ZCurrentPasswordSchema = z
|
|
|
|
|
.string()
|
|
|
|
|
.min(6, { message: 'Must be at least 6 characters in length' })
|
|
|
|
|
.max(72);
|
|
|
|
|
|
|
|
|
|
export const ZPasswordSchema = z
|
|
|
|
|
.string()
|
|
|
|
|
.min(8, { message: 'Must be at least 8 characters in length' })
|
2024-12-27 06:02:45 +01:00
|
|
|
.max(72, { message: 'Cannot be more than 72 characters in length' })
|
|
|
|
|
.refine((value) => value.length > 25 || /[A-Z]/.test(value), {
|
|
|
|
|
message: 'One uppercase character',
|
|
|
|
|
})
|
|
|
|
|
.refine((value) => value.length > 25 || /[a-z]/.test(value), {
|
|
|
|
|
message: 'One lowercase character',
|
|
|
|
|
})
|
|
|
|
|
.refine((value) => value.length > 25 || /\d/.test(value), {
|
|
|
|
|
message: 'One number',
|
|
|
|
|
})
|
|
|
|
|
.refine((value) => value.length > 25 || /[`~<>?,./!@#$%^&*()\-_"'+=|{}[\];:\\]/.test(value), {
|
|
|
|
|
message: 'One special character is required',
|
|
|
|
|
});
|
2024-01-30 06:12:52 +05:30
|
|
|
|
2023-06-09 18:21:18 +10:00
|
|
|
export const ZSignUpMutationSchema = z.object({
|
|
|
|
|
name: z.string().min(1),
|
|
|
|
|
email: z.string().email(),
|
2024-01-30 06:12:52 +05:30
|
|
|
password: ZPasswordSchema,
|
2024-04-11 10:09:04 +03:00
|
|
|
signature: z.string().nullish(),
|
2024-02-29 14:13:37 +11:00
|
|
|
url: z
|
|
|
|
|
.string()
|
|
|
|
|
.trim()
|
|
|
|
|
.toLowerCase()
|
|
|
|
|
.min(1)
|
|
|
|
|
.regex(/^[a-z0-9-]+$/, {
|
|
|
|
|
message: 'Username can only container alphanumeric characters and dashes.',
|
|
|
|
|
})
|
|
|
|
|
.optional(),
|
2023-06-09 18:21:18 +10:00
|
|
|
});
|
|
|
|
|
|
2024-03-26 21:11:59 +08:00
|
|
|
export const ZCreatePasskeyMutationSchema = z.object({
|
|
|
|
|
passkeyName: z.string().trim().min(1),
|
|
|
|
|
verificationResponse: ZRegistrationResponseJSONSchema,
|
|
|
|
|
});
|
|
|
|
|
|
2024-03-31 15:49:12 +08:00
|
|
|
export const ZCreatePasskeyAuthenticationOptionsMutationSchema = z
|
|
|
|
|
.object({
|
|
|
|
|
preferredPasskeyId: z.string().optional(),
|
|
|
|
|
})
|
|
|
|
|
.optional();
|
|
|
|
|
|
2024-03-26 21:11:59 +08:00
|
|
|
export const ZDeletePasskeyMutationSchema = z.object({
|
|
|
|
|
passkeyId: z.string().trim().min(1),
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
export const ZUpdatePasskeyMutationSchema = z.object({
|
|
|
|
|
passkeyId: z.string().trim().min(1),
|
|
|
|
|
name: z.string().trim().min(1),
|
|
|
|
|
});
|
|
|
|
|
|
2024-12-11 19:39:50 +09:00
|
|
|
export const ZFindPasskeysQuerySchema = ZFindSearchParamsSchema.extend({
|
2024-03-26 21:11:59 +08:00
|
|
|
orderBy: z
|
|
|
|
|
.object({
|
|
|
|
|
column: z.enum(['createdAt', 'updatedAt', 'name']),
|
|
|
|
|
direction: z.enum(['asc', 'desc']),
|
|
|
|
|
})
|
|
|
|
|
.optional(),
|
|
|
|
|
});
|
|
|
|
|
|
2023-06-09 18:21:18 +10:00
|
|
|
export type TSignUpMutationSchema = z.infer<typeof ZSignUpMutationSchema>;
|
2023-12-01 05:52:16 +05:30
|
|
|
|
|
|
|
|
export const ZVerifyPasswordMutationSchema = ZSignUpMutationSchema.pick({ password: true });
|