fix(email-renderer): validate brand settings and apply them to AMP
This commit is contained in:
1 parent
fd777605e1
commit
371c23db46
5 files changed
+74
-9
No files matched your search
@@ -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,
|
||||
);
|
||||
Reference in new issue
Block a user