56 lines
1.7 KiB
TypeScript
56 lines
1.7 KiB
TypeScript
import { z } from 'zod';
|
|
import { PERMISSIONS } from './permissions';
|
|
|
|
export const email = z
|
|
.email()
|
|
.max(254)
|
|
.transform((value) => value.toLowerCase());
|
|
export const password = z.string().min(15).max(128);
|
|
const name = z.string().trim().min(1).max(160);
|
|
export const loginSchema = z
|
|
.object({
|
|
organizationId: z.uuid(),
|
|
email,
|
|
password: z.string().min(1).max(128),
|
|
})
|
|
.strict();
|
|
export const recoveryRequestSchema = loginSchema.omit({ password: true });
|
|
export const recoveryResetSchema = z
|
|
.object({
|
|
token: z.string().regex(/^[A-Za-z0-9_-]{43}$/),
|
|
password,
|
|
})
|
|
.strict();
|
|
export const createUserSchema = z.object({ email, name, password }).strict();
|
|
export const statusSchema = z
|
|
.object({ status: z.enum(['ACTIVE', 'SUSPENDED']) })
|
|
.strict();
|
|
export const roleSchema = z
|
|
.object({
|
|
name: z.string().trim().min(1).max(80),
|
|
permissions: z
|
|
.array(z.enum(PERMISSIONS))
|
|
.max(PERMISSIONS.length)
|
|
.refine((values) => new Set(values).size === values.length),
|
|
})
|
|
.strict();
|
|
export const assignmentsSchema = z
|
|
.object({
|
|
roleIds: z
|
|
.array(z.uuid())
|
|
.max(20)
|
|
.refine((ids) => new Set(ids).size === ids.length),
|
|
})
|
|
.strict();
|
|
export const pageSchema = z
|
|
.object({
|
|
limit: z.coerce.number().int().min(1).max(100).default(25),
|
|
offset: z.coerce.number().int().min(0).max(10000).default(0),
|
|
})
|
|
.strict();
|
|
export type LoginInput = z.infer<typeof loginSchema>;
|
|
export type RecoveryInput = z.infer<typeof recoveryRequestSchema>;
|
|
export type CreateUserInput = z.infer<typeof createUserSchema>;
|
|
export type RoleInput = z.infer<typeof roleSchema>;
|
|
export type PageInput = z.infer<typeof pageSchema>;
|