@base44-preview/sdk 0.8.24-pr.134.9c14bd3 → 0.8.24-pr.156.b7d6285
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,
|
|
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";
|
package/dist/modules/auth.js
CHANGED
|
@@ -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
|
-
//
|
|
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,23 +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
|
-
/** User data, present on SIGNED_IN when available. */
|
|
107
|
-
user?: User;
|
|
108
|
-
}
|
|
109
|
-
/**
|
|
110
|
-
* Callback for auth state changes.
|
|
111
|
-
*/
|
|
112
|
-
export type AuthStateChangeCallback = (event: AuthEvent, data: AuthEventData) => void;
|
|
113
96
|
/**
|
|
114
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.
|
|
115
98
|
*
|
|
@@ -495,33 +478,4 @@ export interface AuthModule {
|
|
|
495
478
|
* ```
|
|
496
479
|
*/
|
|
497
480
|
changePassword(params: ChangePasswordParams): Promise<any>;
|
|
498
|
-
/**
|
|
499
|
-
* Registers a callback that fires whenever the authentication state changes.
|
|
500
|
-
*
|
|
501
|
-
* Events:
|
|
502
|
-
* - `SIGNED_IN` — fired after a successful login (email/password, OAuth, or popup).
|
|
503
|
-
* - `SIGNED_OUT` — fired after logout.
|
|
504
|
-
* - `TOKEN_REFRESHED` — fired when `setToken` is called while already authenticated.
|
|
505
|
-
*
|
|
506
|
-
* Returns an unsubscribe function. Call it to stop receiving events.
|
|
507
|
-
*
|
|
508
|
-
* @param callback - Function called with the event type and associated data.
|
|
509
|
-
* @returns Unsubscribe function.
|
|
510
|
-
*
|
|
511
|
-
* @example
|
|
512
|
-
* ```typescript
|
|
513
|
-
* // In a React AuthContext provider
|
|
514
|
-
* useEffect(() => {
|
|
515
|
-
* const unsubscribe = base44.auth.onAuthStateChange((event, data) => {
|
|
516
|
-
* if (event === 'SIGNED_IN') {
|
|
517
|
-
* setUser(data.user);
|
|
518
|
-
* } else if (event === 'SIGNED_OUT') {
|
|
519
|
-
* setUser(null);
|
|
520
|
-
* }
|
|
521
|
-
* });
|
|
522
|
-
* return unsubscribe;
|
|
523
|
-
* }, []);
|
|
524
|
-
* ```
|
|
525
|
-
*/
|
|
526
|
-
onAuthStateChange(callback: AuthStateChangeCallback): () => void;
|
|
527
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
|
/**
|
|
@@ -32,6 +32,15 @@ export interface ConnectorConnectionResponse {
|
|
|
32
32
|
/** Key-value configuration for the connection, or `null` if the connector does not provide one. */
|
|
33
33
|
connectionConfig: Record<string, string> | null;
|
|
34
34
|
}
|
|
35
|
+
/**
|
|
36
|
+
* Connection details for an app-user connector.
|
|
37
|
+
*/
|
|
38
|
+
export interface AppUserConnectorConnectionResponse {
|
|
39
|
+
/** The OAuth access token for the end user's connection. */
|
|
40
|
+
accessToken: string;
|
|
41
|
+
/** Key-value configuration for the connection, or `null` if the connector does not provide one. */
|
|
42
|
+
connectionConfig: Record<string, string> | null;
|
|
43
|
+
}
|
|
35
44
|
/**
|
|
36
45
|
* Connectors module for managing app-scoped OAuth tokens for external services.
|
|
37
46
|
*
|
|
@@ -226,6 +235,8 @@ export interface ConnectorsModule {
|
|
|
226
235
|
/**
|
|
227
236
|
* Retrieves an OAuth access token for an end user's connection to a specific connector.
|
|
228
237
|
*
|
|
238
|
+
* @deprecated Use {@link getCurrentAppUserConnection} instead.
|
|
239
|
+
*
|
|
229
240
|
* Returns the OAuth token string that belongs to the currently authenticated end user
|
|
230
241
|
* for the specified connector.
|
|
231
242
|
*
|
|
@@ -243,6 +254,27 @@ export interface ConnectorsModule {
|
|
|
243
254
|
* ```
|
|
244
255
|
*/
|
|
245
256
|
getCurrentAppUserAccessToken(connectorId: string): Promise<string>;
|
|
257
|
+
/**
|
|
258
|
+
* Retrieves the OAuth access token and connection configuration for an end user's
|
|
259
|
+
* connection to a specific connector.
|
|
260
|
+
*
|
|
261
|
+
* Returns both the OAuth token and any connection-specific configuration that
|
|
262
|
+
* belongs to the currently authenticated end user for the specified connector.
|
|
263
|
+
*
|
|
264
|
+
* @param connectorId - The connector ID (OrgConnector database ID).
|
|
265
|
+
* @returns Promise resolving to an {@link AppUserConnectorConnectionResponse} with `accessToken` and `connectionConfig`.
|
|
266
|
+
*
|
|
267
|
+
* @example
|
|
268
|
+
* ```typescript
|
|
269
|
+
* // Get the end user's connection details for a connector
|
|
270
|
+
* const { accessToken, connectionConfig } = await base44.asServiceRole.connectors.getCurrentAppUserConnection('abc123def');
|
|
271
|
+
*
|
|
272
|
+
* const response = await fetch('https://www.googleapis.com/calendar/v3/calendars/primary/events', {
|
|
273
|
+
* headers: { 'Authorization': `Bearer ${accessToken}` }
|
|
274
|
+
* });
|
|
275
|
+
* ```
|
|
276
|
+
*/
|
|
277
|
+
getCurrentAppUserConnection(connectorId: string): Promise<AppUserConnectorConnectionResponse>;
|
|
246
278
|
}
|
|
247
279
|
/**
|
|
248
280
|
* User-scoped connectors module for managing app-user OAuth connections.
|