@burdenoff/be-sdk 2026.1110.1 → 2026.1110.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (469) hide show
  1. package/configs/eslint/index.js +1 -1
  2. package/configs/tsconfig/tsconfig.json +1 -1
  3. package/dist/EventQueueFactory-9NGZV9jl.js +1457 -0
  4. package/dist/EventQueueFactory-9NGZV9jl.js.map +1 -0
  5. package/dist/RedisStreamsConnection-CY8WySJy.js +283 -0
  6. package/dist/RedisStreamsConnection-CY8WySJy.js.map +1 -0
  7. package/dist/ai-credits/index.d.ts +2 -3
  8. package/dist/ai-credits/index.js +3 -4
  9. package/dist/ai-credits/index.js.map +1 -1
  10. package/dist/ai-credits-Ca-NNcVx.js +546 -0
  11. package/dist/ai-credits-Ca-NNcVx.js.map +1 -0
  12. package/dist/{assistant-session-CJZhF4D6.d.ts → assistant-session-DA5ZKJOr.d.ts} +4 -5
  13. package/dist/auth/index.d.ts +2 -77
  14. package/dist/auth/index.js +3 -7
  15. package/dist/auth/index.js.map +1 -1
  16. package/dist/auth-CEuBEBQN.js +228 -0
  17. package/dist/auth-CEuBEBQN.js.map +1 -0
  18. package/dist/cache/index.d.ts +2 -3
  19. package/dist/cache/index.js +3 -7
  20. package/dist/cache/index.js.map +1 -1
  21. package/dist/cache-CU0uLwcS.js +1837 -0
  22. package/dist/cache-CU0uLwcS.js.map +1 -0
  23. package/dist/captcha/index.d.ts +2 -1
  24. package/dist/captcha/index.js +3 -3
  25. package/dist/captcha/index.js.map +1 -1
  26. package/dist/captcha-BT7yh1YS.js +77 -0
  27. package/dist/captcha-BT7yh1YS.js.map +1 -0
  28. package/dist/client/internal-client.d.ts +4 -7
  29. package/dist/client/internal-client.js +172 -4
  30. package/dist/client/internal-client.js.map +1 -1
  31. package/dist/client-BgAEvDC2.d.ts +86 -0
  32. package/dist/client-DcZ3iGES.js +565 -0
  33. package/dist/client-DcZ3iGES.js.map +1 -0
  34. package/dist/collector-endpoint-iyQYeI50.js +50 -0
  35. package/dist/collector-endpoint-iyQYeI50.js.map +1 -0
  36. package/dist/context-CZnXf2yb.js +247 -0
  37. package/dist/context-CZnXf2yb.js.map +1 -0
  38. package/dist/crypto/index.d.ts +2 -1
  39. package/dist/crypto/index.js +3 -3
  40. package/dist/crypto/index.js.map +1 -1
  41. package/dist/crypto-DO9fM0FO.js +145 -0
  42. package/dist/crypto-DO9fM0FO.js.map +1 -0
  43. package/dist/database/index.d.ts +104 -108
  44. package/dist/database/index.js +468 -6
  45. package/dist/database/index.js.map +1 -1
  46. package/dist/dataloader/index.d.ts +2 -1
  47. package/dist/dataloader/index.js +3 -3
  48. package/dist/dataloader/index.js.map +1 -1
  49. package/dist/dataloader-DwpT3YoS.js +294 -0
  50. package/dist/dataloader-DwpT3YoS.js.map +1 -0
  51. package/dist/deployed-environment-p_Tdl3sT.js +38 -0
  52. package/dist/deployed-environment-p_Tdl3sT.js.map +1 -0
  53. package/dist/dist-BGKdXVy3.js +1718 -0
  54. package/dist/dist-BGKdXVy3.js.map +1 -0
  55. package/dist/env-DdaoGjIt.js +74 -0
  56. package/dist/env-DdaoGjIt.js.map +1 -0
  57. package/dist/event-queue/index.d.ts +2 -7
  58. package/dist/event-queue/index.js +7 -9
  59. package/dist/event-queue/index.js.map +1 -1
  60. package/dist/event-queue-Cw-YJPY_.js +1384 -0
  61. package/dist/event-queue-Cw-YJPY_.js.map +1 -0
  62. package/dist/{explicit-activity-scope-CCoxVwAr.d.ts → explicit-activity-scope-D8VeGGpt.d.ts} +1 -2
  63. package/dist/export/index.d.ts +2 -2
  64. package/dist/export/index.js +3 -14
  65. package/dist/export/index.js.map +1 -1
  66. package/dist/export-B6fphx8a.js +642 -0
  67. package/dist/export-B6fphx8a.js.map +1 -0
  68. package/dist/feature-flags/index.d.ts +2 -10
  69. package/dist/feature-flags/index.js +3 -6
  70. package/dist/feature-flags/index.js.map +1 -1
  71. package/dist/feature-flags-71oDkrUe.js +422 -0
  72. package/dist/feature-flags-71oDkrUe.js.map +1 -0
  73. package/dist/files/index.d.ts +2 -3
  74. package/dist/files/index.js +3 -4
  75. package/dist/files/index.js.map +1 -1
  76. package/dist/files-DjH0099H.js +830 -0
  77. package/dist/files-DjH0099H.js.map +1 -0
  78. package/dist/gateway/index.d.ts +4 -6
  79. package/dist/gateway/index.js +7 -13
  80. package/dist/gateway/index.js.map +1 -1
  81. package/dist/gateway/security/index.d.ts +2 -2
  82. package/dist/gateway/security/index.js +3 -5
  83. package/dist/gateway/security/index.js.map +1 -1
  84. package/dist/gateway-DBFmxWks.js +50 -0
  85. package/dist/gateway-DBFmxWks.js.map +1 -0
  86. package/dist/graph/index.d.ts +3 -10
  87. package/dist/graph/index.js +4 -13
  88. package/dist/graph/index.js.map +1 -1
  89. package/dist/graph-DDYgIryR.js +2152 -0
  90. package/dist/graph-DDYgIryR.js.map +1 -0
  91. package/dist/graph-emitter-CdOXP7Tn.js +621 -0
  92. package/dist/graph-emitter-CdOXP7Tn.js.map +1 -0
  93. package/dist/graphql/index.d.ts +3 -2
  94. package/dist/graphql/index.js +4 -6
  95. package/dist/graphql/index.js.map +1 -1
  96. package/dist/graphql/services/index.d.ts +2 -24
  97. package/dist/graphql/services/index.js +3 -4
  98. package/dist/graphql/services/index.js.map +1 -1
  99. package/dist/graphql-DHAHHcww.js +161 -0
  100. package/dist/graphql-DHAHHcww.js.map +1 -0
  101. package/dist/graphql-DNkMkGBZ.d.ts +21 -0
  102. package/dist/i18n/index.d.ts +3 -3
  103. package/dist/i18n/index.js +3 -4
  104. package/dist/i18n/index.js.map +1 -1
  105. package/dist/i18n-BBMYFd0P.js +860 -0
  106. package/dist/i18n-BBMYFd0P.js.map +1 -0
  107. package/dist/import-optional-peer-B82VYxeX.js +18 -0
  108. package/dist/import-optional-peer-B82VYxeX.js.map +1 -0
  109. package/dist/index-3KOZ1zN9.d.ts +233 -0
  110. package/dist/index-BBqooJ52.d.ts +45 -0
  111. package/dist/index-BGzMYJsm.d.ts +209 -0
  112. package/dist/index-BKwHQtHQ.d.ts +63 -0
  113. package/dist/index-BMIMnp6T.d.ts +8 -0
  114. package/dist/index-BQDsNAMR.d.ts +81 -0
  115. package/dist/index-BVOL7458.d.ts +10 -0
  116. package/dist/index-BcqQs-Uq.d.ts +69 -0
  117. package/dist/index-BeVtqGO-.d.ts +208 -0
  118. package/dist/index-BiTzGUZP.d.ts +114 -0
  119. package/dist/index-BqYfCQSP.d.ts +500 -0
  120. package/dist/index-C0qLquY0.d.ts +150 -0
  121. package/dist/index-C5uEKchX.d.ts +60 -0
  122. package/dist/index-CDOqxSIi.d.ts +37 -0
  123. package/dist/index-CG6wj66Y.d.ts +148 -0
  124. package/dist/index-CIgoeobA.d.ts +145 -0
  125. package/dist/index-CPQDMSFS.d.ts +103 -0
  126. package/dist/index-CSRcgkVi.d.ts +23 -0
  127. package/dist/index-CZTnQIRU.d.ts +341 -0
  128. package/dist/index-CaM9JUcc.d.ts +144 -0
  129. package/dist/index-CkT2aUr3.d.ts +704 -0
  130. package/dist/index-CliOgq6L.d.ts +203 -0
  131. package/dist/index-CnzbJZP7.d.ts +999 -0
  132. package/dist/index-D6UeLAye.d.ts +63 -0
  133. package/dist/index-DGgh9DWn.d.ts +59 -0
  134. package/dist/index-DY3dNhMN.d.ts +420 -0
  135. package/dist/index-DZC-2o9R.d.ts +207 -0
  136. package/dist/index-DqbGqfAy.d.ts +127 -0
  137. package/dist/index-Dt1HJPTX.d.ts +12 -0
  138. package/dist/index-DtI6aBtB.d.ts +22 -0
  139. package/dist/index-FKohsiex.d.ts +38 -0
  140. package/dist/index-FbXPfen7.d.ts +132 -0
  141. package/dist/index-MArCb8Aq.d.ts +306 -0
  142. package/dist/index-N-huORcj.d.ts +303 -0
  143. package/dist/index-YOShAwkq.d.ts +45 -0
  144. package/dist/index-bZKZUvBu.d.ts +646 -0
  145. package/dist/index-yBSjMY32.d.ts +24 -0
  146. package/dist/index.d.ts +501 -544
  147. package/dist/index.js +1820 -2171
  148. package/dist/index.js.map +1 -1
  149. package/dist/init/index.d.ts +2 -2
  150. package/dist/init/index.js +3 -16
  151. package/dist/init/index.js.map +1 -1
  152. package/dist/init-Dy3KhT6Y.js +325 -0
  153. package/dist/init-Dy3KhT6Y.js.map +1 -0
  154. package/dist/instrumentation/index.d.ts +3 -4
  155. package/dist/instrumentation/index.js +5 -5
  156. package/dist/instrumentation/index.js.map +1 -1
  157. package/dist/instrumentation-xkkmDgJ0.js +1678 -0
  158. package/dist/instrumentation-xkkmDgJ0.js.map +1 -0
  159. package/dist/lake/index.d.ts +50 -54
  160. package/dist/lake/index.js +169 -193
  161. package/dist/lake/index.js.map +1 -1
  162. package/dist/layer/index.d.ts +3 -2
  163. package/dist/layer/index.js +4 -5
  164. package/dist/layer/index.js.map +1 -1
  165. package/dist/layer-BZBZZWeV.d.ts +69 -0
  166. package/dist/layer-Bcix-WCl.js +105 -0
  167. package/dist/layer-Bcix-WCl.js.map +1 -0
  168. package/dist/layer-CEKy6cm8.js +252 -0
  169. package/dist/layer-CEKy6cm8.js.map +1 -0
  170. package/dist/lifecycle/index.d.ts +2 -1
  171. package/dist/lifecycle/index.js +3 -4
  172. package/dist/lifecycle/index.js.map +1 -1
  173. package/dist/lifecycle-DeoLSX0U.js +76 -0
  174. package/dist/lifecycle-DeoLSX0U.js.map +1 -0
  175. package/dist/logger/index.d.ts +2 -3
  176. package/dist/logger/index.js +3 -3
  177. package/dist/logger/index.js.map +1 -1
  178. package/dist/logger-B6rCpb7D.js +290 -0
  179. package/dist/logger-B6rCpb7D.js.map +1 -0
  180. package/dist/metrics/index.d.ts +13 -14
  181. package/dist/metrics/index.js +3 -4
  182. package/dist/metrics/index.js.map +1 -1
  183. package/dist/metrics-BrLwNUrb.js +52 -0
  184. package/dist/metrics-BrLwNUrb.js.map +1 -0
  185. package/dist/metrics-collector-C2eShrlW.js +922 -0
  186. package/dist/metrics-collector-C2eShrlW.js.map +1 -0
  187. package/dist/middleware/index.d.ts +3 -3
  188. package/dist/middleware/index.js +3 -4
  189. package/dist/middleware/index.js.map +1 -1
  190. package/dist/middleware-CUxJVUpD.js +1243 -0
  191. package/dist/middleware-CUxJVUpD.js.map +1 -0
  192. package/dist/middleware-Cq0zFMGp.js +253 -0
  193. package/dist/middleware-Cq0zFMGp.js.map +1 -0
  194. package/dist/notifications/index.d.ts +2 -5
  195. package/dist/notifications/index.js +3 -6
  196. package/dist/notifications/index.js.map +1 -1
  197. package/dist/notifications-CdETrtFK.js +869 -0
  198. package/dist/notifications-CdETrtFK.js.map +1 -0
  199. package/dist/observability/index.d.ts +2 -3
  200. package/dist/observability/index.js +3 -4
  201. package/dist/observability/index.js.map +1 -1
  202. package/dist/observability-DBDXipTU.js +272 -0
  203. package/dist/observability-DBDXipTU.js.map +1 -0
  204. package/dist/platform/index.d.ts +2 -1
  205. package/dist/platform/index.js +3 -5
  206. package/dist/platform/index.js.map +1 -1
  207. package/dist/platform-DZwczW7v.js +1510 -0
  208. package/dist/platform-DZwczW7v.js.map +1 -0
  209. package/dist/prisma/generator/index.d.ts +1 -1
  210. package/dist/prisma/generator/index.js +97 -84
  211. package/dist/prisma/generator/index.js.map +1 -1
  212. package/dist/prisma/index.d.ts +4 -7
  213. package/dist/prisma/index.js +5 -12
  214. package/dist/prisma/index.js.map +1 -1
  215. package/dist/prisma-BzOOdt79.js +863 -0
  216. package/dist/prisma-BzOOdt79.js.map +1 -0
  217. package/dist/prisma-extension-Cfl09swM.d.ts +172 -0
  218. package/dist/product-alias/index.d.ts +2 -1
  219. package/dist/product-alias/index.js +3 -3
  220. package/dist/product-alias/index.js.map +1 -1
  221. package/dist/product-alias-BPqtskMq.js +273 -0
  222. package/dist/product-alias-BPqtskMq.js.map +1 -0
  223. package/dist/rbac/index.d.ts +2 -122
  224. package/dist/rbac/index.js +3 -6
  225. package/dist/rbac/index.js.map +1 -1
  226. package/dist/rbac-BB9l9Xph.js +1486 -0
  227. package/dist/rbac-BB9l9Xph.js.map +1 -0
  228. package/dist/resource-caps/index.d.ts +66 -72
  229. package/dist/resource-caps/index.js +430 -5
  230. package/dist/resource-caps/index.js.map +1 -1
  231. package/dist/rolldown-runtime-ad2WFvuA.js +17 -0
  232. package/dist/sdk-Dju9o-sq.js +124 -0
  233. package/dist/sdk-Dju9o-sq.js.map +1 -0
  234. package/dist/security-DIG-95Ic.js +1647 -0
  235. package/dist/security-DIG-95Ic.js.map +1 -0
  236. package/dist/server/index.d.ts +7 -164
  237. package/dist/server/index.js +2000 -1507
  238. package/dist/server/index.js.map +1 -1
  239. package/dist/service-jwt-Bu-WNA_-.js +80 -0
  240. package/dist/service-jwt-Bu-WNA_-.js.map +1 -0
  241. package/dist/services-BWzfz7vG.js +102 -0
  242. package/dist/services-BWzfz7vG.js.map +1 -0
  243. package/dist/sharding/index.d.ts +41 -44
  244. package/dist/sharding/index.js +156 -137
  245. package/dist/sharding/index.js.map +1 -1
  246. package/dist/sharing/index.d.ts +2 -1
  247. package/dist/sharing/index.js +3 -4
  248. package/dist/sharing/index.js.map +1 -1
  249. package/dist/sharing-CflDsSJ-.js +911 -0
  250. package/dist/sharing-CflDsSJ-.js.map +1 -0
  251. package/dist/stub-BqwKn4eh.js +630 -0
  252. package/dist/stub-BqwKn4eh.js.map +1 -0
  253. package/dist/tags/index.d.ts +2 -3
  254. package/dist/tags/index.js +3 -4
  255. package/dist/tags/index.js.map +1 -1
  256. package/dist/tags-B5xpbgsk.js +868 -0
  257. package/dist/{chunk-PBZFAAOM.js.map → tags-B5xpbgsk.js.map} +1 -1
  258. package/dist/telemetry/index.d.ts +64 -76
  259. package/dist/telemetry/index.js +369 -201
  260. package/dist/telemetry/index.js.map +1 -1
  261. package/dist/temporal/index.d.ts +2 -148
  262. package/dist/temporal/index.js +3 -5
  263. package/dist/temporal/index.js.map +1 -1
  264. package/dist/temporal-B534uYK8.js +706 -0
  265. package/dist/temporal-B534uYK8.js.map +1 -0
  266. package/dist/tracker/index.d.ts +5 -11
  267. package/dist/tracker/index.js +5 -20
  268. package/dist/tracker/index.js.map +1 -1
  269. package/dist/tracker-BQVoEFUo.js +839 -0
  270. package/dist/tracker-BQVoEFUo.js.map +1 -0
  271. package/dist/types-BYMYND1L.js +44 -0
  272. package/dist/types-BYMYND1L.js.map +1 -0
  273. package/dist/types-C6EKaS3V.d.ts +106 -0
  274. package/dist/types-CWybW61E.d.ts +323 -0
  275. package/dist/types-C_yfu3XK.d.ts +34 -0
  276. package/dist/types-Cj2RWXbz.js +90 -0
  277. package/dist/types-Cj2RWXbz.js.map +1 -0
  278. package/dist/types-DgaQqvxo.d.ts +70 -0
  279. package/dist/usage/index.d.ts +2 -213
  280. package/dist/usage/index.js +3 -15
  281. package/dist/usage/index.js.map +1 -1
  282. package/dist/usage-BKFZiWQn.js +682 -0
  283. package/dist/usage-BKFZiWQn.js.map +1 -0
  284. package/dist/utils/index.d.ts +2 -1
  285. package/dist/utils/index.js +3 -3
  286. package/dist/utils/index.js.map +1 -1
  287. package/dist/utils-DL85Tnbn.js +500 -0
  288. package/dist/utils-DL85Tnbn.js.map +1 -0
  289. package/dist/validation/index.d.ts +2 -2
  290. package/dist/validation/index.js +3 -3
  291. package/dist/validation/index.js.map +1 -1
  292. package/dist/validation-CPUITdMk.js +762 -0
  293. package/dist/validation-CPUITdMk.js.map +1 -0
  294. package/dist/workspace-extension-COrC0dYi.js +979 -0
  295. package/dist/workspace-extension-COrC0dYi.js.map +1 -0
  296. package/dist/{workspace-extension-BGwTOV_r.d.ts → workspace-extension-DTFTdGVF.d.ts} +43 -45
  297. package/package.json +7 -10
  298. package/dist/EventQueueFactory-PP534MBQ.js +0 -8
  299. package/dist/EventQueueFactory-PP534MBQ.js.map +0 -1
  300. package/dist/chunk-4XIBXZ6J.js +0 -276
  301. package/dist/chunk-4XIBXZ6J.js.map +0 -1
  302. package/dist/chunk-554Z4C2K.js +0 -1006
  303. package/dist/chunk-554Z4C2K.js.map +0 -1
  304. package/dist/chunk-5CAFHK2Z.js +0 -107
  305. package/dist/chunk-5CAFHK2Z.js.map +0 -1
  306. package/dist/chunk-63ZXJ42X.js +0 -451
  307. package/dist/chunk-63ZXJ42X.js.map +0 -1
  308. package/dist/chunk-6XEXJATV.js +0 -304
  309. package/dist/chunk-6XEXJATV.js.map +0 -1
  310. package/dist/chunk-726AR6Q7.js +0 -1532
  311. package/dist/chunk-726AR6Q7.js.map +0 -1
  312. package/dist/chunk-7EISSMFP.js +0 -617
  313. package/dist/chunk-7EISSMFP.js.map +0 -1
  314. package/dist/chunk-A5F6Z5UE.js +0 -21
  315. package/dist/chunk-A5F6Z5UE.js.map +0 -1
  316. package/dist/chunk-A6DE32ZS.js +0 -1507
  317. package/dist/chunk-A6DE32ZS.js.map +0 -1
  318. package/dist/chunk-BJQOGOVW.js +0 -602
  319. package/dist/chunk-BJQOGOVW.js.map +0 -1
  320. package/dist/chunk-CFXWH2IS.js +0 -52
  321. package/dist/chunk-CFXWH2IS.js.map +0 -1
  322. package/dist/chunk-DIOS6L7M.js +0 -690
  323. package/dist/chunk-DIOS6L7M.js.map +0 -1
  324. package/dist/chunk-DJNHR37J.js +0 -1185
  325. package/dist/chunk-DJNHR37J.js.map +0 -1
  326. package/dist/chunk-DRWH5XCJ.js +0 -876
  327. package/dist/chunk-DRWH5XCJ.js.map +0 -1
  328. package/dist/chunk-E4QNLVY4.js +0 -909
  329. package/dist/chunk-E4QNLVY4.js.map +0 -1
  330. package/dist/chunk-E6OAFS7A.js +0 -1346
  331. package/dist/chunk-E6OAFS7A.js.map +0 -1
  332. package/dist/chunk-EBDHIL7V.js +0 -774
  333. package/dist/chunk-EBDHIL7V.js.map +0 -1
  334. package/dist/chunk-ELU7VL3E.js +0 -245
  335. package/dist/chunk-ELU7VL3E.js.map +0 -1
  336. package/dist/chunk-FZRODKIN.js +0 -31
  337. package/dist/chunk-FZRODKIN.js.map +0 -1
  338. package/dist/chunk-GCIB76AJ.js +0 -882
  339. package/dist/chunk-GCIB76AJ.js.map +0 -1
  340. package/dist/chunk-HC6MPUIH.js +0 -1571
  341. package/dist/chunk-HC6MPUIH.js.map +0 -1
  342. package/dist/chunk-I3KOWRT3.js +0 -89
  343. package/dist/chunk-I3KOWRT3.js.map +0 -1
  344. package/dist/chunk-ID3WR4JS.js +0 -509
  345. package/dist/chunk-ID3WR4JS.js.map +0 -1
  346. package/dist/chunk-JVMAQOA3.js +0 -521
  347. package/dist/chunk-JVMAQOA3.js.map +0 -1
  348. package/dist/chunk-K56L7NUR.js +0 -1444
  349. package/dist/chunk-K56L7NUR.js.map +0 -1
  350. package/dist/chunk-KH4TRQCO.js +0 -1063
  351. package/dist/chunk-KH4TRQCO.js.map +0 -1
  352. package/dist/chunk-KJOSPVB2.js +0 -57
  353. package/dist/chunk-KJOSPVB2.js.map +0 -1
  354. package/dist/chunk-KO2ZXZ7W.js +0 -61
  355. package/dist/chunk-KO2ZXZ7W.js.map +0 -1
  356. package/dist/chunk-KS2HQCJR.js +0 -56
  357. package/dist/chunk-KS2HQCJR.js.map +0 -1
  358. package/dist/chunk-LA5KPWZ2.js +0 -413
  359. package/dist/chunk-LA5KPWZ2.js.map +0 -1
  360. package/dist/chunk-MESLAC5W.js +0 -574
  361. package/dist/chunk-MESLAC5W.js.map +0 -1
  362. package/dist/chunk-MWPYA2HD.js +0 -94
  363. package/dist/chunk-MWPYA2HD.js.map +0 -1
  364. package/dist/chunk-NUB5GQTU.js +0 -270
  365. package/dist/chunk-NUB5GQTU.js.map +0 -1
  366. package/dist/chunk-O2JMZHNH.js +0 -1908
  367. package/dist/chunk-O2JMZHNH.js.map +0 -1
  368. package/dist/chunk-OBBCR6WY.js +0 -277
  369. package/dist/chunk-OBBCR6WY.js.map +0 -1
  370. package/dist/chunk-OBZQ4AJC.js +0 -272
  371. package/dist/chunk-OBZQ4AJC.js.map +0 -1
  372. package/dist/chunk-OXNCBE7P.js +0 -971
  373. package/dist/chunk-OXNCBE7P.js.map +0 -1
  374. package/dist/chunk-PBZFAAOM.js +0 -941
  375. package/dist/chunk-PYD44IHJ.js +0 -728
  376. package/dist/chunk-PYD44IHJ.js.map +0 -1
  377. package/dist/chunk-QVPIACWD.js +0 -679
  378. package/dist/chunk-QVPIACWD.js.map +0 -1
  379. package/dist/chunk-QWNNFE4P.js +0 -41
  380. package/dist/chunk-QWNNFE4P.js.map +0 -1
  381. package/dist/chunk-RU266375.js +0 -327
  382. package/dist/chunk-RU266375.js.map +0 -1
  383. package/dist/chunk-RYTSVGGA.js +0 -1624
  384. package/dist/chunk-RYTSVGGA.js.map +0 -1
  385. package/dist/chunk-RZOFS2BQ.js +0 -225
  386. package/dist/chunk-RZOFS2BQ.js.map +0 -1
  387. package/dist/chunk-SBS4S2PJ.js +0 -100
  388. package/dist/chunk-SBS4S2PJ.js.map +0 -1
  389. package/dist/chunk-SPRG6G6G.js +0 -530
  390. package/dist/chunk-SPRG6G6G.js.map +0 -1
  391. package/dist/chunk-STWFX5E2.js +0 -233
  392. package/dist/chunk-STWFX5E2.js.map +0 -1
  393. package/dist/chunk-UNASM5VJ.js +0 -419
  394. package/dist/chunk-UNASM5VJ.js.map +0 -1
  395. package/dist/chunk-VAT66FJA.js +0 -245
  396. package/dist/chunk-VAT66FJA.js.map +0 -1
  397. package/dist/chunk-VFCMR5GX.js +0 -49
  398. package/dist/chunk-VFCMR5GX.js.map +0 -1
  399. package/dist/chunk-VGAHZKNJ.js +0 -66
  400. package/dist/chunk-VGAHZKNJ.js.map +0 -1
  401. package/dist/chunk-VTJTAAXC.js +0 -627
  402. package/dist/chunk-VTJTAAXC.js.map +0 -1
  403. package/dist/chunk-VXVLKRU6.js +0 -758
  404. package/dist/chunk-VXVLKRU6.js.map +0 -1
  405. package/dist/chunk-WWUU5ETI.js +0 -163
  406. package/dist/chunk-WWUU5ETI.js.map +0 -1
  407. package/dist/chunk-XE4OXN2W.js +0 -10
  408. package/dist/chunk-XE4OXN2W.js.map +0 -1
  409. package/dist/chunk-XOJORS75.js +0 -1853
  410. package/dist/chunk-XOJORS75.js.map +0 -1
  411. package/dist/chunk-YMZEUTD2.js +0 -110
  412. package/dist/chunk-YMZEUTD2.js.map +0 -1
  413. package/dist/chunk-ZZK3WEDI.js +0 -181
  414. package/dist/chunk-ZZK3WEDI.js.map +0 -1
  415. package/dist/client-CCXpAZ2r.d.ts +0 -89
  416. package/dist/client-DSI_760t.d.ts +0 -36
  417. package/dist/client-JU6T3UPB.js +0 -11
  418. package/dist/client-JU6T3UPB.js.map +0 -1
  419. package/dist/dist-2X4Q7PJA.js +0 -1491
  420. package/dist/dist-2X4Q7PJA.js.map +0 -1
  421. package/dist/env-4UWSUS64.js +0 -4
  422. package/dist/env-4UWSUS64.js.map +0 -1
  423. package/dist/graph-emitter-r5TylDBm.d.ts +0 -47
  424. package/dist/graphql-CMHMQjvd.d.ts +0 -23
  425. package/dist/i18n-Qm2AkPC-.d.ts +0 -33
  426. package/dist/index--yvpa6ay.d.ts +0 -83
  427. package/dist/index-4gKQKZ2B.d.ts +0 -71
  428. package/dist/index-5x0XMKXN.d.ts +0 -149
  429. package/dist/index-B70b5mYS.d.ts +0 -33
  430. package/dist/index-B8KrxO4j.d.ts +0 -755
  431. package/dist/index-BOuDKnqD.d.ts +0 -201
  432. package/dist/index-BTMt4OjA.d.ts +0 -201
  433. package/dist/index-BejbszA7.d.ts +0 -39
  434. package/dist/index-BkeOYZye.d.ts +0 -198
  435. package/dist/index-BuAj5nXg.d.ts +0 -83
  436. package/dist/index-BvkVcW8I.d.ts +0 -349
  437. package/dist/index-CWmH_-RZ.d.ts +0 -247
  438. package/dist/index-CbgWNcus.d.ts +0 -258
  439. package/dist/index-CmfPeQza.d.ts +0 -166
  440. package/dist/index-CmpG-zak.d.ts +0 -607
  441. package/dist/index-CoMKgL-p.d.ts +0 -12
  442. package/dist/index-D8HGwglK.d.ts +0 -541
  443. package/dist/index-DCaVm66D.d.ts +0 -1101
  444. package/dist/index-DE2w7E0d.d.ts +0 -83
  445. package/dist/index-DSOpj8DI.d.ts +0 -17
  446. package/dist/index-DW9q22GH.d.ts +0 -75
  447. package/dist/index-DnjJ9CwI.d.ts +0 -347
  448. package/dist/index-DwMJZ8PP.d.ts +0 -317
  449. package/dist/index-PaojfSdd.d.ts +0 -71
  450. package/dist/index-aHtYvc3i.d.ts +0 -284
  451. package/dist/index-e_18DzAg.d.ts +0 -18
  452. package/dist/index-ffmipXSA.d.ts +0 -55
  453. package/dist/index-joONjwLt.d.ts +0 -33
  454. package/dist/index-kssw5ziY.d.ts +0 -250
  455. package/dist/index-lFffh5-G.d.ts +0 -125
  456. package/dist/index-pxYge_6k.d.ts +0 -79
  457. package/dist/layer-Cv9vSwBx.d.ts +0 -70
  458. package/dist/pino-logger-H4HPW5P6.js +0 -5
  459. package/dist/pino-logger-H4HPW5P6.js.map +0 -1
  460. package/dist/prisma-extension-gYhYriA0.d.ts +0 -174
  461. package/dist/sdk-L75WWUP3.js +0 -156
  462. package/dist/sdk-L75WWUP3.js.map +0 -1
  463. package/dist/shutdown-registry-CW9LryO8.d.ts +0 -10
  464. package/dist/types-Bo2wkjSP.d.ts +0 -35
  465. package/dist/types-DVpvrAhd.d.ts +0 -71
  466. package/dist/types-DgJ4lDYA.d.ts +0 -108
  467. package/dist/types-USOv09qy.d.ts +0 -327
  468. package/dist/workspace-guard-NXVYYBVJ.js +0 -5
  469. package/dist/workspace-guard-NXVYYBVJ.js.map +0 -1
