logologo
Get Started
Guide
Development
Plugins
API
Home
English
简体中文
日本語
한국어
Español
Português
Deutsch
Français
Русский
Italiano
Türkçe
Українська
Tiếng Việt
Bahasa Indonesia
ไทย
Polski
Nederlands
Čeština
العربية
עברית
हिन्दी
Svenska
Get Started
Guide
Development
Plugins
API
Home
logologo
API Overview

@nocobase/auth

AuthManager
Auth
BaseAuth

@nocobase/cli

NocoBase CLI
Global Environment Variables

@nocobase/client

Application
Plugin

@nocobase/database

Collection
Field

interfaces

BaseInterface
Filter Operators

RelationRepository

BelongsToManyRepository
belongs-to-repository
HasManyRepository
HasOneRepository
Repository

shared

create-options
destroy-options
find-one
find-options
transaction
update-options

@nocobase/flow-engine

DataSourceManager
FlowContext
FlowEngine
FlowModel
FlowResource

@nocobase/server

AppCommand
Application
AuditManager
Context
Migration
Plugin

@nocobase/sdk

Auth
Storage

@nocobase/telemetry

Metric
Telemetry
Trace
Previous PageApplication
Next PageContext

#AuditManager

#Overview

AuditManager is the resource audit management module in NocoBase, used to register resource interfaces that need to be audited.

#Basic Usage

import { Plugin } from '@nocobase/server';

class PluginCustomAuditResourceServer extends Plugin {
  async load() {
    this.app.auditManager.registerAction('resource:action');
  }
}

#Class Methods

#setLogger()

Sets the output method for audit logs.

const auditManager = new AuditManager();
auditManager.setLogger({
  log: async (auditLog: AuditLog) => console.log(auditLog);
})

#Signature

  • setLogger(logger: AuditLogger)

#Type

export interface AuditLog {
  uuid: string;
  dataSource: string;
  resource: string;
  action: string;
  sourceCollection?: string;
  sourceRecordUK?: string;
  targetCollection?: string;
  targetRecordUK?: string;
  userId: string;
  roleName: string;
  ip: string;
  ua: string;
  status: number;
  metadata?: Record<string, any>;
}

export interface AuditLogger {
  log(auditLog: AuditLog): Promise<void>;
}

#registerAction()

Registers a resource action to be audited.

#Signature

  • registerAction(action: Action)

#Type

export interface UserInfo {
  userId?: string;
  roleName?: string;
}

export interface SourceAndTarget {
  sourceCollection?: string;
  sourceRecordUK?: string;
  targetCollection?: string;
  targetRecordUK?: string;
}

type Action =
  | string
  | {
      name: string;
      getMetaData?: (ctx: Context) => Promise<Record<string, any>>;
      getUserInfo?: (ctx: Context) => Promise<UserInfo>;
      getSourceAndTarget?: (ctx: Context) => Promise<SourceAndTarget>;
    };

#Details

Several writing styles are supported:

  1. Apply to all resources
registerActions(['create']);
  1. Apply to all actions of a specific resource resource:*
registerActions(['app:*']);
  1. Apply to a specific action of a specific resource resource:action
registerAction(['pm:update']);
  1. Supports passing custom getMetaData, getUserInfo, and getSourceAndTarget methods for the action
registerActions([
  'create',
  { name: 'auth:signIn', getMetaData, getUserInfo, getSourceAndTarget },
]);

When registered interfaces overlap, the more specific registration method has higher priority. For example:

  1. registerActions('create')

  2. registerAction({ name: 'user:*', getMetaData })

  3. registerAction({ name: 'user:create', getMetaData })

For the user:create interface, 3 will take effect.

#registerActions()

Registers multiple resource actions to be audited.

#Signature

  • registerActions(actions: Action[])