@weatherboard/cms 0.0.0-stage → 0.2.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.
- package/README.md +70 -2
- package/dist/adapters/next/reader.d.cts +2 -0
- package/dist/adapters/next/reader.d.mts +2 -0
- package/dist/adapters/next/reader.d.ts +2 -0
- package/dist/adapters/sanity/adapter.d.cts +15 -0
- package/dist/adapters/sanity/adapter.d.mts +15 -0
- package/dist/adapters/sanity/adapter.d.ts +15 -0
- package/dist/contracts/query.d.cts +20 -0
- package/dist/contracts/query.d.mts +20 -0
- package/dist/contracts/query.d.ts +20 -0
- package/dist/contracts/text.d.cts +65 -0
- package/dist/contracts/text.d.mts +65 -0
- package/dist/contracts/text.d.ts +65 -0
- package/dist/guard.cjs +3 -0
- package/dist/guard.cjs.map +7 -0
- package/dist/guard.d.cts +2 -0
- package/dist/guard.d.mts +2 -0
- package/dist/guard.d.ts +2 -0
- package/dist/guard.mjs +3 -0
- package/dist/guard.mjs.map +7 -0
- package/dist/index.cjs +2 -0
- package/dist/index.cjs.map +7 -0
- package/dist/index.d.cts +4 -0
- package/dist/index.d.mts +4 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.mjs +2 -0
- package/dist/index.mjs.map +7 -0
- package/dist/invalidation/route.d.cts +12 -0
- package/dist/invalidation/route.d.mts +12 -0
- package/dist/invalidation/route.d.ts +12 -0
- package/dist/next.cjs +2 -0
- package/dist/next.cjs.map +7 -0
- package/dist/next.d.cts +4 -0
- package/dist/next.d.mts +4 -0
- package/dist/next.d.ts +4 -0
- package/dist/next.mjs +2 -0
- package/dist/next.mjs.map +7 -0
- package/dist/portable/array.d.cts +2 -0
- package/dist/portable/array.d.mts +2 -0
- package/dist/portable/array.d.ts +2 -0
- package/dist/portable/fallback.d.cts +4 -0
- package/dist/portable/fallback.d.mts +4 -0
- package/dist/portable/fallback.d.ts +4 -0
- package/dist/portable/site-content.d.cts +220 -0
- package/dist/portable/site-content.d.mts +220 -0
- package/dist/portable/site-content.d.ts +220 -0
- package/dist/portable/webhook.d.cts +133 -0
- package/dist/portable/webhook.d.mts +133 -0
- package/dist/portable/webhook.d.ts +133 -0
- package/dist/runtime/reader.d.cts +51 -0
- package/dist/runtime/reader.d.mts +51 -0
- package/dist/runtime/reader.d.ts +51 -0
- package/dist/sanity.cjs +2 -0
- package/dist/sanity.cjs.map +7 -0
- package/dist/sanity.d.cts +3 -0
- package/dist/sanity.d.mts +3 -0
- package/dist/sanity.d.ts +3 -0
- package/dist/sanity.mjs +2 -0
- package/dist/sanity.mjs.map +7 -0
- package/dist/server.cjs +2 -0
- package/dist/server.cjs.map +7 -0
- package/dist/server.d.cts +3 -0
- package/dist/server.d.mts +3 -0
- package/dist/server.d.ts +3 -0
- package/dist/server.mjs +2 -0
- package/dist/server.mjs.map +7 -0
- package/dist/site-content.cjs +7 -0
- package/dist/site-content.cjs.map +7 -0
- package/dist/site-content.d.cts +4 -0
- package/dist/site-content.d.mts +4 -0
- package/dist/site-content.d.ts +4 -0
- package/dist/site-content.mjs +7 -0
- package/dist/site-content.mjs.map +7 -0
- package/dist/testing.cjs +2 -0
- package/dist/testing.cjs.map +7 -0
- package/dist/testing.d.cts +2 -0
- package/dist/testing.d.mts +2 -0
- package/dist/testing.d.ts +2 -0
- package/dist/testing.mjs +2 -0
- package/dist/testing.mjs.map +7 -0
- package/dist/tooling/guard.d.cts +13 -0
- package/dist/tooling/guard.d.mts +13 -0
- package/dist/tooling/guard.d.ts +13 -0
- package/dist/tooling/test-fixtures/break-proof.d.cts +1 -0
- package/dist/tooling/test-fixtures/break-proof.d.mts +1 -0
- package/dist/tooling/test-fixtures/break-proof.d.ts +1 -0
- package/dist/tooling/test-fixtures/consumer.d.cts +9 -0
- package/dist/tooling/test-fixtures/consumer.d.mts +9 -0
- package/dist/tooling/test-fixtures/consumer.d.ts +9 -0
- package/dist/tooling/testing.d.cts +10 -0
- package/dist/tooling/testing.d.mts +10 -0
- package/dist/tooling/testing.d.ts +10 -0
- package/dist/webhook.cjs +2 -0
- package/dist/webhook.cjs.map +7 -0
- package/dist/webhook.d.cts +2 -0
- package/dist/webhook.d.mts +2 -0
- package/dist/webhook.d.ts +2 -0
- package/dist/webhook.mjs +2 -0
- package/dist/webhook.mjs.map +7 -0
- package/package.json +142 -3
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/portable/array.ts", "../src/contracts/query.ts", "../src/portable/fallback.ts", "../src/portable/site-content.ts", "../src/contracts/text.ts"],
|
|
4
|
+
"sourcesContent": ["/** Content lists must contain an own entry at every index. */\nexport function isDenseArray(value: unknown): value is unknown[] {\n if (!Array.isArray(value)) return false;\n for (let index = 0; index < value.length; index += 1) {\n if (!Object.hasOwn(value, index)) return false;\n }\n return true;\n}\n", "/** A-1822 S1 owns this implementation. S0 registers the public signatures. */\nexport type CmsParams = Readonly<Record<string, string | number | boolean | null>>;\nexport type CmsDependencies = {\n readonly types: readonly string[];\n readonly ids?: readonly string[];\n};\nexport type CmsResolution<T> = {\n readonly data: T;\n readonly fallbackFields: readonly string[];\n readonly warnings?: readonly \"siteHero.layout.defaulted\"[];\n};\nexport type CmsQuery<T> = {\n readonly name: string;\n readonly query: string;\n readonly params: CmsParams;\n readonly dependencies: CmsDependencies;\n readonly resolve: (raw: unknown, fallback: T) => CmsResolution<T>;\n};\n\nconst TYPE = /^[A-Za-z][A-Za-z0-9_]{0,63}$/;\nconst ID = /^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/;\nconst SCOPE = /^[a-z0-9]{6,12}\\.[a-z][a-z0-9_-]{0,63}$/;\n\nfunction dependenciesCopy(dependencies: CmsDependencies): CmsDependencies {\n if (!dependencies || !Array.isArray(dependencies.types) || dependencies.types.length === 0) {\n throw new TypeError(\"CMS dependencies require document types\");\n }\n const types = [...dependencies.types];\n for (const type of types) {\n if (typeof type !== \"string\" || !TYPE.test(type)) throw new TypeError(\"Invalid CMS document type\");\n }\n if (dependencies.ids !== undefined && !Array.isArray(dependencies.ids)) throw new TypeError(\"Invalid CMS document IDs\");\n const ids = dependencies.ids === undefined ? undefined : [...dependencies.ids];\n for (const id of ids ?? []) {\n if (typeof id !== \"string\" || !ID.test(id) || /^(drafts|versions)\\./.test(id)) {\n throw new TypeError(\"Invalid CMS document ID\");\n }\n }\n if (new Set(types).size + new Set(ids).size > 128) throw new TypeError(\"Too many CMS tags\");\n return Object.freeze({ types: Object.freeze(types), ...(ids === undefined ? {} : { ids: Object.freeze(ids) }) });\n}\n\nexport function defineCmsQuery<T>(query: CmsQuery<T>): CmsQuery<T> {\n if (!query || typeof query.name !== \"string\" || !/^[A-Za-z][A-Za-z0-9_.-]{0,127}$/.test(query.name)\n || typeof query.query !== \"string\" || query.query.trim() === \"\" || typeof query.resolve !== \"function\") {\n throw new TypeError(\"Invalid CMS query configuration\");\n }\n const params = query.params;\n if (!params || typeof params !== \"object\" || (Object.getPrototypeOf(params) !== Object.prototype && Object.getPrototypeOf(params) !== null)) {\n throw new TypeError(\"CMS params must be plain JSON scalars\");\n }\n const copied: Record<string, string | number | boolean | null> = {};\n for (const key of Reflect.ownKeys(params)) {\n const descriptor = Object.getOwnPropertyDescriptor(params, key);\n if (typeof key !== \"string\" || !descriptor || !Object.hasOwn(descriptor, \"value\") || !descriptor.enumerable) {\n throw new TypeError(\"CMS params must be plain JSON scalars\");\n }\n const value: unknown = descriptor.value;\n if (!(value === null || typeof value === \"string\" || typeof value === \"boolean\" || (typeof value === \"number\" && Number.isFinite(value)))) {\n throw new TypeError(\"CMS params must be plain JSON scalars\");\n }\n Object.defineProperty(copied, key, { value, enumerable: true });\n }\n return Object.freeze({ name: query.name, query: query.query, params: Object.freeze(copied), dependencies: dependenciesCopy(query.dependencies), resolve: query.resolve });\n}\n\nexport function cmsTags(scope: string, dependencies: CmsDependencies): readonly string[] {\n if (typeof scope !== \"string\" || scope.length > 77 || !SCOPE.test(scope)) throw new TypeError(\"Invalid CMS scope\");\n const copied = dependenciesCopy(dependencies);\n const tags = [\n ...[...new Set(copied.types)].sort().map((type) => `cms:${scope}:type:${type}`),\n ...[...new Set(copied.ids ?? [])].sort().map((id) => `cms:${scope}:id:${id}`),\n ];\n return Object.freeze(tags);\n}\n", "import { isDenseArray } from \"./array.js\";\nimport {\n READER_ACTION_HREF, READER_JUMP_LINK, READER_PHOTO_SLUG, READER_STORY_LAYOUTS,\n type CompositionInput, type HomeContent, type PageContent, type SiteSettingsContent,\n} from \"./site-content.js\";\n\nconst object = (value: unknown): value is Record<string, unknown> => value !== null && typeof value === \"object\" && !Array.isArray(value);\nconst words = (value: unknown): boolean => typeof value === \"string\" && value.trim() !== \"\";\nconst nullableText = (value: unknown): boolean => value === null || typeof value === \"string\";\nconst photo = (value: unknown): boolean => value === null || (typeof value === \"string\" && READER_PHOTO_SLUG.test(value));\nconst href = (value: unknown): boolean => typeof value === \"string\" && READER_ACTION_HREF.test(value);\nconst copy = (value: unknown): boolean => words(value) || (object(value) && words(value.text) && (value.copySource === \"captured\" || value.copySource === \"proposed\"));\nconst optionalCopy = (value: unknown): boolean => value === null || copy(value);\nconst action = (value: unknown): boolean => object(value) && copy(value.label) && href(value.href);\nconst optionalAction = (value: unknown): boolean => value === null || action(value);\n\nfunction composition(value: unknown): boolean {\n if (!object(value) || !nullableText(value.intro) || !photo(value.photo) || !isDenseArray(value.blocks)) return false;\n const hero = value.hero;\n if (hero !== null && (!object(hero) || !copy(hero.heading) || !optionalCopy(hero.subline) || !optionalCopy(hero.intro)\n || !photo(hero.image) || !photo(hero.inset) || !optionalAction(hero.cta) || !optionalAction(hero.secondaryCta))) return false;\n const validBlocks = value.blocks.every((block: unknown) => {\n if (!object(block)) return false;\n switch (block.kind) {\n case \"campaign\": return optionalAction(block.action) && isDenseArray(block.images) && block.images.every((image: unknown) => typeof image === \"string\" && photo(image));\n case \"locations\": return (block.anchor === null || (typeof block.anchor === \"string\" && READER_JUMP_LINK.test(block.anchor))) && copy(block.heading) && optionalCopy(block.tail) && photo(block.image);\n case \"feature_stories\": return copy(block.heading) && optionalCopy(block.tail) && isDenseArray(block.items) && block.items.length > 0 && block.items.every((item: unknown) => object(item) && copy(item.heading) && copy(item.body) && action(item.action) && photo(item.image) && READER_STORY_LAYOUTS.some((layout) => layout === item.shape) && typeof item.card === \"boolean\");\n case \"accent_band\": return copy(block.heading) && copy(block.body) && optionalAction(block.action) && photo(block.image);\n case \"cta\": return words(block.heading) && nullableText(block.body) && object(block.link) && words(block.link.label) && href(block.link.href);\n default: return false;\n }\n });\n if (!validBlocks) return false;\n const model = value as unknown as CompositionInput;\n const anchors = model.blocks.flatMap((block) => block.kind === \"locations\" && block.anchor !== null ? [block.anchor] : []);\n if (new Set(anchors).size !== anchors.length) return false;\n const links = [model.hero?.cta?.href, model.hero?.secondaryCta?.href, ...model.blocks.flatMap((block) => {\n switch (block.kind) {\n case \"campaign\": case \"accent_band\": return [block.action?.href];\n case \"feature_stories\": return block.items.map((item) => item.action.href);\n case \"cta\": return [block.link.href];\n default: return [];\n }\n })];\n return links.every((link) => link === undefined || !link.startsWith(\"#\") || anchors.includes(link.slice(1)));\n}\n\nfunction proposed(value: unknown): boolean {\n return isDenseArray(value) && value.every((line: unknown) => object(line) && words(line.where) && typeof line.text === \"string\");\n}\n\nexport function validHomeFallback(value: unknown): value is HomeContent | null {\n return value === null || (object(value) && composition(value.composition) && typeof value.body === \"string\" && proposed(value.proposedCopy)\n && typeof value.campaign === \"string\" && [\"shown\", \"off\", \"not-started\", \"ended\", \"none\"].includes(value.campaign));\n}\n\nexport function validPageFallback(value: unknown): value is PageContent | null {\n return value === null || (object(value) && words(value.slug) && words(value.title) && composition(value.composition)\n && typeof value.body === \"string\" && typeof value.migrated === \"boolean\" && proposed(value.proposedCopy));\n}\n\nexport function validSettingsFallback(value: unknown): value is SiteSettingsContent | null {\n return value === null || (object(value) && words(value.name) && nullableText(value.description) && object(value.contact)\n && nullableText(value.contact.email) && nullableText(value.contact.phone) && isDenseArray(value.social)\n && value.social.every((link: unknown) => object(link) && words(link.network) && typeof link.url === \"string\" && /^https?:\\/\\//.test(link.url)));\n}\n", "/**\n * A-1713. The site content model, read: the home page, content pages and site\n * settings, validated on read and returned in the shape a site's page\n * composition consumes.\n *\n * ===========================================================================\n * READ ONLY, BY CONSTRUCTION\n * ===========================================================================\n *\n * A client site reads its content with a read-only token. All editing goes\n * through the studio's dashboard, which writes to Sanity; nothing on a client\n * site writes, and this module has no write path to call. It is handed a\n * `ContentClient` (a `query` function) and nothing else.\n *\n * ===========================================================================\n * VALIDATED ON READ, BECAUSE SANITY VALIDATION ONLY ADVISES\n * ===========================================================================\n *\n * The schema's rules warn an editor; they do not refuse a publish, and\n * anything writing over the API skips them entirely. So every document is\n * checked here again, and a malformed one is refused BY NAME\n * (`MalformedContentError`, code `malformed-content`) listing every problem\n * with its path, rather than rendered half-empty. A page that renders with a\n * missing headline and a page whose content is broken look identical to a\n * visitor; a build that fails naming `hero.headline` does not.\n *\n * Absent is not malformed: `null` from `home()` means nobody has created the\n * home page yet, and a site decides what to do about that.\n *\n * ===========================================================================\n * THE SHAPE IT RETURNS\n * ===========================================================================\n *\n * The INPUT shape of a site's composition schema (the reference build's\n * frontmatter): a copy value is a plain string for the client's own words\n * with no claim about their source, `{ text, copySource: \"captured\" }` for\n * words claimed verbatim from the capture (the site checks every such claim\n * against its capture evidence, so the claim must survive Sanity), and\n * `{ text, copySource: \"proposed\" }` for studio-written words awaiting\n * approval. All three round-trip exactly; a photo is its library slug; every key a block declares is\n * present, `null` where there is nothing. So a site validates this with the\n * same schema it validates its Markdown frontmatter with, and its components\n * never know where the content came from.\n *\n * Mapping from the generic model to the composition's names:\n *\n * hero.headline / subline / lead hero.heading / subline / intro\n * hero.photos[0], [1] hero.image, hero.inset\n * hero.primaryAction / secondary... hero.cta / secondaryCta\n * campaign (when shown) the FIRST block, kind `campaign`, and\n * the page body (`# title` + its text)\n * featureStoriesBlock kind `feature_stories`\n * surfaceCardBlock kind `cta`\n * accentBandBlock kind `accent_band`\n * locationsBlock kind `locations` (jumpLink \u2192 anchor)\n *\n * Two places the composition cannot carry a proposed marker: a `cta` block's\n * plain strings, and the campaign's title and body (which travel as Markdown).\n * There the text is returned plain and the line is still listed in\n * `proposedCopy`, which is the list a dashboard and a site both read for\n * approval. Nothing is dropped silently.\n */\n\nimport { isDenseArray } from \"./array.js\";\nimport { defineCmsQuery, type CmsQuery, type CmsResolution } from \"../contracts/query.js\";\nimport { validHomeFallback, validPageFallback, validSettingsFallback } from \"./fallback.js\";\n\n// ---------------------------------------------------------------------------\n// Output types\n// ---------------------------------------------------------------------------\n\nexport type CopyInput = string | { readonly text: string; readonly copySource: \"captured\" | \"proposed\" };\nexport type ActionInput = { readonly label: CopyInput; readonly href: string };\n\nexport type HeroInput = {\n readonly heading: CopyInput;\n readonly subline: CopyInput | null;\n readonly intro: CopyInput | null;\n readonly image: string | null;\n readonly inset: string | null;\n readonly cta: ActionInput | null;\n readonly secondaryCta: ActionInput | null;\n};\n\nexport type StoryInput = {\n readonly heading: CopyInput;\n readonly body: CopyInput;\n readonly action: ActionInput;\n readonly image: string | null;\n readonly shape: \"wide\" | \"tall\" | \"round\" | \"free\";\n readonly card: boolean;\n};\n\nexport type CompositionBlockInput =\n | { readonly kind: \"campaign\"; readonly action: ActionInput | null; readonly images: readonly string[] }\n | {\n readonly kind: \"locations\";\n readonly anchor: string | null;\n readonly heading: CopyInput;\n readonly tail: CopyInput | null;\n readonly image: string | null;\n }\n | {\n readonly kind: \"feature_stories\";\n readonly heading: CopyInput;\n readonly tail: CopyInput | null;\n readonly items: readonly StoryInput[];\n }\n | {\n readonly kind: \"accent_band\";\n readonly heading: CopyInput;\n readonly body: CopyInput;\n readonly action: ActionInput | null;\n readonly image: string | null;\n }\n | {\n readonly kind: \"cta\";\n readonly heading: string;\n readonly body: string | null;\n readonly link: { readonly label: string; readonly href: string };\n };\n\nexport type CompositionInput = {\n readonly intro: string | null;\n readonly photo: string | null;\n readonly hero: HeroInput | null;\n readonly blocks: readonly CompositionBlockInput[];\n};\n\n/** One line of studio-written copy awaiting approval, and where it is in the document. */\nexport type ProposedCopy = { readonly where: string; readonly text: string };\n\nexport type CampaignState = \"shown\" | \"off\" | \"not-started\" | \"ended\" | \"none\";\n\nexport type HomeContent = {\n readonly composition: CompositionInput;\n /** The page body as Markdown: the campaign's title and text when it is shown, otherwise empty. */\n readonly body: string;\n readonly campaign: CampaignState;\n readonly proposedCopy: readonly ProposedCopy[];\n};\n\nexport type PageContent = {\n readonly slug: string;\n readonly title: string;\n readonly composition: CompositionInput;\n readonly body: string;\n readonly migrated: boolean;\n readonly proposedCopy: readonly ProposedCopy[];\n};\n\nexport type SiteSettingsContent = {\n readonly name: string;\n readonly description: string | null;\n readonly contact: { readonly email: string | null; readonly phone: string | null };\n readonly social: readonly { readonly network: string; readonly url: string }[];\n};\n\n// ---------------------------------------------------------------------------\n// The refusal\n// ---------------------------------------------------------------------------\n\nexport const MALFORMED_CONTENT = \"malformed-content\";\n\nexport class MalformedContentError extends Error {\n readonly code = MALFORMED_CONTENT;\n readonly documentId: string;\n readonly problems: readonly string[];\n\n constructor(documentId: string, problems: readonly string[]) {\n super(`${MALFORMED_CONTENT}: ${documentId}: ${problems.join(\"; \")}`);\n this.name = \"MalformedContentError\";\n this.documentId = documentId;\n this.problems = problems;\n }\n}\n\n// ---------------------------------------------------------------------------\n// The rules restated\n// ---------------------------------------------------------------------------\n\n/*\n * Runtime-free rules shared with schema-base. The schema adapter imports these\n * objects; content-client compatibility tests pin the shared references.\n */\nexport const READER_PHOTO_SLUG = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;\nexport const READER_ACTION_HREF =\n /^(?:\\/(?![/\\\\])[^\\s]*|#[a-z][a-z0-9]*(?:-[a-z0-9]+)*|mailto:[^\\s@]+@[^\\s@]+|tel:\\+?[0-9][0-9 ()-]*|https?:\\/\\/[^\\s/]+[^\\s]*)$/;\nexport const READER_JUMP_LINK = /^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/;\nexport const READER_STORY_LAYOUTS = [\"wide\", \"tall\", \"round\", \"free\"] as const;\nexport const READER_HOME_PAGE_ID = \"homePage\";\nexport const READER_SITE_SETTINGS_ID = \"siteSettings\";\n\n// ---------------------------------------------------------------------------\n// A small path-aware reader\n// ---------------------------------------------------------------------------\n\ntype Raw = Record<string, unknown>;\n\nclass Reading {\n readonly problems: string[] = [];\n readonly proposed: ProposedCopy[] = [];\n\n fail(path: string, message: string): null {\n this.problems.push(`${path} ${message}`);\n return null;\n }\n\n object(value: unknown, path: string): Raw | null {\n if (typeof value === \"object\" && value !== null && !Array.isArray(value)) return value as Raw;\n return this.fail(path, \"is not an object\");\n }\n\n dense(value: unknown[], path: string): boolean {\n if (isDenseArray(value)) return true;\n this.fail(path, \"contains missing entries\");\n return false;\n }\n\n optionalString(value: unknown, path: string): string | null {\n if (value === undefined || value === null) return null;\n if (typeof value === \"string\") return value.trim() === \"\" ? null : value;\n return this.fail(path, \"is not text\");\n }\n\n /** A copy value, or null when absent or empty. Records a proposed line. */\n copy(value: unknown, path: string): CopyInput | null {\n if (value === undefined || value === null) return null;\n const raw = this.object(value, path);\n if (raw === null) return null;\n const text = raw[\"text\"];\n const source = raw[\"copySource\"];\n if (text !== undefined && typeof text !== \"string\") return this.fail(`${path}.text`, \"is not text\");\n if (source !== undefined && source !== \"captured\" && source !== \"proposed\") {\n return this.fail(`${path}.copySource`, `is ${JSON.stringify(source)}, not captured or proposed`);\n }\n if (typeof text !== \"string\" || text.trim() === \"\") return null;\n if (source === \"proposed\") {\n this.proposed.push({ where: path, text });\n return { text, copySource: \"proposed\" };\n }\n if (source === \"captured\") return { text, copySource: \"captured\" };\n return text;\n }\n\n requiredCopy(value: unknown, path: string): CopyInput | null {\n const copy = this.copy(value, path);\n if (copy === null && !this.problems.some((p) => p.startsWith(path))) this.fail(path, \"is missing its words\");\n return copy;\n }\n\n photo(value: unknown, path: string): string | null {\n if (value === undefined || value === null) return null;\n if (typeof value === \"string\" && READER_PHOTO_SLUG.test(value)) return value;\n return this.fail(path, `is ${JSON.stringify(value)}, not a photo library slug`);\n }\n\n photos(value: unknown, path: string, max: number): string[] {\n if (value === undefined || value === null) return [];\n if (!Array.isArray(value)) {\n this.fail(path, \"is not a list of photos\");\n return [];\n }\n if (!this.dense(value, path)) return [];\n if (value.length > max) this.fail(path, `holds ${String(value.length)} photos; at most ${String(max)}`);\n return value.map((entry, index) => this.photo(entry, `${path}[${String(index)}]`)).filter((p): p is string => p !== null);\n }\n\n action(value: unknown, path: string): ActionInput | null {\n if (value === undefined || value === null) return null;\n const raw = this.object(value, path);\n if (raw === null) return null;\n const label = this.requiredCopy(raw[\"label\"], `${path}.label`);\n const href = raw[\"href\"];\n if (typeof href !== \"string\" || !READER_ACTION_HREF.test(href)) {\n return this.fail(`${path}.href`, `is ${JSON.stringify(href)}, not a site path, #jump-link, mailto:, tel: or web address`);\n }\n return label === null ? null : { label, href };\n }\n\n requiredAction(value: unknown, path: string): ActionInput | null {\n if (value === undefined || value === null) return this.fail(path, \"is missing\");\n return this.action(value, path);\n }\n}\n\nfunction plain(copy: CopyInput): string {\n return typeof copy === \"string\" ? copy : copy.text;\n}\n\n// ---------------------------------------------------------------------------\n// Portable Text to Markdown\n// ---------------------------------------------------------------------------\n\n/**\n * The narrow Portable Text `portableText` declares, back to Markdown: normal,\n * h2, h3 and quote blocks, bullet and numbered lists, bold, italic, code and\n * links. It is the inverse of the seed package's Markdown mapper, and the\n * round-trip test holds the two to each other.\n *\n * An uploaded image inside rich text is REFUSED, not dropped: nothing can\n * upload one yet (the dashboard slice decides how), so one arriving means\n * something wrote the document by hand, and a page silently missing a picture\n * is the failure this reader exists to prevent.\n */\nexport function portableTextToMarkdown(value: unknown): string {\n const reading = new Reading();\n const markdown = richTextToMarkdown(value, \"body\", reading);\n if (reading.problems.length > 0) throw new MalformedContentError(\"body\", reading.problems);\n return markdown;\n}\n\nfunction richTextToMarkdown(value: unknown, path: string, reading: Reading): string {\n if (value === undefined || value === null) return \"\";\n if (!Array.isArray(value)) {\n reading.fail(path, \"is not rich text\");\n return \"\";\n }\n if (!reading.dense(value, path)) return \"\";\n const out: string[] = [];\n let previousWasList = false;\n value.forEach((member, index) => {\n const at = `${path}[${String(index)}]`;\n const block = reading.object(member, at);\n if (block === null) return;\n if (block[\"_type\"] !== \"block\") {\n reading.fail(at, `is a ${JSON.stringify(block[\"_type\"])}; only text is supported in rich text so far`);\n return;\n }\n const text = spansToMarkdown(block, at, reading);\n const listItem = block[\"listItem\"];\n const style = block[\"style\"] ?? \"normal\";\n let line: string;\n if (listItem === \"bullet\" || listItem === \"number\") {\n const level = typeof block[\"level\"] === \"number\" && block[\"level\"] > 1 ? block[\"level\"] : 1;\n line = `${\" \".repeat(level - 1)}${listItem === \"bullet\" ? \"-\" : \"1.\"} ${text}`;\n } else if (style === \"h2\") line = `## ${text}`;\n else if (style === \"h3\") line = `### ${text}`;\n else if (style === \"blockquote\") line = `> ${text}`;\n else if (style === \"normal\") line = text;\n else {\n reading.fail(`${at}.style`, `is ${JSON.stringify(style)}, which the schema does not offer`);\n return;\n }\n const isList = listItem === \"bullet\" || listItem === \"number\";\n if (out.length > 0) out.push(isList && previousWasList ? \"\\n\" : \"\\n\\n\");\n out.push(line);\n previousWasList = isList;\n });\n return out.join(\"\");\n}\n\nconst DECORATORS: Record<string, string> = { strong: \"**\", em: \"*\", code: \"`\" };\n\nfunction spansToMarkdown(block: Raw, path: string, reading: Reading): string {\n const links = new Map<string, string>();\n const markDefs = Array.isArray(block[\"markDefs\"]) ? (block[\"markDefs\"] as unknown[]) : [];\n if (!reading.dense(markDefs, `${path}.markDefs`)) return \"\";\n for (const def of markDefs) {\n const d = def as Raw;\n if (d[\"_type\"] === \"link\" && typeof d[\"_key\"] === \"string\" && typeof d[\"href\"] === \"string\") links.set(d[\"_key\"], d[\"href\"]);\n }\n const children = Array.isArray(block[\"children\"]) ? (block[\"children\"] as unknown[]) : [];\n if (!reading.dense(children, `${path}.children`)) return \"\";\n return children\n .map((child, index) => {\n const span = child as Raw;\n if (span[\"_type\"] !== \"span\" || typeof span[\"text\"] !== \"string\") {\n reading.fail(`${path}.children[${String(index)}]`, \"is not a text span\");\n return \"\";\n }\n let text = span[\"text\"];\n const marks = Array.isArray(span[\"marks\"]) ? (span[\"marks\"] as unknown[]) : [];\n if (!reading.dense(marks, `${path}.children[${String(index)}].marks`)) return \"\";\n let href: string | null = null;\n for (const mark of marks) {\n if (typeof mark !== \"string\") continue;\n const fence = DECORATORS[mark];\n if (fence !== undefined) text = `${fence}${text}${fence}`;\n else if (links.has(mark)) href = links.get(mark) ?? null;\n else reading.fail(`${path}.children[${String(index)}].marks`, `names ${JSON.stringify(mark)}, which is neither a style nor a link`);\n }\n return href === null ? text : `[${text}](${href})`;\n })\n .join(\"\");\n}\n\n// ---------------------------------------------------------------------------\n// The home page\n// ---------------------------------------------------------------------------\n\n/** Whether a campaign is shown at `now`, and if not, why not. */\nexport function campaignState(campaign: unknown, now: Date): CampaignState {\n if (typeof campaign !== \"object\" || campaign === null) return \"none\";\n const c = campaign as Raw;\n if (c[\"enabled\"] !== true) return \"off\";\n const starts = typeof c[\"startsAt\"] === \"string\" ? Date.parse(c[\"startsAt\"]) : null;\n const ends = typeof c[\"endsAt\"] === \"string\" ? Date.parse(c[\"endsAt\"]) : null;\n if (starts !== null && now.getTime() < starts) return \"not-started\";\n if (ends !== null && now.getTime() >= ends) return \"ended\";\n return \"shown\";\n}\n\nfunction keyed(path: string, raw: Raw, index: number): string {\n return typeof raw[\"_key\"] === \"string\" ? `${path}[_key==\"${raw[\"_key\"]}\"]` : `${path}[${String(index)}]`;\n}\n\n/**\n * A stored home page document, validated and mapped. Throws\n * `MalformedContentError` naming every problem. `now` decides whether a\n * scheduled campaign is shown, and is a parameter so a build, a preview and a\n * test each say which moment they mean.\n */\nexport function parseHomePage(document: unknown, options: { readonly now: Date }): HomeContent {\n const reading = new Reading();\n const doc = reading.object(document, \"homePage\");\n if (doc === null) throw new MalformedContentError(READER_HOME_PAGE_ID, reading.problems);\n const id = typeof doc[\"_id\"] === \"string\" ? doc[\"_id\"] : READER_HOME_PAGE_ID;\n if (doc[\"_type\"] !== \"homePage\") reading.fail(\"_type\", `is ${JSON.stringify(doc[\"_type\"])}, not homePage`);\n\n let hero: HeroInput | null = null;\n const rawHero = doc[\"hero\"] === undefined ? reading.fail(\"hero\", \"is missing\") : reading.object(doc[\"hero\"], \"hero\");\n if (rawHero !== null) {\n const photos = reading.photos(rawHero[\"photos\"], \"hero.photos\", 2);\n const heading = reading.requiredCopy(rawHero[\"headline\"], \"hero.headline\");\n const subline = reading.copy(rawHero[\"subline\"], \"hero.subline\");\n const intro = reading.copy(rawHero[\"lead\"], \"hero.lead\");\n const cta = reading.action(rawHero[\"primaryAction\"], \"hero.primaryAction\");\n const secondaryCta = reading.action(rawHero[\"secondaryAction\"], \"hero.secondaryAction\");\n if (heading !== null) {\n hero = { heading, subline, intro, image: photos[0] ?? null, inset: photos[1] ?? null, cta, secondaryCta };\n }\n }\n\n const blocks: CompositionBlockInput[] = [];\n const blockJumps: { where: string; href: string }[] = [];\n let body = \"\";\n const state = campaignState(doc[\"campaign\"], options.now);\n if (state === \"shown\") {\n const campaign = reading.object(doc[\"campaign\"], \"campaign\");\n if (campaign !== null) {\n const title = reading.requiredCopy(campaign[\"title\"], \"campaign.title\");\n const images = reading.photos(campaign[\"photos\"], \"campaign.photos\", 3);\n if (images.length === 0) reading.fail(\"campaign.photos\", \"is empty; a shown campaign needs at least one photo\");\n const text = richTextToMarkdown(campaign[\"body\"], \"campaign.body\", reading);\n if (text === \"\") reading.fail(\"campaign.body\", \"is empty; a shown campaign needs its text\");\n if (campaign[\"bodyCopySource\"] === \"proposed\") reading.proposed.push({ where: \"campaign.body\", text });\n const action = reading.action(campaign[\"action\"], \"campaign.action\");\n if (action !== null) blockJumps.push({ where: \"campaign.action.href\", href: action.href });\n if (title !== null) body = `# ${plain(title)}\\n\\n${text}`;\n blocks.push({ kind: \"campaign\", action, images });\n }\n }\n\n const anchors: string[] = [];\n const rawBlocks = doc[\"blocks\"] ?? [];\n if (!Array.isArray(rawBlocks)) reading.fail(\"blocks\", \"is not a list\");\n else if (reading.dense(rawBlocks, \"blocks\")) {\n rawBlocks.forEach((member, index) => {\n const raw = reading.object(member, `blocks[${String(index)}]`);\n if (raw === null) return;\n const at = keyed(\"blocks\", raw, index);\n const mapped = mapBlock(raw, at, reading);\n if (mapped === null) return;\n blockJumps.push(...buttonsOf(mapped, raw, at));\n if (mapped.kind === \"locations\" && mapped.anchor !== null) {\n if (anchors.includes(mapped.anchor)) reading.fail(`${at}.jumpLink`, `repeats \"${mapped.anchor}\", already used by another section`);\n anchors.push(mapped.anchor);\n }\n blocks.push(mapped);\n });\n }\n\n // A jump link on ANY button must land on a section of this page.\n const jumps: { where: string; href: string }[] = [];\n if (hero?.cta) jumps.push({ where: \"hero.primaryAction.href\", href: hero.cta.href });\n if (hero?.secondaryCta) jumps.push({ where: \"hero.secondaryAction.href\", href: hero.secondaryCta.href });\n jumps.push(...blockJumps);\n for (const { where, href } of jumps) {\n if (href.startsWith(\"#\") && !anchors.includes(href.slice(1))) {\n reading.fail(where, `jumps to ${href}, which no section on the page is named`);\n }\n }\n\n if (reading.problems.length > 0) throw new MalformedContentError(id, reading.problems);\n return {\n composition: { intro: null, photo: null, hero, blocks },\n body,\n campaign: state,\n proposedCopy: reading.proposed,\n };\n}\n\n/** Every button a mapped section carries, with its path in the stored document. */\nfunction buttonsOf(block: CompositionBlockInput, raw: Raw, at: string): { where: string; href: string }[] {\n switch (block.kind) {\n case \"feature_stories\": {\n const stories = Array.isArray(raw[\"stories\"]) ? (raw[\"stories\"] as Raw[]) : [];\n return block.items.map((item, index) => ({\n where: `${keyed(`${at}.stories`, stories[index] ?? {}, index)}.action.href`,\n href: item.action.href,\n }));\n }\n case \"accent_band\":\n return block.action === null ? [] : [{ where: `${at}.action.href`, href: block.action.href }];\n case \"cta\":\n return [{ where: `${at}.action.href`, href: block.link.href }];\n default:\n return [];\n }\n}\n\nfunction mapBlock(raw: Raw, at: string, reading: Reading): CompositionBlockInput | null {\n switch (raw[\"_type\"]) {\n case \"featureStoriesBlock\": {\n const heading = reading.requiredCopy(raw[\"heading\"], `${at}.heading`);\n const tail = reading.copy(raw[\"tail\"], `${at}.tail`);\n const stories = raw[\"stories\"];\n if (!Array.isArray(stories) || stories.length === 0) return reading.fail(`${at}.stories`, \"has no stories\");\n if (!reading.dense(stories, `${at}.stories`)) return null;\n const items: StoryInput[] = [];\n stories.forEach((member, index) => {\n const story = reading.object(member, `${at}.stories[${String(index)}]`);\n if (story === null) return;\n const sat = keyed(`${at}.stories`, story, index);\n const sHeading = reading.requiredCopy(story[\"heading\"], `${sat}.heading`);\n const sBody = reading.requiredCopy(story[\"body\"], `${sat}.body`);\n const action = reading.requiredAction(story[\"action\"], `${sat}.action`);\n const image = reading.photo(story[\"photo\"], `${sat}.photo`);\n const layout = story[\"layout\"] ?? \"wide\";\n if (!(READER_STORY_LAYOUTS as readonly unknown[]).includes(layout)) {\n reading.fail(`${sat}.layout`, `is ${JSON.stringify(layout)}, not wide, tall, round or free`);\n return;\n }\n const onCard = story[\"onCard\"] ?? false;\n if (typeof onCard !== \"boolean\") {\n reading.fail(`${sat}.onCard`, \"is not on or off\");\n return;\n }\n if (sHeading === null || sBody === null || action === null) return;\n items.push({ heading: sHeading, body: sBody, action, image, shape: layout as StoryInput[\"shape\"], card: onCard });\n });\n return heading === null ? null : { kind: \"feature_stories\", heading, tail, items };\n }\n case \"surfaceCardBlock\": {\n const heading = reading.requiredCopy(raw[\"heading\"], `${at}.heading`);\n const body = reading.copy(raw[\"body\"], `${at}.body`);\n const action = reading.requiredAction(raw[\"action\"], `${at}.action`);\n if (heading === null || action === null) return null;\n return {\n kind: \"cta\",\n heading: plain(heading),\n body: body === null ? null : plain(body),\n link: { label: plain(action.label), href: action.href },\n };\n }\n case \"accentBandBlock\": {\n const heading = reading.requiredCopy(raw[\"heading\"], `${at}.heading`);\n const body = reading.requiredCopy(raw[\"body\"], `${at}.body`);\n const action = reading.action(raw[\"action\"], `${at}.action`);\n const image = reading.photo(raw[\"photo\"], `${at}.photo`);\n if (heading === null || body === null) return null;\n return { kind: \"accent_band\", heading, body, action, image };\n }\n case \"locationsBlock\": {\n const jump = raw[\"jumpLink\"];\n let anchor: string | null = null;\n if (jump !== undefined && jump !== null && jump !== \"\") {\n if (typeof jump !== \"string\" || !READER_JUMP_LINK.test(jump)) reading.fail(`${at}.jumpLink`, `is ${JSON.stringify(jump)}, not lowercase words joined by hyphens`);\n else anchor = jump;\n }\n const heading = reading.requiredCopy(raw[\"heading\"], `${at}.heading`);\n const tail = reading.copy(raw[\"tail\"], `${at}.tail`);\n const image = reading.photo(raw[\"photo\"], `${at}.photo`);\n return heading === null ? null : { kind: \"locations\", anchor, heading, tail, image };\n }\n default:\n return reading.fail(`${at}._type`, `is ${JSON.stringify(raw[\"_type\"])}, not a section type this reader knows`);\n }\n}\n\n// ---------------------------------------------------------------------------\n// Content pages and settings\n// ---------------------------------------------------------------------------\n\nexport function parseContentPage(document: unknown): PageContent {\n const reading = new Reading();\n const doc = reading.object(document, \"page\");\n if (doc === null) throw new MalformedContentError(\"page\", reading.problems);\n const id = typeof doc[\"_id\"] === \"string\" ? doc[\"_id\"] : \"page\";\n if (doc[\"_type\"] !== \"page\") reading.fail(\"_type\", `is ${JSON.stringify(doc[\"_type\"])}, not page`);\n const title = reading.optionalString(doc[\"title\"], \"title\");\n if (title === null) reading.fail(\"title\", \"is missing\");\n if (doc[\"titleCopySource\"] === \"proposed\" && title !== null) reading.proposed.push({ where: \"title\", text: title });\n const slugObject = doc[\"slug\"] as Raw | undefined;\n const slug = typeof slugObject?.[\"current\"] === \"string\" && slugObject[\"current\"] !== \"\" ? slugObject[\"current\"] : null;\n if (slug === null) reading.fail(\"slug.current\", \"is missing\");\n const lead = reading.copy(doc[\"lead\"], \"lead\");\n const photo = reading.photo(doc[\"photo\"], \"photo\");\n const body = richTextToMarkdown(doc[\"body\"], \"body\", reading);\n if (doc[\"bodyCopySource\"] === \"proposed\") reading.proposed.push({ where: \"body\", text: body });\n if (reading.problems.length > 0 || title === null || slug === null) throw new MalformedContentError(id, reading.problems);\n return {\n slug,\n title,\n composition: { intro: lead === null ? null : plain(lead), photo, hero: null, blocks: [] },\n body,\n migrated: doc[\"migrated\"] === true,\n proposedCopy: reading.proposed,\n };\n}\n\nexport function parseSiteSettings(document: unknown): SiteSettingsContent {\n const reading = new Reading();\n const doc = reading.object(document, \"siteSettings\");\n if (doc === null) throw new MalformedContentError(READER_SITE_SETTINGS_ID, reading.problems);\n const name = reading.optionalString(doc[\"title\"], \"title\");\n if (name === null) reading.fail(\"title\", \"is missing; a site needs its name\");\n const description = reading.optionalString(doc[\"description\"], \"description\");\n const contact = doc[\"contact\"] === undefined ? {} : (reading.object(doc[\"contact\"], \"contact\") ?? {});\n const email = reading.optionalString(contact[\"email\"], \"contact.email\");\n const phone = reading.optionalString(contact[\"phone\"], \"contact.phone\");\n const social: { network: string; url: string }[] = [];\n const rawSocial = doc[\"social\"] ?? [];\n if (!Array.isArray(rawSocial)) reading.fail(\"social\", \"is not a list\");\n else if (reading.dense(rawSocial, \"social\"))\n rawSocial.forEach((member, index) => {\n const link = reading.object(member, `social[${String(index)}]`);\n if (link === null) return;\n const network = reading.optionalString(link[\"network\"], `social[${String(index)}].network`);\n const url = reading.optionalString(link[\"url\"], `social[${String(index)}].url`);\n if (network === null || url === null || !/^https?:\\/\\//.test(url)) {\n reading.fail(`social[${String(index)}]`, \"needs a network and a web address\");\n return;\n }\n social.push({ network, url });\n });\n if (reading.problems.length > 0 || name === null) throw new MalformedContentError(READER_SITE_SETTINGS_ID, reading.problems);\n return { name, description, contact: { email, phone }, social };\n}\n\n// ---------------------------------------------------------------------------\n// Queries\n// ---------------------------------------------------------------------------\n\n/** By fixed id: a second home page at a random id is never read. */\nexport const HOME_PAGE_DOCUMENT_QUERY = `*[_id == $id][0]`;\nexport const CONTENT_PAGES_QUERY = `*[_type == \"page\" && defined(slug.current)]|order(slug.current asc)`;\nexport const CONTENT_PAGE_BY_SLUG_QUERY = `*[_type == \"page\" && slug.current == $slug][0]`;\n\nexport interface SiteContentReader {\n /** `null` when no home page document exists yet. */\n home: (options: { readonly now: Date }) => Promise<HomeContent | null>;\n pages: () => Promise<PageContent[]>;\n /** `null` when no page has that slug. */\n pageBySlug: (slug: string) => Promise<PageContent | null>;\n /** `null` before anyone has filled in the site's details. */\n siteSettings: () => Promise<SiteSettingsContent | null>;\n}\n\nexport function createSiteContentReader(client: { query: <T>(groq: string, options?: { params?: Record<string, unknown>; tags?: readonly string[] }) => Promise<T> }): SiteContentReader {\n return {\n home: async ({ now }) => {\n const doc = await client.query<unknown>(HOME_PAGE_DOCUMENT_QUERY, { params: { id: READER_HOME_PAGE_ID } });\n return doc === null || doc === undefined ? null : parseHomePage(doc, { now });\n },\n pages: async () => {\n const docs = await client.query<unknown>(CONTENT_PAGES_QUERY);\n if (!Array.isArray(docs)) throw new MalformedContentError(\"page\", [\"the page query did not return a list\"]);\n if (!isDenseArray(docs)) throw new MalformedContentError(\"page\", [\"the page query contains missing entries\"]);\n return docs.map((doc) => parseContentPage(doc));\n },\n pageBySlug: async (slug) => {\n const doc = await client.query<unknown>(CONTENT_PAGE_BY_SLUG_QUERY, { params: { slug } });\n return doc === null || doc === undefined ? null : parseContentPage(doc);\n },\n siteSettings: async () => {\n const doc = await client.query<unknown>(HOME_PAGE_DOCUMENT_QUERY, { params: { id: READER_SITE_SETTINGS_ID } });\n return doc === null || doc === undefined ? null : parseSiteSettings(doc);\n },\n };\n}\n\nfunction atomic<T>(raw: unknown, fallback: T, parse: (value: unknown) => T, validFallback: (value: unknown) => boolean): CmsResolution<T> {\n if (!validFallback(fallback)) throw new TypeError(\"Invalid CMS content fallback\");\n if (raw === null || raw === undefined) return { data: fallback, fallbackFields: [\"$\"] };\n // The server reader catches parser errors and classifies the whole fallback\n // as malformed. Returning fallback here would lose that diagnostic reason.\n return { data: parse(raw), fallbackFields: [] };\n}\n\nexport function homeContentQuery(now: Date): CmsQuery<HomeContent | null> {\n if (!(now instanceof Date) || !Number.isFinite(now.getTime())) throw new TypeError(\"Invalid CMS campaign date\");\n const captured = now.getTime();\n return defineCmsQuery({\n name: \"homePage.v1\", query: HOME_PAGE_DOCUMENT_QUERY, params: { id: READER_HOME_PAGE_ID },\n dependencies: { types: [\"homePage\"], ids: [READER_HOME_PAGE_ID] },\n resolve: (raw, fallback) => atomic(raw, fallback, (value) => parseHomePage(value, { now: new Date(captured) }), validHomeFallback),\n });\n}\n\nexport function contentPageQuery(slug: string): CmsQuery<PageContent | null> {\n if (typeof slug !== \"string\" || slug === \"\") throw new TypeError(\"Invalid CMS page slug\");\n return defineCmsQuery({\n name: \"page.v1\", query: CONTENT_PAGE_BY_SLUG_QUERY, params: { slug }, dependencies: { types: [\"page\"] },\n resolve: (raw, fallback) => atomic(raw, fallback, parseContentPage, validPageFallback),\n });\n}\n\nexport function contentPagesQuery(): CmsQuery<readonly PageContent[]> {\n return defineCmsQuery({\n name: \"pages.v1\", query: CONTENT_PAGES_QUERY, params: {}, dependencies: { types: [\"page\"] },\n resolve: (raw, fallback) => atomic(raw, fallback, (value) => {\n if (!Array.isArray(value)) throw new MalformedContentError(\"page\", [\"the page query did not return a list\"]);\n if (!isDenseArray(value)) throw new MalformedContentError(\"page\", [\"the page query contains missing entries\"]);\n return value.map((document: unknown) => parseContentPage(document));\n }, (value) => isDenseArray(value) && value.every((page: unknown) => page !== null && validPageFallback(page))),\n });\n}\n\nexport function siteSettingsQuery(): CmsQuery<SiteSettingsContent | null> {\n return defineCmsQuery({\n name: \"siteSettings.v1\", query: HOME_PAGE_DOCUMENT_QUERY, params: { id: READER_SITE_SETTINGS_ID },\n dependencies: { types: [\"siteSettings\"], ids: [READER_SITE_SETTINGS_ID] },\n resolve: (raw, fallback) => atomic(raw, fallback, parseSiteSettings, validSettingsFallback),\n });\n}\n", "import { defineCmsQuery, type CmsQuery, type CmsResolution } from \"./query.js\";\n\nexport const SITE_HERO_LAYOUTS = [\"columns\", \"rows\"] as const;\nexport const SITE_HERO_TAGLINE_MAX_LENGTH = 36;\nexport const SITE_HERO_LAYOUT_WARNING = \"siteHero.layout.defaulted\" as const;\nexport type SiteHeroLayout = typeof SITE_HERO_LAYOUTS[number];\nexport type SiteHeroTagline = { readonly key: string; readonly text: string };\n/** Optional additions preserve existing heading/intro-only consumer fallbacks. */\nexport type SiteHero = {\n readonly heading: string;\n readonly intro: string;\n readonly layout?: SiteHeroLayout;\n readonly taglines?: readonly SiteHeroTagline[];\n};\nexport type ParsedSiteHero = SiteHero & {\n readonly layout: SiteHeroLayout;\n readonly taglines: readonly SiteHeroTagline[];\n};\nexport type TextFieldDefinition = {\n readonly name: string;\n readonly label: string;\n readonly noun: { readonly article: \"a\" | \"an\"; readonly word: string };\n readonly kind: \"single-line\" | \"multi-line\";\n readonly required: boolean;\n readonly minLength: number;\n readonly maxLength: number;\n readonly noTrailingFullStop?: boolean;\n};\nexport type TextDocumentDefinition = {\n readonly key: string;\n readonly documentId: string;\n readonly documentType: string;\n readonly fields: readonly TextFieldDefinition[];\n readonly copy: {\n readonly currentTitle: string;\n readonly editTitle: string;\n readonly empty: string;\n };\n};\nexport type TextValidation =\n | { readonly ok: true; readonly value: Readonly<Record<string, string>> }\n | { readonly ok: false; readonly errors: Readonly<Record<string, string>> };\n\nexport const CMS_CONTRACT_VERSION = 1;\n\nexport const SITE_HERO: TextDocumentDefinition = {\n key: \"hero\",\n documentId: \"siteHero\",\n documentType: \"siteHero\",\n fields: [\n {\n name: \"heading\",\n label: \"Heading\",\n noun: { article: \"a\", word: \"heading\" },\n kind: \"single-line\",\n required: true,\n minLength: 1,\n maxLength: 80,\n noTrailingFullStop: true,\n },\n {\n name: \"intro\",\n label: \"Introduction\",\n noun: { article: \"an\", word: \"introduction\" },\n kind: \"multi-line\",\n required: true,\n minLength: 1,\n maxLength: 320,\n },\n ],\n copy: {\n currentTitle: \"On your site now\",\n editTitle: \"Edit and publish\",\n empty: \"Your site has no hero text yet. Whatever you publish below becomes its first version.\",\n },\n};\n\nfunction fieldError(field: TextFieldDefinition, text: string): string | null {\n const { article, word } = field.noun;\n if (text.length === 0) return field.required ? `Enter ${article} ${word}.` : null;\n const count = [...text].length;\n if (count < field.minLength) return `Make the ${word} at least ${String(field.minLength)} characters. It is ${String(count)} now.`;\n if (count > field.maxLength) return `Keep the ${word} to ${String(field.maxLength)} characters or fewer. It is ${String(count)} now.`;\n if (text.includes(\"\\u2014\")) return `The ${word} contains a long dash. Use a comma, a colon or a short dash instead.`;\n if (field.kind === \"single-line\" && /[\\r\\n]/.test(text)) return `The ${word} must be a single line.`;\n if (field.noTrailingFullStop === true && text.endsWith(\".\")) {\n return `${word.charAt(0).toUpperCase()}${word.slice(1)}s on your site do not end with a full stop. Remove the last full stop.`;\n }\n return null;\n}\n\nexport function validateTextDocument(\n definition: TextDocumentDefinition, raw: Readonly<Record<string, unknown>>,\n): TextValidation {\n const value: Record<string, string> = {};\n const errors: Record<string, string> = {};\n for (const field of definition.fields) {\n const submitted = Object.hasOwn(raw, field.name) ? raw[field.name] : undefined;\n const text = typeof submitted === \"string\" ? submitted.trim() : \"\";\n const error = fieldError(field, text);\n Object.defineProperty(error === null ? value : errors, field.name, { value: error ?? text, enumerable: true });\n }\n return Object.keys(errors).length > 0 ? { ok: false, errors } : { ok: true, value };\n}\n\n/** Shared with the schema adapter; no provider metadata is returned. */\nexport function validateSiteHeroTaglines(raw: unknown):\n | { readonly ok: true; readonly value: readonly SiteHeroTagline[] }\n | { readonly ok: false; readonly error: string } {\n if (!Array.isArray(raw)) return { ok: false, error: \"Enter a list of taglines.\" };\n const heading = SITE_HERO.fields[0];\n if (!heading) throw new TypeError(\"Missing siteHero heading definition\");\n const field = { ...heading, name: \"text\", noun: { article: \"a\", word: \"tagline\" } as const,\n maxLength: SITE_HERO_TAGLINE_MAX_LENGTH };\n const value: SiteHeroTagline[] = [];\n const keys = new Set<string>();\n for (const item of raw as unknown[]) {\n if (!item || typeof item !== \"object\" || Array.isArray(item)) return { ok: false, error: \"Enter a key and text for each tagline.\" };\n const record = item as Record<string, unknown>;\n const key = Object.hasOwn(record, \"key\") ? record.key : undefined;\n if (typeof key !== \"string\" || !/^[a-z][a-z0-9_-]{0,31}$/.test(key)) {\n return { ok: false, error: \"Use a lowercase key of 1 to 32 letters, numbers, short dashes or underscores, starting with a letter.\" };\n }\n if (keys.has(key)) return { ok: false, error: \"Use each tagline key only once.\" };\n const text = validateTextDocument({ ...SITE_HERO, fields: [field] }, record);\n if (!text.ok) return { ok: false, error: text.errors.text ?? \"Invalid tagline.\" };\n keys.add(key);\n value.push({ key, text: text.value.text ?? \"\" });\n }\n return { ok: true, value };\n}\n\nfunction isLayout(value: unknown): value is SiteHeroLayout {\n return SITE_HERO_LAYOUTS.some((layout) => value === layout);\n}\n\n/** Strict per-field resolution: an invalid list never partially changes keyed copy. */\nexport function parseSiteHero(raw: unknown, fallback: SiteHero): CmsResolution<ParsedSiteHero> {\n const local = validateTextDocument(SITE_HERO, fallback);\n const localTaglines = validateSiteHeroTaglines(fallback.taglines ?? []);\n if (!local.ok || !localTaglines.ok || (fallback.layout !== undefined && !isLayout(fallback.layout))) {\n throw new TypeError(\"Invalid siteHero fallback\");\n }\n const data: { heading: string; intro: string; layout: SiteHeroLayout; taglines: readonly SiteHeroTagline[] } = {\n heading: local.value.heading ?? \"\", intro: local.value.intro ?? \"\",\n layout: fallback.layout ?? \"columns\", taglines: localTaglines.value,\n };\n if (raw === null || typeof raw !== \"object\" || Array.isArray(raw)) return { data, fallbackFields: [\"$\"] };\n const record = raw as Readonly<Record<string, unknown>>;\n const text = validateTextDocument(SITE_HERO, record);\n const fallbackFields: string[] = text.ok ? [] : Object.keys(text.errors);\n for (const field of SITE_HERO.fields) {\n if (!fallbackFields.includes(field.name)) {\n const value = text.ok ? text.value[field.name] : record[field.name];\n if (typeof value === \"string\" && (field.name === \"heading\" || field.name === \"intro\")) data[field.name] = value.trim();\n }\n }\n const layout = Object.hasOwn(record, \"layout\") ? record.layout : undefined;\n const warnings: (typeof SITE_HERO_LAYOUT_WARNING)[] = [];\n if (isLayout(layout)) data.layout = layout;\n else {\n data.layout = \"columns\";\n fallbackFields.push(\"layout\");\n warnings.push(SITE_HERO_LAYOUT_WARNING);\n }\n const taglines = validateSiteHeroTaglines(Object.hasOwn(record, \"taglines\") ? record.taglines : undefined);\n if (taglines.ok) data.taglines = taglines.value;\n else fallbackFields.push(\"taglines\");\n return { data, fallbackFields: fallbackFields.length === SITE_HERO.fields.length + 2 ? [\"$\"] : fallbackFields,\n ...(warnings.length > 0 ? { warnings } : {}) };\n}\n\nexport function siteHeroQuery(): CmsQuery<SiteHero> {\n return defineCmsQuery<SiteHero>({\n name: \"siteHero.v1\", query: '*[_id == $id && _type == \"siteHero\"][0]{heading,intro,layout,taglines}',\n params: { id: \"siteHero\" }, dependencies: { types: [\"siteHero\"], ids: [\"siteHero\"] },\n resolve: parseSiteHero,\n });\n}\n"],
|
|
5
|
+
"mappings": "AACO,SAASA,EAAaC,EAAoC,CAC/D,GAAI,CAAC,MAAM,QAAQA,CAAK,EAAG,MAAO,GAClC,QAASC,EAAQ,EAAGA,EAAQD,EAAM,OAAQC,GAAS,EACjD,GAAI,CAAC,OAAO,OAAOD,EAAOC,CAAK,EAAG,MAAO,GAE3C,MAAO,EACT,CCYA,IAAMC,GAAO,+BACPC,GAAK,qCAGX,SAASC,GAAiBC,EAAgD,CACxE,GAAI,CAACA,GAAgB,CAAC,MAAM,QAAQA,EAAa,KAAK,GAAKA,EAAa,MAAM,SAAW,EACvF,MAAM,IAAI,UAAU,yCAAyC,EAE/D,IAAMC,EAAQ,CAAC,GAAGD,EAAa,KAAK,EACpC,QAAWE,KAAQD,EACjB,GAAI,OAAOC,GAAS,UAAY,CAACC,GAAK,KAAKD,CAAI,EAAG,MAAM,IAAI,UAAU,2BAA2B,EAEnG,GAAIF,EAAa,MAAQ,QAAa,CAAC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AO,OAAS,OAC3DW,EAAgD,CAAC,EACnDT,GAASE,CAAM,EAAGK,EAAK,OAASL,GAElCK,EAAK,OAAS,UACdC,EAAe,KAAK,QAAQ,EAC5BC,EAAS,KAAKC,EAAwB,GAExC,IAAMC,EAAWlB,EAAyB,OAAO,OAAOK,EAAQ,UAAU,EAAIA,EAAO,SAAW,MAAS,EACzG,OAAIa,EAAS,GAAIJ,EAAK,SAAWI,EAAS,MACrCH,EAAe,KAAK,UAAU,EAC5B,CAAE,KAAAD,EAAM,eAAgBC,EAAe,SAAW7B,EAAU,OAAO,OAAS,EAAI,CAAC,GAAG,EAAI6B,EAC7F,GAAIC,EAAS,OAAS,EAAI,CAAE,SAAAA,CAAS,EAAI,CAAC,CAAG,CACjD,CAEO,SAASG,IAAoC,CAClD,OAAOC,EAAyB,CAC9B,KAAM,cAAe,MAAO,yEAC5B,OAAQ,CAAE,GAAI,UAAW,EAAG,aAAc,CAAE,MAAO,CAAC,UAAU,EAAG,IAAK,CAAC,UAAU,CAAE,EACnF,QAASV,EACX,CAAC,CACH",
|
|
6
|
+
"names": ["isDenseArray", "value", "index", "TYPE", "ID", "dependenciesCopy", "dependencies", "types", "type", "TYPE", "ids", "id", "ID", "defineCmsQuery", "query", "params", "copied", "key", "descriptor", "value", "object", "value", "words", "nullableText", "photo", "READER_PHOTO_SLUG", "href", "READER_ACTION_HREF", "copy", "optionalCopy", "action", "optionalAction", "composition", "isDenseArray", "hero", "block", "image", "READER_JUMP_LINK", "item", "READER_STORY_LAYOUTS", "layout", "model", "anchors", "link", "proposed", "line", "validHomeFallback", "validPageFallback", "validSettingsFallback", "MALFORMED_CONTENT", "MalformedContentError", "documentId", "problems", "READER_PHOTO_SLUG", "READER_ACTION_HREF", "READER_JUMP_LINK", "READER_STORY_LAYOUTS", "READER_HOME_PAGE_ID", "READER_SITE_SETTINGS_ID", "Reading", "path", "message", "value", "isDenseArray", "raw", "text", "source", "copy", "p", "max", "entry", "index", "label", "href", "plain", "portableTextToMarkdown", "reading", "markdown", "richTextToMarkdown", "out", "previousWasList", "member", "at", "block", "spansToMarkdown", "listItem", "style", "line", "level", "isList", "DECORATORS", "links", "markDefs", "def", "d", "children", "child", "span", "marks", "mark", "fence", "campaignState", "campaign", "now", "c", "starts", "ends", "keyed", "parseHomePage", "document", "options", "doc", "id", "hero", "rawHero", "photos", "heading", "subline", "intro", "cta", "secondaryCta", "blocks", "blockJumps", "body", "state", "title", "images", "action", "anchors", "rawBlocks", "mapped", "mapBlock", "buttonsOf", "jumps", "where", "stories", "item", "tail", "items", "story", "sat", "sHeading", "sBody", "image", "layout", "onCard", "jump", "anchor", "parseContentPage", "slugObject", "slug", "lead", "photo", "parseSiteSettings", "name", "description", "contact", "email", "phone", "social", "rawSocial", "link", "network", "url", "HOME_PAGE_DOCUMENT_QUERY", "CONTENT_PAGES_QUERY", "CONTENT_PAGE_BY_SLUG_QUERY", "createSiteContentReader", "client", "docs", "atomic", "fallback", "parse", "validFallback", "homeContentQuery", "captured", "defineCmsQuery", "validHomeFallback", "contentPageQuery", "validPageFallback", "contentPagesQuery", "page", "siteSettingsQuery", "validSettingsFallback", "SITE_HERO_LAYOUTS", "SITE_HERO_TAGLINE_MAX_LENGTH", "SITE_HERO_LAYOUT_WARNING", "SITE_HERO", "fieldError", "field", "text", "article", "word", "count", "validateTextDocument", "definition", "raw", "value", "errors", "submitted", "error", "validateSiteHeroTaglines", "heading", "SITE_HERO_TAGLINE_MAX_LENGTH", "keys", "item", "record", "key", "isLayout", "SITE_HERO_LAYOUTS", "layout", "parseSiteHero", "fallback", "local", "localTaglines", "data", "fallbackFields", "warnings", "SITE_HERO_LAYOUT_WARNING", "taglines", "siteHeroQuery", "defineCmsQuery"]
|
|
7
|
+
}
|
package/dist/testing.cjs
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";var p=Object.create;var o=Object.defineProperty;var g=Object.getOwnPropertyDescriptor;var y=Object.getOwnPropertyNames;var f=Object.getPrototypeOf,C=Object.prototype.hasOwnProperty;var x=(t,r)=>{for(var a in r)o(t,a,{get:r[a],enumerable:!0})},d=(t,r,a,e)=>{if(r&&typeof r=="object"||typeof r=="function")for(let s of y(r))!C.call(t,s)&&s!==a&&o(t,s,{get:()=>r[s],enumerable:!(e=g(r,s))||e.enumerable});return t};var S=(t,r,a)=>(a=t!=null?p(f(t)):{},d(r||!t||!t.__esModule?o(a,"default",{value:t,enumerable:!0}):a,t)),q=t=>d(o({},"__esModule",{value:!0}),t);var v={};x(v,{assertCmsReadContract:()=>u});module.exports=q(v);var n=S(require("node:assert/strict"),1);async function u(t){(0,n.default)(Array.isArray(t.cases)&&t.cases.length>0,"CMS contract requires at least one case");let r=t.revalidateSeconds??3600;(0,n.default)(Number.isInteger(r)&&r>=3600,"CMS contract requires an integer interval of at least 3600 seconds");let a=new Set;for(let e of t.cases){(0,n.default)(e&&typeof e.name=="string"&&e.name.trim()&&!a.has(e.name),"CMS contract requires unique named cases"),a.add(e.name),n.default.equal(typeof e.exercise,"function","CMS contract requires an exercise"),(0,n.default)(Array.isArray(e.expectedTags)&&e.expectedTags.length>0&&e.expectedTags.every(s=>typeof s=="string"&&s.length>0)&&new Set(e.expectedTags).size===e.expectedTags.length,"CMS contract requires nonempty unique expected tags");for(let s of[!1,!0]){let i=0,m=[],l=async(T,c)=>{i++;try{n.default.deepEqual(c?.next?.tags,e.expectedTags,`${e.name}: every fetch must carry exactly the expected tags`),n.default.equal(c?.next?.revalidate,r,`${e.name}: every fetch must carry the expected interval`),(0,n.default)(c.cache!=="no-store"&&c.cache!=="no-cache",`${e.name}: fetch must retain caching`),(0,n.default)(c.method===void 0||c.method==="GET",`${e.name}: read must use GET`)}catch(h){m.push(h)}return s?new Response(null,{status:503}):Response.json({result:{heading:"CMS contract heading",intro:"CMS contract intro"}})};if(await e.exercise(l),(0,n.default)(i>0,`${e.name}: ${s?"failure":"published"} exercise must fetch`),m.length)throw m[0]}}}0&&(module.exports={assertCmsReadContract});
|
|
2
|
+
//# sourceMappingURL=testing.cjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/testing.ts", "../src/tooling/testing.ts"],
|
|
4
|
+
"sourcesContent": ["export { assertCmsReadContract } from \"./tooling/testing.js\";\nexport type { CmsContractCase } from \"./tooling/testing.js\";\n", "import assert from \"node:assert/strict\";\nimport type { CmsFetch } from \"../runtime/reader.js\";\n\nexport type CmsContractCase = {\n readonly name: string;\n readonly exercise: (fetchImpl: CmsFetch) => Promise<unknown>;\n readonly expectedTags: readonly string[];\n};\n\nexport async function assertCmsReadContract(options: {\n cases: readonly CmsContractCase[];\n revalidateSeconds?: number;\n}): Promise<void> {\n assert(Array.isArray(options.cases) && options.cases.length > 0, \"CMS contract requires at least one case\");\n const interval = options.revalidateSeconds ?? 3600;\n assert(Number.isInteger(interval) && interval >= 3600, \"CMS contract requires an integer interval of at least 3600 seconds\");\n const names = new Set<string>();\n for (const entry of options.cases) {\n assert(entry && typeof entry.name === \"string\" && entry.name.trim() && !names.has(entry.name), \"CMS contract requires unique named cases\");\n names.add(entry.name);\n assert.equal(typeof entry.exercise, \"function\", \"CMS contract requires an exercise\");\n assert(Array.isArray(entry.expectedTags) && entry.expectedTags.length > 0\n && entry.expectedTags.every((tag: unknown) => typeof tag === \"string\" && tag.length > 0)\n && new Set(entry.expectedTags).size === entry.expectedTags.length, \"CMS contract requires nonempty unique expected tags\");\n for (const failure of [false, true]) {\n let calls = 0;\n const errors: unknown[] = [];\n const fetchImpl: CmsFetch = async (_url, init) => {\n calls++;\n try {\n assert.deepEqual(init?.next?.tags, entry.expectedTags, `${entry.name}: every fetch must carry exactly the expected tags`);\n assert.equal(init?.next?.revalidate, interval, `${entry.name}: every fetch must carry the expected interval`);\n assert(init.cache !== \"no-store\" && init.cache !== \"no-cache\", `${entry.name}: fetch must retain caching`);\n assert(init.method === undefined || init.method === \"GET\", `${entry.name}: read must use GET`);\n } catch (error) {\n // A production reader can catch fetch errors and fall back. Preserve\n // assertion failures out of band so that catch cannot turn a pass green.\n errors.push(error);\n }\n return failure ? new Response(null, { status: 503 })\n : Response.json({ result: { heading: \"CMS contract heading\", intro: \"CMS contract intro\" } });\n };\n // The consumer owns model/render assertions, including valid local fallback.\n // Custom models can adapt this scripted envelope inside their exercise.\n await entry.exercise(fetchImpl);\n assert(calls > 0, `${entry.name}: ${failure ? \"failure\" : \"published\"} exercise must fetch`);\n if (errors.length) throw errors[0];\n }\n }\n}\n"],
|
|
5
|
+
"mappings": "0jBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,2BAAAE,IAAA,eAAAC,EAAAH,GCAA,IAAAI,EAAmB,mCASnB,eAAsBC,EAAsBC,EAG1B,IAChB,EAAAC,SAAO,MAAM,QAAQD,EAAQ,KAAK,GAAKA,EAAQ,MAAM,OAAS,EAAG,yCAAyC,EAC1G,IAAME,EAAWF,EAAQ,mBAAqB,QAC9C,EAAAC,SAAO,OAAO,UAAUC,CAAQ,GAAKA,GAAY,KAAM,oEAAoE,EAC3H,IAAMC,EAAQ,IAAI,IAClB,QAAWC,KAASJ,EAAQ,MAAO,IACjC,EAAAC,SAAOG,GAAS,OAAOA,EAAM,MAAS,UAAYA,EAAM,KAAK,KAAK,GAAK,CAACD,EAAM,IAAIC,EAAM,IAAI,EAAG,0CAA0C,EACzID,EAAM,IAAIC,EAAM,IAAI,EACpB,EAAAH,QAAO,MAAM,OAAOG,EAAM,SAAU,WAAY,mCAAmC,KACnF,EAAAH,SAAO,MAAM,QAAQG,EAAM,YAAY,GAAKA,EAAM,aAAa,OAAS,GACnEA,EAAM,aAAa,MAAOC,GAAiB,OAAOA,GAAQ,UAAYA,EAAI,OAAS,CAAC,GACpF,IAAI,IAAID,EAAM,YAAY,EAAE,OAASA,EAAM,aAAa,OAAQ,qDAAqD,EAC1H,QAAWE,IAAW,CAAC,GAAO,EAAI,EAAG,CACnC,IAAIC,EAAQ,EACNC,EAAoB,CAAC,EACrBC,EAAsB,MAAOC,EAAMC,IAAS,CAChDJ,IACA,GAAI,CACF,EAAAN,QAAO,UAAUU,GAAM,MAAM,KAAMP,EAAM,aAAc,GAAGA,EAAM,IAAI,oDAAoD,EACxH,EAAAH,QAAO,MAAMU,GAAM,MAAM,WAAYT,EAAU,GAAGE,EAAM,IAAI,gDAAgD,KAC5G,EAAAH,SAAOU,EAAK,QAAU,YAAcA,EAAK,QAAU,WAAY,GAAGP,EAAM,IAAI,6BAA6B,KACzG,EAAAH,SAAOU,EAAK,SAAW,QAAaA,EAAK,SAAW,MAAO,GAAGP,EAAM,IAAI,qBAAqB,CAC/F,OAASQ,EAAO,CAGdJ,EAAO,KAAKI,CAAK,CACnB,CACA,OAAON,EAAU,IAAI,SAAS,KAAM,CAAE,OAAQ,GAAI,CAAC,EAC/C,SAAS,KAAK,CAAE,OAAQ,CAAE,QAAS,uBAAwB,MAAO,oBAAqB,CAAE,CAAC,CAChG,EAKA,GAFA,MAAMF,EAAM,SAASK,CAAS,KAC9B,EAAAR,SAAOM,EAAQ,EAAG,GAAGH,EAAM,IAAI,KAAKE,EAAU,UAAY,WAAW,sBAAsB,EACvFE,EAAO,OAAQ,MAAMA,EAAO,CAAC,CACnC,CACF,CACF",
|
|
6
|
+
"names": ["testing_exports", "__export", "assertCmsReadContract", "__toCommonJS", "import_strict", "assertCmsReadContract", "options", "assert", "interval", "names", "entry", "tag", "failure", "calls", "errors", "fetchImpl", "_url", "init", "error"]
|
|
7
|
+
}
|
package/dist/testing.mjs
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import t from"node:assert/strict";async function u(s){t(Array.isArray(s.cases)&&s.cases.length>0,"CMS contract requires at least one case");let n=s.revalidateSeconds??3600;t(Number.isInteger(n)&&n>=3600,"CMS contract requires an integer interval of at least 3600 seconds");let o=new Set;for(let e of s.cases){t(e&&typeof e.name=="string"&&e.name.trim()&&!o.has(e.name),"CMS contract requires unique named cases"),o.add(e.name),t.equal(typeof e.exercise,"function","CMS contract requires an exercise"),t(Array.isArray(e.expectedTags)&&e.expectedTags.length>0&&e.expectedTags.every(a=>typeof a=="string"&&a.length>0)&&new Set(e.expectedTags).size===e.expectedTags.length,"CMS contract requires nonempty unique expected tags");for(let a of[!1,!0]){let m=0,c=[],i=async(l,r)=>{m++;try{t.deepEqual(r?.next?.tags,e.expectedTags,`${e.name}: every fetch must carry exactly the expected tags`),t.equal(r?.next?.revalidate,n,`${e.name}: every fetch must carry the expected interval`),t(r.cache!=="no-store"&&r.cache!=="no-cache",`${e.name}: fetch must retain caching`),t(r.method===void 0||r.method==="GET",`${e.name}: read must use GET`)}catch(d){c.push(d)}return a?new Response(null,{status:503}):Response.json({result:{heading:"CMS contract heading",intro:"CMS contract intro"}})};if(await e.exercise(i),t(m>0,`${e.name}: ${a?"failure":"published"} exercise must fetch`),c.length)throw c[0]}}}export{u as assertCmsReadContract};
|
|
2
|
+
//# sourceMappingURL=testing.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/tooling/testing.ts"],
|
|
4
|
+
"sourcesContent": ["import assert from \"node:assert/strict\";\nimport type { CmsFetch } from \"../runtime/reader.js\";\n\nexport type CmsContractCase = {\n readonly name: string;\n readonly exercise: (fetchImpl: CmsFetch) => Promise<unknown>;\n readonly expectedTags: readonly string[];\n};\n\nexport async function assertCmsReadContract(options: {\n cases: readonly CmsContractCase[];\n revalidateSeconds?: number;\n}): Promise<void> {\n assert(Array.isArray(options.cases) && options.cases.length > 0, \"CMS contract requires at least one case\");\n const interval = options.revalidateSeconds ?? 3600;\n assert(Number.isInteger(interval) && interval >= 3600, \"CMS contract requires an integer interval of at least 3600 seconds\");\n const names = new Set<string>();\n for (const entry of options.cases) {\n assert(entry && typeof entry.name === \"string\" && entry.name.trim() && !names.has(entry.name), \"CMS contract requires unique named cases\");\n names.add(entry.name);\n assert.equal(typeof entry.exercise, \"function\", \"CMS contract requires an exercise\");\n assert(Array.isArray(entry.expectedTags) && entry.expectedTags.length > 0\n && entry.expectedTags.every((tag: unknown) => typeof tag === \"string\" && tag.length > 0)\n && new Set(entry.expectedTags).size === entry.expectedTags.length, \"CMS contract requires nonempty unique expected tags\");\n for (const failure of [false, true]) {\n let calls = 0;\n const errors: unknown[] = [];\n const fetchImpl: CmsFetch = async (_url, init) => {\n calls++;\n try {\n assert.deepEqual(init?.next?.tags, entry.expectedTags, `${entry.name}: every fetch must carry exactly the expected tags`);\n assert.equal(init?.next?.revalidate, interval, `${entry.name}: every fetch must carry the expected interval`);\n assert(init.cache !== \"no-store\" && init.cache !== \"no-cache\", `${entry.name}: fetch must retain caching`);\n assert(init.method === undefined || init.method === \"GET\", `${entry.name}: read must use GET`);\n } catch (error) {\n // A production reader can catch fetch errors and fall back. Preserve\n // assertion failures out of band so that catch cannot turn a pass green.\n errors.push(error);\n }\n return failure ? new Response(null, { status: 503 })\n : Response.json({ result: { heading: \"CMS contract heading\", intro: \"CMS contract intro\" } });\n };\n // The consumer owns model/render assertions, including valid local fallback.\n // Custom models can adapt this scripted envelope inside their exercise.\n await entry.exercise(fetchImpl);\n assert(calls > 0, `${entry.name}: ${failure ? \"failure\" : \"published\"} exercise must fetch`);\n if (errors.length) throw errors[0];\n }\n }\n}\n"],
|
|
5
|
+
"mappings": "AAAA,OAAOA,MAAY,qBASnB,eAAsBC,EAAsBC,EAG1B,CAChBF,EAAO,MAAM,QAAQE,EAAQ,KAAK,GAAKA,EAAQ,MAAM,OAAS,EAAG,yCAAyC,EAC1G,IAAMC,EAAWD,EAAQ,mBAAqB,KAC9CF,EAAO,OAAO,UAAUG,CAAQ,GAAKA,GAAY,KAAM,oEAAoE,EAC3H,IAAMC,EAAQ,IAAI,IAClB,QAAWC,KAASH,EAAQ,MAAO,CACjCF,EAAOK,GAAS,OAAOA,EAAM,MAAS,UAAYA,EAAM,KAAK,KAAK,GAAK,CAACD,EAAM,IAAIC,EAAM,IAAI,EAAG,0CAA0C,EACzID,EAAM,IAAIC,EAAM,IAAI,EACpBL,EAAO,MAAM,OAAOK,EAAM,SAAU,WAAY,mCAAmC,EACnFL,EAAO,MAAM,QAAQK,EAAM,YAAY,GAAKA,EAAM,aAAa,OAAS,GACnEA,EAAM,aAAa,MAAOC,GAAiB,OAAOA,GAAQ,UAAYA,EAAI,OAAS,CAAC,GACpF,IAAI,IAAID,EAAM,YAAY,EAAE,OAASA,EAAM,aAAa,OAAQ,qDAAqD,EAC1H,QAAWE,IAAW,CAAC,GAAO,EAAI,EAAG,CACnC,IAAIC,EAAQ,EACNC,EAAoB,CAAC,EACrBC,EAAsB,MAAOC,EAAMC,IAAS,CAChDJ,IACA,GAAI,CACFR,EAAO,UAAUY,GAAM,MAAM,KAAMP,EAAM,aAAc,GAAGA,EAAM,IAAI,oDAAoD,EACxHL,EAAO,MAAMY,GAAM,MAAM,WAAYT,EAAU,GAAGE,EAAM,IAAI,gDAAgD,EAC5GL,EAAOY,EAAK,QAAU,YAAcA,EAAK,QAAU,WAAY,GAAGP,EAAM,IAAI,6BAA6B,EACzGL,EAAOY,EAAK,SAAW,QAAaA,EAAK,SAAW,MAAO,GAAGP,EAAM,IAAI,qBAAqB,CAC/F,OAASQ,EAAO,CAGdJ,EAAO,KAAKI,CAAK,CACnB,CACA,OAAON,EAAU,IAAI,SAAS,KAAM,CAAE,OAAQ,GAAI,CAAC,EAC/C,SAAS,KAAK,CAAE,OAAQ,CAAE,QAAS,uBAAwB,MAAO,oBAAqB,CAAE,CAAC,CAChG,EAKA,GAFA,MAAMF,EAAM,SAASK,CAAS,EAC9BV,EAAOQ,EAAQ,EAAG,GAAGH,EAAM,IAAI,KAAKE,EAAU,UAAY,WAAW,sBAAsB,EACvFE,EAAO,OAAQ,MAAMA,EAAO,CAAC,CACnC,CACF,CACF",
|
|
6
|
+
"names": ["assert", "assertCmsReadContract", "options", "interval", "names", "entry", "tag", "failure", "calls", "errors", "fetchImpl", "_url", "init", "error"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export type CmsSourceFile = {
|
|
2
|
+
readonly path: string;
|
|
3
|
+
readonly text: string;
|
|
4
|
+
};
|
|
5
|
+
export type CmsGuardViolation = {
|
|
6
|
+
readonly path: string;
|
|
7
|
+
readonly line: number;
|
|
8
|
+
readonly rule: string;
|
|
9
|
+
};
|
|
10
|
+
export declare function findCmsBoundaryViolations(options: {
|
|
11
|
+
files: readonly CmsSourceFile[];
|
|
12
|
+
allowedProviderFiles?: readonly string[];
|
|
13
|
+
}): readonly CmsGuardViolation[];
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export type CmsSourceFile = {
|
|
2
|
+
readonly path: string;
|
|
3
|
+
readonly text: string;
|
|
4
|
+
};
|
|
5
|
+
export type CmsGuardViolation = {
|
|
6
|
+
readonly path: string;
|
|
7
|
+
readonly line: number;
|
|
8
|
+
readonly rule: string;
|
|
9
|
+
};
|
|
10
|
+
export declare function findCmsBoundaryViolations(options: {
|
|
11
|
+
files: readonly CmsSourceFile[];
|
|
12
|
+
allowedProviderFiles?: readonly string[];
|
|
13
|
+
}): readonly CmsGuardViolation[];
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export type CmsSourceFile = {
|
|
2
|
+
readonly path: string;
|
|
3
|
+
readonly text: string;
|
|
4
|
+
};
|
|
5
|
+
export type CmsGuardViolation = {
|
|
6
|
+
readonly path: string;
|
|
7
|
+
readonly line: number;
|
|
8
|
+
readonly rule: string;
|
|
9
|
+
};
|
|
10
|
+
export declare function findCmsBoundaryViolations(options: {
|
|
11
|
+
files: readonly CmsSourceFile[];
|
|
12
|
+
allowedProviderFiles?: readonly string[];
|
|
13
|
+
}): readonly CmsGuardViolation[];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { CmsContractCase } from "@weatherboard/cms/testing";
|
|
2
|
+
import type { CmsFetch } from "@weatherboard/cms/server";
|
|
3
|
+
export declare const fallback: {
|
|
4
|
+
heading: string;
|
|
5
|
+
intro: string;
|
|
6
|
+
};
|
|
7
|
+
export declare const expectedTags: readonly string[];
|
|
8
|
+
export declare function renderHero(fetchImpl: CmsFetch): Promise<string>;
|
|
9
|
+
export declare const heroCase: CmsContractCase;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { CmsContractCase } from "@weatherboard/cms/testing";
|
|
2
|
+
import type { CmsFetch } from "@weatherboard/cms/server";
|
|
3
|
+
export declare const fallback: {
|
|
4
|
+
heading: string;
|
|
5
|
+
intro: string;
|
|
6
|
+
};
|
|
7
|
+
export declare const expectedTags: readonly string[];
|
|
8
|
+
export declare function renderHero(fetchImpl: CmsFetch): Promise<string>;
|
|
9
|
+
export declare const heroCase: CmsContractCase;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { CmsContractCase } from "@weatherboard/cms/testing";
|
|
2
|
+
import type { CmsFetch } from "@weatherboard/cms/server";
|
|
3
|
+
export declare const fallback: {
|
|
4
|
+
heading: string;
|
|
5
|
+
intro: string;
|
|
6
|
+
};
|
|
7
|
+
export declare const expectedTags: readonly string[];
|
|
8
|
+
export declare function renderHero(fetchImpl: CmsFetch): Promise<string>;
|
|
9
|
+
export declare const heroCase: CmsContractCase;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { CmsFetch } from "../runtime/reader.cjs";
|
|
2
|
+
export type CmsContractCase = {
|
|
3
|
+
readonly name: string;
|
|
4
|
+
readonly exercise: (fetchImpl: CmsFetch) => Promise<unknown>;
|
|
5
|
+
readonly expectedTags: readonly string[];
|
|
6
|
+
};
|
|
7
|
+
export declare function assertCmsReadContract(options: {
|
|
8
|
+
cases: readonly CmsContractCase[];
|
|
9
|
+
revalidateSeconds?: number;
|
|
10
|
+
}): Promise<void>;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { CmsFetch } from "../runtime/reader.mjs";
|
|
2
|
+
export type CmsContractCase = {
|
|
3
|
+
readonly name: string;
|
|
4
|
+
readonly exercise: (fetchImpl: CmsFetch) => Promise<unknown>;
|
|
5
|
+
readonly expectedTags: readonly string[];
|
|
6
|
+
};
|
|
7
|
+
export declare function assertCmsReadContract(options: {
|
|
8
|
+
cases: readonly CmsContractCase[];
|
|
9
|
+
revalidateSeconds?: number;
|
|
10
|
+
}): Promise<void>;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { CmsFetch } from "../runtime/reader.js";
|
|
2
|
+
export type CmsContractCase = {
|
|
3
|
+
readonly name: string;
|
|
4
|
+
readonly exercise: (fetchImpl: CmsFetch) => Promise<unknown>;
|
|
5
|
+
readonly expectedTags: readonly string[];
|
|
6
|
+
};
|
|
7
|
+
export declare function assertCmsReadContract(options: {
|
|
8
|
+
cases: readonly CmsContractCase[];
|
|
9
|
+
revalidateSeconds?: number;
|
|
10
|
+
}): Promise<void>;
|
package/dist/webhook.cjs
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";var i=Object.defineProperty;var M=Object.getOwnPropertyDescriptor;var h=Object.getOwnPropertyNames;var k=Object.prototype.hasOwnProperty;var p=(e,t)=>{for(var n in t)i(e,n,{get:t[n],enumerable:!0})},E=(e,t,n,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of h(t))!k.call(e,r)&&r!==n&&i(e,r,{get:()=>t[r],enumerable:!(o=M(t,r))||o.enumerable});return e};var _=e=>E(i({},"__esModule",{value:!0}),e);var w={};p(w,{DEFAULT_TOLERANCE_MS:()=>m,MINIMUM_TIMESTAMP:()=>f,SANITY_SIGNATURE_HEADER:()=>c,verifySanityWebhook:()=>d});module.exports=_(w);var c="sanity-webhook-signature",T=/^t=(\d+)[, ]+v1=([^, ]+)$/,f=16094592e5,m=3e5,y=new TextEncoder;function I(e){return crypto.subtle.importKey("raw",y.encode(e),{name:"HMAC",hash:"SHA-256"},!1,["sign","verify"])}function S(e){if(!/^[A-Za-z0-9_-]+={0,2}$/.test(e))return null;let t=e.replace(/-/g,"+").replace(/_/g,"/");try{let n=atob(t),o=new Uint8Array(n.length);for(let r=0;r<n.length;r+=1)o[r]=n.charCodeAt(r);return o}catch{return null}}async function d(e){let{secret:t,rawBody:n,headers:o}=e,r=e.now??Date.now(),g=e.toleranceMs??3e5;if(!t||t.length===0)return{ok:!1,reason:"no-secret"};let l=o.get(c);if(!l)return{ok:!1,reason:"no-signature"};let s=T.exec(l.trim());if(s===null)return{ok:!1,reason:"malformed-signature"};let a=Number(s[1]),A=s[2]??"";if(!Number.isSafeInteger(a))return{ok:!1,reason:"malformed-signature"};if(a<16094592e5)return{ok:!1,reason:"stale-timestamp"};if(Math.abs(r-a)>g)return{ok:!1,reason:"stale-timestamp"};let u=S(A);if(u===null)return{ok:!1,reason:"malformed-signature"};let b=await I(t);return await crypto.subtle.verify("HMAC",b,u,y.encode(`${a}.${n}`))?{ok:!0}:{ok:!1,reason:"bad-signature"}}0&&(module.exports={DEFAULT_TOLERANCE_MS,MINIMUM_TIMESTAMP,SANITY_SIGNATURE_HEADER,verifySanityWebhook});
|
|
2
|
+
//# sourceMappingURL=webhook.cjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/webhook.ts", "../src/portable/webhook.ts"],
|
|
4
|
+
"sourcesContent": ["export {\n SANITY_SIGNATURE_HEADER, DEFAULT_TOLERANCE_MS, MINIMUM_TIMESTAMP, verifySanityWebhook,\n} from \"./portable/webhook.js\";\nexport type { WebhookRejection, WebhookVerification } from \"./portable/webhook.js\";\n", "/**\n * Verifying a Sanity webhook (A-590 step 1, A-592's `SANITY_WEBHOOK_SECRET`).\n *\n * -------------------------------------------------------------------------\n * WHY THIS ENDPOINT NEEDS A SIGNATURE AT ALL\n * -------------------------------------------------------------------------\n *\n * `/revalidate` throws away cache entries. A-590: \"An unauthenticated\n * revalidation endpoint is a free cache-purge and rebuild trigger for anyone\n * who finds the URL.\" On a plan whose API request allowance is a HARD cap that\n * returns 402 rather than a bill, an attacker who can empty the cache at will\n * can take a client's site content-offline for the rest of the month. So the\n * signature is not hygiene here; it is the availability control.\n *\n * -------------------------------------------------------------------------\n * THE WIRE FORMAT IS MEASURED, NOT REMEMBERED\n * -------------------------------------------------------------------------\n *\n * Read on 2026-09-16 from Sanity's own toolkit,\n * `https://raw.githubusercontent.com/sanity-io/webhook-toolkit/main/src/signature.ts`:\n *\n * header `sanity-webhook-signature`\n * value `t=<millis>,v1=<signature>` (regex `/^t=(\\d+)[, ]+v1=([^, ]+)$/`)\n * signed payload `` `${timestamp}.${body}` ``\n * algorithm HMAC-SHA256\n * digest encoding base64url \u2014 standard base64 with `+`\u2192`-`, `/`\u2192`_`, padding stripped\n * MINIMUM_TIMESTAMP 1609459200000 (2021-01-01Z), below which a value is nonsense\n *\n * `signature.test.ts` does not take that paragraph's word for it either: it\n * signs a payload with `@sanity/webhook`'s own `encodeSignatureHeader` and\n * asserts this verifier accepts it. If Sanity changes the format, that test\n * goes red rather than production quietly rejecting every webhook.\n *\n * -------------------------------------------------------------------------\n * WHAT THIS ADDS TO THE TOOLKIT, AND WHY IT IS NOT JUST IMPORTED\n * -------------------------------------------------------------------------\n *\n * Two things, both of which are `CLAUDE.md`'s \"take the safer construction\".\n *\n * First, a REPLAY WINDOW. The toolkit enforces only that the timestamp is after\n * 2021; a captured webhook is otherwise replayable forever. A replayed purge is\n * the attack in the first paragraph, executed with a request somebody was\n * legitimately sent. `verifySanityWebhook` takes a symmetric tolerance \u2014 the\n * window is symmetric for A-44's reason, since a far-future timestamp is\n * precisely how you mint a request that stays replayable for a year.\n *\n * Second, a MISSING SECRET IS A REJECTION, never a bypass. A-590 says it in as\n * many words: \"reject on absence rather than skipping the check when the secret\n * is unset.\" The degraded mode of \"no secret configured, so allow it\" is\n * produced by a deploy that forgot `wrangler secret put`, announces itself\n * nowhere, and grants strangers the purge endpoint.\n *\n * The comparison is `crypto.subtle.verify`, which compares raw digests in\n * constant time. A `===` on the base64 strings short-circuits at the first\n * differing character, which turns one 2^256 search into a few dozen sequential\n * 64-way ones against an endpoint that answers in milliseconds.\n *\n * -------------------------------------------------------------------------\n * `encodeSignatureHeader` IS ASYNC. AWAIT IT. (A-651)\n * -------------------------------------------------------------------------\n *\n * `@sanity/webhook@4.0.4` declares\n *\n * encodeSignatureHeader(payload: string, timestamp: number, secret: string):\n * Promise<string>\n *\n * and nothing forces you to await it. Drop the `await` and the Promise is\n * stringified into the header as the literal `[object Promise]`, which arrives\n * here, fails `SIGNATURE_VALUE`, and is rejected as `malformed-signature`. The\n * rejection is correct and the message is about the wire format, so it sends\n * you to read Sanity's header spec \u2014 the one place the bug is not. TypeScript\n * does not save you either: the value usually lands in a `Record<string,\n * string>` built by a helper, or inside a template literal, both of which take\n * a Promise without complaint.\n *\n * The rule: every call to `encodeSignatureHeader` is awaited, and the helper\n * that wraps it is `async` rather than returning the Promise for someone else\n * to forget. The content-client compatibility tests and CMS signer tests await every\n * encoder call; this note exists so the next one\n * is too, because the symptom will not tell you.\n */\n\n/** Sanity's header. Lower-cased; `Headers.get` is case-insensitive either way. */\nexport const SANITY_SIGNATURE_HEADER = \"sanity-webhook-signature\";\n\n/** Sanity's own parser, character for character. See the header. */\nconst SIGNATURE_VALUE = /^t=(\\d+)[, ]+v1=([^, ]+)$/;\n\n/** 2021-01-01T00:00:00.000Z. Sanity's `MINIMUM_TIMESTAMP`; anything earlier is not a timestamp. */\nexport const MINIMUM_TIMESTAMP = 1_609_459_200_000;\n\n/**\n * How far from `now` a webhook timestamp may be, in milliseconds.\n *\n * Five minutes rather than A-44's sixty seconds: this one crosses Sanity's\n * delivery queue rather than two NTP-synced clouds, and a retried delivery is a\n * normal event. It is still a window rather than \"forever\", which is the whole\n * difference from the toolkit.\n */\nexport const DEFAULT_TOLERANCE_MS = 300_000;\n\nexport type WebhookRejection =\n /** `SANITY_WEBHOOK_SECRET` is unset or empty. Fail closed. */\n | \"no-secret\"\n /** No `sanity-webhook-signature` header. */\n | \"no-signature\"\n /** Header present but not `t=\u2026,v1=\u2026`, or `v1` is not decodable base64url. */\n | \"malformed-signature\"\n /** Before 2021, or outside the tolerance in either direction. */\n | \"stale-timestamp\"\n /** Well-formed, in window, wrong. */\n | \"bad-signature\";\n\nexport type WebhookVerification = { ok: true } | { ok: false; reason: WebhookRejection };\n\nconst encoder = new TextEncoder();\n\nfunction hmacKey(secret: string): Promise<CryptoKey> {\n return crypto.subtle.importKey(\n \"raw\",\n encoder.encode(secret),\n { name: \"HMAC\", hash: \"SHA-256\" },\n false,\n [\"sign\", \"verify\"],\n );\n}\n\n/**\n * base64url \u2192 bytes, without `Buffer`.\n *\n * `atob` rather than `node:crypto` or `Buffer` because this file is imported by\n * the Worker, and workerd has neither by default. Returns null rather than\n * throwing on rubbish, so a malformed header is a 401 and not a 500 \u2014 a\n * verifier that crashes on bad input is a verifier an attacker can use as a\n * denial of service.\n */\nfunction base64UrlToBytes(value: string): Uint8Array<ArrayBuffer> | null {\n if (!/^[A-Za-z0-9_-]+={0,2}$/.test(value)) return null;\n const padded = value.replace(/-/g, \"+\").replace(/_/g, \"/\");\n try {\n const binary = atob(padded);\n const bytes = new Uint8Array(binary.length);\n for (let i = 0; i < binary.length; i += 1) bytes[i] = binary.charCodeAt(i);\n return bytes;\n } catch {\n return null;\n }\n}\n\n/**\n * Verify a Sanity webhook delivery.\n *\n * `rawBody` must be the bytes as received \u2014 `await request.text()`, never\n * `JSON.stringify(await request.json())`. A parse-and-restringify is not a\n * byte-for-byte round trip (key order, number formatting, whitespace) and one\n * byte changes the whole digest, so the symptom is every webhook failing after\n * a refactor that looked like tidying.\n *\n * The `reason` is for our logs and our tests. It is never returned to the\n * caller: \"your signature was fine but your clock is stale\" is the next step in\n * an attack, handed over free.\n */\nexport async function verifySanityWebhook(options: {\n secret: string | undefined;\n rawBody: string;\n headers: { get(name: string): string | null };\n now?: number;\n toleranceMs?: number;\n}): Promise<WebhookVerification> {\n const { secret, rawBody, headers } = options;\n const now = options.now ?? Date.now();\n const toleranceMs = options.toleranceMs ?? DEFAULT_TOLERANCE_MS;\n\n if (!secret || secret.length === 0) return { ok: false, reason: \"no-secret\" };\n\n const header = headers.get(SANITY_SIGNATURE_HEADER);\n if (!header) return { ok: false, reason: \"no-signature\" };\n\n const match = SIGNATURE_VALUE.exec(header.trim());\n if (match === null) return { ok: false, reason: \"malformed-signature\" };\n\n const timestamp = Number(match[1]);\n const provided = match[2] ?? \"\";\n if (!Number.isSafeInteger(timestamp)) return { ok: false, reason: \"malformed-signature\" };\n if (timestamp < MINIMUM_TIMESTAMP) return { ok: false, reason: \"stale-timestamp\" };\n if (Math.abs(now - timestamp) > toleranceMs) return { ok: false, reason: \"stale-timestamp\" };\n\n const signature = base64UrlToBytes(provided);\n if (signature === null) return { ok: false, reason: \"malformed-signature\" };\n\n const key = await hmacKey(secret);\n const valid = await crypto.subtle.verify(\n \"HMAC\",\n key,\n signature,\n encoder.encode(`${timestamp}.${rawBody}`),\n );\n return valid ? { ok: true } : { ok: false, reason: \"bad-signature\" };\n}\n"],
|
|
5
|
+
"mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,0BAAAE,EAAA,sBAAAC,EAAA,4BAAAC,EAAA,wBAAAC,IAAA,eAAAC,EAAAN,GCmFO,IAAMO,EAA0B,2BAGjCC,EAAkB,4BAGXC,EAAoB,WAUpBC,EAAuB,IAgB9BC,EAAU,IAAI,YAEpB,SAASC,EAAQC,EAAoC,CACnD,OAAO,OAAO,OAAO,UACnB,MACAF,EAAQ,OAAOE,CAAM,EACrB,CAAE,KAAM,OAAQ,KAAM,SAAU,EAChC,GACA,CAAC,OAAQ,QAAQ,CACnB,CACF,CAWA,SAASC,EAAiBC,EAA+C,CACvE,GAAI,CAAC,yBAAyB,KAAKA,CAAK,EAAG,OAAO,KAClD,IAAMC,EAASD,EAAM,QAAQ,KAAM,GAAG,EAAE,QAAQ,KA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,EACAnB,EAAQ,OAAO,GAAGiB,CAAS,IAAIN,CAAO,EAAE,CAC1C,EACe,CAAE,GAAI,EAAK,EAAI,CAAE,GAAI,GAAO,OAAQ,eAAgB,CACrE",
|
|
6
|
+
"names": ["webhook_exports", "__export", "DEFAULT_TOLERANCE_MS", "MINIMUM_TIMESTAMP", "SANITY_SIGNATURE_HEADER", "verifySanityWebhook", "__toCommonJS", "SANITY_SIGNATURE_HEADER", "SIGNATURE_VALUE", "MINIMUM_TIMESTAMP", "DEFAULT_TOLERANCE_MS", "encoder", "hmacKey", "secret", "base64UrlToBytes", "value", "padded", "binary", "bytes", "i", "verifySanityWebhook", "options", "rawBody", "headers", "now", "toleranceMs", "header", "match", "timestamp", "provided", "signature", "key"]
|
|
7
|
+
}
|
package/dist/webhook.mjs
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var l="sanity-webhook-signature",d=/^t=(\d+)[, ]+v1=([^, ]+)$/,g=16094592e5,A=3e5,u=new TextEncoder;function b(e){return crypto.subtle.importKey("raw",u.encode(e),{name:"HMAC",hash:"SHA-256"},!1,["sign","verify"])}function M(e){if(!/^[A-Za-z0-9_-]+={0,2}$/.test(e))return null;let r=e.replace(/-/g,"+").replace(/_/g,"/");try{let n=atob(r),o=new Uint8Array(n.length);for(let t=0;t<n.length;t+=1)o[t]=n.charCodeAt(t);return o}catch{return null}}async function h(e){let{secret:r,rawBody:n,headers:o}=e,t=e.now??Date.now(),f=e.toleranceMs??3e5;if(!r||r.length===0)return{ok:!1,reason:"no-secret"};let i=o.get(l);if(!i)return{ok:!1,reason:"no-signature"};let s=d.exec(i.trim());if(s===null)return{ok:!1,reason:"malformed-signature"};let a=Number(s[1]),m=s[2]??"";if(!Number.isSafeInteger(a))return{ok:!1,reason:"malformed-signature"};if(a<16094592e5)return{ok:!1,reason:"stale-timestamp"};if(Math.abs(t-a)>f)return{ok:!1,reason:"stale-timestamp"};let c=M(m);if(c===null)return{ok:!1,reason:"malformed-signature"};let y=await b(r);return await crypto.subtle.verify("HMAC",y,c,u.encode(`${a}.${n}`))?{ok:!0}:{ok:!1,reason:"bad-signature"}}export{A as DEFAULT_TOLERANCE_MS,g as MINIMUM_TIMESTAMP,l as SANITY_SIGNATURE_HEADER,h as verifySanityWebhook};
|
|
2
|
+
//# sourceMappingURL=webhook.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/portable/webhook.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * Verifying a Sanity webhook (A-590 step 1, A-592's `SANITY_WEBHOOK_SECRET`).\n *\n * -------------------------------------------------------------------------\n * WHY THIS ENDPOINT NEEDS A SIGNATURE AT ALL\n * -------------------------------------------------------------------------\n *\n * `/revalidate` throws away cache entries. A-590: \"An unauthenticated\n * revalidation endpoint is a free cache-purge and rebuild trigger for anyone\n * who finds the URL.\" On a plan whose API request allowance is a HARD cap that\n * returns 402 rather than a bill, an attacker who can empty the cache at will\n * can take a client's site content-offline for the rest of the month. So the\n * signature is not hygiene here; it is the availability control.\n *\n * -------------------------------------------------------------------------\n * THE WIRE FORMAT IS MEASURED, NOT REMEMBERED\n * -------------------------------------------------------------------------\n *\n * Read on 2026-09-16 from Sanity's own toolkit,\n * `https://raw.githubusercontent.com/sanity-io/webhook-toolkit/main/src/signature.ts`:\n *\n * header `sanity-webhook-signature`\n * value `t=<millis>,v1=<signature>` (regex `/^t=(\\d+)[, ]+v1=([^, ]+)$/`)\n * signed payload `` `${timestamp}.${body}` ``\n * algorithm HMAC-SHA256\n * digest encoding base64url \u2014 standard base64 with `+`\u2192`-`, `/`\u2192`_`, padding stripped\n * MINIMUM_TIMESTAMP 1609459200000 (2021-01-01Z), below which a value is nonsense\n *\n * `signature.test.ts` does not take that paragraph's word for it either: it\n * signs a payload with `@sanity/webhook`'s own `encodeSignatureHeader` and\n * asserts this verifier accepts it. If Sanity changes the format, that test\n * goes red rather than production quietly rejecting every webhook.\n *\n * -------------------------------------------------------------------------\n * WHAT THIS ADDS TO THE TOOLKIT, AND WHY IT IS NOT JUST IMPORTED\n * -------------------------------------------------------------------------\n *\n * Two things, both of which are `CLAUDE.md`'s \"take the safer construction\".\n *\n * First, a REPLAY WINDOW. The toolkit enforces only that the timestamp is after\n * 2021; a captured webhook is otherwise replayable forever. A replayed purge is\n * the attack in the first paragraph, executed with a request somebody was\n * legitimately sent. `verifySanityWebhook` takes a symmetric tolerance \u2014 the\n * window is symmetric for A-44's reason, since a far-future timestamp is\n * precisely how you mint a request that stays replayable for a year.\n *\n * Second, a MISSING SECRET IS A REJECTION, never a bypass. A-590 says it in as\n * many words: \"reject on absence rather than skipping the check when the secret\n * is unset.\" The degraded mode of \"no secret configured, so allow it\" is\n * produced by a deploy that forgot `wrangler secret put`, announces itself\n * nowhere, and grants strangers the purge endpoint.\n *\n * The comparison is `crypto.subtle.verify`, which compares raw digests in\n * constant time. A `===` on the base64 strings short-circuits at the first\n * differing character, which turns one 2^256 search into a few dozen sequential\n * 64-way ones against an endpoint that answers in milliseconds.\n *\n * -------------------------------------------------------------------------\n * `encodeSignatureHeader` IS ASYNC. AWAIT IT. (A-651)\n * -------------------------------------------------------------------------\n *\n * `@sanity/webhook@4.0.4` declares\n *\n * encodeSignatureHeader(payload: string, timestamp: number, secret: string):\n * Promise<string>\n *\n * and nothing forces you to await it. Drop the `await` and the Promise is\n * stringified into the header as the literal `[object Promise]`, which arrives\n * here, fails `SIGNATURE_VALUE`, and is rejected as `malformed-signature`. The\n * rejection is correct and the message is about the wire format, so it sends\n * you to read Sanity's header spec \u2014 the one place the bug is not. TypeScript\n * does not save you either: the value usually lands in a `Record<string,\n * string>` built by a helper, or inside a template literal, both of which take\n * a Promise without complaint.\n *\n * The rule: every call to `encodeSignatureHeader` is awaited, and the helper\n * that wraps it is `async` rather than returning the Promise for someone else\n * to forget. The content-client compatibility tests and CMS signer tests await every\n * encoder call; this note exists so the next one\n * is too, because the symptom will not tell you.\n */\n\n/** Sanity's header. Lower-cased; `Headers.get` is case-insensitive either way. */\nexport const SANITY_SIGNATURE_HEADER = \"sanity-webhook-signature\";\n\n/** Sanity's own parser, character for character. See the header. */\nconst SIGNATURE_VALUE = /^t=(\\d+)[, ]+v1=([^, ]+)$/;\n\n/** 2021-01-01T00:00:00.000Z. Sanity's `MINIMUM_TIMESTAMP`; anything earlier is not a timestamp. */\nexport const MINIMUM_TIMESTAMP = 1_609_459_200_000;\n\n/**\n * How far from `now` a webhook timestamp may be, in milliseconds.\n *\n * Five minutes rather than A-44's sixty seconds: this one crosses Sanity's\n * delivery queue rather than two NTP-synced clouds, and a retried delivery is a\n * normal event. It is still a window rather than \"forever\", which is the whole\n * difference from the toolkit.\n */\nexport const DEFAULT_TOLERANCE_MS = 300_000;\n\nexport type WebhookRejection =\n /** `SANITY_WEBHOOK_SECRET` is unset or empty. Fail closed. */\n | \"no-secret\"\n /** No `sanity-webhook-signature` header. */\n | \"no-signature\"\n /** Header present but not `t=\u2026,v1=\u2026`, or `v1` is not decodable base64url. */\n | \"malformed-signature\"\n /** Before 2021, or outside the tolerance in either direction. */\n | \"stale-timestamp\"\n /** Well-formed, in window, wrong. */\n | \"bad-signature\";\n\nexport type WebhookVerification = { ok: true } | { ok: false; reason: WebhookRejection };\n\nconst encoder = new TextEncoder();\n\nfunction hmacKey(secret: string): Promise<CryptoKey> {\n return crypto.subtle.importKey(\n \"raw\",\n encoder.encode(secret),\n { name: \"HMAC\", hash: \"SHA-256\" },\n false,\n [\"sign\", \"verify\"],\n );\n}\n\n/**\n * base64url \u2192 bytes, without `Buffer`.\n *\n * `atob` rather than `node:crypto` or `Buffer` because this file is imported by\n * the Worker, and workerd has neither by default. Returns null rather than\n * throwing on rubbish, so a malformed header is a 401 and not a 500 \u2014 a\n * verifier that crashes on bad input is a verifier an attacker can use as a\n * denial of service.\n */\nfunction base64UrlToBytes(value: string): Uint8Array<ArrayBuffer> | null {\n if (!/^[A-Za-z0-9_-]+={0,2}$/.test(value)) return null;\n const padded = value.replace(/-/g, \"+\").replace(/_/g, \"/\");\n try {\n const binary = atob(padded);\n const bytes = new Uint8Array(binary.length);\n for (let i = 0; i < binary.length; i += 1) bytes[i] = binary.charCodeAt(i);\n return bytes;\n } catch {\n return null;\n }\n}\n\n/**\n * Verify a Sanity webhook delivery.\n *\n * `rawBody` must be the bytes as received \u2014 `await request.text()`, never\n * `JSON.stringify(await request.json())`. A parse-and-restringify is not a\n * byte-for-byte round trip (key order, number formatting, whitespace) and one\n * byte changes the whole digest, so the symptom is every webhook failing after\n * a refactor that looked like tidying.\n *\n * The `reason` is for our logs and our tests. It is never returned to the\n * caller: \"your signature was fine but your clock is stale\" is the next step in\n * an attack, handed over free.\n */\nexport async function verifySanityWebhook(options: {\n secret: string | undefined;\n rawBody: string;\n headers: { get(name: string): string | null };\n now?: number;\n toleranceMs?: number;\n}): Promise<WebhookVerification> {\n const { secret, rawBody, headers } = options;\n const now = options.now ?? Date.now();\n const toleranceMs = options.toleranceMs ?? DEFAULT_TOLERANCE_MS;\n\n if (!secret || secret.length === 0) return { ok: false, reason: \"no-secret\" };\n\n const header = headers.get(SANITY_SIGNATURE_HEADER);\n if (!header) return { ok: false, reason: \"no-signature\" };\n\n const match = SIGNATURE_VALUE.exec(header.trim());\n if (match === null) return { ok: false, reason: \"malformed-signature\" };\n\n const timestamp = Number(match[1]);\n const provided = match[2] ?? \"\";\n if (!Number.isSafeInteger(timestamp)) return { ok: false, reason: \"malformed-signature\" };\n if (timestamp < MINIMUM_TIMESTAMP) return { ok: false, reason: \"stale-timestamp\" };\n if (Math.abs(now - timestamp) > toleranceMs) return { ok: false, reason: \"stale-timestamp\" };\n\n const signature = base64UrlToBytes(provided);\n if (signature === null) return { ok: false, reason: \"malformed-signature\" };\n\n const key = await hmacKey(secret);\n const valid = await crypto.subtle.verify(\n \"HMAC\",\n key,\n signature,\n encoder.encode(`${timestamp}.${rawBody}`),\n );\n return valid ? { ok: true } : { ok: false, reason: \"bad-signature\" };\n}\n"],
|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cAAcC,CAAS,EAAG,MAAO,CAAE,GAAI,GAAO,OAAQ,qBAAsB,EACxF,GAAIA,EAAY,WAAmB,MAAO,CAAE,GAAI,GAAO,OAAQ,iBAAkB,EACjF,GAAI,KAAK,IAAIJ,EAAMI,CAAS,EAAIH,EAAa,MAAO,CAAE,GAAI,GAAO,OAAQ,iBAAkB,EAE3F,IAAMK,EAAYhB,EAAiBe,CAAQ,EAC3C,GAAIC,IAAc,KAAM,MAAO,CAAE,GAAI,GAAO,OAAQ,qBAAsB,EAE1E,IAAMC,EAAM,MAAMnB,EAAQC,CAAM,EAOhC,OANc,MAAM,OAAO,OAAO,OAChC,OACAkB,EACAD,EACAnB,EAAQ,OAAO,GAAGiB,CAAS,IAAIN,CAAO,EAAE,CAC1C,EACe,CAAE,GAAI,EAAK,EAAI,CAAE,GAAI,GAAO,OAAQ,eAAgB,CACrE",
|
|
6
|
+
"names": ["SANITY_SIGNATURE_HEADER", "SIGNATURE_VALUE", "MINIMUM_TIMESTAMP", "DEFAULT_TOLERANCE_MS", "encoder", "hmacKey", "secret", "base64UrlToBytes", "value", "padded", "binary", "bytes", "i", "verifySanityWebhook", "options", "rawBody", "headers", "now", "toleranceMs", "header", "match", "timestamp", "provided", "signature", "key"]
|
|
7
|
+
}
|