@nivaro/react 0.3.46 → 0.3.48

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 (57) hide show
  1. package/dist/full.css +1 -1
  2. package/dist/hooks/useSessionRecorder.js +1 -1
  3. package/dist/index.d.ts +248 -16
  4. package/dist/index.js +679 -659
  5. package/dist/shared/components/CollectionBrowserView.js +813 -826
  6. package/dist/shared/components/ErrorNotice.js +169 -0
  7. package/dist/shared/components/ErrorSurface.js +23 -17
  8. package/dist/shared/components/ListLoadError.js +8 -29
  9. package/dist/shared/components/LoadErrorNote.js +38 -21
  10. package/dist/shared/components/QueryErrorState.js +8 -11
  11. package/dist/shared/components/ReportView.js +1320 -1291
  12. package/dist/shared/components/chat/ChannelArchive.js +60 -60
  13. package/dist/shared/components/chat/ChannelExtras.js +74 -74
  14. package/dist/shared/components/chat/ChatPanel.js +368 -367
  15. package/dist/shared/components/command-center/PeekPanel.js +33 -32
  16. package/dist/shared/components/command-center/panels/BoardSettings.js +41 -40
  17. package/dist/shared/components/command-center/panels/PeoplePanel.js +32 -31
  18. package/dist/shared/components/help-videos/editor/ClipsPanel.js +49 -48
  19. package/dist/shared/components/help-videos/editor/PublishButton.js +37 -36
  20. package/dist/shared/components/help-videos/editor/StatsTab.js +45 -44
  21. package/dist/shared/components/help-videos/editor/VersionsTab.js +29 -28
  22. package/dist/shared/components/help-videos/library/AuthorRolesButton.js +19 -18
  23. package/dist/shared/components/help-videos/library/HelpVideoLibrary.js +132 -129
  24. package/dist/shared/components/help-videos/library/LearningPathsPanel.js +42 -41
  25. package/dist/shared/components/help-videos/settings/HouseStyleButton.js +21 -20
  26. package/dist/shared/components/help-videos/settings/RenderSettingsButton.js +22 -21
  27. package/dist/shared/components/import/DocumentAutofillButton.js +24 -20
  28. package/dist/shared/components/import/ImportFromFileButton.js +61 -60
  29. package/dist/shared/components/imports/ImportStalenessControl.js +20 -21
  30. package/dist/shared/components/imports/NewImportDialog.js +29 -28
  31. package/dist/shared/components/imports/RunDetailSheet.js +63 -63
  32. package/dist/shared/components/item-edit/FieldRow.js +329 -329
  33. package/dist/shared/components/item-edit/InlineTableField.js +898 -898
  34. package/dist/shared/components/item-edit/PersonalDefaultControl.js +57 -56
  35. package/dist/shared/components/item-edit/PlanGrid.js +220 -221
  36. package/dist/shared/components/item-edit/RecordGrantTools.js +49 -48
  37. package/dist/shared/components/item-edit/placement-behaviour.js +68 -67
  38. package/dist/shared/components/layout-editor/inspector/ColumnFit.js +24 -23
  39. package/dist/shared/components/layout-editor/inspector/PickerPreview.js +17 -16
  40. package/dist/shared/components/layout-editor/matrix/FieldStateMatrix.js +41 -41
  41. package/dist/shared/components/layout-editor/outputs/output-api.js +33 -31
  42. package/dist/shared/components/layout-editor/overview/overview-api.js +84 -83
  43. package/dist/shared/components/layout-editor/useLayoutDraft.js +47 -42
  44. package/dist/shared/components/monitoring/InactiveUserLinksView.js +10 -9
  45. package/dist/shared/components/panels/SlaClock.js +35 -36
  46. package/dist/shared/components/pipeline/PipelineEditorView.js +311 -312
  47. package/dist/shared/components/pipeline/TeamSuggestions.js +31 -30
  48. package/dist/shared/components/profile/AgentsPanel.js +73 -72
  49. package/dist/shared/components/profile/MailSuppressedPill.js +22 -21
  50. package/dist/shared/components/support/SupportRequestDialog.js +85 -81
  51. package/dist/shared/components/support/SupportView.js +94 -87
  52. package/dist/shared/lib/autofill-poll.js +21 -18
  53. package/dist/shared/lib/error-actions.js +85 -0
  54. package/dist/shared/lib/error-message.js +223 -82
  55. package/dist/shared/lib/error-toast.js +71 -13
  56. package/dist/shared/lib/safe-error.js +136 -38
  57. package/package.json +1 -1
