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,639 +0,0 @@
1
- /**
2
- * Leads route group.
3
- *
4
- * Routes:
5
- * POST /v1/leads/submit — lead submission (contact form / inquiry)
6
- * POST /v1/leads/subscribe — newsletter subscription
7
- * POST /v1/leads/callback — callback request (phone-back)
8
- * GET /v1/leads/capture — whether this deployment accepts a contact
9
- * message / a newsletter signup (#6730 D4)
10
- *
11
- * API↔MCP PARITY — `GET /v1/leads/capture` has NO MCP twin, a recorded
12
- * exception on the same footing as the anonymous form-lifecycle routes. It
13
- * exists so a web page can choose between the form and the contact email
14
- * before rendering; an agent never needs that preflight, because the three
15
- * write tools (`capture_lead`, `subscribe_newsletter`, `request_callback`)
16
- * already return a typed `api_error` carrying the 503 when capture is not
17
- * accepted — the same answer, at the moment it matters.
18
- *
19
- * TENANT RESOLUTION (#6203, spec §10.4 operator ruling — reverses this
20
- * file's former byte-unchanged posture). `siteId` used to be taken VERBATIM
21
- * from the request body (`body["siteId"] as string`) — an anonymous, no-
22
- * ownership-check value (`packages/validation/src/schemas/leads.ts`'s
23
- * `safeSiteIdString` permits a `wksp_<uuidv7>`-shaped literal). Every
24
- * capture kind now resolves its tenant SERVER-SIDE, via
25
- * `resolveSiteWorkspaceId()` (`lib/site.ts`) — the SAME alias -> workspace
26
- * resolution `currentSiteId()`/`AILK_SITE_ID` already drive throughout this
27
- * app, unconditional on the content adapter — and a client-posted `siteId`
28
- * is IGNORED entirely: it can no longer place a row anywhere. An unresolved
29
- * result (no DATABASE_URL, or the alias names no workspace this database
30
- * holds) is a 503 before any write is attempted — never a guess. See
31
- * `lead-routing.ts`'s own header for the persistence-side half.
32
- *
33
- * A REGISTERED SPOKE (#7532 D4) resolves FIRST: a hub serving several spokes
34
- * reads the spoke's key from `x-ailk-spoke-key` through
35
- * `resolveCallerSite()` (`services/public-site-resolver.ts`) and writes the
36
- * lead into that spoke's own workspace. A refused key — malformed, unknown or
37
- * revoked, or no key at all on a hub (a deployment whose spoke registry holds
38
- * a row, or one whose `AILK_HUB_REQUIRE_SPOKE_KEY` is `true`; #7633) — is the
39
- * same 503 `tenant_unresolved` before any write. A header-less request on a
40
- * deployment with no registered spoke, or under the emergency opt-out
41
- * (`AILK_HUB_REQUIRE_SPOKE_KEY=false`), takes the alias resolution above,
42
- * unchanged. So does a keyless request whose hub-status read fails before the
43
- * process has any answer: lead capture is never lost (#7633, conductor
44
- * amendment to NFR3). The body's `siteId` stays ignored on every branch.
45
- *
46
- * IDEMPOTENCY KEY (#7869, roadmap D5). `POST /v1/leads/submit` accepts an
47
- * optional `Idempotency-Key` header: 16 to 255 visible ASCII characters, and
48
- * it must be UNGUESSABLE (a UUID, a Stripe Checkout Session id) — a key is
49
- * first-write-wins inside its workspace, so a short or predictable one could
50
- * be claimed by someone else first (SEC-7869-1). It is checked after the
51
- * tenant gate and before `routeLead`; a malformed key is `400 invalid_input`
52
- * with no read or write. A repeat of a stored key in the same workspace with
53
- * the same `email`, `source` and `payload` answers the first lead's 201 and
54
- * writes nothing; with anything different it is `422
55
- * idempotency_key_reused`. The key dedupes only where a `Lead` row exists —
56
- * `inbox` delivery — so a first write that fell back to email or a local
57
- * file leaves nothing to find, and its retry writes again. `subscribe` and
58
- * `callback` never read the header. The key is never logged or echoed.
59
- *
60
- * CONTACT TERMS ACCEPTANCE (#8730). A `submit` whose `source` is a
61
- * consent-bearing source (`isConsentLeadSource` in @working-theory/validation:
62
- * the contact sources `contact-form`, `conversational-intake`, `flow:contact`,
63
- * and since #9130 the Free apply page's `flow:job-application`) must carry a
64
- * top-level `consent: true` — the boolean, nothing else — or it is
65
- * `400 consent_required` before the tenant read or any write. An accepted one
66
- * gets `payload.consent = { statement, acceptedAt }` written HERE, replacing
67
- * any `payload.consent` the client sent: `statement` is the platform's
68
- * contact terms statement (`CONTACT_FORM_TERMS_STATEMENT`) and `acceptedAt`
69
- * this request's receive time. The `consent` flag itself is never stored. A
70
- * lead with any other source, `subscribe` and `callback` are unchanged. A
71
- * direct caller can still send `consent: true`; the gate makes acceptance an
72
- * explicit, recorded assertion, not proof that a person read the terms.
73
- *
74
- * THE BODY GATE (#7171, #7172, #7173 — the operator's decision of
75
- * 2026-10-19: the MCP tool adopts the API, arguments and results). Each of
76
- * the three writes is its own registration, and each parses `request.body`
77
- * with one exported `@working-theory/validation` schema —
78
- * `leadSubmitBodySchema`, `leadSubscribeBodySchema`, `leadCallbackBodySchema`
79
- * — answering `400 invalid_input` (the first issue's message) when the body
80
- * is not admitted; `capture_lead`, `subscribe_newsletter` and
81
- * `request_callback` take exactly those exports and return the 201 below
82
- * unchanged, so the parity guard holds the three pairs as `twin`s. The
83
- * schemas are plain objects, never `.strict()`: every body a site form sends
84
- * today — `siteId` beside the fields, the StepFlow envelope with `email`
85
- * inside `payload`, no `payload` at all — still passes, an unknown key is
86
- * stripped from the parsed copy and never refused. The parsed value is a
87
- * gate only: `captureLead` reads the RAW `request.body`, so what `routeLead`
88
- * validates and persists is byte-identical to before (#5732 — the payload
89
- * walk sees the object that is stored). The one new refusal beyond the
90
- * schema's own is a malformed or `null` body, which threw before.
91
- *
92
- * API↔MCP PARITY for `consent` (#8730): `leadSubmitBodySchema` declares it
93
- * as an optional boolean, so the guard sees the same argument on both sides.
94
- * The REQUIREMENT — `true` on a consent-bearing source — is the handler's
95
- * own check below, which the guard does not model; `capture_lead` sends the
96
- * agent's own `source`, so an agent naming a consent source needs
97
- * `consent: true` exactly as a form does.
98
- *
99
- * A MAGNET'S COMPLETION (#8757 D6). After a `flow:<slug>` submit is written
100
- * to the database, `services/magnet-completion.ts` reads that LIVE magnet's
101
- * completion setting. On `invite` the 201 gains `next: { completion:
102
- * "invite" }` and — on a first write, never a replay — the submitter is sent
103
- * one confirmation email whose link starts sign-in with their address
104
- * prefilled (capped per recipient and per magnet, counted in the database);
105
- * on `checkout`, re-checked against the `commerce` claim and the published
106
- * offerings, it gains `next: { completion: "checkout", checkoutOffering }`.
107
- * `lead`, a draft or missing magnet, or a caller with nowhere to sign in
108
- * leaves the 201 as it was. A failed read or send never changes the 201,
109
- * and the completion read has a time budget (`MAGNET_COMPLETION_BUDGET_MS`).
110
- * `next` is reachable only through a `flow:` source, which the parity guard's
111
- * own argument fixture for `capture_lead` never sends, so the guard's
112
- * observation never carries it and `leadWriteResultSchema` does not declare
113
- * it (NFR5).
114
- *
115
- * A CHECKOUT'S ACCOUNT LINK (#8757 D14). A checkout fulfilment's submit
116
- * (`source: "web"`, `payload.page: "checkout"`) carries the caller's account
117
- * origin into `routeLead` as `accountOrigin`, resolved exactly as the invite
118
- * link's (`accountTargetFor`): the spoke's enabled sign-in client's callback
119
- * origin, or `FRONTEND_URL`'s on a keyless build with an account area. With
120
- * none, or a failed read, it is left out and the buyer's purchase email goes
121
- * without the link. No other submit makes this read, and the 201 is unchanged.
122
- *
123
- * API↔MCP PARITY for the header (#7869 D9, roadmap §12 Q5): NO guard entry.
124
- * The guard binds a route's arguments to the validation export its handler
125
- * `.safeParse`s on `request.params|query|body` — here `leadSubmitBodySchema`
126
- * — and models no header; the header check below is a regex test, not such a
127
- * parse, so the key is outside the compared contract. The 201 body's field
128
- * set is unchanged too, and `capture_lead` sends no header. If the guard
129
- * ever models headers, this becomes an API-side `arg-only-in`.
130
- */
131
-
132
- import { track } from "@working-theory/analytics/server";
133
- import {
134
- CONTACT_FORM_TERMS_STATEMENT,
135
- isConsentLeadSource,
136
- leadCallbackBodySchema,
137
- leadSubmitBodySchema,
138
- leadSubscribeBodySchema,
139
- type LeadSubmitNext,
140
- } from "@working-theory/validation";
141
- import type { FastifyPluginAsync, FastifyReply, FastifyRequest } from "fastify";
142
-
143
- import { acceptsKind, resolveLeadDelivery } from "../../lib/lead-delivery.js";
144
- import { currentSiteId, resolveSiteWorkspaceId } from "../../lib/site.js";
145
- import {
146
- CONSENT_VISITOR_HEADER,
147
- consentVisitorFromHeader,
148
- } from "../../services/consent.js";
149
- import {
150
- type LeadKind,
151
- type RouteLeadInput,
152
- routeLead,
153
- type SourceMeta,
154
- } from "../../services/lead-routing.js";
155
- import {
156
- accountTargetFor,
157
- magnetCompletionWithinBudget,
158
- sendInviteConfirmation,
159
- } from "../../services/magnet-completion.js";
160
- import { resolveCallerSite } from "../../services/public-site-resolver.js";
161
- import { sendRequestConfirmLink } from "../../services/request-confirm.js";
162
-
163
- /** #7869 D1 — 16 to 255 visible ASCII characters; no spaces, no list. */
164
- const IDEMPOTENCY_KEY_PATTERN = /^[\x21-\x7E]{16,255}$/;
165
-
166
- /**
167
- * Read a named string field from the body, falling back to the same-named
168
- * field inside `body.payload` when the top-level value is absent — the
169
- * step-flow envelope (`{ siteId, source, payload: <record> }`) carries its
170
- * identity fields inside `payload` rather than at the top level. A top-level
171
- * value always wins.
172
- */
173
- function liftString(
174
- body: Record<string, unknown>,
175
- payload: Record<string, unknown>,
176
- key: string,
177
- ): string {
178
- const topLevel = body[key];
179
- if (typeof topLevel === "string") return topLevel;
180
- const fromPayload = payload[key];
181
- return (typeof fromPayload === "string" ? fromPayload : topLevel) as string;
182
- }
183
-
184
- /** #8730, #9130 — the refusal a consent-bearing lead without terms acceptance gets. */
185
- const CONSENT_REQUIRED_BODY = {
186
- error: "consent_required",
187
- message: "Accept the terms to send this form.",
188
- } as const;
189
-
190
- /**
191
- * #8730 D3, #9130 — the accepted terms, recorded by the server on a
192
- * consent-bearing lead's payload, replacing any `consent` the client wrote
193
- * there. Only a plain object payload is stamped: anything else is left for
194
- * `routeLead`'s schema to refuse, never spread into an object that would then
195
- * pass it.
196
- */
197
- function withConsentRecord(payload: unknown, acceptedAt: string): unknown {
198
- if (typeof payload !== "object" || payload === null || Array.isArray(payload)) {
199
- return payload;
200
- }
201
- return {
202
- ...(payload as Record<string, unknown>),
203
- consent: { statement: CONTACT_FORM_TERMS_STATEMENT, acceptedAt },
204
- };
205
- }
206
-
207
- /**
208
- * Build a typed RouteLeadInput from the raw request body for a given kind.
209
- * Explicit destructure per kind prevents unknown fields (e.g. attacker-supplied
210
- * `id`) from reaching the service — the service's .strict() Zod schemas provide
211
- * a second layer, but we also keep the handler clean at the boundary. Lifting
212
- * `email`/`name`/`phone` out of `payload` (see liftString above) reads by
213
- * explicit field name only — it does not spread `payload`'s other keys, so
214
- * the same discipline holds. `payload` itself is passed through unchanged.
215
- *
216
- * `siteId` is the RESOLVED `workspaceId` (#6203) — never `body["siteId"]`.
217
- * A body-supplied `siteId` is read nowhere in this function; a client that
218
- * posts one has it silently ignored, never honoured.
219
- */
220
- function buildInput(
221
- kind: LeadKind,
222
- body: Record<string, unknown>,
223
- workspaceId: string,
224
- receivedAt: string,
225
- ): RouteLeadInput {
226
- const payload = (body["payload"] ?? {}) as Record<string, unknown>;
227
-
228
- if (kind === "submit") {
229
- return {
230
- kind,
231
- siteId: workspaceId,
232
- source: body["source"] as string,
233
- email: liftString(body, payload, "email"),
234
- payload: isConsentLeadSource(body["source"])
235
- ? (withConsentRecord(payload, receivedAt) as Record<string, unknown>)
236
- : payload,
237
- };
238
- }
239
- if (kind === "subscribe") {
240
- return {
241
- kind,
242
- siteId: workspaceId,
243
- email: liftString(body, payload, "email"),
244
- source: body["source"] as string,
245
- };
246
- }
247
- return {
248
- kind,
249
- siteId: workspaceId,
250
- name: liftString(body, payload, "name"),
251
- phone: liftString(body, payload, "phone"),
252
- ...(body["preferredTime"] !== undefined && {
253
- preferredTime: body["preferredTime"] as string,
254
- }),
255
- payload,
256
- };
257
- }
258
-
259
- /** A spoke checkout fulfilment's submit (#8757 D14): `source: "web"`, `payload.page: "checkout"`. */
260
- function isCheckoutSubmit(body: Record<string, unknown>): boolean {
261
- const payload = body["payload"];
262
- return (
263
- body["source"] === "web" &&
264
- typeof payload === "object" &&
265
- payload !== null &&
266
- (payload as Record<string, unknown>)["page"] === "checkout"
267
- );
268
- }
269
-
270
- /**
271
- * The refusal a body the route's own export does not admit gets (#7171,
272
- * #7172, #7173): the shape and the first-issue message `routeLead`'s
273
- * `invalid_input` branch already answers. Logs nothing.
274
- */
275
- function refuseBody(
276
- reply: FastifyReply,
277
- issues: readonly { message: string }[],
278
- ) {
279
- return reply.status(400).send({
280
- error: "invalid_input",
281
- message: issues[0]?.message ?? "invalid input",
282
- });
283
- }
284
-
285
- /**
286
- * The shared capture, after a kind's own gates: tenant resolution, the
287
- * idempotency key, `buildInput` over the RAW body, `routeLead`, the confirm
288
- * link, `next`, `track` and the 201. Reads `request.body` itself — never the
289
- * body export's parsed copy — so what `routeLead` validates and persists is
290
- * the object the client sent (the #5732 property: `boundedLeadPayload` walks
291
- * exactly what is persisted, an own `__proto__` key included, where a
292
- * `z.record` copy would have dropped it).
293
- */
294
- async function captureLead(
295
- kind: LeadKind,
296
- request: FastifyRequest,
297
- reply: FastifyReply,
298
- ) {
299
- const body = request.body as Record<string, unknown>;
300
-
301
- // request.ip became attacker-influenceable when trustProxy: true went
302
- // instance-wide (server.ts, #4730/#4778) — leads/index.ts was never
303
- // itself touched by that PR. Traced every consumer of this value
304
- // (#5112, DEF-004): lead-routing.ts's structured log field and its
305
- // opt-in (LEAD_CAPTURE_INCLUDE_IP) persisted metadata.ip both RECORD
306
- // the value; neither branches routing, persistence, or dedup on it.
307
- // The best-effort/record-only posture is judged sufficient — the same
308
- // trade-off server.ts's own trustProxy comment already accepts. The
309
- // private @working-theory/lead-routing package (not present in this
310
- // repo, not inspectable) is the one consumer this trace could not
311
- // complete; see docs/specs/5112-leads-ip-trace-spec.md §8.
312
- const sourceMeta: SourceMeta = {
313
- ip: request.ip,
314
- userAgent: request.headers["user-agent"],
315
- receivedAt: new Date().toISOString(),
316
- };
317
-
318
- // #7532 D4 — a registered spoke resolves first, to its own workspace; a
319
- // refused key never falls through to the alias below. A keyless lead
320
- // whose hub-status read fails on a cold start proceeds as on a non-hub,
321
- // so routeLead's outage fallback captures it (#7633 amendment).
322
- const caller = await resolveCallerSite(request, {
323
- keylessOnRegistryFailure: "anonymous",
324
- });
325
- if (caller.kind === "refused") {
326
- return reply.status(503).send({
327
- error: "tenant_unresolved",
328
- message: "This site is not configured to accept submissions.",
329
- });
330
- }
331
-
332
- // #6203 — resolve the tenant SERVER-SIDE before any write is
333
- // attempted. Two branches, deliberately different:
334
- //
335
- // - No DATABASE_URL: the zero-config OSS file-fallback deployment.
336
- // There is no `workspaces` table to resolve against (and
337
- // `assertSiteAliasResolves()` already skips its own boot check for
338
- // exactly this reason), so the "resolved" value here is the site
339
- // ALIAS itself (`currentSiteId()`) — the same value the file
340
- // fallback would have carried before this unit. Never a rejection:
341
- // that would break lead capture for every zero-config scaffold.
342
- // - DATABASE_URL set: resolve via `resolveSiteWorkspaceId()`, the
343
- // SAME alias -> workspace resolution `currentSiteId()` already
344
- // drives everywhere else in this app. `null` here is a genuine
345
- // misconfiguration `build()` already refuses to boot past
346
- // (`assertSiteAliasResolves()`) — reaching it at request time is
347
- // the residual case that startup check cannot catch (a workspace
348
- // deleted after boot, a transient read), and it fails closed the
349
- // same way: reject, never guess (spec AC-4).
350
- let workspaceId: string;
351
- if (caller.kind === "spoke") {
352
- workspaceId = caller.workspaceId;
353
- sourceMeta.viaSpoke = true;
354
- } else if (!process.env.DATABASE_URL) {
355
- workspaceId = currentSiteId();
356
- } else {
357
- const resolved = await resolveSiteWorkspaceId();
358
- if (resolved === null) {
359
- request.log.error(
360
- { kind },
361
- "lead capture: DATABASE_URL is set but the site alias resolves to no workspace",
362
- );
363
- return reply.status(503).send({
364
- error: "tenant_unresolved",
365
- message: "This site is not configured to accept submissions.",
366
- });
367
- }
368
- workspaceId = resolved;
369
- }
370
-
371
- // #7869 D1 — after the tenant gate, before any read or write. Node
372
- // lower-cases header names, and joins a duplicated header with ", ",
373
- // which the pattern refuses.
374
- let idempotencyKey: string | undefined;
375
- if (kind === "submit") {
376
- const rawKey = request.headers["idempotency-key"];
377
- if (rawKey !== undefined) {
378
- if (
379
- typeof rawKey !== "string" ||
380
- !IDEMPOTENCY_KEY_PATTERN.test(rawKey)
381
- ) {
382
- return reply.status(400).send({
383
- error: "invalid_input",
384
- message:
385
- "Idempotency-Key must be 16 to 255 visible ASCII characters.",
386
- });
387
- }
388
- idempotencyKey = rawKey;
389
- }
390
- }
391
-
392
- // #8185 D3 — a spoke's same-origin relay marks every forwarded call.
393
- // The mark can only remove the spoke-checkout marker, never grant it.
394
- sourceMeta.relayed = request.headers["x-ailk-relayed"] !== undefined;
395
-
396
- // #8438 D11 — the cookie banner's visitor id, forwarded by the site's
397
- // own server from its first-party cookie. Only a v4 UUID counts; the
398
- // header is never echoed or logged. It links the visitor to the
399
- // lead's Person after the write, and changes nothing about the answer.
400
- const consentVisitorId = consentVisitorFromHeader(
401
- request.headers[CONSENT_VISITOR_HEADER],
402
- );
403
- if (consentVisitorId !== undefined) {
404
- sourceMeta.consentVisitorId = consentVisitorId;
405
- }
406
-
407
- // #8757 D14 — where a buyer's account lives, for the purchase email.
408
- let accountOrigin: string | undefined;
409
- if (kind === "submit" && isCheckoutSubmit(body)) {
410
- const target = await accountTargetFor(caller).catch(() => null);
411
- accountOrigin = target?.origin;
412
- }
413
-
414
- const result = await routeLead(
415
- buildInput(kind, body, workspaceId, sourceMeta.receivedAt),
416
- sourceMeta,
417
- {
418
- ...(idempotencyKey !== undefined && { idempotencyKey }),
419
- ...(accountOrigin !== undefined && { accountOrigin }),
420
- },
421
- );
422
-
423
- if (!result.ok) {
424
- if (result.error.kind === "idempotency_conflict") {
425
- // #7869 D6 — the operator's signal that a keyed lead was refused.
426
- // Never the key, the email or the payload.
427
- request.log.warn(
428
- { kind, siteId: workspaceId, outcome: "idempotency_conflict" },
429
- "lead idempotency_conflict",
430
- );
431
- return reply.status(422).send({
432
- error: "idempotency_key_reused",
433
- message: "This Idempotency-Key was used for a different lead.",
434
- });
435
- }
436
- if (result.error.kind === "invalid_input") {
437
- return reply
438
- .status(400)
439
- .send({ error: "invalid_input", message: result.error.message });
440
- }
441
- if (result.error.kind === "persist_failed") {
442
- // Do not surface internal error detail — log it server-side only
443
- request.log.error(
444
- { kind, siteId: workspaceId, error: result.error.message },
445
- "lead persist_failed",
446
- );
447
- return reply.status(503).send({ error: "persist_failed" });
448
- }
449
- if (result.error.kind === "delivery_failed") {
450
- // Email was the delivery and the provider did not accept it —
451
- // never reported as sent (#6730 D5). Detail stays server-side.
452
- // `{ kind, siteId }` only (spec D5): provider error text can echo
453
- // an address.
454
- request.log.error({ kind, siteId: workspaceId }, "lead delivery_failed");
455
- return reply.status(503).send({
456
- error: "delivery_failed",
457
- message: "The message could not be delivered.",
458
- });
459
- }
460
- // config_missing — this deployment has nowhere to put this kind of
461
- // lead (#6730 D1: production with neither a database nor the email
462
- // vars, or a newsletter signup with no database).
463
- return reply.status(503).send({
464
- error: "lead_capture_not_configured",
465
- message: "Lead capture is not configured.",
466
- });
467
- }
468
-
469
- // PII-safe structured log: only routing metadata, no email/phone/name/payload
470
- const emailKind =
471
- "skipped" in result.email
472
- ? "skipped"
473
- : result.email.ok
474
- ? "ok"
475
- : "error";
476
- request.log.info(
477
- {
478
- siteId: workspaceId,
479
- kind,
480
- ip: sourceMeta.ip,
481
- persisted: result.persisted,
482
- emailKind,
483
- replayed: result.replayed === true,
484
- },
485
- "lead routed",
486
- );
487
-
488
- // Request-and-confirm (#5970): mint the tenant's one-time confirm
489
- // credential and email them the link. Fire-and-forget and `void`-
490
- // returning, so the 201 below stays independent of both Resend and that
491
- // write — the request is already persisted by this point, and a send
492
- // that fails must never turn a captured lead into an error.
493
- //
494
- // Callback only: `submit` and `subscribe` have no confirm step. The
495
- // service itself no-ops (with a logged reason) when the feature is not
496
- // configured, which is the default.
497
- // `result.persisted === "db"` for the same reason `lead-routing.ts`
498
- // consults it (#5970 security review round 3, M1): the credential is
499
- // minted by an update on the `callbacks` row, so a FILE-FALLBACK id
500
- // would match nothing and the operator would be left with no email at
501
- // all. On that path the generic notification is sent instead, which is
502
- // what keeps "exactly one" true in both directions.
503
- // A spoke's callback never takes this path (#7532 D4, SEC-7532-2): the
504
- // link is minted on the deployment's one Stripe account.
505
- if (
506
- kind === "callback" &&
507
- result.persisted === "db" &&
508
- caller.kind !== "spoke"
509
- ) {
510
- const callbackInput = buildInput(
511
- kind,
512
- body,
513
- workspaceId,
514
- sourceMeta.receivedAt,
515
- ) as Extract<RouteLeadInput, { kind: "callback" }>;
516
- sendRequestConfirmLink(result.id, {
517
- name: callbackInput.name,
518
- phone: callbackInput.phone,
519
- ...(callbackInput.preferredTime !== undefined && {
520
- preferredTime: callbackInput.preferredTime,
521
- }),
522
- });
523
- }
524
-
525
- // #8757 D6 — a written `flow:<slug>` submit answers its magnet's
526
- // completion. A read that fails, or outlasts its budget, leaves the 201
527
- // as it was: the lead is saved.
528
- let next: LeadSubmitNext | undefined;
529
- const source = body["source"];
530
- if (
531
- kind === "submit" &&
532
- result.persisted === "db" &&
533
- typeof source === "string" &&
534
- source.startsWith("flow:")
535
- ) {
536
- const slug = source.slice("flow:".length);
537
- try {
538
- const completion = await magnetCompletionWithinBudget(workspaceId, slug, () =>
539
- accountTargetFor(caller),
540
- );
541
- if (completion !== null) {
542
- next = completion.next;
543
- if (completion.next.completion === "invite" && !result.replayed) {
544
- const submitInput = buildInput(
545
- kind,
546
- body,
547
- workspaceId,
548
- sourceMeta.receivedAt,
549
- ) as Extract<RouteLeadInput, { kind: "submit" }>;
550
- const locale = submitInput.payload["locale"];
551
- void sendInviteConfirmation({
552
- workspaceId,
553
- slug,
554
- email: submitInput.email,
555
- locale: typeof locale === "string" ? locale : undefined,
556
- completion,
557
- now: new Date(),
558
- });
559
- }
560
- }
561
- } catch (error) {
562
- request.log.error(
563
- { event: "magnet-completion", error: error instanceof Error ? error.name : "unknown" },
564
- "lead magnet completion read failed",
565
- );
566
- }
567
- }
568
-
569
- // Fire-and-forget: track() never throws; no need to hold the response.
570
- // #7869 D6 — a replay records nothing new: the first write counted it.
571
- if (!result.replayed) {
572
- void track("lead-captured", {
573
- source: body["source"] as string | undefined,
574
- locale: (body["payload"] as Record<string, unknown> | undefined)?.[
575
- "locale"
576
- ] as string | undefined,
577
- });
578
- }
579
-
580
- return reply.status(201).send({
581
- id: result.id,
582
- persisted: result.persisted,
583
- email: result.email,
584
- ...(next === undefined ? {} : { next }),
585
- });
586
- }
587
-
588
- export const leadSubmitRoute: FastifyPluginAsync = async (fastify) => {
589
- fastify.post("/v1/leads/submit", async (request, reply) => {
590
- const body = request.body as Record<string, unknown>;
591
-
592
- // #8730 D1, #9130 — a contact lead or a job application carries the
593
- // visitor's terms acceptance, or it is refused before the body gate, the
594
- // tenant read and any write.
595
- if (isConsentLeadSource(body?.["source"]) && body?.["consent"] !== true) {
596
- return reply.status(400).send(CONSENT_REQUIRED_BODY);
597
- }
598
- const parsed = leadSubmitBodySchema.safeParse(request.body);
599
- if (!parsed.success) return refuseBody(reply, parsed.error.issues);
600
- return captureLead("submit", request, reply);
601
- });
602
- };
603
-
604
- export const leadSubscribeRoute: FastifyPluginAsync = async (fastify) => {
605
- fastify.post("/v1/leads/subscribe", async (request, reply) => {
606
- const parsed = leadSubscribeBodySchema.safeParse(request.body);
607
- if (!parsed.success) return refuseBody(reply, parsed.error.issues);
608
- return captureLead("subscribe", request, reply);
609
- });
610
- };
611
-
612
- export const leadCallbackRoute: FastifyPluginAsync = async (fastify) => {
613
- fastify.post("/v1/leads/callback", async (request, reply) => {
614
- const parsed = leadCallbackBodySchema.safeParse(request.body);
615
- if (!parsed.success) return refuseBody(reply, parsed.error.issues);
616
- return captureLead("callback", request, reply);
617
- });
618
- };
619
-
620
- /**
621
- * `GET /v1/leads/capture` (#6730 D4) — two booleans and nothing else: never
622
- * an address or which env var is missing. (The pair implies as much of the
623
- * delivery mode as the rendered page already shows.) Registered at
624
- * the top level in `server.ts`, outside `leadsScope`'s strict per-IP limit
625
- * (a web server's single egress IP already spends that on form submissions),
626
- * so only the server-wide unauthenticated ceiling applies.
627
- */
628
- export const leadCaptureStatusRoute: FastifyPluginAsync = async (fastify) => {
629
- fastify.get("/v1/leads/capture", async (_request, reply) => {
630
- const delivery = resolveLeadDelivery();
631
- return reply.header("Cache-Control", "public, max-age=60").send({
632
- ok: true,
633
- data: {
634
- contact: acceptsKind(delivery, "submit"),
635
- newsletter: acceptsKind(delivery, "subscribe"),
636
- },
637
- });
638
- });
639
- };