@kelpie/server 0.10.0 → 0.12.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 (485) hide show
  1. package/dist/app.d.ts.map +1 -1
  2. package/dist/app.js +2 -0
  3. package/dist/app.js.map +1 -1
  4. package/dist/index.d.ts +3 -3
  5. package/dist/index.d.ts.map +1 -1
  6. package/dist/index.js +1 -1
  7. package/dist/index.js.map +1 -1
  8. package/dist/lib/actor.d.ts +3 -1
  9. package/dist/lib/actor.d.ts.map +1 -1
  10. package/dist/lib/actor.js.map +1 -1
  11. package/dist/lib/apiKeyScopes.d.ts +8 -0
  12. package/dist/lib/apiKeyScopes.d.ts.map +1 -0
  13. package/dist/lib/apiKeyScopes.js +166 -0
  14. package/dist/lib/apiKeyScopes.js.map +1 -0
  15. package/dist/lib/errors.d.ts +18 -0
  16. package/dist/lib/errors.d.ts.map +1 -1
  17. package/dist/lib/errors.js +17 -0
  18. package/dist/lib/errors.js.map +1 -1
  19. package/dist/modules/activities/repository.d.ts +2 -0
  20. package/dist/modules/activities/repository.d.ts.map +1 -1
  21. package/dist/modules/activities/repository.js +9 -0
  22. package/dist/modules/activities/repository.js.map +1 -1
  23. package/dist/modules/agent-tasks/repository.d.ts +2 -0
  24. package/dist/modules/agent-tasks/repository.d.ts.map +1 -1
  25. package/dist/modules/agent-tasks/repository.js +9 -0
  26. package/dist/modules/agent-tasks/repository.js.map +1 -1
  27. package/dist/modules/api-keys/routes.d.ts.map +1 -1
  28. package/dist/modules/api-keys/routes.js +4 -1
  29. package/dist/modules/api-keys/routes.js.map +1 -1
  30. package/dist/modules/api-keys/schema.d.ts +43 -0
  31. package/dist/modules/api-keys/schema.d.ts.map +1 -1
  32. package/dist/modules/api-keys/schema.js +2 -0
  33. package/dist/modules/api-keys/schema.js.map +1 -1
  34. package/dist/modules/api-keys/scopeMiddleware.d.ts +8 -0
  35. package/dist/modules/api-keys/scopeMiddleware.d.ts.map +1 -0
  36. package/dist/modules/api-keys/scopeMiddleware.js +21 -0
  37. package/dist/modules/api-keys/scopeMiddleware.js.map +1 -0
  38. package/dist/modules/api-keys/service.d.ts +3 -1
  39. package/dist/modules/api-keys/service.d.ts.map +1 -1
  40. package/dist/modules/api-keys/service.js +26 -1
  41. package/dist/modules/api-keys/service.js.map +1 -1
  42. package/dist/modules/auth/credentials.d.ts.map +1 -1
  43. package/dist/modules/auth/credentials.js +2 -0
  44. package/dist/modules/auth/credentials.js.map +1 -1
  45. package/dist/modules/auth/index.d.ts.map +1 -1
  46. package/dist/modules/auth/index.js +21 -4
  47. package/dist/modules/auth/index.js.map +1 -1
  48. package/dist/modules/auth/repository.d.ts +2 -1
  49. package/dist/modules/auth/repository.d.ts.map +1 -1
  50. package/dist/modules/auth/repository.js +1 -0
  51. package/dist/modules/auth/repository.js.map +1 -1
  52. package/dist/modules/auth/routes.d.ts.map +1 -1
  53. package/dist/modules/auth/routes.js +2 -6
  54. package/dist/modules/auth/routes.js.map +1 -1
  55. package/dist/modules/auth/schema.d.ts +18 -1
  56. package/dist/modules/auth/schema.d.ts.map +1 -1
  57. package/dist/modules/auth/schema.js +12 -1
  58. package/dist/modules/auth/schema.js.map +1 -1
  59. package/dist/modules/auth/service.d.ts +18 -0
  60. package/dist/modules/auth/service.d.ts.map +1 -1
  61. package/dist/modules/auth/service.js +95 -6
  62. package/dist/modules/auth/service.js.map +1 -1
  63. package/dist/modules/auth/session.d.ts +12 -0
  64. package/dist/modules/auth/session.d.ts.map +1 -1
  65. package/dist/modules/auth/session.js +12 -0
  66. package/dist/modules/auth/session.js.map +1 -1
  67. package/dist/modules/consent-purposes/index.d.ts +1 -1
  68. package/dist/modules/consent-purposes/index.js +1 -1
  69. package/dist/modules/consent-purposes/schema.d.ts +3 -3
  70. package/dist/modules/consent-purposes/schema.js +3 -3
  71. package/dist/modules/consent-purposes/service.d.ts +1 -1
  72. package/dist/modules/consent-purposes/service.d.ts.map +1 -1
  73. package/dist/modules/consent-purposes/service.js +7 -16
  74. package/dist/modules/consent-purposes/service.js.map +1 -1
  75. package/dist/modules/consent-purposes/starters.d.ts +1 -1
  76. package/dist/modules/consent-purposes/tools.js +1 -1
  77. package/dist/modules/consent-purposes/tools.js.map +1 -1
  78. package/dist/modules/conversions/clearPointers.d.ts +10 -0
  79. package/dist/modules/conversions/clearPointers.d.ts.map +1 -0
  80. package/dist/modules/conversions/clearPointers.js +40 -0
  81. package/dist/modules/conversions/clearPointers.js.map +1 -0
  82. package/dist/modules/conversions/factory.d.ts +5 -0
  83. package/dist/modules/conversions/factory.d.ts.map +1 -0
  84. package/dist/modules/conversions/factory.js +18 -0
  85. package/dist/modules/conversions/factory.js.map +1 -0
  86. package/dist/modules/conversions/fieldMap.d.ts +55 -0
  87. package/dist/modules/conversions/fieldMap.d.ts.map +1 -0
  88. package/dist/modules/conversions/fieldMap.js +398 -0
  89. package/dist/modules/conversions/fieldMap.js.map +1 -0
  90. package/dist/modules/conversions/index.d.ts +7 -0
  91. package/dist/modules/conversions/index.d.ts.map +1 -0
  92. package/dist/modules/conversions/index.js +6 -0
  93. package/dist/modules/conversions/index.js.map +1 -0
  94. package/dist/modules/conversions/mcp.d.ts +7 -0
  95. package/dist/modules/conversions/mcp.d.ts.map +1 -0
  96. package/dist/modules/conversions/mcp.js +47 -0
  97. package/dist/modules/conversions/mcp.js.map +1 -0
  98. package/dist/modules/conversions/repoint.d.ts +19 -0
  99. package/dist/modules/conversions/repoint.d.ts.map +1 -0
  100. package/dist/modules/conversions/repoint.js +51 -0
  101. package/dist/modules/conversions/repoint.js.map +1 -0
  102. package/dist/modules/conversions/routes.d.ts +26 -0
  103. package/dist/modules/conversions/routes.d.ts.map +1 -0
  104. package/dist/modules/conversions/routes.js +23 -0
  105. package/dist/modules/conversions/routes.js.map +1 -0
  106. package/dist/modules/conversions/service.d.ts +28 -0
  107. package/dist/modules/conversions/service.d.ts.map +1 -0
  108. package/dist/modules/conversions/service.js +170 -0
  109. package/dist/modules/conversions/service.js.map +1 -0
  110. package/dist/modules/conversions/wire.d.ts +4 -0
  111. package/dist/modules/conversions/wire.d.ts.map +1 -0
  112. package/dist/modules/conversions/wire.js +28 -0
  113. package/dist/modules/conversions/wire.js.map +1 -0
  114. package/dist/modules/deals/events.d.ts +9 -0
  115. package/dist/modules/deals/events.d.ts.map +1 -1
  116. package/dist/modules/deals/events.js +4 -0
  117. package/dist/modules/deals/events.js.map +1 -1
  118. package/dist/modules/deals/index.d.ts.map +1 -1
  119. package/dist/modules/deals/index.js +4 -2
  120. package/dist/modules/deals/index.js.map +1 -1
  121. package/dist/modules/deals/routes.d.ts +2 -0
  122. package/dist/modules/deals/routes.d.ts.map +1 -1
  123. package/dist/modules/deals/routes.js +8 -1
  124. package/dist/modules/deals/routes.js.map +1 -1
  125. package/dist/modules/deals/schema.d.ts +34 -0
  126. package/dist/modules/deals/schema.d.ts.map +1 -1
  127. package/dist/modules/deals/schema.js +7 -2
  128. package/dist/modules/deals/schema.js.map +1 -1
  129. package/dist/modules/deals/service.d.ts.map +1 -1
  130. package/dist/modules/deals/service.js +2 -0
  131. package/dist/modules/deals/service.js.map +1 -1
  132. package/dist/modules/deals/tools.d.ts +2 -1
  133. package/dist/modules/deals/tools.d.ts.map +1 -1
  134. package/dist/modules/deals/tools.js +3 -1
  135. package/dist/modules/deals/tools.js.map +1 -1
  136. package/dist/modules/decisions/repository.d.ts +2 -1
  137. package/dist/modules/decisions/repository.d.ts.map +1 -1
  138. package/dist/modules/decisions/repository.js +9 -1
  139. package/dist/modules/decisions/repository.js.map +1 -1
  140. package/dist/modules/enquiries/events.d.ts +6 -2
  141. package/dist/modules/enquiries/events.d.ts.map +1 -1
  142. package/dist/modules/enquiries/events.js +5 -1
  143. package/dist/modules/enquiries/events.js.map +1 -1
  144. package/dist/modules/enquiries/index.d.ts.map +1 -1
  145. package/dist/modules/enquiries/index.js +4 -2
  146. package/dist/modules/enquiries/index.js.map +1 -1
  147. package/dist/modules/enquiries/routes.d.ts +2 -0
  148. package/dist/modules/enquiries/routes.d.ts.map +1 -1
  149. package/dist/modules/enquiries/routes.js +9 -9
  150. package/dist/modules/enquiries/routes.js.map +1 -1
  151. package/dist/modules/enquiries/schema.d.ts +36 -1
  152. package/dist/modules/enquiries/schema.d.ts.map +1 -1
  153. package/dist/modules/enquiries/schema.js +9 -3
  154. package/dist/modules/enquiries/schema.js.map +1 -1
  155. package/dist/modules/enquiries/service.d.ts +0 -8
  156. package/dist/modules/enquiries/service.d.ts.map +1 -1
  157. package/dist/modules/enquiries/service.js +3 -95
  158. package/dist/modules/enquiries/service.js.map +1 -1
  159. package/dist/modules/enquiries/tools.d.ts +2 -1
  160. package/dist/modules/enquiries/tools.d.ts.map +1 -1
  161. package/dist/modules/enquiries/tools.js +4 -16
  162. package/dist/modules/enquiries/tools.js.map +1 -1
  163. package/dist/modules/forms/applyMappedFields.d.ts +20 -0
  164. package/dist/modules/forms/applyMappedFields.d.ts.map +1 -0
  165. package/dist/modules/forms/applyMappedFields.js +169 -0
  166. package/dist/modules/forms/applyMappedFields.js.map +1 -0
  167. package/dist/modules/forms/applySubmissionFields.d.ts +18 -0
  168. package/dist/modules/forms/applySubmissionFields.d.ts.map +1 -0
  169. package/dist/modules/forms/applySubmissionFields.js +230 -0
  170. package/dist/modules/forms/applySubmissionFields.js.map +1 -0
  171. package/dist/modules/forms/fields.d.ts +7 -2
  172. package/dist/modules/forms/fields.d.ts.map +1 -1
  173. package/dist/modules/forms/fields.js +17 -6
  174. package/dist/modules/forms/fields.js.map +1 -1
  175. package/dist/modules/forms/mapping.d.ts +8 -2
  176. package/dist/modules/forms/mapping.d.ts.map +1 -1
  177. package/dist/modules/forms/mapping.js +11 -0
  178. package/dist/modules/forms/mapping.js.map +1 -1
  179. package/dist/modules/forms/repository.d.ts +0 -5
  180. package/dist/modules/forms/repository.d.ts.map +1 -1
  181. package/dist/modules/forms/repository.js +0 -2
  182. package/dist/modules/forms/repository.js.map +1 -1
  183. package/dist/modules/forms/routes.d.ts +2 -30
  184. package/dist/modules/forms/routes.d.ts.map +1 -1
  185. package/dist/modules/forms/routes.js +2 -2
  186. package/dist/modules/forms/routes.js.map +1 -1
  187. package/dist/modules/forms/schema.d.ts.map +1 -1
  188. package/dist/modules/forms/schema.js +1 -2
  189. package/dist/modules/forms/schema.js.map +1 -1
  190. package/dist/modules/forms/service.d.ts.map +1 -1
  191. package/dist/modules/forms/service.js +18 -3
  192. package/dist/modules/forms/service.js.map +1 -1
  193. package/dist/modules/forms/starters.d.ts +31 -0
  194. package/dist/modules/forms/starters.d.ts.map +1 -0
  195. package/dist/modules/forms/starters.js +94 -0
  196. package/dist/modules/forms/starters.js.map +1 -0
  197. package/dist/modules/forms/submission.d.ts +1 -0
  198. package/dist/modules/forms/submission.d.ts.map +1 -1
  199. package/dist/modules/forms/submission.js +58 -37
  200. package/dist/modules/forms/submission.js.map +1 -1
  201. package/dist/modules/import-export/customFieldCsv.d.ts +9 -0
  202. package/dist/modules/import-export/customFieldCsv.d.ts.map +1 -0
  203. package/dist/modules/import-export/customFieldCsv.js +39 -0
  204. package/dist/modules/import-export/customFieldCsv.js.map +1 -0
  205. package/dist/modules/import-export/customFieldImport.d.ts +19 -0
  206. package/dist/modules/import-export/customFieldImport.d.ts.map +1 -0
  207. package/dist/modules/import-export/customFieldImport.js +76 -0
  208. package/dist/modules/import-export/customFieldImport.js.map +1 -0
  209. package/dist/modules/import-export/drafts.d.ts +57 -3
  210. package/dist/modules/import-export/drafts.d.ts.map +1 -1
  211. package/dist/modules/import-export/drafts.js +65 -3
  212. package/dist/modules/import-export/drafts.js.map +1 -1
  213. package/dist/modules/import-export/exportRows.d.ts +15 -13
  214. package/dist/modules/import-export/exportRows.d.ts.map +1 -1
  215. package/dist/modules/import-export/exportRows.js +99 -26
  216. package/dist/modules/import-export/exportRows.js.map +1 -1
  217. package/dist/modules/import-export/plan.d.ts +42 -11
  218. package/dist/modules/import-export/plan.d.ts.map +1 -1
  219. package/dist/modules/import-export/plan.js +198 -56
  220. package/dist/modules/import-export/plan.js.map +1 -1
  221. package/dist/modules/import-export/repository.d.ts +58 -2
  222. package/dist/modules/import-export/repository.d.ts.map +1 -1
  223. package/dist/modules/import-export/repository.js +201 -12
  224. package/dist/modules/import-export/repository.js.map +1 -1
  225. package/dist/modules/import-export/routes.d.ts.map +1 -1
  226. package/dist/modules/import-export/routes.js +5 -5
  227. package/dist/modules/import-export/routes.js.map +1 -1
  228. package/dist/modules/import-export/service.d.ts +8 -3
  229. package/dist/modules/import-export/service.d.ts.map +1 -1
  230. package/dist/modules/import-export/service.js +133 -40
  231. package/dist/modules/import-export/service.js.map +1 -1
  232. package/dist/modules/import-export/streams.d.ts +2 -2
  233. package/dist/modules/import-export/streams.d.ts.map +1 -1
  234. package/dist/modules/import-export/streams.js +50 -9
  235. package/dist/modules/import-export/streams.js.map +1 -1
  236. package/dist/modules/import-export/tools.d.ts.map +1 -1
  237. package/dist/modules/import-export/tools.js +13 -7
  238. package/dist/modules/import-export/tools.js.map +1 -1
  239. package/dist/modules/import-export/validation.d.ts +5 -1
  240. package/dist/modules/import-export/validation.d.ts.map +1 -1
  241. package/dist/modules/import-export/validation.js +89 -2
  242. package/dist/modules/import-export/validation.js.map +1 -1
  243. package/dist/modules/import-export/writes.d.ts +2 -1
  244. package/dist/modules/import-export/writes.d.ts.map +1 -1
  245. package/dist/modules/import-export/writes.js +358 -25
  246. package/dist/modules/import-export/writes.js.map +1 -1
  247. package/dist/modules/lists/repository.d.ts +0 -1
  248. package/dist/modules/lists/repository.d.ts.map +1 -1
  249. package/dist/modules/lists/repository.js +0 -1
  250. package/dist/modules/lists/repository.js.map +1 -1
  251. package/dist/modules/lists/routes.d.ts +0 -2
  252. package/dist/modules/lists/routes.d.ts.map +1 -1
  253. package/dist/modules/lists/routes.js +0 -8
  254. package/dist/modules/lists/routes.js.map +1 -1
  255. package/dist/modules/lists/schema.d.ts +0 -17
  256. package/dist/modules/lists/schema.d.ts.map +1 -1
  257. package/dist/modules/lists/schema.js +0 -10
  258. package/dist/modules/lists/schema.js.map +1 -1
  259. package/dist/modules/lists/service.d.ts +2 -14
  260. package/dist/modules/lists/service.d.ts.map +1 -1
  261. package/dist/modules/lists/service.js +7 -53
  262. package/dist/modules/lists/service.js.map +1 -1
  263. package/dist/modules/lists/starters.d.ts +12 -0
  264. package/dist/modules/lists/starters.d.ts.map +1 -0
  265. package/dist/modules/lists/starters.js +4 -0
  266. package/dist/modules/lists/starters.js.map +1 -0
  267. package/dist/modules/mcp/protocol.d.ts.map +1 -1
  268. package/dist/modules/mcp/protocol.js +13 -0
  269. package/dist/modules/mcp/protocol.js.map +1 -1
  270. package/dist/modules/notes/repository.d.ts +2 -0
  271. package/dist/modules/notes/repository.d.ts.map +1 -1
  272. package/dist/modules/notes/repository.js +9 -0
  273. package/dist/modules/notes/repository.js.map +1 -1
  274. package/dist/modules/opportunities/events.d.ts +9 -0
  275. package/dist/modules/opportunities/events.d.ts.map +1 -1
  276. package/dist/modules/opportunities/events.js +4 -0
  277. package/dist/modules/opportunities/events.js.map +1 -1
  278. package/dist/modules/opportunities/index.d.ts.map +1 -1
  279. package/dist/modules/opportunities/index.js +4 -2
  280. package/dist/modules/opportunities/index.js.map +1 -1
  281. package/dist/modules/opportunities/routes.d.ts +2 -0
  282. package/dist/modules/opportunities/routes.d.ts.map +1 -1
  283. package/dist/modules/opportunities/routes.js +8 -1
  284. package/dist/modules/opportunities/routes.js.map +1 -1
  285. package/dist/modules/opportunities/schema.d.ts +34 -0
  286. package/dist/modules/opportunities/schema.d.ts.map +1 -1
  287. package/dist/modules/opportunities/schema.js +7 -2
  288. package/dist/modules/opportunities/schema.js.map +1 -1
  289. package/dist/modules/opportunities/service.d.ts.map +1 -1
  290. package/dist/modules/opportunities/service.js +2 -0
  291. package/dist/modules/opportunities/service.js.map +1 -1
  292. package/dist/modules/opportunities/tools.d.ts +2 -1
  293. package/dist/modules/opportunities/tools.d.ts.map +1 -1
  294. package/dist/modules/opportunities/tools.js +3 -1
  295. package/dist/modules/opportunities/tools.js.map +1 -1
  296. package/dist/modules/partnerships/events.d.ts +9 -0
  297. package/dist/modules/partnerships/events.d.ts.map +1 -1
  298. package/dist/modules/partnerships/events.js +4 -0
  299. package/dist/modules/partnerships/events.js.map +1 -1
  300. package/dist/modules/partnerships/index.d.ts.map +1 -1
  301. package/dist/modules/partnerships/index.js +4 -2
  302. package/dist/modules/partnerships/index.js.map +1 -1
  303. package/dist/modules/partnerships/routes.d.ts +2 -0
  304. package/dist/modules/partnerships/routes.d.ts.map +1 -1
  305. package/dist/modules/partnerships/routes.js +8 -1
  306. package/dist/modules/partnerships/routes.js.map +1 -1
  307. package/dist/modules/partnerships/schema.d.ts +34 -0
  308. package/dist/modules/partnerships/schema.d.ts.map +1 -1
  309. package/dist/modules/partnerships/schema.js +7 -2
  310. package/dist/modules/partnerships/schema.js.map +1 -1
  311. package/dist/modules/partnerships/service.d.ts.map +1 -1
  312. package/dist/modules/partnerships/service.js +2 -0
  313. package/dist/modules/partnerships/service.js.map +1 -1
  314. package/dist/modules/partnerships/tools.d.ts +2 -1
  315. package/dist/modules/partnerships/tools.d.ts.map +1 -1
  316. package/dist/modules/partnerships/tools.js +3 -1
  317. package/dist/modules/partnerships/tools.js.map +1 -1
  318. package/dist/modules/people/personConsentWrites.d.ts +1 -1
  319. package/dist/modules/people/schema.js +1 -1
  320. package/dist/modules/people/schema.js.map +1 -1
  321. package/dist/modules/plans/repository.d.ts +2 -0
  322. package/dist/modules/plans/repository.d.ts.map +1 -1
  323. package/dist/modules/plans/repository.js +9 -0
  324. package/dist/modules/plans/repository.js.map +1 -1
  325. package/dist/modules/raises/events.d.ts +9 -0
  326. package/dist/modules/raises/events.d.ts.map +1 -1
  327. package/dist/modules/raises/events.js +4 -0
  328. package/dist/modules/raises/events.js.map +1 -1
  329. package/dist/modules/raises/index.d.ts.map +1 -1
  330. package/dist/modules/raises/index.js +4 -2
  331. package/dist/modules/raises/index.js.map +1 -1
  332. package/dist/modules/raises/routes.d.ts +2 -0
  333. package/dist/modules/raises/routes.d.ts.map +1 -1
  334. package/dist/modules/raises/routes.js +8 -1
  335. package/dist/modules/raises/routes.js.map +1 -1
  336. package/dist/modules/raises/schema.d.ts +34 -0
  337. package/dist/modules/raises/schema.d.ts.map +1 -1
  338. package/dist/modules/raises/schema.js +7 -2
  339. package/dist/modules/raises/schema.js.map +1 -1
  340. package/dist/modules/raises/service.d.ts.map +1 -1
  341. package/dist/modules/raises/service.js +2 -0
  342. package/dist/modules/raises/service.js.map +1 -1
  343. package/dist/modules/raises/tools.d.ts +2 -1
  344. package/dist/modules/raises/tools.d.ts.map +1 -1
  345. package/dist/modules/raises/tools.js +3 -1
  346. package/dist/modules/raises/tools.js.map +1 -1
  347. package/dist/modules/workspace/routes.d.ts +0 -2
  348. package/dist/modules/workspace/routes.d.ts.map +1 -1
  349. package/dist/modules/workspace/routes.js +0 -6
  350. package/dist/modules/workspace/routes.js.map +1 -1
  351. package/dist/modules/workspace/schema.d.ts +0 -34
  352. package/dist/modules/workspace/schema.d.ts.map +1 -1
  353. package/dist/modules/workspace/schema.js +0 -2
  354. package/dist/modules/workspace/schema.js.map +1 -1
  355. package/dist/modules/workspace/seedStarterForms.d.ts +17 -0
  356. package/dist/modules/workspace/seedStarterForms.d.ts.map +1 -0
  357. package/dist/modules/workspace/seedStarterForms.js +71 -0
  358. package/dist/modules/workspace/seedStarterForms.js.map +1 -0
  359. package/dist/modules/workspace/service.d.ts +0 -4
  360. package/dist/modules/workspace/service.d.ts.map +1 -1
  361. package/dist/modules/workspace/service.js +20 -10
  362. package/dist/modules/workspace/service.js.map +1 -1
  363. package/dist/modules/workspace/tools.js +1 -1
  364. package/dist/modules/workspace/tools.js.map +1 -1
  365. package/dist/runtime/module.d.ts +63 -1
  366. package/dist/runtime/module.d.ts.map +1 -1
  367. package/dist/runtime/registry.d.ts.map +1 -1
  368. package/dist/runtime/registry.js +40 -2
  369. package/dist/runtime/registry.js.map +1 -1
  370. package/dist/testing/fixtures.d.ts.map +1 -1
  371. package/dist/testing/fixtures.js +1 -0
  372. package/dist/testing/fixtures.js.map +1 -1
  373. package/migrations/0037_drop_lists_consent_purpose_id.sql +2 -0
  374. package/migrations/0038_smart_white_queen.sql +2 -0
  375. package/migrations/0039_form_map_to_open.sql +1 -0
  376. package/migrations/0040_pipeline_converted_to.sql +20 -0
  377. package/migrations/0041_api_key_scopes.sql +1 -0
  378. package/migrations/0042_drop_workspace_identity.sql +2 -0
  379. package/migrations/0043_external_sign_in.sql +2 -0
  380. package/migrations/meta/0038_snapshot.json +6554 -0
  381. package/migrations/meta/_journal.json +49 -0
  382. package/package.json +2 -2
  383. package/src/app.ts +3 -0
  384. package/src/index.ts +13 -1
  385. package/src/lib/actor.ts +3 -1
  386. package/src/lib/apiKeyScopes.ts +213 -0
  387. package/src/lib/errors.ts +30 -0
  388. package/src/modules/activities/repository.ts +24 -0
  389. package/src/modules/agent-tasks/repository.ts +24 -0
  390. package/src/modules/api-keys/routes.ts +5 -0
  391. package/src/modules/api-keys/schema.ts +2 -0
  392. package/src/modules/api-keys/scopeMiddleware.ts +30 -0
  393. package/src/modules/api-keys/service.ts +36 -2
  394. package/src/modules/auth/credentials.ts +4 -0
  395. package/src/modules/auth/index.ts +25 -4
  396. package/src/modules/auth/repository.ts +2 -1
  397. package/src/modules/auth/routes.ts +2 -8
  398. package/src/modules/auth/schema.ts +12 -1
  399. package/src/modules/auth/service.ts +143 -6
  400. package/src/modules/auth/session.ts +14 -0
  401. package/src/modules/consent-purposes/index.ts +1 -1
  402. package/src/modules/consent-purposes/schema.ts +3 -3
  403. package/src/modules/consent-purposes/service.ts +7 -16
  404. package/src/modules/consent-purposes/starters.ts +1 -1
  405. package/src/modules/consent-purposes/tools.ts +1 -1
  406. package/src/modules/conversions/clearPointers.ts +81 -0
  407. package/src/modules/conversions/factory.ts +20 -0
  408. package/src/modules/conversions/fieldMap.ts +548 -0
  409. package/src/modules/conversions/index.ts +6 -0
  410. package/src/modules/conversions/mcp.ts +71 -0
  411. package/src/modules/conversions/repoint.ts +146 -0
  412. package/src/modules/conversions/routes.ts +68 -0
  413. package/src/modules/conversions/service.ts +310 -0
  414. package/src/modules/conversions/wire.ts +42 -0
  415. package/src/modules/deals/events.ts +9 -0
  416. package/src/modules/deals/index.ts +4 -2
  417. package/src/modules/deals/routes.ts +11 -1
  418. package/src/modules/deals/schema.ts +10 -2
  419. package/src/modules/deals/service.ts +3 -0
  420. package/src/modules/deals/tools.ts +9 -1
  421. package/src/modules/decisions/repository.ts +23 -1
  422. package/src/modules/enquiries/events.ts +8 -2
  423. package/src/modules/enquiries/index.ts +4 -2
  424. package/src/modules/enquiries/routes.ts +11 -13
  425. package/src/modules/enquiries/schema.ts +12 -3
  426. package/src/modules/enquiries/service.ts +3 -150
  427. package/src/modules/enquiries/tools.ts +9 -18
  428. package/src/modules/forms/applyMappedFields.ts +248 -0
  429. package/src/modules/forms/applySubmissionFields.ts +435 -0
  430. package/src/modules/forms/fields.ts +31 -7
  431. package/src/modules/forms/mapping.ts +20 -3
  432. package/src/modules/forms/repository.ts +0 -7
  433. package/src/modules/forms/routes.ts +1 -2
  434. package/src/modules/forms/schema.ts +0 -2
  435. package/src/modules/forms/service.ts +31 -4
  436. package/src/modules/forms/starters.ts +129 -0
  437. package/src/modules/forms/submission.ts +135 -69
  438. package/src/modules/import-export/customFieldCsv.ts +55 -0
  439. package/src/modules/import-export/customFieldImport.ts +111 -0
  440. package/src/modules/import-export/drafts.ts +151 -3
  441. package/src/modules/import-export/exportRows.ts +222 -68
  442. package/src/modules/import-export/plan.ts +321 -67
  443. package/src/modules/import-export/repository.ts +356 -14
  444. package/src/modules/import-export/routes.ts +8 -8
  445. package/src/modules/import-export/service.ts +208 -45
  446. package/src/modules/import-export/streams.ts +95 -13
  447. package/src/modules/import-export/tools.ts +14 -6
  448. package/src/modules/import-export/validation.ts +128 -0
  449. package/src/modules/import-export/writes.ts +559 -27
  450. package/src/modules/lists/repository.ts +0 -2
  451. package/src/modules/lists/routes.ts +0 -8
  452. package/src/modules/lists/schema.ts +0 -10
  453. package/src/modules/lists/service.ts +9 -107
  454. package/src/modules/lists/starters.ts +16 -0
  455. package/src/modules/mcp/protocol.ts +18 -0
  456. package/src/modules/notes/repository.ts +24 -0
  457. package/src/modules/opportunities/events.ts +9 -0
  458. package/src/modules/opportunities/index.ts +4 -2
  459. package/src/modules/opportunities/routes.ts +11 -1
  460. package/src/modules/opportunities/schema.ts +10 -2
  461. package/src/modules/opportunities/service.ts +3 -0
  462. package/src/modules/opportunities/tools.ts +9 -1
  463. package/src/modules/partnerships/events.ts +9 -0
  464. package/src/modules/partnerships/index.ts +4 -2
  465. package/src/modules/partnerships/routes.ts +11 -1
  466. package/src/modules/partnerships/schema.ts +10 -2
  467. package/src/modules/partnerships/service.ts +3 -0
  468. package/src/modules/partnerships/tools.ts +9 -1
  469. package/src/modules/people/personConsentWrites.ts +1 -1
  470. package/src/modules/people/schema.ts +1 -1
  471. package/src/modules/plans/repository.ts +24 -0
  472. package/src/modules/raises/events.ts +9 -0
  473. package/src/modules/raises/index.ts +4 -2
  474. package/src/modules/raises/routes.ts +11 -1
  475. package/src/modules/raises/schema.ts +10 -2
  476. package/src/modules/raises/service.ts +3 -0
  477. package/src/modules/raises/tools.ts +9 -1
  478. package/src/modules/workspace/routes.ts +0 -6
  479. package/src/modules/workspace/schema.ts +0 -2
  480. package/src/modules/workspace/seedStarterForms.ts +98 -0
  481. package/src/modules/workspace/service.ts +23 -15
  482. package/src/modules/workspace/tools.ts +1 -1
  483. package/src/runtime/module.ts +70 -1
  484. package/src/runtime/registry.ts +54 -0
  485. package/src/testing/fixtures.ts +1 -0
