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.2.0 to 2.3.0

35

client.js

@@ -92,3 +92,3 @@ const url = require('url');

}
return (this.currentId).toString();
return this.currentId;
};

@@ -215,10 +215,15 @@

LimitdClient.prototype._fireAndForgetRequest = function (request) {
if (!this.stream || !this.stream.writable) {
const err = new Error(`Unable to send ${request.method} to limitd. The socket is closed.`);
return this.emit('error', err);
}
lpm.write(this.stream, Protocol.Request.encode(request));
};
LimitdClient.prototype._request = function (request, type, callback) {
if (!this.stream || !this.stream.writable) {
const err = new Error('The socket is closed.');
if (callback) {
return setImmediate(callback, err);
} else {
throw err;
}
const err = new Error(`Unable to send ${request.method} to limitd. The socket is closed.`);
return setImmediate(callback, err);
}

@@ -254,3 +259,3 @@

'all': takeAll || null,
'count': !takeAll ? count : null
'count': !takeAll ? count : undefined
};

@@ -272,3 +277,3 @@

if (typeof count === 'undefined' && typeof done === 'undefined') {
done = _.noop;
done = undefined;
count = 'all';

@@ -282,7 +287,6 @@ }

if (typeof done === 'undefined') {
done = _.noop;
}
const reset_all = count === 'all';
const fireAndForget = typeof done !== 'function';
const request = {

@@ -294,5 +298,10 @@ 'id': this.nextId(),

'all': reset_all ? true : null,
'count': !reset_all ? count : null
'count': !reset_all ? count : undefined,
'skipResponse': fireAndForget
};
if (fireAndForget) {
return this._fireAndForgetRequest(request);
}
return this._request(request, type, done);

@@ -299,0 +308,0 @@ };

{
"name": "limitd-client",
"version": "2.2.0",
"version": "2.3.0",
"description": "limitd client for node.js",

@@ -15,3 +15,3 @@ "main": "index.js",

"length-prefixed-stream": "~1.4.0",
"limitd-protocol": "limitd/protocol#v1.6.4",
"limitd-protocol": "limitd/protocol#v1.8.0",
"lodash": "~3.7.0",

@@ -18,0 +18,0 @@ "murmurhash3js": "^3.0.1",

@@ -35,3 +35,3 @@ const LimitdClient = require('../');

server.once('request', function (request) {
assert.isString(request.id);
assert.isNumber(request.id);
assert.equal(request.method, method.toUpperCase());

@@ -50,3 +50,3 @@ assert.equal(request.type, 'ip');

server.once('request', function (request) {
assert.isString(request.id);
assert.isNumber(request.id);
assert.equal(request.method, 'PING');

@@ -61,3 +61,3 @@ done();

server.once('request', function (request) {
assert.isString(request.id);
assert.isNumber(request.id);

@@ -67,2 +67,3 @@ assert.equal(request.method, 'PUT');

assert.equal(request.all, true);
assert.notOk(request.skipResponse);

@@ -72,2 +73,18 @@ done();

client.put('ip', '191.12.23.32', _.noop);
});
it('should be able to send callback-less PUT requests', function (done) {
server.once('request', function (request) {
assert.isNumber(request.id);
assert.equal(request.method, 'PUT');
assert.equal(request.type, 'ip');
assert.equal(request.all, true);
assert.equal(request.skipResponse, true);
done();
});
client.put('ip', '191.12.23.32');

@@ -78,3 +95,3 @@ });

server.once('request', function (request) {
assert.isString(request.id);
assert.isNumber(request.id);

@@ -81,0 +98,0 @@ assert.equal(request.method, 'STATUS');

@@ -46,3 +46,3 @@ const _ = require('lodash');

servers[0].once('request', function (request) {
assert.equal(typeof request.id, 'string');
assert.equal(typeof request.id, 'number');
assert.equal(request.method, 'TAKE');

@@ -61,3 +61,3 @@ assert.equal(request.type, 'ip');

servers[1].once('request', function (request) {
assert.equal(typeof request.id, 'string');
assert.equal(typeof request.id, 'number');
assert.equal(request.method, 'TAKE');

@@ -83,3 +83,3 @@ assert.equal(request.type, 'ip');

servers[0].once('request', function (request) {
assert.equal(typeof request.id, 'string');
assert.equal(typeof request.id, 'number');
assert.equal(request.method, 'TAKE');

@@ -86,0 +86,0 @@ assert.equal(request.type, 'ip');

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