@base44/sdk 0.8.7 → 0.8.8

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_WINDOW_KEY = "base44_analytics_config";
5
+ export declare const ANALYTICS_CONFIG_URL_PARAM_KEY = "analytics-disable";
6
6
  export declare const ANALYTICS_SESSION_ID_LOCAL_STORAGE_KEY = "base44_analytics_session_id";
7
7
  export interface AnalyticsModuleArgs {
8
8
  axiosClient: AxiosInstance;
@@ -14,5 +14,5 @@ export declare const createAnalyticsModule: ({ axiosClient, serverUrl, appId, us
14
14
  track: (params: TrackEventParams) => void;
15
15
  cleanup: () => void;
16
16
  };
17
- export declare function getAnalyticsModuleOptionsFromWindow(): AnalyticsModuleOptions | undefined;
17
+ export declare function getAnalyticsConfigFromUrlParams(): AnalyticsModuleOptions | undefined;
18
18
  export declare function getAnalyticsSessionId(): string;
@@ -1,7 +1,7 @@
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_WINDOW_KEY = "base44_analytics_config";
4
+ export const ANALYTICS_CONFIG_URL_PARAM_KEY = "analytics-disable";
5
5
  export const ANALYTICS_SESSION_ID_LOCAL_STORAGE_KEY = "base44_analytics_session_id";
6
6
  const defaultConfiguration = {
7
7
  enabled: true,
@@ -22,7 +22,7 @@ const analyticsSharedState = getSharedInstance(ANALYTICS_SHARED_STATE_NAME, () =
22
22
  sessionContext: null,
23
23
  config: {
24
24
  ...defaultConfiguration,
25
- ...getAnalyticsModuleOptionsFromWindow(),
25
+ ...getAnalyticsConfigFromUrlParams(),
26
26
  },
27
27
  }));
28
28
  export const createAnalyticsModule = ({ axiosClient, serverUrl, appId, userAuthModule, }) => {
@@ -44,20 +44,23 @@ export const createAnalyticsModule = ({ axiosClient, serverUrl, appId, userAuthM
44
44
  data: { events },
45
45
  });
46
46
  };
47
- const flush = async (eventsData) => {
48
- const sessionContext_ = await getSessionContext(userAuthModule);
49
- const events = eventsData.map(transformEventDataToApiRequestData(sessionContext_));
47
+ const beaconRequest = async (events) => {
50
48
  const beaconPayload = JSON.stringify({ events });
51
49
  try {
52
- if (typeof navigator === "undefined" ||
50
+ const blob = new Blob([beaconPayload], { type: "application/json" });
51
+ return (typeof navigator === "undefined" ||
53
52
  beaconPayload.length > 60000 ||
54
- !navigator.sendBeacon(trackBatchUrl, beaconPayload)) {
55
- // beacon didn't work, fallback to axios
56
- await batchRequestFallback(events);
57
- }
53
+ !navigator.sendBeacon(trackBatchUrl, blob));
58
54
  }
59
55
  catch (_a) {
60
- // TODO: think about retries if needed
56
+ return false;
57
+ }
58
+ };
59
+ const flush = async (eventsData) => {
60
+ const sessionContext_ = await getSessionContext(userAuthModule);
61
+ const events = eventsData.map(transformEventDataToApiRequestData(sessionContext_));
62
+ if (!(await beaconRequest(events))) {
63
+ return batchRequestFallback(events);
61
64
  }
62
65
  };
63
66
  const startProcessing = () => {
@@ -189,10 +192,22 @@ async function getSessionContext(userAuthModule) {
189
192
  }
190
193
  return analyticsSharedState.sessionContext;
191
194
  }
192
- export function getAnalyticsModuleOptionsFromWindow() {
195
+ export function getAnalyticsConfigFromUrlParams() {
193
196
  if (typeof window === "undefined")
194
197
  return undefined;
195
- return window[ANALYTICS_CONFIG_WINDOW_KEY];
198
+ const urlParams = new URLSearchParams(window.location.search);
199
+ const analyticsDisable = urlParams.get(ANALYTICS_CONFIG_URL_PARAM_KEY);
200
+ // if the url param is not set, return undefined //
201
+ if (analyticsDisable == null || !analyticsDisable.length)
202
+ return undefined;
203
+ // remove the url param from the url //
204
+ const newUrlParams = new URLSearchParams(window.location.search);
205
+ newUrlParams.delete(ANALYTICS_CONFIG_URL_PARAM_KEY);
206
+ const newUrl = window.location.pathname +
207
+ (newUrlParams.toString() ? "?" + newUrlParams.toString() : "");
208
+ window.history.replaceState({}, "", newUrl);
209
+ // return the config object //
210
+ return analyticsDisable === "true" ? { enabled: false } : undefined;
196
211
  }
197
212
  export function getAnalyticsSessionId() {
198
213
  if (typeof window === "undefined") {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@base44/sdk",
3
- "version": "0.8.7",
3
+ "version": "0.8.8",
4
4
  "description": "JavaScript SDK for Base44 API",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",