@burdenoff/microfe-auth 2026.627.1 → 2026.627.2
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/hooks/useContextSwitcherData.js +215 -161
- package/dist/auth/hooks/useContextSwitcherData.js.map +1 -1
- package/dist/auth/pages/SecurityPage.js.map +1 -1
- package/dist/auth/pages/SsoConfigPage.js.map +1 -1
- package/dist/auth/pages/UserDetailsPage.js.map +1 -1
- package/dist/auth/pages/UserProfilePage.js.map +1 -1
- package/dist/auth/pages/UsersPage.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,14 +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 {
|
|
4
|
+
import { useEventBus as o } from "@burdenoff/fe-libs/shared/events";
|
|
5
|
+
import { getStoredAuthToken as s, graphqlFetch as c } from "@burdenoff/fe-libs/shared/graphql";
|
|
6
|
+
import { useActiveContext as l } from "@burdenoff/fe-libs/shared/providers/shell/ActiveContextProvider";
|
|
6
7
|
//#region src/auth/hooks/useContextSwitcherData.ts
|
|
7
|
-
var
|
|
8
|
-
async function
|
|
9
|
-
let r = await
|
|
8
|
+
var u = "\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", d = "\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", f = "\n query ContextSwitcherBootstrap {\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: 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", p = "\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", m = "\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", h = "\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";
|
|
9
|
+
async function g({ authToken: e, workspaceBaseUrl: t, workspaceToken: n }) {
|
|
10
|
+
let r = await c({
|
|
10
11
|
gateway: "workspace",
|
|
11
|
-
query:
|
|
12
|
+
query: h,
|
|
12
13
|
variables: { input: { name: "Default Project" } },
|
|
13
14
|
authToken: e,
|
|
14
15
|
workspaceToken: n,
|
|
@@ -16,7 +17,7 @@ async function h({ authToken: e, workspaceBaseUrl: t, workspaceToken: n }) {
|
|
|
16
17
|
});
|
|
17
18
|
return r.errors?.length ? (console.warn("Failed to create default project:", r.errors), null) : r.data?.createProject ?? null;
|
|
18
19
|
}
|
|
19
|
-
function
|
|
20
|
+
function _(e, t = 3e4) {
|
|
20
21
|
try {
|
|
21
22
|
let n = JSON.parse(atob(e.split(".")[1]));
|
|
22
23
|
return n.exp ? n.exp * 1e3 < Date.now() + t : !1;
|
|
@@ -24,7 +25,7 @@ function g(e, t = 3e4) {
|
|
|
24
25
|
return !0;
|
|
25
26
|
}
|
|
26
27
|
}
|
|
27
|
-
function
|
|
28
|
+
function v(e) {
|
|
28
29
|
try {
|
|
29
30
|
let t = JSON.parse(atob(e.split(".")[1]));
|
|
30
31
|
return {
|
|
@@ -37,26 +38,26 @@ function _(e) {
|
|
|
37
38
|
return null;
|
|
38
39
|
}
|
|
39
40
|
}
|
|
40
|
-
function
|
|
41
|
-
if (!e ||
|
|
42
|
-
let n =
|
|
41
|
+
function y(e, t) {
|
|
42
|
+
if (!e || _(e)) return !1;
|
|
43
|
+
let n = v(e);
|
|
43
44
|
return !(!n || t.workspaceId && n.workspaceId !== t.workspaceId || t.organizationId && n.organizationId !== t.organizationId || t.projectId && n.projectId !== t.projectId);
|
|
44
45
|
}
|
|
45
|
-
var
|
|
46
|
+
var b = class extends Error {
|
|
46
47
|
constructor(e) {
|
|
47
48
|
super(e), this.name = "AuthError";
|
|
48
49
|
}
|
|
49
50
|
};
|
|
50
|
-
function
|
|
51
|
+
function x(e) {
|
|
51
52
|
return e.some((e) => e.extensions?.code === "UNAUTHENTICATED" || e.message?.toLowerCase().includes("unauthorized") || e.message?.toLowerCase().includes("not authenticated"));
|
|
52
53
|
}
|
|
53
|
-
function
|
|
54
|
+
function S() {
|
|
54
55
|
let t = e.getState().accessToken;
|
|
55
|
-
if (t && !
|
|
56
|
-
let n =
|
|
57
|
-
return n && !
|
|
56
|
+
if (t && !_(t)) return t;
|
|
57
|
+
let n = s();
|
|
58
|
+
return n && !_(n) ? n : t;
|
|
58
59
|
}
|
|
59
|
-
function
|
|
60
|
+
function C(e) {
|
|
60
61
|
return Array.from(new Set(e.flatMap((e) => e.organizationId ? [e.organizationId] : []))).map((t, n) => ({
|
|
61
62
|
id: t,
|
|
62
63
|
name: e.find((e) => e.organizationId === t)?.name || `Organization ${n + 1}`,
|
|
@@ -64,55 +65,74 @@ function S(e) {
|
|
|
64
65
|
tenantId: e.find((e) => e.organizationId === t)?.tenantId || ""
|
|
65
66
|
}));
|
|
66
67
|
}
|
|
67
|
-
|
|
68
|
-
|
|
68
|
+
var w = new Set([
|
|
69
|
+
"project.created",
|
|
70
|
+
"project.updated",
|
|
71
|
+
"project.deleted",
|
|
72
|
+
"project.archived",
|
|
73
|
+
"project.unarchived"
|
|
74
|
+
]), T = new Set([
|
|
75
|
+
"workspace.created",
|
|
76
|
+
"workspace.updated",
|
|
77
|
+
"workspace.deleted",
|
|
78
|
+
"workspace.archived",
|
|
79
|
+
"workspace.reactivated"
|
|
80
|
+
]);
|
|
81
|
+
function E(e) {
|
|
82
|
+
if (e && typeof e == "object" && "workspaceId" in e) {
|
|
83
|
+
let t = e.workspaceId;
|
|
84
|
+
return typeof t == "string" ? t : void 0;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
function D(s) {
|
|
88
|
+
let { organizationId: h, workspaceId: v, projectId: D, setContext: O } = l(), k = o(), 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), ee = e((e) => e.workspaceToken), F = e((e) => e.isLoadingWorkspaces), I = e((e) => e.projects), L = e((e) => e.currentProjectId), R = e((e) => e.isLoadingProjects), [te, z] = a(null), B = i(null), V = i(/* @__PURE__ */ new Map()), H = i(v), U = i(h);
|
|
69
89
|
r(() => {
|
|
70
|
-
|
|
90
|
+
H.current = v, U.current = h;
|
|
71
91
|
});
|
|
72
|
-
let
|
|
92
|
+
let W = t(), G = s?.globalBaseUrl ?? W.globalBaseUrl, K = s?.workspaceBaseUrl ?? W.workspaceBaseUrl, q = i(null), J = i(null), Y = i(null), X = i(null);
|
|
73
93
|
r(() => {
|
|
74
94
|
let t = e.getState();
|
|
75
|
-
if (
|
|
76
|
-
workspaceId:
|
|
77
|
-
organizationId:
|
|
78
|
-
projectId:
|
|
95
|
+
if (h && h !== t.currentOrganizationId && h !== q.current && (q.current = h, t.setCurrentOrganizationId(h), t.workspaces.length > 0 && !t.workspaces.some((e) => e.organizationId === h) && t.setWorkspaces([])), v && v !== t.currentWorkspaceId && v !== J.current && (J.current = v, t.setCurrentWorkspaceId(v), t.projects.length > 0 && !t.projects.some((e) => e.workspaceId === v) && (t.setProjects([]), t.setCurrentProjectId(null))), D && D !== t.currentProjectId && D !== Y.current && (Y.current = D, t.setCurrentProjectId(D)), t.workspaceToken && !y(t.workspaceToken, {
|
|
96
|
+
workspaceId: v,
|
|
97
|
+
organizationId: h,
|
|
98
|
+
projectId: D
|
|
79
99
|
})) {
|
|
80
|
-
let e = `${
|
|
81
|
-
|
|
100
|
+
let e = `${h ?? ""}|${v ?? ""}|${D ?? ""}`;
|
|
101
|
+
X.current !== e && (X.current = e, t.setWorkspaceToken(null));
|
|
82
102
|
}
|
|
83
103
|
}, [
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
104
|
+
h,
|
|
105
|
+
v,
|
|
106
|
+
D
|
|
87
107
|
]);
|
|
88
|
-
let
|
|
89
|
-
if (
|
|
90
|
-
let t = e.getState(), n =
|
|
91
|
-
return !n ||
|
|
108
|
+
let ne = n(async () => {
|
|
109
|
+
if (B.current) return B.current;
|
|
110
|
+
let t = e.getState(), n = S();
|
|
111
|
+
return !n || _(n) ? [] : (t.setLoadingOrganizations(!0), z(null), B.current = (async () => {
|
|
92
112
|
try {
|
|
93
|
-
let r =
|
|
113
|
+
let r = U.current ?? t.currentOrganizationId, i = await c({
|
|
94
114
|
gateway: "global",
|
|
95
|
-
query: r ?
|
|
115
|
+
query: r ? f : u,
|
|
96
116
|
variables: void 0,
|
|
97
117
|
authToken: n,
|
|
98
|
-
baseUrl:
|
|
118
|
+
baseUrl: G
|
|
99
119
|
});
|
|
100
|
-
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
|
|
120
|
+
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 c({
|
|
101
121
|
gateway: "global",
|
|
102
122
|
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 ",
|
|
103
123
|
authToken: n,
|
|
104
|
-
baseUrl:
|
|
124
|
+
baseUrl: G
|
|
105
125
|
})), i.errors?.length) {
|
|
106
126
|
let e = i.errors[0]?.message ?? "GraphQL error";
|
|
107
|
-
throw
|
|
127
|
+
throw x(i.errors) ? new b(e) : (t.workspaces.length === 0 && console.error("Failed to fetch organizations:", i.errors), Error(e));
|
|
108
128
|
}
|
|
109
129
|
let a = i.data?.myOrganizations?.items ?? [];
|
|
110
130
|
if (r && a.length === 0 && t.workspaces.length === 0) {
|
|
111
|
-
let e = await
|
|
131
|
+
let e = await c({
|
|
112
132
|
gateway: "global",
|
|
113
|
-
query:
|
|
133
|
+
query: u,
|
|
114
134
|
authToken: n,
|
|
115
|
-
baseUrl:
|
|
135
|
+
baseUrl: G
|
|
116
136
|
});
|
|
117
137
|
e.errors?.length ? console.warn("[ContextSwitcher] Stale-context recovery failed:", e.errors) : (a = e.data?.myOrganizations?.items ?? [], i = {
|
|
118
138
|
...e,
|
|
@@ -122,105 +142,105 @@ function C(o) {
|
|
|
122
142
|
} }
|
|
123
143
|
});
|
|
124
144
|
}
|
|
125
|
-
let o = a.length === 0 && t.workspaces.length > 0 ?
|
|
126
|
-
t.setOrganizations(
|
|
127
|
-
let
|
|
128
|
-
if (
|
|
129
|
-
organizationId:
|
|
145
|
+
let o = a.length === 0 && t.workspaces.length > 0 ? C(t.workspaces) : [], s = o.length > 0 ? o : a;
|
|
146
|
+
t.setOrganizations(s);
|
|
147
|
+
let l = r, p = l && a.some((e) => e.id === l);
|
|
148
|
+
if (l && !p && a.length > 0 && (l = a[0].id, O({
|
|
149
|
+
organizationId: l,
|
|
130
150
|
workspaceId: null,
|
|
131
151
|
tenantId: null,
|
|
132
152
|
projectId: null
|
|
133
|
-
}), t.setWorkspaces([]), t.setProjects([]), t.setCurrentWorkspaceId(null), t.setCurrentProjectId(null), t.setWorkspaceToken(null)),
|
|
153
|
+
}), t.setWorkspaces([]), t.setProjects([]), t.setCurrentWorkspaceId(null), t.setCurrentProjectId(null), t.setWorkspaceToken(null)), l && l !== t.currentOrganizationId && t.setCurrentOrganizationId(l), s.length > 0 && !l && (t.setCurrentOrganizationId(s[0].id), l = s[0].id), l && e.getState().workspaces.length === 0) {
|
|
134
154
|
t.setLoadingWorkspaces(!0);
|
|
135
155
|
try {
|
|
136
|
-
let e = (r ===
|
|
156
|
+
let e = (r === l ? i.data?.workspaces?.items?.filter((e) => e.organizationId === l) : void 0) || await c({
|
|
137
157
|
gateway: "global",
|
|
138
|
-
query:
|
|
158
|
+
query: d,
|
|
139
159
|
authToken: n,
|
|
140
|
-
baseUrl:
|
|
141
|
-
}).then((e) => e.errors?.length ? null : (e.data?.workspaces?.items ?? []).filter((e) => e.organizationId ===
|
|
160
|
+
baseUrl: G
|
|
161
|
+
}).then((e) => e.errors?.length ? null : (e.data?.workspaces?.items ?? []).filter((e) => e.organizationId === l));
|
|
142
162
|
if (e) {
|
|
143
163
|
t.setWorkspaces(e);
|
|
144
|
-
let n =
|
|
164
|
+
let n = H.current ? e.find((e) => e.id === H.current) : null;
|
|
145
165
|
if (n) t.setCurrentWorkspaceId(n.id);
|
|
146
166
|
else if (e.length > 0) {
|
|
147
167
|
let n = {
|
|
148
|
-
organizationId:
|
|
168
|
+
organizationId: l,
|
|
149
169
|
workspaceId: e[0].id,
|
|
150
170
|
tenantId: e[0].tenantId,
|
|
151
171
|
projectId: null
|
|
152
172
|
};
|
|
153
|
-
|
|
173
|
+
H.current ? (t.setCurrentWorkspaceId(e[0].id), t.setWorkspaceToken(null), O(n)) : t.currentWorkspaceId || (t.setCurrentWorkspaceId(e[0].id), O(n));
|
|
154
174
|
}
|
|
155
175
|
}
|
|
156
176
|
} catch {} finally {
|
|
157
177
|
t.setLoadingWorkspaces(!1);
|
|
158
178
|
}
|
|
159
179
|
}
|
|
160
|
-
return
|
|
180
|
+
return s;
|
|
161
181
|
} catch (e) {
|
|
162
|
-
if (e instanceof
|
|
182
|
+
if (e instanceof b) return [];
|
|
163
183
|
let n = e instanceof Error ? e.message : "Failed to fetch organizations";
|
|
164
|
-
if (t.workspaces.length === 0 && console.error("Failed to fetch organizations:", e),
|
|
165
|
-
let e =
|
|
184
|
+
if (t.workspaces.length === 0 && console.error("Failed to fetch organizations:", e), z(n), t.workspaces.length > 0) {
|
|
185
|
+
let e = C(t.workspaces);
|
|
166
186
|
if (e.length > 0) return t.setOrganizations(e), t.currentOrganizationId || t.setCurrentOrganizationId(e[0].id), e;
|
|
167
187
|
}
|
|
168
188
|
return [];
|
|
169
189
|
} finally {
|
|
170
|
-
t.setLoadingOrganizations(!1),
|
|
190
|
+
t.setLoadingOrganizations(!1), B.current = null;
|
|
171
191
|
}
|
|
172
|
-
})(),
|
|
173
|
-
}, [
|
|
174
|
-
let n =
|
|
192
|
+
})(), B.current);
|
|
193
|
+
}, [G, O]), Z = n(async (t) => {
|
|
194
|
+
let n = V.current.get(t);
|
|
175
195
|
if (n) return n;
|
|
176
|
-
let r = e.getState(), i =
|
|
177
|
-
if (!i ||
|
|
178
|
-
r.setLoadingWorkspaces(!0),
|
|
196
|
+
let r = e.getState(), i = S();
|
|
197
|
+
if (!i || _(i)) return [];
|
|
198
|
+
r.setLoadingWorkspaces(!0), z(null);
|
|
179
199
|
let a = (async () => {
|
|
180
200
|
try {
|
|
181
|
-
let e = await
|
|
201
|
+
let e = await c({
|
|
182
202
|
gateway: "global",
|
|
183
|
-
query:
|
|
203
|
+
query: d,
|
|
184
204
|
authToken: i,
|
|
185
|
-
baseUrl:
|
|
205
|
+
baseUrl: G
|
|
186
206
|
});
|
|
187
207
|
if (e.data?.workspaces?.items && (e.data.workspaces.items = e.data.workspaces.items.filter((e) => e.organizationId === t)), e.errors?.length) {
|
|
188
208
|
let t = e.errors[0]?.message ?? "GraphQL error";
|
|
189
|
-
throw
|
|
209
|
+
throw x(e.errors) ? new b(t) : (console.error("Failed to fetch workspaces:", e.errors), Error(t));
|
|
190
210
|
}
|
|
191
211
|
let n = (e.data?.workspaces?.items ?? []).filter((e) => e.organizationId === t);
|
|
192
212
|
return r.setWorkspaces(n), n;
|
|
193
213
|
} catch (e) {
|
|
194
|
-
if (e instanceof
|
|
214
|
+
if (e instanceof b) return [];
|
|
195
215
|
let t = e instanceof Error ? e.message : "Failed to fetch workspaces";
|
|
196
|
-
return console.error("Failed to fetch workspaces:", e),
|
|
216
|
+
return console.error("Failed to fetch workspaces:", e), z(t), [];
|
|
197
217
|
} finally {
|
|
198
|
-
r.setLoadingWorkspaces(!1),
|
|
218
|
+
r.setLoadingWorkspaces(!1), V.current.delete(t);
|
|
199
219
|
}
|
|
200
220
|
})();
|
|
201
|
-
return
|
|
202
|
-
}, [
|
|
203
|
-
let i = e.getState(), a =
|
|
204
|
-
if (!a ||
|
|
221
|
+
return V.current.set(t, a), a;
|
|
222
|
+
}, [G]), Q = n(async (t, n, r) => {
|
|
223
|
+
let i = e.getState(), a = S();
|
|
224
|
+
if (!a || _(a)) return {
|
|
205
225
|
success: !1,
|
|
206
226
|
error: "No valid access token available"
|
|
207
227
|
};
|
|
208
|
-
|
|
228
|
+
z(null);
|
|
209
229
|
try {
|
|
210
|
-
let e = await
|
|
230
|
+
let e = await c({
|
|
211
231
|
gateway: "workspace",
|
|
212
|
-
query:
|
|
232
|
+
query: p,
|
|
213
233
|
variables: { input: {
|
|
214
234
|
organizationId: t,
|
|
215
235
|
...n && { workspaceId: n },
|
|
216
236
|
...r && { projectId: r }
|
|
217
237
|
} },
|
|
218
238
|
authToken: a,
|
|
219
|
-
baseUrl:
|
|
239
|
+
baseUrl: K
|
|
220
240
|
});
|
|
221
241
|
if (e.errors?.length) {
|
|
222
242
|
let t = e.errors[0]?.message ?? "GraphQL error";
|
|
223
|
-
return
|
|
243
|
+
return x(e.errors) || console.error("Failed to issue workspace token:", e.errors), {
|
|
224
244
|
success: !1,
|
|
225
245
|
error: t
|
|
226
246
|
};
|
|
@@ -240,57 +260,57 @@ function C(o) {
|
|
|
240
260
|
};
|
|
241
261
|
} catch (e) {
|
|
242
262
|
let t = e instanceof Error ? e.message : "Failed to issue workspace token";
|
|
243
|
-
return console.error("Failed to issue workspace token:", e),
|
|
263
|
+
return console.error("Failed to issue workspace token:", e), z(t), {
|
|
244
264
|
success: !1,
|
|
245
265
|
error: t
|
|
246
266
|
};
|
|
247
267
|
}
|
|
248
|
-
}, [
|
|
249
|
-
let t = e.getState(), n =
|
|
250
|
-
if (!n ||
|
|
251
|
-
t.setLoadingProjects(!0),
|
|
268
|
+
}, [K]), $ = n(async () => {
|
|
269
|
+
let t = e.getState(), n = S(), r = t.workspaceToken, i = t.currentWorkspaceId;
|
|
270
|
+
if (!n || _(n) || !r || !i) return [];
|
|
271
|
+
t.setLoadingProjects(!0), z(null);
|
|
252
272
|
try {
|
|
253
|
-
let e = await
|
|
273
|
+
let e = await c({
|
|
254
274
|
gateway: "workspace",
|
|
255
|
-
query:
|
|
275
|
+
query: m,
|
|
256
276
|
authToken: n,
|
|
257
277
|
workspaceToken: r,
|
|
258
|
-
baseUrl:
|
|
278
|
+
baseUrl: K
|
|
259
279
|
});
|
|
260
280
|
if (e.errors?.length) {
|
|
261
281
|
let t = e.errors[0]?.message ?? "GraphQL error";
|
|
262
|
-
throw
|
|
282
|
+
throw x(e.errors) ? new b(t) : (console.error("Failed to fetch projects:", e.errors), Error(t));
|
|
263
283
|
}
|
|
264
284
|
let i = e.data?.projects?.items ?? [];
|
|
265
285
|
return t.setProjects(i), i;
|
|
266
286
|
} catch (e) {
|
|
267
|
-
if (e instanceof
|
|
287
|
+
if (e instanceof b) return [];
|
|
268
288
|
let t = e instanceof Error ? e.message : "Failed to fetch projects";
|
|
269
|
-
return console.error("Failed to fetch projects:", e),
|
|
289
|
+
return console.error("Failed to fetch projects:", e), z(t), [];
|
|
270
290
|
} finally {
|
|
271
291
|
t.setLoadingProjects(!1);
|
|
272
292
|
}
|
|
273
|
-
}, [
|
|
293
|
+
}, [K]), re = n(async (t) => {
|
|
274
294
|
let n = e.getState();
|
|
275
|
-
return n.setCurrentWorkspaceId(null), n.setWorkspaceToken(null), n.setProjects([]), n.setCurrentProjectId(null), n.setCurrentOrganizationId(t.id), await
|
|
276
|
-
}, [
|
|
295
|
+
return n.setCurrentWorkspaceId(null), n.setWorkspaceToken(null), n.setProjects([]), n.setCurrentProjectId(null), n.setCurrentOrganizationId(t.id), await Z(t.id);
|
|
296
|
+
}, [Z]), ie = n(async (t) => {
|
|
277
297
|
let n = e.getState();
|
|
278
298
|
if (n.setCurrentProjectId(null), n.setProjects([]), !t.organizationId) return console.error("Workspace missing organizationId:", t), {
|
|
279
299
|
success: !1,
|
|
280
300
|
error: "Workspace is missing organizationId"
|
|
281
301
|
};
|
|
282
|
-
let r = await
|
|
302
|
+
let r = await Q(t.organizationId, t.id);
|
|
283
303
|
if (!r.success) return {
|
|
284
304
|
success: !1,
|
|
285
305
|
error: r.error
|
|
286
306
|
};
|
|
287
|
-
let i = await
|
|
307
|
+
let i = await $();
|
|
288
308
|
if (i.length === 0) {
|
|
289
|
-
let t =
|
|
309
|
+
let t = S(), r = e.getState().workspaceToken;
|
|
290
310
|
if (t && r) {
|
|
291
|
-
let e = await
|
|
311
|
+
let e = await g({
|
|
292
312
|
authToken: t,
|
|
293
|
-
workspaceBaseUrl:
|
|
313
|
+
workspaceBaseUrl: K,
|
|
294
314
|
workspaceToken: r
|
|
295
315
|
});
|
|
296
316
|
e && (i = [e], n.setProjects(i));
|
|
@@ -301,54 +321,88 @@ function C(o) {
|
|
|
301
321
|
projects: i
|
|
302
322
|
};
|
|
303
323
|
}, [
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
]),
|
|
324
|
+
Q,
|
|
325
|
+
$,
|
|
326
|
+
K
|
|
327
|
+
]), ae = n((t) => {
|
|
308
328
|
let n = e.getState();
|
|
309
|
-
n.setCurrentProjectId(t.id), n.workspaceToken && !
|
|
329
|
+
n.setCurrentProjectId(t.id), n.workspaceToken && !y(n.workspaceToken, {
|
|
310
330
|
workspaceId: n.currentWorkspaceId,
|
|
311
331
|
organizationId: n.currentOrganizationId,
|
|
312
332
|
projectId: t.id
|
|
313
333
|
}) && n.setWorkspaceToken(null);
|
|
314
334
|
}, []);
|
|
315
|
-
return {
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
335
|
+
return r(() => {
|
|
336
|
+
let t = !1, n = (e) => {
|
|
337
|
+
let n = !1, r = !1, i = () => {
|
|
338
|
+
if (!t) {
|
|
339
|
+
if (n) {
|
|
340
|
+
r = !0;
|
|
341
|
+
return;
|
|
342
|
+
}
|
|
343
|
+
n = !0, e().finally(() => {
|
|
344
|
+
n = !1, !t && r && (r = !1, i());
|
|
345
|
+
});
|
|
346
|
+
}
|
|
347
|
+
};
|
|
348
|
+
return i;
|
|
349
|
+
}, r = n(() => $()), i = n(() => {
|
|
350
|
+
let t = e.getState().currentOrganizationId;
|
|
351
|
+
return t ? Z(t) : Promise.resolve();
|
|
352
|
+
}), a = k.onAny((t) => {
|
|
353
|
+
let n = t.name;
|
|
354
|
+
if (w.has(n)) {
|
|
355
|
+
let n = E(t.payload), { currentWorkspaceId: i } = e.getState();
|
|
356
|
+
if (n && i && n !== i) return;
|
|
357
|
+
r();
|
|
358
|
+
return;
|
|
359
|
+
}
|
|
360
|
+
T.has(n) && i();
|
|
361
|
+
});
|
|
362
|
+
return () => {
|
|
363
|
+
t = !0, a();
|
|
364
|
+
};
|
|
365
|
+
}, [
|
|
366
|
+
k,
|
|
367
|
+
$,
|
|
368
|
+
Z
|
|
369
|
+
]), {
|
|
370
|
+
organizations: A,
|
|
371
|
+
workspaces: N,
|
|
372
|
+
projects: I,
|
|
373
|
+
currentOrganizationId: j,
|
|
374
|
+
currentWorkspaceId: P,
|
|
375
|
+
currentProjectId: L,
|
|
376
|
+
currentOrganization: A.find((e) => e.id === j),
|
|
377
|
+
currentWorkspace: N.find((e) => e.id === P),
|
|
378
|
+
currentProject: I.find((e) => e.id === L),
|
|
379
|
+
workspaceToken: ee,
|
|
380
|
+
isLoadingOrganizations: M,
|
|
381
|
+
isLoadingWorkspaces: F,
|
|
382
|
+
isLoadingProjects: R,
|
|
383
|
+
isLoading: M || F || R,
|
|
384
|
+
error: te,
|
|
385
|
+
fetchOrganizations: ne,
|
|
386
|
+
fetchWorkspacesForOrg: Z,
|
|
387
|
+
issueWorkspaceToken: Q,
|
|
388
|
+
fetchProjects: $,
|
|
389
|
+
selectOrganization: re,
|
|
390
|
+
selectWorkspace: ie,
|
|
391
|
+
selectProject: ae
|
|
338
392
|
};
|
|
339
393
|
}
|
|
340
|
-
function
|
|
341
|
-
let i = e((e) => e.currentOrganizationId), a = e((e) => e.workspaces), o = e((e) => e.accessToken),
|
|
394
|
+
function O(n) {
|
|
395
|
+
let i = e((e) => e.currentOrganizationId), a = e((e) => e.workspaces), o = e((e) => e.accessToken), s = e((e) => e.isLoadingWorkspaces), l = t(), u = n?.globalBaseUrl ?? l.globalBaseUrl, f = n?.disableWorkspaceSync ?? !1;
|
|
342
396
|
r(() => {
|
|
343
|
-
if (f || !i || !o ||
|
|
397
|
+
if (f || !i || !o || s) return;
|
|
344
398
|
let t = a.some((e) => e.organizationId === i);
|
|
345
399
|
if (a.length > 0 && !t) {
|
|
346
400
|
let t = e.getState();
|
|
347
|
-
t.setLoadingWorkspaces(!0),
|
|
401
|
+
t.setLoadingWorkspaces(!0), c({
|
|
348
402
|
gateway: "global",
|
|
349
|
-
query:
|
|
403
|
+
query: d,
|
|
350
404
|
authToken: o,
|
|
351
|
-
baseUrl:
|
|
405
|
+
baseUrl: u
|
|
352
406
|
}).then((e) => {
|
|
353
407
|
if (e.data?.workspaces?.items && (e.data.workspaces.items = e.data.workspaces.items.filter((e) => e.organizationId === i)), !e.errors?.length) {
|
|
354
408
|
let n = (e.data?.workspaces?.items ?? []).filter((e) => e.organizationId === i);
|
|
@@ -362,28 +416,28 @@ function w(n) {
|
|
|
362
416
|
i,
|
|
363
417
|
a,
|
|
364
418
|
o,
|
|
365
|
-
|
|
366
|
-
|
|
419
|
+
s,
|
|
420
|
+
u,
|
|
367
421
|
f
|
|
368
422
|
]);
|
|
369
423
|
}
|
|
370
|
-
function
|
|
371
|
-
let a = e((e) => e.currentWorkspaceId), o = e((e) => e.currentOrganizationId),
|
|
424
|
+
function k(n) {
|
|
425
|
+
let a = e((e) => e.currentWorkspaceId), o = e((e) => e.currentOrganizationId), s = e((e) => e.workspaces), l = e((e) => e.projects), u = e((e) => e.currentProjectId), d = e((e) => e.workspaceToken), f = e((e) => e.accessToken), h = t(), v = n?.workspaceBaseUrl ?? h.workspaceBaseUrl, b = n?.disableProjectSync ?? !1, x = n?.skipProjectFetch ?? !1, S = i(!1), C = i(/* @__PURE__ */ new Map()), w = i(/* @__PURE__ */ new Map()), T = 3e4;
|
|
372
426
|
r(() => {
|
|
373
|
-
if (b || !a || !
|
|
427
|
+
if (b || !a || !f || S.current) return;
|
|
374
428
|
let t = w.current.get(a);
|
|
375
429
|
if (t && t.count >= 8 && Date.now() - t.lastFailureAt < T) return;
|
|
376
430
|
t && Date.now() - t.lastFailureAt >= T && w.current.delete(a);
|
|
377
|
-
let n =
|
|
431
|
+
let n = s.find((e) => e.id === a);
|
|
378
432
|
if (n && o && n.organizationId !== o) return;
|
|
379
433
|
let r = n?.organizationId ?? o;
|
|
380
434
|
if (!r) return;
|
|
381
|
-
let i = e.getState(),
|
|
435
|
+
let i = e.getState(), h = !d || _(d) || !y(d, {
|
|
382
436
|
workspaceId: a,
|
|
383
437
|
organizationId: o,
|
|
384
438
|
projectId: u
|
|
385
439
|
}), E = l.some((e) => e.workspaceId === a);
|
|
386
|
-
if (E && !
|
|
440
|
+
if (E && !h) {
|
|
387
441
|
if (!i.currentProjectId) {
|
|
388
442
|
let e = l.find((e) => e.workspaceId === a);
|
|
389
443
|
e && i.setCurrentProjectId(e.id);
|
|
@@ -395,35 +449,35 @@ function T(n) {
|
|
|
395
449
|
let t = !1;
|
|
396
450
|
try {
|
|
397
451
|
let e = d;
|
|
398
|
-
if (
|
|
399
|
-
let t = await
|
|
452
|
+
if (h) {
|
|
453
|
+
let t = await c({
|
|
400
454
|
gateway: "workspace",
|
|
401
|
-
query:
|
|
455
|
+
query: p,
|
|
402
456
|
variables: { input: {
|
|
403
457
|
organizationId: r,
|
|
404
458
|
workspaceId: a,
|
|
405
459
|
...u ? { projectId: u } : {}
|
|
406
460
|
} },
|
|
407
|
-
authToken:
|
|
408
|
-
baseUrl:
|
|
461
|
+
authToken: f,
|
|
462
|
+
baseUrl: v
|
|
409
463
|
});
|
|
410
464
|
if (t.data?.issueWorkspaceToken?.success && t.data.issueWorkspaceToken.token) e = t.data.issueWorkspaceToken.token, i.setWorkspaceToken(e);
|
|
411
465
|
else return;
|
|
412
466
|
}
|
|
413
467
|
if (e && !E && !x) {
|
|
414
|
-
let t = await
|
|
468
|
+
let t = await c({
|
|
415
469
|
gateway: "workspace",
|
|
416
|
-
query:
|
|
417
|
-
authToken:
|
|
470
|
+
query: m,
|
|
471
|
+
authToken: f,
|
|
418
472
|
workspaceToken: e,
|
|
419
|
-
baseUrl:
|
|
473
|
+
baseUrl: v
|
|
420
474
|
});
|
|
421
475
|
if (t.errors?.length) return;
|
|
422
476
|
let n = t.data?.projects?.items ?? [];
|
|
423
477
|
if (n.length === 0) {
|
|
424
|
-
let t = await
|
|
425
|
-
authToken:
|
|
426
|
-
workspaceBaseUrl:
|
|
478
|
+
let t = await g({
|
|
479
|
+
authToken: f,
|
|
480
|
+
workspaceBaseUrl: v,
|
|
427
481
|
workspaceToken: e
|
|
428
482
|
});
|
|
429
483
|
if (t) n = [t];
|
|
@@ -461,12 +515,12 @@ function T(n) {
|
|
|
461
515
|
}, [
|
|
462
516
|
a,
|
|
463
517
|
o,
|
|
464
|
-
|
|
518
|
+
s,
|
|
465
519
|
l,
|
|
466
520
|
u,
|
|
467
521
|
d,
|
|
468
|
-
|
|
469
|
-
|
|
522
|
+
f,
|
|
523
|
+
v,
|
|
470
524
|
b,
|
|
471
525
|
x
|
|
472
526
|
]), r(() => {
|
|
@@ -477,6 +531,6 @@ function T(n) {
|
|
|
477
531
|
}, []);
|
|
478
532
|
}
|
|
479
533
|
//#endregion
|
|
480
|
-
export {
|
|
534
|
+
export { D as useContextSwitcherData, k as useProjectSyncEffect, O as useWorkspaceSyncEffect };
|
|
481
535
|
|
|
482
536
|
//# sourceMappingURL=useContextSwitcherData.js.map
|