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,1268 +0,0 @@
1
- // Not marked oss: false (D-48/#5366 escalation) — tests the
2
- // always-shipping project-listings anonymous surface; see
3
- // routes/project-listings/me.ts's header comment.
4
- /**
5
- * @file drafts.test.ts
6
- *
7
- * THE ACCEPTANCE GATE for the draft lifecycle (#5036 D1/D7) — the three
8
- * anonymous routes that replaced the single `POST /v1/project-listings`
9
- * create: `start`, `patch` and `submit`.
10
- *
11
- * Real routes and real services, mocked `lib/prisma.js` backed by a small
12
- * in-memory row store, so a patch genuinely WRITES and a later read genuinely
13
- * READS BACK. A `jest.fn()` returning a canned object could not tell a
14
- * round-trip from a no-op, and the round-trip is the thing under test.
15
- * `routeLead` runs for real against a per-test temp path
16
- * (`setupLeadFileEnv`), matching the create test's discipline before it;
17
- * `@working-theory/email` and `@working-theory/license` stay mocked (external
18
- * package boundaries — see docs/lessons/project-listings/02).
19
- *
20
- * `slack-notify` is NOT mocked, deliberately: `AILK_SLACK_BOT_TOKEN` is unset
21
- * here, so `postListingApplication` takes its own documented no-op branch
22
- * (`slack-skipped`) and never reaches `fetch`. Stubbing the module would be
23
- * mocking internal code to avoid a boundary that is already closed.
24
- *
25
- * Four of these fail QUIETLY if they regress, which is why each is here:
26
- * - a draft created from name and email alone must PERSIST, and a
27
- * single-field patch must round-trip — otherwise the lifecycle silently
28
- * stores nothing and the founder loses ten steps of work;
29
- * - an incomplete draft at submit must be refused with the missing fields
30
- * NAMED, not silently accepted into `requested`;
31
- * - a resume token must grant ONE listing and nothing else, since it is the
32
- * only credential on an anonymous surface;
33
- * - drafts must COUNT toward the two-listing limit, or the limit is evaded
34
- * by never submitting.
35
- */
36
- import { createHash } from "node:crypto";
37
-
38
- import Fastify from "fastify";
39
- import type { FastifyInstance } from "fastify";
40
-
41
- // eslint-disable-next-line no-restricted-syntax -- prisma is a DB boundary; __mocks__/prisma.ts activates the auto-mock
42
- jest.mock("../../../lib/prisma.js");
43
-
44
- jest.mock("@working-theory/email", () => ({
45
- sendLeadNotification: jest.fn().mockResolvedValue({ ok: true, messageId: "msg-test" }),
46
- // #5406 — `start` now reaches the resume email. Declared here for the reason
47
- // docs/lessons/project-listings/04 records: a mock factory that omits an
48
- // export the code under test calls leaves it `undefined` at the callsite.
49
- // These suites configure no `resumeEmail`, so the send short-circuits before
50
- // this is reached; it is declared so a future fixture that DOES configure
51
- // one fails on its assertion rather than on a missing mock.
52
- sendListingResumeEmail: jest.fn().mockResolvedValue({ ok: true, messageId: "msg-resume" }),
53
- }));
54
-
55
- jest.mock("@working-theory/license", () => ({
56
- checkLicense: jest.fn().mockResolvedValue({
57
- tier: "free",
58
- plan: null,
59
- features: [],
60
- expiresAt: null,
61
- revoked: false,
62
- }),
63
- }));
64
-
65
- import { logger } from "@working-theory/observability";
66
- import {
67
- resolveConsentStatement,
68
- SITE_CONSENT_CONFIG_DEFAULTS,
69
- } from "@working-theory/validation";
70
-
71
- import {
72
- mockNoWorkspace,
73
- mockWorkspaceExists,
74
- } from "../../../lib/__mocks__/prisma.js";
75
- import { prisma } from "../../../lib/prisma.js";
76
- import { setupLeadFileEnv } from "../../../__tests__/factories/lead-fixture";
77
- import {
78
- MAX_CONSENT_KEYS, UNRECOVERABLE_CONSENT_STATEMENT } from "../../../services/consent.js";
79
- import { patchProjectListingDraftRoute } from "../patch-draft.js";
80
- import { startProjectListingRoute } from "../start.js";
81
- import { submitProjectListingRoute } from "../submit.js";
82
-
83
- // ─── Fixtures ───────────────────────────────────────────────────────────────
84
-
85
- const opt = (value: string, label: string) => ({ value, label });
86
-
87
- const VALID_QUESTIONS = {
88
- q2: {
89
- prompt: "Why are you here?",
90
- options: [opt("scale", "Scaling my team"), opt("just-curious", "Just curious")],
91
- },
92
- q3: { prompt: "Stage?", options: [opt("a", "A"), opt("b", "B"), opt("c", "C")] },
93
- q4: { prompt: "Team size?", options: [opt("a", "A"), opt("b", "B"), opt("c", "C")] },
94
- q5: {
95
- prompt: "Urgency?",
96
- options: [opt("urgent", "Now"), opt("planning", "Soon"), opt("exploring", "Someday")],
97
- },
98
- q6: {
99
- prompt: "Pain?",
100
- options: [
101
- opt("low", "Low"),
102
- opt("medium", "Medium"),
103
- opt("high", "High"),
104
- opt("critical", "Critical"),
105
- ],
106
- },
107
- q7: { prompt: "Anything else?" },
108
- extras: [],
109
- };
110
-
111
- /**
112
- * The site is named by its PUBLIC KEY now (#5048 D2) — `siteId` never travels
113
- * in a request body. `installStore` maps this key to `SITE_ID` the way a
114
- * `SiteListingConfig.publicKey` row does.
115
- */
116
- const SITE_ID = "site-1";
117
- const SITE_KEY = "site-1-public-key";
118
-
119
- const START_PAYLOAD = {
120
- siteKey: SITE_KEY,
121
- founderName: "Ada Founder",
122
- founderEmail: "ada@example.com",
123
- consent: true,
124
- };
125
-
126
- /**
127
- * #6314 — the magnets `capturedByFlowSlug` may name. The resolve runs against
128
- * the RESOLVED workspace id (`resolveWorkspaceIdForSite(SITE_ID)`), which this
129
- * suite's `mockWorkspaceExists(prisma, SITE_ID)` makes `SITE_ID` itself.
130
- */
131
- const WS_OTHER = "wksp_00000000-0000-7000-8000-0000000000bb";
132
- const LISTICLE_ID = "flow_00000000-0000-7000-8000-0000000000d1";
133
- const FOREIGN_LISTICLE_ID = "flow_00000000-0000-7000-8000-0000000000d2";
134
- const CONTACT_FLOW_ID = "flow_00000000-0000-7000-8000-0000000000d3";
135
-
136
- const FLOW_DEFINITION_ROWS: Row[] = [
137
- {
138
- id: LISTICLE_ID,
139
- siteId: SITE_ID,
140
- workspaceId: SITE_ID,
141
- slug: "founder-list",
142
- kind: "listicle",
143
- status: "live",
144
- },
145
- // A listicle magnet of ANOTHER workspace. Its slug is a public path segment,
146
- // so a stranger can name it — the resolve's `siteId`/`workspaceId` terms are
147
- // what make naming it inert.
148
- {
149
- id: FOREIGN_LISTICLE_ID,
150
- siteId: WS_OTHER,
151
- workspaceId: WS_OTHER,
152
- slug: "other-list",
153
- kind: "listicle",
154
- status: "live",
155
- },
156
- // A NON-listicle magnet in THIS workspace: the `kind: "listicle"` term in
157
- // the resolve is what stops an application being filed against it.
158
- {
159
- id: CONTACT_FLOW_ID,
160
- siteId: SITE_ID,
161
- workspaceId: SITE_ID,
162
- slug: "contact-us",
163
- kind: "contact",
164
- status: "live",
165
- },
166
- ];
167
-
168
- /** Everything the ten steps after step one collect. */
169
- const COMPLETE_APPLICATION = {
170
- name: "My Project",
171
- headline: "Ten words or fewer for the tile title here",
172
- oneLiner: "A short sentence describing what the project does for its people.",
173
- problem: "The problem is real and this describes it.",
174
- product: "wireframes",
175
- commitment: "part-time",
176
- teamComposition: "co-founders",
177
- faqs: [
178
- { question: "Q one?", answer: "A one." },
179
- { question: "Q two?", answer: "A two." },
180
- { question: "Q three?", answer: "A three." },
181
- ],
182
- address: "1 Founder Way, Springfield",
183
- questions: VALID_QUESTIONS,
184
- };
185
-
186
- // ─── The in-memory row store the Prisma mock is backed by ───────────────────
187
-
188
- type Row = Record<string, unknown>;
189
-
190
- let rows: Row[];
191
- let nextId: number;
192
-
193
- function matches(row: Row, where: Record<string, unknown>): boolean {
194
- return Object.entries(where).every(([key, value]) => {
195
- if (key === "OR") {
196
- return (value as Record<string, unknown>[]).some((clause) => matches(row, clause));
197
- }
198
- if (value !== null && typeof value === "object" && !(value instanceof Date)) {
199
- const clause = value as Record<string, unknown>;
200
- if ("in" in clause) return (clause["in"] as unknown[]).includes(row[key]);
201
- if ("not" in clause) return row[key] !== clause["not"];
202
- if ("gt" in clause) return (row[key] as Date) > (clause["gt"] as Date);
203
- if ("startsWith" in clause) {
204
- return typeof row[key] === "string" && (row[key] as string).startsWith(clause["startsWith"] as string);
205
- }
206
- }
207
- return row[key] === value;
208
- });
209
- }
210
-
211
- function installStore(): void {
212
- // #6335 — the shared prisma mock no longer resolves ANY requested
213
- // workspace id. `startProjectListingDraft` stamps the row's `workspaceId`
214
- // by resolving the site it was filed against (`resolveWorkspaceIdForSite`,
215
- // services/project-listings.ts), so this suite states the ONE site it is
216
- // built around. Keyed on the requested id — nothing else resolves.
217
- mockWorkspaceExists(prisma, SITE_ID);
218
-
219
- rows = [];
220
- nextId = 1;
221
-
222
- (prisma.lead.create as jest.Mock).mockImplementation(() =>
223
- Promise.resolve({ id: `lead_00000000-0000-7000-8000-00000000000${nextId}` }),
224
- );
225
- // One delegate, two lookups (#5048 D2): `where.publicKey` is the site-key
226
- // resolution (`siteIdForPublicKey`), `where.siteId` the config read
227
- // (`listingConfigFor`). No config row for the latter, so the platform
228
- // defaults apply — the behaviour every test below was written against.
229
- (prisma.siteListingConfig.findUnique as jest.Mock).mockImplementation(
230
- ({ where }: { where: { siteId?: string; publicKey?: string } }) => {
231
- if (where.publicKey !== undefined) {
232
- return Promise.resolve(where.publicKey === SITE_KEY ? { siteId: SITE_ID } : null);
233
- }
234
- return Promise.resolve(null);
235
- },
236
- );
237
-
238
- // #5275 — `start` writes the row and its grant in one interactive
239
- // transaction; the mock hands the same store-backed client through.
240
- (prisma.$transaction as jest.Mock).mockImplementation(
241
- async (fn: (tx: typeof prisma) => Promise<unknown>) => fn(prisma),
242
- );
243
- (prisma.projectListing.create as jest.Mock).mockImplementation(
244
- ({ data }: { data: Row }) => {
245
- const now = new Date();
246
- const row: Row = {
247
- id: `prjl_00000000-0000-7000-8000-00000000000${nextId++}`,
248
- slug: null,
249
- name: null,
250
- oneLiner: null,
251
- problem: null,
252
- url: null,
253
- product: null,
254
- commitment: null,
255
- teamComposition: null,
256
- faqs: null,
257
- anythingElse: null,
258
- address: null,
259
- questions: null,
260
- // #5407 — a row written before the columns existed, and a freshly
261
- // started draft on a site that asks for one name line: parts null,
262
- // no phone, no verification stamp.
263
- founderFirstName: null,
264
- founderLastName: null,
265
- founderPhone: null,
266
- emailVerifiedAt: null,
267
- founderCompany: null,
268
- leadId: null,
269
- headline: null,
270
- logoMarkUrl: null,
271
- logoWordmarkUrl: null,
272
- solution: null,
273
- featured: false,
274
- decidedAt: null,
275
- decidedBy: null,
276
- issueUrl: null,
277
- experimentKey: null,
278
- windowEndsAt: null,
279
- createdAt: now,
280
- updatedAt: now,
281
- ...data,
282
- };
283
- rows.push(row);
284
- return Promise.resolve(row);
285
- },
286
- );
287
-
288
- (prisma.projectListing.findFirst as jest.Mock).mockImplementation(
289
- ({ where }: { where: Record<string, unknown> }) =>
290
- Promise.resolve(rows.find((row) => matches(row, where)) ?? null),
291
- );
292
-
293
- (prisma.projectListing.findMany as jest.Mock).mockImplementation(
294
- ({ where }: { where: Record<string, unknown> }) =>
295
- Promise.resolve(rows.filter((row) => matches(row, where))),
296
- );
297
-
298
- (prisma.projectListing.update as jest.Mock).mockImplementation(
299
- ({ where, data }: { where: Record<string, unknown>; data: Row }) => {
300
- const row = rows.find((r) => matches(r, where));
301
- Object.assign(row!, data, { updatedAt: new Date() });
302
- return Promise.resolve(row);
303
- },
304
- );
305
-
306
- (prisma.projectListing.updateMany as jest.Mock).mockImplementation(
307
- ({ where, data }: { where: Record<string, unknown>; data: Row }) => {
308
- const matched = rows.filter((r) => matches(r, where));
309
- matched.forEach((r) => Object.assign(r, data, { updatedAt: new Date() }));
310
- return Promise.resolve({ count: matched.length });
311
- },
312
- );
313
-
314
- // #5275 — the grant write `start` now makes. Append-only, so the mock only
315
- // needs to resolve; the start tests below assert on what it was called with.
316
- (prisma.consentGrant.createMany as jest.Mock).mockImplementation(
317
- ({ data }: { data: Row[] }) => Promise.resolve({ count: data.length }),
318
- );
319
-
320
- // #6314 — the capturing-magnet resolve. Honours EVERY term the service
321
- // passes, so a resolve that dropped `workspaceId` or `kind` would match a
322
- // row it must not and fail the assertions below.
323
- (prisma.flowDefinition.findFirst as jest.Mock).mockImplementation(
324
- ({ where }: { where: Record<string, unknown> }) =>
325
- Promise.resolve(
326
- FLOW_DEFINITION_ROWS.find((row) => matches(row, where)) ?? null,
327
- ),
328
- );
329
- }
330
-
331
- // ─── Helpers ────────────────────────────────────────────────────────────────
332
-
333
- const sha256 = (value: string) => createHash("sha256").update(value).digest("hex");
334
-
335
- const bearer = (token: string) => ({ authorization: `Bearer ${token}` });
336
-
337
- async function buildApp(): Promise<FastifyInstance> {
338
- const app = Fastify();
339
- await app.register(startProjectListingRoute);
340
- await app.register(patchProjectListingDraftRoute);
341
- await app.register(submitProjectListingRoute);
342
- await app.ready();
343
- return app;
344
- }
345
-
346
- async function startDraft(
347
- app: FastifyInstance,
348
- overrides: Record<string, unknown> = {},
349
- ): Promise<{ id: string; resumeToken: string }> {
350
- const res = await app.inject({
351
- method: "POST",
352
- url: "/v1/project-listings",
353
- payload: { ...START_PAYLOAD, ...overrides },
354
- });
355
- expect(res.statusCode).toBe(201);
356
- return (res.json() as { ok: true; data: { id: string; resumeToken: string } }).data;
357
- }
358
-
359
- // ─── Tests ──────────────────────────────────────────────────────────────────
360
-
361
- describe("the draft lifecycle (#5036 D1)", () => {
362
- setupLeadFileEnv("project-listing-drafts");
363
- let app: FastifyInstance;
364
-
365
- beforeEach(async () => {
366
- jest.clearAllMocks();
367
- installStore();
368
- app = await buildApp();
369
- });
370
-
371
- afterEach(async () => {
372
- await app.close();
373
- });
374
-
375
- // ── start ──
376
-
377
- it("start: a draft created from name and email alone PERSISTS", async () => {
378
- const { id, resumeToken } = await startDraft(app);
379
-
380
- expect(id).toMatch(/^prjl_/);
381
- expect(resumeToken.length).toBeGreaterThan(0);
382
-
383
- // The row exists, at `draft`, carrying nothing but the identity — every
384
- // application field still null. This is the "nullable at rest" invariant
385
- // seen from the outside: without it the create itself would have failed.
386
- const row = rows[0]!;
387
- expect(row["status"]).toBe("draft");
388
- expect(row["founderEmail"]).toBe("ada@example.com");
389
- expect(row["name"]).toBeNull();
390
- expect(row["oneLiner"]).toBeNull();
391
- expect(row["product"]).toBeNull();
392
- expect(row["questions"]).toBeNull();
393
- expect(row["slug"]).toBeNull();
394
-
395
- // NO Lead at step one. The contact is already captured on this row, and
396
- // `routeLead` mails the operator — which on an anonymous route would let a
397
- // stranger fill the operator's inbox by opening drafts they never finish
398
- // (PR #5042 security review, finding 4). The Lead waits for `submit`.
399
- expect(prisma.lead.create).not.toHaveBeenCalled();
400
- expect(row["leadId"]).toBeNull();
401
- });
402
-
403
- it("start: lowercases the founder's email, so the limit cannot be evaded by case", async () => {
404
- // Postgres text equality is case-sensitive, so without this the
405
- // concurrent-listing limit is evaded by holding down shift. (Surrounding
406
- // whitespace needs no test: `z.string().email()` refuses it outright.)
407
- await startDraft(app, { founderEmail: "Ada@Example.COM" });
408
- expect(rows[0]!["founderEmail"]).toBe("ada@example.com");
409
- });
410
-
411
- it("start: stores a DIGEST of the resume token, never the token", async () => {
412
- const { resumeToken } = await startDraft(app);
413
- const stored = rows[0]!["resumeTokenHash"];
414
-
415
- expect(stored).not.toBe(resumeToken);
416
- expect(stored).toBe(sha256(resumeToken));
417
- // 256 bits of CSPRNG output, base64url-encoded.
418
- expect(Buffer.from(resumeToken, "base64url")).toHaveLength(32);
419
- });
420
-
421
- it("start: two drafts get different tokens", async () => {
422
- const first = await startDraft(app);
423
- const second = await startDraft(app, { founderEmail: "grace@example.com" });
424
- expect(first.resumeToken).not.toBe(second.resumeToken);
425
- });
426
-
427
- it("start: refuses a payload that declines consent", async () => {
428
- const res = await app.inject({
429
- method: "POST",
430
- url: "/v1/project-listings",
431
- payload: { ...START_PAYLOAD, consent: false },
432
- });
433
- expect(res.statusCode).toBe(400);
434
- expect((res.json() as { ok: boolean }).ok).toBe(false);
435
- expect(rows).toHaveLength(0);
436
- });
437
-
438
- // ── start: the consent grant (#5275 D7/D11) ──
439
-
440
- it.each([
441
- ["DECLINES the required purpose", { service_terms: false }],
442
- ["is EMPTY beside the literal", {}],
443
- ["OMITS the required purpose", { marketing: true }],
444
- ])(
445
- "start: a consents map that %s is a 400 and creates no row and no grant",
446
- async (_label, consents) => {
447
- const res = await app.inject({
448
- method: "POST",
449
- url: "/v1/project-listings",
450
- payload: { ...START_PAYLOAD, consents, locale: "en" },
451
- });
452
- expect(res.statusCode).toBe(400);
453
- const body = res.json() as { ok: boolean; error: { code: string; message: string } };
454
- expect(body.ok).toBe(false);
455
- expect(body.error.code).toBe("invalid_input");
456
- expect(body.error.message).toMatch(/service_terms/);
457
- expect(rows).toHaveLength(0);
458
- expect(prisma.consentGrant.createMany).not.toHaveBeenCalled();
459
- },
460
- );
461
-
462
- it("start: a consents map with more than MAX_CONSENT_KEYS purposes is a 400", async () => {
463
- const consents: Record<string, boolean> = { service_terms: true };
464
- for (let i = 0; i < MAX_CONSENT_KEYS; i += 1) consents[`junk_${i}`] = true;
465
- const res = await app.inject({
466
- method: "POST",
467
- url: "/v1/project-listings",
468
- payload: { ...START_PAYLOAD, consents, locale: "en" },
469
- });
470
- expect(res.statusCode).toBe(400);
471
- expect(rows).toHaveLength(0);
472
- });
473
-
474
- it("start: a grant write that fails takes the row with it — one transaction, no stranded listing", async () => {
475
- (prisma.$transaction as jest.Mock).mockImplementation(
476
- async (fn: (tx: typeof prisma) => Promise<unknown>) => {
477
- const before = rows.length;
478
- try {
479
- return await fn(prisma);
480
- } catch (err) {
481
- rows.splice(before); // roll back the in-memory store
482
- throw err;
483
- }
484
- },
485
- );
486
- (prisma.consentGrant.createMany as jest.Mock).mockRejectedValueOnce(new Error("db down"));
487
- const res = await app.inject({
488
- method: "POST",
489
- url: "/v1/project-listings",
490
- payload: { ...START_PAYLOAD, consents: { service_terms: true }, locale: "en" },
491
- });
492
- expect(res.statusCode).toBe(500);
493
- expect(rows).toHaveLength(0);
494
- });
495
-
496
- it("start: a body carrying consents records one grant per purpose with the DEFAULT statement text", async () => {
497
- const { id } = await startDraft(app, { consents: { service_terms: true }, locale: "en" });
498
-
499
- // The expected wording is DERIVED from the registry the server resolves
500
- // from, never retyped — the whole point is that the row carries the string
501
- // the renderer showed, not a string this test happens to agree with.
502
- const purpose = SITE_CONSENT_CONFIG_DEFAULTS.purposes[0]!;
503
- const { statement } = resolveConsentStatement(purpose, "en");
504
-
505
- expect(prisma.consentGrant.createMany).toHaveBeenCalledTimes(1);
506
- const { data } = (prisma.consentGrant.createMany as jest.Mock).mock.calls[0]![0] as {
507
- data: Row[];
508
- };
509
- expect(data).toHaveLength(1);
510
- expect(data[0]).toMatchObject({
511
- siteId: SITE_ID,
512
- subjectType: "project_listing",
513
- subjectId: id,
514
- purposeId: "service_terms",
515
- granted: true,
516
- locale: "en",
517
- statement,
518
- statementHash: sha256(statement),
519
- // #8438 D3 — a listing names no magnet slug, so the source is `api`.
520
- source: "api",
521
- personId: null,
522
- policyVersion: 1,
523
- });
524
- expect(data[0]!["statement"]).not.toBe(UNRECOVERABLE_CONSENT_STATEMENT);
525
- // The row's own consentAt is untouched by the grant write (spec §2.3).
526
- expect(rows[0]!["consentAt"]).toBeInstanceOf(Date);
527
- });
528
-
529
- it("start: a body carrying only the legacy literal records ONE grant marked unrecoverable", async () => {
530
- const { id } = await startDraft(app);
531
-
532
- expect(prisma.consentGrant.createMany).toHaveBeenCalledTimes(1);
533
- const { data } = (prisma.consentGrant.createMany as jest.Mock).mock.calls[0]![0] as {
534
- data: Row[];
535
- };
536
- expect(data).toHaveLength(1);
537
- expect(data[0]).toMatchObject({
538
- siteId: SITE_ID,
539
- subjectType: "project_listing",
540
- subjectId: id,
541
- purposeId: "service_terms",
542
- granted: true,
543
- locale: "und",
544
- statement: UNRECOVERABLE_CONSENT_STATEMENT,
545
- statementHash: sha256(UNRECOVERABLE_CONSENT_STATEMENT),
546
- source: "api",
547
- });
548
- // Never today's wording for a legacy call — that would fabricate evidence (D11).
549
- expect(data[0]!["statement"]).not.toContain("You agree to being contacted");
550
- });
551
-
552
- // ── #6314 — the capturing magnet, written at START ────────────────────────
553
-
554
- it("AC-5: a capturedByFlowSlug naming a live listicle magnet of the resolved site writes that magnet's ID, and the response body is byte-unchanged", async () => {
555
- const res = await app.inject({
556
- method: "POST",
557
- url: "/v1/project-listings",
558
- payload: { ...START_PAYLOAD, capturedByFlowSlug: "founder-list" },
559
- });
560
- expect(res.statusCode).toBe(201);
561
- // The hard-floor response contract does not move: `{ id, resumeToken }`
562
- // and nothing else. The column is NEVER echoed back to the anonymous
563
- // caller (spec § 9 SEC-12).
564
- expect(Object.keys(res.json().data).sort()).toEqual(["id", "resumeToken"]);
565
-
566
- expect(rows[0]!["capturedByFlowId"]).toBe(LISTICLE_ID);
567
-
568
- // D1 — ALL FOUR terms in ONE query, and only the slug came from the body.
569
- const call = (prisma.flowDefinition.findFirst as jest.Mock).mock
570
- .calls[0]?.[0] as { where: Record<string, unknown> };
571
- expect(call.where).toEqual({
572
- slug: "founder-list",
573
- siteId: SITE_ID,
574
- workspaceId: SITE_ID,
575
- kind: "listicle",
576
- });
577
- });
578
-
579
- it("a start body carrying NO capturedByFlowSlug writes NULL, and makes no resolve query at all", async () => {
580
- await startDraft(app);
581
- expect(rows[0]!["capturedByFlowId"] ?? null).toBeNull();
582
- expect(prisma.flowDefinition.findFirst).not.toHaveBeenCalled();
583
- });
584
-
585
- it.each([
586
- ["names nothing at all", "no-such-magnet"],
587
- ["names ANOTHER workspace's listicle magnet", "other-list"],
588
- ["names a NON-listicle magnet in this workspace", "contact-us"],
589
- ])(
590
- "AC-6: a capturedByFlowSlug that %s writes NULL and still returns a 201 indistinguishable from a body that named no slug",
591
- async (_label, slug) => {
592
- const withSlug = await app.inject({
593
- method: "POST",
594
- url: "/v1/project-listings",
595
- payload: { ...START_PAYLOAD, capturedByFlowSlug: slug },
596
- });
597
- expect(withSlug.statusCode).toBe(201);
598
- expect(rows[0]!["capturedByFlowId"] ?? null).toBeNull();
599
-
600
- // Indistinguishable on the wire from the no-slug case: same status, same
601
- // key set, same envelope. A distinguishable error would turn this
602
- // anonymous route into a cross-workspace magnet-slug oracle (SEC-02).
603
- const withoutSlug = await app.inject({
604
- method: "POST",
605
- url: "/v1/project-listings",
606
- payload: START_PAYLOAD,
607
- });
608
- expect(withoutSlug.statusCode).toBe(withSlug.statusCode);
609
- expect(Object.keys(withoutSlug.json().data).sort()).toEqual(
610
- Object.keys(withSlug.json().data).sort(),
611
- );
612
- },
613
- );
614
-
615
- it("AC-13: an UNRESOLVED slug is logged, PII-safe — routing metadata only, never the founder's identity or either credential", async () => {
616
- const warn = jest.spyOn(logger, "warn").mockImplementation(() => undefined);
617
- try {
618
- const res = await app.inject({
619
- method: "POST",
620
- url: "/v1/project-listings",
621
- payload: {
622
- ...START_PAYLOAD,
623
- capturedByFlowSlug: "no-such-magnet",
624
- },
625
- });
626
- expect(res.statusCode).toBe(201);
627
-
628
- const call = warn.mock.calls.find(
629
- (c) =>
630
- typeof c[0] === "object" &&
631
- c[0] !== null &&
632
- "capturedByFlowSlug" in (c[0] as Record<string, unknown>),
633
- );
634
- expect(call).toBeDefined();
635
- const meta = call![0] as Record<string, unknown>;
636
- // Routing metadata ONLY. Silence here is what would make a stale or
637
- // mis-wired consuming site produce a permanently empty Applications list
638
- // indistinguishable from "no applications yet" (SEC-03).
639
- expect(Object.keys(meta).sort()).toEqual([
640
- "capturedByFlowSlug",
641
- "listingId",
642
- "siteId",
643
- ]);
644
- const serialized = JSON.stringify(meta);
645
- expect(serialized).not.toContain("ada@example.com");
646
- expect(serialized).not.toContain("Ada Founder");
647
- expect(serialized).not.toContain(rows[0]!["resumeTokenHash"]);
648
- expect(serialized).not.toContain(rows[0]!["emailVerifyNonceHash"]);
649
- } finally {
650
- warn.mockRestore();
651
- }
652
- });
653
-
654
- it("AC-6: a capturedByFlowSlug lookup that THROWS degrades like an unresolvable slug — 201, NULL attribution, and a PII-safe warn distinct from the unresolved line", async () => {
655
- (prisma.flowDefinition.findFirst as jest.Mock).mockRejectedValueOnce(
656
- new Error("statement timeout"),
657
- );
658
- const warn = jest.spyOn(logger, "warn").mockImplementation(() => undefined);
659
- try {
660
- const res = await app.inject({
661
- method: "POST",
662
- url: "/v1/project-listings",
663
- payload: { ...START_PAYLOAD, capturedByFlowSlug: "founder-list" },
664
- });
665
- expect(res.statusCode).toBe(201);
666
- expect(rows[0]!["capturedByFlowId"] ?? null).toBeNull();
667
-
668
- const call = warn.mock.calls.find(
669
- (c) => typeof c[1] === "string" && c[1].includes("lookup failed"),
670
- );
671
- expect(call).toBeDefined();
672
- const meta = call![0] as Record<string, unknown>;
673
- expect(Object.keys(meta).sort()).toEqual([
674
- "capturedByFlowSlug",
675
- "err",
676
- "workspaceId",
677
- ]);
678
- // `JSON.stringify` cannot see an Error's NON-ENUMERABLE own properties —
679
- // `message` and `stack` among them — so stringifying `meta` alone would
680
- // pass whatever the error held and assert nothing. Pull them out by name.
681
- const err = meta["err"] as Error;
682
- const serialized = [
683
- JSON.stringify(meta),
684
- err?.message ?? "",
685
- err?.stack ?? "",
686
- ].join("\n");
687
- expect(serialized).not.toContain("ada@example.com");
688
- expect(serialized).not.toContain("Ada Founder");
689
-
690
- // The real guarantee is STRUCTURAL, not this assertion: the catch wraps
691
- // only the `findFirst`, whose scope holds no founder field at all. This
692
- // check is a tripwire over that property, never the proof of it.
693
- const line = call![1] as string;
694
- expect(line).toContain("lookup failed");
695
- expect(line).not.toContain("resolved to no listicle magnet");
696
- } finally {
697
- warn.mockRestore();
698
- }
699
- });
700
-
701
- it("a lookup that THROWS does NOT also emit the unresolved-slug line — during a DB incident that would be a false magnet-configuration signal", async () => {
702
- (prisma.flowDefinition.findFirst as jest.Mock).mockRejectedValueOnce(
703
- new Error("statement timeout"),
704
- );
705
- const warn = jest.spyOn(logger, "warn").mockImplementation(() => undefined);
706
- try {
707
- const res = await app.inject({
708
- method: "POST",
709
- url: "/v1/project-listings",
710
- payload: { ...START_PAYLOAD, capturedByFlowSlug: "founder-list" },
711
- });
712
- expect(res.statusCode).toBe(201);
713
- expect(rows[0]!["capturedByFlowId"] ?? null).toBeNull();
714
-
715
- const messages = warn.mock.calls.map((c) => String(c[1] ?? ""));
716
- // Exactly one line, and it is the accurate one. The throw never
717
- // established that no such magnet exists.
718
- expect(
719
- messages.filter((m) => m.includes("resolved to no listicle magnet")),
720
- ).toHaveLength(0);
721
- expect(messages.filter((m) => m.includes("lookup failed"))).toHaveLength(1);
722
- } finally {
723
- warn.mockRestore();
724
- }
725
- });
726
-
727
- it("a RESOLVED slug logs nothing — the warn line is the unresolved case's signal, not a per-application line", async () => {
728
- const warn = jest.spyOn(logger, "warn").mockImplementation(() => undefined);
729
- try {
730
- await app.inject({
731
- method: "POST",
732
- url: "/v1/project-listings",
733
- payload: { ...START_PAYLOAD, capturedByFlowSlug: "founder-list" },
734
- });
735
- expect(
736
- warn.mock.calls.filter(
737
- (c) =>
738
- typeof c[0] === "object" &&
739
- c[0] !== null &&
740
- "capturedByFlowSlug" in (c[0] as Record<string, unknown>),
741
- ),
742
- ).toHaveLength(0);
743
- } finally {
744
- warn.mockRestore();
745
- }
746
- });
747
-
748
- it("AC-7: capturedByFlowId is WRITE-ONCE — no patch and no submit changes it, and no patch body can reach it", async () => {
749
- const { id, resumeToken } = (await (async () => {
750
- const res = await app.inject({
751
- method: "POST",
752
- url: "/v1/project-listings",
753
- payload: { ...START_PAYLOAD, capturedByFlowSlug: "founder-list" },
754
- });
755
- expect(res.statusCode).toBe(201);
756
- return res.json().data as { id: string; resumeToken: string };
757
- })());
758
-
759
- expect(rows[0]!["capturedByFlowId"]).toBe(LISTICLE_ID);
760
-
761
- // A patch that tries to name the column outright is a `.strict()` 400 —
762
- // the key is not on any patch schema, so no body can reach the column.
763
- const injected = await app.inject({
764
- method: "PATCH",
765
- url: `/v1/project-listings/drafts/${id}`,
766
- headers: bearer(resumeToken),
767
- payload: { capturedByFlowId: FOREIGN_LISTICLE_ID },
768
- });
769
- expect(injected.statusCode).toBe(400);
770
- expect(rows[0]!["capturedByFlowId"]).toBe(LISTICLE_ID);
771
-
772
- // A legitimate patch leaves it untouched.
773
- const patched = await app.inject({
774
- method: "PATCH",
775
- url: `/v1/project-listings/drafts/${id}`,
776
- headers: bearer(resumeToken),
777
- payload: { name: "My Project" },
778
- });
779
- expect(patched.statusCode).toBe(200);
780
- expect(rows[0]!["capturedByFlowId"]).toBe(LISTICLE_ID);
781
-
782
- // And so does submit.
783
- await app.inject({
784
- method: "PATCH",
785
- url: `/v1/project-listings/drafts/${id}`,
786
- headers: bearer(resumeToken),
787
- payload: COMPLETE_APPLICATION,
788
- });
789
- const submitted = await app.inject({
790
- method: "POST",
791
- url: `/v1/project-listings/drafts/${id}/submit`,
792
- headers: bearer(resumeToken),
793
- });
794
- expect(submitted.statusCode).toBe(200);
795
- expect(rows[0]!["status"]).toBe("requested");
796
- expect(rows[0]!["capturedByFlowId"]).toBe(LISTICLE_ID);
797
- });
798
-
799
- // ── patch ──
800
-
801
- it("patch: a SINGLE-field patch round-trips", async () => {
802
- const { id, resumeToken } = await startDraft(app);
803
-
804
- const res = await app.inject({
805
- method: "PATCH",
806
- url: `/v1/project-listings/drafts/${id}`,
807
- headers: bearer(resumeToken),
808
- payload: { oneLiner: "Just the one field, saved on its own." },
809
- });
810
-
811
- expect(res.statusCode).toBe(200);
812
- const body = res.json() as { ok: boolean; data: Record<string, unknown> };
813
- expect(body.ok).toBe(true);
814
- expect(body.data["oneLiner"]).toBe("Just the one field, saved on its own.");
815
- // Still a draft, still incomplete — `patch` asserts no completeness.
816
- expect(body.data["status"]).toBe("draft");
817
- expect(body.data["name"]).toBeNull();
818
- });
819
-
820
- it("patch: a later patch MERGES rather than replacing", async () => {
821
- const { id, resumeToken } = await startDraft(app);
822
-
823
- await app.inject({
824
- method: "PATCH",
825
- url: `/v1/project-listings/drafts/${id}`,
826
- headers: bearer(resumeToken),
827
- payload: { name: "Step three" },
828
- });
829
- const res = await app.inject({
830
- method: "PATCH",
831
- url: `/v1/project-listings/drafts/${id}`,
832
- headers: bearer(resumeToken),
833
- payload: { address: "1 Founder Way" },
834
- });
835
-
836
- const body = res.json() as { data: Record<string, unknown> };
837
- // The earlier step survives the later one — the failure this guards is a
838
- // patch that blanks the nine fields the founder already filled in.
839
- expect(body.data["name"]).toBe("Step three");
840
- expect(body.data["address"]).toBe("1 Founder Way");
841
- });
842
-
843
- it("patch: refuses an empty body", async () => {
844
- const { id, resumeToken } = await startDraft(app);
845
- const res = await app.inject({
846
- method: "PATCH",
847
- url: `/v1/project-listings/drafts/${id}`,
848
- headers: bearer(resumeToken),
849
- payload: {},
850
- });
851
- expect(res.statusCode).toBe(400);
852
- });
853
-
854
- it("patch: 401s with no resume token at all", async () => {
855
- const { id } = await startDraft(app);
856
- const res = await app.inject({
857
- method: "PATCH",
858
- url: `/v1/project-listings/drafts/${id}`,
859
- payload: { name: "No credential" },
860
- });
861
- expect(res.statusCode).toBe(401);
862
- });
863
-
864
- // ── the token's binding ──
865
-
866
- it("a resume token grants ONE listing and no other", async () => {
867
- const first = await startDraft(app);
868
- const second = await startDraft(app, { founderEmail: "grace@example.com" });
869
-
870
- // The first founder's token, presented against the second's listing.
871
- const res = await app.inject({
872
- method: "PATCH",
873
- url: `/v1/project-listings/drafts/${second.id}`,
874
- headers: bearer(first.resumeToken),
875
- payload: { name: "Not mine to write" },
876
- });
877
-
878
- expect(res.statusCode).toBe(404);
879
- // And nothing was written to the row it was aimed at.
880
- const target = rows.find((r) => r["id"] === second.id)!;
881
- expect(target["name"]).toBeNull();
882
- });
883
-
884
- it("a wrong token is a 404, indistinguishable from an unknown draft", async () => {
885
- const { id } = await startDraft(app);
886
-
887
- const wrongToken = await app.inject({
888
- method: "PATCH",
889
- url: `/v1/project-listings/drafts/${id}`,
890
- headers: bearer("not-the-token"),
891
- payload: { name: "x" },
892
- });
893
- const unknownDraft = await app.inject({
894
- method: "PATCH",
895
- url: "/v1/project-listings/drafts/prjl_00000000-0000-7000-8000-0000000000ff",
896
- headers: bearer("not-the-token"),
897
- payload: { name: "x" },
898
- });
899
-
900
- expect(wrongToken.statusCode).toBe(404);
901
- expect(unknownDraft.statusCode).toBe(404);
902
- expect(wrongToken.json()).toEqual(unknownDraft.json());
903
- });
904
-
905
- // ── submit ──
906
-
907
- it("submit: an INCOMPLETE draft is refused with the missing fields NAMED", async () => {
908
- const { id, resumeToken } = await startDraft(app);
909
- // Two of the eleven required fields filled in; nine still missing.
910
- await app.inject({
911
- method: "PATCH",
912
- url: `/v1/project-listings/drafts/${id}`,
913
- headers: bearer(resumeToken),
914
- payload: { name: "My Project", address: "1 Founder Way" },
915
- });
916
-
917
- const res = await app.inject({
918
- method: "POST",
919
- url: `/v1/project-listings/drafts/${id}/submit`,
920
- headers: bearer(resumeToken),
921
- });
922
-
923
- expect(res.statusCode).toBe(422);
924
- const body = res.json() as { error: { code: string; missingFields: string[] } };
925
- expect(body.error.code).toBe("incomplete_application");
926
- // NAMED, so the form can send the founder to the step that owns each one.
927
- expect(body.error.missingFields).toEqual(
928
- expect.arrayContaining([
929
- "commitment",
930
- "faqs",
931
- "headline",
932
- "oneLiner",
933
- "problem",
934
- "product",
935
- "questions",
936
- "teamComposition",
937
- ]),
938
- );
939
- // The two fields that WERE filled in are not reported missing.
940
- expect(body.error.missingFields).not.toContain("name");
941
- expect(body.error.missingFields).not.toContain("address");
942
- // And the row did not move.
943
- expect(rows.find((r) => r["id"] === id)!["status"]).toBe("draft");
944
- });
945
-
946
- it("submit: a COMPLETE draft transitions to `requested` and returns the derived slug", async () => {
947
- const { id, resumeToken } = await startDraft(app);
948
- await app.inject({
949
- method: "PATCH",
950
- url: `/v1/project-listings/drafts/${id}`,
951
- headers: bearer(resumeToken),
952
- payload: COMPLETE_APPLICATION,
953
- });
954
-
955
- const res = await app.inject({
956
- method: "POST",
957
- url: `/v1/project-listings/drafts/${id}/submit`,
958
- headers: bearer(resumeToken),
959
- });
960
-
961
- expect(res.statusCode).toBe(200);
962
- expect(res.json()).toEqual({ ok: true, data: { id, slug: "my-project" } });
963
-
964
- const row = rows.find((r) => r["id"] === id)!;
965
- expect(row["status"]).toBe("requested");
966
- // The Lead is written HERE, once, for a completed application.
967
- expect(prisma.lead.create).toHaveBeenCalledTimes(1);
968
- const lead = (prisma.lead.create as jest.Mock).mock.calls[0][0];
969
- expect(lead.data.source).toBe("projects-apply");
970
- expect(lead.data.email).toBe("ada@example.com");
971
- expect(row["leadId"]).not.toBeNull();
972
- expect(row["slug"]).toBe("my-project");
973
- // The token is spent: a leak after submission grants nothing.
974
- expect(row["resumeTokenHash"]).toBeNull();
975
- });
976
-
977
- // #8661 D4 — a listing's slug becomes its diagnostic flow's slug, so the
978
- // standard magnets' slugs are taken; any other name is unchanged.
979
- it.each([
980
- ["Contact", "contact-2"],
981
- ["Onboarding", "onboarding-2"],
982
- ["Atlas", "atlas"],
983
- ])("submit: a draft named %s is stored at %s (#8661 D4, AC-2)", async (name, slug) => {
984
- const { id, resumeToken } = await startDraft(app);
985
- await app.inject({
986
- method: "PATCH",
987
- url: `/v1/project-listings/drafts/${id}`,
988
- headers: bearer(resumeToken),
989
- payload: { ...COMPLETE_APPLICATION, name },
990
- });
991
-
992
- const res = await app.inject({
993
- method: "POST",
994
- url: `/v1/project-listings/drafts/${id}/submit`,
995
- headers: bearer(resumeToken),
996
- });
997
-
998
- expect(res.statusCode).toBe(200);
999
- expect(res.json()).toEqual({ ok: true, data: { id, slug } });
1000
- expect(rows.find((r) => r["id"] === id)!["slug"]).toBe(slug);
1001
- });
1002
-
1003
- it("submit: a spent token cannot patch or re-submit the listing", async () => {
1004
- const { id, resumeToken } = await startDraft(app);
1005
- await app.inject({
1006
- method: "PATCH",
1007
- url: `/v1/project-listings/drafts/${id}`,
1008
- headers: bearer(resumeToken),
1009
- payload: COMPLETE_APPLICATION,
1010
- });
1011
- await app.inject({
1012
- method: "POST",
1013
- url: `/v1/project-listings/drafts/${id}/submit`,
1014
- headers: bearer(resumeToken),
1015
- });
1016
-
1017
- const patchAgain = await app.inject({
1018
- method: "PATCH",
1019
- url: `/v1/project-listings/drafts/${id}`,
1020
- headers: bearer(resumeToken),
1021
- payload: { name: "Renamed after the fact" },
1022
- });
1023
- const submitAgain = await app.inject({
1024
- method: "POST",
1025
- url: `/v1/project-listings/drafts/${id}/submit`,
1026
- headers: bearer(resumeToken),
1027
- });
1028
-
1029
- expect(patchAgain.statusCode).toBe(404);
1030
- expect(submitAgain.statusCode).toBe(404);
1031
- expect(rows.find((r) => r["id"] === id)!["name"]).toBe("My Project");
1032
- });
1033
-
1034
- it("submit: 401s with no resume token at all", async () => {
1035
- const { id } = await startDraft(app);
1036
- const res = await app.inject({
1037
- method: "POST",
1038
- url: `/v1/project-listings/drafts/${id}/submit`,
1039
- });
1040
- expect(res.statusCode).toBe(401);
1041
- });
1042
-
1043
- // ── the concurrent-listing limit (#5036 D7) ──
1044
-
1045
- it("a third concurrent listing is refused at submit — and one of the two is a DRAFT", async () => {
1046
- // One already ACTIVE listing for this founder…
1047
- const active = await startDraft(app);
1048
- Object.assign(rows.find((r) => r["id"] === active.id)!, {
1049
- status: "active",
1050
- slug: "already-live",
1051
- windowEndsAt: new Date(Date.now() + 86_400_000),
1052
- });
1053
-
1054
- // …and one still a DRAFT. If drafts did not count, the limit would be
1055
- // evaded by simply never submitting — which is the state a ten-step form
1056
- // leaves a founder in by default.
1057
- await startDraft(app);
1058
-
1059
- // The third.
1060
- const third = await startDraft(app);
1061
- await app.inject({
1062
- method: "PATCH",
1063
- url: `/v1/project-listings/drafts/${third.id}`,
1064
- headers: bearer(third.resumeToken),
1065
- payload: COMPLETE_APPLICATION,
1066
- });
1067
- const res = await app.inject({
1068
- method: "POST",
1069
- url: `/v1/project-listings/drafts/${third.id}/submit`,
1070
- headers: bearer(third.resumeToken),
1071
- });
1072
-
1073
- expect(res.statusCode).toBe(409);
1074
- expect((res.json() as { error: { code: string } }).error.code).toBe("listing_limit_reached");
1075
- expect(rows.find((r) => r["id"] === third.id)!["status"]).toBe("draft");
1076
- });
1077
-
1078
- it("a long-abandoned draft stops holding a slot", async () => {
1079
- // Drafts count — that is D7, and it is what stops the limit being evaded by
1080
- // never submitting. But `founderEmail` is unverified here, so a draft that
1081
- // counted FOREVER would let two anonymous requests lock a named founder out
1082
- // permanently, with no operator remedy (PR #5042 security review, finding
1083
- // 1). The window is what makes that lockout expire.
1084
- for (let i = 0; i < 2; i += 1) {
1085
- const stale = await startDraft(app);
1086
- Object.assign(rows.find((r) => r["id"] === stale.id)!, {
1087
- createdAt: new Date(Date.now() - 15 * 24 * 60 * 60 * 1000),
1088
- });
1089
- }
1090
-
1091
- const third = await startDraft(app);
1092
- await app.inject({
1093
- method: "PATCH",
1094
- url: `/v1/project-listings/drafts/${third.id}`,
1095
- headers: bearer(third.resumeToken),
1096
- payload: COMPLETE_APPLICATION,
1097
- });
1098
- const res = await app.inject({
1099
- method: "POST",
1100
- url: `/v1/project-listings/drafts/${third.id}/submit`,
1101
- headers: bearer(third.resumeToken),
1102
- });
1103
-
1104
- expect(res.statusCode).toBe(200);
1105
- });
1106
-
1107
- it("a FRESH draft still holds a slot", async () => {
1108
- // The other half of the window: two drafts created today do bind, so the
1109
- // limit is not evaded by simply not pressing submit.
1110
- await startDraft(app);
1111
- await startDraft(app);
1112
-
1113
- const third = await startDraft(app);
1114
- await app.inject({
1115
- method: "PATCH",
1116
- url: `/v1/project-listings/drafts/${third.id}`,
1117
- headers: bearer(third.resumeToken),
1118
- payload: COMPLETE_APPLICATION,
1119
- });
1120
- const res = await app.inject({
1121
- method: "POST",
1122
- url: `/v1/project-listings/drafts/${third.id}/submit`,
1123
- headers: bearer(third.resumeToken),
1124
- });
1125
-
1126
- expect(res.statusCode).toBe(409);
1127
- });
1128
-
1129
- it("a TERMINAL listing does not count toward the limit", async () => {
1130
- // Two listings, but both terminal: one rejected, one whose window elapsed
1131
- // (which reads `closed`, computed, with no job having run).
1132
- const rejected = await startDraft(app);
1133
- Object.assign(rows.find((r) => r["id"] === rejected.id)!, {
1134
- status: "rejected",
1135
- slug: "turned-down",
1136
- });
1137
- const expired = await startDraft(app);
1138
- Object.assign(rows.find((r) => r["id"] === expired.id)!, {
1139
- status: "active",
1140
- slug: "ran-its-course",
1141
- windowEndsAt: new Date(Date.now() - 86_400_000),
1142
- });
1143
-
1144
- const third = await startDraft(app);
1145
- await app.inject({
1146
- method: "PATCH",
1147
- url: `/v1/project-listings/drafts/${third.id}`,
1148
- headers: bearer(third.resumeToken),
1149
- payload: COMPLETE_APPLICATION,
1150
- });
1151
- const res = await app.inject({
1152
- method: "POST",
1153
- url: `/v1/project-listings/drafts/${third.id}/submit`,
1154
- headers: bearer(third.resumeToken),
1155
- });
1156
-
1157
- expect(res.statusCode).toBe(200);
1158
- });
1159
-
1160
- it("the limit is scoped to one founder — another founder's listings do not count", async () => {
1161
- for (const email of ["grace@example.com", "alan@example.com"]) {
1162
- const other = await startDraft(app, { founderEmail: email });
1163
- Object.assign(rows.find((r) => r["id"] === other.id)!, {
1164
- status: "active",
1165
- slug: `live-${email.split("@")[0]}`,
1166
- windowEndsAt: new Date(Date.now() + 86_400_000),
1167
- });
1168
- }
1169
-
1170
- const mine = await startDraft(app);
1171
- await app.inject({
1172
- method: "PATCH",
1173
- url: `/v1/project-listings/drafts/${mine.id}`,
1174
- headers: bearer(mine.resumeToken),
1175
- payload: COMPLETE_APPLICATION,
1176
- });
1177
- const res = await app.inject({
1178
- method: "POST",
1179
- url: `/v1/project-listings/drafts/${mine.id}/submit`,
1180
- headers: bearer(mine.resumeToken),
1181
- });
1182
-
1183
- expect(res.statusCode).toBe(200);
1184
- });
1185
-
1186
- // ── logging ──
1187
-
1188
- it("no founder PII and no resume token reaches the route's own log line", async () => {
1189
- // Scoped to the log statements THIS route makes. Fastify's built-in
1190
- // request/response logging serializes the raw request (body included) and
1191
- // `inject`'s own harness stashes the response payload on it — neither is
1192
- // this route's doing, and neither is what the PII boundary is about. What
1193
- // is this route's doing is the one `request.log.info` call below.
1194
- const calls: Record<string, unknown>[] = [];
1195
- const logging = Fastify({
1196
- logger: {
1197
- level: "info",
1198
- hooks: {
1199
- logMethod(args: unknown[], method: (...a: never[]) => void) {
1200
- if (typeof args[1] === "string" && args[1] === "project listing draft started") {
1201
- calls.push(args[0] as Record<string, unknown>);
1202
- }
1203
- method.apply(this, args as never[]);
1204
- },
1205
- },
1206
- },
1207
- disableRequestLogging: true,
1208
- });
1209
- await logging.register(startProjectListingRoute);
1210
- await logging.ready();
1211
-
1212
- const res = await logging.inject({
1213
- method: "POST",
1214
- url: "/v1/project-listings",
1215
- payload: START_PAYLOAD,
1216
- });
1217
- const { resumeToken } = (res.json() as { data: { resumeToken: string } }).data;
1218
-
1219
- expect(calls).toHaveLength(1);
1220
- const serialized = JSON.stringify(calls[0]);
1221
- expect(serialized).not.toContain("ada@example.com");
1222
- expect(serialized).not.toContain("Ada Founder");
1223
- expect(serialized).not.toContain(resumeToken);
1224
- // Routing metadata only.
1225
- expect(Object.keys(calls[0]!).sort()).toEqual(["ip", "listingId", "siteId"]);
1226
-
1227
- await logging.close();
1228
- });
1229
- });
1230
-
1231
- // ── #6335 — the explicit workspace setup above is load-bearing ────────────
1232
- //
1233
- // Every case in this file states that this suite's site has a workspace.
1234
- // This one takes that away, and proves the statement was doing work rather
1235
- // than decorating the setup: `startProjectListingDraft` resolves the site it
1236
- // is filing against (`resolveWorkspaceIdForSite`, services/project-listings.ts)
1237
- // and refuses BEFORE any row is written. With the shared prisma mock's old
1238
- // permissive default in place this case could not be written at all — every
1239
- // id resolved, so the fail-closed path was unreachable from a route test.
1240
- describe("#6335 — start fails closed when the site names no workspace", () => {
1241
- let app: FastifyInstance;
1242
-
1243
- beforeEach(async () => {
1244
- jest.clearAllMocks();
1245
- installStore();
1246
- mockNoWorkspace(prisma);
1247
- app = await buildApp();
1248
- });
1249
-
1250
- afterEach(async () => {
1251
- await app.close();
1252
- });
1253
-
1254
- it("answers 503 tenant_unresolved and creates no ProjectListing", async () => {
1255
- const res = await app.inject({
1256
- method: "POST",
1257
- url: "/v1/project-listings",
1258
- payload: START_PAYLOAD,
1259
- });
1260
-
1261
- expect(res.statusCode).toBe(503);
1262
- expect((res.json() as { error: { code: string } }).error.code).toBe(
1263
- "tenant_unresolved",
1264
- );
1265
- expect(prisma.projectListing.create).not.toHaveBeenCalled();
1266
- expect(rows).toHaveLength(0);
1267
- });
1268
- });