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.d.ts CHANGED
@@ -1,8 +1,10 @@
1
- import { MaskingOption, SessionRecorderConfig } from "./types";
2
- export type { SessionRecorderConfig, MaskingOption, };
1
+ import { MaskingOption, RecorderMode, EventBatch, OnEventsCallback, SessionRecorderConfig, AutoModeConfig, ManualModeConfig } from "./types";
2
+ export type { SessionRecorderConfig, AutoModeConfig, ManualModeConfig, RecorderMode, EventBatch, OnEventsCallback, MaskingOption, };
3
3
  export default class SessionRecorder {
4
4
  #private;
5
+ private mode;
5
6
  private userId?;
7
+ private onEvents?;
6
8
  private TIMEOUT;
7
9
  private BUFFER_SIZE;
8
10
  private maskingOptions;
package/dist/index.esm.js CHANGED
@@ -20711,16 +20711,37 @@ class SessionRecorder {
20711
20711
  writeSessionState({ ...state, chunk_seq: chunk_seq + 1 });
20712
20712
  const start_ts_ms = events[0].timestamp;
20713
20713
  const end_ts_ms = events[events.length - 1].timestamp;
20714
- uploadSessionEvents({
20715
- user_id: this.userId,
20716
- session_uuid: this.sessionUuid,
20717
- chunk_seq,
20718
- chunk_start_ts: new Date(start_ts_ms).toISOString(),
20719
- chunk_end_ts: new Date(end_ts_ms).toISOString(),
20720
- initial_url: chunk_seq === 0 ? state.initial_url : undefined,
20721
- events,
20722
- keepalive: true,
20723
- }).catch(() => { });
20714
+ const initial_url = chunk_seq === 0 ? state.initial_url : undefined;
20715
+ const chunk_start_ts = new Date(start_ts_ms).toISOString();
20716
+ const chunk_end_ts = new Date(end_ts_ms).toISOString();
20717
+ if (this.mode === "manual") {
20718
+ try {
20719
+ void this.onEvents({
20720
+ session_uuid: this.sessionUuid,
20721
+ chunk_seq,
20722
+ chunk_start_ts,
20723
+ chunk_end_ts,
20724
+ initial_url,
20725
+ events,
20726
+ keepalive: true,
20727
+ });
20728
+ }
20729
+ catch {
20730
+ // ignore
20731
+ }
20732
+ }
20733
+ else {
20734
+ uploadSessionEvents({
20735
+ user_id: this.userId,
20736
+ session_uuid: this.sessionUuid,
20737
+ chunk_seq,
20738
+ chunk_start_ts,
20739
+ chunk_end_ts,
20740
+ initial_url,
20741
+ events,
20742
+ keepalive: true,
20743
+ }).catch(() => { });
20744
+ }
20724
20745
  this.sessionEvents = [];
20725
20746
  this.bufferBytes = 0;
20726
20747
  }
@@ -20749,11 +20770,22 @@ class SessionRecorder {
20749
20770
  sessionStorage.setItem(testKey, "1");
20750
20771
  sessionStorage.removeItem(testKey);
20751
20772
  this.debug = (_a = config.debug) !== null && _a !== void 0 ? _a : false;
20752
- if (!((_b = config.WRITE_CODE) === null || _b === void 0 ? void 0 : _b.trim()) || !((_c = config.userId) === null || _c === void 0 ? void 0 : _c.trim())) {
20753
- return;
20773
+ if (config.mode === "manual") {
20774
+ this.mode = "manual";
20775
+ if (!config.onEvents || typeof config.onEvents !== "function") {
20776
+ __classPrivateFieldGet(this, _SessionRecorder_instances, "m", _SessionRecorder_log).call(this, "onEvents callback is required in manual mode");
20777
+ return;
20778
+ }
20779
+ this.onEvents = config.onEvents;
20780
+ }
20781
+ else {
20782
+ this.mode = "auto";
20783
+ if (!((_b = config.WRITE_CODE) === null || _b === void 0 ? void 0 : _b.trim()) || !((_c = config.userId) === null || _c === void 0 ? void 0 : _c.trim())) {
20784
+ return;
20785
+ }
20786
+ saveWriteCode(config.WRITE_CODE);
20787
+ this.userId = config.userId;
20754
20788
  }
20755
- saveWriteCode(config.WRITE_CODE);
20756
- this.userId = config.userId;
20757
20789
  const { recordingOptions = {} } = config;
20758
20790
  const { TIMEOUT = 30 * 60 * 1000, BUFFER_SIZE = 30, maskingOptions = ["passwords"], recordCrossOriginIframes = false, } = recordingOptions;
20759
20791
  this.TIMEOUT = TIMEOUT;
@@ -20900,15 +20932,30 @@ _SessionRecorder_uploading = new WeakMap(), _SessionRecorder_uploadingMaxTs = ne
20900
20932
  return;
20901
20933
  }
20902
20934
  const chunk_seq = state.chunk_seq;
20903
- await uploadSessionEvents({
20904
- user_id: this.userId,
20905
- session_uuid: this.sessionUuid,
20906
- chunk_seq,
20907
- chunk_start_ts: new Date(start_ts_ms).toISOString(),
20908
- chunk_end_ts: new Date(end_ts_ms).toISOString(),
20909
- initial_url: chunk_seq === 0 ? state.initial_url : undefined,
20910
- events,
20911
- });
20935
+ const initial_url = chunk_seq === 0 ? state.initial_url : undefined;
20936
+ const chunk_start_ts = new Date(start_ts_ms).toISOString();
20937
+ const chunk_end_ts = new Date(end_ts_ms).toISOString();
20938
+ if (this.mode === "manual") {
20939
+ await this.onEvents({
20940
+ session_uuid: this.sessionUuid,
20941
+ chunk_seq,
20942
+ chunk_start_ts,
20943
+ chunk_end_ts,
20944
+ initial_url,
20945
+ events,
20946
+ });
20947
+ }
20948
+ else {
20949
+ await uploadSessionEvents({
20950
+ user_id: this.userId,
20951
+ session_uuid: this.sessionUuid,
20952
+ chunk_seq,
20953
+ chunk_start_ts,
20954
+ chunk_end_ts,
20955
+ initial_url,
20956
+ events,
20957
+ });
20958
+ }
20912
20959
  const removedBytes = events.reduce((sum, e) => sum + estimateEventSize(e), 0);
20913
20960
  this.sessionEvents = this.sessionEvents.slice(snapshot_count);
20914
20961
  this.bufferBytes = Math.max(0, this.bufferBytes - removedBytes);