@extn/segi-js 0.1.1 → 0.2.1
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/README.md +24 -0
- package/dist/cdn.global.js +36 -2
- package/dist/index.d.mts +27 -2
- package/dist/index.d.ts +27 -2
- package/dist/index.js +115 -75
- package/dist/index.mjs +81 -14
- package/dist/replay/index.d.mts +61 -0
- package/dist/replay/index.d.ts +61 -0
- package/dist/replay/index.js +492 -0
- package/dist/replay/index.mjs +492 -0
- package/dist/rrweb-3KMD3KRA.js +140 -0
- package/dist/rrweb-VLNL5J73.mjs +140 -0
- package/dist/types-DfmnOA9D.d.mts +30 -0
- package/dist/types-DfmnOA9D.d.ts +30 -0
- package/package.json +8 -2
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
// src/replay/rrweb.ts
|
|
2
|
+
var CHECKOUT_EVERY_MS = 3e4;
|
|
3
|
+
var FLUSH_INTERVAL_MS = 1e4;
|
|
4
|
+
var FLUSH_BYTES = 100 * 1024;
|
|
5
|
+
var IDLE_PAUSE_MS = 3 * 6e4;
|
|
6
|
+
var IDLE_CHECK_MS = 15e3;
|
|
7
|
+
var ACTIVITY_EVENTS = [
|
|
8
|
+
"mousemove",
|
|
9
|
+
"mousedown",
|
|
10
|
+
"keydown",
|
|
11
|
+
"touchstart",
|
|
12
|
+
"scroll",
|
|
13
|
+
"wheel"
|
|
14
|
+
];
|
|
15
|
+
async function startRrweb(args) {
|
|
16
|
+
if (typeof window === "undefined") return null;
|
|
17
|
+
let rrweb;
|
|
18
|
+
try {
|
|
19
|
+
rrweb = await import("rrweb");
|
|
20
|
+
} catch {
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
const maskClass = args.options.mask?.class ?? "segi-mask";
|
|
24
|
+
const inputMode = args.options.mask?.inputs ?? "all";
|
|
25
|
+
const maskInputOptions = inputMode === "all" ? {
|
|
26
|
+
password: true,
|
|
27
|
+
email: true,
|
|
28
|
+
tel: true,
|
|
29
|
+
number: true,
|
|
30
|
+
text: true,
|
|
31
|
+
textarea: true
|
|
32
|
+
} : inputMode === "sensitive" ? { password: true, email: true, tel: true, number: true } : { password: true };
|
|
33
|
+
let buffer = [];
|
|
34
|
+
let bufferBytes = 0;
|
|
35
|
+
let stopFn = null;
|
|
36
|
+
let lastActivityAt = Date.now();
|
|
37
|
+
let paused = false;
|
|
38
|
+
let stopped = false;
|
|
39
|
+
const flushTimer = setInterval(() => {
|
|
40
|
+
if (paused || stopped) return;
|
|
41
|
+
flush();
|
|
42
|
+
}, FLUSH_INTERVAL_MS);
|
|
43
|
+
const idleTimer = setInterval(() => {
|
|
44
|
+
if (paused || stopped) return;
|
|
45
|
+
if (Date.now() - lastActivityAt >= IDLE_PAUSE_MS) {
|
|
46
|
+
stopRrwebOnly();
|
|
47
|
+
}
|
|
48
|
+
}, IDLE_CHECK_MS);
|
|
49
|
+
function startRecorder() {
|
|
50
|
+
if (stopFn) return;
|
|
51
|
+
const stop = rrweb.record({
|
|
52
|
+
emit(event) {
|
|
53
|
+
if (paused || stopped) return;
|
|
54
|
+
buffer.push(event);
|
|
55
|
+
try {
|
|
56
|
+
bufferBytes += JSON.stringify(event).length;
|
|
57
|
+
} catch {
|
|
58
|
+
}
|
|
59
|
+
if (bufferBytes >= FLUSH_BYTES) flush();
|
|
60
|
+
},
|
|
61
|
+
// `input: "last"` emits only the final value of each keystroke
|
|
62
|
+
// run, not one event per character. Smaller payloads, less PII risk
|
|
63
|
+
// for non-masked inputs.
|
|
64
|
+
sampling: { mousemove: 20, scroll: 150, input: "last" },
|
|
65
|
+
maskAllInputs: inputMode === "all",
|
|
66
|
+
maskInputOptions,
|
|
67
|
+
blockClass: maskClass,
|
|
68
|
+
ignoreClass: maskClass,
|
|
69
|
+
maskTextClass: maskClass,
|
|
70
|
+
recordCanvas: false,
|
|
71
|
+
collectFonts: false,
|
|
72
|
+
checkoutEveryNms: CHECKOUT_EVERY_MS
|
|
73
|
+
});
|
|
74
|
+
stopFn = typeof stop === "function" ? stop : null;
|
|
75
|
+
}
|
|
76
|
+
function stopRrwebOnly() {
|
|
77
|
+
try {
|
|
78
|
+
stopFn?.();
|
|
79
|
+
} finally {
|
|
80
|
+
stopFn = null;
|
|
81
|
+
}
|
|
82
|
+
flush();
|
|
83
|
+
}
|
|
84
|
+
function flush(useBeacon = false) {
|
|
85
|
+
if (buffer.length === 0) return;
|
|
86
|
+
const chunk = buffer;
|
|
87
|
+
buffer = [];
|
|
88
|
+
bufferBytes = 0;
|
|
89
|
+
try {
|
|
90
|
+
args.sendChunk(chunk, useBeacon);
|
|
91
|
+
} catch {
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
function onActivity() {
|
|
95
|
+
lastActivityAt = Date.now();
|
|
96
|
+
if (!stopFn && !paused && !stopped) startRecorder();
|
|
97
|
+
}
|
|
98
|
+
for (const ev of ACTIVITY_EVENTS) {
|
|
99
|
+
window.addEventListener(ev, onActivity, { passive: true, capture: true });
|
|
100
|
+
}
|
|
101
|
+
const onPageHide = () => flush(true);
|
|
102
|
+
const onVisibilityChange = () => {
|
|
103
|
+
if (typeof document !== "undefined" && document.visibilityState === "hidden") {
|
|
104
|
+
flush(true);
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
window.addEventListener("pagehide", onPageHide);
|
|
108
|
+
if (typeof document !== "undefined") {
|
|
109
|
+
document.addEventListener("visibilitychange", onVisibilityChange);
|
|
110
|
+
}
|
|
111
|
+
startRecorder();
|
|
112
|
+
return {
|
|
113
|
+
pause() {
|
|
114
|
+
paused = true;
|
|
115
|
+
stopRrwebOnly();
|
|
116
|
+
},
|
|
117
|
+
resume() {
|
|
118
|
+
paused = false;
|
|
119
|
+
lastActivityAt = Date.now();
|
|
120
|
+
startRecorder();
|
|
121
|
+
},
|
|
122
|
+
stop() {
|
|
123
|
+
stopped = true;
|
|
124
|
+
stopRrwebOnly();
|
|
125
|
+
clearInterval(flushTimer);
|
|
126
|
+
clearInterval(idleTimer);
|
|
127
|
+
for (const ev of ACTIVITY_EVENTS) {
|
|
128
|
+
window.removeEventListener(ev, onActivity, { capture: true });
|
|
129
|
+
}
|
|
130
|
+
window.removeEventListener("pagehide", onPageHide);
|
|
131
|
+
if (typeof document !== "undefined") {
|
|
132
|
+
document.removeEventListener("visibilitychange", onVisibilityChange);
|
|
133
|
+
}
|
|
134
|
+
},
|
|
135
|
+
flush
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
export {
|
|
139
|
+
startRrweb
|
|
140
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Replay/heatmap collector — public option types and internal DTOs.
|
|
3
|
+
* Mirrors apps/api/src/trace/trace.types.ts at the field level.
|
|
4
|
+
*
|
|
5
|
+
* This first pass ships heatmap clicks + scroll + page_view events. rrweb
|
|
6
|
+
* DOM replay lands in a follow-up (it requires the rrweb peer dependency
|
|
7
|
+
* and the S3 ingest path on the server, which is currently 501-stubbed).
|
|
8
|
+
*/
|
|
9
|
+
interface ReplayOptions {
|
|
10
|
+
/** Toggle the whole module. Setting `false` causes withReplay() to return null. */
|
|
11
|
+
enabled?: boolean;
|
|
12
|
+
/** 0..100 probabilistic gate — only this percent of sessions get recorded. */
|
|
13
|
+
sample?: number;
|
|
14
|
+
/** Path-prefix deny-list (in addition to the server-side per-project list). */
|
|
15
|
+
blockRoutes?: string[];
|
|
16
|
+
/** rrweb / heatmap mask. Class is recursively checked up the ancestor chain. */
|
|
17
|
+
mask?: {
|
|
18
|
+
inputs?: "all" | "sensitive" | "none";
|
|
19
|
+
class?: string;
|
|
20
|
+
};
|
|
21
|
+
/** Override default endpoint base. Defaults to SegiClientOptions.endpoint. */
|
|
22
|
+
endpoint?: string;
|
|
23
|
+
}
|
|
24
|
+
interface ReplayConfig {
|
|
25
|
+
/** Internal sentinel — set by withReplay(); main init imports the runtime. */
|
|
26
|
+
readonly __segi_replay: true;
|
|
27
|
+
options: ReplayOptions;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export type { ReplayConfig as R, ReplayOptions as a };
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Replay/heatmap collector — public option types and internal DTOs.
|
|
3
|
+
* Mirrors apps/api/src/trace/trace.types.ts at the field level.
|
|
4
|
+
*
|
|
5
|
+
* This first pass ships heatmap clicks + scroll + page_view events. rrweb
|
|
6
|
+
* DOM replay lands in a follow-up (it requires the rrweb peer dependency
|
|
7
|
+
* and the S3 ingest path on the server, which is currently 501-stubbed).
|
|
8
|
+
*/
|
|
9
|
+
interface ReplayOptions {
|
|
10
|
+
/** Toggle the whole module. Setting `false` causes withReplay() to return null. */
|
|
11
|
+
enabled?: boolean;
|
|
12
|
+
/** 0..100 probabilistic gate — only this percent of sessions get recorded. */
|
|
13
|
+
sample?: number;
|
|
14
|
+
/** Path-prefix deny-list (in addition to the server-side per-project list). */
|
|
15
|
+
blockRoutes?: string[];
|
|
16
|
+
/** rrweb / heatmap mask. Class is recursively checked up the ancestor chain. */
|
|
17
|
+
mask?: {
|
|
18
|
+
inputs?: "all" | "sensitive" | "none";
|
|
19
|
+
class?: string;
|
|
20
|
+
};
|
|
21
|
+
/** Override default endpoint base. Defaults to SegiClientOptions.endpoint. */
|
|
22
|
+
endpoint?: string;
|
|
23
|
+
}
|
|
24
|
+
interface ReplayConfig {
|
|
25
|
+
/** Internal sentinel — set by withReplay(); main init imports the runtime. */
|
|
26
|
+
readonly __segi_replay: true;
|
|
27
|
+
options: ReplayOptions;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export type { ReplayConfig as R, ReplayOptions as a };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@extn/segi-js",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"description": "Browser JavaScript SDK for the segi error monitoring service",
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -12,6 +12,11 @@
|
|
|
12
12
|
"import": "./dist/index.mjs",
|
|
13
13
|
"require": "./dist/index.js"
|
|
14
14
|
},
|
|
15
|
+
"./replay": {
|
|
16
|
+
"types": "./dist/replay/index.d.ts",
|
|
17
|
+
"import": "./dist/replay/index.mjs",
|
|
18
|
+
"require": "./dist/replay/index.js"
|
|
19
|
+
},
|
|
15
20
|
"./cdn": "./dist/cdn.global.js"
|
|
16
21
|
},
|
|
17
22
|
"files": [
|
|
@@ -23,7 +28,8 @@
|
|
|
23
28
|
"access": "public"
|
|
24
29
|
},
|
|
25
30
|
"dependencies": {
|
|
26
|
-
"
|
|
31
|
+
"rrweb": "2.0.0-alpha.4",
|
|
32
|
+
"@extn/segi-shared": "0.2.0"
|
|
27
33
|
},
|
|
28
34
|
"devDependencies": {
|
|
29
35
|
"tsup": "^8.3.0",
|