diff --git a/packages/frontend-core/src/api/auditLogs.js b/packages/frontend-core/src/api/auditLogs.js deleted file mode 100644 index c4230df6d9..0000000000 --- a/packages/frontend-core/src/api/auditLogs.js +++ /dev/null @@ -1,63 +0,0 @@ -const buildOpts = ({ - bookmark, - userIds, - appIds, - startDate, - endDate, - fullSearch, - events, -}) => { - const opts = {} - - if (bookmark) { - opts.bookmark = bookmark - } - - if (startDate && endDate) { - opts.startDate = startDate - opts.endDate = endDate - } else if (startDate && !endDate) { - opts.startDate = startDate - } - - if (fullSearch) { - opts.fullSearch = fullSearch - } - - if (events.length) { - opts.events = events - } - - if (userIds.length) { - opts.userIds = userIds - } - - if (appIds.length) { - opts.appIds = appIds - } - - return opts -} - -export const buildAuditLogsEndpoints = API => ({ - /** - * Gets a list of users in the current tenant. - */ - searchAuditLogs: async opts => { - return await API.post({ - url: `/api/global/auditlogs/search`, - body: buildOpts(opts), - }) - }, - - getEventDefinitions: async () => { - return await API.get({ - url: `/api/global/auditlogs/definitions`, - }) - }, - - getDownloadUrl: opts => { - const query = encodeURIComponent(JSON.stringify(opts)) - return `/api/global/auditlogs/download?query=${query}` - }, -}) diff --git a/packages/frontend-core/src/api/auditLogs.ts b/packages/frontend-core/src/api/auditLogs.ts new file mode 100644 index 0000000000..eeb922f981 --- /dev/null +++ b/packages/frontend-core/src/api/auditLogs.ts @@ -0,0 +1,70 @@ +import { + SearchAuditLogsRequest, + SearchAuditLogsResponse, + DefinitionsAuditLogsResponse, + DownloadAuditLogsRequest, +} from "@budibase/types" +import { BaseAPIClient } from "./types" + +export interface AuditLogsEndpoints { + searchAuditLogs: ( + opts: SearchAuditLogsRequest + ) => Promise + getEventDefinitions: () => Promise + getDownloadUrl: (opts: DownloadAuditLogsRequest) => string +} + +const buildOpts = (opts: SearchAuditLogsRequest) => { + const { bookmark, startDate, endDate, fullSearch, events, userIds, appIds } = + opts + const parsedOpts: SearchAuditLogsRequest = {} + + if (bookmark) { + parsedOpts.bookmark = bookmark + } + + if (opts.startDate && endDate) { + parsedOpts.startDate = startDate + parsedOpts.endDate = endDate + } else if (startDate && !endDate) { + parsedOpts.startDate = startDate + } + + if (fullSearch) { + parsedOpts.fullSearch = fullSearch + } + + if (events?.length) { + parsedOpts.events = events + } + + if (userIds?.length) { + parsedOpts.userIds = userIds + } + + if (appIds?.length) { + parsedOpts.appIds = appIds + } + + return parsedOpts +} + +export const buildAuditLogsEndpoints = ( + API: BaseAPIClient +): AuditLogsEndpoints => ({ + searchAuditLogs: async opts => { + return await API.post({ + url: `/api/global/auditlogs/search`, + body: buildOpts(opts), + }) + }, + getEventDefinitions: async () => { + return await API.get({ + url: `/api/global/auditlogs/definitions`, + }) + }, + getDownloadUrl: opts => { + const query = encodeURIComponent(JSON.stringify(opts)) + return `/api/global/auditlogs/download?query=${query}` + }, +}) diff --git a/packages/frontend-core/src/api/types.ts b/packages/frontend-core/src/api/types.ts index 350deb4e90..db8cb4578c 100644 --- a/packages/frontend-core/src/api/types.ts +++ b/packages/frontend-core/src/api/types.ts @@ -1,6 +1,8 @@ import { AIEndpoints } from "./ai" import { AnalyticsEndpoints } from "./analytics" import { AppEndpoints } from "./app" +import { AttachmentEndpoints } from "./attachments" +import { AuditLogsEndpoints } from "./auditLogs" export enum HTTPMethod { POST = "POST", @@ -46,4 +48,6 @@ export type BaseAPIClient = { export type APIClient = BaseAPIClient & AIEndpoints & AnalyticsEndpoints & - AppEndpoints & { [key: string]: any } + AppEndpoints & + AttachmentEndpoints & + AuditLogsEndpoints & { [key: string]: any }