@devilsdev/rag-pipeline-utils 2.2.1 → 2.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 +244 -11
- package/contracts/contract-schema.json +189 -0
- package/dist/index.cjs +19 -0
- package/dist/index.mjs +15 -1
- package/package.json +3 -2
- package/src/cli/commands/wizard.js +627 -0
- package/src/cli/input-sanitization-middleware.js +356 -0
- package/src/cli/templates/development.template.json +64 -0
- package/src/cli/templates/minimal.template.json +33 -0
- package/src/cli/templates/production.template.json +104 -0
- package/src/cli/templates/testing.template.json +45 -0
- package/src/config/connection-pool-config.json +259 -0
- package/src/config/memory-optimization.js +414 -0
- package/src/config/redaction-patterns.json +150 -0
- package/src/config/sanitization-rules.json +323 -0
- package/src/core/plugin-registry.js +266 -20
- package/src/dag/core/error-context.js +391 -0
- package/src/dag/core/execution-scheduler.js +350 -0
- package/src/dag/core/topology-validation.js +415 -0
- package/src/dag/dag-engine.js +26 -424
- package/src/dev/README.md +126 -0
- package/src/dev/dev-server.js +356 -0
- package/src/dev/examples/hot-reload-usage.js +355 -0
- package/src/dev/hot-reload.js +807 -0
- package/src/enterprise/sso-integration.js +67 -25
- package/src/index.js +19 -0
- package/src/observability/event-logger.js +62 -2
- package/src/plugins/optimized-openai-embedder.js +169 -0
- package/src/security/jwt-config.js +431 -0
- package/src/security/jwt-validator.js +701 -0
- package/src/utils/api-client-pool-integration.js +436 -0
- package/src/utils/batch-processor.js +710 -0
- package/src/utils/connection-pool.js +605 -0
- package/src/utils/contract-validator.js +460 -0
- package/src/utils/error-formatter.js +603 -0
- package/src/utils/examples/error-formatter-usage.js +351 -0
- package/src/utils/input-sanitizer.js +967 -0
- package/src/utils/memory-monitor.js +800 -0
- package/src/utils/secure-logger-config.js +352 -0
- package/src/utils/secure-logger.js +576 -0
|
@@ -0,0 +1,352 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Secure Logger Configuration Loader
|
|
5
|
+
*
|
|
6
|
+
* Loads and applies redaction pattern configurations from JSON files
|
|
7
|
+
* or JavaScript objects to create configured SecureLogger instances.
|
|
8
|
+
*
|
|
9
|
+
* @module secure-logger-config
|
|
10
|
+
* @since 2.2.5
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
const fs = require('fs');
|
|
14
|
+
const path = require('path');
|
|
15
|
+
const { SecureLogger } = require('./secure-logger');
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Load configuration from JSON file
|
|
19
|
+
*
|
|
20
|
+
* @param {string} configPath - Path to configuration file
|
|
21
|
+
* @returns {Object} Configuration object
|
|
22
|
+
* @throws {Error} If file cannot be read or parsed
|
|
23
|
+
*
|
|
24
|
+
* @private
|
|
25
|
+
*/
|
|
26
|
+
function loadConfigFile(configPath) {
|
|
27
|
+
try {
|
|
28
|
+
const content = fs.readFileSync(configPath, 'utf8');
|
|
29
|
+
return JSON.parse(content);
|
|
30
|
+
} catch (error) {
|
|
31
|
+
throw new Error(
|
|
32
|
+
`Failed to load redaction config from ${configPath}: ${error.message}`,
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Convert regex string to RegExp object
|
|
39
|
+
*
|
|
40
|
+
* @param {string} regexStr - Regex pattern as string
|
|
41
|
+
* @param {string} flags - Regex flags
|
|
42
|
+
* @returns {RegExp} Compiled regular expression
|
|
43
|
+
*
|
|
44
|
+
* @private
|
|
45
|
+
*/
|
|
46
|
+
function compileRegex(regexStr, flags = 'g') {
|
|
47
|
+
try {
|
|
48
|
+
return new RegExp(regexStr, flags);
|
|
49
|
+
} catch (error) {
|
|
50
|
+
throw new Error(`Invalid regex pattern: ${regexStr} - ${error.message}`);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Apply environment-specific configuration overrides
|
|
56
|
+
*
|
|
57
|
+
* @param {Object} config - Base configuration
|
|
58
|
+
* @param {string} [environment] - Environment name (defaults to NODE_ENV)
|
|
59
|
+
* @returns {Object} Configuration with environment overrides applied
|
|
60
|
+
*
|
|
61
|
+
* @private
|
|
62
|
+
*/
|
|
63
|
+
function applyEnvironmentOverrides(config, environment) {
|
|
64
|
+
const env = environment || process.env.NODE_ENV || 'development';
|
|
65
|
+
|
|
66
|
+
if (config.environments && config.environments[env]) {
|
|
67
|
+
return {
|
|
68
|
+
...config,
|
|
69
|
+
...config.environments[env],
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
return config;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Convert custom pattern configuration to SecureLogger format
|
|
78
|
+
*
|
|
79
|
+
* @param {Object} customPatterns - Custom patterns from config
|
|
80
|
+
* @returns {Object} Patterns in SecureLogger format
|
|
81
|
+
*
|
|
82
|
+
* @private
|
|
83
|
+
*/
|
|
84
|
+
function convertCustomPatterns(customPatterns) {
|
|
85
|
+
const converted = {};
|
|
86
|
+
|
|
87
|
+
for (const [name, pattern] of Object.entries(customPatterns)) {
|
|
88
|
+
converted[name] = {
|
|
89
|
+
regex: compileRegex(pattern.regex, pattern.flags || 'g'),
|
|
90
|
+
replacement: pattern.replacement,
|
|
91
|
+
description: pattern.description || '',
|
|
92
|
+
enabled: pattern.enabled !== false,
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
return converted;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Create SecureLogger from configuration
|
|
101
|
+
*
|
|
102
|
+
* @param {Object|string} config - Configuration object or path to config file
|
|
103
|
+
* @param {string} [environment] - Environment name for overrides
|
|
104
|
+
* @returns {SecureLogger} Configured SecureLogger instance
|
|
105
|
+
*
|
|
106
|
+
* @example
|
|
107
|
+
* // Load from file
|
|
108
|
+
* const logger = createLoggerFromConfig('./redaction-config.json');
|
|
109
|
+
*
|
|
110
|
+
* // Load from object
|
|
111
|
+
* const logger = createLoggerFromConfig({
|
|
112
|
+
* enabled: true,
|
|
113
|
+
* redactEmails: true,
|
|
114
|
+
* customPatterns: {
|
|
115
|
+
* myPattern: {
|
|
116
|
+
* regex: '\\bMY-[A-Z0-9]+\\b',
|
|
117
|
+
* replacement: '[MY_TOKEN]'
|
|
118
|
+
* }
|
|
119
|
+
* }
|
|
120
|
+
* });
|
|
121
|
+
*
|
|
122
|
+
* // Load with environment override
|
|
123
|
+
* const logger = createLoggerFromConfig(config, 'production');
|
|
124
|
+
*/
|
|
125
|
+
function createLoggerFromConfig(config, environment) {
|
|
126
|
+
let configuration;
|
|
127
|
+
|
|
128
|
+
// Load from file if string path provided
|
|
129
|
+
if (typeof config === 'string') {
|
|
130
|
+
configuration = loadConfigFile(config);
|
|
131
|
+
} else {
|
|
132
|
+
configuration = config;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
// Apply environment-specific overrides
|
|
136
|
+
configuration = applyEnvironmentOverrides(configuration, environment);
|
|
137
|
+
|
|
138
|
+
// Build SecureLogger options
|
|
139
|
+
const options = {
|
|
140
|
+
enabled: configuration.enabled !== false,
|
|
141
|
+
trackStats: configuration.trackStats !== false,
|
|
142
|
+
redactionMarker: configuration.redactionMarker,
|
|
143
|
+
redactEmails: configuration.redactEmails || false,
|
|
144
|
+
redactIPs: configuration.redactIPs || false,
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
// Add custom patterns
|
|
148
|
+
if (configuration.customPatterns) {
|
|
149
|
+
options.patterns = convertCustomPatterns(configuration.customPatterns);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
// Add sensitive fields
|
|
153
|
+
if (
|
|
154
|
+
configuration.sensitiveFields &&
|
|
155
|
+
Array.isArray(configuration.sensitiveFields)
|
|
156
|
+
) {
|
|
157
|
+
options.sensitiveFields = configuration.sensitiveFields;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
// Create logger instance
|
|
161
|
+
const logger = new SecureLogger(options);
|
|
162
|
+
|
|
163
|
+
// Handle enabled/disabled patterns
|
|
164
|
+
if (
|
|
165
|
+
configuration.disabledPatterns &&
|
|
166
|
+
Array.isArray(configuration.disabledPatterns)
|
|
167
|
+
) {
|
|
168
|
+
configuration.disabledPatterns.forEach((patternName) => {
|
|
169
|
+
logger.removePattern(patternName);
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
if (
|
|
174
|
+
configuration.enabledPatterns &&
|
|
175
|
+
Array.isArray(configuration.enabledPatterns)
|
|
176
|
+
) {
|
|
177
|
+
// If specific patterns are listed, disable all others
|
|
178
|
+
const activePatterns = logger.getActivePatterns();
|
|
179
|
+
activePatterns.forEach((pattern) => {
|
|
180
|
+
if (!configuration.enabledPatterns.includes(pattern.name)) {
|
|
181
|
+
logger.removePattern(pattern.name);
|
|
182
|
+
}
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
return logger;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* Load default configuration
|
|
191
|
+
*
|
|
192
|
+
* Attempts to load configuration from default locations:
|
|
193
|
+
* 1. ./redaction-config.json (current directory)
|
|
194
|
+
* 2. ./config/redaction-patterns.json
|
|
195
|
+
* 3. src/config/redaction-patterns.json
|
|
196
|
+
*
|
|
197
|
+
* @param {string} [environment] - Environment name for overrides
|
|
198
|
+
* @returns {SecureLogger} Configured logger or default logger if no config found
|
|
199
|
+
*
|
|
200
|
+
* @example
|
|
201
|
+
* const logger = loadDefaultConfig();
|
|
202
|
+
* const prodLogger = loadDefaultConfig('production');
|
|
203
|
+
*/
|
|
204
|
+
function loadDefaultConfig(environment) {
|
|
205
|
+
const defaultPaths = [
|
|
206
|
+
path.join(process.cwd(), 'redaction-config.json'),
|
|
207
|
+
path.join(process.cwd(), 'config', 'redaction-patterns.json'),
|
|
208
|
+
path.join(__dirname, '..', 'config', 'redaction-patterns.json'),
|
|
209
|
+
];
|
|
210
|
+
|
|
211
|
+
for (const configPath of defaultPaths) {
|
|
212
|
+
if (fs.existsSync(configPath)) {
|
|
213
|
+
try {
|
|
214
|
+
return createLoggerFromConfig(configPath, environment);
|
|
215
|
+
} catch (error) {
|
|
216
|
+
console.warn(
|
|
217
|
+
`Failed to load config from ${configPath}:`,
|
|
218
|
+
error.message,
|
|
219
|
+
);
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
// Return default logger if no config found
|
|
225
|
+
return new SecureLogger();
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
/**
|
|
229
|
+
* Validate configuration against schema
|
|
230
|
+
*
|
|
231
|
+
* @param {Object} config - Configuration to validate
|
|
232
|
+
* @returns {Object} Validation result { valid: boolean, errors: string[] }
|
|
233
|
+
*
|
|
234
|
+
* @example
|
|
235
|
+
* const result = validateConfig(myConfig);
|
|
236
|
+
* if (!result.valid) {
|
|
237
|
+
* console.error('Config errors:', result.errors);
|
|
238
|
+
* }
|
|
239
|
+
*/
|
|
240
|
+
function validateConfig(config) {
|
|
241
|
+
const errors = [];
|
|
242
|
+
|
|
243
|
+
// Check required fields
|
|
244
|
+
if (config.enabled !== undefined && typeof config.enabled !== 'boolean') {
|
|
245
|
+
errors.push('enabled must be a boolean');
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
if (
|
|
249
|
+
config.trackStats !== undefined &&
|
|
250
|
+
typeof config.trackStats !== 'boolean'
|
|
251
|
+
) {
|
|
252
|
+
errors.push('trackStats must be a boolean');
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
if (
|
|
256
|
+
config.redactionMarker !== undefined &&
|
|
257
|
+
typeof config.redactionMarker !== 'string'
|
|
258
|
+
) {
|
|
259
|
+
errors.push('redactionMarker must be a string');
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
// Validate custom patterns
|
|
263
|
+
if (config.customPatterns && typeof config.customPatterns === 'object') {
|
|
264
|
+
for (const [name, pattern] of Object.entries(config.customPatterns)) {
|
|
265
|
+
if (!pattern.regex) {
|
|
266
|
+
errors.push(`Custom pattern '${name}' missing regex field`);
|
|
267
|
+
}
|
|
268
|
+
if (!pattern.replacement) {
|
|
269
|
+
errors.push(`Custom pattern '${name}' missing replacement field`);
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
// Try to compile regex
|
|
273
|
+
if (pattern.regex) {
|
|
274
|
+
try {
|
|
275
|
+
compileRegex(pattern.regex, pattern.flags || 'g');
|
|
276
|
+
} catch (error) {
|
|
277
|
+
errors.push(
|
|
278
|
+
`Custom pattern '${name}' has invalid regex: ${error.message}`,
|
|
279
|
+
);
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
// Validate sensitive fields
|
|
286
|
+
if (config.sensitiveFields !== undefined) {
|
|
287
|
+
if (!Array.isArray(config.sensitiveFields)) {
|
|
288
|
+
errors.push('sensitiveFields must be an array');
|
|
289
|
+
} else {
|
|
290
|
+
config.sensitiveFields.forEach((field, index) => {
|
|
291
|
+
if (typeof field !== 'string') {
|
|
292
|
+
errors.push(`sensitiveFields[${index}] must be a string`);
|
|
293
|
+
}
|
|
294
|
+
});
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
return {
|
|
299
|
+
valid: errors.length === 0,
|
|
300
|
+
errors,
|
|
301
|
+
};
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
/**
|
|
305
|
+
* Create configuration template
|
|
306
|
+
*
|
|
307
|
+
* @returns {Object} Template configuration object
|
|
308
|
+
*
|
|
309
|
+
* @example
|
|
310
|
+
* const template = createConfigTemplate();
|
|
311
|
+
* // Modify template as needed
|
|
312
|
+
* const logger = createLoggerFromConfig(template);
|
|
313
|
+
*/
|
|
314
|
+
function createConfigTemplate() {
|
|
315
|
+
return {
|
|
316
|
+
enabled: true,
|
|
317
|
+
trackStats: true,
|
|
318
|
+
redactionMarker: '[REDACTED]',
|
|
319
|
+
redactEmails: false,
|
|
320
|
+
redactIPs: false,
|
|
321
|
+
customPatterns: {},
|
|
322
|
+
sensitiveFields: [],
|
|
323
|
+
disabledPatterns: [],
|
|
324
|
+
enabledPatterns: [],
|
|
325
|
+
environments: {
|
|
326
|
+
development: {
|
|
327
|
+
enabled: false,
|
|
328
|
+
trackStats: false,
|
|
329
|
+
},
|
|
330
|
+
production: {
|
|
331
|
+
enabled: true,
|
|
332
|
+
trackStats: true,
|
|
333
|
+
redactEmails: true,
|
|
334
|
+
redactIPs: true,
|
|
335
|
+
},
|
|
336
|
+
test: {
|
|
337
|
+
enabled: false,
|
|
338
|
+
},
|
|
339
|
+
},
|
|
340
|
+
};
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
module.exports = {
|
|
344
|
+
createLoggerFromConfig,
|
|
345
|
+
loadDefaultConfig,
|
|
346
|
+
validateConfig,
|
|
347
|
+
createConfigTemplate,
|
|
348
|
+
loadConfigFile,
|
|
349
|
+
compileRegex,
|
|
350
|
+
applyEnvironmentOverrides,
|
|
351
|
+
convertCustomPatterns,
|
|
352
|
+
};
|