@weatherboard/cms 0.0.0-stage → 0.1.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/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 +19 -0
- package/dist/contracts/query.d.mts +19 -0
- package/dist/contracts/query.d.ts +19 -0
- package/dist/contracts/text.d.cts +40 -0
- package/dist/contracts/text.d.mts +40 -0
- package/dist/contracts/text.d.ts +40 -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 +49 -0
- package/dist/runtime/reader.d.mts +49 -0
- package/dist/runtime/reader.d.ts +49 -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 +2 -0
- package/dist/site-content.d.mts +2 -0
- package/dist/site-content.d.ts +2 -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 +113 -3
- package/README.md +0 -3
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A-1713. The site content model, read: the home page, content pages and site
|
|
3
|
+
* settings, validated on read and returned in the shape a site's page
|
|
4
|
+
* composition consumes.
|
|
5
|
+
*
|
|
6
|
+
* ===========================================================================
|
|
7
|
+
* READ ONLY, BY CONSTRUCTION
|
|
8
|
+
* ===========================================================================
|
|
9
|
+
*
|
|
10
|
+
* A client site reads its content with a read-only token. All editing goes
|
|
11
|
+
* through the studio's dashboard, which writes to Sanity; nothing on a client
|
|
12
|
+
* site writes, and this module has no write path to call. It is handed a
|
|
13
|
+
* `ContentClient` (a `query` function) and nothing else.
|
|
14
|
+
*
|
|
15
|
+
* ===========================================================================
|
|
16
|
+
* VALIDATED ON READ, BECAUSE SANITY VALIDATION ONLY ADVISES
|
|
17
|
+
* ===========================================================================
|
|
18
|
+
*
|
|
19
|
+
* The schema's rules warn an editor; they do not refuse a publish, and
|
|
20
|
+
* anything writing over the API skips them entirely. So every document is
|
|
21
|
+
* checked here again, and a malformed one is refused BY NAME
|
|
22
|
+
* (`MalformedContentError`, code `malformed-content`) listing every problem
|
|
23
|
+
* with its path, rather than rendered half-empty. A page that renders with a
|
|
24
|
+
* missing headline and a page whose content is broken look identical to a
|
|
25
|
+
* visitor; a build that fails naming `hero.headline` does not.
|
|
26
|
+
*
|
|
27
|
+
* Absent is not malformed: `null` from `home()` means nobody has created the
|
|
28
|
+
* home page yet, and a site decides what to do about that.
|
|
29
|
+
*
|
|
30
|
+
* ===========================================================================
|
|
31
|
+
* THE SHAPE IT RETURNS
|
|
32
|
+
* ===========================================================================
|
|
33
|
+
*
|
|
34
|
+
* The INPUT shape of a site's composition schema (the reference build's
|
|
35
|
+
* frontmatter): a copy value is a plain string for the client's own words
|
|
36
|
+
* with no claim about their source, `{ text, copySource: "captured" }` for
|
|
37
|
+
* words claimed verbatim from the capture (the site checks every such claim
|
|
38
|
+
* against its capture evidence, so the claim must survive Sanity), and
|
|
39
|
+
* `{ text, copySource: "proposed" }` for studio-written words awaiting
|
|
40
|
+
* approval. All three round-trip exactly; a photo is its library slug; every key a block declares is
|
|
41
|
+
* present, `null` where there is nothing. So a site validates this with the
|
|
42
|
+
* same schema it validates its Markdown frontmatter with, and its components
|
|
43
|
+
* never know where the content came from.
|
|
44
|
+
*
|
|
45
|
+
* Mapping from the generic model to the composition's names:
|
|
46
|
+
*
|
|
47
|
+
* hero.headline / subline / lead hero.heading / subline / intro
|
|
48
|
+
* hero.photos[0], [1] hero.image, hero.inset
|
|
49
|
+
* hero.primaryAction / secondary... hero.cta / secondaryCta
|
|
50
|
+
* campaign (when shown) the FIRST block, kind `campaign`, and
|
|
51
|
+
* the page body (`# title` + its text)
|
|
52
|
+
* featureStoriesBlock kind `feature_stories`
|
|
53
|
+
* surfaceCardBlock kind `cta`
|
|
54
|
+
* accentBandBlock kind `accent_band`
|
|
55
|
+
* locationsBlock kind `locations` (jumpLink → anchor)
|
|
56
|
+
*
|
|
57
|
+
* Two places the composition cannot carry a proposed marker: a `cta` block's
|
|
58
|
+
* plain strings, and the campaign's title and body (which travel as Markdown).
|
|
59
|
+
* There the text is returned plain and the line is still listed in
|
|
60
|
+
* `proposedCopy`, which is the list a dashboard and a site both read for
|
|
61
|
+
* approval. Nothing is dropped silently.
|
|
62
|
+
*/
|
|
63
|
+
import { type CmsQuery } from "../contracts/query.mjs";
|
|
64
|
+
export type CopyInput = string | {
|
|
65
|
+
readonly text: string;
|
|
66
|
+
readonly copySource: "captured" | "proposed";
|
|
67
|
+
};
|
|
68
|
+
export type ActionInput = {
|
|
69
|
+
readonly label: CopyInput;
|
|
70
|
+
readonly href: string;
|
|
71
|
+
};
|
|
72
|
+
export type HeroInput = {
|
|
73
|
+
readonly heading: CopyInput;
|
|
74
|
+
readonly subline: CopyInput | null;
|
|
75
|
+
readonly intro: CopyInput | null;
|
|
76
|
+
readonly image: string | null;
|
|
77
|
+
readonly inset: string | null;
|
|
78
|
+
readonly cta: ActionInput | null;
|
|
79
|
+
readonly secondaryCta: ActionInput | null;
|
|
80
|
+
};
|
|
81
|
+
export type StoryInput = {
|
|
82
|
+
readonly heading: CopyInput;
|
|
83
|
+
readonly body: CopyInput;
|
|
84
|
+
readonly action: ActionInput;
|
|
85
|
+
readonly image: string | null;
|
|
86
|
+
readonly shape: "wide" | "tall" | "round" | "free";
|
|
87
|
+
readonly card: boolean;
|
|
88
|
+
};
|
|
89
|
+
export type CompositionBlockInput = {
|
|
90
|
+
readonly kind: "campaign";
|
|
91
|
+
readonly action: ActionInput | null;
|
|
92
|
+
readonly images: readonly string[];
|
|
93
|
+
} | {
|
|
94
|
+
readonly kind: "locations";
|
|
95
|
+
readonly anchor: string | null;
|
|
96
|
+
readonly heading: CopyInput;
|
|
97
|
+
readonly tail: CopyInput | null;
|
|
98
|
+
readonly image: string | null;
|
|
99
|
+
} | {
|
|
100
|
+
readonly kind: "feature_stories";
|
|
101
|
+
readonly heading: CopyInput;
|
|
102
|
+
readonly tail: CopyInput | null;
|
|
103
|
+
readonly items: readonly StoryInput[];
|
|
104
|
+
} | {
|
|
105
|
+
readonly kind: "accent_band";
|
|
106
|
+
readonly heading: CopyInput;
|
|
107
|
+
readonly body: CopyInput;
|
|
108
|
+
readonly action: ActionInput | null;
|
|
109
|
+
readonly image: string | null;
|
|
110
|
+
} | {
|
|
111
|
+
readonly kind: "cta";
|
|
112
|
+
readonly heading: string;
|
|
113
|
+
readonly body: string | null;
|
|
114
|
+
readonly link: {
|
|
115
|
+
readonly label: string;
|
|
116
|
+
readonly href: string;
|
|
117
|
+
};
|
|
118
|
+
};
|
|
119
|
+
export type CompositionInput = {
|
|
120
|
+
readonly intro: string | null;
|
|
121
|
+
readonly photo: string | null;
|
|
122
|
+
readonly hero: HeroInput | null;
|
|
123
|
+
readonly blocks: readonly CompositionBlockInput[];
|
|
124
|
+
};
|
|
125
|
+
/** One line of studio-written copy awaiting approval, and where it is in the document. */
|
|
126
|
+
export type ProposedCopy = {
|
|
127
|
+
readonly where: string;
|
|
128
|
+
readonly text: string;
|
|
129
|
+
};
|
|
130
|
+
export type CampaignState = "shown" | "off" | "not-started" | "ended" | "none";
|
|
131
|
+
export type HomeContent = {
|
|
132
|
+
readonly composition: CompositionInput;
|
|
133
|
+
/** The page body as Markdown: the campaign's title and text when it is shown, otherwise empty. */
|
|
134
|
+
readonly body: string;
|
|
135
|
+
readonly campaign: CampaignState;
|
|
136
|
+
readonly proposedCopy: readonly ProposedCopy[];
|
|
137
|
+
};
|
|
138
|
+
export type PageContent = {
|
|
139
|
+
readonly slug: string;
|
|
140
|
+
readonly title: string;
|
|
141
|
+
readonly composition: CompositionInput;
|
|
142
|
+
readonly body: string;
|
|
143
|
+
readonly migrated: boolean;
|
|
144
|
+
readonly proposedCopy: readonly ProposedCopy[];
|
|
145
|
+
};
|
|
146
|
+
export type SiteSettingsContent = {
|
|
147
|
+
readonly name: string;
|
|
148
|
+
readonly description: string | null;
|
|
149
|
+
readonly contact: {
|
|
150
|
+
readonly email: string | null;
|
|
151
|
+
readonly phone: string | null;
|
|
152
|
+
};
|
|
153
|
+
readonly social: readonly {
|
|
154
|
+
readonly network: string;
|
|
155
|
+
readonly url: string;
|
|
156
|
+
}[];
|
|
157
|
+
};
|
|
158
|
+
export declare const MALFORMED_CONTENT = "malformed-content";
|
|
159
|
+
export declare class MalformedContentError extends Error {
|
|
160
|
+
readonly code = "malformed-content";
|
|
161
|
+
readonly documentId: string;
|
|
162
|
+
readonly problems: readonly string[];
|
|
163
|
+
constructor(documentId: string, problems: readonly string[]);
|
|
164
|
+
}
|
|
165
|
+
export declare const READER_PHOTO_SLUG: RegExp;
|
|
166
|
+
export declare const READER_ACTION_HREF: RegExp;
|
|
167
|
+
export declare const READER_JUMP_LINK: RegExp;
|
|
168
|
+
export declare const READER_STORY_LAYOUTS: readonly ["wide", "tall", "round", "free"];
|
|
169
|
+
export declare const READER_HOME_PAGE_ID = "homePage";
|
|
170
|
+
export declare const READER_SITE_SETTINGS_ID = "siteSettings";
|
|
171
|
+
/**
|
|
172
|
+
* The narrow Portable Text `portableText` declares, back to Markdown: normal,
|
|
173
|
+
* h2, h3 and quote blocks, bullet and numbered lists, bold, italic, code and
|
|
174
|
+
* links. It is the inverse of the seed package's Markdown mapper, and the
|
|
175
|
+
* round-trip test holds the two to each other.
|
|
176
|
+
*
|
|
177
|
+
* An uploaded image inside rich text is REFUSED, not dropped: nothing can
|
|
178
|
+
* upload one yet (the dashboard slice decides how), so one arriving means
|
|
179
|
+
* something wrote the document by hand, and a page silently missing a picture
|
|
180
|
+
* is the failure this reader exists to prevent.
|
|
181
|
+
*/
|
|
182
|
+
export declare function portableTextToMarkdown(value: unknown): string;
|
|
183
|
+
/** Whether a campaign is shown at `now`, and if not, why not. */
|
|
184
|
+
export declare function campaignState(campaign: unknown, now: Date): CampaignState;
|
|
185
|
+
/**
|
|
186
|
+
* A stored home page document, validated and mapped. Throws
|
|
187
|
+
* `MalformedContentError` naming every problem. `now` decides whether a
|
|
188
|
+
* scheduled campaign is shown, and is a parameter so a build, a preview and a
|
|
189
|
+
* test each say which moment they mean.
|
|
190
|
+
*/
|
|
191
|
+
export declare function parseHomePage(document: unknown, options: {
|
|
192
|
+
readonly now: Date;
|
|
193
|
+
}): HomeContent;
|
|
194
|
+
export declare function parseContentPage(document: unknown): PageContent;
|
|
195
|
+
export declare function parseSiteSettings(document: unknown): SiteSettingsContent;
|
|
196
|
+
/** By fixed id: a second home page at a random id is never read. */
|
|
197
|
+
export declare const HOME_PAGE_DOCUMENT_QUERY = "*[_id == $id][0]";
|
|
198
|
+
export declare const CONTENT_PAGES_QUERY = "*[_type == \"page\" && defined(slug.current)]|order(slug.current asc)";
|
|
199
|
+
export declare const CONTENT_PAGE_BY_SLUG_QUERY = "*[_type == \"page\" && slug.current == $slug][0]";
|
|
200
|
+
export interface SiteContentReader {
|
|
201
|
+
/** `null` when no home page document exists yet. */
|
|
202
|
+
home: (options: {
|
|
203
|
+
readonly now: Date;
|
|
204
|
+
}) => Promise<HomeContent | null>;
|
|
205
|
+
pages: () => Promise<PageContent[]>;
|
|
206
|
+
/** `null` when no page has that slug. */
|
|
207
|
+
pageBySlug: (slug: string) => Promise<PageContent | null>;
|
|
208
|
+
/** `null` before anyone has filled in the site's details. */
|
|
209
|
+
siteSettings: () => Promise<SiteSettingsContent | null>;
|
|
210
|
+
}
|
|
211
|
+
export declare function createSiteContentReader(client: {
|
|
212
|
+
query: <T>(groq: string, options?: {
|
|
213
|
+
params?: Record<string, unknown>;
|
|
214
|
+
tags?: readonly string[];
|
|
215
|
+
}) => Promise<T>;
|
|
216
|
+
}): SiteContentReader;
|
|
217
|
+
export declare function homeContentQuery(now: Date): CmsQuery<HomeContent | null>;
|
|
218
|
+
export declare function contentPageQuery(slug: string): CmsQuery<PageContent | null>;
|
|
219
|
+
export declare function contentPagesQuery(): CmsQuery<readonly PageContent[]>;
|
|
220
|
+
export declare function siteSettingsQuery(): CmsQuery<SiteSettingsContent | null>;
|
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A-1713. The site content model, read: the home page, content pages and site
|
|
3
|
+
* settings, validated on read and returned in the shape a site's page
|
|
4
|
+
* composition consumes.
|
|
5
|
+
*
|
|
6
|
+
* ===========================================================================
|
|
7
|
+
* READ ONLY, BY CONSTRUCTION
|
|
8
|
+
* ===========================================================================
|
|
9
|
+
*
|
|
10
|
+
* A client site reads its content with a read-only token. All editing goes
|
|
11
|
+
* through the studio's dashboard, which writes to Sanity; nothing on a client
|
|
12
|
+
* site writes, and this module has no write path to call. It is handed a
|
|
13
|
+
* `ContentClient` (a `query` function) and nothing else.
|
|
14
|
+
*
|
|
15
|
+
* ===========================================================================
|
|
16
|
+
* VALIDATED ON READ, BECAUSE SANITY VALIDATION ONLY ADVISES
|
|
17
|
+
* ===========================================================================
|
|
18
|
+
*
|
|
19
|
+
* The schema's rules warn an editor; they do not refuse a publish, and
|
|
20
|
+
* anything writing over the API skips them entirely. So every document is
|
|
21
|
+
* checked here again, and a malformed one is refused BY NAME
|
|
22
|
+
* (`MalformedContentError`, code `malformed-content`) listing every problem
|
|
23
|
+
* with its path, rather than rendered half-empty. A page that renders with a
|
|
24
|
+
* missing headline and a page whose content is broken look identical to a
|
|
25
|
+
* visitor; a build that fails naming `hero.headline` does not.
|
|
26
|
+
*
|
|
27
|
+
* Absent is not malformed: `null` from `home()` means nobody has created the
|
|
28
|
+
* home page yet, and a site decides what to do about that.
|
|
29
|
+
*
|
|
30
|
+
* ===========================================================================
|
|
31
|
+
* THE SHAPE IT RETURNS
|
|
32
|
+
* ===========================================================================
|
|
33
|
+
*
|
|
34
|
+
* The INPUT shape of a site's composition schema (the reference build's
|
|
35
|
+
* frontmatter): a copy value is a plain string for the client's own words
|
|
36
|
+
* with no claim about their source, `{ text, copySource: "captured" }` for
|
|
37
|
+
* words claimed verbatim from the capture (the site checks every such claim
|
|
38
|
+
* against its capture evidence, so the claim must survive Sanity), and
|
|
39
|
+
* `{ text, copySource: "proposed" }` for studio-written words awaiting
|
|
40
|
+
* approval. All three round-trip exactly; a photo is its library slug; every key a block declares is
|
|
41
|
+
* present, `null` where there is nothing. So a site validates this with the
|
|
42
|
+
* same schema it validates its Markdown frontmatter with, and its components
|
|
43
|
+
* never know where the content came from.
|
|
44
|
+
*
|
|
45
|
+
* Mapping from the generic model to the composition's names:
|
|
46
|
+
*
|
|
47
|
+
* hero.headline / subline / lead hero.heading / subline / intro
|
|
48
|
+
* hero.photos[0], [1] hero.image, hero.inset
|
|
49
|
+
* hero.primaryAction / secondary... hero.cta / secondaryCta
|
|
50
|
+
* campaign (when shown) the FIRST block, kind `campaign`, and
|
|
51
|
+
* the page body (`# title` + its text)
|
|
52
|
+
* featureStoriesBlock kind `feature_stories`
|
|
53
|
+
* surfaceCardBlock kind `cta`
|
|
54
|
+
* accentBandBlock kind `accent_band`
|
|
55
|
+
* locationsBlock kind `locations` (jumpLink → anchor)
|
|
56
|
+
*
|
|
57
|
+
* Two places the composition cannot carry a proposed marker: a `cta` block's
|
|
58
|
+
* plain strings, and the campaign's title and body (which travel as Markdown).
|
|
59
|
+
* There the text is returned plain and the line is still listed in
|
|
60
|
+
* `proposedCopy`, which is the list a dashboard and a site both read for
|
|
61
|
+
* approval. Nothing is dropped silently.
|
|
62
|
+
*/
|
|
63
|
+
import { type CmsQuery } from "../contracts/query.js";
|
|
64
|
+
export type CopyInput = string | {
|
|
65
|
+
readonly text: string;
|
|
66
|
+
readonly copySource: "captured" | "proposed";
|
|
67
|
+
};
|
|
68
|
+
export type ActionInput = {
|
|
69
|
+
readonly label: CopyInput;
|
|
70
|
+
readonly href: string;
|
|
71
|
+
};
|
|
72
|
+
export type HeroInput = {
|
|
73
|
+
readonly heading: CopyInput;
|
|
74
|
+
readonly subline: CopyInput | null;
|
|
75
|
+
readonly intro: CopyInput | null;
|
|
76
|
+
readonly image: string | null;
|
|
77
|
+
readonly inset: string | null;
|
|
78
|
+
readonly cta: ActionInput | null;
|
|
79
|
+
readonly secondaryCta: ActionInput | null;
|
|
80
|
+
};
|
|
81
|
+
export type StoryInput = {
|
|
82
|
+
readonly heading: CopyInput;
|
|
83
|
+
readonly body: CopyInput;
|
|
84
|
+
readonly action: ActionInput;
|
|
85
|
+
readonly image: string | null;
|
|
86
|
+
readonly shape: "wide" | "tall" | "round" | "free";
|
|
87
|
+
readonly card: boolean;
|
|
88
|
+
};
|
|
89
|
+
export type CompositionBlockInput = {
|
|
90
|
+
readonly kind: "campaign";
|
|
91
|
+
readonly action: ActionInput | null;
|
|
92
|
+
readonly images: readonly string[];
|
|
93
|
+
} | {
|
|
94
|
+
readonly kind: "locations";
|
|
95
|
+
readonly anchor: string | null;
|
|
96
|
+
readonly heading: CopyInput;
|
|
97
|
+
readonly tail: CopyInput | null;
|
|
98
|
+
readonly image: string | null;
|
|
99
|
+
} | {
|
|
100
|
+
readonly kind: "feature_stories";
|
|
101
|
+
readonly heading: CopyInput;
|
|
102
|
+
readonly tail: CopyInput | null;
|
|
103
|
+
readonly items: readonly StoryInput[];
|
|
104
|
+
} | {
|
|
105
|
+
readonly kind: "accent_band";
|
|
106
|
+
readonly heading: CopyInput;
|
|
107
|
+
readonly body: CopyInput;
|
|
108
|
+
readonly action: ActionInput | null;
|
|
109
|
+
readonly image: string | null;
|
|
110
|
+
} | {
|
|
111
|
+
readonly kind: "cta";
|
|
112
|
+
readonly heading: string;
|
|
113
|
+
readonly body: string | null;
|
|
114
|
+
readonly link: {
|
|
115
|
+
readonly label: string;
|
|
116
|
+
readonly href: string;
|
|
117
|
+
};
|
|
118
|
+
};
|
|
119
|
+
export type CompositionInput = {
|
|
120
|
+
readonly intro: string | null;
|
|
121
|
+
readonly photo: string | null;
|
|
122
|
+
readonly hero: HeroInput | null;
|
|
123
|
+
readonly blocks: readonly CompositionBlockInput[];
|
|
124
|
+
};
|
|
125
|
+
/** One line of studio-written copy awaiting approval, and where it is in the document. */
|
|
126
|
+
export type ProposedCopy = {
|
|
127
|
+
readonly where: string;
|
|
128
|
+
readonly text: string;
|
|
129
|
+
};
|
|
130
|
+
export type CampaignState = "shown" | "off" | "not-started" | "ended" | "none";
|
|
131
|
+
export type HomeContent = {
|
|
132
|
+
readonly composition: CompositionInput;
|
|
133
|
+
/** The page body as Markdown: the campaign's title and text when it is shown, otherwise empty. */
|
|
134
|
+
readonly body: string;
|
|
135
|
+
readonly campaign: CampaignState;
|
|
136
|
+
readonly proposedCopy: readonly ProposedCopy[];
|
|
137
|
+
};
|
|
138
|
+
export type PageContent = {
|
|
139
|
+
readonly slug: string;
|
|
140
|
+
readonly title: string;
|
|
141
|
+
readonly composition: CompositionInput;
|
|
142
|
+
readonly body: string;
|
|
143
|
+
readonly migrated: boolean;
|
|
144
|
+
readonly proposedCopy: readonly ProposedCopy[];
|
|
145
|
+
};
|
|
146
|
+
export type SiteSettingsContent = {
|
|
147
|
+
readonly name: string;
|
|
148
|
+
readonly description: string | null;
|
|
149
|
+
readonly contact: {
|
|
150
|
+
readonly email: string | null;
|
|
151
|
+
readonly phone: string | null;
|
|
152
|
+
};
|
|
153
|
+
readonly social: readonly {
|
|
154
|
+
readonly network: string;
|
|
155
|
+
readonly url: string;
|
|
156
|
+
}[];
|
|
157
|
+
};
|
|
158
|
+
export declare const MALFORMED_CONTENT = "malformed-content";
|
|
159
|
+
export declare class MalformedContentError extends Error {
|
|
160
|
+
readonly code = "malformed-content";
|
|
161
|
+
readonly documentId: string;
|
|
162
|
+
readonly problems: readonly string[];
|
|
163
|
+
constructor(documentId: string, problems: readonly string[]);
|
|
164
|
+
}
|
|
165
|
+
export declare const READER_PHOTO_SLUG: RegExp;
|
|
166
|
+
export declare const READER_ACTION_HREF: RegExp;
|
|
167
|
+
export declare const READER_JUMP_LINK: RegExp;
|
|
168
|
+
export declare const READER_STORY_LAYOUTS: readonly ["wide", "tall", "round", "free"];
|
|
169
|
+
export declare const READER_HOME_PAGE_ID = "homePage";
|
|
170
|
+
export declare const READER_SITE_SETTINGS_ID = "siteSettings";
|
|
171
|
+
/**
|
|
172
|
+
* The narrow Portable Text `portableText` declares, back to Markdown: normal,
|
|
173
|
+
* h2, h3 and quote blocks, bullet and numbered lists, bold, italic, code and
|
|
174
|
+
* links. It is the inverse of the seed package's Markdown mapper, and the
|
|
175
|
+
* round-trip test holds the two to each other.
|
|
176
|
+
*
|
|
177
|
+
* An uploaded image inside rich text is REFUSED, not dropped: nothing can
|
|
178
|
+
* upload one yet (the dashboard slice decides how), so one arriving means
|
|
179
|
+
* something wrote the document by hand, and a page silently missing a picture
|
|
180
|
+
* is the failure this reader exists to prevent.
|
|
181
|
+
*/
|
|
182
|
+
export declare function portableTextToMarkdown(value: unknown): string;
|
|
183
|
+
/** Whether a campaign is shown at `now`, and if not, why not. */
|
|
184
|
+
export declare function campaignState(campaign: unknown, now: Date): CampaignState;
|
|
185
|
+
/**
|
|
186
|
+
* A stored home page document, validated and mapped. Throws
|
|
187
|
+
* `MalformedContentError` naming every problem. `now` decides whether a
|
|
188
|
+
* scheduled campaign is shown, and is a parameter so a build, a preview and a
|
|
189
|
+
* test each say which moment they mean.
|
|
190
|
+
*/
|
|
191
|
+
export declare function parseHomePage(document: unknown, options: {
|
|
192
|
+
readonly now: Date;
|
|
193
|
+
}): HomeContent;
|
|
194
|
+
export declare function parseContentPage(document: unknown): PageContent;
|
|
195
|
+
export declare function parseSiteSettings(document: unknown): SiteSettingsContent;
|
|
196
|
+
/** By fixed id: a second home page at a random id is never read. */
|
|
197
|
+
export declare const HOME_PAGE_DOCUMENT_QUERY = "*[_id == $id][0]";
|
|
198
|
+
export declare const CONTENT_PAGES_QUERY = "*[_type == \"page\" && defined(slug.current)]|order(slug.current asc)";
|
|
199
|
+
export declare const CONTENT_PAGE_BY_SLUG_QUERY = "*[_type == \"page\" && slug.current == $slug][0]";
|
|
200
|
+
export interface SiteContentReader {
|
|
201
|
+
/** `null` when no home page document exists yet. */
|
|
202
|
+
home: (options: {
|
|
203
|
+
readonly now: Date;
|
|
204
|
+
}) => Promise<HomeContent | null>;
|
|
205
|
+
pages: () => Promise<PageContent[]>;
|
|
206
|
+
/** `null` when no page has that slug. */
|
|
207
|
+
pageBySlug: (slug: string) => Promise<PageContent | null>;
|
|
208
|
+
/** `null` before anyone has filled in the site's details. */
|
|
209
|
+
siteSettings: () => Promise<SiteSettingsContent | null>;
|
|
210
|
+
}
|
|
211
|
+
export declare function createSiteContentReader(client: {
|
|
212
|
+
query: <T>(groq: string, options?: {
|
|
213
|
+
params?: Record<string, unknown>;
|
|
214
|
+
tags?: readonly string[];
|
|
215
|
+
}) => Promise<T>;
|
|
216
|
+
}): SiteContentReader;
|
|
217
|
+
export declare function homeContentQuery(now: Date): CmsQuery<HomeContent | null>;
|
|
218
|
+
export declare function contentPageQuery(slug: string): CmsQuery<PageContent | null>;
|
|
219
|
+
export declare function contentPagesQuery(): CmsQuery<readonly PageContent[]>;
|
|
220
|
+
export declare function siteSettingsQuery(): CmsQuery<SiteSettingsContent | null>;
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Verifying a Sanity webhook (A-590 step 1, A-592's `SANITY_WEBHOOK_SECRET`).
|
|
3
|
+
*
|
|
4
|
+
* -------------------------------------------------------------------------
|
|
5
|
+
* WHY THIS ENDPOINT NEEDS A SIGNATURE AT ALL
|
|
6
|
+
* -------------------------------------------------------------------------
|
|
7
|
+
*
|
|
8
|
+
* `/revalidate` throws away cache entries. A-590: "An unauthenticated
|
|
9
|
+
* revalidation endpoint is a free cache-purge and rebuild trigger for anyone
|
|
10
|
+
* who finds the URL." On a plan whose API request allowance is a HARD cap that
|
|
11
|
+
* returns 402 rather than a bill, an attacker who can empty the cache at will
|
|
12
|
+
* can take a client's site content-offline for the rest of the month. So the
|
|
13
|
+
* signature is not hygiene here; it is the availability control.
|
|
14
|
+
*
|
|
15
|
+
* -------------------------------------------------------------------------
|
|
16
|
+
* THE WIRE FORMAT IS MEASURED, NOT REMEMBERED
|
|
17
|
+
* -------------------------------------------------------------------------
|
|
18
|
+
*
|
|
19
|
+
* Read on 2026-09-16 from Sanity's own toolkit,
|
|
20
|
+
* `https://raw.githubusercontent.com/sanity-io/webhook-toolkit/main/src/signature.ts`:
|
|
21
|
+
*
|
|
22
|
+
* header `sanity-webhook-signature`
|
|
23
|
+
* value `t=<millis>,v1=<signature>` (regex `/^t=(\d+)[, ]+v1=([^, ]+)$/`)
|
|
24
|
+
* signed payload `` `${timestamp}.${body}` ``
|
|
25
|
+
* algorithm HMAC-SHA256
|
|
26
|
+
* digest encoding base64url — standard base64 with `+`→`-`, `/`→`_`, padding stripped
|
|
27
|
+
* MINIMUM_TIMESTAMP 1609459200000 (2021-01-01Z), below which a value is nonsense
|
|
28
|
+
*
|
|
29
|
+
* `signature.test.ts` does not take that paragraph's word for it either: it
|
|
30
|
+
* signs a payload with `@sanity/webhook`'s own `encodeSignatureHeader` and
|
|
31
|
+
* asserts this verifier accepts it. If Sanity changes the format, that test
|
|
32
|
+
* goes red rather than production quietly rejecting every webhook.
|
|
33
|
+
*
|
|
34
|
+
* -------------------------------------------------------------------------
|
|
35
|
+
* WHAT THIS ADDS TO THE TOOLKIT, AND WHY IT IS NOT JUST IMPORTED
|
|
36
|
+
* -------------------------------------------------------------------------
|
|
37
|
+
*
|
|
38
|
+
* Two things, both of which are `CLAUDE.md`'s "take the safer construction".
|
|
39
|
+
*
|
|
40
|
+
* First, a REPLAY WINDOW. The toolkit enforces only that the timestamp is after
|
|
41
|
+
* 2021; a captured webhook is otherwise replayable forever. A replayed purge is
|
|
42
|
+
* the attack in the first paragraph, executed with a request somebody was
|
|
43
|
+
* legitimately sent. `verifySanityWebhook` takes a symmetric tolerance — the
|
|
44
|
+
* window is symmetric for A-44's reason, since a far-future timestamp is
|
|
45
|
+
* precisely how you mint a request that stays replayable for a year.
|
|
46
|
+
*
|
|
47
|
+
* Second, a MISSING SECRET IS A REJECTION, never a bypass. A-590 says it in as
|
|
48
|
+
* many words: "reject on absence rather than skipping the check when the secret
|
|
49
|
+
* is unset." The degraded mode of "no secret configured, so allow it" is
|
|
50
|
+
* produced by a deploy that forgot `wrangler secret put`, announces itself
|
|
51
|
+
* nowhere, and grants strangers the purge endpoint.
|
|
52
|
+
*
|
|
53
|
+
* The comparison is `crypto.subtle.verify`, which compares raw digests in
|
|
54
|
+
* constant time. A `===` on the base64 strings short-circuits at the first
|
|
55
|
+
* differing character, which turns one 2^256 search into a few dozen sequential
|
|
56
|
+
* 64-way ones against an endpoint that answers in milliseconds.
|
|
57
|
+
*
|
|
58
|
+
* -------------------------------------------------------------------------
|
|
59
|
+
* `encodeSignatureHeader` IS ASYNC. AWAIT IT. (A-651)
|
|
60
|
+
* -------------------------------------------------------------------------
|
|
61
|
+
*
|
|
62
|
+
* `@sanity/webhook@4.0.4` declares
|
|
63
|
+
*
|
|
64
|
+
* encodeSignatureHeader(payload: string, timestamp: number, secret: string):
|
|
65
|
+
* Promise<string>
|
|
66
|
+
*
|
|
67
|
+
* and nothing forces you to await it. Drop the `await` and the Promise is
|
|
68
|
+
* stringified into the header as the literal `[object Promise]`, which arrives
|
|
69
|
+
* here, fails `SIGNATURE_VALUE`, and is rejected as `malformed-signature`. The
|
|
70
|
+
* rejection is correct and the message is about the wire format, so it sends
|
|
71
|
+
* you to read Sanity's header spec — the one place the bug is not. TypeScript
|
|
72
|
+
* does not save you either: the value usually lands in a `Record<string,
|
|
73
|
+
* string>` built by a helper, or inside a template literal, both of which take
|
|
74
|
+
* a Promise without complaint.
|
|
75
|
+
*
|
|
76
|
+
* The rule: every call to `encodeSignatureHeader` is awaited, and the helper
|
|
77
|
+
* that wraps it is `async` rather than returning the Promise for someone else
|
|
78
|
+
* to forget. The content-client compatibility tests and CMS signer tests await every
|
|
79
|
+
* encoder call; this note exists so the next one
|
|
80
|
+
* is too, because the symptom will not tell you.
|
|
81
|
+
*/
|
|
82
|
+
/** Sanity's header. Lower-cased; `Headers.get` is case-insensitive either way. */
|
|
83
|
+
export declare const SANITY_SIGNATURE_HEADER = "sanity-webhook-signature";
|
|
84
|
+
/** 2021-01-01T00:00:00.000Z. Sanity's `MINIMUM_TIMESTAMP`; anything earlier is not a timestamp. */
|
|
85
|
+
export declare const MINIMUM_TIMESTAMP = 1609459200000;
|
|
86
|
+
/**
|
|
87
|
+
* How far from `now` a webhook timestamp may be, in milliseconds.
|
|
88
|
+
*
|
|
89
|
+
* Five minutes rather than A-44's sixty seconds: this one crosses Sanity's
|
|
90
|
+
* delivery queue rather than two NTP-synced clouds, and a retried delivery is a
|
|
91
|
+
* normal event. It is still a window rather than "forever", which is the whole
|
|
92
|
+
* difference from the toolkit.
|
|
93
|
+
*/
|
|
94
|
+
export declare const DEFAULT_TOLERANCE_MS = 300000;
|
|
95
|
+
export type WebhookRejection =
|
|
96
|
+
/** `SANITY_WEBHOOK_SECRET` is unset or empty. Fail closed. */
|
|
97
|
+
"no-secret"
|
|
98
|
+
/** No `sanity-webhook-signature` header. */
|
|
99
|
+
| "no-signature"
|
|
100
|
+
/** Header present but not `t=…,v1=…`, or `v1` is not decodable base64url. */
|
|
101
|
+
| "malformed-signature"
|
|
102
|
+
/** Before 2021, or outside the tolerance in either direction. */
|
|
103
|
+
| "stale-timestamp"
|
|
104
|
+
/** Well-formed, in window, wrong. */
|
|
105
|
+
| "bad-signature";
|
|
106
|
+
export type WebhookVerification = {
|
|
107
|
+
ok: true;
|
|
108
|
+
} | {
|
|
109
|
+
ok: false;
|
|
110
|
+
reason: WebhookRejection;
|
|
111
|
+
};
|
|
112
|
+
/**
|
|
113
|
+
* Verify a Sanity webhook delivery.
|
|
114
|
+
*
|
|
115
|
+
* `rawBody` must be the bytes as received — `await request.text()`, never
|
|
116
|
+
* `JSON.stringify(await request.json())`. A parse-and-restringify is not a
|
|
117
|
+
* byte-for-byte round trip (key order, number formatting, whitespace) and one
|
|
118
|
+
* byte changes the whole digest, so the symptom is every webhook failing after
|
|
119
|
+
* a refactor that looked like tidying.
|
|
120
|
+
*
|
|
121
|
+
* The `reason` is for our logs and our tests. It is never returned to the
|
|
122
|
+
* caller: "your signature was fine but your clock is stale" is the next step in
|
|
123
|
+
* an attack, handed over free.
|
|
124
|
+
*/
|
|
125
|
+
export declare function verifySanityWebhook(options: {
|
|
126
|
+
secret: string | undefined;
|
|
127
|
+
rawBody: string;
|
|
128
|
+
headers: {
|
|
129
|
+
get(name: string): string | null;
|
|
130
|
+
};
|
|
131
|
+
now?: number;
|
|
132
|
+
toleranceMs?: number;
|
|
133
|
+
}): Promise<WebhookVerification>;
|