Skip to content

Commit 8cf01a1

Browse files
committed
new public api
1 parent 85025ab commit 8cf01a1

5 files changed

Lines changed: 100 additions & 21 deletions

File tree

src/client.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@ import { createEntitiesModule } from "./modules/entities.js";
33
import { createIntegrationsModule } from "./modules/integrations.js";
44
import { createAuthModule } from "./modules/auth.js";
55
import { createSsoModule } from "./modules/sso.js";
6-
import { createConnectorsModule } from "./modules/connectors.js";
6+
import {
7+
createConnectorsModule,
8+
createUserConnectorsModule,
9+
} from "./modules/connectors.js";
710
import { getAccessToken } from "./utils/auth-utils.js";
811
import { createFunctionsModule } from "./modules/functions.js";
912
import { createAgentsModule } from "./modules/agents.js";
@@ -151,7 +154,7 @@ export function createClient(config: CreateClientConfig): Base44Client {
151154
getSocket,
152155
}),
153156
integrations: createIntegrationsModule(axiosClient, appId),
154-
connectors: createConnectorsModule(axiosClient, appId),
157+
connectors: createUserConnectorsModule(axiosClient, appId),
155158
auth: userAuthModule,
156159
functions: createFunctionsModule(functionsAxiosClient, appId),
157160
agents: createAgentsModule({

src/client.types.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@ import type { EntitiesModule } from "./modules/entities.types.js";
33
import type { IntegrationsModule } from "./modules/integrations.types.js";
44
import type { AuthModule } from "./modules/auth.types.js";
55
import type { SsoModule } from "./modules/sso.types.js";
6-
import type { ConnectorsModule } from "./modules/connectors.types.js";
6+
import type {
7+
ConnectorsModule,
8+
UserConnectorsModule,
9+
} from "./modules/connectors.types.js";
710
import type { FunctionsModule } from "./modules/functions.types.js";
811
import type { AgentsModule } from "./modules/agents.types.js";
912
import type { AppLogsModule } from "./modules/app-logs.types.js";
@@ -88,8 +91,8 @@ export interface Base44Client {
8891
auth: AuthModule;
8992
/** The underlying Axios instance used for API requests. Useful for making custom API calls with the same authentication and configuration as the SDK. */
9093
axiosClient: AxiosInstance;
91-
/** {@link ConnectorsModule | Connectors module} for OAuth token retrieval. */
92-
connectors: ConnectorsModule;
94+
/** {@link UserConnectorsModule | Connectors module} for end-user OAuth flows. */
95+
connectors: UserConnectorsModule;
9396
/** {@link EntitiesModule | Entities module} for CRUD operations on your data models. */
9497
entities: EntitiesModule;
9598
/** {@link FunctionsModule | Functions module} for invoking custom backend functions. */

src/index.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,10 @@ export type { AppLogsModule } from "./modules/app-logs.types.js";
101101

102102
export type { SsoModule, SsoAccessTokenResponse } from "./modules/sso.types.js";
103103

104-
export type { ConnectorsModule } from "./modules/connectors.types.js";
104+
export type {
105+
ConnectorsModule,
106+
UserConnectorsModule,
107+
} from "./modules/connectors.types.js";
105108

106109
export type {
107110
CustomIntegrationsModule,

src/modules/connectors.ts

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
ConnectorAccessTokenResponse,
55
ConnectorInitiateResponse,
66
ConnectorsModule,
7+
UserConnectorsModule,
78
} from "./connectors.types.js";
89

910
/**
@@ -35,8 +36,39 @@ export function createConnectorsModule(
3536
// @ts-expect-error
3637
return response.access_token;
3738
},
39+
};
40+
}
41+
42+
/**
43+
* Creates the user-scoped Connectors module (end-user OAuth flows).
44+
*
45+
* @param axios - Axios instance (user-scoped client)
46+
* @param appId - Application ID
47+
* @returns User connectors module with end-user OAuth methods
48+
* @internal
49+
*/
50+
export function createUserConnectorsModule(
51+
axios: AxiosInstance,
52+
appId: string
53+
): UserConnectorsModule {
54+
return {
55+
// @ts-expect-error Return type mismatch - implementation returns object, interface expects string
56+
async getEndUserAccessToken(
57+
integrationType: ConnectorIntegrationType
58+
): Promise<ConnectorAccessTokenResponse> {
59+
if (!integrationType || typeof integrationType !== "string") {
60+
throw new Error("Integration type is required and must be a string");
61+
}
62+
63+
const response = await axios.get<ConnectorAccessTokenResponse>(
64+
`/apps/${appId}/end-user-auth/tokens/${integrationType}`
65+
);
66+
67+
// @ts-expect-error
68+
return response.access_token;
69+
},
3870

39-
async initiate(
71+
async connectEndUser(
4072
integrationType: ConnectorIntegrationType
4173
): Promise<string> {
4274
if (!integrationType || typeof integrationType !== "string") {
@@ -52,7 +84,7 @@ export function createConnectorsModule(
5284
return response.redirect_url;
5385
},
5486

55-
async disconnect(
87+
async disconnectEndUser(
5688
integrationType: ConnectorIntegrationType
5789
): Promise<void> {
5890
if (!integrationType || typeof integrationType !== "string") {

src/modules/connectors.types.ts

Lines changed: 51 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export interface ConnectorInitiateResponse {
3232
}
3333

3434
/**
35-
* Connectors module for managing OAuth tokens for external services.
35+
* Connectors module for managing app-scoped OAuth tokens for external services.
3636
*
3737
* 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.
3838
*
@@ -41,7 +41,7 @@ export interface ConnectorInitiateResponse {
4141
* the API calls you make. This is useful when you need custom API interactions that aren't
4242
* covered by Base44's pre-built integrations.
4343
*
44-
* 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.
44+
* This module is only available via `base44.asServiceRole.connectors`.
4545
*
4646
* ## Dynamic Types
4747
*
@@ -92,41 +92,79 @@ export interface ConnectorsModule {
9292
* ```
9393
*/
9494
getAccessToken(integrationType: ConnectorIntegrationType): Promise<string>;
95+
}
96+
97+
/**
98+
* User-scoped connectors module for managing end-user OAuth connections.
99+
*
100+
* This module provides methods for end-user OAuth flows: initiating an OAuth connection,
101+
* retrieving the end user's access token, and disconnecting the end user's connection.
102+
*
103+
* Unlike {@link ConnectorsModule | ConnectorsModule} which manages app-scoped tokens,
104+
* this module manages tokens scoped to individual end users.
105+
*
106+
* Available via `base44.connectors`.
107+
*
108+
* ## Dynamic Types
109+
*
110+
* 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. See the [Dynamic Types](/developers/references/sdk/getting-started/dynamic-types) guide to get started.
111+
*/
112+
export interface UserConnectorsModule {
113+
/**
114+
* Retrieves an OAuth access token for an end user's connection to a specific external integration.
115+
*
116+
* Returns the OAuth token string that belongs to the currently authenticated end user
117+
* for the specified external service.
118+
*
119+
* @param integrationType - The type of integration, such as `'googlecalendar'`, `'slack'`, or `'github'`.
120+
* @returns Promise resolving to the access token string.
121+
*
122+
* @example
123+
* ```typescript
124+
* // Get the end user's Google Calendar token
125+
* const token = await base44.connectors.getEndUserAccessToken('googlecalendar');
126+
*
127+
* const response = await fetch('https://www.googleapis.com/calendar/v3/calendars/primary/events', {
128+
* headers: { 'Authorization': `Bearer ${token}` }
129+
* });
130+
* ```
131+
*/
132+
getEndUserAccessToken(integrationType: ConnectorIntegrationType): Promise<string>;
95133

96134
/**
97135
* Initiates the end-user OAuth flow for a specific external integration type.
98136
*
99-
* Returns a redirect URL that the end user should be redirected to in order to
137+
* Returns a redirect URL that the end user should be navigated to in order to
100138
* authenticate with the external service.
101139
*
102140
* @param integrationType - The type of integration, such as `'googlecalendar'`, `'slack'`, or `'github'`.
103141
* @returns Promise resolving to the redirect URL string.
104142
*
105143
* @example
106144
* ```typescript
107-
* // Initiate Google Calendar OAuth for the end user
108-
* const redirectUrl = await base44.asServiceRole.connectors.initiate('googlecalendar');
145+
* // Start Google Calendar OAuth for the end user
146+
* const redirectUrl = await base44.connectors.connectEndUser('googlecalendar');
109147
*
110148
* // Redirect the user to the OAuth provider
111-
* res.redirect(redirectUrl);
149+
* window.location.href = redirectUrl;
112150
* ```
113151
*/
114-
initiate(integrationType: ConnectorIntegrationType): Promise<string>;
152+
connectEndUser(integrationType: ConnectorIntegrationType): Promise<string>;
115153

116154
/**
117-
* Disconnects an end-user's OAuth connection for a specific external integration type.
155+
* Disconnects an end user's OAuth connection for a specific external integration type.
118156
*
119-
* Removes the stored OAuth credentials for the end user's connection to the
120-
* specified external service.
157+
* Removes the stored OAuth credentials for the currently authenticated end user's
158+
* connection to the specified external service.
121159
*
122160
* @param integrationType - The type of integration to disconnect, such as `'googlecalendar'`, `'slack'`, or `'github'`.
123161
* @returns Promise resolving when the connection has been removed.
124162
*
125163
* @example
126164
* ```typescript
127-
* // Disconnect Google Calendar for the end user
128-
* await base44.asServiceRole.connectors.disconnect('googlecalendar');
165+
* // Disconnect the end user's Google Calendar connection
166+
* await base44.connectors.disconnectEndUser('googlecalendar');
129167
* ```
130168
*/
131-
disconnect(integrationType: ConnectorIntegrationType): Promise<void>;
169+
disconnectEndUser(integrationType: ConnectorIntegrationType): Promise<void>;
132170
}

0 commit comments

Comments
 (0)