fix(email): validate MJML before exposing exports
This commit is contained in:
1 parent
2a93e141aa
commit
88f2e456ef
3 files changed
+20
-2
No files matched your search
@@ -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) {
|
||||
|
||||
Reference in new issue
Block a user