@capriza/http-utils
Advanced tools
Comparing version 0.2.15 to 0.2.16-dev.0
var axios = require('axios'); | ||
var BaseUtils = require("./baseUtils"); | ||
var Queue = require("./rateLimitQueue"); | ||
@@ -11,5 +10,4 @@ const CancelToken = axios.CancelToken; | ||
module.exports = class HttpUtils extends BaseUtils { | ||
module.exports = class HttpUtils { | ||
constructor(options = {}){ | ||
super(options); | ||
this.baseURL = options.baseURL || options.baseUrl; | ||
@@ -24,2 +22,4 @@ this.retryInterval = (!isNaN(options.retryInterval) && options.retryInterval) || 5000; | ||
this.requestQueue = new Queue(options.limit, options.interval, options.maxConcurrent); | ||
this.loggingLevel = options.loggingLevel || "debug"; | ||
this.logger = this._getValidLogger(options.logger); | ||
this.http = axios.create(Object.assign(options.requestConfig || {}, { | ||
@@ -63,3 +63,3 @@ baseURL: this.baseURL, | ||
retriesCount = retriesCount === undefined ? this.maxRetries : retriesCount; | ||
const requestLog = logger || this.logger; | ||
const requestLog = this._getValidLogger(logger); | ||
return new Promise((resolve, reject) => { | ||
@@ -89,3 +89,3 @@ try { | ||
var timeout = setTimeout(() => { | ||
requestLog.info("request time exceeded"); | ||
requestLog[this.loggingLevel]("request time exceeded"); | ||
try { | ||
@@ -132,5 +132,4 @@ source.cancel('request was canceled due to time out'); | ||
} | ||
requestLog[this.loggingLevel](`[HttpUtils] PRIORITY[${priority ? priority : 0}] HTTP ${method} request: ${cleanURL}`); | ||
requestLog.debug(`[HttpUtils] PRIORITY[${priority ? priority : 0}] HTTP ${method} request: ${cleanURL}`); | ||
this.requestQueue.add(doRequest, {priority}).then((response) => { | ||
@@ -167,2 +166,10 @@ if(responseTypes.includes(responseType)) { | ||
} | ||
_getValidLogger(logger) { | ||
if(!logger || typeof logger[this.loggingLevel] !== "function" || typeof logger.error !== "function") { | ||
return this.logger || console; | ||
} | ||
return logger; | ||
} | ||
}; |
{ | ||
"name": "@capriza/http-utils", | ||
"version": "0.2.15", | ||
"version": "0.2.16-dev.0", | ||
"description": "HTTP Request utils that handles, request-response, errors, concurrency, priority and authentication", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "./node_modules/.bin/mocha --timeout 10000 --exit --reporter spec" | ||
"test": "./node_modules/.bin/mocha --timeout 10000 --exit --reporter spec", | ||
"test-coverageAndReport": "npm run test", | ||
"build": "node scripts/build.js" | ||
}, | ||
@@ -9,0 +11,0 @@ "repository": { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Shell access
Supply chain riskThis module accesses the system shell. Accessing the system shell increases the risk of executing arbitrary code.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
43476
30
14
621
3
3