UNPKG

@kitstack/nest-powertools

Version:

A comprehensive collection of NestJS powertools, decorators, and utilities to supercharge your backend development

134 lines 4.02 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.PowertoolsConfigService = exports.DEFAULT_POWERTOOLS_CONFIG = void 0; const enums_1 = require("../types/enums"); exports.DEFAULT_POWERTOOLS_CONFIG = { global: { enabled: true, environment: enums_1.Environment.DEVELOPMENT, debug: false, requestIdHeader: 'x-request-id', enableMetrics: true, }, pagination: { enabled: true, defaultPage: 1, defaultLimit: 10, maxLimit: 100, allowUnlimited: false, sortOrder: enums_1.SortOrder.ASC, }, cache: { enabled: true, strategy: enums_1.CacheStrategy.MEMORY, ttl: 300000, }, validation: { enabled: true, strategy: enums_1.ValidationStrategy.STRICT, transform: true, whitelist: true, forbidNonWhitelisted: true, skipMissingProperties: false, }, logging: { enabled: true, level: enums_1.LogLevel.INFO, includeBody: false, includeHeaders: false, includeQuery: true, excludeFields: ['password', 'token', 'secret', 'key'], maxBodySize: 1024 * 10, sensitiveFields: ['authorization', 'cookie', 'x-api-key'], }, rateLimit: { enabled: true, strategy: enums_1.RateLimitStrategy.FIXED_WINDOW, windowMs: 15 * 60 * 1000, max: 100, message: 'Too many requests', skipSuccessfulRequests: false, skipFailedRequests: false, }, audit: { enabled: true, level: enums_1.AuditLevel.MEDIUM, includeRequestBody: false, includeResponseBody: false, excludeFields: ['password', 'token', 'secret'], action: '', storage: { type: 'file', filePath: './audit-logs.json', }, }, resilientHttp: { enabled: true, timeout: 10000, enableLogging: true, enableMetrics: true, retry: { enabled: true, maxAttempts: 3, delay: 1000, strategy: enums_1.RetryStrategy.EXPONENTIAL_BACKOFF, exponentialBase: 2, maxDelay: 30000, }, circuitBreaker: { enabled: false, failureThreshold: 5, resetTimeout: 60000, monitoringPeriod: 30000, }, }, auth: { enabled: true, requireAll: false, }, }; class PowertoolsConfigService { constructor(config = exports.DEFAULT_POWERTOOLS_CONFIG) { this.config = this.mergeConfig(exports.DEFAULT_POWERTOOLS_CONFIG, config); } static getInstance(config) { if (!PowertoolsConfigService.instance) { PowertoolsConfigService.instance = new PowertoolsConfigService(config); } return PowertoolsConfigService.instance; } getConfig() { return { ...this.config }; } updateConfig(updates) { this.config = this.mergeConfig(this.config, updates); } getFeatureConfig(feature) { return this.config[feature]; } isFeatureEnabled(feature) { const featureConfig = this.config[feature]; return (featureConfig?.enabled !== false && this.config.global?.enabled !== false); } mergeConfig(base, override) { const merged = { ...base }; Object.keys(override).forEach((key) => { const typedKey = key; if (override[typedKey] && typeof override[typedKey] === 'object') { merged[typedKey] = { ...base[typedKey], ...override[typedKey] }; } else { merged[typedKey] = override[typedKey]; } }); return merged; } reset() { this.config = { ...exports.DEFAULT_POWERTOOLS_CONFIG }; } validateConfig() { return true; } } exports.PowertoolsConfigService = PowertoolsConfigService; //# sourceMappingURL=powertools.config.js.map