@base44-preview/sdk 0.8.17-pr.77.dfc0f63 → 0.8.18-pr.70.4e2bede
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 +67 -4
- package/dist/client.d.ts +9 -5
- package/dist/client.js +11 -9
- package/dist/client.types.d.ts +8 -2
- package/dist/index.d.ts +1 -1
- package/dist/modules/agents.js +29 -10
- package/dist/modules/agents.types.d.ts +15 -9
- package/dist/modules/analytics.types.d.ts +3 -0
- package/dist/modules/auth.js +11 -13
- package/dist/modules/auth.types.d.ts +21 -0
- package/dist/modules/connectors.types.d.ts +4 -6
- package/dist/modules/custom-integrations.types.d.ts +38 -54
- package/dist/modules/entities.types.d.ts +15 -9
- package/dist/modules/integrations.types.d.ts +17 -26
- package/package.json +3 -1
package/README.md
CHANGED
|
@@ -1,6 +1,21 @@
|
|
|
1
1
|
# Base44 JavaScript SDK
|
|
2
2
|
|
|
3
|
-
The Base44 SDK provides a JavaScript interface for building apps on the Base44 platform.
|
|
3
|
+
The Base44 SDK provides a JavaScript interface for building apps on the Base44 platform.
|
|
4
|
+
|
|
5
|
+
You can use it in two ways:
|
|
6
|
+
|
|
7
|
+
- **Inside Base44 apps**: When Base44 generates your app, the SDK is already set up and ready to use.
|
|
8
|
+
- **External apps**: Use the SDK to build your own frontend or backend that uses Base44 as a backend service.
|
|
9
|
+
|
|
10
|
+
## Installation
|
|
11
|
+
|
|
12
|
+
Install the SDK via npm:
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
npm install @base44/sdk
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
> **Note**: In Base44-generated apps, the SDK is already installed for you.
|
|
4
19
|
|
|
5
20
|
## Modules
|
|
6
21
|
|
|
@@ -12,11 +27,15 @@ The SDK provides access to Base44's functionality through the following modules:
|
|
|
12
27
|
- **[`connectors`](https://docs.base44.com/sdk-docs/interfaces/connectors)**: Manage OAuth connections and access tokens for third-party services.
|
|
13
28
|
- **[`entities`](https://docs.base44.com/sdk-docs/interfaces/entities)**: Work with your app's data entities using CRUD operations.
|
|
14
29
|
- **[`functions`](https://docs.base44.com/sdk-docs/interfaces/functions)**: Execute backend functions.
|
|
15
|
-
- **[`integrations`](https://docs.base44.com/sdk-docs/type-aliases/integrations)**: Pre-built
|
|
30
|
+
- **[`integrations`](https://docs.base44.com/sdk-docs/type-aliases/integrations)**: Pre-built integrations for external services.
|
|
16
31
|
|
|
17
|
-
##
|
|
32
|
+
## Quick starts
|
|
18
33
|
|
|
19
|
-
|
|
34
|
+
How you get started depends on your context:
|
|
35
|
+
|
|
36
|
+
### Inside a Base44 app
|
|
37
|
+
|
|
38
|
+
In Base44-generated apps, the client is pre-configured. Just import and use it:
|
|
20
39
|
|
|
21
40
|
```typescript
|
|
22
41
|
import { base44 } from "@/api/base44Client";
|
|
@@ -37,6 +56,45 @@ await base44.entities.Task.update(newTask.id, {
|
|
|
37
56
|
const tasks = await base44.entities.Task.list();
|
|
38
57
|
```
|
|
39
58
|
|
|
59
|
+
### External apps
|
|
60
|
+
|
|
61
|
+
When using Base44 as a backend for your own app, create and configure the client yourself:
|
|
62
|
+
|
|
63
|
+
```typescript
|
|
64
|
+
import { createClient } from '@base44/sdk';
|
|
65
|
+
|
|
66
|
+
// Create a client for your Base44 app
|
|
67
|
+
const base44 = createClient({
|
|
68
|
+
appId: 'your-app-id' // Find this in the Base44 editor URL
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
// Read public data (anonymous access)
|
|
72
|
+
const products = await base44.entities.Products.list();
|
|
73
|
+
|
|
74
|
+
// Authenticate a user (token is automatically set)
|
|
75
|
+
await base44.auth.loginViaEmailPassword('user@example.com', 'password');
|
|
76
|
+
|
|
77
|
+
// Now operations use the authenticated user's permissions
|
|
78
|
+
const userOrders = await base44.entities.Orders.list();
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
### Service role
|
|
82
|
+
|
|
83
|
+
For backend code that needs admin-level access, use the service role. Service role is only available in Base44-hosted backend functions:
|
|
84
|
+
|
|
85
|
+
```typescript
|
|
86
|
+
import { createClientFromRequest } from 'npm:@base44/sdk';
|
|
87
|
+
|
|
88
|
+
Deno.serve(async (req) => {
|
|
89
|
+
const base44 = createClientFromRequest(req);
|
|
90
|
+
|
|
91
|
+
// Access all data with admin-level permissions
|
|
92
|
+
const allOrders = await base44.asServiceRole.entities.Orders.list();
|
|
93
|
+
|
|
94
|
+
return Response.json({ orders: allOrders });
|
|
95
|
+
});
|
|
96
|
+
```
|
|
97
|
+
|
|
40
98
|
## Learn more
|
|
41
99
|
|
|
42
100
|
For complete documentation, guides, and API reference, visit the **[Base44 SDK Documentation](https://docs.base44.com/sdk-getting-started/overview)**.
|
|
@@ -45,6 +103,8 @@ For complete documentation, guides, and API reference, visit the **[Base44 SDK D
|
|
|
45
103
|
|
|
46
104
|
### Build the SDK
|
|
47
105
|
|
|
106
|
+
Build the SDK from source:
|
|
107
|
+
|
|
48
108
|
```bash
|
|
49
109
|
npm install
|
|
50
110
|
npm run build
|
|
@@ -52,6 +112,8 @@ npm run build
|
|
|
52
112
|
|
|
53
113
|
### Run tests
|
|
54
114
|
|
|
115
|
+
Run the test suite:
|
|
116
|
+
|
|
55
117
|
```bash
|
|
56
118
|
# Run all tests
|
|
57
119
|
npm test
|
|
@@ -64,6 +126,7 @@ npm run test:coverage
|
|
|
64
126
|
```
|
|
65
127
|
|
|
66
128
|
For E2E tests, create a `tests/.env` file with:
|
|
129
|
+
|
|
67
130
|
```
|
|
68
131
|
BASE44_APP_ID=your_app_id
|
|
69
132
|
BASE44_AUTH_TOKEN=your_auth_token
|
package/dist/client.d.ts
CHANGED
|
@@ -5,12 +5,14 @@ export type { Base44Client, CreateClientConfig, CreateClientOptions };
|
|
|
5
5
|
*
|
|
6
6
|
* This is the main entry point for the Base44 SDK. It creates a client that provides access to the SDK's modules, such as {@linkcode EntitiesModule | entities}, {@linkcode AuthModule | auth}, and {@linkcode FunctionsModule | functions}.
|
|
7
7
|
*
|
|
8
|
-
*
|
|
8
|
+
* How you get a client depends on your context:
|
|
9
|
+
* - **Inside a Base44 app:** The client is automatically created and configured for you. Import it from `@/api/base44Client`.
|
|
10
|
+
* - **External app using Base44 as a backend:** Call `createClient()` directly in your code to create and configure the client.
|
|
9
11
|
*
|
|
10
12
|
* The client supports three authentication modes:
|
|
11
|
-
* - **Anonymous**: Access modules
|
|
12
|
-
* - **User authentication**: Access modules with user-level permissions using `base44.moduleName`. Operations are scoped to the authenticated user's data and permissions.
|
|
13
|
-
* - **Service role authentication**: Access modules with elevated permissions using `base44.asServiceRole.moduleName`. Operations can access any data available to the app's admin.
|
|
13
|
+
* - **Anonymous**: Access modules without authentication using `base44.moduleName`. Operations are scoped to public data and permissions.
|
|
14
|
+
* - **User authentication**: Access modules with user-level permissions using `base44.moduleName`. Operations are scoped to the authenticated user's data and permissions. Use `base44.auth.loginViaEmailPassword()` or other auth methods to get a token.
|
|
15
|
+
* - **Service role authentication**: Access modules with elevated permissions using `base44.asServiceRole.moduleName`. Operations can access any data available to the app's admin. Only available in Base44-hosted backend functions. Create a client with service role authentication using {@linkcode createClientFromRequest | createClientFromRequest()}.
|
|
14
16
|
*
|
|
15
17
|
* For example, when using the {@linkcode EntitiesModule | entities} module:
|
|
16
18
|
* - **Anonymous**: Can only read public data.
|
|
@@ -39,7 +41,9 @@ export declare function createClient(config: CreateClientConfig): Base44Client;
|
|
|
39
41
|
/**
|
|
40
42
|
* Creates a Base44 client from an HTTP request.
|
|
41
43
|
*
|
|
42
|
-
*
|
|
44
|
+
* This function is designed for use in Base44-hosted backend functions. For frontends and external backends, use {@linkcode createClient | createClient()} instead.
|
|
45
|
+
*
|
|
46
|
+
* When used in a Base44-hosted backend function, `createClientFromRequest()` automatically extracts authentication tokens from the request headers that Base44 injects when forwarding requests. The returned client includes service role access using `base44.asServiceRole`, which provides admin-level permissions.
|
|
43
47
|
*
|
|
44
48
|
* To learn more about the Base44 client, see {@linkcode createClient | createClient()}.
|
|
45
49
|
*
|
package/dist/client.js
CHANGED
|
@@ -16,12 +16,14 @@ import { createAnalyticsModule } from "./modules/analytics.js";
|
|
|
16
16
|
*
|
|
17
17
|
* This is the main entry point for the Base44 SDK. It creates a client that provides access to the SDK's modules, such as {@linkcode EntitiesModule | entities}, {@linkcode AuthModule | auth}, and {@linkcode FunctionsModule | functions}.
|
|
18
18
|
*
|
|
19
|
-
*
|
|
19
|
+
* How you get a client depends on your context:
|
|
20
|
+
* - **Inside a Base44 app:** The client is automatically created and configured for you. Import it from `@/api/base44Client`.
|
|
21
|
+
* - **External app using Base44 as a backend:** Call `createClient()` directly in your code to create and configure the client.
|
|
20
22
|
*
|
|
21
23
|
* The client supports three authentication modes:
|
|
22
|
-
* - **Anonymous**: Access modules
|
|
23
|
-
* - **User authentication**: Access modules with user-level permissions using `base44.moduleName`. Operations are scoped to the authenticated user's data and permissions.
|
|
24
|
-
* - **Service role authentication**: Access modules with elevated permissions using `base44.asServiceRole.moduleName`. Operations can access any data available to the app's admin.
|
|
24
|
+
* - **Anonymous**: Access modules without authentication using `base44.moduleName`. Operations are scoped to public data and permissions.
|
|
25
|
+
* - **User authentication**: Access modules with user-level permissions using `base44.moduleName`. Operations are scoped to the authenticated user's data and permissions. Use `base44.auth.loginViaEmailPassword()` or other auth methods to get a token.
|
|
26
|
+
* - **Service role authentication**: Access modules with elevated permissions using `base44.asServiceRole.moduleName`. Operations can access any data available to the app's admin. Only available in Base44-hosted backend functions. Create a client with service role authentication using {@linkcode createClientFromRequest | createClientFromRequest()}.
|
|
25
27
|
*
|
|
26
28
|
* For example, when using the {@linkcode EntitiesModule | entities} module:
|
|
27
29
|
* - **Anonymous**: Can only read public data.
|
|
@@ -167,9 +169,7 @@ export function createClient(config) {
|
|
|
167
169
|
}
|
|
168
170
|
}
|
|
169
171
|
// If authentication is required, verify token and redirect to login if needed
|
|
170
|
-
|
|
171
|
-
const isOnLoginPage = typeof window !== "undefined" && window.location.pathname === "/login";
|
|
172
|
-
if (requiresAuth && typeof window !== "undefined" && !isOnLoginPage) {
|
|
172
|
+
if (requiresAuth && typeof window !== "undefined") {
|
|
173
173
|
// We perform this check asynchronously to not block client creation
|
|
174
174
|
setTimeout(async () => {
|
|
175
175
|
try {
|
|
@@ -226,7 +226,7 @@ export function createClient(config) {
|
|
|
226
226
|
/**
|
|
227
227
|
* Provides access to service role modules.
|
|
228
228
|
*
|
|
229
|
-
* Service role authentication provides elevated permissions for
|
|
229
|
+
* Service role authentication provides elevated permissions for backend operations. Unlike user authentication, which is scoped to a specific user's permissions, service role authentication has access to the data and operations available to the app's admin.
|
|
230
230
|
*
|
|
231
231
|
* @throws {Error} When accessed without providing a serviceToken during client creation.
|
|
232
232
|
*
|
|
@@ -253,7 +253,9 @@ export function createClient(config) {
|
|
|
253
253
|
/**
|
|
254
254
|
* Creates a Base44 client from an HTTP request.
|
|
255
255
|
*
|
|
256
|
-
*
|
|
256
|
+
* This function is designed for use in Base44-hosted backend functions. For frontends and external backends, use {@linkcode createClient | createClient()} instead.
|
|
257
|
+
*
|
|
258
|
+
* When used in a Base44-hosted backend function, `createClientFromRequest()` automatically extracts authentication tokens from the request headers that Base44 injects when forwarding requests. The returned client includes service role access using `base44.asServiceRole`, which provides admin-level permissions.
|
|
257
259
|
*
|
|
258
260
|
* To learn more about the Base44 client, see {@linkcode createClient | createClient()}.
|
|
259
261
|
*
|
package/dist/client.types.d.ts
CHANGED
|
@@ -39,10 +39,13 @@ export interface CreateClientConfig {
|
|
|
39
39
|
appId: string;
|
|
40
40
|
/**
|
|
41
41
|
* User authentication token. Used to authenticate as a specific user.
|
|
42
|
+
*
|
|
43
|
+
* Inside Base44 apps, the token is managed automatically. For external apps, use auth methods like {@linkcode AuthModule.loginViaEmailPassword | loginViaEmailPassword()} which set the token automatically.
|
|
42
44
|
*/
|
|
43
45
|
token?: string;
|
|
44
46
|
/**
|
|
45
|
-
* Service role authentication token.
|
|
47
|
+
* Service role authentication token. Provides elevated permissions to access data available to the app's admin. Only available in Base44-hosted backend functions. Automatically added to client's created using {@linkcode createClientFromRequest | createClientFromRequest()}.
|
|
48
|
+
* @internal
|
|
46
49
|
*/
|
|
47
50
|
serviceToken?: string;
|
|
48
51
|
/**
|
|
@@ -83,7 +86,10 @@ export interface Base44Client {
|
|
|
83
86
|
agents: AgentsModule;
|
|
84
87
|
/** {@link AppLogsModule | App logs module} for tracking app usage. */
|
|
85
88
|
appLogs: AppLogsModule;
|
|
86
|
-
/**
|
|
89
|
+
/**
|
|
90
|
+
* {@link AnalyticsModule | Analytics module} for tracking app usage.
|
|
91
|
+
* @internal
|
|
92
|
+
*/
|
|
87
93
|
analytics: AnalyticsModule;
|
|
88
94
|
/** Cleanup function to disconnect WebSocket connections. Call when you're done with the client. */
|
|
89
95
|
cleanup: () => void;
|
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, RealtimeEventType, RealtimeEvent, RealtimeCallback,
|
|
7
|
+
export type { EntitiesModule, EntityHandler, 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 } from "./modules/functions.types.js";
|
package/dist/modules/agents.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { getAccessToken } from "../utils/auth-utils.js";
|
|
2
2
|
export function createAgentsModule({ axios, getSocket, appId, serverUrl, token, }) {
|
|
3
3
|
const baseURL = `/apps/${appId}/agents`;
|
|
4
|
+
// Track active conversations
|
|
5
|
+
const currentConversations = {};
|
|
4
6
|
const getConversations = () => {
|
|
5
7
|
return axios.get(`${baseURL}/conversations`);
|
|
6
8
|
};
|
|
@@ -16,22 +18,39 @@ export function createAgentsModule({ axios, getSocket, appId, serverUrl, token,
|
|
|
16
18
|
return axios.post(`${baseURL}/conversations`, conversation);
|
|
17
19
|
};
|
|
18
20
|
const addMessage = async (conversation, message) => {
|
|
19
|
-
|
|
20
|
-
const socket = getSocket();
|
|
21
|
-
await socket.updateModel(room, {
|
|
22
|
-
...conversation,
|
|
23
|
-
messages: [...(conversation.messages || []), message],
|
|
24
|
-
});
|
|
25
|
-
return axios.post(`${baseURL}/conversations/${conversation.id}/messages`, message);
|
|
21
|
+
return axios.post(`${baseURL}/conversations/v2/${conversation.id}/messages`, message);
|
|
26
22
|
};
|
|
27
23
|
const subscribeToConversation = (conversationId, onUpdate) => {
|
|
28
24
|
const room = `/agent-conversations/${conversationId}`;
|
|
29
25
|
const socket = getSocket();
|
|
26
|
+
// Store the promise for initial conversation state
|
|
27
|
+
const conversationPromise = getConversation(conversationId).then((conv) => {
|
|
28
|
+
currentConversations[conversationId] = conv;
|
|
29
|
+
return conv;
|
|
30
|
+
});
|
|
30
31
|
return socket.subscribeToRoom(room, {
|
|
31
32
|
connect: () => { },
|
|
32
|
-
update_model: ({ data: jsonStr }) => {
|
|
33
|
-
const
|
|
34
|
-
|
|
33
|
+
update_model: async ({ data: jsonStr }) => {
|
|
34
|
+
const data = JSON.parse(jsonStr);
|
|
35
|
+
if (data._message) {
|
|
36
|
+
// Wait for initial conversation to be loaded
|
|
37
|
+
await conversationPromise;
|
|
38
|
+
const message = data._message;
|
|
39
|
+
// Update shared conversation state
|
|
40
|
+
const currentConversation = currentConversations[conversationId];
|
|
41
|
+
if (currentConversation) {
|
|
42
|
+
const messages = currentConversation.messages || [];
|
|
43
|
+
const existingIndex = messages.findIndex((m) => m.id === message.id);
|
|
44
|
+
const updatedMessages = existingIndex !== -1
|
|
45
|
+
? messages.map((m, i) => (i === existingIndex ? message : m))
|
|
46
|
+
: [...messages, message];
|
|
47
|
+
currentConversations[conversationId] = {
|
|
48
|
+
...currentConversation,
|
|
49
|
+
messages: updatedMessages,
|
|
50
|
+
};
|
|
51
|
+
onUpdate === null || onUpdate === void 0 ? void 0 : onUpdate(currentConversations[conversationId]);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
35
54
|
},
|
|
36
55
|
});
|
|
37
56
|
};
|
|
@@ -72,7 +72,7 @@ export interface AgentMessageMetadata {
|
|
|
72
72
|
export interface AgentConversation {
|
|
73
73
|
/** Unique identifier for the conversation. */
|
|
74
74
|
id: string;
|
|
75
|
-
/**
|
|
75
|
+
/** App ID. */
|
|
76
76
|
app_id: string;
|
|
77
77
|
/** Name of the agent in this conversation. */
|
|
78
78
|
agent_name: string;
|
|
@@ -138,9 +138,9 @@ export interface CreateConversationParams {
|
|
|
138
138
|
export interface AgentsModuleConfig {
|
|
139
139
|
/** Axios instance for HTTP requests */
|
|
140
140
|
axios: AxiosInstance;
|
|
141
|
-
/** Function to get WebSocket instance for
|
|
141
|
+
/** Function to get WebSocket instance for realtime updates (lazy initialization) */
|
|
142
142
|
getSocket: () => ReturnType<typeof RoomsSocket>;
|
|
143
|
-
/**
|
|
143
|
+
/** App ID */
|
|
144
144
|
appId: string;
|
|
145
145
|
/** Server URL */
|
|
146
146
|
serverUrl?: string;
|
|
@@ -151,7 +151,7 @@ export interface AgentsModuleConfig {
|
|
|
151
151
|
* Agents module for managing AI agent conversations.
|
|
152
152
|
*
|
|
153
153
|
* This module provides methods to create and manage conversations with AI agents,
|
|
154
|
-
* send messages, and subscribe to
|
|
154
|
+
* send messages, and subscribe to realtime updates. Conversations can be used
|
|
155
155
|
* for chat interfaces, support systems, or any interactive AI app.
|
|
156
156
|
*
|
|
157
157
|
* The agents module enables you to:
|
|
@@ -159,7 +159,7 @@ export interface AgentsModuleConfig {
|
|
|
159
159
|
* - **Create conversations** with agents defined in the app.
|
|
160
160
|
* - **Send messages** from users to agents and receive AI-generated responses.
|
|
161
161
|
* - **Retrieve conversations** individually or as filtered lists with sorting and pagination.
|
|
162
|
-
* - **Subscribe to
|
|
162
|
+
* - **Subscribe to realtime updates** using WebSocket connections to receive instant notifications when new messages arrive.
|
|
163
163
|
* - **Attach metadata** to conversations for tracking context, categories, priorities, or linking to external systems.
|
|
164
164
|
* - **Generate WhatsApp connection URLs** for users to interact with agents through WhatsApp.
|
|
165
165
|
*
|
|
@@ -275,7 +275,7 @@ export interface AgentsModule {
|
|
|
275
275
|
* Adds a message to a conversation.
|
|
276
276
|
*
|
|
277
277
|
* Sends a message to the agent and updates the conversation. This method
|
|
278
|
-
* also updates the
|
|
278
|
+
* also updates the realtime socket to notify any subscribers.
|
|
279
279
|
*
|
|
280
280
|
* @param conversation - The conversation to add the message to.
|
|
281
281
|
* @param message - The message to add.
|
|
@@ -293,19 +293,25 @@ export interface AgentsModule {
|
|
|
293
293
|
*/
|
|
294
294
|
addMessage(conversation: AgentConversation, message: Partial<AgentMessage>): Promise<AgentMessage>;
|
|
295
295
|
/**
|
|
296
|
-
* Subscribes to
|
|
296
|
+
* Subscribes to realtime updates for a conversation.
|
|
297
297
|
*
|
|
298
298
|
* Establishes a WebSocket connection to receive instant updates when new
|
|
299
299
|
* messages are added to the conversation. Returns an unsubscribe function
|
|
300
300
|
* to clean up the connection.
|
|
301
301
|
*
|
|
302
302
|
* @param conversationId - The conversation ID to subscribe to.
|
|
303
|
-
* @param onUpdate - Callback function called when the conversation is updated.
|
|
303
|
+
* @param onUpdate - Callback function called when the conversation is updated. The callback receives a conversation object with the following properties:
|
|
304
|
+
* - `id`: Unique identifier for the conversation.
|
|
305
|
+
* - `agent_name`: Name of the agent in this conversation.
|
|
306
|
+
* - `created_date`: ISO 8601 timestamp of when the conversation was created.
|
|
307
|
+
* - `updated_date`: ISO 8601 timestamp of when the conversation was last updated.
|
|
308
|
+
* - `messages`: Array of messages in the conversation. Each message includes `id`, `role` (`'user'`, `'assistant'`, or `'system'`), `content`, `created_date`, and optionally `tool_calls`, `reasoning`, `file_urls`, and `usage`.
|
|
309
|
+
* - `metadata`: Optional metadata associated with the conversation.
|
|
304
310
|
* @returns Unsubscribe function to stop receiving updates.
|
|
305
311
|
*
|
|
306
312
|
* @example
|
|
307
313
|
* ```typescript
|
|
308
|
-
* // Subscribe to
|
|
314
|
+
* // Subscribe to realtime updates
|
|
309
315
|
* const unsubscribe = base44.agents.subscribeToConversation(
|
|
310
316
|
* 'conv-123',
|
|
311
317
|
* (updatedConversation) => {
|
package/dist/modules/auth.js
CHANGED
|
@@ -25,27 +25,25 @@ export function createAuthModule(axios, functionsAxiosClient, appId, options) {
|
|
|
25
25
|
if (typeof window === "undefined") {
|
|
26
26
|
throw new Error("Login method can only be used in a browser environment");
|
|
27
27
|
}
|
|
28
|
-
// Skip redirect if already on login page to avoid redirect loop
|
|
29
|
-
if (window.location.pathname === "/login") {
|
|
30
|
-
return;
|
|
31
|
-
}
|
|
32
28
|
// If nextUrl is not provided, use the current URL
|
|
33
29
|
const redirectUrl = nextUrl
|
|
34
30
|
? new URL(nextUrl, window.location.origin).toString()
|
|
35
31
|
: window.location.href;
|
|
36
|
-
// For preview URLs (preview--*), redirect to main app's login page
|
|
37
|
-
// but keep from_url pointing to the preview URL
|
|
38
|
-
let loginBaseUrl = (_a = options.appBaseUrl) !== null && _a !== void 0 ? _a : "";
|
|
39
|
-
const hostname = window.location.hostname;
|
|
40
|
-
if (hostname.startsWith("preview--")) {
|
|
41
|
-
const mainHostname = hostname.replace(/^preview--/, "");
|
|
42
|
-
loginBaseUrl = `${window.location.protocol}//${mainHostname}${window.location.port ? ":" + window.location.port : ""}`;
|
|
43
|
-
}
|
|
44
32
|
// Build the login URL
|
|
45
|
-
const loginUrl = `${
|
|
33
|
+
const loginUrl = `${(_a = options.appBaseUrl) !== null && _a !== void 0 ? _a : ""}/login?from_url=${encodeURIComponent(redirectUrl)}`;
|
|
46
34
|
// Redirect to the login page
|
|
47
35
|
window.location.href = loginUrl;
|
|
48
36
|
},
|
|
37
|
+
// Redirects the user to a provider's login page
|
|
38
|
+
loginWithProvider(provider, fromUrl = "/") {
|
|
39
|
+
// Build the full redirect URL
|
|
40
|
+
const redirectUrl = new URL(fromUrl, window.location.origin).toString();
|
|
41
|
+
// Build the provider login URL (google is the default, so no provider path needed)
|
|
42
|
+
const providerPath = provider === "google" ? "" : `/${provider}`;
|
|
43
|
+
const loginUrl = `${options.serverUrl}/api/apps/auth${providerPath}/login?app_id=${appId}&from_url=${encodeURIComponent(redirectUrl)}`;
|
|
44
|
+
// Redirect to the provider login page
|
|
45
|
+
window.location.href = loginUrl;
|
|
46
|
+
},
|
|
49
47
|
// Logout the current user
|
|
50
48
|
// Removes the token from localStorage and optionally redirects to a URL or reloads the page
|
|
51
49
|
logout(redirectUrl) {
|
|
@@ -171,6 +171,27 @@ 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 OAuth/SSO login flow with providers like Google, Microsoft, etc. Requires a browser environment and can't be used in the backend.
|
|
178
|
+
*
|
|
179
|
+
* @param provider - Name of the supported authentication provider (e.g., 'google', 'microsoft').
|
|
180
|
+
* @param fromUrl - URL to redirect to after successful authentication. Defaults to '/'.
|
|
181
|
+
*
|
|
182
|
+
* @example
|
|
183
|
+
* ```typescript
|
|
184
|
+
* // Login with Google and return to current page
|
|
185
|
+
* base44.auth.loginWithProvider('google', window.location.pathname);
|
|
186
|
+
* ```
|
|
187
|
+
*
|
|
188
|
+
* @example
|
|
189
|
+
* ```typescript
|
|
190
|
+
* // Login with GitHub and redirect to dashboard
|
|
191
|
+
* base44.auth.loginWithProvider('microsoft', '/dashboard');
|
|
192
|
+
* ```
|
|
193
|
+
*/
|
|
194
|
+
loginWithProvider(provider: string, fromUrl?: string): void;
|
|
174
195
|
/**
|
|
175
196
|
* Logs out the current user.
|
|
176
197
|
*
|
|
@@ -11,9 +11,7 @@ export interface ConnectorAccessTokenResponse {
|
|
|
11
11
|
/**
|
|
12
12
|
* Connectors module for managing OAuth tokens for external services.
|
|
13
13
|
*
|
|
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.
|
|
14
|
+
* 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
15
|
*
|
|
18
16
|
* Unlike the integrations module that provides pre-built functions, connectors give you
|
|
19
17
|
* raw OAuth tokens so you can call external service APIs directly with full control over
|
|
@@ -26,9 +24,9 @@ export interface ConnectorsModule {
|
|
|
26
24
|
/**
|
|
27
25
|
* Retrieves an OAuth access token for a specific external integration type.
|
|
28
26
|
*
|
|
29
|
-
* Returns the OAuth token string for an external service that
|
|
30
|
-
* has connected to.
|
|
31
|
-
* to that external service.
|
|
27
|
+
* Returns the OAuth token string for an external service that an app builder
|
|
28
|
+
* has connected to. This token represents the connected app builder's account
|
|
29
|
+
* and can be used to make authenticated API calls to that external service on behalf of the app.
|
|
32
30
|
*
|
|
33
31
|
* @param integrationType - The type of integration, such as `'googlecalendar'`, `'slack'`, or `'github'`.
|
|
34
32
|
* @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
|
}
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Event types for realtime entity updates.
|
|
3
|
+
* @internal
|
|
3
4
|
*/
|
|
4
5
|
export type RealtimeEventType = "create" | "update" | "delete";
|
|
5
6
|
/**
|
|
6
7
|
* Payload received when a realtime event occurs.
|
|
8
|
+
* @internal
|
|
7
9
|
*/
|
|
8
10
|
export interface RealtimeEvent {
|
|
9
11
|
/** The type of change that occurred */
|
|
@@ -17,12 +19,9 @@ export interface RealtimeEvent {
|
|
|
17
19
|
}
|
|
18
20
|
/**
|
|
19
21
|
* Callback function invoked when a realtime event occurs.
|
|
22
|
+
* @internal
|
|
20
23
|
*/
|
|
21
24
|
export type RealtimeCallback = (event: RealtimeEvent) => void;
|
|
22
|
-
/**
|
|
23
|
-
* Function returned from subscribe, call it to unsubscribe.
|
|
24
|
-
*/
|
|
25
|
-
export type Subscription = () => void;
|
|
26
25
|
/**
|
|
27
26
|
* Entity handler providing CRUD operations for a specific entity type.
|
|
28
27
|
*
|
|
@@ -270,10 +269,16 @@ export interface EntityHandler {
|
|
|
270
269
|
/**
|
|
271
270
|
* Subscribes to realtime updates for all records of this entity type.
|
|
272
271
|
*
|
|
273
|
-
*
|
|
272
|
+
* Establishes a WebSocket connection to receive instant updates when any
|
|
273
|
+
* record is created, updated, or deleted. Returns an unsubscribe function
|
|
274
|
+
* to clean up the connection.
|
|
274
275
|
*
|
|
275
|
-
* @param callback -
|
|
276
|
-
*
|
|
276
|
+
* @param callback - Callback function called when an entity changes. The callback receives an event object with the following properties:
|
|
277
|
+
* - `type`: The type of change that occurred - `'create'`, `'update'`, or `'delete'`.
|
|
278
|
+
* - `data`: The entity data after the change.
|
|
279
|
+
* - `id`: The unique identifier of the affected entity.
|
|
280
|
+
* - `timestamp`: ISO 8601 timestamp of when the event occurred.
|
|
281
|
+
* @returns Unsubscribe function to stop receiving updates.
|
|
277
282
|
*
|
|
278
283
|
* @example
|
|
279
284
|
* ```typescript
|
|
@@ -282,11 +287,12 @@ export interface EntityHandler {
|
|
|
282
287
|
* console.log(`Task ${event.id} was ${event.type}d:`, event.data);
|
|
283
288
|
* });
|
|
284
289
|
*
|
|
285
|
-
* // Later,
|
|
290
|
+
* // Later, clean up the subscription
|
|
286
291
|
* unsubscribe();
|
|
287
292
|
* ```
|
|
293
|
+
* @internal
|
|
288
294
|
*/
|
|
289
|
-
subscribe(callback: RealtimeCallback):
|
|
295
|
+
subscribe(callback: RealtimeCallback): () => void;
|
|
290
296
|
}
|
|
291
297
|
/**
|
|
292
298
|
* Entities module for managing app data.
|
|
@@ -320,22 +320,28 @@ export interface CoreIntegrations {
|
|
|
320
320
|
CreateFileSignedUrl(params: CreateFileSignedUrlParams): Promise<CreateFileSignedUrlResult>;
|
|
321
321
|
}
|
|
322
322
|
/**
|
|
323
|
-
* Integrations module for calling integration
|
|
323
|
+
* Integrations module for calling integration methods.
|
|
324
324
|
*
|
|
325
|
-
* This module provides access to integration
|
|
326
|
-
* services. Integrations are organized into packages. Base44 provides built-in integrations
|
|
327
|
-
* in the `Core` package.
|
|
325
|
+
* This module provides access to integration methods for interacting with external services. Unlike the connectors module that gives you raw OAuth tokens, integrations provide pre-built functions that Base44 executes on your behalf.
|
|
328
326
|
*
|
|
329
|
-
*
|
|
330
|
-
* pre-built functions that Base44 executes on your behalf.
|
|
327
|
+
* There are two types of integrations:
|
|
331
328
|
*
|
|
332
|
-
*
|
|
333
|
-
*
|
|
329
|
+
* - **Built-in integrations** (`Core`): Pre-built functions provided by Base44 for common tasks such as AI-powered text generation, image creation, file uploads, and email. Access core integration methods using:
|
|
330
|
+
* ```
|
|
331
|
+
* base44.integrations.Core.FunctionName(params)
|
|
332
|
+
* ```
|
|
333
|
+
*
|
|
334
|
+
* - **Custom integrations** (`custom`): Pre-configured external APIs. Custom integration calls are proxied through Base44's backend, so credentials are never exposed to the frontend. Access custom integration methods using:
|
|
335
|
+
* ```
|
|
336
|
+
* base44.integrations.custom.call(slug, operationId, params)
|
|
337
|
+
* ```
|
|
338
|
+
*
|
|
339
|
+
* <Info>To call a custom integration, it must be pre-configured by a workspace administrator who imports an OpenAPI specification.</Info>
|
|
334
340
|
*
|
|
335
341
|
* This module is available to use with a client in all authentication modes:
|
|
336
342
|
*
|
|
337
|
-
* - **Anonymous or User authentication** (`base44.integrations`): Integration
|
|
338
|
-
* - **Service role authentication** (`base44.asServiceRole.integrations`): Integration
|
|
343
|
+
* - **Anonymous or User authentication** (`base44.integrations`): Integration methods are invoked with the current user's permissions. Anonymous users invoke methods without authentication, while authenticated users invoke methods with their authentication context.
|
|
344
|
+
* - **Service role authentication** (`base44.asServiceRole.integrations`): Integration methods are invoked with elevated admin-level permissions. The methods execute with admin authentication context.
|
|
339
345
|
*/
|
|
340
346
|
export type IntegrationsModule = {
|
|
341
347
|
/**
|
|
@@ -343,22 +349,7 @@ export type IntegrationsModule = {
|
|
|
343
349
|
*/
|
|
344
350
|
Core: CoreIntegrations;
|
|
345
351
|
/**
|
|
346
|
-
* Custom integrations module for calling
|
|
347
|
-
*
|
|
348
|
-
* Allows calling external APIs that workspace admins have configured
|
|
349
|
-
* by importing OpenAPI specifications.
|
|
350
|
-
*
|
|
351
|
-
* @example
|
|
352
|
-
* ```typescript
|
|
353
|
-
* const response = await base44.integrations.custom.call(
|
|
354
|
-
* "github", // integration slug
|
|
355
|
-
* "listIssues", // operation ID
|
|
356
|
-
* {
|
|
357
|
-
* pathParams: { owner: "myorg", repo: "myrepo" },
|
|
358
|
-
* queryParams: { state: "open" }
|
|
359
|
-
* }
|
|
360
|
-
* );
|
|
361
|
-
* ```
|
|
352
|
+
* Custom integrations module for calling pre-configured external APIs.
|
|
362
353
|
*/
|
|
363
354
|
custom: CustomIntegrationsModule;
|
|
364
355
|
} & {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@base44-preview/sdk",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.18-pr.70.4e2bede",
|
|
4
4
|
"description": "JavaScript SDK for Base44 API",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -19,7 +19,9 @@
|
|
|
19
19
|
"docs": "typedoc",
|
|
20
20
|
"prepublishOnly": "npm run build",
|
|
21
21
|
"create-docs": "npm run create-docs:generate && npm run create-docs:process",
|
|
22
|
+
"create-docs-local": "npm run create-docs && npm run copy-docs-local",
|
|
22
23
|
"push-docs": "node scripts/mintlify-post-processing/push-to-docs-repo.js",
|
|
24
|
+
"copy-docs-local": "node scripts/mintlify-post-processing/copy-to-local-docs.js",
|
|
23
25
|
"create-docs:generate": "typedoc",
|
|
24
26
|
"create-docs:process": "node scripts/mintlify-post-processing/file-processing/file-processing.js"
|
|
25
27
|
},
|