@mostajs/audit 2.1.1 → 2.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +29 -21
- package/dist/index.d.ts +1 -0
- package/dist/index.js +2 -0
- package/dist/lib/debug-log.d.ts +16 -0
- package/dist/lib/debug-log.js +69 -0
- package/package.json +2 -2
package/LICENSE
CHANGED
|
@@ -1,21 +1,29 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
1
|
+
GNU AFFERO GENERAL PUBLIC LICENSE
|
|
2
|
+
Version 3, 19 November 2007
|
|
3
|
+
|
|
4
|
+
Copyright (c) 2026 Dr Hamid MADANI <drmdh@msn.com>
|
|
5
|
+
|
|
6
|
+
This program is free software: you can redistribute it and/or modify
|
|
7
|
+
it under the terms of the GNU Affero General Public License as published by
|
|
8
|
+
the Free Software Foundation, either version 3 of the License, or
|
|
9
|
+
(at your option) any later version.
|
|
10
|
+
|
|
11
|
+
This program is distributed in the hope that it will be useful,
|
|
12
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
13
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
14
|
+
GNU Affero General Public License for more details.
|
|
15
|
+
|
|
16
|
+
You should have received a copy of the GNU Affero General Public License
|
|
17
|
+
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
18
|
+
|
|
19
|
+
COMMERCIAL LICENSE
|
|
20
|
+
|
|
21
|
+
For organizations that cannot comply with the AGPL open-source requirements,
|
|
22
|
+
a commercial license is available. Contact: drmdh@msn.com
|
|
23
|
+
|
|
24
|
+
The commercial license allows you to:
|
|
25
|
+
- Use the software in proprietary/closed-source projects
|
|
26
|
+
- Modify without publishing your source code
|
|
27
|
+
- Get priority support and SLA
|
|
28
|
+
|
|
29
|
+
Contact: Dr Hamid MADANI <drmdh@msn.com>
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { logAudit, getAuditUser } from './lib/audit';
|
|
2
|
+
export { dlog, dwarn, createLogger, isDebugEnabled, type ScopedLogger } from './lib/debug-log';
|
|
2
3
|
export { AuditLogRepository } from './repositories/audit-log.repository';
|
|
3
4
|
export { AuditLogSchema } from './schemas/audit-log.schema';
|
|
4
5
|
export { createAuditHandlers } from './api/route';
|
package/dist/index.js
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
// Author: Dr Hamid MADANI drmdh@msn.com
|
|
3
3
|
// Core
|
|
4
4
|
export { logAudit, getAuditUser } from './lib/audit';
|
|
5
|
+
// Volatile debug logger (complement de logAudit pour la trace pm2/stdout)
|
|
6
|
+
export { dlog, dwarn, createLogger, isDebugEnabled } from './lib/debug-log';
|
|
5
7
|
// Repository & Schema
|
|
6
8
|
export { AuditLogRepository } from './repositories/audit-log.repository';
|
|
7
9
|
export { AuditLogSchema } from './schemas/audit-log.schema';
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/** Log debug — actif uniquement si MOSTAJS_DEBUG=1 ou hors prod. */
|
|
2
|
+
export declare function dlog(scope: string, data: Record<string, unknown>): void;
|
|
3
|
+
/** Log warning — toujours actif (utile en prod pour les erreurs critiques). */
|
|
4
|
+
export declare function dwarn(scope: string, data: Record<string, unknown>): void;
|
|
5
|
+
export interface ScopedLogger {
|
|
6
|
+
dlog: (scope: string, data: Record<string, unknown>) => void;
|
|
7
|
+
dwarn: (scope: string, data: Record<string, unknown>) => void;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Crée un logger avec un préfixe namespace fixe — utile pour différencier
|
|
11
|
+
* les apps qui consomment le module dans le même environnement
|
|
12
|
+
* (ex: pm2 logs avec plusieurs services partageant la même console).
|
|
13
|
+
*/
|
|
14
|
+
export declare function createLogger(namespace: string): ScopedLogger;
|
|
15
|
+
/** Pour les tests ou les apps qui veulent contrôler l'activation. */
|
|
16
|
+
export declare function isDebugEnabled(): boolean;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
// @mosta/audit — Volatile debug logger
|
|
2
|
+
// Author: Dr Hamid MADANI <drmdh@msn.com>
|
|
3
|
+
//
|
|
4
|
+
// Logger de debug structuré complémentaire de `logAudit` :
|
|
5
|
+
// - `logAudit` persiste en DB → traçabilité long-terme, consultation /admin.
|
|
6
|
+
// - `dlog` / `dwarn` poussent sur stdout/stderr → grep en pm2 logs, désactivable.
|
|
7
|
+
//
|
|
8
|
+
// Activation :
|
|
9
|
+
// - Si `MOSTAJS_DEBUG=1` ou `=true` → activé (toutes envs).
|
|
10
|
+
// - Si `MOSTAJS_DEBUG=0` ou `=false` → désactivé explicitement.
|
|
11
|
+
// - Sinon : activé en non-production (`NODE_ENV !== 'production'`).
|
|
12
|
+
//
|
|
13
|
+
// Usage générique :
|
|
14
|
+
// ```ts
|
|
15
|
+
// import { dlog, dwarn } from '@mostajs/audit'
|
|
16
|
+
// dlog('myapp.scope', { key: 'value' }) // → [myapp.scope] { ... }
|
|
17
|
+
// ```
|
|
18
|
+
//
|
|
19
|
+
// Usage avec namespace dédié à une app :
|
|
20
|
+
// ```ts
|
|
21
|
+
// import { createLogger } from '@mostajs/audit'
|
|
22
|
+
// export const { dlog, dwarn } = createLogger('iquesta')
|
|
23
|
+
// // dlog('magic.enter', { ... }) → [iquesta.magic.enter] { ... }
|
|
24
|
+
// ```
|
|
25
|
+
const ENABLED = (() => {
|
|
26
|
+
const flag = process.env.MOSTAJS_DEBUG;
|
|
27
|
+
if (flag === '1' || flag === 'true')
|
|
28
|
+
return true;
|
|
29
|
+
if (flag === '0' || flag === 'false')
|
|
30
|
+
return false;
|
|
31
|
+
return process.env.NODE_ENV !== 'production';
|
|
32
|
+
})();
|
|
33
|
+
function emit(level, scope, data) {
|
|
34
|
+
// dwarn s'affiche même en prod (utile pour les erreurs critiques).
|
|
35
|
+
// dlog est gated par ENABLED.
|
|
36
|
+
if (level === 'info' && !ENABLED)
|
|
37
|
+
return;
|
|
38
|
+
const payload = { ts: new Date().toISOString(), ...data };
|
|
39
|
+
const target = level === 'warn' ? console.warn : console.info;
|
|
40
|
+
try {
|
|
41
|
+
target(`[${scope}]`, JSON.stringify(payload));
|
|
42
|
+
}
|
|
43
|
+
catch {
|
|
44
|
+
target(`[${scope}]`, payload);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
/** Log debug — actif uniquement si MOSTAJS_DEBUG=1 ou hors prod. */
|
|
48
|
+
export function dlog(scope, data) {
|
|
49
|
+
emit('info', scope, data);
|
|
50
|
+
}
|
|
51
|
+
/** Log warning — toujours actif (utile en prod pour les erreurs critiques). */
|
|
52
|
+
export function dwarn(scope, data) {
|
|
53
|
+
emit('warn', scope, data);
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Crée un logger avec un préfixe namespace fixe — utile pour différencier
|
|
57
|
+
* les apps qui consomment le module dans le même environnement
|
|
58
|
+
* (ex: pm2 logs avec plusieurs services partageant la même console).
|
|
59
|
+
*/
|
|
60
|
+
export function createLogger(namespace) {
|
|
61
|
+
return {
|
|
62
|
+
dlog: (scope, data) => emit('info', `${namespace}.${scope}`, data),
|
|
63
|
+
dwarn: (scope, data) => emit('warn', `${namespace}.${scope}`, data),
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
/** Pour les tests ou les apps qui veulent contrôler l'activation. */
|
|
67
|
+
export function isDebugEnabled() {
|
|
68
|
+
return ENABLED;
|
|
69
|
+
}
|
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mostajs/audit",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.2.0",
|
|
4
4
|
"description": "Reusable audit logging module — fire-and-forget logAudit() with paginated consultation",
|
|
5
5
|
"author": "Dr Hamid MADANI <drmdh@msn.com>",
|
|
6
|
-
"license": "
|
|
6
|
+
"license": "AGPL-3.0-or-later",
|
|
7
7
|
"type": "module",
|
|
8
8
|
"main": "dist/index.js",
|
|
9
9
|
"types": "dist/index.d.ts",
|