@base44-preview/sdk 0.8.40-pr.212.d742832 → 0.8.40-pr.212.ff950a3

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
@@ -183,12 +183,11 @@ export function createClient(config) {
183
183
  appId,
184
184
  actorsWsUrl: resolvedActorsWsUrl,
185
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
186
  getAuthToken: () => token || getAccessToken(),
189
187
  }),
190
188
  cleanup: () => {
191
189
  userModules.analytics.cleanup();
190
+ userModules.actors.closeAll();
192
191
  if (socket) {
193
192
  socket.disconnect();
194
193
  }
@@ -9,5 +9,7 @@ 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
+ closeAll: () => void;
14
+ } & Record<string, (instanceId: string) => ActorRoom>;
13
15
  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;
@@ -53,11 +54,11 @@ class Room {
53
54
  data = JSON.parse(ev.data);
54
55
  }
55
56
  catch (_a) {
56
- return; // ignore malformed
57
+ return;
57
58
  }
58
59
  const msgType = data && typeof data === "object" ? data.type : undefined;
59
60
  if (msgType === "__pong")
60
- return; // platform message — never surface it
61
+ return;
61
62
  for (const listener of this.listeners)
62
63
  listener(data);
63
64
  });
@@ -68,13 +69,12 @@ class Room {
68
69
  return;
69
70
  }
70
71
  try {
71
- // Server contract: the deployed Actor shim echoes __ping with __pong
72
- // (see base44-userapp-bundler shim/actor.ts). If that ever stops, an
73
- // idle room's lastMsg goes stale and this watchdog reconnects every DEAD_MS.
72
+ // The deployed shim echoes __ping → __pong (base44-userapp-bundler
73
+ // shim/actor.ts); without that, an idle room reconnects every DEAD_MS.
74
74
  ws.send(JSON.stringify({ type: "__ping" }));
75
75
  }
76
76
  catch (_a) {
77
- // socket not open; the watchdog above will force a reconnect
77
+ // not open; the watchdog above will reconnect
78
78
  }
79
79
  }, PING_MS);
80
80
  return this;
@@ -95,7 +95,7 @@ class Room {
95
95
  this.ws.send(JSON.stringify(data));
96
96
  }
97
97
  close() {
98
- var _a;
98
+ var _a, _b;
99
99
  if (this.heartbeat) {
100
100
  clearInterval(this.heartbeat);
101
101
  this.heartbeat = null;
@@ -103,12 +103,33 @@ class Room {
103
103
  this.listeners.clear();
104
104
  (_a = this.ws) === null || _a === void 0 ? void 0 : _a.close();
105
105
  this.ws = null;
106
+ this.connId = null;
107
+ (_b = this.onClose) === null || _b === void 0 ? void 0 : _b.call(this);
106
108
  }
107
109
  }
108
110
  export function createActorsModule(config) {
109
- return new Proxy({}, {
110
- get(_, actorName) {
111
- 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 api = {
115
+ closeAll: () => {
116
+ for (const room of [...rooms])
117
+ room.close();
118
+ },
119
+ };
120
+ return new Proxy(api, {
121
+ get(target, key) {
122
+ // Own methods (closeAll), inherited/symbol keys, and `then` (so the
123
+ // module isn't mistaken for a thenable when awaited) resolve normally;
124
+ // any other string key is an actor name → a room factory.
125
+ if (key === "then" || typeof key !== "string" || key in target) {
126
+ return Reflect.get(target, key);
127
+ }
128
+ return (instanceId) => {
129
+ const room = new Room(key, instanceId, config, () => rooms.delete(room));
130
+ rooms.add(room);
131
+ return room;
132
+ };
112
133
  },
113
134
  });
114
135
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@base44-preview/sdk",
3
- "version": "0.8.40-pr.212.d742832",
3
+ "version": "0.8.40-pr.212.ff950a3",
4
4
  "description": "JavaScript SDK for Base44 API",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",