@burdenoff/be-sdk 2026.1110.2 → 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-GXC3A7DH.js +0 -8
  299. package/dist/EventQueueFactory-GXC3A7DH.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-A5F6Z5UE.js +0 -21
  313. package/dist/chunk-A5F6Z5UE.js.map +0 -1
  314. package/dist/chunk-A6DE32ZS.js +0 -1507
  315. package/dist/chunk-A6DE32ZS.js.map +0 -1
  316. package/dist/chunk-AXJDGQPE.js +0 -690
  317. package/dist/chunk-AXJDGQPE.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-DRWH5XCJ.js +0 -876
  323. package/dist/chunk-DRWH5XCJ.js.map +0 -1
  324. package/dist/chunk-E4QNLVY4.js +0 -909
  325. package/dist/chunk-E4QNLVY4.js.map +0 -1
  326. package/dist/chunk-EBDHIL7V.js +0 -774
  327. package/dist/chunk-EBDHIL7V.js.map +0 -1
  328. package/dist/chunk-ELU7VL3E.js +0 -245
  329. package/dist/chunk-ELU7VL3E.js.map +0 -1
  330. package/dist/chunk-FZRODKIN.js +0 -31
  331. package/dist/chunk-FZRODKIN.js.map +0 -1
  332. package/dist/chunk-GCIB76AJ.js +0 -882
  333. package/dist/chunk-GCIB76AJ.js.map +0 -1
  334. package/dist/chunk-HC6MPUIH.js +0 -1571
  335. package/dist/chunk-HC6MPUIH.js.map +0 -1
  336. package/dist/chunk-HNMHPSAM.js +0 -272
  337. package/dist/chunk-HNMHPSAM.js.map +0 -1
  338. package/dist/chunk-HTLEGD3Q.js +0 -1480
  339. package/dist/chunk-HTLEGD3Q.js.map +0 -1
  340. package/dist/chunk-I3KOWRT3.js +0 -89
  341. package/dist/chunk-I3KOWRT3.js.map +0 -1
  342. package/dist/chunk-ID3WR4JS.js +0 -509
  343. package/dist/chunk-ID3WR4JS.js.map +0 -1
  344. package/dist/chunk-JS52ZHTK.js +0 -1346
  345. package/dist/chunk-JS52ZHTK.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-KH4TRQCO.js +0 -1063
  349. package/dist/chunk-KH4TRQCO.js.map +0 -1
  350. package/dist/chunk-KJOSPVB2.js +0 -57
  351. package/dist/chunk-KJOSPVB2.js.map +0 -1
  352. package/dist/chunk-KO2ZXZ7W.js +0 -61
  353. package/dist/chunk-KO2ZXZ7W.js.map +0 -1
  354. package/dist/chunk-KS2HQCJR.js +0 -56
  355. package/dist/chunk-KS2HQCJR.js.map +0 -1
  356. package/dist/chunk-LA5KPWZ2.js +0 -413
  357. package/dist/chunk-LA5KPWZ2.js.map +0 -1
  358. package/dist/chunk-MESLAC5W.js +0 -574
  359. package/dist/chunk-MESLAC5W.js.map +0 -1
  360. package/dist/chunk-MWPYA2HD.js +0 -94
  361. package/dist/chunk-MWPYA2HD.js.map +0 -1
  362. package/dist/chunk-NUB5GQTU.js +0 -270
  363. package/dist/chunk-NUB5GQTU.js.map +0 -1
  364. package/dist/chunk-OBBCR6WY.js +0 -277
  365. package/dist/chunk-OBBCR6WY.js.map +0 -1
  366. package/dist/chunk-OQDSAOG3.js +0 -1908
  367. package/dist/chunk-OQDSAOG3.js.map +0 -1
  368. package/dist/chunk-OXNCBE7P.js +0 -971
  369. package/dist/chunk-OXNCBE7P.js.map +0 -1
  370. package/dist/chunk-PBZFAAOM.js +0 -941
  371. package/dist/chunk-PN6GIF3R.js +0 -1185
  372. package/dist/chunk-PN6GIF3R.js.map +0 -1
  373. package/dist/chunk-PYD44IHJ.js +0 -728
  374. package/dist/chunk-PYD44IHJ.js.map +0 -1
  375. package/dist/chunk-QVPIACWD.js +0 -679
  376. package/dist/chunk-QVPIACWD.js.map +0 -1
  377. package/dist/chunk-QWNNFE4P.js +0 -41
  378. package/dist/chunk-QWNNFE4P.js.map +0 -1
  379. package/dist/chunk-RU266375.js +0 -327
  380. package/dist/chunk-RU266375.js.map +0 -1
  381. package/dist/chunk-RYTSVGGA.js +0 -1624
  382. package/dist/chunk-RYTSVGGA.js.map +0 -1
  383. package/dist/chunk-RZOFS2BQ.js +0 -225
  384. package/dist/chunk-RZOFS2BQ.js.map +0 -1
  385. package/dist/chunk-SBS4S2PJ.js +0 -100
  386. package/dist/chunk-SBS4S2PJ.js.map +0 -1
  387. package/dist/chunk-SPRG6G6G.js +0 -530
  388. package/dist/chunk-SPRG6G6G.js.map +0 -1
  389. package/dist/chunk-STWFX5E2.js +0 -233
  390. package/dist/chunk-STWFX5E2.js.map +0 -1
  391. package/dist/chunk-UNASM5VJ.js +0 -419
  392. package/dist/chunk-UNASM5VJ.js.map +0 -1
  393. package/dist/chunk-VAT66FJA.js +0 -245
  394. package/dist/chunk-VAT66FJA.js.map +0 -1
  395. package/dist/chunk-VFCMR5GX.js +0 -49
  396. package/dist/chunk-VFCMR5GX.js.map +0 -1
  397. package/dist/chunk-VGAHZKNJ.js +0 -66
  398. package/dist/chunk-VGAHZKNJ.js.map +0 -1
  399. package/dist/chunk-VTJTAAXC.js +0 -627
  400. package/dist/chunk-VTJTAAXC.js.map +0 -1
  401. package/dist/chunk-VXVLKRU6.js +0 -758
  402. package/dist/chunk-VXVLKRU6.js.map +0 -1
  403. package/dist/chunk-WWUU5ETI.js +0 -163
  404. package/dist/chunk-WWUU5ETI.js.map +0 -1
  405. package/dist/chunk-XE4OXN2W.js +0 -10
  406. package/dist/chunk-XE4OXN2W.js.map +0 -1
  407. package/dist/chunk-XOJORS75.js +0 -1853
  408. package/dist/chunk-XOJORS75.js.map +0 -1
  409. package/dist/chunk-YMZEUTD2.js +0 -110
  410. package/dist/chunk-YMZEUTD2.js.map +0 -1
  411. package/dist/chunk-Z77BTSOK.js +0 -617
  412. package/dist/chunk-Z77BTSOK.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,1486 @@
