@base44-preview/sdk 0.8.40-pr.212.1534644 → 0.8.40-pr.212.2b700ea

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
@@ -142,6 +142,12 @@ export function createClient(config) {
142
142
  userAuthModule.setToken(accessToken);
143
143
  }
144
144
  }
145
+ const actorsModule = createActorsModule({
146
+ appId,
147
+ actorsWsUrl: resolvedActorsWsUrl,
148
+ functionsVersion,
149
+ getAuthToken: () => token || getAccessToken(),
150
+ });
145
151
  const userModules = {
146
152
  entities: createEntitiesModule({
147
153
  axios: axiosClient,
@@ -179,16 +185,10 @@ export function createClient(config) {
179
185
  appId,
180
186
  userAuthModule,
181
187
  }),
182
- actors: createActorsModule({
183
- appId,
184
- actorsWsUrl: resolvedActorsWsUrl,
185
- functionsVersion,
186
- // Same credential as function calls; the platform proxy authenticates the
187
- // WS connection with it (anonymous when absent) — no pre-connect token mint.
188
- getAuthToken: () => token || getAccessToken(),
189
- }),
188
+ actors: actorsModule.module,
190
189
  cleanup: () => {
191
190
  userModules.analytics.cleanup();
191
+ actorsModule.closeAll();
192
192
  if (socket) {
193
193
  socket.disconnect();
194
194
  }
@@ -9,5 +9,8 @@ interface ActorsConfig {
9
9
  functionsVersion?: string;
10
10
  actorsWsUrl: string;
11
11
  }
12
- export declare function createActorsModule(config: ActorsConfig): Record<string, (instanceId: string) => ActorRoom>;
12
+ export declare function createActorsModule(config: ActorsConfig): {
13
+ module: Record<string, (instanceId: string) => ActorRoom>;
14
+ closeAll: () => void;
15
+ };
13
16
  export {};
@@ -4,10 +4,11 @@ import PartySocket from "partysocket";
4
4
  const PING_MS = 1000;
5
5
  const DEAD_MS = 3000;
6
6
  class Room {
7
- constructor(actorName, instanceId, config) {
7
+ constructor(actorName, instanceId, config, onClose) {
8
8
  this.actorName = actorName;
9
9
  this.instanceId = instanceId;
10
10
  this.config = config;
11
+ this.onClose = onClose;
11
12
  this.ws = null;
12
13
  this.listeners = new Set();
13
14
  this.heartbeat = null;
@@ -94,7 +95,7 @@ class Room {
94
95
  this.ws.send(JSON.stringify(data));
95
96
  }
96
97
  close() {
97
- var _a;
98
+ var _a, _b;
98
99
  if (this.heartbeat) {
99
100
  clearInterval(this.heartbeat);
100
101
  this.heartbeat = null;
@@ -102,12 +103,32 @@ class Room {
102
103
  this.listeners.clear();
103
104
  (_a = this.ws) === null || _a === void 0 ? void 0 : _a.close();
104
105
  this.ws = null;
106
+ this.connId = null;
107
+ (_b = this.onClose) === null || _b === void 0 ? void 0 : _b.call(this);
105
108
  }
106
109
  }
107
110
  export function createActorsModule(config) {
108
- return new Proxy({}, {
109
- get(_, actorName) {
110
- return (instanceId) => new Room(actorName, instanceId, config);
111
+ // Live rooms this client opened, so client.cleanup() can reclaim any the app
112
+ // forgot to close() (each room removes itself here on close).
113
+ const rooms = new Set();
114
+ const module = new Proxy({}, {
115
+ get(_, key) {
116
+ // Symbols and `then` resolve to undefined (so the module isn't mistaken
117
+ // for a thenable when awaited); any string key is an actor name.
118
+ if (typeof key !== "string" || key === "then")
119
+ return undefined;
120
+ return (instanceId) => {
121
+ const room = new Room(key, instanceId, config, () => rooms.delete(room));
122
+ rooms.add(room);
123
+ return room;
124
+ };
111
125
  },
112
126
  });
127
+ return {
128
+ module,
129
+ closeAll: () => {
130
+ for (const room of [...rooms])
131
+ room.close();
132
+ },
133
+ };
113
134
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@base44-preview/sdk",
3
- "version": "0.8.40-pr.212.1534644",
3
+ "version": "0.8.40-pr.212.2b700ea",
4
4
  "description": "JavaScript SDK for Base44 API",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",