@sypnia/telemetry 0.0.0-stage → 0.3.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.
@@ -0,0 +1,225 @@
1
+ // ../shared/src/route.ts
2
+ var UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
3
+ var HEX_RE = /^[0-9a-f]{16,}$/i;
4
+ var TOKEN_RE = /^(?=.*[0-9])[A-Za-z0-9_-]{20,}$/;
5
+ var SCHEME_RE = /^[a-z][a-z0-9+.-]*:\/\//i;
6
+ function isIdSegment(segment) {
7
+ if (!segment) return false;
8
+ return /^[0-9]+$/.test(segment) || UUID_RE.test(segment) || HEX_RE.test(segment) || TOKEN_RE.test(segment) || segment.includes("%");
9
+ }
10
+ function pathnameOf(input) {
11
+ let path = input;
12
+ if (SCHEME_RE.test(path)) {
13
+ try {
14
+ path = new URL(path).pathname;
15
+ } catch {
16
+ }
17
+ }
18
+ const cut = path.search(/[?#]/);
19
+ if (cut >= 0) path = path.slice(0, cut);
20
+ if (path.length > 1) path = path.replace(/\/+$/, "");
21
+ return path || "/";
22
+ }
23
+ function routeOf(input) {
24
+ const path = pathnameOf(input);
25
+ if (path === "/") return path;
26
+ return path.split("/").map((segment) => isIdSegment(segment) ? ":id" : segment).join("/");
27
+ }
28
+ function matchesRoute(path, patterns) {
29
+ if (!patterns || patterns.length === 0) return false;
30
+ return patterns.some((pattern) => {
31
+ if (typeof pattern === "string") {
32
+ const prefix = pattern.length > 1 ? pattern.replace(/\/+$/, "") : pattern;
33
+ return path === prefix || path.startsWith(prefix === "/" ? "/" : `${prefix}/`);
34
+ }
35
+ return testPattern(pattern, path);
36
+ });
37
+ }
38
+ function matchesUrl(url, patterns) {
39
+ if (!patterns || patterns.length === 0) return false;
40
+ return patterns.some((pattern) => typeof pattern === "string" ? url.startsWith(pattern) : testPattern(pattern, url));
41
+ }
42
+ function matchesText(text, patterns) {
43
+ if (!patterns || patterns.length === 0) return false;
44
+ return patterns.some((pattern) => typeof pattern === "string" ? text.includes(pattern) : testPattern(pattern, text));
45
+ }
46
+ function testPattern(pattern, text) {
47
+ pattern.lastIndex = 0;
48
+ return pattern.test(text);
49
+ }
50
+
51
+ // ../shared/src/redact.ts
52
+ var EMAIL_RE = /[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}/g;
53
+ var URL_RE = /[a-z][a-z0-9+.-]*:\/\/[^\s)'"]+/giu;
54
+ var UUID_RE2 = /[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/gi;
55
+ var QUOTED_RE = /"[^"\n]{0,200}"|'[^'\n]{0,200}'/gu;
56
+ var WORD_RE = /[A-Za-z0-9_-]{20,}/g;
57
+ var DIGITS_RE = /[0-9]+/g;
58
+ var MESSAGE_CHARS = 500;
59
+ function cutChars(text, max) {
60
+ if (text.length <= max) return text;
61
+ let out = "";
62
+ let count = 0;
63
+ for (const char of text) {
64
+ if (count === max) break;
65
+ out += char;
66
+ count++;
67
+ }
68
+ return out;
69
+ }
70
+ function scrubEmails(text) {
71
+ return text.replace(EMAIL_RE, "[email]");
72
+ }
73
+ function redactMessage(message) {
74
+ return cutChars(message, MESSAGE_CHARS).replace(EMAIL_RE, "[email]").replace(URL_RE, "<url>").replace(UUID_RE2, "<uuid>").replace(QUOTED_RE, '"\u2026"').replace(WORD_RE, (word) => /[0-9]/.test(word) ? "<token>" : word).replace(DIGITS_RE, "#");
75
+ }
76
+ var DIGIT_RUN_RE = /\+?\(?\d(?:[\s().-]?\d){5,}/g;
77
+ function scrubPersonal(text) {
78
+ return text.replace(EMAIL_RE, "[email]").replace(DIGIT_RUN_RE, "[number]");
79
+ }
80
+
81
+ // ../shared/src/wire.ts
82
+ var TRACEPARENT_HEADER = "traceparent";
83
+ var SESSION_HEADER = "x-sypnia-session";
84
+ var DEFAULT_ENDPOINT = "https://telemetry.ingest.sypnia.com";
85
+ function baseUrl(endpoint) {
86
+ return (endpoint || DEFAULT_ENDPOINT).replace(/\/+$/, "");
87
+ }
88
+
89
+ // ../shared/src/fingerprint.ts
90
+ var PRIME = 16777619;
91
+ var SEED_A = 2166136261;
92
+ var SEED_B = 84696351;
93
+ var MESSAGE_UNITS = 300;
94
+ var STACK_LINES = 30;
95
+ var URL_RE2 = /https?:\/\/[^\s)'"]+/gi;
96
+ var CHUNK_PATH_RE = /\/_next\/static\/chunks\/[^\s)'"]+/gi;
97
+ var UUID_RE3 = /[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/gi;
98
+ var QUOTED_RE2 = /(["'`])(?:\\.|(?!\1).){0,200}\1/g;
99
+ var HEX_RE2 = /\b[0-9a-f]{12,}\b/gi;
100
+ var NUMBER_RE = /[0-9]+(?:[.,][0-9]+)?/g;
101
+ var WHITESPACE = "\\t\\n\\v\\f\\r \\u0085\\u00a0\\u1680\\u2000-\\u200a\\u2028\\u2029\\u202f\\u205f\\u3000";
102
+ var WHITESPACE_RUN_RE = new RegExp(`[${WHITESPACE}]+`, "g");
103
+ var EDGE_WHITESPACE_RE = new RegExp(`^[${WHITESPACE}]+|[${WHITESPACE}]+$`, "g");
104
+ var FRAME_V8_RE = /^\s*at\s+(?:(.*?)\s+\()?(.+?):([0-9]+):([0-9]+)\)?\s*$/;
105
+ var FRAME_GECKO_RE = /^\s*(.*?)@(.+?):([0-9]+):([0-9]+)\s*$/;
106
+ var SCHEME_RE2 = /^[a-z][a-z0-9+.-]*:\/\//i;
107
+ var BUILD_HASH_RE = /[-.][0-9a-f]{8,}(\.(?:m?js|tsx?))$/i;
108
+ var TOP_CHUNK_RE = /^\/_next\/static\/chunks\/([0-9a-z_-]+)\.js$/i;
109
+ var BEFORE_BUILD_FOLDER_RE = /^.*?(\.next\/)/;
110
+ var NOISY_FRAMES = [
111
+ "node_modules",
112
+ "/_next/static/chunks/framework",
113
+ "/_next/static/chunks/main",
114
+ "/_next/static/chunks/webpack",
115
+ "/_next/static/chunks/polyfills",
116
+ "/_next/static/chunks/turbopack-",
117
+ "react-dom",
118
+ "scheduler",
119
+ "node:internal",
120
+ "<anonymous>"
121
+ ];
122
+ function fnv1a(text, seed) {
123
+ let hash = seed >>> 0;
124
+ for (let i = 0; i < text.length; i++) {
125
+ hash ^= text.charCodeAt(i);
126
+ hash = Math.imul(hash, PRIME) >>> 0;
127
+ }
128
+ return hash.toString(16).padStart(8, "0");
129
+ }
130
+ function hash64(text) {
131
+ return fnv1a(text, SEED_A) + fnv1a(text, SEED_B);
132
+ }
133
+ function firstUnits(text, max) {
134
+ if (text.length <= max) return text;
135
+ const last = text.charCodeAt(max - 1);
136
+ const splitsPair = last >= 55296 && last <= 56319;
137
+ return text.slice(0, splitsPair ? max - 1 : max);
138
+ }
139
+ function normalizeMessage(message) {
140
+ if (!message) return "";
141
+ const text = message.replace(URL_RE2, "<url>").replace(CHUNK_PATH_RE, "<chunk>").replace(UUID_RE3, "<uuid>").replace(QUOTED_RE2, "$1\u2026$1").replace(HEX_RE2, "<hex>").replace(NUMBER_RE, "#").replace(WHITESPACE_RUN_RE, " ").replace(EDGE_WHITESPACE_RE, "");
142
+ return firstUnits(text, MESSAGE_UNITS);
143
+ }
144
+ function normalizeFrameFile(file) {
145
+ let out = file;
146
+ if (SCHEME_RE2.test(out)) {
147
+ try {
148
+ out = new URL(out).pathname;
149
+ } catch {
150
+ }
151
+ }
152
+ out = out.replace(/[?#].*$/, "").replace(BUILD_HASH_RE, "$1");
153
+ const chunk = TOP_CHUNK_RE.exec(out)?.[1];
154
+ if (chunk !== void 0) {
155
+ const runtime = chunk.startsWith("turbopack-");
156
+ const id = runtime ? chunk.slice("turbopack-".length) : chunk;
157
+ if (id.length >= 8 && /[0-9]/.test(id) && /[a-z_]/i.test(id)) {
158
+ return `/_next/static/chunks/${runtime ? "turbopack-" : ""}*.js`;
159
+ }
160
+ }
161
+ return out.replace(BEFORE_BUILD_FOLDER_RE, "$1");
162
+ }
163
+ function topFrame(stack) {
164
+ if (!stack) return null;
165
+ let first = null;
166
+ for (const line of stack.split("\n").slice(0, STACK_LINES)) {
167
+ const match = FRAME_V8_RE.exec(line) ?? FRAME_GECKO_RE.exec(line);
168
+ if (!match) continue;
169
+ const frame = {
170
+ fn: (match[1] ?? "").trim() || "<anonymous>",
171
+ file: normalizeFrameFile(match[2] ?? "")
172
+ };
173
+ if (!NOISY_FRAMES.some((marker) => frame.file.includes(marker))) return frame;
174
+ first ??= frame;
175
+ }
176
+ return first;
177
+ }
178
+ function groupingName(name) {
179
+ return (name || "Error").replace(EDGE_WHITESPACE_RE, "");
180
+ }
181
+ function errorFingerprint(input) {
182
+ if (input.digest && /^[0-9]{6,}$/.test(input.digest)) return hash64(`digest:${input.digest}`);
183
+ const frame = topFrame(input.stack);
184
+ return hash64(
185
+ `${groupingName(input.name)}|${normalizeMessage(input.message)}|${frame ? `${frame.fn}@${frame.file}` : ""}`
186
+ );
187
+ }
188
+
189
+ // ../shared/src/ids.ts
190
+ var TRACEPARENT_RE = /^00-([0-9a-f]{32})-([0-9a-f]{16})-[0-9a-f]{2}$/;
191
+ var ZERO_TRACE = "0".repeat(32);
192
+ var ZERO_SPAN = "0".repeat(16);
193
+ function randomHex(chars) {
194
+ const bytes = new Uint8Array(Math.ceil(chars / 2));
195
+ try {
196
+ globalThis.crypto.getRandomValues(bytes);
197
+ } catch {
198
+ for (let i = 0; i < bytes.length; i++) bytes[i] = Math.floor(Math.random() * 256);
199
+ }
200
+ let out = "";
201
+ for (const byte of bytes) out += byte.toString(16).padStart(2, "0");
202
+ return out.slice(0, chars);
203
+ }
204
+ function newTraceId() {
205
+ const id = randomHex(32);
206
+ return id === ZERO_TRACE ? newTraceId() : id;
207
+ }
208
+ function newSpanId() {
209
+ const id = randomHex(16);
210
+ return id === ZERO_SPAN ? newSpanId() : id;
211
+ }
212
+ function formatTraceparent(traceId, spanId) {
213
+ return `00-${traceId}-${spanId}-01`;
214
+ }
215
+ function parseTraceparent(value) {
216
+ if (!value) return null;
217
+ const match = TRACEPARENT_RE.exec(value.trim().toLowerCase());
218
+ if (!match || match[1] === ZERO_TRACE || match[2] === ZERO_SPAN) return null;
219
+ return { traceId: match[1] ?? "", spanId: match[2] ?? "" };
220
+ }
221
+ function isHexId(value) {
222
+ return typeof value === "string" && /^[0-9a-f]{32}$/.test(value);
223
+ }
224
+
225
+ export { SESSION_HEADER, TRACEPARENT_HEADER, baseUrl, cutChars, errorFingerprint, formatTraceparent, hash64, isHexId, matchesRoute, matchesText, matchesUrl, newSpanId, newTraceId, parseTraceparent, pathnameOf, randomHex, redactMessage, routeOf, scrubEmails, scrubPersonal };
@@ -0,0 +1,323 @@
1
+ import { pathnameOf, isHexId } from './chunk-P5DK2OU7.js';
2
+
3
+ // ../browser/src/env.ts
4
+ var STORAGE_KEYS = {
5
+ session: "sypnia:session",
6
+ device: "sypnia:device",
7
+ replay: "sypnia:replay",
8
+ off: "sypnia:off"
9
+ };
10
+ var ANON_SESSION_KEY = "sypnia:anon";
11
+ function isBrowser() {
12
+ return typeof window !== "undefined" && typeof document !== "undefined";
13
+ }
14
+ function readStorage(key) {
15
+ try {
16
+ return window.localStorage.getItem(key);
17
+ } catch {
18
+ return null;
19
+ }
20
+ }
21
+ function writeStorage(key, value) {
22
+ try {
23
+ window.localStorage.setItem(key, value);
24
+ return true;
25
+ } catch {
26
+ return false;
27
+ }
28
+ }
29
+ function readTabStorage(key) {
30
+ try {
31
+ return window.sessionStorage.getItem(key);
32
+ } catch {
33
+ return null;
34
+ }
35
+ }
36
+ function writeTabStorage(key, value) {
37
+ try {
38
+ window.sessionStorage.setItem(key, value);
39
+ return true;
40
+ } catch {
41
+ return false;
42
+ }
43
+ }
44
+ function removeStorage(key) {
45
+ try {
46
+ window.localStorage.removeItem(key);
47
+ } catch {
48
+ }
49
+ }
50
+ function safe(fn) {
51
+ try {
52
+ return fn();
53
+ } catch {
54
+ return void 0;
55
+ }
56
+ }
57
+ function whenIdle(callback, timeoutMs = 2e3) {
58
+ const idle = globalThis.requestIdleCallback;
59
+ try {
60
+ if (typeof idle === "function") {
61
+ idle(callback, { timeout: timeoutMs });
62
+ return;
63
+ }
64
+ } catch {
65
+ }
66
+ setTimeout(callback, 0);
67
+ }
68
+ function isHidden() {
69
+ return safe(() => document.visibilityState === "hidden") === true;
70
+ }
71
+ function canGzip() {
72
+ return typeof CompressionStream === "function" && typeof Response === "function";
73
+ }
74
+ async function gzip(text) {
75
+ const bytes = new TextEncoder().encode(text);
76
+ const source = new ReadableStream({
77
+ start(controller) {
78
+ controller.enqueue(bytes);
79
+ controller.close();
80
+ }
81
+ });
82
+ return new Response(source.pipeThrough(new CompressionStream("gzip"))).arrayBuffer();
83
+ }
84
+ function retryAfterMs(value, now) {
85
+ if (!value) return null;
86
+ const seconds = Number(value);
87
+ if (Number.isFinite(seconds)) return Math.max(0, seconds * 1e3);
88
+ const date = Date.parse(value);
89
+ return Number.isFinite(date) ? Math.max(0, date - now) : null;
90
+ }
91
+
92
+ // ../browser/src/limits.ts
93
+ var FLUSH_INTERVAL_MS = 1e4;
94
+ var FLUSH_AT_EVENTS = 50;
95
+ var EVENTS_PER_BATCH = 200;
96
+ var BATCH_CHARS = 40800;
97
+ var QUEUE_MAX_EVENTS = 500;
98
+ var RETRY_DELAYS_MS = [1e3, 4e3, 15e3];
99
+ var MAX_RETRY_AFTER_MS = 6e4;
100
+ var SESSION_IDLE_MS = 30 * 6e4;
101
+ var ERRORS_PER_MINUTE = 20;
102
+ var ERROR_DEDUPE_MS = 5e3;
103
+ var RAGE_WINDOW_MS = 1e3;
104
+ var RAGE_RADIUS_PX = 30;
105
+ var RAGE_MIN_CLICKS = 3;
106
+ var DEAD_WAIT_MS = 1e3;
107
+ var DEAD_DEDUPE_MS = 2e3;
108
+ var FORM_INVALID_DEDUPE_MS = 1e3;
109
+ var UNANSWERED_GRACE_MS = 1500;
110
+ var CHARS = {
111
+ env: 40,
112
+ release: 40,
113
+ name: 100,
114
+ message: 500,
115
+ stack: 4e3,
116
+ digest: 100,
117
+ label: 80,
118
+ selector: 200,
119
+ path: 500,
120
+ host: 255,
121
+ userAgent: 500,
122
+ code: 40,
123
+ failureMessage: 160,
124
+ customName: 80,
125
+ propName: 40,
126
+ propValue: 200,
127
+ personId: 128,
128
+ personName: 120,
129
+ email: 254
130
+ };
131
+ var CUSTOM_PROPS_MAX = 20;
132
+
133
+ // ../browser/src/page.ts
134
+ function deviceClassOf(width) {
135
+ if (width < 768) return "mobile";
136
+ if (width < 1024) return "tablet";
137
+ return "desktop";
138
+ }
139
+ function currentPath(hashRouting) {
140
+ const location = safe(() => window.location);
141
+ if (!location) return "/";
142
+ if (hashRouting) {
143
+ const inside = location.hash.replace(/^#!?/, "");
144
+ return pathnameOf(inside.startsWith("/") ? inside : `/${inside}`);
145
+ }
146
+ return pathnameOf(location.pathname);
147
+ }
148
+ function pageRefOf(path, routeFor) {
149
+ const url = pathnameOf(path).slice(0, 500);
150
+ let route;
151
+ try {
152
+ route = routeFor(url) || url;
153
+ } catch {
154
+ route = url;
155
+ }
156
+ return { url, route: route.slice(0, 500) };
157
+ }
158
+ function pageLanguage() {
159
+ const lang = safe(() => document.documentElement.lang || navigator.language) ?? "";
160
+ return lang ? lang.slice(0, 16) : null;
161
+ }
162
+ function viewport() {
163
+ const vw = safe(() => window.innerWidth) || 0;
164
+ return { dev: deviceClassOf(vw), vw, vh: safe(() => window.innerHeight) || 0 };
165
+ }
166
+
167
+ // ../browser/src/recorder/limits.ts
168
+ var CHUNK_INTERVAL_MS = 1e4;
169
+ var CHUNK_CHARS = 2e5;
170
+ var BUFFER_MS = 3e4;
171
+ var RECORD_CHECKOUT_MS = 10 * 6e4;
172
+ var RESYNC_DELAYS_MS = [0, 5e3, 15e3, 6e4, 5 * 6e4];
173
+ var MAX_CHUNKS_PER_SESSION = 720;
174
+ var MAX_EVENT_CHARS = 39e5;
175
+ var MAX_BUFFER_CHARS = 5e6;
176
+ var KEEPALIVE_MAX_CHARS = 6e4;
177
+ var GZIP_ABOVE_CHARS = 2048;
178
+ var PARK_BASE_MS = 1e4;
179
+ var PARK_MAX_MS = 5 * 6e4;
180
+ var SNAPSHOT_DELAY_MS = 2e3;
181
+ var QUIET_MS = 500;
182
+ var MAX_QUIET_WAIT_MS = 1e4;
183
+ var SNAPSHOT_CHARS = 3e6;
184
+
185
+ // ../browser/src/http.ts
186
+ async function readAnswer(response) {
187
+ try {
188
+ const body = await response.json();
189
+ return body && typeof body === "object" ? body : {};
190
+ } catch {
191
+ return {};
192
+ }
193
+ }
194
+ function slowDownOf(body) {
195
+ return body.slow_down && typeof body.slow_down === "object" ? body.slow_down : null;
196
+ }
197
+ async function outcomeOf(response, now) {
198
+ const status = response.status;
199
+ if (response.ok) return { kind: "stored", slowDown: slowDownOf(await readAnswer(response)) };
200
+ const body = await readAnswer(response);
201
+ const code = typeof body.error?.code === "string" ? body.error.code : "";
202
+ if (status === 429 && code === "limit_reached") return { kind: "limit", slowDown: slowDownOf(body) };
203
+ if (status === 408 || status === 429 || status >= 500) {
204
+ const wait = retryAfterMs(safe(() => response.headers.get("retry-after")) ?? null, now);
205
+ return { kind: "retry", retryAfterMs: wait, throttled: status === 429 };
206
+ }
207
+ if (status === 403 && code === "not_recordable") return { kind: "not_recordable" };
208
+ if (status === 401 || status === 403) return { kind: "refused" };
209
+ if (status === 422) return { kind: "session_full" };
210
+ return { kind: "rejected" };
211
+ }
212
+ async function encode(body) {
213
+ if (body.length <= GZIP_ABOVE_CHARS || !canGzip()) return body;
214
+ try {
215
+ return await gzip(body);
216
+ } catch {
217
+ return body;
218
+ }
219
+ }
220
+ function isGzip(payload) {
221
+ if (typeof payload === "string" || payload.byteLength < 2) return false;
222
+ const head = new Uint8Array(payload, 0, 2);
223
+ return head[0] === 31 && head[1] === 139;
224
+ }
225
+ function sizeOf(payload) {
226
+ return typeof payload === "string" ? payload.length : payload.byteLength;
227
+ }
228
+ async function post(url, key, payload, now) {
229
+ try {
230
+ const response = await fetch(url, {
231
+ method: "POST",
232
+ // A small body survives the page going away.
233
+ keepalive: sizeOf(payload) <= KEEPALIVE_MAX_CHARS,
234
+ credentials: "omit",
235
+ // A gzipped body says so: hosts in front of the engine (an AWS Lambda function URL) treat a body without
236
+ // Content-Encoding as text and corrupt the bytes (engine design note 67). The engine still sniffs 1f 8b.
237
+ headers: {
238
+ authorization: `Bearer ${key}`,
239
+ "content-type": "application/json",
240
+ ...isGzip(payload) ? { "content-encoding": "gzip" } : {}
241
+ },
242
+ body: payload
243
+ });
244
+ return await outcomeOf(response, now());
245
+ } catch {
246
+ return { kind: "retry", retryAfterMs: null, throttled: false };
247
+ }
248
+ }
249
+ function beacon(url, key, body) {
250
+ try {
251
+ if (typeof navigator === "undefined" || typeof navigator.sendBeacon !== "function") return false;
252
+ const target = `${url}${url.includes("?") ? "&" : "?"}key=${encodeURIComponent(key)}`;
253
+ return navigator.sendBeacon(target, new Blob([body], { type: "text/plain;charset=UTF-8" }));
254
+ } catch {
255
+ return false;
256
+ }
257
+ }
258
+
259
+ // ../browser/src/decision.ts
260
+ var SNAPSHOTS_PER_SESSION = 5;
261
+ var MODES = ["record", "buffer", "off"];
262
+ function fallbackDecision(sid, snapshots) {
263
+ return { sid, mode: "buffer", snapshots, seq: 0, snaps: [], maskAllText: false, blockedRoutes: [], slowDown: null };
264
+ }
265
+ function rate(value, fallback) {
266
+ return typeof value === "number" && Number.isFinite(value) ? Math.min(1, Math.max(0, value)) : fallback;
267
+ }
268
+ function strings(value) {
269
+ return Array.isArray(value) ? value.filter((item) => typeof item === "string") : [];
270
+ }
271
+ function decisionFrom(sid, config, random) {
272
+ const replay = config.replay ?? {};
273
+ const mode = MODES.includes(replay.mode) ? replay.mode : "buffer";
274
+ const slowDown = config.slow_down && typeof config.slow_down === "object" ? config.slow_down : null;
275
+ return {
276
+ sid,
277
+ mode: slowDown?.replay === false ? "off" : mode,
278
+ snapshots: slowDown?.replay !== false && random() < rate(config.snapshots?.sample_rate, 0.5),
279
+ seq: 0,
280
+ snaps: [],
281
+ maskAllText: replay.mask_all_text === true,
282
+ blockedRoutes: strings(replay.blocked_routes),
283
+ slowDown
284
+ };
285
+ }
286
+ function readDecision(sid) {
287
+ const raw = readStorage(STORAGE_KEYS.replay);
288
+ if (!raw) return null;
289
+ try {
290
+ const parsed = JSON.parse(raw);
291
+ if (parsed.sid !== sid || !isHexId(sid) || !MODES.includes(parsed.mode)) return null;
292
+ const seq = typeof parsed.seq === "number" && Number.isInteger(parsed.seq) && parsed.seq >= 0 ? parsed.seq : 0;
293
+ return {
294
+ sid,
295
+ mode: parsed.mode,
296
+ snapshots: parsed.snapshots === true,
297
+ seq,
298
+ snaps: strings(parsed.snaps).slice(0, SNAPSHOTS_PER_SESSION),
299
+ maskAllText: parsed.maskAllText === true,
300
+ blockedRoutes: strings(parsed.blockedRoutes),
301
+ slowDown: parsed.slowDown && typeof parsed.slowDown === "object" ? parsed.slowDown : null
302
+ };
303
+ } catch {
304
+ return null;
305
+ }
306
+ }
307
+ function writeDecision(decision) {
308
+ const stored = readDecision(decision.sid);
309
+ let mode = decision.mode;
310
+ let slowDown = decision.slowDown ?? null;
311
+ if (stored) {
312
+ if (stored.seq > decision.seq) decision.seq = stored.seq;
313
+ for (const route of stored.snaps) if (!decision.snaps.includes(route)) decision.snaps.push(route);
314
+ if (stored.mode === "off" || stored.mode === "record" && mode === "buffer") mode = stored.mode;
315
+ slowDown ??= stored.slowDown;
316
+ }
317
+ writeStorage(
318
+ STORAGE_KEYS.replay,
319
+ JSON.stringify({ ...decision, mode, snaps: decision.snaps.slice(0, SNAPSHOTS_PER_SESSION), slowDown })
320
+ );
321
+ }
322
+
323
+ export { ANON_SESSION_KEY, 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_IDLE_MS, SNAPSHOTS_PER_SESSION, SNAPSHOT_CHARS, SNAPSHOT_DELAY_MS, STORAGE_KEYS, UNANSWERED_GRACE_MS, beacon, currentPath, decisionFrom, deviceClassOf, encode, fallbackDecision, isBrowser, isGzip, isHidden, outcomeOf, pageLanguage, pageRefOf, post, readDecision, readStorage, readTabStorage, removeStorage, safe, viewport, whenIdle, writeDecision, writeStorage, writeTabStorage };
@@ -0,0 +1,27 @@
1
+ // ../next/src/config.ts
2
+ var CONFIG_ENV = "SYPNIA_CONFIG";
3
+ function readConfig() {
4
+ try {
5
+ const raw = typeof process !== "undefined" ? process.env.SYPNIA_CONFIG : void 0;
6
+ if (!raw) return null;
7
+ const parsed = JSON.parse(raw);
8
+ return typeof parsed.project === "string" && parsed.project ? parsed : null;
9
+ } catch {
10
+ return null;
11
+ }
12
+ }
13
+ function serializePatterns(patterns) {
14
+ return patterns?.map((pattern) => typeof pattern === "string" ? pattern : { re: pattern.source, flags: pattern.flags });
15
+ }
16
+ function deserializePatterns(patterns) {
17
+ return patterns?.flatMap((pattern) => {
18
+ if (typeof pattern === "string") return [pattern];
19
+ try {
20
+ return [new RegExp(pattern.re, pattern.flags)];
21
+ } catch {
22
+ return [];
23
+ }
24
+ });
25
+ }
26
+
27
+ export { CONFIG_ENV, deserializePatterns, readConfig, serializePatterns };