fix(email): validate MJML before exposing exports
Quality / quality (ubuntu-latest) (push) Failing after 1s
Quality / quality (windows-latest) (push) Canceled after 0s

This commit is contained in:
Clintchiz committed 2026-09-05 15:59:56 +05:30
1 parent 2a93e141aa
commit 88f2e456ef
3 files changed
+20 -2

No files matched your search

+8 -1
View File
@@ -13,6 +13,7 @@ import {
type Result,
} from "@wrnexus/blocks";
import { emailCoreBlocks, ampLayoutCss } from "./blocks.ts";
import { validateMjml } from "./mjml.ts";
interface AmpValidationError {
severity: string;
@@ -168,7 +169,13 @@ export async function renderEmail(
warnings,
assets: [],
};
if (mjmlResult?.ok) bundle.exports = { mjml: mjmlResult.value.content };
if (mjmlResult?.ok) {
const diagnostics = await validateMjml(mjmlResult.value.content);
if (!diagnostics.length) bundle.exports = { mjml: mjmlResult.value.content };
else warnings.push(...diagnostics.map(diagnostic => ({ ...diagnostic, severity: "warning" as const })));
} else if (mjmlResult) {
warnings.push(...mjmlResult.errors.map(diagnostic => ({ ...diagnostic, severity: "warning" as const })));
}
if (options.amp) {
const amp = await renderTree(source, emailKind, registry, { ...base, target: "ampEmail", data: options.variables });
if (amp.ok) {