@depup/base44__sdk 0.8.22-depup.0

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.
Files changed (72) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +32 -0
  3. package/changes.json +14 -0
  4. package/dist/client.d.ts +96 -0
  5. package/dist/client.js +375 -0
  6. package/dist/client.types.d.ts +144 -0
  7. package/dist/client.types.js +1 -0
  8. package/dist/index.d.ts +16 -0
  9. package/dist/index.js +5 -0
  10. package/dist/modules/agents.d.ts +2 -0
  11. package/dist/modules/agents.js +77 -0
  12. package/dist/modules/agents.types.d.ts +377 -0
  13. package/dist/modules/agents.types.js +1 -0
  14. package/dist/modules/analytics.d.ts +20 -0
  15. package/dist/modules/analytics.js +277 -0
  16. package/dist/modules/analytics.types.d.ts +122 -0
  17. package/dist/modules/analytics.types.js +1 -0
  18. package/dist/modules/app-logs.d.ts +11 -0
  19. package/dist/modules/app-logs.js +27 -0
  20. package/dist/modules/app-logs.types.d.ts +46 -0
  21. package/dist/modules/app-logs.types.js +1 -0
  22. package/dist/modules/app.types.d.ts +142 -0
  23. package/dist/modules/app.types.js +1 -0
  24. package/dist/modules/auth.d.ts +13 -0
  25. package/dist/modules/auth.js +180 -0
  26. package/dist/modules/auth.types.d.ts +481 -0
  27. package/dist/modules/auth.types.js +1 -0
  28. package/dist/modules/connectors.d.ts +20 -0
  29. package/dist/modules/connectors.js +71 -0
  30. package/dist/modules/connectors.types.d.ts +296 -0
  31. package/dist/modules/connectors.types.js +1 -0
  32. package/dist/modules/custom-integrations.d.ts +11 -0
  33. package/dist/modules/custom-integrations.js +32 -0
  34. package/dist/modules/custom-integrations.types.d.ts +89 -0
  35. package/dist/modules/custom-integrations.types.js +1 -0
  36. package/dist/modules/entities.d.ts +20 -0
  37. package/dist/modules/entities.js +149 -0
  38. package/dist/modules/entities.types.d.ts +552 -0
  39. package/dist/modules/entities.types.js +1 -0
  40. package/dist/modules/functions.d.ts +12 -0
  41. package/dist/modules/functions.js +79 -0
  42. package/dist/modules/functions.types.d.ts +103 -0
  43. package/dist/modules/functions.types.js +1 -0
  44. package/dist/modules/integrations.d.ts +11 -0
  45. package/dist/modules/integrations.js +77 -0
  46. package/dist/modules/integrations.types.d.ts +413 -0
  47. package/dist/modules/integrations.types.js +1 -0
  48. package/dist/modules/sso.d.ts +12 -0
  49. package/dist/modules/sso.js +23 -0
  50. package/dist/modules/sso.types.d.ts +44 -0
  51. package/dist/modules/sso.types.js +1 -0
  52. package/dist/modules/types.d.ts +4 -0
  53. package/dist/modules/types.js +4 -0
  54. package/dist/modules/users.d.ts +16 -0
  55. package/dist/modules/users.js +23 -0
  56. package/dist/types.d.ts +72 -0
  57. package/dist/types.js +1 -0
  58. package/dist/utils/auth-utils.d.ts +117 -0
  59. package/dist/utils/auth-utils.js +189 -0
  60. package/dist/utils/auth-utils.types.d.ts +146 -0
  61. package/dist/utils/auth-utils.types.js +1 -0
  62. package/dist/utils/axios-client.d.ts +100 -0
  63. package/dist/utils/axios-client.js +193 -0
  64. package/dist/utils/axios-client.types.d.ts +28 -0
  65. package/dist/utils/axios-client.types.js +1 -0
  66. package/dist/utils/common.d.ts +3 -0
  67. package/dist/utils/common.js +6 -0
  68. package/dist/utils/sharedInstance.d.ts +1 -0
  69. package/dist/utils/sharedInstance.js +15 -0
  70. package/dist/utils/socket-utils.d.ts +47 -0
  71. package/dist/utils/socket-utils.js +115 -0
  72. package/package.json +87 -0
