2
0
Files
bot/packages/schemas/features/customDomains.ts
2023-09-18 17:16:30 +02:00

48 lines
1.2 KiB
TypeScript

import { CustomDomain as CustomDomainInDb } from '@typebot.io/prisma'
import { z } from 'zod'
export const domainVerificationStatusSchema = z.enum([
'Valid Configuration',
'Invalid Configuration',
'Domain Not Found',
'Pending Verification',
'Unknown Error',
])
export type DomainVerificationStatus = z.infer<
typeof domainVerificationStatusSchema
>
export const domainResponseSchema = z.object({
name: z.string(),
apexName: z.string(),
projectId: z.string(),
redirect: z.string().nullable(),
redirectStatusCode: z.number().nullable(),
gitBranch: z.string().nullable(),
updatedAt: z.number().nullable(),
createdAt: z.number().nullable(),
verified: z.boolean(),
verification: z
.array(
z.object({
type: z.string(),
domain: z.string(),
value: z.string(),
reason: z.string(),
})
)
.optional(),
})
export type DomainResponse = z.infer<typeof domainResponseSchema>
const domainNameRegex = /^([a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,}$/
export const customDomainSchema = z.object({
name: z
.string()
.transform((name) => name.toLowerCase())
.refine((name) => domainNameRegex.test(name)),
workspaceId: z.string(),
createdAt: z.date(),
}) satisfies z.ZodType<CustomDomainInDb>