@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
@@ -1,6 +1,431 @@
1
- export { RESOURCE_CAP_DEFAULTS, ResourceCapExceededError, ResourceCapsModule, __resetResourceCapsForTests, configureResourceCaps, getResourceCaps } from '../chunk-63ZXJ42X.js';
2
- import '../chunk-GCIB76AJ.js';
3
- import '../chunk-RU266375.js';
4
- import '../chunk-XE4OXN2W.js';
5
- //# sourceMappingURL=index.js.map
1
+ import { n as createCounter } from "../metrics-collector-C2eShrlW.js";
2
+ import { a as logger } from "../logger-B6rCpb7D.js";
3
+ import { GraphQLError } from "graphql";
4
+
5
+ // src/resource-caps/index.ts
6
+ /**
7
+ * Resource Caps Module
8
+ *
9
+ * Enforces per-user / per-workspace resource ceilings to prevent unbounded
10
+ * resource use on a multi-tenant SaaS. Caps come from the user's billing plan
11
+ * (resolved via global-billing-svc) and fall back to static defaults defined
12
+ * here when the plan lookup fails or the resource isn't overridden.
13
+ *
14
+ * Two plan tiers exist by default:
15
+ * - free: tight per-user / per-workspace ceilings
16
+ * - paid (default): ~100x looser; individual paid plans can override via the
17
+ * `Plan.resourceCaps` JSON column in global-billing-svc.
18
+ *
19
+ * @example
20
+ * ```ts
21
+ * import { resourceCaps } from '@burdenoff/be-sdk/resource-caps';
22
+ *
23
+ * const { limit } = await resourceCaps.getResourceCap(userId, 'tag');
24
+ * await resourceCaps.enforceResourceCap(userId, 'tag', currentCount);
25
+ * ```
26
+ */
27
+ /**
28
+ * Static fallback caps. Real values may be overridden per plan in
29
+ * global-billing-svc Plan.resourceCaps JSON.
30
+ */
31
+ const RESOURCE_CAP_DEFAULTS = {
32
+ workspace: {
33
+ free: 3,
34
+ paidDefault: 50,
35
+ scope: "user"
36
+ },
37
+ workspaceMember: {
38
+ free: 500,
39
+ paidDefault: 500,
40
+ scope: "workspace"
41
+ },
42
+ sandbox: {
43
+ free: 2,
44
+ paidDefault: 50,
45
+ scope: "user"
46
+ },
47
+ vibe: {
48
+ free: 10,
49
+ paidDefault: 500,
50
+ scope: "user"
51
+ },
52
+ agent: {
53
+ free: 2,
54
+ paidDefault: 20,
55
+ scope: "workspace"
56
+ },
57
+ conversation: {
58
+ free: 20,
59
+ paidDefault: 2e3,
60
+ scope: "user/day"
61
+ },
62
+ message: {
63
+ free: 200,
64
+ paidDefault: 2e4,
65
+ scope: "user/day"
66
+ },
67
+ tag: {
68
+ free: 50,
69
+ paidDefault: 5e3,
70
+ scope: "workspace"
71
+ },
72
+ file: {
73
+ free: 100,
74
+ paidDefault: 1e4,
75
+ scope: "user"
76
+ },
77
+ group: {
78
+ free: 5,
79
+ paidDefault: 500,
80
+ scope: "workspace"
81
+ },
82
+ calendar: {
83
+ free: 3,
84
+ paidDefault: 100,
85
+ scope: "user"
86
+ },
87
+ scheduledTask: {
88
+ free: 5,
89
+ paidDefault: 500,
90
+ scope: "user"
91
+ },
92
+ form: {
93
+ free: 5,
94
+ paidDefault: 500,
95
+ scope: "user"
96
+ },
97
+ apiKey: {
98
+ free: 2,
99
+ paidDefault: 50,
100
+ scope: "user"
101
+ },
102
+ webhook: {
103
+ free: 2,
104
+ paidDefault: 100,
105
+ scope: "workspace"
106
+ }
107
+ };
108
+ /**
109
+ * Thrown when an entity create operation would push the user past the cap.
110
+ * The matching GraphQL error has extensions.code = RESOURCE_CAP_EXCEEDED
111
+ * so clients can detect and route to an upgrade flow.
112
+ */
113
+ var ResourceCapExceededError = class extends GraphQLError {
114
+ constructor(detail) {
115
+ super(`Resource cap exceeded for ${detail.resource}: ${detail.currentCount}/${detail.limit} on plan '${detail.planName}'.`, { extensions: {
116
+ code: "RESOURCE_CAP_EXCEEDED",
117
+ userMessage: "You've reached your plan limit. Upgrade your plan to continue.",
118
+ technicalMessage: `Resource cap exceeded for ${detail.resource}: ${detail.currentCount}/${detail.limit} on plan '${detail.planName}'.`,
119
+ resource: detail.resource,
120
+ currentCount: detail.currentCount,
121
+ limit: detail.limit,
122
+ planName: detail.planName
123
+ } });
124
+ this.name = "ResourceCapExceededError";
125
+ }
126
+ };
127
+ const PLAN_QUERY = `
128
+ query GetUserPlanForCaps($userId: ID!) {
129
+ userBillingPlan(userId: $userId) {
130
+ planName
131
+ tier
132
+ resourceCaps
133
+ }
134
+ }
135
+ `;
136
+ var ResourceCapsModule = class {
137
+ client;
138
+ transport;
139
+ cacheTtlMs;
140
+ clientlessTier;
141
+ billingFailureTier;
142
+ onFallback;
143
+ onBillingFailure;
144
+ warnedClientless = false;
145
+ planCache = /* @__PURE__ */ new Map();
146
+ planResolutionCounter;
147
+ enforcementCounter;
148
+ constructor(config = {}) {
149
+ this.client = config.client;
150
+ this.transport = config.transport;
151
+ this.cacheTtlMs = config.cacheTtlMs ?? 6e4;
152
+ this.clientlessTier = config.clientlessTier ?? "free";
153
+ this.billingFailureTier = config.billingFailureTier ?? "paid";
154
+ this.onFallback = config.onFallback;
155
+ this.onBillingFailure = config.onBillingFailure;
156
+ this.planResolutionCounter = createCounter("resource_caps.plan_resolution_total", "Total number of billing plan resolutions for resource caps");
157
+ this.enforcementCounter = createCounter("resource_caps.enforcement_total", "Total number of resource cap enforcement checks");
158
+ }
159
+ /**
160
+ * (Re)bind runtime dependencies on an already-constructed module. The SDK
161
+ * bootstrap uses this to prime the process-wide singleton with a billing
162
+ * transport even if an early caller already lazily created it clientless
163
+ * (a bare `getResourceCaps(config)` ignores config once the instance exists).
164
+ * Clears the plan cache so stale fallback entries don't linger.
165
+ */
166
+ configure(config) {
167
+ if (config.client !== void 0) this.client = config.client;
168
+ if (config.transport !== void 0) this.transport = config.transport;
169
+ if (config.onFallback !== void 0) this.onFallback = config.onFallback;
170
+ if (config.onBillingFailure !== void 0) this.onBillingFailure = config.onBillingFailure;
171
+ if (typeof config.cacheTtlMs === "number") this.cacheTtlMs = config.cacheTtlMs;
172
+ if (config.clientlessTier) this.clientlessTier = config.clientlessTier;
173
+ if (config.billingFailureTier) this.billingFailureTier = config.billingFailureTier;
174
+ if (this.hasBillingSource()) this.warnedClientless = false;
175
+ this.planCache.clear();
176
+ }
177
+ /** True when the module can actually reach billing (has a transport or client). */
178
+ hasBillingSource() {
179
+ return Boolean(this.transport || this.client);
180
+ }
181
+ /**
182
+ * Resolve the cap for a given resource for the supplied user.
183
+ * Order: plan-override → plan-tier-default → static free default.
184
+ */
185
+ async getResourceCap(userId, resource) {
186
+ if (!userId) throw new Error("getResourceCap: userId is required");
187
+ const defaults = RESOURCE_CAP_DEFAULTS[resource];
188
+ if (!defaults) throw new Error(`getResourceCap: unknown resource '${resource}'`);
189
+ const plan = await this.resolvePlan(userId);
190
+ const override = plan.overrides[resource];
191
+ if (typeof override === "number" && override >= 0) return {
192
+ resource,
193
+ limit: override,
194
+ planName: plan.planName,
195
+ planTier: plan.planTier,
196
+ isFallback: plan.isFallback,
197
+ fallbackReason: plan.fallbackReason
198
+ };
199
+ return {
200
+ resource,
201
+ limit: plan.planTier === "paid" ? defaults.paidDefault : defaults.free,
202
+ planName: plan.planName,
203
+ planTier: plan.planTier,
204
+ isFallback: plan.isFallback,
205
+ fallbackReason: plan.fallbackReason
206
+ };
207
+ }
208
+ /**
209
+ * Throws ResourceCapExceededError when currentCount >= limit.
210
+ * Use BEFORE the create transaction to avoid orphan rows.
211
+ */
212
+ async enforceResourceCap(userId, resource, currentCount) {
213
+ const cap = await this.getResourceCap(userId, resource);
214
+ if (currentCount >= cap.limit) {
215
+ this.enforcementCounter.inc({
216
+ resource,
217
+ plan_tier: cap.planTier,
218
+ result: "denied"
219
+ });
220
+ throw new ResourceCapExceededError({
221
+ resource,
222
+ currentCount,
223
+ limit: cap.limit,
224
+ planName: cap.planName
225
+ });
226
+ }
227
+ this.enforcementCounter.inc({
228
+ resource,
229
+ plan_tier: cap.planTier,
230
+ result: "allowed"
231
+ });
232
+ return cap;
233
+ }
234
+ /**
235
+ * Resolve a workspace-scoped resource cap from the workspace's owner
236
+ * organization plan, regardless of which actor triggered the action.
237
+ *
238
+ * @example
239
+ * ```ts
240
+ * const { limit } = await caps.getWorkspaceResourceCap(
241
+ * { workspaceId: 'ws-1', organizationId: 'org-1' },
242
+ * 'group'
243
+ * );
244
+ * ```
245
+ */
246
+ async getWorkspaceResourceCap(scope, resource) {
247
+ const { workspaceId, organizationId } = scope;
248
+ if (!workspaceId) throw new Error("getWorkspaceResourceCap: workspaceId is required");
249
+ if (!organizationId) throw new Error("getWorkspaceResourceCap: organizationId is required");
250
+ const defaults = RESOURCE_CAP_DEFAULTS[resource];
251
+ if (!defaults) throw new Error(`getWorkspaceResourceCap: unknown resource '${resource}'`);
252
+ const plan = await this.resolvePlan(organizationId, this.workspaceCacheKey(workspaceId));
253
+ const override = plan.overrides[resource];
254
+ if (typeof override === "number" && override >= 0) return {
255
+ resource,
256
+ limit: override,
257
+ planName: plan.planName,
258
+ planTier: plan.planTier,
259
+ isFallback: plan.isFallback,
260
+ fallbackReason: plan.fallbackReason
261
+ };
262
+ return {
263
+ resource,
264
+ limit: plan.planTier === "paid" ? defaults.paidDefault : defaults.free,
265
+ planName: plan.planName,
266
+ planTier: plan.planTier,
267
+ isFallback: plan.isFallback,
268
+ fallbackReason: plan.fallbackReason
269
+ };
270
+ }
271
+ /**
272
+ * Throws ResourceCapExceededError when currentCount >= limit for a
273
+ * workspace-scoped resource. The cap is resolved from the workspace owner's
274
+ * organization plan, so the answer is stable across members.
275
+ */
276
+ async enforceWorkspaceResourceCap(scope, resource, currentCount) {
277
+ const cap = await this.getWorkspaceResourceCap(scope, resource);
278
+ if (currentCount >= cap.limit) {
279
+ this.enforcementCounter.inc({
280
+ resource,
281
+ plan_tier: cap.planTier,
282
+ result: "denied"
283
+ });
284
+ throw new ResourceCapExceededError({
285
+ resource,
286
+ currentCount,
287
+ limit: cap.limit,
288
+ planName: cap.planName
289
+ });
290
+ }
291
+ this.enforcementCounter.inc({
292
+ resource,
293
+ plan_tier: cap.planTier,
294
+ result: "allowed"
295
+ });
296
+ return cap;
297
+ }
298
+ /** Invalidate cache for a user (e.g. after plan upgrade) */
299
+ invalidate(userId) {
300
+ this.planCache.delete(userId);
301
+ }
302
+ /** Invalidate cache for a workspace (e.g. after workspace plan change) */
303
+ invalidateWorkspace(workspaceId) {
304
+ this.planCache.delete(this.workspaceCacheKey(workspaceId));
305
+ }
306
+ /** Clear entire plan cache */
307
+ invalidateAll() {
308
+ this.planCache.clear();
309
+ }
310
+ workspaceCacheKey(workspaceId) {
311
+ return `workspace:${workspaceId}`;
312
+ }
313
+ async resolvePlan(userId, cacheKey) {
314
+ const key = cacheKey ?? userId;
315
+ const cached = this.planCache.get(key);
316
+ if (cached && Date.now() - cached.fetchedAt < this.cacheTtlMs) return cached;
317
+ const plan = await this.fetchPlan(userId);
318
+ this.planCache.set(key, plan);
319
+ return plan;
320
+ }
321
+ async fetchPlan(userId) {
322
+ if (!this.hasBillingSource()) {
323
+ this.warnClientlessOnce();
324
+ this.planResolutionCounter.inc({
325
+ result: "fallback",
326
+ reason: "clientless"
327
+ });
328
+ return this.fallbackPlan(this.clientlessTier, "clientless");
329
+ }
330
+ try {
331
+ const planNode = await this.fetchPlanNode(userId);
332
+ if (!planNode) {
333
+ logger.warn("resource-caps: plan lookup returned null; falling back to paid defaults", { userId });
334
+ this.onBillingFailure?.();
335
+ this.planResolutionCounter.inc({
336
+ result: "fallback",
337
+ reason: "billing_error"
338
+ });
339
+ return this.fallbackPlan(this.billingFailureTier, "billing_error");
340
+ }
341
+ const tier = normaliseTier(planNode.tier, this.billingFailureTier);
342
+ const overrides = sanitizeOverrides(planNode.resourceCaps);
343
+ this.planResolutionCounter.inc({ result: "billing" });
344
+ return {
345
+ planName: planNode.planName ?? (tier === "paid" ? "paid" : "free"),
346
+ planTier: tier,
347
+ overrides,
348
+ fetchedAt: Date.now(),
349
+ isFallback: false
350
+ };
351
+ } catch (err) {
352
+ logger.warn("resource-caps: plan lookup failed; falling back to paid defaults", {
353
+ err,
354
+ userId
355
+ });
356
+ this.onBillingFailure?.();
357
+ this.planResolutionCounter.inc({
358
+ result: "fallback",
359
+ reason: "billing_error"
360
+ });
361
+ return this.fallbackPlan(this.billingFailureTier, "billing_error");
362
+ }
363
+ }
364
+ /**
365
+ * Resolve the raw `userBillingPlan` node via the injected transport (preferred)
366
+ * or the legacy direct client. Guarded by {@link hasBillingSource} in the
367
+ * caller, so at least one path is present here.
368
+ */
369
+ async fetchPlanNode(userId) {
370
+ if (this.transport) return (await this.transport(PLAN_QUERY, { userId }))?.userBillingPlan ?? null;
371
+ if (this.client) return (await this.client.query(PLAN_QUERY, { userId }))?.userBillingPlan ?? null;
372
+ return null;
373
+ }
374
+ warnClientlessOnce() {
375
+ if (this.warnedClientless) return;
376
+ this.warnedClientless = true;
377
+ logger.warn("resource-caps: running WITHOUT a billing transport/client — every resource cap will use the free-tier fallback regardless of the customer plan. Ensure initializeBurdenoffSDK() ran with a layer/gateway configured (BOFF-4805).");
378
+ this.onFallback?.();
379
+ }
380
+ fallbackPlan(tier, reason) {
381
+ return {
382
+ planName: tier === "paid" ? "fallback-paid" : "fallback-free",
383
+ planTier: tier,
384
+ overrides: {},
385
+ fetchedAt: Date.now(),
386
+ isFallback: true,
387
+ fallbackReason: reason
388
+ };
389
+ }
390
+ };
391
+ function normaliseTier(raw, fallback) {
392
+ if (!raw) return fallback;
393
+ const lc = raw.toLowerCase();
394
+ if (lc === "free" || lc === "paid") return lc;
395
+ if (lc === "enterprise" || lc === "business" || lc === "pro" || lc === "team") return "paid";
396
+ return fallback;
397
+ }
398
+ function sanitizeOverrides(raw) {
399
+ if (!raw || typeof raw !== "object") return {};
400
+ const out = {};
401
+ for (const [key, value] of Object.entries(raw)) if (key in RESOURCE_CAP_DEFAULTS && typeof value === "number" && Number.isFinite(value)) out[key] = Math.max(0, Math.floor(value));
402
+ return out;
403
+ }
404
+ let defaultInstance = null;
405
+ /**
406
+ * Obtain a process-wide singleton. The first call binds the GraphQL client
407
+ * (typically the SDK's internal client). Later calls return the same instance.
408
+ */
409
+ function getResourceCaps(config) {
410
+ if (!defaultInstance) defaultInstance = new ResourceCapsModule(config);
411
+ else if (config) defaultInstance.configure(config);
412
+ return defaultInstance;
413
+ }
414
+ /**
415
+ * Prime/rebind the process-wide singleton with billing connectivity. Call once
416
+ * during SDK bootstrap. Unlike a bare `getResourceCaps(config)` on a fresh
417
+ * process, this is explicit about the intent to (re)wire and is safe to call
418
+ * after the singleton was already lazily created clientless.
419
+ */
420
+ function configureResourceCaps(config) {
421
+ const instance = getResourceCaps();
422
+ instance.configure(config);
423
+ return instance;
424
+ }
425
+ /** Reset the singleton (for tests) */
426
+ function __resetResourceCapsForTests() {
427
+ defaultInstance = null;
428
+ }
429
+
430
+ export { RESOURCE_CAP_DEFAULTS, ResourceCapExceededError, ResourceCapsModule, __resetResourceCapsForTests, configureResourceCaps, getResourceCaps };
6
431
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":[],"names":[],"mappings":"","file":"index.js"}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../../src/resource-caps/index.ts"],"sourcesContent":["/**\n * Resource Caps Module\n *\n * Enforces per-user / per-workspace resource ceilings to prevent unbounded\n * resource use on a multi-tenant SaaS. Caps come from the user's billing plan\n * (resolved via global-billing-svc) and fall back to static defaults defined\n * here when the plan lookup fails or the resource isn't overridden.\n *\n * Two plan tiers exist by default:\n * - free: tight per-user / per-workspace ceilings\n * - paid (default): ~100x looser; individual paid plans can override via the\n * `Plan.resourceCaps` JSON column in global-billing-svc.\n *\n * @example\n * ```ts\n * import { resourceCaps } from '@burdenoff/be-sdk/resource-caps';\n *\n * const { limit } = await resourceCaps.getResourceCap(userId, 'tag');\n * await resourceCaps.enforceResourceCap(userId, 'tag', currentCount);\n * ```\n */\n\nimport { GraphQLError } from 'graphql';\n\nimport type { BurdenoffGraphQLClient } from '../client/graphql.js';\nimport { createCounter } from '../instrumentation/metrics-collector.js';\nimport { logger } from '../logger/index.js';\n\n// ---------------------------------------------------------------------------\n// Resource registry\n// ---------------------------------------------------------------------------\n\n/**\n * Canonical resource names. Adding a new capped resource? Append it here,\n * extend RESOURCE_CAP_DEFAULTS, and reference it from the relevant svc.\n */\nexport type ResourceName =\n | 'workspace' // per user\n | 'workspaceMember' // per workspace\n | 'sandbox' // per user\n | 'vibe' // per user\n | 'agent' // per workspace\n | 'conversation' // per user/day\n | 'message' // per user/day\n | 'tag' // per workspace\n | 'file' // per user (count only)\n | 'group' // per workspace\n | 'calendar' // per user\n | 'scheduledTask' // per user\n | 'form' // per user\n | 'apiKey' // per user\n | 'webhook'; // per workspace\n\nexport type PlanTier = 'free' | 'paid';\n\nexport interface ResourceCapDefaults {\n free: number;\n paidDefault: number;\n /** Optional scope hint used by callers when wiring guards */\n scope: 'user' | 'workspace' | 'user/day';\n}\n\n/**\n * Static fallback caps. Real values may be overridden per plan in\n * global-billing-svc Plan.resourceCaps JSON.\n */\nexport const RESOURCE_CAP_DEFAULTS: Record<ResourceName, ResourceCapDefaults> = {\n workspace: { free: 3, paidDefault: 50, scope: 'user' },\n workspaceMember: { free: 500, paidDefault: 500, scope: 'workspace' },\n sandbox: { free: 2, paidDefault: 50, scope: 'user' },\n vibe: { free: 10, paidDefault: 500, scope: 'user' },\n agent: { free: 2, paidDefault: 20, scope: 'workspace' },\n conversation: { free: 20, paidDefault: 2000, scope: 'user/day' },\n message: { free: 200, paidDefault: 20000, scope: 'user/day' },\n tag: { free: 50, paidDefault: 5000, scope: 'workspace' },\n file: { free: 100, paidDefault: 10000, scope: 'user' },\n group: { free: 5, paidDefault: 500, scope: 'workspace' },\n calendar: { free: 3, paidDefault: 100, scope: 'user' },\n scheduledTask: { free: 5, paidDefault: 500, scope: 'user' },\n form: { free: 5, paidDefault: 500, scope: 'user' },\n apiKey: { free: 2, paidDefault: 50, scope: 'user' },\n webhook: { free: 2, paidDefault: 100, scope: 'workspace' },\n};\n\n// ---------------------------------------------------------------------------\n// Types & errors\n// ---------------------------------------------------------------------------\n\nexport interface ResourceCap {\n resource: ResourceName;\n limit: number;\n planName: string;\n planTier: PlanTier;\n /** True when the cap came from defaults, not from the billing service */\n isFallback: boolean;\n /** Why the fallback was used, when isFallback is true */\n fallbackReason?: 'clientless' | 'billing_error';\n}\n\n/**\n * Scope for workspace-scoped resource caps. The cap is derived from the plan of\n * the workspace's owning organization, not from whichever actor happens to be\n * making the request, so two members of the same workspace always see the same\n * limit (BOFF-4808).\n */\nexport interface WorkspaceResourceCapScope {\n /** Stable workspace identifier; used as the cache key. */\n workspaceId: string;\n /**\n * Organization that owns the workspace and whose billing plan determines the\n * cap. This is the `organizationId` from global-tenant-svc's Workspace type\n * (or `orgId` from wspace-workspace-svc's Workspace type).\n */\n organizationId: string;\n}\n\n/**\n * Layer-aware transport for the `userBillingPlan` lookup. Given the GraphQL\n * document + variables, returns the response `data` object (or null). Preferred\n * over `client`: the SDK bootstrap wires this to a same-layer (global) or\n * cross-layer (wspace→global) gateway call so billing is reachable from every\n * service without any per-call-site wiring (BOFF-4805).\n */\nexport type BillingPlanTransport = (query: string, variables: Record<string, unknown>) => Promise<unknown>;\n\nexport interface ResourceCapsConfig {\n client?: BurdenoffGraphQLClient;\n /** Preferred billing lookup path; see {@link BillingPlanTransport}. */\n transport?: BillingPlanTransport;\n /** Optional in-memory TTL for plan lookups; defaults to 60s */\n cacheTtlMs?: number;\n /**\n * Plan tier used when the module has no billing source (clientless). This is\n * the misconfiguration path: services should always bootstrap with a billing\n * transport. Defaults to `free` so a clientless service is visibly broken in\n * tests, while still not hard-blocking local unit tests.\n */\n clientlessTier?: PlanTier;\n /**\n * Plan tier used when a billing source is configured but the lookup fails\n * (network error, billing service down, etc.). Defaults to `paid` so a\n * transient billing outage does not silently downgrade paid customers to the\n * tightest free-tier caps (fail-open with alerting; BOFF-4805/4809).\n */\n billingFailureTier?: PlanTier;\n /**\n * Telemetry hook invoked when the module cannot reach billing (no transport /\n * client) and collapses to the clientless fallback. Wired to a metric counter\n * by observability so an unwired/broken integration is visible (BOFF-4809).\n */\n onFallback?: () => void;\n /**\n * Telemetry hook invoked when a billing source is configured but the lookup\n * fails (billing error fallback to the paid default).\n */\n onBillingFailure?: () => void;\n}\n\ninterface CachedPlan {\n planName: string;\n planTier: PlanTier;\n overrides: Partial<Record<ResourceName, number>>;\n fetchedAt: number;\n isFallback: boolean;\n fallbackReason?: 'clientless' | 'billing_error';\n}\n\n/**\n * Thrown when an entity create operation would push the user past the cap.\n * The matching GraphQL error has extensions.code = RESOURCE_CAP_EXCEEDED\n * so clients can detect and route to an upgrade flow.\n */\nexport class ResourceCapExceededError extends GraphQLError {\n constructor(detail: { resource: ResourceName; currentCount: number; limit: number; planName: string }) {\n super(\n `Resource cap exceeded for ${detail.resource}: ${detail.currentCount}/${detail.limit} on plan '${detail.planName}'.`,\n {\n extensions: {\n code: 'RESOURCE_CAP_EXCEEDED',\n userMessage: \"You've reached your plan limit. Upgrade your plan to continue.\",\n technicalMessage: `Resource cap exceeded for ${detail.resource}: ${detail.currentCount}/${detail.limit} on plan '${detail.planName}'.`,\n resource: detail.resource,\n currentCount: detail.currentCount,\n limit: detail.limit,\n planName: detail.planName,\n },\n }\n );\n this.name = 'ResourceCapExceededError';\n }\n}\n\n// ---------------------------------------------------------------------------\n// Module\n// ---------------------------------------------------------------------------\n\nconst PLAN_QUERY = /* GraphQL */ `\n query GetUserPlanForCaps($userId: ID!) {\n userBillingPlan(userId: $userId) {\n planName\n tier\n resourceCaps\n }\n }\n`;\n\ninterface PlanQueryResponse {\n userBillingPlan?: {\n planName?: string | null;\n tier?: string | null;\n resourceCaps?: Record<string, number> | null;\n } | null;\n}\n\ntype PlanNode = NonNullable<PlanQueryResponse['userBillingPlan']>;\n\nexport class ResourceCapsModule {\n private client?: BurdenoffGraphQLClient;\n private transport?: BillingPlanTransport;\n private cacheTtlMs: number;\n private clientlessTier: PlanTier;\n private billingFailureTier: PlanTier;\n private onFallback?: () => void;\n private onBillingFailure?: () => void;\n private warnedClientless = false;\n private readonly planCache = new Map<string, CachedPlan>();\n private readonly planResolutionCounter;\n private readonly enforcementCounter;\n\n constructor(config: ResourceCapsConfig = {}) {\n this.client = config.client;\n this.transport = config.transport;\n this.cacheTtlMs = config.cacheTtlMs ?? 60_000;\n this.clientlessTier = config.clientlessTier ?? 'free';\n this.billingFailureTier = config.billingFailureTier ?? 'paid';\n this.onFallback = config.onFallback;\n this.onBillingFailure = config.onBillingFailure;\n this.planResolutionCounter = createCounter(\n 'resource_caps.plan_resolution_total',\n 'Total number of billing plan resolutions for resource caps'\n );\n this.enforcementCounter = createCounter(\n 'resource_caps.enforcement_total',\n 'Total number of resource cap enforcement checks'\n );\n }\n\n /**\n * (Re)bind runtime dependencies on an already-constructed module. The SDK\n * bootstrap uses this to prime the process-wide singleton with a billing\n * transport even if an early caller already lazily created it clientless\n * (a bare `getResourceCaps(config)` ignores config once the instance exists).\n * Clears the plan cache so stale fallback entries don't linger.\n */\n configure(config: ResourceCapsConfig): void {\n if (config.client !== undefined) this.client = config.client;\n if (config.transport !== undefined) this.transport = config.transport;\n if (config.onFallback !== undefined) this.onFallback = config.onFallback;\n if (config.onBillingFailure !== undefined) this.onBillingFailure = config.onBillingFailure;\n if (typeof config.cacheTtlMs === 'number') this.cacheTtlMs = config.cacheTtlMs;\n if (config.clientlessTier) this.clientlessTier = config.clientlessTier;\n if (config.billingFailureTier) this.billingFailureTier = config.billingFailureTier;\n if (this.hasBillingSource()) this.warnedClientless = false;\n this.planCache.clear();\n }\n\n /** True when the module can actually reach billing (has a transport or client). */\n hasBillingSource(): boolean {\n return Boolean(this.transport || this.client);\n }\n\n /**\n * Resolve the cap for a given resource for the supplied user.\n * Order: plan-override → plan-tier-default → static free default.\n */\n async getResourceCap(userId: string, resource: ResourceName): Promise<ResourceCap> {\n if (!userId) {\n throw new Error('getResourceCap: userId is required');\n }\n const defaults = RESOURCE_CAP_DEFAULTS[resource];\n if (!defaults) {\n throw new Error(`getResourceCap: unknown resource '${resource}'`);\n }\n\n const plan = await this.resolvePlan(userId);\n const override = plan.overrides[resource];\n if (typeof override === 'number' && override >= 0) {\n return {\n resource,\n limit: override,\n planName: plan.planName,\n planTier: plan.planTier,\n isFallback: plan.isFallback,\n fallbackReason: plan.fallbackReason,\n };\n }\n\n const limit = plan.planTier === 'paid' ? defaults.paidDefault : defaults.free;\n return {\n resource,\n limit,\n planName: plan.planName,\n planTier: plan.planTier,\n isFallback: plan.isFallback,\n fallbackReason: plan.fallbackReason,\n };\n }\n\n /**\n * Throws ResourceCapExceededError when currentCount >= limit.\n * Use BEFORE the create transaction to avoid orphan rows.\n */\n async enforceResourceCap(userId: string, resource: ResourceName, currentCount: number): Promise<ResourceCap> {\n const cap = await this.getResourceCap(userId, resource);\n if (currentCount >= cap.limit) {\n this.enforcementCounter.inc({\n resource,\n plan_tier: cap.planTier,\n result: 'denied',\n });\n throw new ResourceCapExceededError({\n resource,\n currentCount,\n limit: cap.limit,\n planName: cap.planName,\n });\n }\n this.enforcementCounter.inc({\n resource,\n plan_tier: cap.planTier,\n result: 'allowed',\n });\n return cap;\n }\n\n /**\n * Resolve a workspace-scoped resource cap from the workspace's owner\n * organization plan, regardless of which actor triggered the action.\n *\n * @example\n * ```ts\n * const { limit } = await caps.getWorkspaceResourceCap(\n * { workspaceId: 'ws-1', organizationId: 'org-1' },\n * 'group'\n * );\n * ```\n */\n async getWorkspaceResourceCap(scope: WorkspaceResourceCapScope, resource: ResourceName): Promise<ResourceCap> {\n const { workspaceId, organizationId } = scope;\n if (!workspaceId) {\n throw new Error('getWorkspaceResourceCap: workspaceId is required');\n }\n if (!organizationId) {\n throw new Error('getWorkspaceResourceCap: organizationId is required');\n }\n const defaults = RESOURCE_CAP_DEFAULTS[resource];\n if (!defaults) {\n throw new Error(`getWorkspaceResourceCap: unknown resource '${resource}'`);\n }\n\n const plan = await this.resolvePlan(organizationId, this.workspaceCacheKey(workspaceId));\n const override = plan.overrides[resource];\n if (typeof override === 'number' && override >= 0) {\n return {\n resource,\n limit: override,\n planName: plan.planName,\n planTier: plan.planTier,\n isFallback: plan.isFallback,\n fallbackReason: plan.fallbackReason,\n };\n }\n\n const limit = plan.planTier === 'paid' ? defaults.paidDefault : defaults.free;\n return {\n resource,\n limit,\n planName: plan.planName,\n planTier: plan.planTier,\n isFallback: plan.isFallback,\n fallbackReason: plan.fallbackReason,\n };\n }\n\n /**\n * Throws ResourceCapExceededError when currentCount >= limit for a\n * workspace-scoped resource. The cap is resolved from the workspace owner's\n * organization plan, so the answer is stable across members.\n */\n async enforceWorkspaceResourceCap(\n scope: WorkspaceResourceCapScope,\n resource: ResourceName,\n currentCount: number\n ): Promise<ResourceCap> {\n const cap = await this.getWorkspaceResourceCap(scope, resource);\n if (currentCount >= cap.limit) {\n this.enforcementCounter.inc({\n resource,\n plan_tier: cap.planTier,\n result: 'denied',\n });\n throw new ResourceCapExceededError({\n resource,\n currentCount,\n limit: cap.limit,\n planName: cap.planName,\n });\n }\n this.enforcementCounter.inc({\n resource,\n plan_tier: cap.planTier,\n result: 'allowed',\n });\n return cap;\n }\n\n /** Invalidate cache for a user (e.g. after plan upgrade) */\n invalidate(userId: string): void {\n this.planCache.delete(userId);\n }\n\n /** Invalidate cache for a workspace (e.g. after workspace plan change) */\n invalidateWorkspace(workspaceId: string): void {\n this.planCache.delete(this.workspaceCacheKey(workspaceId));\n }\n\n /** Clear entire plan cache */\n invalidateAll(): void {\n this.planCache.clear();\n }\n\n // -------------------------------------------------------------------------\n // Internals\n // -------------------------------------------------------------------------\n\n private workspaceCacheKey(workspaceId: string): string {\n return `workspace:${workspaceId}`;\n }\n\n private async resolvePlan(userId: string, cacheKey?: string): Promise<CachedPlan> {\n const key = cacheKey ?? userId;\n const cached = this.planCache.get(key);\n if (cached && Date.now() - cached.fetchedAt < this.cacheTtlMs) {\n return cached;\n }\n\n const plan = await this.fetchPlan(userId);\n this.planCache.set(key, plan);\n return plan;\n }\n\n private async fetchPlan(userId: string): Promise<CachedPlan> {\n // No billing source wired → every cap silently collapses to the configured\n // clientless tier. Warn loudly (once) so an unwired/broken integration\n // can't hide in prod (BOFF-4805/4809).\n if (!this.hasBillingSource()) {\n this.warnClientlessOnce();\n this.planResolutionCounter.inc({ result: 'fallback', reason: 'clientless' });\n return this.fallbackPlan(this.clientlessTier, 'clientless');\n }\n try {\n const planNode = await this.fetchPlanNode(userId);\n if (!planNode) {\n logger.warn('resource-caps: plan lookup returned null; falling back to paid defaults', {\n userId,\n });\n this.onBillingFailure?.();\n this.planResolutionCounter.inc({ result: 'fallback', reason: 'billing_error' });\n return this.fallbackPlan(this.billingFailureTier, 'billing_error');\n }\n const tier = normaliseTier(planNode.tier, this.billingFailureTier);\n const overrides = sanitizeOverrides(planNode.resourceCaps);\n this.planResolutionCounter.inc({ result: 'billing' });\n return {\n planName: planNode.planName ?? (tier === 'paid' ? 'paid' : 'free'),\n planTier: tier,\n overrides,\n fetchedAt: Date.now(),\n isFallback: false,\n };\n } catch (err) {\n logger.warn('resource-caps: plan lookup failed; falling back to paid defaults', {\n err,\n userId,\n });\n this.onBillingFailure?.();\n this.planResolutionCounter.inc({ result: 'fallback', reason: 'billing_error' });\n return this.fallbackPlan(this.billingFailureTier, 'billing_error');\n }\n }\n\n /**\n * Resolve the raw `userBillingPlan` node via the injected transport (preferred)\n * or the legacy direct client. Guarded by {@link hasBillingSource} in the\n * caller, so at least one path is present here.\n */\n private async fetchPlanNode(userId: string): Promise<PlanNode | null> {\n if (this.transport) {\n const data = (await this.transport(PLAN_QUERY, { userId })) as PlanQueryResponse | null | undefined;\n return data?.userBillingPlan ?? null;\n }\n if (this.client) {\n const res = await this.client.query<PlanQueryResponse>(PLAN_QUERY, { userId });\n return res?.userBillingPlan ?? null;\n }\n return null;\n }\n\n private warnClientlessOnce(): void {\n if (this.warnedClientless) return;\n this.warnedClientless = true;\n logger.warn(\n 'resource-caps: running WITHOUT a billing transport/client — every resource cap will use the ' +\n 'free-tier fallback regardless of the customer plan. Ensure initializeBurdenoffSDK() ran with a ' +\n 'layer/gateway configured (BOFF-4805).'\n );\n this.onFallback?.();\n }\n\n private fallbackPlan(tier: PlanTier, reason: 'clientless' | 'billing_error'): CachedPlan {\n return {\n planName: tier === 'paid' ? 'fallback-paid' : 'fallback-free',\n planTier: tier,\n overrides: {},\n fetchedAt: Date.now(),\n isFallback: true,\n fallbackReason: reason,\n };\n }\n}\n\n// ---------------------------------------------------------------------------\n// Helpers\n// ---------------------------------------------------------------------------\n\nfunction normaliseTier(raw: string | null | undefined, fallback: PlanTier): PlanTier {\n if (!raw) return fallback;\n const lc = raw.toLowerCase();\n if (lc === 'free' || lc === 'paid') return lc;\n // Treat anything non-free as paid (enterprise, business, pro, etc.)\n if (lc === 'enterprise' || lc === 'business' || lc === 'pro' || lc === 'team') {\n return 'paid';\n }\n return fallback;\n}\n\nfunction sanitizeOverrides(raw: Record<string, number> | null | undefined): Partial<Record<ResourceName, number>> {\n if (!raw || typeof raw !== 'object') return {};\n const out: Partial<Record<ResourceName, number>> = {};\n for (const [key, value] of Object.entries(raw)) {\n if (key in RESOURCE_CAP_DEFAULTS && typeof value === 'number' && Number.isFinite(value)) {\n out[key as ResourceName] = Math.max(0, Math.floor(value));\n }\n }\n return out;\n}\n\n// ---------------------------------------------------------------------------\n// Convenience singleton\n// ---------------------------------------------------------------------------\n\nlet defaultInstance: ResourceCapsModule | null = null;\n\n/**\n * Obtain a process-wide singleton. The first call binds the GraphQL client\n * (typically the SDK's internal client). Later calls return the same instance.\n */\nexport function getResourceCaps(config?: ResourceCapsConfig): ResourceCapsModule {\n if (!defaultInstance) {\n defaultInstance = new ResourceCapsModule(config);\n } else if (config) {\n // Previously the config was silently dropped once the singleton existed —\n // the root cause of BOFF-4805 where the billing client could never be bound\n // after a lazy first construction. Apply it instead.\n defaultInstance.configure(config);\n }\n return defaultInstance;\n}\n\n/**\n * Prime/rebind the process-wide singleton with billing connectivity. Call once\n * during SDK bootstrap. Unlike a bare `getResourceCaps(config)` on a fresh\n * process, this is explicit about the intent to (re)wire and is safe to call\n * after the singleton was already lazily created clientless.\n */\nexport function configureResourceCaps(config: ResourceCapsConfig): ResourceCapsModule {\n const instance = getResourceCaps();\n instance.configure(config);\n return instance;\n}\n\n/** Reset the singleton (for tests) */\nexport function __resetResourceCapsForTests(): void {\n defaultInstance = null;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkEA,MAAa,wBAAmE;CAC9E,WAAW;EAAE,MAAM;EAAG,aAAa;EAAI,OAAO;CAAO;CACrD,iBAAiB;EAAE,MAAM;EAAK,aAAa;EAAK,OAAO;CAAY;CACnE,SAAS;EAAE,MAAM;EAAG,aAAa;EAAI,OAAO;CAAO;CACnD,MAAM;EAAE,MAAM;EAAI,aAAa;EAAK,OAAO;CAAO;CAClD,OAAO;EAAE,MAAM;EAAG,aAAa;EAAI,OAAO;CAAY;CACtD,cAAc;EAAE,MAAM;EAAI,aAAa;EAAM,OAAO;CAAW;CAC/D,SAAS;EAAE,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6C,CAAC;CACpD,KAAK,MAAM,CAAC,KAAK,UAAU,OAAO,QAAQ,GAAG,GAC3C,IAAI,OAAO,yBAAyB,OAAO,UAAU,YAAY,OAAO,SAAS,KAAK,GACpF,IAAI,OAAuB,KAAK,IAAI,GAAG,KAAK,MAAM,KAAK,CAAC;CAG5D,OAAO;AACT;AAMA,IAAI,kBAA6C;;;;;AAMjD,SAAgB,gBAAgB,QAAiD;CAC/E,IAAI,CAAC,iBACH,kBAAkB,IAAI,mBAAmB,MAAM;MAC1C,IAAI,QAIT,gBAAgB,UAAU,MAAM;CAElC,OAAO;AACT;;;;;;;AAQA,SAAgB,sBAAsB,QAAgD;CACpF,MAAM,WAAW,gBAAgB;CACjC,SAAS,UAAU,MAAM;CACzB,OAAO;AACT;;AAGA,SAAgB,8BAAoC;CAClD,kBAAkB;AACpB"}
@@ -0,0 +1,17 @@
1
+ // \0rolldown/runtime.js
2
+ var __defProp = Object.defineProperty;
3
+ var __exportAll = (all, flags) => {
4
+ let target = Object.setPrototypeOf({}, null);
5
+ for (var name in all) {
6
+ __defProp(target, name, {
7
+ get: all[name],
8
+ enumerable: true
9
+ });
10
+ }
11
+ if (!(flags & 1)) {
12
+ __defProp(target, Symbol.toStringTag, { value: "Module" });
13
+ }
14
+ return flags & 2 ? target : Object.preventExtensions(target);
15
+ };
16
+
17
+ export { __exportAll as t };
@@ -0,0 +1,124 @@
1
+ import { t as importOptionalPeer } from "./import-optional-peer-B82VYxeX.js";
2
+
3
+ // src/telemetry/sdk.ts
4
+ /**
5
+ * Thin wrapper that initializes `@opentelemetry/sdk-node` with the
6
+ * OTLPTrace + OTLPMetric exporters and standard auto-instrumentations.
7
+ *
8
+ * All imports are dynamic so services that haven't installed sdk-node
9
+ * still compile and run. The function resolves `undefined` when the SDK
10
+ * isn't available, letting `bootstrapTelemetry` fall back gracefully.
11
+ */
12
+ const isThenable = (value) => {
13
+ return typeof value === "object" && value !== null && typeof value.then === "function";
14
+ };
15
+ const asyncDisposeMetricReader = async (metricReaderCandidate) => {
16
+ const shutdown = metricReaderCandidate.shutdown;
17
+ if (typeof shutdown === "function") {
18
+ const result = shutdown.call(metricReaderCandidate);
19
+ if (isThenable(result)) await result;
20
+ }
21
+ };
22
+ async function createOtelSdk(cfg) {
23
+ console.log("[sdk] importing @opentelemetry/sdk-node...");
24
+ const sdkMod = await importOptionalPeer("@opentelemetry/sdk-node");
25
+ console.log("[sdk] importing @opentelemetry/resources...");
26
+ const resources = await importOptionalPeer("@opentelemetry/resources");
27
+ console.log("[sdk] importing @opentelemetry/semantic-conventions...");
28
+ const sem = await importOptionalPeer("@opentelemetry/semantic-conventions");
29
+ console.log("[sdk] importing @opentelemetry/exporter-trace-otlp-http...");
30
+ const traceExp = await importOptionalPeer("@opentelemetry/exporter-trace-otlp-http");
31
+ console.log("[sdk] importing @opentelemetry/exporter-metrics-otlp-http...");
32
+ let metricsExp;
33
+ try {
34
+ metricsExp = await importOptionalPeer("@opentelemetry/exporter-metrics-otlp-http");
35
+ } catch {
36
+ metricsExp = void 0;
37
+ console.log("[sdk] metrics exporter not available (non-fatal)");
38
+ }
39
+ let metricReader;
40
+ let metricsEnabled = false;
41
+ let metricsDropReason;
42
+ if (metricsExp?.OTLPMetricExporter) try {
43
+ const candidate = new (await (importOptionalPeer("@opentelemetry/sdk-metrics"))).PeriodicExportingMetricReader({ exporter: new metricsExp.OTLPMetricExporter({ url: `${cfg.otlpEndpoint.replace(/\/$/, "")}/v1/metrics` }) });
44
+ if (typeof candidate.setMetricProducer === "function") {
45
+ metricReader = candidate;
46
+ metricsEnabled = true;
47
+ } else {
48
+ metricsDropReason = "setMetricProducer is not a function on PeriodicExportingMetricReader; skipping metrics path";
49
+ await asyncDisposeMetricReader(candidate);
50
+ metricReader = void 0;
51
+ }
52
+ } catch {
53
+ if (metricsDropReason === void 0) metricsDropReason = "metric reader construction or compatibility check failed";
54
+ metricReader = void 0;
55
+ }
56
+ console.log("[sdk] importing @opentelemetry/sdk-trace-base for sampler...");
57
+ let sampler;
58
+ try {
59
+ const traceBase = await importOptionalPeer("@opentelemetry/sdk-trace-base");
60
+ sampler = new traceBase.ParentBasedSampler({ root: new traceBase.TraceIdRatioBasedSampler(Math.min(1, Math.max(0, cfg.sampleRatio))) });
61
+ } catch {
62
+ sampler = void 0;
63
+ console.log("[sdk] sampler not available (non-fatal)");
64
+ }
65
+ console.log("[sdk] importing @opentelemetry/auto-instrumentations-node...");
66
+ let autoInstrumentations;
67
+ try {
68
+ autoInstrumentations = (await importOptionalPeer("@opentelemetry/auto-instrumentations-node")).getNodeAutoInstrumentations({ "@opentelemetry/instrumentation-fs": { enabled: false } });
69
+ console.log("[sdk] auto-instrumentations loaded");
70
+ } catch {
71
+ autoInstrumentations = void 0;
72
+ console.log("[sdk] auto-instrumentations not available (non-fatal)");
73
+ }
74
+ const serviceNamespaceByBoundary = {
75
+ wspace: "workspaces",
76
+ global: "tenant",
77
+ gateway: "gateways"
78
+ };
79
+ const resourceAttributes = {
80
+ [sem["SEMRESATTRS_SERVICE_NAME"] ?? "service.name"]: cfg.serviceName,
81
+ [sem["SEMRESATTRS_SERVICE_VERSION"] ?? "service.version"]: cfg.serviceVersion,
82
+ [sem["SEMRESATTRS_SERVICE_NAMESPACE"] ?? "service.namespace"]: serviceNamespaceByBoundary[cfg.boundary],
83
+ [sem["SEMRESATTRS_DEPLOYMENT_ENVIRONMENT"] ?? "deployment.environment"]: cfg.env,
84
+ "burdenoff.boundary": cfg.boundary
85
+ };
86
+ if (cfg.module) resourceAttributes["burdenoff.module"] = cfg.module;
87
+ const serviceInstanceId = process.env["POD_NAME"] ?? process.env["HOSTNAME"];
88
+ if (serviceInstanceId) resourceAttributes["service.instance.id"] = serviceInstanceId;
89
+ const clusterName = process.env["CLUSTER_NAME"];
90
+ if (clusterName) {
91
+ resourceAttributes["cluster"] = clusterName;
92
+ resourceAttributes["k8s.cluster.name"] = clusterName;
93
+ }
94
+ const resource = resources.resourceFromAttributes(resourceAttributes);
95
+ const traceExporter = new traceExp.OTLPTraceExporter({ url: `${cfg.otlpEndpoint.replace(/\/$/, "")}/v1/traces` });
96
+ console.log("[sdk] constructing NodeSDK...");
97
+ const nodeSdk = new sdkMod.NodeSDK({
98
+ resource,
99
+ traceExporter,
100
+ ...metricReader ? { metricReader } : {},
101
+ ...sampler ? { sampler } : {},
102
+ ...cfg.idGenerator ? { idGenerator: cfg.idGenerator } : {},
103
+ ...autoInstrumentations ? { instrumentations: autoInstrumentations } : {}
104
+ });
105
+ console.log("[sdk] NodeSDK constructed, calling start()...");
106
+ const startResult = nodeSdk.start();
107
+ if (isThenable(startResult)) await startResult;
108
+ console.log("[sdk] NodeSDK started");
109
+ try {
110
+ globalThis.__otelApi = await importOptionalPeer("@opentelemetry/api");
111
+ console.log("[sdk] @opentelemetry/api stashed for pino mixin");
112
+ } catch {
113
+ console.log("[sdk] @opentelemetry/api stash failed (non-fatal)");
114
+ }
115
+ console.log("[sdk] OTel SDK initialization complete");
116
+ return {
117
+ shutdown: async () => nodeSdk.shutdown(),
118
+ metricsEnabled,
119
+ metricsDropReason
120
+ };
121
+ }
122
+
123
+ export { createOtelSdk };
124
+ //# sourceMappingURL=sdk-Dju9o-sq.js.map