add store and api funcs
This commit is contained in:
parent
00388c4b04
commit
6d60c27521
|
@ -0,0 +1,37 @@
|
|||
import { writable, get } from "svelte/store"
|
||||
import { API } from "api"
|
||||
import { licensing } from "stores/portal"
|
||||
|
||||
export function createAuditLogsStore() {
|
||||
const { subscribe, set } = writable({
|
||||
logs: [],
|
||||
})
|
||||
|
||||
async function search(opts = {}) {
|
||||
if (get(licensing).auditLogsEnabled) {
|
||||
const paged = await API.searchAuditLogs(opts)
|
||||
set({
|
||||
...paged,
|
||||
...opts,
|
||||
})
|
||||
return paged
|
||||
}
|
||||
}
|
||||
|
||||
async function getEventDefinitions() {
|
||||
return await API.getEventDefinitions()
|
||||
}
|
||||
|
||||
async function downloadLogs(opts = {}) {
|
||||
return await API.downloadLogs(opts)
|
||||
}
|
||||
|
||||
return {
|
||||
subscribe,
|
||||
search,
|
||||
getEventDefinitions,
|
||||
downloadLogs,
|
||||
}
|
||||
}
|
||||
|
||||
export const environment = createAuditLogsStore()
|
|
@ -0,0 +1,58 @@
|
|||
const buildOpts = ({
|
||||
userIds,
|
||||
appIds,
|
||||
startDate,
|
||||
endDate,
|
||||
metadataSearch,
|
||||
event,
|
||||
}) => {
|
||||
const opts = {}
|
||||
|
||||
if (startDate && endDate) {
|
||||
opts.startDate = startDate
|
||||
opts.endDate = endDate
|
||||
}
|
||||
|
||||
if (metadataSearch) {
|
||||
opts.metadataSearch = metadataSearch
|
||||
}
|
||||
|
||||
if (event) {
|
||||
opts.event = event
|
||||
}
|
||||
|
||||
if (userIds) {
|
||||
opts.userId = userIds
|
||||
}
|
||||
|
||||
if (appIds) {
|
||||
opts.appId = 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/auditlogs/search`,
|
||||
body: buildOpts(opts),
|
||||
})
|
||||
},
|
||||
|
||||
getEventDefinitions: async () => {
|
||||
return await API.get({
|
||||
url: `/api/auditlogs/definitions`,
|
||||
})
|
||||
},
|
||||
|
||||
downloadLogs: async opts => {
|
||||
return await API.post({
|
||||
url: `/api/auditlogs/definitions`,
|
||||
body: buildOpts(opts),
|
||||
})
|
||||
},
|
||||
})
|
|
@ -28,6 +28,8 @@ import { buildPluginEndpoints } from "./plugins"
|
|||
import { buildBackupsEndpoints } from "./backups"
|
||||
import { buildEnvironmentVariableEndpoints } from "./environmentVariables"
|
||||
import { buildEventEndpoints } from "./events"
|
||||
import { buildAuditLogsEndpoints } from "./auditLogs"
|
||||
|
||||
const defaultAPIClientConfig = {
|
||||
/**
|
||||
* Certain definitions can't change at runtime for client apps, such as the
|
||||
|
@ -250,5 +252,6 @@ export const createAPIClient = config => {
|
|||
...buildBackupsEndpoints(API),
|
||||
...buildEnvironmentVariableEndpoints(API),
|
||||
...buildEventEndpoints(API),
|
||||
...buildAuditLogsEndpoints(API),
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue