@base44-preview/sdk 0.8.48-pr.282.1b5a2bd → 0.8.48-pr.282.3c9bac2

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
@@ -65,23 +65,6 @@ export function createClient(config) {
65
65
  const embedded = Boolean(embedOtt) || isEmbeddedTab();
66
66
  // In a frame the passed token is the OTT itself or a stale stored one, not this session.
67
67
  const token = embedded ? undefined : config.token;
68
- const socketConfig = {
69
- serverUrl,
70
- mountPath: "/ws-user-apps/socket.io/",
71
- transports: ["websocket"],
72
- appId,
73
- // null (not undefined): inside a frame the socket must never fall back to storage.
74
- token: embedded ? null : token,
75
- };
76
- let socket = null;
77
- const getSocket = () => {
78
- if (!socket) {
79
- socket = RoomsSocket({
80
- config: socketConfig,
81
- });
82
- }
83
- return socket;
84
- };
85
68
  const headers = {
86
69
  ...optionalHeaders,
87
70
  "X-App-Id": String(appId),
@@ -149,12 +132,23 @@ export function createClient(config) {
149
132
  }
150
133
  // Live token for every module; outside a frame it still falls back to storage.
151
134
  const getToken = () => { var _a; return (_a = userAuthModule.getToken()) !== null && _a !== void 0 ? _a : (embedded ? null : getAccessToken()); };
135
+ const socketConfig = {
136
+ serverUrl,
137
+ mountPath: "/ws-user-apps/socket.io/",
138
+ transports: ["websocket"],
139
+ appId,
140
+ getToken,
141
+ };
142
+ let socket = null;
143
+ const getSocket = () => {
144
+ if (!socket) {
145
+ socket = RoomsSocket({ config: socketConfig });
146
+ }
147
+ return socket;
148
+ };
152
149
  const applyToken = (newToken, saveToStorage) => {
153
150
  userAuthModule.setToken(newToken, saveToStorage);
154
- socketConfig.token = newToken;
155
- if (socket) {
156
- socket.updateConfig({ token: newToken });
157
- }
151
+ socket === null || socket === void 0 ? void 0 : socket.reconnect();
158
152
  };
159
153
  // Settles once the exchanged session is applied (memory only); at once otherwise.
160
154
  const authReady = embedOtt
@@ -4,9 +4,8 @@ export interface RoomsSocketConfig {
4
4
  mountPath: string;
5
5
  transports: string[];
6
6
  appId: string;
7
- /** `undefined` means unknown — the socket looks in storage; `null` means
8
- * known to be anonymous, so storage is never consulted. */
9
- token?: string | null;
7
+ /** Asked on every connect, so the socket always carries the current session. */
8
+ getToken: () => string | null;
10
9
  }
11
10
  export type TSocketRoom = string;
12
11
  export type TJsonStr = string;
@@ -42,7 +41,7 @@ export declare function RoomsSocket({ config }: {
42
41
  leave: (room: string) => void;
43
42
  }>;
44
43
  subscribeToRoom: (room: TSocketRoom, handlers: Partial<{ [k in TEvent]: THandler<k>; }>) => () => void;
45
- updateConfig: (config: Partial<RoomsSocketConfig>) => void;
44
+ reconnect: () => void;
46
45
  updateModel: (room: string, data: any) => Promise<void>;
47
46
  disconnect: () => void;
48
47
  };
@@ -1,5 +1,4 @@
1
1
  import { io } from "socket.io-client";
2
- import { getAccessToken } from "./auth-utils.js";
3
2
  import { getAnalyticsSessionId } from "../modules/analytics.js";
4
3
  const ROOM_LEAVE_GRACE_MS = 250;
5
4
  function initializeSocket(config, handlers) {
@@ -7,7 +6,7 @@ function initializeSocket(config, handlers) {
7
6
  // handshake so the backend can verify room access for anonymous agent
8
7
  // conversations (mirrors the X-Base44-Anonymous-Id HTTP header). Authenticated
9
8
  // clients are identified by their token instead.
10
- const resolvedToken = config.token === undefined ? getAccessToken() : config.token;
9
+ const resolvedToken = config.getToken();
11
10
  const query = {
12
11
  app_id: config.appId,
13
12
  token: resolvedToken,
@@ -41,7 +40,6 @@ function initializeSocket(config, handlers) {
41
40
  return socket;
42
41
  }
43
42
  export function RoomsSocket({ config }) {
44
- let currentConfig = { ...config };
45
43
  const roomsToListeners = {};
46
44
  const pendingRoomLeaves = {};
47
45
  const handlers = {
@@ -83,13 +81,10 @@ export function RoomsSocket({ config }) {
83
81
  socket.disconnect();
84
82
  }
85
83
  }
86
- function updateConfig(config) {
84
+ /** Drops the connection and opens a new one with the current token. */
85
+ function reconnect() {
87
86
  cleanup();
88
- currentConfig = {
89
- ...currentConfig,
90
- ...config,
91
- };
92
- socket = initializeSocket(currentConfig, handlers);
87
+ socket = initializeSocket(config, handlers);
93
88
  }
94
89
  function joinRoom(room) {
95
90
  socket.emit("join", room);
@@ -162,7 +157,7 @@ export function RoomsSocket({ config }) {
162
157
  return {
163
158
  socket,
164
159
  subscribeToRoom,
165
- updateConfig,
160
+ reconnect,
166
161
  updateModel,
167
162
  disconnect,
168
163
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@base44-preview/sdk",
3
- "version": "0.8.48-pr.282.1b5a2bd",
3
+ "version": "0.8.48-pr.282.3c9bac2",
4
4
  "description": "JavaScript SDK for Base44 API",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",