create-ailk 0.23.0 → 0.25.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (604) hide show
  1. package/README.md +68 -33
  2. package/component-catalog.json +3 -3
  3. package/component-catalog.md +3 -3
  4. package/dist/add-module.js +10 -3
  5. package/dist/add-route.d.ts +12 -1
  6. package/dist/add-route.js +38 -4
  7. package/dist/cli.js +12 -7
  8. package/dist/derive-architecture.d.ts +3 -4
  9. package/dist/derive-architecture.js +75 -22
  10. package/dist/lib/design-checks.d.ts +9 -4
  11. package/dist/lib/design-checks.js +13 -7
  12. package/dist/lib/extract-module-bundle.js +29 -2
  13. package/dist/lib/fetch-template-snapshot.d.ts +1 -1
  14. package/dist/lib/fetch-template-snapshot.js +7 -3
  15. package/dist/lib/import-graph.d.ts +1 -1
  16. package/dist/lib/import-graph.js +4 -4
  17. package/dist/lib/module-license-gate.d.ts +12 -1
  18. package/dist/lib/module-license-gate.js +34 -12
  19. package/dist/lib/scaffold-render-sweep.d.ts +33 -0
  20. package/dist/lib/scaffold-render-sweep.js +45 -0
  21. package/dist/module-architecture.d.ts +20 -3
  22. package/dist/module-architecture.js +122 -538
  23. package/dist/paid-sections.d.ts +25 -1
  24. package/dist/paid-sections.js +88 -3
  25. package/dist/surfaces.js +10 -2
  26. package/dist/sync-routes.d.ts +30 -4
  27. package/dist/sync-routes.js +271 -18
  28. package/dist/template-record.d.ts +14 -4
  29. package/dist/template-record.js +23 -5
  30. package/dist/topology.d.ts +16 -3
  31. package/dist/topology.js +31 -19
  32. package/dist/update.d.ts +10 -1
  33. package/dist/update.js +540 -16
  34. package/package.json +3 -3
  35. package/release-scope.json +1 -1
  36. package/templates/.claude/cloudparity-repo-hooks.json +5 -0
  37. package/templates/.claude/hooks/template-guard.sh +137 -0
  38. package/templates/.claude/rules/extending.md +106 -0
  39. package/templates/.claude/rules/loop-contract.md +2 -2
  40. package/templates/.claude/settings.json +11 -0
  41. package/templates/.env.example +9 -5
  42. package/templates/.github/workflows/ci.yml +7 -4
  43. package/templates/CLAUDE.md +15 -3
  44. package/templates/CONVENTIONS.md +8 -10
  45. package/templates/README.md +14 -13
  46. package/templates/apps/api/.env.example +9 -2
  47. package/templates/apps/api/CLAUDE.md +122 -82
  48. package/templates/apps/api/jest.config.cjs +15 -5
  49. package/templates/apps/api/package.json +16 -20
  50. package/templates/apps/api/src/__tests__/trusted-origins.server.test.ts +2 -2
  51. package/templates/apps/api/src/__tests__/vercel-handler.test.ts +4 -4
  52. package/templates/apps/api/src/index.ts +1 -1
  53. package/templates/apps/api/src/lib/__mocks__/prisma.ts +7 -4
  54. package/templates/apps/api/src/modules/commerce.ts +10 -0
  55. package/templates/apps/api/src/modules/content-write.ts +10 -0
  56. package/templates/apps/api/src/modules/multi-tenant.ts +10 -0
  57. package/templates/apps/api/src/modules/scheduling.ts +10 -0
  58. package/templates/apps/api/src/modules/signal-collectors.ts +10 -0
  59. package/templates/apps/api/src/modules/workspace.ts +10 -0
  60. package/templates/apps/api/src/server.ts +117 -1857
  61. package/templates/apps/api/vercel.json +2 -2
  62. package/templates/apps/mcp/CLAUDE.md +77 -24
  63. package/templates/apps/mcp/__tests__/app-entry.test.ts +4 -254
  64. package/templates/apps/mcp/__tests__/boot-file.test.ts +92 -0
  65. package/templates/apps/mcp/jest.config.cjs +6 -1
  66. package/templates/apps/mcp/package.json +5 -12
  67. package/templates/apps/mcp/src/app.ts +8 -7
  68. package/templates/apps/mcp/src/index.ts +6 -34
  69. package/templates/apps/mcp/src/lib/paid-tools.generated.ts +10 -0
  70. package/templates/apps/mcp/src/lib/topology.generated.ts +2 -2
  71. package/templates/apps/mcp/src/site.ts +12 -0
  72. package/templates/apps/web/.env.example +1 -1
  73. package/templates/apps/web/CLAUDE.md +21 -5
  74. package/templates/apps/web/app/.well-known/mcp.json/route.ts +9 -3
  75. package/templates/apps/web/app/[locale]/contact/__tests__/ConversationalIntakeWrapper.test.tsx +1 -1
  76. package/templates/apps/web/app/[locale]/contact/contact.actions.ts +14 -4
  77. package/templates/apps/web/app/[locale]/contact/intake-analytics.ts +1 -1
  78. package/templates/apps/web/app/[locale]/contact/intake-script.ts +1 -1
  79. package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/magnet-page.test.tsx +22 -1
  80. package/templates/apps/web/app/[locale]/flows/[slug]/magnet-page.tsx +28 -7
  81. package/templates/apps/web/app/[locale]/pricing/__tests__/unconnected.test.tsx +43 -0
  82. package/templates/apps/web/app/[locale]/pricing/page.tsx +7 -3
  83. package/templates/apps/web/app/api/offerings/checkout/[lookupKey]/__tests__/route.test.ts +222 -0
  84. package/templates/apps/web/app/api/offerings/checkout/[lookupKey]/route.ts +10 -3
  85. package/templates/apps/web/app/api/revalidate/route.ts +3 -3
  86. package/templates/apps/web/auth.ts +2 -2
  87. package/templates/apps/web/jest.config.cjs +1 -0
  88. package/templates/apps/web/lib/__tests__/magnet-routes.test.ts +7 -0
  89. package/templates/apps/web/lib/auth-email.ts +1 -1
  90. package/templates/apps/web/lib/magnet-routes.ts +3 -1
  91. package/templates/apps/web/lib/newsletter.actions.ts +9 -6
  92. package/templates/apps/web/lib/relay.ts +2 -2
  93. package/templates/apps/web/lib/release-scope.ts +47 -0
  94. package/templates/apps/web/lib/server-api.ts +1 -1
  95. package/templates/apps/web/src/lib/commerce-claim.ts +1 -1
  96. package/templates/customizations.yaml +37 -0
  97. package/templates/database/prisma.config.ts +10 -14
  98. package/templates/database/seed-test.ts +2 -2
  99. package/templates/database/seed.ts +32 -5
  100. package/templates/package.json +12 -6
  101. package/templates/pnpm-workspace.yaml +0 -1
  102. package/templates/project.yaml +16 -8
  103. package/templates/tools/jest/reporters.cjs +65 -0
  104. package/templates/tools/lint-architecture.ts +757 -7
  105. package/templates/tsconfig.json +1 -2
  106. package/versions.json +48 -35
  107. package/templates/apps/api/src/__tests__/commerce-claim-registration.test.ts +0 -409
  108. package/templates/apps/api/src/__tests__/factories/agent-caller.ts +0 -102
  109. package/templates/apps/api/src/__tests__/factories/content-fixture.ts +0 -138
  110. package/templates/apps/api/src/__tests__/factories/in-memory-prisma.ts +0 -441
  111. package/templates/apps/api/src/__tests__/factories/index.ts +0 -70
  112. package/templates/apps/api/src/__tests__/factories/lead-fixture.ts +0 -82
  113. package/templates/apps/api/src/__tests__/leads-forwarded-rate-limit.test.ts +0 -135
  114. package/templates/apps/api/src/__tests__/services/enrichment-shim.test.ts +0 -126
  115. package/templates/apps/api/src/__tests__/stripe-boot.test.ts +0 -132
  116. package/templates/apps/api/src/__tests__/support/hub-sign-in-fake-db.ts +0 -362
  117. package/templates/apps/api/src/bin/__tests__/rate-limit-probe.test.ts +0 -184
  118. package/templates/apps/api/src/bin/abandon-sweep.ts +0 -42
  119. package/templates/apps/api/src/bin/rate-limit-probe.ts +0 -53
  120. package/templates/apps/api/src/bin/spokes.ts +0 -198
  121. package/templates/apps/api/src/bin/stripe-connections-rekey.ts +0 -45
  122. package/templates/apps/api/src/config/__tests__/hub-require-spoke-key.test.ts +0 -196
  123. package/templates/apps/api/src/config/__tests__/index.test.ts +0 -233
  124. package/templates/apps/api/src/config/__tests__/modules.test.ts +0 -76
  125. package/templates/apps/api/src/config/__tests__/stripe-connection-key.test.ts +0 -185
  126. package/templates/apps/api/src/config/__tests__/trusted-origins.test.ts +0 -238
  127. package/templates/apps/api/src/config/index.ts +0 -596
  128. package/templates/apps/api/src/config/modules.ts +0 -83
  129. package/templates/apps/api/src/lib/__tests__/agent-store.test.ts +0 -581
  130. package/templates/apps/api/src/lib/__tests__/auth-email-budget.test.ts +0 -143
  131. package/templates/apps/api/src/lib/__tests__/consent-ledger-double.ts +0 -237
  132. package/templates/apps/api/src/lib/__tests__/consent-store.test.ts +0 -353
  133. package/templates/apps/api/src/lib/__tests__/content-adapter.test.ts +0 -201
  134. package/templates/apps/api/src/lib/__tests__/deliverable-asset-store.test.ts +0 -224
  135. package/templates/apps/api/src/lib/__tests__/error-serializer.test.ts +0 -120
  136. package/templates/apps/api/src/lib/__tests__/errors.test.ts +0 -94
  137. package/templates/apps/api/src/lib/__tests__/file-fallback.test.ts +0 -144
  138. package/templates/apps/api/src/lib/__tests__/fixtures/HomePage/home.mdx +0 -8
  139. package/templates/apps/api/src/lib/__tests__/flow-completion-store.test.ts +0 -149
  140. package/templates/apps/api/src/lib/__tests__/flow-rename-race.db.test.ts +0 -116
  141. package/templates/apps/api/src/lib/__tests__/hub-sign-in-store.test.ts +0 -209
  142. package/templates/apps/api/src/lib/__tests__/lead-capture-store.test.ts +0 -257
  143. package/templates/apps/api/src/lib/__tests__/lead-delivery.test.ts +0 -96
  144. package/templates/apps/api/src/lib/__tests__/outbound-http.test.ts +0 -125
  145. package/templates/apps/api/src/lib/__tests__/prisma.test.ts +0 -165
  146. package/templates/apps/api/src/lib/__tests__/require-commerce-claim.test.ts +0 -317
  147. package/templates/apps/api/src/lib/__tests__/require-paid-tier.test.ts +0 -129
  148. package/templates/apps/api/src/lib/__tests__/site.test.ts +0 -292
  149. package/templates/apps/api/src/lib/__tests__/slice-load.test.ts +0 -89
  150. package/templates/apps/api/src/lib/__tests__/spoke-store.test.ts +0 -202
  151. package/templates/apps/api/src/lib/__tests__/stripe-admission.test.ts +0 -217
  152. package/templates/apps/api/src/lib/__tests__/stripe.test.ts +0 -82
  153. package/templates/apps/api/src/lib/agent-store.ts +0 -613
  154. package/templates/apps/api/src/lib/auth-email-budget.ts +0 -161
  155. package/templates/apps/api/src/lib/consent-store.ts +0 -363
  156. package/templates/apps/api/src/lib/content-adapter.ts +0 -112
  157. package/templates/apps/api/src/lib/deliverable-asset-store.ts +0 -96
  158. package/templates/apps/api/src/lib/error-serializer.ts +0 -164
  159. package/templates/apps/api/src/lib/errors.ts +0 -95
  160. package/templates/apps/api/src/lib/file-fallback.ts +0 -87
  161. package/templates/apps/api/src/lib/flow-completion-store.ts +0 -136
  162. package/templates/apps/api/src/lib/hub-sign-in-store.ts +0 -455
  163. package/templates/apps/api/src/lib/lead-capture-store.ts +0 -122
  164. package/templates/apps/api/src/lib/lead-delivery.ts +0 -52
  165. package/templates/apps/api/src/lib/license-key-store.ts +0 -45
  166. package/templates/apps/api/src/lib/locales.ts +0 -201
  167. package/templates/apps/api/src/lib/outbound-http.ts +0 -127
  168. package/templates/apps/api/src/lib/prisma.ts +0 -21
  169. package/templates/apps/api/src/lib/proposal-paid-store.ts +0 -66
  170. package/templates/apps/api/src/lib/rate-limit-probe.ts +0 -165
  171. package/templates/apps/api/src/lib/rate-limit-store.ts +0 -142
  172. package/templates/apps/api/src/lib/require-commerce-claim.ts +0 -250
  173. package/templates/apps/api/src/lib/require-paid-tier.ts +0 -53
  174. package/templates/apps/api/src/lib/site.ts +0 -254
  175. package/templates/apps/api/src/lib/slice-load.ts +0 -90
  176. package/templates/apps/api/src/lib/spoke-store.ts +0 -180
  177. package/templates/apps/api/src/lib/stripe.ts +0 -318
  178. package/templates/apps/api/src/lib/webhook-idempotency.ts +0 -156
  179. package/templates/apps/api/src/middleware/__tests__/adversarial/bearer-token-format.test.ts +0 -111
  180. package/templates/apps/api/src/middleware/__tests__/adversarial/cookie-or-bearer-precedence.test.ts +0 -172
  181. package/templates/apps/api/src/middleware/__tests__/adversarial/csrf-bearer-skip.test.ts +0 -119
  182. package/templates/apps/api/src/middleware/__tests__/adversarial/csrf-cookie-path.test.ts +0 -138
  183. package/templates/apps/api/src/middleware/__tests__/adversarial/csrf-trusted-origins.test.ts +0 -142
  184. package/templates/apps/api/src/middleware/__tests__/adversarial/session-fixation.test.ts +0 -155
  185. package/templates/apps/api/src/middleware/__tests__/adversarial/session-timeout.test.ts +0 -139
  186. package/templates/apps/api/src/middleware/__tests__/auth.bearer-path.test.ts +0 -562
  187. package/templates/apps/api/src/middleware/__tests__/auth.both-present-precedence.test.ts +0 -76
  188. package/templates/apps/api/src/middleware/__tests__/auth.cookie-path.test.ts +0 -220
  189. package/templates/apps/api/src/middleware/__tests__/auth.database-not-configured.test.ts +0 -97
  190. package/templates/apps/api/src/middleware/__tests__/auth.hub-session-path.test.ts +0 -557
  191. package/templates/apps/api/src/middleware/__tests__/auth.neither-present.test.ts +0 -72
  192. package/templates/apps/api/src/middleware/__tests__/auth.optional-cookie.test.ts +0 -140
  193. package/templates/apps/api/src/middleware/__tests__/default-tenant.test.ts +0 -721
  194. package/templates/apps/api/src/middleware/__tests__/rate-limit-cross-isolate.db.test.ts +0 -220
  195. package/templates/apps/api/src/middleware/__tests__/rate-limit-store.test.ts +0 -430
  196. package/templates/apps/api/src/middleware/__tests__/rate-limit.test.ts +0 -1409
  197. package/templates/apps/api/src/middleware/__tests__/write-budget.test.ts +0 -174
  198. package/templates/apps/api/src/middleware/auth.ts +0 -864
  199. package/templates/apps/api/src/middleware/default-tenant.ts +0 -166
  200. package/templates/apps/api/src/middleware/rate-limit.ts +0 -983
  201. package/templates/apps/api/src/openapi/__tests__/openapi.test.ts +0 -264
  202. package/templates/apps/api/src/openapi/__tests__/spec-identity.test.ts +0 -182
  203. package/templates/apps/api/src/openapi/index.ts +0 -18
  204. package/templates/apps/api/src/openapi/spec.ts +0 -1815
  205. package/templates/apps/api/src/openapi/surface-drift.ts +0 -195
  206. package/templates/apps/api/src/routes/aeo/__tests__/index.test.ts +0 -175
  207. package/templates/apps/api/src/routes/aeo/index.ts +0 -107
  208. package/templates/apps/api/src/routes/auth/__tests__/auth-tokens.functional.test.ts +0 -196
  209. package/templates/apps/api/src/routes/auth/__tests__/auth-user.functional.test.ts +0 -249
  210. package/templates/apps/api/src/routes/auth/__tests__/hub-sign-in.test.ts +0 -532
  211. package/templates/apps/api/src/routes/auth/__tests__/tokens.test.ts +0 -313
  212. package/templates/apps/api/src/routes/auth/__tests__/transactional-email.test.ts +0 -413
  213. package/templates/apps/api/src/routes/auth/__tests__/user.test.ts +0 -609
  214. package/templates/apps/api/src/routes/auth/hub-sign-in.ts +0 -242
  215. package/templates/apps/api/src/routes/auth/tokens.ts +0 -211
  216. package/templates/apps/api/src/routes/auth/transactional-email.ts +0 -301
  217. package/templates/apps/api/src/routes/auth/user.ts +0 -305
  218. package/templates/apps/api/src/routes/billing/plan-checkout.ts +0 -325
  219. package/templates/apps/api/src/routes/checkout/__tests__/live-key.test.ts +0 -178
  220. package/templates/apps/api/src/routes/checkout/__tests__/offerings-authorization.test.ts +0 -1300
  221. package/templates/apps/api/src/routes/checkout/__tests__/session.test.ts +0 -448
  222. package/templates/apps/api/src/routes/checkout/__tests__/sessions.test.ts +0 -1742
  223. package/templates/apps/api/src/routes/checkout/index.ts +0 -34
  224. package/templates/apps/api/src/routes/checkout/session.ts +0 -171
  225. package/templates/apps/api/src/routes/checkout/sessions.ts +0 -540
  226. package/templates/apps/api/src/routes/consent/__tests__/account.test.ts +0 -386
  227. package/templates/apps/api/src/routes/consent/__tests__/sign-up-rate-limit.test.ts +0 -160
  228. package/templates/apps/api/src/routes/consent/account.ts +0 -268
  229. package/templates/apps/api/src/routes/consent/cookie.ts +0 -90
  230. package/templates/apps/api/src/routes/consent/index.ts +0 -26
  231. package/templates/apps/api/src/routes/consent/unsubscribe.ts +0 -127
  232. package/templates/apps/api/src/routes/content/__tests__/get-page.test.ts +0 -853
  233. package/templates/apps/api/src/routes/content/__tests__/list-pages.test.ts +0 -230
  234. package/templates/apps/api/src/routes/content/__tests__/list-types.test.ts +0 -44
  235. package/templates/apps/api/src/routes/content/__tests__/locale.test.ts +0 -118
  236. package/templates/apps/api/src/routes/content/__tests__/offerings.test.ts +0 -731
  237. package/templates/apps/api/src/routes/content/__tests__/pricing.test.ts +0 -753
  238. package/templates/apps/api/src/routes/content/__tests__/rate-limit.test.ts +0 -51
  239. package/templates/apps/api/src/routes/content/__tests__/search.test.ts +0 -450
  240. package/templates/apps/api/src/routes/content/__tests__/shown-offerings.test.ts +0 -762
  241. package/templates/apps/api/src/routes/content/get-page.ts +0 -268
  242. package/templates/apps/api/src/routes/content/index.ts +0 -49
  243. package/templates/apps/api/src/routes/content/list-pages.ts +0 -95
  244. package/templates/apps/api/src/routes/content/list-types.ts +0 -19
  245. package/templates/apps/api/src/routes/content/offerings.ts +0 -184
  246. package/templates/apps/api/src/routes/content/pricing.ts +0 -176
  247. package/templates/apps/api/src/routes/content/rate-limit.ts +0 -22
  248. package/templates/apps/api/src/routes/content/search.ts +0 -129
  249. package/templates/apps/api/src/routes/content/shown-offerings.ts +0 -229
  250. package/templates/apps/api/src/routes/content/slug.ts +0 -9
  251. package/templates/apps/api/src/routes/leads/__tests__/capture.test.ts +0 -88
  252. package/templates/apps/api/src/routes/leads/__tests__/list.test.ts +0 -171
  253. package/templates/apps/api/src/routes/leads/__tests__/magnet-completion.test.ts +0 -515
  254. package/templates/apps/api/src/routes/leads/__tests__/spoke.test.ts +0 -392
  255. package/templates/apps/api/src/routes/leads/__tests__/track.test.ts +0 -165
  256. package/templates/apps/api/src/routes/leads/index.ts +0 -573
  257. package/templates/apps/api/src/routes/leads/list.ts +0 -104
  258. package/templates/apps/api/src/routes/project-listings/__tests__/configured-application.test.ts +0 -626
  259. package/templates/apps/api/src/routes/project-listings/__tests__/drafts.test.ts +0 -1268
  260. package/templates/apps/api/src/routes/project-listings/__tests__/founder-identity.test.ts +0 -847
  261. package/templates/apps/api/src/routes/project-listings/__tests__/me.test.ts +0 -480
  262. package/templates/apps/api/src/routes/project-listings/__tests__/public.test.ts +0 -465
  263. package/templates/apps/api/src/routes/project-listings/__tests__/resume-email.test.ts +0 -872
  264. package/templates/apps/api/src/routes/project-listings/__tests__/site-answers.test.ts +0 -1022
  265. package/templates/apps/api/src/routes/project-listings/__tests__/site-key.test.ts +0 -484
  266. package/templates/apps/api/src/routes/project-listings/__tests__/structured-address.test.ts +0 -535
  267. package/templates/apps/api/src/routes/project-listings/index.ts +0 -164
  268. package/templates/apps/api/src/routes/project-listings/me.ts +0 -87
  269. package/templates/apps/api/src/routes/project-listings/patch-copy.ts +0 -224
  270. package/templates/apps/api/src/routes/project-listings/patch-draft.ts +0 -102
  271. package/templates/apps/api/src/routes/project-listings/public.ts +0 -98
  272. package/templates/apps/api/src/routes/project-listings/respond.ts +0 -48
  273. package/templates/apps/api/src/routes/project-listings/resume-token.ts +0 -27
  274. package/templates/apps/api/src/routes/project-listings/start.ts +0 -140
  275. package/templates/apps/api/src/routes/project-listings/submit.ts +0 -130
  276. package/templates/apps/api/src/routes/project-listings/verify-email.ts +0 -150
  277. package/templates/apps/api/src/routes/requests/__tests__/confirm.test.ts +0 -686
  278. package/templates/apps/api/src/routes/requests/confirm.ts +0 -601
  279. package/templates/apps/api/src/routes/requests/index.ts +0 -54
  280. package/templates/apps/api/src/routes/test/auth/__tests__/session.test.ts +0 -306
  281. package/templates/apps/api/src/routes/test/auth/session.ts +0 -143
  282. package/templates/apps/api/src/routes/webhooks/README.md +0 -398
  283. package/templates/apps/api/src/routes/webhooks/__tests__/stripe-checkout-consent.test.ts +0 -649
  284. package/templates/apps/api/src/routes/webhooks/__tests__/stripe-dunning.test.ts +0 -749
  285. package/templates/apps/api/src/routes/webhooks/__tests__/stripe-flow-checkout.test.ts +0 -448
  286. package/templates/apps/api/src/routes/webhooks/__tests__/stripe-idempotency.test.ts +0 -264
  287. package/templates/apps/api/src/routes/webhooks/__tests__/stripe-livemode-live.test.ts +0 -159
  288. package/templates/apps/api/src/routes/webhooks/__tests__/stripe-livemode.test.ts +0 -158
  289. package/templates/apps/api/src/routes/webhooks/__tests__/stripe-offerings.test.ts +0 -814
  290. package/templates/apps/api/src/routes/webhooks/__tests__/stripe-org-billing.test.ts +0 -301
  291. package/templates/apps/api/src/routes/webhooks/__tests__/stripe-proposal-paid.test.ts +0 -369
  292. package/templates/apps/api/src/routes/webhooks/__tests__/stripe-rate-limit.test.ts +0 -215
  293. package/templates/apps/api/src/routes/webhooks/__tests__/stripe-request-paid.test.ts +0 -301
  294. package/templates/apps/api/src/routes/webhooks/__tests__/stripe-site-filter.test.ts +0 -808
  295. package/templates/apps/api/src/routes/webhooks/__tests__/stripe.test.ts +0 -1155
  296. package/templates/apps/api/src/routes/webhooks/index.ts +0 -141
  297. package/templates/apps/api/src/routes/webhooks/stripe-offerings.ts +0 -384
  298. package/templates/apps/api/src/routes/webhooks/stripe.ts +0 -2026
  299. package/templates/apps/api/src/services/__tests__/abandon-email.test.ts +0 -528
  300. package/templates/apps/api/src/services/__tests__/answer-distributions.test.ts +0 -132
  301. package/templates/apps/api/src/services/__tests__/audit-log.test.ts +0 -1028
  302. package/templates/apps/api/src/services/__tests__/checkout-plan.test.ts +0 -313
  303. package/templates/apps/api/src/services/__tests__/consent-ledger.test.ts +0 -503
  304. package/templates/apps/api/src/services/__tests__/consent-migration.test.ts +0 -65
  305. package/templates/apps/api/src/services/__tests__/consent.test.ts +0 -299
  306. package/templates/apps/api/src/services/__tests__/default-tenant.test.ts +0 -147
  307. package/templates/apps/api/src/services/__tests__/deliverable-fulfillment.test.ts +0 -867
  308. package/templates/apps/api/src/services/__tests__/deliverable-resend.test.ts +0 -379
  309. package/templates/apps/api/src/services/__tests__/dunning-policy.test.ts +0 -368
  310. package/templates/apps/api/src/services/__tests__/entitlements.test.ts +0 -142
  311. package/templates/apps/api/src/services/__tests__/hub-sign-in.test.ts +0 -854
  312. package/templates/apps/api/src/services/__tests__/keyless-workspace-predicate.test.ts +0 -234
  313. package/templates/apps/api/src/services/__tests__/lead-accept-user.test.ts +0 -251
  314. package/templates/apps/api/src/services/__tests__/lead-routing.test.ts +0 -2660
  315. package/templates/apps/api/src/services/__tests__/listing-config.test.ts +0 -166
  316. package/templates/apps/api/src/services/__tests__/magnet-completion.test.ts +0 -389
  317. package/templates/apps/api/src/services/__tests__/person.test.ts +0 -1176
  318. package/templates/apps/api/src/services/__tests__/plan-offerings.test.ts +0 -444
  319. package/templates/apps/api/src/services/__tests__/project-listings.fence.test.ts +0 -154
  320. package/templates/apps/api/src/services/__tests__/public-site-resolver.test.ts +0 -137
  321. package/templates/apps/api/src/services/__tests__/request-confirm.test.ts +0 -531
  322. package/templates/apps/api/src/services/__tests__/revalidation.test.ts +0 -372
  323. package/templates/apps/api/src/services/__tests__/slack-notify.test.ts +0 -348
  324. package/templates/apps/api/src/services/__tests__/spoke-resolution.test.ts +0 -660
  325. package/templates/apps/api/src/services/__tests__/usage-aggregation.test.ts +0 -941
  326. package/templates/apps/api/src/services/__tests__/usage-credits.test.ts +0 -588
  327. package/templates/apps/api/src/services/__tests__/verified-email.test.ts +0 -78
  328. package/templates/apps/api/src/services/abandon-email.ts +0 -313
  329. package/templates/apps/api/src/services/aeo-score.ts +0 -325
  330. package/templates/apps/api/src/services/answer-distributions.ts +0 -138
  331. package/templates/apps/api/src/services/audit-log.ts +0 -961
  332. package/templates/apps/api/src/services/checkout-buyer.ts +0 -168
  333. package/templates/apps/api/src/services/consent.ts +0 -834
  334. package/templates/apps/api/src/services/default-tenant.ts +0 -416
  335. package/templates/apps/api/src/services/deliverable-fulfillment.ts +0 -755
  336. package/templates/apps/api/src/services/dunning-policy.ts +0 -294
  337. package/templates/apps/api/src/services/enrichment-shim.ts +0 -53
  338. package/templates/apps/api/src/services/entitlements.ts +0 -338
  339. package/templates/apps/api/src/services/hub-sign-in.ts +0 -472
  340. package/templates/apps/api/src/services/lead-accept-user.ts +0 -126
  341. package/templates/apps/api/src/services/lead-promotion.ts +0 -160
  342. package/templates/apps/api/src/services/lead-routing.ts +0 -1372
  343. package/templates/apps/api/src/services/leads-inbox.ts +0 -312
  344. package/templates/apps/api/src/services/listing-config.ts +0 -178
  345. package/templates/apps/api/src/services/magnet-completion.ts +0 -242
  346. package/templates/apps/api/src/services/offerings/__tests__/catalog.test.ts +0 -295
  347. package/templates/apps/api/src/services/offerings/__tests__/checkout-session-record.test.ts +0 -268
  348. package/templates/apps/api/src/services/offerings/__tests__/connection.test.ts +0 -868
  349. package/templates/apps/api/src/services/offerings/__tests__/fixtures.ts +0 -416
  350. package/templates/apps/api/src/services/offerings/__tests__/org-products.test.ts +0 -396
  351. package/templates/apps/api/src/services/offerings/__tests__/readers.test.ts +0 -681
  352. package/templates/apps/api/src/services/offerings/__tests__/source.test.ts +0 -231
  353. package/templates/apps/api/src/services/offerings/catalog.ts +0 -308
  354. package/templates/apps/api/src/services/offerings/checkout-authorization.ts +0 -385
  355. package/templates/apps/api/src/services/offerings/checkout-session-record.ts +0 -192
  356. package/templates/apps/api/src/services/offerings/connection.ts +0 -1003
  357. package/templates/apps/api/src/services/offerings/index.ts +0 -614
  358. package/templates/apps/api/src/services/offerings/source.ts +0 -140
  359. package/templates/apps/api/src/services/offerings/store.ts +0 -150
  360. package/templates/apps/api/src/services/owner-workspaces.ts +0 -132
  361. package/templates/apps/api/src/services/person.ts +0 -1188
  362. package/templates/apps/api/src/services/plan-offerings.ts +0 -125
  363. package/templates/apps/api/src/services/project-listing-resume-email.ts +0 -326
  364. package/templates/apps/api/src/services/project-listings.ts +0 -2073
  365. package/templates/apps/api/src/services/public-site-resolver.ts +0 -396
  366. package/templates/apps/api/src/services/request-confirm.ts +0 -698
  367. package/templates/apps/api/src/services/revalidation.ts +0 -235
  368. package/templates/apps/api/src/services/slack-notify.ts +0 -291
  369. package/templates/apps/api/src/services/usage-aggregation.ts +0 -516
  370. package/templates/apps/api/src/services/usage-credits.ts +0 -340
  371. package/templates/apps/api/src/services/verified-email.ts +0 -71
  372. package/templates/apps/mcp/__tests__/abuse/daily-cap.test.ts +0 -52
  373. package/templates/apps/mcp/__tests__/abuse/email-validator.test.ts +0 -46
  374. package/templates/apps/mcp/__tests__/abuse/guard.test.ts +0 -198
  375. package/templates/apps/mcp/__tests__/abuse/honeypot.test.ts +0 -36
  376. package/templates/apps/mcp/__tests__/abuse/user-agent-deny.test.ts +0 -54
  377. package/templates/apps/mcp/__tests__/aeo-cli-parity.test.ts +0 -116
  378. package/templates/apps/mcp/__tests__/audit-single-page.test.ts +0 -299
  379. package/templates/apps/mcp/__tests__/boot.test.ts +0 -280
  380. package/templates/apps/mcp/__tests__/catalog-drift.test.ts +0 -359
  381. package/templates/apps/mcp/__tests__/config/modules.test.ts +0 -78
  382. package/templates/apps/mcp/__tests__/get_business_hours.test.ts +0 -82
  383. package/templates/apps/mcp/__tests__/get_faq.test.ts +0 -80
  384. package/templates/apps/mcp/__tests__/get_locations.test.ts +0 -65
  385. package/templates/apps/mcp/__tests__/get_offerings.test.ts +0 -557
  386. package/templates/apps/mcp/__tests__/get_pricing.test.ts +0 -524
  387. package/templates/apps/mcp/__tests__/get_site_info.test.ts +0 -81
  388. package/templates/apps/mcp/__tests__/http-transport.test.ts +0 -1151
  389. package/templates/apps/mcp/__tests__/index.test.ts +0 -195
  390. package/templates/apps/mcp/__tests__/lib/audit-single-page-readiness-scan.test.ts +0 -191
  391. package/templates/apps/mcp/__tests__/lib/commerce-claim.test.ts +0 -531
  392. package/templates/apps/mcp/__tests__/lib/content-adapter-parity.test.ts +0 -65
  393. package/templates/apps/mcp/__tests__/lib/content-adapter.test.ts +0 -187
  394. package/templates/apps/mcp/__tests__/lib/content-root.test.ts +0 -93
  395. package/templates/apps/mcp/__tests__/lib/errors.test.ts +0 -75
  396. package/templates/apps/mcp/__tests__/lib/fail-closed-tools.test.ts +0 -165
  397. package/templates/apps/mcp/__tests__/lib/public-workspace.test.ts +0 -124
  398. package/templates/apps/mcp/__tests__/list_pages.test.ts +0 -228
  399. package/templates/apps/mcp/__tests__/locale.test.ts +0 -135
  400. package/templates/apps/mcp/__tests__/module-exclusion.test.ts +0 -175
  401. package/templates/apps/mcp/__tests__/purchase-disabled.test.ts +0 -101
  402. package/templates/apps/mcp/__tests__/read_content.test.ts +0 -474
  403. package/templates/apps/mcp/__tests__/request_callback.test.ts +0 -225
  404. package/templates/apps/mcp/__tests__/search_content.test.ts +0 -256
  405. package/templates/apps/mcp/__tests__/server.test.ts +0 -388
  406. package/templates/apps/mcp/__tests__/start_purchase.test.ts +0 -448
  407. package/templates/apps/mcp/__tests__/submit_lead.test.ts +0 -307
  408. package/templates/apps/mcp/__tests__/subscribe_newsletter.test.ts +0 -223
  409. package/templates/apps/mcp/__tests__/tools/create_project.test.ts +0 -243
  410. package/templates/apps/mcp/__tests__/tools/purchase.test.ts +0 -451
  411. package/templates/apps/mcp/src/abuse/daily-cap.ts +0 -47
  412. package/templates/apps/mcp/src/abuse/email-validator.ts +0 -25
  413. package/templates/apps/mcp/src/abuse/honeypot.ts +0 -21
  414. package/templates/apps/mcp/src/abuse/index.ts +0 -342
  415. package/templates/apps/mcp/src/abuse/user-agent-deny.ts +0 -58
  416. package/templates/apps/mcp/src/boot.ts +0 -167
  417. package/templates/apps/mcp/src/config/modules.ts +0 -43
  418. package/templates/apps/mcp/src/http-transport.ts +0 -526
  419. package/templates/apps/mcp/src/lib/audit-single-page.ts +0 -308
  420. package/templates/apps/mcp/src/lib/commerce-claim.ts +0 -263
  421. package/templates/apps/mcp/src/lib/content-adapter.ts +0 -142
  422. package/templates/apps/mcp/src/lib/empty-content-adapter.ts +0 -139
  423. package/templates/apps/mcp/src/lib/errors.ts +0 -61
  424. package/templates/apps/mcp/src/lib/license-key-store.ts +0 -45
  425. package/templates/apps/mcp/src/lib/locales.ts +0 -171
  426. package/templates/apps/mcp/src/lib/prisma.ts +0 -39
  427. package/templates/apps/mcp/src/lib/public-workspace.ts +0 -133
  428. package/templates/apps/mcp/src/lib/resolve-locale.ts +0 -30
  429. package/templates/apps/mcp/src/lib/shown-offerings.ts +0 -105
  430. package/templates/apps/mcp/src/lib/stripe-tax-signal.ts +0 -59
  431. package/templates/apps/mcp/src/request-context.ts +0 -52
  432. package/templates/apps/mcp/src/server.ts +0 -343
  433. package/templates/apps/mcp/src/serverless-app.ts +0 -88
  434. package/templates/apps/mcp/src/tools/audit.ts +0 -127
  435. package/templates/apps/mcp/src/tools/capture_lead.ts +0 -64
  436. package/templates/apps/mcp/src/tools/create_project.ts +0 -134
  437. package/templates/apps/mcp/src/tools/get_business_hours.ts +0 -68
  438. package/templates/apps/mcp/src/tools/get_faq.ts +0 -71
  439. package/templates/apps/mcp/src/tools/get_locations.ts +0 -88
  440. package/templates/apps/mcp/src/tools/get_offerings.ts +0 -96
  441. package/templates/apps/mcp/src/tools/get_pricing.ts +0 -94
  442. package/templates/apps/mcp/src/tools/get_site_info.ts +0 -86
  443. package/templates/apps/mcp/src/tools/index.ts +0 -137
  444. package/templates/apps/mcp/src/tools/list_pages.ts +0 -74
  445. package/templates/apps/mcp/src/tools/person_notes.ts +0 -25
  446. package/templates/apps/mcp/src/tools/proposals.ts +0 -27
  447. package/templates/apps/mcp/src/tools/purchase.ts +0 -205
  448. package/templates/apps/mcp/src/tools/read_content.ts +0 -75
  449. package/templates/apps/mcp/src/tools/request_callback.ts +0 -59
  450. package/templates/apps/mcp/src/tools/search_content.ts +0 -67
  451. package/templates/apps/mcp/src/tools/subscribe_newsletter.ts +0 -57
  452. package/templates/apps/mcp/src/workspace-server.ts +0 -224
  453. package/templates/database/CHANGELOG.md +0 -961
  454. package/templates/database/LICENSE +0 -202
  455. package/templates/database/NOTICE +0 -2
  456. package/templates/database/README.md +0 -243
  457. package/templates/database/__tests__/agents.db.test.ts +0 -320
  458. package/templates/database/__tests__/appointment.db.test.ts +0 -106
  459. package/templates/database/__tests__/artifact-content-store.db.test.ts +0 -316
  460. package/templates/database/__tests__/composite-fence.db.test.ts +0 -206
  461. package/templates/database/__tests__/consent-ledger.db.test.ts +0 -345
  462. package/templates/database/__tests__/consent-source-checkout-migration.test.ts +0 -79
  463. package/templates/database/__tests__/fence-fan-out.db.test.ts +0 -715
  464. package/templates/database/__tests__/fixtures/appointment-create-probe.ts +0 -79
  465. package/templates/database/__tests__/fixtures/person-backfill.json +0 -264
  466. package/templates/database/__tests__/fixtures/person-contact-backfill.json +0 -182
  467. package/templates/database/__tests__/fixtures/project-listing-consent-probe.ts +0 -100
  468. package/templates/database/__tests__/flow-completion-migration.test.ts +0 -115
  469. package/templates/database/__tests__/flow-completion.db.test.ts +0 -136
  470. package/templates/database/__tests__/flow-workspace-key.db.test.ts +0 -263
  471. package/templates/database/__tests__/flows-listing-diagnostic.test.ts +0 -392
  472. package/templates/database/__tests__/flows-presets.test.ts +0 -173
  473. package/templates/database/__tests__/in-page-magnets-migration.test.ts +0 -161
  474. package/templates/database/__tests__/lead-idempotency-key.db.test.ts +0 -92
  475. package/templates/database/__tests__/member-area.db.test.ts +0 -257
  476. package/templates/database/__tests__/member-contract-migration.test.ts +0 -85
  477. package/templates/database/__tests__/member-contract.db.test.ts +0 -413
  478. package/templates/database/__tests__/offerings-checkout-session.db.test.ts +0 -270
  479. package/templates/database/__tests__/offerings-migration.test.ts +0 -197
  480. package/templates/database/__tests__/offerings-shown-price-ids-migration.test.ts +0 -86
  481. package/templates/database/__tests__/offerings.db.test.ts +0 -303
  482. package/templates/database/__tests__/outbound-message-action.db.test.ts +0 -80
  483. package/templates/database/__tests__/person-contact.db.test.ts +0 -563
  484. package/templates/database/__tests__/person-notes.db.test.ts +0 -249
  485. package/templates/database/__tests__/person.db.test.ts +0 -586
  486. package/templates/database/__tests__/piece-kind-migration.test.ts +0 -67
  487. package/templates/database/__tests__/piece-kind.db.test.ts +0 -208
  488. package/templates/database/__tests__/prefixed-ids.db.test.ts +0 -222
  489. package/templates/database/__tests__/project-listing-consent-at.db.test.ts +0 -111
  490. package/templates/database/__tests__/seed.test.ts +0 -240
  491. package/templates/database/__tests__/spoke-registry.db.test.ts +0 -191
  492. package/templates/database/__tests__/tenancy.test.ts +0 -141
  493. package/templates/database/__tests__/user-cascade.test.ts +0 -140
  494. package/templates/database/_gitignore +0 -8
  495. package/templates/database/auth/.gitkeep +0 -0
  496. package/templates/database/auth/schema.prisma +0 -641
  497. package/templates/database/config/.gitkeep +0 -0
  498. package/templates/database/config/schema.prisma +0 -441
  499. package/templates/database/content/.gitkeep +0 -0
  500. package/templates/database/content/schema.prisma +0 -339
  501. package/templates/database/eslint.config.mjs +0 -69
  502. package/templates/database/flows/listing-diagnostic.ts +0 -182
  503. package/templates/database/flows/presets.ts +0 -315
  504. package/templates/database/inbox/.gitkeep +0 -0
  505. package/templates/database/inbox/README.md +0 -3
  506. package/templates/database/inbox/__tests__/schema.test.ts +0 -44
  507. package/templates/database/inbox/schema.prisma +0 -1447
  508. package/templates/database/jest.config.cjs +0 -36
  509. package/templates/database/migrations/20260508000000_add_inbox_namespace/migration.sql +0 -328
  510. package/templates/database/migrations/20260513000000_better_auth_migration/migration.sql +0 -100
  511. package/templates/database/migrations/20260515000000_add_user_billing_fields/migration.sql +0 -28
  512. package/templates/database/migrations/20260516000000_add_user_tier_care_plan_seat/migration.sql +0 -25
  513. package/templates/database/migrations/20260518000000_add_telemetry_records/migration.sql +0 -42
  514. package/templates/database/migrations/20260525000000_theme_wiring/migration.sql +0 -67
  515. package/templates/database/migrations/20260710000000_retire_commercial_tier/migration.sql +0 -21
  516. package/templates/database/migrations/20260712215647_add_multi_tenant_tenancy/migration.sql +0 -201
  517. package/templates/database/migrations/20260713143320_reanchor_site_config_to_workspace/migration.sql +0 -67
  518. package/templates/database/migrations/20260713174000_add_audit_logs/migration.sql +0 -46
  519. package/templates/database/migrations/20260713190000_drop_telemetry_records/migration.sql +0 -25
  520. package/templates/database/migrations/20260713192000_add_uuidv7_function/migration.sql +0 -49
  521. package/templates/database/migrations/20260713192429_prefixed_uuid_entity_ids/migration.sql +0 -197
  522. package/templates/database/migrations/20260713200000_add_org_billing/migration.sql +0 -32
  523. package/templates/database/migrations/20260714000000_add_lead_promotion_fields/migration.sql +0 -22
  524. package/templates/database/migrations/20260714010000_add_usage_billing_content_models/migration.sql +0 -151
  525. package/templates/database/migrations/20260714020000_add_usage_billing_auth_config_models/migration.sql +0 -223
  526. package/templates/database/migrations/20260714030000_credit_balance_non_negative/migration.sql +0 -22
  527. package/templates/database/migrations/20260714030000_widen_usage_billing_report_aggregates/migration.sql +0 -32
  528. package/templates/database/migrations/20260810233516_add_flow_engine_models/migration.sql +0 -40
  529. package/templates/database/migrations/20260811020000_add_flow_session_abandon_email_columns/migration.sql +0 -4
  530. package/templates/database/migrations/20260811030000_add_flow_session_abandon_email_index/migration.sql +0 -2
  531. package/templates/database/migrations/20260811040000_add_flow_session_segment/migration.sql +0 -2
  532. package/templates/database/migrations/20260811050000_add_deliverable_models/migration.sql +0 -29
  533. package/templates/database/migrations/20260812000000_add_deliverable_grant_send_columns/migration.sql +0 -6
  534. package/templates/database/migrations/20260902222948_add_waitlist_experiment_models/migration.sql +0 -39
  535. package/templates/database/migrations/20260902224500_add_waitlist_id_format_checks/migration.sql +0 -24
  536. package/templates/database/migrations/20260903004112_add_flow_session_flags_aeo_score/migration.sql +0 -3
  537. package/templates/database/migrations/20260903010000_add_playbook_instance/migration.sql +0 -33
  538. package/templates/database/migrations/20260904000000_add_waitlist_followup_send/migration.sql +0 -30
  539. package/templates/database/migrations/20260905230000_add_flow_checkout/migration.sql +0 -47
  540. package/templates/database/migrations/20260906000000_add_flow_checkout_idempotency/migration.sql +0 -16
  541. package/templates/database/migrations/20260907120000_add_project_listing/migration.sql +0 -47
  542. package/templates/database/migrations/20260907130000_add_project_listing_slack_columns/migration.sql +0 -10
  543. package/templates/database/migrations/20260907180000_add_listing_csv_send/migration.sql +0 -26
  544. package/templates/database/migrations/20260909120000_project_listings_platform/migration.sql +0 -90
  545. package/templates/database/migrations/20260909180000_listing_draft_and_fields/migration.sql +0 -174
  546. package/templates/database/migrations/20260910120000_listing_public_site_key/migration.sql +0 -14
  547. package/templates/database/migrations/20260911120000_listing_copy_edit_audit/migration.sql +0 -25
  548. package/templates/database/migrations/20260911140000_listing_structured_address/migration.sql +0 -32
  549. package/templates/database/migrations/20260911180000_consent_grants/migration.sql +0 -71
  550. package/templates/database/migrations/20260911200000_listing_site_answers/migration.sql +0 -30
  551. package/templates/database/migrations/20260912120000_listing_owner_link/migration.sql +0 -49
  552. package/templates/database/migrations/20260914120000_listing_founder_identity/migration.sql +0 -123
  553. package/templates/database/migrations/20260915120000_project_listing_solution/migration.sql +0 -15
  554. package/templates/database/migrations/20260916120000_artifact_content_store/migration.sql +0 -158
  555. package/templates/database/migrations/20260917120000_callback_request_confirm/migration.sql +0 -40
  556. package/templates/database/migrations/20260918120000_add_appointment/migration.sql +0 -67
  557. package/templates/database/migrations/20260918120000_asset_metadata_columns/migration.sql +0 -70
  558. package/templates/database/migrations/20260919120000_flow_workspace_key/migration.sql +0 -181
  559. package/templates/database/migrations/20260919130000_flow_definition_admin_columns/migration.sql +0 -172
  560. package/templates/database/migrations/20260919130000_workspace_meetings/migration.sql +0 -41
  561. package/templates/database/migrations/20260919140000_inbox_workspace_key/migration.sql +0 -185
  562. package/templates/database/migrations/20260920120000_lead_handled_at/migration.sql +0 -70
  563. package/templates/database/migrations/20260920130000_lead_workspace_source_index/migration.sql +0 -57
  564. package/templates/database/migrations/20260921120000_deliverable_grant_workspace_key/migration.sql +0 -68
  565. package/templates/database/migrations/20260922120000_tenancy_fence/migration.sql +0 -1067
  566. package/templates/database/migrations/20260923120000_listing_capturing_magnet/migration.sql +0 -210
  567. package/templates/database/migrations/20261003120000_spoke_registry/migration.sql +0 -80
  568. package/templates/database/migrations/20261003130000_scheduling_connection/migration.sql +0 -49
  569. package/templates/database/migrations/20261005120000_agents/migration.sql +0 -84
  570. package/templates/database/migrations/20261008120000_user_last_workspace/migration.sql +0 -35
  571. package/templates/database/migrations/20261008130000_lead_idempotency_key/migration.sql +0 -20
  572. package/templates/database/migrations/20261009120000_agent_grants/migration.sql +0 -33
  573. package/templates/database/migrations/20261010120000_person/migration.sql +0 -106
  574. package/templates/database/migrations/20261010121000_person_backfill/migration.sql +0 -132
  575. package/templates/database/migrations/20261010130000_agent_grants_people_read/migration.sql +0 -20
  576. package/templates/database/migrations/20261011120000_member_area/migration.sql +0 -158
  577. package/templates/database/migrations/20261011130000_agent_grants_member_pieces_manage/migration.sql +0 -21
  578. package/templates/database/migrations/20261012120000_member_contract/migration.sql +0 -192
  579. package/templates/database/migrations/20261013120000_lead_spoke_checkout/migration.sql +0 -20
  580. package/templates/database/migrations/20261014120000_consent_ledger/migration.sql +0 -122
  581. package/templates/database/migrations/20261014120000_person_contact/migration.sql +0 -231
  582. package/templates/database/migrations/20261015120000_person_notes/migration.sql +0 -77
  583. package/templates/database/migrations/20261015120000_rate_limit_counters/migration.sql +0 -43
  584. package/templates/database/migrations/20261016120000_piece_kind/migration.sql +0 -95
  585. package/templates/database/migrations/20261017120000_outbound_message_action/migration.sql +0 -30
  586. package/templates/database/migrations/20261018120000_flow_completion/migration.sql +0 -52
  587. package/templates/database/migrations/20261019120000_consent_source_checkout/migration.sql +0 -27
  588. package/templates/database/migrations/20261020120000_offerings_data_model/migration.sql +0 -146
  589. package/templates/database/migrations/20261021120000_offerings_checkout_session/migration.sql +0 -77
  590. package/templates/database/migrations/20261022120000_in_page_magnets/migration.sql +0 -45
  591. package/templates/database/migrations/20261023120000_offerings_shown_price_ids/migration.sql +0 -47
  592. package/templates/database/migrations/20261024120000_organization_plan_checkout_session/migration.sql +0 -16
  593. package/templates/database/migrations/migration_lock.toml +0 -3
  594. package/templates/database/ops/.gitkeep +0 -0
  595. package/templates/database/ops/schema.prisma +0 -43
  596. package/templates/database/package.json +0 -89
  597. package/templates/database/schema.prisma +0 -71
  598. package/templates/database/scripts/db-generate-locked.sh +0 -80
  599. package/templates/database/scripts/person-backfill.sql +0 -132
  600. package/templates/database/tenancy.ts +0 -183
  601. package/templates/database/tsconfig.build.json +0 -16
  602. package/templates/database/tsconfig.flows.json +0 -15
  603. package/templates/database/tsconfig.json +0 -16
  604. package/templates/database/tsconfig.tenancy.json +0 -14
