2
0

(engine) Improve engine overall robustness

This commit is contained in:
Baptiste Arnaud
2023-01-25 11:27:47 +01:00
parent ff62b922a0
commit 30baa611e5
210 changed files with 1820 additions and 1919 deletions

View File

@ -0,0 +1,32 @@
import { z } from 'zod'
import { blockBaseSchema } from '../baseSchemas'
import { IntegrationBlockType } from './enums'
export const chatwootOptionsSchema = z.object({
baseUrl: z.string(),
websiteToken: z.string(),
user: z
.object({
id: z.string().optional(),
email: z.string().optional(),
name: z.string().optional(),
avatarUrl: z.string().optional(),
phoneNumber: z.string().optional(),
})
.optional(),
})
export const chatwootBlockSchema = blockBaseSchema.and(
z.object({
type: z.enum([IntegrationBlockType.CHATWOOT]),
options: chatwootOptionsSchema,
})
)
export const defaultChatwootOptions: ChatwootOptions = {
baseUrl: 'https://app.chatwoot.com',
websiteToken: '',
}
export type ChatwootBlock = z.infer<typeof chatwootBlockSchema>
export type ChatwootOptions = z.infer<typeof chatwootOptionsSchema>

View File

@ -0,0 +1,10 @@
export enum IntegrationBlockType {
GOOGLE_SHEETS = 'Google Sheets',
GOOGLE_ANALYTICS = 'Google Analytics',
WEBHOOK = 'Webhook',
EMAIL = 'Email',
ZAPIER = 'Zapier',
MAKE_COM = 'Make.com',
PABBLY_CONNECT = 'Pabbly',
CHATWOOT = 'Chatwoot',
}

View File

@ -0,0 +1,25 @@
import { z } from 'zod'
import { blockBaseSchema } from '../baseSchemas'
import { IntegrationBlockType } from './enums'
export const googleAnalyticsOptionsSchema = z.object({
trackingId: z.string().optional(),
category: z.string().optional(),
action: z.string().optional(),
label: z.string().optional(),
value: z.number().optional(),
})
export const googleAnalyticsBlockSchema = blockBaseSchema.and(
z.object({
type: z.enum([IntegrationBlockType.GOOGLE_ANALYTICS]),
options: googleAnalyticsOptionsSchema,
})
)
export const defaultGoogleAnalyticsOptions: GoogleAnalyticsOptions = {}
export type GoogleAnalyticsBlock = z.infer<typeof googleAnalyticsBlockSchema>
export type GoogleAnalyticsOptions = z.infer<
typeof googleAnalyticsOptionsSchema
>

View File

@ -0,0 +1,5 @@
export enum GoogleSheetsAction {
GET = 'Get data from sheet',
INSERT_ROW = 'Insert a row',
UPDATE_ROW = 'Update a row',
}

View File

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

View File

@ -0,0 +1,126 @@
import { z } from 'zod'
import { ComparisonOperators, LogicalOperator } from '../../logic/condition'
import cuid from 'cuid'
import { IntegrationBlockType } from '../enums'
import { GoogleSheetsAction } from './enums'
import { blockBaseSchema } from '../../baseSchemas'
const cellSchema = z.object({
column: z.string().optional(),
value: z.string().optional(),
id: z.string(),
})
const extractingCellSchema = z.object({
column: z.string().optional(),
id: z.string(),
variableId: z.string().optional(),
})
const googleSheetsOptionsBaseSchema = z.object({
credentialsId: z.string().optional(),
sheetId: z.string().optional(),
spreadsheetId: z.string().optional(),
})
const rowsFilterComparisonSchema = z.object({
id: z.string(),
column: z.string().optional(),
comparisonOperator: z.nativeEnum(ComparisonOperators).optional(),
value: z.string().optional(),
})
const googleSheetsGetOptionsSchema = googleSheetsOptionsBaseSchema.and(
z.object({
action: z.enum([GoogleSheetsAction.GET]),
// TODO: remove referenceCell once migrated to filtering
referenceCell: cellSchema.optional(),
filter: z.object({
comparisons: z.array(rowsFilterComparisonSchema),
logicalOperator: z.nativeEnum(LogicalOperator),
}),
cellsToExtract: z.array(extractingCellSchema),
})
)
const googleSheetsInsertRowOptionsSchema = googleSheetsOptionsBaseSchema.and(
z.object({
action: z.enum([GoogleSheetsAction.INSERT_ROW]),
cellsToInsert: z.array(cellSchema),
})
)
const googleSheetsUpdateRowOptionsSchema = googleSheetsOptionsBaseSchema.and(
z.object({
action: z.enum([GoogleSheetsAction.UPDATE_ROW]),
cellsToUpsert: z.array(cellSchema),
referenceCell: cellSchema.optional(),
})
)
export const googleSheetsOptionsSchema = googleSheetsGetOptionsSchema
.or(googleSheetsInsertRowOptionsSchema)
.or(googleSheetsUpdateRowOptionsSchema)
.or(googleSheetsOptionsBaseSchema)
export const googleSheetsBlockSchema = blockBaseSchema.and(
z.object({
type: z.enum([IntegrationBlockType.GOOGLE_SHEETS]),
options: googleSheetsOptionsSchema,
})
)
export const defaultGoogleSheetsOptions: GoogleSheetsOptions = {}
export const defaultGoogleSheetsGetOptions: GoogleSheetsGetOptions = {
action: GoogleSheetsAction.GET,
cellsToExtract: [
{
id: cuid(),
},
],
filter: {
comparisons: [
{
id: cuid(),
},
],
logicalOperator: LogicalOperator.AND,
},
}
export const defaultGoogleSheetsInsertOptions: GoogleSheetsInsertRowOptions = {
action: GoogleSheetsAction.INSERT_ROW,
cellsToInsert: [
{
id: cuid(),
},
],
}
export const defaultGoogleSheetsUpdateOptions: GoogleSheetsUpdateRowOptions = {
action: GoogleSheetsAction.UPDATE_ROW,
cellsToUpsert: [
{
id: cuid(),
},
],
}
export type GoogleSheetsBlock = z.infer<typeof googleSheetsBlockSchema>
export type GoogleSheetsOptions = z.infer<typeof googleSheetsOptionsSchema>
export type GoogleSheetsOptionsBase = z.infer<
typeof googleSheetsOptionsBaseSchema
>
export type GoogleSheetsGetOptions = z.infer<
typeof googleSheetsGetOptionsSchema
>
export type GoogleSheetsInsertRowOptions = z.infer<
typeof googleSheetsInsertRowOptionsSchema
>
export type GoogleSheetsUpdateRowOptions = z.infer<
typeof googleSheetsUpdateRowOptionsSchema
>
export type Cell = z.infer<typeof cellSchema>
export type ExtractingCell = z.infer<typeof extractingCellSchema>
export type RowsFilterComparison = z.infer<typeof rowsFilterComparisonSchema>

