2022-06-07 08:49:12 +02:00
|
|
|
import { z } from 'zod'
|
2023-03-09 08:46:36 +01:00
|
|
|
import { blockBaseSchema, credentialsBaseSchema } from '../baseSchemas'
|
2023-01-25 11:27:47 +01:00
|
|
|
import { IntegrationBlockType } from './enums'
|
2022-06-07 08:49:12 +02:00
|
|
|
|
|
|
|
export const sendEmailOptionsSchema = z.object({
|
|
|
|
credentialsId: z.string(),
|
2022-06-12 09:05:10 +02:00
|
|
|
isCustomBody: z.boolean().optional(),
|
|
|
|
isBodyCode: z.boolean().optional(),
|
2022-06-07 08:49:12 +02:00
|
|
|
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(),
|
2022-06-24 16:18:07 +02:00
|
|
|
attachmentsVariableId: z.string().optional(),
|
2022-06-07 08:49:12 +02:00
|
|
|
})
|
|
|
|
|
2022-06-11 07:27:38 +02:00
|
|
|
export const sendEmailBlockSchema = blockBaseSchema.and(
|
2022-06-07 08:49:12 +02:00
|
|
|
z.object({
|
2022-06-11 07:27:38 +02:00
|
|
|
type: z.enum([IntegrationBlockType.EMAIL]),
|
2022-06-07 08:49:12 +02:00
|
|
|
options: sendEmailOptionsSchema,
|
|
|
|
})
|
|
|
|
)
|
|
|
|
|
2023-03-09 08:46:36 +01:00
|
|
|
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)
|
|
|
|
|
2022-06-07 08:49:12 +02:00
|
|
|
export const defaultSendEmailOptions: SendEmailOptions = {
|
|
|
|
credentialsId: 'default',
|
2022-06-15 16:34:35 +02:00
|
|
|
isCustomBody: false,
|
2022-06-07 08:49:12 +02:00
|
|
|
recipients: [],
|
|
|
|
}
|
|
|
|
|
2022-06-11 07:27:38 +02:00
|
|
|
export type SendEmailBlock = z.infer<typeof sendEmailBlockSchema>
|
2022-06-07 08:49:12 +02:00
|
|
|
export type SendEmailOptions = z.infer<typeof sendEmailOptionsSchema>
|
2023-03-09 08:46:36 +01:00
|
|
|
export type SmtpCredentials = z.infer<typeof smtpCredentialsSchema>
|