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