create-ailk 0.22.0 → 0.24.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 (287) hide show
  1. package/README.md +27 -14
  2. package/component-catalog.json +149 -5
  3. package/component-catalog.md +7 -6
  4. package/dist/add-module.js +17 -10
  5. package/dist/add-route.d.ts +55 -1
  6. package/dist/add-route.js +301 -13
  7. package/dist/cli.js +27 -10
  8. package/dist/derive-architecture.d.ts +7 -5
  9. package/dist/derive-architecture.js +26 -32
  10. package/dist/lib/design-checks.js +4 -2
  11. package/dist/lib/env-catalog.js +0 -4
  12. package/dist/lib/npm-auth.d.ts +9 -0
  13. package/dist/lib/npm-auth.js +48 -0
  14. package/dist/lib/scaffold-render-sweep.d.ts +36 -2
  15. package/dist/lib/scaffold-render-sweep.js +50 -8
  16. package/dist/module-architecture.js +115 -10
  17. package/dist/paid-sections.d.ts +21 -2
  18. package/dist/paid-sections.js +69 -7
  19. package/dist/seed-flows.d.ts +4 -1
  20. package/dist/seed-flows.js +50 -4
  21. package/dist/spoke-checkout.d.ts +38 -35
  22. package/dist/spoke-checkout.js +66 -229
  23. package/dist/starter-grid.d.ts +0 -3
  24. package/dist/starter-grid.js +24 -14
  25. package/dist/surfaces.js +33 -12
  26. package/dist/sync-routes.d.ts +68 -5
  27. package/dist/sync-routes.js +455 -29
  28. package/dist/template-record.d.ts +1 -1
  29. package/dist/template-record.js +3 -2
  30. package/dist/update.js +10 -0
  31. package/package.json +3 -3
  32. package/site-templates/_base/content/en/NewsletterSignup/newsletter.mdx +4 -49
  33. package/site-templates/_base/content/en/Pricing/pricing.mdx +3 -21
  34. package/site-templates/marketing-site/TEMPLATE-MANIFEST.json +23 -20
  35. package/site-templates/marketing-site/TEMPLATE-MANIFEST.md +28 -14
  36. package/site-templates/marketing-site-free/TEMPLATE-MANIFEST.json +15 -39
  37. package/site-templates/marketing-site-free/TEMPLATE-MANIFEST.md +38 -34
  38. package/site-templates/marketing-site-free/content/en/NewsletterSignup/newsletter.mdx +6 -43
  39. package/site-templates/shapes/local-business-service/TEMPLATE-MANIFEST.json +14 -31
  40. package/site-templates/shapes/local-business-service/TEMPLATE-MANIFEST.md +26 -25
  41. package/site-templates/shapes/local-business-service/content/en/NewsletterSignup/newsletter.mdx +6 -43
  42. package/site-templates/shapes/organization-service/TEMPLATE-MANIFEST.json +14 -31
  43. package/site-templates/shapes/organization-service/TEMPLATE-MANIFEST.md +26 -25
  44. package/site-templates/shapes/organization-service/content/en/NewsletterSignup/newsletter.mdx +6 -43
  45. package/site-templates/shapes/person-service/TEMPLATE-MANIFEST.json +14 -31
  46. package/site-templates/shapes/person-service/TEMPLATE-MANIFEST.md +26 -25
  47. package/site-templates/shapes/person-service/content/en/NewsletterSignup/newsletter.mdx +6 -43
  48. package/templates/.env.example +13 -7
  49. package/templates/.github/workflows/ci.yml +13 -0
  50. package/templates/CLAUDE.md +4 -2
  51. package/templates/README.md +1 -0
  52. package/templates/_gitignore +4 -0
  53. package/templates/apps/api/.env.example +34 -0
  54. package/templates/apps/api/CLAUDE.md +94 -19
  55. package/templates/apps/api/package.json +1 -0
  56. package/templates/apps/api/src/__tests__/factories/in-memory-prisma.ts +2 -0
  57. package/templates/apps/api/src/bin/stripe-connections-rekey.ts +45 -0
  58. package/templates/apps/api/src/config/__tests__/stripe-connection-key.test.ts +185 -0
  59. package/templates/apps/api/src/config/index.ts +109 -0
  60. package/templates/apps/api/src/lib/__mocks__/prisma.ts +7 -1
  61. package/templates/apps/api/src/lib/__tests__/flow-rename-race.db.test.ts +116 -0
  62. package/templates/apps/api/src/lib/__tests__/site.test.ts +16 -0
  63. package/templates/apps/api/src/lib/error-serializer.ts +74 -7
  64. package/templates/apps/api/src/lib/site.ts +4 -1
  65. package/templates/apps/api/src/lib/stripe.ts +77 -4
  66. package/templates/apps/api/src/lib/webhook-idempotency.ts +66 -2
  67. package/templates/apps/api/src/middleware/__tests__/rate-limit.test.ts +218 -0
  68. package/templates/apps/api/src/middleware/__tests__/write-budget.test.ts +174 -0
  69. package/templates/apps/api/src/middleware/rate-limit.ts +226 -4
  70. package/templates/apps/api/src/openapi/__tests__/openapi.test.ts +127 -0
  71. package/templates/apps/api/src/openapi/spec.ts +343 -7
  72. package/templates/apps/api/src/routes/billing/plan-checkout.ts +332 -0
  73. package/templates/apps/api/src/routes/checkout/__tests__/live-key.test.ts +11 -0
  74. package/templates/apps/api/src/routes/checkout/__tests__/offerings-authorization.test.ts +1426 -0
  75. package/templates/apps/api/src/routes/checkout/__tests__/session.test.ts +11 -0
  76. package/templates/apps/api/src/routes/checkout/__tests__/sessions.test.ts +49 -0
  77. package/templates/apps/api/src/routes/checkout/session.ts +57 -25
  78. package/templates/apps/api/src/routes/checkout/sessions.ts +232 -82
  79. package/templates/apps/api/src/routes/consent/__tests__/account.test.ts +5 -5
  80. package/templates/apps/api/src/routes/consent/__tests__/sign-up-rate-limit.test.ts +160 -0
  81. package/templates/apps/api/src/routes/consent/account.ts +4 -2
  82. package/templates/apps/api/src/routes/content/__tests__/get-page.test.ts +2 -2
  83. package/templates/apps/api/src/routes/content/__tests__/offerings.test.ts +731 -0
  84. package/templates/apps/api/src/routes/content/__tests__/pricing.test.ts +753 -0
  85. package/templates/apps/api/src/routes/content/__tests__/shown-offerings.test.ts +762 -0
  86. package/templates/apps/api/src/routes/content/get-page.ts +34 -119
  87. package/templates/apps/api/src/routes/content/index.ts +16 -2
  88. package/templates/apps/api/src/routes/content/list-pages.ts +15 -36
  89. package/templates/apps/api/src/routes/content/offerings.ts +184 -0
  90. package/templates/apps/api/src/routes/content/pricing.ts +176 -0
  91. package/templates/apps/api/src/routes/content/search.ts +16 -45
  92. package/templates/apps/api/src/routes/content/shown-offerings.ts +229 -0
  93. package/templates/apps/api/src/routes/leads/index.ts +377 -308
  94. package/templates/apps/api/src/routes/project-listings/__tests__/me.test.ts +20 -9
  95. package/templates/apps/api/src/routes/project-listings/__tests__/public.test.ts +17 -6
  96. package/templates/apps/api/src/routes/project-listings/__tests__/site-answers.test.ts +1 -1
  97. package/templates/apps/api/src/routes/webhooks/README.md +66 -0
  98. package/templates/apps/api/src/routes/webhooks/__tests__/stripe-flow-checkout.test.ts +1 -0
  99. package/templates/apps/api/src/routes/webhooks/__tests__/stripe-offerings.test.ts +814 -0
  100. package/templates/apps/api/src/routes/webhooks/__tests__/stripe-org-billing.test.ts +80 -68
  101. package/templates/apps/api/src/routes/webhooks/__tests__/stripe-site-filter.test.ts +6 -5
  102. package/templates/apps/api/src/routes/webhooks/__tests__/stripe.test.ts +8 -2
  103. package/templates/apps/api/src/routes/webhooks/index.ts +23 -0
  104. package/templates/apps/api/src/routes/webhooks/stripe-offerings.ts +384 -0
  105. package/templates/apps/api/src/routes/webhooks/stripe.ts +93 -17
  106. package/templates/apps/api/src/server.ts +165 -51
  107. package/templates/apps/api/src/services/__tests__/abandon-email.test.ts +121 -4
  108. package/templates/apps/api/src/services/__tests__/checkout-plan.test.ts +313 -0
  109. package/templates/apps/api/src/services/__tests__/deliverable-fulfillment.test.ts +61 -2
  110. package/templates/apps/api/src/services/__tests__/keyless-workspace-predicate.test.ts +234 -0
  111. package/templates/apps/api/src/services/__tests__/lead-routing.test.ts +374 -44
  112. package/templates/apps/api/src/services/__tests__/person.test.ts +260 -1
  113. package/templates/apps/api/src/services/__tests__/plan-offerings.test.ts +450 -0
  114. package/templates/apps/api/src/services/__tests__/project-listings.counts.test.ts +202 -0
  115. package/templates/apps/api/src/services/__tests__/project-listings.fence.test.ts +15 -18
  116. package/templates/apps/api/src/services/abandon-email.ts +28 -5
  117. package/templates/apps/api/src/services/deliverable-fulfillment.ts +15 -12
  118. package/templates/apps/api/src/services/entitlements.ts +157 -1
  119. package/templates/apps/api/src/services/lead-routing.ts +113 -58
  120. package/templates/apps/api/src/services/offerings/__tests__/catalog.test.ts +348 -0
  121. package/templates/apps/api/src/services/offerings/__tests__/checkout-session-record.test.ts +268 -0
  122. package/templates/apps/api/src/services/offerings/__tests__/connection.test.ts +975 -0
  123. package/templates/apps/api/src/services/offerings/__tests__/fixtures.ts +416 -0
  124. package/templates/apps/api/src/services/offerings/__tests__/org-products.test.ts +400 -0
  125. package/templates/apps/api/src/services/offerings/__tests__/readers.test.ts +685 -0
  126. package/templates/apps/api/src/services/offerings/__tests__/source.test.ts +231 -0
  127. package/templates/apps/api/src/services/offerings/catalog.ts +318 -0
  128. package/templates/apps/api/src/services/offerings/checkout-authorization.ts +403 -0
  129. package/templates/apps/api/src/services/offerings/checkout-session-record.ts +192 -0
  130. package/templates/apps/api/src/services/offerings/connection.ts +1083 -0
  131. package/templates/apps/api/src/services/offerings/index.ts +614 -0
  132. package/templates/apps/api/src/services/offerings/source.ts +140 -0
  133. package/templates/apps/api/src/services/offerings/store.ts +150 -0
  134. package/templates/apps/api/src/services/person.ts +147 -9
  135. package/templates/apps/api/src/services/plan-offerings.ts +96 -30
  136. package/templates/apps/api/src/services/project-listings.ts +43 -31
  137. package/templates/apps/api/src/services/public-site-resolver.ts +19 -14
  138. package/templates/apps/mcp/CLAUDE.md +32 -18
  139. package/templates/apps/mcp/__tests__/app-entry.test.ts +2 -2
  140. package/templates/apps/mcp/__tests__/catalog-drift.test.ts +9 -4
  141. package/templates/apps/mcp/__tests__/get_offerings.test.ts +358 -0
  142. package/templates/apps/mcp/__tests__/get_pricing.test.ts +364 -0
  143. package/templates/apps/mcp/__tests__/http-transport.test.ts +95 -14
  144. package/templates/apps/mcp/__tests__/lib/content-adapter-parity.test.ts +8 -3
  145. package/templates/apps/mcp/__tests__/lib/content-adapter.test.ts +0 -25
  146. package/templates/apps/mcp/__tests__/lib/fail-closed-tools.test.ts +22 -7
  147. package/templates/apps/mcp/__tests__/list_pages.test.ts +84 -44
  148. package/templates/apps/mcp/__tests__/locale.test.ts +41 -56
  149. package/templates/apps/mcp/__tests__/module-exclusion.test.ts +2 -2
  150. package/templates/apps/mcp/__tests__/rate-limit-write.test.ts +189 -0
  151. package/templates/apps/mcp/__tests__/read_content.test.ts +115 -78
  152. package/templates/apps/mcp/__tests__/request_callback.test.ts +63 -128
  153. package/templates/apps/mcp/__tests__/search_content.test.ts +76 -61
  154. package/templates/apps/mcp/__tests__/server.test.ts +13 -11
  155. package/templates/apps/mcp/__tests__/start_purchase.test.ts +208 -12
  156. package/templates/apps/mcp/__tests__/submit_lead.test.ts +82 -167
  157. package/templates/apps/mcp/__tests__/subscribe_newsletter.test.ts +59 -130
  158. package/templates/apps/mcp/__tests__/tools/purchase.test.ts +11 -11
  159. package/templates/apps/mcp/package.json +1 -0
  160. package/templates/apps/mcp/src/abuse/index.ts +18 -11
  161. package/templates/apps/mcp/src/http-transport.ts +47 -9
  162. package/templates/apps/mcp/src/lib/content-adapter.ts +0 -26
  163. package/templates/apps/mcp/src/lib/empty-content-adapter.ts +5 -4
  164. package/templates/apps/mcp/src/lib/shown-offerings.ts +105 -0
  165. package/templates/apps/mcp/src/lib/site-config.ts +53 -0
  166. package/templates/apps/mcp/src/server.ts +5 -0
  167. package/templates/apps/mcp/src/tools/capture_lead.ts +30 -28
  168. package/templates/apps/mcp/src/tools/get_offerings.ts +47 -30
  169. package/templates/apps/mcp/src/tools/get_pricing.ts +40 -40
  170. package/templates/apps/mcp/src/tools/index.ts +22 -21
  171. package/templates/apps/mcp/src/tools/list_pages.ts +27 -33
  172. package/templates/apps/mcp/src/tools/purchase.ts +30 -2
  173. package/templates/apps/mcp/src/tools/read_content.ts +46 -40
  174. package/templates/apps/mcp/src/tools/request_callback.ts +21 -28
  175. package/templates/apps/mcp/src/tools/search_content.ts +20 -24
  176. package/templates/apps/mcp/src/tools/subscribe_newsletter.ts +23 -26
  177. package/templates/apps/mcp/src/workspace-server.ts +15 -0
  178. package/templates/apps/web/.env.example +10 -31
  179. package/templates/apps/web/CLAUDE.md +324 -42
  180. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/agreements-prompt.test.tsx +3 -3
  181. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/layout.test.tsx +3 -3
  182. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/privacy.test.tsx +3 -3
  183. package/templates/apps/web/app/[locale]/careers/[slug]/[action]/page.tsx +189 -0
  184. package/templates/apps/web/app/[locale]/careers/[slug]/apply.actions.ts +4 -2
  185. package/templates/apps/web/app/[locale]/careers/[slug]/job-application-form.ts +8 -3
  186. package/templates/apps/web/app/[locale]/careers/[slug]/page.tsx +22 -144
  187. package/templates/apps/web/app/[locale]/careers/__tests__/apply.actions.test.ts +9 -0
  188. package/templates/apps/web/app/[locale]/careers/__tests__/careers-hub.test.tsx +172 -0
  189. package/templates/apps/web/app/[locale]/careers/__tests__/careers-set.test.tsx +149 -0
  190. package/templates/apps/web/app/[locale]/careers/__tests__/job-application-form.test.ts +22 -24
  191. package/templates/apps/web/app/[locale]/careers/__tests__/job-apply-page.test.tsx +140 -66
  192. package/templates/apps/web/app/[locale]/careers/__tests__/page-renderer-migration.test.tsx +57 -22
  193. package/templates/apps/web/app/[locale]/careers/page.tsx +129 -5
  194. package/templates/apps/web/app/[locale]/contact/__tests__/ConversationalIntakeWrapper.test.tsx +1 -1
  195. package/templates/apps/web/app/[locale]/contact/__tests__/contact-magnet-page.test.tsx +119 -11
  196. package/templates/apps/web/app/[locale]/contact/__tests__/contact.actions.test.ts +28 -5
  197. package/templates/apps/web/app/[locale]/contact/contact.actions.ts +20 -6
  198. package/templates/apps/web/app/[locale]/contact/intake-script.ts +1 -1
  199. package/templates/apps/web/app/[locale]/contact/page.tsx +99 -92
  200. package/templates/apps/web/app/[locale]/flows/[slug]/FlowStepperClient.tsx +237 -5
  201. package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/FlowStepperClient.count.test.tsx +43 -0
  202. package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/FlowStepperClient.deliverable.test.tsx +200 -0
  203. package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/FlowStepperClient.ending.test.tsx +197 -0
  204. package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/magnet-page.test.tsx +430 -0
  205. package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/two-route-tool.test.tsx +21 -9
  206. package/templates/apps/web/app/[locale]/flows/[slug]/magnet-page.tsx +369 -0
  207. package/templates/apps/web/app/[locale]/flows/[slug]/page.tsx +12 -73
  208. package/templates/apps/web/app/[locale]/flows/[slug]/start/page.tsx +10 -31
  209. package/templates/apps/web/app/[locale]/layout.tsx +55 -4
  210. package/templates/apps/web/app/[locale]/newsletter/__tests__/page.test.tsx +174 -104
  211. package/templates/apps/web/app/[locale]/newsletter/page.tsx +95 -58
  212. package/templates/apps/web/app/[locale]/pricing/__tests__/__snapshots__/unconnected.test.tsx.snap +7 -0
  213. package/templates/apps/web/app/[locale]/pricing/__tests__/offerings.test.tsx +599 -0
  214. package/templates/apps/web/app/[locale]/pricing/__tests__/page.test.tsx +216 -0
  215. package/templates/apps/web/app/[locale]/pricing/__tests__/unconnected.test.tsx +236 -0
  216. package/templates/apps/web/app/[locale]/pricing/page.tsx +367 -6
  217. package/templates/apps/web/app/[locale]/team/__tests__/team-routes.test.tsx +4 -1
  218. package/templates/apps/web/app/[locale]/unsubscribe/__tests__/unsubscribe-rsc-boundary.test.tsx +17 -0
  219. package/templates/apps/web/app/[locale]/unsubscribe/__tests__/unsubscribe.test.tsx +62 -3
  220. package/templates/apps/web/app/[locale]/unsubscribe/page.tsx +70 -18
  221. package/templates/apps/web/app/[locale]/unsubscribe/unsubscribe-button.tsx +30 -9
  222. package/templates/apps/web/app/api/offerings/checkout/[lookupKey]/route.ts +316 -0
  223. package/templates/apps/web/app/api/offerings/checkout/__tests__/route.test.ts +810 -0
  224. package/templates/apps/web/lib/__tests__/auth-routes.test.ts +27 -1
  225. package/templates/apps/web/lib/__tests__/deck-page.test.ts +2 -1
  226. package/templates/apps/web/lib/__tests__/in-page-magnet.test.ts +265 -0
  227. package/templates/apps/web/lib/__tests__/magnet-routes.test.ts +64 -0
  228. package/templates/apps/web/lib/__tests__/newsletter.actions.test.ts +293 -0
  229. package/templates/apps/web/lib/__tests__/offerings-pricing.test.ts +601 -0
  230. package/templates/apps/web/lib/__tests__/structured-data.test.tsx +67 -8
  231. package/templates/apps/web/lib/auth-routes.ts +36 -2
  232. package/templates/apps/web/lib/checkout-config.ts +9 -20
  233. package/templates/apps/web/lib/deck-page.ts +1 -0
  234. package/templates/apps/web/lib/deliverable-grant.ts +18 -0
  235. package/templates/apps/web/lib/in-page-magnet.ts +416 -0
  236. package/templates/apps/web/lib/magnet-routes.ts +44 -0
  237. package/templates/apps/web/lib/modules.generated.ts +9 -0
  238. package/templates/apps/web/lib/newsletter.actions.ts +205 -0
  239. package/templates/apps/web/lib/offerings-pricing.ts +326 -0
  240. package/templates/apps/web/lib/posting-title.ts +17 -0
  241. package/templates/apps/web/lib/sign-up-agreements.ts +4 -2
  242. package/templates/apps/web/messages/en.json +49 -15
  243. package/templates/apps/web/middleware.ts +12 -2
  244. package/templates/apps/web/security-headers.config.ts +17 -0
  245. package/templates/content/en/BlogList/blog.mdx +4 -71
  246. package/templates/content/en/BookCall/book-a-call.mdx +1 -41
  247. package/templates/content/en/BookCall/onsite-estimate.mdx +1 -17
  248. package/templates/content/en/BookCall/onsite-service.mdx +1 -17
  249. package/templates/content/en/BookCall/start-project.mdx +1 -17
  250. package/templates/content/en/ContactPage/contact.mdx +6 -63
  251. package/templates/content/en/HomePage/home.mdx +3 -21
  252. package/templates/database/CHANGELOG.md +51 -0
  253. package/templates/database/__tests__/in-page-magnets-migration.test.ts +161 -0
  254. package/templates/database/__tests__/offerings-checkout-session.db.test.ts +270 -0
  255. package/templates/database/__tests__/offerings-migration.test.ts +197 -0
  256. package/templates/database/__tests__/offerings-shown-price-ids-migration.test.ts +86 -0
  257. package/templates/database/__tests__/offerings.db.test.ts +303 -0
  258. package/templates/database/__tests__/seed.test.ts +63 -1
  259. package/templates/database/__tests__/trial-magnet-migration.test.ts +186 -0
  260. package/templates/database/auth/schema.prisma +4 -0
  261. package/templates/database/config/schema.prisma +91 -0
  262. package/templates/database/migrations/20261020120000_offerings_data_model/migration.sql +146 -0
  263. package/templates/database/migrations/20261021120000_offerings_checkout_session/migration.sql +77 -0
  264. package/templates/database/migrations/20261022120000_in_page_magnets/migration.sql +45 -0
  265. package/templates/database/migrations/20261023120000_offerings_shown_price_ids/migration.sql +47 -0
  266. package/templates/database/migrations/20261024120000_organization_plan_checkout_session/migration.sql +16 -0
  267. package/templates/database/migrations/20261025120000_trial_magnet/migration.sql +28 -0
  268. package/templates/database/migrations/20261026120000_trial_magnet_proof_line/migration.sql +23 -0
  269. package/templates/database/package.json +1 -1
  270. package/templates/database/seed.ts +57 -2
  271. package/templates/tools/lint-architecture.ts +205 -1
  272. package/versions.json +35 -35
  273. package/site-templates/marketing-site-free/content/en/Pricing/pricing.mdx +0 -199
  274. package/templates/apps/api/src/routes/content/slug.ts +0 -9
  275. package/templates/apps/web/app/[locale]/downloads/__tests__/page-renderer-migration.test.tsx +0 -93
  276. package/templates/apps/web/app/[locale]/downloads/page.tsx +0 -37
  277. package/templates/apps/web/app/[locale]/newsletter/__tests__/newsletter.actions.test.ts +0 -139
  278. package/templates/apps/web/app/[locale]/newsletter/newsletter.actions.ts +0 -93
  279. package/templates/apps/web/app/api/checkout/[offering]/route.ts +0 -48
  280. package/templates/apps/web/app/api/checkout/__tests__/route.test.ts +0 -120
  281. package/templates/apps/web/app/api/checkout/__tests__/success-path.test.ts +0 -86
  282. package/templates/apps/web/app/api/webhooks/stripe/__tests__/route.test.ts +0 -92
  283. package/templates/apps/web/app/api/webhooks/stripe/route.ts +0 -31
  284. package/templates/apps/web/lib/__tests__/checkout.test.ts +0 -243
  285. package/templates/apps/web/lib/__tests__/meeting-slugs.test.ts +0 -120
  286. package/templates/apps/web/lib/checkout.ts +0 -93
  287. package/templates/apps/web/lib/meeting-slugs.ts +0 -63
