@base44/sdk 0.8.4 → 0.8.6
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 +6 -0
- package/dist/client.js +32 -10
- package/dist/modules/agents.d.ts +2 -2
- package/dist/modules/agents.js +3 -1
- package/dist/modules/users.d.ts +16 -0
- package/dist/modules/users.js +23 -0
- package/package.json +2 -1
package/dist/client.d.ts
CHANGED
|
@@ -125,6 +125,9 @@ export declare function createClient(config: {
|
|
|
125
125
|
fetchLogs(params?: Record<string, any>): Promise<any>;
|
|
126
126
|
getStats(params?: Record<string, any>): Promise<any>;
|
|
127
127
|
};
|
|
128
|
+
users: {
|
|
129
|
+
inviteUser(user_email: string, role: "user" | "admin"): Promise<any>;
|
|
130
|
+
};
|
|
128
131
|
cleanup: () => void;
|
|
129
132
|
};
|
|
130
133
|
export declare function createClientFromRequest(request: Request): {
|
|
@@ -229,5 +232,8 @@ export declare function createClientFromRequest(request: Request): {
|
|
|
229
232
|
fetchLogs(params?: Record<string, any>): Promise<any>;
|
|
230
233
|
getStats(params?: Record<string, any>): Promise<any>;
|
|
231
234
|
};
|
|
235
|
+
users: {
|
|
236
|
+
inviteUser(user_email: string, role: "user" | "admin"): Promise<any>;
|
|
237
|
+
};
|
|
232
238
|
cleanup: () => void;
|
|
233
239
|
};
|
package/dist/client.js
CHANGED
|
@@ -8,6 +8,7 @@ import { getAccessToken } from "./utils/auth-utils.js";
|
|
|
8
8
|
import { createFunctionsModule } from "./modules/functions.js";
|
|
9
9
|
import { createAgentsModule } from "./modules/agents.js";
|
|
10
10
|
import { createAppLogsModule } from "./modules/app-logs.js";
|
|
11
|
+
import { createUsersModule } from "./modules/users.js";
|
|
11
12
|
import { RoomsSocket } from "./utils/socket-utils.js";
|
|
12
13
|
/**
|
|
13
14
|
* Create a Base44 client instance
|
|
@@ -29,9 +30,15 @@ export function createClient(config) {
|
|
|
29
30
|
appId,
|
|
30
31
|
token,
|
|
31
32
|
};
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
33
|
+
let socket = null;
|
|
34
|
+
const getSocket = () => {
|
|
35
|
+
if (!socket) {
|
|
36
|
+
socket = RoomsSocket({
|
|
37
|
+
config: socketConfig,
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
return socket;
|
|
41
|
+
};
|
|
35
42
|
const headers = {
|
|
36
43
|
...optionalHeaders,
|
|
37
44
|
"X-App-Id": String(appId),
|
|
@@ -77,14 +84,17 @@ export function createClient(config) {
|
|
|
77
84
|
functions: createFunctionsModule(functionsAxiosClient, appId),
|
|
78
85
|
agents: createAgentsModule({
|
|
79
86
|
axios: axiosClient,
|
|
80
|
-
|
|
87
|
+
getSocket,
|
|
81
88
|
appId,
|
|
82
89
|
serverUrl,
|
|
83
90
|
token,
|
|
84
91
|
}),
|
|
85
92
|
appLogs: createAppLogsModule(axiosClient, appId),
|
|
93
|
+
users: createUsersModule(axiosClient, appId),
|
|
86
94
|
cleanup: () => {
|
|
87
|
-
socket
|
|
95
|
+
if (socket) {
|
|
96
|
+
socket.disconnect();
|
|
97
|
+
}
|
|
88
98
|
},
|
|
89
99
|
};
|
|
90
100
|
const serviceRoleModules = {
|
|
@@ -95,14 +105,16 @@ export function createClient(config) {
|
|
|
95
105
|
functions: createFunctionsModule(serviceRoleFunctionsAxiosClient, appId),
|
|
96
106
|
agents: createAgentsModule({
|
|
97
107
|
axios: serviceRoleAxiosClient,
|
|
98
|
-
|
|
108
|
+
getSocket,
|
|
99
109
|
appId,
|
|
100
110
|
serverUrl,
|
|
101
111
|
token,
|
|
102
112
|
}),
|
|
103
113
|
appLogs: createAppLogsModule(serviceRoleAxiosClient, appId),
|
|
104
114
|
cleanup: () => {
|
|
105
|
-
socket
|
|
115
|
+
if (socket) {
|
|
116
|
+
socket.disconnect();
|
|
117
|
+
}
|
|
106
118
|
},
|
|
107
119
|
};
|
|
108
120
|
// Always try to get token from localStorage or URL parameters
|
|
@@ -138,9 +150,12 @@ export function createClient(config) {
|
|
|
138
150
|
*/
|
|
139
151
|
setToken(newToken) {
|
|
140
152
|
userModules.auth.setToken(newToken);
|
|
141
|
-
socket
|
|
142
|
-
|
|
143
|
-
|
|
153
|
+
if (socket) {
|
|
154
|
+
socket.updateConfig({
|
|
155
|
+
token: newToken,
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
socketConfig.token = newToken;
|
|
144
159
|
},
|
|
145
160
|
/**
|
|
146
161
|
* Get current configuration
|
|
@@ -172,6 +187,7 @@ export function createClientFromRequest(request) {
|
|
|
172
187
|
const appId = request.headers.get("Base44-App-Id");
|
|
173
188
|
const serverUrlHeader = request.headers.get("Base44-Api-Url");
|
|
174
189
|
const functionsVersion = request.headers.get("Base44-Functions-Version");
|
|
190
|
+
const stateHeader = request.headers.get("Base44-State");
|
|
175
191
|
if (!appId) {
|
|
176
192
|
throw new Error("Base44-App-Id header is required, but is was not found on the request");
|
|
177
193
|
}
|
|
@@ -194,11 +210,17 @@ export function createClientFromRequest(request) {
|
|
|
194
210
|
}
|
|
195
211
|
userToken = authHeader.split(" ")[1];
|
|
196
212
|
}
|
|
213
|
+
// Prepare additional headers to propagate
|
|
214
|
+
const additionalHeaders = {};
|
|
215
|
+
if (stateHeader) {
|
|
216
|
+
additionalHeaders["Base44-State"] = stateHeader;
|
|
217
|
+
}
|
|
197
218
|
return createClient({
|
|
198
219
|
serverUrl: serverUrlHeader || "https://base44.app",
|
|
199
220
|
appId,
|
|
200
221
|
token: userToken,
|
|
201
222
|
serviceToken: serviceRoleToken,
|
|
202
223
|
functionsVersion: functionsVersion !== null && functionsVersion !== void 0 ? functionsVersion : undefined,
|
|
224
|
+
headers: additionalHeaders,
|
|
203
225
|
});
|
|
204
226
|
}
|
package/dist/modules/agents.d.ts
CHANGED
|
@@ -4,12 +4,12 @@ import { AxiosInstance } from "axios";
|
|
|
4
4
|
import { ModelFilterParams } from "../types.js";
|
|
5
5
|
export type AgentsModuleConfig = {
|
|
6
6
|
axios: AxiosInstance;
|
|
7
|
-
|
|
7
|
+
getSocket: () => ReturnType<typeof RoomsSocket>;
|
|
8
8
|
appId: string;
|
|
9
9
|
serverUrl?: string;
|
|
10
10
|
token?: string;
|
|
11
11
|
};
|
|
12
|
-
export declare function createAgentsModule({ axios,
|
|
12
|
+
export declare function createAgentsModule({ axios, getSocket, appId, serverUrl, token, }: AgentsModuleConfig): {
|
|
13
13
|
getConversations: () => Promise<AgentConversation[]>;
|
|
14
14
|
getConversation: (conversationId: string) => Promise<AgentConversation | undefined>;
|
|
15
15
|
listConversations: (filterParams: ModelFilterParams) => Promise<AgentConversation[]>;
|
package/dist/modules/agents.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { getAccessToken } from "../utils/auth-utils.js";
|
|
2
|
-
export function createAgentsModule({ axios,
|
|
2
|
+
export function createAgentsModule({ axios, getSocket, appId, serverUrl, token, }) {
|
|
3
3
|
const baseURL = `/apps/${appId}/agents`;
|
|
4
4
|
const getConversations = () => {
|
|
5
5
|
return axios.get(`${baseURL}/conversations`);
|
|
@@ -17,6 +17,7 @@ export function createAgentsModule({ axios, socket, appId, serverUrl, token, })
|
|
|
17
17
|
};
|
|
18
18
|
const addMessage = async (conversation, message) => {
|
|
19
19
|
const room = `/agent-conversations/${conversation.id}`;
|
|
20
|
+
const socket = getSocket();
|
|
20
21
|
await socket.updateModel(room, {
|
|
21
22
|
...conversation,
|
|
22
23
|
messages: [...(conversation.messages || []), message],
|
|
@@ -25,6 +26,7 @@ export function createAgentsModule({ axios, socket, appId, serverUrl, token, })
|
|
|
25
26
|
};
|
|
26
27
|
const subscribeToConversation = (conversationId, onUpdate) => {
|
|
27
28
|
const room = `/agent-conversations/${conversationId}`;
|
|
29
|
+
const socket = getSocket();
|
|
28
30
|
return socket.subscribeToRoom(room, {
|
|
29
31
|
connect: () => { },
|
|
30
32
|
update_model: ({ data: jsonStr }) => {
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { AxiosInstance } from "axios";
|
|
2
|
+
/**
|
|
3
|
+
* Creates the users module for the Base44 SDK
|
|
4
|
+
* @param {AxiosInstance} axios - Axios instance
|
|
5
|
+
* @param {string} appId - Application ID
|
|
6
|
+
* @returns {Object} Users module
|
|
7
|
+
*/
|
|
8
|
+
export declare function createUsersModule(axios: AxiosInstance, appId: string): {
|
|
9
|
+
/**
|
|
10
|
+
* Invite a user to the application
|
|
11
|
+
* @param {string} user_email - User's email address
|
|
12
|
+
* @param {'user'|'admin'} role - User's role (user or admin)
|
|
13
|
+
* @returns {Promise<any>}
|
|
14
|
+
*/
|
|
15
|
+
inviteUser(user_email: string, role: "user" | "admin"): Promise<any>;
|
|
16
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates the users module for the Base44 SDK
|
|
3
|
+
* @param {AxiosInstance} axios - Axios instance
|
|
4
|
+
* @param {string} appId - Application ID
|
|
5
|
+
* @returns {Object} Users module
|
|
6
|
+
*/
|
|
7
|
+
export function createUsersModule(axios, appId) {
|
|
8
|
+
return {
|
|
9
|
+
/**
|
|
10
|
+
* Invite a user to the application
|
|
11
|
+
* @param {string} user_email - User's email address
|
|
12
|
+
* @param {'user'|'admin'} role - User's role (user or admin)
|
|
13
|
+
* @returns {Promise<any>}
|
|
14
|
+
*/
|
|
15
|
+
async inviteUser(user_email, role) {
|
|
16
|
+
if (role !== "user" && role !== "admin") {
|
|
17
|
+
throw new Error(`Invalid role: "${role}". Role must be either "user" or "admin".`);
|
|
18
|
+
}
|
|
19
|
+
const response = await axios.post(`/apps/${appId}/runtime/users/invite-user`, { user_email, role });
|
|
20
|
+
return response;
|
|
21
|
+
},
|
|
22
|
+
};
|
|
23
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@base44/sdk",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.6",
|
|
4
4
|
"description": "JavaScript SDK for Base44 API",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -24,6 +24,7 @@
|
|
|
24
24
|
"uuid": "^13.0.0"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
|
+
"@types/node": "^25.0.1",
|
|
27
28
|
"@vitest/coverage-istanbul": "^1.0.0",
|
|
28
29
|
"@vitest/coverage-v8": "^1.0.0",
|
|
29
30
|
"@vitest/ui": "^1.0.0",
|