@depup/base44__sdk 0.8.22-depup.0

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.
Files changed (72) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +32 -0
  3. package/changes.json +14 -0
  4. package/dist/client.d.ts +96 -0
  5. package/dist/client.js +375 -0
  6. package/dist/client.types.d.ts +144 -0
  7. package/dist/client.types.js +1 -0
  8. package/dist/index.d.ts +16 -0
  9. package/dist/index.js +5 -0
  10. package/dist/modules/agents.d.ts +2 -0
  11. package/dist/modules/agents.js +77 -0
  12. package/dist/modules/agents.types.d.ts +377 -0
  13. package/dist/modules/agents.types.js +1 -0
  14. package/dist/modules/analytics.d.ts +20 -0
  15. package/dist/modules/analytics.js +277 -0
  16. package/dist/modules/analytics.types.d.ts +122 -0
  17. package/dist/modules/analytics.types.js +1 -0
  18. package/dist/modules/app-logs.d.ts +11 -0
  19. package/dist/modules/app-logs.js +27 -0
  20. package/dist/modules/app-logs.types.d.ts +46 -0
  21. package/dist/modules/app-logs.types.js +1 -0
  22. package/dist/modules/app.types.d.ts +142 -0
  23. package/dist/modules/app.types.js +1 -0
  24. package/dist/modules/auth.d.ts +13 -0
  25. package/dist/modules/auth.js +180 -0
  26. package/dist/modules/auth.types.d.ts +481 -0
  27. package/dist/modules/auth.types.js +1 -0
  28. package/dist/modules/connectors.d.ts +20 -0
  29. package/dist/modules/connectors.js +71 -0
  30. package/dist/modules/connectors.types.d.ts +296 -0
  31. package/dist/modules/connectors.types.js +1 -0
  32. package/dist/modules/custom-integrations.d.ts +11 -0
  33. package/dist/modules/custom-integrations.js +32 -0
  34. package/dist/modules/custom-integrations.types.d.ts +89 -0
  35. package/dist/modules/custom-integrations.types.js +1 -0
  36. package/dist/modules/entities.d.ts +20 -0
  37. package/dist/modules/entities.js +149 -0
  38. package/dist/modules/entities.types.d.ts +552 -0
  39. package/dist/modules/entities.types.js +1 -0
  40. package/dist/modules/functions.d.ts +12 -0
  41. package/dist/modules/functions.js +79 -0
  42. package/dist/modules/functions.types.d.ts +103 -0
  43. package/dist/modules/functions.types.js +1 -0
  44. package/dist/modules/integrations.d.ts +11 -0
  45. package/dist/modules/integrations.js +77 -0
  46. package/dist/modules/integrations.types.d.ts +413 -0
  47. package/dist/modules/integrations.types.js +1 -0
  48. package/dist/modules/sso.d.ts +12 -0
  49. package/dist/modules/sso.js +23 -0
  50. package/dist/modules/sso.types.d.ts +44 -0
  51. package/dist/modules/sso.types.js +1 -0
  52. package/dist/modules/types.d.ts +4 -0
  53. package/dist/modules/types.js +4 -0
  54. package/dist/modules/users.d.ts +16 -0
  55. package/dist/modules/users.js +23 -0
  56. package/dist/types.d.ts +72 -0
  57. package/dist/types.js +1 -0
  58. package/dist/utils/auth-utils.d.ts +117 -0
  59. package/dist/utils/auth-utils.js +189 -0
  60. package/dist/utils/auth-utils.types.d.ts +146 -0
  61. package/dist/utils/auth-utils.types.js +1 -0
  62. package/dist/utils/axios-client.d.ts +100 -0
  63. package/dist/utils/axios-client.js +193 -0
  64. package/dist/utils/axios-client.types.d.ts +28 -0
  65. package/dist/utils/axios-client.types.js +1 -0
  66. package/dist/utils/common.d.ts +3 -0
  67. package/dist/utils/common.js +6 -0
  68. package/dist/utils/sharedInstance.d.ts +1 -0
  69. package/dist/utils/sharedInstance.js +15 -0
  70. package/dist/utils/socket-utils.d.ts +47 -0
  71. package/dist/utils/socket-utils.js +115 -0
  72. package/package.json +87 -0
