limitd-client
Advanced tools
Comparing version 2.0.1 to 2.0.2
@@ -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
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
23428
8
14
566
1
2
+ Addeduuid@^3.0.1
+ Addedlength-prefixed-message@3.0.4(transitive)
+ Addeduuid@3.4.0(transitive)
+ Addedvarint@3.0.1(transitive)
- Removedprotobufjs@^6.6.5
- Removedrandomstring@~1.0.5
- Removed@protobufjs/aspromise@1.1.2(transitive)
- Removed@protobufjs/base64@1.1.2(transitive)
- Removed@protobufjs/codegen@2.0.4(transitive)
- Removed@protobufjs/eventemitter@1.1.0(transitive)
- Removed@protobufjs/fetch@1.1.0(transitive)
- Removed@protobufjs/float@1.0.2(transitive)
- Removed@protobufjs/inquire@1.1.0(transitive)
- Removed@protobufjs/path@1.1.2(transitive)
- Removed@protobufjs/pool@1.1.0(transitive)
- Removed@protobufjs/utf8@1.1.0(transitive)
- Removed@types/long@4.0.2(transitive)
- Removed@types/node@22.9.3(transitive)
- Removedlong@4.0.0(transitive)
- Removedprotobufjs@6.11.4(transitive)
- Removedrandomstring@1.0.8(transitive)
- Removedundici-types@6.19.8(transitive)