mirror of
https://github.com/logto-io/logto.git
synced 2025-02-17 22:04:19 -05:00
feat(schemas): add new email templates table (#7002)
* feat(schemas): add new email templates table add new email templates table * fix(schemas): fix the alteration script syntax error fix the alteration script syntax error
This commit is contained in:
parent
14d1703b71
commit
e6a9ed5670
4 changed files with 98 additions and 0 deletions
|
@ -0,0 +1,40 @@
|
|||
import { sql } from '@silverhand/slonik';
|
||||
|
||||
import type { AlterationScript } from '../lib/types/alteration.js';
|
||||
|
||||
import { applyTableRls, dropTableRls } from './utils/1704934999-tables.js';
|
||||
|
||||
const alteration: AlterationScript = {
|
||||
up: async (pool) => {
|
||||
await pool.query(sql`
|
||||
create table email_templates (
|
||||
tenant_id varchar(21) not null
|
||||
references tenants (id) on update cascade on delete cascade,
|
||||
id varchar(21) not null,
|
||||
language_tag varchar(16) not null,
|
||||
template_type varchar(64) not null,
|
||||
details jsonb not null,
|
||||
created_at timestamptz not null default now(),
|
||||
primary key (tenant_id, id),
|
||||
constraint email_templates__tenant_id__language_tag__template_type
|
||||
unique (tenant_id, language_tag, template_type)
|
||||
);
|
||||
|
||||
create index email_templates__tenant_id__language_tag
|
||||
on email_templates (tenant_id, language_tag);
|
||||
|
||||
create index email_templates__tenant_id__template_type
|
||||
on email_templates (tenant_id, template_type);
|
||||
`);
|
||||
|
||||
await applyTableRls(pool, 'email_templates');
|
||||
},
|
||||
down: async (pool) => {
|
||||
await dropTableRls(pool, 'email_templates');
|
||||
await pool.query(sql`
|
||||
drop table if exists email_templates;
|
||||
`);
|
||||
},
|
||||
};
|
||||
|
||||
export default alteration;
|
|
@ -0,0 +1,39 @@
|
|||
import { z } from 'zod';
|
||||
|
||||
export { TemplateType, templateTypeGuard } from '@logto/connector-kit';
|
||||
|
||||
export type EmailTemplateDetails = {
|
||||
subject: string;
|
||||
content: string;
|
||||
/**
|
||||
* OPTIONAL: The content type of the email template.
|
||||
*
|
||||
* Some email clients may render email templates differently based on the content type. (e.g. Sendgrid, Mailgun)
|
||||
* Use this field to specify the content type of the email template.
|
||||
*/
|
||||
contentType?: 'text/html' | 'text/plain';
|
||||
/**
|
||||
* OPTIONAL: Custom replyTo template.
|
||||
*
|
||||
* Based on the email client, the replyTo field may be used to customize the reply-to field of the email.
|
||||
* @remarks
|
||||
* The original reply email value can be found in the template variables.
|
||||
*/
|
||||
replyTo?: string;
|
||||
/**
|
||||
* OPTIONAL: Custom from template.
|
||||
*
|
||||
* Based on the email client, the sendFrom field may be used to customize the from field of the email.
|
||||
* @remarks
|
||||
* The sender email value can be found in the template variables.
|
||||
*/
|
||||
sendFrom?: string;
|
||||
};
|
||||
|
||||
export const emailTemplateDetailsGuard = z.object({
|
||||
subject: z.string(),
|
||||
content: z.string(),
|
||||
contentType: z.union([z.literal('text/html'), z.literal('text/plain')]).optional(),
|
||||
replyTo: z.string().optional(),
|
||||
sendFrom: z.string().optional(),
|
||||
}) satisfies z.ZodType<EmailTemplateDetails>;
|
|
@ -12,6 +12,7 @@ export * from './verification-records.js';
|
|||
export * from './account-centers.js';
|
||||
export * from './saml-application-configs.js';
|
||||
export * from './saml-application-sessions.js';
|
||||
export * from './email-templates.js';
|
||||
|
||||
export {
|
||||
configurableConnectorMetadataGuard,
|
||||
|
|
18
packages/schemas/tables/email_templates.sql
Normal file
18
packages/schemas/tables/email_templates.sql
Normal file
|
@ -0,0 +1,18 @@
|
|||
create table email_templates (
|
||||
tenant_id varchar(21) not null
|
||||
references tenants (id) on update cascade on delete cascade,
|
||||
id varchar(21) not null,
|
||||
language_tag varchar(16) not null,
|
||||
template_type varchar(64) /* @use TemplateType */ not null,
|
||||
details jsonb /* @use EmailTemplateDetails */ not null,
|
||||
created_at timestamptz not null default now(),
|
||||
primary key (tenant_id, id),
|
||||
constraint email_templates__tenant_id__language_tag__template_type
|
||||
unique (tenant_id, language_tag, template_type)
|
||||
);
|
||||
|
||||
create index email_templates__tenant_id__language_tag
|
||||
on email_templates (tenant_id, language_tag);
|
||||
|
||||
create index email_templates__tenant_id__template_type
|
||||
on email_templates (tenant_id, template_type);
|
Loading…
Add table
Reference in a new issue