feat(blocks): add typed personalization resolution
Quality / quality (ubuntu-latest) (push) Failing after 9m58s
Quality / quality (windows-latest) (push) Canceled after 0s

This commit is contained in:
Clintchiz committed 2026-09-05 11:23:02 +05:30
1 parent 2428df6e78
commit 157eec7a78
9 files changed
+128 -12

No files matched your search

+7 -1
View File
@@ -92,8 +92,14 @@ export function safeUrl(
if ((value === undefined || value === "") && options.optional) return { ok: true, value: "" };
if (typeof value !== "string" || value.length > 4_096)
return fail("schema.url", "Expected a bounded URL.", path);
const token = /^\{\{\s*[A-Za-z][A-Za-z0-9_.-]*(?:\|[^{}]*)?\s*\}\}$/;
if (token.test(value)) return { ok: true, value };
try {
const parsed = new URL(value);
const templated = value.replace(
/\{\{\s*[A-Za-z][A-Za-z0-9_.-]*(?:\|[^{}]*)?\s*\}\}/g,
"variable",
);
const parsed = new URL(templated);
return schemes.has(parsed.protocol.replace(/:$/, ""))
? { ok: true, value: parsed.href }
: fail("schema.url.scheme", `URL scheme ${parsed.protocol} is not allowed.`, path);