@burdenoff/be-sdk 2026.1110.1 → 2026.1110.3

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 (469) hide show
  1. package/configs/eslint/index.js +1 -1
  2. package/configs/tsconfig/tsconfig.json +1 -1
  3. package/dist/EventQueueFactory-9NGZV9jl.js +1457 -0
  4. package/dist/EventQueueFactory-9NGZV9jl.js.map +1 -0
  5. package/dist/RedisStreamsConnection-CY8WySJy.js +283 -0
  6. package/dist/RedisStreamsConnection-CY8WySJy.js.map +1 -0
  7. package/dist/ai-credits/index.d.ts +2 -3
  8. package/dist/ai-credits/index.js +3 -4
  9. package/dist/ai-credits/index.js.map +1 -1
  10. package/dist/ai-credits-Ca-NNcVx.js +546 -0
  11. package/dist/ai-credits-Ca-NNcVx.js.map +1 -0
  12. package/dist/{assistant-session-CJZhF4D6.d.ts → assistant-session-DA5ZKJOr.d.ts} +4 -5
  13. package/dist/auth/index.d.ts +2 -77
  14. package/dist/auth/index.js +3 -7
  15. package/dist/auth/index.js.map +1 -1
  16. package/dist/auth-CEuBEBQN.js +228 -0
  17. package/dist/auth-CEuBEBQN.js.map +1 -0
  18. package/dist/cache/index.d.ts +2 -3
  19. package/dist/cache/index.js +3 -7
  20. package/dist/cache/index.js.map +1 -1
  21. package/dist/cache-CU0uLwcS.js +1837 -0
  22. package/dist/cache-CU0uLwcS.js.map +1 -0
  23. package/dist/captcha/index.d.ts +2 -1
  24. package/dist/captcha/index.js +3 -3
  25. package/dist/captcha/index.js.map +1 -1
  26. package/dist/captcha-BT7yh1YS.js +77 -0
  27. package/dist/captcha-BT7yh1YS.js.map +1 -0
  28. package/dist/client/internal-client.d.ts +4 -7
  29. package/dist/client/internal-client.js +172 -4
  30. package/dist/client/internal-client.js.map +1 -1
  31. package/dist/client-BgAEvDC2.d.ts +86 -0
  32. package/dist/client-DcZ3iGES.js +565 -0
  33. package/dist/client-DcZ3iGES.js.map +1 -0
  34. package/dist/collector-endpoint-iyQYeI50.js +50 -0
  35. package/dist/collector-endpoint-iyQYeI50.js.map +1 -0
  36. package/dist/context-CZnXf2yb.js +247 -0
  37. package/dist/context-CZnXf2yb.js.map +1 -0
  38. package/dist/crypto/index.d.ts +2 -1
  39. package/dist/crypto/index.js +3 -3
  40. package/dist/crypto/index.js.map +1 -1
  41. package/dist/crypto-DO9fM0FO.js +145 -0
  42. package/dist/crypto-DO9fM0FO.js.map +1 -0
  43. package/dist/database/index.d.ts +104 -108
  44. package/dist/database/index.js +468 -6
  45. package/dist/database/index.js.map +1 -1
  46. package/dist/dataloader/index.d.ts +2 -1
  47. package/dist/dataloader/index.js +3 -3
  48. package/dist/dataloader/index.js.map +1 -1
  49. package/dist/dataloader-DwpT3YoS.js +294 -0
  50. package/dist/dataloader-DwpT3YoS.js.map +1 -0
  51. package/dist/deployed-environment-p_Tdl3sT.js +38 -0
  52. package/dist/deployed-environment-p_Tdl3sT.js.map +1 -0
  53. package/dist/dist-BGKdXVy3.js +1718 -0
  54. package/dist/dist-BGKdXVy3.js.map +1 -0
  55. package/dist/env-DdaoGjIt.js +74 -0
  56. package/dist/env-DdaoGjIt.js.map +1 -0
  57. package/dist/event-queue/index.d.ts +2 -7
  58. package/dist/event-queue/index.js +7 -9
  59. package/dist/event-queue/index.js.map +1 -1
  60. package/dist/event-queue-Cw-YJPY_.js +1384 -0
  61. package/dist/event-queue-Cw-YJPY_.js.map +1 -0
  62. package/dist/{explicit-activity-scope-CCoxVwAr.d.ts → explicit-activity-scope-D8VeGGpt.d.ts} +1 -2
  63. package/dist/export/index.d.ts +2 -2
  64. package/dist/export/index.js +3 -14
  65. package/dist/export/index.js.map +1 -1
  66. package/dist/export-B6fphx8a.js +642 -0
  67. package/dist/export-B6fphx8a.js.map +1 -0
  68. package/dist/feature-flags/index.d.ts +2 -10
  69. package/dist/feature-flags/index.js +3 -6
  70. package/dist/feature-flags/index.js.map +1 -1
  71. package/dist/feature-flags-71oDkrUe.js +422 -0
  72. package/dist/feature-flags-71oDkrUe.js.map +1 -0
  73. package/dist/files/index.d.ts +2 -3
  74. package/dist/files/index.js +3 -4
  75. package/dist/files/index.js.map +1 -1
  76. package/dist/files-DjH0099H.js +830 -0
  77. package/dist/files-DjH0099H.js.map +1 -0
  78. package/dist/gateway/index.d.ts +4 -6
  79. package/dist/gateway/index.js +7 -13
  80. package/dist/gateway/index.js.map +1 -1
  81. package/dist/gateway/security/index.d.ts +2 -2
  82. package/dist/gateway/security/index.js +3 -5
  83. package/dist/gateway/security/index.js.map +1 -1
  84. package/dist/gateway-DBFmxWks.js +50 -0
  85. package/dist/gateway-DBFmxWks.js.map +1 -0
  86. package/dist/graph/index.d.ts +3 -10
  87. package/dist/graph/index.js +4 -13
  88. package/dist/graph/index.js.map +1 -1
  89. package/dist/graph-DDYgIryR.js +2152 -0
  90. package/dist/graph-DDYgIryR.js.map +1 -0
  91. package/dist/graph-emitter-CdOXP7Tn.js +621 -0
  92. package/dist/graph-emitter-CdOXP7Tn.js.map +1 -0
  93. package/dist/graphql/index.d.ts +3 -2
  94. package/dist/graphql/index.js +4 -6
  95. package/dist/graphql/index.js.map +1 -1
  96. package/dist/graphql/services/index.d.ts +2 -24
  97. package/dist/graphql/services/index.js +3 -4
  98. package/dist/graphql/services/index.js.map +1 -1
  99. package/dist/graphql-DHAHHcww.js +161 -0
  100. package/dist/graphql-DHAHHcww.js.map +1 -0
  101. package/dist/graphql-DNkMkGBZ.d.ts +21 -0
  102. package/dist/i18n/index.d.ts +3 -3
  103. package/dist/i18n/index.js +3 -4
  104. package/dist/i18n/index.js.map +1 -1
  105. package/dist/i18n-BBMYFd0P.js +860 -0
  106. package/dist/i18n-BBMYFd0P.js.map +1 -0
  107. package/dist/import-optional-peer-B82VYxeX.js +18 -0
  108. package/dist/import-optional-peer-B82VYxeX.js.map +1 -0
  109. package/dist/index-3KOZ1zN9.d.ts +233 -0
  110. package/dist/index-BBqooJ52.d.ts +45 -0
  111. package/dist/index-BGzMYJsm.d.ts +209 -0
  112. package/dist/index-BKwHQtHQ.d.ts +63 -0
  113. package/dist/index-BMIMnp6T.d.ts +8 -0
  114. package/dist/index-BQDsNAMR.d.ts +81 -0
  115. package/dist/index-BVOL7458.d.ts +10 -0
  116. package/dist/index-BcqQs-Uq.d.ts +69 -0
  117. package/dist/index-BeVtqGO-.d.ts +208 -0
  118. package/dist/index-BiTzGUZP.d.ts +114 -0
  119. package/dist/index-BqYfCQSP.d.ts +500 -0
  120. package/dist/index-C0qLquY0.d.ts +150 -0
  121. package/dist/index-C5uEKchX.d.ts +60 -0
  122. package/dist/index-CDOqxSIi.d.ts +37 -0
  123. package/dist/index-CG6wj66Y.d.ts +148 -0
  124. package/dist/index-CIgoeobA.d.ts +145 -0
  125. package/dist/index-CPQDMSFS.d.ts +103 -0
  126. package/dist/index-CSRcgkVi.d.ts +23 -0
  127. package/dist/index-CZTnQIRU.d.ts +341 -0
  128. package/dist/index-CaM9JUcc.d.ts +144 -0
  129. package/dist/index-CkT2aUr3.d.ts +704 -0
  130. package/dist/index-CliOgq6L.d.ts +203 -0
  131. package/dist/index-CnzbJZP7.d.ts +999 -0
  132. package/dist/index-D6UeLAye.d.ts +63 -0
  133. package/dist/index-DGgh9DWn.d.ts +59 -0
  134. package/dist/index-DY3dNhMN.d.ts +420 -0
  135. package/dist/index-DZC-2o9R.d.ts +207 -0
  136. package/dist/index-DqbGqfAy.d.ts +127 -0
  137. package/dist/index-Dt1HJPTX.d.ts +12 -0
  138. package/dist/index-DtI6aBtB.d.ts +22 -0
  139. package/dist/index-FKohsiex.d.ts +38 -0
  140. package/dist/index-FbXPfen7.d.ts +132 -0
  141. package/dist/index-MArCb8Aq.d.ts +306 -0
  142. package/dist/index-N-huORcj.d.ts +303 -0
  143. package/dist/index-YOShAwkq.d.ts +45 -0
  144. package/dist/index-bZKZUvBu.d.ts +646 -0
  145. package/dist/index-yBSjMY32.d.ts +24 -0
  146. package/dist/index.d.ts +501 -544
  147. package/dist/index.js +1820 -2171
  148. package/dist/index.js.map +1 -1
  149. package/dist/init/index.d.ts +2 -2
  150. package/dist/init/index.js +3 -16
  151. package/dist/init/index.js.map +1 -1
  152. package/dist/init-Dy3KhT6Y.js +325 -0
  153. package/dist/init-Dy3KhT6Y.js.map +1 -0
  154. package/dist/instrumentation/index.d.ts +3 -4
  155. package/dist/instrumentation/index.js +5 -5
  156. package/dist/instrumentation/index.js.map +1 -1
  157. package/dist/instrumentation-xkkmDgJ0.js +1678 -0
  158. package/dist/instrumentation-xkkmDgJ0.js.map +1 -0
  159. package/dist/lake/index.d.ts +50 -54
  160. package/dist/lake/index.js +169 -193
  161. package/dist/lake/index.js.map +1 -1
  162. package/dist/layer/index.d.ts +3 -2
  163. package/dist/layer/index.js +4 -5
  164. package/dist/layer/index.js.map +1 -1
  165. package/dist/layer-BZBZZWeV.d.ts +69 -0
  166. package/dist/layer-Bcix-WCl.js +105 -0
  167. package/dist/layer-Bcix-WCl.js.map +1 -0
  168. package/dist/layer-CEKy6cm8.js +252 -0
  169. package/dist/layer-CEKy6cm8.js.map +1 -0
  170. package/dist/lifecycle/index.d.ts +2 -1
  171. package/dist/lifecycle/index.js +3 -4
  172. package/dist/lifecycle/index.js.map +1 -1
  173. package/dist/lifecycle-DeoLSX0U.js +76 -0
  174. package/dist/lifecycle-DeoLSX0U.js.map +1 -0
  175. package/dist/logger/index.d.ts +2 -3
  176. package/dist/logger/index.js +3 -3
  177. package/dist/logger/index.js.map +1 -1
  178. package/dist/logger-B6rCpb7D.js +290 -0
  179. package/dist/logger-B6rCpb7D.js.map +1 -0
  180. package/dist/metrics/index.d.ts +13 -14
  181. package/dist/metrics/index.js +3 -4
  182. package/dist/metrics/index.js.map +1 -1
  183. package/dist/metrics-BrLwNUrb.js +52 -0
  184. package/dist/metrics-BrLwNUrb.js.map +1 -0
  185. package/dist/metrics-collector-C2eShrlW.js +922 -0
  186. package/dist/metrics-collector-C2eShrlW.js.map +1 -0
  187. package/dist/middleware/index.d.ts +3 -3
  188. package/dist/middleware/index.js +3 -4
  189. package/dist/middleware/index.js.map +1 -1
  190. package/dist/middleware-CUxJVUpD.js +1243 -0
  191. package/dist/middleware-CUxJVUpD.js.map +1 -0
  192. package/dist/middleware-Cq0zFMGp.js +253 -0
  193. package/dist/middleware-Cq0zFMGp.js.map +1 -0
  194. package/dist/notifications/index.d.ts +2 -5
  195. package/dist/notifications/index.js +3 -6
  196. package/dist/notifications/index.js.map +1 -1
  197. package/dist/notifications-CdETrtFK.js +869 -0
  198. package/dist/notifications-CdETrtFK.js.map +1 -0
  199. package/dist/observability/index.d.ts +2 -3
  200. package/dist/observability/index.js +3 -4
  201. package/dist/observability/index.js.map +1 -1
  202. package/dist/observability-DBDXipTU.js +272 -0
  203. package/dist/observability-DBDXipTU.js.map +1 -0
  204. package/dist/platform/index.d.ts +2 -1
  205. package/dist/platform/index.js +3 -5
  206. package/dist/platform/index.js.map +1 -1
  207. package/dist/platform-DZwczW7v.js +1510 -0
  208. package/dist/platform-DZwczW7v.js.map +1 -0
  209. package/dist/prisma/generator/index.d.ts +1 -1
  210. package/dist/prisma/generator/index.js +97 -84
  211. package/dist/prisma/generator/index.js.map +1 -1
  212. package/dist/prisma/index.d.ts +4 -7
  213. package/dist/prisma/index.js +5 -12
  214. package/dist/prisma/index.js.map +1 -1
  215. package/dist/prisma-BzOOdt79.js +863 -0
  216. package/dist/prisma-BzOOdt79.js.map +1 -0
  217. package/dist/prisma-extension-Cfl09swM.d.ts +172 -0
  218. package/dist/product-alias/index.d.ts +2 -1
  219. package/dist/product-alias/index.js +3 -3
  220. package/dist/product-alias/index.js.map +1 -1
  221. package/dist/product-alias-BPqtskMq.js +273 -0
  222. package/dist/product-alias-BPqtskMq.js.map +1 -0
  223. package/dist/rbac/index.d.ts +2 -122
  224. package/dist/rbac/index.js +3 -6
  225. package/dist/rbac/index.js.map +1 -1
  226. package/dist/rbac-BB9l9Xph.js +1486 -0
  227. package/dist/rbac-BB9l9Xph.js.map +1 -0
  228. package/dist/resource-caps/index.d.ts +66 -72
  229. package/dist/resource-caps/index.js +430 -5
  230. package/dist/resource-caps/index.js.map +1 -1
  231. package/dist/rolldown-runtime-ad2WFvuA.js +17 -0
  232. package/dist/sdk-Dju9o-sq.js +124 -0
  233. package/dist/sdk-Dju9o-sq.js.map +1 -0
  234. package/dist/security-DIG-95Ic.js +1647 -0
  235. package/dist/security-DIG-95Ic.js.map +1 -0
  236. package/dist/server/index.d.ts +7 -164
  237. package/dist/server/index.js +2000 -1507
  238. package/dist/server/index.js.map +1 -1
  239. package/dist/service-jwt-Bu-WNA_-.js +80 -0
  240. package/dist/service-jwt-Bu-WNA_-.js.map +1 -0
  241. package/dist/services-BWzfz7vG.js +102 -0
  242. package/dist/services-BWzfz7vG.js.map +1 -0
  243. package/dist/sharding/index.d.ts +41 -44
  244. package/dist/sharding/index.js +156 -137
  245. package/dist/sharding/index.js.map +1 -1
  246. package/dist/sharing/index.d.ts +2 -1
  247. package/dist/sharing/index.js +3 -4
  248. package/dist/sharing/index.js.map +1 -1
  249. package/dist/sharing-CflDsSJ-.js +911 -0
  250. package/dist/sharing-CflDsSJ-.js.map +1 -0
  251. package/dist/stub-BqwKn4eh.js +630 -0
  252. package/dist/stub-BqwKn4eh.js.map +1 -0
  253. package/dist/tags/index.d.ts +2 -3
  254. package/dist/tags/index.js +3 -4
  255. package/dist/tags/index.js.map +1 -1
  256. package/dist/tags-B5xpbgsk.js +868 -0
  257. package/dist/{chunk-PBZFAAOM.js.map → tags-B5xpbgsk.js.map} +1 -1
  258. package/dist/telemetry/index.d.ts +64 -76
  259. package/dist/telemetry/index.js +369 -201
  260. package/dist/telemetry/index.js.map +1 -1
  261. package/dist/temporal/index.d.ts +2 -148
  262. package/dist/temporal/index.js +3 -5
  263. package/dist/temporal/index.js.map +1 -1
  264. package/dist/temporal-B534uYK8.js +706 -0
  265. package/dist/temporal-B534uYK8.js.map +1 -0
  266. package/dist/tracker/index.d.ts +5 -11
  267. package/dist/tracker/index.js +5 -20
  268. package/dist/tracker/index.js.map +1 -1
  269. package/dist/tracker-BQVoEFUo.js +839 -0
  270. package/dist/tracker-BQVoEFUo.js.map +1 -0
  271. package/dist/types-BYMYND1L.js +44 -0
  272. package/dist/types-BYMYND1L.js.map +1 -0
  273. package/dist/types-C6EKaS3V.d.ts +106 -0
  274. package/dist/types-CWybW61E.d.ts +323 -0
  275. package/dist/types-C_yfu3XK.d.ts +34 -0
  276. package/dist/types-Cj2RWXbz.js +90 -0
  277. package/dist/types-Cj2RWXbz.js.map +1 -0
  278. package/dist/types-DgaQqvxo.d.ts +70 -0
  279. package/dist/usage/index.d.ts +2 -213
  280. package/dist/usage/index.js +3 -15
  281. package/dist/usage/index.js.map +1 -1
  282. package/dist/usage-BKFZiWQn.js +682 -0
  283. package/dist/usage-BKFZiWQn.js.map +1 -0
  284. package/dist/utils/index.d.ts +2 -1
  285. package/dist/utils/index.js +3 -3
  286. package/dist/utils/index.js.map +1 -1
  287. package/dist/utils-DL85Tnbn.js +500 -0
  288. package/dist/utils-DL85Tnbn.js.map +1 -0
  289. package/dist/validation/index.d.ts +2 -2
  290. package/dist/validation/index.js +3 -3
  291. package/dist/validation/index.js.map +1 -1
  292. package/dist/validation-CPUITdMk.js +762 -0
  293. package/dist/validation-CPUITdMk.js.map +1 -0
  294. package/dist/workspace-extension-COrC0dYi.js +979 -0
  295. package/dist/workspace-extension-COrC0dYi.js.map +1 -0
  296. package/dist/{workspace-extension-BGwTOV_r.d.ts → workspace-extension-DTFTdGVF.d.ts} +43 -45
  297. package/package.json +7 -10
  298. package/dist/EventQueueFactory-PP534MBQ.js +0 -8
  299. package/dist/EventQueueFactory-PP534MBQ.js.map +0 -1
  300. package/dist/chunk-4XIBXZ6J.js +0 -276
  301. package/dist/chunk-4XIBXZ6J.js.map +0 -1
  302. package/dist/chunk-554Z4C2K.js +0 -1006
  303. package/dist/chunk-554Z4C2K.js.map +0 -1
  304. package/dist/chunk-5CAFHK2Z.js +0 -107
  305. package/dist/chunk-5CAFHK2Z.js.map +0 -1
  306. package/dist/chunk-63ZXJ42X.js +0 -451
  307. package/dist/chunk-63ZXJ42X.js.map +0 -1
  308. package/dist/chunk-6XEXJATV.js +0 -304
  309. package/dist/chunk-6XEXJATV.js.map +0 -1
  310. package/dist/chunk-726AR6Q7.js +0 -1532
  311. package/dist/chunk-726AR6Q7.js.map +0 -1
  312. package/dist/chunk-7EISSMFP.js +0 -617
  313. package/dist/chunk-7EISSMFP.js.map +0 -1
  314. package/dist/chunk-A5F6Z5UE.js +0 -21
  315. package/dist/chunk-A5F6Z5UE.js.map +0 -1
  316. package/dist/chunk-A6DE32ZS.js +0 -1507
  317. package/dist/chunk-A6DE32ZS.js.map +0 -1
  318. package/dist/chunk-BJQOGOVW.js +0 -602
  319. package/dist/chunk-BJQOGOVW.js.map +0 -1
  320. package/dist/chunk-CFXWH2IS.js +0 -52
  321. package/dist/chunk-CFXWH2IS.js.map +0 -1
  322. package/dist/chunk-DIOS6L7M.js +0 -690
  323. package/dist/chunk-DIOS6L7M.js.map +0 -1
  324. package/dist/chunk-DJNHR37J.js +0 -1185
  325. package/dist/chunk-DJNHR37J.js.map +0 -1
  326. package/dist/chunk-DRWH5XCJ.js +0 -876
  327. package/dist/chunk-DRWH5XCJ.js.map +0 -1
  328. package/dist/chunk-E4QNLVY4.js +0 -909
  329. package/dist/chunk-E4QNLVY4.js.map +0 -1
  330. package/dist/chunk-E6OAFS7A.js +0 -1346
  331. package/dist/chunk-E6OAFS7A.js.map +0 -1
  332. package/dist/chunk-EBDHIL7V.js +0 -774
  333. package/dist/chunk-EBDHIL7V.js.map +0 -1
  334. package/dist/chunk-ELU7VL3E.js +0 -245
  335. package/dist/chunk-ELU7VL3E.js.map +0 -1
  336. package/dist/chunk-FZRODKIN.js +0 -31
  337. package/dist/chunk-FZRODKIN.js.map +0 -1
  338. package/dist/chunk-GCIB76AJ.js +0 -882
  339. package/dist/chunk-GCIB76AJ.js.map +0 -1
  340. package/dist/chunk-HC6MPUIH.js +0 -1571
  341. package/dist/chunk-HC6MPUIH.js.map +0 -1
  342. package/dist/chunk-I3KOWRT3.js +0 -89
  343. package/dist/chunk-I3KOWRT3.js.map +0 -1
  344. package/dist/chunk-ID3WR4JS.js +0 -509
  345. package/dist/chunk-ID3WR4JS.js.map +0 -1
  346. package/dist/chunk-JVMAQOA3.js +0 -521
  347. package/dist/chunk-JVMAQOA3.js.map +0 -1
  348. package/dist/chunk-K56L7NUR.js +0 -1444
  349. package/dist/chunk-K56L7NUR.js.map +0 -1
  350. package/dist/chunk-KH4TRQCO.js +0 -1063
  351. package/dist/chunk-KH4TRQCO.js.map +0 -1
  352. package/dist/chunk-KJOSPVB2.js +0 -57
  353. package/dist/chunk-KJOSPVB2.js.map +0 -1
  354. package/dist/chunk-KO2ZXZ7W.js +0 -61
  355. package/dist/chunk-KO2ZXZ7W.js.map +0 -1
  356. package/dist/chunk-KS2HQCJR.js +0 -56
  357. package/dist/chunk-KS2HQCJR.js.map +0 -1
  358. package/dist/chunk-LA5KPWZ2.js +0 -413
  359. package/dist/chunk-LA5KPWZ2.js.map +0 -1
  360. package/dist/chunk-MESLAC5W.js +0 -574
  361. package/dist/chunk-MESLAC5W.js.map +0 -1
  362. package/dist/chunk-MWPYA2HD.js +0 -94
  363. package/dist/chunk-MWPYA2HD.js.map +0 -1
  364. package/dist/chunk-NUB5GQTU.js +0 -270
  365. package/dist/chunk-NUB5GQTU.js.map +0 -1
  366. package/dist/chunk-O2JMZHNH.js +0 -1908
  367. package/dist/chunk-O2JMZHNH.js.map +0 -1
  368. package/dist/chunk-OBBCR6WY.js +0 -277
  369. package/dist/chunk-OBBCR6WY.js.map +0 -1
  370. package/dist/chunk-OBZQ4AJC.js +0 -272
  371. package/dist/chunk-OBZQ4AJC.js.map +0 -1
  372. package/dist/chunk-OXNCBE7P.js +0 -971
  373. package/dist/chunk-OXNCBE7P.js.map +0 -1
  374. package/dist/chunk-PBZFAAOM.js +0 -941
  375. package/dist/chunk-PYD44IHJ.js +0 -728
  376. package/dist/chunk-PYD44IHJ.js.map +0 -1
  377. package/dist/chunk-QVPIACWD.js +0 -679
  378. package/dist/chunk-QVPIACWD.js.map +0 -1
  379. package/dist/chunk-QWNNFE4P.js +0 -41
  380. package/dist/chunk-QWNNFE4P.js.map +0 -1
  381. package/dist/chunk-RU266375.js +0 -327
  382. package/dist/chunk-RU266375.js.map +0 -1
  383. package/dist/chunk-RYTSVGGA.js +0 -1624
  384. package/dist/chunk-RYTSVGGA.js.map +0 -1
  385. package/dist/chunk-RZOFS2BQ.js +0 -225
  386. package/dist/chunk-RZOFS2BQ.js.map +0 -1
  387. package/dist/chunk-SBS4S2PJ.js +0 -100
  388. package/dist/chunk-SBS4S2PJ.js.map +0 -1
  389. package/dist/chunk-SPRG6G6G.js +0 -530
  390. package/dist/chunk-SPRG6G6G.js.map +0 -1
  391. package/dist/chunk-STWFX5E2.js +0 -233
  392. package/dist/chunk-STWFX5E2.js.map +0 -1
  393. package/dist/chunk-UNASM5VJ.js +0 -419
  394. package/dist/chunk-UNASM5VJ.js.map +0 -1
  395. package/dist/chunk-VAT66FJA.js +0 -245
  396. package/dist/chunk-VAT66FJA.js.map +0 -1
  397. package/dist/chunk-VFCMR5GX.js +0 -49
  398. package/dist/chunk-VFCMR5GX.js.map +0 -1
  399. package/dist/chunk-VGAHZKNJ.js +0 -66
  400. package/dist/chunk-VGAHZKNJ.js.map +0 -1
  401. package/dist/chunk-VTJTAAXC.js +0 -627
  402. package/dist/chunk-VTJTAAXC.js.map +0 -1
  403. package/dist/chunk-VXVLKRU6.js +0 -758
  404. package/dist/chunk-VXVLKRU6.js.map +0 -1
  405. package/dist/chunk-WWUU5ETI.js +0 -163
  406. package/dist/chunk-WWUU5ETI.js.map +0 -1
  407. package/dist/chunk-XE4OXN2W.js +0 -10
  408. package/dist/chunk-XE4OXN2W.js.map +0 -1
  409. package/dist/chunk-XOJORS75.js +0 -1853
  410. package/dist/chunk-XOJORS75.js.map +0 -1
  411. package/dist/chunk-YMZEUTD2.js +0 -110
  412. package/dist/chunk-YMZEUTD2.js.map +0 -1
  413. package/dist/chunk-ZZK3WEDI.js +0 -181
  414. package/dist/chunk-ZZK3WEDI.js.map +0 -1
  415. package/dist/client-CCXpAZ2r.d.ts +0 -89
  416. package/dist/client-DSI_760t.d.ts +0 -36
  417. package/dist/client-JU6T3UPB.js +0 -11
  418. package/dist/client-JU6T3UPB.js.map +0 -1
  419. package/dist/dist-2X4Q7PJA.js +0 -1491
  420. package/dist/dist-2X4Q7PJA.js.map +0 -1
  421. package/dist/env-4UWSUS64.js +0 -4
  422. package/dist/env-4UWSUS64.js.map +0 -1
  423. package/dist/graph-emitter-r5TylDBm.d.ts +0 -47
  424. package/dist/graphql-CMHMQjvd.d.ts +0 -23
  425. package/dist/i18n-Qm2AkPC-.d.ts +0 -33
  426. package/dist/index--yvpa6ay.d.ts +0 -83
  427. package/dist/index-4gKQKZ2B.d.ts +0 -71
  428. package/dist/index-5x0XMKXN.d.ts +0 -149
  429. package/dist/index-B70b5mYS.d.ts +0 -33
  430. package/dist/index-B8KrxO4j.d.ts +0 -755
  431. package/dist/index-BOuDKnqD.d.ts +0 -201
  432. package/dist/index-BTMt4OjA.d.ts +0 -201
  433. package/dist/index-BejbszA7.d.ts +0 -39
  434. package/dist/index-BkeOYZye.d.ts +0 -198
  435. package/dist/index-BuAj5nXg.d.ts +0 -83
  436. package/dist/index-BvkVcW8I.d.ts +0 -349
  437. package/dist/index-CWmH_-RZ.d.ts +0 -247
  438. package/dist/index-CbgWNcus.d.ts +0 -258
  439. package/dist/index-CmfPeQza.d.ts +0 -166
  440. package/dist/index-CmpG-zak.d.ts +0 -607
  441. package/dist/index-CoMKgL-p.d.ts +0 -12
  442. package/dist/index-D8HGwglK.d.ts +0 -541
  443. package/dist/index-DCaVm66D.d.ts +0 -1101
  444. package/dist/index-DE2w7E0d.d.ts +0 -83
  445. package/dist/index-DSOpj8DI.d.ts +0 -17
  446. package/dist/index-DW9q22GH.d.ts +0 -75
  447. package/dist/index-DnjJ9CwI.d.ts +0 -347
  448. package/dist/index-DwMJZ8PP.d.ts +0 -317
  449. package/dist/index-PaojfSdd.d.ts +0 -71
  450. package/dist/index-aHtYvc3i.d.ts +0 -284
  451. package/dist/index-e_18DzAg.d.ts +0 -18
  452. package/dist/index-ffmipXSA.d.ts +0 -55
  453. package/dist/index-joONjwLt.d.ts +0 -33
  454. package/dist/index-kssw5ziY.d.ts +0 -250
  455. package/dist/index-lFffh5-G.d.ts +0 -125
  456. package/dist/index-pxYge_6k.d.ts +0 -79
  457. package/dist/layer-Cv9vSwBx.d.ts +0 -70
  458. package/dist/pino-logger-H4HPW5P6.js +0 -5
  459. package/dist/pino-logger-H4HPW5P6.js.map +0 -1
  460. package/dist/prisma-extension-gYhYriA0.d.ts +0 -174
  461. package/dist/sdk-L75WWUP3.js +0 -156
  462. package/dist/sdk-L75WWUP3.js.map +0 -1
  463. package/dist/shutdown-registry-CW9LryO8.d.ts +0 -10
  464. package/dist/types-Bo2wkjSP.d.ts +0 -35
  465. package/dist/types-DVpvrAhd.d.ts +0 -71
  466. package/dist/types-DgJ4lDYA.d.ts +0 -108
  467. package/dist/types-USOv09qy.d.ts +0 -327
  468. package/dist/workspace-guard-NXVYYBVJ.js +0 -5
  469. package/dist/workspace-guard-NXVYYBVJ.js.map +0 -1
