@morojs/moro 1.5.5 → 1.5.7

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.
Files changed (70) hide show
  1. package/dist/core/config/config-manager.d.ts +44 -0
  2. package/dist/core/config/config-manager.js +114 -0
  3. package/dist/core/config/config-manager.js.map +1 -0
  4. package/dist/core/config/config-sources.d.ts +21 -0
  5. package/dist/core/config/config-sources.js +314 -0
  6. package/dist/core/config/config-sources.js.map +1 -0
  7. package/dist/core/config/config-validator.d.ts +21 -0
  8. package/dist/core/config/config-validator.js +744 -0
  9. package/dist/core/config/config-validator.js.map +1 -0
  10. package/dist/core/config/file-loader.d.ts +0 -5
  11. package/dist/core/config/file-loader.js +0 -171
  12. package/dist/core/config/file-loader.js.map +1 -1
  13. package/dist/core/config/index.d.ts +39 -10
  14. package/dist/core/config/index.js +66 -29
  15. package/dist/core/config/index.js.map +1 -1
  16. package/dist/core/config/schema.js +29 -31
  17. package/dist/core/config/schema.js.map +1 -1
  18. package/dist/core/config/utils.d.ts +9 -2
  19. package/dist/core/config/utils.js +19 -32
  20. package/dist/core/config/utils.js.map +1 -1
  21. package/dist/core/framework.d.ts +4 -7
  22. package/dist/core/framework.js +38 -12
  23. package/dist/core/framework.js.map +1 -1
  24. package/dist/core/http/http-server.d.ts +12 -0
  25. package/dist/core/http/http-server.js +56 -0
  26. package/dist/core/http/http-server.js.map +1 -1
  27. package/dist/core/http/router.d.ts +12 -0
  28. package/dist/core/http/router.js +114 -36
  29. package/dist/core/http/router.js.map +1 -1
  30. package/dist/core/logger/index.d.ts +1 -1
  31. package/dist/core/logger/index.js +2 -1
  32. package/dist/core/logger/index.js.map +1 -1
  33. package/dist/core/logger/logger.d.ts +9 -1
  34. package/dist/core/logger/logger.js +36 -3
  35. package/dist/core/logger/logger.js.map +1 -1
  36. package/dist/core/routing/index.d.ts +20 -0
  37. package/dist/core/routing/index.js +109 -11
  38. package/dist/core/routing/index.js.map +1 -1
  39. package/dist/moro.d.ts +7 -20
  40. package/dist/moro.js +115 -200
  41. package/dist/moro.js.map +1 -1
  42. package/dist/types/config.d.ts +46 -2
  43. package/dist/types/core.d.ts +22 -39
  44. package/dist/types/logger.d.ts +4 -0
  45. package/package.json +1 -1
  46. package/src/core/config/config-manager.ts +133 -0
  47. package/src/core/config/config-sources.ts +384 -0
  48. package/src/core/config/config-validator.ts +1042 -0
  49. package/src/core/config/file-loader.ts +0 -233
  50. package/src/core/config/index.ts +77 -32
  51. package/src/core/config/schema.ts +29 -31
  52. package/src/core/config/utils.ts +22 -29
  53. package/src/core/framework.ts +51 -18
  54. package/src/core/http/http-server.ts +66 -0
  55. package/src/core/http/router.ts +127 -38
  56. package/src/core/logger/index.ts +1 -0
  57. package/src/core/logger/logger.ts +43 -4
  58. package/src/core/routing/index.ts +116 -12
  59. package/src/moro.ts +127 -233
  60. package/src/types/config.ts +47 -2
  61. package/src/types/core.ts +32 -43
  62. package/src/types/logger.ts +6 -0
  63. package/dist/core/config/loader.d.ts +0 -7
  64. package/dist/core/config/loader.js +0 -269
  65. package/dist/core/config/loader.js.map +0 -1
  66. package/dist/core/config/validation.d.ts +0 -17
  67. package/dist/core/config/validation.js +0 -131
  68. package/dist/core/config/validation.js.map +0 -1
  69. package/src/core/config/loader.ts +0 -633
  70. package/src/core/config/validation.ts +0 -140
@@ -0,0 +1,744 @@
1
+ "use strict";
2
+ /**
3
+ * Configuration Validator - Type-Safe Schema Validation
4
+ *
5
+ * This module provides runtime validation for configuration objects using
6
+ * simple TypeScript functions that match the type definitions exactly.
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.ConfigValidationError = void 0;
10
+ exports.validateConfig = validateConfig;
11
+ const logger_1 = require("../logger");
12
+ const logger = (0, logger_1.createFrameworkLogger)('ConfigValidator');
13
+ /**
14
+ * Configuration validation error with detailed context
15
+ */
16
+ class ConfigValidationError extends Error {
17
+ field;
18
+ value;
19
+ expectedType;
20
+ constructor(field, value, expectedType, message) {
21
+ super(`Configuration validation failed for '${field}': ${message}`);
22
+ this.field = field;
23
+ this.value = value;
24
+ this.expectedType = expectedType;
25
+ this.name = 'ConfigValidationError';
26
+ }
27
+ }
28
+ exports.ConfigValidationError = ConfigValidationError;
29
+ /**
30
+ * Validate and normalize a complete configuration object
31
+ * This ensures type safety and provides helpful error messages
32
+ */
33
+ function validateConfig(config) {
34
+ logger.debug('Validating configuration');
35
+ try {
36
+ const validatedConfig = {
37
+ server: validateServerConfig(config.server, 'server'),
38
+ serviceDiscovery: validateServiceDiscoveryConfig(config.serviceDiscovery, 'serviceDiscovery'),
39
+ database: validateDatabaseConfig(config.database, 'database'),
40
+ modules: validateModuleDefaultsConfig(config.modules, 'modules'),
41
+ logging: validateLoggingConfig(config.logging, 'logging'),
42
+ security: validateSecurityConfig(config.security, 'security'),
43
+ external: validateExternalServicesConfig(config.external, 'external'),
44
+ performance: validatePerformanceConfig(config.performance, 'performance'),
45
+ websocket: validateWebSocketConfig(config.websocket, 'websocket'),
46
+ };
47
+ logger.debug('Configuration validation successful');
48
+ return validatedConfig;
49
+ }
50
+ catch (error) {
51
+ if (error instanceof ConfigValidationError) {
52
+ logger.error(`❌ Configuration validation failed for '${error.field}':`, error.message);
53
+ // Provide helpful hints
54
+ provideValidationHints(error);
55
+ throw error;
56
+ }
57
+ logger.error('❌ Unexpected configuration validation error:', String(error));
58
+ throw new Error(`Configuration validation failed: ${String(error)}`);
59
+ }
60
+ }
61
+ /**
62
+ * Validate server configuration
63
+ */
64
+ function validateServerConfig(config, path) {
65
+ if (!config || typeof config !== 'object') {
66
+ throw new ConfigValidationError(path, config, 'object', 'Server configuration must be an object');
67
+ }
68
+ return {
69
+ port: validatePort(config.port, `${path}.port`),
70
+ host: validateString(config.host, `${path}.host`),
71
+ maxConnections: validateNumber(config.maxConnections, `${path}.maxConnections`, { min: 1 }),
72
+ timeout: validateNumber(config.timeout, `${path}.timeout`, { min: 1000 }),
73
+ bodySizeLimit: validateString(config.bodySizeLimit, `${path}.bodySizeLimit`),
74
+ requestTracking: {
75
+ enabled: validateBoolean(config.requestTracking?.enabled, `${path}.requestTracking.enabled`),
76
+ },
77
+ errorBoundary: {
78
+ enabled: validateBoolean(config.errorBoundary?.enabled, `${path}.errorBoundary.enabled`),
79
+ },
80
+ };
81
+ }
82
+ /**
83
+ * Validate service discovery configuration
84
+ */
85
+ function validateServiceDiscoveryConfig(config, path) {
86
+ if (!config || typeof config !== 'object') {
87
+ throw new ConfigValidationError(path, config, 'object', 'Service discovery configuration must be an object');
88
+ }
89
+ return {
90
+ enabled: validateBoolean(config.enabled, `${path}.enabled`),
91
+ type: validateEnum(config.type, ['memory', 'consul', 'kubernetes'], `${path}.type`),
92
+ consulUrl: validateString(config.consulUrl, `${path}.consulUrl`),
93
+ kubernetesNamespace: validateString(config.kubernetesNamespace, `${path}.kubernetesNamespace`),
94
+ healthCheckInterval: validateNumber(config.healthCheckInterval, `${path}.healthCheckInterval`, {
95
+ min: 1000,
96
+ }),
97
+ retryAttempts: validateNumber(config.retryAttempts, `${path}.retryAttempts`, { min: 0 }),
98
+ };
99
+ }
100
+ /**
101
+ * Validate database configuration
102
+ */
103
+ function validateDatabaseConfig(config, path) {
104
+ if (!config || typeof config !== 'object') {
105
+ throw new ConfigValidationError(path, config, 'object', 'Database configuration must be an object');
106
+ }
107
+ const result = {};
108
+ // Optional URL
109
+ if (config.url !== undefined) {
110
+ result.url = validateString(config.url, `${path}.url`);
111
+ }
112
+ // Optional Redis - only validate if present
113
+ if (config.redis !== undefined) {
114
+ result.redis = validateRedisConfig(config.redis, `${path}.redis`);
115
+ }
116
+ // Optional MySQL - only validate if present
117
+ if (config.mysql !== undefined) {
118
+ result.mysql = validateMySQLConfig(config.mysql, `${path}.mysql`);
119
+ }
120
+ // Optional PostgreSQL - only validate if present
121
+ if (config.postgresql !== undefined) {
122
+ result.postgresql = validatePostgreSQLConfig(config.postgresql, `${path}.postgresql`);
123
+ }
124
+ // Optional SQLite - only validate if present
125
+ if (config.sqlite !== undefined) {
126
+ result.sqlite = validateSQLiteConfig(config.sqlite, `${path}.sqlite`);
127
+ }
128
+ // Optional MongoDB - only validate if present
129
+ if (config.mongodb !== undefined) {
130
+ result.mongodb = validateMongoDBConfig(config.mongodb, `${path}.mongodb`);
131
+ }
132
+ return result;
133
+ }
134
+ /**
135
+ * Validate Redis configuration
136
+ */
137
+ function validateRedisConfig(config, path) {
138
+ if (!config || typeof config !== 'object') {
139
+ throw new ConfigValidationError(path, config, 'object', 'Redis configuration must be an object');
140
+ }
141
+ return {
142
+ url: validateString(config.url, `${path}.url`),
143
+ maxRetries: validateNumber(config.maxRetries, `${path}.maxRetries`, { min: 0 }),
144
+ retryDelay: validateNumber(config.retryDelay, `${path}.retryDelay`, { min: 0 }),
145
+ keyPrefix: validateString(config.keyPrefix, `${path}.keyPrefix`),
146
+ };
147
+ }
148
+ /**
149
+ * Validate MySQL configuration
150
+ */
151
+ function validateMySQLConfig(config, path) {
152
+ if (!config || typeof config !== 'object') {
153
+ throw new ConfigValidationError(path, config, 'object', 'MySQL configuration must be an object');
154
+ }
155
+ const result = {
156
+ host: validateString(config.host, `${path}.host`),
157
+ port: validatePort(config.port, `${path}.port`),
158
+ connectionLimit: validateNumber(config.connectionLimit, `${path}.connectionLimit`, { min: 1 }),
159
+ acquireTimeout: validateNumber(config.acquireTimeout, `${path}.acquireTimeout`, { min: 1000 }),
160
+ timeout: validateNumber(config.timeout, `${path}.timeout`, { min: 1000 }),
161
+ };
162
+ // Optional fields
163
+ if (config.database !== undefined) {
164
+ result.database = validateString(config.database, `${path}.database`);
165
+ }
166
+ if (config.username !== undefined) {
167
+ result.username = validateString(config.username, `${path}.username`);
168
+ }
169
+ if (config.password !== undefined) {
170
+ result.password = validateString(config.password, `${path}.password`);
171
+ }
172
+ return result;
173
+ }
174
+ /**
175
+ * Validate PostgreSQL configuration
176
+ */
177
+ function validatePostgreSQLConfig(config, path) {
178
+ if (!config || typeof config !== 'object') {
179
+ throw new ConfigValidationError(path, config, 'object', 'PostgreSQL configuration must be an object');
180
+ }
181
+ const result = {
182
+ host: validateString(config.host, `${path}.host`),
183
+ port: validatePort(config.port, `${path}.port`),
184
+ connectionLimit: validateNumber(config.connectionLimit, `${path}.connectionLimit`, { min: 1 }),
185
+ };
186
+ // Optional fields
187
+ if (config.database !== undefined) {
188
+ result.database = validateString(config.database, `${path}.database`);
189
+ }
190
+ if (config.user !== undefined) {
191
+ result.user = validateString(config.user, `${path}.user`);
192
+ }
193
+ if (config.password !== undefined) {
194
+ result.password = validateString(config.password, `${path}.password`);
195
+ }
196
+ if (config.ssl !== undefined) {
197
+ result.ssl = validateBoolean(config.ssl, `${path}.ssl`);
198
+ }
199
+ return result;
200
+ }
201
+ /**
202
+ * Validate SQLite configuration
203
+ */
204
+ function validateSQLiteConfig(config, path) {
205
+ if (!config || typeof config !== 'object') {
206
+ throw new ConfigValidationError(path, config, 'object', 'SQLite configuration must be an object');
207
+ }
208
+ const result = {
209
+ filename: validateString(config.filename, `${path}.filename`),
210
+ };
211
+ // Optional fields
212
+ if (config.memory !== undefined) {
213
+ result.memory = validateBoolean(config.memory, `${path}.memory`);
214
+ }
215
+ if (config.verbose !== undefined) {
216
+ result.verbose = validateBoolean(config.verbose, `${path}.verbose`);
217
+ }
218
+ return result;
219
+ }
220
+ /**
221
+ * Validate MongoDB configuration
222
+ */
223
+ function validateMongoDBConfig(config, path) {
224
+ if (!config || typeof config !== 'object') {
225
+ throw new ConfigValidationError(path, config, 'object', 'MongoDB configuration must be an object');
226
+ }
227
+ const result = {};
228
+ // Either url or host+port
229
+ if (config.url !== undefined) {
230
+ result.url = validateString(config.url, `${path}.url`);
231
+ }
232
+ if (config.host !== undefined) {
233
+ result.host = validateString(config.host, `${path}.host`);
234
+ }
235
+ if (config.port !== undefined) {
236
+ result.port = validatePort(config.port, `${path}.port`);
237
+ }
238
+ if (config.database !== undefined) {
239
+ result.database = validateString(config.database, `${path}.database`);
240
+ }
241
+ if (config.username !== undefined) {
242
+ result.username = validateString(config.username, `${path}.username`);
243
+ }
244
+ if (config.password !== undefined) {
245
+ result.password = validateString(config.password, `${path}.password`);
246
+ }
247
+ return result;
248
+ }
249
+ /**
250
+ * Validate module defaults configuration
251
+ */
252
+ function validateModuleDefaultsConfig(config, path) {
253
+ if (!config || typeof config !== 'object') {
254
+ throw new ConfigValidationError(path, config, 'object', 'Module defaults configuration must be an object');
255
+ }
256
+ return {
257
+ cache: validateCacheConfig(config.cache, `${path}.cache`),
258
+ rateLimit: validateRateLimitConfig(config.rateLimit, `${path}.rateLimit`),
259
+ validation: validateValidationConfig(config.validation, `${path}.validation`),
260
+ };
261
+ }
262
+ /**
263
+ * Validate cache configuration
264
+ */
265
+ function validateCacheConfig(config, path) {
266
+ if (!config || typeof config !== 'object') {
267
+ throw new ConfigValidationError(path, config, 'object', 'Cache configuration must be an object');
268
+ }
269
+ return {
270
+ enabled: validateBoolean(config.enabled, `${path}.enabled`),
271
+ defaultTtl: validateNumber(config.defaultTtl, `${path}.defaultTtl`, { min: 0 }),
272
+ maxSize: validateNumber(config.maxSize, `${path}.maxSize`, { min: 1 }),
273
+ strategy: validateEnum(config.strategy, ['lru', 'lfu', 'fifo'], `${path}.strategy`),
274
+ };
275
+ }
276
+ /**
277
+ * Validate rate limit configuration
278
+ */
279
+ function validateRateLimitConfig(config, path) {
280
+ if (!config || typeof config !== 'object') {
281
+ throw new ConfigValidationError(path, config, 'object', 'Rate limit configuration must be an object');
282
+ }
283
+ return {
284
+ enabled: validateBoolean(config.enabled, `${path}.enabled`),
285
+ defaultRequests: validateNumber(config.defaultRequests, `${path}.defaultRequests`, { min: 1 }),
286
+ defaultWindow: validateNumber(config.defaultWindow, `${path}.defaultWindow`, { min: 1000 }),
287
+ skipSuccessfulRequests: validateBoolean(config.skipSuccessfulRequests, `${path}.skipSuccessfulRequests`),
288
+ skipFailedRequests: validateBoolean(config.skipFailedRequests, `${path}.skipFailedRequests`),
289
+ };
290
+ }
291
+ /**
292
+ * Validate validation configuration
293
+ */
294
+ function validateValidationConfig(config, path) {
295
+ if (!config || typeof config !== 'object') {
296
+ throw new ConfigValidationError(path, config, 'object', 'Validation configuration must be an object');
297
+ }
298
+ return {
299
+ enabled: validateBoolean(config.enabled, `${path}.enabled`),
300
+ stripUnknown: validateBoolean(config.stripUnknown, `${path}.stripUnknown`),
301
+ abortEarly: validateBoolean(config.abortEarly, `${path}.abortEarly`),
302
+ };
303
+ }
304
+ /**
305
+ * Validate logging configuration
306
+ */
307
+ function validateLoggingConfig(config, path) {
308
+ if (!config || typeof config !== 'object') {
309
+ throw new ConfigValidationError(path, config, 'object', 'Logging configuration must be an object');
310
+ }
311
+ return {
312
+ level: validateEnum(config.level, ['debug', 'info', 'warn', 'error', 'fatal'], `${path}.level`),
313
+ format: validateEnum(config.format, ['pretty', 'json', 'compact'], `${path}.format`),
314
+ enableColors: validateBoolean(config.enableColors, `${path}.enableColors`),
315
+ enableTimestamp: validateBoolean(config.enableTimestamp, `${path}.enableTimestamp`),
316
+ enableContext: validateBoolean(config.enableContext, `${path}.enableContext`),
317
+ outputs: validateLoggingOutputsConfig(config.outputs, `${path}.outputs`),
318
+ };
319
+ }
320
+ /**
321
+ * Validate logging outputs configuration
322
+ */
323
+ function validateLoggingOutputsConfig(config, path) {
324
+ if (!config || typeof config !== 'object') {
325
+ throw new ConfigValidationError(path, config, 'object', 'Logging outputs configuration must be an object');
326
+ }
327
+ return {
328
+ console: validateBoolean(config.console, `${path}.console`),
329
+ file: validateLoggingFileConfig(config.file, `${path}.file`),
330
+ webhook: validateLoggingWebhookConfig(config.webhook, `${path}.webhook`),
331
+ };
332
+ }
333
+ /**
334
+ * Validate logging file configuration
335
+ */
336
+ function validateLoggingFileConfig(config, path) {
337
+ if (!config || typeof config !== 'object') {
338
+ throw new ConfigValidationError(path, config, 'object', 'Logging file configuration must be an object');
339
+ }
340
+ return {
341
+ enabled: validateBoolean(config.enabled, `${path}.enabled`),
342
+ path: validateString(config.path, `${path}.path`),
343
+ maxSize: validateString(config.maxSize, `${path}.maxSize`),
344
+ maxFiles: validateNumber(config.maxFiles, `${path}.maxFiles`, { min: 1 }),
345
+ };
346
+ }
347
+ /**
348
+ * Validate logging webhook configuration
349
+ */
350
+ function validateLoggingWebhookConfig(config, path) {
351
+ if (!config || typeof config !== 'object') {
352
+ throw new ConfigValidationError(path, config, 'object', 'Logging webhook configuration must be an object');
353
+ }
354
+ const result = {
355
+ enabled: validateBoolean(config.enabled, `${path}.enabled`),
356
+ headers: validateObject(config.headers, `${path}.headers`),
357
+ };
358
+ // Optional URL
359
+ if (config.url !== undefined) {
360
+ result.url = validateString(config.url, `${path}.url`);
361
+ }
362
+ return result;
363
+ }
364
+ /**
365
+ * Validate security configuration
366
+ */
367
+ function validateSecurityConfig(config, path) {
368
+ if (!config || typeof config !== 'object') {
369
+ throw new ConfigValidationError(path, config, 'object', 'Security configuration must be an object');
370
+ }
371
+ return {
372
+ cors: validateCorsConfig(config.cors, `${path}.cors`),
373
+ helmet: validateHelmetConfig(config.helmet, `${path}.helmet`),
374
+ rateLimit: validateSecurityRateLimitConfig(config.rateLimit, `${path}.rateLimit`),
375
+ };
376
+ }
377
+ /**
378
+ * Validate CORS configuration
379
+ */
380
+ function validateCorsConfig(config, path) {
381
+ if (!config || typeof config !== 'object') {
382
+ throw new ConfigValidationError(path, config, 'object', 'CORS configuration must be an object');
383
+ }
384
+ return {
385
+ enabled: validateBoolean(config.enabled, `${path}.enabled`),
386
+ origin: validateCorsOrigin(config.origin, `${path}.origin`),
387
+ methods: validateStringArray(config.methods, `${path}.methods`),
388
+ allowedHeaders: validateStringArray(config.allowedHeaders, `${path}.allowedHeaders`),
389
+ credentials: validateBoolean(config.credentials, `${path}.credentials`),
390
+ };
391
+ }
392
+ /**
393
+ * Validate CORS origin (can be string, array, or boolean)
394
+ */
395
+ function validateCorsOrigin(value, path) {
396
+ if (typeof value === 'boolean' || typeof value === 'string') {
397
+ return value;
398
+ }
399
+ if (Array.isArray(value)) {
400
+ return validateStringArray(value, path);
401
+ }
402
+ throw new ConfigValidationError(path, value, 'string | string[] | boolean', 'Must be a string, array of strings, or boolean');
403
+ }
404
+ /**
405
+ * Validate helmet configuration
406
+ */
407
+ function validateHelmetConfig(config, path) {
408
+ if (!config || typeof config !== 'object') {
409
+ throw new ConfigValidationError(path, config, 'object', 'Helmet configuration must be an object');
410
+ }
411
+ return {
412
+ enabled: validateBoolean(config.enabled, `${path}.enabled`),
413
+ contentSecurityPolicy: validateBoolean(config.contentSecurityPolicy, `${path}.contentSecurityPolicy`),
414
+ hsts: validateBoolean(config.hsts, `${path}.hsts`),
415
+ noSniff: validateBoolean(config.noSniff, `${path}.noSniff`),
416
+ frameguard: validateBoolean(config.frameguard, `${path}.frameguard`),
417
+ };
418
+ }
419
+ /**
420
+ * Validate security rate limit configuration
421
+ */
422
+ function validateSecurityRateLimitConfig(config, path) {
423
+ if (!config || typeof config !== 'object') {
424
+ throw new ConfigValidationError(path, config, 'object', 'Security rate limit configuration must be an object');
425
+ }
426
+ return {
427
+ global: validateGlobalRateLimitConfig(config.global, `${path}.global`),
428
+ };
429
+ }
430
+ /**
431
+ * Validate global rate limit configuration
432
+ */
433
+ function validateGlobalRateLimitConfig(config, path) {
434
+ if (!config || typeof config !== 'object') {
435
+ throw new ConfigValidationError(path, config, 'object', 'Global rate limit configuration must be an object');
436
+ }
437
+ return {
438
+ enabled: validateBoolean(config.enabled, `${path}.enabled`),
439
+ requests: validateNumber(config.requests, `${path}.requests`, { min: 1 }),
440
+ window: validateNumber(config.window, `${path}.window`, { min: 1000 }),
441
+ };
442
+ }
443
+ /**
444
+ * Validate external services configuration
445
+ */
446
+ function validateExternalServicesConfig(config, path) {
447
+ if (!config || typeof config !== 'object') {
448
+ throw new ConfigValidationError(path, config, 'object', 'External services configuration must be an object');
449
+ }
450
+ const result = {};
451
+ // Optional services - only validate if present
452
+ if (config.stripe !== undefined) {
453
+ result.stripe = validateStripeConfig(config.stripe, `${path}.stripe`);
454
+ }
455
+ if (config.paypal !== undefined) {
456
+ result.paypal = validatePayPalConfig(config.paypal, `${path}.paypal`);
457
+ }
458
+ if (config.smtp !== undefined) {
459
+ result.smtp = validateSMTPConfig(config.smtp, `${path}.smtp`);
460
+ }
461
+ return result;
462
+ }
463
+ /**
464
+ * Validate Stripe configuration
465
+ */
466
+ function validateStripeConfig(config, path) {
467
+ if (!config || typeof config !== 'object') {
468
+ throw new ConfigValidationError(path, config, 'object', 'Stripe configuration must be an object');
469
+ }
470
+ const result = {};
471
+ // Optional fields
472
+ if (config.secretKey !== undefined) {
473
+ result.secretKey = validateString(config.secretKey, `${path}.secretKey`);
474
+ }
475
+ if (config.publishableKey !== undefined) {
476
+ result.publishableKey = validateString(config.publishableKey, `${path}.publishableKey`);
477
+ }
478
+ if (config.webhookSecret !== undefined) {
479
+ result.webhookSecret = validateString(config.webhookSecret, `${path}.webhookSecret`);
480
+ }
481
+ if (config.apiVersion !== undefined) {
482
+ result.apiVersion = validateString(config.apiVersion, `${path}.apiVersion`);
483
+ }
484
+ else {
485
+ result.apiVersion = '2023-10-16'; // Default API version
486
+ }
487
+ return result;
488
+ }
489
+ /**
490
+ * Validate PayPal configuration
491
+ */
492
+ function validatePayPalConfig(config, path) {
493
+ if (!config || typeof config !== 'object') {
494
+ throw new ConfigValidationError(path, config, 'object', 'PayPal configuration must be an object');
495
+ }
496
+ const result = {
497
+ environment: validateEnum(config.environment, ['sandbox', 'production'], `${path}.environment`),
498
+ };
499
+ // Optional fields
500
+ if (config.clientId !== undefined) {
501
+ result.clientId = validateString(config.clientId, `${path}.clientId`);
502
+ }
503
+ if (config.clientSecret !== undefined) {
504
+ result.clientSecret = validateString(config.clientSecret, `${path}.clientSecret`);
505
+ }
506
+ if (config.webhookId !== undefined) {
507
+ result.webhookId = validateString(config.webhookId, `${path}.webhookId`);
508
+ }
509
+ return result;
510
+ }
511
+ /**
512
+ * Validate SMTP configuration
513
+ */
514
+ function validateSMTPConfig(config, path) {
515
+ if (!config || typeof config !== 'object') {
516
+ throw new ConfigValidationError(path, config, 'object', 'SMTP configuration must be an object');
517
+ }
518
+ const result = {
519
+ port: validatePort(config.port, `${path}.port`),
520
+ secure: validateBoolean(config.secure, `${path}.secure`),
521
+ };
522
+ // Optional fields
523
+ if (config.host !== undefined) {
524
+ result.host = validateString(config.host, `${path}.host`);
525
+ }
526
+ if (config.username !== undefined) {
527
+ result.username = validateString(config.username, `${path}.username`);
528
+ }
529
+ if (config.password !== undefined) {
530
+ result.password = validateString(config.password, `${path}.password`);
531
+ }
532
+ return result;
533
+ }
534
+ /**
535
+ * Validate performance configuration
536
+ */
537
+ function validatePerformanceConfig(config, path) {
538
+ if (!config || typeof config !== 'object') {
539
+ throw new ConfigValidationError(path, config, 'object', 'Performance configuration must be an object');
540
+ }
541
+ return {
542
+ compression: validateCompressionConfig(config.compression, `${path}.compression`),
543
+ circuitBreaker: validateCircuitBreakerConfig(config.circuitBreaker, `${path}.circuitBreaker`),
544
+ clustering: validateClusteringConfig(config.clustering, `${path}.clustering`),
545
+ };
546
+ }
547
+ /**
548
+ * Validate compression configuration
549
+ */
550
+ function validateCompressionConfig(config, path) {
551
+ if (!config || typeof config !== 'object') {
552
+ throw new ConfigValidationError(path, config, 'object', 'Compression configuration must be an object');
553
+ }
554
+ return {
555
+ enabled: validateBoolean(config.enabled, `${path}.enabled`),
556
+ level: validateNumber(config.level, `${path}.level`, { min: 1, max: 9 }),
557
+ threshold: validateNumber(config.threshold, `${path}.threshold`, { min: 0 }),
558
+ };
559
+ }
560
+ /**
561
+ * Validate circuit breaker configuration
562
+ */
563
+ function validateCircuitBreakerConfig(config, path) {
564
+ if (!config || typeof config !== 'object') {
565
+ throw new ConfigValidationError(path, config, 'object', 'Circuit breaker configuration must be an object');
566
+ }
567
+ return {
568
+ enabled: validateBoolean(config.enabled, `${path}.enabled`),
569
+ failureThreshold: validateNumber(config.failureThreshold, `${path}.failureThreshold`, {
570
+ min: 1,
571
+ }),
572
+ resetTimeout: validateNumber(config.resetTimeout, `${path}.resetTimeout`, { min: 1000 }),
573
+ monitoringPeriod: validateNumber(config.monitoringPeriod, `${path}.monitoringPeriod`, {
574
+ min: 1000,
575
+ }),
576
+ };
577
+ }
578
+ /**
579
+ * Validate clustering configuration
580
+ */
581
+ function validateClusteringConfig(config, path) {
582
+ if (!config || typeof config !== 'object') {
583
+ throw new ConfigValidationError(path, config, 'object', 'Clustering configuration must be an object');
584
+ }
585
+ const result = {
586
+ enabled: validateBoolean(config.enabled, `${path}.enabled`),
587
+ };
588
+ // Workers can be number or 'auto'
589
+ if (typeof config.workers === 'string' && config.workers === 'auto') {
590
+ result.workers = 'auto';
591
+ }
592
+ else {
593
+ result.workers = validateNumber(config.workers, `${path}.workers`, { min: 1 });
594
+ }
595
+ // Optional memoryPerWorkerGB
596
+ if (config.memoryPerWorkerGB !== undefined) {
597
+ result.memoryPerWorkerGB = validateNumber(config.memoryPerWorkerGB, `${path}.memoryPerWorkerGB`, { min: 0.1 });
598
+ }
599
+ return result;
600
+ }
601
+ /**
602
+ * Validate WebSocket configuration
603
+ */
604
+ function validateWebSocketConfig(config, path) {
605
+ if (!config || typeof config !== 'object') {
606
+ throw new ConfigValidationError(path, config, 'object', 'WebSocket configuration must be an object');
607
+ }
608
+ const result = {
609
+ enabled: validateBoolean(config.enabled, `${path}.enabled`),
610
+ };
611
+ // Optional fields
612
+ if (config.adapter !== undefined) {
613
+ result.adapter = validateString(config.adapter, `${path}.adapter`);
614
+ }
615
+ if (config.compression !== undefined) {
616
+ result.compression = validateBoolean(config.compression, `${path}.compression`);
617
+ }
618
+ if (config.customIdGenerator !== undefined) {
619
+ result.customIdGenerator = config.customIdGenerator; // Function - no validation needed
620
+ }
621
+ if (config.options !== undefined) {
622
+ result.options = validateWebSocketOptions(config.options, `${path}.options`);
623
+ }
624
+ return result;
625
+ }
626
+ /**
627
+ * Validate WebSocket options
628
+ */
629
+ function validateWebSocketOptions(config, path) {
630
+ if (!config || typeof config !== 'object') {
631
+ throw new ConfigValidationError(path, config, 'object', 'WebSocket options must be an object');
632
+ }
633
+ const result = {};
634
+ if (config.cors !== undefined) {
635
+ result.cors = validateWebSocketCorsOptions(config.cors, `${path}.cors`);
636
+ }
637
+ if (config.path !== undefined) {
638
+ result.path = validateString(config.path, `${path}.path`);
639
+ }
640
+ if (config.maxPayloadLength !== undefined) {
641
+ result.maxPayloadLength = validateNumber(config.maxPayloadLength, `${path}.maxPayloadLength`, {
642
+ min: 1024,
643
+ });
644
+ }
645
+ return result;
646
+ }
647
+ /**
648
+ * Validate WebSocket CORS options
649
+ */
650
+ function validateWebSocketCorsOptions(config, path) {
651
+ if (!config || typeof config !== 'object') {
652
+ throw new ConfigValidationError(path, config, 'object', 'WebSocket CORS options must be an object');
653
+ }
654
+ const result = {};
655
+ if (config.origin !== undefined) {
656
+ result.origin = validateCorsOrigin(config.origin, `${path}.origin`);
657
+ }
658
+ if (config.credentials !== undefined) {
659
+ result.credentials = validateBoolean(config.credentials, `${path}.credentials`);
660
+ }
661
+ return result;
662
+ }
663
+ // Basic validation functions
664
+ function validatePort(value, path) {
665
+ const num = Number(value);
666
+ if (isNaN(num) || num < 1 || num > 65535) {
667
+ throw new ConfigValidationError(path, value, 'number (1-65535)', 'Must be a number between 1 and 65535');
668
+ }
669
+ return num;
670
+ }
671
+ function validateBoolean(value, path) {
672
+ if (value === 'true' || value === true)
673
+ return true;
674
+ if (value === 'false' || value === false)
675
+ return false;
676
+ if (value === '1' || value === 1)
677
+ return true;
678
+ if (value === '0' || value === 0)
679
+ return false;
680
+ throw new ConfigValidationError(path, value, 'boolean', 'Must be a boolean (true/false) or numeric (1/0)');
681
+ }
682
+ function validateNumber(value, path, options = {}) {
683
+ const num = Number(value);
684
+ if (isNaN(num)) {
685
+ throw new ConfigValidationError(path, value, 'number', 'Must be a valid number');
686
+ }
687
+ if (options.min !== undefined && num < options.min) {
688
+ throw new ConfigValidationError(path, value, `number >= ${options.min}`, `Must be at least ${options.min}`);
689
+ }
690
+ if (options.max !== undefined && num > options.max) {
691
+ throw new ConfigValidationError(path, value, `number <= ${options.max}`, `Must be at most ${options.max}`);
692
+ }
693
+ return num;
694
+ }
695
+ function validateString(value, path) {
696
+ if (typeof value !== 'string') {
697
+ throw new ConfigValidationError(path, value, 'string', 'Must be a string');
698
+ }
699
+ return value;
700
+ }
701
+ function validateEnum(value, validValues, path) {
702
+ const str = validateString(value, path);
703
+ if (!validValues.includes(str)) {
704
+ throw new ConfigValidationError(path, value, `one of: ${validValues.join(', ')}`, `Must be one of: ${validValues.join(', ')}`);
705
+ }
706
+ return str;
707
+ }
708
+ function validateStringArray(value, path) {
709
+ if (!Array.isArray(value)) {
710
+ // Try to parse comma-separated string
711
+ if (typeof value === 'string') {
712
+ return value
713
+ .split(',')
714
+ .map(s => s.trim())
715
+ .filter(s => s.length > 0);
716
+ }
717
+ throw new ConfigValidationError(path, value, 'string[]', 'Must be an array or comma-separated string');
718
+ }
719
+ return value.map((item, index) => validateString(item, `${path}[${index}]`));
720
+ }
721
+ function validateObject(value, path) {
722
+ if (!value || typeof value !== 'object' || Array.isArray(value)) {
723
+ throw new ConfigValidationError(path, value, 'object', 'Must be an object');
724
+ }
725
+ return value;
726
+ }
727
+ /**
728
+ * Provide helpful validation hints based on the error
729
+ */
730
+ function provideValidationHints(error) {
731
+ if (error.field.includes('port')) {
732
+ logger.error(' 💡 Hint: Ports must be numbers between 1 and 65535');
733
+ }
734
+ if (error.field.includes('url')) {
735
+ logger.error(' 💡 Hint: URLs must include protocol (http:// or https://)');
736
+ }
737
+ if (error.field.includes('environment')) {
738
+ logger.error(' 💡 Hint: NODE_ENV must be one of: development, staging, production');
739
+ }
740
+ if (error.field.includes('level')) {
741
+ logger.error(' 💡 Hint: Log level must be one of: debug, info, warn, error, fatal');
742
+ }
743
+ }
744
+ //# sourceMappingURL=config-validator.js.map