Some updates to add in the audit log DB.

This commit is contained in:
mike12345567 2023-02-13 18:16:13 +00:00
parent d0fda67046
commit 46e9bf1443
5 changed files with 25 additions and 4 deletions

View File

@ -68,6 +68,7 @@ export enum DocumentType {
MEM_VIEW = "view", MEM_VIEW = "view",
USER_FLAG = "flag", USER_FLAG = "flag",
AUTOMATION_METADATA = "meta_au", AUTOMATION_METADATA = "meta_au",
AUDIT_LOG = "al",
} }
export const StaticDatabases = { export const StaticDatabases = {
@ -88,6 +89,9 @@ export const StaticDatabases = {
install: "install", install: "install",
}, },
}, },
AUDIT_LOGS: {
name: "audit-logs",
},
} }
export const APP_PREFIX = DocumentType.APP + SEPARATOR export const APP_PREFIX = DocumentType.APP + SEPARATOR

View File

@ -30,6 +30,13 @@ export function getGlobalDBName(tenantId?: string) {
return baseGlobalDBName(tenantId) return baseGlobalDBName(tenantId)
} }
export function getAuditLogDBName(tenantId?: string) {
if (!tenantId) {
tenantId = getTenantId()
}
return `${tenantId}${SEPARATOR}${StaticDatabases.AUDIT_LOGS.name}`
}
export function baseGlobalDBName(tenantId: string | undefined | null) { export function baseGlobalDBName(tenantId: string | undefined | null) {
let dbName let dbName
if (!tenantId || tenantId === DEFAULT_TENANT_ID) { if (!tenantId || tenantId === DEFAULT_TENANT_ID) {
@ -228,6 +235,13 @@ export function getGlobalDB(): Database {
return getDB(baseGlobalDBName(context?.tenantId)) return getDB(baseGlobalDBName(context?.tenantId))
} }
export function getAuditLogsDB(): Database {
if (!getTenantId()) {
throw new Error("Audit log DB not found")
}
return getDB(getAuditLogDBName())
}
/** /**
* Gets the app database based on whatever the request * Gets the app database based on whatever the request
* contained, dev or prod. * contained, dev or prod.

View File

@ -1,7 +1,7 @@
import { Event, AuditedEventFriendlyName } from "../../../sdk" import { Event, AuditedEventFriendlyName } from "../../../sdk"
import { PaginationResponse, PaginationRequest } from "../" import { PaginationResponse, PaginationRequest } from "../"
export interface DownloadAuditLogsRequest { export interface AuditLogSearchParams {
userId?: string[] userId?: string[]
appId?: string[] appId?: string[]
event?: Event[] event?: Event[]
@ -10,9 +10,11 @@ export interface DownloadAuditLogsRequest {
metadataSearch?: string metadataSearch?: string
} }
export interface DownloadAuditLogsRequest extends AuditLogSearchParams {}
export interface SearchAuditLogsRequest export interface SearchAuditLogsRequest
extends PaginationRequest, extends PaginationRequest,
DownloadAuditLogsRequest {} AuditLogSearchParams {}
export interface SearchAuditLogsResponse extends PaginationResponse { export interface SearchAuditLogsResponse extends PaginationResponse {
data: { data: {

View File

@ -1,8 +1,8 @@
import { Document } from "../document" import { Document } from "../document"
import { Event } from "../../sdk" import { Event } from "../../sdk"
export interface AuditLogDocument extends Document { export interface AuditLogDoc extends Document {
appId: string appId?: string
event: Event event: Event
userId: string userId: string
timestamp: string timestamp: string

View File

@ -6,3 +6,4 @@ export * from "./quotas"
export * from "./schedule" export * from "./schedule"
export * from "./templates" export * from "./templates"
export * from "./environmentVariables" export * from "./environmentVariables"
export * from "./auditLogs"