@nivaro/react 0.3.130 → 0.3.132

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,46 +1,57 @@
1
- import { errorDetailsText as c } from "./error-message.js";
1
+ import { errorDetailsText as l } from "./error-message.js";
2
2
  let o = {};
3
- function g(n) {
3
+ function h(n) {
4
4
  o = { ...o, ...n };
5
5
  }
6
- const i = "nvr:support-draft", s = 15 * 6e4;
6
+ const r = "nvr:support-draft", u = 15 * 6e4;
7
7
  function f(n, e = Date.now()) {
8
8
  try {
9
- localStorage.setItem(i, JSON.stringify({ ...n, at: e }));
9
+ localStorage.setItem(r, JSON.stringify({ ...n, at: e }));
10
10
  } catch {
11
11
  }
12
12
  }
13
- function y(n = Date.now()) {
13
+ function S(n = Date.now()) {
14
14
  try {
15
- const e = localStorage.getItem(i);
15
+ const e = localStorage.getItem(r);
16
16
  if (!e) return null;
17
- localStorage.removeItem(i);
17
+ localStorage.removeItem(r);
18
18
  const t = JSON.parse(e);
19
- return typeof t.at != "number" || n - t.at > s || typeof t.title != "string" || typeof t.description != "string" ? null : { title: t.title.slice(0, 200), description: t.description.slice(0, 4e3) };
19
+ return typeof t.at != "number" || n - t.at > u || typeof t.title != "string" || typeof t.description != "string" ? null : { title: t.title.slice(0, 200), description: t.description.slice(0, 4e3) };
20
20
  } catch {
21
21
  return null;
22
22
  }
23
23
  }
24
- function l(n, e = {}) {
24
+ function d(n, e = {}) {
25
25
  const t = n.kind === "forbidden" ? "I need access to do this." : "I ran into a problem and could not finish what I was doing.";
26
26
  return {
27
27
  title: (n.kind === "forbidden" ? `Access: ${n.title}` : n.title).slice(0, 200),
28
28
  description: `${t}
29
29
 
30
- ${c(n, e)}`
30
+ ${l(n, e)}`
31
31
  };
32
32
  }
33
- function a(n) {
33
+ function s(n) {
34
34
  o.navigate ? o.navigate(n) : typeof window < "u" && window.location.assign(n);
35
35
  }
36
- function d(n, e = {}) {
37
- f(l(n, e));
38
- const t = `${o.supportPath ?? "/support"}?new=1`;
36
+ let i = null;
37
+ function I(n) {
38
+ return i = n, () => {
39
+ i === n && (i = null);
40
+ };
41
+ }
42
+ function w(n, e = {}) {
43
+ const t = d(n, e);
44
+ if (i) {
45
+ i(t);
46
+ return;
47
+ }
48
+ f(t);
49
+ const a = `${o.supportPath ?? "/support"}?new=1`;
39
50
  if (typeof window > "u") return;
40
- const r = window.open(t, "_blank");
41
- r ? r.opener = null : a(t);
51
+ const c = window.open(a, "_blank");
52
+ c ? c.opener = null : s(a);
42
53
  }
43
- function u() {
54
+ function p() {
44
55
  if (o.signIn) {
45
56
  o.signIn();
46
57
  return;
@@ -51,10 +62,10 @@ function u() {
51
62
  n && !n.startsWith(e) ? `${e}?redirect=${encodeURIComponent(n)}` : e
52
63
  );
53
64
  }
54
- function w() {
55
- typeof window > "u" || (window.history.length > 1 ? window.history.back() : a("/"));
65
+ function g() {
66
+ typeof window > "u" || (window.history.length > 1 ? window.history.back() : s("/"));
56
67
  }
57
- function h(n, e, t = {}) {
68
+ function m(n, e, t = {}) {
58
69
  switch (n) {
59
70
  case "retry":
60
71
  t.retry ? t.retry() : typeof window < "u" && window.location.reload();
@@ -63,23 +74,24 @@ function h(n, e, t = {}) {
63
74
  typeof window < "u" && window.location.reload();
64
75
  return;
65
76
  case "sign-in":
66
- u();
77
+ p();
67
78
  return;
68
79
  case "go-back":
69
- w();
80
+ g();
70
81
  return;
71
82
  case "contact":
72
- d(e, { action: t.action });
83
+ w(e, { action: t.action });
73
84
  return;
74
85
  }
75
86
  }
76
87
  export {
77
- w as goBack,
78
- u as goToSignIn,
79
- d as openSupportForError,
80
- h as runErrorAction,
88
+ g as goBack,
89
+ p as goToSignIn,
90
+ w as openSupportForError,
91
+ I as registerSupportDialog,
92
+ m as runErrorAction,
81
93
  f as saveSupportDraft,
82
- g as setErrorActionHost,
83
- l as supportDraftFor,
84
- y as takeSupportDraft
94
+ h as setErrorActionHost,
95
+ d as supportDraftFor,
96
+ S as takeSupportDraft
85
97
  };
@@ -1,6 +1,6 @@
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 = {
1
+ import { fieldsFromBody as q, hintFor as F } from "./error-hints.js";
2
+ import { isCodeError as L, isRawErrorText as I, plainErrorText as N, STATUS_TITLES as p, errorStatusOf as U, isBareStatusText as D, SOMETHING_WENT_WRONG as x, statusTitle as P } from "./safe-error.js";
3
+ const _ = "x-nivaro-request-id", H = /^[A-Z][A-Z0-9_]{2,}$/, W = /^(ERR_|E[A-Z]+$)/, B = /failed to fetch|load failed|networkerror|network request failed|network error|cannot reach/i, S = "Try again. If it keeps happening, ask for help.", u = {
4
4
  retry: { kind: "retry", label: "Try again" },
5
5
  signIn: { kind: "sign-in", label: "Sign in again" },
6
6
  reload: { kind: "reload", label: "Reload" },
@@ -19,7 +19,7 @@ function k(t) {
19
19
  function K(t, e) {
20
20
  const n = d(e == null ? void 0 : e.extensions) ? e.extensions : null;
21
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;
22
+ if (typeof i == "string" && H.test(i) && !W.test(i)) return i;
23
23
  }
24
24
  function Y(t, e) {
25
25
  const n = k(e == null ? void 0 : e.request_id) ?? k(e == null ? void 0 : e.requestId);
@@ -34,7 +34,7 @@ function Y(t, e) {
34
34
  }
35
35
  }
36
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;
37
+ const n = U(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
38
  return r && r >= 100 && r < 600 ? r : void 0;
39
39
  }
40
40
  function M(t) {
@@ -65,9 +65,9 @@ function J(t, e) {
65
65
  function X(t, e = 500) {
66
66
  return t.length > e ? `${t.slice(0, e - 1)}…` : t;
67
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);
68
+ function O(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), R = Y(t, i), E = { title: e };
70
+ o && (E.status = o), h && (E.code = h), R && (E.requestId = R);
71
71
  const T = (s) => {
72
72
  const w = [
73
73
  i ? k(i.message) : void 0,
@@ -77,11 +77,11 @@ function R(t, e = "Something went wrong", n = {}) {
77
77
  ].filter((g) => !!(g != null && g.trim()) && !D(g)).find((g) => I(g) || !!o && o >= 500 && g !== s.title);
78
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
79
  };
80
- if (y(t))
80
+ if (L(t))
81
81
  return T({
82
82
  ...E,
83
83
  kind: "bug",
84
- title: U,
84
+ title: x,
85
85
  hint: "Try again. If it keeps happening, reload the page.",
86
86
  action: u.reloadPage
87
87
  });
@@ -103,7 +103,7 @@ function R(t, e = "Something went wrong", n = {}) {
103
103
  hint: "Check your internet connection, then try again. Nothing you entered is lost.",
104
104
  action: u.retry
105
105
  });
106
- if (m || !i && W.test($))
106
+ if (m || !i && B.test($))
107
107
  return T({
108
108
  ...E,
109
109
  kind: "network",
@@ -112,7 +112,7 @@ function R(t, e = "Something went wrong", n = {}) {
112
112
  action: u.retry
113
113
  });
114
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) : [];
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 ? F(h, o ?? 400) : void 0, v = i ? q(i) : [];
116
116
  v.length && (E.fields = v);
117
117
  const f = (s, w, g, C) => T({
118
118
  ...E,
@@ -177,22 +177,22 @@ function R(t, e = "Something went wrong", n = {}) {
177
177
  return f(
178
178
  l ?? p[500],
179
179
  "server",
180
- a && !/copy the details/i.test(a) ? a : O,
180
+ a && !/copy the details/i.test(a) ? a : S,
181
181
  u.retry
182
182
  );
183
183
  if (o && o >= 400)
184
184
  return f(l ?? P(o) ?? e, "refused", a ?? c);
185
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);
186
+ const y = $.trim() ? N($, e) : e;
187
+ return f(y, "unknown", a ?? c ?? S, u.retry);
188
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;
189
+ function rt(t, e = "this", n = {}) {
190
+ const i = `Couldn’t load ${e}`, r = O(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 : S, r.kind !== "bug" && (r.action = u.retry)), r;
192
192
  }
193
193
  function b(t, e = {}) {
194
194
  var m;
195
- const n = tt(t) ? t : R(t), i = e.page ?? (typeof window < "u" && window.location ? window.location.pathname : void 0);
195
+ const n = et(t) ? t : O(t), i = e.page ?? (typeof window < "u" && window.location ? window.location.pathname : void 0);
196
196
  return [
197
197
  e.action ? `Action: ${e.action}` : null,
198
198
  `What happened: ${n.title}`,
@@ -202,14 +202,25 @@ function b(t, e = {}) {
202
202
  n.requestId ? `Request id: ${n.requestId}` : null,
203
203
  n.technical ? `Technical: ${n.technical}` : null,
204
204
  i ? `Page: ${i}` : null,
205
- `When: ${(e.now ?? /* @__PURE__ */ new Date()).toISOString()}`
205
+ `When: ${tt(e.now ?? /* @__PURE__ */ new Date(), e.timeZone)}`
206
206
  ].filter((o) => !!o).join(`
207
207
  `);
208
208
  }
209
- function tt(t) {
209
+ function tt(t, e) {
210
+ try {
211
+ return new Intl.DateTimeFormat("en-US", {
212
+ dateStyle: "medium",
213
+ timeStyle: "long",
214
+ ...e ? { timeZone: e } : {}
215
+ }).format(t);
216
+ } catch {
217
+ return t.toISOString();
218
+ }
219
+ }
220
+ function et(t) {
210
221
  return d(t) && typeof t.title == "string" && !("response" in t) && !("stack" in t);
211
222
  }
212
- async function rt(t, e) {
223
+ async function ot(t, e) {
213
224
  try {
214
225
  const n = b(t, e);
215
226
  return typeof navigator > "u" || !navigator.clipboard ? !1 : (await navigator.clipboard.writeText(n), !0);
@@ -217,7 +228,7 @@ async function rt(t, e) {
217
228
  return !1;
218
229
  }
219
230
  }
220
- function ot(t) {
231
+ function st(t) {
221
232
  const e = typeof t == "string" ? t.trim() : String(t ?? "").trim();
222
233
  if (!e) return "This row was not imported";
223
234
  let n = e;
@@ -229,18 +240,19 @@ function ot(t) {
229
240
  const r = /Cannot insert the value NULL into column '([^']+)'/i.exec(n);
230
241
  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();
231
242
  }
232
- function st(t, e) {
233
- const n = R(t, e);
243
+ function at(t, e) {
244
+ const n = O(t, e);
234
245
  return n.hint ? `${n.title.replace(/[.!?]\s*$/, "")}. ${n.hint}` : n.title;
235
246
  }
236
247
  export {
237
- O as ASK_FOR_HELP_HINT,
238
- rt as copyErrorDetails,
239
- R as describeError,
240
- it as describeLoadError,
248
+ S as ASK_FOR_HELP_HINT,
249
+ ot as copyErrorDetails,
250
+ O as describeError,
251
+ rt as describeLoadError,
241
252
  b as errorDetailsText,
242
253
  J as errorFieldList,
243
254
  z as errorFieldName,
244
- st as errorSentence,
245
- ot as rowErrorSentence
255
+ at as errorSentence,
256
+ tt as formatWhen,
257
+ st as rowErrorSentence
246
258
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nivaro/react",
3
- "version": "0.3.130",
3
+ "version": "0.3.132",
4
4
  "description": "React hooks and components for Nivaro CMS forms",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",