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,23 @@
import { WebhookBlockV6 } from './schema'
export enum HttpMethod {
POST = 'POST',
GET = 'GET',
PUT = 'PUT',
DELETE = 'DELETE',
PATCH = 'PATCH',
HEAD = 'HEAD',
CONNECT = 'CONNECT',
OPTIONS = 'OPTIONS',
TRACE = 'TRACE',
}
export const defaultWebhookAttributes = {
method: HttpMethod.POST,
} as const
export const defaultWebhookBlockOptions = {
isAdvancedConfig: false,
isCustomBody: false,
isExecutedOnClient: false,
} as const satisfies WebhookBlockV6['options']

View File

@ -1,11 +0,0 @@
export enum HttpMethod {
POST = 'POST',
GET = 'GET',
PUT = 'PUT',
DELETE = 'DELETE',
PATCH = 'PATCH',
HEAD = 'HEAD',
CONNECT = 'CONNECT',
OPTIONS = 'OPTIONS',
TRACE = 'TRACE',
}

View File

@ -1,2 +1 @@
export * from './enums'
export * from './schemas'
export * from './schema'

View File

@ -1,7 +1,7 @@
import { z } from 'zod'
import { blockBaseSchema } from '../../baseSchemas'
import { IntegrationBlockType } from '../enums'
import { HttpMethod } from './enums'
import { blockBaseSchema } from '../../shared'
import { IntegrationBlockType } from '../constants'
import { HttpMethod } from './constants'
const variableForTestSchema = z.object({
id: z.string(),
@ -21,54 +21,67 @@ const keyValueSchema = z.object({
value: z.string().optional(),
})
export const webhookSchema = z.object({
export const webhookV5Schema = z.object({
id: z.string(),
queryParams: keyValueSchema.array(),
headers: keyValueSchema.array(),
method: z.nativeEnum(HttpMethod),
queryParams: keyValueSchema.array().optional(),
headers: keyValueSchema.array().optional(),
method: z.nativeEnum(HttpMethod).optional(),
url: z.string().optional(),
body: z.string().optional(),
})
export const webhookOptionsSchema = z.object({
variablesForTest: z.array(variableForTestSchema),
responseVariableMapping: z.array(responseVariableMappingSchema),
const webhookSchemas = {
v5: webhookV5Schema,
v6: webhookV5Schema.omit({
id: true,
}),
}
const webhookSchema = z.union([webhookSchemas.v5, webhookSchemas.v6])
export const webhookOptionsV5Schema = z.object({
variablesForTest: z.array(variableForTestSchema).optional(),
responseVariableMapping: z.array(responseVariableMappingSchema).optional(),
isAdvancedConfig: z.boolean().optional(),
isCustomBody: z.boolean().optional(),
isExecutedOnClient: z.boolean().optional(),
webhook: webhookSchema.optional(),
webhook: webhookSchemas.v5.optional(),
})
export const webhookBlockSchema = blockBaseSchema.merge(
const webhookOptionsSchemas = {
v5: webhookOptionsV5Schema,
v6: webhookOptionsV5Schema.merge(
z.object({
webhook: webhookSchemas.v6.optional(),
})
),
}
const webhookBlockV5Schema = blockBaseSchema.merge(
z.object({
type: z.enum([IntegrationBlockType.WEBHOOK]),
options: webhookOptionsSchema,
webhookId: z
.string()
.describe('Deprecated, now integrated in webhook block options')
.optional(),
options: webhookOptionsSchemas.v5.optional(),
webhookId: z.string().optional(),
})
)
export const defaultWebhookAttributes: Omit<
Webhook,
'id' | 'body' | 'url' | 'typebotId' | 'createdAt' | 'updatedAt'
> = {
method: HttpMethod.POST,
headers: [],
queryParams: [],
export const webhookBlockSchemas = {
v5: webhookBlockV5Schema,
v6: webhookBlockV5Schema
.omit({
webhookId: true,
})
.merge(
z.object({
options: webhookOptionsSchemas.v6.optional(),
})
),
}
export const defaultWebhookOptions = (webhookId: string): WebhookOptions => ({
responseVariableMapping: [],
variablesForTest: [],
isAdvancedConfig: false,
isCustomBody: false,
webhook: {
id: webhookId,
...defaultWebhookAttributes,
},
})
const webhookBlockSchema = z.union([
webhookBlockSchemas.v5,
webhookBlockSchemas.v6,
])
export const executableWebhookSchema = z.object({
url: z.string(),
@ -88,7 +101,7 @@ export type ExecutableWebhook = z.infer<typeof executableWebhookSchema>
export type Webhook = z.infer<typeof webhookSchema>
export type WebhookBlock = z.infer<typeof webhookBlockSchema>
export type WebhookOptions = z.infer<typeof webhookOptionsSchema>
export type WebhookBlockV6 = z.infer<typeof webhookBlockSchemas.v6>
export type ResponseVariableMapping = z.infer<
typeof responseVariableMappingSchema
>