@burdenoff/microfe-auth 2026.1023.2 → 2026.1031.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.
|
@@ -9,8 +9,12 @@ import { clearWorkspaceWideSelection as p, isWorkspaceWideSelection as m, select
|
|
|
9
9
|
import { getUrlParam as g } from "@burdenoff/fe-libs/shared/providers/shell/ActiveContextStorage";
|
|
10
10
|
import { useActiveContext as _ } from "@burdenoff/fe-libs/shared/providers/shell/ActiveContextProvider";
|
|
11
11
|
//#region src/auth/hooks/useContextSwitcherData.ts
|
|
12
|
-
var v = "\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", y = "\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", b = "\n query MyWorkspacesPage($limit: Int, $offset: Int) {\n workspaces: myWorkspaces(limit: $limit, offset: $offset) {\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", x =
|
|
13
|
-
function
|
|
12
|
+
var v = "\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", y = "\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", b = "\n query MyWorkspacesPage($limit: Int, $offset: Int) {\n workspaces: myWorkspaces(limit: $limit, offset: $offset) {\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", x = new Set(["NOT_PROJECT_MEMBER", "PROJECT_NOT_FOUND"]);
|
|
13
|
+
function S(e) {
|
|
14
|
+
return !!e && x.has(e);
|
|
15
|
+
}
|
|
16
|
+
var C = 100, w = 20, ee = "\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", te = "\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";
|
|
17
|
+
function T(e, t = 3e4) {
|
|
14
18
|
try {
|
|
15
19
|
let n = JSON.parse(atob(e.split(".")[1]));
|
|
16
20
|
return n.exp ? n.exp * 1e3 < Date.now() + t : !1;
|
|
@@ -18,7 +22,7 @@ function C(e, t = 3e4) {
|
|
|
18
22
|
return !0;
|
|
19
23
|
}
|
|
20
24
|
}
|
|
21
|
-
function
|
|
25
|
+
function E(e) {
|
|
22
26
|
try {
|
|
23
27
|
let t = JSON.parse(atob(e.split(".")[1]));
|
|
24
28
|
return {
|
|
@@ -31,33 +35,33 @@ function w(e) {
|
|
|
31
35
|
return null;
|
|
32
36
|
}
|
|
33
37
|
}
|
|
34
|
-
function
|
|
35
|
-
if (!e ||
|
|
36
|
-
let n =
|
|
38
|
+
function D(e, t) {
|
|
39
|
+
if (!e || T(e)) return !1;
|
|
40
|
+
let n = E(e);
|
|
37
41
|
return !(!n || t.workspaceId && n.workspaceId !== t.workspaceId || t.organizationId && n.organizationId !== t.organizationId || t.workspaceWide && n.projectId || t.projectId && n.projectId !== t.projectId);
|
|
38
42
|
}
|
|
39
|
-
var
|
|
43
|
+
var O = class extends Error {
|
|
40
44
|
constructor(e) {
|
|
41
45
|
super(e), this.name = "AuthError";
|
|
42
46
|
}
|
|
43
47
|
};
|
|
44
|
-
function
|
|
48
|
+
function k(e) {
|
|
45
49
|
return e.some((e) => e.extensions?.code === "UNAUTHENTICATED" || e.message?.toLowerCase().includes("unauthorized") || e.message?.toLowerCase().includes("not authenticated"));
|
|
46
50
|
}
|
|
47
|
-
function
|
|
51
|
+
function A() {
|
|
48
52
|
let t = e.getState().accessToken;
|
|
49
|
-
if (t && !
|
|
53
|
+
if (t && !T(t)) return t;
|
|
50
54
|
let n = d();
|
|
51
|
-
return n && !
|
|
55
|
+
return n && !T(n) ? n : t;
|
|
52
56
|
}
|
|
53
|
-
async function
|
|
57
|
+
async function j(e, t, n) {
|
|
54
58
|
let r = [...e.items], i = e.total;
|
|
55
|
-
for (let e = 1; e <
|
|
59
|
+
for (let e = 1; e < w && r.length < i; e += 1) {
|
|
56
60
|
let e = await f({
|
|
57
61
|
gateway: "global",
|
|
58
62
|
query: b,
|
|
59
63
|
variables: {
|
|
60
|
-
limit:
|
|
64
|
+
limit: C,
|
|
61
65
|
offset: r.length
|
|
62
66
|
},
|
|
63
67
|
authToken: t,
|
|
@@ -74,7 +78,7 @@ async function k(e, t, n) {
|
|
|
74
78
|
items: r
|
|
75
79
|
};
|
|
76
80
|
}
|
|
77
|
-
function
|
|
81
|
+
function M(e) {
|
|
78
82
|
return Array.from(new Set(e.flatMap((e) => e.organizationId ? [e.organizationId] : []))).map((t, n) => ({
|
|
79
83
|
id: t,
|
|
80
84
|
name: e.find((e) => e.organizationId === t)?.name || `Organization ${n + 1}`,
|
|
@@ -82,36 +86,36 @@ function A(e) {
|
|
|
82
86
|
tenantId: e.find((e) => e.organizationId === t)?.tenantId || ""
|
|
83
87
|
}));
|
|
84
88
|
}
|
|
85
|
-
var
|
|
89
|
+
var N = new Set([
|
|
86
90
|
"project.created",
|
|
87
91
|
"project.updated",
|
|
88
92
|
"project.deleted",
|
|
89
93
|
"project.archived",
|
|
90
94
|
"project.unarchived"
|
|
91
|
-
]),
|
|
95
|
+
]), P = new Set([
|
|
92
96
|
"workspace.created",
|
|
93
97
|
"workspace.updated",
|
|
94
98
|
"workspace.deleted",
|
|
95
99
|
"workspace.archived",
|
|
96
100
|
"workspace.reactivated"
|
|
97
101
|
]);
|
|
98
|
-
function
|
|
102
|
+
function F(e) {
|
|
99
103
|
if (e && typeof e == "object" && "workspaceId" in e) {
|
|
100
104
|
let t = e.workspaceId;
|
|
101
105
|
return typeof t == "string" ? t : void 0;
|
|
102
106
|
}
|
|
103
107
|
}
|
|
104
|
-
function
|
|
105
|
-
let { organizationId: b, workspaceId: x, projectId: S, tenantId: C, setContext: w } = _(),
|
|
108
|
+
function I(d) {
|
|
109
|
+
let { organizationId: b, workspaceId: x, projectId: S, tenantId: C, setContext: w } = _(), T = u(), E = e((e) => e.organizations), I = e((e) => e.currentOrganizationId), L = e((e) => e.isLoadingOrganizations), R = e((e) => e.workspaces), ne = e((e) => e.currentWorkspaceId), re = e((e) => e.workspaceToken), ie = e((e) => e.isLoadingWorkspaces), ae = e((e) => e.projects), z = e((e) => e.currentProjectId), B = e((e) => e.isLoadingProjects);
|
|
106
110
|
o(() => {
|
|
107
|
-
let e =
|
|
111
|
+
let e = R.find((e) => e.id === x && e.organizationId === b), t = E.find((e) => e.id === b);
|
|
108
112
|
!e || !t || !/^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$/i.test(e.tenantId) || e.tenantId !== t.tenantId || C === e.tenantId || w({ tenantId: e.tenantId });
|
|
109
113
|
}, [
|
|
110
114
|
b,
|
|
111
115
|
x,
|
|
112
116
|
C,
|
|
113
|
-
|
|
114
|
-
|
|
117
|
+
E,
|
|
118
|
+
R,
|
|
115
119
|
w
|
|
116
120
|
]);
|
|
117
121
|
let [oe, V] = c(null), [se, H] = c(0), U = s(0), W = s(null), G = s(/* @__PURE__ */ new Map()), K = s(x), q = s(b);
|
|
@@ -124,7 +128,7 @@ function P(d) {
|
|
|
124
128
|
if (b && b !== t.currentOrganizationId && b !== le.current && (le.current = b, t.setCurrentOrganizationId(b), t.workspaces.length > 0 && !t.workspaces.some((e) => e.organizationId === b) && t.setWorkspaces([])), x && x !== t.currentWorkspaceId && x !== ue.current && (ue.current = x, t.setCurrentWorkspaceId(x), t.projects.length > 0 && !t.projects.some((e) => e.workspaceId === x) && (t.setProjects([]), t.setCurrentProjectId(null))), m({
|
|
125
129
|
organizationId: b,
|
|
126
130
|
workspaceId: x
|
|
127
|
-
}) && !S && t.currentProjectId && (t.setCurrentProjectId(null), t.setWorkspaceToken(null)), S && S !== t.currentProjectId && S !== de.current && (de.current = S, t.setCurrentProjectId(S)), t.workspaceToken && !
|
|
131
|
+
}) && !S && t.currentProjectId && (t.setCurrentProjectId(null), t.setWorkspaceToken(null)), S && S !== t.currentProjectId && S !== de.current && (de.current = S, t.setCurrentProjectId(S)), t.workspaceToken && !D(t.workspaceToken, {
|
|
128
132
|
workspaceId: x,
|
|
129
133
|
organizationId: b,
|
|
130
134
|
projectId: S,
|
|
@@ -143,7 +147,7 @@ function P(d) {
|
|
|
143
147
|
]);
|
|
144
148
|
let X = a(async () => {
|
|
145
149
|
if (W.current) return W.current;
|
|
146
|
-
let t = e.getState(), a =
|
|
150
|
+
let t = e.getState(), a = A();
|
|
147
151
|
return a ? (t.setLoadingOrganizations(!0), V(null), W.current = (async () => {
|
|
148
152
|
try {
|
|
149
153
|
let o = q.current ?? t.currentOrganizationId, s = K.current, c = !!s && g("workspace") === s, l = !!o && g("org") === o, u = o || s ? await (async () => {
|
|
@@ -178,7 +182,7 @@ function P(d) {
|
|
|
178
182
|
baseUrl: J
|
|
179
183
|
})), u.errors?.length) {
|
|
180
184
|
let e = u.errors[0]?.message ?? "GraphQL error";
|
|
181
|
-
throw
|
|
185
|
+
throw k(u.errors) ? new O(e) : (t.workspaces.length === 0 && console.error("Failed to fetch organizations:", u.errors), Error(e));
|
|
182
186
|
}
|
|
183
187
|
let d = u.data?.myOrganizations?.items ?? [];
|
|
184
188
|
if (o && d.length === 0 && t.workspaces.length === 0) {
|
|
@@ -198,13 +202,13 @@ function P(d) {
|
|
|
198
202
|
else {
|
|
199
203
|
console.warn("[ContextSwitcher] Stale-context recovery failed:", e.errors);
|
|
200
204
|
let t = e.errors?.[0]?.message ?? "Failed to fetch organizations";
|
|
201
|
-
throw
|
|
205
|
+
throw k(e.errors ?? []) ? new O(t) : Error(t);
|
|
202
206
|
}
|
|
203
207
|
}
|
|
204
|
-
let p = d.length === 0 && t.workspaces.length > 0 ?
|
|
208
|
+
let p = d.length === 0 && t.workspaces.length > 0 ? M(t.workspaces) : [], m = p.length > 0 ? p : d;
|
|
205
209
|
t.setOrganizations(m);
|
|
206
210
|
let h = o, _ = u.data?.workspaces ?? null;
|
|
207
|
-
c && _ && !_.items.some((e) => e.id === s) && !i(_) && (_ = await
|
|
211
|
+
c && _ && !_.items.some((e) => e.id === s) && !i(_) && (_ = await j(_, a, J));
|
|
208
212
|
let b = r({
|
|
209
213
|
requestedWorkspaceId: s,
|
|
210
214
|
fromUrl: c,
|
|
@@ -266,10 +270,10 @@ function P(d) {
|
|
|
266
270
|
}
|
|
267
271
|
return U.current = 0, m;
|
|
268
272
|
} catch (e) {
|
|
269
|
-
if (e instanceof
|
|
273
|
+
if (e instanceof O) return [];
|
|
270
274
|
let n = e instanceof Error ? e.message : "Failed to fetch organizations";
|
|
271
275
|
if (t.workspaces.length === 0 && console.error("Failed to fetch organizations:", e), V(n), H((e) => e + 1), t.workspaces.length > 0) {
|
|
272
|
-
let e =
|
|
276
|
+
let e = M(t.workspaces);
|
|
273
277
|
if (e.length > 0) return t.setOrganizations(e), t.currentOrganizationId || t.setCurrentOrganizationId(e[0].id), e;
|
|
274
278
|
}
|
|
275
279
|
return [];
|
|
@@ -279,7 +283,7 @@ function P(d) {
|
|
|
279
283
|
})(), W.current) : [];
|
|
280
284
|
}, [J, w]);
|
|
281
285
|
o(() => {
|
|
282
|
-
if (se === 0 || U.current >= 5 || !
|
|
286
|
+
if (se === 0 || U.current >= 5 || !A()) return;
|
|
283
287
|
U.current += 1;
|
|
284
288
|
let e = Math.min(1500 * 2 ** (U.current - 1), 12e3), t = window.setTimeout(() => {
|
|
285
289
|
X();
|
|
@@ -289,14 +293,14 @@ function P(d) {
|
|
|
289
293
|
};
|
|
290
294
|
}, [se, X]), o(() => {
|
|
291
295
|
let t = () => {
|
|
292
|
-
e.getState().organizations.length === 0 &&
|
|
296
|
+
e.getState().organizations.length === 0 && A() && (U.current = 0, X());
|
|
293
297
|
};
|
|
294
298
|
return window.addEventListener("online", t), () => {
|
|
295
299
|
window.removeEventListener("online", t);
|
|
296
300
|
};
|
|
297
301
|
}, [X]);
|
|
298
302
|
let Z = a(async (t) => {
|
|
299
|
-
let n = e.getState(), r =
|
|
303
|
+
let n = e.getState(), r = A(), i = l(), a = n.user?.id, o = JSON.stringify([
|
|
300
304
|
i,
|
|
301
305
|
a,
|
|
302
306
|
r,
|
|
@@ -305,7 +309,7 @@ function P(d) {
|
|
|
305
309
|
if (s) return s;
|
|
306
310
|
let c = () => {
|
|
307
311
|
let n = e.getState();
|
|
308
|
-
return l() === i && n.user?.id === a &&
|
|
312
|
+
return l() === i && n.user?.id === a && A() === r && n.currentOrganizationId === t;
|
|
309
313
|
};
|
|
310
314
|
if (!r) return [];
|
|
311
315
|
n.setLoadingWorkspaces(!0), V(null);
|
|
@@ -320,12 +324,12 @@ function P(d) {
|
|
|
320
324
|
if (!c()) return [];
|
|
321
325
|
if (e.data?.workspaces?.items && (e.data.workspaces.items = e.data.workspaces.items.filter((e) => e.organizationId === t)), e.errors?.length) {
|
|
322
326
|
let t = e.errors[0]?.message ?? "GraphQL error";
|
|
323
|
-
throw
|
|
327
|
+
throw k(e.errors) ? new O(t) : (console.error("Failed to fetch workspaces:", e.errors), Error(t));
|
|
324
328
|
}
|
|
325
329
|
let i = (e.data?.workspaces?.items ?? []).filter((e) => e.organizationId === t);
|
|
326
330
|
return n.setWorkspaces(i), i;
|
|
327
331
|
} catch (e) {
|
|
328
|
-
if (!c() || e instanceof
|
|
332
|
+
if (!c() || e instanceof O) return [];
|
|
329
333
|
let t = e instanceof Error ? e.message : "Failed to fetch workspaces";
|
|
330
334
|
return console.error("Failed to fetch workspaces:", e), V(t), [];
|
|
331
335
|
} finally {
|
|
@@ -341,7 +345,7 @@ function P(d) {
|
|
|
341
345
|
], s = m({
|
|
342
346
|
organizationId: t,
|
|
343
347
|
workspaceId: n ?? null
|
|
344
|
-
}), c =
|
|
348
|
+
}), c = A(), u = l(), d = a.user?.id;
|
|
345
349
|
if (!c) return {
|
|
346
350
|
success: !1,
|
|
347
351
|
error: "No valid access token available"
|
|
@@ -362,7 +366,7 @@ function P(d) {
|
|
|
362
366
|
});
|
|
363
367
|
if (p.errors?.length) {
|
|
364
368
|
let e = p.errors[0]?.message ?? "GraphQL error";
|
|
365
|
-
return
|
|
369
|
+
return k(p.errors) || console.error("Failed to issue workspace token:", p.errors), {
|
|
366
370
|
success: !1,
|
|
367
371
|
error: e
|
|
368
372
|
};
|
|
@@ -370,14 +374,14 @@ function P(d) {
|
|
|
370
374
|
let h = p.data?.issueWorkspaceToken;
|
|
371
375
|
if (h?.success && h.token) {
|
|
372
376
|
let i = e.getState();
|
|
373
|
-
if (l() !== u || e.getState().user?.id !== d ||
|
|
377
|
+
if (l() !== u || e.getState().user?.id !== d || A() !== c || o.some((e, t) => e !== [
|
|
374
378
|
i.currentOrganizationId,
|
|
375
379
|
i.currentWorkspaceId,
|
|
376
380
|
i.currentProjectId
|
|
377
381
|
][t]) || m({
|
|
378
382
|
organizationId: t,
|
|
379
383
|
workspaceId: n ?? null
|
|
380
|
-
}) !== s || !
|
|
384
|
+
}) !== s || !D(h.token, {
|
|
381
385
|
organizationId: t,
|
|
382
386
|
workspaceId: n,
|
|
383
387
|
projectId: r,
|
|
@@ -405,12 +409,12 @@ function P(d) {
|
|
|
405
409
|
};
|
|
406
410
|
}
|
|
407
411
|
}, [Y]), $ = a(async () => {
|
|
408
|
-
let t = e.getState(), n =
|
|
412
|
+
let t = e.getState(), n = A(), r = t.workspaceToken, i = t.currentWorkspaceId, a = l(), o = t.user?.id, s = t.currentOrganizationId, c = t.currentProjectId, u = m({
|
|
409
413
|
organizationId: s,
|
|
410
414
|
workspaceId: i
|
|
411
415
|
}), d = () => {
|
|
412
416
|
let t = e.getState();
|
|
413
|
-
return l() === a && t.user?.id === o &&
|
|
417
|
+
return l() === a && t.user?.id === o && A() === n && t.workspaceToken === r && t.currentOrganizationId === s && t.currentWorkspaceId === i && t.currentProjectId === c && m({
|
|
414
418
|
organizationId: s,
|
|
415
419
|
workspaceId: i
|
|
416
420
|
}) === u;
|
|
@@ -428,12 +432,12 @@ function P(d) {
|
|
|
428
432
|
if (!d()) return [];
|
|
429
433
|
if (e.errors?.length) {
|
|
430
434
|
let t = e.errors[0]?.message ?? "GraphQL error";
|
|
431
|
-
throw
|
|
435
|
+
throw k(e.errors) ? new O(t) : (console.error("Failed to fetch projects:", e.errors), Error(t));
|
|
432
436
|
}
|
|
433
437
|
let i = e.data?.projects?.items ?? [];
|
|
434
438
|
return t.setProjects(i), i;
|
|
435
439
|
} catch (e) {
|
|
436
|
-
if (e instanceof
|
|
440
|
+
if (e instanceof O) return [];
|
|
437
441
|
let t = e instanceof Error ? e.message : "Failed to fetch projects";
|
|
438
442
|
return console.error("Failed to fetch projects:", e), V(t), [];
|
|
439
443
|
} finally {
|
|
@@ -453,12 +457,12 @@ function P(d) {
|
|
|
453
457
|
success: !1,
|
|
454
458
|
error: r.error
|
|
455
459
|
};
|
|
456
|
-
let i = e.getState(), a = l(), o = i.user?.id, s =
|
|
460
|
+
let i = e.getState(), a = l(), o = i.user?.id, s = A(), c = i.workspaceToken, u = i.currentProjectId, d = m({
|
|
457
461
|
organizationId: t.organizationId,
|
|
458
462
|
workspaceId: t.id
|
|
459
463
|
}), f = () => {
|
|
460
464
|
let n = e.getState();
|
|
461
|
-
return l() === a && n.user?.id === o &&
|
|
465
|
+
return l() === a && n.user?.id === o && A() === s && n.workspaceToken === c && n.currentOrganizationId === t.organizationId && n.currentWorkspaceId === t.id && n.currentProjectId === u && m({
|
|
462
466
|
organizationId: t.organizationId,
|
|
463
467
|
workspaceId: t.id
|
|
464
468
|
}) === d;
|
|
@@ -478,7 +482,7 @@ function P(d) {
|
|
|
478
482
|
p({
|
|
479
483
|
organizationId: n.currentOrganizationId,
|
|
480
484
|
workspaceId: n.currentWorkspaceId
|
|
481
|
-
}), n.setCurrentProjectId(t.id), n.workspaceToken && !
|
|
485
|
+
}), n.setCurrentProjectId(t.id), n.workspaceToken && !D(n.workspaceToken, {
|
|
482
486
|
workspaceId: n.currentWorkspaceId,
|
|
483
487
|
organizationId: n.currentOrganizationId,
|
|
484
488
|
projectId: t.id
|
|
@@ -509,38 +513,38 @@ function P(d) {
|
|
|
509
513
|
}, r = n(() => $()), i = n(() => {
|
|
510
514
|
let t = e.getState().currentOrganizationId;
|
|
511
515
|
return t ? Z(t) : Promise.resolve();
|
|
512
|
-
}), a =
|
|
516
|
+
}), a = T.onAny((t) => {
|
|
513
517
|
let n = t.name;
|
|
514
|
-
if (
|
|
515
|
-
let n =
|
|
518
|
+
if (N.has(n)) {
|
|
519
|
+
let n = F(t.payload), { currentWorkspaceId: i } = e.getState();
|
|
516
520
|
if (n && i && n !== i) return;
|
|
517
521
|
r();
|
|
518
522
|
return;
|
|
519
523
|
}
|
|
520
|
-
|
|
524
|
+
P.has(n) && i();
|
|
521
525
|
});
|
|
522
526
|
return () => {
|
|
523
527
|
t = !0, a();
|
|
524
528
|
};
|
|
525
529
|
}, [
|
|
526
|
-
|
|
530
|
+
T,
|
|
527
531
|
$,
|
|
528
532
|
Z
|
|
529
533
|
]), {
|
|
530
|
-
organizations:
|
|
531
|
-
workspaces:
|
|
532
|
-
projects:
|
|
534
|
+
organizations: E,
|
|
535
|
+
workspaces: R,
|
|
536
|
+
projects: ae,
|
|
533
537
|
currentOrganizationId: I,
|
|
534
|
-
currentWorkspaceId:
|
|
535
|
-
currentProjectId:
|
|
536
|
-
currentOrganization:
|
|
537
|
-
currentWorkspace:
|
|
538
|
-
currentProject:
|
|
538
|
+
currentWorkspaceId: ne,
|
|
539
|
+
currentProjectId: z,
|
|
540
|
+
currentOrganization: E.find((e) => e.id === I),
|
|
541
|
+
currentWorkspace: R.find((e) => e.id === ne),
|
|
542
|
+
currentProject: ae.find((e) => e.id === z),
|
|
539
543
|
workspaceToken: re,
|
|
540
|
-
isLoadingOrganizations:
|
|
541
|
-
isLoadingWorkspaces:
|
|
542
|
-
isLoadingProjects:
|
|
543
|
-
isLoading:
|
|
544
|
+
isLoadingOrganizations: L,
|
|
545
|
+
isLoadingWorkspaces: ie,
|
|
546
|
+
isLoadingProjects: B,
|
|
547
|
+
isLoading: L || ie || B,
|
|
544
548
|
error: oe,
|
|
545
549
|
fetchOrganizations: X,
|
|
546
550
|
fetchWorkspacesForOrg: Z,
|
|
@@ -552,7 +556,7 @@ function P(d) {
|
|
|
552
556
|
selectWorkspaceWide: ge
|
|
553
557
|
};
|
|
554
558
|
}
|
|
555
|
-
function
|
|
559
|
+
function L(n) {
|
|
556
560
|
let r = e((e) => e.currentOrganizationId), i = e((e) => e.workspaces), a = e((e) => e.accessToken), s = e((e) => e.isLoadingWorkspaces), c = t(), l = n?.globalBaseUrl ?? c.globalBaseUrl, u = n?.disableWorkspaceSync ?? !1;
|
|
557
561
|
o(() => {
|
|
558
562
|
if (u || !r || !a || s) return;
|
|
@@ -582,13 +586,13 @@ function F(n) {
|
|
|
582
586
|
u
|
|
583
587
|
]);
|
|
584
588
|
}
|
|
585
|
-
function
|
|
586
|
-
let r = e((e) => e.currentWorkspaceId), i = e((e) => e.currentOrganizationId), a = e((e) => e.workspaces), u = e((e) => e.projects), d = e((e) => e.currentProjectId), h = e((e) => e.workspaceToken),
|
|
589
|
+
function R(n) {
|
|
590
|
+
let r = e((e) => e.currentWorkspaceId), i = e((e) => e.currentOrganizationId), a = e((e) => e.workspaces), u = e((e) => e.projects), d = e((e) => e.currentProjectId), h = e((e) => e.workspaceToken), v = e((e) => e.accessToken), { setContext: y } = _(), b = t(), x = n?.workspaceBaseUrl ?? b.workspaceBaseUrl, C = n?.disableProjectSync ?? !1, w = n?.skipProjectFetch ?? !1, E = s(!1), [O, k] = c(0), A = s(null), j = s(/* @__PURE__ */ new Map()), M = s(/* @__PURE__ */ new Map()), N = 3e4;
|
|
587
591
|
o(() => {
|
|
588
|
-
if (
|
|
589
|
-
let t =
|
|
590
|
-
if (t && t.count >= 8 && Date.now() - t.lastFailureAt <
|
|
591
|
-
t && Date.now() - t.lastFailureAt >=
|
|
592
|
+
if (C || !r || !v || E.current) return;
|
|
593
|
+
let t = M.current.get(r);
|
|
594
|
+
if (t && t.count >= 8 && Date.now() - t.lastFailureAt < N) return;
|
|
595
|
+
t && Date.now() - t.lastFailureAt >= N && M.current.delete(r);
|
|
592
596
|
let n = a.find((e) => e.id === r);
|
|
593
597
|
if (n && i && n.organizationId !== i) return;
|
|
594
598
|
let o = n?.organizationId ?? i;
|
|
@@ -598,45 +602,45 @@ function I(n) {
|
|
|
598
602
|
organizationId: o,
|
|
599
603
|
workspaceId: r
|
|
600
604
|
});
|
|
601
|
-
let c = l(),
|
|
605
|
+
let c = l(), _ = s.user?.id, b = m({
|
|
602
606
|
organizationId: o,
|
|
603
607
|
workspaceId: r
|
|
604
608
|
});
|
|
605
|
-
if (
|
|
609
|
+
if (b && s.currentProjectId) {
|
|
606
610
|
s.setCurrentProjectId(null), s.setWorkspaceToken(null);
|
|
607
611
|
return;
|
|
608
612
|
}
|
|
609
|
-
let
|
|
613
|
+
let O = !h || T(h) || !D(h, {
|
|
610
614
|
workspaceId: r,
|
|
611
615
|
organizationId: i,
|
|
612
616
|
projectId: d,
|
|
613
|
-
workspaceWide:
|
|
614
|
-
}),
|
|
617
|
+
workspaceWide: b
|
|
618
|
+
}), P = JSON.stringify([
|
|
615
619
|
c,
|
|
616
|
-
v,
|
|
617
620
|
_,
|
|
621
|
+
v,
|
|
618
622
|
o,
|
|
619
623
|
r
|
|
620
|
-
]),
|
|
621
|
-
if (
|
|
622
|
-
if (!s.currentProjectId && !
|
|
624
|
+
]), F = u.some((e) => e.workspaceId === r) || A.current?.scopeKey === P && A.current.projects === u;
|
|
625
|
+
if (F && !O) {
|
|
626
|
+
if (!s.currentProjectId && !b) {
|
|
623
627
|
let e = u.find((e) => e.workspaceId === r);
|
|
624
628
|
e && s.setCurrentProjectId(e.id);
|
|
625
629
|
}
|
|
626
630
|
return;
|
|
627
631
|
}
|
|
628
|
-
let
|
|
632
|
+
let I = () => {
|
|
629
633
|
let t = e.getState();
|
|
630
|
-
return t.accessToken ===
|
|
634
|
+
return t.accessToken === v && t.user?.id === _ && l() === c && t.currentOrganizationId === o && t.currentWorkspaceId === r && t.currentProjectId === d && m({
|
|
631
635
|
organizationId: o,
|
|
632
636
|
workspaceId: r
|
|
633
|
-
}) ===
|
|
634
|
-
},
|
|
635
|
-
|
|
637
|
+
}) === b;
|
|
638
|
+
}, L = async () => {
|
|
639
|
+
E.current = !0, s.setLoadingProjects(!0);
|
|
636
640
|
let t = !1;
|
|
637
641
|
try {
|
|
638
642
|
let n = h;
|
|
639
|
-
if (
|
|
643
|
+
if (O) {
|
|
640
644
|
let e = await f({
|
|
641
645
|
gateway: "workspace",
|
|
642
646
|
query: ee,
|
|
@@ -645,32 +649,35 @@ function I(n) {
|
|
|
645
649
|
workspaceId: r,
|
|
646
650
|
...d ? { projectId: d } : {}
|
|
647
651
|
} },
|
|
648
|
-
authToken:
|
|
649
|
-
baseUrl:
|
|
652
|
+
authToken: v,
|
|
653
|
+
baseUrl: x,
|
|
650
654
|
tenantId: a.find((e) => e.id === r)?.tenantId
|
|
651
655
|
});
|
|
652
656
|
if (e.data?.issueWorkspaceToken?.success && e.data.issueWorkspaceToken.token) {
|
|
653
|
-
if (n = e.data.issueWorkspaceToken.token, !
|
|
657
|
+
if (n = e.data.issueWorkspaceToken.token, !I() || !D(n, {
|
|
654
658
|
workspaceId: r,
|
|
655
659
|
organizationId: o,
|
|
656
660
|
projectId: d,
|
|
657
|
-
workspaceWide:
|
|
661
|
+
workspaceWide: b
|
|
658
662
|
})) return;
|
|
659
663
|
s.setWorkspaceToken(n);
|
|
660
|
-
} else
|
|
664
|
+
} else {
|
|
665
|
+
d && I() && S(e.data?.issueWorkspaceToken?.error?.code) && (s.setCurrentProjectId(null), s.setWorkspaceToken(null), y({ projectId: null }));
|
|
666
|
+
return;
|
|
667
|
+
}
|
|
661
668
|
}
|
|
662
|
-
if (n && !
|
|
669
|
+
if (n && !F && !w) {
|
|
663
670
|
let t = await f({
|
|
664
671
|
gateway: "workspace",
|
|
665
672
|
query: te,
|
|
666
|
-
authToken:
|
|
673
|
+
authToken: v,
|
|
667
674
|
workspaceToken: n,
|
|
668
|
-
baseUrl:
|
|
675
|
+
baseUrl: x
|
|
669
676
|
});
|
|
670
|
-
if (!
|
|
677
|
+
if (!I() || t.errors?.length) return;
|
|
671
678
|
let i = t.data?.projects?.items ?? [];
|
|
672
|
-
|
|
673
|
-
scopeKey:
|
|
679
|
+
A.current = i.length === 0 ? {
|
|
680
|
+
scopeKey: P,
|
|
674
681
|
projects: i
|
|
675
682
|
} : null, s.setProjects(i), d && !i.some((e) => e.id === d) && (s.setCurrentProjectId(null), s.setWorkspaceToken(null)), i.length > 0 && !e.getState().currentProjectId && !m({
|
|
676
683
|
organizationId: o,
|
|
@@ -679,53 +686,54 @@ function I(n) {
|
|
|
679
686
|
}
|
|
680
687
|
t = !0;
|
|
681
688
|
} catch {} finally {
|
|
682
|
-
s.setLoadingProjects(!1),
|
|
683
|
-
let n =
|
|
684
|
-
n ||
|
|
685
|
-
let i =
|
|
689
|
+
s.setLoadingProjects(!1), E.current = !1;
|
|
690
|
+
let n = I();
|
|
691
|
+
n || k((e) => e + 1);
|
|
692
|
+
let i = M.current;
|
|
686
693
|
if (n && t) {
|
|
687
694
|
i.delete(r);
|
|
688
|
-
let e =
|
|
689
|
-
e && (clearTimeout(e),
|
|
695
|
+
let e = j.current.get(r);
|
|
696
|
+
e && (clearTimeout(e), j.current.delete(r));
|
|
690
697
|
} else if (n) {
|
|
691
698
|
let t = (i.get(r)?.count ?? 0) + 1;
|
|
692
699
|
if (i.set(r, {
|
|
693
700
|
count: t,
|
|
694
701
|
lastFailureAt: Date.now()
|
|
695
702
|
}), t < 8) {
|
|
696
|
-
let n =
|
|
703
|
+
let n = j.current.get(r);
|
|
697
704
|
n && clearTimeout(n);
|
|
698
705
|
let i = Math.min(1e3 * 2 ** (t - 1), 8e3), a = setTimeout(() => {
|
|
699
|
-
|
|
706
|
+
j.current.delete(r);
|
|
700
707
|
let t = e.getState();
|
|
701
|
-
|
|
708
|
+
I() && t.currentWorkspaceId === r && !t.projects.some((e) => e.workspaceId === r) && !E.current && L();
|
|
702
709
|
}, i);
|
|
703
|
-
|
|
710
|
+
j.current.set(r, a);
|
|
704
711
|
}
|
|
705
712
|
}
|
|
706
713
|
}
|
|
707
714
|
};
|
|
708
|
-
|
|
715
|
+
L();
|
|
709
716
|
}, [
|
|
710
|
-
|
|
717
|
+
O,
|
|
711
718
|
r,
|
|
712
719
|
i,
|
|
713
720
|
a,
|
|
714
721
|
u,
|
|
715
722
|
d,
|
|
716
723
|
h,
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
724
|
+
v,
|
|
725
|
+
x,
|
|
726
|
+
C,
|
|
727
|
+
w,
|
|
728
|
+
y
|
|
721
729
|
]), o(() => {
|
|
722
|
-
let e =
|
|
730
|
+
let e = j.current;
|
|
723
731
|
return () => {
|
|
724
732
|
e.forEach((e) => clearTimeout(e)), e.clear();
|
|
725
733
|
};
|
|
726
734
|
}, []);
|
|
727
735
|
}
|
|
728
736
|
//#endregion
|
|
729
|
-
export {
|
|
737
|
+
export { I as useContextSwitcherData, R as useProjectSyncEffect, L as useWorkspaceSyncEffect };
|
|
730
738
|
|
|
731
739
|
//# sourceMappingURL=useContextSwitcherData.js.map
|