create-ailk 0.40.1 → 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.
Files changed (57) hide show
  1. package/README.md +26 -4
  2. package/dist/add-module.d.ts +2 -1
  3. package/dist/add-module.js +17 -1
  4. package/dist/cutover.d.ts +7 -3
  5. package/dist/cutover.js +8 -3
  6. package/dist/lib/declared-env.d.ts +5 -1
  7. package/dist/lib/declared-env.js +6 -1
  8. package/dist/lib/env-catalog.d.ts +3 -2
  9. package/dist/lib/env-catalog.js +4 -8
  10. package/dist/module-architecture.js +0 -1
  11. package/dist/programmatic.js +18 -9
  12. package/dist/remove-module.js +1 -1
  13. package/dist/seam-refresh.d.ts +60 -0
  14. package/dist/seam-refresh.js +214 -0
  15. package/dist/spoke-checkout.d.ts +12 -3
  16. package/dist/spoke-checkout.js +14 -5
  17. package/dist/sync-routes.d.ts +10 -1
  18. package/dist/sync-routes.js +61 -6
  19. package/dist/template-record.d.ts +14 -2
  20. package/dist/template-record.js +60 -22
  21. package/dist/topology.js +3 -4
  22. package/dist/update.d.ts +13 -1
  23. package/dist/update.js +100 -8
  24. package/package.json +3 -3
  25. package/templates/.env.example +6 -0
  26. package/templates/.github/workflows/ci.yml +3 -0
  27. package/templates/apps/api/.env.example +12 -0
  28. package/templates/apps/api/CLAUDE.md +10 -7
  29. package/templates/apps/mcp/CLAUDE.md +25 -5
  30. package/templates/apps/web/.env.example +7 -1
  31. package/templates/apps/web/CLAUDE.md +29 -13
  32. package/templates/apps/web/app/[locale]/(authed)/account/connect/__tests__/page.test.tsx +1 -1
  33. package/templates/apps/web/app/llms.txt/__tests__/site-listing.test.ts +10 -3
  34. package/templates/apps/web/app/llms.txt/route.ts +13 -3
  35. package/templates/apps/web/app/openapi.json/__tests__/route.test.ts +15 -7
  36. package/templates/apps/web/auth.config.tsx +2 -0
  37. package/templates/apps/web/auth.ts +28 -4
  38. package/templates/apps/web/jest.config.cjs +1 -1
  39. package/templates/apps/web/lib/__tests__/auth-email.test.ts +21 -0
  40. package/templates/apps/web/lib/__tests__/docs-path.test.ts +20 -2
  41. package/templates/apps/web/lib/__tests__/hub-site-config.test.ts +17 -10
  42. package/templates/apps/web/lib/__tests__/relay.test.ts +127 -12
  43. package/templates/apps/web/lib/__tests__/server-api.test.ts +72 -7
  44. package/templates/apps/web/lib/__tests__/services-path.test.ts +22 -1
  45. package/templates/apps/web/lib/__tests__/site-identity-feature-list.test.ts +33 -5
  46. package/templates/apps/web/lib/auth-email.ts +19 -0
  47. package/templates/apps/web/lib/docs-path.ts +1 -1
  48. package/templates/apps/web/lib/hub-site-config.ts +11 -8
  49. package/templates/apps/web/lib/mcp-oauth.ts +123 -17
  50. package/templates/apps/web/lib/relay.ts +48 -9
  51. package/templates/apps/web/lib/server-api.ts +37 -4
  52. package/templates/apps/web/lib/services-path.ts +1 -1
  53. package/templates/apps/web/messages/en.json +10 -8
  54. package/templates/apps/web/middleware.ts +4 -2
  55. package/templates/apps/web/src/lib/routes.ts +13 -0
  56. package/templates/tools/declared-env.ts +6 -1
  57. package/versions.json +51 -51
