AccessToken.schemas.ts23 lines · main
1import { z } from 'zod'
2
3export const PermissionRowSchema = z.object({
4 resource: z.string().min(1, 'Please select a resource'),
5 actions: z.array(z.string()).min(1, 'Please select at least one action'),
6})
7
8export const TokenSchema = z
9 .object({
10 tokenName: z.string().min(1, 'Please enter a name for the token'),
11 expiresAt: z.preprocess((val) => (val === 'never' ? undefined : val), z.string().optional()),
12 customExpiryDate: z.string().optional(),
13 resourceAccess: z.enum(['all-orgs', 'selected-orgs', 'selected-projects']),
14 selectedOrganizations: z.array(z.string()).optional(),
15 selectedProjects: z.array(z.string()).optional(),
16 permissionRows: z.array(PermissionRowSchema).min(1, 'Please configure at least one permission'),
17 })
18 .refine((data) => !(data.expiresAt === 'custom' && !data.customExpiryDate), {
19 message: 'Please select a custom expiry date',
20 path: ['expiresAt'],
21 })
22
23export type TokenFormValues = z.infer<typeof TokenSchema>