@base44-preview/sdk 0.8.23-pr.154.5b2229d → 0.8.24-pr.134.4e99e37

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, LoginResponse, RegisterParams, VerifyOtpParams, ChangePasswordParams, ResetPasswordParams, User, } from "./modules/auth.types.js";
8
+ export type { AuthModule, AuthEvent, AuthEventData, AuthStateChangeCallback, 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";
@@ -72,6 +72,7 @@ export function createAgentsModule({ axios, getSocket, appId, serverUrl, token,
72
72
  return `${baseUrl}?token=${accessToken}`;
73
73
  }
74
74
  else {
75
+ // No token - URL will redirect to login automatically
75
76
  return baseUrl;
76
77
  }
77
78
  };
@@ -1,3 +1,50 @@
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
+ }
1
48
  /**
2
49
  * Creates the auth module for the Base44 SDK.
3
50
  *
@@ -9,6 +56,11 @@
9
56
  * @internal
10
57
  */
11
58
  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
+ }
12
64
  return {
13
65
  // Get current user information
14
66
  async me() {
@@ -49,13 +101,23 @@ export function createAuthModule(axios, functionsAxiosClient, appId, options) {
49
101
  authPath = `/apps/auth${providerPath}/login`;
50
102
  }
51
103
  const loginUrl = `${options.appBaseUrl}/api${authPath}?${queryParams}`;
52
- // Redirect to the provider login page
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
53
113
  window.location.href = loginUrl;
54
114
  },
55
115
  // Logout the current user
56
116
  logout(redirectUrl) {
57
117
  // Remove token from axios headers (always do this)
58
118
  delete axios.defaults.headers.common["Authorization"];
119
+ hasToken = false;
120
+ notify("SIGNED_OUT");
59
121
  // Only do the rest if in a browser environment
60
122
  if (typeof window !== "undefined") {
61
123
  // Remove token from localStorage
@@ -80,6 +142,7 @@ export function createAuthModule(axios, functionsAxiosClient, appId, options) {
80
142
  setToken(token, saveToStorage = true) {
81
143
  if (!token)
82
144
  return;
145
+ const event = hasToken ? "TOKEN_REFRESHED" : "SIGNED_IN";
83
146
  // handle token change for axios clients
84
147
  axios.defaults.headers.common["Authorization"] = `Bearer ${token}`;
85
148
  functionsAxiosClient.defaults.headers.common["Authorization"] = `Bearer ${token}`;
@@ -96,6 +159,8 @@ export function createAuthModule(axios, functionsAxiosClient, appId, options) {
96
159
  console.error("Failed to save token to localStorage:", e);
97
160
  }
98
161
  }
162
+ hasToken = true;
163
+ notify(event, { access_token: token });
99
164
  },
100
165
  // Login using username and password
101
166
  async loginViaEmailPassword(email, password, turnstileToken) {
@@ -176,5 +241,12 @@ export function createAuthModule(axios, functionsAxiosClient, appId, options) {
176
241
  new_password: newPassword,
177
242
  });
178
243
  },
244
+ // Subscribe to auth state changes
245
+ onAuthStateChange(callback) {
246
+ listeners.add(callback);
247
+ return () => {
248
+ listeners.delete(callback);
249
+ };
250
+ },
179
251
  };
180
252
  }
@@ -93,6 +93,21 @@ 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;
96
111
  /**
97
112
  * 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.
98
113
  *
@@ -478,4 +493,34 @@ export interface AuthModule {
478
493
  * ```
479
494
  */
480
495
  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;
481
526
  }
@@ -175,8 +175,13 @@ export interface CoreIntegrations {
175
175
  /**
176
176
  * Create AI-generated images from text prompts.
177
177
  *
178
+ * Images are generated as PNG files at approximately 1024px on the shorter side. The
179
+ * exact dimensions vary by aspect ratio.
180
+ *
181
+ * Prompts that violate the AI provider's content policy will be refused.
182
+ *
178
183
  * @param params - Parameters for image generation
179
- * @returns Promise resolving to the generated image URL.
184
+ * @returns Promise resolving to an object containing the URL of the generated PNG image.
180
185
  *
181
186
  * @example
182
187
  * ```typescript
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@base44-preview/sdk",
3
- "version": "0.8.23-pr.154.5b2229d",
3
+ "version": "0.8.24-pr.134.4e99e37",
4
4
  "description": "JavaScript SDK for Base44 API",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",