Updating types for audit logs to correctly handle the deletion of resources like users or apps.
This commit is contained in:
parent
49d2dc20d1
commit
70e525b928
|
@ -13,7 +13,7 @@ interface PaginatedSearchResponse<T> extends SearchResponse<T> {
|
||||||
hasNextPage: boolean
|
hasNextPage: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
export type SearchParams = {
|
export type SearchParams<T> = {
|
||||||
tableId?: string
|
tableId?: string
|
||||||
sort?: string
|
sort?: string
|
||||||
sortOrder?: string
|
sortOrder?: string
|
||||||
|
@ -23,7 +23,7 @@ export type SearchParams = {
|
||||||
version?: string
|
version?: string
|
||||||
indexer?: () => Promise<any>
|
indexer?: () => Promise<any>
|
||||||
disableEscaping?: boolean
|
disableEscaping?: boolean
|
||||||
rows?: Row[]
|
rows?: T | Row[]
|
||||||
}
|
}
|
||||||
|
|
||||||
export function removeKeyNumbering(key: any): string {
|
export function removeKeyNumbering(key: any): string {
|
||||||
|
@ -502,7 +502,7 @@ async function recursiveSearch<T>(
|
||||||
if (rows.length > params.limit - 200) {
|
if (rows.length > params.limit - 200) {
|
||||||
pageSize = params.limit - rows.length
|
pageSize = params.limit - rows.length
|
||||||
}
|
}
|
||||||
const page = await new QueryBuilder<T | Row>(dbName, index, query)
|
const page = await new QueryBuilder<T>(dbName, index, query)
|
||||||
.setVersion(params.version)
|
.setVersion(params.version)
|
||||||
.setTable(params.tableId)
|
.setTable(params.tableId)
|
||||||
.setBookmark(bookmark)
|
.setBookmark(bookmark)
|
||||||
|
@ -546,14 +546,14 @@ export async function paginatedSearch<T>(
|
||||||
dbName: string,
|
dbName: string,
|
||||||
index: string,
|
index: string,
|
||||||
query: SearchFilters,
|
query: SearchFilters,
|
||||||
params: SearchParams
|
params: SearchParams<T>
|
||||||
) {
|
) {
|
||||||
let limit = params.limit
|
let limit = params.limit
|
||||||
if (limit == null || isNaN(limit) || limit < 0) {
|
if (limit == null || isNaN(limit) || limit < 0) {
|
||||||
limit = 50
|
limit = 50
|
||||||
}
|
}
|
||||||
limit = Math.min(limit, 200)
|
limit = Math.min(limit, 200)
|
||||||
const search = new QueryBuilder<T | Row>(dbName, index, query)
|
const search = new QueryBuilder<T>(dbName, index, query)
|
||||||
if (params.version) {
|
if (params.version) {
|
||||||
search.setVersion(params.version)
|
search.setVersion(params.version)
|
||||||
}
|
}
|
||||||
|
@ -612,13 +612,13 @@ export async function fullSearch<T>(
|
||||||
dbName: string,
|
dbName: string,
|
||||||
index: string,
|
index: string,
|
||||||
query: SearchFilters,
|
query: SearchFilters,
|
||||||
params: SearchParams
|
params: SearchParams<T>
|
||||||
) {
|
) {
|
||||||
let limit = params.limit
|
let limit = params.limit
|
||||||
if (limit == null || isNaN(limit) || limit < 0) {
|
if (limit == null || isNaN(limit) || limit < 0) {
|
||||||
limit = 1000
|
limit = 1000
|
||||||
}
|
}
|
||||||
params.limit = Math.min(limit, 1000)
|
params.limit = Math.min(limit, 1000)
|
||||||
const rows = await recursiveSearch<T | Row>(dbName, index, query, params)
|
const rows = await recursiveSearch<T>(dbName, index, query, params)
|
||||||
return { rows }
|
return { rows }
|
||||||
}
|
}
|
||||||
|
|
|
@ -366,6 +366,16 @@ export async function getAllApps({
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function getAppsById(appIds: string[]) {
|
||||||
|
const settled = await Promise.allSettled(
|
||||||
|
appIds.map(appId => getAppMetadata(appId))
|
||||||
|
)
|
||||||
|
// have to list the apps which exist, some may have been deleted
|
||||||
|
return settled
|
||||||
|
.filter(promise => promise.status === "fulfilled")
|
||||||
|
.map(promise => (promise as PromiseFulfilledResult<App>).value)
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Utility function for getAllApps but filters to production apps only.
|
* Utility function for getAllApps but filters to production apps only.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import { Event, AuditedEventFriendlyName } from "../../../sdk"
|
import { Event, AuditedEventFriendlyName } from "../../../sdk"
|
||||||
import { PaginationResponse, PaginationRequest } from "../"
|
import { PaginationResponse, PaginationRequest } from "../"
|
||||||
|
import { User, App } from "../../../"
|
||||||
|
|
||||||
export interface AuditLogSearchParams {
|
export interface AuditLogSearchParams {
|
||||||
userId?: string[]
|
userId?: string[]
|
||||||
|
@ -16,15 +17,13 @@ export interface SearchAuditLogsRequest
|
||||||
extends PaginationRequest,
|
extends PaginationRequest,
|
||||||
AuditLogSearchParams {}
|
AuditLogSearchParams {}
|
||||||
|
|
||||||
|
export enum AuditLogResourceStatus {
|
||||||
|
DELETED = "deleted",
|
||||||
|
}
|
||||||
|
|
||||||
export interface AuditLogEnriched {
|
export interface AuditLogEnriched {
|
||||||
app: {
|
app?: App | { _id: string; status: AuditLogResourceStatus }
|
||||||
_id: string
|
user: User | { _id: string; status: AuditLogResourceStatus }
|
||||||
name: string
|
|
||||||
}
|
|
||||||
user: {
|
|
||||||
_id: string
|
|
||||||
name: string
|
|
||||||
}
|
|
||||||
event: Event
|
event: Event
|
||||||
timestamp: string
|
timestamp: string
|
||||||
name: string
|
name: string
|
||||||
|
|
Loading…
Reference in New Issue