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