@leanbase-giangnd/js 0.0.3 → 0.0.4

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.mjs CHANGED
@@ -1183,7 +1183,7 @@ const detectDeviceType = function (user_agent) {
1183
1183
  }
1184
1184
  };
1185
1185
 
1186
- var version = "0.0.3";
1186
+ var version = "0.0.4";
1187
1187
  var packageInfo = {
1188
1188
  version: version};
1189
1189
 
@@ -5883,6 +5883,35 @@ class Leanbase extends PostHogCore {
5883
5883
  // eslint-disable-next-line no-console
5884
5884
  console.debug('[Leanbase.fetch] parsed.batch.length=', parsed.batch.length, 'hasSnapshot=', hasSnapshot);
5885
5885
  } catch {}
5886
+ // If remote config has explicitly disabled session recording, drop snapshot events
5887
+ try {
5888
+ // Read persisted remote config that SessionRecording stores
5889
+ const persisted = this.get_property(SESSION_RECORDING_REMOTE_CONFIG);
5890
+ const serverAllowsRecording = !(persisted && persisted.enabled === false || this.config.disable_session_recording === true);
5891
+ if (!serverAllowsRecording && hasSnapshot) {
5892
+ // remove snapshot events from the batch before sending to /batch/
5893
+ parsed.batch = parsed.batch.filter(item => !(item && item.event === '$snapshot'));
5894
+ // If no events remain, short-circuit and avoid sending an empty batch
5895
+ if (!parsed.batch.length) {
5896
+ try {
5897
+ // eslint-disable-next-line no-console
5898
+ console.debug('[Leanbase.fetch] sessionRecording disabled, dropping snapshot-only batch');
5899
+ } catch {}
5900
+ return {
5901
+ status: 200,
5902
+ json: async () => ({})
5903
+ };
5904
+ }
5905
+ // re-encode the body so the underlying fetch receives the modified batch
5906
+ try {
5907
+ const newBody = JSON.stringify(parsed);
5908
+ options = {
5909
+ ...options,
5910
+ body: newBody
5911
+ };
5912
+ } catch {}
5913
+ }
5914
+ } catch {}
5886
5915
  if (hasSnapshot) {
5887
5916
  const host = this.config && this.config.host || '';
5888
5917
  const newUrl = host ? `${host.replace(/\/$/, '')}/s/` : url;