UNPKG

@enonic-types/lib-auditlog

Version:

Type definitions for lib-auditlog.

103 lines (102 loc) 3.35 kB
/** * Functions to log and find audit logs. * * @example * var auditLib = require('/lib/xp/auditlog'); * * @module audit */ declare global { interface XpLibraries { '/lib/xp/auditlog': typeof import('./auditlog'); } } import type { UserKey } from '@enonic-types/core'; export type { ScriptValue, UserKey } from '@enonic-types/core'; export interface AuditLogParams<Data extends Record<string, unknown>> { type: string; time?: string; source?: string; user?: UserKey; objects?: string[]; data?: Data; } export interface AuditLog<Data extends Record<string, unknown> = Record<string, unknown>> { _id: string; type: string; time: string; source: string; user: UserKey; objects: string[]; data: Data; } /** * This function creates a single audit log entry. * * The parameter 'type' is required and all other parameters are optional. * * @example-ref examples/auditlog/log.js * * @param {object} params JSON with the parameters. * @param {string} params.type Type of log entry. * @param {string} [params.time] Log entry timestamp. Defaults to now. * @param {string} [params.source] Log entry source. Defaults to the application ID. * @param {string} [params.user] Log entry user. Defaults to the user of current context. * @param {array} [params.objects] URIs to objects that relate to this log entry. Defaults to empty array. * @param {object} [params.data] Custom extra data for this log entry. Defaults to empty object. * * @returns {object} Audit log created as JSON. */ export declare function log<Data extends Record<string, unknown> = Record<string, unknown>>(params: AuditLogParams<Data>): AuditLog<Data>; export interface GetAuditLogParams { id: string; } /** * This function fetches an audit log. * * @example-ref examples/auditlog/get.js * * @param {object} params JSON with the parameters. * @param {string} params.id Id of the audit log. * * @returns {object} Audit log as JSON. */ export declare function get(params: GetAuditLogParams): AuditLog | null; export interface FindAuditLogParams { start?: number; count?: number; ids?: string[]; from?: string; to?: string; type?: string; source?: string; users?: string[]; objects?: string[]; } export interface AuditLogs { total: number; count: number; hits: AuditLog[]; } /** * This function searches for audit logs. * * All parameters are semi-optional, meaning that you should at least supply one * of them. If no parameters are supplied you will get an empty result. * * @example-ref examples/auditlog/find.js * * @param {object} params JSON with the parameters. * @param {number} [params.start=0] Start index (used for paging). * @param {number} [params.count=10] Number of contents to fetch. * @param {array} [params.ids] Filter by ids of audit logs. * @param {string} [params.from] Filter by logs younger than from. * @param {string} [params.to] Filter by logs older than to. * @param {string} [params.type] Filter by type. * @param {string} [params.source] Filter by source. * @param {array} [params.users] Filter by user keys. * @param {array} [params.objects] Filter by object URIs. * * @returns {object} Audit log search results. */ export declare function find(params: FindAuditLogParams): AuditLogs;