♻️ Re-organize workspace folders
This commit is contained in:
55
packages/schemas/features/blocks/logic/condition.ts
Normal file
55
packages/schemas/features/blocks/logic/condition.ts
Normal file
@@ -0,0 +1,55 @@
|
||||
import { z } from 'zod'
|
||||
import { ItemType } from '../../items/enums'
|
||||
import { itemBaseSchema } from '../../items/baseSchemas'
|
||||
import { blockBaseSchema } from '../baseSchemas'
|
||||
import { LogicBlockType } from './enums'
|
||||
|
||||
export enum LogicalOperator {
|
||||
OR = 'OR',
|
||||
AND = 'AND',
|
||||
}
|
||||
|
||||
export enum ComparisonOperators {
|
||||
EQUAL = 'Equal to',
|
||||
NOT_EQUAL = 'Not equal',
|
||||
CONTAINS = 'Contains',
|
||||
GREATER = 'Greater than',
|
||||
LESS = 'Less than',
|
||||
IS_SET = 'Is set',
|
||||
}
|
||||
|
||||
const comparisonSchema = z.object({
|
||||
id: z.string(),
|
||||
variableId: z.string().optional(),
|
||||
comparisonOperator: z.nativeEnum(ComparisonOperators).optional(),
|
||||
value: z.string().optional(),
|
||||
})
|
||||
|
||||
const conditionContentSchema = z.object({
|
||||
logicalOperator: z.nativeEnum(LogicalOperator),
|
||||
comparisons: z.array(comparisonSchema),
|
||||
})
|
||||
|
||||
export const conditionItemSchema = itemBaseSchema.merge(
|
||||
z.object({
|
||||
type: z.literal(ItemType.CONDITION),
|
||||
content: conditionContentSchema,
|
||||
})
|
||||
)
|
||||
|
||||
export const conditionBlockSchema = blockBaseSchema.merge(
|
||||
z.object({
|
||||
type: z.enum([LogicBlockType.CONDITION]),
|
||||
items: z.array(conditionItemSchema),
|
||||
})
|
||||
)
|
||||
|
||||
export const defaultConditionContent: ConditionContent = {
|
||||
comparisons: [],
|
||||
logicalOperator: LogicalOperator.AND,
|
||||
}
|
||||
|
||||
export type ConditionItem = z.infer<typeof conditionItemSchema>
|
||||
export type Comparison = z.infer<typeof comparisonSchema>
|
||||
export type ConditionBlock = z.infer<typeof conditionBlockSchema>
|
||||
export type ConditionContent = z.infer<typeof conditionContentSchema>
|
||||
9
packages/schemas/features/blocks/logic/enums.ts
Normal file
9
packages/schemas/features/blocks/logic/enums.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
export enum LogicBlockType {
|
||||
SET_VARIABLE = 'Set variable',
|
||||
CONDITION = 'Condition',
|
||||
REDIRECT = 'Redirect',
|
||||
SCRIPT = 'Code',
|
||||
TYPEBOT_LINK = 'Typebot link',
|
||||
WAIT = 'Wait',
|
||||
JUMP = 'Jump',
|
||||
}
|
||||
7
packages/schemas/features/blocks/logic/index.ts
Normal file
7
packages/schemas/features/blocks/logic/index.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
export * from './script'
|
||||
export * from './condition'
|
||||
export * from './enums'
|
||||
export * from './redirect'
|
||||
export * from './setVariable'
|
||||
export * from './typebotLink'
|
||||
export * from './wait'
|
||||
17
packages/schemas/features/blocks/logic/jump.ts
Normal file
17
packages/schemas/features/blocks/logic/jump.ts
Normal file
@@ -0,0 +1,17 @@
|
||||
import { z } from 'zod'
|
||||
import { blockBaseSchema } from '../baseSchemas'
|
||||
import { LogicBlockType } from './enums'
|
||||
|
||||
export const jumpOptionsSchema = z.object({
|
||||
groupId: z.string().optional(),
|
||||
blockId: z.string().optional(),
|
||||
})
|
||||
|
||||
export const jumpBlockSchema = blockBaseSchema.merge(
|
||||
z.object({
|
||||
type: z.enum([LogicBlockType.JUMP]),
|
||||
options: jumpOptionsSchema,
|
||||
})
|
||||
)
|
||||
|
||||
export type JumpBlock = z.infer<typeof jumpBlockSchema>
|
||||
20
packages/schemas/features/blocks/logic/redirect.ts
Normal file
20
packages/schemas/features/blocks/logic/redirect.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
import { z } from 'zod'
|
||||
import { blockBaseSchema } from '../baseSchemas'
|
||||
import { LogicBlockType } from './enums'
|
||||
|
||||
export const redirectOptionsSchema = z.object({
|
||||
url: z.string().optional(),
|
||||
isNewTab: z.boolean(),
|
||||
})
|
||||
|
||||
export const redirectBlockSchema = blockBaseSchema.merge(
|
||||
z.object({
|
||||
type: z.enum([LogicBlockType.REDIRECT]),
|
||||
options: redirectOptionsSchema,
|
||||
})
|
||||
)
|
||||
|
||||
export const defaultRedirectOptions: RedirectOptions = { isNewTab: false }
|
||||
|
||||
export type RedirectBlock = z.infer<typeof redirectBlockSchema>
|
||||
export type RedirectOptions = z.infer<typeof redirectOptionsSchema>
|
||||
21
packages/schemas/features/blocks/logic/script.ts
Normal file
21
packages/schemas/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.merge(
|
||||
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>
|
||||
21
packages/schemas/features/blocks/logic/setVariable.ts
Normal file
21
packages/schemas/features/blocks/logic/setVariable.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
import { z } from 'zod'
|
||||
import { blockBaseSchema } from '../baseSchemas'
|
||||
import { LogicBlockType } from './enums'
|
||||
|
||||
export const setVariableOptionsSchema = z.object({
|
||||
variableId: z.string().optional(),
|
||||
expressionToEvaluate: z.string().optional(),
|
||||
isCode: z.boolean().optional(),
|
||||
})
|
||||
|
||||
export const setVariableBlockSchema = blockBaseSchema.merge(
|
||||
z.object({
|
||||
type: z.enum([LogicBlockType.SET_VARIABLE]),
|
||||
options: setVariableOptionsSchema,
|
||||
})
|
||||
)
|
||||
|
||||
export const defaultSetVariablesOptions: SetVariableOptions = {}
|
||||
|
||||
export type SetVariableBlock = z.infer<typeof setVariableBlockSchema>
|
||||
export type SetVariableOptions = z.infer<typeof setVariableOptionsSchema>
|
||||
20
packages/schemas/features/blocks/logic/typebotLink.ts
Normal file
20
packages/schemas/features/blocks/logic/typebotLink.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
import { z } from 'zod'
|
||||
import { blockBaseSchema } from '../baseSchemas'
|
||||
import { LogicBlockType } from './enums'
|
||||
|
||||
export const typebotLinkOptionsSchema = z.object({
|
||||
typebotId: z.string().optional(),
|
||||
groupId: z.string().optional(),
|
||||
})
|
||||
|
||||
export const typebotLinkBlockSchema = blockBaseSchema.merge(
|
||||
z.object({
|
||||
type: z.enum([LogicBlockType.TYPEBOT_LINK]),
|
||||
options: typebotLinkOptionsSchema,
|
||||
})
|
||||
)
|
||||
|
||||
export const defaultTypebotLinkOptions: TypebotLinkOptions = {}
|
||||
|
||||
export type TypebotLinkBlock = z.infer<typeof typebotLinkBlockSchema>
|
||||
export type TypebotLinkOptions = z.infer<typeof typebotLinkOptionsSchema>
|
||||
19
packages/schemas/features/blocks/logic/wait.ts
Normal file
19
packages/schemas/features/blocks/logic/wait.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
import { z } from 'zod'
|
||||
import { blockBaseSchema } from '../baseSchemas'
|
||||
import { LogicBlockType } from './enums'
|
||||
|
||||
export const waitOptionsSchema = z.object({
|
||||
secondsToWaitFor: z.string().optional(),
|
||||
})
|
||||
|
||||
export const waitBlockSchema = blockBaseSchema.merge(
|
||||
z.object({
|
||||
type: z.enum([LogicBlockType.WAIT]),
|
||||
options: waitOptionsSchema,
|
||||
})
|
||||
)
|
||||
|
||||
export const defaultWaitOptions: WaitOptions = {}
|
||||
|
||||
export type WaitBlock = z.infer<typeof waitBlockSchema>
|
||||
export type WaitOptions = z.infer<typeof waitOptionsSchema>
|
||||
Reference in New Issue
Block a user