fix(email-renderer): validate brand settings and apply them to AMP
Quality / quality (ubuntu-latest) (push) Failing after 10m1s
Quality / quality (windows-latest) (push) Canceled after 0s

This commit is contained in:
Clintchiz committed 2026-09-05 12:47:43 +05:30
1 parent fd777605e1
commit 371c23db46
5 files changed
+74 -9

No files matched your search

+42
View File
@@ -0,0 +1,42 @@
import { string, type ValueSchema } from "@wrnexus/blocks";
// Brand fields are semantic values, never arbitrary CSS declarations.
export function brandValue(
defaultValue: string,
accepts: (value: string) => boolean,
): ValueSchema<string> {
const base = string({ default: defaultValue, max: 160 });
return {
...base,
parse(value, path = "value") {
const result = base.parse(value, path);
if (!result.ok) return result;
return accepts(result.value)
? result
: {
ok: false,
errors: [
{
code: "email.brand",
message: "Unsupported brand style value.",
severity: "error",
path,
},
],
};
},
};
}
export const brandColor = (fallback: string) =>
brandValue(fallback, (value) =>
/^(#[0-9a-f]{3}|#[0-9a-f]{6}|#[0-9a-f]{8}|transparent)$/i.test(value),
);
export const brandFont = brandValue(
"Arial, sans-serif",
(value) => /^[a-z0-9 ,'"-]+$/i.test(value) && /[a-z]/i.test(value),
);
export const brandWidth = brandValue(
"600",
(value) => /^\d{2,4}$/.test(value) && Number(value) >= 240 && Number(value) <= 1200,
);