2
0

🚑 Fix parsing issue with new events field on ongoing session states

This commit is contained in:
Baptiste Arnaud
2023-11-08 15:47:30 +01:00
parent 35300eaf34
commit db17a0f508
2 changed files with 4 additions and 2 deletions

View File

@ -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)
: [],

View File

@ -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),