UNPKG

uz-pay-sdk

Version:

🚀 Universal Payment SDK for Uzbekistan - Integrate Payme, Click, UzCard, Humo & Apelsin with one simple API. Battle-tested, production-ready, 95% faster integration.

131 lines • 5.03 kB
"use strict"; var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.HttpLoggingInterceptor = void 0; const common_1 = require("@nestjs/common"); const operators_1 = require("rxjs/operators"); const rxjs_1 = require("rxjs"); const logger_config_1 = require("../logger/logger.config"); let HttpLoggingInterceptor = class HttpLoggingInterceptor { intercept(context, next) { if (context.getType() !== 'http') { return next.handle(); } const ctx = context.switchToHttp(); const request = ctx.getRequest(); const response = ctx.getResponse(); const { method, url, body, headers, query, params } = request; const userAgent = headers['user-agent'] || ''; const ip = request.ip || 'unknown'; const startTime = Date.now(); const requestId = this.generateRequestId(); // Request logini yozish const requestLog = { requestId, type: 'HTTP_REQUEST', method, url, ip, userAgent, query, params, body: this.sanitizeRequestBody(body), headers: this.sanitizeHeaders(headers), timestamp: new Date().toISOString(), }; logger_config_1.httpLogger.info('HTTP Request', requestLog); logger_config_1.logger.debug(`HTTP ${method} ${url} started`, { requestId, ip }); return next.handle().pipe((0, operators_1.tap)((data) => { const duration = Date.now() - startTime; const { statusCode } = response; const responseLog = { requestId, type: 'HTTP_RESPONSE', method, url, statusCode, duration, responseSize: JSON.stringify(data).length, success: statusCode < 400, timestamp: new Date().toISOString(), }; logger_config_1.httpLogger.info('HTTP Response', responseLog); logger_config_1.logger.debug(`HTTP ${method} ${url} completed`, { requestId, statusCode, duration: `${duration}ms`, }); }), (0, operators_1.catchError)((error) => { const duration = Date.now() - startTime; const statusCode = error.status || 500; const errorLog = { requestId, type: 'HTTP_ERROR', method, url, statusCode, duration, error: error.message, stack: error.stack, timestamp: new Date().toISOString(), }; logger_config_1.httpLogger.error('HTTP Error', errorLog); logger_config_1.logger.error(`HTTP ${method} ${url} failed`, { requestId, statusCode, duration: `${duration}ms`, error: error.message, }); return (0, rxjs_1.throwError)(() => error); })); } generateRequestId() { return `http_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`; } sanitizeRequestBody(body) { if (!body || typeof body !== 'object') return body; const sensitiveFields = [ 'password', 'secret', 'key', 'token', 'cardNumber', 'cvv', 'pin', 'authorization', ]; const sanitized = { ...body }; for (const field of sensitiveFields) { if (sanitized[field]) { sanitized[field] = '*'.repeat(sanitized[field].toString().length); } } return sanitized; } sanitizeHeaders(headers) { const sensitiveHeaders = [ 'authorization', 'x-api-key', 'x-auth-token', 'cookie', ]; const sanitized = { ...headers }; for (const header of sensitiveHeaders) { if (sanitized[header]) { sanitized[header] = '***REDACTED***'; } } return sanitized; } }; exports.HttpLoggingInterceptor = HttpLoggingInterceptor; exports.HttpLoggingInterceptor = HttpLoggingInterceptor = __decorate([ (0, common_1.Injectable)() ], HttpLoggingInterceptor); //# sourceMappingURL=http-logging.interceptor.js.map