API Reference

auditLogExtension(options?: AuditLogOptions)

This is the main function for configuring and creating the extension.

  • options: An object for customizing the extension's behavior.

    • cls: (ClsService) - The ClsService instance from nestjs-cls to automatically retrieve the user ID from the request context.

    • blackList: (LogControlConfig) - An object that specifies which operations, models, or fine-grained model/operation combinations should not be logged.

    • whiteList: (LogControlConfig) - An object that specifies which operations, models, or fine-grained model/operation combinations should be logged.

LogControlConfig Explained

LogControlConfig is a powerful tool for specifying which database operations should be included or excluded from the audit log. It is used by both the blackList and whiteList options. The extension first checks if a blackList is provided. If it is, the whiteList is completely ignored.

The interface is defined as:

export type LogControlConfig = {
    operations: OperationType[];
    models: string[];
    finegrained: {
        model: string;
        operations: OperationType[];
    }[];
};

Here is a breakdown of each property:

Property

Type

Description

operations

OperationType[]

An array of operation types (CREATE, UPDATE`, DELETE, READ, OTHER). This allows you to apply a global rule to all models. For a blackList, it will exclude these operations everywhere. For a whiteList, it will only log these operations everywhere.

models

string[]

An array of model names from your Prisma schema. This allows you to apply a global rule to all operations on the specified models. For a blackList, it will exclude all operations on these models. For a whiteList, it will only log all operations on these models.

finegrained

{

model: string;

operations: OperationType[];

}[]

An array of objects for fine-grained control. Each object specifies a particular model and a list of operations to be included for that model only. This is the most specific way to control logging.

Last updated