feat(email-renderer): render countdown images across email targets
This commit is contained in:
1 parent
4df4173dfb
commit
d1f42e0566
4 files changed
+47
-4
No files matched your search
@@ -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 }),
|
||||
|
||||
Reference in new issue
Block a user