@ -1,21 +0,0 @@
|
||||
import { z } from 'zod'
|
||||
import { blockBaseSchema } from '../baseSchemas'
|
||||
import { LogicBlockType } from './enums'
|
||||
|
||||
export const codeOptionsSchema = z.object({
|
||||
name: z.string(),
|
||||
content: z.string().optional(),
|
||||
shouldExecuteInParentContext: z.boolean().optional(),
|
||||
})
|
||||
|
||||
export const codeBlockSchema = blockBaseSchema.and(
|
||||
z.object({
|
||||
type: z.enum([LogicBlockType.CODE]),
|
||||
options: codeOptionsSchema,
|
||||
})
|
||||
)
|
||||
|
||||
export const defaultCodeOptions: CodeOptions = { name: 'Code snippet' }
|
||||
|
||||
export type CodeBlock = z.infer<typeof codeBlockSchema>
|
||||
export type CodeOptions = z.infer<typeof codeOptionsSchema>
|
@ -2,7 +2,7 @@ export enum LogicBlockType {
|
||||
SET_VARIABLE = 'Set variable',
|
||||
CONDITION = 'Condition',
|
||||
REDIRECT = 'Redirect',
|
||||
CODE = 'Code',
|
||||
SCRIPT = 'Code',
|
||||
TYPEBOT_LINK = 'Typebot link',
|
||||
WAIT = 'Wait',
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
export * from './code'
|
||||
export * from './script'
|
||||
export * from './condition'
|
||||
export * from './enums'
|
||||
export * from './logicBlock'
|
||||
|
@ -1,18 +1,18 @@
|
||||
import { z } from 'zod'
|
||||
import { codeOptionsSchema, codeBlockSchema } from './code'
|
||||
import { scriptOptionsSchema, scriptBlockSchema } from './script'
|
||||
import { conditionBlockSchema } from './condition'
|
||||
import { redirectOptionsSchema, redirectBlockSchema } from './redirect'
|
||||
import { setVariableOptionsSchema, setVariableBlockSchema } from './setVariable'
|
||||
import { typebotLinkOptionsSchema, typebotLinkBlockSchema } from './typebotLink'
|
||||
import { waitBlockSchema, waitOptionsSchema } from './wait'
|
||||
|
||||
const logicBlockOptionsSchema = codeOptionsSchema
|
||||
const logicBlockOptionsSchema = scriptOptionsSchema
|
||||
.or(redirectOptionsSchema)
|
||||
.or(setVariableOptionsSchema)
|
||||
.or(typebotLinkOptionsSchema)
|
||||
.or(waitOptionsSchema)
|
||||
|
||||
export const logicBlockSchema = codeBlockSchema
|
||||
export const logicBlockSchema = scriptBlockSchema
|
||||
.or(conditionBlockSchema)
|
||||
.or(redirectBlockSchema)
|
||||
.or(typebotLinkBlockSchema)
|
||||
|
21
packages/models/features/blocks/logic/script.ts
Normal file
21
packages/models/features/blocks/logic/script.ts
Normal file
@ -0,0 +1,21 @@
|
||||
import { z } from 'zod'
|
||||
import { blockBaseSchema } from '../baseSchemas'
|
||||
import { LogicBlockType } from './enums'
|
||||
|
||||
export const scriptOptionsSchema = z.object({
|
||||
name: z.string(),
|
||||
content: z.string().optional(),
|
||||
shouldExecuteInParentContext: z.boolean().optional(),
|
||||
})
|
||||
|
||||
export const scriptBlockSchema = blockBaseSchema.and(
|
||||
z.object({
|
||||
type: z.enum([LogicBlockType.SCRIPT]),
|
||||
options: scriptOptionsSchema,
|
||||
})
|
||||
)
|
||||
|
||||
export const defaultScriptOptions: ScriptOptions = { name: 'Script' }
|
||||
|
||||
export type ScriptBlock = z.infer<typeof scriptBlockSchema>
|
||||
export type ScriptOptions = z.infer<typeof scriptOptionsSchema>
|
Reference in New Issue
Block a user