@base44/sdk 0.8.9 → 0.8.10

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.
@@ -46,9 +46,9 @@ export const createAnalyticsModule = ({ axiosClient, serverUrl, appId, userAuthM
46
46
  });
47
47
  };
48
48
  // currently disabled, until fully tested //
49
- const beaconRequest = async (events) => {
50
- const beaconPayload = JSON.stringify({ events });
49
+ const beaconRequest = (events) => {
51
50
  try {
51
+ const beaconPayload = JSON.stringify({ events });
52
52
  const blob = new Blob([beaconPayload], { type: "application/json" });
53
53
  return (typeof navigator === "undefined" ||
54
54
  beaconPayload.length > 60000 ||
@@ -58,11 +58,15 @@ export const createAnalyticsModule = ({ axiosClient, serverUrl, appId, userAuthM
58
58
  return false;
59
59
  }
60
60
  };
61
- const flush = async (eventsData) => {
61
+ const flush = async (eventsData, options = {}) => {
62
+ if (eventsData.length === 0)
63
+ return;
62
64
  const sessionContext_ = await getSessionContext(userAuthModule);
63
65
  const events = eventsData.map(transformEventDataToApiRequestData(sessionContext_));
64
66
  try {
65
- return batchRequestFallback(events);
67
+ if (!options.isBeacon || !beaconRequest(events)) {
68
+ await batchRequestFallback(events);
69
+ }
66
70
  }
67
71
  catch (_a) {
68
72
  // do nothing
@@ -94,10 +98,10 @@ export const createAnalyticsModule = ({ axiosClient, serverUrl, appId, userAuthM
94
98
  };
95
99
  const onDocHidden = () => {
96
100
  stopAnalyticsProcessor();
101
+ clearHeartBeatProcessor === null || clearHeartBeatProcessor === void 0 ? void 0 : clearHeartBeatProcessor();
97
102
  // flush entire queue on visibility change and hope for the best //
98
103
  const eventsData = analyticsSharedState.requestsQueue.splice(0);
99
- flush(eventsData);
100
- clearHeartBeatProcessor === null || clearHeartBeatProcessor === void 0 ? void 0 : clearHeartBeatProcessor();
104
+ flush(eventsData, { isBeacon: true });
101
105
  };
102
106
  const onVisibilityChange = () => {
103
107
  if (typeof window === "undefined")
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@base44/sdk",
3
- "version": "0.8.9",
3
+ "version": "0.8.10",
4
4
  "description": "JavaScript SDK for Base44 API",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",