// audit-log-readable-actions: mobile-api records an audited endpoint that declares no action as a readable // UPPER_SNAKE code (AppAccessAspect.defaultAuditAction). Events stored before that carry the raw // "XController.method" name; this derives the same code for display, so old and new events read alike. // Stored audit rows are never rewritten. const LEGACY_ACTION = /^([A-Za-z0-9]+)\.([A-Za-z0-9]+)$/; function upperSnake(camel: string): string { return camel .replace(/([a-z0-9])([A-Z])/g, "$1_$2") .replace(/([A-Z]+)([A-Z][a-z])/g, "$1_$2") .toUpperCase(); } export function displayAuditAction(action: string | null | undefined): string { if (!action) return ""; const legacy = LEGACY_ACTION.exec(action); if (!legacy) return action; let type = legacy[1]; if (type.endsWith("Controller") && type.length > "Controller".length) { type = type.slice(0, -"Controller".length); } if (type.startsWith("Admin") && type.length > "Admin".length) { type = type.slice("Admin".length); } return `${upperSnake(type)}_${upperSnake(legacy[2])}`; }