@wgtechlabs/log-engine 1.2.0 → 1.3.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/README.md +283 -18
- package/dist/formatter/colors.d.ts +32 -0
- package/dist/formatter/colors.d.ts.map +1 -0
- package/dist/formatter/colors.js +34 -0
- package/dist/formatter/data-formatter.d.ts +25 -0
- package/dist/formatter/data-formatter.d.ts.map +1 -0
- package/dist/formatter/data-formatter.js +53 -0
- package/dist/formatter/index.d.ts +10 -0
- package/dist/formatter/index.d.ts.map +1 -0
- package/dist/formatter/index.js +21 -0
- package/dist/formatter/message-formatter.d.ts +41 -0
- package/dist/formatter/message-formatter.d.ts.map +1 -0
- package/dist/formatter/message-formatter.js +87 -0
- package/dist/formatter/timestamp.d.ts +27 -0
- package/dist/formatter/timestamp.d.ts.map +1 -0
- package/dist/formatter/timestamp.js +39 -0
- package/dist/formatter.d.ts +10 -2
- package/dist/formatter.d.ts.map +1 -1
- package/dist/formatter.js +42 -5
- package/dist/index.d.ts +143 -41
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +155 -71
- package/dist/logger/config.d.ts +42 -0
- package/dist/logger/config.d.ts.map +1 -0
- package/dist/logger/config.js +101 -0
- package/dist/logger/core.d.ts +108 -0
- package/dist/logger/core.d.ts.map +1 -0
- package/dist/logger/core.js +185 -0
- package/dist/logger/environment.d.ts +36 -0
- package/dist/logger/environment.d.ts.map +1 -0
- package/dist/logger/environment.js +61 -0
- package/dist/logger/filtering.d.ts +36 -0
- package/dist/logger/filtering.d.ts.map +1 -0
- package/dist/logger/filtering.js +65 -0
- package/dist/logger/index.d.ts +10 -0
- package/dist/logger/index.d.ts.map +1 -0
- package/dist/logger/index.js +18 -0
- package/dist/logger.d.ts +61 -5
- package/dist/logger.d.ts.map +1 -1
- package/dist/logger.js +117 -10
- package/dist/redaction/config.d.ts +29 -0
- package/dist/redaction/config.d.ts.map +1 -0
- package/dist/redaction/config.js +95 -0
- package/dist/redaction/index.d.ts +8 -0
- package/dist/redaction/index.d.ts.map +1 -0
- package/dist/redaction/index.js +12 -0
- package/dist/redaction/redactor.d.ts +99 -0
- package/dist/redaction/redactor.d.ts.map +1 -0
- package/dist/redaction/redactor.js +257 -0
- package/dist/types/index.d.ts +164 -0
- package/dist/types/index.d.ts.map +1 -1
- package/package.json +11 -4
package/dist/logger.js
CHANGED
|
@@ -4,26 +4,53 @@
|
|
|
4
4
|
* Supports DEBUG, INFO, WARN, ERROR, and LOG levels with intelligent filtering
|
|
5
5
|
* LOG level always outputs regardless of configuration
|
|
6
6
|
* Uses colorized console output with timestamps for better readability
|
|
7
|
+
* Includes automatic data redaction for sensitive information
|
|
7
8
|
*/
|
|
8
9
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
10
|
exports.Logger = void 0;
|
|
10
11
|
const types_1 = require("./types");
|
|
11
12
|
const formatter_1 = require("./formatter");
|
|
13
|
+
const redaction_1 = require("./redaction");
|
|
12
14
|
/**
|
|
13
15
|
* Logger class responsible for managing log output and configuration
|
|
14
16
|
* Provides mode-based filtering and formatted console output
|
|
15
17
|
*/
|
|
16
18
|
class Logger {
|
|
19
|
+
/**
|
|
20
|
+
* Logger constructor - sets up environment-based auto-configuration
|
|
21
|
+
*/
|
|
17
22
|
constructor() {
|
|
18
23
|
// Internal configuration state with sensible defaults
|
|
19
24
|
this.config = {
|
|
20
25
|
mode: types_1.LogMode.INFO
|
|
21
26
|
};
|
|
27
|
+
// Set initial mode based on NODE_ENV for auto-configuration
|
|
28
|
+
this.config.mode = this.getEnvironmentMode();
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Determines the appropriate log mode based on NODE_ENV
|
|
32
|
+
* @returns LogMode appropriate for current environment
|
|
33
|
+
*/
|
|
34
|
+
getEnvironmentMode() {
|
|
35
|
+
const nodeEnv = process.env.NODE_ENV;
|
|
36
|
+
switch (nodeEnv) {
|
|
37
|
+
case 'development':
|
|
38
|
+
return types_1.LogMode.DEBUG; // Verbose logging for development
|
|
39
|
+
case 'production':
|
|
40
|
+
return types_1.LogMode.INFO; // Important info and above for production
|
|
41
|
+
case 'staging':
|
|
42
|
+
return types_1.LogMode.WARN; // Focused logging for staging
|
|
43
|
+
case 'test':
|
|
44
|
+
return types_1.LogMode.ERROR; // Minimal logging during tests
|
|
45
|
+
default:
|
|
46
|
+
return types_1.LogMode.INFO; // Default fallback for unknown environments
|
|
47
|
+
}
|
|
22
48
|
}
|
|
23
49
|
/**
|
|
24
50
|
* Updates logger configuration with new settings
|
|
25
51
|
* Merges provided config with existing settings (partial update)
|
|
26
52
|
* Supports backwards compatibility by mapping level to mode with deprecation warnings
|
|
53
|
+
* Also updates redaction configuration based on environment
|
|
27
54
|
* @param config - Partial configuration object to apply
|
|
28
55
|
*/
|
|
29
56
|
configure(config) {
|
|
@@ -57,6 +84,11 @@ class Logger {
|
|
|
57
84
|
// Normal configuration update
|
|
58
85
|
this.config = { ...this.config, ...config };
|
|
59
86
|
}
|
|
87
|
+
// Update redaction configuration based on current environment
|
|
88
|
+
redaction_1.DataRedactor.updateConfig({
|
|
89
|
+
...redaction_1.defaultRedactionConfig,
|
|
90
|
+
...redaction_1.RedactionController.getEnvironmentConfig()
|
|
91
|
+
});
|
|
60
92
|
}
|
|
61
93
|
/**
|
|
62
94
|
* Determines if a message should be logged based on current log mode
|
|
@@ -78,44 +110,56 @@ class Logger {
|
|
|
78
110
|
/**
|
|
79
111
|
* Log a debug message with DEBUG level formatting
|
|
80
112
|
* Uses console.log for output with purple/magenta coloring
|
|
113
|
+
* Automatically redacts sensitive data when provided
|
|
81
114
|
* @param message - The debug message to log
|
|
115
|
+
* @param data - Optional data object to log (will be redacted)
|
|
82
116
|
*/
|
|
83
|
-
debug(message) {
|
|
117
|
+
debug(message, data) {
|
|
84
118
|
if (this.shouldLog(types_1.LogLevel.DEBUG)) {
|
|
85
|
-
const
|
|
119
|
+
const processedData = redaction_1.DataRedactor.redactData(data);
|
|
120
|
+
const formatted = formatter_1.LogFormatter.format(types_1.LogLevel.DEBUG, message, processedData);
|
|
86
121
|
console.log(formatted);
|
|
87
122
|
}
|
|
88
123
|
}
|
|
89
124
|
/**
|
|
90
125
|
* Log an informational message with INFO level formatting
|
|
91
126
|
* Uses console.log for output with blue coloring
|
|
127
|
+
* Automatically redacts sensitive data when provided
|
|
92
128
|
* @param message - The info message to log
|
|
129
|
+
* @param data - Optional data object to log (will be redacted)
|
|
93
130
|
*/
|
|
94
|
-
info(message) {
|
|
131
|
+
info(message, data) {
|
|
95
132
|
if (this.shouldLog(types_1.LogLevel.INFO)) {
|
|
96
|
-
const
|
|
133
|
+
const processedData = redaction_1.DataRedactor.redactData(data);
|
|
134
|
+
const formatted = formatter_1.LogFormatter.format(types_1.LogLevel.INFO, message, processedData);
|
|
97
135
|
console.log(formatted);
|
|
98
136
|
}
|
|
99
137
|
}
|
|
100
138
|
/**
|
|
101
139
|
* Log a warning message with WARN level formatting
|
|
102
140
|
* Uses console.warn for output with yellow coloring
|
|
141
|
+
* Automatically redacts sensitive data when provided
|
|
103
142
|
* @param message - The warning message to log
|
|
143
|
+
* @param data - Optional data object to log (will be redacted)
|
|
104
144
|
*/
|
|
105
|
-
warn(message) {
|
|
145
|
+
warn(message, data) {
|
|
106
146
|
if (this.shouldLog(types_1.LogLevel.WARN)) {
|
|
107
|
-
const
|
|
147
|
+
const processedData = redaction_1.DataRedactor.redactData(data);
|
|
148
|
+
const formatted = formatter_1.LogFormatter.format(types_1.LogLevel.WARN, message, processedData);
|
|
108
149
|
console.warn(formatted);
|
|
109
150
|
}
|
|
110
151
|
}
|
|
111
152
|
/**
|
|
112
153
|
* Log an error message with ERROR level formatting
|
|
113
154
|
* Uses console.error for output with red coloring
|
|
155
|
+
* Automatically redacts sensitive data when provided
|
|
114
156
|
* @param message - The error message to log
|
|
157
|
+
* @param data - Optional data object to log (will be redacted)
|
|
115
158
|
*/
|
|
116
|
-
error(message) {
|
|
159
|
+
error(message, data) {
|
|
117
160
|
if (this.shouldLog(types_1.LogLevel.ERROR)) {
|
|
118
|
-
const
|
|
161
|
+
const processedData = redaction_1.DataRedactor.redactData(data);
|
|
162
|
+
const formatted = formatter_1.LogFormatter.format(types_1.LogLevel.ERROR, message, processedData);
|
|
119
163
|
console.error(formatted);
|
|
120
164
|
}
|
|
121
165
|
}
|
|
@@ -123,11 +167,74 @@ class Logger {
|
|
|
123
167
|
* Log a critical message that always outputs (LOG level)
|
|
124
168
|
* Uses console.log for output with green coloring
|
|
125
169
|
* Always shown regardless of configured log level
|
|
170
|
+
* Automatically redacts sensitive data when provided
|
|
171
|
+
* @param message - The critical log message to log
|
|
172
|
+
* @param data - Optional data object to log (will be redacted)
|
|
173
|
+
*/
|
|
174
|
+
log(message, data) {
|
|
175
|
+
if (this.shouldLog(types_1.LogLevel.LOG)) {
|
|
176
|
+
const processedData = redaction_1.DataRedactor.redactData(data);
|
|
177
|
+
const formatted = formatter_1.LogFormatter.format(types_1.LogLevel.LOG, message, processedData);
|
|
178
|
+
console.log(formatted);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Log a debug message without redaction (use with caution)
|
|
183
|
+
* Bypasses automatic data redaction for debugging purposes
|
|
184
|
+
* @param message - The debug message to log
|
|
185
|
+
* @param data - Optional data object to log (no redaction applied)
|
|
186
|
+
*/
|
|
187
|
+
debugRaw(message, data) {
|
|
188
|
+
if (this.shouldLog(types_1.LogLevel.DEBUG)) {
|
|
189
|
+
const formatted = formatter_1.LogFormatter.format(types_1.LogLevel.DEBUG, message, data);
|
|
190
|
+
console.log(formatted);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* Log an info message without redaction (use with caution)
|
|
195
|
+
* Bypasses automatic data redaction for debugging purposes
|
|
196
|
+
* @param message - The info message to log
|
|
197
|
+
* @param data - Optional data object to log (no redaction applied)
|
|
198
|
+
*/
|
|
199
|
+
infoRaw(message, data) {
|
|
200
|
+
if (this.shouldLog(types_1.LogLevel.INFO)) {
|
|
201
|
+
const formatted = formatter_1.LogFormatter.format(types_1.LogLevel.INFO, message, data);
|
|
202
|
+
console.log(formatted);
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* Log a warning message without redaction (use with caution)
|
|
207
|
+
* Bypasses automatic data redaction for debugging purposes
|
|
208
|
+
* @param message - The warning message to log
|
|
209
|
+
* @param data - Optional data object to log (no redaction applied)
|
|
210
|
+
*/
|
|
211
|
+
warnRaw(message, data) {
|
|
212
|
+
if (this.shouldLog(types_1.LogLevel.WARN)) {
|
|
213
|
+
const formatted = formatter_1.LogFormatter.format(types_1.LogLevel.WARN, message, data);
|
|
214
|
+
console.warn(formatted);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* Log an error message without redaction (use with caution)
|
|
219
|
+
* Bypasses automatic data redaction for debugging purposes
|
|
220
|
+
* @param message - The error message to log
|
|
221
|
+
* @param data - Optional data object to log (no redaction applied)
|
|
222
|
+
*/
|
|
223
|
+
errorRaw(message, data) {
|
|
224
|
+
if (this.shouldLog(types_1.LogLevel.ERROR)) {
|
|
225
|
+
const formatted = formatter_1.LogFormatter.format(types_1.LogLevel.ERROR, message, data);
|
|
226
|
+
console.error(formatted);
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
/**
|
|
230
|
+
* Log a critical message without redaction (use with caution)
|
|
231
|
+
* Bypasses automatic data redaction for debugging purposes
|
|
126
232
|
* @param message - The critical log message to log
|
|
233
|
+
* @param data - Optional data object to log (no redaction applied)
|
|
127
234
|
*/
|
|
128
|
-
|
|
235
|
+
logRaw(message, data) {
|
|
129
236
|
if (this.shouldLog(types_1.LogLevel.LOG)) {
|
|
130
|
-
const formatted = formatter_1.LogFormatter.format(types_1.LogLevel.LOG, message);
|
|
237
|
+
const formatted = formatter_1.LogFormatter.format(types_1.LogLevel.LOG, message, data);
|
|
131
238
|
console.log(formatted);
|
|
132
239
|
}
|
|
133
240
|
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Default configuration and constants for data redaction
|
|
3
|
+
* Provides comprehensive coverage of common sensitive field patterns
|
|
4
|
+
*/
|
|
5
|
+
import { RedactionConfig } from '../types';
|
|
6
|
+
/**
|
|
7
|
+
* Default redaction configuration with comprehensive sensitive field detection
|
|
8
|
+
* Covers authentication, personal information, financial data, and internal systems
|
|
9
|
+
*/
|
|
10
|
+
export declare const defaultRedactionConfig: RedactionConfig;
|
|
11
|
+
/**
|
|
12
|
+
* Environment-based redaction controller
|
|
13
|
+
* Determines when redaction should be disabled based on environment variables
|
|
14
|
+
*/
|
|
15
|
+
export declare class RedactionController {
|
|
16
|
+
/**
|
|
17
|
+
* Check if redaction should be disabled based on environment variables
|
|
18
|
+
* Development mode and explicit flags can disable redaction for debugging
|
|
19
|
+
* @returns true if redaction should be disabled, false otherwise
|
|
20
|
+
*/
|
|
21
|
+
static isRedactionDisabled(): boolean;
|
|
22
|
+
/**
|
|
23
|
+
* Get environment-specific configuration overrides
|
|
24
|
+
* Allows customization through environment variables
|
|
25
|
+
* @returns Partial redaction config with environment-based overrides
|
|
26
|
+
*/
|
|
27
|
+
static getEnvironmentConfig(): Partial<RedactionConfig>;
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/redaction/config.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAE3C;;;GAGG;AACH,eAAO,MAAM,sBAAsB,EAAE,eAyCpC,CAAC;AAEF;;;GAGG;AACH,qBAAa,mBAAmB;IAC5B;;;;OAIG;IACH,MAAM,CAAC,mBAAmB,IAAI,OAAO;IAUrC;;;;OAIG;IACH,MAAM,CAAC,oBAAoB,IAAI,OAAO,CAAC,eAAe,CAAC;CA4B1D"}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Default configuration and constants for data redaction
|
|
4
|
+
* Provides comprehensive coverage of common sensitive field patterns
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.RedactionController = exports.defaultRedactionConfig = void 0;
|
|
8
|
+
/**
|
|
9
|
+
* Default redaction configuration with comprehensive sensitive field detection
|
|
10
|
+
* Covers authentication, personal information, financial data, and internal systems
|
|
11
|
+
*/
|
|
12
|
+
exports.defaultRedactionConfig = {
|
|
13
|
+
enabled: true,
|
|
14
|
+
deepRedaction: true,
|
|
15
|
+
maxContentLength: 100,
|
|
16
|
+
redactionText: '[REDACTED]',
|
|
17
|
+
truncationText: '... [TRUNCATED]',
|
|
18
|
+
// Comprehensive list of sensitive field patterns (case-insensitive)
|
|
19
|
+
sensitiveFields: [
|
|
20
|
+
// Authentication & Security
|
|
21
|
+
'password', 'pwd', 'pass', 'passphrase',
|
|
22
|
+
'token', 'accessToken', 'refreshToken', 'bearerToken',
|
|
23
|
+
'apiKey', 'api_key', 'secret', 'secretKey', 'privateKey',
|
|
24
|
+
'auth', 'authorization', 'authToken',
|
|
25
|
+
'jwt', 'sessionId', 'session_id',
|
|
26
|
+
'cookie', 'cookies', 'csrf', 'csrfToken',
|
|
27
|
+
// Personal Information (PII)
|
|
28
|
+
'email', 'emailAddress', 'email_address',
|
|
29
|
+
'phone', 'phoneNumber', 'phone_number', 'mobile',
|
|
30
|
+
'ssn', 'socialSecurityNumber', 'social_security_number',
|
|
31
|
+
'address', 'homeAddress', 'workAddress',
|
|
32
|
+
'firstName', 'lastName', 'fullName', 'realName', 'displayName',
|
|
33
|
+
'dateOfBirth', 'dob', 'birthDate',
|
|
34
|
+
// Financial Information
|
|
35
|
+
'creditCard', 'credit_card', 'cardNumber', 'card_number',
|
|
36
|
+
'cvv', 'cvc', 'pin', 'expiryDate', 'expiry_date',
|
|
37
|
+
'bankAccount', 'bank_account', 'routingNumber',
|
|
38
|
+
// Internal/System Information
|
|
39
|
+
'internalId', 'userId', 'customerId',
|
|
40
|
+
'personalInfo', 'pii', 'sensitive',
|
|
41
|
+
'clientSecret', 'webhookSecret'
|
|
42
|
+
],
|
|
43
|
+
// Fields that should be truncated rather than redacted
|
|
44
|
+
contentFields: [
|
|
45
|
+
'content', 'text', 'message', 'body', 'data',
|
|
46
|
+
'payload', 'response', 'request', 'description'
|
|
47
|
+
]
|
|
48
|
+
};
|
|
49
|
+
/**
|
|
50
|
+
* Environment-based redaction controller
|
|
51
|
+
* Determines when redaction should be disabled based on environment variables
|
|
52
|
+
*/
|
|
53
|
+
class RedactionController {
|
|
54
|
+
/**
|
|
55
|
+
* Check if redaction should be disabled based on environment variables
|
|
56
|
+
* Development mode and explicit flags can disable redaction for debugging
|
|
57
|
+
* @returns true if redaction should be disabled, false otherwise
|
|
58
|
+
*/
|
|
59
|
+
static isRedactionDisabled() {
|
|
60
|
+
return (process.env.NODE_ENV === 'development' ||
|
|
61
|
+
process.env.LOG_REDACTION_DISABLED === 'true' ||
|
|
62
|
+
process.env.DEBUG_FULL_PAYLOADS === 'true' ||
|
|
63
|
+
process.env.LOG_LEVEL === 'debug' ||
|
|
64
|
+
process.env.LOG_REDACTION_ENABLED === 'false');
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Get environment-specific configuration overrides
|
|
68
|
+
* Allows customization through environment variables
|
|
69
|
+
* @returns Partial redaction config with environment-based overrides
|
|
70
|
+
*/
|
|
71
|
+
static getEnvironmentConfig() {
|
|
72
|
+
const envConfig = {
|
|
73
|
+
enabled: !this.isRedactionDisabled()
|
|
74
|
+
};
|
|
75
|
+
// Apply environment variable overrides if they exist
|
|
76
|
+
if (process.env.LOG_MAX_CONTENT_LENGTH) {
|
|
77
|
+
const parsedLength = parseInt(process.env.LOG_MAX_CONTENT_LENGTH, 10);
|
|
78
|
+
if (!isNaN(parsedLength) && parsedLength > 0) {
|
|
79
|
+
envConfig.maxContentLength = parsedLength;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
if (process.env.LOG_REDACTION_TEXT) {
|
|
83
|
+
envConfig.redactionText = process.env.LOG_REDACTION_TEXT;
|
|
84
|
+
}
|
|
85
|
+
if (process.env.LOG_TRUNCATION_TEXT) {
|
|
86
|
+
envConfig.truncationText = process.env.LOG_TRUNCATION_TEXT;
|
|
87
|
+
}
|
|
88
|
+
if (process.env.LOG_SENSITIVE_FIELDS) {
|
|
89
|
+
const customFields = process.env.LOG_SENSITIVE_FIELDS.split(',').map(f => f.trim());
|
|
90
|
+
envConfig.sensitiveFields = [...exports.defaultRedactionConfig.sensitiveFields, ...customFields];
|
|
91
|
+
}
|
|
92
|
+
return envConfig;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
exports.RedactionController = RedactionController;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Redaction module exports
|
|
3
|
+
* Provides centralized access to all redaction functionality
|
|
4
|
+
*/
|
|
5
|
+
export { DataRedactor } from './redactor';
|
|
6
|
+
export { defaultRedactionConfig, RedactionController } from './config';
|
|
7
|
+
export type { RedactionConfig } from '../types';
|
|
8
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/redaction/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC1C,OAAO,EAAE,sBAAsB,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC;AACvE,YAAY,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Redaction module exports
|
|
4
|
+
* Provides centralized access to all redaction functionality
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.RedactionController = exports.defaultRedactionConfig = exports.DataRedactor = void 0;
|
|
8
|
+
var redactor_1 = require("./redactor");
|
|
9
|
+
Object.defineProperty(exports, "DataRedactor", { enumerable: true, get: function () { return redactor_1.DataRedactor; } });
|
|
10
|
+
var config_1 = require("./config");
|
|
11
|
+
Object.defineProperty(exports, "defaultRedactionConfig", { enumerable: true, get: function () { return config_1.defaultRedactionConfig; } });
|
|
12
|
+
Object.defineProperty(exports, "RedactionController", { enumerable: true, get: function () { return config_1.RedactionController; } });
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Core data redaction engine
|
|
3
|
+
* Handles automatic detection and redaction of sensitive information in log data
|
|
4
|
+
*/
|
|
5
|
+
import { RedactionConfig } from '../types';
|
|
6
|
+
/**
|
|
7
|
+
* DataRedactor class - Core redaction logic for processing log data
|
|
8
|
+
* Automatically detects and redacts sensitive information while preserving structure
|
|
9
|
+
*/
|
|
10
|
+
export declare class DataRedactor {
|
|
11
|
+
private static config;
|
|
12
|
+
private static readonly MAX_RECURSION_DEPTH;
|
|
13
|
+
private static readonly MAX_REDACT_OBJECT_DEPTH;
|
|
14
|
+
/**
|
|
15
|
+
* Update the redaction configuration with new settings
|
|
16
|
+
* Merges provided config with existing settings and reloads environment variables
|
|
17
|
+
* @param newConfig - Partial configuration to merge with current settings
|
|
18
|
+
*/
|
|
19
|
+
static updateConfig(newConfig: Partial<RedactionConfig>): void;
|
|
20
|
+
/**
|
|
21
|
+
* Get the current redaction configuration
|
|
22
|
+
* @returns Deep copy of current redaction configuration
|
|
23
|
+
*/
|
|
24
|
+
static getConfig(): RedactionConfig;
|
|
25
|
+
/**
|
|
26
|
+
* Refresh configuration from environment variables
|
|
27
|
+
* Useful for picking up runtime environment changes
|
|
28
|
+
*/
|
|
29
|
+
static refreshConfig(): void;
|
|
30
|
+
/**
|
|
31
|
+
* Add custom regex patterns for advanced field detection
|
|
32
|
+
* @param patterns - Array of regex patterns to add
|
|
33
|
+
*/
|
|
34
|
+
static addCustomPatterns(patterns: RegExp[]): void;
|
|
35
|
+
/**
|
|
36
|
+
* Clear all custom regex patterns
|
|
37
|
+
*/
|
|
38
|
+
static clearCustomPatterns(): void;
|
|
39
|
+
/**
|
|
40
|
+
* Add custom sensitive field names to the existing list
|
|
41
|
+
* @param fields - Array of field names to add
|
|
42
|
+
*/
|
|
43
|
+
static addSensitiveFields(fields: string[]): void;
|
|
44
|
+
/**
|
|
45
|
+
* Test if a field name would be redacted with current configuration
|
|
46
|
+
* @param fieldName - Field name to test
|
|
47
|
+
* @returns true if field would be redacted, false otherwise
|
|
48
|
+
*/
|
|
49
|
+
static testFieldRedaction(fieldName: string): boolean;
|
|
50
|
+
/**
|
|
51
|
+
* Main entry point for data redaction
|
|
52
|
+
* Processes any type of data and returns a redacted version
|
|
53
|
+
* @param data - Data to be processed for redaction
|
|
54
|
+
* @returns Redacted version of the data
|
|
55
|
+
*/
|
|
56
|
+
static redactData(data: any): any;
|
|
57
|
+
/**
|
|
58
|
+
* Process a value of any type (primitive, object, array)
|
|
59
|
+
* Recursively handles nested structures when deepRedaction is enabled
|
|
60
|
+
* Includes circular reference protection and recursion depth limiting
|
|
61
|
+
* @param value - Value to process
|
|
62
|
+
* @param visited - Set to track visited objects (prevents circular references)
|
|
63
|
+
* @param depth - Current recursion depth (prevents stack overflow)
|
|
64
|
+
* @returns Processed value with redaction applied
|
|
65
|
+
*/
|
|
66
|
+
private static processValue;
|
|
67
|
+
/**
|
|
68
|
+
* Process an object and redact sensitive fields
|
|
69
|
+
* Handles field-level redaction and content truncation
|
|
70
|
+
* @param obj - Object to process
|
|
71
|
+
* @param visited - Set to track visited objects (prevents circular references)
|
|
72
|
+
* @param depth - Current recursion depth (prevents stack overflow)
|
|
73
|
+
* @returns Object with sensitive fields redacted
|
|
74
|
+
*/
|
|
75
|
+
private static redactObject;
|
|
76
|
+
/**
|
|
77
|
+
* Check if a field name indicates sensitive information
|
|
78
|
+
* Uses case-insensitive matching with exact and partial matches
|
|
79
|
+
* Includes smart filtering to avoid false positives and custom patterns
|
|
80
|
+
* @param fieldName - Field name to check
|
|
81
|
+
* @returns true if field should be redacted, false otherwise
|
|
82
|
+
*/
|
|
83
|
+
private static isSensitiveField;
|
|
84
|
+
/**
|
|
85
|
+
* Check if a field name indicates content that should be truncated
|
|
86
|
+
* Uses exact case-insensitive matching for content fields
|
|
87
|
+
* @param fieldName - Field name to check
|
|
88
|
+
* @returns true if field is a content field, false otherwise
|
|
89
|
+
*/
|
|
90
|
+
private static isContentField;
|
|
91
|
+
/**
|
|
92
|
+
* Truncate content that exceeds the maximum length
|
|
93
|
+
* Preserves readability while preventing log bloat
|
|
94
|
+
* @param content - Content string to potentially truncate
|
|
95
|
+
* @returns Original content or truncated version with indicator
|
|
96
|
+
*/
|
|
97
|
+
private static truncateContent;
|
|
98
|
+
}
|
|
99
|
+
//# sourceMappingURL=redactor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"redactor.d.ts","sourceRoot":"","sources":["../../src/redaction/redactor.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAG3C;;;GAGG;AACH,qBAAa,YAAY;IACrB,OAAO,CAAC,MAAM,CAAC,MAAM,CAGnB;IAGF,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,mBAAmB,CAAO;IAElD,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,uBAAuB,CAAM;IAErD;;;;OAIG;IACH,MAAM,CAAC,YAAY,CAAC,SAAS,EAAE,OAAO,CAAC,eAAe,CAAC,GAAG,IAAI;IAU9D;;;OAGG;IACH,MAAM,CAAC,SAAS,IAAI,eAAe;IASnC;;;OAGG;IACH,MAAM,CAAC,aAAa,IAAI,IAAI;IAQ5B;;;OAGG;IACH,MAAM,CAAC,iBAAiB,CAAC,QAAQ,EAAE,MAAM,EAAE,GAAG,IAAI;IAQlD;;OAEG;IACH,MAAM,CAAC,mBAAmB,IAAI,IAAI;IAOlC;;;OAGG;IACH,MAAM,CAAC,kBAAkB,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,IAAI;IAOjD;;;;OAIG;IACH,MAAM,CAAC,kBAAkB,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO;IAMrD;;;;;OAKG;IACH,MAAM,CAAC,UAAU,CAAC,IAAI,EAAE,GAAG,GAAG,GAAG;IASjC;;;;;;;;OAQG;IACH,OAAO,CAAC,MAAM,CAAC,YAAY;IAyC3B;;;;;;;OAOG;IACH,OAAO,CAAC,MAAM,CAAC,YAAY;IA8B3B;;;;;;OAMG;IACH,OAAO,CAAC,MAAM,CAAC,gBAAgB;IAgD/B;;;;;OAKG;IACH,OAAO,CAAC,MAAM,CAAC,cAAc;IAK7B;;;;;OAKG;IACH,OAAO,CAAC,MAAM,CAAC,eAAe;CAMjC"}
|