@nivaro/react 0.3.7 → 0.3.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,18 +1,18 @@
1
- var b = Object.defineProperty;
2
- var m = (n, t, e) => t in n ? b(n, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : n[t] = e;
3
- var d = (n, t, e) => m(n, typeof t != "symbol" ? t + "" : t, e);
4
- const K = 2e6, M = 6e4, O = 6e4, k = 2e7, U = 6e5, N = 2e3, C = 6e4, D = 864e5;
1
+ var m = Object.defineProperty;
2
+ var B = (n, t, e) => t in n ? m(n, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : n[t] = e;
3
+ var d = (n, t, e) => B(n, typeof t != "symbol" ? t + "" : t, e);
4
+ const K = 2e6, M = 6e4, k = 6e4, O = 2e7, U = 6e5, C = 2e3, N = 6e4, D = 864e5;
5
5
  function Q(n, t = 2e6) {
6
6
  const e = [];
7
- let r = [], s = 2;
8
- for (const o of n) {
9
- let i = 0;
7
+ let r = [], i = 2;
8
+ for (const u of n) {
9
+ let s = 0;
10
10
  try {
11
- i = JSON.stringify(o).length + 1;
11
+ s = JSON.stringify(u).length + 1;
12
12
  } catch {
13
13
  continue;
14
14
  }
15
- r.length > 0 && s + i > t && (e.push(r), r = [], s = 2), r.push(o), s += i;
15
+ r.length > 0 && i + s > t && (e.push(r), r = [], i = 2), r.push(u), i += s;
16
16
  }
17
17
  return r.length > 0 && e.push(r), e;
18
18
  }
@@ -20,9 +20,13 @@ function T(n, t = Math.random) {
20
20
  const e = Math.max(1, Math.floor(n)), r = Math.min(6e4, 2e3 * 2 ** (e - 1));
21
21
  return Math.round(r / 2 + t() * (r / 2));
22
22
  }
23
- function B(n) {
23
+ function S(n) {
24
24
  return n === 409 ? "closed" : n === 413 || n === 400 ? "drop-chunk" : n === 408 || n === 429 ? "retry" : typeof n == "number" && n >= 400 && n < 500 ? "abandon" : "retry";
25
25
  }
26
+ function R(n) {
27
+ const t = S(n);
28
+ return t === "closed" || t === "abandon" ? "stop" : "next";
29
+ }
26
30
  function E(n) {
27
31
  var r;
28
32
  const t = n, e = typeof (t == null ? void 0 : t.status) == "number" ? t.status : (r = t == null ? void 0 : t.response) == null ? void 0 : r.status;
@@ -36,10 +40,10 @@ function q(n) {
36
40
  }
37
41
  }
38
42
  function I(n, t = 0) {
39
- const e = S(n, t);
43
+ const e = b(n, t);
40
44
  return JSON.stringify({ seq: n.seq, events: n.events, ...e });
41
45
  }
42
- function S(n, t = 0) {
46
+ function b(n, t = 0) {
43
47
  const e = {};
44
48
  return n.route && (e.route = n.route), n.build && (e.build = n.build), t > 0 && (e.retries = t), e;
45
49
  }
@@ -50,38 +54,38 @@ function v() {
50
54
  n.set(t(e.recordingId, e.seq), e);
51
55
  },
52
56
  async list(e) {
53
- return [...n.values()].filter((r) => r.recordingId === e).sort((r, s) => r.seq - s.seq);
57
+ return [...n.values()].filter((r) => r.recordingId === e).sort((r, i) => r.seq - i.seq);
54
58
  },
55
59
  async remove(e, r) {
56
60
  n.delete(t(e, r));
57
61
  },
58
62
  async clear(e) {
59
- for (const [r, s] of n) s.recordingId === e && n.delete(r);
63
+ for (const [r, i] of n) i.recordingId === e && n.delete(r);
60
64
  },
61
65
  async prune(e) {
62
- for (const [r, s] of n) s.at < e && n.delete(r);
66
+ for (const [r, i] of n) i.at < e && n.delete(r);
63
67
  }
64
68
  };
65
69
  }
66
70
  const _ = "nivaro-replay-queue", p = "chunks";
67
- function w(n) {
71
+ function x(n) {
68
72
  const t = typeof indexedDB < "u" ? indexedDB : null, e = v();
69
73
  if (!t) return e;
70
- const r = new Promise((i) => {
74
+ const r = new Promise((s) => {
71
75
  try {
72
- const u = t.open(_, 1);
73
- u.onupgradeneeded = () => {
74
- u.result.createObjectStore(p, { keyPath: ["recordingId", "seq"] }).createIndex("at", "at");
75
- }, u.onsuccess = () => i(u.result), u.onerror = () => i(null), u.onblocked = () => i(null);
76
+ const o = t.open(_, 1);
77
+ o.onupgradeneeded = () => {
78
+ o.result.createObjectStore(p, { keyPath: ["recordingId", "seq"] }).createIndex("at", "at");
79
+ }, o.onsuccess = () => s(o.result), o.onerror = () => s(null), o.onblocked = () => s(null);
76
80
  } catch {
77
- i(null);
81
+ s(null);
78
82
  }
79
- }), s = (i) => IDBKeyRange.bound([i, -1 / 0], [i, 1 / 0]);
80
- async function o(i, u, h, c) {
83
+ }), i = (s) => IDBKeyRange.bound([s, -1 / 0], [s, 1 / 0]);
84
+ async function u(s, o, h, c) {
81
85
  const l = await r;
82
86
  return l ? new Promise((a) => {
83
87
  try {
84
- const f = l.transaction(p, i), g = u(f.objectStore(p));
88
+ const f = l.transaction(p, s), g = o(f.objectStore(p));
85
89
  f.oncomplete = () => a(g ? g() : c), f.onerror = () => a(c), f.onabort = () => a(c);
86
90
  } catch {
87
91
  a(c);
@@ -89,56 +93,56 @@ function w(n) {
89
93
  }) : h();
90
94
  }
91
95
  return {
92
- put: (i) => o(
96
+ put: (s) => u(
93
97
  "readwrite",
94
- (u) => {
95
- u.put(i);
98
+ (o) => {
99
+ o.put(s);
96
100
  },
97
- () => e.put(i),
101
+ () => e.put(s),
98
102
  void 0
99
103
  ),
100
- list: (i) => o(
104
+ list: (s) => u(
101
105
  "readonly",
102
- (u) => {
103
- const h = u.getAll(s(i));
106
+ (o) => {
107
+ const h = o.getAll(i(s));
104
108
  return () => (h.result ?? []).sort((c, l) => c.seq - l.seq);
105
109
  },
106
- () => e.list(i),
110
+ () => e.list(s),
107
111
  []
108
112
  ),
109
- remove: (i, u) => o(
113
+ remove: (s, o) => u(
110
114
  "readwrite",
111
115
  (h) => {
112
- h.delete([i, u]);
116
+ h.delete([s, o]);
113
117
  },
114
- () => e.remove(i, u),
118
+ () => e.remove(s, o),
115
119
  void 0
116
120
  ),
117
- clear: (i) => o(
121
+ clear: (s) => u(
118
122
  "readwrite",
119
- (u) => {
120
- u.delete(s(i));
123
+ (o) => {
124
+ o.delete(i(s));
121
125
  },
122
- () => e.clear(i),
126
+ () => e.clear(s),
123
127
  void 0
124
128
  ),
125
- prune: (i) => o(
129
+ prune: (s) => u(
126
130
  "readwrite",
127
- (u) => {
128
- const h = u.index("at").openCursor(IDBKeyRange.upperBound(i, !0));
131
+ (o) => {
132
+ const h = o.index("at").openCursor(IDBKeyRange.upperBound(s, !0));
129
133
  h.onsuccess = () => {
130
134
  const c = h.result;
131
135
  c && (c.delete(), c.continue());
132
136
  };
133
137
  },
134
- () => e.prune(i),
138
+ () => e.prune(s),
135
139
  void 0
136
140
  )
137
141
  };
138
142
  }
139
143
  let y = null;
140
- function R() {
141
- return y || (y = w()), y;
144
+ function F() {
145
+ return y || (y = x()), y;
142
146
  }
143
147
  function P() {
144
148
  try {
@@ -147,7 +151,7 @@ function P() {
147
151
  return null;
148
152
  }
149
153
  }
150
- function F(n, t) {
154
+ function Y(n, t) {
151
155
  try {
152
156
  const e = n == null ? void 0 : n.getItem(t);
153
157
  if (!e) return null;
@@ -157,34 +161,34 @@ function F(n, t) {
157
161
  return null;
158
162
  }
159
163
  }
160
- function Y(n, t, e) {
164
+ function H(n, t, e) {
161
165
  try {
162
166
  n == null || n.setItem(t, JSON.stringify(e));
163
167
  } catch {
164
168
  }
165
169
  }
166
- function H(n, t) {
170
+ function J(n, t) {
167
171
  try {
168
172
  n == null || n.removeItem(t);
169
173
  } catch {
170
174
  }
171
175
  }
172
- function J(n, t, e) {
176
+ function L(n, t, e) {
173
177
  if (!n) return !1;
174
178
  const r = t - n.lastActivityAt;
175
179
  return !(r < 0 || r > 6e5);
176
180
  }
177
- function x(n, t) {
181
+ function w(n, t) {
178
182
  const e = [];
179
183
  let r = t;
180
- for (const s of n) {
181
- const o = I(s), i = q(o);
182
- if (i > r) break;
183
- e.push({ chunk: s, body: o }), r -= i;
184
+ for (const i of n) {
185
+ const u = I(i), s = q(u);
186
+ if (s > r) break;
187
+ e.push({ chunk: i, body: u }), r -= s;
184
188
  }
185
189
  return e;
186
190
  }
187
- class L {
191
+ class W {
188
192
  constructor(t) {
189
193
  d(this, "recordingId", null);
190
194
  d(this, "nextSeq", 0);
@@ -195,6 +199,12 @@ class L {
195
199
  * up from sessionStorage until the server has taken a chunk for it.
196
200
  */
197
201
  d(this, "trusted", !0);
202
+ /**
203
+ * The recording was refused for good (closed / abandoned): nothing more is
204
+ * queued or sent for it until `begin()` / `rebase()` points the uploader at
205
+ * another one. A pagehide keepalive after the refusal sends nothing.
206
+ */
207
+ d(this, "stopped", !1);
198
208
  d(this, "pending", []);
199
209
  d(this, "bytesQueued", 0);
200
210
  d(this, "restored", /* @__PURE__ */ new WeakSet());
@@ -212,10 +222,10 @@ class L {
212
222
  * this tab left in the store for it; they go first.
213
223
  */
214
224
  begin(t, e = 0, r = {}) {
215
- this.recordingId = t, this.nextSeq = e, this.trusted = r.trusted ?? !0, this.attempt = 0, this.pending = [], this.bytesQueued = 0;
216
- for (const s of r.restored ?? [])
217
- s.recordingId === t && (this.restored.add(s), this.pending.push(s), this.bytesQueued += s.bytes, s.seq >= this.nextSeq && (this.nextSeq = s.seq + 1));
218
- this.pending.sort((s, o) => s.seq - o.seq), this.enforceBound();
225
+ this.recordingId = t, this.nextSeq = e, this.trusted = r.trusted ?? !0, this.stopped = !1, this.attempt = 0, this.pending = [], this.bytesQueued = 0;
226
+ for (const i of r.restored ?? [])
227
+ i.recordingId === t && (this.restored.add(i), this.pending.push(i), this.bytesQueued += i.bytes, i.seq >= this.nextSeq && (this.nextSeq = i.seq + 1));
228
+ this.pending.sort((i, u) => i.seq - u.seq), this.enforceBound();
219
229
  }
220
230
  hasPending() {
221
231
  return this.pending.length > 0;
@@ -235,13 +245,13 @@ class L {
235
245
  * names the route it was recorded on and the build (#1368).
236
246
  */
237
247
  enqueue(t, e = {}) {
238
- if (!this.recordingId || t.length === 0) return null;
248
+ if (!this.recordingId || this.stopped || t.length === 0) return null;
239
249
  let r = 2;
240
250
  try {
241
251
  r = JSON.stringify(t).length;
242
252
  } catch {
243
253
  }
244
- const s = {
254
+ const i = {
245
255
  recordingId: this.recordingId,
246
256
  seq: this.nextSeq++,
247
257
  events: t,
@@ -250,7 +260,7 @@ class L {
250
260
  ...e.route ? { route: e.route } : {},
251
261
  ...e.build ? { build: e.build } : {}
252
262
  };
253
- return this.pending.push(s), this.bytesQueued += r, this.store.put(s), this.enforceBound(), s;
263
+ return this.pending.push(i), this.bytesQueued += r, this.store.put(i), this.enforceBound(), i;
254
264
  }
255
265
  /** Oldest first, but never the last chunk standing. */
256
266
  enforceBound() {
@@ -277,7 +287,7 @@ class L {
277
287
  * Callers keep this single-flight.
278
288
  */
279
289
  async drain(t = !1) {
280
- for (; this.recordingId && this.pending.length > 0; ) {
290
+ for (; this.recordingId && !this.stopped && this.pending.length > 0; ) {
281
291
  if (!this.online()) return "offline";
282
292
  const e = this.pending[0], r = t && e.bytes <= 6e4;
283
293
  this.sending = e, this.sendingKeepaliveBytes = r ? e.bytes : 0;
@@ -287,21 +297,23 @@ class L {
287
297
  e.seq,
288
298
  e.events,
289
299
  r,
290
- S(e, this.attempt)
300
+ b(e, this.attempt)
291
301
  ), this.trusted = !0, this.attempt = 0, this.forget(e);
292
- } catch (s) {
293
- const o = B(E(s));
294
- if (o === "retry")
302
+ } catch (i) {
303
+ const u = E(i), s = S(u);
304
+ if (s === "retry")
295
305
  return this.attempt++, "retry";
296
- if (o === "drop-chunk") {
297
- console.warn(`[session-recorder] chunk ${e.seq} too large — dropped`), this.trusted = !0, this.forget(e);
306
+ if (s === "drop-chunk") {
307
+ console.warn(
308
+ `[session-recorder] chunk ${e.seq} refused (too large or malformed) — dropped`
309
+ ), this.trusted = !0, this.forget(e);
298
310
  continue;
299
311
  }
300
- if (!this.trusted) {
301
- for (const i of [...this.pending]) this.restored.has(i) && this.forget(i);
312
+ if (!this.trusted && u !== 401) {
313
+ for (const o of [...this.pending]) this.restored.has(o) && this.forget(o);
302
314
  return "stale";
303
315
  }
304
- return this.discard(), o === "closed" ? "closed" : "abandoned";
316
+ return this.discard(), this.stopped = !0, s === "closed" ? "closed" : "abandoned";
305
317
  } finally {
306
318
  this.sending = null, this.sendingKeepaliveBytes = 0;
307
319
  }
@@ -313,11 +325,11 @@ class L {
313
325
  * restart at 0 in the same order.
314
326
  */
315
327
  rebase(t) {
316
- const e = this.recordingId, r = this.pending.filter((s) => !this.restored.has(s));
317
- e && e !== t && this.store.clear(e), this.recordingId = t, this.nextSeq = 0, this.trusted = !0, this.attempt = 0, this.pending = [], this.bytesQueued = 0;
318
- for (const s of r) {
319
- const o = { ...s, recordingId: t, seq: this.nextSeq++ };
320
- this.pending.push(o), this.bytesQueued += o.bytes, this.store.put(o);
328
+ const e = this.recordingId, r = this.pending.filter((i) => !this.restored.has(i));
329
+ e && e !== t && this.store.clear(e), this.recordingId = t, this.nextSeq = 0, this.trusted = !0, this.stopped = !1, this.attempt = 0, this.pending = [], this.bytesQueued = 0;
330
+ for (const i of r) {
331
+ const u = { ...i, recordingId: t, seq: this.nextSeq++ };
332
+ this.pending.push(u), this.bytesQueued += u.bytes, this.store.put(u);
321
333
  }
322
334
  }
323
335
  /**
@@ -328,33 +340,35 @@ class L {
328
340
  * the server ignores a seq it already holds.
329
341
  */
330
342
  keepaliveBatch(t = 6e4) {
343
+ if (this.stopped) return [];
331
344
  const e = this.pending.filter((r) => r !== this.sending);
332
- return x(e, t - this.sendingKeepaliveBytes);
345
+ return w(e, t - this.sendingKeepaliveBytes);
333
346
  }
334
347
  }
335
348
  export {
336
- N as BACKOFF_BASE_MS,
337
- C as BACKOFF_MAX_MS,
349
+ C as BACKOFF_BASE_MS,
350
+ N as BACKOFF_MAX_MS,
338
351
  K as CHUNK_BYTES,
339
- O as KEEPALIVE_BUDGET,
352
+ k as KEEPALIVE_BUDGET,
340
353
  M as KEEPALIVE_CHUNK_BYTES,
341
354
  D as ORPHAN_TTL_MS,
342
- k as QUEUE_MAX_BYTES,
355
+ O as QUEUE_MAX_BYTES,
343
356
  U as RESUME_WINDOW_MS,
344
- L as ReplayUploader,
357
+ W as ReplayUploader,
345
358
  T as backoffDelay,
346
359
  I as chunkBody,
347
- S as chunkExtra,
348
- B as classifyUploadError,
349
- H as clearResume,
360
+ b as chunkExtra,
361
+ S as classifyUploadError,
362
+ J as clearResume,
363
+ R as clipChunkFailure,
350
364
  E as errorStatus,
351
- w as idbChunkStore,
352
- J as isResumable,
365
+ x as idbChunkStore,
366
+ L as isResumable,
353
367
  v as memoryChunkStore,
354
- x as packKeepalive,
355
- F as readResume,
368
+ w as packKeepalive,
369
+ Y as readResume,
356
370
  P as sessionStore,
357
- R as sharedChunkStore,
371
+ F as sharedChunkStore,
358
372
  Q as splitBySize,
359
- Y as writeResume
373
+ H as writeResume
360
374
  };