Skip to content

Commit 8865e20

Browse files
roymilohdavidvaks
andauthored
external auth support - add connectors to service role (#40)
* external auth support * mv * url * change naming from app-connections to connectors --------- Co-authored-by: vaksdavid <davidv@wix.com>
1 parent 01fb2e8 commit 8865e20

4 files changed

Lines changed: 48 additions & 1 deletion

File tree

src/client.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ 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";
67
import { getAccessToken } from "./utils/auth-utils.js";
78
import { createFunctionsModule } from "./modules/functions.js";
89
import { createAgentsModule } from "./modules/agents.js";
@@ -127,6 +128,7 @@ export function createClient(config: {
127128
entities: createEntitiesModule(serviceRoleAxiosClient, appId),
128129
integrations: createIntegrationsModule(serviceRoleAxiosClient, appId),
129130
sso: createSsoModule(serviceRoleAxiosClient, appId, token),
131+
connectors: createConnectorsModule(serviceRoleAxiosClient, appId),
130132
functions: createFunctionsModule(serviceRoleFunctionsAxiosClient, appId),
131133
agents: createAgentsModule({
132134
axios: serviceRoleAxiosClient,

src/modules/connectors.ts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import { AxiosInstance } from "axios";
2+
import {
3+
ConnectorIntegrationType,
4+
ConnectorAccessTokenResponse,
5+
} from "./connectors.types.js";
6+
7+
/**
8+
* Creates the Connectors module for the Base44 SDK
9+
* @param axios - Axios instance (should be service role client)
10+
* @param appId - Application ID
11+
* @returns Connectors module
12+
*/
13+
export function createConnectorsModule(axios: AxiosInstance, appId: string) {
14+
return {
15+
/**
16+
* Retrieve an access token for a given integration type
17+
* @param integrationType - The integration type to get access token for
18+
* @returns Access token response
19+
*/
20+
async getAccessToken(
21+
integrationType: ConnectorIntegrationType
22+
): Promise<ConnectorAccessTokenResponse> {
23+
if (!integrationType || typeof integrationType !== "string") {
24+
throw new Error(
25+
"Integration type is required and must be a string"
26+
);
27+
}
28+
29+
const response = await axios.get<ConnectorAccessTokenResponse>(
30+
`/apps/${appId}/external-auth/tokens/${integrationType}`
31+
);
32+
33+
// @ts-expect-error
34+
return response.access_token;
35+
},
36+
};
37+
}
38+

src/modules/connectors.types.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
export type ConnectorIntegrationType = string;
2+
3+
export type ConnectorAccessTokenResponse = {
4+
access_token: string;
5+
};
6+

src/modules/types.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
export * from "./app.types.js";
2-
export * from "./agents.types.js";
2+
export * from "./agents.types.js";
3+
export * from "./connectors.types.js";

0 commit comments

Comments
 (0)