@@ -1,105 +1,246 @@
1
- import { fieldsFromBody as w, hintFor as T } from "./error-hints.js";
2
- import { isCodeError as O, SOMETHING_WENT_WRONG as R, userErrorMessage as v, isBareStatusText as h, statusTitle as I, errorStatusOf as S } from "./safe-error.js";
3
- const d = "x-nivaro-request-id", $ = /^[A-Z][A-Z0-9_]{2,}$/, A = /^(ERR_|E[A-Z]+$)/, q = /failed to fetch|load failed|networkerror|network request failed|network error/i, r = (t) => !!t && typeof t == "object" && !Array.isArray(t);
4
- function N(t) {
5
- if (!r(t)) return null;
6
- const n = t.response;
7
- return r(n) ? r(n.data) ? n.data : "data" in n && typeof n.data == "string" ? null : n : r(t.extensions) || !(t instanceof Error) && ("error" in t || "message" in t || "code" in t) ? t : null;
8
- }
9
- function u(t) {
1
+ import { fieldsFromBody as x, hintFor as L } from "./error-hints.js";
2
+ import { isCodeError as y, isRawErrorText as I, plainErrorText as N, STATUS_TITLES as p, errorStatusOf as F, isBareStatusText as D, SOMETHING_WENT_WRONG as U, statusTitle as P } from "./safe-error.js";
3
+ const _ = "x-nivaro-request-id", H = /^[A-Z][A-Z0-9_]{2,}$/, B = /^(ERR_|E[A-Z]+$)/, W = /failed to fetch|load failed|networkerror|network request failed|network error|cannot reach/i, O = "Try again. If it keeps happening, ask for help.", u = {
4
+ retry: { kind: "retry", label: "Try again" },
5
+ signIn: { kind: "sign-in", label: "Sign in again" },
6
+ reload: { kind: "reload", label: "Reload" },
7
+ reloadPage: { kind: "reload", label: "Reload the page" },
8
+ askAccess: { kind: "contact", label: "Ask for access" },
9
+ back: { kind: "go-back", label: "Go back" }
10
+ }, d = (t) => !!t && typeof t == "object" && !Array.isArray(t);
11
+ function j(t) {
12
+ if (!d(t)) return null;
13
+ const e = t.response;
14
+ return d(e) ? d(e.data) ? e.data : "data" in e && typeof e.data == "string" ? null : e : d(t.extensions) || !(t instanceof Error) && ("error" in t || "message" in t || "code" in t) ? t : null;
15
+ }
16
+ function k(t) {
10
17
  return typeof t == "string" && t.trim() ? t.trim() : void 0;
11
18
  }
12
- function x(t, n) {
13
- const e = r(n == null ? void 0 : n.extensions) ? n.extensions : null;
14
- for (const i of [n == null ? void 0 : n.code, e == null ? void 0 : e.code, r(t) ? t.code : void 0])
15
- if (typeof i == "string" && $.test(i) && !A.test(i)) return i;
19
+ function K(t, e) {
20
+ const n = d(e == null ? void 0 : e.extensions) ? e.extensions : null;
21
+ for (const i of [e == null ? void 0 : e.code, n == null ? void 0 : n.code, d(t) ? t.code : void 0])
22
+ if (typeof i == "string" && H.test(i) && !B.test(i)) return i;
16
23
  }
17
- function C(t, n) {
18
- const e = u(n == null ? void 0 : n.request_id) ?? u(n == null ? void 0 : n.requestId);
19
- if (e) return e;
20
- if (!r(t)) return;
21
- const i = u(t.requestId) ?? u(t.request_id);
24
+ function Y(t, e) {
25
+ const n = k(e == null ? void 0 : e.request_id) ?? k(e == null ? void 0 : e.requestId);
26
+ if (n) return n;
27
+ if (!d(t)) return;
28
+ const i = k(t.requestId) ?? k(t.request_id);
22
29
  if (i) return i;
23
- const s = r(t.response) ? t.response.headers : void 0;
24
- if (r(s)) return u(s[d]);
25
- const a = s == null ? void 0 : s.get;
26
- if (typeof a == "function") return u(a.call(s, d));
27
- }
28
- function D(t, n) {
29
- const e = S(t) ?? (n == null ? void 0 : n.statusCode) ?? (n == null ? void 0 : n.status), i = r(n == null ? void 0 : n.extensions) ? n.extensions.status : void 0, s = typeof e == "number" ? e : typeof i == "number" ? i : void 0;
30
- return s && s >= 100 && s < 600 ? s : void 0;
31
- }
32
- function _(t) {
33
- for (const n of ["error", "message"]) {
34
- const e = u(t[n]);
35
- if (e && !h(e)) return e;
30
+ const r = d(t.response) ? t.response.headers : void 0;
31
+ if (d(r)) {
32
+ const m = r.get;
33
+ return k(typeof m == "function" ? m.call(r, _) : r[_]);
36
34
  }
37
35
  }
38
- function k(t) {
39
- return r(t) ? t.name === "TimeoutError" || t.code === "ECONNABORTED" || t.code === "ETIMEDOUT" || /timed out|timeout of \d+ms exceeded/i.test(String(t.message ?? "")) : !1;
40
- }
41
- function p(t, n = "Something went wrong") {
42
- const e = N(t), i = D(t, e), s = x(t, e), a = C(t, e), o = { title: n };
43
- if (i && (o.status = i), s && (o.code = s), a && (o.requestId = a), O(t))
44
- return o.title = R, o;
45
- const g = r(t) ? String(t.message ?? "") : typeof t == "string" ? t : "";
46
- if (!i && !e && q.test(g))
47
- return o.title = "Cannot reach the server", o.hint = "Check your connection, then try again.", o;
48
- if (!i && k(t))
49
- return o.title = "The server took too long to answer", o.hint = "Try again in a minute. Narrow the request if it keeps happening.", o;
50
- const c = (e ? _(e) : void 0) ?? v(t, "");
51
- o.title = c && !h(c) ? c : I(i) ?? (c || n), o.title || (o.title = n);
52
- const m = u(e == null ? void 0 : e.hint) ?? u(e == null ? void 0 : e.explanation), E = i || s ? T(s, i ?? 400) : void 0, f = m ?? E;
53
- f && f !== o.title && (o.hint = f);
54
- const l = e ? w(e) : [];
55
- return l.length && (o.fields = l), o;
56
- }
57
- function F(t, n = {}) {
58
- var a;
59
- const e = U(t) ? t : p(t), i = n.page ?? (typeof window < "u" && window.location ? window.location.pathname : void 0);
36
+ function G(t, e) {
37
+ const n = F(t) ?? (e == null ? void 0 : e.statusCode) ?? (e == null ? void 0 : e.status), i = d(e == null ? void 0 : e.extensions) ? e.extensions.status : void 0, r = typeof n == "number" ? n : typeof i == "number" ? i : void 0;
38
+ return r && r >= 100 && r < 600 ? r : void 0;
39
+ }
40
+ function M(t) {
41
+ for (const e of ["error", "message"]) {
42
+ const n = k(t[e]);
43
+ if (n && !D(n)) return n;
44
+ }
45
+ }
46
+ function Z(t) {
47
+ return d(t) ? t.name === "TimeoutError" || t.code === "ECONNABORTED" || t.code === "ETIMEDOUT" || /timed out|timeout of \d+ms exceeded|took too long/i.test(String(t.message ?? "")) : !1;
48
+ }
49
+ function Q() {
50
+ return typeof navigator < "u" && navigator.onLine === !1;
51
+ }
52
+ function V(t, e, n) {
53
+ return t === 500 && !!e && typeof e.statusCode == "number" && !n;
54
+ }
55
+ function z(t, e) {
56
+ const n = typeof e == "function" ? e(t) : e == null ? void 0 : e[t];
57
+ if (n) return n;
58
+ const r = (t.split(".").filter((m) => !/^\d+$/.test(m)).pop() ?? t).replace(/([a-z])([A-Z])/g, "$1 $2").replace(/[_$]+/g, " ").replace(/\s+/g, " ").trim().toLowerCase();
59
+ return r ? r[0].toUpperCase() + r.slice(1) : t;
60
+ }
61
+ function J(t, e) {
62
+ const n = [...new Set(t.map((r) => z(r, e)))], i = n.length > 4 ? [...n.slice(0, 3), `${n.length - 3} more`] : n;
63
+ return i.length < 2 ? i[0] ?? "" : `${i.slice(0, -1).join(", ")} and ${i[i.length - 1]}`;
64
+ }
65
+ function X(t, e = 500) {
66
+ return t.length > e ? `${t.slice(0, e - 1)}…` : t;
67
+ }
68
+ function R(t, e = "Something went wrong", n = {}) {
69
+ const i = j(t), r = d(t) && typeof t.message == "string" ? t.message : void 0, m = d(t) && t.status === 0, o = G(t, i), h = K(t, i), S = Y(t, i), E = { title: e };
70
+ o && (E.status = o), h && (E.code = h), S && (E.requestId = S);
71
+ const T = (s) => {
72
+ const w = [
73
+ i ? k(i.message) : void 0,
74
+ i ? k(i.error) : void 0,
75
+ r,
76
+ typeof t == "string" ? t : ""
77
+ ].filter((g) => !!(g != null && g.trim()) && !D(g)).find((g) => I(g) || !!o && o >= 500 && g !== s.title);
78
+ return w && w !== s.title && (s.technical = X(w.trim())), I(s.title) && (s.title = N(s.title, e, o)), s.hint && (I(s.hint) || s.title.includes(s.hint)) && delete s.hint, s;
79
+ };
80
+ if (y(t))
81
+ return T({
82
+ ...E,
83
+ kind: "bug",
84
+ title: U,
85
+ hint: "Try again. If it keeps happening, reload the page.",
86
+ action: u.reloadPage
87
+ });
88
+ const $ = r ?? (typeof t == "string" ? t : "");
89
+ if (!o && !h) {
90
+ if (Z(t))
91
+ return T({
92
+ ...E,
93
+ kind: "timeout",
94
+ title: "The server took too long to answer",
95
+ hint: "Try again in a minute. If it keeps happening, ask for less at once.",
96
+ action: u.retry
97
+ });
98
+ if (Q() && (m || !i))
99
+ return T({
100
+ ...E,
101
+ kind: "offline",
102
+ title: "You’re offline",
103
+ hint: "Check your internet connection, then try again. Nothing you entered is lost.",
104
+ action: u.retry
105
+ });
106
+ if (m || !i && W.test($))
107
+ return T({
108
+ ...E,
109
+ kind: "network",
110
+ title: "Cannot reach the server",
111
+ hint: "Check your connection, then try again.",
112
+ action: u.retry
113
+ });
114
+ }
115
+ const A = (i ? M(i) : void 0) ?? (r && !i ? r : void 0), l = A && !I(A) && !V(o, i, h) ? A.trim() : void 0, a = k(i == null ? void 0 : i.hint) ?? k(i == null ? void 0 : i.explanation), c = o || h ? L(h, o ?? 400) : void 0, v = i ? x(i) : [];
116
+ v.length && (E.fields = v);
117
+ const f = (s, w, g, C) => T({
118
+ ...E,
119
+ kind: w,
120
+ title: s,
121
+ ...g ? { hint: g } : {},
122
+ ...C ? { action: C } : {}
123
+ });
124
+ if (h === "MAINTENANCE")
125
+ return f(
126
+ l ?? "The system is down for maintenance",
127
+ "maintenance",
128
+ a ?? c,
129
+ u.reload
130
+ );
131
+ if (o === 401)
132
+ return f(
133
+ l ?? p[401],
134
+ "signed-out",
135
+ a ?? c ?? "Sign in again, then try once more.",
136
+ u.signIn
137
+ );
138
+ if (o === 403)
139
+ return f(
140
+ l ?? p[403],
141
+ "forbidden",
142
+ a ?? c,
143
+ h && !/ask/i.test(a ?? c ?? "") ? void 0 : u.askAccess
144
+ );
145
+ if (o === 404 || o === 410)
146
+ return f(l ?? p[404], "not-found", a ?? c, u.back);
147
+ if (o === 409 || o === 412) {
148
+ const s = a ?? (h ? c : "Reload to see their changes, then make yours again.");
149
+ return f(
150
+ l ?? p[409],
151
+ "conflict",
152
+ s,
153
+ !s || /\breload\b/i.test(s) ? u.reload : void 0
154
+ );
155
+ }
156
+ if (o === 423)
157
+ return f(l ?? p[423], "locked", a ?? c, u.reload);
158
+ if (o === 413) return f(l ?? p[413], "too-large", a ?? c);
159
+ if (o === 429)
160
+ return f(l ?? p[429], "rate-limited", a ?? c, u.retry);
161
+ if (o === 400 || o === 422) {
162
+ const s = v.length ? J(v, n.fieldLabels) : "", w = a ?? (s && (!h || /highlighted/i.test(c ?? "")) ? `Check ${s}, then try again.` : c), g = v.length > 0 || /^(VALIDATION|REQUIRED)/.test(h ?? "");
163
+ return f(
164
+ l ?? (g ? p[422] : p[400]),
165
+ g ? "validation" : "refused",
166
+ w
167
+ );
168
+ }
169
+ if (o === 502 || o === 503 || o === 504)
170
+ return f(
171
+ l ?? p[o],
172
+ o === 504 ? "timeout" : "unavailable",
173
+ a ?? c,
174
+ u.retry
175
+ );
176
+ if (o && o >= 500)
177
+ return f(
178
+ l ?? p[500],
179
+ "server",
180
+ a && !/copy the details/i.test(a) ? a : O,
181
+ u.retry
182
+ );
183
+ if (o && o >= 400)
184
+ return f(l ?? P(o) ?? e, "refused", a ?? c);
185
+ if (l) return f(l, h ? "refused" : "unknown", a ?? c);
186
+ const q = $.trim() ? N($, e) : e;
187
+ return f(q, "unknown", a ?? c ?? O, u.retry);
188
+ }
189
+ function it(t, e = "this", n = {}) {
190
+ const i = `Couldn’t load ${e}`, r = R(t, i, n);
191
+ return (r.kind === "bug" || r.kind === "server" && r.title === p[500] || r.title === i) && (r.kind === "server" || r.kind === "bug" || r.kind === "unknown") && (r.title = i, r.hint = r.kind === "bug" ? r.hint : O, r.kind !== "bug" && (r.action = u.retry)), r;
192
+ }
193
+ function b(t, e = {}) {
194
+ var m;
195
+ const n = tt(t) ? t : R(t), i = e.page ?? (typeof window < "u" && window.location ? window.location.pathname : void 0);
60
196
  return [
61
- n.action ? `Action: ${n.action}` : null,
62
- `What happened: ${e.title}`,
63
- e.hint ? `What to do: ${e.hint}` : null,
64
- e.code || e.status ? `Code: ${[e.code, e.status ? `HTTP ${e.status}` : null].filter(Boolean).join(" · ")}` : null,
65
- (a = e.fields) != null && a.length ? `Fields: ${e.fields.join(", ")}` : null,
66
- e.requestId ? `Request id: ${e.requestId}` : null,
197
+ e.action ? `Action: ${e.action}` : null,
198
+ `What happened: ${n.title}`,
199
+ n.hint ? `What to do: ${n.hint}` : null,
200
+ n.code || n.status ? `Code: ${[n.code, n.status ? `HTTP ${n.status}` : null].filter(Boolean).join(" · ")}` : null,
201
+ (m = n.fields) != null && m.length ? `Fields: ${n.fields.join(", ")}` : null,
202
+ n.requestId ? `Request id: ${n.requestId}` : null,
203
+ n.technical ? `Technical: ${n.technical}` : null,
67
204
  i ? `Page: ${i}` : null,
68
- `When: ${(n.now ?? /* @__PURE__ */ new Date()).toISOString()}`
205
+ `When: ${(e.now ?? /* @__PURE__ */ new Date()).toISOString()}`
69
206
  ].filter((o) => !!o).join(`
70
207
  `);
71
208
  }
72
- function U(t) {
73
- return r(t) && typeof t.title == "string" && !("response" in t) && !("stack" in t);
209
+ function tt(t) {
210
+ return d(t) && typeof t.title == "string" && !("response" in t) && !("stack" in t);
74
211
  }
75
- async function H(t, n) {
212
+ async function rt(t, e) {
76
213
  try {
77
- const e = F(t, n);
78
- return typeof navigator > "u" || !navigator.clipboard ? !1 : (await navigator.clipboard.writeText(e), !0);
214
+ const n = b(t, e);
215
+ return typeof navigator > "u" || !navigator.clipboard ? !1 : (await navigator.clipboard.writeText(n), !0);
79
216
  } catch {
80
217
  return !1;
81
218
  }
82
219
  }
83
- function P(t) {
84
- const n = typeof t == "string" ? t.trim() : String(t ?? "").trim();
85
- if (!n) return "This row was not imported";
86
- let e = n;
87
- const i = n.lastIndexOf(" - ");
88
- if (i > 0 && /^(insert|update|delete|merge|select|exec)\s/i.test(n) && (e = n.slice(i + 3)), /conflicted with the (FOREIGN KEY|REFERENCE)/i.test(e))
220
+ function ot(t) {
221
+ const e = typeof t == "string" ? t.trim() : String(t ?? "").trim();
222
+ if (!e) return "This row was not imported";
223
+ let n = e;
224
+ const i = e.lastIndexOf(" - ");
225
+ if (i > 0 && /^(insert|update|delete|merge|select|exec)\s/i.test(e) && (n = e.slice(i + 3)), /conflicted with the (FOREIGN KEY|REFERENCE)/i.test(n))
89
226
  return "A linked value in this row does not exist — check the spelling or add that record first";
90
- if (/Violation of (UNIQUE KEY|PRIMARY KEY)|Cannot insert duplicate key/i.test(e))
227
+ if (/Violation of (UNIQUE KEY|PRIMARY KEY)|Cannot insert duplicate key/i.test(n))
91
228
  return "Another record already has a value from this row — change it in the file, or import with Overwrite";
92
- const s = /Cannot insert the value NULL into column '([^']+)'/i.exec(e);
93
- return s ? `${s[1].replace(/_/g, " ")} is empty — fill it in the file or map a column to it` : e.replace(/,? table '[^']*'/gi, "").replace(/\s*(INSERT|UPDATE) fails\./gi, "").trim();
229
+ const r = /Cannot insert the value NULL into column '([^']+)'/i.exec(n);
230
+ return r ? `${r[1].replace(/_/g, " ")} is empty — fill it in the file or map a column to it` : n.replace(/,? table '[^']*'/gi, "").replace(/\s*(INSERT|UPDATE) fails\./gi, "").trim();
94
231
  }
95
- function j(t, n) {
96
- const e = p(t, n);
97
- return e.hint ? `${e.title.replace(/[.!?]\s*$/, "")}. ${e.hint}` : e.title;
232
+ function st(t, e) {
233
+ const n = R(t, e);
234
+ return n.hint ? `${n.title.replace(/[.!?]\s*$/, "")}. ${n.hint}` : n.title;
98
235
  }
99
236
  export {
100
- H as copyErrorDetails,
101
- p as describeError,
102
- F as errorDetailsText,
103
- j as errorSentence,
104
- P as rowErrorSentence
237
+ O as ASK_FOR_HELP_HINT,
238
+ rt as copyErrorDetails,
239
+ R as describeError,
240
+ it as describeLoadError,
241
+ b as errorDetailsText,
242
+ J as errorFieldList,
243
+ z as errorFieldName,
244
+ st as errorSentence,
245
+ ot as rowErrorSentence
105
246
  };
@@ -1,22 +1,80 @@
1
- import { toast as t } from "sonner";
2
- import { describeError as s, copyErrorDetails as n } from "./error-message.js";
3
- function d(o, e = {}) {
4
- const r = c(o) ? o : s(o);
5
- return {
6
- ...r.hint ? { description: r.hint } : {},
7
- action: {
1
+ import { isValidElement as y } from "react";
2
+ import { toast as l } from "sonner";
3
+ import { runErrorAction as p, openSupportForError as E } from "./error-actions.js";
4
+ import { STATUS_HINTS as d } from "./error-hints.js";
5
+ import { describeError as f, copyErrorDetails as T } from "./error-message.js";
6
+ import { isRawErrorText as k, statusInText as h, plainErrorText as C } from "./safe-error.js";
7
+ function m(r, o) {
8
+ const t = r.action;
9
+ if ((t == null ? void 0 : t.kind) === "retry" && o.retry) return { label: t.label, onClick: () => {
10
+ var n;
11
+ return (n = o.retry) == null ? void 0 : n.call(o);
12
+ } };
13
+ if (t && (t.kind === "sign-in" || t.kind === "contact"))
14
+ return { label: t.label, onClick: () => p(t.kind, r, o) };
15
+ if ((t == null ? void 0 : t.kind) === "reload" && r.kind !== "bug")
16
+ return { label: t.label, onClick: () => p("reload", r, o) };
17
+ if (r.kind === "server" || r.kind === "bug" || r.kind === "unknown" && r.action)
18
+ return {
19
+ label: "Get help",
20
+ onClick: () => E(r, { action: o.action })
21
+ };
22
+ if (r.requestId)
23
+ return {
8
24
  label: "Copy details",
9
25
  onClick: () => {
10
- n(r, e).then(
11
- (i) => i ? t.success("Details copied") : t.error("Could not copy the details")
26
+ T(r, o).then(
27
+ (n) => n ? l.success("Details copied") : l.error("Could not copy the details")
12
28
  );
13
29
  }
14
- }
30
+ };
31
+ }
32
+ function a(r, o = {}) {
33
+ const t = w(r) ? r : f(r), n = m(t, o);
34
+ return {
35
+ ...t.hint ? { description: t.hint } : {},
36
+ ...n ? { action: n } : {}
15
37
  };
16
38
  }
17
- function c(o) {
18
- return !!o && typeof o == "object" && typeof o.title == "string" && !(o instanceof Error) && !("response" in o);
39
+ function _(r, o, t = {}) {
40
+ const n = f(r, o);
41
+ return l.error(n.title, a(n, t)), n;
42
+ }
43
+ function w(r) {
44
+ return !!r && typeof r == "object" && typeof r.title == "string" && !(r instanceof Error) && !("response" in r);
45
+ }
46
+ let b = !1;
47
+ function q(r = l) {
48
+ if (b) return;
49
+ b = !0;
50
+ const o = r.error, t = ((n, e) => {
51
+ try {
52
+ if (n && typeof n == "object" && !y(n)) {
53
+ const i = f(n);
54
+ return o(i.title, { ...a(i), ...u(e) });
55
+ }
56
+ if (typeof n == "string" && k(n)) {
57
+ const i = h(n), s = i ? d[i] ?? d[i >= 500 ? 500 : 400] : void 0, c = u(e);
58
+ return o(C(n), {
59
+ ...s && !(c != null && c.description) ? { description: s } : {},
60
+ ...c
61
+ });
62
+ }
63
+ return o(n, u(e));
64
+ } catch {
65
+ return o(n, e);
66
+ }
67
+ });
68
+ r.error = t;
69
+ }
70
+ function u(r) {
71
+ if (!r || typeof r.description != "string" || !k(r.description))
72
+ return r;
73
+ const { description: o, ...t } = r;
74
+ return t;
19
75
  }
20
76
  export {
21
- d as errorToastOptions
77
+ a as errorToastOptions,
78
+ q as guardErrorToasts,
79
+ _ as toastError
22
80
  };
@@ -1,38 +1,46 @@
1
- import { reportClientCrash as c } from "./client-crash.js";
2
- const d = "Something went wrong — it’s been reported", g = /failed to fetch|load failed|networkerror|network request failed|network error/i;
3
- function u(e) {
4
- var s;
5
- const t = e, o = (t == null ? void 0 : t.status) ?? ((s = t == null ? void 0 : t.response) == null ? void 0 : s.status);
1
+ import { reportClientCrash as T } from "./client-crash.js";
2
+ const d = "Something went wrong — it’s been reported", m = /failed to fetch|load failed|networkerror|network request failed|network error/i;
3
+ function h(e) {
4
+ var r;
5
+ const t = e, o = (t == null ? void 0 : t.status) ?? ((r = t == null ? void 0 : t.response) == null ? void 0 : r.status);
6
6
  return typeof o == "number" ? o : null;
7
7
  }
8
- function f(e) {
9
- return !(e instanceof Error) || u(e) != null || e.response != null || g.test(e.message) ? !1 : e instanceof TypeError || e instanceof ReferenceError || e instanceof RangeError;
8
+ function w(e) {
9
+ return !(e instanceof Error) || h(e) != null || e.response != null || m.test(e.message) ? !1 : e instanceof TypeError || e instanceof ReferenceError || e instanceof RangeError;
10
10
  }
11
- const l = /^(bad request|unauthorized|forbidden|not found|conflict|unprocessable entity|too many requests|internal server error|bad gateway|service unavailable|gateway timeout)$/i;
12
- function h(e) {
13
- var s;
14
- const t = e, o = [(s = t == null ? void 0 : t.response) == null ? void 0 : s.data, t == null ? void 0 : t.response];
15
- for (const r of o) {
16
- const n = r == null ? void 0 : r.error;
17
- if (typeof n == "string" && n.trim() && !l.test(n.trim())) return n.trim();
11
+ const g = /^(bad request|unauthorized|forbidden|not found|conflict|unprocessable entity|too many requests|internal server error|bad gateway|service unavailable|gateway timeout)$/i;
12
+ function y(e) {
13
+ var r;
14
+ const t = e, o = [(r = t == null ? void 0 : t.response) == null ? void 0 : r.data, t == null ? void 0 : t.response];
15
+ for (const n of o) {
16
+ const i = n == null ? void 0 : n.error;
17
+ if (typeof i == "string" && i.trim() && !g.test(i.trim())) return i.trim();
18
18
  }
19
- for (const r of o) {
20
- const n = r == null ? void 0 : r.message;
21
- if (typeof n == "string" && n.trim()) return n.trim();
19
+ for (const n of o) {
20
+ const i = n == null ? void 0 : n.message;
21
+ if (typeof i == "string" && i.trim()) return i.trim();
22
22
  }
23
23
  return null;
24
24
  }
25
- function p(e, t = "Failed") {
26
- const o = h(e);
27
- return o || (f(e) ? d : e instanceof Error ? w(e.message) ? m(u(e)) ?? t : e.message || t : typeof e == "string" && e.trim() ? e : t);
25
+ function A(e, t = "Failed") {
26
+ const o = h(e), r = y(e);
27
+ if (r && !c(r) && !S(e, o)) return r;
28
+ if (w(e)) return d;
29
+ const n = e instanceof Error ? e.message : typeof e == "string" ? e : "";
30
+ return !o && m.test(n) ? "Cannot reach the server" : n.trim() && !c(n) ? n.trim() : n.trim() ? C(n, t || d, o) : r ? f(o) ?? (t || d) : t;
28
31
  }
29
- const i = {
32
+ function S(e, t) {
33
+ if (t !== 500) return !1;
34
+ const o = e, r = o == null ? void 0 : o.response, n = r && typeof r.data == "object" && r.data ? r.data : r;
35
+ return !!n && typeof n.statusCode == "number" && typeof n.code != "string";
36
+ }
37
+ const E = {
30
38
  400: "That request could not be completed",
31
- 401: "You are signed out",
39
+ 401: "You’ve been signed out",
32
40
  403: "You do not have access to do this",
33
- 404: "That could not be found",
41
+ 404: "This could not be found",
34
42
  408: "The server took too long to answer",
35
- 409: "This changed while you were working on it",
43
+ 409: "Someone else changed this",
36
44
  413: "That is too large to send",
37
45
  422: "Some values need fixing",
38
46
  423: "Someone else is working on this",
@@ -42,26 +50,116 @@ const i = {
42
50
  503: "The server is not answering right now",
43
51
  504: "The server took too long to answer"
44
52
  };
45
- function m(e) {
46
- return e == null ? null : i[e] ?? (e >= 500 ? i[500] : e >= 400 ? i[400] : null);
53
+ function f(e) {
54
+ return e == null ? null : E[e] ?? (e >= 500 ? E[500] : e >= 400 ? E[400] : null);
47
55
  }
48
- function w(e) {
56
+ function v(e) {
49
57
  if (typeof e != "string") return !1;
50
58
  const t = e.trim();
51
- return /^request failed with status( code)? \d{3}$/i.test(t) || l.test(t) || /^(payload too large|request entity too large|locked|request timeout)$/i.test(t);
59
+ return /^request failed with status( code)? \d{3}$/i.test(t) || // apiFetch-style "Request failed (500)", the SDK's "HTTP 500", "Error 404", "500 Internal Server Error"
60
+ /^(\w+ )?failed \(\d{3}\)$/i.test(t) || /^(http|error|status)( code)?:? ?\d{3}$/i.test(t) || /^\d{3}( [a-z][a-z ]+)?$/i.test(t) || g.test(t) || /^(payload too large|request entity too large|locked|request timeout|method not allowed|not acceptable|precondition failed|unsupported media type)$/i.test(
61
+ t
62
+ );
52
63
  }
53
- const a = /* @__PURE__ */ new WeakSet();
54
- function S(e, t) {
55
- !e || !f(t) || a.has(t) || (a.add(t), c(e, t, null).catch(() => {
64
+ function b(e) {
65
+ if (typeof e != "string") return null;
66
+ const t = /\b([45]\d{2})\b/.exec(e);
67
+ return t ? Number(t[1]) : null;
68
+ }
69
+ const R = [
70
+ // Status lines inside a sentence ("Not saved — Request failed (500)")
71
+ /request failed( with status( code)?)? ?\(?\d{3}\)?/i,
72
+ /\bHTTP\/?\d?(\.\d)? ?[45]\d{2}\b/,
73
+ /\bstatus( code)? [45]\d{2}\b/i,
74
+ /\((HTTP )?[45]\d{2}\)\.?$/,
75
+ // JavaScript / runtime errors
76
+ /^(TypeError|ReferenceError|RangeError|SyntaxError|EvalError|URIError|AxiosError|FetchError|AbortError)\b/,
77
+ /cannot read propert(y|ies) of/i,
78
+ /cannot set propert(y|ies) of/i,
79
+ /\bis not a function\b/i,
80
+ /\bis not defined\b/i,
81
+ /\bis not iterable\b/i,
82
+ /\bundefined is not\b/i,
83
+ /unexpected (token|end of (json|input))/i,
84
+ /\bJSON\.parse\b|is not valid JSON/i,
85
+ /Minified React error/i,
86
+ /Maximum call stack/i,
87
+ /\[object \w+\]/,
88
+ /^(undefined|null|NaN|true|false|\{\}|\[\])$/,
89
+ // Stack frames and source paths
90
+ /\n\s*at\s+\S/,
91
+ /\bat\s+[\w$.<>]+\s+\(.*:\d+:\d+\)/,
92
+ /\.(m?[jt]sx?|cjs):\d+(:\d+)?\b/,
93
+ /node_modules\//,
94
+ // SQL and the database's own words
95
+ /\b(select\s[\s\S]+\sfrom|insert\s+into|update\s+\[?[\w.]+\]?\s+set|delete\s+from|merge\s+(into\s+)?\[?[\w.]+\]?\s+(as\s+)?\w*\s*using|exec(ute)?\s+\[?dbo)\b/i,
96
+ /invalid (column|object) name/i,
97
+ /conflicted with the (FOREIGN KEY|REFERENCE|CHECK) constraint/i,
98
+ /violation of (UNIQUE|PRIMARY) KEY/i,
99
+ /cannot insert (the value NULL|duplicate key|explicit value)/i,
100
+ /conversion failed when converting/i,
101
+ /arithmetic overflow/i,
102
+ /string or binary data would be truncated/i,
103
+ /\bdeadlock(ed)? victim/i,
104
+ /incorrect syntax near/i,
105
+ /\bmust declare the scalar variable/i,
106
+ /\b(dbo|sys)\.\w+/i,
107
+ /\b(nivaro|directus)_\w+/i,
108
+ /\bknex\b/i,
109
+ // Drivers, sockets and the network stack
110
+ /\b(ECONNREFUSED|ECONNRESET|ETIMEDOUT|ENOTFOUND|EAI_AGAIN|EPIPE|EHOSTUNREACH|ENETUNREACH|ERR_[A-Z_]+)\b/,
111
+ /socket hang up/i,
112
+ /\b(ConnectionError|RequestError|TediousError|SequelizeError|PrismaClient\w*)\b/,
113
+ /timeout: request failed to complete in \d+ms/i,
114
+ /failed to connect to [\w.-]+:\d+/i,
115
+ /\b\d{1,3}(\.\d{1,3}){3}(:\d+)?\b/,
116
+ /^(failed to fetch|load failed|network ?error|network request failed)$/i,
117
+ // Internal ids
118
+ /\b[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\b/i
119
+ ];
120
+ function c(e) {
121
+ if (typeof e != "string") return e != null;
122
+ const t = e.trim();
123
+ return t ? v(t) ? !0 : R.some((o) => o.test(t)) : !1;
124
+ }
125
+ const N = /\s+[—–-]\s+|:\s+|\.\s+/;
126
+ function C(e, t = d, o) {
127
+ if (typeof e != "string" || !e.trim()) return t;
128
+ const r = e.trim();
129
+ if (!c(r)) return r;
130
+ if (!o && m.test(r) && !/\d{3}/.test(r)) return "Cannot reach the server";
131
+ const n = /^(.*\S)\s*\((?:HTTP )?([45]\d{2})\)\.?$/.exec(r);
132
+ if (n) {
133
+ const s = n[1].replace(/\s*[—–:-]?\s*request failed$/i, "").trim(), a = f(o ?? Number(n[2]));
134
+ if (!s) return a ?? t;
135
+ if (!c(s)) return a ? `${s.replace(/[.!?]\s*$/, "")}. ${a}` : s;
136
+ }
137
+ const i = r.split(N), u = [];
138
+ for (const s of i) {
139
+ if (!s.trim() || c(s)) break;
140
+ u.push(s.trim());
141
+ }
142
+ if (u.length && u.join(" ").length >= 4 && i.length > u.length) {
143
+ const s = o ?? b(r.slice(u.join(" ").length)), a = s ? f(s) : null, l = u.join(". ").replace(/[.!?]\s*$/, "");
144
+ return a && a.toLowerCase() !== l.toLowerCase() ? `${l}. ${a}` : l;
145
+ }
146
+ return f(o ?? b(r)) ?? t;
147
+ }
148
+ const p = /* @__PURE__ */ new WeakSet();
149
+ function O(e, t) {
150
+ !e || !w(t) || p.has(t) || (p.add(t), T(e, t, null).catch(() => {
56
151
  }));
57
152
  }
58
153
  export {
59
154
  d as SOMETHING_WENT_WRONG,
60
- i as STATUS_TITLES,
61
- u as errorStatusOf,
62
- w as isBareStatusText,
63
- f as isCodeError,
64
- S as reportCodeError,
65
- m as statusTitle,
66
- p as userErrorMessage
155
+ E as STATUS_TITLES,
156
+ h as errorStatusOf,
157
+ v as isBareStatusText,
158
+ w as isCodeError,
159
+ c as isRawErrorText,
160
+ C as plainErrorText,
161
+ O as reportCodeError,
162
+ b as statusInText,
163
+ f as statusTitle,
164
+ A as userErrorMessage
67
165
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nivaro/react",
3
- "version": "0.3.46",
3
+ "version": "0.3.48",
4
4
  "description": "React hooks and components for Nivaro CMS forms",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",