create-ailk 0.40.1 → 0.40.3
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/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 +29 -13
- package/templates/apps/web/account.config.tsx +3 -2
- package/templates/apps/web/app/[locale]/(authed)/account/connect/__tests__/page.test.tsx +1 -1
- package/templates/apps/web/app/llms.txt/__tests__/site-listing.test.ts +10 -3
- package/templates/apps/web/app/llms.txt/route.ts +13 -3
- 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 +17 -10
- package/templates/apps/web/lib/__tests__/relay.test.ts +127 -12
- 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-identity-feature-list.test.ts +33 -5
- 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 +11 -8
- package/templates/apps/web/lib/mcp-oauth.ts +123 -17
- package/templates/apps/web/lib/relay.ts +48 -9
- 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-identity.ts +15 -1
- package/templates/apps/web/messages/en.json +10 -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
|
@@ -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
|
+
});
|
|
@@ -2,13 +2,14 @@
|
|
|
2
2
|
* Tests for `forwardedCookieInit` — the RSC cookie/origin-forwarding helper
|
|
3
3
|
* (#5371 shepherd fix-up).
|
|
4
4
|
*
|
|
5
|
-
* Contract: the returned `init.headers` always carries
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
5
|
+
* Contract: the returned `init.headers` always carries `cookie` — exactly
|
|
6
|
+
* one Better Auth session-token pair, the `__Secure-` name first, or `""`
|
|
7
|
+
* when the jar holds neither (#8089) — and carries `origin` ONLY when the
|
|
8
|
+
* incoming request's `Origin` header is present — never a fabricated value.
|
|
9
|
+
* This is what lets a Server Action `PUT`/`PATCH` through
|
|
10
|
+
* `@working-theory/api-client`'s `workspace.*` namespace pass `apps/api`'s
|
|
11
|
+
* same-origin CSRF check (`isOriginAllowed`), which Node's server-side
|
|
12
|
+
* `fetch` cannot satisfy on its own since it never sets `Origin`.
|
|
12
13
|
*
|
|
13
14
|
* On a spoke that signs in through its hub (`SIGN_IN_PROVIDER === "hub"`) it
|
|
14
15
|
* returns the hub credential instead. The provider is the seam's, mocked to
|
|
@@ -99,4 +100,68 @@ describe("forwardedCookieInit", () => {
|
|
|
99
100
|
expect(mockCookies).not.toHaveBeenCalled();
|
|
100
101
|
expect(mockHeaders).not.toHaveBeenCalled();
|
|
101
102
|
});
|
|
103
|
+
|
|
104
|
+
describe("forwards only the Better Auth session cookie (#8089)", () => {
|
|
105
|
+
async function initFor(jar: string, origin?: string) {
|
|
106
|
+
mockCookies.mockResolvedValue({ toString: () => jar });
|
|
107
|
+
mockHeaders.mockResolvedValue(new Headers(origin ? { origin } : {}));
|
|
108
|
+
return forwardedCookieInit();
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
it("forwards the __Secure- session cookie first and nothing else", async () => {
|
|
112
|
+
const init = await initFor(
|
|
113
|
+
"theme=dark; better-auth.session_token=plain.sig; __Secure-better-auth.session_token=sec.sig%3D; ailk-vid=v1; __Host-ailk-hub-session=SEALED",
|
|
114
|
+
"https://app.example.com",
|
|
115
|
+
);
|
|
116
|
+
|
|
117
|
+
expect(init).toEqual({
|
|
118
|
+
headers: {
|
|
119
|
+
cookie: "__Secure-better-auth.session_token=sec.sig%3D",
|
|
120
|
+
origin: "https://app.example.com",
|
|
121
|
+
},
|
|
122
|
+
});
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
it("forwards the plain session cookie when it is the only one", async () => {
|
|
126
|
+
const init = await initFor(
|
|
127
|
+
"NEXT_LOCALE=en; better-auth.session_token=plain.sig; theme=dark",
|
|
128
|
+
);
|
|
129
|
+
|
|
130
|
+
expect(init).toEqual({
|
|
131
|
+
headers: { cookie: "better-auth.session_token=plain.sig" },
|
|
132
|
+
});
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
it("skips a session cookie with an empty value", async () => {
|
|
136
|
+
const init = await initFor(
|
|
137
|
+
"__Secure-better-auth.session_token=; better-auth.session_token=plain.sig",
|
|
138
|
+
);
|
|
139
|
+
|
|
140
|
+
expect(init.headers.cookie).toBe("better-auth.session_token=plain.sig");
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
it("skips a session cookie pair with no `=`", async () => {
|
|
144
|
+
const init = await initFor(
|
|
145
|
+
"__Secure-better-auth.session_token; better-auth.session_token=plain.sig",
|
|
146
|
+
);
|
|
147
|
+
|
|
148
|
+
expect(init.headers.cookie).toBe("better-auth.session_token=plain.sig");
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
it("forwards an empty cookie header when the jar holds no session cookie", async () => {
|
|
152
|
+
const init = await initFor(
|
|
153
|
+
"theme=dark; ailk-vid=v1; __Host-ailk-hub-session=SEALED; __Host-ailk-hub-flow=F",
|
|
154
|
+
);
|
|
155
|
+
|
|
156
|
+
expect(init).toEqual({ headers: { cookie: "" } });
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
it("never matches a look-alike cookie name", async () => {
|
|
160
|
+
const init = await initFor(
|
|
161
|
+
"Better-Auth.session_token=a; better-auth.session_token_x=b; xbetter-auth.session_token=c; __secure-better-auth.session_token=d",
|
|
162
|
+
);
|
|
163
|
+
|
|
164
|
+
expect(init.headers.cookie).toBe("");
|
|
165
|
+
});
|
|
166
|
+
});
|
|
102
167
|
});
|
|
@@ -64,11 +64,32 @@ describe("services-path with services.path /capabilities", () => {
|
|
|
64
64
|
const mapped = mod.withPublicServicesPaths(items);
|
|
65
65
|
expect(mapped[0]?.path).toBe("/capabilities");
|
|
66
66
|
expect(mapped[1]?.flyout?.features[0]?.path).toBe("/capabilities/x");
|
|
67
|
-
expect(mapped[1]?.flyout?.actions[0]?.path).toBe("/capabilities");
|
|
67
|
+
expect(mapped[1]?.flyout?.actions?.[0]?.path).toBe("/capabilities");
|
|
68
68
|
expect(mapped[2]?.path).toBe("/docs");
|
|
69
69
|
expect(mapped[3]?.path).toBe("/servicesx");
|
|
70
70
|
});
|
|
71
71
|
|
|
72
|
+
it("maps a flyout with no actions and adds none (#10047)", () => {
|
|
73
|
+
const items: NavItem[] = [
|
|
74
|
+
{
|
|
75
|
+
labelKey: "more",
|
|
76
|
+
flyout: {
|
|
77
|
+
features: [{ labelKey: "x", path: "/services/x" }],
|
|
78
|
+
groups: [
|
|
79
|
+
{
|
|
80
|
+
headingKey: "h",
|
|
81
|
+
items: [{ labelKey: "x", path: "/services/x" }],
|
|
82
|
+
},
|
|
83
|
+
],
|
|
84
|
+
},
|
|
85
|
+
},
|
|
86
|
+
];
|
|
87
|
+
const flyout = mod.withPublicServicesPaths(items)[0]?.flyout;
|
|
88
|
+
expect(flyout?.features[0]?.path).toBe("/capabilities/x");
|
|
89
|
+
expect(flyout?.groups?.[0]?.items[0]?.path).toBe("/capabilities/x");
|
|
90
|
+
expect(flyout).not.toHaveProperty("actions");
|
|
91
|
+
});
|
|
92
|
+
|
|
72
93
|
it("maps a footer item", () => {
|
|
73
94
|
const columns = [
|
|
74
95
|
{
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* through the content adapter when a page's JSON-LD is composed, never from a
|
|
8
8
|
* directory scan. Under the mdx adapter no reader is registered.
|
|
9
9
|
*/
|
|
10
|
-
import { mkdtempSync, readdirSync, rmSync, writeFileSync } from "node:fs";
|
|
10
|
+
import { mkdirSync, mkdtempSync, readdirSync, rmSync, writeFileSync } from "node:fs";
|
|
11
11
|
import { tmpdir } from "node:os";
|
|
12
12
|
import { join } from "node:path";
|
|
13
13
|
|
|
@@ -227,7 +227,6 @@ describe("the featureList registration with no content directory (#10644 AC-2)",
|
|
|
227
227
|
};
|
|
228
228
|
|
|
229
229
|
function hubConnect(): void {
|
|
230
|
-
process.env.CONTENT_ADAPTER = "database";
|
|
231
230
|
process.env.AILK_SPOKE_KEY = "ailk_spk_TESTKEYxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
|
|
232
231
|
process.env.AILK_API_URL = "https://hub.example";
|
|
233
232
|
}
|
|
@@ -293,12 +292,41 @@ describe("the featureList registration with no content directory (#10644 AC-2)",
|
|
|
293
292
|
await expect(reader()).resolves.toBeUndefined();
|
|
294
293
|
});
|
|
295
294
|
|
|
295
|
+
// #11515 — a file-content site with a key reads the hub, and the file's
|
|
296
|
+
// scanned featureList rides a hub identity that carries a product.
|
|
297
|
+
const HUB_PRODUCT_IDENTITY = {
|
|
298
|
+
...HUB_IDENTITY,
|
|
299
|
+
secondary: { kind: "SoftwareApplication", name: "Hub App", url: `${ORIGIN}/app` },
|
|
300
|
+
};
|
|
301
|
+
it.each([
|
|
302
|
+
["a product: the file's featureList rides it", HUB_PRODUCT_IDENTITY, ["File A", "File B"]],
|
|
303
|
+
["no product: no featureList", HUB_IDENTITY, undefined],
|
|
304
|
+
])("hub-connected with a spoke key and CONTENT_ADAPTER unset, a hub identity with %s (#11515)", async (_label, identity, featureList) => {
|
|
305
|
+
hubConnect();
|
|
306
|
+
delete process.env.CONTENT_ADAPTER;
|
|
307
|
+
mkdirSync(join(root, "en", "Feature"), { recursive: true });
|
|
308
|
+
writeFileSync(join(root, "en", "Feature", "b.mdx"), "---\ntitle: File B\n---\n");
|
|
309
|
+
writeFileSync(join(root, "en", "Feature", "a.mdx"), "---\ntitle: File A\n---\n");
|
|
310
|
+
mockSiteConfigGet.mockResolvedValue({ ok: true, body: { identity, seo: null } });
|
|
311
|
+
load();
|
|
312
|
+
expect(calls("setSiteIdentityReader")).toHaveLength(1);
|
|
313
|
+
const reader = calls("setSiteIdentityReader")[0]![0] as () => Promise<unknown>;
|
|
314
|
+
await expect(reader()).resolves.toEqual({
|
|
315
|
+
siteName: "Hub Co",
|
|
316
|
+
baseUrl: ORIGIN,
|
|
317
|
+
identity,
|
|
318
|
+
...(featureList === undefined ? {} : { featureList }),
|
|
319
|
+
});
|
|
320
|
+
expect(mockSiteConfigGet).toHaveBeenCalledTimes(1);
|
|
321
|
+
});
|
|
322
|
+
|
|
296
323
|
it.each([
|
|
297
|
-
["no AILK_SPOKE_KEY", () => delete process.env.AILK_SPOKE_KEY],
|
|
298
324
|
["CONTENT_ADAPTER unset", () => delete process.env.CONTENT_ADAPTER],
|
|
299
|
-
|
|
325
|
+
["CONTENT_ADAPTER=database", () => (process.env.CONTENT_ADAPTER = "database")],
|
|
326
|
+
])("not hub-connected (no AILK_SPOKE_KEY, %s): registers no reader, and setSiteIdentity receives the file registration", (_label, arrange) => {
|
|
300
327
|
hubConnect();
|
|
301
|
-
|
|
328
|
+
delete process.env.AILK_SPOKE_KEY;
|
|
329
|
+
arrange();
|
|
302
330
|
load();
|
|
303
331
|
expect(calls("setSiteIdentityReader")).toEqual([]);
|
|
304
332
|
expect(calls("setSiteIdentity")).toEqual([[readSiteIdentity(root)]]);
|
|
@@ -67,6 +67,8 @@ export interface AuthEmailPayload {
|
|
|
67
67
|
expiresInMinutes?: number;
|
|
68
68
|
agreements?: string[];
|
|
69
69
|
locale?: string;
|
|
70
|
+
/** The workspace a hub-sign-in site's link is sent for (workspace-email-sender-name). */
|
|
71
|
+
workspaceId?: string;
|
|
70
72
|
}
|
|
71
73
|
|
|
72
74
|
export interface AuthEmailRequest {
|
|
@@ -137,6 +139,9 @@ export function buildAuthEmailRequest(
|
|
|
137
139
|
? { agreements: payload.agreements }
|
|
138
140
|
: {}),
|
|
139
141
|
...(payload.locale !== undefined ? { locale: payload.locale } : {}),
|
|
142
|
+
...(payload.workspaceId !== undefined
|
|
143
|
+
? { workspaceId: payload.workspaceId }
|
|
144
|
+
: {}),
|
|
140
145
|
});
|
|
141
146
|
const timestamp = String(Math.floor(Date.now() / 1000));
|
|
142
147
|
const signature = `sha256=${createHmac("sha256", secret)
|
|
@@ -496,6 +501,16 @@ export interface PurchaseCaptureStore {
|
|
|
496
501
|
*/
|
|
497
502
|
export const purchaseCapture = new AsyncLocalStorage<PurchaseCaptureStore>();
|
|
498
503
|
|
|
504
|
+
/**
|
|
505
|
+
* The workspace a magic link is sent for (workspace-email-sender-name). The
|
|
506
|
+
* hub web's spoke-hosted email route runs `signInMagicLink` inside
|
|
507
|
+
* `senderWorkspace.run(workspaceId, …)` with the workspace the hub API read
|
|
508
|
+
* from the spoke's key, never a visitor value; `sendMagicLink` puts it on the
|
|
509
|
+
* signed payload, so the relay sends the link as "<workspace> via
|
|
510
|
+
* <organization>". Outside a run nothing changes.
|
|
511
|
+
*/
|
|
512
|
+
export const senderWorkspace = new AsyncLocalStorage<string>();
|
|
513
|
+
|
|
499
514
|
/**
|
|
500
515
|
* Magic-link token lifetime (#7435 § D2). Five minutes — the library default,
|
|
501
516
|
* and the number `packages/email`'s magic-link template already promises ("This
|
|
@@ -613,6 +628,8 @@ function makeSendMagicLink(deps: MagicLinkDeps) {
|
|
|
613
628
|
// A new address has no user yet; the relay only logs `userId`, so a
|
|
614
629
|
// sign-up link carries the fixed sentinel and the binding's ids, never
|
|
615
630
|
// the request's (#9720 D6).
|
|
631
|
+
const workspaceId = senderWorkspace.getStore();
|
|
632
|
+
const sender = workspaceId === undefined ? {} : { workspaceId };
|
|
616
633
|
let payload: AuthEmailPayload;
|
|
617
634
|
if (found) {
|
|
618
635
|
payload = {
|
|
@@ -620,6 +637,7 @@ function makeSendMagicLink(deps: MagicLinkDeps) {
|
|
|
620
637
|
userId: found.user.id,
|
|
621
638
|
to: found.user.email,
|
|
622
639
|
url: data.url,
|
|
640
|
+
...sender,
|
|
623
641
|
};
|
|
624
642
|
} else if (binding) {
|
|
625
643
|
payload = {
|
|
@@ -629,6 +647,7 @@ function makeSendMagicLink(deps: MagicLinkDeps) {
|
|
|
629
647
|
url: data.url,
|
|
630
648
|
agreements: binding.agreements,
|
|
631
649
|
locale: binding.locale,
|
|
650
|
+
...sender,
|
|
632
651
|
};
|
|
633
652
|
} else {
|
|
634
653
|
// No address in the line — the PII boundary holds for unknown addresses
|
|
@@ -2,11 +2,12 @@
|
|
|
2
2
|
* The hub read of the site's identity and seo (#11456, spec
|
|
3
3
|
* docs/specs/11456-a-hub-connected-site-reads-spec.md D3).
|
|
4
4
|
*
|
|
5
|
-
* A HUB-CONNECTED site —
|
|
6
|
-
* `
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
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.
|
|
10
11
|
*
|
|
11
12
|
* Cached with Next's `unstable_cache` under `siteConfigTag()` for at most
|
|
12
13
|
* `HUB_SITE_REVALIDATE_SECONDS`. The `site-config` revalidate event an Admin
|
|
@@ -32,7 +33,6 @@
|
|
|
32
33
|
import { createHash } from "node:crypto";
|
|
33
34
|
|
|
34
35
|
import { sendsSpokeKey, siteConfig } from "@working-theory/api-client";
|
|
35
|
-
import { resolvedAdapterKind } from "@working-theory/content-adapters";
|
|
36
36
|
import {
|
|
37
37
|
siteConfigTag,
|
|
38
38
|
siteWorkspaceSegment,
|
|
@@ -57,9 +57,12 @@ export const HUB_SITE_REVALIDATE_SECONDS = 300;
|
|
|
57
57
|
/** A read slower than this is a failed read. */
|
|
58
58
|
export const HUB_SITE_TIMEOUT_MS = 3_000;
|
|
59
59
|
|
|
60
|
-
/**
|
|
60
|
+
/**
|
|
61
|
+
* Whether this site reads its identity and seo from the hub: a spoke key on
|
|
62
|
+
* the wire, whatever the content adapter (#11515).
|
|
63
|
+
*/
|
|
61
64
|
export function hubConnected(): boolean {
|
|
62
|
-
return
|
|
65
|
+
return sendsSpokeKey();
|
|
63
66
|
}
|
|
64
67
|
|
|
65
68
|
/** The last value `readHubSite` resolved on this instance. */
|