@base44-preview/sdk 0.8.24-pr.134.4e99e37 → 0.8.24-pr.156.8ddb70c

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/index.d.ts CHANGED
@@ -5,7 +5,7 @@ export { createClient, createClientFromRequest, Base44Error, getAccessToken, sav
5
5
  export type { Base44Client, CreateClientConfig, CreateClientOptions, Base44ErrorJSON, };
6
6
  export * from "./types.js";
7
7
  export type { DeleteManyResult, DeleteResult, EntitiesModule, EntityHandler, EntityRecord, EntityTypeRegistry, ImportResult, RealtimeEventType, RealtimeEvent, RealtimeCallback, SortField, UpdateManyResult, } from "./modules/entities.types.js";
8
- export type { AuthModule, AuthEvent, AuthEventData, AuthStateChangeCallback, LoginResponse, RegisterParams, VerifyOtpParams, ChangePasswordParams, ResetPasswordParams, User, } from "./modules/auth.types.js";
8
+ export type { AuthModule, LoginResponse, RegisterParams, VerifyOtpParams, ChangePasswordParams, ResetPasswordParams, User, } from "./modules/auth.types.js";
9
9
  export type { IntegrationsModule, IntegrationEndpointFunction, CoreIntegrations, InvokeLLMParams, GenerateImageParams, GenerateImageResult, UploadFileParams, UploadFileResult, SendEmailParams, SendEmailResult, ExtractDataFromUploadedFileParams, ExtractDataFromUploadedFileResult, UploadPrivateFileParams, UploadPrivateFileResult, CreateFileSignedUrlParams, CreateFileSignedUrlResult, } from "./modules/integrations.types.js";
10
10
  export type { FunctionsModule, FunctionName, FunctionNameRegistry, } from "./modules/functions.types.js";
11
11
  export type { AgentsModule, AgentName, AgentNameRegistry, AgentConversation, AgentMessage, AgentMessageReasoning, AgentMessageToolCall, AgentMessageUsage, AgentMessageCustomContext, AgentMessageMetadata, CreateConversationParams, } from "./modules/agents.types.js";
@@ -1,50 +1,3 @@
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, calls onToken so the SDK can set the
9
- * token and fire auth state change events — no page redirect needed.
10
- *
11
- * @param url - The login URL to open in the popup (should include popup_origin).
12
- * @param expectedOrigin - The origin we expect the postMessage to come from.
13
- * @param onToken - Callback invoked with the access_token when auth completes.
14
- */
15
- function loginViaPopup(url, expectedOrigin, onToken) {
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 cleanup = () => {
25
- window.removeEventListener("message", onMessage);
26
- clearInterval(pollTimer);
27
- if (!popup.closed)
28
- popup.close();
29
- };
30
- const onMessage = (event) => {
31
- var _a;
32
- if (event.origin !== expectedOrigin)
33
- return;
34
- if (event.source !== popup)
35
- return;
36
- if (!((_a = event.data) === null || _a === void 0 ? void 0 : _a.access_token))
37
- return;
38
- cleanup();
39
- onToken(event.data.access_token);
40
- };
41
- // Only used to detect the user closing the popup before auth completes
42
- const pollTimer = setInterval(() => {
43
- if (popup.closed)
44
- cleanup();
45
- }, 500);
46
- window.addEventListener("message", onMessage);
47
- }
48
1
  /**
49
2
  * Creates the auth module for the Base44 SDK.
50
3
  *
@@ -56,11 +9,6 @@ function loginViaPopup(url, expectedOrigin, onToken) {
56
9
  * @internal
57
10
  */
58
11
  export function createAuthModule(axios, functionsAxiosClient, appId, options) {
59
- const listeners = new Set();
60
- let hasToken = false;
61
- function notify(event, data = {}) {
62
- listeners.forEach((cb) => cb(event, data));
63
- }
64
12
  return {
65
13
  // Get current user information
66
14
  async me() {
@@ -101,23 +49,13 @@ export function createAuthModule(axios, functionsAxiosClient, appId, options) {
101
49
  authPath = `/apps/auth${providerPath}/login`;
102
50
  }
103
51
  const loginUrl = `${options.appBaseUrl}/api${authPath}?${queryParams}`;
104
- // When running inside an iframe, use a popup to avoid OAuth providers
105
- // blocking iframe navigation.
106
- if (isInsideIframe()) {
107
- const popupLoginUrl = `${loginUrl}&popup_origin=${encodeURIComponent(window.location.origin)}`;
108
- return loginViaPopup(popupLoginUrl, window.location.origin, (token) => {
109
- this.setToken(token);
110
- });
111
- }
112
- // Default: full-page redirect
52
+ // Redirect to the provider login page
113
53
  window.location.href = loginUrl;
114
54
  },
115
55
  // Logout the current user
116
56
  logout(redirectUrl) {
117
57
  // Remove token from axios headers (always do this)
118
58
  delete axios.defaults.headers.common["Authorization"];
119
- hasToken = false;
120
- notify("SIGNED_OUT");
121
59
  // Only do the rest if in a browser environment
122
60
  if (typeof window !== "undefined") {
123
61
  // Remove token from localStorage
@@ -142,7 +80,6 @@ export function createAuthModule(axios, functionsAxiosClient, appId, options) {
142
80
  setToken(token, saveToStorage = true) {
143
81
  if (!token)
144
82
  return;
145
- const event = hasToken ? "TOKEN_REFRESHED" : "SIGNED_IN";
146
83
  // handle token change for axios clients
147
84
  axios.defaults.headers.common["Authorization"] = `Bearer ${token}`;
148
85
  functionsAxiosClient.defaults.headers.common["Authorization"] = `Bearer ${token}`;
@@ -159,8 +96,6 @@ export function createAuthModule(axios, functionsAxiosClient, appId, options) {
159
96
  console.error("Failed to save token to localStorage:", e);
160
97
  }
161
98
  }
162
- hasToken = true;
163
- notify(event, { access_token: token });
164
99
  },
165
100
  // Login using username and password
166
101
  async loginViaEmailPassword(email, password, turnstileToken) {
@@ -241,12 +176,5 @@ export function createAuthModule(axios, functionsAxiosClient, appId, options) {
241
176
  new_password: newPassword,
242
177
  });
243
178
  },
244
- // Subscribe to auth state changes
245
- onAuthStateChange(callback) {
246
- listeners.add(callback);
247
- return () => {
248
- listeners.delete(callback);
249
- };
250
- },
251
179
  };
252
180
  }
@@ -93,21 +93,6 @@ export interface AuthModuleOptions {
93
93
  /** Base URL for the app (used for login redirects). */
94
94
  appBaseUrl: string;
95
95
  }
96
- /**
97
- * Auth state change event types.
98
- */
99
- export type AuthEvent = "SIGNED_IN" | "SIGNED_OUT" | "TOKEN_REFRESHED";
100
- /**
101
- * Data passed to auth state change callbacks.
102
- */
103
- export interface AuthEventData {
104
- /** JWT access token, present on SIGNED_IN and TOKEN_REFRESHED events. */
105
- access_token?: string;
106
- }
107
- /**
108
- * Callback for auth state changes.
109
- */
110
- export type AuthStateChangeCallback = (event: AuthEvent, data: AuthEventData) => void;
111
96
  /**
112
97
  * Authentication module for managing user authentication and authorization. The module automatically stores tokens in local storage when available and manages authorization headers for API requests.
113
98
  *
@@ -493,34 +478,4 @@ export interface AuthModule {
493
478
  * ```
494
479
  */
495
480
  changePassword(params: ChangePasswordParams): Promise<any>;
496
- /**
497
- * Registers a callback that fires whenever the authentication state changes.
498
- *
499
- * Events:
500
- * - `SIGNED_IN` — fired after a successful login (email/password, OAuth, or popup).
501
- * - `SIGNED_OUT` — fired after logout.
502
- * - `TOKEN_REFRESHED` — fired when `setToken` is called while already authenticated.
503
- *
504
- * Returns an unsubscribe function. Call it to stop receiving events.
505
- *
506
- * @param callback - Function called with the event type and associated data.
507
- * @returns Unsubscribe function.
508
- *
509
- * @example
510
- * ```typescript
511
- * // In a React AuthContext provider
512
- * useEffect(() => {
513
- * const unsubscribe = base44.auth.onAuthStateChange(async (event, data) => {
514
- * if (event === 'SIGNED_IN') {
515
- * const user = await base44.auth.me();
516
- * setUser(user);
517
- * } else if (event === 'SIGNED_OUT') {
518
- * setUser(null);
519
- * }
520
- * });
521
- * return unsubscribe;
522
- * }, []);
523
- * ```
524
- */
525
- onAuthStateChange(callback: AuthStateChangeCallback): () => void;
526
481
  }
@@ -33,6 +33,9 @@ export function createConnectorsModule(axios, appId) {
33
33
  connectionConfig: (_a = data.connection_config) !== null && _a !== void 0 ? _a : null,
34
34
  };
35
35
  },
