diff --git a/apps/builder/src/features/templates/components/ImportTypebotFromFileButton.tsx b/apps/builder/src/features/templates/components/ImportTypebotFromFileButton.tsx index 959944f3ac8..700ae897252 100644 --- a/apps/builder/src/features/templates/components/ImportTypebotFromFileButton.tsx +++ b/apps/builder/src/features/templates/components/ImportTypebotFromFileButton.tsx @@ -26,7 +26,7 @@ export const ImportTypebotFromFileButton = ({ updatedAt: true, }) .parse(typebot) - onNewTypebot(typebot) + onNewTypebot(typebot as Typebot) } catch (err) { console.error(err) showToast({ diff --git a/apps/builder/src/features/typebot/api/getPublishedTypebot.ts b/apps/builder/src/features/typebot/api/getPublishedTypebot.ts index dd5249d0868..ec11b290226 100644 --- a/apps/builder/src/features/typebot/api/getPublishedTypebot.ts +++ b/apps/builder/src/features/typebot/api/getPublishedTypebot.ts @@ -4,6 +4,8 @@ import { TRPCError } from '@trpc/server' import { publicTypebotSchema } from '@typebot.io/schemas' import { z } from 'zod' import { isReadTypebotForbidden } from '../helpers/isReadTypebotForbidden' +import { parseInvalidTypebot } from '../helpers/parseInvalidTypebot' +import { PublicTypebot } from '@typebot.io/schemas' export const getPublishedTypebot = authenticatedProcedure .meta({ @@ -48,7 +50,7 @@ export const getPublishedTypebot = authenticatedProcedure try { const parsedTypebot = publicTypebotSchema.parse( - existingTypebot.publishedTypebot + parseInvalidTypebot(existingTypebot.publishedTypebot as PublicTypebot) ) return { diff --git a/apps/builder/src/features/typebot/helpers/parseInvalidTypebot.ts b/apps/builder/src/features/typebot/helpers/parseInvalidTypebot.ts index 0b7ea6d1183..bd2635e0872 100644 --- a/apps/builder/src/features/typebot/helpers/parseInvalidTypebot.ts +++ b/apps/builder/src/features/typebot/helpers/parseInvalidTypebot.ts @@ -1,6 +1,8 @@ -import { Edge, Typebot, edgeSchema } from '@typebot.io/schemas' +import { Edge, PublicTypebot, Typebot, edgeSchema } from '@typebot.io/schemas' -export const parseInvalidTypebot = (typebot: Typebot): Typebot => ({ +export const parseInvalidTypebot = ( + typebot: Typebot | PublicTypebot +): Typebot | PublicTypebot => ({ ...typebot, version: typebot.version as null | '3' | '4' | '5', edges: parseInvalidEdges(typebot.edges), diff --git a/packages/schemas/features/typebot/typebot.ts b/packages/schemas/features/typebot/typebot.ts index 94ea767b316..342c5f0f3b3 100644 --- a/packages/schemas/features/typebot/typebot.ts +++ b/packages/schemas/features/typebot/typebot.ts @@ -41,6 +41,11 @@ const resultsTablePreferencesSchema = z.object({ const isPathNameCompatible = (str: string) => /^([a-z0-9]+-[a-z0-9]*)*$/.test(str) || /^[a-z0-9]*$/.test(str) +const isDomainNameWithPathNameCompatible = (str: string) => + /^(?:(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?\.)+[a-zA-Z]{2,}(?:\/[\w-\/]*)?)$/.test( + str + ) + export const typebotSchema = z.object({ version: z.enum(['3', '4', '5']).nullable(), id: z.string(), @@ -56,7 +61,10 @@ export const typebotSchema = z.object({ icon: z.string().nullable(), folderId: z.string().nullable(), publicId: z.string().refine(isPathNameCompatible).nullable(), - customDomain: z.string().refine(isPathNameCompatible).nullable(), + customDomain: z + .string() + .refine(isDomainNameWithPathNameCompatible) + .nullable(), workspaceId: z.string(), resultsTablePreferences: resultsTablePreferencesSchema.nullable(), isArchived: z.boolean(),