@burdenoff/microfe-auth 2026.510.127

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 (301) hide show
  1. package/README.md +12 -0
  2. package/dist/_virtual/_rolldown/runtime.js +13 -0
  3. package/dist/auth/AuthRoot.d.ts +30 -0
  4. package/dist/auth/AuthRoot.d.ts.map +1 -0
  5. package/dist/auth/AuthRoot.js +82 -0
  6. package/dist/auth/AuthRoot.js.map +1 -0
  7. package/dist/auth/AuthRoutes.d.ts +29 -0
  8. package/dist/auth/AuthRoutes.d.ts.map +1 -0
  9. package/dist/auth/AuthRoutes.js +271 -0
  10. package/dist/auth/AuthRoutes.js.map +1 -0
  11. package/dist/auth/components/AuthIcons.d.ts +17 -0
  12. package/dist/auth/components/AuthIcons.d.ts.map +1 -0
  13. package/dist/auth/components/AuthIcons.js +197 -0
  14. package/dist/auth/components/AuthIcons.js.map +1 -0
  15. package/dist/auth/components/AuthLayout.d.ts +17 -0
  16. package/dist/auth/components/AuthLayout.d.ts.map +1 -0
  17. package/dist/auth/components/AuthLayout.js +237 -0
  18. package/dist/auth/components/AuthLayout.js.map +1 -0
  19. package/dist/auth/components/CaptchaV2.d.ts +16 -0
  20. package/dist/auth/components/CaptchaV2.d.ts.map +1 -0
  21. package/dist/auth/components/CaptchaV2.js +47 -0
  22. package/dist/auth/components/CaptchaV2.js.map +1 -0
  23. package/dist/auth/components/ConfirmActionDialog.d.ts +16 -0
  24. package/dist/auth/components/ConfirmActionDialog.d.ts.map +1 -0
  25. package/dist/auth/components/ConfirmActionDialog.js +68 -0
  26. package/dist/auth/components/ConfirmActionDialog.js.map +1 -0
  27. package/dist/auth/components/index.d.ts +4 -0
  28. package/dist/auth/components/index.d.ts.map +1 -0
  29. package/dist/auth/components/profile/UserProfileMenu.d.ts +42 -0
  30. package/dist/auth/components/profile/UserProfileMenu.d.ts.map +1 -0
  31. package/dist/auth/components/profile/UserProfileMenu.js +91 -0
  32. package/dist/auth/components/profile/UserProfileMenu.js.map +1 -0
  33. package/dist/auth/components/workspace/WorkspaceSelector.d.ts +76 -0
  34. package/dist/auth/components/workspace/WorkspaceSelector.d.ts.map +1 -0
  35. package/dist/auth/components/workspace/WorkspaceSelector.js +240 -0
  36. package/dist/auth/components/workspace/WorkspaceSelector.js.map +1 -0
  37. package/dist/auth/constants/permissions.d.ts +30 -0
  38. package/dist/auth/constants/permissions.d.ts.map +1 -0
  39. package/dist/auth/constants/permissions.js +18 -0
  40. package/dist/auth/constants/permissions.js.map +1 -0
  41. package/dist/auth/constants/sessionKeys.d.ts +18 -0
  42. package/dist/auth/constants/sessionKeys.d.ts.map +1 -0
  43. package/dist/auth/constants/sessionKeys.js +6 -0
  44. package/dist/auth/constants/sessionKeys.js.map +1 -0
  45. package/dist/auth/hooks/index.d.ts +18 -0
  46. package/dist/auth/hooks/index.d.ts.map +1 -0
  47. package/dist/auth/hooks/index.js +16 -0
  48. package/dist/auth/hooks/useAccountOperations.d.ts +19 -0
  49. package/dist/auth/hooks/useAccountOperations.d.ts.map +1 -0
  50. package/dist/auth/hooks/useAccountOperations.js +52 -0
  51. package/dist/auth/hooks/useAccountOperations.js.map +1 -0
  52. package/dist/auth/hooks/useApiKeyOperations.d.ts +22 -0
  53. package/dist/auth/hooks/useApiKeyOperations.d.ts.map +1 -0
  54. package/dist/auth/hooks/useApiKeyOperations.js +4 -0
  55. package/dist/auth/hooks/useAppOperations.d.ts +26 -0
  56. package/dist/auth/hooks/useAppOperations.d.ts.map +1 -0
  57. package/dist/auth/hooks/useAppOperations.js +4 -0
  58. package/dist/auth/hooks/useAuthOperations.d.ts +57 -0
  59. package/dist/auth/hooks/useAuthOperations.d.ts.map +1 -0
  60. package/dist/auth/hooks/useAuthOperations.js +236 -0
  61. package/dist/auth/hooks/useAuthOperations.js.map +1 -0
  62. package/dist/auth/hooks/useAuthPermissions.d.ts +20 -0
  63. package/dist/auth/hooks/useAuthPermissions.d.ts.map +1 -0
  64. package/dist/auth/hooks/useAuthPermissions.js +22 -0
  65. package/dist/auth/hooks/useAuthPermissions.js.map +1 -0
  66. package/dist/auth/hooks/useCaptchaV3.d.ts +13 -0
  67. package/dist/auth/hooks/useCaptchaV3.d.ts.map +1 -0
  68. package/dist/auth/hooks/useCaptchaV3.js +19 -0
  69. package/dist/auth/hooks/useCaptchaV3.js.map +1 -0
  70. package/dist/auth/hooks/useContextSwitcherData.d.ts +106 -0
  71. package/dist/auth/hooks/useContextSwitcherData.d.ts.map +1 -0
  72. package/dist/auth/hooks/useContextSwitcherData.js +466 -0
  73. package/dist/auth/hooks/useContextSwitcherData.js.map +1 -0
  74. package/dist/auth/hooks/useDelegationOperations.d.ts +25 -0
  75. package/dist/auth/hooks/useDelegationOperations.d.ts.map +1 -0
  76. package/dist/auth/hooks/useDelegationOperations.js +4 -0
  77. package/dist/auth/hooks/useMfaOperations.d.ts +18 -0
  78. package/dist/auth/hooks/useMfaOperations.d.ts.map +1 -0
  79. package/dist/auth/hooks/useMfaOperations.js +103 -0
  80. package/dist/auth/hooks/useMfaOperations.js.map +1 -0
  81. package/dist/auth/hooks/useMyWorkspaces.d.ts +45 -0
  82. package/dist/auth/hooks/useMyWorkspaces.d.ts.map +1 -0
  83. package/dist/auth/hooks/useMyWorkspaces.js +140 -0
  84. package/dist/auth/hooks/useMyWorkspaces.js.map +1 -0
  85. package/dist/auth/hooks/useOAuthOperations.d.ts +19 -0
  86. package/dist/auth/hooks/useOAuthOperations.d.ts.map +1 -0
  87. package/dist/auth/hooks/useOAuthOperations.js +103 -0
  88. package/dist/auth/hooks/useOAuthOperations.js.map +1 -0
  89. package/dist/auth/hooks/usePasswordOperations.d.ts +13 -0
  90. package/dist/auth/hooks/usePasswordOperations.d.ts.map +1 -0
  91. package/dist/auth/hooks/usePasswordOperations.js +56 -0
  92. package/dist/auth/hooks/usePasswordOperations.js.map +1 -0
  93. package/dist/auth/hooks/useSessionOperations.d.ts +41 -0
  94. package/dist/auth/hooks/useSessionOperations.d.ts.map +1 -0
  95. package/dist/auth/hooks/useSessionOperations.js +59 -0
  96. package/dist/auth/hooks/useSessionOperations.js.map +1 -0
  97. package/dist/auth/hooks/useSsoOperations.d.ts +65 -0
  98. package/dist/auth/hooks/useSsoOperations.d.ts.map +1 -0
  99. package/dist/auth/hooks/useSsoOperations.js +236 -0
  100. package/dist/auth/hooks/useSsoOperations.js.map +1 -0
  101. package/dist/auth/hooks/useTokenRefresh.d.ts +56 -0
  102. package/dist/auth/hooks/useTokenRefresh.d.ts.map +1 -0
  103. package/dist/auth/hooks/useTokenRefresh.js +53 -0
  104. package/dist/auth/hooks/useTokenRefresh.js.map +1 -0
  105. package/dist/auth/hooks/useUserOperations.d.ts +32 -0
  106. package/dist/auth/hooks/useUserOperations.d.ts.map +1 -0
  107. package/dist/auth/hooks/useUserOperations.js +100 -0
  108. package/dist/auth/hooks/useUserOperations.js.map +1 -0
  109. package/dist/auth/hooks/useWorkspaceOperations.d.ts +35 -0
  110. package/dist/auth/hooks/useWorkspaceOperations.d.ts.map +1 -0
  111. package/dist/auth/hooks/useWorkspaceOperations.js +35 -0
  112. package/dist/auth/hooks/useWorkspaceOperations.js.map +1 -0
  113. package/dist/auth/hooks/useWorkspaceToken.d.ts +56 -0
  114. package/dist/auth/hooks/useWorkspaceToken.d.ts.map +1 -0
  115. package/dist/auth/hooks/useWorkspaceToken.js +94 -0
  116. package/dist/auth/hooks/useWorkspaceToken.js.map +1 -0
  117. package/dist/auth/index.d.ts +63 -0
  118. package/dist/auth/index.d.ts.map +1 -0
  119. package/dist/auth/index.js +18 -0
  120. package/dist/auth/pages/ApiKeysPage.d.ts +5 -0
  121. package/dist/auth/pages/ApiKeysPage.d.ts.map +1 -0
  122. package/dist/auth/pages/AppsPage.d.ts +5 -0
  123. package/dist/auth/pages/AppsPage.d.ts.map +1 -0
  124. package/dist/auth/pages/AuditLogPage.d.ts +5 -0
  125. package/dist/auth/pages/AuditLogPage.d.ts.map +1 -0
  126. package/dist/auth/pages/AuditLogPage.js +129 -0
  127. package/dist/auth/pages/AuditLogPage.js.map +1 -0
  128. package/dist/auth/pages/DelegationsPage.d.ts +5 -0
  129. package/dist/auth/pages/DelegationsPage.d.ts.map +1 -0
  130. package/dist/auth/pages/EmailVerifyPage.d.ts +5 -0
  131. package/dist/auth/pages/EmailVerifyPage.d.ts.map +1 -0
  132. package/dist/auth/pages/EmailVerifyPage.js +166 -0
  133. package/dist/auth/pages/EmailVerifyPage.js.map +1 -0
  134. package/dist/auth/pages/LoginPage.d.ts +6 -0
  135. package/dist/auth/pages/LoginPage.d.ts.map +1 -0
  136. package/dist/auth/pages/LoginPage.js +575 -0
  137. package/dist/auth/pages/LoginPage.js.map +1 -0
  138. package/dist/auth/pages/MagicLinkPage.d.ts +6 -0
  139. package/dist/auth/pages/MagicLinkPage.d.ts.map +1 -0
  140. package/dist/auth/pages/MagicLinkPage.js +219 -0
  141. package/dist/auth/pages/MagicLinkPage.js.map +1 -0
  142. package/dist/auth/pages/MfaSetupPage.d.ts +5 -0
  143. package/dist/auth/pages/MfaSetupPage.d.ts.map +1 -0
  144. package/dist/auth/pages/MfaSetupPage.js +341 -0
  145. package/dist/auth/pages/MfaSetupPage.js.map +1 -0
  146. package/dist/auth/pages/MfaVerifyPage.d.ts +7 -0
  147. package/dist/auth/pages/MfaVerifyPage.d.ts.map +1 -0
  148. package/dist/auth/pages/MfaVerifyPage.js +189 -0
  149. package/dist/auth/pages/MfaVerifyPage.js.map +1 -0
  150. package/dist/auth/pages/OAuthCallbackPage.d.ts +7 -0
  151. package/dist/auth/pages/OAuthCallbackPage.d.ts.map +1 -0
  152. package/dist/auth/pages/OAuthCallbackPage.js +100 -0
  153. package/dist/auth/pages/OAuthCallbackPage.js.map +1 -0
  154. package/dist/auth/pages/PasswordResetPage.d.ts +6 -0
  155. package/dist/auth/pages/PasswordResetPage.d.ts.map +1 -0
  156. package/dist/auth/pages/PasswordResetPage.js +352 -0
  157. package/dist/auth/pages/PasswordResetPage.js.map +1 -0
  158. package/dist/auth/pages/ReactivatePage.d.ts +6 -0
  159. package/dist/auth/pages/ReactivatePage.d.ts.map +1 -0
  160. package/dist/auth/pages/ReactivatePage.js +217 -0
  161. package/dist/auth/pages/ReactivatePage.js.map +1 -0
  162. package/dist/auth/pages/RegisterPage.d.ts +5 -0
  163. package/dist/auth/pages/RegisterPage.d.ts.map +1 -0
  164. package/dist/auth/pages/RegisterPage.js +439 -0
  165. package/dist/auth/pages/RegisterPage.js.map +1 -0
  166. package/dist/auth/pages/SSORelayCallbackPage.d.ts +8 -0
  167. package/dist/auth/pages/SSORelayCallbackPage.d.ts.map +1 -0
  168. package/dist/auth/pages/SSORelayCallbackPage.js +48 -0
  169. package/dist/auth/pages/SSORelayCallbackPage.js.map +1 -0
  170. package/dist/auth/pages/SSORelayPage.d.ts +18 -0
  171. package/dist/auth/pages/SSORelayPage.d.ts.map +1 -0
  172. package/dist/auth/pages/SSORelayPage.js +134 -0
  173. package/dist/auth/pages/SSORelayPage.js.map +1 -0
  174. package/dist/auth/pages/SecurityPage.d.ts +5 -0
  175. package/dist/auth/pages/SecurityPage.d.ts.map +1 -0
  176. package/dist/auth/pages/SecurityPage.js +587 -0
  177. package/dist/auth/pages/SecurityPage.js.map +1 -0
  178. package/dist/auth/pages/SessionBridgePage.d.ts +14 -0
  179. package/dist/auth/pages/SessionBridgePage.d.ts.map +1 -0
  180. package/dist/auth/pages/SessionBridgePage.js +231 -0
  181. package/dist/auth/pages/SessionBridgePage.js.map +1 -0
  182. package/dist/auth/pages/SessionsPage.d.ts +5 -0
  183. package/dist/auth/pages/SessionsPage.d.ts.map +1 -0
  184. package/dist/auth/pages/SessionsPage.js +258 -0
  185. package/dist/auth/pages/SessionsPage.js.map +1 -0
  186. package/dist/auth/pages/SsoCallbackPage.d.ts +8 -0
  187. package/dist/auth/pages/SsoCallbackPage.d.ts.map +1 -0
  188. package/dist/auth/pages/SsoCallbackPage.js +188 -0
  189. package/dist/auth/pages/SsoCallbackPage.js.map +1 -0
  190. package/dist/auth/pages/SsoConfigPage.d.ts +6 -0
  191. package/dist/auth/pages/SsoConfigPage.d.ts.map +1 -0
  192. package/dist/auth/pages/SsoConfigPage.js +1144 -0
  193. package/dist/auth/pages/SsoConfigPage.js.map +1 -0
  194. package/dist/auth/pages/SsoLoginPage.d.ts +7 -0
  195. package/dist/auth/pages/SsoLoginPage.d.ts.map +1 -0
  196. package/dist/auth/pages/SsoLoginPage.js +236 -0
  197. package/dist/auth/pages/SsoLoginPage.js.map +1 -0
  198. package/dist/auth/pages/UserDetailsPage.d.ts +11 -0
  199. package/dist/auth/pages/UserDetailsPage.d.ts.map +1 -0
  200. package/dist/auth/pages/UserDetailsPage.js +338 -0
  201. package/dist/auth/pages/UserDetailsPage.js.map +1 -0
  202. package/dist/auth/pages/UserProfilePage.d.ts +5 -0
  203. package/dist/auth/pages/UserProfilePage.d.ts.map +1 -0
  204. package/dist/auth/pages/UserProfilePage.js +445 -0
  205. package/dist/auth/pages/UserProfilePage.js.map +1 -0
  206. package/dist/auth/pages/UsersPage.d.ts +5 -0
  207. package/dist/auth/pages/UsersPage.d.ts.map +1 -0
  208. package/dist/auth/pages/UsersPage.js +899 -0
  209. package/dist/auth/pages/UsersPage.js.map +1 -0
  210. package/dist/auth/providers/AuthProvider.d.ts +18 -0
  211. package/dist/auth/providers/AuthProvider.d.ts.map +1 -0
  212. package/dist/auth/providers/AuthProvider.js +36 -0
  213. package/dist/auth/providers/AuthProvider.js.map +1 -0
  214. package/dist/auth/providers/CaptchaProvider.d.ts +13 -0
  215. package/dist/auth/providers/CaptchaProvider.d.ts.map +1 -0
  216. package/dist/auth/providers/CaptchaProvider.js +21 -0
  217. package/dist/auth/providers/CaptchaProvider.js.map +1 -0
  218. package/dist/auth/store/authStore.d.ts +91 -0
  219. package/dist/auth/store/authStore.d.ts.map +1 -0
  220. package/dist/auth/store/authStore.js +314 -0
  221. package/dist/auth/store/authStore.js.map +1 -0
  222. package/dist/auth/types/index.d.ts +636 -0
  223. package/dist/auth/types/index.d.ts.map +1 -0
  224. package/dist/auth/utils/captchaConfig.d.ts +4 -0
  225. package/dist/auth/utils/captchaConfig.d.ts.map +1 -0
  226. package/dist/auth/utils/captchaConfig.js +13 -0
  227. package/dist/auth/utils/captchaConfig.js.map +1 -0
  228. package/dist/auth/utils/formatters.d.ts +37 -0
  229. package/dist/auth/utils/formatters.d.ts.map +1 -0
  230. package/dist/auth/utils/formatters.js +48 -0
  231. package/dist/auth/utils/formatters.js.map +1 -0
  232. package/dist/auth/utils/gatewayBaseUrls.d.ts +6 -0
  233. package/dist/auth/utils/gatewayBaseUrls.d.ts.map +1 -0
  234. package/dist/auth/utils/gatewayBaseUrls.js +18 -0
  235. package/dist/auth/utils/gatewayBaseUrls.js.map +1 -0
  236. package/dist/auth/utils/index.d.ts +3 -0
  237. package/dist/auth/utils/index.d.ts.map +1 -0
  238. package/dist/auth/utils/validation.d.ts +30 -0
  239. package/dist/auth/utils/validation.d.ts.map +1 -0
  240. package/dist/auth/utils/validation.js +15 -0
  241. package/dist/auth/utils/validation.js.map +1 -0
  242. package/dist/dev/main.d.ts +2 -0
  243. package/dist/dev/main.d.ts.map +1 -0
  244. package/dist/generated/global-operations.d.ts +2978 -0
  245. package/dist/generated/global-operations.d.ts.map +1 -0
  246. package/dist/generated/global-operations.js +944 -0
  247. package/dist/generated/global-operations.js.map +1 -0
  248. package/dist/generated/global-types.d.ts +21253 -0
  249. package/dist/generated/global-types.d.ts.map +1 -0
  250. package/dist/generated/wspace-operations.d.ts +2 -0
  251. package/dist/generated/wspace-operations.d.ts.map +1 -0
  252. package/dist/generated/wspace-types.d.ts +55214 -0
  253. package/dist/generated/wspace-types.d.ts.map +1 -0
  254. package/dist/index.d.ts +4 -0
  255. package/dist/index.d.ts.map +1 -0
  256. package/dist/index.js +20 -0
  257. package/dist/microfe-auth.css +3 -0
  258. package/dist/node_modules/hoist-non-react-statics/dist/hoist-non-react-statics.cjs.js +70 -0
  259. package/dist/node_modules/hoist-non-react-statics/dist/hoist-non-react-statics.cjs.js.map +1 -0
  260. package/dist/node_modules/object-assign/index.js +41 -0
  261. package/dist/node_modules/object-assign/index.js.map +1 -0
  262. package/dist/node_modules/prop-types/checkPropTypes.js +46 -0
  263. package/dist/node_modules/prop-types/checkPropTypes.js.map +1 -0
  264. package/dist/node_modules/prop-types/factoryWithThrowingShims.js +49 -0
  265. package/dist/node_modules/prop-types/factoryWithThrowingShims.js.map +1 -0
  266. package/dist/node_modules/prop-types/factoryWithTypeCheckers.js +272 -0
  267. package/dist/node_modules/prop-types/factoryWithTypeCheckers.js.map +1 -0
  268. package/dist/node_modules/prop-types/index.js +16 -0
  269. package/dist/node_modules/prop-types/index.js.map +1 -0
  270. package/dist/node_modules/prop-types/lib/ReactPropTypesSecret.js +10 -0
  271. package/dist/node_modules/prop-types/lib/ReactPropTypesSecret.js.map +1 -0
  272. package/dist/node_modules/prop-types/lib/has.js +10 -0
  273. package/dist/node_modules/prop-types/lib/has.js.map +1 -0
  274. package/dist/node_modules/qrcode.react/lib/esm/index.js +959 -0
  275. package/dist/node_modules/qrcode.react/lib/esm/index.js.map +1 -0
  276. package/dist/node_modules/react-async-script/lib/esm/async-script-loader.js +114 -0
  277. package/dist/node_modules/react-async-script/lib/esm/async-script-loader.js.map +1 -0
  278. package/dist/node_modules/react-google-recaptcha/lib/esm/index.js +8 -0
  279. package/dist/node_modules/react-google-recaptcha/lib/esm/index.js.map +1 -0
  280. package/dist/node_modules/react-google-recaptcha/lib/esm/recaptcha-wrapper.js +20 -0
  281. package/dist/node_modules/react-google-recaptcha/lib/esm/recaptcha-wrapper.js.map +1 -0
  282. package/dist/node_modules/react-google-recaptcha/lib/esm/recaptcha.js +148 -0
  283. package/dist/node_modules/react-google-recaptcha/lib/esm/recaptcha.js.map +1 -0
  284. package/dist/node_modules/react-google-recaptcha-v3/dist/react-google-recaptcha-v3.esm.js +445 -0
  285. package/dist/node_modules/react-google-recaptcha-v3/dist/react-google-recaptcha-v3.esm.js.map +1 -0
  286. package/dist/node_modules/react-is/cjs/react-is.development.js +84 -0
  287. package/dist/node_modules/react-is/cjs/react-is.development.js.map +1 -0
  288. package/dist/node_modules/react-is/cjs/react-is.production.min.js +64 -0
  289. package/dist/node_modules/react-is/cjs/react-is.production.min.js.map +1 -0
  290. package/dist/node_modules/react-is/index.js +12 -0
  291. package/dist/node_modules/react-is/index.js.map +1 -0
  292. package/dist/shared/hooks/index.d.ts +7 -0
  293. package/dist/shared/hooks/index.d.ts.map +1 -0
  294. package/dist/shared/index.d.ts +6 -0
  295. package/dist/shared/index.d.ts.map +1 -0
  296. package/dist/shared/types/index.d.ts +109 -0
  297. package/dist/shared/types/index.d.ts.map +1 -0
  298. package/dist/utils/nativeBridge.d.ts +3 -0
  299. package/dist/utils/nativeBridge.d.ts.map +1 -0
  300. package/dist/utils/nativeBridge.js +2 -0
  301. package/package.json +114 -0
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Hook for auth admin RBAC permissions.
3
+ *
4
+ * Only covers admin-facing operations. Public auth flows and self-service
5
+ * operations don't need RBAC checks — they're either @rbac(public: true)
6
+ * or scoped to the current user's own data.
7
+ */
8
+ export declare function useAuthPermissions(): {
9
+ canViewUsers: boolean;
10
+ canUpdateUsers: boolean;
11
+ canDeleteUsers: boolean;
12
+ canViewApps: boolean;
13
+ canCreateApps: boolean;
14
+ canUpdateApps: boolean;
15
+ canManageSsoConfig: boolean;
16
+ canManageOidcConfig: boolean;
17
+ canManageAuthMethods: boolean;
18
+ isLoading: boolean;
19
+ };
20
+ //# sourceMappingURL=useAuthPermissions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useAuthPermissions.d.ts","sourceRoot":"","sources":["../../../src/auth/hooks/useAuthPermissions.ts"],"names":[],"mappings":"AAGA;;;;;;GAMG;AACH,wBAAgB,kBAAkB;;;;;;;;;;;EAuBjC"}
@@ -0,0 +1,22 @@
1
+ import { AUTH_PERMISSIONS as e } from "../constants/permissions.js";
2
+ import { usePermissions as t } from "@burdenoff/fe-libs/shared/providers/shell";
3
+ //#region src/auth/hooks/useAuthPermissions.ts
4
+ function n() {
5
+ let { hasPermission: n, isLoading: r } = t();
6
+ return {
7
+ canViewUsers: n(e.USER_READ),
8
+ canUpdateUsers: n(e.USER_UPDATE),
9
+ canDeleteUsers: n(e.USER_DELETE),
10
+ canViewApps: n(e.APP_READ),
11
+ canCreateApps: n(e.APP_CREATE),
12
+ canUpdateApps: n(e.APP_UPDATE),
13
+ canManageSsoConfig: n(e.SSO_CONFIG_MANAGE),
14
+ canManageOidcConfig: n(e.OIDC_CONFIG_MANAGE),
15
+ canManageAuthMethods: n(e.AUTH_METHOD_UPDATE),
16
+ isLoading: r
17
+ };
18
+ }
19
+ //#endregion
20
+ export { n as useAuthPermissions };
21
+
22
+ //# sourceMappingURL=useAuthPermissions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useAuthPermissions.js","names":[],"sources":["../../../src/auth/hooks/useAuthPermissions.ts"],"sourcesContent":["import { usePermissions } from \"@burdenoff/fe-libs/shared/providers/shell\";\nimport { AUTH_PERMISSIONS } from \"../constants/permissions\";\n\n/**\n * Hook for auth admin RBAC permissions.\n *\n * Only covers admin-facing operations. Public auth flows and self-service\n * operations don't need RBAC checks — they're either @rbac(public: true)\n * or scoped to the current user's own data.\n */\nexport function useAuthPermissions() {\n const { hasPermission, isLoading } = usePermissions();\n\n return {\n // User management (admin pages)\n canViewUsers: hasPermission(AUTH_PERMISSIONS.USER_READ),\n canUpdateUsers: hasPermission(AUTH_PERMISSIONS.USER_UPDATE),\n canDeleteUsers: hasPermission(AUTH_PERMISSIONS.USER_DELETE),\n\n // OAuth app management\n canViewApps: hasPermission(AUTH_PERMISSIONS.APP_READ),\n canCreateApps: hasPermission(AUTH_PERMISSIONS.APP_CREATE),\n canUpdateApps: hasPermission(AUTH_PERMISSIONS.APP_UPDATE),\n\n // SSO/OIDC configuration\n canManageSsoConfig: hasPermission(AUTH_PERMISSIONS.SSO_CONFIG_MANAGE),\n canManageOidcConfig: hasPermission(AUTH_PERMISSIONS.OIDC_CONFIG_MANAGE),\n\n // Auth method configuration\n canManageAuthMethods: hasPermission(AUTH_PERMISSIONS.AUTH_METHOD_UPDATE),\n\n isLoading,\n };\n}\n"],"mappings":";;;AAUA,SAAgB,IAAqB;CACnC,IAAM,EAAE,kBAAe,iBAAc,GAAgB;AAErD,QAAO;EAEL,cAAc,EAAc,EAAiB,UAAU;EACvD,gBAAgB,EAAc,EAAiB,YAAY;EAC3D,gBAAgB,EAAc,EAAiB,YAAY;EAG3D,aAAa,EAAc,EAAiB,SAAS;EACrD,eAAe,EAAc,EAAiB,WAAW;EACzD,eAAe,EAAc,EAAiB,WAAW;EAGzD,oBAAoB,EAAc,EAAiB,kBAAkB;EACrE,qBAAqB,EAAc,EAAiB,mBAAmB;EAGvE,sBAAsB,EAAc,EAAiB,mBAAmB;EAExE;EACD"}
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Hook for reCAPTCHA v3 invisible verification.
3
+ * Returns a no-op when VITE_CAPTCHA_ENABLED is not "true".
4
+ *
5
+ * When enabled, dynamically imports `react-google-recaptcha-v3` and uses
6
+ * the `useGoogleReCaptcha` hook from the `GoogleReCaptchaProvider` context.
7
+ * The provider must be mounted above this hook in the component tree
8
+ * (handled by CaptchaProvider in AuthRoot).
9
+ */
10
+ export declare function useCaptchaV3(): {
11
+ executeRecaptcha: (action: string) => Promise<string | undefined>;
12
+ };
13
+ //# sourceMappingURL=useCaptchaV3.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useCaptchaV3.d.ts","sourceRoot":"","sources":["../../../src/auth/hooks/useCaptchaV3.ts"],"names":[],"mappings":"AAMA;;;;;;;;GAQG;AACH,wBAAgB,YAAY;+BAaT,MAAM,KAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC;EA8BtD"}
@@ -0,0 +1,19 @@
1
+ import { isCaptchaEnabled as e, requireRecaptchaSiteKey as t } from "../utils/captchaConfig.js";
2
+ import { useCallback as n, useEffect as r } from "react";
3
+ //#region src/auth/hooks/useCaptchaV3.ts
4
+ function i() {
5
+ return r(() => {
6
+ e() && import("../../node_modules/react-google-recaptcha-v3/dist/react-google-recaptcha-v3.esm.js").catch(() => {
7
+ console.warn("[captcha-v3] Failed to load react-google-recaptcha-v3");
8
+ });
9
+ }, []), { executeRecaptcha: n(async (n) => {
10
+ if (!e()) return;
11
+ let r = t(), i = window.grecaptcha;
12
+ if (i?.execute) return i.execute(r, { action: n });
13
+ console.warn("[captcha-v3] grecaptcha not yet available");
14
+ }, []) };
15
+ }
16
+ //#endregion
17
+ export { i as useCaptchaV3 };
18
+
19
+ //# sourceMappingURL=useCaptchaV3.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useCaptchaV3.js","names":[],"sources":["../../../src/auth/hooks/useCaptchaV3.ts"],"sourcesContent":["import { useCallback, useEffect } from \"react\";\nimport {\n isCaptchaEnabled,\n requireRecaptchaSiteKey,\n} from \"../utils/captchaConfig\";\n\n/**\n * Hook for reCAPTCHA v3 invisible verification.\n * Returns a no-op when VITE_CAPTCHA_ENABLED is not \"true\".\n *\n * When enabled, dynamically imports `react-google-recaptcha-v3` and uses\n * the `useGoogleReCaptcha` hook from the `GoogleReCaptchaProvider` context.\n * The provider must be mounted above this hook in the component tree\n * (handled by CaptchaProvider in AuthRoot).\n */\nexport function useCaptchaV3() {\n useEffect(() => {\n if (!isCaptchaEnabled()) return;\n\n // Dynamically import react-google-recaptcha-v3 so the provider's global\n // grecaptcha object is initialized. We don't use the module export\n // directly — execute() below reads from window.grecaptcha instead.\n import(\"react-google-recaptcha-v3\").catch(() => {\n console.warn(\"[captcha-v3] Failed to load react-google-recaptcha-v3\");\n });\n }, []);\n\n const execute = useCallback(\n async (action: string): Promise<string | undefined> => {\n if (!isCaptchaEnabled()) {\n return undefined;\n }\n\n const siteKey = requireRecaptchaSiteKey();\n\n // Use the global grecaptcha object that GoogleReCaptchaProvider sets up\n const grecaptcha = (window as unknown as Record<string, unknown>)[\n \"grecaptcha\"\n ] as\n | {\n execute?: (\n siteKey: string,\n options: { action: string },\n ) => Promise<string>;\n }\n | undefined;\n\n if (grecaptcha?.execute) {\n return grecaptcha.execute(siteKey, { action });\n }\n\n console.warn(\"[captcha-v3] grecaptcha not yet available\");\n return undefined;\n },\n [],\n );\n\n return { executeRecaptcha: execute };\n}\n"],"mappings":";;;AAeA,SAAgB,IAAe;AA0C7B,QAzCA,QAAgB;AACT,KAAkB,IAKvB,OAAO,sFAA6B,YAAY;AAC9C,WAAQ,KAAK,wDAAwD;IACrE;IACD,EAAE,CAAC,EAgCC,EAAE,kBA9BO,EACd,OAAO,MAAgD;AACrD,MAAI,CAAC,GAAkB,CACrB;EAGF,IAAM,IAAU,GAAyB,EAGnC,IAAc,OAClB;AAUF,MAAI,GAAY,QACd,QAAO,EAAW,QAAQ,GAAS,EAAE,WAAQ,CAAC;AAGhD,UAAQ,KAAK,4CAA4C;IAG3D,EAAE,CACH,EAEmC"}
@@ -0,0 +1,106 @@
1
+ import { Organization, Workspace, Project } from '../types';
2
+
3
+ export interface UseContextSwitcherDataOptions {
4
+ /**
5
+ * Optional Global API Gateway base URL override.
6
+ * If not provided, uses GATEWAYS config from fe-libs.
7
+ */
8
+ globalBaseUrl?: string;
9
+ /**
10
+ * Optional Workspaces API Gateway base URL override.
11
+ * If not provided, uses GATEWAYS config from fe-libs.
12
+ */
13
+ workspaceBaseUrl?: string;
14
+ /** Disable initial organization/workspace bootstrap fetches */
15
+ disableBootstrap?: boolean;
16
+ /** Disable the workspace sync effect */
17
+ disableWorkspaceSync?: boolean;
18
+ /** Disable the project sync effect */
19
+ disableProjectSync?: boolean;
20
+ /** Only hydrate the workspace token; do not eagerly fetch projects */
21
+ skipProjectFetch?: boolean;
22
+ }
23
+ /**
24
+ * Hook for managing the context switcher data (organizations, workspaces, projects)
25
+ *
26
+ * Data flow:
27
+ * 1. fetchOrganizations() - Get all orgs user has access to (Global Gateway)
28
+ * 2. selectOrganization(org) - Set current org & fetch workspaces for that org
29
+ * 3. selectWorkspace(ws) - Issue workspace token & fetch projects
30
+ * 4. selectProject(proj) - Set current project
31
+ *
32
+ * All GraphQL calls go through graphqlFetch from fe-libs which automatically
33
+ * resolves gateway URLs and injects auth + locale headers.
34
+ *
35
+ * @param options - Optional configuration (gateway base URL overrides)
36
+ */
37
+ export declare function useContextSwitcherData(options?: UseContextSwitcherDataOptions): {
38
+ organizations: Organization[];
39
+ workspaces: Workspace[];
40
+ projects: Project[];
41
+ currentOrganizationId: string | null;
42
+ currentWorkspaceId: string | null;
43
+ currentProjectId: string | null;
44
+ currentOrganization: Organization | undefined;
45
+ currentWorkspace: Workspace | undefined;
46
+ currentProject: Project | undefined;
47
+ workspaceToken: string | null;
48
+ isLoadingOrganizations: boolean;
49
+ isLoadingWorkspaces: boolean;
50
+ isLoadingProjects: boolean;
51
+ isLoading: boolean;
52
+ error: string | null;
53
+ fetchOrganizations: () => Promise<Organization[]>;
54
+ fetchWorkspacesForOrg: (organizationId: string) => Promise<Workspace[]>;
55
+ issueWorkspaceToken: (organizationId: string, workspaceId?: string) => Promise<{
56
+ success: boolean;
57
+ token?: string;
58
+ resolvedWorkspaceId?: string;
59
+ error?: string;
60
+ }>;
61
+ fetchProjects: () => Promise<Project[]>;
62
+ selectOrganization: (org: Organization) => Promise<Workspace[]>;
63
+ selectWorkspace: (workspace: Workspace) => Promise<{
64
+ success: boolean;
65
+ projects?: Project[];
66
+ error?: string;
67
+ }>;
68
+ selectProject: (project: Project) => void;
69
+ };
70
+ /**
71
+ * Hook to reactively ensure workspaces are synced with the current organization.
72
+ *
73
+ * This handles edge cases where the organization changes but workspaces
74
+ * from a different org are still in the store (e.g., stale data, race conditions).
75
+ *
76
+ * Usage:
77
+ * ```tsx
78
+ * import { useWorkspaceSyncEffect } from '@burdenoff/microfe-auth';
79
+ *
80
+ * function MyComponent() {
81
+ * useWorkspaceSyncEffect(); // Ensures workspaces stay in sync
82
+ * // ...
83
+ * }
84
+ * ```
85
+ */
86
+ export declare function useWorkspaceSyncEffect(options?: UseContextSwitcherDataOptions): void;
87
+ /**
88
+ * Hook to reactively ensure projects are loaded when a workspace is selected.
89
+ *
90
+ * This handles the case where a workspace is auto-selected (from URL/localStorage)
91
+ * but projects haven't been fetched yet. It will:
92
+ * 1. Issue a workspace token if not present
93
+ * 2. Fetch projects for the selected workspace
94
+ *
95
+ * Usage:
96
+ * ```tsx
97
+ * import { useProjectSyncEffect } from '@burdenoff/microfe-auth';
98
+ *
99
+ * function MyComponent() {
100
+ * useProjectSyncEffect(); // Ensures projects are loaded for selected workspace
101
+ * // ...
102
+ * }
103
+ * ```
104
+ */
105
+ export declare function useProjectSyncEffect(options?: UseContextSwitcherDataOptions): void;
106
+ //# sourceMappingURL=useContextSwitcherData.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useContextSwitcherData.d.ts","sourceRoot":"","sources":["../../../src/auth/hooks/useContextSwitcherData.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,YAAY,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AAOjE,MAAM,WAAW,6BAA6B;IAC5C;;;OAGG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB;;;OAGG;IACH,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,+DAA+D;IAC/D,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,wCAAwC;IACxC,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAC/B,sCAAsC;IACtC,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B,sEAAsE;IACtE,gBAAgB,CAAC,EAAE,OAAO,CAAC;CAC5B;AAiWD;;;;;;;;;;;;;GAaG;AACH,wBAAgB,sBAAsB,CACpC,OAAO,CAAC,EAAE,6BAA6B;;;;;;;;;;;;;;;;8BA0GU,OAAO,CAAC,YAAY,EAAE,CAAC;4CAmT/C,MAAM,KAAG,OAAO,CAAC,SAAS,EAAE,CAAC;0CAoElC,MAAM,gBACR,MAAM,KACnB,OAAO,CAAC;QACT,OAAO,EAAE,OAAO,CAAC;QACjB,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,mBAAmB,CAAC,EAAE,MAAM,CAAC;QAC7B,KAAK,CAAC,EAAE,MAAM,CAAC;KAChB,CAAC;yBAuEwC,OAAO,CAAC,OAAO,EAAE,CAAC;8BA8DhD,YAAY,KAAG,OAAO,CAAC,SAAS,EAAE,CAAC;iCAiBlC,SAAS,KACnB,OAAO,CAAC;QACT,OAAO,EAAE,OAAO,CAAC;QACjB,QAAQ,CAAC,EAAE,OAAO,EAAE,CAAC;QACrB,KAAK,CAAC,EAAE,MAAM,CAAC;KAChB,CAAC;6BAiDwC,OAAO,KAAG,IAAI;EAqD3D;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,sBAAsB,CACpC,OAAO,CAAC,EAAE,6BAA6B,QA4DxC;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,oBAAoB,CAAC,OAAO,CAAC,EAAE,6BAA6B,QAoR3E"}
@@ -0,0 +1,466 @@
1
+ import { useAuthStore as e } from "../store/authStore.js";
2
+ import { resolveGatewayBaseUrls as t } from "../utils/gatewayBaseUrls.js";
3
+ import { useCallback as n, useEffect as r, useRef as i, useState as a } from "react";
4
+ import { getStoredAuthToken as o, graphqlFetch as s } from "@burdenoff/fe-libs/shared/graphql";
5
+ import { useActiveContext as c } from "@burdenoff/fe-libs/shared/providers/shell/ActiveContextProvider";
6
+ //#region src/auth/hooks/useContextSwitcherData.ts
7
+ var l = "\n query MyOrganizations {\n myOrganizations {\n total\n items {\n id\n name\n slug\n tenantId\n description\n logo\n website\n status\n type\n createdAt\n updatedAt\n }\n }\n }\n", u = "\n query WorkspacesByOrg($filter: WorkspaceFilterInput) {\n workspaces(filter: $filter) {\n total\n items {\n id\n name\n slug\n tenantId\n organizationId\n type\n status\n region\n createdAt\n updatedAt\n }\n }\n }\n", d = "\n query ContextSwitcherBootstrap($filter: WorkspaceFilterInput) {\n myOrganizations {\n total\n items {\n id\n name\n slug\n tenantId\n description\n logo\n website\n status\n type\n createdAt\n updatedAt\n }\n }\n workspaces(filter: $filter) {\n total\n items {\n id\n name\n slug\n tenantId\n organizationId\n type\n status\n region\n createdAt\n updatedAt\n }\n }\n }\n", f = "\n mutation IssueWorkspaceToken($input: IssueWorkspaceTokenInput!) {\n issueWorkspaceToken(input: $input) {\n success\n token\n expiresAt\n organizationId\n workspaceId\n projectId\n scopes\n error {\n code\n message\n }\n }\n }\n", p = "\n query Projects($filter: ProjectFilterInput) {\n projects(filter: $filter) {\n total\n items {\n id\n name\n key\n workspaceId\n status\n archived\n createdAt\n updatedAt\n }\n }\n }\n", m = "\n mutation CreateDefaultProject($input: CreateProjectInput!) {\n createProject(input: $input) {\n id\n name\n key\n workspaceId\n status\n archived\n createdAt\n updatedAt\n }\n }\n";
8
+ async function h({ authToken: e, workspaceBaseUrl: t, workspaceToken: n }) {
9
+ let r = await s({
10
+ gateway: "workspace",
11
+ query: m,
12
+ variables: { input: { name: "Default Project" } },
13
+ authToken: e,
14
+ workspaceToken: n,
15
+ baseUrl: t
16
+ });
17
+ return r.errors?.length ? (console.warn("Failed to create default project:", r.errors), null) : r.data?.createProject ?? null;
18
+ }
19
+ function g(e, t = 3e4) {
20
+ try {
21
+ let n = JSON.parse(atob(e.split(".")[1]));
22
+ return n.exp ? n.exp * 1e3 < Date.now() + t : !1;
23
+ } catch {
24
+ return !0;
25
+ }
26
+ }
27
+ function _(e) {
28
+ try {
29
+ let t = JSON.parse(atob(e.split(".")[1]));
30
+ return {
31
+ workspaceId: typeof t.workspaceId == "string" ? t.workspaceId : void 0,
32
+ organizationId: typeof t.organizationId == "string" ? t.organizationId : void 0,
33
+ exp: typeof t.exp == "number" ? t.exp : void 0
34
+ };
35
+ } catch {
36
+ return null;
37
+ }
38
+ }
39
+ function v(e, t) {
40
+ if (!e || g(e)) return !1;
41
+ let n = _(e);
42
+ return !(!n || t.workspaceId && n.workspaceId !== t.workspaceId || t.organizationId && n.organizationId !== t.organizationId);
43
+ }
44
+ var y = class extends Error {
45
+ constructor(e) {
46
+ super(e), this.name = "AuthError";
47
+ }
48
+ };
49
+ function b(e) {
50
+ return e.some((e) => e.extensions?.code === "UNAUTHENTICATED" || e.message?.toLowerCase().includes("unauthorized") || e.message?.toLowerCase().includes("not authenticated"));
51
+ }
52
+ function x() {
53
+ let t = e.getState().accessToken;
54
+ if (t && !g(t)) return t;
55
+ let n = o();
56
+ return n && !g(n) ? n : t;
57
+ }
58
+ function S(e) {
59
+ return Array.from(new Set(e.map((e) => e.organizationId).filter(Boolean))).map((t, n) => ({
60
+ id: t,
61
+ name: e.find((e) => e.organizationId === t)?.name || `Organization ${n + 1}`,
62
+ slug: t,
63
+ tenantId: e.find((e) => e.organizationId === t)?.tenantId || ""
64
+ }));
65
+ }
66
+ function C(o) {
67
+ let { organizationId: m, workspaceId: _, projectId: C, setContext: w } = c(), T = e((e) => e.organizations), E = e((e) => e.currentOrganizationId), D = e((e) => e.isLoadingOrganizations), O = e((e) => e.workspaces), k = e((e) => e.currentWorkspaceId), A = e((e) => e.workspaceToken), j = e((e) => e.isLoadingWorkspaces), M = e((e) => e.projects), N = e((e) => e.currentProjectId), P = e((e) => e.isLoadingProjects), [F, I] = a(null), L = i(null), R = i(/* @__PURE__ */ new Map()), z = i(_), B = i(m);
68
+ r(() => {
69
+ z.current = _, B.current = m;
70
+ });
71
+ let V = t(), H = o?.globalBaseUrl ?? V.globalBaseUrl, U = o?.workspaceBaseUrl ?? V.workspaceBaseUrl;
72
+ r(() => {
73
+ let t = e.getState();
74
+ m && m !== t.currentOrganizationId && (t.setCurrentOrganizationId(m), t.workspaces.length > 0 && !t.workspaces.some((e) => e.organizationId === m) && t.setWorkspaces([])), _ && _ !== t.currentWorkspaceId && (t.setCurrentWorkspaceId(_), t.projects.length > 0 && !t.projects.some((e) => e.workspaceId === _) && (t.setProjects([]), t.setCurrentProjectId(null))), C && C !== t.currentProjectId && t.setCurrentProjectId(C), t.workspaceToken && !v(t.workspaceToken, {
75
+ workspaceId: _,
76
+ organizationId: m
77
+ }) && t.setWorkspaceToken(null);
78
+ }, [
79
+ m,
80
+ _,
81
+ C
82
+ ]);
83
+ let W = n(async () => {
84
+ if (L.current) return L.current;
85
+ let t = e.getState(), n = x();
86
+ return !n || g(n) ? [] : (t.setLoadingOrganizations(!0), I(null), L.current = (async () => {
87
+ try {
88
+ let r = B.current ?? t.currentOrganizationId, i = await s({
89
+ gateway: "global",
90
+ query: r ? d : l,
91
+ variables: r ? { filter: { organizationId: r } } : void 0,
92
+ authToken: n,
93
+ baseUrl: H
94
+ });
95
+ if (r && i.errors?.length && i.errors.some((e) => e?.extensions?.code === "FORBIDDEN" || /not a member of this organization/i.test(e?.message ?? "") || /Cannot return null for non-nullable field Query\.myOrganizations/i.test(e?.message ?? "")) && (i = await s({
96
+ gateway: "global",
97
+ query: "\n query ContextSwitcherRecover {\n myOrganizations {\n total\n items { id name slug tenantId description logo website status type createdAt updatedAt }\n }\n workspaces {\n total\n items { id name slug tenantId organizationId type status region createdAt updatedAt }\n }\n }\n ",
98
+ authToken: n,
99
+ baseUrl: H
100
+ })), i.errors?.length) {
101
+ let e = i.errors[0]?.message ?? "GraphQL error";
102
+ throw b(i.errors) ? new y(e) : (t.workspaces.length === 0 && console.error("Failed to fetch organizations:", i.errors), Error(e));
103
+ }
104
+ let a = i.data?.myOrganizations?.items ?? [];
105
+ if (r && a.length === 0 && t.workspaces.length === 0) {
106
+ let e = await s({
107
+ gateway: "global",
108
+ query: l,
109
+ authToken: n,
110
+ baseUrl: H
111
+ });
112
+ e.errors?.length ? console.warn("[ContextSwitcher] Stale-context recovery failed:", e.errors) : (a = e.data?.myOrganizations?.items ?? [], i = {
113
+ ...e,
114
+ data: { myOrganizations: e.data?.myOrganizations ?? {
115
+ items: [],
116
+ total: 0
117
+ } }
118
+ });
119
+ }
120
+ let o = a.length === 0 && t.workspaces.length > 0 ? S(t.workspaces) : [], c = o.length > 0 ? o : a;
121
+ t.setOrganizations(c);
122
+ let f = r, p = f && a.some((e) => e.id === f);
123
+ if (f && !p && a.length > 0 && (f = a[0].id, w({
124
+ organizationId: f,
125
+ workspaceId: null,
126
+ projectId: null
127
+ }), t.setWorkspaces([]), t.setProjects([]), t.setCurrentWorkspaceId(null), t.setCurrentProjectId(null), t.setWorkspaceToken(null)), f && f !== t.currentOrganizationId && t.setCurrentOrganizationId(f), c.length > 0 && !f && (t.setCurrentOrganizationId(c[0].id), f = c[0].id), f && e.getState().workspaces.length === 0) {
128
+ t.setLoadingWorkspaces(!0);
129
+ try {
130
+ let e = (r === f ? i.data?.workspaces?.items : void 0) || await s({
131
+ gateway: "global",
132
+ query: u,
133
+ variables: { filter: { organizationId: f } },
134
+ authToken: n,
135
+ baseUrl: H
136
+ }).then((e) => e.errors?.length ? null : e.data?.workspaces?.items ?? []);
137
+ if (e) {
138
+ t.setWorkspaces(e);
139
+ let n = z.current ? e.find((e) => e.id === z.current) : null;
140
+ n ? t.setCurrentWorkspaceId(n.id) : z.current && e.length > 0 ? (t.setCurrentWorkspaceId(e[0].id), t.setWorkspaceToken(null), w({
141
+ workspaceId: e[0].id,
142
+ projectId: null
143
+ })) : e.length > 0 && !t.currentWorkspaceId && t.setCurrentWorkspaceId(e[0].id);
144
+ }
145
+ } catch {} finally {
146
+ t.setLoadingWorkspaces(!1);
147
+ }
148
+ }
149
+ return c;
150
+ } catch (e) {
151
+ if (e instanceof y) return [];
152
+ let n = e instanceof Error ? e.message : "Failed to fetch organizations";
153
+ if (t.workspaces.length === 0 && console.error("Failed to fetch organizations:", e), I(n), t.workspaces.length > 0) {
154
+ let e = S(t.workspaces);
155
+ if (e.length > 0) return t.setOrganizations(e), t.currentOrganizationId || t.setCurrentOrganizationId(e[0].id), e;
156
+ }
157
+ return [];
158
+ } finally {
159
+ t.setLoadingOrganizations(!1), L.current = null;
160
+ }
161
+ })(), L.current);
162
+ }, [H, w]), G = n(async (t) => {
163
+ let n = R.current.get(t);
164
+ if (n) return n;
165
+ let r = e.getState(), i = x();
166
+ if (!i || g(i)) return [];
167
+ r.setLoadingWorkspaces(!0), I(null);
168
+ let a = (async () => {
169
+ try {
170
+ let e = await s({
171
+ gateway: "global",
172
+ query: u,
173
+ variables: { filter: { organizationId: t } },
174
+ authToken: i,
175
+ baseUrl: H
176
+ });
177
+ if (e.errors?.length) {
178
+ let t = e.errors[0]?.message ?? "GraphQL error";
179
+ throw b(e.errors) ? new y(t) : (console.error("Failed to fetch workspaces:", e.errors), Error(t));
180
+ }
181
+ let n = e.data?.workspaces?.items ?? [];
182
+ return r.setWorkspaces(n), n;
183
+ } catch (e) {
184
+ if (e instanceof y) return [];
185
+ let t = e instanceof Error ? e.message : "Failed to fetch workspaces";
186
+ return console.error("Failed to fetch workspaces:", e), I(t), [];
187
+ } finally {
188
+ r.setLoadingWorkspaces(!1), R.current.delete(t);
189
+ }
190
+ })();
191
+ return R.current.set(t, a), a;
192
+ }, [H]), K = n(async (t, n) => {
193
+ let r = e.getState(), i = x();
194
+ if (!i || g(i)) return {
195
+ success: !1,
196
+ error: "No valid access token available"
197
+ };
198
+ I(null);
199
+ try {
200
+ let e = await s({
201
+ gateway: "workspace",
202
+ query: f,
203
+ variables: { input: {
204
+ organizationId: t,
205
+ ...n && { workspaceId: n }
206
+ } },
207
+ authToken: i,
208
+ baseUrl: U
209
+ });
210
+ if (e.errors?.length) {
211
+ let t = e.errors[0]?.message ?? "GraphQL error";
212
+ return b(e.errors) || console.error("Failed to issue workspace token:", e.errors), {
213
+ success: !1,
214
+ error: t
215
+ };
216
+ }
217
+ let a = e.data?.issueWorkspaceToken;
218
+ if (a?.success && a.token) {
219
+ let e = a.workspaceId || n;
220
+ return e && r.setCurrentWorkspaceId(e), r.setWorkspaceToken(a.token), {
221
+ success: !0,
222
+ token: a.token,
223
+ resolvedWorkspaceId: e || void 0
224
+ };
225
+ }
226
+ return {
227
+ success: !1,
228
+ error: a?.error?.message ?? "Failed to issue workspace token"
229
+ };
230
+ } catch (e) {
231
+ let t = e instanceof Error ? e.message : "Failed to issue workspace token";
232
+ return console.error("Failed to issue workspace token:", e), I(t), {
233
+ success: !1,
234
+ error: t
235
+ };
236
+ }
237
+ }, [U]), q = n(async () => {
238
+ let t = e.getState(), n = x(), r = t.workspaceToken, i = t.currentWorkspaceId;
239
+ if (!n || g(n) || !r || !i) return [];
240
+ t.setLoadingProjects(!0), I(null);
241
+ try {
242
+ let e = await s({
243
+ gateway: "workspace",
244
+ query: p,
245
+ variables: { filter: { workspaceId: i } },
246
+ authToken: n,
247
+ workspaceToken: r,
248
+ baseUrl: U
249
+ });
250
+ if (e.errors?.length) {
251
+ let t = e.errors[0]?.message ?? "GraphQL error";
252
+ throw b(e.errors) ? new y(t) : (console.error("Failed to fetch projects:", e.errors), Error(t));
253
+ }
254
+ let a = e.data?.projects?.items ?? [];
255
+ return t.setProjects(a), a;
256
+ } catch (e) {
257
+ if (e instanceof y) return [];
258
+ let t = e instanceof Error ? e.message : "Failed to fetch projects";
259
+ return console.error("Failed to fetch projects:", e), I(t), [];
260
+ } finally {
261
+ t.setLoadingProjects(!1);
262
+ }
263
+ }, [U]), J = n(async (t) => {
264
+ let n = e.getState();
265
+ return n.setCurrentWorkspaceId(null), n.setWorkspaceToken(null), n.setProjects([]), n.setCurrentProjectId(null), n.setCurrentOrganizationId(t.id), await G(t.id);
266
+ }, [G]), Y = n(async (t) => {
267
+ let n = e.getState();
268
+ if (n.setCurrentProjectId(null), n.setProjects([]), !t.organizationId) return console.error("Workspace missing organizationId:", t), {
269
+ success: !1,
270
+ error: "Workspace is missing organizationId"
271
+ };
272
+ let r = await K(t.organizationId, t.id);
273
+ if (!r.success) return {
274
+ success: !1,
275
+ error: r.error
276
+ };
277
+ let i = await q();
278
+ if (i.length === 0) {
279
+ let t = x(), r = e.getState().workspaceToken;
280
+ if (t && r) {
281
+ let e = await h({
282
+ authToken: t,
283
+ workspaceBaseUrl: U,
284
+ workspaceToken: r
285
+ });
286
+ e && (i = [e], n.setProjects(i));
287
+ }
288
+ }
289
+ return i.length > 0 && n.setCurrentProjectId(i[0].id), {
290
+ success: !0,
291
+ projects: i
292
+ };
293
+ }, [
294
+ K,
295
+ q,
296
+ U
297
+ ]), X = n((t) => {
298
+ e.getState().setCurrentProjectId(t.id);
299
+ }, []);
300
+ return {
301
+ organizations: T,
302
+ workspaces: O,
303
+ projects: M,
304
+ currentOrganizationId: E,
305
+ currentWorkspaceId: k,
306
+ currentProjectId: N,
307
+ currentOrganization: T.find((e) => e.id === E),
308
+ currentWorkspace: O.find((e) => e.id === k),
309
+ currentProject: M.find((e) => e.id === N),
310
+ workspaceToken: A,
311
+ isLoadingOrganizations: D,
312
+ isLoadingWorkspaces: j,
313
+ isLoadingProjects: P,
314
+ isLoading: D || j || P,
315
+ error: F,
316
+ fetchOrganizations: W,
317
+ fetchWorkspacesForOrg: G,
318
+ issueWorkspaceToken: K,
319
+ fetchProjects: q,
320
+ selectOrganization: J,
321
+ selectWorkspace: Y,
322
+ selectProject: X
323
+ };
324
+ }
325
+ function w(n) {
326
+ let i = e((e) => e.currentOrganizationId), a = e((e) => e.workspaces), o = e((e) => e.accessToken), c = e((e) => e.isLoadingWorkspaces), l = t(), d = n?.globalBaseUrl ?? l.globalBaseUrl, f = n?.disableWorkspaceSync ?? !1;
327
+ r(() => {
328
+ if (f || !i || !o || c) return;
329
+ let t = a.some((e) => e.organizationId === i);
330
+ if (a.length > 0 && !t) {
331
+ let t = e.getState();
332
+ t.setLoadingWorkspaces(!0), s({
333
+ gateway: "global",
334
+ query: u,
335
+ variables: { filter: { organizationId: i } },
336
+ authToken: o,
337
+ baseUrl: d
338
+ }).then((e) => {
339
+ if (!e.errors?.length) {
340
+ let n = e.data?.workspaces?.items ?? [];
341
+ t.setWorkspaces(n);
342
+ }
343
+ }).catch(() => {}).finally(() => {
344
+ t.setLoadingWorkspaces(!1);
345
+ });
346
+ }
347
+ }, [
348
+ i,
349
+ a,
350
+ o,
351
+ c,
352
+ d,
353
+ f
354
+ ]);
355
+ }
356
+ function T(n) {
357
+ let a = e((e) => e.currentWorkspaceId), o = e((e) => e.currentOrganizationId), c = e((e) => e.workspaces), l = e((e) => e.projects), u = e((e) => e.workspaceToken), d = e((e) => e.accessToken), m = t(), _ = n?.workspaceBaseUrl ?? m.workspaceBaseUrl, y = n?.disableProjectSync ?? !1, b = n?.skipProjectFetch ?? !1, x = i(!1), S = i(/* @__PURE__ */ new Map()), C = i(/* @__PURE__ */ new Map()), w = 3e4;
358
+ r(() => {
359
+ if (y || !a || !d || x.current) return;
360
+ let t = C.current.get(a);
361
+ if (t && t.count >= 8 && Date.now() - t.lastFailureAt < w) return;
362
+ t && Date.now() - t.lastFailureAt >= w && C.current.delete(a);
363
+ let n = c.find((e) => e.id === a);
364
+ if (n && o && n.organizationId !== o) return;
365
+ let r = n?.organizationId ?? o;
366
+ if (!r) return;
367
+ let i = e.getState(), m = !u || g(u) || !v(u, {
368
+ workspaceId: a,
369
+ organizationId: o
370
+ }), T = l.some((e) => e.workspaceId === a);
371
+ if (T && !m) {
372
+ if (!i.currentProjectId) {
373
+ let e = l.find((e) => e.workspaceId === a);
374
+ e && i.setCurrentProjectId(e.id);
375
+ }
376
+ return;
377
+ }
378
+ let E = async () => {
379
+ x.current = !0, i.setLoadingProjects(!0);
380
+ let t = !1;
381
+ try {
382
+ let e = u;
383
+ if (m) {
384
+ let t = await s({
385
+ gateway: "workspace",
386
+ query: f,
387
+ variables: { input: {
388
+ organizationId: r,
389
+ workspaceId: a
390
+ } },
391
+ authToken: d,
392
+ baseUrl: _
393
+ });
394
+ if (t.data?.issueWorkspaceToken?.success && t.data.issueWorkspaceToken.token) e = t.data.issueWorkspaceToken.token, i.setWorkspaceToken(e);
395
+ else return;
396
+ }
397
+ if (e && !T && !b) {
398
+ let t = await s({
399
+ gateway: "workspace",
400
+ query: p,
401
+ variables: { filter: { workspaceId: a } },
402
+ authToken: d,
403
+ workspaceToken: e,
404
+ baseUrl: _
405
+ });
406
+ if (t.errors?.length) return;
407
+ let n = t.data?.projects?.items ?? [];
408
+ if (n.length === 0) {
409
+ let t = await h({
410
+ authToken: d,
411
+ workspaceBaseUrl: _,
412
+ workspaceToken: e
413
+ });
414
+ if (t) n = [t];
415
+ else return;
416
+ }
417
+ i.setProjects(n), n.length > 0 && !i.currentProjectId && i.setCurrentProjectId(n[0].id);
418
+ }
419
+ t = !0;
420
+ } catch {} finally {
421
+ i.setLoadingProjects(!1), x.current = !1;
422
+ let n = C.current;
423
+ if (t) {
424
+ n.delete(a);
425
+ let e = S.current.get(a);
426
+ e && (clearTimeout(e), S.current.delete(a));
427
+ } else {
428
+ let t = (n.get(a)?.count ?? 0) + 1;
429
+ if (n.set(a, {
430
+ count: t,
431
+ lastFailureAt: Date.now()
432
+ }), t < 8) {
433
+ let n = S.current.get(a);
434
+ n && clearTimeout(n);
435
+ let r = Math.min(1e3 * 2 ** (t - 1), 8e3), i = setTimeout(() => {
436
+ S.current.delete(a);
437
+ let t = e.getState();
438
+ t.currentWorkspaceId === a && !t.projects.some((e) => e.workspaceId === a) && !x.current && E();
439
+ }, r);
440
+ S.current.set(a, i);
441
+ }
442
+ }
443
+ }
444
+ };
445
+ E();
446
+ }, [
447
+ a,
448
+ o,
449
+ c,
450
+ l,
451
+ u,
452
+ d,
453
+ _,
454
+ y,
455
+ b
456
+ ]), r(() => {
457
+ let e = S.current;
458
+ return () => {
459
+ e.forEach((e) => clearTimeout(e)), e.clear();
460
+ };
461
+ }, []);
462
+ }
463
+ //#endregion
464
+ export { C as useContextSwitcherData, T as useProjectSyncEffect, w as useWorkspaceSyncEffect };
465
+
466
+ //# sourceMappingURL=useContextSwitcherData.js.map