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