Skip to content

Commit ab0c64e

Browse files
committed
add deprecation notice on getAccessToken
1 parent 85565c5 commit ab0c64e

2 files changed

Lines changed: 24 additions & 9 deletions

File tree

src/modules/connectors.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,17 @@ export function createConnectorsModule(
1919
appId: string
2020
): ConnectorsModule {
2121
return {
22-
// Retrieve an OAuth access token for a specific external integration type
23-
// @ts-expect-error Return type mismatch with interface - implementation returns object, interface expects string
22+
/**
23+
* Retrieve an OAuth access token for a specific external integration type.
24+
* @deprecated Use getConnection(integrationType) and use the returned accessToken (and connectionConfig when needed) instead.
25+
*/
26+
// @ts-expect-error Return type mismatch with interface - implementation returns string, interface expects string but implementation is typed as ConnectorAccessTokenResponse
2427
async getAccessToken(
2528
integrationType: ConnectorIntegrationType
2629
): Promise<ConnectorAccessTokenResponse> {
30+
console.warn(
31+
"[Base44 SDK] connectors.getAccessToken() is deprecated. Use getConnection(integrationType) and use the returned accessToken instead."
32+
);
2733
if (!integrationType || typeof integrationType !== "string") {
2834
throw new Error("Integration type is required and must be a string");
2935
}

src/modules/connectors.types.ts

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ export interface ConnectorIntegrationTypeRegistry {}
1010
* ```typescript
1111
* // Using generated connector type names
1212
* // With generated types, you get autocomplete on integration types
13-
* const token = await base44.asServiceRole.connectors.getAccessToken('googlecalendar');
13+
* const connection = await base44.asServiceRole.connectors.getConnection('googlecalendar');
14+
* const token = connection.accessToken;
1415
* ```
1516
*/
1617
export type ConnectorIntegrationType = keyof ConnectorIntegrationTypeRegistry extends never
@@ -52,12 +53,14 @@ export interface ConnectorConnectionResponse {
5253
*
5354
* ## Dynamic Types
5455
*
55-
* 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 `getAccessToken()`. See the [Dynamic Types](/developers/references/sdk/getting-started/dynamic-types) guide to get started.
56+
* 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.
5657
*/
5758
export interface ConnectorsModule {
5859
/**
5960
* Retrieves an OAuth access token for a specific external integration type.
6061
*
62+
* @deprecated Use {@link getConnection} and use the returned `accessToken` (and `connectionConfig` when needed) instead.
63+
*
6164
* Returns the OAuth token string for an external service that an app builder
6265
* has connected to. This token represents the connected app builder's account
6366
* and can be used to make authenticated API calls to that external service on behalf of the app.
@@ -120,14 +123,20 @@ export interface ConnectorsModule {
120123
*
121124
* @example
122125
* ```typescript
123-
* // Using connection config for a service that requires extra parameters
126+
* // Shopify: connectionConfig has subdomain (e.g. "my-store" for my-store.myshopify.com)
124127
* const connection = await base44.asServiceRole.connectors.getConnection('shopify');
125128
* const { accessToken, connectionConfig } = connection;
129+
* const shop = connectionConfig?.subdomain
130+
* ? `https://${connectionConfig.subdomain}.myshopify.com`
131+
* : null;
126132
*
127-
* const response = await fetch(
128-
* `https://${connectionConfig?.shop}/admin/api/2024-01/products.json`,
129-
* { headers: { 'X-Shopify-Access-Token': accessToken } }
130-
* );
133+
* if (shop) {
134+
* const response = await fetch(
135+
* `${shop}/admin/api/2024-01/products.json?limit=10`,
136+
* { headers: { 'X-Shopify-Access-Token': accessToken } }
137+
* );
138+
* const { products } = await response.json();
139+
* }
131140
* ```
132141
*/
133142
getConnection(integrationType: ConnectorIntegrationType): Promise<ConnectorConnectionResponse>;

0 commit comments

Comments
 (0)