Skip to content

Commit e37eecd

Browse files
committed
connectors initiate method
1 parent 27a8748 commit e37eecd

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

src/modules/connectors.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { AxiosInstance } from "axios";
22
import {
33
ConnectorIntegrationType,
44
ConnectorAccessTokenResponse,
5+
ConnectorInitiateResponse,
56
ConnectorsModule,
67
} from "./connectors.types.js";
78

@@ -34,5 +35,21 @@ export function createConnectorsModule(
3435
// @ts-expect-error
3536
return response.access_token;
3637
},
38+
39+
async initiate(
40+
integrationType: ConnectorIntegrationType
41+
): Promise<string> {
42+
if (!integrationType || typeof integrationType !== "string") {
43+
throw new Error("Integration type is required and must be a string");
44+
}
45+
46+
const response = await axios.post<ConnectorInitiateResponse>(
47+
`/apps/${appId}/end-user-auth/initiate`,
48+
{ integration_type: integrationType }
49+
);
50+
51+
// @ts-expect-error
52+
return response.redirect_url;
53+
},
3754
};
3855
}

src/modules/connectors.types.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,13 @@ export interface ConnectorAccessTokenResponse {
2424
access_token: string;
2525
}
2626

27+
/**
28+
* Response from the connectors initiate endpoint.
29+
*/
30+
export interface ConnectorInitiateResponse {
31+
redirect_url: string;
32+
}
33+
2734
/**
2835
* Connectors module for managing OAuth tokens for external services.
2936
*
@@ -85,4 +92,24 @@ export interface ConnectorsModule {
8592
* ```
8693
*/
8794
getAccessToken(integrationType: ConnectorIntegrationType): Promise<string>;
95+
96+
/**
97+
* Initiates the end-user OAuth flow for a specific external integration type.
98+
*
99+
* Returns a redirect URL that the end user should be redirected to in order to
100+
* authenticate with the external service.
101+
*
102+
* @param integrationType - The type of integration, such as `'googlecalendar'`, `'slack'`, or `'github'`.
103+
* @returns Promise resolving to the redirect URL string.
104+
*
105+
* @example
106+
* ```typescript
107+
* // Initiate Google Calendar OAuth for the end user
108+
* const redirectUrl = await base44.asServiceRole.connectors.initiate('googlecalendar');
109+
*
110+
* // Redirect the user to the OAuth provider
111+
* res.redirect(redirectUrl);
112+
* ```
113+
*/
114+
initiate(integrationType: ConnectorIntegrationType): Promise<string>;
88115
}

0 commit comments

Comments
 (0)