userlens-session-recorder 2.0.2 → 2.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/dist/index.cjs.js +70 -23
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +4 -2
- package/dist/index.esm.js +70 -23
- package/dist/index.esm.js.map +1 -1
- package/dist/types/index.d.ts +25 -2
- package/dist/userlens-session-recorder.umd.js +70 -23
- package/dist/userlens-session-recorder.umd.js.map +1 -1
- package/package.json +1 -1
package/dist/types/index.d.ts
CHANGED
|
@@ -1,20 +1,43 @@
|
|
|
1
|
+
import { eventWithTime } from 'rrweb';
|
|
2
|
+
|
|
1
3
|
type MaskingOption = "passwords" | "all";
|
|
4
|
+
type RecorderMode = "auto" | "manual";
|
|
2
5
|
interface SessionRecordingOptions {
|
|
3
6
|
TIMEOUT?: number;
|
|
4
7
|
BUFFER_SIZE?: number;
|
|
5
8
|
maskingOptions?: MaskingOption[];
|
|
6
9
|
recordCrossOriginIframes?: boolean;
|
|
7
10
|
}
|
|
8
|
-
interface
|
|
11
|
+
interface EventBatch {
|
|
12
|
+
session_uuid: string;
|
|
13
|
+
chunk_seq: number;
|
|
14
|
+
chunk_start_ts: string;
|
|
15
|
+
chunk_end_ts: string;
|
|
16
|
+
initial_url?: string;
|
|
17
|
+
events: eventWithTime[];
|
|
18
|
+
keepalive?: boolean;
|
|
19
|
+
}
|
|
20
|
+
type OnEventsCallback = (batch: EventBatch) => void | Promise<void>;
|
|
21
|
+
interface AutoModeConfig {
|
|
22
|
+
mode?: "auto";
|
|
9
23
|
WRITE_CODE: string;
|
|
10
24
|
userId: string;
|
|
11
25
|
recordingOptions?: SessionRecordingOptions;
|
|
12
26
|
debug?: boolean;
|
|
13
27
|
}
|
|
28
|
+
interface ManualModeConfig {
|
|
29
|
+
mode: "manual";
|
|
30
|
+
onEvents: OnEventsCallback;
|
|
31
|
+
recordingOptions?: SessionRecordingOptions;
|
|
32
|
+
debug?: boolean;
|
|
33
|
+
}
|
|
34
|
+
type SessionRecorderConfig = AutoModeConfig | ManualModeConfig;
|
|
14
35
|
|
|
15
36
|
declare class SessionRecorder {
|
|
16
37
|
#private;
|
|
38
|
+
private mode;
|
|
17
39
|
private userId?;
|
|
40
|
+
private onEvents?;
|
|
18
41
|
private TIMEOUT;
|
|
19
42
|
private BUFFER_SIZE;
|
|
20
43
|
private maskingOptions;
|
|
@@ -30,4 +53,4 @@ declare class SessionRecorder {
|
|
|
30
53
|
}
|
|
31
54
|
|
|
32
55
|
export { SessionRecorder as default };
|
|
33
|
-
export type { MaskingOption, SessionRecorderConfig };
|
|
56
|
+
export type { AutoModeConfig, EventBatch, ManualModeConfig, MaskingOption, OnEventsCallback, RecorderMode, SessionRecorderConfig };
|
|
@@ -20717,16 +20717,37 @@
|
|
|
20717
20717
|
writeSessionState({ ...state, chunk_seq: chunk_seq + 1 });
|
|
20718
20718
|
const start_ts_ms = events[0].timestamp;
|
|
20719
20719
|
const end_ts_ms = events[events.length - 1].timestamp;
|
|
20720
|
-
|
|
20721
|
-
|
|
20722
|
-
|
|
20723
|
-
|
|
20724
|
-
|
|
20725
|
-
|
|
20726
|
-
|
|
20727
|
-
|
|
20728
|
-
|
|
20729
|
-
|
|
20720
|
+
const initial_url = chunk_seq === 0 ? state.initial_url : undefined;
|
|
20721
|
+
const chunk_start_ts = new Date(start_ts_ms).toISOString();
|
|
20722
|
+
const chunk_end_ts = new Date(end_ts_ms).toISOString();
|
|
20723
|
+
if (this.mode === "manual") {
|
|
20724
|
+
try {
|
|
20725
|
+
void this.onEvents({
|
|
20726
|
+
session_uuid: this.sessionUuid,
|
|
20727
|
+
chunk_seq,
|
|
20728
|
+
chunk_start_ts,
|
|
20729
|
+
chunk_end_ts,
|
|
20730
|
+
initial_url,
|
|
20731
|
+
events,
|
|
20732
|
+
keepalive: true,
|
|
20733
|
+
});
|
|
20734
|
+
}
|
|
20735
|
+
catch {
|
|
20736
|
+
// ignore
|
|
20737
|
+
}
|
|
20738
|
+
}
|
|
20739
|
+
else {
|
|
20740
|
+
uploadSessionEvents({
|
|
20741
|
+
user_id: this.userId,
|
|
20742
|
+
session_uuid: this.sessionUuid,
|
|
20743
|
+
chunk_seq,
|
|
20744
|
+
chunk_start_ts,
|
|
20745
|
+
chunk_end_ts,
|
|
20746
|
+
initial_url,
|
|
20747
|
+
events,
|
|
20748
|
+
keepalive: true,
|
|
20749
|
+
}).catch(() => { });
|
|
20750
|
+
}
|
|
20730
20751
|
this.sessionEvents = [];
|
|
20731
20752
|
this.bufferBytes = 0;
|
|
20732
20753
|
}
|
|
@@ -20755,11 +20776,22 @@
|
|
|
20755
20776
|
sessionStorage.setItem(testKey, "1");
|
|
20756
20777
|
sessionStorage.removeItem(testKey);
|
|
20757
20778
|
this.debug = (_a = config.debug) !== null && _a !== void 0 ? _a : false;
|
|
20758
|
-
if (
|
|
20759
|
-
|
|
20779
|
+
if (config.mode === "manual") {
|
|
20780
|
+
this.mode = "manual";
|
|
20781
|
+
if (!config.onEvents || typeof config.onEvents !== "function") {
|
|
20782
|
+
__classPrivateFieldGet(this, _SessionRecorder_instances, "m", _SessionRecorder_log).call(this, "onEvents callback is required in manual mode");
|
|
20783
|
+
return;
|
|
20784
|
+
}
|
|
20785
|
+
this.onEvents = config.onEvents;
|
|
20786
|
+
}
|
|
20787
|
+
else {
|
|
20788
|
+
this.mode = "auto";
|
|
20789
|
+
if (!((_b = config.WRITE_CODE) === null || _b === void 0 ? void 0 : _b.trim()) || !((_c = config.userId) === null || _c === void 0 ? void 0 : _c.trim())) {
|
|
20790
|
+
return;
|
|
20791
|
+
}
|
|
20792
|
+
saveWriteCode(config.WRITE_CODE);
|
|
20793
|
+
this.userId = config.userId;
|
|
20760
20794
|
}
|
|
20761
|
-
saveWriteCode(config.WRITE_CODE);
|
|
20762
|
-
this.userId = config.userId;
|
|
20763
20795
|
const { recordingOptions = {} } = config;
|
|
20764
20796
|
const { TIMEOUT = 30 * 60 * 1000, BUFFER_SIZE = 30, maskingOptions = ["passwords"], recordCrossOriginIframes = false, } = recordingOptions;
|
|
20765
20797
|
this.TIMEOUT = TIMEOUT;
|
|
@@ -20906,15 +20938,30 @@
|
|
|
20906
20938
|
return;
|
|
20907
20939
|
}
|
|
20908
20940
|
const chunk_seq = state.chunk_seq;
|
|
20909
|
-
|
|
20910
|
-
|
|
20911
|
-
|
|
20912
|
-
|
|
20913
|
-
|
|
20914
|
-
|
|
20915
|
-
|
|
20916
|
-
|
|
20917
|
-
|
|
20941
|
+
const initial_url = chunk_seq === 0 ? state.initial_url : undefined;
|
|
20942
|
+
const chunk_start_ts = new Date(start_ts_ms).toISOString();
|
|
20943
|
+
const chunk_end_ts = new Date(end_ts_ms).toISOString();
|
|
20944
|
+
if (this.mode === "manual") {
|
|
20945
|
+
await this.onEvents({
|
|
20946
|
+
session_uuid: this.sessionUuid,
|
|
20947
|
+
chunk_seq,
|
|
20948
|
+
chunk_start_ts,
|
|
20949
|
+
chunk_end_ts,
|
|
20950
|
+
initial_url,
|
|
20951
|
+
events,
|
|
20952
|
+
});
|
|
20953
|
+
}
|
|
20954
|
+
else {
|
|
20955
|
+
await uploadSessionEvents({
|
|
20956
|
+
user_id: this.userId,
|
|
20957
|
+
session_uuid: this.sessionUuid,
|
|
20958
|
+
chunk_seq,
|
|
20959
|
+
chunk_start_ts,
|
|
20960
|
+
chunk_end_ts,
|
|
20961
|
+
initial_url,
|
|
20962
|
+
events,
|
|
20963
|
+
});
|
|
20964
|
+
}
|
|
20918
20965
|
const removedBytes = events.reduce((sum, e) => sum + estimateEventSize(e), 0);
|
|
20919
20966
|
this.sessionEvents = this.sessionEvents.slice(snapshot_count);
|
|
20920
20967
|
this.bufferBytes = Math.max(0, this.bufferBytes - removedBytes);
|