2
0

(api) Add CRUD typebot endpoints

Closes #320, closes #696
This commit is contained in:
Baptiste Arnaud
2023-08-17 09:39:11 +02:00
parent 019f72ac7e
commit 454d320c6b
78 changed files with 25014 additions and 1073 deletions

View File

@@ -21,7 +21,7 @@ export const parseTestTypebot = (
folderId: null,
name: 'My typebot',
theme: defaultTheme,
settings: defaultSettings,
settings: defaultSettings({ isBrandingEnabled: true }),
publicId: null,
updatedAt: new Date(),
createdAt: new Date(),

View File

@@ -8,7 +8,7 @@ export const emailInputOptionsSchema = optionBaseSchema
.merge(textInputOptionsBaseSchema)
.merge(
z.object({
retryMessageContent: z.string(),
retryMessageContent: z.string().optional(),
})
)
@@ -19,13 +19,14 @@ export const emailInputSchema = blockBaseSchema.merge(
})
)
export const invalidEmailDefaultRetryMessage =
"This email doesn't seem to be valid. Can you type it again?"
export const defaultEmailInputOptions: EmailInputOptions = {
labels: {
button: defaultButtonLabel,
placeholder: 'Type your email...',
},
retryMessageContent:
"This email doesn't seem to be valid. Can you type it again?",
}
export type EmailInputBlock = z.infer<typeof emailInputSchema>

View File

@@ -0,0 +1,10 @@
import { CollaborationType, CollaboratorsOnTypebots } from '@typebot.io/prisma'
import { z } from 'zod'
export const collaboratorSchema = z.object({
type: z.nativeEnum(CollaborationType),
userId: z.string(),
typebotId: z.string(),
createdAt: z.date(),
updatedAt: z.date(),
}) satisfies z.ZodType<CollaboratorsOnTypebots>

View File

@@ -11,7 +11,7 @@ import { z } from 'zod'
export const publicTypebotSchema = z.object({
id: z.string(),
version: z.enum(['3', '4']).nullable(),
version: z.enum(['3', '4', '5']).nullable(),
createdAt: z.date(),
updatedAt: z.date(),
typebotId: z.string(),

View File

@@ -37,9 +37,13 @@ export const settingsSchema = z.object({
metadata: metadataSchema,
})
export const defaultSettings: Settings = {
export const defaultSettings = ({
isBrandingEnabled,
}: {
isBrandingEnabled: boolean
}): Settings => ({
general: {
isBrandingEnabled: true,
isBrandingEnabled,
rememberUser: {
isEnabled: false,
},
@@ -51,7 +55,7 @@ export const defaultSettings: Settings = {
description:
'Build beautiful conversational forms and embed them directly in your applications without a line of code. Triple your response rate and collect answers that has more value compared to a traditional form.',
},
}
})
export type Settings = z.infer<typeof settingsSchema>
export type GeneralSettings = z.infer<typeof generalSettings>

View File

@@ -38,8 +38,11 @@ const resultsTablePreferencesSchema = z.object({
columnsWidth: z.record(z.string(), z.number()),
})
const isPathNameCompatible = (str: string) =>
/^([a-z0-9]+-[a-z0-9]*)*$/.test(str) || /^[a-z0-9]*$/.test(str)
export const typebotSchema = z.object({
version: z.enum(['3', '4']).nullable(),
version: z.enum(['3', '4', '5']).nullable(),
id: z.string(),
name: z.string(),
groups: z.array(groupSchema),
@@ -52,8 +55,8 @@ export const typebotSchema = z.object({
updatedAt: z.date(),
icon: z.string().nullable(),
folderId: z.string().nullable(),
publicId: z.string().nullable(),
customDomain: z.string().nullable(),
publicId: z.string().refine(isPathNameCompatible).nullable(),
customDomain: z.string().refine(isPathNameCompatible).nullable(),
workspaceId: z.string(),
resultsTablePreferences: resultsTablePreferencesSchema.nullable(),
isArchived: z.boolean(),