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.0.1 to 2.0.2

71

client.js

@@ -1,16 +0,16 @@

const url = require('url');
const _ = require('lodash');
const EventEmitter = require('events').EventEmitter;
const util = require('util');
const randomstring = require('randomstring');
const reconnect = require('reconnect-net');
const failover = require('tcp-client-failover');
const Transform = require('stream').Transform;
const url = require('url');
const _ = require('lodash');
const EventEmitter = require('events').EventEmitter;
const util = require('util');
const reconnect = require('reconnect-net');
const failover = require('tcp-client-failover');
const Transform = require('stream').Transform;
const Protocol = require('limitd-protocol');
const uuid = require('uuid/v1');
const RequestMessage = require('./lib/protocol').Request;
const ResponseMessage = require('./lib/protocol').Response;
const ErrorResponse = require('./lib/protocol').ErrorResponse;
const disyuntor = require('disyuntor');
const lps = require('length-prefixed-stream');
const disyuntor = require('disyuntor');
const lps = require('length-prefixed-stream');
const lpm = require('length-prefixed-message');
var defaults = {

@@ -143,3 +143,3 @@ port: 9231,

try {
const decoded = ResponseMessage.decode(chunk);
const decoded = Protocol.Response.decode(chunk);
this.push(decoded);

@@ -189,3 +189,3 @@ } catch(err) {

this.stream.write(RequestMessage.encodeDelimited(request).finish());
lpm.write(this.stream, Protocol.Request.encode(request));

@@ -197,12 +197,9 @@ const start = Date.now();

if (response['.limitd.ErrorResponse.response'] &&
response['.limitd.ErrorResponse.response'].type === ErrorResponse.Type.UNKNOWN_BUCKET_TYPE) {
if (response.error &&
response.error.type === 'UNKNOWN_BUCKET_TYPE') {
return callback(new Error(type + ' is not a valid bucket type'));
}
const resp = response['.limitd.TakeResponse.response'] ||
response['.limitd.PutResponse.response'] ||
response['.limitd.StatusResponse.response'];
const resp = response[response.body];
if (resp) {

@@ -233,10 +230,10 @@ resp.took = Date.now() - start;

var request = RequestMessage.create({
'id': randomstring.generate(7),
const request = {
'id': uuid(),
'type': type,
'key': key,
'method': RequestMessage.Method[method],
'method': method,
'all': count === 'all' || null,
'count': count !== 'all' ? count : null
});
};

@@ -270,10 +267,10 @@ return this._request(request, type, done);

var request = RequestMessage.create({
'id': randomstring.generate(7),
const request = {
'id': uuid(),
'type': type,
'key': key,
'method': RequestMessage.Method.PUT,
'method': 'PUT',
'all': count === 'all' ? true : null,
'count': count !== 'all' ? count : null
});
};

@@ -284,8 +281,8 @@ return this._request(request, type, done);

LimitdClient.prototype.status = function (type, key, done) {
var request = RequestMessage.create({
'id': randomstring.generate(7),
var request = {
'id': uuid(),
'type': type,
'key': key,
'method': RequestMessage.Method.STATUS,
});
'method': 'STATUS',
};

@@ -296,8 +293,8 @@ return this._request(request, type, done);

LimitdClient.prototype.ping = function (done) {
var request = RequestMessage.create({
'id': randomstring.generate(7),
var request = {
'id': uuid(),
'type': '',
'key': '',
'method': RequestMessage.Method.PING,
});
'method': 'PING',
};

@@ -304,0 +301,0 @@ return this._request(request, '', done);

{
"name": "limitd-client",
"version": "2.0.1",
"version": "2.0.2",
"description": "limitd client for node.js",

@@ -13,8 +13,9 @@ "main": "index.js",

"disyuntor": "~1.2.1",
"length-prefixed-message": "^3.0.3",
"length-prefixed-stream": "~1.4.0",
"limitd-protocol": "limitd/protocol#v1.6.2",
"lodash": "~3.7.0",
"protobufjs": "^6.6.5",
"randomstring": "~1.0.5",
"reconnect-net": "0.0.0",
"tcp-client-failover": "^1.0.2"
"tcp-client-failover": "^1.0.2",
"uuid": "^3.0.1"
},

@@ -21,0 +22,0 @@ "devDependencies": {

const LimitdClient = require('../');
const MockServer = require('./MockServer');
const assert = require('chai').assert;
const protocol = require('../lib/protocol');
const Response = protocol.Response;
const TakeResponse = protocol.TakeResponse;
const ErrorResponse = protocol.ErrorResponse;
const _ = require('lodash');

@@ -34,3 +30,3 @@

assert.isString(request.id);
assert.equal(request.method, protocol.Request.Method[method.toUpperCase()]);
assert.equal(request.method, method.toUpperCase());
assert.equal(request.type, 'ip');

@@ -49,3 +45,3 @@ assert.equal(request.count, 1);

assert.isString(request.id);
assert.equal(request.method, protocol.Request.Method.PING);
assert.equal(request.method, 'PING');
done();

@@ -61,3 +57,3 @@ });

assert.equal(request.method, protocol.Request.Method.PUT);
assert.equal(request.method, 'PUT');
assert.equal(request.type, 'ip');

@@ -76,3 +72,3 @@ assert.equal(request.all, true);

assert.equal(request.method, protocol.Request.Method.STATUS);
assert.equal(request.method, 'STATUS');
assert.equal(request.type, 'ip');

@@ -89,15 +85,12 @@

server.once('request', function (request, reply) {
var takeResponse = TakeResponse.create({
conformant: true,
remaining: 10,
reset: 11111111,
limit: 100
});
var response = Response.create({
const response = {
request_id: request.id,
'.limitd.TakeResponse.response': takeResponse
});
'take': {
conformant: true,
remaining: 10,
reset: 11111111,
limit: 100
}
};
reply(response);

@@ -120,10 +113,8 @@ });

server.once('request', function (request, reply) {
var errorResponse = ErrorResponse.create({
type: ErrorResponse.Type.UNKNOWN_BUCKET_TYPE
});
var response = Response.create({
const response = {
request_id: request.id,
'.limitd.ErrorResponse.response': errorResponse
});
'error': {
type: 'UNKNOWN_BUCKET_TYPE'
}
};

@@ -130,0 +121,0 @@ reply(response);

@@ -1,7 +0,6 @@

var _ = require('lodash');
var assert = require('assert');
var protocol = require('../lib/protocol');
var LimitdClient = require('../');
var MockServer = require('./MockServer');
var async = require('async');
const _ = require('lodash');
const assert = require('assert');
const LimitdClient = require('../');
const MockServer = require('./MockServer');
const async = require('async');

@@ -48,3 +47,3 @@ var PORT = 9231;

assert.equal(typeof request.id, 'string');
assert.equal(request.method, protocol.Request.Method.TAKE);
assert.equal(request.method, 'TAKE');
assert.equal(request.type, 'ip');

@@ -63,3 +62,3 @@ assert.equal(request.count, 1);

assert.equal(typeof request.id, 'string');
assert.equal(request.method, protocol.Request.Method.TAKE);
assert.equal(request.method, 'TAKE');
assert.equal(request.type, 'ip');

@@ -85,3 +84,3 @@ assert.equal(request.count, 1);

assert.equal(typeof request.id, 'string');
assert.equal(request.method, protocol.Request.Method.TAKE);
assert.equal(request.method, 'TAKE');
assert.equal(request.type, 'ip');

@@ -88,0 +87,0 @@ assert.equal(request.count, 1);

@@ -6,3 +6,3 @@ const net = require('net');

const EventEmitter = require('events').EventEmitter;
const protocol = require('../lib/protocol');
const Protocol = require('limitd-protocol');

@@ -37,3 +37,3 @@ function stream_map (mapper) {

.pipe(lps.decode())
.pipe(stream_map(chunk => protocol.Request.decode(chunk)))
.pipe(stream_map(chunk => Protocol.Request.decode(chunk)))
.pipe(Transform({

@@ -52,3 +52,4 @@ objectMode: true,

}))
.pipe(stream_map(response => protocol.Response.encodeDelimited(response).finish()))
.pipe(stream_map(response => Protocol.Response.encode(response)))
.pipe(lps.encode())
.pipe(socket);

@@ -55,0 +56,0 @@ });

@@ -1,21 +0,16 @@

var LimitdClient = require('../');
var MockServer = require('./MockServer');
var protocol = require('../lib/protocol');
const LimitdClient = require('../');
const MockServer = require('./MockServer');
var Response = protocol.Response;
var TakeResponse = protocol.TakeResponse;
function mock_response (request, reply) {
var takeResponse = TakeResponse.create({
conformant: true,
remaining: 10,
reset: 11111111,
limit: 100
});
var response = Response.create({
var response = {
request_id: request.id,
'.limitd.TakeResponse.response': takeResponse
});
'take': {
conformant: true,
remaining: 10,
reset: 11111111,
limit: 100
}
};

@@ -22,0 +17,0 @@ reply(response);

Sorry, the diff of this file is not supported yet

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