@hexclave/react 1.0.26 → 1.0.28
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/components/elements/ssr-layout-effect.d.ts.map +1 -1
- package/dist/components/elements/ssr-layout-effect.js +5 -3
- package/dist/components/elements/ssr-layout-effect.js.map +1 -1
- package/dist/dev-tool/dev-tool-core.js +1 -1
- package/dist/dev-tool/dev-tool-core.js.map +1 -1
- package/dist/esm/components/elements/ssr-layout-effect.d.ts.map +1 -1
- package/dist/esm/components/elements/ssr-layout-effect.js +5 -3
- package/dist/esm/components/elements/ssr-layout-effect.js.map +1 -1
- package/dist/esm/dev-tool/dev-tool-core.js +1 -1
- package/dist/esm/dev-tool/dev-tool-core.js.map +1 -1
- package/dist/esm/lib/hexclave-app/apps/implementations/admin-app-impl.d.ts.map +1 -1
- package/dist/esm/lib/hexclave-app/apps/implementations/admin-app-impl.js +6 -1
- package/dist/esm/lib/hexclave-app/apps/implementations/admin-app-impl.js.map +1 -1
- package/dist/esm/lib/hexclave-app/apps/implementations/common.js +1 -1
- package/dist/esm/lib/hexclave-app/apps/implementations/session-replay.d.ts +1 -0
- package/dist/esm/lib/hexclave-app/apps/implementations/session-replay.d.ts.map +1 -1
- package/dist/esm/lib/hexclave-app/apps/implementations/session-replay.js +44 -19
- package/dist/esm/lib/hexclave-app/apps/implementations/session-replay.js.map +1 -1
- package/dist/esm/lib/hexclave-app/apps/implementations/session-replay.test.js +97 -8
- package/dist/esm/lib/hexclave-app/apps/implementations/session-replay.test.js.map +1 -1
- package/dist/lib/hexclave-app/apps/implementations/admin-app-impl.d.ts.map +1 -1
- package/dist/lib/hexclave-app/apps/implementations/admin-app-impl.js +6 -1
- package/dist/lib/hexclave-app/apps/implementations/admin-app-impl.js.map +1 -1
- package/dist/lib/hexclave-app/apps/implementations/common.js +1 -1
- package/dist/lib/hexclave-app/apps/implementations/session-replay.d.ts +1 -0
- package/dist/lib/hexclave-app/apps/implementations/session-replay.d.ts.map +1 -1
- package/dist/lib/hexclave-app/apps/implementations/session-replay.js +43 -18
- package/dist/lib/hexclave-app/apps/implementations/session-replay.js.map +1 -1
- package/dist/lib/hexclave-app/apps/implementations/session-replay.test.js +97 -8
- package/dist/lib/hexclave-app/apps/implementations/session-replay.test.js.map +1 -1
- package/package.json +4 -4
- package/src/components/elements/ssr-layout-effect.tsx +15 -3
- package/src/dev-tool/dev-tool-core.ts +1 -1
- package/src/lib/hexclave-app/apps/implementations/admin-app-impl.ts +2 -1
- package/src/lib/hexclave-app/apps/implementations/session-replay.test.ts +123 -4
- package/src/lib/hexclave-app/apps/implementations/session-replay.ts +63 -29
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
//===========================================
|
|
5
5
|
import { KnownErrors } from "@hexclave/shared/dist/known-errors";
|
|
6
6
|
import { isBrowserLike } from "@hexclave/shared/dist/utils/env";
|
|
7
|
-
import { captureWarning } from "@hexclave/shared/dist/utils/errors";
|
|
7
|
+
import { captureWarning, throwErr } from "@hexclave/shared/dist/utils/errors";
|
|
8
8
|
import { runAsynchronously } from "@hexclave/shared/dist/utils/promises";
|
|
9
9
|
import { Result } from "@hexclave/shared/dist/utils/results";
|
|
10
10
|
|
|
@@ -110,6 +110,9 @@ const IDLE_TTL_MS = 3 * 60 * 1000;
|
|
|
110
110
|
const FLUSH_INTERVAL_MS = 5_000;
|
|
111
111
|
const MAX_EVENTS_PER_BATCH = 200;
|
|
112
112
|
const MAX_APPROX_BYTES_PER_BATCH = 512_000;
|
|
113
|
+
// The server rejects payloads > 1MB. Stay well under to account for JSON
|
|
114
|
+
// envelope overhead (browser_session_id, timestamps, wrapper keys, etc.).
|
|
115
|
+
const MAX_FLUSH_PAYLOAD_BYTES = 900_000;
|
|
113
116
|
|
|
114
117
|
export type StoredSession = {
|
|
115
118
|
session_id: string,
|
|
@@ -193,6 +196,7 @@ export class SessionRecorder {
|
|
|
193
196
|
private _detachListeners: (() => void) | null = null;
|
|
194
197
|
private _flushTimer: ReturnType<typeof setInterval> | null = null;
|
|
195
198
|
private _events: unknown[] = [];
|
|
199
|
+
private _eventSizes: number[] = [];
|
|
196
200
|
private _approxBytes = 0;
|
|
197
201
|
private _lastPersistActivity = 0;
|
|
198
202
|
private _recording = false;
|
|
@@ -243,6 +247,7 @@ export class SessionRecorder {
|
|
|
243
247
|
|
|
244
248
|
clearBuffer() {
|
|
245
249
|
this._events = [];
|
|
250
|
+
this._eventSizes = [];
|
|
246
251
|
this._approxBytes = 0;
|
|
247
252
|
}
|
|
248
253
|
|
|
@@ -268,42 +273,68 @@ export class SessionRecorder {
|
|
|
268
273
|
const nowMs = Date.now();
|
|
269
274
|
const stored = getOrRotateSession({ key: this._storageKey, legacyKey: this._legacyStorageKey, nowMs });
|
|
270
275
|
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
started_at_ms: stored.created_at_ms,
|
|
277
|
-
sent_at_ms: nowMs,
|
|
278
|
-
events: this._events,
|
|
279
|
-
};
|
|
280
|
-
|
|
276
|
+
// Capture all buffered events upfront (before any await) so that
|
|
277
|
+
// stop() / _stopCurrentRecording() clearing this._events cannot race
|
|
278
|
+
// with the async send loop below and silently discard overflow batches.
|
|
279
|
+
const allEvents = this._events;
|
|
280
|
+
const allSizes = this._eventSizes;
|
|
281
281
|
this._events = [];
|
|
282
|
+
this._eventSizes = [];
|
|
282
283
|
this._approxBytes = 0;
|
|
283
284
|
|
|
284
285
|
this._flushInProgress = true;
|
|
285
286
|
try {
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
287
|
+
let offset = 0;
|
|
288
|
+
while (offset < allEvents.length) {
|
|
289
|
+
// Build a batch that fits under the server's payload limit.
|
|
290
|
+
// When _flushInProgress blocked earlier flushes, events can accumulate
|
|
291
|
+
// well past MAX_APPROX_BYTES_PER_BATCH; sending them all at once would
|
|
292
|
+
// exceed the server's 1MB body limit (413).
|
|
293
|
+
let batchBytes = 0;
|
|
294
|
+
let batchEnd = offset;
|
|
295
|
+
for (let i = offset; i < allEvents.length; i++) {
|
|
296
|
+
const nextSize = allSizes[i] ?? throwErr("_eventSizes out of sync with _events — this should never happen");
|
|
297
|
+
if (batchBytes + nextSize > MAX_FLUSH_PAYLOAD_BYTES && batchEnd > offset) break;
|
|
298
|
+
batchBytes += nextSize;
|
|
299
|
+
batchEnd = i + 1;
|
|
295
300
|
}
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
301
|
+
|
|
302
|
+
const batchEvents = allEvents.slice(offset, batchEnd);
|
|
303
|
+
offset = batchEnd;
|
|
304
|
+
|
|
305
|
+
const batchId = generateUuid();
|
|
306
|
+
const payload = {
|
|
307
|
+
browser_session_id: stored.session_id,
|
|
308
|
+
session_replay_segment_id: this._sessionReplaySegmentId,
|
|
309
|
+
batch_id: batchId,
|
|
310
|
+
started_at_ms: stored.created_at_ms,
|
|
311
|
+
sent_at_ms: nowMs,
|
|
312
|
+
events: batchEvents,
|
|
313
|
+
};
|
|
314
|
+
|
|
315
|
+
const res = await this._deps.sendBatch(
|
|
316
|
+
JSON.stringify(payload),
|
|
317
|
+
{ keepalive: options.keepalive },
|
|
318
|
+
);
|
|
319
|
+
|
|
320
|
+
if (res.status === "error") {
|
|
321
|
+
if (isAnalyticsNotEnabledError(res.error)) {
|
|
322
|
+
this._disable();
|
|
323
|
+
return;
|
|
324
|
+
}
|
|
325
|
+
// Ad blockers commonly block analytics endpoints, causing network
|
|
326
|
+
// errors. These are expected and should not pollute the console.
|
|
327
|
+
if (isAdBlockerNetworkError(res.error)) {
|
|
328
|
+
return;
|
|
329
|
+
}
|
|
330
|
+
captureWarning("SessionRecorder.flush", res.error);
|
|
299
331
|
return;
|
|
300
332
|
}
|
|
301
|
-
captureWarning("SessionRecorder.flush", res.error);
|
|
302
|
-
return;
|
|
303
|
-
}
|
|
304
333
|
|
|
305
|
-
|
|
306
|
-
|
|
334
|
+
if (!res.data.ok) {
|
|
335
|
+
captureWarning("SessionRecorder.flush", new Error(`SessionRecorder flush failed: ${res.data.status} ${await res.data.text()}`));
|
|
336
|
+
return;
|
|
337
|
+
}
|
|
307
338
|
}
|
|
308
339
|
} finally {
|
|
309
340
|
this._flushInProgress = false;
|
|
@@ -357,8 +388,10 @@ export class SessionRecorder {
|
|
|
357
388
|
}
|
|
358
389
|
}
|
|
359
390
|
|
|
391
|
+
const eventSize = JSON.stringify(event).length;
|
|
360
392
|
this._events.push(event);
|
|
361
|
-
this.
|
|
393
|
+
this._eventSizes.push(eventSize);
|
|
394
|
+
this._approxBytes += eventSize;
|
|
362
395
|
if (this._events.length >= MAX_EVENTS_PER_BATCH || this._approxBytes >= MAX_APPROX_BYTES_PER_BATCH) {
|
|
363
396
|
runAsynchronously(() => this._flush({ keepalive: false }));
|
|
364
397
|
}
|
|
@@ -391,6 +424,7 @@ export class SessionRecorder {
|
|
|
391
424
|
this._stopRecording = null;
|
|
392
425
|
}
|
|
393
426
|
this._events = [];
|
|
427
|
+
this._eventSizes = [];
|
|
394
428
|
this._approxBytes = 0;
|
|
395
429
|
this._recording = false;
|
|
396
430
|
}
|