create-ailk 0.23.0 → 0.25.1

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 (604) hide show
  1. package/README.md +68 -33
  2. package/component-catalog.json +3 -3
  3. package/component-catalog.md +3 -3
  4. package/dist/add-module.js +10 -3
  5. package/dist/add-route.d.ts +12 -1
  6. package/dist/add-route.js +38 -4
  7. package/dist/cli.js +12 -7
  8. package/dist/derive-architecture.d.ts +3 -4
  9. package/dist/derive-architecture.js +75 -22
  10. package/dist/lib/design-checks.d.ts +9 -4
  11. package/dist/lib/design-checks.js +13 -7
  12. package/dist/lib/extract-module-bundle.js +29 -2
  13. package/dist/lib/fetch-template-snapshot.d.ts +1 -1
  14. package/dist/lib/fetch-template-snapshot.js +7 -3
  15. package/dist/lib/import-graph.d.ts +1 -1
  16. package/dist/lib/import-graph.js +4 -4
  17. package/dist/lib/module-license-gate.d.ts +12 -1
  18. package/dist/lib/module-license-gate.js +34 -12
  19. package/dist/lib/scaffold-render-sweep.d.ts +33 -0
  20. package/dist/lib/scaffold-render-sweep.js +45 -0
  21. package/dist/module-architecture.d.ts +20 -3
  22. package/dist/module-architecture.js +122 -538
  23. package/dist/paid-sections.d.ts +25 -1
  24. package/dist/paid-sections.js +88 -3
  25. package/dist/surfaces.js +10 -2
  26. package/dist/sync-routes.d.ts +30 -4
  27. package/dist/sync-routes.js +271 -18
  28. package/dist/template-record.d.ts +14 -4
  29. package/dist/template-record.js +23 -5
  30. package/dist/topology.d.ts +16 -3
  31. package/dist/topology.js +31 -19
  32. package/dist/update.d.ts +10 -1
  33. package/dist/update.js +540 -16
  34. package/package.json +3 -3
  35. package/release-scope.json +1 -1
  36. package/templates/.claude/cloudparity-repo-hooks.json +5 -0
  37. package/templates/.claude/hooks/template-guard.sh +137 -0
  38. package/templates/.claude/rules/extending.md +106 -0
  39. package/templates/.claude/rules/loop-contract.md +2 -2
  40. package/templates/.claude/settings.json +11 -0
  41. package/templates/.env.example +9 -5
  42. package/templates/.github/workflows/ci.yml +7 -4
  43. package/templates/CLAUDE.md +15 -3
  44. package/templates/CONVENTIONS.md +8 -10
  45. package/templates/README.md +14 -13
  46. package/templates/apps/api/.env.example +9 -2
  47. package/templates/apps/api/CLAUDE.md +122 -82
  48. package/templates/apps/api/jest.config.cjs +15 -5
  49. package/templates/apps/api/package.json +16 -20
  50. package/templates/apps/api/src/__tests__/trusted-origins.server.test.ts +2 -2
  51. package/templates/apps/api/src/__tests__/vercel-handler.test.ts +4 -4
  52. package/templates/apps/api/src/index.ts +1 -1
  53. package/templates/apps/api/src/lib/__mocks__/prisma.ts +7 -4
  54. package/templates/apps/api/src/modules/commerce.ts +10 -0
  55. package/templates/apps/api/src/modules/content-write.ts +10 -0
  56. package/templates/apps/api/src/modules/multi-tenant.ts +10 -0
  57. package/templates/apps/api/src/modules/scheduling.ts +10 -0
  58. package/templates/apps/api/src/modules/signal-collectors.ts +10 -0
  59. package/templates/apps/api/src/modules/workspace.ts +10 -0
  60. package/templates/apps/api/src/server.ts +117 -1857
  61. package/templates/apps/api/vercel.json +2 -2
  62. package/templates/apps/mcp/CLAUDE.md +77 -24
  63. package/templates/apps/mcp/__tests__/app-entry.test.ts +4 -254
  64. package/templates/apps/mcp/__tests__/boot-file.test.ts +92 -0
  65. package/templates/apps/mcp/jest.config.cjs +6 -1
  66. package/templates/apps/mcp/package.json +5 -12
  67. package/templates/apps/mcp/src/app.ts +8 -7
  68. package/templates/apps/mcp/src/index.ts +6 -34
  69. package/templates/apps/mcp/src/lib/paid-tools.generated.ts +10 -0
  70. package/templates/apps/mcp/src/lib/topology.generated.ts +2 -2
  71. package/templates/apps/mcp/src/site.ts +12 -0
  72. package/templates/apps/web/.env.example +1 -1
  73. package/templates/apps/web/CLAUDE.md +21 -5
  74. package/templates/apps/web/app/.well-known/mcp.json/route.ts +9 -3
  75. package/templates/apps/web/app/[locale]/contact/__tests__/ConversationalIntakeWrapper.test.tsx +1 -1
  76. package/templates/apps/web/app/[locale]/contact/contact.actions.ts +14 -4
  77. package/templates/apps/web/app/[locale]/contact/intake-analytics.ts +1 -1
  78. package/templates/apps/web/app/[locale]/contact/intake-script.ts +1 -1
  79. package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/magnet-page.test.tsx +22 -1
  80. package/templates/apps/web/app/[locale]/flows/[slug]/magnet-page.tsx +28 -7
  81. package/templates/apps/web/app/[locale]/pricing/__tests__/unconnected.test.tsx +43 -0
  82. package/templates/apps/web/app/[locale]/pricing/page.tsx +7 -3
  83. package/templates/apps/web/app/api/offerings/checkout/[lookupKey]/__tests__/route.test.ts +222 -0
  84. package/templates/apps/web/app/api/offerings/checkout/[lookupKey]/route.ts +10 -3
  85. package/templates/apps/web/app/api/revalidate/route.ts +3 -3
  86. package/templates/apps/web/auth.ts +2 -2
  87. package/templates/apps/web/jest.config.cjs +1 -0
  88. package/templates/apps/web/lib/__tests__/magnet-routes.test.ts +7 -0
  89. package/templates/apps/web/lib/auth-email.ts +1 -1
  90. package/templates/apps/web/lib/magnet-routes.ts +3 -1
  91. package/templates/apps/web/lib/newsletter.actions.ts +9 -6
  92. package/templates/apps/web/lib/relay.ts +2 -2
  93. package/templates/apps/web/lib/release-scope.ts +47 -0
  94. package/templates/apps/web/lib/server-api.ts +1 -1
  95. package/templates/apps/web/src/lib/commerce-claim.ts +1 -1
  96. package/templates/customizations.yaml +37 -0
  97. package/templates/database/prisma.config.ts +10 -14
  98. package/templates/database/seed-test.ts +2 -2
  99. package/templates/database/seed.ts +32 -5
  100. package/templates/package.json +12 -6
  101. package/templates/pnpm-workspace.yaml +0 -1
  102. package/templates/project.yaml +16 -8
  103. package/templates/tools/jest/reporters.cjs +65 -0
  104. package/templates/tools/lint-architecture.ts +757 -7
  105. package/templates/tsconfig.json +1 -2
  106. package/versions.json +48 -35
  107. package/templates/apps/api/src/__tests__/commerce-claim-registration.test.ts +0 -409
  108. package/templates/apps/api/src/__tests__/factories/agent-caller.ts +0 -102
  109. package/templates/apps/api/src/__tests__/factories/content-fixture.ts +0 -138
  110. package/templates/apps/api/src/__tests__/factories/in-memory-prisma.ts +0 -441
  111. package/templates/apps/api/src/__tests__/factories/index.ts +0 -70
  112. package/templates/apps/api/src/__tests__/factories/lead-fixture.ts +0 -82
  113. package/templates/apps/api/src/__tests__/leads-forwarded-rate-limit.test.ts +0 -135
  114. package/templates/apps/api/src/__tests__/services/enrichment-shim.test.ts +0 -126
  115. package/templates/apps/api/src/__tests__/stripe-boot.test.ts +0 -132
  116. package/templates/apps/api/src/__tests__/support/hub-sign-in-fake-db.ts +0 -362
  117. package/templates/apps/api/src/bin/__tests__/rate-limit-probe.test.ts +0 -184
  118. package/templates/apps/api/src/bin/abandon-sweep.ts +0 -42
  119. package/templates/apps/api/src/bin/rate-limit-probe.ts +0 -53
  120. package/templates/apps/api/src/bin/spokes.ts +0 -198
  121. package/templates/apps/api/src/bin/stripe-connections-rekey.ts +0 -45
  122. package/templates/apps/api/src/config/__tests__/hub-require-spoke-key.test.ts +0 -196
  123. package/templates/apps/api/src/config/__tests__/index.test.ts +0 -233
  124. package/templates/apps/api/src/config/__tests__/modules.test.ts +0 -76
  125. package/templates/apps/api/src/config/__tests__/stripe-connection-key.test.ts +0 -185
  126. package/templates/apps/api/src/config/__tests__/trusted-origins.test.ts +0 -238
  127. package/templates/apps/api/src/config/index.ts +0 -596
  128. package/templates/apps/api/src/config/modules.ts +0 -83
  129. package/templates/apps/api/src/lib/__tests__/agent-store.test.ts +0 -581
  130. package/templates/apps/api/src/lib/__tests__/auth-email-budget.test.ts +0 -143
  131. package/templates/apps/api/src/lib/__tests__/consent-ledger-double.ts +0 -237
  132. package/templates/apps/api/src/lib/__tests__/consent-store.test.ts +0 -353
  133. package/templates/apps/api/src/lib/__tests__/content-adapter.test.ts +0 -201
  134. package/templates/apps/api/src/lib/__tests__/deliverable-asset-store.test.ts +0 -224
  135. package/templates/apps/api/src/lib/__tests__/error-serializer.test.ts +0 -120
  136. package/templates/apps/api/src/lib/__tests__/errors.test.ts +0 -94
  137. package/templates/apps/api/src/lib/__tests__/file-fallback.test.ts +0 -144
  138. package/templates/apps/api/src/lib/__tests__/fixtures/HomePage/home.mdx +0 -8
  139. package/templates/apps/api/src/lib/__tests__/flow-completion-store.test.ts +0 -149
  140. package/templates/apps/api/src/lib/__tests__/flow-rename-race.db.test.ts +0 -116
  141. package/templates/apps/api/src/lib/__tests__/hub-sign-in-store.test.ts +0 -209
  142. package/templates/apps/api/src/lib/__tests__/lead-capture-store.test.ts +0 -257
  143. package/templates/apps/api/src/lib/__tests__/lead-delivery.test.ts +0 -96
  144. package/templates/apps/api/src/lib/__tests__/outbound-http.test.ts +0 -125
  145. package/templates/apps/api/src/lib/__tests__/prisma.test.ts +0 -165
  146. package/templates/apps/api/src/lib/__tests__/require-commerce-claim.test.ts +0 -317
  147. package/templates/apps/api/src/lib/__tests__/require-paid-tier.test.ts +0 -129
  148. package/templates/apps/api/src/lib/__tests__/site.test.ts +0 -292
  149. package/templates/apps/api/src/lib/__tests__/slice-load.test.ts +0 -89
  150. package/templates/apps/api/src/lib/__tests__/spoke-store.test.ts +0 -202
  151. package/templates/apps/api/src/lib/__tests__/stripe-admission.test.ts +0 -217
  152. package/templates/apps/api/src/lib/__tests__/stripe.test.ts +0 -82
  153. package/templates/apps/api/src/lib/agent-store.ts +0 -613
  154. package/templates/apps/api/src/lib/auth-email-budget.ts +0 -161
  155. package/templates/apps/api/src/lib/consent-store.ts +0 -363
  156. package/templates/apps/api/src/lib/content-adapter.ts +0 -112
  157. package/templates/apps/api/src/lib/deliverable-asset-store.ts +0 -96
  158. package/templates/apps/api/src/lib/error-serializer.ts +0 -164
  159. package/templates/apps/api/src/lib/errors.ts +0 -95
  160. package/templates/apps/api/src/lib/file-fallback.ts +0 -87
  161. package/templates/apps/api/src/lib/flow-completion-store.ts +0 -136
  162. package/templates/apps/api/src/lib/hub-sign-in-store.ts +0 -455
  163. package/templates/apps/api/src/lib/lead-capture-store.ts +0 -122
  164. package/templates/apps/api/src/lib/lead-delivery.ts +0 -52
  165. package/templates/apps/api/src/lib/license-key-store.ts +0 -45
  166. package/templates/apps/api/src/lib/locales.ts +0 -201
  167. package/templates/apps/api/src/lib/outbound-http.ts +0 -127
  168. package/templates/apps/api/src/lib/prisma.ts +0 -21
  169. package/templates/apps/api/src/lib/proposal-paid-store.ts +0 -66
  170. package/templates/apps/api/src/lib/rate-limit-probe.ts +0 -165
  171. package/templates/apps/api/src/lib/rate-limit-store.ts +0 -142
  172. package/templates/apps/api/src/lib/require-commerce-claim.ts +0 -250
  173. package/templates/apps/api/src/lib/require-paid-tier.ts +0 -53
  174. package/templates/apps/api/src/lib/site.ts +0 -254
  175. package/templates/apps/api/src/lib/slice-load.ts +0 -90
  176. package/templates/apps/api/src/lib/spoke-store.ts +0 -180
  177. package/templates/apps/api/src/lib/stripe.ts +0 -318
  178. package/templates/apps/api/src/lib/webhook-idempotency.ts +0 -156
  179. package/templates/apps/api/src/middleware/__tests__/adversarial/bearer-token-format.test.ts +0 -111
  180. package/templates/apps/api/src/middleware/__tests__/adversarial/cookie-or-bearer-precedence.test.ts +0 -172
  181. package/templates/apps/api/src/middleware/__tests__/adversarial/csrf-bearer-skip.test.ts +0 -119
  182. package/templates/apps/api/src/middleware/__tests__/adversarial/csrf-cookie-path.test.ts +0 -138
  183. package/templates/apps/api/src/middleware/__tests__/adversarial/csrf-trusted-origins.test.ts +0 -142
  184. package/templates/apps/api/src/middleware/__tests__/adversarial/session-fixation.test.ts +0 -155
  185. package/templates/apps/api/src/middleware/__tests__/adversarial/session-timeout.test.ts +0 -139
  186. package/templates/apps/api/src/middleware/__tests__/auth.bearer-path.test.ts +0 -562
  187. package/templates/apps/api/src/middleware/__tests__/auth.both-present-precedence.test.ts +0 -76
  188. package/templates/apps/api/src/middleware/__tests__/auth.cookie-path.test.ts +0 -220
  189. package/templates/apps/api/src/middleware/__tests__/auth.database-not-configured.test.ts +0 -97
  190. package/templates/apps/api/src/middleware/__tests__/auth.hub-session-path.test.ts +0 -557
  191. package/templates/apps/api/src/middleware/__tests__/auth.neither-present.test.ts +0 -72
  192. package/templates/apps/api/src/middleware/__tests__/auth.optional-cookie.test.ts +0 -140
  193. package/templates/apps/api/src/middleware/__tests__/default-tenant.test.ts +0 -721
  194. package/templates/apps/api/src/middleware/__tests__/rate-limit-cross-isolate.db.test.ts +0 -220
  195. package/templates/apps/api/src/middleware/__tests__/rate-limit-store.test.ts +0 -430
  196. package/templates/apps/api/src/middleware/__tests__/rate-limit.test.ts +0 -1409
  197. package/templates/apps/api/src/middleware/__tests__/write-budget.test.ts +0 -174
  198. package/templates/apps/api/src/middleware/auth.ts +0 -864
  199. package/templates/apps/api/src/middleware/default-tenant.ts +0 -166
  200. package/templates/apps/api/src/middleware/rate-limit.ts +0 -983
  201. package/templates/apps/api/src/openapi/__tests__/openapi.test.ts +0 -264
  202. package/templates/apps/api/src/openapi/__tests__/spec-identity.test.ts +0 -182
  203. package/templates/apps/api/src/openapi/index.ts +0 -18
  204. package/templates/apps/api/src/openapi/spec.ts +0 -1815
  205. package/templates/apps/api/src/openapi/surface-drift.ts +0 -195
  206. package/templates/apps/api/src/routes/aeo/__tests__/index.test.ts +0 -175
  207. package/templates/apps/api/src/routes/aeo/index.ts +0 -107
  208. package/templates/apps/api/src/routes/auth/__tests__/auth-tokens.functional.test.ts +0 -196
  209. package/templates/apps/api/src/routes/auth/__tests__/auth-user.functional.test.ts +0 -249
  210. package/templates/apps/api/src/routes/auth/__tests__/hub-sign-in.test.ts +0 -532
  211. package/templates/apps/api/src/routes/auth/__tests__/tokens.test.ts +0 -313
  212. package/templates/apps/api/src/routes/auth/__tests__/transactional-email.test.ts +0 -413
  213. package/templates/apps/api/src/routes/auth/__tests__/user.test.ts +0 -609
  214. package/templates/apps/api/src/routes/auth/hub-sign-in.ts +0 -242
  215. package/templates/apps/api/src/routes/auth/tokens.ts +0 -211
  216. package/templates/apps/api/src/routes/auth/transactional-email.ts +0 -301
  217. package/templates/apps/api/src/routes/auth/user.ts +0 -305
  218. package/templates/apps/api/src/routes/billing/plan-checkout.ts +0 -325
  219. package/templates/apps/api/src/routes/checkout/__tests__/live-key.test.ts +0 -178
  220. package/templates/apps/api/src/routes/checkout/__tests__/offerings-authorization.test.ts +0 -1300
  221. package/templates/apps/api/src/routes/checkout/__tests__/session.test.ts +0 -448
  222. package/templates/apps/api/src/routes/checkout/__tests__/sessions.test.ts +0 -1742
  223. package/templates/apps/api/src/routes/checkout/index.ts +0 -34
  224. package/templates/apps/api/src/routes/checkout/session.ts +0 -171
  225. package/templates/apps/api/src/routes/checkout/sessions.ts +0 -540
  226. package/templates/apps/api/src/routes/consent/__tests__/account.test.ts +0 -386
  227. package/templates/apps/api/src/routes/consent/__tests__/sign-up-rate-limit.test.ts +0 -160
  228. package/templates/apps/api/src/routes/consent/account.ts +0 -268
  229. package/templates/apps/api/src/routes/consent/cookie.ts +0 -90
  230. package/templates/apps/api/src/routes/consent/index.ts +0 -26
  231. package/templates/apps/api/src/routes/consent/unsubscribe.ts +0 -127
  232. package/templates/apps/api/src/routes/content/__tests__/get-page.test.ts +0 -853
  233. package/templates/apps/api/src/routes/content/__tests__/list-pages.test.ts +0 -230
  234. package/templates/apps/api/src/routes/content/__tests__/list-types.test.ts +0 -44
  235. package/templates/apps/api/src/routes/content/__tests__/locale.test.ts +0 -118
  236. package/templates/apps/api/src/routes/content/__tests__/offerings.test.ts +0 -731
  237. package/templates/apps/api/src/routes/content/__tests__/pricing.test.ts +0 -753
  238. package/templates/apps/api/src/routes/content/__tests__/rate-limit.test.ts +0 -51
  239. package/templates/apps/api/src/routes/content/__tests__/search.test.ts +0 -450
  240. package/templates/apps/api/src/routes/content/__tests__/shown-offerings.test.ts +0 -762
  241. package/templates/apps/api/src/routes/content/get-page.ts +0 -268
  242. package/templates/apps/api/src/routes/content/index.ts +0 -49
  243. package/templates/apps/api/src/routes/content/list-pages.ts +0 -95
  244. package/templates/apps/api/src/routes/content/list-types.ts +0 -19
  245. package/templates/apps/api/src/routes/content/offerings.ts +0 -184
  246. package/templates/apps/api/src/routes/content/pricing.ts +0 -176
  247. package/templates/apps/api/src/routes/content/rate-limit.ts +0 -22
  248. package/templates/apps/api/src/routes/content/search.ts +0 -129
  249. package/templates/apps/api/src/routes/content/shown-offerings.ts +0 -229
  250. package/templates/apps/api/src/routes/content/slug.ts +0 -9
  251. package/templates/apps/api/src/routes/leads/__tests__/capture.test.ts +0 -88
  252. package/templates/apps/api/src/routes/leads/__tests__/list.test.ts +0 -171
  253. package/templates/apps/api/src/routes/leads/__tests__/magnet-completion.test.ts +0 -515
  254. package/templates/apps/api/src/routes/leads/__tests__/spoke.test.ts +0 -392
  255. package/templates/apps/api/src/routes/leads/__tests__/track.test.ts +0 -165
  256. package/templates/apps/api/src/routes/leads/index.ts +0 -573
  257. package/templates/apps/api/src/routes/leads/list.ts +0 -104
  258. package/templates/apps/api/src/routes/project-listings/__tests__/configured-application.test.ts +0 -626
  259. package/templates/apps/api/src/routes/project-listings/__tests__/drafts.test.ts +0 -1268
  260. package/templates/apps/api/src/routes/project-listings/__tests__/founder-identity.test.ts +0 -847
  261. package/templates/apps/api/src/routes/project-listings/__tests__/me.test.ts +0 -480
  262. package/templates/apps/api/src/routes/project-listings/__tests__/public.test.ts +0 -465
  263. package/templates/apps/api/src/routes/project-listings/__tests__/resume-email.test.ts +0 -872
  264. package/templates/apps/api/src/routes/project-listings/__tests__/site-answers.test.ts +0 -1022
  265. package/templates/apps/api/src/routes/project-listings/__tests__/site-key.test.ts +0 -484
  266. package/templates/apps/api/src/routes/project-listings/__tests__/structured-address.test.ts +0 -535
  267. package/templates/apps/api/src/routes/project-listings/index.ts +0 -164
  268. package/templates/apps/api/src/routes/project-listings/me.ts +0 -87
  269. package/templates/apps/api/src/routes/project-listings/patch-copy.ts +0 -224
  270. package/templates/apps/api/src/routes/project-listings/patch-draft.ts +0 -102
  271. package/templates/apps/api/src/routes/project-listings/public.ts +0 -98
  272. package/templates/apps/api/src/routes/project-listings/respond.ts +0 -48
  273. package/templates/apps/api/src/routes/project-listings/resume-token.ts +0 -27
  274. package/templates/apps/api/src/routes/project-listings/start.ts +0 -140
  275. package/templates/apps/api/src/routes/project-listings/submit.ts +0 -130
  276. package/templates/apps/api/src/routes/project-listings/verify-email.ts +0 -150
  277. package/templates/apps/api/src/routes/requests/__tests__/confirm.test.ts +0 -686
  278. package/templates/apps/api/src/routes/requests/confirm.ts +0 -601
  279. package/templates/apps/api/src/routes/requests/index.ts +0 -54
  280. package/templates/apps/api/src/routes/test/auth/__tests__/session.test.ts +0 -306
  281. package/templates/apps/api/src/routes/test/auth/session.ts +0 -143
  282. package/templates/apps/api/src/routes/webhooks/README.md +0 -398
  283. package/templates/apps/api/src/routes/webhooks/__tests__/stripe-checkout-consent.test.ts +0 -649
  284. package/templates/apps/api/src/routes/webhooks/__tests__/stripe-dunning.test.ts +0 -749
  285. package/templates/apps/api/src/routes/webhooks/__tests__/stripe-flow-checkout.test.ts +0 -448
  286. package/templates/apps/api/src/routes/webhooks/__tests__/stripe-idempotency.test.ts +0 -264
  287. package/templates/apps/api/src/routes/webhooks/__tests__/stripe-livemode-live.test.ts +0 -159
  288. package/templates/apps/api/src/routes/webhooks/__tests__/stripe-livemode.test.ts +0 -158
  289. package/templates/apps/api/src/routes/webhooks/__tests__/stripe-offerings.test.ts +0 -814
  290. package/templates/apps/api/src/routes/webhooks/__tests__/stripe-org-billing.test.ts +0 -301
  291. package/templates/apps/api/src/routes/webhooks/__tests__/stripe-proposal-paid.test.ts +0 -369
  292. package/templates/apps/api/src/routes/webhooks/__tests__/stripe-rate-limit.test.ts +0 -215
  293. package/templates/apps/api/src/routes/webhooks/__tests__/stripe-request-paid.test.ts +0 -301
  294. package/templates/apps/api/src/routes/webhooks/__tests__/stripe-site-filter.test.ts +0 -808
  295. package/templates/apps/api/src/routes/webhooks/__tests__/stripe.test.ts +0 -1155
  296. package/templates/apps/api/src/routes/webhooks/index.ts +0 -141
  297. package/templates/apps/api/src/routes/webhooks/stripe-offerings.ts +0 -384
  298. package/templates/apps/api/src/routes/webhooks/stripe.ts +0 -2026
  299. package/templates/apps/api/src/services/__tests__/abandon-email.test.ts +0 -528
  300. package/templates/apps/api/src/services/__tests__/answer-distributions.test.ts +0 -132
  301. package/templates/apps/api/src/services/__tests__/audit-log.test.ts +0 -1028
  302. package/templates/apps/api/src/services/__tests__/checkout-plan.test.ts +0 -313
  303. package/templates/apps/api/src/services/__tests__/consent-ledger.test.ts +0 -503
  304. package/templates/apps/api/src/services/__tests__/consent-migration.test.ts +0 -65
  305. package/templates/apps/api/src/services/__tests__/consent.test.ts +0 -299
  306. package/templates/apps/api/src/services/__tests__/default-tenant.test.ts +0 -147
  307. package/templates/apps/api/src/services/__tests__/deliverable-fulfillment.test.ts +0 -867
  308. package/templates/apps/api/src/services/__tests__/deliverable-resend.test.ts +0 -379
  309. package/templates/apps/api/src/services/__tests__/dunning-policy.test.ts +0 -368
  310. package/templates/apps/api/src/services/__tests__/entitlements.test.ts +0 -142
  311. package/templates/apps/api/src/services/__tests__/hub-sign-in.test.ts +0 -854
  312. package/templates/apps/api/src/services/__tests__/keyless-workspace-predicate.test.ts +0 -234
  313. package/templates/apps/api/src/services/__tests__/lead-accept-user.test.ts +0 -251
  314. package/templates/apps/api/src/services/__tests__/lead-routing.test.ts +0 -2660
  315. package/templates/apps/api/src/services/__tests__/listing-config.test.ts +0 -166
  316. package/templates/apps/api/src/services/__tests__/magnet-completion.test.ts +0 -389
  317. package/templates/apps/api/src/services/__tests__/person.test.ts +0 -1176
  318. package/templates/apps/api/src/services/__tests__/plan-offerings.test.ts +0 -444
  319. package/templates/apps/api/src/services/__tests__/project-listings.fence.test.ts +0 -154
  320. package/templates/apps/api/src/services/__tests__/public-site-resolver.test.ts +0 -137
  321. package/templates/apps/api/src/services/__tests__/request-confirm.test.ts +0 -531
  322. package/templates/apps/api/src/services/__tests__/revalidation.test.ts +0 -372
  323. package/templates/apps/api/src/services/__tests__/slack-notify.test.ts +0 -348
  324. package/templates/apps/api/src/services/__tests__/spoke-resolution.test.ts +0 -660
  325. package/templates/apps/api/src/services/__tests__/usage-aggregation.test.ts +0 -941
  326. package/templates/apps/api/src/services/__tests__/usage-credits.test.ts +0 -588
  327. package/templates/apps/api/src/services/__tests__/verified-email.test.ts +0 -78
  328. package/templates/apps/api/src/services/abandon-email.ts +0 -313
  329. package/templates/apps/api/src/services/aeo-score.ts +0 -325
  330. package/templates/apps/api/src/services/answer-distributions.ts +0 -138
  331. package/templates/apps/api/src/services/audit-log.ts +0 -961
  332. package/templates/apps/api/src/services/checkout-buyer.ts +0 -168
  333. package/templates/apps/api/src/services/consent.ts +0 -834
  334. package/templates/apps/api/src/services/default-tenant.ts +0 -416
  335. package/templates/apps/api/src/services/deliverable-fulfillment.ts +0 -755
  336. package/templates/apps/api/src/services/dunning-policy.ts +0 -294
  337. package/templates/apps/api/src/services/enrichment-shim.ts +0 -53
  338. package/templates/apps/api/src/services/entitlements.ts +0 -338
  339. package/templates/apps/api/src/services/hub-sign-in.ts +0 -472
  340. package/templates/apps/api/src/services/lead-accept-user.ts +0 -126
  341. package/templates/apps/api/src/services/lead-promotion.ts +0 -160
  342. package/templates/apps/api/src/services/lead-routing.ts +0 -1372
  343. package/templates/apps/api/src/services/leads-inbox.ts +0 -312
  344. package/templates/apps/api/src/services/listing-config.ts +0 -178
  345. package/templates/apps/api/src/services/magnet-completion.ts +0 -242
  346. package/templates/apps/api/src/services/offerings/__tests__/catalog.test.ts +0 -295
  347. package/templates/apps/api/src/services/offerings/__tests__/checkout-session-record.test.ts +0 -268
  348. package/templates/apps/api/src/services/offerings/__tests__/connection.test.ts +0 -868
  349. package/templates/apps/api/src/services/offerings/__tests__/fixtures.ts +0 -416
  350. package/templates/apps/api/src/services/offerings/__tests__/org-products.test.ts +0 -396
  351. package/templates/apps/api/src/services/offerings/__tests__/readers.test.ts +0 -681
  352. package/templates/apps/api/src/services/offerings/__tests__/source.test.ts +0 -231
  353. package/templates/apps/api/src/services/offerings/catalog.ts +0 -308
  354. package/templates/apps/api/src/services/offerings/checkout-authorization.ts +0 -385
  355. package/templates/apps/api/src/services/offerings/checkout-session-record.ts +0 -192
  356. package/templates/apps/api/src/services/offerings/connection.ts +0 -1003
  357. package/templates/apps/api/src/services/offerings/index.ts +0 -614
  358. package/templates/apps/api/src/services/offerings/source.ts +0 -140
  359. package/templates/apps/api/src/services/offerings/store.ts +0 -150
  360. package/templates/apps/api/src/services/owner-workspaces.ts +0 -132
  361. package/templates/apps/api/src/services/person.ts +0 -1188
  362. package/templates/apps/api/src/services/plan-offerings.ts +0 -125
  363. package/templates/apps/api/src/services/project-listing-resume-email.ts +0 -326
  364. package/templates/apps/api/src/services/project-listings.ts +0 -2073
  365. package/templates/apps/api/src/services/public-site-resolver.ts +0 -396
  366. package/templates/apps/api/src/services/request-confirm.ts +0 -698
  367. package/templates/apps/api/src/services/revalidation.ts +0 -235
  368. package/templates/apps/api/src/services/slack-notify.ts +0 -291
  369. package/templates/apps/api/src/services/usage-aggregation.ts +0 -516
  370. package/templates/apps/api/src/services/usage-credits.ts +0 -340
  371. package/templates/apps/api/src/services/verified-email.ts +0 -71
  372. package/templates/apps/mcp/__tests__/abuse/daily-cap.test.ts +0 -52
  373. package/templates/apps/mcp/__tests__/abuse/email-validator.test.ts +0 -46
  374. package/templates/apps/mcp/__tests__/abuse/guard.test.ts +0 -198
  375. package/templates/apps/mcp/__tests__/abuse/honeypot.test.ts +0 -36
  376. package/templates/apps/mcp/__tests__/abuse/user-agent-deny.test.ts +0 -54
  377. package/templates/apps/mcp/__tests__/aeo-cli-parity.test.ts +0 -116
  378. package/templates/apps/mcp/__tests__/audit-single-page.test.ts +0 -299
  379. package/templates/apps/mcp/__tests__/boot.test.ts +0 -280
  380. package/templates/apps/mcp/__tests__/catalog-drift.test.ts +0 -359
  381. package/templates/apps/mcp/__tests__/config/modules.test.ts +0 -78
  382. package/templates/apps/mcp/__tests__/get_business_hours.test.ts +0 -82
  383. package/templates/apps/mcp/__tests__/get_faq.test.ts +0 -80
  384. package/templates/apps/mcp/__tests__/get_locations.test.ts +0 -65
  385. package/templates/apps/mcp/__tests__/get_offerings.test.ts +0 -557
  386. package/templates/apps/mcp/__tests__/get_pricing.test.ts +0 -524
  387. package/templates/apps/mcp/__tests__/get_site_info.test.ts +0 -81
  388. package/templates/apps/mcp/__tests__/http-transport.test.ts +0 -1151
  389. package/templates/apps/mcp/__tests__/index.test.ts +0 -195
  390. package/templates/apps/mcp/__tests__/lib/audit-single-page-readiness-scan.test.ts +0 -191
  391. package/templates/apps/mcp/__tests__/lib/commerce-claim.test.ts +0 -531
  392. package/templates/apps/mcp/__tests__/lib/content-adapter-parity.test.ts +0 -65
  393. package/templates/apps/mcp/__tests__/lib/content-adapter.test.ts +0 -187
  394. package/templates/apps/mcp/__tests__/lib/content-root.test.ts +0 -93
  395. package/templates/apps/mcp/__tests__/lib/errors.test.ts +0 -75
  396. package/templates/apps/mcp/__tests__/lib/fail-closed-tools.test.ts +0 -165
  397. package/templates/apps/mcp/__tests__/lib/public-workspace.test.ts +0 -124
  398. package/templates/apps/mcp/__tests__/list_pages.test.ts +0 -228
  399. package/templates/apps/mcp/__tests__/locale.test.ts +0 -135
  400. package/templates/apps/mcp/__tests__/module-exclusion.test.ts +0 -175
  401. package/templates/apps/mcp/__tests__/purchase-disabled.test.ts +0 -101
  402. package/templates/apps/mcp/__tests__/read_content.test.ts +0 -474
  403. package/templates/apps/mcp/__tests__/request_callback.test.ts +0 -225
  404. package/templates/apps/mcp/__tests__/search_content.test.ts +0 -256
  405. package/templates/apps/mcp/__tests__/server.test.ts +0 -388
  406. package/templates/apps/mcp/__tests__/start_purchase.test.ts +0 -448
  407. package/templates/apps/mcp/__tests__/submit_lead.test.ts +0 -307
  408. package/templates/apps/mcp/__tests__/subscribe_newsletter.test.ts +0 -223
  409. package/templates/apps/mcp/__tests__/tools/create_project.test.ts +0 -243
  410. package/templates/apps/mcp/__tests__/tools/purchase.test.ts +0 -451
  411. package/templates/apps/mcp/src/abuse/daily-cap.ts +0 -47
  412. package/templates/apps/mcp/src/abuse/email-validator.ts +0 -25
  413. package/templates/apps/mcp/src/abuse/honeypot.ts +0 -21
  414. package/templates/apps/mcp/src/abuse/index.ts +0 -342
  415. package/templates/apps/mcp/src/abuse/user-agent-deny.ts +0 -58
  416. package/templates/apps/mcp/src/boot.ts +0 -167
  417. package/templates/apps/mcp/src/config/modules.ts +0 -43
  418. package/templates/apps/mcp/src/http-transport.ts +0 -526
  419. package/templates/apps/mcp/src/lib/audit-single-page.ts +0 -308
  420. package/templates/apps/mcp/src/lib/commerce-claim.ts +0 -263
  421. package/templates/apps/mcp/src/lib/content-adapter.ts +0 -142
  422. package/templates/apps/mcp/src/lib/empty-content-adapter.ts +0 -139
  423. package/templates/apps/mcp/src/lib/errors.ts +0 -61
  424. package/templates/apps/mcp/src/lib/license-key-store.ts +0 -45
  425. package/templates/apps/mcp/src/lib/locales.ts +0 -171
  426. package/templates/apps/mcp/src/lib/prisma.ts +0 -39
  427. package/templates/apps/mcp/src/lib/public-workspace.ts +0 -133
  428. package/templates/apps/mcp/src/lib/resolve-locale.ts +0 -30
  429. package/templates/apps/mcp/src/lib/shown-offerings.ts +0 -105
  430. package/templates/apps/mcp/src/lib/stripe-tax-signal.ts +0 -59
  431. package/templates/apps/mcp/src/request-context.ts +0 -52
  432. package/templates/apps/mcp/src/server.ts +0 -343
  433. package/templates/apps/mcp/src/serverless-app.ts +0 -88
  434. package/templates/apps/mcp/src/tools/audit.ts +0 -127
  435. package/templates/apps/mcp/src/tools/capture_lead.ts +0 -64
  436. package/templates/apps/mcp/src/tools/create_project.ts +0 -134
  437. package/templates/apps/mcp/src/tools/get_business_hours.ts +0 -68
  438. package/templates/apps/mcp/src/tools/get_faq.ts +0 -71
  439. package/templates/apps/mcp/src/tools/get_locations.ts +0 -88
  440. package/templates/apps/mcp/src/tools/get_offerings.ts +0 -96
  441. package/templates/apps/mcp/src/tools/get_pricing.ts +0 -94
  442. package/templates/apps/mcp/src/tools/get_site_info.ts +0 -86
  443. package/templates/apps/mcp/src/tools/index.ts +0 -137
  444. package/templates/apps/mcp/src/tools/list_pages.ts +0 -74
  445. package/templates/apps/mcp/src/tools/person_notes.ts +0 -25
  446. package/templates/apps/mcp/src/tools/proposals.ts +0 -27
  447. package/templates/apps/mcp/src/tools/purchase.ts +0 -205
  448. package/templates/apps/mcp/src/tools/read_content.ts +0 -75
  449. package/templates/apps/mcp/src/tools/request_callback.ts +0 -59
  450. package/templates/apps/mcp/src/tools/search_content.ts +0 -67
  451. package/templates/apps/mcp/src/tools/subscribe_newsletter.ts +0 -57
  452. package/templates/apps/mcp/src/workspace-server.ts +0 -224
  453. package/templates/database/CHANGELOG.md +0 -961
  454. package/templates/database/LICENSE +0 -202
  455. package/templates/database/NOTICE +0 -2
  456. package/templates/database/README.md +0 -243
  457. package/templates/database/__tests__/agents.db.test.ts +0 -320
  458. package/templates/database/__tests__/appointment.db.test.ts +0 -106
  459. package/templates/database/__tests__/artifact-content-store.db.test.ts +0 -316
  460. package/templates/database/__tests__/composite-fence.db.test.ts +0 -206
  461. package/templates/database/__tests__/consent-ledger.db.test.ts +0 -345
  462. package/templates/database/__tests__/consent-source-checkout-migration.test.ts +0 -79
  463. package/templates/database/__tests__/fence-fan-out.db.test.ts +0 -715
  464. package/templates/database/__tests__/fixtures/appointment-create-probe.ts +0 -79
  465. package/templates/database/__tests__/fixtures/person-backfill.json +0 -264
  466. package/templates/database/__tests__/fixtures/person-contact-backfill.json +0 -182
  467. package/templates/database/__tests__/fixtures/project-listing-consent-probe.ts +0 -100
  468. package/templates/database/__tests__/flow-completion-migration.test.ts +0 -115
  469. package/templates/database/__tests__/flow-completion.db.test.ts +0 -136
  470. package/templates/database/__tests__/flow-workspace-key.db.test.ts +0 -263
  471. package/templates/database/__tests__/flows-listing-diagnostic.test.ts +0 -392
  472. package/templates/database/__tests__/flows-presets.test.ts +0 -173
  473. package/templates/database/__tests__/in-page-magnets-migration.test.ts +0 -161
  474. package/templates/database/__tests__/lead-idempotency-key.db.test.ts +0 -92
  475. package/templates/database/__tests__/member-area.db.test.ts +0 -257
  476. package/templates/database/__tests__/member-contract-migration.test.ts +0 -85
  477. package/templates/database/__tests__/member-contract.db.test.ts +0 -413
  478. package/templates/database/__tests__/offerings-checkout-session.db.test.ts +0 -270
  479. package/templates/database/__tests__/offerings-migration.test.ts +0 -197
  480. package/templates/database/__tests__/offerings-shown-price-ids-migration.test.ts +0 -86
  481. package/templates/database/__tests__/offerings.db.test.ts +0 -303
  482. package/templates/database/__tests__/outbound-message-action.db.test.ts +0 -80
  483. package/templates/database/__tests__/person-contact.db.test.ts +0 -563
  484. package/templates/database/__tests__/person-notes.db.test.ts +0 -249
  485. package/templates/database/__tests__/person.db.test.ts +0 -586
  486. package/templates/database/__tests__/piece-kind-migration.test.ts +0 -67
  487. package/templates/database/__tests__/piece-kind.db.test.ts +0 -208
  488. package/templates/database/__tests__/prefixed-ids.db.test.ts +0 -222
  489. package/templates/database/__tests__/project-listing-consent-at.db.test.ts +0 -111
  490. package/templates/database/__tests__/seed.test.ts +0 -240
  491. package/templates/database/__tests__/spoke-registry.db.test.ts +0 -191
  492. package/templates/database/__tests__/tenancy.test.ts +0 -141
  493. package/templates/database/__tests__/user-cascade.test.ts +0 -140
  494. package/templates/database/_gitignore +0 -8
  495. package/templates/database/auth/.gitkeep +0 -0
  496. package/templates/database/auth/schema.prisma +0 -641
  497. package/templates/database/config/.gitkeep +0 -0
  498. package/templates/database/config/schema.prisma +0 -441
  499. package/templates/database/content/.gitkeep +0 -0
  500. package/templates/database/content/schema.prisma +0 -339
  501. package/templates/database/eslint.config.mjs +0 -69
  502. package/templates/database/flows/listing-diagnostic.ts +0 -182
  503. package/templates/database/flows/presets.ts +0 -315
  504. package/templates/database/inbox/.gitkeep +0 -0
  505. package/templates/database/inbox/README.md +0 -3
  506. package/templates/database/inbox/__tests__/schema.test.ts +0 -44
  507. package/templates/database/inbox/schema.prisma +0 -1447
  508. package/templates/database/jest.config.cjs +0 -36
  509. package/templates/database/migrations/20260508000000_add_inbox_namespace/migration.sql +0 -328
  510. package/templates/database/migrations/20260513000000_better_auth_migration/migration.sql +0 -100
  511. package/templates/database/migrations/20260515000000_add_user_billing_fields/migration.sql +0 -28
  512. package/templates/database/migrations/20260516000000_add_user_tier_care_plan_seat/migration.sql +0 -25
  513. package/templates/database/migrations/20260518000000_add_telemetry_records/migration.sql +0 -42
  514. package/templates/database/migrations/20260525000000_theme_wiring/migration.sql +0 -67
  515. package/templates/database/migrations/20260710000000_retire_commercial_tier/migration.sql +0 -21
  516. package/templates/database/migrations/20260712215647_add_multi_tenant_tenancy/migration.sql +0 -201
  517. package/templates/database/migrations/20260713143320_reanchor_site_config_to_workspace/migration.sql +0 -67
  518. package/templates/database/migrations/20260713174000_add_audit_logs/migration.sql +0 -46
  519. package/templates/database/migrations/20260713190000_drop_telemetry_records/migration.sql +0 -25
  520. package/templates/database/migrations/20260713192000_add_uuidv7_function/migration.sql +0 -49
  521. package/templates/database/migrations/20260713192429_prefixed_uuid_entity_ids/migration.sql +0 -197
  522. package/templates/database/migrations/20260713200000_add_org_billing/migration.sql +0 -32
  523. package/templates/database/migrations/20260714000000_add_lead_promotion_fields/migration.sql +0 -22
  524. package/templates/database/migrations/20260714010000_add_usage_billing_content_models/migration.sql +0 -151
  525. package/templates/database/migrations/20260714020000_add_usage_billing_auth_config_models/migration.sql +0 -223
  526. package/templates/database/migrations/20260714030000_credit_balance_non_negative/migration.sql +0 -22
  527. package/templates/database/migrations/20260714030000_widen_usage_billing_report_aggregates/migration.sql +0 -32
  528. package/templates/database/migrations/20260810233516_add_flow_engine_models/migration.sql +0 -40
  529. package/templates/database/migrations/20260811020000_add_flow_session_abandon_email_columns/migration.sql +0 -4
  530. package/templates/database/migrations/20260811030000_add_flow_session_abandon_email_index/migration.sql +0 -2
  531. package/templates/database/migrations/20260811040000_add_flow_session_segment/migration.sql +0 -2
  532. package/templates/database/migrations/20260811050000_add_deliverable_models/migration.sql +0 -29
  533. package/templates/database/migrations/20260812000000_add_deliverable_grant_send_columns/migration.sql +0 -6
  534. package/templates/database/migrations/20260902222948_add_waitlist_experiment_models/migration.sql +0 -39
  535. package/templates/database/migrations/20260902224500_add_waitlist_id_format_checks/migration.sql +0 -24
  536. package/templates/database/migrations/20260903004112_add_flow_session_flags_aeo_score/migration.sql +0 -3
  537. package/templates/database/migrations/20260903010000_add_playbook_instance/migration.sql +0 -33
  538. package/templates/database/migrations/20260904000000_add_waitlist_followup_send/migration.sql +0 -30
  539. package/templates/database/migrations/20260905230000_add_flow_checkout/migration.sql +0 -47
  540. package/templates/database/migrations/20260906000000_add_flow_checkout_idempotency/migration.sql +0 -16
  541. package/templates/database/migrations/20260907120000_add_project_listing/migration.sql +0 -47
  542. package/templates/database/migrations/20260907130000_add_project_listing_slack_columns/migration.sql +0 -10
  543. package/templates/database/migrations/20260907180000_add_listing_csv_send/migration.sql +0 -26
  544. package/templates/database/migrations/20260909120000_project_listings_platform/migration.sql +0 -90
  545. package/templates/database/migrations/20260909180000_listing_draft_and_fields/migration.sql +0 -174
  546. package/templates/database/migrations/20260910120000_listing_public_site_key/migration.sql +0 -14
  547. package/templates/database/migrations/20260911120000_listing_copy_edit_audit/migration.sql +0 -25
  548. package/templates/database/migrations/20260911140000_listing_structured_address/migration.sql +0 -32
  549. package/templates/database/migrations/20260911180000_consent_grants/migration.sql +0 -71
  550. package/templates/database/migrations/20260911200000_listing_site_answers/migration.sql +0 -30
  551. package/templates/database/migrations/20260912120000_listing_owner_link/migration.sql +0 -49
  552. package/templates/database/migrations/20260914120000_listing_founder_identity/migration.sql +0 -123
  553. package/templates/database/migrations/20260915120000_project_listing_solution/migration.sql +0 -15
  554. package/templates/database/migrations/20260916120000_artifact_content_store/migration.sql +0 -158
  555. package/templates/database/migrations/20260917120000_callback_request_confirm/migration.sql +0 -40
  556. package/templates/database/migrations/20260918120000_add_appointment/migration.sql +0 -67
  557. package/templates/database/migrations/20260918120000_asset_metadata_columns/migration.sql +0 -70
  558. package/templates/database/migrations/20260919120000_flow_workspace_key/migration.sql +0 -181
  559. package/templates/database/migrations/20260919130000_flow_definition_admin_columns/migration.sql +0 -172
  560. package/templates/database/migrations/20260919130000_workspace_meetings/migration.sql +0 -41
  561. package/templates/database/migrations/20260919140000_inbox_workspace_key/migration.sql +0 -185
  562. package/templates/database/migrations/20260920120000_lead_handled_at/migration.sql +0 -70
  563. package/templates/database/migrations/20260920130000_lead_workspace_source_index/migration.sql +0 -57
  564. package/templates/database/migrations/20260921120000_deliverable_grant_workspace_key/migration.sql +0 -68
  565. package/templates/database/migrations/20260922120000_tenancy_fence/migration.sql +0 -1067
  566. package/templates/database/migrations/20260923120000_listing_capturing_magnet/migration.sql +0 -210
  567. package/templates/database/migrations/20261003120000_spoke_registry/migration.sql +0 -80
  568. package/templates/database/migrations/20261003130000_scheduling_connection/migration.sql +0 -49
  569. package/templates/database/migrations/20261005120000_agents/migration.sql +0 -84
  570. package/templates/database/migrations/20261008120000_user_last_workspace/migration.sql +0 -35
  571. package/templates/database/migrations/20261008130000_lead_idempotency_key/migration.sql +0 -20
  572. package/templates/database/migrations/20261009120000_agent_grants/migration.sql +0 -33
  573. package/templates/database/migrations/20261010120000_person/migration.sql +0 -106
  574. package/templates/database/migrations/20261010121000_person_backfill/migration.sql +0 -132
  575. package/templates/database/migrations/20261010130000_agent_grants_people_read/migration.sql +0 -20
  576. package/templates/database/migrations/20261011120000_member_area/migration.sql +0 -158
  577. package/templates/database/migrations/20261011130000_agent_grants_member_pieces_manage/migration.sql +0 -21
  578. package/templates/database/migrations/20261012120000_member_contract/migration.sql +0 -192
  579. package/templates/database/migrations/20261013120000_lead_spoke_checkout/migration.sql +0 -20
  580. package/templates/database/migrations/20261014120000_consent_ledger/migration.sql +0 -122
  581. package/templates/database/migrations/20261014120000_person_contact/migration.sql +0 -231
  582. package/templates/database/migrations/20261015120000_person_notes/migration.sql +0 -77
  583. package/templates/database/migrations/20261015120000_rate_limit_counters/migration.sql +0 -43
  584. package/templates/database/migrations/20261016120000_piece_kind/migration.sql +0 -95
  585. package/templates/database/migrations/20261017120000_outbound_message_action/migration.sql +0 -30
  586. package/templates/database/migrations/20261018120000_flow_completion/migration.sql +0 -52
  587. package/templates/database/migrations/20261019120000_consent_source_checkout/migration.sql +0 -27
  588. package/templates/database/migrations/20261020120000_offerings_data_model/migration.sql +0 -146
  589. package/templates/database/migrations/20261021120000_offerings_checkout_session/migration.sql +0 -77
  590. package/templates/database/migrations/20261022120000_in_page_magnets/migration.sql +0 -45
  591. package/templates/database/migrations/20261023120000_offerings_shown_price_ids/migration.sql +0 -47
  592. package/templates/database/migrations/20261024120000_organization_plan_checkout_session/migration.sql +0 -16
  593. package/templates/database/migrations/migration_lock.toml +0 -3
  594. package/templates/database/ops/.gitkeep +0 -0
  595. package/templates/database/ops/schema.prisma +0 -43
  596. package/templates/database/package.json +0 -89
  597. package/templates/database/schema.prisma +0 -71
  598. package/templates/database/scripts/db-generate-locked.sh +0 -80
  599. package/templates/database/scripts/person-backfill.sql +0 -132
  600. package/templates/database/tenancy.ts +0 -183
  601. package/templates/database/tsconfig.build.json +0 -16
  602. package/templates/database/tsconfig.flows.json +0 -15
  603. package/templates/database/tsconfig.json +0 -16
  604. package/templates/database/tsconfig.tenancy.json +0 -14
