0
Fork 0
mirror of https://github.com/logto-io/logto.git synced 2025-02-17 22:04:19 -05:00

refactor(schemas): update email service data guard (#4159)

This commit is contained in:
Darcy Ye 2023-07-12 14:32:41 +08:00 committed by GitHub
parent 6b54d9190d
commit 99e346e55a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,4 +1,3 @@
import { verificationCodeTypeGuard } from '@logto/connector-kit';
import type { ZodType } from 'zod';
import { z } from 'zod';
@ -70,33 +69,12 @@ export enum EmailServiceProvider {
SendGrid = 'SendGrid',
}
/**
* `General` is now used as a fallback scenario.
* This will be extended in the future since we will send different emails for
* different purposes (such as webhook that inform users of suspicious account activities).
*/
export enum OtherEmailTemplate {
General = 'General',
}
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,
templateId: z.string(),
fromName: z.string(),
fromEmail: z.string(),
});
export type SendgridEmailServiceData = z.infer<typeof sendgridEmailServiceDataGuard>;