create-ailk 0.22.0 → 0.23.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (238) hide show
  1. package/component-catalog.json +149 -5
  2. package/component-catalog.md +7 -6
  3. package/dist/add-module.js +11 -9
  4. package/dist/add-route.d.ts +55 -1
  5. package/dist/add-route.js +294 -12
  6. package/dist/cli.js +27 -10
  7. package/dist/derive-architecture.d.ts +7 -5
  8. package/dist/derive-architecture.js +9 -32
  9. package/dist/lib/design-checks.js +4 -2
  10. package/dist/lib/env-catalog.js +0 -4
  11. package/dist/lib/npm-auth.d.ts +9 -0
  12. package/dist/lib/npm-auth.js +48 -0
  13. package/dist/lib/scaffold-render-sweep.d.ts +3 -2
  14. package/dist/lib/scaffold-render-sweep.js +5 -8
  15. package/dist/module-architecture.js +98 -10
  16. package/dist/paid-sections.d.ts +21 -2
  17. package/dist/paid-sections.js +69 -7
  18. package/dist/seed-flows.d.ts +4 -1
  19. package/dist/seed-flows.js +50 -4
  20. package/dist/spoke-checkout.d.ts +38 -35
  21. package/dist/spoke-checkout.js +66 -229
  22. package/dist/starter-grid.d.ts +0 -3
  23. package/dist/starter-grid.js +24 -14
  24. package/dist/surfaces.js +33 -12
  25. package/dist/sync-routes.d.ts +38 -1
  26. package/dist/sync-routes.js +184 -11
  27. package/dist/template-record.d.ts +1 -1
  28. package/dist/template-record.js +3 -2
  29. package/dist/update.js +10 -0
  30. package/package.json +3 -3
  31. package/site-templates/_base/content/en/NewsletterSignup/newsletter.mdx +4 -49
  32. package/site-templates/_base/content/en/Pricing/pricing.mdx +3 -21
  33. package/site-templates/marketing-site/TEMPLATE-MANIFEST.json +23 -20
  34. package/site-templates/marketing-site/TEMPLATE-MANIFEST.md +28 -14
  35. package/site-templates/marketing-site-free/TEMPLATE-MANIFEST.json +15 -39
  36. package/site-templates/marketing-site-free/TEMPLATE-MANIFEST.md +38 -34
  37. package/site-templates/marketing-site-free/content/en/NewsletterSignup/newsletter.mdx +6 -43
  38. package/site-templates/shapes/local-business-service/TEMPLATE-MANIFEST.json +14 -31
  39. package/site-templates/shapes/local-business-service/TEMPLATE-MANIFEST.md +26 -25
  40. package/site-templates/shapes/local-business-service/content/en/NewsletterSignup/newsletter.mdx +6 -43
  41. package/site-templates/shapes/organization-service/TEMPLATE-MANIFEST.json +14 -31
  42. package/site-templates/shapes/organization-service/TEMPLATE-MANIFEST.md +26 -25
  43. package/site-templates/shapes/organization-service/content/en/NewsletterSignup/newsletter.mdx +6 -43
  44. package/site-templates/shapes/person-service/TEMPLATE-MANIFEST.json +14 -31
  45. package/site-templates/shapes/person-service/TEMPLATE-MANIFEST.md +26 -25
  46. package/site-templates/shapes/person-service/content/en/NewsletterSignup/newsletter.mdx +6 -43
  47. package/templates/.env.example +9 -7
  48. package/templates/.github/workflows/ci.yml +13 -0
  49. package/templates/README.md +1 -0
  50. package/templates/_gitignore +4 -0
  51. package/templates/apps/api/.env.example +27 -0
  52. package/templates/apps/api/CLAUDE.md +77 -16
  53. package/templates/apps/api/package.json +1 -0
  54. package/templates/apps/api/src/__tests__/factories/in-memory-prisma.ts +2 -0
  55. package/templates/apps/api/src/bin/stripe-connections-rekey.ts +45 -0
  56. package/templates/apps/api/src/config/__tests__/stripe-connection-key.test.ts +185 -0
  57. package/templates/apps/api/src/config/index.ts +109 -0
  58. package/templates/apps/api/src/lib/__mocks__/prisma.ts +3 -0
  59. package/templates/apps/api/src/lib/__tests__/flow-rename-race.db.test.ts +116 -0
  60. package/templates/apps/api/src/lib/error-serializer.ts +74 -7
  61. package/templates/apps/api/src/lib/stripe.ts +74 -4
  62. package/templates/apps/api/src/lib/webhook-idempotency.ts +66 -2
  63. package/templates/apps/api/src/middleware/__tests__/rate-limit.test.ts +218 -0
  64. package/templates/apps/api/src/middleware/__tests__/write-budget.test.ts +174 -0
  65. package/templates/apps/api/src/middleware/rate-limit.ts +226 -4
  66. package/templates/apps/api/src/openapi/spec.ts +10 -7
  67. package/templates/apps/api/src/routes/billing/plan-checkout.ts +325 -0
  68. package/templates/apps/api/src/routes/checkout/__tests__/live-key.test.ts +11 -0
  69. package/templates/apps/api/src/routes/checkout/__tests__/offerings-authorization.test.ts +1300 -0
  70. package/templates/apps/api/src/routes/checkout/__tests__/session.test.ts +11 -0
  71. package/templates/apps/api/src/routes/checkout/__tests__/sessions.test.ts +49 -0
  72. package/templates/apps/api/src/routes/checkout/session.ts +57 -25
  73. package/templates/apps/api/src/routes/checkout/sessions.ts +232 -82
  74. package/templates/apps/api/src/routes/consent/__tests__/account.test.ts +5 -5
  75. package/templates/apps/api/src/routes/consent/__tests__/sign-up-rate-limit.test.ts +160 -0
  76. package/templates/apps/api/src/routes/consent/account.ts +4 -2
  77. package/templates/apps/api/src/routes/content/__tests__/get-page.test.ts +2 -2
  78. package/templates/apps/api/src/routes/content/__tests__/offerings.test.ts +731 -0
  79. package/templates/apps/api/src/routes/content/__tests__/pricing.test.ts +753 -0
  80. package/templates/apps/api/src/routes/content/__tests__/shown-offerings.test.ts +762 -0
  81. package/templates/apps/api/src/routes/content/index.ts +16 -2
  82. package/templates/apps/api/src/routes/content/offerings.ts +184 -0
  83. package/templates/apps/api/src/routes/content/pricing.ts +176 -0
  84. package/templates/apps/api/src/routes/content/shown-offerings.ts +229 -0
  85. package/templates/apps/api/src/routes/leads/index.ts +17 -14
  86. package/templates/apps/api/src/routes/webhooks/README.md +66 -0
  87. package/templates/apps/api/src/routes/webhooks/__tests__/stripe-offerings.test.ts +814 -0
  88. package/templates/apps/api/src/routes/webhooks/__tests__/stripe-org-billing.test.ts +80 -68
  89. package/templates/apps/api/src/routes/webhooks/__tests__/stripe-site-filter.test.ts +5 -5
  90. package/templates/apps/api/src/routes/webhooks/__tests__/stripe.test.ts +8 -2
  91. package/templates/apps/api/src/routes/webhooks/index.ts +23 -0
  92. package/templates/apps/api/src/routes/webhooks/stripe-offerings.ts +384 -0
  93. package/templates/apps/api/src/routes/webhooks/stripe.ts +91 -17
  94. package/templates/apps/api/src/server.ts +140 -51
  95. package/templates/apps/api/src/services/__tests__/checkout-plan.test.ts +313 -0
  96. package/templates/apps/api/src/services/__tests__/deliverable-fulfillment.test.ts +51 -2
  97. package/templates/apps/api/src/services/__tests__/keyless-workspace-predicate.test.ts +234 -0
  98. package/templates/apps/api/src/services/__tests__/lead-routing.test.ts +374 -44
  99. package/templates/apps/api/src/services/__tests__/person.test.ts +232 -1
  100. package/templates/apps/api/src/services/__tests__/plan-offerings.test.ts +444 -0
  101. package/templates/apps/api/src/services/deliverable-fulfillment.ts +13 -5
  102. package/templates/apps/api/src/services/entitlements.ts +157 -1
  103. package/templates/apps/api/src/services/lead-routing.ts +113 -58
  104. package/templates/apps/api/src/services/offerings/__tests__/catalog.test.ts +295 -0
  105. package/templates/apps/api/src/services/offerings/__tests__/checkout-session-record.test.ts +268 -0
  106. package/templates/apps/api/src/services/offerings/__tests__/connection.test.ts +868 -0
  107. package/templates/apps/api/src/services/offerings/__tests__/fixtures.ts +416 -0
  108. package/templates/apps/api/src/services/offerings/__tests__/org-products.test.ts +396 -0
  109. package/templates/apps/api/src/services/offerings/__tests__/readers.test.ts +681 -0
  110. package/templates/apps/api/src/services/offerings/__tests__/source.test.ts +231 -0
  111. package/templates/apps/api/src/services/offerings/catalog.ts +308 -0
  112. package/templates/apps/api/src/services/offerings/checkout-authorization.ts +385 -0
  113. package/templates/apps/api/src/services/offerings/checkout-session-record.ts +192 -0
  114. package/templates/apps/api/src/services/offerings/connection.ts +1003 -0
  115. package/templates/apps/api/src/services/offerings/index.ts +614 -0
  116. package/templates/apps/api/src/services/offerings/source.ts +140 -0
  117. package/templates/apps/api/src/services/offerings/store.ts +150 -0
  118. package/templates/apps/api/src/services/person.ts +124 -9
  119. package/templates/apps/api/src/services/plan-offerings.ts +96 -30
  120. package/templates/apps/api/src/services/public-site-resolver.ts +19 -14
  121. package/templates/apps/mcp/CLAUDE.md +22 -14
  122. package/templates/apps/mcp/__tests__/catalog-drift.test.ts +9 -4
  123. package/templates/apps/mcp/__tests__/get_offerings.test.ts +358 -0
  124. package/templates/apps/mcp/__tests__/get_pricing.test.ts +364 -0
  125. package/templates/apps/mcp/__tests__/http-transport.test.ts +4 -4
  126. package/templates/apps/mcp/__tests__/module-exclusion.test.ts +2 -2
  127. package/templates/apps/mcp/__tests__/server.test.ts +13 -11
  128. package/templates/apps/mcp/__tests__/start_purchase.test.ts +208 -12
  129. package/templates/apps/mcp/__tests__/tools/purchase.test.ts +11 -11
  130. package/templates/apps/mcp/src/lib/shown-offerings.ts +105 -0
  131. package/templates/apps/mcp/src/server.ts +5 -0
  132. package/templates/apps/mcp/src/tools/get_offerings.ts +47 -30
  133. package/templates/apps/mcp/src/tools/get_pricing.ts +40 -40
  134. package/templates/apps/mcp/src/tools/purchase.ts +30 -2
  135. package/templates/apps/mcp/src/workspace-server.ts +15 -0
  136. package/templates/apps/web/.env.example +10 -31
  137. package/templates/apps/web/CLAUDE.md +315 -42
  138. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/agreements-prompt.test.tsx +3 -3
  139. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/layout.test.tsx +3 -3
  140. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/privacy.test.tsx +3 -3
  141. package/templates/apps/web/app/[locale]/careers/[slug]/[action]/page.tsx +189 -0
  142. package/templates/apps/web/app/[locale]/careers/[slug]/apply.actions.ts +4 -2
  143. package/templates/apps/web/app/[locale]/careers/[slug]/job-application-form.ts +8 -3
  144. package/templates/apps/web/app/[locale]/careers/[slug]/page.tsx +22 -144
  145. package/templates/apps/web/app/[locale]/careers/__tests__/apply.actions.test.ts +9 -0
  146. package/templates/apps/web/app/[locale]/careers/__tests__/careers-hub.test.tsx +172 -0
  147. package/templates/apps/web/app/[locale]/careers/__tests__/careers-set.test.tsx +149 -0
  148. package/templates/apps/web/app/[locale]/careers/__tests__/job-application-form.test.ts +22 -24
  149. package/templates/apps/web/app/[locale]/careers/__tests__/job-apply-page.test.tsx +140 -66
  150. package/templates/apps/web/app/[locale]/careers/__tests__/page-renderer-migration.test.tsx +57 -22
  151. package/templates/apps/web/app/[locale]/careers/page.tsx +129 -5
  152. package/templates/apps/web/app/[locale]/contact/__tests__/contact-magnet-page.test.tsx +119 -11
  153. package/templates/apps/web/app/[locale]/contact/__tests__/contact.actions.test.ts +28 -5
  154. package/templates/apps/web/app/[locale]/contact/contact.actions.ts +6 -2
  155. package/templates/apps/web/app/[locale]/contact/page.tsx +99 -92
  156. package/templates/apps/web/app/[locale]/flows/[slug]/FlowStepperClient.tsx +237 -5
  157. package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/FlowStepperClient.count.test.tsx +43 -0
  158. package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/FlowStepperClient.deliverable.test.tsx +200 -0
  159. package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/FlowStepperClient.ending.test.tsx +197 -0
  160. package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/magnet-page.test.tsx +430 -0
  161. package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/two-route-tool.test.tsx +21 -9
  162. package/templates/apps/web/app/[locale]/flows/[slug]/magnet-page.tsx +352 -0
  163. package/templates/apps/web/app/[locale]/flows/[slug]/page.tsx +12 -73
  164. package/templates/apps/web/app/[locale]/flows/[slug]/start/page.tsx +10 -31
  165. package/templates/apps/web/app/[locale]/layout.tsx +55 -4
  166. package/templates/apps/web/app/[locale]/newsletter/__tests__/page.test.tsx +174 -104
  167. package/templates/apps/web/app/[locale]/newsletter/page.tsx +95 -58
  168. package/templates/apps/web/app/[locale]/pricing/__tests__/__snapshots__/unconnected.test.tsx.snap +7 -0
  169. package/templates/apps/web/app/[locale]/pricing/__tests__/offerings.test.tsx +599 -0
  170. package/templates/apps/web/app/[locale]/pricing/__tests__/page.test.tsx +216 -0
  171. package/templates/apps/web/app/[locale]/pricing/__tests__/unconnected.test.tsx +236 -0
  172. package/templates/apps/web/app/[locale]/pricing/page.tsx +367 -6
  173. package/templates/apps/web/app/[locale]/team/__tests__/team-routes.test.tsx +4 -1
  174. package/templates/apps/web/app/[locale]/unsubscribe/__tests__/unsubscribe-rsc-boundary.test.tsx +17 -0
  175. package/templates/apps/web/app/[locale]/unsubscribe/__tests__/unsubscribe.test.tsx +62 -3
  176. package/templates/apps/web/app/[locale]/unsubscribe/page.tsx +70 -18
  177. package/templates/apps/web/app/[locale]/unsubscribe/unsubscribe-button.tsx +30 -9
  178. package/templates/apps/web/app/api/offerings/checkout/[lookupKey]/route.ts +316 -0
  179. package/templates/apps/web/app/api/offerings/checkout/__tests__/route.test.ts +810 -0
  180. package/templates/apps/web/lib/__tests__/auth-routes.test.ts +27 -1
  181. package/templates/apps/web/lib/__tests__/deck-page.test.ts +2 -1
  182. package/templates/apps/web/lib/__tests__/in-page-magnet.test.ts +265 -0
  183. package/templates/apps/web/lib/__tests__/magnet-routes.test.ts +57 -0
  184. package/templates/apps/web/lib/__tests__/newsletter.actions.test.ts +293 -0
  185. package/templates/apps/web/lib/__tests__/offerings-pricing.test.ts +601 -0
  186. package/templates/apps/web/lib/__tests__/structured-data.test.tsx +67 -8
  187. package/templates/apps/web/lib/auth-routes.ts +36 -2
  188. package/templates/apps/web/lib/checkout-config.ts +9 -20
  189. package/templates/apps/web/lib/deck-page.ts +1 -0
  190. package/templates/apps/web/lib/deliverable-grant.ts +18 -0
  191. package/templates/apps/web/lib/in-page-magnet.ts +416 -0
  192. package/templates/apps/web/lib/magnet-routes.ts +42 -0
  193. package/templates/apps/web/lib/modules.generated.ts +9 -0
  194. package/templates/apps/web/lib/newsletter.actions.ts +202 -0
  195. package/templates/apps/web/lib/offerings-pricing.ts +326 -0
  196. package/templates/apps/web/lib/posting-title.ts +17 -0
  197. package/templates/apps/web/lib/sign-up-agreements.ts +4 -2
  198. package/templates/apps/web/messages/en.json +49 -15
  199. package/templates/apps/web/middleware.ts +12 -2
  200. package/templates/apps/web/security-headers.config.ts +17 -0
  201. package/templates/content/en/BlogList/blog.mdx +4 -71
  202. package/templates/content/en/BookCall/book-a-call.mdx +1 -41
  203. package/templates/content/en/BookCall/onsite-estimate.mdx +1 -17
  204. package/templates/content/en/BookCall/onsite-service.mdx +1 -17
  205. package/templates/content/en/BookCall/start-project.mdx +1 -17
  206. package/templates/content/en/ContactPage/contact.mdx +6 -63
  207. package/templates/content/en/HomePage/home.mdx +3 -21
  208. package/templates/database/CHANGELOG.md +31 -0
  209. package/templates/database/__tests__/in-page-magnets-migration.test.ts +161 -0
  210. package/templates/database/__tests__/offerings-checkout-session.db.test.ts +270 -0
  211. package/templates/database/__tests__/offerings-migration.test.ts +197 -0
  212. package/templates/database/__tests__/offerings-shown-price-ids-migration.test.ts +86 -0
  213. package/templates/database/__tests__/offerings.db.test.ts +303 -0
  214. package/templates/database/__tests__/seed.test.ts +31 -1
  215. package/templates/database/auth/schema.prisma +4 -0
  216. package/templates/database/config/schema.prisma +91 -0
  217. package/templates/database/migrations/20261020120000_offerings_data_model/migration.sql +146 -0
  218. package/templates/database/migrations/20261021120000_offerings_checkout_session/migration.sql +77 -0
  219. package/templates/database/migrations/20261022120000_in_page_magnets/migration.sql +45 -0
  220. package/templates/database/migrations/20261023120000_offerings_shown_price_ids/migration.sql +47 -0
  221. package/templates/database/migrations/20261024120000_organization_plan_checkout_session/migration.sql +16 -0
  222. package/templates/database/package.json +1 -1
  223. package/templates/database/seed.ts +30 -2
  224. package/versions.json +35 -35
  225. package/site-templates/marketing-site-free/content/en/Pricing/pricing.mdx +0 -199
  226. package/templates/apps/web/app/[locale]/downloads/__tests__/page-renderer-migration.test.tsx +0 -93
  227. package/templates/apps/web/app/[locale]/downloads/page.tsx +0 -37
  228. package/templates/apps/web/app/[locale]/newsletter/__tests__/newsletter.actions.test.ts +0 -139
  229. package/templates/apps/web/app/[locale]/newsletter/newsletter.actions.ts +0 -93
  230. package/templates/apps/web/app/api/checkout/[offering]/route.ts +0 -48
  231. package/templates/apps/web/app/api/checkout/__tests__/route.test.ts +0 -120
  232. package/templates/apps/web/app/api/checkout/__tests__/success-path.test.ts +0 -86
  233. package/templates/apps/web/app/api/webhooks/stripe/__tests__/route.test.ts +0 -92
  234. package/templates/apps/web/app/api/webhooks/stripe/route.ts +0 -31
  235. package/templates/apps/web/lib/__tests__/checkout.test.ts +0 -243
  236. package/templates/apps/web/lib/__tests__/meeting-slugs.test.ts +0 -120
  237. package/templates/apps/web/lib/checkout.ts +0 -93
  238. package/templates/apps/web/lib/meeting-slugs.ts +0 -63
