♻️ Re-organize workspace folders
This commit is contained in:
36
packages/schemas/features/blocks/integrations/chatwoot.ts
Normal file
36
packages/schemas/features/blocks/integrations/chatwoot.ts
Normal file
@@ -0,0 +1,36 @@
|
||||
import { z } from 'zod'
|
||||
import { blockBaseSchema } from '../baseSchemas'
|
||||
import { IntegrationBlockType } from './enums'
|
||||
|
||||
export const chatwootTasks = ['Show widget', 'Close widget'] as const
|
||||
|
||||
export const chatwootOptionsSchema = z.object({
|
||||
task: z.enum(chatwootTasks).optional(),
|
||||
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.merge(
|
||||
z.object({
|
||||
type: z.enum([IntegrationBlockType.CHATWOOT]),
|
||||
options: chatwootOptionsSchema,
|
||||
})
|
||||
)
|
||||
|
||||
export const defaultChatwootOptions: ChatwootOptions = {
|
||||
task: 'Show widget',
|
||||
baseUrl: 'https://app.chatwoot.com',
|
||||
websiteToken: '',
|
||||
}
|
||||
|
||||
export type ChatwootBlock = z.infer<typeof chatwootBlockSchema>
|
||||
export type ChatwootOptions = z.infer<typeof chatwootOptionsSchema>
|
||||
11
packages/schemas/features/blocks/integrations/enums.ts
Normal file
11
packages/schemas/features/blocks/integrations/enums.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
export enum IntegrationBlockType {
|
||||
GOOGLE_SHEETS = 'Google Sheets',
|
||||
OPEN_AI = 'OpenAI',
|
||||
GOOGLE_ANALYTICS = 'Google Analytics',
|
||||
WEBHOOK = 'Webhook',
|
||||
EMAIL = 'Email',
|
||||
ZAPIER = 'Zapier',
|
||||
MAKE_COM = 'Make.com',
|
||||
PABBLY_CONNECT = 'Pabbly',
|
||||
CHATWOOT = 'Chatwoot',
|
||||
}
|
||||
@@ -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.merge(
|
||||
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
|
||||
>
|
||||
@@ -0,0 +1,5 @@
|
||||
export enum GoogleSheetsAction {
|
||||
GET = 'Get data from sheet',
|
||||
INSERT_ROW = 'Insert a row',
|
||||
UPDATE_ROW = 'Update a row',
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
export * from './enums'
|
||||
export * from './schemas'
|
||||
@@ -0,0 +1,156 @@
|
||||
import { z } from 'zod'
|
||||
import { ComparisonOperators, LogicalOperator } from '../../logic/condition'
|
||||
import { IntegrationBlockType } from '../enums'
|
||||
import { GoogleSheetsAction } from './enums'
|
||||
import { blockBaseSchema, credentialsBaseSchema } 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 initialGoogleSheetsOptionsSchema = googleSheetsOptionsBaseSchema.merge(
|
||||
z.object({
|
||||
action: z.undefined(),
|
||||
})
|
||||
)
|
||||
|
||||
const googleSheetsGetOptionsSchema = googleSheetsOptionsBaseSchema.merge(
|
||||
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.merge(
|
||||
z.object({
|
||||
action: z.enum([GoogleSheetsAction.INSERT_ROW]),
|
||||
cellsToInsert: z.array(cellSchema),
|
||||
})
|
||||
)
|
||||
|
||||
const googleSheetsUpdateRowOptionsSchema = googleSheetsOptionsBaseSchema.merge(
|
||||
z.object({
|
||||
action: z.enum([GoogleSheetsAction.UPDATE_ROW]),
|
||||
cellsToUpsert: z.array(cellSchema),
|
||||
referenceCell: cellSchema.optional(),
|
||||
})
|
||||
)
|
||||
|
||||
export const googleSheetsOptionsSchema = z.discriminatedUnion('action', [
|
||||
googleSheetsGetOptionsSchema,
|
||||
googleSheetsInsertRowOptionsSchema,
|
||||
googleSheetsUpdateRowOptionsSchema,
|
||||
initialGoogleSheetsOptionsSchema,
|
||||
])
|
||||
|
||||
export const googleSheetsBlockSchema = blockBaseSchema.merge(
|
||||
z.object({
|
||||
type: z.enum([IntegrationBlockType.GOOGLE_SHEETS]),
|
||||
options: googleSheetsOptionsSchema,
|
||||
})
|
||||
)
|
||||
|
||||
export const googleSheetsCredentialsSchema = z
|
||||
.object({
|
||||
type: z.literal('google sheets'),
|
||||
data: z.object({
|
||||
refresh_token: z.string().nullish(),
|
||||
expiry_date: z.number().nullish(),
|
||||
access_token: z.string().nullish(),
|
||||
token_type: z.string().nullish(),
|
||||
id_token: z.string().nullish(),
|
||||
scope: z.string().optional(),
|
||||
}),
|
||||
})
|
||||
.merge(credentialsBaseSchema)
|
||||
|
||||
export const defaultGoogleSheetsOptions: GoogleSheetsOptions = {}
|
||||
|
||||
export const defaultGoogleSheetsGetOptions = (
|
||||
createId: () => string
|
||||
): GoogleSheetsGetOptions => ({
|
||||
action: GoogleSheetsAction.GET,
|
||||
cellsToExtract: [
|
||||
{
|
||||
id: createId(),
|
||||
},
|
||||
],
|
||||
filter: {
|
||||
comparisons: [
|
||||
{
|
||||
id: createId(),
|
||||
},
|
||||
],
|
||||
logicalOperator: LogicalOperator.AND,
|
||||
},
|
||||
})
|
||||
|
||||
export const defaultGoogleSheetsInsertOptions = (
|
||||
createId: () => string
|
||||
): GoogleSheetsInsertRowOptions => ({
|
||||
action: GoogleSheetsAction.INSERT_ROW,
|
||||
cellsToInsert: [
|
||||
{
|
||||
id: createId(),
|
||||
},
|
||||
],
|
||||
})
|
||||
|
||||
export const defaultGoogleSheetsUpdateOptions = (
|
||||
createId: () => string
|
||||
): GoogleSheetsUpdateRowOptions => ({
|
||||
action: GoogleSheetsAction.UPDATE_ROW,
|
||||
cellsToUpsert: [
|
||||
{
|
||||
id: createId(),
|
||||
},
|
||||
],
|
||||
})
|
||||
|
||||
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>
|
||||
export type GoogleSheetsCredentials = z.infer<
|
||||
typeof googleSheetsCredentialsSchema
|
||||
>
|
||||
9
packages/schemas/features/blocks/integrations/index.ts
Normal file
9
packages/schemas/features/blocks/integrations/index.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
export * from './chatwoot'
|
||||
export * from './enums'
|
||||
export * from './googleAnalytics'
|
||||
export * from './googleSheets'
|
||||
export * from './makeCom'
|
||||
export * from './pabblyConnect'
|
||||
export * from './sendEmail'
|
||||
export * from './webhook'
|
||||
export * from './zapier'
|
||||
14
packages/schemas/features/blocks/integrations/makeCom.ts
Normal file
14
packages/schemas/features/blocks/integrations/makeCom.ts
Normal 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.merge(
|
||||
z.object({
|
||||
type: z.enum([IntegrationBlockType.MAKE_COM]),
|
||||
options: webhookOptionsSchema,
|
||||
webhookId: z.string(),
|
||||
})
|
||||
)
|
||||
|
||||
export type MakeComBlock = z.infer<typeof makeComBlockSchema>
|
||||
131
packages/schemas/features/blocks/integrations/openai.ts
Normal file
131
packages/schemas/features/blocks/integrations/openai.ts
Normal file
@@ -0,0 +1,131 @@
|
||||
import { z } from 'zod'
|
||||
import { blockBaseSchema, credentialsBaseSchema } from '../baseSchemas'
|
||||
import { IntegrationBlockType } from './enums'
|
||||
|
||||
export const openAITasks = ['Create chat completion', 'Create image'] as const
|
||||
|
||||
export const chatCompletionModels = [
|
||||
'gpt-3.5-turbo',
|
||||
'gpt-3.5-turbo-0301',
|
||||
] as const
|
||||
|
||||
export const chatCompletionMessageRoles = [
|
||||
'system',
|
||||
'user',
|
||||
'assistant',
|
||||
] as const
|
||||
|
||||
export const chatCompletionMessageCustomRoles = [
|
||||
'Messages sequence ✨',
|
||||
] as const
|
||||
|
||||
export const chatCompletionResponseValues = [
|
||||
'Message content',
|
||||
'Total tokens',
|
||||
] as const
|
||||
|
||||
const openAIBaseOptionsSchema = z.object({
|
||||
credentialsId: z.string().optional(),
|
||||
})
|
||||
|
||||
const initialOptionsSchema = z
|
||||
.object({
|
||||
task: z.undefined(),
|
||||
})
|
||||
.merge(openAIBaseOptionsSchema)
|
||||
|
||||
const chatCompletionMessageSchema = z.object({
|
||||
id: z.string(),
|
||||
role: z.enum(chatCompletionMessageRoles).optional(),
|
||||
content: z.string().optional(),
|
||||
})
|
||||
|
||||
const chatCompletionCustomMessageSchema = z.object({
|
||||
id: z.string(),
|
||||
role: z.enum(chatCompletionMessageCustomRoles),
|
||||
content: z
|
||||
.object({
|
||||
assistantMessagesVariableId: z.string().optional(),
|
||||
userMessagesVariableId: z.string().optional(),
|
||||
})
|
||||
.optional(),
|
||||
})
|
||||
|
||||
const chatCompletionOptionsSchema = z
|
||||
.object({
|
||||
task: z.literal(openAITasks[0]),
|
||||
model: z.enum(chatCompletionModels),
|
||||
messages: z.array(
|
||||
z.union([chatCompletionMessageSchema, chatCompletionCustomMessageSchema])
|
||||
),
|
||||
responseMapping: z.array(
|
||||
z.object({
|
||||
id: z.string(),
|
||||
valueToExtract: z.enum(chatCompletionResponseValues),
|
||||
variableId: z.string().optional(),
|
||||
})
|
||||
),
|
||||
})
|
||||
.merge(openAIBaseOptionsSchema)
|
||||
|
||||
const createImageOptionsSchema = z
|
||||
.object({
|
||||
task: z.literal(openAITasks[1]),
|
||||
prompt: z.string().optional(),
|
||||
advancedOptions: z.object({
|
||||
size: z.enum(['256x256', '512x512', '1024x1024']).optional(),
|
||||
}),
|
||||
responseMapping: z.array(
|
||||
z.object({
|
||||
id: z.string(),
|
||||
valueToExtract: z.enum(['Image URL']),
|
||||
variableId: z.string().optional(),
|
||||
})
|
||||
),
|
||||
})
|
||||
.merge(openAIBaseOptionsSchema)
|
||||
|
||||
export const openAIBlockSchema = blockBaseSchema.merge(
|
||||
z.object({
|
||||
type: z.enum([IntegrationBlockType.OPEN_AI]),
|
||||
options: z.discriminatedUnion('task', [
|
||||
initialOptionsSchema,
|
||||
chatCompletionOptionsSchema,
|
||||
createImageOptionsSchema,
|
||||
]),
|
||||
})
|
||||
)
|
||||
|
||||
export const openAICredentialsSchema = z
|
||||
.object({
|
||||
type: z.literal('openai'),
|
||||
data: z.object({
|
||||
apiKey: z.string(),
|
||||
}),
|
||||
})
|
||||
.merge(credentialsBaseSchema)
|
||||
|
||||
export const defaultChatCompletionOptions = (
|
||||
createId: () => string
|
||||
): ChatCompletionOpenAIOptions => ({
|
||||
task: 'Create chat completion',
|
||||
messages: [
|
||||
{
|
||||
id: createId(),
|
||||
},
|
||||
],
|
||||
responseMapping: [
|
||||
{
|
||||
id: createId(),
|
||||
valueToExtract: 'Message content',
|
||||
},
|
||||
],
|
||||
model: 'gpt-3.5-turbo',
|
||||
})
|
||||
|
||||
export type OpenAICredentials = z.infer<typeof openAICredentialsSchema>
|
||||
export type OpenAIBlock = z.infer<typeof openAIBlockSchema>
|
||||
export type ChatCompletionOpenAIOptions = z.infer<
|
||||
typeof chatCompletionOptionsSchema
|
||||
>
|
||||
export type CreateImageOpenAIOptions = z.infer<typeof createImageOptionsSchema>
|
||||
@@ -0,0 +1,14 @@
|
||||
import { z } from 'zod'
|
||||
import { blockBaseSchema } from '../baseSchemas'
|
||||
import { IntegrationBlockType } from './enums'
|
||||
import { webhookOptionsSchema } from './webhook'
|
||||
|
||||
export const pabblyConnectBlockSchema = blockBaseSchema.merge(
|
||||
z.object({
|
||||
type: z.enum([IntegrationBlockType.PABBLY_CONNECT]),
|
||||
options: webhookOptionsSchema,
|
||||
webhookId: z.string(),
|
||||
})
|
||||
)
|
||||
|
||||
export type PabblyConnectBlock = z.infer<typeof pabblyConnectBlockSchema>
|
||||
50
packages/schemas/features/blocks/integrations/sendEmail.ts
Normal file
50
packages/schemas/features/blocks/integrations/sendEmail.ts
Normal file
@@ -0,0 +1,50 @@
|
||||
import { z } from 'zod'
|
||||
import { blockBaseSchema, credentialsBaseSchema } 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.merge(
|
||||
z.object({
|
||||
type: z.enum([IntegrationBlockType.EMAIL]),
|
||||
options: sendEmailOptionsSchema,
|
||||
})
|
||||
)
|
||||
|
||||
export const smtpCredentialsSchema = z
|
||||
.object({
|
||||
type: z.literal('smtp'),
|
||||
data: z.object({
|
||||
host: z.string().optional(),
|
||||
username: z.string().optional(),
|
||||
password: z.string().optional(),
|
||||
isTlsEnabled: z.boolean().optional(),
|
||||
port: z.number(),
|
||||
from: z.object({
|
||||
email: z.string().optional(),
|
||||
name: z.string().optional(),
|
||||
}),
|
||||
}),
|
||||
})
|
||||
.merge(credentialsBaseSchema)
|
||||
|
||||
export const defaultSendEmailOptions: SendEmailOptions = {
|
||||
credentialsId: 'default',
|
||||
isCustomBody: false,
|
||||
recipients: [],
|
||||
}
|
||||
|
||||
export type SendEmailBlock = z.infer<typeof sendEmailBlockSchema>
|
||||
export type SendEmailOptions = z.infer<typeof sendEmailOptionsSchema>
|
||||
export type SmtpCredentials = z.infer<typeof smtpCredentialsSchema>
|
||||
44
packages/schemas/features/blocks/integrations/webhook.ts
Normal file
44
packages/schemas/features/blocks/integrations/webhook.ts
Normal 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.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>
|
||||
14
packages/schemas/features/blocks/integrations/zapier.ts
Normal file
14
packages/schemas/features/blocks/integrations/zapier.ts
Normal 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.merge(
|
||||
z.object({
|
||||
type: z.enum([IntegrationBlockType.ZAPIER]),
|
||||
options: webhookOptionsSchema,
|
||||
webhookId: z.string(),
|
||||
})
|
||||
)
|
||||
|
||||
export type ZapierBlock = z.infer<typeof zapierBlockSchema>
|
||||
Reference in New Issue
Block a user