Some DB type updates (typing dump function) and adding in main audit log event publishers.

This commit is contained in:
mike12345567 2023-02-21 14:56:38 +00:00
parent 59afdc94d4
commit b48acd8cf4
8 changed files with 72 additions and 5 deletions

View File

@ -0,0 +1,26 @@
import {
Event,
AuditLogSearchParams,
AuditLogFilterEvent,
AuditLogDownloadEvent,
} from "@budibase/types"
import { publishEvent } from "../events"
async function filtered(search: AuditLogSearchParams) {
const properties: AuditLogFilterEvent = {
filters: search,
}
await publishEvent(Event.AUDIT_LOG_FILTER, properties)
}
async function download(search: AuditLogSearchParams) {
const properties: AuditLogDownloadEvent = {
filters: search,
}
await publishEvent(Event.AUDIT_LOG_DOWNLOAD, properties)
}
export default {
filtered,
download,
}

View File

@ -21,3 +21,4 @@ export { default as group } from "./group"
export { default as plugin } from "./plugin"
export { default as backup } from "./backup"
export { default as environmentVariable } from "./environmentVariable"
export { default as auditLog } from "./auditLog"

View File

@ -1,5 +1,9 @@
import { Event, AuditedEventFriendlyName } from "../../../sdk"
import { PaginationResponse, PaginationRequest } from "../"
import {
PaginationResponse,
PaginationRequest,
BasicPaginationRequest,
} from "../"
import { User, App } from "../../../"
export interface AuditLogSearchParams {
@ -9,12 +13,13 @@ export interface AuditLogSearchParams {
startDate?: string
endDate?: string
fullSearch?: string
bookmark?: string
}
export interface DownloadAuditLogsRequest extends AuditLogSearchParams {}
export interface SearchAuditLogsRequest
extends PaginationRequest,
extends BasicPaginationRequest,
AuditLogSearchParams {}
export enum AuditLogResourceStatus {

View File

@ -8,9 +8,12 @@ export enum SortType {
number = "number",
}
export interface PaginationRequest {
limit?: number
export interface BasicPaginationRequest {
bookmark?: string
}
export interface PaginationRequest extends BasicPaginationRequest {
limit?: number
sort?: {
order: SortOrder
column: string

View File

@ -1,5 +1,6 @@
import Nano from "@budibase/nano"
import { AllDocsResponse, AnyDocument, Document } from "../"
import { Writable } from "stream"
export type PouchOptions = {
inMemory?: boolean
@ -63,6 +64,18 @@ export const isDocument = (doc: any): doc is Document => {
return typeof doc === "object" && doc._id && doc._rev
}
export interface DatabaseDumpOpts {
filter?: (doc: AnyDocument) => boolean
batch_size?: number
batch_limit?: number
style?: "main_only" | "all_docs"
timeout?: number
doc_ids?: string[]
query_params?: any
view?: string
selector?: any
}
export interface Database {
name: string
@ -87,7 +100,7 @@ export interface Database {
compact(): Promise<Nano.OkResponse | void>
// these are all PouchDB related functions that are rarely used - in future
// should be replaced by better typed/non-pouch implemented methods
dump(...args: any[]): Promise<any>
dump(stream: Writable, opts?: DatabaseDumpOpts): Promise<any>
load(...args: any[]): Promise<any>
createIndex(...args: any[]): Promise<any>
deleteIndex(...args: any[]): Promise<any>

View File

@ -0,0 +1,10 @@
import { BaseEvent } from "./event"
import { AuditLogSearchParams } from "../../api"
export interface AuditLogFilterEvent extends BaseEvent {
filters: AuditLogSearchParams
}
export interface AuditLogDownloadEvent extends BaseEvent {
filters: AuditLogSearchParams
}

View File

@ -180,6 +180,10 @@ export enum Event {
ENVIRONMENT_VARIABLE_CREATED = "environment_variable:created",
ENVIRONMENT_VARIABLE_DELETED = "environment_variable:deleted",
ENVIRONMENT_VARIABLE_UPGRADE_PANEL_OPENED = "environment_variable:upgrade_panel_opened",
// AUDIT LOG
AUDIT_LOG_FILTER = "audit_log:filter",
AUDIT_LOG_DOWNLOAD = "audit_log:download",
}
// all events that are not audited have been added to this record as undefined, this means
@ -356,6 +360,10 @@ export const AuditedEventFriendlyName: Record<Event, string | undefined> = {
[Event.INSTALLATION_VERSION_UPGRADED]: undefined,
[Event.INSTALLATION_VERSION_DOWNGRADED]: undefined,
[Event.INSTALLATION_FIRST_STARTUP]: undefined,
// AUDIT LOG - NOT AUDITED
[Event.AUDIT_LOG_FILTER]: undefined,
[Event.AUDIT_LOG_DOWNLOAD]: undefined,
}
// properties added at the final stage of the event pipeline

View File

@ -22,3 +22,4 @@ export * from "./userGroup"
export * from "./plugin"
export * from "./backup"
export * from "./environmentVariable"
export * from "./auditLog"