@kelpie/server 0.9.0 → 0.11.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 (449) 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 +2 -0
  5. package/dist/index.d.ts.map +1 -1
  6. package/dist/index.js +1 -0
  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/modules/activities/repository.d.ts +2 -0
  16. package/dist/modules/activities/repository.d.ts.map +1 -1
  17. package/dist/modules/activities/repository.js +9 -0
  18. package/dist/modules/activities/repository.js.map +1 -1
  19. package/dist/modules/agent-tasks/repository.d.ts +2 -0
  20. package/dist/modules/agent-tasks/repository.d.ts.map +1 -1
  21. package/dist/modules/agent-tasks/repository.js +9 -0
  22. package/dist/modules/agent-tasks/repository.js.map +1 -1
  23. package/dist/modules/api-keys/routes.d.ts.map +1 -1
  24. package/dist/modules/api-keys/routes.js +4 -1
  25. package/dist/modules/api-keys/routes.js.map +1 -1
  26. package/dist/modules/api-keys/schema.d.ts +43 -0
  27. package/dist/modules/api-keys/schema.d.ts.map +1 -1
  28. package/dist/modules/api-keys/schema.js +2 -0
  29. package/dist/modules/api-keys/schema.js.map +1 -1
  30. package/dist/modules/api-keys/scopeMiddleware.d.ts +8 -0
  31. package/dist/modules/api-keys/scopeMiddleware.d.ts.map +1 -0
  32. package/dist/modules/api-keys/scopeMiddleware.js +21 -0
  33. package/dist/modules/api-keys/scopeMiddleware.js.map +1 -0
  34. package/dist/modules/api-keys/service.d.ts +3 -1
  35. package/dist/modules/api-keys/service.d.ts.map +1 -1
  36. package/dist/modules/api-keys/service.js +26 -1
  37. package/dist/modules/api-keys/service.js.map +1 -1
  38. package/dist/modules/auth/credentials.d.ts.map +1 -1
  39. package/dist/modules/auth/credentials.js +2 -0
  40. package/dist/modules/auth/credentials.js.map +1 -1
  41. package/dist/modules/consent-purposes/index.d.ts +1 -1
  42. package/dist/modules/consent-purposes/index.js +1 -1
  43. package/dist/modules/consent-purposes/schema.d.ts +3 -3
  44. package/dist/modules/consent-purposes/schema.js +3 -3
  45. package/dist/modules/consent-purposes/service.d.ts +1 -1
  46. package/dist/modules/consent-purposes/service.d.ts.map +1 -1
  47. package/dist/modules/consent-purposes/service.js +7 -16
  48. package/dist/modules/consent-purposes/service.js.map +1 -1
  49. package/dist/modules/consent-purposes/starters.d.ts +1 -1
  50. package/dist/modules/consent-purposes/tools.js +1 -1
  51. package/dist/modules/consent-purposes/tools.js.map +1 -1
  52. package/dist/modules/conversions/clearPointers.d.ts +10 -0
  53. package/dist/modules/conversions/clearPointers.d.ts.map +1 -0
  54. package/dist/modules/conversions/clearPointers.js +40 -0
  55. package/dist/modules/conversions/clearPointers.js.map +1 -0
  56. package/dist/modules/conversions/factory.d.ts +5 -0
  57. package/dist/modules/conversions/factory.d.ts.map +1 -0
  58. package/dist/modules/conversions/factory.js +18 -0
  59. package/dist/modules/conversions/factory.js.map +1 -0
  60. package/dist/modules/conversions/fieldMap.d.ts +55 -0
  61. package/dist/modules/conversions/fieldMap.d.ts.map +1 -0
  62. package/dist/modules/conversions/fieldMap.js +398 -0
  63. package/dist/modules/conversions/fieldMap.js.map +1 -0
  64. package/dist/modules/conversions/index.d.ts +7 -0
  65. package/dist/modules/conversions/index.d.ts.map +1 -0
  66. package/dist/modules/conversions/index.js +6 -0
  67. package/dist/modules/conversions/index.js.map +1 -0
  68. package/dist/modules/conversions/mcp.d.ts +7 -0
  69. package/dist/modules/conversions/mcp.d.ts.map +1 -0
  70. package/dist/modules/conversions/mcp.js +47 -0
  71. package/dist/modules/conversions/mcp.js.map +1 -0
  72. package/dist/modules/conversions/repoint.d.ts +19 -0
  73. package/dist/modules/conversions/repoint.d.ts.map +1 -0
  74. package/dist/modules/conversions/repoint.js +51 -0
  75. package/dist/modules/conversions/repoint.js.map +1 -0
  76. package/dist/modules/conversions/routes.d.ts +26 -0
  77. package/dist/modules/conversions/routes.d.ts.map +1 -0
  78. package/dist/modules/conversions/routes.js +23 -0
  79. package/dist/modules/conversions/routes.js.map +1 -0
  80. package/dist/modules/conversions/service.d.ts +28 -0
  81. package/dist/modules/conversions/service.d.ts.map +1 -0
  82. package/dist/modules/conversions/service.js +170 -0
  83. package/dist/modules/conversions/service.js.map +1 -0
  84. package/dist/modules/conversions/wire.d.ts +4 -0
  85. package/dist/modules/conversions/wire.d.ts.map +1 -0
  86. package/dist/modules/conversions/wire.js +28 -0
  87. package/dist/modules/conversions/wire.js.map +1 -0
  88. package/dist/modules/deals/events.d.ts +9 -0
  89. package/dist/modules/deals/events.d.ts.map +1 -1
  90. package/dist/modules/deals/events.js +4 -0
  91. package/dist/modules/deals/events.js.map +1 -1
  92. package/dist/modules/deals/index.d.ts.map +1 -1
  93. package/dist/modules/deals/index.js +4 -2
  94. package/dist/modules/deals/index.js.map +1 -1
  95. package/dist/modules/deals/routes.d.ts +2 -0
  96. package/dist/modules/deals/routes.d.ts.map +1 -1
  97. package/dist/modules/deals/routes.js +8 -1
  98. package/dist/modules/deals/routes.js.map +1 -1
  99. package/dist/modules/deals/schema.d.ts +34 -0
  100. package/dist/modules/deals/schema.d.ts.map +1 -1
  101. package/dist/modules/deals/schema.js +7 -2
  102. package/dist/modules/deals/schema.js.map +1 -1
  103. package/dist/modules/deals/service.d.ts.map +1 -1
  104. package/dist/modules/deals/service.js +2 -0
  105. package/dist/modules/deals/service.js.map +1 -1
  106. package/dist/modules/deals/tools.d.ts +2 -1
  107. package/dist/modules/deals/tools.d.ts.map +1 -1
  108. package/dist/modules/deals/tools.js +3 -1
  109. package/dist/modules/deals/tools.js.map +1 -1
  110. package/dist/modules/decisions/repository.d.ts +2 -1
  111. package/dist/modules/decisions/repository.d.ts.map +1 -1
  112. package/dist/modules/decisions/repository.js +9 -1
  113. package/dist/modules/decisions/repository.js.map +1 -1
  114. package/dist/modules/enquiries/events.d.ts +6 -2
  115. package/dist/modules/enquiries/events.d.ts.map +1 -1
  116. package/dist/modules/enquiries/events.js +5 -1
  117. package/dist/modules/enquiries/events.js.map +1 -1
  118. package/dist/modules/enquiries/index.d.ts.map +1 -1
  119. package/dist/modules/enquiries/index.js +4 -2
  120. package/dist/modules/enquiries/index.js.map +1 -1
  121. package/dist/modules/enquiries/routes.d.ts +2 -0
  122. package/dist/modules/enquiries/routes.d.ts.map +1 -1
  123. package/dist/modules/enquiries/routes.js +9 -9
  124. package/dist/modules/enquiries/routes.js.map +1 -1
  125. package/dist/modules/enquiries/schema.d.ts +36 -1
  126. package/dist/modules/enquiries/schema.d.ts.map +1 -1
  127. package/dist/modules/enquiries/schema.js +9 -3
  128. package/dist/modules/enquiries/schema.js.map +1 -1
  129. package/dist/modules/enquiries/service.d.ts +0 -8
  130. package/dist/modules/enquiries/service.d.ts.map +1 -1
  131. package/dist/modules/enquiries/service.js +3 -95
  132. package/dist/modules/enquiries/service.js.map +1 -1
  133. package/dist/modules/enquiries/tools.d.ts +2 -1
  134. package/dist/modules/enquiries/tools.d.ts.map +1 -1
  135. package/dist/modules/enquiries/tools.js +4 -16
  136. package/dist/modules/enquiries/tools.js.map +1 -1
  137. package/dist/modules/forms/applyMappedFields.d.ts +20 -0
  138. package/dist/modules/forms/applyMappedFields.d.ts.map +1 -0
  139. package/dist/modules/forms/applyMappedFields.js +169 -0
  140. package/dist/modules/forms/applyMappedFields.js.map +1 -0
  141. package/dist/modules/forms/applySubmissionFields.d.ts +18 -0
  142. package/dist/modules/forms/applySubmissionFields.d.ts.map +1 -0
  143. package/dist/modules/forms/applySubmissionFields.js +230 -0
  144. package/dist/modules/forms/applySubmissionFields.js.map +1 -0
  145. package/dist/modules/forms/fields.d.ts +7 -2
  146. package/dist/modules/forms/fields.d.ts.map +1 -1
  147. package/dist/modules/forms/fields.js +17 -6
  148. package/dist/modules/forms/fields.js.map +1 -1
  149. package/dist/modules/forms/mapping.d.ts +8 -2
  150. package/dist/modules/forms/mapping.d.ts.map +1 -1
  151. package/dist/modules/forms/mapping.js +11 -0
  152. package/dist/modules/forms/mapping.js.map +1 -1
  153. package/dist/modules/forms/repository.d.ts +0 -5
  154. package/dist/modules/forms/repository.d.ts.map +1 -1
  155. package/dist/modules/forms/repository.js +0 -2
  156. package/dist/modules/forms/repository.js.map +1 -1
  157. package/dist/modules/forms/routes.d.ts +2 -30
  158. package/dist/modules/forms/routes.d.ts.map +1 -1
  159. package/dist/modules/forms/routes.js +2 -2
  160. package/dist/modules/forms/routes.js.map +1 -1
  161. package/dist/modules/forms/schema.d.ts.map +1 -1
  162. package/dist/modules/forms/schema.js +1 -2
  163. package/dist/modules/forms/schema.js.map +1 -1
  164. package/dist/modules/forms/service.d.ts.map +1 -1
  165. package/dist/modules/forms/service.js +18 -3
  166. package/dist/modules/forms/service.js.map +1 -1
  167. package/dist/modules/forms/starters.d.ts +31 -0
  168. package/dist/modules/forms/starters.d.ts.map +1 -0
  169. package/dist/modules/forms/starters.js +94 -0
  170. package/dist/modules/forms/starters.js.map +1 -0
  171. package/dist/modules/forms/submission.d.ts +1 -0
  172. package/dist/modules/forms/submission.d.ts.map +1 -1
  173. package/dist/modules/forms/submission.js +58 -37
  174. package/dist/modules/forms/submission.js.map +1 -1
  175. package/dist/modules/import-export/customFieldCsv.d.ts +9 -0
  176. package/dist/modules/import-export/customFieldCsv.d.ts.map +1 -0
  177. package/dist/modules/import-export/customFieldCsv.js +39 -0
  178. package/dist/modules/import-export/customFieldCsv.js.map +1 -0
  179. package/dist/modules/import-export/customFieldImport.d.ts +19 -0
  180. package/dist/modules/import-export/customFieldImport.d.ts.map +1 -0
  181. package/dist/modules/import-export/customFieldImport.js +76 -0
  182. package/dist/modules/import-export/customFieldImport.js.map +1 -0
  183. package/dist/modules/import-export/drafts.d.ts +57 -3
  184. package/dist/modules/import-export/drafts.d.ts.map +1 -1
  185. package/dist/modules/import-export/drafts.js +65 -3
  186. package/dist/modules/import-export/drafts.js.map +1 -1
  187. package/dist/modules/import-export/exportRows.d.ts +15 -13
  188. package/dist/modules/import-export/exportRows.d.ts.map +1 -1
  189. package/dist/modules/import-export/exportRows.js +99 -26
  190. package/dist/modules/import-export/exportRows.js.map +1 -1
  191. package/dist/modules/import-export/plan.d.ts +42 -11
  192. package/dist/modules/import-export/plan.d.ts.map +1 -1
  193. package/dist/modules/import-export/plan.js +198 -56
  194. package/dist/modules/import-export/plan.js.map +1 -1
  195. package/dist/modules/import-export/repository.d.ts +58 -2
  196. package/dist/modules/import-export/repository.d.ts.map +1 -1
  197. package/dist/modules/import-export/repository.js +201 -12
  198. package/dist/modules/import-export/repository.js.map +1 -1
  199. package/dist/modules/import-export/routes.d.ts.map +1 -1
  200. package/dist/modules/import-export/routes.js +5 -5
  201. package/dist/modules/import-export/routes.js.map +1 -1
  202. package/dist/modules/import-export/service.d.ts +8 -3
  203. package/dist/modules/import-export/service.d.ts.map +1 -1
  204. package/dist/modules/import-export/service.js +133 -40
  205. package/dist/modules/import-export/service.js.map +1 -1
  206. package/dist/modules/import-export/streams.d.ts +2 -2
  207. package/dist/modules/import-export/streams.d.ts.map +1 -1
  208. package/dist/modules/import-export/streams.js +50 -9
  209. package/dist/modules/import-export/streams.js.map +1 -1
  210. package/dist/modules/import-export/tools.d.ts.map +1 -1
  211. package/dist/modules/import-export/tools.js +13 -7
  212. package/dist/modules/import-export/tools.js.map +1 -1
  213. package/dist/modules/import-export/validation.d.ts +5 -1
  214. package/dist/modules/import-export/validation.d.ts.map +1 -1
  215. package/dist/modules/import-export/validation.js +89 -2
  216. package/dist/modules/import-export/validation.js.map +1 -1
  217. package/dist/modules/import-export/writes.d.ts +2 -1
  218. package/dist/modules/import-export/writes.d.ts.map +1 -1
  219. package/dist/modules/import-export/writes.js +358 -25
  220. package/dist/modules/import-export/writes.js.map +1 -1
  221. package/dist/modules/lists/index.d.ts +38 -0
  222. package/dist/modules/lists/index.d.ts.map +1 -1
  223. package/dist/modules/lists/index.js +27 -0
  224. package/dist/modules/lists/index.js.map +1 -1
  225. package/dist/modules/lists/repository.d.ts +15 -1
  226. package/dist/modules/lists/repository.d.ts.map +1 -1
  227. package/dist/modules/lists/repository.js +19 -1
  228. package/dist/modules/lists/repository.js.map +1 -1
  229. package/dist/modules/lists/routes.d.ts +0 -2
  230. package/dist/modules/lists/routes.d.ts.map +1 -1
  231. package/dist/modules/lists/routes.js +0 -8
  232. package/dist/modules/lists/routes.js.map +1 -1
  233. package/dist/modules/lists/schema.d.ts +0 -17
  234. package/dist/modules/lists/schema.d.ts.map +1 -1
  235. package/dist/modules/lists/schema.js +0 -10
  236. package/dist/modules/lists/schema.js.map +1 -1
  237. package/dist/modules/lists/service.d.ts +2 -14
  238. package/dist/modules/lists/service.d.ts.map +1 -1
  239. package/dist/modules/lists/service.js +7 -53
  240. package/dist/modules/lists/service.js.map +1 -1
  241. package/dist/modules/lists/starters.d.ts +12 -0
  242. package/dist/modules/lists/starters.d.ts.map +1 -0
  243. package/dist/modules/lists/starters.js +4 -0
  244. package/dist/modules/lists/starters.js.map +1 -0
  245. package/dist/modules/mcp/protocol.d.ts.map +1 -1
  246. package/dist/modules/mcp/protocol.js +13 -0
  247. package/dist/modules/mcp/protocol.js.map +1 -1
  248. package/dist/modules/notes/repository.d.ts +2 -0
  249. package/dist/modules/notes/repository.d.ts.map +1 -1
  250. package/dist/modules/notes/repository.js +9 -0
  251. package/dist/modules/notes/repository.js.map +1 -1
  252. package/dist/modules/opportunities/events.d.ts +9 -0
  253. package/dist/modules/opportunities/events.d.ts.map +1 -1
  254. package/dist/modules/opportunities/events.js +4 -0
  255. package/dist/modules/opportunities/events.js.map +1 -1
  256. package/dist/modules/opportunities/index.d.ts.map +1 -1
  257. package/dist/modules/opportunities/index.js +4 -2
  258. package/dist/modules/opportunities/index.js.map +1 -1
  259. package/dist/modules/opportunities/routes.d.ts +2 -0
  260. package/dist/modules/opportunities/routes.d.ts.map +1 -1
  261. package/dist/modules/opportunities/routes.js +8 -1
  262. package/dist/modules/opportunities/routes.js.map +1 -1
  263. package/dist/modules/opportunities/schema.d.ts +34 -0
  264. package/dist/modules/opportunities/schema.d.ts.map +1 -1
  265. package/dist/modules/opportunities/schema.js +7 -2
  266. package/dist/modules/opportunities/schema.js.map +1 -1
  267. package/dist/modules/opportunities/service.d.ts.map +1 -1
  268. package/dist/modules/opportunities/service.js +2 -0
  269. package/dist/modules/opportunities/service.js.map +1 -1
  270. package/dist/modules/opportunities/tools.d.ts +2 -1
  271. package/dist/modules/opportunities/tools.d.ts.map +1 -1
  272. package/dist/modules/opportunities/tools.js +3 -1
  273. package/dist/modules/opportunities/tools.js.map +1 -1
  274. package/dist/modules/partnerships/events.d.ts +9 -0
  275. package/dist/modules/partnerships/events.d.ts.map +1 -1
  276. package/dist/modules/partnerships/events.js +4 -0
  277. package/dist/modules/partnerships/events.js.map +1 -1
  278. package/dist/modules/partnerships/index.d.ts.map +1 -1
  279. package/dist/modules/partnerships/index.js +4 -2
  280. package/dist/modules/partnerships/index.js.map +1 -1
  281. package/dist/modules/partnerships/routes.d.ts +2 -0
  282. package/dist/modules/partnerships/routes.d.ts.map +1 -1
  283. package/dist/modules/partnerships/routes.js +8 -1
  284. package/dist/modules/partnerships/routes.js.map +1 -1
  285. package/dist/modules/partnerships/schema.d.ts +34 -0
  286. package/dist/modules/partnerships/schema.d.ts.map +1 -1
  287. package/dist/modules/partnerships/schema.js +7 -2
  288. package/dist/modules/partnerships/schema.js.map +1 -1
  289. package/dist/modules/partnerships/service.d.ts.map +1 -1
  290. package/dist/modules/partnerships/service.js +2 -0
  291. package/dist/modules/partnerships/service.js.map +1 -1
  292. package/dist/modules/partnerships/tools.d.ts +2 -1
  293. package/dist/modules/partnerships/tools.d.ts.map +1 -1
  294. package/dist/modules/partnerships/tools.js +3 -1
  295. package/dist/modules/partnerships/tools.js.map +1 -1
  296. package/dist/modules/people/personConsentWrites.d.ts +1 -1
  297. package/dist/modules/people/schema.js +1 -1
  298. package/dist/modules/people/schema.js.map +1 -1
  299. package/dist/modules/plans/repository.d.ts +2 -0
  300. package/dist/modules/plans/repository.d.ts.map +1 -1
  301. package/dist/modules/plans/repository.js +9 -0
  302. package/dist/modules/plans/repository.js.map +1 -1
  303. package/dist/modules/raises/events.d.ts +9 -0
  304. package/dist/modules/raises/events.d.ts.map +1 -1
  305. package/dist/modules/raises/events.js +4 -0
  306. package/dist/modules/raises/events.js.map +1 -1
  307. package/dist/modules/raises/index.d.ts.map +1 -1
  308. package/dist/modules/raises/index.js +4 -2
  309. package/dist/modules/raises/index.js.map +1 -1
  310. package/dist/modules/raises/routes.d.ts +2 -0
  311. package/dist/modules/raises/routes.d.ts.map +1 -1
  312. package/dist/modules/raises/routes.js +8 -1
  313. package/dist/modules/raises/routes.js.map +1 -1
  314. package/dist/modules/raises/schema.d.ts +34 -0
  315. package/dist/modules/raises/schema.d.ts.map +1 -1
  316. package/dist/modules/raises/schema.js +7 -2
  317. package/dist/modules/raises/schema.js.map +1 -1
  318. package/dist/modules/raises/service.d.ts.map +1 -1
  319. package/dist/modules/raises/service.js +2 -0
  320. package/dist/modules/raises/service.js.map +1 -1
  321. package/dist/modules/raises/tools.d.ts +2 -1
  322. package/dist/modules/raises/tools.d.ts.map +1 -1
  323. package/dist/modules/raises/tools.js +3 -1
  324. package/dist/modules/raises/tools.js.map +1 -1
  325. package/dist/modules/workspace/routes.d.ts +0 -2
  326. package/dist/modules/workspace/routes.d.ts.map +1 -1
  327. package/dist/modules/workspace/routes.js +0 -6
  328. package/dist/modules/workspace/routes.js.map +1 -1
  329. package/dist/modules/workspace/schema.d.ts +0 -34
  330. package/dist/modules/workspace/schema.d.ts.map +1 -1
  331. package/dist/modules/workspace/schema.js +0 -2
  332. package/dist/modules/workspace/schema.js.map +1 -1
  333. package/dist/modules/workspace/seedStarterForms.d.ts +17 -0
  334. package/dist/modules/workspace/seedStarterForms.d.ts.map +1 -0
  335. package/dist/modules/workspace/seedStarterForms.js +71 -0
  336. package/dist/modules/workspace/seedStarterForms.js.map +1 -0
  337. package/dist/modules/workspace/service.d.ts +0 -4
  338. package/dist/modules/workspace/service.d.ts.map +1 -1
  339. package/dist/modules/workspace/service.js +20 -10
  340. package/dist/modules/workspace/service.js.map +1 -1
  341. package/dist/modules/workspace/tools.js +1 -1
  342. package/dist/modules/workspace/tools.js.map +1 -1
  343. package/dist/testing/fixtures.d.ts.map +1 -1
  344. package/dist/testing/fixtures.js +1 -0
  345. package/dist/testing/fixtures.js.map +1 -1
  346. package/migrations/0037_drop_lists_consent_purpose_id.sql +2 -0
  347. package/migrations/0038_smart_white_queen.sql +2 -0
  348. package/migrations/0039_form_map_to_open.sql +1 -0
  349. package/migrations/0040_pipeline_converted_to.sql +20 -0
  350. package/migrations/0041_api_key_scopes.sql +1 -0
  351. package/migrations/0042_drop_workspace_identity.sql +2 -0
  352. package/migrations/meta/0038_snapshot.json +6554 -0
  353. package/migrations/meta/_journal.json +42 -0
  354. package/package.json +2 -2
  355. package/src/app.ts +3 -0
  356. package/src/index.ts +6 -0
  357. package/src/lib/actor.ts +3 -1
  358. package/src/lib/apiKeyScopes.ts +213 -0
  359. package/src/modules/activities/repository.ts +24 -0
  360. package/src/modules/agent-tasks/repository.ts +24 -0
  361. package/src/modules/api-keys/routes.ts +5 -0
  362. package/src/modules/api-keys/schema.ts +2 -0
  363. package/src/modules/api-keys/scopeMiddleware.ts +30 -0
  364. package/src/modules/api-keys/service.ts +36 -2
  365. package/src/modules/auth/credentials.ts +4 -0
  366. package/src/modules/consent-purposes/index.ts +1 -1
  367. package/src/modules/consent-purposes/schema.ts +3 -3
  368. package/src/modules/consent-purposes/service.ts +7 -16
  369. package/src/modules/consent-purposes/starters.ts +1 -1
  370. package/src/modules/consent-purposes/tools.ts +1 -1
  371. package/src/modules/conversions/clearPointers.ts +81 -0
  372. package/src/modules/conversions/factory.ts +20 -0
  373. package/src/modules/conversions/fieldMap.ts +548 -0
  374. package/src/modules/conversions/index.ts +6 -0
  375. package/src/modules/conversions/mcp.ts +71 -0
  376. package/src/modules/conversions/repoint.ts +146 -0
  377. package/src/modules/conversions/routes.ts +68 -0
  378. package/src/modules/conversions/service.ts +310 -0
  379. package/src/modules/conversions/wire.ts +42 -0
  380. package/src/modules/deals/events.ts +9 -0
  381. package/src/modules/deals/index.ts +4 -2
  382. package/src/modules/deals/routes.ts +11 -1
  383. package/src/modules/deals/schema.ts +10 -2
  384. package/src/modules/deals/service.ts +3 -0
  385. package/src/modules/deals/tools.ts +9 -1
  386. package/src/modules/decisions/repository.ts +23 -1
  387. package/src/modules/enquiries/events.ts +8 -2
  388. package/src/modules/enquiries/index.ts +4 -2
  389. package/src/modules/enquiries/routes.ts +11 -13
  390. package/src/modules/enquiries/schema.ts +12 -3
  391. package/src/modules/enquiries/service.ts +3 -150
  392. package/src/modules/enquiries/tools.ts +9 -18
  393. package/src/modules/forms/applyMappedFields.ts +248 -0
  394. package/src/modules/forms/applySubmissionFields.ts +435 -0
  395. package/src/modules/forms/fields.ts +31 -7
  396. package/src/modules/forms/mapping.ts +20 -3
  397. package/src/modules/forms/repository.ts +0 -7
  398. package/src/modules/forms/routes.ts +1 -2
  399. package/src/modules/forms/schema.ts +0 -2
  400. package/src/modules/forms/service.ts +31 -4
  401. package/src/modules/forms/starters.ts +129 -0
  402. package/src/modules/forms/submission.ts +135 -69
  403. package/src/modules/import-export/customFieldCsv.ts +55 -0
  404. package/src/modules/import-export/customFieldImport.ts +111 -0
  405. package/src/modules/import-export/drafts.ts +151 -3
  406. package/src/modules/import-export/exportRows.ts +222 -68
  407. package/src/modules/import-export/plan.ts +321 -67
  408. package/src/modules/import-export/repository.ts +356 -14
  409. package/src/modules/import-export/routes.ts +8 -8
  410. package/src/modules/import-export/service.ts +208 -45
  411. package/src/modules/import-export/streams.ts +95 -13
  412. package/src/modules/import-export/tools.ts +14 -6
  413. package/src/modules/import-export/validation.ts +128 -0
  414. package/src/modules/import-export/writes.ts +559 -27
  415. package/src/modules/lists/index.ts +71 -0
  416. package/src/modules/lists/repository.ts +34 -2
  417. package/src/modules/lists/routes.ts +0 -8
  418. package/src/modules/lists/schema.ts +0 -10
  419. package/src/modules/lists/service.ts +9 -107
  420. package/src/modules/lists/starters.ts +16 -0
  421. package/src/modules/mcp/protocol.ts +18 -0
  422. package/src/modules/notes/repository.ts +24 -0
  423. package/src/modules/opportunities/events.ts +9 -0
  424. package/src/modules/opportunities/index.ts +4 -2
  425. package/src/modules/opportunities/routes.ts +11 -1
  426. package/src/modules/opportunities/schema.ts +10 -2
  427. package/src/modules/opportunities/service.ts +3 -0
  428. package/src/modules/opportunities/tools.ts +9 -1
  429. package/src/modules/partnerships/events.ts +9 -0
  430. package/src/modules/partnerships/index.ts +4 -2
  431. package/src/modules/partnerships/routes.ts +11 -1
  432. package/src/modules/partnerships/schema.ts +10 -2
  433. package/src/modules/partnerships/service.ts +3 -0
  434. package/src/modules/partnerships/tools.ts +9 -1
  435. package/src/modules/people/personConsentWrites.ts +1 -1
  436. package/src/modules/people/schema.ts +1 -1
  437. package/src/modules/plans/repository.ts +24 -0
  438. package/src/modules/raises/events.ts +9 -0
  439. package/src/modules/raises/index.ts +4 -2
  440. package/src/modules/raises/routes.ts +11 -1
  441. package/src/modules/raises/schema.ts +10 -2
  442. package/src/modules/raises/service.ts +3 -0
  443. package/src/modules/raises/tools.ts +9 -1
  444. package/src/modules/workspace/routes.ts +0 -6
  445. package/src/modules/workspace/schema.ts +0 -2
  446. package/src/modules/workspace/seedStarterForms.ts +98 -0
  447. package/src/modules/workspace/service.ts +23 -15
  448. package/src/modules/workspace/tools.ts +1 -1
  449. package/src/testing/fixtures.ts +1 -0