@@ -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
+ };
@@ -7,11 +7,12 @@
7
7
  * parity contract in the root CLAUDE.md. Until this route existed the parity
8
8
  * was one-sided, the tool having no endpoint to map to.
9
9
  *
10
- * Query:
11
- * q required, 1..200 chars — the search string. The ceiling matches
12
- * the `search_content` MCP tool's own cap (`searchContentInputSchema`)
13
- * so the pair rejects the same inputs, and bounds the work an
14
- * unauthenticated caller can ask of the scorer per request.
10
+ * Query — parsed with `contentSearchQuerySchema` (`@working-theory/validation`),
11
+ * the export the `search_content` MCP tool parses with too, so the pair
12
+ * accepts and rejects the same inputs (#7167):
13
+ * q required, 1..200 chars — the search string. The ceiling bounds
14
+ * the work an unauthenticated caller can ask of the scorer per
15
+ * request.
15
16
  * type optional — a schema.org page type
16
17
  * category optional — a LEAF slug from the site-category registry. Outside
17
18
  * the registry is a 400, not an empty result: the registry is
@@ -26,10 +27,10 @@
26
27
  * ordering is belt-and-braces, and `/v1/content/types` is the same shape that
27
28
  * already proves it.
28
29
  *
29
- * The response is an `ItemList` JSON-LD document. `items` is the adapter's own
30
- * `SearchResult[]`, unreshaped: a caller comparing this route against the MCP
31
- * tool must see the same objects, and a projection here would be the place
32
- * they silently diverged.
30
+ * The response is an `ItemList` JSON-LD document, built by
31
+ * `searchContentItemList` in `@working-theory/content-adapters` — the shared
32
+ * seam the MCP tool answers through, so the pair cannot diverge. `items` is
33
+ * the adapter's own `SearchResult[]`, unreshaped.
33
34
  *
34
35
  * Rate limiting is inherited: `server.ts` registers the limiter GLOBALLY with
35
36
  * the content ceiling (`rate-limit.ts`'s `CONTENT_RATE_LIMIT_UNAUTH` /
@@ -46,30 +47,13 @@
46
47
  * carries no detail an unauthenticated caller could use to tell it apart
47
48
  * from "nothing matched" (AC-WCE-05).
48
49
  */
49
- import {
50
- SCHEMA_ORG_TYPES,
51
- type SearchOptions,
52
- } from "@working-theory/content-adapters";
53
- import { CategorySlugSchema } from "@working-theory/schema/categories";
50
+ import { searchContentItemList } from "@working-theory/content-adapters";
51
+ import { contentSearchQuerySchema } from "@working-theory/validation";
54
52
  import type { FastifyPluginAsync } from "fastify";
55
- import { z } from "zod";
56
53
 
57
54
  import { resolveLocale } from "../../lib/locales.js";
58
55
  import { resolvePublicContentAdapter } from "../../services/public-site-resolver.js";
59
56
 
60
- const LIMIT_MAX = 50;
61
- const LIMIT_DEFAULT = 10;
62
- /** Mirrors `searchContentInputSchema`'s `query` cap — the pair rejects alike. */
63
- const QUERY_MAX = 200;
64
-
65
- const querySchema = z.object({
66
- q: z.string().min(1).max(QUERY_MAX),
67
- type: z.enum(SCHEMA_ORG_TYPES).optional(),
68
- category: CategorySlugSchema.optional(),
69
- limit: z.coerce.number().int().min(1).max(LIMIT_MAX).default(LIMIT_DEFAULT),
70
- locale: z.string().optional(),
71
- });
72
-
73
57
  export const searchContentRoute: FastifyPluginAsync = async (fastify) => {
74
58
  fastify.get<{
75
59
  Querystring: {
@@ -80,7 +64,7 @@ export const searchContentRoute: FastifyPluginAsync = async (fastify) => {
80
64
  locale?: string;
81
65
  };
82
66
  }>("/v1/content/search", async (request, reply) => {
83
- const query = querySchema.safeParse(request.query);
67
+ const query = contentSearchQuerySchema.safeParse(request.query);
84
68
  if (!query.success) {
85
69
  return reply.status(400).send({
86
70
  error: "Invalid query parameters",
@@ -91,13 +75,6 @@ export const searchContentRoute: FastifyPluginAsync = async (fastify) => {
91
75
  const { q, type, category, limit } = query.data;
92
76
  const locale = resolveLocale(query.data.locale);
93
77
 
94
- const options: SearchOptions = {
95
- limit,
96
- ...(type !== undefined && { type }),
97
- ...(category !== undefined && { category }),
98
- locale,
99
- };
100
-
101
78
  try {
102
79
  // Site resolution precedes any content query (#5852, #5910). A refusal
103
80
  // is a 404 sharing the same "Page not found" error string a
@@ -112,15 +89,9 @@ export const searchContentRoute: FastifyPluginAsync = async (fastify) => {
112
89
  });
113
90
  }
114
91
 
115
- const items = await adapter.searchPages(q, options);
116
-
117
- return reply.send({
118
- "@context": "https://schema.org",
119
- "@type": "ItemList",
120
- query: q,
121
- items,
122
- totalItems: items.length,
123
- });
92
+ return reply.send(
93
+ await searchContentItemList(adapter, { q, type, category, limit, locale }),
94
+ );
124
95
  } catch (error) {
125
96
  request.log.error({ err: error }, "[Content] searchPages failed");
126
97
  return reply.status(500).send({ error: "Internal server error" });
@@ -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
+ };