@@ -0,0 +1,552 @@
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
+ * @typeParam T - The entity type for the data field. Defaults to `any`.
9
+ */
10
+ export interface RealtimeEvent<T = any> {
11
+ /** The type of change that occurred */
12
+ type: RealtimeEventType;
13
+ /** The entity data */
14
+ data: T;
15
+ /** The unique identifier of the affected entity */
16
+ id: string;
17
+ /** ISO 8601 timestamp of when the event occurred */
18
+ timestamp: string;
19
+ }
20
+ /**
21
+ * Callback function invoked when a realtime event occurs.
22
+ *
23
+ * @typeParam T - The entity type for the event data. Defaults to `any`.
24
+ */
25
+ export type RealtimeCallback<T = any> = (event: RealtimeEvent<T>) => void;
26
+ /**
27
+ * Result returned when deleting a single entity.
28
+ */
29
+ export interface DeleteResult {
30
+ /** Whether the deletion was successful. */
31
+ success: boolean;
32
+ }
33
+ /**
34
+ * Result returned when deleting multiple entities.
35
+ */
36
+ export interface DeleteManyResult {
37
+ /** Whether the deletion was successful. */
38
+ success: boolean;
39
+ /** Number of entities that were deleted. */
40
+ deleted: number;
41
+ }
42
+ /**
43
+ * Result returned when updating multiple entities via a query.
44
+ */
45
+ export interface UpdateManyResult {
46
+ /** Whether the operation was successful. */
47
+ success: boolean;
48
+ /** Number of entities that were updated. */
49
+ updated: number;
50
+ /** Whether there are more entities matching the query that were not updated in this batch. When `true`, call `updateMany` again with the same query to update the next batch. */
51
+ has_more: boolean;
52
+ }
53
+ /**
54
+ * Result returned when importing entities from a file.
55
+ *
56
+ * @typeParam T - The entity type for imported records. Defaults to `any`.
57
+ */
58
+ export interface ImportResult<T = any> {
59
+ /** Status of the import operation. */
60
+ status: "success" | "error";
61
+ /** Details message, e.g., "Successfully imported 3 entities with RLS enforcement". */
62
+ details: string | null;
63
+ /** Array of created entity objects when successful, or null on error. */
64
+ output: T[] | null;
65
+ }
66
+ /**
67
+ * Sort field type for entity queries.
68
+ *
69
+ * Accepts any field name from the entity type with an optional prefix:
70
+ * - `'+'` prefix or no prefix: ascending sort
71
+ * - `'-'` prefix: descending sort
72
+ *
73
+ * @typeParam T - The entity type to derive sortable fields from.
74
+ *
75
+ * @example
76
+ * ```typescript
77
+ * // Specify sort direction by prefixing field names with + or -
78
+ * // Ascending sort
79
+ * 'created_date'
80
+ * '+created_date'
81
+ *
82
+ * // Descending sort
83
+ * '-created_date'
84
+ * ```
85
+ */
86
+ export type SortField<T> = (keyof T & string) | `+${keyof T & string}` | `-${keyof T & string}`;
87
+ /**
88
+ * Fields added by the server to every entity record, such as `id`, `created_date`, `updated_date`, and `created_by`.
89
+ */
90
+ interface ServerEntityFields {
91
+ /** Unique identifier of the record */
92
+ id: string;
93
+ /** ISO 8601 timestamp when the record was created */
94
+ created_date: string;
95
+ /** ISO 8601 timestamp when the record was last updated */
96
+ updated_date: string;
97
+ /** Email of the user who created the record (may be hidden in some responses) */
98
+ created_by?: string | null;
99
+ /** ID of the user who created the record */
100
+ created_by_id?: string | null;
101
+ /** Whether the record is sample/seed data */
102
+ is_sample?: boolean;
103
+ }
104
+ /**
105
+ * Registry mapping entity names to their TypeScript types. The [`types generate`](/developers/references/cli/commands/types-generate) command fills this registry, then [`EntityRecord`](#entityrecord) adds server fields.
106
+ */
107
+ export interface EntityTypeRegistry {
108
+ }
109
+ /**
110
+ * Combines the [`EntityTypeRegistry`](#entitytyperegistry) schemas with server fields like `id`, `created_date`, and `updated_date` to give the complete record type for each entity. Use this when you need to type variables holding entity data.
111
+ *
112
+ * @example
113
+ * ```typescript
114
+ * // Using EntityRecord to get the complete type for an entity
115
+ * // Combine your schema with server fields (id, created_date, etc.)
116
+ * type TaskRecord = EntityRecord['Task'];
117
+ *
118
+ * const task: TaskRecord = await base44.entities.Task.create({
119
+ * title: 'My task',
120
+ * status: 'pending'
121
+ * });
122
+ *
123
+ * // Task now includes both your fields and server fields:
124
+ * console.log(task.id); // Server field
125
+ * console.log(task.created_date); // Server field
126
+ * console.log(task.title); // Your field
127
+ * ```
128
+ */
129
+ export type EntityRecord = {
130
+ [K in keyof EntityTypeRegistry]: EntityTypeRegistry[K] & ServerEntityFields;
131
+ };
132
+ /**
133
+ * Entity handler providing CRUD operations for a specific entity type.
134
+ *
135
+ * Each entity in the app gets a handler with these methods for managing data.
136
+ *
137
+ * @typeParam T - The entity type. Defaults to `any` for backward compatibility.
138
+ */
139
+ export interface EntityHandler<T = any> {
140
+ /**
141
+ * Lists records with optional pagination and sorting.
142
+ *
143
+ * Retrieves all records of this type with support for sorting,
144
+ * pagination, and field selection.
145
+ *
146
+ * **Note:** The maximum limit is 5,000 items per request.
147
+ *
148
+ * @typeParam K - The fields to include in the response. Defaults to all fields.
149
+ * @param sort - Sort parameter, such as `'-created_date'` for descending. Defaults to `'-created_date'`.
150
+ * @param limit - Maximum number of results to return. Defaults to `50`.
151
+ * @param skip - Number of results to skip for pagination. Defaults to `0`.
152
+ * @param fields - Array of field names to include in the response. Defaults to all fields.
153
+ * @returns Promise resolving to an array of records with selected fields.
154
+ *
155
+ * @example
156
+ * ```typescript
157
+ * // Get all records
158
+ * const records = await base44.entities.MyEntity.list();
159
+ * ```
160
+ *
161
+ * @example
162
+ * ```typescript
163
+ * // Get first 10 records sorted by date
164
+ * const recentRecords = await base44.entities.MyEntity.list('-created_date', 10);
165
+ * ```
166
+ *
167
+ * @example
168
+ * ```typescript
169
+ * // Get paginated results
170
+ * // Skip first 20, get next 10
171
+ * const page3 = await base44.entities.MyEntity.list('-created_date', 10, 20);
172
+ * ```
173
+ *
174
+ * @example
175
+ * ```typescript
176
+ * // Get only specific fields
177
+ * const fields = await base44.entities.MyEntity.list('-created_date', 10, 0, ['name', 'status']);
178
+ * ```
179
+ */
180
+ list<K extends keyof T = keyof T>(sort?: SortField<T>, limit?: number, skip?: number, fields?: K[]): Promise<Pick<T, K>[]>;
181
+ /**
182
+ * Filters records based on a query.
183
+ *
184
+ * Retrieves records that match specific criteria with support for
185
+ * sorting, pagination, and field selection.
186
+ *
187
+ * **Note:** The maximum limit is 5,000 items per request.
188
+ *
189
+ * @typeParam K - The fields to include in the response. Defaults to all fields.
190
+ * @param query - Query object with field-value pairs. Each key should be a field name
191
+ * from your entity schema, and each value is the criteria to match. Records matching all
192
+ * specified criteria are returned. Field names are case-sensitive.
193
+ * @param sort - Sort parameter, such as `'-created_date'` for descending. Defaults to `'-created_date'`.
194
+ * @param limit - Maximum number of results to return. Defaults to `50`.
195
+ * @param skip - Number of results to skip for pagination. Defaults to `0`.
196
+ * @param fields - Array of field names to include in the response. Defaults to all fields.
197
+ * @returns Promise resolving to an array of filtered records with selected fields.
198
+ *
199
+ * @example
200
+ * ```typescript
201
+ * // Filter by single field
202
+ * const activeRecords = await base44.entities.MyEntity.filter({
203
+ * status: 'active'
204
+ * });
205
+ * ```
206
+ *
207
+ * @example
208
+ * ```typescript
209
+ * // Filter by multiple fields
210
+ * const filteredRecords = await base44.entities.MyEntity.filter({
211
+ * priority: 'high',
212
+ * status: 'active'
213
+ * });
214
+ * ```
215
+ *
216
+ * @example
217
+ * ```typescript
218
+ * // Filter with sorting and pagination
219
+ * const results = await base44.entities.MyEntity.filter(
220
+ * { status: 'active' },
221
+ * '-created_date',
222
+ * 20,
223
+ * 0
224
+ * );
225
+ * ```
226
+ *
227
+ * @example
228
+ * ```typescript
229
+ * // Filter with specific fields
230
+ * const fields = await base44.entities.MyEntity.filter(
231
+ * { priority: 'high' },
232
+ * '-created_date',
233
+ * 10,
234
+ * 0,
235
+ * ['name', 'priority']
236
+ * );
237
+ * ```
238
+ */
239
+ filter<K extends keyof T = keyof T>(query: Partial<T>, sort?: SortField<T>, limit?: number, skip?: number, fields?: K[]): Promise<Pick<T, K>[]>;
240
+ /**
241
+ * Gets a single record by ID.
242
+ *
243
+ * Retrieves a specific record using its unique identifier.
244
+ *
245
+ * @param id - The unique identifier of the record.
246
+ * @returns Promise resolving to the record.
247
+ *
248
+ * @example
249
+ * ```typescript
250
+ * // Get record by ID
251
+ * const record = await base44.entities.MyEntity.get('entity-123');
252
+ * console.log(record.name);
253
+ * ```
254
+ */
255
+ get(id: string): Promise<T>;
256
+ /**
257
+ * Creates a new record.
258
+ *
259
+ * Creates a new record with the provided data.
260
+ *
261
+ * @param data - Object containing the record data.
262
+ * @returns Promise resolving to the created record.
263
+ *
264
+ * @example
265
+ * ```typescript
266
+ * // Create a new record
267
+ * const newRecord = await base44.entities.MyEntity.create({
268
+ * name: 'My Item',
269
+ * status: 'active',
270
+ * priority: 'high'
271
+ * });
272
+ * console.log('Created record with ID:', newRecord.id);
273
+ * ```
274
+ */
275
+ create(data: Partial<T>): Promise<T>;
276
+ /**
277
+ * Updates an existing record.
278
+ *
279
+ * Updates a record by ID with the provided data. Only the fields
280
+ * included in the data object will be updated.
281
+ *
282
+ * @param id - The unique identifier of the record to update.
283
+ * @param data - Object containing the fields to update.
284
+ * @returns Promise resolving to the updated record.
285
+ *
286
+ * @example
287
+ * ```typescript
288
+ * // Update single field
289
+ * const updated = await base44.entities.MyEntity.update('entity-123', {
290
+ * status: 'completed'
291
+ * });
292
+ * ```
293
+ *
294
+ * @example
295
+ * ```typescript
296
+ * // Update multiple fields
297
+ * const updated = await base44.entities.MyEntity.update('entity-123', {
298
+ * name: 'Updated name',
299
+ * priority: 'low',
300
+ * status: 'active'
301
+ * });
302
+ * ```
303
+ */
304
+ update(id: string, data: Partial<T>): Promise<T>;
305
+ /**
306
+ * Deletes a single record by ID.
307
+ *
308
+ * Permanently removes a record from the database.
309
+ *
310
+ * @param id - The unique identifier of the record to delete.
311
+ * @returns Promise resolving to the deletion result.
312
+ *
313
+ * @example
314
+ * ```typescript
315
+ * // Delete a record
316
+ * const result = await base44.entities.MyEntity.delete('entity-123');
317
+ * console.log('Deleted:', result.success);
318
+ * ```
319
+ */
320
+ delete(id: string): Promise<DeleteResult>;
321
+ /**
322
+ * Deletes multiple records matching a query.
323
+ *
324
+ * Permanently removes all records that match the provided query.
325
+ *
326
+ * @param query - Query object with field-value pairs. Each key should be a field name
327
+ * from your entity schema, and each value is the criteria to match. Records matching all
328
+ * specified criteria will be deleted. Field names are case-sensitive.
329
+ * @returns Promise resolving to the deletion result.
330
+ *
331
+ * @example
332
+ * ```typescript
333
+ * // Delete by multiple criteria
334
+ * const result = await base44.entities.MyEntity.deleteMany({
335
+ * status: 'completed',
336
+ * priority: 'low'
337
+ * });
338
+ * console.log('Deleted:', result.deleted);
339
+ * ```
340
+ */
341
+ deleteMany(query: Partial<T>): Promise<DeleteManyResult>;
342
+ /**
343
+ * Creates multiple records in a single request.
344
+ *
345
+ * Efficiently creates multiple records at once. This is faster
346
+ * than creating them individually.
347
+ *
348
+ * @param data - Array of record data objects.
349
+ * @returns Promise resolving to an array of created records.
350
+ *
351
+ * @example
352
+ * ```typescript
353
+ * // Create multiple records at once
354
+ * const result = await base44.entities.MyEntity.bulkCreate([
355
+ * { name: 'Item 1', status: 'active' },
356
+ * { name: 'Item 2', status: 'active' },
357
+ * { name: 'Item 3', status: 'completed' }
358
+ * ]);
359
+ * ```
360
+ */
361
+ bulkCreate(data: Partial<T>[]): Promise<T[]>;
362
+ /**
363
+ * Updates multiple records matching a query using a MongoDB update operator.
364
+ *
365
+ * Applies the same update operation to all records matching the query.
366
+ * The `data` parameter must contain one or more MongoDB update operators
367
+ * (e.g., `$set`, `$inc`, `$push`). Multiple operators can be combined in a
368
+ * single call, but each field may only appear in one operator.
369
+ *
370
+ * Results are batched in groups of up to 500 — when `has_more` is `true`
371
+ * in the response, call `updateMany` again with the same query to update
372
+ * the next batch.
373
+ *
374
+ * @param query - Query object to filter which records to update. Records matching all
375
+ * specified criteria will be updated.
376
+ * @param data - Update operation object containing one or more MongoDB update operators.
377
+ * Each field may only appear in one operator per call.
378
+ * Supported operators: `$set`, `$rename`, `$unset`, `$inc`, `$mul`, `$min`, `$max`,
379
+ * `$currentDate`, `$addToSet`, `$push`, `$pull`.
380
+ * @returns Promise resolving to the update result.
381
+ *
382
+ * @example
383
+ * ```typescript
384
+ * // Set status to 'archived' for all completed records
385
+ * const result = await base44.entities.MyEntity.updateMany(
386
+ * { status: 'completed' },
387
+ * { $set: { status: 'archived' } }
388
+ * );
389
+ * console.log(`Updated ${result.updated} records`);
390
+ * ```
391
+ *
392
+ * @example
393
+ * ```typescript
394
+ * // Combine multiple operators in a single call
395
+ * const result = await base44.entities.MyEntity.updateMany(
396
+ * { category: 'sales' },
397
+ * { $set: { status: 'done' }, $inc: { view_count: 1 } }
398
+ * );
399
+ * ```
400
+ *
401
+ * @example
402
+ * ```typescript
403
+ * // Handle batched updates for large datasets
404
+ * let hasMore = true;
405
+ * let totalUpdated = 0;
406
+ * while (hasMore) {
407
+ * const result = await base44.entities.MyEntity.updateMany(
408
+ * { status: 'pending' },
409
+ * { $set: { status: 'processed' } }
410
+ * );
411
+ * totalUpdated += result.updated;
412
+ * hasMore = result.has_more;
413
+ * }
414
+ * ```
415
+ */
416
+ updateMany(query: Partial<T>, data: Record<string, Record<string, any>>): Promise<UpdateManyResult>;
417
+ /**
418
+ * Updates multiple records in a single request, each with its own update data.
419
+ *
420
+ * Unlike `updateMany` which applies the same update to all matching records,
421
+ * `bulkUpdate` allows different updates for each record. Each item in the
422
+ * array must include an `id` field identifying which record to update.
423
+ *
424
+ * **Note:** Maximum 500 items per request.
425
+ *
426
+ * @param data - Array of update objects (max 500). Each object must have an `id` field
427
+ * and any number of fields to update.
428
+ * @returns Promise resolving to an array of updated records.
429
+ *
430
+ * @example
431
+ * ```typescript
432
+ * // Update multiple records with different data
433
+ * const updated = await base44.entities.MyEntity.bulkUpdate([
434
+ * { id: 'entity-1', status: 'paid', amount: 999 },
435
+ * { id: 'entity-2', status: 'cancelled' },
436
+ * { id: 'entity-3', name: 'Renamed Item' }
437
+ * ]);
438
+ * ```
439
+ */
440
+ bulkUpdate(data: (Partial<T> & {
441
+ id: string;
442
+ })[]): Promise<T[]>;
443
+ /**
444
+ * Imports records from a file.
445
+ *
446
+ * Imports records from a file, typically CSV or similar format.
447
+ * The file format should match your entity structure. Requires a browser environment and can't be used in the backend.
448
+ *
449
+ * @param file - File object to import.
450
+ * @returns Promise resolving to the import result containing status, details, and created records.
451
+ *
452
+ * @example
453
+ * ```typescript
454
+ * // Import records from file in React
455
+ * const handleFileImport = async (event: React.ChangeEvent<HTMLInputElement>) => {
456
+ * const file = event.target.files?.[0];
457
+ * if (file) {
458
+ * const result = await base44.entities.MyEntity.importEntities(file);
459
+ * if (result.status === 'success' && result.output) {
460
+ * console.log(`Imported ${result.output.length} records`);
461
+ * }
462
+ * }
463
+ * };
464
+ * ```
465
+ */
466
+ importEntities(file: File): Promise<ImportResult<T>>;
467
+ /**
468
+ * Subscribes to realtime updates for all records of this entity type.
469
+ *
470
+ * Establishes a WebSocket connection to receive instant updates when any
471
+ * record is created, updated, or deleted. Returns an unsubscribe function
472
+ * to clean up the connection.
473
+ *
474
+ * @param callback - Callback function called when an entity changes. The callback receives an event object with the following properties:
475
+ * - `type`: The type of change that occurred - `'create'`, `'update'`, or `'delete'`.
476
+ * - `data`: The entity data after the change.
477
+ * - `id`: The unique identifier of the affected entity.
478
+ * - `timestamp`: ISO 8601 timestamp of when the event occurred.
479
+ * @returns Unsubscribe function to stop receiving updates.
480
+ *
481
+ * @example
482
+ * ```typescript
483
+ * // Subscribe to all Task changes
484
+ * const unsubscribe = base44.entities.Task.subscribe((event) => {
485
+ * console.log(`Task ${event.id} was ${event.type}d:`, event.data);
486
+ * });
487
+ *
488
+ * // Later, clean up the subscription
489
+ * unsubscribe();
490
+ * ```
491
+ */
492
+ subscribe(callback: RealtimeCallback<T>): () => void;
493
+ }
494
+ /**
495
+ * Typed entities module - maps registry keys to typed handlers (full record type).
496
+ */
497
+ type TypedEntitiesModule = {
498
+ [K in keyof EntityTypeRegistry]: EntityHandler<EntityRecord[K]>;
499
+ };
500
+ /**
501
+ * Dynamic entities module - allows any entity name with untyped handler.
502
+ */
503
+ type DynamicEntitiesModule = {
504
+ [entityName: string]: EntityHandler<any>;
505
+ };
506
+ /**
507
+ * Entities module for managing app data.
508
+ *
509
+ * This module provides dynamic access to all entities in the app.
510
+ * Each entity gets a handler with full CRUD operations and additional utility methods.
511
+ *
512
+ * Entities are accessed dynamically using the pattern:
513
+ * `base44.entities.EntityName.method()`
514
+ *
515
+ * This module is available to use with a client in all authentication modes:
516
+ *
517
+ * - **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.
518
+ * - **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.
519
+ *
520
+ * ## Entity Handlers
521
+ *
522
+ * An entity handler is the object you get when you access an entity through `base44.entities.EntityName`. Every entity in your app automatically gets a handler with CRUD methods for managing records.
523
+ *
524
+ * For example, `base44.entities.Task` is an entity handler for Task records, and `base44.entities.User` is an entity handler for User records. Each handler provides methods like `list()`, `create()`, `update()`, and `delete()`.
525
+ *
526
+ * You don't need to instantiate or import entity handlers. They're automatically available for every entity you create in your app.
527
+ *
528
+ * ## Built-in User Entity
529
+ *
530
+ * Every app includes a built-in `User` entity that stores user account information. This entity has special security rules that can't be changed.
531
+ *
532
+ * 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.
533
+ *
534
+ * ## Generated Types
535
+ *
536
+ * If you're working in a TypeScript project, you can generate types from your entity schemas to get autocomplete and type checking on all entity methods. See the [Dynamic Types](/developers/references/sdk/getting-started/dynamic-types) guide to get started.
537
+ *
538
+ * @example
539
+ * ```typescript
540
+ * // Get all records from the MyEntity entity
541
+ * // Get all records the current user has permissions to view
542
+ * const myRecords = await base44.entities.MyEntity.list();
543
+ * ```
544
+ *
545
+ * @example
546
+ * ```typescript
547
+ * // List all users (admin only)
548
+ * const allUsers = await base44.asServiceRole.entities.User.list();
549
+ * ```
550
+ */
551
+ export type EntitiesModule = TypedEntitiesModule & DynamicEntitiesModule;
552
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,12 @@
1
+ import { AxiosInstance } from "axios";
2
+ import { FunctionsModule, FunctionsModuleConfig } from "./functions.types";
3
+ /**
4
+ * Creates the functions module for the Base44 SDK.
5
+ *
6
+ * @param axios - Axios instance
7
+ * @param appId - Application ID
8
+ * @param config - Optional configuration for fetch functionality
9
+ * @returns Functions module with methods to invoke custom backend functions
10
+ * @internal
11
+ */
12
+ export declare function createFunctionsModule(axios: AxiosInstance, appId: string, config?: FunctionsModuleConfig): FunctionsModule;
@@ -0,0 +1,79 @@
1
+ /**
2
+ * Creates the functions module for the Base44 SDK.
3
+ *
4
+ * @param axios - Axios instance
5
+ * @param appId - Application ID
6
+ * @param config - Optional configuration for fetch functionality
7
+ * @returns Functions module with methods to invoke custom backend functions
8
+ * @internal
9
+ */
10
+ export function createFunctionsModule(axios, appId, config) {
11
+ const joinBaseUrl = (base, path) => {
12
+ if (!base)
13
+ return path;
14
+ return `${String(base).replace(/\/$/, "")}${path}`;
15
+ };
16
+ const toHeaders = (inputHeaders) => {
17
+ const headers = new Headers();
18
+ // Get auth headers from the getter function if provided
19
+ if (config === null || config === void 0 ? void 0 : config.getAuthHeaders) {
20
+ const authHeaders = config.getAuthHeaders();
21
+ Object.entries(authHeaders).forEach(([key, value]) => {
22
+ if (value !== undefined && value !== null) {
23
+ headers.set(key, String(value));
24
+ }
25
+ });
26
+ }
27
+ if (inputHeaders) {
28
+ new Headers(inputHeaders).forEach((value, key) => {
29
+ headers.set(key, value);
30
+ });
31
+ }
32
+ return headers;
33
+ };
34
+ return {
35
+ // Invoke a custom backend function by name
36
+ async invoke(functionName, data) {
37
+ // Validate input
38
+ if (typeof data === "string") {
39
+ throw new Error(`Function ${functionName} must receive an object with named parameters, received: ${data}`);
40
+ }
41
+ let formData;
42
+ let contentType;
43
+ // Handle file uploads with FormData
44
+ if (data instanceof FormData ||
45
+ (data && Object.values(data).some((value) => value instanceof File))) {
46
+ formData = new FormData();
47
+ Object.keys(data).forEach((key) => {
48
+ if (data[key] instanceof File) {
49
+ formData.append(key, data[key], data[key].name);
50
+ }
51
+ else if (typeof data[key] === "object" && data[key] !== null) {
52
+ formData.append(key, JSON.stringify(data[key]));
53
+ }
54
+ else {
55
+ formData.append(key, data[key]);
56
+ }
57
+ });
58
+ contentType = "multipart/form-data";
59
+ }
60
+ else {
61
+ formData = data;
62
+ contentType = "application/json";
63
+ }
64
+ return axios.post(`/apps/${appId}/functions/${functionName}`, formData || data, { headers: { "Content-Type": contentType } });
65
+ },
66
+ // Fetch a backend function endpoint directly.
67
+ async fetch(path, init = {}) {
68
+ const normalizedPath = path.startsWith("/") ? path : `/${path}`;
69
+ const primaryPath = `/functions${normalizedPath}`;
70
+ const headers = toHeaders(init.headers);
71
+ const requestInit = {
72
+ ...init,
73
+ headers,
74
+ };
75
+ const response = await fetch(joinBaseUrl(config === null || config === void 0 ? void 0 : config.baseURL, primaryPath), requestInit);
76
+ return response;
77
+ },
78
+ };
79
+ }