@base44-preview/sdk 0.8.18-pr.108.7e35c83 → 0.8.18-pr.116.3508d64
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/modules/auth.js +15 -1
- package/dist/modules/entities.types.d.ts +20 -77
- package/package.json +1 -1
package/dist/modules/auth.js
CHANGED
|
@@ -26,9 +26,23 @@ export function createAuthModule(axios, functionsAxiosClient, appId, options) {
|
|
|
26
26
|
throw new Error("Login method can only be used in a browser environment");
|
|
27
27
|
}
|
|
28
28
|
// If nextUrl is not provided, use the current URL
|
|
29
|
-
|
|
29
|
+
let redirectUrl = nextUrl
|
|
30
30
|
? new URL(nextUrl, window.location.origin).toString()
|
|
31
31
|
: window.location.href;
|
|
32
|
+
// Prevent redirect loops: if redirectUrl is already a login URL, extract the original from_url
|
|
33
|
+
try {
|
|
34
|
+
const parsedUrl = new URL(redirectUrl);
|
|
35
|
+
if (parsedUrl.pathname.endsWith("/login")) {
|
|
36
|
+
const originalFromUrl = parsedUrl.searchParams.get("from_url");
|
|
37
|
+
if (originalFromUrl) {
|
|
38
|
+
// Use the original destination instead of nesting login URLs
|
|
39
|
+
redirectUrl = originalFromUrl;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
catch (_b) {
|
|
44
|
+
// If URL parsing fails, continue with the original redirectUrl
|
|
45
|
+
}
|
|
32
46
|
// Build the login URL
|
|
33
47
|
const loginUrl = `${(_a = options.appBaseUrl) !== null && _a !== void 0 ? _a : ""}/login?from_url=${encodeURIComponent(redirectUrl)}`;
|
|
34
48
|
// Redirect to the login page
|
|
@@ -4,14 +4,12 @@
|
|
|
4
4
|
export type RealtimeEventType = "create" | "update" | "delete";
|
|
5
5
|
/**
|
|
6
6
|
* Payload received when a realtime event occurs.
|
|
7
|
-
*
|
|
8
|
-
* @typeParam T - The entity type for the data field. Defaults to `any`.
|
|
9
7
|
*/
|
|
10
|
-
export interface RealtimeEvent
|
|
8
|
+
export interface RealtimeEvent {
|
|
11
9
|
/** The type of change that occurred */
|
|
12
10
|
type: RealtimeEventType;
|
|
13
11
|
/** The entity data */
|
|
14
|
-
data:
|
|
12
|
+
data: any;
|
|
15
13
|
/** The unique identifier of the affected entity */
|
|
16
14
|
id: string;
|
|
17
15
|
/** ISO 8601 timestamp of when the event occurred */
|
|
@@ -19,65 +17,14 @@ export interface RealtimeEvent<T = any> {
|
|
|
19
17
|
}
|
|
20
18
|
/**
|
|
21
19
|
* 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 importing entities from a file.
|
|
44
|
-
*
|
|
45
|
-
* @typeParam T - The entity type for imported records. Defaults to `any`.
|
|
46
20
|
*/
|
|
47
|
-
export
|
|
48
|
-
/** Status of the import operation */
|
|
49
|
-
status: "success" | "error";
|
|
50
|
-
/** Details message, e.g., "Successfully imported 3 entities with RLS enforcement" */
|
|
51
|
-
details: string | null;
|
|
52
|
-
/** Array of created entity objects when successful, or null on error */
|
|
53
|
-
output: T[] | null;
|
|
54
|
-
}
|
|
55
|
-
/**
|
|
56
|
-
* Sort field type for entity queries.
|
|
57
|
-
*
|
|
58
|
-
* Supports ascending (no prefix or `'+'`) and descending (`'-'`) sorting.
|
|
59
|
-
*
|
|
60
|
-
* @typeParam T - The entity type to derive sortable fields from.
|
|
61
|
-
*
|
|
62
|
-
* @example
|
|
63
|
-
* ```typescript
|
|
64
|
-
* // Ascending sort (default)
|
|
65
|
-
* 'created_date'
|
|
66
|
-
* '+created_date'
|
|
67
|
-
*
|
|
68
|
-
* // Descending sort
|
|
69
|
-
* '-created_date'
|
|
70
|
-
* ```
|
|
71
|
-
*/
|
|
72
|
-
export type SortField<T> = (keyof T & string) | `+${keyof T & string}` | `-${keyof T & string}`;
|
|
21
|
+
export type RealtimeCallback = (event: RealtimeEvent) => void;
|
|
73
22
|
/**
|
|
74
23
|
* Entity handler providing CRUD operations for a specific entity type.
|
|
75
24
|
*
|
|
76
25
|
* Each entity in the app gets a handler with these methods for managing data.
|
|
77
|
-
*
|
|
78
|
-
* @typeParam T - The entity type. Defaults to `any` for backward compatibility.
|
|
79
26
|
*/
|
|
80
|
-
export interface EntityHandler
|
|
27
|
+
export interface EntityHandler {
|
|
81
28
|
/**
|
|
82
29
|
* Lists records with optional pagination and sorting.
|
|
83
30
|
*
|
|
@@ -86,12 +33,11 @@ export interface EntityHandler<T = any> {
|
|
|
86
33
|
*
|
|
87
34
|
* **Note:** The maximum limit is 5,000 items per request.
|
|
88
35
|
*
|
|
89
|
-
* @typeParam K - The fields to include in the response. Defaults to all fields.
|
|
90
36
|
* @param sort - Sort parameter, such as `'-created_date'` for descending. Defaults to `'-created_date'`.
|
|
91
37
|
* @param limit - Maximum number of results to return. Defaults to `50`.
|
|
92
38
|
* @param skip - Number of results to skip for pagination. Defaults to `0`.
|
|
93
39
|
* @param fields - Array of field names to include in the response. Defaults to all fields.
|
|
94
|
-
* @returns Promise resolving to an array of records
|
|
40
|
+
* @returns Promise resolving to an array of records.
|
|
95
41
|
*
|
|
96
42
|
* @example
|
|
97
43
|
* ```typescript
|
|
@@ -118,7 +64,7 @@ export interface EntityHandler<T = any> {
|
|
|
118
64
|
* const fields = await base44.entities.MyEntity.list('-created_date', 10, 0, ['name', 'status']);
|
|
119
65
|
* ```
|
|
120
66
|
*/
|
|
121
|
-
list
|
|
67
|
+
list(sort?: string, limit?: number, skip?: number, fields?: string[]): Promise<any>;
|
|
122
68
|
/**
|
|
123
69
|
* Filters records based on a query.
|
|
124
70
|
*
|
|
@@ -127,7 +73,6 @@ export interface EntityHandler<T = any> {
|
|
|
127
73
|
*
|
|
128
74
|
* **Note:** The maximum limit is 5,000 items per request.
|
|
129
75
|
*
|
|
130
|
-
* @typeParam K - The fields to include in the response. Defaults to all fields.
|
|
131
76
|
* @param query - Query object with field-value pairs. Each key should be a field name
|
|
132
77
|
* from your entity schema, and each value is the criteria to match. Records matching all
|
|
133
78
|
* specified criteria are returned. Field names are case-sensitive.
|
|
@@ -135,7 +80,7 @@ export interface EntityHandler<T = any> {
|
|
|
135
80
|
* @param limit - Maximum number of results to return. Defaults to `50`.
|
|
136
81
|
* @param skip - Number of results to skip for pagination. Defaults to `0`.
|
|
137
82
|
* @param fields - Array of field names to include in the response. Defaults to all fields.
|
|
138
|
-
* @returns Promise resolving to an array of filtered records
|
|
83
|
+
* @returns Promise resolving to an array of filtered records.
|
|
139
84
|
*
|
|
140
85
|
* @example
|
|
141
86
|
* ```typescript
|
|
@@ -177,7 +122,7 @@ export interface EntityHandler<T = any> {
|
|
|
177
122
|
* );
|
|
178
123
|
* ```
|
|
179
124
|
*/
|
|
180
|
-
filter
|
|
125
|
+
filter(query: Record<string, any>, sort?: string, limit?: number, skip?: number, fields?: string[]): Promise<any>;
|
|
181
126
|
/**
|
|
182
127
|
* Gets a single record by ID.
|
|
183
128
|
*
|
|
@@ -193,7 +138,7 @@ export interface EntityHandler<T = any> {
|
|
|
193
138
|
* console.log(record.name);
|
|
194
139
|
* ```
|
|
195
140
|
*/
|
|
196
|
-
get(id: string): Promise<
|
|
141
|
+
get(id: string): Promise<any>;
|
|
197
142
|
/**
|
|
198
143
|
* Creates a new record.
|
|
199
144
|
*
|
|
@@ -213,7 +158,7 @@ export interface EntityHandler<T = any> {
|
|
|
213
158
|
* console.log('Created record with ID:', newRecord.id);
|
|
214
159
|
* ```
|
|
215
160
|
*/
|
|
216
|
-
create(data:
|
|
161
|
+
create(data: Record<string, any>): Promise<any>;
|
|
217
162
|
/**
|
|
218
163
|
* Updates an existing record.
|
|
219
164
|
*
|
|
@@ -242,7 +187,7 @@ export interface EntityHandler<T = any> {
|
|
|
242
187
|
* });
|
|
243
188
|
* ```
|
|
244
189
|
*/
|
|
245
|
-
update(id: string, data:
|
|
190
|
+
update(id: string, data: Record<string, any>): Promise<any>;
|
|
246
191
|
/**
|
|
247
192
|
* Deletes a single record by ID.
|
|
248
193
|
*
|
|
@@ -255,10 +200,10 @@ export interface EntityHandler<T = any> {
|
|
|
255
200
|
* ```typescript
|
|
256
201
|
* // Delete a record
|
|
257
202
|
* const result = await base44.entities.MyEntity.delete('entity-123');
|
|
258
|
-
* console.log('Deleted:', result
|
|
203
|
+
* console.log('Deleted:', result);
|
|
259
204
|
* ```
|
|
260
205
|
*/
|
|
261
|
-
delete(id: string): Promise<
|
|
206
|
+
delete(id: string): Promise<any>;
|
|
262
207
|
/**
|
|
263
208
|
* Deletes multiple records matching a query.
|
|
264
209
|
*
|
|
@@ -279,7 +224,7 @@ export interface EntityHandler<T = any> {
|
|
|
279
224
|
* console.log('Deleted:', result);
|
|
280
225
|
* ```
|
|
281
226
|
*/
|
|
282
|
-
deleteMany(query:
|
|
227
|
+
deleteMany(query: Record<string, any>): Promise<any>;
|
|
283
228
|
/**
|
|
284
229
|
* Creates multiple records in a single request.
|
|
285
230
|
*
|
|
@@ -299,7 +244,7 @@ export interface EntityHandler<T = any> {
|
|
|
299
244
|
* ]);
|
|
300
245
|
* ```
|
|
301
246
|
*/
|
|
302
|
-
bulkCreate(data:
|
|
247
|
+
bulkCreate(data: Record<string, any>[]): Promise<any>;
|
|
303
248
|
/**
|
|
304
249
|
* Imports records from a file.
|
|
305
250
|
*
|
|
@@ -307,7 +252,7 @@ export interface EntityHandler<T = any> {
|
|
|
307
252
|
* The file format should match your entity structure. Requires a browser environment and can't be used in the backend.
|
|
308
253
|
*
|
|
309
254
|
* @param file - File object to import.
|
|
310
|
-
* @returns Promise resolving to the import result
|
|
255
|
+
* @returns Promise resolving to the import result.
|
|
311
256
|
*
|
|
312
257
|
* @example
|
|
313
258
|
* ```typescript
|
|
@@ -316,14 +261,12 @@ export interface EntityHandler<T = any> {
|
|
|
316
261
|
* const file = event.target.files?.[0];
|
|
317
262
|
* if (file) {
|
|
318
263
|
* const result = await base44.entities.MyEntity.importEntities(file);
|
|
319
|
-
*
|
|
320
|
-
* console.log(`Imported ${result.output.length} records`);
|
|
321
|
-
* }
|
|
264
|
+
* console.log(`Imported ${result.count} records`);
|
|
322
265
|
* }
|
|
323
266
|
* };
|
|
324
267
|
* ```
|
|
325
268
|
*/
|
|
326
|
-
importEntities(file: File): Promise<
|
|
269
|
+
importEntities(file: File): Promise<any>;
|
|
327
270
|
/**
|
|
328
271
|
* Subscribes to realtime updates for all records of this entity type.
|
|
329
272
|
*
|
|
@@ -349,7 +292,7 @@ export interface EntityHandler<T = any> {
|
|
|
349
292
|
* unsubscribe();
|
|
350
293
|
* ```
|
|
351
294
|
*/
|
|
352
|
-
subscribe(callback: RealtimeCallback
|
|
295
|
+
subscribe(callback: RealtimeCallback): () => void;
|
|
353
296
|
}
|
|
354
297
|
/**
|
|
355
298
|
* Entities module for managing app data.
|
|
@@ -397,5 +340,5 @@ export interface EntitiesModule {
|
|
|
397
340
|
* base44.entities.AnotherEntity
|
|
398
341
|
* ```
|
|
399
342
|
*/
|
|
400
|
-
[entityName: string]: EntityHandler
|
|
343
|
+
[entityName: string]: EntityHandler;
|
|
401
344
|
}
|