@base44-preview/sdk 0.8.48-pr.282.8affbe6 → 0.8.48-pr.282.d771123
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 +13 -14
- package/package.json +1 -1
package/dist/client.js
CHANGED
|
@@ -55,23 +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
|
-
const inBrowser = typeof window !== "undefined";
|
|
62
61
|
// A host platform embeds the app with a one-time token on the iframe URL.
|
|
63
62
|
// It comes off the URL here, before any other code can read it; the
|
|
64
63
|
// exchange that turns it into a session runs once the modules exist.
|
|
65
|
-
const embedOtt =
|
|
66
|
-
const embedded = embedOtt !== null || (inBrowser && isEmbeddedTab());
|
|
64
|
+
const embedOtt = takeEmbedTokenFromUrl();
|
|
67
65
|
if (embedOtt) {
|
|
68
66
|
markEmbeddedTab();
|
|
69
67
|
}
|
|
68
|
+
const embedded = Boolean(embedOtt) || isEmbeddedTab();
|
|
70
69
|
// What an app passes as `token` is whatever getAccessToken() returned as the
|
|
71
70
|
// page loaded. In an embedded frame that is the one-time token itself, or a
|
|
72
71
|
// token an earlier visitor left in storage; neither is this session.
|
|
73
|
-
const
|
|
74
|
-
let currentToken =
|
|
72
|
+
const token = embedded ? undefined : config.token;
|
|
73
|
+
let currentToken = token !== null && token !== void 0 ? token : null;
|
|
75
74
|
const socketConfig = {
|
|
76
75
|
serverUrl,
|
|
77
76
|
mountPath: "/ws-user-apps/socket.io/",
|
|
@@ -79,7 +78,7 @@ export function createClient(config) {
|
|
|
79
78
|
appId,
|
|
80
79
|
// null (not undefined): an embedded frame's only identity is the one the
|
|
81
80
|
// platform minted, so the socket must not fall back to a stored token.
|
|
82
|
-
token: embedded ? null :
|
|
81
|
+
token: embedded ? null : token,
|
|
83
82
|
};
|
|
84
83
|
let socket = null;
|
|
85
84
|
const getSocket = () => {
|
|
@@ -103,19 +102,19 @@ export function createClient(config) {
|
|
|
103
102
|
const axiosClient = createAxiosClient({
|
|
104
103
|
baseURL: `${serverUrl}/api`,
|
|
105
104
|
headers,
|
|
106
|
-
token
|
|
105
|
+
token,
|
|
107
106
|
onError: options === null || options === void 0 ? void 0 : options.onError,
|
|
108
107
|
});
|
|
109
108
|
const functionsAxiosClient = createAxiosClient({
|
|
110
109
|
baseURL: `${serverUrl}/api`,
|
|
111
110
|
headers: functionHeaders,
|
|
112
|
-
token
|
|
111
|
+
token,
|
|
113
112
|
interceptResponses: false,
|
|
114
113
|
onError: options === null || options === void 0 ? void 0 : options.onError,
|
|
115
114
|
});
|
|
116
115
|
const serviceRoleHeaders = {
|
|
117
116
|
...headers,
|
|
118
|
-
...(
|
|
117
|
+
...(token ? { "on-behalf-of": `Bearer ${token}` } : {}),
|
|
119
118
|
};
|
|
120
119
|
const serviceRoleAxiosClient = createAxiosClient({
|
|
121
120
|
baseURL: `${serverUrl}/api`,
|
|
@@ -141,7 +140,7 @@ export function createClient(config) {
|
|
|
141
140
|
const userAuthModule = createAuthModule(axiosClient, functionsAxiosClient, appId, {
|
|
142
141
|
appBaseUrl: normalizedAppBaseUrl,
|
|
143
142
|
serverUrl,
|
|
144
|
-
token
|
|
143
|
+
token,
|
|
145
144
|
embedded,
|
|
146
145
|
});
|
|
147
146
|
// Apply the access token before any module that may issue authenticated
|
|
@@ -150,8 +149,8 @@ export function createClient(config) {
|
|
|
150
149
|
// request is built before setToken runs and goes out unauthenticated.
|
|
151
150
|
// An embedded load skips this: its session comes from the exchange below,
|
|
152
151
|
// and a token an earlier visitor left in storage must not become it.
|
|
153
|
-
if (
|
|
154
|
-
const accessToken =
|
|
152
|
+
if (typeof window !== "undefined" && !embedded) {
|
|
153
|
+
const accessToken = token || getAccessToken();
|
|
155
154
|
if (accessToken) {
|
|
156
155
|
currentToken = accessToken;
|
|
157
156
|
userAuthModule.setToken(accessToken);
|
|
@@ -164,7 +163,7 @@ export function createClient(config) {
|
|
|
164
163
|
if (userAuthModule.hasToken()) {
|
|
165
164
|
return currentToken;
|
|
166
165
|
}
|
|
167
|
-
return embedded
|
|
166
|
+
return embedded ? null : getAccessToken();
|
|
168
167
|
};
|
|
169
168
|
const applyToken = (newToken, saveToStorage) => {
|
|
170
169
|
userAuthModule.setToken(newToken, saveToStorage);
|