@@ -1,13 +1,20 @@
1
1
  import { and, asc, eq, gt, inArray, sql } from 'drizzle-orm'
2
2
 
3
+ import type { CustomFieldValue } from '@kelpie/schemas'
3
4
  import type { Queryable } from '../../runtime/transaction.ts'
4
5
  import { users } from '../auth/schema.ts'
5
6
  import { companies } from '../companies/schema.ts'
6
7
  import { consentPurposes } from '../consent-purposes/schema.ts'
8
+ import { customFieldDefinitions } from '../custom-fields/schema.ts'
9
+ import type { CustomFieldDefinitionRecord } from '../custom-fields/repository.ts'
7
10
  import { deals } from '../deals/schema.ts'
11
+ import { enquiries } from '../enquiries/schema.ts'
12
+ import { opportunities } from '../opportunities/schema.ts'
13
+ import { partnerships } from '../partnerships/schema.ts'
8
14
  import { people, personConsents, personLinks } from '../people/schema.ts'
9
15
  import { pipelineStages } from '../pipelines/schema.ts'
10
16
  import { positions } from '../positions/schema.ts'
17
+ import { raises } from '../raises/schema.ts'
11
18
  import { workspaceMembers } from '../workspace/schema.ts'
12
19
  import type { MatchKeyParts } from './mapping.ts'
