@kelpie/server 0.5.2 → 0.7.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 (406) hide show
  1. package/README.md +5 -2
  2. package/dist/app.d.ts +13 -0
  3. package/dist/app.d.ts.map +1 -1
  4. package/dist/app.js +9 -0
  5. package/dist/app.js.map +1 -1
  6. package/dist/boot.d.ts +42 -0
  7. package/dist/boot.d.ts.map +1 -0
  8. package/dist/boot.js +57 -0
  9. package/dist/boot.js.map +1 -0
  10. package/dist/index.d.ts +20 -8
  11. package/dist/index.d.ts.map +1 -1
  12. package/dist/index.js +13 -4
  13. package/dist/index.js.map +1 -1
  14. package/dist/lib/actor.d.ts +9 -1
  15. package/dist/lib/actor.d.ts.map +1 -1
  16. package/dist/lib/actor.js +13 -0
  17. package/dist/lib/actor.js.map +1 -1
  18. package/dist/lib/config.d.ts +51 -6
  19. package/dist/lib/config.d.ts.map +1 -1
  20. package/dist/lib/config.js +11 -5
  21. package/dist/lib/config.js.map +1 -1
  22. package/dist/lib/email.d.ts +15 -63
  23. package/dist/lib/email.d.ts.map +1 -1
  24. package/dist/lib/email.js +13 -65
  25. package/dist/lib/email.js.map +1 -1
  26. package/dist/lib/fromEnv.d.ts +60 -0
  27. package/dist/lib/fromEnv.d.ts.map +1 -0
  28. package/dist/lib/fromEnv.js +94 -0
  29. package/dist/lib/fromEnv.js.map +1 -0
  30. package/dist/lib/ids.d.ts +6 -0
  31. package/dist/lib/ids.d.ts.map +1 -1
  32. package/dist/lib/ids.js +6 -0
  33. package/dist/lib/ids.js.map +1 -1
  34. package/dist/lib/kelpieConfigFile.d.ts +129 -0
  35. package/dist/lib/kelpieConfigFile.d.ts.map +1 -0
  36. package/dist/lib/kelpieConfigFile.js +112 -0
  37. package/dist/lib/kelpieConfigFile.js.map +1 -0
  38. package/dist/lib/logger.d.ts +38 -7
  39. package/dist/lib/logger.d.ts.map +1 -1
  40. package/dist/lib/logger.js +58 -20
  41. package/dist/lib/logger.js.map +1 -1
  42. package/dist/modules/agent-tasks/index.d.ts.map +1 -1
  43. package/dist/modules/agent-tasks/index.js +4 -1
  44. package/dist/modules/agent-tasks/index.js.map +1 -1
  45. package/dist/modules/agent-tasks/prompt.d.ts +36 -6
  46. package/dist/modules/agent-tasks/prompt.d.ts.map +1 -1
  47. package/dist/modules/agent-tasks/prompt.js +33 -4
  48. package/dist/modules/agent-tasks/prompt.js.map +1 -1
  49. package/dist/modules/agent-tasks/service.d.ts.map +1 -1
  50. package/dist/modules/agent-tasks/service.js +3 -2
  51. package/dist/modules/agent-tasks/service.js.map +1 -1
  52. package/dist/modules/agent-tasks/wire.d.ts +11 -0
  53. package/dist/modules/agent-tasks/wire.d.ts.map +1 -1
  54. package/dist/modules/agent-tasks/wire.js +1 -0
  55. package/dist/modules/agent-tasks/wire.js.map +1 -1
  56. package/dist/modules/auth/index.d.ts.map +1 -1
  57. package/dist/modules/auth/index.js +8 -7
  58. package/dist/modules/auth/index.js.map +1 -1
  59. package/dist/modules/companies/events.d.ts +22 -0
  60. package/dist/modules/companies/events.d.ts.map +1 -0
  61. package/dist/modules/companies/events.js +8 -0
  62. package/dist/modules/companies/events.js.map +1 -0
  63. package/dist/modules/companies/index.d.ts.map +1 -1
  64. package/dist/modules/companies/index.js +2 -0
  65. package/dist/modules/companies/index.js.map +1 -1
  66. package/dist/modules/companies/service.d.ts +1 -0
  67. package/dist/modules/companies/service.d.ts.map +1 -1
  68. package/dist/modules/companies/service.js +8 -11
  69. package/dist/modules/companies/service.js.map +1 -1
  70. package/dist/modules/core.d.ts.map +1 -1
  71. package/dist/modules/core.js +4 -0
  72. package/dist/modules/core.js.map +1 -1
  73. package/dist/modules/deals/events.d.ts +31 -0
  74. package/dist/modules/deals/events.d.ts.map +1 -0
  75. package/dist/modules/deals/events.js +12 -0
  76. package/dist/modules/deals/events.js.map +1 -0
  77. package/dist/modules/deals/index.d.ts.map +1 -1
  78. package/dist/modules/deals/index.js +2 -0
  79. package/dist/modules/deals/index.js.map +1 -1
  80. package/dist/modules/deals/service.d.ts +1 -0
  81. package/dist/modules/deals/service.d.ts.map +1 -1
  82. package/dist/modules/deals/service.js +9 -18
  83. package/dist/modules/deals/service.js.map +1 -1
  84. package/dist/modules/decisions/events.d.ts +21 -0
  85. package/dist/modules/decisions/events.d.ts.map +1 -0
  86. package/dist/modules/decisions/events.js +11 -0
  87. package/dist/modules/decisions/events.js.map +1 -0
  88. package/dist/modules/decisions/index.d.ts.map +1 -1
  89. package/dist/modules/decisions/index.js +2 -0
  90. package/dist/modules/decisions/index.js.map +1 -1
  91. package/dist/modules/decisions/service.d.ts +1 -0
  92. package/dist/modules/decisions/service.d.ts.map +1 -1
  93. package/dist/modules/decisions/service.js +4 -7
  94. package/dist/modules/decisions/service.js.map +1 -1
  95. package/dist/modules/eventCatalogs.d.ts +35 -0
  96. package/dist/modules/eventCatalogs.d.ts.map +1 -0
  97. package/dist/modules/eventCatalogs.js +35 -0
  98. package/dist/modules/eventCatalogs.js.map +1 -0
  99. package/dist/modules/forms/events.d.ts +37 -0
  100. package/dist/modules/forms/events.d.ts.map +1 -0
  101. package/dist/modules/forms/events.js +15 -0
  102. package/dist/modules/forms/events.js.map +1 -0
  103. package/dist/modules/forms/index.d.ts.map +1 -1
  104. package/dist/modules/forms/index.js +2 -0
  105. package/dist/modules/forms/index.js.map +1 -1
  106. package/dist/modules/forms/service.d.ts +1 -0
  107. package/dist/modules/forms/service.d.ts.map +1 -1
  108. package/dist/modules/forms/service.js +8 -11
  109. package/dist/modules/forms/service.js.map +1 -1
  110. package/dist/modules/forms/submission.d.ts +5 -0
  111. package/dist/modules/forms/submission.d.ts.map +1 -1
  112. package/dist/modules/forms/submission.js +54 -28
  113. package/dist/modules/forms/submission.js.map +1 -1
  114. package/dist/modules/handbook/events.d.ts +28 -0
  115. package/dist/modules/handbook/events.d.ts.map +1 -0
  116. package/dist/modules/handbook/events.js +14 -0
  117. package/dist/modules/handbook/events.js.map +1 -0
  118. package/dist/modules/handbook/index.d.ts.map +1 -1
  119. package/dist/modules/handbook/index.js +2 -0
  120. package/dist/modules/handbook/index.js.map +1 -1
  121. package/dist/modules/handbook/service.d.ts +1 -0
  122. package/dist/modules/handbook/service.d.ts.map +1 -1
  123. package/dist/modules/handbook/service.js +8 -15
  124. package/dist/modules/handbook/service.js.map +1 -1
  125. package/dist/modules/hiring/candidates.d.ts +1 -0
  126. package/dist/modules/hiring/candidates.d.ts.map +1 -1
  127. package/dist/modules/hiring/candidates.js +8 -11
  128. package/dist/modules/hiring/candidates.js.map +1 -1
  129. package/dist/modules/hiring/events.d.ts +35 -0
  130. package/dist/modules/hiring/events.d.ts.map +1 -0
  131. package/dist/modules/hiring/events.js +11 -0
  132. package/dist/modules/hiring/events.js.map +1 -0
  133. package/dist/modules/hiring/index.d.ts.map +1 -1
  134. package/dist/modules/hiring/index.js +2 -0
  135. package/dist/modules/hiring/index.js.map +1 -1
  136. package/dist/modules/hiring/roles.d.ts +1 -0
  137. package/dist/modules/hiring/roles.d.ts.map +1 -1
  138. package/dist/modules/hiring/roles.js +8 -11
  139. package/dist/modules/hiring/roles.js.map +1 -1
  140. package/dist/modules/import-export/drafts.d.ts +9 -0
  141. package/dist/modules/import-export/drafts.d.ts.map +1 -1
  142. package/dist/modules/import-export/drafts.js +25 -0
  143. package/dist/modules/import-export/drafts.js.map +1 -1
  144. package/dist/modules/import-export/events.d.ts +22 -0
  145. package/dist/modules/import-export/events.d.ts.map +1 -0
  146. package/dist/modules/import-export/events.js +12 -0
  147. package/dist/modules/import-export/events.js.map +1 -0
  148. package/dist/modules/import-export/exportRows.d.ts +9 -0
  149. package/dist/modules/import-export/exportRows.d.ts.map +1 -1
  150. package/dist/modules/import-export/exportRows.js +10 -1
  151. package/dist/modules/import-export/exportRows.js.map +1 -1
  152. package/dist/modules/import-export/index.d.ts.map +1 -1
  153. package/dist/modules/import-export/index.js +2 -0
  154. package/dist/modules/import-export/index.js.map +1 -1
  155. package/dist/modules/import-export/plan.d.ts +23 -1
  156. package/dist/modules/import-export/plan.d.ts.map +1 -1
  157. package/dist/modules/import-export/plan.js +62 -3
  158. package/dist/modules/import-export/plan.js.map +1 -1
  159. package/dist/modules/import-export/presets.d.ts.map +1 -1
  160. package/dist/modules/import-export/presets.js +25 -0
  161. package/dist/modules/import-export/presets.js.map +1 -1
  162. package/dist/modules/import-export/repository.d.ts +17 -0
  163. package/dist/modules/import-export/repository.d.ts.map +1 -1
  164. package/dist/modules/import-export/repository.js +21 -1
  165. package/dist/modules/import-export/repository.js.map +1 -1
  166. package/dist/modules/import-export/routes.d.ts.map +1 -1
  167. package/dist/modules/import-export/routes.js +5 -1
  168. package/dist/modules/import-export/routes.js.map +1 -1
  169. package/dist/modules/import-export/schema.d.ts +55 -0
  170. package/dist/modules/import-export/schema.d.ts.map +1 -1
  171. package/dist/modules/import-export/schema.js +13 -1
  172. package/dist/modules/import-export/schema.js.map +1 -1
  173. package/dist/modules/import-export/service.d.ts +9 -1
  174. package/dist/modules/import-export/service.d.ts.map +1 -1
  175. package/dist/modules/import-export/service.js +104 -17
  176. package/dist/modules/import-export/service.js.map +1 -1
  177. package/dist/modules/import-export/tools.d.ts.map +1 -1
  178. package/dist/modules/import-export/tools.js +7 -1
  179. package/dist/modules/import-export/tools.js.map +1 -1
  180. package/dist/modules/import-export/writes.d.ts +16 -0
  181. package/dist/modules/import-export/writes.d.ts.map +1 -1
  182. package/dist/modules/import-export/writes.js +77 -2
  183. package/dist/modules/import-export/writes.js.map +1 -1
  184. package/dist/modules/notes/events.d.ts +22 -0
  185. package/dist/modules/notes/events.d.ts.map +1 -0
  186. package/dist/modules/notes/events.js +12 -0
  187. package/dist/modules/notes/events.js.map +1 -0
  188. package/dist/modules/notes/index.d.ts.map +1 -1
  189. package/dist/modules/notes/index.js +2 -0
  190. package/dist/modules/notes/index.js.map +1 -1
  191. package/dist/modules/notes/service.d.ts +1 -0
  192. package/dist/modules/notes/service.d.ts.map +1 -1
  193. package/dist/modules/notes/service.js +4 -7
  194. package/dist/modules/notes/service.js.map +1 -1
  195. package/dist/modules/opportunities/events.d.ts +31 -0
  196. package/dist/modules/opportunities/events.d.ts.map +1 -0
  197. package/dist/modules/opportunities/events.js +12 -0
  198. package/dist/modules/opportunities/events.js.map +1 -0
  199. package/dist/modules/opportunities/index.d.ts.map +1 -1
  200. package/dist/modules/opportunities/index.js +2 -0
  201. package/dist/modules/opportunities/index.js.map +1 -1
  202. package/dist/modules/opportunities/service.d.ts +1 -0
  203. package/dist/modules/opportunities/service.d.ts.map +1 -1
  204. package/dist/modules/opportunities/service.js +9 -18
  205. package/dist/modules/opportunities/service.js.map +1 -1
  206. package/dist/modules/partnerships/events.d.ts +31 -0
  207. package/dist/modules/partnerships/events.d.ts.map +1 -0
  208. package/dist/modules/partnerships/events.js +12 -0
  209. package/dist/modules/partnerships/events.js.map +1 -0
  210. package/dist/modules/partnerships/index.d.ts.map +1 -1
  211. package/dist/modules/partnerships/index.js +2 -0
  212. package/dist/modules/partnerships/index.js.map +1 -1
  213. package/dist/modules/partnerships/service.d.ts +1 -0
  214. package/dist/modules/partnerships/service.d.ts.map +1 -1
  215. package/dist/modules/partnerships/service.js +9 -18
  216. package/dist/modules/partnerships/service.js.map +1 -1
  217. package/dist/modules/people/events.d.ts +28 -0
  218. package/dist/modules/people/events.d.ts.map +1 -0
  219. package/dist/modules/people/events.js +18 -0
  220. package/dist/modules/people/events.js.map +1 -0
  221. package/dist/modules/people/index.d.ts.map +1 -1
  222. package/dist/modules/people/index.js +2 -0
  223. package/dist/modules/people/index.js.map +1 -1
  224. package/dist/modules/people/service.d.ts +1 -0
  225. package/dist/modules/people/service.d.ts.map +1 -1
  226. package/dist/modules/people/service.js +8 -11
  227. package/dist/modules/people/service.js.map +1 -1
  228. package/dist/modules/pipelines/service.d.ts +4 -0
  229. package/dist/modules/pipelines/service.d.ts.map +1 -1
  230. package/dist/modules/pipelines/service.js +31 -8
  231. package/dist/modules/pipelines/service.js.map +1 -1
  232. package/dist/modules/plans/events.d.ts +21 -0
  233. package/dist/modules/plans/events.d.ts.map +1 -0
  234. package/dist/modules/plans/events.js +11 -0
  235. package/dist/modules/plans/events.js.map +1 -0
  236. package/dist/modules/plans/index.d.ts.map +1 -1
  237. package/dist/modules/plans/index.js +2 -0
  238. package/dist/modules/plans/index.js.map +1 -1
  239. package/dist/modules/plans/service.d.ts +1 -0
  240. package/dist/modules/plans/service.d.ts.map +1 -1
  241. package/dist/modules/plans/service.js +6 -14
  242. package/dist/modules/plans/service.js.map +1 -1
  243. package/dist/modules/positions/events.d.ts +22 -0
  244. package/dist/modules/positions/events.d.ts.map +1 -0
  245. package/dist/modules/positions/events.js +8 -0
  246. package/dist/modules/positions/events.js.map +1 -0
  247. package/dist/modules/positions/index.d.ts.map +1 -1
  248. package/dist/modules/positions/index.js +2 -0
  249. package/dist/modules/positions/index.js.map +1 -1
  250. package/dist/modules/positions/service.d.ts +1 -0
  251. package/dist/modules/positions/service.d.ts.map +1 -1
  252. package/dist/modules/positions/service.js +8 -11
  253. package/dist/modules/positions/service.js.map +1 -1
  254. package/dist/modules/raises/events.d.ts +31 -0
  255. package/dist/modules/raises/events.d.ts.map +1 -0
  256. package/dist/modules/raises/events.js +12 -0
  257. package/dist/modules/raises/events.js.map +1 -0
  258. package/dist/modules/raises/index.d.ts.map +1 -1
  259. package/dist/modules/raises/index.js +2 -0
  260. package/dist/modules/raises/index.js.map +1 -1
  261. package/dist/modules/raises/service.d.ts +1 -0
  262. package/dist/modules/raises/service.d.ts.map +1 -1
  263. package/dist/modules/raises/service.js +9 -18
  264. package/dist/modules/raises/service.js.map +1 -1
  265. package/dist/modules/reseal.d.ts +55 -0
  266. package/dist/modules/reseal.d.ts.map +1 -1
  267. package/dist/modules/reseal.js +90 -1
  268. package/dist/modules/reseal.js.map +1 -1
  269. package/dist/modules/smtp-email/index.d.ts +69 -0
  270. package/dist/modules/smtp-email/index.d.ts.map +1 -0
  271. package/dist/modules/smtp-email/index.js +82 -0
  272. package/dist/modules/smtp-email/index.js.map +1 -0
  273. package/dist/modules/webhooks/index.d.ts.map +1 -1
  274. package/dist/modules/webhooks/index.js +5 -1
  275. package/dist/modules/webhooks/index.js.map +1 -1
  276. package/dist/modules/webhooks/payloads.d.ts +22 -7
  277. package/dist/modules/webhooks/payloads.d.ts.map +1 -1
  278. package/dist/modules/webhooks/payloads.js +63 -44
  279. package/dist/modules/webhooks/payloads.js.map +1 -1
  280. package/dist/modules/workspace/events.d.ts +52 -0
  281. package/dist/modules/workspace/events.d.ts.map +1 -0
  282. package/dist/modules/workspace/events.js +16 -0
  283. package/dist/modules/workspace/events.js.map +1 -0
  284. package/dist/modules/workspace/index.d.ts.map +1 -1
  285. package/dist/modules/workspace/index.js +6 -2
  286. package/dist/modules/workspace/index.js.map +1 -1
  287. package/dist/modules/workspace/service.d.ts +1 -0
  288. package/dist/modules/workspace/service.d.ts.map +1 -1
  289. package/dist/modules/workspace/service.js +13 -15
  290. package/dist/modules/workspace/service.js.map +1 -1
  291. package/dist/runtime/events.d.ts +86 -108
  292. package/dist/runtime/events.d.ts.map +1 -1
  293. package/dist/runtime/events.js +123 -52
  294. package/dist/runtime/events.js.map +1 -1
  295. package/dist/runtime/module.d.ts +54 -2
  296. package/dist/runtime/module.d.ts.map +1 -1
  297. package/dist/runtime/registry.d.ts +23 -0
  298. package/dist/runtime/registry.d.ts.map +1 -1
  299. package/dist/runtime/registry.js +102 -2
  300. package/dist/runtime/registry.js.map +1 -1
  301. package/dist/runtime/transaction.d.ts +29 -4
  302. package/dist/runtime/transaction.d.ts.map +1 -1
  303. package/dist/runtime/transaction.js +48 -7
  304. package/dist/runtime/transaction.js.map +1 -1
  305. package/dist/testing/app.d.ts +5 -1
  306. package/dist/testing/app.d.ts.map +1 -1
  307. package/dist/testing/app.js +13 -3
  308. package/dist/testing/app.js.map +1 -1
  309. package/dist/testing/database.d.ts.map +1 -1
  310. package/dist/testing/database.js +6 -3
  311. package/dist/testing/database.js.map +1 -1
  312. package/dist/testing/services.d.ts +21 -1
  313. package/dist/testing/services.d.ts.map +1 -1
  314. package/dist/testing/services.js +20 -5
  315. package/dist/testing/services.js.map +1 -1
  316. package/migrations/0019_sharp_red_skull.sql +4 -0
  317. package/migrations/0020_early_nemesis.sql +2 -0
  318. package/migrations/meta/0019_snapshot.json +5138 -0
  319. package/migrations/meta/0020_snapshot.json +5138 -0
  320. package/migrations/meta/_journal.json +14 -0
  321. package/package.json +5 -2
  322. package/src/app.ts +26 -0
  323. package/src/boot.ts +89 -0
  324. package/src/index.ts +52 -9
  325. package/src/lib/actor.ts +15 -1
  326. package/src/lib/config.ts +65 -7
  327. package/src/lib/email.ts +22 -92
  328. package/src/lib/fromEnv.ts +143 -0
  329. package/src/lib/ids.ts +6 -0
  330. package/src/lib/kelpieConfigFile.ts +291 -0
  331. package/src/lib/logger.ts +92 -34
  332. package/src/modules/agent-tasks/index.ts +4 -1
  333. package/src/modules/agent-tasks/prompt.ts +57 -9
  334. package/src/modules/agent-tasks/service.ts +3 -2
  335. package/src/modules/agent-tasks/wire.ts +12 -0
  336. package/src/modules/auth/index.ts +11 -9
  337. package/src/modules/companies/events.ts +25 -0
  338. package/src/modules/companies/index.ts +2 -0
  339. package/src/modules/companies/service.ts +8 -11
  340. package/src/modules/core.ts +4 -0
  341. package/src/modules/deals/events.ts +34 -0
  342. package/src/modules/deals/index.ts +2 -0
  343. package/src/modules/deals/service.ts +17 -18
  344. package/src/modules/decisions/events.ts +24 -0
  345. package/src/modules/decisions/index.ts +2 -0
  346. package/src/modules/decisions/service.ts +8 -7
  347. package/src/modules/eventCatalogs.ts +35 -0
  348. package/src/modules/forms/events.ts +37 -0
  349. package/src/modules/forms/index.ts +2 -0
  350. package/src/modules/forms/service.ts +12 -11
  351. package/src/modules/forms/submission.ts +80 -29
  352. package/src/modules/handbook/events.ts +31 -0
  353. package/src/modules/handbook/index.ts +2 -0
  354. package/src/modules/handbook/service.ts +8 -15
  355. package/src/modules/hiring/candidates.ts +8 -11
  356. package/src/modules/hiring/events.ts +36 -0
  357. package/src/modules/hiring/index.ts +2 -0
  358. package/src/modules/hiring/roles.ts +8 -11
  359. package/src/modules/import-export/drafts.ts +27 -0
  360. package/src/modules/import-export/events.ts +25 -0
  361. package/src/modules/import-export/exportRows.ts +10 -1
  362. package/src/modules/import-export/index.ts +2 -0
  363. package/src/modules/import-export/plan.ts +107 -5
  364. package/src/modules/import-export/presets.ts +25 -0
  365. package/src/modules/import-export/repository.ts +35 -1
  366. package/src/modules/import-export/routes.ts +5 -0
  367. package/src/modules/import-export/schema.ts +13 -0
  368. package/src/modules/import-export/service.ts +153 -19
  369. package/src/modules/import-export/tools.ts +9 -0
  370. package/src/modules/import-export/writes.ts +116 -3
  371. package/src/modules/notes/events.ts +25 -0
  372. package/src/modules/notes/index.ts +2 -0
  373. package/src/modules/notes/service.ts +8 -7
  374. package/src/modules/opportunities/events.ts +34 -0
  375. package/src/modules/opportunities/index.ts +2 -0
  376. package/src/modules/opportunities/service.ts +17 -18
  377. package/src/modules/partnerships/events.ts +34 -0
  378. package/src/modules/partnerships/index.ts +2 -0
  379. package/src/modules/partnerships/service.ts +17 -18
  380. package/src/modules/people/events.ts +36 -0
  381. package/src/modules/people/index.ts +2 -0
  382. package/src/modules/people/service.ts +97 -87
  383. package/src/modules/pipelines/service.ts +47 -8
  384. package/src/modules/plans/events.ts +24 -0
  385. package/src/modules/plans/index.ts +2 -0
  386. package/src/modules/plans/service.ts +14 -14
  387. package/src/modules/positions/events.ts +25 -0
  388. package/src/modules/positions/index.ts +2 -0
  389. package/src/modules/positions/service.ts +8 -11
  390. package/src/modules/raises/events.ts +34 -0
  391. package/src/modules/raises/index.ts +2 -0
  392. package/src/modules/raises/service.ts +17 -18
  393. package/src/modules/reseal.ts +144 -1
  394. package/src/modules/smtp-email/index.ts +119 -0
  395. package/src/modules/webhooks/index.ts +5 -1
  396. package/src/modules/webhooks/payloads.ts +94 -48
  397. package/src/modules/workspace/events.ts +46 -0
  398. package/src/modules/workspace/index.ts +6 -2
  399. package/src/modules/workspace/service.ts +37 -15
  400. package/src/runtime/events.ts +268 -107
  401. package/src/runtime/module.ts +55 -2
  402. package/src/runtime/registry.ts +169 -1
  403. package/src/runtime/transaction.ts +94 -17
  404. package/src/testing/app.ts +18 -4
  405. package/src/testing/database.ts +6 -3
  406. package/src/testing/services.ts +34 -5
