Skip to content

Commit 7a02156

Browse files
authored
Add App Logs (#42)
1 parent 0d7ece3 commit 7a02156

2 files changed

Lines changed: 46 additions & 0 deletions

File tree

src/client.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { createSsoModule } from "./modules/sso.js";
66
import { getAccessToken } from "./utils/auth-utils.js";
77
import { createFunctionsModule } from "./modules/functions.js";
88
import { createAgentsModule } from "./modules/agents.js";
9+
import { createAppLogsModule } from "./modules/app-logs.js";
910
import { RoomsSocket, RoomsSocketConfig } from "./utils/socket-utils.js";
1011

1112
export type CreateClientOptions = {
@@ -116,6 +117,7 @@ export function createClient(config: {
116117
serverUrl,
117118
token,
118119
}),
120+
appLogs: createAppLogsModule(axiosClient, appId),
119121
cleanup: () => {
120122
socket.disconnect();
121123
},
@@ -133,6 +135,7 @@ export function createClient(config: {
133135
serverUrl,
134136
token,
135137
}),
138+
appLogs: createAppLogsModule(serviceRoleAxiosClient, appId),
136139
cleanup: () => {
137140
socket.disconnect();
138141
},

src/modules/app-logs.ts

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import { AxiosInstance } from "axios";
2+
3+
/**
4+
* Creates the app logs module for the Base44 SDK
5+
* @param {AxiosInstance} axios - Axios instance
6+
* @param {string} appId - Application ID
7+
* @returns {Object} App logs module
8+
*/
9+
export function createAppLogsModule(axios: AxiosInstance, appId: string) {
10+
const baseURL = `/app-logs/${appId}`;
11+
12+
return {
13+
/**
14+
* Log user activity in the app
15+
* @param {string} pageName - Name of the page being visited
16+
* @returns {Promise<void>}
17+
*/
18+
async logUserInApp(pageName: string): Promise<void> {
19+
await axios.post(`${baseURL}/log-user-in-app/${pageName}`);
20+
},
21+
22+
/**
23+
* Fetch app logs with optional parameters
24+
* @param {Object} params - Query parameters for filtering logs
25+
* @returns {Promise<any>} App logs data
26+
*/
27+
async fetchLogs(params: Record<string, any> = {}): Promise<any> {
28+
const response = await axios.get(baseURL, { params });
29+
return response;
30+
},
31+
32+
/**
33+
* Get app statistics
34+
* @param {Object} params - Query parameters for filtering stats
35+
* @returns {Promise<any>} App statistics
36+
*/
37+
async getStats(params: Record<string, any> = {}): Promise<any> {
38+
const response = await axios.get(`${baseURL}/stats`, { params });
39+
return response;
40+
},
41+
};
42+
}
43+

0 commit comments

Comments
 (0)