36
+ /**
37
+ * @deprecated Use getCurrentAppUserConnection(connectorId) and use the returned accessToken (and connectionConfig when needed) instead.
38
+ */
36
39
  async getCurrentAppUserAccessToken(connectorId) {
37
40
  if (!connectorId || typeof connectorId !== "string") {
38
41
  throw new Error("Connector ID is required and must be a string");
@@ -41,6 +44,18 @@ export function createConnectorsModule(axios, appId) {
41
44
  const data = response;
42
45
  return data.access_token;
43
46
  },
47
+ async getCurrentAppUserConnection(connectorId) {
48
+ var _a;
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 {
55
+ accessToken: data.access_token,
56
+ connectionConfig: (_a = data.connection_config) !== null && _a !== void 0 ? _a : null,
57
+ };
58
+ },
44
59
  };
45
60
  }
46
61
  /**
@@ -226,6 +226,8 @@ export interface ConnectorsModule {
226
226
  /**
227
227
  * Retrieves an OAuth access token for an end user's connection to a specific connector.
228
228
  *
229
+ * @deprecated Use {@link getCurrentAppUserConnection} instead.
230
+ *
229
231
  * Returns the OAuth token string that belongs to the currently authenticated end user
230
232
  * for the specified connector.
231
233
  *
@@ -243,6 +245,27 @@ export interface ConnectorsModule {
243
245
  * ```
244
246
  */