@@ -7,14 +7,19 @@ import { moduleCapabilityName } from '../../runtime/moduleConfig.ts'
7
7
  import type { BufferedEvents, Transaction, TransactionScope } from '../../runtime/transaction.ts'
8
8
  import type { ActivityRecorder, SystemActor } from '../activities/recorder.ts'
9
9
  import { describeCreationVia, describeFormSubmission } from '../activities/wording.ts'
10
+ import '../companies/events.ts'
10
11
  import * as companyRepository from '../companies/repository.ts'
11
12
  import type { CompanyRecord } from '../companies/repository.ts'
12
13
  import * as dealRepository from '../deals/repository.ts'
14
+ import '../deals/events.ts'
15
+ import '../people/events.ts'
13
16
  import * as peopleRepository from '../people/repository.ts'
14
17
  import type { PersonRecord } from '../people/repository.ts'
15
18
  import * as pipelineRepository from '../pipelines/repository.ts'
19
+ import '../positions/events.ts'
16
20
  import * as positionRepository from '../positions/repository.ts'
17
21
  import * as workspaceRepository from '../workspace/repository.ts'
22
+ import './events.ts'
18
23
  import {
19
24
  DEAL_CLOSE_HORIZON_DAYS,
20
25
  companyNameFrom,
@@ -148,34 +153,80 @@ function emitRecordEvents(
148
153
  workspaceId: string,
149
154
  touched: TouchedRecords,
150
155
  ): void {
151
- const upserts = [
152
- { objectType: 'person', outcome: touched.person } as const,
153
- { objectType: 'company', outcome: touched.company } as const,
154
- { objectType: 'position', outcome: touched.position } as const,
155
- ]
156
-
157
- for (const { objectType, outcome } of upserts) {
158
- if (outcome === undefined) {
159
- continue
160
- }
156
+ if (touched.person !== undefined) {
157
+ emitUpsertEvent(events, 'person', touched.person)
158
+ }
159
+ if (touched.company !== undefined) {
160
+ emitUpsertEvent(events, 'company', touched.company)
161
+ }
162
+ if (touched.position !== undefined) {
163
+ emitUpsertEvent(events, 'position', touched.position)
164
+ }
161
165
 
162
- if (outcome.created) {
163
- events.emit('record.created', { workspaceId, objectType, recordId: outcome.record.id })
164
- continue
165
- }
166
+ if (touched.dealId !== null) {
167
+ events.emit('deals.deal.created', { type: 'deal', id: touched.dealId }, {})
168
+ }
169
+ // workspaceId is used by the transaction scope's envelope stamping; the
170
+ // parameter stays on the signature so future call sites keep the same shape.
171
+ void workspaceId
172
+ }
166
173
 
167
- if (outcome.filled.length > 0) {
168
- events.emit('record.updated', {
169
- workspaceId,
170
- objectType,
171
- recordId: outcome.record.id,
172
- changedFields: outcome.filled,
173
- })
174
+ /**
175
+ * Dispatches the created/updated event owned by the record's module for one
176
+ * upsert. Split from the loop above so TypeScript can correlate the object
177
+ * type with its typed event name at each call site.
178
+ */
179
+ function emitUpsertEvent(
180
+ events: BufferedEvents,
181
+ objectType: 'person' | 'company' | 'position',
182
+ outcome: { readonly created: boolean; readonly record: { readonly id: string }; readonly filled: readonly string[] },
183
+ ): void {
184
+ if (outcome.created) {
185
+ switch (objectType) {
186
+ case 'person':
187
+ events.emit('people.person.created', { type: 'person', id: outcome.record.id }, {})
188
+ return
189
+ case 'company':
190
+ events.emit('companies.company.created', { type: 'company', id: outcome.record.id }, {})
191
+ return
192
+ case 'position':
193
+ events.emit(
194
+ 'positions.position.created',
195
+ { type: 'position', id: outcome.record.id },
196
+ {},
197
+ )
198
+ return
174
199
  }
175
200
  }
176
201
 
177
- if (touched.dealId !== null) {
178
- events.emit('record.created', { workspaceId, objectType: 'deal', recordId: touched.dealId })
202
+ if (outcome.filled.length === 0) {
203
+ return
204
+ }
205
+
206
+ const changed = outcome.filled
207
+
208
+ switch (objectType) {
209
+ case 'person':
210
+ events.emit(
211
+ 'people.person.updated',
212
+ { type: 'person', id: outcome.record.id },
213
+ { changed },
214
+ )
215
+ return
216
+ case 'company':
217
+ events.emit(
218
+ 'companies.company.updated',
219
+ { type: 'company', id: outcome.record.id },
220
+ { changed },
221
+ )
222
+ return
223
+ case 'position':
224
+ events.emit(
225
+ 'positions.position.updated',
226
+ { type: 'position', id: outcome.record.id },
227
+ { changed },
228
+ )
229
+ return
179
230
  }
180
231
  }
181
232
 
@@ -484,11 +535,11 @@ export function createFormSubmitService(dependencies: SubmissionDependencies): F
484
535
  }
485
536
 
486
537
  emitRecordEvents(events, workspaceId, { person, company, position, dealId })
487
- events.emit('form.submitted', {
488
- workspaceId,
489
- formId: form.id,
490
- submissionId: submission.id,
491
- })
538
+ events.emit(
539
+ 'forms.submission.submitted',
540
+ { type: 'submission', id: submission.id },
541
+ { formId: form.id, submissionId: submission.id },
542
+ )
492
543
 
493
544
  return {
494
545
  submissionId: submission.id,
@@ -500,7 +551,7 @@ export function createFormSubmitService(dependencies: SubmissionDependencies): F
500
551
  submittedAt: submission.submittedAt,
501
552
  thankYouMessage: form.thankYouMessage,
502
553
  }
503
- })
554
+ }, { workspaceId })
504
555
  },
