Reorganize repo structure and standards references
This commit is contained in:
1 parent
3cb93a81be
commit
be2054274d
5885 files changed
+2588
-195
No files matched your search
@@ -0,0 +1,95 @@
|
||||
/**
|
||||
* Public entry-point for React-Email transactional templates.
|
||||
*
|
||||
* Dispatches a template-name plus props to the matching React component
|
||||
* and renders `{ html, text }` deterministically via react-dom/server.
|
||||
* The canonical entry-point for transactional mail rendering. Called
|
||||
* directly from the host application's mail wrapper (see
|
||||
* `apps/web/app/modules/emails/utils/EmailTemplates.ts`).
|
||||
*
|
||||
* Each entry intentionally accepts a small, explicit prop shape — we
|
||||
* do not pipe arbitrary objects into the templates, so a malicious
|
||||
* caller cannot inject extra React props.
|
||||
*/
|
||||
import { createElement, type ReactElement } from "react";
|
||||
import { renderReactEmail } from "./render-helpers.js";
|
||||
import { withBrandDefaults, type MailBrand } from "./_layout/theme.js";
|
||||
import { WelcomeEmail, type WelcomeEmailProps } from "./transactional/Welcome.js";
|
||||
import { MagicLinkEmail, type MagicLinkEmailProps } from "./transactional/MagicLink.js";
|
||||
import { PasswordResetEmail, type PasswordResetEmailProps } from "./transactional/PasswordReset.js";
|
||||
import { InvitationEmail, type InvitationEmailProps } from "./transactional/Invitation.js";
|
||||
import {
|
||||
SubscriptionSuccessEmail,
|
||||
type SubscriptionSuccessEmailProps,
|
||||
} from "./transactional/SubscriptionSuccess.js";
|
||||
import {
|
||||
SubscriptionFailedEmail,
|
||||
type SubscriptionFailedEmailProps,
|
||||
} from "./transactional/SubscriptionFailed.js";
|
||||
import { InvoiceSentEmail, type InvoiceSentEmailProps } from "./transactional/InvoiceSent.js";
|
||||
import { TenantNotificationEmail, type TenantNotificationEmailProps } from "./transactional/TenantNotification.js";
|
||||
|
||||
export type ReactTransactionalTemplateName =
|
||||
| "welcome"
|
||||
| "magic-link"
|
||||
| "password-reset"
|
||||
| "invitation"
|
||||
| "subscription-success"
|
||||
| "subscription-failed"
|
||||
| "invoice-sent"
|
||||
| "tenant-notification";
|
||||
|
||||
export type ReactTemplatePropsMap = {
|
||||
welcome: WelcomeEmailProps;
|
||||
"magic-link": MagicLinkEmailProps;
|
||||
"password-reset": PasswordResetEmailProps;
|
||||
invitation: InvitationEmailProps;
|
||||
"subscription-success": SubscriptionSuccessEmailProps;
|
||||
"subscription-failed": SubscriptionFailedEmailProps;
|
||||
"invoice-sent": InvoiceSentEmailProps;
|
||||
"tenant-notification": TenantNotificationEmailProps;
|
||||
};
|
||||
|
||||
export interface RenderedReactEmail {
|
||||
readonly html: string;
|
||||
readonly text: string;
|
||||
}
|
||||
|
||||
type AnyTemplateProps = ReactTemplatePropsMap[ReactTransactionalTemplateName];
|
||||
|
||||
const COMPONENTS: { [K in ReactTransactionalTemplateName]: (props: ReactTemplatePropsMap[K]) => ReactElement } = {
|
||||
welcome: WelcomeEmail,
|
||||
"magic-link": MagicLinkEmail,
|
||||
"password-reset": PasswordResetEmail,
|
||||
invitation: InvitationEmail,
|
||||
"subscription-success": SubscriptionSuccessEmail,
|
||||
"subscription-failed": SubscriptionFailedEmail,
|
||||
"invoice-sent": InvoiceSentEmail,
|
||||
"tenant-notification": TenantNotificationEmail,
|
||||
};
|
||||
|
||||
export function renderTransactionalEmail<K extends ReactTransactionalTemplateName>(
|
||||
template: K,
|
||||
props: ReactTemplatePropsMap[K]
|
||||
): RenderedReactEmail {
|
||||
const component = COMPONENTS[template] as (p: AnyTemplateProps) => ReactElement;
|
||||
if (!component) {
|
||||
throw new Error(`Unknown React transactional template: ${template}`);
|
||||
}
|
||||
const element = createElement<AnyTemplateProps>(
|
||||
component as (p: AnyTemplateProps) => ReactElement,
|
||||
props as AnyTemplateProps
|
||||
);
|
||||
return renderReactEmail(element);
|
||||
}
|
||||
|
||||
export function reactTransactionalTemplateNames(): readonly ReactTransactionalTemplateName[] {
|
||||
return Object.keys(COMPONENTS) as ReactTransactionalTemplateName[];
|
||||
}
|
||||
|
||||
export function buildBrand(override?: Partial<MailBrand>): MailBrand {
|
||||
return withBrandDefaults(override);
|
||||
}
|
||||
|
||||
export { withBrandDefaults, defaultMailBrand } from "./_layout/theme.js";
|
||||
export type { MailBrand } from "./_layout/theme.js";
|
||||
Reference in new issue
Block a user