@base44-preview/sdk 0.8.40-pr.212.f89ce7f → 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
@@ -12,7 +12,7 @@ import { createAppLogsModule } from "./modules/app-logs.js";
12
12
  import { createUsersModule } from "./modules/users.js";
13
13
  import { RoomsSocket } from "./utils/socket-utils.js";
14
14
  import { createAnalyticsModule } from "./modules/analytics.js";
15
- import { createActorsModule, resolveActorsWsUrl } from "./modules/actors.js";
15
+ import { createActorsModule } from "./modules/actors.js";
16
16
  /**
17
17
  * Creates a Base44 client.
18
18
  *
@@ -51,18 +51,28 @@ import { createActorsModule, resolveActorsWsUrl } from "./modules/actors.js";
51
51
  * ```
52
52
  */
53
53
  export function createClient(config) {
54
- var _a, _b, _c, _d;
54
+ var _a, _b;
55
55
  const { serverUrl = "https://base44.app", appId, token, serviceToken, requiresAuth = false, appBaseUrl, options, functionsVersion, headers: optionalHeaders, actorsWsUrl, } = config;
56
56
  // Normalize appBaseUrl to always be a string (empty if not provided or invalid)
57
57
  const normalizedAppBaseUrl = typeof appBaseUrl === "string" ? appBaseUrl : "";
58
- // Same-origin with the running app (it proxies /parties to the backend), not
59
- // the API host. React Native has a bare `window` with no `location`, so guard both.
60
- const resolvedActorsWsUrl = resolveActorsWsUrl({
61
- actorsWsUrl,
62
- appBaseUrl: normalizedAppBaseUrl,
63
- browserOrigin: typeof window !== "undefined" ? (_b = (_a = window.location) === null || _a === void 0 ? void 0 : _a.origin) !== null && _b !== void 0 ? _b : "" : "",
64
- serverUrl,
65
- });
58
+ // Derive the Actor WebSocket URL if not explicitly provided. Default to
59
+ // the app's OWN origin (the app URL proxies /parties to the backend) so the
60
+ // socket is same-origin with the running app, not the API host: prefer an
61
+ // explicit appBaseUrl, then the browser origin, then fall back to serverUrl
62
+ // (Node/SSR, where there's no window). Convert https:// → wss:// (http → ws)
63
+ // and strip the trailing slash.
64
+ const resolvedActorsWsUrl = (() => {
65
+ var _a, _b;
66
+ if (actorsWsUrl)
67
+ return actorsWsUrl.replace(/\/$/, "");
68
+ const appOrigin = normalizedAppBaseUrl ||
69
+ // React Native has a bare `window` with no `location`, so guard both.
70
+ (typeof window !== "undefined" ? (_b = (_a = window.location) === null || _a === void 0 ? void 0 : _a.origin) !== null && _b !== void 0 ? _b : "" : "");
71
+ return (appOrigin || serverUrl)
72
+ .replace(/\/$/, "")
73
+ .replace(/^https:\/\//, "wss://")
74
+ .replace(/^http:\/\//, "ws://");
75
+ })();
66
76
  const socketConfig = {
67
77
  serverUrl,
68
78
  mountPath: "/ws-user-apps/socket.io/",
@@ -132,12 +142,6 @@ export function createClient(config) {
132
142
  userAuthModule.setToken(accessToken);
133
143
  }
134
144
  }
135
- const actorsModule = createActorsModule({
136
- appId,
137
- actorsWsUrl: resolvedActorsWsUrl,
138
- functionsVersion,
139
- getAuthToken: () => token || getAccessToken(),
140
- });
141
145
  const userModules = {
142
146
  entities: createEntitiesModule({
143
147
  axios: axiosClient,
@@ -157,7 +161,7 @@ export function createClient(config) {
157
161
  }
158
162
  return headers;
159
163
  },
160
- baseURL: (_c = functionsAxiosClient.defaults) === null || _c === void 0 ? void 0 : _c.baseURL,
164
+ baseURL: (_a = functionsAxiosClient.defaults) === null || _a === void 0 ? void 0 : _a.baseURL,
161
165
  }),
162
166
  agents: createAgentsModule({
163
167
  axios: axiosClient,
@@ -175,10 +179,15 @@ export function createClient(config) {
175
179
  appId,
176
180
  userAuthModule,
177
181
  }),
178
- actors: actorsModule.module,
182
+ actors: createActorsModule({
183
+ appId,
184
+ actorsWsUrl: resolvedActorsWsUrl,
185
+ functionsVersion,
186
+ getAuthToken: () => token || getAccessToken(),
187
+ }),
179
188
  cleanup: () => {
180
189
  userModules.analytics.cleanup();
181
- actorsModule.closeAll();
190
+ userModules.actors.closeAll();
182
191
  if (socket) {
183
192
  socket.disconnect();
184
193
  }
@@ -202,7 +211,7 @@ export function createClient(config) {
202
211
  }
203
212
  return headers;
204
213
  },
205
- baseURL: (_d = serviceRoleFunctionsAxiosClient.defaults) === null || _d === void 0 ? void 0 : _d.baseURL,
214
+ baseURL: (_b = serviceRoleFunctionsAxiosClient.defaults) === null || _b === void 0 ? void 0 : _b.baseURL,
206
215
  }),
207
216
  agents: createAgentsModule({
208
217
  axios: serviceRoleAxiosClient,
@@ -9,20 +9,7 @@ interface ActorsConfig {
9
9
  functionsVersion?: string;
10
10
  actorsWsUrl: string;
11
11
  }
12
- /**
13
- * Base WebSocket URL for Actor connections. An explicit `actorsWsUrl` wins;
14
- * otherwise the app's own origin (`appBaseUrl`, else the browser origin, else
15
- * `serverUrl`) with `https://`→`wss://` / `http://`→`ws://` and no trailing
16
- * slash — the app proxies `/parties` to the backend dispatcher.
17
- */
18
- export declare function resolveActorsWsUrl(opts: {
19
- actorsWsUrl?: string;
20
- appBaseUrl?: string;
21
- browserOrigin?: string;
22
- serverUrl: string;
23
- }): string;
24
12
  export declare function createActorsModule(config: ActorsConfig): {
25
- module: Record<string, (instanceId: string) => ActorRoom>;
26
13
  closeAll: () => void;
27
- };
14
+ } & Record<string, (instanceId: string) => ActorRoom>;
28
15
  export {};
@@ -107,31 +107,24 @@ class Room {
107
107
  (_b = this.onClose) === null || _b === void 0 ? void 0 : _b.call(this);
108
108
  }
109
109
  }
110
- /**
111
- * Base WebSocket URL for Actor connections. An explicit `actorsWsUrl` wins;
112
- * otherwise the app's own origin (`appBaseUrl`, else the browser origin, else
113
- * `serverUrl`) with `https://`→`wss://` / `http://`→`ws://` and no trailing
114
- * slash — the app proxies `/parties` to the backend dispatcher.
115
- */
116
- export function resolveActorsWsUrl(opts) {
117
- if (opts.actorsWsUrl)
118
- return opts.actorsWsUrl.replace(/\/$/, "");
119
- const appOrigin = opts.appBaseUrl || opts.browserOrigin || "";
120
- return (appOrigin || opts.serverUrl)
121
- .replace(/\/$/, "")
122
- .replace(/^https:\/\//, "wss://")
123
- .replace(/^http:\/\//, "ws://");
124
- }
125
110
  export function createActorsModule(config) {
126
111
  // Live rooms this client opened, so client.cleanup() can reclaim any the app
127
112
  // forgot to close() (each room removes itself here on close).
128
113
  const rooms = new Set();
129
- const module = new Proxy({}, {
130
- get(_, key) {
131
- // Symbols and `then` resolve to undefined (so the module isn't mistaken
132
- // for a thenable when awaited); any string key is an actor name.
133
- if (typeof key !== "string" || key === "then")
134
- return undefined;
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
+ }
135
128
  return (instanceId) => {
136
129
  const room = new Room(key, instanceId, config, () => rooms.delete(room));
137
130
  rooms.add(room);
@@ -139,11 +132,4 @@ export function createActorsModule(config) {
139
132
  };
140
133
  },
141
134
  });
142
- return {
143
- module,
144
- closeAll: () => {
145
- for (const room of [...rooms])
146
- room.close();
147
- },
148
- };
149
135
  }
@@ -58,7 +58,7 @@ export interface ActorRoom<N extends string = string> {
58
58
  connect(options?: ActorConnectOptions): this;
59
59
  /** Register a message listener. Multiple are allowed; returns a per-listener unsubscribe. */
60
60
  subscribe(callback: (data: ToClientFor<N>) => void): ActorSubscription;
61
- /** Send a message. Throws before {@link connect}; buffered by the socket once connecting. */
61
+ /** Send a message. Throws before {@link connect}; buffered by the socket until open. */
62
62
  send(data: ToServerFor<N>): void;
63
63
  /** Tear down the socket, heartbeat, and all listeners. */
64
64
  close(): void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@base44-preview/sdk",
3
- "version": "0.8.40-pr.212.f89ce7f",
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",