@@ -20,7 +20,13 @@
20
20
  * - one issuer per token (#10912 D4): a server given an `issuerTag` binds
21
21
  * `ailk:issuer:<tag>` beside the workspace, and every server's code
22
22
  * exchange, refresh and token-info accept only their own tokens — none
23
- * for a server with no tag, as a site's apps/web has.
23
+ * for a server with no tag, as a site's apps/web has;
24
+ * - one sign-in for every workspace (#11607 D1a): a server given
25
+ * `allWorkspaces` (the Admin) binds `ailk:all-workspaces` in place of the
26
+ * one workspace, after a confirmation naming every workspace it reaches,
27
+ * and its token-info answers the person's live memberships at each call
28
+ * (D2). A server without it never binds one and treats such a token as
29
+ * another server's.
24
30
  *
25
31
  * Every refusal is code-shaped: no English string reaches a client. No answer
26
32
  * or log line carries a token, code, verifier or client secret.
@@ -28,6 +34,7 @@
28
34
  import { createHash, timingSafeEqual } from "node:crypto";
29
35
 
30
36
  import {
37
+ ALL_WORKSPACES_SCOPE,
31
38
  ISSUER_SCOPE_PREFIX,
32
39
  lowerRole,
33
40
  MCP_SCOPES,
@@ -76,6 +83,12 @@ export interface McpOAuthDeps {
76
83
  * entry, and only such tokens are this server's.
77
84
  */
78
85
  issuerTag?: string;
86
+ /**
87
+ * Bind `ailk:all-workspaces` at consent in place of one workspace (#11607
88
+ * D1a) — the Admin's. Absent: today's one-workspace consent, and a token
89
+ * carrying the entry is not this server's. Requires `issuerTag`.
90
+ */
91
+ allWorkspaces?: boolean;
79
92
  }
80
93
 
81
94
  /** The scopes `/mcp/authorize` accepts a request for. */
@@ -228,6 +241,8 @@ interface OAuthApplicationRow {
228
241
  createdAt: Date;
229
242
  }
230
243
 
244
+ // The plugin stores both tokens as it is given them and validates by lookup on
245
+ // those columns; hashing them would mean patching it. Accepted (#10459 D7).
231
246
  interface OAuthAccessTokenRow {
232
247
  accessToken: string;
233
248
  refreshToken: string;
@@ -248,6 +263,12 @@ function parseValue(raw: string): AuthorizationValue | null {
248
263
  }
249
264
 
250
265
  export function mcpOAuthPlugin(deps: McpOAuthDeps) {
266
+ // An untagged server's all-workspaces token is one no API honours (#11607
267
+ // D1a): refuse to build it at all.
268
+ if (deps.allWorkspaces === true && !deps.issuerTag) {
269
+ throw new Error("mcp_oauth_all_workspaces_requires_issuer_tag");
270
+ }
271
+ const allWorkspaces = deps.allWorkspaces === true;
251
272
  type AuthCtx = Parameters<Parameters<typeof createAuthMiddleware>[0]>[0]["context"];
252
273
  /** What the helpers below need of an endpoint's or a hook's context. */
253
274
  interface Ctx {
@@ -295,7 +316,7 @@ export function mcpOAuthPlugin(deps: McpOAuthDeps) {
295
316
  });
296
317
  }
297
318
 
298
- /** Bounded cleanup on every registration (SEC-10357-03). */
319
+ /** Bounded cleanup after an accepted consent (SEC-10357-03, #10459 D4). */
299
320
  async function sweep(ctx: Ctx): Promise<void> {
300
321
  const adapter = ctx.context.adapter;
301
322
  await adapter.deleteMany({
@@ -333,9 +354,29 @@ export function mcpOAuthPlugin(deps: McpOAuthDeps) {
333
354
  }
334
355
  }
335
356
 
336
- /** Whether a token or code's scopes are this server's own (#10912 D4). */
357
+ /**
358
+ * Whether a token or code's scopes are this server's own (#10912 D4): its
359
+ * issuer entry, and an `ailk:all-workspaces` entry only on a server that
360
+ * binds one (#11607 D1a).
361
+ */
337
362
  function ownsScopes(scopes: string | readonly string[]): boolean {
338
- return tokenIssuedBy(typeof scopes === "string" ? scopes : scopes.join(" "), deps.issuerTag);
363
+ const joined = typeof scopes === "string" ? scopes : scopes.join(" ");
364
+ return (
365
+ tokenIssuedBy(joined, deps.issuerTag) && (allWorkspaces || !joined.split(" ").includes(ALL_WORKSPACES_SCOPE))
366
+ );
367
+ }
368
+
369
+ /**
370
+ * The all-workspaces consent's union (#11607 D1a): every workspace, and the
371
+ * requested scopes any of the person's roles may approve, in `MCP_SCOPES` order.
372
+ */
373
+ async function offeredReach(userId: string, requested: string[]) {
374
+ const workspaces = await offeredWorkspaces(userId, requested);
375
+ const union = new Set(workspaces.flatMap((w) => w.offered));
376
+ return {
377
+ workspaces: workspaces.map(({ id, name, organizationName, role }) => ({ id, name, organizationName, role })),
378
+ offered: MCP_SCOPES.filter((s) => union.has(s)),
379
+ };
339
380
  }
340
381
 
341
382
  async function deleteTokensOf(ctx: Ctx, where: Array<{ field: string; value: string }>): Promise<number> {
@@ -359,6 +400,8 @@ export function mcpOAuthPlugin(deps: McpOAuthDeps) {
359
400
  }
360
401
  const scopes = typeof query.scope === "string" ? query.scope.split(" ").filter(Boolean) : [];
361
402
  if (scopes.some((s) => !REQUESTABLE_SCOPES.has(s))) throw refuse("BAD_REQUEST", "invalid_scope");
403
+ // The plugin never reads the consent row, so this forced prompt is
404
+ // what makes a revoked client ask the person again (#10459 D2).
362
405
  return { context: { query: { ...query, prompt: "consent" } } };
363
406
  }),
364
407
  },
@@ -387,12 +430,19 @@ export function mcpOAuthPlugin(deps: McpOAuthDeps) {
387
430
  ) {
388
431
  throw refuse("BAD_REQUEST", "invalid_client_metadata");
389
432
  }
390
- // The register endpoint answers with a raw Response, which skips
391
- // every after-hook, so the sweep runs here.
392
- await sweep(ctx);
393
433
  return { context: { body: { ...body, client_name: normaliseClientName(body.client_name) } } };
394
434
  }),
395
435
  },
436
+ {
437
+ matcher: (ctx) => ctx.path === "/change-password",
438
+ // A changed password signs the person's other devices out; the
439
+ // caller gets a new session (#10459 D5). The after-hook below then
440
+ // ends their MCP tokens, so no surviving session can approve a
441
+ // code in between.
442
+ handler: createAuthMiddleware(async (ctx) => {
443
+ return { context: { body: { ...bodyOf(ctx.body), revokeOtherSessions: true } } };
444
+ }),
445
+ },
396
446
  {
397
447
  matcher: (ctx) => ctx.path === "/mcp/token",
398
448
  handler: createAuthMiddleware(async (ctx) => {
@@ -488,8 +538,19 @@ export function mcpOAuthPlugin(deps: McpOAuthDeps) {
488
538
  model: "oauthAccessToken",
489
539
  where: [{ field: "refreshToken", value: body.refresh_token }],
490
540
  });
491
- if (!used) return;
492
- await deleteTokensOf(ctx, [{ field: "refreshToken", value: body.refresh_token }]);
541
+ // The delete is the check: only the refresh that removes the used
542
+ // row keeps its pair. A row already gone — deleted after the
543
+ // plugin read it by a revoke, a password change or a concurrent
544
+ // refresh of the same token — refuses, and the pair the plugin
545
+ // just minted is deleted, so the client never holds it
546
+ // (SEC-10393-01, #10459 D1).
547
+ const rotated = used
548
+ ? await deleteTokensOf(ctx, [{ field: "refreshToken", value: body.refresh_token }])
549
+ : 0;
550
+ if (!used || rotated === 0) {
551
+ await deleteTokensOf(ctx, [{ field: "accessToken", value: returned.access_token }]);
552
+ throw refuse("BAD_REQUEST", "invalid_grant");
553
+ }
493
554
  await ctx.context.internalAdapter.createVerificationValue({
494
555
  identifier: ROTATED_PREFIX + sha256(body.refresh_token),
495
556
  value: JSON.stringify({ userId: used.userId, clientId: used.clientId }),
@@ -550,8 +611,12 @@ export function mcpOAuthPlugin(deps: McpOAuthDeps) {
550
611
  where: [{ field: "clientId", value: value.clientId }],
551
612
  });
552
613
  if (!client) throw refuse("NOT_FOUND", "invalid_request");
614
+ const shown = { name: normaliseClientName(client.name), redirectOrigin: redirectOriginOf(value.redirectURI) };
615
+ if (allWorkspaces) {
616
+ return ctx.json({ client: shown, allWorkspaces: true, ...(await offeredReach(userId, value.scope)) });
617
+ }
553
618
  return ctx.json({
554
- client: { name: normaliseClientName(client.name), redirectOrigin: redirectOriginOf(value.redirectURI) },
619
+ client: shown,
555
620
  workspaces: await offeredWorkspaces(userId, value.scope),
556
621
  });
557
622
  },
@@ -583,12 +648,25 @@ export function mcpOAuthPlugin(deps: McpOAuthDeps) {
583
648
  return ctx.json({ redirectURI: redirect.toString() });
584
649
  }
585
650
 
586
- const workspace = (await offeredWorkspaces(userId, value.scope)).find(
587
- (w) => w.id === ctx.body.workspace_id,
588
- );
589
651
  const chosen = ctx.body.scopes ?? [];
590
- if (!workspace || chosen.some((s) => !(workspace.offered as string[]).includes(s))) {
591
- throw refuse("BAD_REQUEST", "invalid_scope");
652
+ let binding: string;
653
+ if (allWorkspaces) {
654
+ // The reach is every workspace, so naming one is a client of the
655
+ // single-workspace consent (#11607 D1a).
656
+ if (ctx.body.workspace_id !== undefined) throw refuse("BAD_REQUEST", "invalid_request");
657
+ const reach = await offeredReach(userId, value.scope);
658
+ if (reach.workspaces.length === 0 || chosen.some((s) => !(reach.offered as string[]).includes(s))) {
659
+ throw refuse("BAD_REQUEST", "invalid_scope");
660
+ }
661
+ binding = ALL_WORKSPACES_SCOPE;
662
+ } else {
663
+ const workspace = (await offeredWorkspaces(userId, value.scope)).find(
664
+ (w) => w.id === ctx.body.workspace_id,
665
+ );
666
+ if (!workspace || chosen.some((s) => !(workspace.offered as string[]).includes(s))) {
667
+ throw refuse("BAD_REQUEST", "invalid_scope");
668
+ }
669
+ binding = WORKSPACE_SCOPE_PREFIX + workspace.id;
592
670
  }
593
671
 
594
672
  // The plugin's token endpoint treats anything but "public" as
@@ -611,9 +689,11 @@ export function mcpOAuthPlugin(deps: McpOAuthDeps) {
611
689
 
612
690
  // `openid`, `profile` and `email` are never bound: no id_token.
613
691
  const scope = [
692
+ // Always bound: the plugin issues and refreshes only for it, and
693
+ // AILK's refresh tokens rotate and are revocable. Accepted (#10459 D6).
614
694
  "offline_access",
615
695
  ...new Set(chosen),
616
- WORKSPACE_SCOPE_PREFIX + workspace.id,
696
+ binding,
617
697
  // The issuer entry, only on a server that has a tag (#10912 D4).
618
698
  ...(deps.issuerTag ? [ISSUER_SCOPE_PREFIX + deps.issuerTag] : []),
619
699
  ];
@@ -640,6 +720,10 @@ export function mcpOAuthPlugin(deps: McpOAuthDeps) {
640
720
  updatedAt: new Date(),
641
721
  },
642
722
  });
723
+ // The register endpoint answers a raw Response, which skips every
724
+ // after-hook, and is anonymous; so the sweep runs here, after a
725
+ // signed-in approval, in the background (#10459 D4).
726
+ await ctx.context.runInBackgroundOrAwait(sweep(ctx));
643
727
  expireCookie(ctx, { name: CONSENT_COOKIE, attributes: { path: "/" } });
644
728
  redirect.searchParams.set("code", code);
645
729
  if (value.state) redirect.searchParams.set("state", value.state);
@@ -724,7 +808,29 @@ export function mcpOAuthPlugin(deps: McpOAuthDeps) {
724
808
  if (!row || new Date(row.accessTokenExpiresAt) < new Date() || !row.userId) throw invalid();
725
809
  // Another issuer's token answers as an unknown one (#10912 D4).
726
810
  if (!ownsScopes(row.scopes)) throw invalid();
727
- const { workspaceId } = parseGrantedScopes(row.scopes);
811
+ const granted = parseGrantedScopes(row.scopes);
812
+ if (granted.allWorkspaces) {
813
+ // The reach is the live membership set, read now — never a list
814
+ // held from consent (#11607 D2). None left: nothing to reach.
815
+ const memberships = await deps.readMemberships(row.userId);
816
+ if (memberships.length === 0) throw invalid();
817
+ return ctx.json({
818
+ active: true,
819
+ userId: row.userId,
820
+ clientId: row.clientId,
821
+ allWorkspaces: true,
822
+ workspaces: memberships.map((m) => ({
823
+ workspaceId: m.workspaceId,
824
+ workspaceName: m.workspaceName,
825
+ organizationName: m.organizationName,
826
+ role: m.role,
827
+ actingRole: lowerRole(m.role as MembershipRole, "member"),
828
+ grants: grantsForWorkspace(row.scopes, m.workspaceId, m.role) ?? [],
829
+ })),
830
+ expiresAt: new Date(row.accessTokenExpiresAt).toISOString(),
831
+ });
832
+ }
833
+ const { workspaceId } = granted;
728
834
  if (!workspaceId) throw invalid();
729
835
  const membership = (await deps.readMemberships(row.userId)).find((m) => m.workspaceId === workspaceId);
730
836
  if (!membership) throw invalid();
@@ -16,8 +16,10 @@
16
16
  *
17
17
  * - ONLY THE LIST (D2). `RELAY_ROUTES` is the fixed set of (method, path)
18
18
  * pairs a browser form calls; an exact, case-sensitive match on the
19
- * pathname or a 404 with no hub call. Adding a route is a reviewed change
20
- * to this list, its test and apps/web/.env.example.
19
+ * pathname or a 404 with no hub call. The session route is on the list on
20
+ * a hub only (#8066 D2): a spoke answers it 404 with no hub call. Adding a
21
+ * route is a reviewed change to this list, its test and
22
+ * apps/web/.env.example.
21
23
  * - NO CROSS-SITE POST (D4). `Sec-Fetch-Site` other than `same-origin`, or
22
24
  * an `Origin` whose host is not this site's own, is refused with 403
23
25
  * before the hub is called. A POST must be JSON, which no cross-origin
@@ -27,7 +29,9 @@
27
29
  * still count each visitor (#7615's rule; `flow.actions.ts`).
28
30
  * - AN ALLOW-LIST OF HEADERS (D3). Nothing else from the incoming request is
29
31
  * forwarded: no `authorization`, no client-sent `x-ailk-*`, no `host`, and
30
- * a `cookie` only on the one session route.
32
+ * a `cookie` only on the one session route — and there only the hub's own
33
+ * Better Auth session cookie (#8066 D1), never a spoke's sealed
34
+ * `__Host-ailk-hub-session` or any other cookie.
31
35
  * - A PER-VISITOR BUDGET (#7707, D1-D7). Each visitor gets 8 calls per 10
32
36
  * minutes across the five visitor routes, and 30 per 10 minutes on the
33
37
  * session route, counted in this instance's own in-memory store; the
@@ -58,6 +62,7 @@ import {
58
62
  import { browserApiOrigin } from "./api-origin.generated";
59
63
  import { runBotCheck } from "./bot-check";
60
64
  import { readConsentVisitorFromCookieHeader } from "./consent-visitor";
65
+ import { TOPOLOGY } from "./topology.generated";
61
66
 
62
67
  type RelayMethod = "GET" | "POST";
63
68
 
@@ -77,9 +82,10 @@ function route(method: RelayMethod, path: string): RelayRoute {
77
82
  */
78
83
  /**
79
84
  * The one session route: a site-admin, cookie-authenticated write. It is
80
- * forwarded with the visitor's `cookie` and `Origin` (the hub still checks
81
- * that `Origin` against its trusted list), mirroring `forwardedCookieInit` in
82
- * lib/server-api.ts. Every other entry is a visitor route.
85
+ * forwarded with the visitor's Better Auth session cookie and `Origin` (the
86
+ * hub still checks that `Origin` against its trusted list). Every other entry
87
+ * is a visitor route. A hub only (#8066 D2): from a spoke the hub has no
88
+ * cookie session to read, and nothing a spoke renders calls it.
83
89
  */
84
90
  const SESSION_ROUTE = route("POST", "/v1/commerce/invoices");
85
91
 
@@ -95,7 +101,7 @@ export const RELAY_ROUTES: readonly RelayRoute[] = Object.freeze([
95
101
  CALLBACK_ROUTE,
96
102
  route("GET", "/v1/schedule/availability"),
97
103
  BOOK_ROUTE,
98
- SESSION_ROUTE,
104
+ ...(TOPOLOGY === "hub" ? [SESSION_ROUTE] : []),
99
105
  ]);
100
106
 
101
107
  /**
@@ -425,6 +431,39 @@ async function readCapped(
425
431
  return new TextDecoder().decode(bytes);
426
432
  }
427
433
 
434
+ /**
435
+ * The two Better Auth session-token cookies the hub reads (#8066 D1): a copy
436
+ * of `COOKIE_NAMES` in packages/api/src/middleware/auth.ts, which apps/web
437
+ * cannot import. If that list changes, this one changes in the same PR.
438
+ */
439
+ const BETTER_AUTH_SESSION_COOKIES: readonly string[] = [
440
+ "better-auth.session_token",
441
+ "__Secure-better-auth.session_token",
442
+ ];
443
+
444
+ /**
445
+ * The one session cookie pair the session route forwards (#8066 D1), parsed
446
+ * by the hub's own `readSessionCookie` rules: split on `;`, the trimmed name
447
+ * before the first `=` matched exactly, a pair with no `=` or an empty value
448
+ * dropped. The first `__Secure-` pair wins over the first plain one, so a
449
+ * plain-named cookie, which any host can set, cannot shadow the visitor's
450
+ * secure one (SEC-8066-1). `__Secure-` requires only the Secure flag, not a
451
+ * host-only cookie, so a sibling https host can still set one.
452
+ * `undefined` when there is none.
453
+ */
454
+ function sessionCookieHeader(raw: string | null): string | undefined {
455
+ const pairs = (raw ?? "").split(";").flatMap((part) => {
456
+ const eq = part.indexOf("=");
457
+ if (eq < 0) return [];
458
+ const name = part.slice(0, eq).trim();
459
+ const value = part.slice(eq + 1).trim();
460
+ return value && BETTER_AUTH_SESSION_COOKIES.includes(name)
461
+ ? [`${name}=${value}`]
462
+ : [];
463
+ });
464
+ return pairs.find((pair) => pair.startsWith("__Secure-")) ?? pairs[0];
465
+ }
466
+
428
467
  /** The outbound headers, built from an allow-list (D3). Never a spread of the incoming set. */
429
468
  function relayHeaders(
430
469
  request: Request,
@@ -444,8 +483,8 @@ function relayHeaders(
444
483
  if (visitorIp) out["x-forwarded-for"] = visitorIp;
445
484
 
446
485
  if (entry === SESSION_ROUTE) {
447
- const cookie = incoming.get("cookie");
448
- if (cookie) out.cookie = cookie;
486
+ const sessionCookie = sessionCookieHeader(incoming.get("cookie"));
487
+ if (sessionCookie) out.cookie = sessionCookie;
449
488
  const origin = incoming.get("origin");
450
489
  if (origin) out.origin = origin;
451
490
  } else {
@@ -2,7 +2,8 @@
2
2
  * Server-side (RSC) helper for reading the operator-dashboard read API
3
3
  * (#4665 D9).
4
4
  *
5
- * Forwards the incoming request's cookies to `@working-theory/api-client`'s
5
+ * Forwards the incoming request's Better Auth session cookie — only that one
6
+ * cookie, the `__Secure-` name first (#8089) — to `@working-theory/api-client`'s
6
7
  * `waitlistExperiments` / `workspace` namespaces (B0, #4671; #5371) so
7
8
  * `apps/api`'s cookie-session auth preHandler resolves the SAME Better Auth
8
9
  * session the browser holds — both apps share the session store. Every page
@@ -64,8 +65,40 @@ interface ErrorBody {
64
65
  }
65
66
 
66
67
  /**
67
- * Forward the incoming request's cookies — and, when present, its `Origin` —
68
- * as the `init` every `waitlistExperiments.*` / `workspace.*` call accepts.
68
+ * The two Better Auth session-token cookies the API reads, secure name first
69
+ * (#8089 D1): a copy of `COOKIE_NAMES` in packages/api/src/middleware/auth.ts,
70
+ * which apps/web cannot import. If that list changes, this one changes in the
71
+ * same PR.
72
+ */
73
+ const BETTER_AUTH_SESSION_COOKIES = [
74
+ "__Secure-better-auth.session_token",
75
+ "better-auth.session_token",
76
+ ] as const;
77
+
78
+ /**
79
+ * The one session cookie pair to forward. It parses by the API's own
80
+ * `readSessionCookie` rules — split on `;`, the trimmed name before the first
81
+ * `=` matched exactly, a pair with no `=` or an empty value skipped — but,
82
+ * unlike that reader, picks by allow-list order rather than header order: a
83
+ * `__Secure-` cookie needs a secure origin to be set, so an http origin
84
+ * cannot plant one to stand in for the visitor's. `""` when there is none.
85
+ */
86
+ function sessionCookiePair(jar: string): string {
87
+ const values = new Map<string, string>();
88
+ for (const part of jar.split(";")) {
89
+ const eq = part.indexOf("=");
90
+ if (eq < 0) continue;
91
+ const value = part.slice(eq + 1).trim();
92
+ if (value) values.set(part.slice(0, eq).trim(), value);
93
+ }
94
+ const name = BETTER_AUTH_SESSION_COOKIES.find((n) => values.has(n));
95
+ return name ? `${name}=${values.get(name)}` : "";
96
+ }
97
+
98
+ /**
99
+ * Forward the incoming request's Better Auth session cookie (only it, #8089)
100
+ * — and, when present, its `Origin` — as the `init` every
101
+ * `waitlistExperiments.*` / `workspace.*` call accepts.
69
102
  * Call once per request — `cookies()` / `headers()` read the current RSC
70
103
  * request context.
71
104
  *
@@ -89,7 +122,7 @@ export async function forwardedCookieInit(): Promise<{
89
122
  headers: Record<string, string>;
90
123
  }> {
91
124
  if (SIGN_IN_PROVIDER === "hub") return hubSessionInit();
92
- const cookieHeader = (await cookies()).toString();
125
+ const cookieHeader = sessionCookiePair((await cookies()).toString());
93
126
  const origin = (await headers()).get("origin");
94
127
  return { headers: { cookie: cookieHeader, ...(origin ? { origin } : {}) } };
95
128
  }
@@ -67,7 +67,7 @@ function mapFlyout(flyout: NavFlyout): NavFlyout {
67
67
  })),
68
68
  }
69
69
  : {}),
70
- actions: flyout.actions.map(mapPath),
70
+ ...(flyout.actions ? { actions: flyout.actions.map(mapPath) } : {}),
71
71
  };
72
72
  }
73
73
 
@@ -689,15 +689,19 @@
689
689
  "editor": {
690
690
  "toolChanges": "Show unsaved changes",
691
691
  "backLabel": "Pages",
692
+ "statusLive": "Live",
692
693
  "statusDraft": "Draft",
693
- "statusPublished": "Published",
694
- "statusPublishedNewer": "Published, newer changes not live",
694
+ "statusDraftHint": "Someone who can publish needs to publish it.",
695
+ "publishButton": "Publish",
696
+ "publishing": "Publishing…",
697
+ "publishMenu": "More publish options",
698
+ "discardChanges": "Discard changes",
699
+ "discardConfirm": "Discard all unpublished changes?",
700
+ "discardConfirmDetail": "The page goes back to what's live.",
701
+ "discardCancel": "Cancel",
702
+ "discardError": "Could not discard the changes. Try again.",
695
703
  "publishedSwitch": "Published",
696
704
  "publishBlockedHint": "Publish waits until the page is ready.",
697
- "publishChanges": "Publish changes",
698
- "unsaved": "Unsaved",
699
- "unsavedChanges": "Unsaved changes",
700
- "discardButton": "Discard",
701
705
  "loading": "Loading…",
702
706
  "loadError": "Could not load this page. Try again.",
703
707
  "retryButton": "Try again",
@@ -760,9 +764,7 @@
760
764
  "altWhy": "Screen readers and search engines can't see an image without alt text.",
761
765
  "altOutcome": "Every reader gets the image's meaning, and the page is easier to find."
762
766
  },
763
- "saveButton": "Save",
764
767
  "saving": "Saving…",
765
- "saved": "Saved",
766
768
  "saveError": "Could not save. Try again.",
767
769
  "publishError": "Could not publish. Try again.",
768
770
  "unpublishError": "Could not unpublish. Try again.",
@@ -20,8 +20,9 @@
20
20
  // the security headers are stamped.
21
21
  //
22
22
  // The spoke file routes (#9162) — `/reports/<slug>/file`,
23
- // `/account/inbox/message/<id>/file` and
24
- // `/account/artifacts/<pieceId>/versions/<version>/file` — get every baseline
23
+ // `/account/inbox/message/<id>/file`,
24
+ // `/account/artifacts/<pieceId>/versions/<version>/file` and the data export
25
+ // `/account/privacy/export` (#11164) — get every baseline
25
26
  // header but the CSP. Their handlers set the hub's sandbox policy, and this
26
27
  // middleware runs before them: Next puts its headers on the response first and
27
28
  // adds a handler header only where none is set yet, so a site CSP stamped here
@@ -120,6 +121,7 @@ const FILE_ROUTE_PATHS = [
120
121
  /^\/reports\/[^/]+\/file$/,
121
122
  /^\/account\/inbox\/message\/[^/]+\/file$/,
122
123
  /^\/account\/artifacts\/[^/]+\/versions\/[^/]+\/file$/,
124
+ /^\/account\/privacy\/export$/,
123
125
  ];
124
126
 
125
127
  const LOCALE_PREFIX = new RegExp(`^/(${enabledLocales.join("|")})(?=/)`);
@@ -59,3 +59,16 @@ export function pagePathFor(page: {
59
59
  }): string {
60
60
  return pagePath(page, SERVICES_PATH);
61
61
  }
62
+
63
+ /** The agent-contact block llms.txt ends with on a site that serves /contact (#11423). */
64
+ export function agentContactLines(baseUrl: string, siteName: string): string[] {
65
+ return [
66
+ "## For agents",
67
+ "",
68
+ `- Contact page: ${baseUrl}/contact`,
69
+ ` To reach ${siteName} for a person, send their message through this page's form. Send one message per person, not one per attempt.`,
70
+ `- MCP manifest: ${baseUrl}/.well-known/mcp.json`,
71
+ ` Where it names an mcpEndpoint, that server's capture_lead tool sends the message without the form: give the person's email, put their name and message in payload, and send source "mcp".`,
72
+ "",
73
+ ];
74
+ }
@@ -27,11 +27,16 @@
27
27
  import { existsSync, readFileSync, readdirSync, writeFileSync } from "node:fs";
28
28
  import { join } from "node:path";
29
29
 
30
- /** Names the platform sets, which need no row (D4). Fixed: a site cannot extend it. */
30
+ /**
31
+ * Names the platform sets, which need no row (D4). Fixed: a site cannot extend it.
32
+ * `__NEXT_RELATIVE_DIST_DIR` is Next's own: it sets it for the build it runs, and
33
+ * `apps/web/lib/served-pages.ts` reads it to find the build's routes manifest.
34
+ */
31
35
  export const PLATFORM_ENV_NAMES: readonly string[] = [
32
36
  "NODE_ENV",
33
37
  "NEXT_RUNTIME",
34
38
  "NEXT_PHASE",
39
+ "__NEXT_RELATIVE_DIST_DIR",
35
40
  "CI",
36
41
  "PORT",
37
42
  "VERCEL",
package/versions.json CHANGED
@@ -1,69 +1,69 @@
1
1
  {
2
- "@working-theory/account": "0.65.0",
3
- "@working-theory/admin-ui": "0.65.0",
4
- "@working-theory/aeo": "0.65.0",
5
- "@working-theory/agent-context": "0.65.0",
2
+ "@working-theory/account": "0.66.0",
3
+ "@working-theory/admin-ui": "0.66.0",
4
+ "@working-theory/aeo": "0.66.0",
5
+ "@working-theory/agent-context": "0.66.0",
6
6
  "@working-theory/agent-contract": "0.1.0",
7
7
  "@working-theory/agent-memory": "0.0.0",
8
8
  "@working-theory/ai": "0.1.0",
9
- "@working-theory/analytics": "0.65.0",
10
- "@working-theory/api": "0.65.0",
11
- "@working-theory/api-client": "0.65.0",
12
- "@working-theory/auth": "0.65.0",
9
+ "@working-theory/analytics": "0.66.0",
10
+ "@working-theory/api": "0.66.0",
11
+ "@working-theory/api-client": "0.66.0",
12
+ "@working-theory/auth": "0.66.0",
13
13
  "@working-theory/cda-filesystem": "0.0.0",
14
- "@working-theory/cli": "0.65.0",
15
- "@working-theory/common": "0.65.0",
14
+ "@working-theory/cli": "0.66.0",
15
+ "@working-theory/common": "0.66.0",
16
16
  "@working-theory/consent": "0.1.0",
17
- "@working-theory/content-adapters": "0.65.0",
18
- "@working-theory/content-projection": "0.65.0",
19
- "@working-theory/email": "0.65.0",
17
+ "@working-theory/content-adapters": "0.66.0",
18
+ "@working-theory/content-projection": "0.66.0",
19
+ "@working-theory/email": "0.66.0",
20
20
  "@working-theory/env": "0.0.0",
21
- "@working-theory/eslint-config": "0.65.0",
22
- "@working-theory/fumadocs-schema": "0.65.0",
23
- "@working-theory/ids": "0.20.1",
24
- "@working-theory/jsonld": "0.65.0",
25
- "@working-theory/license": "0.65.0",
26
- "@working-theory/mcp-server": "0.65.0",
27
- "@working-theory/metadata": "0.65.0",
28
- "@working-theory/observability": "0.65.0",
29
- "@working-theory/page-renderer": "0.65.0",
21
+ "@working-theory/eslint-config": "0.66.0",
22
+ "@working-theory/fumadocs-schema": "0.66.0",
23
+ "@working-theory/ids": "0.21.0",
24
+ "@working-theory/jsonld": "0.66.0",
25
+ "@working-theory/license": "0.66.0",
26
+ "@working-theory/mcp-server": "0.66.0",
27
+ "@working-theory/metadata": "0.66.0",
28
+ "@working-theory/observability": "0.66.0",
29
+ "@working-theory/page-renderer": "0.66.0",
30
30
  "@working-theory/plugin-mcp": "0.1.3",
31
- "@working-theory/schema": "0.65.0",
32
- "@working-theory/schema-pack-registry": "0.65.0",
33
- "@working-theory/schema-validator": "0.65.0",
34
- "@working-theory/sections-registry": "0.65.0",
35
- "@working-theory/site-config": "0.65.0",
36
- "@working-theory/site-pages": "0.65.0",
37
- "@working-theory/spoke-checkout": "0.7.21",
38
- "@working-theory/stripe-client": "0.65.0",
39
- "@working-theory/templates": "0.65.0",
40
- "@working-theory/theme": "0.65.0",
41
- "@working-theory/ui": "0.65.0",
42
- "@working-theory/validation": "0.65.0",
43
- "@working-theory/web-i18n": "0.65.0",
44
- "@working-theory/admin": "0.17.0",
45
- "@working-theory/api-commerce": "0.1.19",
46
- "@working-theory/api-content-write": "0.10.3",
47
- "@working-theory/api-hub": "0.6.4",
48
- "@working-theory/api-multi-tenant": "0.3.5",
49
- "@working-theory/api-scheduling": "0.6.4",
50
- "@working-theory/api-signal-collectors": "0.6.5",
51
- "@working-theory/api-workspace": "0.11.0",
31
+ "@working-theory/schema": "0.66.0",
32
+ "@working-theory/schema-pack-registry": "0.66.0",
33
+ "@working-theory/schema-validator": "0.66.0",
34
+ "@working-theory/sections-registry": "0.66.0",
35
+ "@working-theory/site-config": "0.66.0",
36
+ "@working-theory/site-pages": "0.66.0",
37
+ "@working-theory/spoke-checkout": "0.7.22",
38
+ "@working-theory/stripe-client": "0.66.0",
39
+ "@working-theory/templates": "0.66.0",
40
+ "@working-theory/theme": "0.66.0",
41
+ "@working-theory/ui": "0.66.0",
42
+ "@working-theory/validation": "0.66.0",
43
+ "@working-theory/web-i18n": "0.66.0",
44
+ "@working-theory/admin": "0.18.0",
45
+ "@working-theory/api-commerce": "0.2.0",
46
+ "@working-theory/api-content-write": "0.11.0",
47
+ "@working-theory/api-hub": "0.7.0",
48
+ "@working-theory/api-multi-tenant": "0.4.0",
49
+ "@working-theory/api-scheduling": "0.6.5",
50
+ "@working-theory/api-signal-collectors": "0.6.6",
51
+ "@working-theory/api-workspace": "0.12.0",
52
52
  "@working-theory/billing-client": "0.0.0",
53
53
  "@working-theory/branding": "0.0.0",
54
54
  "@working-theory/license-client": "0.0.0",
55
55
  "@working-theory/license-manifest": "0.0.0",
56
- "@working-theory/mcp-scheduling": "0.4.6",
57
- "@working-theory/mcp-signal-collectors": "0.2.19",
58
- "@working-theory/mcp-workspace": "0.9.3",
56
+ "@working-theory/mcp-scheduling": "0.4.7",
57
+ "@working-theory/mcp-signal-collectors": "0.2.20",
58
+ "@working-theory/mcp-workspace": "0.10.0",
59
59
  "@working-theory/partner-session": "0.0.0",
60
60
  "@working-theory/preview-protocol": "0.0.0",
61
- "@working-theory/ui-commerce": "0.65.0",
62
- "@working-theory/ui-docs-blog": "0.65.0",
63
- "@working-theory/ui-scheduling": "0.65.0",
64
- "@working-theory/ui-signal-collectors": "0.65.0",
61
+ "@working-theory/ui-commerce": "0.66.0",
62
+ "@working-theory/ui-docs-blog": "0.66.0",
63
+ "@working-theory/ui-scheduling": "0.66.0",
64
+ "@working-theory/ui-signal-collectors": "0.66.0",
65
65
  "@working-theory/web": "0.0.0",
66
66
  "@working-theory/app-api": "1.0.0",
67
67
  "@working-theory/mcp": "0.0.0",
68
- "@working-theory/database": "0.65.0"
68
+ "@working-theory/database": "0.66.0"
69
69
  }