1
+ import { c as ValidationError, i as PermissionDeniedError } from "./types-Cj2RWXbz.js";
2
+ import { a as logger } from "./logger-B6rCpb7D.js";
3
+ import { i as DEFAULT_LAYER_RESOURCES, r as DEFAULT_GATEWAY_ROUTING } from "./layer-Bcix-WCl.js";
4
+ import { GraphQLClient } from "graphql-request";
5
+ import { GraphQLError } from "graphql";
6
+
7
+ // src/rbac/directive.ts
8
+ /**
9
+ * Simple LRU cache for permission checks
10
+ */
11
+ var LRUCache = class {
12
+ cache = /* @__PURE__ */ new Map();
13
+ maxSize;
14
+ ttl;
15
+ constructor(maxSize, ttl) {
16
+ this.maxSize = maxSize;
17
+ this.ttl = ttl;
18
+ }
19
+ get(key) {
20
+ const entry = this.cache.get(key);
21
+ if (!entry) return void 0;
22
+ if (Date.now() > entry.expiry) {
23
+ this.cache.delete(key);
24
+ return;
25
+ }
26
+ this.cache.delete(key);
27
+ this.cache.set(key, entry);
28
+ return entry.value;
29
+ }
30
+ set(key, value) {
31
+ if (this.cache.size >= this.maxSize) {
32
+ const firstKey = this.cache.keys().next().value;
33
+ if (firstKey !== void 0) this.cache.delete(firstKey);
34
+ }
35
+ this.cache.set(key, {
36
+ value,
37
+ expiry: Date.now() + this.ttl
38
+ });
39
+ }
40
+ clear() {
41
+ this.cache.clear();
42
+ }
43
+ /**
44
+ * Invalidate all entries whose key starts with the given prefix.
45
+ * Used to evict all cached permissions for a specific actor.
46
+ */
47
+ invalidateByPrefix(prefix) {
48
+ let count = 0;
49
+ for (const key of [...this.cache.keys()]) if (typeof key === "string" && key.startsWith(prefix)) {
50
+ this.cache.delete(key);
51
+ count++;
52
+ }
53
+ return count;
54
+ }
55
+ };
56
+ /**
57
+ * RBAC service client for permission checks
58
+ */
59
+ var RBACClient = class {
60
+ client;
61
+ cache;
62
+ config;
63
+ /**
64
+ * Per-request timeout (ms) for the RBAC service call.
65
+ * Bounds each checkPermission so a slow/cold RBAC gateway cannot hang the
66
+ * request indefinitely (previously the federation gateway killed the hung
67
+ * call at ~90s → 502). Defaults to 5000ms (matches RBACDirectiveConfig.timeout).
68
+ */
69
+ timeoutMs;
70
+ constructor(config) {
71
+ this.client = new GraphQLClient(config.rbacServiceUrl);
72
+ this.timeoutMs = config.timeout ?? 5e3;
73
+ this.config = {
74
+ failClosed: config.failClosed !== false,
75
+ layer: config.layer || "wspace"
76
+ };
77
+ if (config.enableCaching !== false) this.cache = new LRUCache(config.cacheMaxSize || 1e4, config.cacheTTL || 6e4);
78
+ }
79
+ /**
80
+ * Parse permission string into resourceType and action
81
+ * @example "project:read" => { resourceType: "project", action: "read" }
82
+ * @example "rbac:role:create" => { resourceType: "rbac", action: "role:create" }
83
+ */
84
+ parsePermission(permission) {
85
+ const colonIndex = permission.indexOf(":");
86
+ if (colonIndex === -1) return {
87
+ resourceType: permission,
88
+ action: "read"
89
+ };
90
+ return {
91
+ resourceType: permission.substring(0, colonIndex),
92
+ action: permission.substring(colonIndex + 1)
93
+ };
94
+ }
95
+ /**
96
+ * Check if actor has permission using the new PBAC checkPermission query
97
+ */
98
+ async checkPermission(actorId, actorType, scopeId, permission, resourceId) {
99
+ const { resourceType, action } = this.parsePermission(permission);
100
+ const cacheKey = `${actorId}:${actorType}:${scopeId}:${resourceType}:${action}:${resourceId || ""}`;
101
+ if (this.cache) {
102
+ const cached = this.cache.get(cacheKey);
103
+ if (cached !== void 0) {
104
+ logger.debug("[RBAC Directive] Cache hit", {
105
+ actorId,
106
+ actorType,
107
+ scopeId,
108
+ resourceType,
109
+ action,
110
+ resourceId,
111
+ hasPermission: cached
112
+ });
113
+ return {
114
+ hasPermission: cached,
115
+ reason: cached ? "Cached: Permission granted" : "Cached: Permission denied"
116
+ };
117
+ }
118
+ }
119
+ const CHECK_PERMISSION_QUERY = `
120
+ query CheckPermission($input: PermissionCheckInput!) {
121
+ checkPermission(input: $input) {
122
+ allowed
123
+ decisionPath
124
+ roleName
125
+ roleLevel
126
+ overrideType
127
+ }
128
+ }
129
+ `;
130
+ const input = {
131
+ actorId,
132
+ actorType,
133
+ scopeId,
134
+ resourceType,
135
+ action,
136
+ resourceId
137
+ };
138
+ try {
139
+ logger.debug("[RBAC Directive] Checking permission via RBAC service (PBAC)", {
140
+ input,
141
+ layer: this.config.layer
142
+ });
143
+ const result = await this.client.request({
144
+ document: CHECK_PERMISSION_QUERY,
145
+ variables: { input },
146
+ signal: AbortSignal.timeout(this.timeoutMs)
147
+ });
148
+ const hasPermission = result.checkPermission.allowed;
149
+ const decisionPath = result.checkPermission.decisionPath;
150
+ if (this.cache) this.cache.set(cacheKey, hasPermission);
151
+ logger.debug("[RBAC Directive] Permission check result", {
152
+ actorId,
153
+ resourceType,
154
+ action,
155
+ hasPermission,
156
+ decisionPath
157
+ });
158
+ return {
159
+ hasPermission,
160
+ reason: decisionPath
161
+ };
162
+ } catch (error) {
163
+ logger.error("[RBAC Directive] RBAC service error", {
164
+ error,
165
+ input,
166
+ layer: this.config.layer
167
+ });
168
+ if (this.config.failClosed) return {
169
+ hasPermission: false,
170
+ reason: "RBAC service unavailable - access denied (fail-closed)"
171
+ };
172
+ else {
173
+ logger.warn("[RBAC Directive] Fail-open mode: allowing access despite RBAC error");
174
+ return {
175
+ hasPermission: true,
176
+ reason: "RBAC service unavailable - access allowed (fail-open)"
177
+ };
178
+ }
179
+ }
180
+ }
181
+ /**
182
+ * Clear permission cache (useful for testing or when permissions change)
183
+ */
184
+ clearCache() {
185
+ this.cache?.clear();
186
+ }
187
+ /**
188
+ * Invalidate cached permissions for a specific actor.
189
+ * Call this when an actor's roles or permissions change to avoid stale cache hits.
190
+ *
191
+ * @param actorId - The actor whose cached permissions should be evicted
192
+ * @returns Number of cache entries invalidated
193
+ */
194
+ invalidateForActor(actorId) {
195
+ if (!this.cache) return 0;
196
+ const count = this.cache.invalidateByPrefix(`${actorId}:`);
197
+ if (count > 0) logger.info("[RBAC Directive] Invalidated cached permissions for actor", {
198
+ actorId,
199
+ entriesRemoved: count
200
+ });
201
+ return count;
202
+ }
203
+ /**
204
+ * Get the configured layer
205
+ */
206
+ getLayer() {
207
+ return this.config.layer;
208
+ }
209
+ };
210
+ /**
211
+ * Extract value from nested object path
212
+ * @example getValueAtPath({ input: { id: '123' } }, 'input.id') => '123'
213
+ */
214
+ function getValueAtPath(obj, path) {
215
+ const parts = path.split(".");
216
+ let current = obj;
217
+ for (const part of parts) {
218
+ if (current === null || current === void 0) return;
219
+ if (typeof current !== "object") return;
220
+ current = current[part];
221
+ }
222
+ return typeof current === "string" ? current : void 0;
223
+ }
224
+ /**
225
+ * Extract directive argument value
226
+ */
227
+ function getDirectiveArgument(directive, name) {
228
+ const arg = directive.arguments?.find((a) => a.name.value === name);
229
+ if (arg && arg.value.kind === "StringValue") return arg.value.value;
230
+ }
231
+ /**
232
+ * Parse GraphQL arguments to plain object
233
+ */
234
+ function parseFieldArguments(field, variableValues) {
235
+ const args = {};
236
+ for (const arg of field.arguments || []) {
237
+ const argName = arg.name.value;
238
+ const argValue = arg.value;
239
+ if (argValue.kind === "Variable") args[argName] = variableValues[argValue.name.value];
240
+ else if (argValue.kind === "ObjectValue") args[argName] = parseObjectValue(argValue, variableValues);
241
+ else if ("value" in argValue) args[argName] = argValue.value;
242
+ }
243
+ return args;
244
+ }
245
+ /**
246
+ * Parse GraphQL object value to plain object
247
+ */
248
+ function parseObjectValue(obj, variableValues) {
249
+ const result = {};
250
+ for (const field of obj.fields || []) {
251
+ const fieldName = field.name.value;
252
+ const fieldValue = field.value;
253
+ if (fieldValue.kind === "Variable") result[fieldName] = variableValues[fieldValue.name.value];
254
+ else if (fieldValue.kind === "ObjectValue") result[fieldName] = parseObjectValue(fieldValue, variableValues);
255
+ else if ("value" in fieldValue) result[fieldName] = fieldValue.value;
256
+ }
257
+ return result;
258
+ }
259
+ /**
260
+ * Convert user ID to actor ID format
261
+ *
262
+ * NOTE: This function currently performs no transformation (identity function).
263
+ * It was added as an extension point for future actor ID transformations if needed.
264
+ *
265
+ * Historically, actor IDs used a different format (e.g., "actor:user-123"),
266
+ * but this was simplified to use user IDs directly for consistency.
267
+ *
268
+ * Keep this function in place to:
269
+ * 1. Maintain API compatibility with existing code
270
+ * 2. Provide a centralized point for future ID transformations
271
+ * 3. Make the ID transformation intent explicit in the code
272
+ *
273
+ * @param userId - User ID from context
274
+ * @returns Actor ID (currently identical to user ID)
275
+ * @example abc-123 => abc-123
276
+ */
277
+ function toActorId(userId) {
278
+ return userId;
279
+ }
280
+ /**
281
+ * Sanitize headers for logging (redact sensitive values)
282
+ * @param headers - Headers object to sanitize
283
+ * @returns Sanitized headers with sensitive values redacted
284
+ */
285
+ function sanitizeHeadersForLogging(headers) {
286
+ const sanitized = {};
287
+ for (const [key, value] of Object.entries(headers)) {
288
+ const lowerKey = key.toLowerCase();
289
+ if (lowerKey.includes("auth") || lowerKey.includes("token") || lowerKey.includes("password") || lowerKey.includes("secret") || lowerKey.includes("key") || lowerKey.includes("credential")) sanitized[key] = "***REDACTED***";
290
+ else sanitized[key] = value;
291
+ }
292
+ return sanitized;
293
+ }
294
+ /**
295
+ * Get header value from context (checks both request.headers and headers)
296
+ */
297
+ function getHeader(context, key) {
298
+ if (context.request?.headers) {
299
+ if (typeof context.request.headers.get === "function") {
300
+ const value = context.request.headers.get(key);
301
+ if (value) return value;
302
+ }
303
+ const value = context.request.headers[key];
304
+ if (value) return value;
305
+ }
306
+ if (context.headers) {
307
+ const value = context.headers[key];
308
+ if (value) return value;
309
+ }
310
+ }
311
+ /**
312
+ * Validate bypass timestamp to prevent replay attacks
313
+ * @param timestamp - Timestamp string in milliseconds
314
+ * @returns true if timestamp is fresh (< 1 minute old)
315
+ */
316
+ function validateBypassTimestamp(timestamp) {
317
+ try {
318
+ const timestampMs = parseInt(timestamp, 10);
319
+ if (isNaN(timestampMs)) return false;
320
+ const now = Date.now();
321
+ const age = now - timestampMs;
322
+ if (age > 6e4 || age < 0) {
323
+ logger.warn("[RBAC Directive] Stale bypass timestamp", {
324
+ age,
325
+ timestamp: timestampMs,
326
+ now
327
+ });
328
+ return false;
329
+ }
330
+ return true;
331
+ } catch (error) {
332
+ const errorMessage = error instanceof Error ? error.message : "Unknown error";
333
+ logger.warn("[RBAC Directive] Invalid bypass timestamp format", {
334
+ timestamp,
335
+ error: errorMessage
336
+ });
337
+ return false;
338
+ }
339
+ }
340
+ /**
341
+ * Check if request should bypass RBAC based on headers
342
+ * This is used for internal service-to-service communication
343
+ *
344
+ * ⚠️ ARCHITECTURE NOTE: Header Transformation Flow
345
+ * ================================================
346
+ * These headers are TRANSFORMED by the Internal API Gateway before reaching this directive.
347
+ *
348
+ * Flow:
349
+ * 1. Service A (internal-client.ts) → Internal API Gateway
350
+ * Headers sent: x-bypass-permission, x-service-identity, x-call-type
351
+ *
352
+ * 2. Internal API Gateway → Service B (this RBAC directive)
353
+ * Headers transformed to: x-rbac-bypass, x-bypass-source, x-bypass-timestamp
354
+ *
355
+ * This directive validates the TRANSFORMED headers from the gateway, not the original
356
+ * headers from the internal client. The mismatch between internal-client.ts:101-106
357
+ * and this function is INTENTIONAL and part of the security architecture.
358
+ *
359
+ * DO NOT "fix" internal-client.ts to send these headers - the gateway handles transformation.
360
+ *
361
+ * Headers required (after gateway transformation):
362
+ * - x-rbac-bypass: "true"
363
+ * - x-bypass-source: Service identity (e.g., "scheduler-service")
364
+ * - x-bypass-timestamp: Unix timestamp in milliseconds
365
+ *
366
+ * @param context - GraphQL context containing headers
367
+ * @returns Bypass check result with context for error reporting
368
+ */
369
+ function checkBypassHeaders(context) {
370
+ const actorType = getHeader(context, "x-actor-type");
371
+ const actorId = getHeader(context, "x-actor-id");
372
+ if (actorType === "service" || actorType === "super_admin") {
373
+ logger.debug("[RBAC Directive] Actor type bypass - service/super_admin", {
374
+ actorType,
375
+ actorId
376
+ });
377
+ return { shouldBypass: true };
378
+ }
379
+ logger.debug("[RBAC Directive] Checking bypass headers - context structure", {
380
+ hasRequest: !!context.request,
381
+ hasRequestHeaders: !!context.request?.headers,
382
+ hasContextHeaders: !!context.headers,
383
+ requestHeadersType: context.request?.headers ? typeof context.request.headers : "undefined",
384
+ contextHeadersType: context.headers ? typeof context.headers : "undefined",
385
+ actorType,
386
+ actorId
387
+ });
388
+ const allHeaders = {};
389
+ if (context.request?.headers) {
390
+ if (typeof context.request.headers.get === "function") logger.debug("[RBAC Directive] Headers object has get method");
391
+ else {
392
+ const headers = context.request.headers;
393
+ Object.keys(headers).forEach((key) => {
394
+ const value = headers[key];
395
+ if (value) allHeaders[key] = value;
396
+ });
397
+ const sanitizedHeaders = sanitizeHeadersForLogging(allHeaders);
398
+ logger.debug("[RBAC Directive] Request headers (plain object)", { headers: sanitizedHeaders });
399
+ }
400
+ }
401
+ if (context.headers) {
402
+ const headers = context.headers;
403
+ const contextHeadersObj = {};
404
+ Object.keys(headers).forEach((key) => {
405
+ const value = headers[key];
406
+ if (value) contextHeadersObj[key] = value;
407
+ });
408
+ const sanitizedHeaders = sanitizeHeadersForLogging(contextHeadersObj);
409
+ logger.debug("[RBAC Directive] Context headers", { headers: sanitizedHeaders });
410
+ }
411
+ const bypassHeader = getHeader(context, "x-rbac-bypass");
412
+ const bypassSource = getHeader(context, "x-bypass-source");
413
+ const bypassTimestamp = getHeader(context, "x-bypass-timestamp");
414
+ logger.debug("[RBAC Directive] Extracted bypass headers", {
415
+ bypassHeader,
416
+ bypassSource,
417
+ bypassTimestamp
418
+ });
419
+ const bypassAttempted = !!(bypassHeader || bypassSource || bypassTimestamp);
420
+ if (!bypassHeader || !bypassSource || !bypassTimestamp) {
421
+ logger.debug("[RBAC Directive] Missing bypass headers - bypass NOT granted", {
422
+ hasRbacBypass: !!bypassHeader,
423
+ hasBypassSource: !!bypassSource,
424
+ hasBypassTimestamp: !!bypassTimestamp
425
+ });
426
+ if (bypassAttempted) return {
427
+ shouldBypass: false,
428
+ bypassContext: {
429
+ bypassAttempted: true,
430
+ bypassSource,
431
+ bypassTimestamp,
432
+ bypassFailureReason: "Missing required bypass headers"
433
+ }
434
+ };
435
+ return { shouldBypass: false };
436
+ }
437
+ if (bypassHeader !== "true") {
438
+ logger.warn("[RBAC Directive] Invalid bypass header value", { value: bypassHeader });
439
+ return {
440
+ shouldBypass: false,
441
+ bypassContext: {
442
+ bypassAttempted: true,
443
+ bypassSource,
444
+ bypassTimestamp,
445
+ bypassFailureReason: `Invalid bypass header value: ${bypassHeader}`
446
+ }
447
+ };
448
+ }
449
+ if (!validateBypassTimestamp(bypassTimestamp)) {
450
+ logger.warn("[RBAC Directive] Bypass rejected: stale timestamp", {
451
+ source: bypassSource,
452
+ timestamp: bypassTimestamp
453
+ });
454
+ return {
455
+ shouldBypass: false,
456
+ bypassContext: {
457
+ bypassAttempted: true,
458
+ bypassSource,
459
+ bypassTimestamp,
460
+ bypassFailureReason: "Stale or invalid timestamp (replay attack prevention)"
461
+ }
462
+ };
463
+ }
464
+ logger.debug("[RBAC Directive] Valid bypass headers detected", {
465
+ source: bypassSource,
466
+ timestamp: bypassTimestamp
467
+ });
468
+ return { shouldBypass: true };
469
+ }
470
+ /**
471
+ * Verify user authentication from context
472
+ */
473
+ function verifyAuthentication(contextValue, fieldName, permission) {
474
+ const ctx = contextValue;
475
+ const user = ctx.user ?? (ctx.actor?.id ? {
476
+ id: ctx.actor.id,
477
+ email: ctx.actor.email,
478
+ workspace_id: ctx.workspace?.id
479
+ } : ctx.actorId ? {
480
+ id: ctx.actorId,
481
+ workspace_id: ctx.workspace?.id
482
+ } : void 0);
483
+ logger.debug("[RBAC Directive] Checking authentication", {
484
+ hasUser: !!user,
485
+ userId: user?.id,
486
+ fieldName
487
+ });
488
+ if (!user?.id) {
489
+ logger.warn("[RBAC Directive] Authentication required but user not found", {
490
+ fieldName,
491
+ permission
492
+ });
493
+ throw new GraphQLError("Authentication required", { extensions: {
494
+ code: "UNAUTHENTICATED",
495
+ field: fieldName,
496
+ permission
497
+ } });
498
+ }
499
+ return user;
500
+ }
501
+ /**
502
+ * Resolve resource ID from field arguments and configuration
503
+ */
504
+ async function resolveResourceId(resourceIdField, selection, variableValues, config, _rbacClient, _ctx, permission, fieldName) {
505
+ let resourceId;
506
+ const fieldArgs = parseFieldArguments(selection, variableValues || {});
507
+ if (resourceIdField) {
508
+ resourceId = getValueAtPath(fieldArgs, resourceIdField);
509
+ if (!resourceId) {
510
+ logger.error("[RBAC Directive] Resource ID not found at specified path", {
511
+ resourceIdField,
512
+ fieldName,
513
+ permission,
514
+ availableArgs: Object.keys(fieldArgs)
515
+ });
516
+ throw new GraphQLError(`Resource ID not found at specified path "${resourceIdField}" for permission "${permission}"`, { extensions: {
517
+ code: "INVALID_RESOURCE_CONFIGURATION",
518
+ field: fieldName,
519
+ permission,
520
+ resourceIdField,
521
+ hint: `Check that the field path "${resourceIdField}" exists in your arguments`
522
+ } });
523
+ }
524
+ logger.debug("[RBAC Directive] Using explicit resourceIdField", {
525
+ resourceIdField,
526
+ resourceId,
527
+ fieldName
528
+ });
529
+ } else {
530
+ const defaultPaths = ["id", "input.id"];
531
+ for (const path of defaultPaths) {
532
+ resourceId = getValueAtPath(fieldArgs, path);
533
+ if (resourceId) {
534
+ logger.debug("[RBAC Directive] Auto-resolved resource ID from convention", {
535
+ path,
536
+ resourceId,
537
+ fieldName,
538
+ permission
539
+ });
540
+ break;
541
+ }
542
+ }
543
+ if (!resourceId) {
544
+ const contextWorkspaceId = _ctx.workspace?.id;
545
+ if (contextWorkspaceId) {
546
+ resourceId = contextWorkspaceId;
547
+ logger.debug("[RBAC Directive] Using workspace ID from context headers", {
548
+ resourceId,
549
+ fieldName,
550
+ permission
551
+ });
552
+ } else {
553
+ logger.error("[RBAC Directive] No resource ID available for permission check", {
554
+ permission,
555
+ fieldName,
556
+ triedPaths: defaultPaths,
557
+ availableArgs: Object.keys(fieldArgs)
558
+ });
559
+ throw new GraphQLError(`Cannot check permission "${permission}": No resource ID available. Tried default paths: ${defaultPaths.join(", ")}. Either provide one of these fields in your arguments, specify resourceIdField in the directive, or pass x-workspace-id header.`, { extensions: {
560
+ code: "INVALID_RESOURCE_CONFIGURATION",
561
+ field: fieldName,
562
+ permission,
563
+ triedPaths: defaultPaths,
564
+ hint: "Add resourceIdField parameter to @requiresPermission directive (e.g., resourceIdField: \"input.workspaceId\") or pass x-workspace-id header"
565
+ } });
566
+ }
567
+ }
568
+ }
569
+ if (resourceId && config.resourceResolver) {
570
+ const resolved = await config.resourceResolver(resourceId, permission.split(":")[0]);
571
+ if (!resolved) {
572
+ logger.warn("[RBAC Directive] Custom resource resolver returned null", {
573
+ originalResourceId: resourceId,
574
+ permission,
575
+ fieldName
576
+ });
577
+ throw new GraphQLError("Resource not found or invalid", { extensions: {
578
+ code: "FORBIDDEN",
579
+ field: fieldName,
580
+ permission,
581
+ resourceId,
582
+ hint: "Resource resolver could not resolve the resource ID"
583
+ } });
584
+ }
585
+ logger.debug("[RBAC Directive] Custom resource resolver applied", {
586
+ originalResourceId: resourceId,
587
+ resolvedResourceId: resolved,
588
+ fieldName
589
+ });
590
+ return resolved;
591
+ }
592
+ return resourceId;
593
+ }
594
+ /**
595
+ * Extract scope ID from context based on layer
596
+ */
597
+ function extractScopeId(ctx, layer) {
598
+ if (layer === "wspace") {
599
+ const workspaceId = getHeader(ctx, "x-workspace-id") || ctx.workspace?.id;
600
+ if (!workspaceId) throw new GraphQLError("Workspace ID required for workspace-layer RBAC", { extensions: {
601
+ code: "BAD_REQUEST",
602
+ hint: "Pass x-workspace-id header or ensure workspace context is set"
603
+ } });
604
+ return workspaceId;
605
+ } else return getHeader(ctx, "x-tenant-id") || ctx.tenant?.id || "global";
606
+ }
607
+ /**
608
+ * Extract actor type from context
609
+ */
610
+ function extractActorType(ctx) {
611
+ const actorTypeHeader = getHeader(ctx, "x-actor-type");
612
+ if (actorTypeHeader) {
613
+ const upperType = actorTypeHeader.toUpperCase();
614
+ if ([
615
+ "USER",
616
+ "BOT",
617
+ "INTEGRATION",
618
+ "DELEGATED_AGENT"
619
+ ].includes(upperType)) return upperType;
620
+ }
621
+ return "USER";
622
+ }
623
+ /**
624
+ * Check permission and throw error if denied
625
+ */
626
+ async function checkAndEnforcePermission(rbacClient, ctx, actorId, permission, resolvedResourceId, userId, fieldName, bypassContext) {
627
+ const layer = rbacClient.getLayer();
628
+ const actorType = extractActorType(ctx);
629
+ const scopeId = extractScopeId(ctx, layer);
630
+ logger.info("[RBAC Directive] Checking permission", {
631
+ userId,
632
+ actorId,
633
+ actorType,
634
+ scopeId,
635
+ permission,
636
+ resourceId: resolvedResourceId,
637
+ fieldName,
638
+ layer,
639
+ bypassAttempted: bypassContext?.bypassAttempted ?? false
640
+ });
641
+ const { hasPermission, reason } = await rbacClient.checkPermission(actorId, actorType, scopeId, permission, resolvedResourceId);
642
+ if (!hasPermission) {
643
+ logger.warn("[RBAC Directive] Permission denied", {
644
+ userId,
645
+ actorType,
646
+ scopeId,
647
+ permission,
648
+ reason,
649
+ fieldName,
650
+ bypassContext
651
+ });
652
+ const errorMessage = `Forbidden: Missing permission "${permission}"${reason ? ` - ${reason}` : ""}`;
653
+ const extensions = {
654
+ code: "FORBIDDEN",
655
+ permission,
656
+ reason,
657
+ field: fieldName,
658
+ resourceId: resolvedResourceId,
659
+ scopeId,
660
+ layer
661
+ };
662
+ if (bypassContext?.bypassAttempted) {
663
+ extensions["bypassAttempted"] = true;
664
+ extensions["bypassSource"] = bypassContext.bypassSource;
665
+ extensions["bypassTimestamp"] = bypassContext.bypassTimestamp;
666
+ extensions["bypassFailureReason"] = bypassContext.bypassFailureReason;
667
+ }
668
+ throw new GraphQLError(errorMessage, { extensions });
669
+ }
670
+ logger.info("[RBAC Directive] Permission granted", {
671
+ userId,
672
+ permission,
673
+ fieldName,
674
+ reason
675
+ });
676
+ }
677
+ /**
678
+ * Create RBAC directive enforcement plugin
679
+ *
680
+ * This plugin:
681
+ * 1. Intercepts GraphQL operations BEFORE execution
682
+ * 2. Checks for @requiresPermission directive on fields
683
+ * 3. Validates user authentication
684
+ * 4. Extracts resource ID from field arguments
685
+ * 5. Calls RBAC service to check permissions
686
+ * 6. Allows or denies operation based on permission check
687
+ *
688
+ * @param config - RBAC directive configuration
689
+ * @returns Envelop plugin instance
690
+ *
691
+ * @example
692
+ * ```typescript
693
+ * // In microservice server initialization
694
+ * const server = await createServer({
695
+ * yogaPlugins: [
696
+ * createRBACDirective({
697
+ * // Use Workspaces Gateway (RBAC is part of workspaces supergraph)
698
+ * rbacServiceUrl: process.env.RBAC_GATEWAY_URL || 'http://localhost:4001/graphql',
699
+ * enableCaching: true,
700
+ * cacheTTL: 300000, // 5 minutes
701
+ * failClosed: true, // Deny access on errors
702
+ * }),
703
+ * useGraphQLModules(application),
704
+ * ],
705
+ * });
706
+ * ```
707
+ */
708
+ function createRBACDirective(config) {
709
+ if (process.env["SKIP_RBAC"] === "true" || config.skipRbac === true) {
710
+ if (process.env["NODE_ENV"] === "production") throw new Error("[RBAC Directive] FATAL: SKIP_RBAC cannot be enabled in production environments. This would bypass all authorization checks and is a critical security vulnerability. Remove SKIP_RBAC=true from your environment configuration.");
711
+ logger.warn("[RBAC Directive] ⚠️ RBAC CHECKS ARE DISABLED (SKIP_RBAC=true) - DO NOT USE IN PRODUCTION!");
712
+ return { async onExecute({ args }) {
713
+ const { document } = args;
714
+ const operationName = document.definitions.find((def) => def.kind === "OperationDefinition")?.name?.value || "anonymous";
715
+ logger.warn("[RBAC Directive] RBAC check skipped for operation", { operationName });
716
+ } };
717
+ }
718
+ const rbacClient = new RBACClient(config);
719
+ return { async onExecute({ args }) {
720
+ logger.debug("[RBAC Directive] onExecute called");
721
+ const { schema, document, contextValue, variableValues } = args;
722
+ const operation = document.definitions.find((def) => def.kind === "OperationDefinition");
723
+ if (!operation) {
724
+ logger.debug("[RBAC Directive] No operation definition found, skipping");
725
+ return;
726
+ }
727
+ const typeName = operation.operation === "mutation" ? "Mutation" : "Query";
728
+ const type = schema.getType(typeName);
729
+ if (!type || !("getFields" in type)) {
730
+ logger.debug(`[RBAC Directive] Type ${typeName} not found, skipping`);
731
+ return;
732
+ }
733
+ const fields = type.getFields();
734
+ for (const selection of operation.selectionSet.selections) {
735
+ if (selection.kind !== "Field") continue;
736
+ const fieldName = selection.name.value;
737
+ const fieldDef = fields[fieldName];
738
+ if (!fieldDef?.astNode) continue;
739
+ const directive = fieldDef.astNode.directives?.find((d) => d.name.value === "requiresPermission");
740
+ if (!directive) continue;
741
+ const permission = getDirectiveArgument(directive, "permission");
742
+ const resourceIdField = getDirectiveArgument(directive, "resourceIdField");
743
+ if (!permission) throw new GraphQLError("Invalid @requiresPermission directive: permission argument is required and must be a string", { extensions: {
744
+ code: "INTERNAL_SERVER_ERROR",
745
+ field: fieldName
746
+ } });
747
+ const ctx = contextValue;
748
+ const bypassCheckResult = checkBypassHeaders(ctx);
749
+ if (bypassCheckResult.shouldBypass) {
750
+ const bypassSource = getHeader(ctx, "x-bypass-source");
751
+ const bypassTimestamp = getHeader(ctx, "x-bypass-timestamp");
752
+ logger.info("[RBAC Directive] RBAC bypassed for internal service call", {
753
+ field: fieldName,
754
+ permission,
755
+ resource: resourceIdField,
756
+ bypassSource,
757
+ bypassTimestamp,
758
+ operationType: operation.operation
759
+ });
760
+ continue;
761
+ }
762
+ const user = verifyAuthentication(contextValue, fieldName, permission);
763
+ let resolvedResourceId;
764
+ try {
765
+ resolvedResourceId = await resolveResourceId(resourceIdField, selection, variableValues, config, rbacClient, ctx, permission, fieldName);
766
+ } catch (error) {
767
+ if (!resourceIdField) logger.debug("[RBAC Directive] No resource ID resolved, checking permission at scope level", {
768
+ fieldName,
769
+ permission
770
+ });
771
+ else throw error;
772
+ }
773
+ const actorId = toActorId(user.id);
774
+ await checkAndEnforcePermission(rbacClient, ctx, actorId, permission, resolvedResourceId, user.id, fieldName, bypassCheckResult.bypassContext);
775
+ }
776
+ } };
777
+ }
778
+ /**
779
+ * Build RBAC service URL for a layer
780
+ *
781
+ * @param layer - Service layer ('wspace' or 'global')
782
+ * @returns RBAC service URL
783
+ */
784
+ function buildRBACServiceUrl(layer) {
785
+ const routing = DEFAULT_GATEWAY_ROUTING[layer];
786
+ const gateway = layer === "wspace" ? routing.internalGateway : routing.crossLayerGateway;
787
+ return `http://${gateway.host}:${gateway.port}${gateway.graphqlPath}`;
788
+ }
789
+ /**
790
+ * Create RBAC directive plugin for a specific layer
791
+ *
792
+ * This factory function automatically configures the RBAC directive with
793
+ * the correct internal gateway URL based on the service layer.
794
+ *
795
+ * @param layer - Service layer ('wspace' or 'global')
796
+ * @param config - Optional configuration overrides
797
+ * @returns RBAC directive plugin configured for the layer
798
+ *
799
+ * @example
800
+ * ```typescript
801
+ * // In a workspace layer service
802
+ * const rbacPlugin = createRBACDirectiveForLayer('wspace', {
803
+ * enableCaching: true,
804
+ * cacheTTL: 300000,
805
+ * });
806
+ *
807
+ * // In a global layer service
808
+ * const rbacPlugin = createRBACDirectiveForLayer('global', {
809
+ * enableCaching: true,
810
+ * });
811
+ * ```
812
+ */
813
+ function createRBACDirectiveForLayer(layer, config) {
814
+ const envPrefix = layer.toUpperCase();
815
+ const rbacServiceUrl = config?.rbacServiceUrl || process.env[`${envPrefix}_RBAC_GATEWAY_URL`] || process.env["RBAC_GATEWAY_URL"] || buildRBACServiceUrl(layer);
816
+ const rbacLayer = layer;
817
+ logger.info("[RBAC Directive] Creating layer-aware RBAC directive", {
818
+ layer: rbacLayer,
819
+ rbacServiceUrl,
820
+ enableCaching: config?.enableCaching ?? true
821
+ });
822
+ return createRBACDirective({
823
+ rbacServiceUrl,
824
+ layer: rbacLayer,
825
+ enableCaching: config?.enableCaching ?? true,
826
+ cacheTTL: config?.cacheTTL,
827
+ cacheMaxSize: config?.cacheMaxSize,
828
+ timeout: config?.timeout,
829
+ failClosed: config?.failClosed,
830
+ resourceResolver: config?.resourceResolver,
831
+ skipRbac: config?.skipRbac
832
+ });
833
+ }
834
+ /**
835
+ * Create RBAC directive from environment with automatic layer detection
836
+ *
837
+ * @param serviceName - Service name for layer detection
838
+ * @param config - Optional configuration overrides
839
+ * @returns RBAC directive plugin
840
+ */
841
+ function createRBACDirectiveFromEnv(serviceName, config) {
842
+ return createRBACDirectiveForLayer(process.env["SERVICE_LAYER"] || (serviceName.startsWith("global-") ? "global" : "wspace"), config);
843
+ }
844
+
845
+ // src/rbac/index.ts
846
+ /**
847
+ * Build an `RBACClient` from env vars (mirrors `createRBACDirectiveFromEnv`).
848
+ *
849
+ * Resolution order for the gateway URL:
850
+ * 1. explicit `rbacServiceUrl` option
851
+ * 2. `<LAYER>_RBAC_GATEWAY_URL`
852
+ * 3. `RBAC_GATEWAY_URL`
853
+ * 4. layer default
854
+ */
855
+ function createRBACClientFromEnv(options = {}) {
856
+ const layer = options.layer ?? (process.env["SERVICE_LAYER"] || "wspace");
857
+ const envPrefix = layer.toUpperCase();
858
+ const rbacServiceUrl = options.rbacServiceUrl || process.env[`${envPrefix}_RBAC_GATEWAY_URL`] || process.env["RBAC_GATEWAY_URL"] || DEFAULT_LAYER_RESOURCES[layer].rbacGatewayUrl;
859
+ return new RBACClient({
860
+ rbacServiceUrl,
861
+ layer,
862
+ failClosed: options.failClosed
863
+ });
864
+ }
865
+ /**
866
+ * RBAC Module
867
+ */
868
+ var RBACModule = class {
869
+ client;
870
+ context;
871
+ constructor(client, context) {
872
+ this.client = client;
873
+ this.context = context;
874
+ }
875
+ /**
876
+ * Check if user has permission (returns boolean)
877
+ */
878
+ async checkPermission(options) {
879
+ try {
880
+ await this.requirePermission(options);
881
+ return true;
882
+ } catch {
883
+ return false;
884
+ }
885
+ }
886
+ /**
887
+ * Require permission (throws if denied)
888
+ */
889
+ async requirePermission(options) {
890
+ if (!options.userId) throw new ValidationError("User ID is required");
891
+ if (!options.action) throw new ValidationError("Action is required");
892
+ if (!options.resourceType) throw new ValidationError("Resource type is required");
893
+ logger.debug("[RBAC] Checking permission", options);
894
+ const query = `
895
+ query CheckPermission($input: PermissionCheckInput!) {
896
+ checkPermission(input: $input) {
897
+ allowed
898
+ decisionPath
899
+ }
900
+ }
901
+ `;
902
+ const variables = { input: {
903
+ actorId: options.userId,
904
+ actorType: options.actorType || "USER",
905
+ scopeId: options.workspaceId || this.context.workspaceId || this.context.tenantId || "",
906
+ resourceType: options.resourceType,
907
+ action: options.action,
908
+ resourceId: options.resourceId
909
+ } };
910
+ const response = options.workspaceId || this.context.workspaceId ? await this.client.query(query, variables, this.context) : await this.client.tenantQuery(query, variables, this.context);
911
+ if (!response.checkPermission.allowed) throw new PermissionDeniedError(`Permission denied: ${response.checkPermission.decisionPath}`, {
912
+ action: options.action,
913
+ resourceType: options.resourceType,
914
+ resourceId: options.resourceId,
915
+ userId: options.userId
916
+ });
917
+ logger.debug("[RBAC] Permission granted", {
918
+ ...options,
919
+ decisionPath: response.checkPermission.decisionPath
920
+ });
921
+ }
922
+ /**
923
+ * Get user roles in workspace
924
+ * Uses the new PBAC actorRoleAssignments query
925
+ */
926
+ async getUserRoles(userId, workspaceId) {
927
+ logger.debug("[RBAC] Getting user roles", {
928
+ userId,
929
+ workspaceId
930
+ });
931
+ const query = `
932
+ query GetActorRoleAssignments($actorId: String!, $scopeId: String!) {
933
+ actorRoleAssignments(actorId: $actorId, scopeId: $scopeId) {
934
+ id
935
+ role {
936
+ id
937
+ name
938
+ description
939
+ defaultPermissions {
940
+ resourceType
941
+ level
942
+ }
943
+ }
944
+ }
945
+ }
946
+ `;
947
+ const variables = {
948
+ actorId: userId,
949
+ scopeId: workspaceId
950
+ };
951
+ const contextWithWorkspace = {
952
+ ...this.context,
953
+ workspaceId
954
+ };
955
+ return (await this.client.query(query, variables, contextWithWorkspace)).actorRoleAssignments.map((assignment) => ({
956
+ id: assignment.role.id,
957
+ name: assignment.role.name,
958
+ description: assignment.role.description,
959
+ defaultPermissions: assignment.role.defaultPermissions
960
+ }));
961
+ }
962
+ /**
963
+ * Assign role to user
964
+ * Uses the new PBAC assignRoleToActor mutation
965
+ */
966
+ async assignRoleToUser(userId, roleId, workspaceId, actorType = "USER") {
967
+ logger.debug("[RBAC] Assigning role to user", {
968
+ userId,
969
+ roleId,
970
+ workspaceId,
971
+ actorType
972
+ });
973
+ const mutation = `
974
+ mutation AssignRoleToActor($input: AssignRoleInput!) {
975
+ assignRoleToActor(input: $input) {
976
+ id
977
+ actorId
978
+ roleId
979
+ scopeId
980
+ }
981
+ }
982
+ `;
983
+ const variables = { input: {
984
+ actorId: userId,
985
+ actorType,
986
+ roleId,
987
+ scopeId: workspaceId
988
+ } };
989
+ const contextWithWorkspace = {
990
+ ...this.context,
991
+ workspaceId
992
+ };
993
+ await this.client.query(mutation, variables, contextWithWorkspace);
994
+ logger.info("[RBAC] Role assigned to actor", {
995
+ userId,
996
+ roleId,
997
+ workspaceId
998
+ });
999
+ return true;
1000
+ }
1001
+ /**
1002
+ * Remove role from user
1003
+ * Uses the new PBAC removeRoleFromActor mutation
1004
+ * Note: This first finds the assignment ID, then removes it
1005
+ */
1006
+ async removeRoleFromUser(userId, roleId, workspaceId) {
1007
+ logger.debug("[RBAC] Removing role from user", {
1008
+ userId,
1009
+ roleId,
1010
+ workspaceId
1011
+ });
1012
+ const contextWithWorkspace = {
1013
+ ...this.context,
1014
+ workspaceId
1015
+ };
1016
+ const assignment = (await this.client.query(`
1017
+ query FindAssignment($actorId: String!, $scopeId: String!) {
1018
+ actorRoleAssignments(actorId: $actorId, scopeId: $scopeId) {
1019
+ id
1020
+ roleId
1021
+ }
1022
+ }
1023
+ `, {
1024
+ actorId: userId,
1025
+ scopeId: workspaceId
1026
+ }, contextWithWorkspace)).actorRoleAssignments.find((a) => a.roleId === roleId);
1027
+ if (!assignment) {
1028
+ logger.warn("[RBAC] No role assignment found to remove", {
1029
+ userId,
1030
+ roleId,
1031
+ workspaceId
1032
+ });
1033
+ return false;
1034
+ }
1035
+ await this.client.query(`
1036
+ mutation RemoveRoleFromActor($assignmentId: ID!) {
1037
+ removeRoleFromActor(assignmentId: $assignmentId)
1038
+ }
1039
+ `, { assignmentId: assignment.id }, contextWithWorkspace);
1040
+ logger.info("[RBAC] Role removed from actor", {
1041
+ userId,
1042
+ roleId,
1043
+ workspaceId,
1044
+ assignmentId: assignment.id
1045
+ });
1046
+ return true;
1047
+ }
1048
+ /**
1049
+ * Create custom role with default permissions
1050
+ *
1051
+ * Uses the new PBAC createRole mutation and setRoleDefaultPermission for permissions.
1052
+ *
1053
+ * @param name - Role name
1054
+ * @param description - Role description
1055
+ * @param defaultPermissions - Array of default permission configurations
1056
+ * (e.g., [{ resourceType: 'project', level: 'ADMIN' }])
1057
+ * OR legacy permission strings (converted to ADMIN level)
1058
+ * @param workspaceId - Workspace ID (scopeId)
1059
+ */
1060
+ async createRole(name, description, defaultPermissions, workspaceId) {
1061
+ logger.debug("[RBAC] Creating role", {
1062
+ name,
1063
+ workspaceId,
1064
+ permissionCount: defaultPermissions.length
1065
+ });
1066
+ const contextWithWorkspace = {
1067
+ ...this.context,
1068
+ workspaceId
1069
+ };
1070
+ const createRoleMutation = `
1071
+ mutation CreateRole($input: CreateRoleInput!) {
1072
+ createRole(input: $input) {
1073
+ id
1074
+ name
1075
+ description
1076
+ defaultPermissions {
1077
+ resourceType
1078
+ level
1079
+ }
1080
+ }
1081
+ }
1082
+ `;
1083
+ const createRoleVariables = { input: {
1084
+ name,
1085
+ description,
1086
+ scopeId: workspaceId,
1087
+ scopeType: "workspace"
1088
+ } };
1089
+ const createResponse = await this.client.query(createRoleMutation, createRoleVariables, contextWithWorkspace);
1090
+ const roleId = createResponse.createRole.id;
1091
+ logger.info("[RBAC] Role created", {
1092
+ name,
1093
+ roleId
1094
+ });
1095
+ if (defaultPermissions.length > 0) {
1096
+ logger.debug("[RBAC] Setting default permissions for role", {
1097
+ roleId,
1098
+ count: defaultPermissions.length
1099
+ });
1100
+ const normalizedPermissions = defaultPermissions.map((perm) => {
1101
+ if (typeof perm === "string") return {
1102
+ resourceType: perm.split(":")[0] || perm,
1103
+ level: "ADMIN"
1104
+ };
1105
+ return perm;
1106
+ });
1107
+ const permMap = /* @__PURE__ */ new Map();
1108
+ const levelPriority = {
1109
+ ADMIN: 4,
1110
+ EDITOR: 3,
1111
+ VIEWER: 2,
1112
+ NONE: 1
1113
+ };
1114
+ for (const perm of normalizedPermissions) {
1115
+ const existing = permMap.get(perm.resourceType);
1116
+ if (!existing || levelPriority[perm.level] > levelPriority[existing]) permMap.set(perm.resourceType, perm.level);
1117
+ }
1118
+ const setPermissionMutation = `
1119
+ mutation SetRoleDefaultPermission($input: SetRoleDefaultPermissionInput!) {
1120
+ setRoleDefaultPermission(input: $input) {
1121
+ id
1122
+ defaultPermissions {
1123
+ resourceType
1124
+ level
1125
+ }
1126
+ }
1127
+ }
1128
+ `;
1129
+ const failedPermissions = [];
1130
+ for (const [resourceType, level] of permMap) try {
1131
+ await this.client.query(setPermissionMutation, { input: {
1132
+ roleId,
1133
+ resourceType,
1134
+ level
1135
+ } }, contextWithWorkspace);
1136
+ logger.debug("[RBAC] Set default permission", {
1137
+ roleId,
1138
+ resourceType,
1139
+ level
1140
+ });
1141
+ } catch (error) {
1142
+ const errorMsg = error instanceof Error ? error.message : String(error);
1143
+ logger.error("[RBAC] Failed to set default permission", {
1144
+ roleId,
1145
+ resourceType,
1146
+ level,
1147
+ error: errorMsg
1148
+ });
1149
+ failedPermissions.push({
1150
+ resourceType,
1151
+ level,
1152
+ error: errorMsg
1153
+ });
1154
+ }
1155
+ if (failedPermissions.length > 0) {
1156
+ const failedTypes = failedPermissions.map((p) => p.resourceType).join(", ");
1157
+ throw new ValidationError(`Role created but failed to set ${failedPermissions.length} default permission(s): ${failedTypes}. Role ID: ${roleId}. Check logs for details.`);
1158
+ }
1159
+ logger.info("[RBAC] Default permissions set for role", {
1160
+ roleId,
1161
+ count: permMap.size
1162
+ });
1163
+ }
1164
+ const role = (await this.client.query(`
1165
+ query GetRole($id: ID!) {
1166
+ role(id: $id) {
1167
+ id
1168
+ name
1169
+ description
1170
+ defaultPermissions {
1171
+ resourceType
1172
+ level
1173
+ }
1174
+ }
1175
+ }
1176
+ `, { id: roleId }, contextWithWorkspace)).role || createResponse.createRole;
1177
+ return {
1178
+ id: role.id,
1179
+ name: role.name,
1180
+ description: role.description,
1181
+ defaultPermissions: role.defaultPermissions
1182
+ };
1183
+ }
1184
+ /**
1185
+ * Get all available action definitions (replaces getAvailablePermissions)
1186
+ * Returns actions organized by resource type
1187
+ */
1188
+ async getAvailablePermissions() {
1189
+ logger.debug("[RBAC] Getting available action definitions");
1190
+ const resourceTypesQuery = `
1191
+ query GetResourceTypes {
1192
+ resourceTypes
1193
+ }
1194
+ `;
1195
+ const hasWorkspace = !!this.context.workspaceId;
1196
+ const resourceTypesResponse = hasWorkspace ? await this.client.query(resourceTypesQuery, {}, this.context) : await this.client.tenantQuery(resourceTypesQuery, {}, this.context);
1197
+ const permissions = [];
1198
+ const actionsQuery = `
1199
+ query GetActionDefinitions($resourceType: String!) {
1200
+ actionDefinitions(resourceType: $resourceType) {
1201
+ id
1202
+ action
1203
+ resourceType
1204
+ description
1205
+ }
1206
+ }
1207
+ `;
1208
+ for (const resourceType of resourceTypesResponse.resourceTypes) {
1209
+ const actionsResponse = hasWorkspace ? await this.client.query(actionsQuery, { resourceType }, this.context) : await this.client.tenantQuery(actionsQuery, { resourceType }, this.context);
1210
+ for (const action of actionsResponse.actionDefinitions) permissions.push({
1211
+ id: action.id,
1212
+ action: action.action,
1213
+ resourceType: action.resourceType,
1214
+ description: action.description
1215
+ });
1216
+ }
1217
+ return permissions;
1218
+ }
1219
+ /**
1220
+ * Check multiple permissions at once
1221
+ * Uses the new PBAC checkPermissions query
1222
+ */
1223
+ async checkMultiplePermissions(checks) {
1224
+ logger.debug("[RBAC] Checking multiple permissions", { count: checks.length });
1225
+ const query = `
1226
+ query CheckPermissions($inputs: [PermissionCheckInput!]!) {
1227
+ checkPermissions(inputs: $inputs) {
1228
+ allowed
1229
+ decisionPath
1230
+ }
1231
+ }
1232
+ `;
1233
+ const inputs = checks.map((check) => ({
1234
+ actorId: check.userId,
1235
+ actorType: check.actorType || "USER",
1236
+ scopeId: check.workspaceId || this.context.workspaceId || this.context.tenantId || "",
1237
+ resourceType: check.resourceType,
1238
+ action: check.action,
1239
+ resourceId: check.resourceId
1240
+ }));
1241
+ return (checks.some((c) => c.workspaceId) || !!this.context.workspaceId ? await this.client.query(query, { inputs }, this.context) : await this.client.tenantQuery(query, { inputs }, this.context)).checkPermissions.map((result) => ({
1242
+ allowed: result.allowed,
1243
+ reason: result.decisionPath
1244
+ }));
1245
+ }
1246
+ /**
1247
+ * Get effective permissions for a user in a workspace
1248
+ * New method that uses the PBAC effectivePermissions query
1249
+ */
1250
+ async getEffectivePermissions(userId, workspaceId, actorType = "USER") {
1251
+ logger.debug("[RBAC] Getting effective permissions", {
1252
+ userId,
1253
+ workspaceId,
1254
+ actorType
1255
+ });
1256
+ const query = `
1257
+ query EffectivePermissions($actorId: String!, $actorType: ActorType!, $scopeId: String!) {
1258
+ effectivePermissions(actorId: $actorId, actorType: $actorType, scopeId: $scopeId) {
1259
+ actorId
1260
+ scopeId
1261
+ permissions {
1262
+ resourceType
1263
+ level
1264
+ allowedActions
1265
+ source
1266
+ }
1267
+ }
1268
+ }
1269
+ `;
1270
+ const variables = {
1271
+ actorId: userId,
1272
+ actorType,
1273
+ scopeId: workspaceId
1274
+ };
1275
+ const contextWithWorkspace = {
1276
+ ...this.context,
1277
+ workspaceId
1278
+ };
1279
+ return (await this.client.query(query, variables, contextWithWorkspace)).effectivePermissions;
1280
+ }
1281
+ /**
1282
+ * Initialize workspace roles by cloning system roles
1283
+ * New method for workspace initialization
1284
+ */
1285
+ async initializeWorkspaceRoles(workspaceId, ownerId) {
1286
+ logger.debug("[RBAC] Initializing workspace roles", {
1287
+ workspaceId,
1288
+ ownerId
1289
+ });
1290
+ const mutation = `
1291
+ mutation InitializeWorkspaceRoles($workspaceId: String!, $ownerId: String!) {
1292
+ initializeWorkspaceRoles(workspaceId: $workspaceId, ownerId: $ownerId) {
1293
+ success
1294
+ rolesCreated
1295
+ roleNames
1296
+ ownerAssigned
1297
+ message
1298
+ }
1299
+ }
1300
+ `;
1301
+ const contextWithWorkspace = {
1302
+ ...this.context,
1303
+ workspaceId
1304
+ };
1305
+ const response = await this.client.query(mutation, {
1306
+ workspaceId,
1307
+ ownerId
1308
+ }, contextWithWorkspace);
1309
+ logger.info("[RBAC] Workspace roles initialized", response.initializeWorkspaceRoles);
1310
+ return response.initializeWorkspaceRoles;
1311
+ }
1312
+ /**
1313
+ * Update an existing role
1314
+ * Uses the new PBAC updateRole mutation
1315
+ *
1316
+ * @param roleId - Role ID to update
1317
+ * @param updates - Fields to update (name, description, priority)
1318
+ * @param workspaceId - Workspace ID (scopeId)
1319
+ */
1320
+ async updateRole(roleId, updates, workspaceId) {
1321
+ logger.debug("[RBAC] Updating role", {
1322
+ roleId,
1323
+ updates,
1324
+ workspaceId
1325
+ });
1326
+ const contextWithWorkspace = {
1327
+ ...this.context,
1328
+ workspaceId
1329
+ };
1330
+ const response = await this.client.query(`
1331
+ mutation UpdateRole($id: ID!, $input: UpdateRoleInput!) {
1332
+ updateRole(id: $id, input: $input) {
1333
+ id
1334
+ name
1335
+ description
1336
+ priority
1337
+ defaultPermissions {
1338
+ resourceType
1339
+ level
1340
+ }
1341
+ }
1342
+ }
1343
+ `, {
1344
+ id: roleId,
1345
+ input: updates
1346
+ }, contextWithWorkspace);
1347
+ logger.info("[RBAC] Role updated", {
1348
+ roleId,
1349
+ name: response.updateRole.name
1350
+ });
1351
+ return {
1352
+ id: response.updateRole.id,
1353
+ name: response.updateRole.name,
1354
+ description: response.updateRole.description,
1355
+ defaultPermissions: response.updateRole.defaultPermissions
1356
+ };
1357
+ }
1358
+ /**
1359
+ * Delete a role
1360
+ * Uses the new PBAC deleteRole mutation
1361
+ *
1362
+ * @param roleId - Role ID to delete
1363
+ * @param workspaceId - Workspace ID (scopeId)
1364
+ * @param reassignToRoleId - Optional role ID to reassign existing actors to
1365
+ */
1366
+ async deleteRole(roleId, workspaceId, reassignToRoleId) {
1367
+ logger.debug("[RBAC] Deleting role", {
1368
+ roleId,
1369
+ workspaceId,
1370
+ reassignToRoleId
1371
+ });
1372
+ const contextWithWorkspace = {
1373
+ ...this.context,
1374
+ workspaceId
1375
+ };
1376
+ const response = await this.client.query(`
1377
+ mutation DeleteRole($id: ID!, $reassignToRoleId: ID) {
1378
+ deleteRole(id: $id, reassignToRoleId: $reassignToRoleId)
1379
+ }
1380
+ `, {
1381
+ id: roleId,
1382
+ reassignToRoleId
1383
+ }, contextWithWorkspace);
1384
+ logger.info("[RBAC] Role deleted", {
1385
+ roleId,
1386
+ success: response.deleteRole
1387
+ });
1388
+ return response.deleteRole;
1389
+ }
1390
+ /**
1391
+ * List roles in a workspace
1392
+ * Uses the new PBAC roles query
1393
+ *
1394
+ * @param workspaceId - Workspace ID (scopeId)
1395
+ * @param options - Filter and pagination options
1396
+ */
1397
+ async listRoles(workspaceId, options) {
1398
+ logger.debug("[RBAC] Listing roles", {
1399
+ workspaceId,
1400
+ options
1401
+ });
1402
+ const contextWithWorkspace = {
1403
+ ...this.context,
1404
+ workspaceId
1405
+ };
1406
+ const query = `
1407
+ query ListRoles($scopeId: String!, $filter: RoleFilterInput, $pagination: PaginationInput) {
1408
+ roles(scopeId: $scopeId, filter: $filter, pagination: $pagination) {
1409
+ id
1410
+ name
1411
+ description
1412
+ isSystem
1413
+ priority
1414
+ defaultPermissions {
1415
+ resourceType
1416
+ level
1417
+ }
1418
+ }
1419
+ }
1420
+ `;
1421
+ const variables = {
1422
+ scopeId: workspaceId,
1423
+ filter: options?.includeSystem !== void 0 ? { includeSystem: options.includeSystem } : void 0,
1424
+ pagination: {
1425
+ limit: options?.limit ?? 50,
1426
+ offset: options?.offset ?? 0
1427
+ }
1428
+ };
1429
+ const response = await this.client.query(query, variables, contextWithWorkspace);
1430
+ logger.debug("[RBAC] Roles listed", {
1431
+ workspaceId,
1432
+ count: response.roles.length
1433
+ });
1434
+ return response.roles.map((role) => ({
1435
+ id: role.id,
1436
+ name: role.name,
1437
+ description: role.description,
1438
+ defaultPermissions: role.defaultPermissions
1439
+ }));
1440
+ }
1441
+ /**
1442
+ * Get a specific role by ID
1443
+ * Uses the new PBAC role query
1444
+ *
1445
+ * @param roleId - Role ID
1446
+ * @param workspaceId - Workspace ID (scopeId)
1447
+ */
1448
+ async getRole(roleId, workspaceId) {
1449
+ logger.debug("[RBAC] Getting role", {
1450
+ roleId,
1451
+ workspaceId
1452
+ });
1453
+ const contextWithWorkspace = {
1454
+ ...this.context,
1455
+ workspaceId
1456
+ };
1457
+ const response = await this.client.query(`
1458
+ query GetRole($id: ID!) {
1459
+ role(id: $id) {
1460
+ id
1461
+ name
1462
+ description
1463
+ isSystem
1464
+ priority
1465
+ defaultPermissions {
1466
+ resourceType
1467
+ level
1468
+ }
1469
+ }
1470
+ }
1471
+ `, { id: roleId }, contextWithWorkspace);
1472
+ if (!response.role) {
1473
+ logger.debug("[RBAC] Role not found", { roleId });
1474
+ return null;
1475
+ }
1476
+ return {
1477
+ id: response.role.id,
1478
+ name: response.role.name,
1479
+ description: response.role.description,
1480
+ defaultPermissions: response.role.defaultPermissions
1481
+ };
1482
+ }
1483
+ };
1484
+
1485
+ export { createRBACDirectiveForLayer as a, createRBACDirective as i, createRBACClientFromEnv as n, createRBACDirectiveFromEnv as o, RBACClient as r, RBACModule as t };
1486
+ //# sourceMappingURL=rbac-BB9l9Xph.js.map