diff --git a/src/client.ts b/src/client.ts index b3bcc74..f70e4c3 100644 --- a/src/client.ts +++ b/src/client.ts @@ -8,6 +8,7 @@ import { getAccessToken } from "./utils/auth-utils.js"; import { createFunctionsModule } from "./modules/functions.js"; import { createAgentsModule } from "./modules/agents.js"; import { createAppLogsModule } from "./modules/app-logs.js"; +import { createUsersModule } from "./modules/users.js"; import { RoomsSocket, RoomsSocketConfig } from "./utils/socket-utils.js"; export type CreateClientOptions = { @@ -119,6 +120,7 @@ export function createClient(config: { token, }), appLogs: createAppLogsModule(axiosClient, appId), + users: createUsersModule(axiosClient, appId), cleanup: () => { socket.disconnect(); }, diff --git a/src/modules/users.ts b/src/modules/users.ts new file mode 100644 index 0000000..5ace597 --- /dev/null +++ b/src/modules/users.ts @@ -0,0 +1,28 @@ +import { AxiosInstance } from "axios"; + +/** + * Creates the users module for the Base44 SDK + * @param {AxiosInstance} axios - Axios instance + * @param {string} appId - Application ID + * @returns {Object} Users module + */ +export function createUsersModule(axios: AxiosInstance, appId: string) { + return { + /** + * Invite a user to the application + * @param {string} user_email - User's email address + * @param {'user'|'admin'} role - User's role (user or admin) + * @returns {Promise} + */ + async inviteUser(user_email: string, role: "user" | "admin"): Promise { + if (role !== "user" && role !== "admin") { + throw new Error( + `Invalid role: "${role}". Role must be either "user" or "admin".` + ); + } + + const response = await axios.post(`/apps/${appId}/runtime/users/invite-user`, { user_email, role }); + return response; + }, + }; +}