@base44/sdk 0.8.8 → 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.
@@ -2,7 +2,7 @@ import { AxiosInstance } from "axios";
2
2
  import { TrackEventParams, AnalyticsModuleOptions } from "./analytics.types";
3
3
  import type { AuthModule } from "./auth.types";
4
4
  export declare const USER_HEARTBEAT_EVENT_NAME = "__user_heartbeat_event__";
5
- export declare const ANALYTICS_CONFIG_URL_PARAM_KEY = "analytics-disable";
5
+ export declare const ANALYTICS_CONFIG_ENABLE_URL_PARAM_KEY = "analytics-enable";
6
6
  export declare const ANALYTICS_SESSION_ID_LOCAL_STORAGE_KEY = "base44_analytics_session_id";
7
7
  export interface AnalyticsModuleArgs {
8
8
  axiosClient: AxiosInstance;
@@ -1,10 +1,11 @@
1
1
  import { getSharedInstance } from "../utils/sharedInstance";
2
2
  import { generateUuid } from "../utils/common";
3
3
  export const USER_HEARTBEAT_EVENT_NAME = "__user_heartbeat_event__";
4
- export const ANALYTICS_CONFIG_URL_PARAM_KEY = "analytics-disable";
4
+ export const ANALYTICS_CONFIG_ENABLE_URL_PARAM_KEY = "analytics-enable";
5
5
  export const ANALYTICS_SESSION_ID_LOCAL_STORAGE_KEY = "base44_analytics_session_id";
6
6
  const defaultConfiguration = {
7
- enabled: true,
7
+ // default to disabled //
8
+ enabled: false,
8
9
  maxQueueSize: 1000,
9
10
  throttleTime: 1000,
10
11
  batchSize: 30,
@@ -44,9 +45,10 @@ export const createAnalyticsModule = ({ axiosClient, serverUrl, appId, userAuthM
44
45
  data: { events },
45
46
  });
46
47
  };
47
- const beaconRequest = async (events) => {
48
- const beaconPayload = JSON.stringify({ events });
48
+ // currently disabled, until fully tested //
49
+ const beaconRequest = (events) => {
49
50
  try {
51
+ const beaconPayload = JSON.stringify({ events });
50
52
  const blob = new Blob([beaconPayload], { type: "application/json" });
51
53
  return (typeof navigator === "undefined" ||
52
54
  beaconPayload.length > 60000 ||
@@ -56,11 +58,18 @@ export const createAnalyticsModule = ({ axiosClient, serverUrl, appId, userAuthM
56
58
  return false;
57
59
  }
58
60
  };
59
- const flush = async (eventsData) => {
61
+ const flush = async (eventsData, options = {}) => {
62
+ if (eventsData.length === 0)
63
+ return;
60
64
  const sessionContext_ = await getSessionContext(userAuthModule);
61
65
  const events = eventsData.map(transformEventDataToApiRequestData(sessionContext_));
62
- if (!(await beaconRequest(events))) {
63
- return batchRequestFallback(events);
66
+ try {
67
+ if (!options.isBeacon || !beaconRequest(events)) {
68
+ await batchRequestFallback(events);
69
+ }
70
+ }
71
+ catch (_a) {
72
+ // do nothing
64
73
  }
65
74
  };
66
75
  const startProcessing = () => {
@@ -89,10 +98,10 @@ export const createAnalyticsModule = ({ axiosClient, serverUrl, appId, userAuthM
89
98
  };
90
99
  const onDocHidden = () => {
91
100
  stopAnalyticsProcessor();
101
+ clearHeartBeatProcessor === null || clearHeartBeatProcessor === void 0 ? void 0 : clearHeartBeatProcessor();
92
102
  // flush entire queue on visibility change and hope for the best //
93
103
  const eventsData = analyticsSharedState.requestsQueue.splice(0);
94
- flush(eventsData);
95
- clearHeartBeatProcessor === null || clearHeartBeatProcessor === void 0 ? void 0 : clearHeartBeatProcessor();
104
+ flush(eventsData, { isBeacon: true });
96
105
  };
97
106
  const onVisibilityChange = () => {
98
107
  if (typeof window === "undefined")
@@ -196,18 +205,18 @@ export function getAnalyticsConfigFromUrlParams() {
196
205
  if (typeof window === "undefined")
197
206
  return undefined;
198
207
  const urlParams = new URLSearchParams(window.location.search);
199
- const analyticsDisable = urlParams.get(ANALYTICS_CONFIG_URL_PARAM_KEY);
208
+ const analyticsEnable = urlParams.get(ANALYTICS_CONFIG_ENABLE_URL_PARAM_KEY);
200
209
  // if the url param is not set, return undefined //
201
- if (analyticsDisable == null || !analyticsDisable.length)
210
+ if (analyticsEnable == null || !analyticsEnable.length)
202
211
  return undefined;
203
212
  // remove the url param from the url //
204
213
  const newUrlParams = new URLSearchParams(window.location.search);
205
- newUrlParams.delete(ANALYTICS_CONFIG_URL_PARAM_KEY);
214
+ newUrlParams.delete(ANALYTICS_CONFIG_ENABLE_URL_PARAM_KEY);
206
215
  const newUrl = window.location.pathname +
207
216
  (newUrlParams.toString() ? "?" + newUrlParams.toString() : "");
208
217
  window.history.replaceState({}, "", newUrl);
209
218
  // return the config object //
210
- return analyticsDisable === "true" ? { enabled: false } : undefined;
219
+ return { enabled: analyticsEnable === "true" };
211
220
  }
212
221
  export function getAnalyticsSessionId() {
213
222
  if (typeof window === "undefined") {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@base44/sdk",
3
- "version": "0.8.8",
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",