View File

@ -0,0 +1,10 @@
export * from './chatwoot'
export * from './enums'
export * from './googleAnalytics'
export * from './googleSheets'
export * from './makeCom'
export * from './pabblyConnect'
export * from './schemas'
export * from './sendEmail'
export * from './webhook'
export * from './zapier'

View File

@ -0,0 +1,14 @@
import { z } from 'zod'
import { blockBaseSchema } from '../baseSchemas'
import { IntegrationBlockType } from './enums'
import { webhookOptionsSchema } from './webhook'
export const makeComBlockSchema = blockBaseSchema.and(
z.object({
type: z.enum([IntegrationBlockType.MAKE_COM]),
options: webhookOptionsSchema,
webhookId: z.string(),
})
)
export type MakeComBlock = z.infer<typeof makeComBlockSchema>

View File

@ -0,0 +1,14 @@
import { z } from 'zod'
import { blockBaseSchema } from '../baseSchemas'
import { IntegrationBlockType } from './enums'
import { webhookOptionsSchema } from './webhook'
export const pabblyConnectBlockSchema = blockBaseSchema.and(
z.object({
type: z.enum([IntegrationBlockType.PABBLY_CONNECT]),
options: webhookOptionsSchema,
webhookId: z.string(),
})
)
export type PabblyConnectBlock = z.infer<typeof pabblyConnectBlockSchema>

View File

@ -0,0 +1,35 @@
import { z } from 'zod'
import { chatwootBlockSchema, chatwootOptionsSchema } from './chatwoot'
import {
googleAnalyticsOptionsSchema,
googleAnalyticsBlockSchema,
} from './googleAnalytics'
import {
googleSheetsOptionsSchema,
googleSheetsBlockSchema,
} from './googleSheets/schemas'
import { makeComBlockSchema } from './makeCom'
import { pabblyConnectBlockSchema } from './pabblyConnect'
import { sendEmailOptionsSchema, sendEmailBlockSchema } from './sendEmail'
import { webhookOptionsSchema, webhookBlockSchema } from './webhook'
import { zapierBlockSchema } from './zapier'
const integrationBlockOptionsSchema = googleSheetsOptionsSchema
.or(googleAnalyticsOptionsSchema)
.or(webhookOptionsSchema)
.or(sendEmailOptionsSchema)
.or(chatwootOptionsSchema)
export const integrationBlockSchema = googleSheetsBlockSchema
.or(googleAnalyticsBlockSchema)
.or(webhookBlockSchema)
.or(sendEmailBlockSchema)
.or(zapierBlockSchema)
.or(makeComBlockSchema)
.or(pabblyConnectBlockSchema)
.or(chatwootBlockSchema)
export type IntegrationBlock = z.infer<typeof integrationBlockSchema>
export type IntegrationBlockOptions = z.infer<
typeof integrationBlockOptionsSchema
>

View File

@ -0,0 +1,32 @@
import { z } from 'zod'
import { blockBaseSchema } from '../baseSchemas'
import { IntegrationBlockType } from './enums'
export const sendEmailOptionsSchema = z.object({
credentialsId: z.string(),
isCustomBody: z.boolean().optional(),
isBodyCode: z.boolean().optional(),
recipients: z.array(z.string()),
subject: z.string().optional(),
body: z.string().optional(),
replyTo: z.string().optional(),
cc: z.array(z.string()).optional(),
bcc: z.array(z.string()).optional(),
attachmentsVariableId: z.string().optional(),
})
export const sendEmailBlockSchema = blockBaseSchema.and(
z.object({
type: z.enum([IntegrationBlockType.EMAIL]),
options: sendEmailOptionsSchema,
})
)
export const defaultSendEmailOptions: SendEmailOptions = {
credentialsId: 'default',
isCustomBody: false,
recipients: [],
}
export type SendEmailBlock = z.infer<typeof sendEmailBlockSchema>
export type SendEmailOptions = z.infer<typeof sendEmailOptionsSchema>

View File

@ -0,0 +1,44 @@
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(),
})
export const webhookBlockSchema = blockBaseSchema.and(
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>

View File

@ -0,0 +1,14 @@
import { z } from 'zod'
import { blockBaseSchema } from '../baseSchemas'
import { IntegrationBlockType } from './enums'
import { webhookOptionsSchema } from './webhook'
export const zapierBlockSchema = blockBaseSchema.and(
z.object({
type: z.enum([IntegrationBlockType.ZAPIER]),
options: webhookOptionsSchema,
webhookId: z.string(),
})
)
export type ZapierBlock = z.infer<typeof zapierBlockSchema>