@12-apps/notifications 4.7.1 → 4.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/ADOPTING.md +145 -0
- package/README.md +65 -0
- package/dist/catalog-BOVZ2b-b.d.ts +132 -0
- package/dist/{chunk-XE7HZVMH.js → chunk-BGI4BQ66.js} +1 -1
- package/dist/chunk-BGI4BQ66.js.map +1 -0
- package/dist/chunk-EKUSNUBT.js +222 -0
- package/dist/chunk-EKUSNUBT.js.map +1 -0
- package/dist/chunk-FTFLU6KH.js +114 -0
- package/dist/chunk-FTFLU6KH.js.map +1 -0
- package/dist/{chunk-HHMRCMQU.js → chunk-GGAZOLNN.js} +2 -2
- package/dist/{chunk-CUZW62JS.js → chunk-KU4FVOFA.js} +2 -2
- package/dist/{chunk-WHBMPHQE.js → chunk-KZG7QGFA.js} +28 -6
- package/dist/chunk-KZG7QGFA.js.map +1 -0
- package/dist/{chunk-MMLV4EZT.js → chunk-M5XTROYM.js} +2 -2
- package/dist/chunk-ZFIYBNZ7.js +502 -0
- package/dist/chunk-ZFIYBNZ7.js.map +1 -0
- package/dist/{create-api-notifications-B3u6Kx3x.d.ts → create-api-notifications-B-VMezVB.d.ts} +43 -4
- package/dist/{create-web-notifications-BHCzaU2y.d.ts → create-web-notifications-B-xQ6R0B.d.ts} +2 -2
- package/dist/email/index.d.ts +26 -0
- package/dist/email/index.js +20 -0
- package/dist/email/index.js.map +1 -0
- package/dist/email/locales.d.ts +43 -0
- package/dist/email/locales.js +29 -0
- package/dist/email/locales.js.map +1 -0
- package/dist/email/previews/hono.d.ts +46 -0
- package/dist/email/previews/hono.js +33 -0
- package/dist/email/previews/hono.js.map +1 -0
- package/dist/email/previews/index.d.ts +67 -0
- package/dist/email/previews/index.js +12 -0
- package/dist/email/previews/index.js.map +1 -0
- package/dist/email/previews/react/index.d.ts +43 -0
- package/dist/email/previews/react/index.js +58 -0
- package/dist/email/previews/react/index.js.map +1 -0
- package/dist/{generators-B9xt3sRh.d.ts → generators-BsuXe8Mp.d.ts} +1 -1
- package/dist/hono/index.d.ts +6 -5
- package/dist/hono/index.js +4 -3
- package/dist/hono/index.js.map +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.js +5 -5
- package/dist/{jobs-BDZ7aGHV.d.ts → jobs-D64B_bg7.d.ts} +1 -1
- package/dist/manifest/index.d.ts +39 -1
- package/dist/manifest/index.js +9 -0
- package/dist/manifest/index.js.map +1 -1
- package/dist/manifest/server.d.ts +32 -7
- package/dist/manifest/server.js +15 -4
- package/dist/manifest/server.js.map +1 -1
- package/dist/manifest/web.d.ts +18 -4
- package/dist/manifest/web.js +9 -1
- package/dist/manifest/web.js.map +1 -1
- package/dist/{preferences-screen-IOW6Y2H2.js → preferences-screen-V3ZBWP7A.js} +2 -2
- package/dist/preview-screen-DYJRAnAY.d.ts +83 -0
- package/dist/react/index.d.ts +4 -4
- package/dist/react/index.js +10 -10
- package/dist/server/index.d.ts +8 -7
- package/dist/server/index.js +5 -4
- package/dist/template-Dlt5S54z.d.ts +196 -0
- package/dist/{types-CXLAG3UU.d.ts → types-BFmAY0P5.d.ts} +39 -2
- package/dist/web-push/index.d.ts +2 -2
- package/dist/{web-push-Cs14Wp9u.d.ts → web-push-D-ysQd5h.d.ts} +1 -1
- package/dist/{wire-6dzyfDE7.d.ts → wire-_coV3tJk.d.ts} +1 -1
- package/package.json +23 -3
- package/src/email/chrome.en-US.ts +8 -0
- package/src/email/chrome.pt-BR.ts +21 -0
- package/src/email/index.ts +43 -0
- package/src/email/locales.ts +29 -0
- package/src/email/previews/catalog.ts +208 -0
- package/src/email/previews/hono.ts +69 -0
- package/src/email/previews/index.ts +26 -0
- package/src/email/previews/react/copy.en-US.ts +24 -0
- package/src/email/previews/react/copy.pt-BR.ts +24 -0
- package/src/email/previews/react/copy.ts +42 -0
- package/src/email/previews/react/index.tsx +14 -0
- package/src/email/previews/react/loadable.tsx +83 -0
- package/src/email/previews/react/message-list.tsx +133 -0
- package/src/email/previews/react/message-view.tsx +167 -0
- package/src/email/previews/react/preview-screen.tsx +342 -0
- package/src/email/previews/react/transport.ts +60 -0
- package/src/email/previews/routes.ts +111 -0
- package/src/email/template.ts +365 -0
- package/src/email/text.ts +59 -0
- package/src/email/theme.ts +77 -0
- package/src/index.ts +1 -0
- package/src/manifest/index.ts +37 -0
- package/src/manifest/server.ts +23 -0
- package/src/manifest/web.ts +13 -0
- package/src/server/db.ts +12 -1
- package/src/server/dispatch.ts +4 -0
- package/src/server/router.ts +17 -1
- package/src/server/transports/email.ts +62 -0
- package/src/types.ts +39 -1
- package/dist/chunk-WHBMPHQE.js.map +0 -1
- package/dist/chunk-XE7HZVMH.js.map +0 -1
- /package/dist/{chunk-HHMRCMQU.js.map → chunk-GGAZOLNN.js.map} +0 -0
- /package/dist/{chunk-CUZW62JS.js.map → chunk-KU4FVOFA.js.map} +0 -0
- /package/dist/{chunk-MMLV4EZT.js.map → chunk-M5XTROYM.js.map} +0 -0
- /package/dist/{preferences-screen-IOW6Y2H2.js.map → preferences-screen-V3ZBWP7A.js.map} +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/email/text.ts","../src/email/theme.ts","../src/email/template.ts"],"sourcesContent":["import type { EmailDocument } from './template';\n\n/**\n * The plain-text half.\n *\n * Not a courtesy. Every major spam filter scores a `text/html` part with no\n * `text/plain` twin, and a watch, a terminal client and a screen reader in\n * plain-text mode show this and nothing else.\n *\n * It renders from the SAME `EmailDocument` the HTML half does, which is the\n * property that matters: a line added to one is in the other, so the two cannot\n * drift. Its own module only because the HTML renderer is already a file's\n * worth of client workarounds — the seam is the output format, not the content.\n */\n\n/**\n * Render the document as the plain-text half.\n *\n * Not a courtesy. Every major spam filter scores a `text/html` part with no\n * `text/plain` twin, and a watch, a terminal client and a screen reader in\n * plain-text mode show this and nothing else. It is rendered from the SAME\n * object, so it cannot say less than the HTML does.\n */\nexport function renderEmailText(document: EmailDocument): string {\n const blocks = [\n document.heading,\n \"\",\n ...textParagraphs(document),\n ...textFacts(document),\n ...textAction(document),\n ...textNotes(document),\n \"--\",\n document.chrome.tagline(document.brand),\n document.chrome.automated,\n ];\n return `${blocks.join(\"\\n\").replace(/\\n{3,}/g, \"\\n\\n\").trimEnd()}\\n`;\n}\n\n/** One blank line after each paragraph, as prose reads. */\nfunction textParagraphs(document: EmailDocument): string[] {\n return (document.paragraphs ?? []).flatMap((text) => [text, \"\"]);\n}\n\n/** `Label: value` per row, as a receipt is quoted back over the phone. */\nfunction textFacts(document: EmailDocument): string[] {\n const rows = document.facts ?? [];\n return rows.length === 0 ? [] : [...rows.map((f) => `${f.label}: ${f.value}`), \"\"];\n}\n\n/** The CTA as label + URL: a plain-text reader has no button to press. */\nfunction textAction(document: EmailDocument): string[] {\n return document.action ? [`${document.action.label}: ${document.action.href}`, \"\"] : [];\n}\n\nfunction textNotes(document: EmailDocument): string[] {\n const notes = document.notes ?? [];\n return notes.length === 0 ? [] : [...notes, \"\"];\n}\n\n","/**\n * The layout's design tokens — the nine colours a mail is drawn from.\n *\n * ## Why a theme is a VALUE here and copy is required config\n *\n * The copy-portability doctrine is that a package ships no user-facing\n * sentences: a default in the origin host's language reads as finished to the\n * next host right up until somebody's customer gets mail in a language they do\n * not speak. Colour is not that. {@link NEUTRAL_EMAIL_THEME} is not anybody's\n * brand — it is grey on white, which reads as *unstyled but tidy* rather than\n * as *somebody else's product*. A host that passes nothing gets a mail that\n * looks plain, not a mail that looks like a different company.\n *\n * So this one has a default and the copy does not, and the difference is\n * exactly whether getting it wrong is invisible. A missing theme is visible in\n * the first preview; a wrong-language default is invisible until a customer\n * complains.\n *\n * ## What a host should know before overriding it\n *\n * Two rungs of most brand palettes cannot carry light text, and a mail has no\n * theme to fall back on when a client ignores a colour. {@link accent} is the\n * one that MUST clear 4.5:1 against white — it is the CTA fill and every link.\n * A warm mid-tone that looks fine on a screen at 2.6:1 is unreadable in an\n * inbox, and nothing in the pipeline will say so.\n */\nexport interface EmailTheme {\n /** The page behind the card. Never pure white: a white card needs a ground. */\n readonly page: string;\n /** The card itself. */\n readonly surface: string;\n /** A quieter panel inside the card — the facts table. */\n readonly panel: string;\n /** Every hairline. */\n readonly border: string;\n /** Body text. */\n readonly ink: string;\n /** Secondary text: the footer, the fallback link, a fact's label. */\n readonly muted: string;\n /** The action colour — the CTA fill and every link. Must clear 4.5:1 on white. */\n readonly accent: string;\n /** Ink ON {@link accent}. */\n readonly onAccent: string;\n /** The rule under the wordmark. Decorative — nothing is written on it. */\n readonly rule: string;\n}\n\n/**\n * A brand-free default: greys, one blue, nothing anybody would mistake for a\n * product. Every value clears its contrast requirement against its own ground.\n */\nexport const NEUTRAL_EMAIL_THEME: EmailTheme = {\n page: '#F5F6F8',\n surface: '#FFFFFF',\n panel: '#F5F6F8',\n border: '#E1E4E9',\n ink: '#1A1D23',\n muted: '#5C6470',\n accent: '#1F5EDB',\n onAccent: '#FFFFFF',\n rule: '#1F5EDB',\n};\n\n/**\n * The font stack, as one string.\n *\n * System fonts only, and no web font: a `@font-face` is stripped by Gmail and\n * by Outlook, so a mail that depends on one renders in whatever the client\n * substitutes — never the fallback the designer chose. The stack ends in the\n * emoji faces so a status glyph in a subject line does not drop to a tofu box\n * on Windows.\n */\nexport const EMAIL_FONT_STACK =\n \"-apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji'\";\n\n/** The card's width. 600px is the width every client lays out without scroll. */\nexport const EMAIL_CONTENT_WIDTH = 600;\n","import { renderEmailText } from './text';\nimport {\n EMAIL_CONTENT_WIDTH,\n EMAIL_FONT_STACK,\n NEUTRAL_EMAIL_THEME,\n type EmailTheme,\n} from './theme';\n\n/**\n * THE transactional-mail layout: one document model, one HTML renderer, one\n * plain-text twin.\n *\n * ## The problem it exists for\n *\n * A host that sends mail from more than one place ends up rendering it in more\n * than one way — the notification pipeline emits a bold paragraph and a bare\n * anchor, the sign-in flow emits a `div` with a max-width, the receipt builds\n * its own list — and each grows its own `escapeHtml` and its own text twin. The\n * three look like three different products, because a paragraph with no\n * document around it inherits whatever the client decides: 13px Arial in Gmail,\n * Times New Roman in Outlook, no centring anywhere.\n *\n * That is a LAYOUT problem rather than a wording one, which is what makes it a\n * package's to solve. The words stay the host's; the document does not.\n *\n * ## Why the document is a MODEL and not a string\n *\n * Every caller hands over structure — a heading, some paragraphs, an optional\n * facts table, at most one call to action — and never markup. Three things fall\n * out of that, and each is a real defect in the hand-rolled renderers this\n * replaces:\n *\n * 1. **Escaping cannot be forgotten.** Every field is escaped here, once. Of\n * the three renderers this was extracted from, two escaped the body and\n * interpolated the LINK raw.\n * 2. **The plain-text twin cannot drift.** Both halves render from the same\n * object, so a line added to one is in the other. A `text/html` part with no\n * `text/plain` twin is scored by every major spam filter, and it is what a\n * watch, a terminal client and a screen reader in plain-text mode show.\n * 3. **A preview is honest.** `./server`'s catalogue renders exactly this, from\n * exactly these inputs, so a preview cannot be right about a mail nobody\n * gets.\n *\n * ## The client constraints this encodes\n *\n * Stated once here, so no caller has to know them:\n *\n * - **Tables, not divs.** Outlook 2016+ on Windows lays HTML out with Word,\n * which supports no `flex`, no `grid` and no reliable `max-width` on a block.\n * A centred 600px table is the one construction every client agrees on.\n * - **Inline styles.** Gmail strips `<style>` from the document it renders in\n * several contexts, and always in the Gmail app for a non-Gmail account. The\n * `<style>` block below therefore carries only the mobile media query —\n * progressive enhancement, never anything the layout depends on.\n * - **No web fonts, no `color-mix()`, no CSS variables.** See `./theme`.\n * - **A preheader.** The inbox list shows the first text in the body after the\n * subject; without one it shows the footer's legal line.\n * - **`role=\"presentation\"`** on every layout table, so a screen reader reads\n * the message rather than announcing a five-column grid.\n */\n\n/** The words the LAYOUT itself needs — never the message's own sentences. */\nexport interface EmailChromeCopy {\n /** \"If the button does not work, paste this address into your browser:\" */\n readonly fallbackHint: string;\n /** \"This is an automated message — please do not reply.\" */\n readonly automated: string;\n /** The footer's one line about the product, given the brand name. */\n readonly tagline: (brand: string) => string;\n}\n\n/** The one call to action a message may carry. More than one dilutes both. */\nexport interface EmailAction {\n readonly label: string;\n readonly href: string;\n}\n\n/** One row of the facts panel — a receipt's total, an order's reference. */\nexport interface EmailFact {\n readonly label: string;\n readonly value: string;\n /** Renders bolder and larger — the one number the reader came for. */\n readonly emphasis?: boolean;\n}\n\n/** Everything a message says, with no opinion about how it looks. */\nexport interface EmailDocument {\n /** The subject line. Also the document `<title>`. */\n readonly subject: string;\n /**\n * The inbox-list preview, ~90 chars. Falls back to the first paragraph,\n * which is right far more often than it is wrong.\n */\n readonly preheader?: string;\n /** The `<h1>`. Usually a restatement of the subject in the reader's terms. */\n readonly heading: string;\n /** The body, one entry per paragraph. Plain sentences — never markup. */\n readonly paragraphs?: readonly string[];\n /** An optional label/value panel under the body. */\n readonly facts?: readonly EmailFact[];\n /** At most one CTA. */\n readonly action?: EmailAction;\n /** Small print under the CTA — a deadline, a \"you can ignore this\". */\n readonly notes?: readonly string[];\n /**\n * The layout's own words, in the recipient's language.\n *\n * REQUIRED, with no default in any language — the copy-portability doctrine.\n * `@12-apps/notifications/email/locales` ships a pack per language and a host\n * passes one BY\n * NAME, which is a decision rather than a silence.\n */\n readonly chrome: EmailChromeCopy;\n /**\n * The product name in the header and the footer. REQUIRED: a package that\n * defaulted this would sign another company's mail.\n */\n readonly brand: string;\n /** The recipient's language, for the document's `lang` attribute. */\n readonly locale: string;\n /** Defaults to {@link NEUTRAL_EMAIL_THEME} — see `./theme` for why this one may. */\n readonly theme?: EmailTheme;\n}\n\n/**\n * Escape everything that reaches the HTML body.\n *\n * A store name, a buyer's display name and a product title are all user input\n * that reaches a mail, and the ONE thing a shared layout must guarantee is that\n * none of them can close a tag. Single quotes are escaped too: attribute values\n * below are double-quoted, but a caller reading this should not have to check.\n */\nfunction escapeHtml(value: string): string {\n return value\n .replaceAll(\"&\", \"&\")\n .replaceAll(\"<\", \"<\")\n .replaceAll(\">\", \">\")\n .replaceAll('\"', \""\")\n .replaceAll(\"'\", \"'\");\n}\n\n/**\n * The schemes a link in a mail may use.\n *\n * `javascript:` is inert in every mail client, so this is not the XSS guard it\n * would be on a page — it is the guard for the PREVIEW, which renders the same\n * HTML in a browser, and for the day some part of this markup is reused on a\n * screen. A rejected href drops to `#`, which fails visibly rather than\n * silently linking somewhere unexpected.\n */\nconst SAFE_LINK_SCHEMES = new Set([\"http:\", \"https:\", \"mailto:\"]);\n\n/** A URL as an attribute value, or `#` when it is not one this layout will emit. */\nexport function safeHref(href: string): string {\n const trimmed = href.trim();\n // A relative link is fine and common — every caller that has an origin\n // resolves it before it gets here, and one that does not is better off with\n // a path than with nothing.\n if (trimmed.startsWith(\"/\")) return escapeHtml(trimmed);\n try {\n const url = new URL(trimmed);\n return SAFE_LINK_SCHEMES.has(url.protocol) ? escapeHtml(url.toString()) : \"#\";\n } catch {\n return \"#\";\n }\n}\n\n/** The message's own first sentence, when the caller named no preheader. */\nfunction preheaderOf(document: EmailDocument): string {\n return document.preheader ?? document.paragraphs?.[0] ?? document.heading;\n}\n\n/** A `<td>` of body copy. One paragraph, at the layout's own rhythm. */\nfunction paragraph(text: string, theme: EmailTheme): string {\n return `<p style=\"margin:0 0 16px;font-size:16px;line-height:1.6;color:${theme.ink}\">${escapeHtml(text)}</p>`;\n}\n\n/**\n * The facts panel — a receipt's four lines, an order's reference.\n *\n * Two cells per row rather than a definition list: `<dl>` is styled\n * inconsistently across clients and collapses to a single column in Outlook,\n * which is the one place these are read side by side.\n */\nfunction facts(rows: readonly EmailFact[], theme: EmailTheme): string {\n if (rows.length === 0) return \"\";\n const cells = rows\n .map((row, index) => {\n const divider =\n index === 0 ? \"\" : `border-top:1px solid ${theme.border};`;\n const value = row.emphasis\n ? `font-size:20px;font-weight:700;color:${theme.ink}`\n : `font-size:15px;color:${theme.ink}`;\n return [\n `<tr>`,\n `<td style=\"${divider}padding:12px 0 12px 16px;font-size:13px;line-height:1.4;color:${theme.muted};text-transform:uppercase;letter-spacing:.4px;white-space:nowrap\">${escapeHtml(row.label)}</td>`,\n `<td align=\"right\" style=\"${divider}padding:12px 16px 12px 0;line-height:1.4;${value}\">${escapeHtml(row.value)}</td>`,\n `</tr>`,\n ].join(\"\");\n })\n .join(\"\");\n return [\n `<table role=\"presentation\" width=\"100%\" cellpadding=\"0\" cellspacing=\"0\" border=\"0\" style=\"border-collapse:separate;background:${theme.page};border:1px solid ${theme.border};border-radius:10px;margin:0 0 24px\">`,\n cells,\n `</table>`,\n ].join(\"\");\n}\n\n/**\n * The CTA.\n *\n * A single-cell table with `bgcolor` AND a background style: Outlook reads the\n * attribute and ignores the property, every other client does the reverse, and\n * a button that loses its fill is invisible ink on white. `border-radius` is\n * simply dropped by Word — a square button is the accepted degradation, and the\n * alternative (a VML rounded rectangle) is forty lines of conditional comment\n * that then has to be kept in step with the colour.\n */\nfunction action(cta: EmailAction, theme: EmailTheme): string {\n return [\n `<table role=\"presentation\" cellpadding=\"0\" cellspacing=\"0\" border=\"0\" style=\"margin:8px 0 24px\">`,\n `<tr>`,\n `<td align=\"center\" bgcolor=\"${theme.accent}\" style=\"border-radius:8px;background:${theme.accent}\">`,\n `<a href=\"${safeHref(cta.href)}\" style=\"display:inline-block;padding:14px 32px;font-family:${EMAIL_FONT_STACK};font-size:16px;font-weight:600;line-height:1;color:${theme.onAccent};text-decoration:none;border-radius:8px\">${escapeHtml(cta.label)}</a>`,\n `</td>`,\n `</tr>`,\n `</table>`,\n ].join(\"\");\n}\n\n/**\n * The \"paste this address\" fallback, printed whenever there is a CTA.\n *\n * Not optional, and the reason is measured elsewhere in this repo: corporate\n * mail gateways rewrite link targets, and a reader whose gateway mangles the\n * button has no other way to reach a verification or reset link. `word-break`\n * because a signed URL is longer than the card.\n */\nfunction fallback(cta: EmailAction, chrome: EmailChromeCopy, theme: EmailTheme): string {\n return [\n `<p style=\"margin:0 0 8px;font-size:13px;line-height:1.5;color:${theme.muted}\">${escapeHtml(chrome.fallbackHint)}</p>`,\n `<p style=\"margin:0 0 24px;font-size:13px;line-height:1.5;word-break:break-all\"><a href=\"${safeHref(cta.href)}\" style=\"color:${theme.accent};text-decoration:underline\">${escapeHtml(cta.href)}</a></p>`,\n ].join(\"\");\n}\n\n/** The brand header: wordmark over the ramp's rule. */\nfunction header(document: EmailDocument, theme: EmailTheme): string {\n return [\n `<tr>`,\n `<td style=\"padding:32px 40px 0\">`,\n `<table role=\"presentation\" width=\"100%\" cellpadding=\"0\" cellspacing=\"0\" border=\"0\">`,\n `<tr><td style=\"font-size:20px;font-weight:700;letter-spacing:-.2px;color:${theme.ink}\">${escapeHtml(document.brand)}</td></tr>`,\n `<tr><td style=\"padding-top:12px\"><div style=\"height:3px;width:44px;background:${theme.rule};border-radius:2px;font-size:0;line-height:0\"> </div></td></tr>`,\n `</table>`,\n `</td>`,\n `</tr>`,\n ].join(\"\");\n}\n\n/** The footer: the tagline, the \"do not reply\" line, and nothing else. */\nfunction footer(document: EmailDocument, theme: EmailTheme): string {\n const { chrome, brand } = document;\n return [\n `<tr>`,\n `<td style=\"padding:0 40px 40px\">`,\n `<table role=\"presentation\" width=\"100%\" cellpadding=\"0\" cellspacing=\"0\" border=\"0\">`,\n `<tr><td style=\"border-top:1px solid ${theme.border};padding-top:20px\">`,\n `<p style=\"margin:0 0 6px;font-size:13px;line-height:1.5;color:${theme.muted}\">${escapeHtml(chrome.tagline(brand))}</p>`,\n `<p style=\"margin:0;font-size:12px;line-height:1.5;color:${theme.muted}\">${escapeHtml(chrome.automated)}</p>`,\n `</td></tr>`,\n `</table>`,\n `</td>`,\n `</tr>`,\n ].join(\"\");\n}\n\n/**\n * The mobile media query — the one thing in a `<style>` block.\n *\n * Everything it does is also correct without it: the card is already\n * `width:100%` up to 600px, so a client that strips this renders a slightly\n * roomier mail rather than a broken one. That is the test for whether a rule\n * belongs here at all.\n */\nfunction styleBlock(): string {\n return [\n `<style>`,\n `@media only screen and (max-width:620px){`,\n `.fp-card{width:100%!important;border-radius:0!important;border-left:0!important;border-right:0!important}`,\n `.fp-pad{padding-left:24px!important;padding-right:24px!important}`,\n `.fp-h1{font-size:22px!important}`,\n `}`,\n `</style>`,\n ].join(\"\");\n}\n\n/**\n * Render the document as the HTML half of the message.\n *\n * A complete document rather than a fragment: a `<!DOCTYPE>` is what puts\n * Outlook into standards mode, and `x-apple-disable-message-reformatting` is\n * what stops iOS Mail re-flowing the card to the screen width and shrinking the\n * type with it.\n */\nexport function renderEmailHtml(document: EmailDocument): string {\n const theme = document.theme ?? NEUTRAL_EMAIL_THEME;\n const body = [\n `<h1 class=\"fp-h1\" style=\"margin:0 0 16px;font-size:26px;line-height:1.25;font-weight:700;letter-spacing:-.3px;color:${theme.ink}\">${escapeHtml(document.heading)}</h1>`,\n ...(document.paragraphs ?? []).map((text) => paragraph(text, theme)),\n facts(document.facts ?? [], theme),\n ...(document.action ? [action(document.action, theme)] : []),\n ...(document.action ? [fallback(document.action, document.chrome, theme)] : []),\n ...(document.notes ?? []).map(\n (note) =>\n `<p style=\"margin:0 0 8px;font-size:13px;line-height:1.5;color:${theme.muted}\">${escapeHtml(note)}</p>`,\n ),\n ].join(\"\\n \");\n\n return `<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n<html xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"${escapeHtml(document.locale)}\">\n<head>\n<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" />\n<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\" />\n<meta name=\"x-apple-disable-message-reformatting\" />\n<meta name=\"color-scheme\" content=\"light\" />\n<meta name=\"supported-color-schemes\" content=\"light\" />\n<title>${escapeHtml(document.subject)}</title>\n${styleBlock()}\n</head>\n<body style=\"margin:0;padding:0;background:${theme.page};font-family:${EMAIL_FONT_STACK};-webkit-font-smoothing:antialiased\">\n<div style=\"display:none;max-height:0;overflow:hidden;opacity:0;mso-hide:all\">${escapeHtml(preheaderOf(document))}</div>\n<table role=\"presentation\" width=\"100%\" cellpadding=\"0\" cellspacing=\"0\" border=\"0\" style=\"background:${theme.page}\">\n<tr>\n<td align=\"center\" style=\"padding:32px 12px\">\n<table role=\"presentation\" class=\"fp-card\" width=\"${EMAIL_CONTENT_WIDTH}\" cellpadding=\"0\" cellspacing=\"0\" border=\"0\" style=\"width:${EMAIL_CONTENT_WIDTH}px;max-width:100%;background:${theme.surface};border:1px solid ${theme.border};border-radius:14px\">\n${header(document, theme)}\n<tr>\n<td class=\"fp-pad\" style=\"padding:24px 40px 8px\">\n ${body}\n</td>\n</tr>\n${footer(document, theme)}\n</table>\n</td>\n</tr>\n</table>\n</body>\n</html>`;\n}\n\n/** Both halves plus the subject — what every driver in this repo is handed. */\nexport interface RenderedEmail {\n readonly subject: string;\n readonly html: string;\n readonly text: string;\n}\n\n/** Render one document into the message shape `EmailDriver.send` takes. */\nexport function renderEmail(document: EmailDocument): RenderedEmail {\n return {\n subject: document.subject,\n html: renderEmailHtml(document),\n text: renderEmailText(document),\n };\n}\n"],"mappings":";;;;;AAuBO,SAAS,gBAAgB,UAAiC;AAC/D,QAAM,SAAS;AAAA,IACb,SAAS;AAAA,IACT;AAAA,IACA,GAAG,eAAe,QAAQ;AAAA,IAC1B,GAAG,UAAU,QAAQ;AAAA,IACrB,GAAG,WAAW,QAAQ;AAAA,IACtB,GAAG,UAAU,QAAQ;AAAA,IACrB;AAAA,IACA,SAAS,OAAO,QAAQ,SAAS,KAAK;AAAA,IACtC,SAAS,OAAO;AAAA,EAClB;AACA,SAAO,GAAG,OAAO,KAAK,IAAI,EAAE,QAAQ,WAAW,MAAM,EAAE,QAAQ,CAAC;AAAA;AAClE;AAbgB;AAgBhB,SAAS,eAAe,UAAmC;AACzD,UAAQ,SAAS,cAAc,CAAC,GAAG,QAAQ,CAAC,SAAS,CAAC,MAAM,EAAE,CAAC;AACjE;AAFS;AAKT,SAAS,UAAU,UAAmC;AACpD,QAAM,OAAO,SAAS,SAAS,C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I,SAAS,SAAS,CAAC,SAAS,SAAS,QAAQ,SAAS,QAAQ,KAAK,CAAC,IAAI,CAAC;AAAA,IAC7E,IAAI,SAAS,SAAS,CAAC,GAAG;AAAA,MACxB,CAAC,SACC,iEAAiE,MAAM,KAAK,KAAK,WAAW,IAAI,CAAC;AAAA,IACrG;AAAA,EACF,EAAE,KAAK,UAAU;AAEjB,SAAO;AAAA,mDAC0C,WAAW,SAAS,MAAM,CAAC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,SAOrE,WAAW,SAAS,OAAO,CAAC;AAAA,EACnC,WAAW,CAAC;AAAA;AAAA,6CAE+B,MAAM,IAAI,gBAAgB,gBAAgB;AAAA,gFACP,WAAW,YAAY,QAAQ,CAAC,CAAC;AAAA,uGACV,MAAM,IAAI;AAAA;AAAA;AAAA,oDAG7D,mBAAmB,6DAA6D,mBAAmB,gCAAgC,MAAM,OAAO,qBAAqB,MAAM,MAAM;AAAA,EACnO,OAAO,UAAU,KAAK,CAAC;AAAA;AAAA;AAAA,QAGjB,IAAI;AAAA;AAAA;AAAA,EAGV,OAAO,UAAU,KAAK,CAAC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAOzB;AA5CgB;AAsDT,SAAS,YAAY,UAAwC;AAClE,SAAO;AAAA,IACL,SAAS,SAAS;AAAA,IAClB,MAAM,gBAAgB,QAAQ;AAAA,IAC9B,MAAM,gBAAgB,QAAQ;AAAA,EAChC;AACF;AANgB;","names":[]}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import {
|
|
2
|
+
__name
|
|
3
|
+
} from "./chunk-7QVYU63E.js";
|
|
4
|
+
|
|
5
|
+
// src/email/previews/catalog.ts
|
|
6
|
+
var DuplicateEmailPreviewIdError = class _DuplicateEmailPreviewIdError extends Error {
|
|
7
|
+
static {
|
|
8
|
+
__name(this, "DuplicateEmailPreviewIdError");
|
|
9
|
+
}
|
|
10
|
+
constructor(id) {
|
|
11
|
+
super(`@12-apps/notifications: two e-mail preview messages share the id "${id}".`);
|
|
12
|
+
this.name = "DuplicateEmailPreviewIdError";
|
|
13
|
+
Object.setPrototypeOf(this, _DuplicateEmailPreviewIdError.prototype);
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
function collect(sources) {
|
|
17
|
+
const owned = sources.flatMap(
|
|
18
|
+
(source) => source.list().map((message) => ({ owner: source.owner, message }))
|
|
19
|
+
);
|
|
20
|
+
const seen = /* @__PURE__ */ new Set();
|
|
21
|
+
for (const { message } of owned) {
|
|
22
|
+
if (seen.has(message.id)) throw new DuplicateEmailPreviewIdError(message.id);
|
|
23
|
+
seen.add(message.id);
|
|
24
|
+
}
|
|
25
|
+
return owned;
|
|
26
|
+
}
|
|
27
|
+
__name(collect, "collect");
|
|
28
|
+
function createEmailPreviews(config) {
|
|
29
|
+
const { sources, locales, defaultLocale } = config;
|
|
30
|
+
const localeOf = /* @__PURE__ */ __name((locale) => locale && locales.includes(locale) ? locale : defaultLocale, "localeOf");
|
|
31
|
+
const rowOf = /* @__PURE__ */ __name(({ owner, message }, locale) => ({
|
|
32
|
+
id: message.id,
|
|
33
|
+
key: message.key,
|
|
34
|
+
family: message.family,
|
|
35
|
+
owner,
|
|
36
|
+
subject: message.render(locale).subject
|
|
37
|
+
}), "rowOf");
|
|
38
|
+
return {
|
|
39
|
+
index(locale) {
|
|
40
|
+
const tag = localeOf(locale);
|
|
41
|
+
return {
|
|
42
|
+
locale: tag,
|
|
43
|
+
locales,
|
|
44
|
+
items: collect(sources).map((owned) => rowOf(owned, tag)),
|
|
45
|
+
coverage: this.coverage()
|
|
46
|
+
};
|
|
47
|
+
},
|
|
48
|
+
render(id, locale) {
|
|
49
|
+
const owned = collect(sources).find((entry) => entry.message.id === id);
|
|
50
|
+
if (!owned) return null;
|
|
51
|
+
const tag = localeOf(locale);
|
|
52
|
+
const message = owned.message.render(tag);
|
|
53
|
+
return { ...rowOf(owned, tag), locale: tag, html: message.html, text: message.text };
|
|
54
|
+
},
|
|
55
|
+
coverage() {
|
|
56
|
+
const missing = [];
|
|
57
|
+
const orphan = [];
|
|
58
|
+
for (const source of sources) {
|
|
59
|
+
const gap = source.coverage?.();
|
|
60
|
+
if (!gap) continue;
|
|
61
|
+
missing.push(...gap.missing);
|
|
62
|
+
orphan.push(...gap.orphan);
|
|
63
|
+
}
|
|
64
|
+
return { missing: missing.sort(), orphan: orphan.sort() };
|
|
65
|
+
},
|
|
66
|
+
supportsLocale: /* @__PURE__ */ __name((locale) => locales.includes(locale), "supportsLocale")
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
__name(createEmailPreviews, "createEmailPreviews");
|
|
70
|
+
|
|
71
|
+
// src/email/previews/routes.ts
|
|
72
|
+
var ok = /* @__PURE__ */ __name((body) => ({ status: 200, body: { data: body } }), "ok");
|
|
73
|
+
var fail = /* @__PURE__ */ __name((status, error) => ({ status, body: { error } }), "fail");
|
|
74
|
+
function readLocale(previews, request) {
|
|
75
|
+
const tag = request.query?.locale;
|
|
76
|
+
if (tag === void 0 || tag === "") return { ok: true };
|
|
77
|
+
return previews.supportsLocale(tag) ? { ok: true, locale: tag } : { ok: false, tag };
|
|
78
|
+
}
|
|
79
|
+
__name(readLocale, "readLocale");
|
|
80
|
+
function emailPreviewRoutes(config) {
|
|
81
|
+
const previews = createEmailPreviews(config);
|
|
82
|
+
return [
|
|
83
|
+
{
|
|
84
|
+
method: "GET",
|
|
85
|
+
path: "/",
|
|
86
|
+
kind: "authenticated",
|
|
87
|
+
handle: /* @__PURE__ */ __name((request) => {
|
|
88
|
+
const locale = readLocale(previews, request);
|
|
89
|
+
if (!locale.ok) return Promise.resolve(fail(400, `Unknown locale "${locale.tag}".`));
|
|
90
|
+
return Promise.resolve(ok(previews.index(locale.locale)));
|
|
91
|
+
}, "handle")
|
|
92
|
+
},
|
|
93
|
+
{
|
|
94
|
+
method: "GET",
|
|
95
|
+
path: "/:id",
|
|
96
|
+
kind: "authenticated",
|
|
97
|
+
handle: /* @__PURE__ */ __name((request) => {
|
|
98
|
+
const locale = readLocale(previews, request);
|
|
99
|
+
if (!locale.ok) return Promise.resolve(fail(400, `Unknown locale "${locale.tag}".`));
|
|
100
|
+
const id = request.params?.id ?? "";
|
|
101
|
+
const detail = previews.render(id, locale.locale);
|
|
102
|
+
return Promise.resolve(detail ? ok(detail) : fail(404, `No e-mail preview named "${id}".`));
|
|
103
|
+
}, "handle")
|
|
104
|
+
}
|
|
105
|
+
];
|
|
106
|
+
}
|
|
107
|
+
__name(emailPreviewRoutes, "emailPreviewRoutes");
|
|
108
|
+
|
|
109
|
+
export {
|
|
110
|
+
DuplicateEmailPreviewIdError,
|
|
111
|
+
createEmailPreviews,
|
|
112
|
+
emailPreviewRoutes
|
|
113
|
+
};
|
|
114
|
+
//# sourceMappingURL=chunk-FTFLU6KH.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/email/previews/catalog.ts","../src/email/previews/routes.ts"],"sourcesContent":["import type { RenderedEmail } from '../template';\n\n/**\n * The preview catalogue: every message a host can send, as a navigable set.\n *\n * ## The problem it exists for\n *\n * There is normally no way to SEE a transactional mail without triggering the\n * event that sends it — signing up with a throwaway address to look at the\n * verification mail, settling an order to look at the receipt, exhausting a\n * quota to look at that alert. So nobody looks, and a host that renders mail in\n * three different ways does not find out.\n *\n * A layout nobody can see is one release from being three layouts again, which\n * is why this ships in the same package as the layout rather than beside it.\n *\n * ## What is the package's and what is the host's\n *\n * The MECHANISM is here: group by owner, render one message for one reader,\n * report what cannot be shown. WHICH messages exist is the host's, and it\n * cannot be otherwise — a package cannot know that a host sends a\n * \"your quota is exhausted\" notice, let alone what data that notice is\n * rendered from.\n *\n * So a host declares SOURCES. Each names an owner and answers with its\n * messages, and the catalogue is the union. That inverts the obvious design,\n * where the package would hold a registry a host writes into: a source is\n * asked, per request, so a source backed by a registry that fills at import\n * time answers with whatever is registered NOW rather than with whatever had\n * been registered when the mount was built.\n *\n * ## Why coverage is a first-class output\n *\n * A catalogue that quietly omits a message looks exactly like a product that\n * does not send it. So a source may report what it knows it cannot show —\n * a message with no sample data, or sample data for a message that no longer\n * exists — and the surface returns that beside the list rather than swallowing\n * it. A gap that is visible is a gap somebody closes.\n */\n\n/** One previewable message. */\nexport interface EmailPreviewMessage {\n /**\n * Stable id, and the path segment the console navigates by.\n *\n * The host chooses the spelling; the surface only requires it to be unique\n * across every source. Ids that survive a rename are what make a link to one\n * mail worth sending to a colleague.\n */\n readonly id: string;\n /** The wire identity — an event type, a template key. Shown beside the subject. */\n readonly key: string;\n /** Which mail path this belongs to, for grouping inside one owner. */\n readonly family: string;\n /** Render it for one reader. MUST be pure — nothing may be sent. */\n render(locale: string): RenderedEmail;\n}\n\n/** What a source knows it cannot show. Both directions are worth reporting. */\nexport interface EmailPreviewCoverage {\n /** Messages that exist but have no sample data, so no preview. */\n readonly missing: readonly string[];\n /** Sample data for a message nothing produces any more. */\n readonly orphan: readonly string[];\n}\n\n/** One group of messages, owned by whichever code words them. */\nexport interface EmailPreviewSource {\n /**\n * Who owns these messages — a package name, or the host's own module.\n *\n * This is the console's grouping, and it is the answer to \"which parts of\n * this system send mail\", which is a question most hosts cannot otherwise\n * answer at all.\n */\n readonly owner: string;\n /** Called PER REQUEST — see the docblock above for why that matters. */\n list(): readonly EmailPreviewMessage[];\n /** Optional: what this source cannot show. Absent means \"nothing missing\". */\n coverage?(): EmailPreviewCoverage;\n}\n\n/** One catalogue row: everything the sidebar needs, and no rendered bytes. */\nexport interface EmailPreviewRow {\n readonly id: string;\n readonly key: string;\n readonly family: string;\n readonly owner: string;\n /** The subject in the requested language, so the list reads as an inbox. */\n readonly subject: string;\n}\n\n/** One rendered message: what the vendor would be handed, verbatim. */\nexport interface EmailPreviewDetail extends EmailPreviewRow {\n readonly locale: string;\n readonly html: string;\n readonly text: string;\n}\n\nexport interface EmailPreviewIndex {\n readonly locale: string;\n readonly locales: readonly string[];\n readonly items: readonly EmailPreviewRow[];\n readonly coverage: EmailPreviewCoverage;\n}\n\nexport interface EmailPreviewsConfig {\n /** The host's sources, in the order the console should list their owners. */\n readonly sources: readonly EmailPreviewSource[];\n /**\n * The languages a preview may be asked for.\n *\n * REQUIRED, and not derived from the shipped packs: a host's own messages may\n * be written in languages this package has never heard of, and a preview that\n * silently refused one of them would look exactly like a product with no\n * translation.\n */\n readonly locales: readonly string[];\n /** The language a preview opens in when the caller names none. */\n readonly defaultLocale: string;\n}\n\n/** An id that appears in more than one source — the one thing that must not happen. */\nexport class DuplicateEmailPreviewIdError extends Error {\n constructor(id: string) {\n super(`@12-apps/notifications: two e-mail preview messages share the id \"${id}\".`);\n this.name = 'DuplicateEmailPreviewIdError';\n Object.setPrototypeOf(this, DuplicateEmailPreviewIdError.prototype);\n }\n}\n\n/** The catalogue, assembled from every source. */\nexport interface ApiEmailPreviews {\n /** Every message, with each subject rendered in `locale`. */\n index(locale?: string): EmailPreviewIndex;\n /** One rendered message, or `null` when no source owns that id. */\n render(id: string, locale?: string): EmailPreviewDetail | null;\n /** The union of every source's gaps. */\n coverage(): EmailPreviewCoverage;\n /** Is this a language the host said it writes in? */\n supportsLocale(locale: string): boolean;\n}\n\n/** One source's messages, tagged with their owner. */\ninterface OwnedMessage {\n readonly owner: string;\n readonly message: EmailPreviewMessage;\n}\n\nfunction collect(sources: readonly EmailPreviewSource[]): OwnedMessage[] {\n const owned = sources.flatMap((source) =>\n source.list().map((message) => ({ owner: source.owner, message })),\n );\n const seen = new Set<string>();\n for (const { message } of owned) {\n // A duplicate id makes one message unreachable and the other ambiguous —\n // and silently, since the console would simply show whichever came first.\n // Throwing here surfaces it on the request that would have hidden it.\n if (seen.has(message.id)) throw new DuplicateEmailPreviewIdError(message.id);\n seen.add(message.id);\n }\n return owned;\n}\n\nexport function createEmailPreviews(config: EmailPreviewsConfig): ApiEmailPreviews {\n const { sources, locales, defaultLocale } = config;\n const localeOf = (locale?: string): string =>\n locale && locales.includes(locale) ? locale : defaultLocale;\n\n const rowOf = ({ owner, message }: OwnedMessage, locale: string): EmailPreviewRow => ({\n id: message.id,\n key: message.key,\n family: message.family,\n owner,\n subject: message.render(locale).subject,\n });\n\n return {\n index(locale) {\n const tag = localeOf(locale);\n return {\n locale: tag,\n locales,\n items: collect(sources).map((owned) => rowOf(owned, tag)),\n coverage: this.coverage(),\n };\n },\n render(id, locale) {\n const owned = collect(sources).find((entry) => entry.message.id === id);\n if (!owned) return null;\n const tag = localeOf(locale);\n const message = owned.message.render(tag);\n return { ...rowOf(owned, tag), locale: tag, html: message.html, text: message.text };\n },\n coverage() {\n const missing: string[] = [];\n const orphan: string[] = [];\n for (const source of sources) {\n const gap = source.coverage?.();\n if (!gap) continue;\n missing.push(...gap.missing);\n orphan.push(...gap.orphan);\n }\n return { missing: missing.sort(), orphan: orphan.sort() };\n },\n supportsLocale: (locale) => locales.includes(locale),\n };\n}\n","import {\n createEmailPreviews,\n type ApiEmailPreviews,\n type EmailPreviewsConfig,\n} from './catalog';\n\n/**\n * The two endpoints over the catalogue, as descriptors.\n *\n * `GET /` answers the list — one row per message, a subject each, no rendered\n * bytes — and `GET /:id` answers one whole document. Two calls rather than one\n * because a rendered mail is 6-10 KB and a catalogue of twenty would be twenty\n * times that on a screen where the operator reads one.\n *\n * ## Nothing here can send anything\n *\n * The surface holds no driver, no transport and no address. `render` is pure by\n * the contract `EmailPreviewMessage` states, so the one mistake a preview\n * surface must be incapable of — putting a sample in somebody's inbox — is not\n * reachable from this code at all rather than merely not done.\n *\n * ## The gate is the HOST's — but the POSTURE is declared here\n *\n * Every route carries `kind: 'authenticated'`, the wiring contract's own word\n * for \"behind the host's session resolution and its RBAC\". A package cannot\n * know WHICH gate a host uses, and this one does not try: it names no\n * permission id, because the ids belong to whichever host mounts it.\n *\n * What it must not do is stay silent. `public` is the contract's word for\n * anonymous-by-design, and the contract's DEFAULT is `authenticated` — so a\n * descriptor that declared nothing would still read as authenticated to a\n * host's gates, while saying nothing to the person adopting it. This surface\n * publishes a host's whole transactional-mail inventory and the exact wording\n * and link shape of its verification and password-reset mails, which is the\n * reference somebody writing a convincing phishing mail would want. That is\n * worth one word in the descriptor rather than a sentence in a document.\n *\n * `ADOPTING.md` states the obligation in prose as well, because a host still\n * has to supply the gate this word only asks for.\n *\n * An unknown LOCALE is a 400 rather than a silent fall back to the default.\n * This is a diagnostic surface: quietly answering the default language to\n * `?locale=es-AR` looks exactly like a product with no Spanish, which is the\n * question the operator was asking.\n */\n\n/** Twin of the wiring contract's request; no import, so this package stays liftable. */\nexport interface EmailPreviewRequest {\n /** The path segment after the mount, when the caller asked for one message. */\n params?: Readonly<Record<string, string | undefined>>;\n query?: Readonly<Record<string, string | undefined>>;\n}\n\nexport interface EmailPreviewResponse {\n status: number;\n body: unknown;\n}\n\nexport interface EmailPreviewRoute {\n method: 'GET';\n path: string;\n /**\n * The wiring contract's `WireRouteKind`, restated. Always `authenticated`\n * here: the host supplies the gate, and this is the descriptor asking for\n * one — see the docblock above for why silence was not an option.\n */\n kind: 'authenticated';\n handle(request: EmailPreviewRequest): Promise<EmailPreviewResponse>;\n}\n\nconst ok = (body: unknown): EmailPreviewResponse => ({ status: 200, body: { data: body } });\nconst fail = (status: number, error: string): EmailPreviewResponse => ({ status, body: { error } });\n\n/** `undefined` passes through as \"not asked\"; anything unknown is refused. */\nfunction readLocale(\n previews: ApiEmailPreviews,\n request: EmailPreviewRequest,\n): { ok: true; locale?: string } | { ok: false; tag: string } {\n const tag = request.query?.locale;\n if (tag === undefined || tag === '') return { ok: true };\n return previews.supportsLocale(tag) ? { ok: true, locale: tag } : { ok: false, tag };\n}\n\nexport function emailPreviewRoutes(config: EmailPreviewsConfig): EmailPreviewRoute[] {\n const previews = createEmailPreviews(config);\n\n return [\n {\n method: 'GET',\n path: '/',\n kind: 'authenticated',\n handle: (request) => {\n const locale = readLocale(previews, request);\n if (!locale.ok) return Promise.resolve(fail(400, `Unknown locale \"${locale.tag}\".`));\n return Promise.resolve(ok(previews.index(locale.locale)));\n },\n },\n {\n method: 'GET',\n path: '/:id',\n kind: 'authenticated',\n handle: (request) => {\n const locale = readLocale(previews, request);\n if (!locale.ok) return Promise.resolve(fail(400, `Unknown locale \"${locale.tag}\".`));\n const id = request.params?.id ?? '';\n const detail = previews.render(id, locale.locale);\n return Promise.resolve(detail ? ok(detail) : fail(404, `No e-mail preview named \"${id}\".`));\n },\n },\n ];\n}\n"],"mappings":";;;;;AA2HO,IAAM,+BAAN,MAAM,sCAAqC,MAAM;AAAA,EA3HxD,OA2HwD;AAAA;AAAA;AAAA,EACtD,YAAY,IAAY;AACtB,UAAM,qEAAqE,EAAE,IAAI;AACjF,SAAK,OAAO;AACZ,WAAO,eAAe,MAAM,8BAA6B,SAAS;AAAA,EACpE;AACF;AAoBA,SAAS,QAAQ,SAAwD;AACvE,QAAM,QAAQ,QAAQ;AAAA,IAAQ,CAAC,WAC7B,OAAO,KAAK,EAAE,IAAI,CAAC,aAAa,EAAE,OAAO,OAAO,OAAO,QAAQ,EAAE;AAAA,EACnE;AACA,QAAM,OAAO,oBAAI,IAAY;AAC7B,aAAW,EAAE,QAAQ,KAAK,OAAO;AAI/B,QAAI,KAAK,IAAI,QAAQ,EAAE,EAAG,OAAM,IAAI,6BAA6B,QAAQ,EAAE;AAC3E,SAAK,IAAI,QAAQ,EAAE;AAAA,EACrB;AACA,SAAO;AACT;AAbS;AAeF,SAAS,oBAAoB,QAA+C;AACjF,QAAM,EAAE,SAAS,SAAS,cAAc,IAAI;AAC5C,QAAM,WAAW,wBAAC,WAChB,UAAU,QAAQ,SAAS,MAAM,IAAI,SAAS,eAD/B;AAGjB,QAAM,QAAQ,wBAAC,EAAE,OAAO,QAAQ,GAAiB,YAAqC;AAAA,IACpF,IAAI,QAAQ;AAAA,IACZ,KAAK,QAAQ;AAAA,IACb,QAAQ,QAAQ;AAAA,IAChB;AAAA,IACA,SAAS,QAAQ,OAAO,MAAM,EAAE;AAAA,EAClC,IANc;AAQd,SAAO;AAAA,IACL,MAAM,QAAQ;AACZ,YAAM,MAAM,SAAS,MAAM;AAC3B,a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
134
|
-
//# sourceMappingURL=chunk-
|
|
134
|
+
//# sourceMappingURL=chunk-GGAZOLNN.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
UnknownNotificationRecipientError,
|
|
3
3
|
UnknownNotificationTypeError
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-GGAZOLNN.js";
|
|
5
5
|
import {
|
|
6
6
|
__name
|
|
7
7
|
} from "./chunk-7QVYU63E.js";
|
|
@@ -91,4 +91,4 @@ export {
|
|
|
91
91
|
NOTIFICATIONS_DRAIN_LEASE_MS,
|
|
92
92
|
NOTIFICATIONS_JOBS
|
|
93
93
|
};
|
|
94
|
-
//# sourceMappingURL=chunk-
|
|
94
|
+
//# sourceMappingURL=chunk-KU4FVOFA.js.map
|
|
@@ -7,14 +7,17 @@ import {
|
|
|
7
7
|
mergeChoices,
|
|
8
8
|
mergeStoredRow,
|
|
9
9
|
normalizePhoneE164
|
|
10
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-GGAZOLNN.js";
|
|
11
|
+
import {
|
|
12
|
+
messagesOf
|
|
13
|
+
} from "./chunk-M2TVBVH2.js";
|
|
11
14
|
import {
|
|
12
15
|
NOTIFICATION_CHANNELS,
|
|
13
16
|
taxonomyOf
|
|
14
|
-
} from "./chunk-
|
|
17
|
+
} from "./chunk-BGI4BQ66.js";
|
|
15
18
|
import {
|
|
16
|
-
|
|
17
|
-
} from "./chunk-
|
|
19
|
+
renderEmail
|
|
20
|
+
} from "./chunk-EKUSNUBT.js";
|
|
18
21
|
import {
|
|
19
22
|
__name
|
|
20
23
|
} from "./chunk-7QVYU63E.js";
|
|
@@ -278,6 +281,7 @@ var EMAIL_DRIVERS = {
|
|
|
278
281
|
function formatEmail(content, declaration) {
|
|
279
282
|
const href = absoluteLink(content.link, declaration.appUrl);
|
|
280
283
|
const label = declaration.linkLabel;
|
|
284
|
+
if (declaration.layout) return layoutEmail(content, declaration.layout, href, label);
|
|
281
285
|
return {
|
|
282
286
|
subject: content.title,
|
|
283
287
|
text: href ? `${content.body}
|
|
@@ -291,6 +295,20 @@ ${href}` : content.body,
|
|
|
291
295
|
};
|
|
292
296
|
}
|
|
293
297
|
__name(formatEmail, "formatEmail");
|
|
298
|
+
function layoutEmail(content, layout, href, label) {
|
|
299
|
+
const rendered = renderEmail({
|
|
300
|
+
subject: content.title,
|
|
301
|
+
heading: content.title,
|
|
302
|
+
paragraphs: [content.body],
|
|
303
|
+
action: href ? { label, href } : void 0,
|
|
304
|
+
chrome: layout.chrome,
|
|
305
|
+
brand: layout.brand,
|
|
306
|
+
locale: layout.locale,
|
|
307
|
+
theme: layout.theme
|
|
308
|
+
});
|
|
309
|
+
return { subject: rendered.subject, text: rendered.text, html: rendered.html };
|
|
310
|
+
}
|
|
311
|
+
__name(layoutEmail, "layoutEmail");
|
|
294
312
|
function emailTransport(declaration, extraDrivers = {}) {
|
|
295
313
|
const driver = resolveDriver("EMAIL", declaration, { ...EMAIL_DRIVERS, ...extraDrivers });
|
|
296
314
|
return {
|
|
@@ -665,6 +683,10 @@ async function loadRecipient(deps, userId) {
|
|
|
665
683
|
userId,
|
|
666
684
|
email: contact.email,
|
|
667
685
|
phone: contact.phone,
|
|
686
|
+
// Carried through UNRESOLVED and only where the host supplied one: the
|
|
687
|
+
// absent case has to stay distinguishable from a stated language, because
|
|
688
|
+
// that is what lets a generator apply its own default in one place.
|
|
689
|
+
...contact.locale === void 0 ? {} : { locale: contact.locale },
|
|
668
690
|
pushSubscriptionCount: await deps.pushSubscriptions.count(userId)
|
|
669
691
|
};
|
|
670
692
|
}
|
|
@@ -1206,9 +1228,9 @@ function createNotificationRouter(deps) {
|
|
|
1206
1228
|
drainPending: /* @__PURE__ */ __name((olderThanMs = DEFAULT_SWEEP_CUTOFF_MS, take = DEFAULT_SWEEP_TAKE) => drainPending(deps, olderThanMs, take), "drainPending"),
|
|
1207
1229
|
async notify(event, options = {}) {
|
|
1208
1230
|
const generator = deps.generators.resolve(event.type);
|
|
1209
|
-
const content = generator.generate(event.payload);
|
|
1210
1231
|
const recipient = await loadRecipient(deps, event.recipient.userId);
|
|
1211
1232
|
if (!recipient) throw new UnknownNotificationRecipientError(event.recipient.userId);
|
|
1233
|
+
const content = generator.generate(event.payload, { locale: recipient.locale });
|
|
1212
1234
|
const channels = await resolveChannels(deps, event, generator.category, recipient);
|
|
1213
1235
|
const notification = await commit(deps, event, generator.category, content, channels);
|
|
1214
1236
|
announce(deps, {
|
|
@@ -1327,4 +1349,4 @@ export {
|
|
|
1327
1349
|
createTransportRegistry,
|
|
1328
1350
|
createApiNotifications
|
|
1329
1351
|
};
|
|
1330
|
-
//# sourceMappingURL=chunk-
|
|
1352
|
+
//# sourceMappingURL=chunk-KZG7QGFA.js.map
|