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