@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.
@@ -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 { useCallback as n, useEffect as r, useRef as i, useState as a } from "react";
4
- import { resolveActiveProfileId as o } from "@burdenoff/fe-libs/shared/providers/shell/ProfileStorageManager";
5
- import { useEventBus as s } from "@burdenoff/fe-libs/shared/events";
6
- import { getStoredAuthToken as c, graphqlFetch as l } from "@burdenoff/fe-libs/shared/graphql";
7
- import { clearWorkspaceWideSelection as u, isWorkspaceWideSelection as d, selectWorkspaceWide as f } from "@burdenoff/fe-libs/shared/providers/shell/WorkspaceWideSelection";
8
- import { getUrlParam as p } from "@burdenoff/fe-libs/shared/providers/shell/ActiveContextStorage";
9
- import { useActiveContext as m } from "@burdenoff/fe-libs/shared/providers/shell/ActiveContextProvider";
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 h = "\n query MyOrganizations {\n myOrganizations {\n total\n items {\n id\n name\n slug\n tenantId\n description\n logo\n website\n status\n type\n createdAt\n updatedAt\n }\n }\n }\n", g = "\n query WorkspacesByOrg {\n workspaces: myWorkspaces(limit: 100) {\n total\n items {\n id\n name\n slug\n tenantId\n organizationId\n type\n status\n region\n createdAt\n updatedAt\n }\n }\n }\n", 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", _ = "\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";
12
- function v(e, t = 3e4) {
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 y(e) {
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 b(e, t) {
34
- if (!e || v(e)) return !1;
35
- let n = y(e);
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 x = class extends Error {
39
+ var E = class extends Error {
39
40
  constructor(e) {
40
41
  super(e), this.name = "AuthError";
41
42
  }
42
43
  };
43
- function S(e) {
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 C() {
47
+ function O() {
47
48
  let t = e.getState().accessToken;
48
- if (t && !v(t)) return t;
49
- let n = c();
50
- return n && !v(n) ? n : t;
49
+ if (t && !C(t)) return t;
50
+ let n = d();
51
+ return n && !C(n) ? n : t;
51
52
  }
52
- function w(e) {
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 T = new Set([
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
- ]), E = new Set([
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 D(e) {
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 O(c) {
80
- let { organizationId: p, workspaceId: v, projectId: y, tenantId: O, setContext: k } = m(), A = s(), j = e((e) => e.organizations), M = e((e) => e.currentOrganizationId), N = e((e) => e.isLoadingOrganizations), P = e((e) => e.workspaces), F = e((e) => e.currentWorkspaceId), I = e((e) => e.workspaceToken), L = e((e) => e.isLoadingWorkspaces), te = e((e) => e.projects), ne = e((e) => e.currentProjectId), re = e((e) => e.isLoadingProjects);
81
- r(() => {
82
- let e = P.find((e) => e.id === v && e.organizationId === p), t = j.find((e) => e.id === p);
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 || O === e.tenantId || k({ tenantId: e.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
- p,
86
- v,
87
- O,
88
- j,
89
- P,
90
- k
110
+ b,
111
+ x,
112
+ C,
113
+ F,
114
+ L,
115
+ w
91
116
  ]);
92
- let [ie, R] = a(null), [z, B] = a(0), V = i(0), H = i(null), U = i(/* @__PURE__ */ new Map()), W = i(v), G = i(p);
93
- r(() => {
94
- W.current = v, G.current = p;
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 K = t(), q = c?.globalBaseUrl ?? K.globalBaseUrl, J = c?.workspaceBaseUrl ?? K.workspaceBaseUrl, ae = i(null), Y = i(null), oe = i(null), se = i(null);
97
- r(() => {
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 (p && p !== t.currentOrganizationId && p !== ae.current && (ae.current = p, t.setCurrentOrganizationId(p), t.workspaces.length > 0 && !t.workspaces.some((e) => e.organizationId === p) && t.setWorkspaces([])), v && v !== t.currentWorkspaceId && v !== Y.current && (Y.current = v, t.setCurrentWorkspaceId(v), t.projects.length > 0 && !t.projects.some((e) => e.workspaceId === v) && (t.setProjects([]), t.setCurrentProjectId(null))), d({
100
- organizationId: p,
101
- workspaceId: v
102
- }) && !y && t.currentProjectId && (t.setCurrentProjectId(null), t.setWorkspaceToken(null)), y && y !== t.currentProjectId && y !== oe.current && (oe.current = y, t.setCurrentProjectId(y)), t.workspaceToken && !b(t.workspaceToken, {
103
- workspaceId: v,
104
- organizationId: p,
105
- projectId: y,
106
- workspaceWide: !y && d({
107
- organizationId: p,
108
- workspaceId: v
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 = `${p ?? ""}|${v ?? ""}|${y ?? ""}`;
112
- se.current !== e && (se.current = e, t.setWorkspaceToken(null));
136
+ let e = `${b ?? ""}|${x ?? ""}|${S ?? ""}`;
137
+ fe.current !== e && (fe.current = e, t.setWorkspaceToken(null));
113
138
  }
114
139
  }, [
115
- p,
116
- v,
117
- y
140
+ b,
141
+ x,
142
+ S
118
143
  ]);
119
- let X = n(async () => {
120
- if (H.current) return H.current;
121
- let t = e.getState(), n = C();
122
- return n ? (t.setLoadingOrganizations(!0), R(null), H.current = (async () => {
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 r = G.current ?? t.currentOrganizationId, i = r ? await (async () => {
125
- let [e, t] = await Promise.all([l({
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: h,
128
- authToken: n,
129
- baseUrl: q
130
- }), l({
152
+ query: v,
153
+ authToken: a,
154
+ baseUrl: J
155
+ }), f({
131
156
  gateway: "global",
132
- query: g,
133
- authToken: n,
134
- baseUrl: q
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 l({
168
+ })() : await f({
144
169
  gateway: "global",
145
- query: h,
146
- authToken: n,
147
- baseUrl: q
170
+ query: v,
171
+ authToken: a,
172
+ baseUrl: J
148
173
  });
149
- if (r && i.errors?.length && i.errors.some((e) => e?.extensions?.code === "FORBIDDEN" || /not a member of this organization/i.test(e?.message ?? "") || /Cannot return null for non-nullable field Query\.myOrganizations/i.test(e?.message ?? "")) && (i = await l({
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: n,
153
- baseUrl: q
154
- })), i.errors?.length) {
155
- let e = i.errors[0]?.message ?? "GraphQL error";
156
- throw S(i.errors) ? new x(e) : (t.workspaces.length === 0 && console.error("Failed to fetch organizations:", i.errors), Error(e));
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 a = i.data?.myOrganizations?.items ?? [];
159
- if (r && a.length === 0 && t.workspaces.length === 0) {
160
- let e = await l({
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: h,
163
- authToken: n,
164
- baseUrl: q
187
+ query: v,
188
+ authToken: a,
189
+ baseUrl: J
165
190
  });
166
- if (!e.errors?.length) a = e.data?.myOrganizations?.items ?? [], i = {
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 S(e.errors ?? []) ? new x(t) : Error(t);
201
+ throw D(e.errors ?? []) ? new E(t) : Error(t);
177
202
  }
178
203
  }
179
- let o = a.length === 0 && t.workspaces.length > 0 ? w(t.workspaces) : [], s = o.length > 0 ? o : a;
180
- t.setOrganizations(s);
181
- let c = r, u = c && a.some((e) => e.id === c);
182
- if (c && !u && a.length > 0 && (c = a[0].id, k({
183
- organizationId: c,
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)), c && c !== t.currentOrganizationId && t.setCurrentOrganizationId(c), s.length > 0 && !c && (t.setCurrentOrganizationId(s[0].id), c = s[0].id), c && e.getState().workspaces.length === 0) {
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 = (r === c ? i.data?.workspaces?.items?.filter((e) => e.organizationId === c) : void 0) || await l({
241
+ let e = (_ ? _.items.filter((e) => e.organizationId === h) : void 0) || await f({
191
242
  gateway: "global",
192
- query: g,
193
- authToken: n,
194
- baseUrl: q
195
- }).then((e) => e.errors?.length ? null : (e.data?.workspaces?.items ?? []).filter((e) => e.organizationId === c));
196
- if (e || B((e) => e + 1), 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 = W.current ? e.find((e) => e.id === W.current) : null;
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: c,
253
+ organizationId: h,
203
254
  workspaceId: e[0].id,
204
255
  tenantId: e[0].tenantId,
205
256
  projectId: null
206
257
  };
207
- W.current ? (t.setCurrentWorkspaceId(e[0].id), t.setWorkspaceToken(null), k(n)) : t.currentWorkspaceId || (t.setCurrentWorkspaceId(e[0].id), k(n));
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
- B((e) => e + 1);
262
+ H((e) => e + 1);
212
263
  } finally {
213
264
  t.setLoadingWorkspaces(!1);
214
265
  }
215
266
  }
216
- return V.current = 0, s;
267
+ return U.current = 0, m;
217
268
  } catch (e) {
218
- if (e instanceof x) return [];
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), R(n), B((e) => e + 1), t.workspaces.length > 0) {
221
- let e = w(t.workspaces);
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), H.current = null;
277
+ t.setLoadingOrganizations(!1), W.current = null;
227
278
  }
228
- })(), H.current) : [];
229
- }, [q, k]);
230
- r(() => {
231
- if (z === 0 || V.current >= 5 || !C()) return;
232
- V.current += 1;
233
- let e = Math.min(1500 * 2 ** (V.current - 1), 12e3), t = window.setTimeout(() => {
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
- }, [z, X]), r(() => {
290
+ }, [se, X]), o(() => {
240
291
  let t = () => {
241
- e.getState().organizations.length === 0 && C() && (V.current = 0, X());
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 = n(async (t) => {
248
- let n = e.getState(), r = C(), i = o(), a = n.user?.id, s = JSON.stringify([
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
- ]), c = U.current.get(s);
254
- if (c) return c;
255
- let u = () => {
304
+ ]), s = G.current.get(o);
305
+ if (s) return s;
306
+ let c = () => {
256
307
  let n = e.getState();
257
- return o() === i && n.user?.id === a && C() === r && n.currentOrganizationId === t;
308
+ return l() === i && n.user?.id === a && O() === r && n.currentOrganizationId === t;
258
309
  };
259
310
  if (!r) return [];
260
- n.setLoadingWorkspaces(!0), R(null);
261
- let d = (async () => {
311
+ n.setLoadingWorkspaces(!0), V(null);
312
+ let u = (async () => {
262
313
  try {
263
- let e = await l({
314
+ let e = await f({
264
315
  gateway: "global",
265
- query: g,
316
+ query: y,
266
317
  authToken: r,
267
- baseUrl: q
318
+ baseUrl: J
268
319
  });
269
- if (!u()) return [];
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 S(e.errors) ? new x(t) : (console.error("Failed to fetch workspaces:", e.errors), Error(t));
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 (!u() || e instanceof x) return [];
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), R(t), [];
330
+ return console.error("Failed to fetch workspaces:", e), V(t), [];
280
331
  } finally {
281
- u() && n.setLoadingWorkspaces(!1), U.current.delete(s);
332
+ c() && n.setLoadingWorkspaces(!1), G.current.delete(o);
282
333
  }
283
334
  })();
284
- return U.current.set(s, d), d;
285
- }, [q]), Q = n(async (t, n, r, i) => {
286
- let a = e.getState(), s = [
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
- ], c = d({
341
+ ], s = m({
291
342
  organizationId: t,
292
343
  workspaceId: n ?? null
293
- }), u = C(), f = o(), p = a.user?.id;
294
- if (!u) return {
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
- R(null);
349
+ V(null);
299
350
  try {
300
- let m = await l({
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: u,
309
- baseUrl: J,
359
+ authToken: c,
360
+ baseUrl: Y,
310
361
  tenantId: i
311
362
  });
312
- if (m.errors?.length) {
313
- let e = m.errors[0]?.message ?? "GraphQL error";
314
- return S(m.errors) || console.error("Failed to issue workspace token:", m.errors), {
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 = m.data?.issueWorkspaceToken;
370
+ let h = p.data?.issueWorkspaceToken;
320
371
  if (h?.success && h.token) {
321
372
  let i = e.getState();
322
- if (o() !== f || e.getState().user?.id !== p || C() !== u || s.some((e, t) => e !== [
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]) || d({
377
+ ][t]) || m({
327
378
  organizationId: t,
328
379
  workspaceId: n ?? null
329
- }) !== c || !b(h.token, {
380
+ }) !== s || !T(h.token, {
330
381
  organizationId: t,
331
382
  workspaceId: n,
332
383
  projectId: r,
333
- workspaceWide: c
384
+ workspaceWide: s
334
385
  })) return {
335
386
  success: !1,
336
387
  error: "Workspace context changed during token issuance"
337
388
  };
338
- let l = h.workspaceId || n;
339
- return l && a.setCurrentWorkspaceId(l), a.setWorkspaceToken(h.token), {
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: l || void 0
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), R(t), {
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
- }, [J]), $ = n(async () => {
357
- let t = e.getState(), n = C(), r = t.workspaceToken, i = t.currentWorkspaceId, a = o(), s = t.user?.id, c = t.currentOrganizationId, u = t.currentProjectId, f = d({
358
- organizationId: c,
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
- }), p = () => {
411
+ }), d = () => {
361
412
  let t = e.getState();
362
- return o() === a && t.user?.id === s && C() === n && t.workspaceToken === r && t.currentOrganizationId === c && t.currentWorkspaceId === i && t.currentProjectId === u && d({
363
- organizationId: c,
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
- }) === f;
416
+ }) === u;
366
417
  };
367
418
  if (!n || !r || !i) return [];
368
- t.setLoadingProjects(!0), R(null);
419
+ t.setLoadingProjects(!0), V(null);
369
420
  try {
370
- let e = await l({
421
+ let e = await f({
371
422
  gateway: "workspace",
372
- query: _,
423
+ query: te,
373
424
  authToken: n,
374
425
  workspaceToken: r,
375
- baseUrl: J
426
+ baseUrl: Y
376
427
  });
377
- if (!p()) return [];
428
+ if (!d()) return [];
378
429
  if (e.errors?.length) {
379
430
  let t = e.errors[0]?.message ?? "GraphQL error";
380
- throw S(e.errors) ? new x(t) : (console.error("Failed to fetch projects:", e.errors), Error(t));
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 x) return [];
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), R(t), [];
438
+ return console.error("Failed to fetch projects:", e), V(t), [];
388
439
  } finally {
389
440
  t.setLoadingProjects(!1);
390
441
  }
391
- }, [J]), ce = n(async (t) => {
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]), le = n(async (t) => {
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 = o(), s = i.user?.id, c = C(), l = i.workspaceToken, u = i.currentProjectId, f = d({
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
- }), p = () => {
459
+ }), f = () => {
409
460
  let n = e.getState();
410
- return o() === a && n.user?.id === s && C() === c && n.workspaceToken === l && n.currentOrganizationId === t.organizationId && n.currentWorkspaceId === t.id && n.currentProjectId === u && d({
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
- }) === f;
414
- }, m = await $();
415
- return p() ? (m.length > 0 && !d({
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(m[0].id), {
469
+ }) && n.setCurrentProjectId(p[0].id), {
419
470
  success: !0,
420
- projects: m
471
+ projects: p
421
472
  }) : {
422
473
  success: !1,
423
474
  error: "Context changed during selection"
424
475
  };
425
- }, [Q, $]), ue = n((t) => {
476
+ }, [Q, $]), he = a((t) => {
426
477
  let n = e.getState();
427
- u({
478
+ p({
428
479
  organizationId: n.currentOrganizationId,
429
480
  workspaceId: n.currentWorkspaceId
430
- }), n.setCurrentProjectId(t.id), n.workspaceToken && !b(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
- }, []), de = n(() => {
486
+ }, []), ge = a(() => {
436
487
  let t = e.getState(), n = {
437
- organizationId: G.current,
438
- workspaceId: W.current
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 (!f(n)) throw Error("Workspace-wide preference could not be saved");
442
- t.setCurrentProjectId(null), t.setWorkspaceToken(null), k({ projectId: null });
443
- }, [k]);
444
- return r(() => {
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 = A.onAny((t) => {
512
+ }), a = P.onAny((t) => {
462
513
  let n = t.name;
463
- if (T.has(n)) {
464
- let n = D(t.payload), { currentWorkspaceId: i } = e.getState();
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
- E.has(n) && i();
520
+ M.has(n) && i();
470
521
  });
471
522
  return () => {
472
523
  t = !0, a();
473
524
  };
474
525
  }, [
475
- A,
526
+ P,
476
527
  $,
477
528
  Z
478
529
  ]), {
479
- organizations: j,
480
- workspaces: P,
481
- projects: te,
482
- currentOrganizationId: M,
483
- currentWorkspaceId: F,
484
- currentProjectId: ne,
485
- currentOrganization: j.find((e) => e.id === M),
486
- currentWorkspace: P.find((e) => e.id === F),
487
- currentProject: te.find((e) => e.id === ne),
488
- workspaceToken: I,
489
- isLoadingOrganizations: N,
490
- isLoadingWorkspaces: L,
491
- isLoadingProjects: re,
492
- isLoading: N || L || re,
493
- error: ie,
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: ce,
499
- selectWorkspace: le,
500
- selectProject: ue,
501
- selectWorkspaceWide: de
549
+ selectOrganization: pe,
550
+ selectWorkspace: me,
551
+ selectProject: he,
552
+ selectWorkspaceWide: ge
502
553
  };
503
554
  }
504
- function k(n) {
505
- let i = e((e) => e.currentOrganizationId), a = e((e) => e.workspaces), o = e((e) => e.accessToken), s = e((e) => e.isLoadingWorkspaces), c = t(), u = n?.globalBaseUrl ?? c.globalBaseUrl, d = n?.disableWorkspaceSync ?? !1;
506
- r(() => {
507
- if (d || !i || !o || s) return;
508
- let t = a.some((e) => e.organizationId === i);
509
- if (a.length > 0 && !t) {
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), l({
562
+ t.setLoadingWorkspaces(!0), f({
512
563
  gateway: "global",
513
- query: g,
514
- authToken: o,
515
- baseUrl: u
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 === i)), !e.errors?.length) {
518
- let n = (e.data?.workspaces?.items ?? []).filter((e) => e.organizationId === i);
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
- u,
531
- d
581
+ l,
582
+ u
532
583
  ]);
533
584
  }
534
- function A(n) {
535
- let s = e((e) => e.currentWorkspaceId), c = e((e) => e.currentOrganizationId), f = e((e) => e.workspaces), m = e((e) => e.projects), h = e((e) => e.currentProjectId), g = e((e) => e.workspaceToken), y = e((e) => e.accessToken), x = t(), S = n?.workspaceBaseUrl ?? x.workspaceBaseUrl, C = n?.disableProjectSync ?? !1, w = n?.skipProjectFetch ?? !1, T = i(!1), [E, D] = a(0), O = i(null), k = i(/* @__PURE__ */ new Map()), A = i(/* @__PURE__ */ new Map()), j = 3e4;
536
- r(() => {
537
- if (C || !s || !y || T.current) return;
538
- let t = A.current.get(s);
539
- if (t && t.count >= 8 && Date.now() - t.lastFailureAt < j) return;
540
- t && Date.now() - t.lastFailureAt >= j && A.current.delete(s);
541
- let n = f.find((e) => e.id === s);
542
- if (n && c && n.organizationId !== c) return;
543
- let r = n?.organizationId ?? c;
544
- if (!r) return;
545
- let i = e.getState();
546
- h && p("project") === h && p("workspace") === s && p("org") === r && u({
547
- organizationId: r,
548
- workspaceId: s
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 a = o(), x = i.user?.id, E = d({
551
- organizationId: r,
552
- workspaceId: s
601
+ let c = l(), v = s.user?.id, w = m({
602
+ organizationId: o,
603
+ workspaceId: r
553
604
  });
554
- if (E && i.currentProjectId) {
555
- i.setCurrentProjectId(null), i.setWorkspaceToken(null);
605
+ if (w && s.currentProjectId) {
606
+ s.setCurrentProjectId(null), s.setWorkspaceToken(null);
556
607
  return;
557
608
  }
558
- let M = !g || v(g) || !b(g, {
559
- workspaceId: s,
560
- organizationId: c,
561
- projectId: h,
562
- workspaceWide: E
563
- }), N = JSON.stringify([
564
- a,
565
- x,
566
- y,
567
- r,
568
- s
569
- ]), P = m.some((e) => e.workspaceId === s) || O.current?.scopeKey === N && O.current.projects === m;
570
- if (P && !M) {
571
- if (!i.currentProjectId && !E) {
572
- let e = m.find((e) => e.workspaceId === s);
573
- e && i.setCurrentProjectId(e.id);
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 F = () => {
628
+ let P = () => {
578
629
  let t = e.getState();
579
- return t.accessToken === y && t.user?.id === x && o() === a && t.currentOrganizationId === r && t.currentWorkspaceId === s && t.currentProjectId === h && d({
580
- organizationId: r,
581
- workspaceId: s
582
- }) === E;
583
- }, I = async () => {
584
- T.current = !0, i.setLoadingProjects(!0);
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 = g;
588
- if (M) {
589
- let e = await l({
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: r,
594
- workspaceId: s,
595
- ...h ? { projectId: h } : {}
644
+ organizationId: o,
645
+ workspaceId: r,
646
+ ...d ? { projectId: d } : {}
596
647
  } },
597
- authToken: y,
598
- baseUrl: S,
599
- tenantId: f.find((e) => e.id === s)?.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, !F() || !b(n, {
603
- workspaceId: s,
604
- organizationId: r,
605
- projectId: h,
606
- workspaceWide: E
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
- i.setWorkspaceToken(n);
659
+ s.setWorkspaceToken(n);
609
660
  } else return;
610
661
  }
611
- if (n && !P && !w) {
612
- let t = await l({
662
+ if (n && !N && !x) {
663
+ let t = await f({
613
664
  gateway: "workspace",
614
- query: _,
615
- authToken: y,
665
+ query: te,
666
+ authToken: _,
616
667
  workspaceToken: n,
617
- baseUrl: S
668
+ baseUrl: y
618
669
  });
619
- if (!F() || t.errors?.length) return;
620
- let a = t.data?.projects?.items ?? [];
621
- O.current = a.length === 0 ? {
622
- scopeKey: N,
623
- projects: a
624
- } : null, i.setProjects(a), h && !a.some((e) => e.id === h) && (i.setCurrentProjectId(null), i.setWorkspaceToken(null)), a.length > 0 && !e.getState().currentProjectId && !d({
625
- organizationId: r,
626
- workspaceId: s
627
- }) && i.setCurrentProjectId(a[0].id);
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
- i.setLoadingProjects(!1), T.current = !1;
632
- let n = F();
633
- n || D((e) => e + 1);
634
- let r = A.current;
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
- r.delete(s);
637
- let e = k.current.get(s);
638
- e && (clearTimeout(e), k.current.delete(s));
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 = (r.get(s)?.count ?? 0) + 1;
641
- if (r.set(s, {
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 = k.current.get(s);
696
+ let n = O.current.get(r);
646
697
  n && clearTimeout(n);
647
- let r = Math.min(1e3 * 2 ** (t - 1), 8e3), i = setTimeout(() => {
648
- k.current.delete(s);
698
+ let i = Math.min(1e3 * 2 ** (t - 1), 8e3), a = setTimeout(() => {
699
+ O.current.delete(r);
649
700
  let t = e.getState();
650
- F() && t.currentWorkspaceId === s && !t.projects.some((e) => e.workspaceId === s) && !T.current && I();
651
- }, r);
652
- k.current.set(s, i);
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
- I();
708
+ F();
658
709
  }, [
659
- E,
660
- s,
661
- c,
662
- f,
663
- m,
710
+ w,
711
+ r,
712
+ i,
713
+ a,
714
+ u,
715
+ d,
664
716
  h,
665
- g,
717
+ _,
666
718
  y,
667
- S,
668
- C,
669
- w
670
- ]), r(() => {
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 { O as useContextSwitcherData, A as useProjectSyncEffect, k as useWorkspaceSyncEffect };
729
+ export { P as useContextSwitcherData, I as useProjectSyncEffect, F as useWorkspaceSyncEffect };
679
730
 
680
731
  //# sourceMappingURL=useContextSwitcherData.js.map