505
556
  }
506
557
  }
@@ -0,0 +1,31 @@
1
+ import { z } from 'zod'
2
+
3
+ import type { ModuleEventCatalog } from '../../runtime/module.ts'
4
+
5
+ /**
6
+ * Domain events published by the handbook module.
7
+ *
8
+ * Handbook pages are content objects, not CRM records — the target type is
9
+ * `handbook_page`, and the webhooks bridge does not (yet) deliver these to
10
+ * subscribers. They still fire on the bus for in-process consumers.
11
+ */
12
+
13
+ export const handbookEvents = {
14
+ 'handbook.page.created': z.object({}).strict(),
15
+ 'handbook.page.updated': z.object({ changed: z.array(z.string()).readonly() }),
16
+ 'handbook.page.deleted': z.object({}).strict(),
17
+ } satisfies ModuleEventCatalog
18
+
19
+ export type HandbookPageCreatedData = Record<string, never>
20
+ export interface HandbookPageUpdatedData {
21
+ readonly changed: readonly string[]
22
+ }
23
+ export type HandbookPageDeletedData = Record<string, never>
24
+
25
+ declare module '../../runtime/events.ts' {
26
+ interface KelpieEventMap {
27
+ 'handbook.page.created': HandbookPageCreatedData
28
+ 'handbook.page.updated': HandbookPageUpdatedData
29
+ 'handbook.page.deleted': HandbookPageDeletedData
30
+ }
31
+ }
@@ -1,4 +1,5 @@
1
1
  import type { KelpieModule } from '../../runtime/module.ts'
