@base44-preview/sdk 0.8.48-pr.282.8affbe6 → 0.8.48-pr.282.c69fdcd

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,23 +55,18 @@ 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, token, serviceToken, requiresAuth = false, appBaseUrl, options, functionsVersion, headers: optionalHeaders, } = config;
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
- // A host platform embeds the app with a one-time token on the iframe URL.
63
- // It comes off the URL here, before any other code can read it; the
64
- // exchange that turns it into a session runs once the modules exist.
65
- const embedOtt = inBrowser ? takeEmbedTokenFromUrl() : null;
66
- const embedded = embedOtt !== null || (inBrowser && isEmbeddedTab());
61
+ const embedOtt = takeEmbedTokenFromUrl();
67
62
  if (embedOtt) {
68
63
  markEmbeddedTab();
69
64
  }
65
+ const embedded = Boolean(embedOtt) || isEmbeddedTab();
70
66
  // What an app passes as `token` is whatever getAccessToken() returned as the
71
67
  // page loaded. In an embedded frame that is the one-time token itself, or a
72
68
  // token an earlier visitor left in storage; neither is this session.
73
- const configToken = embedded ? undefined : token;
74
- let currentToken = configToken !== null && configToken !== void 0 ? configToken : null;
69
+ const token = embedded ? undefined : config.token;
75
70
  const socketConfig = {
76
71
  serverUrl,
77
72
  mountPath: "/ws-user-apps/socket.io/",
@@ -79,7 +74,7 @@ export function createClient(config) {
79
74
  appId,
80
75
  // null (not undefined): an embedded frame's only identity is the one the
81
76
  // platform minted, so the socket must not fall back to a stored token.
82
- token: embedded ? null : configToken,
77
+ token: embedded ? null : token,
83
78
  };
84
79
  let socket = null;
85
80
  const getSocket = () => {
@@ -103,19 +98,19 @@ export function createClient(config) {
103
98
  const axiosClient = createAxiosClient({
104
99
  baseURL: `${serverUrl}/api`,
105
100
  headers,
106
- token: configToken,
101
+ token,
107
102
  onError: options === null || options === void 0 ? void 0 : options.onError,
108
103
  });
109
104
  const functionsAxiosClient = createAxiosClient({
110
105
  baseURL: `${serverUrl}/api`,
111
106
  headers: functionHeaders,
112
- token: configToken,
107
+ token,
113
108
  interceptResponses: false,
114
109
  onError: options === null || options === void 0 ? void 0 : options.onError,
115
110
  });
116
111
  const serviceRoleHeaders = {
117
112
  ...headers,
118
- ...(configToken ? { "on-behalf-of": `Bearer ${configToken}` } : {}),
113
+ ...(token ? { "on-behalf-of": `Bearer ${token}` } : {}),
119
114
  };
120
115
  const serviceRoleAxiosClient = createAxiosClient({
121
116
  baseURL: `${serverUrl}/api`,
@@ -141,7 +136,7 @@ export function createClient(config) {
141
136
  const userAuthModule = createAuthModule(axiosClient, functionsAxiosClient, appId, {
142
137
  appBaseUrl: normalizedAppBaseUrl,
143
138
  serverUrl,
144
- token: configToken,
139
+ token,
145
140
  embedded,
146
141
  });
147
142
  // Apply the access token before any module that may issue authenticated
@@ -150,25 +145,18 @@ export function createClient(config) {
150
145
  // request is built before setToken runs and goes out unauthenticated.
151
146
  // An embedded load skips this: its session comes from the exchange below,
152
147
  // and a token an earlier visitor left in storage must not become it.
153
- if (inBrowser && !embedded) {
154
- const accessToken = configToken || getAccessToken();
148
+ if (typeof window !== "undefined" && !embedded) {
149
+ const accessToken = token || getAccessToken();
155
150
  if (accessToken) {
156
- currentToken = accessToken;
157
151
  userAuthModule.setToken(accessToken);
158
152
  }
159
153
  }
160
154
  // The one answer every module reads. Follows setToken and logout; outside an
161
155
  // embedded frame it still falls back to storage, so a login in another tab is
162
156
  // picked up on the next connection, as before.
163
- const getToken = () => {
164
- if (userAuthModule.hasToken()) {
165
- return currentToken;
166
- }
167
- return embedded || !inBrowser ? null : getAccessToken();
168
- };
157
+ const getToken = () => { var _a; return (_a = userAuthModule.getToken()) !== null && _a !== void 0 ? _a : (embedded ? null : getAccessToken()); };
169
158
  const applyToken = (newToken, saveToStorage) => {
170
159
  userAuthModule.setToken(newToken, saveToStorage);
171
- currentToken = newToken;
172
160
  socketConfig.token = newToken;
173
161
  if (socket) {
174
162
  socket.updateConfig({ token: newToken });
@@ -82,10 +82,13 @@ 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 hasAccessToken = Boolean(options.token);
85
+ let accessToken = options.token || null;
86
86
  return {
87
87
  hasToken() {
88
- return hasAccessToken;
88
+ return accessToken !== null;
89
+ },
90
+ getToken() {
91
+ return accessToken;
89
92
  },
90
93
  isEmbedded() {
91
94
  return Boolean(options.embedded);
@@ -161,7 +164,7 @@ export function createAuthModule(axios, functionsAxiosClient, appId, options) {
161
164
  // flight would otherwise resolve into callers that run after the logout.
162
165
  clearPendingMe();
163
166
  resetAnalyticsSessionContext();
164
- hasAccessToken = false;
167
+ accessToken = null;
165
168
  // Only do the rest if in a browser environment
166
169
  if (typeof window !== "undefined") {
167
170
  // Remove token from localStorage
@@ -190,7 +193,7 @@ export function createAuthModule(axios, functionsAxiosClient, appId, options) {
190
193
  // resolved for the previous one must not be handed to later callers.
191
194
  clearPendingMe();
192
195
  resetAnalyticsSessionContext();
193
- hasAccessToken = true;
196
+ accessToken = token;
194
197
  // handle token change for axios clients
195
198
  axios.defaults.headers.common["Authorization"] = `Bearer ${token}`;
196
199
  functionsAxiosClient.defaults.headers.common["Authorization"] = `Bearer ${token}`;
@@ -560,4 +560,9 @@ 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;
563
568
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@base44-preview/sdk",
3
- "version": "0.8.48-pr.282.8affbe6",
3
+ "version": "0.8.48-pr.282.c69fdcd",
4
4
  "description": "JavaScript SDK for Base44 API",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",