@base44/sdk 0.8.20 → 0.8.22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/client.js +26 -3
- package/dist/client.types.d.ts +10 -3
- package/dist/index.d.ts +2 -2
- package/dist/modules/auth.types.d.ts +6 -5
- package/dist/modules/connectors.d.ts +10 -1
- package/dist/modules/connectors.js +34 -0
- package/dist/modules/connectors.types.d.ts +190 -31
- package/dist/modules/entities.js +8 -0
- package/dist/modules/entities.types.d.ts +92 -0
- package/dist/modules/functions.d.ts +3 -2
- package/dist/modules/functions.js +37 -1
- package/dist/modules/functions.types.d.ts +32 -0
- package/dist/modules/integrations.types.d.ts +8 -3
- package/package.json +1 -1
package/dist/client.js
CHANGED
|
@@ -3,7 +3,7 @@ import { createEntitiesModule } from "./modules/entities.js";
|
|
|
3
3
|
import { createIntegrationsModule } from "./modules/integrations.js";
|
|
4
4
|
import { createAuthModule } from "./modules/auth.js";
|
|
5
5
|
import { createSsoModule } from "./modules/sso.js";
|
|
6
|
-
import { createConnectorsModule } from "./modules/connectors.js";
|
|
6
|
+
import { createConnectorsModule, createUserConnectorsModule, } from "./modules/connectors.js";
|
|
7
7
|
import { getAccessToken } from "./utils/auth-utils.js";
|
|
8
8
|
import { createFunctionsModule } from "./modules/functions.js";
|
|
9
9
|
import { createAgentsModule } from "./modules/agents.js";
|
|
@@ -49,6 +49,7 @@ import { createAnalyticsModule } from "./modules/analytics.js";
|
|
|
49
49
|
* ```
|
|
50
50
|
*/
|
|
51
51
|
export function createClient(config) {
|
|
52
|
+
var _a, _b;
|
|
52
53
|
const { serverUrl = "https://base44.app", appId, token, serviceToken, requiresAuth = false, appBaseUrl, options, functionsVersion, headers: optionalHeaders, } = config;
|
|
53
54
|
// Normalize appBaseUrl to always be a string (empty if not provided or invalid)
|
|
54
55
|
const normalizedAppBaseUrl = typeof appBaseUrl === "string" ? appBaseUrl : "";
|
|
@@ -114,8 +115,20 @@ export function createClient(config) {
|
|
|
114
115
|
getSocket,
|
|
115
116
|
}),
|
|
116
117
|
integrations: createIntegrationsModule(axiosClient, appId),
|
|
118
|
+
connectors: createUserConnectorsModule(axiosClient, appId),
|
|
117
119
|
auth: userAuthModule,
|
|
118
|
-
functions: createFunctionsModule(functionsAxiosClient, appId
|
|
120
|
+
functions: createFunctionsModule(functionsAxiosClient, appId, {
|
|
121
|
+
getAuthHeaders: () => {
|
|
122
|
+
const headers = {};
|
|
123
|
+
// Get current token from storage or initial config
|
|
124
|
+
const currentToken = token || getAccessToken();
|
|
125
|
+
if (currentToken) {
|
|
126
|
+
headers["Authorization"] = `Bearer ${currentToken}`;
|
|
127
|
+
}
|
|
128
|
+
return headers;
|
|
129
|
+
},
|
|
130
|
+
baseURL: (_a = functionsAxiosClient.defaults) === null || _a === void 0 ? void 0 : _a.baseURL,
|
|
131
|
+
}),
|
|
119
132
|
agents: createAgentsModule({
|
|
120
133
|
axios: axiosClient,
|
|
121
134
|
getSocket,
|
|
@@ -147,7 +160,17 @@ export function createClient(config) {
|
|
|
147
160
|
integrations: createIntegrationsModule(serviceRoleAxiosClient, appId),
|
|
148
161
|
sso: createSsoModule(serviceRoleAxiosClient, appId, token),
|
|
149
162
|
connectors: createConnectorsModule(serviceRoleAxiosClient, appId),
|
|
150
|
-
functions: createFunctionsModule(serviceRoleFunctionsAxiosClient, appId
|
|
163
|
+
functions: createFunctionsModule(serviceRoleFunctionsAxiosClient, appId, {
|
|
164
|
+
getAuthHeaders: () => {
|
|
165
|
+
const headers = {};
|
|
166
|
+
// Use service token for authorization
|
|
167
|
+
if (serviceToken) {
|
|
168
|
+
headers["Authorization"] = `Bearer ${serviceToken}`;
|
|
169
|
+
}
|
|
170
|
+
return headers;
|
|
171
|
+
},
|
|
172
|
+
baseURL: (_b = serviceRoleFunctionsAxiosClient.defaults) === null || _b === void 0 ? void 0 : _b.baseURL,
|
|
173
|
+
}),
|
|
151
174
|
agents: createAgentsModule({
|
|
152
175
|
axios: serviceRoleAxiosClient,
|
|
153
176
|
getSocket,
|
package/dist/client.types.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import type { EntitiesModule } from "./modules/entities.types.js";
|
|
|
2
2
|
import type { IntegrationsModule } from "./modules/integrations.types.js";
|
|
3
3
|
import type { AuthModule } from "./modules/auth.types.js";
|
|
4
4
|
import type { SsoModule } from "./modules/sso.types.js";
|
|
5
|
-
import type { ConnectorsModule } from "./modules/connectors.types.js";
|
|
5
|
+
import type { ConnectorsModule, UserConnectorsModule } from "./modules/connectors.types.js";
|
|
6
6
|
import type { FunctionsModule } from "./modules/functions.types.js";
|
|
7
7
|
import type { AgentsModule } from "./modules/agents.types.js";
|
|
8
8
|
import type { AppLogsModule } from "./modules/app-logs.types.js";
|
|
@@ -21,8 +21,13 @@ export interface CreateClientOptions {
|
|
|
21
21
|
*/
|
|
22
22
|
export interface CreateClientConfig {
|
|
23
23
|
/**
|
|
24
|
-
* The Base44 server URL.
|
|
25
|
-
*
|
|
24
|
+
* The Base44 server URL.
|
|
25
|
+
*
|
|
26
|
+
* You don't need to set this for production use. The SDK defaults to `https://base44.app`.
|
|
27
|
+
*
|
|
28
|
+
* Set this when using a local development server to point SDK requests at your local machine instead of the hosted backend.
|
|
29
|
+
*
|
|
30
|
+
* @defaultValue `"https://base44.app"`
|
|
26
31
|
*/
|
|
27
32
|
serverUrl?: string;
|
|
28
33
|
/**
|
|
@@ -82,6 +87,8 @@ export interface Base44Client {
|
|
|
82
87
|
appLogs: AppLogsModule;
|
|
83
88
|
/** {@link AuthModule | Auth module} for user authentication and management. */
|
|
84
89
|
auth: AuthModule;
|
|
90
|
+
/** {@link UserConnectorsModule | Connectors module} for app-user OAuth flows. */
|
|
91
|
+
connectors: UserConnectorsModule;
|
|
85
92
|
/** {@link EntitiesModule | Entities module} for CRUD operations on your data models. */
|
|
86
93
|
entities: EntitiesModule;
|
|
87
94
|
/** {@link FunctionsModule | Functions module} for invoking custom backend functions. */
|
package/dist/index.d.ts
CHANGED
|
@@ -4,13 +4,13 @@ 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 { DeleteManyResult, DeleteResult, EntitiesModule, EntityHandler, EntityRecord, EntityTypeRegistry, ImportResult, RealtimeEventType, RealtimeEvent, RealtimeCallback, SortField, } from "./modules/entities.types.js";
|
|
7
|
+
export type { DeleteManyResult, DeleteResult, EntitiesModule, EntityHandler, EntityRecord, EntityTypeRegistry, ImportResult, RealtimeEventType, RealtimeEvent, RealtimeCallback, SortField, UpdateManyResult, } 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, 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, FunctionName, FunctionNameRegistry, } from "./modules/functions.types.js";
|
|
11
11
|
export type { AgentsModule, AgentName, 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
|
-
export type { ConnectorsModule } from "./modules/connectors.types.js";
|
|
14
|
+
export type { ConnectorsModule, UserConnectorsModule, } from "./modules/connectors.types.js";
|
|
15
15
|
export type { CustomIntegrationsModule, CustomIntegrationCallParams, CustomIntegrationCallResponse, } from "./modules/custom-integrations.types.js";
|
|
16
16
|
export type { GetAccessTokenOptions, SaveAccessTokenOptions, RemoveAccessTokenOptions, GetLoginUrlOptions, } from "./utils/auth-utils.types.js";
|
|
@@ -181,11 +181,11 @@ export interface AuthModule {
|
|
|
181
181
|
* Initiates an OAuth login flow with one of the built-in providers. Requires a browser environment and can't be used in the backend.
|
|
182
182
|
*
|
|
183
183
|
* Supported providers:
|
|
184
|
-
* - `'google'
|
|
185
|
-
* - `'microsoft'
|
|
186
|
-
* - `'facebook'
|
|
187
|
-
* - `'apple'
|
|
188
|
-
* - `'sso'
|
|
184
|
+
* - `'google'`: {@link https://developers.google.com/identity/protocols/oauth2 | Google OAuth}. Enabled by default.
|
|
185
|
+
* - `'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.
|
|
186
|
+
* - `'facebook'`: {@link https://developers.facebook.com/docs/facebook-login | Facebook Login}. Enable Facebook in your app's authentication settings before using.
|
|
187
|
+
* - `'apple'`: {@link https://developer.apple.com/sign-in-with-apple/ | Sign in with Apple}. Enable Apple in your app's authentication settings before using this provider.
|
|
188
|
+
* - `'sso'`: Enterprise SSO. {@link https://docs.base44.com/Setting-up-your-app/Setting-up-SSO | Set up an SSO provider} in your app's authentication settings before using this provider.
|
|
189
189
|
*
|
|
190
190
|
* @param provider - The authentication provider to use: `'google'`, `'microsoft'`, `'facebook'`, `'apple'`, or `'sso'`.
|
|
191
191
|
* @param fromUrl - URL to redirect to after successful authentication. Defaults to `'/'`.
|
|
@@ -213,6 +213,7 @@ export interface AuthModule {
|
|
|
213
213
|
* // SSO
|
|
214
214
|
* base44.auth.loginWithProvider('sso', '/dashboard');
|
|
215
215
|
* ```
|
|
216
|
+
*
|
|
216
217
|
*/
|
|
217
218
|
loginWithProvider(provider: string, fromUrl?: string): void;
|
|
218
219
|
/**
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { AxiosInstance } from "axios";
|
|
2
|
-
import { ConnectorsModule } from "./connectors.types.js";
|
|
2
|
+
import { ConnectorsModule, UserConnectorsModule } from "./connectors.types.js";
|
|
3
3
|
/**
|
|
4
4
|
* Creates the Connectors module for the Base44 SDK.
|
|
5
5
|
*
|
|
@@ -9,3 +9,12 @@ import { ConnectorsModule } from "./connectors.types.js";
|
|
|
9
9
|
* @internal
|
|
10
10
|
*/
|
|
11
11
|
export declare function createConnectorsModule(axios: AxiosInstance, appId: string): ConnectorsModule;
|
|
12
|
+
/**
|
|
13
|
+
* Creates the user-scoped Connectors module (app-user OAuth flows).
|
|
14
|
+
*
|
|
15
|
+
* @param axios - Axios instance (user-scoped client)
|
|
16
|
+
* @param appId - Application ID
|
|
17
|
+
* @returns User connectors module with app-user OAuth methods
|
|
18
|
+
* @internal
|
|
19
|
+
*/
|
|
20
|
+
export declare function createUserConnectorsModule(axios: AxiosInstance, appId: string): UserConnectorsModule;
|
|
@@ -35,3 +35,37 @@ export function createConnectorsModule(axios, appId) {
|
|
|
35
35
|
},
|
|
36
36
|
};
|
|
37
37
|
}
|
|
38
|
+
/**
|
|
39
|
+
* Creates the user-scoped Connectors module (app-user OAuth flows).
|
|
40
|
+
*
|
|
41
|
+
* @param axios - Axios instance (user-scoped client)
|
|
42
|
+
* @param appId - Application ID
|
|
43
|
+
* @returns User connectors module with app-user OAuth methods
|
|
44
|
+
* @internal
|
|
45
|
+
*/
|
|
46
|
+
export function createUserConnectorsModule(axios, appId) {
|
|
47
|
+
return {
|
|
48
|
+
async getCurrentAppUserAccessToken(connectorId) {
|
|
49
|
+
if (!connectorId || typeof connectorId !== "string") {
|
|
50
|
+
throw new Error("Connector ID is required and must be a string");
|
|
51
|
+
}
|
|
52
|
+
const response = await axios.get(`/apps/${appId}/app-user-auth/connectors/${connectorId}/token`);
|
|
53
|
+
const data = response;
|
|
54
|
+
return data.access_token;
|
|
55
|
+
},
|
|
56
|
+
async connectAppUser(connectorId) {
|
|
57
|
+
if (!connectorId || typeof connectorId !== "string") {
|
|
58
|
+
throw new Error("Connector ID is required and must be a string");
|
|
59
|
+
}
|
|
60
|
+
const response = await axios.post(`/apps/${appId}/app-user-auth/connectors/${connectorId}/initiate`);
|
|
61
|
+
const data = response;
|
|
62
|
+
return data.redirect_url;
|
|
63
|
+
},
|
|
64
|
+
async disconnectAppUser(connectorId) {
|
|
65
|
+
if (!connectorId || typeof connectorId !== "string") {
|
|
66
|
+
throw new Error("Connector ID is required and must be a string");
|
|
67
|
+
}
|
|
68
|
+
await axios.delete(`/apps/${appId}/app-user-auth/connectors/${connectorId}`);
|
|
69
|
+
},
|
|
70
|
+
};
|
|
71
|
+
}
|
|
@@ -24,7 +24,7 @@ export interface ConnectorAccessTokenResponse {
|
|
|
24
24
|
connection_config: Record<string, string> | null;
|
|
25
25
|
}
|
|
26
26
|
/**
|
|
27
|
-
*
|
|
27
|
+
* Connection details.
|
|
28
28
|
*/
|
|
29
29
|
export interface ConnectorConnectionResponse {
|
|
30
30
|
/** The OAuth access token for the external service. */
|
|
@@ -33,15 +33,59 @@ export interface ConnectorConnectionResponse {
|
|
|
33
33
|
connectionConfig: Record<string, string> | null;
|
|
34
34
|
}
|
|
35
35
|
/**
|
|
36
|
-
* Connectors module for managing OAuth tokens for external services.
|
|
36
|
+
* Connectors module for managing app-scoped OAuth tokens for external services.
|
|
37
37
|
*
|
|
38
|
-
* 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
|
|
38
|
+
* 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, Slack, or GitHub, all users of the app share that same connection.
|
|
39
39
|
*
|
|
40
40
|
* Unlike the integrations module that provides pre-built functions, connectors give you
|
|
41
41
|
* raw OAuth tokens so you can call external service APIs directly with full control over
|
|
42
42
|
* the API calls you make. This is useful when you need custom API interactions that aren't
|
|
43
43
|
* covered by Base44's pre-built integrations.
|
|
44
44
|
*
|
|
45
|
+
* ## Available connectors
|
|
46
|
+
*
|
|
47
|
+
* All connectors work through [`getConnection()`](#getconnection). Pass the integration type string and use the returned OAuth token to call the external service's API directly.
|
|
48
|
+
*
|
|
49
|
+
* | Service | Type identifier |
|
|
50
|
+
* |---|---|
|
|
51
|
+
* | Airtable | `airtable` |
|
|
52
|
+
* | Box | `box` |
|
|
53
|
+
* | ClickUp | `clickup` |
|
|
54
|
+
* | Discord | `discord` |
|
|
55
|
+
* | Dropbox | `dropbox` |
|
|
56
|
+
* | GitHub | `github` |
|
|
57
|
+
* | Gmail | `gmail` |
|
|
58
|
+
* | Google Analytics | `google_analytics` |
|
|
59
|
+
* | Google BigQuery | `googlebigquery` |
|
|
60
|
+
* | Google Calendar | `googlecalendar` |
|
|
61
|
+
* | Google Classroom | `google_classroom` |
|
|
62
|
+
* | Google Docs | `googledocs` |
|
|
63
|
+
* | Google Drive | `googledrive` |
|
|
64
|
+
* | Google Search Console | `google_search_console` |
|
|
65
|
+
* | Google Sheets | `googlesheets` |
|
|
66
|
+
* | Google Slides | `googleslides` |
|
|
67
|
+
* | HubSpot | `hubspot` |
|
|
68
|
+
* | Linear | `linear` |
|
|
69
|
+
* | LinkedIn | `linkedin` |
|
|
70
|
+
* | Microsoft Teams | `microsoft_teams` |
|
|
71
|
+
* | Microsoft OneDrive | `one_drive` |
|
|
72
|
+
* | Notion | `notion` |
|
|
73
|
+
* | Outlook | `outlook` |
|
|
74
|
+
* | Salesforce | `salesforce` |
|
|
75
|
+
* | SharePoint | `share_point` |
|
|
76
|
+
* | Slack User | `slack` |
|
|
77
|
+
* | Slack Bot | `slackbot` |
|
|
78
|
+
* | Splitwise | `splitwise` |
|
|
79
|
+
* | TikTok | `tiktok` |
|
|
80
|
+
* | Typeform | `typeform` |
|
|
81
|
+
* | Wix | `wix` |
|
|
82
|
+
* | Wrike | `wrike` |
|
|
83
|
+
*
|
|
84
|
+
* See the integration guides for more details:
|
|
85
|
+
*
|
|
86
|
+
* - **Scopes and permissions**: {@link https://docs.base44.com/Integrations/gmail-connector#gmail-scopes-and-permissions | Gmail}, {@link https://docs.base44.com/Integrations/linkedin-connector#linkedin-scopes-and-permissions | LinkedIn}, {@link https://docs.base44.com/Integrations/slack-connector#slack-scopes-and-permissions | Slack}, {@link https://docs.base44.com/Integrations/github-connector#github-scopes-and-permissions | GitHub}
|
|
87
|
+
* - **Slack connector types**: {@link https://docs.base44.com/Integrations/slack-connector#about-the-slack-connectors | About the Slack connectors} explains the difference between `slack` and `slackbot`
|
|
88
|
+
*
|
|
45
89
|
* ## Authentication Modes
|
|
46
90
|
*
|
|
47
91
|
* This module is only available to use with a client in service role authentication mode, which means it can only be used in backend environments.
|
|
@@ -52,15 +96,15 @@ export interface ConnectorConnectionResponse {
|
|
|
52
96
|
*/
|
|
53
97
|
export interface ConnectorsModule {
|
|
54
98
|
/**
|
|
55
|
-
* Retrieves an OAuth access token for a specific external integration type.
|
|
99
|
+
* Retrieves an OAuth access token for a specific [external integration type](#available-connectors).
|
|
56
100
|
*
|
|
57
|
-
* @deprecated Use {@link getConnection}
|
|
101
|
+
* @deprecated Use {@link getConnection} instead.
|
|
58
102
|
*
|
|
59
103
|
* Returns the OAuth token string for an external service that an app builder
|
|
60
104
|
* has connected to. This token represents the connected app builder's account
|
|
61
105
|
* and can be used to make authenticated API calls to that external service on behalf of the app.
|
|
62
106
|
*
|
|
63
|
-
* @param integrationType - The type of integration, such as `'googlecalendar'`, `'slack'`,
|
|
107
|
+
* @param integrationType - The type of integration, such as `'googlecalendar'`, `'slack'`, `'slackbot'`, `'github'`, or `'discord'`. See [Available connectors](#available-connectors) for the full list.
|
|
64
108
|
* @returns Promise resolving to the access token string.
|
|
65
109
|
*
|
|
66
110
|
* @example
|
|
@@ -82,8 +126,8 @@ export interface ConnectorsModule {
|
|
|
82
126
|
*
|
|
83
127
|
* @example
|
|
84
128
|
* ```typescript
|
|
85
|
-
* // Slack connection
|
|
86
|
-
* // Get Slack
|
|
129
|
+
* // Slack User connection
|
|
130
|
+
* // Get Slack user token and list channels
|
|
87
131
|
* const slackToken = await base44.asServiceRole.connectors.getAccessToken('slack');
|
|
88
132
|
*
|
|
89
133
|
* // List all public and private channels
|
|
@@ -95,43 +139,158 @@ export interface ConnectorsModule {
|
|
|
95
139
|
*
|
|
96
140
|
* const data = await slackResponse.json();
|
|
97
141
|
* ```
|
|
142
|
+
*
|
|
143
|
+
* @example
|
|
144
|
+
* ```typescript
|
|
145
|
+
* // Slack Bot connection
|
|
146
|
+
* // Get Slack bot token and post a message with a custom bot identity
|
|
147
|
+
* const botToken = await base44.asServiceRole.connectors.getAccessToken('slackbot');
|
|
148
|
+
*
|
|
149
|
+
* const response = await fetch('https://slack.com/api/chat.postMessage', {
|
|
150
|
+
* method: 'POST',
|
|
151
|
+
* headers: {
|
|
152
|
+
* 'Authorization': `Bearer ${botToken}`,
|
|
153
|
+
* 'Content-Type': 'application/json'
|
|
154
|
+
* },
|
|
155
|
+
* body: JSON.stringify({
|
|
156
|
+
* channel: '#alerts',
|
|
157
|
+
* text: 'Deployment to production completed successfully.',
|
|
158
|
+
* username: 'Deploy Bot',
|
|
159
|
+
* icon_emoji: ':rocket:'
|
|
160
|
+
* })
|
|
161
|
+
* });
|
|
162
|
+
*
|
|
163
|
+
* const result = await response.json();
|
|
164
|
+
* ```
|
|
98
165
|
*/
|
|
99
166
|
getAccessToken(integrationType: ConnectorIntegrationType): Promise<string>;
|
|
100
167
|
/**
|
|
101
|
-
* Retrieves the OAuth access token and connection configuration for a specific external integration type.
|
|
168
|
+
* Retrieves the OAuth access token and connection configuration for a specific [external integration type](#available-connectors).
|
|
169
|
+
*
|
|
170
|
+
* Some connectors require connection-specific parameters to build API calls.
|
|
171
|
+
* In such cases, the returned `connectionConfig` is an object with the additional parameters. If there are no extra parameters needed for the connection, the `connectionConfig` is `null`.
|
|
102
172
|
*
|
|
103
|
-
*
|
|
104
|
-
*
|
|
105
|
-
* extra parameters beyond the access token (e.g., a shop domain, account ID, or API base URL).
|
|
173
|
+
* For example, a service might need a subdomain to construct the API URL in
|
|
174
|
+
* the form of `{subdomain}.example.com`. In such a case the subdomain will be available as a property of the `connectionConfig` object.
|
|
106
175
|
*
|
|
107
|
-
* @param integrationType - The type of integration, such as `'googlecalendar'`, `'slack'`,
|
|
176
|
+
* @param integrationType - The type of integration, such as `'googlecalendar'`, `'slack'`, `'slackbot'`, `'github'`, or `'discord'`. See [Available connectors](#available-connectors) for the full list.
|
|
108
177
|
* @returns Promise resolving to a {@link ConnectorConnectionResponse} with `accessToken` and `connectionConfig`.
|
|
109
178
|
*
|
|
110
179
|
* @example
|
|
111
180
|
* ```typescript
|
|
112
|
-
* //
|
|
113
|
-
*
|
|
114
|
-
*
|
|
115
|
-
*
|
|
181
|
+
* // Google Calendar connection
|
|
182
|
+
* // Get Google Calendar OAuth token and fetch upcoming events
|
|
183
|
+
* const { accessToken } = await base44.asServiceRole.connectors.getConnection('googlecalendar');
|
|
184
|
+
*
|
|
185
|
+
* const timeMin = new Date().toISOString();
|
|
186
|
+
* const url = `https://www.googleapis.com/calendar/v3/calendars/primary/events?maxResults=10&orderBy=startTime&singleEvents=true&timeMin=${timeMin}`;
|
|
187
|
+
*
|
|
188
|
+
* const calendarResponse = await fetch(url, {
|
|
189
|
+
* headers: { Authorization: `Bearer ${accessToken}` }
|
|
190
|
+
* });
|
|
191
|
+
*
|
|
192
|
+
* const events = await calendarResponse.json();
|
|
193
|
+
* ```
|
|
194
|
+
*
|
|
195
|
+
* @example
|
|
196
|
+
* ```typescript
|
|
197
|
+
* // Slack connection
|
|
198
|
+
* // Get Slack OAuth token and list channels
|
|
199
|
+
* const { accessToken } = await base44.asServiceRole.connectors.getConnection('slack');
|
|
200
|
+
*
|
|
201
|
+
* const url = 'https://slack.com/api/conversations.list?types=public_channel,private_channel&limit=100';
|
|
202
|
+
*
|
|
203
|
+
* const slackResponse = await fetch(url, {
|
|
204
|
+
* headers: { Authorization: `Bearer ${accessToken}` }
|
|
205
|
+
* });
|
|
206
|
+
*
|
|
207
|
+
* const data = await slackResponse.json();
|
|
116
208
|
* ```
|
|
117
209
|
*
|
|
118
210
|
* @example
|
|
119
211
|
* ```typescript
|
|
120
|
-
* //
|
|
121
|
-
*
|
|
122
|
-
* const { accessToken, connectionConfig } =
|
|
123
|
-
*
|
|
124
|
-
*
|
|
125
|
-
*
|
|
126
|
-
*
|
|
127
|
-
*
|
|
128
|
-
*
|
|
129
|
-
*
|
|
130
|
-
*
|
|
131
|
-
* );
|
|
132
|
-
* const { products } = await response.json();
|
|
133
|
-
* }
|
|
212
|
+
* // Using connectionConfig
|
|
213
|
+
* // Some connectors return a subdomain or other params needed to build the API URL
|
|
214
|
+
* const { accessToken, connectionConfig } = await base44.asServiceRole.connectors.getConnection('myservice');
|
|
215
|
+
*
|
|
216
|
+
* const subdomain = connectionConfig?.subdomain;
|
|
217
|
+
* const response = await fetch(
|
|
218
|
+
* `https://${subdomain}.example.com/api/v1/resources`,
|
|
219
|
+
* { headers: { Authorization: `Bearer ${accessToken}` } }
|
|
220
|
+
* );
|
|
221
|
+
*
|
|
222
|
+
* const data = await response.json();
|
|
134
223
|
* ```
|
|
135
224
|
*/
|
|
136
225
|
getConnection(integrationType: ConnectorIntegrationType): Promise<ConnectorConnectionResponse>;
|
|
137
226
|
}
|
|
227
|
+
/**
|
|
228
|
+
* User-scoped connectors module for managing app-user OAuth connections.
|
|
229
|
+
*
|
|
230
|
+
* This module provides methods for app-user OAuth flows: initiating an OAuth connection,
|
|
231
|
+
* retrieving the end user's access token, and disconnecting the end user's connection.
|
|
232
|
+
*
|
|
233
|
+
* Unlike {@link ConnectorsModule | ConnectorsModule} which manages app-scoped tokens,
|
|
234
|
+
* this module manages tokens scoped to individual end users. Methods are keyed on
|
|
235
|
+
* the connector ID (the OrgConnector's database ID) rather than the integration type.
|
|
236
|
+
*
|
|
237
|
+
* Available via `base44.connectors`.
|
|
238
|
+
*/
|
|
239
|
+
export interface UserConnectorsModule {
|
|
240
|
+
/**
|
|
241
|
+
* Retrieves an OAuth access token for an end user's connection to a specific connector.
|
|
242
|
+
*
|
|
243
|
+
* Returns the OAuth token string that belongs to the currently authenticated end user
|
|
244
|
+
* for the specified connector.
|
|
245
|
+
*
|
|
246
|
+
* @param connectorId - The connector ID (OrgConnector database ID).
|
|
247
|
+
* @returns Promise resolving to the access token string.
|
|
248
|
+
*
|
|
249
|
+
* @example
|
|
250
|
+
* ```typescript
|
|
251
|
+
* // Get the end user's access token for a connector
|
|
252
|
+
* const token = await base44.connectors.getCurrentAppUserAccessToken('abc123def');
|
|
253
|
+
*
|
|
254
|
+
* const response = await fetch('https://www.googleapis.com/calendar/v3/calendars/primary/events', {
|
|
255
|
+
* headers: { 'Authorization': `Bearer ${token}` }
|
|
256
|
+
* });
|
|
257
|
+
* ```
|
|
258
|
+
*/
|
|
259
|
+
getCurrentAppUserAccessToken(connectorId: string): Promise<string>;
|
|
260
|
+
/**
|
|
261
|
+
* Initiates the app-user OAuth flow for a specific connector.
|
|
262
|
+
*
|
|
263
|
+
* Returns a redirect URL that the end user should be navigated to in order to
|
|
264
|
+
* authenticate with the external service. The scopes and integration type are
|
|
265
|
+
* derived from the connector configuration server-side.
|
|
266
|
+
*
|
|
267
|
+
* @param connectorId - The connector ID (OrgConnector database ID).
|
|
268
|
+
* @returns Promise resolving to the redirect URL string.
|
|
269
|
+
*
|
|
270
|
+
* @example
|
|
271
|
+
* ```typescript
|
|
272
|
+
* // Start OAuth for the end user
|
|
273
|
+
* const redirectUrl = await base44.connectors.connectAppUser('abc123def');
|
|
274
|
+
*
|
|
275
|
+
* // Redirect the user to the OAuth provider
|
|
276
|
+
* window.location.href = redirectUrl;
|
|
277
|
+
* ```
|
|
278
|
+
*/
|
|
279
|
+
connectAppUser(connectorId: string): Promise<string>;
|
|
280
|
+
/**
|
|
281
|
+
* Disconnects an end user's OAuth connection for a specific connector.
|
|
282
|
+
*
|
|
283
|
+
* Removes the stored OAuth credentials for the currently authenticated end user's
|
|
284
|
+
* connection to the specified connector.
|
|
285
|
+
*
|
|
286
|
+
* @param connectorId - The connector ID (OrgConnector database ID).
|
|
287
|
+
* @returns Promise resolving when the connection has been removed.
|
|
288
|
+
*
|
|
289
|
+
* @example
|
|
290
|
+
* ```typescript
|
|
291
|
+
* // Disconnect the end user's connection
|
|
292
|
+
* await base44.connectors.disconnectAppUser('abc123def');
|
|
293
|
+
* ```
|
|
294
|
+
*/
|
|
295
|
+
disconnectAppUser(connectorId: string): Promise<void>;
|
|
296
|
+
}
|
package/dist/modules/entities.js
CHANGED
|
@@ -106,6 +106,14 @@ function createEntityHandler(axios, appId, entityName, getSocket) {
|
|
|
106
106
|
async bulkCreate(data) {
|
|
107
107
|
return axios.post(`${baseURL}/bulk`, data);
|
|
108
108
|
},
|
|
109
|
+
// Update multiple entities matching a query using a MongoDB update operator
|
|
110
|
+
async updateMany(query, data) {
|
|
111
|
+
return axios.patch(`${baseURL}/update-many`, { query, data });
|
|
112
|
+
},
|
|
113
|
+
// Update multiple entities by ID, each with its own update data
|
|
114
|
+
async bulkUpdate(data) {
|
|
115
|
+
return axios.put(`${baseURL}/bulk`, data);
|
|
116
|
+
},
|
|
109
117
|
// Import entities from a file
|
|
110
118
|
async importEntities(file) {
|
|
111
119
|
const formData = new FormData();
|
|
@@ -39,6 +39,17 @@ export interface DeleteManyResult {
|
|
|
39
39
|
/** Number of entities that were deleted. */
|
|
40
40
|
deleted: number;
|
|
41
41
|
}
|
|
42
|
+
/**
|
|
43
|
+
* Result returned when updating multiple entities via a query.
|
|
44
|
+
*/
|
|
45
|
+
export interface UpdateManyResult {
|
|
46
|
+
/** Whether the operation was successful. */
|
|
47
|
+
success: boolean;
|
|
48
|
+
/** Number of entities that were updated. */
|
|
49
|
+
updated: number;
|
|
50
|
+
/** Whether there are more entities matching the query that were not updated in this batch. When `true`, call `updateMany` again with the same query to update the next batch. */
|
|
51
|
+
has_more: boolean;
|
|
52
|
+
}
|
|
42
53
|
/**
|
|
43
54
|
* Result returned when importing entities from a file.
|
|
44
55
|
*
|
|
@@ -348,6 +359,87 @@ export interface EntityHandler<T = any> {
|
|
|
348
359
|
* ```
|
|
349
360
|
*/
|
|
350
361
|
bulkCreate(data: Partial<T>[]): Promise<T[]>;
|
|
362
|
+
/**
|
|
363
|
+
* Updates multiple records matching a query using a MongoDB update operator.
|
|
364
|
+
*
|
|
365
|
+
* Applies the same update operation to all records matching the query.
|
|
366
|
+
* The `data` parameter must contain one or more MongoDB update operators
|
|
367
|
+
* (e.g., `$set`, `$inc`, `$push`). Multiple operators can be combined in a
|
|
368
|
+
* single call, but each field may only appear in one operator.
|
|
369
|
+
*
|
|
370
|
+
* Results are batched in groups of up to 500 — when `has_more` is `true`
|
|
371
|
+
* in the response, call `updateMany` again with the same query to update
|
|
372
|
+
* the next batch.
|
|
373
|
+
*
|
|
374
|
+
* @param query - Query object to filter which records to update. Records matching all
|
|
375
|
+
* specified criteria will be updated.
|
|
376
|
+
* @param data - Update operation object containing one or more MongoDB update operators.
|
|
377
|
+
* Each field may only appear in one operator per call.
|
|
378
|
+
* Supported operators: `$set`, `$rename`, `$unset`, `$inc`, `$mul`, `$min`, `$max`,
|
|
379
|
+
* `$currentDate`, `$addToSet`, `$push`, `$pull`.
|
|
380
|
+
* @returns Promise resolving to the update result.
|
|
381
|
+
*
|
|
382
|
+
* @example
|
|
383
|
+
* ```typescript
|
|
384
|
+
* // Set status to 'archived' for all completed records
|
|
385
|
+
* const result = await base44.entities.MyEntity.updateMany(
|
|
386
|
+
* { status: 'completed' },
|
|
387
|
+
* { $set: { status: 'archived' } }
|
|
388
|
+
* );
|
|
389
|
+
* console.log(`Updated ${result.updated} records`);
|
|
390
|
+
* ```
|
|
391
|
+
*
|
|
392
|
+
* @example
|
|
393
|
+
* ```typescript
|
|
394
|
+
* // Combine multiple operators in a single call
|
|
395
|
+
* const result = await base44.entities.MyEntity.updateMany(
|
|
396
|
+
* { category: 'sales' },
|
|
397
|
+
* { $set: { status: 'done' }, $inc: { view_count: 1 } }
|
|
398
|
+
* );
|
|
399
|
+
* ```
|
|
400
|
+
*
|
|
401
|
+
* @example
|
|
402
|
+
* ```typescript
|
|
403
|
+
* // Handle batched updates for large datasets
|
|
404
|
+
* let hasMore = true;
|
|
405
|
+
* let totalUpdated = 0;
|
|
406
|
+
* while (hasMore) {
|
|
407
|
+
* const result = await base44.entities.MyEntity.updateMany(
|
|
408
|
+
* { status: 'pending' },
|
|
409
|
+
* { $set: { status: 'processed' } }
|
|
410
|
+
* );
|
|
411
|
+
* totalUpdated += result.updated;
|
|
412
|
+
* hasMore = result.has_more;
|
|
413
|
+
* }
|
|
414
|
+
* ```
|
|
415
|
+
*/
|
|
416
|
+
updateMany(query: Partial<T>, data: Record<string, Record<string, any>>): Promise<UpdateManyResult>;
|
|
417
|
+
/**
|
|
418
|
+
* Updates multiple records in a single request, each with its own update data.
|
|
419
|
+
*
|
|
420
|
+
* Unlike `updateMany` which applies the same update to all matching records,
|
|
421
|
+
* `bulkUpdate` allows different updates for each record. Each item in the
|
|
422
|
+
* array must include an `id` field identifying which record to update.
|
|
423
|
+
*
|
|
424
|
+
* **Note:** Maximum 500 items per request.
|
|
425
|
+
*
|
|
426
|
+
* @param data - Array of update objects (max 500). Each object must have an `id` field
|
|
427
|
+
* and any number of fields to update.
|
|
428
|
+
* @returns Promise resolving to an array of updated records.
|
|
429
|
+
*
|
|
430
|
+
* @example
|
|
431
|
+
* ```typescript
|
|
432
|
+
* // Update multiple records with different data
|
|
433
|
+
* const updated = await base44.entities.MyEntity.bulkUpdate([
|
|
434
|
+
* { id: 'entity-1', status: 'paid', amount: 999 },
|
|
435
|
+
* { id: 'entity-2', status: 'cancelled' },
|
|
436
|
+
* { id: 'entity-3', name: 'Renamed Item' }
|
|
437
|
+
* ]);
|
|
438
|
+
* ```
|
|
439
|
+
*/
|
|
440
|
+
bulkUpdate(data: (Partial<T> & {
|
|
441
|
+
id: string;
|
|
442
|
+
})[]): Promise<T[]>;
|
|
351
443
|
/**
|
|
352
444
|
* Imports records from a file.
|
|
353
445
|
*
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { AxiosInstance } from "axios";
|
|
2
|
-
import { FunctionsModule } from "./functions.types";
|
|
2
|
+
import { FunctionsModule, FunctionsModuleConfig } from "./functions.types";
|
|
3
3
|
/**
|
|
4
4
|
* Creates the functions module for the Base44 SDK.
|
|
5
5
|
*
|
|
6
6
|
* @param axios - Axios instance
|
|
7
7
|
* @param appId - Application ID
|
|
8
|
+
* @param config - Optional configuration for fetch functionality
|
|
8
9
|
* @returns Functions module with methods to invoke custom backend functions
|
|
9
10
|
* @internal
|
|
10
11
|
*/
|
|
11
|
-
export declare function createFunctionsModule(axios: AxiosInstance, appId: string): FunctionsModule;
|
|
12
|
+
export declare function createFunctionsModule(axios: AxiosInstance, appId: string, config?: FunctionsModuleConfig): FunctionsModule;
|
|
@@ -3,10 +3,34 @@
|
|
|
3
3
|
*
|
|
4
4
|
* @param axios - Axios instance
|
|
5
5
|
* @param appId - Application ID
|
|
6
|
+
* @param config - Optional configuration for fetch functionality
|
|
6
7
|
* @returns Functions module with methods to invoke custom backend functions
|
|
7
8
|
* @internal
|
|
8
9
|
*/
|
|
9
|
-
export function createFunctionsModule(axios, appId) {
|
|
10
|
+
export function createFunctionsModule(axios, appId, config) {
|
|
11
|
+
const joinBaseUrl = (base, path) => {
|
|
12
|
+
if (!base)
|
|
13
|
+
return path;
|
|
14
|
+
return `${String(base).replace(/\/$/, "")}${path}`;
|
|
15
|
+
};
|
|
16
|
+
const toHeaders = (inputHeaders) => {
|
|
17
|
+
const headers = new Headers();
|
|
18
|
+
// Get auth headers from the getter function if provided
|
|
19
|
+
if (config === null || config === void 0 ? void 0 : config.getAuthHeaders) {
|
|
20
|
+
const authHeaders = config.getAuthHeaders();
|
|
21
|
+
Object.entries(authHeaders).forEach(([key, value]) => {
|
|
22
|
+
if (value !== undefined && value !== null) {
|
|
23
|
+
headers.set(key, String(value));
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
if (inputHeaders) {
|
|
28
|
+
new Headers(inputHeaders).forEach((value, key) => {
|
|
29
|
+
headers.set(key, value);
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
return headers;
|
|
33
|
+
};
|
|
10
34
|
return {
|
|
11
35
|
// Invoke a custom backend function by name
|
|
12
36
|
async invoke(functionName, data) {
|
|
@@ -39,5 +63,17 @@ export function createFunctionsModule(axios, appId) {
|
|
|
39
63
|
}
|
|
40
64
|
return axios.post(`/apps/${appId}/functions/${functionName}`, formData || data, { headers: { "Content-Type": contentType } });
|
|
41
65
|
},
|
|
66
|
+
// Fetch a backend function endpoint directly.
|
|
67
|
+
async fetch(path, init = {}) {
|
|
68
|
+
const normalizedPath = path.startsWith("/") ? path : `/${path}`;
|
|
69
|
+
const primaryPath = `/functions${normalizedPath}`;
|
|
70
|
+
const headers = toHeaders(init.headers);
|
|
71
|
+
const requestInit = {
|
|
72
|
+
...init,
|
|
73
|
+
headers,
|
|
74
|
+
};
|
|
75
|
+
const response = await fetch(joinBaseUrl(config === null || config === void 0 ? void 0 : config.baseURL, primaryPath), requestInit);
|
|
76
|
+
return response;
|
|
77
|
+
},
|
|
42
78
|
};
|
|
43
79
|
}
|
|
@@ -14,6 +14,20 @@ export interface FunctionNameRegistry {
|
|
|
14
14
|
* ```
|
|
15
15
|
*/
|
|
16
16
|
export type FunctionName = keyof FunctionNameRegistry extends never ? string : keyof FunctionNameRegistry;
|
|
17
|
+
/**
|
|
18
|
+
* Options for {@linkcode FunctionsModule.fetch}.
|
|
19
|
+
*
|
|
20
|
+
* Uses native `fetch` options directly.
|
|
21
|
+
*/
|
|
22
|
+
export type FunctionsFetchInit = RequestInit;
|
|
23
|
+
/**
|
|
24
|
+
* Configuration for the functions module.
|
|
25
|
+
* @internal
|
|
26
|
+
*/
|
|
27
|
+
export interface FunctionsModuleConfig {
|
|
28
|
+
getAuthHeaders?: () => Record<string, string>;
|
|
29
|
+
baseURL?: string;
|
|
30
|
+
}
|
|
17
31
|
/**
|
|
18
32
|
* Functions module for invoking custom backend functions.
|
|
19
33
|
*
|
|
@@ -68,4 +82,22 @@ export interface FunctionsModule {
|
|
|
68
82
|
* ```
|
|
69
83
|
*/
|
|
70
84
|
invoke(functionName: FunctionName, data?: Record<string, any>): Promise<any>;
|
|
85
|
+
/**
|
|
86
|
+
* Performs a direct HTTP request to a backend function path and returns the native `Response`.
|
|
87
|
+
*
|
|
88
|
+
* Use this method when you need low-level control over the request/response that the higher-level
|
|
89
|
+
* `invoke()` abstraction doesn't provide, such as:
|
|
90
|
+
* - Streaming responses (SSE, chunked text, NDJSON)
|
|
91
|
+
* - Custom HTTP methods (PUT, PATCH, DELETE, etc.)
|
|
92
|
+
* - Custom headers or request configuration
|
|
93
|
+
* - Access to raw response metadata (status, headers)
|
|
94
|
+
* - Direct control over request/response bodies
|
|
95
|
+
*
|
|
96
|
+
* Requests are sent to `/api/functions/<path>`.
|
|
97
|
+
*
|
|
98
|
+
* @param path - Function path, e.g. `/streaming_demo` or `/streaming_demo/deep/path`
|
|
99
|
+
* @param init - Native fetch options.
|
|
100
|
+
* @returns Promise resolving to a native fetch `Response`
|
|
101
|
+
*/
|
|
102
|
+
fetch(path: string, init?: FunctionsFetchInit): Promise<Response>;
|
|
71
103
|
}
|
|
@@ -19,7 +19,7 @@ export type IntegrationEndpointFunction = (data: Record<string, any>) => Promise
|
|
|
19
19
|
* ```typescript
|
|
20
20
|
* await base44.integrations.Core.InvokeLLM({
|
|
21
21
|
* prompt: 'Explain quantum computing',
|
|
22
|
-
* model: '
|
|
22
|
+
* model: 'gpt_5'
|
|
23
23
|
* });
|
|
24
24
|
* ```
|
|
25
25
|
*
|
|
@@ -41,6 +41,11 @@ export type IntegrationPackage = {
|
|
|
41
41
|
export interface InvokeLLMParams {
|
|
42
42
|
/** The prompt text to send to the model */
|
|
43
43
|
prompt: string;
|
|
44
|
+
/** Optionally specify a model to override the app-level model setting for this specific call.
|
|
45
|
+
*
|
|
46
|
+
* Options: `"gpt_5_mini"`, `"gemini_3_flash"`, `"gpt_5"`, `"gemini_3_pro"`, `"claude_sonnet_4_6"`, `"claude_opus_4_6"`
|
|
47
|
+
*/
|
|
48
|
+
model?: 'gpt_5_mini' | 'gemini_3_flash' | 'gpt_5' | 'gemini_3_pro' | 'claude_sonnet_4_6' | 'claude_opus_4_6';
|
|
44
49
|
/** If set to `true`, the LLM will use Google Search, Maps, and News to gather real-time context before answering.
|
|
45
50
|
* @default false
|
|
46
51
|
*/
|
|
@@ -362,7 +367,7 @@ export type IntegrationsModule = {
|
|
|
362
367
|
* ```typescript
|
|
363
368
|
* const response = await base44.integrations.Core.InvokeLLM({
|
|
364
369
|
* prompt: 'Explain quantum computing',
|
|
365
|
-
* model: '
|
|
370
|
+
* model: 'gpt_5'
|
|
366
371
|
* });
|
|
367
372
|
* ```
|
|
368
373
|
*/
|
|
@@ -391,7 +396,7 @@ export type IntegrationsModule = {
|
|
|
391
396
|
* ```typescript
|
|
392
397
|
* const response = await base44.integrations.Core.InvokeLLM({
|
|
393
398
|
* prompt: 'Explain quantum computing',
|
|
394
|
-
* model: '
|
|
399
|
+
* model: 'gpt_5'
|
|
395
400
|
* });
|
|
396
401
|
* ```
|
|
397
402
|
*
|