2
0

♻️ Introduce typebot v6 with events (#1013)

Closes #885
This commit is contained in:
Baptiste Arnaud
2023-11-08 15:34:16 +01:00
committed by GitHub
parent 68e4fc71fb
commit 35300eaf34
634 changed files with 58971 additions and 31449 deletions

View File

@ -0,0 +1,5 @@
import { AbTestBlock } from './schema'
export const defaultAbTestOptions = {
aPercent: 50,
} as const satisfies AbTestBlock['options']

View File

@ -0,0 +1 @@
export * from './schema'

View File

@ -0,0 +1,48 @@
import { z } from 'zod'
import { blockBaseSchema } from '../../shared'
import { LogicBlockType } from '../constants'
import { itemBaseSchemas } from '../../../items/shared'
export const aItemSchemas = {
v5: itemBaseSchemas.v5.extend({
path: z.literal('a'),
}),
v6: itemBaseSchemas.v6.extend({
path: z.literal('a'),
}),
}
export const bItemSchemas = {
v5: itemBaseSchemas.v5.extend({
path: z.literal('b'),
}),
v6: itemBaseSchemas.v6.extend({
path: z.literal('b'),
}),
}
const abTestBlockV5Schema = blockBaseSchema.merge(
z.object({
type: z.enum([LogicBlockType.AB_TEST]),
items: z.tuple([aItemSchemas.v5, bItemSchemas.v5]),
options: z
.object({
aPercent: z.number().min(0).max(100).optional(),
})
.optional(),
})
)
export const abTestBlockSchemas = {
v5: abTestBlockV5Schema,
v6: abTestBlockV5Schema.extend({
items: z.tuple([aItemSchemas.v6, bItemSchemas.v6]),
}),
} as const
export const abTestBlockSchema = z.union([
abTestBlockSchemas.v5,
abTestBlockSchemas.v6,
])
export type AbTestBlock = z.infer<typeof abTestBlockSchema>