2
+ import { handbookEvents } from './events.ts'
2
3
  import { mountHandbookRoutes } from './routes.ts'
3
4
  import * as schema from './schema.ts'
4
5
  import { createHandbookService } from './service.ts'
@@ -20,6 +21,7 @@ export function createHandbookModule(migrationsDirectory: string): KelpieModule
20
21
  return {
21
22
  id: 'handbook',
22
23
  requires: ['workspace'],
24
+ events: handbookEvents,
23
25
 
24
26
  register(context) {
25
27
  const service = createHandbookService({
@@ -6,8 +6,10 @@ import type { IdFactory } from '../../lib/ids.ts'
6
6
  import { mapPage, readListWindow, toPage } from '../../lib/pagination.ts'
7
7
  import type { ListQueryParameters, Page } from '../../lib/pagination.ts'
8
8
  import type { Transaction, TransactionScope } from '../../runtime/transaction.ts'
9
+ import { toEventActor } from '../../lib/actor.ts'
9
10
  import type { Actor } from '../auth/actor.ts'
10
11
  import { actorMemberId, requireWorkspaceId } from '../auth/actor.ts'
12
+ import './events.ts'
11
13
  import * as repository from './repository.ts'
12
14
  import { DEFAULT_HANDBOOK_PAGE_SORT, HANDBOOK_PAGE_SORTS } from './repository.ts'
13
15
  import type { HandbookPageFilters, HandbookPageRecord } from './repository.ts'
@@ -292,11 +294,7 @@ export function createHandbookService(dependencies: HandbookDependencies): Handb
292
294
  updatedBy: actorMemberId(actor),
293
295
  })
294
296
 
295
- events.emit('record.created', {
296
- workspaceId,
297
- objectType: 'handbook_page',
298
- recordId: id,
299
- })
297
+ events.emit('handbook.page.created', { type: 'handbook_page', id }, {})
300
298
 
301
299
  return toView(created)
302
300
  } catch (error: unknown) {
@@ -308,7 +306,7 @@ export function createHandbookService(dependencies: HandbookDependencies): Handb
308
306
 
309
307
  throw error
310
308
  }
311
- })
309
+ }, { workspaceId, actor: toEventActor(actor) })
312
310
  },
