Convert portal audit logs store to TS
This commit is contained in:
parent
5272bc4cd9
commit
da19c4b608
|
@ -1,43 +0,0 @@
|
|||
import { writable, get } from "svelte/store"
|
||||
import { API } from "api"
|
||||
import { licensing } from "stores/portal"
|
||||
|
||||
export function createAuditLogsStore() {
|
||||
const { subscribe, update } = writable({
|
||||
events: {},
|
||||
logs: {},
|
||||
})
|
||||
|
||||
async function search(opts = {}) {
|
||||
if (get(licensing).auditLogsEnabled) {
|
||||
const paged = await API.searchAuditLogs(opts)
|
||||
|
||||
update(state => {
|
||||
return { ...state, logs: { ...paged, opts } }
|
||||
})
|
||||
|
||||
return paged
|
||||
}
|
||||
}
|
||||
|
||||
async function getEventDefinitions() {
|
||||
const events = await API.getEventDefinitions()
|
||||
|
||||
update(state => {
|
||||
return { ...state, ...events }
|
||||
})
|
||||
}
|
||||
|
||||
function getDownloadUrl(opts = {}) {
|
||||
return API.getDownloadUrl(opts)
|
||||
}
|
||||
|
||||
return {
|
||||
subscribe,
|
||||
search,
|
||||
getEventDefinitions,
|
||||
getDownloadUrl,
|
||||
}
|
||||
}
|
||||
|
||||
export const auditLogs = createAuditLogsStore()
|
|
@ -0,0 +1,45 @@
|
|||
import { get } from "svelte/store"
|
||||
import { API } from "api"
|
||||
import { licensing } from "./licensing"
|
||||
import BudiStore from "../BudiStore"
|
||||
import {
|
||||
DownloadAuditLogsRequest,
|
||||
SearchAuditLogsRequest,
|
||||
SearchAuditLogsResponse,
|
||||
} from "@budibase/types"
|
||||
|
||||
interface PortalAuditLogsStore {
|
||||
events?: Record<string, string>
|
||||
logs?: SearchAuditLogsResponse
|
||||
}
|
||||
|
||||
export class AuditLogsStore extends BudiStore<PortalAuditLogsStore> {
|
||||
constructor() {
|
||||
super({})
|
||||
}
|
||||
|
||||
async search(opts: SearchAuditLogsRequest = {}) {
|
||||
if (get(licensing).auditLogsEnabled) {
|
||||
const res = await API.searchAuditLogs(opts)
|
||||
this.update(state => ({
|
||||
...state,
|
||||
logs: res,
|
||||
}))
|
||||
return res
|
||||
}
|
||||
}
|
||||
|
||||
async getEventDefinitions() {
|
||||
const res = await API.getEventDefinitions()
|
||||
this.update(state => ({
|
||||
...state,
|
||||
events: res.events,
|
||||
}))
|
||||
}
|
||||
|
||||
getDownloadUrl(opts: DownloadAuditLogsRequest = {}) {
|
||||
return API.getDownloadUrl(opts)
|
||||
}
|
||||
}
|
||||
|
||||
export const auditLogs = new AuditLogsStore()
|
|
@ -24,6 +24,7 @@ export const createLicensingStore = () => {
|
|||
scimEnabled: false,
|
||||
budibaseAIEnabled: false,
|
||||
customAIConfigsEnabled: false,
|
||||
auditLogsEnabled: false,
|
||||
// the currently used quotas from the db
|
||||
quotaUsage: undefined,
|
||||
// derived quota metrics for percentages used
|
||||
|
|
Loading…
Reference in New Issue