@burdenoff/microfe-auth 2026.925.1 → 2026.1009.1
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.
- package/README.md +14 -0
- package/dist/auth/AuthRoot.d.ts +0 -1
- package/dist/auth/AuthRoot.js.map +1 -1
- package/dist/auth/AuthRoutes.d.ts +1 -1
- package/dist/auth/AuthRoutes.js.map +1 -1
- package/dist/auth/components/AuthIcons.d.ts +12 -13
- package/dist/auth/components/AuthIcons.js.map +1 -1
- package/dist/auth/components/AuthLayout.d.ts +1 -2
- package/dist/auth/components/AuthLayout.js.map +1 -1
- package/dist/auth/components/CaptchaV2.d.ts +1 -1
- package/dist/auth/components/CaptchaV2.js +2 -2
- package/dist/auth/components/CaptchaV2.js.map +1 -1
- package/dist/auth/components/ConfirmActionDialog.d.ts +1 -1
- package/dist/auth/components/ConfirmActionDialog.js.map +1 -1
- package/dist/auth/components/profile/UserProfileMenu.d.ts +1 -1
- package/dist/auth/components/profile/UserProfileMenu.js.map +1 -1
- package/dist/auth/components/workspace/WorkspaceSelector.d.ts +1 -2
- package/dist/auth/components/workspace/WorkspaceSelector.js.map +1 -1
- package/dist/auth/constants/permissions.js.map +1 -1
- package/dist/auth/hooks/useAccountOperations.d.ts +0 -1
- package/dist/auth/hooks/useAccountOperations.js.map +1 -1
- package/dist/auth/hooks/useActiveContextBootstrapMirror.js.map +1 -1
- package/dist/auth/hooks/useApiKeyOperations.d.ts +1 -2
- package/dist/auth/hooks/useAppOperations.d.ts +1 -2
- package/dist/auth/hooks/useAuthOperations.d.ts +0 -1
- package/dist/auth/hooks/useAuthOperations.js.map +1 -1
- package/dist/auth/hooks/useAuthPermissions.js.map +1 -1
- package/dist/auth/hooks/useCaptchaV3.js +1 -1
- package/dist/auth/hooks/useCaptchaV3.js.map +1 -1
- package/dist/auth/hooks/useContextSwitcherData.d.ts +1 -1
- package/dist/auth/hooks/useContextSwitcherData.js +346 -259
- package/dist/auth/hooks/useContextSwitcherData.js.map +1 -1
- package/dist/auth/hooks/useDelegationOperations.d.ts +0 -1
- package/dist/auth/hooks/useMfaOperations.d.ts +0 -1
- package/dist/auth/hooks/useMfaOperations.js.map +1 -1
- package/dist/auth/hooks/useMyWorkspaces.d.ts +0 -1
- package/dist/auth/hooks/useMyWorkspaces.js.map +1 -1
- package/dist/auth/hooks/useOAuthOperations.d.ts +0 -1
- package/dist/auth/hooks/useOAuthOperations.js +2 -2
- package/dist/auth/hooks/useOAuthOperations.js.map +1 -1
- package/dist/auth/hooks/usePasswordOperations.d.ts +0 -1
- package/dist/auth/hooks/usePasswordOperations.js.map +1 -1
- package/dist/auth/hooks/useSessionOperations.d.ts +0 -1
- package/dist/auth/hooks/useSessionOperations.js.map +1 -1
- package/dist/auth/hooks/useSignupCaptcha.js +1 -1
- package/dist/auth/hooks/useSignupCaptcha.js.map +1 -1
- package/dist/auth/hooks/useSsoOperations.d.ts +0 -1
- package/dist/auth/hooks/useSsoOperations.js.map +1 -1
- package/dist/auth/hooks/useTokenRefresh.js.map +1 -1
- package/dist/auth/hooks/useUserOperations.d.ts +0 -1
- package/dist/auth/hooks/useUserOperations.js.map +1 -1
- package/dist/auth/hooks/useWorkspaceOperations.d.ts +0 -1
- package/dist/auth/hooks/useWorkspaceOperations.js.map +1 -1
- package/dist/auth/hooks/useWorkspaceToken.js.map +1 -1
- package/dist/auth/pages/AuditLogPage.d.ts +1 -1
- package/dist/auth/pages/AuditLogPage.js.map +1 -1
- package/dist/auth/pages/EmailVerifyPage.d.ts +1 -1
- package/dist/auth/pages/EmailVerifyPage.js.map +1 -1
- package/dist/auth/pages/LoginPage.d.ts +1 -1
- package/dist/auth/pages/LoginPage.js.map +1 -1
- package/dist/auth/pages/MagicLinkPage.d.ts +1 -1
- package/dist/auth/pages/MagicLinkPage.js.map +1 -1
- package/dist/auth/pages/MfaSetupPage.d.ts +1 -1
- package/dist/auth/pages/MfaSetupPage.js +88 -88
- package/dist/auth/pages/MfaSetupPage.js.map +1 -1
- package/dist/auth/pages/MfaVerifyPage.d.ts +1 -1
- package/dist/auth/pages/MfaVerifyPage.js.map +1 -1
- package/dist/auth/pages/OAuthCallbackPage.d.ts +1 -1
- package/dist/auth/pages/OAuthCallbackPage.js.map +1 -1
- package/dist/auth/pages/PasswordResetPage.d.ts +1 -1
- package/dist/auth/pages/PasswordResetPage.js.map +1 -1
- package/dist/auth/pages/ReactivatePage.d.ts +1 -1
- package/dist/auth/pages/ReactivatePage.js.map +1 -1
- package/dist/auth/pages/RegisterPage.d.ts +1 -1
- package/dist/auth/pages/RegisterPage.js.map +1 -1
- package/dist/auth/pages/SSOClearPage.d.ts +1 -1
- package/dist/auth/pages/SSOClearPage.js.map +1 -1
- package/dist/auth/pages/SSODepositPage.d.ts +1 -1
- package/dist/auth/pages/SSODepositPage.js.map +1 -1
- package/dist/auth/pages/SSORelayCallbackPage.d.ts +1 -1
- package/dist/auth/pages/SSORelayCallbackPage.js.map +1 -1
- package/dist/auth/pages/SSORelayPage.d.ts +1 -1
- package/dist/auth/pages/SSORelayPage.js.map +1 -1
- package/dist/auth/pages/SecurityPage.d.ts +1 -1
- package/dist/auth/pages/SecurityPage.js.map +1 -1
- package/dist/auth/pages/SessionBridgePage.d.ts +1 -1
- package/dist/auth/pages/SessionBridgePage.js.map +1 -1
- package/dist/auth/pages/SessionsPage.d.ts +1 -1
- package/dist/auth/pages/SessionsPage.js.map +1 -1
- package/dist/auth/pages/SsoCallbackPage.d.ts +1 -1
- package/dist/auth/pages/SsoCallbackPage.js.map +1 -1
- package/dist/auth/pages/SsoConfigPage.d.ts +1 -1
- package/dist/auth/pages/SsoConfigPage.js.map +1 -1
- package/dist/auth/pages/SsoLoginPage.d.ts +1 -1
- package/dist/auth/pages/SsoLoginPage.js.map +1 -1
- package/dist/auth/pages/UserDetailsPage.d.ts +1 -1
- package/dist/auth/pages/UserDetailsPage.js.map +1 -1
- package/dist/auth/pages/UserProfilePage.d.ts +1 -1
- package/dist/auth/pages/UserProfilePage.js.map +1 -1
- package/dist/auth/pages/UsersPage.d.ts +1 -1
- package/dist/auth/pages/UsersPage.js.map +1 -1
- package/dist/auth/providers/AuthProvider.d.ts +0 -1
- package/dist/auth/providers/AuthProvider.js.map +1 -1
- package/dist/auth/providers/CaptchaProvider.d.ts +1 -2
- package/dist/auth/providers/CaptchaProvider.js +2 -2
- package/dist/auth/providers/CaptchaProvider.js.map +1 -1
- package/dist/auth/store/authStore.d.ts +0 -1
- package/dist/auth/store/authStore.js.map +1 -1
- package/dist/auth/types/index.d.ts +0 -1
- package/dist/auth/utils/captchaConfig.js.map +1 -1
- package/dist/auth/utils/formatters.js.map +1 -1
- package/dist/auth/utils/gatewayBaseUrls.js.map +1 -1
- package/dist/auth/utils/legalUrls.js.map +1 -1
- package/dist/auth/utils/redirect.js.map +1 -1
- package/dist/auth/utils/ssoOrigins.js.map +1 -1
- package/dist/auth/utils/validation.d.ts +0 -1
- package/dist/auth/utils/validation.js.map +1 -1
- package/dist/dev/main.d.ts +0 -1
- package/dist/generated/global-operations.js.map +1 -1
- package/dist/generated/wspace-operations.js.map +1 -1
- package/dist/index.d.ts +0 -1
- package/dist/shared/hooks/useTr.js.map +1 -1
- package/dist/shared/types/index.d.ts +0 -1
- package/dist/translations/en.js.map +1 -1
- package/package.json +27 -20
- package/dist/_virtual/_rolldown/runtime.js +0 -13
- package/dist/node_modules/hoist-non-react-statics/dist/hoist-non-react-statics.cjs.js +0 -70
- package/dist/node_modules/hoist-non-react-statics/dist/hoist-non-react-statics.cjs.js.map +0 -1
- package/dist/node_modules/object-assign/index.js +0 -41
- package/dist/node_modules/object-assign/index.js.map +0 -1
- package/dist/node_modules/prop-types/checkPropTypes.js +0 -46
- package/dist/node_modules/prop-types/checkPropTypes.js.map +0 -1
- package/dist/node_modules/prop-types/factoryWithThrowingShims.js +0 -49
- package/dist/node_modules/prop-types/factoryWithThrowingShims.js.map +0 -1
- package/dist/node_modules/prop-types/factoryWithTypeCheckers.js +0 -272
- package/dist/node_modules/prop-types/factoryWithTypeCheckers.js.map +0 -1
- package/dist/node_modules/prop-types/index.js +0 -16
- package/dist/node_modules/prop-types/index.js.map +0 -1
- package/dist/node_modules/prop-types/lib/ReactPropTypesSecret.js +0 -10
- package/dist/node_modules/prop-types/lib/ReactPropTypesSecret.js.map +0 -1
- package/dist/node_modules/prop-types/lib/has.js +0 -10
- package/dist/node_modules/prop-types/lib/has.js.map +0 -1
- package/dist/node_modules/qrcode.react/lib/esm/index.js +0 -959
- package/dist/node_modules/qrcode.react/lib/esm/index.js.map +0 -1
- package/dist/node_modules/react-async-script/lib/esm/async-script-loader.js +0 -114
- package/dist/node_modules/react-async-script/lib/esm/async-script-loader.js.map +0 -1
- package/dist/node_modules/react-google-recaptcha/lib/esm/index.js +0 -8
- package/dist/node_modules/react-google-recaptcha/lib/esm/index.js.map +0 -1
- package/dist/node_modules/react-google-recaptcha/lib/esm/recaptcha-wrapper.js +0 -20
- package/dist/node_modules/react-google-recaptcha/lib/esm/recaptcha-wrapper.js.map +0 -1
- package/dist/node_modules/react-google-recaptcha/lib/esm/recaptcha.js +0 -148
- package/dist/node_modules/react-google-recaptcha/lib/esm/recaptcha.js.map +0 -1
- package/dist/node_modules/react-google-recaptcha-v3/dist/react-google-recaptcha-v3.esm.js +0 -445
- package/dist/node_modules/react-google-recaptcha-v3/dist/react-google-recaptcha-v3.esm.js.map +0 -1
- package/dist/node_modules/react-is/cjs/react-is.development.js +0 -84
- package/dist/node_modules/react-is/cjs/react-is.development.js.map +0 -1
- package/dist/node_modules/react-is/cjs/react-is.production.min.js +0 -64
- package/dist/node_modules/react-is/cjs/react-is.production.min.js.map +0 -1
- package/dist/node_modules/react-is/index.js +0 -12
- package/dist/node_modules/react-is/index.js.map +0 -1
|
@@ -1,23 +1,15 @@
|
|
|
1
1
|
import { useAuthStore as e } from "../store/authStore.js";
|
|
2
2
|
import { resolveGatewayBaseUrls as t } from "../utils/gatewayBaseUrls.js";
|
|
3
3
|
import { useCallback as n, useEffect as r, useRef as i, useState as a } from "react";
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
4
|
+
import { resolveActiveProfileId as o } from "@burdenoff/fe-libs/shared/providers/shell/ProfileStorageManager";
|
|
5
|
+
import { useEventBus as s } from "@burdenoff/fe-libs/shared/events";
|
|
6
|
+
import { getStoredAuthToken as c, graphqlFetch as l } from "@burdenoff/fe-libs/shared/graphql";
|
|
7
|
+
import { clearWorkspaceWideSelection as u, isWorkspaceWideSelection as d, selectWorkspaceWide as f } from "@burdenoff/fe-libs/shared/providers/shell/WorkspaceWideSelection";
|
|
8
|
+
import { getUrlParam as p } from "@burdenoff/fe-libs/shared/providers/shell/ActiveContextStorage";
|
|
9
|
+
import { useActiveContext as m } from "@burdenoff/fe-libs/shared/providers/shell/ActiveContextProvider";
|
|
7
10
|
//#region src/auth/hooks/useContextSwitcherData.ts
|
|
8
|
-
var
|
|
9
|
-
|
|
10
|
-
let r = await c({
|
|
11
|
-
gateway: "workspace",
|
|
12
|
-
query: p,
|
|
13
|
-
variables: { input: { name: "Default Project" } },
|
|
14
|
-
authToken: e,
|
|
15
|
-
workspaceToken: n,
|
|
16
|
-
baseUrl: t
|
|
17
|
-
});
|
|
18
|
-
return r.errors?.length ? (console.warn("Failed to create default project:", r.errors), null) : r.data?.createProject ?? null;
|
|
19
|
-
}
|
|
20
|
-
function h(e, t = 3e4) {
|
|
11
|
+
var h = "\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", g = "\n query WorkspacesByOrg {\n workspaces: myWorkspaces(limit: 100) {\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", _ = "\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", v = "\n query MyProjectsForContext {\n projects: myProjects {\n total\n items {\n id\n name\n key\n workspaceId\n status\n archived\n createdAt\n updatedAt\n }\n }\n }\n";
|
|
12
|
+
function y(e, t = 3e4) {
|
|
21
13
|
try {
|
|
22
14
|
let n = JSON.parse(atob(e.split(".")[1]));
|
|
23
15
|
return n.exp ? n.exp * 1e3 < Date.now() + t : !1;
|
|
@@ -25,7 +17,7 @@ function h(e, t = 3e4) {
|
|
|
25
17
|
return !0;
|
|
26
18
|
}
|
|
27
19
|
}
|
|
28
|
-
function
|
|
20
|
+
function b(e) {
|
|
29
21
|
try {
|
|
30
22
|
let t = JSON.parse(atob(e.split(".")[1]));
|
|
31
23
|
return {
|
|
@@ -38,26 +30,26 @@ function g(e) {
|
|
|
38
30
|
return null;
|
|
39
31
|
}
|
|
40
32
|
}
|
|
41
|
-
function
|
|
42
|
-
if (!e ||
|
|
43
|
-
let n =
|
|
44
|
-
return !(!n || t.workspaceId && n.workspaceId !== t.workspaceId || t.organizationId && n.organizationId !== t.organizationId || t.projectId && n.projectId !== t.projectId);
|
|
33
|
+
function x(e, t) {
|
|
34
|
+
if (!e || y(e)) return !1;
|
|
35
|
+
let n = b(e);
|
|
36
|
+
return !(!n || t.workspaceId && n.workspaceId !== t.workspaceId || t.organizationId && n.organizationId !== t.organizationId || t.workspaceWide && n.projectId || t.projectId && n.projectId !== t.projectId);
|
|
45
37
|
}
|
|
46
|
-
var
|
|
38
|
+
var S = class extends Error {
|
|
47
39
|
constructor(e) {
|
|
48
40
|
super(e), this.name = "AuthError";
|
|
49
41
|
}
|
|
50
42
|
};
|
|
51
|
-
function
|
|
43
|
+
function C(e) {
|
|
52
44
|
return e.some((e) => e.extensions?.code === "UNAUTHENTICATED" || e.message?.toLowerCase().includes("unauthorized") || e.message?.toLowerCase().includes("not authenticated"));
|
|
53
45
|
}
|
|
54
|
-
function
|
|
46
|
+
function w() {
|
|
55
47
|
let t = e.getState().accessToken;
|
|
56
|
-
if (t && !
|
|
57
|
-
let n =
|
|
58
|
-
return n && !
|
|
48
|
+
if (t && !y(t)) return t;
|
|
49
|
+
let n = c();
|
|
50
|
+
return n && !y(n) ? n : t;
|
|
59
51
|
}
|
|
60
|
-
function
|
|
52
|
+
function T(e) {
|
|
61
53
|
return Array.from(new Set(e.flatMap((e) => e.organizationId ? [e.organizationId] : []))).map((t, n) => ({
|
|
62
54
|
id: t,
|
|
63
55
|
name: e.find((e) => e.organizationId === t)?.name || `Organization ${n + 1}`,
|
|
@@ -65,62 +57,69 @@ function x(e) {
|
|
|
65
57
|
tenantId: e.find((e) => e.organizationId === t)?.tenantId || ""
|
|
66
58
|
}));
|
|
67
59
|
}
|
|
68
|
-
var
|
|
60
|
+
var E = new Set([
|
|
69
61
|
"project.created",
|
|
70
62
|
"project.updated",
|
|
71
63
|
"project.deleted",
|
|
72
64
|
"project.archived",
|
|
73
65
|
"project.unarchived"
|
|
74
|
-
]),
|
|
66
|
+
]), D = new Set([
|
|
75
67
|
"workspace.created",
|
|
76
68
|
"workspace.updated",
|
|
77
69
|
"workspace.deleted",
|
|
78
70
|
"workspace.archived",
|
|
79
71
|
"workspace.reactivated"
|
|
80
72
|
]);
|
|
81
|
-
function
|
|
73
|
+
function ee(e) {
|
|
82
74
|
if (e && typeof e == "object" && "workspaceId" in e) {
|
|
83
75
|
let t = e.workspaceId;
|
|
84
76
|
return typeof t == "string" ? t : void 0;
|
|
85
77
|
}
|
|
86
78
|
}
|
|
87
|
-
function
|
|
88
|
-
let { organizationId: p, workspaceId:
|
|
79
|
+
function O(c) {
|
|
80
|
+
let { organizationId: p, workspaceId: y, projectId: b, setContext: O } = m(), k = s(), A = e((e) => e.organizations), j = e((e) => e.currentOrganizationId), M = e((e) => e.isLoadingOrganizations), N = e((e) => e.workspaces), P = e((e) => e.currentWorkspaceId), F = e((e) => e.workspaceToken), I = e((e) => e.isLoadingWorkspaces), L = e((e) => e.projects), R = e((e) => e.currentProjectId), z = e((e) => e.isLoadingProjects), [te, B] = a(null), [V, H] = a(0), U = i(0), W = i(null), G = i(/* @__PURE__ */ new Map()), K = i(y), q = i(p);
|
|
89
81
|
r(() => {
|
|
90
|
-
|
|
82
|
+
K.current = y, q.current = p;
|
|
91
83
|
});
|
|
92
|
-
let
|
|
84
|
+
let ne = t(), J = c?.globalBaseUrl ?? ne.globalBaseUrl, Y = c?.workspaceBaseUrl ?? ne.workspaceBaseUrl, re = i(null), ie = i(null), ae = i(null), oe = i(null);
|
|
93
85
|
r(() => {
|
|
94
86
|
let t = e.getState();
|
|
95
|
-
if (p && p !== t.currentOrganizationId && p !==
|
|
96
|
-
|
|
87
|
+
if (p && p !== t.currentOrganizationId && p !== re.current && (re.current = p, t.setCurrentOrganizationId(p), t.workspaces.length > 0 && !t.workspaces.some((e) => e.organizationId === p) && t.setWorkspaces([])), y && y !== t.currentWorkspaceId && y !== ie.current && (ie.current = y, t.setCurrentWorkspaceId(y), t.projects.length > 0 && !t.projects.some((e) => e.workspaceId === y) && (t.setProjects([]), t.setCurrentProjectId(null))), d({
|
|
88
|
+
organizationId: p,
|
|
89
|
+
workspaceId: y
|
|
90
|
+
}) && !b && t.currentProjectId && (t.setCurrentProjectId(null), t.setWorkspaceToken(null)), b && b !== t.currentProjectId && b !== ae.current && (ae.current = b, t.setCurrentProjectId(b)), t.workspaceToken && !x(t.workspaceToken, {
|
|
91
|
+
workspaceId: y,
|
|
97
92
|
organizationId: p,
|
|
98
|
-
projectId:
|
|
93
|
+
projectId: b,
|
|
94
|
+
workspaceWide: !b && d({
|
|
95
|
+
organizationId: p,
|
|
96
|
+
workspaceId: y
|
|
97
|
+
})
|
|
99
98
|
})) {
|
|
100
|
-
let e = `${p ?? ""}|${
|
|
101
|
-
|
|
99
|
+
let e = `${p ?? ""}|${y ?? ""}|${b ?? ""}`;
|
|
100
|
+
oe.current !== e && (oe.current = e, t.setWorkspaceToken(null));
|
|
102
101
|
}
|
|
103
102
|
}, [
|
|
104
103
|
p,
|
|
105
|
-
|
|
106
|
-
|
|
104
|
+
y,
|
|
105
|
+
b
|
|
107
106
|
]);
|
|
108
107
|
let X = n(async () => {
|
|
109
|
-
if (
|
|
110
|
-
let t = e.getState(), n =
|
|
111
|
-
return n ? (t.setLoadingOrganizations(!0),
|
|
108
|
+
if (W.current) return W.current;
|
|
109
|
+
let t = e.getState(), n = w();
|
|
110
|
+
return n ? (t.setLoadingOrganizations(!0), B(null), W.current = (async () => {
|
|
112
111
|
try {
|
|
113
|
-
let r =
|
|
114
|
-
let [e, t] = await Promise.all([
|
|
112
|
+
let r = q.current ?? t.currentOrganizationId, i = r ? await (async () => {
|
|
113
|
+
let [e, t] = await Promise.all([l({
|
|
115
114
|
gateway: "global",
|
|
116
|
-
query:
|
|
115
|
+
query: h,
|
|
117
116
|
authToken: n,
|
|
118
|
-
baseUrl:
|
|
119
|
-
}),
|
|
117
|
+
baseUrl: J
|
|
118
|
+
}), l({
|
|
120
119
|
gateway: "global",
|
|
121
|
-
query:
|
|
120
|
+
query: g,
|
|
122
121
|
authToken: n,
|
|
123
|
-
baseUrl:
|
|
122
|
+
baseUrl: J
|
|
124
123
|
})]);
|
|
125
124
|
return {
|
|
126
125
|
data: e.data?.myOrganizations ? {
|
|
@@ -129,28 +128,28 @@ function T(s) {
|
|
|
129
128
|
} : null,
|
|
130
129
|
errors: [...e.errors ?? [], ...t.errors ?? []]
|
|
131
130
|
};
|
|
132
|
-
})() : await
|
|
131
|
+
})() : await l({
|
|
133
132
|
gateway: "global",
|
|
134
|
-
query:
|
|
133
|
+
query: h,
|
|
135
134
|
authToken: n,
|
|
136
|
-
baseUrl:
|
|
135
|
+
baseUrl: J
|
|
137
136
|
});
|
|
138
|
-
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
|
|
137
|
+
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 l({
|
|
139
138
|
gateway: "global",
|
|
140
139
|
query: "\n query ContextSwitcherRecover {\n myOrganizations {\n total\n items { id name slug tenantId description logo website status type createdAt updatedAt }\n }\n workspaces: myWorkspaces {\n total\n items { id name slug tenantId organizationId type status region createdAt updatedAt }\n }\n }\n ",
|
|
141
140
|
authToken: n,
|
|
142
|
-
baseUrl:
|
|
141
|
+
baseUrl: J
|
|
143
142
|
})), i.errors?.length) {
|
|
144
143
|
let e = i.errors[0]?.message ?? "GraphQL error";
|
|
145
|
-
throw
|
|
144
|
+
throw C(i.errors) ? new S(e) : (t.workspaces.length === 0 && console.error("Failed to fetch organizations:", i.errors), Error(e));
|
|
146
145
|
}
|
|
147
146
|
let a = i.data?.myOrganizations?.items ?? [];
|
|
148
147
|
if (r && a.length === 0 && t.workspaces.length === 0) {
|
|
149
|
-
let e = await
|
|
148
|
+
let e = await l({
|
|
150
149
|
gateway: "global",
|
|
151
|
-
query:
|
|
150
|
+
query: h,
|
|
152
151
|
authToken: n,
|
|
153
|
-
baseUrl:
|
|
152
|
+
baseUrl: J
|
|
154
153
|
});
|
|
155
154
|
if (!e.errors?.length) a = e.data?.myOrganizations?.items ?? [], i = {
|
|
156
155
|
...e,
|
|
@@ -162,182 +161,225 @@ function T(s) {
|
|
|
162
161
|
else {
|
|
163
162
|
console.warn("[ContextSwitcher] Stale-context recovery failed:", e.errors);
|
|
164
163
|
let t = e.errors?.[0]?.message ?? "Failed to fetch organizations";
|
|
165
|
-
throw
|
|
164
|
+
throw C(e.errors ?? []) ? new S(t) : Error(t);
|
|
166
165
|
}
|
|
167
166
|
}
|
|
168
|
-
let o = a.length === 0 && t.workspaces.length > 0 ?
|
|
167
|
+
let o = a.length === 0 && t.workspaces.length > 0 ? T(t.workspaces) : [], s = o.length > 0 ? o : a;
|
|
169
168
|
t.setOrganizations(s);
|
|
170
|
-
let
|
|
171
|
-
if (
|
|
172
|
-
organizationId:
|
|
169
|
+
let c = r, u = c && a.some((e) => e.id === c);
|
|
170
|
+
if (c && !u && a.length > 0 && (c = a[0].id, O({
|
|
171
|
+
organizationId: c,
|
|
173
172
|
workspaceId: null,
|
|
174
173
|
tenantId: null,
|
|
175
174
|
projectId: null
|
|
176
|
-
}), t.setWorkspaces([]), t.setProjects([]), t.setCurrentWorkspaceId(null), t.setCurrentProjectId(null), t.setWorkspaceToken(null)),
|
|
175
|
+
}), t.setWorkspaces([]), t.setProjects([]), t.setCurrentWorkspaceId(null), t.setCurrentProjectId(null), t.setWorkspaceToken(null)), c && c !== t.currentOrganizationId && t.setCurrentOrganizationId(c), s.length > 0 && !c && (t.setCurrentOrganizationId(s[0].id), c = s[0].id), c && e.getState().workspaces.length === 0) {
|
|
177
176
|
t.setLoadingWorkspaces(!0);
|
|
178
177
|
try {
|
|
179
|
-
let e = (r ===
|
|
178
|
+
let e = (r === c ? i.data?.workspaces?.items?.filter((e) => e.organizationId === c) : void 0) || await l({
|
|
180
179
|
gateway: "global",
|
|
181
|
-
query:
|
|
180
|
+
query: g,
|
|
182
181
|
authToken: n,
|
|
183
|
-
baseUrl:
|
|
184
|
-
}).then((e) => e.errors?.length ? null : (e.data?.workspaces?.items ?? []).filter((e) => e.organizationId ===
|
|
185
|
-
if (e ||
|
|
182
|
+
baseUrl: J
|
|
183
|
+
}).then((e) => e.errors?.length ? null : (e.data?.workspaces?.items ?? []).filter((e) => e.organizationId === c));
|
|
184
|
+
if (e || H((e) => e + 1), e) {
|
|
186
185
|
t.setWorkspaces(e);
|
|
187
|
-
let n =
|
|
186
|
+
let n = K.current ? e.find((e) => e.id === K.current) : null;
|
|
188
187
|
if (n) t.setCurrentWorkspaceId(n.id);
|
|
189
188
|
else if (e.length > 0) {
|
|
190
189
|
let n = {
|
|
191
|
-
organizationId:
|
|
190
|
+
organizationId: c,
|
|
192
191
|
workspaceId: e[0].id,
|
|
193
192
|
tenantId: e[0].tenantId,
|
|
194
193
|
projectId: null
|
|
195
194
|
};
|
|
196
|
-
|
|
195
|
+
K.current ? (t.setCurrentWorkspaceId(e[0].id), t.setWorkspaceToken(null), O(n)) : t.currentWorkspaceId || (t.setCurrentWorkspaceId(e[0].id), O(n));
|
|
197
196
|
}
|
|
198
197
|
}
|
|
199
198
|
} catch {
|
|
200
|
-
|
|
199
|
+
H((e) => e + 1);
|
|
201
200
|
} finally {
|
|
202
201
|
t.setLoadingWorkspaces(!1);
|
|
203
202
|
}
|
|
204
203
|
}
|
|
205
|
-
return
|
|
204
|
+
return U.current = 0, s;
|
|
206
205
|
} catch (e) {
|
|
207
|
-
if (e instanceof
|
|
206
|
+
if (e instanceof S) return [];
|
|
208
207
|
let n = e instanceof Error ? e.message : "Failed to fetch organizations";
|
|
209
|
-
if (t.workspaces.length === 0 && console.error("Failed to fetch organizations:", e),
|
|
210
|
-
let e =
|
|
208
|
+
if (t.workspaces.length === 0 && console.error("Failed to fetch organizations:", e), B(n), H((e) => e + 1), t.workspaces.length > 0) {
|
|
209
|
+
let e = T(t.workspaces);
|
|
211
210
|
if (e.length > 0) return t.setOrganizations(e), t.currentOrganizationId || t.setCurrentOrganizationId(e[0].id), e;
|
|
212
211
|
}
|
|
213
212
|
return [];
|
|
214
213
|
} finally {
|
|
215
|
-
t.setLoadingOrganizations(!1),
|
|
214
|
+
t.setLoadingOrganizations(!1), W.current = null;
|
|
216
215
|
}
|
|
217
|
-
})(),
|
|
218
|
-
}, [
|
|
216
|
+
})(), W.current) : [];
|
|
217
|
+
}, [J, O]);
|
|
219
218
|
r(() => {
|
|
220
|
-
if (
|
|
221
|
-
|
|
222
|
-
let e = Math.min(1500 * 2 ** (
|
|
219
|
+
if (V === 0 || U.current >= 5 || !w()) return;
|
|
220
|
+
U.current += 1;
|
|
221
|
+
let e = Math.min(1500 * 2 ** (U.current - 1), 12e3), t = window.setTimeout(() => {
|
|
223
222
|
X();
|
|
224
223
|
}, e);
|
|
225
224
|
return () => {
|
|
226
225
|
window.clearTimeout(t);
|
|
227
226
|
};
|
|
228
|
-
}, [
|
|
227
|
+
}, [V, X]), r(() => {
|
|
229
228
|
let t = () => {
|
|
230
|
-
e.getState().organizations.length === 0 &&
|
|
229
|
+
e.getState().organizations.length === 0 && w() && (U.current = 0, X());
|
|
231
230
|
};
|
|
232
231
|
return window.addEventListener("online", t), () => {
|
|
233
232
|
window.removeEventListener("online", t);
|
|
234
233
|
};
|
|
235
234
|
}, [X]);
|
|
236
235
|
let Z = n(async (t) => {
|
|
237
|
-
let n =
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
236
|
+
let n = e.getState(), r = w(), i = o(), a = n.user?.id, s = JSON.stringify([
|
|
237
|
+
i,
|
|
238
|
+
a,
|
|
239
|
+
r,
|
|
240
|
+
t
|
|
241
|
+
]), c = G.current.get(s);
|
|
242
|
+
if (c) return c;
|
|
243
|
+
let u = () => {
|
|
244
|
+
let n = e.getState();
|
|
245
|
+
return o() === i && n.user?.id === a && w() === r && n.currentOrganizationId === t;
|
|
246
|
+
};
|
|
247
|
+
if (!r) return [];
|
|
248
|
+
n.setLoadingWorkspaces(!0), B(null);
|
|
249
|
+
let d = (async () => {
|
|
243
250
|
try {
|
|
244
|
-
let e = await
|
|
251
|
+
let e = await l({
|
|
245
252
|
gateway: "global",
|
|
246
|
-
query:
|
|
247
|
-
authToken:
|
|
248
|
-
baseUrl:
|
|
253
|
+
query: g,
|
|
254
|
+
authToken: r,
|
|
255
|
+
baseUrl: J
|
|
249
256
|
});
|
|
257
|
+
if (!u()) return [];
|
|
250
258
|
if (e.data?.workspaces?.items && (e.data.workspaces.items = e.data.workspaces.items.filter((e) => e.organizationId === t)), e.errors?.length) {
|
|
251
259
|
let t = e.errors[0]?.message ?? "GraphQL error";
|
|
252
|
-
throw
|
|
260
|
+
throw C(e.errors) ? new S(t) : (console.error("Failed to fetch workspaces:", e.errors), Error(t));
|
|
253
261
|
}
|
|
254
|
-
let
|
|
255
|
-
return
|
|
262
|
+
let i = (e.data?.workspaces?.items ?? []).filter((e) => e.organizationId === t);
|
|
263
|
+
return n.setWorkspaces(i), i;
|
|
256
264
|
} catch (e) {
|
|
257
|
-
if (e instanceof
|
|
265
|
+
if (!u() || e instanceof S) return [];
|
|
258
266
|
let t = e instanceof Error ? e.message : "Failed to fetch workspaces";
|
|
259
|
-
return console.error("Failed to fetch workspaces:", e),
|
|
267
|
+
return console.error("Failed to fetch workspaces:", e), B(t), [];
|
|
260
268
|
} finally {
|
|
261
|
-
|
|
269
|
+
u() && n.setLoadingWorkspaces(!1), G.current.delete(s);
|
|
262
270
|
}
|
|
263
271
|
})();
|
|
264
|
-
return
|
|
265
|
-
}, [
|
|
266
|
-
let a = e.getState(),
|
|
267
|
-
|
|
272
|
+
return G.current.set(s, d), d;
|
|
273
|
+
}, [J]), Q = n(async (t, n, r, i) => {
|
|
274
|
+
let a = e.getState(), s = [
|
|
275
|
+
a.currentOrganizationId,
|
|
276
|
+
a.currentWorkspaceId,
|
|
277
|
+
a.currentProjectId
|
|
278
|
+
], c = d({
|
|
279
|
+
organizationId: t,
|
|
280
|
+
workspaceId: n ?? null
|
|
281
|
+
}), u = w(), f = o(), p = a.user?.id;
|
|
282
|
+
if (!u) return {
|
|
268
283
|
success: !1,
|
|
269
284
|
error: "No valid access token available"
|
|
270
285
|
};
|
|
271
|
-
|
|
286
|
+
B(null);
|
|
272
287
|
try {
|
|
273
|
-
let
|
|
288
|
+
let m = await l({
|
|
274
289
|
gateway: "workspace",
|
|
275
|
-
query:
|
|
290
|
+
query: _,
|
|
276
291
|
variables: { input: {
|
|
277
292
|
organizationId: t,
|
|
278
293
|
...n && { workspaceId: n },
|
|
279
294
|
...r && { projectId: r }
|
|
280
295
|
} },
|
|
281
|
-
authToken:
|
|
282
|
-
baseUrl:
|
|
296
|
+
authToken: u,
|
|
297
|
+
baseUrl: Y,
|
|
283
298
|
tenantId: i
|
|
284
299
|
});
|
|
285
|
-
if (
|
|
286
|
-
let
|
|
287
|
-
return
|
|
300
|
+
if (m.errors?.length) {
|
|
301
|
+
let e = m.errors[0]?.message ?? "GraphQL error";
|
|
302
|
+
return C(m.errors) || console.error("Failed to issue workspace token:", m.errors), {
|
|
288
303
|
success: !1,
|
|
289
|
-
error:
|
|
304
|
+
error: e
|
|
290
305
|
};
|
|
291
306
|
}
|
|
292
|
-
let
|
|
293
|
-
if (
|
|
294
|
-
let
|
|
295
|
-
|
|
307
|
+
let h = m.data?.issueWorkspaceToken;
|
|
308
|
+
if (h?.success && h.token) {
|
|
309
|
+
let i = e.getState();
|
|
310
|
+
if (o() !== f || e.getState().user?.id !== p || w() !== u || s.some((e, t) => e !== [
|
|
311
|
+
i.currentOrganizationId,
|
|
312
|
+
i.currentWorkspaceId,
|
|
313
|
+
i.currentProjectId
|
|
314
|
+
][t]) || d({
|
|
315
|
+
organizationId: t,
|
|
316
|
+
workspaceId: n ?? null
|
|
317
|
+
}) !== c || !x(h.token, {
|
|
318
|
+
organizationId: t,
|
|
319
|
+
workspaceId: n,
|
|
320
|
+
projectId: r,
|
|
321
|
+
workspaceWide: c
|
|
322
|
+
})) return {
|
|
323
|
+
success: !1,
|
|
324
|
+
error: "Workspace context changed during token issuance"
|
|
325
|
+
};
|
|
326
|
+
let l = h.workspaceId || n;
|
|
327
|
+
return l && a.setCurrentWorkspaceId(l), a.setWorkspaceToken(h.token), {
|
|
296
328
|
success: !0,
|
|
297
|
-
token:
|
|
298
|
-
resolvedWorkspaceId:
|
|
329
|
+
token: h.token,
|
|
330
|
+
resolvedWorkspaceId: l || void 0
|
|
299
331
|
};
|
|
300
332
|
}
|
|
301
333
|
return {
|
|
302
334
|
success: !1,
|
|
303
|
-
error:
|
|
335
|
+
error: h?.error?.message ?? "Failed to issue workspace token"
|
|
304
336
|
};
|
|
305
337
|
} catch (e) {
|
|
306
338
|
let t = e instanceof Error ? e.message : "Failed to issue workspace token";
|
|
307
|
-
return console.error("Failed to issue workspace token:", e),
|
|
339
|
+
return console.error("Failed to issue workspace token:", e), B(t), {
|
|
308
340
|
success: !1,
|
|
309
341
|
error: t
|
|
310
342
|
};
|
|
311
343
|
}
|
|
312
|
-
}, [
|
|
313
|
-
let t = e.getState(), n =
|
|
344
|
+
}, [Y]), $ = n(async () => {
|
|
345
|
+
let t = e.getState(), n = w(), r = t.workspaceToken, i = t.currentWorkspaceId, a = o(), s = t.user?.id, c = t.currentOrganizationId, u = t.currentProjectId, f = d({
|
|
346
|
+
organizationId: c,
|
|
347
|
+
workspaceId: i
|
|
348
|
+
}), p = () => {
|
|
349
|
+
let t = e.getState();
|
|
350
|
+
return o() === a && t.user?.id === s && w() === n && t.workspaceToken === r && t.currentOrganizationId === c && t.currentWorkspaceId === i && t.currentProjectId === u && d({
|
|
351
|
+
organizationId: c,
|
|
352
|
+
workspaceId: i
|
|
353
|
+
}) === f;
|
|
354
|
+
};
|
|
314
355
|
if (!n || !r || !i) return [];
|
|
315
|
-
t.setLoadingProjects(!0),
|
|
356
|
+
t.setLoadingProjects(!0), B(null);
|
|
316
357
|
try {
|
|
317
|
-
let e = await
|
|
358
|
+
let e = await l({
|
|
318
359
|
gateway: "workspace",
|
|
319
|
-
query:
|
|
360
|
+
query: v,
|
|
320
361
|
authToken: n,
|
|
321
362
|
workspaceToken: r,
|
|
322
|
-
baseUrl:
|
|
363
|
+
baseUrl: Y
|
|
323
364
|
});
|
|
365
|
+
if (!p()) return [];
|
|
324
366
|
if (e.errors?.length) {
|
|
325
367
|
let t = e.errors[0]?.message ?? "GraphQL error";
|
|
326
|
-
throw
|
|
368
|
+
throw C(e.errors) ? new S(t) : (console.error("Failed to fetch projects:", e.errors), Error(t));
|
|
327
369
|
}
|
|
328
370
|
let i = e.data?.projects?.items ?? [];
|
|
329
371
|
return t.setProjects(i), i;
|
|
330
372
|
} catch (e) {
|
|
331
|
-
if (e instanceof
|
|
373
|
+
if (e instanceof S) return [];
|
|
332
374
|
let t = e instanceof Error ? e.message : "Failed to fetch projects";
|
|
333
|
-
return console.error("Failed to fetch projects:", e),
|
|
375
|
+
return console.error("Failed to fetch projects:", e), B(t), [];
|
|
334
376
|
} finally {
|
|
335
377
|
t.setLoadingProjects(!1);
|
|
336
378
|
}
|
|
337
|
-
}, [
|
|
379
|
+
}, [Y]), se = n(async (t) => {
|
|
338
380
|
let n = e.getState();
|
|
339
381
|
return n.setCurrentWorkspaceId(null), n.setWorkspaceToken(null), n.setProjects([]), n.setCurrentProjectId(null), n.setCurrentOrganizationId(t.id), await Z(t.id);
|
|
340
|
-
}, [Z]),
|
|
382
|
+
}, [Z]), ce = n(async (t) => {
|
|
341
383
|
let n = e.getState();
|
|
342
384
|
if (n.setCurrentProjectId(null), n.setProjects([]), !t.organizationId) return console.error("Workspace missing organizationId:", t), {
|
|
343
385
|
success: !1,
|
|
@@ -348,34 +390,45 @@ function T(s) {
|
|
|
348
390
|
success: !1,
|
|
349
391
|
error: r.error
|
|
350
392
|
};
|
|
351
|
-
let i =
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
393
|
+
let i = e.getState(), a = o(), s = i.user?.id, c = w(), l = i.workspaceToken, u = i.currentProjectId, f = d({
|
|
394
|
+
organizationId: t.organizationId,
|
|
395
|
+
workspaceId: t.id
|
|
396
|
+
}), p = () => {
|
|
397
|
+
let n = e.getState();
|
|
398
|
+
return o() === a && n.user?.id === s && w() === c && n.workspaceToken === l && n.currentOrganizationId === t.organizationId && n.currentWorkspaceId === t.id && n.currentProjectId === u && d({
|
|
399
|
+
organizationId: t.organizationId,
|
|
400
|
+
workspaceId: t.id
|
|
401
|
+
}) === f;
|
|
402
|
+
}, m = await $();
|
|
403
|
+
return p() ? (m.length > 0 && !d({
|
|
404
|
+
organizationId: t.organizationId,
|
|
405
|
+
workspaceId: t.id
|
|
406
|
+
}) && n.setCurrentProjectId(m[0].id), {
|
|
364
407
|
success: !0,
|
|
365
|
-
projects:
|
|
408
|
+
projects: m
|
|
409
|
+
}) : {
|
|
410
|
+
success: !1,
|
|
411
|
+
error: "Context changed during selection"
|
|
366
412
|
};
|
|
367
|
-
}, [
|
|
368
|
-
Q,
|
|
369
|
-
$,
|
|
370
|
-
G
|
|
371
|
-
]), oe = n((t) => {
|
|
413
|
+
}, [Q, $]), le = n((t) => {
|
|
372
414
|
let n = e.getState();
|
|
373
|
-
|
|
415
|
+
u({
|
|
416
|
+
organizationId: n.currentOrganizationId,
|
|
417
|
+
workspaceId: n.currentWorkspaceId
|
|
418
|
+
}), n.setCurrentProjectId(t.id), n.workspaceToken && !x(n.workspaceToken, {
|
|
374
419
|
workspaceId: n.currentWorkspaceId,
|
|
375
420
|
organizationId: n.currentOrganizationId,
|
|
376
421
|
projectId: t.id
|
|
377
422
|
}) && n.setWorkspaceToken(null);
|
|
378
|
-
}, [])
|
|
423
|
+
}, []), ue = n(() => {
|
|
424
|
+
let t = e.getState(), n = {
|
|
425
|
+
organizationId: q.current,
|
|
426
|
+
workspaceId: K.current
|
|
427
|
+
};
|
|
428
|
+
if (!n.organizationId || !n.workspaceId || t.currentOrganizationId !== n.organizationId || t.currentWorkspaceId !== n.workspaceId) throw Error("Current workspace context required");
|
|
429
|
+
if (!f(n)) throw Error("Workspace-wide preference could not be saved");
|
|
430
|
+
t.setCurrentProjectId(null), t.setWorkspaceToken(null), O({ projectId: null });
|
|
431
|
+
}, [O]);
|
|
379
432
|
return r(() => {
|
|
380
433
|
let t = !1, n = (e) => {
|
|
381
434
|
let n = !1, r = !1, i = () => {
|
|
@@ -393,58 +446,59 @@ function T(s) {
|
|
|
393
446
|
}, r = n(() => $()), i = n(() => {
|
|
394
447
|
let t = e.getState().currentOrganizationId;
|
|
395
448
|
return t ? Z(t) : Promise.resolve();
|
|
396
|
-
}), a =
|
|
449
|
+
}), a = k.onAny((t) => {
|
|
397
450
|
let n = t.name;
|
|
398
|
-
if (
|
|
399
|
-
let n =
|
|
451
|
+
if (E.has(n)) {
|
|
452
|
+
let n = ee(t.payload), { currentWorkspaceId: i } = e.getState();
|
|
400
453
|
if (n && i && n !== i) return;
|
|
401
454
|
r();
|
|
402
455
|
return;
|
|
403
456
|
}
|
|
404
|
-
|
|
457
|
+
D.has(n) && i();
|
|
405
458
|
});
|
|
406
459
|
return () => {
|
|
407
460
|
t = !0, a();
|
|
408
461
|
};
|
|
409
462
|
}, [
|
|
410
|
-
|
|
463
|
+
k,
|
|
411
464
|
$,
|
|
412
465
|
Z
|
|
413
466
|
]), {
|
|
414
|
-
organizations:
|
|
415
|
-
workspaces:
|
|
416
|
-
projects:
|
|
417
|
-
currentOrganizationId:
|
|
418
|
-
currentWorkspaceId:
|
|
419
|
-
currentProjectId:
|
|
420
|
-
currentOrganization:
|
|
421
|
-
currentWorkspace:
|
|
422
|
-
currentProject:
|
|
423
|
-
workspaceToken:
|
|
424
|
-
isLoadingOrganizations:
|
|
425
|
-
isLoadingWorkspaces:
|
|
426
|
-
isLoadingProjects:
|
|
427
|
-
isLoading:
|
|
428
|
-
error:
|
|
467
|
+
organizations: A,
|
|
468
|
+
workspaces: N,
|
|
469
|
+
projects: L,
|
|
470
|
+
currentOrganizationId: j,
|
|
471
|
+
currentWorkspaceId: P,
|
|
472
|
+
currentProjectId: R,
|
|
473
|
+
currentOrganization: A.find((e) => e.id === j),
|
|
474
|
+
currentWorkspace: N.find((e) => e.id === P),
|
|
475
|
+
currentProject: L.find((e) => e.id === R),
|
|
476
|
+
workspaceToken: F,
|
|
477
|
+
isLoadingOrganizations: M,
|
|
478
|
+
isLoadingWorkspaces: I,
|
|
479
|
+
isLoadingProjects: z,
|
|
480
|
+
isLoading: M || I || z,
|
|
481
|
+
error: te,
|
|
429
482
|
fetchOrganizations: X,
|
|
430
483
|
fetchWorkspacesForOrg: Z,
|
|
431
484
|
issueWorkspaceToken: Q,
|
|
432
485
|
fetchProjects: $,
|
|
433
|
-
selectOrganization:
|
|
434
|
-
selectWorkspace:
|
|
435
|
-
selectProject:
|
|
486
|
+
selectOrganization: se,
|
|
487
|
+
selectWorkspace: ce,
|
|
488
|
+
selectProject: le,
|
|
489
|
+
selectWorkspaceWide: ue
|
|
436
490
|
};
|
|
437
491
|
}
|
|
438
|
-
function
|
|
439
|
-
let i = e((e) => e.currentOrganizationId), a = e((e) => e.workspaces), o = e((e) => e.accessToken), s = e((e) => e.isLoadingWorkspaces),
|
|
492
|
+
function k(n) {
|
|
493
|
+
let i = e((e) => e.currentOrganizationId), a = e((e) => e.workspaces), o = e((e) => e.accessToken), s = e((e) => e.isLoadingWorkspaces), c = t(), u = n?.globalBaseUrl ?? c.globalBaseUrl, d = n?.disableWorkspaceSync ?? !1;
|
|
440
494
|
r(() => {
|
|
441
|
-
if (
|
|
495
|
+
if (d || !i || !o || s) return;
|
|
442
496
|
let t = a.some((e) => e.organizationId === i);
|
|
443
497
|
if (a.length > 0 && !t) {
|
|
444
498
|
let t = e.getState();
|
|
445
|
-
t.setLoadingWorkspaces(!0),
|
|
499
|
+
t.setLoadingWorkspaces(!0), l({
|
|
446
500
|
gateway: "global",
|
|
447
|
-
query:
|
|
501
|
+
query: g,
|
|
448
502
|
authToken: o,
|
|
449
503
|
baseUrl: u
|
|
450
504
|
}).then((e) => {
|
|
@@ -462,120 +516,153 @@ function E(n) {
|
|
|
462
516
|
o,
|
|
463
517
|
s,
|
|
464
518
|
u,
|
|
465
|
-
|
|
519
|
+
d
|
|
466
520
|
]);
|
|
467
521
|
}
|
|
468
|
-
function
|
|
469
|
-
let
|
|
522
|
+
function A(n) {
|
|
523
|
+
let s = e((e) => e.currentWorkspaceId), c = e((e) => e.currentOrganizationId), f = e((e) => e.workspaces), m = e((e) => e.projects), h = e((e) => e.currentProjectId), g = e((e) => e.workspaceToken), b = e((e) => e.accessToken), S = t(), C = n?.workspaceBaseUrl ?? S.workspaceBaseUrl, w = n?.disableProjectSync ?? !1, T = n?.skipProjectFetch ?? !1, E = i(!1), [D, ee] = a(0), O = i(null), k = i(/* @__PURE__ */ new Map()), A = i(/* @__PURE__ */ new Map()), j = 3e4;
|
|
470
524
|
r(() => {
|
|
471
|
-
if (
|
|
472
|
-
let t =
|
|
473
|
-
if (t && t.count >= 8 && Date.now() - t.lastFailureAt <
|
|
474
|
-
t && Date.now() - t.lastFailureAt >=
|
|
475
|
-
let n =
|
|
476
|
-
if (n &&
|
|
477
|
-
let r = n?.organizationId ??
|
|
525
|
+
if (w || !s || !b || E.current) return;
|
|
526
|
+
let t = A.current.get(s);
|
|
527
|
+
if (t && t.count >= 8 && Date.now() - t.lastFailureAt < j) return;
|
|
528
|
+
t && Date.now() - t.lastFailureAt >= j && A.current.delete(s);
|
|
529
|
+
let n = f.find((e) => e.id === s);
|
|
530
|
+
if (n && c && n.organizationId !== c) return;
|
|
531
|
+
let r = n?.organizationId ?? c;
|
|
478
532
|
if (!r) return;
|
|
479
|
-
let i = e.getState()
|
|
480
|
-
|
|
481
|
-
organizationId:
|
|
482
|
-
|
|
483
|
-
})
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
533
|
+
let i = e.getState();
|
|
534
|
+
h && p("project") === h && p("workspace") === s && p("org") === r && u({
|
|
535
|
+
organizationId: r,
|
|
536
|
+
workspaceId: s
|
|
537
|
+
});
|
|
538
|
+
let a = o(), S = i.user?.id, D = d({
|
|
539
|
+
organizationId: r,
|
|
540
|
+
workspaceId: s
|
|
541
|
+
});
|
|
542
|
+
if (D && i.currentProjectId) {
|
|
543
|
+
i.setCurrentProjectId(null), i.setWorkspaceToken(null);
|
|
544
|
+
return;
|
|
545
|
+
}
|
|
546
|
+
let M = !g || y(g) || !x(g, {
|
|
547
|
+
workspaceId: s,
|
|
548
|
+
organizationId: c,
|
|
549
|
+
projectId: h,
|
|
550
|
+
workspaceWide: D
|
|
551
|
+
}), N = JSON.stringify([
|
|
552
|
+
a,
|
|
553
|
+
S,
|
|
554
|
+
b,
|
|
555
|
+
r,
|
|
556
|
+
s
|
|
557
|
+
]), P = m.some((e) => e.workspaceId === s) || O.current?.scopeKey === N && O.current.projects === m;
|
|
558
|
+
if (P && !M) {
|
|
559
|
+
if (!i.currentProjectId && !D) {
|
|
560
|
+
let e = m.find((e) => e.workspaceId === s);
|
|
487
561
|
e && i.setCurrentProjectId(e.id);
|
|
488
562
|
}
|
|
489
563
|
return;
|
|
490
564
|
}
|
|
491
|
-
let
|
|
492
|
-
|
|
565
|
+
let F = () => {
|
|
566
|
+
let t = e.getState();
|
|
567
|
+
return t.accessToken === b && t.user?.id === S && o() === a && t.currentOrganizationId === r && t.currentWorkspaceId === s && t.currentProjectId === h && d({
|
|
568
|
+
organizationId: r,
|
|
569
|
+
workspaceId: s
|
|
570
|
+
}) === D;
|
|
571
|
+
}, I = async () => {
|
|
572
|
+
E.current = !0, i.setLoadingProjects(!0);
|
|
493
573
|
let t = !1;
|
|
494
574
|
try {
|
|
495
|
-
let
|
|
496
|
-
if (
|
|
497
|
-
let
|
|
575
|
+
let n = g;
|
|
576
|
+
if (M) {
|
|
577
|
+
let e = await l({
|
|
498
578
|
gateway: "workspace",
|
|
499
|
-
query:
|
|
579
|
+
query: _,
|
|
500
580
|
variables: { input: {
|
|
501
581
|
organizationId: r,
|
|
502
|
-
workspaceId:
|
|
503
|
-
...
|
|
582
|
+
workspaceId: s,
|
|
583
|
+
...h ? { projectId: h } : {}
|
|
504
584
|
} },
|
|
505
|
-
authToken:
|
|
506
|
-
baseUrl:
|
|
507
|
-
tenantId:
|
|
585
|
+
authToken: b,
|
|
586
|
+
baseUrl: C,
|
|
587
|
+
tenantId: f.find((e) => e.id === s)?.tenantId
|
|
508
588
|
});
|
|
509
|
-
if (
|
|
510
|
-
|
|
589
|
+
if (e.data?.issueWorkspaceToken?.success && e.data.issueWorkspaceToken.token) {
|
|
590
|
+
if (n = e.data.issueWorkspaceToken.token, !F() || !x(n, {
|
|
591
|
+
workspaceId: s,
|
|
592
|
+
organizationId: r,
|
|
593
|
+
projectId: h,
|
|
594
|
+
workspaceWide: D
|
|
595
|
+
})) return;
|
|
596
|
+
i.setWorkspaceToken(n);
|
|
597
|
+
} else return;
|
|
511
598
|
}
|
|
512
|
-
if (
|
|
513
|
-
let t = await
|
|
599
|
+
if (n && !P && !T) {
|
|
600
|
+
let t = await l({
|
|
514
601
|
gateway: "workspace",
|
|
515
|
-
query:
|
|
516
|
-
authToken:
|
|
517
|
-
workspaceToken:
|
|
518
|
-
baseUrl:
|
|
602
|
+
query: v,
|
|
603
|
+
authToken: b,
|
|
604
|
+
workspaceToken: n,
|
|
605
|
+
baseUrl: C
|
|
519
606
|
});
|
|
520
|
-
if (t.errors?.length) return;
|
|
521
|
-
let
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
else return;
|
|
530
|
-
}
|
|
531
|
-
i.setProjects(n), n.length > 0 && !i.currentProjectId && i.setCurrentProjectId(n[0].id);
|
|
607
|
+
if (!F() || t.errors?.length) return;
|
|
608
|
+
let a = t.data?.projects?.items ?? [];
|
|
609
|
+
O.current = a.length === 0 ? {
|
|
610
|
+
scopeKey: N,
|
|
611
|
+
projects: a
|
|
612
|
+
} : null, i.setProjects(a), h && !a.some((e) => e.id === h) && (i.setCurrentProjectId(null), i.setWorkspaceToken(null)), a.length > 0 && !e.getState().currentProjectId && !d({
|
|
613
|
+
organizationId: r,
|
|
614
|
+
workspaceId: s
|
|
615
|
+
}) && i.setCurrentProjectId(a[0].id);
|
|
532
616
|
}
|
|
533
617
|
t = !0;
|
|
534
618
|
} catch {} finally {
|
|
535
|
-
i.setLoadingProjects(!1),
|
|
536
|
-
let n =
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
619
|
+
i.setLoadingProjects(!1), E.current = !1;
|
|
620
|
+
let n = F();
|
|
621
|
+
n || ee((e) => e + 1);
|
|
622
|
+
let r = A.current;
|
|
623
|
+
if (n && t) {
|
|
624
|
+
r.delete(s);
|
|
625
|
+
let e = k.current.get(s);
|
|
626
|
+
e && (clearTimeout(e), k.current.delete(s));
|
|
627
|
+
} else if (n) {
|
|
628
|
+
let t = (r.get(s)?.count ?? 0) + 1;
|
|
629
|
+
if (r.set(s, {
|
|
544
630
|
count: t,
|
|
545
631
|
lastFailureAt: Date.now()
|
|
546
632
|
}), t < 8) {
|
|
547
|
-
let n =
|
|
633
|
+
let n = k.current.get(s);
|
|
548
634
|
n && clearTimeout(n);
|
|
549
635
|
let r = Math.min(1e3 * 2 ** (t - 1), 8e3), i = setTimeout(() => {
|
|
550
|
-
|
|
636
|
+
k.current.delete(s);
|
|
551
637
|
let t = e.getState();
|
|
552
|
-
t.currentWorkspaceId ===
|
|
638
|
+
F() && t.currentWorkspaceId === s && !t.projects.some((e) => e.workspaceId === s) && !E.current && I();
|
|
553
639
|
}, r);
|
|
554
|
-
|
|
640
|
+
k.current.set(s, i);
|
|
555
641
|
}
|
|
556
642
|
}
|
|
557
643
|
}
|
|
558
644
|
};
|
|
559
|
-
|
|
645
|
+
I();
|
|
560
646
|
}, [
|
|
561
|
-
|
|
562
|
-
o,
|
|
647
|
+
D,
|
|
563
648
|
s,
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
649
|
+
c,
|
|
650
|
+
f,
|
|
651
|
+
m,
|
|
652
|
+
h,
|
|
653
|
+
g,
|
|
654
|
+
b,
|
|
655
|
+
C,
|
|
656
|
+
w,
|
|
657
|
+
T
|
|
571
658
|
]), r(() => {
|
|
572
|
-
let e =
|
|
659
|
+
let e = k.current;
|
|
573
660
|
return () => {
|
|
574
661
|
e.forEach((e) => clearTimeout(e)), e.clear();
|
|
575
662
|
};
|
|
576
663
|
}, []);
|
|
577
664
|
}
|
|
578
665
|
//#endregion
|
|
579
|
-
export {
|
|
666
|
+
export { O as useContextSwitcherData, A as useProjectSyncEffect, k as useWorkspaceSyncEffect };
|
|
580
667
|
|
|
581
668
|
//# sourceMappingURL=useContextSwitcherData.js.map
|