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 CHANGED
@@ -20715,16 +20715,37 @@ class SessionRecorder {
20715
20715
  writeSessionState({ ...state, chunk_seq: chunk_seq + 1 });
20716
20716
  const start_ts_ms = events[0].timestamp;
20717
20717
  const end_ts_ms = events[events.length - 1].timestamp;
20718
- uploadSessionEvents({
20719
- user_id: this.userId,
20720
- session_uuid: this.sessionUuid,
20721
- chunk_seq,
20722
- chunk_start_ts: new Date(start_ts_ms).toISOString(),
20723
- chunk_end_ts: new Date(end_ts_ms).toISOString(),
20724
- initial_url: chunk_seq === 0 ? state.initial_url : undefined,
20725
- events,
20726
- keepalive: true,
20727
- }).catch(() => { });
20718
+ const initial_url = chunk_seq === 0 ? state.initial_url : undefined;
20719
+ const chunk_start_ts = new Date(start_ts_ms).toISOString();
20720
+ const chunk_end_ts = new Date(end_ts_ms).toISOString();
20721
+ if (this.mode === "manual") {
20722
+ try {
20723
+ void this.onEvents({
20724
+ session_uuid: this.sessionUuid,
20725
+ chunk_seq,
20726
+ chunk_start_ts,
20727
+ chunk_end_ts,
20728
+ initial_url,
20729
+ events,
20730
+ keepalive: true,
20731
+ });
20732
+ }
20733
+ catch {
20734
+ // ignore
20735
+ }
20736
+ }
20737
+ else {
20738
+ uploadSessionEvents({
20739
+ user_id: this.userId,
20740
+ session_uuid: this.sessionUuid,
20741
+ chunk_seq,
20742
+ chunk_start_ts,
20743
+ chunk_end_ts,
20744
+ initial_url,
20745
+ events,
20746
+ keepalive: true,
20747
+ }).catch(() => { });
20748
+ }
20728
20749
  this.sessionEvents = [];
20729
20750
  this.bufferBytes = 0;
20730
20751
  }
@@ -20753,11 +20774,22 @@ class SessionRecorder {
20753
20774
  sessionStorage.setItem(testKey, "1");
20754
20775
  sessionStorage.removeItem(testKey);
20755
20776
  this.debug = (_a = config.debug) !== null && _a !== void 0 ? _a : false;
20756
- if (!((_b = config.WRITE_CODE) === null || _b === void 0 ? void 0 : _b.trim()) || !((_c = config.userId) === null || _c === void 0 ? void 0 : _c.trim())) {
20757
- return;
20777
+ if (config.mode === "manual") {
20778
+ this.mode = "manual";
20779
+ if (!config.onEvents || typeof config.onEvents !== "function") {
20780
+ __classPrivateFieldGet(this, _SessionRecorder_instances, "m", _SessionRecorder_log).call(this, "onEvents callback is required in manual mode");
20781
+ return;
20782
+ }
20783
+ this.onEvents = config.onEvents;
20784
+ }
20785
+ else {
20786
+ this.mode = "auto";
20787
+ if (!((_b = config.WRITE_CODE) === null || _b === void 0 ? void 0 : _b.trim()) || !((_c = config.userId) === null || _c === void 0 ? void 0 : _c.trim())) {
20788
+ return;
20789
+ }
20790
+ saveWriteCode(config.WRITE_CODE);
20791
+ this.userId = config.userId;
20758
20792
  }
20759
- saveWriteCode(config.WRITE_CODE);
20760
- this.userId = config.userId;
20761
20793
  const { recordingOptions = {} } = config;
20762
20794
  const { TIMEOUT = 30 * 60 * 1000, BUFFER_SIZE = 30, maskingOptions = ["passwords"], recordCrossOriginIframes = false, } = recordingOptions;
20763
20795
  this.TIMEOUT = TIMEOUT;
@@ -20904,15 +20936,30 @@ _SessionRecorder_uploading = new WeakMap(), _SessionRecorder_uploadingMaxTs = ne
20904
20936
  return;
20905
20937
  }
20906
20938
  const chunk_seq = state.chunk_seq;
20907
- await uploadSessionEvents({
20908
- user_id: this.userId,
20909
- session_uuid: this.sessionUuid,
20910
- chunk_seq,
20911
- chunk_start_ts: new Date(start_ts_ms).toISOString(),
20912
- chunk_end_ts: new Date(end_ts_ms).toISOString(),
20913
- initial_url: chunk_seq === 0 ? state.initial_url : undefined,
20914
- events,
20915
- });
20939
+ const initial_url = chunk_seq === 0 ? state.initial_url : undefined;
20940
+ const chunk_start_ts = new Date(start_ts_ms).toISOString();
20941
+ const chunk_end_ts = new Date(end_ts_ms).toISOString();
20942
+ if (this.mode === "manual") {
20943
+ await this.onEvents({
20944
+ session_uuid: this.sessionUuid,
20945
+ chunk_seq,
20946
+ chunk_start_ts,
20947
+ chunk_end_ts,
20948
+ initial_url,
20949
+ events,
20950
+ });
20951
+ }
20952
+ else {
20953
+ await uploadSessionEvents({
20954
+ user_id: this.userId,
20955
+ session_uuid: this.sessionUuid,
20956
+ chunk_seq,
20957
+ chunk_start_ts,
20958
+ chunk_end_ts,
20959
+ initial_url,
20960
+ events,
20961
+ });
20962
+ }
20916
20963
  const removedBytes = events.reduce((sum, e) => sum + estimateEventSize(e), 0);
20917
20964
  this.sessionEvents = this.sessionEvents.slice(snapshot_count);
20918
20965
  this.bufferBytes = Math.max(0, this.bufferBytes - removedBytes);