@base44-preview/sdk 0.8.36-pr.219.4b81d03 → 0.8.36-pr.223.4029308
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.
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { getSharedInstance } from "../utils/sharedInstance.js";
|
|
2
|
-
import { generateUuid } from "../utils/common.js";
|
|
2
|
+
import { generateUuid, isReactNative } from "../utils/common.js";
|
|
3
3
|
export const USER_HEARTBEAT_EVENT_NAME = "__user_heartbeat_event__";
|
|
4
4
|
export const ANALYTICS_INITIALIZATION_EVENT_NAME = "__initialization_event__";
|
|
5
5
|
export const ANALYTICS_SESSION_DURATION_EVENT_NAME = "__session_duration_event__";
|
|
@@ -34,7 +34,11 @@ export const createAnalyticsModule = ({ axiosClient, serverUrl, appId, userAuthM
|
|
|
34
34
|
var _a;
|
|
35
35
|
// prevent overflow of events //
|
|
36
36
|
const { maxQueueSize, throttleTime, batchSize } = analyticsSharedState.config;
|
|
37
|
-
|
|
37
|
+
// Disable analytics on React Native. It defines `window` but not `document`,
|
|
38
|
+
// so the per-callsite `typeof window` guards below aren't enough to keep it
|
|
39
|
+
// from touching `document` (e.g. `document.referrer` on init). Node/SSR is
|
|
40
|
+
// still handled by those `window` guards, so this doesn't affect it.
|
|
41
|
+
if (!((_a = analyticsSharedState.config) === null || _a === void 0 ? void 0 : _a.enabled) || isReactNative) {
|
|
38
42
|
return {
|
|
39
43
|
track: () => { },
|
|
40
44
|
cleanup: () => { },
|
|
@@ -242,7 +246,10 @@ async function getSessionContext(userAuthModule) {
|
|
|
242
246
|
return analyticsSharedState.sessionContext;
|
|
243
247
|
}
|
|
244
248
|
export function getAnalyticsConfigFromUrlParams() {
|
|
245
|
-
|
|
249
|
+
// `window.location` is absent on React Native. This runs at module load (via
|
|
250
|
+
// the shared-state factory), so an unguarded `window.location.search` would
|
|
251
|
+
// throw on import there.
|
|
252
|
+
if (typeof window === "undefined" || !window.location)
|
|
246
253
|
return undefined;
|
|
247
254
|
const urlParams = new URLSearchParams(window.location.search);
|
|
248
255
|
const analyticsEnable = urlParams.get(ANALYTICS_CONFIG_ENABLE_URL_PARAM_KEY);
|
|
@@ -130,7 +130,9 @@ export function createAxiosClient({ baseURL, headers = {}, token, interceptRespo
|
|
|
130
130
|
}
|
|
131
131
|
// Add origin URL in browser environment
|
|
132
132
|
client.interceptors.request.use((config) => {
|
|
133
|
-
|
|
133
|
+
// `window.location` is absent on React Native (where `window` still exists),
|
|
134
|
+
// so guard on it before reading `.href`.
|
|
135
|
+
if (typeof window !== "undefined" && window.location) {
|
|
134
136
|
config.headers.set("X-Origin-URL", window.location.href);
|
|
135
137
|
// On unauthenticated requests, attach a stable anonymous visitor id so the
|
|
136
138
|
// backend can support anonymous agent access (conversation grouping + ownership).
|
package/dist/utils/common.d.ts
CHANGED
package/dist/utils/common.js
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
export const isNode = typeof window === "undefined";
|
|
2
2
|
export const isInIFrame = !isNode && window.self !== window.top;
|
|
3
|
+
// React Native defines `window` (so `isNode` is false there) but not `document`.
|
|
4
|
+
// Browser-only code paths gated on `window`/`isNode` alone would run — and crash —
|
|
5
|
+
// on React Native. Node (no `window`) is already handled by those `window` guards;
|
|
6
|
+
// this flags the window-without-a-DOM case that isn't.
|
|
7
|
+
export const isReactNative = !isNode && typeof document === "undefined";
|
|
3
8
|
export const generateUuid = () => {
|
|
4
9
|
return (Math.random().toString(36).substring(2, 15) +
|
|
5
10
|
Math.random().toString(36).substring(2, 15));
|