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