@@ -1,1151 +0,0 @@
1
- /**
2
- * Integration tests for the MCP HTTP transport.
3
- *
4
- * Starts a real Fastify server on an ephemeral port (port 0) per test suite
5
- * and uses Node's global fetch to send requests. Real TCP sockets avoid the
6
- * `socket.destroySoon is not a function` crash that occurs when the MCP SDK's
7
- * StreamableHTTPServerTransport receives the mock socket from app.inject().
8
- *
9
- * Uses stateless transport mode: each request is independent, responses are
10
- * plain JSON (no SSE). This is the simplest deployment model and the easiest
11
- * to test. Stateful session behaviour is exercised by the SDK's own test suite.
12
- *
13
- * Acceptance criteria verified here (Layer 2):
14
- * - tools/list returns all OSS tools (count matches listRegisteredTools())
15
- * - Read-tool call succeeds over HTTP
16
- * - Write-tool call from a disallowed origin returns 403
17
- * - Rate-limit triggers at configured threshold
18
- * - Abuse rules reject invalid email on capture_lead
19
- * - Honeypot field rejection on capture_lead
20
- * - Blocked UA returns 403
21
- * - #5971: a start_purchase burst past the per-IP daily cap is refused with
22
- * the rate-limit error, and no Checkout Session is created
23
- * - #8071: create_booking and submit_flow_step take the same write branch —
24
- * the origin allow-list, each tool's own daily cap (no hub call for a
25
- * refused one), one cap unit per batched call, and for create_booking an
26
- * attendee.email format check
27
- * - #8073: a capture_lead call forwards the socket address the transport
28
- * trusted (never a caller-forged X-Forwarded-For) plus
29
- * AILK_VISITOR_FORWARD_KEY as the two visitor-forwarding headers, and sends
30
- * neither when the key is unset
31
- */
32
-
33
- import type { AddressInfo } from "node:net";
34
-
35
- import type { FastifyInstance, FastifyRequest } from "fastify";
36
- import { apiClient, checkout } from "@working-theory/api-client";
37
-
38
- import {
39
- __setMcpCommerceClaimForTest,
40
- resetMcpCommerceClaim,
41
- } from "../src/lib/commerce-claim.js";
42
- import { AbuseGuard, AbuseReasonCode } from "../src/abuse/index.js";
43
- import {
44
- ABUSE_REFUSAL_STATUS,
45
- buildHttpTransportApp,
46
- WRITE_TOOLS,
47
- } from "../src/http-transport.js";
48
- import { listRegisteredTools } from "../src/server.js";
49
-
50
- jest.mock("@working-theory/api-client", () => {
51
- const actual = jest.requireActual("@working-theory/api-client");
52
- // The hub stubs for the two #8071 write tools: every other surface stays
53
- // real, so a tool these tests do not name behaves exactly as before.
54
- return {
55
- ...actual,
56
- checkout: { createSession: jest.fn() },
57
- apiClient: {
58
- ...actual.apiClient,
59
- schedule: { ...actual.apiClient.schedule, book: jest.fn() },
60
- flows: { ...actual.apiClient.flows, submitStep: jest.fn() },
61
- },
62
- };
63
- });
64
-
65
- /** Permissive JSON-RPC 2.0 envelope type for response body assertions. */
66
- type JsonRpcResponse = {
67
- jsonrpc?: string;
68
- id?: number | string | null;
69
- result?: { tools?: unknown[]; [k: string]: unknown };
70
- error?: { code: number; message: string };
71
- };
72
-
73
- const TOOLS_LIST_PAYLOAD = {
74
- jsonrpc: "2.0",
75
- id: 1,
76
- method: "tools/list",
77
- params: {},
78
- };
79
-
80
- /** Default config used by most test suites. */
81
- const DEFAULT_CONFIG = {
82
- path: "/mcp",
83
- stateless: true,
84
- rateLimits: { readPerMin: 60, writePerMin: 10 },
85
- cors: { writeAllowedOrigins: [] as string[] },
86
- abuse: {
87
- captureLeadDailyCapPerIp: 50,
88
- blockedUserAgents: "",
89
- },
90
- } as const;
91
-
92
- /**
93
- * Post a JSON-RPC payload to the server at the given port and return the
94
- * fetch Response. Includes the Accept header required by the MCP Streamable
95
- * HTTP spec.
96
- */
97
- async function mcpPost(
98
- port: number,
99
- payload: object,
100
- headers: Record<string, string> = {},
101
- ): Promise<Response> {
102
- return fetch(`http://127.0.0.1:${port}/mcp`, {
103
- method: "POST",
104
- body: JSON.stringify(payload),
105
- headers: {
106
- "content-type": "application/json",
107
- accept: "application/json, text/event-stream",
108
- ...headers,
109
- },
110
- });
111
- }
112
-
113
- describe("buildHttpTransportApp", () => {
114
- let app: FastifyInstance;
115
- let port: number;
116
-
117
- beforeEach(async () => {
118
- app = await buildHttpTransportApp(DEFAULT_CONFIG);
119
- await app.listen({ host: "127.0.0.1", port: 0 });
120
- port = (app.server.address() as AddressInfo).port;
121
- });
122
-
123
- afterEach(async () => {
124
- await app.close();
125
- });
126
-
127
- it("starts listening on an ephemeral port without throwing", () => {
128
- expect(app.server.listening).toBe(true);
129
- expect(port).toBeGreaterThan(0);
130
- });
131
- });
132
-
133
- describe("tools/list over HTTP (stateless)", () => {
134
- let app: FastifyInstance;
135
- let port: number;
136
-
137
- beforeEach(async () => {
138
- app = await buildHttpTransportApp(DEFAULT_CONFIG);
139
- await app.listen({ host: "127.0.0.1", port: 0 });
140
- port = (app.server.address() as AddressInfo).port;
141
- });
142
-
143
- afterEach(async () => {
144
- await app.close();
145
- });
146
-
147
- it("returns 200 for a tools/list request", async () => {
148
- const res = await mcpPost(port, TOOLS_LIST_PAYLOAD);
149
- expect(res.status).toBe(200);
150
- });
151
-
152
- it("tools/list response includes all OSS tools", async () => {
153
- const res = await mcpPost(port, TOOLS_LIST_PAYLOAD);
154
- expect(res.status).toBe(200);
155
-
156
- const body = (await res.json()) as JsonRpcResponse;
157
- expect(body.result).toBeDefined();
158
- // body.result is confirmed defined above; non-null assertion is safe
159
- expect(Array.isArray(body.result!.tools)).toBe(true);
160
-
161
- const expectedCount = listRegisteredTools().length;
162
- expect(body.result!.tools).toHaveLength(expectedCount);
163
- });
164
- });
165
-
166
- describe("CORS enforcement on write tools", () => {
167
- let app: FastifyInstance;
168
- let port: number;
169
-
170
- beforeEach(async () => {
171
- app = await buildHttpTransportApp(DEFAULT_CONFIG);
172
- await app.listen({ host: "127.0.0.1", port: 0 });
173
- port = (app.server.address() as AddressInfo).port;
174
- });
175
-
176
- afterEach(async () => {
177
- await app.close();
178
- });
179
-
180
- it("blocks a tools/call write from a non-allowlisted origin", async () => {
181
- const payload = {
182
- jsonrpc: "2.0",
183
- id: 3,
184
- method: "tools/call",
185
- params: {
186
- name: "capture_lead",
187
- arguments: {
188
- name: "Bot",
189
- email: "bot@evil.com",
190
- },
191
- },
192
- };
193
-
194
- const res = await mcpPost(port, payload, {
195
- origin: "https://evil.example.com",
196
- });
197
-
198
- expect(res.status).toBe(403);
199
- });
200
-
201
- it("allows a tools/call write from an allowlisted origin", async () => {
202
- const allowedApp = await buildHttpTransportApp({
203
- ...DEFAULT_CONFIG,
204
- cors: { writeAllowedOrigins: ["https://allowed.example.com"] },
205
- });
206
- await allowedApp.listen({ host: "127.0.0.1", port: 0 });
207
- const allowedPort = (allowedApp.server.address() as AddressInfo).port;
208
-
209
- try {
210
- const payload = {
211
- jsonrpc: "2.0",
212
- id: 3,
213
- method: "tools/call",
214
- params: {
215
- name: "capture_lead",
216
- arguments: {
217
- name: "Jane",
218
- email: "jane@example.com",
219
- },
220
- },
221
- };
222
-
223
- const res = await mcpPost(allowedPort, payload, {
224
- origin: "https://allowed.example.com",
225
- });
226
-
227
- // Should NOT be 403 (may be 200 or a tool-level error, but not CORS blocked)
228
- expect(res.status).not.toBe(403);
229
- } finally {
230
- await allowedApp.close();
231
- }
232
- });
233
- });
234
-
235
- describe("Rate limiting", () => {
236
- // Use a very low limit to test without hammering
237
- const LOW_RATE_CONFIG = {
238
- ...DEFAULT_CONFIG,
239
- rateLimits: { readPerMin: 3, writePerMin: 2 },
240
- } as const;
241
-
242
- let app: FastifyInstance;
243
- let port: number;
244
-
245
- beforeEach(async () => {
246
- app = await buildHttpTransportApp(LOW_RATE_CONFIG);
247
- await app.listen({ host: "127.0.0.1", port: 0 });
248
- port = (app.server.address() as AddressInfo).port;
249
- });
250
-
251
- afterEach(async () => {
252
- await app.close();
253
- });
254
-
255
- it("returns 429 after exceeding the read rate limit", async () => {
256
- const payload = {
257
- jsonrpc: "2.0",
258
- id: 10,
259
- method: "tools/list",
260
- params: {},
261
- };
262
-
263
- let lastStatus = 200;
264
- for (let i = 0; i < 5; i++) {
265
- const res = await mcpPost(port, payload);
266
- lastStatus = res.status;
267
- }
268
-
269
- expect(lastStatus).toBe(429);
270
- });
271
- });
272
-
273
- describe("Abuse rules", () => {
274
- const OPEN_CORS_CONFIG = {
275
- ...DEFAULT_CONFIG,
276
- cors: { writeAllowedOrigins: ["*"] as string[] },
277
- };
278
-
279
- let app: FastifyInstance;
280
- let port: number;
281
-
282
- beforeEach(async () => {
283
- app = await buildHttpTransportApp(OPEN_CORS_CONFIG);
284
- await app.listen({ host: "127.0.0.1", port: 0 });
285
- port = (app.server.address() as AddressInfo).port;
286
- });
287
-
288
- afterEach(async () => {
289
- await app.close();
290
- });
291
-
292
- it("rejects capture_lead with malformed email", async () => {
293
- const payload = {
294
- jsonrpc: "2.0",
295
- id: 20,
296
- method: "tools/call",
297
- params: {
298
- name: "capture_lead",
299
- arguments: {
300
- name: "Spammer",
301
- email: "not-an-email",
302
- },
303
- },
304
- };
305
-
306
- const res = await mcpPost(port, payload);
307
- expect(res.status).toBe(422);
308
- });
309
-
310
- it("rejects capture_lead with honeypot field filled", async () => {
311
- const payload = {
312
- jsonrpc: "2.0",
313
- id: 21,
314
- method: "tools/call",
315
- params: {
316
- name: "capture_lead",
317
- arguments: {
318
- name: "Bot",
319
- email: "bot@example.com",
320
- honeypot: "i-am-a-bot",
321
- },
322
- },
323
- };
324
-
325
- const res = await mcpPost(port, payload);
326
- expect(res.status).toBe(422);
327
- });
328
-
329
- it("blocks requests from blocked user agents", async () => {
330
- const blockedApp = await buildHttpTransportApp({
331
- ...OPEN_CORS_CONFIG,
332
- abuse: {
333
- captureLeadDailyCapPerIp: 50,
334
- blockedUserAgents: "EvilBot",
335
- },
336
- });
337
- await blockedApp.listen({ host: "127.0.0.1", port: 0 });
338
- const blockedPort = (blockedApp.server.address() as AddressInfo).port;
339
-
340
- try {
341
- const res = await mcpPost(
342
- blockedPort,
343
- {
344
- jsonrpc: "2.0",
345
- id: 22,
346
- method: "tools/call",
347
- params: {
348
- name: "capture_lead",
349
- arguments: { name: "Bot", email: "bot@example.com" },
350
- },
351
- },
352
- { "user-agent": "EvilBot/1.0" },
353
- );
354
- expect(res.status).toBe(403);
355
- } finally {
356
- await blockedApp.close();
357
- }
358
- });
359
- });
360
-
361
- /**
362
- * #8073 — the lead-write tools forward the address the transport TRUSTED
363
- * (`request.ip`), not a caller-supplied `X-Forwarded-For` value. The
364
- * long-running entry (`buildHttpTransportApp`, used throughout this file)
365
- * sets no `trustProxy`, so `request.ip` is always the real socket address —
366
- * 127.0.0.1 here — exactly the D5 guarantee a forged header cannot move.
367
- */
368
- describe("capture_lead forwards the trusted caller address (#8073)", () => {
369
- let app: FastifyInstance;
370
- let port: number;
371
- let submitSpy: jest.SpiedFunction<typeof apiClient.leads.submit>;
372
-
373
- beforeEach(async () => {
374
- submitSpy = jest
375
- .spyOn(apiClient.leads, "submit")
376
- .mockResolvedValue({ ok: true, body: { id: "lead_1", persisted: "db" } });
377
- app = await buildHttpTransportApp(DEFAULT_CONFIG);
378
- await app.listen({ host: "127.0.0.1", port: 0 });
379
- port = (app.server.address() as AddressInfo).port;
380
- });
381
-
382
- afterEach(async () => {
383
- await app.close();
384
- submitSpy.mockRestore();
385
- delete process.env.AILK_VISITOR_FORWARD_KEY;
386
- });
387
-
388
- function capturePayload(id: number, email: string) {
389
- return {
390
- jsonrpc: "2.0",
391
- id,
392
- method: "tools/call",
393
- params: { name: "capture_lead", arguments: { name: "Jane", email } },
394
- };
395
- }
396
-
397
- it("sends the socket address and the forward key as the two visitor headers", async () => {
398
- process.env.AILK_VISITOR_FORWARD_KEY = "spoke-key";
399
-
400
- const res = await mcpPost(port, capturePayload(40, "jane@example.com"), {
401
- // A caller-forged hop: D5 says this must not move the key.
402
- "x-forwarded-for": "203.0.113.7",
403
- });
404
-
405
- expect(res.status).toBe(200);
406
- expect(submitSpy).toHaveBeenCalledTimes(1);
407
- const init = submitSpy.mock.calls[0]?.[1];
408
- expect(init?.headers).toEqual({
409
- "x-ailk-visitor-ip": "127.0.0.1",
410
- "x-ailk-visitor-forward-key": "spoke-key",
411
- });
412
- });
413
-
414
- it("sends no visitor headers (and no second argument) when the key is unset", async () => {
415
- delete process.env.AILK_VISITOR_FORWARD_KEY;
416
-
417
- const res = await mcpPost(port, capturePayload(41, "jane2@example.com"));
418
-
419
- expect(res.status).toBe(200);
420
- expect(submitSpy).toHaveBeenCalledTimes(1);
421
- expect(submitSpy.mock.calls[0]).toHaveLength(1);
422
- });
423
- });
424
-
425
- /**
426
- * AC-3 — a `start_purchase` burst beyond the AbuseGuard per-IP cap is refused
427
- * with the rate-limit error and creates no Checkout Session (#5971 D6).
428
- *
429
- * The refusal happens in the POST preHandler, BEFORE the MCP handler runs, so
430
- * `checkout.createSession` is the thing to count: it is called once per call
431
- * that got through and never for the one that was refused.
432
- *
433
- * `start_purchase` takes the write branch only because #5971 added it to
434
- * `WRITE_TOOLS`; on the read branch the AbuseGuard checks the UA deny list
435
- * alone and the cap would never be consulted.
436
- */
437
- describe("start_purchase — per-IP daily cap (#5971)", () => {
438
- const CAP = 2;
439
- const CAPPED_CONFIG = {
440
- ...DEFAULT_CONFIG,
441
- cors: { writeAllowedOrigins: ["*"] as string[] },
442
- abuse: {
443
- captureLeadDailyCapPerIp: 50,
444
- startPurchaseDailyCapPerIp: CAP,
445
- blockedUserAgents: "",
446
- },
447
- };
448
-
449
- const createSession = checkout.createSession as jest.MockedFunction<
450
- typeof checkout.createSession
451
- >;
452
-
453
- let app: FastifyInstance;
454
- let port: number;
455
-
456
- function purchasePayload(id: number) {
457
- return {
458
- jsonrpc: "2.0",
459
- id,
460
- method: "tools/call",
461
- params: {
462
- name: "start_purchase",
463
- arguments: { productCode: "growth_monthly" },
464
- },
465
- };
466
- }
467
-
468
- beforeEach(async () => {
469
- __setMcpCommerceClaimForTest("claimed");
470
- createSession.mockResolvedValue({
471
- ok: true,
472
- body: {
473
- sessionId: "cs_test_burst",
474
- url: "https://checkout.stripe.com/c/pay/cs_test_burst",
475
- },
476
- });
477
- app = await buildHttpTransportApp(CAPPED_CONFIG);
478
- await app.listen({ host: "127.0.0.1", port: 0 });
479
- port = (app.server.address() as AddressInfo).port;
480
- });
481
-
482
- afterEach(async () => {
483
- await app.close();
484
- jest.clearAllMocks();
485
- resetMcpCommerceClaim();
486
- });
487
-
488
- it("refuses the call past the cap with 403 and a 'daily cap' reason", async () => {
489
- const first = await mcpPost(port, purchasePayload(30));
490
- const second = await mcpPost(port, purchasePayload(31));
491
- const third = await mcpPost(port, purchasePayload(32));
492
-
493
- expect(first.status).toBe(200);
494
- expect(second.status).toBe(200);
495
- expect(third.status).toBe(403);
496
-
497
- const body = (await third.json()) as { error?: string };
498
- expect(body.error).toContain("daily");
499
- expect(body.error).toContain("cap");
500
- });
501
-
502
- it("creates no Checkout Session for the refused call", async () => {
503
- await mcpPost(port, purchasePayload(33));
504
- await mcpPost(port, purchasePayload(34));
505
- await mcpPost(port, purchasePayload(35));
506
-
507
- expect(createSession).toHaveBeenCalledTimes(CAP);
508
- });
509
-
510
- it("start_purchase takes the write branch, so the guard sees it at all", async () => {
511
- const res = await mcpPost(port, purchasePayload(36), {
512
- "user-agent": "curl/8.0",
513
- });
514
-
515
- // A built-in blocked UA is refused on the write branch; a read-branch
516
- // tool would be too, but only the write branch consults the cap above.
517
- expect(res.status).toBe(403);
518
- });
519
- });
520
-
521
- /**
522
- * JSON-RPC BATCH envelope — the write branch must survive it (#5971 security
523
- * review, High).
524
- *
525
- * JSON-RPC 2.0 allows an ARRAY of messages in one POST, and the pinned MCP SDK
526
- * dispatches every one of them. The write-tool guard used to read
527
- * `body.method` on a body that may be an array: an array has no `.method`, so
528
- * the whole batch was classified as a READ, skipping the write-origin
529
- * allow-list and every AbuseGuard rule — including the per-IP daily cap. N
530
- * batched `start_purchase` calls then executed on zero cap units, each one
531
- * creating a real Stripe Checkout Session on the seller's account.
532
- *
533
- * These tests pin the envelope, not the tool: any future WRITE_TOOLS addition
534
- * inherits them. The gap predated `start_purchase` and covered the three other
535
- * write tools too, which is why the last case here is `capture_lead`.
536
- */
537
- describe("JSON-RPC batch bodies take the write branch (#5971)", () => {
538
- const CAP = 2;
539
- const BATCH_CONFIG = {
540
- ...DEFAULT_CONFIG,
541
- cors: { writeAllowedOrigins: ["*"] as string[] },
542
- abuse: {
543
- captureLeadDailyCapPerIp: CAP,
544
- startPurchaseDailyCapPerIp: CAP,
545
- blockedUserAgents: "",
546
- },
547
- };
548
-
549
- const createSession = checkout.createSession as jest.MockedFunction<
550
- typeof checkout.createSession
551
- >;
552
-
553
- let app: FastifyInstance;
554
- let port: number;
555
-
556
- function purchaseMessage(id: number) {
557
- return {
558
- jsonrpc: "2.0",
559
- id,
560
- method: "tools/call",
561
- params: {
562
- name: "start_purchase",
563
- arguments: { productCode: "growth_monthly" },
564
- },
565
- };
566
- }
567
-
568
- beforeEach(async () => {
569
- __setMcpCommerceClaimForTest("claimed");
570
- createSession.mockResolvedValue({
571
- ok: true,
572
- body: {
573
- sessionId: "cs_test_batch",
574
- url: "https://checkout.stripe.com/c/pay/cs_test_batch",
575
- },
576
- });
577
- app = await buildHttpTransportApp(BATCH_CONFIG);
578
- await app.listen({ host: "127.0.0.1", port: 0 });
579
- port = (app.server.address() as AddressInfo).port;
580
- });
581
-
582
- afterEach(async () => {
583
- await app.close();
584
- jest.clearAllMocks();
585
- resetMcpCommerceClaim();
586
- });
587
-
588
- it("a batch of N write calls consumes N cap units, not one", async () => {
589
- // One POST carrying CAP + 1 messages. Under the old per-request check this
590
- // returned 200 and executed every one; the cap must refuse it outright.
591
- const res = await mcpPost(port, [
592
- purchaseMessage(40),
593
- purchaseMessage(41),
594
- purchaseMessage(42),
595
- ]);
596
-
597
- expect(res.status).toBe(403);
598
- const body = (await res.json()) as { error?: string };
599
- expect(body.error).toContain("daily cap");
600
- });
601
-
602
- it("refuses the batch before the SDK dispatches any of its messages", async () => {
603
- await mcpPost(port, [
604
- purchaseMessage(43),
605
- purchaseMessage(44),
606
- purchaseMessage(45),
607
- ]);
608
-
609
- // Refused in the preHandler ⇒ no Checkout Session for ANY message.
610
- expect(createSession).not.toHaveBeenCalled();
611
- });
612
-
613
- it("a batch within the cap still works, and charges one unit per message", async () => {
614
- const res = await mcpPost(port, [purchaseMessage(46), purchaseMessage(47)]);
615
- expect(res.status).toBe(200);
616
-
617
- // Both units are now spent, so a single further call is refused.
618
- const third = await mcpPost(port, purchaseMessage(48));
619
- expect(third.status).toBe(403);
620
- });
621
-
622
- it("a batch is subject to the write-origin allow-list", async () => {
623
- const strictApp = await buildHttpTransportApp({
624
- ...BATCH_CONFIG,
625
- cors: { writeAllowedOrigins: [] as string[] },
626
- });
627
- await strictApp.listen({ host: "127.0.0.1", port: 0 });
628
- const strictPort = (strictApp.server.address() as AddressInfo).port;
629
-
630
- try {
631
- const res = await mcpPost(strictPort, [purchaseMessage(49)], {
632
- origin: "https://evil.example",
633
- });
634
- expect(res.status).toBe(403);
635
- const body = (await res.json()) as { error?: string };
636
- expect(body.error).toContain("CORS");
637
- } finally {
638
- await strictApp.close();
639
- }
640
- });
641
-
642
- it("the same protection covers the pre-existing write tools (capture_lead)", async () => {
643
- const leadMessage = (id: number) => ({
644
- jsonrpc: "2.0",
645
- id,
646
- method: "tools/call",
647
- params: {
648
- name: "capture_lead",
649
- arguments: { name: "A", email: "a@example.com" },
650
- },
651
- });
652
-
653
- const res = await mcpPost(port, [
654
- leadMessage(50),
655
- leadMessage(51),
656
- leadMessage(52),
657
- ]);
658
-
659
- expect(res.status).toBe(403);
660
- });
661
-
662
- it("a batch of READ messages is unaffected", async () => {
663
- const res = await mcpPost(port, [TOOLS_LIST_PAYLOAD]);
664
- expect(res.status).toBe(200);
665
- });
666
- });
667
-
668
- /**
669
- * Guardrail — batch coverage is driven from WRITE_TOOLS itself (#5971 security
670
- * review round 2), not from hand-picked names.
671
- *
672
- * The round-1 defect was invisible because every existing test used the
673
- * single-message envelope. A comment on WRITE_TOOLS saying "enforce this
674
- * batch-aware" is the weakest available remedy for a defect whose whole
675
- * character was that nobody thought to send an array — so the inheritance is
676
- * mechanical here: a tool added to WRITE_TOOLS without batch enforcement fails
677
- * this suite on its first run.
678
- *
679
- * The assertion is the write-branch ORIGIN check rather than the cap, because
680
- * it needs no per-tool arguments and no per-tool budget — only two of the four
681
- * write tools carry a daily cap (see DAILY_CAPPED_TOOLS).
682
- */
683
- describe.each([...WRITE_TOOLS])(
684
- "a batch naming %s takes the write branch (#5971)",
685
- (toolName) => {
686
- let app: FastifyInstance;
687
- let port: number;
688
-
689
- beforeEach(async () => {
690
- // Empty allow-list ⇒ a cross-origin write must be refused. On the read
691
- // branch the origin is never consulted, so a 200 here means the batch
692
- // was misclassified.
693
- app = await buildHttpTransportApp({
694
- ...DEFAULT_CONFIG,
695
- cors: { writeAllowedOrigins: [] as string[] },
696
- });
697
- await app.listen({ host: "127.0.0.1", port: 0 });
698
- port = (app.server.address() as AddressInfo).port;
699
- });
700
-
701
- afterEach(async () => {
702
- await app.close();
703
- });
704
-
705
- it("is refused by the write-origin allow-list inside an array body", async () => {
706
- const res = await mcpPost(
707
- port,
708
- [
709
- {
710
- jsonrpc: "2.0",
711
- id: 60,
712
- method: "tools/call",
713
- params: { name: toolName, arguments: {} },
714
- },
715
- ],
716
- { origin: "https://evil.example" },
717
- );
718
-
719
- expect(res.status).toBe(403);
720
- });
721
- },
722
- );
723
-
724
- /**
725
- * Guardrail — a blank or malformed cap must not silently disable enforcement
726
- * (#5971 security review round 2, Medium).
727
- *
728
- * `parseInt("")` is NaN, NaN survives every `??` guard, and `count >= NaN` is
729
- * always false — so the cap stops refusing anything, with no log and no
730
- * startup warning. A misconfigured deployment looks identical to a correct one
731
- * at rest, which is why this is pinned rather than left to convention.
732
- */
733
- describe("a non-finite daily cap falls back to the default, never to unlimited (#5971)", () => {
734
- let app: FastifyInstance;
735
- let port: number;
736
-
737
- afterEach(async () => {
738
- if (app) await app.close();
739
- jest.clearAllMocks();
740
- resetMcpCommerceClaim();
741
- });
742
-
743
- async function startWithCap(cap: number): Promise<void> {
744
- __setMcpCommerceClaimForTest("claimed");
745
- (
746
- checkout.createSession as jest.MockedFunction<
747
- typeof checkout.createSession
748
- >
749
- ).mockResolvedValue({
750
- ok: true,
751
- body: { sessionId: "cs_nan", url: "https://checkout.stripe.com/c/nan" },
752
- });
753
- app = await buildHttpTransportApp({
754
- ...DEFAULT_CONFIG,
755
- cors: { writeAllowedOrigins: ["*"] as string[] },
756
- abuse: {
757
- captureLeadDailyCapPerIp: 50,
758
- startPurchaseDailyCapPerIp: cap,
759
- blockedUserAgents: "",
760
- },
761
- });
762
- await app.listen({ host: "127.0.0.1", port: 0 });
763
- port = (app.server.address() as AddressInfo).port;
764
- }
765
-
766
- it("NaN does not disable the start_purchase cap", async () => {
767
- // What `parseInt("")` on a blank MCP_ABUSE_START_PURCHASE_DAILY_CAP yields.
768
- await startWithCap(Number.NaN);
769
-
770
- // The default (20) must still bite. 21 calls ⇒ the last one is refused.
771
- let lastStatus = 0;
772
- for (let i = 0; i < 21; i += 1) {
773
- const res = await mcpPost(port, {
774
- jsonrpc: "2.0",
775
- id: 70 + i,
776
- method: "tools/call",
777
- params: {
778
- name: "start_purchase",
779
- arguments: { productCode: "growth_monthly" },
780
- },
781
- });
782
- lastStatus = res.status;
783
- }
784
-
785
- expect(lastStatus).toBe(403);
786
- });
787
- });
788
-
789
- /**
790
- * #5994 — the 403-vs-422 split is keyed on a TYPED reason code, never on the
791
- * wording of the refusal reason.
792
- *
793
- * The guard refuses for two different kinds of reason and the transport owes
794
- * them different statuses: a refusal of the CALLER (blocked UA, per-IP daily
795
- * cap) is 403, a refusal of the INPUT (honeypot, malformed email) is 422.
796
- * Before this change the transport told them apart with
797
- * `reason.includes("daily cap")`, so a reworded reason silently turned a
798
- * rate-limit refusal into a 422 — and `capture_lead`'s wording carried the
799
- * substring only by accident ("daily capture_lead cap" contains "daily cap"
800
- * because the tool name starts with "cap").
801
- *
802
- * These tests pin the mapping from the code, and assert the two daily-capped
803
- * tools — whose reason wordings differ — both reach 403 through it.
804
- */
805
- describe("abuse refusal status is keyed on the typed reason code (#5994)", () => {
806
- const CODE_KEYED_CONFIG = {
807
- ...DEFAULT_CONFIG,
808
- cors: { writeAllowedOrigins: ["*"] as string[] },
809
- abuse: {
810
- captureLeadDailyCapPerIp: 1,
811
- startPurchaseDailyCapPerIp: 1,
812
- blockedUserAgents: "",
813
- },
814
- };
815
-
816
- const createSession = checkout.createSession as jest.MockedFunction<
817
- typeof checkout.createSession
818
- >;
819
-
820
- let app: FastifyInstance;
821
- let port: number;
822
-
823
- beforeEach(async () => {
824
- __setMcpCommerceClaimForTest("claimed");
825
- createSession.mockResolvedValue({
826
- ok: true,
827
- body: {
828
- sessionId: "cs_test_5994",
829
- url: "https://checkout.stripe.com/c/pay/cs_test_5994",
830
- },
831
- });
832
- app = await buildHttpTransportApp(CODE_KEYED_CONFIG);
833
- await app.listen({ host: "127.0.0.1", port: 0 });
834
- port = (app.server.address() as AddressInfo).port;
835
- });
836
-
837
- afterEach(async () => {
838
- await app.close();
839
- jest.clearAllMocks();
840
- resetMcpCommerceClaim();
841
- });
842
-
843
- function captureLeadPayload(id: number, args: Record<string, unknown>) {
844
- return {
845
- jsonrpc: "2.0",
846
- id,
847
- method: "tools/call",
848
- params: { name: "capture_lead", arguments: args },
849
- };
850
- }
851
-
852
- it("maps a capture_lead daily-cap refusal to 403", async () => {
853
- // The first call spends the IP's single cap unit. Whatever the handler
854
- // then makes of it is irrelevant here — only the SECOND call, refused in
855
- // the preHandler, is under test.
856
- await mcpPost(
857
- port,
858
- captureLeadPayload(40, { name: "First", email: "first@example.com" }),
859
- );
860
-
861
- const capped = await mcpPost(
862
- port,
863
- captureLeadPayload(41, { name: "Second", email: "second@example.com" }),
864
- );
865
-
866
- expect(capped.status).toBe(403);
867
- });
868
-
869
- it("maps a start_purchase daily-cap refusal to 403", async () => {
870
- const purchase = (id: number) => ({
871
- jsonrpc: "2.0",
872
- id,
873
- method: "tools/call",
874
- params: { name: "start_purchase", arguments: { productCode: "growth_monthly" } },
875
- });
876
-
877
- const first = await mcpPost(port, purchase(42));
878
- const capped = await mcpPost(port, purchase(43));
879
-
880
- expect(first.status).toBe(200);
881
- expect(capped.status).toBe(403);
882
- });
883
-
884
- it("maps a validation refusal to 422", async () => {
885
- const res = await mcpPost(
886
- port,
887
- captureLeadPayload(44, { name: "Spammer", email: "not-an-email" }),
888
- );
889
-
890
- expect(res.status).toBe(422);
891
- });
892
-
893
- /**
894
- * The AbuseGuard reads exactly two things off the request — the
895
- * `user-agent` header and `ip`. The UA here is one the built-in deny list
896
- * lets through, so Rule 4 (the cap) is what refuses these calls rather than
897
- * Rule 1.
898
- */
899
- function makeGuardRequest(): FastifyRequest {
900
- // @ts-expect-error: a stub carrying only the two members the guard reads;
901
- // a full FastifyRequest cannot be constructed without a live server.
902
- return {
903
- headers: { "user-agent": "Mozilla/5.0 (compatible; TestAgent/1.0)" },
904
- ip: "203.0.113.7",
905
- };
906
- }
907
-
908
- it("derives the status from the code alone — the two daily-capped tools word their reasons differently yet both map to 403", () => {
909
- const guard = new AbuseGuard({
910
- captureLeadDailyCapPerIp: 1,
911
- startPurchaseDailyCapPerIp: 1,
912
- blockedUserAgents: "",
913
- });
914
- const request = makeGuardRequest();
915
-
916
- // Spend each tool's single cap unit, then collect the refusal.
917
- guard.validate("capture_lead", {}, request);
918
- guard.validate("start_purchase", {}, request);
919
- const lead = guard.validate("capture_lead", {}, request);
920
- const purchase = guard.validate("start_purchase", {}, request);
921
-
922
- expect(lead.allowed).toBe(false);
923
- expect(purchase.allowed).toBe(false);
924
- if (lead.allowed || purchase.allowed) return;
925
-
926
- // Same code, different wording — the wording is prose for the caller, the
927
- // code is what the transport reads.
928
- expect(lead.code).toBe(AbuseReasonCode.DAILY_CAP_REACHED);
929
- expect(purchase.code).toBe(AbuseReasonCode.DAILY_CAP_REACHED);
930
- expect(lead.reason).not.toBe(purchase.reason);
931
-
932
- expect(ABUSE_REFUSAL_STATUS[lead.code]).toBe(403);
933
- expect(ABUSE_REFUSAL_STATUS[purchase.code]).toBe(403);
934
- });
935
-
936
- it("declares a status for every reason code the guard can return", () => {
937
- expect(Object.keys(ABUSE_REFUSAL_STATUS).sort()).toEqual(
938
- Object.values(AbuseReasonCode).sort(),
939
- );
940
- expect(ABUSE_REFUSAL_STATUS[AbuseReasonCode.BLOCKED_USER_AGENT]).toBe(403);
941
- expect(ABUSE_REFUSAL_STATUS[AbuseReasonCode.HONEYPOT_FILLED]).toBe(422);
942
- expect(ABUSE_REFUSAL_STATUS[AbuseReasonCode.INVALID_EMAIL]).toBe(422);
943
- });
944
- });
945
-
946
- /**
947
- * #8071 — `create_booking` and `submit_flow_step` send caller-chosen data to
948
- * the hub, so they take the same write branch as `capture_lead`: the
949
- * write-origin allow-list, then the AbuseGuard once per call — each on its OWN
950
- * daily-cap tracker.
951
- *
952
- * Every assertion here is a refusal the preHandler makes, so the suite holds
953
- * in a scaffold that does not register the tool (no `scheduling` or
954
- * `signal-collectors` module): the hub stub is checked for "no request for the
955
- * refused call", never for a count the handler would have to produce.
956
- */
957
- const HUB_WRITE_TOOLS = [
958
- {
959
- toolName: "create_booking",
960
- capField: "createBookingDailyCapPerIp",
961
- hubStub: () => apiClient.schedule.book as jest.Mock,
962
- args: () => ({
963
- calLink: "acme/intro",
964
- start: "2030-01-07T15:00:00.000Z",
965
- attendee: { name: "Ada", email: "ada@example.com" },
966
- }),
967
- },
968
- {
969
- toolName: "submit_flow_step",
970
- capField: "submitFlowStepDailyCapPerIp",
971
- hubStub: () => apiClient.flows.submitStep as jest.Mock,
972
- args: () => ({
973
- slug: "intake",
974
- stepKey: "contact",
975
- values: { company: "Acme" },
976
- }),
977
- },
978
- ] as const;
979
-
980
- describe.each(HUB_WRITE_TOOLS)(
981
- "$toolName takes the write branch of the HTTP guard (#8071)",
982
- ({ toolName, capField, hubStub, args }) => {
983
- const CAP = 2;
984
- const config = {
985
- ...DEFAULT_CONFIG,
986
- cors: { writeAllowedOrigins: ["https://allowed.example"] as string[] },
987
- abuse: {
988
- captureLeadDailyCapPerIp: 50,
989
- startPurchaseDailyCapPerIp: 20,
990
- [capField]: CAP,
991
- blockedUserAgents: "",
992
- },
993
- };
994
-
995
- let app: FastifyInstance;
996
- let port: number;
997
-
998
- function call(id: number, callArgs: object = args()) {
999
- return {
1000
- jsonrpc: "2.0",
1001
- id,
1002
- method: "tools/call",
1003
- params: { name: toolName, arguments: callArgs },
1004
- };
1005
- }
1006
-
1007
- beforeEach(async () => {
1008
- hubStub().mockResolvedValue({ ok: false, status: 503, body: {} });
1009
- app = await buildHttpTransportApp(config);
1010
- await app.listen({ host: "127.0.0.1", port: 0 });
1011
- port = (app.server.address() as AddressInfo).port;
1012
- });
1013
-
1014
- afterEach(async () => {
1015
- await app.close();
1016
- jest.clearAllMocks();
1017
- });
1018
-
1019
- it("is a member of WRITE_TOOLS", () => {
1020
- expect(WRITE_TOOLS.has(toolName)).toBe(true);
1021
- });
1022
-
1023
- it("refuses a call from an origin not on writeAllowedOrigins with 403", async () => {
1024
- const res = await mcpPost(port, call(80), {
1025
- origin: "https://evil.example",
1026
- });
1027
-
1028
- expect(res.status).toBe(403);
1029
- const body = (await res.json()) as { error?: string };
1030
- expect(body.error).toContain("CORS");
1031
- expect(hubStub()).not.toHaveBeenCalled();
1032
- });
1033
-
1034
- it("refuses the call past its daily cap with 403, and the hub gets no request for it", async () => {
1035
- for (let i = 0; i < CAP; i += 1) {
1036
- const res = await mcpPost(port, call(81 + i));
1037
- expect(res.status).toBe(200);
1038
- }
1039
- const hubCallsBefore = hubStub().mock.calls.length;
1040
-
1041
- const capped = await mcpPost(port, call(90));
1042
-
1043
- expect(capped.status).toBe(403);
1044
- const body = (await capped.json()) as { error?: string };
1045
- expect(body.error).toContain(toolName);
1046
- expect(hubStub().mock.calls.length).toBe(hubCallsBefore);
1047
- });
1048
-
1049
- it("a batch of N calls charges N cap units", async () => {
1050
- const res = await mcpPost(port, [call(91), call(92), call(93)]);
1051
-
1052
- expect(res.status).toBe(403);
1053
- expect(hubStub()).not.toHaveBeenCalled();
1054
- });
1055
-
1056
- it("its cap is its own — spending it leaves capture_lead callable", async () => {
1057
- for (let i = 0; i < CAP; i += 1) await mcpPost(port, call(94 + i));
1058
- expect((await mcpPost(port, call(97))).status).toBe(403);
1059
-
1060
- const lead = await mcpPost(port, {
1061
- jsonrpc: "2.0",
1062
- id: 98,
1063
- method: "tools/call",
1064
- params: {
1065
- name: "capture_lead",
1066
- arguments: { name: "Ada", email: "ada@example.com" },
1067
- },
1068
- });
1069
- expect(lead.status).not.toBe(403);
1070
- });
1071
-
1072
- it("a refusal maps through the typed code: past the cap is DAILY_CAP_REACHED", () => {
1073
- const guard = new AbuseGuard({
1074
- captureLeadDailyCapPerIp: 50,
1075
- [capField]: 1,
1076
- blockedUserAgents: "",
1077
- });
1078
- // @ts-expect-error: a stub carrying only the two members the guard reads.
1079
- const request: FastifyRequest = {
1080
- headers: { "user-agent": "Mozilla/5.0 (compatible; TestAgent/1.0)" },
1081
- ip: "203.0.113.9",
1082
- };
1083
-
1084
- expect(guard.validate(toolName, args(), request).allowed).toBe(true);
1085
- const refused = guard.validate(toolName, args(), request);
1086
-
1087
- expect(refused.allowed).toBe(false);
1088
- if (refused.allowed) return;
1089
- expect(refused.code).toBe(AbuseReasonCode.DAILY_CAP_REACHED);
1090
- expect(ABUSE_REFUSAL_STATUS[refused.code]).toBe(403);
1091
- });
1092
- },
1093
- );
1094
-
1095
- describe("create_booking — attendee.email is format-checked before the hub (#8071)", () => {
1096
- let app: FastifyInstance;
1097
- let port: number;
1098
-
1099
- const book = () => apiClient.schedule.book as jest.Mock;
1100
-
1101
- function booking(id: number, attendee: unknown) {
1102
- return {
1103
- jsonrpc: "2.0",
1104
- id,
1105
- method: "tools/call",
1106
- params: {
1107
- name: "create_booking",
1108
- arguments: {
1109
- calLink: "acme/intro",
1110
- start: "2030-01-07T15:00:00.000Z",
1111
- attendee,
1112
- },
1113
- },
1114
- };
1115
- }
1116
-
1117
- beforeEach(async () => {
1118
- book().mockResolvedValue({ ok: false, status: 503, body: {} });
1119
- app = await buildHttpTransportApp(DEFAULT_CONFIG);
1120
- await app.listen({ host: "127.0.0.1", port: 0 });
1121
- port = (app.server.address() as AddressInfo).port;
1122
- });
1123
-
1124
- afterEach(async () => {
1125
- await app.close();
1126
- jest.clearAllMocks();
1127
- });
1128
-
1129
- it("refuses a malformed attendee.email with 422 and leaves the hub stub untouched", async () => {
1130
- const res = await mcpPost(
1131
- port,
1132
- booking(100, { name: "Spammer", email: "not-an-email" }),
1133
- );
1134
-
1135
- expect(res.status).toBe(422);
1136
- const body = (await res.json()) as { error?: string };
1137
- expect(body.error).toContain("email");
1138
- expect(book()).not.toHaveBeenCalled();
1139
- });
1140
-
1141
- it.each([null, "ada@example.com", ["ada@example.com"], 42])(
1142
- "a non-object attendee (%p) is not a guard refusal and never a 500",
1143
- async (attendee) => {
1144
- const res = await mcpPost(port, booking(101, attendee));
1145
-
1146
- // The handler's own Zod schema is the authority on the shape.
1147
- expect(res.status).toBe(200);
1148
- expect(book()).not.toHaveBeenCalled();
1149
- },
1150
- );
1151
- });