@base44-preview/sdk 0.8.48-pr.282.2b05017 → 0.8.48-pr.282.60e9a18
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
|
@@ -55,18 +55,22 @@ import { createActorsModule, resolveActorsHost, } from "./modules/actors.js";
|
|
|
55
55
|
*/
|
|
56
56
|
export function createClient(config) {
|
|
57
57
|
var _a, _b, _c, _d;
|
|
58
|
-
const { serverUrl = "https://base44.app", appId, analytics,
|
|
58
|
+
const { serverUrl = "https://base44.app", appId, analytics, serviceToken, requiresAuth = false, appBaseUrl, options, functionsVersion, headers: optionalHeaders, } = config;
|
|
59
59
|
// Normalize appBaseUrl to always be a string (empty if not provided or invalid)
|
|
60
60
|
const normalizedAppBaseUrl = typeof appBaseUrl === "string" ? appBaseUrl : "";
|
|
61
61
|
const inBrowser = typeof window !== "undefined";
|
|
62
62
|
// A host platform embeds the app with a one-time token on the iframe URL.
|
|
63
63
|
// It comes off the URL here, before any other code can read it; the
|
|
64
64
|
// exchange that turns it into a session runs once the modules exist.
|
|
65
|
-
const embedOtt =
|
|
66
|
-
const embedded = embedOtt !== null || (inBrowser && isEmbeddedTab());
|
|
65
|
+
const embedOtt = takeEmbedTokenFromUrl();
|
|
67
66
|
if (embedOtt) {
|
|
68
67
|
markEmbeddedTab();
|
|
69
68
|
}
|
|
69
|
+
const embedded = Boolean(embedOtt) || isEmbeddedTab();
|
|
70
|
+
// What an app passes as `token` is whatever getAccessToken() returned as the
|
|
71
|
+
// page loaded. In an embedded frame that is the one-time token itself, or a
|
|
72
|
+
// token an earlier visitor left in storage; neither is this session.
|
|
73
|
+
const token = embedded ? undefined : config.token;
|
|
70
74
|
let currentToken = token !== null && token !== void 0 ? token : null;
|
|
71
75
|
const socketConfig = {
|
|
72
76
|
serverUrl,
|
|
@@ -99,13 +103,13 @@ export function createClient(config) {
|
|
|
99
103
|
const axiosClient = createAxiosClient({
|
|
100
104
|
baseURL: `${serverUrl}/api`,
|
|
101
105
|
headers,
|
|
102
|
-
token,
|
|
106
|
+
token: token,
|
|
103
107
|
onError: options === null || options === void 0 ? void 0 : options.onError,
|
|
104
108
|
});
|
|
105
109
|
const functionsAxiosClient = createAxiosClient({
|
|
106
110
|
baseURL: `${serverUrl}/api`,
|
|
107
111
|
headers: functionHeaders,
|
|
108
|
-
token,
|
|
112
|
+
token: token,
|
|
109
113
|
interceptResponses: false,
|
|
110
114
|
onError: options === null || options === void 0 ? void 0 : options.onError,
|
|
111
115
|
});
|
|
@@ -137,7 +141,7 @@ export function createClient(config) {
|
|
|
137
141
|
const userAuthModule = createAuthModule(axiosClient, functionsAxiosClient, appId, {
|
|
138
142
|
appBaseUrl: normalizedAppBaseUrl,
|
|
139
143
|
serverUrl,
|
|
140
|
-
token,
|
|
144
|
+
token: token,
|
|
141
145
|
embedded,
|
|
142
146
|
});
|
|
143
147
|
// Apply the access token before any module that may issue authenticated
|
|
@@ -160,7 +164,7 @@ export function createClient(config) {
|
|
|
160
164
|
if (userAuthModule.hasToken()) {
|
|
161
165
|
return currentToken;
|
|
162
166
|
}
|
|
163
|
-
return embedded
|
|
167
|
+
return embedded ? null : getAccessToken();
|
|
164
168
|
};
|
|
165
169
|
const applyToken = (newToken, saveToStorage) => {
|
|
166
170
|
userAuthModule.setToken(newToken, saveToStorage);
|
|
@@ -5,6 +5,8 @@ import { GetAccessTokenOptions, SaveAccessTokenOptions, RemoveAccessTokenOptions
|
|
|
5
5
|
* Low-level utility for manually retrieving tokens. In most cases, the Base44 client handles
|
|
6
6
|
* token management automatically. This function is useful for custom authentication flows or when you need direct access to stored tokens. Requires a browser environment and can't be used in the backend.
|
|
7
7
|
*
|
|
8
|
+
* When a host platform has embedded the app with a one-time token (`?ott=`), that token is returned as it stands: it is what {@linkcode createClient} trades for the session, so a page that gates on "is there a token?" as it loads sees one. It is neither stored nor removed from the URL here.
|
|
9
|
+
*
|
|
8
10
|
* @internal
|
|
9
11
|
*
|
|
10
12
|
* @param options - Configuration options for token retrieval.
|
package/dist/utils/auth-utils.js
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
|
+
import { EMBED_TOKEN_PARAM } from "./embed-session.js";
|
|
1
2
|
/**
|
|
2
3
|
* Retrieves an access token from URL parameters or local storage.
|
|
3
4
|
*
|
|
4
5
|
* Low-level utility for manually retrieving tokens. In most cases, the Base44 client handles
|
|
5
6
|
* token management automatically. This function is useful for custom authentication flows or when you need direct access to stored tokens. Requires a browser environment and can't be used in the backend.
|
|
6
7
|
*
|
|
8
|
+
* When a host platform has embedded the app with a one-time token (`?ott=`), that token is returned as it stands: it is what {@linkcode createClient} trades for the session, so a page that gates on "is there a token?" as it loads sees one. It is neither stored nor removed from the URL here.
|
|
9
|
+
*
|
|
7
10
|
* @internal
|
|
8
11
|
*
|
|
9
12
|
* @param options - Configuration options for token retrieval.
|
|
@@ -56,6 +59,14 @@ export function getAccessToken(options = {}) {
|
|
|
56
59
|
}
|
|
57
60
|
return token;
|
|
58
61
|
}
|
|
62
|
+
// A platform-embedded load carries a one-time token instead. It is not a
|
|
63
|
+
// session yet — createClient takes it off the URL and exchanges it — but
|
|
64
|
+
// it is the identity this load arrives with, and callers that read this
|
|
65
|
+
// once as the page loads must not conclude there is none.
|
|
66
|
+
const embedToken = urlParams.get(EMBED_TOKEN_PARAM);
|
|
67
|
+
if (embedToken) {
|
|
68
|
+
return embedToken;
|
|
69
|
+
}
|
|
59
70
|
}
|
|
60
71
|
catch (e) {
|
|
61
72
|
console.error("Error retrieving token from URL:", e);
|
|
@@ -9,6 +9,8 @@
|
|
|
9
9
|
*
|
|
10
10
|
* @internal
|
|
11
11
|
*/
|
|
12
|
+
/** The query parameter a host platform puts the one-time token on. @internal */
|
|
13
|
+
export declare const EMBED_TOKEN_PARAM = "ott";
|
|
12
14
|
/**
|
|
13
15
|
* Reads the one-time token off the current URL and strips it, so it is never
|
|
14
16
|
* left in the address bar, in history, or in a shared link.
|
|
@@ -9,7 +9,8 @@
|
|
|
9
9
|
*
|
|
10
10
|
* @internal
|
|
11
11
|
*/
|
|
12
|
-
|
|
12
|
+
/** The query parameter a host platform puts the one-time token on. @internal */
|
|
13
|
+
export const EMBED_TOKEN_PARAM = "ott";
|
|
13
14
|
const EMBED_TAB_KEY = "base44_embed_session";
|
|
14
15
|
const GRANT_TYPE = "urn:ietf:params:oauth:grant-type:token-exchange";
|
|
15
16
|
const SUBJECT_TOKEN_TYPE = "urn:base44:params:oauth:token-type:embed-ott";
|
|
@@ -28,11 +29,11 @@ export function takeEmbedTokenFromUrl() {
|
|
|
28
29
|
}
|
|
29
30
|
try {
|
|
30
31
|
const url = new URL(window.location.href);
|
|
31
|
-
const ott = url.searchParams.get(
|
|
32
|
+
const ott = url.searchParams.get(EMBED_TOKEN_PARAM);
|
|
32
33
|
if (!ott) {
|
|
33
34
|
return null;
|
|
34
35
|
}
|
|
35
|
-
url.searchParams.delete(
|
|
36
|
+
url.searchParams.delete(EMBED_TOKEN_PARAM);
|
|
36
37
|
window.history.replaceState(window.history.state, "", url.toString());
|
|
37
38
|
return ott;
|
|
38
39
|
}
|