create-ailk 0.46.6 → 0.47.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,38 +1,71 @@
1
1
  /**
2
2
  * The hub read of the site's identity and seo (#11456, spec
3
- * docs/specs/11456-a-hub-connected-site-reads-spec.md D3).
3
+ * docs/specs/11456-a-hub-connected-site-reads-spec.md D3; #12390, spec
4
+ * docs/specs/12390-a-single-tenant-site-shows-what-its-admin-saves-spec.md
5
+ * D2, D3).
4
6
  *
5
- * A HUB-CONNECTED site — one with a spoke key that would go on the wire
6
- * (`sendsSpokeKey()`), whatever its content adapter (#11515) — reads its
7
- * identity and seo from `GET /v1/content/site-config`, which answers its own
8
- * workspace's rows; a site serving file content with a key reads them too. A
9
- * site with no key makes no call and keeps reading `content/_site.mdx`:
10
- * without a key the route can only answer 401.
7
+ * A HUB-CONNECTED site reads its identity and seo from
8
+ * `GET /v1/content/site-config`, whatever its content adapter (#11515). It is
9
+ * one of two kinds:
10
+ * - a spoke: a spoke key that would go on the wire (`sendsSpokeKey()`); the
11
+ * route answers the key's own workspace;
12
+ * - a single-tenant site: no key, but an API address it names
13
+ * (`apiBaseConfigured()`) over `https:` or loopback (`isSafeTransport`,
14
+ * the key's own transport rule); the route answers the deployment's one
15
+ * workspace, and 401 on a hub, or on a deployment with zero or several
16
+ * workspaces or a sole one that is not the seeded default.
17
+ * A site with neither makes no call and keeps reading `content/_site.mdx`;
18
+ * `getApiBase()`'s `localhost:3001` default is not an address it names.
11
19
  *
12
20
  * Cached with Next's `unstable_cache` under `siteConfigTag()` for at most
13
21
  * `HUB_SITE_REVALIDATE_SECONDS`. The `site-config` revalidate event an Admin
14
22
  * save fires purges the tag (`app/api/revalidate/route.ts`); the expiry is the
15
- * safety net for a spoke with no `revalidateUrl`. The key parts carry a
23
+ * safety net for a site with no revalidate target. The key parts carry a
16
24
  * digest of the spoke key — never the key — so two deployments with different
17
- * keys sharing one data cache never share an entry (SEC-11456-2).
25
+ * keys sharing one data cache never share an entry (SEC-11456-2); a keyless
26
+ * read's part is `keyless:` plus a digest of the API address, so it never
27
+ * shares an entry with a keyed read or a site with another API
28
+ * (SEC-12390-3).
18
29
  *
19
30
  * Inside the cached callback a non-2xx, a throw, a read slower than
20
31
  * `HUB_SITE_TIMEOUT_MS` or a body without the two keys THROWS, so nothing is
21
32
  * written and Next keeps serving the last entry (`page-renderer`'s
22
- * `api-source.ts` failure rule). Outside, a failure answers this instance's
23
- * last good value, else `undefined` — so a hub outage never reaches a page.
24
- * The timeout does not abort the request (`http.ts`'s `get` takes no signal).
33
+ * `api-source.ts` failure rule). One exception: a keyless read the API
34
+ * refuses (401) resolves no rows, so the refusal is cached like a workspace
35
+ * with none and the site renders from its file, with one warn per held
36
+ * answer (SEC-12390-4); a keyed 401 still throws, so a spoke whose key was
37
+ * revoked keeps its last good value. Outside, a failure answers this
38
+ * instance's last good value, else `undefined` — so a hub outage never
39
+ * reaches a page — and a failed keyless read makes this instance wait
40
+ * `HUB_SITE_RETRY_SECONDS` before asking again (SEC-12390-5). The timeout
41
+ * does not abort the request (`http.ts`'s `get` takes no signal).
25
42
  *
26
43
  * One read per request: `readHubSite` is wrapped in React's `cache()`, so
27
44
  * the layout's metadata, its render and every page's JSON-LD share it.
28
45
  *
46
+ * The workspace's site navigation rides the same read (#12401, spec
47
+ * docs/specs/12401-a-site-renders-its-header-spec.md D1): `navigation` is
48
+ * `{ version, record }` when the body carries one `siteNavigationSchema`
49
+ * accepts, else `null` — an absent key (a hub older than #12400), `null`, a
50
+ * version that is not a positive integer or a record the schema refuses, the
51
+ * last two with one warning per distinct refused field path, naming the path
52
+ * and never a value. The schema check is the only barrier between a hub value
53
+ * and a link (`localeHref` passes any scheme through), so only its parsed
54
+ * output is kept. `identity` and `seo` are parsed as before in every case.
55
+ *
29
56
  * `site-brand.tsx`, `site-identity.ts`, `site-contact-email.ts` and
30
57
  * `site-contact-lines.ts` import this module; it imports none of them.
31
58
  */
