@base44-preview/sdk 0.8.48-pr.282.6dd99a0 → 0.8.48-pr.282.6ea0687
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 -23
- package/package.json +1 -1
package/dist/client.js
CHANGED
|
@@ -59,9 +59,7 @@ export function createClient(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 embedOtt = takeEmbedTokenFromUrl();
|
|
62
|
-
//
|
|
63
|
-
// exchange, or from a login — reaches the socket and every other module.
|
|
64
|
-
// A declaration, not a const, so this block can stay above the auth module.
|
|
62
|
+
// A declaration, not a const: this block sits above the auth module.
|
|
65
63
|
function getToken() {
|
|
66
64
|
var _a;
|
|
67
65
|
return (_a = userAuthModule.getToken()) !== null && _a !== void 0 ? _a : (embedOtt ? null : getAccessToken());
|
|
@@ -82,9 +80,8 @@ export function createClient(config) {
|
|
|
82
80
|
}
|
|
83
81
|
return socket;
|
|
84
82
|
};
|
|
85
|
-
// Apps
|
|
86
|
-
//
|
|
87
|
-
// send as a bearer. The exchange below is what turns it into a session.
|
|
83
|
+
// Apps pass getAccessToken() in as `token`, which in a frame is the OTT —
|
|
84
|
+
// what the exchange trades for a session, never a bearer itself.
|
|
88
85
|
const token = embedOtt ? undefined : config.token;
|
|
89
86
|
const headers = {
|
|
90
87
|
...optionalHeaders,
|
|
@@ -139,17 +136,15 @@ export function createClient(config) {
|
|
|
139
136
|
serverUrl,
|
|
140
137
|
token,
|
|
141
138
|
embedded: Boolean(embedOtt),
|
|
142
|
-
// The socket carries its token on the handshake, so
|
|
143
|
-
//
|
|
144
|
-
// dropping the one still running as the user who just left.
|
|
139
|
+
// The socket carries its token on the handshake, so it can only pick a
|
|
140
|
+
// new one up by redialling — or, on logout, by dropping what it has.
|
|
145
141
|
onSessionChange: (hasSession) => hasSession ? socket === null || socket === void 0 ? void 0 : socket.reconnect() : socket === null || socket === void 0 ? void 0 : socket.disconnect(),
|
|
146
142
|
});
|
|
147
143
|
// Apply the access token before any module that may issue authenticated
|
|
148
144
|
// requests during construction (notably analytics, which fires an init
|
|
149
145
|
// event whose flush calls auth.me()). Without this, the first User/me
|
|
150
146
|
// request is built before setToken runs and goes out unauthenticated.
|
|
151
|
-
// Not in a frame: a stored token there belongs to an earlier visitor
|
|
152
|
-
// this session, which only the exchange below can produce.
|
|
147
|
+
// Not in a frame: a stored token there belongs to an earlier visitor.
|
|
153
148
|
if (typeof window !== "undefined" && !embedOtt) {
|
|
154
149
|
const accessToken = token || getAccessToken();
|
|
155
150
|
if (accessToken) {
|
|
@@ -159,9 +154,8 @@ export function createClient(config) {
|
|
|
159
154
|
const session = embedOtt
|
|
160
155
|
? exchangeEmbedToken({ serverUrl, appId, ott: embedOtt })
|
|
161
156
|
: null;
|
|
162
|
-
//
|
|
163
|
-
//
|
|
164
|
-
// must not turn into a rejection on each of them.
|
|
157
|
+
// Never rejects: every request waits on it, so one failure here must not
|
|
158
|
+
// become a rejection on each of them.
|
|
165
159
|
const authReady = session
|
|
166
160
|
? session
|
|
167
161
|
.then((sessionToken) => {
|
|
@@ -170,8 +164,6 @@ export function createClient(config) {
|
|
|
170
164
|
userAuthModule.setToken(sessionToken, false);
|
|
171
165
|
return;
|
|
172
166
|
}
|
|
173
|
-
// The app is about to run anonymous. Say why, once, instead of
|
|
174
|
-
// leaving only the 401s that follow.
|
|
175
167
|
const error = new Error("Base44: the embed token was refused, so this app is not signed in.");
|
|
176
168
|
console.error(error.message);
|
|
177
169
|
(_a = options === null || options === void 0 ? void 0 : options.onError) === null || _a === void 0 ? void 0 : _a.call(options, error);
|
|
@@ -181,8 +173,8 @@ export function createClient(config) {
|
|
|
181
173
|
})
|
|
182
174
|
: Promise.resolve();
|
|
183
175
|
if (session) {
|
|
184
|
-
//
|
|
185
|
-
//
|
|
176
|
+
// Registered after createAxiosClient's so it runs first (axios unshifts),
|
|
177
|
+
// letting the anonymous-visitor header see the Authorization we just set.
|
|
186
178
|
for (const client of [axiosClient, functionsAxiosClient]) {
|
|
187
179
|
client.interceptors.request.use(async (requestConfig) => {
|
|
188
180
|
await authReady;
|
|
@@ -247,8 +239,7 @@ export function createClient(config) {
|
|
|
247
239
|
getSocket,
|
|
248
240
|
appId,
|
|
249
241
|
serverUrl,
|
|
250
|
-
//
|
|
251
|
-
// than issue a request, so during the exchange they see no token.
|
|
242
|
+
// Sync, unlike everything else: these return a URL, not a promise.
|
|
252
243
|
getToken,
|
|
253
244
|
}),
|
|
254
245
|
aiGateway: createAiGatewayModule({ serverUrl, getToken, appId }),
|
|
@@ -296,9 +287,8 @@ export function createClient(config) {
|
|
|
296
287
|
getSocket,
|
|
297
288
|
appId,
|
|
298
289
|
serverUrl,
|
|
299
|
-
// The user's token,
|
|
300
|
-
//
|
|
301
|
-
// the app's service credential must never end up in.
|
|
290
|
+
// The user's token, deliberately: this is read only for the `?token=` on
|
|
291
|
+
// a channel URL handed to that user. Never the service credential.
|
|
302
292
|
getToken,
|
|
303
293
|
}),
|
|
304
294
|
aiGateway: createAiGatewayModule({
|