13
20
  import { importJobRows, importJobs } from './schema.ts'
@@ -364,6 +371,150 @@ export function findDealKeysByCompany(
364
371
  )
365
372
  }
366
373
 
374
+ export function findOpportunityKeysByName(
375
+ db: Queryable,
376
+ workspaceId: string,
377
+ names: readonly string[],
378
+ ): Promise<KeyedRecord[]> {
379
+ return overChunks(names, (chunk) =>
380
+ db
381
+ .select({ id: opportunities.id, name: opportunities.name })
382
+ .from(opportunities)
383
+ .where(
384
+ and(
385
+ eq(opportunities.workspaceId, workspaceId),
386
+ inArray(sql<string>`lower(${opportunities.name})`, [...chunk]),
387
+ ),
388
+ ),
389
+ ).then((rows) => rows.map((row) => ({ id: row.id, parts: { name: row.name } })))
390
+ }
391
+
392
+ export function findOpportunityKeysByCompany(
393
+ db: Queryable,
394
+ workspaceId: string,
395
+ domains: readonly string[],
396
+ ): Promise<KeyedRecord[]> {
397
+ return overChunks(domains, (chunk) =>
398
+ db
399
+ .select({ id: opportunities.id, name: opportunities.name, companyDomain: companies.domain })
400
+ .from(opportunities)
401
+ .leftJoin(companies, eq(companies.id, opportunities.companyId))
402
+ .where(and(eq(opportunities.workspaceId, workspaceId), inArray(companies.domain, [...chunk]))),
403
+ ).then((rows) =>
404
+ rows.map((row) => ({
405
+ id: row.id,
406
+ parts: { name: row.name, company_domain: row.companyDomain },
407
+ })),
408
+ )
409
+ }
410
+
411
+ export function findEnquiryKeysByName(
412
+ db: Queryable,
413
+ workspaceId: string,
414
+ names: readonly string[],
415
+ ): Promise<KeyedRecord[]> {
416
+ return overChunks(names, (chunk) =>
417
+ db
418
+ .select({ id: enquiries.id, name: enquiries.name })
419
+ .from(enquiries)
420
+ .where(
421
+ and(
422
+ eq(enquiries.workspaceId, workspaceId),
423
+ inArray(sql<string>`lower(${enquiries.name})`, [...chunk]),
424
+ ),
425
+ ),
426
+ ).then((rows) => rows.map((row) => ({ id: row.id, parts: { name: row.name } })))
427
+ }
428
+
429
+ export function findEnquiryKeysByCompany(
430
+ db: Queryable,
431
+ workspaceId: string,
432
+ domains: readonly string[],
433
+ ): Promise<KeyedRecord[]> {
434
+ return overChunks(domains, (chunk) =>
435
+ db
436
+ .select({ id: enquiries.id, name: enquiries.name, companyDomain: companies.domain })
437
+ .from(enquiries)
438
+ .leftJoin(companies, eq(companies.id, enquiries.companyId))
439
+ .where(and(eq(enquiries.workspaceId, workspaceId), inArray(companies.domain, [...chunk]))),
440
+ ).then((rows) =>
441
+ rows.map((row) => ({
442
+ id: row.id,
443
+ parts: { name: row.name, company_domain: row.companyDomain },
444
+ })),
445
+ )
446
+ }
447
+
448
+ export function findPartnershipKeysByCompany(
449
+ db: Queryable,
450
+ workspaceId: string,
451
+ domains: readonly string[],
452
+ ): Promise<KeyedRecord[]> {
453
+ return overChunks(domains, (chunk) =>
454
+ db
455
+ .select({ id: partnerships.id, name: partnerships.name, companyDomain: companies.domain })
456
+ .from(partnerships)
457
+ .innerJoin(companies, eq(companies.id, partnerships.companyId))
458
+ .where(and(eq(partnerships.workspaceId, workspaceId), inArray(companies.domain, [...chunk]))),
459
+ ).then((rows) =>
460
+ rows.map((row) => ({
461
+ id: row.id,
462
+ parts: { name: row.name, company_domain: row.companyDomain },
463
+ })),
464
+ )
465
+ }
466
+
467
+ export function findRaiseKeysByCompany(
468
+ db: Queryable,
469
+ workspaceId: string,
470
+ domains: readonly string[],
471
+ ): Promise<KeyedRecord[]> {
472
+ return overChunks(domains, (chunk) =>
473
+ db
474
+ .select({ id: raises.id, name: raises.name, companyDomain: companies.domain })
475
+ .from(raises)
476
+ .innerJoin(companies, eq(companies.id, raises.companyId))
477
+ .where(and(eq(raises.workspaceId, workspaceId), inArray(companies.domain, [...chunk]))),
478
+ ).then((rows) =>
479
+ rows.map((row) => ({
480
+ id: row.id,
481
+ parts: { name: row.name, company_domain: row.companyDomain },
482
+ })),
483
+ )
484
+ }
485
+
486
+ export function findCustomFieldDefinitionKeys(
487
+ db: Queryable,
488
+ workspaceId: string,
489
+ objectTypes: readonly string[],
490
+ keys: readonly string[],
491
+ ): Promise<KeyedRecord[]> {
492
+ if (objectTypes.length === 0 || keys.length === 0) {
493
+ return Promise.resolve([])
494
+ }
495
+
496
+ return db
497
+ .select({
498
+ id: customFieldDefinitions.id,
499
+ objectType: customFieldDefinitions.objectType,
500
+ key: customFieldDefinitions.key,
501
+ })
502
+ .from(customFieldDefinitions)
503
+ .where(
504
+ and(
505
+ eq(customFieldDefinitions.workspaceId, workspaceId),
506
+ inArray(customFieldDefinitions.objectType, [...objectTypes]),
507
+ inArray(customFieldDefinitions.key, [...keys]),
508
+ ),
509
+ )
510
+ .then((rows) =>
511
+ rows.map((row) => ({
512
+ id: row.id,
513
+ parts: { object_type: row.objectType, key: row.key },
514
+ })),
515
+ )
516
+ }
517
+
367
518
  export function findPersonIdsByEmail(
368
519
  db: Queryable,
369
520
  workspaceId: string,
@@ -428,18 +579,27 @@ export function listMemberEmails(
428
579
  .where(eq(workspaceMembers.workspaceId, workspaceId))
429
580
  }
430
581
 
431
- /** The deal pipeline's stages, for resolving a stage name in a row. */
432
- export function listDealStages(
582
+ /** A pipeline's stages, for resolving a stage name in a row. */
583
+ export function listPipelineStages(
433
584
  db: Queryable,
434
585
  workspaceId: string,
586
+ kind: import('../pipelines/schema.ts').PipelineKind,
435
587
  ): Promise<{ id: string; slug: string; label: string }[]> {
436
588
  return db
437
589
  .select({ id: pipelineStages.id, slug: pipelineStages.slug, label: pipelineStages.label })
438
590
  .from(pipelineStages)
439
- .where(and(eq(pipelineStages.workspaceId, workspaceId), eq(pipelineStages.kind, 'deal')))
591
+ .where(and(eq(pipelineStages.workspaceId, workspaceId), eq(pipelineStages.kind, kind)))
440
592
  .orderBy(asc(pipelineStages.sortOrder), asc(pipelineStages.id))
441
593
  }
442
594
 
595
+ /** @deprecated Use `listPipelineStages` with kind `deal`. */
596
+ export function listDealStages(
597
+ db: Queryable,
598
+ workspaceId: string,
599
+ ): Promise<{ id: string; slug: string; label: string }[]> {
600
+ return listPipelineStages(db, workspaceId, 'deal')
601
+ }
602
+
443
603
  /* Export readers. Keyset by id, which is a ULID and therefore creation order. */
444
604
 
445
605
  export interface ExportCompanyRow {
@@ -456,6 +616,7 @@ export interface ExportCompanyRow {
456
616
  readonly tags: readonly string[]
457
617
  readonly website: string | null
458
618
  readonly hq: string | null
619
+ readonly customFields: Readonly<Record<string, CustomFieldValue>>
459
620
  }
460
621
 
461
622
  export function readCompanies(
@@ -478,6 +639,7 @@ export function readCompanies(
478
639
  tags: companies.tags,
479
640
  website: companies.website,
480
641
  hq: companies.hq,
642
+ customFields: companies.customFields,
481
643
  })
482
644
  .from(companies)
483
645
  .where(and(eq(companies.workspaceId, workspaceId), gt(companies.id, after)))
@@ -507,6 +669,7 @@ export interface ExportPersonRow {
507
669
  * Purposes at their default (no explicit `person_consents` row) are omitted.
508
670
  */
509
671
  readonly consents: string
672
+ readonly customFields: Readonly<Record<string, CustomFieldValue>>
510
673
  }
511
674
 
512
675
  export async function readPeople(
@@ -532,6 +695,7 @@ export async function readPeople(
532
695
  tags: people.tags,
533
696
  phones: people.phones,
534
697
  doNotContact: people.doNotContact,
698
+ customFields: people.customFields,
535
699
  })
536
700
  .from(people)
537
701
  .where(and(eq(people.workspaceId, workspaceId), gt(people.id, after)))
@@ -622,6 +786,7 @@ export interface ExportDealRow {
622
786
  readonly summary: string
623
787
  readonly tags: readonly string[]
624
788
  readonly externalId: string | null
789
+ readonly customFields: Readonly<Record<string, CustomFieldValue>>
625
790
  }
626
791
 
627
792
  /**
@@ -648,6 +813,7 @@ export function readDeals(
648
813
  summary: deals.summary,
649
814
  tags: deals.tags,
650
815
  externalId: deals.externalId,
816
+ customFields: deals.customFields,
651
817
  })
652
818
  .from(deals)
653
819
  .innerJoin(companies, eq(companies.id, deals.companyId))
@@ -659,44 +825,220 @@ export function readDeals(
659
825
  .limit(EXPORT_PAGE)
660
826
  }
661
827
 
662
- /** The addresses of the people on each of a page of deals, in one query. */
663
- export async function readDealPersonEmails(
828
+ /** The addresses of the people linked to each of a page of pipeline records. */
829
+ export async function readLinkedPersonEmails(
664
830
  db: Queryable,
665
831
  workspaceId: string,
666
- dealIds: readonly string[],
832
+ targetType: string,
833
+ targetIds: readonly string[],
667
834
  ): Promise<ReadonlyMap<string, readonly string[]>> {
668
- if (dealIds.length === 0) {
835
+ if (targetIds.length === 0) {
669
836
  return new Map()
670
837
  }
671
838
 
672
839
  const rows = await db
673
- .select({ dealId: personLinks.targetId, email: people.email })
840
+ .select({ targetId: personLinks.targetId, email: people.email })
674
841
  .from(personLinks)
675
842
  .innerJoin(people, eq(people.id, personLinks.personId))
676
843
  .where(
677
844
  and(
678
845
  eq(personLinks.workspaceId, workspaceId),
679
- eq(personLinks.targetType, 'deal'),
680
- inArray(personLinks.targetId, [...dealIds]),
846
+ eq(personLinks.targetType, targetType),
847
+ inArray(personLinks.targetId, [...targetIds]),
681
848
  ),
682
849
  )
683
850
  .orderBy(asc(people.email))
684
851
 
685
- const byDeal = new Map<string, string[]>()
852
+ const byTarget = new Map<string, string[]>()
686
853
 
687
854
  for (const row of rows) {
688
855
  if (row.email === null) {
689
856
  continue
690
857
  }
691
858
 
692
- const existing = byDeal.get(row.dealId)
859
+ const existing = byTarget.get(row.targetId)
693
860
 
694
861
  if (existing === undefined) {
695
- byDeal.set(row.dealId, [row.email])
862
+ byTarget.set(row.targetId, [row.email])
696
863
  } else {
697
864
  existing.push(row.email)
698
865
  }
699
866
  }
700
867
 
701
- return byDeal
868
+ return byTarget
869
+ }
870
+
871
+ /** @deprecated Use {@link readLinkedPersonEmails} with `targetType: 'deal'`. */
872
+ export async function readDealPersonEmails(
873
+ db: Queryable,
874
+ workspaceId: string,
875
+ dealIds: readonly string[],
876
+ ): Promise<ReadonlyMap<string, readonly string[]>> {
877
+ return readLinkedPersonEmails(db, workspaceId, 'deal', dealIds)
878
+ }
879
+
880
+ interface PipelineExportRow {
881
+ readonly id: string
882
+ readonly name: string
883
+ readonly companyDomain: string | null
884
+ readonly stageSlug: string
885
+ readonly ownerEmail: string | null
886
+ readonly summary: string
887
+ readonly tags: readonly string[]
888
+ readonly customFields: Readonly<Record<string, CustomFieldValue>>
889
+ }
890
+
891
+ export interface ExportOpportunityRow extends PipelineExportRow {
892
+ readonly kind: string
893
+ readonly expectedClose: string | null
894
+ }
895
+
896
+ export function readOpportunities(
897
+ db: Queryable,
898
+ workspaceId: string,
899
+ after: string,
900
+ ): Promise<ExportOpportunityRow[]> {
901
+ return db
902
+ .select({
903
+ id: opportunities.id,
904
+ name: opportunities.name,
905
+ kind: opportunities.kind,
906
+ companyDomain: companies.domain,
907
+ stageSlug: pipelineStages.slug,
908
+ ownerEmail: users.email,
909
+ expectedClose: opportunities.expectedClose,
910
+ summary: opportunities.summary,
911
+ tags: opportunities.tags,
912
+ customFields: opportunities.customFields,
913
+ })
914
+ .from(opportunities)
915
+ .leftJoin(companies, eq(companies.id, opportunities.companyId))
916
+ .innerJoin(pipelineStages, eq(pipelineStages.id, opportunities.stageId))
917
+ .leftJoin(workspaceMembers, eq(workspaceMembers.id, opportunities.ownerId))
918
+ .leftJoin(users, eq(users.id, workspaceMembers.userId))
919
+ .where(and(eq(opportunities.workspaceId, workspaceId), gt(opportunities.id, after)))
920
+ .orderBy(asc(opportunities.id))
921
+ .limit(EXPORT_PAGE)
922
+ }
923
+
924
+ export interface ExportEnquiryRow extends PipelineExportRow {
925
+ readonly source: string
926
+ }
927
+
928
+ export function readEnquiries(
929
+ db: Queryable,
930
+ workspaceId: string,
931
+ after: string,
932
+ ): Promise<ExportEnquiryRow[]> {
933
+ return db
934
+ .select({
935
+ id: enquiries.id,
936
+ name: enquiries.name,
937
+ source: enquiries.source,
938
+ companyDomain: companies.domain,
939
+ stageSlug: pipelineStages.slug,
940
+ ownerEmail: users.email,
941
+ summary: enquiries.summary,
942
+ tags: enquiries.tags,
943
+ customFields: enquiries.customFields,
944
+ })
945
+ .from(enquiries)
946
+ .leftJoin(companies, eq(companies.id, enquiries.companyId))
947
+ .innerJoin(pipelineStages, eq(pipelineStages.id, enquiries.stageId))
948
+ .leftJoin(workspaceMembers, eq(workspaceMembers.id, enquiries.ownerId))
949
+ .leftJoin(users, eq(users.id, workspaceMembers.userId))
950
+ .where(and(eq(enquiries.workspaceId, workspaceId), gt(enquiries.id, after)))
951
+ .orderBy(asc(enquiries.id))
952
+ .limit(EXPORT_PAGE)
953
+ }
954
+
955
+ export interface ExportPartnershipRow extends PipelineExportRow {
956
+ readonly kind: string
957
+ readonly nextTouchpoint: string | null
958
+ readonly goals: string
959
+ readonly successLooksLike: string
960
+ }
961
+
962
+ export function readPartnerships(
963
+ db: Queryable,
964
+ workspaceId: string,
965
+ after: string,
966
+ ): Promise<ExportPartnershipRow[]> {
967
+ return db
968
+ .select({
969
+ id: partnerships.id,
970
+ name: partnerships.name,
971
+ companyDomain: companies.domain,
972
+ stageSlug: pipelineStages.slug,
973
+ kind: partnerships.kind,
974
+ nextTouchpoint: partnerships.nextTouchpoint,
975
+ ownerEmail: users.email,
976
+ goals: partnerships.goals,
977
+ successLooksLike: partnerships.successLooksLike,
978
+ summary: partnerships.summary,
979
+ tags: partnerships.tags,
980
+ customFields: partnerships.customFields,
981
+ })
982
+ .from(partnerships)
983
+ .innerJoin(companies, eq(companies.id, partnerships.companyId))
984
+ .innerJoin(pipelineStages, eq(pipelineStages.id, partnerships.stageId))
985
+ .leftJoin(workspaceMembers, eq(workspaceMembers.id, partnerships.ownerId))
986
+ .leftJoin(users, eq(users.id, workspaceMembers.userId))
987
+ .where(and(eq(partnerships.workspaceId, workspaceId), gt(partnerships.id, after)))
988
+ .orderBy(asc(partnerships.id))
989
+ .limit(EXPORT_PAGE)
990
+ }
991
+
992
+ export interface ExportRaiseRow extends PipelineExportRow {
993
+ readonly checkSizeCents: number | null
994
+ readonly currency: string | null
995
+ readonly thesisFit: string
996
+ readonly passReason: string | null
997
+ readonly expectedClose: string | null
998
+ }
999
+
1000
+ export function readRaises(
1001
+ db: Queryable,
1002
+ workspaceId: string,
1003
+ after: string,
1004
+ ): Promise<ExportRaiseRow[]> {
1005
+ return db
1006
+ .select({
1007
+ id: raises.id,
1008
+ name: raises.name,
1009
+ companyDomain: companies.domain,
1010
+ stageSlug: pipelineStages.slug,
1011
+ checkSizeCents: raises.checkSizeCents,
1012
+ currency: raises.currency,
1013
+ thesisFit: raises.thesisFit,
1014
+ passReason: raises.passReason,
1015
+ ownerEmail: users.email,
1016
+ expectedClose: raises.expectedClose,
1017
+ summary: raises.summary,
1018
+ tags: raises.tags,
1019
+ customFields: raises.customFields,
1020
+ })
1021
+ .from(raises)
1022
+ .innerJoin(companies, eq(companies.id, raises.companyId))
1023
+ .innerJoin(pipelineStages, eq(pipelineStages.id, raises.stageId))
1024
+ .leftJoin(workspaceMembers, eq(workspaceMembers.id, raises.ownerId))
1025
+ .leftJoin(users, eq(users.id, workspaceMembers.userId))
1026
+ .where(and(eq(raises.workspaceId, workspaceId), gt(raises.id, after)))
1027
+ .orderBy(asc(raises.id))
1028
+ .limit(EXPORT_PAGE)
1029
+ }
1030
+
1031
+ export function readCustomFieldDefinitions(
1032
+ db: Queryable,
1033
+ workspaceId: string,
1034
+ after: string,
1035
+ ): Promise<CustomFieldDefinitionRecord[]> {
1036
+ return db
1037
+ .select()
1038
+ .from(customFieldDefinitions)
1039
+ .where(
1040
+ and(eq(customFieldDefinitions.workspaceId, workspaceId), gt(customFieldDefinitions.id, after)),
1041
+ )
1042
+ .orderBy(asc(customFieldDefinitions.id))
1043
+ .limit(EXPORT_PAGE)
702
1044
  }
@@ -1,4 +1,5 @@
1
1
  import {
2
+ EXPORT_OBJECTS,
2
3
  IMPORT_CONFLICT_MODES,
3
4
  IMPORT_OBJECTS,
4
5
  IMPORT_SOURCES,
@@ -6,7 +7,7 @@ import {
6
7
  ON_MISSING_COMPANY,
7
8
  defaultMatchKeyId,
8
9
  } from '@kelpie/schemas'
9
- import type { ImportColumnMap, ImportObject } from '@kelpie/schemas'
10
+ import type { ExportObject, ImportColumnMap } from '@kelpie/schemas'
10
11
  import type { Context, Hono } from 'hono'
11
12
  import { stream } from 'hono/streaming'
12
13
  import { z } from 'zod'
@@ -29,7 +30,7 @@ import type { ImportExportService, ImportJobView } from './service.ts'
29
30
  /** The file name a download is offered under. */
30
31
  const DOWNLOAD_PREFIX = 'kelpie'
31
32
 
32
- const objectFile = z.enum(IMPORT_OBJECTS.map((object) => `${object}.csv`) as [string, ...string[]])
33
+ const objectFile = z.enum(EXPORT_OBJECTS.map((object) => `${object}.csv`) as [string, ...string[]])
33
34
 
34
35
  /**
35
36
  * `column_map` arrives as a JSON string inside the form, since a multipart field
@@ -78,16 +79,16 @@ export function importJobResponse(job: ImportJobView): Record<string, unknown> {
78
79
  }
79
80
 
80
81
  /** `people.csv` → `people`. The route's own param, so an unknown one is a 404. */
81
- function readObjectFile(context: Context): ImportObject {
82
+ function readObjectFile(context: Context): ExportObject {
82
83
  const parsed = objectFile.safeParse(context.req.param('file'))
83
84
 
84
85
  if (!parsed.success) {
85
86
  throw AppError.notFound(
86
- `Export ${IMPORT_OBJECTS.map((object) => `${object}.csv`).join(', ')}`,
87
+ `Export ${EXPORT_OBJECTS.map((object) => `${object}.csv`).join(', ')}`,
87
88
  )
88
89
  }
89
90
 
90
- return parsed.data.replace(/\.csv$/u, '') as ImportObject
91
+ return parsed.data.replace(/\.csv$/u, '') as ExportObject
91
92
  }
92
93
 
93
94
  function csvHeaders(fileName: string): Record<string, string> {
@@ -198,11 +199,10 @@ export function mountImportExportRoutes(
198
199
 
199
200
  router.get('/export/templates/:file', async (context) => {
200
201
  const object = readObjectFile(context)
201
-
202
- await requireActor(context)
202
+ const actor = await requireActor(context)
203
203
 
204
204
  return context.body(
205
- dependencies.service.templateCsv(object),
205
+ await dependencies.service.templateCsv(actor, object),
206
206
  200,
207
207
  csvHeaders(`${DOWNLOAD_PREFIX}-${object}-template.csv`),
208
208
  )