@base44-preview/sdk 0.8.48-pr.282.c69fdcd → 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 CHANGED
@@ -58,6 +58,9 @@ export function createClient(config) {
58
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
+ // A host platform embeds the app with a one-time token on the iframe URL.
62
+ // It comes off the URL here, before any other code can read it; the
63
+ // exchange that turns it into a session runs once the modules exist.
61
64
  const embedOtt = takeEmbedTokenFromUrl();
62
65
  if (embedOtt) {
63
66
  markEmbeddedTab();
@@ -67,6 +70,7 @@ export function createClient(config) {
67
70
  // page loaded. In an embedded frame that is the one-time token itself, or a
68
71
  // token an earlier visitor left in storage; neither is this session.
69
72
  const token = embedded ? undefined : config.token;
73
+ let currentToken = token !== null && token !== void 0 ? token : null;
70
74
  const socketConfig = {
71
75
  serverUrl,
72
76
  mountPath: "/ws-user-apps/socket.io/",
@@ -148,15 +152,22 @@ export function createClient(config) {
148
152
  if (typeof window !== "undefined" && !embedded) {
149
153
  const accessToken = token || getAccessToken();
150
154
  if (accessToken) {
155
+ currentToken = accessToken;
151
156
  userAuthModule.setToken(accessToken);
152
157
  }
153
158
  }
154
159
  // The one answer every module reads. Follows setToken and logout; outside an
155
160
  // embedded frame it still falls back to storage, so a login in another tab is
156
161
  // picked up on the next connection, as before.
157
- const getToken = () => { var _a; return (_a = userAuthModule.getToken()) !== null && _a !== void 0 ? _a : (embedded ? null : getAccessToken()); };
162
+ const getToken = () => {
163
+ if (userAuthModule.hasToken()) {
164
+ return currentToken;
165
+ }
166
+ return embedded ? null : getAccessToken();
167
+ };
158
168
  const applyToken = (newToken, saveToStorage) => {
159
169
  userAuthModule.setToken(newToken, saveToStorage);
170
+ currentToken = newToken;
160
171
  socketConfig.token = newToken;
161
172
  if (socket) {
162
173
  socket.updateConfig({ token: newToken });
@@ -82,13 +82,10 @@ export function createAuthModule(axios, functionsAxiosClient, appId, options) {
82
82
  // Tracked here rather than read off `axios.defaults` so the answer stays tied
83
83
  // to the identity transitions below (`setToken`, `logout`) instead of to the
84
84
  // header a caller may have set on the instance directly.
85
- let accessToken = options.token || null;
85
+ let hasAccessToken = Boolean(options.token);
86
86
  return {
87
87
  hasToken() {
88
- return accessToken !== null;
89
- },
90
- getToken() {
91
- return accessToken;
88
+ return hasAccessToken;
92
89
  },
93
90
  isEmbedded() {
94
91
  return Boolean(options.embedded);
@@ -164,7 +161,7 @@ export function createAuthModule(axios, functionsAxiosClient, appId, options) {
164
161
  // flight would otherwise resolve into callers that run after the logout.
165
162
  clearPendingMe();
166
163
  resetAnalyticsSessionContext();
167
- accessToken = null;
164
+ hasAccessToken = false;
168
165
  // Only do the rest if in a browser environment
169
166
  if (typeof window !== "undefined") {
170
167
  // Remove token from localStorage
@@ -193,7 +190,7 @@ export function createAuthModule(axios, functionsAxiosClient, appId, options) {
193
190
  // resolved for the previous one must not be handed to later callers.
194
191
  clearPendingMe();
195
192
  resetAnalyticsSessionContext();
196
- accessToken = token;
193
+ hasAccessToken = true;
197
194
  // handle token change for axios clients
198
195
  axios.defaults.headers.common["Authorization"] = `Bearer ${token}`;
199
196
  functionsAxiosClient.defaults.headers.common["Authorization"] = `Bearer ${token}`;
@@ -560,9 +560,4 @@ export interface InternalAuthModule extends AuthModule {
560
560
  * could not succeed without a session, not to decide that one is valid.
561
561
  */
562
562
  hasToken(): boolean;
563
- /**
564
- * The access token currently set on the client, or `null` when there is none.
565
- * Follows {@linkcode AuthModule.setToken | setToken} and {@linkcode AuthModule.logout | logout}.
566
- */
567
- getToken(): string | null;
568
563
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@base44-preview/sdk",
3
- "version": "0.8.48-pr.282.c69fdcd",
3
+ "version": "0.8.48-pr.282.d771123",
4
4
  "description": "JavaScript SDK for Base44 API",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",