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.
- package/dist/lib/env-catalog.js +4 -0
- package/package.json +3 -3
- package/templates/apps/api/.env.example +18 -0
- package/templates/apps/api/CLAUDE.md +1 -0
- package/templates/apps/api/src/__tests__/vercel-handler.test.ts +176 -2
- package/templates/apps/api/src/lib/__mocks__/prisma.ts +16 -0
- package/templates/apps/api/src/vercel-handler.ts +32 -2
- package/templates/apps/mcp/.env.example +8 -0
- package/templates/apps/mcp/CLAUDE.md +2 -2
- package/templates/apps/web/CLAUDE.md +19 -3
- package/templates/apps/web/app/[locale]/layout.tsx +98 -37
- package/templates/apps/web/app/llms.txt/__tests__/site-listing.test.ts +13 -3
- package/templates/apps/web/lib/__tests__/hub-site-config.test.ts +394 -10
- package/templates/apps/web/lib/__tests__/page-chrome-navigation.test.ts +194 -0
- package/templates/apps/web/lib/__tests__/site-identity-feature-list.test.ts +19 -1
- package/templates/apps/web/lib/__tests__/site-navigation.test.ts +288 -0
- package/templates/apps/web/lib/hub-site-config.ts +154 -29
- package/templates/apps/web/lib/page-chrome.ts +70 -3
- package/templates/apps/web/lib/site-navigation.ts +208 -0
- package/templates/apps/web/next.config.mjs +19 -6
- package/versions.json +51 -51
|
@@ -4,15 +4,21 @@
|
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* The hub read of the site's identity and seo (#11456, spec
|
|
7
|
-
* docs/specs/11456-a-hub-connected-site-reads-spec.md D3; AC-2, AC-3)
|
|
7
|
+
* docs/specs/11456-a-hub-connected-site-reads-spec.md D3; AC-2, AC-3), and
|
|
8
|
+
* the keyless read of a single-tenant site (#12390, spec
|
|
9
|
+
* docs/specs/12390-a-single-tenant-site-shows-what-its-admin-saves-spec.md
|
|
10
|
+
* D2, D3; AC-4, AC-5).
|
|
8
11
|
*
|
|
9
12
|
* External boundaries doubled:
|
|
10
13
|
* - `@working-theory/api-client`'s `siteConfig.get` — the HTTP call to the
|
|
11
|
-
* hub (`sendsSpokeKey`
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
14
|
+
* hub (`sendsSpokeKey`, `apiBaseConfigured` and `isSafeTransport` stay
|
|
15
|
+
* real, so the switch is the env's);
|
|
16
|
+
* - `next/cache`'s `unstable_cache` — a fake with Next's rules: an entry is
|
|
17
|
+
* served while it stands, a RESOLVED callback is written, a THROWING one
|
|
18
|
+
* writes nothing and the last entry is served (`unstable-cache.js`
|
|
19
|
+
* `cacheNewResult`).
|
|
15
20
|
*/
|
|
21
|
+
import { createHash } from "node:crypto";
|
|
16
22
|
import { mkdtempSync, rmSync, writeFileSync } from "node:fs";
|
|
17
23
|
import { tmpdir } from "node:os";
|
|
18
24
|
import { join } from "node:path";
|
|
@@ -33,6 +39,7 @@ const mockUnstableCache = jest.fn(
|
|
|
33
39
|
) =>
|
|
34
40
|
async () => {
|
|
35
41
|
const key = keyParts.join("|");
|
|
42
|
+
if (mockCacheStore.has(key)) return mockCacheStore.get(key);
|
|
36
43
|
try {
|
|
37
44
|
const value = await fn();
|
|
38
45
|
mockCacheStore.set(key, value);
|
|
@@ -52,6 +59,7 @@ import { siteConfigTag } from "@working-theory/page-renderer/edge";
|
|
|
52
59
|
|
|
53
60
|
import {
|
|
54
61
|
__resetHubSiteForTests,
|
|
62
|
+
HUB_SITE_RETRY_SECONDS,
|
|
55
63
|
HUB_SITE_REVALIDATE_SECONDS,
|
|
56
64
|
HUB_SITE_TIMEOUT_MS,
|
|
57
65
|
heldHubSite,
|
|
@@ -70,7 +78,14 @@ const HUB_IDENTITY = {
|
|
|
70
78
|
const HUB_SEO = { version: "1", robots: { index: false } };
|
|
71
79
|
const ok = (data: unknown) => ({ ok: true, body: data });
|
|
72
80
|
|
|
73
|
-
const ENV_KEYS = [
|
|
81
|
+
const ENV_KEYS = [
|
|
82
|
+
"CONTENT_ADAPTER",
|
|
83
|
+
"AILK_SPOKE_KEY",
|
|
84
|
+
"AILK_API_URL",
|
|
85
|
+
"NEXT_PUBLIC_AILK_API_URL",
|
|
86
|
+
"NEXT_PUBLIC_API_URL",
|
|
87
|
+
"AILK_CONTENT_ROOT",
|
|
88
|
+
] as const;
|
|
74
89
|
const savedEnv = new Map(ENV_KEYS.map((k) => [k, process.env[k]]));
|
|
75
90
|
let root: string;
|
|
76
91
|
|
|
@@ -79,6 +94,19 @@ function hubConnect(): void {
|
|
|
79
94
|
process.env.AILK_API_URL = "https://hub.example";
|
|
80
95
|
}
|
|
81
96
|
|
|
97
|
+
/** A single-tenant site: its own API's address, no spoke key (#12390). */
|
|
98
|
+
function keylessConnect(address = "https://api.solo.example"): void {
|
|
99
|
+
delete process.env.AILK_SPOKE_KEY;
|
|
100
|
+
process.env.AILK_API_URL = address;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/** The warn lines a keyless refusal wrote. */
|
|
104
|
+
function refusalWarns(): unknown[][] {
|
|
105
|
+
return jest
|
|
106
|
+
.mocked(console.warn)
|
|
107
|
+
.mock.calls.filter((call) => String(call[0]).includes("refused"));
|
|
108
|
+
}
|
|
109
|
+
|
|
82
110
|
beforeEach(() => {
|
|
83
111
|
mockGet.mockReset();
|
|
84
112
|
mockUnstableCache.mockClear();
|
|
@@ -113,17 +141,49 @@ describe("hubConnected (#11456 D3, #11515)", () => {
|
|
|
113
141
|
process.env.CONTENT_ADAPTER = "database";
|
|
114
142
|
expect(hubConnected()).toBe(true);
|
|
115
143
|
delete process.env.AILK_SPOKE_KEY;
|
|
144
|
+
delete process.env.AILK_API_URL;
|
|
116
145
|
expect(hubConnected()).toBe(false);
|
|
117
146
|
});
|
|
118
147
|
});
|
|
119
148
|
|
|
149
|
+
describe("hubConnected — a key or a configured API address (#12390 D2, AC-4)", () => {
|
|
150
|
+
it("is true with a spoke key and no address (the loopback default carries the key)", () => {
|
|
151
|
+
process.env.AILK_SPOKE_KEY = KEY;
|
|
152
|
+
expect(hubConnected()).toBe(true);
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
it.each([
|
|
156
|
+
["an https: address", "AILK_API_URL", "https://api.solo.example"],
|
|
157
|
+
["a loopback http: address", "AILK_API_URL", "http://127.0.0.1:4000"],
|
|
158
|
+
["localhost on the browser name", "NEXT_PUBLIC_AILK_API_URL", "http://localhost:3001"],
|
|
159
|
+
["an https: address on the deprecated name", "NEXT_PUBLIC_API_URL", "https://api.solo.example"],
|
|
160
|
+
])("is true with %s and no key", (_label, name, address) => {
|
|
161
|
+
process.env[name] = address;
|
|
162
|
+
expect(hubConnected()).toBe(true);
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
it("is false with an http: address on another host and no key — never clear text to a remote host", () => {
|
|
166
|
+
process.env.AILK_API_URL = "http://api.solo.example";
|
|
167
|
+
expect(hubConnected()).toBe(false);
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
it("is false with neither; readHubSite answers undefined and never calls siteConfig.get", async () => {
|
|
171
|
+
expect(hubConnected()).toBe(false);
|
|
172
|
+
await expect(readHubSite()).resolves.toBeUndefined();
|
|
173
|
+
expect(mockGet).not.toHaveBeenCalled();
|
|
174
|
+
expect(mockUnstableCache).not.toHaveBeenCalled();
|
|
175
|
+
expect(heldHubSite()).toBeUndefined();
|
|
176
|
+
});
|
|
177
|
+
});
|
|
178
|
+
|
|
120
179
|
describe("readHubSite (#11456 D3, AC-3)", () => {
|
|
121
180
|
it.each([
|
|
122
181
|
["CONTENT_ADAPTER unset", () => undefined],
|
|
123
182
|
["CONTENT_ADAPTER=database", () => (process.env.CONTENT_ADAPTER = "database")],
|
|
124
|
-
])("with no AILK_SPOKE_KEY and %s answers undefined and never calls the hub", async (_label, arrange) => {
|
|
183
|
+
])("with no AILK_SPOKE_KEY, no API address and %s answers undefined and never calls the hub", async (_label, arrange) => {
|
|
125
184
|
hubConnect();
|
|
126
185
|
delete process.env.AILK_SPOKE_KEY;
|
|
186
|
+
delete process.env.AILK_API_URL;
|
|
127
187
|
arrange();
|
|
128
188
|
await expect(readHubSite()).resolves.toBeUndefined();
|
|
129
189
|
expect(mockGet).not.toHaveBeenCalled();
|
|
@@ -133,7 +193,7 @@ describe("readHubSite (#11456 D3, AC-3)", () => {
|
|
|
133
193
|
it("with a spoke key and CONTENT_ADAPTER unset reads the hub (#11515)", async () => {
|
|
134
194
|
hubConnect();
|
|
135
195
|
mockGet.mockResolvedValue(ok({ identity: HUB_IDENTITY, seo: HUB_SEO }));
|
|
136
|
-
await expect(readHubSite()).resolves.toEqual({ identity: HUB_IDENTITY, seo: HUB_SEO });
|
|
196
|
+
await expect(readHubSite()).resolves.toEqual({ identity: HUB_IDENTITY, seo: HUB_SEO, navigation: null });
|
|
137
197
|
expect(mockGet).toHaveBeenCalledTimes(1);
|
|
138
198
|
});
|
|
139
199
|
|
|
@@ -141,7 +201,7 @@ describe("readHubSite (#11456 D3, AC-3)", () => {
|
|
|
141
201
|
hubConnect();
|
|
142
202
|
mockGet.mockResolvedValue(ok({ identity: HUB_IDENTITY, seo: HUB_SEO }));
|
|
143
203
|
|
|
144
|
-
await expect(readHubSite()).resolves.toEqual({ identity: HUB_IDENTITY, seo: HUB_SEO });
|
|
204
|
+
await expect(readHubSite()).resolves.toEqual({ identity: HUB_IDENTITY, seo: HUB_SEO, navigation: null });
|
|
145
205
|
|
|
146
206
|
expect(mockUnstableCache).toHaveBeenCalledTimes(1);
|
|
147
207
|
const [, keyParts, options] = mockUnstableCache.mock.calls[0]!;
|
|
@@ -168,7 +228,7 @@ describe("readHubSite (#11456 D3, AC-3)", () => {
|
|
|
168
228
|
mockGet.mockResolvedValue(
|
|
169
229
|
ok({ identity: { kind: "Organization", name: "" }, seo: { version: "1", robots: { index: "no" } } }),
|
|
170
230
|
);
|
|
171
|
-
await expect(readHubSite()).resolves.toEqual({ identity: null, seo: null });
|
|
231
|
+
await expect(readHubSite()).resolves.toEqual({ identity: null, seo: null, navigation: null });
|
|
172
232
|
});
|
|
173
233
|
|
|
174
234
|
it.each([
|
|
@@ -204,6 +264,155 @@ describe("readHubSite (#11456 D3, AC-3)", () => {
|
|
|
204
264
|
});
|
|
205
265
|
});
|
|
206
266
|
|
|
267
|
+
describe("readHubSite — a spoke's read is unchanged (#12390 AC-5)", () => {
|
|
268
|
+
it("a keyed 401 throws: nothing written, the last good value served, and the next request reads again", async () => {
|
|
269
|
+
hubConnect();
|
|
270
|
+
mockGet.mockResolvedValue(ok({ identity: HUB_IDENTITY, seo: HUB_SEO }));
|
|
271
|
+
await readHubSite();
|
|
272
|
+
mockCacheStore.clear(); // a purged tag: the next read misses
|
|
273
|
+
mockGet.mockReset().mockResolvedValue({ ok: false, status: 401, body: {} });
|
|
274
|
+
|
|
275
|
+
await expect(readHubSite()).resolves.toEqual({ identity: HUB_IDENTITY, seo: HUB_SEO, navigation: null });
|
|
276
|
+
expect(mockCacheStore.size).toBe(0);
|
|
277
|
+
expect(refusalWarns()).toHaveLength(0);
|
|
278
|
+
|
|
279
|
+
await readHubSite();
|
|
280
|
+
expect(mockGet).toHaveBeenCalledTimes(2);
|
|
281
|
+
});
|
|
282
|
+
|
|
283
|
+
it("a keyed read's key parts are today's: the key's digest", async () => {
|
|
284
|
+
hubConnect();
|
|
285
|
+
mockGet.mockResolvedValue(ok({ identity: HUB_IDENTITY, seo: HUB_SEO }));
|
|
286
|
+
await readHubSite();
|
|
287
|
+
const [, keyParts] = mockUnstableCache.mock.calls[0]!;
|
|
288
|
+
expect(keyParts).toEqual([
|
|
289
|
+
"ailk-hub-site-config",
|
|
290
|
+
"default",
|
|
291
|
+
createHash("sha256").update(KEY, "utf8").digest("hex").slice(0, 16),
|
|
292
|
+
"nav1",
|
|
293
|
+
]);
|
|
294
|
+
});
|
|
295
|
+
});
|
|
296
|
+
|
|
297
|
+
describe("readHubSite — a keyless single-tenant site (#12390 D2, D3, AC-5)", () => {
|
|
298
|
+
it("a 200's rows are parsed and returned as for a spoke", async () => {
|
|
299
|
+
keylessConnect();
|
|
300
|
+
mockGet.mockResolvedValue(
|
|
301
|
+
ok({ identity: HUB_IDENTITY, seo: { version: "1", robots: { index: "no" } } }),
|
|
302
|
+
);
|
|
303
|
+
await expect(readHubSite()).resolves.toEqual({ identity: HUB_IDENTITY, seo: null, navigation: null });
|
|
304
|
+
expect(mockGet).toHaveBeenCalledTimes(1);
|
|
305
|
+
expect(heldHubSite()).toEqual({ identity: HUB_IDENTITY, seo: null, navigation: null });
|
|
306
|
+
});
|
|
307
|
+
|
|
308
|
+
it("a 401 resolves no rows from inside the cached callback, so a later request makes no second call; one warn", async () => {
|
|
309
|
+
keylessConnect();
|
|
310
|
+
mockGet.mockResolvedValue({ ok: false, status: 401, body: {} });
|
|
311
|
+
|
|
312
|
+
await expect(readHubSite()).resolves.toEqual({ identity: null, seo: null, navigation: null });
|
|
313
|
+
expect(mockCacheStore.size).toBe(1);
|
|
314
|
+
expect([...mockCacheStore.values()]).toEqual([{ identity: null, seo: null, navigation: null }]);
|
|
315
|
+
|
|
316
|
+
await expect(readHubSite()).resolves.toEqual({ identity: null, seo: null, navigation: null });
|
|
317
|
+
expect(mockGet).toHaveBeenCalledTimes(1);
|
|
318
|
+
expect(refusalWarns()).toHaveLength(1);
|
|
319
|
+
expect(String(refusalWarns()[0]![0])).toContain("_site.mdx");
|
|
320
|
+
});
|
|
321
|
+
|
|
322
|
+
it("the contact email falls back to the file after a refused read", async () => {
|
|
323
|
+
keylessConnect();
|
|
324
|
+
mockGet.mockResolvedValue({ ok: false, status: 401, body: {} });
|
|
325
|
+
await readHubSite();
|
|
326
|
+
expect(readSiteContactEmail()).toBe("file@file.example");
|
|
327
|
+
});
|
|
328
|
+
|
|
329
|
+
it.each([
|
|
330
|
+
["a 500", 0, () => mockGet.mockResolvedValue({ ok: false, status: 500, body: {} })],
|
|
331
|
+
["a throw", 0, () => mockGet.mockRejectedValue(new TypeError("fetch failed"))],
|
|
332
|
+
["a timeout", HUB_SITE_TIMEOUT_MS, () => mockGet.mockReturnValue(new Promise(() => undefined))],
|
|
333
|
+
])("%s writes nothing, answers undefined cold, and makes no further call for 15 s", async (_label, failsAfterMs, fail) => {
|
|
334
|
+
jest.useFakeTimers();
|
|
335
|
+
keylessConnect();
|
|
336
|
+
fail();
|
|
337
|
+
|
|
338
|
+
// The 15 s run from when the read failed.
|
|
339
|
+
const first = readHubSite();
|
|
340
|
+
await jest.advanceTimersByTimeAsync(failsAfterMs);
|
|
341
|
+
await expect(first).resolves.toBeUndefined();
|
|
342
|
+
expect(mockCacheStore.size).toBe(0);
|
|
343
|
+
expect(mockGet).toHaveBeenCalledTimes(1);
|
|
344
|
+
expect(refusalWarns()).toHaveLength(0);
|
|
345
|
+
|
|
346
|
+
await expect(readHubSite()).resolves.toBeUndefined();
|
|
347
|
+
jest.advanceTimersByTime(HUB_SITE_RETRY_SECONDS * 1_000 - 1);
|
|
348
|
+
await expect(readHubSite()).resolves.toBeUndefined();
|
|
349
|
+
expect(mockGet).toHaveBeenCalledTimes(1);
|
|
350
|
+
|
|
351
|
+
jest.advanceTimersByTime(1);
|
|
352
|
+
mockGet.mockReset().mockResolvedValue(ok({ identity: HUB_IDENTITY, seo: HUB_SEO }));
|
|
353
|
+
await expect(readHubSite()).resolves.toEqual({ identity: HUB_IDENTITY, seo: HUB_SEO, navigation: null });
|
|
354
|
+
expect(mockGet).toHaveBeenCalledTimes(1);
|
|
355
|
+
});
|
|
356
|
+
|
|
357
|
+
it.each([
|
|
358
|
+
["a 500", () => mockGet.mockResolvedValue({ ok: false, status: 500, body: {} })],
|
|
359
|
+
["a throw", () => mockGet.mockRejectedValue(new TypeError("fetch failed"))],
|
|
360
|
+
])("%s after a good read answers the last good value, and holds it without a call", async (_label, fail) => {
|
|
361
|
+
keylessConnect();
|
|
362
|
+
mockGet.mockResolvedValue(ok({ identity: HUB_IDENTITY, seo: HUB_SEO }));
|
|
363
|
+
await readHubSite();
|
|
364
|
+
mockCacheStore.clear(); // a purged tag: the next read misses
|
|
365
|
+
mockGet.mockReset();
|
|
366
|
+
fail();
|
|
367
|
+
|
|
368
|
+
await expect(readHubSite()).resolves.toEqual({ identity: HUB_IDENTITY, seo: HUB_SEO, navigation: null });
|
|
369
|
+
await expect(readHubSite()).resolves.toEqual({ identity: HUB_IDENTITY, seo: HUB_SEO, navigation: null });
|
|
370
|
+
expect(mockGet).toHaveBeenCalledTimes(1);
|
|
371
|
+
expect(mockCacheStore.size).toBe(0);
|
|
372
|
+
});
|
|
373
|
+
|
|
374
|
+
it("is HUB_SITE_RETRY_SECONDS 15", () => {
|
|
375
|
+
expect(HUB_SITE_RETRY_SECONDS).toBe(15);
|
|
376
|
+
});
|
|
377
|
+
|
|
378
|
+
it("keys its entry `keyless:` plus a digest of the API address, one entry per address", async () => {
|
|
379
|
+
keylessConnect("https://api.one.example");
|
|
380
|
+
mockGet.mockResolvedValue(ok({ identity: HUB_IDENTITY, seo: null }));
|
|
381
|
+
await readHubSite();
|
|
382
|
+
keylessConnect("https://api.two.example");
|
|
383
|
+
await readHubSite();
|
|
384
|
+
const [a, b] = mockUnstableCache.mock.calls.map((call) => call[1]);
|
|
385
|
+
expect(a![2]).toBe(
|
|
386
|
+
`keyless:${createHash("sha256").update("https://api.one.example", "utf8").digest("hex").slice(0, 16)}`,
|
|
387
|
+
);
|
|
388
|
+
expect(b![2]).toMatch(/^keyless:[0-9a-f]{16}$/);
|
|
389
|
+
expect(a![2]).not.toBe(b![2]);
|
|
390
|
+
expect(mockGet).toHaveBeenCalledTimes(2);
|
|
391
|
+
});
|
|
392
|
+
|
|
393
|
+
it("a key that would be dropped on the wire reads under the keyless part, never the key's digest", async () => {
|
|
394
|
+
keylessConnect();
|
|
395
|
+
process.env.AILK_SPOKE_KEY = "has a space";
|
|
396
|
+
mockGet.mockResolvedValue({ ok: false, status: 401, body: {} });
|
|
397
|
+
await expect(readHubSite()).resolves.toEqual({ identity: null, seo: null, navigation: null });
|
|
398
|
+
const [, keyParts] = mockUnstableCache.mock.calls[0]!;
|
|
399
|
+
expect(keyParts[2]).toMatch(/^keyless:/);
|
|
400
|
+
expect(keyParts[2]).not.toContain(
|
|
401
|
+
createHash("sha256").update("has a space", "utf8").digest("hex").slice(0, 16),
|
|
402
|
+
);
|
|
403
|
+
});
|
|
404
|
+
|
|
405
|
+
it("a keyless entry is never read by a keyed call at the same address", async () => {
|
|
406
|
+
keylessConnect("https://hub.example");
|
|
407
|
+
mockGet.mockResolvedValue({ ok: false, status: 401, body: {} });
|
|
408
|
+
await readHubSite();
|
|
409
|
+
hubConnect();
|
|
410
|
+
mockGet.mockReset().mockResolvedValue(ok({ identity: HUB_IDENTITY, seo: HUB_SEO }));
|
|
411
|
+
await expect(readHubSite()).resolves.toEqual({ identity: HUB_IDENTITY, seo: HUB_SEO, navigation: null });
|
|
412
|
+
expect(mockGet).toHaveBeenCalledTimes(1);
|
|
413
|
+
});
|
|
414
|
+
});
|
|
415
|
+
|
|
207
416
|
describe("the contact email from the held hub value (#11456 D4, AC-2)", () => {
|
|
208
417
|
it("answers the file value on a cold instance, then the hub email after one resolved read", async () => {
|
|
209
418
|
hubConnect();
|
|
@@ -240,7 +449,182 @@ describe("the contact email from the held hub value (#11456 D4, AC-2)", () => {
|
|
|
240
449
|
mockGet.mockResolvedValue(ok({ identity: HUB_IDENTITY, seo: null }));
|
|
241
450
|
await readHubSite();
|
|
242
451
|
delete process.env.AILK_SPOKE_KEY;
|
|
452
|
+
delete process.env.AILK_API_URL;
|
|
243
453
|
expect(heldHubSite()).toBeUndefined();
|
|
244
454
|
expect(readSiteContactEmail()).toBe("file@file.example");
|
|
245
455
|
});
|
|
246
456
|
});
|
|
457
|
+
|
|
458
|
+
// #12401 D1, AC-1 — the workspace's navigation record rides the same read.
|
|
459
|
+
describe("readHubSite — the navigation record (#12401 D1, AC-1)", () => {
|
|
460
|
+
const RECORD = {
|
|
461
|
+
version: "1",
|
|
462
|
+
header: {
|
|
463
|
+
items: [
|
|
464
|
+
{ kind: "link", label: { text: "Plans" }, target: { kind: "path", path: "/plans" } },
|
|
465
|
+
{
|
|
466
|
+
kind: "menu",
|
|
467
|
+
label: { text: "Learn" },
|
|
468
|
+
groups: [{ links: [{ kind: "link", label: { text: "Guide" }, target: { kind: "page", address: { type: "AboutPage", slug: "about" } } }] }],
|
|
469
|
+
},
|
|
470
|
+
],
|
|
471
|
+
button: { kind: "link", label: { text: "Book" }, target: { kind: "path", path: "/contact" } },
|
|
472
|
+
},
|
|
473
|
+
footer: {
|
|
474
|
+
columns: [{ heading: { text: "Company" }, links: [{ kind: "link", label: { text: "About" }, target: { kind: "path", path: "/about" } }] }],
|
|
475
|
+
bottomBar: { links: [{ kind: "link", label: { text: "Privacy" }, target: { kind: "path", path: "/privacy" } }] },
|
|
476
|
+
closing: {
|
|
477
|
+
location: "Paris",
|
|
478
|
+
buttons: [{ kind: "link", label: { text: "Call" }, target: { kind: "page", address: { type: "AboutPage", slug: "about" } } }],
|
|
479
|
+
},
|
|
480
|
+
},
|
|
481
|
+
};
|
|
482
|
+
const NAV = { version: 3, record: RECORD };
|
|
483
|
+
const withTarget = (target: unknown) => ({
|
|
484
|
+
...RECORD,
|
|
485
|
+
header: { ...RECORD.header, items: [{ kind: "link", label: { text: "Secret label" }, target }] },
|
|
486
|
+
});
|
|
487
|
+
const navWarns = () =>
|
|
488
|
+
jest.mocked(console.warn).mock.calls.filter((call) => String(call[0]).includes("navigation unreadable"));
|
|
489
|
+
|
|
490
|
+
it.each([
|
|
491
|
+
["a spoke key", hubConnect],
|
|
492
|
+
["a safe API address and no key", () => keylessConnect()],
|
|
493
|
+
])("with %s, a valid navigation resolves its version and record beside identity and seo", async (_label, connect) => {
|
|
494
|
+
connect();
|
|
495
|
+
mockGet.mockResolvedValue(ok({ identity: HUB_IDENTITY, seo: HUB_SEO, navigation: NAV }));
|
|
496
|
+
await expect(readHubSite()).resolves.toEqual({ identity: HUB_IDENTITY, seo: HUB_SEO, navigation: NAV });
|
|
497
|
+
expect(navWarns()).toHaveLength(0);
|
|
498
|
+
});
|
|
499
|
+
|
|
500
|
+
it.each([
|
|
501
|
+
["no navigation key (a hub older than #12400)", { identity: HUB_IDENTITY, seo: HUB_SEO }],
|
|
502
|
+
["navigation: null", { identity: HUB_IDENTITY, seo: HUB_SEO, navigation: null }],
|
|
503
|
+
])("%s resolves navigation null with identity and seo as given, and no warning", async (_label, body) => {
|
|
504
|
+
hubConnect();
|
|
505
|
+
mockGet.mockResolvedValue(ok(body));
|
|
506
|
+
await expect(readHubSite()).resolves.toEqual({ identity: HUB_IDENTITY, seo: HUB_SEO, navigation: null });
|
|
507
|
+
expect(navWarns()).toHaveLength(0);
|
|
508
|
+
});
|
|
509
|
+
|
|
510
|
+
it.each([
|
|
511
|
+
["a record the schema refuses", { version: 7, record: withTarget({ kind: "url", href: "javascript:alert(1)" }) }, "header.items.0.target.href"],
|
|
512
|
+
["a version of 0", { version: 0, record: RECORD }, "version"],
|
|
513
|
+
["a version that is not an integer", { version: 1.5, record: RECORD }, "version"],
|
|
514
|
+
])("%s resolves navigation null with identity and seo kept, and one warning with no value in it", async (_label, navigation, field) => {
|
|
515
|
+
hubConnect();
|
|
516
|
+
mockGet.mockResolvedValue(ok({ identity: HUB_IDENTITY, seo: HUB_SEO, navigation }));
|
|
517
|
+
await expect(readHubSite()).resolves.toEqual({ identity: HUB_IDENTITY, seo: HUB_SEO, navigation: null });
|
|
518
|
+
expect(navWarns()).toHaveLength(1);
|
|
519
|
+
const line = String(navWarns()[0]![0]);
|
|
520
|
+
expect(line).toBe(`[hub-site-config] navigation unreadable at ${field}; rendering the site's own navigation`);
|
|
521
|
+
expect(line).not.toContain("Secret label");
|
|
522
|
+
expect(line).not.toContain("javascript");
|
|
523
|
+
expect(line).not.toContain(String(navigation.version));
|
|
524
|
+
});
|
|
525
|
+
|
|
526
|
+
it.each([
|
|
527
|
+
["a url target javascript:alert(1)", { kind: "url", href: "javascript:alert(1)" }, "header.items.0.target.href"],
|
|
528
|
+
["a url target JaVaScRiPt:alert(1)", { kind: "url", href: "JaVaScRiPt:alert(1)" }, "header.items.0.target.href"],
|
|
529
|
+
["a url target data:text/html,x", { kind: "url", href: "data:text/html,x" }, "header.items.0.target.href"],
|
|
530
|
+
["a path target //evil.example", { kind: "path", path: "//evil.example" }, "header.items.0.target.path"],
|
|
531
|
+
["a path target /\\evil.example", { kind: "path", path: "/\\evil.example" }, "header.items.0.target.path"],
|
|
532
|
+
])("%s is refused: navigation null, identity kept, a warning naming the field's path", async (_label, target, field) => {
|
|
533
|
+
hubConnect();
|
|
534
|
+
mockGet.mockResolvedValue(ok({ identity: HUB_IDENTITY, seo: null, navigation: { version: 2, record: withTarget(target) } }));
|
|
535
|
+
await expect(readHubSite()).resolves.toEqual({ identity: HUB_IDENTITY, seo: null, navigation: null });
|
|
536
|
+
expect(navWarns().map((call) => String(call[0]))).toEqual([
|
|
537
|
+
`[hub-site-config] navigation unreadable at ${field}; rendering the site's own navigation`,
|
|
538
|
+
]);
|
|
539
|
+
});
|
|
540
|
+
|
|
541
|
+
it("a byLocale key the schema refuses is masked in the warning's path", async () => {
|
|
542
|
+
hubConnect();
|
|
543
|
+
const record = {
|
|
544
|
+
...RECORD,
|
|
545
|
+
header: { items: [{ kind: "link", label: { text: "Plans", byLocale: { secretvalue: "x" } }, target: { kind: "path", path: "/plans" } }] },
|
|
546
|
+
};
|
|
547
|
+
mockGet.mockResolvedValue(ok({ identity: HUB_IDENTITY, seo: null, navigation: { version: 2, record } }));
|
|
548
|
+
await expect(readHubSite()).resolves.toMatchObject({ identity: HUB_IDENTITY, navigation: null });
|
|
549
|
+
const lines = navWarns().map((call) => String(call[0]));
|
|
550
|
+
expect(lines).toHaveLength(1);
|
|
551
|
+
expect(lines[0]).toContain("header.items.0.label.byLocale.*");
|
|
552
|
+
expect(lines[0]).not.toContain("secretvalue");
|
|
553
|
+
});
|
|
554
|
+
|
|
555
|
+
it("warns once per distinct refused path, and a different later refusal still warns", async () => {
|
|
556
|
+
hubConnect();
|
|
557
|
+
const bad = (target: unknown) =>
|
|
558
|
+
mockGet.mockResolvedValue(ok({ identity: HUB_IDENTITY, seo: null, navigation: { version: 2, record: withTarget(target) } }));
|
|
559
|
+
bad({ kind: "url", href: "javascript:alert(1)" });
|
|
560
|
+
await readHubSite();
|
|
561
|
+
mockCacheStore.clear();
|
|
562
|
+
bad({ kind: "url", href: "data:text/html,x" });
|
|
563
|
+
await readHubSite();
|
|
564
|
+
expect(navWarns()).toHaveLength(1);
|
|
565
|
+
mockCacheStore.clear();
|
|
566
|
+
bad({ kind: "path", path: "//evil.example" });
|
|
567
|
+
await readHubSite();
|
|
568
|
+
expect(navWarns()).toHaveLength(2);
|
|
569
|
+
});
|
|
570
|
+
|
|
571
|
+
it("the hub's answer for a record whose closing footer's only button pointed at a draft page — the strip removed the closing footer — resolves with no closing", async () => {
|
|
572
|
+
hubConnect();
|
|
573
|
+
// #12400 D5's `liveOnly`: a closing footer left with no button is removed.
|
|
574
|
+
const { closing: _stripped, ...footer } = RECORD.footer;
|
|
575
|
+
const stripped = { ...RECORD, footer };
|
|
576
|
+
mockGet.mockResolvedValue(ok({ identity: HUB_IDENTITY, seo: null, navigation: { version: 4, record: stripped } }));
|
|
577
|
+
const site = await readHubSite();
|
|
578
|
+
expect(site?.navigation).toEqual({ version: 4, record: stripped });
|
|
579
|
+
expect(site?.navigation?.record.footer).not.toHaveProperty("closing");
|
|
580
|
+
});
|
|
581
|
+
|
|
582
|
+
it("after a good read, a rejected siteConfig.get resolves the earlier record", async () => {
|
|
583
|
+
hubConnect();
|
|
584
|
+
mockGet.mockResolvedValue(ok({ identity: HUB_IDENTITY, seo: null, navigation: NAV }));
|
|
585
|
+
await readHubSite();
|
|
586
|
+
mockCacheStore.clear(); // a purged tag: the next read misses
|
|
587
|
+
mockGet.mockReset().mockRejectedValue(new TypeError("fetch failed"));
|
|
588
|
+
await expect(readHubSite()).resolves.toEqual({ identity: HUB_IDENTITY, seo: null, navigation: NAV });
|
|
589
|
+
});
|
|
590
|
+
|
|
591
|
+
it("after the purge, a new body's record is what resolves", async () => {
|
|
592
|
+
hubConnect();
|
|
593
|
+
mockGet.mockResolvedValue(ok({ identity: HUB_IDENTITY, seo: null, navigation: NAV }));
|
|
594
|
+
await readHubSite();
|
|
595
|
+
const renamed = {
|
|
596
|
+
version: 4,
|
|
597
|
+
record: { ...RECORD, header: { items: [{ kind: "link", label: { text: "Prices" }, target: { kind: "path", path: "/plans" } }] } },
|
|
598
|
+
};
|
|
599
|
+
mockGet.mockReset().mockResolvedValue(ok({ identity: HUB_IDENTITY, seo: null, navigation: renamed }));
|
|
600
|
+
// The entry stands until the tag is purged.
|
|
601
|
+
await expect(readHubSite()).resolves.toMatchObject({ navigation: NAV });
|
|
602
|
+
mockCacheStore.clear();
|
|
603
|
+
await expect(readHubSite()).resolves.toMatchObject({ navigation: renamed });
|
|
604
|
+
});
|
|
605
|
+
|
|
606
|
+
it("with neither a key nor an address, siteConfig.get is never called", async () => {
|
|
607
|
+
mockGet.mockResolvedValue(ok({ identity: HUB_IDENTITY, seo: null, navigation: NAV }));
|
|
608
|
+
await expect(readHubSite()).resolves.toBeUndefined();
|
|
609
|
+
expect(mockGet).not.toHaveBeenCalled();
|
|
610
|
+
});
|
|
611
|
+
|
|
612
|
+
it("a keyless 401 resolves navigation null beside the other rows", async () => {
|
|
613
|
+
keylessConnect();
|
|
614
|
+
mockGet.mockResolvedValue({ ok: false, status: 401, body: {} });
|
|
615
|
+
await expect(readHubSite()).resolves.toEqual({ identity: null, seo: null, navigation: null });
|
|
616
|
+
});
|
|
617
|
+
|
|
618
|
+
it("an entry of the old shape, under the key without the nav1 part, is never served", async () => {
|
|
619
|
+
hubConnect();
|
|
620
|
+
const oldKey = [
|
|
621
|
+
"ailk-hub-site-config",
|
|
622
|
+
"default",
|
|
623
|
+
createHash("sha256").update(KEY, "utf8").digest("hex").slice(0, 16),
|
|
624
|
+
].join("|");
|
|
625
|
+
mockCacheStore.set(oldKey, { identity: HUB_IDENTITY, seo: null });
|
|
626
|
+
mockGet.mockResolvedValue(ok({ identity: HUB_IDENTITY, seo: null, navigation: NAV }));
|
|
627
|
+
await expect(readHubSite()).resolves.toEqual({ identity: HUB_IDENTITY, seo: null, navigation: NAV });
|
|
628
|
+
expect(mockGet).toHaveBeenCalledTimes(1);
|
|
629
|
+
});
|
|
630
|
+
});
|