@base44-preview/sdk 0.8.11-pr.65.dc85e14 → 0.8.12-pr.63.2ce5b64
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/LICENSE +21 -0
- package/dist/client.js +8 -1
- package/dist/client.types.d.ts +5 -0
- package/dist/modules/agents.types.d.ts +2 -2
- package/dist/modules/analytics.d.ts +2 -1
- package/dist/modules/analytics.js +38 -11
- package/package.json +8 -6
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 base44
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/dist/client.js
CHANGED
|
@@ -47,7 +47,11 @@ import { createAnalyticsModule } from "./modules/analytics.js";
|
|
|
47
47
|
* ```
|
|
48
48
|
*/
|
|
49
49
|
export function createClient(config) {
|
|
50
|
-
|
|
50
|
+
// Auto-detect staging mode from URL if in browser and not explicitly set
|
|
51
|
+
const autoDetectStagingDb = typeof window !== "undefined"
|
|
52
|
+
? new URLSearchParams(window.location.search).get("use_staging_db") === "true"
|
|
53
|
+
: false;
|
|
54
|
+
const { serverUrl = "https://base44.app", appId, token, serviceToken, requiresAuth = false, appBaseUrl, options, functionsVersion, headers: optionalHeaders, useStagingDb = autoDetectStagingDb, } = config;
|
|
51
55
|
const socketConfig = {
|
|
52
56
|
serverUrl,
|
|
53
57
|
mountPath: "/ws-user-apps/socket.io/",
|
|
@@ -67,6 +71,7 @@ export function createClient(config) {
|
|
|
67
71
|
const headers = {
|
|
68
72
|
...optionalHeaders,
|
|
69
73
|
"X-App-Id": String(appId),
|
|
74
|
+
"Base44-Use-Staging-DB": String(useStagingDb),
|
|
70
75
|
};
|
|
71
76
|
const functionHeaders = functionsVersion
|
|
72
77
|
? {
|
|
@@ -299,6 +304,7 @@ export function createClientFromRequest(request) {
|
|
|
299
304
|
const appId = request.headers.get("Base44-App-Id");
|
|
300
305
|
const serverUrlHeader = request.headers.get("Base44-Api-Url");
|
|
301
306
|
const functionsVersion = request.headers.get("Base44-Functions-Version");
|
|
307
|
+
const useStagingDb = request.headers.get("Base44-Use-Staging-DB") === "true";
|
|
302
308
|
const stateHeader = request.headers.get("Base44-State");
|
|
303
309
|
if (!appId) {
|
|
304
310
|
throw new Error("Base44-App-Id header is required, but is was not found on the request");
|
|
@@ -333,6 +339,7 @@ export function createClientFromRequest(request) {
|
|
|
333
339
|
token: userToken,
|
|
334
340
|
serviceToken: serviceRoleToken,
|
|
335
341
|
functionsVersion: functionsVersion !== null && functionsVersion !== void 0 ? functionsVersion : undefined,
|
|
342
|
+
useStagingDb: useStagingDb !== null && useStagingDb !== void 0 ? useStagingDb : undefined,
|
|
336
343
|
headers: additionalHeaders,
|
|
337
344
|
});
|
|
338
345
|
}
|
package/dist/client.types.d.ts
CHANGED
|
@@ -60,6 +60,11 @@ export interface CreateClientConfig {
|
|
|
60
60
|
* @internal
|
|
61
61
|
*/
|
|
62
62
|
headers?: Record<string, string>;
|
|
63
|
+
/**
|
|
64
|
+
* Whether to use the staging database. Defaults to false.
|
|
65
|
+
* When true, API requests will use the staging database instead of production.
|
|
66
|
+
*/
|
|
67
|
+
useStagingDb?: boolean;
|
|
63
68
|
/**
|
|
64
69
|
* Additional client options.
|
|
65
70
|
*/
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { AxiosInstance } from "axios";
|
|
2
|
-
import { RoomsSocket } from "../utils/socket-utils";
|
|
3
|
-
import { ModelFilterParams } from "../types";
|
|
2
|
+
import { RoomsSocket } from "../utils/socket-utils.js";
|
|
3
|
+
import { ModelFilterParams } from "../types.js";
|
|
4
4
|
/**
|
|
5
5
|
* Reasoning information for an agent message.
|
|
6
6
|
*
|
|
@@ -2,7 +2,8 @@ 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
|
|
5
|
+
export declare const ANALYTICS_INITIALIZATION_EVENT_NAME = "__initialization_event__";
|
|
6
|
+
export declare const ANALYTICS_SESSION_DURATION_EVENT_NAME = "__session_duration_event__";
|
|
6
7
|
export declare const ANALYTICS_CONFIG_ENABLE_URL_PARAM_KEY = "analytics-enable";
|
|
7
8
|
export declare const ANALYTICS_SESSION_ID_LOCAL_STORAGE_KEY = "base44_analytics_session_id";
|
|
8
9
|
export interface AnalyticsModuleArgs {
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { getSharedInstance } from "../utils/sharedInstance";
|
|
2
|
-
import { generateUuid } from "../utils/common";
|
|
1
|
+
import { getSharedInstance } from "../utils/sharedInstance.js";
|
|
2
|
+
import { generateUuid } from "../utils/common.js";
|
|
3
3
|
export const USER_HEARTBEAT_EVENT_NAME = "__user_heartbeat_event__";
|
|
4
|
-
export const
|
|
4
|
+
export const ANALYTICS_INITIALIZATION_EVENT_NAME = "__initialization_event__";
|
|
5
|
+
export const ANALYTICS_SESSION_DURATION_EVENT_NAME = "__session_duration_event__";
|
|
5
6
|
export const ANALYTICS_CONFIG_ENABLE_URL_PARAM_KEY = "analytics-enable";
|
|
6
7
|
export const ANALYTICS_SESSION_ID_LOCAL_STORAGE_KEY = "base44_analytics_session_id";
|
|
7
8
|
const defaultConfiguration = {
|
|
@@ -21,8 +22,9 @@ const analyticsSharedState = getSharedInstance(ANALYTICS_SHARED_STATE_NAME, () =
|
|
|
21
22
|
requestsQueue: [],
|
|
22
23
|
isProcessing: false,
|
|
23
24
|
isHeartBeatProcessing: false,
|
|
24
|
-
|
|
25
|
+
wasInitializationTracked: false,
|
|
25
26
|
sessionContext: null,
|
|
27
|
+
sessionStartTime: null,
|
|
26
28
|
config: {
|
|
27
29
|
...defaultConfiguration,
|
|
28
30
|
...getAnalyticsConfigFromUrlParams(),
|
|
@@ -97,10 +99,12 @@ export const createAnalyticsModule = ({ axiosClient, serverUrl, appId, userAuthM
|
|
|
97
99
|
batchSize,
|
|
98
100
|
});
|
|
99
101
|
clearHeartBeatProcessor = startHeartBeatProcessor(track);
|
|
102
|
+
setSessionDurationTimerStart();
|
|
100
103
|
};
|
|
101
104
|
const onDocHidden = () => {
|
|
102
105
|
stopAnalyticsProcessor();
|
|
103
106
|
clearHeartBeatProcessor === null || clearHeartBeatProcessor === void 0 ? void 0 : clearHeartBeatProcessor();
|
|
107
|
+
trackSessionDurationEvent(track);
|
|
104
108
|
// flush entire queue on visibility change and hope for the best //
|
|
105
109
|
const eventsData = analyticsSharedState.requestsQueue.splice(0);
|
|
106
110
|
flush(eventsData, { isBeacon: true });
|
|
@@ -127,7 +131,7 @@ export const createAnalyticsModule = ({ axiosClient, serverUrl, appId, userAuthM
|
|
|
127
131
|
// start the heart beat processor //
|
|
128
132
|
clearHeartBeatProcessor = startHeartBeatProcessor(track);
|
|
129
133
|
// track the referrer event //
|
|
130
|
-
|
|
134
|
+
trackInitializationEvent(track);
|
|
131
135
|
// start the visibility change listener //
|
|
132
136
|
if (typeof window !== "undefined") {
|
|
133
137
|
window.addEventListener("visibilitychange", onVisibilityChange);
|
|
@@ -170,14 +174,37 @@ function startHeartBeatProcessor(track) {
|
|
|
170
174
|
analyticsSharedState.isHeartBeatProcessing = false;
|
|
171
175
|
};
|
|
172
176
|
}
|
|
173
|
-
function
|
|
174
|
-
if (typeof window === "undefined" ||
|
|
177
|
+
function trackInitializationEvent(track) {
|
|
178
|
+
if (typeof window === "undefined" ||
|
|
179
|
+
analyticsSharedState.wasInitializationTracked) {
|
|
175
180
|
return;
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
181
|
+
}
|
|
182
|
+
analyticsSharedState.wasInitializationTracked = true;
|
|
183
|
+
track({
|
|
184
|
+
eventName: ANALYTICS_INITIALIZATION_EVENT_NAME,
|
|
185
|
+
properties: {
|
|
186
|
+
referrer: document === null || document === void 0 ? void 0 : document.referrer,
|
|
187
|
+
},
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
function setSessionDurationTimerStart() {
|
|
191
|
+
if (typeof window === "undefined" ||
|
|
192
|
+
analyticsSharedState.sessionStartTime !== null) {
|
|
179
193
|
return;
|
|
180
|
-
|
|
194
|
+
}
|
|
195
|
+
analyticsSharedState.sessionStartTime = new Date().toISOString();
|
|
196
|
+
}
|
|
197
|
+
function trackSessionDurationEvent(track) {
|
|
198
|
+
if (typeof window === "undefined" ||
|
|
199
|
+
analyticsSharedState.sessionStartTime === null)
|
|
200
|
+
return;
|
|
201
|
+
const sessionDuration = new Date().getTime() -
|
|
202
|
+
new Date(analyticsSharedState.sessionStartTime).getTime();
|
|
203
|
+
analyticsSharedState.sessionStartTime = null;
|
|
204
|
+
track({
|
|
205
|
+
eventName: ANALYTICS_SESSION_DURATION_EVENT_NAME,
|
|
206
|
+
properties: { sessionDuration },
|
|
207
|
+
});
|
|
181
208
|
}
|
|
182
209
|
function getEventIntrinsicData() {
|
|
183
210
|
return {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@base44-preview/sdk",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.12-pr.63.2ce5b64",
|
|
4
4
|
"description": "JavaScript SDK for Base44 API",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -32,15 +32,18 @@
|
|
|
32
32
|
"@types/hast": "^3.0.4",
|
|
33
33
|
"@types/node": "^25.0.1",
|
|
34
34
|
"@types/unist": "^3.0.3",
|
|
35
|
+
"@typescript-eslint/parser": "^8.51.0",
|
|
35
36
|
"@vitest/coverage-istanbul": "^1.0.0",
|
|
36
37
|
"@vitest/coverage-v8": "^1.0.0",
|
|
37
38
|
"@vitest/ui": "^1.0.0",
|
|
38
39
|
"dotenv": "^16.3.1",
|
|
39
|
-
"eslint": "^
|
|
40
|
+
"eslint": "^9.39.2",
|
|
41
|
+
"eslint-plugin-import": "^2.32.0",
|
|
40
42
|
"nock": "^13.4.0",
|
|
41
43
|
"typedoc": "^0.28.14",
|
|
42
44
|
"typedoc-plugin-markdown": "^4.9.0",
|
|
43
45
|
"typescript": "^5.3.2",
|
|
46
|
+
"typescript-eslint": "^8.51.0",
|
|
44
47
|
"vitest": "^1.6.1"
|
|
45
48
|
},
|
|
46
49
|
"keywords": [
|
|
@@ -52,11 +55,10 @@
|
|
|
52
55
|
"license": "MIT",
|
|
53
56
|
"repository": {
|
|
54
57
|
"type": "git",
|
|
55
|
-
"url": "git+https://github.com/base44/sdk.git"
|
|
58
|
+
"url": "git+https://github.com/base44/javascript-sdk.git"
|
|
56
59
|
},
|
|
57
60
|
"bugs": {
|
|
58
|
-
"url": "https://github.com/base44/sdk/issues"
|
|
61
|
+
"url": "https://github.com/base44/javascript-sdk/issues"
|
|
59
62
|
},
|
|
60
|
-
"homepage": "https://github.com/base44/sdk#readme"
|
|
61
|
-
"packageManager": "yarn@1.22.22+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e"
|
|
63
|
+
"homepage": "https://github.com/base44/javascript-sdk#readme"
|
|
62
64
|
}
|