create-ailk 0.40.0 → 0.40.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +26 -4
- package/component-catalog.json +1 -1
- package/component-catalog.md +1 -1
- package/dist/add-module.d.ts +2 -1
- package/dist/add-module.js +17 -1
- package/dist/cutover.d.ts +7 -3
- package/dist/cutover.js +8 -3
- package/dist/lib/declared-env.d.ts +5 -1
- package/dist/lib/declared-env.js +6 -1
- package/dist/lib/env-catalog.d.ts +3 -2
- package/dist/lib/env-catalog.js +4 -8
- package/dist/module-architecture.js +0 -1
- package/dist/programmatic.js +18 -9
- package/dist/remove-module.js +1 -1
- package/dist/seam-refresh.d.ts +60 -0
- package/dist/seam-refresh.js +214 -0
- package/dist/spoke-checkout.d.ts +12 -3
- package/dist/spoke-checkout.js +14 -5
- package/dist/sync-routes.d.ts +10 -1
- package/dist/sync-routes.js +61 -6
- package/dist/template-record.d.ts +14 -2
- package/dist/template-record.js +60 -22
- package/dist/topology.js +3 -4
- package/dist/update.d.ts +13 -1
- package/dist/update.js +100 -8
- package/package.json +3 -3
- package/templates/.env.example +6 -0
- package/templates/.github/workflows/ci.yml +3 -0
- package/templates/apps/api/.env.example +12 -0
- package/templates/apps/api/CLAUDE.md +10 -7
- package/templates/apps/mcp/CLAUDE.md +25 -5
- package/templates/apps/web/.env.example +7 -1
- package/templates/apps/web/CLAUDE.md +40 -13
- package/templates/apps/web/app/[locale]/(authed)/account/connect/__tests__/page.test.tsx +1 -1
- package/templates/apps/web/app/[locale]/layout.tsx +41 -24
- package/templates/apps/web/app/api/revalidate/__tests__/route.test.ts +56 -1
- package/templates/apps/web/app/api/revalidate/route.ts +45 -4
- package/templates/apps/web/app/llms.txt/__tests__/site-listing.test.ts +60 -0
- package/templates/apps/web/app/llms.txt/route.ts +17 -4
- package/templates/apps/web/app/openapi.json/__tests__/route.test.ts +15 -7
- package/templates/apps/web/auth.config.tsx +2 -0
- package/templates/apps/web/auth.ts +28 -4
- package/templates/apps/web/jest.config.cjs +1 -1
- package/templates/apps/web/lib/__tests__/auth-email.test.ts +21 -0
- package/templates/apps/web/lib/__tests__/docs-path.test.ts +20 -2
- package/templates/apps/web/lib/__tests__/hub-site-config.test.ts +246 -0
- package/templates/apps/web/lib/__tests__/profile-back-link.test.ts +58 -0
- package/templates/apps/web/lib/__tests__/relay.test.ts +127 -12
- package/templates/apps/web/lib/__tests__/served-pages.test.ts +163 -20
- package/templates/apps/web/lib/__tests__/server-api.test.ts +72 -7
- package/templates/apps/web/lib/__tests__/services-path.test.ts +22 -1
- package/templates/apps/web/lib/__tests__/site-brand.test.ts +77 -0
- package/templates/apps/web/lib/__tests__/site-contact-lines.test.ts +64 -0
- package/templates/apps/web/lib/__tests__/site-identity-feature-list.test.ts +144 -4
- package/templates/apps/web/lib/auth-email.ts +19 -0
- package/templates/apps/web/lib/docs-path.ts +1 -1
- package/templates/apps/web/lib/hub-site-config.ts +154 -0
- package/templates/apps/web/lib/mcp-oauth.ts +123 -17
- package/templates/apps/web/lib/profile-back-link.ts +49 -12
- package/templates/apps/web/lib/relay.ts +48 -9
- package/templates/apps/web/lib/served-pages.ts +144 -39
- package/templates/apps/web/lib/server-api.ts +37 -4
- package/templates/apps/web/lib/services-path.ts +1 -1
- package/templates/apps/web/lib/site-brand.tsx +66 -0
- package/templates/apps/web/lib/site-contact-email.ts +24 -4
- package/templates/apps/web/lib/site-contact-lines.ts +20 -4
- package/templates/apps/web/lib/site-identity.ts +38 -2
- package/templates/apps/web/messages/en.json +13 -8
- package/templates/apps/web/middleware.ts +4 -2
- package/templates/apps/web/src/lib/routes.ts +13 -0
- package/templates/tools/declared-env.ts +6 -1
- package/versions.json +51 -51
|
@@ -26,6 +26,7 @@ import {
|
|
|
26
26
|
confirmSignUpEmail,
|
|
27
27
|
makeSendAccountOpen,
|
|
28
28
|
purchaseCapture,
|
|
29
|
+
senderWorkspace,
|
|
29
30
|
} from "./lib/auth-email";
|
|
30
31
|
import {
|
|
31
32
|
getActiveProviderIds,
|
|
@@ -102,6 +103,7 @@ export const site = {
|
|
|
102
103
|
buildAuthEmailRequest: (payload, secret) =>
|
|
103
104
|
buildAuthEmailRequest(payload, secret),
|
|
104
105
|
purchaseCapture,
|
|
106
|
+
senderWorkspace,
|
|
105
107
|
},
|
|
106
108
|
},
|
|
107
109
|
} satisfies AuthSite;
|
|
@@ -207,8 +207,9 @@ export const MCP_DISABLED_PATHS = [
|
|
|
207
207
|
];
|
|
208
208
|
|
|
209
209
|
/**
|
|
210
|
-
* Rate rules for the anonymous MCP endpoints — applied
|
|
211
|
-
* custom rules
|
|
210
|
+
* Rate rules for the anonymous MCP endpoints — applied beside the other
|
|
211
|
+
* custom rules where the client IP resolves; `/mcp/register` alone applies
|
|
212
|
+
* without one too (#10459 D3, see the rate-limit block).
|
|
212
213
|
*/
|
|
213
214
|
export const MCP_RATE_RULES = {
|
|
214
215
|
"/mcp/register": { window: 3600, max: 10 },
|
|
@@ -364,7 +365,11 @@ interface VerificationStore {
|
|
|
364
365
|
}
|
|
365
366
|
|
|
366
367
|
type SocialProviders = {
|
|
367
|
-
google?: {
|
|
368
|
+
google?: {
|
|
369
|
+
clientId: string;
|
|
370
|
+
clientSecret: string;
|
|
371
|
+
disableIdTokenSignIn?: boolean;
|
|
372
|
+
};
|
|
368
373
|
github?: { clientId: string; clientSecret: string };
|
|
369
374
|
};
|
|
370
375
|
|
|
@@ -376,6 +381,10 @@ function buildSocialProviders(): SocialProviders {
|
|
|
376
381
|
providers.google = {
|
|
377
382
|
clientId: process.env.GOOGLE_CLIENT_ID!,
|
|
378
383
|
clientSecret: process.env.GOOGLE_CLIENT_SECRET!,
|
|
384
|
+
// #11109: refuse `POST /sign-in/social` with a raw `idToken`. A One Tap
|
|
385
|
+
// token a spoke's server received may carry this same audience, and
|
|
386
|
+
// must never buy a hub session here; sign-in uses the redirect flow.
|
|
387
|
+
disableIdTokenSignIn: true,
|
|
379
388
|
};
|
|
380
389
|
}
|
|
381
390
|
|
|
@@ -971,7 +980,22 @@ export function createAuth(deps: CreateAuthDeps = {}) {
|
|
|
971
980
|
...(baseURL ? MCP_RATE_RULES : {}),
|
|
972
981
|
},
|
|
973
982
|
}
|
|
974
|
-
:
|
|
983
|
+
: baseURL
|
|
984
|
+
? {
|
|
985
|
+
// #10459 D3: registration keeps its 10 per hour without a
|
|
986
|
+
// resolvable IP too, and nothing else leaves the guard. Under
|
|
987
|
+
// the shared `no-trusted-ip` bucket this is a site-wide 10
|
|
988
|
+
// registrations an hour, so a caller can hold NEW-client
|
|
989
|
+
// registration closed — accepted, because that is all it
|
|
990
|
+
// denies (every connected client keeps refreshing, revoking
|
|
991
|
+
// and checking under the library defaults), and the
|
|
992
|
+
// alternative is unbounded anonymous row creation. With a
|
|
993
|
+
// single-hop header the key is the caller's claimed address,
|
|
994
|
+
// which a scripted caller rotates. AILK_AUTH_TRUSTED_PROXIES is
|
|
995
|
+
// what makes the limit per visitor.
|
|
996
|
+
customRules: { "/mcp/register": MCP_RATE_RULES["/mcp/register"] },
|
|
997
|
+
}
|
|
998
|
+
: {}),
|
|
975
999
|
},
|
|
976
1000
|
// Ids are minted by the DATABASE (ADR-0031): generateId: false makes the
|
|
977
1001
|
// Prisma adapter omit `id` on insert so the dbgenerated prefixed-UUIDv7
|
|
@@ -159,7 +159,7 @@ module.exports = {
|
|
|
159
159
|
// from their own install, a second physical copy of each (the #5025
|
|
160
160
|
// class above), so a test's `jest.mock()` of either would miss them.
|
|
161
161
|
// Collapse every copy onto the one this app resolves.
|
|
162
|
-
"^next/headers
|
|
162
|
+
"^next/headers(\\.js)?$": require.resolve("next/headers"),
|
|
163
163
|
"^better-auth/react$": require.resolve("better-auth/react"),
|
|
164
164
|
// The dependency-free tenancy-constants subpath (database/tenancy.ts).
|
|
165
165
|
// Mapped to source like every sibling above; `database/dist` is not
|
|
@@ -33,6 +33,7 @@ import {
|
|
|
33
33
|
makeSendVerificationEmail,
|
|
34
34
|
makeSendPasswordChangedNotice,
|
|
35
35
|
purchaseCapture,
|
|
36
|
+
senderWorkspace,
|
|
36
37
|
} from "../auth-email";
|
|
37
38
|
|
|
38
39
|
const ORIGINAL_ENV = process.env;
|
|
@@ -420,6 +421,26 @@ describe("sendMagicLink — existing users only, deferred (#7435 § D3, AC-2)",
|
|
|
420
421
|
expect(serialized).not.toContain("magic-link/verify");
|
|
421
422
|
});
|
|
422
423
|
|
|
424
|
+
it("inside senderWorkspace.run, the payload names the workspace the link is sent for (workspace-email-sender-name)", async () => {
|
|
425
|
+
const send = jest.fn().mockResolvedValue({ ok: true });
|
|
426
|
+
const { log } = makeLog();
|
|
427
|
+
const { ctx, background } = makeCtx({ id: "user_1", email: "person@example.com" });
|
|
428
|
+
const { sendMagicLink } = makeMagicLinkOptions({ send, log });
|
|
429
|
+
|
|
430
|
+
await senderWorkspace.run("wksp_1", () =>
|
|
431
|
+
sendMagicLink({ email: "person@example.com", url: LINK, token: "MLTOKEN" }, ctx),
|
|
432
|
+
);
|
|
433
|
+
await Promise.all(background);
|
|
434
|
+
|
|
435
|
+
expect(JSON.parse(send.mock.calls[0]![0] as string)).toEqual({
|
|
436
|
+
kind: "magic-link",
|
|
437
|
+
userId: "user_1",
|
|
438
|
+
to: "person@example.com",
|
|
439
|
+
url: LINK,
|
|
440
|
+
workspaceId: "wksp_1",
|
|
441
|
+
});
|
|
442
|
+
});
|
|
443
|
+
|
|
423
444
|
it("never throws, and sends nothing, when the user lookup fails", async () => {
|
|
424
445
|
const send = jest.fn();
|
|
425
446
|
const { lines, log } = makeLog();
|
|
@@ -125,10 +125,10 @@ describe("docs-path — docsPath /working-theory/docs (AC-2a, AC-2b)", () => {
|
|
|
125
125
|
expect(mapped[0]!.flyout!.groups![0]!.items[0]!.path).toBe(
|
|
126
126
|
"/working-theory/docs",
|
|
127
127
|
);
|
|
128
|
-
expect(mapped[0]!.flyout!.actions[0]!.path).toBe(
|
|
128
|
+
expect(mapped[0]!.flyout!.actions![0]!.path).toBe(
|
|
129
129
|
"/working-theory/docs/start",
|
|
130
130
|
);
|
|
131
|
-
expect(mapped[0]!.flyout!.actions[0]!.icon).toBe(Icon);
|
|
131
|
+
expect(mapped[0]!.flyout!.actions![0]!.icon).toBe(Icon);
|
|
132
132
|
expect(mapped[0]!.flyout!.features[0]!.icon).toBe(Icon);
|
|
133
133
|
expect(mapped[0]!.flyout!.width).toBe("panel");
|
|
134
134
|
expect(mapped[1]).toEqual({
|
|
@@ -144,6 +144,24 @@ describe("docs-path — docsPath /working-theory/docs (AC-2a, AC-2b)", () => {
|
|
|
144
144
|
expect(items[1]!.path).toBe("/docs");
|
|
145
145
|
});
|
|
146
146
|
|
|
147
|
+
it("maps a flyout with no actions and adds none (#10047)", () => {
|
|
148
|
+
const items: NavItem[] = [
|
|
149
|
+
{
|
|
150
|
+
labelKey: "resources",
|
|
151
|
+
flyout: {
|
|
152
|
+
features: [{ labelKey: "docs", path: "/docs" }],
|
|
153
|
+
groups: [
|
|
154
|
+
{ headingKey: "h", items: [{ labelKey: "docs", path: "/docs" }] },
|
|
155
|
+
],
|
|
156
|
+
},
|
|
157
|
+
},
|
|
158
|
+
];
|
|
159
|
+
const flyout = m.withPublicDocsPaths(items)[0]!.flyout!;
|
|
160
|
+
expect(flyout.features[0]!.path).toBe("/working-theory/docs");
|
|
161
|
+
expect(flyout.groups![0]!.items[0]!.path).toBe("/working-theory/docs");
|
|
162
|
+
expect(flyout).not.toHaveProperty("actions");
|
|
163
|
+
});
|
|
164
|
+
|
|
147
165
|
it("maps footer column items", () => {
|
|
148
166
|
const cols = [
|
|
149
167
|
{
|
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @jest-environment node
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
/**
|
|
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).
|
|
8
|
+
*
|
|
9
|
+
* External boundaries doubled:
|
|
10
|
+
* - `@working-theory/api-client`'s `siteConfig.get` — the HTTP call to the
|
|
11
|
+
* hub (`sendsSpokeKey` stays real, so the switch is the env's);
|
|
12
|
+
* - `next/cache`'s `unstable_cache` — a fake with Next's write rule: a
|
|
13
|
+
* RESOLVED callback is written, a THROWING one writes nothing and the
|
|
14
|
+
* last entry is served (`unstable-cache.js` `cacheNewResult`).
|
|
15
|
+
*/
|
|
16
|
+
import { mkdtempSync, rmSync, writeFileSync } from "node:fs";
|
|
17
|
+
import { tmpdir } from "node:os";
|
|
18
|
+
import { join } from "node:path";
|
|
19
|
+
|
|
20
|
+
const mockGet = jest.fn();
|
|
21
|
+
jest.mock("@working-theory/api-client", () => ({
|
|
22
|
+
...jest.requireActual("@working-theory/api-client"),
|
|
23
|
+
siteConfig: { get: (...args: unknown[]) => mockGet(...args) },
|
|
24
|
+
}));
|
|
25
|
+
|
|
26
|
+
/** The fake data cache: one entry per joined key parts. */
|
|
27
|
+
const mockCacheStore = new Map<string, unknown>();
|
|
28
|
+
const mockUnstableCache = jest.fn(
|
|
29
|
+
(
|
|
30
|
+
fn: () => Promise<unknown>,
|
|
31
|
+
keyParts: string[],
|
|
32
|
+
_options: { tags: string[]; revalidate: number },
|
|
33
|
+
) =>
|
|
34
|
+
async () => {
|
|
35
|
+
const key = keyParts.join("|");
|
|
36
|
+
try {
|
|
37
|
+
const value = await fn();
|
|
38
|
+
mockCacheStore.set(key, value);
|
|
39
|
+
return value;
|
|
40
|
+
} catch (err) {
|
|
41
|
+
if (mockCacheStore.has(key)) return mockCacheStore.get(key);
|
|
42
|
+
throw err;
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
);
|
|
46
|
+
jest.mock("next/cache", () => ({
|
|
47
|
+
unstable_cache: (...args: Parameters<typeof mockUnstableCache>) =>
|
|
48
|
+
mockUnstableCache(...args),
|
|
49
|
+
}));
|
|
50
|
+
|
|
51
|
+
import { siteConfigTag } from "@working-theory/page-renderer/edge";
|
|
52
|
+
|
|
53
|
+
import {
|
|
54
|
+
__resetHubSiteForTests,
|
|
55
|
+
HUB_SITE_REVALIDATE_SECONDS,
|
|
56
|
+
HUB_SITE_TIMEOUT_MS,
|
|
57
|
+
heldHubSite,
|
|
58
|
+
hubConnected,
|
|
59
|
+
readHubSite,
|
|
60
|
+
} from "../hub-site-config";
|
|
61
|
+
import { readSiteContactEmail } from "../site-contact-email";
|
|
62
|
+
|
|
63
|
+
const KEY = "ailk_spk_TESTKEYxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
|
|
64
|
+
const HUB_IDENTITY = {
|
|
65
|
+
kind: "Person",
|
|
66
|
+
name: "Hub Person",
|
|
67
|
+
url: "https://hub.example",
|
|
68
|
+
email: "hub@hub.example",
|
|
69
|
+
};
|
|
70
|
+
const HUB_SEO = { version: "1", robots: { index: false } };
|
|
71
|
+
const ok = (data: unknown) => ({ ok: true, body: data });
|
|
72
|
+
|
|
73
|
+
const ENV_KEYS = ["CONTENT_ADAPTER", "AILK_SPOKE_KEY", "AILK_API_URL", "AILK_CONTENT_ROOT"] as const;
|
|
74
|
+
const savedEnv = new Map(ENV_KEYS.map((k) => [k, process.env[k]]));
|
|
75
|
+
let root: string;
|
|
76
|
+
|
|
77
|
+
function hubConnect(): void {
|
|
78
|
+
process.env.AILK_SPOKE_KEY = KEY;
|
|
79
|
+
process.env.AILK_API_URL = "https://hub.example";
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
beforeEach(() => {
|
|
83
|
+
mockGet.mockReset();
|
|
84
|
+
mockUnstableCache.mockClear();
|
|
85
|
+
mockCacheStore.clear();
|
|
86
|
+
__resetHubSiteForTests();
|
|
87
|
+
for (const k of ENV_KEYS) delete process.env[k];
|
|
88
|
+
root = mkdtempSync(join(tmpdir(), "hub-site-config-"));
|
|
89
|
+
process.env.AILK_CONTENT_ROOT = root;
|
|
90
|
+
writeFileSync(
|
|
91
|
+
join(root, "_site.mdx"),
|
|
92
|
+
"---\nsiteName: File Site\ncontactEmail: file@file.example\n---\n",
|
|
93
|
+
);
|
|
94
|
+
jest.spyOn(console, "warn").mockImplementation(() => undefined);
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
afterEach(() => {
|
|
98
|
+
jest.restoreAllMocks();
|
|
99
|
+
jest.useRealTimers();
|
|
100
|
+
rmSync(root, { recursive: true, force: true });
|
|
101
|
+
for (const [k, v] of savedEnv) {
|
|
102
|
+
if (v === undefined) delete process.env[k];
|
|
103
|
+
else process.env[k] = v;
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
describe("hubConnected (#11456 D3, #11515)", () => {
|
|
108
|
+
it("is true with a spoke key on the wire, whatever the content adapter", () => {
|
|
109
|
+
expect(hubConnected()).toBe(false);
|
|
110
|
+
hubConnect();
|
|
111
|
+
expect(process.env.CONTENT_ADAPTER).toBeUndefined();
|
|
112
|
+
expect(hubConnected()).toBe(true);
|
|
113
|
+
process.env.CONTENT_ADAPTER = "database";
|
|
114
|
+
expect(hubConnected()).toBe(true);
|
|
115
|
+
delete process.env.AILK_SPOKE_KEY;
|
|
116
|
+
expect(hubConnected()).toBe(false);
|
|
117
|
+
});
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
describe("readHubSite (#11456 D3, AC-3)", () => {
|
|
121
|
+
it.each([
|
|
122
|
+
["CONTENT_ADAPTER unset", () => undefined],
|
|
123
|
+
["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) => {
|
|
125
|
+
hubConnect();
|
|
126
|
+
delete process.env.AILK_SPOKE_KEY;
|
|
127
|
+
arrange();
|
|
128
|
+
await expect(readHubSite()).resolves.toBeUndefined();
|
|
129
|
+
expect(mockGet).not.toHaveBeenCalled();
|
|
130
|
+
expect(mockUnstableCache).not.toHaveBeenCalled();
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
it("with a spoke key and CONTENT_ADAPTER unset reads the hub (#11515)", async () => {
|
|
134
|
+
hubConnect();
|
|
135
|
+
mockGet.mockResolvedValue(ok({ identity: HUB_IDENTITY, seo: HUB_SEO }));
|
|
136
|
+
await expect(readHubSite()).resolves.toEqual({ identity: HUB_IDENTITY, seo: HUB_SEO });
|
|
137
|
+
expect(mockGet).toHaveBeenCalledTimes(1);
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
it("wraps the read with tags [siteConfigTag()] and revalidate 300, keyed by a digest of the key, never the key", async () => {
|
|
141
|
+
hubConnect();
|
|
142
|
+
mockGet.mockResolvedValue(ok({ identity: HUB_IDENTITY, seo: HUB_SEO }));
|
|
143
|
+
|
|
144
|
+
await expect(readHubSite()).resolves.toEqual({ identity: HUB_IDENTITY, seo: HUB_SEO });
|
|
145
|
+
|
|
146
|
+
expect(mockUnstableCache).toHaveBeenCalledTimes(1);
|
|
147
|
+
const [, keyParts, options] = mockUnstableCache.mock.calls[0]!;
|
|
148
|
+
expect(options).toEqual({ tags: [siteConfigTag()], revalidate: 300 });
|
|
149
|
+
expect(HUB_SITE_REVALIDATE_SECONDS).toBe(300);
|
|
150
|
+
expect(keyParts[0]).toBe("ailk-hub-site-config");
|
|
151
|
+
expect(keyParts[1]).toBe("default");
|
|
152
|
+
expect(keyParts[2]).toMatch(/^[0-9a-f]{16}$/);
|
|
153
|
+
expect(keyParts.join("|")).not.toContain(KEY);
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
it("two different keys never share an entry", async () => {
|
|
157
|
+
hubConnect();
|
|
158
|
+
mockGet.mockResolvedValue(ok({ identity: HUB_IDENTITY, seo: null }));
|
|
159
|
+
await readHubSite();
|
|
160
|
+
process.env.AILK_SPOKE_KEY = `${KEY.slice(0, -1)}y`;
|
|
161
|
+
await readHubSite();
|
|
162
|
+
const [a, b] = mockUnstableCache.mock.calls.map((call) => call[1].join("|"));
|
|
163
|
+
expect(a).not.toBe(b);
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
it("re-parses each row; a row its schema refuses is null", async () => {
|
|
167
|
+
hubConnect();
|
|
168
|
+
mockGet.mockResolvedValue(
|
|
169
|
+
ok({ identity: { kind: "Organization", name: "" }, seo: { version: "1", robots: { index: "no" } } }),
|
|
170
|
+
);
|
|
171
|
+
await expect(readHubSite()).resolves.toEqual({ identity: null, seo: null });
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
it.each([
|
|
175
|
+
["a non-2xx", () => mockGet.mockResolvedValue({ ok: false, status: 401, body: {} })],
|
|
176
|
+
["a throw", () => mockGet.mockRejectedValue(new TypeError("fetch failed"))],
|
|
177
|
+
["a body without the two keys", () => mockGet.mockResolvedValue(ok({ identity: HUB_IDENTITY }))],
|
|
178
|
+
])("%s writes nothing, serves the last good value and never rejects", async (_label, fail) => {
|
|
179
|
+
hubConnect();
|
|
180
|
+
// Cold instance, nothing cached: a failure answers undefined.
|
|
181
|
+
fail();
|
|
182
|
+
await expect(readHubSite()).resolves.toBeUndefined();
|
|
183
|
+
expect(mockCacheStore.size).toBe(0);
|
|
184
|
+
|
|
185
|
+
// One good read, then the failure again: the entry and the held value stand.
|
|
186
|
+
mockGet.mockReset().mockResolvedValue(ok({ identity: HUB_IDENTITY, seo: HUB_SEO }));
|
|
187
|
+
await readHubSite();
|
|
188
|
+
const [entry] = [...mockCacheStore.values()];
|
|
189
|
+
mockGet.mockReset();
|
|
190
|
+
fail();
|
|
191
|
+
mockCacheStore.clear(); // a purged tag: the next read misses
|
|
192
|
+
await expect(readHubSite()).resolves.toEqual(entry);
|
|
193
|
+
expect(mockCacheStore.size).toBe(0);
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
it("a read slower than 3 s is a failed read", async () => {
|
|
197
|
+
jest.useFakeTimers();
|
|
198
|
+
hubConnect();
|
|
199
|
+
mockGet.mockReturnValue(new Promise(() => undefined));
|
|
200
|
+
const read = readHubSite();
|
|
201
|
+
await jest.advanceTimersByTimeAsync(HUB_SITE_TIMEOUT_MS);
|
|
202
|
+
await expect(read).resolves.toBeUndefined();
|
|
203
|
+
expect(mockCacheStore.size).toBe(0);
|
|
204
|
+
});
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
describe("the contact email from the held hub value (#11456 D4, AC-2)", () => {
|
|
208
|
+
it("answers the file value on a cold instance, then the hub email after one resolved read", async () => {
|
|
209
|
+
hubConnect();
|
|
210
|
+
expect(heldHubSite()).toBeUndefined();
|
|
211
|
+
expect(readSiteContactEmail()).toBe("file@file.example");
|
|
212
|
+
|
|
213
|
+
mockGet.mockResolvedValue(ok({ identity: HUB_IDENTITY, seo: null }));
|
|
214
|
+
await readHubSite();
|
|
215
|
+
|
|
216
|
+
expect(readSiteContactEmail()).toBe("hub@hub.example");
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
it("a hub identity with no email falls back to the file's top-level contactEmail", async () => {
|
|
220
|
+
hubConnect();
|
|
221
|
+
const { email: _email, ...noEmail } = HUB_IDENTITY;
|
|
222
|
+
mockGet.mockResolvedValue(ok({ identity: noEmail, seo: null }));
|
|
223
|
+
await readHubSite();
|
|
224
|
+
expect(readSiteContactEmail()).toBe("file@file.example");
|
|
225
|
+
});
|
|
226
|
+
|
|
227
|
+
it.each([
|
|
228
|
+
["has no frontmatter", "No frontmatter here.\n"],
|
|
229
|
+
["has empty frontmatter", "---\n---\n"],
|
|
230
|
+
])("answers the hub email when _site.mdx %s", async (_label, body) => {
|
|
231
|
+
hubConnect();
|
|
232
|
+
writeFileSync(join(root, "_site.mdx"), body);
|
|
233
|
+
mockGet.mockResolvedValue(ok({ identity: HUB_IDENTITY, seo: null }));
|
|
234
|
+
await readHubSite();
|
|
235
|
+
expect(readSiteContactEmail()).toBe("hub@hub.example");
|
|
236
|
+
});
|
|
237
|
+
|
|
238
|
+
it("a site that is not hub-connected never reads a held value", async () => {
|
|
239
|
+
hubConnect();
|
|
240
|
+
mockGet.mockResolvedValue(ok({ identity: HUB_IDENTITY, seo: null }));
|
|
241
|
+
await readHubSite();
|
|
242
|
+
delete process.env.AILK_SPOKE_KEY;
|
|
243
|
+
expect(heldHubSite()).toBeUndefined();
|
|
244
|
+
expect(readSiteContactEmail()).toBe("file@file.example");
|
|
245
|
+
});
|
|
246
|
+
});
|
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
import { deckReturnHref } from "@working-theory/ui/chrome";
|
|
14
14
|
|
|
15
15
|
import {
|
|
16
|
+
ancestorPaths,
|
|
16
17
|
backLinkHref,
|
|
17
18
|
backLinkName,
|
|
18
19
|
navLabelsByPath,
|
|
@@ -87,6 +88,17 @@ describe("backLinkHref — the served parent", () => {
|
|
|
87
88
|
});
|
|
88
89
|
});
|
|
89
90
|
|
|
91
|
+
describe("ancestorPaths — the parents the walk asks about (#11438)", () => {
|
|
92
|
+
it("lists the bare ancestors below the home, nearest first, locale prefix dropped", () => {
|
|
93
|
+
expect(ancestorPaths("/es/flows/audit/start?x=1", LOCALES)).toEqual(["/flows/audit", "/flows"]);
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
it("has none for a top-level page or an absent pathname", () => {
|
|
97
|
+
expect(ancestorPaths("/about", LOCALES)).toEqual([]);
|
|
98
|
+
expect(ancestorPaths(null, LOCALES)).toEqual([]);
|
|
99
|
+
});
|
|
100
|
+
});
|
|
101
|
+
|
|
90
102
|
describe("backLinkName — the destination named in the label", () => {
|
|
91
103
|
const titles = new Map([
|
|
92
104
|
["/meet", "Book a meeting with Sam"],
|
|
@@ -109,6 +121,52 @@ describe("backLinkName — the destination named in the label", () => {
|
|
|
109
121
|
"Case studies",
|
|
110
122
|
);
|
|
111
123
|
});
|
|
124
|
+
|
|
125
|
+
describe("a title carrying the site name as a suffix", () => {
|
|
126
|
+
const siteName = "Sam Henry";
|
|
127
|
+
const suffixed = new Map([
|
|
128
|
+
["/about", "About — Sam Henry"],
|
|
129
|
+
["/faq", "Questions about hiring Sam | Sam Henry"],
|
|
130
|
+
["/work", "Work - Sam Henry"],
|
|
131
|
+
["/blog/ai-builder-principles", "The AI Builder Principles"],
|
|
132
|
+
["/notes", "Sam Henry — Notes from the field"],
|
|
133
|
+
["/press", "Working with Sam Henry and the team"],
|
|
134
|
+
["/only", " — Sam Henry"],
|
|
135
|
+
]);
|
|
136
|
+
const name = (parent: string, navLabels = new Map<string, string>()): string =>
|
|
137
|
+
backLinkName(parent, { navLabels, titles: suffixed, siteName });
|
|
138
|
+
|
|
139
|
+
it.each([
|
|
140
|
+
["/about", "About"],
|
|
141
|
+
["/faq", "Questions about hiring Sam"],
|
|
142
|
+
["/work", "Work"],
|
|
143
|
+
])("strips the trailing suffix: %s → %s", (parent, expected) => {
|
|
144
|
+
expect(name(parent)).toBe(expected);
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
it("leaves a title without the suffix unchanged", () => {
|
|
148
|
+
expect(name("/blog/ai-builder-principles")).toBe("The AI Builder Principles");
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
it("leaves the site name anywhere but the trailing suffix alone", () => {
|
|
152
|
+
expect(name("/notes")).toBe("Sam Henry — Notes from the field");
|
|
153
|
+
expect(name("/press")).toBe("Working with Sam Henry and the team");
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
it("prefers the nav label when the nav has one for the parent", () => {
|
|
157
|
+
expect(name("/about", new Map([["/about", "About me"]]))).toBe("About me");
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
it("keeps the title when stripping would leave nothing", () => {
|
|
161
|
+
expect(name("/only")).toBe(" — Sam Henry");
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
it("leaves the title whole when no site name is known", () => {
|
|
165
|
+
expect(backLinkName("/about", { navLabels: new Map(), titles: suffixed })).toBe(
|
|
166
|
+
"About — Sam Henry",
|
|
167
|
+
);
|
|
168
|
+
});
|
|
169
|
+
});
|
|
112
170
|
});
|
|
113
171
|
|
|
114
172
|
describe("navLabelsByPath", () => {
|
|
@@ -111,17 +111,19 @@ async function errorCode(res: Response): Promise<string | undefined> {
|
|
|
111
111
|
return json.error?.code;
|
|
112
112
|
}
|
|
113
113
|
|
|
114
|
-
const
|
|
114
|
+
const VISITOR_ENTRIES: ReadonlyArray<{ method: "GET" | "POST"; path: string }> = [
|
|
115
115
|
{ method: "POST", path: "/v1/leads/submit" },
|
|
116
116
|
{ method: "POST", path: "/v1/leads/subscribe" },
|
|
117
117
|
{ method: "POST", path: "/v1/leads/callback" },
|
|
118
118
|
{ method: "GET", path: "/v1/schedule/availability" },
|
|
119
119
|
{ method: "POST", path: "/v1/schedule/book" },
|
|
120
|
-
{ method: "POST", path: "/v1/commerce/invoices" },
|
|
121
120
|
];
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
121
|
+
// #8066 D2 — the session route exists on a hub render only, so a spoke
|
|
122
|
+
// scaffold's copy of this suite relays the five visitor pairs alone.
|
|
123
|
+
const ENTRIES: ReadonlyArray<{ method: "GET" | "POST"; path: string }> =
|
|
124
|
+
TOPOLOGY === "hub"
|
|
125
|
+
? [...VISITOR_ENTRIES, { method: "POST", path: "/v1/commerce/invoices" }]
|
|
126
|
+
: VISITOR_ENTRIES;
|
|
125
127
|
|
|
126
128
|
/** The relay request for one D2 entry, with the GET's query string. */
|
|
127
129
|
function entryRequest(
|
|
@@ -350,7 +352,7 @@ describe("AC-4 — the visitor, unchanged; a cross-site post, refused", () => {
|
|
|
350
352
|
},
|
|
351
353
|
);
|
|
352
354
|
|
|
353
|
-
it("POST /v1/commerce/invoices carries no keyed visitor IP", async () => {
|
|
355
|
+
(TOPOLOGY === "hub" ? it : it.skip)("POST /v1/commerce/invoices carries no keyed visitor IP", async () => {
|
|
354
356
|
process.env.AILK_VISITOR_FORWARD_KEY = FORWARD_KEY;
|
|
355
357
|
await handleRelay(
|
|
356
358
|
relayRequest("/v1/commerce/invoices", {
|
|
@@ -362,12 +364,14 @@ describe("AC-4 — the visitor, unchanged; a cross-site post, refused", () => {
|
|
|
362
364
|
expect(headers.get("x-ailk-visitor-forward-key")).toBeNull();
|
|
363
365
|
});
|
|
364
366
|
|
|
365
|
-
it("forwards cookie and origin on /v1/commerce/invoices", async () => {
|
|
367
|
+
(TOPOLOGY === "hub" ? it : it.skip)("forwards cookie and origin on /v1/commerce/invoices", async () => {
|
|
366
368
|
await handleRelay(
|
|
367
|
-
relayRequest("/v1/commerce/invoices", {
|
|
369
|
+
relayRequest("/v1/commerce/invoices", {
|
|
370
|
+
headers: { cookie: "better-auth.session_token=s" },
|
|
371
|
+
}),
|
|
368
372
|
);
|
|
369
373
|
const { headers } = sent();
|
|
370
|
-
expect(headers.get("cookie")).toBe("s
|
|
374
|
+
expect(headers.get("cookie")).toBe("better-auth.session_token=s");
|
|
371
375
|
expect(headers.get("origin")).toBe(SITE);
|
|
372
376
|
});
|
|
373
377
|
|
|
@@ -594,7 +598,7 @@ describe("the banner's visitor id (#8438 D12)", () => {
|
|
|
594
598
|
expect(sent().headers.get("x-ailk-consent-visitor")).toBeNull();
|
|
595
599
|
});
|
|
596
600
|
|
|
597
|
-
it("the session route carries no consent-visitor header", async () => {
|
|
601
|
+
(TOPOLOGY === "hub" ? it : it.skip)("the session route carries no consent-visitor header", async () => {
|
|
598
602
|
await handleRelay(
|
|
599
603
|
relayRequest("/v1/commerce/invoices", { headers: { cookie: `ailk-vid=${VALID_ID}` } }),
|
|
600
604
|
);
|
|
@@ -930,7 +934,7 @@ describe("the per-visitor rate limit (#7707)", () => {
|
|
|
930
934
|
});
|
|
931
935
|
});
|
|
932
936
|
|
|
933
|
-
describe("AC-8 — the session route has its own, wider, independent budget", () => {
|
|
937
|
+
(TOPOLOGY === "hub" ? describe : describe.skip)("AC-8 — the session route has its own, wider, independent budget", () => {
|
|
934
938
|
it("30 forwarded, the 31st refused; the visitor budget is untouched", async () => {
|
|
935
939
|
for (let i = 0; i < 30; i++) {
|
|
936
940
|
const res = await handleRelay(
|
|
@@ -1364,7 +1368,7 @@ describe("the write bot check on the lead routes (#9255)", () => {
|
|
|
1364
1368
|
|
|
1365
1369
|
it.each([
|
|
1366
1370
|
{ method: "GET", path: "/v1/schedule/availability" },
|
|
1367
|
-
{ method: "POST", path: "/v1/commerce/invoices" },
|
|
1371
|
+
...(TOPOLOGY === "hub" ? [{ method: "POST", path: "/v1/commerce/invoices" }] : []),
|
|
1368
1372
|
])("$method $path forwards with no BotID call", async (entry) => {
|
|
1369
1373
|
checkBotIdMock.mockResolvedValue(BOT);
|
|
1370
1374
|
const res = await handleRelay(entryRequest(entry));
|
|
@@ -1390,3 +1394,114 @@ describe("the write bot check on the lead routes (#9255)", () => {
|
|
|
1390
1394
|
expect(fetchMock).not.toHaveBeenCalled();
|
|
1391
1395
|
});
|
|
1392
1396
|
});
|
|
1397
|
+
|
|
1398
|
+
// The session route forwards only the hub's own session cookie, and exists on
|
|
1399
|
+
// a hub only (#8066, spec docs/specs/8066-relay-session-cookie-spec.md §5.1).
|
|
1400
|
+
describe("the session route's cookie (#8066)", () => {
|
|
1401
|
+
const INVOICES = "/v1/commerce/invoices";
|
|
1402
|
+
const SEALED = "sealed.hub-session.value";
|
|
1403
|
+
|
|
1404
|
+
async function forwardedCookie(cookie: string | null): Promise<string | null> {
|
|
1405
|
+
const res = await handleRelay(relayRequest(INVOICES, { headers: { cookie } }));
|
|
1406
|
+
expect(res.status).toBe(201);
|
|
1407
|
+
return sent().headers.get("cookie");
|
|
1408
|
+
}
|
|
1409
|
+
|
|
1410
|
+
describe("AC-1 — one Better Auth session pair, the __Secure- one first", () => {
|
|
1411
|
+
(TOPOLOGY === "hub" ? it : it.skip)(
|
|
1412
|
+
"drops the spoke's hub-session and flow cookies and every other cookie",
|
|
1413
|
+
async () => {
|
|
1414
|
+
const cookie = await forwardedCookie(
|
|
1415
|
+
`theme=dark; __Host-ailk-hub-session=${SEALED}; better-auth.session_token=tok.sig; __Host-ailk-hub-flow=F; __Secure-better-auth.session_token=tok2.sig2`,
|
|
1416
|
+
);
|
|
1417
|
+
expect(cookie).toBe("__Secure-better-auth.session_token=tok2.sig2");
|
|
1418
|
+
expect(sent().headers.get("origin")).toBe(SITE);
|
|
1419
|
+
},
|
|
1420
|
+
);
|
|
1421
|
+
|
|
1422
|
+
(TOPOLOGY === "hub" ? it : it.skip)(
|
|
1423
|
+
"forwards the first plain pair when no __Secure- pair is present",
|
|
1424
|
+
async () => {
|
|
1425
|
+
expect(
|
|
1426
|
+
await forwardedCookie(
|
|
1427
|
+
"theme=dark; better-auth.session_token=tok.sig; better-auth.session_token=late.sig",
|
|
1428
|
+
),
|
|
1429
|
+
).toBe("better-auth.session_token=tok.sig");
|
|
1430
|
+
},
|
|
1431
|
+
);
|
|
1432
|
+
|
|
1433
|
+
(TOPOLOGY === "hub" ? it : it.skip)(
|
|
1434
|
+
"skips an empty __Secure- value for the plain pair",
|
|
1435
|
+
async () => {
|
|
1436
|
+
expect(
|
|
1437
|
+
await forwardedCookie(
|
|
1438
|
+
"__Secure-better-auth.session_token=; better-auth.session_token=tok.sig",
|
|
1439
|
+
),
|
|
1440
|
+
).toBe("better-auth.session_token=tok.sig");
|
|
1441
|
+
},
|
|
1442
|
+
);
|
|
1443
|
+
});
|
|
1444
|
+
|
|
1445
|
+
describe("AC-2 — no session pair, no cookie header", () => {
|
|
1446
|
+
(TOPOLOGY === "hub" ? it.each : it.skip.each)([
|
|
1447
|
+
["only the spoke's own cookies", `__Host-ailk-hub-session=${SEALED}; ailk-hub-session=${SEALED}; theme=dark`],
|
|
1448
|
+
[
|
|
1449
|
+
"near-miss names and a pair with no =",
|
|
1450
|
+
"Better-Auth.session_token=x; better-auth.session_token_x=y; better-auth.session_data=z; better-auth.session_token",
|
|
1451
|
+
],
|
|
1452
|
+
["no cookie header at all", null],
|
|
1453
|
+
])("%s", async (_label, cookie) => {
|
|
1454
|
+
expect(await forwardedCookie(cookie)).toBeNull();
|
|
1455
|
+
});
|
|
1456
|
+
});
|
|
1457
|
+
|
|
1458
|
+
/** Runs `fn` against `../relay` loaded with a spoke render of the topology seam. */
|
|
1459
|
+
async function onSpoke(fn: (relay: typeof import("../relay")) => Promise<void>): Promise<void> {
|
|
1460
|
+
await jest.isolateModulesAsync(async () => {
|
|
1461
|
+
jest.doMock("../topology.generated", () => ({
|
|
1462
|
+
...jest.requireActual<typeof import("../topology.generated")>("../topology.generated"),
|
|
1463
|
+
TOPOLOGY: "spoke",
|
|
1464
|
+
}));
|
|
1465
|
+
await fn(await import("../relay"));
|
|
1466
|
+
});
|
|
1467
|
+
}
|
|
1468
|
+
|
|
1469
|
+
describe("AC-3 — a spoke relays no session route", () => {
|
|
1470
|
+
it("answers 404 not_found and calls no hub, and lists only the five visitor pairs", async () => {
|
|
1471
|
+
await onSpoke(async (spoke) => {
|
|
1472
|
+
const res = await spoke.handleRelay(
|
|
1473
|
+
relayRequest(INVOICES, {
|
|
1474
|
+
headers: { cookie: `__Host-ailk-hub-session=${SEALED}; better-auth.session_token=tok.sig` },
|
|
1475
|
+
}),
|
|
1476
|
+
);
|
|
1477
|
+
expect(res.status).toBe(404);
|
|
1478
|
+
expect(await errorCode(res)).toBe("not_found");
|
|
1479
|
+
expect(fetchMock).not.toHaveBeenCalled();
|
|
1480
|
+
|
|
1481
|
+
expect(spoke.RELAY_ROUTES).toEqual([
|
|
1482
|
+
{ method: "POST", path: "/v1/leads/submit" },
|
|
1483
|
+
{ method: "POST", path: "/v1/leads/subscribe" },
|
|
1484
|
+
{ method: "POST", path: "/v1/leads/callback" },
|
|
1485
|
+
{ method: "GET", path: "/v1/schedule/availability" },
|
|
1486
|
+
{ method: "POST", path: "/v1/schedule/book" },
|
|
1487
|
+
]);
|
|
1488
|
+
expect(Object.isFrozen(spoke.RELAY_ROUTES)).toBe(true);
|
|
1489
|
+
});
|
|
1490
|
+
});
|
|
1491
|
+
});
|
|
1492
|
+
|
|
1493
|
+
describe("AC-4 — a spoke's visitor routes forward no cookie", () => {
|
|
1494
|
+
it.each(VISITOR_ENTRIES)(
|
|
1495
|
+
"$method $path never forwards the hub-session cookie",
|
|
1496
|
+
async (entry) => {
|
|
1497
|
+
await onSpoke(async (spoke) => {
|
|
1498
|
+
const res = await spoke.handleRelay(
|
|
1499
|
+
entryRequest(entry, { cookie: `__Host-ailk-hub-session=${SEALED}` }),
|
|
1500
|
+
);
|
|
1501
|
+
expect(res.status).toBe(201);
|
|
1502
|
+
});
|
|
1503
|
+
expect(sent().headers.get("cookie")).toBeNull();
|
|
1504
|
+
},
|
|
1505
|
+
);
|
|
1506
|
+
});
|
|
1507
|
+
});
|