@base44-preview/sdk 0.8.22-pr.150.8a73523 → 0.8.23-pr.134.95f58f7
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 +7 -2
- package/dist/modules/auth.js +64 -1
- package/dist/modules/connectors.js +8 -8
- package/dist/modules/connectors.types.d.ts +15 -15
- package/dist/modules/sso.d.ts +1 -1
- package/dist/modules/sso.js +2 -7
- package/package.json +1 -1
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
|
|
165
|
+
sso: createSsoModule(serviceRoleAxiosClient, appId),
|
|
161
166
|
connectors: createConnectorsModule(serviceRoleAxiosClient, appId),
|
|
162
167
|
functions: createFunctionsModule(serviceRoleFunctionsAxiosClient, appId, {
|
|
163
168
|
getAuthHeaders: () => {
|
package/dist/modules/auth.js
CHANGED
|
@@ -1,3 +1,60 @@
|
|
|
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 waits for the backend to postMessage
|
|
9
|
+
* the auth result back. On success, redirects the current window to
|
|
10
|
+
* redirectUrl with the token params appended, preserving the same behaviour
|
|
11
|
+
* as a normal full-page redirect flow.
|
|
12
|
+
*
|
|
13
|
+
* @param url - The login URL to open in the popup (should include popup_origin).
|
|
14
|
+
* @param redirectUrl - Where to redirect after auth (the original fromUrl).
|
|
15
|
+
* @param expectedOrigin - The origin we expect the postMessage to come from.
|
|
16
|
+
*/
|
|
17
|
+
function loginViaPopup(url, redirectUrl, expectedOrigin) {
|
|
18
|
+
const width = 500;
|
|
19
|
+
const height = 600;
|
|
20
|
+
const left = Math.round(window.screenX + (window.outerWidth - width) / 2);
|
|
21
|
+
const top = Math.round(window.screenY + (window.outerHeight - height) / 2);
|
|
22
|
+
const popup = window.open(url, "base44_auth", `width=${width},height=${height},left=${left},top=${top},resizable=yes,scrollbars=yes`);
|
|
23
|
+
if (!popup) {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
const cleanup = () => {
|
|
27
|
+
window.removeEventListener("message", onMessage);
|
|
28
|
+
clearInterval(pollTimer);
|
|
29
|
+
if (!popup.closed)
|
|
30
|
+
popup.close();
|
|
31
|
+
};
|
|
32
|
+
const onMessage = (event) => {
|
|
33
|
+
var _a;
|
|
34
|
+
if (event.origin !== expectedOrigin)
|
|
35
|
+
return;
|
|
36
|
+
if (event.source !== popup)
|
|
37
|
+
return;
|
|
38
|
+
if (!((_a = event.data) === null || _a === void 0 ? void 0 : _a.access_token))
|
|
39
|
+
return;
|
|
40
|
+
cleanup();
|
|
41
|
+
// Append the token params to redirectUrl so the app processes them
|
|
42
|
+
// exactly as it would from a normal OAuth callback redirect.
|
|
43
|
+
const callbackUrl = new URL(redirectUrl);
|
|
44
|
+
const { access_token, is_new_user } = event.data;
|
|
45
|
+
callbackUrl.searchParams.set("access_token", access_token);
|
|
46
|
+
if (is_new_user != null) {
|
|
47
|
+
callbackUrl.searchParams.set("is_new_user", String(is_new_user));
|
|
48
|
+
}
|
|
49
|
+
window.location.href = callbackUrl.toString();
|
|
50
|
+
};
|
|
51
|
+
// Only used to detect the user closing the popup before auth completes
|
|
52
|
+
const pollTimer = setInterval(() => {
|
|
53
|
+
if (popup.closed)
|
|
54
|
+
cleanup();
|
|
55
|
+
}, 500);
|
|
56
|
+
window.addEventListener("message", onMessage);
|
|
57
|
+
}
|
|
1
58
|
/**
|
|
2
59
|
* Creates the auth module for the Base44 SDK.
|
|
3
60
|
*
|
|
@@ -49,7 +106,13 @@ export function createAuthModule(axios, functionsAxiosClient, appId, options) {
|
|
|
49
106
|
authPath = `/apps/auth${providerPath}/login`;
|
|
50
107
|
}
|
|
51
108
|
const loginUrl = `${options.appBaseUrl}/api${authPath}?${queryParams}`;
|
|
52
|
-
//
|
|
109
|
+
// On preview/sandbox/checkpoint domains the app runs inside an iframe —
|
|
110
|
+
// use a popup to avoid OAuth providers blocking iframe navigation.
|
|
111
|
+
if (isPopupAuthDomain()) {
|
|
112
|
+
const popupLoginUrl = `${loginUrl}&popup_origin=${encodeURIComponent(window.location.origin)}`;
|
|
113
|
+
return loginViaPopup(popupLoginUrl, redirectUrl, window.location.origin);
|
|
114
|
+
}
|
|
115
|
+
// Default: full-page redirect
|
|
53
116
|
window.location.href = loginUrl;
|
|
54
117
|
},
|
|
55
118
|
// 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
|
*
|
package/dist/modules/sso.d.ts
CHANGED
|
@@ -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
|
|
12
|
+
export declare function createSsoModule(axios: AxiosInstance, appId: string): SsoModule;
|
package/dist/modules/sso.js
CHANGED
|
@@ -7,17 +7,12 @@
|
|
|
7
7
|
* @returns SSO module with authentication methods
|
|
8
8
|
* @internal
|
|
9
9
|
*/
|
|
10
|
-
export function createSsoModule(axios, appId
|
|
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
|
-
|
|
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
|
}
|