eh-api-client
Advanced tools
Comparing version 0.10.0 to 0.12.0
43
index.js
var | ||
request = require("request"), | ||
request = require("requestretry"), | ||
Q = require("q"), | ||
_ = require("lodash"); | ||
_ = require("lodash"), | ||
Agent = require("http").Agent; | ||
@@ -52,2 +53,3 @@ function buildError(res, data, url, method) { | ||
this.apiURL = apiURL; | ||
this._factory = null; | ||
}; | ||
@@ -58,2 +60,3 @@ | ||
var newClient = new Client(apiURL, this._options); | ||
newClient._factory = this._factory; | ||
return newClient; | ||
@@ -167,4 +170,6 @@ }; | ||
Client.prototype._makeRequest = function() { | ||
return request.apply(this, arguments); | ||
Client.prototype._makeRequest = function(params, cb) { | ||
params.agent = this._factory.agent; | ||
_.extend(params, this._factory.retryOptions); | ||
return request(params, cb); | ||
}; | ||
@@ -208,2 +213,11 @@ | ||
this.apiURL = apiURL; | ||
this.retryOptions = { | ||
maxAttempts: 5, | ||
retryDelay: 100, | ||
retryStrategy: request.RetryStrategies.NetworkError | ||
}; | ||
this.agent = new Agent({ | ||
keepAlive: true, | ||
maxSockets: 1000 | ||
}); | ||
}; | ||
@@ -213,2 +227,17 @@ | ||
Factory.prototype.setRetryOptions = function(options) { | ||
var self = this; | ||
var allowOpts = ["maxAttempts", "retryDelay", "retryStrategy"]; | ||
allowOpts.forEach(function(k) { | ||
if(k in options) { | ||
self.retryOptions[k] = options[k]; | ||
} | ||
}); | ||
}; | ||
Factory.prototype.setAgentOptions = function(options) { | ||
_.defaults(options, {keepAlive: true}); | ||
self.agent = new Agent(options); | ||
}; | ||
Factory.prototype.exists = function() { | ||
@@ -224,2 +253,3 @@ var c = new Client(this.apiURL); | ||
var c = new Client(this.apiURL); | ||
c._factory = this; | ||
return c.request.apply(c, args); | ||
@@ -254,2 +284,3 @@ }; | ||
}); | ||
client._factory = self; | ||
cb(null, client); | ||
@@ -264,7 +295,9 @@ }); | ||
Factory.prototype.getClient = function(userId, app) { | ||
return new Client(this.apiURL, { | ||
var client = new Client(this.apiURL, { | ||
internalAuth: userId + ":" + app | ||
}); | ||
client._factory = this; | ||
return client; | ||
}; | ||
module.exports = Factory; |
{ | ||
"name": "eh-api-client", | ||
"version": "0.10.0", | ||
"version": "0.12.0", | ||
"description": "Node.js rest client", | ||
@@ -18,5 +18,6 @@ "main": "index.js", | ||
"q": "^1.4.1", | ||
"request": "^2.55.0" | ||
"requestretry": "^1.4.0" | ||
}, | ||
"devDependencies": { | ||
"async": "^1.4.0", | ||
"eh-guid": "^0.2.0", | ||
@@ -23,0 +24,0 @@ "should": "^6.0.3", |
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
Network access
Supply chain riskThis module accesses the network.
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
15851
6
568
4
2
+ Addedrequestretry@^1.4.0
+ Addedlodash@4.17.21(transitive)
+ Addedrequestretry@1.13.0(transitive)
+ Addedwhen@3.7.8(transitive)
- Removedrequest@^2.55.0