diff --git a/.github/workflows/bump-version.yml b/.github/workflows/bump-version.yml new file mode 100644 index 0000000..aa844b9 --- /dev/null +++ b/.github/workflows/bump-version.yml @@ -0,0 +1,53 @@ +on: + push: + branches: + - master + +name: Bump Version + +# Avoid race conditions with tags release +concurrency: nodejs-coralogix-sdk + +jobs: + # CI is performed by ArgoCD + push-tag: + name: Push new tag + runs-on: ubuntu-latest + steps: + - name: Generate token + id: generate-token + uses: tibdex/github-app-token@v1 + with: + github_api_url: https://api.github.com + app_id: ${{ secrets.AUTOMATION_APP_ID }} + private_key: ${{ secrets.AUTOMATION_PRIVATE_KEY }} + - name: Checkout sources + uses: actions/checkout@v2 + with: + # Required so the tags can be detected + fetch-depth: 0 + github_token: ${{ steps.generate-token.outputs.token }} + - name: Configure committer + run: | + git config --local user.email "121110262+coralogix-automation[bot]@users.noreply.github.com" + git config --local user.name "coralogix-automation[bot]" + git remote set-url origin https://coralogix-automation:${{ steps.generate-token.outputs.token }}@github.com/coralogix/nodejs-coralogix-sdk + - name: Bump version + env: + GITHUB_TOKEN: ${{ steps.generate-token.outputs.token }} + run: | + npm install -g standard-version + git checkout -b chore/${{ github.run_number }} + standard-version --skip.tag + npm run update-version + git add . + git commit -m "Created SDK version file" + git push --follow-tags origin chore/${{ github.run_number }} + gh pr create --base master --head chore/${{ github.run_number }} --fill + gh api -XPOST /repos/coralogix/nodejs-coralogix-sdk/statuses/$(git rev-parse HEAD) -f state=success -f context="ticket-id-validator" + gh api -XPOST /repos/coralogix/nodejs-coralogix-sdk/statuses/$(git rev-parse HEAD) -f state=success -f context="All Status Checks" + gh pr merge --delete-branch --admin --squash chore/${{ github.run_number }} + git checkout master + git pull + git tag v$(npm pkg get version | sed 's/"//g') + git push --tags diff --git a/.github/workflows/npm-publish.yml b/.github/workflows/npm-publish.yml new file mode 100644 index 0000000..5483b89 --- /dev/null +++ b/.github/workflows/npm-publish.yml @@ -0,0 +1,47 @@ +name: Node.js Package + +on: + release: + types: [created] +#change to this when you need to publish on pr level +#on: +# push: +# branches: +# - your-branch-name + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-node@v3 + with: + node-version: 18 + - uses: webfactory/ssh-agent@v0.8.0 + with: + ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }} + - name: Install dependencies + run: npm install + - name: Build + run: npm run build + publish-npm: + needs: build + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-node@v3 + with: + node-version: 18 + registry-url: https://registry.npmjs.org/ + - uses: webfactory/ssh-agent@v0.8.0 + with: + ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }} + - name: Install dependencies + run: npm install + - name: Build + run: npm run build + - name: Publish to npm + working-directory: dist/libs/browser + run: npm publish --access public + env: + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} diff --git a/.github/workflows/npm-test.yml b/.github/workflows/npm-test.yml new file mode 100644 index 0000000..c89ad55 --- /dev/null +++ b/.github/workflows/npm-test.yml @@ -0,0 +1,25 @@ +name: Node.js Test + +#change to this when you need to publish on pr level +on: + pull_request: + paths: + - '**.js' + - '**.ts' + - .github/workflows/npm-test.yml + +jobs: + test: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-node@v3 + with: + node-version: 20 + #- uses: webfactory/ssh-agent@v0.8.0 + # with: + # ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }} + - name: Install dependencies + run: npm install + - name: Run tests + run: npm run test diff --git a/dist/constants.d.ts b/dist/constants.d.ts index 30fe27b..bb30af0 100644 --- a/dist/constants.d.ts +++ b/dist/constants.d.ts @@ -76,7 +76,7 @@ export declare class Constants { * @description Coralogix logs API endpoint (production) * @static * @public - * @default https://api.coralogix.com:443/api/v1/logs + * @default https://ingress.coralogix.com:443/api/v1/logs */ static PROD_URL: string; /** diff --git a/dist/constants.js b/dist/constants.js index bd098ad..54583b4 100644 --- a/dist/constants.js +++ b/dist/constants.js @@ -1,3 +1,4 @@ +"use strict"; /** * Coralogix constants * @@ -10,194 +11,195 @@ * @version 1.0.0 * @since 1.0.0 */ -"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.Constants = void 0; /** * @class Constants * @classdesc Class Constants representing default values for Coralogix logger * @description Create new instance of configuration container class */ -var Constants = (function () { +var Constants = /** @class */ (function () { function Constants() { } + /** + * @member {string} SDK_VERSION + * @memberOf Constants + * @description Current SDK version + * @static + * @public + * @default 2.0.0 + */ + Constants.SDK_VERSION = "2.0.0"; + /** + * @member {number} MAX_LOG_BUFFER_SIZE + * @memberOf Constants + * @description Maximum log buffer size + * @static + * @public + * @default 12MiB + */ + Constants.MAX_LOG_BUFFER_SIZE = process.env.CORALOGIX_BUFFER_SIZE ? parseInt(process.env.CORALOGIX_BUFFER_SIZE) : 12582912; + /** + * @member {number} MAX_LOG_CHUNK_SIZE + * @memberOf Constants + * @description Maximum chunk size + * @static + * @public + * @default 1.5MiB + */ + Constants.MAX_LOG_CHUNK_SIZE = 1572864; // 1.5mb + /** + * @member {number} NORMAL_SEND_SPEED_INTERVAL + * @memberOf Constants + * @description Entities bulk send interval in normal mode + * @static + * @public + * @default 500 + */ + Constants.NORMAL_SEND_SPEED_INTERVAL = 500; + /** + * @member {number} FAST_SEND_SPEED_INTERVAL + * @memberOf Constants + * @description Entities bulk send interval in fast mode + * @static + * @public + * @default 100 + */ + Constants.FAST_SEND_SPEED_INTERVAL = 100; + /** + * @member {string} TEST_URL + * @memberOf Constants + * @description Coralogix logs API endpoint (test) + * @static + * @public + * @default https://test.coralogix.com:443/api/v1/logs + */ + Constants.TEST_URL = "https://test.coralogix.com:443/api/v1/logs"; + /** + * @member {string} PROD_URL + * @memberOf Constants + * @description Coralogix logs API endpoint (production) + * @static + * @public + * @default https://ingress.coralogix.com:443/api/v1/logs + */ + Constants.PROD_URL = "https://ingress.coralogix.com:443/api/v1/logs"; + /** + * @member {string} CORALOGIX_LOG_URL + * @memberOf Constants + * @description Coralogix logs API used endpoint + * @static + * @public + */ + Constants.CORALOGIX_LOG_URL = process.env.CORALOGIX_URL || Constants.PROD_URL; + /** + * @member {string} CORALOGIX_TIME_DELTA_URL + * @memberOf Constants + * @description Coralogix timedelta service endpoint + * @static + * @public + * @default https://test.coralogix.com:443/sdk/v1/time + */ + Constants.CORALOGIX_TIME_DELTA_URL = "https://test.coralogix.com:443/sdk/v1/time"; + /** + * @member {string} FAILED_PRIVATE_KEY + * @memberOf Constants + * @description Default private key for Coralogix account + * @static + * @public + * @default 9626c7dd-8174-5015-a3fe-5572e042b6d9 + */ + Constants.FAILED_PRIVATE_KEY = "9626c7dd-8174-5015-a3fe-5572e042b6d9"; + /** + * @member {string} NO_APP_NAME + * @memberOf Constants + * @description Default application name + * @static + * @public + * @default NO_APP_NAME + */ + Constants.NO_APP_NAME = "NO_APP_NAME"; + /** + * @member {string} NO_SUB_SYSTEM + * @memberOf Constants + * @description Default subsystem name + * @static + * @public + * @default NO_SUB_SYSTEM + */ + Constants.NO_SUB_SYSTEM = "NO_SUB_NAME"; + /** + * @member {string} LOG_FILE_NAME + * @memberOf Constants + * @description Default log file name + * @static + * @public + * @default coralogix.sdk.log + */ + Constants.LOG_FILE_NAME = "coralogix.sdk.log"; + /** + * @member {number} HTTP_TIMEOUT + * @memberOf Constants + * @description Default HTTP timeout + * @static + * @public + * @default 30000ms + */ + Constants.HTTP_TIMEOUT = 30000; + /** + * @member {number} HTTP_SEND_RETRY_COUNT + * @memberOf Constants + * @description Number of attempts to retry http post + * @static + * @public + * @default 5 + */ + Constants.HTTP_SEND_RETRY_COUNT = 5; + /** + * @member {number} HTTP_SEND_RETRY_INTERVAL + * @memberOf Constants + * @description Interval between failed http post requests + * @static + * @public + * @default 2000ms + */ + Constants.HTTP_SEND_RETRY_INTERVAL = 2000; + /** + * @member {string} CORALOGIX_CATEGORY + * @memberOf Constants + * @description Coralogix log record category + * @static + * @public + * @default CORALOGIX + */ + Constants.CORALOGIX_CATEGORY = "CORALOGIX"; + /** + * @member {number} SYNC_TIME_UPDATE_INTERVAL + * @memberOf Constants + * @description Synchronization time update interval + * @static + * @public + * @default 300000 + */ + Constants.SYNC_TIME_UPDATE_INTERVAL = 5 * 60 * 1000; + /** + * @member {string} EMPTY_TEXT + * @memberOf Constants + * @description Default log record text + * @static + * @public + * @default EMPTY_TEXT + */ + Constants.EMPTY_TEXT = "EMPTY_TEXT"; + /** + * @member {string} EMPTY_CATEGORY + * @memberOf Constants + * @description Default log record category + * @static + * @public + * @default NO_CATEGORY + */ + Constants.EMPTY_CATEGORY = "NO_CATEGORY"; return Constants; }()); -/** - * @member {string} SDK_VERSION - * @memberOf Constants - * @description Current SDK version - * @static - * @public - * @default 2.0.0 - */ -Constants.SDK_VERSION = "2.0.0"; -/** - * @member {number} MAX_LOG_BUFFER_SIZE - * @memberOf Constants - * @description Maximum log buffer size - * @static - * @public - * @default 12MiB - */ -Constants.MAX_LOG_BUFFER_SIZE = process.env.CORALOGIX_BUFFER_SIZE ? parseInt(process.env.CORALOGIX_BUFFER_SIZE) : 12582912; -/** - * @member {number} MAX_LOG_CHUNK_SIZE - * @memberOf Constants - * @description Maximum chunk size - * @static - * @public - * @default 1.5MiB - */ -Constants.MAX_LOG_CHUNK_SIZE = 1572864; // 1.5mb -/** - * @member {number} NORMAL_SEND_SPEED_INTERVAL - * @memberOf Constants - * @description Entities bulk send interval in normal mode - * @static - * @public - * @default 500 - */ -Constants.NORMAL_SEND_SPEED_INTERVAL = 500; -/** - * @member {number} FAST_SEND_SPEED_INTERVAL - * @memberOf Constants - * @description Entities bulk send interval in fast mode - * @static - * @public - * @default 100 - */ -Constants.FAST_SEND_SPEED_INTERVAL = 100; -/** - * @member {string} TEST_URL - * @memberOf Constants - * @description Coralogix logs API endpoint (test) - * @static - * @public - * @default https://test.coralogix.com:443/api/v1/logs - */ -Constants.TEST_URL = "https://test.coralogix.com:443/api/v1/logs"; -/** - * @member {string} PROD_URL - * @memberOf Constants - * @description Coralogix logs API endpoint (production) - * @static - * @public - * @default https://api.coralogix.com:443/api/v1/logs - */ -Constants.PROD_URL = "https://api.coralogix.com:443/api/v1/logs"; -/** - * @member {string} CORALOGIX_LOG_URL - * @memberOf Constants - * @description Coralogix logs API used endpoint - * @static - * @public - */ -Constants.CORALOGIX_LOG_URL = process.env.CORALOGIX_URL || Constants.PROD_URL; -/** - * @member {string} CORALOGIX_TIME_DELTA_URL - * @memberOf Constants - * @description Coralogix timedelta service endpoint - * @static - * @public - * @default https://test.coralogix.com:443/sdk/v1/time - */ -Constants.CORALOGIX_TIME_DELTA_URL = "https://test.coralogix.com:443/sdk/v1/time"; -/** - * @member {string} FAILED_PRIVATE_KEY - * @memberOf Constants - * @description Default private key for Coralogix account - * @static - * @public - * @default 9626c7dd-8174-5015-a3fe-5572e042b6d9 - */ -Constants.FAILED_PRIVATE_KEY = "9626c7dd-8174-5015-a3fe-5572e042b6d9"; -/** - * @member {string} NO_APP_NAME - * @memberOf Constants - * @description Default application name - * @static - * @public - * @default NO_APP_NAME - */ -Constants.NO_APP_NAME = "NO_APP_NAME"; -/** - * @member {string} NO_SUB_SYSTEM - * @memberOf Constants - * @description Default subsystem name - * @static - * @public - * @default NO_SUB_SYSTEM - */ -Constants.NO_SUB_SYSTEM = "NO_SUB_NAME"; -/** - * @member {string} LOG_FILE_NAME - * @memberOf Constants - * @description Default log file name - * @static - * @public - * @default coralogix.sdk.log - */ -Constants.LOG_FILE_NAME = "coralogix.sdk.log"; -/** - * @member {number} HTTP_TIMEOUT - * @memberOf Constants - * @description Default HTTP timeout - * @static - * @public - * @default 30000ms - */ -Constants.HTTP_TIMEOUT = 30000; -/** - * @member {number} HTTP_SEND_RETRY_COUNT - * @memberOf Constants - * @description Number of attempts to retry http post - * @static - * @public - * @default 5 - */ -Constants.HTTP_SEND_RETRY_COUNT = 5; -/** - * @member {number} HTTP_SEND_RETRY_INTERVAL - * @memberOf Constants - * @description Interval between failed http post requests - * @static - * @public - * @default 2000ms - */ -Constants.HTTP_SEND_RETRY_INTERVAL = 2000; -/** - * @member {string} CORALOGIX_CATEGORY - * @memberOf Constants - * @description Coralogix log record category - * @static - * @public - * @default CORALOGIX - */ -Constants.CORALOGIX_CATEGORY = "CORALOGIX"; -/** - * @member {number} SYNC_TIME_UPDATE_INTERVAL - * @memberOf Constants - * @description Synchronization time update interval - * @static - * @public - * @default 300000 - */ -Constants.SYNC_TIME_UPDATE_INTERVAL = 5 * 60 * 1000; -/** - * @member {string} EMPTY_TEXT - * @memberOf Constants - * @description Default log record text - * @static - * @public - * @default EMPTY_TEXT - */ -Constants.EMPTY_TEXT = "EMPTY_TEXT"; -/** - * @member {string} EMPTY_CATEGORY - * @memberOf Constants - * @description Default log record category - * @static - * @public - * @default NO_CATEGORY - */ -Constants.EMPTY_CATEGORY = "NO_CATEGORY"; exports.Constants = Constants; diff --git a/dist/debug.logger.js b/dist/debug.logger.js index f68002b..ae5b484 100644 --- a/dist/debug.logger.js +++ b/dist/debug.logger.js @@ -1,3 +1,4 @@ +"use strict"; /** * Internal debug logger * @@ -10,13 +11,14 @@ * @version 1.0.0 * @since 1.0.0 */ -"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.DebugLogger = void 0; /** * @class DebugLogger * @classdesc Class DebugLogger representing internal logger * @description Create new instance of internal debugger interface */ -var DebugLogger = (function () { +var DebugLogger = /** @class */ (function () { function DebugLogger() { } /** @@ -43,15 +45,15 @@ var DebugLogger = (function () { } return false; }; + /** + * @member {boolean} isDebug + * @memberOf DebugLogger + * @description Debug mode status + * @default false + * @static + * @public + */ + DebugLogger.isDebug = false; return DebugLogger; }()); -/** - * @member {boolean} isDebug - * @memberOf DebugLogger - * @description Debug mode status - * @default false - * @static - * @public - */ -DebugLogger.isDebug = false; exports.DebugLogger = DebugLogger; diff --git a/dist/entities/LoggerConfig.d.ts b/dist/entities/LoggerConfig.d.ts index 2a6b86b..210bb35 100644 --- a/dist/entities/LoggerConfig.d.ts +++ b/dist/entities/LoggerConfig.d.ts @@ -1,3 +1,16 @@ +/** + * Logger configuration object + * + * @file This file contains logger configuration object description + * @author Yoni Farin + * @author Eldar Aliiev + * @link https://coralogix.com/ + * @copyright Coralogix Ltd. + * @licence Apache-2.0 + * @version 1.0.0 + * @since 1.0.0 + */ +import { AxiosProxyConfig } from "axios"; /** * @class LoggerConfig * @classdesc Class LoggerConfig representing logger configuration container @@ -46,13 +59,14 @@ export declare class LoggerConfig { */ debug: boolean; /** - * @member {string|undefined} proxyUri + * @member {AxiosProxyConfig|undefined} proxyUri * @memberOf LoggerConfig * @description Proxy uri * @default undefined * @public */ - proxyUri?: string; + proxyUri?: AxiosProxyConfig; + private getAxioProxyConfig; /** * @description Initialize new instance of logger configuration container class * @param {object} [config] - Logger configuration parameters diff --git a/dist/entities/LoggerConfig.js b/dist/entities/LoggerConfig.js index 27a9cbb..2747012 100644 --- a/dist/entities/LoggerConfig.js +++ b/dist/entities/LoggerConfig.js @@ -1,3 +1,4 @@ +"use strict"; /** * Logger configuration object * @@ -10,7 +11,8 @@ * @version 1.0.0 * @since 1.0.0 */ -"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.LoggerConfig = void 0; var constants_1 = require("../constants"); var ip_helper_1 = require("../helpers/ip.helper"); /** @@ -19,7 +21,7 @@ var ip_helper_1 = require("../helpers/ip.helper"); * @description Create new instance of logger configuration container class * @param {object} [config] - Logger configuration parameters */ -var LoggerConfig = (function () { +var LoggerConfig = /** @class */ (function () { /** * @description Initialize new instance of logger configuration container class * @param {object} [config] - Logger configuration parameters @@ -70,8 +72,21 @@ var LoggerConfig = (function () { this.subsystemName = config.subsystemName || this.subsystemName; this.computerName = config.computerName || this.computerName; this.debug = config.debug; - this.proxyUri = config.proxyUri; + this.proxyUri = this.getAxioProxyConfig(config.proxyUri); } + LoggerConfig.prototype.getAxioProxyConfig = function (proxyUri) { + if (proxyUri) { + var proxyURL = new URL(proxyUri); + var axioAuth = proxyURL.username ? ({ username: proxyURL.username, password: proxyURL.password }) : null; + var proxyConfig = { + host: proxyURL.hostname, + port: Number.parseInt(proxyURL.port), + auth: axioAuth, + protocol: proxyURL.protocol.slice(0, -1) + }; + return proxyConfig; + } + }; return LoggerConfig; }()); exports.LoggerConfig = LoggerConfig; diff --git a/dist/entities/buffer.action.js b/dist/entities/buffer.action.js index 9f8c2fc..81b3211 100644 --- a/dist/entities/buffer.action.js +++ b/dist/entities/buffer.action.js @@ -1,3 +1,4 @@ +"use strict"; /** * Buffer Action instance * @@ -10,7 +11,8 @@ * @version 1.0.0 * @since 1.0.0 */ -"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.BufferAction = void 0; /** * @class BufferAction * @classdesc Class BufferAction representing buffer action container @@ -18,7 +20,7 @@ * @param {string} type - Type of action * @param {Log} payload - Action payload data */ -var BufferAction = (function () { +var BufferAction = /** @class */ (function () { /** * @description Initialize new instance of buffer action container class * @param {string} type - Type of action diff --git a/dist/entities/bulk.d.ts b/dist/entities/bulk.d.ts index 1105480..34369b4 100644 --- a/dist/entities/bulk.d.ts +++ b/dist/entities/bulk.d.ts @@ -1,3 +1,15 @@ +/** + * Log records bulk + * + * @file This file contains log records bulk container + * @author Yoni Farin + * @author Eldar Aliiev + * @link https://coralogix.com/ + * @copyright Coralogix Ltd. + * @licence Apache-2.0 + * @version 1.0.0 + * @since 1.0.0 + */ import { Log } from "./log"; import { LoggerConfig } from "./LoggerConfig"; /** diff --git a/dist/entities/bulk.js b/dist/entities/bulk.js index b3c9506..e3cf972 100644 --- a/dist/entities/bulk.js +++ b/dist/entities/bulk.js @@ -1,3 +1,4 @@ +"use strict"; /** * Log records bulk * @@ -10,7 +11,8 @@ * @version 1.0.0 * @since 1.0.0 */ -"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.Bulk = void 0; var constants_1 = require("../constants"); var ip_helper_1 = require("../helpers/ip.helper"); /** @@ -18,7 +20,7 @@ var ip_helper_1 = require("../helpers/ip.helper"); * @classdesc Class Bulk representing logs bulk container * @description Create new instance of logs bulk container class */ -var Bulk = (function () { +var Bulk = /** @class */ (function () { function Bulk() { /** * @member {string} applicationName diff --git a/dist/entities/log.d.ts b/dist/entities/log.d.ts index 5b0a124..09e3f01 100644 --- a/dist/entities/log.d.ts +++ b/dist/entities/log.d.ts @@ -1,3 +1,15 @@ +/** + * Log record instance + * + * @file This file contains log record object description + * @author Yoni Farin + * @author Eldar Aliiev + * @link https://coralogix.com/ + * @copyright Coralogix Ltd. + * @licence Apache-2.0 + * @version 1.0.0 + * @since 1.0.0 + */ /** * @class Log * @classdesc Class Log representing log record container @@ -80,5 +92,5 @@ export declare enum Severity { info = 3, warning = 4, error = 5, - critical = 6, + critical = 6 } diff --git a/dist/entities/log.js b/dist/entities/log.js index 94b41a2..e01812e 100644 --- a/dist/entities/log.js +++ b/dist/entities/log.js @@ -1,3 +1,4 @@ +"use strict"; /** * Log record instance * @@ -10,7 +11,8 @@ * @version 1.0.0 * @since 1.0.0 */ -"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.Severity = exports.Log = void 0; var constants_1 = require("../constants"); var stringify = require("json-stringify-safe"); /** @@ -19,7 +21,7 @@ var stringify = require("json-stringify-safe"); * @description Create new instance of log record container class * @param {object} [data] - Log record data */ -var Log = (function () { +var Log = /** @class */ (function () { /** * @description Initialize new instance of log record container class * @param {object} [data] - Log record data @@ -78,4 +80,4 @@ var Severity; Severity[Severity["warning"] = 4] = "warning"; Severity[Severity["error"] = 5] = "error"; Severity[Severity["critical"] = 6] = "critical"; -})(Severity = exports.Severity || (exports.Severity = {})); +})(Severity || (exports.Severity = Severity = {})); diff --git a/dist/entities/logs.buffer.d.ts b/dist/entities/logs.buffer.d.ts index 1402952..68fd977 100644 --- a/dist/entities/logs.buffer.d.ts +++ b/dist/entities/logs.buffer.d.ts @@ -25,7 +25,7 @@ export declare class LogsBuffer { * @public * @returns {number} Size of logs collection */ - readonly size: number; + get size(): number; /** * @member {Array} logs * @memberOf LoggerConfig diff --git a/dist/entities/logs.buffer.js b/dist/entities/logs.buffer.js index ba7f347..8a15982 100644 --- a/dist/entities/logs.buffer.js +++ b/dist/entities/logs.buffer.js @@ -1,3 +1,4 @@ +"use strict"; /** * Logger configuration object * @@ -10,7 +11,8 @@ * @version 1.0.0 * @since 1.0.0 */ -"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.LogsBuffer = void 0; /** * @name sizeof * @constant {function} @@ -23,7 +25,7 @@ var sizeof = require("object-sizeof"); * @description Create new instance of logs buffer class * @param {Array} [logs] - Logs collection */ -var LogsBuffer = (function () { +var LogsBuffer = /** @class */ (function () { /** * @description Create new instance of logs buffer class * @param {Array} [logs] - Logs collection @@ -42,7 +44,7 @@ var LogsBuffer = (function () { get: function () { return sizeof(this.logs); }, - enumerable: true, + enumerable: false, configurable: true }); return LogsBuffer; diff --git a/dist/helpers/ip.helper.d.ts b/dist/helpers/ip.helper.d.ts index c5e1deb..67160f8 100644 --- a/dist/helpers/ip.helper.d.ts +++ b/dist/helpers/ip.helper.d.ts @@ -1,3 +1,15 @@ +/** + * IP-address helper functions + * + * @file This file contains helper functions for work with IP + * @author Yoni Farin + * @author Eldar Aliiev + * @link https://coralogix.com/ + * @copyright Coralogix Ltd. + * @licence Apache-2.0 + * @version 1.0.0 + * @since 1.0.0 + */ /** * @namespace IPHelper * @description IP-address helper methods namespace diff --git a/dist/helpers/ip.helper.js b/dist/helpers/ip.helper.js index 84797b2..2d22c14 100644 --- a/dist/helpers/ip.helper.js +++ b/dist/helpers/ip.helper.js @@ -1,3 +1,4 @@ +"use strict"; /** * IP-address helper functions * @@ -10,7 +11,8 @@ * @version 1.0.0 * @since 1.0.0 */ -"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.IPHelper = void 0; var os = require("os"); var debug_logger_1 = require("../debug.logger"); var hostname; @@ -62,4 +64,4 @@ var IPHelper; return hostname; } IPHelper.getComputerName = getComputerName; -})(IPHelper = exports.IPHelper || (exports.IPHelper = {})); +})(IPHelper || (exports.IPHelper = IPHelper = {})); diff --git a/dist/helpers/rx.helper.d.ts b/dist/helpers/rx.helper.d.ts index d85e022..2cc1110 100644 --- a/dist/helpers/rx.helper.d.ts +++ b/dist/helpers/rx.helper.d.ts @@ -10,7 +10,7 @@ * @version 1.0.0 * @since 1.0.0 */ -import { Observable } from "rxjs"; +import { Observable } from "rxjs-compat"; /** * @namespace rxHelper * @description Helper methods for RxJS @@ -24,7 +24,7 @@ export declare namespace rxHelper { * @param pauser - Pauser * @returns {Observable} Observable pauser object */ - function makePausable(source: any, pauser: any): Observable<{}>; + function makePausable(source: any, pauser: any): Observable; /** * @function makeReset * @description Make observable restarter object @@ -33,5 +33,5 @@ export declare namespace rxHelper { * @param restarter - Restarter * @returns {Observable} Observable restarter object */ - function makeReset(source: any, restarter: any): Observable<{}>; + function makeReset(source: any, restarter: any): Observable; } diff --git a/dist/helpers/rx.helper.js b/dist/helpers/rx.helper.js index 7364485..6058605 100644 --- a/dist/helpers/rx.helper.js +++ b/dist/helpers/rx.helper.js @@ -1,3 +1,4 @@ +"use strict"; /** * rxHelper functions * @@ -10,8 +11,9 @@ * @version 1.0.0 * @since 1.0.0 */ -"use strict"; -var rxjs_1 = require("rxjs"); +Object.defineProperty(exports, "__esModule", { value: true }); +exports.rxHelper = void 0; +var rxjs_compat_1 = require("rxjs-compat"); /** * @namespace rxHelper * @description Helper methods for RxJS @@ -27,9 +29,9 @@ var rxHelper; * @returns {Observable} Observable pauser object */ function makePausable(source, pauser) { - return rxjs_1.Observable.from(pauser) + return rxjs_compat_1.Observable.from(pauser) .startWith(false) - .switchMap(function (pause) { return pause ? rxjs_1.Observable.never() : source; }); + .switchMap(function (pause) { return pause ? rxjs_compat_1.Observable.never() : source; }); } rxHelper.makePausable = makePausable; /** @@ -41,9 +43,9 @@ var rxHelper; * @returns {Observable} Observable restarter object */ function makeReset(source, restarter) { - return rxjs_1.Observable.from(restarter) + return rxjs_compat_1.Observable.from(restarter) .startWith(true) .switchMapTo(source); } rxHelper.makeReset = makeReset; -})(rxHelper = exports.rxHelper || (exports.rxHelper = {})); +})(rxHelper || (exports.rxHelper = rxHelper = {})); diff --git a/dist/http.service.d.ts b/dist/http.service.d.ts index df8fa19..24dd33d 100644 --- a/dist/http.service.d.ts +++ b/dist/http.service.d.ts @@ -1,3 +1,15 @@ +/** + * HTTP helping methods + * + * @file This file contains implementation of helper methods for HTTP + * @author Yoni Farin + * @author Eldar Aliiev + * @link https://coralogix.com/ + * @copyright Coralogix Ltd. + * @licence Apache-2.0 + * @version 1.0.0 + * @since 1.0.0 + */ import { Observable } from "rxjs"; import { LoggerConfig } from "./entities/LoggerConfig"; /** diff --git a/dist/http.service.js b/dist/http.service.js index 951de4a..01b2ad7 100644 --- a/dist/http.service.js +++ b/dist/http.service.js @@ -1,3 +1,4 @@ +"use strict"; /** * HTTP helping methods * @@ -10,8 +11,9 @@ * @version 1.0.0 * @since 1.0.0 */ -"use strict"; -var request = require("request"); +Object.defineProperty(exports, "__esModule", { value: true }); +exports.HttpHelper = void 0; +var axios_1 = require("axios"); var rxjs_1 = require("rxjs"); var constants_1 = require("./constants"); /** @@ -30,29 +32,24 @@ var HttpHelper; */ function sendBulk(jsonData, config) { var options = { - body: jsonData, - gzip: true, - json: true, - method: "POST", + decompress: true, timeout: constants_1.Constants.HTTP_TIMEOUT, - url: constants_1.Constants.CORALOGIX_LOG_URL, }; if (config.proxyUri) { options.proxy = config.proxyUri; } return rxjs_1.Observable.create(function (observer) { - request(options, function (error, response, body) { - if (error || response.statusCode < 200 || response.statusCode > 299) { - if (!error) { - error = { code: response.statusCode }; - } - observer.error(error); + axios_1.default.post(constants_1.Constants.CORALOGIX_LOG_URL, jsonData, options) + .then(function (response) { + if (response.status < 200 || response.status > 299) { + observer.error({ code: response.status }); } else { - observer.next(new HTTPResponse(response, body)); + observer.next(new HTTPResponse(response, response.data.json)); } - observer.complete(); - }); + }).catch(function (error) { + observer.error(error); + }).finally(function () { return observer.complete(); }); }); } HttpHelper.sendBulk = sendBulk; @@ -64,7 +61,7 @@ var HttpHelper; * @param {any} response - Response data * @param {any} body - Response body */ - var HTTPResponse = (function () { + var HTTPResponse = /** @class */ (function () { /** * @description Initialize new instance of HTTPResponse object * @param {any} response - Response data @@ -77,4 +74,4 @@ var HttpHelper; return HTTPResponse; }()); HttpHelper.HTTPResponse = HTTPResponse; -})(HttpHelper = exports.HttpHelper || (exports.HttpHelper = {})); +})(HttpHelper || (exports.HttpHelper = HttpHelper = {})); diff --git a/dist/index.d.ts b/dist/index.d.ts index 25f81f5..49560d6 100644 --- a/dist/index.d.ts +++ b/dist/index.d.ts @@ -1,3 +1,15 @@ +/** + * Main package file + * + * @file This file contains all functionality of current package + * @author Yoni Farin + * @author Eldar Aliiev + * @link https://coralogix.com/ + * @copyright Coralogix Ltd. + * @licence Apache-2.0 + * @version 1.0.0 + * @since 1.0.0 + */ import { Log } from "./entities/log"; import { LoggerConfig } from "./entities/LoggerConfig"; /** @@ -49,7 +61,7 @@ export declare class CoralogixLogger { * @static * @private */ - private static sendWelcomeMessage(config); + private static sendWelcomeMessage; /** * @member {string} category * @memberOf CoralogixLogger diff --git a/dist/index.js b/dist/index.js index 656e080..013cc54 100644 --- a/dist/index.js +++ b/dist/index.js @@ -1,3 +1,4 @@ +"use strict"; /** * Main package file * @@ -10,10 +11,22 @@ * @version 1.0.0 * @since 1.0.0 */ -"use strict"; -function __export(m) { - for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p]; -} +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 __exportStar = (this && this.__exportStar) || function(m, exports) { + for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.CoralogixCentralLogger = exports.CoralogixLogger = void 0; var constants_1 = require("./constants"); var debug_logger_1 = require("./debug.logger"); var log_1 = require("./entities/log"); @@ -30,7 +43,7 @@ var pjson = require("../package.json"); * @description Create new instance of external logger * @param {string} category - Coralogix logger category */ -var CoralogixLogger = (function () { +var CoralogixLogger = /** @class */ (function () { /** * @description Initialize new instance of CoralogixLogger object * @param {string} category - Coralogix logger category @@ -114,23 +127,23 @@ var CoralogixLogger = (function () { CoralogixLogger.prototype.waitForFlush = function () { return CoralogixLogger.loggerManager.waitForFlush(); }; + /** + * @member {LoggerManager} loggerManager + * @memberOf CoralogixLogger + * @description Logger manager instance + * @static + * @private + */ + CoralogixLogger.loggerManager = new logger_manager_1.LoggerManager(); return CoralogixLogger; }()); -/** - * @member {LoggerManager} loggerManager - * @memberOf CoralogixLogger - * @description Logger manager instance - * @static - * @private - */ -CoralogixLogger.loggerManager = new logger_manager_1.LoggerManager(); exports.CoralogixLogger = CoralogixLogger; /** * @class CoralogixCentralLogger * @classdesc Class CoralogixCentralLogger representing central external logger to Coralogix service * @description Create new instance of central external logger */ -var CoralogixCentralLogger = (function () { +var CoralogixCentralLogger = /** @class */ (function () { function CoralogixCentralLogger() { /** * @member {Map} loggers @@ -204,7 +217,7 @@ var CoralogixCentralLogger = (function () { return CoralogixCentralLogger; }()); exports.CoralogixCentralLogger = CoralogixCentralLogger; -__export(require("./constants")); -__export(require("./debug.logger")); -__export(require("./entities/log")); -__export(require("./entities/LoggerConfig")); +__exportStar(require("./constants"), exports); +__exportStar(require("./debug.logger"), exports); +__exportStar(require("./entities/log"), exports); +__exportStar(require("./entities/LoggerConfig"), exports); diff --git a/dist/logger.manager.d.ts b/dist/logger.manager.d.ts index 69b0e13..c5f63c0 100644 --- a/dist/logger.manager.d.ts +++ b/dist/logger.manager.d.ts @@ -1,3 +1,15 @@ +/** + * Logger manager file + * + * @file This file contains logging queue manager + * @author Yoni Farin + * @author Eldar Aliiev + * @link https://coralogix.com/ + * @copyright Coralogix Ltd. + * @licence Apache-2.0 + * @version 1.0.0 + * @since 1.0.0 + */ import { Log } from "./entities/log"; import { LoggerConfig } from "./entities/LoggerConfig"; /** @@ -120,7 +132,7 @@ export declare class LoggerManager { * @param {Log[]} buffer - Logs buffer * @private */ - private sendBulk(buffer); + private sendBulk; /** * @method cleanAfterSend * @description On buffer send completed (success of failed) free the buffer size @@ -128,7 +140,7 @@ export declare class LoggerManager { * @param {Log[]} sentBuffer - Logs buffer * @private */ - private cleanAfterSend(sentBuffer); + private cleanAfterSend; /** * @method cleanAfterSend * @description Return an on error observable that will retry @@ -140,5 +152,5 @@ export declare class LoggerManager { * @private * @returns {Observable} Logger manager observable object */ - private retryObservable(errors$); + private retryObservable; } diff --git a/dist/logger.manager.js b/dist/logger.manager.js index fe29569..fec012f 100644 --- a/dist/logger.manager.js +++ b/dist/logger.manager.js @@ -1,3 +1,4 @@ +"use strict"; /** * Logger manager file * @@ -10,7 +11,8 @@ * @version 1.0.0 * @since 1.0.0 */ -"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.LoggerManager = void 0; var rxjs_1 = require("rxjs"); var constants_1 = require("./constants"); var debug_logger_1 = require("./debug.logger"); @@ -30,7 +32,7 @@ var sizeof = require("object-sizeof"); * @classdesc Class LoggerManager representing logging queue manager * @description Create new instance of logging queue manager */ -var LoggerManager = (function () { +var LoggerManager = /** @class */ (function () { /** * @description Initialize new instance of LoggerManager object */ @@ -85,7 +87,7 @@ var LoggerManager = (function () { if (!this.logStreamSubscription) { return Promise.resolve(); // there are no pending logs } - if (!this.flushedPromise) { + if (!this.flushedPromise) { // there are pending logs - wait for them this.flushedPromise = new Promise(function (resolve) { _this.flushPromiseFulfilled = resolve; }); diff --git a/dist/rxOperators/buffer-predicate-or-observable.operator.d.ts b/dist/rxOperators/buffer-predicate-or-observable.operator.d.ts index 1b5def4..3ea19a4 100644 --- a/dist/rxOperators/buffer-predicate-or-observable.operator.d.ts +++ b/dist/rxOperators/buffer-predicate-or-observable.operator.d.ts @@ -105,5 +105,5 @@ export declare class BufferPredicateOrObservable extends OuterSubscriber} predicate - Predicate * @param {Observable} closingNotifier - Notify before closing */ -var BufferPredicateOrObservableOperator = (function () { +var BufferPredicateOrObservableOperator = /** @class */ (function () { /** * @description Initialize new instance of BufferPredicateOrObservableOperator class * @param {BufferPredicate} predicate - Predicate @@ -61,7 +73,7 @@ exports.BufferPredicateOrObservableOperator = BufferPredicateOrObservableOperato * @param {BufferPredicate} predicate - Predicate * @param {Observable} closingNotifier - Notify before closing */ -var BufferPredicateOrObservable = (function (_super) { +var BufferPredicateOrObservable = /** @class */ (function (_super) { __extends(BufferPredicateOrObservable, _super); /** * @description Initialize new instance of BufferPredicateOrObservable class @@ -80,7 +92,7 @@ var BufferPredicateOrObservable = (function (_super) { * @default [] */ _this.buffer = []; - _this.add(subscribeToResult_1.subscribeToResult(_this, closingNotifier)); + _this.add((0, subscribeToResult_1.subscribeToResult)(_this, closingNotifier)); return _this; } /** diff --git a/examples/bunyan-js.examples.js b/examples/bunyan-js.examples.js index d2b745f..0aef886 100644 --- a/examples/bunyan-js.examples.js +++ b/examples/bunyan-js.examples.js @@ -3,7 +3,7 @@ var CoralogixBunyan = require("coralogix-logger-bunyan"); // global configuration for coralogix var config = { - privateKey: "9626c7dd-8174-5015-a3fe-5572e042b6d9", + privateKey: "*************", applicationName: "YOUR APP NAME", subsystemName: "YOUR SUBSYSTEM", }; diff --git a/examples/sdk-js.example.js b/examples/sdk-js.example.js index 66215ae..eec835e 100644 --- a/examples/sdk-js.example.js +++ b/examples/sdk-js.example.js @@ -2,7 +2,7 @@ var Coralogix = require("coralogix-logger"); // global confing const config = new Coralogix.LoggerConfig({ - privateKey:"9626c7dd-8174-5015-a3fe-5572e042b6d9", + privateKey:"*************", }); Coralogix.CoralogixLogger.configure(config); diff --git a/examples/winston-js.example.js b/examples/winston-js.example.js index 08c3d19..5cc8bc0 100644 --- a/examples/winston-js.example.js +++ b/examples/winston-js.example.js @@ -3,7 +3,7 @@ // // global configuration for coralogix // var config = { -// privateKey: "6fb78c92-11af-314f-49d6-b6dbaaab17ba", +// privateKey: "*************", // applicationName: "Yoni TEST", // subsystemName: "YOUR SUBSYSTEM", // }; @@ -32,8 +32,8 @@ const winston = require("winston"); const stackTrace = require("stack-trace"); const CoralogixWinston = require("coralogix-logger-winston"); -// const test_key = "6411e033-3439-d71c-542b-0d45419d6b30"; -// const prod_key = "6fb78c92-11af-314f-49d6-b6dbaaab17ba"; +// const test_key = "*************"; +// const prod_key = "*************"; // const config = { @@ -93,12 +93,12 @@ const CoralogixWinston = require("coralogix-logger-winston"); }; let consoleLoggerConfig = Object.assign({}, baseLoggerConfig); - let loggerTransports = [ + let loggerTransports = [ new (winston.transports.Console)(consoleLoggerConfig) ]; - + let coralogixLoggerConfig = Object.assign({}, baseLoggerConfig, { - privateKey: '6fb78c92-11af-314f-49d6-b6dbaaab17ba', + privateKey: '*************', applicationName: 'aaaaaa', subsystemName: "external-webapp", json: true, @@ -107,7 +107,7 @@ const CoralogixWinston = require("coralogix-logger-winston"); CoralogixWinston.CoralogixTransport.configure(coralogixLoggerConfig); let coralogixLoggerConfigCrap = Object.assign({}, baseLoggerConfig, {category: "CORALOGIX"}); loggerTransports.push(new CoralogixWinston.CoralogixTransport(coralogixLoggerConfigCrap)); - + let logger = new (winston.Logger)({transports: loggerTransports}); diff --git a/external/bunyan/src/tester.ts b/external/bunyan/src/tester.ts index d5a244e..2d320f8 100644 --- a/external/bunyan/src/tester.ts +++ b/external/bunyan/src/tester.ts @@ -1,7 +1,7 @@ import * as bunyan from "bunyan"; import {CoralogixStream} from "./coralogix-bunyan.stream"; -const prod_key = "9626c7dd-8174-5015-a3fe-5572e042b6d9"; +const prod_key = "*************; const config = { privateKey: prod_key, @@ -25,4 +25,4 @@ var logger = bunyan.createLogger({ logger.info('hello world'); -logger.child({category:"CATEGORY",className:"AAA",methodName:"METHOD",threadId:"threadID"}).error(JSON.stringify({a:"AAA"})); \ No newline at end of file +logger.child({category:"CATEGORY",className:"AAA",methodName:"METHOD",threadId:"threadID"}).error(JSON.stringify({a:"AAA"})); diff --git a/external/winston/README.md b/external/winston/README.md index abbc07c..2dd7dff 100644 --- a/external/winston/README.md +++ b/external/winston/README.md @@ -19,7 +19,7 @@ var CoralogixWinston = require("coralogix-logger-winston"); // global configuration for coralogix var config = { - privateKey: "9626c7dd-8174-5015-a3fe-5572e042b6d9", + privateKey: "*************, applicationName: "YOUR APP NAME", subsystemName: "YOUR SUBSYSTEM", }; @@ -35,7 +35,7 @@ winston.configure({ // use winston winston.info("use winston to send your logs to coralogix"); - + ``` @@ -44,7 +44,7 @@ winston.info("use winston to send your logs to coralogix"); import * as winston from "winston"; import {CoralogixTransport} from "coralogix-logger-winston"; -// global configuration for private key, application name, subsystem name +// global configuration for private key, application name, subsystem name const config = { privateKey: "YOUR PRIVATE KEY", applicationName: "YOUR APP NAME", diff --git a/external/winston/src/tester.ts b/external/winston/src/tester.ts index 9409338..a70a992 100644 --- a/external/winston/src/tester.ts +++ b/external/winston/src/tester.ts @@ -1,8 +1,8 @@ const winston = require("winston"); const stackTrace = require("stack-trace"); const CoralogixTransport = require("./coralogix-winston.transport").CoralogixTransport; -const test_key = "6411e033-3439-d71c-542b-0d45419d6b30"; -const prod_key = "6fb78c92-11af-314f-49d6-b6dbaaab17ba"; +const test_key = "*************"; +const prod_key = "*************"; const config = { @@ -75,7 +75,7 @@ winston.info('your message',{category:"ZZZZZ",methodName:"MMMMMMMM",threadId:"II // ]; // // let coralogixLoggerConfig = Object.assign({}, baseLoggerConfig, { -// privateKey: '6fb78c92-11af-314f-49d6-b6dbaaab17ba', +// privateKey: '*************', // applicationName: 'aaaaaa', // subsystemName: "external-webapp", // json: true, diff --git a/package.json b/package.json index fbe375a..3a39457 100644 --- a/package.json +++ b/package.json @@ -60,21 +60,22 @@ "t": "tsc -p src ; node dist/tester.js" }, "devDependencies": { - "@types/node": "6.0.52", - "@types/request": "0.0.36", + "@types/node": "^13.11.1", "chai": "^4.1.2", - "jsdoc": "^3.5.5", - "mocha": "^5.2.0", - "nyc": "^11.8.0", - "tslint": "^5.10.0", - "typescript": "2.1.4" + "jsdoc": "^4.0.2", + "mocha": "^10.2.0", + "nyc": "^15.1.0", + "tslint": "^5.20.1", + "typescript": "^5.3.3" }, "dependencies": { + "axios": "^1.6.3", "form-data": "^2.5.0", "json-stringify-safe": "5.0.1", "object-sizeof": "1.1.1", - "request": "2.88.0", - "rxjs": "5.4.0" + "proxy-from-env": "^1.1.0", + "rxjs": "^6.6.7", + "rxjs-compat": "^6.6.7" }, "directories": { "doc": "docs", diff --git a/src/constants.ts b/src/constants.ts index 8e24fce..ac113cf 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -83,9 +83,9 @@ export class Constants { * @description Coralogix logs API endpoint (production) * @static * @public - * @default https://api.coralogix.com:443/api/v1/logs + * @default https://ingress.coralogix.com:443/api/v1/logs */ - public static PROD_URL: string = "https://api.coralogix.com:443/api/v1/logs"; + public static PROD_URL: string = "https://ingress.coralogix.com:443/api/v1/logs"; /** * @member {string} CORALOGIX_LOG_URL @@ -112,9 +112,9 @@ export class Constants { * @description Default private key for Coralogix account * @static * @public - * @default 9626c7dd-8174-5015-a3fe-5572e042b6d9 + * @default ******** */ - public static FAILED_PRIVATE_KEY: string = "9626c7dd-8174-5015-a3fe-5572e042b6d9"; + public static FAILED_PRIVATE_KEY: string = "*************"; /** * @member {string} NO_APP_NAME diff --git a/src/entities/LoggerConfig.ts b/src/entities/LoggerConfig.ts index 468edf4..15180d8 100644 --- a/src/entities/LoggerConfig.ts +++ b/src/entities/LoggerConfig.ts @@ -11,6 +11,7 @@ * @since 1.0.0 */ +import {AxiosBasicCredentials, AxiosProxyConfig} from "axios"; import {Constants} from "../constants"; import {IPHelper} from "../helpers/ip.helper"; @@ -67,14 +68,27 @@ export class LoggerConfig { public debug: boolean = false; /** - * @member {string|undefined} proxyUri + * @member {AxiosProxyConfig|undefined} proxyUri * @memberOf LoggerConfig * @description Proxy uri * @default undefined * @public */ - public proxyUri?: string; + public proxyUri?: AxiosProxyConfig; + private getAxioProxyConfig(proxyUri?: string): AxiosProxyConfig | undefined { + if (proxyUri) { + const proxyURL = new URL(proxyUri) + const axioAuth: AxiosBasicCredentials = proxyURL.username ? ({username: proxyURL.username, password: proxyURL.password}) : null; + const proxyConfig: AxiosProxyConfig = { + host: proxyURL.hostname, + port: Number.parseInt(proxyURL.port), + auth: axioAuth, + protocol: proxyURL.protocol.slice(0, -1) + } + return proxyConfig + } + } /** * @description Initialize new instance of logger configuration container class * @param {object} [config] - Logger configuration parameters @@ -85,6 +99,6 @@ export class LoggerConfig { this.subsystemName = config.subsystemName || this.subsystemName; this.computerName = config.computerName || this.computerName; this.debug = config.debug; - this.proxyUri = config.proxyUri; + this.proxyUri = this.getAxioProxyConfig(config.proxyUri); } } diff --git a/src/helpers/rx.helper.ts b/src/helpers/rx.helper.ts index 26956bf..5728c0e 100644 --- a/src/helpers/rx.helper.ts +++ b/src/helpers/rx.helper.ts @@ -11,7 +11,7 @@ * @since 1.0.0 */ -import {Observable} from "rxjs"; +import {Observable} from "rxjs-compat"; /** * @namespace rxHelper diff --git a/src/http.service.ts b/src/http.service.ts index 8fa5c66..b942b95 100644 --- a/src/http.service.ts +++ b/src/http.service.ts @@ -11,8 +11,7 @@ * @since 1.0.0 */ -import * as request from "request"; -import {CoreOptions, UrlOptions} from "request"; +import axios, {AxiosRequestConfig} from 'axios'; import {Observable} from "rxjs"; import {Constants} from "./constants"; import {LoggerConfig} from "./entities/LoggerConfig"; @@ -31,30 +30,25 @@ export namespace HttpHelper { * @returns {Observable} Valid HTTP response object */ export function sendBulk(jsonData: any, config: LoggerConfig): Observable { - const options: CoreOptions & UrlOptions = { - body: jsonData, - gzip: true, - json: true, - method: "POST", + const options: AxiosRequestConfig = { + decompress: true, timeout: Constants.HTTP_TIMEOUT, - url: Constants.CORALOGIX_LOG_URL, }; if (config.proxyUri) { options.proxy = config.proxyUri; } return Observable.create(observer => { - request(options, (error, response, body) => { - if (error || response.statusCode < 200 || response.statusCode > 299) { - if (!error) { - error = {code: response.statusCode}; - } - observer.error(error); + axios.post(Constants.CORALOGIX_LOG_URL, jsonData, options) + .then(response => { + if (response.status < 200 || response.status > 299) { + observer.error({code: response.status}) } else { - observer.next(new HTTPResponse(response, body)); + observer.next(new HTTPResponse(response, response.data.json)); } - observer.complete(); - }); + }).catch(error => { + observer.error(error); + }).finally(() => observer.complete()); }); } diff --git a/test/entries/LoggerConfig.js b/test/entries/LoggerConfig.js index 2aec1ea..ba3d0a0 100644 --- a/test/entries/LoggerConfig.js +++ b/test/entries/LoggerConfig.js @@ -8,7 +8,7 @@ var logger_config_entry = require('../../dist/entities/LoggerConfig'); describe('LoggerConfig', function () { describe('#LoggerConfig()', function () { it('should fill logger configuration with user values', function () { - var privateKey = 'ca290f7c-460b-4e50-a64b-460d9b373086'; + var privateKey = '****************'; var applicationName = 'NodeJS test'; var subsystemName = 'Test subsystem'; var computerName = 'Test host'; @@ -45,7 +45,7 @@ describe('LoggerConfig', function () { }); it('should fill logger configuration with default application name', function () { - var privateKey = 'ca290f7c-460b-4e50-a64b-460d9b373086'; + var privateKey = '****************'; var applicationName = null; var subsystemName = 'Test subsystem'; @@ -62,7 +62,7 @@ describe('LoggerConfig', function () { }); it('should fill logger configuration with default subsystem name', function () { - var privateKey = 'ca290f7c-460b-4e50-a64b-460d9b373086'; + var privateKey = '****************'; var applicationName = 'NodeJS test'; var subsystemName = null; @@ -79,7 +79,7 @@ describe('LoggerConfig', function () { }); it('should fill logger configuration with default computer name', function () { - var privateKey = 'ca290f7c-460b-4e50-a64b-460d9b373086'; + var privateKey = '****************'; var applicationName = 'NodeJS test'; var subsystemName = 'Test subsystem'; diff --git a/test/entries/bulk.js b/test/entries/bulk.js index 7915940..c8dba50 100644 --- a/test/entries/bulk.js +++ b/test/entries/bulk.js @@ -18,7 +18,7 @@ describe('Bulk', function () { describe('#bulkFromConfig()', function () { it('should fill bulk with user values', function () { - var privateKey = 'ca290f7c-460b-4e50-a64b-460d9b373086'; + var privateKey = '*************'; var applicationName = 'NodeJS test'; var subsystemName = 'Test subsystem'; var computerName = 'Test host'; @@ -52,7 +52,7 @@ describe('Bulk', function () { }); it('should fill bulk with default application name', function () { - var privateKey = 'ca290f7c-460b-4e50-a64b-460d9b373086'; + var privateKey = '*************'; var subsystemName = 'Test subsystem'; var bulk = bulk_entry.Bulk.bulkFromConfig({ @@ -67,7 +67,7 @@ describe('Bulk', function () { }); it('should fill bulk with default subsystem name', function () { - var privateKey = 'ca290f7c-460b-4e50-a64b-460d9b373086'; + var privateKey = '*************'; var applicationName = 'NodeJS test'; var bulk = bulk_entry.Bulk.bulkFromConfig({ @@ -82,7 +82,7 @@ describe('Bulk', function () { }); it('should fill bulk with default computer name', function () { - var privateKey = 'ca290f7c-460b-4e50-a64b-460d9b373086'; + var privateKey = '*************'; var applicationName = 'NodeJS test'; var subsystemName = 'Test subsystem'; @@ -98,4 +98,4 @@ describe('Bulk', function () { assert.equal(bulk.computerName, ip_helper.IPHelper.getComputerName()); }); }); -}); \ No newline at end of file +}); diff --git a/test_proxy/nginx.conf b/test_proxy/nginx.conf new file mode 100644 index 0000000..3f23cc5 --- /dev/null +++ b/test_proxy/nginx.conf @@ -0,0 +1,119 @@ + +#user nobody; +worker_processes 1; + +#error_log logs/error.log; +#error_log logs/error.log notice; +#error_log logs/error.log info; + +#pid logs/nginx.pid; + + +events { + worker_connections 1024; +} + + +http { + include mime.types; + default_type application/octet-stream; + + #log_format main '$remote_addr - $remote_user [$time_local] "$request" ' + # '$status $body_bytes_sent "$http_referer" ' + # '"$http_user_agent" "$http_x_forwarded_for"'; + + #access_log logs/access.log main; + + sendfile on; + #tcp_nopush on; + + #keepalive_timeout 0; + keepalive_timeout 65; + + #gzip on; + + server { + listen 9999; + server_name localhost; + + #charset koi8-r; + + #access_log logs/host.access.log main; + + location / { + resolver 1.1.1.1; + proxy_http_version 1.1; + + proxy_pass https://$http_host$uri$is_args$args; + } + + #error_page 404 /404.html; + + # redirect server error pages to the static page /50x.html + # + #error_page 500 502 503 504 /50x.html; + #location = /50x.html { + # root html; + #} + + # proxy the PHP scripts to Apache listening on 127.0.0.1:80 + # + #location ~ \.php$ { + # proxy_pass http://127.0.0.1; + #} + + # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 + # + #location ~ \.php$ { + # root html; + # fastcgi_pass 127.0.0.1:9000; + # fastcgi_index index.php; + # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; + # include fastcgi_params; + #} + + # deny access to .htaccess files, if Apache's document root + # concurs with nginx's one + # + #location ~ /\.ht { + # deny all; + #} + } + + + # another virtual host using mix of IP-, name-, and port-based configuration + # + #server { + # listen 8000; + # listen somename:8080; + # server_name somename alias another.alias; + + # location / { + # root html; + # index index.html index.htm; + # } + #} + + + # HTTPS server + # + #server { + # listen 443 ssl; + # server_name localhost; + + # ssl_certificate cert.pem; + # ssl_certificate_key cert.key; + + # ssl_session_cache shared:SSL:1m; + # ssl_session_timeout 5m; + + # ssl_ciphers HIGH:!aNULL:!MD5; + # ssl_prefer_server_ciphers on; + + # location / { + # root html; + # index index.html index.htm; + # } + #} + include servers/*; +} diff --git a/test_proxy/run_with_proxy.js b/test_proxy/run_with_proxy.js new file mode 100644 index 0000000..32991c6 --- /dev/null +++ b/test_proxy/run_with_proxy.js @@ -0,0 +1,25 @@ +var Coralogix = require("./dist"); + +// global confing for application name, private key, subsystem name +const config = new Coralogix.LoggerConfig({ + applicationName: "node tester", + privateKey: "*************", + subsystemName: "node tester sub", + proxyUri: "http://127.0.0.1:9999/", + debug: true +}); + +Coralogix.CoralogixLogger.configure(config); + +// create a new logger with category +const logger = new Coralogix.CoralogixLogger("My Category"); + +// create a log +const log = new Coralogix.Log({ + severity: Coralogix.Severity.info, + className: "className", + methodName: "methodName", + text: "log data", +}) +// send log to coralogix +logger.addLog(log);