@burdenoff/fe-libs 2026.1023.7 → 2026.1023.9

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.
Files changed (39) hide show
  1. package/dist/shared/events/sinks/RybbitSink.d.ts +21 -0
  2. package/dist/shared/events/sinks/RybbitSink.js +36 -11
  3. package/dist/shared/events/sinks/index.d.ts +1 -1
  4. package/dist/shared/graphql/client.d.ts +9 -0
  5. package/dist/shared/graphql/client.js +241 -201
  6. package/dist/shared/graphql/fetch.js +135 -123
  7. package/dist/shared/graphql/index.d.ts +1 -0
  8. package/dist/shared/graphql/workspaceOperationGuard.d.ts +70 -0
  9. package/dist/shared/graphql/workspaceOperationGuard.js +62 -0
  10. package/dist/shared/providers/AppShellProvider.d.ts +16 -0
  11. package/dist/shared/providers/AppShellProvider.js +232 -226
  12. package/dist/shared/providers/shell/AuthProvider.d.ts +14 -1
  13. package/dist/shared/providers/shell/AuthProvider.js +105 -94
  14. package/dist/shared/providers/shell/MultiGatewayProvider.d.ts +8 -1
  15. package/dist/shared/providers/shell/MultiGatewayProvider.js +115 -119
  16. package/dist/shared/providers/shell/ProfileStorageManager.js +1 -1
  17. package/dist/shared/providers/shell/WorkspaceWriteRefusedToastListener.d.ts +4 -0
  18. package/dist/shared/providers/shell/WorkspaceWriteRefusedToastListener.js +23 -0
  19. package/dist/shared/providers/shell/authProvider/identityChange.d.ts +26 -0
  20. package/dist/shared/providers/shell/authProvider/identityChange.js +11 -0
  21. package/dist/shared/providers/shell/authProvider/useAuthActions.d.ts +4 -1
  22. package/dist/shared/providers/shell/authProvider/useAuthActions.js +105 -92
  23. package/dist/shared/providers/shell/authProvider/useBridgeInitialization.d.ts +27 -1
  24. package/dist/shared/providers/shell/authProvider/useBridgeInitialization.js +82 -62
  25. package/dist/shared/providers/shell/authProvider/useRemoteSLO.d.ts +4 -1
  26. package/dist/shared/providers/shell/authProvider/useRemoteSLO.js +16 -14
  27. package/dist/shared/providers/shell/authProvider/useStorageSync.d.ts +4 -1
  28. package/dist/shared/providers/shell/authProvider/useStorageSync.js +19 -14
  29. package/dist/shared/providers/shell/contextSwitchCache.d.ts +4 -0
  30. package/dist/shared/providers/shell/contextSwitchCache.js +17 -0
  31. package/dist/shared/providers/shell/identityQueryReset.d.ts +17 -0
  32. package/dist/shared/providers/shell/identityQueryReset.js +21 -0
  33. package/dist/shared/providers/shell/identityScopedQueryReset.d.ts +16 -0
  34. package/dist/shared/providers/shell/identityScopedQueryReset.js +30 -0
  35. package/dist/shared/providers/shell/index.d.ts +1 -1
  36. package/dist/shared-events.js +29 -29
  37. package/dist/shared-graphql.js +11 -10
  38. package/dist/shared.js +129 -128
  39. package/package.json +2 -2
@@ -2,44 +2,45 @@ import { isOperationRetryable as e } from "./retryPolicy.js";
2
2
  import { GATEWAYS as t, getGatewayUrl as n } from "../../shared-config.js";
3
3
  import { validateGatewayBaseUrl as r } from "./security.js";
4
4
  import { isWorkspaceTokenValidForContext as i } from "./workspaceToken.js";
