AccessToken.schemas.ts 984 B

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