@@ -0,0 +1,1384 @@
1
+ import { t as __exportAll } from "./rolldown-runtime-ad2WFvuA.js";
2
+ import { a as RedisStreamsEventConsumer, l as QueueType, r as RedisStreamsEventPublisher, t as EventQueueFactory } from "./EventQueueFactory-9NGZV9jl.js";
3
+ import { c as matchSubject, d as streamKey, o as dlqKey, t as RedisStreamsConnection } from "./RedisStreamsConnection-CY8WySJy.js";
4
+ import { a as MemoryEventBus, c as MemoryEventQueue, d as createMemoryPublisher, i as resetGraphEventEmitter, l as createGraphEventEmitter$1, n as createGraphEventEmitter, o as MemoryEventConsumer, r as getGraphEventEmitter, s as MemoryEventPublisher, t as GraphEventEmitterImpl, u as createMemoryConsumer } from "./graph-emitter-CdOXP7Tn.js";
5
+ import { a as logger } from "./logger-B6rCpb7D.js";
6
+ import { a as resolveEventStreamsUrl, c as resolveGraphEventsUrlSource, i as eventKeyScopeForUrl, n as GRAPH_EVENTS_URL_ENV_KEYS, o as resolveEventStreamsUrlSource, s as resolveGraphEventsUrl, t as EVENT_STREAMS_URL_ENV_KEYS } from "./env-DdaoGjIt.js";
7
+ import { randomUUID } from "node:crypto";
8
+
9
+ // src/event-queue/module-events.ts
10
+ /**
11
+ * Module Events Service
12
+ *
13
+ * Generic event publishing service that modules can configure to publish
14
+ * domain-specific events to NATS JetStream.
15
+ *
16
+ * @module event-queue/module-events
17
+ * @category Events
18
+ *
19
+ * @example
20
+ * ```typescript
21
+ * import { createModuleEventsService } from '@burdenoff/be-sdk/event-queue';
22
+ *
23
+ * // Create a configured event service for the tags module
24
+ * const tagsEventsService = createModuleEventsService({
25
+ * moduleName: 'tags',
26
+ * entityTypes: ['Tag', 'Vocabulary', 'Assignment'],
27
+ * });
28
+ *
29
+ * // Publish events
30
+ * await tagsEventsService.publishCreated('Tag', tagId, tagData, userId);
31
+ * await tagsEventsService.publishUpdated('Vocabulary', vocabId, vocabData, userId);
32
+ * ```
33
+ */
34
+ /**
35
+ * Generic Module Events Service
36
+ *
37
+ * Provides a consistent interface for publishing domain events across all modules.
38
+ * Automatically falls back to in-memory publisher when NATS is not configured.
39
+ */
40
+ var ModuleEventsService = class {
41
+ productSource;
42
+ subjectPrefix;
43
+ loggerLabel;
44
+ publisher;
45
+ connected = false;
46
+ connecting = null;
47
+ constructor(config) {
48
+ this.productSource = config.moduleName;
49
+ this.subjectPrefix = config.subjectPrefix || config.moduleName;
50
+ this.loggerLabel = config.loggerLabel || `${config.moduleName.charAt(0).toUpperCase()}${config.moduleName.slice(1)}EventsService`;
51
+ if (process.env["REDIS_URL"]) {
52
+ this.publisher = EventQueueFactory.createPublisherFromEnv();
53
+ logger.info(`[${this.loggerLabel}] Using Redis Streams publisher`);
54
+ } else {
55
+ this.publisher = new MemoryEventPublisher();
56
+ logger.info(`[${this.loggerLabel}] Using in-memory publisher (REDIS_URL not configured)`);
57
+ }
58
+ }
59
+ /**
60
+ * Ensure publisher is connected before publishing
61
+ */
62
+ async ensureConnected() {
63
+ if (this.connected) return;
64
+ if (this.connecting) {
65
+ await this.connecting;
66
+ return;
67
+ }
68
+ this.connecting = this.publisher.connect().then(() => {
69
+ this.connected = true;
70
+ this.connecting = null;
71
+ logger.info(`[${this.loggerLabel}] Publisher connected`);
72
+ });
73
+ await this.connecting;
74
+ }
75
+ /**
76
+ * Publish an event to the queue
77
+ */
78
+ async publish(subject, payload) {
79
+ await this.ensureConnected();
80
+ await this.publisher.publish({
81
+ subject,
82
+ data: payload
83
+ });
84
+ }
85
+ /**
86
+ * Build event payload
87
+ */
88
+ buildPayload(type, action, id, data, userId, tenantId, workspaceId, correlationId) {
89
+ return {
90
+ id,
91
+ type,
92
+ action,
93
+ data,
94
+ metadata: {
95
+ tenantId,
96
+ workspaceId,
97
+ userId,
98
+ timestamp: (/* @__PURE__ */ new Date()).toISOString(),
99
+ productSource: this.productSource,
100
+ ...correlationId && { correlationId }
101
+ }
102
+ };
103
+ }
104
+ /**
105
+ * Build subject string
106
+ */
107
+ buildSubject(entityType, action) {
108
+ const normalizedType = entityType.replace(/^Universal/, "").replace(/([A-Z])/g, (_match, p1, offset) => (offset > 0 ? "_" : "") + p1.toLowerCase()).replace(/^_/, "");
109
+ return `${this.subjectPrefix}.${normalizedType}.${action}`;
110
+ }
111
+ /**
112
+ * Publish entity created event
113
+ */
114
+ async publishCreated(entityType, id, data, userId, tenantId, workspaceId) {
115
+ const payload = this.buildPayload(entityType, "created", id, data, userId, tenantId, workspaceId);
116
+ await this.publish(this.buildSubject(entityType, "created"), payload);
117
+ }
118
+ /**
119
+ * Publish entity updated event
120
+ */
121
+ async publishUpdated(entityType, id, data, userId, tenantId, workspaceId) {
122
+ const payload = this.buildPayload(entityType, "updated", id, data, userId, tenantId, workspaceId);
123
+ await this.publish(this.buildSubject(entityType, "updated"), payload);
124
+ }
125
+ /**
126
+ * Publish entity deleted event
127
+ */
128
+ async publishDeleted(entityType, id, userId, tenantId, workspaceId) {
129
+ const payload = this.buildPayload(entityType, "deleted", id, {}, userId, tenantId, workspaceId);
130
+ await this.publish(this.buildSubject(entityType, "deleted"), payload);
131
+ }
132
+ /**
133
+ * Publish custom action event
134
+ */
135
+ async publishCustom(entityType, action, id, data, userId, tenantId, workspaceId) {
136
+ const payload = this.buildPayload(entityType, action, id, data, userId, tenantId, workspaceId);
137
+ await this.publish(this.buildSubject(entityType, action), payload);
138
+ }
139
+ /**
140
+ * Publish bulk created event
141
+ */
142
+ async publishBulkCreated(_entityType, items, userId, tenantId, workspaceId) {
143
+ const payload = {
144
+ items,
145
+ metadata: {
146
+ tenantId,
147
+ workspaceId,
148
+ userId,
149
+ timestamp: (/* @__PURE__ */ new Date()).toISOString(),
150
+ productSource: this.productSource
151
+ }
152
+ };
153
+ await this.publish(`${this.subjectPrefix}.bulk.created`, payload);
154
+ }
155
+ /**
156
+ * Close event queue connection
157
+ */
158
+ async close() {
159
+ if (this.connected) {
160
+ await this.publisher.disconnect();
161
+ this.connected = false;
162
+ logger.info(`[${this.loggerLabel}] Publisher disconnected`);
163
+ }
164
+ }
165
+ /**
166
+ * Get health check status
167
+ */
168
+ async healthCheck() {
169
+ const result = await this.publisher.healthCheck();
170
+ const isHealthy = result.status === "healthy";
171
+ return {
172
+ healthy: isHealthy,
173
+ message: result.error || (isHealthy ? "Healthy" : "Unhealthy")
174
+ };
175
+ }
176
+ };
177
+ /**
178
+ * Create a module events service instance
179
+ */
180
+ function createModuleEventsService(config) {
181
+ return new ModuleEventsService(config);
182
+ }
183
+
184
+ // src/event-queue/events.ts
185
+ let EventPriority = /* @__PURE__ */ function(EventPriority) {
186
+ EventPriority["LOW"] = "low";
187
+ EventPriority["NORMAL"] = "normal";
188
+ EventPriority["HIGH"] = "high";
189
+ EventPriority["CRITICAL"] = "critical";
190
+ return EventPriority;
191
+ }({});
192
+ /**
193
+ * Events Module
194
+ */
195
+ var EventsModule = class {
196
+ client;
197
+ context;
198
+ constructor(client, context) {
199
+ this.client = client;
200
+ this.context = context;
201
+ }
202
+ /**
203
+ * Create stream
204
+ */
205
+ async createStream(name, subjects, options) {
206
+ logger.debug("[Events] Creating stream", {
207
+ name,
208
+ subjects
209
+ });
210
+ const mutation = `
211
+ mutation CreateStream($input: CreateStreamInput!) {
212
+ createStream(input: $input) {
213
+ name
214
+ subjects
215
+ messageCount
216
+ byteCount
217
+ firstSequence
218
+ lastSequence
219
+ consumerCount
220
+ }
221
+ }
222
+ `;
223
+ const variables = { input: {
224
+ name,
225
+ subjects,
226
+ maxMessages: options?.maxMessages,
227
+ maxBytes: options?.maxBytes,
228
+ maxAge: options?.maxAge,
229
+ storageType: options?.storageType || "file",
230
+ replicas: options?.replicas || 1
231
+ } };
232
+ const response = await this.client.query(mutation, variables, this.context);
233
+ logger.info("[Events] Stream created", { name });
234
+ return response.createStream;
235
+ }
236
+ /**
237
+ * Get stream info
238
+ */
239
+ async getStreamInfo(name) {
240
+ logger.debug("[Events] Getting stream info", { name });
241
+ return (await this.client.query(`
242
+ query GetStreamInfo($name: String!) {
243
+ getStreamInfo(name: $name) {
244
+ name
245
+ subjects
246
+ messageCount
247
+ byteCount
248
+ firstSequence
249
+ lastSequence
250
+ consumerCount
251
+ }
252
+ }
253
+ `, { name }, this.context)).getStreamInfo;
254
+ }
255
+ /**
256
+ * Delete stream
257
+ */
258
+ async deleteStream(name) {
259
+ logger.debug("[Events] Deleting stream", { name });
260
+ await this.client.query(`
261
+ mutation DeleteStream($name: String!) {
262
+ deleteStream(name: $name) {
263
+ success
264
+ }
265
+ }
266
+ `, { name }, this.context);
267
+ logger.info("[Events] Stream deleted", { name });
268
+ return true;
269
+ }
270
+ /**
271
+ * Purge stream messages
272
+ */
273
+ async purgeStream(name, options) {
274
+ logger.debug("[Events] Purging stream", {
275
+ name,
276
+ options
277
+ });
278
+ const response = await this.client.query(`
279
+ mutation PurgeStream($name: String!, $subject: String, $sequence: Int) {
280
+ purgeStream(name: $name, subject: $subject, sequence: $sequence) {
281
+ purgedCount
282
+ }
283
+ }
284
+ `, {
285
+ name,
286
+ subject: options?.subject,
287
+ sequence: options?.sequence
288
+ }, this.context);
289
+ logger.info("[Events] Stream purged", {
290
+ name,
291
+ purgedCount: response.purgeStream.purgedCount
292
+ });
293
+ return response.purgeStream.purgedCount;
294
+ }
295
+ /**
296
+ * Create consumer
297
+ */
298
+ async createConsumer(streamName, consumerName, options) {
299
+ logger.debug("[Events] Creating consumer", {
300
+ streamName,
301
+ consumerName
302
+ });
303
+ const mutation = `
304
+ mutation CreateConsumer($input: CreateConsumerInput!) {
305
+ createConsumer(input: $input) {
306
+ name
307
+ pending
308
+ }
309
+ }
310
+ `;
311
+ const variables = { input: {
312
+ streamName,
313
+ consumerName,
314
+ subject: options.subject,
315
+ queueGroup: options.queueGroup,
316
+ durableName: options.durableName,
317
+ startPosition: options.startPosition || "last",
318
+ ackMode: options.ackMode || "explicit",
319
+ maxDeliver: options.maxDeliver || 5,
320
+ ackWait: options.ackWait || 3e4
321
+ } };
322
+ const response = await this.client.query(mutation, variables, this.context);
323
+ logger.info("[Events] Consumer created", { consumerName });
324
+ return response.createConsumer;
325
+ }
326
+ /**
327
+ * Delete consumer
328
+ */
329
+ async deleteConsumer(streamName, consumerName) {
330
+ logger.debug("[Events] Deleting consumer", {
331
+ streamName,
332
+ consumerName
333
+ });
334
+ await this.client.query(`
335
+ mutation DeleteConsumer($streamName: String!, $consumerName: String!) {
336
+ deleteConsumer(streamName: $streamName, consumerName: $consumerName) {
337
+ success
338
+ }
339
+ }
340
+ `, {
341
+ streamName,
342
+ consumerName
343
+ }, this.context);
344
+ logger.info("[Events] Consumer deleted", { consumerName });
345
+ return true;
346
+ }
347
+ /**
348
+ * Acknowledge message
349
+ */
350
+ async ackMessage(streamName, consumerName, sequence) {
351
+ logger.debug("[Events] Acknowledging message", {
352
+ streamName,
353
+ consumerName,
354
+ sequence
355
+ });
356
+ await this.client.query(`
357
+ mutation AckMessage($streamName: String!, $consumerName: String!, $sequence: Int!) {
358
+ ackMessage(streamName: $streamName, consumerName: $consumerName, sequence: $sequence) {
359
+ success
360
+ }
361
+ }
362
+ `, {
363
+ streamName,
364
+ consumerName,
365
+ sequence
366
+ }, this.context);
367
+ return true;
368
+ }
369
+ /**
370
+ * Negative acknowledge message (requeue)
371
+ */
372
+ async nakMessage(streamName, consumerName, sequence) {
373
+ logger.debug("[Events] Negative acknowledging message", {
374
+ streamName,
375
+ consumerName,
376
+ sequence
377
+ });
378
+ await this.client.query(`
379
+ mutation NakMessage($streamName: String!, $consumerName: String!, $sequence: Int!) {
380
+ nakMessage(streamName: $streamName, consumerName: $consumerName, sequence: $sequence) {
381
+ success
382
+ }
383
+ }
384
+ `, {
385
+ streamName,
386
+ consumerName,
387
+ sequence
388
+ }, this.context);
389
+ return true;
390
+ }
391
+ /**
392
+ * Get consumer info
393
+ */
394
+ async getConsumerInfo(streamName, consumerName) {
395
+ logger.debug("[Events] Getting consumer info", {
396
+ streamName,
397
+ consumerName
398
+ });
399
+ return (await this.client.query(`
400
+ query GetConsumerInfo($streamName: String!, $consumerName: String!) {
401
+ getConsumerInfo(streamName: $streamName, consumerName: $consumerName) {
402
+ name
403
+ pending
404
+ redelivered
405
+ numAckPending
406
+ }
407
+ }
408
+ `, {
409
+ streamName,
410
+ consumerName
411
+ }, this.context)).getConsumerInfo;
412
+ }
413
+ };
414
+
415
+ // src/event-queue/factories.ts
416
+ /**
417
+ * Env-driven publisher / consumer constructors.
418
+ *
419
+ * Kept apart from `index.ts` so modules inside event-queue (EventsManager,
420
+ * lifecycle consumer) can use them without importing the barrel.
421
+ */
422
+ /**
423
+ * Create an event publisher from environment configuration.
424
+ *
425
+ * Backend resolution:
426
+ * - `REDIS_STREAMS_URL` or `REDIS_URL` set → Redis Streams (the only
427
+ * supported backend since the NATS retirement on 2026-05-16).
428
+ * `REDIS_STREAMS_URL` wins when both are set.
429
+ * - neither set → in-memory (dev/test fallback).
430
+ */
431
+ function createPublisher() {
432
+ if (resolveEventStreamsUrl()) return EventQueueFactory.createPublisherFromEnv();
433
+ return new MemoryEventPublisher();
434
+ }
435
+ /**
436
+ * Create an event consumer from environment configuration.
437
+ */
438
+ function createConsumer(stream, consumer) {
439
+ if (resolveEventStreamsUrl()) return EventQueueFactory.createConsumerFromEnv(stream, consumer);
440
+ return new MemoryEventConsumer(stream, consumer);
441
+ }
442
+
443
+ // src/event-queue/taxonomy.ts
444
+ /**
445
+ * Typed event taxonomy registry.
446
+ *
447
+ * EVENT_TAXONOMY.md (product-factory) names backend events
448
+ * `{domain}.{entity}.{action}`: past tense for facts, imperative for commands.
449
+ * Graph events are `graph.<module>.<Entity>.<created|updated|deleted>`.
450
+ * Until now those names were string literals scattered across services, so a
451
+ * typo was a consumer that never fired. This module makes them data:
452
+ *
453
+ * ```ts
454
+ * import { defineEventTaxonomy, eventSpec, publishTaxonomyEvent } from '@burdenoff/be-sdk/event-queue';
455
+ *
456
+ * export const VC_EVENTS = defineEventTaxonomy({
457
+ * 'vibecontrols.agent.connected': eventSpec<{ agentId: string; workspaceId: string }>({
458
+ * kind: 'fact', layer: 'wspace', producer: 'wspace-vibecontrols-svc', status: 'published',
459
+ * description: 'An agent opened its control channel.',
460
+ * }),
461
+ * });
462
+ *
463
+ * // Name and payload are both compile-checked:
464
+ * await publishTaxonomyEvent(publisher, VC_EVENTS, 'vibecontrols.agent.connected',
465
+ * { agentId, workspaceId }, { source: 'wspace-vibecontrols-svc', workspaceId, tenantId });
466
+ * ```
467
+ *
468
+ * `defineEventTaxonomy` also validates every name at module load, so a
469
+ * malformed name fails the service's unit tests instead of production.
470
+ *
471
+ * {@link PLATFORM_EVENT_TAXONOMY} records the platform events products consume,
472
+ * with the status they really have on main: `published` means a producer emits
473
+ * it today; `planned` means the name is reserved and no producer exists yet
474
+ * (consumers must not depend on it).
475
+ */
476
+ /** Brand set (non-enumerable) on registries built by {@link defineEventTaxonomy}. */
477
+ const EVENT_TAXONOMY_BRAND = Symbol.for("@burdenoff/be-sdk/event-taxonomy");
478
+ /** Build an {@link EventSpec} with a typed payload. */
479
+ function eventSpec(spec) {
480
+ return spec;
481
+ }
482
+ const FACT_OR_COMMAND_NAME = new RegExp(`^[a-z][a-z0-9_-]*(\\.[a-z][a-z0-9_]*){1,3}$`);
483
+ const GRAPH_NAME = /^graph\.[a-z][a-z0-9-]*\.[A-Za-z]\w*\.(created|updated|deleted)$/;
484
+ const SERVICE_NAME$2 = /^[a-z][a-z0-9-]*[a-z0-9]$/;
485
+ /** Why `name` is not a valid taxonomy name for `kind`, or `null` when it is. */
486
+ function taxonomyNameViolation(name, kind) {
487
+ if (kind === "graph") return GRAPH_NAME.test(name) ? null : "graph events are graph.<module>.<Entity>.<created|updated|deleted>";
488
+ if (name.startsWith("graph.")) return "the graph. prefix is reserved for graph events (kind: graph)";
489
+ if (!FACT_OR_COMMAND_NAME.test(name)) return "names are {domain}.{entity}.{action}: 2-4 lower-case dot-separated segments";
490
+ return null;
491
+ }
492
+ /**
493
+ * Validate and freeze a registry. Throws on the first malformed entry, so
494
+ * registries defined at module scope fail fast in unit tests.
495
+ */
496
+ function defineEventTaxonomy(registry) {
497
+ for (const [name, spec] of Object.entries(registry)) {
498
+ const violation = taxonomyNameViolation(name, spec.kind);
499
+ if (violation) throw new Error(`[EventTaxonomy] Invalid event name "${name}": ${violation}`);
500
+ if (!SERVICE_NAME$2.test(spec.producer)) throw new Error(`[EventTaxonomy] Event "${name}" has an invalid producer "${spec.producer}"`);
501
+ if (!spec.description.trim()) throw new Error(`[EventTaxonomy] Event "${name}" needs a description`);
502
+ if (spec.stream !== void 0 && !/^[A-Za-z0-9_.:-]+$/.test(spec.stream)) throw new Error(`[EventTaxonomy] Event "${name}" has an invalid stream "${spec.stream}"`);
503
+ }
504
+ const copy = { ...registry };
505
+ Object.defineProperty(copy, EVENT_TAXONOMY_BRAND, {
506
+ value: true,
507
+ enumerable: false
508
+ });
509
+ return Object.freeze(copy);
510
+ }
511
+ /** True when `registry` came from {@link defineEventTaxonomy}. */
512
+ function isDefinedEventTaxonomy(registry) {
513
+ return typeof registry === "object" && registry !== null && registry[EVENT_TAXONOMY_BRAND] === true;
514
+ }
515
+ /** Event names in a registry, sorted. */
516
+ function taxonomyEventNames(registry) {
517
+ return Object.keys(registry).sort((x, y) => x.localeCompare(y));
518
+ }
519
+ /** Merge registries; a name defined twice with different specs throws. */
520
+ function mergeEventTaxonomies(a, b) {
521
+ for (const name of Object.keys(b)) if (name in a && a[name] !== b[name]) throw new Error(`[EventTaxonomy] Event "${name}" is defined in both registries`);
522
+ return defineEventTaxonomy({
523
+ ...a,
524
+ ...b
525
+ });
526
+ }
527
+ /**
528
+ * Publish a registered fact or command. The name must exist in `registry`
529
+ * (compile time and run time), graph events are refused (the graph emitter
530
+ * owns them), and the spec's `stream` is applied so publisher and consumers
531
+ * agree on the key.
532
+ */
533
+ async function publishTaxonomyEvent(publisher, registry, name, payload, metadata, options = {}) {
534
+ const spec = registry[name];
535
+ if (!spec) throw new Error(`[EventTaxonomy] Event "${name}" is not registered`);
536
+ if (spec.kind === "graph") throw new Error(`[EventTaxonomy] "${name}" is a graph event; publish it through the module graph emitter`);
537
+ if (!metadata.source.trim()) throw new Error(`[EventTaxonomy] Event "${name}" needs metadata.source`);
538
+ return publisher.publish({
539
+ subject: name,
540
+ data: payload,
541
+ metadata: {
542
+ ...metadata,
543
+ correlationId: metadata.correlationId ?? randomUUID()
544
+ },
545
+ options: spec.stream ? {
546
+ ...options,
547
+ stream: spec.stream
548
+ } : options
549
+ });
550
+ }
551
+ /** Stream that carries every graph entity event (`GRAPH_SYNC_STREAM_NAME`). */
552
+ const WSPACE_GRAPH_EVENTS_STREAM = "WSPACE_GRAPH_EVENTS";
553
+ /**
554
+ * Platform events a product may consume, with their real status on main
555
+ * (audited 2026-10-21 against wspace-workspace-svc, global-tenant-svc,
556
+ * global-auth-svc and global-billing-svc).
557
+ */
558
+ const PLATFORM_EVENT_TAXONOMY = defineEventTaxonomy({
559
+ "workspace.created": eventSpec({
560
+ kind: "fact",
561
+ layer: "wspace",
562
+ producer: "wspace-workspace-svc",
563
+ status: "published",
564
+ pii: "names",
565
+ description: "A workspace was created (also re-published when synced from the global layer)."
566
+ }),
567
+ "workspace.initialized": eventSpec({
568
+ kind: "fact",
569
+ layer: "wspace",
570
+ producer: "wspace-workspace-svc",
571
+ status: "published",
572
+ pii: "names",
573
+ description: "A new workspace finished provisioning its default resources."
574
+ }),
575
+ "workspace.member.added": eventSpec({
576
+ kind: "fact",
577
+ layer: "wspace",
578
+ producer: "wspace-workspace-svc",
579
+ status: "published",
580
+ description: "A user became a member of a workspace."
581
+ }),
582
+ "workspace.member.removed": eventSpec({
583
+ kind: "fact",
584
+ layer: "wspace",
585
+ producer: "wspace-workspace-svc",
586
+ status: "published",
587
+ description: "A user was removed from a workspace. Revoke what the user held in that workspace."
588
+ }),
589
+ "workspace.member.role_updated": eventSpec({
590
+ kind: "fact",
591
+ layer: "wspace",
592
+ producer: "wspace-workspace-svc",
593
+ status: "published",
594
+ description: "A member's workspace roles changed."
595
+ }),
596
+ "workspace.deleted": eventSpec({
597
+ kind: "fact",
598
+ layer: "wspace",
599
+ producer: "wspace-workspace-svc",
600
+ status: "planned",
601
+ description: "Reserved. Deletion is published today only as graph.module-workspace.Workspace.deleted; the lifecycle consumer reads both."
602
+ }),
603
+ "graph.module-workspace.Workspace.deleted": eventSpec({
604
+ kind: "graph",
605
+ layer: "wspace",
606
+ producer: "wspace-workspace-svc",
607
+ status: "published",
608
+ stream: WSPACE_GRAPH_EVENTS_STREAM,
609
+ description: "Graph event for a soft-deleted workspace (status DELETED, deletedAt set)."
610
+ }),
611
+ "organization.deleted": eventSpec({
612
+ kind: "fact",
613
+ layer: "global",
614
+ producer: "global-tenant-svc",
615
+ status: "published",
616
+ description: "An organization was deleted. Global-layer stream: wspace services cannot read it."
617
+ }),
618
+ "user.deleted": eventSpec({
619
+ kind: "fact",
620
+ layer: "global",
621
+ producer: "global-auth-svc",
622
+ status: "planned",
623
+ description: "Reserved. No producer yet: products must check user state lazily at read time."
624
+ }),
625
+ "subscription.created": eventSpec({
626
+ kind: "fact",
627
+ layer: "global",
628
+ producer: "global-billing-svc",
629
+ status: "planned",
630
+ description: "Reserved. No producer yet: entitlement is checked lazily at quota/usage time."
631
+ }),
632
+ "subscription.updated": eventSpec({
633
+ kind: "fact",
634
+ layer: "global",
635
+ producer: "global-billing-svc",
636
+ status: "planned",
637
+ description: "Reserved. No producer yet: entitlement is checked lazily at quota/usage time."
638
+ }),
639
+ "subscription.cancelled": eventSpec({
640
+ kind: "fact",
641
+ layer: "global",
642
+ producer: "global-billing-svc",
643
+ status: "planned",
644
+ description: "Reserved. No producer yet: entitlement is checked lazily at quota/usage time."
645
+ })
646
+ });
647
+ /**
648
+ * Product facts of the two reference products, defined here so other products
649
+ * (cross-product nodes, webhooks) can consume them with types. `planned` until
650
+ * the producing service ships its publisher.
651
+ */
652
+ const REFERENCE_PRODUCT_EVENT_TAXONOMY = defineEventTaxonomy({
653
+ "vibecontrols.agent.connected": eventSpec({
654
+ kind: "fact",
655
+ layer: "wspace",
656
+ producer: "wspace-vibecontrols-svc",
657
+ status: "planned",
658
+ description: "An agent opened its control channel to VibeControls."
659
+ }),
660
+ "vibecontrols.agent.disconnected": eventSpec({
661
+ kind: "fact",
662
+ layer: "wspace",
663
+ producer: "wspace-vibecontrols-svc",
664
+ status: "planned",
665
+ description: "An agent control channel closed or timed out."
666
+ }),
667
+ "vibecontrols.session.started": eventSpec({
668
+ kind: "fact",
669
+ layer: "wspace",
670
+ producer: "wspace-vibecontrols-svc",
671
+ status: "planned",
672
+ description: "A VibeControls session started on an agent."
673
+ }),
674
+ "vibecontrols.session.ended": eventSpec({
675
+ kind: "fact",
676
+ layer: "wspace",
677
+ producer: "wspace-vibecontrols-svc",
678
+ status: "planned",
679
+ description: "A VibeControls session ended."
680
+ }),
681
+ "workflow.run.started": eventSpec({
682
+ kind: "fact",
683
+ layer: "wspace",
684
+ producer: "wspace-workflow-svc",
685
+ status: "planned",
686
+ description: "A FluidGrids workflow run started (fact; the internal run.run.status stays as is)."
687
+ }),
688
+ "workflow.run.completed": eventSpec({
689
+ kind: "fact",
690
+ layer: "wspace",
691
+ producer: "wspace-workflow-svc",
692
+ status: "planned",
693
+ description: "A FluidGrids workflow run completed successfully."
694
+ }),
695
+ "workflow.run.failed": eventSpec({
696
+ kind: "fact",
697
+ layer: "wspace",
698
+ producer: "wspace-workflow-svc",
699
+ status: "planned",
700
+ description: "A FluidGrids workflow run failed."
701
+ })
702
+ });
703
+
704
+ // src/event-queue/events-manager.ts
705
+ /**
706
+ * EventsManager: one publisher plus per-group consumers behind a small
707
+ * subject-routing surface.
708
+ *
709
+ * Lifted from wspace-workflow-svc and fluidgrids-workers
710
+ * `src/services/events/manager.ts` (two drifted copies of the same wrapper;
711
+ * this keeps the fluidgrids-workers improvements: a promise-guarded singleton,
712
+ * an unsubscribe handle, and a REDIS_URL fail-fast).
713
+ *
714
+ * ```ts
715
+ * const events = createEventsManagerSingleton({
716
+ * serviceName: 'wspace-workflow-svc',
717
+ * streamRoutes: [
718
+ * { subject: 'workflow.jobs.start', stream: 'WORKFLOW_JOBS' },
719
+ * { subject: 'run.>', stream: 'WORKFLOW_EVENTS' },
720
+ * ],
721
+ * defaultStream: 'WORKFLOW_EVENTS',
722
+ * maxDeliver: 5,
723
+ * });
724
+ * export const getEventsManager = events.get;
725
+ * export const closeEventsManager = events.close;
726
+ * ```
727
+ *
728
+ * Messages keep the NATS `JsMsg`-shaped surface the workflow handlers were
729
+ * written against (`subject`, `data: Uint8Array`, `ack()`, `nak(delay?)`) and
730
+ * add the decoded `payload` and the raw `event`.
731
+ *
732
+ * Two behaviours differ deliberately from the copies it replaces:
733
+ * - Subject filtering is strict by default. On an aggregated stream the
734
+ * Redis consumer hands an exact-subject subscription EVERY entry on the
735
+ * stream; the manager now acks and skips entries whose subject does not
736
+ * match (`strictSubjectFilter: false` restores the old pass-through).
737
+ * - Two subscriptions on the same stream with the same consumer group in
738
+ * one process are refused: they would split the group's entries between
739
+ * them, so each handler would silently miss part of its traffic.
740
+ */
741
+ const SERVICE_NAME$1 = /^[a-z][a-z0-9-]*[a-z0-9]$/;
742
+ function errorMessage$1(error) {
743
+ return error instanceof Error ? error.message : String(error);
744
+ }
745
+ function encodePayload(payload) {
746
+ return new TextEncoder().encode(JSON.stringify(payload ?? null));
747
+ }
748
+ function toMessage(event) {
749
+ return {
750
+ subject: event.subject,
751
+ data: encodePayload(event.data),
752
+ payload: event.data,
753
+ event,
754
+ ack() {
755
+ event.ack().catch((err) => logger.warn("[Events] ack failed", { error: errorMessage$1(err) }));
756
+ },
757
+ nak(delay) {
758
+ event.nak(delay).catch((err) => logger.warn("[Events] nak failed", { error: errorMessage$1(err) }));
759
+ },
760
+ term() {
761
+ event.term().catch((err) => logger.warn("[Events] term failed", { error: errorMessage$1(err) }));
762
+ }
763
+ };
764
+ }
765
+ var EventsManager = class {
766
+ publisher = null;
767
+ publisherConnecting = null;
768
+ consumers = /* @__PURE__ */ new Map();
769
+ active = /* @__PURE__ */ new Map();
770
+ serviceName;
771
+ routes;
772
+ defaultStream;
773
+ maxDeliver;
774
+ strict;
775
+ requireRedisUrl;
776
+ publisherFactory;
777
+ consumerFactory;
778
+ constructor(options) {
779
+ if (!SERVICE_NAME$1.test(options.serviceName)) throw new Error(`[Events] serviceName "${options.serviceName}" must be a kebab-case service name`);
780
+ const maxDeliver = options.maxDeliver ?? 5;
781
+ if (!Number.isInteger(maxDeliver) || maxDeliver < 1) throw new Error("[Events] maxDeliver must be a positive integer");
782
+ this.serviceName = options.serviceName;
783
+ this.routes = [...options.streamRoutes ?? []];
784
+ this.defaultStream = options.defaultStream;
785
+ this.maxDeliver = maxDeliver;
786
+ this.strict = options.strictSubjectFilter ?? true;
787
+ this.requireRedisUrl = options.requireRedisUrl ?? false;
788
+ this.publisherFactory = options.publisherFactory ?? createPublisher;
789
+ this.consumerFactory = options.consumerFactory ?? createConsumer;
790
+ }
791
+ /** Create and connect the shared publisher. Idempotent and safe to call concurrently. */
792
+ async connect() {
793
+ if (this.publisher?.isConnected()) return;
794
+ this.publisherConnecting ??= this.connectPublisher().finally(() => {
795
+ this.publisherConnecting = null;
796
+ });
797
+ await this.publisherConnecting;
798
+ }
799
+ assertBusConfigured() {
800
+ if (this.requireRedisUrl && !resolveEventStreamsUrl()) throw new Error(`[Events] ${this.serviceName}: neither REDIS_STREAMS_URL nor REDIS_URL is set, so events would go to an in-process bus. Point it at the same Valkey (and DB index) as the services it talks to.`);
801
+ }
802
+ async connectPublisher() {
803
+ this.assertBusConfigured();
804
+ const publisher = this.publisher ?? this.publisherFactory();
805
+ await publisher.connect();
806
+ this.publisher = publisher;
807
+ const url = resolveEventStreamsUrl();
808
+ logger.info("[Events] Publisher connected", {
809
+ service: this.serviceName,
810
+ urlSource: resolveEventStreamsUrlSource() ?? "in-memory",
811
+ keyScope: eventKeyScopeForUrl(url) || "(none)"
812
+ });
813
+ }
814
+ /**
815
+ * Publish a JSON-serialisable payload. The stream comes from the routes,
816
+ * else `defaultStream`, else the per-subject stream.
817
+ */
818
+ async publish(subject, payload, metadata) {
819
+ await this.connect();
820
+ const publisher = this.publisher;
821
+ if (!publisher) throw new Error("[Events] publisher not initialized");
822
+ const stream = this.resolveStream(subject);
823
+ try {
824
+ await publisher.publish({
825
+ subject,
826
+ data: payload,
827
+ metadata: {
828
+ source: this.serviceName,
829
+ ...metadata
830
+ },
831
+ ...stream ? { options: { stream } } : {}
832
+ });
833
+ } catch (error) {
834
+ logger.error(`[Events] Failed to publish to ${subject}`, { error: errorMessage$1(error) });
835
+ throw error;
836
+ }
837
+ }
838
+ /**
839
+ * Subscribe with a durable consumer group. `consumerName` IS the Redis
840
+ * consumer-group name: replicas sharing it split the work (queue
841
+ * semantics); services that each need every entry must use distinct names.
842
+ * Omitted, it is derived as `<serviceName>-<subject>`.
843
+ *
844
+ * A throwing handler naks the entry; it is redelivered until `maxDeliver`,
845
+ * then dead-lettered. Returns an unsubscribe handle.
846
+ */
847
+ async subscribe(subject, handler, consumerName, options = {}) {
848
+ this.assertBusConfigured();
849
+ const stream = options.stream ?? this.resolveStream(subject);
850
+ const group = consumerName ?? this.consumerNameFor(subject);
851
+ const streamLabel = stream ?? `subject:${subject}`;
852
+ const key = `${streamLabel}|${group}`;
853
+ if (this.active.has(key)) throw new Error(`[Events] ${group} already has a subscription on ${streamLabel}; a second one would split its entries. Use a distinct consumer name per subscription.`);
854
+ let consumer = this.consumers.get(group);
855
+ if (!consumer) {
856
+ consumer = this.consumerFactory(stream ?? subject, group);
857
+ await consumer.connect();
858
+ this.consumers.set(group, consumer);
859
+ }
860
+ const strict = this.strict;
861
+ const subscription = await consumer.subscribe({
862
+ subject,
863
+ handler: async (event) => {
864
+ if (strict && !matchSubject(subject, event.subject)) {
865
+ await event.ack();
866
+ return;
867
+ }
868
+ try {
869
+ await handler(toMessage(event));
870
+ } catch (error) {
871
+ logger.error("[Events] Handler error", {
872
+ subject: event.subject,
873
+ error: errorMessage$1(error)
874
+ });
875
+ await event.nak();
876
+ }
877
+ },
878
+ options: {
879
+ consumer: group,
880
+ ...stream ? { stream } : {},
881
+ maxDeliver: options.maxDeliver ?? this.maxDeliver,
882
+ ackPolicy: "explicit",
883
+ deliverPolicy: options.deliverPolicy ?? "new",
884
+ ...options.concurrency !== void 0 ? { concurrency: options.concurrency } : {},
885
+ ...options.drainTimeoutMs !== void 0 ? { drainTimeoutMs: options.drainTimeoutMs } : {}
886
+ }
887
+ });
888
+ this.active.set(key, subscription);
889
+ logger.info("[Events] Subscribed", {
890
+ subject,
891
+ stream: streamLabel,
892
+ group
893
+ });
894
+ return async () => {
895
+ if (this.active.get(key) !== subscription) return;
896
+ this.active.delete(key);
897
+ try {
898
+ await subscription.unsubscribe();
899
+ } catch (error) {
900
+ logger.warn("[Events] unsubscribe failed", {
901
+ subject,
902
+ error: errorMessage$1(error)
903
+ });
904
+ }
905
+ };
906
+ }
907
+ /**
908
+ * Close every subscription, consumer and the publisher. Subscriptions are
909
+ * drained in parallel: each waits for its in-flight handlers (bounded by its
910
+ * drain timeout) before the consumers and the publisher close.
911
+ */
912
+ async close() {
913
+ await Promise.all([...this.active.values()].map(async (subscription) => {
914
+ try {
915
+ await subscription.unsubscribe();
916
+ } catch (error) {
917
+ logger.warn("[Events] unsubscribe failed", { error: errorMessage$1(error) });
918
+ }
919
+ }));
920
+ this.active.clear();
921
+ for (const consumer of this.consumers.values()) try {
922
+ await consumer.disconnect();
923
+ } catch (error) {
924
+ logger.warn("[Events] consumer disconnect failed", { error: errorMessage$1(error) });
925
+ }
926
+ this.consumers.clear();
927
+ if (this.publisherConnecting) await this.publisherConnecting.catch(() => void 0);
928
+ if (this.publisher) {
929
+ try {
930
+ await this.publisher.disconnect();
931
+ } catch (error) {
932
+ logger.warn("[Events] publisher disconnect failed", { error: errorMessage$1(error) });
933
+ }
934
+ this.publisher = null;
935
+ }
936
+ logger.info("[Events] Connections closed", { service: this.serviceName });
937
+ }
938
+ /** Publisher connection state only; consumers connect on their own. */
939
+ isConnected() {
940
+ return this.publisher?.isConnected() ?? false;
941
+ }
942
+ /** Number of active subscriptions (diagnostics). */
943
+ getSubscriptionCount() {
944
+ return this.active.size;
945
+ }
946
+ /** The aggregated stream for `subject`, or `undefined` for the per-subject stream. */
947
+ resolveStream(subject) {
948
+ for (const route of this.routes) if (matchSubject(route.subject, subject)) return route.stream;
949
+ return this.defaultStream;
950
+ }
951
+ /** Derived consumer-group name for `subject`. */
952
+ consumerNameFor(subject) {
953
+ return `${this.serviceName}-${subject.replace(/[^a-zA-Z0-9]+/g, "-").replace(/-$/, "")}`;
954
+ }
955
+ };
956
+ function createEventsManagerSingleton(options) {
957
+ let instance = null;
958
+ return {
959
+ get() {
960
+ instance ??= (async () => {
961
+ const manager = new EventsManager(options);
962
+ await manager.connect();
963
+ return manager;
964
+ })().catch((error) => {
965
+ instance = null;
966
+ throw error;
967
+ });
968
+ return instance;
969
+ },
970
+ async close() {
971
+ const pending = instance;
972
+ instance = null;
973
+ if (!pending) return;
974
+ await (await pending.catch(() => null))?.close();
975
+ }
976
+ };
977
+ }
978
+
979
+ // src/event-queue/lifecycle-consumer.ts
980
+ /**
981
+ * Platform lifecycle consumer (registry PR-EVT-06, PR-BE-24).
982
+ *
983
+ * Products hold rows keyed by workspace, member and organization ids. When the
984
+ * platform deletes one of those, the product has to clean up. This helper
985
+ * subscribes to the subjects the producers ACTUALLY publish (audited on main,
986
+ * see PLATFORM_EVENT_TAXONOMY), validates every payload, and calls typed
987
+ * handlers:
988
+ *
989
+ * ```ts
990
+ * const lifecycle = createLifecycleConsumer({
991
+ * serviceName: 'wspace-vibecontrols-svc',
992
+ * layer: 'wspace',
993
+ * handlers: {
994
+ * onWorkspaceDeleted: async ({ workspaceId }) => agents.retireWorkspace(workspaceId),
995
+ * onWorkspaceMemberRemoved: async ({ workspaceId, userId }) => sessions.revoke(workspaceId, userId),
996
+ * },
997
+ * });
998
+ * await lifecycle.start();
999
+ * // shutdown: await lifecycle.stop();
1000
+ * ```
1001
+ *
1002
+ * Sources per handler:
1003
+ *
1004
+ * | Handler | Subject (stream) | Layer |
1005
+ * |----------------------------|-------------------------------------------------------------------|--------|
1006
+ * | `onWorkspaceDeleted` | `graph.module-workspace.Workspace.deleted` (`WSPACE_GRAPH_EVENTS`) | wspace |
1007
+ * | | `workspace.deleted` (per-subject; reserved, no producer yet) | wspace |
1008
+ * | `onWorkspaceMemberRemoved` | `workspace.member.removed` (per-subject) | wspace |
1009
+ * | `onOrganizationDeleted` | `organization.deleted` (per-subject) | global |
1010
+ *
1011
+ * `user.deleted` and `subscription.*` have no producer, so there is no handler
1012
+ * for them: check user state and entitlement lazily at read / quota time.
1013
+ *
1014
+ * Safety properties (the risk of this helper is a destructive cleanup on the
1015
+ * wrong event):
1016
+ * - The consumer group is `<serviceName>.<purpose>`, unique per service, and
1017
+ * a process cannot start two consumers with the same group. Shared
1018
+ * queue-group names such as `workflow_workers` are refused.
1019
+ * - Every entry's subject is compared EXACTLY. On the aggregated graph
1020
+ * stream the Redis consumer delivers all graph events to an exact-subject
1021
+ * subscription; non-matching entries are acked and skipped here.
1022
+ * - Payloads are validated before a handler runs. An invalid payload is
1023
+ * dead-lettered (`term`), never passed on with a missing id.
1024
+ * - Handlers that throw are retried (nak) up to `maxDeliver`, then
1025
+ * dead-lettered. Handlers MUST be idempotent: delivery is at-least-once,
1026
+ * and a workspace deletion can arrive from both sources (an in-process
1027
+ * window suppresses the duplicate on one replica, not across replicas).
1028
+ * - New groups start at the stream tail (`$`): enabling the consumer never
1029
+ * replays historical deletions.
1030
+ */
1031
+ /** Subjects, as published on main. */
1032
+ const LIFECYCLE_SUBJECTS = {
1033
+ workspaceDeleted: "workspace.deleted",
1034
+ workspaceDeletedGraph: "graph.module-workspace.Workspace.deleted",
1035
+ workspaceMemberRemoved: "workspace.member.removed",
1036
+ organizationDeleted: "organization.deleted"
1037
+ };
1038
+ const SERVICE_NAME = /^[a-z][a-z0-9-]*[a-z0-9]$/;
1039
+ const PURPOSE = /^[a-z][a-z0-9-]*$/;
1040
+ const ID = /^[A-Za-z0-9_-]{1,128}$/;
1041
+ /** Group names that are shared on purpose (work queues) or are SDK defaults. */
1042
+ const RESERVED_GROUPS = /* @__PURE__ */ new Set([
1043
+ "workflow_workers",
1044
+ "default-consumer",
1045
+ "default"
1046
+ ]);
1047
+ const claimedGroups = /* @__PURE__ */ new Set();
1048
+ /**
1049
+ * Consumer-group name for a service-owned consumer: `<serviceName>.<purpose>`.
1050
+ * Every service consuming a broadcast fact needs its own group, otherwise the
1051
+ * services split the entries between them (PR-BE-24).
1052
+ */
1053
+ function buildConsumerGroupName(serviceName, purpose = "lifecycle") {
1054
+ if (!SERVICE_NAME.test(serviceName)) throw new Error(`[Lifecycle] serviceName "${serviceName}" must be a kebab-case service name`);
1055
+ if (!PURPOSE.test(purpose)) throw new Error(`[Lifecycle] purpose "${purpose}" must be lower-case kebab-case`);
1056
+ const group = `${serviceName}.${purpose}`;
1057
+ if (RESERVED_GROUPS.has(serviceName) || RESERVED_GROUPS.has(group)) throw new Error(`[Lifecycle] "${group}" is a shared or default consumer group; use the service's own name`);
1058
+ return group;
1059
+ }
1060
+ function errorMessage(error) {
1061
+ return error instanceof Error ? error.message : String(error);
1062
+ }
1063
+ function isRecord(value) {
1064
+ return typeof value === "object" && value !== null && !Array.isArray(value);
1065
+ }
1066
+ function readId(record, key) {
1067
+ const value = record[key];
1068
+ return typeof value === "string" && ID.test(value) ? value : void 0;
1069
+ }
1070
+ function readOptionalString(record, key) {
1071
+ const value = record[key];
1072
+ return typeof value === "string" && value.length > 0 ? value : void 0;
1073
+ }
1074
+ function readTimestamp(value) {
1075
+ if (value instanceof Date) return value.toISOString();
1076
+ return typeof value === "string" && !Number.isNaN(Date.parse(value)) ? value : void 0;
1077
+ }
1078
+ /** Parse `workspace.deleted`. Exported for tests. */
1079
+ function parseWorkspaceDeletedStream(data) {
1080
+ if (!isRecord(data)) return null;
1081
+ const workspaceId = readId(data, "workspaceId");
1082
+ if (!workspaceId) return null;
1083
+ return {
1084
+ workspaceId,
1085
+ tenantId: readId(data, "tenantId"),
1086
+ deletedBy: readOptionalString(data, "deletedBy"),
1087
+ deletedAt: readTimestamp(data["deletedAt"])
1088
+ };
1089
+ }
1090
+ /** Parse `graph.module-workspace.Workspace.deleted`. Exported for tests. */
1091
+ function parseWorkspaceDeletedGraph(data) {
1092
+ if (!isRecord(data) || data["eventType"] !== "entity.deleted") return null;
1093
+ const entity = data["entity"];
1094
+ if (!isRecord(entity) || entity["type"] !== "Workspace") return null;
1095
+ const workspaceId = readId(entity, "id");
1096
+ if (!workspaceId) return null;
1097
+ const row = isRecord(entity["data"]) ? entity["data"] : {};
1098
+ const context = isRecord(data["context"]) ? data["context"] : {};
1099
+ return {
1100
+ workspaceId,
1101
+ tenantId: readId(row, "tenantId"),
1102
+ organizationId: readId(data, "organizationId"),
1103
+ deletedBy: readOptionalString(context, "actorId"),
1104
+ deletedAt: readTimestamp(row["deletedAt"]) ?? readTimestamp(data["timestamp"])
1105
+ };
1106
+ }
1107
+ /** Parse `workspace.member.removed`. Exported for tests. */
1108
+ function parseWorkspaceMemberRemoved(data) {
1109
+ if (!isRecord(data)) return null;
1110
+ const workspaceId = readId(data, "workspaceId");
1111
+ const userId = readId(data, "userId");
1112
+ if (!workspaceId || !userId) return null;
1113
+ return {
1114
+ workspaceId,
1115
+ userId,
1116
+ tenantId: readId(data, "tenantId"),
1117
+ removedBy: readOptionalString(data, "removedBy"),
1118
+ previousRole: readOptionalString(data, "previousRole")
1119
+ };
1120
+ }
1121
+ /** Parse `organization.deleted`. Exported for tests. */
1122
+ function parseOrganizationDeleted(data) {
1123
+ if (!isRecord(data)) return null;
1124
+ const organizationId = readId(data, "organizationId");
1125
+ if (!organizationId) return null;
1126
+ return {
1127
+ organizationId,
1128
+ tenantId: readId(data, "tenantId"),
1129
+ deletedBy: readOptionalString(data, "actorId"),
1130
+ deletedAt: readTimestamp(data["occurredAt"])
1131
+ };
1132
+ }
1133
+ var DedupeWindow = class {
1134
+ windowMs;
1135
+ seen = /* @__PURE__ */ new Map();
1136
+ constructor(windowMs) {
1137
+ this.windowMs = windowMs;
1138
+ }
1139
+ /** True when `key` was seen inside the window; records it otherwise. */
1140
+ check(key) {
1141
+ if (this.windowMs <= 0) return false;
1142
+ const now = Date.now();
1143
+ for (const [k, at] of this.seen) {
1144
+ if (now - at < this.windowMs) break;
1145
+ this.seen.delete(k);
1146
+ }
1147
+ if (this.seen.has(key)) return true;
1148
+ this.seen.set(key, now);
1149
+ return false;
1150
+ }
1151
+ forget(key) {
1152
+ this.seen.delete(key);
1153
+ }
1154
+ };
1155
+ function createLifecycleConsumer(options) {
1156
+ const group = buildConsumerGroupName(options.serviceName, options.purpose);
1157
+ const { handlers, layer } = options;
1158
+ const maxDeliver = options.maxDeliver ?? 5;
1159
+ if (!Number.isInteger(maxDeliver) || maxDeliver < 1) throw new Error("[Lifecycle] maxDeliver must be a positive integer");
1160
+ if (layer === "wspace" && handlers.onOrganizationDeleted) throw new Error("[Lifecycle] onOrganizationDeleted needs a global-layer service: organization.deleted is published on the global Valkey, which wspace services do not read");
1161
+ if (layer === "global" && (handlers.onWorkspaceDeleted || handlers.onWorkspaceMemberRemoved)) throw new Error("[Lifecycle] workspace lifecycle events are published on the wspace Valkey; use a wspace service");
1162
+ const graphStream = options.graphStream ?? process.env["GRAPH_SYNC_STREAM_NAME"] ?? "WSPACE_GRAPH_EVENTS";
1163
+ const dedupe = new DedupeWindow(options.dedupeWindowMs ?? 6e5);
1164
+ const routes = [];
1165
+ const once = async (key, run) => {
1166
+ if (dedupe.check(key)) return "duplicate";
1167
+ try {
1168
+ await run();
1169
+ return "handled";
1170
+ } catch (error) {
1171
+ dedupe.forget(key);
1172
+ throw error;
1173
+ }
1174
+ };
1175
+ const { onWorkspaceDeleted, onWorkspaceMemberRemoved, onOrganizationDeleted } = handlers;
1176
+ if (onWorkspaceDeleted) {
1177
+ const sources = options.workspaceDeletedSources ?? ["graph", "stream"];
1178
+ if (sources.length === 0) throw new Error("[Lifecycle] workspaceDeletedSources must not be empty");
1179
+ const deliver = (parse) => async (data, ctx) => {
1180
+ const fact = parse(data);
1181
+ if (!fact) return "invalid";
1182
+ return once(`workspace.deleted:${fact.workspaceId}`, () => onWorkspaceDeleted(fact, ctx));
1183
+ };
1184
+ if (sources.includes("graph")) routes.push({
1185
+ subject: LIFECYCLE_SUBJECTS.workspaceDeletedGraph,
1186
+ stream: graphStream,
1187
+ source: "graph",
1188
+ dispatch: deliver(parseWorkspaceDeletedGraph)
1189
+ });
1190
+ if (sources.includes("stream")) routes.push({
1191
+ subject: LIFECYCLE_SUBJECTS.workspaceDeleted,
1192
+ source: "stream",
1193
+ dispatch: deliver(parseWorkspaceDeletedStream)
1194
+ });
1195
+ }
1196
+ if (onWorkspaceMemberRemoved) routes.push({
1197
+ subject: LIFECYCLE_SUBJECTS.workspaceMemberRemoved,
1198
+ source: "stream",
1199
+ dispatch: async (data, ctx) => {
1200
+ const fact = parseWorkspaceMemberRemoved(data);
1201
+ if (!fact) return "invalid";
1202
+ return once(`workspace.member.removed:${fact.workspaceId}:${fact.userId}:${ctx.eventId}`, () => onWorkspaceMemberRemoved(fact, ctx));
1203
+ }
1204
+ });
1205
+ if (onOrganizationDeleted) routes.push({
1206
+ subject: LIFECYCLE_SUBJECTS.organizationDeleted,
1207
+ source: "stream",
1208
+ dispatch: async (data, ctx) => {
1209
+ const fact = parseOrganizationDeleted(data);
1210
+ if (!fact) return "invalid";
1211
+ return once(`organization.deleted:${fact.organizationId}`, () => onOrganizationDeleted(fact, ctx));
1212
+ }
1213
+ });
1214
+ if (routes.length === 0) throw new Error("[Lifecycle] at least one handler is required");
1215
+ const consumerFactory = options.consumerFactory ?? createConsumer;
1216
+ let consumer = null;
1217
+ let subscriptions = [];
1218
+ let starting = null;
1219
+ const handle = (route) => async (event) => {
1220
+ if (event.subject !== route.subject) {
1221
+ await event.ack();
1222
+ return;
1223
+ }
1224
+ const correlationId = event.metadata?.correlationId;
1225
+ const ctx = {
1226
+ eventId: event.id,
1227
+ subject: event.subject,
1228
+ source: route.source,
1229
+ deliveryAttempt: event.getDeliveryAttempt(),
1230
+ ...typeof correlationId === "string" ? { correlationId } : {}
1231
+ };
1232
+ let outcome;
1233
+ try {
1234
+ outcome = await route.dispatch(event.data, ctx);
1235
+ } catch (error) {
1236
+ logger.error("[Lifecycle] handler failed; will retry", {
1237
+ group,
1238
+ subject: event.subject,
1239
+ eventId: event.id,
1240
+ attempt: ctx.deliveryAttempt,
1241
+ error: errorMessage(error)
1242
+ });
1243
+ await event.nak();
1244
+ return;
1245
+ }
1246
+ if (outcome === "invalid") {
1247
+ logger.error("[Lifecycle] invalid payload; dead-lettering without running the handler", {
1248
+ group,
1249
+ subject: event.subject,
1250
+ eventId: event.id
1251
+ });
1252
+ await event.term();
1253
+ return;
1254
+ }
1255
+ await event.ack();
1256
+ logger.info("[Lifecycle] event processed", {
1257
+ group,
1258
+ subject: event.subject,
1259
+ eventId: event.id,
1260
+ outcome
1261
+ });
1262
+ };
1263
+ const doStart = async () => {
1264
+ if (claimedGroups.has(group)) throw new Error(`[Lifecycle] consumer group ${group} is already running in this process`);
1265
+ claimedGroups.add(group);
1266
+ const created = consumerFactory(routes[0]?.stream ?? routes[0]?.subject ?? group, group);
1267
+ const opened = [];
1268
+ try {
1269
+ await created.connect();
1270
+ for (const route of routes) opened.push(await created.subscribe({
1271
+ subject: route.subject,
1272
+ handler: handle(route),
1273
+ options: {
1274
+ consumer: group,
1275
+ ...route.stream ? { stream: route.stream } : {},
1276
+ deliverPolicy: "new",
1277
+ ackPolicy: "explicit",
1278
+ maxDeliver
1279
+ }
1280
+ }));
1281
+ } catch (error) {
1282
+ for (const sub of opened) await sub.unsubscribe().catch(() => void 0);
1283
+ await created.disconnect().catch(() => void 0);
1284
+ claimedGroups.delete(group);
1285
+ throw error;
1286
+ }
1287
+ consumer = created;
1288
+ subscriptions = opened;
1289
+ logger.info("[Lifecycle] consumer started", {
1290
+ group,
1291
+ subjects: routes.map((r) => r.stream ? `${r.subject} (${r.stream})` : r.subject),
1292
+ keyScope: eventKeyScopeForUrl(resolveEventStreamsUrl()) || "(none)"
1293
+ });
1294
+ };
1295
+ return {
1296
+ group,
1297
+ subjects: routes.map((r) => r.subject),
1298
+ async start() {
1299
+ if (consumer) return;
1300
+ starting ??= doStart().finally(() => {
1301
+ starting = null;
1302
+ });
1303
+ await starting;
1304
+ },
1305
+ async stop() {
1306
+ if (starting) await starting.catch(() => void 0);
1307
+ const current = consumer;
1308
+ if (!current) return;
1309
+ consumer = null;
1310
+ for (const sub of subscriptions) await sub.unsubscribe().catch((error) => logger.warn("[Lifecycle] unsubscribe failed", {
1311
+ group,
1312
+ error: errorMessage(error)
1313
+ }));
1314
+ subscriptions = [];
1315
+ await current.disconnect().catch((error) => logger.warn("[Lifecycle] disconnect failed", {
1316
+ group,
1317
+ error: errorMessage(error)
1318
+ }));
1319
+ claimedGroups.delete(group);
1320
+ logger.info("[Lifecycle] consumer stopped", { group });
1321
+ },
1322
+ isRunning() {
1323
+ return consumer !== null;
1324
+ }
1325
+ };
1326
+ }
1327
+
1328
+ // src/event-queue/index.ts
1329
+ var event_queue_exports = /* @__PURE__ */ __exportAll({
1330
+ EVENT_STREAMS_URL_ENV_KEYS: () => EVENT_STREAMS_URL_ENV_KEYS,
1331
+ EVENT_TAXONOMY_BRAND: () => EVENT_TAXONOMY_BRAND,
1332
+ EventPriority: () => EventPriority,
1333
+ EventQueueFactory: () => EventQueueFactory,
1334
+ EventsManager: () => EventsManager,
1335
+ EventsModule: () => EventsModule,
1336
+ GRAPH_EVENTS_URL_ENV_KEYS: () => GRAPH_EVENTS_URL_ENV_KEYS,
1337
+ GraphEventEmitterImpl: () => GraphEventEmitterImpl,
1338
+ LIFECYCLE_SUBJECTS: () => LIFECYCLE_SUBJECTS,
1339
+ MemoryEventBus: () => MemoryEventBus,
1340
+ MemoryEventConsumer: () => MemoryEventConsumer,
1341
+ MemoryEventPublisher: () => MemoryEventPublisher,
1342
+ MemoryEventQueue: () => MemoryEventQueue,
1343
+ ModuleEventsService: () => ModuleEventsService,
1344
+ PLATFORM_EVENT_TAXONOMY: () => PLATFORM_EVENT_TAXONOMY,
1345
+ QueueType: () => QueueType,
1346
+ REFERENCE_PRODUCT_EVENT_TAXONOMY: () => REFERENCE_PRODUCT_EVENT_TAXONOMY,
1347
+ RedisStreamsConnection: () => RedisStreamsConnection,
1348
+ RedisStreamsEventConsumer: () => RedisStreamsEventConsumer,
1349
+ RedisStreamsEventPublisher: () => RedisStreamsEventPublisher,
1350
+ WSPACE_GRAPH_EVENTS_STREAM: () => WSPACE_GRAPH_EVENTS_STREAM,
1351
+ buildConsumerGroupName: () => buildConsumerGroupName,
1352
+ createConsumer: () => createConsumer,
1353
+ createEventsManagerSingleton: () => createEventsManagerSingleton,
1354
+ createGraphEventEmitter: () => createGraphEventEmitter,
1355
+ createLifecycleConsumer: () => createLifecycleConsumer,
1356
+ createMemoryConsumer: () => createMemoryConsumer,
1357
+ createMemoryGraphEventEmitter: () => createGraphEventEmitter$1,
1358
+ createMemoryPublisher: () => createMemoryPublisher,
1359
+ createModuleEventsService: () => createModuleEventsService,
1360
+ createPublisher: () => createPublisher,
1361
+ defineEventTaxonomy: () => defineEventTaxonomy,
1362
+ eventKeyScopeForUrl: () => eventKeyScopeForUrl,
1363
+ eventSpec: () => eventSpec,
1364
+ getGraphEventEmitter: () => getGraphEventEmitter,
1365
+ isDefinedEventTaxonomy: () => isDefinedEventTaxonomy,
1366
+ mergeEventTaxonomies: () => mergeEventTaxonomies,
1367
+ parseOrganizationDeleted: () => parseOrganizationDeleted,
1368
+ parseWorkspaceDeletedGraph: () => parseWorkspaceDeletedGraph,
1369
+ parseWorkspaceDeletedStream: () => parseWorkspaceDeletedStream,
1370
+ parseWorkspaceMemberRemoved: () => parseWorkspaceMemberRemoved,
1371
+ publishTaxonomyEvent: () => publishTaxonomyEvent,
1372
+ redisDlqKey: () => dlqKey,
1373
+ redisStreamKey: () => streamKey,
1374
+ resetGraphEventEmitter: () => resetGraphEventEmitter,
1375
+ resolveEventStreamsUrl: () => resolveEventStreamsUrl,
1376
+ resolveEventStreamsUrlSource: () => resolveEventStreamsUrlSource,
1377
+ resolveGraphEventsUrl: () => resolveGraphEventsUrl,
1378
+ resolveGraphEventsUrlSource: () => resolveGraphEventsUrlSource,
1379
+ taxonomyEventNames: () => taxonomyEventNames,
1380
+ taxonomyNameViolation: () => taxonomyNameViolation
1381
+ });
1382
+
1383
+ export { createPublisher as C, createModuleEventsService as D, ModuleEventsService as E, createConsumer as S, EventsModule as T, isDefinedEventTaxonomy as _, parseOrganizationDeleted as a, taxonomyEventNames as b, parseWorkspaceMemberRemoved as c, EVENT_TAXONOMY_BRAND as d, PLATFORM_EVENT_TAXONOMY as f, eventSpec as g, defineEventTaxonomy as h, createLifecycleConsumer as i, EventsManager as l, WSPACE_GRAPH_EVENTS_STREAM as m, LIFECYCLE_SUBJECTS as n, parseWorkspaceDeletedGraph as o, REFERENCE_PRODUCT_EVENT_TAXONOMY as p, buildConsumerGroupName as r, parseWorkspaceDeletedStream as s, event_queue_exports as t, createEventsManagerSingleton as u, mergeEventTaxonomies as v, EventPriority as w, taxonomyNameViolation as x, publishTaxonomyEvent as y };
1384
+ //# sourceMappingURL=event-queue-Cw-YJPY_.js.map