feat(email-renderer): render countdown images across email targets
Quality / quality (ubuntu-latest) (push) Failing after 11m4s
Quality / quality (windows-latest) (push) Canceled after 0s

This commit is contained in:
Clintchiz committed 2026-09-05 12:27:39 +05:30
1 parent 4df4173dfb
commit d1f42e0566
4 files changed
+47 -4

No files matched your search

+10
View File
@@ -106,18 +106,28 @@ export async function renderEmail(
direction?: "ltr" | "rtl";
variables?: Record<string, unknown>;
requireVariables?: boolean;
countdownImageUrl?: string;
} = {},
): Promise<Result<EmailRenderBundle>> {
const personalized = resolveDocumentVariables(document, emailKind.variables, options.variables, {
requireValues: options.requireVariables,
});
if (!personalized.ok) return personalized;
if (options.countdownImageUrl) {
try {
const url = new URL(options.countdownImageUrl);
if (url.username || url.password || (url.protocol !== "https:" && !(url.protocol === "http:" && (url.hostname === "localhost" || url.hostname.endsWith(".localhost"))))) throw new Error();
} catch {
return { ok: false, errors: [{ code: "countdown.endpoint", message: "Countdown images require HTTPS (or a local development host).", severity: "error" }] };
}
}
const source = personalized.value;
const registry = registryForKind(emailKind).freeze();
const base = {
locale: options.locale ?? "en",
timezone: options.timezone ?? "UTC",
direction: options.direction ?? "ltr",
countdownImageUrl: options.countdownImageUrl,
};
const [htmlResult, textResult, mjmlResult] = await Promise.all([
renderTree(source, emailKind, registry, { ...base, target: "emailHtml", data: options.variables }),