32
59
 
33
60
  import { createHash } from "node:crypto";
34
61
 
35
- import { sendsSpokeKey, siteConfig } from "@working-theory/api-client";
62
+ import {
63
+ apiBaseConfigured,
64
+ getApiBase,
65
+ isSafeTransport,
66
+ sendsSpokeKey,
67
+ siteConfig,
68
+ } from "@working-theory/api-client";
36
69
  import {
37
70
  siteConfigTag,
38
71
  siteWorkspaceSegment,
@@ -43,38 +76,111 @@ import {
43
76
  type SEO,
44
77
  type SiteIdentity,
45
78
  } from "@working-theory/site-config/schema";
79
+ import {
80
+ siteNavigationSchema,
81
+ siteNavigationVersionSchema,
82
+ type SiteNavigation,
83
+ } from "@working-theory/validation";
46
84
  import { cache } from "react";
47
85
  import type { ZodType } from "zod";
48
86
 
49
- /** The workspace's identity and seo rows as the site reads them; each `null` when absent or unreadable. */
87
+ /** The workspace's navigation record and the version it was saved at (#12401 D1). */
88
+ export interface HubNavigation {
89
+ version: number;
90
+ record: SiteNavigation;
91
+ }
92
+
93
+ /** The workspace's identity, seo and navigation rows as the site reads them; each `null` when absent or unreadable. */
50
94
  export interface HubSite {
51
95
  identity: SiteIdentity | null;
52
96
  seo: SEO | null;
97
+ navigation: HubNavigation | null;
53
98
  }
54
99
 
100
+ /**
101
+ * The cache key's shape part, bumped whenever the parsed `HubSite` shape or
102
+ * the schema it is checked with changes, so an entry written by older site
103
+ * code is never served as this shape (#12401 D1).
104
+ */
105
+ const HUB_SITE_SHAPE = "nav1";
106
+
55
107
  /** How long one hub read is served before it is read again. */
56
108
  export const HUB_SITE_REVALIDATE_SECONDS = 300;
57
109
  /** A read slower than this is a failed read. */
58
110
  export const HUB_SITE_TIMEOUT_MS = 3_000;
111
+ /** How long an instance waits after a failed keyless read (the discovery reader's hold). */
112
+ export const HUB_SITE_RETRY_SECONDS = 15;
59
113
 
60
114
  /**
61
- * Whether this site reads its identity and seo from the hub: a spoke key on
62
- * the wire, whatever the content adapter (#11515).
115
+ * Whether this site reads its identity and seo from the hub, whatever the
116
+ * content adapter (#11515): a spoke key on the wire, or an API address it
117
+ * names over `https:` or loopback (#12390 D2).
63
118
  */
64
119
  export function hubConnected(): boolean {
65
- return sendsSpokeKey();
120
+ return (
121
+ sendsSpokeKey() || (apiBaseConfigured() && isSafeTransport(getApiBase()))
122
+ );
66
123
  }
67
124
 
68
125
  /** The last value `readHubSite` resolved on this instance. */
69
126
  let held: HubSite | undefined;
127
+ /** Until when this instance makes no keyless read (epoch ms), after one failed. */
128
+ let keylessRetryAt = 0;
70
129
 
71
130
  function parsedOrNull<T>(schema: ZodType<T>, value: unknown): T | null {
72
131
  const parsed = schema.safeParse(value);
73
132
  return parsed.success ? parsed.data : null;
74
133
  }
75
134
 
76
- /** One hub read. Throws on any failure, so the cache writes nothing. */
77
- async function fetchHubSite(): Promise<HubSite> {
135
+ /** The refused navigation field paths this process has warned about. */
136
+ const warnedNavigationPaths = new Set<string>();
137
+
138
+ /**
139
+ * A refused field's path, with every segment a hub value chose masked — a
140
+ * `byLocale` key, or any segment that is not an index or a plain field name —
141
+ * so it never carries a value.
142
+ */
143
+ function fieldPath(path: readonly PropertyKey[]): string {
144
+ const parts = path.map((part, i) =>
145
+ typeof part === "number" ||
146
+ (typeof part === "string" && /^[A-Za-z]{1,32}$/.test(part) && path[i - 1] !== "byLocale")
147
+ ? String(part)
148
+ : "*",
149
+ );
150
+ return parts.length > 0 ? parts.join(".") : "(record)";
151
+ }
152
+
153
+ function navigationUnreadable(path: string): null {
154
+ if (!warnedNavigationPaths.has(path)) {
155
+ warnedNavigationPaths.add(path);
156
+ console.warn(
157
+ `[hub-site-config] navigation unreadable at ${path}; rendering the site's own navigation`,
158
+ );
159
+ }
160
+ return null;
161
+ }
162
+
163
+ /** The body's `navigation`, parsed, else `null` (#12401 D1). */
164
+ function navigationOrNull(value: unknown): HubNavigation | null {
165
+ if (value === undefined || value === null) return null;
166
+ if (typeof value !== "object" || Array.isArray(value)) {
167
+ return navigationUnreadable("navigation");
168
+ }
169
+ const { version, record } = value as { version?: unknown; record?: unknown };
170
+ const parsedVersion = siteNavigationVersionSchema.safeParse(version);
171
+ if (!parsedVersion.success) return navigationUnreadable("version");
172
+ const parsedRecord = siteNavigationSchema.safeParse(record);
173
+ if (!parsedRecord.success) {
174
+ return navigationUnreadable(fieldPath(parsedRecord.error.issues[0]?.path ?? []));
175
+ }
176
+ return { version: parsedVersion.data, record: parsedRecord.data };
177
+ }
178
+
179
+ /**
180
+ * One hub read. Throws on any failure, so the cache writes nothing — except
181
+ * a keyless read's 401, which resolves no rows (#12390 D3).
182
+ */
183
+ async function fetchHubSite(keyed: boolean): Promise<HubSite> {
78
184
  let timer: ReturnType<typeof setTimeout> | undefined;
79
185
  const timeout = new Promise<never>((_resolve, reject) => {
80
186
  timer = setTimeout(
@@ -85,6 +191,12 @@ async function fetchHubSite(): Promise<HubSite> {
85
191
  });
86
192
  try {
87
193
  const res = await Promise.race([siteConfig.get(), timeout]);
194
+ if (!res.ok && res.status === 401 && !keyed) {
195
+ console.warn(
196
+ "[hub-site-config] the API refused a keyless read (401); rendering from content/_site.mdx",
197
+ );
198
+ return { identity: null, seo: null, navigation: null };
199
+ }
88
200
  if (!res.ok) throw new Error(`hub site-config read answered ${res.status}`);
89
201
  const body: unknown = res.body;
90
202
  if (
@@ -98,22 +210,30 @@ async function fetchHubSite(): Promise<HubSite> {
98
210
  return {
99
211
  identity: parsedOrNull(SiteIdentitySchema, body.identity),
100
212
  seo: parsedOrNull(SEOSchema, body.seo),
213
+ navigation: navigationOrNull("navigation" in body ? body.navigation : undefined),
101
214
  };
102
215
  } finally {
103
216
  clearTimeout(timer);
104
217
  }
105
218
  }
106
219
 
107
- /** The first 16 hex of the spoke key's SHA-256 — a cache-key part, never the key. */
108
- function spokeKeyDigest(): string {
109
- return createHash("sha256")
110
- .update((process.env.AILK_SPOKE_KEY ?? "").trim(), "utf8")
111
- .digest("hex")
112
- .slice(0, 16);
220
+ /** The first 16 hex of a value's SHA-256 — a cache-key part, never the value. */
221
+ function digest16(value: string): string {
222
+ return createHash("sha256").update(value, "utf8").digest("hex").slice(0, 16);
223
+ }
224
+
225
+ /**
226
+ * The cache key's third part: the spoke key's digest for a keyed read, else
227
+ * `keyless:` plus the API address's digest (SEC-12390-3).
228
+ */
229
+ function callerKeyPart(keyed: boolean): string {
230
+ return keyed
231
+ ? digest16((process.env.AILK_SPOKE_KEY ?? "").trim())
232
+ : `keyless:${digest16(getApiBase())}`;
113
233
  }
114
234
 
115
235
  /**
116
- * The hub's identity and seo for this site, or `undefined` when the site is
236
+ * The hub's identity, seo and navigation for this site, or `undefined` when the site is
117
237
  * not hub-connected (no call made) or no read has ever succeeded here.
118
238
  * Never rejects. Shared within one request (React `cache()`).
119
239
  */
@@ -121,17 +241,20 @@ export const readHubSite = cache(async function readHubSite(): Promise<
121
241
  HubSite | undefined
122
242
  > {
123
243
  if (!hubConnected()) return undefined;
244
+ const keyed = sendsSpokeKey();
245
+ if (!keyed && Date.now() < keylessRetryAt) return held;
124
246
  try {
125
247
  // Loaded only on the hub-connected path, so a site that is not one loads
126
248
  // nothing it did not load before.
127
249
  const { unstable_cache } = await import("next/cache");
128
250
  const read = unstable_cache(
129
- fetchHubSite,
130
- ["ailk-hub-site-config", siteWorkspaceSegment(), spokeKeyDigest()],
251
+ () => fetchHubSite(keyed),
252
+ ["ailk-hub-site-config", siteWorkspaceSegment(), callerKeyPart(keyed), HUB_SITE_SHAPE],
131
253
  { tags: [siteConfigTag()], revalidate: HUB_SITE_REVALIDATE_SECONDS },
132
254
  );
133
255
  held = await read();
134
256
  } catch (err) {
257
+ if (!keyed) keylessRetryAt = Date.now() + HUB_SITE_RETRY_SECONDS * 1_000;
135
258
  console.warn(
136
259
  `[hub-site-config] read failed (${err instanceof Error ? err.name : typeof err}); serving the last good value`,
137
260
  );
@@ -148,7 +271,9 @@ export function heldHubSite(): HubSite | undefined {
148
271
  return hubConnected() ? held : undefined;
149
272
  }
150
273
 
151
- /** Test seam: forget the held value. */
274
+ /** Test seam: forget the held value, any keyless wait and the navigation warnings. */
152
275
  export function __resetHubSiteForTests(): void {
153
276
  held = undefined;
277
+ keylessRetryAt = 0;
278
+ warnedNavigationPaths.clear();
154
279
  }
@@ -38,6 +38,7 @@ import {
38
38
  type SiteLayout,
39
39
  } from "@working-theory/site-config/schema";
40
40
  import { conventionPath, ROUTES } from "@working-theory/templates/routes";
41
+ import type { SiteNavigation } from "@working-theory/validation";
41
42
  import { readLocales } from "@working-theory/web-i18n";
42
43
  import { cache } from "react";
43
44
  import { parse as parseYaml } from "yaml";
@@ -51,8 +52,10 @@ import {
51
52
  resolveTypeAndSlug,
52
53
  } from "./deck-page";
53
54
  import { toInternalDocsPath } from "./docs-path";
55
+ import { readHubSite } from "./hub-site-config";
54
56
  import { SERVICES_ROUTE, toInternalServicesPath } from "./services-path";
55
57
  import { resolveContentRoot } from "./site-brand";
58
+ import { safeNavigationChrome, type NavigationChrome } from "./site-navigation";
56
59
 
57
60
  /** The chrome settings a site sets in `_site.mdx`. */
58
61
  export interface SiteChromeSettings {
@@ -167,6 +170,60 @@ export const readSiteChromeSettings = cache(
167
170
  },
168
171
  );
169
172
 
173
+ /**
174
+ * The file settings with the hub navigation record's styles laid over them
175
+ * (#12401 D4): the record's header and footer style, and each route family's
176
+ * `header` and `footer`, win where the record sets them; every other value —
177
+ * the layout, a family's `path` — is the file's. Returns new objects and never
178
+ * changes `site`, which `readSiteChromeSettings` shares across the request.
179
+ */
180
+ export function withNavigationStyles(
181
+ site: SiteChromeSettings,
182
+ record: SiteNavigation | null,
183
+ ): SiteChromeSettings {
184
+ if (record === null) return site;
185
+ const families: SiteChromeSettings["families"] = { ...site.families };
186
+ for (const key of ROUTE_FAMILY_KEYS) {
187
+ const styles = record.families?.[key];
188
+ if (styles?.header === undefined && styles?.footer === undefined) continue;
189
+ families[key] = {
190
+ ...site.families[key],
191
+ ...(styles.header !== undefined ? { header: styles.header } : {}),
192
+ ...(styles.footer !== undefined ? { footer: styles.footer } : {}),
193
+ };
194
+ }
195
+ const headerStyle = record.header.style ?? site.headerStyle;
196
+ const footerStyle = record.footer.style ?? site.footerStyle;
197
+ return {
198
+ ...site,
199
+ ...(headerStyle !== undefined ? { headerStyle } : {}),
200
+ ...(footerStyle !== undefined ? { footerStyle } : {}),
201
+ families,
202
+ };
203
+ }
204
+
205
+ /** The hub navigation record a page renders, with its translation (#12401 D3). */
206
+ export interface RecordNavigation {
207
+ version: number;
208
+ record: SiteNavigation;
209
+ chrome: NavigationChrome;
210
+ }
211
+
212
+ /**
213
+ * The hub navigation record this request renders for `locale`, with its
214
+ * translation (#12401 D3, D4) — `null` when the hub read carries none or the
215
+ * translator refuses it. `resolveHomeChrome` answers it, so the record's
216
+ * styles apply exactly when its links render.
217
+ */
218
+ const readRecordNavigation = cache(async function readRecordNavigation(
219
+ locale: string,
220
+ ): Promise<RecordNavigation | null> {
221
+ const navigation = (await readHubSite())?.navigation ?? null;
222
+ if (navigation === null) return null;
223
+ const chrome = safeNavigationChrome(navigation.record, locale);
224
+ return chrome === null ? null : { version: navigation.version, record: navigation.record, chrome };
225
+ });
226
+
170
227
  /** The closing footer's site settings (#10550 D3). */
171
228
  export interface ClosingFooterSettings {
172
229
  locality?: string;
@@ -394,18 +451,28 @@ function templateChrome(
394
451
 
395
452
  /**
396
453
  * The home's layout and chrome — the one resolution both the layout and the
397
- * home page read, so the bar and the landing can never disagree.
454
+ * home page read, so the bar and the landing can never disagree. The site
455
+ * settings are `_site.mdx`'s with the hub navigation record's styles over
456
+ * them (#12401 D4) — only when the record renders, so a refused record's
457
+ * files keep the files' styles. `navigation` is that record, for the layout.
398
458
  */
399
459
  export async function resolveHomeChrome(
400
460
  locale: string,
401
461
  chrome: ChromeKnobs,
402
- ): Promise<{ layout: SiteLayout; chrome: ResolvedChrome; site: SiteChromeSettings }> {
403
- const site = readSiteChromeSettings();
462
+ ): Promise<{
463
+ layout: SiteLayout;
464
+ chrome: ResolvedChrome;
465
+ site: SiteChromeSettings;
466
+ navigation: RecordNavigation | null;
467
+ }> {
468
+ const navigation = await readRecordNavigation(locale);
469
+ const site = withNavigationStyles(readSiteChromeSettings(), navigation?.record ?? null);
404
470
  const page = await resolveChromePage("/", locale);
405
471
  const layout = resolveHomeLayout(site, page, chrome);
406
472
  return {
407
473
  layout,
408
474
  site,
475
+ navigation,
409
476
  chrome: resolvePageChrome({
410
477
  isHome: true,
411
478
  homeIsDeck: layout === "deck",
@@ -0,0 +1,208 @@
1
+ /**
2
+ * A site's navigation from its hub (#12401, spec
3
+ * docs/specs/12401-a-site-renders-its-header-spec.md D2, D3).
4
+ *
5
+ * `navigationChrome` turns the workspace's navigation record (#12400 D1) into
6
+ * the props the locale layout hands `Nav` and `Footer` — the components'
7
+ * names and props do not change. It is pure: no I/O, and no environment read
8
+ * beyond the three its path helpers make (the docs base, the services base
9
+ * and the route-family renames `pagePath` applies).
10
+ *
11
+ * - A `page` target links to the page's public path on this site:
12
+ * `pagePath` puts a service at the services base and applies the
13
+ * route-family renames, and `toPublicDocsHref` moves `/docs` to the docs
14
+ * path. A `path` or `url` target is used as stored — the record holds the
15
+ * address a visitor sees. No locale prefix is added: the chrome adds it.
16
+ * - A label is the visitor's locale's text when the record has one, else its
17
+ * default text. Every key made here contains a dot and no `nav` message key
18
+ * does, so a record label never replaces a translated one; keys are by
19
+ * position, so two links with the same label stay two links.
20
+ * - Order is the record's; nothing is added, merged or sorted. The hub has
21
+ * already left out every item whose page is not live (#12400 D5).
22
+ * - Every address it emits is checked before it returns, by the record's own
23
+ * target rules: a site path or an `http:`/`https:` URL. Anything else throws, so
24
+ * `safeNavigationChrome` answers `null` and the site's own files render.
25
+ *
26
+ * It imports no site module but `docs-path` and `services-path`, so it closes
27
+ * no import cycle (#12385).
28
+ */
29
+
30
+ import { pagePath } from "@working-theory/templates/routes";
31
+ import type { NavItem } from "@working-theory/ui";
32
+ import {
33
+ siteNavigationTargetSchema,
34
+ type SiteNavigation,
35
+ type SiteNavigationLabel,
36
+ type SiteNavigationLink,
37
+ type SiteNavigationTarget,
38
+ } from "@working-theory/validation";
39
+
40
+ import { toPublicDocsHref } from "./docs-path";
41
+ import { SERVICES_PATH } from "./services-path";
42
+
43
+ type NavFlyoutFeature = NonNullable<NavItem["flyout"]>["features"][number];
44
+
45
+ /** A link with a label already in the visitor's locale. */
46
+ export interface NavigationLink {
47
+ label: string;
48
+ href: string;
49
+ }
50
+
51
+ /** What the layout puts into `Nav` and `Footer` from a record. */
52
+ export interface NavigationChrome {
53
+ /** `Nav`'s and `Footer`'s `navItems`. */
54
+ navItems: NavItem[];
55
+ /** `Footer`'s `columns`. */
56
+ columns: {
57
+ heading: string;
58
+ headingKey: string;
59
+ items: { labelKey: string; path: string; label: string }[];
60
+ }[];
61
+ /** Every label, heading and description, merged into the layout's label map. */
62
+ labels: Record<string, string>;
63
+ /** The signed-out header's button. */
64
+ button?: NavigationLink;
65
+ signIn?: "link" | "hidden";
66
+ /** The bottom bar's links, before the cookie-settings link. */
67
+ legalLinks: NavigationLink[];
68
+ /** The closing footer's locality line and actions. */
69
+ closing?: { locality?: string; actions: NavigationLink[] };
70
+ }
71
+
72
+ /**
73
+ * Whether an emitted address passes the record's own target rules — a site
74
+ * path (one leading `/` not followed by `/` or a backslash, no whitespace or
75
+ * backslash), else an `http:`/`https:` URL with no user or password — the
76
+ * schema's checks, shared rather than restated.
77
+ */
78
+ function isSafeAddress(address: string): boolean {
79
+ return siteNavigationTargetSchema.safeParse(
80
+ address.startsWith("/") ? { kind: "path", path: address } : { kind: "url", href: address },
81
+ ).success;
82
+ }
83
+
84
+ /**
85
+ * The record's header and footer as the layout's chrome props, for the
86
+ * visitor's `locale`. Throws on an address that is neither a site path nor an
87
+ * `http:`/`https:` URL.
88
+ */
89
+ export function navigationChrome(record: SiteNavigation, locale: string): NavigationChrome {
90
+ const wanted = locale.toLowerCase();
91
+ const labels: Record<string, string> = {};
92
+ const emitted: string[] = [];
93
+
94
+ const text = (label: SiteNavigationLabel): string => {
95
+ for (const [code, value] of Object.entries(label.byLocale ?? {})) {
96
+ if (code.toLowerCase() === wanted) return value;
97
+ }
98
+ return label.text;
99
+ };
100
+ const addressOf = (target: SiteNavigationTarget): string => {
101
+ const address =
102
+ target.kind === "page"
103
+ ? toPublicDocsHref(pagePath({ type: target.address.type, slug: target.address.slug }, SERVICES_PATH))
104
+ : target.kind === "path"
105
+ ? target.path
106
+ : target.href;
107
+ emitted.push(address);
108
+ return address;
109
+ };
110
+ const linkOf = (link: SiteNavigationLink): NavigationLink => ({
111
+ label: text(link.label),
112
+ href: addressOf(link.target),
113
+ });
114
+ const keyed = (key: string, link: SiteNavigationLink): NavFlyoutFeature => {
115
+ labels[key] = text(link.label);
116
+ const feature: NavFlyoutFeature = { labelKey: key, path: addressOf(link.target) };
117
+ if (link.description !== undefined) {
118
+ labels[`${key}.d`] = text(link.description);
119
+ feature.descKey = `${key}.d`;
120
+ }
121
+ return feature;
122
+ };
123
+
124
+ const navItems = record.header.items.map((item, i): NavItem => {
125
+ const key = `rec.h${i}`;
126
+ labels[key] = text(item.label);
127
+ if (item.kind === "link") return { labelKey: key, path: addressOf(item.target) };
128
+ const [only] = item.groups;
129
+ if (item.groups.length === 1 && only !== undefined && only.heading === undefined) {
130
+ const features = only.links.map((link, l) => keyed(`${key}.g0.l${l}`, link));
131
+ const described = features.some((feature) => feature.descKey !== undefined);
132
+ return {
133
+ labelKey: key,
134
+ flyout: described
135
+ ? { features, presentation: "grid", width: "panel" }
136
+ : { features, presentation: "list", width: "trigger" },
137
+ };
138
+ }
139
+ const groups = item.groups.map((group, g) => {
140
+ const headingKey = `${key}.g${g}`;
141
+ labels[headingKey] = group.heading === undefined ? "" : text(group.heading);
142
+ return {
143
+ headingKey,
144
+ items: group.links.map((link, l) => keyed(`${headingKey}.l${l}`, link)),
145
+ };
146
+ });
147
+ return {
148
+ labelKey: key,
149
+ flyout: { features: groups.flatMap((group) => group.items), groups, width: "panel" },
150
+ };
151
+ });
152
+
153
+ const columns = record.footer.columns.map((column, c) => {
154
+ const headingKey = `rec.f${c}`;
155
+ const heading = text(column.heading);
156
+ labels[headingKey] = heading;
157
+ return {
158
+ heading,
159
+ headingKey,
160
+ items: column.links.map((link, l) => {
161
+ const labelKey = `${headingKey}.l${l}`;
162
+ const label = text(link.label);
163
+ labels[labelKey] = label;
164
+ return { labelKey, path: addressOf(link.target), label };
165
+ }),
166
+ };
167
+ });
168
+
169
+ const { button, signIn } = record.header;
170
+ const { closing } = record.footer;
171
+ const chrome: NavigationChrome = {
172
+ navItems,
173
+ columns,
174
+ labels,
175
+ legalLinks: (record.footer.bottomBar?.links ?? []).map(linkOf),
176
+ ...(button !== undefined ? { button: linkOf(button) } : {}),
177
+ ...(signIn !== undefined ? { signIn } : {}),
178
+ ...(closing !== undefined
179
+ ? {
180
+ closing: {
181
+ ...(closing.location !== undefined ? { locality: closing.location } : {}),
182
+ actions: closing.buttons.map(linkOf),
183
+ },
184
+ }
185
+ : {}),
186
+ };
187
+
188
+ for (const address of emitted) {
189
+ if (!isSafeAddress(address)) throw new TypeError("navigation address refused");
190
+ }
191
+ return chrome;
192
+ }
193
+
194
+ /**
195
+ * `navigationChrome`, or `null` when it throws — with one warning naming the
196
+ * error's kind, never a value — so a record that cannot be rendered never
197
+ * throws into a page and the site's own files render.
198
+ */
199
+ export function safeNavigationChrome(record: SiteNavigation, locale: string): NavigationChrome | null {
200
+ try {
201
+ return navigationChrome(record, locale);
202
+ } catch (err) {
203
+ console.warn(
204
+ `[site-navigation] record not rendered (${err instanceof Error ? err.name : typeof err})`,
205
+ );
206
+ return null;
207
+ }
208
+ }
@@ -11,7 +11,7 @@ import {
11
11
  ROUTES,
12
12
  SERVICES_ROUTE,
13
13
  } from "@working-theory/templates/routes";
14
- import { assetRemotePattern } from "@working-theory/validation";
14
+ import { assetImageConfigWarning, assetRemotePattern } from "@working-theory/validation";
15
15
  import { parseStealth } from "@working-theory/web-i18n/stealth";
16
16
  import { withBotId } from "botid/next/config";
17
17
 
@@ -401,10 +401,20 @@ process.env.NEXT_PUBLIC_AILK_ROUTE_PATHS = routePathsAtBuild;
401
401
  // which the hub resolves to its own `/v1/assets/:id` URLs. `next/image` admits
402
402
  // that path on the hub's origin, and nothing else, when `AILK_API_URL` (the
403
403
  // server-side hub origin this site already reads) is an http(s) URL at build
404
- // time; otherwise there is no `images` key, as before. A change of hub origin
405
- // needs a rebuild.
404
+ // time; otherwise there are no remote patterns. A change of hub origin needs a
405
+ // rebuild.
406
+ //
407
+ // #12428 D4 (M3) — `minimumCacheTTL: 60` always, in place of Next's four-hour
408
+ // default, so a made-private, disabled or deleted image leaves this site's
409
+ // image cache within a minute of the hub and the store dropping it.
406
410
  const assetPatternAtBuild = assetRemotePattern(process.env.AILK_API_URL);
407
411
 
412
+ // #12420 D7 — every site that reads hub pages needs that origin, not only a
413
+ // spoke: a database site built without it is told so, once, by name. It
414
+ // reads `CONTENT_ADAPTER` and `AILK_API_URL` only.
415
+ const assetConfigWarning = assetImageConfigWarning(process.env);
416
+ if (assetConfigWarning !== null) console.warn(`[next.config] ${assetConfigWarning}`);
417
+
408
418
  /** @type {import('next').NextConfig} */
409
419
  const nextConfig = {
410
420
  reactStrictMode: true,
@@ -519,9 +529,12 @@ const nextConfig = {
519
529
  // mutates a tracked file as a side effect of running the dev server,
520
530
  // which this scaffold does not want.
521
531
  agentRules: false,
522
- ...(assetPatternAtBuild === null
523
- ? {}
524
- : { images: { remotePatterns: [assetPatternAtBuild] } }),
532
+ images: {
533
+ minimumCacheTTL: 60,
534
+ ...(assetPatternAtBuild === null
535
+ ? {}
536
+ : { remotePatterns: [assetPatternAtBuild] }),
537
+ },
525
538
  env: {
526
539
  // Comma-separated locale list baked at build time — consumed by middleware
527
540
  // and the sitemap route. NEXT_PUBLIC_ prefix makes it available in Edge