@base44-preview/sdk 0.8.4-pr.55.172cc47 → 0.8.5-pr.52.e60528e
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 +19 -23
- package/dist/index.d.ts +2 -1
- package/dist/index.js +2 -1
- package/dist/modules/agents.d.ts +2 -2
- package/dist/modules/agents.js +1 -3
- package/dist/modules/users.d.ts +16 -0
- package/dist/modules/users.js +23 -0
- package/dist/utils/app-params.d.ts +11 -0
- package/dist/utils/app-params.js +43 -0
- package/dist/utils/common.d.ts +1 -0
- package/dist/utils/common.js +2 -1
- package/package.json +1 -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,15 +30,9 @@ export function createClient(config) {
|
|
|
29
30
|
appId,
|
|
30
31
|
token,
|
|
31
32
|
};
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
socket = RoomsSocket({
|
|
36
|
-
config: socketConfig,
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
return socket;
|
|
40
|
-
};
|
|
33
|
+
const socket = RoomsSocket({
|
|
34
|
+
config: socketConfig,
|
|
35
|
+
});
|
|
41
36
|
const headers = {
|
|
42
37
|
...optionalHeaders,
|
|
43
38
|
"X-App-Id": String(appId),
|
|
@@ -83,16 +78,15 @@ export function createClient(config) {
|
|
|
83
78
|
functions: createFunctionsModule(functionsAxiosClient, appId),
|
|
84
79
|
agents: createAgentsModule({
|
|
85
80
|
axios: axiosClient,
|
|
86
|
-
|
|
81
|
+
socket,
|
|
87
82
|
appId,
|
|
88
83
|
serverUrl,
|
|
89
84
|
token,
|
|
90
85
|
}),
|
|
91
86
|
appLogs: createAppLogsModule(axiosClient, appId),
|
|
87
|
+
users: createUsersModule(axiosClient, appId),
|
|
92
88
|
cleanup: () => {
|
|
93
|
-
|
|
94
|
-
socket.disconnect();
|
|
95
|
-
}
|
|
89
|
+
socket.disconnect();
|
|
96
90
|
},
|
|
97
91
|
};
|
|
98
92
|
const serviceRoleModules = {
|
|
@@ -103,16 +97,14 @@ export function createClient(config) {
|
|
|
103
97
|
functions: createFunctionsModule(serviceRoleFunctionsAxiosClient, appId),
|
|
104
98
|
agents: createAgentsModule({
|
|
105
99
|
axios: serviceRoleAxiosClient,
|
|
106
|
-
|
|
100
|
+
socket,
|
|
107
101
|
appId,
|
|
108
102
|
serverUrl,
|
|
109
103
|
token,
|
|
110
104
|
}),
|
|
111
105
|
appLogs: createAppLogsModule(serviceRoleAxiosClient, appId),
|
|
112
106
|
cleanup: () => {
|
|
113
|
-
|
|
114
|
-
socket.disconnect();
|
|
115
|
-
}
|
|
107
|
+
socket.disconnect();
|
|
116
108
|
},
|
|
117
109
|
};
|
|
118
110
|
// Always try to get token from localStorage or URL parameters
|
|
@@ -148,12 +140,9 @@ export function createClient(config) {
|
|
|
148
140
|
*/
|
|
149
141
|
setToken(newToken) {
|
|
150
142
|
userModules.auth.setToken(newToken);
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
});
|
|
155
|
-
}
|
|
156
|
-
socketConfig.token = newToken;
|
|
143
|
+
socket.updateConfig({
|
|
144
|
+
token: newToken,
|
|
145
|
+
});
|
|
157
146
|
},
|
|
158
147
|
/**
|
|
159
148
|
* Get current configuration
|
|
@@ -185,6 +174,7 @@ export function createClientFromRequest(request) {
|
|
|
185
174
|
const appId = request.headers.get("Base44-App-Id");
|
|
186
175
|
const serverUrlHeader = request.headers.get("Base44-Api-Url");
|
|
187
176
|
const functionsVersion = request.headers.get("Base44-Functions-Version");
|
|
177
|
+
const stateHeader = request.headers.get("Base44-State");
|
|
188
178
|
if (!appId) {
|
|
189
179
|
throw new Error("Base44-App-Id header is required, but is was not found on the request");
|
|
190
180
|
}
|
|
@@ -207,11 +197,17 @@ export function createClientFromRequest(request) {
|
|
|
207
197
|
}
|
|
208
198
|
userToken = authHeader.split(" ")[1];
|
|
209
199
|
}
|
|
200
|
+
// Prepare additional headers to propagate
|
|
201
|
+
const additionalHeaders = {};
|
|
202
|
+
if (stateHeader) {
|
|
203
|
+
additionalHeaders["Base44-State"] = stateHeader;
|
|
204
|
+
}
|
|
210
205
|
return createClient({
|
|
211
206
|
serverUrl: serverUrlHeader || "https://base44.app",
|
|
212
207
|
appId,
|
|
213
208
|
token: userToken,
|
|
214
209
|
serviceToken: serviceRoleToken,
|
|
215
210
|
functionsVersion: functionsVersion !== null && functionsVersion !== void 0 ? functionsVersion : undefined,
|
|
211
|
+
headers: additionalHeaders,
|
|
216
212
|
});
|
|
217
213
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
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
|
+
import { appParams } from "./utils/app-params.js";
|
|
5
|
+
export { createClient, createClientFromRequest, Base44Error, getAccessToken, saveAccessToken, removeAccessToken, getLoginUrl, appParams };
|
|
5
6
|
export type { Base44Client };
|
|
6
7
|
export * from "./types.js";
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
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
|
+
import { appParams } from "./utils/app-params.js";
|
|
5
|
+
export { createClient, createClientFromRequest, Base44Error, getAccessToken, saveAccessToken, removeAccessToken, getLoginUrl, appParams };
|
|
5
6
|
export * from "./types.js";
|
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
|
+
socket: 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, socket, 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, socket, appId, serverUrl, token, }) {
|
|
3
3
|
const baseURL = `/apps/${appId}/agents`;
|
|
4
4
|
const getConversations = () => {
|
|
5
5
|
return axios.get(`${baseURL}/conversations`);
|
|
@@ -17,7 +17,6 @@ export function createAgentsModule({ axios, getSocket, appId, serverUrl, token,
|
|
|
17
17
|
};
|
|
18
18
|
const addMessage = async (conversation, message) => {
|
|
19
19
|
const room = `/agent-conversations/${conversation.id}`;
|
|
20
|
-
const socket = getSocket();
|
|
21
20
|
await socket.updateModel(room, {
|
|
22
21
|
...conversation,
|
|
23
22
|
messages: [...(conversation.messages || []), message],
|
|
@@ -26,7 +25,6 @@ export function createAgentsModule({ axios, getSocket, appId, serverUrl, token,
|
|
|
26
25
|
};
|
|
27
26
|
const subscribeToConversation = (conversationId, onUpdate) => {
|
|
28
27
|
const room = `/agent-conversations/${conversationId}`;
|
|
29
|
-
const socket = getSocket();
|
|
30
28
|
return socket.subscribeToRoom(room, {
|
|
31
29
|
connect: () => { },
|
|
32
30
|
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
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { isBrowser } from './common';
|
|
2
|
+
const toSnakeCase = (str) => {
|
|
3
|
+
return str.replace(/([A-Z])/g, '_$1').toLowerCase();
|
|
4
|
+
};
|
|
5
|
+
const getAppParamValue = (paramName, { defaultValue = undefined, removeFromUrl = false } = {}) => {
|
|
6
|
+
const storageKey = `base44_${toSnakeCase(paramName)}`;
|
|
7
|
+
const urlParams = new URLSearchParams(window.location.search);
|
|
8
|
+
const searchParam = urlParams.get(paramName);
|
|
9
|
+
if (removeFromUrl) {
|
|
10
|
+
urlParams.delete(paramName);
|
|
11
|
+
const newUrl = `${window.location.pathname}${urlParams.toString() ? `?${urlParams.toString()}` : ""}${window.location.hash}`;
|
|
12
|
+
window.history.replaceState({}, document.title, newUrl);
|
|
13
|
+
}
|
|
14
|
+
if (searchParam) {
|
|
15
|
+
localStorage.setItem(storageKey, searchParam);
|
|
16
|
+
return searchParam;
|
|
17
|
+
}
|
|
18
|
+
if (defaultValue) {
|
|
19
|
+
localStorage.setItem(storageKey, defaultValue);
|
|
20
|
+
return defaultValue;
|
|
21
|
+
}
|
|
22
|
+
const storedValue = localStorage.getItem(storageKey);
|
|
23
|
+
if (storedValue) {
|
|
24
|
+
return storedValue;
|
|
25
|
+
}
|
|
26
|
+
return null;
|
|
27
|
+
};
|
|
28
|
+
const getAppParams = () => {
|
|
29
|
+
if (!isBrowser) {
|
|
30
|
+
return {};
|
|
31
|
+
}
|
|
32
|
+
if (getAppParamValue("clear_access_token") === 'true') {
|
|
33
|
+
localStorage.removeItem('base44_access_token');
|
|
34
|
+
localStorage.removeItem('token');
|
|
35
|
+
}
|
|
36
|
+
return {
|
|
37
|
+
appId: getAppParamValue("app_id", { defaultValue: import.meta.env.VITE_BASE44_APP_ID }),
|
|
38
|
+
token: getAppParamValue("access_token", { removeFromUrl: true }),
|
|
39
|
+
fromUrl: getAppParamValue("from_url", { defaultValue: window.location.href }),
|
|
40
|
+
functionsVersion: getAppParamValue("functions_version", { defaultValue: import.meta.env.VITE_BASE44_FUNCTIONS_VERSION }),
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
export const appParams = getAppParams();
|
package/dist/utils/common.d.ts
CHANGED
package/dist/utils/common.js
CHANGED