Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

limitd-client

Package Overview
Dependencies
Maintainers
2
Versions
70
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

limitd-client - npm Package Compare versions

Comparing version 2.13.2 to 2.14.0

16

client.js

@@ -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') {

4

package.json
{
"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) {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc