@base44/sdk 0.7.1 → 0.7.4
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 +99 -0
- package/dist/client.js +61 -13
- package/dist/index.d.ts +3 -1
- package/dist/index.js +1 -0
- package/dist/modules/agents.d.ts +20 -0
- package/dist/modules/agents.js +43 -0
- package/dist/modules/agents.types.d.ts +44 -0
- package/dist/modules/agents.types.js +1 -0
- package/dist/modules/app.types.d.ts +115 -0
- package/dist/modules/app.types.js +1 -0
- package/dist/modules/auth.d.ts +26 -1
- package/dist/modules/auth.js +43 -2
- package/dist/modules/types.d.ts +2 -0
- package/dist/modules/types.js +2 -0
- package/dist/types.d.ts +9 -0
- package/dist/types.js +1 -0
- package/dist/utils/axios-client.d.ts +3 -1
- package/dist/utils/axios-client.js +5 -2
- package/dist/utils/socket-utils.d.ts +47 -0
- package/dist/utils/socket-utils.js +115 -0
- package/package.json +3 -2
package/dist/client.d.ts
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
export type CreateClientOptions = {
|
|
2
|
+
onError?: (error: Error) => void;
|
|
3
|
+
};
|
|
4
|
+
export type Base44Client = ReturnType<typeof createClient>;
|
|
1
5
|
/**
|
|
2
6
|
* Create a Base44 client instance
|
|
3
7
|
* @param {Object} config - Client configuration
|
|
@@ -15,6 +19,9 @@ export declare function createClient(config: {
|
|
|
15
19
|
serviceToken?: string;
|
|
16
20
|
requiresAuth?: boolean;
|
|
17
21
|
functionsVersion?: string;
|
|
22
|
+
headers?: Record<string, string>;
|
|
23
|
+
options?: CreateClientOptions;
|
|
24
|
+
onRedirectToLogin?: () => void;
|
|
18
25
|
}): {
|
|
19
26
|
/**
|
|
20
27
|
* Set authentication token for all requests
|
|
@@ -39,6 +46,18 @@ export declare function createClient(config: {
|
|
|
39
46
|
functions: {
|
|
40
47
|
invoke(functionName: string, data: Record<string, any>): Promise<import("axios").AxiosResponse<any, any>>;
|
|
41
48
|
};
|
|
49
|
+
agents: {
|
|
50
|
+
getConversations: () => Promise<import("./types.js").AgentConversation[]>;
|
|
51
|
+
getConversation: (conversationId: string) => Promise<import("./types.js").AgentConversation | undefined>;
|
|
52
|
+
listConversations: (filterParams: import("./types.js").ModelFilterParams) => Promise<import("./types.js").AgentConversation[]>;
|
|
53
|
+
createConversation: (conversation: {
|
|
54
|
+
agent_name: string;
|
|
55
|
+
metadata?: Record<string, any>;
|
|
56
|
+
}) => Promise<import("./types.js").AgentConversation>;
|
|
57
|
+
addMessage: (conversation: import("./types.js").AgentConversation, message: import("./types.js").AgentMessage) => Promise<import("./types.js").AgentMessage>;
|
|
58
|
+
subscribeToConversation: (conversationId: string, onUpdate?: (conversation: import("./types.js").AgentConversation) => void) => () => void;
|
|
59
|
+
};
|
|
60
|
+
cleanup: () => void;
|
|
42
61
|
};
|
|
43
62
|
entities: {};
|
|
44
63
|
integrations: {};
|
|
@@ -53,10 +72,44 @@ export declare function createClient(config: {
|
|
|
53
72
|
user: any;
|
|
54
73
|
}>;
|
|
55
74
|
isAuthenticated(): Promise<boolean>;
|
|
75
|
+
inviteUser(userEmail: string, role: string): Promise<import("axios").AxiosResponse<any, any>>;
|
|
76
|
+
register(payload: {
|
|
77
|
+
email: string;
|
|
78
|
+
password: string;
|
|
79
|
+
turnstile_token?: string | null;
|
|
80
|
+
referral_code?: string | null;
|
|
81
|
+
}): Promise<import("axios").AxiosResponse<any, any>>;
|
|
82
|
+
verifyOtp({ email, otpCode }: {
|
|
83
|
+
email: string;
|
|
84
|
+
otpCode: string;
|
|
85
|
+
}): Promise<import("axios").AxiosResponse<any, any>>;
|
|
86
|
+
resendOtp(email: string): Promise<import("axios").AxiosResponse<any, any>>;
|
|
87
|
+
resetPasswordRequest(email: string): Promise<import("axios").AxiosResponse<any, any>>;
|
|
88
|
+
resetPassword({ resetToken, newPassword, }: {
|
|
89
|
+
resetToken: string;
|
|
90
|
+
newPassword: string;
|
|
91
|
+
}): Promise<import("axios").AxiosResponse<any, any>>;
|
|
92
|
+
changePassword({ userId, currentPassword, newPassword, }: {
|
|
93
|
+
userId: string;
|
|
94
|
+
currentPassword: string;
|
|
95
|
+
newPassword: string;
|
|
96
|
+
}): Promise<import("axios").AxiosResponse<any, any>>;
|
|
56
97
|
};
|
|
57
98
|
functions: {
|
|
58
99
|
invoke(functionName: string, data: Record<string, any>): Promise<import("axios").AxiosResponse<any, any>>;
|
|
59
100
|
};
|
|
101
|
+
agents: {
|
|
102
|
+
getConversations: () => Promise<import("./types.js").AgentConversation[]>;
|
|
103
|
+
getConversation: (conversationId: string) => Promise<import("./types.js").AgentConversation | undefined>;
|
|
104
|
+
listConversations: (filterParams: import("./types.js").ModelFilterParams) => Promise<import("./types.js").AgentConversation[]>;
|
|
105
|
+
createConversation: (conversation: {
|
|
106
|
+
agent_name: string;
|
|
107
|
+
metadata?: Record<string, any>;
|
|
108
|
+
}) => Promise<import("./types.js").AgentConversation>;
|
|
109
|
+
addMessage: (conversation: import("./types.js").AgentConversation, message: import("./types.js").AgentMessage) => Promise<import("./types.js").AgentMessage>;
|
|
110
|
+
subscribeToConversation: (conversationId: string, onUpdate?: (conversation: import("./types.js").AgentConversation) => void) => () => void;
|
|
111
|
+
};
|
|
112
|
+
cleanup: () => void;
|
|
60
113
|
};
|
|
61
114
|
export declare function createClientFromRequest(request: Request): {
|
|
62
115
|
/**
|
|
@@ -82,6 +135,18 @@ export declare function createClientFromRequest(request: Request): {
|
|
|
82
135
|
functions: {
|
|
83
136
|
invoke(functionName: string, data: Record<string, any>): Promise<import("axios").AxiosResponse<any, any>>;
|
|
84
137
|
};
|
|
138
|
+
agents: {
|
|
139
|
+
getConversations: () => Promise<import("./types.js").AgentConversation[]>;
|
|
140
|
+
getConversation: (conversationId: string) => Promise<import("./types.js").AgentConversation | undefined>;
|
|
141
|
+
listConversations: (filterParams: import("./types.js").ModelFilterParams) => Promise<import("./types.js").AgentConversation[]>;
|
|
142
|
+
createConversation: (conversation: {
|
|
143
|
+
agent_name: string;
|
|
144
|
+
metadata?: Record<string, any>;
|
|
145
|
+
}) => Promise<import("./types.js").AgentConversation>;
|
|
146
|
+
addMessage: (conversation: import("./types.js").AgentConversation, message: import("./types.js").AgentMessage) => Promise<import("./types.js").AgentMessage>;
|
|
147
|
+
subscribeToConversation: (conversationId: string, onUpdate?: (conversation: import("./types.js").AgentConversation) => void) => () => void;
|
|
148
|
+
};
|
|
149
|
+
cleanup: () => void;
|
|
85
150
|
};
|
|
86
151
|
entities: {};
|
|
87
152
|
integrations: {};
|
|
@@ -96,8 +161,42 @@ export declare function createClientFromRequest(request: Request): {
|
|
|
96
161
|
user: any;
|
|
97
162
|
}>;
|
|
98
163
|
isAuthenticated(): Promise<boolean>;
|
|
164
|
+
inviteUser(userEmail: string, role: string): Promise<import("axios").AxiosResponse<any, any>>;
|
|
165
|
+
register(payload: {
|
|
166
|
+
email: string;
|
|
167
|
+
password: string;
|
|
168
|
+
turnstile_token?: string | null;
|
|
169
|
+
referral_code?: string | null;
|
|
170
|
+
}): Promise<import("axios").AxiosResponse<any, any>>;
|
|
171
|
+
verifyOtp({ email, otpCode }: {
|
|
172
|
+
email: string;
|
|
173
|
+
otpCode: string;
|
|
174
|
+
}): Promise<import("axios").AxiosResponse<any, any>>;
|
|
175
|
+
resendOtp(email: string): Promise<import("axios").AxiosResponse<any, any>>;
|
|
176
|
+
resetPasswordRequest(email: string): Promise<import("axios").AxiosResponse<any, any>>;
|
|
177
|
+
resetPassword({ resetToken, newPassword, }: {
|
|
178
|
+
resetToken: string;
|
|
179
|
+
newPassword: string;
|
|
180
|
+
}): Promise<import("axios").AxiosResponse<any, any>>;
|
|
181
|
+
changePassword({ userId, currentPassword, newPassword, }: {
|
|
182
|
+
userId: string;
|
|
183
|
+
currentPassword: string;
|
|
184
|
+
newPassword: string;
|
|
185
|
+
}): Promise<import("axios").AxiosResponse<any, any>>;
|
|
99
186
|
};
|
|
100
187
|
functions: {
|
|
101
188
|
invoke(functionName: string, data: Record<string, any>): Promise<import("axios").AxiosResponse<any, any>>;
|
|
102
189
|
};
|
|
190
|
+
agents: {
|
|
191
|
+
getConversations: () => Promise<import("./types.js").AgentConversation[]>;
|
|
192
|
+
getConversation: (conversationId: string) => Promise<import("./types.js").AgentConversation | undefined>;
|
|
193
|
+
listConversations: (filterParams: import("./types.js").ModelFilterParams) => Promise<import("./types.js").AgentConversation[]>;
|
|
194
|
+
createConversation: (conversation: {
|
|
195
|
+
agent_name: string;
|
|
196
|
+
metadata?: Record<string, any>;
|
|
197
|
+
}) => Promise<import("./types.js").AgentConversation>;
|
|
198
|
+
addMessage: (conversation: import("./types.js").AgentConversation, message: import("./types.js").AgentMessage) => Promise<import("./types.js").AgentMessage>;
|
|
199
|
+
subscribeToConversation: (conversationId: string, onUpdate?: (conversation: import("./types.js").AgentConversation) => void) => () => void;
|
|
200
|
+
};
|
|
201
|
+
cleanup: () => void;
|
|
103
202
|
};
|
package/dist/client.js
CHANGED
|
@@ -5,6 +5,8 @@ import { createAuthModule } from "./modules/auth.js";
|
|
|
5
5
|
import { createSsoModule } from "./modules/sso.js";
|
|
6
6
|
import { getAccessToken } from "./utils/auth-utils.js";
|
|
7
7
|
import { createFunctionsModule } from "./modules/functions.js";
|
|
8
|
+
import { createAgentsModule } from "./modules/agents.js";
|
|
9
|
+
import { RoomsSocket } from "./utils/socket-utils.js";
|
|
8
10
|
/**
|
|
9
11
|
* Create a Base44 client instance
|
|
10
12
|
* @param {Object} config - Client configuration
|
|
@@ -16,14 +18,27 @@ import { createFunctionsModule } from "./modules/functions.js";
|
|
|
16
18
|
* @returns {Object} Base44 client instance
|
|
17
19
|
*/
|
|
18
20
|
export function createClient(config) {
|
|
19
|
-
const { serverUrl = "https://base44.app", appId, token, serviceToken, requiresAuth = false, functionsVersion } = config;
|
|
21
|
+
const { serverUrl = "https://base44.app", appId, token, serviceToken, requiresAuth = false, options, functionsVersion, onRedirectToLogin, headers: optionalHeaders, } = config;
|
|
22
|
+
const socketConfig = {
|
|
23
|
+
serverUrl,
|
|
24
|
+
mountPath: "/ws-user-apps/socket.io/",
|
|
25
|
+
transports: ["websocket"],
|
|
26
|
+
appId,
|
|
27
|
+
token,
|
|
28
|
+
};
|
|
29
|
+
const socket = RoomsSocket({
|
|
30
|
+
config: socketConfig,
|
|
31
|
+
});
|
|
20
32
|
const headers = {
|
|
33
|
+
...optionalHeaders,
|
|
21
34
|
"X-App-Id": String(appId),
|
|
22
35
|
};
|
|
23
|
-
const functionHeaders = functionsVersion
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
36
|
+
const functionHeaders = functionsVersion
|
|
37
|
+
? {
|
|
38
|
+
...headers,
|
|
39
|
+
"Base44-Functions-Version": functionsVersion,
|
|
40
|
+
}
|
|
41
|
+
: headers;
|
|
27
42
|
const axiosClient = createAxiosClient({
|
|
28
43
|
baseURL: `${serverUrl}/api`,
|
|
29
44
|
headers,
|
|
@@ -31,6 +46,8 @@ export function createClient(config) {
|
|
|
31
46
|
requiresAuth,
|
|
32
47
|
appId,
|
|
33
48
|
serverUrl,
|
|
49
|
+
onError: options === null || options === void 0 ? void 0 : options.onError,
|
|
50
|
+
onRedirectToLogin,
|
|
34
51
|
});
|
|
35
52
|
const functionsAxiosClient = createAxiosClient({
|
|
36
53
|
baseURL: `${serverUrl}/api`,
|
|
@@ -40,6 +57,8 @@ export function createClient(config) {
|
|
|
40
57
|
appId,
|
|
41
58
|
serverUrl,
|
|
42
59
|
interceptResponses: false,
|
|
60
|
+
onError: options === null || options === void 0 ? void 0 : options.onError,
|
|
61
|
+
onRedirectToLogin,
|
|
43
62
|
});
|
|
44
63
|
const serviceRoleAxiosClient = createAxiosClient({
|
|
45
64
|
baseURL: `${serverUrl}/api`,
|
|
@@ -47,6 +66,8 @@ export function createClient(config) {
|
|
|
47
66
|
token: serviceToken,
|
|
48
67
|
serverUrl,
|
|
49
68
|
appId,
|
|
69
|
+
onError: options === null || options === void 0 ? void 0 : options.onError,
|
|
70
|
+
onRedirectToLogin,
|
|
50
71
|
});
|
|
51
72
|
const serviceRoleFunctionsAxiosClient = createAxiosClient({
|
|
52
73
|
baseURL: `${serverUrl}/api`,
|
|
@@ -55,18 +76,38 @@ export function createClient(config) {
|
|
|
55
76
|
serverUrl,
|
|
56
77
|
appId,
|
|
57
78
|
interceptResponses: false,
|
|
79
|
+
onRedirectToLogin,
|
|
58
80
|
});
|
|
59
81
|
const userModules = {
|
|
60
82
|
entities: createEntitiesModule(axiosClient, appId),
|
|
61
83
|
integrations: createIntegrationsModule(axiosClient, appId),
|
|
62
|
-
auth: createAuthModule(axiosClient, functionsAxiosClient, appId
|
|
84
|
+
auth: createAuthModule(axiosClient, functionsAxiosClient, appId, {
|
|
85
|
+
onRedirectToLogin,
|
|
86
|
+
serverUrl,
|
|
87
|
+
}),
|
|
63
88
|
functions: createFunctionsModule(functionsAxiosClient, appId),
|
|
89
|
+
agents: createAgentsModule({
|
|
90
|
+
axios: axiosClient,
|
|
91
|
+
socket,
|
|
92
|
+
appId,
|
|
93
|
+
}),
|
|
94
|
+
cleanup: () => {
|
|
95
|
+
socket.disconnect();
|
|
96
|
+
},
|
|
64
97
|
};
|
|
65
98
|
const serviceRoleModules = {
|
|
66
99
|
entities: createEntitiesModule(serviceRoleAxiosClient, appId),
|
|
67
100
|
integrations: createIntegrationsModule(serviceRoleAxiosClient, appId),
|
|
68
101
|
sso: createSsoModule(serviceRoleAxiosClient, appId, token),
|
|
69
102
|
functions: createFunctionsModule(serviceRoleFunctionsAxiosClient, appId),
|
|
103
|
+
agents: createAgentsModule({
|
|
104
|
+
axios: serviceRoleAxiosClient,
|
|
105
|
+
socket,
|
|
106
|
+
appId,
|
|
107
|
+
}),
|
|
108
|
+
cleanup: () => {
|
|
109
|
+
socket.disconnect();
|
|
110
|
+
},
|
|
70
111
|
};
|
|
71
112
|
// Always try to get token from localStorage or URL parameters
|
|
72
113
|
if (typeof window !== "undefined") {
|
|
@@ -101,6 +142,9 @@ export function createClient(config) {
|
|
|
101
142
|
*/
|
|
102
143
|
setToken(newToken) {
|
|
103
144
|
userModules.auth.setToken(newToken);
|
|
145
|
+
socket.updateConfig({
|
|
146
|
+
token: newToken,
|
|
147
|
+
});
|
|
104
148
|
},
|
|
105
149
|
/**
|
|
106
150
|
* Get current configuration
|
|
@@ -119,10 +163,10 @@ export function createClient(config) {
|
|
|
119
163
|
*/
|
|
120
164
|
get asServiceRole() {
|
|
121
165
|
if (!serviceToken) {
|
|
122
|
-
throw new Error(
|
|
166
|
+
throw new Error("Service token is required to use asServiceRole. Please provide a serviceToken when creating the client.");
|
|
123
167
|
}
|
|
124
168
|
return serviceRoleModules;
|
|
125
|
-
}
|
|
169
|
+
},
|
|
126
170
|
};
|
|
127
171
|
return client;
|
|
128
172
|
}
|
|
@@ -139,22 +183,26 @@ export function createClientFromRequest(request) {
|
|
|
139
183
|
let serviceRoleToken;
|
|
140
184
|
let userToken;
|
|
141
185
|
if (serviceRoleAuthHeader !== null) {
|
|
142
|
-
if (serviceRoleAuthHeader ===
|
|
186
|
+
if (serviceRoleAuthHeader === "" ||
|
|
187
|
+
!serviceRoleAuthHeader.startsWith("Bearer ") ||
|
|
188
|
+
serviceRoleAuthHeader.split(" ").length !== 2) {
|
|
143
189
|
throw new Error('Invalid authorization header format. Expected "Bearer <token>"');
|
|
144
190
|
}
|
|
145
|
-
serviceRoleToken = serviceRoleAuthHeader.split(
|
|
191
|
+
serviceRoleToken = serviceRoleAuthHeader.split(" ")[1];
|
|
146
192
|
}
|
|
147
193
|
if (authHeader !== null) {
|
|
148
|
-
if (authHeader ===
|
|
194
|
+
if (authHeader === "" ||
|
|
195
|
+
!authHeader.startsWith("Bearer ") ||
|
|
196
|
+
authHeader.split(" ").length !== 2) {
|
|
149
197
|
throw new Error('Invalid authorization header format. Expected "Bearer <token>"');
|
|
150
198
|
}
|
|
151
|
-
userToken = authHeader.split(
|
|
199
|
+
userToken = authHeader.split(" ")[1];
|
|
152
200
|
}
|
|
153
201
|
return createClient({
|
|
154
202
|
serverUrl: serverUrlHeader || "https://base44.app",
|
|
155
203
|
appId,
|
|
156
204
|
token: userToken,
|
|
157
205
|
serviceToken: serviceRoleToken,
|
|
158
|
-
functionsVersion: functionsVersion !== null && functionsVersion !== void 0 ? functionsVersion : undefined
|
|
206
|
+
functionsVersion: functionsVersion !== null && functionsVersion !== void 0 ? functionsVersion : undefined,
|
|
159
207
|
});
|
|
160
208
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import { createClient, createClientFromRequest } 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 { Base44Client };
|
|
6
|
+
export * from "./types.js";
|
package/dist/index.js
CHANGED
|
@@ -2,3 +2,4 @@ import { createClient, createClientFromRequest } 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 * from "./types.js";
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { RoomsSocket } from "../utils/socket-utils.js";
|
|
2
|
+
import { AgentConversation, AgentMessage } from "./agents.types.js";
|
|
3
|
+
import { AxiosInstance } from "axios";
|
|
4
|
+
import { ModelFilterParams } from "../types.js";
|
|
5
|
+
export type AgentsModuleConfig = {
|
|
6
|
+
axios: AxiosInstance;
|
|
7
|
+
socket: ReturnType<typeof RoomsSocket>;
|
|
8
|
+
appId: string;
|
|
9
|
+
};
|
|
10
|
+
export declare function createAgentsModule({ axios, socket, appId, }: AgentsModuleConfig): {
|
|
11
|
+
getConversations: () => Promise<AgentConversation[]>;
|
|
12
|
+
getConversation: (conversationId: string) => Promise<AgentConversation | undefined>;
|
|
13
|
+
listConversations: (filterParams: ModelFilterParams) => Promise<AgentConversation[]>;
|
|
14
|
+
createConversation: (conversation: {
|
|
15
|
+
agent_name: string;
|
|
16
|
+
metadata?: Record<string, any>;
|
|
17
|
+
}) => Promise<AgentConversation>;
|
|
18
|
+
addMessage: (conversation: AgentConversation, message: AgentMessage) => Promise<AgentMessage>;
|
|
19
|
+
subscribeToConversation: (conversationId: string, onUpdate?: (conversation: AgentConversation) => void) => () => void;
|
|
20
|
+
};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
export function createAgentsModule({ axios, socket, appId, }) {
|
|
2
|
+
const baseURL = `/apps/${appId}/agents`;
|
|
3
|
+
const getConversations = () => {
|
|
4
|
+
return axios.get(`${baseURL}/conversations`);
|
|
5
|
+
};
|
|
6
|
+
const getConversation = (conversationId) => {
|
|
7
|
+
return axios.get(`${baseURL}/conversations/${conversationId}`);
|
|
8
|
+
};
|
|
9
|
+
const listConversations = (filterParams) => {
|
|
10
|
+
return axios.get(`${baseURL}/conversations`, {
|
|
11
|
+
params: filterParams,
|
|
12
|
+
});
|
|
13
|
+
};
|
|
14
|
+
const createConversation = (conversation) => {
|
|
15
|
+
return axios.post(`${baseURL}/conversations`, conversation);
|
|
16
|
+
};
|
|
17
|
+
const addMessage = async (conversation, message) => {
|
|
18
|
+
const room = `/agent-conversations/${conversation.id}`;
|
|
19
|
+
await socket.updateModel(room, {
|
|
20
|
+
...conversation,
|
|
21
|
+
messages: [...(conversation.messages || []), message],
|
|
22
|
+
});
|
|
23
|
+
return axios.post(`${baseURL}/conversations/${conversation.id}/messages`, message);
|
|
24
|
+
};
|
|
25
|
+
const subscribeToConversation = (conversationId, onUpdate) => {
|
|
26
|
+
const room = `/agent-conversations/${conversationId}`;
|
|
27
|
+
return socket.subscribeToRoom(room, {
|
|
28
|
+
connect: () => { },
|
|
29
|
+
update_model: ({ data: jsonStr }) => {
|
|
30
|
+
const conv = JSON.parse(jsonStr);
|
|
31
|
+
onUpdate === null || onUpdate === void 0 ? void 0 : onUpdate(conv);
|
|
32
|
+
},
|
|
33
|
+
});
|
|
34
|
+
};
|
|
35
|
+
return {
|
|
36
|
+
getConversations,
|
|
37
|
+
getConversation,
|
|
38
|
+
listConversations,
|
|
39
|
+
createConversation,
|
|
40
|
+
addMessage,
|
|
41
|
+
subscribeToConversation,
|
|
42
|
+
};
|
|
43
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
export type AgentConversation = {
|
|
2
|
+
id: string;
|
|
3
|
+
app_id: string;
|
|
4
|
+
agent_name: string;
|
|
5
|
+
created_by_id: string;
|
|
6
|
+
messages: AgentMessage[];
|
|
7
|
+
metadata?: Record<string, any>;
|
|
8
|
+
};
|
|
9
|
+
export type AgentMessage = {
|
|
10
|
+
id: string;
|
|
11
|
+
role: "user" | "assistant" | "system";
|
|
12
|
+
reasoning?: {
|
|
13
|
+
start_date: string;
|
|
14
|
+
end_date?: string;
|
|
15
|
+
content: string;
|
|
16
|
+
};
|
|
17
|
+
content?: string | Record<string, any> | null;
|
|
18
|
+
file_urls?: string[] | null;
|
|
19
|
+
tool_calls?: {
|
|
20
|
+
id: string;
|
|
21
|
+
name: string;
|
|
22
|
+
arguments_string: string;
|
|
23
|
+
status: "running" | "success" | "error" | "stopped";
|
|
24
|
+
results?: string | null;
|
|
25
|
+
}[] | null;
|
|
26
|
+
usage?: {
|
|
27
|
+
prompt_tokens?: number;
|
|
28
|
+
completion_tokens?: number;
|
|
29
|
+
} | null;
|
|
30
|
+
hidden?: boolean;
|
|
31
|
+
custom_context?: {
|
|
32
|
+
message: string;
|
|
33
|
+
data: Record<string, any>;
|
|
34
|
+
type: string;
|
|
35
|
+
}[] | null;
|
|
36
|
+
model?: string | null;
|
|
37
|
+
checkpoint_id?: string | null;
|
|
38
|
+
metadata?: {
|
|
39
|
+
created_date: string;
|
|
40
|
+
created_by_email: string;
|
|
41
|
+
created_by_full_name: string | null;
|
|
42
|
+
};
|
|
43
|
+
additional_message_params?: Record<string, any>;
|
|
44
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
export interface AppMessageContent {
|
|
2
|
+
content?: string;
|
|
3
|
+
file_urls?: string[];
|
|
4
|
+
custom_context?: unknown;
|
|
5
|
+
additional_message_params?: Record<string, unknown>;
|
|
6
|
+
[key: string]: unknown;
|
|
7
|
+
}
|
|
8
|
+
export interface AppConversationMessage extends AppMessageContent {
|
|
9
|
+
id?: string | null;
|
|
10
|
+
role?: "user" | "assistant" | string;
|
|
11
|
+
}
|
|
12
|
+
export interface AppConversationLike {
|
|
13
|
+
id?: string | null;
|
|
14
|
+
messages?: AppMessageContent[] | null;
|
|
15
|
+
model?: string;
|
|
16
|
+
functions_fail_silently?: boolean;
|
|
17
|
+
}
|
|
18
|
+
export interface DenoProjectLike {
|
|
19
|
+
project_id: string;
|
|
20
|
+
project_name: string;
|
|
21
|
+
app_id: string;
|
|
22
|
+
deployment_name_to_info: Record<string, {
|
|
23
|
+
id: string;
|
|
24
|
+
code: string;
|
|
25
|
+
}>;
|
|
26
|
+
}
|
|
27
|
+
export interface AppLike {
|
|
28
|
+
id?: string;
|
|
29
|
+
conversation?: AppConversationLike | null;
|
|
30
|
+
app_stage?: "pending" | "product_flows" | "ready" | string;
|
|
31
|
+
created_date?: string;
|
|
32
|
+
updated_date?: string;
|
|
33
|
+
created_by?: string;
|
|
34
|
+
organization_id?: string;
|
|
35
|
+
name?: string;
|
|
36
|
+
user_description?: string;
|
|
37
|
+
entities?: Record<string, any>;
|
|
38
|
+
additional_user_data_schema?: any;
|
|
39
|
+
pages?: {
|
|
40
|
+
[key: string]: string;
|
|
41
|
+
};
|
|
42
|
+
components: {
|
|
43
|
+
[key: string]: any;
|
|
44
|
+
};
|
|
45
|
+
layout?: string;
|
|
46
|
+
globals_css?: string;
|
|
47
|
+
agents?: Record<string, any>;
|
|
48
|
+
logo_url?: string;
|
|
49
|
+
slug?: string;
|
|
50
|
+
public_settings?: "private_with_login" | "public_with_login" | "public_without_login" | "workspace_with_login" | string;
|
|
51
|
+
is_blocked?: boolean;
|
|
52
|
+
github_repo_url?: string;
|
|
53
|
+
main_page?: string;
|
|
54
|
+
installable_integrations?: any;
|
|
55
|
+
backend_project?: DenoProjectLike;
|
|
56
|
+
last_deployed_at?: string;
|
|
57
|
+
is_remixable?: boolean;
|
|
58
|
+
remixed_from_app_id?: string;
|
|
59
|
+
hide_entity_created_by?: boolean;
|
|
60
|
+
platform_version?: number;
|
|
61
|
+
enable_username_password?: boolean;
|
|
62
|
+
auth_config?: AuthConfigLike;
|
|
63
|
+
status?: {
|
|
64
|
+
state?: string;
|
|
65
|
+
details?: any;
|
|
66
|
+
last_updated_date?: string;
|
|
67
|
+
};
|
|
68
|
+
custom_instructions?: any;
|
|
69
|
+
frozen_files?: string[];
|
|
70
|
+
deep_coding_mode?: boolean;
|
|
71
|
+
needs_to_add_diff?: boolean;
|
|
72
|
+
installed_integration_context_items?: any[];
|
|
73
|
+
model?: string;
|
|
74
|
+
is_starred?: boolean;
|
|
75
|
+
agents_enabled?: boolean;
|
|
76
|
+
categories?: string[];
|
|
77
|
+
functions?: any;
|
|
78
|
+
function_names?: string[];
|
|
79
|
+
user_entity?: UserEntityLike;
|
|
80
|
+
app_code_hash?: string;
|
|
81
|
+
has_backend_functions_enabled?: boolean;
|
|
82
|
+
}
|
|
83
|
+
export interface UserLike {
|
|
84
|
+
id?: string | null;
|
|
85
|
+
}
|
|
86
|
+
export interface UserEntityLike {
|
|
87
|
+
type: string;
|
|
88
|
+
name: string;
|
|
89
|
+
title?: string;
|
|
90
|
+
properties?: {
|
|
91
|
+
role?: {
|
|
92
|
+
type?: string;
|
|
93
|
+
description?: string;
|
|
94
|
+
enum?: ("admin" | "user" | string)[];
|
|
95
|
+
};
|
|
96
|
+
email?: {
|
|
97
|
+
type?: string;
|
|
98
|
+
description?: string;
|
|
99
|
+
};
|
|
100
|
+
full_name?: {
|
|
101
|
+
type?: string;
|
|
102
|
+
description?: string;
|
|
103
|
+
};
|
|
104
|
+
};
|
|
105
|
+
required: string[];
|
|
106
|
+
}
|
|
107
|
+
export interface AuthConfigLike {
|
|
108
|
+
enable_username_password?: boolean;
|
|
109
|
+
enable_google_login?: boolean;
|
|
110
|
+
enable_microsoft_login?: boolean;
|
|
111
|
+
enable_facebook_login?: boolean;
|
|
112
|
+
sso_provider_name?: string;
|
|
113
|
+
enable_sso_login?: boolean;
|
|
114
|
+
}
|
|
115
|
+
export type LoginInfoResponse = Pick<AppLike, "id" | "name" | "slug" | "logo_url" | "user_description" | "updated_date" | "created_date" | "auth_config" | "platform_version">;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/modules/auth.d.ts
CHANGED
|
@@ -6,7 +6,10 @@ import { AxiosInstance } from "axios";
|
|
|
6
6
|
* @param {string} serverUrl - Server URL
|
|
7
7
|
* @returns {Object} Auth module with authentication methods
|
|
8
8
|
*/
|
|
9
|
-
export declare function createAuthModule(axios: AxiosInstance, functionsAxiosClient: AxiosInstance, appId: string
|
|
9
|
+
export declare function createAuthModule(axios: AxiosInstance, functionsAxiosClient: AxiosInstance, appId: string, options: {
|
|
10
|
+
serverUrl: string;
|
|
11
|
+
onRedirectToLogin?: () => void;
|
|
12
|
+
}): {
|
|
10
13
|
/**
|
|
11
14
|
* Get current user information
|
|
12
15
|
* @returns {Promise<Object>} Current user data
|
|
@@ -53,4 +56,26 @@ export declare function createAuthModule(axios: AxiosInstance, functionsAxiosCli
|
|
|
53
56
|
* @returns {Promise<boolean>} True if token is valid
|
|
54
57
|
*/
|
|
55
58
|
isAuthenticated(): Promise<boolean>;
|
|
59
|
+
inviteUser(userEmail: string, role: string): Promise<import("axios").AxiosResponse<any, any>>;
|
|
60
|
+
register(payload: {
|
|
61
|
+
email: string;
|
|
62
|
+
password: string;
|
|
63
|
+
turnstile_token?: string | null;
|
|
64
|
+
referral_code?: string | null;
|
|
65
|
+
}): Promise<import("axios").AxiosResponse<any, any>>;
|
|
66
|
+
verifyOtp({ email, otpCode }: {
|
|
67
|
+
email: string;
|
|
68
|
+
otpCode: string;
|
|
69
|
+
}): Promise<import("axios").AxiosResponse<any, any>>;
|
|
70
|
+
resendOtp(email: string): Promise<import("axios").AxiosResponse<any, any>>;
|
|
71
|
+
resetPasswordRequest(email: string): Promise<import("axios").AxiosResponse<any, any>>;
|
|
72
|
+
resetPassword({ resetToken, newPassword, }: {
|
|
73
|
+
resetToken: string;
|
|
74
|
+
newPassword: string;
|
|
75
|
+
}): Promise<import("axios").AxiosResponse<any, any>>;
|
|
76
|
+
changePassword({ userId, currentPassword, newPassword, }: {
|
|
77
|
+
userId: string;
|
|
78
|
+
currentPassword: string;
|
|
79
|
+
newPassword: string;
|
|
80
|
+
}): Promise<import("axios").AxiosResponse<any, any>>;
|
|
56
81
|
};
|
package/dist/modules/auth.js
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* @param {string} serverUrl - Server URL
|
|
6
6
|
* @returns {Object} Auth module with authentication methods
|
|
7
7
|
*/
|
|
8
|
-
export function createAuthModule(axios, functionsAxiosClient, appId) {
|
|
8
|
+
export function createAuthModule(axios, functionsAxiosClient, appId, options) {
|
|
9
9
|
return {
|
|
10
10
|
/**
|
|
11
11
|
* Get current user information
|
|
@@ -32,10 +32,14 @@ export function createAuthModule(axios, functionsAxiosClient, appId) {
|
|
|
32
32
|
if (typeof window === "undefined") {
|
|
33
33
|
throw new Error("Login method can only be used in a browser environment");
|
|
34
34
|
}
|
|
35
|
+
if (options.onRedirectToLogin) {
|
|
36
|
+
options.onRedirectToLogin();
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
35
39
|
// If nextUrl is not provided, use the current URL
|
|
36
40
|
const redirectUrl = nextUrl || window.location.href;
|
|
37
41
|
// Build the login URL
|
|
38
|
-
const loginUrl =
|
|
42
|
+
const loginUrl = `${options.serverUrl}/login?from_url=${encodeURIComponent(redirectUrl)}&app_id=${appId}`;
|
|
39
43
|
// Redirect to the login page
|
|
40
44
|
window.location.href = loginUrl;
|
|
41
45
|
},
|
|
@@ -77,6 +81,7 @@ export function createAuthModule(axios, functionsAxiosClient, appId) {
|
|
|
77
81
|
setToken(token, saveToStorage = true) {
|
|
78
82
|
if (!token)
|
|
79
83
|
return;
|
|
84
|
+
// handle token change for axios clients
|
|
80
85
|
axios.defaults.headers.common["Authorization"] = `Bearer ${token}`;
|
|
81
86
|
functionsAxiosClient.defaults.headers.common["Authorization"] = `Bearer ${token}`;
|
|
82
87
|
// Save token to localStorage if requested
|
|
@@ -136,5 +141,41 @@ export function createAuthModule(axios, functionsAxiosClient, appId) {
|
|
|
136
141
|
return false;
|
|
137
142
|
}
|
|
138
143
|
},
|
|
144
|
+
inviteUser(userEmail, role) {
|
|
145
|
+
return axios.post(`/apps/${appId}/users/invite-user`, {
|
|
146
|
+
user_email: userEmail,
|
|
147
|
+
role,
|
|
148
|
+
});
|
|
149
|
+
},
|
|
150
|
+
register(payload) {
|
|
151
|
+
return axios.post(`/apps/${appId}/auth/register`, payload);
|
|
152
|
+
},
|
|
153
|
+
verifyOtp({ email, otpCode }) {
|
|
154
|
+
return axios.post(`/apps/${appId}/auth/verify-otp`, {
|
|
155
|
+
email,
|
|
156
|
+
otp_code: otpCode,
|
|
157
|
+
});
|
|
158
|
+
},
|
|
159
|
+
resendOtp(email) {
|
|
160
|
+
return axios.post(`/apps/${appId}/auth/resend-otp`, { email });
|
|
161
|
+
},
|
|
162
|
+
resetPasswordRequest(email) {
|
|
163
|
+
return axios.post(`/apps/${appId}/auth/reset-password-request`, {
|
|
164
|
+
email,
|
|
165
|
+
});
|
|
166
|
+
},
|
|
167
|
+
resetPassword({ resetToken, newPassword, }) {
|
|
168
|
+
return axios.post(`/apps/${appId}/auth/reset-password`, {
|
|
169
|
+
reset_token: resetToken,
|
|
170
|
+
new_password: newPassword,
|
|
171
|
+
});
|
|
172
|
+
},
|
|
173
|
+
changePassword({ userId, currentPassword, newPassword, }) {
|
|
174
|
+
return axios.post(`/apps/${appId}/auth/change-password`, {
|
|
175
|
+
user_id: userId,
|
|
176
|
+
current_password: currentPassword,
|
|
177
|
+
new_password: newPassword,
|
|
178
|
+
});
|
|
179
|
+
},
|
|
139
180
|
};
|
|
140
181
|
}
|
package/dist/types.d.ts
ADDED
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./modules/types.js";
|
|
@@ -23,7 +23,7 @@ export declare class Base44Error extends Error {
|
|
|
23
23
|
* @param {string} options.serverUrl - Server URL (needed for login redirect)
|
|
24
24
|
* @returns {import('axios').AxiosInstance} Configured axios instance
|
|
25
25
|
*/
|
|
26
|
-
export declare function createAxiosClient({ baseURL, headers, token, requiresAuth, appId, serverUrl, interceptResponses, }: {
|
|
26
|
+
export declare function createAxiosClient({ baseURL, headers, token, requiresAuth, appId, serverUrl, interceptResponses, onError, onRedirectToLogin, }: {
|
|
27
27
|
baseURL: string;
|
|
28
28
|
headers?: Record<string, string>;
|
|
29
29
|
token?: string;
|
|
@@ -31,4 +31,6 @@ export declare function createAxiosClient({ baseURL, headers, token, requiresAut
|
|
|
31
31
|
appId: string;
|
|
32
32
|
serverUrl: string;
|
|
33
33
|
interceptResponses?: boolean;
|
|
34
|
+
onError?: (error: Error) => void;
|
|
35
|
+
onRedirectToLogin?: () => void;
|
|
34
36
|
}): import("axios").AxiosInstance;
|
|
@@ -64,7 +64,7 @@ function redirectToLogin(serverUrl, appId) {
|
|
|
64
64
|
* @param {string} options.serverUrl - Server URL (needed for login redirect)
|
|
65
65
|
* @returns {import('axios').AxiosInstance} Configured axios instance
|
|
66
66
|
*/
|
|
67
|
-
export function createAxiosClient({ baseURL, headers = {}, token, requiresAuth = false, appId, serverUrl, interceptResponses = true, }) {
|
|
67
|
+
export function createAxiosClient({ baseURL, headers = {}, token, requiresAuth = false, appId, serverUrl, interceptResponses = true, onError, onRedirectToLogin, }) {
|
|
68
68
|
const client = axios.create({
|
|
69
69
|
baseURL,
|
|
70
70
|
headers: {
|
|
@@ -104,9 +104,12 @@ export function createAxiosClient({ baseURL, headers = {}, token, requiresAuth =
|
|
|
104
104
|
console.log("Authentication required. Redirecting to login...");
|
|
105
105
|
// Use a slight delay to allow the error to propagate first
|
|
106
106
|
setTimeout(() => {
|
|
107
|
-
|
|
107
|
+
onRedirectToLogin
|
|
108
|
+
? onRedirectToLogin()
|
|
109
|
+
: redirectToLogin(serverUrl, appId);
|
|
108
110
|
}, 100);
|
|
109
111
|
}
|
|
112
|
+
onError === null || onError === void 0 ? void 0 : onError(base44Error);
|
|
110
113
|
return Promise.reject(base44Error);
|
|
111
114
|
});
|
|
112
115
|
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { Socket } from "socket.io-client";
|
|
2
|
+
export type 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
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@base44/sdk",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.4",
|
|
4
4
|
"description": "JavaScript SDK for Base44 API",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -19,7 +19,8 @@
|
|
|
19
19
|
"prepublishOnly": "npm run build"
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"axios": "^1.6.2"
|
|
22
|
+
"axios": "^1.6.2",
|
|
23
|
+
"socket.io-client": "^4.7.5"
|
|
23
24
|
},
|
|
24
25
|
"devDependencies": {
|
|
25
26
|
"vitest": "^1.0.0",
|