@@ -0,0 +1,71 @@
1
+ /**
2
+ * Creates the Connectors module for the Base44 SDK.
3
+ *
4
+ * @param axios - Axios instance (should be service role client)
5
+ * @param appId - Application ID
6
+ * @returns Connectors module with methods to retrieve OAuth tokens
7
+ * @internal
8
+ */
9
+ export function createConnectorsModule(axios, appId) {
10
+ return {
11
+ /**
12
+ * Retrieve an OAuth access token for a specific external integration type.
13
+ * @deprecated Use getConnection(integrationType) and use the returned accessToken (and connectionConfig when needed) instead.
14
+ */
15
+ // @ts-expect-error Return type mismatch with interface - implementation returns string, interface expects string but implementation is typed as ConnectorAccessTokenResponse
16
+ async getAccessToken(integrationType) {
17
+ if (!integrationType || typeof integrationType !== "string") {
18
+ throw new Error("Integration type is required and must be a string");
19
+ }
20
+ const response = await axios.get(`/apps/${appId}/external-auth/tokens/${integrationType}`);
21
+ // @ts-expect-error
22
+ return response.access_token;
23
+ },
24
+ async getConnection(integrationType) {
25
+ var _a;
26
+ if (!integrationType || typeof integrationType !== "string") {
27
+ throw new Error("Integration type is required and must be a string");
28
+ }
29
+ const response = await axios.get(`/apps/${appId}/external-auth/tokens/${integrationType}`);
30
+ const data = response;
31
+ return {
32
+ accessToken: data.access_token,
33
+ connectionConfig: (_a = data.connection_config) !== null && _a !== void 0 ? _a : null,
34
+ };
35
+ },
36
+ };
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
+ }
@@ -0,0 +1,296 @@
1
+ /**
2
+ * Registry of connector integration type names. The [`types generate`](/developers/references/cli/commands/types-generate) command fills this registry, then [`ConnectorIntegrationType`](#connectorintegrationtype) resolves to a union of the keys.
3
+ */
4
+ export interface ConnectorIntegrationTypeRegistry {
5
+ }
6
+ /**
7
+ * Union of all connector integration type names from the [`ConnectorIntegrationTypeRegistry`](#connectorintegrationtyperegistry). Defaults to `string` when no types have been generated.
8
+ *
9
+ * @example
10
+ * ```typescript
11
+ * // Using generated connector type names
12
+ * // With generated types, you get autocomplete on integration types
13
+ * const connection = await base44.asServiceRole.connectors.getConnection('googlecalendar');
14
+ * const token = connection.accessToken;
15
+ * ```
16
+ */
17
+ export type ConnectorIntegrationType = keyof ConnectorIntegrationTypeRegistry extends never ? string : keyof ConnectorIntegrationTypeRegistry;
18
+ /**
19
+ * Response from the connectors access token endpoint.
20
+ */
21
+ export interface ConnectorAccessTokenResponse {
22
+ access_token: string;
23
+ integration_type: string;
24
+ connection_config: Record<string, string> | null;
25
+ }
26
+ /**
27
+ * Connection details.
28
+ */
29
+ export interface ConnectorConnectionResponse {
30
+ /** The OAuth access token for the external service. */
31
+ accessToken: string;
32
+ /** Key-value configuration for the connection, or `null` if the connector does not provide one. */
33
+ connectionConfig: Record<string, string> | null;
34
+ }
35
+ /**
36
+ * Connectors module for managing app-scoped OAuth tokens for external services.
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, Slack, or GitHub, all users of the app share that same connection.
39
+ *
40
+ * Unlike the integrations module that provides pre-built functions, connectors give you
41
+ * raw OAuth tokens so you can call external service APIs directly with full control over
42
+ * the API calls you make. This is useful when you need custom API interactions that aren't
43
+ * covered by Base44's pre-built integrations.
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
+ *
89
+ * ## Authentication Modes
90
+ *
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.
92
+ *
93
+ * ## Dynamic Types
94
+ *
95
+ * If you're working in a TypeScript project, you can generate types from your app's connector configurations to get autocomplete on integration type names when calling `getConnection()`. See the [Dynamic Types](/developers/references/sdk/getting-started/dynamic-types) guide to get started.
96
+ */
97
+ export interface ConnectorsModule {
98
+ /**
99
+ * Retrieves an OAuth access token for a specific [external integration type](#available-connectors).
100
+ *
101
+ * @deprecated Use {@link getConnection} instead.
102
+ *
103
+ * Returns the OAuth token string for an external service that an app builder
104
+ * has connected to. This token represents the connected app builder's account
105
+ * and can be used to make authenticated API calls to that external service on behalf of the app.
106
+ *
107
+ * @param integrationType - The type of integration, such as `'googlecalendar'`, `'slack'`, `'slackbot'`, `'github'`, or `'discord'`. See [Available connectors](#available-connectors) for the full list.
108
+ * @returns Promise resolving to the access token string.
109
+ *
110
+ * @example
111
+ * ```typescript
112
+ * // Google Calendar connection
113
+ * // Get Google Calendar OAuth token and fetch upcoming events
114
+ * const googleToken = await base44.asServiceRole.connectors.getAccessToken('googlecalendar');
115
+ *
116
+ * // Fetch upcoming 10 events
117
+ * const timeMin = new Date().toISOString();
118
+ * const url = `https://www.googleapis.com/calendar/v3/calendars/primary/events?maxResults=10&orderBy=startTime&singleEvents=true&timeMin=${timeMin}`;
119
+ *
120
+ * const calendarResponse = await fetch(url, {
121
+ * headers: { 'Authorization': `Bearer ${googleToken}` }
122
+ * });
123
+ *
124
+ * const events = await calendarResponse.json();
125
+ * ```
126
+ *
127
+ * @example
128
+ * ```typescript
129
+ * // Slack User connection
130
+ * // Get Slack user token and list channels
131
+ * const slackToken = await base44.asServiceRole.connectors.getAccessToken('slack');
132
+ *
133
+ * // List all public and private channels
134
+ * const url = 'https://slack.com/api/conversations.list?types=public_channel,private_channel&limit=100';
135
+ *
136
+ * const slackResponse = await fetch(url, {
137
+ * headers: { 'Authorization': `Bearer ${slackToken}` }
138
+ * });
139
+ *
140
+ * const data = await slackResponse.json();
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
+ * ```
165
+ */
166
+ getAccessToken(integrationType: ConnectorIntegrationType): Promise<string>;
167
+ /**
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`.
172
+ *
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.
175
+ *
176
+ * @param integrationType - The type of integration, such as `'googlecalendar'`, `'slack'`, `'slackbot'`, `'github'`, or `'discord'`. See [Available connectors](#available-connectors) for the full list.
177
+ * @returns Promise resolving to a {@link ConnectorConnectionResponse} with `accessToken` and `connectionConfig`.
178
+ *
179
+ * @example
180
+ * ```typescript
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();
208
+ * ```
209
+ *
210
+ * @example
211
+ * ```typescript
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();
223
+ * ```
224
+ */
225
+ getConnection(integrationType: ConnectorIntegrationType): Promise<ConnectorConnectionResponse>;
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
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,11 @@
1
+ import { AxiosInstance } from "axios";
2
+ import { CustomIntegrationsModule } from "./custom-integrations.types.js";
3
+ /**
4
+ * Creates the custom integrations module for the Base44 SDK.
5
+ *
6
+ * @param axios - Axios instance for making HTTP requests
7
+ * @param appId - Application ID
8
+ * @returns Custom integrations module with `call()` method
9
+ * @internal
10
+ */
11
+ export declare function createCustomIntegrationsModule(axios: AxiosInstance, appId: string): CustomIntegrationsModule;
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Creates the custom integrations module for the Base44 SDK.
3
+ *
4
+ * @param axios - Axios instance for making HTTP requests
5
+ * @param appId - Application ID
6
+ * @returns Custom integrations module with `call()` method
7
+ * @internal
8
+ */
9
+ export function createCustomIntegrationsModule(axios, appId) {
10
+ return {
11
+ async call(slug, operationId, params) {
12
+ // Validate required parameters
13
+ if (!(slug === null || slug === void 0 ? void 0 : slug.trim())) {
14
+ throw new Error("Integration slug is required and cannot be empty");
15
+ }
16
+ if (!(operationId === null || operationId === void 0 ? void 0 : operationId.trim())) {
17
+ throw new Error("Operation ID is required and cannot be empty");
18
+ }
19
+ // Convert camelCase to snake_case for Python backend
20
+ const { pathParams, queryParams, ...rest } = params !== null && params !== void 0 ? params : {};
21
+ const body = {
22
+ ...rest,
23
+ ...(pathParams && { path_params: pathParams }),
24
+ ...(queryParams && { query_params: queryParams }),
25
+ };
26
+ // Make the API call
27
+ const response = await axios.post(`/apps/${appId}/integrations/custom/${slug}/${operationId}`, body);
28
+ // The axios interceptor extracts response.data, so we get the payload directly
29
+ return response;
30
+ },
31
+ };
32
+ }
@@ -0,0 +1,89 @@
1
+ /**
2
+ * Parameters for calling a custom integration endpoint.
3
+ * @internal
4
+ */
5
+ export interface CustomIntegrationCallParams {
6
+ /**
7
+ * Request body payload to send to the external API.
8
+ */
9
+ payload?: Record<string, any>;
10
+ /**
11
+ * Path parameters to substitute in the URL. For example, `{ owner: "user", repo: "repo" }`.
12
+ */
13
+ pathParams?: Record<string, string>;
14
+ /**
15
+ * Query string parameters to append to the URL.
16
+ */
17
+ queryParams?: Record<string, any>;
18
+ }
19
+ /**
20
+ * Response from a custom integration call.
21
+ * @internal
22
+ */
23
+ export interface CustomIntegrationCallResponse {
24
+ /**
25
+ * Whether the external API returned a 2xx status code.
26
+ */
27
+ success: boolean;
28
+ /**
29
+ * The HTTP status code returned by the external API.
30
+ */
31
+ status_code: number;
32
+ /**
33
+ * The response data from the external API.
34
+ * Can be any JSON-serializable value depending on the external API's response.
35
+ */
36
+ data: any;
37
+ }
38
+ /**
39
+ * Module for calling custom pre-configured API integrations.
40
+ *
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.
42
+ */
43
+ export interface CustomIntegrationsModule {
44
+ /**
45
+ * Call a custom integration endpoint.
46
+ *
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.
50
+ * @returns Promise resolving to the integration call response.
51
+ *
52
+ * @throws {Error} If slug is not provided.
53
+ * @throws {Error} If operationId is not provided.
54
+ * @throws {Base44Error} If the integration or operation is not found (404).
55
+ * @throws {Base44Error} If the external API call fails (502).
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
+ * ```
87
+ */
88
+ call(slug: string, operationId: string, params?: CustomIntegrationCallParams): Promise<CustomIntegrationCallResponse>;
89
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,20 @@
1
+ import { AxiosInstance } from "axios";
2
+ import { EntitiesModule } from "./entities.types";
3
+ import { RoomsSocket } from "../utils/socket-utils.js";
4
+ /**
5
+ * Configuration for the entities module.
6
+ * @internal
7
+ */
8
+ export interface EntitiesModuleConfig {
9
+ axios: AxiosInstance;
10
+ appId: string;
11
+ getSocket: () => ReturnType<typeof RoomsSocket>;
12
+ }
13
+ /**
14
+ * Creates the entities module for the Base44 SDK.
15
+ *
16
+ * @param config - Configuration object containing axios, appId, and getSocket
17
+ * @returns Entities module with dynamic entity access
18
+ * @internal
19
+ */
20
+ export declare function createEntitiesModule(config: EntitiesModuleConfig): EntitiesModule;
@@ -0,0 +1,149 @@
1
+ /**
2
+ * Creates the entities module for the Base44 SDK.
3
+ *
4
+ * @param config - Configuration object containing axios, appId, and getSocket
5
+ * @returns Entities module with dynamic entity access
6
+ * @internal
7
+ */
8
+ export function createEntitiesModule(config) {
9
+ const { axios, appId, getSocket } = config;
10
+ // Using Proxy to dynamically handle entity names
11
+ return new Proxy({}, {
12
+ get(target, entityName) {
13
+ // Don't create handlers for internal properties
14
+ if (typeof entityName !== "string" ||
15
+ entityName === "then" ||
16
+ entityName.startsWith("_")) {
17
+ return undefined;
18
+ }
19
+ // Create entity handler
20
+ return createEntityHandler(axios, appId, entityName, getSocket);
21
+ },
22
+ });
23
+ }
24
+ /**
25
+ * Parses the realtime message data and extracts event information.
26
+ * @internal
27
+ */
28
+ function parseRealtimeMessage(dataStr) {
29
+ var _a;
30
+ try {
31
+ const parsed = JSON.parse(dataStr);
32
+ return {
33
+ type: parsed.type,
34
+ data: parsed.data,
35
+ id: parsed.id || ((_a = parsed.data) === null || _a === void 0 ? void 0 : _a.id),
36
+ timestamp: parsed.timestamp || new Date().toISOString(),
37
+ };
38
+ }
39
+ catch (error) {
40
+ console.warn("[Base44 SDK] Failed to parse realtime message:", error);
41
+ return null;
42
+ }
43
+ }
44
+ /**
45
+ * Creates a handler for a specific entity.
46
+ *
47
+ * @param axios - Axios instance
48
+ * @param appId - Application ID
49
+ * @param entityName - Entity name
50
+ * @param getSocket - Function to get the socket instance
51
+ * @returns Entity handler with CRUD methods
52
+ * @internal
53
+ */
54
+ function createEntityHandler(axios, appId, entityName, getSocket) {
55
+ const baseURL = `/apps/${appId}/entities/${entityName}`;
56
+ return {
57
+ // List entities with optional pagination and sorting
58
+ async list(sort, limit, skip, fields) {
59
+ const params = {};
60
+ if (sort)
61
+ params.sort = sort;
62
+ if (limit)
63
+ params.limit = limit;
64
+ if (skip)
65
+ params.skip = skip;
66
+ if (fields)
67
+ params.fields = Array.isArray(fields) ? fields.join(",") : fields;
68
+ return axios.get(baseURL, { params });
69
+ },
70
+ // Filter entities based on query
71
+ async filter(query, sort, limit, skip, fields) {
72
+ const params = {
73
+ q: JSON.stringify(query),
74
+ };
75
+ if (sort)
76
+ params.sort = sort;
77
+ if (limit)
78
+ params.limit = limit;
79
+ if (skip)
80
+ params.skip = skip;
81
+ if (fields)
82
+ params.fields = Array.isArray(fields) ? fields.join(",") : fields;
83
+ return axios.get(baseURL, { params });
84
+ },
85
+ // Get entity by ID
86
+ async get(id) {
87
+ return axios.get(`${baseURL}/${id}`);
88
+ },
89
+ // Create new entity
90
+ async create(data) {
91
+ return axios.post(baseURL, data);
92
+ },
93
+ // Update entity by ID
94
+ async update(id, data) {
95
+ return axios.put(`${baseURL}/${id}`, data);
96
+ },
97
+ // Delete entity by ID
98
+ async delete(id) {
99
+ return axios.delete(`${baseURL}/${id}`);
100
+ },
101
+ // Delete multiple entities based on query
102
+ async deleteMany(query) {
103
+ return axios.delete(baseURL, { data: query });
104
+ },
105
+ // Create multiple entities in a single request
106
+ async bulkCreate(data) {
107
+ return axios.post(`${baseURL}/bulk`, data);
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
+ },
117
+ // Import entities from a file
118
+ async importEntities(file) {
119
+ const formData = new FormData();
120
+ formData.append("file", file, file.name);
121
+ return axios.post(`${baseURL}/import`, formData, {
122
+ headers: {
123
+ "Content-Type": "multipart/form-data",
124
+ },
125
+ });
126
+ },
127
+ // Subscribe to realtime updates
128
+ subscribe(callback) {
129
+ const room = `entities:${appId}:${entityName}`;
130
+ // Get the socket and subscribe to the room
131
+ const socket = getSocket();
132
+ const unsubscribe = socket.subscribeToRoom(room, {
133
+ update_model: (msg) => {
134
+ const event = parseRealtimeMessage(msg.data);
135
+ if (!event) {
136
+ return;
137
+ }
138
+ try {
139
+ callback(event);
140
+ }
141
+ catch (error) {
142
+ console.error("[Base44 SDK] Subscription callback error:", error);
143
+ }
144
+ },
145
+ });
146
+ return unsubscribe;
147
+ },
148
+ };
149
+ }