Skip to content

feat(audit): make route→type map config-driven instead of hardcoded #3413

@PierreBrisorgueil

Description

@PierreBrisorgueil

Problem

modules/audit/middlewares/audit.middleware.js hardcodes a map of route segments to entity type names:

const map = {
  auth: 'User',
  users: 'User',
  billing: 'Organization',
  tasks: 'Task',
};

This means adding audit support for a new module requires modifying core audit middleware — a violation of module isolation. Optional modules (tasks, billing) should not appear in core module code.

Fix

Move the map to config. Each module declares its own route → type mapping in its module config (e.g. tasks.development.config.js):

audit: {
  routeTypeMap: { tasks: 'Task' }
}

The audit middleware reads and merges all audit.routeTypeMap entries from config at startup. No code change needed to add a new module.

Migration note (MIGRATIONS.md)

  • Remove hardcoded entries from audit middleware
  • Each module that wants audit type labelling must add audit.routeTypeMap to its module config
  • Downstream projects: verify audit logs still show correct type names after upgrade

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions