Skip to content

Commit a909a88

Browse files
committed
address review
1 parent eac4705 commit a909a88

2 files changed

Lines changed: 81 additions & 73 deletions

File tree

src/modules/custom-integrations.types.ts

Lines changed: 55 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,19 @@
33
*/
44
export interface CustomIntegrationCallParams {
55
/**
6-
* Request body to send to the external API. The payload is JSON-serialized before being sent.
6+
* Request body payload to send to the external API.
77
*/
88
payload?: Record<string, any>;
99

1010
/**
11-
* Path parameters to substitute into the URL template.
12-
* For example, if the API endpoint is `/repos/{owner}/{repo}/issues`,
13-
* pass `{ owner: "myorg", repo: "myrepo" }`.
11+
* Path parameters to substitute in the URL (e.g., `{ owner: "user", repo: "repo" }`).
1412
*/
1513
pathParams?: Record<string, string>;
1614

1715
/**
1816
* Query string parameters to append to the URL.
19-
* For example, `{ state: "open", per_page: 50 }` becomes `?state=open&per_page=50`.
2017
*/
2118
queryParams?: Record<string, any>;
22-
23-
/**
24-
* Additional HTTP headers to include in the request.
25-
* These headers are merged with any headers configured for the integration itself, with headers specified here taking precedence in case of conflicts.
26-
*/
27-
headers?: Record<string, string>;
2819
}
2920

3021
/**
@@ -42,69 +33,77 @@ export interface CustomIntegrationCallResponse {
4233
status_code: number;
4334

4435
/**
45-
* The parsed JSON response body from the external API.
46-
* The structure depends on the API endpoint being called.
36+
* The response data from the external API.
37+
* Can be any JSON-serializable value depending on the external API's response.
4738
*/
4839
data: any;
4940
}
5041

5142
/**
52-
* Custom integrations module for calling workspace-level API integrations.
43+
* Module for calling custom workspace-level API integrations.
44+
*
45+
* Custom integrations allow workspace administrators to connect any external API
46+
* by importing an OpenAPI specification. Apps in the workspace can then call
47+
* these integrations using this module.
48+
*
49+
* Unlike the built-in integrations (like `Core`), custom integrations:
50+
* - Are defined per-workspace by importing OpenAPI specs
51+
* - Use a slug-based identifier instead of package names
52+
* - Proxy requests through Base44's backend (credentials never exposed to frontend)
53+
*
54+
* @example
55+
* ```typescript
56+
* // Call a custom CRM integration
57+
* const response = await base44.integrations.custom.call(
58+
* "my-crm", // integration slug (defined by workspace admin)
59+
* "get:/contacts", // endpoint: method:path format
60+
* {
61+
* queryParams: { limit: 10 }
62+
* }
63+
* );
64+
*
65+
* if (response.success) {
66+
* console.log("Contacts:", response.data);
67+
* } else {
68+
* console.error("API returned error:", response.status_code);
69+
* }
70+
* ```
71+
*
72+
* @example
73+
* ```typescript
74+
* // Call with path params and request body payload
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+
* labels: ["bug"]
84+
* }
85+
* }
86+
* );
87+
* ```
5388
*/
5489
export interface CustomIntegrationsModule {
5590
/**
5691
* Call a custom integration endpoint.
5792
*
58-
* Custom integrations are external APIs that have been pre-configured by a workspace administrator who imports an OpenAPI specification. Each integration is identified by a slug and exposes operations defined in the specification.
59-
*
60-
* Requests are proxied through Base44's backend, so API credentials aren't exposed. That means you can safely use this method to call external APIs from frontend code.
61-
*
62-
* @param slug - The integration's unique identifier, as defined by the workspace admin.
63-
* @param operationId - The operation ID from the OpenAPI specification, such as `"listIssues"` or `"getUser"`.
64-
* @param params - Optional parameters to send to the external API.
93+
* @param slug - The integration's unique identifier (slug), as defined by the workspace admin.
94+
* @param endpoint - The endpoint in `method:path` format (e.g., `"get:/contacts"`, `"post:/users/{id}"`). The method is the HTTP verb (lowercase) and the path matches the OpenAPI specification.
95+
* @param params - Optional parameters including payload, pathParams, and queryParams.
6596
* @returns Promise resolving to the integration call response.
6697
*
6798
* @throws {Error} If slug is not provided.
68-
* @throws {Error} If operationId is not provided.
69-
* @throws {Base44Error} If the integration or operation is not found (404).
99+
* @throws {Error} If endpoint is not provided.
100+
* @throws {Base44Error} If the integration or endpoint is not found (404).
70101
* @throws {Base44Error} If the external API call fails (502).
71102
* @throws {Base44Error} If the request times out (504).
72-
*
73-
* @example
74-
* ```typescript
75-
* // GET request with path and query parameters
76-
* const response = await base44.integrations.custom.call(
77-
* "github",
78-
* "listRepoIssues",
79-
* {
80-
* pathParams: { owner: "myorg", repo: "myrepo" },
81-
* queryParams: { state: "open", per_page: 50 }
82-
* }
83-
* );
84-
*
85-
* if (response.success) {
86-
* console.log("Found issues:", response.data.length);
87-
* }
88-
* ```
89-
*
90-
* @example
91-
* ```typescript
92-
* // POST request with a JSON body
93-
* const response = await base44.integrations.custom.call(
94-
* "slack",
95-
* "postMessage",
96-
* {
97-
* payload: {
98-
* channel: "#general",
99-
* text: "Hello from Base44!"
100-
* }
101-
* }
102-
* );
103-
* ```
104103
*/
105104
call(
106105
slug: string,
107-
operationId: string,
106+
endpoint: string,
108107
params?: CustomIntegrationCallParams
109108
): Promise<CustomIntegrationCallResponse>;
110109
}

src/modules/integrations.types.ts

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -351,28 +351,22 @@ export interface CoreIntegrations {
351351
}
352352

353353
/**
354-
* Integrations module for calling integration methods.
354+
* Integrations module for calling integration endpoints.
355355
*
356-
* 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.
356+
* This module provides access to integration endpoints for interacting with external
357+
* services. Integrations are organized into packages. Base44 provides built-in integrations
358+
* in the `Core` package.
357359
*
358-
* There are two types of integrations:
360+
* Unlike the connectors module that gives you raw OAuth tokens, integrations provide
361+
* pre-built functions that Base44 executes on your behalf.
359362
*
360-
* - **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:
361-
* ```
362-
* base44.integrations.Core.FunctionName(params)
363-
* ```
364-
*
365-
* - **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:
366-
* ```
367-
* base44.integrations.custom.call(slug, operationId, params)
368-
* ```
369-
*
370-
* <Info>To call a custom integration, it must be pre-configured by a workspace administrator who imports an OpenAPI specification.</Info>
363+
* Integration endpoints are accessed dynamically using the pattern:
364+
* `base44.integrations.PackageName.EndpointName(params)`
371365
*
372366
* This module is available to use with a client in all authentication modes:
373367
*
374-
* - **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.
375-
* - **Service role authentication** (`base44.asServiceRole.integrations`): Integration methods are invoked with elevated admin-level permissions. The methods execute with admin authentication context.
368+
* - **Anonymous or User authentication** (`base44.integrations`): Integration endpoints are invoked with the current user's permissions. Anonymous users invoke endpoints without authentication, while authenticated users invoke endpoints with their authentication context.
369+
* - **Service role authentication** (`base44.asServiceRole.integrations`): Integration endpoints are invoked with elevated admin-level permissions. The endpoints execute with admin authentication context.
376370
*/
377371
export type IntegrationsModule = {
378372
/**
@@ -381,7 +375,22 @@ export type IntegrationsModule = {
381375
Core: CoreIntegrations;
382376

383377
/**
384-
* Custom integrations module for calling pre-configured external APIs.
378+
* Custom integrations module for calling workspace-level API integrations.
379+
*
380+
* Allows calling external APIs that workspace admins have configured
381+
* by importing OpenAPI specifications.
382+
*
383+
* @example
384+
* ```typescript
385+
* const response = await base44.integrations.custom.call(
386+
* "github", // integration slug
387+
* "listIssues", // operation ID
388+
* {
389+
* pathParams: { owner: "myorg", repo: "myrepo" },
390+
* queryParams: { state: "open" }
391+
* }
392+
* );
393+
* ```
385394
*/
386395
custom: CustomIntegrationsModule;
387396
} & {

0 commit comments

Comments
 (0)