@nivaro/react 0.3.8 → 0.3.10

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 (60) hide show
  1. package/dist/components/fields/FileField.js +20 -19
  2. package/dist/full.css +1 -1
  3. package/dist/hooks/replayUploadQueue.js +107 -93
  4. package/dist/hooks/useNivaroForm.js +129 -126
  5. package/dist/hooks/useSessionRecorder.js +103 -101
  6. package/dist/index.d.ts +115 -2
  7. package/dist/index.js +466 -447
  8. package/dist/shared/components/CollectionBrowserView.js +1058 -1059
  9. package/dist/shared/components/ConformanceView.js +36 -35
  10. package/dist/shared/components/DataTable.js +230 -223
  11. package/dist/shared/components/ForceReloadBanner.js +58 -34
  12. package/dist/shared/components/ItemEditForm.js +3687 -3580
  13. package/dist/shared/components/JsonMapEditor.js +18 -17
  14. package/dist/shared/components/MatrixEditor.js +8 -7
  15. package/dist/shared/components/MyWorkView.js +32 -31
  16. package/dist/shared/components/PageRenderer.js +146 -145
  17. package/dist/shared/components/QueryTable.js +49 -49
  18. package/dist/shared/components/RecordGridEditor.js +76 -75
  19. package/dist/shared/components/ai/AiMemorySuggestions.js +15 -14
  20. package/dist/shared/components/ai/AskPanel.js +55 -54
  21. package/dist/shared/components/bulk/BulkActionButtons.js +30 -29
  22. package/dist/shared/components/bulk/PushBulkButtons.js +57 -56
  23. package/dist/shared/components/chat/ChatPanel.js +288 -287
  24. package/dist/shared/components/chat/SlashCommands.js +30 -29
  25. package/dist/shared/components/chat/chat-outbox.js +76 -75
  26. package/dist/shared/components/help-videos/recorder/useLeaveWarning.js +6 -5
  27. package/dist/shared/components/integrations/console/SignalCard.js +124 -123
  28. package/dist/shared/components/integrations/console/SnoozeMenu.js +24 -23
  29. package/dist/shared/components/item-edit/CloneDialog.js +85 -78
  30. package/dist/shared/components/item-edit/InlineTableField.js +301 -300
  31. package/dist/shared/components/item-edit/MembershipSetField.js +24 -23
  32. package/dist/shared/components/item-edit/QuickCreateButton.js +8 -7
  33. package/dist/shared/components/item-edit/RecordLiveSync.js +101 -100
  34. package/dist/shared/components/item-edit/staged-links.js +86 -0
  35. package/dist/shared/components/layout-editor/LayoutEditor.js +275 -274
  36. package/dist/shared/components/layout-editor/editors/cascade-rule-row.js +18 -17
  37. package/dist/shared/components/layout-editor/inspector/HelpTab.js +37 -36
  38. package/dist/shared/components/layout-editor/matrix/FieldStateMatrix.js +50 -49
  39. package/dist/shared/components/panels/CommentPanel.js +237 -236
  40. package/dist/shared/components/profile/AiMemoryCard.js +15 -14
  41. package/dist/shared/components/profile/PersonAdminTools.js +70 -67
  42. package/dist/shared/components/profile/usePersonPresence.js +42 -37
  43. package/dist/shared/components/queue/QueueItemSheet.js +36 -35
  44. package/dist/shared/components/queue/QueueWorklist.js +597 -598
  45. package/dist/shared/lib/client-version.js +63 -0
  46. package/dist/shared/lib/force-reload.js +36 -0
  47. package/dist/shared/lib/load-error.js +11 -10
  48. package/dist/shared/lib/presence-live.js +73 -0
  49. package/dist/shared/lib/presence-state.js +39 -31
  50. package/dist/shared/lib/record-outbox.js +76 -75
  51. package/dist/shared/lib/request-gate.js +120 -102
  52. package/dist/shared/lib/rum.js +45 -36
  53. package/dist/shared/lib/safe-error.js +39 -0
  54. package/dist/shared/lib/server-clock.js +11 -7
  55. package/dist/shared/lib/signed-out.js +114 -0
  56. package/dist/shared/lib/socket-realtime.js +19 -17
  57. package/dist/shared/lib/unsaved-work.js +62 -0
  58. package/dist/shared/lib/use-online-users.js +11 -10
  59. package/dist/shared/lib/worker-socket.js +89 -79
  60. package/package.json +1 -1
