@base44-preview/sdk 0.8.18-pr.117.7c9cdfc → 0.8.18-pr.117.d56cb92
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/README.md +25 -16
- package/dist/index.d.ts +1 -1
- package/dist/modules/entities.types.d.ts +45 -9
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -9,31 +9,32 @@ You can use it in two ways:
|
|
|
9
9
|
|
|
10
10
|
## Installation
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
**Inside Base44 apps**: The SDK is already available. No installation needed.
|
|
13
|
+
|
|
14
|
+
**External apps**: Install the SDK via npm:
|
|
13
15
|
|
|
14
16
|
```bash
|
|
15
17
|
npm install @base44/sdk
|
|
16
18
|
```
|
|
17
19
|
|
|
18
|
-
> **Note**: In Base44-generated apps, the SDK is already installed for you.
|
|
19
|
-
|
|
20
20
|
## Modules
|
|
21
21
|
|
|
22
22
|
The SDK provides access to Base44's functionality through the following modules:
|
|
23
23
|
|
|
24
24
|
- **[`agents`](https://docs.base44.com/developers/references/sdk/docs/interfaces/agents)**: Interact with AI agents and manage conversations.
|
|
25
|
+
- **[`analytics`](https://docs.base44.com/developers/references/sdk/docs/interfaces/analytics)**: Track custom events in your app.
|
|
25
26
|
- **[`app-logs`](https://docs.base44.com/developers/references/sdk/docs/interfaces/app-logs)**: Access and query app logs.
|
|
26
27
|
- **[`auth`](https://docs.base44.com/developers/references/sdk/docs/interfaces/auth)**: Manage user authentication, registration, and session handling.
|
|
27
28
|
- **[`connectors`](https://docs.base44.com/developers/references/sdk/docs/interfaces/connectors)**: Manage OAuth connections and access tokens for third-party services.
|
|
28
29
|
- **[`entities`](https://docs.base44.com/developers/references/sdk/docs/interfaces/entities)**: Work with your app's data entities using CRUD operations.
|
|
29
30
|
- **[`functions`](https://docs.base44.com/developers/references/sdk/docs/interfaces/functions)**: Execute backend functions.
|
|
30
|
-
- **[`integrations`](https://docs.base44.com/developers/references/sdk/docs/type-aliases/integrations)**:
|
|
31
|
+
- **[`integrations`](https://docs.base44.com/developers/references/sdk/docs/type-aliases/integrations)**: Access pre-built and third-party integrations.
|
|
31
32
|
|
|
32
|
-
##
|
|
33
|
+
## Quickstarts
|
|
33
34
|
|
|
34
|
-
How you get started depends on your
|
|
35
|
+
How you get started depends on whether you're working inside a Base44-generated app or building your own.
|
|
35
36
|
|
|
36
|
-
### Inside
|
|
37
|
+
### Inside Base44 apps
|
|
37
38
|
|
|
38
39
|
In Base44-generated apps, the client is pre-configured. Just import and use it:
|
|
39
40
|
|
|
@@ -58,32 +59,32 @@ const tasks = await base44.entities.Task.list();
|
|
|
58
59
|
|
|
59
60
|
### External apps
|
|
60
61
|
|
|
61
|
-
When using Base44 as a backend for your own app,
|
|
62
|
+
When using Base44 as a backend for your own app, install the SDK and create the client yourself:
|
|
62
63
|
|
|
63
64
|
```typescript
|
|
64
|
-
import { createClient } from
|
|
65
|
+
import { createClient } from "@base44/sdk";
|
|
65
66
|
|
|
66
67
|
// Create a client for your Base44 app
|
|
67
68
|
const base44 = createClient({
|
|
68
|
-
appId:
|
|
69
|
+
appId: "your-app-id", // Find this in the Base44 editor URL
|
|
69
70
|
});
|
|
70
71
|
|
|
71
|
-
// Read public data
|
|
72
|
+
// Read public data
|
|
72
73
|
const products = await base44.entities.Products.list();
|
|
73
74
|
|
|
74
75
|
// Authenticate a user (token is automatically set)
|
|
75
|
-
await base44.auth.loginViaEmailPassword(
|
|
76
|
+
await base44.auth.loginViaEmailPassword("user@example.com", "password");
|
|
76
77
|
|
|
77
|
-
//
|
|
78
|
+
// Access user's data
|
|
78
79
|
const userOrders = await base44.entities.Orders.list();
|
|
79
80
|
```
|
|
80
81
|
|
|
81
82
|
### Service role
|
|
82
83
|
|
|
83
|
-
|
|
84
|
+
By default, the client operates with user-level permissions, limiting access to what the current user can see and do. The service role provides elevated permissions for backend operations and is only available in Base44-hosted backend functions. External backends can't use service role permissions.
|
|
84
85
|
|
|
85
86
|
```typescript
|
|
86
|
-
import { createClientFromRequest } from
|
|
87
|
+
import { createClientFromRequest } from "npm:@base44/sdk";
|
|
87
88
|
|
|
88
89
|
Deno.serve(async (req) => {
|
|
89
90
|
const base44 = createClientFromRequest(req);
|
|
@@ -97,7 +98,15 @@ Deno.serve(async (req) => {
|
|
|
97
98
|
|
|
98
99
|
## Learn more
|
|
99
100
|
|
|
100
|
-
|
|
101
|
+
The best way to get started with the JavaScript SDK is to have Base44 build an app for you. Once you have an app, you can explore the generated code and experiment with the SDK to see how it works in practice. You can also ask Base44 to demonstrate specific features of the SDK.
|
|
102
|
+
|
|
103
|
+
For a deeper understanding, check out these guides:
|
|
104
|
+
|
|
105
|
+
1. [Base44 client](https://docs.base44.com/developers/references/sdk/getting-started/client) - Work with the client in frontend, backend, and external app contexts.
|
|
106
|
+
2. [Work with data](https://docs.base44.com/developers/references/sdk/getting-started/work-with-data) - Create, read, update, and delete data.
|
|
107
|
+
3. [Common SDK patterns](https://docs.base44.com/developers/references/sdk/getting-started/work-with-sdk) - Authentication, integrations, functions, and error handling.
|
|
108
|
+
|
|
109
|
+
For the complete documentation and API reference, visit the **[Base44 Developer Docs](https://docs.base44.com/developers/home)**.
|
|
101
110
|
|
|
102
111
|
## Development
|
|
103
112
|
|
package/dist/index.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { getAccessToken, saveAccessToken, removeAccessToken, getLoginUrl } from
|
|
|
4
4
|
export { createClient, createClientFromRequest, Base44Error, getAccessToken, saveAccessToken, removeAccessToken, getLoginUrl, };
|
|
5
5
|
export type { Base44Client, CreateClientConfig, CreateClientOptions, Base44ErrorJSON, };
|
|
6
6
|
export * from "./types.js";
|
|
7
|
-
export type { EntitiesModule, EntityHandler, EntityTypeRegistry, RealtimeEventType, RealtimeEvent, RealtimeCallback, } from "./modules/entities.types.js";
|
|
7
|
+
export type { EntitiesModule, EntityHandler, EntityRecord, EntityTypeRegistry, RealtimeEventType, RealtimeEvent, RealtimeCallback, } from "./modules/entities.types.js";
|
|
8
8
|
export type { AuthModule, LoginResponse, RegisterParams, VerifyOtpParams, ChangePasswordParams, ResetPasswordParams, User, } from "./modules/auth.types.js";
|
|
9
9
|
export type { IntegrationsModule, IntegrationPackage, IntegrationEndpointFunction, CoreIntegrations, InvokeLLMParams, GenerateImageParams, GenerateImageResult, UploadFileParams, UploadFileResult, SendEmailParams, SendEmailResult, ExtractDataFromUploadedFileParams, ExtractDataFromUploadedFileResult, UploadPrivateFileParams, UploadPrivateFileResult, CreateFileSignedUrlParams, CreateFileSignedUrlResult, } from "./modules/integrations.types.js";
|
|
10
10
|
export type { FunctionsModule, FunctionNameRegistry, } from "./modules/functions.types.js";
|
|
@@ -4,6 +4,8 @@
|
|
|
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`.
|
|
7
9
|
*/
|
|
8
10
|
export interface RealtimeEvent<T = any> {
|
|
9
11
|
/** The type of change that occurred */
|
|
@@ -17,6 +19,8 @@ export interface RealtimeEvent<T = any> {
|
|
|
17
19
|
}
|
|
18
20
|
/**
|
|
19
21
|
* Callback function invoked when a realtime event occurs.
|
|
22
|
+
*
|
|
23
|
+
* @typeParam T - The entity type for the event data. Defaults to `any`.
|
|
20
24
|
*/
|
|
21
25
|
export type RealtimeCallback<T = any> = (event: RealtimeEvent<T>) => void;
|
|
22
26
|
/**
|
|
@@ -37,11 +41,13 @@ export interface DeleteManyResult {
|
|
|
37
41
|
}
|
|
38
42
|
/**
|
|
39
43
|
* Result returned when importing entities from a file.
|
|
44
|
+
*
|
|
45
|
+
* @typeParam T - The entity type for imported records. Defaults to `any`.
|
|
40
46
|
*/
|
|
41
47
|
export interface ImportResult<T = any> {
|
|
42
48
|
/** Status of the import operation */
|
|
43
49
|
status: "success" | "error";
|
|
44
|
-
/** Details message */
|
|
50
|
+
/** Details message, e.g., "Successfully imported 3 entities with RLS enforcement" */
|
|
45
51
|
details: string | null;
|
|
46
52
|
/** Array of created entity objects when successful, or null on error */
|
|
47
53
|
output: T[] | null;
|
|
@@ -51,6 +57,8 @@ export interface ImportResult<T = any> {
|
|
|
51
57
|
*
|
|
52
58
|
* Supports ascending (no prefix or `'+'`) and descending (`'-'`) sorting.
|
|
53
59
|
*
|
|
60
|
+
* @typeParam T - The entity type to derive sortable fields from.
|
|
61
|
+
*
|
|
54
62
|
* @example
|
|
55
63
|
* ```typescript
|
|
56
64
|
* // Ascending sort (default)
|
|
@@ -62,16 +70,42 @@ export interface ImportResult<T = any> {
|
|
|
62
70
|
* ```
|
|
63
71
|
*/
|
|
64
72
|
export type SortField<T> = (keyof T & string) | `+${keyof T & string}` | `-${keyof T & string}`;
|
|
73
|
+
/**
|
|
74
|
+
* Fields added by the server to every entity record (id, dates, created_by, etc.).
|
|
75
|
+
*/
|
|
76
|
+
export interface ServerEntityFields {
|
|
77
|
+
/** Unique identifier of the record */
|
|
78
|
+
id: string;
|
|
79
|
+
/** ISO 8601 timestamp when the record was created */
|
|
80
|
+
created_date: string;
|
|
81
|
+
/** ISO 8601 timestamp when the record was last updated */
|
|
82
|
+
updated_date: string;
|
|
83
|
+
/** Email of the user who created the record (may be hidden in some responses) */
|
|
84
|
+
created_by?: string | null;
|
|
85
|
+
/** ID of the user who created the record */
|
|
86
|
+
created_by_id?: string | null;
|
|
87
|
+
/** Whether the record is sample/seed data */
|
|
88
|
+
is_sample?: boolean;
|
|
89
|
+
}
|
|
65
90
|
/**
|
|
66
91
|
* Registry mapping entity names to their TypeScript types.
|
|
67
|
-
* Augment this interface
|
|
92
|
+
* Augment this interface with your entity schema (user-defined fields only).
|
|
68
93
|
*/
|
|
69
94
|
export interface EntityTypeRegistry {
|
|
70
95
|
}
|
|
96
|
+
/**
|
|
97
|
+
* Full record type for each entity: schema fields + server-injected fields (id, created_date, etc.).
|
|
98
|
+
* Use for state that holds results of list()/get(), e.g. `useState<EntityRecord['Task']>([])`.
|
|
99
|
+
*/
|
|
100
|
+
export type EntityRecord = {
|
|
101
|
+
[K in keyof EntityTypeRegistry]: EntityTypeRegistry[K] & ServerEntityFields;
|
|
102
|
+
};
|
|
71
103
|
/**
|
|
72
104
|
* Entity handler providing CRUD operations for a specific entity type.
|
|
73
105
|
*
|
|
74
106
|
* Each entity in the app gets a handler with these methods for managing data.
|
|
107
|
+
*
|
|
108
|
+
* @typeParam T - The entity type. Defaults to `any` for backward compatibility.
|
|
75
109
|
*/
|
|
76
110
|
export interface EntityHandler<T = any> {
|
|
77
111
|
/**
|
|
@@ -82,11 +116,12 @@ export interface EntityHandler<T = any> {
|
|
|
82
116
|
*
|
|
83
117
|
* **Note:** The maximum limit is 5,000 items per request.
|
|
84
118
|
*
|
|
119
|
+
* @typeParam K - The fields to include in the response. Defaults to all fields.
|
|
85
120
|
* @param sort - Sort parameter, such as `'-created_date'` for descending. Defaults to `'-created_date'`.
|
|
86
121
|
* @param limit - Maximum number of results to return. Defaults to `50`.
|
|
87
122
|
* @param skip - Number of results to skip for pagination. Defaults to `0`.
|
|
88
123
|
* @param fields - Array of field names to include in the response. Defaults to all fields.
|
|
89
|
-
* @returns Promise resolving to an array of records.
|
|
124
|
+
* @returns Promise resolving to an array of records with selected fields.
|
|
90
125
|
*
|
|
91
126
|
* @example
|
|
92
127
|
* ```typescript
|
|
@@ -122,6 +157,7 @@ export interface EntityHandler<T = any> {
|
|
|
122
157
|
*
|
|
123
158
|
* **Note:** The maximum limit is 5,000 items per request.
|
|
124
159
|
*
|
|
160
|
+
* @typeParam K - The fields to include in the response. Defaults to all fields.
|
|
125
161
|
* @param query - Query object with field-value pairs. Each key should be a field name
|
|
126
162
|
* from your entity schema, and each value is the criteria to match. Records matching all
|
|
127
163
|
* specified criteria are returned. Field names are case-sensitive.
|
|
@@ -129,7 +165,7 @@ export interface EntityHandler<T = any> {
|
|
|
129
165
|
* @param limit - Maximum number of results to return. Defaults to `50`.
|
|
130
166
|
* @param skip - Number of results to skip for pagination. Defaults to `0`.
|
|
131
167
|
* @param fields - Array of field names to include in the response. Defaults to all fields.
|
|
132
|
-
* @returns Promise resolving to an array of filtered records.
|
|
168
|
+
* @returns Promise resolving to an array of filtered records with selected fields.
|
|
133
169
|
*
|
|
134
170
|
* @example
|
|
135
171
|
* ```typescript
|
|
@@ -301,7 +337,7 @@ export interface EntityHandler<T = any> {
|
|
|
301
337
|
* The file format should match your entity structure. Requires a browser environment and can't be used in the backend.
|
|
302
338
|
*
|
|
303
339
|
* @param file - File object to import.
|
|
304
|
-
* @returns Promise resolving to the import result.
|
|
340
|
+
* @returns Promise resolving to the import result containing status, details, and created records.
|
|
305
341
|
*
|
|
306
342
|
* @example
|
|
307
343
|
* ```typescript
|
|
@@ -310,8 +346,8 @@ export interface EntityHandler<T = any> {
|
|
|
310
346
|
* const file = event.target.files?.[0];
|
|
311
347
|
* if (file) {
|
|
312
348
|
* const result = await base44.entities.MyEntity.importEntities(file);
|
|
313
|
-
* if (result.status === 'success') {
|
|
314
|
-
* console.log(`Imported ${result.output
|
|
349
|
+
* if (result.status === 'success' && result.output) {
|
|
350
|
+
* console.log(`Imported ${result.output.length} records`);
|
|
315
351
|
* }
|
|
316
352
|
* }
|
|
317
353
|
* };
|
|
@@ -346,10 +382,10 @@ export interface EntityHandler<T = any> {
|
|
|
346
382
|
subscribe(callback: RealtimeCallback<T>): () => void;
|
|
347
383
|
}
|
|
348
384
|
/**
|
|
349
|
-
* Typed entities module - maps registry keys to typed handlers.
|
|
385
|
+
* Typed entities module - maps registry keys to typed handlers (full record type).
|
|
350
386
|
*/
|
|
351
387
|
type TypedEntitiesModule = {
|
|
352
|
-
[K in keyof EntityTypeRegistry]: EntityHandler<
|
|
388
|
+
[K in keyof EntityTypeRegistry]: EntityHandler<EntityRecord[K]>;
|
|
353
389
|
};
|
|
354
390
|
/**
|
|
355
391
|
* Dynamic entities module - allows any entity name with untyped handler.
|