@depup/base44__sdk 0.8.22-depup.0
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/LICENSE +21 -0
- package/README.md +32 -0
- package/changes.json +14 -0
- package/dist/client.d.ts +96 -0
- package/dist/client.js +375 -0
- package/dist/client.types.d.ts +144 -0
- package/dist/client.types.js +1 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.js +5 -0
- package/dist/modules/agents.d.ts +2 -0
- package/dist/modules/agents.js +77 -0
- package/dist/modules/agents.types.d.ts +377 -0
- package/dist/modules/agents.types.js +1 -0
- package/dist/modules/analytics.d.ts +20 -0
- package/dist/modules/analytics.js +277 -0
- package/dist/modules/analytics.types.d.ts +122 -0
- package/dist/modules/analytics.types.js +1 -0
- package/dist/modules/app-logs.d.ts +11 -0
- package/dist/modules/app-logs.js +27 -0
- package/dist/modules/app-logs.types.d.ts +46 -0
- package/dist/modules/app-logs.types.js +1 -0
- package/dist/modules/app.types.d.ts +142 -0
- package/dist/modules/app.types.js +1 -0
- package/dist/modules/auth.d.ts +13 -0
- package/dist/modules/auth.js +180 -0
- package/dist/modules/auth.types.d.ts +481 -0
- package/dist/modules/auth.types.js +1 -0
- package/dist/modules/connectors.d.ts +20 -0
- package/dist/modules/connectors.js +71 -0
- package/dist/modules/connectors.types.d.ts +296 -0
- package/dist/modules/connectors.types.js +1 -0
- package/dist/modules/custom-integrations.d.ts +11 -0
- package/dist/modules/custom-integrations.js +32 -0
- package/dist/modules/custom-integrations.types.d.ts +89 -0
- package/dist/modules/custom-integrations.types.js +1 -0
- package/dist/modules/entities.d.ts +20 -0
- package/dist/modules/entities.js +149 -0
- package/dist/modules/entities.types.d.ts +552 -0
- package/dist/modules/entities.types.js +1 -0
- package/dist/modules/functions.d.ts +12 -0
- package/dist/modules/functions.js +79 -0
- package/dist/modules/functions.types.d.ts +103 -0
- package/dist/modules/functions.types.js +1 -0
- package/dist/modules/integrations.d.ts +11 -0
- package/dist/modules/integrations.js +77 -0
- package/dist/modules/integrations.types.d.ts +413 -0
- package/dist/modules/integrations.types.js +1 -0
- package/dist/modules/sso.d.ts +12 -0
- package/dist/modules/sso.js +23 -0
- package/dist/modules/sso.types.d.ts +44 -0
- package/dist/modules/sso.types.js +1 -0
- package/dist/modules/types.d.ts +4 -0
- package/dist/modules/types.js +4 -0
- package/dist/modules/users.d.ts +16 -0
- package/dist/modules/users.js +23 -0
- package/dist/types.d.ts +72 -0
- package/dist/types.js +1 -0
- package/dist/utils/auth-utils.d.ts +117 -0
- package/dist/utils/auth-utils.js +189 -0
- package/dist/utils/auth-utils.types.d.ts +146 -0
- package/dist/utils/auth-utils.types.js +1 -0
- package/dist/utils/axios-client.d.ts +100 -0
- package/dist/utils/axios-client.js +193 -0
- package/dist/utils/axios-client.types.d.ts +28 -0
- package/dist/utils/axios-client.types.js +1 -0
- package/dist/utils/common.d.ts +3 -0
- package/dist/utils/common.js +6 -0
- package/dist/utils/sharedInstance.d.ts +1 -0
- package/dist/utils/sharedInstance.js +15 -0
- package/dist/utils/socket-utils.d.ts +47 -0
- package/dist/utils/socket-utils.js +115 -0
- package/package.json +87 -0
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import type { Base44ErrorJSON } from "./axios-client.types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Custom error class for Base44 SDK errors.
|
|
4
|
+
*
|
|
5
|
+
* This error is thrown when API requests fail. It extends the standard `Error` class and includes additional information about the HTTP status, error code, and response data from the server.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* try {
|
|
10
|
+
* await client.entities.Todo.get('invalid-id');
|
|
11
|
+
* } catch (error) {
|
|
12
|
+
* if (error instanceof Base44Error) {
|
|
13
|
+
* console.error('Status:', error.status); // 404
|
|
14
|
+
* console.error('Message:', error.message); // "Not found"
|
|
15
|
+
* console.error('Code:', error.code); // "NOT_FOUND"
|
|
16
|
+
* console.error('Data:', error.data); // Full response data
|
|
17
|
+
* }
|
|
18
|
+
* }
|
|
19
|
+
* ```
|
|
20
|
+
*
|
|
21
|
+
*/
|
|
22
|
+
export declare class Base44Error extends Error {
|
|
23
|
+
/**
|
|
24
|
+
* HTTP status code of the error.
|
|
25
|
+
*/
|
|
26
|
+
status: number;
|
|
27
|
+
/**
|
|
28
|
+
* Error code from the API.
|
|
29
|
+
*/
|
|
30
|
+
code: string;
|
|
31
|
+
/**
|
|
32
|
+
* Full response data from the server containing error details.
|
|
33
|
+
*/
|
|
34
|
+
data: any;
|
|
35
|
+
/**
|
|
36
|
+
* The original error object from Axios.
|
|
37
|
+
*/
|
|
38
|
+
originalError: unknown;
|
|
39
|
+
/**
|
|
40
|
+
* Creates a new Base44Error instance.
|
|
41
|
+
*
|
|
42
|
+
* @param message - Human-readable error message
|
|
43
|
+
* @param status - HTTP status code
|
|
44
|
+
* @param code - Error code from the API
|
|
45
|
+
* @param data - Full response data from the server
|
|
46
|
+
* @param originalError - Original axios error object
|
|
47
|
+
* @internal
|
|
48
|
+
*/
|
|
49
|
+
constructor(message: string, status: number, code: string, data: any, originalError: unknown);
|
|
50
|
+
/**
|
|
51
|
+
* Serializes the error to a JSON-safe object.
|
|
52
|
+
*
|
|
53
|
+
* Useful for logging or sending error information to external services
|
|
54
|
+
* without circular reference issues.
|
|
55
|
+
*
|
|
56
|
+
* @returns JSON-safe representation of the error.
|
|
57
|
+
*
|
|
58
|
+
* @example
|
|
59
|
+
* ```typescript
|
|
60
|
+
* try {
|
|
61
|
+
* await client.entities.Todo.get('invalid-id');
|
|
62
|
+
* } catch (error) {
|
|
63
|
+
* if (error instanceof Base44Error) {
|
|
64
|
+
* const json = error.toJSON();
|
|
65
|
+
* console.log(json);
|
|
66
|
+
* // {
|
|
67
|
+
* // name: "Base44Error",
|
|
68
|
+
* // message: "Not found",
|
|
69
|
+
* // status: 404,
|
|
70
|
+
* // code: "NOT_FOUND",
|
|
71
|
+
* // data: { ... }
|
|
72
|
+
* // }
|
|
73
|
+
* }
|
|
74
|
+
* }
|
|
75
|
+
* ```
|
|
76
|
+
*/
|
|
77
|
+
toJSON(): Base44ErrorJSON;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Creates an axios client with default configuration and interceptors.
|
|
81
|
+
*
|
|
82
|
+
* Sets up an axios instance with:
|
|
83
|
+
* - Default headers
|
|
84
|
+
* - Authentication token injection
|
|
85
|
+
* - Response data unwrapping
|
|
86
|
+
* - Error transformation to Base44Error
|
|
87
|
+
* - iframe messaging support
|
|
88
|
+
*
|
|
89
|
+
* @param options - Client configuration options
|
|
90
|
+
* @returns Configured axios instance
|
|
91
|
+
* @internal
|
|
92
|
+
*/
|
|
93
|
+
export declare function createAxiosClient({ baseURL, headers, token, interceptResponses, onError, }: {
|
|
94
|
+
baseURL: string;
|
|
95
|
+
headers?: Record<string, string>;
|
|
96
|
+
token?: string;
|
|
97
|
+
interceptResponses?: boolean;
|
|
98
|
+
onError?: (error: Error) => void;
|
|
99
|
+
}): import("axios").AxiosInstance;
|
|
100
|
+
export type { Base44ErrorJSON } from "./axios-client.types.js";
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
import axios from "axios";
|
|
2
|
+
import { isInIFrame } from "./common.js";
|
|
3
|
+
import { v4 as uuidv4 } from "uuid";
|
|
4
|
+
/**
|
|
5
|
+
* Custom error class for Base44 SDK errors.
|
|
6
|
+
*
|
|
7
|
+
* This error is thrown when API requests fail. It extends the standard `Error` class and includes additional information about the HTTP status, error code, and response data from the server.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* try {
|
|
12
|
+
* await client.entities.Todo.get('invalid-id');
|
|
13
|
+
* } catch (error) {
|
|
14
|
+
* if (error instanceof Base44Error) {
|
|
15
|
+
* console.error('Status:', error.status); // 404
|
|
16
|
+
* console.error('Message:', error.message); // "Not found"
|
|
17
|
+
* console.error('Code:', error.code); // "NOT_FOUND"
|
|
18
|
+
* console.error('Data:', error.data); // Full response data
|
|
19
|
+
* }
|
|
20
|
+
* }
|
|
21
|
+
* ```
|
|
22
|
+
*
|
|
23
|
+
*/
|
|
24
|
+
export class Base44Error extends Error {
|
|
25
|
+
/**
|
|
26
|
+
* Creates a new Base44Error instance.
|
|
27
|
+
*
|
|
28
|
+
* @param message - Human-readable error message
|
|
29
|
+
* @param status - HTTP status code
|
|
30
|
+
* @param code - Error code from the API
|
|
31
|
+
* @param data - Full response data from the server
|
|
32
|
+
* @param originalError - Original axios error object
|
|
33
|
+
* @internal
|
|
34
|
+
*/
|
|
35
|
+
constructor(message, status, code, data, originalError) {
|
|
36
|
+
super(message);
|
|
37
|
+
this.name = "Base44Error";
|
|
38
|
+
this.status = status;
|
|
39
|
+
this.code = code;
|
|
40
|
+
this.data = data;
|
|
41
|
+
this.originalError = originalError;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Serializes the error to a JSON-safe object.
|
|
45
|
+
*
|
|
46
|
+
* Useful for logging or sending error information to external services
|
|
47
|
+
* without circular reference issues.
|
|
48
|
+
*
|
|
49
|
+
* @returns JSON-safe representation of the error.
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* ```typescript
|
|
53
|
+
* try {
|
|
54
|
+
* await client.entities.Todo.get('invalid-id');
|
|
55
|
+
* } catch (error) {
|
|
56
|
+
* if (error instanceof Base44Error) {
|
|
57
|
+
* const json = error.toJSON();
|
|
58
|
+
* console.log(json);
|
|
59
|
+
* // {
|
|
60
|
+
* // name: "Base44Error",
|
|
61
|
+
* // message: "Not found",
|
|
62
|
+
* // status: 404,
|
|
63
|
+
* // code: "NOT_FOUND",
|
|
64
|
+
* // data: { ... }
|
|
65
|
+
* // }
|
|
66
|
+
* }
|
|
67
|
+
* }
|
|
68
|
+
* ```
|
|
69
|
+
*/
|
|
70
|
+
toJSON() {
|
|
71
|
+
return {
|
|
72
|
+
name: this.name,
|
|
73
|
+
message: this.message,
|
|
74
|
+
status: this.status,
|
|
75
|
+
code: this.code,
|
|
76
|
+
data: this.data,
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Safely logs error information without circular references.
|
|
82
|
+
*
|
|
83
|
+
* @param prefix - Prefix for the log message
|
|
84
|
+
* @param error - The error to log
|
|
85
|
+
* @internal
|
|
86
|
+
*/
|
|
87
|
+
function safeErrorLog(prefix, error) {
|
|
88
|
+
if (error instanceof Base44Error) {
|
|
89
|
+
console.error(`${prefix} ${error.status}: ${error.message}`);
|
|
90
|
+
if (error.data) {
|
|
91
|
+
try {
|
|
92
|
+
console.error("Error data:", JSON.stringify(error.data, null, 2));
|
|
93
|
+
}
|
|
94
|
+
catch (e) {
|
|
95
|
+
console.error("Error data: [Cannot stringify error data]");
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
else {
|
|
100
|
+
console.error(`${prefix} ${error instanceof Error ? error.message : String(error)}`);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Creates an axios client with default configuration and interceptors.
|
|
105
|
+
*
|
|
106
|
+
* Sets up an axios instance with:
|
|
107
|
+
* - Default headers
|
|
108
|
+
* - Authentication token injection
|
|
109
|
+
* - Response data unwrapping
|
|
110
|
+
* - Error transformation to Base44Error
|
|
111
|
+
* - iframe messaging support
|
|
112
|
+
*
|
|
113
|
+
* @param options - Client configuration options
|
|
114
|
+
* @returns Configured axios instance
|
|
115
|
+
* @internal
|
|
116
|
+
*/
|
|
117
|
+
export function createAxiosClient({ baseURL, headers = {}, token, interceptResponses = true, onError, }) {
|
|
118
|
+
const client = axios.create({
|
|
119
|
+
baseURL,
|
|
120
|
+
headers: {
|
|
121
|
+
"Content-Type": "application/json",
|
|
122
|
+
Accept: "application/json",
|
|
123
|
+
...headers,
|
|
124
|
+
},
|
|
125
|
+
});
|
|
126
|
+
// Add token to requests if available
|
|
127
|
+
if (token) {
|
|
128
|
+
client.defaults.headers.common["Authorization"] = `Bearer ${token}`;
|
|
129
|
+
}
|
|
130
|
+
// Add origin URL in browser environment
|
|
131
|
+
client.interceptors.request.use((config) => {
|
|
132
|
+
if (typeof window !== "undefined") {
|
|
133
|
+
config.headers.set("X-Origin-URL", window.location.href);
|
|
134
|
+
}
|
|
135
|
+
const requestId = uuidv4();
|
|
136
|
+
config.requestId = requestId;
|
|
137
|
+
if (isInIFrame) {
|
|
138
|
+
try {
|
|
139
|
+
window.parent.postMessage({
|
|
140
|
+
type: "api-request-start",
|
|
141
|
+
requestId,
|
|
142
|
+
data: {
|
|
143
|
+
url: baseURL + config.url,
|
|
144
|
+
method: config.method,
|
|
145
|
+
body: config.data instanceof FormData
|
|
146
|
+
? "[FormData object]"
|
|
147
|
+
: config.data,
|
|
148
|
+
},
|
|
149
|
+
}, "*");
|
|
150
|
+
}
|
|
151
|
+
catch (_a) {
|
|
152
|
+
/* skip the logging */
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
return config;
|
|
156
|
+
});
|
|
157
|
+
// Handle responses
|
|
158
|
+
if (interceptResponses) {
|
|
159
|
+
client.interceptors.response.use((response) => {
|
|
160
|
+
var _a;
|
|
161
|
+
const requestId = (_a = response.config) === null || _a === void 0 ? void 0 : _a.requestId;
|
|
162
|
+
try {
|
|
163
|
+
if (isInIFrame && requestId) {
|
|
164
|
+
window.parent.postMessage({
|
|
165
|
+
type: "api-request-end",
|
|
166
|
+
requestId,
|
|
167
|
+
data: {
|
|
168
|
+
statusCode: response.status,
|
|
169
|
+
response: response.data,
|
|
170
|
+
},
|
|
171
|
+
}, "*");
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
catch (_b) {
|
|
175
|
+
/* do nothing */
|
|
176
|
+
}
|
|
177
|
+
return response.data;
|
|
178
|
+
}, (error) => {
|
|
179
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
180
|
+
const message = ((_b = (_a = error.response) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.message) ||
|
|
181
|
+
((_d = (_c = error.response) === null || _c === void 0 ? void 0 : _c.data) === null || _d === void 0 ? void 0 : _d.detail) ||
|
|
182
|
+
error.message;
|
|
183
|
+
const base44Error = new Base44Error(message, (_e = error.response) === null || _e === void 0 ? void 0 : _e.status, (_g = (_f = error.response) === null || _f === void 0 ? void 0 : _f.data) === null || _g === void 0 ? void 0 : _g.code, (_h = error.response) === null || _h === void 0 ? void 0 : _h.data, error);
|
|
184
|
+
// Log errors in development
|
|
185
|
+
if (process.env.NODE_ENV !== "production") {
|
|
186
|
+
safeErrorLog("[Base44 SDK Error]", base44Error);
|
|
187
|
+
}
|
|
188
|
+
onError === null || onError === void 0 ? void 0 : onError(base44Error);
|
|
189
|
+
return Promise.reject(base44Error);
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
return client;
|
|
193
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* JSON representation of a Base44Error.
|
|
3
|
+
*
|
|
4
|
+
* This is the structure returned by {@linkcode Base44Error.toJSON | Base44Error.toJSON()}.
|
|
5
|
+
* Useful for logging or sending error information to external services.
|
|
6
|
+
*/
|
|
7
|
+
export interface Base44ErrorJSON {
|
|
8
|
+
/**
|
|
9
|
+
* The error name, always "Base44Error".
|
|
10
|
+
*/
|
|
11
|
+
name: string;
|
|
12
|
+
/**
|
|
13
|
+
* Human-readable error message.
|
|
14
|
+
*/
|
|
15
|
+
message: string;
|
|
16
|
+
/**
|
|
17
|
+
* HTTP status code of the error.
|
|
18
|
+
*/
|
|
19
|
+
status: number;
|
|
20
|
+
/**
|
|
21
|
+
* Error code from the API.
|
|
22
|
+
*/
|
|
23
|
+
code: string;
|
|
24
|
+
/**
|
|
25
|
+
* Full response data from the server containing error details.
|
|
26
|
+
*/
|
|
27
|
+
data: any;
|
|
28
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function getSharedInstance<T>(name: string, factory: () => T): T;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
const windowObj = typeof window !== "undefined"
|
|
2
|
+
? window
|
|
3
|
+
: { base44SharedInstances: {} };
|
|
4
|
+
// Singleton (shared between sdk instances)//
|
|
5
|
+
export function getSharedInstance(name, factory) {
|
|
6
|
+
if (!windowObj.base44SharedInstances) {
|
|
7
|
+
windowObj.base44SharedInstances = {};
|
|
8
|
+
}
|
|
9
|
+
if (!windowObj.base44SharedInstances[name]) {
|
|
10
|
+
windowObj.base44SharedInstances[name] = {
|
|
11
|
+
instance: factory(),
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
return windowObj.base44SharedInstances[name].instance;
|
|
15
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { Socket } from "socket.io-client";
|
|
2
|
+
export interface RoomsSocketConfig {
|
|
3
|
+
serverUrl: string;
|
|
4
|
+
mountPath: string;
|
|
5
|
+
transports: string[];
|
|
6
|
+
appId: string;
|
|
7
|
+
token?: string;
|
|
8
|
+
}
|
|
9
|
+
export type TSocketRoom = string;
|
|
10
|
+
export type TJsonStr = string;
|
|
11
|
+
type RoomsSocketEventsMap = {
|
|
12
|
+
listen: {
|
|
13
|
+
connect: () => Promise<void> | void;
|
|
14
|
+
update_model: (msg: {
|
|
15
|
+
room: string;
|
|
16
|
+
data: TJsonStr;
|
|
17
|
+
}) => Promise<void> | void;
|
|
18
|
+
error: (error: Error) => Promise<void> | void;
|
|
19
|
+
};
|
|
20
|
+
emit: {
|
|
21
|
+
join: (room: string) => void;
|
|
22
|
+
leave: (room: string) => void;
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
type TEvent = keyof RoomsSocketEventsMap["listen"];
|
|
26
|
+
type THandler<E extends TEvent> = RoomsSocketEventsMap["listen"][E];
|
|
27
|
+
export type RoomsSocket = ReturnType<typeof RoomsSocket>;
|
|
28
|
+
export declare function RoomsSocket({ config }: {
|
|
29
|
+
config: RoomsSocketConfig;
|
|
30
|
+
}): {
|
|
31
|
+
socket: Socket<{
|
|
32
|
+
connect: () => Promise<void> | void;
|
|
33
|
+
update_model: (msg: {
|
|
34
|
+
room: string;
|
|
35
|
+
data: TJsonStr;
|
|
36
|
+
}) => Promise<void> | void;
|
|
37
|
+
error: (error: Error) => Promise<void> | void;
|
|
38
|
+
}, {
|
|
39
|
+
join: (room: string) => void;
|
|
40
|
+
leave: (room: string) => void;
|
|
41
|
+
}>;
|
|
42
|
+
subscribeToRoom: (room: TSocketRoom, handlers: Partial<{ [k in TEvent]: THandler<k>; }>) => () => void;
|
|
43
|
+
updateConfig: (config: Partial<RoomsSocketConfig>) => void;
|
|
44
|
+
updateModel: (room: string, data: any) => Promise<void>;
|
|
45
|
+
disconnect: () => void;
|
|
46
|
+
};
|
|
47
|
+
export {};
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { io } from "socket.io-client";
|
|
2
|
+
import { getAccessToken } from "./auth-utils.js";
|
|
3
|
+
function initializeSocket(config, handlers) {
|
|
4
|
+
var _a;
|
|
5
|
+
const socket = io(config.serverUrl, {
|
|
6
|
+
path: config.mountPath,
|
|
7
|
+
transports: config.transports,
|
|
8
|
+
query: {
|
|
9
|
+
app_id: config.appId,
|
|
10
|
+
token: (_a = config.token) !== null && _a !== void 0 ? _a : getAccessToken(),
|
|
11
|
+
},
|
|
12
|
+
});
|
|
13
|
+
socket.on("connect", async () => {
|
|
14
|
+
var _a;
|
|
15
|
+
console.log("connect", socket.id);
|
|
16
|
+
return (_a = handlers.connect) === null || _a === void 0 ? void 0 : _a.call(handlers);
|
|
17
|
+
});
|
|
18
|
+
socket.on("update_model", async (msg) => {
|
|
19
|
+
var _a;
|
|
20
|
+
return (_a = handlers.update_model) === null || _a === void 0 ? void 0 : _a.call(handlers, msg);
|
|
21
|
+
});
|
|
22
|
+
socket.on("error", async (error) => {
|
|
23
|
+
var _a;
|
|
24
|
+
return (_a = handlers.error) === null || _a === void 0 ? void 0 : _a.call(handlers, error);
|
|
25
|
+
});
|
|
26
|
+
socket.on("connect_error", async (error) => {
|
|
27
|
+
var _a;
|
|
28
|
+
console.error("connect_error", error);
|
|
29
|
+
return (_a = handlers.error) === null || _a === void 0 ? void 0 : _a.call(handlers, error);
|
|
30
|
+
});
|
|
31
|
+
return socket;
|
|
32
|
+
}
|
|
33
|
+
export function RoomsSocket({ config }) {
|
|
34
|
+
let currentConfig = { ...config };
|
|
35
|
+
const roomsToListeners = {};
|
|
36
|
+
const handlers = {
|
|
37
|
+
connect: async () => {
|
|
38
|
+
const promises = [];
|
|
39
|
+
Object.keys(roomsToListeners).forEach((room) => {
|
|
40
|
+
joinRoom(room);
|
|
41
|
+
const listeners = getListeners(room);
|
|
42
|
+
listeners === null || listeners === void 0 ? void 0 : listeners.forEach(({ connect }) => {
|
|
43
|
+
const promise = async () => connect === null || connect === void 0 ? void 0 : connect();
|
|
44
|
+
promises.push(promise());
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
await Promise.all(promises);
|
|
48
|
+
},
|
|
49
|
+
update_model: async (msg) => {
|
|
50
|
+
const listeners = getListeners(msg.room);
|
|
51
|
+
const promises = listeners.map((listener) => { var _a; return (_a = listener.update_model) === null || _a === void 0 ? void 0 : _a.call(listener, msg); });
|
|
52
|
+
await Promise.all(promises);
|
|
53
|
+
},
|
|
54
|
+
error: async (error) => {
|
|
55
|
+
console.error("error", 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);
|
|
60
|
+
},
|
|
61
|
+
};
|
|
62
|
+
let socket = initializeSocket(config, handlers);
|
|
63
|
+
function cleanup() {
|
|
64
|
+
disconnect();
|
|
65
|
+
}
|
|
66
|
+
function disconnect() {
|
|
67
|
+
if (socket) {
|
|
68
|
+
socket.disconnect();
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
function updateConfig(config) {
|
|
72
|
+
cleanup();
|
|
73
|
+
currentConfig = {
|
|
74
|
+
...currentConfig,
|
|
75
|
+
...config,
|
|
76
|
+
};
|
|
77
|
+
socket = initializeSocket(currentConfig, handlers);
|
|
78
|
+
}
|
|
79
|
+
function joinRoom(room) {
|
|
80
|
+
socket.emit("join", room);
|
|
81
|
+
}
|
|
82
|
+
function leaveRoom(room) {
|
|
83
|
+
socket.emit("leave", room);
|
|
84
|
+
}
|
|
85
|
+
async function updateModel(room, data) {
|
|
86
|
+
var _a;
|
|
87
|
+
const dataStr = JSON.stringify(data);
|
|
88
|
+
return (_a = handlers.update_model) === null || _a === void 0 ? void 0 : _a.call(handlers, { room, data: dataStr });
|
|
89
|
+
}
|
|
90
|
+
function getListeners(room) {
|
|
91
|
+
return roomsToListeners[room];
|
|
92
|
+
}
|
|
93
|
+
const subscribeToRoom = (room, handlers) => {
|
|
94
|
+
if (!roomsToListeners[room]) {
|
|
95
|
+
joinRoom(room);
|
|
96
|
+
roomsToListeners[room] = [];
|
|
97
|
+
}
|
|
98
|
+
roomsToListeners[room].push(handlers);
|
|
99
|
+
return () => {
|
|
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
|
+
}
|
|
106
|
+
};
|
|
107
|
+
};
|
|
108
|
+
return {
|
|
109
|
+
socket,
|
|
110
|
+
subscribeToRoom,
|
|
111
|
+
updateConfig,
|
|
112
|
+
updateModel,
|
|
113
|
+
disconnect,
|
|
114
|
+
};
|
|
115
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@depup/base44__sdk",
|
|
3
|
+
"version": "0.8.22-depup.0",
|
|
4
|
+
"description": "[DepUp] JavaScript SDK for Base44 API",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"files": [
|
|
9
|
+
"dist",
|
|
10
|
+
"changes.json",
|
|
11
|
+
"README.md"
|
|
12
|
+
],
|
|
13
|
+
"scripts": {
|
|
14
|
+
"build": "tsc",
|
|
15
|
+
"lint": "eslint src",
|
|
16
|
+
"test": "vitest run",
|
|
17
|
+
"test:unit": "vitest run tests/unit",
|
|
18
|
+
"test:e2e": "vitest run tests/e2e",
|
|
19
|
+
"test:watch": "vitest",
|
|
20
|
+
"test:coverage": "vitest run --coverage",
|
|
21
|
+
"docs": "typedoc",
|
|
22
|
+
"create-docs": "npm run create-docs:generate && npm run create-docs:process",
|
|
23
|
+
"create-docs-local": "npm run create-docs && npm run copy-docs-local",
|
|
24
|
+
"copy-docs-local": "node scripts/mintlify-post-processing/copy-to-local-docs.js",
|
|
25
|
+
"create-docs:generate": "typedoc",
|
|
26
|
+
"create-docs:process": "node scripts/mintlify-post-processing/file-processing/file-processing.js"
|
|
27
|
+
},
|
|
28
|
+
"dependencies": {
|
|
29
|
+
"axios": "^1.13.6",
|
|
30
|
+
"socket.io-client": "^4.8.3",
|
|
31
|
+
"uuid": "^13.0.0"
|
|
32
|
+
},
|
|
33
|
+
"devDependencies": {
|
|
34
|
+
"@types/hast": "^3.0.4",
|
|
35
|
+
"@types/node": "^25.0.1",
|
|
36
|
+
"@types/unist": "^3.0.3",
|
|
37
|
+
"@typescript-eslint/parser": "^8.51.0",
|
|
38
|
+
"@vitest/coverage-istanbul": "^1.0.0",
|
|
39
|
+
"@vitest/coverage-v8": "^1.0.0",
|
|
40
|
+
"@vitest/ui": "^1.0.0",
|
|
41
|
+
"dotenv": "^16.3.1",
|
|
42
|
+
"eslint": "^9.39.2",
|
|
43
|
+
"eslint-plugin-import": "^2.32.0",
|
|
44
|
+
"nock": "^13.4.0",
|
|
45
|
+
"typedoc": "^0.28.14",
|
|
46
|
+
"typedoc-plugin-markdown": "^4.9.0",
|
|
47
|
+
"typescript": "^5.3.2",
|
|
48
|
+
"typescript-eslint": "^8.51.0",
|
|
49
|
+
"vitest": "^1.6.1"
|
|
50
|
+
},
|
|
51
|
+
"keywords": [
|
|
52
|
+
"depup",
|
|
53
|
+
"dependency-bumped",
|
|
54
|
+
"updated-deps",
|
|
55
|
+
"@base44/sdk",
|
|
56
|
+
"base44",
|
|
57
|
+
"api",
|
|
58
|
+
"sdk"
|
|
59
|
+
],
|
|
60
|
+
"author": "Base44",
|
|
61
|
+
"license": "MIT",
|
|
62
|
+
"repository": {
|
|
63
|
+
"type": "git",
|
|
64
|
+
"url": "git+https://github.com/base44/javascript-sdk.git"
|
|
65
|
+
},
|
|
66
|
+
"bugs": {
|
|
67
|
+
"url": "https://github.com/base44/javascript-sdk/issues"
|
|
68
|
+
},
|
|
69
|
+
"homepage": "https://github.com/base44/javascript-sdk#readme",
|
|
70
|
+
"depup": {
|
|
71
|
+
"changes": {
|
|
72
|
+
"axios": {
|
|
73
|
+
"from": "^1.6.2",
|
|
74
|
+
"to": "^1.13.6"
|
|
75
|
+
},
|
|
76
|
+
"socket.io-client": {
|
|
77
|
+
"from": "^4.7.5",
|
|
78
|
+
"to": "^4.8.3"
|
|
79
|
+
}
|
|
80
|
+
},
|
|
81
|
+
"depsUpdated": 2,
|
|
82
|
+
"originalPackage": "@base44/sdk",
|
|
83
|
+
"originalVersion": "0.8.22",
|
|
84
|
+
"processedAt": "2026-03-17T16:31:07.030Z",
|
|
85
|
+
"smokeTest": "passed"
|
|
86
|
+
}
|
|
87
|
+
}
|