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
|
@@ -214,15 +214,23 @@ authorize step. **The purchase link:** after a paid Offerings session the hub
|
|
|
214
214
|
mails "Open your account" to `<spoke>/account?claim=<claim>`; that page's GET
|
|
215
215
|
changes nothing, and its one "Open my account" button POSTs the claim to
|
|
216
216
|
`/api/hub-session/open`, which spends it at the hub web's
|
|
217
|
-
`POST /api/auth/hub/purchase
|
|
218
|
-
|
|
217
|
+
`POST /api/auth/hub/purchase`. That route runs the magic-link verify
|
|
218
|
+
in-process (the account and its `sign_up` grant are created as for a
|
|
219
|
+
browser verify), uses the session only to mint this spoke's PKCE-bound code,
|
|
220
|
+
deletes the session and answers `{ code }`, so the spoke's server never holds
|
|
221
|
+
a hub session (#11109); the spoke 303s to its own callback with it (`409
|
|
222
|
+
account_exists` or `consent_required` → `?error=exists`, anything else →
|
|
223
|
+
`?error=claim`). `/account/billing` lists the
|
|
219
224
|
member's purchases (`member.purchases`, the verified-email join) on such a
|
|
220
225
|
spoke only. **One Tap** (off by default): `AILK_HUB_ONE_TAP=on` on the spoke
|
|
221
226
|
and `AILK_GOOGLE_ONE_TAP_CLIENT_ID` on the hub API render the `OneTap`
|
|
222
227
|
island, which takes a nonce from `/api/hub-session/one-tap/nonce` (a 300 s
|
|
223
228
|
sealed cookie) and posts Google's credential to `/api/hub-session/one-tap`;
|
|
224
229
|
the hub verifies it and the route seals the session (`sessionCookieFor`) before
|
|
225
|
-
the page moves.
|
|
230
|
+
the page moves. Because that token reaches the spoke's server, the hub's own
|
|
231
|
+
Better Auth Google provider (here and in the Admin) sets
|
|
232
|
+
`disableIdTokenSignIn: true`: `POST /api/auth/sign-in/social` never accepts a
|
|
233
|
+
raw ID token, whatever its audience (#11109). `middleware.ts` adds Google's One Tap origins
|
|
226
234
|
(`ONE_TAP_CSP`) to every page's CSP only while that setting is on. Every new
|
|
227
235
|
spoke route is same-origin only, and every body is `.strict()`: a password is
|
|
228
236
|
never accepted. `claim` is in both telemetry scrub lists.
|
|
@@ -257,11 +265,12 @@ spoke removal seed, so no spoke carries the hub route.
|
|
|
257
265
|
**The site is the OAuth 2.1 authorization server an MCP client signs in through (#10357).** `auth.ts`'s block between `// mcp-oauth:begin` and `// mcp-oauth:end` installs better-auth's `mcp` plugin (dynamic client registration, S256 PKCE, one-hour access tokens, seven-day refresh tokens) and AILK's `lib/mcp-oauth.ts` beside it, only when `BETTER_AUTH_URL` pins the issuer. The plugin is configured, never patched: every AILK behaviour is a hook or an endpoint in that file.
|
|
258
266
|
|
|
259
267
|
- **Tokens are opaque, validated by lookup** (decision (a)): no JWKS and no `jwt` plugin. `GET /api/auth/mcp/token-info` is the self-check: the bound workspace, the member-clamped `actingRole` and the grants the person's live role still holds — never a token.
|
|
260
|
-
- **Every authorization asks** (decision (b)): a before-hook forces `prompt=consent`, so the plugin always redirects to `/consent` (an `(auth)` page, `AUTH_SEGMENTS`). The page reads only `consent_code` and asks `GET /mcp/consent-details`; Allow posts `POST /mcp/consent`, which binds one `ailk:workspace:<id>` and only role-held `ailk:*` scopes. `/mcp/token` refuses any code that did not pass it or whose approving session has ended, any `code` not shaped like one (so no AILK verification row can be named and consumed), and any non-string body field. The plugin's own `/oauth2/consent`, `/mcp/get-session` and discovery copy are `disabledPaths`; the site serves `/.well-known/oauth-authorization-server` at its root.
|
|
261
|
-
- **Rotation and revocation**: a refresh deletes the used pair and leaves a tombstone, so a replayed refresh token ends the person's line for that client. `POST /mcp/revoke` (RFC 7009) and the person's own `POST /mcp/revoke-client` delete tokens.
|
|
262
|
-
- **A password reset or change deletes every MCP token** of the person: `onPasswordReset`'s guarded blocks, which end the person's sessions first (so none can mint a token in between) and then their tokens (`reason: "session_revocation_failed"` / `"mcp_token_revocation_failed"` on failure, never a rejection) and an after-hook
|
|
268
|
+
- **Every authorization asks** (decision (b)): a before-hook forces `prompt=consent`, so the plugin always redirects to `/consent` (an `(auth)` page, `AUTH_SEGMENTS`) — the plugin never reads the `oauthConsent` row, so a client an admin revoked asks the person again (#10459 D2). The page reads only `consent_code` and asks `GET /mcp/consent-details`; Allow posts `POST /mcp/consent`, which binds one `ailk:workspace:<id>` and only role-held `ailk:*` scopes. `/mcp/token` refuses any code that did not pass it or whose approving session has ended, any `code` not shaped like one (so no AILK verification row can be named and consumed), and any non-string body field. The plugin's own `/oauth2/consent`, `/mcp/get-session` and discovery copy are `disabledPaths`; the site serves `/.well-known/oauth-authorization-server` at its root.
|
|
269
|
+
- **Rotation and revocation**: a refresh deletes the used pair and leaves a tombstone, so a replayed refresh token ends the person's line for that client. A refresh whose used row is already gone when AILK's after-hook reads it — deleted by a revoke, a password change or a second refresh of the same token after the plugin read it — answers `invalid_grant` and its new pair is deleted (#10459 D1). `POST /mcp/revoke` (RFC 7009) and the person's own `POST /mcp/revoke-client` delete tokens.
|
|
270
|
+
- **A password reset or change deletes every MCP token** of the person: `onPasswordReset`'s guarded blocks, which end the person's sessions first (so none can mint a token in between) and then their tokens (`reason: "session_revocation_failed"` / `"mcp_token_revocation_failed"` on failure, never a rejection) and on `/change-password` a before-hook that forces `revokeOtherSessions: true` (the caller gets a new session, every other device is signed out, #10459 D5) and an after-hook that then deletes the tokens.
|
|
263
271
|
- **One issuer per token (#10912)**: the plugin takes an optional `issuerTag` and `signInLocation`; this site passes neither, so its tokens carry no `ailk:issuer:` entry and its code exchange, refresh and token-info refuse any token or code that carries one. On a hub the Admin runs a byte-identical copy (`packages-paid/admin/lib/mcp-oauth.ts`, a parity test holds it equal) with `issuerTag: "admin"`, so an edit here is an edit there.
|
|
264
|
-
-
|
|
272
|
+
- **Registration** is limited to 10 per hour with or without `AILK_AUTH_TRUSTED_PROXIES` — without it a site-wide bucket, the one rule outside the trusted-proxy guard (#10459 D3).
|
|
273
|
+
- Two plugin facts AILK works around: `/mcp/register` answers a raw `Response`, so no after-hook runs on it (the cleanup sweep runs after an accepted `POST /mcp/consent`, in the background, never on the anonymous register — #10459 D4), and the plugin's `/mcp/token` treats any `oauthApplication.type` but `public` as confidential, so `POST /mcp/consent` re-derives it from the stored secret (`public` for a client with no secret, the column defaulting to `web`).
|
|
265
274
|
|
|
266
275
|
## Contact page
|
|
267
276
|
|
|
@@ -305,7 +314,8 @@ declares any, else the built-in form, which is the seeded config itself. Any
|
|
|
305
314
|
failed read (absent, draft, a Free build with no flow route, a throw) is the
|
|
306
315
|
fallback, never an error. A magnet-driven post carries a hidden
|
|
307
316
|
`source: "flow:contact"`, so it is an Inbox submission of the Contact form
|
|
308
|
-
with every answer shown
|
|
317
|
+
with every answer shown — and, with its Person, a thread in Messages
|
|
318
|
+
(#10943); a fallback post is `contact-form` (#8747). The terms statement
|
|
309
319
|
links Terms, Privacy Policy and Working Agreement from a page-built
|
|
310
320
|
`policies` map, and `captureLeadAction` refuses a post without
|
|
311
321
|
`consent=true` whatever its source (#8730 D2 — the hidden `source` picks the
|
|
@@ -709,10 +719,10 @@ What a site that carries `commerce` gets (#8748, #11253); a site without
|
|
|
709
719
|
|
|
710
720
|
A visitor's browser never calls the hub. Lead capture, newsletter signup, callback, scheduling and the commerce invoice call post to this site's own `/v1/...` address, and `app/v1/[...path]/route.ts` hands each request to `lib/relay.ts` (`handleRelay`), which forwards it server-side through `@working-theory/api-client`'s `relayToApi` with the site's own `AILK_SPOKE_KEY` when it has one (#7644). The browser never holds the key, so a hub can refuse unknown callers (#7633) without taking a site's forms down.
|
|
711
721
|
|
|
712
|
-
- **Only the list.** `RELAY_ROUTES` is the fixed set of (method, path) pairs: `POST /v1/leads/{submit,subscribe,callback}`, `GET /v1/schedule/availability`, `POST /v1/schedule/book`, `POST /v1/commerce/invoices
|
|
722
|
+
- **Only the list.** `RELAY_ROUTES` is the fixed set of (method, path) pairs: `POST /v1/leads/{submit,subscribe,callback}`, `GET /v1/schedule/availability`, `POST /v1/schedule/book`, and on a hub only `POST /v1/commerce/invoices` (a spoke answers it 404 with no hub call, #8066). Anything else is a 404 with no hub call. Adding a route is a reviewed change to that list, its test and `.env.example`.
|
|
713
723
|
- **No cross-site POST.** A `Sec-Fetch-Site` other than `same-origin`, or an `Origin` not on this site's own host, is refused 403 before the hub is called.
|
|
714
|
-
- **Headers are an allow-list.** The visitor's `x-forwarded-for` (else `x-real-ip`) and `user-agent` pass through so per-visitor rate limits still count each visitor; no `authorization`, client-sent `x-ailk-*` or `host` is forwarded, and a `cookie` goes only on `POST /v1/commerce/invoices`, the one session route.
|
|
715
|
-
- **The relay has its own per-visitor budget (#7707).** Each visitor gets 8 calls per 10 minutes across the five visitor routes, and the session route (`POST /v1/commerce/invoices
|
|
724
|
+
- **Headers are an allow-list.** The visitor's `x-forwarded-for` (else `x-real-ip`) and `user-agent` pass through so per-visitor rate limits still count each visitor; no `authorization`, client-sent `x-ailk-*` or `host` is forwarded, and a `cookie` goes only on `POST /v1/commerce/invoices`, the one session route — and there only one of the two Better Auth session cookies the hub reads (`__Secure-better-auth.session_token` first, else `better-auth.session_token`), never a spoke's sealed `__Host-ailk-hub-session` or any other cookie (#8066).
|
|
725
|
+
- **The relay has its own per-visitor budget (#7707).** Each visitor gets 8 calls per 10 minutes across the five visitor routes, and the session route (`POST /v1/commerce/invoices`, a hub only) gets its own, wider budget of 30 per 10 minutes; the call that exceeds either gets `429 rate_limited` before any hub call. The budget is held in this instance's own process (no shared store, no env variable) and holds only where the site's edge overwrites `x-forwarded-for` and `x-real-ip` — Vercel does; a bare self-hosted Next server does not.
|
|
716
726
|
- **A bot check on the public writes (#9889, #9255).** On Vercel, `lib/bot-check.ts`'s `runBotCheck` asks Vercel BotID for a verdict before the hub is called — in the relay for `POST /v1/leads/{submit,subscribe,callback}` and `POST /v1/schedule/book` (`BOT_CHECKED_ROUTES`: `403 bot_detected`, or `503 bot_check_unavailable` when the check throws, answers no boolean or takes over 5 seconds), and in the contact, careers, newsletter, flow-step, flow-checkout, saved-recommendation and `/dev/purchase` Server Actions immediately before their hub call, which answer their own existing failure variant. The locale layout's `BotIdClient` protects every same-origin POST (`BOT_CLIENT_PROTECT`, `/*`), because a Server Action posts to the page it was submitted from; `next.config.mjs` wraps `withBotId` and `middleware.ts` keeps BotID's proxy prefix out of its matcher. It is on by default and inert off Vercel: `AILK_BOT_CHECK=off` turns every check off, `AILK_BOOKING_BOT_CHECK=off` the booking's alone, and MCP tools never pass through a site, so they are never challenged. A refusal logs `[<source>] bot refused` with BotID's `classificationReason`, `bypassed` and `isVerifiedBot`, the request's `host` and `forwardedHost`, and `proxied` (a `cf-ray` header) — no other header value, no form field (#10715). `AILK_BOT_CHECK=observe` runs the check and logs the same facts plus `isBot` as `observed`, but passes every write — for diagnosis only. **A BotID-protected site must be reached directly — Cloudflare DNS-only, no reverse proxy in front of Vercel (#10715).** Behind a proxy the write reaches Vercel from the proxy's egress rather than the browser that solved the challenge, so BotID refuses every real visitor; the first proxied request per process logs `[<source>] reverse proxy detected` (outcome `proxied`) naming that fix.
|
|
717
727
|
- `/v1` is exempt from next-intl's locale rewrite in `middleware.ts`, as `/api` is.
|
|
718
728
|
|
|
@@ -753,7 +763,16 @@ A list page whose frontmatter sets `navOnly: true` (valid on a registry list typ
|
|
|
753
763
|
- **The seven handlers.** `robots.txt`, `sitemap.xml`, `llms.txt` (both copies — the docs + blog module's `lib/slices/docs-blog/llms-route.ts` too), `.well-known/mcp.json`, `.well-known/ai-plugin.json` and `openapi.json` are `force-dynamic` and read it once per request, after the checks each already makes and before any other work. `createSitemapHandler` and `createLlmsHandler` take a `discoverable` dep (default `siteDiscoverable`); every test caller passes one, so no suite reads a hub.
|
|
754
764
|
- **On** is today, byte for byte. **Off**: robots.txt answers STEALTH's `User-agent: *` / `Disallow: /` with no Sitemap line; the other five answer 404 with no body (mcp.json keeps its CORS headers; its `OPTIONS` is unchanged). Every off answer is `cache-control: no-store`, so a crawler asks again.
|
|
755
765
|
- **Hidden wins.** With `STEALTH` on, or no public page (`PUBLIC_PAGES` false), robots.txt answers as before and makes no read; sitemap.xml and llms.txt 404 before it.
|
|
756
|
-
- **Pages are never hidden.** No page, layout or `middleware.ts` reads the switch, and
|
|
766
|
+
- **Pages are never hidden.** No page, layout or `middleware.ts` reads the switch, and only `STEALTH` sets `X-Robots-Tag`: off is a preference about discovery, not access control. `<meta robots>` has two writers: `STEALTH` (`noindex, nofollow`, which always wins), and on a hub-connected site the workspace's Allow search indexing (`seo.robots.index: false` → the layout's `noindex, follow`, § A hub-connected site's identity). `STEALTH` remains the hard, deploy-time hide.
|
|
767
|
+
|
|
768
|
+
## A hub-connected site's identity
|
|
769
|
+
|
|
770
|
+
**A site connected to its hub reads its name, description, legal name, contact, sameAs and indexing switch from the hub (#11456).** Hub-connected means a spoke key on the wire (`sendsSpokeKey()`), whatever the content adapter — a site serving file content with a key reads the hub too (#11515); `lib/hub-site-config.ts`'s `readHubSite()` then reads `GET /v1/content/site-config` through `siteConfig.get()` — the key's own workspace's identity and seo rows, 401 to any other caller — cached by `unstable_cache` under `siteConfigTag()` for at most 300 s. A site with no spoke key makes no call and renders from `_site.mdx` exactly as before.
|
|
771
|
+
|
|
772
|
+
- **Who reads it.** `resolveSiteBrand()` (`lib/site-brand.tsx`) gives the locale layout's title, description, og/twitter copy, Nav/Footer `siteName` and copyright holder, and both llms.txt headings; `lib/site-identity.ts` registers a JSON-LD reader (`setSiteIdentityReader`) whose registration keeps the file's `baseUrl`, so no hub value moves an `@id`; the contact email and the closing footer's contact lines read the value the last read resolved (`heldHubSite()`), because their seam is synchronous. `SITE_NAME`'s other readers (og image, icons, auth, mcp.json, ai-plugin.json) keep the file value.
|
|
773
|
+
- **A hub row is the whole identity.** A field the operator cleared is absent, never refilled from the file; only a missing row, an unreadable one or a failed read falls back to `_site.mdx`. The file's top-level `contactEmail` stays the contact email's fallback. Hub values are collapsed to one line.
|
|
774
|
+
- **A save shows without a redeploy.** A 200 PUT of `identity` or `seo` sends the signed `site-config` revalidate event (`notifySiteConfigRevalidate`) to the site and its spokes; `app/api/revalidate/route.ts` answers it by purging `siteConfigTag()`. The 300 s expiry is the net for a spoke with no `revalidateUrl`.
|
|
775
|
+
- **A hub outage never breaks a page**: a failed read writes no cache entry and serves the instance's last good value, else the file. The indexing switch fails open.
|
|
757
776
|
|
|
758
777
|
## AEO & performance
|
|
759
778
|
|
|
@@ -771,7 +790,15 @@ A list page whose frontmatter sets `navOnly: true` (valid on a registry list typ
|
|
|
771
790
|
- Don't reach into `apps/api` or `apps/mcp` from `apps/web`. They're peer apps — talk via HTTP/MCP.
|
|
772
791
|
- Don't commit images to `screenshots/` — only the `.gitkeep` is tracked.
|
|
773
792
|
|
|
774
|
-
Last updated: 2026-11-
|
|
793
|
+
Last updated: 2026-11-12 — § The `(auth)` route group: the purchase spend answers this spoke's code, never the hub's verify URL, and the hub's Google provider refuses a raw ID token (#11109) — verified against `packages/auth/src/api/{auth/hub/purchase,hub-session/open}/route.ts` and `auth.ts`.
|
|
794
|
+
|
|
795
|
+
Prior: 2026-11-12 — § The MCP authorization server: a refresh racing a revoke is refused, the forced prompt is what makes a revoked client ask again, `/change-password` signs other devices out, the register limit applies without a trusted proxy, and the sweep runs after an accepted consent (#10459) — verified against `lib/mcp-oauth.ts` and `auth.ts`.
|
|
796
|
+
|
|
797
|
+
Prior: 2026-11-12 — § A hub-connected site's identity: hub-connected is a spoke key on the wire, whatever the content adapter (#11515) — verified against `lib/hub-site-config.ts`.
|
|
798
|
+
|
|
799
|
+
Prior: 2026-11-11 — § A hub-connected site's identity: the hub read, the brand, JSON-LD reader and contact readers that take it, the `site-config` revalidate event, and `<meta robots>`'s second writer (#11456) — verified against `lib/{hub-site-config.ts,site-brand.tsx,site-identity.ts,site-contact-email.ts,site-contact-lines.ts}`, `app/[locale]/layout.tsx`, `app/llms.txt/route.ts` and `app/api/revalidate/route.ts`.
|
|
800
|
+
|
|
801
|
+
Prior: 2026-11-11 — § Where the base pages live: the 63 base pages, their actions, loaders and libs ship in `@working-theory/site-pages`, this app holds their generated route files and `site-pages.config.tsx`, and the ten namespaces ship in the package (#11259) — verified against `packages/site-pages/{routes.json,src/site.ts,src/index.ts}`, `site-pages.config.tsx` and `i18n/request.ts`.
|
|
775
802
|
|
|
776
803
|
Prior: 2026-11-10 — § The `(auth)` route group: sign-in, the hub session and the auth routes ship in `@working-theory/auth`, this app holds their 25 generated route files and `auth.config.tsx`, Better Auth reaches the package through `loadAuth()`, and the middleware's auth half is the package's edge entry (#11257) — verified against `packages/auth/{routes.json,src/site.ts,src/edge.ts}`, `auth.config.tsx`, `middleware.ts`, `lib/topology.generated.ts` and `i18n/request.ts`.
|
|
777
804
|
|
|
@@ -40,7 +40,7 @@ jest.mock("next-intl/server", () => {
|
|
|
40
40
|
jest.mock("next/headers", () => ({
|
|
41
41
|
__esModule: true,
|
|
42
42
|
headers: jest.fn().mockResolvedValue(new Headers()),
|
|
43
|
-
cookies: jest.fn().mockResolvedValue({ toString: () => "
|
|
43
|
+
cookies: jest.fn().mockResolvedValue({ toString: () => "better-auth.session_token=abc" }),
|
|
44
44
|
}));
|
|
45
45
|
|
|
46
46
|
const mockSecret = "k".repeat(43);
|
|
@@ -99,6 +99,7 @@ import {
|
|
|
99
99
|
routeFamilyOf,
|
|
100
100
|
} from "../../lib/page-chrome";
|
|
101
101
|
import {
|
|
102
|
+
ancestorPaths,
|
|
102
103
|
backLinkName,
|
|
103
104
|
navLabelsByPath,
|
|
104
105
|
parentHref,
|
|
@@ -109,12 +110,7 @@ import {
|
|
|
109
110
|
withPublicServicesColumns,
|
|
110
111
|
withPublicServicesPaths,
|
|
111
112
|
} from "../../lib/services-path";
|
|
112
|
-
import {
|
|
113
|
-
COPYRIGHT_HOLDER,
|
|
114
|
-
SITE_DESCRIPTION,
|
|
115
|
-
SITE_NAME,
|
|
116
|
-
resolveContentRoot,
|
|
117
|
-
} from "../../lib/site-brand";
|
|
113
|
+
import { resolveContentRoot, resolveSiteBrand } from "../../lib/site-brand";
|
|
118
114
|
import { siteChrome, type SiteChrome } from "../../lib/site-chrome";
|
|
119
115
|
import {
|
|
120
116
|
ACCOUNT_LABEL_KEY,
|
|
@@ -141,6 +137,7 @@ import {
|
|
|
141
137
|
import { pagePathFor, resolveBaseUrl } from "../../src/lib/routes";
|
|
142
138
|
|
|
143
139
|
import { ConsentBanner } from "./consent-banner";
|
|
140
|
+
|
|
144
141
|
import { readSiteContactLines } from "../../lib/site-contact-lines";
|
|
145
142
|
|
|
146
143
|
/**
|
|
@@ -279,6 +276,8 @@ const FLASH_PREVENTION_SCRIPT = `(function(){
|
|
|
279
276
|
// ── Metadata ─────────────────────────────────────────────────────────────────
|
|
280
277
|
|
|
281
278
|
export async function generateMetadata(): Promise<Metadata> {
|
|
279
|
+
// #11456 D4 — the hub's brand on a hub-connected site, else `_site.mdx`'s.
|
|
280
|
+
const brand = await resolveSiteBrand();
|
|
282
281
|
const headerStore = await headers();
|
|
283
282
|
const pathname = headerStore.get("x-pathname") ?? "/";
|
|
284
283
|
|
|
@@ -286,7 +285,7 @@ export async function generateMetadata(): Promise<Metadata> {
|
|
|
286
285
|
const baseUrl = resolveBaseUrl();
|
|
287
286
|
// #11244 — absolute: no layout sets `metadataBase`, so a relative og:image
|
|
288
287
|
// reached crawlers as a path they could not fetch.
|
|
289
|
-
const ogImageUrl = `${baseUrl.replace(/\/+$/, "")}${getOgImageUrl({ title:
|
|
288
|
+
const ogImageUrl = `${baseUrl.replace(/\/+$/, "")}${getOgImageUrl({ title: brand.siteName, schemaType: "WebSite" })}`;
|
|
290
289
|
const languages = buildHreflangAlternates(
|
|
291
290
|
pathname,
|
|
292
291
|
locales,
|
|
@@ -297,23 +296,31 @@ export async function generateMetadata(): Promise<Metadata> {
|
|
|
297
296
|
// none of its own: the request's own URL, never the home page's.
|
|
298
297
|
const requestUrl = pathname === "/" ? baseUrl : `${baseUrl}${pathname}`;
|
|
299
298
|
|
|
299
|
+
// #11456 D6 — `STEALTH` wins; otherwise the hub's Allow search indexing
|
|
300
|
+
// off answers `noindex, follow` on every page that sets no robots of its own.
|
|
301
|
+
const stealthRobots = getStealthRobots();
|
|
302
|
+
|
|
300
303
|
return {
|
|
301
|
-
title:
|
|
302
|
-
description:
|
|
304
|
+
title: brand.siteName,
|
|
305
|
+
description: brand.description,
|
|
303
306
|
openGraph: {
|
|
304
|
-
title:
|
|
305
|
-
description:
|
|
307
|
+
title: brand.siteName,
|
|
308
|
+
description: brand.description,
|
|
306
309
|
type: "website",
|
|
307
310
|
url: requestUrl,
|
|
308
311
|
images: [ogImageUrl],
|
|
309
312
|
},
|
|
310
313
|
twitter: {
|
|
311
314
|
card: "summary_large_image",
|
|
312
|
-
title:
|
|
313
|
-
description:
|
|
315
|
+
title: brand.siteName,
|
|
316
|
+
description: brand.description,
|
|
314
317
|
images: [ogImageUrl],
|
|
315
318
|
},
|
|
316
|
-
...
|
|
319
|
+
...("robots" in stealthRobots
|
|
320
|
+
? stealthRobots
|
|
321
|
+
: brand.indexable
|
|
322
|
+
? {}
|
|
323
|
+
: { robots: { index: false, follow: true } }),
|
|
317
324
|
alternates: {
|
|
318
325
|
canonical: requestUrl,
|
|
319
326
|
languages,
|
|
@@ -376,6 +383,9 @@ export default async function LocaleLayout({
|
|
|
376
383
|
if (moved !== null)
|
|
377
384
|
permanentRedirect(localeHref(locale, moved, DEFAULT_LOCALE));
|
|
378
385
|
const messages = await getMessages();
|
|
386
|
+
// #11456 D4 — awaited before `readSiteContactLines`, so the held hub value
|
|
387
|
+
// the contact lines read is this render's.
|
|
388
|
+
const brand = await resolveSiteBrand();
|
|
379
389
|
// #7742 D2 — `colorMode: "light"` pins the mode: a saved dark cookie is
|
|
380
390
|
// ignored, no flash script runs and no theme switch renders.
|
|
381
391
|
const pinLight = chrome.colorMode === "light";
|
|
@@ -584,7 +594,7 @@ export default async function LocaleLayout({
|
|
|
584
594
|
const brandWordmark = {
|
|
585
595
|
src: "/wordmark.svg",
|
|
586
596
|
darkSrc: "/wordmark-light.svg",
|
|
587
|
-
alt:
|
|
597
|
+
alt: brand.siteName,
|
|
588
598
|
width: 140,
|
|
589
599
|
height: 16,
|
|
590
600
|
};
|
|
@@ -676,7 +686,7 @@ export default async function LocaleLayout({
|
|
|
676
686
|
// snap an unpinned bar scrolls away with slide 1 (#5697). It keeps its
|
|
677
687
|
// own actions, mark and bar style — only `sticky` is added.
|
|
678
688
|
...(isDeckPage ? { sticky: true } : {}),
|
|
679
|
-
siteName:
|
|
689
|
+
siteName: brand.siteName,
|
|
680
690
|
frame: "contained",
|
|
681
691
|
navAlignment: "right",
|
|
682
692
|
showThemeToggle: false,
|
|
@@ -717,7 +727,7 @@ export default async function LocaleLayout({
|
|
|
717
727
|
}));
|
|
718
728
|
|
|
719
729
|
// The bare header's back arrow (operator handoff 2026-11-09): the page's
|
|
720
|
-
// served parent — a content page, a
|
|
730
|
+
// served parent — a content page, a page route the app builds or a nav entry —
|
|
721
731
|
// named in its label; home when no ancestor is served. Read only where
|
|
722
732
|
// the arrow renders. A slide-left arrival is rewritten client-side by
|
|
723
733
|
// NavBackLink (#8644).
|
|
@@ -725,7 +735,7 @@ export default async function LocaleLayout({
|
|
|
725
735
|
// name follows the href NavBackLink resolves to.
|
|
726
736
|
let bareBackLink: { href: string; label: string; returnLabel: string } | undefined;
|
|
727
737
|
if (!isHome && pageChrome.header === "bare") {
|
|
728
|
-
const titles = await servedPages(locale);
|
|
738
|
+
const titles = await servedPages(locale, ancestorPaths(pathname, enabledLocales));
|
|
729
739
|
const navPathLabels = navLabelsByPath([publicNavItems, footerColumnDefs], labelFor);
|
|
730
740
|
const served = (path: string): boolean => titles.has(path) || navPathLabels.has(path);
|
|
731
741
|
const parent = servedParent({ pathname, locales: enabledLocales, served });
|
|
@@ -734,15 +744,22 @@ export default async function LocaleLayout({
|
|
|
734
744
|
label:
|
|
735
745
|
parent === null
|
|
736
746
|
? tNav("home")
|
|
737
|
-
: tNav("backTo", {
|
|
747
|
+
: tNav("backTo", {
|
|
748
|
+
name: backLinkName(parent, {
|
|
749
|
+
navLabels: navPathLabels,
|
|
750
|
+
titles,
|
|
751
|
+
siteName: brand.siteName,
|
|
752
|
+
}),
|
|
753
|
+
}),
|
|
738
754
|
returnLabel: tNav("home"),
|
|
739
755
|
};
|
|
740
756
|
}
|
|
741
757
|
|
|
742
|
-
// The site's own name (#6942) —
|
|
743
|
-
// `siteName
|
|
744
|
-
//
|
|
745
|
-
|
|
758
|
+
// The site's own name (#6942) — the brand's name resolves from `_site.mdx`'s
|
|
759
|
+
// `siteName:` (or the hub's identity, #11456), so a customer's footer never
|
|
760
|
+
// carries the kit vendor's name. The holder is the identity's `legalName`
|
|
761
|
+
// when declared (#7796), else the name.
|
|
762
|
+
const copyrightText = `© ${new Date().getFullYear()} ${brand.copyrightHolder}. All rights reserved.`;
|
|
746
763
|
|
|
747
764
|
// Footer legal links (#5612 D3). The centered variant folds in FAQ — the
|
|
748
765
|
// roster's third always-scaffolded core route (`/faq`, alongside `/privacy`
|
|
@@ -974,7 +991,7 @@ export default async function LocaleLayout({
|
|
|
974
991
|
itemLabels={navLabels.items}
|
|
975
992
|
navItems={publicNavItems}
|
|
976
993
|
columns={footerColumnDefs}
|
|
977
|
-
siteName={
|
|
994
|
+
siteName={brand.siteName}
|
|
978
995
|
logo={brandLogo}
|
|
979
996
|
wordmark={brandWordmark}
|
|
980
997
|
social={[...socialLinks]}
|
|
@@ -50,7 +50,11 @@ import { createHmac } from "node:crypto";
|
|
|
50
50
|
import { readFileSync } from "node:fs";
|
|
51
51
|
import { join } from "node:path";
|
|
52
52
|
|
|
53
|
-
import {
|
|
53
|
+
import {
|
|
54
|
+
contentListTag,
|
|
55
|
+
contentPageTag,
|
|
56
|
+
siteConfigTag,
|
|
57
|
+
} from "@working-theory/page-renderer";
|
|
54
58
|
import { revalidateTag } from "next/cache";
|
|
55
59
|
import * as ts from "typescript";
|
|
56
60
|
|
|
@@ -538,6 +542,57 @@ describe("POST /api/revalidate", () => {
|
|
|
538
542
|
|
|
539
543
|
// --- #5902: replay window, signed event, bounded fields ------------------
|
|
540
544
|
|
|
545
|
+
describe("#11456 D5, AC-3 — the site-config event purges the hub-read tag", () => {
|
|
546
|
+
const SITE_CONFIG_BODY = { workspaceId: "wksp_fixture" };
|
|
547
|
+
|
|
548
|
+
it("a correctly signed site-config delivery purges siteConfigTag() with { expire: 0 } and no content tag", async () => {
|
|
549
|
+
const response = await POST(signedRequest(SITE_CONFIG_BODY, SECRET, "site-config"));
|
|
550
|
+
|
|
551
|
+
expect(response.status).toBe(200);
|
|
552
|
+
await expect(response.json()).resolves.toEqual({ revalidated: true });
|
|
553
|
+
expect(mockRevalidateTag).toHaveBeenCalledTimes(1);
|
|
554
|
+
expect(mockRevalidateTag).toHaveBeenCalledWith(siteConfigTag(), { expire: 0 });
|
|
555
|
+
expect(siteConfigTag()).toBe("site-config:default");
|
|
556
|
+
const info = (console.info as jest.Mock).mock.calls[0][0] as string;
|
|
557
|
+
expect(info).toContain('"event":"site-config"');
|
|
558
|
+
expect(info).toContain('"workspaceId":"wksp_fixture"');
|
|
559
|
+
});
|
|
560
|
+
|
|
561
|
+
it.each([
|
|
562
|
+
["a type key", { workspaceId: "wksp_fixture", type: "Service" }],
|
|
563
|
+
["the publish body", VALID_BODY],
|
|
564
|
+
["no workspaceId", {}],
|
|
565
|
+
["a non-string workspaceId", { workspaceId: 7 }],
|
|
566
|
+
["a workspaceId over 64 characters", { workspaceId: "w".repeat(65) }],
|
|
567
|
+
])("a correctly signed site-config body with %s is 400", async (_label, body) => {
|
|
568
|
+
const response = await POST(signedRequest(body, SECRET, "site-config"));
|
|
569
|
+
expect(response.status).toBe(400);
|
|
570
|
+
await expect(response.json()).resolves.toEqual({ error: "invalid_body" });
|
|
571
|
+
expect(mockRevalidateTag).not.toHaveBeenCalled();
|
|
572
|
+
});
|
|
573
|
+
|
|
574
|
+
it("a site-config delivery with a bad signature is 401", async () => {
|
|
575
|
+
const response = await POST(signedRequest(SITE_CONFIG_BODY, WRONG_SECRET, "site-config"));
|
|
576
|
+
expect(response.status).toBe(401);
|
|
577
|
+
expect(mockRevalidateTag).not.toHaveBeenCalled();
|
|
578
|
+
});
|
|
579
|
+
|
|
580
|
+
it("a site-config body signed as publish is not a site-config purge", async () => {
|
|
581
|
+
const rawBody = JSON.stringify(SITE_CONFIG_BODY);
|
|
582
|
+
const timestamp = String(nowSeconds());
|
|
583
|
+
const response = await POST(
|
|
584
|
+
makeRequest({
|
|
585
|
+
rawBody,
|
|
586
|
+
signature: sign(rawBody, SECRET, timestamp, "publish"),
|
|
587
|
+
event: "site-config",
|
|
588
|
+
timestamp,
|
|
589
|
+
}),
|
|
590
|
+
);
|
|
591
|
+
expect(response.status).toBe(401);
|
|
592
|
+
expect(mockRevalidateTag).not.toHaveBeenCalled();
|
|
593
|
+
});
|
|
594
|
+
});
|
|
595
|
+
|
|
541
596
|
describe("#5902 — the timestamp and event are signed, and the fields are bounded", () => {
|
|
542
597
|
it("accepts a timestamp just inside the 5-minute tolerance, either side", async () => {
|
|
543
598
|
for (const offset of [-(TOLERANCE_SECONDS - 5), TOLERANCE_SECONDS - 5]) {
|
|
@@ -11,9 +11,10 @@
|
|
|
11
11
|
* apps/api (ADR 0002, headless-first).
|
|
12
12
|
*
|
|
13
13
|
* The wire contract is #5851's as amended by #5902 (its spec's D1/D2): POST;
|
|
14
|
-
* body the four-key JSON { workspaceId, type, slug, locale }
|
|
14
|
+
* body the four-key JSON { workspaceId, type, slug, locale } (the one-key
|
|
15
|
+
* { workspaceId } for `site-config`, below); headers
|
|
15
16
|
* `x-ailk-revalidate-timestamp: <unix seconds>`,
|
|
16
|
-
* `x-ailk-revalidate-event: publish | unpublish` and
|
|
17
|
+
* `x-ailk-revalidate-event: publish | unpublish | site-config` and
|
|
17
18
|
* `x-ailk-revalidate-signature: sha256=<lowercase hex>` — HMAC-SHA256 over
|
|
18
19
|
* `v0:{timestamp}:{event}:{rawBody}`.
|
|
19
20
|
*
|
|
@@ -40,6 +41,15 @@
|
|
|
40
41
|
* can forge another page's tag. A page tag over Next's 256-character limit is
|
|
41
42
|
* a 400 too — the read path cannot cache under such a tag either.
|
|
42
43
|
*
|
|
44
|
+
* THE SITE-CONFIG EVENT (#11456, spec
|
|
45
|
+
* docs/specs/11456-a-hub-connected-site-reads-spec.md D5) — a third signed
|
|
46
|
+
* event, sent after the workspace's identity or seo is saved. Same headers
|
|
47
|
+
* and base string; the body is exactly `{ workspaceId }` (a string of at most
|
|
48
|
+
* 64 characters, no other key — else 400). It purges `siteConfigTag()`, the
|
|
49
|
+
* tag `lib/hub-site-config.ts` caches the hub read under, and no content tag.
|
|
50
|
+
* `workspaceId` is logged, never compared or tagged: the signing secret
|
|
51
|
+
* already names the site.
|
|
52
|
+
*
|
|
43
53
|
* PII / secret boundary (FR9): no log line carries the secret, the signature
|
|
44
54
|
* header value, the request body, or page content.
|
|
45
55
|
*/
|
|
@@ -49,7 +59,11 @@ import {
|
|
|
49
59
|
SCHEMA_ORG_TYPES,
|
|
50
60
|
SLUG_PATTERN,
|
|
51
61
|
} from "@working-theory/content-adapters";
|
|
52
|
-
import {
|
|
62
|
+
import {
|
|
63
|
+
contentListTag,
|
|
64
|
+
contentPageTag,
|
|
65
|
+
siteConfigTag,
|
|
66
|
+
} from "@working-theory/page-renderer";
|
|
53
67
|
import { localeSchema } from "@working-theory/validation";
|
|
54
68
|
import { revalidateTag } from "next/cache";
|
|
55
69
|
import { z } from "zod";
|
|
@@ -77,6 +91,11 @@ const bodySchema = z.object({
|
|
|
77
91
|
locale: localeSchema,
|
|
78
92
|
});
|
|
79
93
|
|
|
94
|
+
/** The `site-config` event's body (#11456 D5): its one key, bounded, nothing else. */
|
|
95
|
+
const siteConfigBodySchema = z
|
|
96
|
+
.object({ workspaceId: z.string().max(64) })
|
|
97
|
+
.strict();
|
|
98
|
+
|
|
80
99
|
/** next@16.3.3 `NEXT_CACHE_TAG_MAX_LENGTH` (dist/lib/constants.js). */
|
|
81
100
|
const CACHE_TAG_MAX_LENGTH = 256;
|
|
82
101
|
|
|
@@ -148,7 +167,11 @@ export async function POST(request: Request): Promise<Response> {
|
|
|
148
167
|
|
|
149
168
|
const rawEvent = request.headers.get(EVENT_HEADER);
|
|
150
169
|
const event =
|
|
151
|
-
rawEvent === "publish" ||
|
|
170
|
+
rawEvent === "publish" ||
|
|
171
|
+
rawEvent === "unpublish" ||
|
|
172
|
+
rawEvent === "site-config"
|
|
173
|
+
? rawEvent
|
|
174
|
+
: "unknown";
|
|
152
175
|
|
|
153
176
|
/**
|
|
154
177
|
* The one place a line is emitted (FR8), so the `[revalidate]` prefix, the
|
|
@@ -197,6 +220,24 @@ export async function POST(request: Request): Promise<Response> {
|
|
|
197
220
|
return Response.json({ error: "invalid_signature" }, { status: 401 });
|
|
198
221
|
}
|
|
199
222
|
|
|
223
|
+
if (event === "site-config") {
|
|
224
|
+
let parsed: unknown;
|
|
225
|
+
try {
|
|
226
|
+
parsed = JSON.parse(rawBody);
|
|
227
|
+
} catch {
|
|
228
|
+
parsed = undefined;
|
|
229
|
+
}
|
|
230
|
+
const siteConfig = siteConfigBodySchema.safeParse(parsed);
|
|
231
|
+
if (!siteConfig.success) {
|
|
232
|
+
log("warn", { status: 400 });
|
|
233
|
+
return Response.json({ error: "invalid_body" }, { status: 400 });
|
|
234
|
+
}
|
|
235
|
+
// The tag `lib/hub-site-config.ts` reads under — one builder, one process.
|
|
236
|
+
revalidateTag(siteConfigTag(), { expire: 0 });
|
|
237
|
+
log("info", { status: 200, workspaceId: siteConfig.data.workspaceId });
|
|
238
|
+
return Response.json({ revalidated: true }, { status: 200 });
|
|
239
|
+
}
|
|
240
|
+
|
|
200
241
|
const body = parseBody(rawBody);
|
|
201
242
|
if (body === null) {
|
|
202
243
|
log("warn", { status: 400 });
|
|
@@ -33,6 +33,17 @@ jest.mock("../../../lib/modules.generated", () => ({
|
|
|
33
33
|
// eslint-disable-next-line no-restricted-syntax -- #507: a per-site generated or site-owned file; this suite pins the value it tests (#11246)
|
|
34
34
|
jest.mock("../../../lib/site-listing", () => ({ __esModule: true, SITE_LISTING: {} }));
|
|
35
35
|
|
|
36
|
+
// #11456 — the hub read's HTTP call; the rest of the client stays real, so
|
|
37
|
+
// `sendsSpokeKey` reads the env. `next/cache` runs the read uncached.
|
|
38
|
+
const mockSiteConfigGet = jest.fn();
|
|
39
|
+
jest.mock("@working-theory/api-client", () => ({
|
|
40
|
+
...jest.requireActual("@working-theory/api-client"),
|
|
41
|
+
siteConfig: { get: (...args: unknown[]) => mockSiteConfigGet(...args) },
|
|
42
|
+
}));
|
|
43
|
+
jest.mock("next/cache", () => ({
|
|
44
|
+
unstable_cache: (fn: () => Promise<unknown>) => fn,
|
|
45
|
+
}));
|
|
46
|
+
|
|
36
47
|
type Route = typeof import("../route");
|
|
37
48
|
|
|
38
49
|
const BASE = "https://example.com";
|
|
@@ -130,3 +141,52 @@ describe.each(ROUTES)("GET /llms.txt (%s) — the site listing (#10940)", (path)
|
|
|
130
141
|
expect(text).not.toContain("/thanks/projects-approved");
|
|
131
142
|
});
|
|
132
143
|
});
|
|
144
|
+
|
|
145
|
+
describe("the llms.txt heading — a hub-connected site's name (#11456 D4, AC-2)", () => {
|
|
146
|
+
const KEY = "ailk_spk_TESTKEYxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
|
|
147
|
+
const identity = (name: string) => ({
|
|
148
|
+
ok: true,
|
|
149
|
+
body: { identity: { kind: "Organization", name, url: "https://elsewhere.example" }, seo: null },
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
// #11515 — hub-connected is a spoke key on the wire alone, so these cases
|
|
153
|
+
// run a file-content site (CONTENT_ADAPTER unset).
|
|
154
|
+
beforeEach(() => {
|
|
155
|
+
delete process.env.CONTENT_ADAPTER;
|
|
156
|
+
process.env.NEXT_PUBLIC_BASE_URL = BASE;
|
|
157
|
+
process.env.AILK_API_URL = "https://hub.example";
|
|
158
|
+
mockSiteConfigGet.mockReset();
|
|
159
|
+
});
|
|
160
|
+
afterEach(() => {
|
|
161
|
+
delete process.env.CONTENT_ADAPTER;
|
|
162
|
+
delete process.env.NEXT_PUBLIC_BASE_URL;
|
|
163
|
+
delete process.env.AILK_API_URL;
|
|
164
|
+
delete process.env.AILK_SPOKE_KEY;
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
it("carries the hub name on a hub-connected site with no CONTENT_ADAPTER", async () => {
|
|
168
|
+
process.env.AILK_SPOKE_KEY = KEY;
|
|
169
|
+
mockSiteConfigGet.mockResolvedValue(identity("Hub Co"));
|
|
170
|
+
expect((await llms("../route", PUBLIC_ROWS)).split("\n")[0]).toBe("# Hub Co — content index");
|
|
171
|
+
expect(mockSiteConfigGet).toHaveBeenCalled();
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
it("a hub name holding a newline heads llms.txt on one line", async () => {
|
|
175
|
+
process.env.AILK_SPOKE_KEY = KEY;
|
|
176
|
+
mockSiteConfigGet.mockResolvedValue(identity("A\nB"));
|
|
177
|
+
const text = await llms("../route", PUBLIC_ROWS);
|
|
178
|
+
expect(text.split("\n")[0]).toBe("# A B — content index");
|
|
179
|
+
expect(text.split("\n")[1]).toBe("");
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
it.each([
|
|
183
|
+
["CONTENT_ADAPTER unset", () => undefined],
|
|
184
|
+
["CONTENT_ADAPTER=database", () => (process.env.CONTENT_ADAPTER = "database")],
|
|
185
|
+
])("carries SITE_NAME with no AILK_SPOKE_KEY (%s), and never calls the hub", async (_label, arrange) => {
|
|
186
|
+
arrange();
|
|
187
|
+
mockSiteConfigGet.mockResolvedValue(identity("Hub Co"));
|
|
188
|
+
const { SITE_NAME } = jest.requireActual<typeof import("../../../lib/site-brand")>("../../../lib/site-brand");
|
|
189
|
+
expect((await llms("../route", PUBLIC_ROWS)).split("\n")[0]).toBe(`# ${SITE_NAME} — content index`);
|
|
190
|
+
expect(mockSiteConfigGet).not.toHaveBeenCalled();
|
|
191
|
+
});
|
|
192
|
+
});
|
|
@@ -28,6 +28,10 @@
|
|
|
28
28
|
*
|
|
29
29
|
* Blog (#10644 D1): under the database adapter the adapter's `BlogList` /
|
|
30
30
|
* `BlogPosting` rows are the blog, and `getBlogPages` is not called.
|
|
31
|
+
*
|
|
32
|
+
* Agent contact (#11423): on a site that serves `/contact` (`MARKETING_PAGES`),
|
|
33
|
+
* the body ends with `agentContactLines` — the operator's decision of
|
|
34
|
+
* 2026-11-11 on #11423.
|
|
31
35
|
*/
|
|
32
36
|
|
|
33
37
|
import { siteDiscoverable } from "@working-theory/api-client";
|
|
@@ -48,10 +52,10 @@ import {
|
|
|
48
52
|
listDocsPages,
|
|
49
53
|
type DocsIndexPage,
|
|
50
54
|
} from "../../lib/docs-index";
|
|
51
|
-
import { PUBLIC_PAGES } from "../../lib/modules.generated";
|
|
52
|
-
import {
|
|
55
|
+
import { MARKETING_PAGES, PUBLIC_PAGES } from "../../lib/modules.generated";
|
|
56
|
+
import { resolveSiteBrand } from "../../lib/site-brand";
|
|
53
57
|
import { SITE_LISTING } from "../../lib/site-listing";
|
|
54
|
-
import { pagePathFor, resolveBaseUrl } from "../../src/lib/routes";
|
|
58
|
+
import { agentContactLines, pagePathFor, resolveBaseUrl } from "../../src/lib/routes";
|
|
55
59
|
|
|
56
60
|
// #10510 D4 — read per request: the owner's discovery switch is a runtime
|
|
57
61
|
// setting a prerendered file could never follow.
|
|
@@ -77,6 +81,8 @@ export interface LlmsHandlerDeps {
|
|
|
77
81
|
discoverable?: () => Promise<boolean>;
|
|
78
82
|
/** The site's own listing (#10940 D3). Defaults to `SITE_LISTING`. */
|
|
79
83
|
getSiteListing?: () => SiteListing;
|
|
84
|
+
/** Whether this site serves /contact (#11423). Defaults to `MARKETING_PAGES`. */
|
|
85
|
+
hasContactPage?: () => boolean;
|
|
80
86
|
}
|
|
81
87
|
|
|
82
88
|
/**
|
|
@@ -89,6 +95,7 @@ export function createLlmsHandler(deps: LlmsHandlerDeps = {}) {
|
|
|
89
95
|
const resolveDocsPages = deps.getDocsPages ?? listDocsPages;
|
|
90
96
|
const isDiscoverable = deps.discoverable ?? siteDiscoverable;
|
|
91
97
|
const resolveSiteListing = deps.getSiteListing ?? (() => SITE_LISTING);
|
|
98
|
+
const resolveHasContactPage = deps.hasContactPage ?? (() => MARKETING_PAGES);
|
|
92
99
|
|
|
93
100
|
return async function llmsGET(): Promise<Response> {
|
|
94
101
|
// #10040 decision 7 — no public page, no content index: 404 before the adapter.
|
|
@@ -97,7 +104,11 @@ export function createLlmsHandler(deps: LlmsHandlerDeps = {}) {
|
|
|
97
104
|
if (!(await isDiscoverable())) return new Response(null, { status: 404, headers: { "cache-control": "no-store" } });
|
|
98
105
|
const adapter = resolveAdapter();
|
|
99
106
|
const baseUrl = resolveBaseUrl();
|
|
100
|
-
const
|
|
107
|
+
const { siteName } = await resolveSiteBrand();
|
|
108
|
+
const lines: string[] = [
|
|
109
|
+
`# ${siteName} — content index`,
|
|
110
|
+
"",
|
|
111
|
+
];
|
|
101
112
|
|
|
102
113
|
// llms.txt is default-locale-only per Phase 3 roadmap §3 (AEO MVP is
|
|
103
114
|
// default-locale; per-locale AEO grading is deferred). Pass the default
|
|
@@ -159,6 +170,8 @@ export function createLlmsHandler(deps: LlmsHandlerDeps = {}) {
|
|
|
159
170
|
}
|
|
160
171
|
}
|
|
161
172
|
|
|
173
|
+
if (resolveHasContactPage()) lines.push(...agentContactLines(baseUrl, siteName));
|
|
174
|
+
|
|
162
175
|
return new Response(lines.join("\n"), {
|
|
163
176
|
status: 200,
|
|
164
177
|
headers: {
|
|
@@ -40,14 +40,22 @@ const { TOPOLOGY: SEAM_TOPOLOGY } = jest.requireActual<
|
|
|
40
40
|
// The generated topology seam (#7426 D5), mocked so each case picks its
|
|
41
41
|
// topology: the hub cases below run against `"hub"`, exactly as before; the
|
|
42
42
|
// spoke cases (D12) flip it. Mocked rather than imported because the hub
|
|
43
|
-
// render imports `../auth`, which this route never touches.
|
|
44
|
-
|
|
43
|
+
// render imports `../auth`, which this route never touches. The factory owns
|
|
44
|
+
// the state because `lib/relay` reads `TOPOLOGY` while it loads (#8066 D2),
|
|
45
|
+
// before a module-scope `const` here would be initialised.
|
|
45
46
|
// eslint-disable-next-line no-restricted-syntax -- #507: the topology is a generated constant (#7426 D5), not a runtime input; the seam IS the boundary between a hub and a spoke build, and there is no env or HTTP surface that selects it.
|
|
46
|
-
jest.mock("../../../lib/topology.generated", () =>
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
47
|
+
jest.mock("../../../lib/topology.generated", () => {
|
|
48
|
+
const state: { value: "hub" | "spoke" } = { value: "hub" };
|
|
49
|
+
return {
|
|
50
|
+
__state: state,
|
|
51
|
+
get TOPOLOGY() {
|
|
52
|
+
return state.value;
|
|
53
|
+
},
|
|
54
|
+
};
|
|
55
|
+
});
|
|
56
|
+
const mockTopology = jest.requireMock<{
|
|
57
|
+
__state: { value: "hub" | "spoke" };
|
|
58
|
+
}>("../../../lib/topology.generated").__state;
|
|
51
59
|
|
|
52
60
|
const SPEC = {
|
|
53
61
|
openapi: "3.1.0",
|