@burdenoff/be-sdk 2026.1110.2 → 2026.1110.4

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 (497) 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/activity/index.d.ts +165 -0
  8. package/dist/activity/index.js +389 -0
  9. package/dist/activity/index.js.map +1 -0
  10. package/dist/ai-credits/index.d.ts +2 -3
  11. package/dist/ai-credits/index.js +3 -4
  12. package/dist/ai-credits/index.js.map +1 -1
  13. package/dist/ai-credits-xxfwGpHS.js +546 -0
  14. package/dist/ai-credits-xxfwGpHS.js.map +1 -0
  15. package/dist/{assistant-session-CJZhF4D6.d.ts → assistant-session-DA5ZKJOr.d.ts} +4 -5
  16. package/dist/auth/index.d.ts +2 -77
  17. package/dist/auth/index.js +3 -7
  18. package/dist/auth/index.js.map +1 -1
  19. package/dist/auth-C5ctwSLp.js +228 -0
  20. package/dist/auth-C5ctwSLp.js.map +1 -0
  21. package/dist/bootstrap/index.d.ts +74 -0
  22. package/dist/bootstrap/index.js +282 -0
  23. package/dist/bootstrap/index.js.map +1 -0
  24. package/dist/cache/index.d.ts +2 -3
  25. package/dist/cache/index.js +3 -7
  26. package/dist/cache/index.js.map +1 -1
  27. package/dist/cache-CU0uLwcS.js +1837 -0
  28. package/dist/cache-CU0uLwcS.js.map +1 -0
  29. package/dist/captcha/index.d.ts +2 -1
  30. package/dist/captcha/index.js +3 -3
  31. package/dist/captcha/index.js.map +1 -1
  32. package/dist/captcha-BT7yh1YS.js +77 -0
  33. package/dist/captcha-BT7yh1YS.js.map +1 -0
  34. package/dist/client/internal-client.d.ts +4 -7
  35. package/dist/client/internal-client.js +172 -4
  36. package/dist/client/internal-client.js.map +1 -1
  37. package/dist/client-BgAEvDC2.d.ts +86 -0
  38. package/dist/client-sAJTrb4i.js +565 -0
  39. package/dist/client-sAJTrb4i.js.map +1 -0
  40. package/dist/collector-endpoint-iyQYeI50.js +50 -0
  41. package/dist/collector-endpoint-iyQYeI50.js.map +1 -0
  42. package/dist/context/index.d.ts +35 -0
  43. package/dist/context/index.js +283 -0
  44. package/dist/context/index.js.map +1 -0
  45. package/dist/crypto/index.d.ts +2 -1
  46. package/dist/crypto/index.js +3 -3
  47. package/dist/crypto/index.js.map +1 -1
  48. package/dist/crypto-DO9fM0FO.js +145 -0
  49. package/dist/crypto-DO9fM0FO.js.map +1 -0
  50. package/dist/database/index.d.ts +104 -108
  51. package/dist/database/index.js +468 -6
  52. package/dist/database/index.js.map +1 -1
  53. package/dist/dataloader/index.d.ts +2 -1
  54. package/dist/dataloader/index.js +3 -3
  55. package/dist/dataloader/index.js.map +1 -1
  56. package/dist/dataloader-DwpT3YoS.js +294 -0
  57. package/dist/dataloader-DwpT3YoS.js.map +1 -0
  58. package/dist/deployed-environment-p_Tdl3sT.js +38 -0
  59. package/dist/deployed-environment-p_Tdl3sT.js.map +1 -0
  60. package/dist/dist-BGKdXVy3.js +1718 -0
  61. package/dist/dist-BGKdXVy3.js.map +1 -0
  62. package/dist/env-DdaoGjIt.js +74 -0
  63. package/dist/env-DdaoGjIt.js.map +1 -0
  64. package/dist/event-queue/index.d.ts +2 -7
  65. package/dist/event-queue/index.js +7 -9
  66. package/dist/event-queue/index.js.map +1 -1
  67. package/dist/event-queue-Cw-YJPY_.js +1384 -0
  68. package/dist/event-queue-Cw-YJPY_.js.map +1 -0
  69. package/dist/{explicit-activity-scope-CCoxVwAr.d.ts → explicit-activity-scope-D8VeGGpt.d.ts} +1 -2
  70. package/dist/explicit-activity-scope-DikJ7NAE.js +57 -0
  71. package/dist/explicit-activity-scope-DikJ7NAE.js.map +1 -0
  72. package/dist/export/index.d.ts +2 -2
  73. package/dist/export/index.js +3 -14
  74. package/dist/export/index.js.map +1 -1
  75. package/dist/export-DJXE3Osa.js +642 -0
  76. package/dist/export-DJXE3Osa.js.map +1 -0
  77. package/dist/feature-flags/index.d.ts +2 -10
  78. package/dist/feature-flags/index.js +3 -6
  79. package/dist/feature-flags/index.js.map +1 -1
  80. package/dist/feature-flags-CP1KRgwD.js +422 -0
  81. package/dist/feature-flags-CP1KRgwD.js.map +1 -0
  82. package/dist/files/index.d.ts +2 -3
  83. package/dist/files/index.js +3 -4
  84. package/dist/files/index.js.map +1 -1
  85. package/dist/files-h5U-D2AF.js +830 -0
  86. package/dist/files-h5U-D2AF.js.map +1 -0
  87. package/dist/gateway/index.d.ts +4 -6
  88. package/dist/gateway/index.js +7 -13
  89. package/dist/gateway/index.js.map +1 -1
  90. package/dist/gateway/security/index.d.ts +2 -2
  91. package/dist/gateway/security/index.js +3 -5
  92. package/dist/gateway/security/index.js.map +1 -1
  93. package/dist/gateway-ByVo-n37.js +50 -0
  94. package/dist/gateway-ByVo-n37.js.map +1 -0
  95. package/dist/graph/index.d.ts +3 -10
  96. package/dist/graph/index.js +4 -13
  97. package/dist/graph/index.js.map +1 -1
  98. package/dist/graph-CR7u4lpl.js +2152 -0
  99. package/dist/graph-CR7u4lpl.js.map +1 -0
  100. package/dist/graph-emitter-CdOXP7Tn.js +621 -0
  101. package/dist/graph-emitter-CdOXP7Tn.js.map +1 -0
  102. package/dist/graphql/index.d.ts +3 -2
  103. package/dist/graphql/index.js +4 -6
  104. package/dist/graphql/index.js.map +1 -1
  105. package/dist/graphql/services/index.d.ts +2 -24
  106. package/dist/graphql/services/index.js +3 -4
  107. package/dist/graphql/services/index.js.map +1 -1
  108. package/dist/graphql-CUDyhibV.d.ts +21 -0
  109. package/dist/graphql-DHAHHcww.js +161 -0
  110. package/dist/graphql-DHAHHcww.js.map +1 -0
  111. package/dist/i18n/index.d.ts +3 -3
  112. package/dist/i18n/index.js +3 -4
  113. package/dist/i18n/index.js.map +1 -1
  114. package/dist/i18n-BBMYFd0P.js +860 -0
  115. package/dist/i18n-BBMYFd0P.js.map +1 -0
  116. package/dist/import-optional-peer-B82VYxeX.js +18 -0
  117. package/dist/import-optional-peer-B82VYxeX.js.map +1 -0
  118. package/dist/index-3KOZ1zN9.d.ts +233 -0
  119. package/dist/index-ADmsX0BI.d.ts +646 -0
  120. package/dist/index-B2LCaK0R.d.ts +500 -0
  121. package/dist/index-BBqooJ52.d.ts +45 -0
  122. package/dist/index-BGzMYJsm.d.ts +209 -0
  123. package/dist/index-BMIMnp6T.d.ts +8 -0
  124. package/dist/index-BVOL7458.d.ts +10 -0
  125. package/dist/index-BcqQs-Uq.d.ts +69 -0
  126. package/dist/index-BeVtqGO-.d.ts +208 -0
  127. package/dist/index-BiTzGUZP.d.ts +114 -0
  128. package/dist/index-C0qLquY0.d.ts +150 -0
  129. package/dist/index-C5uEKchX.d.ts +60 -0
  130. package/dist/index-CDOqxSIi.d.ts +37 -0
  131. package/dist/index-CG6wj66Y.d.ts +148 -0
  132. package/dist/index-CHwMhK6v.d.ts +63 -0
  133. package/dist/index-CIgoeobA.d.ts +145 -0
  134. package/dist/index-CPQDMSFS.d.ts +103 -0
  135. package/dist/index-CSRcgkVi.d.ts +23 -0
  136. package/dist/index-CTTwo9av.d.ts +102 -0
  137. package/dist/index-CVCyKzhB.d.ts +207 -0
  138. package/dist/index-C_GXXF32.d.ts +704 -0
  139. package/dist/index-CaM9JUcc.d.ts +144 -0
  140. package/dist/index-CliOgq6L.d.ts +203 -0
  141. package/dist/index-Cot73bdh.d.ts +63 -0
  142. package/dist/index-DGgh9DWn.d.ts +59 -0
  143. package/dist/index-DY3dNhMN.d.ts +420 -0
  144. package/dist/index-DqbGqfAy.d.ts +127 -0
  145. package/dist/index-Dt1HJPTX.d.ts +12 -0
  146. package/dist/index-DtI6aBtB.d.ts +22 -0
  147. package/dist/index-FKohsiex.d.ts +38 -0
  148. package/dist/index-FRRaa6h2.d.ts +999 -0
  149. package/dist/index-FbXPfen7.d.ts +132 -0
  150. package/dist/index-MArCb8Aq.d.ts +306 -0
  151. package/dist/index-U_tu3zUl.d.ts +303 -0
  152. package/dist/index-YOShAwkq.d.ts +45 -0
  153. package/dist/index-cmR9k9ga.d.ts +26 -0
  154. package/dist/index-yBSjMY32.d.ts +24 -0
  155. package/dist/index-zd_NPGJo.d.ts +206 -0
  156. package/dist/index.d.ts +106 -609
  157. package/dist/index.js +769 -2590
  158. package/dist/index.js.map +1 -1
  159. package/dist/init/index.d.ts +2 -2
  160. package/dist/init/index.js +3 -16
  161. package/dist/init/index.js.map +1 -1
  162. package/dist/init-CQPFmOOe.js +325 -0
  163. package/dist/init-CQPFmOOe.js.map +1 -0
  164. package/dist/instrumentation/index.d.ts +3 -4
  165. package/dist/instrumentation/index.js +5 -5
  166. package/dist/instrumentation/index.js.map +1 -1
  167. package/dist/instrumentation-xkkmDgJ0.js +1678 -0
  168. package/dist/instrumentation-xkkmDgJ0.js.map +1 -0
  169. package/dist/lake/index.d.ts +50 -54
  170. package/dist/lake/index.js +169 -193
  171. package/dist/lake/index.js.map +1 -1
  172. package/dist/layer/index.d.ts +3 -2
  173. package/dist/layer/index.js +4 -5
  174. package/dist/layer/index.js.map +1 -1
  175. package/dist/layer-BZBZZWeV.d.ts +69 -0
  176. package/dist/layer-Bcix-WCl.js +105 -0
  177. package/dist/layer-Bcix-WCl.js.map +1 -0
  178. package/dist/layer-CEKy6cm8.js +252 -0
  179. package/dist/layer-CEKy6cm8.js.map +1 -0
  180. package/dist/lifecycle/index.d.ts +2 -1
  181. package/dist/lifecycle/index.js +3 -4
  182. package/dist/lifecycle/index.js.map +1 -1
  183. package/dist/lifecycle-DeoLSX0U.js +76 -0
  184. package/dist/lifecycle-DeoLSX0U.js.map +1 -0
  185. package/dist/logger/index.d.ts +2 -3
  186. package/dist/logger/index.js +3 -3
  187. package/dist/logger/index.js.map +1 -1
  188. package/dist/logger-B6rCpb7D.js +290 -0
  189. package/dist/logger-B6rCpb7D.js.map +1 -0
  190. package/dist/metrics/index.d.ts +13 -14
  191. package/dist/metrics/index.js +3 -4
  192. package/dist/metrics/index.js.map +1 -1
  193. package/dist/metrics-BrLwNUrb.js +52 -0
  194. package/dist/metrics-BrLwNUrb.js.map +1 -0
  195. package/dist/metrics-collector-C2eShrlW.js +922 -0
  196. package/dist/metrics-collector-C2eShrlW.js.map +1 -0
  197. package/dist/middleware/index.d.ts +3 -3
  198. package/dist/middleware/index.js +3 -4
  199. package/dist/middleware/index.js.map +1 -1
  200. package/dist/middleware-CUxJVUpD.js +1243 -0
  201. package/dist/middleware-CUxJVUpD.js.map +1 -0
  202. package/dist/middleware-Cq0zFMGp.js +253 -0
  203. package/dist/middleware-Cq0zFMGp.js.map +1 -0
  204. package/dist/notifications/index.d.ts +2 -5
  205. package/dist/notifications/index.js +3 -6
  206. package/dist/notifications/index.js.map +1 -1
  207. package/dist/notifications-DY_i37WN.js +869 -0
  208. package/dist/notifications-DY_i37WN.js.map +1 -0
  209. package/dist/observability/index.d.ts +2 -3
  210. package/dist/observability/index.js +3 -4
  211. package/dist/observability/index.js.map +1 -1
  212. package/dist/observability-DBDXipTU.js +272 -0
  213. package/dist/observability-DBDXipTU.js.map +1 -0
  214. package/dist/payments/index.d.ts +144 -0
  215. package/dist/payments/index.js +404 -0
  216. package/dist/payments/index.js.map +1 -0
  217. package/dist/platform/index.d.ts +2 -1
  218. package/dist/platform/index.js +3 -5
  219. package/dist/platform/index.js.map +1 -1
  220. package/dist/platform-DZwczW7v.js +1510 -0
  221. package/dist/platform-DZwczW7v.js.map +1 -0
  222. package/dist/prisma/generator/index.d.ts +1 -1
  223. package/dist/prisma/generator/index.js +97 -84
  224. package/dist/prisma/generator/index.js.map +1 -1
  225. package/dist/prisma/index.d.ts +4 -7
  226. package/dist/prisma/index.js +5 -12
  227. package/dist/prisma/index.js.map +1 -1
  228. package/dist/prisma-BzOOdt79.js +863 -0
  229. package/dist/prisma-BzOOdt79.js.map +1 -0
  230. package/dist/prisma-extension-Cfl09swM.d.ts +172 -0
  231. package/dist/product-alias/index.d.ts +2 -1
  232. package/dist/product-alias/index.js +3 -3
  233. package/dist/product-alias/index.js.map +1 -1
  234. package/dist/product-alias-BPqtskMq.js +273 -0
  235. package/dist/product-alias-BPqtskMq.js.map +1 -0
  236. package/dist/rate-limit-CBrK_U5H.js +142 -0
  237. package/dist/rate-limit-CBrK_U5H.js.map +1 -0
  238. package/dist/rbac/index.d.ts +2 -122
  239. package/dist/rbac/index.js +3 -6
  240. package/dist/rbac/index.js.map +1 -1
  241. package/dist/rbac-Dvz0YzEt.js +1486 -0
  242. package/dist/rbac-Dvz0YzEt.js.map +1 -0
  243. package/dist/resource-caps/index.d.ts +66 -72
  244. package/dist/resource-caps/index.js +430 -5
  245. package/dist/resource-caps/index.js.map +1 -1
  246. package/dist/rolldown-runtime-ad2WFvuA.js +17 -0
  247. package/dist/sdk-Dju9o-sq.js +124 -0
  248. package/dist/sdk-Dju9o-sq.js.map +1 -0
  249. package/dist/search/index.d.ts +112 -0
  250. package/dist/search/index.js +266 -0
  251. package/dist/search/index.js.map +1 -0
  252. package/dist/security/index.d.ts +2 -0
  253. package/dist/security/index.js +4 -0
  254. package/dist/security/index.js.map +1 -0
  255. package/dist/security/rate-limit/index.d.ts +2 -0
  256. package/dist/security/rate-limit/index.js +4 -0
  257. package/dist/security/rate-limit/index.js.map +1 -0
  258. package/dist/security-DIG-95Ic.js +1647 -0
  259. package/dist/security-DIG-95Ic.js.map +1 -0
  260. package/dist/server/index.d.ts +7 -164
  261. package/dist/server/index.js +2001 -1507
  262. package/dist/server/index.js.map +1 -1
  263. package/dist/service-jwt-Bu-WNA_-.js +80 -0
  264. package/dist/service-jwt-Bu-WNA_-.js.map +1 -0
  265. package/dist/services-BWzfz7vG.js +102 -0
  266. package/dist/services-BWzfz7vG.js.map +1 -0
  267. package/dist/sharding/index.d.ts +41 -44
  268. package/dist/sharding/index.js +156 -137
  269. package/dist/sharding/index.js.map +1 -1
  270. package/dist/sharing/index.d.ts +2 -1
  271. package/dist/sharing/index.js +3 -4
  272. package/dist/sharing/index.js.map +1 -1
  273. package/dist/sharing-CflDsSJ-.js +911 -0
  274. package/dist/sharing-CflDsSJ-.js.map +1 -0
  275. package/dist/stub-BUnfMiAS.js +577 -0
  276. package/dist/stub-BUnfMiAS.js.map +1 -0
  277. package/dist/tags/index.d.ts +2 -3
  278. package/dist/tags/index.js +3 -4
  279. package/dist/tags/index.js.map +1 -1
  280. package/dist/tags-CbijgoqR.js +868 -0
  281. package/dist/{chunk-PBZFAAOM.js.map → tags-CbijgoqR.js.map} +1 -1
  282. package/dist/telemetry/index.d.ts +64 -76
  283. package/dist/telemetry/index.js +369 -201
  284. package/dist/telemetry/index.js.map +1 -1
  285. package/dist/temporal/index.d.ts +2 -148
  286. package/dist/temporal/index.js +3 -5
  287. package/dist/temporal/index.js.map +1 -1
  288. package/dist/temporal-B534uYK8.js +706 -0
  289. package/dist/temporal-B534uYK8.js.map +1 -0
  290. package/dist/tracker/index.d.ts +5 -11
  291. package/dist/tracker/index.js +7 -20
  292. package/dist/tracker/index.js.map +1 -1
  293. package/dist/tracker-PQztSlhJ.js +458 -0
  294. package/dist/tracker-PQztSlhJ.js.map +1 -0
  295. package/dist/translation/index.d.ts +120 -0
  296. package/dist/translation/index.js +573 -0
  297. package/dist/translation/index.js.map +1 -0
  298. package/dist/types/index.d.ts +3 -0
  299. package/dist/types/index.js +90 -0
  300. package/dist/types/index.js.map +1 -0
  301. package/dist/types-BYMYND1L.js +44 -0
  302. package/dist/types-BYMYND1L.js.map +1 -0
  303. package/dist/types-C6EKaS3V.d.ts +106 -0
  304. package/dist/types-CWybW61E.d.ts +323 -0
  305. package/dist/types-C_yfu3XK.d.ts +34 -0
  306. package/dist/types-DgaQqvxo.d.ts +70 -0
  307. package/dist/usage/index.d.ts +2 -213
  308. package/dist/usage/index.js +3 -15
  309. package/dist/usage/index.js.map +1 -1
  310. package/dist/usage-BRqVP3CJ.js +682 -0
  311. package/dist/usage-BRqVP3CJ.js.map +1 -0
  312. package/dist/utils/index.d.ts +2 -1
  313. package/dist/utils/index.js +3 -3
  314. package/dist/utils/index.js.map +1 -1
  315. package/dist/utils-DL85Tnbn.js +500 -0
  316. package/dist/utils-DL85Tnbn.js.map +1 -0
  317. package/dist/validation/index.d.ts +2 -2
  318. package/dist/validation/index.js +3 -3
  319. package/dist/validation/index.js.map +1 -1
  320. package/dist/validation-CPUITdMk.js +762 -0
  321. package/dist/validation-CPUITdMk.js.map +1 -0
  322. package/dist/workspace-extension-COrC0dYi.js +979 -0
  323. package/dist/workspace-extension-COrC0dYi.js.map +1 -0
  324. package/dist/{workspace-extension-BGwTOV_r.d.ts → workspace-extension-DTFTdGVF.d.ts} +43 -45
  325. package/package.json +7 -10
  326. package/dist/EventQueueFactory-GXC3A7DH.js +0 -8
  327. package/dist/EventQueueFactory-GXC3A7DH.js.map +0 -1
  328. package/dist/chunk-4XIBXZ6J.js +0 -276
  329. package/dist/chunk-4XIBXZ6J.js.map +0 -1
  330. package/dist/chunk-554Z4C2K.js +0 -1006
  331. package/dist/chunk-554Z4C2K.js.map +0 -1
  332. package/dist/chunk-5CAFHK2Z.js +0 -107
  333. package/dist/chunk-5CAFHK2Z.js.map +0 -1
  334. package/dist/chunk-63ZXJ42X.js +0 -451
  335. package/dist/chunk-63ZXJ42X.js.map +0 -1
  336. package/dist/chunk-6XEXJATV.js +0 -304
  337. package/dist/chunk-6XEXJATV.js.map +0 -1
  338. package/dist/chunk-726AR6Q7.js +0 -1532
  339. package/dist/chunk-726AR6Q7.js.map +0 -1
  340. package/dist/chunk-A5F6Z5UE.js +0 -21
  341. package/dist/chunk-A5F6Z5UE.js.map +0 -1
  342. package/dist/chunk-A6DE32ZS.js +0 -1507
  343. package/dist/chunk-A6DE32ZS.js.map +0 -1
  344. package/dist/chunk-AXJDGQPE.js +0 -690
  345. package/dist/chunk-AXJDGQPE.js.map +0 -1
  346. package/dist/chunk-BJQOGOVW.js +0 -602
  347. package/dist/chunk-BJQOGOVW.js.map +0 -1
  348. package/dist/chunk-CFXWH2IS.js +0 -52
  349. package/dist/chunk-CFXWH2IS.js.map +0 -1
  350. package/dist/chunk-DRWH5XCJ.js +0 -876
  351. package/dist/chunk-DRWH5XCJ.js.map +0 -1
  352. package/dist/chunk-E4QNLVY4.js +0 -909
  353. package/dist/chunk-E4QNLVY4.js.map +0 -1
  354. package/dist/chunk-EBDHIL7V.js +0 -774
  355. package/dist/chunk-EBDHIL7V.js.map +0 -1
  356. package/dist/chunk-ELU7VL3E.js +0 -245
  357. package/dist/chunk-ELU7VL3E.js.map +0 -1
  358. package/dist/chunk-FZRODKIN.js +0 -31
  359. package/dist/chunk-FZRODKIN.js.map +0 -1
  360. package/dist/chunk-GCIB76AJ.js +0 -882
  361. package/dist/chunk-GCIB76AJ.js.map +0 -1
  362. package/dist/chunk-HC6MPUIH.js +0 -1571
  363. package/dist/chunk-HC6MPUIH.js.map +0 -1
  364. package/dist/chunk-HNMHPSAM.js +0 -272
  365. package/dist/chunk-HNMHPSAM.js.map +0 -1
  366. package/dist/chunk-HTLEGD3Q.js +0 -1480
  367. package/dist/chunk-HTLEGD3Q.js.map +0 -1
  368. package/dist/chunk-I3KOWRT3.js +0 -89
  369. package/dist/chunk-I3KOWRT3.js.map +0 -1
  370. package/dist/chunk-ID3WR4JS.js +0 -509
  371. package/dist/chunk-ID3WR4JS.js.map +0 -1
  372. package/dist/chunk-JS52ZHTK.js +0 -1346
  373. package/dist/chunk-JS52ZHTK.js.map +0 -1
  374. package/dist/chunk-JVMAQOA3.js +0 -521
  375. package/dist/chunk-JVMAQOA3.js.map +0 -1
  376. package/dist/chunk-KH4TRQCO.js +0 -1063
  377. package/dist/chunk-KH4TRQCO.js.map +0 -1
  378. package/dist/chunk-KJOSPVB2.js +0 -57
  379. package/dist/chunk-KJOSPVB2.js.map +0 -1
  380. package/dist/chunk-KO2ZXZ7W.js +0 -61
  381. package/dist/chunk-KO2ZXZ7W.js.map +0 -1
  382. package/dist/chunk-KS2HQCJR.js +0 -56
  383. package/dist/chunk-KS2HQCJR.js.map +0 -1
  384. package/dist/chunk-LA5KPWZ2.js +0 -413
  385. package/dist/chunk-LA5KPWZ2.js.map +0 -1
  386. package/dist/chunk-MESLAC5W.js +0 -574
  387. package/dist/chunk-MESLAC5W.js.map +0 -1
  388. package/dist/chunk-MWPYA2HD.js +0 -94
  389. package/dist/chunk-MWPYA2HD.js.map +0 -1
  390. package/dist/chunk-NUB5GQTU.js +0 -270
  391. package/dist/chunk-NUB5GQTU.js.map +0 -1
  392. package/dist/chunk-OBBCR6WY.js +0 -277
  393. package/dist/chunk-OBBCR6WY.js.map +0 -1
  394. package/dist/chunk-OQDSAOG3.js +0 -1908
  395. package/dist/chunk-OQDSAOG3.js.map +0 -1
  396. package/dist/chunk-OXNCBE7P.js +0 -971
  397. package/dist/chunk-OXNCBE7P.js.map +0 -1
  398. package/dist/chunk-PBZFAAOM.js +0 -941
  399. package/dist/chunk-PN6GIF3R.js +0 -1185
  400. package/dist/chunk-PN6GIF3R.js.map +0 -1
  401. package/dist/chunk-PYD44IHJ.js +0 -728
  402. package/dist/chunk-PYD44IHJ.js.map +0 -1
  403. package/dist/chunk-QVPIACWD.js +0 -679
  404. package/dist/chunk-QVPIACWD.js.map +0 -1
  405. package/dist/chunk-QWNNFE4P.js +0 -41
  406. package/dist/chunk-QWNNFE4P.js.map +0 -1
  407. package/dist/chunk-RU266375.js +0 -327
  408. package/dist/chunk-RU266375.js.map +0 -1
  409. package/dist/chunk-RYTSVGGA.js +0 -1624
  410. package/dist/chunk-RYTSVGGA.js.map +0 -1
  411. package/dist/chunk-RZOFS2BQ.js +0 -225
  412. package/dist/chunk-RZOFS2BQ.js.map +0 -1
  413. package/dist/chunk-SBS4S2PJ.js +0 -100
  414. package/dist/chunk-SBS4S2PJ.js.map +0 -1
  415. package/dist/chunk-SPRG6G6G.js +0 -530
  416. package/dist/chunk-SPRG6G6G.js.map +0 -1
  417. package/dist/chunk-STWFX5E2.js +0 -233
  418. package/dist/chunk-STWFX5E2.js.map +0 -1
  419. package/dist/chunk-UNASM5VJ.js +0 -419
  420. package/dist/chunk-UNASM5VJ.js.map +0 -1
  421. package/dist/chunk-VAT66FJA.js +0 -245
  422. package/dist/chunk-VAT66FJA.js.map +0 -1
  423. package/dist/chunk-VFCMR5GX.js +0 -49
  424. package/dist/chunk-VFCMR5GX.js.map +0 -1
  425. package/dist/chunk-VGAHZKNJ.js +0 -66
  426. package/dist/chunk-VGAHZKNJ.js.map +0 -1
  427. package/dist/chunk-VTJTAAXC.js +0 -627
  428. package/dist/chunk-VTJTAAXC.js.map +0 -1
  429. package/dist/chunk-VXVLKRU6.js +0 -758
  430. package/dist/chunk-VXVLKRU6.js.map +0 -1
  431. package/dist/chunk-WWUU5ETI.js +0 -163
  432. package/dist/chunk-WWUU5ETI.js.map +0 -1
  433. package/dist/chunk-XE4OXN2W.js +0 -10
  434. package/dist/chunk-XE4OXN2W.js.map +0 -1
  435. package/dist/chunk-XOJORS75.js +0 -1853
  436. package/dist/chunk-XOJORS75.js.map +0 -1
  437. package/dist/chunk-YMZEUTD2.js +0 -110
  438. package/dist/chunk-YMZEUTD2.js.map +0 -1
  439. package/dist/chunk-Z77BTSOK.js +0 -617
  440. package/dist/chunk-Z77BTSOK.js.map +0 -1
  441. package/dist/chunk-ZZK3WEDI.js +0 -181
  442. package/dist/chunk-ZZK3WEDI.js.map +0 -1
  443. package/dist/client-CCXpAZ2r.d.ts +0 -89
  444. package/dist/client-DSI_760t.d.ts +0 -36
  445. package/dist/client-JU6T3UPB.js +0 -11
  446. package/dist/client-JU6T3UPB.js.map +0 -1
  447. package/dist/dist-2X4Q7PJA.js +0 -1491
  448. package/dist/dist-2X4Q7PJA.js.map +0 -1
  449. package/dist/env-4UWSUS64.js +0 -4
  450. package/dist/env-4UWSUS64.js.map +0 -1
  451. package/dist/graph-emitter-r5TylDBm.d.ts +0 -47
  452. package/dist/graphql-CMHMQjvd.d.ts +0 -23
  453. package/dist/i18n-Qm2AkPC-.d.ts +0 -33
  454. package/dist/index--yvpa6ay.d.ts +0 -83
  455. package/dist/index-4gKQKZ2B.d.ts +0 -71
  456. package/dist/index-5x0XMKXN.d.ts +0 -149
  457. package/dist/index-B70b5mYS.d.ts +0 -33
  458. package/dist/index-B8KrxO4j.d.ts +0 -755
  459. package/dist/index-BOuDKnqD.d.ts +0 -201
  460. package/dist/index-BTMt4OjA.d.ts +0 -201
  461. package/dist/index-BejbszA7.d.ts +0 -39
  462. package/dist/index-BkeOYZye.d.ts +0 -198
  463. package/dist/index-BuAj5nXg.d.ts +0 -83
  464. package/dist/index-BvkVcW8I.d.ts +0 -349
  465. package/dist/index-CWmH_-RZ.d.ts +0 -247
  466. package/dist/index-CbgWNcus.d.ts +0 -258
  467. package/dist/index-CmfPeQza.d.ts +0 -166
  468. package/dist/index-CmpG-zak.d.ts +0 -607
  469. package/dist/index-CoMKgL-p.d.ts +0 -12
  470. package/dist/index-D8HGwglK.d.ts +0 -541
  471. package/dist/index-DCaVm66D.d.ts +0 -1101
  472. package/dist/index-DE2w7E0d.d.ts +0 -83
  473. package/dist/index-DSOpj8DI.d.ts +0 -17
  474. package/dist/index-DW9q22GH.d.ts +0 -75
  475. package/dist/index-DnjJ9CwI.d.ts +0 -347
  476. package/dist/index-DwMJZ8PP.d.ts +0 -317
  477. package/dist/index-PaojfSdd.d.ts +0 -71
  478. package/dist/index-aHtYvc3i.d.ts +0 -284
  479. package/dist/index-e_18DzAg.d.ts +0 -18
  480. package/dist/index-ffmipXSA.d.ts +0 -55
  481. package/dist/index-joONjwLt.d.ts +0 -33
  482. package/dist/index-kssw5ziY.d.ts +0 -250
  483. package/dist/index-lFffh5-G.d.ts +0 -125
  484. package/dist/index-pxYge_6k.d.ts +0 -79
  485. package/dist/layer-Cv9vSwBx.d.ts +0 -70
  486. package/dist/pino-logger-H4HPW5P6.js +0 -5
  487. package/dist/pino-logger-H4HPW5P6.js.map +0 -1
  488. package/dist/prisma-extension-gYhYriA0.d.ts +0 -174
  489. package/dist/sdk-L75WWUP3.js +0 -156
  490. package/dist/sdk-L75WWUP3.js.map +0 -1
  491. package/dist/shutdown-registry-CW9LryO8.d.ts +0 -10
  492. package/dist/types-Bo2wkjSP.d.ts +0 -35
  493. package/dist/types-DVpvrAhd.d.ts +0 -71
  494. package/dist/types-DgJ4lDYA.d.ts +0 -108
  495. package/dist/types-USOv09qy.d.ts +0 -327
  496. package/dist/workspace-guard-NXVYYBVJ.js +0 -5
  497. package/dist/workspace-guard-NXVYYBVJ.js.map +0 -1
