@base44-preview/sdk 0.8.19-pr.134.bf04bef → 0.8.19-pr.135.d9d067f

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,50 +1,3 @@
1
- const POPUP_AUTH_DOMAIN_REGEX = /^(preview-sandbox--|preview--|checkpoint--)[^.]+\./;
2
- function isPopupAuthDomain() {
3
- if (typeof window === "undefined")
4
- return false;
5
- return POPUP_AUTH_DOMAIN_REGEX.test(window.location.hostname);
6
- }
7
- /**
8
- * Opens a URL in a centered popup and, once the OAuth provider redirects
9
- * back to our origin, mirrors that callback URL in the current window so the
10
- * iframe processes the access_token query param exactly as a normal redirect
11
- * would.
12
- *
13
- * @param url - The URL to open in the popup.
14
- */
15
- function loginViaPopup(url) {
16
- const width = 500;
17
- const height = 600;
18
- const left = Math.round(window.screenX + (window.outerWidth - width) / 2);
19
- const top = Math.round(window.screenY + (window.outerHeight - height) / 2);
20
- const popup = window.open(url, "base44_auth", `width=${width},height=${height},left=${left},top=${top},resizable=yes,scrollbars=yes`);
21
- if (!popup) {
22
- return;
23
- }
24
- const pollTimer = setInterval(() => {
25
- if (popup.closed) {
26
- clearInterval(pollTimer);
27
- return;
28
- }
29
- try {
30
- // Accessing popup.location.href throws a cross-origin error while the
31
- // OAuth provider's pages are open — that's expected and means the flow
32
- // is still in progress. Once it stops throwing, the popup has landed
33
- // back on our origin with the callback URL (e.g. ?access_token=...).
34
- const callbackUrl = popup.location.href;
35
- if (new URL(callbackUrl).origin === window.location.origin) {
36
- clearInterval(pollTimer);
37
- popup.close();
38
- // Redirect the iframe to the same URL the popup landed on so it
39
- // processes the token from the query params as it normally would.
40
- window.location.href = callbackUrl;
41
- }
42
- }
43
- catch (_a) {
44
- // Still on the OAuth provider's domain — keep polling
45
- }
46
- }, 300);
47
- }
48
1
  /**
49
2
  * Creates the auth module for the Base44 SDK.
50
3
  *
@@ -96,12 +49,7 @@ export function createAuthModule(axios, functionsAxiosClient, appId, options) {
96
49
  authPath = `/apps/auth${providerPath}/login`;
97
50
  }
98
51
  const loginUrl = `${options.appBaseUrl}/api${authPath}?${queryParams}`;
99
- // On preview/sandbox/checkpoint domains the app runs inside an iframe —
100
- // use a popup to avoid OAuth providers blocking iframe navigation.
101
- if (isPopupAuthDomain()) {
102
- return loginViaPopup(loginUrl);
103
- }
104
- // Default: full-page redirect
52
+ // Redirect to the provider login page
105
53
  window.location.href = loginUrl;
106
54
  },
107
55
  // Logout the current user
@@ -8,9 +8,13 @@
8
8
  */
