From db17a0f508a3557072b34fefaa5c6826c722eed3 Mon Sep 17 00:00:00 2001 From: Baptiste Arnaud Date: Wed, 8 Nov 2023 15:47:30 +0100 Subject: [PATCH] :ambulance: Fix parsing issue with new events field on ongoing session states --- .../schemas/features/typebot/helpers/preprocessTypebot.ts | 4 +++- packages/schemas/features/typebot/typebot.ts | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/schemas/features/typebot/helpers/preprocessTypebot.ts b/packages/schemas/features/typebot/helpers/preprocessTypebot.ts index 96494c024..3ed390b96 100644 --- a/packages/schemas/features/typebot/helpers/preprocessTypebot.ts +++ b/packages/schemas/features/typebot/helpers/preprocessTypebot.ts @@ -1,7 +1,8 @@ import { edgeSchema } from '../edge' export const preprocessTypebot = (typebot: any) => { - if (!typebot || typebot.version === '5') return typebot + if (!typebot || typebot.version === '5' || typebot.version === '6') + return typebot return { ...typebot, version: @@ -9,6 +10,7 @@ export const preprocessTypebot = (typebot: any) => { ? '3' : typebot.version, groups: typebot.groups ? typebot.groups.map(preprocessGroup) : [], + events: null, edges: typebot.edges ? typebot.edges?.filter((edge: any) => edgeSchema.safeParse(edge).success) : [], diff --git a/packages/schemas/features/typebot/typebot.ts b/packages/schemas/features/typebot/typebot.ts index 2bbe1ea04..5525c0eda 100644 --- a/packages/schemas/features/typebot/typebot.ts +++ b/packages/schemas/features/typebot/typebot.ts @@ -25,7 +25,7 @@ export const typebotV5Schema = z.preprocess( version: z.enum(['3', '4', '5']), id: z.string(), name: z.string(), - events: z.null(), + events: z.preprocess((val) => (val === undefined ? null : val), z.null()), groups: z.array(groupV5Schema), edges: z.array(edgeSchema), variables: z.array(variableSchema),