313
311
 
314
312
  async update(actor, id, changes) {
@@ -346,16 +344,11 @@ export function createHandbookService(dependencies: HandbookDependencies): Handb
346
344
  const changed = [...written, ...movedFields]
347
345
 
348
346
  if (changed.length > 0) {
349
- events.emit('record.updated', {
350
- workspaceId,
351
- objectType: 'handbook_page',
352
- recordId: id,
353
- changedFields: changed,
354
- })
347
+ events.emit('handbook.page.updated', { type: 'handbook_page', id }, { changed })
355
348
  }
356
349
 
357
350
  return toView(updated)
358
- })
351
+ }, { workspaceId, actor: toEventActor(actor) })
359
352
  },
360
353
 
361
354
  /**
@@ -391,9 +384,9 @@ export function createHandbookService(dependencies: HandbookDependencies): Handb
391
384
  )
392
385
 
393
386
  for (const recordId of removed) {
394
- events.emit('record.deleted', { workspaceId, objectType: 'handbook_page', recordId })
387
+ events.emit('handbook.page.deleted', { type: 'handbook_page', id: recordId }, {})
395
388
  }
396
- })
389
+ }, { workspaceId, actor: toEventActor(actor) })
397
390
  },
398
391
  }
399
392
  }
@@ -12,8 +12,10 @@ import type { TransactionScope } from '../../runtime/transaction.ts'
12
12
  import type { ActivityRecorder } from '../activities/recorder.ts'
13
13
  import { describeLink, describeUnlink, describeUpdate } from '../activities/wording.ts'
14
14
  import type { FieldLabels } from '../activities/wording.ts'
15
+ import { toEventActor } from '../../lib/actor.ts'
15
16
  import type { Actor } from '../auth/actor.ts'
16
17
  import { requireWorkspaceId } from '../auth/actor.ts'
18
+ import './events.ts'
17
19
  import { deleteRecordsAttachedTo } from '../attachedRecords.ts'
18
20
  import * as repository from './repository.ts'
19
21
  import { DEFAULT_CANDIDATE_SORT, CANDIDATE_SORTS } from './repository.ts'
@@ -287,10 +289,10 @@ export function createCandidatesService(dependencies: CandidatesDependencies): C
287
289
  ...describeLink('role', roleTitle),
288
290
  })
289
291
 
290
- events.emit('record.created', { workspaceId, objectType: 'candidate', recordId: id })
292
+ events.emit('hiring.candidate.created', { type: 'candidate', id }, {})
291
293
 
292
294
  return toView(created)
293
- })
295
+ }, { workspaceId, actor: toEventActor(actor) })
294
296
  },
295
297
 
296
298
  async update(actor, id, changes) {
@@ -354,15 +356,10 @@ export function createCandidatesService(dependencies: CandidatesDependencies): C
354
356
  ),
355
357
  })
356
358
 
357
- events.emit('record.updated', {
358
- workspaceId,
359
- objectType: 'candidate',
360
- recordId: id,
361
- changedFields: changed,
362
- })
359
+ events.emit('hiring.candidate.updated', { type: 'candidate', id }, { changed })
363
360
 
364
361
  return toView(updated)
365
- })
362
+ }, { workspaceId, actor: toEventActor(actor) })
366
363
  },
367
364
 
368
365
  async remove(actor, id) {
@@ -384,8 +381,8 @@ export function createCandidatesService(dependencies: CandidatesDependencies): C
384
381
  ...describeUnlink('role', roleTitle),
385
382
  })
386
383
 
387
- events.emit('record.deleted', { workspaceId, objectType: 'candidate', recordId: id })
388
- })
384
+ events.emit('hiring.candidate.deleted', { type: 'candidate', id }, {})
385
+ }, { workspaceId, actor: toEventActor(actor) })
389
386
  },
390
387
  }
391
388
  }
@@ -0,0 +1,36 @@
1
+ import { z } from 'zod'
2
+
3
+ import type { ModuleEventCatalog } from '../../runtime/module.ts'
4
+
5
+ /** Domain events published by the hiring module (roles + candidates). */
6
+
7
+ export const hiringEvents = {
8
+ 'hiring.role.created': z.object({}).strict(),
9
+ 'hiring.role.updated': z.object({ changed: z.array(z.string()).readonly() }),
10
+ 'hiring.role.deleted': z.object({}).strict(),
11
+ 'hiring.candidate.created': z.object({}).strict(),
12
+ 'hiring.candidate.updated': z.object({ changed: z.array(z.string()).readonly() }),
13
+ 'hiring.candidate.deleted': z.object({}).strict(),
14
+ } satisfies ModuleEventCatalog
15
+
16
+ export type RoleCreatedData = Record<string, never>
17
+ export interface RoleUpdatedData {
18
+ readonly changed: readonly string[]
19
+ }
20
+ export type RoleDeletedData = Record<string, never>
21
+ export type CandidateCreatedData = Record<string, never>
22
+ export interface CandidateUpdatedData {
23
+ readonly changed: readonly string[]
24
+ }
25
+ export type CandidateDeletedData = Record<string, never>
26
+
27
+ declare module '../../runtime/events.ts' {
28
+ interface KelpieEventMap {
29
+ 'hiring.role.created': RoleCreatedData
30
+ 'hiring.role.updated': RoleUpdatedData
31
+ 'hiring.role.deleted': RoleDeletedData
32
+ 'hiring.candidate.created': CandidateCreatedData
33
+ 'hiring.candidate.updated': CandidateUpdatedData
34
+ 'hiring.candidate.deleted': CandidateDeletedData
35
+ }
36
+ }
@@ -1,6 +1,7 @@
1
1
  import type { KelpieModule } from '../../runtime/module.ts'