9
9
  export function createConnectorsModule(axios, appId) {
10
10
  return {
11
- // Retrieve an OAuth access token for a specific external integration type
12
- // @ts-expect-error Return type mismatch with interface - implementation returns object, interface expects string
11
+ /**
12
+ * Retrieve an OAuth access token for a specific external integration type.
13
+ * @deprecated Use getConnection(integrationType) and use the returned accessToken (and connectionConfig when needed) instead.
14
+ */
15
+ // @ts-expect-error Return type mismatch with interface - implementation returns string, interface expects string but implementation is typed as ConnectorAccessTokenResponse
13
16
  async getAccessToken(integrationType) {
17
+ console.warn("[Base44 SDK] connectors.getAccessToken() is deprecated. Use getConnection(integrationType) and use the returned accessToken instead.");
14
18
  if (!integrationType || typeof integrationType !== "string") {
15
19
  throw new Error("Integration type is required and must be a string");
16
20
  }
@@ -18,5 +22,17 @@ export function createConnectorsModule(axios, appId) {
18
22
  // @ts-expect-error
19
23
  return response.access_token;
20
24
  },
25
+ async getConnection(integrationType) {
26
+ var _a;
27
+ if (!integrationType || typeof integrationType !== "string") {
28
+ throw new Error("Integration type is required and must be a string");
29
+ }
30
+ const response = await axios.get(`/apps/${appId}/external-auth/tokens/${integrationType}`);
31
+ const data = response;
32
+ return {
33
+ accessToken: data.access_token,
34
+ connectionConfig: (_a = data.connection_config) !== null && _a !== void 0 ? _a : null,
35
+ };
36
+ },
21
37
  };
22
38
  }
@@ -10,7 +10,8 @@ export interface ConnectorIntegrationTypeRegistry {
10
10
  * ```typescript
11
11
  * // Using generated connector type names
12
12
  * // 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;
14
15
  * ```
15
16
  */
16
17
  export type ConnectorIntegrationType = keyof ConnectorIntegrationTypeRegistry extends never ? string : keyof ConnectorIntegrationTypeRegistry;
@@ -19,6 +20,17 @@ export type ConnectorIntegrationType = keyof ConnectorIntegrationTypeRegistry ex
19
20
  */
20
21
  export interface ConnectorAccessTokenResponse {
21
22
  access_token: string;
23
+ integration_type: string;
24
+ connection_config: Record<string, string> | null;
25
+ }
26
+ /**
27
+ * Camel-cased connection details returned by {@linkcode ConnectorsModule.getConnection | getConnection()}.
28
+ */
29
+ export interface ConnectorConnectionResponse {
30
+ /** The OAuth access token for the external service. */
31
+ accessToken: string;
32
+ /** Key-value configuration for the connection, or `null` if the connector does not provide one. */
33
+ connectionConfig: Record<string, string> | null;
22
34
  }
23
35
  /**
24
36
  * Connectors module for managing OAuth tokens for external services.
@@ -36,12 +48,14 @@ export interface ConnectorAccessTokenResponse {
36
48
  *
37
49
  * ## Dynamic Types
38
50
  *
39
- * 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.
51
+ * 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.
40
52
  */
41
53
  export interface ConnectorsModule {
42
54
  /**
43
55
  * Retrieves an OAuth access token for a specific external integration type.
44
56
  *
57
+ * @deprecated Use {@link getConnection} and use the returned `accessToken` (and `connectionConfig` when needed) instead.
58
+ *
45
59
  * Returns the OAuth token string for an external service that an app builder
46
60
  * has connected to. This token represents the connected app builder's account
47
61
  * and can be used to make authenticated API calls to that external service on behalf of the app.
@@ -83,4 +97,41 @@ export interface ConnectorsModule {
83
97
  * ```
84
98
  */
85
99
  getAccessToken(integrationType: ConnectorIntegrationType): Promise<string>;
100
+ /**
101
+ * Retrieves the OAuth access token and connection configuration for a specific external integration type.
102
+ *
103
+ * Returns both the OAuth token and any additional connection configuration
104
+ * that the connector provides. This is useful when the external service requires
105
+ * extra parameters beyond the access token (e.g., a shop domain, account ID, or API base URL).
106
+ *
107
+ * @param integrationType - The type of integration, such as `'googlecalendar'`, `'slack'`, or `'github'`.
108
+ * @returns Promise resolving to a {@link ConnectorConnectionResponse} with `accessToken` and `connectionConfig`.
109
+ *
110
+ * @example
111
+ * ```typescript
112
+ * // Basic usage
113
+ * const connection = await base44.asServiceRole.connectors.getConnection('googlecalendar');
114
+ * console.log(connection.accessToken);
115
+ * console.log(connection.connectionConfig);
116
+ * ```
117
+ *
118
+ * @example
119
+ * ```typescript
120
+ * // Shopify: connectionConfig has subdomain (e.g. "my-store" for my-store.myshopify.com)
121
+ * const connection = await base44.asServiceRole.connectors.getConnection('shopify');
122
+ * const { accessToken, connectionConfig } = connection;
123
+ * const shop = connectionConfig?.subdomain
124
+ * ? `https://${connectionConfig.subdomain}.myshopify.com`
125
+ * : null;
126
+ *
127
+ * if (shop) {
128
+ * const response = await fetch(
129
+ * `${shop}/admin/api/2024-01/products.json?limit=10`,
130
+ * { headers: { 'X-Shopify-Access-Token': accessToken } }
131
+ * );
132
+ * const { products } = await response.json();
133
+ * }
134
+ * ```
135
+ */
136
+ getConnection(integrationType: ConnectorIntegrationType): Promise<ConnectorConnectionResponse>;
86
137
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@base44-preview/sdk",
3
- "version": "0.8.19-pr.134.bf04bef",
3
+ "version": "0.8.19-pr.135.d9d067f",
4
4
  "description": "JavaScript SDK for Base44 API",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",