@templatical/template-tools 0.46.0 → 0.47.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1 @@
1
+ {"version":3,"file":"custom-block-sAM61QPU.js","names":["rawSchema","rawSchema"],"sources":["../schema.json","../src/validate.ts","../src/custom-block/safety.ts","../src/custom-block/a11y.ts","../custom-block-schema.json","../src/custom-block/definition.ts","../src/custom-block/liquid.ts","../src/custom-block/recipe.ts","../src/custom-block/specimen.ts","../src/custom-block/render.ts","../src/custom-block/check.ts"],"sourcesContent":["","// Structural validation of a Templatical template against the generated JSON\n// Schema, plus the @templatical/quality lint layered on top.\n//\n// Structural validation is discriminator-aware: each block is checked against\n// the subschema for its declared `type` (e.g. a block with `\"type\": \"button\"`\n// is validated as a ButtonBlock), so errors are precise (\"blocks[2] (button)\n// must have required property 'url'\") instead of the raw anyOf's \"must match\n// exactly one schema in anyOf\".\n\nimport Ajv, { type ValidateFunction, type ErrorObject } from \"ajv\";\nimport { lintTemplate, type LintIssue } from \"@templatical/quality\";\nimport type { TemplateContent } from \"@templatical/types\";\nimport rawSchema from \"../schema.json\";\n\ninterface SchemaDefinition {\n properties?: { type?: { const?: unknown } } & Record<string, unknown>;\n [key: string]: unknown;\n}\n\ninterface SchemaDocument {\n definitions: Record<string, SchemaDefinition>;\n [key: string]: unknown;\n}\n\n/** The generated JSON Schema for `TemplateContent`, as a plain object. */\nexport const schema = rawSchema as unknown as SchemaDocument;\n\nconst ajv = new Ajv({ allErrors: true, strict: false });\n\n// Map a block's `type` discriminator (e.g. \"button\", \"social\") to its schema\n// definition name (e.g. \"ButtonBlock\", \"SocialIconsBlock\"), derived from the\n// schema itself so it never drifts from the generated defs.\nconst typeToDef: Record<string, string> = {};\nfor (const [name, def] of Object.entries(schema.definitions)) {\n const constType = def?.properties?.type?.const;\n if (typeof constType === \"string\") {\n typeToDef[constType] = name;\n }\n}\n\nconst validatorCache = new Map<string, ValidateFunction>();\n\nfunction validatorFor(defName: string): ValidateFunction {\n const cached = validatorCache.get(defName);\n if (cached) return cached;\n\n const definitions = structuredClone(schema.definitions);\n // A section's `children` holds nested blocks (Block[][]); we recurse into\n // them separately for precise paths, so stub the deep check here.\n if (defName === \"SectionBlock\") {\n const section = definitions.SectionBlock;\n if (section?.properties) {\n section.properties.children = { type: \"array\" };\n }\n }\n const compiled = ajv.compile({\n $ref: `#/definitions/${defName}`,\n definitions,\n });\n validatorCache.set(defName, compiled);\n return compiled;\n}\n\nconst settingsValidator = ajv.compile({\n $ref: \"#/definitions/TemplateSettings\",\n definitions: structuredClone(schema.definitions),\n});\n\ninterface FlatBlock {\n path: string;\n block: Record<string, unknown> | null;\n}\n\nfunction flattenBlocks(\n blocks: unknown,\n basePath: string,\n out: FlatBlock[],\n): void {\n if (!Array.isArray(blocks)) return;\n blocks.forEach((block, i) => {\n const path = `${basePath}[${i}]`;\n out.push({ path, block: block ?? null });\n if (block?.type === \"section\" && Array.isArray(block.children)) {\n block.children.forEach((column: unknown, ci: number) => {\n flattenBlocks(column, `${path}.children[${ci}]`, out);\n });\n }\n });\n}\n\nfunction formatAjvErrors(\n errors: ErrorObject[] | null | undefined,\n prefix: string,\n): string[] {\n return (errors ?? []).map((e) => {\n const where = `${prefix}${e.instancePath}`;\n const extra =\n e.keyword === \"additionalProperties\"\n ? ` (${(e.params as { additionalProperty?: string }).additionalProperty})`\n : \"\";\n return `${where} ${e.message}${extra}`;\n });\n}\n\nexport interface ValidationResult {\n valid: boolean;\n errors: string[];\n}\n\n/**\n * Structural validation. Synchronous, depends only on ajv + the committed\n * schema.json (no build of the workspace packages required).\n */\nexport function validateTemplate(data: unknown): ValidationResult {\n const errors: string[] = [];\n\n if (data === null || typeof data !== \"object\" || Array.isArray(data)) {\n return { valid: false, errors: [\"(root) must be an object\"] };\n }\n\n const doc = data as Record<string, unknown>;\n\n if (!Array.isArray(doc.blocks)) {\n errors.push(\"blocks must be an array\");\n }\n if (doc.settings === null || typeof doc.settings !== \"object\") {\n errors.push(\"settings must be an object\");\n } else if (!settingsValidator(doc.settings)) {\n errors.push(...formatAjvErrors(settingsValidator.errors, \"settings\"));\n }\n\n const flat: FlatBlock[] = [];\n flattenBlocks(doc.blocks, \"blocks\", flat);\n for (const { path, block } of flat) {\n const type = block?.type;\n const defName = typeof type === \"string\" ? typeToDef[type] : undefined;\n if (!defName) {\n const known = Object.keys(typeToDef).join(\", \");\n errors.push(\n `${path} has unknown or missing block type ${JSON.stringify(type)} (expected one of: ${known})`,\n );\n continue;\n }\n const validate = validatorFor(defName);\n if (!validate(block)) {\n errors.push(...formatAjvErrors(validate.errors, `${path} (${type})`));\n }\n }\n\n return { valid: errors.length === 0, errors };\n}\n\nexport interface QualityLintResult {\n issues: LintIssue[];\n /** Set when the linter itself threw — the template is structurally suspect. */\n error?: string;\n}\n\n/**\n * Quality layer — accessibility / structure / link linting.\n *\n * Assumes structurally-valid input, so callers should run `validateTemplate`\n * first; the try/catch is a guard against a malformed template crashing the\n * linter rather than a substitute for that ordering.\n */\nexport function runQualityLint(data: unknown): QualityLintResult {\n try {\n return { issues: lintTemplate(data as TemplateContent) ?? [] };\n } catch (err) {\n return { issues: [], error: (err as Error).message };\n }\n}\n","// Email-client safety over a custom block's rendered HTML. Custom blocks are\n// raw HTML the SDK passes through untouched (inside <mj-text>), so nothing\n// downstream repairs a layout Outlook can't draw; this is the only check.\n// Rules run on every specimen state's output so both sides of each {% if %}\n// are seen, and an empty optional image surfaces as src=\"\".\n\nimport { Parser } from \"htmlparser2\";\nimport type { RenderedState } from \"./render\";\nimport type { CustomBlockIssue, CustomBlockWorkingFile } from \"./types\";\n\nconst FLEX_GRID = /(^|;)\\s*display\\s*:\\s*(inline-)?(flex|grid)\\b/i;\nconst POSITION = /(^|;)\\s*position\\s*:\\s*(absolute|fixed)\\b/i;\nconst DIV_LAYOUT = /(^|;)\\s*(width|max-width|float)\\s*:/i;\n// `var(--x)` anywhere: Gmail and Outlook drop custom properties, and with them\n// the whole declaration that reads one.\nconst CSS_VARIABLE = /\\bvar\\(\\s*--/i;\n// A colour value in a `background:` shorthand: hex, or an rgb()/hsl() call.\nconst COLOR_VALUE = /#[0-9a-f]{3,8}\\b|\\b(?:rgba?|hsla?)\\(/i;\nconst FORM_CONTROLS = new Set([\"form\", \"input\", \"select\", \"textarea\"]);\n\n// The same two layout rules over stylesheet text, where a declaration can\n// also follow `{` or a newline.\nconst CSS_FLEX_GRID = /(^|[;{\\s])display\\s*:\\s*(inline-)?(flex|grid)\\b/i;\nconst CSS_POSITION = /(^|[;{\\s])position\\s*:\\s*(absolute|fixed)\\b/i;\n\nconst IMPORT_MESSAGE =\n \"`@import` is dropped by most email clients; inline the rules.\";\nconst FLEX_GRID_MESSAGE =\n \"`display: flex`/`grid` is ignored by Outlook and Gmail on many clients; use tables.\";\nconst POSITION_MESSAGE =\n \"`position: absolute/fixed` is unsupported in email clients.\";\nconst CSS_VARIABLE_MESSAGE =\n \"CSS custom properties (`var(--…)`) are dropped by Gmail and Outlook, and the whole declaration with them; write the value itself.\";\n\n/** A style attribute's declarations as lowercase property → raw value pairs. */\nexport function declarations(style: string): [string, string][] {\n const out: [string, string][] = [];\n for (const part of style.split(\";\")) {\n const colon = part.indexOf(\":\");\n if (colon > 0) {\n out.push([\n part.slice(0, colon).trim().toLowerCase(),\n part.slice(colon + 1),\n ]);\n }\n }\n return out;\n}\n\n/**\n * Whether a background image here has a colour to fall back on when images\n * are blocked: `background-color`, a colour inside the `background:`\n * shorthand, or the `bgcolor` attribute Outlook reads.\n */\nfunction backgroundIssue(\n style: string,\n attrs: Record<string, string>,\n): boolean {\n const decls = declarations(style);\n const hasImage = decls.some(\n ([prop, value]) =>\n (prop === \"background\" || prop === \"background-image\") &&\n /url\\(/i.test(value),\n );\n if (!hasImage || \"bgcolor\" in attrs) return false;\n return !decls.some(\n ([prop, value]) =>\n prop === \"background-color\" ||\n (prop === \"background\" &&\n COLOR_VALUE.test(stripCssUrlsAndStrings(value))),\n );\n}\n\n/** Drops `/* … *\\/` comments in one linear pass; an unterminated comment drops the rest. */\nexport function stripCssComments(css: string): string {\n let out = \"\";\n let i = 0;\n for (;;) {\n const open = css.indexOf(\"/*\", i);\n if (open === -1) return out + css.slice(i);\n out += css.slice(i, open);\n const close = css.indexOf(\"*/\", open + 2);\n if (close === -1) return out;\n i = close + 2;\n }\n}\n\n/**\n * Remove `url(...)` and quoted strings so the class scan can't read `.png` or\n * `\"x.y\"` as a selector. Linear: each opener's next position is searched for\n * again only once the cursor has passed it, so an opener that never closes\n * costs one scan, not one per occurrence. An unterminated `url(` or quote\n * drops the rest, as a CSS parser would.\n */\nexport function stripCssUrlsAndStrings(css: string): string {\n const lower = css.toLowerCase();\n const next = (needle: string, from: number) => {\n const at = lower.indexOf(needle, from);\n return at === -1 ? Infinity : at;\n };\n const closers: Record<string, string> = { \"url(\": \")\", '\"': '\"', \"'\": \"'\" };\n const pos: Record<string, number> = { \"url(\": 0, '\"': 0, \"'\": 0 };\n for (const k of Object.keys(pos)) pos[k] = next(k, 0);\n let out = \"\";\n let i = 0;\n for (;;) {\n let opener = \"\";\n let open = Infinity;\n for (const k of Object.keys(pos)) {\n if (pos[k] < i) pos[k] = next(k, i);\n if (pos[k] < open) {\n open = pos[k];\n opener = k;\n }\n }\n if (open === Infinity) return out + css.slice(i);\n out += css.slice(i, open);\n const close = lower.indexOf(closers[opener], open + opener.length);\n if (close === -1) return out;\n i = close + 1;\n }\n}\n\n/** Layout rules that hold for stylesheet text: the definition's and a `<style>`'s. */\nfunction cssLayoutIssues(css: string, path?: string): CustomBlockIssue[] {\n const text = stripCssComments(css);\n const issues: CustomBlockIssue[] = [];\n const at = path === undefined ? {} : { path };\n if (CSS_FLEX_GRID.test(text))\n issues.push({\n ruleId: \"safety.flex-grid\",\n severity: \"error\",\n ...at,\n message: FLEX_GRID_MESSAGE,\n });\n if (CSS_POSITION.test(text))\n issues.push({\n ruleId: \"safety.position\",\n severity: \"error\",\n ...at,\n message: POSITION_MESSAGE,\n });\n if (CSS_VARIABLE.test(text))\n issues.push({\n ruleId: \"safety.css-variable\",\n severity: \"warning\",\n ...at,\n message: CSS_VARIABLE_MESSAGE,\n });\n return issues;\n}\n\nfunction stylesheetIssues(\n def: CustomBlockWorkingFile,\n css: string,\n): CustomBlockIssue[] {\n const issues: CustomBlockIssue[] = [];\n if (/@import\\b/i.test(stripCssComments(css))) {\n issues.push({\n ruleId: \"safety.import\",\n severity: \"error\",\n path: \"/stylesheet\",\n message: IMPORT_MESSAGE,\n });\n }\n issues.push(...cssLayoutIssues(css, \"/stylesheet\"));\n const stripped = stripCssUrlsAndStrings(stripCssComments(css));\n const prefix = `tplc-${def.type}-`;\n const unscoped = [\n ...new Set(\n [...stripped.matchAll(/\\.(-?[_a-zA-Z][\\w-]*)/g)].map((m) => m[1]),\n ),\n ].filter((cls) => !cls.startsWith(prefix));\n if (unscoped.length > 0) {\n issues.push({\n ruleId: \"safety.unscoped-class\",\n severity: \"warning\",\n path: \"/stylesheet\",\n message: `Classes ${unscoped.map((c) => `.${c}`).join(\", \")} aren't prefixed \\`${prefix}\\`; the SDK doesn't scope them, so they can collide with other blocks.`,\n });\n }\n return issues;\n}\n\nexport function checkEmailSafety(\n def: CustomBlockWorkingFile,\n rendered: RenderedState[],\n): CustomBlockIssue[] {\n const issues: CustomBlockIssue[] = [];\n const add = (\n ruleId: string,\n severity: CustomBlockIssue[\"severity\"],\n message: string,\n ) => issues.push({ ruleId, severity, message });\n\n for (const { state, html } of rendered) {\n let inStyle = false;\n let styleText = \"\";\n const parser = new Parser(\n {\n onopentag(name, attrs) {\n const style = attrs.style ?? \"\";\n if (FLEX_GRID.test(style))\n add(\"safety.flex-grid\", \"error\", FLEX_GRID_MESSAGE);\n if (POSITION.test(style))\n add(\"safety.position\", \"error\", POSITION_MESSAGE);\n if (CSS_VARIABLE.test(style))\n add(\"safety.css-variable\", \"warning\", CSS_VARIABLE_MESSAGE);\n if (backgroundIssue(style, attrs))\n add(\n \"safety.bg-image-fallback\",\n \"warning\",\n \"A background image needs a fallback colour (`background-color`, a colour in `background:`, or `bgcolor`); many clients block images.\",\n );\n if (name === \"svg\")\n add(\n \"safety.svg\",\n \"error\",\n \"Inline `<svg>` is stripped by Gmail and not drawn by Outlook; use a PNG `<img>`.\",\n );\n if (FORM_CONTROLS.has(name))\n add(\n \"safety.form\",\n \"warning\",\n `\\`<${name}>\\` doesn't work in most email clients (Gmail and Outlook disable forms); link to a page instead.`,\n );\n if (name === \"script\")\n add(\n \"safety.script\",\n \"error\",\n \"`<script>` is stripped by every email client.\",\n );\n if (\n name === \"link\" &&\n (attrs.rel ?? \"\").toLowerCase() === \"stylesheet\"\n )\n add(\n \"safety.external-stylesheet\",\n \"error\",\n \"External stylesheets are not loaded by email clients; use inline styles or `stylesheet`.\",\n );\n if (name === \"style\") {\n inStyle = true;\n styleText = \"\";\n add(\n \"safety.style-tag\",\n \"warning\",\n \"Move `<style>` rules into the definition's `stylesheet`, which the renderer places in `<mj-head>`.\",\n );\n }\n if (name === \"div\" && DIV_LAYOUT.test(style))\n add(\n \"safety.div-layout\",\n \"warning\",\n \"A `<div>` carrying width or float is unreliable in Outlook; lay out with tables.\",\n );\n if (name === \"img\") {\n if (!(\"alt\" in attrs))\n add(\n \"safety.img-alt\",\n \"warning\",\n 'Every `<img>` needs an `alt` attribute (`alt=\"\"` for decorative images), ideally bound to a field.',\n );\n if (!(\"width\" in attrs))\n add(\n \"safety.img-width\",\n \"warning\",\n \"Give `<img>` a `width` attribute; Outlook ignores CSS widths on images.\",\n );\n if ((attrs.src ?? \"\") === \"\")\n add(\n \"safety.empty-img-src\",\n \"warning\",\n `An \\`<img>\\` renders with an empty \\`src\\` in the \"${state}\" state; wrap it in \\`{% if <field> != blank %}\\` (Liquid treats an empty string as true, so a bare \\`{% if <field> %}\\` doesn't hide it).`,\n );\n }\n },\n ontext(text) {\n if (inStyle) styleText += text;\n },\n onclosetag(name) {\n if (name === \"style\") {\n inStyle = false;\n if (/@import\\b/i.test(stripCssComments(styleText)))\n add(\"safety.import\", \"error\", IMPORT_MESSAGE);\n issues.push(...cssLayoutIssues(styleText));\n }\n },\n },\n { decodeEntities: true },\n );\n parser.write(html);\n parser.end();\n }\n if (def.stylesheet) issues.push(...stylesheetIssues(def, def.stylesheet));\n\n const seen = new Set<string>();\n return issues.filter((i) => {\n const k = `${i.ruleId}\\0${i.path ?? \"\"}\\0${i.message}`;\n if (seen.has(k)) return false;\n seen.add(k);\n return true;\n });\n}\n","// Accessibility over a custom block's rendered HTML, on every specimen state.\n// Built-in blocks get @templatical/quality's rules from structured fields; a\n// custom block is opaque HTML, so these read the markup itself. All are\n// warnings: they read inline markup only, and a block's colours or table use\n// can come from context they can't see.\n\nimport { Parser } from \"htmlparser2\";\nimport {\n getContrastRatio,\n isOpaqueHex,\n lintAccessibility,\n} from \"@templatical/quality\";\nimport {\n createDefaultTemplateContent,\n createParagraphBlock,\n} from \"@templatical/types\";\nimport type { RenderedState } from \"./render\";\nimport { declarations, stripCssUrlsAndStrings } from \"./safety\";\nimport type { CustomBlockIssue } from \"./types\";\n\nconst HEX = /#[0-9a-f]{3,8}\\b/i;\nconst PX = /^\\s*(\\d+(?:\\.\\d+)?)px/i;\n\ninterface Frame {\n color?: string;\n background?: string;\n fontSize?: number;\n}\n\n/** The colours and font size an element sets inline, over its parent's. */\nfunction frameFor(attrs: Record<string, string>, parent: Frame): Frame {\n const frame: Frame = { ...parent };\n if (attrs.bgcolor && isOpaqueHex(attrs.bgcolor))\n frame.background = attrs.bgcolor;\n for (const [prop, raw] of declarations(attrs.style ?? \"\")) {\n const value = raw.replace(/!important/i, \"\").trim();\n if (prop === \"color\" && isOpaqueHex(value)) frame.color = value;\n if (prop === \"background-color\" && isOpaqueHex(value))\n frame.background = value;\n if (prop === \"background\") {\n const hex = stripCssUrlsAndStrings(value).match(HEX)?.[0];\n if (hex && isOpaqueHex(hex)) frame.background = hex;\n }\n if (prop === \"font-size\") {\n const px = value.match(PX)?.[1];\n if (px) frame.fontSize = Number(px);\n }\n }\n return frame;\n}\n\n/** quality's own vague-link rule, run over the HTML as if it were a paragraph. */\nfunction vagueLinkMessages(html: string): string[] {\n const content = createDefaultTemplateContent();\n content.blocks = [createParagraphBlock({ content: html })];\n return lintAccessibility(content)\n .filter((i) => i.ruleId === \"a11y.link-vague-text\")\n .map((i) => i.message);\n}\n\nexport function checkAccessibility(\n rendered: RenderedState[],\n): CustomBlockIssue[] {\n const issues: CustomBlockIssue[] = [];\n const add = (ruleId: string, message: string) =>\n issues.push({ ruleId, severity: \"warning\", message });\n\n for (const { state, html } of rendered) {\n for (const message of vagueLinkMessages(html)) {\n add(\"a11y.link-vague-text\", message);\n }\n\n const frames: Frame[] = [{}];\n const tables: { presentation: boolean; hasHeader: boolean }[] = [];\n let link: { named: boolean } | null = null;\n\n const parser = new Parser(\n {\n onopentag(name, attrs) {\n frames.push(frameFor(attrs, frames[frames.length - 1]));\n if (name === \"table\") {\n const role = (attrs.role ?? \"\").toLowerCase();\n tables.push({\n presentation: role === \"presentation\" || role === \"none\",\n hasHeader: false,\n });\n }\n if (name === \"th\" && tables.length > 0) {\n tables[tables.length - 1].hasHeader = true;\n }\n if (name === \"a\") {\n link = {\n named:\n (attrs[\"aria-label\"] ?? \"\").trim() !== \"\" ||\n (attrs.title ?? \"\").trim() !== \"\",\n };\n }\n if (name === \"img\" && link && (attrs.alt ?? \"\").trim() !== \"\") {\n link.named = true;\n }\n },\n ontext(text) {\n const trimmed = text.trim();\n if (trimmed === \"\") return;\n if (link) link.named = true;\n const { color, background, fontSize } = frames[frames.length - 1];\n if (!color || !background) return;\n const required = (fontSize ?? 0) >= 24 ? 3 : 4.5;\n const ratio = getContrastRatio(color, background);\n if (Number.isNaN(ratio) || ratio >= required) return;\n add(\n \"a11y.contrast\",\n `Text in ${color} on ${background} has ${ratio.toFixed(2)}:1 contrast; it needs ${required}:1.`,\n );\n },\n onclosetag(name) {\n frames.pop();\n if (name === \"table\") {\n const table = tables.pop();\n if (table && !table.presentation && !table.hasHeader) {\n add(\n \"a11y.table-role\",\n 'A layout `<table>` needs `role=\"presentation\"`, or screen readers read it as a data table, cell by cell. A data table needs `<th>` headers instead.',\n );\n }\n }\n if (name === \"a\" && link) {\n if (!link.named) {\n add(\n \"a11y.link-no-name\",\n `A link has no text, \\`aria-label\\` or image \\`alt\\` in the \"${state}\" state, so a screen reader announces only \"link\".`,\n );\n }\n link = null;\n }\n },\n },\n { decodeEntities: true },\n );\n parser.write(html);\n parser.end();\n }\n\n const seen = new Set<string>();\n return issues.filter((i) => {\n const key = `${i.ruleId}\\0${i.message}`;\n if (seen.has(key)) return false;\n seen.add(key);\n return true;\n });\n}\n","","// Structural validation of a custom block definition: the generated\n// CustomBlockDefinition schema (dataSource excluded, see generate-schema.mjs),\n// the hand-written dataSourcePreview recipe schema, and the field-model checks\n// a JSON Schema can't express (duplicate keys, bounds that are ordered,\n// defaults within bounds). It takes a JSON working file or the object a\n// consumer's own module exports, `dataSource` function included, so the same\n// check can run in their CI over the definitions they ship.\n\nimport Ajv, { type ErrorObject } from \"ajv\";\nimport rawSchema from \"../../custom-block-schema.json\";\nimport type { CustomBlockCheckResult, CustomBlockIssue } from \"./types\";\n\nconst ajv = new Ajv({ allErrors: true, strict: false });\nconst validateDefinition = ajv.compile(rawSchema as object);\n\n// Owned by this package: the recipe is a template-tools concept, not part of\n// the SDK's block model, so it has no generated schema to drift from.\n// Reports the first problem only: a recipe is small, and one pointed message\n// reads better than a cascade of missing-property errors.\nconst validateRecipe = new Ajv({ allErrors: false, strict: false }).compile({\n type: \"object\",\n additionalProperties: false,\n required: [\"label\", \"request\", \"map\"],\n properties: {\n label: { type: \"string\", minLength: 1 },\n request: {\n type: \"object\",\n additionalProperties: false,\n required: [\"url\"],\n properties: {\n method: { enum: [\"GET\", \"POST\"] },\n url: { type: \"string\", minLength: 1 },\n headers: { type: \"object\", additionalProperties: { type: \"string\" } },\n body: { type: \"string\" },\n },\n },\n map: {\n type: \"object\",\n additionalProperties: { type: \"string\", minLength: 1 },\n },\n },\n});\n\nfunction schemaIssues(\n errors: ErrorObject[] | null | undefined,\n base = \"\",\n): CustomBlockIssue[] {\n return (errors ?? []).map((e) => ({\n ruleId: \"schema\",\n severity: \"error\",\n path: `${base}${e.instancePath}` || \"/\",\n message: `${base}${e.instancePath || \"\"} ${e.message ?? \"is invalid\"}${\n e.keyword === \"additionalProperties\"\n ? ` (\\`${(e.params as { additionalProperty: string }).additionalProperty}\\`)`\n : \"\"\n }`.trim(),\n }));\n}\n\ninterface FieldLike {\n key: string;\n type: string;\n default?: unknown;\n min?: number;\n max?: number;\n minItems?: number;\n maxItems?: number;\n options?: { value: string }[];\n fields?: FieldLike[];\n}\n\nconst isCount = (n: number | undefined) =>\n n === undefined || (Number.isInteger(n) && n >= 0);\n\nfunction fieldIssues(fields: FieldLike[], base: string): CustomBlockIssue[] {\n const issues: CustomBlockIssue[] = [];\n const seen = new Set<string>();\n fields.forEach((field, i) => {\n const path = `${base}/${i}`;\n if (seen.has(field.key)) {\n issues.push({\n ruleId: \"field.duplicate-key\",\n severity: \"error\",\n path,\n message: `Field key \\`${field.key}\\` is used twice; the second would overwrite the first's value.`,\n });\n }\n seen.add(field.key);\n if (\n field.type === \"number\" &&\n field.min !== undefined &&\n field.max !== undefined &&\n field.min > field.max\n ) {\n issues.push({\n ruleId: \"field.range\",\n severity: \"error\",\n path,\n message: `\\`${field.key}\\` has min ${field.min} above max ${field.max}, so no value is allowed.`,\n });\n }\n if (field.type === \"number\" && typeof field.default === \"number\") {\n const below = field.min !== undefined && field.default < field.min;\n const above = field.max !== undefined && field.default > field.max;\n if (below || above) {\n issues.push({\n ruleId: \"field.default-range\",\n severity: \"error\",\n path: `${path}/default`,\n message: `\\`${field.key}\\` defaults to ${field.default}, outside ${field.min ?? \"-∞\"}–${field.max ?? \"∞\"}.`,\n });\n }\n }\n if (\n field.type === \"select\" &&\n field.default !== undefined &&\n !(field.options ?? []).some((o) => o.value === field.default)\n ) {\n issues.push({\n ruleId: \"field.default-option\",\n severity: \"error\",\n path: `${path}/default`,\n message: `\\`${field.key}\\` defaults to \"${String(field.default)}\", which is not one of its options.`,\n });\n }\n if (field.type === \"repeatable\") {\n const { minItems, maxItems } = field;\n if (!isCount(minItems) || !isCount(maxItems)) {\n issues.push({\n ruleId: \"field.items-range\",\n severity: \"error\",\n path,\n message: `\\`${field.key}\\`'s minItems and maxItems must be whole numbers of 0 or more.`,\n });\n } else if (\n minItems !== undefined &&\n maxItems !== undefined &&\n minItems > maxItems\n ) {\n issues.push({\n ruleId: \"field.items-range\",\n severity: \"error\",\n path,\n message: `\\`${field.key}\\` has minItems ${minItems} above maxItems ${maxItems}, so no list length is allowed.`,\n });\n } else if (Array.isArray(field.default)) {\n const n = field.default.length;\n if (\n (minItems !== undefined && n < minItems) ||\n (maxItems !== undefined && n > maxItems)\n ) {\n issues.push({\n ruleId: \"field.default-items\",\n severity: \"error\",\n path: `${path}/default`,\n message: `\\`${field.key}\\` defaults to ${n} item(s), outside ${minItems ?? 0}–${maxItems ?? \"∞\"}; the palette would insert a list the editor won't allow.`,\n });\n }\n }\n if (field.fields) {\n issues.push(...fieldIssues(field.fields, `${path}/fields`));\n }\n }\n });\n return issues;\n}\n\n/**\n * A module's `dataSource` is `{ label, onFetch }` with a function, which the\n * schema can't describe (the generator hides functions). A JSON working file\n * can't hold a function at all, so there it is always an error that points at\n * `dataSourcePreview`.\n */\nfunction dataSourceIssues(dataSource: unknown): CustomBlockIssue[] {\n const ds = dataSource as { label?: unknown; onFetch?: unknown } | null;\n const issue = (message: string): CustomBlockIssue[] => [\n { ruleId: \"schema\", severity: \"error\", path: \"/dataSource\", message },\n ];\n if (ds === null || typeof ds !== \"object\" || Array.isArray(ds)) {\n return issue(\"`dataSource` must be an object with `label` and `onFetch`.\");\n }\n if (typeof ds.onFetch !== \"function\") {\n return issue(\n \"`dataSource.onFetch` must be a function. A JSON working file can't hold one: preview with `dataSourcePreview`, and write `dataSource` in the module at handoff.\",\n );\n }\n if (typeof ds.label !== \"string\" || ds.label === \"\") {\n return issue(\"`dataSource.label` must be a non-empty string.\");\n }\n return [];\n}\n\nexport function validateCustomBlockDefinition(\n data: unknown,\n): CustomBlockCheckResult {\n if (data === null || typeof data !== \"object\" || Array.isArray(data)) {\n return {\n valid: false,\n issues: [\n {\n ruleId: \"schema\",\n severity: \"error\",\n path: \"/\",\n message: \"A custom block definition must be a JSON object.\",\n },\n ],\n };\n }\n const { dataSourcePreview, dataSource, ...definition } = data as Record<\n string,\n unknown\n >;\n const issues: CustomBlockIssue[] = [];\n if (dataSource !== undefined) issues.push(...dataSourceIssues(dataSource));\n if (!validateDefinition(definition)) {\n issues.push(...schemaIssues(validateDefinition.errors));\n }\n if (dataSourcePreview !== undefined && !validateRecipe(dataSourcePreview)) {\n issues.push(...schemaIssues(validateRecipe.errors, \"/dataSourcePreview\"));\n }\n if (issues.length === 0) {\n issues.push(\n ...fieldIssues((definition as { fields: FieldLike[] }).fields, \"/fields\"),\n );\n }\n return { valid: !issues.some((i) => i.severity === \"error\"), issues };\n}\n","// Static analysis of a custom block's Liquid template against its field\n// model. The engine options must equal the editor's renderer\n// (packages/editor/src/composables/useBlockRegistry.ts): a template that\n// renders here and fails there, or the reverse, makes every check below lie.\n// tests/custom-block-liquid.test.ts holds the two equal.\n\nimport { ForTag, Liquid, Output, Tag, type Template } from \"liquidjs\";\nimport type { CustomBlockIssue, CustomBlockWorkingFile } from \"./types\";\n\nexport function createLiquid(): Liquid {\n // `templates: {}` resolves include/render/layout against an empty in-memory\n // map, never the disk. Without it, Node's engine reads files relative to\n // the cwd: a recipe body could carry `.env` to the API host, and a template\n // would render here while the editor, which has no partials, fails.\n return new Liquid({\n strictVariables: false,\n strictFilters: false,\n templates: {},\n });\n}\n\n// `forloop` is Liquid's own loop object, never a field.\nconst LIQUID_GLOBALS = new Set([\"forloop\"]);\n\n// Tags that load another template file. A custom block's template and a\n// recipe are each one string, so nothing exists for them to load.\nconst FILE_TAGS = new Set([\"include\", \"render\", \"layout\"]);\n\n// Static analysis follows include/render into the partial by default, which\n// the engine refuses to load, so every analysis call skips partials. The\n// file-tag rule reports those tags instead.\nexport const NO_PARTIALS = { partials: false } as const;\n\n/** A tag's child templates, from liquidjs's static-analysis generator. */\nfunction childTemplates(template: Template): Template[] {\n if (!template.children) return [];\n const gen = template.children(false, true);\n let step = gen.next();\n while (!step.done) step = gen.next();\n return step.value ?? [];\n}\n\n/** Every template in the tree, depth-first, nested tags included. */\nfunction allTemplates(templates: Template[]): Template[] {\n return templates.flatMap((t) => [t, ...allTemplates(childTemplates(t))]);\n}\n\n/** Every `for` tag in the tree, nested ones included. */\nfunction forTags(templates: Template[]): ForTag[] {\n return allTemplates(templates).filter(\n (t): t is ForTag => t instanceof ForTag,\n );\n}\n\n/** Names of the file-loading tags in the tree, each once, in source order. */\nexport function fileTags(templates: Template[]): string[] {\n const names = allTemplates(templates)\n .filter((t): t is Tag => t instanceof Tag && FILE_TAGS.has(t.name))\n .map((t) => t.name);\n return [...new Set(names)];\n}\n\n/** How many `{{ }}` outputs in the tree reach the text without a `json` filter. */\nexport function outputsWithoutJson(templates: Template[]): number {\n return allTemplates(templates).filter(\n (t) =>\n t instanceof Output && !t.value.filters.some((f) => f.name === \"json\"),\n ).length;\n}\n\n/** The message for a template or recipe that uses a file-loading tag. */\nexport function fileTagMessage(name: string, where: string): string {\n return `\\`{% ${name} %}\\` loads another template file, and ${where} has none to load. Write its content inline instead.`;\n}\n\n/**\n * The field a loop iterates, when its collection is a bare identifier.\n * `for x in a.b` iterates a property of `a`, not `a`, so it has none.\n */\nfunction bareCollection(tag: ForTag): string | null {\n const c = tag.collection as {\n variable?: unknown;\n props?: Array<{ content?: unknown }>;\n };\n if (c.variable !== undefined || c.props?.length !== 1) return null;\n const name = c.props[0].content;\n return typeof name === \"string\" ? name : null;\n}\n\nexport function checkLiquid(def: CustomBlockWorkingFile): CustomBlockIssue[] {\n const engine = createLiquid();\n let parsed: Template[];\n try {\n parsed = engine.parse(def.template);\n } catch (err) {\n return [\n {\n ruleId: \"liquid.parse\",\n severity: \"error\",\n path: \"/template\",\n message: `The template does not parse: ${(err as Error).message}`,\n },\n ];\n }\n\n const issues: CustomBlockIssue[] = fileTags(parsed).map((name) => ({\n ruleId: \"liquid.file-tag\",\n severity: \"error\",\n path: \"/template\",\n message: fileTagMessage(name, \"a custom block\"),\n }));\n const fields = new Map(\n def.fields.map((f, i) => [f.key, { field: f, index: i }]),\n );\n\n const globals = new Set(\n engine\n .globalVariableSegmentsSync(def.template, NO_PARTIALS)\n .map((segments) => String(segments[0]))\n .filter((name) => !LIQUID_GLOBALS.has(name)),\n );\n for (const name of globals) {\n if (!fields.has(name)) {\n issues.push({\n ruleId: \"liquid.undefined-variable\",\n severity: \"error\",\n path: \"/template\",\n message: `The template reads \\`${name}\\`, which no field defines.`,\n });\n }\n }\n // A field only the data-source recipe reads (the product id it fetches by)\n // is in use; recipe Liquid that fails to parse is reported by checkRecipe.\n const recipeReads = new Set<string>();\n const request = def.dataSourcePreview?.request;\n for (const text of [request?.url, request?.body]) {\n if (text === undefined) continue;\n try {\n for (const [name] of engine.globalVariableSegmentsSync(\n text,\n NO_PARTIALS,\n )) {\n recipeReads.add(String(name));\n }\n } catch {\n /* reported by checkRecipe */\n }\n }\n for (const [key, { index }] of fields) {\n if (!globals.has(key) && !recipeReads.has(key)) {\n issues.push({\n ruleId: \"liquid.unused-field\",\n severity: \"warning\",\n path: `/fields/${index}`,\n message: `Field \\`${key}\\` is never read by the template or the data-source recipe.`,\n });\n }\n }\n\n // Each loop's body is checked against that loop's own collection, so two\n // loops may reuse one local name over different repeatables.\n for (const loop of forTags(parsed)) {\n const local = loop.variable;\n const collection = bareCollection(loop);\n if (collection === null) continue;\n const target = fields.get(collection)?.field;\n if (!target) continue;\n if (target.type !== \"repeatable\") {\n issues.push({\n ruleId: \"liquid.loop-not-repeatable\",\n severity: \"error\",\n path: \"/template\",\n message: `\\`{% for ${local} in ${collection} %}\\` iterates \\`${collection}\\`, which is a ${target.type} field, not a repeatable.`,\n });\n continue;\n }\n for (const [head, sub] of engine.variableSegmentsSync(\n loop.templates,\n NO_PARTIALS,\n )) {\n if (String(head) !== local || typeof sub !== \"string\") continue;\n if (!target.fields.some((f) => f.key === sub)) {\n issues.push({\n ruleId: \"liquid.unknown-item-key\",\n severity: \"error\",\n path: \"/template\",\n message: `\\`${local}.${sub}\\` reads \\`${sub}\\`, which \\`${collection}\\`'s items don't define.`,\n });\n }\n }\n }\n return issues;\n}\n","// The preview-only data-source recipe. The live bridge runs it from Node so\n// the page never sees a secret and no CORS applies; the agent generates the\n// shipped onFetch from the same recipe, so preview and production agree.\n//\n// These rules keep secrets contained, and each is load-bearing:\n// - `${env:NAME}` resolves only in header values;\n// - field values interpolate only into `url` and `body`;\n// - the Liquid engine loads no files, so `{% include %}` can't put a local\n// file (`.env`) into the request;\n// - the URL's scheme and host are literal, every field value is URL-encoded\n// (non-scalars as JSON), and the rendered URL must keep the recipe's\n// origin, so no field value can send the headers to another host.\n// A field value can never pull an env var into the request, and a secret can\n// never be moved into the URL or off to a host the author didn't write.\n\nimport {\n createLiquid,\n fileTagMessage,\n fileTags,\n NO_PARTIALS,\n outputsWithoutJson,\n} from \"./liquid\";\nimport type {\n CustomBlockIssue,\n CustomBlockWorkingFile,\n DataSourcePreview,\n} from \"./types\";\n\nconst ENV_REF = /\\$\\{env:([A-Za-z_][A-Za-z0-9_]*)\\}/g;\nconst LIQUID = /\\{\\{|\\{%/;\nconst UNSAFE_KEYS = new Set([\"__proto__\", \"constructor\", \"prototype\"]);\n// A header-name word that names a credential. Whole words of the name split\n// on - and _, so X-Session-Locale and Accept-Keys don't match while X-API-Key,\n// X-Auth-Token and X-AccessToken do. `session` counts only before `id`.\nconst CREDENTIAL_WORD =\n /^(?:authorization|auth|cookie|key|apikey|password|credentials?|sessionid)$|(?:token|secret)$/;\n\nfunction namesCredential(header: string): boolean {\n const words = header.toLowerCase().split(/[-_]/);\n return words.some(\n (w, i) =>\n CREDENTIAL_WORD.test(w) || (w === \"session\" && words[i + 1] === \"id\"),\n );\n}\n\nconst HOST_TEMPLATE_ERROR =\n \"The request URL's scheme and host must be literal; Liquid may only follow the first `/` after the host.\";\n\n/**\n * Where the URL's scheme and authority end: the first `/`, `?` or `#` after\n * `://`, or the whole string when there is no `://`. Anything before this\n * index decides the origin, so it must hold no Liquid.\n */\nfunction authorityEnd(url: string): number {\n const scheme = url.indexOf(\"://\");\n if (scheme < 0) return url.length;\n const rest = url.slice(scheme + 3).search(/[/?#]/);\n return rest < 0 ? url.length : scheme + 3 + rest;\n}\n\n/** The recipe URL's origin, or null when Liquid can reach it. */\nfunction literalOrigin(url: string): string | null {\n const prefix = url.slice(0, authorityEnd(url));\n if (LIQUID.test(prefix)) return null;\n try {\n return new URL(prefix).origin;\n } catch {\n return null;\n }\n}\n\nfunction encodeValue(value: unknown): string {\n if (value === null || value === undefined) return \"\";\n if (typeof value === \"string\" || typeof value === \"number\") {\n return encodeURIComponent(String(value));\n }\n return encodeURIComponent(JSON.stringify(value));\n}\n\nexport function getPath(value: unknown, path: string): unknown {\n const parts = path\n .replace(/\\[(\\d+)\\]/g, \".$1\")\n .split(\".\")\n .filter(Boolean);\n let cur: unknown = value;\n for (const part of parts) {\n if (cur === null || typeof cur !== \"object\") return undefined;\n cur = (cur as Record<string, unknown>)[part];\n }\n return cur;\n}\n\nexport function checkRecipe(def: CustomBlockWorkingFile): CustomBlockIssue[] {\n const r = def.dataSourcePreview;\n if (!r) return [];\n const issues: CustomBlockIssue[] = [];\n const keys = new Set(def.fields.map((f) => f.key));\n const add =\n (severity: CustomBlockIssue[\"severity\"]) =>\n (ruleId: string, path: string, message: string) =>\n issues.push({\n ruleId,\n severity,\n path: `/dataSourcePreview${path}`,\n message,\n });\n const err = add(\"error\");\n const warn = add(\"warning\");\n const engine = createLiquid();\n\n for (const [part, text] of [\n [\"/request/url\", r.request.url],\n [\"/request/body\", r.request.body],\n ] as const) {\n if (text === undefined) continue;\n if (new RegExp(ENV_REF.source).test(text)) {\n err(\n \"recipe.env-outside-headers\",\n part,\n \"`${env:…}` is resolved only in header values; keep secrets out of the URL and body.\",\n );\n }\n try {\n for (const [name] of engine.globalVariableSegmentsSync(\n text,\n NO_PARTIALS,\n )) {\n if (!keys.has(String(name)))\n err(\n \"recipe.undefined-variable\",\n part,\n `The recipe reads \\`${String(name)}\\`, which no field defines.`,\n );\n }\n // The engine can't read files, so such a recipe would fail at fetch\n // time; refusing it here keeps the bridge from running it at all.\n const parsed = engine.parse(text);\n for (const name of fileTags(parsed)) {\n err(\"recipe.file-tag\", part, fileTagMessage(name, \"a recipe\"));\n }\n // Body values go in raw, so a quote typed into a field ends the string\n // early. `| json` quotes and escapes the value.\n if (\n part === \"/request/body\" &&\n /^\\s*[[{]/.test(text) &&\n outputsWithoutJson(parsed) > 0\n ) {\n warn(\n \"recipe.body-unescaped\",\n part,\n \"A JSON body interpolates a value without `| json`, so a quote in it breaks the JSON. Write `{{ key | json }}`, which adds the quotes.\",\n );\n }\n } catch (e) {\n err(\n \"recipe.undefined-variable\",\n part,\n `Does not parse: ${(e as Error).message}`,\n );\n }\n }\n // Without `://` the URL is not absolute, which recipe.url below reports.\n if (\n r.request.url.includes(\"://\") &&\n LIQUID.test(r.request.url.slice(0, authorityEnd(r.request.url)))\n ) {\n err(\"recipe.url-host-template\", \"/request/url\", HOST_TEMPLATE_ERROR);\n }\n const probeUrl = replaceLiquid(r.request.url);\n let parses = true;\n try {\n new URL(probeUrl);\n } catch {\n parses = false;\n }\n if (!/^https?:\\/\\//i.test(probeUrl) || !parses) {\n err(\n \"recipe.url\",\n \"/request/url\",\n \"The request URL must be an absolute http(s) URL.\",\n );\n }\n if (r.request.body !== undefined && (r.request.method ?? \"GET\") !== \"POST\") {\n err(\n \"recipe.body-without-post\",\n \"/request/body\",\n 'A `body` is sent only with `\"method\": \"POST\"`; a GET request can\\'t carry one.',\n );\n }\n for (const [name, value] of Object.entries(r.request.headers ?? {})) {\n if (LIQUID.test(value)) {\n err(\n \"recipe.field-in-header\",\n `/request/headers/${name}`,\n `Header \\`${name}\\` interpolates a field; headers take only \\`\\${env:NAME}\\`.`,\n );\n } else if (\n namesCredential(name) &&\n !new RegExp(ENV_REF.source).test(value)\n ) {\n err(\n \"recipe.literal-secret\",\n `/request/headers/${name}`,\n `Header \\`${name}\\` holds a literal credential. Use \\`\\${env:NAME}\\` and export the variable instead.`,\n );\n }\n }\n for (const field of Object.keys(r.map)) {\n if (!keys.has(field))\n err(\n \"recipe.unknown-map-key\",\n `/map/${field}`,\n `\\`map\\` writes \\`${field}\\`, which no field defines.`,\n );\n }\n return issues;\n}\n\nexport interface RecipeOptions {\n env?: Record<string, string | undefined>;\n fetch?: typeof fetch;\n timeoutMs?: number;\n}\nexport type RecipeResult =\n | {\n ok: true;\n status: number;\n values: Record<string, unknown>;\n unmapped: string[];\n }\n | { ok: false; status?: number; error: string };\n\nexport async function runRecipe(\n recipe: DataSourcePreview,\n fieldValues: Record<string, unknown>,\n {\n env = process.env,\n fetch: doFetch = fetch,\n timeoutMs = 10_000,\n }: RecipeOptions = {},\n): Promise<RecipeResult> {\n const expectedOrigin = literalOrigin(recipe.request.url);\n if (expectedOrigin === null) return { ok: false, error: HOST_TEMPLATE_ERROR };\n const engine = createLiquid();\n const encoded = Object.fromEntries(\n Object.entries(fieldValues).map(([k, v]) => [k, encodeValue(v)]),\n );\n let url: string;\n let body: string | undefined;\n try {\n url = String(await engine.parseAndRender(recipe.request.url, encoded));\n body =\n recipe.request.body === undefined\n ? undefined\n : String(await engine.parseAndRender(recipe.request.body, fieldValues));\n } catch (e) {\n return {\n ok: false,\n error: `The request template does not render: ${(e as Error).message}`,\n };\n }\n\n let renderedOrigin: string | null = null;\n try {\n renderedOrigin = new URL(url).origin;\n } catch {\n /* reported below */\n }\n // Unreachable while the URL authority refuses Liquid and every value is\n // encoded; it stops the proxy being repointed if either guard regresses.\n /* v8 ignore start */\n if (renderedOrigin !== expectedOrigin) {\n return {\n ok: false,\n error: `The rendered URL's origin (${renderedOrigin ?? \"unparseable\"}) differs from the recipe's (${expectedOrigin}); no request was made.`,\n };\n }\n /* v8 ignore stop */\n\n const secrets: string[] = [];\n const headers: Record<string, string> = {};\n for (const [name, template] of Object.entries(recipe.request.headers ?? {})) {\n let missing: string | undefined;\n headers[name] = template.replace(ENV_REF, (_, variable: string) => {\n const value = env[variable];\n if (value === undefined || value === \"\") {\n missing ??= variable;\n return \"\";\n }\n secrets.push(value);\n return value;\n });\n if (missing) {\n return {\n ok: false,\n error: `Environment variable ${missing} is not set. Export it in the shell that runs the live server.`,\n };\n }\n }\n const redact = (s: string) =>\n secrets.reduce((acc, secret) => acc.split(secret).join(\"***\"), s);\n const redactDeep = (v: unknown): unknown => {\n if (typeof v === \"string\") return redact(v);\n if (Array.isArray(v)) return v.map(redactDeep);\n if (v !== null && typeof v === \"object\") {\n return Object.fromEntries(\n Object.entries(v).map(([k, x]) => [k, redactDeep(x)]),\n );\n }\n return v;\n };\n const method = recipe.request.method ?? \"GET\";\n\n try {\n const res = await doFetch(url, {\n method,\n headers,\n body,\n redirect: \"manual\",\n signal: AbortSignal.timeout(timeoutMs),\n });\n if (res.status >= 300 && res.status < 400) {\n const location = res.headers.get(\"location\") ?? \"(none)\";\n return {\n ok: false,\n status: res.status,\n error: redact(\n `${method} ${url} redirected (${res.status}) to ${location}. Redirects are not followed; point the recipe at the final URL.`,\n ),\n };\n }\n const text = await res.text();\n if (!res.ok) {\n return {\n ok: false,\n status: res.status,\n error: `${redact(`${method} ${url} returned ${res.status}: `)}${redact(text).slice(0, 200)}`,\n };\n }\n let json: unknown;\n try {\n json = JSON.parse(text);\n } catch {\n return {\n ok: false,\n status: res.status,\n error: redact(`${method} ${url} did not return JSON.`),\n };\n }\n const values: Record<string, unknown> = {};\n const unmapped: string[] = [];\n for (const [field, path] of Object.entries(recipe.map)) {\n if (UNSAFE_KEYS.has(field)) continue;\n const v = getPath(json, path);\n if (v === undefined) unmapped.push(field);\n else values[field] = redactDeep(v);\n }\n return { ok: true, status: res.status, values, unmapped };\n } catch (e) {\n return {\n ok: false,\n error: redact(`${method} ${url} failed: ${(e as Error).message}`),\n };\n }\n}\n\n/** Replaces each `{{…}}` / `{%…%}` span with \"x\" in one linear pass; an unterminated opener swallows the rest. */\nexport function replaceLiquid(text: string): string {\n const MISSING = Infinity;\n const next = (needle: string, from: number) => {\n const at = text.indexOf(needle, from);\n return at === -1 ? MISSING : at;\n };\n let out = \"\";\n let i = 0;\n // Each opener is searched for again only once the cursor passes its cached\n // position, so an opener that never recurs is scanned for once, not per span.\n let a = next(\"{{\", 0);\n let b = next(\"{%\", 0);\n for (;;) {\n if (a < i) a = next(\"{{\", i);\n if (b < i) b = next(\"{%\", i);\n const open = Math.min(a, b);\n if (open === MISSING) return out + text.slice(i);\n out += text.slice(i, open);\n const close = text.indexOf(open === a ? \"}}\" : \"%}\", open + 2);\n if (close === -1) return out + \"x\";\n out += \"x\";\n i = close + 2;\n }\n}\n","// The specimen sheet: one instance of the block per state that commonly\n// breaks a custom block — defaults, every optional cleared, long copy,\n// repeatables at their bounds, booleans inverted — so the live preview shows\n// the edge cases without the user thinking to try them.\n\nimport { escapeHtml } from \"@templatical/renderer\";\nimport {\n createCustomBlock,\n createDefaultTemplateContent,\n createParagraphBlock,\n type Block,\n type CustomBlockDefinition,\n type CustomBlockField,\n type TemplateContent,\n} from \"@templatical/types\";\nimport type { CustomBlockWorkingFile } from \"./types\";\n\nexport type SpecimenState =\n \"defaults\" | \"empty\" | \"long\" | \"min-items\" | \"max-items\" | \"flipped\";\nexport const SPECIMEN_STATES: readonly SpecimenState[] = [\n \"defaults\",\n \"empty\",\n \"long\",\n \"min-items\",\n \"max-items\",\n \"flipped\",\n];\nexport interface SpecimenInstance {\n state: SpecimenState;\n fieldValues: Record<string, unknown>;\n}\nexport const DEFAULT_MAX_ITEMS = 6;\n\ntype ItemField = Exclude<CustomBlockField, { type: \"repeatable\" }>;\ntype Repeatable = Extract<CustomBlockField, { type: \"repeatable\" }>;\n\n// Same fallbacks as @templatical/types' createCustomBlock, which keeps its own\n// copy private; the \"defaults\" test holds the two equal.\nfunction fieldDefault(f: CustomBlockField): unknown {\n if (f.default !== undefined) return structuredClone(f.default);\n if (f.type === \"repeatable\") return [];\n if (f.type === \"boolean\") return false;\n if (f.type === \"number\") return 0;\n return \"\";\n}\n\nfunction itemFrom(fields: ItemField[]): Record<string, unknown> {\n return Object.fromEntries(fields.map((f) => [f.key, fieldDefault(f)]));\n}\n\nfunction items(f: Repeatable, n: number): Record<string, unknown>[] {\n const seeds =\n Array.isArray(f.default) && f.default.length > 0\n ? f.default\n : [itemFrom(f.fields)];\n return Array.from({ length: n }, (_, i) =>\n structuredClone(seeds[i % seeds.length]),\n );\n}\n\nfunction lengthen(f: CustomBlockField, v: unknown): unknown {\n if (f.type === \"text\" || f.type === \"textarea\") {\n const base = (typeof v === \"string\" && v) || f.placeholder || f.label;\n return [base, base, base].join(\" \");\n }\n if (f.type === \"number\") return f.max ?? v;\n if (f.type === \"repeatable\" && Array.isArray(v)) {\n return v.map((item: Record<string, unknown>) =>\n Object.fromEntries(\n f.fields.map((s) => [s.key, lengthen(s, item[s.key])]),\n ),\n );\n }\n return v;\n}\n\nfunction clear(f: CustomBlockField, v: unknown): unknown {\n if (f.required) return v;\n if (f.type === \"boolean\") return false;\n if (f.type === \"number\") return null;\n if (f.type === \"repeatable\") return items(f, f.minItems ?? 0);\n return \"\";\n}\n\nexport function buildSpecimen(def: CustomBlockWorkingFile): SpecimenInstance[] {\n const defaults = createCustomBlock(def as CustomBlockDefinition).fieldValues;\n const map = (fn: (f: CustomBlockField, v: unknown) => unknown) =>\n Object.fromEntries(\n def.fields.map((f) => [f.key, fn(f, structuredClone(defaults[f.key]))]),\n );\n\n const out: SpecimenInstance[] = [\n { state: \"defaults\", fieldValues: structuredClone(defaults) },\n { state: \"empty\", fieldValues: map(clear) },\n { state: \"long\", fieldValues: map(lengthen) },\n ];\n const repeatables = def.fields.filter(\n (f): f is Repeatable => f.type === \"repeatable\",\n );\n if (repeatables.length > 0) {\n const sized = (pick: (f: Repeatable) => number) => ({\n ...structuredClone(defaults),\n ...Object.fromEntries(repeatables.map((f) => [f.key, items(f, pick(f))])),\n });\n out.push({\n state: \"min-items\",\n fieldValues: sized((f) => f.minItems ?? 0),\n });\n // Never below minItems: without a maxItems, the fallback can sit under\n // the minimum, and the editor never lets a list get that short.\n out.push({\n state: \"max-items\",\n fieldValues: sized((f) =>\n Math.max(f.minItems ?? 0, f.maxItems ?? DEFAULT_MAX_ITEMS),\n ),\n });\n }\n const booleans = def.fields.filter((f) => f.type === \"boolean\");\n if (booleans.length > 0) {\n out.push({\n state: \"flipped\",\n fieldValues: {\n ...structuredClone(defaults),\n ...Object.fromEntries(booleans.map((f) => [f.key, !defaults[f.key]])),\n },\n });\n }\n return out;\n}\n\n/** What running the data-source recipe for the live preview produced. */\nexport type FetchedSpecimen =\n | { ok: true; fieldValues: Record<string, unknown> }\n | { ok: false; error: string };\n\n/**\n * The live preview's \"fetched\" state: the block filled from the real\n * endpoint and marked fetched, so read-only fields lock as they do in\n * production. A failed request puts its error on the label instead.\n */\nexport function fetchedSpecimenBlocks(\n def: CustomBlockWorkingFile,\n fetched: FetchedSpecimen,\n): Block[] {\n const id = \"specimen-fetched\";\n if (!fetched.ok) {\n return [\n createParagraphBlock({\n id: `${id}-label`,\n content: `<p><strong>Specimen:</strong> fetched. The request failed: ${escapeHtml(fetched.error)}</p>`,\n }),\n ];\n }\n return [\n createParagraphBlock({\n id: `${id}-label`,\n content: \"<p><strong>Specimen:</strong> fetched</p>\",\n }),\n {\n ...createCustomBlock(def as CustomBlockDefinition),\n id,\n fieldValues: fetched.fieldValues,\n dataSourceFetched: true,\n },\n ];\n}\n\n/** The id each state's custom block gets in the specimen sheet; its label is `${id}-label`. */\nexport function specimenBlockId(state: SpecimenState): string {\n return `specimen-${state}`;\n}\n\nexport function buildSpecimenTemplate(\n def: CustomBlockWorkingFile,\n host?: TemplateContent,\n only?: SpecimenState,\n): TemplateContent {\n const content = host ? structuredClone(host) : createDefaultTemplateContent();\n for (const instance of buildSpecimen(def)) {\n if (only && instance.state !== only) continue;\n // Fixed ids, not fresh ones: the sheet is rebuilt on every reload and\n // page load, and a note left on a block keys on its id. A random id\n // would orphan every note at the next reload.\n const id = specimenBlockId(instance.state);\n content.blocks.push(\n createParagraphBlock({\n id: `${id}-label`,\n content: `<p><strong>Specimen:</strong> ${instance.state}</p>`,\n }),\n {\n ...createCustomBlock(def as CustomBlockDefinition),\n id,\n fieldValues: instance.fieldValues,\n },\n );\n }\n return content;\n}\n","// Renders a custom block the way the editor and the renderer do: Liquid over\n// fieldValues for the HTML, then renderToMjml with that HTML and the\n// definition's stylesheet, which the renderer emits once into <mj-head>.\n\nimport { renderToMjml } from \"@templatical/renderer\";\nimport type { TemplateContent } from \"@templatical/types\";\nimport { createLiquid } from \"./liquid\";\nimport {\n buildSpecimen,\n buildSpecimenTemplate,\n type SpecimenInstance,\n type SpecimenState,\n} from \"./specimen\";\nimport type { CustomBlockWorkingFile } from \"./types\";\n\nexport interface RenderedState {\n state: SpecimenState;\n html: string;\n}\n\nexport async function renderStates(\n def: CustomBlockWorkingFile,\n instances: SpecimenInstance[] = buildSpecimen(def),\n): Promise<RenderedState[]> {\n const liquid = createLiquid();\n return Promise.all(\n instances.map(async (i) => ({\n state: i.state,\n html: String(await liquid.parseAndRender(def.template, i.fieldValues)),\n })),\n );\n}\n\nexport async function renderSpecimenMjml(\n def: CustomBlockWorkingFile,\n template: TemplateContent = buildSpecimenTemplate(def),\n): Promise<string> {\n const liquid = createLiquid();\n return renderToMjml(template, {\n renderCustomBlock: async (block) =>\n String(await liquid.parseAndRender(def.template, block.fieldValues)),\n getCustomBlockStylesheet: (customType) =>\n customType === def.type ? def.stylesheet : undefined,\n });\n}\n","// The full `custom-block validate` pipeline, as a library function. Stages\n// short-circuit where a later stage would only report noise: no Liquid or\n// render checks on a structurally broken definition, no render on a template\n// that doesn't parse or loads another file, and no lint on one that fails to\n// render.\n\nimport { checkAccessibility } from \"./a11y\";\nimport { validateCustomBlockDefinition } from \"./definition\";\nimport { checkLiquid } from \"./liquid\";\nimport { checkRecipe } from \"./recipe\";\nimport { renderSpecimenMjml, renderStates, type RenderedState } from \"./render\";\nimport { checkEmailSafety } from \"./safety\";\nimport type {\n CustomBlockCheckResult,\n CustomBlockIssue,\n CustomBlockWorkingFile,\n} from \"./types\";\n\nexport interface CheckCustomBlockOptions {\n compileMjml?: (mjml: string) => Promise<{ errors: unknown[] }>;\n}\n\nconst finish = (issues: CustomBlockIssue[]): CustomBlockCheckResult => ({\n valid: !issues.some((i) => i.severity === \"error\"),\n issues,\n});\n\nexport async function checkCustomBlock(\n data: unknown,\n { compileMjml }: CheckCustomBlockOptions = {},\n): Promise<CustomBlockCheckResult> {\n const structural = validateCustomBlockDefinition(data);\n if (!structural.valid) return structural;\n const def = data as CustomBlockWorkingFile;\n\n const issues = [...structural.issues, ...checkRecipe(def)];\n const liquid = checkLiquid(def);\n issues.push(...liquid);\n if (\n liquid.some(\n (i) => i.ruleId === \"liquid.parse\" || i.ruleId === \"liquid.file-tag\",\n )\n )\n return finish(issues);\n\n // A template can parse and still throw while rendering; that is a finding\n // about the definition, not a crash of the check.\n let rendered: RenderedState[];\n try {\n rendered = await renderStates(def);\n } catch (err) {\n issues.push({\n ruleId: \"liquid.render\",\n severity: \"error\",\n path: \"/template\",\n message: `The template does not render: ${(err as Error).message}`,\n });\n return finish(issues);\n }\n issues.push(...checkEmailSafety(def, rendered));\n issues.push(...checkAccessibility(rendered));\n const mjml = await renderSpecimenMjml(def);\n // The renderer trims the stylesheet before emitting it.\n const stylesheet = def.stylesheet?.trim();\n if (stylesheet && !mjml.includes(stylesheet)) {\n issues.push({\n ruleId: \"render.stylesheet-missing\",\n severity: \"error\",\n message: \"The stylesheet did not reach <mj-head> in the rendered MJML.\",\n });\n }\n if (compileMjml) {\n for (const e of (await compileMjml(mjml)).errors) {\n const o = e as { formattedMessage?: string; message?: string };\n issues.push({\n ruleId: \"render.mjml\",\n severity: \"warning\",\n message: o.formattedMessage ?? o.message ?? String(e),\n });\n }\n }\n return finish(issues);\n}\n"],"mappings":";;;;;;;;;ACyBA,MAAa,SAASA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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kB,EAAE,WAAW,iBACrD,GAEA,OAAO,OAAO,MAAM;CAItB,IAAI;CACJ,IAAI;EACF,WAAW,MAAM,aAAa,GAAG;CACnC,SAAS,KAAK;EACZ,OAAO,KAAK;GACV,QAAQ;GACR,UAAU;GACV,MAAM;GACN,SAAS,iCAAkC,IAAc;EAC3D,CAAC;EACD,OAAO,OAAO,MAAM;CACtB;CACA,OAAO,KAAK,GAAG,iBAAiB,KAAK,QAAQ,CAAC;CAC9C,OAAO,KAAK,GAAG,mBAAmB,QAAQ,CAAC;CAC3C,MAAM,OAAO,MAAM,mBAAmB,GAAG;CAEzC,MAAM,aAAa,IAAI,YAAY,KAAK;CACxC,IAAI,cAAc,CAAC,KAAK,SAAS,UAAU,GACzC,OAAO,KAAK;EACV,QAAQ;EACR,UAAU;EACV,SAAS;CACX,CAAC;CAEH,IAAI,aACF,KAAK,MAAM,MAAM,MAAM,YAAY,IAAI,EAAA,CAAG,QAAQ;EAChD,MAAM,IAAI;EACV,OAAO,KAAK;GACV,QAAQ;GACR,UAAU;GACV,SAAS,EAAE,oBAAoB,EAAE,WAAW,OAAO,CAAC;EACtD,CAAC;CACH;CAEF,OAAO,OAAO,MAAM;AACtB"}
package/dist/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import { LintIssue } from "@templatical/quality";
2
- import { ColumnLayout, TemplateContent, TemplateOperationPayload } from "@templatical/types";
2
+ import { ColumnLayout, CustomBlockDefinition, TemplateContent, TemplateOperationPayload } from "@templatical/types";
3
+ import { Liquid } from "liquidjs";
3
4
  //#region src/validate.d.ts