2
2
  import { createActivityRecorder } from '../activities/index.ts'
3
3
  import { createCandidatesService } from './candidates.ts'
4
+ import { hiringEvents } from './events.ts'
4
5
  import { createRolesService } from './roles.ts'
5
6
  import { mountHiringRoutes } from './routes.ts'
6
7
  import * as schema from './schema.ts'
@@ -22,6 +23,7 @@ export function createHiringModule(migrationsDirectory: string): KelpieModule {
22
23
  return {
23
24
  id: 'hiring',
24
25
  requires: ['people', 'activities'],
26
+ events: hiringEvents,
25
27
 
26
28
  register(context) {
27
29
  const recordActivity = createActivityRecorder({
@@ -9,8 +9,10 @@ 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 { describeUnlink } from '../activities/wording.ts'
12
+ import { toEventActor } from '../../lib/actor.ts'
12
13
  import type { Actor } from '../auth/actor.ts'
13
14
  import { requireWorkspaceId } from '../auth/actor.ts'
15
+ import './events.ts'
14
16
  import { deleteRecordsAttachedTo } from '../attachedRecords.ts'
15
17
  import * as repository from './repository.ts'
16
18
  import { DEFAULT_ROLE_SORT, ROLE_SORTS } from './repository.ts'
@@ -103,10 +105,10 @@ export function createRolesService(dependencies: RolesDependencies): RolesServic
103
105
  status: input.status,
104
106
  })
105
107
 
106
- events.emit('record.created', { workspaceId, objectType: 'role', recordId: id })
108
+ events.emit('hiring.role.created', { type: 'role', id }, {})
107
109
 
108
110
  return toView(created)
109
- })
111
+ }, { workspaceId, actor: toEventActor(actor) })
110
112
  },