5
- import { dispatchBackendErrorEvent as a, markConnectionHealthy as o } from "../utils/backendErrors.js";
6
- import { clearGraphqlFetchResponseCache as s, enqueueGraphQLFetch as c, ensureWorkspaceToken as l } from "./fetch.js";
7
- import { SSELink as u } from "./links/sse-link.js";
8
- import { onError as d } from "@apollo/client/link/error";
9
- import { RetryLink as f } from "@apollo/client/link/retry";
10
- import { setContext as p } from "@apollo/client/link/context";
11
- import { ApolloClient as m, ApolloLink as h, InMemoryCache as ee, Observable as g, from as te, split as _ } from "@apollo/client/core";
12
- import { getMainDefinition as v } from "@apollo/client/utilities";
13
- import { print as y } from "graphql";
5
+ import { WORKSPACE_CONTEXT_MISMATCH_EVENT as a, WORKSPACE_WRITE_REFUSED_EVENT as o, WorkspaceContextChangedError as s, findWorkspaceContextMismatch as c, isWorkspaceContextChangedError as l, normalizeWorkspaceOperationGuardMode as u, refetchActiveQueries as d } from "./workspaceOperationGuard.js";
6
+ import { dispatchBackendErrorEvent as f, markConnectionHealthy as p } from "../utils/backendErrors.js";
7
+ import { clearGraphqlFetchResponseCache as m, enqueueGraphQLFetch as h, ensureWorkspaceToken as ee } from "./fetch.js";
8
+ import { SSELink as te } from "./links/sse-link.js";
9
+ import { onError as ne } from "@apollo/client/link/error";
10
+ import { RetryLink as g } from "@apollo/client/link/retry";
11
+ import { setContext as _ } from "@apollo/client/link/context";
12
+ import { ApolloClient as re, ApolloLink as v, InMemoryCache as ie, Observable as y, from as b, split as x } from "@apollo/client/core";
13
+ import { getMainDefinition as S } from "@apollo/client/utilities";
14
+ import { print as C } from "graphql";
14
15
  //#region src/shared/graphql/client.ts