4
5
  interface SchemaDefinition {
5
6
  properties?: {
@@ -50,5 +51,51 @@ interface OperationResult {
50
51
  /** Apply one operation, returning a new document. Never mutates the input. */
51
52
  export declare function applyOperation(content: TemplateContent, payload: TemplateOperationPayload): OperationResult;
52
53
  //#endregion
53
- export type { OperationResult, QualityLintResult, ValidationResult };
54
+ //#region src/custom-block/types.d.ts
55
+ type CustomBlockIssueSeverity = "error" | "warning";
56
+ interface CustomBlockIssue {
57
+ ruleId: string;
58
+ severity: CustomBlockIssueSeverity;
59
+ message: string;
60
+ /** JSON-pointer-ish location, e.g. "/fields/2/default". Absent for whole-definition issues. */
61
+ path?: string;
62
+ }
63
+ interface DataSourcePreview {
64
+ label: string;
65
+ request: {
66
+ method?: "GET" | "POST";
67
+ /** Liquid over the block's fieldValues; values are URL-encoded. */
68
+ url: string;
69
+ /** Values may hold `${env:NAME}`; never `{{ }}`. */
70
+ headers?: Record<string, string>;
71
+ /** Liquid over the block's fieldValues, raw. */
72
+ body?: string;
73
+ };
74
+ /** Field key → dot/index path into the JSON response ("images[0].url"). */
75
+ map: Record<string, string>;
76
+ }
77
+ type CustomBlockWorkingFile = Omit<CustomBlockDefinition, "dataSource"> & {
78
+ dataSourcePreview?: DataSourcePreview;
79
+ };
80
+ interface CustomBlockCheckResult {
81
+ valid: boolean;
82
+ issues: CustomBlockIssue[];
83
+ }
84
+ //#endregion
85
+ //#region src/custom-block/check.d.ts
86
+ interface CheckCustomBlockOptions {
87
+ compileMjml?: (mjml: string) => Promise<{
88
+ errors: unknown[];
89
+ }>;
90
+ }
91
+ export declare function checkCustomBlock(data: unknown, { compileMjml }?: CheckCustomBlockOptions): Promise<CustomBlockCheckResult>;
92
+ //#endregion
93
+ //#region src/custom-block/definition.d.ts
94
+ export declare function validateCustomBlockDefinition(data: unknown): CustomBlockCheckResult;
95
+ //#endregion
96
+ //#region src/custom-block/specimen.d.ts
97
+ type SpecimenState = "defaults" | "empty" | "long" | "min-items" | "max-items" | "flipped";
98
+ export declare const SPECIMEN_STATES: readonly SpecimenState[];
99
+ //#endregion
100
+ export type { CheckCustomBlockOptions, CustomBlockCheckResult, CustomBlockIssue, CustomBlockIssueSeverity, CustomBlockWorkingFile, DataSourcePreview, OperationResult, QualityLintResult, SpecimenState, ValidationResult };
54
101
  //# sourceMappingURL=index.d.ts.map
package/dist/index.js CHANGED
@@ -1 +1,3 @@
1
- export { t as applyOperation, n as getColumnCount, r as runQualityLint, i as schema, a as validateTemplate } from "./src-De5svMDM.js";
1
+ import { d as schema, f as validateTemplate, l as validateCustomBlockDefinition, r as SPECIMEN_STATES, t as checkCustomBlock, u as runQualityLint } from "./custom-block-sAM61QPU.js";
2
+ import { n as getColumnCount, t as applyOperation } from "./src-Ce1Oh8m_.js";
3
+ export { SPECIMEN_STATES, applyOperation, checkCustomBlock, getColumnCount, runQualityLint, schema, validateCustomBlockDefinition, validateTemplate };
@@ -1,6 +1,6 @@
1
1
  import { Server } from "node:http";
2
2
  //#region src/live/index.d.ts
3
- export declare const EDITOR_VERSION = "0.46.0";
3
+ export declare const EDITOR_VERSION = "0.47.0";
4
4
  export declare const DEFAULT_PORT = 4747;
5
5
  export declare const WORKING_DIR = ".templatical";
6
6
  export declare const PID_FILE: string;
@@ -16,9 +16,36 @@ export declare function listWorkingFiles(cwd: string): string[];
16
16
  * always surface the URL too, so nothing is lost when this does nothing.
17
17
  */
18
18
  export declare function openBrowser(url: string): void;
19
+ export type LiveMode = "template" | "custom-block";
19
20
  export interface PidfileInfo {
20
21
  pid: number;
21
22
  port: number;
23
+ /** Absent in a pidfile from a template-only bridge; read as "template". */
24
+ mode?: LiveMode;
25
+ /** The absolute path the server is serving. */
26
+ path?: string;
27
+ /** Custom-block mode: the absolute --host template, when one was given. */
28
+ host?: string;
29
+ /** Custom-block mode with --fetch: the --values the recipe runs with. */
30
+ fetch?: Record<string, unknown>;
31
+ }
32
+ /** How the data-source request for the fetched specimen state went. */
33
+ export type FetchSummary = {
34
+ ok: true;
35
+ unmapped: string[];
36
+ } | {
37
+ ok: false;
38
+ error: string;
39
+ };
40
+ /** What a reload pushed, and why it pushed nothing when `ok` is false. */
41
+ export interface ReloadResult {
42
+ ok: boolean;
43
+ clients: number;
44
+ consumed: boolean;
45
+ mode: LiveMode;
46
+ error?: string;
47
+ /** With the `fetch` option: the request behind the fetched state. */
48
+ fetch?: FetchSummary;
22
49
  }
23
50
  export declare function pidfilePath(cwd: string): string;
24
51
  export declare function readPidfile(cwd: string): PidfileInfo | null;
@@ -55,11 +82,9 @@ export interface BridgeHandle {
55
82
  /** Re-read the working file and push it to every connected page. */
56
83
  reload: (options?: {
57
84
  consumeAnnotations?: boolean;
58
- }) => {
59
- ok: boolean;
60
- clients: number;
61
- consumed: boolean;
62
- };
85
+ }) => ReloadResult;
86
+ /** With the `fetch` option: the last data-source request's outcome. */
87
+ lastFetch: () => FetchSummary | null;
63
88
  close: () => Promise<void>;
64
89
  }
65
90
  export interface StartBridgeOptions {
@@ -67,6 +92,22 @@ export interface StartBridgeOptions {
67
92
  port?: number;
68
93
  file?: string;
69
94
  harnessFile?: string;
95
+ /** Custom-block mode: serve this definition's specimen instead of a template. */
96
+ customBlock?: string;
97
+ /** Custom-block mode only: a template the specimen is appended to. */
98
+ host?: string;
99
+ /** Environment the data-source recipe resolves `${env:…}` from. Defaults to process.env. */
100
+ env?: Record<string, string | undefined>;
101
+ /**
102
+ * Custom-block mode only: run the `dataSourcePreview` recipe and add a
103
+ * "fetched" state, filled from the real endpoint, to the specimen. `values`
104
+ * override the field defaults for the request (the id it fetches by). It
105
+ * runs before the bridge starts listening and again on every `POST
106
+ * /reload`; the in-process `reload()` reuses the last result.
107
+ */
108
+ fetch?: {
109
+ values: Record<string, unknown>;
110
+ };
70
111
  }
71
112
  /**
72
113
  * Start the bridge HTTP server. Pure server + in-memory sync state; callers own
@@ -77,7 +118,7 @@ export interface StartBridgeOptions {
77
118
  * own bridge — that is the whole reason live mode can work inside a sandboxed
78
119
  * agent. The equivalent HTTP endpoints stay for the skill's out-of-process CLI.
79
120
  */
80
- export declare function startBridge({ cwd, port, file, harnessFile }?: StartBridgeOptions): Promise<BridgeHandle>;
121
+ export declare function startBridge({ cwd, port, file, harnessFile, customBlock, host, env, fetch: fetchOption }?: StartBridgeOptions): Promise<BridgeHandle>;
81
122
  export interface PreferringHandle extends BridgeHandle {
82
123
  fellBack: boolean;
83
124
  preferredPort?: number;