@nivaro/react 0.3.11 → 0.3.12
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.
- package/dist/full.css +1 -1
- package/dist/hooks/useSessionRecorder.js +109 -102
- package/dist/shared/components/ProfileView.js +115 -109
- package/dist/shared/components/chat/ChatPanel.js +492 -472
- package/dist/shared/components/item-edit/UserChip.js +301 -233
- package/dist/shared/components/profile/PersonAdminTools.js +168 -144
- package/dist/shared/components/profile/PersonProfile.js +42 -41
- package/dist/shared/components/profile/session-actions.js +52 -0
- package/dist/shared/lib/replay-checkout.js +20 -0
- package/package.json +1 -1
|
@@ -1,15 +1,16 @@
|
|
|
1
|
-
import { endSessionRecording as $, appendSessionRecordingEvents as X, sessionRecordingEnabled as ce, startSessionRecording as
|
|
1
|
+
import { endSessionRecording as $, appendSessionRecordingEvents as X, sessionRecordingEnabled as ce, startSessionRecording as L } from "@nivaro/sdk";
|
|
2
2
|
import { useRef as de, useEffect as fe } from "react";
|
|
3
|
-
import { sessionStore as pe, sharedChunkStore as he, ReplayUploader as me, clearResume as P, ORPHAN_TTL_MS as we, readResume as
|
|
4
|
-
import { useAutoRecord as
|
|
5
|
-
import { useOptionalNivaroClient as
|
|
3
|
+
import { sessionStore as pe, sharedChunkStore as he, ReplayUploader as me, clearResume as P, ORPHAN_TTL_MS as we, readResume as ye, isResumable as ge, splitBySize as Z, writeResume as ve, KEEPALIVE_CHUNK_BYTES as be, CHUNK_BYTES as Re, backoffDelay as Se, errorStatus as ke, clipChunkFailure as Ce } from "./replayUploadQueue.js";
|
|
4
|
+
import { useAutoRecord as Ee } from "./useAutoRecord.js";
|
|
5
|
+
import { useOptionalNivaroClient as Ae } from "../shared/context.js";
|
|
6
6
|
import { normalizeReplayMasking as B, buildReplayMaskingOptions as z } from "../shared/lib/replay-masking.js";
|
|
7
|
-
import { normalizeReplaySampling as x, replaySampleDraw as Ie, currentReplayRoute as
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
|
|
12
|
-
|
|
7
|
+
import { normalizeReplaySampling as x, replaySampleDraw as Ie, currentReplayRoute as D, isReplayRouteSampled as Y, attributeChunkRoutes as ee } from "../shared/lib/replay-sampling.js";
|
|
8
|
+
import { noteReplayEvent as _e, createReplayCheckoutState as De } from "../shared/lib/replay-checkout.js";
|
|
9
|
+
import { emitReplayTap as Te, setReplayRecorderMode as N, registerReplayCapture as qe, clipEndOffset as Le, withClipKind as Pe } from "../shared/lib/replay-capture.js";
|
|
10
|
+
import { instrumentConsole as Ne, instrumentRequests as Fe, redactSecrets as Me } from "../shared/lib/replay-context.js";
|
|
11
|
+
import { instrumentSocket as Oe } from "../shared/lib/replay-socket.js";
|
|
12
|
+
const Ue = "nivaro-react@0.3.12", j = 1e4, We = 150, He = 3e3, Ke = 600, $e = (n) => `nvr_replay_resume${n ? `:${n}` : ""}`, G = () => typeof navigator > "u" || navigator.onLine !== !1;
|
|
13
|
+
function Be(n) {
|
|
13
14
|
return typeof n.url != "string" || typeof fetch != "function" ? null : (f, a) => {
|
|
14
15
|
const u = typeof n.getToken == "function" ? n.getToken() : void 0, d = { "Content-Type": "application/json" };
|
|
15
16
|
return u && (d.Authorization = `Bearer ${u}`), fetch(`${n.url}/api/session-recordings/${f}/events`, {
|
|
@@ -21,32 +22,32 @@ function Ke(n) {
|
|
|
21
22
|
});
|
|
22
23
|
};
|
|
23
24
|
}
|
|
24
|
-
async function
|
|
25
|
-
const l = Z(u), { routes:
|
|
25
|
+
async function ze(n, f, a, u, d) {
|
|
26
|
+
const l = Z(u), { routes: R } = ee(l, d.startRoute);
|
|
26
27
|
for (const [c, e] of l.entries()) {
|
|
27
28
|
const g = a();
|
|
28
29
|
try {
|
|
29
30
|
await n.request(
|
|
30
31
|
X(f, g, e, {
|
|
31
|
-
route:
|
|
32
|
+
route: R[c],
|
|
32
33
|
...d.build ? { build: d.build } : {}
|
|
33
34
|
})
|
|
34
35
|
);
|
|
35
36
|
} catch (v) {
|
|
36
|
-
const
|
|
37
|
-
if (
|
|
38
|
-
|
|
37
|
+
const b = ke(v);
|
|
38
|
+
if (Ce(b) === "stop") return "closed";
|
|
39
|
+
b === 413 && console.warn(`[session-recorder] chunk ${g} too large — dropped`);
|
|
39
40
|
}
|
|
40
41
|
}
|
|
41
42
|
return "ok";
|
|
42
43
|
}
|
|
43
|
-
const
|
|
44
|
-
let J = !1,
|
|
45
|
-
async function
|
|
46
|
-
if (!
|
|
44
|
+
const xe = 3e4, Ye = 3e4;
|
|
45
|
+
let J = !1, y = null, k = null;
|
|
46
|
+
async function je(n = "error") {
|
|
47
|
+
if (!k) return null;
|
|
47
48
|
try {
|
|
48
49
|
return await Promise.race([
|
|
49
|
-
|
|
50
|
+
k(n),
|
|
50
51
|
new Promise((f) => setTimeout(() => f(null), 4e3))
|
|
51
52
|
]);
|
|
52
53
|
} catch {
|
|
@@ -63,27 +64,27 @@ async function Q() {
|
|
|
63
64
|
}
|
|
64
65
|
}
|
|
65
66
|
function V(n, f) {
|
|
66
|
-
const a =
|
|
67
|
+
const a = Ne(n), u = Fe(n), d = Oe(n), l = () => {
|
|
67
68
|
f == null || f();
|
|
68
69
|
try {
|
|
69
70
|
n("route", {
|
|
70
|
-
path:
|
|
71
|
+
path: Me(window.location.pathname + window.location.search)
|
|
71
72
|
});
|
|
72
73
|
} catch {
|
|
73
74
|
}
|
|
74
|
-
},
|
|
75
|
+
}, R = history.pushState.bind(history), c = history.replaceState.bind(history);
|
|
75
76
|
return history.pushState = (...e) => {
|
|
76
|
-
|
|
77
|
+
R(...e), l();
|
|
77
78
|
}, history.replaceState = (...e) => {
|
|
78
79
|
c(...e), l();
|
|
79
80
|
}, window.addEventListener("popstate", l), l(), () => {
|
|
80
|
-
a(), u(), d(), history.pushState =
|
|
81
|
+
a(), u(), d(), history.pushState = R, history.replaceState = c, window.removeEventListener("popstate", l);
|
|
81
82
|
};
|
|
82
83
|
}
|
|
83
|
-
function
|
|
84
|
-
const f =
|
|
85
|
-
|
|
86
|
-
const
|
|
84
|
+
function st(n = {}) {
|
|
85
|
+
const f = Ae(), a = n.client ?? f, u = n.app, d = n.disabled ?? !1, l = n.build ?? Ue;
|
|
86
|
+
Ee({ client: a, disabled: d });
|
|
87
|
+
const R = de({
|
|
87
88
|
buffer: [],
|
|
88
89
|
stop: null,
|
|
89
90
|
uninstrument: null,
|
|
@@ -102,94 +103,94 @@ function nt(n = {}) {
|
|
|
102
103
|
fe(() => {
|
|
103
104
|
if (!a || d || typeof window > "u") return;
|
|
104
105
|
let c = !1;
|
|
105
|
-
const e =
|
|
106
|
+
const e = R.current;
|
|
106
107
|
e.dead = !1;
|
|
107
|
-
const g = a, v = pe(),
|
|
108
|
+
const g = a, v = pe(), b = $e(u), C = he(), E = Be(g), te = async (t, r, i, h, w = {}) => {
|
|
108
109
|
if (!h || !E) {
|
|
109
|
-
await g.request(X(t, r, i,
|
|
110
|
+
await g.request(X(t, r, i, w));
|
|
110
111
|
return;
|
|
111
112
|
}
|
|
112
|
-
const
|
|
113
|
-
if (!
|
|
114
|
-
}, o = new me({ store:
|
|
115
|
-
let
|
|
116
|
-
const re = () => document.readyState === "complete" && Date.now() - e.lastNavAt >=
|
|
117
|
-
function
|
|
118
|
-
o.recordingId &&
|
|
113
|
+
const s = await E(t, JSON.stringify({ seq: r, events: i, ...w }));
|
|
114
|
+
if (!s.ok) throw Object.assign(new Error(`HTTP ${s.status}`), { status: s.status });
|
|
115
|
+
}, o = new me({ store: C, send: te, online: G });
|
|
116
|
+
let S = null, A = 0;
|
|
117
|
+
const re = () => document.readyState === "complete" && Date.now() - e.lastNavAt >= He;
|
|
118
|
+
function I() {
|
|
119
|
+
o.recordingId && ve(v, b, {
|
|
119
120
|
recordingId: o.recordingId,
|
|
120
121
|
nextSeq: o.nextSeq,
|
|
121
122
|
startedAt: e.startedAt,
|
|
122
123
|
lastActivityAt: Date.now()
|
|
123
124
|
});
|
|
124
125
|
}
|
|
125
|
-
function
|
|
126
|
-
|
|
126
|
+
function _() {
|
|
127
|
+
S && clearTimeout(S), S = null, A = 0;
|
|
127
128
|
}
|
|
128
129
|
function ne() {
|
|
129
|
-
|
|
130
|
+
_();
|
|
130
131
|
const t = Se(o.attempt);
|
|
131
|
-
A = Date.now() + t,
|
|
132
|
-
|
|
132
|
+
A = Date.now() + t, S = setTimeout(() => {
|
|
133
|
+
S = null, A = 0, m(!0);
|
|
133
134
|
}, t);
|
|
134
135
|
}
|
|
135
|
-
function
|
|
136
|
+
function F() {
|
|
136
137
|
var t;
|
|
137
|
-
e.dead = !0, (t = e.stop) == null || t.call(e), e.stop = null, e.buffer = [],
|
|
138
|
+
e.dead = !0, (t = e.stop) == null || t.call(e), e.stop = null, e.buffer = [], _(), o.discard(), o.stopped = !0, P(v, b);
|
|
138
139
|
}
|
|
139
|
-
function
|
|
140
|
+
function M(t) {
|
|
140
141
|
if (e.buffer.length === 0 || !o.recordingId) return;
|
|
141
142
|
const r = e.buffer;
|
|
142
143
|
e.buffer = [];
|
|
143
144
|
const i = Z(r, t ? be : Re), { routes: h } = ee(i, e.bufferRoute);
|
|
144
|
-
for (const [
|
|
145
|
-
o.enqueue(
|
|
146
|
-
|
|
145
|
+
for (const [w, s] of i.entries())
|
|
146
|
+
o.enqueue(s, { route: h[w], ...l ? { build: l } : {} });
|
|
147
|
+
I();
|
|
147
148
|
}
|
|
148
149
|
async function oe(t) {
|
|
149
150
|
if (!c) {
|
|
150
151
|
if (t === "retry") ne();
|
|
151
|
-
else if (t === "closed" || t === "abandoned")
|
|
152
|
+
else if (t === "closed" || t === "abandoned") F();
|
|
152
153
|
else if (t === "stale")
|
|
153
154
|
try {
|
|
154
|
-
const r = await g.request(
|
|
155
|
+
const r = await g.request(L(u));
|
|
155
156
|
if (c) return;
|
|
156
|
-
o.rebase(r.data.id), e.startedAt = Date.now(),
|
|
157
|
+
o.rebase(r.data.id), e.startedAt = Date.now(), I(), e.flushAfter = !0;
|
|
157
158
|
} catch {
|
|
158
|
-
|
|
159
|
+
F();
|
|
159
160
|
}
|
|
160
161
|
}
|
|
161
162
|
}
|
|
162
163
|
function m(t = !1, r = !1) {
|
|
163
|
-
return e.inFlight ? (t && (e.flushAfter = !0), e.inFlight) : e.dead || !o.recordingId || !t && !re() && e.buffer.length <
|
|
164
|
+
return e.inFlight ? (t && (e.flushAfter = !0), e.inFlight) : e.dead || !o.recordingId || !t && !re() && e.buffer.length < Ke || (M(r), !o.hasPending() || Date.now() < A) ? Promise.resolve() : (e.inFlight = o.drain(r).then(oe).catch(() => {
|
|
164
165
|
}).finally(() => {
|
|
165
166
|
e.inFlight = null, e.flushAfter && (e.flushAfter = !1, m(!0));
|
|
166
167
|
}), e.inFlight);
|
|
167
168
|
}
|
|
168
|
-
function
|
|
169
|
+
function O() {
|
|
169
170
|
const t = window.requestIdleCallback;
|
|
170
171
|
t ? t(() => void m(), { timeout: j }) : m();
|
|
171
172
|
}
|
|
172
173
|
async function ie() {
|
|
173
174
|
const t = await Q();
|
|
174
175
|
if (c || !t) return;
|
|
175
|
-
|
|
176
|
-
const r =
|
|
177
|
-
if (r &&
|
|
178
|
-
const s = await
|
|
176
|
+
C.prune(Date.now() - we);
|
|
177
|
+
const r = ye(v, b);
|
|
178
|
+
if (r && ge(r, Date.now())) {
|
|
179
|
+
const s = await C.list(r.recordingId);
|
|
179
180
|
if (c) return;
|
|
180
181
|
o.begin(r.recordingId, r.nextSeq, { trusted: !1, restored: s }), e.startedAt = r.startedAt;
|
|
181
182
|
} else {
|
|
182
|
-
r && (
|
|
183
|
-
const s = await g.request(
|
|
183
|
+
r && (C.clear(r.recordingId), P(v, b));
|
|
184
|
+
const s = await g.request(L(u));
|
|
184
185
|
if (c) return;
|
|
185
186
|
o.begin(s.data.id), e.startedAt = Date.now();
|
|
186
187
|
}
|
|
187
|
-
|
|
188
|
+
I(), e.lastNavAt = Date.now();
|
|
188
189
|
const i = Ie(v);
|
|
189
|
-
e.route =
|
|
190
|
+
e.route = D(), e.bufferRoute = e.route, e.sampled = Y(q, e.route, i);
|
|
190
191
|
const h = () => {
|
|
191
192
|
var p;
|
|
192
|
-
e.route =
|
|
193
|
+
e.route = D();
|
|
193
194
|
const s = e.sampled;
|
|
194
195
|
if (e.sampled = Y(q, e.route, i), e.sampled && !s)
|
|
195
196
|
try {
|
|
@@ -199,13 +200,19 @@ function nt(n = {}) {
|
|
|
199
200
|
);
|
|
200
201
|
} catch {
|
|
201
202
|
}
|
|
202
|
-
};
|
|
203
|
+
}, w = De();
|
|
203
204
|
e.stop = t({
|
|
204
205
|
emit(s) {
|
|
205
|
-
e.sampled && (e.buffer.length === 0 && (e.bufferRoute = e.route), e.buffer.push(s), e.buffer.length >=
|
|
206
|
+
e.sampled && (e.buffer.length === 0 && (e.bufferRoute = e.route), e.buffer.push(s), e.buffer.length >= We && O(), _e(w, s) && setTimeout(() => {
|
|
207
|
+
var p;
|
|
208
|
+
try {
|
|
209
|
+
(p = t.takeFullSnapshot) == null || p.call(t, !0);
|
|
210
|
+
} catch {
|
|
211
|
+
w.pending = !1;
|
|
212
|
+
}
|
|
213
|
+
}, 0));
|
|
206
214
|
},
|
|
207
|
-
...z(() =>
|
|
208
|
-
checkoutEveryNms: 6e4
|
|
215
|
+
...z(() => T)
|
|
209
216
|
}) ?? null, e.uninstrument = V(
|
|
210
217
|
(s, p) => t.addCustomEvent(
|
|
211
218
|
s,
|
|
@@ -214,12 +221,12 @@ function nt(n = {}) {
|
|
|
214
221
|
() => {
|
|
215
222
|
e.lastNavAt = Date.now(), h();
|
|
216
223
|
}
|
|
217
|
-
),
|
|
224
|
+
), k = async () => {
|
|
218
225
|
if (!o.recordingId) return null;
|
|
219
226
|
const s = Date.now() - e.startedAt;
|
|
220
227
|
return await m(!0).catch(() => {
|
|
221
228
|
}), o.recordingId ? { recording_id: o.recordingId, offset_ms: s } : null;
|
|
222
|
-
}, N("full"),
|
|
229
|
+
}, N("full"), y = () => {
|
|
223
230
|
if (!o.recordingId) return null;
|
|
224
231
|
const s = Date.now() - e.startedAt;
|
|
225
232
|
return async () => (await m(!0).catch(() => {
|
|
@@ -228,67 +235,67 @@ function nt(n = {}) {
|
|
|
228
235
|
}
|
|
229
236
|
async function se() {
|
|
230
237
|
const t = await Q();
|
|
231
|
-
c || !t || (e.buffer = [], e.prevWindow = [], e.route =
|
|
238
|
+
c || !t || (e.buffer = [], e.prevWindow = [], e.route = D(), e.bufferRoute = e.route, e.prevWindowRoute = e.route, e.stop = t({
|
|
232
239
|
emit(r, i) {
|
|
233
|
-
|
|
240
|
+
Te(r), i ? (e.prevWindow = e.buffer, e.prevWindowRoute = e.bufferRoute, e.buffer = [r], e.bufferRoute = e.route) : e.buffer.push(r);
|
|
234
241
|
},
|
|
235
|
-
...z(() =>
|
|
236
|
-
checkoutEveryNms:
|
|
242
|
+
...z(() => T),
|
|
243
|
+
checkoutEveryNms: xe
|
|
237
244
|
}) ?? null, e.uninstrument = V(
|
|
238
245
|
(r, i) => t.addCustomEvent(
|
|
239
246
|
r,
|
|
240
247
|
i
|
|
241
248
|
),
|
|
242
249
|
() => {
|
|
243
|
-
e.route =
|
|
250
|
+
e.route = D();
|
|
244
251
|
}
|
|
245
|
-
), N("clip"),
|
|
252
|
+
), N("clip"), y = (r) => {
|
|
246
253
|
const i = [...e.prevWindow, ...e.buffer], h = e.prevWindow.length > 0 ? e.prevWindowRoute : e.bufferRoute;
|
|
247
254
|
if (i.length === 0 || !a) return null;
|
|
248
|
-
const
|
|
255
|
+
const w = Le(i, r);
|
|
249
256
|
return async () => {
|
|
250
|
-
const
|
|
251
|
-
|
|
257
|
+
const p = (await a.request(
|
|
258
|
+
Pe(L(u ?? "error-clip", void 0, !0), r)
|
|
252
259
|
)).data.id;
|
|
253
260
|
let le = 0;
|
|
254
|
-
return await
|
|
261
|
+
return await ze(a, p, () => le++, i, {
|
|
255
262
|
startRoute: h,
|
|
256
263
|
build: l
|
|
257
|
-
}) === "ok" && await a.request($(
|
|
258
|
-
}), { recording_id:
|
|
264
|
+
}) === "ok" && await a.request($(p)).catch(() => {
|
|
265
|
+
}), { recording_id: p, offset_ms: w };
|
|
259
266
|
};
|
|
260
|
-
},
|
|
267
|
+
}, k = async (r) => {
|
|
261
268
|
if (r === "error") {
|
|
262
|
-
if (e.lastClip && Date.now() - e.lastClip.at <
|
|
269
|
+
if (e.lastClip && Date.now() - e.lastClip.at < Ye)
|
|
263
270
|
return e.lastClip.link;
|
|
264
271
|
e.lastClip = { at: Date.now(), link: null };
|
|
265
272
|
}
|
|
266
|
-
const i =
|
|
273
|
+
const i = y == null ? void 0 : y(r);
|
|
267
274
|
if (!i) return null;
|
|
268
275
|
const h = await i();
|
|
269
276
|
return r === "error" && (e.lastClip = { at: Date.now(), link: h }), h;
|
|
270
277
|
});
|
|
271
278
|
}
|
|
272
|
-
let
|
|
279
|
+
let U = !1, T = B(null), q = x(null);
|
|
273
280
|
async function ae() {
|
|
274
281
|
try {
|
|
275
282
|
const t = await a.request(ce());
|
|
276
283
|
if (c) return;
|
|
277
|
-
|
|
284
|
+
T = B(t.data.masking), q = x(t.data.sampling);
|
|
278
285
|
const r = t.data.cap_reached === !0;
|
|
279
|
-
|
|
286
|
+
U = t.data.enabled === !0 && !r;
|
|
280
287
|
const i = t.data.enabled !== !0 && t.data.error_replay === !0 && !r;
|
|
281
|
-
|
|
288
|
+
U ? await ie() : i && await se();
|
|
282
289
|
} catch {
|
|
283
290
|
}
|
|
284
291
|
}
|
|
285
292
|
ae();
|
|
286
|
-
const ue = setInterval(
|
|
293
|
+
const ue = setInterval(O, j), W = () => {
|
|
287
294
|
document.visibilityState === "hidden" && m(!0, !0);
|
|
288
295
|
};
|
|
289
|
-
document.addEventListener("visibilitychange",
|
|
296
|
+
document.addEventListener("visibilitychange", W);
|
|
290
297
|
const H = () => {
|
|
291
|
-
if (!(e.dead || !o.recordingId) && (
|
|
298
|
+
if (!(e.dead || !o.recordingId) && (M(!0), I(), !(!G() || !E)))
|
|
292
299
|
for (const { chunk: t, body: r } of o.keepaliveBatch())
|
|
293
300
|
try {
|
|
294
301
|
E(t.recordingId, r).catch(() => {
|
|
@@ -298,23 +305,23 @@ function nt(n = {}) {
|
|
|
298
305
|
};
|
|
299
306
|
window.addEventListener("pagehide", H);
|
|
300
307
|
const K = () => {
|
|
301
|
-
|
|
308
|
+
_(), m(!0);
|
|
302
309
|
};
|
|
303
310
|
return window.addEventListener("online", K), () => {
|
|
304
311
|
var t, r;
|
|
305
|
-
c = !0,
|
|
312
|
+
c = !0, k = null, y = null, N(null), document.removeEventListener("visibilitychange", W), window.removeEventListener("pagehide", H), window.removeEventListener("online", K), clearInterval(ue), _(), (t = e.uninstrument) == null || t.call(e), e.uninstrument = null, (r = e.stop) == null || r.call(e), e.stop = null, e.prevWindow = [], m(!0).then(() => {
|
|
306
313
|
const i = o.recordingId;
|
|
307
314
|
i && (e.dead || g.request($(i)).catch(() => {
|
|
308
|
-
}), o.discard(), o.recordingId = null, P(v,
|
|
315
|
+
}), o.discard(), o.recordingId = null, P(v, b));
|
|
309
316
|
});
|
|
310
317
|
};
|
|
311
318
|
}, [a, d, u, l]);
|
|
312
319
|
}
|
|
313
|
-
|
|
314
|
-
(n) =>
|
|
315
|
-
(n) => (
|
|
320
|
+
qe(
|
|
321
|
+
(n) => je(n),
|
|
322
|
+
(n) => (y == null ? void 0 : y(n)) ?? null
|
|
316
323
|
);
|
|
317
324
|
export {
|
|
318
|
-
|
|
319
|
-
|
|
325
|
+
je as captureErrorClip,
|
|
326
|
+
st as useSessionRecorder
|
|
320
327
|
};
|