@doany-ai/sdk 0.1.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 (75) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +60 -0
  3. package/dist/client.d.ts +96 -0
  4. package/dist/client.js +395 -0
  5. package/dist/client.types.d.ts +149 -0
  6. package/dist/client.types.js +1 -0
  7. package/dist/index.d.ts +17 -0
  8. package/dist/index.js +5 -0
  9. package/dist/modules/agents.d.ts +2 -0
  10. package/dist/modules/agents.js +89 -0
  11. package/dist/modules/agents.types.d.ts +397 -0
  12. package/dist/modules/agents.types.js +1 -0
  13. package/dist/modules/ai-gateway.d.ts +2 -0
  14. package/dist/modules/ai-gateway.js +13 -0
  15. package/dist/modules/ai-gateway.types.d.ts +88 -0
  16. package/dist/modules/ai-gateway.types.js +1 -0
  17. package/dist/modules/analytics.d.ts +20 -0
  18. package/dist/modules/analytics.js +284 -0
  19. package/dist/modules/analytics.types.d.ts +122 -0
  20. package/dist/modules/analytics.types.js +1 -0
  21. package/dist/modules/app-logs.d.ts +11 -0
  22. package/dist/modules/app-logs.js +27 -0
  23. package/dist/modules/app-logs.types.d.ts +46 -0
  24. package/dist/modules/app-logs.types.js +1 -0
  25. package/dist/modules/app.types.d.ts +142 -0
  26. package/dist/modules/app.types.js +1 -0
  27. package/dist/modules/auth.d.ts +13 -0
  28. package/dist/modules/auth.js +240 -0
  29. package/dist/modules/auth.types.d.ts +517 -0
  30. package/dist/modules/auth.types.js +1 -0
  31. package/dist/modules/connectors.d.ts +20 -0
  32. package/dist/modules/connectors.js +98 -0
  33. package/dist/modules/connectors.types.d.ts +376 -0
  34. package/dist/modules/connectors.types.js +1 -0
  35. package/dist/modules/custom-integrations.d.ts +11 -0
  36. package/dist/modules/custom-integrations.js +32 -0
  37. package/dist/modules/custom-integrations.types.d.ts +89 -0
  38. package/dist/modules/custom-integrations.types.js +1 -0
  39. package/dist/modules/entities.d.ts +20 -0
  40. package/dist/modules/entities.js +163 -0
  41. package/dist/modules/entities.types.d.ts +702 -0
  42. package/dist/modules/entities.types.js +1 -0
  43. package/dist/modules/functions.d.ts +12 -0
  44. package/dist/modules/functions.js +79 -0
  45. package/dist/modules/functions.types.d.ts +150 -0
  46. package/dist/modules/functions.types.js +1 -0
  47. package/dist/modules/integrations.d.ts +11 -0
  48. package/dist/modules/integrations.js +77 -0
  49. package/dist/modules/integrations.types.d.ts +418 -0
  50. package/dist/modules/integrations.types.js +1 -0
  51. package/dist/modules/sso.d.ts +11 -0
  52. package/dist/modules/sso.js +22 -0
  53. package/dist/modules/sso.types.d.ts +68 -0
  54. package/dist/modules/sso.types.js +1 -0
  55. package/dist/modules/types.d.ts +5 -0
  56. package/dist/modules/types.js +5 -0
  57. package/dist/modules/users.d.ts +16 -0
  58. package/dist/modules/users.js +23 -0
  59. package/dist/types.d.ts +72 -0
  60. package/dist/types.js +1 -0
  61. package/dist/utils/auth-utils.d.ts +117 -0
  62. package/dist/utils/auth-utils.js +189 -0
  63. package/dist/utils/auth-utils.types.d.ts +146 -0
  64. package/dist/utils/auth-utils.types.js +1 -0
  65. package/dist/utils/axios-client.d.ts +100 -0
  66. package/dist/utils/axios-client.js +202 -0
  67. package/dist/utils/axios-client.types.d.ts +28 -0
  68. package/dist/utils/axios-client.types.js +1 -0
  69. package/dist/utils/common.d.ts +4 -0
  70. package/dist/utils/common.js +11 -0
  71. package/dist/utils/sharedInstance.d.ts +1 -0
  72. package/dist/utils/sharedInstance.js +15 -0
  73. package/dist/utils/socket-utils.d.ts +47 -0
  74. package/dist/utils/socket-utils.js +170 -0
  75. package/package.json +54 -0