@@ -1,1480 +0,0 @@
1
- import { resolveEventStreamsUrl } from './chunk-KS2HQCJR.js';
2
- import { RedisStreamsConnection, isWildcard, streamKey, boundaryOf, dlqKey, registryKey, delayLockKey, delayQueueKey, dedupKey, replyKey, matchSubject } from './chunk-6XEXJATV.js';
3
- import { registerDisposable, unregisterDisposable } from './chunk-KO2ZXZ7W.js';
4
- import { logger } from './chunk-RU266375.js';
5
- import { __name } from './chunk-XE4OXN2W.js';
6
- import { randomUUID } from 'crypto';
7
- import { hostname } from 'os';
8
-
9
- // src/event-queue/implementations/redis-streams/trace-context.ts
10
- var otelApiPromise = null;
11
- async function loadOtelApi() {
12
- if (otelApiPromise) return otelApiPromise;
13
- otelApiPromise = (async () => {
14
- try {
15
- const mod = await import('./dist-2X4Q7PJA.js');
16
- return mod;
17
- } catch {
18
- logger.debug("[redis-streams/trace-context] @opentelemetry/api not available; tracing disabled");
19
- return null;
20
- }
21
- })();
22
- return otelApiPromise;
23
- }
24
- __name(loadOtelApi, "loadOtelApi");
25
- var TRACE_KEYS = [
26
- "traceparent",
27
- "tracestate",
28
- "baggage"
29
- ];
30
- async function injectTraceFields() {
31
- const api = await loadOtelApi();
32
- if (!api) return {};
33
- const carrier = {};
34
- try {
35
- api.propagation.inject(api.context.active(), carrier, {
36
- set(c, k, v) {
37
- c[k] = v;
38
- }
39
- });
40
- } catch (err) {
41
- logger.debug("[redis-streams/trace-context] inject failed", {
42
- error: err instanceof Error ? err.message : String(err)
43
- });
44
- }
45
- return carrier;
46
- }
47
- __name(injectTraceFields, "injectTraceFields");
48
- async function extractTraceContext(fields) {
49
- const api = await loadOtelApi();
50
- if (!api) return void 0;
51
- const carrier = {};
52
- for (const key of TRACE_KEYS) {
53
- const value = fields[key];
54
- if (value) carrier[key] = value;
55
- }
56
- try {
57
- return api.propagation.extract(api.context.active(), carrier, {
58
- get(c, k) {
59
- return c[k];
60
- },
61
- keys(c) {
62
- return Object.keys(c);
63
- }
64
- });
65
- } catch {
66
- return void 0;
67
- }
68
- }
69
- __name(extractTraceContext, "extractTraceContext");
70
- async function runWithConsumerSpan(subject, fields, handler) {
71
- const api = await loadOtelApi();
72
- if (!api) return handler();
73
- let started = false;
74
- const once = /* @__PURE__ */ __name(() => {
75
- started = true;
76
- return handler();
77
- }, "once");
78
- try {
79
- const parentCtx = await extractTraceContext(fields);
80
- const tracer = api.trace.getTracer("@burdenoff/be-sdk/redis-streams");
81
- return await new Promise((resolve, reject) => {
82
- tracer.startActiveSpan(`redis-streams.consume ${subject}`, {
83
- kind: 5,
84
- attributes: {
85
- "messaging.system": "redis",
86
- "messaging.destination.name": subject
87
- }
88
- }, parentCtx, async (span) => {
89
- try {
90
- const result = await once();
91
- span.setStatus({
92
- code: 1
93
- });
94
- span.end();
95
- resolve(result);
96
- } catch (err) {
97
- span.recordException(err instanceof Error ? err : new Error(String(err)));
98
- span.setStatus({
99
- code: 2,
100
- message: err instanceof Error ? err.message : String(err)
101
- });
102
- span.end();
103
- reject(err);
104
- }
105
- });
106
- });
107
- } catch (err) {
108
- if (started) throw err;
109
- return handler();
110
- }
111
- }
112
- __name(runWithConsumerSpan, "runWithConsumerSpan");
113
-
114
- // src/event-queue/implementations/redis-streams/settlement.ts
115
- function messageSettlement(transport) {
116
- let tail = Promise.resolve();
117
- let confirmed = false;
118
- let publication = null;
119
- let published = false;
120
- let held = false;
121
- const serial = /* @__PURE__ */ __name((operation) => {
122
- const result = tail.then(operation);
123
- tail = result.catch(() => void 0);
124
- return result;
125
- }, "serial");
126
- const acknowledge = /* @__PURE__ */ __name(async () => {
127
- await transport.acknowledge();
128
- confirmed = true;
129
- transport.confirmed();
130
- }, "acknowledge");
131
- const settle = /* @__PURE__ */ __name((intent, publish) => serial(async () => {
132
- if (confirmed) return;
133
- if (held) throw new Error("EVENT_SETTLEMENT_PUBLICATION_UNKNOWN");
134
- if (publication && intent !== publication && intent !== "ACK") throw new Error("EVENT_SETTLEMENT_INTENT_CONFLICT");
135
- publication ??= intent;
136
- if (publish && !published) {
137
- publication = intent;
138
- held = true;
139
- try {
140
- await publish();
141
- published = true;
142
- held = false;
143
- } catch {
144
- throw new Error("EVENT_SETTLEMENT_PUBLICATION_UNKNOWN");
145
- }
146
- }
147
- await acknowledge();
148
- }), "settle");
149
- return {
150
- ack: /* @__PURE__ */ __name(() => settle("ACK"), "ack"),
151
- nak: /* @__PURE__ */ __name((delay = 0) => {
152
- if (!Number.isSafeInteger(delay) || delay < 0) return Promise.reject(new Error("EVENT_SETTLEMENT_DELAY_INVALID"));
153
- if (delay === 0) return serial(async () => {
154
- if (held) throw new Error("EVENT_SETTLEMENT_PUBLICATION_UNKNOWN");
155
- if (publication && !confirmed) throw new Error("EVENT_SETTLEMENT_INTENT_CONFLICT");
156
- });
157
- return settle(`DELAY:${delay}`, () => transport.delay(delay));
158
- }, "nak"),
159
- term: /* @__PURE__ */ __name((reason) => settle(`TERM:${reason ?? "explicit"}`, () => transport.terminate(reason)), "term")
160
- };
161
- }
162
- __name(messageSettlement, "messageSettlement");
163
-
164
- // src/event-queue/implementations/dispatch-limiter.ts
165
- function resolveConcurrency(value, label = "concurrency") {
166
- if (value === void 0) return 1;
167
- if (!Number.isInteger(value) || value < 1) {
168
- throw new Error(`[event-queue] ${label} must be a positive integer, got ${String(value)}`);
169
- }
170
- return value;
171
- }
172
- __name(resolveConcurrency, "resolveConcurrency");
173
- function resolveDrainTimeout(value, fallbackMs) {
174
- if (value === void 0) return fallbackMs;
175
- if (!Number.isFinite(value) || value < 0) {
176
- throw new Error(`[event-queue] drainTimeoutMs must be a non-negative number, got ${String(value)}`);
177
- }
178
- return value;
179
- }
180
- __name(resolveDrainTimeout, "resolveDrainTimeout");
181
- var DispatchLimiter = class {
182
- static {
183
- __name(this, "DispatchLimiter");
184
- }
185
- concurrency;
186
- active = 0;
187
- waiters = [];
188
- running = /* @__PURE__ */ new Set();
189
- constructor(concurrency) {
190
- this.concurrency = concurrency;
191
- resolveConcurrency(concurrency);
192
- }
193
- /** Slots not currently held. */
194
- get freeSlots() {
195
- return this.concurrency - this.active;
196
- }
197
- /** Handlers started through {@link run} that have not settled yet. */
198
- get inFlight() {
199
- return this.running.size;
200
- }
201
- /** Waits for a slot and takes it. Waiters are served in FIFO order. */
202
- acquire() {
203
- if (this.active < this.concurrency) {
204
- this.active++;
205
- return Promise.resolve();
206
- }
207
- return new Promise((resolve) => {
208
- this.waiters.push(() => {
209
- this.active++;
210
- resolve();
211
- });
212
- });
213
- }
214
- /** Takes a slot only if one is free right now. */
215
- tryAcquire() {
216
- if (this.active >= this.concurrency) return false;
217
- this.active++;
218
- return true;
219
- }
220
- /** Returns a slot taken with {@link acquire} or {@link tryAcquire} that was not passed to {@link run}. */
221
- release() {
222
- if (this.active === 0) return;
223
- this.active--;
224
- const next = this.waiters.shift();
225
- next?.();
226
- }
227
- /**
228
- * Runs `task` on a slot the caller already holds and releases the slot when
229
- * the task settles. The task must handle its own errors; a rejection is
230
- * swallowed here so one failure never affects its siblings.
231
- */
232
- run(task) {
233
- const promise = Promise.resolve().then(task).catch(() => void 0).finally(() => {
234
- this.running.delete(promise);
235
- this.release();
236
- });
237
- this.running.add(promise);
238
- }
239
- /**
240
- * Waits for every running task, at most `timeoutMs`. Resolves `true` when
241
- * everything settled in time and `false` on timeout (the tasks keep running).
242
- */
243
- async drain(timeoutMs) {
244
- if (this.running.size === 0) return true;
245
- let timer;
246
- const timedOut = new Promise((resolve) => {
247
- timer = setTimeout(() => resolve(false), timeoutMs);
248
- timer.unref?.();
249
- });
250
- const settled = (async () => {
251
- while (this.running.size > 0) await Promise.allSettled([
252
- ...this.running
253
- ]);
254
- return true;
255
- })();
256
- try {
257
- return await Promise.race([
258
- settled,
259
- timedOut
260
- ]);
261
- } finally {
262
- if (timer) clearTimeout(timer);
263
- }
264
- }
265
- };
266
-
267
- // src/event-queue/implementations/redis-streams/RedisStreamsEventConsumer.ts
268
- var DEFAULT_BLOCK_MS = 5e3;
269
- var DEFAULT_BATCH = 10;
270
- var REGISTRY_REFRESH_MS = 1e4;
271
- var DEFAULT_ACK_WAIT_MS = 3e4;
272
- var DEFAULT_MAX_DELIVER = 3;
273
- var SWEEP_INTERVAL_MS = 15e3;
274
- var SWEEP_BATCH = 50;
275
- var HEARTBEAT_MIN_INTERVAL_MS = 250;
276
- var HEARTBEAT_CHUNK = 100;
277
- var DELAYQ_INTERVAL_MS = 1e3;
278
- var DELIVERY_ATTEMPTS_FIELD = "delivery-attempts";
279
- function parsePendingRows(reply) {
280
- if (!Array.isArray(reply)) return [];
281
- const rows = [];
282
- for (const row of reply) {
283
- if (!Array.isArray(row)) continue;
284
- const id = row[0];
285
- const deliveries = Number(row[3]);
286
- if (typeof id !== "string" || !Number.isFinite(deliveries)) continue;
287
- rows.push({
288
- id,
289
- deliveries
290
- });
291
- }
292
- return rows;
293
- }
294
- __name(parsePendingRows, "parsePendingRows");
295
- function parseClaimedEntries(reply) {
296
- const out = /* @__PURE__ */ new Map();
297
- if (!Array.isArray(reply)) return out;
298
- for (const entry of reply) {
299
- if (!Array.isArray(entry)) continue;
300
- const id = entry[0];
301
- const fields = entry[1];
302
- if (typeof id !== "string" || !Array.isArray(fields)) continue;
303
- out.set(id, fields.filter((f) => typeof f === "string"));
304
- }
305
- return out;
306
- }
307
- __name(parseClaimedEntries, "parseClaimedEntries");
308
- function errorMessage(err) {
309
- return err instanceof Error ? err.message : String(err);
310
- }
311
- __name(errorMessage, "errorMessage");
312
- function priorAttempts(fields) {
313
- const raw = fields[DELIVERY_ATTEMPTS_FIELD];
314
- if (raw === void 0) return 0;
315
- const n = Number(raw);
316
- return Number.isSafeInteger(n) && n > 0 ? n : 0;
317
- }
318
- __name(priorAttempts, "priorAttempts");
319
- function resolveMaxDeliver(value, fallback) {
320
- if (value === void 0) return fallback;
321
- if (!Number.isInteger(value) || value < 1) {
322
- throw new Error(`[RedisStreamsEventConsumer] maxDeliver must be a positive integer, got ${String(value)}`);
323
- }
324
- return value;
325
- }
326
- __name(resolveMaxDeliver, "resolveMaxDeliver");
327
- var RedisStreamsSubscription = class RedisStreamsSubscription2 {
328
- static {
329
- __name(this, "RedisStreamsSubscription");
330
- }
331
- subject;
332
- unsubscribeFn;
333
- id = randomUUID();
334
- active = true;
335
- receivedCount = 0;
336
- processedCount = 0;
337
- failedCount = 0;
338
- lastActivity = (/* @__PURE__ */ new Date()).toISOString();
339
- constructor(subject, unsubscribeFn) {
340
- this.subject = subject;
341
- this.unsubscribeFn = unsubscribeFn;
342
- }
343
- async unsubscribe() {
344
- if (!this.active) return;
345
- this.active = false;
346
- await this.unsubscribeFn();
347
- }
348
- isActive() {
349
- return this.active;
350
- }
351
- getStats() {
352
- return {
353
- messagesReceived: this.receivedCount,
354
- messagesProcessed: this.processedCount,
355
- messagesFailed: this.failedCount,
356
- lastActivity: this.lastActivity
357
- };
358
- }
359
- recordReceived() {
360
- this.receivedCount++;
361
- this.lastActivity = (/* @__PURE__ */ new Date()).toISOString();
362
- }
363
- recordProcessed() {
364
- this.processedCount++;
365
- this.lastActivity = (/* @__PURE__ */ new Date()).toISOString();
366
- }
367
- recordFailed() {
368
- this.failedCount++;
369
- this.lastActivity = (/* @__PURE__ */ new Date()).toISOString();
370
- }
371
- };
372
- var RedisStreamsEventConsumer = class {
373
- static {
374
- __name(this, "RedisStreamsEventConsumer");
375
- }
376
- shutdownName;
377
- connection;
378
- subscriptions = [];
379
- subscriptionLoops = /* @__PURE__ */ new Set();
380
- keyPrefix;
381
- consumerName;
382
- group;
383
- maxDeliver;
384
- ackWaitMs;
385
- /** XREADGROUP COUNT for serial subscriptions (historical name; not a concurrency limit). */
386
- maxConcurrent;
387
- concurrency;
388
- drainTimeoutMs;
389
- consumedCount = 0;
390
- failedCount = 0;
391
- lastActivity = null;
392
- stopped = false;
393
- sweepTimer = null;
394
- delayqTimer = null;
395
- heartbeatTimer = null;
396
- /** stream -> the subscription loop consuming it (used to re-dispatch reclaimed entries). */
397
- workers = /* @__PURE__ */ new Map();
398
- /** Every stream loop a subscription started, for drain and cleanup. */
399
- subWorkers = /* @__PURE__ */ new Map();
400
- /** stream -> ids read by this process and not yet settled by their handler. */
401
- held = /* @__PURE__ */ new Map();
402
- /** Blocking clients per subscription, closed on unsubscribe to abort a pending XREADGROUP BLOCK. */
403
- blockingClients = /* @__PURE__ */ new Map();
404
- settlements = /* @__PURE__ */ new Map();
405
- retainedSerializedFieldsBytes = 0;
406
- knownStreams = /* @__PURE__ */ new Map();
407
- constructor(config) {
408
- this.connection = new RedisStreamsConnection({
409
- type: "redis-streams",
410
- url: config.url ?? process.env["REDIS_URL"] ?? "redis://localhost:6379",
411
- user: config.user,
412
- password: config.password,
413
- name: config.name,
414
- connectionTimeout: config.connectionTimeout,
415
- keyScope: config.keyScope
416
- });
417
- this.keyPrefix = config.keyPrefix ?? process.env["REDIS_STREAMS_KEY_PREFIX"] ?? "boff:events";
418
- this.group = config.consumer || config.name || "default-consumer";
419
- this.consumerName = `${this.group}:${hostname()}:${process.pid}`;
420
- this.maxDeliver = config.maxDeliver ?? DEFAULT_MAX_DELIVER;
421
- this.ackWaitMs = config.ackWait ? Math.max(1e3, Math.round(config.ackWait / 1e6)) : DEFAULT_ACK_WAIT_MS;
422
- this.maxConcurrent = config.maxConcurrent ?? 5;
423
- this.concurrency = resolveConcurrency(config.concurrency);
424
- this.drainTimeoutMs = resolveDrainTimeout(config.drainTimeoutMs, this.ackWaitMs);
425
- this.shutdownName = `redis-streams-consumer:${config.name ?? this.group}`;
426
- registerDisposable(this);
427
- }
428
- /** Close underlying connections on graceful shutdown. */
429
- dispose() {
430
- return this.disconnect();
431
- }
432
- async connect() {
433
- await this.connection.connect();
434
- if (!this.sweepTimer) {
435
- const t = setInterval(() => {
436
- void this.sweepPending().catch((err) => {
437
- logger.debug("[RedisStreamsEventConsumer] sweep error", {
438
- error: err instanceof Error ? err.message : String(err)
439
- });
440
- });
441
- }, SWEEP_INTERVAL_MS);
442
- t.unref?.();
443
- this.sweepTimer = t;
444
- }
445
- if (!this.delayqTimer) {
446
- const t = setInterval(() => {
447
- void this.drainDelayQueues().catch(() => void 0);
448
- }, DELAYQ_INTERVAL_MS);
449
- t.unref?.();
450
- this.delayqTimer = t;
451
- }
452
- if (!this.heartbeatTimer) {
453
- const t = setInterval(() => {
454
- void this.heartbeat().catch(() => void 0);
455
- }, Math.max(HEARTBEAT_MIN_INTERVAL_MS, Math.floor(this.ackWaitMs / 2)));
456
- t.unref?.();
457
- this.heartbeatTimer = t;
458
- }
459
- }
460
- /**
461
- * Stops reading, waits for in-flight handlers (bounded by `drainTimeoutMs`)
462
- * so they can still ack, then closes the connection. The heartbeat keeps
463
- * running during the drain so live entries are not reclaimed meanwhile.
464
- */
465
- async disconnect() {
466
- unregisterDisposable(this);
467
- this.stopped = true;
468
- if (this.sweepTimer) clearInterval(this.sweepTimer);
469
- if (this.delayqTimer) clearInterval(this.delayqTimer);
470
- this.sweepTimer = null;
471
- this.delayqTimer = null;
472
- await this.unsubscribeAll();
473
- if (this.heartbeatTimer) clearInterval(this.heartbeatTimer);
474
- this.heartbeatTimer = null;
475
- await this.connection.disconnect();
476
- }
477
- isConnected() {
478
- return this.connection.isConnected();
479
- }
480
- async healthCheck() {
481
- try {
482
- const t0 = Date.now();
483
- const pong = await this.connection.ping();
484
- return {
485
- status: pong === "PONG" ? "healthy" : "degraded",
486
- timestamp: (/* @__PURE__ */ new Date()).toISOString(),
487
- connected: this.isConnected(),
488
- latencyMs: Date.now() - t0,
489
- details: {
490
- type: "redis-streams",
491
- subscriptions: this.subscriptions.length
492
- }
493
- };
494
- } catch (err) {
495
- return {
496
- status: "unhealthy",
497
- timestamp: (/* @__PURE__ */ new Date()).toISOString(),
498
- connected: false,
499
- details: {
500
- type: "redis-streams"
501
- },
502
- error: err instanceof Error ? err.message : String(err)
503
- };
504
- }
505
- }
506
- async getStatistics() {
507
- return Promise.resolve({
508
- messagesConsumed: this.consumedCount,
509
- messagesFailed: this.failedCount,
510
- messagesPublished: 0,
511
- activeConsumers: this.subscriptions.length,
512
- lastActivity: this.lastActivity?.toISOString() ?? null,
513
- details: {
514
- type: "redis-streams",
515
- group: this.group
516
- }
517
- });
518
- }
519
- async ensureStream(_config) {
520
- return Promise.resolve();
521
- }
522
- async ensureConsumer(_config) {
523
- return Promise.resolve();
524
- }
525
- async subscribe(opts) {
526
- await this.connect();
527
- const concurrency = resolveConcurrency(opts.options?.concurrency ?? this.concurrency);
528
- const drainTimeoutMs = resolveDrainTimeout(opts.options?.drainTimeoutMs, this.drainTimeoutMs);
529
- const maxDeliver = resolveMaxDeliver(opts.options?.maxDeliver, this.maxDeliver);
530
- const limiter = /* @__PURE__ */ __name(() => new DispatchLimiter(concurrency), "limiter");
531
- const sub = new RedisStreamsSubscription(opts.subject, async () => {
532
- this.subscriptions = this.subscriptions.filter((s) => s !== sub);
533
- this.abortReads(sub);
534
- await this.drainSubscription(sub, opts.subject, drainTimeoutMs);
535
- this.releaseStreams(sub);
536
- });
537
- this.subscriptions.push(sub);
538
- const startId = this.resolveStartId(opts.options?.deliverPolicy);
539
- const wildcard = isWildcard(opts.subject);
540
- const handlerFn = opts.handler;
541
- if (opts.options?.stream) {
542
- const stream = streamKey(opts.options.stream, {
543
- prefix: this.keyPrefix,
544
- scope: this.connection.keyScope
545
- });
546
- await this.ensureGroup(stream, startId);
547
- this.knownStreams.set(stream, opts.subject);
548
- const subjectFilter = wildcard ? opts.subject : null;
549
- const filteredHandler = subjectFilter ? async (evt) => {
550
- if (matchSubject(subjectFilter, evt.subject)) {
551
- await handlerFn(evt);
552
- } else {
553
- await evt.ack();
554
- }
555
- } : handlerFn;
556
- this.spawnLoop(sub, stream, opts.subject, filteredHandler, limiter(), maxDeliver);
557
- return sub;
558
- }
559
- if (!wildcard) {
560
- const stream = streamKey(opts.subject, {
561
- prefix: this.keyPrefix,
562
- scope: this.connection.keyScope
563
- });
564
- await this.ensureGroup(stream, startId);
565
- this.knownStreams.set(stream, opts.subject);
566
- this.spawnLoop(sub, stream, opts.subject, handlerFn, limiter(), maxDeliver);
567
- } else {
568
- const boundary = boundaryOf(opts.subject);
569
- const refresh = /* @__PURE__ */ __name(async () => {
570
- const client = this.connection.getClient();
571
- const subjects = await client.smembers(registryKey(boundary, this.connection.keyScope));
572
- for (const s of subjects) {
573
- if (!matchSubject(opts.subject, s)) continue;
574
- const stream = streamKey(s, {
575
- prefix: this.keyPrefix,
576
- scope: this.connection.keyScope
577
- });
578
- if (this.knownStreams.has(stream)) continue;
579
- await this.ensureGroup(stream, startId);
580
- this.knownStreams.set(stream, s);
581
- this.spawnLoop(sub, stream, s, handlerFn, limiter(), maxDeliver);
582
- }
583
- }, "refresh");
584
- await refresh();
585
- const t = setInterval(() => {
586
- if (this.stopped || !sub.isActive()) {
587
- clearInterval(t);
588
- return;
589
- }
590
- void refresh().catch(() => void 0);
591
- }, REGISTRY_REFRESH_MS);
592
- t.unref?.();
593
- }
594
- return sub;
595
- }
596
- async subscribeMultiple(subjects, handler, options) {
597
- const out = [];
598
- for (const subject of subjects) {
599
- out.push(await this.subscribe({
600
- subject,
601
- handler,
602
- options
603
- }));
604
- }
605
- return out;
606
- }
607
- async pull(opts) {
608
- await this.connect();
609
- const stream = streamKey(opts.subject, {
610
- prefix: this.keyPrefix,
611
- scope: this.connection.keyScope
612
- });
613
- await this.ensureGroup(stream, "$");
614
- const client = this.connection.getClient();
615
- const raw = await client.xreadgroup("GROUP", this.group, this.consumerName, "COUNT", opts.batch ?? DEFAULT_BATCH, "BLOCK", opts.timeout ?? DEFAULT_BLOCK_MS, "STREAMS", stream, ">");
616
- if (!raw) return [];
617
- const out = [];
618
- for (const [streamName, entries] of raw) {
619
- for (const [id, rawFields] of entries) {
620
- const parsed = this.parseEntry(streamName, id, rawFields);
621
- out.push(this.toAcknowledgeable(streamName, id, parsed));
622
- }
623
- }
624
- return out;
625
- }
626
- async unsubscribeAll() {
627
- await Promise.all([
628
- ...this.subscriptions
629
- ].map((sub) => sub.unsubscribe()));
630
- this.subscriptions = [];
631
- this.subscriptionLoops.clear();
632
- }
633
- getSubscriptions() {
634
- return [
635
- ...this.subscriptions
636
- ];
637
- }
638
- async processDLQ(handler) {
639
- await this.connect();
640
- const client = this.connection.getClient();
641
- const dlqGroup = `${this.group}-dlq`;
642
- for (const [stream] of this.knownStreams) {
643
- const dlq = dlqKey(stream, this.connection.keyScope);
644
- try {
645
- await client.xgroup("CREATE", dlq, dlqGroup, "0", "MKSTREAM");
646
- } catch {
647
- }
648
- const res = await client.xreadgroup("GROUP", dlqGroup, this.consumerName, "COUNT", 50, "BLOCK", 100, "STREAMS", dlq, ">");
649
- if (!res) continue;
650
- for (const [, entries] of res) {
651
- for (const [id, rawFields] of entries) {
652
- const parsed = this.parseEntry(dlq, id, rawFields);
653
- const evt = this.toAcknowledgeable(dlq, id, parsed, dlqGroup);
654
- try {
655
- await handler(evt);
656
- } catch (err) {
657
- logger.error("[RedisStreamsEventConsumer] DLQ handler error", {
658
- error: err instanceof Error ? err.message : String(err)
659
- });
660
- }
661
- }
662
- }
663
- }
664
- }
665
- async listSubjects(_stream) {
666
- await this.connect();
667
- const client = this.connection.getClient();
668
- const seen = /* @__PURE__ */ new Set();
669
- for (const subject of this.knownStreams.values()) {
670
- const members = await client.smembers(registryKey(boundaryOf(subject), this.connection.keyScope));
671
- for (const m of members) seen.add(m);
672
- }
673
- return [
674
- ...seen
675
- ];
676
- }
677
- // ---- internals ----
678
- resolveStartId(policy) {
679
- switch (policy) {
680
- case "all":
681
- return "0";
682
- case "new":
683
- return "$";
684
- case "last":
685
- return "$";
686
- default:
687
- return "$";
688
- }
689
- }
690
- async ensureGroup(stream, startId) {
691
- const client = this.connection.getClient();
692
- try {
693
- await client.xgroup("CREATE", stream, this.group, startId, "MKSTREAM");
694
- logger.debug("[RedisStreamsEventConsumer] group created", {
695
- stream,
696
- group: this.group,
697
- startId
698
- });
699
- } catch (err) {
700
- const msg = err instanceof Error ? err.message : String(err);
701
- if (!msg.includes("BUSYGROUP")) {
702
- throw err;
703
- }
704
- }
705
- }
706
- heldFor(stream) {
707
- let ids = this.held.get(stream);
708
- if (!ids) {
709
- ids = /* @__PURE__ */ new Set();
710
- this.held.set(stream, ids);
711
- }
712
- return ids;
713
- }
714
- /** Closes the subscription's blocking clients so a pending XREADGROUP BLOCK returns now. */
715
- abortReads(sub) {
716
- for (const client of this.blockingClients.get(sub) ?? []) {
717
- try {
718
- client.disconnect();
719
- } catch {
720
- }
721
- }
722
- }
723
- /** Waits for the in-flight handlers of every stream loop of `sub`, at most `timeoutMs` in total. */
724
- async drainSubscription(sub, subject, timeoutMs) {
725
- const limiters = (this.subWorkers.get(sub) ?? []).map(({ worker }) => worker.limiter);
726
- const results = await Promise.all(limiters.map((l) => l.drain(timeoutMs)));
727
- if (results.every(Boolean)) return;
728
- logger.warn("[RedisStreamsEventConsumer] drain timed out; unfinished entries stay pending for reclaim", {
729
- subject,
730
- inFlight: limiters.reduce((sum, l) => sum + l.inFlight, 0),
731
- drainTimeoutMs: timeoutMs
732
- });
733
- }
734
- /** Forgets the streams a finished subscription consumed so the sweep and heartbeat stop touching them. */
735
- releaseStreams(sub) {
736
- for (const { stream, worker } of this.subWorkers.get(sub) ?? []) {
737
- if (this.workers.get(stream) !== worker) continue;
738
- this.workers.delete(stream);
739
- this.knownStreams.delete(stream);
740
- this.held.delete(stream);
741
- }
742
- this.subWorkers.delete(sub);
743
- this.blockingClients.delete(sub);
744
- }
745
- spawnLoop(sub, stream, subject, handler, limiter, maxDeliver) {
746
- const worker = {
747
- sub,
748
- subject,
749
- handler,
750
- limiter,
751
- maxDeliver,
752
- queued: 0
753
- };
754
- this.workers.set(stream, worker);
755
- const started = this.subWorkers.get(sub) ?? [];
756
- started.push({
757
- stream,
758
- worker
759
- });
760
- this.subWorkers.set(sub, started);
761
- void this.runLoop(stream, worker).catch((err) => {
762
- logger.error("[RedisStreamsEventConsumer] loop crashed", {
763
- stream,
764
- error: errorMessage(err)
765
- });
766
- });
767
- }
768
- isRunning(worker) {
769
- return !this.stopped && worker.sub.isActive();
770
- }
771
- async runLoop(stream, worker) {
772
- const client = await this.connection.makeBlockingClient();
773
- let clients = this.blockingClients.get(worker.sub);
774
- if (!clients) {
775
- clients = /* @__PURE__ */ new Set();
776
- this.blockingClients.set(worker.sub, clients);
777
- }
778
- clients.add(client);
779
- try {
780
- while (this.isRunning(worker)) {
781
- await worker.limiter.acquire();
782
- if (!this.isRunning(worker)) {
783
- worker.limiter.release();
784
- break;
785
- }
786
- const entries = await this.readBatch(client, stream, worker);
787
- if (entries.length === 0) {
788
- worker.limiter.release();
789
- continue;
790
- }
791
- await this.dispatchBatch(stream, worker, entries);
792
- }
793
- } finally {
794
- clients.delete(client);
795
- try {
796
- client.disconnect();
797
- } catch {
798
- }
799
- }
800
- }
801
- /**
802
- * One XREADGROUP. A serial subscription reads `maxConcurrent` (the batch
803
- * size); a parallel one reads only as many entries as it has slots for.
804
- * Read errors are logged and yield an empty batch.
805
- */
806
- async readBatch(client, stream, worker) {
807
- const { limiter } = worker;
808
- const count = limiter.concurrency === 1 ? this.maxConcurrent : 1 + limiter.freeSlots;
809
- try {
810
- const raw = await client.xreadgroup("GROUP", this.group, this.consumerName, "COUNT", count, "BLOCK", DEFAULT_BLOCK_MS, "STREAMS", stream, ">");
811
- return (raw ?? []).flatMap(([, batch]) => batch);
812
- } catch (err) {
813
- if (!this.isRunning(worker)) return [];
814
- const msg = errorMessage(err);
815
- if (msg.includes("NOGROUP")) {
816
- await this.ensureGroup(stream, "$");
817
- return [];
818
- }
819
- logger.warn("[RedisStreamsEventConsumer] read error", {
820
- stream,
821
- error: msg
822
- });
823
- await new Promise((res) => setTimeout(res, 1e3));
824
- return [];
825
- }
826
- }
827
- /**
828
- * Starts each entry of a batch on its own slot, in stream order. The caller
829
- * already holds the slot for the first entry. Every entry is held (and so
830
- * heartbeated) from the moment it is read until its handler settles.
831
- */
832
- async dispatchBatch(stream, worker, entries) {
833
- const { limiter } = worker;
834
- const held = this.heldFor(stream);
835
- for (const [id] of entries) held.add(id);
836
- for (let index = 0; index < entries.length; index++) {
837
- if (index > 0) await limiter.acquire();
838
- if (!this.isRunning(worker)) {
839
- limiter.release();
840
- for (const [rest] of entries.slice(index)) held.delete(rest);
841
- return;
842
- }
843
- const [id, rawFields] = entries[index] ?? [
844
- "",
845
- []
846
- ];
847
- limiter.run(() => this.dispatchEntry(worker, stream, id, rawFields, 1).finally(() => held.delete(id)));
848
- }
849
- }
850
- /**
851
- * Runs one entry's handler. Never rejects: a throw is logged and the entry
852
- * nak'd (left pending). `streamDeliveries` is the entry's own delivery count
853
- * in the group (1 on a first read); an entry a delayed nak re-added past the
854
- * subscription's maxDeliver is dead-lettered without running the handler.
855
- */
856
- async dispatchEntry(worker, stream, id, rawFields, streamDeliveries) {
857
- const { sub, subject, handler } = worker;
858
- sub.recordReceived();
859
- this.consumedCount++;
860
- this.lastActivity = /* @__PURE__ */ new Date();
861
- let evt = null;
862
- let fields = {};
863
- try {
864
- const parsed = this.parseEntry(stream, id, rawFields, streamDeliveries);
865
- if (parsed.deliveryCount > worker.maxDeliver) {
866
- await this.deadLetter(stream, parsed);
867
- return;
868
- }
869
- fields = parsed.fields;
870
- evt = this.toAcknowledgeable(stream, id, parsed);
871
- const event = evt;
872
- await runWithConsumerSpan(subject, fields, () => handler(event));
873
- sub.recordProcessed();
874
- } catch (err) {
875
- sub.recordFailed();
876
- this.failedCount++;
877
- logger.error("[RedisStreamsEventConsumer] handler error", {
878
- subject,
879
- id,
880
- error: errorMessage(err)
881
- });
882
- if (evt) {
883
- try {
884
- await evt.nak();
885
- } catch {
886
- }
887
- }
888
- }
889
- }
890
- /** Resets the idle time of every held entry without bumping its delivery count. */
891
- async heartbeat() {
892
- if (this.held.size === 0) return;
893
- const client = this.connection.getClient();
894
- for (const [stream, ids] of this.held) {
895
- if (ids.size === 0) continue;
896
- const list = [
897
- ...ids
898
- ];
899
- try {
900
- for (let i = 0; i < list.length; i += HEARTBEAT_CHUNK) {
901
- await client.xclaim(stream, this.group, this.consumerName, 0, ...list.slice(i, i + HEARTBEAT_CHUNK), "JUSTID");
902
- }
903
- } catch (err) {
904
- logger.debug("[RedisStreamsEventConsumer] heartbeat error", {
905
- stream,
906
- error: errorMessage(err)
907
- });
908
- }
909
- }
910
- }
911
- /**
912
- * `streamDeliveries` is the entry's delivery count in the group (1 on a
913
- * first read); attempts used before a delayed nak re-added it are added on.
914
- */
915
- parseEntry(stream, id, rawFields, streamDeliveries = 1) {
916
- const fields = {};
917
- for (let i = 0; i + 1 < rawFields.length; i += 2) {
918
- const key = rawFields[i];
919
- const val = rawFields[i + 1];
920
- if (key === void 0 || val === void 0) continue;
921
- fields[key] = val;
922
- }
923
- let data;
924
- try {
925
- data = JSON.parse(fields["payload"] ?? "null");
926
- } catch {
927
- data = fields["payload"];
928
- }
929
- let metadata;
930
- try {
931
- metadata = JSON.parse(fields["metadata"] ?? "{}");
932
- } catch {
933
- metadata = {
934
- correlationId: fields["correlation-id"] ?? ""
935
- };
936
- }
937
- if (!metadata.correlationId) metadata.correlationId = fields["correlation-id"] ?? "";
938
- return {
939
- id,
940
- stream,
941
- subject: fields["subject"] ?? "",
942
- data,
943
- metadata,
944
- timestamp: fields["timestamp"] ?? (/* @__PURE__ */ new Date()).toISOString(),
945
- fields,
946
- deliveryCount: priorAttempts(fields) + streamDeliveries
947
- };
948
- }
949
- toAcknowledgeable(stream, id, parsed, group = this.group) {
950
- const actions = this.settlement(stream, id, parsed, group);
951
- return {
952
- id,
953
- subject: parsed.subject,
954
- data: parsed.data,
955
- metadata: parsed.metadata,
956
- timestamp: parsed.timestamp,
957
- ack: actions.ack,
958
- nak: actions.nak,
959
- term: /* @__PURE__ */ __name(() => actions.term(), "term"),
960
- isRedelivered() {
961
- return parsed.deliveryCount > 1;
962
- },
963
- getDeliveryAttempt() {
964
- return parsed.deliveryCount;
965
- }
966
- };
967
- }
968
- settlement(stream, id, parsed, group) {
969
- const key = JSON.stringify([
970
- stream,
971
- group,
972
- id
973
- ]);
974
- const existing = this.settlements.get(key);
975
- if (existing) {
976
- existing.entry.deliveryCount = Math.max(existing.entry.deliveryCount, parsed.deliveryCount);
977
- return existing.actions;
978
- }
979
- const serializedFieldsBytes = new TextEncoder().encode(JSON.stringify(parsed.fields)).byteLength;
980
- if (this.settlements.size >= 1e4 || this.retainedSerializedFieldsBytes + serializedFieldsBytes > 64 * 1024 * 1024) throw new Error("EVENT_SETTLEMENT_CAPACITY_HELD");
981
- const actions = messageSettlement({
982
- acknowledge: /* @__PURE__ */ __name(async () => {
983
- await this.connection.getClient().xack(stream, group, id);
984
- }, "acknowledge"),
985
- delay: /* @__PURE__ */ __name(async (milliseconds) => {
986
- const score = Date.now() + milliseconds;
987
- if (!Number.isSafeInteger(score)) throw new Error("EVENT_SETTLEMENT_DELAY_INVALID");
988
- const carried = {
989
- ...parsed.fields,
990
- [DELIVERY_ATTEMPTS_FIELD]: String(parsed.deliveryCount)
991
- };
992
- await this.connection.getClient().zadd(delayQueueKey(stream, this.connection.keyScope), score, `${id}|${JSON.stringify(carried)}`);
993
- }, "delay"),
994
- terminate: /* @__PURE__ */ __name(async (reason) => {
995
- const flat = [];
996
- for (const [k, v] of Object.entries(parsed.fields)) flat.push(k, v);
997
- if (reason) flat.push("dlq-reason", reason, "dlq-deliveries", String(parsed.deliveryCount));
998
- await this.connection.getClient().xadd(dlqKey(stream, this.connection.keyScope), "MAXLEN", "~", 1e4, "*", ...flat);
999
- }, "terminate"),
1000
- confirmed: /* @__PURE__ */ __name(() => {
1001
- const retained = this.settlements.get(key);
1002
- if (retained) this.retainedSerializedFieldsBytes -= retained.serializedFieldsBytes;
1003
- this.settlements.delete(key);
1004
- }, "confirmed")
1005
- });
1006
- this.settlements.set(key, {
1007
- actions,
1008
- entry: parsed,
1009
- serializedFieldsBytes
1010
- });
1011
- this.retainedSerializedFieldsBytes += serializedFieldsBytes;
1012
- return actions;
1013
- }
1014
- /**
1015
- * Reclaims entries idle longer than ackWait that this process is not
1016
- * handling. Within maxDeliver they are re-dispatched through the stream's
1017
- * bounded dispatcher; past it they are dead-lettered.
1018
- */
1019
- async sweepPending() {
1020
- if (this.stopped || this.knownStreams.size === 0) return;
1021
- for (const [stream] of this.knownStreams) {
1022
- try {
1023
- await this.sweepStream(stream);
1024
- } catch (err) {
1025
- const msg = errorMessage(err);
1026
- if (msg.includes("NOGROUP")) continue;
1027
- logger.debug("[RedisStreamsEventConsumer] sweep iteration error", {
1028
- stream,
1029
- error: msg
1030
- });
1031
- }
1032
- }
1033
- }
1034
- async sweepStream(stream) {
1035
- const client = this.connection.getClient();
1036
- const rows = parsePendingRows(await client.xpending(stream, this.group, "IDLE", this.ackWaitMs, "-", "+", SWEEP_BATCH));
1037
- const worker = this.workers.get(stream);
1038
- const live = worker && this.isRunning(worker) ? worker : void 0;
1039
- const maxDeliver = live?.maxDeliver ?? this.maxDeliver;
1040
- const picked = this.pickReclaimable(stream, rows, live, maxDeliver);
1041
- if (picked.length === 0) return;
1042
- const claimed = parseClaimedEntries(await client.xclaim(stream, this.group, this.consumerName, this.ackWaitMs, ...picked.map((r) => r.id)));
1043
- for (const row of picked) {
1044
- const rawFields = claimed.get(row.id);
1045
- if (!rawFields) continue;
1046
- const streamDeliveries = row.deliveries + 1;
1047
- const parsed = this.parseEntry(stream, row.id, rawFields, streamDeliveries);
1048
- if (parsed.deliveryCount > maxDeliver) await this.deadLetter(stream, parsed);
1049
- else if (live) this.redispatch(stream, live, row.id, rawFields, streamDeliveries);
1050
- }
1051
- }
1052
- /**
1053
- * Chooses which idle entries to claim: never one this process is handling;
1054
- * every one past maxDeliver (to dead-letter it); and, within maxDeliver, no
1055
- * more than the live dispatcher can run alongside what it already runs, so
1056
- * a replica never hoards reclaimed work it cannot start soon.
1057
- */
1058
- pickReclaimable(stream, rows, live, maxDeliver) {
1059
- const held = this.held.get(stream);
1060
- let budget = live ? live.limiter.concurrency - live.limiter.inFlight - live.queued : 0;
1061
- const picked = [];
1062
- for (const row of rows) {
1063
- if (held?.has(row.id)) continue;
1064
- if (row.deliveries + 1 > maxDeliver) {
1065
- picked.push(row);
1066
- } else if (budget > 0) {
1067
- budget--;
1068
- picked.push(row);
1069
- }
1070
- }
1071
- return picked;
1072
- }
1073
- async deadLetter(stream, parsed) {
1074
- const { id, deliveryCount } = parsed;
1075
- try {
1076
- await this.settlement(stream, id, parsed, this.group).term("max-deliver-exceeded");
1077
- logger.warn("[RedisStreamsEventConsumer] message moved to DLQ", {
1078
- stream,
1079
- id,
1080
- deliveryCount
1081
- });
1082
- } catch (err) {
1083
- logger.debug("[RedisStreamsEventConsumer] dead-letter failed; retried on next sweep", {
1084
- stream,
1085
- id,
1086
- error: errorMessage(err)
1087
- });
1088
- }
1089
- }
1090
- /**
1091
- * Runs a reclaimed entry on the stream's dispatcher. It is held (and so
1092
- * heartbeated) while it waits for a slot; if the subscription stops first
1093
- * it is left pending for another replica.
1094
- */
1095
- redispatch(stream, worker, id, rawFields, streamDeliveries) {
1096
- const held = this.heldFor(stream);
1097
- held.add(id);
1098
- worker.queued++;
1099
- void worker.limiter.acquire().then(() => {
1100
- worker.queued--;
1101
- if (!this.isRunning(worker)) {
1102
- worker.limiter.release();
1103
- held.delete(id);
1104
- return;
1105
- }
1106
- worker.limiter.run(() => this.dispatchEntry(worker, stream, id, rawFields, streamDeliveries).finally(() => held.delete(id)));
1107
- });
1108
- }
1109
- async drainDelayQueues() {
1110
- if (this.stopped || this.knownStreams.size === 0) return;
1111
- const client = this.connection.getClient();
1112
- for (const [stream] of this.knownStreams) {
1113
- const lockKey = delayLockKey(stream, this.connection.keyScope);
1114
- const got = await client.set(lockKey, this.consumerName, "NX", "EX", 30).catch(() => null);
1115
- if (got !== "OK") continue;
1116
- try {
1117
- const due = await client.zrangebyscore(delayQueueKey(stream, this.connection.keyScope), 0, Date.now(), "LIMIT", 0, 50);
1118
- for (const member of due) {
1119
- const split = member.indexOf("|");
1120
- if (split < 0) continue;
1121
- const payload = member.slice(split + 1);
1122
- let fields = {};
1123
- try {
1124
- fields = JSON.parse(payload);
1125
- } catch {
1126
- continue;
1127
- }
1128
- const flat = [];
1129
- for (const [k, v] of Object.entries(fields)) flat.push(k, v);
1130
- await client.xadd(stream, "MAXLEN", "~", 1e5, "*", ...flat);
1131
- await client.zrem(delayQueueKey(stream, this.connection.keyScope), member);
1132
- }
1133
- } finally {
1134
- await client.del(lockKey).catch(() => void 0);
1135
- }
1136
- }
1137
- }
1138
- };
1139
-
1140
- // src/event-queue/implementations/redis-streams/serialize.ts
1141
- function safeStringify(value) {
1142
- return JSON.stringify(value ?? null, (_key, val) => typeof val === "bigint" ? val.toString() : val);
1143
- }
1144
- __name(safeStringify, "safeStringify");
1145
-
1146
- // src/event-queue/implementations/redis-streams/RedisStreamsEventPublisher.ts
1147
- var RedisStreamsEventPublisher = class {
1148
- static {
1149
- __name(this, "RedisStreamsEventPublisher");
1150
- }
1151
- config;
1152
- connection;
1153
- publishCount = 0;
1154
- lastPublishTime = null;
1155
- maxLen;
1156
- dedupTtl;
1157
- keyPrefix;
1158
- shutdownName;
1159
- constructor(config) {
1160
- this.config = config;
1161
- this.connection = new RedisStreamsConnection(config);
1162
- this.maxLen = config.maxLen ?? parseInt(process.env["REDIS_STREAMS_MAXLEN"] ?? "100000", 10);
1163
- this.dedupTtl = config.dedupTtlSeconds ?? parseInt(process.env["REDIS_STREAMS_DEDUP_TTL"] ?? "120", 10);
1164
- this.keyPrefix = config.keyPrefix ?? process.env["REDIS_STREAMS_KEY_PREFIX"] ?? "boff:events";
1165
- this.shutdownName = `redis-streams-publisher:${config.name ?? "default"}`;
1166
- registerDisposable(this);
1167
- }
1168
- /** Close underlying connections on graceful shutdown. */
1169
- dispose() {
1170
- return this.disconnect();
1171
- }
1172
- async connect() {
1173
- await this.connection.connect();
1174
- }
1175
- async disconnect() {
1176
- unregisterDisposable(this);
1177
- await this.connection.disconnect();
1178
- }
1179
- isConnected() {
1180
- return this.connection.isConnected();
1181
- }
1182
- async healthCheck() {
1183
- try {
1184
- const t0 = Date.now();
1185
- const pong = await this.connection.ping();
1186
- return {
1187
- status: pong === "PONG" ? "healthy" : "degraded",
1188
- timestamp: (/* @__PURE__ */ new Date()).toISOString(),
1189
- connected: this.isConnected(),
1190
- latencyMs: Date.now() - t0,
1191
- details: {
1192
- type: "redis-streams",
1193
- url: this.config.url
1194
- }
1195
- };
1196
- } catch (err) {
1197
- return {
1198
- status: "unhealthy",
1199
- timestamp: (/* @__PURE__ */ new Date()).toISOString(),
1200
- connected: false,
1201
- details: {
1202
- type: "redis-streams"
1203
- },
1204
- error: err instanceof Error ? err.message : String(err)
1205
- };
1206
- }
1207
- }
1208
- async getStatistics() {
1209
- return {
1210
- messagesPublished: this.publishCount,
1211
- messagesConsumed: 0,
1212
- messagesFailed: 0,
1213
- activePublishers: 1,
1214
- activeConsumers: 0,
1215
- lastActivity: this.lastPublishTime?.toISOString() ?? null,
1216
- details: {
1217
- type: "redis-streams"
1218
- }
1219
- };
1220
- }
1221
- async ensureStream(_config) {
1222
- return Promise.resolve();
1223
- }
1224
- async publish(options) {
1225
- return this.publishInternal(options);
1226
- }
1227
- async publishInternal(opts) {
1228
- await this.connect();
1229
- const client = this.connection.getClient();
1230
- const streamName = opts.options?.stream ?? opts.subject;
1231
- const stream = streamKey(streamName, {
1232
- prefix: this.keyPrefix,
1233
- scope: this.connection.keyScope
1234
- });
1235
- const msgId = opts.options?.messageId ?? randomUUID();
1236
- const correlationId = opts.metadata?.correlationId ?? randomUUID();
1237
- const enableDedup = this.config.enableDeduplication === true || opts.options?.messageId !== void 0;
1238
- if (enableDedup) {
1239
- const ok = await client.set(dedupKey(stream, msgId, this.connection.keyScope), "1", "NX", "EX", this.dedupTtl);
1240
- if (ok !== "OK") {
1241
- logger.debug("[RedisStreamsEventPublisher] dedup hit; skipping publish", {
1242
- subject: opts.subject,
1243
- msgId
1244
- });
1245
- return msgId;
1246
- }
1247
- }
1248
- const trace = await injectTraceFields();
1249
- const fields = {
1250
- "msg-id": msgId,
1251
- subject: opts.subject,
1252
- "correlation-id": correlationId,
1253
- timestamp: (/* @__PURE__ */ new Date()).toISOString(),
1254
- priority: opts.options?.priority ?? this.config.defaultPriority ?? "normal",
1255
- source: opts.metadata?.source ?? this.config.name ?? "unknown",
1256
- payload: safeStringify(opts.data ?? null),
1257
- metadata: safeStringify(opts.metadata ?? {}),
1258
- ...trace
1259
- };
1260
- if (opts.metadata?.userId) fields["user-id"] = String(opts.metadata.userId);
1261
- if (opts.metadata?.workspaceId) fields["workspace-id"] = String(opts.metadata.workspaceId);
1262
- if (opts.metadata?.tenantId) fields["tenant-id"] = String(opts.metadata.tenantId);
1263
- const flat = [];
1264
- for (const [k, v] of Object.entries(fields)) {
1265
- flat.push(k, v);
1266
- }
1267
- const id = await client.xadd(stream, "MAXLEN", "~", this.maxLen, "*", ...flat);
1268
- void client.sadd(registryKey(boundaryOf(opts.subject), this.connection.keyScope), opts.subject).catch(() => void 0);
1269
- this.publishCount++;
1270
- this.lastPublishTime = /* @__PURE__ */ new Date();
1271
- logger.debug("[RedisStreamsEventPublisher] published", {
1272
- subject: opts.subject,
1273
- stream,
1274
- id
1275
- });
1276
- return id;
1277
- }
1278
- async publishBatch(events) {
1279
- const out = [];
1280
- for (const e of events) {
1281
- out.push(await this.publishInternal(e));
1282
- }
1283
- return out;
1284
- }
1285
- /**
1286
- * Emulated request/response: writer XADDs onto its own subject, then
1287
- * blocks on a one-shot reply stream keyed by correlationId.
1288
- */
1289
- async publishWithAck(opts) {
1290
- await this.connect();
1291
- const client = this.connection.getClient();
1292
- const correlationId = opts.metadata?.correlationId ?? randomUUID();
1293
- const reply = replyKey(correlationId, this.connection.keyScope);
1294
- await this.publishInternal({
1295
- subject: opts.subject,
1296
- data: opts.data,
1297
- metadata: {
1298
- ...opts.metadata,
1299
- correlationId,
1300
- replyTo: reply
1301
- }
1302
- });
1303
- const timeoutMs = opts.timeout ?? 5e3;
1304
- const t0 = Date.now();
1305
- while (Date.now() - t0 < timeoutMs) {
1306
- const entries = await client.xrange(reply, "-", "+");
1307
- if (Array.isArray(entries) && entries.length > 0) {
1308
- const last = entries[entries.length - 1];
1309
- if (!last) break;
1310
- const rawFields = last[1];
1311
- const payloadIdx = rawFields.indexOf("payload");
1312
- const payload = payloadIdx >= 0 ? rawFields[payloadIdx + 1] : "{}";
1313
- await client.del(reply);
1314
- return JSON.parse(payload ?? "{}");
1315
- }
1316
- await new Promise((res) => setTimeout(res, 50));
1317
- }
1318
- await client.del(reply).catch(() => void 0);
1319
- throw new Error(`[RedisStreamsEventPublisher] publishWithAck timed out for subject=${opts.subject}`);
1320
- }
1321
- /** Internal helper used by the consumer's reply path. */
1322
- async sendReply(correlationId, data) {
1323
- await this.connect();
1324
- const client = this.connection.getClient();
1325
- const key = replyKey(correlationId, this.connection.keyScope);
1326
- await client.xadd(key, "*", "payload", safeStringify(data ?? null));
1327
- await client.expire(key, 60);
1328
- }
1329
- };
1330
-
1331
- // src/event-queue/types/config.ts
1332
- var QueueType = /* @__PURE__ */ (function(QueueType2) {
1333
- QueueType2["REDIS_STREAMS"] = "redis-streams";
1334
- QueueType2["RABBITMQ"] = "rabbitmq";
1335
- QueueType2["KAFKA"] = "kafka";
1336
- QueueType2["SQS"] = "sqs";
1337
- return QueueType2;
1338
- })({});
1339
-
1340
- // src/event-queue/factory/EventQueueFactory.ts
1341
- var DEFAULT_STREAMS_URL = "redis://localhost:6379";
1342
- function streamsUrlFromEnv() {
1343
- return resolveEventStreamsUrl() ?? DEFAULT_STREAMS_URL;
1344
- }
1345
- __name(streamsUrlFromEnv, "streamsUrlFromEnv");
1346
- function optionalIntEnv(name) {
1347
- const raw = process.env[name];
1348
- if (raw === void 0 || raw.trim() === "") return void 0;
1349
- return Number(raw.trim());
1350
- }
1351
- __name(optionalIntEnv, "optionalIntEnv");
1352
- function resolveQueueType() {
1353
- return QueueType.REDIS_STREAMS;
1354
- }
1355
- __name(resolveQueueType, "resolveQueueType");
1356
- function redactConnectionUrl(url) {
1357
- if (!url) return url;
1358
- try {
1359
- const parsed = new URL(url);
1360
- const rendered = parsed.toString();
1361
- const authorityStart = rendered.indexOf("//") + 2;
1362
- const authorityEnd = rendered.indexOf("@", authorityStart);
1363
- if (authorityStart < 2 || authorityEnd < 0) return rendered;
1364
- return `${rendered.slice(0, authorityStart)}:***@${rendered.slice(authorityEnd + 1)}`;
1365
- } catch {
1366
- const schemeEnd = url.indexOf("://");
1367
- if (schemeEnd < 0) return url;
1368
- const authorityStart = schemeEnd + 3;
1369
- const authorityEnd = url.indexOf("@", authorityStart);
1370
- if (authorityEnd < 0) return url;
1371
- return `${url.slice(0, authorityStart)}:***@${url.slice(authorityEnd + 1)}`;
1372
- }
1373
- }
1374
- __name(redactConnectionUrl, "redactConnectionUrl");
1375
- var EventQueueFactory = class _EventQueueFactory {
1376
- static {
1377
- __name(this, "EventQueueFactory");
1378
- }
1379
- /**
1380
- * Create an event publisher based on configuration
1381
- */
1382
- static createPublisher(config) {
1383
- logger.info("[EventQueueFactory] Creating event publisher", {
1384
- type: config.type,
1385
- url: redactConnectionUrl(config.url)
1386
- });
1387
- if (config.type === QueueType.REDIS_STREAMS) {
1388
- return new RedisStreamsEventPublisher(config);
1389
- }
1390
- throw new Error(`Unsupported queue type: ${config.type}. NATS was retired on 2026-05-16; use 'redis-streams'.`);
1391
- }
1392
- /**
1393
- * Create an event consumer based on configuration
1394
- */
1395
- static createConsumer(config) {
1396
- logger.info("[EventQueueFactory] Creating event consumer", {
1397
- type: config.type,
1398
- url: redactConnectionUrl(config.url),
1399
- stream: config.stream,
1400
- consumer: config.consumer
1401
- });
1402
- if (config.type === QueueType.REDIS_STREAMS) {
1403
- return new RedisStreamsEventConsumer(config);
1404
- }
1405
- throw new Error(`Unsupported queue type: ${config.type}. NATS was retired on 2026-05-16; use 'redis-streams'.`);
1406
- }
1407
- /**
1408
- * Create a publisher from environment variables.
1409
- * Reads `REDIS_STREAMS_URL` (else `REDIS_URL`), `REDIS_PASSWORD`, and
1410
- * standard queue options.
1411
- */
1412
- static createPublisherFromEnv() {
1413
- return _EventQueueFactory.createPublisher({
1414
- type: QueueType.REDIS_STREAMS,
1415
- url: streamsUrlFromEnv(),
1416
- password: process.env["REDIS_PASSWORD"],
1417
- name: process.env["QUEUE_CLIENT_NAME"] ?? process.env["SERVICE_NAME"] ?? "be-sdk-publisher",
1418
- enableDeduplication: process.env["QUEUE_ENABLE_DEDUPLICATION"] === "true",
1419
- defaultPriority: process.env["QUEUE_DEFAULT_PRIORITY"] ?? "normal"
1420
- });
1421
- }
1422
- /**
1423
- * Create a consumer from environment variables.
1424
- */
1425
- static createConsumerFromEnv(stream, consumer) {
1426
- return _EventQueueFactory.createConsumer({
1427
- type: QueueType.REDIS_STREAMS,
1428
- url: streamsUrlFromEnv(),
1429
- password: process.env["REDIS_PASSWORD"],
1430
- name: process.env["QUEUE_CLIENT_NAME"] ?? process.env["SERVICE_NAME"] ?? consumer,
1431
- stream,
1432
- consumer,
1433
- maxConcurrent: process.env["QUEUE_MAX_CONCURRENT"] ? parseInt(process.env["QUEUE_MAX_CONCURRENT"], 10) : 5,
1434
- concurrency: optionalIntEnv("QUEUE_CONCURRENCY"),
1435
- drainTimeoutMs: optionalIntEnv("QUEUE_DRAIN_TIMEOUT_MS"),
1436
- maxDeliver: process.env["QUEUE_MAX_DELIVER"] ? parseInt(process.env["QUEUE_MAX_DELIVER"], 10) : 3,
1437
- ackWait: process.env["QUEUE_ACK_WAIT"] ? parseInt(process.env["QUEUE_ACK_WAIT"], 10) * 1e9 : 3e10
1438
- });
1439
- }
1440
- // ========================================================================
1441
- // Layer-Aware Factory Methods
1442
- // ========================================================================
1443
- /**
1444
- * Create a publisher for a specific layer.
1445
- * The layer is preserved on the publisher name; otherwise identical to
1446
- * `createPublisherFromEnv()`.
1447
- */
1448
- static createPublisherForLayer(_layer, serviceName) {
1449
- return _EventQueueFactory.createPublisher({
1450
- type: QueueType.REDIS_STREAMS,
1451
- url: streamsUrlFromEnv(),
1452
- password: process.env["REDIS_PASSWORD"],
1453
- name: serviceName,
1454
- enableDeduplication: process.env["QUEUE_ENABLE_DEDUPLICATION"] === "true",
1455
- defaultPriority: process.env["QUEUE_DEFAULT_PRIORITY"] ?? "normal"
1456
- });
1457
- }
1458
- /**
1459
- * Create a consumer for a specific layer.
1460
- */
1461
- static createConsumerForLayer(_layer, serviceName, stream, consumer) {
1462
- return _EventQueueFactory.createConsumer({
1463
- type: QueueType.REDIS_STREAMS,
1464
- url: streamsUrlFromEnv(),
1465
- password: process.env["REDIS_PASSWORD"],
1466
- name: serviceName,
1467
- stream,
1468
- consumer,
1469
- maxConcurrent: process.env["QUEUE_MAX_CONCURRENT"] ? parseInt(process.env["QUEUE_MAX_CONCURRENT"], 10) : 5,
1470
- concurrency: optionalIntEnv("QUEUE_CONCURRENCY"),
1471
- drainTimeoutMs: optionalIntEnv("QUEUE_DRAIN_TIMEOUT_MS"),
1472
- maxDeliver: process.env["QUEUE_MAX_DELIVER"] ? parseInt(process.env["QUEUE_MAX_DELIVER"], 10) : 3,
1473
- ackWait: process.env["QUEUE_ACK_WAIT"] ? parseInt(process.env["QUEUE_ACK_WAIT"], 10) * 1e9 : 3e10
1474
- });
1475
- }
1476
- };
1477
-
1478
- export { DispatchLimiter, EventQueueFactory, QueueType, RedisStreamsEventConsumer, RedisStreamsEventPublisher, resolveConcurrency, resolveDrainTimeout, resolveQueueType, safeStringify };
1479
- //# sourceMappingURL=chunk-HTLEGD3Q.js.map
1480
- //# sourceMappingURL=chunk-HTLEGD3Q.js.map