limitd-client
Advanced tools
Comparing version 2.13.2 to 2.14.0
@@ -453,2 +453,18 @@ const url = require('url'); | ||
LimitdClient.prototype.get = function (type, key, done) { | ||
if (typeof key !== 'string') { | ||
return done(new Error('key must be a string')); | ||
} | ||
const request = { | ||
'id': this.nextId(), | ||
'type': type, | ||
'key': key, | ||
'method': 'GET', | ||
'skipResponse': false | ||
}; | ||
return this._retriedRequest(request, done); | ||
}; | ||
LimitdClient.prototype.status = function (type, key, done) { | ||
@@ -455,0 +471,0 @@ if (typeof key !== 'string') { |
{ | ||
"name": "limitd-client", | ||
"version": "2.13.2", | ||
"version": "2.14.0", | ||
"description": "limitd client for node.js", | ||
@@ -18,3 +18,3 @@ "main": "index.js", | ||
"length-prefixed-stream": "~1.4.0", | ||
"limitd-protocol": "limitd/protocol#v2.0.1", | ||
"limitd-protocol": "limitd/protocol#v2.1.0", | ||
"lodash": "~3.7.0", | ||
@@ -21,0 +21,0 @@ "ms": "^1.0.0", |
@@ -104,3 +104,3 @@ const LimitdClient = require('./client'); | ||
['reset', 'put', 'take', 'wait'].forEach(method => { | ||
['reset', 'put', 'take', 'wait', 'get'].forEach(method => { | ||
ShardClient.prototype[method] = function(type, key) { | ||
@@ -107,0 +107,0 @@ const client = this.getDestinationClient(type, key); |
@@ -69,2 +69,38 @@ const LimitdClient = require('../'); | ||
it('should require a key for GET requests', (done) => { | ||
client.get('ip', ['bar'], (err) => { | ||
assert.isDefined(err); | ||
assert.equal(err.toString(), 'Error: key must be a string'); | ||
done(); | ||
}); | ||
}); | ||
it('should be able to send GET requests', function (done) { | ||
server.once('request', function (request, reply) { | ||
assert.isNumber(request.id); | ||
assert.equal(request.method, 'GET'); | ||
assert.equal(request.type, 'ip'); | ||
const response = { | ||
request_id: request.id, | ||
'get': { | ||
remaining: 15, | ||
reset: 22222222, | ||
limit: 101 | ||
} | ||
}; | ||
reply(response); | ||
}); | ||
client.get('ip', '192.12.23.32', (err, response) => { | ||
assert.isNull(err); | ||
assert.isDefined(response); | ||
assert.equal(response.remaining, 15); | ||
assert.equal(response.reset, 22222222); | ||
assert.equal(response.limit, 101); | ||
done(); | ||
}); | ||
}); | ||
it('should be able to send PING requests', function (done) { | ||
@@ -71,0 +107,0 @@ server.once('request', function (request) { |
@@ -69,3 +69,3 @@ const ShardClient = require('../shard_client'); | ||
['take', 'put', 'wait', 'status', 'on', 'once', 'ping'].forEach(method => { | ||
['take', 'put', 'wait', 'status', 'on', 'once', 'ping', 'get'].forEach(method => { | ||
it(`should define ${method}`, function() { | ||
@@ -126,2 +126,24 @@ const shardClient = new ShardClient({ | ||
it('should invoke GET on the client based on the hash', function(done) { | ||
const client = function(params) { | ||
this.host = params.host; | ||
this.get = function(type, key, callback) { | ||
assert.equal(this.host, 'limitd://host-1:9231'); | ||
assert.equal(type, 'ip'); | ||
assert.equal(key, '10.0.0.1'); | ||
assert.isFunction(callback); | ||
done(); | ||
}; | ||
}; | ||
const ShardClient = ShardClientCtor(client); | ||
const shardClient = new ShardClient({ | ||
client, | ||
shard: { hosts: [ 'host-1', 'host-2' ] } | ||
}); | ||
shardClient.get('ip', '10.0.0.1', _.noop); | ||
}); | ||
it('should invoke PUT on the client based on the hash (2)', function(done) { | ||
@@ -128,0 +150,0 @@ const client = function(params) { |
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
GitHub dependency
Supply chain riskContains a dependency which resolves to a GitHub URL. Dependencies fetched from GitHub specifiers are not immutable can be used to inject untrusted code or reduce the likelihood of a reproducible install.
Found 1 instance in 1 package
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
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
GitHub dependency
Supply chain riskContains a dependency which resolves to a GitHub URL. Dependencies fetched from GitHub specifiers are not immutable can be used to inject untrusted code or reduce the likelihood of a reproducible install.
Found 1 instance in 1 package
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
60795
1645
20