fix(email): preserve personalization tokens for template rendering
Quality / quality (ubuntu-latest) (push) Failing after 10m0s
Quality / quality (windows-latest) (push) Canceled after 0s

This commit is contained in:
Clintchiz committed 2026-09-05 15:37:36 +05:30
1 parent 8bc8fe85c3
commit e1ea6e2977
5 files changed
+41 -3

No files matched your search

+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@wrnexus/blocks",
"version": "0.1.2",
"version": "0.1.3",
"type": "module",
"description": "Pure dynamic block document engine for WRNexus builders.",
"exports": {
+4 -1
View File
@@ -27,9 +27,11 @@ export function resolveDocumentVariables(
document: BlockDocument,
catalog: Record<string, "string" | "number" | "date" | "boolean">,
data: Record<string, unknown> = {},
options: { requireValues?: boolean } = {},
options: { requireValues?: boolean; preserveTokens?: boolean } = {},
): Result<BlockDocument> {
const diagnostics: Diagnostic[] = [];
if (options.preserveTokens && options.requireValues)
return { ok: false, errors: [{ code: "variable.mode", message: "Template tokens cannot be preserved when resolved values are required.", severity: "error" }] };
const visit = (value: JsonValue, path: string): JsonValue => {
if (typeof value === "string")
return value.replace(TOKEN, (raw, key: string, fallback: string | undefined) => {
@@ -38,6 +40,7 @@ export function resolveDocumentVariables(
diagnostics.push({ code: "variable.unknown", message: `Unknown variable ${key}.`, severity: "error", path });
return raw;
}
if (options.preserveTokens) return raw;
const supplied = data[key];
if (supplied === undefined || supplied === null || supplied === "") {
if (fallback !== undefined) return fallback.trim();