@base44-preview/sdk 0.8.6-pr.57.d5771ed → 0.8.6-pr.58.9363801
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/dist/client.js +10 -8
- package/dist/client.types.d.ts +0 -2
- package/dist/index.d.ts +1 -1
- package/dist/modules/entities.d.ts +19 -0
- package/dist/modules/entities.js +100 -11
- package/dist/modules/entities.types.d.ts +124 -0
- package/dist/modules/types.d.ts +0 -1
- package/dist/modules/types.js +0 -1
- package/package.json +1 -1
- package/dist/modules/analytics.d.ts +0 -10
- package/dist/modules/analytics.js +0 -68
- package/dist/modules/analytics.types.d.ts +0 -35
- package/dist/modules/analytics.types.js +0 -1
- package/dist/utils/singleton.d.ts +0 -2
- package/dist/utils/singleton.js +0 -16
package/dist/client.js
CHANGED
|
@@ -10,7 +10,6 @@ import { createAgentsModule } from "./modules/agents.js";
|
|
|
10
10
|
import { createAppLogsModule } from "./modules/app-logs.js";
|
|
11
11
|
import { createUsersModule } from "./modules/users.js";
|
|
12
12
|
import { RoomsSocket } from "./utils/socket-utils.js";
|
|
13
|
-
import { createAnalyticsModule } from "./modules/analytics.js";
|
|
14
13
|
/**
|
|
15
14
|
* Creates a Base44 client.
|
|
16
15
|
*
|
|
@@ -100,7 +99,11 @@ export function createClient(config) {
|
|
|
100
99
|
interceptResponses: false,
|
|
101
100
|
});
|
|
102
101
|
const userModules = {
|
|
103
|
-
entities: createEntitiesModule(
|
|
102
|
+
entities: createEntitiesModule({
|
|
103
|
+
axios: axiosClient,
|
|
104
|
+
appId,
|
|
105
|
+
getSocket,
|
|
106
|
+
}),
|
|
104
107
|
integrations: createIntegrationsModule(axiosClient, appId),
|
|
105
108
|
auth: createAuthModule(axiosClient, functionsAxiosClient, appId, {
|
|
106
109
|
appBaseUrl,
|
|
@@ -116,11 +119,6 @@ export function createClient(config) {
|
|
|
116
119
|
}),
|
|
117
120
|
appLogs: createAppLogsModule(axiosClient, appId),
|
|
118
121
|
users: createUsersModule(axiosClient, appId),
|
|
119
|
-
analytics: createAnalyticsModule({
|
|
120
|
-
axiosClient,
|
|
121
|
-
appId,
|
|
122
|
-
options: options === null || options === void 0 ? void 0 : options.analytics,
|
|
123
|
-
}),
|
|
124
122
|
cleanup: () => {
|
|
125
123
|
if (socket) {
|
|
126
124
|
socket.disconnect();
|
|
@@ -128,7 +126,11 @@ export function createClient(config) {
|
|
|
128
126
|
},
|
|
129
127
|
};
|
|
130
128
|
const serviceRoleModules = {
|
|
131
|
-
entities: createEntitiesModule(
|
|
129
|
+
entities: createEntitiesModule({
|
|
130
|
+
axios: serviceRoleAxiosClient,
|
|
131
|
+
appId,
|
|
132
|
+
getSocket,
|
|
133
|
+
}),
|
|
132
134
|
integrations: createIntegrationsModule(serviceRoleAxiosClient, appId),
|
|
133
135
|
sso: createSsoModule(serviceRoleAxiosClient, appId, token),
|
|
134
136
|
connectors: createConnectorsModule(serviceRoleAxiosClient, appId),
|
package/dist/client.types.d.ts
CHANGED
|
@@ -6,7 +6,6 @@ import type { ConnectorsModule } from "./modules/connectors.types.js";
|
|
|
6
6
|
import type { FunctionsModule } from "./modules/functions.types.js";
|
|
7
7
|
import type { AgentsModule } from "./modules/agents.types.js";
|
|
8
8
|
import type { AppLogsModule } from "./modules/app-logs.types.js";
|
|
9
|
-
import type { AnalyticsModuleOptions } from "./modules/analytics.types.js";
|
|
10
9
|
/**
|
|
11
10
|
* Options for creating a Base44 client.
|
|
12
11
|
*/
|
|
@@ -15,7 +14,6 @@ export interface CreateClientOptions {
|
|
|
15
14
|
* Optional error handler that will be called whenever an API error occurs.
|
|
16
15
|
*/
|
|
17
16
|
onError?: (error: Error) => void;
|
|
18
|
-
analytics?: AnalyticsModuleOptions;
|
|
19
17
|
}
|
|
20
18
|
/**
|
|
21
19
|
* Configuration for creating a Base44 client.
|
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, SubscribeOptions, 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";
|
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
import { AxiosInstance } from "axios";
|
|
2
2
|
import { EntitiesModule } from "./entities.types";
|
|
3
|
+
import { RoomsSocket } from "../utils/socket-utils";
|
|
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
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Creates the entities module for the Base44 SDK.
|
|
15
|
+
*
|
|
16
|
+
* @param config - Configuration object containing axios, appId, and getSocket
|
|
17
|
+
* @returns Entities module with dynamic entity access
|
|
18
|
+
* @internal
|
|
19
|
+
*/
|
|
20
|
+
export declare function createEntitiesModule(config: EntitiesModuleConfig): EntitiesModule;
|
|
3
21
|
/**
|
|
4
22
|
* Creates the entities module for the Base44 SDK.
|
|
5
23
|
*
|
|
@@ -7,5 +25,6 @@ import { EntitiesModule } from "./entities.types";
|
|
|
7
25
|
* @param appId - Application ID
|
|
8
26
|
* @returns Entities module with dynamic entity access
|
|
9
27
|
* @internal
|
|
28
|
+
* @deprecated Use the config object overload instead
|
|
10
29
|
*/
|
|
11
30
|
export declare function createEntitiesModule(axios: AxiosInstance, appId: string): EntitiesModule;
|
package/dist/modules/entities.js
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
export function createEntitiesModule(configOrAxios, appIdArg) {
|
|
2
|
+
// Handle both old and new signatures for backwards compatibility
|
|
3
|
+
const config = "axios" in configOrAxios
|
|
4
|
+
? configOrAxios
|
|
5
|
+
: {
|
|
6
|
+
axios: configOrAxios,
|
|
7
|
+
appId: appIdArg,
|
|
8
|
+
getSocket: () => {
|
|
9
|
+
throw new Error("Realtime subscriptions are not available. Please update your client configuration.");
|
|
10
|
+
},
|
|
11
|
+
};
|
|
12
|
+
const { axios, appId, getSocket } = config;
|
|
10
13
|
// Using Proxy to dynamically handle entity names
|
|
11
14
|
return new Proxy({}, {
|
|
12
15
|
get(target, entityName) {
|
|
@@ -17,20 +20,59 @@ export function createEntitiesModule(axios, appId) {
|
|
|
17
20
|
return undefined;
|
|
18
21
|
}
|
|
19
22
|
// Create entity handler
|
|
20
|
-
return createEntityHandler(axios, appId, entityName);
|
|
23
|
+
return createEntityHandler(axios, appId, entityName, getSocket);
|
|
21
24
|
},
|
|
22
25
|
});
|
|
23
26
|
}
|
|
27
|
+
/**
|
|
28
|
+
* Creates a stable hash from a query object for room naming.
|
|
29
|
+
* @internal
|
|
30
|
+
*/
|
|
31
|
+
function hashQuery(query) {
|
|
32
|
+
const sortedKeys = Object.keys(query).sort();
|
|
33
|
+
const normalized = sortedKeys
|
|
34
|
+
.map((k) => `${k}:${JSON.stringify(query[k])}`)
|
|
35
|
+
.join("|");
|
|
36
|
+
// Simple hash function
|
|
37
|
+
let hash = 0;
|
|
38
|
+
for (let i = 0; i < normalized.length; i++) {
|
|
39
|
+
const char = normalized.charCodeAt(i);
|
|
40
|
+
hash = (hash << 5) - hash + char;
|
|
41
|
+
hash = hash & hash; // Convert to 32bit integer
|
|
42
|
+
}
|
|
43
|
+
return Math.abs(hash).toString(36);
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Parses the realtime message data and extracts event information.
|
|
47
|
+
* @internal
|
|
48
|
+
*/
|
|
49
|
+
function parseRealtimeMessage(dataStr) {
|
|
50
|
+
var _a;
|
|
51
|
+
try {
|
|
52
|
+
const parsed = JSON.parse(dataStr);
|
|
53
|
+
return {
|
|
54
|
+
type: parsed.type,
|
|
55
|
+
data: parsed.data,
|
|
56
|
+
id: parsed.id || ((_a = parsed.data) === null || _a === void 0 ? void 0 : _a.id),
|
|
57
|
+
timestamp: parsed.timestamp || new Date().toISOString(),
|
|
58
|
+
previousData: parsed.previousData,
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
catch (_b) {
|
|
62
|
+
return null;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
24
65
|
/**
|
|
25
66
|
* Creates a handler for a specific entity.
|
|
26
67
|
*
|
|
27
68
|
* @param axios - Axios instance
|
|
28
69
|
* @param appId - Application ID
|
|
29
70
|
* @param entityName - Entity name
|
|
71
|
+
* @param getSocket - Function to get the socket instance
|
|
30
72
|
* @returns Entity handler with CRUD methods
|
|
31
73
|
* @internal
|
|
32
74
|
*/
|
|
33
|
-
function createEntityHandler(axios, appId, entityName) {
|
|
75
|
+
function createEntityHandler(axios, appId, entityName, getSocket) {
|
|
34
76
|
const baseURL = `/apps/${appId}/entities/${entityName}`;
|
|
35
77
|
return {
|
|
36
78
|
// List entities with optional pagination and sorting
|
|
@@ -95,5 +137,52 @@ function createEntityHandler(axios, appId, entityName) {
|
|
|
95
137
|
},
|
|
96
138
|
});
|
|
97
139
|
},
|
|
140
|
+
// Subscribe to realtime updates
|
|
141
|
+
subscribe(callbackOrIdOrQuery, callbackOrOptions, optionsArg) {
|
|
142
|
+
let room;
|
|
143
|
+
let callback;
|
|
144
|
+
let options;
|
|
145
|
+
// Parse overloaded arguments
|
|
146
|
+
if (typeof callbackOrIdOrQuery === "function") {
|
|
147
|
+
// subscribe(callback, options?)
|
|
148
|
+
room = `entities:${appId}:${entityName}`;
|
|
149
|
+
callback = callbackOrIdOrQuery;
|
|
150
|
+
options = callbackOrOptions;
|
|
151
|
+
}
|
|
152
|
+
else if (typeof callbackOrIdOrQuery === "string") {
|
|
153
|
+
// subscribe(id, callback, options?)
|
|
154
|
+
room = `entities:${appId}:${entityName}:${callbackOrIdOrQuery}`;
|
|
155
|
+
callback = callbackOrOptions;
|
|
156
|
+
options = optionsArg;
|
|
157
|
+
}
|
|
158
|
+
else {
|
|
159
|
+
// subscribe(query, callback, options?)
|
|
160
|
+
const queryHash = hashQuery(callbackOrIdOrQuery);
|
|
161
|
+
room = `entities:${appId}:${entityName}:query:${queryHash}`;
|
|
162
|
+
callback = callbackOrOptions;
|
|
163
|
+
options = optionsArg;
|
|
164
|
+
}
|
|
165
|
+
const eventFilter = options === null || options === void 0 ? void 0 : options.events;
|
|
166
|
+
// Get the socket and subscribe to the room
|
|
167
|
+
const socket = getSocket();
|
|
168
|
+
const unsubscribe = socket.subscribeToRoom(room, {
|
|
169
|
+
update_model: (msg) => {
|
|
170
|
+
// Only process messages for our room
|
|
171
|
+
if (msg.room !== room)
|
|
172
|
+
return;
|
|
173
|
+
const event = parseRealtimeMessage(msg.data);
|
|
174
|
+
if (!event)
|
|
175
|
+
return;
|
|
176
|
+
// Apply event type filter if specified
|
|
177
|
+
if (eventFilter && !eventFilter.includes(event.type)) {
|
|
178
|
+
return;
|
|
179
|
+
}
|
|
180
|
+
callback(event);
|
|
181
|
+
},
|
|
182
|
+
});
|
|
183
|
+
return {
|
|
184
|
+
unsubscribe,
|
|
185
|
+
};
|
|
186
|
+
},
|
|
98
187
|
};
|
|
99
188
|
}
|
|
@@ -1,3 +1,40 @@
|
|
|
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<T = Record<string, any>> {
|
|
9
|
+
/** The type of change that occurred */
|
|
10
|
+
type: RealtimeEventType;
|
|
11
|
+
/** The entity data (new/updated for create/update, previous for delete) */
|
|
12
|
+
data: T;
|
|
13
|
+
/** The unique identifier of the affected entity */
|
|
14
|
+
id: string;
|
|
15
|
+
/** ISO 8601 timestamp of when the event occurred */
|
|
16
|
+
timestamp: string;
|
|
17
|
+
/** For update events, contains the previous data before the change */
|
|
18
|
+
previousData?: T;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Callback function invoked when a realtime event occurs.
|
|
22
|
+
*/
|
|
23
|
+
export type RealtimeCallback<T = Record<string, any>> = (event: RealtimeEvent<T>) => void;
|
|
24
|
+
/**
|
|
25
|
+
* Options for subscribing to realtime updates.
|
|
26
|
+
*/
|
|
27
|
+
export interface SubscribeOptions {
|
|
28
|
+
/** Filter events by type. Defaults to all types. */
|
|
29
|
+
events?: RealtimeEventType[];
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Handle returned from subscribe, used to unsubscribe.
|
|
33
|
+
*/
|
|
34
|
+
export interface Subscription {
|
|
35
|
+
/** Stops listening to updates and cleans up the subscription. */
|
|
36
|
+
unsubscribe: () => void;
|
|
37
|
+
}
|
|
1
38
|
/**
|
|
2
39
|
* Entity handler providing CRUD operations for a specific entity type.
|
|
3
40
|
*
|
|
@@ -242,6 +279,93 @@ export interface EntityHandler {
|
|
|
242
279
|
* ```
|
|
243
280
|
*/
|
|
244
281
|
importEntities(file: File): Promise<any>;
|
|
282
|
+
/**
|
|
283
|
+
* Subscribes to realtime updates for all records of this entity type.
|
|
284
|
+
*
|
|
285
|
+
* Receives notifications whenever any record is created, updated, or deleted.
|
|
286
|
+
*
|
|
287
|
+
* @param callback - Function called when an entity changes.
|
|
288
|
+
* @param options - Optional configuration for filtering events.
|
|
289
|
+
* @returns Subscription handle with an unsubscribe method.
|
|
290
|
+
*
|
|
291
|
+
* @example
|
|
292
|
+
* ```typescript
|
|
293
|
+
* // Subscribe to all Task changes
|
|
294
|
+
* const subscription = base44.entities.Task.subscribe((event) => {
|
|
295
|
+
* console.log(`Task ${event.id} was ${event.type}d:`, event.data);
|
|
296
|
+
* });
|
|
297
|
+
*
|
|
298
|
+
* // Later, unsubscribe
|
|
299
|
+
* subscription.unsubscribe();
|
|
300
|
+
* ```
|
|
301
|
+
*
|
|
302
|
+
* @example
|
|
303
|
+
* ```typescript
|
|
304
|
+
* // Subscribe only to create events
|
|
305
|
+
* const subscription = base44.entities.Task.subscribe(
|
|
306
|
+
* (event) => console.log("New task:", event.data),
|
|
307
|
+
* { events: ["create"] }
|
|
308
|
+
* );
|
|
309
|
+
* ```
|
|
310
|
+
*/
|
|
311
|
+
subscribe(callback: RealtimeCallback, options?: SubscribeOptions): Subscription;
|
|
312
|
+
/**
|
|
313
|
+
* Subscribes to realtime updates for a specific entity record.
|
|
314
|
+
*
|
|
315
|
+
* Receives notifications when the specified record is updated or deleted.
|
|
316
|
+
*
|
|
317
|
+
* @param id - The unique identifier of the record to watch.
|
|
318
|
+
* @param callback - Function called when the entity changes.
|
|
319
|
+
* @param options - Optional configuration for filtering events.
|
|
320
|
+
* @returns Subscription handle with an unsubscribe method.
|
|
321
|
+
*
|
|
322
|
+
* @example
|
|
323
|
+
* ```typescript
|
|
324
|
+
* // Subscribe to a specific task
|
|
325
|
+
* const subscription = base44.entities.Task.subscribe("task-123", (event) => {
|
|
326
|
+
* if (event.type === "update") {
|
|
327
|
+
* console.log("Task updated:", event.data);
|
|
328
|
+
* } else if (event.type === "delete") {
|
|
329
|
+
* console.log("Task was deleted");
|
|
330
|
+
* }
|
|
331
|
+
* });
|
|
332
|
+
* ```
|
|
333
|
+
*/
|
|
334
|
+
subscribe(id: string, callback: RealtimeCallback, options?: SubscribeOptions): Subscription;
|
|
335
|
+
/**
|
|
336
|
+
* Subscribes to realtime updates for records matching a query.
|
|
337
|
+
*
|
|
338
|
+
* Receives notifications for records that match the specified criteria.
|
|
339
|
+
* Includes create events when new records match the query, update events
|
|
340
|
+
* when matching records change, and delete events when matching records
|
|
341
|
+
* are removed.
|
|
342
|
+
*
|
|
343
|
+
* @param query - Query object with field-value pairs to filter records.
|
|
344
|
+
* @param callback - Function called when a matching entity changes.
|
|
345
|
+
* @param options - Optional configuration for filtering events.
|
|
346
|
+
* @returns Subscription handle with an unsubscribe method.
|
|
347
|
+
*
|
|
348
|
+
* @example
|
|
349
|
+
* ```typescript
|
|
350
|
+
* // Subscribe to all completed tasks
|
|
351
|
+
* const subscription = base44.entities.Task.subscribe(
|
|
352
|
+
* { isCompleted: true },
|
|
353
|
+
* (event) => {
|
|
354
|
+
* console.log(`Completed task ${event.type}:`, event.data);
|
|
355
|
+
* }
|
|
356
|
+
* );
|
|
357
|
+
* ```
|
|
358
|
+
*
|
|
359
|
+
* @example
|
|
360
|
+
* ```typescript
|
|
361
|
+
* // Subscribe to high-priority active tasks
|
|
362
|
+
* const subscription = base44.entities.Task.subscribe(
|
|
363
|
+
* { priority: "high", status: "active" },
|
|
364
|
+
* (event) => console.log("High priority task changed:", event.data)
|
|
365
|
+
* );
|
|
366
|
+
* ```
|
|
367
|
+
*/
|
|
368
|
+
subscribe(query: Record<string, any>, callback: RealtimeCallback, options?: SubscribeOptions): Subscription;
|
|
245
369
|
}
|
|
246
370
|
/**
|
|
247
371
|
* Entities module for managing app data.
|
package/dist/modules/types.d.ts
CHANGED
package/dist/modules/types.js
CHANGED
package/package.json
CHANGED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { AxiosInstance } from "axios";
|
|
2
|
-
import { TrackEventParams, AnalyticsModuleOptions } from "./analytics.types";
|
|
3
|
-
export interface AnalyticsModuleArgs {
|
|
4
|
-
axiosClient: AxiosInstance;
|
|
5
|
-
appId: string;
|
|
6
|
-
options?: AnalyticsModuleOptions;
|
|
7
|
-
}
|
|
8
|
-
export declare const createAnalyticsModule: ({ axiosClient, appId, options, }: AnalyticsModuleArgs) => {
|
|
9
|
-
track: (params: TrackEventParams) => void;
|
|
10
|
-
};
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
import { getSharedInstance, getSharedInstanceRefCount, } from "../utils/singleton";
|
|
2
|
-
const ANALYTICS_SHARED_STATE_NAME = "analytics";
|
|
3
|
-
// shared state//
|
|
4
|
-
const analyticsSharedState = getSharedInstance(ANALYTICS_SHARED_STATE_NAME, () => ({
|
|
5
|
-
requestsQueue: [],
|
|
6
|
-
}));
|
|
7
|
-
export const createAnalyticsModule = ({ axiosClient, appId, options, }) => {
|
|
8
|
-
// prevent overflow of events //
|
|
9
|
-
const MAX_QUEUE_SIZE = 1000;
|
|
10
|
-
const isEnabled = (options === null || options === void 0 ? void 0 : options.enabled) !== false;
|
|
11
|
-
const track = (params) => {
|
|
12
|
-
if (!isEnabled ||
|
|
13
|
-
analyticsSharedState.requestsQueue.length >= MAX_QUEUE_SIZE) {
|
|
14
|
-
return;
|
|
15
|
-
}
|
|
16
|
-
const intrinsicData = getEventIntrinsicData();
|
|
17
|
-
analyticsSharedState.requestsQueue.push({
|
|
18
|
-
...params,
|
|
19
|
-
...intrinsicData,
|
|
20
|
-
});
|
|
21
|
-
};
|
|
22
|
-
const flush = async (eventsData) => {
|
|
23
|
-
const apiEvents = eventsData.map(transformEventDataToApiRequestData);
|
|
24
|
-
await axiosClient.request({
|
|
25
|
-
method: "POST",
|
|
26
|
-
url: `/apps/${appId}/analytics/track/batch`,
|
|
27
|
-
data: { events: apiEvents },
|
|
28
|
-
});
|
|
29
|
-
};
|
|
30
|
-
// start analytics processor only if it's the first instance and analytics is enabled //
|
|
31
|
-
if (getSharedInstanceRefCount(ANALYTICS_SHARED_STATE_NAME) <= 1 &&
|
|
32
|
-
isEnabled) {
|
|
33
|
-
startAnalyticsProcessor(flush, options === null || options === void 0 ? void 0 : options.trackService);
|
|
34
|
-
}
|
|
35
|
-
return {
|
|
36
|
-
track,
|
|
37
|
-
};
|
|
38
|
-
};
|
|
39
|
-
async function startAnalyticsProcessor(handleTrack, options) {
|
|
40
|
-
const { throttleTime = 1000, batchSize = 30 } = options !== null && options !== void 0 ? options : {};
|
|
41
|
-
while (true) {
|
|
42
|
-
await new Promise((resolve) => setTimeout(resolve, throttleTime));
|
|
43
|
-
const requests = analyticsSharedState.requestsQueue.splice(0, batchSize);
|
|
44
|
-
if (requests.length > 0) {
|
|
45
|
-
try {
|
|
46
|
-
await handleTrack(requests);
|
|
47
|
-
}
|
|
48
|
-
catch (error) {
|
|
49
|
-
// TODO: think about retries if needed
|
|
50
|
-
console.error("Error processing analytics request:", error);
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
function getEventIntrinsicData() {
|
|
56
|
-
return {
|
|
57
|
-
timestamp: new Date().toISOString(),
|
|
58
|
-
pageUrl: typeof window !== "undefined" ? window.location.href : null,
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
|
-
function transformEventDataToApiRequestData(eventData) {
|
|
62
|
-
return {
|
|
63
|
-
event_name: eventData.eventName,
|
|
64
|
-
properties: eventData.properties,
|
|
65
|
-
timestamp: eventData.timestamp,
|
|
66
|
-
page_url: eventData.pageUrl,
|
|
67
|
-
};
|
|
68
|
-
}
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
export type TrackEventProperties = {
|
|
2
|
-
[key: string]: string | number | boolean | null | undefined;
|
|
3
|
-
};
|
|
4
|
-
export type TrackEventParams = {
|
|
5
|
-
eventName: string;
|
|
6
|
-
properties?: TrackEventProperties;
|
|
7
|
-
};
|
|
8
|
-
export type TrackEventIntrinsicData = {
|
|
9
|
-
timestamp: string;
|
|
10
|
-
pageUrl?: string | null;
|
|
11
|
-
};
|
|
12
|
-
export type TrackEventData = {
|
|
13
|
-
properties?: TrackEventProperties;
|
|
14
|
-
eventName: string;
|
|
15
|
-
} & TrackEventIntrinsicData;
|
|
16
|
-
export type AnalyticsApiRequestData = {
|
|
17
|
-
event_name: string;
|
|
18
|
-
properties?: TrackEventProperties;
|
|
19
|
-
timestamp?: string;
|
|
20
|
-
page_url?: string | null;
|
|
21
|
-
};
|
|
22
|
-
export type AnalyticsApiBatchRequest = {
|
|
23
|
-
method: "POST";
|
|
24
|
-
url: `/apps/${string}/analytics/track/batch`;
|
|
25
|
-
data: {
|
|
26
|
-
events: AnalyticsApiRequestData[];
|
|
27
|
-
};
|
|
28
|
-
};
|
|
29
|
-
export type AnalyticsModuleOptions = {
|
|
30
|
-
enabled?: boolean;
|
|
31
|
-
trackService?: {
|
|
32
|
-
throttleTime: number;
|
|
33
|
-
batchSize: number;
|
|
34
|
-
};
|
|
35
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/dist/utils/singleton.js
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
// Singleton (shared between sdk instances)//
|
|
2
|
-
export function getSharedInstance(name, factory) {
|
|
3
|
-
const windowObj = typeof window !== "undefined" ? window : { base44: {} };
|
|
4
|
-
if (!windowObj.base44) {
|
|
5
|
-
windowObj.base44 = {};
|
|
6
|
-
}
|
|
7
|
-
if (!windowObj.base44[name]) {
|
|
8
|
-
windowObj.base44[name] = { instance: factory(), _refCount: 1 };
|
|
9
|
-
}
|
|
10
|
-
return windowObj.base44[name].instance;
|
|
11
|
-
}
|
|
12
|
-
export function getSharedInstanceRefCount(name) {
|
|
13
|
-
var _a, _b, _c;
|
|
14
|
-
const windowObj = typeof window !== "undefined" ? window : { base44: {} };
|
|
15
|
-
return (_c = (_b = (_a = windowObj.base44) === null || _a === void 0 ? void 0 : _a[name]) === null || _b === void 0 ? void 0 : _b._refCount) !== null && _c !== void 0 ? _c : 0;
|
|
16
|
-
}
|