@base44-preview/sdk 0.8.22-pr.150.8a73523 → 0.8.23-pr.134.41d3771

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.
package/dist/client.js CHANGED
@@ -71,6 +71,7 @@ export function createClient(config) {
71
71
  };
72
72
  const headers = {
73
73
  ...optionalHeaders,
74
+ "X-App-Id": String(appId),
74
75
  };
75
76
  const functionHeaders = functionsVersion
76
77
  ? {
@@ -91,9 +92,13 @@ export function createClient(config) {
91
92
  interceptResponses: false,
92
93
  onError: options === null || options === void 0 ? void 0 : options.onError,
93
94
  });
95
+ const serviceRoleHeaders = {
96
+ ...headers,
97
+ ...(token ? { "on-behalf-of": `Bearer ${token}` } : {}),
98
+ };
94
99
  const serviceRoleAxiosClient = createAxiosClient({
95
100
  baseURL: `${serverUrl}/api`,
96
- headers,
101
+ headers: serviceRoleHeaders,
97
102
  token: serviceToken,
98
103
  onError: options === null || options === void 0 ? void 0 : options.onError,
99
104
  });
@@ -157,7 +162,7 @@ export function createClient(config) {
157
162
  getSocket,
158
163
  }),
159
164
  integrations: createIntegrationsModule(serviceRoleAxiosClient, appId),
160
- sso: createSsoModule(serviceRoleAxiosClient, appId, token),
165
+ sso: createSsoModule(serviceRoleAxiosClient, appId),
161
166
  connectors: createConnectorsModule(serviceRoleAxiosClient, appId),