@@ -1,1028 +0,0 @@
1
- /**
2
- * @file audit-log.test.ts
3
- * @description Unit tests for the audit writer (#6040, REL-017 row 5 /
4
- * FEAT-084 SUB-096), scored against docs/specs/6040-one-auditlog-row-per-agent-spec.md §5.1,
5
- * and its actor-and-domain reshape (#3591 D8,
6
- * docs/specs/3591-tenant-scoped-agent-auth-secure-spec.md).
7
- *
8
- * External dependency boundaries mocked:
9
- * - apps/api/src/lib/prisma — the repo-standard `__mocks__/prisma.ts`
10
- * manual mock (`jest.mock("../../lib/prisma.js")`). Not read directly by
11
- * any case below — `recordAuditAction`'s injectable `AuditWriteClient`
12
- * (D1) means every case supplies its own stub delegate — this mock is
13
- * kept only so importing `audit-log.ts` never constructs a real
14
- * `PrismaPg` adapter (the repo-standard reason every sibling service
15
- * test carries this line regardless of whether it touches `prisma`
16
- * directly).
17
- * - @working-theory/observability `logger` — a partial mock (`...actual`
18
- * plus an overridden `logger`) so `redactHighEntropy` and `sanitizePII`
19
- * still run for real (AC-2 case 5 pins the real `sanitizePII`'s
20
- * behaviour) while `logger.error` / `logger.warn` are observable.
21
- */
22
-
23
- // eslint-disable-next-line no-restricted-syntax -- lib/prisma.ts wraps the external DB boundary (PrismaClient requires a live connection); __mocks__/prisma.ts is the repo-standard test double for this boundary.
24
- jest.mock("../../lib/prisma.js");
25
-
26
- const mockLoggerError = jest.fn();
27
- const mockLoggerWarn = jest.fn();
28
- jest.mock("@working-theory/observability", () => {
29
- const actual = jest.requireActual("@working-theory/observability");
30
- return {
31
- ...actual,
32
- logger: {
33
- info: jest.fn(),
34
- debug: jest.fn(),
35
- warn: (...args: unknown[]) => mockLoggerWarn(...args),
36
- error: (...args: unknown[]) => mockLoggerError(...args),
37
- },
38
- };
39
- });
40
-
41
- import { readFileSync } from "node:fs";
42
- import { join } from "node:path";
43
-
44
- import { zAuditLogId, zWorkspaceId, type Id } from "@working-theory/ids";
45
- import { sanitizePII } from "@working-theory/observability";
46
-
47
- import type { TenantContext } from "../default-tenant.js";
48
- import {
49
- auditActorFor,
50
- deriveAuditRowId,
51
- freshAuditIdempotencyKey,
52
- recordAgentWrite,
53
- recordAuditAction,
54
- recordWorkspaceAuditAction,
55
- redactPersonalData,
56
- type AuditActor,
57
- type AuditRowDigestInput,
58
- type AuditWriteClient,
59
- type RecordAuditActionInput,
60
- } from "../audit-log.js";
61
-
62
- // ─── Fixtures ───────────────────────────────────────────────────────────────
63
-
64
- // v7-shaped, RFC-4122-variant uuids — each satisfies the same
65
- // `[0-9a-f]{8}-[0-9a-f]{4}-7[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}` CHECK
66
- // grammar `zWorkspaceId` / `zAuditLogId` enforce.
67
- const WORKSPACE_ID = "wksp_0190f3a2-7c1d-7e4a-9b2c-000000000001";
68
- const ORG_ID = "org_0190f3a2-7c1d-7e4a-9b2c-000000000002";
69
- const USER_ID = "user_0190f3a2-7c1d-7e4a-9b2c-000000000003";
70
-
71
- const TENANT: TenantContext = {
72
- userId: USER_ID as Id<"user">,
73
- organizationId: ORG_ID as Id<"organization">,
74
- workspaceId: WORKSPACE_ID as Id<"workspace">,
75
- role: "owner",
76
- };
77
-
78
- /** An agent actor with the given id, acting for `USER_ID`. */
79
- function agentActor(agentId: string): AuditActor {
80
- return {
81
- type: "agent",
82
- agentId: agentId as Id<"agent">,
83
- onBehalfOfUserId: USER_ID as Id<"user">,
84
- };
85
- }
86
-
87
- /** A person actor with the given id. */
88
- function userActor(userId: string): AuditActor {
89
- return { type: "user", userId: userId as Id<"user"> };
90
- }
91
-
92
- const BASE_INPUT: RecordAuditActionInput = {
93
- tenant: TENANT,
94
- actor: agentActor("agent_abc123"),
95
- domain: "commerce",
96
- tool: "refund",
97
- outcome: "succeeded",
98
- idempotencyKey: "req_abc123",
99
- };
100
-
101
- /** A resolved row's `data` argument, as `AuditWriteClient.auditLog.create`
102
- * would have received it — loosely typed here since the test asserts on
103
- * individual fields rather than importing the module-private row shape. */
104
- interface WrittenRow {
105
- id: string;
106
- workspaceId: string;
107
- actorId: string;
108
- actorType: string;
109
- action: string;
110
- targetType?: string;
111
- targetId?: string;
112
- metadata: Record<string, unknown>;
113
- }
114
-
115
- function stubDb(
116
- create: jest.Mock = jest.fn().mockResolvedValue({ id: "ignored" }),
117
- ): {
118
- db: AuditWriteClient;
119
- create: jest.Mock;
120
- } {
121
- return { db: { auditLog: { create } }, create };
122
- }
123
-
124
- function firstWrittenRow(create: jest.Mock): WrittenRow {
125
- return (create.mock.calls[0]![0] as { data: WrittenRow }).data;
126
- }
127
-
128
- beforeEach(() => {
129
- mockLoggerError.mockClear();
130
- mockLoggerWarn.mockClear();
131
- });
132
-
133
- // ─── AC-1 — exactly one row, carrying the five facts ───────────────────────
134
-
135
- describe("AC-1 — exactly one row, carrying the five facts", () => {
136
- it("calls create exactly once for one recordAuditAction call", async () => {
137
- const { db, create } = stubDb();
138
- await recordAuditAction(BASE_INPUT, db);
139
- expect(create).toHaveBeenCalledTimes(1);
140
- });
141
-
142
- it("writes workspaceId from the resolved tenant, satisfying zWorkspaceId", async () => {
143
- const { db, create } = stubDb();
144
- await recordAuditAction(BASE_INPUT, db);
145
- const row = firstWrittenRow(create);
146
- expect(row.workspaceId).toBe(TENANT.workspaceId);
147
- expect(zWorkspaceId.safeParse(row.workspaceId).success).toBe(true);
148
- });
149
-
150
- it("writes an agent actor as actorType 'agent', actorId the agent's id, and metadata.onBehalfOf its person (#3591 D8)", async () => {
151
- const { db, create } = stubDb();
152
- await recordAuditAction({ ...BASE_INPUT, outcome: "refused" }, db);
153
- const row = firstWrittenRow(create);
154
- expect(row.actorType).toBe("agent");
155
- expect(row.actorId).toBe("agent_abc123");
156
- expect(row.metadata.onBehalfOf).toBe(USER_ID);
157
- });
158
-
159
- it("writes a person actor as actorType 'user', actorId their user id, and no onBehalfOf (#3591 D8)", async () => {
160
- const { db, create } = stubDb();
161
- await recordAuditAction({ ...BASE_INPUT, actor: userActor(USER_ID) }, db);
162
- const row = firstWrittenRow(create);
163
- expect(row.actorType).toBe("user");
164
- expect(row.actorId).toBe(USER_ID);
165
- expect(row.metadata).not.toHaveProperty("onBehalfOf");
166
- });
167
-
168
- it("writes action as domain + '.' + tool — never the retired 'agent.commerce.' prefix (#3591 D8)", async () => {
169
- const { db, create } = stubDb();
170
- await recordAuditAction({ ...BASE_INPUT, domain: "inbox", tool: "accept_message" }, db);
171
- const row = firstWrittenRow(create);
172
- expect(row.action).toBe("inbox.accept_message");
173
- expect(row.action).not.toMatch(/^agent\.commerce\./);
174
- });
175
-
176
- it("writes metadata at v: 2 (#3591 D8)", async () => {
177
- const { db, create } = stubDb();
178
- await recordAuditAction(BASE_INPUT, db);
179
- expect(firstWrittenRow(create).metadata.v).toBe(2);
180
- });
181
-
182
- it.each(["", "Inbox", "in box", "inbox.accept", "a".repeat(33)])(
183
- "refuses a domain outside the identifier grammar (%j)",
184
- async (domain) => {
185
- const { db, create } = stubDb();
186
- const result = await recordAuditAction({ ...BASE_INPUT, domain }, db);
187
- expect(result.ok).toBe(false);
188
- expect(create).not.toHaveBeenCalled();
189
- },
190
- );
191
-
192
- it.each([
193
- "succeeded",
194
- "failed",
195
- "refused",
196
- "awaiting_approval",
197
- ] satisfies RecordAuditActionInput["outcome"][])(
198
- "writes metadata.outcome = %s for every AuditActionOutcome member",
199
- async (outcome) => {
200
- const { db, create } = stubDb();
201
- await recordAuditAction({ ...BASE_INPUT, outcome }, db);
202
- const row = firstWrittenRow(create);
203
- expect(row.metadata.outcome).toBe(outcome);
204
- },
205
- );
206
-
207
- it("omits createdAt so the database clock supplies it — an agent cannot backdate its own row", async () => {
208
- const { db, create } = stubDb();
209
- await recordAuditAction(BASE_INPUT, db);
210
- const row = firstWrittenRow(create) as WrittenRow & { createdAt?: unknown };
211
- expect(row.createdAt).toBeUndefined();
212
- });
213
-
214
- it("writes an id satisfying zAuditLogId and the migration's literal CHECK regex", async () => {
215
- const { db, create } = stubDb();
216
- await recordAuditAction(BASE_INPUT, db);
217
- const row = firstWrittenRow(create);
218
- // database/migrations/20260713192429_prefixed_uuid_entity_ids/migration.sql:158
219
- expect(row.id).toMatch(
220
- /^audit_[0-9a-f]{8}-[0-9a-f]{4}-7[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/,
221
- );
222
- expect(zAuditLogId.safeParse(row.id).success).toBe(true);
223
- });
224
- });
225
-
226
- // ─── AC-2 — personal data never reaches the stored row in clear form ───────
227
-
228
- describe("AC-2 — personal data never reaches the stored row in clear form", () => {
229
- it("redacts an email and phone number from summary/failureReason on the serialized row", async () => {
230
- const { db, create } = stubDb();
231
- await recordAuditAction(
232
- {
233
- ...BASE_INPUT,
234
- outcome: "failed",
235
- summary: "refunded buyer jane.doe@example.com, phone +1 415 555 0134",
236
- failureReason: "declined for jane.doe@example.com",
237
- },
238
- db,
239
- );
240
- const row = firstWrittenRow(create);
241
- const serialized = JSON.stringify(row);
242
- expect(serialized).not.toContain("jane.doe@example.com");
243
- expect(serialized).not.toContain("555 0134");
244
- expect(serialized).toContain("[REDACTED:email]");
245
- });
246
-
247
- it("folds a full-width @ via NFKC so an email survives a unicode homoglyph domain", async () => {
248
- const { db, create } = stubDb();
249
- const fullWidthAt = "@";
250
- const cyrillicA = "а"; // homoglyph for latin "a" — NOT folded by NFKC
251
- const summary = `contact jane.doe${fullWidthAt}ex${cyrillicA}mple.com`;
252
- await recordAuditAction({ ...BASE_INPUT, summary }, db);
253
- const row = firstWrittenRow(create);
254
- const serialized = JSON.stringify(row);
255
- expect(serialized).not.toContain(summary);
256
- expect(serialized).toContain("[REDACTED:email]");
257
- });
258
-
259
- it.each([
260
- ["tool", { tool: "refund_jane.doe@example.com" }],
261
- ["targetType", { targetType: "jane@example.com" }],
262
- ["targetId", { targetId: "jane@example.com" }],
263
- ["actorId", { actor: agentActor("agent jane@example.com") }],
264
- ["onBehalfOf", { actor: { ...agentActor("agent_abc123"), onBehalfOfUserId: "jane@example.com" as Id<"user"> } }],
265
- ] as [string, Partial<RecordAuditActionInput>][])(
266
- "refuses a personal-data-shaped %s rather than writing it verbatim",
267
- async (_name, override) => {
268
- const { db, create } = stubDb();
269
- const result = await recordAuditAction(
270
- { ...BASE_INPUT, ...override },
271
- db,
272
- );
273
- expect(result).toEqual({
274
- ok: false,
275
- error: {
276
- kind: "invalid_input",
277
- message: expect.any(String),
278
- persisted: false,
279
- },
280
- });
281
- expect(create).not.toHaveBeenCalled();
282
- },
283
- );
284
-
285
- it.each([
286
- ["summary", { summary: "a".repeat(2001) }],
287
- ["failureReason", { failureReason: "a".repeat(2001) }],
288
- ] as [string, Partial<RecordAuditActionInput>][])(
289
- "refuses a %s over the 2000-character cap rather than truncating it",
290
- async (_name, override) => {
291
- const { db, create } = stubDb();
292
- const result = await recordAuditAction(
293
- { ...BASE_INPUT, ...override },
294
- db,
295
- );
296
- expect(result.ok).toBe(false);
297
- if (!result.ok) expect(result.error.kind).toBe("invalid_input");
298
- expect(create).not.toHaveBeenCalled();
299
- },
300
- );
301
-
302
- it("refuses an idempotencyKey outside the required identifier grammar (a space)", async () => {
303
- const { db, create } = stubDb();
304
- const result = await recordAuditAction(
305
- { ...BASE_INPUT, idempotencyKey: "req 1" },
306
- db,
307
- );
308
- expect(result.ok).toBe(false);
309
- expect(create).not.toHaveBeenCalled();
310
- });
311
-
312
- it.each([
313
- ["actorId", { actor: userActor("4155550134") }],
314
- ["onBehalfOf", { actor: { ...agentActor("agent_abc123"), onBehalfOfUserId: "4155550134" as Id<"user"> } }],
315
- ["idempotencyKey", { idempotencyKey: "4155550134" }],
316
- ] as [string, Partial<RecordAuditActionInput>][])(
317
- "refuses a charset-valid but personal-data-shaped %s (a bare digit run) rather than silently rewriting an identifier",
318
- async (_name, override) => {
319
- const { db, create } = stubDb();
320
- const result = await recordAuditAction(
321
- { ...BASE_INPUT, ...override },
322
- db,
323
- );
324
- expect(result.ok).toBe(false);
325
- expect(create).not.toHaveBeenCalled();
326
- },
327
- );
328
-
329
- it.each([
330
- ["tool", { tool: "refund" }],
331
- ["summary", { summary: "notehere" }],
332
- ] as [string, Partial<RecordAuditActionInput>][])(
333
- "refuses a %s containing a NUL character — a reliable audit-disable switch if it reached Postgres",
334
- async (_name, override) => {
335
- const { db, create } = stubDb();
336
- const result = await recordAuditAction(
337
- { ...BASE_INPUT, ...override },
338
- db,
339
- );
340
- expect(result.ok).toBe(false);
341
- expect(create).not.toHaveBeenCalled();
342
- },
343
- );
344
-
345
- it("never stores a hash or pseudonym of the redacted value", async () => {
346
- const { db, create } = stubDb();
347
- await recordAuditAction(
348
- { ...BASE_INPUT, summary: "contact jane.doe@example.com" },
349
- db,
350
- );
351
- const row = firstWrittenRow(create);
352
- expect(JSON.stringify(row)).not.toMatch(/[0-9a-f]{32,}/);
353
- });
354
-
355
- it("writes exactly the allow-listed metadata keys on the success path", async () => {
356
- const { db, create } = stubDb();
357
- await recordAuditAction({ ...BASE_INPUT, summary: "ok" }, db);
358
- const row = firstWrittenRow(create);
359
- expect(Object.keys(row.metadata).sort()).toEqual(
360
- ["idempotencyKey", "onBehalfOf", "outcome", "summary", "tool", "v"].sort(),
361
- );
362
- });
363
-
364
- it("adds failureReason to the allow-listed metadata keys on the failure path", async () => {
365
- const { db, create } = stubDb();
366
- await recordAuditAction(
367
- { ...BASE_INPUT, outcome: "failed", failureReason: "declined" },
368
- db,
369
- );
370
- const row = firstWrittenRow(create);
371
- expect(Object.keys(row.metadata).sort()).toEqual(
372
- ["failureReason", "idempotencyKey", "onBehalfOf", "outcome", "tool", "v"].sort(),
373
- );
374
- });
375
-
376
- it("declares no member whose purpose is a buyer's identity", () => {
377
- void recordAuditAction({
378
- ...BASE_INPUT,
379
- // @ts-expect-error — `buyerEmail` is not a declared member of
380
- // RecordAuditActionInput (D5(a), D11). This proves the member is
381
- // UNDECLARED, not that no declared member can carry personal data —
382
- // `summary` can (D5 concedes this; § 9 SEC-12).
383
- buyerEmail: "buyer@example.com",
384
- });
385
- });
386
-
387
- it("pins the tree's sanitizePII helper NOT redacting an email — a canary on a module this writer does not use", () => {
388
- expect(sanitizePII({ email: "jane@example.com" }).email).toBe(
389
- "jane@example.com",
390
- );
391
- });
392
- });
393
-
394
- // ─── AC-3 — a write failure is surfaced, and the block decision is explicit ─
395
-
396
- describe("AC-3 — a write failure is surfaced, and the block decision is explicit in the code", () => {
397
- it("resolves with ok:false rather than throwing on a write failure", async () => {
398
- const { db } = stubDb(jest.fn().mockRejectedValue(new Error("boom")));
399
- const result = await recordAuditAction(BASE_INPUT, db);
400
- expect(result).toEqual({
401
- ok: false,
402
- error: {
403
- kind: "write_failed",
404
- message: expect.any(String),
405
- persisted: false,
406
- },
407
- });
408
- });
409
-
410
- it("never returns or logs the raw error message — Prisma's data argument IS the audit row", async () => {
411
- const sentinel = "SENTINEL-jane.doe@example.com";
412
- const { db } = stubDb(jest.fn().mockRejectedValue(new Error(sentinel)));
413
- const result = await recordAuditAction(BASE_INPUT, db);
414
- expect(result.ok).toBe(false);
415
- if (!result.ok) expect(result.error.message).not.toContain(sentinel);
416
- expect(JSON.stringify(mockLoggerError.mock.calls[0])).not.toContain(
417
- sentinel,
418
- );
419
- });
420
-
421
- it("logs exactly once at error, with a code but no personal data", async () => {
422
- const { db } = stubDb(jest.fn().mockRejectedValue({ code: "P2025" }));
423
- await recordAuditAction(
424
- { ...BASE_INPUT, summary: "contact jane.doe@example.com" },
425
- db,
426
- );
427
- expect(mockLoggerError).toHaveBeenCalledTimes(1);
428
- const fields = mockLoggerError.mock.calls[0]![0] as Record<string, unknown>;
429
- expect(fields.errorCode).toBe("P2025");
430
- expect(JSON.stringify(fields)).not.toContain("jane.doe@example.com");
431
- });
432
-
433
- it("states the no-block decision as source text under a named docblock heading", () => {
434
- const source = readFileSync(join(__dirname, "../audit-log.ts"), "utf8");
435
- expect(source).toContain("AUDIT FAILURE DOES NOT BLOCK THE AUDITED ACTION");
436
- expect(source).toContain("never aborts the caller's action");
437
- });
438
- });
439
-
440
- // ─── AC-4 — a replay produces no duplicate row ─────────────────────────────
441
-
442
- describe("AC-4 — a replay produces no duplicate row", () => {
443
- const DIGEST_BASE: AuditRowDigestInput = {
444
- workspaceId: TENANT.workspaceId,
445
- actorId: "agent_abc123",
446
- actorType: "agent",
447
- onBehalfOf: USER_ID,
448
- action: "commerce.refund",
449
- targetType: "lead",
450
- targetId: "lead_xyz",
451
- outcome: "succeeded",
452
- summary: "ok",
453
- failureReason: "n-a",
454
- idempotencyKey: "req_1",
455
- };
456
-
457
- it("is deterministic for identical whole-row input", () => {
458
- expect(deriveAuditRowId(DIGEST_BASE)).toBe(
459
- deriveAuditRowId({ ...DIGEST_BASE }),
460
- );
461
- });
462
-
463
- it.each(Object.keys(DIGEST_BASE))(
464
- "changes the id when %s changes, holding every other field fixed",
465
- (field) => {
466
- const before = deriveAuditRowId(DIGEST_BASE);
467
- // eslint-disable-next-line no-restricted-syntax -- generic field-flip over every AuditRowDigestInput key (incl. the AuditActorType/AgentActionOutcome unions), read purely as a string for the mutation; the digest function itself only ever sees valid AuditRowDigestInput values in production.
468
- const baseAsStrings = DIGEST_BASE as unknown as Record<string, string>;
469
- const changed = {
470
- ...DIGEST_BASE,
471
- [field]: `${baseAsStrings[field]}-x`,
472
- } as AuditRowDigestInput;
473
- expect(deriveAuditRowId(changed)).not.toBe(before);
474
- },
475
- );
476
-
477
- it("resists boundary forgery from the length-prefixed encoding (§9 SEC-10)", () => {
478
- // Shifting content across the action/idempotencyKey boundary must not
479
- // collide — a separator-concatenation implementation would produce the
480
- // same byte string ("a.b" + "k" === "a" + ".b.k"-shaped) for both.
481
- const a = deriveAuditRowId({
482
- ...DIGEST_BASE,
483
- action: "a.b",
484
- idempotencyKey: "k",
485
- });
486
- const b = deriveAuditRowId({
487
- ...DIGEST_BASE,
488
- action: "a",
489
- idempotencyKey: "b.k",
490
- });
491
- expect(a).not.toBe(b);
492
- });
493
-
494
- it("does not let a byte-identical decoy suppress the real action's record (the suppression attack, §9 SEC-01)", async () => {
495
- const { db, create } = stubDb();
496
- const shared = {
497
- ...BASE_INPUT,
498
- tool: "refund",
499
- idempotencyKey: "req_shared",
500
- };
501
- const first = await recordAuditAction(
502
- { ...shared, outcome: "refused", summary: "decoy" },
503
- db,
504
- );
505
- const second = await recordAuditAction(
506
- { ...shared, outcome: "succeeded", summary: "real refund" },
507
- db,
508
- );
509
- expect(create).toHaveBeenCalledTimes(2);
510
- expect(first).toEqual({
511
- ok: true,
512
- outcome: "recorded",
513
- id: expect.any(String),
514
- });
515
- expect(second).toEqual({
516
- ok: true,
517
- outcome: "recorded",
518
- id: expect.any(String),
519
- });
520
- if (first.ok && second.ok) {
521
- expect(first.id).not.toBe(second.id);
522
- }
523
- });
524
-
525
- it("reports a replay as duplicate — ok:true, and NOT 'recorded'", async () => {
526
- const create = jest
527
- .fn()
528
- .mockResolvedValueOnce({ id: "ignored" })
529
- .mockRejectedValueOnce({ code: "P2002" });
530
- const { db } = stubDb(create);
531
- const first = await recordAuditAction(BASE_INPUT, db);
532
- const second = await recordAuditAction(BASE_INPUT, db);
533
- expect(first).toEqual({
534
- ok: true,
535
- outcome: "recorded",
536
- id: expect.any(String),
537
- });
538
- expect(second).toEqual({
539
- ok: true,
540
- outcome: "duplicate",
541
- id: expect.any(String),
542
- });
543
- expect(mockLoggerWarn).toHaveBeenCalledTimes(1);
544
- });
545
-
546
- it("refuses a digit-heavy dashed uuid as an idempotencyKey — the personal-data scan reads it as a phone number, so a caller must re-spell its entropy (#6231)", async () => {
547
- const { db, create } = stubDb();
548
- const result = await recordAuditAction(
549
- { ...BASE_INPUT, idempotencyKey: "01234567-8901-4234-8567-890123456789" },
550
- db,
551
- );
552
- expect(result).toEqual({
553
- ok: false,
554
- error: {
555
- kind: "invalid_input",
556
- message: expect.stringContaining("personal data"),
557
- persisted: false,
558
- },
559
- });
560
- // A refusal writes NO row — an unaudited action, the failure mode the
561
- // magnet routes' `_`-grouped key exists to avoid.
562
- expect(create).not.toHaveBeenCalled();
563
- });
564
-
565
- it("logs the duplicate outcome at warn, naming the colliding row — a collision is never silent regardless of caller (#6231)", async () => {
566
- const { db } = stubDb(jest.fn().mockRejectedValue({ code: "P2002" }));
567
- const result = await recordAuditAction(BASE_INPUT, db);
568
- expect(result).toEqual({
569
- ok: true,
570
- outcome: "duplicate",
571
- id: expect.any(String),
572
- });
573
- const collidingId = result.ok ? result.id : undefined;
574
- expect(mockLoggerError).not.toHaveBeenCalled();
575
- expect(mockLoggerWarn).toHaveBeenCalledTimes(1);
576
- const [payload, message] = mockLoggerWarn.mock.calls[0] as [
577
- Record<string, unknown>,
578
- string,
579
- ];
580
- expect(payload).toMatchObject({
581
- workspaceId: WORKSPACE_ID,
582
- auditLogId: collidingId,
583
- });
584
- expect(message).toMatch(/duplicate/i);
585
- });
586
-
587
- it("never reads before writing — no find*/update/delete on the delegate (a narrow claim; §6.2's manual psql insert is the real evidence)", () => {
588
- const source = readFileSync(join(__dirname, "../audit-log.ts"), "utf8");
589
- expect(source).not.toMatch(/auditLog\.(find|update|delete|count)/);
590
- });
591
-
592
- it("classifies a non-P2002 rejection as write_failed, never as duplicate", async () => {
593
- const { db } = stubDb(jest.fn().mockRejectedValue({ code: "P2025" }));
594
- const result = await recordAuditAction(BASE_INPUT, db);
595
- expect(result).toEqual({
596
- ok: false,
597
- error: {
598
- kind: "write_failed",
599
- message: expect.any(String),
600
- persisted: false,
601
- },
602
- });
603
- });
604
- });
605
-
606
- // ─── Supplementary — targetType/targetId pass-through (§3 D3, D5(a2)) ──────
607
-
608
- describe("targetType/targetId pass-through", () => {
609
- it("validates targetId against its named entity's own id grammar when targetType names a registered entity", async () => {
610
- const { db, create } = stubDb();
611
- const result = await recordAuditAction(
612
- { ...BASE_INPUT, targetType: "workspace", targetId: TENANT.workspaceId },
613
- db,
614
- );
615
- expect(result.ok).toBe(true);
616
- const row = firstWrittenRow(create);
617
- expect(row.targetType).toBe("workspace");
618
- expect(row.targetId).toBe(TENANT.workspaceId);
619
- });
620
-
621
- it("refuses a targetId that does not match its named entity's id grammar", async () => {
622
- const { db, create } = stubDb();
623
- const result = await recordAuditAction(
624
- {
625
- ...BASE_INPUT,
626
- targetType: "workspace",
627
- targetId: "not-a-workspace-id",
628
- },
629
- db,
630
- );
631
- expect(result.ok).toBe(false);
632
- expect(create).not.toHaveBeenCalled();
633
- });
634
-
635
- it("refuses a malformed tenant.workspaceId", async () => {
636
- const { db, create } = stubDb();
637
- const result = await recordAuditAction(
638
- {
639
- ...BASE_INPUT,
640
- tenant: {
641
- ...TENANT,
642
- workspaceId: "not-a-workspace-id" as Id<"workspace">,
643
- },
644
- },
645
- db,
646
- );
647
- expect(result.ok).toBe(false);
648
- expect(create).not.toHaveBeenCalled();
649
- });
650
- });
651
-
652
- // ─── redactPersonalData — the exported pure helper, directly ───────────────
653
-
654
- describe("redactPersonalData (exported pure helper)", () => {
655
- it("returns the input unchanged when it carries no personal-data-shaped substring", () => {
656
- expect(redactPersonalData("nothing to see here")).toBe(
657
- "nothing to see here",
658
- );
659
- });
660
-
661
- it("redacts a long digit run (account/card-shaped) not caught by the phone pattern", () => {
662
- expect(redactPersonalData("card 411111111111111")).toContain(
663
- "[REDACTED:number]",
664
- );
665
- });
666
- });
667
-
668
- // ─── #7636 D7, #3591 D8 — a registry user or agent id is never "personal data"
669
-
670
- describe("actor ids — a well-formed user or agent id (#7636 D7, #3591 D8)", () => {
671
- // Real DB-minted shapes whose hex happens to contain a long digit run: the
672
- // phone pattern reads `-` as a digit separator, so the bare scan flagged
673
- // about a third of real ids and dropped their audit rows.
674
- const DIGIT_HEAVY_USER = "user_01a1081d-15ec-7fcf-a280-4cb63886627f";
675
- const DIGIT_HEAVY_SPEC_USER = "user_01923456-7890-7abc-8def-0123456789ab";
676
- const DIGIT_HEAVY_AGENT = "agent_01923456-7890-7abc-8def-0123456789ab";
677
-
678
- it("writes the row for a digit-heavy user_<uuidv7> actor", async () => {
679
- const { db, create } = stubDb();
680
- const result = await recordAuditAction({ ...BASE_INPUT, actor: userActor(DIGIT_HEAVY_USER) }, db);
681
- expect(result.ok).toBe(true);
682
- expect(firstWrittenRow(create).actorId).toBe(DIGIT_HEAVY_USER);
683
- });
684
-
685
- it("the ids really are phone-shaped to the scan — the exemption, not the id, is what admits them", () => {
686
- for (const id of [DIGIT_HEAVY_SPEC_USER, DIGIT_HEAVY_AGENT]) {
687
- expect(redactPersonalData(id)).toContain("[REDACTED:");
688
- }
689
- });
690
-
691
- it("records a digit-heavy user id as a person actor", async () => {
692
- const { db, create } = stubDb();
693
- const result = await recordAuditAction({ ...BASE_INPUT, actor: userActor(DIGIT_HEAVY_SPEC_USER) }, db);
694
- expect(result.ok).toBe(true);
695
- expect(firstWrittenRow(create)).toMatchObject({ actorType: "user", actorId: DIGIT_HEAVY_SPEC_USER });
696
- });
697
-
698
- it("records a digit-heavy agent id acting for a digit-heavy user id", async () => {
699
- const { db, create } = stubDb();
700
- const result = await recordAuditAction(
701
- {
702
- ...BASE_INPUT,
703
- actor: {
704
- type: "agent",
705
- agentId: DIGIT_HEAVY_AGENT as Id<"agent">,
706
- onBehalfOfUserId: DIGIT_HEAVY_SPEC_USER as Id<"user">,
707
- },
708
- },
709
- db,
710
- );
711
- expect(result.ok).toBe(true);
712
- const row = firstWrittenRow(create);
713
- expect(row).toMatchObject({ actorType: "agent", actorId: DIGIT_HEAVY_AGENT });
714
- expect(row.metadata.onBehalfOf).toBe(DIGIT_HEAVY_SPEC_USER);
715
- });
716
-
717
- it("still refuses a phone-shaped actor id that is not a registry id", async () => {
718
- const { db, create } = stubDb();
719
- const result = await recordAuditAction({ ...BASE_INPUT, actor: agentActor("agent-555-867-5309") }, db);
720
- expect(result.ok).toBe(false);
721
- expect(create).not.toHaveBeenCalled();
722
- });
723
-
724
- it("still scans every other identifier — a registry-shaped idempotencyKey is not exempt", async () => {
725
- const { db, create } = stubDb();
726
- const result = await recordAuditAction({ ...BASE_INPUT, idempotencyKey: DIGIT_HEAVY_SPEC_USER }, db);
727
- expect(result.ok).toBe(false);
728
- expect(create).not.toHaveBeenCalled();
729
- });
730
- });
731
-
732
- // ─── #3591 D8 — the route helpers ───────────────────────────────────────────
733
-
734
- describe("freshAuditIdempotencyKey (#3591 D8)", () => {
735
- it("is 32 hex characters in `_`-joined runs of at most six, fresh per call", () => {
736
- const first = freshAuditIdempotencyKey();
737
- expect(first).toMatch(/^[0-9a-f]{6}(?:_[0-9a-f]{1,6})*$/);
738
- expect(first.replace(/_/g, "")).toHaveLength(32);
739
- expect(freshAuditIdempotencyKey()).not.toBe(first);
740
- });
741
- });
742
-
743
- describe("auditActorFor (#3591 D8)", () => {
744
- it("passes request.actor through, and falls back to the tenant's own person with a warning", () => {
745
- const agent = agentActor("agent_abc123");
746
- expect(auditActorFor(agent, TENANT)).toBe(agent);
747
- expect(mockLoggerWarn).not.toHaveBeenCalled();
748
- expect(auditActorFor(undefined, TENANT)).toEqual({ type: "user", userId: USER_ID });
749
- expect(mockLoggerWarn).toHaveBeenCalledTimes(1);
750
- });
751
- });
752
-
753
- describe("recordAgentWrite (#3591 D8)", () => {
754
- const WRITE = {
755
- tenant: TENANT,
756
- domain: "inbox",
757
- tool: "mark_message_done",
758
- targetType: "lead",
759
- targetId: "lead_0190f3a2-7c1d-7e4a-9b2c-000000000004",
760
- };
761
-
762
- it("writes nothing for a person or an unknown actor", async () => {
763
- const { db, create } = stubDb();
764
- await recordAgentWrite(userActor(USER_ID), WRITE, { ok: true }, db);
765
- await recordAgentWrite(undefined, WRITE, { ok: true }, db);
766
- expect(create).not.toHaveBeenCalled();
767
- });
768
-
769
- it("writes one succeeded row for an agent's write that succeeded", async () => {
770
- const { db, create } = stubDb();
771
- await recordAgentWrite(agentActor("agent_abc123"), WRITE, { ok: true }, db);
772
- expect(create).toHaveBeenCalledTimes(1);
773
- const row = firstWrittenRow(create);
774
- expect(row).toMatchObject({
775
- actorType: "agent",
776
- actorId: "agent_abc123",
777
- action: "inbox.mark_message_done",
778
- targetType: "lead",
779
- });
780
- expect(row.metadata).toMatchObject({ outcome: "succeeded", onBehalfOf: USER_ID });
781
- expect(row.metadata).not.toHaveProperty("failureReason");
782
- });
783
-
784
- it("writes one failed row carrying the service's error kind for an agent's write that failed", async () => {
785
- const { db, create } = stubDb();
786
- await recordAgentWrite(
787
- agentActor("agent_abc123"),
788
- WRITE,
789
- { ok: false, error: { kind: "not_found" } },
790
- db,
791
- );
792
- const row = firstWrittenRow(create);
793
- expect(row.metadata).toMatchObject({ outcome: "failed", failureReason: "not_found" });
794
- });
795
-
796
- it("logs a failed audit write once at error and resolves, so the caller's response is unchanged", async () => {
797
- const { db } = stubDb(jest.fn().mockRejectedValue(new Error("boom")));
798
- await expect(
799
- recordAgentWrite(agentActor("agent_abc123"), WRITE, { ok: true }, db),
800
- ).resolves.toBeUndefined();
801
- const messages = mockLoggerError.mock.calls.map((call) => call[1] as string);
802
- expect(messages).toEqual(["[audit-log] audit row write failed"]);
803
- });
804
-
805
- it("logs a refused audit row once at error and resolves", async () => {
806
- const { db, create } = stubDb();
807
- await expect(
808
- recordAgentWrite(agentActor("agent_abc123"), { ...WRITE, domain: "In Box" }, { ok: true }, db),
809
- ).resolves.toBeUndefined();
810
- expect(create).not.toHaveBeenCalled();
811
- const messages = mockLoggerError.mock.calls.map((call) => call[1] as string);
812
- expect(messages).toEqual(["[audit-log] agent write audit refused"]);
813
- });
814
- });
815
-
816
- // #3591 PR-B — a registry id is an identifier, not personal data, in free
817
- // text too: the agent lifecycle rows name the person they were made for by
818
- // user id in `summary`, and a digit-heavy id must survive the scan.
819
- describe("summary and failureReason keep a registry user_ or agent_ id whole (#3591 D8)", () => {
820
- const DIGIT_HEAVY_USER = "user_01923456-7890-7abc-8def-0123456789ab";
821
- const DIGIT_HEAVY_AGENT = "agent_01923456-7890-7abc-8def-0123456789ab";
822
-
823
- async function storedSummary(summary: string): Promise<unknown> {
824
- const { db, create } = stubDb();
825
- const result = await recordAuditAction({ ...BASE_INPUT, summary }, db);
826
- expect(result.ok).toBe(true);
827
- return firstWrittenRow(create).metadata.summary;
828
- }
829
-
830
- it("the fixture id really is phone-shaped to the bare scan", () => {
831
- expect(redactPersonalData(DIGIT_HEAVY_USER)).toContain("[REDACTED:");
832
- });
833
-
834
- it("a summary naming a digit-heavy user id is stored as written", async () => {
835
- expect(await storedSummary(`responsibleUserId=${DIGIT_HEAVY_USER}`)).toBe(
836
- `responsibleUserId=${DIGIT_HEAVY_USER}`,
837
- );
838
- });
839
-
840
- it("keeps the ids and still redacts the personal data around them", async () => {
841
- const out = (await storedSummary(
842
- `responsibleUserId=${DIGIT_HEAVY_USER} agent=${DIGIT_HEAVY_AGENT} call +1 415 555 0100 or jane@example.com`,
843
- )) as string;
844
- expect(out).toContain(`responsibleUserId=${DIGIT_HEAVY_USER}`);
845
- expect(out).toContain(`agent=${DIGIT_HEAVY_AGENT}`);
846
- expect(out).toContain("[REDACTED:phone]");
847
- expect(out).toContain("[REDACTED:email]");
848
- expect(out).not.toContain("jane@example.com");
849
- });
850
-
851
- it("still scans a digit run glued onto an id, and an id of another entity", async () => {
852
- expect(await storedSummary(`${DIGIT_HEAVY_USER}5550100`)).toContain("[REDACTED:");
853
- expect(await storedSummary("lead_01923456-7890-7abc-8def-0123456789ab")).toContain("[REDACTED:");
854
- });
855
-
856
- it("does not exempt a phone number dressed up as an id, nor an id inside a longer token", async () => {
857
- for (const disguised of [
858
- "user_+1-415-555-0100",
859
- "user_4155550100-7abc-8def-0123456789ab",
860
- `x${DIGIT_HEAVY_USER}`,
861
- `${DIGIT_HEAVY_USER}.`,
862
- ]) {
863
- expect(await storedSummary(`responsibleUserId=${disguised}`)).toContain("[REDACTED:");
864
- }
865
- });
866
-
867
- it("still catches a phone number written with spaces between exempt ids", async () => {
868
- const out = (await storedSummary(`${DIGIT_HEAVY_USER} +1 415 555 0100 ${DIGIT_HEAVY_AGENT}`)) as string;
869
- expect(out).toBe(`${DIGIT_HEAVY_USER} [REDACTED:phone] ${DIGIT_HEAVY_AGENT}`);
870
- });
871
-
872
- it("applies to failureReason the same way", async () => {
873
- const { db, create } = stubDb();
874
- await recordAuditAction(
875
- { ...BASE_INPUT, outcome: "failed", failureReason: `not a member: ${DIGIT_HEAVY_USER}` },
876
- db,
877
- );
878
- expect(firstWrittenRow(create).metadata.failureReason).toBe(`not a member: ${DIGIT_HEAVY_USER}`);
879
- });
880
- });
881
-
882
- describe("recordAgentWrite given the request (#3591 PR-B)", () => {
883
- const AGENT_ID = "agent_0190f3a2-7c1d-7e4a-9b2c-000000000005";
884
- const WRITE = {
885
- tenant: TENANT,
886
- domain: "inbox",
887
- tool: "set_application_featured",
888
- targetType: "project_listing",
889
- targetId: "listing_abc123",
890
- };
891
-
892
- it("reads request.actor when it is set", async () => {
893
- const { db, create } = stubDb();
894
- await recordAgentWrite(
895
- { actor: agentActor(AGENT_ID), agent: { agentId: AGENT_ID as Id<"agent"> } },
896
- WRITE,
897
- { ok: true },
898
- db,
899
- );
900
- expect(firstWrittenRow(create)).toMatchObject({ actorType: "agent", actorId: AGENT_ID });
901
- expect(mockLoggerError).not.toHaveBeenCalled();
902
- });
903
-
904
- it("an agent request with no request.actor is logged at error and still recorded, from request.agent", async () => {
905
- const { db, create } = stubDb();
906
- await recordAgentWrite({ agent: { agentId: AGENT_ID as Id<"agent"> } }, WRITE, { ok: true }, db);
907
-
908
- expect(create).toHaveBeenCalledTimes(1);
909
- const row = firstWrittenRow(create);
910
- expect(row).toMatchObject({
911
- actorType: "agent",
912
- actorId: AGENT_ID,
913
- action: "inbox.set_application_featured",
914
- });
915
- expect(row.metadata).toMatchObject({ onBehalfOf: USER_ID, outcome: "succeeded" });
916
- expect(mockLoggerError).toHaveBeenCalledTimes(1);
917
- expect(mockLoggerError.mock.calls[0]![0]).toMatchObject({ actorId: AGENT_ID });
918
- expect(mockLoggerError.mock.calls[0]![1]).toBe(
919
- "[audit-log] agent write without request.actor; recording from request.agent",
920
- );
921
- });
922
-
923
- it("a request with neither, or a person's request, records nothing and logs nothing", async () => {
924
- const { db, create } = stubDb();
925
- await recordAgentWrite({}, WRITE, { ok: true }, db);
926
- await recordAgentWrite({ actor: userActor(USER_ID) }, WRITE, { ok: true }, db);
927
- expect(create).not.toHaveBeenCalled();
928
- expect(mockLoggerError).not.toHaveBeenCalled();
929
- });
930
-
931
- it("the refused-row error line names the actor id", async () => {
932
- const { db } = stubDb();
933
- await recordAgentWrite({ actor: agentActor(AGENT_ID) }, { ...WRITE, domain: "In Box" }, { ok: true }, db);
934
- expect(mockLoggerError).toHaveBeenCalledTimes(1);
935
- expect(mockLoggerError.mock.calls[0]![0]).toMatchObject({ actorId: AGENT_ID });
936
- expect(mockLoggerError.mock.calls[0]![1]).toBe("[audit-log] agent write audit refused");
937
- });
938
- });
939
-
940
- // ─── #8516 D14 — recordWorkspaceAuditAction, a row without a tenant ────────────
941
-
942
- describe("#8516 AC-7 — recordWorkspaceAuditAction", () => {
943
- const PIECE_ID = "piece_0190f3a2-7c1d-7e4a-9b2c-000000000004";
944
- const ROW = {
945
- domain: "people",
946
- tool: "proposal.client_review",
947
- outcome: "succeeded" as const,
948
- idempotencyKey: "req_proposal_review",
949
- targetType: "piece",
950
- targetId: PIECE_ID,
951
- summary: '{"by":"client","review":"approved","priced":true}',
952
- };
953
-
954
- it("writes the row recordAuditAction would for the same workspace and user actor", async () => {
955
- const tenantWrite = stubDb();
956
- const tenantResult = await recordAuditAction(
957
- { ...ROW, tenant: TENANT, actor: userActor(USER_ID) },
958
- tenantWrite.db,
959
- );
960
- const workspaceWrite = stubDb();
961
- const workspaceResult = await recordWorkspaceAuditAction(
962
- { ...ROW, workspaceId: WORKSPACE_ID, actor: { type: "user", userId: USER_ID as Id<"user"> } },
963
- workspaceWrite.db,
964
- );
965
-
966
- expect(workspaceWrite.create).toHaveBeenCalledTimes(1);
967
- expect(firstWrittenRow(workspaceWrite.create)).toEqual(firstWrittenRow(tenantWrite.create));
968
- expect(workspaceResult).toEqual(tenantResult);
969
- expect(workspaceResult).toMatchObject({ ok: true, outcome: "recorded" });
970
- });
971
-
972
- it("the system actor stores actor_type system and actor_id stripe", async () => {
973
- const { db, create } = stubDb();
974
- const result = await recordWorkspaceAuditAction(
975
- {
976
- workspaceId: WORKSPACE_ID,
977
- actor: { type: "system", systemId: "stripe" },
978
- domain: "people",
979
- tool: "proposal.paid",
980
- outcome: "failed",
981
- failureReason: "already_paid",
982
- idempotencyKey: "evt_test_proposal",
983
- targetType: "piece",
984
- targetId: PIECE_ID,
985
- },
986
- db,
987
- );
988
-
989
- expect(result).toMatchObject({ ok: true, outcome: "recorded" });
990
- expect(create).toHaveBeenCalledTimes(1);
991
- const row = firstWrittenRow(create);
992
- expect(row).toMatchObject({
993
- workspaceId: WORKSPACE_ID,
994
- actorType: "system",
995
- actorId: "stripe",
996
- action: "people.proposal.paid",
997
- targetType: "piece",
998
- targetId: PIECE_ID,
999
- });
1000
- expect(row.metadata).toEqual({
1001
- v: 2,
1002
- outcome: "failed",
1003
- tool: "proposal.paid",
1004
- idempotencyKey: "evt_test_proposal",
1005
- failureReason: "already_paid",
1006
- });
1007
- expect(row.metadata).not.toHaveProperty("onBehalfOf");
1008
- expect(zAuditLogId.safeParse(row.id).success).toBe(true);
1009
- });
1010
-
1011
- it("an invalid workspaceId is invalid_input and writes nothing", async () => {
1012
- const { db, create } = stubDb();
1013
- const result = await recordWorkspaceAuditAction(
1014
- { ...ROW, workspaceId: "not-a-workspace", actor: { type: "system", systemId: "stripe" } },
1015
- db,
1016
- );
1017
-
1018
- expect(result).toEqual({
1019
- ok: false,
1020
- error: {
1021
- kind: "invalid_input",
1022
- message: "workspaceId is not a valid workspace id",
1023
- persisted: false,
1024
- },
1025
- });
1026
- expect(create).not.toHaveBeenCalled();
1027
- });
1028
- });