@@ -21,6 +21,7 @@ import type { Actor } from '../auth/actor.ts'
21
21
  import { actorMemberId, requireWorkspaceId } from '../auth/actor.ts'
22
22
  import './events.ts'
23
23
  import { deleteRecordsAttachedTo } from '../attachedRecords.ts'
24
+ import { clearConversionPointersToTarget } from '../conversions/clearPointers.ts'
24
25
  import * as companyRepository from '../companies/repository.ts'
25
26
  import type { CustomFieldValuesValidator } from '../custom-fields/values.ts'
26
27
  import * as personLinks from '../personLinks.ts'
@@ -488,6 +489,8 @@ export function createDealsService(dependencies: DealsDependencies): DealsServic
488
489
  await dependencies.transaction(async ({ tx, events }) => {
489
490
  await require(workspaceId, id)
490
491
 
492
+ await clearConversionPointersToTarget(tx, workspaceId, 'deal', id)
493
+
491
494
  // Form submissions unlink themselves through `set null`; notes,
492
495
  // activities, decisions, plan items, and person_links have no key back
493
496
  // to the deal, so they are removed here, in the same transaction.
@@ -2,6 +2,8 @@ import { z } from 'zod'
2
2
 
3
3
  import type { McpToolRegistry } from '../../runtime/module.ts'
4
4
  import { idArg, idSetArg, listWindowShape, registerCrudTools, termArg, toSet } from '../crudTools.ts'
5
+ import type { ConversionsService } from '../conversions/index.ts'
6
+ import { registerPipelineConvertTool } from '../conversions/mcp.ts'
5
7
  import { createBody, dealResponse, toCreateInput, toUpdateInput, updateBody } from './routes.ts'
6
8
  import type { DealsService } from './service.ts'
7
9
 
@@ -15,7 +17,11 @@ const listArgs = z.strictObject({
15
17
  person_id: idSetArg.optional().describe('Only deals one of these people is a contact on.'),
16
18
  })
17
19
 
18
- export function registerDealsTools(mcp: McpToolRegistry, service: DealsService): void {
20
+ export function registerDealsTools(
21
+ mcp: McpToolRegistry,
22
+ service: DealsService,
23
+ conversions: ConversionsService,
24
+ ): void {
19
25
  registerCrudTools(mcp, {
20
26
  resource: 'deals',
21
27
  subject: 'deal',
@@ -36,4 +42,6 @@ export function registerDealsTools(mcp: McpToolRegistry, service: DealsService):
36
42
  updateArgs: updateBody.extend({ id: idArg }),
37
43
  toUpdateInput,
38
44
  })
45
+
46
+ registerPipelineConvertTool(mcp, conversions, 'deal')
39
47
  }
@@ -191,7 +191,29 @@ export async function deleteForTarget(
191
191
  return deleted.length
192
192
  }
193
193
 
194
- /** Whether a member belongs to this workspace, for validating `owner_id`. */
194
+ /** Moves every decision from one target to another inside a conversion transaction. */
195
+ export async function repointForTarget(
196
+ db: Queryable,
197
+ workspaceId: string,
198
+ fromType: string,
199
+ fromId: string,
200
+ toType: string,
201
+ toId: string,
202
+ ): Promise<number> {
203
+ const updated = await db
204
+ .update(decisions)
205
+ .set({ targetType: toType, targetId: toId })
206
+ .where(
207
+ and(
208
+ eq(decisions.workspaceId, workspaceId),
209
+ eq(decisions.targetType, fromType),
210
+ eq(decisions.targetId, fromId),
211
+ ),
212
+ )
213
+ .returning({ id: decisions.id })
214
+
215
+ return updated.length
216
+ }
195
217
  export async function memberExists(
196
218
  db: Queryable,
197
219
  workspaceId: string,
@@ -18,7 +18,11 @@ export const enquiriesEvents = {
18
18
  * outside Kelpie subscribe to `record.created` on the deal instead. Kept for
19
19
  * internal listeners that want the semantic signal.
20
20
  */
21
- 'enquiries.enquiry.converted': z.object({ dealId: z.string() }),
21
+ 'enquiries.enquiry.converted': z.object({
22
+ dealId: z.string().optional(),
23
+ targetType: z.string(),
24
+ targetId: z.string(),
25
+ }),
22
26
  } satisfies ModuleEventCatalog
23
27
 
24
28
  export type EnquiryCreatedData = Record<string, never>
@@ -31,7 +35,9 @@ export interface EnquiryStageChangedData {
31
35
  readonly toStageId: string
32
36
  }
33
37
  export interface EnquiryConvertedData {
34
- readonly dealId: string
38
+ readonly dealId?: string | undefined
39
+ readonly targetType: string
40
+ readonly targetId: string
35
41
  }
36
42
 
37
43
  declare module '../../runtime/events.ts' {
@@ -1,5 +1,6 @@
1
1
  import type { KelpieModule } from '../../runtime/module.ts'
2
2
  import { createActivityRecorder } from '../activities/index.ts'
3
+ import { createConversionsFromContext } from '../conversions/index.ts'
3
4
  import { createCustomFieldValues } from '../custom-fields/index.ts'
4
5
  import { enquiriesEvents } from './events.ts'
5
6
  import { mountEnquiriesRoutes } from './routes.ts'
@@ -24,6 +25,7 @@ export function createEnquiriesModule(migrationsDirectory: string): KelpieModule
24
25
  events: enquiriesEvents,
25
26
 
26
27
  register(context) {
28
+ const conversions = createConversionsFromContext(context)
27
29
  const service = createEnquiriesService({
28
30
  db: context.db,
29
31
  transaction: context.transaction,
@@ -39,10 +41,10 @@ export function createEnquiriesModule(migrationsDirectory: string): KelpieModule
39
41
  context.schema(schema, migrationsDirectory)
40
42
 
41
43
  context.routes((router) => {
42
- mountEnquiriesRoutes(router, { db: context.db, now: context.now, service })
44
+ mountEnquiriesRoutes(router, { db: context.db, now: context.now, service, conversions })
43
45
  })
44
46
 
45
- registerEnquiriesTools(context.mcp, service)
47
+ registerEnquiriesTools(context.mcp, service, conversions)
46
48
 
47
49
  return Promise.resolve()
48
50
  },
@@ -1,4 +1,4 @@
1
- import { customFieldsPatchShape } from '@kelpie/schemas'
1
+ import { convertEnquiryBody, convertedToResponse, customFieldsPatchShape } from '@kelpie/schemas'
2
2
  import type { Context, Hono } from 'hono'
3
3
  import { z } from 'zod'
4
4
 
@@ -7,7 +7,8 @@ import type { Actor } from '../auth/actor.ts'
7
7
  import { resolveActorFrom } from '../auth/credentials.ts'
8
8
  import type { CredentialDependencies } from '../auth/credentials.ts'
9
9
  import { renderCustomFieldsForWire } from '../custom-fields/wire.ts'
10
- import { dealResponse } from '../deals/routes.ts'
10
+ import { mountPipelineConvertRoute } from '../conversions/routes.ts'
11
+ import type { ConversionsService } from '../conversions/index.ts'
11
12
  import type { CreateEnquiryInput, EnquiriesService, EnquiryView, UpdateEnquiryInput } from './service.ts'
12
13
 
13
14
  /** Wire shapes for `/v1/enquiries`. Bodies are strict; an unknown field is a 422, per `api.md`. */
@@ -52,6 +53,7 @@ export const updateBody = z.strictObject(enquiryShape).partial()
52
53
 
53
54
  export interface EnquiriesRoutesDependencies extends CredentialDependencies {
54
55
  readonly service: EnquiriesService
56
+ readonly conversions: ConversionsService
55
57
  }
56
58
 
57
59
  export function toCreateInput(body: z.infer<typeof createBody>): CreateEnquiryInput {
@@ -91,6 +93,7 @@ export function enquiryResponse(enquiry: EnquiryView): Record<string, unknown> {
91
93
  company_id: enquiry.companyId,
92
94
  owner_id: enquiry.ownerId,
93
95
  converted_deal_id: enquiry.convertedDealId,
96
+ converted_to: convertedToResponse(enquiry.convertedTargetType, enquiry.convertedTargetId),
94
97
  person_ids: enquiry.personIds,
95
98
  summary: enquiry.summary,
96
99
  tags: enquiry.tags,
@@ -156,17 +159,12 @@ export function mountEnquiriesRoutes(
156
159
  })
157
160
 
158
161
  /**
159
- * Convert an enquiry to a deal. Idempotent-ish: a second call 409s and
160
- * carries the existing deal id in `details`. Returns the freshly created
161
- * deal, wire-shaped, so the caller can navigate straight to it.
162
+ * Convert an enquiry to another pipeline record type. An empty body defaults
163
+ * the target to a deal for backward compatibility.
162
164
  */
163
- router.post('/enquiries/:id/convert', async (context) => {
164
- const { deal, personIds } = await dependencies.service.convertToDeal(
165
- await requireActor(context),
166
- context.req.param('id'),
167
- )
168
- const { workspaceId: _workspaceId, ...dealView } = deal
169
-
170
- return context.json(dealResponse({ ...dealView, personIds }), 201)
165
+ mountPipelineConvertRoute(router, '/enquiries/:id/convert', {
166
+ ...dependencies,
167
+ sourceKind: 'enquiry',
168
+ bodySchema: convertEnquiryBody,
171
169
  })
172
170
  }
@@ -1,7 +1,9 @@
1
+ import { sql } from 'drizzle-orm'
2
+ import { check, index, jsonb, pgTable, text } from 'drizzle-orm/pg-core'
3
+ import { PIPELINE_KINDS } from '@kelpie/schemas'
1
4
  import type { CustomFieldValue } from '@kelpie/schemas'
2
- import { index, jsonb, pgTable, text } from 'drizzle-orm/pg-core'
3
5
 
4
- import { createdAt, primaryId, searchVector, updatedAt } from '../../lib/columns.ts'
6
+ import { createdAt, oneOf, primaryId, searchVector, updatedAt } from '../../lib/columns.ts'
5
7
  import type { SearchVectorPart } from '../../lib/columns.ts'
6
8
  import { companies } from '../companies/schema.ts'
7
9
  import { deals } from '../deals/schema.ts'
@@ -17,7 +19,8 @@ import { workspaceMembers, workspaces } from '../workspace/schema.ts'
17
19
  * enquiry may arrive before a company is on file. `converted_deal_id` becomes
18
20
  * non-null when the enquiry is converted via
19
21
  * `POST /v1/enquiries/:id/convert`; deleting the deal nulls it back so a
20
- * fresh conversion is possible.
22
+ * fresh conversion is possible. `converted_target_*` generalises that pointer
23
+ * to any pipeline type.
21
24
  */
22
25
  export const enquiries = pgTable(
23
26
  'enquiries',
@@ -34,6 +37,8 @@ export const enquiries = pgTable(
34
37
  companyId: text('company_id').references(() => companies.id, { onDelete: 'restrict' }),
35
38
  ownerId: text('owner_id').references(() => workspaceMembers.id, { onDelete: 'restrict' }),
36
39
  convertedDealId: text('converted_deal_id').references(() => deals.id, { onDelete: 'set null' }),
40
+ convertedTargetType: text('converted_target_type'),
41
+ convertedTargetId: text('converted_target_id'),
37
42
  summary: text('summary').notNull().default(''),
38
43
  tags: text('tags').array().notNull().default([]),
39
44
  // Workspace-defined fields, keyed by definition key. See people/schema.ts.
@@ -55,5 +60,9 @@ export const enquiries = pgTable(
55
60
  index('enquiries_stage_idx').on(table.stageId),
56
61
  index('enquiries_converted_deal_idx').on(table.convertedDealId),
57
62
  index('enquiries_search_idx').using('gin', table.searchVector),
63
+ check(
64
+ 'enquiries_converted_target_type_check',
65
+ sql`${table.convertedTargetType} is null or ${oneOf('enquiries_converted_target_type_check', table.convertedTargetType, PIPELINE_KINDS)}`,
66
+ ),
58
67
  ],
59
68
  )
@@ -9,9 +9,7 @@ import type { ListQueryParameters, Page } from '../../lib/pagination.ts'
9
9
  import type { TransactionScope } from '../../runtime/transaction.ts'
10
10
  import type { ActivityRecorder } from '../activities/recorder.ts'
11
11
  import {
12
- describeConversion,
13
12
  describeCreation,
14
- describeCreationFrom,
15
13
  describeLink,
16
14
  describeStageChange,
17
15
  describeUnlink,
@@ -22,12 +20,10 @@ import { toEventActor } from '../../lib/actor.ts'
22
20
  import type { Actor } from '../auth/actor.ts'
23
21
  import { actorMemberId, requireWorkspaceId } from '../auth/actor.ts'
24
22
  import './events.ts'
25
- import '../deals/events.ts'
26
23
  import { deleteRecordsAttachedTo } from '../attachedRecords.ts'
24
+ import { clearConversionPointersToTarget } from '../conversions/clearPointers.ts'
27
25
  import * as companyRepository from '../companies/repository.ts'
28
26
  import type { CustomFieldValuesValidator } from '../custom-fields/values.ts'
29
- import * as dealRepository from '../deals/repository.ts'
30
- import type { DealRecord } from '../deals/repository.ts'
31
27
  import * as personLinks from '../personLinks.ts'
32
28
  import * as pipelineRepository from '../pipelines/repository.ts'
33
29
  import type { PipelineStageRecord } from '../pipelines/repository.ts'
@@ -108,12 +104,6 @@ export interface UpdateEnquiryInput {
108
104
  readonly customFields?: Readonly<Record<string, CustomFieldWireValue | null>> | undefined
109
105
  }
110
106
 
111
- /** What `convertToDeal` returns: the freshly created deal, plus its people. */
112
- export interface ConvertedDealView {
113
- readonly deal: DealRecord
114
- readonly personIds: readonly string[]
115
- }
116
-
117
107
  export interface EnquiriesService {
118
108
  list(
119
109
  actor: Actor,
@@ -124,7 +114,6 @@ export interface EnquiriesService {
124
114
  create(actor: Actor, input: CreateEnquiryInput): Promise<EnquiryView>
125
115
  update(actor: Actor, id: string, changes: UpdateEnquiryInput): Promise<EnquiryView>
126
116
  remove(actor: Actor, id: string): Promise<void>
127
- convertToDeal(actor: Actor, id: string): Promise<ConvertedDealView>
128
117
  }
129
118
 
130
119
  function toView(record: EnquiryRecord, personIds: readonly string[]): EnquiryView {
@@ -492,6 +481,8 @@ export function createEnquiriesService(dependencies: EnquiriesDependencies): Enq
492
481
  await dependencies.transaction(async ({ tx, events }) => {
493
482
  await require(workspaceId, id)
494
483
 
484
+ await clearConversionPointersToTarget(tx, workspaceId, 'enquiry', id)
485
+
495
486
  // Notes, activities, decisions, plan items, person_links, list
496
487
  // memberships and form_attach_targets rows are removed here in the
497
488
  // same transaction. `form_submissions.enquiry_id` is a set-null FK, so
@@ -502,143 +493,5 @@ export function createEnquiriesService(dependencies: EnquiriesDependencies): Enq
502
493
  events.emit('enquiries.enquiry.deleted', { type: 'enquiry', id }, {})
503
494
  }, { workspaceId, actor: toEventActor(actor) })
504
495
  },
505
-
506
- async convertToDeal(actor, id) {
507
- const workspaceId = requireWorkspaceId(actor)
508
- const existing = await require(workspaceId, id)
509
-
510
- if (existing.convertedDealId !== null) {
511
- throw new AppError(
512
- 'conflict',
513
- 'This enquiry has already been converted to a deal',
514
- [{ field: 'converted_deal_id', message: `Deal ${existing.convertedDealId}` }],
515
- )
516
- }
517
-
518
- if (existing.companyId === null) {
519
- throw AppError.validationFailed('An enquiry needs a company before it can become a deal', [
520
- { field: 'company_id', message: 'Link a company to the enquiry first' },
521
- ])
522
- }
523
-
524
- const dealStages = await pipelineRepository.listStagesOfKind(
525
- dependencies.db,
526
- workspaceId,
527
- 'deal',
528
- )
529
- const openDealStage = dealStages.find((row) => row.open) ?? dealStages[0]
530
-
531
- if (openDealStage === undefined) {
532
- // Unreachable through the API: workspaces seed stages and the last
533
- // deal stage cannot be removed.
534
- throw AppError.conflict('This workspace has no deal stages')
535
- }
536
-
537
- const enquiryStages = await pipelineRepository.listStagesOfKind(
538
- dependencies.db,
539
- workspaceId,
540
- 'enquiry',
541
- )
542
- // A closed enquiry stage is where a converted enquiry lands. If the
543
- // workspace has deleted every closed stage we leave the enquiry where it
544
- // is rather than refuse the conversion over board cosmetics.
545
- const closedEnquiryStage = enquiryStages.find((row) => !row.open)
546
-
547
- const personIds = await personLinks.listPersonIds(dependencies.db, workspaceId, {
548
- targetType: 'enquiry',
549
- targetId: id,
550
- })
551
- const dealId = dependencies.createId('deal')
552
- const now = dependencies.now()
553
-
554
- return dependencies.transaction(async ({ tx, events }) => {
555
- const deal = await dealRepository.insertDeal(tx, {
556
- id: dealId,
557
- workspaceId,
558
- name: existing.name,
559
- companyId: existing.companyId as string,
560
- stageId: openDealStage.id,
561
- valueCents: null,
562
- currency: null,
563
- ownerId: existing.ownerId,
564
- expectedClose: null,
565
- competitors: [],
566
- risks: '',
567
- whyWin: '',
568
- summary: existing.summary,
569
- tags: [...existing.tags],
570
- externalId: null,
571
- customFields: {},
572
- })
573
-
574
- await personLinks.linkPeople(
575
- tx,
576
- dependencies.createId,
577
- workspaceId,
578
- { targetType: 'deal', targetId: dealId },
579
- personIds,
580
- )
581
-
582
- const stageChanged =
583
- closedEnquiryStage !== undefined && closedEnquiryStage.id !== existing.stageId
584
- const currentEnquiryStage = enquiryStages.find((row) => row.id === existing.stageId)
585
-
586
- const updatedEnquiry = await repository.updateEnquiry(tx, workspaceId, id, {
587
- convertedDealId: dealId,
588
- ...(stageChanged ? { stageId: closedEnquiryStage.id } : {}),
589
- updatedAt: now,
590
- })
591
-
592
- if (updatedEnquiry === undefined) {
593
- throw AppError.notFound('Enquiry not found')
594
- }
595
-
596
- await dependencies.recordActivity(tx, workspaceId, actor, {
597
- targetType: 'deal',
598
- targetId: dealId,
599
- kind: 'created',
600
- ...describeCreationFrom('Deal', 'Enquiry', existing.name),
601
- })
602
-
603
- await dependencies.recordActivity(tx, workspaceId, actor, {
604
- targetType: 'enquiry',
605
- targetId: id,
606
- kind: 'updated',
607
- ...describeConversion('Deal', deal.name),
608
- })
609
-
610
- if (stageChanged && currentEnquiryStage !== undefined) {
611
- await dependencies.recordActivity(tx, workspaceId, actor, {
612
- targetType: 'enquiry',
613
- targetId: id,
614
- kind: 'stage_changed',
615
- ...describeStageChange(currentEnquiryStage.label, closedEnquiryStage.label),
616
- })
617
- }
618
-
619
- events.emit('deals.deal.created', { type: 'deal', id: dealId }, {})
620
- events.emit(
621
- 'enquiries.enquiry.updated',
622
- { type: 'enquiry', id },
623
- {
624
- changed: stageChanged
625
- ? ['convertedDealId', 'stageId']
626
- : ['convertedDealId'],
627
- },
628
- )
629
-
630
- if (stageChanged && currentEnquiryStage !== undefined) {
631
- events.emit(
632
- 'enquiries.enquiry.stage_changed',
633
- { type: 'enquiry', id },
634
- { fromStageId: currentEnquiryStage.id, toStageId: closedEnquiryStage.id },
635
- )
636
- }
637
-
638
- events.emit('enquiries.enquiry.converted', { type: 'enquiry', id }, { dealId })
639
-
640
- return { deal, personIds }
641
- }, { workspaceId, actor: toEventActor(actor) })
642
- },
643
496
  }
644
497
  }
@@ -9,7 +9,8 @@ import {
9
9
  termArg,
10
10
  toSet,
11
11
  } from '../crudTools.ts'
12
- import { dealResponse } from '../deals/routes.ts'
12
+ import type { ConversionsService } from '../conversions/index.ts'
13
+ import { registerEnquiryConvertToDealTool, registerPipelineConvertTool } from '../conversions/mcp.ts'
13
14
  import { createBody, enquiryResponse, toCreateInput, toUpdateInput, updateBody } from './routes.ts'
14
15
  import type { EnquiriesService } from './service.ts'
15
16
 
@@ -24,7 +25,11 @@ const listArgs = z.strictObject({
24
25
  person_id: idSetArg.optional().describe('Only enquiries any of these people are on.'),
25
26
  })
26
27
 
27
- export function registerEnquiriesTools(mcp: McpToolRegistry, service: EnquiriesService): void {
28
+ export function registerEnquiriesTools(
29
+ mcp: McpToolRegistry,
30
+ service: EnquiriesService,
31
+ conversions: ConversionsService,
32
+ ): void {
28
33
  registerCrudTools(mcp, {
29
34
  resource: 'enquiries',
30
35
  subject: 'enquiry',
@@ -47,20 +52,6 @@ export function registerEnquiriesTools(mcp: McpToolRegistry, service: EnquiriesS
47
52
  toUpdateInput,
48
53
  })
49
54
 
50
- mcp.tool({
51
- name: 'enquiries_convert_to_deal',
52
- description:
53
- 'Convert an enquiry to a Deal. Copies name, company, owner and linked ' +
54
- 'people to a new deal in the first open deal stage, moves the enquiry ' +
55
- 'to its first closed stage, and records the link on the enquiry. 409 if ' +
56
- 'the enquiry has already been converted; 422 if it has no company. ' +
57
- 'Mirrors POST /v1/enquiries/{id}/convert.',
58
- inputSchema: z.strictObject({ id: idArg }),
59
- invoke: async ({ id }, actor) => {
60
- const { deal, personIds } = await service.convertToDeal(actor, id)
61
- const { workspaceId: _workspaceId, ...dealView } = deal
62
-
63
- return dealResponse({ ...dealView, personIds })
64
- },
65
- })
55
+ registerPipelineConvertTool(mcp, conversions, 'enquiry')
56
+ registerEnquiryConvertToDealTool(mcp, conversions)
66
57
  }