@x12i/logxer 4.0.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 +21 -0
- package/README.md +1255 -0
- package/dist/app-info.d.ts +25 -0
- package/dist/app-info.d.ts.map +1 -0
- package/dist/app-info.js +179 -0
- package/dist/app-info.js.map +1 -0
- package/dist/formatters/table-formatter.d.ts +23 -0
- package/dist/formatters/table-formatter.d.ts.map +1 -0
- package/dist/formatters/table-formatter.js +218 -0
- package/dist/formatters/table-formatter.js.map +1 -0
- package/dist/formatters/yaml-formatter.d.ts +14 -0
- package/dist/formatters/yaml-formatter.d.ts.map +1 -0
- package/dist/formatters/yaml-formatter.js +164 -0
- package/dist/formatters/yaml-formatter.js.map +1 -0
- package/dist/index.d.ts +44 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +219 -0
- package/dist/index.js.map +1 -0
- package/dist/logxer.d.ts +145 -0
- package/dist/logxer.d.ts.map +1 -0
- package/dist/logxer.js +811 -0
- package/dist/logxer.js.map +1 -0
- package/dist/outputs/shadow-sink.d.ts +83 -0
- package/dist/outputs/shadow-sink.d.ts.map +1 -0
- package/dist/outputs/shadow-sink.js +380 -0
- package/dist/outputs/shadow-sink.js.map +1 -0
- package/dist/outputs/unified-logger-output.d.ts +30 -0
- package/dist/outputs/unified-logger-output.d.ts.map +1 -0
- package/dist/outputs/unified-logger-output.js +125 -0
- package/dist/outputs/unified-logger-output.js.map +1 -0
- package/dist/sanitizer.d.ts +69 -0
- package/dist/sanitizer.d.ts.map +1 -0
- package/dist/sanitizer.js +507 -0
- package/dist/sanitizer.js.map +1 -0
- package/dist/trails/headers.d.ts +21 -0
- package/dist/trails/headers.d.ts.map +1 -0
- package/dist/trails/headers.js +121 -0
- package/dist/trails/headers.js.map +1 -0
- package/dist/trails/index.d.ts +59 -0
- package/dist/trails/index.d.ts.map +1 -0
- package/dist/trails/index.js +197 -0
- package/dist/trails/index.js.map +1 -0
- package/dist/types.d.ts +411 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +8 -0
- package/dist/types.js.map +1 -0
- package/dist/utils/debug-config.d.ts +19 -0
- package/dist/utils/debug-config.d.ts.map +1 -0
- package/dist/utils/debug-config.js +172 -0
- package/dist/utils/debug-config.js.map +1 -0
- package/dist/utils/package-logs-level.d.ts +40 -0
- package/dist/utils/package-logs-level.d.ts.map +1 -0
- package/dist/utils/package-logs-level.js +79 -0
- package/dist/utils/package-logs-level.js.map +1 -0
- package/docs/package-usage.md +155 -0
- package/docs/package.md +48 -0
- package/docs/upgrade-for-package-authors.md +85 -0
- package/package.json +98 -0
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* logs-gateway - Unified Logger Output Implementation
|
|
4
|
+
*
|
|
5
|
+
* This file handles integration with @x-developer/unified-logger for Papertrail/UDP/Console output.
|
|
6
|
+
*
|
|
7
|
+
* Note: This transport always receives structured data (JSON format) regardless of the
|
|
8
|
+
* configured logFormat setting. YAML formatting only applies to console and file outputs.
|
|
9
|
+
*/
|
|
10
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
+
exports.UnifiedLoggerOutput = void 0;
|
|
12
|
+
const unified_logger_1 = require("@x-developer/unified-logger");
|
|
13
|
+
const app_info_1 = require("../app-info");
|
|
14
|
+
/**
|
|
15
|
+
* Unified logger output handler
|
|
16
|
+
*/
|
|
17
|
+
class UnifiedLoggerOutput {
|
|
18
|
+
constructor(cfg) {
|
|
19
|
+
this.cfg = cfg;
|
|
20
|
+
this.initialized = false;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Initialize the unified logger if not already done
|
|
24
|
+
*/
|
|
25
|
+
ensureInit() {
|
|
26
|
+
if (this.initialized)
|
|
27
|
+
return;
|
|
28
|
+
try {
|
|
29
|
+
if (this.cfg.configPath) {
|
|
30
|
+
(0, unified_logger_1.initLogger)(this.cfg.configPath);
|
|
31
|
+
}
|
|
32
|
+
else if (this.cfg.configInline) {
|
|
33
|
+
(0, unified_logger_1.initLogger)(this.cfg.configInline);
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
// Create inline configuration
|
|
37
|
+
const inline = {
|
|
38
|
+
service: this.cfg.service ?? 'logs-gateway',
|
|
39
|
+
env: this.cfg.env ?? process.env.NODE_ENV ?? 'production',
|
|
40
|
+
level: (this.cfg.level ?? 'info').toUpperCase(),
|
|
41
|
+
transports: {
|
|
42
|
+
console: {
|
|
43
|
+
enabled: this.cfg.transports?.console ?? false
|
|
44
|
+
},
|
|
45
|
+
papertrail: {
|
|
46
|
+
enabled: this.cfg.transports?.papertrail ?? false,
|
|
47
|
+
host: process.env.PAPERTRAIL_HOST || '',
|
|
48
|
+
port: Number(process.env.PAPERTRAIL_PORT || 0),
|
|
49
|
+
program: this.cfg.service ?? 'logs-gateway'
|
|
50
|
+
},
|
|
51
|
+
udpRelay: {
|
|
52
|
+
enabled: this.cfg.transports?.udpRelay ?? false,
|
|
53
|
+
host: process.env.UDP_RELAY_HOST || '127.0.0.1',
|
|
54
|
+
port: Number(process.env.UDP_RELAY_PORT || 0),
|
|
55
|
+
maxPacketBytes: 65000
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
(0, unified_logger_1.initLogger)(inline);
|
|
60
|
+
}
|
|
61
|
+
this.initialized = true;
|
|
62
|
+
}
|
|
63
|
+
catch (err) {
|
|
64
|
+
console.error('[logs-gateway] Failed to initialize unified-logger:', err);
|
|
65
|
+
// Don't throw - this is an optional output
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Map logs-gateway log levels to unified-logger levels
|
|
70
|
+
*/
|
|
71
|
+
mapLevel(level) {
|
|
72
|
+
switch (level) {
|
|
73
|
+
case 'debug': return 'debug';
|
|
74
|
+
case 'info': return 'info';
|
|
75
|
+
case 'warn': return 'warn';
|
|
76
|
+
case 'error': return 'error';
|
|
77
|
+
default: return 'info';
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Write a log entry to unified-logger
|
|
82
|
+
*/
|
|
83
|
+
write(level, message, meta) {
|
|
84
|
+
// Check level filter
|
|
85
|
+
if (this.cfg.levels && !this.cfg.levels.includes(level)) {
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
// Respect routing metadata when present
|
|
89
|
+
if (meta?._routing?.blockOutputs?.includes('unified-logger')) {
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
if (meta?._routing?.allowedOutputs && !meta._routing.allowedOutputs.includes('unified-logger')) {
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
this.ensureInit();
|
|
96
|
+
if (!this.initialized) {
|
|
97
|
+
return; // Failed to initialize, skip silently
|
|
98
|
+
}
|
|
99
|
+
try {
|
|
100
|
+
const mappedLevel = this.mapLevel(level);
|
|
101
|
+
const appInfo = (0, app_info_1.detectAppInfo)();
|
|
102
|
+
const payload = {
|
|
103
|
+
...meta,
|
|
104
|
+
source: meta?.source ?? 'application',
|
|
105
|
+
...(appInfo.name && { appName: appInfo.name }),
|
|
106
|
+
...(appInfo.version && { appVersion: appInfo.version })
|
|
107
|
+
};
|
|
108
|
+
if (meta?.correlationId) {
|
|
109
|
+
payload.correlationId = meta.correlationId;
|
|
110
|
+
}
|
|
111
|
+
if (meta?.identity) {
|
|
112
|
+
payload.identity = meta.identity;
|
|
113
|
+
}
|
|
114
|
+
// Remove routing metadata from the payload to avoid noise
|
|
115
|
+
delete payload._routing;
|
|
116
|
+
unified_logger_1.logger[mappedLevel](message, payload);
|
|
117
|
+
}
|
|
118
|
+
catch (err) {
|
|
119
|
+
console.error('[logs-gateway] Failed to write to unified-logger:', err);
|
|
120
|
+
// Don't throw - this is an optional output
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
exports.UnifiedLoggerOutput = UnifiedLoggerOutput;
|
|
125
|
+
//# sourceMappingURL=unified-logger-output.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"unified-logger-output.js","sourceRoot":"","sources":["../../src/outputs/unified-logger-output.ts"],"names":[],"mappings":";AAAA;;;;;;;GAOG;;;AAEH,gEAAiE;AACjE,0CAA4C;AAG5C;;GAEG;AACH,MAAa,mBAAmB;IAG9B,YAA6B,GAAwB;QAAxB,QAAG,GAAH,GAAG,CAAqB;QAF7C,gBAAW,GAAG,KAAK,CAAC;IAE4B,CAAC;IAEzD;;OAEG;IACK,UAAU;QAChB,IAAI,IAAI,CAAC,WAAW;YAAE,OAAO;QAE7B,IAAI,CAAC;YACH,IAAI,IAAI,CAAC,GAAG,CAAC,UAAU,EAAE,CAAC;gBACxB,IAAA,2BAAU,EAAC,IAAI,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;YAClC,CAAC;iBAAM,IAAI,IAAI,CAAC,GAAG,CAAC,YAAY,EAAE,CAAC;gBACjC,IAAA,2BAAU,EAAC,IAAI,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC;YACpC,CAAC;iBAAM,CAAC;gBACN,8BAA8B;gBAC9B,MAAM,MAAM,GAAG;oBACb,OAAO,EAAE,IAAI,CAAC,GAAG,CAAC,OAAO,IAAI,cAAc;oBAC3C,GAAG,EAAE,IAAI,CAAC,GAAG,CAAC,GAAG,IAAI,OAAO,CAAC,GAAG,CAAC,QAAQ,IAAI,YAAY;oBACzD,KAAK,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,IAAI,MAAM,CAAC,CAAC,WAAW,EAAE;oBAC/C,UAAU,EAAE;wBACV,OAAO,EAAE;4BACP,OAAO,EAAE,IAAI,CAAC,GAAG,CAAC,UAAU,EAAE,OAAO,IAAI,KAAK;yBAC/C;wBACD,UAAU,EAAE;4BACV,OAAO,EAAE,IAAI,CAAC,GAAG,CAAC,UAAU,EAAE,UAAU,IAAI,KAAK;4BACjD,IAAI,EAAE,OAAO,CAAC,GAAG,CAAC,e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AAO,CAAC,KAAK,CAAC,mDAAmD,EAAE,GAAG,CAAC,CAAC;YACxE,2CAA2C;QAC7C,CAAC;IACH,CAAC;CACF;AAhHD,kDAgHC"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* logs-gateway - PII/Credentials Sanitizer
|
|
3
|
+
*
|
|
4
|
+
* This file contains the sanitization logic for detecting and masking sensitive data.
|
|
5
|
+
* Uses established npm packages for robust PII detection and sanitization.
|
|
6
|
+
*/
|
|
7
|
+
import { SanitizationConfig } from './types';
|
|
8
|
+
/**
|
|
9
|
+
* Sanitization result with metadata about what was sanitized
|
|
10
|
+
*/
|
|
11
|
+
export interface SanitizationResult {
|
|
12
|
+
sanitized: any;
|
|
13
|
+
redactionCount: number;
|
|
14
|
+
truncated: boolean;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Main sanitizer class for detecting and masking PII/credentials
|
|
18
|
+
*/
|
|
19
|
+
export declare class LogSanitizer {
|
|
20
|
+
private config;
|
|
21
|
+
constructor(config: SanitizationConfig);
|
|
22
|
+
/**
|
|
23
|
+
* Initialize fast-redact with configuration
|
|
24
|
+
*/
|
|
25
|
+
/**
|
|
26
|
+
* Sanitize a log entry's message and metadata
|
|
27
|
+
*/
|
|
28
|
+
sanitize(message: string, meta?: any): SanitizationResult;
|
|
29
|
+
/**
|
|
30
|
+
* Whether `fullPath` (lowercase, dot-separated) matches a deny/allow pattern.
|
|
31
|
+
* - `password` matches only path `password` (single segment).
|
|
32
|
+
* - `user.password` matches exactly that path.
|
|
33
|
+
* - `*.token` matches one segment + `.token` (e.g. `api.token`).
|
|
34
|
+
*/
|
|
35
|
+
private pathMatchesPattern;
|
|
36
|
+
/**
|
|
37
|
+
* Sanitize an object recursively
|
|
38
|
+
*/
|
|
39
|
+
private sanitizeObject;
|
|
40
|
+
/**
|
|
41
|
+
* Sanitize a string value
|
|
42
|
+
*/
|
|
43
|
+
private sanitizeString;
|
|
44
|
+
/**
|
|
45
|
+
* Detect and mask sensitive patterns in a string using npm packages
|
|
46
|
+
*/
|
|
47
|
+
detectAndMask(str: string): string;
|
|
48
|
+
/**
|
|
49
|
+
* Fallback pattern detection if npm packages fail
|
|
50
|
+
*/
|
|
51
|
+
private fallbackPatternDetection;
|
|
52
|
+
/**
|
|
53
|
+
* Detect credentials and API keys using custom patterns
|
|
54
|
+
*/
|
|
55
|
+
detectCredentials(str: string): string;
|
|
56
|
+
/**
|
|
57
|
+
* Apply pattern detection to object values
|
|
58
|
+
*/
|
|
59
|
+
private applyPatternDetectionToObject;
|
|
60
|
+
/**
|
|
61
|
+
* Hash a value using SHA-256
|
|
62
|
+
*/
|
|
63
|
+
private hashValue;
|
|
64
|
+
/**
|
|
65
|
+
* Validate credit card number using Luhn algorithm
|
|
66
|
+
*/
|
|
67
|
+
private isValidCreditCard;
|
|
68
|
+
}
|
|
69
|
+
//# sourceMappingURL=sanitizer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sanitizer.d.ts","sourceRoot":"","sources":["../src/sanitizer.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAOH,OAAO,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAE7C;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,SAAS,EAAE,GAAG,CAAC;IACf,cAAc,EAAE,MAAM,CAAC;IACvB,SAAS,EAAE,OAAO,CAAC;CACpB;AAED;;GAEG;AACH,qBAAa,YAAY;IACvB,OAAO,CAAC,MAAM,CAA+B;gBAGjC,MAAM,EAAE,kBAAkB;IA6BtC;;OAEG;IAgBH;;OAEG;IACH,QAAQ,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,GAAG,GAAG,kBAAkB;IAsEzD;;;;;OAKG;IACH,OAAO,CAAC,kBAAkB;IA2B1B;;OAEG;IACH,OAAO,CAAC,cAAc;IAmHtB;;OAEG;IACH,OAAO,CAAC,cAAc;IAStB;;OAEG;IACI,aAAa,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM;IAyCzC;;OAEG;IACH,OAAO,CAAC,wBAAwB;IA+ChC;;OAEG;IACI,iBAAiB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM;IAqE7C;;OAEG;IACH,OAAO,CAAC,6BAA6B;IA4CrC;;OAEG;IACH,OAAO,CAAC,SAAS;IAIjB;;OAEG;IACH,OAAO,CAAC,iBAAiB;CA2B1B"}
|