UNPKG

@kitstack/nest-powertools

Version:

A comprehensive collection of NestJS powertools, decorators, and utilities to supercharge your backend development

73 lines (72 loc) 4.87 kB
import { type NestInterceptor, type ExecutionContext, type CallHandler } from '@nestjs/common'; import type { Observable } from 'rxjs'; import type { AuditConfig, AuditLogEntry, AuditStorage, PaginatedResponse } from '../types/generics'; import { AuditAction } from '../types/enums'; export declare class MongoAuditStorage<TUser = any, TMetadata = any> implements AuditStorage<AuditLogEntry<TUser, TMetadata>> { private readonly logger; save(entry: AuditLogEntry<TUser, TMetadata>): Promise<void>; find(filters: Partial<AuditLogEntry<TUser, TMetadata>>, pagination?: any): Promise<PaginatedResponse<AuditLogEntry<TUser, TMetadata>>>; findById(id: string): Promise<AuditLogEntry<TUser, TMetadata> | null>; count(filters: Partial<AuditLogEntry<TUser, TMetadata>>): Promise<number>; delete(id: string): Promise<boolean>; deleteMany(filters: Partial<AuditLogEntry<TUser, TMetadata>>): Promise<number>; } export declare class InMemoryAuditStorage<TUser = any, TMetadata = any> implements AuditStorage<AuditLogEntry<TUser, TMetadata>> { private logs; private readonly logger; save(entry: AuditLogEntry<TUser, TMetadata>): Promise<void>; find(filters: Partial<AuditLogEntry<TUser, TMetadata>>, pagination?: any): Promise<PaginatedResponse<AuditLogEntry<TUser, TMetadata>>>; findById(id: string): Promise<AuditLogEntry<TUser, TMetadata> | null>; count(filters: Partial<AuditLogEntry<TUser, TMetadata>>): Promise<number>; delete(id: string): Promise<boolean>; deleteMany(filters: Partial<AuditLogEntry<TUser, TMetadata>>): Promise<number>; getAllLogs(): AuditLogEntry<TUser, TMetadata>[]; clearLogs(): void; } export declare class FileAuditStorage<TUser = any, TMetadata = any> implements AuditStorage<AuditLogEntry<TUser, TMetadata>> { private readonly logger; private filePath; constructor(filePath?: string); save(entry: AuditLogEntry<TUser, TMetadata>): Promise<void>; find(filters: Partial<AuditLogEntry<TUser, TMetadata>>, pagination?: { page?: number; limit?: number; }): Promise<PaginatedResponse<AuditLogEntry<TUser, TMetadata>>>; findById(id: string): Promise<AuditLogEntry<TUser, TMetadata> | null>; count(filters: Partial<AuditLogEntry<TUser, TMetadata>>): Promise<number>; delete(id: string): Promise<boolean>; deleteMany(filters: Partial<AuditLogEntry<TUser, TMetadata>>): Promise<number>; } export declare function getAuditStorageFromConfig(): AuditStorage<any>; export declare class AuditInterceptor<TUser = any, TMetadata = any> implements NestInterceptor { private readonly auditStorage; private readonly logger; private readonly configService; constructor(auditStorage: AuditStorage<AuditLogEntry<TUser, TMetadata>>); intercept(context: ExecutionContext, next: CallHandler): Observable<any>; private getAuditConfig; private extractResourceFromContext; private extractResourceId; private sanitizeData; } export declare const Audit: <TUser = any, TMetadata = any>(action: AuditAction | string, options?: Omit<AuditConfig<TUser, TMetadata>, "action">) => MethodDecorator; export declare const AuditCreate: <TUser = any, TMetadata = any>(resource?: string, options?: Omit<AuditConfig<TUser, TMetadata>, "action" | "resource">) => MethodDecorator; export declare const AuditRead: <TUser = any, TMetadata = any>(resource?: string, options?: Omit<AuditConfig<TUser, TMetadata>, "action" | "resource">) => MethodDecorator; export declare const AuditUpdate: <TUser = any, TMetadata = any>(resource?: string, options?: Omit<AuditConfig<TUser, TMetadata>, "action" | "resource">) => MethodDecorator; export declare const AuditDelete: <TUser = any, TMetadata = any>(resource?: string, options?: Omit<AuditConfig<TUser, TMetadata>, "action" | "resource">) => MethodDecorator; export declare class AuditService<TUser = any, TMetadata = any> { private readonly auditStorage; constructor(auditStorage: AuditStorage<AuditLogEntry<TUser, TMetadata>>); getAuditLogs(filters?: Partial<AuditLogEntry<TUser, TMetadata>>, pagination?: any): Promise<PaginatedResponse<AuditLogEntry<TUser, TMetadata>>>; getAuditLogById(id: string): Promise<AuditLogEntry<TUser, TMetadata> | null>; getUserAuditLogs(userId: string, pagination?: any): Promise<PaginatedResponse<AuditLogEntry<TUser, TMetadata>>>; getResourceAuditLogs(resource: string, resourceId?: string, pagination?: any): Promise<PaginatedResponse<AuditLogEntry<TUser, TMetadata>>>; getAuditStats(): Promise<{ totalLogs: number; actionBreakdown: Record<string, number>; userBreakdown: Record<string, number>; recentActivity: AuditLogEntry<TUser, TMetadata>[]; }>; deleteAuditLog(id: string): Promise<boolean>; deleteAuditLogs(filters: Partial<AuditLogEntry<TUser, TMetadata>>): Promise<number>; }