From 3d3c82b1c5d37505a07c0af749eb36f55b7533b3 Mon Sep 17 00:00:00 2001 From: Darcy Ye Date: Wed, 28 Jun 2023 18:02:10 +0800 Subject: [PATCH] fix(schemas): fix sendgrid email service config (#4093) --- packages/schemas/src/types/system.ts | 34 +++++++++++++++++----------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/packages/schemas/src/types/system.ts b/packages/schemas/src/types/system.ts index 554fa82db..fa326a4cc 100644 --- a/packages/schemas/src/types/system.ts +++ b/packages/schemas/src/types/system.ts @@ -81,20 +81,28 @@ export enum OtherEmailTemplate { export const otherEmailTemplateGuard = z.nativeEnum(OtherEmailTemplate); +const emailServiceBasicConfig = { + fromName: z.string(), + fromEmail: z.string(), + templates: z.record( + verificationCodeTypeGuard.or(otherEmailTemplateGuard), + z.object({ + subject: z.string(), + content: z.string(), + }) + ), +}; + +export const sendgridEmailServiceDataGuard = z.object({ + provider: z.literal(EmailServiceProvider.SendGrid), + apiKey: z.string(), + ...emailServiceBasicConfig, +}); + +export type SendgridEmailServiceData = z.infer; + export const emailServiceDataGuard = z.discriminatedUnion('provider', [ - z.object({ - provider: z.literal(EmailServiceProvider.SendGrid), - appId: z.string(), - appSecret: z.string(), - fromEmail: z.string(), - templates: z.record( - verificationCodeTypeGuard.or(otherEmailTemplateGuard), - z.object({ - subject: z.string(), - content: z.string(), - }) - ), - }), + sendgridEmailServiceDataGuard, ]); export type EmailServiceData = z.infer;