@burdenoff/fe-libs 2026.1114.5 → 2026.1114.7

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.
@@ -26,6 +26,12 @@ export interface GraphQLBackendErrorLike {
26
26
  }
27
27
  export interface BackendErrorDisplay {
28
28
  message: string;
29
+ /**
30
+ * i18n key for `message`, when the message came from fe-libs' own copy (the
31
+ * gateway auth-failure table below). The toast resolves it through the shell
32
+ * dictionary and falls back to `message`, the English (BOFF-10107).
33
+ */
34
+ messageKey?: string;
29
35
  subtitle?: string;
30
36
  technicalMessage?: string;
31
37
  code?: string;
@@ -39,6 +45,18 @@ export interface ExtractBackendErrorOptions {
39
45
  operationName?: string;
40
46
  fallbackMessage?: string;
41
47
  }
48
+ /** A message fe-libs owns: an i18n key and its English. */
49
+ export interface BackendErrorCopy {
50
+ readonly key: string;
51
+ readonly english: string;
52
+ }
53
+ export declare const AUTH_FAILURE_COPY: Readonly<Record<string, BackendErrorCopy>>;
54
+ /** Every message key the backend-error toast can resolve, for the shell label seed. */
55
+ export declare const BACKEND_ERROR_COPY: readonly BackendErrorCopy[];
56
+ /** True when fe-libs knows what this gateway `authFailure` class means. */
57
+ export declare function isKnownAuthFailure(value: string): boolean;
58
+ /** Test hook: forget which unmapped classes were already reported. */
59
+ export declare function resetUnmappedAuthFailureReportsForTests(): void;
42
60
  /** AbortError in either form — a user/navigation cancellation, never surfaced. */
43
61
  export declare function isAbortError(input: unknown): boolean;
44
62
  /**
@@ -23,15 +23,58 @@ var e = "burdenoff:backend-error", t = "burdenoff:connection-status", n = "Somet
23
23
  RBAC_SERVICE_UNAVAILABLE: "We couldn't verify your access just now. Please try again in a moment.",
24
24
  DOWNSTREAM_SERVICE_ERROR: "A service is temporarily unavailable. Please try again in a moment."
25
25
  }, i = {
26
- UNAUTHENTICATED_ACTOR: "Your session has expired. Please sign in again.",
27
- WORKSPACE_SESSION_UNRESOLVED: "Your workspace session has expired. Refresh the page to continue.",
28
- WORKSPACE_CONTEXT_MISSING: "Please choose a workspace and try again."
26
+ key: "backendErrors.generic",
27
+ english: n
28
+ }, a = Object.freeze({
29
+ UNAUTHENTICATED_ACTOR: {
30
+ key: "backendErrors.sessionExpired",
31
+ english: "Your session has expired. Please sign in again."
32
+ },
33
+ WORKSPACE_SESSION_UNRESOLVED: {
34
+ key: "backendErrors.workspaceSessionExpired",
35
+ english: "Your workspace session has expired. Refresh the page to continue."
36
+ },
37
+ WORKSPACE_CONTEXT_MISSING: {
38
+ key: "backendErrors.chooseWorkspace",
39
+ english: "Please choose a workspace and try again."
40
+ },
41
+ CREDENTIAL_EXPIRED: {
42
+ key: "backendErrors.sessionExpired",
43
+ english: "Your session has expired. Please sign in again."
44
+ },
45
+ CREDENTIAL_REVOKED: {
46
+ key: "backendErrors.signedOut",
47
+ english: "You were signed out. Please sign in again."
48
+ },
49
+ CREDENTIAL_INVALID: {
50
+ key: "backendErrors.sessionInvalid",
51
+ english: "Your session is no longer valid. Please sign in again."
52
+ },
53
+ AUTH_SERVICE_UNAVAILABLE: {
54
+ key: "backendErrors.accessCheckUnavailable",
55
+ english: "We couldn't verify your access just now. Please try again in a moment."
56
+ }
57
+ });
58
+ Object.freeze([i, ...Object.values(a).filter((e, t, n) => n.findIndex((t) => t.key === e.key) === t)]);
59
+ function o(e) {
60
+ return Object.prototype.hasOwnProperty.call(a, e);
61
+ }
62
+ var s = /* @__PURE__ */ new Set(), c = class extends Error {
63
+ constructor(e) {
64
+ super(`Unmapped gateway authFailure: ${e}`), this.name = "UnmappedAuthFailureError";
65
+ }
29
66
  };
30
- function a(e) {
67
+ function l(e) {
68
+ if (s.has(e)) return;
69
+ s.add(e), console.warn("[Burdenoff backend error] The gateway sent an authFailure class this app does not know; showing the neutral message. Add it to AUTH_FAILURE_COPY in fe-libs backendErrors.ts.", { authFailure: e });
70
+ let t = new c(e);
71
+ import("../providers/shell/crashReporting.js").then(({ reportError: e }) => e(t)).catch(() => void 0);
72
+ }
73
+ function u(e) {
31
74
  let t = e?.authFailure;
32
- if (typeof t == "string") return i[t];
75
+ if (typeof t == "string" && t.trim().length !== 0) return o(t) ? a[t] : (l(t), i);
33
76
  }
34
- var o = [
77
+ var d = [
35
78
  /^Syntax Error:/i,
36
79
  /^Cannot query field\b/i,
37
80
  /^Cannot return null for non-nullable field\b/i,
@@ -43,124 +86,124 @@ var o = [
43
86
  /^Fragment "[^"]+" cannot be spread here/i,
44
87
  /^There can be only one/i,
45
88
  /Did you mean /i
46
- ], s = /* @__PURE__ */ new Set([
89
+ ], f = /* @__PURE__ */ new Set([
47
90
  "UNAUTHENTICATED",
48
91
  "TOKEN_EXPIRED",
49
92
  "RESOURCE_CAP_EXCEEDED",
50
93
  "STORAGE_QUOTA_EXCEEDED",
51
94
  "QUOTA_EXHAUSTED"
52
- ]), c = /* @__PURE__ */ new Set([
95
+ ]), p = /* @__PURE__ */ new Set([
53
96
  "ExportTranslations",
54
97
  "exportTranslations",
55
98
  "AdminEntityCounts",
56
99
  "GetTenants",
57
100
  "NodeManifest"
58
- ]), l = ["exportTranslations"], u = ["No translation keys found for the specified criteria"], d = [
101
+ ]), m = ["exportTranslations"], h = ["No translation keys found for the specified criteria"], g = [
59
102
  /failed to fetch/i,
60
103
  /networkerror when attempting to fetch/i,
61
104
  /network request failed/i,
62
105
  /the network connection was lost/i,
63
106
  /\bECONNREFUSED\b|\bECONNRESET\b|\bETIMEDOUT\b|\bENOTFOUND\b|\bEAI_AGAIN\b|\bEHOSTUNREACH\b|\bENETUNREACH\b/i,
64
107
  /network circuit breaker is open/i
65
- ], f = [
108
+ ], _ = [
66
109
  "We could not reach the server. Please check your connection and try again.",
67
110
  "The server is having trouble right now. Please try again in a moment.",
68
111
  "The server took too long to respond. Please try again."
69
- ], p = [
112
+ ], v = [
70
113
  /\bunauthori[sz]ed\b|\bunauthenticated\b|\btoken[\s_-]?expired\b|\b401\b|\b403\b/i,
71
114
  /invalid email or password/i,
72
115
  /you do not have permission/i
73
116
  ];
74
- function m(e) {
117
+ function y(e) {
75
118
  return typeof e == "object" && !!e && !Array.isArray(e);
76
119
  }
77
- function h(e) {
120
+ function b(e) {
78
121
  if (!e) return !1;
79
122
  let t = e.trim();
80
- return t.length === 0 || p.some((e) => e.test(t)) ? !1 : f.includes(t) || t.toLowerCase() === "load failed" ? !0 : d.some((e) => e.test(t));
123
+ return t.length === 0 || v.some((e) => e.test(t)) ? !1 : _.includes(t) || t.toLowerCase() === "load failed" ? !0 : g.some((e) => e.test(t));
81
124
  }
82
- function g(e) {
83
- return !!(e instanceof DOMException && e.name === "AbortError" || e instanceof Error && e.name === "AbortError" || m(e) && e.name === "AbortError");
125
+ function x(e) {
126
+ return !!(e instanceof DOMException && e.name === "AbortError" || e instanceof Error && e.name === "AbortError" || y(e) && e.name === "AbortError");
84
127
  }
85
- function _(e) {
128
+ function S(e) {
86
129
  if (typeof e == "string") return e;
87
130
  if (e instanceof Error) return e.message;
88
- if (m(e)) {
89
- let t = T(e, "message");
131
+ if (y(e)) {
132
+ let t = A(e, "message");
90
133
  if (t) return t;
91
- let n = D(e);
134
+ let n = M(e);
92
135
  if (n && n.length > 0 && typeof n[0]?.message == "string") return n[0].message ?? void 0;
93
136
  let r = e.networkError;
94
- if (m(r)) return T(r, "message");
137
+ if (y(r)) return A(r, "message");
95
138
  }
96
139
  }
97
- function v(e) {
98
- if (!m(e)) return;
140
+ function C(e) {
141
+ if (!y(e)) return;
99
142
  let t = e.statusCode ?? e.status;
100
143
  if (typeof t == "number") return t;
101
144
  let n = e.networkError;
102
- if (m(n)) {
145
+ if (y(n)) {
103
146
  let e = n.statusCode ?? n.status;
104
147
  if (typeof e == "number") return e;
105
148
  }
106
149
  }
107
- function y(e) {
108
- if (e == null || g(e)) return !1;
109
- let t = O(e);
110
- if (E(t?.extensions?.code ?? t?.extensions?.errorCode)) return !1;
111
- let n = v(e);
112
- return n === 401 || n === 403 ? !1 : typeof navigator < "u" && navigator.onLine === !1 || e instanceof TypeError && h(e.message) ? !0 : h(_(e));
113
- }
114
- var b = 1e4, x = 0, S = !1;
115
- function C(e, n) {
116
- let r = Date.now(), i = _(e) ?? "Network request failed", a = typeof navigator > "u" || navigator.onLine;
117
- r - x > b && (x = r, console.warn("[Burdenoff network] request could not reach the server", {
150
+ function w(e) {
151
+ if (e == null || x(e)) return !1;
152
+ let t = N(e);
153
+ if (j(t?.extensions?.code ?? t?.extensions?.errorCode)) return !1;
154
+ let n = C(e);
155
+ return n === 401 || n === 403 ? !1 : typeof navigator < "u" && navigator.onLine === !1 || e instanceof TypeError && b(e.message) ? !0 : b(S(e));
156
+ }
157
+ var T = 1e4, E = 0, D = !1;
158
+ function O(e, n) {
159
+ let r = Date.now(), i = S(e) ?? "Network request failed", a = typeof navigator > "u" || navigator.onLine;
160
+ r - E > T && (E = r, console.warn("[Burdenoff network] request could not reach the server", {
118
161
  message: i,
119
162
  operationName: n.operationName,
120
163
  online: a
121
- })), typeof window < "u" && !S && (S = !0, window.dispatchEvent(new CustomEvent(t, { detail: {
164
+ })), typeof window < "u" && !D && (D = !0, window.dispatchEvent(new CustomEvent(t, { detail: {
122
165
  online: !1,
123
166
  since: r
124
167
  } })));
125
168
  }
126
- function w() {
127
- typeof window < "u" && (S && (S = !1, x = 0), window.dispatchEvent(new CustomEvent(t, { detail: {
169
+ function k() {
170
+ typeof window < "u" && (D && (D = !1, E = 0), window.dispatchEvent(new CustomEvent(t, { detail: {
128
171
  online: !0,
129
172
  since: Date.now()
130
173
  } })));
131
174
  }
132
- function T(e, t) {
175
+ function A(e, t) {
133
176
  let n = e[t];
134
177
  return typeof n == "string" && n.trim().length > 0 ? n : void 0;
135
178
  }
136
- function E(e) {
179
+ function j(e) {
137
180
  if (typeof e == "string" && e.trim().length !== 0) return e.trim().replace(/[\s-]+/g, "_").toUpperCase();
138
181
  }
139
- function D(e) {
140
- if (!m(e)) return;
182
+ function M(e) {
183
+ if (!y(e)) return;
141
184
  let t = e.errors;
142
185
  if (Array.isArray(t)) return t;
143
186
  let n = e.graphQLErrors;
144
187
  if (Array.isArray(n)) return n;
145
188
  let r = e.networkError;
146
- if (m(r)) {
189
+ if (y(r)) {
147
190
  let e = r.result;
148
- if (m(e) && Array.isArray(e.errors)) return e.errors;
191
+ if (y(e) && Array.isArray(e.errors)) return e.errors;
149
192
  }
150
193
  }
151
- function O(e) {
152
- let t = D(e);
194
+ function N(e) {
195
+ let t = M(e);
153
196
  if (t && t.length > 0) return t[0];
154
- if (m(e) && ("message" in e || "extensions" in e)) return e;
197
+ if (y(e) && ("message" in e || "extensions" in e)) return e;
155
198
  }
156
- function k(e) {
199
+ function P(e) {
157
200
  if (e) return e.userMessage ?? e.humanMessage ?? e.displayMessage;
158
201
  }
159
- function A(e) {
160
- return e.length > 220 || e.includes("\n") || o.some((t) => t.test(e)) || /\b(prisma|sql|constraint|undefined|null|ECONN[A-Z_]*|ETIMEDOUT|ENOTFOUND)\b/i.test(e) || /failed to fetch|network error|graphql fetch failed/i.test(e) || /socket connection was closed|pass `?verbose: true`?/i.test(e) || /^HTTP error!?\s*(status)?:?\s*\d{3}\b/i.test(e) || /Cannot (read|set|find|access|query)/i.test(e);
202
+ function F(e) {
203
+ return e.length > 220 || e.includes("\n") || d.some((t) => t.test(e)) || /\b(prisma|sql|constraint|undefined|null|ECONN[A-Z_]*|ETIMEDOUT|ENOTFOUND)\b/i.test(e) || /failed to fetch|network error|graphql fetch failed/i.test(e) || /socket connection was closed|pass `?verbose: true`?/i.test(e) || /^HTTP error!?\s*(status)?:?\s*\d{3}\b/i.test(e) || /Cannot (read|set|find|access|query)/i.test(e);
161
204
  }
162
- function j(e) {
163
- if (o.some((t) => t.test(e))) return "BAD_USER_INPUT";
205
+ function I(e) {
206
+ if (d.some((t) => t.test(e))) return "BAD_USER_INPUT";
164
207
  let t = e.toLowerCase();
165
208
  if (t.includes("unauthenticated") || t.includes("unauthorized")) return "UNAUTHENTICATED";
166
209
  if (t.includes("workspace context")) return "WORKSPACE_REQUIRED";
@@ -169,25 +212,29 @@ function j(e) {
169
212
  if (t.includes("quota") || t.includes("limit reached")) return "QUOTA_EXCEEDED";
170
213
  if (t.includes("required") || t.includes("invalid") || t.includes("missing")) return "BAD_USER_INPUT";
171
214
  }
172
- function M(e, t, i, o) {
173
- let s = k(e?.extensions ?? void 0);
174
- if (s) return s;
175
- let c = a(e?.extensions ?? void 0);
176
- if (c) return c;
177
- if (t && r[t]) return r[t];
178
- if (i) return i;
179
- let l = e ? void 0 : o;
180
- return l && !A(l) ? l : e?.message && !A(e.message) ? e.message : i ?? n;
215
+ function L(e, t, i, a) {
216
+ let o = P(e?.extensions ?? void 0);
217
+ if (o) return { message: o };
218
+ let s = u(e?.extensions ?? void 0);
219
+ if (s) return {
220
+ message: s.english,
221
+ messageKey: s.key
222
+ };
223
+ if (t && r[t]) return { message: r[t] };
224
+ if (i) return { message: i };
225
+ let c = e ? void 0 : a;
226
+ return c && !F(c) ? { message: c } : e?.message && !F(e.message) ? { message: e.message } : { message: n };
181
227
  }
182
- function N(e) {
228
+ function R(e) {
183
229
  if (e && e.length !== 0) return e.map((e) => String(e)).join(".");
184
230
  }
185
- function P(e, t = {}) {
231
+ function z(e, t = {}) {
186
232
  if (e == null) return null;
187
- let n = O(e), r = n?.extensions ?? void 0, i = e instanceof Error ? e.message : m(e) ? T(e, "message") : void 0, a = E(r?.code ?? r?.errorCode) ?? j(i ?? n?.message ?? ""), o = r?.serviceName, s = N(n?.path), c = r?.requestId ?? r?.correlationId ?? r?.traceId, l = M(n, a, t.fallbackMessage, i);
233
+ let n = N(e), r = n?.extensions ?? void 0, i = e instanceof Error ? e.message : y(e) ? A(e, "message") : void 0, a = j(r?.code ?? r?.errorCode) ?? I(i ?? n?.message ?? ""), o = r?.serviceName, s = R(n?.path), c = r?.requestId ?? r?.correlationId ?? r?.traceId, { message: l, messageKey: u } = L(n, a, t.fallbackMessage, i), d = r?.technicalMessage ?? (n?.message && n.message !== l ? n.message : void 0) ?? (i && i !== l ? i : void 0);
188
234
  return {
189
235
  message: l,
190
- technicalMessage: r?.technicalMessage ?? (n?.message && n.message !== l ? n.message : void 0) ?? (i && i !== l ? i : void 0),
236
+ ...u ? { messageKey: u } : {},
237
+ technicalMessage: d,
191
238
  code: a,
192
239
  operationName: t.operationName,
193
240
  serviceName: o,
@@ -196,30 +243,30 @@ function P(e, t = {}) {
196
243
  extensions: r
197
244
  };
198
245
  }
199
- function F(e) {
200
- return m(e) && typeof e.message == "string";
246
+ function B(e) {
247
+ return y(e) && typeof e.message == "string";
201
248
  }
202
- var I = /* @__PURE__ */ new Set(["RBAC_SERVICE_UNAVAILABLE", "AUTH_SERVICE_UNAVAILABLE"]), L = 4e3, R = 3e4;
203
- function z(e) {
249
+ var V = /* @__PURE__ */ new Set(["RBAC_SERVICE_UNAVAILABLE", "AUTH_SERVICE_UNAVAILABLE"]), H = 4e3, U = 3e4;
250
+ function W(e) {
204
251
  let t = e.code ?? "";
205
- return I.has(t) ? {
252
+ return V.has(t) ? {
206
253
  key: t,
207
- windowMs: R
254
+ windowMs: U
208
255
  } : {
209
256
  key: `${t}|${e.message}`,
210
- windowMs: L
257
+ windowMs: H
211
258
  };
212
259
  }
213
- function B(e) {
214
- return !e || e.code && s.has(e.code) || e.operationName && c.has(e.operationName) || e.path && l.some((t) => e.path === t || e.path?.startsWith(`${t}.`)) || e.technicalMessage && u.some((t) => e.technicalMessage.includes(t)) || !e.code && h(e.technicalMessage ?? e.message) ? !1 : e.message.trim().length > 0;
260
+ function G(e) {
261
+ return !e || e.code && f.has(e.code) || e.operationName && p.has(e.operationName) || e.path && m.some((t) => e.path === t || e.path?.startsWith(`${t}.`)) || e.technicalMessage && h.some((t) => e.technicalMessage.includes(t)) || !e.code && b(e.technicalMessage ?? e.message) ? !1 : e.message.trim().length > 0;
215
262
  }
216
- function V(t, n = {}) {
217
- if (typeof window > "u" || g(t)) return;
218
- if (y(t)) {
219
- C(t, n);
263
+ function K(t, n = {}) {
264
+ if (typeof window > "u" || x(t)) return;
265
+ if (w(t)) {
266
+ O(t, n);
220
267
  return;
221
268
  }
222
- let r = F(t) ? t : P(t, n);
223
- B(r) && window.dispatchEvent(new CustomEvent(e, { detail: r }));
269
+ let r = B(t) ? t : z(t, n);
270
+ G(r) && window.dispatchEvent(new CustomEvent(e, { detail: r }));
224
271
  }
225
- export { e as BACKEND_ERROR_EVENT, t as CONNECTION_STATUS_EVENT, V as dispatchBackendErrorEvent, P as extractBackendError, z as getBackendErrorToastDedupe, g as isAbortError, F as isBackendErrorDisplay, y as isTransportError, w as markConnectionHealthy, B as shouldToastBackendError };
272
+ export { a as AUTH_FAILURE_COPY, e as BACKEND_ERROR_EVENT, t as CONNECTION_STATUS_EVENT, K as dispatchBackendErrorEvent, z as extractBackendError, W as getBackendErrorToastDedupe, x as isAbortError, B as isBackendErrorDisplay, o as isKnownAuthFailure, w as isTransportError, k as markConnectionHealthy, G as shouldToastBackendError };