@base44-preview/sdk 0.7.0-pr.27.b5c0834 → 0.7.0-pr.27.df967f0

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.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  export type CreateClientOptions = {
2
2
  onError?: (error: Error) => void;
3
3
  };
4
- export type Base44SDK = ReturnType<typeof createClient>;
4
+ export type Base44Client = ReturnType<typeof createClient>;
5
5
  /**
6
6
  * Create a Base44 client instance
7
7
  * @param {Object} config - Client configuration
@@ -18,6 +18,7 @@ export declare function createClient(config: {
18
18
  token?: string;
19
19
  serviceToken?: string;
20
20
  requiresAuth?: boolean;
21
+ functionsVersion?: string;
21
22
  options?: CreateClientOptions;
22
23
  }): {
23
24
  /**
package/dist/client.js CHANGED
@@ -18,7 +18,7 @@ import { RoomsSocket } from "./utils/socket-utils.js";
18
18
  * @returns {Object} Base44 client instance
19
19
  */
20
20
  export function createClient(config) {
21
- const { serverUrl = "https://base44.app", appId, token, serviceToken, requiresAuth = false, options, } = config;
21
+ const { serverUrl = "https://base44.app", appId, token, serviceToken, requiresAuth = false, options, functionsVersion, } = config;
22
22
  const socketConfig = {
23
23
  serverUrl,
24
24
  mountPath: "/ws-user-apps/socket.io/",
@@ -29,11 +29,18 @@ export function createClient(config) {
29
29
  const socket = RoomsSocket({
30
30
  config: socketConfig,
31
31
  });
32
+ const headers = {
33
+ "X-App-Id": String(appId),
34
+ };
35
+ const functionHeaders = functionsVersion
36
+ ? {
37
+ ...headers,
38
+ "Base44-Functions-Version": functionsVersion,
39
+ }
40
+ : headers;
32
41
  const axiosClient = createAxiosClient({
33
42
  baseURL: `${serverUrl}/api`,
34
- headers: {
35
- "X-App-Id": String(appId),
36
- },
43
+ headers,
37
44
  token,
38
45
  requiresAuth,
39
46
  appId,
@@ -42,9 +49,7 @@ export function createClient(config) {
42
49
  });
43
50
  const functionsAxiosClient = createAxiosClient({
44
51
  baseURL: `${serverUrl}/api`,
45
- headers: {
46
- "X-App-Id": String(appId),
47
- },
52
+ headers: functionHeaders,
48
53
  token,
49
54
  requiresAuth,
50
55
  appId,
@@ -54,9 +59,7 @@ export function createClient(config) {
54
59
  });
55
60
  const serviceRoleAxiosClient = createAxiosClient({
56
61
  baseURL: `${serverUrl}/api`,
57
- headers: {
58
- "X-App-Id": String(appId),
59
- },
62
+ headers,
60
63
  token: serviceToken,
61
64
  serverUrl,
62
65
  appId,
@@ -64,9 +67,7 @@ export function createClient(config) {
64
67
  });
65
68
  const serviceRoleFunctionsAxiosClient = createAxiosClient({
66
69
  baseURL: `${serverUrl}/api`,
67
- headers: {
68
- "X-App-Id": String(appId),
69
- },
70
+ headers: functionHeaders,
70
71
  token: serviceToken,
71
72
  serverUrl,
72
73
  appId,
@@ -166,6 +167,7 @@ export function createClientFromRequest(request) {
166
167
  const serviceRoleAuthHeader = request.headers.get("Base44-Service-Authorization");
167
168
  const appId = request.headers.get("Base44-App-Id");
168
169
  const serverUrlHeader = request.headers.get("Base44-Api-Url");
170
+ const functionsVersion = request.headers.get("Base44-Functions-Version");
169
171
  if (!appId) {
170
172
  throw new Error("Base44-App-Id header is required, but is was not found on the request");
171
173
  }
@@ -193,5 +195,6 @@ export function createClientFromRequest(request) {
193
195
  appId,
194
196
  token: userToken,
195
197
  serviceToken: serviceRoleToken,
198
+ functionsVersion: functionsVersion !== null && functionsVersion !== void 0 ? functionsVersion : undefined,
196
199
  });
197
200
  }
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
- import { createClient, createClientFromRequest, Base44SDK } from "./client.js";
1
+ import { createClient, createClientFromRequest, type Base44Client } from "./client.js";
2
2
  import { Base44Error } from "./utils/axios-client.js";
3
3
  import { getAccessToken, saveAccessToken, removeAccessToken, getLoginUrl } from "./utils/auth-utils.js";
4
4
  export { createClient, createClientFromRequest, Base44Error, getAccessToken, saveAccessToken, removeAccessToken, getLoginUrl, };
5
- export type { Base44SDK };
5
+ export type { Base44Client };
6
6
  export * from "./types.js";
@@ -10,23 +10,23 @@ function initializeSocket(config, handlers) {
10
10
  token: (_a = config.token) !== null && _a !== void 0 ? _a : getAccessToken(),
11
11
  },
12
12
  });
13
- socket.on("connect", () => {
13
+ socket.on("connect", async () => {
14
14
  var _a;
15
15
  console.log("connect", socket.id);
16
- (_a = handlers.connect) === null || _a === void 0 ? void 0 : _a.call(handlers);
16
+ return (_a = handlers.connect) === null || _a === void 0 ? void 0 : _a.call(handlers);
17
17
  });
18
- socket.on("update_model", (msg) => {
18
+ socket.on("update_model", async (msg) => {
19
19
  var _a;
20
- (_a = handlers.update_model) === null || _a === void 0 ? void 0 : _a.call(handlers, msg);
20
+ return (_a = handlers.update_model) === null || _a === void 0 ? void 0 : _a.call(handlers, msg);
21
21
  });
22
- socket.on("error", (error) => {
22
+ socket.on("error", async (error) => {
23
23
  var _a;
24
- (_a = handlers.error) === null || _a === void 0 ? void 0 : _a.call(handlers, error);
24
+ return (_a = handlers.error) === null || _a === void 0 ? void 0 : _a.call(handlers, error);
25
25
  });
26
- socket.on("connect_error", (error) => {
26
+ socket.on("connect_error", async (error) => {
27
27
  var _a;
28
28
  console.error("connect_error", error);
29
- (_a = handlers.error) === null || _a === void 0 ? void 0 : _a.call(handlers, error);
29
+ return (_a = handlers.error) === null || _a === void 0 ? void 0 : _a.call(handlers, error);
30
30
  });
31
31
  return socket;
32
32
  }
@@ -52,9 +52,11 @@ export function RoomsSocket({ config }) {
52
52
  await Promise.all(promises);
53
53
  },
54
54
  error: async (error) => {
55
- var _a;
56
55
  console.error("error", error);
57
- await ((_a = handlers.error) === null || _a === void 0 ? void 0 : _a.call(handlers, error));
56
+ const promises = Object.values(roomsToListeners)
57
+ .flat()
58
+ .map((listener) => { var _a; return (_a = listener.error) === null || _a === void 0 ? void 0 : _a.call(listener, error); });
59
+ await Promise.all(promises);
58
60
  },
59
61
  };
60
62
  let socket = initializeSocket(config, handlers);
@@ -95,7 +97,12 @@ export function RoomsSocket({ config }) {
95
97
  }
96
98
  roomsToListeners[room].push(handlers);
97
99
  return () => {
98
- roomsToListeners[room] = roomsToListeners[room].filter((listener) => listener !== handlers);
100
+ var _a, _b;
101
+ roomsToListeners[room] =
102
+ (_b = (_a = roomsToListeners[room]) === null || _a === void 0 ? void 0 : _a.filter((listener) => listener !== handlers)) !== null && _b !== void 0 ? _b : [];
103
+ if (roomsToListeners[room].length === 0) {
104
+ leaveRoom(room);
105
+ }
99
106
  };
100
107
  };
101
108
  return {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@base44-preview/sdk",
3
- "version": "0.7.0-pr.27.b5c0834",
3
+ "version": "0.7.0-pr.27.df967f0",
4
4
  "description": "JavaScript SDK for Base44 API",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",