162
167
  functions: createFunctionsModule(serviceRoleFunctionsAxiosClient, appId, {
163
168
  getAuthHeaders: () => {
@@ -1,3 +1,59 @@
1
+ function isInsideIframe() {
2
+ if (typeof window === "undefined")
3
+ return false;
4
+ return window !== window.parent;
5
+ }
6
+ /**
7
+ * Opens a URL in a centered popup and waits for the backend to postMessage
8
+ * the auth result back. On success, redirects the current window to
9
+ * redirectUrl with the token params appended, preserving the same behaviour
10
+ * as a normal full-page redirect flow.
11
+ *
12
+ * @param url - The login URL to open in the popup (should include popup_origin).
13
+ * @param redirectUrl - Where to redirect after auth (the original fromUrl).
14
+ * @param expectedOrigin - The origin we expect the postMessage to come from.
15
+ */
16
+ function loginViaPopup(url, redirectUrl, expectedOrigin) {
17
+ const width = 500;
18
+ const height = 600;
19
+ const left = Math.round(window.screenX + (window.outerWidth - width) / 2);
20
+ const top = Math.round(window.screenY + (window.outerHeight - height) / 2);
21
+ const popup = window.open(url, "base44_auth", `width=${width},height=${height},left=${left},top=${top},resizable=yes,scrollbars=yes`);
22
+ if (!popup) {
23
+ return;
24
+ }
25
+ const cleanup = () => {
26
+ window.removeEventListener("message", onMessage);
27
+ clearInterval(pollTimer);
28
+ if (!popup.closed)
29
+ popup.close();
30
+ };
31
+ const onMessage = (event) => {
32
+ var _a;
33
+ if (event.origin !== expectedOrigin)
34
+ return;
35
+ if (event.source !== popup)
36
+ return;
37
+ if (!((_a = event.data) === null || _a === void 0 ? void 0 : _a.access_token))
38
+ return;
39
+ cleanup();
40
+ // Append the token params to redirectUrl so the app processes them
41
+ // exactly as it would from a normal OAuth callback redirect.
42
+ const callbackUrl = new URL(redirectUrl);
43
+ const { access_token, is_new_user } = event.data;
44
+ callbackUrl.searchParams.set("access_token", access_token);
45
+ if (is_new_user != null) {
46
+ callbackUrl.searchParams.set("is_new_user", String(is_new_user));
47
+ }
48
+ window.location.href = callbackUrl.toString();
49
+ };
50
+ // Only used to detect the user closing the popup before auth completes
51
+ const pollTimer = setInterval(() => {
52
+ if (popup.closed)
53
+ cleanup();
54
+ }, 500);
55
+ window.addEventListener("message", onMessage);
56
+ }
1
57
  /**
2
58
  * Creates the auth module for the Base44 SDK.
3
59
  *
@@ -49,7 +105,13 @@ export function createAuthModule(axios, functionsAxiosClient, appId, options) {
49
105
  authPath = `/apps/auth${providerPath}/login`;
50
106
  }
51
107
  const loginUrl = `${options.appBaseUrl}/api${authPath}?${queryParams}`;
52
- // Redirect to the provider login page
108
+ // When running inside an iframe, use a popup to avoid OAuth providers
109
+ // blocking iframe navigation.
110
+ if (isInsideIframe()) {
111
+ const popupLoginUrl = `${loginUrl}&popup_origin=${encodeURIComponent(window.location.origin)}`;
112
+ return loginViaPopup(popupLoginUrl, redirectUrl, window.location.origin);
113
+ }
114
+ // Default: full-page redirect
53
115
  window.location.href = loginUrl;
54
116
  },
55
117
  // Logout the current user
@@ -33,6 +33,14 @@ export function createConnectorsModule(axios, appId) {
33
33
  connectionConfig: (_a = data.connection_config) !== null && _a !== void 0 ? _a : null,
34
34
  };
35
35
  },
36
+ async getCurrentAppUserAccessToken(connectorId) {
37
+ if (!connectorId || typeof connectorId !== "string") {
38
+ throw new Error("Connector ID is required and must be a string");
39
+ }
40
+ const response = await axios.get(`/apps/${appId}/app-user-auth/connectors/${connectorId}/token`);
41
+ const data = response;
42
+ return data.access_token;
43
+ },
36
44
  };
37
45
  }
38
46
  /**
@@ -45,14 +53,6 @@ export function createConnectorsModule(axios, appId) {
45
53
  */
46
54
  export function createUserConnectorsModule(axios, appId) {
47
55
  return {
48
- async getCurrentAppUserAccessToken(connectorId) {
49
- if (!connectorId || typeof connectorId !== "string") {
50
- throw new Error("Connector ID is required and must be a string");
51
- }
52
- const response = await axios.get(`/apps/${appId}/app-user-auth/connectors/${connectorId}/token`);
53
- const data = response;
54
- return data.access_token;
55
- },
56
56
  async connectAppUser(connectorId) {
57
57
  if (!connectorId || typeof connectorId !== "string") {
58
58
  throw new Error("Connector ID is required and must be a string");
@@ -223,20 +223,6 @@ export interface ConnectorsModule {
223
223
  * ```
224
224
  */
225
225
  getConnection(integrationType: ConnectorIntegrationType): Promise<ConnectorConnectionResponse>;
226
- }
227
- /**
228
- * User-scoped connectors module for managing app-user OAuth connections.
229
- *
230
- * This module provides methods for app-user OAuth flows: initiating an OAuth connection,
231
- * retrieving the end user's access token, and disconnecting the end user's connection.
232
- *
233
- * Unlike {@link ConnectorsModule | ConnectorsModule} which manages app-scoped tokens,
234
- * this module manages tokens scoped to individual end users. Methods are keyed on
235
- * the connector ID (the OrgConnector's database ID) rather than the integration type.
236
- *
237
- * Available via `base44.connectors`.
238
- */
239
- export interface UserConnectorsModule {
240
226
  /**
241
227
  * Retrieves an OAuth access token for an end user's connection to a specific connector.
242
228
  *
@@ -249,7 +235,7 @@ export interface UserConnectorsModule {
249
235
  * @example
250
236
  * ```typescript
251
237
  * // Get the end user's access token for a connector
252
- * const token = await base44.connectors.getCurrentAppUserAccessToken('abc123def');
238
+ * const token = await base44.asServiceRole.connectors.getCurrentAppUserAccessToken('abc123def');
253
239
  *
254
240
  * const response = await fetch('https://www.googleapis.com/calendar/v3/calendars/primary/events', {
255
241
  * headers: { 'Authorization': `Bearer ${token}` }
@@ -257,6 +243,20 @@ export interface UserConnectorsModule {
257
243
  * ```
258
244
  */
259
245
  getCurrentAppUserAccessToken(connectorId: string): Promise<string>;
246
+ }
247
+ /**
248
+ * User-scoped connectors module for managing app-user OAuth connections.
249
+ *
250
+ * This module provides methods for app-user OAuth flows: initiating an OAuth connection,
251
+ * retrieving the end user's access token, and disconnecting the end user's connection.
252
+ *
253
+ * Unlike {@link ConnectorsModule | ConnectorsModule} which manages app-scoped tokens,
254
+ * this module manages tokens scoped to individual end users. Methods are keyed on
255
+ * the connector ID (the OrgConnector's database ID) rather than the integration type.
256
+ *
257
+ * Available via `base44.connectors`.
258
+ */
259
+ export interface UserConnectorsModule {
260
260
  /**
261
261
  * Initiates the app-user OAuth flow for a specific connector.
262
262
  *
@@ -9,4 +9,4 @@ import { SsoModule } from "./sso.types";
9
9
  * @returns SSO module with authentication methods
10
10
  * @internal
11
11
  */
12
- export declare function createSsoModule(axios: AxiosInstance, appId: string, userToken?: string): SsoModule;
12
+ export declare function createSsoModule(axios: AxiosInstance, appId: string): SsoModule;
@@ -7,17 +7,12 @@
7
7
  * @returns SSO module with authentication methods
8
8
  * @internal
9
9
  */
10
- export function createSsoModule(axios, appId, userToken) {
10
+ export function createSsoModule(axios, appId) {
11
11
  return {
12
12
  // Get SSO access token for a specific user
13
13
  async getAccessToken(userid) {
14
14
  const url = `/apps/${appId}/auth/sso/accesstoken/${userid}`;
15
- // Prepare headers with both tokens if available
16
- const headers = {};
17
- if (userToken) {
18
- headers["on-behalf-of"] = `Bearer ${userToken}`;
19
- }
20
- return axios.get(url, { headers });
15
+ return axios.get(url);
21
16
  },
22
17
  };
23
18
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@base44-preview/sdk",
3
- "version": "0.8.22-pr.150.8a73523",
3
+ "version": "0.8.23-pr.134.41d3771",
4
4
  "description": "JavaScript SDK for Base44 API",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",