@base44-preview/sdk 0.8.5-pr.52.f01053f → 0.8.6-pr.48.d625f02
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.d.ts +90 -237
- package/dist/client.js +141 -25
- package/dist/client.types.d.ts +131 -0
- package/dist/client.types.js +1 -0
- package/dist/index.d.ts +13 -5
- package/dist/index.js +2 -3
- package/dist/modules/agents.d.ts +2 -23
- package/dist/modules/agents.js +3 -1
- package/dist/modules/agents.types.d.ts +330 -34
- package/dist/modules/app-logs.d.ts +8 -24
- package/dist/modules/app-logs.js +9 -19
- package/dist/modules/app-logs.types.d.ts +44 -0
- package/dist/modules/app-logs.types.js +1 -0
- package/dist/modules/app.types.d.ts +27 -0
- package/dist/modules/auth.d.ts +10 -78
- package/dist/modules/auth.js +24 -42
- package/dist/modules/auth.types.d.ts +436 -0
- package/dist/modules/auth.types.js +1 -0
- package/dist/modules/connectors.d.ts +6 -11
- package/dist/modules/connectors.js +6 -7
- package/dist/modules/connectors.types.d.ts +68 -2
- package/dist/modules/entities.d.ts +8 -5
- package/dist/modules/entities.js +22 -62
- package/dist/modules/entities.types.d.ts +293 -0
- package/dist/modules/entities.types.js +1 -0
- package/dist/modules/functions.d.ts +8 -7
- package/dist/modules/functions.js +7 -5
- package/dist/modules/functions.types.d.ts +50 -0
- package/dist/modules/functions.types.js +1 -0
- package/dist/modules/integrations.d.ts +8 -5
- package/dist/modules/integrations.js +7 -5
- package/dist/modules/integrations.types.d.ts +352 -0
- package/dist/modules/integrations.types.js +1 -0
- package/dist/modules/sso.d.ts +9 -14
- package/dist/modules/sso.js +9 -12
- package/dist/modules/sso.types.d.ts +44 -0
- package/dist/modules/sso.types.js +1 -0
- package/dist/types.d.ts +65 -2
- package/dist/utils/auth-utils.d.ts +107 -45
- package/dist/utils/auth-utils.js +107 -33
- package/dist/utils/auth-utils.types.d.ts +146 -0
- package/dist/utils/auth-utils.types.js +1 -0
- package/dist/utils/axios-client.d.ts +84 -16
- package/dist/utils/axios-client.js +74 -13
- package/dist/utils/axios-client.types.d.ts +28 -0
- package/dist/utils/axios-client.types.js +1 -0
- package/dist/utils/common.d.ts +0 -1
- package/dist/utils/common.js +1 -2
- package/dist/utils/socket-utils.d.ts +2 -2
- package/package.json +12 -3
- package/dist/utils/app-params.d.ts +0 -13
- package/dist/utils/app-params.js +0 -44
package/dist/modules/entities.js
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Creates the entities module for the Base44 SDK
|
|
3
|
-
*
|
|
4
|
-
* @param
|
|
5
|
-
* @
|
|
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
|
|
6
8
|
*/
|
|
7
9
|
export function createEntitiesModule(axios, appId) {
|
|
8
10
|
// Using Proxy to dynamically handle entity names
|
|
@@ -20,23 +22,18 @@ export function createEntitiesModule(axios, appId) {
|
|
|
20
22
|
});
|
|
21
23
|
}
|
|
22
24
|
/**
|
|
23
|
-
* Creates a handler for a specific entity
|
|
24
|
-
*
|
|
25
|
-
* @param
|
|
26
|
-
* @param
|
|
27
|
-
* @
|
|
25
|
+
* Creates a handler for a specific entity.
|
|
26
|
+
*
|
|
27
|
+
* @param axios - Axios instance
|
|
28
|
+
* @param appId - Application ID
|
|
29
|
+
* @param entityName - Entity name
|
|
30
|
+
* @returns Entity handler with CRUD methods
|
|
31
|
+
* @internal
|
|
28
32
|
*/
|
|
29
33
|
function createEntityHandler(axios, appId, entityName) {
|
|
30
34
|
const baseURL = `/apps/${appId}/entities/${entityName}`;
|
|
31
35
|
return {
|
|
32
|
-
|
|
33
|
-
* List entities with optional pagination and sorting
|
|
34
|
-
* @param {string} [sort] - Sort parameter
|
|
35
|
-
* @param {number} [limit] - Limit results
|
|
36
|
-
* @param {number} [skip] - Skip results (pagination)
|
|
37
|
-
* @param {string[]} [fields] - Fields to include
|
|
38
|
-
* @returns {Promise<Array>} List of entities
|
|
39
|
-
*/
|
|
36
|
+
// List entities with optional pagination and sorting
|
|
40
37
|
async list(sort, limit, skip, fields) {
|
|
41
38
|
const params = {};
|
|
42
39
|
if (sort)
|
|
@@ -49,15 +46,7 @@ function createEntityHandler(axios, appId, entityName) {
|
|
|
49
46
|
params.fields = Array.isArray(fields) ? fields.join(",") : fields;
|
|
50
47
|
return axios.get(baseURL, { params });
|
|
51
48
|
},
|
|
52
|
-
|
|
53
|
-
* Filter entities based on query
|
|
54
|
-
* @param {Object} query - Filter query
|
|
55
|
-
* @param {string} [sort] - Sort parameter
|
|
56
|
-
* @param {number} [limit] - Limit results
|
|
57
|
-
* @param {number} [skip] - Skip results (pagination)
|
|
58
|
-
* @param {string[]} [fields] - Fields to include
|
|
59
|
-
* @returns {Promise<Array>} Filtered entities
|
|
60
|
-
*/
|
|
49
|
+
// Filter entities based on query
|
|
61
50
|
async filter(query, sort, limit, skip, fields) {
|
|
62
51
|
const params = {
|
|
63
52
|
q: JSON.stringify(query),
|
|
@@ -72,60 +61,31 @@ function createEntityHandler(axios, appId, entityName) {
|
|
|
72
61
|
params.fields = Array.isArray(fields) ? fields.join(",") : fields;
|
|
73
62
|
return axios.get(baseURL, { params });
|
|
74
63
|
},
|
|
75
|
-
|
|
76
|
-
* Get entity by ID
|
|
77
|
-
* @param {string} id - Entity ID
|
|
78
|
-
* @returns {Promise<Object>} Entity
|
|
79
|
-
*/
|
|
64
|
+
// Get entity by ID
|
|
80
65
|
async get(id) {
|
|
81
66
|
return axios.get(`${baseURL}/${id}`);
|
|
82
67
|
},
|
|
83
|
-
|
|
84
|
-
* Create new entity
|
|
85
|
-
* @param {Object} data - Entity data
|
|
86
|
-
* @returns {Promise<Object>} Created entity
|
|
87
|
-
*/
|
|
68
|
+
// Create new entity
|
|
88
69
|
async create(data) {
|
|
89
70
|
return axios.post(baseURL, data);
|
|
90
71
|
},
|
|
91
|
-
|
|
92
|
-
* Update entity by ID
|
|
93
|
-
* @param {string} id - Entity ID
|
|
94
|
-
* @param {Object} data - Updated entity data
|
|
95
|
-
* @returns {Promise<Object>} Updated entity
|
|
96
|
-
*/
|
|
72
|
+
// Update entity by ID
|
|
97
73
|
async update(id, data) {
|
|
98
74
|
return axios.put(`${baseURL}/${id}`, data);
|
|
99
75
|
},
|
|
100
|
-
|
|
101
|
-
* Delete entity by ID
|
|
102
|
-
* @param {string} id - Entity ID
|
|
103
|
-
* @returns {Promise<void>}
|
|
104
|
-
*/
|
|
76
|
+
// Delete entity by ID
|
|
105
77
|
async delete(id) {
|
|
106
78
|
return axios.delete(`${baseURL}/${id}`);
|
|
107
79
|
},
|
|
108
|
-
|
|
109
|
-
* Delete multiple entities based on query
|
|
110
|
-
* @param {Object} query - Delete query
|
|
111
|
-
* @returns {Promise<void>}
|
|
112
|
-
*/
|
|
80
|
+
// Delete multiple entities based on query
|
|
113
81
|
async deleteMany(query) {
|
|
114
82
|
return axios.delete(baseURL, { data: query });
|
|
115
83
|
},
|
|
116
|
-
|
|
117
|
-
* Create multiple entities in a single request
|
|
118
|
-
* @param {Array} data - Array of entity data
|
|
119
|
-
* @returns {Promise<Array>} Created entities
|
|
120
|
-
*/
|
|
84
|
+
// Create multiple entities in a single request
|
|
121
85
|
async bulkCreate(data) {
|
|
122
86
|
return axios.post(`${baseURL}/bulk`, data);
|
|
123
87
|
},
|
|
124
|
-
|
|
125
|
-
* Import entities from a file
|
|
126
|
-
* @param {File} file - File to import
|
|
127
|
-
* @returns {Promise<Object>} Import result
|
|
128
|
-
*/
|
|
88
|
+
// Import entities from a file
|
|
129
89
|
async importEntities(file) {
|
|
130
90
|
const formData = new FormData();
|
|
131
91
|
formData.append("file", file, file.name);
|
|
@@ -0,0 +1,293 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Entity handler providing CRUD operations for a specific entity type.
|
|
3
|
+
*
|
|
4
|
+
* Each entity in the app gets a handler with these methods for managing data.
|
|
5
|
+
*/
|
|
6
|
+
export interface EntityHandler {
|
|
7
|
+
/**
|
|
8
|
+
* Lists records with optional pagination and sorting.
|
|
9
|
+
*
|
|
10
|
+
* Retrieves all records of this type with support for sorting,
|
|
11
|
+
* pagination, and field selection.
|
|
12
|
+
*
|
|
13
|
+
* @param sort - Sort parameter, such as `'-created_date'` for descending. Defaults to `'-created_date'`.
|
|
14
|
+
* @param limit - Maximum number of results to return. Defaults to `50`.
|
|
15
|
+
* @param skip - Number of results to skip for pagination. Defaults to `0`.
|
|
16
|
+
* @param fields - Array of field names to include in the response. Defaults to all fields.
|
|
17
|
+
* @returns Promise resolving to an array of records.
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```typescript
|
|
21
|
+
* // Get all records
|
|
22
|
+
* const records = await base44.entities.MyEntity.list();
|
|
23
|
+
* ```
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* ```typescript
|
|
27
|
+
* // Get first 10 records sorted by date
|
|
28
|
+
* const recentRecords = await base44.entities.MyEntity.list('-created_date', 10);
|
|
29
|
+
* ```
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* ```typescript
|
|
33
|
+
* // Get paginated results
|
|
34
|
+
* // Skip first 20, get next 10
|
|
35
|
+
* const page3 = await base44.entities.MyEntity.list('-created_date', 10, 20);
|
|
36
|
+
* ```
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* ```typescript
|
|
40
|
+
* // Get only specific fields
|
|
41
|
+
* const fields = await base44.entities.MyEntity.list('-created_date', 10, 0, ['name', 'status']);
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
44
|
+
list(sort?: string, limit?: number, skip?: number, fields?: string[]): Promise<any>;
|
|
45
|
+
/**
|
|
46
|
+
* Filters records based on a query.
|
|
47
|
+
*
|
|
48
|
+
* Retrieves records that match specific criteria with support for
|
|
49
|
+
* sorting, pagination, and field selection.
|
|
50
|
+
*
|
|
51
|
+
* @param query - Query object with field-value pairs. Each key should be a field name
|
|
52
|
+
* from your entity schema, and each value is the criteria to match. Records matching all
|
|
53
|
+
* specified criteria are returned. Field names are case-sensitive.
|
|
54
|
+
* @param sort - Sort parameter, such as `'-created_date'` for descending. Defaults to `'-created_date'`.
|
|
55
|
+
* @param limit - Maximum number of results to return. Defaults to `50`.
|
|
56
|
+
* @param skip - Number of results to skip for pagination. Defaults to `0`.
|
|
57
|
+
* @param fields - Array of field names to include in the response. Defaults to all fields.
|
|
58
|
+
* @returns Promise resolving to an array of filtered records.
|
|
59
|
+
*
|
|
60
|
+
* @example
|
|
61
|
+
* ```typescript
|
|
62
|
+
* // Filter by single field
|
|
63
|
+
* const activeRecords = await base44.entities.MyEntity.filter({
|
|
64
|
+
* status: 'active'
|
|
65
|
+
* });
|
|
66
|
+
* ```
|
|
67
|
+
*
|
|
68
|
+
* @example
|
|
69
|
+
* ```typescript
|
|
70
|
+
* // Filter by multiple fields
|
|
71
|
+
* const filteredRecords = await base44.entities.MyEntity.filter({
|
|
72
|
+
* priority: 'high',
|
|
73
|
+
* status: 'active'
|
|
74
|
+
* });
|
|
75
|
+
* ```
|
|
76
|
+
*
|
|
77
|
+
* @example
|
|
78
|
+
* ```typescript
|
|
79
|
+
* // Filter with sorting and pagination
|
|
80
|
+
* const results = await base44.entities.MyEntity.filter(
|
|
81
|
+
* { status: 'active' },
|
|
82
|
+
* '-created_date',
|
|
83
|
+
* 20,
|
|
84
|
+
* 0
|
|
85
|
+
* );
|
|
86
|
+
* ```
|
|
87
|
+
*
|
|
88
|
+
* @example
|
|
89
|
+
* ```typescript
|
|
90
|
+
* // Filter with specific fields
|
|
91
|
+
* const fields = await base44.entities.MyEntity.filter(
|
|
92
|
+
* { priority: 'high' },
|
|
93
|
+
* '-created_date',
|
|
94
|
+
* 10,
|
|
95
|
+
* 0,
|
|
96
|
+
* ['name', 'priority']
|
|
97
|
+
* );
|
|
98
|
+
* ```
|
|
99
|
+
*/
|
|
100
|
+
filter(query: Record<string, any>, sort?: string, limit?: number, skip?: number, fields?: string[]): Promise<any>;
|
|
101
|
+
/**
|
|
102
|
+
* Gets a single record by ID.
|
|
103
|
+
*
|
|
104
|
+
* Retrieves a specific record using its unique identifier.
|
|
105
|
+
*
|
|
106
|
+
* @param id - The unique identifier of the record.
|
|
107
|
+
* @returns Promise resolving to the record.
|
|
108
|
+
*
|
|
109
|
+
* @example
|
|
110
|
+
* ```typescript
|
|
111
|
+
* // Get record by ID
|
|
112
|
+
* const record = await base44.entities.MyEntity.get('entity-123');
|
|
113
|
+
* console.log(record.name);
|
|
114
|
+
* ```
|
|
115
|
+
*/
|
|
116
|
+
get(id: string): Promise<any>;
|
|
117
|
+
/**
|
|
118
|
+
* Creates a new record.
|
|
119
|
+
*
|
|
120
|
+
* Creates a new record with the provided data.
|
|
121
|
+
*
|
|
122
|
+
* @param data - Object containing the record data.
|
|
123
|
+
* @returns Promise resolving to the created record.
|
|
124
|
+
*
|
|
125
|
+
* @example
|
|
126
|
+
* ```typescript
|
|
127
|
+
* // Create a new record
|
|
128
|
+
* const newRecord = await base44.entities.MyEntity.create({
|
|
129
|
+
* name: 'My Item',
|
|
130
|
+
* status: 'active',
|
|
131
|
+
* priority: 'high'
|
|
132
|
+
* });
|
|
133
|
+
* console.log('Created record with ID:', newRecord.id);
|
|
134
|
+
* ```
|
|
135
|
+
*/
|
|
136
|
+
create(data: Record<string, any>): Promise<any>;
|
|
137
|
+
/**
|
|
138
|
+
* Updates an existing record.
|
|
139
|
+
*
|
|
140
|
+
* Updates a record by ID with the provided data. Only the fields
|
|
141
|
+
* included in the data object will be updated.
|
|
142
|
+
*
|
|
143
|
+
* @param id - The unique identifier of the record to update.
|
|
144
|
+
* @param data - Object containing the fields to update.
|
|
145
|
+
* @returns Promise resolving to the updated record.
|
|
146
|
+
*
|
|
147
|
+
* @example
|
|
148
|
+
* ```typescript
|
|
149
|
+
* // Update single field
|
|
150
|
+
* const updated = await base44.entities.MyEntity.update('entity-123', {
|
|
151
|
+
* status: 'completed'
|
|
152
|
+
* });
|
|
153
|
+
* ```
|
|
154
|
+
*
|
|
155
|
+
* @example
|
|
156
|
+
* ```typescript
|
|
157
|
+
* // Update multiple fields
|
|
158
|
+
* const updated = await base44.entities.MyEntity.update('entity-123', {
|
|
159
|
+
* name: 'Updated name',
|
|
160
|
+
* priority: 'low',
|
|
161
|
+
* status: 'active'
|
|
162
|
+
* });
|
|
163
|
+
* ```
|
|
164
|
+
*/
|
|
165
|
+
update(id: string, data: Record<string, any>): Promise<any>;
|
|
166
|
+
/**
|
|
167
|
+
* Deletes a single record by ID.
|
|
168
|
+
*
|
|
169
|
+
* Permanently removes a record from the database.
|
|
170
|
+
*
|
|
171
|
+
* @param id - The unique identifier of the record to delete.
|
|
172
|
+
* @returns Promise resolving to the deletion result.
|
|
173
|
+
*
|
|
174
|
+
* @example
|
|
175
|
+
* ```typescript
|
|
176
|
+
* // Delete a record
|
|
177
|
+
* const result = await base44.entities.MyEntity.delete('entity-123');
|
|
178
|
+
* console.log('Deleted:', result);
|
|
179
|
+
* ```
|
|
180
|
+
*/
|
|
181
|
+
delete(id: string): Promise<any>;
|
|
182
|
+
/**
|
|
183
|
+
* Deletes multiple records matching a query.
|
|
184
|
+
*
|
|
185
|
+
* Permanently removes all records that match the provided query.
|
|
186
|
+
*
|
|
187
|
+
* @param query - Query object with field-value pairs. Each key should be a field name
|
|
188
|
+
* from your entity schema, and each value is the criteria to match. Records matching all
|
|
189
|
+
* specified criteria will be deleted. Field names are case-sensitive.
|
|
190
|
+
* @returns Promise resolving to the deletion result.
|
|
191
|
+
*
|
|
192
|
+
* @example
|
|
193
|
+
* ```typescript
|
|
194
|
+
* // Delete by multiple criteria
|
|
195
|
+
* const result = await base44.entities.MyEntity.deleteMany({
|
|
196
|
+
* status: 'completed',
|
|
197
|
+
* priority: 'low'
|
|
198
|
+
* });
|
|
199
|
+
* console.log('Deleted:', result);
|
|
200
|
+
* ```
|
|
201
|
+
*/
|
|
202
|
+
deleteMany(query: Record<string, any>): Promise<any>;
|
|
203
|
+
/**
|
|
204
|
+
* Creates multiple records in a single request.
|
|
205
|
+
*
|
|
206
|
+
* Efficiently creates multiple records at once. This is faster
|
|
207
|
+
* than creating them individually.
|
|
208
|
+
*
|
|
209
|
+
* @param data - Array of record data objects.
|
|
210
|
+
* @returns Promise resolving to an array of created records.
|
|
211
|
+
*
|
|
212
|
+
* @example
|
|
213
|
+
* ```typescript
|
|
214
|
+
* // Create multiple records at once
|
|
215
|
+
* const result = await base44.entities.MyEntity.bulkCreate([
|
|
216
|
+
* { name: 'Item 1', status: 'active' },
|
|
217
|
+
* { name: 'Item 2', status: 'active' },
|
|
218
|
+
* { name: 'Item 3', status: 'completed' }
|
|
219
|
+
* ]);
|
|
220
|
+
* ```
|
|
221
|
+
*/
|
|
222
|
+
bulkCreate(data: Record<string, any>[]): Promise<any>;
|
|
223
|
+
/**
|
|
224
|
+
* Imports records from a file.
|
|
225
|
+
*
|
|
226
|
+
* Imports records from a file, typically CSV or similar format.
|
|
227
|
+
* The file format should match your entity structure. Requires a browser environment and can't be used in the backend.
|
|
228
|
+
*
|
|
229
|
+
* @param file - File object to import.
|
|
230
|
+
* @returns Promise resolving to the import result.
|
|
231
|
+
*
|
|
232
|
+
* @example
|
|
233
|
+
* ```typescript
|
|
234
|
+
* // Import records from file in React
|
|
235
|
+
* const handleFileImport = async (event: React.ChangeEvent<HTMLInputElement>) => {
|
|
236
|
+
* const file = event.target.files?.[0];
|
|
237
|
+
* if (file) {
|
|
238
|
+
* const result = await base44.entities.MyEntity.importEntities(file);
|
|
239
|
+
* console.log(`Imported ${result.count} records`);
|
|
240
|
+
* }
|
|
241
|
+
* };
|
|
242
|
+
* ```
|
|
243
|
+
*/
|
|
244
|
+
importEntities(file: File): Promise<any>;
|
|
245
|
+
}
|
|
246
|
+
/**
|
|
247
|
+
* Entities module for managing app data.
|
|
248
|
+
*
|
|
249
|
+
* This module provides dynamic access to all entities in the app.
|
|
250
|
+
* Each entity gets a handler with full CRUD operations and additional utility methods.
|
|
251
|
+
*
|
|
252
|
+
* Entities are accessed dynamically using the pattern:
|
|
253
|
+
* `base44.entities.EntityName.method()`
|
|
254
|
+
*
|
|
255
|
+
* This module is available to use with a client in all three authentication modes:
|
|
256
|
+
*
|
|
257
|
+
* - **Anonymous or User authentication** (`base44.entities`): Access is scoped to the current user's permissions. Anonymous users can only access public entities, while authenticated users can access entities they have permission to view or modify.
|
|
258
|
+
* - **Service role authentication** (`base44.asServiceRole.entities`): Operations have elevated admin-level permissions. Can access all entities that the app's admin role has access to.
|
|
259
|
+
*
|
|
260
|
+
* ## Built-in User Entity
|
|
261
|
+
*
|
|
262
|
+
* Every app includes a built-in `User` entity that stores user account information. This entity has special security rules that can't be changed.
|
|
263
|
+
*
|
|
264
|
+
* Regular users can only read and update their own user record. With service role authentication, you can read, update, and delete any user. You can't create users using the entities module. Instead, use the functions of the {@link AuthModule | auth module} to invite or register new users.
|
|
265
|
+
*
|
|
266
|
+
* @example
|
|
267
|
+
* ```typescript
|
|
268
|
+
* // Get all records from the MyEntity entity
|
|
269
|
+
* // Get all records the current user has permissions to view
|
|
270
|
+
* const myRecords = await base44.entities.MyEntity.list();
|
|
271
|
+
* ```
|
|
272
|
+
*
|
|
273
|
+
* @example
|
|
274
|
+
* ```typescript
|
|
275
|
+
* // List all users (admin only)
|
|
276
|
+
* const allUsers = await base44.asServiceRole.entities.User.list();
|
|
277
|
+
* ```
|
|
278
|
+
*/
|
|
279
|
+
export interface EntitiesModule {
|
|
280
|
+
/**
|
|
281
|
+
* Access any entity by name.
|
|
282
|
+
*
|
|
283
|
+
* Use this to access entities defined in the app.
|
|
284
|
+
*
|
|
285
|
+
* @example
|
|
286
|
+
* ```typescript
|
|
287
|
+
* // Access entities dynamically
|
|
288
|
+
* base44.entities.MyEntity
|
|
289
|
+
* base44.entities.AnotherEntity
|
|
290
|
+
* ```
|
|
291
|
+
*/
|
|
292
|
+
[entityName: string]: EntityHandler;
|
|
293
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { AxiosInstance } from "axios";
|
|
2
|
+
import { FunctionsModule } from "./functions.types";
|
|
2
3
|
/**
|
|
3
|
-
* Creates the functions module for the Base44 SDK
|
|
4
|
-
*
|
|
5
|
-
* @param
|
|
6
|
-
* @
|
|
4
|
+
* Creates the functions module for the Base44 SDK.
|
|
5
|
+
*
|
|
6
|
+
* @param axios - Axios instance
|
|
7
|
+
* @param appId - Application ID
|
|
8
|
+
* @returns Functions module with methods to invoke custom backend functions
|
|
9
|
+
* @internal
|
|
7
10
|
*/
|
|
8
|
-
export declare function createFunctionsModule(axios: AxiosInstance, appId: string):
|
|
9
|
-
invoke(functionName: string, data: Record<string, any>): Promise<import("axios").AxiosResponse<any, any>>;
|
|
10
|
-
};
|
|
11
|
+
export declare function createFunctionsModule(axios: AxiosInstance, appId: string): FunctionsModule;
|
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Creates the functions module for the Base44 SDK
|
|
3
|
-
*
|
|
4
|
-
* @param
|
|
5
|
-
* @
|
|
2
|
+
* Creates the functions module for the Base44 SDK.
|
|
3
|
+
*
|
|
4
|
+
* @param axios - Axios instance
|
|
5
|
+
* @param appId - Application ID
|
|
6
|
+
* @returns Functions module with methods to invoke custom backend functions
|
|
7
|
+
* @internal
|
|
6
8
|
*/
|
|
7
9
|
export function createFunctionsModule(axios, appId) {
|
|
8
|
-
// Using nested Proxy objects to handle dynamic function names
|
|
9
10
|
return {
|
|
11
|
+
// Invoke a custom backend function by name
|
|
10
12
|
async invoke(functionName, data) {
|
|
11
13
|
// Validate input
|
|
12
14
|
if (typeof data === "string") {
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Functions module for invoking custom backend functions.
|
|
3
|
+
*
|
|
4
|
+
* This module allows you to invoke the custom backend functions defined in the app.
|
|
5
|
+
*
|
|
6
|
+
* This module is available to use with a client in all authentication modes:
|
|
7
|
+
*
|
|
8
|
+
* - **Anonymous or User authentication** (`base44.functions`): Functions are invoked with the current user's permissions. Anonymous users invoke functions without authentication, while authenticated users invoke functions with their authentication context.
|
|
9
|
+
* - **Service role authentication** (`base44.asServiceRole.functions`): Functions are invoked with elevated admin-level permissions. The function code receives a request with admin authentication context.
|
|
10
|
+
*/
|
|
11
|
+
export interface FunctionsModule {
|
|
12
|
+
/**
|
|
13
|
+
* Invokes a custom backend function by name.
|
|
14
|
+
*
|
|
15
|
+
* Calls a custom backend function deployed to the app.
|
|
16
|
+
* The function receives the provided data as named parameters and returns
|
|
17
|
+
* the result. If any parameter is a `File` object, the request will automatically be
|
|
18
|
+
* sent as `multipart/form-data`. Otherwise, it will be sent as JSON.
|
|
19
|
+
*
|
|
20
|
+
* @param functionName - The name of the function to invoke.
|
|
21
|
+
* @param data - An object containing named parameters for the function.
|
|
22
|
+
* @returns Promise resolving to the function's response. The `data` property contains the data returned by the function, if there is any.
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```typescript
|
|
26
|
+
* // Basic function call
|
|
27
|
+
* const result = await base44.functions.invoke('calculateTotal', {
|
|
28
|
+
* items: ['item1', 'item2'],
|
|
29
|
+
* discount: 0.1
|
|
30
|
+
* });
|
|
31
|
+
* console.log(result.data.total);
|
|
32
|
+
* ```
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* ```typescript
|
|
36
|
+
* // Function with file upload in React
|
|
37
|
+
* const handleFileUpload = async (event: React.ChangeEvent<HTMLInputElement>) => {
|
|
38
|
+
* const file = event.target.files?.[0];
|
|
39
|
+
* if (file) {
|
|
40
|
+
* const processedImage = await base44.functions.invoke('processImage', {
|
|
41
|
+
* image: file,
|
|
42
|
+
* filter: 'grayscale',
|
|
43
|
+
* quality: 80
|
|
44
|
+
* });
|
|
45
|
+
* }
|
|
46
|
+
* };
|
|
47
|
+
* ```
|
|
48
|
+
*/
|
|
49
|
+
invoke(functionName: string, data: Record<string, any>): Promise<any>;
|
|
50
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import { AxiosInstance } from "axios";
|
|
2
|
+
import { IntegrationsModule } from "./integrations.types";
|
|
2
3
|
/**
|
|
3
|
-
* Creates the integrations module for the Base44 SDK
|
|
4
|
-
*
|
|
5
|
-
* @param
|
|
6
|
-
* @
|
|
4
|
+
* Creates the integrations module for the Base44 SDK.
|
|
5
|
+
*
|
|
6
|
+
* @param axios - Axios instance
|
|
7
|
+
* @param appId - Application ID
|
|
8
|
+
* @returns Integrations module with dynamic access to integration endpoints
|
|
9
|
+
* @internal
|
|
7
10
|
*/
|
|
8
|
-
export declare function createIntegrationsModule(axios: AxiosInstance, appId: string):
|
|
11
|
+
export declare function createIntegrationsModule(axios: AxiosInstance, appId: string): IntegrationsModule;
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Creates the integrations module for the Base44 SDK
|
|
3
|
-
*
|
|
4
|
-
* @param
|
|
5
|
-
* @
|
|
2
|
+
* Creates the integrations module for the Base44 SDK.
|
|
3
|
+
*
|
|
4
|
+
* @param axios - Axios instance
|
|
5
|
+
* @param appId - Application ID
|
|
6
|
+
* @returns Integrations module with dynamic access to integration endpoints
|
|
7
|
+
* @internal
|
|
6
8
|
*/
|
|
7
9
|
export function createIntegrationsModule(axios, appId) {
|
|
8
|
-
// Using nested Proxy objects to handle dynamic package and endpoint names
|
|
9
10
|
return new Proxy({}, {
|
|
10
11
|
get(target, packageName) {
|
|
11
12
|
// Skip internal properties
|
|
@@ -24,6 +25,7 @@ export function createIntegrationsModule(axios, appId) {
|
|
|
24
25
|
return undefined;
|
|
25
26
|
}
|
|
26
27
|
// Return a function that calls the integration endpoint
|
|
28
|
+
// This allows: client.integrations.PackageName.EndpointName(data)
|
|
27
29
|
return async (data) => {
|
|
28
30
|
// Validate input
|
|
29
31
|
if (typeof data === "string") {
|