15
- var b = {
16
+ var w = {
16
17
  consecutiveFailures: 0,
17
18
  lastFailureTime: 0,
18
19
  isOpen: !1,
19
20
  openCount: 0,
20
21
  nextRetryTime: 0
21
- }, x = 20, S = 5e3, C = 3e4;
22
- function ne() {
23
- if (b.consecutiveFailures++, b.lastFailureTime = Date.now(), !b.isOpen && b.consecutiveFailures >= x) {
24
- b.isOpen = !0, b.openCount++;
25
- let e = Math.min(S * 2 ** (b.openCount - 1), C);
26
- b.nextRetryTime = Date.now() + e;
22
+ }, T = 20, E = 5e3, D = 3e4;
23
+ function ae() {
24
+ if (w.consecutiveFailures++, w.lastFailureTime = Date.now(), !w.isOpen && w.consecutiveFailures >= T) {
25
+ w.isOpen = !0, w.openCount++;
26
+ let e = Math.min(E * 2 ** (w.openCount - 1), D);
27
+ w.nextRetryTime = Date.now() + e;
27
28
  }
28
- return b.isOpen;
29
+ return w.isOpen;
29
30
  }
30
- function w() {
31
- b.consecutiveFailures = 0, b.isOpen = !1, b.openCount = 0, b.nextRetryTime = 0, o();
31
+ function O() {
32
+ w.consecutiveFailures = 0, w.isOpen = !1, w.openCount = 0, w.nextRetryTime = 0, p();
32
33
  }
33
- function re() {
34
- return !(!b.isOpen || Date.now() >= b.nextRetryTime);
34
+ function k() {
35
+ return !(!w.isOpen || Date.now() >= w.nextRetryTime);
35
36
  }
36
- function T(t, n, r) {
37
- if (r || !t) return !1;
37
+ function A(t, n, r) {
38
+ if (r || !t || l(t)) return !1;
38
39
  let i = t.message?.toLowerCase?.() ?? "";
39
40
  return !(i.includes("401") || i.includes("403") || i.includes("unauthorized") || i.includes("forbidden") || i.includes("unauthenticated") || !e(n));
40
41
  }
41
- function ie({ maxAttempts: e, delay: t }) {
42
- return new f({
42
+ function oe({ maxAttempts: e, delay: t }) {
43
+ return new g({
43
44
  delay: t ?? {
44
45
  initial: 1e3,
45
46
  max: 8e3,
@@ -47,197 +48,224 @@ function ie({ maxAttempts: e, delay: t }) {
47
48
  },
48
49
  attempts: {
49
50
  max: e,
50
- retryIf: (e, t) => T(e, t, re())
51
+ retryIf: (e, t) => A(e, t, k())
51
52
  }
52
53
  });
53
54
  }
54
- var E = /(?:\b40[13]\b|status code 40[13]|unauthori[sz]ed|unauthenticated|forbidden|invalid email or password)/i;
55
- function D(e) {
55
+ var j = /(?:\b40[13]\b|status code 40[13]|unauthori[sz]ed|unauthenticated|forbidden|invalid email or password)/i;
56
+ function M(e) {
56
57
  return typeof e == "number" && Number.isInteger(e) ? e : typeof e == "string" && /^\d{3}$/.test(e) ? Number(e) : null;
57
58
  }
58
- function ae(e) {
59
+ function se(e) {
59
60
  let t = /* @__PURE__ */ new Set(), n = (e, r) => {
60
61
  if (r > 3 || e == null || t.has(e)) return !1;
61
- if (typeof e == "string") return E.test(e);
62
+ if (typeof e == "string") return j.test(e);
62
63
  if (typeof e != "object") return !1;
63
64
  t.add(e);
64
- let i = e, a = D(i.status) ?? D(i.statusCode) ?? D(i.response?.status);
65
+ let i = e, a = M(i.status) ?? M(i.statusCode) ?? M(i.response?.status);
65
66
  if (a === 401 || a === 403) return !0;
66
67
  let o = i.message;
67
- return typeof o == "string" && E.test(o) ? !0 : n(i.cause, r + 1);
68
+ return typeof o == "string" && j.test(o) ? !0 : n(i.cause, r + 1);
68
69
  };
69
70
  return n(e, 0);
70
71
  }
71
- function oe(e) {
72
+ function ce(e) {
72
73
  if (!e || typeof e != "object") return null;
73
74
  let t = e, n = t.workspaceId || t.input?.workspaceId;
74
75
  return typeof n == "string" && n.trim() ? n : null;
75
76
  }
76
- function se(e) {
77
+ function N(e) {
78
+ let t = e.workspaceDecision;
79
+ return t && typeof t == "object" ? t : null;
80
+ }
81
+ function le(e) {
77
82
  if (!e || typeof e != "object") return null;
78
83
  let t = e.projectId;
79
84
  return typeof t == "string" && t.trim() ? t : null;
80
85
  }
81
- function ce(e) {
82
- let t = v(e);
86
+ function ue(e) {
87
+ let t = S(e);
83
88
  return t.kind === "OperationDefinition" && t.operation === "mutation";
84
89
  }
85
- function le(e) {
90
+ function de(e) {
86
91
  let t = e.errors;
87
92
  return Array.isArray(t) && t.length > 0;
88
93
  }
89
- function O(e) {
94
+ function P(e) {
90
95
  let t = e.headers;
91
96
  if (!t || typeof t != "object" || Array.isArray(t)) return {};
92
97
  let n = {};
93
98
  for (let [e, r] of Object.entries(t)) typeof r == "string" && (n[e] = r);
94
99
  return n;
95
100
  }
96
- function k(e) {
101
+ function F(e) {
97
102
  let t = e.fetchOptions;
98
103
  if (!t || typeof t != "object" || !("signal" in t)) return;
99
104
  let n = t.signal;
100
105
  return n instanceof AbortSignal ? n : void 0;
101
106
  }
102
- function ue({ uri: e, batchMax: t, batchInterval: n }) {
103
- return new h((r) => new g((i) => {
104
- let a = r.getContext(), o = { query: y(r.query) };
107
+ function fe({ uri: e, batchMax: t, batchInterval: n }) {
108
+ return new v((r) => new y((i) => {
109
+ let a = r.getContext(), o = { query: C(r.query) };
105
110
  r.operationName && (o.operationName = r.operationName);
106
- let s = r.variables ?? {}, l = r.extensions ?? {};
107
- Object.keys(s).length > 0 && (o.variables = s), Object.keys(l).length > 0 && (o.extensions = l);
108
- let u = !1;
109
- return c(e, {
111
+ let s = r.variables ?? {}, c = r.extensions ?? {};
112
+ Object.keys(s).length > 0 && (o.variables = s), Object.keys(c).length > 0 && (o.extensions = c);
113
+ let l = !1;
114
+ return h(e, {
110
115
  "content-type": "application/json",
111
116
  "Apollo-Require-Preflight": "true",
112
- ...O(a)
113
- }, o, k(a), {
117
+ ...P(a)
118
+ }, o, F(a), {
114
119
  batchMax: t,
115
120
  batchInterval: n
116
121
  }).then((e) => {
117
- u || (i.next(e), i.complete());
122
+ l || (i.next(e), i.complete());
118
123
  }).catch((e) => {
119
- u || i.error(e);
124
+ l || i.error(e);
120
125
  }), () => {
121
- u = !0;
126
+ l = !0;
122
127
  };
123
128
  }));
124
129
  }
125
- function A(e) {
126
- let { gateway: o, baseUrl: c, authToken: f, workspaceToken: y, locale: x, geography: S, organizationId: C, productId: T, productSlug: E, workspaceId: D, projectId: O, tenantId: k, cache: A, enableSubscriptions: j = !1, sseUrl: M, onAuthError: N, onRefreshToken: P, onNetworkError: F, onNetworkStatusChange: I, onMutationSuccess: L, maxRetryAttempts: de = 3, batchMax: fe = 10, batchInterval: pe, debug: R = !1 } = e, z = null, B = null, me = (e) => {
127
- B ||= setTimeout(() => {
128
- B = null, z && z.refetchQueries({ include: "active" }).catch((t) => {
129
- R && console.warn("[GraphQL] Active query refresh failed after mutation:", {
130
- gateway: o,
130
+ function I(e) {
131
+ let { gateway: p, baseUrl: h, authToken: g, workspaceToken: C, locale: T, geography: E, organizationId: D, productId: A, productSlug: j, workspaceId: M, projectId: P, tenantId: F, cache: I, enableSubscriptions: L = !1, sseUrl: R, onAuthError: z, onRefreshToken: B, onNetworkError: V, onNetworkStatusChange: H, onMutationSuccess: U, maxRetryAttempts: pe = 3, batchMax: me = 10, batchInterval: he, debug: W = !1 } = e, G = u(e.workspaceOperationGuard), K = null, q = null, J = () => ({
132
+ workspaceId: (typeof M == "function" ? M() : M) || null,
133
+ organizationId: (typeof D == "function" ? D() : D) || null,
134
+ tenantId: (typeof F == "function" ? F() : F) || null,
135
+ projectId: (typeof P == "function" ? P() : P) || null
136
+ }), ge = (e) => {
137
+ q ||= setTimeout(() => {
138
+ q = null, K && d(K, G, () => J().workspaceId).catch((t) => {
139
+ W && console.warn("[GraphQL] Active query refresh failed after mutation:", {
140
+ gateway: p,
131
141
  operationName: e,
132
142
  error: t
133
143
  });
134
144
  });
135
145
  }, 0);
136
- }, V = t[o], H = r(n(c, o)), he = ue({
137
- uri: H,
138
- batchMax: fe,
139
- batchInterval: pe
140
- }), U = p((e, t) => {
141
- let n = t.headers ?? {}, r = typeof f == "function" ? f() : f;
146
+ }, _e = t[p], ve = r(n(h, p)), ye = fe({
147
+ uri: ve,
148
+ batchMax: me,
149
+ batchInterval: he
150
+ }), be = _((e, t) => {
151
+ let n = t.headers ?? {}, r = typeof g == "function" ? g() : g;
142
152
  return { headers: {
143
153
  ...n,
144
154
  ...r ? { authorization: `Bearer ${r}` } : {}
145
155
  } };
146
- }), W = p((e, t) => {
147
- let n = t.headers ?? {}, r = typeof x == "function" ? x() : x;
156
+ }), xe = _((e, t) => {
157
+ let n = t.headers ?? {}, r = typeof T == "function" ? T() : T;
148
158
  return { headers: {
149
159
  ...n,
150
160
  ...r ? { "accept-language": r } : {}
151
161
  } };
152
- }), G = p((e, t) => {
153
- let n = t.headers ?? {}, r = typeof S == "function" ? S() : null;
162
+ }), Se = _((e, t) => {
163
+ let n = t.headers ?? {}, r = typeof E == "function" ? E() : null;
154
164
  return { headers: {
155
165
  ...n,
156
166
  ...r?.country ? { "x-geo-country": r.country } : {},
157
167
  ...r?.currency ? { "x-geo-currency": r.currency } : {},
158
168
  ...r?.timezone ? { "x-geo-timezone": r.timezone } : {}
159
169
  } };
160
- }), K = p((e, t) => {
161
- let n = t.headers ?? {}, r = typeof C == "function" ? C() : C;
170
+ }), Ce = _((e, t) => {
171
+ let n = t.headers ?? {}, r = typeof D == "function" ? D() : D;
162
172
  return { headers: {
163
173
  ...n,
164
174
  ...r ? { "x-org-id": r } : {}
165
175
  } };
166
- }), q = p((e, t) => {
167
- let n = t.headers ?? {}, r = typeof T == "function" ? T() : T, i = typeof E == "function" ? E() : E;
176
+ }), we = _((e, t) => {
177
+ let n = t.headers ?? {}, r = typeof A == "function" ? A() : A, i = typeof j == "function" ? j() : j;
168
178
  return { headers: {
169
179
  ...n,
170
180
  ...r ? { "x-product-id": r } : {},
171
181
  ...i ? { "x-product-slug": i } : {}
172
182
  } };
173
- }), J = p((e, t) => {
174
- let n = t.headers ?? {}, r = (typeof D == "function" ? D() : D) || oe(e.variables);
183
+ }), Te = _((e, t) => {
184
+ let n = t.headers ?? {}, r = N(t), i = (r ? r.workspaceId : typeof M == "function" ? M() : M) || ce(e.variables);
175
185
  return { headers: {
176
186
  ...n,
177
- ...r ? { "x-workspace-id": r } : {}
187
+ ...i ? { "x-workspace-id": i } : {}
178
188
  } };
179
- }), Y = p((e, t) => {
180
- let n = t.headers ?? {}, r = (typeof O == "function" ? O() : O) || se(e.variables);
189
+ }), Ee = _((e, t) => {
190
+ let n = t.headers ?? {}, r = N(t), i = (r ? r.projectId : typeof P == "function" ? P() : P) || le(e.variables);
181
191
  return { headers: {
182
192
  ...n,
183
- ...r ? { "x-project-id": r } : {}
193
+ ...i ? { "x-project-id": i } : {}
184
194
  } };
185
- }), ge = p((e, t) => {
186
- let n = t.headers ?? {}, r = typeof k == "function" ? k() : k;
195
+ }), De = _((e, t) => {
196
+ let n = t.headers ?? {}, r = typeof F == "function" ? F() : F;
187
197
  return { headers: {
188
198
  ...n,
189
199
  ...r ? { "x-tenant-id": r } : {}
190
200
  } };
191
- }), X = p(async (e, t) => {
201
+ }), Oe = (e, t, n) => {
202
+ if (p !== "workspace" || G === "off") return;
203
+ let r = c(e, t, n);
204
+ if (r) {
205
+ if (G === "enforce") throw new s(r);
206
+ typeof window < "u" && window.dispatchEvent(new CustomEvent(a, { detail: r }));
207
+ }
208
+ }, ke = _(async (e, t) => {
192
209
  let r = t.headers ?? {}, a = t.requiredWorkspaceAuth === !0;
193
- if (o === "global" && !a) return { headers: r };
194
- let s = typeof f == "function" ? f() : f, c = typeof y == "function" ? y() : y, u = typeof D == "function" ? D() : D, d = typeof C == "function" ? C() : C, p = typeof k == "function" ? k() : k, m = typeof O == "function" ? O() : O, h = i(c, {
195
- workspaceId: u,
196
- organizationId: d,
197
- tenantId: p,
198
- projectId: m
199
- }) ? c : null;
200
- if (a && t.requiredWorkspaceId && t.requiredWorkspaceId !== u) throw Error("The active workspace changed; retry the request");
201
- if (a && !u) throw Error("Workspace authentication requires an active workspace");
202
- if (!h && (o === "workspace" || a)) try {
203
- let t = typeof f == "function" ? f() : f;
210
+ if (p === "global" && !a) return { headers: r };
211
+ let o = typeof g == "function" ? g() : g, s = typeof C == "function" ? C() : C, c = J(), { workspaceId: l, organizationId: u, tenantId: d, projectId: f } = c;
212
+ Oe(e, l, "before-send");
213
+ let m = !1, h = i(s, {
214
+ workspaceId: l,
215
+ organizationId: u,
216
+ tenantId: d,
217
+ projectId: f
218
+ }) ? s : null;
219
+ if (a && t.requiredWorkspaceId && t.requiredWorkspaceId !== l) throw Error("The active workspace changed; retry the request");
220
+ if (a && !l) throw Error("Workspace authentication requires an active workspace");
221
+ if (!h && (p === "workspace" || a)) try {
222
+ let t = typeof g == "function" ? g() : g;
204
223
  if (t) {
205
- let r = await Promise.race([l({
206
- url: o === "workspace" ? H : n(void 0, "workspace"),
224
+ m = !0;
225
+ let r = await Promise.race([ee({
226
+ url: p === "workspace" ? ve : n(void 0, "workspace"),
207
227
  authToken: t,
208
- workspaceId: u ?? void 0,
209
- organizationId: d ?? void 0,
210
- projectId: m ?? void 0,
228
+ workspaceId: l ?? void 0,
229
+ organizationId: u ?? void 0,
230
+ projectId: f ?? void 0,
211
231
  currentQuery: e.operationName ?? ""
212
232
  }), new Promise((e) => setTimeout(() => e(null), 4e3))]);
213
233
  i(r, {
214
- workspaceId: u,
215
- organizationId: d,
216
- tenantId: p,
217
- projectId: m
234
+ workspaceId: l,
235
+ organizationId: u,
236
+ tenantId: d,
237
+ projectId: f
218
238
  }) && (h = r);
219
239
  }
220
240
  } catch {}
221
241
  if (a) {
222
242
  if (!h) throw Error("Workspace authentication is unavailable; retry the request");
223
- if (s !== (typeof f == "function" ? f() : f) || u !== (typeof D == "function" ? D() : D) || d !== (typeof C == "function" ? C() : C) || m !== (typeof O == "function" ? O() : O) || p !== (typeof k == "function" ? k() : k)) throw Error("The active workspace changed; retry the request");
243
+ let e = J();
244
+ if (o !== (typeof g == "function" ? g() : g) || e.workspaceId !== l || e.organizationId !== u || e.projectId !== f || e.tenantId !== d) throw Error("The active workspace changed; retry the request");
224
245
  }
225
- return { headers: {
226
- ...r,
227
- ...h ? { "x-workspace-authorization": `Bearer ${h}` } : {}
228
- } };
229
- }), _e = ie({ maxAttempts: de }), ve = new h((e, t) => {
230
- if (re()) {
231
- R && console.warn("[CircuitBreaker] Circuit is open, blocking request:", e.operationName);
232
- let t = Math.max(0, Math.ceil((b.nextRetryTime - Date.now()) / 1e3)), n = /* @__PURE__ */ Error(`Network circuit breaker is open — backend appears unreachable. Retrying in ${t} seconds.`);
233
- return F?.(n), new g((e) => {
246
+ if (m) {
247
+ let t = J().workspaceId;
248
+ t !== l && Oe(e, t, "after-token-mint");
249
+ }
250
+ return {
251
+ headers: {
252
+ ...r,
253
+ ...h ? { "x-workspace-authorization": `Bearer ${h}` } : {}
254
+ },
255
+ workspaceDecision: c
256
+ };
257
+ }), Ae = oe({ maxAttempts: pe }), je = new v((e, t) => {
258
+ if (k()) {
259
+ W && console.warn("[CircuitBreaker] Circuit is open, blocking request:", e.operationName);
260
+ let t = Math.max(0, Math.ceil((w.nextRetryTime - Date.now()) / 1e3)), n = /* @__PURE__ */ Error(`Network circuit breaker is open — backend appears unreachable. Retrying in ${t} seconds.`);
261
+ return V?.(n), new y((e) => {
234
262
  e.error(n);
235
263
  });
236
264
  }
237
- return new g((n) => {
265
+ return new y((n) => {
238
266
  let r = t(e).subscribe({
239
267
  next: (e) => {
240
- w(), b.consecutiveFailures === 0 && I?.(!1), n.next(e);
268
+ O(), w.consecutiveFailures === 0 && H?.(!1), n.next(e);
241
269
  },
242
270
  error: (e) => {
243
271
  n.error(e);
@@ -250,83 +278,95 @@ function A(e) {
250
278
  r.unsubscribe();
251
279
  };
252
280
  });
253
- }), Z = !1, Q = [];
254
- function $(e) {
255
- Q.forEach(({ resolve: t }) => t(e)), Q = [];
281
+ }), Y = !1, X = [];
282
+ function Z(e) {
283
+ X.forEach(({ resolve: t }) => t(e)), X = [];
256
284
  }
257
- let ye = d(({ error: e, operation: t, forward: n }) => {
285
+ let Q = (e) => {
286
+ l(e) && e.detail?.operationKind === "mutation" && typeof window < "u" && window.dispatchEvent(new CustomEvent(o, { detail: e.detail }));
287
+ }, Me = (e, t, n) => t(e).subscribe({
288
+ next: (e) => n.next(e),
289
+ error: (e) => {
290
+ Q(e), n.error(e);
291
+ },
292
+ complete: () => n.complete()
293
+ }), Ne = ne(({ error: e, operation: t, forward: n }) => {
294
+ if (l(e)) {
295
+ Q(e);
296
+ return;
297
+ }
258
298
  let r = e.errors;
259
299
  if (r) {
260
300
  let i = r.some((e) => e.extensions?.code === "UNAUTHENTICATED" || e.message.includes("Unauthorized") || e.message.includes("Unauthenticated"));
261
- for (let e of r) R && console.error("[GraphQL Error]:", e.message);
262
- i && P || a({ errors: r }, { operationName: t.operationName });
263
- let o = new Set(["STORAGE_QUOTA_EXCEEDED", "RESOURCE_CAP_EXCEEDED"]);
301
+ for (let e of r) W && console.error("[GraphQL Error]:", e.message);
302
+ i && B || f({ errors: r }, { operationName: t.operationName });
303
+ let a = new Set(["STORAGE_QUOTA_EXCEEDED", "RESOURCE_CAP_EXCEEDED"]);
264
304
  for (let e of r) {
265
305
  let t = e.extensions?.code;
266
- if (t && o.has(t) && typeof window < "u") {
306
+ if (t && a.has(t) && typeof window < "u") {
267
307
  window.dispatchEvent(new CustomEvent("burdenoff:upgrade-prompt", { detail: { extensions: e.extensions } }));
268
308
  break;
269
309
  }
270
310
  }
271
- if (i && P) return new g((r) => {
311
+ if (i && B) return new y((r) => {
272
312
  (async () => {
273
- if (Z) if (await new Promise((e) => {
274
- Q.push({ resolve: e });
313
+ if (Y) if (await new Promise((e) => {
314
+ X.push({ resolve: e });
275
315
  })) {
276
- let e = n(t).subscribe(r);
316
+ let e = Me(t, n, r);
277
317
  return () => e.unsubscribe();
278
- } else return N?.(), r.error(e), () => {};
279
- Z = !0;
318
+ } else return z?.(), r.error(e), () => {};
319
+ Y = !0;
280
320
  try {
281
- let i = await P();
282
- if (Z = !1, i) {
283
- $(!0);
284
- let e = n(t).subscribe(r);
321
+ let i = await B();
322
+ if (Y = !1, i) {
323
+ Z(!0);
324
+ let e = Me(t, n, r);
285
325
  return () => e.unsubscribe();
286
- } else return $(!1), N?.(), r.error(e), () => {};
326
+ } else return Z(!1), z?.(), r.error(e), () => {};
287
327
  } catch {
288
- return Z = !1, $(!1), N?.(), r.error(e), () => {};
328
+ return Y = !1, Z(!1), z?.(), r.error(e), () => {};
289
329
  }
290
330
  })();
291
331
  });
292
- i && N?.(), w();
332
+ i && z?.(), O();
293
333
  } else {
294
- if (R && console.error("[Network Error]:", e), ae(e)) {
295
- w(), e instanceof Error && a(e, {
334
+ if (W && console.error("[Network Error]:", e), se(e)) {
335
+ O(), e instanceof Error && f(e, {
296
336
  operationName: t.operationName,
297
337
  fallbackMessage: "Your session is no longer valid. Please sign in again."
298
338
  });
299
339
  return;
300
340
  }
301
- if (ne() && I?.(!0), e instanceof Error) F?.(e), a(e, {
341
+ if (ae() && H?.(!0), e instanceof Error) V?.(e), f(e, {
302
342
  operationName: t.operationName,
303
343
  fallbackMessage: "We could not reach the server. Please check your connection and try again."
304
344
  });
305
345
  else {
306
346
  let n = Error(String(e));
307
- F?.(n), a(n, {
347
+ V?.(n), f(n, {
308
348
  operationName: t.operationName,
309
349
  fallbackMessage: "We could not reach the server. Please check your connection and try again."
310
350
  });
311
351
  }
312
352
  }
313
- }), be = new h((e, t) => {
314
- let n = ce(e.query), r = n && e.getContext().autoRefreshAfterMutation !== !1 && e.getContext().skipMutationAutoRefresh !== !0;
315
- return new g((i) => {
353
+ }), Pe = new v((e, t) => {
354
+ let n = ue(e.query), r = n && e.getContext().autoRefreshAfterMutation !== !1 && e.getContext().skipMutationAutoRefresh !== !0;
355
+ return new y((i) => {
316
356
  let a = t(e).subscribe({
317
357
  next: (t) => {
318
- if (i.next(t), le(t) || (n && s(), !r)) return;
358
+ if (i.next(t), de(t) || (n && m(), !r)) return;
319
359
  let a = e.operationName || "anonymous mutation";
320
- L ? Promise.resolve(L({
321
- gateway: o,
360
+ U ? Promise.resolve(U({
361
+ gateway: p,
322
362
  operationName: a
323
363
  })).catch((e) => {
324
- R && console.warn("[GraphQL] Mutation refresh callback failed:", {
325
- gateway: o,
364
+ W && console.warn("[GraphQL] Mutation refresh callback failed:", {
365
+ gateway: p,
326
366
  operationName: a,
327
367
  error: e
328
368
  });
329
- }) : me(a);
369
+ }) : ge(a);
330
370
  },
331
371
  error: (e) => {
332
372
  i.error(e);
@@ -339,54 +379,54 @@ function A(e) {
339
379
  a.unsubscribe();
340
380
  };
341
381
  });
342
- }), xe = te([
343
- _e,
344
- ve,
345
- ye,
382
+ }), $ = b([
383
+ Ae,
384
+ je,
385
+ Ne,
386
+ Pe,
346
387
  be,
347
- U,
348
- X,
349
- K,
350
- q,
351
- J,
352
- Y,
353
- ge,
354
- W,
355
- G,
356
- _(({ query: e }) => {
357
- let t = v(e);
388
+ ke,
389
+ Ce,
390
+ we,
391
+ Te,
392
+ Ee,
393
+ De,
394
+ xe,
395
+ Se,
396
+ x(({ query: e }) => {
397
+ let t = S(e);
358
398
  return t.kind === "OperationDefinition" && t.operation === "subscription";
359
- }, new h((e) => new g((t) => {
399
+ }, new v((e) => new y((t) => {
360
400
  t.error(/* @__PURE__ */ Error(`[graphql] Refusing to send subscription "${e.operationName ?? "anonymous"}" over the batched HTTP transport — this gateway client was created without enableSubscriptions/SSE. Enable subscriptions on this client so it routes over SSE.`));
361
- })), he)
401
+ })), ye)
362
402
  ]);
363
- if (j) {
364
- let e = V.sse, t = M || (e ? r(c || V.defaultBaseUrl) + e : void 0);
365
- t && (xe = te([
366
- _e,
367
- ve,
368
- ye,
403
+ if (L) {
404
+ let e = _e.sse, t = R || (e ? r(h || _e.defaultBaseUrl) + e : void 0);
405
+ t && ($ = b([
406
+ Ae,
407
+ je,
408
+ Ne,
409
+ Pe,
369
410
  be,
370
- U,
371
- X,
372
- K,
373
- q,
374
- J,
375
- Y,
376
- ge,
377
- W,
378
- G,
379
- _(({ query: e }) => {
380
- let t = v(e);
411
+ ke,
412
+ Ce,
413
+ we,
414
+ Te,
415
+ Ee,
416
+ De,
417
+ xe,
418
+ Se,
419
+ x(({ query: e }) => {
420
+ let t = S(e);
381
421
  return t.kind === "OperationDefinition" && t.operation === "subscription";
382
- }, new u({
422
+ }, new te({
383
423
  url: t,
384
424
  headers: {},
385
- debug: R
386
- }), he)
425
+ debug: W
426
+ }), ye)
387
427
  ]));
388
428
  }
389
- let Se = new ee({ typePolicies: {
429
+ let Fe = new ie({ typePolicies: {
390
430
  File: { keyFields: ["id"] },
391
431
  Folder: { keyFields: ["id"] },
392
432
  Tag: { keyFields: ["id"] },
@@ -421,9 +461,9 @@ function A(e) {
421
461
  VibecontrolsAgent: { keyFields: ["id"] },
422
462
  Query: { fields: { vibes: { keyArgs: ["filter"] } } }
423
463
  } });
424
- return z = new m({
425
- link: xe,
426
- cache: A ?? Se,
464
+ return K = new re({
465
+ link: $,
466
+ cache: I ?? Fe,
427
467
  defaultOptions: {
428
468
  watchQuery: {
429
469
  fetchPolicy: "cache-and-network",
@@ -435,19 +475,19 @@ function A(e) {
435
475
  },
436
476
  mutate: { errorPolicy: "all" }
437
477
  }
438
- }), z;
478
+ }), K;
439
479
  }
440
- var j = null, M = null;
441
- function N(e) {
480
+ var L = null, R = null;
481
+ function z(e) {
442
482
  let { workspaceBaseUrl: t, globalBaseUrl: n, authToken: r, enableSubscriptions: i = !1, onAuthError: a, debug: o = !1 } = e;
443
- j = A({
483
+ L = I({
444
484
  gateway: "workspace",
445
485
  baseUrl: t,
446
486
  authToken: r,
447
487
  enableSubscriptions: i,
448
488
  onAuthError: a,
449
489
  debug: o
450
- }), M = A({
490
+ }), R = I({
451
491
  gateway: "global",
452
492
  baseUrl: n,
453
493
  authToken: r,
@@ -455,16 +495,16 @@ function N(e) {
455
495
  debug: o
456
496
  });
457
497
  }
458
- function P() {
459
- if (!j) throw Error("Workspace client not initialized. Call initializeAppClients first.");
460
- return j;
498
+ function B() {
499
+ if (!L) throw Error("Workspace client not initialized. Call initializeAppClients first.");
500
+ return L;
461
501
  }
462
- function F() {
463
- if (!M) throw Error("Global client not initialized. Call initializeAppClients first.");
464
- return M;
502
+ function V() {
503
+ if (!R) throw Error("Global client not initialized. Call initializeAppClients first.");
504
+ return R;
465
505
  }
466
- function I() {
467
- j &&= (j.clearStore(), null), M &&= (M.clearStore(), null);
506
+ function H() {
507
+ L &&= (L.clearStore(), null), R &&= (R.clearStore(), null);
468
508
  }
469
509
  //#endregion
470
- export { A as createGraphQLClient, F as getGlobalClient, P as getWorkspaceClient, N as initializeAppClients, I as resetAppClients };
510
+ export { I as createGraphQLClient, V as getGlobalClient, B as getWorkspaceClient, z as initializeAppClients, H as resetAppClients };