@base44-preview/sdk 0.8.11-pr.58.aadf182 → 0.8.11-pr.63.63e4139
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 +2 -10
- package/dist/index.d.ts +1 -1
- package/dist/modules/entities.d.ts +0 -19
- package/dist/modules/entities.js +24 -58
- package/dist/modules/entities.types.d.ts +0 -45
- package/package.json +1 -1
package/dist/client.js
CHANGED
|
@@ -104,11 +104,7 @@ export function createClient(config) {
|
|
|
104
104
|
serverUrl,
|
|
105
105
|
});
|
|
106
106
|
const userModules = {
|
|
107
|
-
entities: createEntitiesModule(
|
|
108
|
-
axios: axiosClient,
|
|
109
|
-
appId,
|
|
110
|
-
getSocket,
|
|
111
|
-
}),
|
|
107
|
+
entities: createEntitiesModule(axiosClient, appId),
|
|
112
108
|
integrations: createIntegrationsModule(axiosClient, appId),
|
|
113
109
|
auth: userAuthModule,
|
|
114
110
|
functions: createFunctionsModule(functionsAxiosClient, appId),
|
|
@@ -135,11 +131,7 @@ export function createClient(config) {
|
|
|
135
131
|
},
|
|
136
132
|
};
|
|
137
133
|
const serviceRoleModules = {
|
|
138
|
-
entities: createEntitiesModule(
|
|
139
|
-
axios: serviceRoleAxiosClient,
|
|
140
|
-
appId,
|
|
141
|
-
getSocket,
|
|
142
|
-
}),
|
|
134
|
+
entities: createEntitiesModule(serviceRoleAxiosClient, appId),
|
|
143
135
|
integrations: createIntegrationsModule(serviceRoleAxiosClient, appId),
|
|
144
136
|
sso: createSsoModule(serviceRoleAxiosClient, appId, token),
|
|
145
137
|
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,
|
|
7
|
+
export type { EntitiesModule, EntityHandler, } 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,23 +1,5 @@
|
|
|
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;
|
|
21
3
|
/**
|
|
22
4
|
* Creates the entities module for the Base44 SDK.
|
|
23
5
|
*
|
|
@@ -25,6 +7,5 @@ export declare function createEntitiesModule(config: EntitiesModuleConfig): Enti
|
|
|
25
7
|
* @param appId - Application ID
|
|
26
8
|
* @returns Entities module with dynamic entity access
|
|
27
9
|
* @internal
|
|
28
|
-
* @deprecated Use the config object overload instead
|
|
29
10
|
*/
|
|
30
11
|
export declare function createEntitiesModule(axios: AxiosInstance, appId: string): EntitiesModule;
|
package/dist/modules/entities.js
CHANGED
|
@@ -1,15 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
},
|
|
11
|
-
};
|
|
12
|
-
const { axios, appId, getSocket } = config;
|
|
1
|
+
/**
|
|
2
|
+
* Creates the entities module for the Base44 SDK.
|
|
3
|
+
*
|
|
4
|
+
* @param axios - Axios instance
|
|
5
|
+
* @param appId - Application ID
|
|
6
|
+
* @returns Entities module with dynamic entity access
|
|
7
|
+
* @internal
|
|
8
|
+
*/
|
|
9
|
+
export function createEntitiesModule(axios, appId) {
|
|
13
10
|
// Using Proxy to dynamically handle entity names
|
|
14
11
|
return new Proxy({}, {
|
|
15
12
|
get(target, entityName) {
|
|
@@ -20,41 +17,25 @@ export function createEntitiesModule(configOrAxios, appIdArg) {
|
|
|
20
17
|
return undefined;
|
|
21
18
|
}
|
|
22
19
|
// Create entity handler
|
|
23
|
-
return createEntityHandler(axios, appId, entityName
|
|
20
|
+
return createEntityHandler(axios, appId, entityName);
|
|
24
21
|
},
|
|
25
22
|
});
|
|
26
23
|
}
|
|
27
|
-
/**
|
|
28
|
-
* Parses the realtime message data and extracts event information.
|
|
29
|
-
* @internal
|
|
30
|
-
*/
|
|
31
|
-
function parseRealtimeMessage(dataStr) {
|
|
32
|
-
var _a;
|
|
33
|
-
try {
|
|
34
|
-
const parsed = JSON.parse(dataStr);
|
|
35
|
-
return {
|
|
36
|
-
type: parsed.type,
|
|
37
|
-
data: parsed.data,
|
|
38
|
-
id: parsed.id || ((_a = parsed.data) === null || _a === void 0 ? void 0 : _a.id),
|
|
39
|
-
timestamp: parsed.timestamp || new Date().toISOString(),
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
catch (_b) {
|
|
43
|
-
return null;
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
24
|
/**
|
|
47
25
|
* Creates a handler for a specific entity.
|
|
48
26
|
*
|
|
49
27
|
* @param axios - Axios instance
|
|
50
28
|
* @param appId - Application ID
|
|
51
29
|
* @param entityName - Entity name
|
|
52
|
-
* @param getSocket - Function to get the socket instance
|
|
53
30
|
* @returns Entity handler with CRUD methods
|
|
54
31
|
* @internal
|
|
55
32
|
*/
|
|
56
|
-
function createEntityHandler(axios, appId, entityName
|
|
33
|
+
function createEntityHandler(axios, appId, entityName) {
|
|
57
34
|
const baseURL = `/apps/${appId}/entities/${entityName}`;
|
|
35
|
+
const isDevMode = typeof window !== "undefined"
|
|
36
|
+
? new URLSearchParams(window.location.search).get("use_dev_table") === "true"
|
|
37
|
+
: false;
|
|
38
|
+
const headers = { "X-Use-Dev-Table": String(isDevMode) };
|
|
58
39
|
return {
|
|
59
40
|
// List entities with optional pagination and sorting
|
|
60
41
|
async list(sort, limit, skip, fields) {
|
|
@@ -67,7 +48,7 @@ function createEntityHandler(axios, appId, entityName, getSocket) {
|
|
|
67
48
|
params.skip = skip;
|
|
68
49
|
if (fields)
|
|
69
50
|
params.fields = Array.isArray(fields) ? fields.join(",") : fields;
|
|
70
|
-
return axios.get(baseURL, { params });
|
|
51
|
+
return axios.get(baseURL, { params, headers });
|
|
71
52
|
},
|
|
72
53
|
// Filter entities based on query
|
|
73
54
|
async filter(query, sort, limit, skip, fields) {
|
|
@@ -82,31 +63,31 @@ function createEntityHandler(axios, appId, entityName, getSocket) {
|
|
|
82
63
|
params.skip = skip;
|
|
83
64
|
if (fields)
|
|
84
65
|
params.fields = Array.isArray(fields) ? fields.join(",") : fields;
|
|
85
|
-
return axios.get(baseURL, { params });
|
|
66
|
+
return axios.get(baseURL, { params, headers });
|
|
86
67
|
},
|
|
87
68
|
// Get entity by ID
|
|
88
69
|
async get(id) {
|
|
89
|
-
return axios.get(`${baseURL}/${id}
|
|
70
|
+
return axios.get(`${baseURL}/${id}`, { headers });
|
|
90
71
|
},
|
|
91
72
|
// Create new entity
|
|
92
73
|
async create(data) {
|
|
93
|
-
return axios.post(baseURL, data);
|
|
74
|
+
return axios.post(baseURL, data, { headers });
|
|
94
75
|
},
|
|
95
76
|
// Update entity by ID
|
|
96
77
|
async update(id, data) {
|
|
97
|
-
return axios.put(`${baseURL}/${id}`, data);
|
|
78
|
+
return axios.put(`${baseURL}/${id}`, data, { headers });
|
|
98
79
|
},
|
|
99
80
|
// Delete entity by ID
|
|
100
81
|
async delete(id) {
|
|
101
|
-
return axios.delete(`${baseURL}/${id}
|
|
82
|
+
return axios.delete(`${baseURL}/${id}`, { headers });
|
|
102
83
|
},
|
|
103
84
|
// Delete multiple entities based on query
|
|
104
85
|
async deleteMany(query) {
|
|
105
|
-
return axios.delete(baseURL, { data: query });
|
|
86
|
+
return axios.delete(baseURL, { data: query, headers });
|
|
106
87
|
},
|
|
107
88
|
// Create multiple entities in a single request
|
|
108
89
|
async bulkCreate(data) {
|
|
109
|
-
return axios.post(`${baseURL}/bulk`, data);
|
|
90
|
+
return axios.post(`${baseURL}/bulk`, data, { headers });
|
|
110
91
|
},
|
|
111
92
|
// Import entities from a file
|
|
112
93
|
async importEntities(file) {
|
|
@@ -114,25 +95,10 @@ function createEntityHandler(axios, appId, entityName, getSocket) {
|
|
|
114
95
|
formData.append("file", file, file.name);
|
|
115
96
|
return axios.post(`${baseURL}/import`, formData, {
|
|
116
97
|
headers: {
|
|
98
|
+
...headers,
|
|
117
99
|
"Content-Type": "multipart/form-data",
|
|
118
100
|
},
|
|
119
101
|
});
|
|
120
102
|
},
|
|
121
|
-
// Subscribe to realtime updates
|
|
122
|
-
subscribe(callback) {
|
|
123
|
-
const room = `entities:${appId}:${entityName}`;
|
|
124
|
-
// Get the socket and subscribe to the room
|
|
125
|
-
const socket = getSocket();
|
|
126
|
-
const unsubscribe = socket.subscribeToRoom(room, {
|
|
127
|
-
update_model: (msg) => {
|
|
128
|
-
const event = parseRealtimeMessage(msg.data);
|
|
129
|
-
if (!event) {
|
|
130
|
-
return;
|
|
131
|
-
}
|
|
132
|
-
callback(event);
|
|
133
|
-
},
|
|
134
|
-
});
|
|
135
|
-
return unsubscribe;
|
|
136
|
-
},
|
|
137
103
|
};
|
|
138
104
|
}
|
|
@@ -1,28 +1,3 @@
|
|
|
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
|
-
}
|
|
18
|
-
/**
|
|
19
|
-
* Callback function invoked when a realtime event occurs.
|
|
20
|
-
*/
|
|
21
|
-
export type RealtimeCallback<T = Record<string, any>> = (event: RealtimeEvent<T>) => void;
|
|
22
|
-
/**
|
|
23
|
-
* Function returned from subscribe, call it to unsubscribe.
|
|
24
|
-
*/
|
|
25
|
-
export type Subscription = () => void;
|
|
26
1
|
/**
|
|
27
2
|
* Entity handler providing CRUD operations for a specific entity type.
|
|
28
3
|
*
|
|
@@ -267,26 +242,6 @@ export interface EntityHandler {
|
|
|
267
242
|
* ```
|
|
268
243
|
*/
|
|
269
244
|
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;
|
|
290
245
|
}
|
|
291
246
|
/**
|
|
292
247
|
* Entities module for managing app data.
|