@ -5,7 +5,7 @@ export * from './googleSheets'
|
||||
export * from './makeCom'
|
||||
export * from './pabblyConnect'
|
||||
export * from './sendEmail'
|
||||
export * from './webhook'
|
||||
export * from './webhook/schemas'
|
||||
export * from './zapier'
|
||||
export * from './pixel/schemas'
|
||||
export * from './pixel/constants'
|
||||
|
@ -1,13 +1,16 @@
|
||||
import { z } from 'zod'
|
||||
import { blockBaseSchema } from '../baseSchemas'
|
||||
import { IntegrationBlockType } from './enums'
|
||||
import { webhookOptionsSchema } from './webhook'
|
||||
import { webhookOptionsSchema } from './webhook/schemas'
|
||||
|
||||
export const makeComBlockSchema = blockBaseSchema.merge(
|
||||
z.object({
|
||||
type: z.enum([IntegrationBlockType.MAKE_COM]),
|
||||
options: webhookOptionsSchema,
|
||||
webhookId: z.string(),
|
||||
webhookId: z
|
||||
.string()
|
||||
.describe('Deprecated, use webhook.id instead')
|
||||
.optional(),
|
||||
})
|
||||
)
|
||||
|
||||
|
@ -1,13 +1,16 @@
|
||||
import { z } from 'zod'
|
||||
import { blockBaseSchema } from '../baseSchemas'
|
||||
import { IntegrationBlockType } from './enums'
|
||||
import { webhookOptionsSchema } from './webhook'
|
||||
import { webhookOptionsSchema } from './webhook/schemas'
|
||||
|
||||
export const pabblyConnectBlockSchema = blockBaseSchema.merge(
|
||||
z.object({
|
||||
type: z.enum([IntegrationBlockType.PABBLY_CONNECT]),
|
||||
options: webhookOptionsSchema,
|
||||
webhookId: z.string(),
|
||||
webhookId: z
|
||||
.string()
|
||||
.describe('Deprecated, use webhook.id instead')
|
||||
.optional(),
|
||||
})
|
||||
)
|
||||
|
||||
|
@ -1,45 +0,0 @@
|
||||
import { z } from 'zod'
|
||||
import { blockBaseSchema } from '../baseSchemas'
|
||||
import { IntegrationBlockType } from './enums'
|
||||
|
||||
const variableForTestSchema = z.object({
|
||||
id: z.string(),
|
||||
variableId: z.string().optional(),
|
||||
value: z.string().optional(),
|
||||
})
|
||||
|
||||
const responseVariableMappingSchema = z.object({
|
||||
id: z.string(),
|
||||
variableId: z.string().optional(),
|
||||
bodyPath: z.string().optional(),
|
||||
})
|
||||
|
||||
export const webhookOptionsSchema = z.object({
|
||||
variablesForTest: z.array(variableForTestSchema),
|
||||
responseVariableMapping: z.array(responseVariableMappingSchema),
|
||||
isAdvancedConfig: z.boolean().optional(),
|
||||
isCustomBody: z.boolean().optional(),
|
||||
isExecutedOnClient: z.boolean().optional(),
|
||||
})
|
||||
|
||||
export const webhookBlockSchema = blockBaseSchema.merge(
|
||||
z.object({
|
||||
type: z.enum([IntegrationBlockType.WEBHOOK]),
|
||||
options: webhookOptionsSchema,
|
||||
webhookId: z.string(),
|
||||
})
|
||||
)
|
||||
|
||||
export const defaultWebhookOptions: Omit<WebhookOptions, 'webhookId'> = {
|
||||
responseVariableMapping: [],
|
||||
variablesForTest: [],
|
||||
isAdvancedConfig: false,
|
||||
isCustomBody: false,
|
||||
}
|
||||
|
||||
export type WebhookBlock = z.infer<typeof webhookBlockSchema>
|
||||
export type WebhookOptions = z.infer<typeof webhookOptionsSchema>
|
||||
export type ResponseVariableMapping = z.infer<
|
||||
typeof responseVariableMappingSchema
|
||||
>
|
||||
export type VariableForTest = z.infer<typeof variableForTestSchema>
|
@ -0,0 +1,11 @@
|
||||
export enum HttpMethod {
|
||||
POST = 'POST',
|
||||
GET = 'GET',
|
||||
PUT = 'PUT',
|
||||
DELETE = 'DELETE',
|
||||
PATCH = 'PATCH',
|
||||
HEAD = 'HEAD',
|
||||
CONNECT = 'CONNECT',
|
||||
OPTIONS = 'OPTIONS',
|
||||
TRACE = 'TRACE',
|
||||
}
|
@ -0,0 +1,2 @@
|
||||
export * from './enums'
|
||||
export * from './schemas'
|
@ -0,0 +1,95 @@
|
||||
import { z } from 'zod'
|
||||
import { blockBaseSchema } from '../../baseSchemas'
|
||||
import { IntegrationBlockType } from '../enums'
|
||||
import { HttpMethod } from './enums'
|
||||
|
||||
const variableForTestSchema = z.object({
|
||||
id: z.string(),
|
||||
variableId: z.string().optional(),
|
||||
value: z.string().optional(),
|
||||
})
|
||||
|
||||
const responseVariableMappingSchema = z.object({
|
||||
id: z.string(),
|
||||
variableId: z.string().optional(),
|
||||
bodyPath: z.string().optional(),
|
||||
})
|
||||
|
||||
const keyValueSchema = z.object({
|
||||
id: z.string(),
|
||||
key: z.string().optional(),
|
||||
value: z.string().optional(),
|
||||
})
|
||||
|
||||
export const webhookSchema = z.object({
|
||||
id: z.string(),
|
||||
queryParams: keyValueSchema.array(),
|
||||
headers: keyValueSchema.array(),
|
||||
method: z.nativeEnum(HttpMethod),
|
||||
url: z.string().optional(),
|
||||
body: z.string().optional(),
|
||||
})
|
||||
|
||||
export const webhookOptionsSchema = z.object({
|
||||
variablesForTest: z.array(variableForTestSchema),
|
||||
responseVariableMapping: z.array(responseVariableMappingSchema),
|
||||
isAdvancedConfig: z.boolean().optional(),
|
||||
isCustomBody: z.boolean().optional(),
|
||||
isExecutedOnClient: z.boolean().optional(),
|
||||
webhook: webhookSchema.optional(),
|
||||
})
|
||||
|
||||
export const webhookBlockSchema = blockBaseSchema.merge(
|
||||
z.object({
|
||||
type: z.enum([IntegrationBlockType.WEBHOOK]),
|
||||
options: webhookOptionsSchema,
|
||||
webhookId: z
|
||||
.string()
|
||||
.describe('Deprecated, now integrated in webhook block options')
|
||||
.optional(),
|
||||
})
|
||||
)
|
||||
|
||||
export const defaultWebhookAttributes: Omit<
|
||||
Webhook,
|
||||
'id' | 'body' | 'url' | 'typebotId' | 'createdAt' | 'updatedAt'
|
||||
> = {
|
||||
method: HttpMethod.POST,
|
||||
headers: [],
|
||||
queryParams: [],
|
||||
}
|
||||
|
||||
export const defaultWebhookOptions = (webhookId: string): WebhookOptions => ({
|
||||
responseVariableMapping: [],
|
||||
variablesForTest: [],
|
||||
isAdvancedConfig: false,
|
||||
isCustomBody: false,
|
||||
webhook: {
|
||||
id: webhookId,
|
||||
...defaultWebhookAttributes,
|
||||
},
|
||||
})
|
||||
|
||||
export const executableWebhookSchema = z.object({
|
||||
url: z.string(),
|
||||
headers: z.record(z.string()).optional(),
|
||||
body: z.unknown().optional(),
|
||||
method: z.nativeEnum(HttpMethod).optional(),
|
||||
})
|
||||
|
||||
export type KeyValue = { id: string; key?: string; value?: string }
|
||||
|
||||
export type WebhookResponse = {
|
||||
statusCode: number
|
||||
data?: unknown
|
||||
}
|
||||
|
||||
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 ResponseVariableMapping = z.infer<
|
||||
typeof responseVariableMappingSchema
|
||||
>
|
||||
export type VariableForTest = z.infer<typeof variableForTestSchema>
|
@ -1,13 +1,16 @@
|
||||
import { z } from 'zod'
|
||||
import { blockBaseSchema } from '../baseSchemas'
|
||||
import { IntegrationBlockType } from './enums'
|
||||
import { webhookOptionsSchema } from './webhook'
|
||||
import { webhookOptionsSchema } from './webhook/schemas'
|
||||
|
||||
export const zapierBlockSchema = blockBaseSchema.merge(
|
||||
z.object({
|
||||
type: z.enum([IntegrationBlockType.ZAPIER]),
|
||||
options: webhookOptionsSchema,
|
||||
webhookId: z.string(),
|
||||
webhookId: z
|
||||
.string()
|
||||
.describe('Deprecated, use webhook.id instead')
|
||||
.optional(),
|
||||
})
|
||||
)
|
||||
|
||||
|
Reference in New Issue
Block a user