@@ -0,0 +1 @@
1
+ {"version":3,"file":"usage-BKFZiWQn.js","names":[],"sources":["../src/usage/billing.ts","../src/usage/index.ts"],"sourcesContent":["/**\n * Billing Usage Client\n *\n * Canonical cross-layer quota/usage surface for wspace services talking to\n * `global-billing-svc`. All transport (URL resolution, actor/service header\n * assembly, service-JWT minting, retries, circuit breaker, timeouts,\n * telemetry) comes from the {@link GatewayClient}:\n *\n * - **wspace -> wspace** (resolving a workspace's org) uses `internalQuery`\n * (same-layer internal gateway, `WSPACE_INT_GATEWAY_URL`).\n * - **wspace -> global** (billing account + quota + usage) uses\n * `crossLayerQuery`, which routes via the global PUBLIC gateway\n * (`GLOBAL_PUBLIC_GATEWAY_URL`) and mints a signed `service` JWT the\n * gateway trusts. Only `x-actor-type: service` is presented — never\n * `x-actor-id` (auth-middleware reads that as an on-behalf-of override and\n * downgrades the caller to `user`, yielding a 403). Actor identity for the\n * usage record is carried in the GraphQL variables (`userId`), not in\n * headers.\n *\n * Every read/write fails open (returns `null`/`false`, or `true` for the\n * workspace quota gate) so transient billing unavailability never blocks a\n * product operation; callers that need hard enforcement must layer it on top.\n *\n * @module usage/billing\n * @category Usage\n */\n\nimport { GatewayClient } from '../gateway/index.js';\nimport { logger } from '../logger/index.js';\n\n/**\n * Bound each gateway attempt so a slow billing gateway never stalls the\n * (blocking) quota-limit read.\n */\nconst DEFAULT_REQUEST_TIMEOUT_MS = 5_000;\n\n/** Default TTL for the in-process plan-limit cache. */\nconst DEFAULT_QUOTA_LIMIT_CACHE_TTL_MS = 5 * 60 * 1000;\n\n/** Lazy prune threshold — keeps the plan-limit cache bounded without timers. */\nconst QUOTA_LIMIT_CACHE_MAX_ENTRIES = 1_000;\n\nconst GET_WORKSPACE_ORG_QUERY = `\n query GetWorkspaceOrg($workspaceId: ID!) {\n workspace(id: $workspaceId) {\n orgId\n }\n }\n`;\n\nconst GET_DEFAULT_BILLING_ACCOUNT_QUERY = `\n query GetDefaultBillingAccount($orgId: ID!) {\n getDefaultBillingAccountByOrgId(orgId: $orgId) {\n id\n }\n }\n`;\n\nconst CHECK_QUOTA_QUERY = `\n query CheckQuotaExhausted($billingAccountId: ID!, $quotaName: String!, $productId: String) {\n checkQuotaExhausted(\n billingAccountId: $billingAccountId\n quotaName: $quotaName\n productId: $productId\n ) {\n limitLeft\n noLimit\n quotaAssignmentId\n }\n }\n`;\n\nconst ADD_USAGE_MUTATION = `\n mutation AddUsage(\n $billingAccountId: ID!\n $quotaName: String!\n $value: Int!\n $description: String!\n $tags: JSON\n $hash: String\n $userId: ID\n $productId: String\n ) {\n addUsage(\n billingAccountId: $billingAccountId\n quotaName: $quotaName\n value: $value\n description: $description\n tags: $tags\n hash: $hash\n userId: $userId\n productId: $productId\n )\n }\n`;\n\nconst GET_QUOTA_LIMIT_QUERY = `\n query GetQuotaLimit($billingAccountId: ID!, $quotaName: String!, $productId: String) {\n getQuotaUsageAndLimit(\n billingAccountId: $billingAccountId\n quotaName: $quotaName\n productId: $productId\n ) {\n limit\n noLimit\n }\n }\n`;\n\nconst FREE_UP_USAGE_MUTATION = `\n mutation FreeUpUsage(\n $billingAccountId: ID!\n $quotaName: String!\n $value: Int!\n $description: String\n $tags: JSON\n $hash: String\n $userId: ID\n $productId: String\n ) {\n freeUpUsage(\n billingAccountId: $billingAccountId\n quotaName: $quotaName\n value: $value\n description: $description\n tags: $tags\n hash: $hash\n userId: $userId\n productId: $productId\n )\n }\n`;\n\ninterface WorkspaceOrgQueryData {\n workspace?: {\n orgId?: string | null;\n } | null;\n}\n\ninterface BillingAccountQueryData {\n getDefaultBillingAccountByOrgId?: {\n id?: string | null;\n } | null;\n}\n\ninterface QuotaCheckQueryData {\n checkQuotaExhausted?: {\n limitLeft: number;\n noLimit: boolean;\n quotaAssignmentId: string;\n } | null;\n}\n\ninterface QuotaLimitQueryData {\n getQuotaUsageAndLimit?: {\n limit: number;\n noLimit: boolean;\n } | null;\n}\n\ninterface UsageMutationData {\n addUsage?: boolean;\n freeUpUsage?: boolean;\n}\n\n/** Common input for a quota/usage operation against a billing account. */\nexport interface BillingUsageOperationInput {\n quotaName: string;\n value?: number;\n description: string;\n /**\n * Product scope for the quota/usage record. Required — every caller must be\n * explicit about which product's meter it is touching (there is no implicit\n * default, which historically shipped as a copy-paste `'vibecontrols'`).\n */\n productId: string;\n userId?: string;\n hash?: string;\n tags?: Record<string, unknown>;\n}\n\n/** Quota/usage operation addressed by organization. */\nexport interface OrgBillingUsageOperationInput extends BillingUsageOperationInput {\n orgId: string;\n}\n\n/** Quota/usage operation addressed by workspace (org resolved internally). */\nexport interface WorkspaceBillingUsageOperationInput extends BillingUsageOperationInput {\n workspaceId: string;\n}\n\n/** Plan limit for a quota, as stored by billing-svc. */\nexport interface QuotaLimit {\n limit: number;\n noLimit: boolean;\n}\n\n/** Configuration for {@link BillingUsageClient}. */\nexport interface BillingUsageClientConfig {\n /**\n * Owning service identity (e.g. `wspace-tags-svc`). Sent as the service\n * identity header and used for log attribution.\n */\n serviceName: string;\n /** Per-request timeout in milliseconds. Defaults to 5s. */\n timeout?: number;\n /**\n * Pre-built {@link GatewayClient}. When omitted, one is created for the\n * `wspace` layer (deriving internal/cross-layer gateway URLs from env).\n * Primarily a test seam.\n */\n gatewayClient?: GatewayClient;\n /** TTL for the in-process plan-limit cache. Defaults to 5 minutes. */\n quotaLimitCacheTtlMs?: number;\n}\n\ninterface CachedQuotaLimit extends QuotaLimit {\n expiresAt: number;\n}\n\nfunction unwrap<TData>(data: TData | undefined): TData {\n if (!data) {\n throw new Error('GraphQL response did not include data');\n }\n return data;\n}\n\n/**\n * Canonical quota/usage client for wspace -> global-billing-svc traffic.\n *\n * See the module docstring for the transport contract. All methods fail open;\n * see individual method docs for the exact fallback value.\n */\nexport class BillingUsageClient {\n private readonly gatewayClient: GatewayClient;\n private readonly quotaLimitCacheTtlMs: number;\n private readonly logPrefix: string;\n\n // In-process cache for plan limits (changes at most when a workspace\n // upgrades their plan). Lazily pruned on access — no timers in a library.\n private readonly quotaLimitCache = new Map<string, CachedQuotaLimit>();\n\n constructor(config: BillingUsageClientConfig) {\n if (!config.serviceName) {\n throw new TypeError('BillingUsageClient requires a serviceName');\n }\n this.gatewayClient =\n config.gatewayClient ??\n new GatewayClient({\n layer: 'wspace',\n serviceName: config.serviceName,\n timeout: config.timeout ?? DEFAULT_REQUEST_TIMEOUT_MS,\n });\n this.quotaLimitCacheTtlMs = config.quotaLimitCacheTtlMs ?? DEFAULT_QUOTA_LIMIT_CACHE_TTL_MS;\n this.logPrefix = `[billing-usage:${config.serviceName}]`;\n }\n\n /**\n * Same-layer (wspace -> wspace) internal-gateway call.\n */\n private async queryWorkspaceLayer<TData>(\n query: string,\n variables: Record<string, unknown>,\n workspaceId: string\n ): Promise<TData> {\n const response = await this.gatewayClient.internalQuery<TData>({\n query,\n variables,\n headers: { 'x-workspace-id': workspaceId },\n // Blocking on the create path — keep it single-shot & snappy; consumers fail open.\n skipRetry: true,\n });\n return unwrap(response.data);\n }\n\n /**\n * Cross-layer (wspace -> global) public-gateway call. No actor headers — the\n * signed service JWT carries identity; adding `x-actor-id` would 403.\n */\n private async queryGlobalLayer<TData>(query: string, variables: Record<string, unknown>): Promise<TData> {\n const response = await this.gatewayClient.crossLayerQuery<TData>({ query, variables });\n return unwrap(response.data);\n }\n\n /**\n * Resolve the organization that owns a workspace. Fails open (`null`).\n */\n async getOrgIdFromWorkspace(workspaceId: string): Promise<string | null> {\n try {\n const data = await this.queryWorkspaceLayer<WorkspaceOrgQueryData>(\n GET_WORKSPACE_ORG_QUERY,\n { workspaceId },\n workspaceId\n );\n return data.workspace?.orgId ?? null;\n } catch (error) {\n logger.warn(`${this.logPrefix} Failed to resolve workspace org`, {\n workspaceId,\n error: error instanceof Error ? error.message : String(error),\n });\n return null;\n }\n }\n\n /**\n * Resolve the default billing account for an organization via the global\n * layer. Fails open (`null`).\n */\n async getDefaultBillingAccountId(orgId: string): Promise<string | null> {\n try {\n const data = await this.queryGlobalLayer<BillingAccountQueryData>(GET_DEFAULT_BILLING_ACCOUNT_QUERY, {\n orgId,\n });\n return data.getDefaultBillingAccountByOrgId?.id ?? null;\n } catch (error) {\n logger.warn(`${this.logPrefix} Failed to resolve default billing account`, {\n orgId,\n error: error instanceof Error ? error.message : String(error),\n });\n return null;\n }\n }\n\n /**\n * Check that an organization still has quota headroom for `value` units of\n * `quotaName`. Returns `false` when no billing account exists or the quota\n * is exhausted; rethrows nothing — transport errors propagate to the caller\n * of this low-level variant (the workspace variant fails open instead).\n */\n async ensureQuotaAvailableForOrg(input: OrgBillingUsageOperationInput): Promise<boolean> {\n const billingAccountId = await this.getDefaultBillingAccountId(input.orgId);\n if (!billingAccountId) {\n logger.warn(`${this.logPrefix} No billing account available for org quota check`, {\n orgId: input.orgId,\n quotaName: input.quotaName,\n });\n return false;\n }\n\n const amount = input.value ?? 1;\n const data = await this.queryGlobalLayer<QuotaCheckQueryData>(CHECK_QUOTA_QUERY, {\n billingAccountId,\n quotaName: input.quotaName,\n productId: input.productId,\n });\n\n const result = data.checkQuotaExhausted;\n if (!result) {\n return false;\n }\n\n if (result.noLimit) {\n return true;\n }\n\n return result.limitLeft >= amount;\n }\n\n /**\n * Workspace-addressed quota gate: resolves the org, then applies\n * {@link ensureQuotaAvailableForOrg}. Fails OPEN (`true`) when org\n * resolution fails (unbilled / dev / internal workspaces) so local-stack\n * test workspaces and workspaces with a transiently broken tenant lookup\n * are never locked out; real limits only kick in when the workspace has a\n * billable org.\n */\n async ensureQuotaAvailableForWorkspace(input: WorkspaceBillingUsageOperationInput): Promise<boolean> {\n const orgId = await this.getOrgIdFromWorkspace(input.workspaceId);\n if (!orgId) {\n logger.warn(`${this.logPrefix} No organization available; allowing quota op (fail-open)`, {\n workspaceId: input.workspaceId,\n quotaName: input.quotaName,\n });\n return true;\n }\n\n return this.ensureQuotaAvailableForOrg({ ...input, orgId });\n }\n\n /**\n * Record usage against an organization's billing account. No-ops (`false`)\n * when there is no billing account.\n */\n async addUsageForOrg(input: OrgBillingUsageOperationInput): Promise<boolean> {\n const billingAccountId = await this.getDefaultBillingAccountId(input.orgId);\n if (!billingAccountId) {\n logger.warn(`${this.logPrefix} No billing account available for addUsage`, {\n orgId: input.orgId,\n quotaName: input.quotaName,\n });\n return false;\n }\n\n const data = await this.queryGlobalLayer<UsageMutationData>(ADD_USAGE_MUTATION, {\n billingAccountId,\n quotaName: input.quotaName,\n value: input.value ?? 1,\n description: input.description,\n tags: input.tags,\n hash: input.hash,\n userId: input.userId,\n productId: input.productId,\n });\n\n return data.addUsage ?? false;\n }\n\n /**\n * Workspace-addressed {@link addUsageForOrg}. No-ops (`false`) when the\n * workspace has no org.\n */\n async addUsageForWorkspace(input: WorkspaceBillingUsageOperationInput): Promise<boolean> {\n const orgId = await this.getOrgIdFromWorkspace(input.workspaceId);\n if (!orgId) {\n logger.warn(`${this.logPrefix} No organization available for workspace addUsage`, {\n workspaceId: input.workspaceId,\n quotaName: input.quotaName,\n });\n return false;\n }\n\n return this.addUsageForOrg({ ...input, orgId });\n }\n\n /**\n * Credit usage back to an organization's billing account. No-ops (`false`)\n * when there is no billing account.\n */\n async freeUpUsageForOrg(input: OrgBillingUsageOperationInput): Promise<boolean> {\n const billingAccountId = await this.getDefaultBillingAccountId(input.orgId);\n if (!billingAccountId) {\n logger.warn(`${this.logPrefix} No billing account available for freeUpUsage`, {\n orgId: input.orgId,\n quotaName: input.quotaName,\n });\n return false;\n }\n\n const data = await this.queryGlobalLayer<UsageMutationData>(FREE_UP_USAGE_MUTATION, {\n billingAccountId,\n quotaName: input.quotaName,\n value: input.value ?? 1,\n description: input.description,\n tags: input.tags,\n hash: input.hash,\n userId: input.userId,\n productId: input.productId,\n });\n\n return data.freeUpUsage ?? false;\n }\n\n /**\n * Workspace-addressed {@link freeUpUsageForOrg}. No-ops (`false`) when the\n * workspace has no org.\n */\n async freeUpUsageForWorkspace(input: WorkspaceBillingUsageOperationInput): Promise<boolean> {\n const orgId = await this.getOrgIdFromWorkspace(input.workspaceId);\n if (!orgId) {\n logger.warn(`${this.logPrefix} No organization available for workspace freeUpUsage`, {\n workspaceId: input.workspaceId,\n quotaName: input.quotaName,\n });\n return false;\n }\n\n return this.freeUpUsageForOrg({ ...input, orgId });\n }\n\n /**\n * Fetch the plan limit for a quota from billing-svc, bypassing billing's\n * internal usage counter (the caller's own DB is the source of truth for\n * current usage; billing only stores the plan maximum). Results are cached\n * in-process per workspace/quota/product. Fails open (`null`) when billing\n * is unreachable so dev/test workspaces without billing accounts are never\n * blocked.\n */\n async getQuotaLimitForWorkspace(\n workspaceId: string,\n quotaName: string,\n productId: string\n ): Promise<QuotaLimit | null> {\n const cacheKey = `${workspaceId}:${quotaName}:${productId}`;\n const cached = this.quotaLimitCache.get(cacheKey);\n if (cached && cached.expiresAt > Date.now()) {\n return { limit: cached.limit, noLimit: cached.noLimit };\n }\n\n const orgId = await this.getOrgIdFromWorkspace(workspaceId);\n if (!orgId) {\n logger.warn(`${this.logPrefix} No org found for quota limit lookup; failing open`, {\n workspaceId,\n quotaName,\n });\n return null;\n }\n\n const billingAccountId = await this.getDefaultBillingAccountId(orgId);\n if (!billingAccountId) {\n logger.warn(`${this.logPrefix} No billing account found for quota limit lookup; failing open`, {\n workspaceId,\n quotaName,\n });\n return null;\n }\n\n try {\n const data = await this.queryGlobalLayer<QuotaLimitQueryData>(GET_QUOTA_LIMIT_QUERY, {\n billingAccountId,\n quotaName,\n productId,\n });\n\n const result = data.getQuotaUsageAndLimit;\n if (!result) {\n return null;\n }\n\n this.rememberQuotaLimit(cacheKey, { limit: result.limit, noLimit: result.noLimit });\n return { limit: result.limit, noLimit: result.noLimit };\n } catch (error) {\n logger.warn(`${this.logPrefix} Failed to fetch quota limit; failing open`, {\n workspaceId,\n quotaName,\n error: error instanceof Error ? error.message : String(error),\n });\n return null;\n }\n }\n\n private rememberQuotaLimit(cacheKey: string, value: QuotaLimit): void {\n if (this.quotaLimitCache.size >= QUOTA_LIMIT_CACHE_MAX_ENTRIES) {\n const now = Date.now();\n for (const [key, entry] of this.quotaLimitCache) {\n if (entry.expiresAt <= now) this.quotaLimitCache.delete(key);\n }\n // Still full after pruning (all entries fresh): drop the oldest-inserted\n // entries rather than refusing to cache. Plan limits are re-fetchable.\n if (this.quotaLimitCache.size >= QUOTA_LIMIT_CACHE_MAX_ENTRIES) {\n const overflow = this.quotaLimitCache.size - QUOTA_LIMIT_CACHE_MAX_ENTRIES + 1;\n let removed = 0;\n for (const key of this.quotaLimitCache.keys()) {\n this.quotaLimitCache.delete(key);\n removed += 1;\n if (removed >= overflow) break;\n }\n }\n }\n this.quotaLimitCache.set(cacheKey, { ...value, expiresAt: Date.now() + this.quotaLimitCacheTtlMs });\n }\n}\n","/**\n * Usage & Quota Module\n *\n * Checks and records workspace quota usage against the workspace usage owner\n * (wspace-activity-svc). The owner's published contract is:\n *\n * - `checkWorkspaceQuota(workspaceId, quotaName, amount): WorkspaceQuotaCheckResult!`\n * - `trackUsage(input: TrackUsageInput!): Boolean!`\n *\n * Quotas are keyed by `quotaName` (for example `platform.projects.created`), not by the\n * `entityId`/`entityType`/`metricType` triple this module used to send. That triple was\n * never part of the owner's schema, so every legacy call failed GraphQL validation\n * (BOFF-10955). The legacy methods remain for source compatibility and fail with\n * {@link UsageOperationUnsupportedError} before any network call.\n */\n\nimport { randomUUID } from 'node:crypto';\nimport type { BurdenoffGraphQLClient } from '../client/graphql.js';\nimport type { SDKContext } from '../types/index.js';\nimport { SDKError, ValidationError, QuotaExceededError } from '../types/index.js';\nimport { logger } from '../logger/index.js';\n\n/**\n * Legacy usage metric names. The workspace usage owner has no metric types; quotas are\n * addressed by `quotaName`. Kept so existing `sdk.tracker.track({ usage: { metricType } })`\n * call sites keep compiling; the tracker does not meter a metric type on its own.\n */\nexport enum UsageMetricType {\n API_CALLS = 'api_calls',\n STORAGE = 'storage',\n BANDWIDTH = 'bandwidth',\n USERS = 'users',\n PROJECTS = 'projects',\n WORKSPACES = 'workspaces',\n RECORDS = 'records',\n COMPUTE_TIME = 'compute_time',\n TRANSACTIONS = 'transactions',\n CUSTOM = 'custom',\n}\n\nexport enum QuotaPeriod {\n DAILY = 'daily',\n WEEKLY = 'weekly',\n MONTHLY = 'monthly',\n YEARLY = 'yearly',\n LIFETIME = 'lifetime',\n}\n\n/**\n * Entity type for usage tracking\n */\nexport type UsageEntityType = 'user' | 'workspace' | 'organization';\n\nexport interface TrackUsageOptions {\n /** User or workspace consuming the resource */\n entityId: string;\n /** Type of entity (user or workspace) */\n entityType: UsageEntityType;\n /** Metric type */\n metricType: UsageMetricType;\n /** Amount to increment */\n amount: number;\n /** Optional resource identifier */\n resourceId?: string;\n /** Optional metadata */\n metadata?: Record<string, unknown>;\n /** Workspace context */\n workspaceId?: string;\n /** Organization context */\n organizationId?: string;\n}\n\nexport interface CheckQuotaOptions {\n /** Entity to check quota for */\n entityId: string;\n /** Type of entity */\n entityType: UsageEntityType;\n /** Metric type */\n metricType: UsageMetricType;\n /** Amount to check availability for */\n requestedAmount: number;\n /** Workspace context */\n workspaceId?: string;\n /** Organization context */\n organizationId?: string;\n}\n\nexport interface QuotaCheckResult {\n allowed: boolean;\n currentUsage: number;\n quotaLimit: number;\n remainingQuota: number;\n resetAt?: string;\n period: QuotaPeriod;\n reason?: string;\n}\n\nexport interface UsageRecord {\n id: string;\n entityId: string;\n entityType: UsageEntityType;\n metricType: UsageMetricType;\n amount: number;\n resourceId?: string;\n metadata?: Record<string, unknown>;\n workspaceId?: string;\n organizationId?: string;\n recordedAt: string;\n}\n\nexport interface UsageSummary {\n entityId: string;\n entityType: string;\n metricType: UsageMetricType;\n totalUsage: number;\n period: QuotaPeriod;\n periodStart: string;\n periodEnd: string;\n quotaLimit?: number;\n utilizationPercentage?: number;\n}\n\nexport interface SetQuotaOptions {\n entityId: string;\n entityType: UsageEntityType;\n metricType: UsageMetricType;\n limit: number;\n period: QuotaPeriod;\n workspaceId?: string;\n organizationId?: string;\n}\n\nexport interface Quota {\n id: string;\n entityId: string;\n entityType: string;\n metricType: UsageMetricType;\n limit: number;\n period: QuotaPeriod;\n currentUsage: number;\n resetAt: string;\n createdAt: string;\n updatedAt: string;\n}\n\nexport interface GetUsageOptions {\n entityId: string;\n entityType: UsageEntityType;\n metricType?: UsageMetricType;\n startDate?: string;\n endDate?: string;\n workspaceId?: string;\n organizationId?: string;\n limit?: number;\n offset?: number;\n}\n\n/** Thrown by SDK usage operations the workspace usage owner does not expose. */\nexport class UsageOperationUnsupportedError extends SDKError {\n constructor(operation: string, guidance: string) {\n super(\n `UsageModule.${operation} is not supported by the workspace usage owner: ${guidance}`,\n 'USAGE_OPERATION_UNSUPPORTED',\n { operation }\n );\n this.name = 'UsageOperationUnsupportedError';\n Object.setPrototypeOf(this, UsageOperationUnsupportedError.prototype);\n }\n}\n\n/**\n * Query sent to the owner's `checkWorkspaceQuota`. Every argument and selected field must\n * exist on the published wspace schema (see tests/usage-module.test.ts).\n */\nexport const CHECK_WORKSPACE_QUOTA_QUERY = `\n query CheckWorkspaceQuota($workspaceId: ID!, $quotaName: String!, $amount: Float) {\n checkWorkspaceQuota(workspaceId: $workspaceId, quotaName: $quotaName, amount: $amount) {\n allowed\n assignmentId\n limitLeft\n noLimit\n }\n }\n`;\n\n/** Mutation sent to the owner's `trackUsage`, which returns `Boolean!`. */\nexport const TRACK_USAGE_MUTATION = `\n mutation TrackUsage($input: TrackUsageInput!) {\n trackUsage(input: $input)\n }\n`;\n\nexport interface CheckWorkspaceQuotaOptions {\n /** Quota to check, for example `platform.projects.created`. */\n quotaName: string;\n /** Amount the caller is about to consume. Must be positive; defaults to 1. */\n amount?: number;\n /** Workspace that owns the quota. Defaults to the SDK context's workspace. */\n workspaceId?: string;\n /** End user the check is made for. Defaults to the SDK context's actor. */\n userId?: string;\n}\n\n/** The owner's `WorkspaceQuotaCheckResult`. */\nexport interface WorkspaceQuotaCheckResult {\n /** True when the quota has enough remaining capacity for the requested amount. */\n allowed: boolean;\n /** Active assignment to charge, or null when the workspace's plan does not include the quota. */\n assignmentId: string | null;\n /** Remaining capacity after the requested amount; null when unlimited or not provisioned. */\n limitLeft: number | null;\n /** True when the quota is unlimited. */\n noLimit: boolean;\n}\n\nexport interface TrackWorkspaceUsageOptions {\n /** Quota to charge, for example `platform.projects.created`. */\n quotaName: string;\n /** Product the quota belongs to, for example `platform`. Defaults to the SDK context's product. */\n productId?: string;\n /**\n * Amount to record. A positive amount consumes quota; a negative amount releases it (for\n * example on delete). The owner only accepts negative amounts from services and super\n * admins, which is how this module relays the call. Zero is rejected.\n */\n amount: number;\n /** Human-readable reason stored on the usage record. */\n description: string;\n /** Workspace to charge. Defaults to the SDK context's workspace. */\n workspaceId?: string;\n /** End user the usage is recorded for. Defaults to the SDK context's actor. */\n userId?: string;\n /** Assignment returned by {@link UsageModule.checkWorkspaceQuota}; saves the owner a lookup. */\n quotaAssignmentId?: string;\n /** Billing account reference stored on the record. Omit for workspace quotas. */\n billingAccountId?: string;\n /**\n * Idempotency key. The owner records one charge per hash and workspace, so a retried\n * request cannot charge twice. A random key is generated per call when omitted.\n */\n hash?: string;\n /** Additional metadata stored on the usage record. */\n metadata?: Record<string, unknown>;\n}\n\nfunction legacyGuidance(replacement: string): string {\n return `quotas are addressed by quotaName on the workspace usage owner; use ${replacement}`;\n}\n\nfunction nonEmpty(value: string | undefined): string | undefined {\n const trimmed = value?.trim();\n return trimmed ? trimmed : undefined;\n}\n\n/**\n * Builds the owner's `TrackUsageInput` from SDK options, filling defaults from the context.\n * Throws {@link ValidationError} for input the owner would refuse.\n */\nexport function buildTrackUsageInput(\n options: TrackWorkspaceUsageOptions,\n context: SDKContext = {}\n): Record<string, unknown> {\n const quotaName = nonEmpty(options.quotaName);\n if (!quotaName) {\n throw new ValidationError('Quota name is required');\n }\n const productId = nonEmpty(options.productId) ?? nonEmpty(context.productId);\n if (!productId) {\n throw new ValidationError('Product ID is required');\n }\n const description = nonEmpty(options.description);\n if (!description) {\n throw new ValidationError('Description is required');\n }\n if (typeof options.amount !== 'number' || !Number.isFinite(options.amount) || options.amount === 0) {\n throw new ValidationError('Amount must be a finite, non-zero number');\n }\n const workspaceId = nonEmpty(options.workspaceId) ?? nonEmpty(context.workspaceId);\n if (!workspaceId) {\n throw new ValidationError('Workspace ID is required');\n }\n\n const input: Record<string, unknown> = {\n quotaName,\n productId,\n amount: options.amount,\n description,\n workspaceId,\n hash: nonEmpty(options.hash) ?? `sdk-usage:${randomUUID()}`,\n };\n const userId = nonEmpty(options.userId) ?? nonEmpty(context.actorId);\n if (userId) input['userId'] = userId;\n if (options.quotaAssignmentId) input['quotaAssignmentId'] = options.quotaAssignmentId;\n if (options.billingAccountId) input['billingAccountId'] = options.billingAccountId;\n if (options.metadata) input['metadata'] = options.metadata;\n return input;\n}\n\n/**\n * Usage & Quota Module\n */\nexport class UsageModule {\n constructor(\n private client: BurdenoffGraphQLClient,\n private context: SDKContext\n ) {}\n\n /**\n * Context for one owner call: relayed as a platform service acting for `userId`, with the\n * quota's workspace in scope. The owner takes the workspace from this context, never from\n * the input, and only lets services release (decrement) usage.\n */\n private requestContext(workspaceId: string, userId: string | undefined): SDKContext {\n const actorId = userId ?? this.context.actorId;\n return {\n ...this.context,\n ...(actorId ? { actorId } : {}),\n actorType: 'service',\n workspaceId,\n };\n }\n\n /**\n * Check whether a workspace quota has capacity for `amount` (default 1).\n */\n public async checkWorkspaceQuota(options: CheckWorkspaceQuotaOptions): Promise<WorkspaceQuotaCheckResult> {\n const quotaName = nonEmpty(options.quotaName);\n if (!quotaName) {\n throw new ValidationError('Quota name is required');\n }\n const amount = options.amount ?? 1;\n if (typeof amount !== 'number' || !Number.isFinite(amount) || amount <= 0) {\n throw new ValidationError('Quota checks need a positive amount');\n }\n const workspaceId = nonEmpty(options.workspaceId) ?? nonEmpty(this.context.workspaceId);\n if (!workspaceId) {\n throw new ValidationError('Workspace ID is required');\n }\n\n logger.debug('[Usage] Checking workspace quota', { workspaceId, quotaName, amount });\n\n const response = await this.client.query<{ checkWorkspaceQuota: WorkspaceQuotaCheckResult }>(\n CHECK_WORKSPACE_QUOTA_QUERY,\n { workspaceId, quotaName, amount },\n this.requestContext(workspaceId, nonEmpty(options.userId))\n );\n\n const result = response.checkWorkspaceQuota;\n logger.debug('[Usage] Workspace quota check result', { workspaceId, quotaName, allowed: result.allowed });\n return result;\n }\n\n /**\n * Check a workspace quota and throw {@link QuotaExceededError} when it has no capacity.\n * Returns the check result so the caller can pass `assignmentId` to {@link trackUsage}.\n */\n public async requireWorkspaceQuota(options: CheckWorkspaceQuotaOptions): Promise<WorkspaceQuotaCheckResult> {\n const result = await this.checkWorkspaceQuota(options);\n if (!result.allowed) {\n const notProvisioned = result.assignmentId === null;\n throw new QuotaExceededError(\n notProvisioned ? `Quota ${options.quotaName} is not included in this workspace's plan` : 'Quota exceeded',\n {\n quotaName: options.quotaName,\n requestedAmount: options.amount ?? 1,\n limitLeft: result.limitLeft,\n notProvisioned,\n }\n );\n }\n return result;\n }\n\n /**\n * Record workspace quota usage. A negative amount releases previously recorded usage.\n * Resolves to `true` once the owner has stored (or deduplicated) the record.\n */\n public async trackUsage(options: TrackWorkspaceUsageOptions): Promise<boolean> {\n const input = buildTrackUsageInput(options, this.context);\n const workspaceId = input['workspaceId'] as string;\n\n logger.debug('[Usage] Tracking workspace usage', {\n workspaceId,\n quotaName: input['quotaName'],\n amount: input['amount'],\n });\n\n const response = await this.client.query<{ trackUsage: boolean }>(\n TRACK_USAGE_MUTATION,\n { input },\n this.requestContext(workspaceId, nonEmpty(options.userId))\n );\n\n logger.info('[Usage] Workspace usage tracked', { workspaceId, quotaName: input['quotaName'] });\n return response.trackUsage;\n }\n\n /**\n * @deprecated The workspace usage owner has no `trackUsage` record shape keyed by\n * `entityId`/`metricType`. Use {@link trackUsage} with a `quotaName`.\n */\n public async track(_options: TrackUsageOptions): Promise<UsageRecord> {\n throw new UsageOperationUnsupportedError('track', legacyGuidance('trackUsage({ quotaName, productId, amount })'));\n }\n\n /**\n * @deprecated The owner has no `checkQuota` operation. Use {@link checkWorkspaceQuota}.\n */\n public async checkQuota(_options: CheckQuotaOptions): Promise<QuotaCheckResult> {\n throw new UsageOperationUnsupportedError(\n 'checkQuota',\n legacyGuidance('checkWorkspaceQuota({ quotaName, amount })')\n );\n }\n\n /**\n * @deprecated The owner has no `checkQuota` operation. Use {@link requireWorkspaceQuota}.\n */\n public async requireQuota(_options: CheckQuotaOptions): Promise<void> {\n throw new UsageOperationUnsupportedError(\n 'requireQuota',\n legacyGuidance('requireWorkspaceQuota({ quotaName, amount })')\n );\n }\n\n /**\n * @deprecated Use {@link requireWorkspaceQuota} followed by {@link trackUsage}.\n */\n public async trackAndCheck(_options: TrackUsageOptions): Promise<{\n usage: UsageRecord;\n quotaCheck: QuotaCheckResult;\n }> {\n throw new UsageOperationUnsupportedError(\n 'trackAndCheck',\n legacyGuidance('requireWorkspaceQuota() and then trackUsage()')\n );\n }\n\n /**\n * @deprecated The owner has no `getUsage` operation; read records with the owner's\n * `getUsageRecords(filters, pagination)`.\n */\n public async getUsage(_options: GetUsageOptions): Promise<{\n records: UsageRecord[];\n total: number;\n }> {\n throw new UsageOperationUnsupportedError('getUsage', legacyGuidance(\"the owner's getUsageRecords query\"));\n }\n\n /**\n * @deprecated The owner's `getUsageSummary` takes `UsageFilters` and returns a list; this\n * signature does not map onto it.\n */\n public async getSummary(\n _entityId: string,\n _entityType: UsageEntityType,\n _metricType: UsageMetricType,\n _period: QuotaPeriod\n ): Promise<UsageSummary> {\n throw new UsageOperationUnsupportedError(\n 'getSummary',\n legacyGuidance(\"the owner's getUsageSummary(filters) query\")\n );\n }\n\n /**\n * @deprecated Quota limits are assigned by global-billing-svc through the owner's\n * `assignWorkspaceQuota`, which only billing's service identity may call.\n */\n public async setQuota(_options: SetQuotaOptions): Promise<Quota> {\n throw new UsageOperationUnsupportedError('setQuota', 'quota limits are assigned by global-billing-svc');\n }\n\n /**\n * @deprecated The owner has no `getQuota` operation; read `workspaceQuotaStatuses(workspaceId)`.\n */\n public async getQuota(\n _entityId: string,\n _entityType: UsageEntityType,\n _metricType: UsageMetricType\n ): Promise<Quota | null> {\n throw new UsageOperationUnsupportedError('getQuota', legacyGuidance(\"the owner's workspaceQuotaStatuses query\"));\n }\n\n /**\n * @deprecated The owner has no `getQuotas` operation; read `workspaceQuotaAssignments(workspaceId)`.\n */\n public async getQuotas(_entityId: string, _entityType: UsageEntityType): Promise<Quota[]> {\n throw new UsageOperationUnsupportedError(\n 'getQuotas',\n legacyGuidance(\"the owner's workspaceQuotaAssignments query\")\n );\n }\n\n /**\n * @deprecated The owner has no `resetQuota` operation; quotas reset on their `resetPeriod`.\n */\n public async resetQuota(\n _entityId: string,\n _entityType: UsageEntityType,\n _metricType: UsageMetricType\n ): Promise<boolean> {\n throw new UsageOperationUnsupportedError('resetQuota', \"quotas reset on the assignment's resetPeriod\");\n }\n\n /**\n * @deprecated The owner has no `deleteQuota` operation; billing deactivates assignments.\n */\n public async deleteQuota(\n _entityId: string,\n _entityType: UsageEntityType,\n _metricType: UsageMetricType\n ): Promise<boolean> {\n throw new UsageOperationUnsupportedError('deleteQuota', 'quota assignments are deactivated by global-billing-svc');\n }\n\n /**\n * @deprecated The owner has no `trackUsageBulk` operation. Call {@link trackUsage} per record.\n */\n public async trackBulk(_records: TrackUsageOptions[]): Promise<UsageRecord[]> {\n throw new UsageOperationUnsupportedError('trackBulk', legacyGuidance('trackUsage() per record'));\n }\n}\n\nexport {\n BillingUsageClient,\n type BillingUsageClientConfig,\n type BillingUsageOperationInput,\n type OrgBillingUsageOperationInput,\n type WorkspaceBillingUsageOperationInput,\n type QuotaLimit,\n} from './billing.js';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkCA,MAAM,6BAA6B;;AAGnC,MAAM,mCAAmC;;AAGzC,MAAM,gCAAgC;AAEtC,MAAM,0BAA0B;;;;;;;AAQhC,MAAM,oCAAoC;;;;;;;AAQ1C,MAAM,oBAAoB;;;;;;;;;;;;;AAc1B,MAAM,qBAAqB;;;;;;;;;;;;;;;;;;;;;;;AAwB3B,MAAM,wBAAwB;;;;;;;;;;;;AAa9B,MAAM,yBAAyB;;;;;;;;;;;;;;;;;;;;;;;AA+G/B,SAAS,OAAc,MAAgC;CACrD,IAAI,CAAC,MACH,MAAM,IAAI,MAAM,uCAAuC;CAEzD,OAAO;AACT;;;;;;;AAQA,IAAa,qBAAb,MAAgC;CAC9B,AAAiB;CACjB,AAAiB;CACjB,AAAiB;CAIjB,AAAiB,kCAAkB,IAAI,IAA8B;CAErE,YAAY,QAAkC;EAC5C,IAAI,CAAC,OAAO,aACV,MAAM,IAAI,UAAU,2CAA2C;EAEjE,KAAK,gBACH,OAAO,iBACP,IAAI,cAAc;GAChB,OAAO;GACP,aAAa,OAAO;GACpB,SAAS,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ACkB;EAClB,MAAM,IAAI,+BAA+B,cAAc,8CAA8C;CACvG;;;;CAKA,MAAa,YACX,WACA,aACA,aACkB;EAClB,MAAM,IAAI,+BAA+B,eAAe,yDAAyD;CACnH;;;;CAKA,MAAa,UAAU,UAAuD;EAC5E,MAAM,IAAI,+BAA+B,aAAa,eAAe,yBAAyB,CAAC;CACjG;AACF"}
@@ -1 +1,2 @@
1
- export { c as chunk, a as compileValidatedPattern, d as debounce, b as deepMerge, f as formatBytes, g as generateUUID, e as groupBy, h as isNumberInRange, j as isStringLengthValid, k as isTokenExpired, l as isValidBase64, m as isValidEmail, n as isValidHexColor, o as isValidIPv4, p as isValidJSON, q as isValidPhone, r as isValidRegexPattern, s as isValidSlug, t as isValidUUID, u as isValidUrl, v as omit, w as parseJWT, x as pick, y as retry, z as sanitizeForLog, A as sleep, B as throttle, C as truncate, D as unique } from '../index-PaojfSdd.js';
1
+ import { A as isValidUrl, C as isValidHexColor, D as isValidRegexPattern, E as isValidPhone, O as isValidSlug, S as isValidEmail, T as isValidJSON, _ as unique, a as generateUUID, b as isStringLengthValid, c as isTokenExpired, d as pick, f as retry, g as truncate, h as throttle, i as formatBytes, k as isValidUUID, l as omit, m as sleep, n as debounce, o as groupBy, p as sanitizeForLog, r as deepMerge, t as chunk, u as parseJWT, v as compileValidatedPattern, w as isValidIPv4, x as isValidBase64, y as isNumberInRange } from "../index-FKohsiex.js";
2
+ export { chunk, compileValidatedPattern, debounce, deepMerge, formatBytes, generateUUID, groupBy, isNumberInRange, isStringLengthValid, isTokenExpired, isValidBase64, isValidEmail, isValidHexColor, isValidIPv4, isValidJSON, isValidPhone, isValidRegexPattern, isValidSlug, isValidUUID, isValidUrl, omit, parseJWT, pick, retry, sanitizeForLog, sleep, throttle, truncate, unique };
@@ -1,4 +1,4 @@
1
- export { chunk, compileValidatedPattern, debounce, deepMerge, formatBytes, generateUUID, groupBy, isNumberInRange, isStringLengthValid, isTokenExpired, isValidBase64, isValidEmail, isValidHexColor, isValidIPv4, isValidJSON, isValidPhone, isValidRegexPattern, isValidSlug, isValidUUID, isValidUrl, omit, parseJWT, pick, retry, sanitizeForLog, sleep, throttle, truncate, unique } from '../chunk-LA5KPWZ2.js';
2
- import '../chunk-XE4OXN2W.js';
1
+ import { A as isValidUrl, C as isValidHexColor, D as isValidRegexPattern, E as isValidPhone, O as isValidSlug, S as isValidEmail, T as isValidJSON, a as generateUUID, b as isStringLengthValid, c as omit, d as retry, f as sanitizeForLog, g as unique, h as truncate, i as formatBytes, k as isValidUUID, l as parseJWT, m as throttle, n as debounce, o as groupBy, p as sleep, r as deepMerge, s as isTokenExpired, t as chunk, u as pick, v as compileValidatedPattern, w as isValidIPv4, x as isValidBase64, y as isNumberInRange } from "../utils-DL85Tnbn.js";
2
+
3
+ export { chunk, compileValidatedPattern, debounce, deepMerge, formatBytes, generateUUID, groupBy, isNumberInRange, isStringLengthValid, isTokenExpired, isValidBase64, isValidEmail, isValidHexColor, isValidIPv4, isValidJSON, isValidPhone, isValidRegexPattern, isValidSlug, isValidUUID, isValidUrl, omit, parseJWT, pick, retry, sanitizeForLog, sleep, throttle, truncate, unique };
3
4
  //# sourceMappingURL=index.js.map
4
- //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":[],"names":[],"mappings":"","file":"index.js"}
1
+ {"version":3,"file":"index.js","sources":[],"names":[],"mappings":""}
@@ -0,0 +1,500 @@
1
+ import { t as __exportAll } from "./rolldown-runtime-ad2WFvuA.js";
2
+
3
+ // src/utils/validation.ts
4
+ /**
5
+ * Validation utilities
6
+ *
7
+ * Provides secure, robust validation functions for common data types.
8
+ */
9
+ /**
10
+ * Validate email format with enhanced security and edge case handling
11
+ *
12
+ * Features:
13
+ * - Optimized regex that avoids catastrophic backtracking
14
+ * - Length validation (max 320 chars per RFC 5321)
15
+ * - Validates local-part@domain.tld format
16
+ * - Local part: alphanumeric, dots, hyphens, underscores (1-64 chars)
17
+ * - Domain: alphanumeric, dots, hyphens (1-253 chars)
18
+ * - TLD: alphabetic (2-63 chars)
19
+ *
20
+ * @param email - Email address to validate
21
+ * @returns true if email is valid, false otherwise
22
+ */
23
+ function isValidEmail(email) {
24
+ const emailRegex = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,63}$/;
25
+ if (!email || email.length > 320) return false;
26
+ return emailRegex.test(email);
27
+ }
28
+ /**
29
+ * Validate URL format
30
+ *
31
+ * Uses the built-in URL constructor for robust validation.
32
+ * Supports all standard URL schemes (http, https, ftp, etc.)
33
+ *
34
+ * @param url - URL string to validate
35
+ * @returns true if URL is valid, false otherwise
36
+ */
37
+ function isValidUrl(url) {
38
+ try {
39
+ new URL(url);
40
+ return true;
41
+ } catch {
42
+ return false;
43
+ }
44
+ }
45
+ /**
46
+ * Validate regex pattern to prevent ReDoS attacks
47
+ *
48
+ * This method only validates, it does NOT compile the RegExp.
49
+ * Use compileValidatedPattern() to safely compile after validation.
50
+ *
51
+ * Security checks:
52
+ * 1. Pattern is not empty or whitespace-only
53
+ * 2. Pattern length is reasonable (<= 1000 chars) to prevent DoS
54
+ * 3. Pattern can be successfully compiled (syntax check)
55
+ *
56
+ * @param pattern - Regular expression pattern to validate
57
+ * @returns true if pattern is valid and safe, false otherwise
58
+ */
59
+ function isValidRegexPattern(pattern) {
60
+ if (!pattern || pattern.trim().length === 0) return false;
61
+ if (pattern.length > 1e3) return false;
62
+ try {
63
+ new RegExp(pattern);
64
+ return true;
65
+ } catch {
66
+ return false;
67
+ }
68
+ }
69
+ /**
70
+ * Safely compile a validation pattern to RegExp after validation
71
+ *
72
+ * Returns null if the pattern is invalid.
73
+ *
74
+ * SECURITY: This method provides protection against ReDoS attacks by:
75
+ * 1. Validating pattern isn't empty or null
76
+ * 2. Rejecting patterns >1000 chars (prevents DoS via catastrophic backtracking)
77
+ * 3. Testing compilation in try-catch to handle malformed patterns
78
+ * 4. Only compiling patterns that pass all validation checks
79
+ *
80
+ * @param pattern - Regular expression pattern to compile
81
+ * @returns Compiled RegExp or null if pattern is invalid
82
+ */
83
+ function compileValidatedPattern(pattern) {
84
+ if (!isValidRegexPattern(pattern)) return null;
85
+ try {
86
+ return new RegExp(pattern);
87
+ } catch {
88
+ return null;
89
+ }
90
+ }
91
+ /**
92
+ * Validate phone number format
93
+ *
94
+ * Validates international phone numbers in E.164 format.
95
+ * Format: +[country code][number] (e.g., +14155552671)
96
+ *
97
+ * Requirements:
98
+ * - Starts with +
99
+ * - Followed by 1-3 digit country code
100
+ * - Followed by 4-14 digits
101
+ * - Total length: 6-18 characters
102
+ *
103
+ * @param phone - Phone number to validate
104
+ * @returns true if phone is valid E.164 format, false otherwise
105
+ */
106
+ function isValidPhone(phone) {
107
+ const phoneRegex = /^\+[1-9]\d{1,14}$/;
108
+ if (!phone || phone.length < 6 || phone.length > 18) return false;
109
+ return phoneRegex.test(phone);
110
+ }
111
+ /**
112
+ * Validate UUID format (v4)
113
+ *
114
+ * Validates UUIDs in the standard format:
115
+ * xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx
116
+ *
117
+ * @param uuid - UUID string to validate
118
+ * @returns true if UUID is valid v4 format, false otherwise
119
+ */
120
+ function isValidUUID(uuid) {
121
+ return /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(uuid);
122
+ }
123
+ /**
124
+ * Validate IPv4 address format
125
+ *
126
+ * Validates IPv4 addresses in dotted decimal notation.
127
+ * Format: xxx.xxx.xxx.xxx where each xxx is 0-255
128
+ *
129
+ * @param ip - IP address to validate
130
+ * @returns true if IP is valid IPv4, false otherwise
131
+ */
132
+ function isValidIPv4(ip) {
133
+ const match = /^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/.exec(ip);
134
+ if (!match) return false;
135
+ for (let i = 1; i <= 4; i++) {
136
+ const octet = parseInt(match[i] || "0", 10);
137
+ if (octet < 0 || octet > 255) return false;
138
+ }
139
+ return true;
140
+ }
141
+ /**
142
+ * Validate slug format
143
+ *
144
+ * Slugs are URL-friendly strings used in paths.
145
+ * Requirements:
146
+ * - Lowercase letters, numbers, hyphens only
147
+ * - Must start and end with alphanumeric
148
+ * - No consecutive hyphens
149
+ * - Length: 1-100 characters
150
+ *
151
+ * @param slug - Slug to validate
152
+ * @returns true if slug is valid, false otherwise
153
+ */
154
+ function isValidSlug(slug) {
155
+ if (!slug || slug.length < 1 || slug.length > 100) return false;
156
+ if (!/^[a-z0-9-]+$/.test(slug)) return false;
157
+ if (slug.startsWith("-") || slug.endsWith("-")) return false;
158
+ if (slug.includes("--")) return false;
159
+ return true;
160
+ }
161
+ /**
162
+ * Validate hex color code
163
+ *
164
+ * Validates hex color codes in formats:
165
+ * - #RGB (e.g., #f0f)
166
+ * - #RRGGBB (e.g., #ff00ff)
167
+ * - #RRGGBBAA (e.g., #ff00ff80)
168
+ *
169
+ * @param color - Hex color code to validate
170
+ * @returns true if color is valid hex, false otherwise
171
+ */
172
+ function isValidHexColor(color) {
173
+ return /^#([0-9a-f]{3}|[0-9a-f]{6}|[0-9a-f]{8})$/i.test(color);
174
+ }
175
+ /**
176
+ * Validate base64 string
177
+ *
178
+ * Validates base64-encoded strings.
179
+ * Supports both standard and URL-safe base64.
180
+ *
181
+ * @param str - String to validate
182
+ * @returns true if string is valid base64, false otherwise
183
+ */
184
+ function isValidBase64(str) {
185
+ if (!str || str.length === 0) return false;
186
+ if (!/^[A-Za-z0-9+/\-_]+=*$/.test(str)) return false;
187
+ try {
188
+ return Buffer.from(str, "base64").toString("base64") === str;
189
+ } catch {
190
+ return false;
191
+ }
192
+ }
193
+ /**
194
+ * Validate JSON string
195
+ *
196
+ * Validates that a string contains valid JSON.
197
+ * Does not parse the JSON, only validates syntax.
198
+ *
199
+ * @param str - String to validate
200
+ * @returns true if string is valid JSON, false otherwise
201
+ */
202
+ function isValidJSON(str) {
203
+ try {
204
+ JSON.parse(str);
205
+ return true;
206
+ } catch {
207
+ return false;
208
+ }
209
+ }
210
+ /**
211
+ * Validate number is within range
212
+ *
213
+ * @param value - Number to validate
214
+ * @param min - Minimum value (inclusive), or null for no minimum
215
+ * @param max - Maximum value (inclusive), or null for no maximum
216
+ * @returns true if number is within range, false otherwise
217
+ */
218
+ function isNumberInRange(value, min, max) {
219
+ if (typeof value !== "number" || isNaN(value)) return false;
220
+ if (min !== null && value < min) return false;
221
+ if (max !== null && value > max) return false;
222
+ return true;
223
+ }
224
+ /**
225
+ * Validate string length is within range
226
+ *
227
+ * @param value - String to validate
228
+ * @param min - Minimum length (inclusive), or null for no minimum
229
+ * @param max - Maximum length (inclusive), or null for no maximum
230
+ * @returns true if string length is within range, false otherwise
231
+ */
232
+ function isStringLengthValid(value, min, max) {
233
+ if (typeof value !== "string") return false;
234
+ const length = value.length;
235
+ if (min !== null && length < min) return false;
236
+ if (max !== null && length > max) return false;
237
+ return true;
238
+ }
239
+
240
+ // src/utils/index.ts
241
+ var utils_exports = /* @__PURE__ */ __exportAll({
242
+ chunk: () => chunk,
243
+ compileValidatedPattern: () => compileValidatedPattern,
244
+ debounce: () => debounce,
245
+ deepMerge: () => deepMerge,
246
+ formatBytes: () => formatBytes,
247
+ generateUUID: () => generateUUID,
248
+ groupBy: () => groupBy,
249
+ isNumberInRange: () => isNumberInRange,
250
+ isStringLengthValid: () => isStringLengthValid,
251
+ isTokenExpired: () => isTokenExpired,
252
+ isValidBase64: () => isValidBase64,
253
+ isValidEmail: () => isValidEmail,
254
+ isValidHexColor: () => isValidHexColor,
255
+ isValidIPv4: () => isValidIPv4,
256
+ isValidJSON: () => isValidJSON,
257
+ isValidPhone: () => isValidPhone,
258
+ isValidRegexPattern: () => isValidRegexPattern,
259
+ isValidSlug: () => isValidSlug,
260
+ isValidUUID: () => isValidUUID,
261
+ isValidUrl: () => isValidUrl,
262
+ omit: () => omit,
263
+ parseJWT: () => parseJWT,
264
+ pick: () => pick,
265
+ retry: () => retry,
266
+ sanitizeForLog: () => sanitizeForLog,
267
+ sleep: () => sleep,
268
+ throttle: () => throttle,
269
+ truncate: () => truncate,
270
+ unique: () => unique
271
+ });
272
+ /**
273
+ * Utility functions for the SDK
274
+ */
275
+ const uuidv4 = () => crypto.randomUUID();
276
+ /**
277
+ * Retry function with exponential backoff
278
+ */
279
+ async function retry(fn, options) {
280
+ let lastError;
281
+ let delay = options.initialDelay;
282
+ for (let attempt = 1; attempt <= options.maxAttempts; attempt++) try {
283
+ return await fn();
284
+ } catch (error) {
285
+ lastError = error;
286
+ if (attempt === options.maxAttempts) break;
287
+ await sleep(Math.min(delay, options.maxDelay));
288
+ delay *= options.backoffMultiplier;
289
+ }
290
+ throw lastError || /* @__PURE__ */ new Error("Retry failed");
291
+ }
292
+ /**
293
+ * Sleep utility
294
+ */
295
+ function sleep(ms) {
296
+ return new Promise((resolve) => setTimeout(resolve, ms));
297
+ }
298
+ /**
299
+ * Deep merge two objects
300
+ */
301
+ function deepMerge(target, source) {
302
+ const output = { ...target };
303
+ for (const key in source) if (Object.prototype.hasOwnProperty.call(source, key)) {
304
+ const sourceValue = source[key];
305
+ const targetValue = Object.hasOwn(output, key) ? output[key] : void 0;
306
+ if (isObject(sourceValue) && isObject(targetValue)) Object.defineProperty(output, key, {
307
+ value: deepMerge(targetValue, sourceValue),
308
+ enumerable: true,
309
+ writable: true,
310
+ configurable: true
311
+ });
312
+ else Object.defineProperty(output, key, {
313
+ value: sourceValue,
314
+ enumerable: true,
315
+ writable: true,
316
+ configurable: true
317
+ });
318
+ }
319
+ return output;
320
+ }
321
+ /**
322
+ * Check if value is a plain object
323
+ */
324
+ function isObject(value) {
325
+ return value !== null && typeof value === "object" && !Array.isArray(value);
326
+ }
327
+ /**
328
+ * Generate UUID v4 (cryptographically secure)
329
+ */
330
+ function generateUUID() {
331
+ return uuidv4();
332
+ }
333
+ /**
334
+ * Sanitize string for logging (remove sensitive data)
335
+ */
336
+ function sanitizeForLog(data) {
337
+ const sensitiveKeys = [
338
+ "password",
339
+ "token",
340
+ "secret",
341
+ "apiKey",
342
+ "accessToken",
343
+ "refreshToken"
344
+ ];
345
+ const ancestors = /* @__PURE__ */ new WeakSet();
346
+ function sanitizeValue(value) {
347
+ if (Array.isArray(value)) {
348
+ if (ancestors.has(value)) return "[Circular]";
349
+ ancestors.add(value);
350
+ const sanitized = value.map(sanitizeValue);
351
+ ancestors.delete(value);
352
+ return sanitized;
353
+ }
354
+ return isObject(value) ? sanitizeObject(value) : value;
355
+ }
356
+ function sanitizeObject(value) {
357
+ ancestors.add(value);
358
+ const sanitized = {};
359
+ for (const [key, item] of Object.entries(value)) {
360
+ const sensitive = sensitiveKeys.some((name) => key.toLowerCase().includes(name.toLowerCase()));
361
+ const circular = typeof item === "object" && item !== null && ancestors.has(item);
362
+ let sanitizedValue;
363
+ if (sensitive) sanitizedValue = "[REDACTED]";
364
+ else if (circular) sanitizedValue = "[Circular]";
365
+ else sanitizedValue = sanitizeValue(item);
366
+ Object.defineProperty(sanitized, key, {
367
+ value: sanitizedValue,
368
+ enumerable: true,
369
+ writable: true,
370
+ configurable: true
371
+ });
372
+ }
373
+ ancestors.delete(value);
374
+ return sanitized;
375
+ }
376
+ return sanitizeObject(data);
377
+ }
378
+ /**
379
+ * Debounce function
380
+ */
381
+ function debounce(fn, delay) {
382
+ let timeoutId;
383
+ return function(...args) {
384
+ if (timeoutId) clearTimeout(timeoutId);
385
+ timeoutId = setTimeout(() => {
386
+ fn.apply(this, args);
387
+ }, delay);
388
+ };
389
+ }
390
+ /**
391
+ * Throttle function
392
+ */
393
+ function throttle(fn, delay) {
394
+ let lastCall = 0;
395
+ return function(...args) {
396
+ const now = Date.now();
397
+ if (now - lastCall >= delay) {
398
+ lastCall = now;
399
+ fn.apply(this, args);
400
+ }
401
+ };
402
+ }
403
+ /**
404
+ * Parse JWT token (without verification)
405
+ */
406
+ function parseJWT(token) {
407
+ try {
408
+ const parts = token.split(".");
409
+ if (parts.length !== 3) return null;
410
+ const payload = parts[1];
411
+ if (!payload) return null;
412
+ const decoded = Buffer.from(payload, "base64").toString("utf8");
413
+ return JSON.parse(decoded);
414
+ } catch {
415
+ return null;
416
+ }
417
+ }
418
+ /**
419
+ * Check if JWT token is expired
420
+ */
421
+ function isTokenExpired(token) {
422
+ const payload = parseJWT(token);
423
+ if (!payload || typeof payload["exp"] !== "number") return true;
424
+ const now = Math.floor(Date.now() / 1e3);
425
+ return payload["exp"] < now;
426
+ }
427
+ /**
428
+ * Format bytes to human readable string
429
+ */
430
+ function formatBytes(bytes, decimals = 2) {
431
+ if (bytes === 0) return "0 Bytes";
432
+ const k = 1024;
433
+ const dm = decimals < 0 ? 0 : decimals;
434
+ const sizes = [
435
+ "Bytes",
436
+ "KB",
437
+ "MB",
438
+ "GB",
439
+ "TB"
440
+ ];
441
+ const i = Math.floor(Math.log(bytes) / Math.log(k));
442
+ return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + " " + sizes[i];
443
+ }
444
+ /**
445
+ * Truncate string with ellipsis
446
+ */
447
+ function truncate(str, maxLength) {
448
+ if (str.length <= maxLength) return str;
449
+ return str.substring(0, maxLength - 3) + "...";
450
+ }
451
+ /**
452
+ * Chunk array into smaller arrays
453
+ */
454
+ function chunk(array, size) {
455
+ const chunks = [];
456
+ for (let i = 0; i < array.length; i += size) chunks.push(array.slice(i, i + size));
457
+ return chunks;
458
+ }
459
+ /**
460
+ * Remove duplicates from array
461
+ */
462
+ function unique(array) {
463
+ return Array.from(new Set(array));
464
+ }
465
+ /**
466
+ * Group array by key
467
+ */
468
+ function groupBy(array, key) {
469
+ return array.reduce((result, item) => {
470
+ const groupKey = String(item[key]);
471
+ const existing = Object.hasOwn(result, groupKey) ? result[groupKey] : void 0;
472
+ if (existing) existing.push(item);
473
+ else Object.defineProperty(result, groupKey, {
474
+ value: [item],
475
+ enumerable: true,
476
+ writable: true,
477
+ configurable: true
478
+ });
479
+ return result;
480
+ }, {});
481
+ }
482
+ /**
483
+ * Pick specific keys from object
484
+ */
485
+ function pick(obj, keys) {
486
+ const result = {};
487
+ for (const key of keys) if (key in obj) result[key] = obj[key];
488
+ return result;
489
+ }
490
+ /**
491
+ * Omit specific keys from object
492
+ */
493
+ function omit(obj, keys) {
494
+ const result = { ...obj };
495
+ for (const key of keys) delete result[key];
496
+ return result;
497
+ }
498
+
499
+ export { isValidUrl as A, isValidHexColor as C, isValidRegexPattern as D, isValidPhone as E, isValidSlug as O, isValidEmail as S, isValidJSON as T, utils_exports as _, generateUUID as a, isStringLengthValid as b, omit as c, retry as d, sanitizeForLog as f, unique as g, truncate as h, formatBytes as i, isValidUUID as k, parseJWT as l, throttle as m, debounce as n, groupBy as o, sleep as p, deepMerge as r, isTokenExpired as s, chunk as t, pick as u, compileValidatedPattern as v, isValidIPv4 as w, isValidBase64 as x, isNumberInRange as y };
500
+ //# sourceMappingURL=utils-DL85Tnbn.js.map