@base44-preview/sdk 0.8.18-pr.91.a4c0940 → 0.8.19-pr.124.bb33a2f
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/client.js +3 -1
- package/dist/index.d.ts +3 -3
- package/dist/modules/agents.types.d.ts +19 -3
- package/dist/modules/auth.js +2 -3
- package/dist/modules/auth.types.d.ts +2 -2
- package/dist/modules/connectors.types.d.ts +8 -1
- package/dist/modules/entities.types.d.ts +120 -35
- package/dist/modules/functions.types.d.ts +11 -1
- 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/client.js
CHANGED
|
@@ -50,6 +50,8 @@ import { createAnalyticsModule } from "./modules/analytics.js";
|
|
|
50
50
|
*/
|
|
51
51
|
export function createClient(config) {
|
|
52
52
|
const { serverUrl = "https://base44.app", appId, token, serviceToken, requiresAuth = false, appBaseUrl, options, functionsVersion, headers: optionalHeaders, } = config;
|
|
53
|
+
// Normalize appBaseUrl to always be a string (empty if not provided or invalid)
|
|
54
|
+
const normalizedAppBaseUrl = typeof appBaseUrl === "string" ? appBaseUrl : "";
|
|
53
55
|
const socketConfig = {
|
|
54
56
|
serverUrl,
|
|
55
57
|
mountPath: "/ws-user-apps/socket.io/",
|
|
@@ -102,7 +104,7 @@ export function createClient(config) {
|
|
|
102
104
|
interceptResponses: false,
|
|
103
105
|
});
|
|
104
106
|
const userAuthModule = createAuthModule(axiosClient, functionsAxiosClient, appId, {
|
|
105
|
-
appBaseUrl,
|
|
107
|
+
appBaseUrl: normalizedAppBaseUrl,
|
|
106
108
|
serverUrl,
|
|
107
109
|
});
|
|
108
110
|
const userModules = {
|
package/dist/index.d.ts
CHANGED
|
@@ -4,11 +4,11 @@ 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, 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
|
-
export type { FunctionsModule } from "./modules/functions.types.js";
|
|
11
|
-
export type { AgentsModule, AgentConversation, AgentMessage, AgentMessageReasoning, AgentMessageToolCall, AgentMessageUsage, AgentMessageCustomContext, AgentMessageMetadata, CreateConversationParams, } from "./modules/agents.types.js";
|
|
10
|
+
export type { FunctionsModule, FunctionNameRegistry, } from "./modules/functions.types.js";
|
|
11
|
+
export type { AgentsModule, AgentNameRegistry, AgentConversation, AgentMessage, AgentMessageReasoning, AgentMessageToolCall, AgentMessageUsage, AgentMessageCustomContext, AgentMessageMetadata, CreateConversationParams, } from "./modules/agents.types.js";
|
|
12
12
|
export type { AppLogsModule } from "./modules/app-logs.types.js";
|
|
13
13
|
export type { SsoModule, SsoAccessTokenResponse } from "./modules/sso.types.js";
|
|
14
14
|
export type { ConnectorsModule } from "./modules/connectors.types.js";
|
|
@@ -1,6 +1,16 @@
|
|
|
1
1
|
import { AxiosInstance } from "axios";
|
|
2
2
|
import { RoomsSocket } from "../utils/socket-utils.js";
|
|
3
3
|
import { ModelFilterParams } from "../types.js";
|
|
4
|
+
/**
|
|
5
|
+
* Registry of agent names.
|
|
6
|
+
* Augment this interface to enable autocomplete for agent names.
|
|
7
|
+
*/
|
|
8
|
+
export interface AgentNameRegistry {
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Agent name type - uses registry keys if augmented, otherwise string.
|
|
12
|
+
*/
|
|
13
|
+
export type AgentName = keyof AgentNameRegistry extends never ? string : keyof AgentNameRegistry;
|
|
4
14
|
/**
|
|
5
15
|
* Reasoning information for an agent message.
|
|
6
16
|
*
|
|
@@ -127,7 +137,7 @@ export interface AgentMessage {
|
|
|
127
137
|
*/
|
|
128
138
|
export interface CreateConversationParams {
|
|
129
139
|
/** The name of the agent to create a conversation with. */
|
|
130
|
-
agent_name:
|
|
140
|
+
agent_name: AgentName;
|
|
131
141
|
/** Optional metadata to attach to the conversation. */
|
|
132
142
|
metadata?: Record<string, any>;
|
|
133
143
|
}
|
|
@@ -171,7 +181,7 @@ export interface AgentsModuleConfig {
|
|
|
171
181
|
*
|
|
172
182
|
* This module is available to use with a client in all authentication modes:
|
|
173
183
|
*
|
|
174
|
-
* - **Anonymous or User authentication** (`base44.agents`): Access is scoped to the current user's permissions.
|
|
184
|
+
* - **Anonymous or User authentication** (`base44.agents`): Access is scoped to the current user's permissions. Users must be authenticated to create and access conversations.
|
|
175
185
|
* - **Service role authentication** (`base44.asServiceRole.agents`): Operations have elevated admin-level permissions. Can access all conversations that the app's admin role has access to.
|
|
176
186
|
*
|
|
177
187
|
*/
|
|
@@ -200,6 +210,8 @@ export interface AgentsModule {
|
|
|
200
210
|
* Retrieves a single conversation using its unique identifier. To retrieve
|
|
201
211
|
* all conversations, use {@linkcode getConversations | getConversations()} To filter, sort, or paginate conversations, use {@linkcode listConversations | listConversations()}.
|
|
202
212
|
*
|
|
213
|
+
* This function returns the complete stored conversation including full tool call results, even for large responses.
|
|
214
|
+
*
|
|
203
215
|
* @param conversationId - The unique identifier of the conversation.
|
|
204
216
|
* @returns Promise resolving to the conversation, or undefined if not found.
|
|
205
217
|
*
|
|
@@ -298,6 +310,10 @@ export interface AgentsModule {
|
|
|
298
310
|
* Establishes a WebSocket connection to receive instant updates when new
|
|
299
311
|
* messages are added to the conversation. Returns an unsubscribe function
|
|
300
312
|
* to clean up the connection.
|
|
313
|
+
*
|
|
314
|
+
* <Note>
|
|
315
|
+
When receiving messages through this function, tool call data is truncated for efficiency. The `arguments_string` is limited to 500 characters and `results` to 50 characters. The complete tool call data is always saved in storage and can be retrieved by calling {@linkcode getConversation | getConversation()} after the message completes.
|
|
316
|
+
</Note>
|
|
301
317
|
*
|
|
302
318
|
* @param conversationId - The conversation ID to subscribe to.
|
|
303
319
|
* @param onUpdate - Callback function called when the conversation is updated. The callback receives a conversation object with the following properties:
|
|
@@ -342,5 +358,5 @@ export interface AgentsModule {
|
|
|
342
358
|
* // User can open this URL to start a WhatsApp conversation
|
|
343
359
|
* ```
|
|
344
360
|
*/
|
|
345
|
-
getWhatsAppConnectURL(agentName:
|
|
361
|
+
getWhatsAppConnectURL(agentName: AgentName): string;
|
|
346
362
|
}
|
package/dist/modules/auth.js
CHANGED
|
@@ -20,7 +20,6 @@ export function createAuthModule(axios, functionsAxiosClient, appId, options) {
|
|
|
20
20
|
},
|
|
21
21
|
// Redirects the user to the app's login page
|
|
22
22
|
redirectToLogin(nextUrl) {
|
|
23
|
-
var _a;
|
|
24
23
|
// This function only works in a browser environment
|
|
25
24
|
if (typeof window === "undefined") {
|
|
26
25
|
throw new Error("Login method can only be used in a browser environment");
|
|
@@ -30,7 +29,7 @@ export function createAuthModule(axios, functionsAxiosClient, appId, options) {
|
|
|
30
29
|
? new URL(nextUrl, window.location.origin).toString()
|
|
31
30
|
: window.location.href;
|
|
32
31
|
// Build the login URL
|
|
33
|
-
const loginUrl = `${
|
|
32
|
+
const loginUrl = `${options.appBaseUrl}/login?from_url=${encodeURIComponent(redirectUrl)}`;
|
|
34
33
|
// Redirect to the login page
|
|
35
34
|
window.location.href = loginUrl;
|
|
36
35
|
},
|
|
@@ -64,7 +63,7 @@ export function createAuthModule(axios, functionsAxiosClient, appId, options) {
|
|
|
64
63
|
// Determine the from_url parameter
|
|
65
64
|
const fromUrl = redirectUrl || window.location.href;
|
|
66
65
|
// Redirect to server-side logout endpoint to clear HTTP-only cookies
|
|
67
|
-
const logoutUrl = `${options.appBaseUrl}/api/apps
|
|
66
|
+
const logoutUrl = `${options.appBaseUrl}/api/apps/auth/logout?from_url=${encodeURIComponent(fromUrl)}`;
|
|
68
67
|
window.location.href = logoutUrl;
|
|
69
68
|
}
|
|
70
69
|
},
|
|
@@ -90,8 +90,8 @@ export interface ResetPasswordParams {
|
|
|
90
90
|
export interface AuthModuleOptions {
|
|
91
91
|
/** Server URL for API requests. */
|
|
92
92
|
serverUrl: string;
|
|
93
|
-
/**
|
|
94
|
-
appBaseUrl
|
|
93
|
+
/** Base URL for the app (used for login redirects). */
|
|
94
|
+
appBaseUrl: string;
|
|
95
95
|
}
|
|
96
96
|
/**
|
|
97
97
|
* Authentication module for managing user authentication and authorization. The module automatically stores tokens in local storage when available and manages authorization headers for API requests.
|
|
@@ -1,7 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Registry of connector integration types.
|
|
3
|
+
* Augment this interface to enable autocomplete for connector integration types.
|
|
4
|
+
*/
|
|
5
|
+
export interface ConnectorIntegrationTypeRegistry {
|
|
6
|
+
}
|
|
1
7
|
/**
|
|
2
8
|
* The type of external integration/connector, such as `'googlecalendar'`, `'slack'`, or `'github'`.
|
|
9
|
+
* Uses registry keys if augmented, otherwise falls back to string.
|
|
3
10
|
*/
|
|
4
|
-
export type ConnectorIntegrationType = string;
|
|
11
|
+
export type ConnectorIntegrationType = keyof ConnectorIntegrationTypeRegistry extends never ? string : keyof ConnectorIntegrationTypeRegistry;
|
|
5
12
|
/**
|
|
6
13
|
* Response from the connectors access token endpoint.
|
|
7
14
|
*/
|
|
@@ -4,12 +4,14 @@
|
|
|
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
|
-
export interface RealtimeEvent {
|
|
10
|
+
export interface RealtimeEvent<T = any> {
|
|
9
11
|
/** The type of change that occurred */
|
|
10
12
|
type: RealtimeEventType;
|
|
11
13
|
/** The entity data */
|
|
12
|
-
data:
|
|
14
|
+
data: T;
|
|
13
15
|
/** The unique identifier of the affected entity */
|
|
14
16
|
id: string;
|
|
15
17
|
/** ISO 8601 timestamp of when the event occurred */
|
|
@@ -17,14 +19,94 @@ export interface RealtimeEvent {
|
|
|
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`.
|
|
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`.
|
|
20
46
|
*/
|
|
21
|
-
export
|
|
47
|
+
export interface ImportResult<T = any> {
|
|
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}`;
|
|
73
|
+
/**
|
|
74
|
+
* Fields added by the server to every entity record (id, dates, created_by, etc.).
|
|
75
|
+
*/
|
|
76
|
+
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
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Registry mapping entity names to their TypeScript types.
|
|
92
|
+
* Augment this interface with your entity schema (user-defined fields only).
|
|
93
|
+
*/
|
|
94
|
+
export interface EntityTypeRegistry {
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Full record type for each entity: schema fields + server-injected fields (id, created_date, etc.).
|
|
98
|
+
*/
|
|
99
|
+
export type EntityRecord = {
|
|
100
|
+
[K in keyof EntityTypeRegistry]: EntityTypeRegistry[K] & ServerEntityFields;
|
|
101
|
+
};
|
|
22
102
|
/**
|
|
23
103
|
* Entity handler providing CRUD operations for a specific entity type.
|
|
24
104
|
*
|
|
25
105
|
* Each entity in the app gets a handler with these methods for managing data.
|
|
106
|
+
*
|
|
107
|
+
* @typeParam T - The entity type. Defaults to `any` for backward compatibility.
|
|
26
108
|
*/
|
|
27
|
-
export interface EntityHandler {
|
|
109
|
+
export interface EntityHandler<T = any> {
|
|
28
110
|
/**
|
|
29
111
|
* Lists records with optional pagination and sorting.
|
|
30
112
|
*
|
|
@@ -33,11 +115,12 @@ export interface EntityHandler {
|
|
|
33
115
|
*
|
|
34
116
|
* **Note:** The maximum limit is 5,000 items per request.
|
|
35
117
|
*
|
|
118
|
+
* @typeParam K - The fields to include in the response. Defaults to all fields.
|
|
36
119
|
* @param sort - Sort parameter, such as `'-created_date'` for descending. Defaults to `'-created_date'`.
|
|
37
120
|
* @param limit - Maximum number of results to return. Defaults to `50`.
|
|
38
121
|
* @param skip - Number of results to skip for pagination. Defaults to `0`.
|
|
39
122
|
* @param fields - Array of field names to include in the response. Defaults to all fields.
|
|
40
|
-
* @returns Promise resolving to an array of records.
|
|
123
|
+
* @returns Promise resolving to an array of records with selected fields.
|
|
41
124
|
*
|
|
42
125
|
* @example
|
|
43
126
|
* ```typescript
|
|
@@ -64,7 +147,7 @@ export interface EntityHandler {
|
|
|
64
147
|
* const fields = await base44.entities.MyEntity.list('-created_date', 10, 0, ['name', 'status']);
|
|
65
148
|
* ```
|
|
66
149
|
*/
|
|
67
|
-
list(sort?:
|
|
150
|
+
list<K extends keyof T = keyof T>(sort?: SortField<T>, limit?: number, skip?: number, fields?: K[]): Promise<Pick<T, K>[]>;
|
|
68
151
|
/**
|
|
69
152
|
* Filters records based on a query.
|
|
70
153
|
*
|
|
@@ -73,6 +156,7 @@ export interface EntityHandler {
|
|
|
73
156
|
*
|
|
74
157
|
* **Note:** The maximum limit is 5,000 items per request.
|
|
75
158
|
*
|
|
159
|
+
* @typeParam K - The fields to include in the response. Defaults to all fields.
|
|
76
160
|
* @param query - Query object with field-value pairs. Each key should be a field name
|
|
77
161
|
* from your entity schema, and each value is the criteria to match. Records matching all
|
|
78
162
|
* specified criteria are returned. Field names are case-sensitive.
|
|
@@ -80,7 +164,7 @@ export interface EntityHandler {
|
|
|
80
164
|
* @param limit - Maximum number of results to return. Defaults to `50`.
|
|
81
165
|
* @param skip - Number of results to skip for pagination. Defaults to `0`.
|
|
82
166
|
* @param fields - Array of field names to include in the response. Defaults to all fields.
|
|
83
|
-
* @returns Promise resolving to an array of filtered records.
|
|
167
|
+
* @returns Promise resolving to an array of filtered records with selected fields.
|
|
84
168
|
*
|
|
85
169
|
* @example
|
|
86
170
|
* ```typescript
|
|
@@ -122,7 +206,7 @@ export interface EntityHandler {
|
|
|
122
206
|
* );
|
|
123
207
|
* ```
|
|
124
208
|
*/
|
|
125
|
-
filter(query:
|
|
209
|
+
filter<K extends keyof T = keyof T>(query: Partial<T>, sort?: SortField<T>, limit?: number, skip?: number, fields?: K[]): Promise<Pick<T, K>[]>;
|
|
126
210
|
/**
|
|
127
211
|
* Gets a single record by ID.
|
|
128
212
|
*
|
|
@@ -138,7 +222,7 @@ export interface EntityHandler {
|
|
|
138
222
|
* console.log(record.name);
|
|
139
223
|
* ```
|
|
140
224
|
*/
|
|
141
|
-
get(id: string): Promise<
|
|
225
|
+
get(id: string): Promise<T>;
|
|
142
226
|
/**
|
|
143
227
|
* Creates a new record.
|
|
144
228
|
*
|
|
@@ -158,7 +242,7 @@ export interface EntityHandler {
|
|
|
158
242
|
* console.log('Created record with ID:', newRecord.id);
|
|
159
243
|
* ```
|
|
160
244
|
*/
|
|
161
|
-
create(data:
|
|
245
|
+
create(data: Partial<T>): Promise<T>;
|
|
162
246
|
/**
|
|
163
247
|
* Updates an existing record.
|
|
164
248
|
*
|
|
@@ -187,7 +271,7 @@ export interface EntityHandler {
|
|
|
187
271
|
* });
|
|
188
272
|
* ```
|
|
189
273
|
*/
|
|
190
|
-
update(id: string, data:
|
|
274
|
+
update(id: string, data: Partial<T>): Promise<T>;
|
|
191
275
|
/**
|
|
192
276
|
* Deletes a single record by ID.
|
|
193
277
|
*
|
|
@@ -200,10 +284,10 @@ export interface EntityHandler {
|
|
|
200
284
|
* ```typescript
|
|
201
285
|
* // Delete a record
|
|
202
286
|
* const result = await base44.entities.MyEntity.delete('entity-123');
|
|
203
|
-
* console.log('Deleted:', result);
|
|
287
|
+
* console.log('Deleted:', result.success);
|
|
204
288
|
* ```
|
|
205
289
|
*/
|
|
206
|
-
delete(id: string): Promise<
|
|
290
|
+
delete(id: string): Promise<DeleteResult>;
|
|
207
291
|
/**
|
|
208
292
|
* Deletes multiple records matching a query.
|
|
209
293
|
*
|
|
@@ -221,10 +305,10 @@ export interface EntityHandler {
|
|
|
221
305
|
* status: 'completed',
|
|
222
306
|
* priority: 'low'
|
|
223
307
|
* });
|
|
224
|
-
* console.log('Deleted:', result);
|
|
308
|
+
* console.log('Deleted:', result.deleted);
|
|
225
309
|
* ```
|
|
226
310
|
*/
|
|
227
|
-
deleteMany(query:
|
|
311
|
+
deleteMany(query: Partial<T>): Promise<DeleteManyResult>;
|
|
228
312
|
/**
|
|
229
313
|
* Creates multiple records in a single request.
|
|
230
314
|
*
|
|
@@ -244,7 +328,7 @@ export interface EntityHandler {
|
|
|
244
328
|
* ]);
|
|
245
329
|
* ```
|
|
246
330
|
*/
|
|
247
|
-
bulkCreate(data:
|
|
331
|
+
bulkCreate(data: Partial<T>[]): Promise<T[]>;
|
|
248
332
|
/**
|
|
249
333
|
* Imports records from a file.
|
|
250
334
|
*
|
|
@@ -252,7 +336,7 @@ export interface EntityHandler {
|
|
|
252
336
|
* The file format should match your entity structure. Requires a browser environment and can't be used in the backend.
|
|
253
337
|
*
|
|
254
338
|
* @param file - File object to import.
|
|
255
|
-
* @returns Promise resolving to the import result.
|
|
339
|
+
* @returns Promise resolving to the import result containing status, details, and created records.
|
|
256
340
|
*
|
|
257
341
|
* @example
|
|
258
342
|
* ```typescript
|
|
@@ -261,12 +345,14 @@ export interface EntityHandler {
|
|
|
261
345
|
* const file = event.target.files?.[0];
|
|
262
346
|
* if (file) {
|
|
263
347
|
* const result = await base44.entities.MyEntity.importEntities(file);
|
|
264
|
-
*
|
|
348
|
+
* if (result.status === 'success' && result.output) {
|
|
349
|
+
* console.log(`Imported ${result.output.length} records`);
|
|
350
|
+
* }
|
|
265
351
|
* }
|
|
266
352
|
* };
|
|
267
353
|
* ```
|
|
268
354
|
*/
|
|
269
|
-
importEntities(file: File): Promise<
|
|
355
|
+
importEntities(file: File): Promise<ImportResult<T>>;
|
|
270
356
|
/**
|
|
271
357
|
* Subscribes to realtime updates for all records of this entity type.
|
|
272
358
|
*
|
|
@@ -292,8 +378,20 @@ export interface EntityHandler {
|
|
|
292
378
|
* unsubscribe();
|
|
293
379
|
* ```
|
|
294
380
|
*/
|
|
295
|
-
subscribe(callback: RealtimeCallback): () => void;
|
|
381
|
+
subscribe(callback: RealtimeCallback<T>): () => void;
|
|
296
382
|
}
|
|
383
|
+
/**
|
|
384
|
+
* Typed entities module - maps registry keys to typed handlers (full record type).
|
|
385
|
+
*/
|
|
386
|
+
type TypedEntitiesModule = {
|
|
387
|
+
[K in keyof EntityTypeRegistry]: EntityHandler<EntityRecord[K]>;
|
|
388
|
+
};
|
|
389
|
+
/**
|
|
390
|
+
* Dynamic entities module - allows any entity name with untyped handler.
|
|
391
|
+
*/
|
|
392
|
+
type DynamicEntitiesModule = {
|
|
393
|
+
[entityName: string]: EntityHandler<any>;
|
|
394
|
+
};
|
|
297
395
|
/**
|
|
298
396
|
* Entities module for managing app data.
|
|
299
397
|
*
|
|
@@ -327,18 +425,5 @@ export interface EntityHandler {
|
|
|
327
425
|
* const allUsers = await base44.asServiceRole.entities.User.list();
|
|
328
426
|
* ```
|
|
329
427
|
*/
|
|
330
|
-
export
|
|
331
|
-
|
|
332
|
-
* Access any entity by name.
|
|
333
|
-
*
|
|
334
|
-
* Use this to access entities defined in the app.
|
|
335
|
-
*
|
|
336
|
-
* @example
|
|
337
|
-
* ```typescript
|
|
338
|
-
* // Access entities dynamically
|
|
339
|
-
* base44.entities.MyEntity
|
|
340
|
-
* base44.entities.AnotherEntity
|
|
341
|
-
* ```
|
|
342
|
-
*/
|
|
343
|
-
[entityName: string]: EntityHandler;
|
|
344
|
-
}
|
|
428
|
+
export type EntitiesModule = TypedEntitiesModule & DynamicEntitiesModule;
|
|
429
|
+
export {};
|
|
@@ -1,3 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Registry of function names.
|
|
3
|
+
* Augment this interface to enable autocomplete for function names.
|
|
4
|
+
*/
|
|
5
|
+
export interface FunctionNameRegistry {
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Function name type - uses registry keys if augmented, otherwise string.
|
|
9
|
+
*/
|
|
10
|
+
export type FunctionName = keyof FunctionNameRegistry extends never ? string : keyof FunctionNameRegistry;
|
|
1
11
|
/**
|
|
2
12
|
* Functions module for invoking custom backend functions.
|
|
3
13
|
*
|
|
@@ -46,5 +56,5 @@ export interface FunctionsModule {
|
|
|
46
56
|
* };
|
|
47
57
|
* ```
|
|
48
58
|
*/
|
|
49
|
-
invoke(functionName:
|
|
59
|
+
invoke(functionName: FunctionName, data?: Record<string, any>): Promise<any>;
|
|
50
60
|
}
|