UNPKG

logs-interceptor

Version:

High-performance, production-ready log interceptor for Node.js applications with Loki integration. Built with Clean Architecture principles. Supports Node.js, Browser, and Node-RED.

88 lines 3.52 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); __setModuleDefault(result, mod); return result; }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.AxiosHttpClient = void 0; /** * Infrastructure: AxiosHttpClient * HTTP client implementation using Axios */ const axios_1 = __importDefault(require("axios")); const zlib = __importStar(require("zlib")); class AxiosHttpClient { constructor(baseURL, defaultHeaders) { this.client = axios_1.default.create({ baseURL, headers: defaultHeaders, maxContentLength: 100 * 1024 * 1024, maxBodyLength: 100 * 1024 * 1024, }); } async post(url, data, options = {}) { var _a, _b, _c, _d; const maxRetries = (_a = options.retries) !== null && _a !== void 0 ? _a : 0; let lastError; for (let attempt = 0; attempt <= maxRetries; attempt++) { try { let payload = JSON.stringify(data); const headers = { ...options.headers, }; // Apply compression if enabled if (options.compression) { payload = zlib.gzipSync(payload, { level: (_b = options.compressionLevel) !== null && _b !== void 0 ? _b : 6, }); headers['Content-Encoding'] = 'gzip'; } const config = { method: 'POST', url, data: payload, headers, timeout: (_c = options.timeout) !== null && _c !== void 0 ? _c : 5000, }; await this.client.request(config); return; } catch (error) { lastError = error; if (attempt < maxRetries) { const delay = ((_d = options.retryDelay) !== null && _d !== void 0 ? _d : 1000) * Math.pow(2, attempt); const jitter = Math.random() * 1000; await this.sleep(delay + jitter); } } } throw lastError !== null && lastError !== void 0 ? lastError : new Error('HTTP request failed'); } sleep(ms) { return new Promise((resolve) => setTimeout(resolve, ms)); } } exports.AxiosHttpClient = AxiosHttpClient; //# sourceMappingURL=AxiosHttpClient.js.map