@base44/sdk 0.8.12 → 0.8.14
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 +10 -2
- package/dist/index.d.ts +1 -1
- package/dist/modules/analytics.d.ts +2 -0
- package/dist/modules/analytics.js +40 -0
- package/dist/modules/entities.d.ts +12 -3
- package/dist/modules/entities.js +47 -5
- package/dist/modules/entities.types.d.ts +45 -0
- package/package.json +4 -4
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
|
@@ -104,7 +104,11 @@ export function createClient(config) {
|
|
|
104
104
|
serverUrl,
|
|
105
105
|
});
|
|
106
106
|
const userModules = {
|
|
107
|
-
entities: createEntitiesModule(
|
|
107
|
+
entities: createEntitiesModule({
|
|
108
|
+
axios: axiosClient,
|
|
109
|
+
appId,
|
|
110
|
+
getSocket,
|
|
111
|
+
}),
|
|
108
112
|
integrations: createIntegrationsModule(axiosClient, appId),
|
|
109
113
|
auth: userAuthModule,
|
|
110
114
|
functions: createFunctionsModule(functionsAxiosClient, appId),
|
|
@@ -131,7 +135,11 @@ export function createClient(config) {
|
|
|
131
135
|
},
|
|
132
136
|
};
|
|
133
137
|
const serviceRoleModules = {
|
|
134
|
-
entities: createEntitiesModule(
|
|
138
|
+
entities: createEntitiesModule({
|
|
139
|
+
axios: serviceRoleAxiosClient,
|
|
140
|
+
appId,
|
|
141
|
+
getSocket,
|
|
142
|
+
}),
|
|
135
143
|
integrations: createIntegrationsModule(serviceRoleAxiosClient, appId),
|
|
136
144
|
sso: createSsoModule(serviceRoleAxiosClient, appId, token),
|
|
137
145
|
connectors: createConnectorsModule(serviceRoleAxiosClient, appId),
|
package/dist/index.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { getAccessToken, saveAccessToken, removeAccessToken, getLoginUrl } from
|
|
|
4
4
|
export { createClient, createClientFromRequest, Base44Error, getAccessToken, saveAccessToken, removeAccessToken, getLoginUrl, };
|
|
5
5
|
export type { Base44Client, CreateClientConfig, CreateClientOptions, Base44ErrorJSON, };
|
|
6
6
|
export * from "./types.js";
|
|
7
|
-
export type { EntitiesModule, EntityHandler, } from "./modules/entities.types.js";
|
|
7
|
+
export type { EntitiesModule, EntityHandler, RealtimeEventType, RealtimeEvent, RealtimeCallback, Subscription, } from "./modules/entities.types.js";
|
|
8
8
|
export type { AuthModule, LoginResponse, RegisterParams, VerifyOtpParams, ChangePasswordParams, ResetPasswordParams, User, } from "./modules/auth.types.js";
|
|
9
9
|
export type { IntegrationsModule, IntegrationPackage, IntegrationEndpointFunction, CoreIntegrations, InvokeLLMParams, GenerateImageParams, GenerateImageResult, UploadFileParams, UploadFileResult, SendEmailParams, SendEmailResult, ExtractDataFromUploadedFileParams, ExtractDataFromUploadedFileResult, UploadPrivateFileParams, UploadPrivateFileResult, CreateFileSignedUrlParams, CreateFileSignedUrlResult, } from "./modules/integrations.types.js";
|
|
10
10
|
export type { FunctionsModule } from "./modules/functions.types.js";
|
|
@@ -2,6 +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 ANALYTICS_INITIALIZATION_EVENT_NAME = "__initialization_event__";
|
|
6
|
+
export declare const ANALYTICS_SESSION_DURATION_EVENT_NAME = "__session_duration_event__";
|
|
5
7
|
export declare const ANALYTICS_CONFIG_ENABLE_URL_PARAM_KEY = "analytics-enable";
|
|
6
8
|
export declare const ANALYTICS_SESSION_ID_LOCAL_STORAGE_KEY = "base44_analytics_session_id";
|
|
7
9
|
export interface AnalyticsModuleArgs {
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { getSharedInstance } from "../utils/sharedInstance.js";
|
|
2
2
|
import { generateUuid } from "../utils/common.js";
|
|
3
3
|
export const USER_HEARTBEAT_EVENT_NAME = "__user_heartbeat_event__";
|
|
4
|
+
export const ANALYTICS_INITIALIZATION_EVENT_NAME = "__initialization_event__";
|
|
5
|
+
export const ANALYTICS_SESSION_DURATION_EVENT_NAME = "__session_duration_event__";
|
|
4
6
|
export const ANALYTICS_CONFIG_ENABLE_URL_PARAM_KEY = "analytics-enable";
|
|
5
7
|
export const ANALYTICS_SESSION_ID_LOCAL_STORAGE_KEY = "base44_analytics_session_id";
|
|
6
8
|
const defaultConfiguration = {
|
|
@@ -20,7 +22,9 @@ const analyticsSharedState = getSharedInstance(ANALYTICS_SHARED_STATE_NAME, () =
|
|
|
20
22
|
requestsQueue: [],
|
|
21
23
|
isProcessing: false,
|
|
22
24
|
isHeartBeatProcessing: false,
|
|
25
|
+
wasInitializationTracked: false,
|
|
23
26
|
sessionContext: null,
|
|
27
|
+
sessionStartTime: null,
|
|
24
28
|
config: {
|
|
25
29
|
...defaultConfiguration,
|
|
26
30
|
...getAnalyticsConfigFromUrlParams(),
|
|
@@ -95,10 +99,12 @@ export const createAnalyticsModule = ({ axiosClient, serverUrl, appId, userAuthM
|
|
|
95
99
|
batchSize,
|
|
96
100
|
});
|
|
97
101
|
clearHeartBeatProcessor = startHeartBeatProcessor(track);
|
|
102
|
+
setSessionDurationTimerStart();
|
|
98
103
|
};
|
|
99
104
|
const onDocHidden = () => {
|
|
100
105
|
stopAnalyticsProcessor();
|
|
101
106
|
clearHeartBeatProcessor === null || clearHeartBeatProcessor === void 0 ? void 0 : clearHeartBeatProcessor();
|
|
107
|
+
trackSessionDurationEvent(track);
|
|
102
108
|
// flush entire queue on visibility change and hope for the best //
|
|
103
109
|
const eventsData = analyticsSharedState.requestsQueue.splice(0);
|
|
104
110
|
flush(eventsData, { isBeacon: true });
|
|
@@ -124,6 +130,8 @@ export const createAnalyticsModule = ({ axiosClient, serverUrl, appId, userAuthM
|
|
|
124
130
|
startProcessing();
|
|
125
131
|
// start the heart beat processor //
|
|
126
132
|
clearHeartBeatProcessor = startHeartBeatProcessor(track);
|
|
133
|
+
// track the referrer event //
|
|
134
|
+
trackInitializationEvent(track);
|
|
127
135
|
// start the visibility change listener //
|
|
128
136
|
if (typeof window !== "undefined") {
|
|
129
137
|
window.addEventListener("visibilitychange", onVisibilityChange);
|
|
@@ -166,6 +174,38 @@ function startHeartBeatProcessor(track) {
|
|
|
166
174
|
analyticsSharedState.isHeartBeatProcessing = false;
|
|
167
175
|
};
|
|
168
176
|
}
|
|
177
|
+
function trackInitializationEvent(track) {
|
|
178
|
+
if (typeof window === "undefined" ||
|
|
179
|
+
analyticsSharedState.wasInitializationTracked) {
|
|
180
|
+
return;
|
|
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) {
|
|
193
|
+
return;
|
|
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
|
+
});
|
|
208
|
+
}
|
|
169
209
|
function getEventIntrinsicData() {
|
|
170
210
|
return {
|
|
171
211
|
timestamp: new Date().toISOString(),
|
|
@@ -1,11 +1,20 @@
|
|
|
1
1
|
import { AxiosInstance } from "axios";
|
|
2
2
|
import { EntitiesModule } from "./entities.types";
|
|
3
|
+
import { RoomsSocket } from "../utils/socket-utils.js";
|
|
4
|
+
/**
|
|
5
|
+
* Configuration for the entities module.
|
|
6
|
+
* @internal
|
|
7
|
+
*/
|
|
8
|
+
export interface EntitiesModuleConfig {
|
|
9
|
+
axios: AxiosInstance;
|
|
10
|
+
appId: string;
|
|
11
|
+
getSocket: () => ReturnType<typeof RoomsSocket>;
|
|
12
|
+
}
|
|
3
13
|
/**
|
|
4
14
|
* Creates the entities module for the Base44 SDK.
|
|
5
15
|
*
|
|
6
|
-
* @param
|
|
7
|
-
* @param appId - Application ID
|
|
16
|
+
* @param config - Configuration object containing axios, appId, and getSocket
|
|
8
17
|
* @returns Entities module with dynamic entity access
|
|
9
18
|
* @internal
|
|
10
19
|
*/
|
|
11
|
-
export declare function createEntitiesModule(
|
|
20
|
+
export declare function createEntitiesModule(config: EntitiesModuleConfig): EntitiesModule;
|
package/dist/modules/entities.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Creates the entities module for the Base44 SDK.
|
|
3
3
|
*
|
|
4
|
-
* @param
|
|
5
|
-
* @param appId - Application ID
|
|
4
|
+
* @param config - Configuration object containing axios, appId, and getSocket
|
|
6
5
|
* @returns Entities module with dynamic entity access
|
|
7
6
|
* @internal
|
|
8
7
|
*/
|
|
9
|
-
export function createEntitiesModule(
|
|
8
|
+
export function createEntitiesModule(config) {
|
|
9
|
+
const { axios, appId, getSocket } = config;
|
|
10
10
|
// Using Proxy to dynamically handle entity names
|
|
11
11
|
return new Proxy({}, {
|
|
12
12
|
get(target, entityName) {
|
|
@@ -17,20 +17,41 @@ export function createEntitiesModule(axios, appId) {
|
|
|
17
17
|
return undefined;
|
|
18
18
|
}
|
|
19
19
|
// Create entity handler
|
|
20
|
-
return createEntityHandler(axios, appId, entityName);
|
|
20
|
+
return createEntityHandler(axios, appId, entityName, getSocket);
|
|
21
21
|
},
|
|
22
22
|
});
|
|
23
23
|
}
|
|
24
|
+
/**
|
|
25
|
+
* Parses the realtime message data and extracts event information.
|
|
26
|
+
* @internal
|
|
27
|
+
*/
|
|
28
|
+
function parseRealtimeMessage(dataStr) {
|
|
29
|
+
var _a;
|
|
30
|
+
try {
|
|
31
|
+
const parsed = JSON.parse(dataStr);
|
|
32
|
+
return {
|
|
33
|
+
type: parsed.type,
|
|
34
|
+
data: parsed.data,
|
|
35
|
+
id: parsed.id || ((_a = parsed.data) === null || _a === void 0 ? void 0 : _a.id),
|
|
36
|
+
timestamp: parsed.timestamp || new Date().toISOString(),
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
catch (error) {
|
|
40
|
+
console.warn("[Base44 SDK] Failed to parse realtime message:", error);
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
24
44
|
/**
|
|
25
45
|
* Creates a handler for a specific entity.
|
|
26
46
|
*
|
|
27
47
|
* @param axios - Axios instance
|
|
28
48
|
* @param appId - Application ID
|
|
29
49
|
* @param entityName - Entity name
|
|
50
|
+
* @param getSocket - Function to get the socket instance
|
|
30
51
|
* @returns Entity handler with CRUD methods
|
|
31
52
|
* @internal
|
|
32
53
|
*/
|
|
33
|
-
function createEntityHandler(axios, appId, entityName) {
|
|
54
|
+
function createEntityHandler(axios, appId, entityName, getSocket) {
|
|
34
55
|
const baseURL = `/apps/${appId}/entities/${entityName}`;
|
|
35
56
|
return {
|
|
36
57
|
// List entities with optional pagination and sorting
|
|
@@ -95,5 +116,26 @@ function createEntityHandler(axios, appId, entityName) {
|
|
|
95
116
|
},
|
|
96
117
|
});
|
|
97
118
|
},
|
|
119
|
+
// Subscribe to realtime updates
|
|
120
|
+
subscribe(callback) {
|
|
121
|
+
const room = `entities:${appId}:${entityName}`;
|
|
122
|
+
// Get the socket and subscribe to the room
|
|
123
|
+
const socket = getSocket();
|
|
124
|
+
const unsubscribe = socket.subscribeToRoom(room, {
|
|
125
|
+
update_model: (msg) => {
|
|
126
|
+
const event = parseRealtimeMessage(msg.data);
|
|
127
|
+
if (!event) {
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
try {
|
|
131
|
+
callback(event);
|
|
132
|
+
}
|
|
133
|
+
catch (error) {
|
|
134
|
+
console.error("[Base44 SDK] Subscription callback error:", error);
|
|
135
|
+
}
|
|
136
|
+
},
|
|
137
|
+
});
|
|
138
|
+
return unsubscribe;
|
|
139
|
+
},
|
|
98
140
|
};
|
|
99
141
|
}
|
|
@@ -1,3 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Event types for realtime entity updates.
|
|
3
|
+
*/
|
|
4
|
+
export type RealtimeEventType = "create" | "update" | "delete";
|
|
5
|
+
/**
|
|
6
|
+
* Payload received when a realtime event occurs.
|
|
7
|
+
*/
|
|
8
|
+
export interface RealtimeEvent {
|
|
9
|
+
/** The type of change that occurred */
|
|
10
|
+
type: RealtimeEventType;
|
|
11
|
+
/** The entity data */
|
|
12
|
+
data: any;
|
|
13
|
+
/** The unique identifier of the affected entity */
|
|
14
|
+
id: string;
|
|
15
|
+
/** ISO 8601 timestamp of when the event occurred */
|
|
16
|
+
timestamp: string;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Callback function invoked when a realtime event occurs.
|
|
20
|
+
*/
|
|
21
|
+
export type RealtimeCallback = (event: RealtimeEvent) => void;
|
|
22
|
+
/**
|
|
23
|
+
* Function returned from subscribe, call it to unsubscribe.
|
|
24
|
+
*/
|
|
25
|
+
export type Subscription = () => void;
|
|
1
26
|
/**
|
|
2
27
|
* Entity handler providing CRUD operations for a specific entity type.
|
|
3
28
|
*
|
|
@@ -242,6 +267,26 @@ export interface EntityHandler {
|
|
|
242
267
|
* ```
|
|
243
268
|
*/
|
|
244
269
|
importEntities(file: File): Promise<any>;
|
|
270
|
+
/**
|
|
271
|
+
* Subscribes to realtime updates for all records of this entity type.
|
|
272
|
+
*
|
|
273
|
+
* Receives notifications whenever any record is created, updated, or deleted.
|
|
274
|
+
*
|
|
275
|
+
* @param callback - Function called when an entity changes.
|
|
276
|
+
* @returns Unsubscribe function to stop listening.
|
|
277
|
+
*
|
|
278
|
+
* @example
|
|
279
|
+
* ```typescript
|
|
280
|
+
* // Subscribe to all Task changes
|
|
281
|
+
* const unsubscribe = base44.entities.Task.subscribe((event) => {
|
|
282
|
+
* console.log(`Task ${event.id} was ${event.type}d:`, event.data);
|
|
283
|
+
* });
|
|
284
|
+
*
|
|
285
|
+
* // Later, unsubscribe
|
|
286
|
+
* unsubscribe();
|
|
287
|
+
* ```
|
|
288
|
+
*/
|
|
289
|
+
subscribe(callback: RealtimeCallback): Subscription;
|
|
245
290
|
}
|
|
246
291
|
/**
|
|
247
292
|
* Entities module for managing app data.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@base44/sdk",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.14",
|
|
4
4
|
"description": "JavaScript SDK for Base44 API",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -55,10 +55,10 @@
|
|
|
55
55
|
"license": "MIT",
|
|
56
56
|
"repository": {
|
|
57
57
|
"type": "git",
|
|
58
|
-
"url": "git+https://github.com/base44/sdk.git"
|
|
58
|
+
"url": "git+https://github.com/base44/javascript-sdk.git"
|
|
59
59
|
},
|
|
60
60
|
"bugs": {
|
|
61
|
-
"url": "https://github.com/base44/sdk/issues"
|
|
61
|
+
"url": "https://github.com/base44/javascript-sdk/issues"
|
|
62
62
|
},
|
|
63
|
-
"homepage": "https://github.com/base44/sdk#readme"
|
|
63
|
+
"homepage": "https://github.com/base44/javascript-sdk#readme"
|
|
64
64
|
}
|