@sypnia/browser 0.0.0-stage → 0.1.0

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Sypnia
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,17 @@
1
- # Temporary Holding Version
1
+ # @sypnia/browser
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Errors, session replay, page performance, slow and failing API calls, and rage and dead clicks from any web app, with nothing a person types ever leaving their browser.
4
+
5
+ ```bash
6
+ npm install @sypnia/browser
7
+ ```
8
+
9
+ ```ts
10
+ import { init } from '@sypnia/browser';
11
+
12
+ init({ project: 'spk_…' });
13
+ ```
14
+
15
+ Self-hosted: add `endpoint: 'https://sypnia.example.com'`. Every option, the script tag and what is captured: [docs.sypnia.com/sdks/browser](https://docs.sypnia.com/sdks/browser).
16
+
17
+ MIT licensed.
@@ -0,0 +1,487 @@
1
+ // src/env.ts
2
+ var STORAGE_KEYS = {
3
+ session: "sypnia:session",
4
+ device: "sypnia:device",
5
+ replay: "sypnia:replay",
6
+ off: "sypnia:off"
7
+ };
8
+ function isBrowser() {
9
+ return typeof window !== "undefined" && typeof document !== "undefined";
10
+ }
11
+ function readStorage(key) {
12
+ try {
13
+ return window.localStorage.getItem(key);
14
+ } catch {
15
+ return null;
16
+ }
17
+ }
18
+ function writeStorage(key, value) {
19
+ try {
20
+ window.localStorage.setItem(key, value);
21
+ return true;
22
+ } catch {
23
+ return false;
24
+ }
25
+ }
26
+ function removeStorage(key) {
27
+ try {
28
+ window.localStorage.removeItem(key);
29
+ } catch {
30
+ }
31
+ }
32
+ function safe(fn) {
33
+ try {
34
+ return fn();
35
+ } catch {
36
+ return void 0;
37
+ }
38
+ }
39
+ function whenIdle(callback, timeoutMs = 2e3) {
40
+ const idle = globalThis.requestIdleCallback;
41
+ try {
42
+ if (typeof idle === "function") {
43
+ idle(callback, { timeout: timeoutMs });
44
+ return;
45
+ }
46
+ } catch {
47
+ }
48
+ setTimeout(callback, 0);
49
+ }
50
+ function isHidden() {
51
+ return safe(() => document.visibilityState === "hidden") === true;
52
+ }
53
+ function canGzip() {
54
+ return typeof CompressionStream === "function" && typeof Response === "function";
55
+ }
56
+ async function gzip(text) {
57
+ const bytes = new TextEncoder().encode(text);
58
+ const source = new ReadableStream({
59
+ start(controller) {
60
+ controller.enqueue(bytes);
61
+ controller.close();
62
+ }
63
+ });
64
+ return new Response(source.pipeThrough(new CompressionStream("gzip"))).arrayBuffer();
65
+ }
66
+ function retryAfterMs(value, now) {
67
+ if (!value) return null;
68
+ const seconds = Number(value);
69
+ if (Number.isFinite(seconds)) return Math.max(0, seconds * 1e3);
70
+ const date = Date.parse(value);
71
+ return Number.isFinite(date) ? Math.max(0, date - now) : null;
72
+ }
73
+
74
+ // ../shared/src/route.ts
75
+ var UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
76
+ var HEX_RE = /^[0-9a-f]{16,}$/i;
77
+ var TOKEN_RE = /^(?=.*[0-9])[A-Za-z0-9_-]{20,}$/;
78
+ var SCHEME_RE = /^[a-z][a-z0-9+.-]*:\/\//i;
79
+ function isIdSegment(segment) {
80
+ if (!segment) return false;
81
+ return /^[0-9]+$/.test(segment) || UUID_RE.test(segment) || HEX_RE.test(segment) || TOKEN_RE.test(segment) || segment.includes("%");
82
+ }
83
+ function pathnameOf(input) {
84
+ let path = input;
85
+ if (SCHEME_RE.test(path)) {
86
+ try {
87
+ path = new URL(path).pathname;
88
+ } catch {
89
+ }
90
+ }
91
+ const cut = path.search(/[?#]/);
92
+ if (cut >= 0) path = path.slice(0, cut);
93
+ if (path.length > 1) path = path.replace(/\/+$/, "");
94
+ return path || "/";
95
+ }
96
+ function routeOf(input) {
97
+ const path = pathnameOf(input);
98
+ if (path === "/") return path;
99
+ return path.split("/").map((segment) => isIdSegment(segment) ? ":id" : segment).join("/");
100
+ }
101
+ function matchesRoute(path, patterns) {
102
+ if (!patterns || patterns.length === 0) return false;
103
+ return patterns.some((pattern) => {
104
+ if (typeof pattern === "string") {
105
+ const prefix = pattern.length > 1 ? pattern.replace(/\/+$/, "") : pattern;
106
+ return path === prefix || path.startsWith(prefix === "/" ? "/" : `${prefix}/`);
107
+ }
108
+ return testPattern(pattern, path);
109
+ });
110
+ }
111
+ function matchesUrl(url, patterns) {
112
+ if (!patterns || patterns.length === 0) return false;
113
+ return patterns.some((pattern) => typeof pattern === "string" ? url.startsWith(pattern) : testPattern(pattern, url));
114
+ }
115
+ function matchesText(text, patterns) {
116
+ if (!patterns || patterns.length === 0) return false;
117
+ return patterns.some((pattern) => typeof pattern === "string" ? text.includes(pattern) : testPattern(pattern, text));
118
+ }
119
+ function testPattern(pattern, text) {
120
+ pattern.lastIndex = 0;
121
+ return pattern.test(text);
122
+ }
123
+
124
+ // ../shared/src/fingerprint.ts
125
+ var PRIME = 16777619;
126
+ var SEED_A = 2166136261;
127
+ var SEED_B = 84696351;
128
+ var MESSAGE_UNITS = 300;
129
+ var STACK_LINES = 30;
130
+ var URL_RE = /https?:\/\/[^\s)'"]+/gi;
131
+ var CHUNK_PATH_RE = /\/_next\/static\/chunks\/[^\s)'"]+/gi;
132
+ var UUID_RE2 = /[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/gi;
133
+ var QUOTED_RE = /(["'`])(?:\\.|(?!\1).){0,200}\1/g;
134
+ var HEX_RE2 = /\b[0-9a-f]{12,}\b/gi;
135
+ var NUMBER_RE = /[0-9]+(?:[.,][0-9]+)?/g;
136
+ var WHITESPACE = "\\t\\n\\v\\f\\r \\u0085\\u00a0\\u1680\\u2000-\\u200a\\u2028\\u2029\\u202f\\u205f\\u3000";
137
+ var WHITESPACE_RUN_RE = new RegExp(`[${WHITESPACE}]+`, "g");
138
+ var EDGE_WHITESPACE_RE = new RegExp(`^[${WHITESPACE}]+|[${WHITESPACE}]+$`, "g");
139
+ var FRAME_V8_RE = /^\s*at\s+(?:(.*?)\s+\()?(.+?):([0-9]+):([0-9]+)\)?\s*$/;
140
+ var FRAME_GECKO_RE = /^\s*(.*?)@(.+?):([0-9]+):([0-9]+)\s*$/;
141
+ var SCHEME_RE2 = /^[a-z][a-z0-9+.-]*:\/\//i;
142
+ var BUILD_HASH_RE = /[-.][0-9a-f]{8,}(\.(?:m?js|tsx?))$/i;
143
+ var TOP_CHUNK_RE = /^\/_next\/static\/chunks\/([0-9a-z_-]+)\.js$/i;
144
+ var BEFORE_BUILD_FOLDER_RE = /^.*?(\.next\/)/;
145
+ var NOISY_FRAMES = [
146
+ "node_modules",
147
+ "/_next/static/chunks/framework",
148
+ "/_next/static/chunks/main",
149
+ "/_next/static/chunks/webpack",
150
+ "/_next/static/chunks/polyfills",
151
+ "/_next/static/chunks/turbopack-",
152
+ "react-dom",
153
+ "scheduler",
154
+ "node:internal",
155
+ "<anonymous>"
156
+ ];
157
+ function fnv1a(text, seed) {
158
+ let hash = seed >>> 0;
159
+ for (let i = 0; i < text.length; i++) {
160
+ hash ^= text.charCodeAt(i);
161
+ hash = Math.imul(hash, PRIME) >>> 0;
162
+ }
163
+ return hash.toString(16).padStart(8, "0");
164
+ }
165
+ function hash64(text) {
166
+ return fnv1a(text, SEED_A) + fnv1a(text, SEED_B);
167
+ }
168
+ function firstUnits(text, max) {
169
+ if (text.length <= max) return text;
170
+ const last = text.charCodeAt(max - 1);
171
+ const splitsPair = last >= 55296 && last <= 56319;
172
+ return text.slice(0, splitsPair ? max - 1 : max);
173
+ }
174
+ function normalizeMessage(message) {
175
+ if (!message) return "";
176
+ const text = message.replace(URL_RE, "<url>").replace(CHUNK_PATH_RE, "<chunk>").replace(UUID_RE2, "<uuid>").replace(QUOTED_RE, "$1\u2026$1").replace(HEX_RE2, "<hex>").replace(NUMBER_RE, "#").replace(WHITESPACE_RUN_RE, " ").replace(EDGE_WHITESPACE_RE, "");
177
+ return firstUnits(text, MESSAGE_UNITS);
178
+ }
179
+ function normalizeFrameFile(file) {
180
+ let out = file;
181
+ if (SCHEME_RE2.test(out)) {
182
+ try {
183
+ out = new URL(out).pathname;
184
+ } catch {
185
+ }
186
+ }
187
+ out = out.replace(/[?#].*$/, "").replace(BUILD_HASH_RE, "$1");
188
+ const chunk = TOP_CHUNK_RE.exec(out)?.[1];
189
+ if (chunk !== void 0) {
190
+ const runtime = chunk.startsWith("turbopack-");
191
+ const id = runtime ? chunk.slice("turbopack-".length) : chunk;
192
+ if (id.length >= 8 && /[0-9]/.test(id) && /[a-z_]/i.test(id)) {
193
+ return `/_next/static/chunks/${runtime ? "turbopack-" : ""}*.js`;
194
+ }
195
+ }
196
+ return out.replace(BEFORE_BUILD_FOLDER_RE, "$1");
197
+ }
198
+ function topFrame(stack) {
199
+ if (!stack) return null;
200
+ let first = null;
201
+ for (const line of stack.split("\n").slice(0, STACK_LINES)) {
202
+ const match = FRAME_V8_RE.exec(line) ?? FRAME_GECKO_RE.exec(line);
203
+ if (!match) continue;
204
+ const frame = {
205
+ fn: (match[1] ?? "").trim() || "<anonymous>",
206
+ file: normalizeFrameFile(match[2] ?? "")
207
+ };
208
+ if (!NOISY_FRAMES.some((marker) => frame.file.includes(marker))) return frame;
209
+ first ??= frame;
210
+ }
211
+ return first;
212
+ }
213
+ function groupingName(name) {
214
+ return (name || "Error").replace(EDGE_WHITESPACE_RE, "");
215
+ }
216
+ function errorFingerprint(input) {
217
+ if (input.digest && /^[0-9]{6,}$/.test(input.digest)) return hash64(`digest:${input.digest}`);
218
+ const frame = topFrame(input.stack);
219
+ return hash64(
220
+ `${groupingName(input.name)}|${normalizeMessage(input.message)}|${frame ? `${frame.fn}@${frame.file}` : ""}`
221
+ );
222
+ }
223
+
224
+ // ../shared/src/redact.ts
225
+ var EMAIL_RE = /[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}/g;
226
+ function scrubEmails(text) {
227
+ return text.replace(EMAIL_RE, "[email]");
228
+ }
229
+
230
+ // ../shared/src/ids.ts
231
+ var ZERO_TRACE = "0".repeat(32);
232
+ var ZERO_SPAN = "0".repeat(16);
233
+ function randomHex(chars) {
234
+ const bytes = new Uint8Array(Math.ceil(chars / 2));
235
+ try {
236
+ globalThis.crypto.getRandomValues(bytes);
237
+ } catch {
238
+ for (let i = 0; i < bytes.length; i++) bytes[i] = Math.floor(Math.random() * 256);
239
+ }
240
+ let out = "";
241
+ for (const byte of bytes) out += byte.toString(16).padStart(2, "0");
242
+ return out.slice(0, chars);
243
+ }
244
+ function newTraceId() {
245
+ const id = randomHex(32);
246
+ return id === ZERO_TRACE ? newTraceId() : id;
247
+ }
248
+ function newSpanId() {
249
+ const id = randomHex(16);
250
+ return id === ZERO_SPAN ? newSpanId() : id;
251
+ }
252
+ function formatTraceparent(traceId, spanId) {
253
+ return `00-${traceId}-${spanId}-01`;
254
+ }
255
+ function isHexId(value) {
256
+ return typeof value === "string" && /^[0-9a-f]{32}$/.test(value);
257
+ }
258
+
259
+ // ../shared/src/wire.ts
260
+ var TRACEPARENT_HEADER = "traceparent";
261
+ var SESSION_HEADER = "x-sypnia-session";
262
+ var DEFAULT_ENDPOINT = "https://ingest.sypnia.com";
263
+ function baseUrl(endpoint) {
264
+ return (endpoint || DEFAULT_ENDPOINT).replace(/\/+$/, "");
265
+ }
266
+
267
+ // src/limits.ts
268
+ var FLUSH_INTERVAL_MS = 1e4;
269
+ var FLUSH_AT_EVENTS = 50;
270
+ var EVENTS_PER_BATCH = 200;
271
+ var BATCH_CHARS = 40800;
272
+ var QUEUE_MAX_EVENTS = 500;
273
+ var RETRY_DELAYS_MS = [1e3, 4e3, 15e3];
274
+ var MAX_RETRY_AFTER_MS = 6e4;
275
+ var SESSION_IDLE_MS = 30 * 6e4;
276
+ var ERRORS_PER_MINUTE = 20;
277
+ var ERROR_DEDUPE_MS = 5e3;
278
+ var RAGE_WINDOW_MS = 1e3;
279
+ var RAGE_RADIUS_PX = 30;
280
+ var RAGE_MIN_CLICKS = 3;
281
+ var DEAD_WAIT_MS = 1e3;
282
+ var DEAD_DEDUPE_MS = 2e3;
283
+ var FORM_INVALID_DEDUPE_MS = 1e3;
284
+ var UNANSWERED_GRACE_MS = 1500;
285
+ var CHARS = {
286
+ env: 40,
287
+ release: 40,
288
+ name: 100,
289
+ message: 500,
290
+ stack: 4e3,
291
+ digest: 100,
292
+ label: 80,
293
+ selector: 200,
294
+ path: 500,
295
+ host: 255,
296
+ userAgent: 500,
297
+ code: 40,
298
+ failureMessage: 160,
299
+ customName: 80,
300
+ propName: 40,
301
+ propValue: 200,
302
+ personId: 128,
303
+ personName: 120,
304
+ email: 254
305
+ };
306
+ var CUSTOM_PROPS_MAX = 20;
307
+
308
+ // src/page.ts
309
+ function deviceClassOf(width) {
310
+ if (width < 768) return "mobile";
311
+ if (width < 1024) return "tablet";
312
+ return "desktop";
313
+ }
314
+ function currentPath(hashRouting) {
315
+ const location = safe(() => window.location);
316
+ if (!location) return "/";
317
+ if (hashRouting) {
318
+ const inside = location.hash.replace(/^#!?/, "");
319
+ return pathnameOf(inside.startsWith("/") ? inside : `/${inside}`);
320
+ }
321
+ return pathnameOf(location.pathname);
322
+ }
323
+ function pageRefOf(path, routeFor) {
324
+ const url = pathnameOf(path).slice(0, 500);
325
+ let route;
326
+ try {
327
+ route = routeFor(url) || url;
328
+ } catch {
329
+ route = url;
330
+ }
331
+ return { url, route: route.slice(0, 500) };
332
+ }
333
+ function pageLanguage() {
334
+ const lang = safe(() => document.documentElement.lang || navigator.language) ?? "";
335
+ return lang ? lang.slice(0, 16) : null;
336
+ }
337
+ function viewport() {
338
+ const vw = safe(() => window.innerWidth) || 0;
339
+ return { dev: deviceClassOf(vw), vw, vh: safe(() => window.innerHeight) || 0 };
340
+ }
341
+
342
+ // src/recorder/limits.ts
343
+ var CHUNK_INTERVAL_MS = 1e4;
344
+ var CHUNK_CHARS = 2e5;
345
+ var BUFFER_MS = 3e4;
346
+ var RECORD_CHECKOUT_MS = 10 * 6e4;
347
+ var RESYNC_DELAYS_MS = [0, 5e3, 15e3, 6e4, 5 * 6e4];
348
+ var MAX_CHUNKS_PER_SESSION = 720;
349
+ var MAX_EVENT_CHARS = 39e5;
350
+ var MAX_BUFFER_CHARS = 5e6;
351
+ var KEEPALIVE_MAX_CHARS = 6e4;
352
+ var GZIP_ABOVE_CHARS = 2048;
353
+ var PARK_BASE_MS = 1e4;
354
+ var PARK_MAX_MS = 5 * 6e4;
355
+ var SNAPSHOT_DELAY_MS = 2e3;
356
+ var QUIET_MS = 500;
357
+ var MAX_QUIET_WAIT_MS = 1e4;
358
+ var SNAPSHOT_CHARS = 3e6;
359
+
360
+ // src/http.ts
361
+ async function readAnswer(response) {
362
+ try {
363
+ const body = await response.json();
364
+ return body && typeof body === "object" ? body : {};
365
+ } catch {
366
+ return {};
367
+ }
368
+ }
369
+ function slowDownOf(body) {
370
+ return body.slow_down && typeof body.slow_down === "object" ? body.slow_down : null;
371
+ }
372
+ async function outcomeOf(response, now) {
373
+ const status = response.status;
374
+ if (response.ok) return { kind: "stored", slowDown: slowDownOf(await readAnswer(response)) };
375
+ const body = await readAnswer(response);
376
+ const code = typeof body.error?.code === "string" ? body.error.code : "";
377
+ if (status === 429 && code === "limit_reached") return { kind: "limit", slowDown: slowDownOf(body) };
378
+ if (status === 408 || status === 429 || status >= 500) {
379
+ const wait = retryAfterMs(safe(() => response.headers.get("retry-after")) ?? null, now);
380
+ return { kind: "retry", retryAfterMs: wait, throttled: status === 429 };
381
+ }
382
+ if (status === 403 && code === "not_recordable") return { kind: "not_recordable" };
383
+ if (status === 401 || status === 403) return { kind: "refused" };
384
+ if (status === 422) return { kind: "session_full" };
385
+ return { kind: "rejected" };
386
+ }
387
+ async function encode(body) {
388
+ if (body.length <= GZIP_ABOVE_CHARS || !canGzip()) return body;
389
+ try {
390
+ return await gzip(body);
391
+ } catch {
392
+ return body;
393
+ }
394
+ }
395
+ function sizeOf(payload) {
396
+ return typeof payload === "string" ? payload.length : payload.byteLength;
397
+ }
398
+ async function post(url, key, payload, now) {
399
+ try {
400
+ const response = await fetch(url, {
401
+ method: "POST",
402
+ // A small body survives the page going away.
403
+ keepalive: sizeOf(payload) <= KEEPALIVE_MAX_CHARS,
404
+ credentials: "omit",
405
+ headers: { authorization: `Bearer ${key}`, "content-type": "application/json" },
406
+ body: payload
407
+ });
408
+ return await outcomeOf(response, now());
409
+ } catch {
410
+ return { kind: "retry", retryAfterMs: null, throttled: false };
411
+ }
412
+ }
413
+ function beacon(url, key, body) {
414
+ try {
415
+ if (typeof navigator === "undefined" || typeof navigator.sendBeacon !== "function") return false;
416
+ const target = `${url}${url.includes("?") ? "&" : "?"}key=${encodeURIComponent(key)}`;
417
+ return navigator.sendBeacon(target, new Blob([body], { type: "text/plain;charset=UTF-8" }));
418
+ } catch {
419
+ return false;
420
+ }
421
+ }
422
+
423
+ // src/decision.ts
424
+ var SNAPSHOTS_PER_SESSION = 5;
425
+ var MODES = ["record", "buffer", "off"];
426
+ function fallbackDecision(sid, snapshots) {
427
+ return { sid, mode: "buffer", snapshots, seq: 0, snaps: [], maskAllText: false, blockedRoutes: [], slowDown: null };
428
+ }
429
+ function rate(value, fallback) {
430
+ return typeof value === "number" && Number.isFinite(value) ? Math.min(1, Math.max(0, value)) : fallback;
431
+ }
432
+ function strings(value) {
433
+ return Array.isArray(value) ? value.filter((item) => typeof item === "string") : [];
434
+ }
435
+ function decisionFrom(sid, config, random) {
436
+ const replay = config.replay ?? {};
437
+ const mode = MODES.includes(replay.mode) ? replay.mode : "buffer";
438
+ const slowDown = config.slow_down && typeof config.slow_down === "object" ? config.slow_down : null;
439
+ return {
440
+ sid,
441
+ mode: slowDown?.replay === false ? "off" : mode,
442
+ snapshots: slowDown?.replay !== false && random() < rate(config.snapshots?.sample_rate, 0.5),
443
+ seq: 0,
444
+ snaps: [],
445
+ maskAllText: replay.mask_all_text === true,
446
+ blockedRoutes: strings(replay.blocked_routes),
447
+ slowDown
448
+ };
449
+ }
450
+ function readDecision(sid) {
451
+ const raw = readStorage(STORAGE_KEYS.replay);
452
+ if (!raw) return null;
453
+ try {
454
+ const parsed = JSON.parse(raw);
455
+ if (parsed.sid !== sid || !isHexId(sid) || !MODES.includes(parsed.mode)) return null;
456
+ const seq = typeof parsed.seq === "number" && Number.isInteger(parsed.seq) && parsed.seq >= 0 ? parsed.seq : 0;
457
+ return {
458
+ sid,
459
+ mode: parsed.mode,
460
+ snapshots: parsed.snapshots === true,
461
+ seq,
462
+ snaps: strings(parsed.snaps).slice(0, SNAPSHOTS_PER_SESSION),
463
+ maskAllText: parsed.maskAllText === true,
464
+ blockedRoutes: strings(parsed.blockedRoutes),
465
+ slowDown: parsed.slowDown && typeof parsed.slowDown === "object" ? parsed.slowDown : null
466
+ };
467
+ } catch {
468
+ return null;
469
+ }
470
+ }
471
+ function writeDecision(decision) {
472
+ const stored = readDecision(decision.sid);
473
+ let mode = decision.mode;
474
+ let slowDown = decision.slowDown ?? null;
475
+ if (stored) {
476
+ if (stored.seq > decision.seq) decision.seq = stored.seq;
477
+ for (const route of stored.snaps) if (!decision.snaps.includes(route)) decision.snaps.push(route);
478
+ if (stored.mode === "off" || stored.mode === "record" && mode === "buffer") mode = stored.mode;
479
+ slowDown ??= stored.slowDown;
480
+ }
481
+ writeStorage(
482
+ STORAGE_KEYS.replay,
483
+ JSON.stringify({ ...decision, mode, snaps: decision.snaps.slice(0, SNAPSHOTS_PER_SESSION), slowDown })
484
+ );
485
+ }
486
+
487
+ export { BATCH_CHARS, BUFFER_MS, CHARS, CHUNK_CHARS, CHUNK_INTERVAL_MS, CUSTOM_PROPS_MAX, DEAD_DEDUPE_MS, DEAD_WAIT_MS, ERRORS_PER_MINUTE, ERROR_DEDUPE_MS, EVENTS_PER_BATCH, FLUSH_AT_EVENTS, FLUSH_INTERVAL_MS, FORM_INVALID_DEDUPE_MS, KEEPALIVE_MAX_CHARS, MAX_BUFFER_CHARS, MAX_CHUNKS_PER_SESSION, MAX_EVENT_CHARS, MAX_QUIET_WAIT_MS, MAX_RETRY_AFTER_MS, PARK_BASE_MS, PARK_MAX_MS, QUEUE_MAX_EVENTS, QUIET_MS, RAGE_MIN_CLICKS, RAGE_RADIUS_PX, RAGE_WINDOW_MS, RECORD_CHECKOUT_MS, RESYNC_DELAYS_MS, RETRY_DELAYS_MS, SESSION_HEADER, SESSION_IDLE_MS, SNAPSHOTS_PER_SESSION, SNAPSHOT_CHARS, SNAPSHOT_DELAY_MS, STORAGE_KEYS, TRACEPARENT_HEADER, UNANSWERED_GRACE_MS, baseUrl, beacon, currentPath, decisionFrom, deviceClassOf, encode, errorFingerprint, fallbackDecision, formatTraceparent, hash64, isBrowser, isHexId, isHidden, matchesRoute, matchesText, matchesUrl, newSpanId, newTraceId, outcomeOf, pageLanguage, pageRefOf, pathnameOf, post, randomHex, readDecision, readStorage, removeStorage, routeOf, safe, scrubEmails, viewport, whenIdle, writeDecision, writeStorage };