@@ -1,19 +1,20 @@
1
- import { noteOwnWriteFromCommand as b } from "./own-writes.js";
1
+ import { noteOwnWriteFromCommand as C } from "./own-writes.js";
2
+ import { noteCredentialChanged as z, isIdentityRead as D, claimIdentityCall as M, signedOutError as $, noteSignedIn as Z, isSignedOutError as U, noteUnauthorized as x } from "./signed-out.js";
2
3
  function q(t) {
3
4
  if (!t || typeof t != "object") return "";
4
5
  const s = Object.entries(t).filter(([, o]) => o != null).map(([o, u]) => [o, String(u)]).sort(([o], [u]) => o < u ? -1 : o > u ? 1 : 0);
5
6
  return s.length ? new URLSearchParams(s).toString() : "";
6
7
  }
7
- function k(t) {
8
+ function P(t) {
8
9
  const s = (t._method ?? "GET").toUpperCase(), o = s === "GET" || t._body === void 0 ? "" : JSON.stringify(t._body);
9
10
  return `${s} ${t._path ?? ""} ${q(t._params)} ${o}`;
10
11
  }
11
- function g(t) {
12
+ function A(t) {
12
13
  return (t._method ?? "GET").toUpperCase() === "GET";
13
14
  }
14
- const P = /^\/(widgets-internal\/[^/]+\/render|items\/[^/]+\/[^/]+\/child-summary|items\/[^/]+\/auto-id-preview|config-conformance\/record\/.+\/check|pipelines\/instance\/[^/]+\/owners\/batch|addendums\/summary|at-risk\/evaluate|record-views\/.+\/touch)$/;
15
- function j(t) {
16
- return g(t) ? !0 : (t._method ?? "GET").toUpperCase() !== "POST" ? !1 : P.test((t._path ?? "").split("?")[0]);
15
+ const I = /^\/(widgets-internal\/[^/]+\/render|items\/[^/]+\/[^/]+\/child-summary|items\/[^/]+\/auto-id-preview|config-conformance\/record\/.+\/check|pipelines\/instance\/[^/]+\/owners\/batch|addendums\/summary|at-risk\/evaluate|record-views\/.+\/touch)$/;
16
+ function H(t) {
17
+ return A(t) ? !0 : (t._method ?? "GET").toUpperCase() !== "POST" ? !1 : I.test((t._path ?? "").split("?")[0]);
17
18
  }
18
19
  function T(t) {
19
20
  if (t == null || typeof t != "object") return t;
@@ -23,11 +24,11 @@ function T(t) {
23
24
  return t;
24
25
  }
25
26
  }
26
- const L = Symbol("nivaro.coalesced");
27
- function z(t) {
28
- return t[L] === !0;
27
+ const j = Symbol("nivaro.coalesced");
28
+ function B(t) {
29
+ return t[j] === !0;
29
30
  }
30
- const C = 20, D = /^\/items\/([A-Za-z_][A-Za-z0-9_]*)(?:\/([^/?#]+))?$/, I = /* @__PURE__ */ new Set(["aggregate", "export", "distinct", "resolve-paths", "batch-read"]), M = /* @__PURE__ */ new Set([
31
+ const O = 20, F = /^\/items\/([A-Za-z_][A-Za-z0-9_]*)(?:\/([^/?#]+))?$/, W = /* @__PURE__ */ new Set(["aggregate", "export", "distinct", "resolve-paths", "batch-read"]), K = /* @__PURE__ */ new Set([
31
32
  "fields",
32
33
  "filter",
33
34
  "sort",
@@ -40,32 +41,32 @@ const C = 20, D = /^\/items\/([A-Za-z_][A-Za-z0-9_]*)(?:\/([^/?#]+))?$/, I = /*
40
41
  "conditions",
41
42
  "labels"
42
43
  ]);
43
- function $(t) {
44
+ function Y(t) {
44
45
  const s = t;
45
46
  if ((s._method ?? "GET").toUpperCase() !== "GET") return null;
46
- const o = D.exec(s._path ?? "");
47
+ const o = F.exec(s._path ?? "");
47
48
  if (!o) return null;
48
49
  const [, u, d] = o;
49
- if (d !== void 0 && I.has(d)) return null;
50
- const m = s._params ?? {}, i = {};
50
+ if (d !== void 0 && W.has(d)) return null;
51
+ const m = s._params ?? {}, a = {};
51
52
  for (const [r, c] of Object.entries(m))
52
53
  if (c !== void 0) {
53
- if (!M.has(r)) return null;
54
- i[r] = c;
54
+ if (!K.has(r)) return null;
55
+ a[r] = c;
55
56
  }
56
- return d === void 0 ? { collection: u, query: i } : { collection: u, id: d, query: i };
57
+ return d === void 0 ? { collection: u, query: a } : { collection: u, id: d, query: a };
57
58
  }
58
- function Z(t) {
59
+ function J(t) {
59
60
  let s = [], o;
60
- const u = (i) => t.request(i.command).then(i.resolve, i.reject), d = async (i) => {
61
- if (i.length === 1) return u(i[0]);
61
+ const u = (a) => t.request(a.command).then(a.resolve, a.reject), d = async (a) => {
62
+ if (a.length === 1) return u(a[0]);
62
63
  let r;
63
64
  try {
64
65
  const c = await t.request({
65
66
  _method: "POST",
66
67
  _path: "/items/batch-read",
67
68
  _body: {
68
- reads: i.map((n, e) => ({
69
+ reads: a.map((n, e) => ({
69
70
  key: String(e),
70
71
  collection: n.read.collection,
71
72
  ...n.read.id !== void 0 ? { id: n.read.id } : {},
@@ -77,7 +78,7 @@ function Z(t) {
77
78
  } catch {
78
79
  r = void 0;
79
80
  }
80
- i.forEach((c, n) => {
81
+ a.forEach((c, n) => {
81
82
  const e = r == null ? void 0 : r[n];
82
83
  if ((e == null ? void 0 : e.status) !== 200 || e === void 0) {
83
84
  u(c);
@@ -87,36 +88,36 @@ function Z(t) {
87
88
  });
88
89
  }, m = () => {
89
90
  o = void 0;
90
- const i = s;
91
+ const a = s;
91
92
  s = [];
92
- for (let r = 0; r < i.length; r += C)
93
- d(i.slice(r, r + C));
93
+ for (let r = 0; r < a.length; r += O)
94
+ d(a.slice(r, r + O));
94
95
  };
95
- return (i, r) => new Promise((c, n) => {
96
+ return (a, r) => new Promise((c, n) => {
96
97
  s.push({
97
98
  read: r,
98
- command: i,
99
+ command: a,
99
100
  resolve: c,
100
101
  reject: n
101
102
  }), o === void 0 && (o = setTimeout(m, 0));
102
103
  });
103
104
  }
104
- const O = 50, x = 10, H = /^\/collections\/([A-Za-z_][A-Za-z0-9_-]{0,127})$/;
105
- function U(t) {
105
+ const b = 50, Q = 10, V = /^\/collections\/([A-Za-z_][A-Za-z0-9_-]{0,127})$/;
106
+ function X(t) {
106
107
  const s = t;
107
108
  if ((s._method ?? "GET").toUpperCase() !== "GET" || q(s._params) !== "") return null;
108
- const o = H.exec(s._path ?? "");
109
+ const o = V.exec(s._path ?? "");
109
110
  return o ? o[1] : null;
110
111
  }
111
- function B() {
112
+ function ee() {
112
113
  return Object.assign(new Error("Not found"), { status: 404, response: { error: "Not found" } });
113
114
  }
114
- function F(t) {
115
+ function te(t) {
115
116
  let s = !0, o = [], u;
116
117
  const d = (r) => t.request(r.command).then(r.resolve, r.reject), m = async (r) => {
117
- const c = [...new Set(r.map((a) => a.name))];
118
+ const c = [...new Set(r.map((i) => i.name))];
118
119
  if (c.length === 1 || !s) {
119
- for (const a of r) d(a);
120
+ for (const i of r) d(i);
120
121
  return;
121
122
  }
122
123
  let n;
@@ -126,11 +127,11 @@ function F(t) {
126
127
  _path: "/collections",
127
128
  _params: { names: c.join(",") }
128
129
  });
129
- } catch (a) {
130
- const h = a == null ? void 0 : a.status;
130
+ } catch (i) {
131
+ const h = i == null ? void 0 : i.status;
131
132
  if (h === 400 || h === 404 || h === 405) s = !1;
132
133
  else if (h === 429 || h !== void 0 && h >= 500) {
133
- for (const p of r) p.reject(a);
134
+ for (const p of r) p.reject(i);
134
135
  return;
135
136
  }
136
137
  n = void 0;
@@ -138,13 +139,13 @@ function F(t) {
138
139
  const e = n == null ? void 0 : n.data;
139
140
  if (!e || typeof e != "object" || Array.isArray(e)) {
140
141
  Array.isArray(e) && (s = !1);
141
- for (const a of r) d(a);
142
+ for (const i of r) d(i);
142
143
  return;
143
144
  }
144
145
  const l = e, f = new Set(Array.isArray(n == null ? void 0 : n.missing) ? n.missing : []);
145
- for (const a of r)
146
- Object.hasOwn(l, a.name) ? a.resolve({ data: T(l[a.name]) }) : f.has(a.name) ? a.reject(B()) : d(a);
147
- }, i = () => {
146
+ for (const i of r)
147
+ Object.hasOwn(l, i.name) ? i.resolve({ data: T(l[i.name]) }) : f.has(i.name) ? i.reject(ee()) : d(i);
148
+ }, a = () => {
148
149
  u = void 0;
149
150
  const r = o;
150
151
  o = [];
@@ -152,8 +153,8 @@ function F(t) {
152
153
  for (const e of r) {
153
154
  let l = n.get(e.name);
154
155
  if (!l) {
155
- const f = c[c.length - 1], a = f ? new Set(f.map((h) => h.name)).size : O;
156
- l = f && a < O ? f : [], l !== f && c.push(l), n.set(e.name, l);
156
+ const f = c[c.length - 1], i = f ? new Set(f.map((h) => h.name)).size : b;
157
+ l = f && i < b ? f : [], l !== f && c.push(l), n.set(e.name, l);
157
158
  }
158
159
  l.push(e);
159
160
  }
@@ -165,108 +166,125 @@ function F(t) {
165
166
  command: r,
166
167
  resolve: n,
167
168
  reject: e
168
- }), u === void 0 && (u = setTimeout(i, x));
169
+ }), u === void 0 && (u = setTimeout(a, Q));
169
170
  });
170
171
  }
171
- const R = 3e3, W = /^\/(collections\/[A-Za-z_][A-Za-z0-9_-]*|field-config\/[A-Za-z_][A-Za-z0-9_-]*|collection-layouts(\/active|\/summary\/[A-Za-z_][A-Za-z0-9_-]*)?|chat\/room-types|users\/me)$/, K = /^\/(record-views|item-locks|drafts|presence|rum|comments|notifications|tasks|field-rules\/evaluate|chat\/(?!room-types)|field-config\/[^/]+\/(evaluate-visibility|evaluate-defaults|evaluate-lock|cascade|project)$|items\/(?!nivaro_|directus_)[^/]+|users\/cards$|files\/verify$)/;
172
- function Y(t) {
172
+ const R = 3e3, ne = /^\/(collections\/[A-Za-z_][A-Za-z0-9_-]*|field-config\/[A-Za-z_][A-Za-z0-9_-]*|collection-layouts(\/active|\/summary\/[A-Za-z_][A-Za-z0-9_-]*)?|chat\/room-types|users\/me)$/, se = /^\/(record-views|item-locks|drafts|presence|rum|comments|notifications|tasks|field-rules\/evaluate|chat\/(?!room-types)|field-config\/[^/]+\/(evaluate-visibility|evaluate-defaults|evaluate-lock|cascade|project)$|items\/(?!nivaro_|directus_)[^/]+|users\/cards$|files\/verify$)/;
173
+ function oe(t) {
173
174
  const s = (t._path ?? "").split("?")[0];
174
- return (t._method ?? "GET").toUpperCase() === "POST" && P.test(s) ? !0 : K.test(s);
175
+ return (t._method ?? "GET").toUpperCase() === "POST" && I.test(s) ? !0 : se.test(s);
175
176
  }
176
- function J(t) {
177
+ function re(t) {
177
178
  const s = t;
178
- if (!g(s) || !W.test(s._path ?? "")) return !1;
179
+ if (!A(s) || !ne.test(s._path ?? "")) return !1;
179
180
  const o = s._params;
180
181
  return !(o && o.item != null && /^\/collection-layouts\/active$/.test(s._path ?? ""));
181
182
  }
182
- let v = 0;
183
- function G() {
184
- v++;
183
+ let y = 0;
184
+ function k() {
185
+ y++;
185
186
  }
186
- function ee(t, s = {}) {
187
- if (z(t)) return t;
188
- const o = /* @__PURE__ */ new Map(), u = s.batchReads ? Z(t) : null, d = s.batchCollections === !1 ? null : F(t), m = /* @__PURE__ */ new Map();
189
- let i = v;
187
+ function G(t, s) {
188
+ return t.then(
189
+ (o) => (s && Z(), o),
190
+ (o) => {
191
+ throw U(o, s) && x(s), o;
192
+ }
193
+ );
194
+ }
195
+ function le(t, s = {}) {
196
+ if (B(t)) return t;
197
+ const o = /* @__PURE__ */ new Map(), u = s.batchReads ? J(t) : null, d = s.batchCollections === !1 ? null : te(t), m = /* @__PURE__ */ new Map();
198
+ let a = y;
190
199
  const r = (n, e, l) => {
191
- if (e !== v) return;
192
- i !== v && (m.clear(), i = v);
200
+ if (e !== y) return;
201
+ a !== y && (m.clear(), a = y);
193
202
  const f = Date.now();
194
- for (const [a, h] of m) f - h.at >= R && m.delete(a);
203
+ for (const [i, h] of m) f - h.at >= R && m.delete(i);
195
204
  m.set(n, { at: f, epoch: e, value: l });
196
205
  }, c = (n) => {
197
206
  const e = n;
198
- if (!g(e)) {
199
- b(e._method, e._path, e._body);
200
- const _ = !Y(e);
201
- _ && G();
202
- const w = t.request(n);
203
- return (_ ? w.finally(G) : w).then((S) => (b(e._method, e._path, e._body, S), S));
207
+ if (!A(e)) {
208
+ C(e._method, e._path, e._body);
209
+ const _ = !oe(e);
210
+ _ && k();
211
+ const w = G(t.request(n), !1);
212
+ return (_ ? w.finally(k) : w).then((S) => (C(e._method, e._path, e._body, S), S));
204
213
  }
205
- const l = k(e), f = J(e);
214
+ const l = P(e), f = re(e);
206
215
  if (f) {
207
216
  const _ = m.get(l);
208
- if (_ && _.epoch === v && Date.now() - _.at < R)
217
+ if (_ && _.epoch === y && Date.now() - _.at < R)
209
218
  return Promise.resolve(T(_.value));
210
219
  }
211
- const a = o.get(l);
212
- if (a) return a.then(T);
213
- const h = u ? $(e) : null, p = !h && d ? U(e) : null, A = h && u ? u(n, h) : p && d ? d(n, p) : t.request(n), N = v, E = A.then((_) => (f && r(l, N, T(_)), _)).finally(() => {
214
- o.get(l) === E && o.delete(l);
220
+ const i = o.get(l);
221
+ if (i) return i.then(T);
222
+ const h = D(e._method, e._path, e._params);
223
+ if (h && !M()) return Promise.reject($());
224
+ const p = u ? Y(e) : null, E = !p && d ? X(e) : null, L = G(
225
+ p && u ? u(n, p) : E && d ? d(n, E) : t.request(n),
226
+ h
227
+ ), N = y, g = L.then((_) => (f && r(l, N, T(_)), _)).finally(() => {
228
+ o.get(l) === g && o.delete(l);
215
229
  });
216
- return o.set(l, E), E;
230
+ return o.set(l, g), g;
217
231
  };
218
232
  return new Proxy(t, {
219
233
  get(n, e, l) {
220
234
  if (e === "request") return c;
221
- if (e === L) return !0;
235
+ if (e === j) return !0;
236
+ if (e === "setToken" && typeof n.setToken == "function")
237
+ return (i) => {
238
+ n.setToken(i), z();
239
+ };
222
240
  const f = Reflect.get(n, e, l);
223
241
  return typeof f == "function" ? f.bind(n) : f;
224
242
  }
225
243
  });
226
244
  }
227
- const Q = /^\/(item-locks|drafts|auth)\b/, y = /* @__PURE__ */ new Set();
228
- function V() {
229
- for (const t of [...y]) t();
245
+ const ie = /^\/(item-locks|drafts|auth)\b/, v = /* @__PURE__ */ new Set();
246
+ function ae() {
247
+ for (const t of [...v]) t();
230
248
  }
231
- function te(t) {
249
+ function fe(t) {
232
250
  return t.subscribe((s) => {
233
- s.type === "observerAdded" && s.query.state.fetchStatus === "fetching" && y.size !== 0 && V();
251
+ s.type === "observerAdded" && s.query.state.fetchStatus === "fetching" && v.size !== 0 && ae();
234
252
  });
235
253
  }
236
- function ne(t, s = {}) {
254
+ function de(t, s = {}) {
237
255
  let o = s.open ?? !0, u;
238
256
  const d = /* @__PURE__ */ new Map(), m = () => {
239
257
  const n = [...d.values()];
240
258
  d.clear();
241
259
  for (const e of n) e.release();
242
- }, i = () => {
243
- y.delete(i), m();
260
+ }, a = () => {
261
+ v.delete(a), m();
244
262
  }, r = (n) => {
245
263
  const e = n;
246
- if (o || !j(e) || Q.test(e._path ?? "")) return t.request(n);
247
- const l = k(e), f = d.get(l);
264
+ if (o || !H(e) || ie.test(e._path ?? "")) return t.request(n);
265
+ const l = P(e), f = d.get(l);
248
266
  if (f) return f.promise.then(T);
249
- let a = () => {
267
+ let i = () => {
250
268
  };
251
- const p = new Promise((A) => {
252
- a = A;
269
+ const p = new Promise((E) => {
270
+ i = E;
253
271
  }).then(() => t.request(n));
254
- return d.set(l, { promise: p, release: a }), y.add(i), p;
272
+ return d.set(l, { promise: p, release: i }), v.add(a), p;
255
273
  };
256
274
  return new Proxy(t, {
257
275
  get(n, e, l) {
258
276
  if (e === "request") return r;
259
277
  if (e === "open") return o;
260
278
  if (e === "setOpen")
261
- return (a) => {
279
+ return (i) => {
262
280
  u !== void 0 && (clearTimeout(u), u = void 0);
263
281
  const h = o;
264
- o = a, a && !h && (y.delete(i), m());
282
+ o = i, i && !h && (v.delete(a), m());
265
283
  };
266
284
  if (e === "dispose")
267
285
  return () => {
268
286
  u === void 0 && (u = setTimeout(() => {
269
- u = void 0, o = !0, y.delete(i), m();
287
+ u = void 0, o = !0, v.delete(a), m();
270
288
  }, 0));
271
289
  };
272
290
  const f = Reflect.get(n, e, l);
@@ -275,17 +293,17 @@ function ne(t, s = {}) {
275
293
  });
276
294
  }
277
295
  export {
278
- C as BATCH_READ_LIMIT,
279
- O as COLLECTION_BATCH_LIMIT,
280
- x as COLLECTION_BATCH_WINDOW_MS,
296
+ O as BATCH_READ_LIMIT,
297
+ b as COLLECTION_BATCH_LIMIT,
298
+ Q as COLLECTION_BATCH_WINDOW_MS,
281
299
  R as SETTLED_READ_MS,
282
- U as batchableCollectionMeta,
283
- $ as batchableRead,
284
- ne as createGatedClient,
285
- G as forgetSettledReads,
286
- z as isCoalesced,
287
- J as isSettledRead,
288
- V as releaseGatedReads,
289
- te as releaseGatedReadsOnSharedFetch,
290
- ee as withGetCoalescing
300
+ X as batchableCollectionMeta,
301
+ Y as batchableRead,
302
+ de as createGatedClient,
303
+ k as forgetSettledReads,
304
+ B as isCoalesced,
305
+ re as isSettledRead,
306
+ ae as releaseGatedReads,
307
+ fe as releaseGatedReadsOnSharedFetch,
308
+ le as withGetCoalescing
291
309
  };
@@ -1,34 +1,35 @@
1
- let m = !1, v, c = (e) => e;
2
- const d = [];
3
- let h = null, p = "/api", f, w = null, u = 0, g = null;
1
+ import { isSignedOut as E, isSignedOutError as T, noteUnauthorized as k } from "./signed-out.js";
2
+ let m = !1, v, d = (e) => e;
3
+ const o = [];
4
+ let h = null, p = "/api", f, w = null, c = 0, g = null;
4
5
  function y(e) {
5
6
  const t = e.tagName.toLowerCase(), n = (e.textContent ?? "").trim().slice(0, 40), r = e.getAttribute("aria-label"), i = e.getAttribute("data-testid");
6
7
  return `${t}${i ? `[${i}]` : ""}${r ? ` '${r}'` : n ? ` '${n}'` : ""}`;
7
8
  }
8
- function E(e) {
9
+ function _(e) {
9
10
  typeof window > "u" || window.addEventListener(
10
11
  "click",
11
12
  (t) => {
12
13
  const n = t.target instanceof Element ? t.target.closest('button, a, [role="button"], input, [data-testid]') : null;
13
- n && (n === w ? (u++, u === 3 && (s({
14
+ n && (n === w ? (c++, c === 3 && (s({
14
15
  kind: "rage",
15
16
  route: `${e()} :: ${y(n)}`.slice(0, 300),
16
- duration_ms: u
17
- }), o())) : (w = n, u = 1), g && clearTimeout(g), g = setTimeout(() => {
18
- w = null, u = 0;
17
+ duration_ms: c
18
+ }), u())) : (w = n, c = 1), g && clearTimeout(g), g = setTimeout(() => {
19
+ w = null, c = 0;
19
20
  }, 600));
20
21
  },
21
22
  { capture: !0, passive: !0 }
22
23
  );
23
24
  }
24
- const T = 1e3, k = 1e4, b = 3;
25
- function _(e = b, t = k) {
25
+ const $ = 1e3, M = 1e4, b = 3;
26
+ function D(e = b, t = M) {
26
27
  let n = [];
27
28
  return (r) => (n = n.filter((i) => r - i < t), n.push(r), n.length >= e ? (n = [], !0) : !1);
28
29
  }
29
- function $(e) {
30
+ function A(e) {
30
31
  if (typeof window > "u" || typeof MutationObserver > "u") return;
31
- const t = _();
32
+ const t = D();
32
33
  window.addEventListener(
33
34
  "click",
34
35
  (n) => {
@@ -54,15 +55,19 @@ function $(e) {
54
55
  kind: "dead",
55
56
  route: `${e()} :: ${y(r)}`.slice(0, 300),
56
57
  duration_ms: b
57
- }), o());
58
- }, T);
58
+ }), u());
59
+ }, $);
59
60
  },
60
61
  { capture: !0, passive: !0 }
61
62
  );
62
63
  }
63
- function o() {
64
- if (d.length === 0) return;
65
- const e = JSON.stringify({ events: d.splice(0, d.length) });
64
+ function u() {
65
+ if (o.length === 0) return;
66
+ if (E()) {
67
+ o.length = 0;
68
+ return;
69
+ }
70
+ const e = JSON.stringify({ events: o.splice(0, o.length) });
66
71
  try {
67
72
  const t = f == null ? void 0 : f();
68
73
  !t && typeof navigator.sendBeacon == "function" && navigator.sendBeacon(`${p}/rum`, new Blob([e], { type: "application/json" })) || fetch(`${p}/rum`, {
@@ -74,22 +79,26 @@ function o() {
74
79
  },
75
80
  body: e,
76
81
  keepalive: !0
82
+ }).then(async (r) => {
83
+ if (r.status !== 401) return;
84
+ const i = await r.json().catch(() => null);
85
+ T({ status: 401, response: i }) && k(!1);
77
86
  }).catch(() => {
78
87
  });
79
88
  } catch {
80
89
  }
81
90
  }
82
91
  function s(e) {
83
- d.push({
92
+ o.push({
84
93
  ...e,
85
94
  app: v,
86
95
  vw: typeof window > "u" ? void 0 : window.innerWidth
87
- }), d.length >= 10 ? o() : (h && clearTimeout(h), h = setTimeout(o, 1e4));
96
+ }), o.length >= 10 ? u() : (h && clearTimeout(h), h = setTimeout(u, 1e4));
88
97
  }
89
- const M = /^[A-Za-z0-9._:-]{1,80}$/, D = /^[0-9A-Fa-f-]{36}$/;
90
- function A(e) {
91
- if (!m || !M.test(e.key)) return;
92
- const t = e.roleId && D.test(e.roleId) ? e.roleId.toUpperCase() : void 0;
98
+ const C = /^[A-Za-z0-9._:-]{1,80}$/, B = /^[0-9A-Fa-f-]{36}$/;
99
+ function O(e) {
100
+ if (!m || !C.test(e.key)) return;
101
+ const t = e.roleId && B.test(e.roleId) ? e.roleId.toUpperCase() : void 0;
93
102
  s({
94
103
  kind: "widget",
95
104
  route: `widget:${e.key}`,
@@ -99,19 +108,19 @@ function A(e) {
99
108
  paint_ms: Math.max(0, Math.round(e.paintMs))
100
109
  });
101
110
  }
102
- function C(e) {
111
+ function S(e) {
103
112
  if (!m || typeof window > "u") return;
104
113
  const t = performance.now();
105
114
  requestAnimationFrame(() => {
106
115
  requestAnimationFrame(() => {
107
116
  const n = Math.round(performance.now() - t);
108
- s({ route: c(e), kind: "route", duration_ms: n });
117
+ s({ route: d(e), kind: "route", duration_ms: n });
109
118
  });
110
119
  });
111
120
  }
112
- function B(e) {
121
+ function I(e) {
113
122
  if (m || typeof window > "u" || typeof performance > "u") return;
114
- m = !0, v = e == null ? void 0 : e.app, e != null && e.routePattern && (c = e.routePattern), e != null && e.apiBase && (p = e.apiBase), f = e == null ? void 0 : e.getToken, E(() => c(window.location.pathname)), $(() => c(window.location.pathname));
123
+ m = !0, v = e == null ? void 0 : e.app, e != null && e.routePattern && (d = e.routePattern), e != null && e.apiBase && (p = e.apiBase), f = e == null ? void 0 : e.getToken, _(() => d(window.location.pathname)), A(() => d(window.location.pathname));
115
124
  const t = performance.getEntriesByType("navigation")[0];
116
125
  let n = null;
117
126
  try {
@@ -124,23 +133,23 @@ function B(e) {
124
133
  setTimeout(() => {
125
134
  const i = performance.getEntriesByName("first-contentful-paint")[0];
126
135
  s({
127
- route: c(window.location.pathname),
136
+ route: d(window.location.pathname),
128
137
  kind: "load",
129
138
  ttfb_ms: t ? Math.round(t.responseStart) : void 0,
130
139
  fcp_ms: i ? Math.round(i.startTime) : void 0,
131
140
  lcp_ms: n ?? void 0,
132
141
  duration_ms: t ? Math.round(t.loadEventEnd || t.domContentLoadedEventEnd) : void 0
133
142
  });
134
- }, 6e3), window.addEventListener("pagehide", o), document.addEventListener("visibilitychange", () => {
135
- document.visibilityState === "hidden" && o();
143
+ }, 6e3), window.addEventListener("pagehide", u), document.addEventListener("visibilitychange", () => {
144
+ document.visibilityState === "hidden" && u();
136
145
  });
137
146
  }
138
147
  export {
139
148
  b as DEAD_BURST,
140
- T as DEAD_WAIT_MS,
141
- k as DEAD_WINDOW_MS,
142
- _ as createDeadClickCounter,
143
- C as rumRouteChange,
144
- A as rumWidget,
145
- B as startRum
149
+ $ as DEAD_WAIT_MS,
150
+ M as DEAD_WINDOW_MS,
151
+ D as createDeadClickCounter,
152
+ S as rumRouteChange,
153
+ O as rumWidget,
154
+ I as startRum
146
155
  };
@@ -0,0 +1,39 @@
1
+ import { reportClientCrash as a } from "./client-crash.js";
2
+ const u = "Something went wrong — it’s been reported", c = /failed to fetch|load failed|networkerror|network request failed|network error/i;
3
+ function l(t) {
4
+ var s;
5
+ const r = t, e = (r == null ? void 0 : r.status) ?? ((s = r == null ? void 0 : r.response) == null ? void 0 : s.status);
6
+ return typeof e == "number" ? e : null;
7
+ }
8
+ function f(t) {
9
+ return !(t instanceof Error) || l(t) != null || t.response != null || c.test(t.message) ? !1 : t instanceof TypeError || t instanceof ReferenceError || t instanceof RangeError;
10
+ }
11
+ const d = /^(bad request|unauthorized|forbidden|not found|conflict|unprocessable entity|too many requests|internal server error|bad gateway|service unavailable|gateway timeout)$/i;
12
+ function m(t) {
13
+ var s;
14
+ const r = t, e = [(s = r == null ? void 0 : r.response) == null ? void 0 : s.data, r == null ? void 0 : r.response];
15
+ for (const o of e) {
16
+ const n = o == null ? void 0 : o.error;
17
+ if (typeof n == "string" && n.trim() && !d.test(n.trim())) return n.trim();
18
+ }
19
+ for (const o of e) {
20
+ const n = o == null ? void 0 : o.message;
21
+ if (typeof n == "string" && n.trim()) return n.trim();
22
+ }
23
+ return null;
24
+ }
25
+ function g(t, r = "Failed") {
26
+ const e = m(t);
27
+ return e || (f(t) ? u : t instanceof Error ? t.message || r : typeof t == "string" && t.trim() ? t : r);
28
+ }
29
+ const i = /* @__PURE__ */ new WeakSet();
30
+ function E(t, r) {
31
+ !t || !f(r) || i.has(r) || (i.add(r), a(t, r, null).catch(() => {
32
+ }));
33
+ }
34
+ export {
35
+ u as SOMETHING_WENT_WRONG,
36
+ f as isCodeError,
37
+ E as reportCodeError,
38
+ g as userErrorMessage
39
+ };
@@ -3,19 +3,23 @@ const i = 1e3;
3
3
  function o() {
4
4
  return Date.now() + s;
5
5
  }
6
- function f(t) {
7
- s = Number.isFinite(t) && Math.abs(t) >= i ? Math.round(t) : 0;
6
+ function f() {
7
+ return s;
8
8
  }
9
9
  function u(t) {
10
+ s = Number.isFinite(t) && Math.abs(t) >= i ? Math.round(t) : 0;
11
+ }
12
+ function c(t) {
10
13
  let e = null;
11
- for (const n of t) {
12
- const r = n.received - n.sent;
13
- !Number.isFinite(r) || r < 0 || !Number.isFinite(n.server) || (!e || r < e.received - e.sent) && (e = n);
14
+ for (const r of t) {
15
+ const n = r.received - r.sent;
16
+ !Number.isFinite(n) || n < 0 || !Number.isFinite(r.server) || (!e || n < e.received - e.sent) && (e = r);
14
17
  }
15
18
  return e ? e.server - (e.sent + (e.received - e.sent) / 2) : null;
16
19
  }
17
20
  export {
18
- u as measureClockOffset,
21
+ c as measureClockOffset,
22
+ f as serverClockOffset,
19
23
  o as serverNow,
20
- f as setServerClockOffset
24
+ u as setServerClockOffset
21
25
  };