Update audit logs endpoints to use TS
This commit is contained in:
parent
9c35a7758c
commit
544e3a9da4
|
@ -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}`
|
||||
},
|
||||
})
|
|
@ -0,0 +1,70 @@
|
|||
import {
|
||||
SearchAuditLogsRequest,
|
||||
SearchAuditLogsResponse,
|
||||
DefinitionsAuditLogsResponse,
|
||||
DownloadAuditLogsRequest,
|
||||
} from "@budibase/types"
|
||||
import { BaseAPIClient } from "./types"
|
||||
|
||||
export interface AuditLogsEndpoints {
|
||||
searchAuditLogs: (
|
||||
opts: SearchAuditLogsRequest
|
||||
) => Promise<SearchAuditLogsResponse>
|
||||
getEventDefinitions: () => Promise<DefinitionsAuditLogsResponse>
|
||||
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}`
|
||||
},
|
||||
})
|
|
@ -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 }
|
||||
|
|
Loading…
Reference in New Issue