245
247
  getCurrentAppUserAccessToken(connectorId: string): Promise<string>;
248
+ /**
249
+ * Retrieves the OAuth access token and connection configuration for an end user's
250
+ * connection to a specific connector.
251
+ *
252
+ * Returns both the OAuth token and any connection-specific configuration that
253
+ * belongs to the currently authenticated end user for the specified connector.
254
+ *
255
+ * @param connectorId - The connector ID (OrgConnector database ID).
256
+ * @returns Promise resolving to a {@link ConnectorConnectionResponse} with `accessToken` and `connectionConfig`.
257
+ *
258
+ * @example
259
+ * ```typescript
260
+ * // Get the end user's connection details for a connector
261
+ * const { accessToken, connectionConfig } = await base44.asServiceRole.connectors.getCurrentAppUserConnection('abc123def');
262
+ *
263
+ * const response = await fetch('https://www.googleapis.com/calendar/v3/calendars/primary/events', {
264
+ * headers: { 'Authorization': `Bearer ${accessToken}` }
265
+ * });
266
+ * ```
267
+ */
268
+ getCurrentAppUserConnection(connectorId: string): Promise<ConnectorConnectionResponse>;
246
269
  }
247
270
  /**
248
271
  * User-scoped connectors module for managing app-user OAuth connections.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@base44-preview/sdk",
3
- "version": "0.8.24-pr.134.4e99e37",
3
+ "version": "0.8.24-pr.156.8ddb70c",
4
4
  "description": "JavaScript SDK for Base44 API",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",