@leanbase-giangnd/js 0.0.0 → 0.0.2

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.0";
1186
+ var version = "0.0.2";
1187
1187
  var packageInfo = {
1188
1188
  version: version};
1189
1189
 
@@ -5820,6 +5820,29 @@ class Leanbase extends PostHogCore {
5820
5820
  if (!fetchFn) {
5821
5821
  return Promise.reject(new Error('Fetch API is not available in this environment.'));
5822
5822
  }
5823
+ try {
5824
+ const isPost = !options.method || options.method.toUpperCase() === 'POST';
5825
+ const isBatchEndpoint = typeof url === 'string' && url.endsWith('/batch/');
5826
+ if (isPost && isBatchEndpoint && options && options.body) {
5827
+ let parsed = null;
5828
+ try {
5829
+ const bodyString = typeof options.body === 'string' ? options.body : String(options.body);
5830
+ parsed = JSON.parse(bodyString);
5831
+ } catch {
5832
+ parsed = null;
5833
+ }
5834
+ if (parsed && isArray(parsed.batch)) {
5835
+ const hasSnapshot = parsed.batch.some(item => item && item.event === '$snapshot');
5836
+ if (hasSnapshot) {
5837
+ const host = this.config && this.config.host || '';
5838
+ const newUrl = host ? `${host.replace(/\/$/, '')}/s/` : url;
5839
+ return fetchFn(newUrl, options);
5840
+ }
5841
+ }
5842
+ }
5843
+ } catch {
5844
+ return fetchFn(url, options);
5845
+ }
5823
5846
  return fetchFn(url, options);
5824
5847
  }
5825
5848
  setConfig(config) {