111
113
 
112
114
  async update(actor, id, changes) {
@@ -129,15 +131,10 @@ export function createRolesService(dependencies: RolesDependencies): RolesServic
129
131
  throw AppError.notFound('Role not found')
130
132
  }
131
133
 
132
- events.emit('record.updated', {
133
- workspaceId,
134
- objectType: 'role',
135
- recordId: id,
136
- changedFields: changed,
137
- })
134
+ events.emit('hiring.role.updated', { type: 'role', id }, { changed })
138
135
 
139
136
  return toView(updated)
140
- })
137
+ }, { workspaceId, actor: toEventActor(actor) })
141
138
  },
142
139
 
143
140
  /**
@@ -167,8 +164,8 @@ export function createRolesService(dependencies: RolesDependencies): RolesServic
167
164
 
168
165
  await repository.deleteRole(tx, workspaceId, id)
169
166
 
170
- events.emit('record.deleted', { workspaceId, objectType: 'role', recordId: id })
171
- })
167
+ events.emit('hiring.role.deleted', { type: 'role', id }, {})
168
+ }, { workspaceId, actor: toEventActor(actor) })
172
169
  },
173
170
  }
174
171
  }
@@ -174,6 +174,33 @@ export function personDraft(mapped: Readonly<Record<string, string>>): PersonDra
174
174
  })
175
175
  }
176
176
 
177
+ /**
178
+ * The company a People row's affiliation would create.
179
+ *
180
+ * Built from the row's `company_domain` and `company_name` cells, not the
181
+ * `name`/`domain` a Companies file uses. The name falls back to the raw domain
182
+ * so a create from a domain-only row is not a nameless company. The write lays
183
+ * `NEW_COMPANY_DEFAULTS` over this, the same as a Companies import.
184
+ */
185
+ export function affiliationCompanyDraft(mapped: Readonly<Record<string, string>>): CompanyDraft {
186
+ const domainRaw = text(mapped, 'company_domain')
187
+
188
+ return present<CompanyDraft>({
189
+ name: text(mapped, 'company_name') ?? domainRaw,
190
+ domain: domainRaw === undefined ? undefined : (normaliseDomain(domainRaw) ?? undefined),
191
+ industry: undefined,
192
+ description: undefined,
193
+ stage: undefined,
194
+ sizeBand: undefined,
195
+ hq: undefined,
196
+ website: undefined,
197
+ accountType: undefined,
198
+ icpFit: undefined,
199
+ summary: undefined,
200
+ tags: undefined,
201
+ })
202
+ }
203
+
177
204
  /**
178
205
  * `value` is required, so `moneyToCents` has already been checked by
179
206
  * `validateRow` and cannot be undefined here.
@@ -0,0 +1,25 @@
1
+ import { z } from 'zod'
2
+
3
+ import type { ModuleEventCatalog } from '../../runtime/module.ts'
4
+
5
+ /**
6
+ * Domain events published by the import-export module.
7
+ *
8
+ * Record events (`people.person.created`, etc.) fire from this module during
9
+ * an import, but they are owned by the record's module and declared in its
10
+ * catalog. `imports.job.completed` is what this module owns.
11
+ */
12
+
13
+ export const importExportEvents = {
14
+ 'imports.job.completed': z.object({ object: z.string() }),
15
+ } satisfies ModuleEventCatalog
16
+
17
+ export interface ImportCompletedData {
18
+ readonly object: string
19
+ }
20
+
21
+ declare module '../../runtime/events.ts' {
22
+ interface KelpieEventMap {
23
+ 'imports.job.completed': ImportCompletedData
24
+ }
25
+ }
@@ -26,8 +26,17 @@ function joinList(values: readonly string[]): string {
26
26
  return values.join('|')
27
27
  }