@@ -1,9 +1,16 @@
1
1
  /**
2
2
  * Public content API.
3
3
  *
4
- * Read endpoints, all GET, all JSON-LD-shaped at the document root:
4
+ * Read endpoints, all GET, JSON-LD-shaped at the document root unless noted:
5
5
  * GET /v1/content/types — supported page types
6
6
  * GET /v1/content/search — keyword search (#5831)
7
+ * GET /v1/content/offerings — Services + Products (#7177); answers the
8
+ * `{ ok, data }` envelope, not JSON-LD
9
+ * GET /v1/content/pricing — pricing tiers (#7178); answers the
10
+ * `{ ok, data }` envelope, not JSON-LD
11
+ * GET /v1/content/shown-offerings — the /pricing page's Offerings read
12
+ * (#8924); answers the { ok, data }
13
+ * envelope, not JSON-LD
7
14
  * GET /v1/content/:type — paginated list of pages
8
15
  * GET /v1/content/:type/:slug — single page with resolved JSON-LD
9
16
  *
@@ -24,12 +31,19 @@ import type { FastifyPluginAsync } from "fastify";
24
31
  import { getPageRoute } from "./get-page.js";
25
32
  import { listPagesRoute } from "./list-pages.js";
26
33
  import { listTypesRoute } from "./list-types.js";
34
+ import { offeringsRoute } from "./offerings.js";
35
+ import { pricingRoute } from "./pricing.js";
27
36
  import { searchContentRoute } from "./search.js";
37
+ import { shownOfferingsRoute } from "./shown-offerings.js";
28
38
 
29
39
  export const contentRoutes: FastifyPluginAsync = async (fastify) => {
30
40
  await fastify.register(listTypesRoute);
31
- // Before `listPagesRoute`: `search` must never be read as a `:type`.
41
+ // Before `listPagesRoute`: `search`, `offerings`, `pricing` and
42
+ // `shown-offerings` must never be read as a `:type`.
32
43
  await fastify.register(searchContentRoute);
44
+ await fastify.register(offeringsRoute);
45
+ await fastify.register(pricingRoute);
46
+ await fastify.register(shownOfferingsRoute);
33
47
  await fastify.register(listPagesRoute);
34
48
  await fastify.register(getPageRoute);
35
49
  };
@@ -0,0 +1,184 @@
1
+ /**
2
+ * GET /v1/content/offerings
3
+ *
4
+ * The site's Services and Products as one offerings list (#7177). The HTTP
5
+ * twin of the `get_offerings` MCP tool: same arguments, parsed with the same
6
+ * `@working-theory/validation` schema, and the same result, produced by the
7
+ * same function — `listOfferings` in `@working-theory/content-adapters`, the
8
+ * shared seam the tool also answers through. That is the API ↔ MCP parity
9
+ * contract in the root CLAUDE.md; the parity guard's `get_offerings` row is a
10
+ * `twin` naming this route.
11
+ *
12
+ * Query:
13
+ * type optional — `service` or `product`; omit for both
14
+ * locale optional — BCP-47 (`xx` or `xx-XX`). A well-formed tag outside the
15
+ * project's allowlist silently falls back to the default locale
16
+ * (AC-i18n-07), matching every other content read; a malformed one
17
+ * is a 400, as the tool refuses it.
18
+ *
19
+ * Success: `{ ok: true, data: { offerings } }` — the API's documented
20
+ * envelope, not the JSON-LD `ItemList` the older content routes answer.
21
+ * Refusals: `400 validation_failed` (issues are not echoed), `404 not_found`
22
+ * when no public site resolves, `500 internal_error`.
23
+ *
24
+ * Registered BEFORE `/v1/content/:type` in `index.ts`. Fastify's radix router
25
+ * prefers a static segment over a parametric one regardless of order — the
26
+ * ordering is belt-and-braces, as it is for search.
27
+ *
28
+ * Rate limiting is inherited: `server.ts` registers the limiter GLOBALLY with
29
+ * the content ceiling, so this route is covered without one of its own.
30
+ *
31
+ * Which site this read serves is resolved BEFORE any content query (#5852)
32
+ * through the same `resolvePublicContentAdapter(request)` seam the sibling
33
+ * content reads use. The resolver reads `x-ailk-spoke-key`, so every answer
34
+ * past the query parse appends that header to `Vary`: a cache keyed on the
35
+ * URL alone must never share one site's answer — or one bad key's 404 — with
36
+ * another (SEC-7177-C). It appends rather than sets, because `@fastify/cors`
37
+ * has already written `Vary: Origin`.
38
+ *
39
+ * Offerings (#8933, spec D4): on a connected workspace with a current shown
40
+ * set, every read but `type=service` answers the Service pages followed by
41
+ * that set's Products — in place of the Product pages, since Stripe is that
42
+ * site's price authority — through `readShownOfferings` (#8924's read, the
43
+ * one code path every agent surface shares) and `listOfferingsWithShownSet`
44
+ * in `@working-theory/content-adapters`, the mapping the tool answers through
45
+ * too. Each shown Product carries `prices`: every price with its interval and
46
+ * full lookup key. `type=service`, and every workspace with no connection, no
47
+ * claim or no current set, answers page content exactly as before; a failed
48
+ * shown-set read takes the content path too. The read refreshes, or not,
49
+ * exactly as the shown-offerings route does (`options`, D5): never with the
50
+ * owner's override, never per request (T7).
51
+ *
52
+ * Anonymous and identity-blind: no `Authorization`, cookie, session or user
53
+ * id is read.
54
+ */
55
+ import {
56
+ currentShownSet,
57
+ listOfferings,
58
+ listOfferingsWithShownSet,
59
+ type ContentAdapter,
60
+ type ListOfferingsOptions,
61
+ } from "@working-theory/content-adapters";
62
+ import {
63
+ getOfferingsInputSchema,
64
+ type GetOfferingsOutput,
65
+ } from "@working-theory/validation";
66
+ import type {
67
+ FastifyPluginAsync,
68
+ FastifyReply,
69
+ FastifyRequest,
70
+ } from "fastify";
71
+
72
+ import { resolveLocale } from "../../lib/locales.js";
73
+ import { resolvePublicContentAdapter } from "../../services/public-site-resolver.js";
74
+
75
+ import {
76
+ readShownOfferings,
77
+ type ShownOfferingsRouteOptions,
78
+ } from "./shown-offerings.js";
79
+
80
+ /** The request header the resolver picks the site's workspace from. */
81
+ const SPOKE_KEY_HEADER = "x-ailk-spoke-key";
82
+
83
+ /** Adds the spoke-key header to `Vary`, keeping every value already there. */
84
+ function varyOnSpokeKey(reply: FastifyReply): void {
85
+ const existing = reply.getHeader("vary");
86
+ const values = (
87
+ Array.isArray(existing) ? existing.join(",") : String(existing ?? "")
88
+ )
89
+ .split(",")
90
+ .map((value) => value.trim())
91
+ .filter((value) => value !== "");
92
+ if (!values.some((value) => value.toLowerCase() === SPOKE_KEY_HEADER)) {
93
+ values.push(SPOKE_KEY_HEADER);
94
+ }
95
+ reply.header("Vary", values.join(", "));
96
+ }
97
+
98
+ /** An error's class name only — never its message, which may carry Stripe text. */
99
+ function errName(err: unknown): string {
100
+ return err instanceof Error ? err.constructor.name : typeof err;
101
+ }
102
+
103
+ /**
104
+ * The page Services followed by the connected workspace's shown Products, or
105
+ * `null` for the content path (#8933 D4). A failed read or mapping is one
106
+ * fixed `warn` line and the content path, never a 500 and never an `{ err }`
107
+ * line.
108
+ */
109
+ async function shownSetOfferings(
110
+ request: FastifyRequest,
111
+ options: ShownOfferingsRouteOptions,
112
+ adapter: ContentAdapter,
113
+ listOptions: ListOfferingsOptions,
114
+ ): Promise<GetOfferingsOutput | null> {
115
+ try {
116
+ const shownSet = currentShownSet(
117
+ await readShownOfferings(request, options),
118
+ );
119
+ return shownSet === null
120
+ ? null
121
+ : await listOfferingsWithShownSet(adapter, listOptions, shownSet);
122
+ } catch (err) {
123
+ request.log.warn(
124
+ { outcome: "shown_set_failed", errName: errName(err) },
125
+ "[Content] offerings: shown set unavailable, answering page content",
126
+ );
127
+ return null;
128
+ }
129
+ }
130
+
131
+ export const offeringsRoute: FastifyPluginAsync<
132
+ ShownOfferingsRouteOptions
133
+ > = async (fastify, options) => {
134
+ fastify.get<{
135
+ Querystring: { type?: string; locale?: string };
136
+ }>("/v1/content/offerings", async (request, reply) => {
137
+ const query = getOfferingsInputSchema.safeParse(request.query);
138
+ if (!query.success) {
139
+ return reply.status(400).send({
140
+ ok: false,
141
+ error: {
142
+ code: "validation_failed",
143
+ message: "Invalid query parameters",
144
+ },
145
+ });
146
+ }
147
+
148
+ const locale = resolveLocale(query.data.locale);
149
+ // Every answer from here on depends on the spoke key — the 404 and 500
150
+ // included — so each carries the Vary.
151
+ varyOnSpokeKey(reply);
152
+
153
+ try {
154
+ const adapter = await resolvePublicContentAdapter(request);
155
+ if (adapter === null) {
156
+ return reply.status(404).send({
157
+ ok: false,
158
+ error: { code: "not_found", message: "Page not found" },
159
+ });
160
+ }
161
+
162
+ if (query.data.type !== "service") {
163
+ const shown = await shownSetOfferings(request, options, adapter, {
164
+ type: query.data.type,
165
+ locale,
166
+ });
167
+ if (shown !== null) return reply.send({ ok: true, data: shown });
168
+ }
169
+
170
+ const data = await listOfferings(adapter, {
171
+ type: query.data.type,
172
+ locale,
173
+ });
174
+
175
+ return reply.send({ ok: true, data });
176
+ } catch (error) {
177
+ request.log.error({ err: error }, "[Content] listOfferings failed");
178
+ return reply.status(500).send({
179
+ ok: false,
180
+ error: { code: "internal_error", message: "Internal server error" },
181
+ });
182
+ }
183
+ });
184
+ };
@@ -0,0 +1,176 @@
1
+ /**
2
+ * GET /v1/content/pricing
3
+ *
4
+ * The site's pricing tiers, read from a `Product` page's `offers` (#7178).
5
+ * The HTTP twin of the `get_pricing` MCP tool: same arguments, parsed with
6
+ * the same `@working-theory/validation` schema, and the same result, produced
7
+ * by the same function — `getPricingTiers` in `@working-theory/content-adapters`,
8
+ * the shared seam the tool also answers through. That is the API ↔ MCP parity
9
+ * contract in the root CLAUDE.md; the parity guard's `get_pricing` row is a
10
+ * `twin` naming this route.
11
+ *
12
+ * Query:
13
+ * slug optional — lowercase alphanumeric and hyphens; default `pricing`
14
+ * locale optional — BCP-47 (`xx` or `xx-XX`). A well-formed tag outside the
15
+ * project's allowlist silently falls back to the default locale
16
+ * (AC-i18n-07), matching every other content read; a malformed one
17
+ * is a 400, as the tool refuses it.
18
+ *
19
+ * Success: `{ ok: true, data: { tiers } | null }` — the API's documented
20
+ * envelope, not the JSON-LD `ItemList` the older content routes answer. "No
21
+ * pricing" is a 200 with `data: null`, exactly as the tool answers it.
22
+ * Refusals: `400 validation_failed` (issues are not echoed), `404 not_found`
23
+ * when no public site resolves, `500 internal_error`.
24
+ *
25
+ * Registered BEFORE `/v1/content/:type` in `index.ts`. Fastify's radix router
26
+ * prefers a static segment over a parametric one regardless of order — the
27
+ * ordering is belt-and-braces, as it is for search. `/v1/content/Pricing`
28
+ * (the page type, capitalised) stays the type list.
29
+ *
30
+ * Rate limiting is inherited: `server.ts` registers the limiter GLOBALLY with
31
+ * the content ceiling, so this route is covered without one of its own.
32
+ *
33
+ * Which site this read serves is resolved BEFORE any content query (#5852)
34
+ * through the same `resolvePublicContentAdapter(request)` seam the sibling
35
+ * content reads use. The resolver reads `x-ailk-spoke-key`, so every answer
36
+ * past the query parse appends that header to `Vary`: a cache keyed on the
37
+ * URL alone must never share one site's answer — or one bad key's 404 — with
38
+ * another. It appends rather than sets, because `@fastify/cors` has already
39
+ * written `Vary: Origin`.
40
+ *
41
+ * Offerings (#8933, spec D4): on a connected workspace with a current shown
42
+ * set, the `pricing` page (the default slug) answers that set instead — one
43
+ * tier per Stripe Price, through `readShownOfferings` (#8924's read, the one
44
+ * code path every agent surface shares) and `pricingTiersFromShownSet` in
45
+ * `@working-theory/content-adapters`, the mapping the tool answers through
46
+ * too. Each tier then also carries `interval` and the full `lookupKey`. Every
47
+ * other slug, and every workspace with no connection, no claim or no current
48
+ * set, answers page content exactly as before; a failed shown-set read takes
49
+ * the content path too. The read refreshes, or not, exactly as the
50
+ * shown-offerings route does (`options`, D5): never with the owner's
51
+ * override, never per request (T7).
52
+ *
53
+ * Anonymous and identity-blind: no `Authorization`, cookie, session or user
54
+ * id is read.
55
+ */
56
+ import {
57
+ currentShownSet,
58
+ getPricingTiers,
59
+ pricingTiersFromShownSet,
60
+ shownSetAnswersPricing,
61
+ } from "@working-theory/content-adapters";
62
+ import {
63
+ getPricingInputSchema,
64
+ type GetPricingOutput,
65
+ } from "@working-theory/validation";
66
+ import type {
67
+ FastifyPluginAsync,
68
+ FastifyReply,
69
+ FastifyRequest,
70
+ } from "fastify";
71
+
72
+ import { resolveLocale } from "../../lib/locales.js";
73
+ import { resolvePublicContentAdapter } from "../../services/public-site-resolver.js";
74
+
75
+ import {
76
+ readShownOfferings,
77
+ type ShownOfferingsRouteOptions,
78
+ } from "./shown-offerings.js";
79
+
80
+ /** The request header the resolver picks the site's workspace from. */
81
+ const SPOKE_KEY_HEADER = "x-ailk-spoke-key";
82
+
83
+ /** Adds the spoke-key header to `Vary`, keeping every value already there. */
84
+ function varyOnSpokeKey(reply: FastifyReply): void {
85
+ const existing = reply.getHeader("vary");
86
+ const values = (
87
+ Array.isArray(existing) ? existing.join(",") : String(existing ?? "")
88
+ )
89
+ .split(",")
90
+ .map((value) => value.trim())
91
+ .filter((value) => value !== "");
92
+ if (!values.some((value) => value.toLowerCase() === SPOKE_KEY_HEADER)) {
93
+ values.push(SPOKE_KEY_HEADER);
94
+ }
95
+ reply.header("Vary", values.join(", "));
96
+ }
97
+
98
+ /** An error's class name only — never its message, which may carry Stripe text. */
99
+ function errName(err: unknown): string {
100
+ return err instanceof Error ? err.constructor.name : typeof err;
101
+ }
102
+
103
+ /**
104
+ * The connected workspace's shown set as tiers, or `null` for the content
105
+ * path (#8933 D4). A failed read or mapping is one fixed `warn` line and the
106
+ * content path, never a 500 and never an `{ err }` line.
107
+ */
108
+ async function shownSetTiers(
109
+ request: FastifyRequest,
110
+ options: ShownOfferingsRouteOptions,
111
+ ): Promise<NonNullable<GetPricingOutput> | null> {
112
+ try {
113
+ const shownSet = currentShownSet(
114
+ await readShownOfferings(request, options),
115
+ );
116
+ return shownSet === null ? null : pricingTiersFromShownSet(shownSet);
117
+ } catch (err) {
118
+ request.log.warn(
119
+ { outcome: "shown_set_failed", errName: errName(err) },
120
+ "[Content] pricing: shown set unavailable, answering page content",
121
+ );
122
+ return null;
123
+ }
124
+ }
125
+
126
+ export const pricingRoute: FastifyPluginAsync<
127
+ ShownOfferingsRouteOptions
128
+ > = async (fastify, options) => {
129
+ fastify.get<{
130
+ Querystring: { slug?: string; locale?: string };
131
+ }>("/v1/content/pricing", async (request, reply) => {
132
+ const query = getPricingInputSchema.safeParse(request.query);
133
+ if (!query.success) {
134
+ return reply.status(400).send({
135
+ ok: false,
136
+ error: {
137
+ code: "validation_failed",
138
+ message: "Invalid query parameters",
139
+ },
140
+ });
141
+ }
142
+
143
+ const locale = resolveLocale(query.data.locale);
144
+ // Every answer from here on depends on the spoke key — the 404 and 500
145
+ // included — so each carries the Vary.
146
+ varyOnSpokeKey(reply);
147
+
148
+ try {
149
+ const adapter = await resolvePublicContentAdapter(request);
150
+ if (adapter === null) {
151
+ return reply.status(404).send({
152
+ ok: false,
153
+ error: { code: "not_found", message: "Page not found" },
154
+ });
155
+ }
156
+
157
+ if (shownSetAnswersPricing(query.data.slug)) {
158
+ const tiers = await shownSetTiers(request, options);
159
+ if (tiers !== null) return reply.send({ ok: true, data: tiers });
160
+ }
161
+
162
+ const data = await getPricingTiers(adapter, {
163
+ slug: query.data.slug,
164
+ locale,
165
+ });
166
+
167
+ return reply.send({ ok: true, data });
168
+ } catch (error) {
169
+ request.log.error({ err: error }, "[Content] getPricingTiers failed");
170
+ return reply.status(500).send({
171
+ ok: false,
172
+ error: { code: "internal_error", message: "Internal server error" },
173
+ });
174
+ }
175
+ });
176
+ };
@@ -0,0 +1,229 @@
1
+ /**
2
+ * GET /v1/content/shown-offerings
3
+ *
4
+ * The `/pricing` page's Offerings read (#8924, spec
5
+ * docs/specs/8924-the-anonymous-pricing-read-the-spec.md): the resolved
6
+ * workspace's shown set, read from its persisted Stripe snapshot through
7
+ * #8876's `getWorkspaceShownSet`. No argument — no path parameter, query or
8
+ * body, and a query string is ignored.
9
+ *
10
+ * Answers (D2), each in the `{ ok, data }` envelope, never a JSON-LD root:
11
+ * `{ status: "shown", shownSet }` — a resolved, connected workspace with
12
+ * the `commerce` claim. `shownSet` is the service's parsed result less
13
+ * `workspaceId` and `organizationId`: `productIds`, `recommended`,
14
+ * `offerings`, `state` and `snapshotAt`, as the service answered them.
15
+ * `{ status: "unconnected" }` — render the page content as today: the
16
+ * content adapter is not `database` (the resolver's `not-required`),
17
+ * the licence lacks the claim, or the workspace has no connection or
18
+ * no `WorkspaceOfferings` row.
19
+ * `{ status: "empty" }` — fail closed, show no prices at all: the resolver
20
+ * answered `unresolved` (a refused spoke key, an ambiguous or unmatched
21
+ * host), or the licence is configured but cannot be read.
22
+ * `500 internal_error` — the resolver, the claim read or the first read
23
+ * threw. A refresh never turns an answer into a 500.
24
+ *
25
+ * T7 — an anonymous read never reaches Stripe per request (D6). A snapshot
26
+ * that is not `current`, or is at least `SHOWN_OFFERINGS_REFRESH_AFTER_MS`
27
+ * old, triggers `refreshWorkspaceSnapshot` on its bounded path only: the
28
+ * service joins the Organization's read in flight, reuses a read under a
29
+ * minute old and holds a failed one for a minute. This route never passes
30
+ * the owner's override, keeps no state of its own, and waits at most
31
+ * `SHOWN_OFFERINGS_REFRESH_BUDGET_MS`; a refresh that fails, stalls or
32
+ * throws leaves the first read served. `server.ts` registers it with the
33
+ * Organization's Stripe catalog source (#8922, #9124); registered with no
34
+ * `sourceFor` (D7) it serves the persisted snapshot and never refreshes.
35
+ *
36
+ * The workspace comes only from `resolvePublicWorkspace(request)`, whose one
37
+ * request input is a hub spoke's `x-ailk-spoke-key`; so every answer, the
38
+ * 500 included, appends that header to `Vary`. No `Cache-Control` is set.
39
+ * The claim is read in the handler, not by the `requireCommerceClaim`
40
+ * preHandler, so a refused spoke key answers `empty` rather than a 404 (D4),
41
+ * and the services are imported only after it reads `claimed` (D5).
42
+ *
43
+ * T6 — a log line carries only the resolver's `reason`, a fixed `outcome`,
44
+ * `workspaceId` and an error's class name: never a product or price id, a
45
+ * name, any Stripe text or an error message (D9).
46
+ *
47
+ * Rate limiting is inherited from the server's global content ceiling. No
48
+ * MCP twin, by decision (`tests/parity/README.md`, D8): agents read offerings
49
+ * through `get_pricing` and `get_offerings`, whose HTTP twins answer through
50
+ * this file's `readShownOfferings` (#8933 D1) — the one read of the snapshot
51
+ * every agent surface shares.
52
+ *
53
+ * Anonymous and identity-blind: no `Authorization`, cookie, session or user
54
+ * id is read.
55
+ */
56
+ import type { ShownOfferingsAnswer } from "@working-theory/validation";
57
+ import type {
58
+ FastifyPluginAsync,
59
+ FastifyReply,
60
+ FastifyRequest,
61
+ } from "fastify";
62
+
63
+ import { resolveCommerceClaim } from "../../lib/require-commerce-claim.js";
64
+ import type { OfferingsSourceFor } from "../../services/offerings/index.js";
65
+ import { resolvePublicWorkspace } from "../../services/public-site-resolver.js";
66
+
67
+ /** A snapshot at least this old is refreshed, on the service's own bound. */
68
+ export const SHOWN_OFFERINGS_REFRESH_AFTER_MS = 60_000;
69
+ /** The longest one request waits on a refresh before serving its first read. */
70
+ export const SHOWN_OFFERINGS_REFRESH_BUDGET_MS = 3000;
71
+
72
+ export interface ShownOfferingsRouteOptions {
73
+ /** The Stripe-backed catalog source; without it the route never refreshes. */
74
+ sourceFor?: OfferingsSourceFor;
75
+ now?: () => Date;
76
+ }
77
+
78
+ /** The request header the resolver picks the site's workspace from. */
79
+ const SPOKE_KEY_HEADER = "x-ailk-spoke-key";
80
+
81
+ /** Adds the spoke-key header to `Vary`, keeping every value already there. */
82
+ function varyOnSpokeKey(reply: FastifyReply): void {
83
+ const existing = reply.getHeader("vary");
84
+ const values = (
85
+ Array.isArray(existing) ? existing.join(",") : String(existing ?? "")
86
+ )
87
+ .split(",")
88
+ .map((value) => value.trim())
89
+ .filter((value) => value !== "");
90
+ if (!values.some((value) => value.toLowerCase() === SPOKE_KEY_HEADER)) {
91
+ values.push(SPOKE_KEY_HEADER);
92
+ }
93
+ reply.header("Vary", values.join(", "));
94
+ }
95
+
96
+ /** An error's class name only — never its message, which may carry Stripe text. */
97
+ function errName(err: unknown): string {
98
+ return err instanceof Error ? err.constructor.name : typeof err;
99
+ }
100
+
101
+ const OVER_BUDGET = Symbol("over-budget");
102
+
103
+ /**
104
+ * The read itself (#8933 D1), shared by this route and the two agent twins
105
+ * (`GET /v1/content/pricing` and `GET /v1/content/offerings`): the
106
+ * resolver's arms, the claim gate, the late import and the bounded refresh,
107
+ * answering one of the three answers. It sets no header and writes no reply;
108
+ * a resolver, claim or first-read error rejects. Its log lines go through
109
+ * `request.log`, so a twin's request emits them too.
110
+ */
111
+ export async function readShownOfferings(
112
+ request: FastifyRequest,
113
+ { sourceFor, now: clock = () => new Date() }: ShownOfferingsRouteOptions,
114
+ ): Promise<ShownOfferingsAnswer> {
115
+ const now = clock();
116
+
117
+ const resolution = await resolvePublicWorkspace(request);
118
+ if (resolution.kind === "unresolved") {
119
+ request.log.warn(
120
+ { reason: resolution.reason },
121
+ "[content] shown-offerings: workspace unresolved",
122
+ );
123
+ return { status: "empty" };
124
+ }
125
+ if (resolution.kind === "not-required") {
126
+ return { status: "unconnected" };
127
+ }
128
+
129
+ const claim = await resolveCommerceClaim();
130
+ if (claim === "unclaimed") {
131
+ return { status: "unconnected" };
132
+ }
133
+ if (claim === "undetermined") {
134
+ request.log.warn(
135
+ { outcome: "license_undetermined" },
136
+ "[content] shown-offerings: licence unreadable",
137
+ );
138
+ return { status: "empty" };
139
+ }
140
+
141
+ const { workspaceId } = resolution;
142
+ const { getWorkspaceShownSet, refreshWorkspaceSnapshot } =
143
+ await import("../../services/offerings/index.js");
144
+ let shown = await getWorkspaceShownSet(workspaceId, { now });
145
+ if (shown === null) {
146
+ return { status: "unconnected" };
147
+ }
148
+
149
+ const stale =
150
+ shown.state !== "current" ||
151
+ shown.snapshotAt === null ||
152
+ now.getTime() - Date.parse(shown.snapshotAt) >=
153
+ SHOWN_OFFERINGS_REFRESH_AFTER_MS;
154
+ if (sourceFor && stale) {
155
+ // Caught before the race, so a rejection after the budget is logged
156
+ // the same way and is never unhandled.
157
+ const refresh = refreshWorkspaceSnapshot(workspaceId, sourceFor, {
158
+ now,
159
+ }).catch((err: unknown) => {
160
+ request.log.warn(
161
+ { workspaceId, outcome: "refresh_failed", errName: errName(err) },
162
+ "[content] shown-offerings: refresh failed",
163
+ );
164
+ return null;
165
+ });
166
+ let timer: NodeJS.Timeout | undefined;
167
+ const budget = new Promise<typeof OVER_BUDGET>((resolve) => {
168
+ timer = setTimeout(
169
+ () => resolve(OVER_BUDGET),
170
+ SHOWN_OFFERINGS_REFRESH_BUDGET_MS,
171
+ );
172
+ });
173
+ let outcome: Awaited<typeof refresh> | typeof OVER_BUDGET;
174
+ try {
175
+ outcome = await Promise.race([refresh, budget]);
176
+ } finally {
177
+ clearTimeout(timer);
178
+ }
179
+
180
+ if (outcome === OVER_BUDGET) {
181
+ request.log.warn(
182
+ { workspaceId, outcome: "refresh_over_budget" },
183
+ "[content] shown-offerings: refresh over budget",
184
+ );
185
+ } else if (outcome === "refreshed") {
186
+ try {
187
+ const reread = await getWorkspaceShownSet(workspaceId, { now });
188
+ if (reread === null) {
189
+ return { status: "unconnected" };
190
+ }
191
+ shown = reread;
192
+ } catch (err) {
193
+ request.log.warn(
194
+ { workspaceId, outcome: "reread_failed", errName: errName(err) },
195
+ "[content] shown-offerings: re-read failed",
196
+ );
197
+ }
198
+ }
199
+ }
200
+
201
+ const {
202
+ workspaceId: _workspaceId,
203
+ organizationId: _organizationId,
204
+ ...shownSet
205
+ } = shown;
206
+ return { status: "shown", shownSet };
207
+ }
208
+
209
+ export const shownOfferingsRoute: FastifyPluginAsync<
210
+ ShownOfferingsRouteOptions
211
+ > = async (fastify, options) => {
212
+ fastify.get("/v1/content/shown-offerings", async (request, reply) => {
213
+ varyOnSpokeKey(reply);
214
+
215
+ try {
216
+ const data = await readShownOfferings(request, options);
217
+ return reply.send({ ok: true, data });
218
+ } catch (err) {
219
+ request.log.error(
220
+ { errName: errName(err) },
221
+ "[content] shown-offerings read failed",
222
+ );
223
+ return reply.status(500).send({
224
+ ok: false,
225
+ error: { code: "internal_error", message: "Internal server error" },
226
+ });
227
+ }
228
+ });
229
+ };