31
packages/schemas/features/blocks/logic/abTest.ts
Normal file
31
packages/schemas/features/blocks/logic/abTest.ts
Normal file
@ -0,0 +1,31 @@
|
||||
import { z } from 'zod'
|
||||
import { blockBaseSchema } from '../baseSchemas'
|
||||
import { LogicBlockType } from './enums'
|
||||
import { itemBaseSchema } from '../../items/baseSchemas'
|
||||
import { ItemType } from '../../items/enums'
|
||||
|
||||
export const aItemSchema = itemBaseSchema.extend({
|
||||
type: z.literal(ItemType.AB_TEST),
|
||||
path: z.literal('a'),
|
||||
})
|
||||
|
||||
export const bItemSchema = itemBaseSchema.extend({
|
||||
type: z.literal(ItemType.AB_TEST),
|
||||
path: z.literal('b'),
|
||||
})
|
||||
|
||||
export const abTestBlockSchema = blockBaseSchema.merge(
|
||||
z.object({
|
||||
type: z.enum([LogicBlockType.AB_TEST]),
|
||||
items: z.tuple([aItemSchema, bItemSchema]),
|
||||
options: z.object({
|
||||
aPercent: z.number().min(0).max(100),
|
||||
}),
|
||||
})
|
||||
)
|
||||
|
||||
export const defaultAbTestOptions = {
|
||||
aPercent: 50,
|
||||
}
|
||||
|
||||
export type AbTestBlock = z.infer<typeof abTestBlockSchema>
|
@ -6,4 +6,5 @@ export enum LogicBlockType {
|
||||
TYPEBOT_LINK = 'Typebot link',
|
||||
WAIT = 'Wait',
|
||||
JUMP = 'Jump',
|
||||
AB_TEST = 'AB test',
|
||||
}
|
||||
|
@ -5,3 +5,4 @@ export * from './redirect'
|
||||
export * from './setVariable'
|
||||
export * from './typebotLink'
|
||||
export * from './wait'
|
||||
export * from './abTest'
|
||||
|
@ -42,6 +42,8 @@ import {
|
||||
setVariableBlockSchema,
|
||||
typebotLinkBlockSchema,
|
||||
waitBlockSchema,
|
||||
abTestBlockSchema,
|
||||
AbTestBlock,
|
||||
} from './logic'
|
||||
import { jumpBlockSchema } from './logic/jump'
|
||||
|
||||
@ -79,7 +81,7 @@ export type BlockOptions =
|
||||
| LogicBlockOptions
|
||||
| IntegrationBlockOptions
|
||||
|
||||
export type BlockWithItems = ConditionBlock | ChoiceInputBlock
|
||||
export type BlockWithItems = ConditionBlock | ChoiceInputBlock | AbTestBlock
|
||||
|
||||
export type BlockBase = z.infer<typeof blockBaseSchema>
|
||||
|
||||
@ -123,6 +125,7 @@ export const logicBlockSchema = z.discriminatedUnion('type', [
|
||||
typebotLinkBlockSchema,
|
||||
waitBlockSchema,
|
||||
jumpBlockSchema,
|
||||
abTestBlockSchema,
|
||||
])
|
||||
|
||||
export type LogicBlock = z.infer<typeof logicBlockSchema>
|
||||
|
@ -1,4 +1,5 @@
|
||||
export enum ItemType {
|
||||
BUTTON,
|
||||
CONDITION,
|
||||
AB_TEST,
|
||||
}
|
||||
|
@ -1,7 +1,11 @@
|
||||
import { z } from 'zod'
|
||||
import { buttonItemSchema } from '../blocks/inputs/choice'
|
||||
import { conditionItemSchema } from '../blocks/logic/condition'
|
||||
import { aItemSchema, bItemSchema } from '../blocks'
|
||||
|
||||
const itemSchema = buttonItemSchema.or(conditionItemSchema)
|
||||
const itemSchema = buttonItemSchema
|
||||
.or(conditionItemSchema)
|
||||
.or(aItemSchema)
|
||||
.or(bItemSchema)
|
||||
|
||||
export type Item = z.infer<typeof itemSchema>
|
||||
|
Reference in New Issue
Block a user