@base44/sdk 0.8.17 → 0.8.19
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 +84 -12
- package/dist/client.d.ts +9 -5
- package/dist/client.js +13 -7
- package/dist/client.types.d.ts +22 -19
- package/dist/index.d.ts +3 -3
- package/dist/modules/agents.js +29 -10
- package/dist/modules/agents.types.d.ts +34 -12
- package/dist/modules/analytics.types.d.ts +79 -3
- package/dist/modules/auth.js +28 -21
- package/dist/modules/auth.types.d.ts +28 -2
- package/dist/modules/connectors.types.d.ts +12 -7
- package/dist/modules/custom-integrations.types.d.ts +38 -54
- package/dist/modules/entities.types.d.ts +132 -41
- package/dist/modules/functions.types.d.ts +11 -1
- package/dist/modules/integrations.types.d.ts +17 -26
- package/package.json +3 -2
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,34 +29,42 @@ 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
|
},
|
|
36
|
+
// Redirects the user to a provider's login page
|
|
37
|
+
loginWithProvider(provider, fromUrl = "/") {
|
|
38
|
+
// Build the full redirect URL
|
|
39
|
+
const redirectUrl = new URL(fromUrl, window.location.origin).toString();
|
|
40
|
+
// Build the provider login URL (google is the default, so no provider path needed)
|
|
41
|
+
const providerPath = provider === "google" ? "" : `/${provider}`;
|
|
42
|
+
const loginUrl = `${options.appBaseUrl}/api/apps/auth${providerPath}/login?app_id=${appId}&from_url=${encodeURIComponent(redirectUrl)}`;
|
|
43
|
+
// Redirect to the provider login page
|
|
44
|
+
window.location.href = loginUrl;
|
|
45
|
+
},
|
|
37
46
|
// Logout the current user
|
|
38
|
-
// Removes the token from localStorage and optionally redirects to a URL or reloads the page
|
|
39
47
|
logout(redirectUrl) {
|
|
40
|
-
// Remove token from axios headers
|
|
48
|
+
// Remove token from axios headers (always do this)
|
|
41
49
|
delete axios.defaults.headers.common["Authorization"];
|
|
42
|
-
//
|
|
43
|
-
if (typeof window !== "undefined" && window.localStorage) {
|
|
44
|
-
try {
|
|
45
|
-
window.localStorage.removeItem("base44_access_token");
|
|
46
|
-
// Remove "token" that is set by the built-in SDK of platform version 2
|
|
47
|
-
window.localStorage.removeItem("token");
|
|
48
|
-
}
|
|
49
|
-
catch (e) {
|
|
50
|
-
console.error("Failed to remove token from localStorage:", e);
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
// Redirect if a URL is provided
|
|
50
|
+
// Only do the rest if in a browser environment
|
|
54
51
|
if (typeof window !== "undefined") {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
52
|
+
// Remove token from localStorage
|
|
53
|
+
if (window.localStorage) {
|
|
54
|
+
try {
|
|
55
|
+
window.localStorage.removeItem("base44_access_token");
|
|
56
|
+
// Remove "token" that is set by the built-in SDK of platform version 2
|
|
57
|
+
window.localStorage.removeItem("token");
|
|
58
|
+
}
|
|
59
|
+
catch (e) {
|
|
60
|
+
console.error("Failed to remove token from localStorage:", e);
|
|
61
|
+
}
|
|
60
62
|
}
|
|
63
|
+
// Determine the from_url parameter
|
|
64
|
+
const fromUrl = redirectUrl || window.location.href;
|
|
65
|
+
// Redirect to server-side logout endpoint to clear HTTP-only cookies
|
|
66
|
+
const logoutUrl = `${options.appBaseUrl}/api/apps/auth/logout?from_url=${encodeURIComponent(fromUrl)}`;
|
|
67
|
+
window.location.href = logoutUrl;
|
|
61
68
|
}
|
|
62
69
|
},
|
|
63
70
|
// Set authentication token
|
|
@@ -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.
|
|
@@ -171,6 +171,32 @@ export interface AuthModule {
|
|
|
171
171
|
* ```
|
|
172
172
|
*/
|
|
173
173
|
redirectToLogin(nextUrl: string): void;
|
|
174
|
+
/**
|
|
175
|
+
* Redirects the user to a third-party authentication provider's login page.
|
|
176
|
+
*
|
|
177
|
+
* Initiates an OAuth login flow with one of the built-in providers. Requires a browser environment and can't be used in the backend.
|
|
178
|
+
*
|
|
179
|
+
* Supported providers:
|
|
180
|
+
* - `'google'` - {@link https://developers.google.com/identity/protocols/oauth2 | Google OAuth}. Enabled by default.
|
|
181
|
+
* - `'microsoft'` - {@link https://learn.microsoft.com/en-us/entra/identity-platform/v2-oauth2-auth-code-flow | Microsoft OAuth}. Enable Microsoft in your app's authentication settings before specifying this provider.
|
|
182
|
+
* - `'facebook'` - {@link https://developers.facebook.com/docs/facebook-login | Facebook Login}. Enable this in your app's authentication settings before using.
|
|
183
|
+
*
|
|
184
|
+
* @param provider - The authentication provider to use: `'google'`, `'microsoft'`, or `'facebook'`.
|
|
185
|
+
* @param fromUrl - URL to redirect to after successful authentication. Defaults to `'/'`.
|
|
186
|
+
*
|
|
187
|
+
* @example
|
|
188
|
+
* ```typescript
|
|
189
|
+
* // Login with Google and return to current page
|
|
190
|
+
* base44.auth.loginWithProvider('google', window.location.pathname);
|
|
191
|
+
* ```
|
|
192
|
+
*
|
|
193
|
+
* @example
|
|
194
|
+
* ```typescript
|
|
195
|
+
* // Login with Microsoft and redirect to dashboard
|
|
196
|
+
* base44.auth.loginWithProvider('microsoft', '/dashboard');
|
|
197
|
+
* ```
|
|
198
|
+
*/
|
|
199
|
+
loginWithProvider(provider: string, fromUrl?: string): void;
|
|
174
200
|
/**
|
|
175
201
|
* Logs out the current user.
|
|
176
202
|
*
|
|
@@ -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
|
*/
|
|
@@ -11,9 +18,7 @@ export interface ConnectorAccessTokenResponse {
|
|
|
11
18
|
/**
|
|
12
19
|
* Connectors module for managing OAuth tokens for external services.
|
|
13
20
|
*
|
|
14
|
-
* This module allows you to retrieve OAuth access tokens for external services
|
|
15
|
-
* that the app has connected to. Use these tokens to make API
|
|
16
|
-
* calls to external services.
|
|
21
|
+
* This module allows you to retrieve OAuth access tokens for external services that the app has connected to. Connectors are app-scoped. When an app builder connects an integration like Google Calendar or Slack, all users of the app share that same connection.
|
|
17
22
|
*
|
|
18
23
|
* Unlike the integrations module that provides pre-built functions, connectors give you
|
|
19
24
|
* raw OAuth tokens so you can call external service APIs directly with full control over
|
|
@@ -26,9 +31,9 @@ export interface ConnectorsModule {
|
|
|
26
31
|
/**
|
|
27
32
|
* Retrieves an OAuth access token for a specific external integration type.
|
|
28
33
|
*
|
|
29
|
-
* Returns the OAuth token string for an external service that
|
|
30
|
-
* has connected to.
|
|
31
|
-
* to that external service.
|
|
34
|
+
* Returns the OAuth token string for an external service that an app builder
|
|
35
|
+
* has connected to. This token represents the connected app builder's account
|
|
36
|
+
* and can be used to make authenticated API calls to that external service on behalf of the app.
|
|
32
37
|
*
|
|
33
38
|
* @param integrationType - The type of integration, such as `'googlecalendar'`, `'slack'`, or `'github'`.
|
|
34
39
|
* @returns Promise resolving to the access token string.
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Parameters for calling a custom integration endpoint.
|
|
3
|
+
* @internal
|
|
3
4
|
*/
|
|
4
5
|
export interface CustomIntegrationCallParams {
|
|
5
6
|
/**
|
|
@@ -7,21 +8,17 @@ export interface CustomIntegrationCallParams {
|
|
|
7
8
|
*/
|
|
8
9
|
payload?: Record<string, any>;
|
|
9
10
|
/**
|
|
10
|
-
* Path parameters to substitute in the URL
|
|
11
|
+
* Path parameters to substitute in the URL. For example, `{ owner: "user", repo: "repo" }`.
|
|
11
12
|
*/
|
|
12
13
|
pathParams?: Record<string, string>;
|
|
13
14
|
/**
|
|
14
15
|
* Query string parameters to append to the URL.
|
|
15
16
|
*/
|
|
16
17
|
queryParams?: Record<string, any>;
|
|
17
|
-
/**
|
|
18
|
-
* Additional headers to send with this specific request.
|
|
19
|
-
* These are merged with the integration's configured headers.
|
|
20
|
-
*/
|
|
21
|
-
headers?: Record<string, string>;
|
|
22
18
|
}
|
|
23
19
|
/**
|
|
24
20
|
* Response from a custom integration call.
|
|
21
|
+
* @internal
|
|
25
22
|
*/
|
|
26
23
|
export interface CustomIntegrationCallResponse {
|
|
27
24
|
/**
|
|
@@ -39,60 +36,17 @@ export interface CustomIntegrationCallResponse {
|
|
|
39
36
|
data: any;
|
|
40
37
|
}
|
|
41
38
|
/**
|
|
42
|
-
* Module for calling custom
|
|
43
|
-
*
|
|
44
|
-
* Custom integrations allow workspace administrators to connect any external API
|
|
45
|
-
* by importing an OpenAPI specification. Apps in the workspace can then call
|
|
46
|
-
* these integrations using this module.
|
|
47
|
-
*
|
|
48
|
-
* Unlike the built-in integrations (like `Core`), custom integrations:
|
|
49
|
-
* - Are defined per-workspace by importing OpenAPI specs
|
|
50
|
-
* - Use a slug-based identifier instead of package names
|
|
51
|
-
* - Proxy requests through Base44's backend (credentials never exposed to frontend)
|
|
52
|
-
*
|
|
53
|
-
* @example
|
|
54
|
-
* ```typescript
|
|
55
|
-
* // Call a custom GitHub integration
|
|
56
|
-
* const response = await base44.integrations.custom.call(
|
|
57
|
-
* "github", // integration slug (defined by workspace admin)
|
|
58
|
-
* "listIssues", // operation ID from the OpenAPI spec
|
|
59
|
-
* {
|
|
60
|
-
* pathParams: { owner: "myorg", repo: "myrepo" },
|
|
61
|
-
* queryParams: { state: "open", per_page: 100 }
|
|
62
|
-
* }
|
|
63
|
-
* );
|
|
39
|
+
* Module for calling custom pre-configured API integrations.
|
|
64
40
|
*
|
|
65
|
-
*
|
|
66
|
-
* console.log("Issues:", response.data);
|
|
67
|
-
* } else {
|
|
68
|
-
* console.error("API returned error:", response.status_code);
|
|
69
|
-
* }
|
|
70
|
-
* ```
|
|
71
|
-
*
|
|
72
|
-
* @example
|
|
73
|
-
* ```typescript
|
|
74
|
-
* // Call with request body payload
|
|
75
|
-
* const response = await base44.integrations.custom.call(
|
|
76
|
-
* "github",
|
|
77
|
-
* "createIssue",
|
|
78
|
-
* {
|
|
79
|
-
* pathParams: { owner: "myorg", repo: "myrepo" },
|
|
80
|
-
* payload: {
|
|
81
|
-
* title: "Bug report",
|
|
82
|
-
* body: "Something is broken",
|
|
83
|
-
* labels: ["bug"]
|
|
84
|
-
* }
|
|
85
|
-
* }
|
|
86
|
-
* );
|
|
87
|
-
* ```
|
|
41
|
+
* Custom integrations allow workspace administrators to connect any external API by importing an OpenAPI specification. Apps in the workspace can then call these integrations using this module.
|
|
88
42
|
*/
|
|
89
43
|
export interface CustomIntegrationsModule {
|
|
90
44
|
/**
|
|
91
45
|
* Call a custom integration endpoint.
|
|
92
46
|
*
|
|
93
|
-
* @param slug - The integration's unique identifier
|
|
94
|
-
* @param operationId - The
|
|
95
|
-
* @param params - Optional parameters including payload, pathParams,
|
|
47
|
+
* @param slug - The integration's unique identifier, as defined by the workspace admin.
|
|
48
|
+
* @param operationId - The endpoint in `method:path` format. For example, `"get:/contacts"`, or `"post:/users/{id}"`. The method is the HTTP verb in lowercase and the path matches the OpenAPI specification.
|
|
49
|
+
* @param params - Optional parameters including payload, pathParams, and queryParams.
|
|
96
50
|
* @returns Promise resolving to the integration call response.
|
|
97
51
|
*
|
|
98
52
|
* @throws {Error} If slug is not provided.
|
|
@@ -100,6 +54,36 @@ export interface CustomIntegrationsModule {
|
|
|
100
54
|
* @throws {Base44Error} If the integration or operation is not found (404).
|
|
101
55
|
* @throws {Base44Error} If the external API call fails (502).
|
|
102
56
|
* @throws {Base44Error} If the request times out (504).
|
|
57
|
+
*
|
|
58
|
+
* @example
|
|
59
|
+
* ```typescript
|
|
60
|
+
* // Call a custom CRM integration
|
|
61
|
+
* const response = await base44.integrations.custom.call(
|
|
62
|
+
* "my-crm",
|
|
63
|
+
* "get:/contacts",
|
|
64
|
+
* { queryParams: { limit: 10 } }
|
|
65
|
+
* );
|
|
66
|
+
*
|
|
67
|
+
* if (response.success) {
|
|
68
|
+
* console.log("Contacts:", response.data);
|
|
69
|
+
* }
|
|
70
|
+
* ```
|
|
71
|
+
*
|
|
72
|
+
* @example
|
|
73
|
+
* ```typescript
|
|
74
|
+
* // Call with path params and request body
|
|
75
|
+
* const response = await base44.integrations.custom.call(
|
|
76
|
+
* "github",
|
|
77
|
+
* "post:/repos/{owner}/{repo}/issues",
|
|
78
|
+
* {
|
|
79
|
+
* pathParams: { owner: "myorg", repo: "myrepo" },
|
|
80
|
+
* payload: {
|
|
81
|
+
* title: "Bug report",
|
|
82
|
+
* body: "Something is broken"
|
|
83
|
+
* }
|
|
84
|
+
* }
|
|
85
|
+
* );
|
|
86
|
+
* ```
|
|
103
87
|
*/
|
|
104
88
|
call(slug: string, operationId: string, params?: CustomIntegrationCallParams): Promise<CustomIntegrationCallResponse>;
|
|
105
89
|
}
|
|
@@ -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,29 +19,108 @@ 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
|
+
}
|
|
22
55
|
/**
|
|
23
|
-
*
|
|
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
|
+
* ```
|
|
24
71
|
*/
|
|
25
|
-
export type
|
|
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
|
+
};
|
|
26
102
|
/**
|
|
27
103
|
* Entity handler providing CRUD operations for a specific entity type.
|
|
28
104
|
*
|
|
29
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.
|
|
30
108
|
*/
|
|
31
|
-
export interface EntityHandler {
|
|
109
|
+
export interface EntityHandler<T = any> {
|
|
32
110
|
/**
|
|
33
111
|
* Lists records with optional pagination and sorting.
|
|
34
112
|
*
|
|
35
113
|
* Retrieves all records of this type with support for sorting,
|
|
36
114
|
* pagination, and field selection.
|
|
37
115
|
*
|
|
116
|
+
* **Note:** The maximum limit is 5,000 items per request.
|
|
117
|
+
*
|
|
118
|
+
* @typeParam K - The fields to include in the response. Defaults to all fields.
|
|
38
119
|
* @param sort - Sort parameter, such as `'-created_date'` for descending. Defaults to `'-created_date'`.
|
|
39
120
|
* @param limit - Maximum number of results to return. Defaults to `50`.
|
|
40
121
|
* @param skip - Number of results to skip for pagination. Defaults to `0`.
|
|
41
122
|
* @param fields - Array of field names to include in the response. Defaults to all fields.
|
|
42
|
-
* @returns Promise resolving to an array of records.
|
|
123
|
+
* @returns Promise resolving to an array of records with selected fields.
|
|
43
124
|
*
|
|
44
125
|
* @example
|
|
45
126
|
* ```typescript
|
|
@@ -66,13 +147,16 @@ export interface EntityHandler {
|
|
|
66
147
|
* const fields = await base44.entities.MyEntity.list('-created_date', 10, 0, ['name', 'status']);
|
|
67
148
|
* ```
|
|
68
149
|
*/
|
|
69
|
-
list(sort?:
|
|
150
|
+
list<K extends keyof T = keyof T>(sort?: SortField<T>, limit?: number, skip?: number, fields?: K[]): Promise<Pick<T, K>[]>;
|
|
70
151
|
/**
|
|
71
152
|
* Filters records based on a query.
|
|
72
153
|
*
|
|
73
154
|
* Retrieves records that match specific criteria with support for
|
|
74
155
|
* sorting, pagination, and field selection.
|
|
75
156
|
*
|
|
157
|
+
* **Note:** The maximum limit is 5,000 items per request.
|
|
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,19 +345,27 @@ 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
|
*
|
|
273
|
-
*
|
|
359
|
+
* Establishes a WebSocket connection to receive instant updates when any
|
|
360
|
+
* record is created, updated, or deleted. Returns an unsubscribe function
|
|
361
|
+
* to clean up the connection.
|
|
274
362
|
*
|
|
275
|
-
* @param callback -
|
|
276
|
-
*
|
|
363
|
+
* @param callback - Callback function called when an entity changes. The callback receives an event object with the following properties:
|
|
364
|
+
* - `type`: The type of change that occurred - `'create'`, `'update'`, or `'delete'`.
|
|
365
|
+
* - `data`: The entity data after the change.
|
|
366
|
+
* - `id`: The unique identifier of the affected entity.
|
|
367
|
+
* - `timestamp`: ISO 8601 timestamp of when the event occurred.
|
|
368
|
+
* @returns Unsubscribe function to stop receiving updates.
|
|
277
369
|
*
|
|
278
370
|
* @example
|
|
279
371
|
* ```typescript
|
|
@@ -282,12 +374,24 @@ export interface EntityHandler {
|
|
|
282
374
|
* console.log(`Task ${event.id} was ${event.type}d:`, event.data);
|
|
283
375
|
* });
|
|
284
376
|
*
|
|
285
|
-
* // Later,
|
|
377
|
+
* // Later, clean up the subscription
|
|
286
378
|
* unsubscribe();
|
|
287
379
|
* ```
|
|
288
380
|
*/
|
|
289
|
-
subscribe(callback: RealtimeCallback):
|
|
381
|
+
subscribe(callback: RealtimeCallback<T>): () => void;
|
|
290
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
|
+
};
|
|
291
395
|
/**
|
|
292
396
|
* Entities module for managing app data.
|
|
293
397
|
*
|
|
@@ -321,18 +425,5 @@ export interface EntityHandler {
|
|
|
321
425
|
* const allUsers = await base44.asServiceRole.entities.User.list();
|
|
322
426
|
* ```
|
|
323
427
|
*/
|
|
324
|
-
export
|
|
325
|
-
|
|
326
|
-
* Access any entity by name.
|
|
327
|
-
*
|
|
328
|
-
* Use this to access entities defined in the app.
|
|
329
|
-
*
|
|
330
|
-
* @example
|
|
331
|
-
* ```typescript
|
|
332
|
-
* // Access entities dynamically
|
|
333
|
-
* base44.entities.MyEntity
|
|
334
|
-
* base44.entities.AnotherEntity
|
|
335
|
-
* ```
|
|
336
|
-
*/
|
|
337
|
-
[entityName: string]: EntityHandler;
|
|
338
|
-
}
|
|
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
|
}
|