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,1426 +0,0 @@
1
- /**
2
- * The Offerings checkout (#8931; spec
3
- * docs/specs/8931-offerings-checkout-authorization-server-side-spec.md AC-1 …
4
- * AC-6 and AC-3's composed A9 and A13 cases; contract A-T1, A-T2, A-T3).
5
- *
6
- * The harness drives `checkoutRoutes` through `app.inject()` on a Fastify
7
- * instance configured as `server.ts` configures its own (`trustProxy`, the
8
- * `req` serializer), with a logger whose stream captures every line.
9
- * Mocked: the resolver, `store.js`, `connection.js`, the session record store
10
- * and `chargeWriteBudget`. Real: `getSellableProductIds`, `normalizeCatalog`,
11
- * `parseLookupKey` and the `stripe-client` calls, run against a fake client
12
- * object. `STRIPE_SECRET_KEY` is unset, so any env-path answer is
13
- * `500 stripe-not-configured`, distinguishable from every Offerings answer.
14
- * The A9 cases set a composed `sk_test_` key and mock the `stripe` SDK, so the
15
- * real `createCheckoutSession` runs the real `isOfferingsProduct`; the #9126
16
- * cases set one too, so the env path they keep is a sale, not a 500.
17
- */
18
- import { Writable } from "node:stream";
19
-
20
- import { logger } from "@working-theory/observability";
21
- import Fastify, { type FastifyInstance } from "fastify";
22
-
23
- jest.mock("@working-theory/analytics/server", () => ({
24
- track: jest.fn().mockResolvedValue(undefined),
25
- }));
26
- // `server.ts` (for `requestLogSerializer`) reaches the email package, whose
27
- // React Email dependency is ESM-only.
28
- jest.mock("@working-theory/email", () => ({
29
- sendLeadNotification: jest.fn().mockResolvedValue({ ok: true }),
30
- }));
31
-
32
- const mockEnvPricesList = jest.fn();
33
- const mockEnvSessionsCreate = jest.fn();
34
- const mockEnvSessionsRetrieve = jest.fn();
35
- const mockEnvCustomersCreate = jest.fn();
36
- jest.mock("stripe", () =>
37
- jest.fn().mockImplementation(() => ({
38
- prices: { list: mockEnvPricesList },
39
- customers: { create: mockEnvCustomersCreate },
40
- checkout: {
41
- sessions: {
42
- create: mockEnvSessionsCreate,
43
- retrieve: mockEnvSessionsRetrieve,
44
- },
45
- },
46
- })),
47
- );
48
-
49
- // eslint-disable-next-line no-restricted-syntax -- jest mock factory must be hoisted; the DB boundary, mirrors sessions.test.ts
50
- jest.mock("../../../lib/prisma.js", () => ({
51
- prisma: {
52
- session: { findUnique: jest.fn() },
53
- user: { findUnique: jest.fn() },
54
- apiToken: { findUnique: jest.fn(), update: jest.fn() },
55
- },
56
- }));
57
-
58
- const mockResolvePublicWorkspace = jest.fn();
59
- // eslint-disable-next-line no-restricted-syntax -- the resolver reads the spoke registry and the workspace table; the spec's harness (§5) stubs its answers.
60
- jest.mock("../../../services/public-site-resolver.js", () => ({
61
- ...jest.requireActual("../../../services/public-site-resolver.js"),
62
- resolvePublicWorkspace: (...args: unknown[]) =>
63
- mockResolvePublicWorkspace(...args),
64
- }));
65
-
66
- const mockOrganizationIdOfWorkspace = jest.fn();
67
- const mockReadWorkspaceSelection = jest.fn();
68
- const mockReadEnabledProductIds = jest.fn();
69
- const mockReadWorkspaceSnapshot = jest.fn();
70
- // eslint-disable-next-line no-restricted-syntax -- store.js is the Offerings rows' one database file (#8876); the rows are stubbed here, the readers above them run as themselves.
71
- jest.mock("../../../services/offerings/store.js", () => ({
72
- ...jest.requireActual("../../../services/offerings/store.js"),
73
- organizationIdOfWorkspace: (...args: unknown[]) =>
74
- mockOrganizationIdOfWorkspace(...args),
75
- readWorkspaceSelection: (...args: unknown[]) =>
76
- mockReadWorkspaceSelection(...args),
77
- readEnabledProductIds: (...args: unknown[]) =>
78
- mockReadEnabledProductIds(...args),
79
- readWorkspaceSnapshot: (...args: unknown[]) =>
80
- mockReadWorkspaceSnapshot(...args),
81
- }));
82
-
83
- const mockConnectionSummary = jest.fn();
84
- const mockClientForOrganization = jest.fn();
85
- // eslint-disable-next-line no-restricted-syntax -- the connection custody wraps the database and the AES-GCM key (#8907); the spec's harness stubs its two answers.
86
- jest.mock("../../../services/offerings/connection.js", () => ({
87
- getStripeConnectionSummary: (...args: unknown[]) =>
88
- mockConnectionSummary(...args),
89
- // The connection state Offerings sells on (#9285): the stub answers both.
90
- getOfferingsConnectionState: (...args: unknown[]) =>
91
- mockConnectionSummary(...args),
92
- stripeClientForOrganization: (...args: unknown[]) =>
93
- mockClientForOrganization(...args),
94
- }));
95
-
96
- const mockRecordCheckoutSession = jest.fn();
97
- const mockReadCheckoutSessionRecord = jest.fn();
98
- // eslint-disable-next-line no-restricted-syntax -- the session record wraps the database (#8930); its write and read are stubbed.
99
- jest.mock("../../../services/offerings/checkout-session-record.js", () => ({
100
- ...jest.requireActual(
101
- "../../../services/offerings/checkout-session-record.js",
102
- ),
103
- recordCheckoutSession: (...args: unknown[]) =>
104
- mockRecordCheckoutSession(...args),
105
- readCheckoutSessionRecord: (...args: unknown[]) =>
106
- mockReadCheckoutSessionRecord(...args),
107
- }));
108
-
109
- const mockChargeWriteBudget = jest.fn();
110
- // eslint-disable-next-line no-restricted-syntax -- chargeWriteBudget runs on the database store (#8907); the bucket's answers are stubbed, the rest of the module is real.
111
- jest.mock("../../../middleware/rate-limit.js", () => ({
112
- ...jest.requireActual("../../../middleware/rate-limit.js"),
113
- chargeWriteBudget: (...args: unknown[]) => mockChargeWriteBudget(...args),
114
- }));
115
-
116
- import { config } from "../../../config/index.js";
117
- import { prisma } from "../../../lib/prisma.js";
118
- import { requestLogSerializer } from "../../../server.js";
119
- import { CheckoutSessionRecordError } from "../../../services/offerings/checkout-session-record.js";
120
- import { checkoutRoutes } from "../index";
121
-
122
- config.FRONTEND_URL = "https://example.com";
123
- config.TRUSTED_ORIGINS = ["https://example.com"];
124
-
125
- /** The mocked SDK constructor: a call to it is the env client being built. */
126
- const envStripeConstructor = () => jest.requireMock("stripe") as jest.Mock;
127
-
128
- // ── Fixture ──────────────────────────────────────────────────────────────────
129
-
130
- const WS = "wksp_00000000-0000-7000-8000-000000008931";
131
- const ORG = "org_00000000-0000-7000-8000-000000008931";
132
- const SESSION_ID = "cs_test_a1B2c3D4e5F6g7H8offerings8931";
133
- const SESSION_URL = `https://checkout.stripe.com/c/pay/${SESSION_ID}`;
134
- const SUMMARY = {
135
- mode: "test",
136
- last4: "4242",
137
- connectedAt: "2026-10-18T00:00:00.000Z",
138
- liveAt: null,
139
- updatedAt: "2026-10-18T00:00:00.000Z",
140
- };
141
-
142
- function product(id: string, overrides: Record<string, unknown> = {}) {
143
- return {
144
- id,
145
- object: "product",
146
- active: true,
147
- name: `Product ${id.slice(5)}`,
148
- metadata: { ailk_group: "plan" },
149
- ...overrides,
150
- };
151
- }
152
-
153
- function recurringPrice(id: string, lookupKey: string, prod: unknown) {
154
- return {
155
- id,
156
- object: "price",
157
- active: true,
158
- product: prod,
159
- lookup_key: lookupKey,
160
- type: "recurring",
161
- recurring: { interval: "month", interval_count: 1, usage_type: "licensed" },
162
- billing_scheme: "per_unit",
163
- unit_amount: 2900,
164
- currency: "usd",
165
- };
166
- }
167
-
168
- function oneTimePrice(id: string, lookupKey: string, prod: unknown) {
169
- return {
170
- id,
171
- object: "price",
172
- active: true,
173
- product: prod,
174
- lookup_key: lookupKey,
175
- type: "one_time",
176
- recurring: null,
177
- billing_scheme: "per_unit",
178
- unit_amount: 9900,
179
- currency: "usd",
180
- };
181
- }
182
-
183
- const PROD_A = product("prod_A8931");
184
- const PROD_B = product("prod_B8931");
185
- const PROD_C = product("prod_C8931");
186
- const PROD_D = product("prod_D8931");
187
- const PROD_X = product("prod_X8931");
188
- const PRICE_A = recurringPrice("price_A8931growth", "growth_monthly", PROD_A);
189
- const PRICE_B = recurringPrice("price_B8931scale", "scale_monthly", PROD_B);
190
- const PRICE_C = recurringPrice("price_C8931team", "team_monthly", PROD_C);
191
- const PRICE_D = oneTimePrice("price_D8931basic", "basic_once", PROD_D);
192
- /** PROD_A's yearly Price, for the per-Price shown set (#9070 D5). */
193
- const PRICE_A_YEARLY = {
194
- ...recurringPrice("price_A8931growthyear", "growth_yearly", PROD_A),
195
- recurring: { interval: "year", interval_count: 1, usage_type: "licensed" },
196
- unit_amount: 29000,
197
- };
198
- const PRICE_MOVED = recurringPrice(
199
- "price_X8931moved",
200
- "growth_monthly",
201
- PROD_X,
202
- );
203
-
204
- /** Every id, key and URL that must never reach a log line or a refusal body (AC-6). */
205
- const SECRETS = [
206
- "growth_monthly",
207
- "growth_yearly",
208
- "scale_monthly",
209
- "team_monthly",
210
- "basic_once",
211
- "enterprise_monthly",
212
- "Growth_Monthly",
213
- "growth_pro_monthly",
214
- "wendi_retainer",
215
- "ailk-pro-plus_monthly",
216
- "ailk-pro_yearly",
217
- PROD_A.id,
218
- PROD_B.id,
219
- PROD_C.id,
220
- PROD_D.id,
221
- PROD_X.id,
222
- PRICE_A.id,
223
- PRICE_A_YEARLY.id,
224
- PRICE_B.id,
225
- PRICE_C.id,
226
- PRICE_D.id,
227
- PRICE_MOVED.id,
228
- SESSION_ID,
229
- SESSION_URL,
230
- ];
231
-
232
- const BODY = {
233
- productCode: "growth_monthly",
234
- successUrl: "https://example.com/thanks",
235
- cancelUrl: "https://example.com/pricing",
236
- };
237
-
238
- type Fake = ReturnType<typeof fakeClient>;
239
-
240
- /** The Organization's own client: `prices.list` answers from `catalog` by key. */
241
- function fakeClient(
242
- catalog: Record<string, unknown[]> = { growth_monthly: [PRICE_A] },
243
- ) {
244
- return {
245
- prices: {
246
- list: jest.fn(async (params: { lookup_keys: string[] }) => ({
247
- data: catalog[params.lookup_keys[0]!] ?? [],
248
- })),
249
- },
250
- checkout: {
251
- sessions: {
252
- create: jest
253
- .fn()
254
- .mockResolvedValue({ id: SESSION_ID, url: SESSION_URL }),
255
- expire: jest.fn().mockResolvedValue({}),
256
- retrieve: jest.fn(),
257
- },
258
- },
259
- };
260
- }
261
-
262
- // ── The log capture (AC-6) ──────────────────────────────────────────────────
263
-
264
- const logged: string[] = [];
265
- const bodies: Array<{ status: number; body: string }> = [];
266
-
267
- function captureStream(): Writable {
268
- return new Writable({
269
- write(chunk, _enc, done) {
270
- logged.push(chunk.toString());
271
- done();
272
- },
273
- });
274
- }
275
-
276
- function buildApp(): FastifyInstance {
277
- const app = Fastify({
278
- logger: {
279
- level: "info",
280
- stream: captureStream(),
281
- serializers: { req: requestLogSerializer },
282
- },
283
- trustProxy: true,
284
- });
285
- app.register(checkoutRoutes);
286
- return app;
287
- }
288
-
289
- let app: FastifyInstance;
290
- let client: Fake;
291
- const savedKey = process.env.STRIPE_SECRET_KEY;
292
- const savedDatabaseUrl = process.env.DATABASE_URL;
293
-
294
- async function post(
295
- body: Record<string, unknown> = BODY,
296
- headers: Record<string, string> = {},
297
- ) {
298
- const res = await app.inject({
299
- method: "POST",
300
- url: "/v1/checkout/sessions",
301
- payload: body,
302
- headers,
303
- });
304
- bodies.push({ status: res.statusCode, body: res.body });
305
- return res;
306
- }
307
-
308
- async function get(id = SESSION_ID) {
309
- const res = await app.inject({
310
- method: "GET",
311
- url: `/v1/checkout/sessions/${id}`,
312
- });
313
- bodies.push({ status: res.statusCode, body: res.body });
314
- return res;
315
- }
316
-
317
- function givenRows(enabled: string[], shown: string[], shownPrices: string[] = []) {
318
- mockReadEnabledProductIds.mockResolvedValue(enabled);
319
- mockReadWorkspaceSelection.mockResolvedValue({
320
- shownProductIds: shown,
321
- shownPriceIds: shownPrices,
322
- recommendedPlanProductId: null,
323
- recommendedAddonProductId: null,
324
- });
325
- }
326
-
327
- beforeAll(() => {
328
- for (const level of ["info", "warn", "error", "debug"] as const) {
329
- jest.spyOn(logger, level).mockImplementation(((...args: unknown[]) => {
330
- logged.push(JSON.stringify(args));
331
- }) as never);
332
- }
333
- });
334
-
335
- beforeEach(async () => {
336
- jest.clearAllMocks();
337
- delete process.env.STRIPE_SECRET_KEY;
338
- process.env.DATABASE_URL = savedDatabaseUrl;
339
- client = fakeClient();
340
- mockResolvePublicWorkspace.mockResolvedValue({
341
- kind: "resolved",
342
- workspaceId: WS,
343
- });
344
- mockOrganizationIdOfWorkspace.mockResolvedValue(ORG);
345
- mockConnectionSummary.mockResolvedValue(SUMMARY);
346
- mockClientForOrganization.mockImplementation(async () => ({
347
- kind: "ok",
348
- client,
349
- mode: "test",
350
- }));
351
- givenRows([PROD_A.id, PROD_B.id], [PROD_A.id, PROD_C.id]);
352
- mockReadWorkspaceSnapshot.mockResolvedValue(null);
353
- mockRecordCheckoutSession.mockResolvedValue(undefined);
354
- mockReadCheckoutSessionRecord.mockResolvedValue(null);
355
- mockChargeWriteBudget.mockResolvedValue({ ok: true });
356
- app = buildApp();
357
- await app.ready();
358
- });
359
-
360
- afterEach(async () => {
361
- await app.close();
362
- });
363
-
364
- afterAll(() => {
365
- process.env.STRIPE_SECRET_KEY = savedKey;
366
- process.env.DATABASE_URL = savedDatabaseUrl;
367
- });
368
-
369
- // ── AC-1: one identical 404 for every miss (A3, A4, A5, A-T1, A-T2) ─────────
370
-
371
- describe("AC-1 — every miss is one 404 that never echoes the key", () => {
372
- const NOT_FOUND = JSON.stringify({ error: "unknown-product-code" });
373
-
374
- function expectMiss(res: { statusCode: number; body: string }, key: string) {
375
- expect(res.statusCode).toBe(404);
376
- expect(res.body).toBe(NOT_FOUND);
377
- expect(res.body).not.toContain(key);
378
- expect(client.checkout.sessions.create).not.toHaveBeenCalled();
379
- expect(mockRecordCheckoutSession).not.toHaveBeenCalled();
380
- }
381
-
382
- it.each<[string, string, Record<string, unknown[]>]>([
383
- ["enabled but not shown", "scale_monthly", { scale_monthly: [PRICE_B] }],
384
- ["shown but not enabled", "team_monthly", { team_monthly: [PRICE_C] }],
385
- [
386
- "moved to another Product",
387
- "growth_monthly",
388
- { growth_monthly: [PRICE_MOVED] },
389
- ],
390
- ["nonexistent", "enterprise_monthly", {}],
391
- ])("a key %s answers the 404", async (_label, key, catalog) => {
392
- client = fakeClient(catalog);
393
- const res = await post({ ...BODY, productCode: key });
394
- expectMiss(res, key);
395
- expect(client.prices.list).toHaveBeenCalledTimes(1);
396
- });
397
-
398
- it.each(["Growth_Monthly", "growth_pro_monthly", "wendi_retainer"])(
399
- "the ungrammatical %s answers the 404 with no Stripe or database call",
400
- async (key) => {
401
- const res = await post({ ...BODY, productCode: key });
402
- expectMiss(res, key);
403
- expect(client.prices.list).not.toHaveBeenCalled();
404
- expect(mockClientForOrganization).not.toHaveBeenCalled();
405
- expect(mockReadWorkspaceSelection).not.toHaveBeenCalled();
406
- },
407
- );
408
-
409
- it("a key in the shown set's snapshot but not the live read answers 404 with no session (A-T2)", async () => {
410
- mockReadWorkspaceSnapshot.mockResolvedValue({
411
- snapshot: {
412
- offerings: [
413
- { productId: PROD_A.id, prices: [{ lookupKey: "growth_monthly" }] },
414
- ],
415
- },
416
- snapshotAt: new Date(),
417
- });
418
- client = fakeClient({});
419
- const res = await post();
420
- expectMiss(res, "growth_monthly");
421
- expect(mockReadWorkspaceSnapshot).not.toHaveBeenCalled();
422
- });
423
-
424
- it("the same fixtures sell growth_monthly (so each 404 above is the check, not the fixture)", async () => {
425
- const res = await post();
426
- expect(res.statusCode).toBe(201);
427
- });
428
-
429
- it("a workspace that sells nothing answers the 404 with no Stripe call", async () => {
430
- givenRows([PROD_A.id], [PROD_C.id]);
431
- const res = await post();
432
- expectMiss(res, "growth_monthly");
433
- expect(client.prices.list).not.toHaveBeenCalled();
434
- });
435
-
436
- it("a Price whose period disagrees with its key answers the 404", async () => {
437
- const yearly = {
438
- ...PRICE_A,
439
- recurring: {
440
- interval: "year",
441
- interval_count: 1,
442
- usage_type: "licensed",
443
- },
444
- };
445
- client = fakeClient({ growth_monthly: [yearly] });
446
- expectMiss(await post(), "growth_monthly");
447
- });
448
-
449
- it("a Product the normalizer holds (no ailk_group) answers the 404", async () => {
450
- const unmarked = recurringPrice(PRICE_A.id, "growth_monthly", {
451
- ...PROD_A,
452
- metadata: {},
453
- });
454
- client = fakeClient({ growth_monthly: [unmarked] });
455
- expectMiss(await post(), "growth_monthly");
456
- });
457
- });
458
-
459
- // ── #9338 DD5: the Offerings path never sells a hub plan ───────────────────
460
-
461
- describe("#9338 DD5 (AC-5) — the anonymous Offerings path refuses the hub's plans", () => {
462
- const PROD_HUB = product("prod_Hub9338");
463
- const HUB_PP_MONTHLY = recurringPrice("price_Hub9338ppm", "ailk-pro-plus_monthly", PROD_HUB);
464
- const HUB_PRO_YEARLY = {
465
- ...recurringPrice("price_Hub9338proy", "ailk-pro_yearly", PROD_HUB),
466
- recurring: { interval: "year", interval_count: 1, usage_type: "licensed" },
467
- };
468
-
469
- beforeEach(() => {
470
- // The hub Product is enabled AND shown, so only the guard can refuse it.
471
- givenRows([PROD_A.id, PROD_HUB.id], [PROD_A.id, PROD_HUB.id]);
472
- client = fakeClient({
473
- growth_monthly: [PRICE_A],
474
- "ailk-pro-plus_monthly": [HUB_PP_MONTHLY],
475
- "ailk-pro_yearly": [HUB_PRO_YEARLY],
476
- });
477
- });
478
-
479
- it.each(["ailk-pro-plus_monthly", "ailk-pro_yearly"])(
480
- "%s, shown and enabled, answers the one 404 before any read or Stripe call",
481
- async (key) => {
482
- const res = await post({ ...BODY, productCode: key });
483
- expect(res.statusCode).toBe(404);
484
- expect(res.body).toBe(JSON.stringify({ error: "unknown-product-code" }));
485
- expect(mockClientForOrganization).not.toHaveBeenCalled();
486
- expect(mockReadEnabledProductIds).not.toHaveBeenCalled();
487
- expect(mockReadWorkspaceSelection).not.toHaveBeenCalled();
488
- expect(client.prices.list).not.toHaveBeenCalled();
489
- expect(client.checkout.sessions.create).not.toHaveBeenCalled();
490
- expect(mockRecordCheckoutSession).not.toHaveBeenCalled();
491
- },
492
- );
493
-
494
- it("growth_monthly from the same fixtures still sells", async () => {
495
- const res = await post();
496
- expect(res.statusCode).toBe(201);
497
- });
498
- });
499
-
500
- // ── AC-2: the stamped, anonymous, recorded session (A6, A7, A11) ────────────
501
-
502
- describe("#9070 D5 (AC-5) — a workspace saved per Price sells only its shown Prices", () => {
503
- const catalog = { growth_monthly: [PRICE_A], growth_yearly: [PRICE_A_YEARLY] };
504
-
505
- it("sells the shown yearly Price and refuses its switched-off monthly sibling as the one 404", async () => {
506
- client = fakeClient(catalog);
507
- givenRows([PROD_A.id], [PROD_A.id], [PRICE_A_YEARLY.id]);
508
-
509
- const yearly = await post({ ...BODY, productCode: "growth_yearly" });
510
- expect(yearly.statusCode).toBe(201);
511
- expect(client.checkout.sessions.create).toHaveBeenCalledTimes(1);
512
- expect(client.checkout.sessions.create.mock.calls[0][0].line_items).toEqual([
513
- { price: PRICE_A_YEARLY.id, quantity: 1 },
514
- ]);
515
-
516
- jest.clearAllMocks();
517
- const monthly = await post();
518
- expect(monthly.statusCode).toBe(404);
519
- expect(monthly.json()).toEqual({ error: "unknown-product-code" });
520
- expect(monthly.body).not.toContain("growth_monthly");
521
- expect(client.checkout.sessions.create).not.toHaveBeenCalled();
522
- expect(mockRecordCheckoutSession).not.toHaveBeenCalled();
523
- });
524
-
525
- it("with no stored Prices both Prices of a shown Product sell", async () => {
526
- client = fakeClient(catalog);
527
- givenRows([PROD_A.id], [PROD_A.id]);
528
-
529
- expect((await post({ ...BODY, productCode: "growth_yearly" })).statusCode).toBe(201);
530
- expect((await post()).statusCode).toBe(201);
531
- expect(client.checkout.sessions.create).toHaveBeenCalledTimes(2);
532
- });
533
- });
534
-
535
- describe("AC-2 — an authorized key sells its Price in a stamped hosted session", () => {
536
- it("answers 201 { sessionId, url } from a session created for the authorized Price", async () => {
537
- const res = await post();
538
-
539
- expect(res.statusCode).toBe(201);
540
- expect(res.json()).toEqual({ sessionId: SESSION_ID, url: SESSION_URL });
541
- expect(client.prices.list).toHaveBeenCalledTimes(1);
542
- expect(client.prices.list).toHaveBeenCalledWith({
543
- lookup_keys: ["growth_monthly"],
544
- active: true,
545
- limit: 1,
546
- expand: ["data.product"],
547
- });
548
- expect(client.checkout.sessions.create).toHaveBeenCalledTimes(1);
549
- const params = client.checkout.sessions.create.mock.calls[0][0];
550
- expect(params.line_items).toEqual([{ price: PRICE_A.id, quantity: 1 }]);
551
- expect(params.mode).toBe("subscription");
552
- expect(params.allow_promotion_codes).toBe(true);
553
- expect(Object.keys(params.metadata).sort()).toEqual([
554
- "ailk_offering",
555
- "ailk_terms",
556
- "site",
557
- ]);
558
- expect(params.metadata.site).toBe(WS);
559
- expect(params.metadata.ailk_offering).toBe("growth_monthly");
560
- expect(params.subscription_data).toEqual({
561
- metadata: { site: WS, ailk_offering: "growth_monthly" },
562
- });
563
- expect(params).not.toHaveProperty("customer");
564
- expect(params).not.toHaveProperty("customer_creation");
565
- // The env client is never built.
566
- expect(envStripeConstructor()).not.toHaveBeenCalled();
567
- });
568
-
569
- it("allows promotion codes even when the body says false (C3)", async () => {
570
- await post({ ...BODY, allowPromotionCodes: false });
571
- expect(
572
- client.checkout.sessions.create.mock.calls[0][0].allow_promotion_codes,
573
- ).toBe(true);
574
- });
575
-
576
- it("a one-time Price opens a payment session that creates a customer, with no subscription_data", async () => {
577
- givenRows([PROD_D.id], [PROD_D.id]);
578
- client = fakeClient({ basic_once: [PRICE_D] });
579
-
580
- const res = await post({ ...BODY, productCode: "basic_once" });
581
-
582
- expect(res.statusCode).toBe(201);
583
- const params = client.checkout.sessions.create.mock.calls[0][0];
584
- expect(params.mode).toBe("payment");
585
- expect(params.customer_creation).toBe("always");
586
- expect(params).not.toHaveProperty("subscription_data");
587
- expect(params).not.toHaveProperty("customer");
588
- });
589
-
590
- it("a signed-in cookie is never read and no param carries ailk_user_id (C4)", async () => {
591
- (prisma.session.findUnique as jest.Mock).mockResolvedValue({
592
- id: "ses_1",
593
- userId: "usr_buyer",
594
- expiresAt: new Date(Date.now() + 60_000),
595
- activeOrganizationId: null,
596
- activeWorkspaceId: null,
597
- });
598
- (prisma.user.findUnique as jest.Mock).mockResolvedValue({
599
- id: "usr_buyer",
600
- email: "buyer@example.com",
601
- emailVerified: true,
602
- billingProvider: null,
603
- billingCustomerId: null,
604
- });
605
-
606
- const res = await post(BODY, {
607
- cookie: "better-auth.session_token=sess_tok_buyer.signature",
608
- origin: "https://example.com",
609
- });
610
-
611
- expect(res.statusCode).toBe(201);
612
- expect(prisma.session.findUnique).not.toHaveBeenCalled();
613
- expect(
614
- JSON.stringify(client.checkout.sessions.create.mock.calls),
615
- ).not.toContain("ailk_user_id");
616
- });
617
-
618
- it("records the session through the keystone store, after the create", async () => {
619
- await post();
620
-
621
- expect(mockRecordCheckoutSession).toHaveBeenCalledTimes(1);
622
- expect(mockRecordCheckoutSession).toHaveBeenCalledWith({
623
- sessionId: SESSION_ID,
624
- workspaceId: WS,
625
- organizationId: ORG,
626
- priceId: PRICE_A.id,
627
- lookupKey: "growth_monthly",
628
- mode: "test",
629
- });
630
- expect(
631
- mockRecordCheckoutSession.mock.invocationCallOrder[0],
632
- ).toBeGreaterThan(
633
- client.checkout.sessions.create.mock.invocationCallOrder[0]!,
634
- );
635
- });
636
-
637
- it("does not answer while the record is pending", async () => {
638
- let release!: () => void;
639
- mockRecordCheckoutSession.mockReturnValue(
640
- new Promise<void>((resolve) => {
641
- release = resolve;
642
- }),
643
- );
644
- let answered = false;
645
- const pending = post().then((res) => {
646
- answered = true;
647
- return res;
648
- });
649
- for (
650
- let i = 0;
651
- i < 20 && mockRecordCheckoutSession.mock.calls.length === 0;
652
- i++
653
- ) {
654
- await new Promise((resolve) => setImmediate(resolve));
655
- }
656
- expect(mockRecordCheckoutSession).toHaveBeenCalledTimes(1);
657
- await new Promise((resolve) => setImmediate(resolve));
658
- expect(answered).toBe(false);
659
-
660
- release();
661
- const res = await pending;
662
- expect(res.statusCode).toBe(201);
663
- });
664
-
665
- it.each([
666
- "invalid",
667
- "workspace_mismatch",
668
- "conflict",
669
- "write_failed",
670
- ] as const)(
671
- "a record that rejects %s expires the session and answers 502",
672
- async (reason) => {
673
- mockRecordCheckoutSession.mockRejectedValue(
674
- new CheckoutSessionRecordError(reason),
675
- );
676
-
677
- const res = await post();
678
-
679
- expect(res.statusCode).toBe(502);
680
- expect(res.json()).toEqual({ error: "checkout-unavailable" });
681
- expect(client.checkout.sessions.expire).toHaveBeenCalledWith(SESSION_ID);
682
- },
683
- );
684
-
685
- it("a budget store that throws answers 502 with no Stripe call (code review #9032)", async () => {
686
- mockChargeWriteBudget.mockRejectedValueOnce(new Error("store down"));
687
-
688
- const res = await post();
689
-
690
- expect(res.statusCode).toBe(502);
691
- expect(res.json()).toEqual({ error: "checkout-unavailable" });
692
- expect(client.checkout.sessions.create).not.toHaveBeenCalled();
693
- });
694
-
695
- it("a failed record whose expire also fails still answers 502", async () => {
696
- mockRecordCheckoutSession.mockRejectedValue(
697
- new CheckoutSessionRecordError("write_failed"),
698
- );
699
- client.checkout.sessions.expire.mockRejectedValue(new Error("stripe down"));
700
-
701
- const res = await post();
702
-
703
- expect(res.statusCode).toBe(502);
704
- expect(res.json()).toEqual({ error: "checkout-unavailable" });
705
- expect(client.checkout.sessions.expire).toHaveBeenCalledWith(SESSION_ID);
706
- });
707
- });
708
-
709
- // ── AC-3: the env path refuses an Offerings product (A9) ────────────────────
710
-
711
- describe("AC-3 (A9) — the env path, composed with the real stripe-client and marker", () => {
712
- beforeEach(() => {
713
- mockResolvePublicWorkspace.mockResolvedValue({ kind: "not-required" });
714
- process.env.STRIPE_SECRET_KEY =
715
- ["sk", "test", ""].join("_") + "OfferingsEnv8931";
716
- mockEnvSessionsCreate.mockResolvedValue({
717
- id: "cs_test_env8931",
718
- url: "https://checkout.stripe.com/c/pay/cs_test_env8931",
719
- });
720
- });
721
-
722
- it.each<[string, unknown]>([
723
- [
724
- "a Product carrying metadata.ailk_group",
725
- { id: "prod_Env1", metadata: { ailk_group: "plan" } },
726
- ],
727
- ["a bare product id the expand did not turn into an object", "prod_Env2"],
728
- ])("%s answers the 404 with no session", async (_label, prod) => {
729
- mockEnvPricesList.mockResolvedValue({
730
- data: [{ id: "price_Env", type: "recurring", product: prod }],
731
- });
732
-
733
- const res = await post({ ...BODY, productCode: "ailk-pro" });
734
-
735
- expect(res.statusCode).toBe(404);
736
- expect(res.json()).toEqual({ error: "unknown-product-code" });
737
- expect(mockEnvPricesList).toHaveBeenCalledWith({
738
- lookup_keys: ["ailk-pro"],
739
- active: true,
740
- limit: 1,
741
- expand: ["data.product"],
742
- });
743
- expect(mockEnvSessionsCreate).not.toHaveBeenCalled();
744
- expect(mockChargeWriteBudget).not.toHaveBeenCalled();
745
- });
746
-
747
- it("the re-keyed Pro Plus (ailk-pro-plus_monthly, ailk_group plan) answers the 404 (#9338 DD5)", async () => {
748
- mockEnvPricesList.mockResolvedValue({
749
- data: [
750
- {
751
- id: "price_EnvPP",
752
- type: "recurring",
753
- product: { id: "prod_EnvPP", metadata: { ailk_group: "plan" } },
754
- },
755
- ],
756
- });
757
-
758
- const res = await post({ ...BODY, productCode: "ailk-pro-plus_monthly" });
759
-
760
- expect(res.statusCode).toBe(404);
761
- expect(res.json()).toEqual({ error: "unknown-product-code" });
762
- expect(mockEnvSessionsCreate).not.toHaveBeenCalled();
763
- });
764
-
765
- it("a Product with no ailk_group still sells on the env path", async () => {
766
- mockEnvPricesList.mockResolvedValue({
767
- data: [
768
- {
769
- id: "price_Env",
770
- type: "recurring",
771
- product: { id: "prod_Env3", metadata: {} },
772
- },
773
- ],
774
- });
775
-
776
- const res = await post({ ...BODY, productCode: "ailk-pro" });
777
-
778
- expect(res.statusCode).toBe(201);
779
- expect(mockEnvSessionsCreate).toHaveBeenCalledTimes(1);
780
- expect(mockEnvSessionsCreate.mock.calls[0][0].metadata).toHaveProperty(
781
- "site",
782
- );
783
- });
784
- });
785
-
786
- // ── AC-3: the session read uses the record's own connection (A13) ───────────
787
-
788
- describe("AC-3 (A13) — GET /v1/checkout/sessions/:id for a recorded session", () => {
789
- const RECORD = {
790
- sessionId: SESSION_ID,
791
- workspaceId: WS,
792
- organizationId: ORG,
793
- priceId: PRICE_A.id,
794
- lookupKey: "growth_monthly",
795
- mode: "test" as const,
796
- createdAt: new Date("2026-10-18T00:00:00Z"),
797
- };
798
- const LONG_NAME = "Growth‮ plan" + "x".repeat(300);
799
-
800
- function stripeSession() {
801
- return {
802
- id: SESSION_ID,
803
- status: "complete",
804
- payment_status: "paid",
805
- currency: "usd",
806
- amount_total: 2900,
807
- line_items: {
808
- data: [
809
- {
810
- description: LONG_NAME,
811
- quantity: 1,
812
- amount_total: 2900,
813
- currency: "usd",
814
- },
815
- ],
816
- },
817
- };
818
- }
819
-
820
- beforeEach(() => {
821
- mockReadCheckoutSessionRecord.mockResolvedValue(RECORD);
822
- client.checkout.sessions.retrieve.mockResolvedValue(stripeSession());
823
- });
824
-
825
- it("reads on the record's connection and serves today's 200 body and headers", async () => {
826
- const res = await get();
827
-
828
- expect(res.statusCode).toBe(200);
829
- expect(mockClientForOrganization).toHaveBeenCalledWith(ORG);
830
- expect(client.checkout.sessions.retrieve).toHaveBeenCalledWith(SESSION_ID, {
831
- expand: ["line_items"],
832
- });
833
- expect(envStripeConstructor()).not.toHaveBeenCalled();
834
- expect(res.headers["cache-control"]).toBe("no-store");
835
- expect(res.headers["x-robots-tag"]).toBe("noindex, nofollow");
836
- expect(res.headers["referrer-policy"]).toBe("no-referrer");
837
- const body = res.json();
838
- expect(Object.keys(body).sort()).toEqual(
839
- [
840
- "amountTotal",
841
- "currency",
842
- "id",
843
- "lineItems",
844
- "paymentStatus",
845
- "status",
846
- ].sort(),
847
- );
848
- expect(body).toMatchObject({
849
- id: SESSION_ID,
850
- status: "complete",
851
- paymentStatus: "paid",
852
- currency: "usd",
853
- amountTotal: 2900,
854
- });
855
- const description: string = body.lineItems[0].description;
856
- expect(description).not.toContain("‮");
857
- expect([...description].length).toBeLessThanOrEqual(200);
858
- expect(description.startsWith("Growth plan")).toBe(true);
859
- });
860
-
861
- it.each<[string, () => void]>([
862
- [
863
- "a connection in another mode",
864
- () =>
865
- mockClientForOrganization.mockResolvedValue({
866
- kind: "ok",
867
- client,
868
- mode: "live",
869
- }),
870
- ],
871
- [
872
- "no connection",
873
- () => mockClientForOrganization.mockResolvedValue({ kind: "none" }),
874
- ],
875
- [
876
- "an unusable connection",
877
- () => mockClientForOrganization.mockResolvedValue({ kind: "unusable" }),
878
- ],
879
- [
880
- "an unreadable record",
881
- () => mockReadCheckoutSessionRecord.mockResolvedValue("unreadable"),
882
- ],
883
- [
884
- "a rejected record read",
885
- () =>
886
- mockReadCheckoutSessionRecord.mockRejectedValue(
887
- new CheckoutSessionRecordError("read_failed"),
888
- ),
889
- ],
890
- [
891
- "a rejected connection read",
892
- () =>
893
- mockClientForOrganization.mockRejectedValue(new Error("store down")),
894
- ],
895
- ])(
896
- "%s answers 502 with no retrieve on any client",
897
- async (_label, arrange) => {
898
- arrange();
899
-
900
- const res = await get();
901
-
902
- expect(res.statusCode).toBe(502);
903
- expect(res.json()).toEqual({ error: "checkout-unavailable" });
904
- expect(client.checkout.sessions.retrieve).not.toHaveBeenCalled();
905
- expect(mockEnvSessionsRetrieve).not.toHaveBeenCalled();
906
- },
907
- );
908
-
909
- it("a recorded session Stripe does not know answers 404 unknown-session", async () => {
910
- client.checkout.sessions.retrieve.mockRejectedValue(
911
- Object.assign(new Error("No such checkout.session"), {
912
- code: "resource_missing",
913
- }),
914
- );
915
- const res = await get();
916
- expect(res.statusCode).toBe(404);
917
- expect(res.json()).toEqual({ error: "unknown-session" });
918
- });
919
-
920
- it("no record answers as the env path does", async () => {
921
- mockReadCheckoutSessionRecord.mockResolvedValue(null);
922
- const res = await get();
923
- expect(res.statusCode).toBe(500);
924
- expect(res.json()).toEqual({ error: "stripe-not-configured" });
925
- expect(client.checkout.sessions.retrieve).not.toHaveBeenCalled();
926
- });
927
-
928
- it("with no database the record store is never called", async () => {
929
- delete process.env.DATABASE_URL;
930
- const res = await get();
931
- expect(mockReadCheckoutSessionRecord).not.toHaveBeenCalled();
932
- expect(res.statusCode).toBe(500);
933
- expect(res.json()).toEqual({ error: "stripe-not-configured" });
934
- });
935
- });
936
-
937
- // ── AC-4: the path decision (A1, A2, A-T3) ──────────────────────────────────
938
-
939
- describe("AC-4 — the workspace is the server's, and a refused spoke key is 503", () => {
940
- it("a refused spoke key answers 503 tenant_unresolved with no Stripe, budget or Organization call", async () => {
941
- mockResolvePublicWorkspace.mockResolvedValue({
942
- kind: "unresolved",
943
- reason: "spoke-refused",
944
- });
945
-
946
- const res = await post(BODY, { "x-ailk-spoke-key": "revoked-key" });
947
-
948
- expect(res.statusCode).toBe(503);
949
- expect(res.json()).toEqual({ error: "tenant_unresolved" });
950
- expect(client.prices.list).not.toHaveBeenCalled();
951
- expect(mockClientForOrganization).not.toHaveBeenCalled();
952
- expect(mockChargeWriteBudget).not.toHaveBeenCalled();
953
- expect(mockOrganizationIdOfWorkspace).not.toHaveBeenCalled();
954
- });
955
-
956
- it.each<[string, () => void]>([
957
- [
958
- "a header-less call refused as key-required",
959
- () =>
960
- mockResolvePublicWorkspace.mockResolvedValue({
961
- kind: "unresolved",
962
- reason: "spoke-refused",
963
- }),
964
- ],
965
- [
966
- "an ambiguous resolution",
967
- () =>
968
- mockResolvePublicWorkspace.mockResolvedValue({
969
- kind: "unresolved",
970
- reason: "ambiguous",
971
- }),
972
- ],
973
- [
974
- "an unmatched host",
975
- () =>
976
- mockResolvePublicWorkspace.mockResolvedValue({
977
- kind: "unresolved",
978
- reason: "host-unmatched",
979
- }),
980
- ],
981
- [
982
- "a deployment off the database adapter",
983
- () =>
984
- mockResolvePublicWorkspace.mockResolvedValue({ kind: "not-required" }),
985
- ],
986
- [
987
- "a workspace with no Organization row",
988
- () => mockOrganizationIdOfWorkspace.mockResolvedValue(null),
989
- ],
990
- [
991
- "an Organization with no connection",
992
- () => mockConnectionSummary.mockResolvedValue(null),
993
- ],
994
- ])("%s takes the env path", async (_label, arrange) => {
995
- arrange();
996
-
997
- const res = await post();
998
-
999
- expect(res.statusCode).toBe(500);
1000
- expect(res.json()).toEqual({ error: "stripe-not-configured" });
1001
- expect(mockChargeWriteBudget).not.toHaveBeenCalled();
1002
- expect(client.prices.list).not.toHaveBeenCalled();
1003
- });
1004
-
1005
- it("an unreadable connection answers 502, never the env path", async () => {
1006
- mockConnectionSummary.mockResolvedValue("unreadable");
1007
- const res = await post();
1008
- expect(res.statusCode).toBe(502);
1009
- expect(res.json()).toEqual({ error: "checkout-unavailable" });
1010
- expect(mockReadWorkspaceSelection).not.toHaveBeenCalled();
1011
- });
1012
-
1013
- it.each<[string, () => void]>([
1014
- [
1015
- "the resolver",
1016
- () =>
1017
- mockResolvePublicWorkspace.mockRejectedValue(
1018
- new Error("registry down"),
1019
- ),
1020
- ],
1021
- [
1022
- "the Organization read",
1023
- () =>
1024
- mockOrganizationIdOfWorkspace.mockRejectedValue(new Error("db down")),
1025
- ],
1026
- [
1027
- "the summary read",
1028
- () => mockConnectionSummary.mockRejectedValue(new Error("db down")),
1029
- ],
1030
- ])("a rejecting %s answers 502", async (_label, arrange) => {
1031
- arrange();
1032
- const res = await post();
1033
- expect(res.statusCode).toBe(502);
1034
- expect(res.json()).toEqual({ error: "checkout-unavailable" });
1035
- });
1036
-
1037
- it("a body naming a workspace, an Organization or a site is ignored", async () => {
1038
- const res = await post({
1039
- ...BODY,
1040
- workspaceId: "wksp_00000000-0000-7000-8000-00000000dead",
1041
- organizationId: "org_00000000-0000-7000-8000-00000000dead",
1042
- site: "wksp_00000000-0000-7000-8000-00000000dead",
1043
- });
1044
-
1045
- expect(res.statusCode).toBe(201);
1046
- expect(mockRecordCheckoutSession.mock.calls[0][0]).toMatchObject({
1047
- workspaceId: WS,
1048
- organizationId: ORG,
1049
- });
1050
- expect(client.checkout.sessions.create.mock.calls[0][0].metadata.site).toBe(
1051
- WS,
1052
- );
1053
- expect(mockOrganizationIdOfWorkspace).toHaveBeenCalledWith(WS);
1054
- });
1055
- });
1056
-
1057
- // ── #9126: a resolved spoke with no connection never takes the env path ─────
1058
-
1059
- describe("#9126 — a spoke's workspace with no Stripe connection is refused, never the env path", () => {
1060
- const SPOKE = { "x-ailk-spoke-key": "spoke-key-9126" };
1061
- const ENV_SESSION_ID = "cs_test_env9126";
1062
- const LOGGER_KEYS = new Set([
1063
- "level",
1064
- "time",
1065
- "pid",
1066
- "hostname",
1067
- "reqId",
1068
- "msg",
1069
- ]);
1070
-
1071
- beforeEach(() => {
1072
- // An env key is set and its Price sells, so the env path would answer
1073
- // 201: a 404 below is the refusal, not a missing key or Price.
1074
- process.env.STRIPE_SECRET_KEY =
1075
- ["sk", "test", ""].join("_") + "Unconnected9126";
1076
- mockEnvPricesList.mockResolvedValue({
1077
- data: [
1078
- {
1079
- id: "price_Env9126",
1080
- type: "recurring",
1081
- product: { id: "prod_Env9126", metadata: {} },
1082
- },
1083
- ],
1084
- });
1085
- mockEnvSessionsCreate.mockResolvedValue({
1086
- id: ENV_SESSION_ID,
1087
- url: `https://checkout.stripe.com/c/pay/${ENV_SESSION_ID}`,
1088
- });
1089
- });
1090
-
1091
- function unconnectedLines(from: number): Array<Record<string, unknown>> {
1092
- return logged
1093
- .slice(from)
1094
- .flatMap((line) => {
1095
- try {
1096
- return [JSON.parse(line) as Record<string, unknown>];
1097
- } catch {
1098
- return [];
1099
- }
1100
- })
1101
- .filter((entry) => entry.outcome === "unconnected");
1102
- }
1103
-
1104
- it.each<[string, () => void]>([
1105
- [
1106
- "no Organization row",
1107
- () => mockOrganizationIdOfWorkspace.mockResolvedValue(null),
1108
- ],
1109
- [
1110
- "an Organization with no connection",
1111
- () => mockConnectionSummary.mockResolvedValue(null),
1112
- ],
1113
- ])(
1114
- "a spoke's workspace with %s answers the one 404 with no Stripe call",
1115
- async (_label, arrange) => {
1116
- arrange();
1117
- const from = logged.length;
1118
-
1119
- const res = await post(BODY, SPOKE);
1120
-
1121
- expect(res.statusCode).toBe(404);
1122
- expect(res.json()).toEqual({ error: "unknown-product-code" });
1123
- expect(envStripeConstructor()).not.toHaveBeenCalled();
1124
- expect(mockEnvPricesList).not.toHaveBeenCalled();
1125
- expect(mockEnvSessionsCreate).not.toHaveBeenCalled();
1126
- expect(mockClientForOrganization).not.toHaveBeenCalled();
1127
- expect(client.prices.list).not.toHaveBeenCalled();
1128
- expect(mockChargeWriteBudget).not.toHaveBeenCalled();
1129
- expect(mockRecordCheckoutSession).not.toHaveBeenCalled();
1130
-
1131
- const lines = unconnectedLines(from);
1132
- expect(lines).toHaveLength(1);
1133
- // Everything but the logger's own bindings is what the route chose to log.
1134
- const fields = Object.fromEntries(
1135
- Object.entries(lines[0]!).filter(([key]) => !LOGGER_KEYS.has(key)),
1136
- );
1137
- expect(fields).toEqual({ outcome: "unconnected", workspaceId: WS });
1138
- },
1139
- );
1140
-
1141
- it("answers before the env key is read: with no STRIPE_SECRET_KEY it is still the 404, never 500", async () => {
1142
- delete process.env.STRIPE_SECRET_KEY;
1143
- mockConnectionSummary.mockResolvedValue(null);
1144
-
1145
- const res = await post(BODY, SPOKE);
1146
-
1147
- expect(res.statusCode).toBe(404);
1148
- expect(res.json()).toEqual({ error: "unknown-product-code" });
1149
- });
1150
-
1151
- it("a spoke's workspace whose Organization is connected still takes the Offerings path", async () => {
1152
- const res = await post(BODY, SPOKE);
1153
-
1154
- expect(res.statusCode).toBe(201);
1155
- expect(res.json()).toEqual({ sessionId: SESSION_ID, url: SESSION_URL });
1156
- expect(envStripeConstructor()).not.toHaveBeenCalled();
1157
- });
1158
-
1159
- it.each<[string, () => void]>([
1160
- [
1161
- "a deployment off the database adapter (not-required)",
1162
- () =>
1163
- mockResolvePublicWorkspace.mockResolvedValue({ kind: "not-required" }),
1164
- ],
1165
- [
1166
- "a keyless call on a non-hub whose workspace has no Organization row",
1167
- () => mockOrganizationIdOfWorkspace.mockResolvedValue(null),
1168
- ],
1169
- [
1170
- "a keyless call on a non-hub whose Organization has no connection",
1171
- () => mockConnectionSummary.mockResolvedValue(null),
1172
- ],
1173
- [
1174
- "a keyless call a hub refused",
1175
- () =>
1176
- mockResolvePublicWorkspace.mockResolvedValue({
1177
- kind: "unresolved",
1178
- reason: "spoke-refused",
1179
- }),
1180
- ],
1181
- ])("%s takes the env path, unchanged", async (_label, arrange) => {
1182
- arrange();
1183
- const from = logged.length;
1184
-
1185
- const res = await post();
1186
-
1187
- expect(res.statusCode).toBe(201);
1188
- expect(res.json()).toEqual({
1189
- sessionId: ENV_SESSION_ID,
1190
- url: `https://checkout.stripe.com/c/pay/${ENV_SESSION_ID}`,
1191
- });
1192
- expect(mockEnvSessionsCreate).toHaveBeenCalledTimes(1);
1193
- expect(mockChargeWriteBudget).not.toHaveBeenCalled();
1194
- expect(client.prices.list).not.toHaveBeenCalled();
1195
- expect(unconnectedLines(from)).toHaveLength(0);
1196
- });
1197
- });
1198
-
1199
- // ── AC-5: the bucket, and every failure is 502 (A5, A8, K6) ─────────────────
1200
-
1201
- describe("AC-5 — the per-request bucket and the failure answers", () => {
1202
- function charge(key: string, limit: number) {
1203
- return {
1204
- scope: "offeringscheckout",
1205
- charges: [{ key, limit }],
1206
- windowMs: 60000,
1207
- now: expect.any(Number),
1208
- warn: expect.any(Function),
1209
- };
1210
- }
1211
-
1212
- function expectCharged(ip: string) {
1213
- expect(mockChargeWriteBudget).toHaveBeenCalledWith(charge(`ip,${ip}`, 10));
1214
- expect(mockChargeWriteBudget).toHaveBeenCalledWith(charge(`ws,${WS}`, 60));
1215
- }
1216
-
1217
- function chargedKeys(): string[] {
1218
- return mockChargeWriteBudget.mock.calls.flatMap(([input]) =>
1219
- (input as { charges: Array<{ key: string }> }).charges.map((c) => c.key),
1220
- );
1221
- }
1222
-
1223
- it("charges the per-IP and per-workspace buckets once per request, whatever the forwarded address", async () => {
1224
- await post(BODY, { "x-forwarded-for": "203.0.113.7" });
1225
- await post(BODY, { "x-forwarded-for": "198.51.100.9" });
1226
-
1227
- expect(mockChargeWriteBudget).toHaveBeenCalledTimes(4);
1228
- expectCharged("203.0.113.7");
1229
- expectCharged("198.51.100.9");
1230
- expect(chargedKeys()).toEqual([
1231
- "ip,203.0.113.7",
1232
- `ws,${WS}`,
1233
- "ip,198.51.100.9",
1234
- `ws,${WS}`,
1235
- ]);
1236
- });
1237
-
1238
- it("a request its IP bucket refuses never spends the workspace's bucket", async () => {
1239
- mockChargeWriteBudget.mockResolvedValueOnce({
1240
- ok: false,
1241
- retryAfterSeconds: 5,
1242
- });
1243
-
1244
- const res = await post(BODY, { "x-forwarded-for": "203.0.113.7" });
1245
-
1246
- expect(res.statusCode).toBe(429);
1247
- expect(chargedKeys()).toEqual(["ip,203.0.113.7"]);
1248
- });
1249
-
1250
- it.each<[string, Record<string, unknown>, number]>([
1251
- [
1252
- "a malformed body",
1253
- { productCode: "bad/code", successUrl: "x", cancelUrl: "y" },
1254
- 400,
1255
- ],
1256
- ["an ungrammatical key", { ...BODY, productCode: "Growth_Monthly" }, 404],
1257
- ])("charges %s before the body is read", async (_label, body, status) => {
1258
- const res = await post(body, { "x-forwarded-for": "203.0.113.7" });
1259
- expect(res.statusCode).toBe(status);
1260
- expect(mockChargeWriteBudget).toHaveBeenCalledTimes(2);
1261
- expectCharged("203.0.113.7");
1262
- });
1263
-
1264
- it("an exhausted bucket answers 429 with Retry-After and no Stripe call", async () => {
1265
- mockChargeWriteBudget.mockResolvedValue({
1266
- ok: false,
1267
- retryAfterSeconds: 7,
1268
- });
1269
-
1270
- const res = await post();
1271
-
1272
- expect(res.statusCode).toBe(429);
1273
- expect(res.headers["retry-after"]).toBe("7");
1274
- expect(res.json()).toEqual({ error: "rate_limited", retryAfterSeconds: 7 });
1275
- expect(client.prices.list).not.toHaveBeenCalled();
1276
- expect(mockClientForOrganization).not.toHaveBeenCalled();
1277
- expect(client.checkout.sessions.create).not.toHaveBeenCalled();
1278
- });
1279
-
1280
- it("the env path never charges it", async () => {
1281
- mockConnectionSummary.mockResolvedValue(null);
1282
- await post();
1283
- expect(mockChargeWriteBudget).not.toHaveBeenCalled();
1284
- });
1285
-
1286
- it.each<[string, () => void]>([
1287
- [
1288
- "prices.list rejecting",
1289
- () => client.prices.list.mockRejectedValue(new Error("unreachable")),
1290
- ],
1291
- [
1292
- "checkout.sessions.create rejecting",
1293
- () =>
1294
- client.checkout.sessions.create.mockRejectedValue(
1295
- new Error("stripe down"),
1296
- ),
1297
- ],
1298
- [
1299
- "a refused terms box",
1300
- () =>
1301
- client.checkout.sessions.create.mockRejectedValue(
1302
- Object.assign(new Error("You must set a Terms of Service URL"), {
1303
- type: "StripeInvalidRequestError",
1304
- param: "consent_collection[terms_of_service]",
1305
- }),
1306
- ),
1307
- ],
1308
- [
1309
- "the rows' store rejecting",
1310
- () => mockReadWorkspaceSelection.mockRejectedValue(new Error("db down")),
1311
- ],
1312
- [
1313
- "an unusable connection",
1314
- () => mockClientForOrganization.mockResolvedValue({ kind: "unusable" }),
1315
- ],
1316
- [
1317
- "a connection gone since the path decision",
1318
- () => mockClientForOrganization.mockResolvedValue({ kind: "none" }),
1319
- ],
1320
- [
1321
- "a rejected connection read",
1322
- () => mockClientForOrganization.mockRejectedValue(new Error("db down")),
1323
- ],
1324
- [
1325
- "rows read for another Organization than the path decision's",
1326
- () =>
1327
- mockOrganizationIdOfWorkspace
1328
- .mockResolvedValueOnce(ORG)
1329
- .mockResolvedValueOnce("org_00000000-0000-7000-8000-00000000dead"),
1330
- ],
1331
- ])("%s answers 502, never 500 or 201", async (_label, arrange) => {
1332
- arrange();
1333
-
1334
- const res = await post();
1335
-
1336
- expect(res.statusCode).toBe(502);
1337
- expect(res.json()).toEqual({ error: "checkout-unavailable" });
1338
- expect(mockRecordCheckoutSession).not.toHaveBeenCalled();
1339
- });
1340
- });
1341
-
1342
- // ── AC-6: no key, id or URL in a log line or a refusal body (C5, T6, NFR1) ──
1343
-
1344
- describe("AC-6 — what the logs and the bodies never carry", () => {
1345
- it("no log line holds a lookup key, a Price or Product id, a full session id or a URL", () => {
1346
- expect(logged.length).toBeGreaterThan(0);
1347
- const all = logged.join("\n");
1348
- for (const secret of SECRETS) {
1349
- expect(all).not.toContain(secret);
1350
- }
1351
- });
1352
-
1353
- it("only the two success bodies hold a session id or URL, and no body holds a key or id", () => {
1354
- expect(bodies.length).toBeGreaterThan(0);
1355
- for (const { status, body } of bodies) {
1356
- for (const secret of SECRETS) {
1357
- if (secret === SESSION_ID && (status === 200 || status === 201))
1358
- continue;
1359
- if (secret === SESSION_URL && status === 201) continue;
1360
- expect(body).not.toContain(secret);
1361
- }
1362
- }
1363
- });
1364
- });
1365
-
1366
- // ── #9285: an Organization selling through the environment key ──────────────
1367
-
1368
- describe("#9296 — an Organization on the environment key never takes the Offerings path", () => {
1369
- const SPOKE = { "x-ailk-spoke-key": "spoke-key-9285" };
1370
-
1371
- beforeEach(() => {
1372
- mockConnectionSummary.mockResolvedValue("environment");
1373
- });
1374
-
1375
- it("keeps the env path even when the workspace has a saved selection", async () => {
1376
- // The default fixtures give the workspace a selection (givenRows).
1377
- const res = await post();
1378
-
1379
- expect(res.statusCode).toBe(500);
1380
- expect(res.json()).toEqual({ error: "stripe-not-configured" });
1381
- expect(mockClientForOrganization).not.toHaveBeenCalled();
1382
- expect(mockRecordCheckoutSession).not.toHaveBeenCalled();
1383
- });
1384
-
1385
- it("keeps the env path while the workspace has no selection", async () => {
1386
- mockReadWorkspaceSelection.mockResolvedValue(null);
1387
-
1388
- const res = await post();
1389
-
1390
- expect(res.statusCode).toBe(500);
1391
- expect(res.json()).toEqual({ error: "stripe-not-configured" });
1392
- expect(mockClientForOrganization).not.toHaveBeenCalled();
1393
- expect(mockRecordCheckoutSession).not.toHaveBeenCalled();
1394
- });
1395
-
1396
- it("refuses a spoke's workspace as unconnected, selection or not", async () => {
1397
- const res = await post(BODY, SPOKE);
1398
-
1399
- expect(res.statusCode).toBe(404);
1400
- expect(res.json()).toEqual({ error: "unknown-product-code" });
1401
- expect(mockClientForOrganization).not.toHaveBeenCalled();
1402
- });
1403
-
1404
- it("still takes the Offerings path for a stored connection", async () => {
1405
- mockConnectionSummary.mockResolvedValue(SUMMARY);
1406
-
1407
- const res = await post();
1408
-
1409
- expect(res.statusCode).toBe(201);
1410
- expect(mockClientForOrganization).toHaveBeenCalledWith(ORG);
1411
- expect(mockRecordCheckoutSession.mock.calls[0][0]).toMatchObject({
1412
- workspaceId: WS,
1413
- organizationId: ORG,
1414
- });
1415
- });
1416
-
1417
- it("leaves a non-owner (no connection) on the env path, as before", async () => {
1418
- mockConnectionSummary.mockResolvedValue(null);
1419
-
1420
- const res = await post();
1421
-
1422
- expect(res.statusCode).toBe(500);
1423
- expect(res.json()).toEqual({ error: "stripe-not-configured" });
1424
- expect(mockClientForOrganization).not.toHaveBeenCalled();
1425
- });
1426
- });