@@ -0,0 +1,702 @@
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 using 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
+ * Entity filter query type system.
89
+ *
90
+ * `EntityFilterQuery<T>` keeps field names tied to the entity schema while
91
+ * allowing Base44's documented filtering syntax. Each field can use an exact
92
+ * value, `null`, an array shorthand for matching any listed value, or a
93
+ * field-level operator object. Root-level `$and`, `$or`, and `$nor` combine
94
+ * nested filter queries.
95
+ *
96
+ * Operator values are typed from the field they filter where possible. For
97
+ * example, numeric fields accept numeric comparison values, string fields
98
+ * accept `$regex`, and array fields accept `$all` and `$size`.
99
+ */
100
+ /**
101
+ * Value accepted when filtering an entity field.
102
+ *
103
+ * Supports exact matches, `null`, array shorthand for matching any of the
104
+ * provided values, and documented MongoDB-style query operators.
105
+ *
106
+ * @typeParam T - Field value type.
107
+ */
108
+ export type EntityFilterValue<T> = EntityFilterComparable<T> | EntityFilterComparable<T>[] | EntityFilterOperators<T>;
109
+ /**
110
+ * MongoDB-style query operators accepted for a single entity field.
111
+ *
112
+ * @typeParam T - Field value type.
113
+ */
114
+ export type EntityFilterOperators<T> = EntityFilterCommonOperators<T> & {
115
+ /** Negates another field-level filter expression. */
116
+ $not?: EntityFilterCommonOperators<T>;
117
+ };
118
+ type EntityFilterComparable<T> = Exclude<T, undefined> | null;
119
+ type EntityFilterCommonOperators<T> = {
120
+ $eq?: EntityFilterComparable<T>;
121
+ $ne?: EntityFilterComparable<T>;
122
+ $gt?: EntityFilterComparable<T>;
123
+ $gte?: EntityFilterComparable<T>;
124
+ $lt?: EntityFilterComparable<T>;
125
+ $lte?: EntityFilterComparable<T>;
126
+ $in?: EntityFilterComparable<T>[];
127
+ $nin?: EntityFilterComparable<T>[];
128
+ $exists?: boolean;
129
+ } & EntityFilterStringOperators<T> & EntityFilterArrayOperators<T>;
130
+ type EntityFilterStringOperators<T> = Extract<Exclude<T, undefined | null>, string> extends never ? {} : {
131
+ $regex?: string;
132
+ };
133
+ type EntityFilterArrayElement<T> = T extends readonly (infer U)[] ? U : never;
134
+ type EntityFilterArrayOperators<T> = [
135
+ EntityFilterArrayElement<Exclude<T, undefined | null>>
136
+ ] extends [never] ? {} : {
137
+ $all?: EntityFilterArrayElement<Exclude<T, undefined | null>>[];
138
+ $size?: number;
139
+ };
140
+ /**
141
+ * Query object accepted by entity filtering methods.
142
+ *
143
+ * Field keys are typed from the entity schema. `$and`, `$or`, and `$nor`
144
+ * combine nested filter queries at the root level.
145
+ *
146
+ * @typeParam T - Entity record type.
147
+ */
148
+ export type EntityFilterQuery<T> = {
149
+ [K in keyof T]?: EntityFilterValue<T[K]>;
150
+ } & {
151
+ $and?: EntityFilterQuery<T>[];
152
+ $or?: EntityFilterQuery<T>[];
153
+ $nor?: EntityFilterQuery<T>[];
154
+ };
155
+ /**
156
+ * Fields added by the server to every entity record, such as `id`, `created_date`, `updated_date`, and `created_by`.
157
+ */
158
+ interface ServerEntityFields {
159
+ /** Unique identifier of the record */
160
+ id: string;
161
+ /** ISO 8601 timestamp when the record was created */
162
+ created_date: string;
163
+ /** ISO 8601 timestamp when the record was last updated */
164
+ updated_date: string;
165
+ /** Email of the user who created the record (may be hidden in some responses) */
166
+ created_by?: string | null;
167
+ /** ID of the user who created the record */
168
+ created_by_id?: string | null;
169
+ /** Whether the record is sample/seed data */
170
+ is_sample?: boolean;
171
+ }
172
+ /**
173
+ * 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.
174
+ */
175
+ export interface EntityTypeRegistry {
176
+ }
177
+ /**
178
+ * 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.
179
+ *
180
+ * @example
181
+ * ```typescript
182
+ * // Using EntityRecord to get the complete type for an entity
183
+ * // Combine your schema with server fields (id, created_date, etc.)
184
+ * type TaskRecord = EntityRecord['Task'];
185
+ *
186
+ * const task: TaskRecord = await base44.entities.Task.create({
187
+ * title: 'My task',
188
+ * status: 'pending'
189
+ * });
190
+ *
191
+ * // Task now includes both your fields and server fields:
192
+ * console.log(task.id); // Server field
193
+ * console.log(task.created_date); // Server field
194
+ * console.log(task.title); // Your field
195
+ * ```
196
+ */
197
+ export type EntityRecord = {
198
+ [K in keyof EntityTypeRegistry]: EntityTypeRegistry[K] & ServerEntityFields;
199
+ };
200
+ /**
201
+ * Entity handler providing CRUD operations for a specific entity type.
202
+ *
203
+ * Each entity in the app gets a handler with these methods for managing data.
204
+ *
205
+ * @typeParam T - The entity type. Defaults to `any` for backward compatibility.
206
+ */
207
+ export interface EntityHandler<T = any> {
208
+ /**
209
+ * Lists records with optional pagination and sorting.
210
+ *
211
+ * Retrieves all records of this type with support for sorting,
212
+ * pagination, and field selection.
213
+ *
214
+ * **Note:** The maximum limit is 5,000 items per request.
215
+ *
216
+ * @typeParam K - The fields to include in the response. Defaults to all fields.
217
+ * @param sort - Sort parameter, such as `'-created_date'` for descending. Defaults to `'-created_date'`.
218
+ * @param limit - Maximum number of results to return. Defaults to `50`.
219
+ * @param skip - Number of results to skip for pagination. Defaults to `0`.
220
+ * @param fields - Array of field names to include in the response. Defaults to all fields.
221
+ * @returns Promise resolving to an array of records with selected fields.
222
+ *
223
+ * @example
224
+ * ```typescript
225
+ * // Get all records
226
+ * const records = await base44.entities.MyEntity.list();
227
+ * ```
228
+ *
229
+ * @example
230
+ * ```typescript
231
+ * // Get first 10 records sorted by date
232
+ * const recentRecords = await base44.entities.MyEntity.list('-created_date', 10);
233
+ * ```
234
+ *
235
+ * @example
236
+ * ```typescript
237
+ * // Get paginated results
238
+ * // Skip first 20, get next 10
239
+ * const page3 = await base44.entities.MyEntity.list('-created_date', 10, 20);
240
+ * ```
241
+ *
242
+ * @example
243
+ * ```typescript
244
+ * // Get only specific fields
245
+ * const fields = await base44.entities.MyEntity.list('-created_date', 10, 0, ['name', 'status']);
246
+ * ```
247
+ */
248
+ list<K extends keyof T = keyof T>(sort?: SortField<T>, limit?: number, skip?: number, fields?: K[]): Promise<Pick<T, K>[]>;
249
+ /**
250
+ * Filters records based on a query.
251
+ *
252
+ * Retrieves records that match specific criteria with support for
253
+ * sorting, pagination, and field selection.
254
+ *
255
+ * **Note:** The maximum limit is 5,000 items per request.
256
+ *
257
+ * @typeParam K - The fields to include in the response. Defaults to all fields.
258
+ * @param query - Query object with field-value pairs. Each key should be a field name
259
+ * from your entity schema, and each value is the criteria to match. Records matching all
260
+ * specified criteria are returned. Field names are case-sensitive. Use field-value pairs
261
+ * for exact matches, `null` for null values, arrays as shorthand for matching any of the
262
+ * provided values, or documented MongoDB query operators for advanced filtering.
263
+ * @param sort - Sort parameter, such as `'-created_date'` for descending. Defaults to `'-created_date'`.
264
+ * @param limit - Maximum number of results to return. Defaults to `50`.
265
+ * @param skip - Number of results to skip for pagination. Defaults to `0`.
266
+ * @param fields - Array of field names to include in the response. Defaults to all fields.
267
+ * @returns Promise resolving to an array of filtered records with selected fields.
268
+ *
269
+ * @example
270
+ * ```typescript
271
+ * // Filter by single field
272
+ * const activeRecords = await base44.entities.MyEntity.filter({
273
+ * status: 'active'
274
+ * });
275
+ * ```
276
+ *
277
+ * @example
278
+ * ```typescript
279
+ * // Filter by multiple fields
280
+ * const filteredRecords = await base44.entities.MyEntity.filter({
281
+ * priority: 'high',
282
+ * status: 'active'
283
+ * });
284
+ * ```
285
+ *
286
+ * @example
287
+ * ```typescript
288
+ * // Filter by any matching value
289
+ * const records = await base44.entities.MyEntity.filter({
290
+ * external_id: ['item-1', 'item-2']
291
+ * });
292
+ * ```
293
+ *
294
+ * @example
295
+ * ```typescript
296
+ * // Filter with query operators
297
+ * const popularRecords = await base44.entities.MyEntity.filter({
298
+ * count: { $gte: 100 },
299
+ * external_id: { $in: ['item-1', 'item-2'] }
300
+ * });
301
+ * ```
302
+ *
303
+ * @example
304
+ * ```typescript
305
+ * // Filter with logical operators
306
+ * const records = await base44.entities.MyEntity.filter({
307
+ * $or: [
308
+ * { name: 'Example item' },
309
+ * { slug: 'example-item' }
310
+ * ]
311
+ * });
312
+ * ```
313
+ *
314
+ * @example
315
+ * ```typescript
316
+ * // Filter null values
317
+ * const recordsWithoutDescription = await base44.entities.MyEntity.filter({
318
+ * description: null
319
+ * });
320
+ * ```
321
+ *
322
+ * @example
323
+ * ```typescript
324
+ * // Filter with sorting and pagination
325
+ * const results = await base44.entities.MyEntity.filter(
326
+ * { status: 'active' },
327
+ * '-created_date',
328
+ * 20,
329
+ * 0
330
+ * );
331
+ * ```
332
+ *
333
+ * @example
334
+ * ```typescript
335
+ * // Filter with specific fields
336
+ * const fields = await base44.entities.MyEntity.filter(
337
+ * { priority: 'high' },
338
+ * '-created_date',
339
+ * 10,
340
+ * 0,
341
+ * ['name', 'priority']
342
+ * );
343
+ * ```
344
+ */
345
+ filter<K extends keyof T = keyof T>(query: EntityFilterQuery<T>, sort?: SortField<T>, limit?: number, skip?: number, fields?: K[]): Promise<Pick<T, K>[]>;
346
+ /**
347
+ * Gets a single record by ID.
348
+ *
349
+ * Retrieves a specific record using its unique identifier.
350
+ *
351
+ * @param id - The unique identifier of the record.
352
+ * @returns Promise resolving to the record.
353
+ *
354
+ * @example
355
+ * ```typescript
356
+ * // Get record by ID
357
+ * const record = await base44.entities.MyEntity.get('entity-123');
358
+ * console.log(record.name);
359
+ * ```
360
+ */
361
+ get(id: string): Promise<T>;
362
+ /**
363
+ * Creates a new record.
364
+ *
365
+ * Creates a new record with the provided data.
366
+ *
367
+ * @param data - Object containing the record data.
368
+ * @returns Promise resolving to the created record.
369
+ *
370
+ * @example
371
+ * ```typescript
372
+ * // Create a new record
373
+ * const newRecord = await base44.entities.MyEntity.create({
374
+ * name: 'My Item',
375
+ * status: 'active',
376
+ * priority: 'high'
377
+ * });
378
+ * console.log('Created record with ID:', newRecord.id);
379
+ * ```
380
+ */
381
+ create(data: Partial<T>): Promise<T>;
382
+ /**
383
+ * Updates an existing record.
384
+ *
385
+ * Updates a record by ID with the provided data. Only the fields
386
+ * included in the data object will be updated.
387
+ *
388
+ * To update a single record by ID, use this method. To apply the same
389
+ * update to many records matching a query, use {@linkcode updateMany | updateMany()}.
390
+ * To update multiple specific records with different data each, use
391
+ * {@linkcode bulkUpdate | bulkUpdate()}.
392
+ *
393
+ * @param id - The unique identifier of the record to update.
394
+ * @param data - Object containing the fields to update.
395
+ * @returns Promise resolving to the updated record.
396
+ *
397
+ * @example
398
+ * ```typescript
399
+ * // Update single field
400
+ * const updated = await base44.entities.MyEntity.update('entity-123', {
401
+ * status: 'completed'
402
+ * });
403
+ * ```
404
+ *
405
+ * @example
406
+ * ```typescript
407
+ * // Update multiple fields
408
+ * const updated = await base44.entities.MyEntity.update('entity-123', {
409
+ * name: 'Updated name',
410
+ * priority: 'low',
411
+ * status: 'active'
412
+ * });
413
+ * ```
414
+ */
415
+ update(id: string, data: Partial<T>): Promise<T>;
416
+ /**
417
+ * Deletes a single record by ID.
418
+ *
419
+ * Permanently removes a record from the database.
420
+ *
421
+ * @param id - The unique identifier of the record to delete.
422
+ * @returns Promise resolving to the deletion result.
423
+ *
424
+ * @example
425
+ * ```typescript
426
+ * // Delete a record
427
+ * const result = await base44.entities.MyEntity.delete('entity-123');
428
+ * console.log('Deleted:', result.success);
429
+ * ```
430
+ */
431
+ delete(id: string): Promise<DeleteResult>;
432
+ /**
433
+ * Deletes multiple records matching a query.
434
+ *
435
+ * Permanently removes all records that match the provided query.
436
+ *
437
+ * @param query - Query object with field-value pairs. Each key should be a field name
438
+ * from your entity schema, and each value is the criteria to match. Records matching all
439
+ * specified criteria will be deleted. Field names are case-sensitive.
440
+ * @returns Promise resolving to the deletion result.
441
+ *
442
+ * @example
443
+ * ```typescript
444
+ * // Delete by multiple criteria
445
+ * const result = await base44.entities.MyEntity.deleteMany({
446
+ * status: 'completed',
447
+ * priority: 'low'
448
+ * });
449
+ * console.log('Deleted:', result.deleted);
450
+ * ```
451
+ */
452
+ deleteMany(query: Partial<T>): Promise<DeleteManyResult>;
453
+ /**
454
+ * Creates multiple records in a single request.
455
+ *
456
+ * Efficiently creates multiple records at once. This is faster
457
+ * than creating them individually.
458
+ *
459
+ * @param data - Array of record data objects.
460
+ * @returns Promise resolving to an array of created records.
461
+ *
462
+ * @example
463
+ * ```typescript
464
+ * // Create multiple records at once
465
+ * const result = await base44.entities.MyEntity.bulkCreate([
466
+ * { name: 'Item 1', status: 'active' },
467
+ * { name: 'Item 2', status: 'active' },
468
+ * { name: 'Item 3', status: 'completed' }
469
+ * ]);
470
+ * ```
471
+ */
472
+ bulkCreate(data: Partial<T>[]): Promise<T[]>;
473
+ /**
474
+ * Applies the same update to all records that match a query.
475
+ *
476
+ * Use this when you need to make the same change across all records that
477
+ * match specific criteria. For example, you could set every completed order
478
+ * to "archived", or increment a counter on all active users.
479
+ *
480
+ * Results are batched in groups of up to 500. When `has_more` is `true`
481
+ * in the response, call `updateMany` again with the same query to update
482
+ * the next batch. Make sure the query excludes already-updated records
483
+ * so you don't re-process the same entities on each iteration. For
484
+ * example, filter by `status: 'pending'` when setting status to `'processed'`.
485
+ *
486
+ * To update a single record by ID, use {@linkcode update | update()} instead. To update
487
+ * multiple specific records with different data each, use {@linkcode bulkUpdate | bulkUpdate()}.
488
+ *
489
+ * @param query - Query object to filter which records to update. Use field-value
490
+ * pairs for exact matches, or
491
+ * [MongoDB query operators](https://www.mongodb.com/docs/manual/reference/operator/query/)
492
+ * for advanced filtering. Supported query operators include `$eq`, `$ne`, `$gt`,
493
+ * `$gte`, `$lt`, `$lte`, `$in`, `$nin`, `$and`, `$or`, `$not`, `$nor`,
494
+ * `$exists`, `$regex`, `$all`, `$elemMatch`, and `$size`.
495
+ * @param data - Update operation object containing one or more
496
+ * [MongoDB update operators](https://www.mongodb.com/docs/manual/reference/operator/update/).
497
+ * Each field may only appear in one operator per call.
498
+ * Supported update operators include `$set`, `$rename`, `$unset`, `$inc`, `$mul`, `$min`, `$max`,
499
+ * `$currentDate`, `$addToSet`, `$push`, and `$pull`.
500
+ * @returns Promise resolving to the update result.
501
+ *
502
+ * @example
503
+ * ```typescript
504
+ * // Basic usage
505
+ * // Archive all completed orders
506
+ * const result = await base44.entities.Order.updateMany(
507
+ * { status: 'completed' },
508
+ * { $set: { status: 'archived' } }
509
+ * );
510
+ * console.log(`Updated ${result.updated} records`);
511
+ * ```
512
+ *
513
+ * @example
514
+ * ```typescript
515
+ * // Multiple query operators
516
+ * // Flag urgent items that haven't been handled yet
517
+ * const result = await base44.entities.Task.updateMany(
518
+ * { priority: { $in: ['high', 'critical'] }, status: { $ne: 'done' } },
519
+ * { $set: { flagged: true } }
520
+ * );
521
+ * ```
522
+ *
523
+ * @example
524
+ * ```typescript
525
+ * // Multiple update operators
526
+ * // Close out sales records and bump the view count
527
+ * const result = await base44.entities.Deal.updateMany(
528
+ * { category: 'sales' },
529
+ * { $set: { status: 'done' }, $inc: { view_count: 1 } }
530
+ * );
531
+ * ```
532
+ *
533
+ * @example
534
+ * ```typescript
535
+ * // Batched updates
536
+ * // Process all pending items in batches of 500.
537
+ * // The query filters by 'pending', so updated records (now 'processed')
538
+ * // are automatically excluded from the next batch.
539
+ * let hasMore = true;
540
+ * let totalUpdated = 0;
541
+ * while (hasMore) {
542
+ * const result = await base44.entities.Job.updateMany(
543
+ * { status: 'pending' },
544
+ * { $set: { status: 'processed' } }
545
+ * );
546
+ * totalUpdated += result.updated;
547
+ * hasMore = result.has_more;
548
+ * }
549
+ * ```
550
+ */
551
+ updateMany(query: Partial<T>, data: Record<string, Record<string, any>>): Promise<UpdateManyResult>;
552
+ /**
553
+ * Updates the specified records in a single request, each with its own data.
554
+ *
555
+ * Use this when you already know which records to update and each one needs
556
+ * different field values. For example, you could update the status and amount
557
+ * on three separate invoices in one call.
558
+ *
559
+ * You can update up to 500 records per request.
560
+ *
561
+ * To apply the same update to all records matching a query, use
562
+ * {@linkcode updateMany | updateMany()}. To update a single record by ID, use
563
+ * {@linkcode update | update()}.
564
+ *
565
+ * @param data - Array of objects to update. Each object must contain an `id` field identifying which record to update and any fields to change.
566
+ * @returns Promise resolving to an array of the updated records.
567
+ *
568
+ * @example
569
+ * ```typescript
570
+ * // Basic usage
571
+ * // Update three invoices with different statuses and amounts
572
+ * const updated = await base44.entities.Invoice.bulkUpdate([
573
+ * { id: 'inv-1', status: 'paid', amount: 999 },
574
+ * { id: 'inv-2', status: 'cancelled' },
575
+ * { id: 'inv-3', amount: 450 }
576
+ * ]);
577
+ * ```
578
+ *
579
+ * @example
580
+ * ```typescript
581
+ * // More than 500 items
582
+ * // Reassign each task to a different owner in batches
583
+ * const allUpdates = reassignments.map(r => ({ id: r.taskId, owner: r.newOwner }));
584
+ * for (let i = 0; i < allUpdates.length; i += 500) {
585
+ * const batch = allUpdates.slice(i, i + 500);
586
+ * await base44.entities.Task.bulkUpdate(batch);
587
+ * }
588
+ * ```
589
+ */
590
+ bulkUpdate(data: (Partial<T> & {
591
+ id: string;
592
+ })[]): Promise<T[]>;
593
+ /**
594
+ * Imports records from a file.
595
+ *
596
+ * Imports records from a file, typically CSV or similar format.
597
+ * The file format should match your entity structure. Requires a browser environment and can't be used in the backend.
598
+ *
599
+ * @param file - File object to import.
600
+ * @returns Promise resolving to the import result containing status, details, and created records.
601
+ *
602
+ * @example
603
+ * ```typescript
604
+ * // Import records from file in React
605
+ * const handleFileImport = async (event: React.ChangeEvent<HTMLInputElement>) => {
606
+ * const file = event.target.files?.[0];
607
+ * if (file) {
608
+ * const result = await base44.entities.MyEntity.importEntities(file);
609
+ * if (result.status === 'success' && result.output) {
610
+ * console.log(`Imported ${result.output.length} records`);
611
+ * }
612
+ * }
613
+ * };
614
+ * ```
615
+ */
616
+ importEntities(file: File): Promise<ImportResult<T>>;
617
+ /**
618
+ * Subscribes to realtime updates for all records of this entity type.
619
+ *
620
+ * Establishes a WebSocket connection to receive instant updates when any
621
+ * record is created, updated, or deleted. Returns an unsubscribe function
622
+ * to clean up the connection.
623
+ *
624
+ * @param callback - Callback function called when an entity changes. The callback receives an event object with the following properties:
625
+ * - `type`: The type of change that occurred - `'create'`, `'update'`, or `'delete'`.
626
+ * - `data`: The entity data after the change.
627
+ * - `id`: The unique identifier of the affected entity.
628
+ * - `timestamp`: ISO 8601 timestamp of when the event occurred.
629
+ * @returns Unsubscribe function to stop receiving updates.
630
+ *
631
+ * @example
632
+ * ```typescript
633
+ * // Subscribe to all Task changes
634
+ * const unsubscribe = base44.entities.Task.subscribe((event) => {
635
+ * console.log(`Task ${event.id} was ${event.type}d:`, event.data);
636
+ * });
637
+ *
638
+ * // Later, clean up the subscription
639
+ * unsubscribe();
640
+ * ```
641
+ */
642
+ subscribe(callback: RealtimeCallback<T>): () => void;
643
+ }
644
+ /**
645
+ * Typed entities module - maps registry keys to typed handlers (full record type).
646
+ */
647
+ type TypedEntitiesModule = {
648
+ [K in keyof EntityTypeRegistry]: EntityHandler<EntityRecord[K]>;
649
+ };
650
+ /**
651
+ * Dynamic entities module - allows any entity name with untyped handler.
652
+ */
653
+ type DynamicEntitiesModule = {
654
+ [entityName: string]: EntityHandler<any>;
655
+ };
656
+ /**
657
+ * Entities module for managing app data.
658
+ *
659
+ * This module provides dynamic access to all entities in the app.
660
+ * Each entity gets a handler with full CRUD operations and additional utility methods.
661
+ *
662
+ * Entities are accessed dynamically using the pattern:
663
+ * `base44.entities.EntityName.method()`
664
+ *
665
+ * This module is available to use with a client in all authentication modes:
666
+ *
667
+ * - **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.
668
+ * - **Service role authentication** (`base44.asServiceRole.entities`): Operations bypass entity access rules and field-level security entirely. Can read and write any record in any entity.
669
+ *
670
+ * ## Entity Handlers
671
+ *
672
+ * 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.
673
+ *
674
+ * 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()`.
675
+ *
676
+ * You don't need to instantiate or import entity handlers. They're automatically available for every entity you create in your app.
677
+ *
678
+ * ## Built-in User Entity
679
+ *
680
+ * Every app includes a built-in `User` entity that stores user account information. This entity has special security rules that can't be changed.
681
+ *
682
+ * 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.
683
+ *
684
+ * ## Generated Types
685
+ *
686
+ * 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.
687
+ *
688
+ * @example
689
+ * ```typescript
690
+ * // Get all records from the MyEntity entity
691
+ * // Get all records the current user has permissions to view
692
+ * const myRecords = await base44.entities.MyEntity.list();
693
+ * ```
694
+ *
695
+ * @example
696
+ * ```typescript
697
+ * // List every user, bypassing the User entity's access rules
698
+ * const allUsers = await base44.asServiceRole.entities.User.list();
699
+ * ```
700
+ */
701
+ export type EntitiesModule = TypedEntitiesModule & DynamicEntitiesModule;
702
+ export {};
@@ -0,0 +1 @@
1
+ export {};