28
28
 
29
+ /**
30
+ * The header row of an export and of a template.
31
+ *
32
+ * `importOnly` columns are left out: a People import may map `company_domain`,
33
+ * `company_name` and `title` to drive a Position, but a person holds many
34
+ * positions and none of them is a field on the person. Writing one on the export
35
+ * would be lossy, so the export and the template carry the round-trippable
36
+ * columns only, and each cell function matches this order one for one.
37
+ */
29
38
  export function headersFor(object: ImportObject): readonly string[] {
30
- return OBJECT_COLUMNS[object].map((column) => column.key)
39
+ return OBJECT_COLUMNS[object].filter((column) => column.importOnly !== true).map((column) => column.key)
31
40
  }
32
41
 
33
42
  export function companyCells(row: ExportCompanyRow): readonly string[] {
@@ -1,5 +1,6 @@
1
1
  import type { KelpieModule } from '../../runtime/module.ts'
2
2
  import { createActivityRecorder } from '../activities/index.ts'
3
+ import { importExportEvents } from './events.ts'
3
4
  import { mountImportExportRoutes } from './routes.ts'
4
5
  import * as schema from './schema.ts'
5
6
  import { createImportExportService } from './service.ts'
@@ -21,6 +22,7 @@ export function createImportExportModule(migrationsDirectory: string): KelpieMod
21
22
  return {
22
23
  id: 'import-export',
23
24
  requires: ['people', 'companies', 'positions', 'pipelines', 'deals', 'activities'],
25
+ events: importExportEvents,
24
26
 
25
27
  register(context) {
26
28
  const service = createImportExportService({