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

nats

Package Overview
Dependencies
Maintainers
2
Versions
195
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

nats - npm Package Compare versions

Comparing version 0.6.4 to 0.6.8

test/json.js

63

lib/nats.js

@@ -20,3 +20,3 @@ /*!

events = require('events'),
nuid = require('./nuid.js');
nuid = require('nuid');

@@ -27,3 +27,3 @@ /**

var VERSION = '0.6.4',
var VERSION = '0.6.8',

@@ -72,7 +72,8 @@ DEFAULT_PORT = 4222,

// Errors
BAD_SUBJECT_ERR = new Error('Subject must be supplied'),
BAD_MSG_ERR = new Error('Message can\'t be a function'),
BAD_REPLY_ERR = new Error('Reply can\'t be a function'),
CONN_CLOSED_ERR = new Error('Connection closed'),
BAD_JSON_MSG_ERR = new Error('Message should be a JSON object'),
BAD_SUBJECT = 'Subject must be supplied',
BAD_MSG = 'Message can\'t be a function',
BAD_REPLY = 'Reply can\'t be a function',
CONN_CLOSED = 'Connection closed',
BAD_JSON_MSG = 'Message should be a JSON object',
BAD_AUTHENTICATION = 'User and Token can not both be provided',

@@ -196,2 +197,3 @@ // Pedantic Mode support

this.assignOption(opts, 'pass');
this.assignOption(opts, 'token');
this.assignOption(opts, 'password', 'pass');

@@ -223,3 +225,11 @@ this.assignOption(opts, 'verbose');

client.pass = options.pass;
// Set token as needed if in options.
client.token = options.token;
// Authentication - make sure authentication is valid.
if (client.user && client.token) {
throw(new Error(BAD_AUTHENTICATION));
}
// Encoding - make sure its valid.

@@ -281,8 +291,14 @@ if (Buffer.isEncoding(options.encoding)) {

var auth = server.url.auth.split(':');
if (client.options.user === undefined) {
client.user = auth[0];
if (auth.length !== 1) {
if (client.options.user === undefined) {
client.user = auth[0];
}
if (client.options.pass === undefined) {
client.pass = auth[1];
}
} else {
if (client.options.token === undefined) {
client.token = auth[0];
}
}
if (client.options.pass === undefined) {
client.pass = auth[1];
}
}

@@ -434,2 +450,5 @@ client.servers.push(server);

}
if (this.token !== undefined) {
cs.auth_token = this.token;
}
if (this.options.name !== undefined) {

@@ -911,6 +930,6 @@ cs.name = this.options.name;

if (typeof opt_callback === 'function') {
opt_callback(CONN_CLOSED_ERR);
opt_callback(new Error(CONN_CLOSED));
return;
} else {
throw(CONN_CLOSED_ERR);
throw(new Error(CONN_CLOSED));
}

@@ -944,5 +963,5 @@ }

if (opt_callback) {
opt_callback(BAD_SUBJECT_ERR);
opt_callback(new Error(BAD_SUBJECT));
} else {
throw(BAD_SUBJECT_ERR);
throw(new Error(BAD_SUBJECT));
}

@@ -952,3 +971,3 @@ }

if (opt_callback || opt_reply) {
opt_callback(BAD_MSG_ERR);
opt_callback(new Error(BAD_MSG));
return;

@@ -962,3 +981,3 @@ }

if (opt_callback) {
opt_callback(BAD_REPLY_ERR);
opt_callback(new Error(BAD_REPLY));
return;

@@ -983,3 +1002,3 @@ }

if (typeof msg !== 'object' || Array.isArray(msg)) {
throw(BAD_JSON_MSG_ERR);
throw(new Error(BAD_JSON_MSG));
}

@@ -989,3 +1008,3 @@ try {

} catch (e) {
throw(BAD_JSON_MSG_ERR);
throw(new Error(BAD_JSON_MSG));
}

@@ -1005,3 +1024,3 @@ }

} else if (this.closed) {
throw(CONN_CLOSED_ERR);
throw(new Error(CONN_CLOSED));
}

@@ -1023,3 +1042,3 @@ };

if (this.closed) {
throw(CONN_CLOSED_ERR);
throw(new Error(CONN_CLOSED));
}

@@ -1026,0 +1045,0 @@ var qgroup, max;

{
"name": "nats",
"version": "0.6.4",
"version": "0.6.8",
"description": "Node.js client for NATS, a lightweight, high-performance cloud native messaging system",

@@ -37,3 +37,4 @@ "keywords": [

"test": "npm run depcheck && npm run depcheck:unused && npm run lint && npm run test:unit",
"coveralls": "cat ./reports/coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js"
"coveralls": "npm run cover -- --report lcovonly && cat ./reports/coverage/lcov.info | coveralls",
"cover": "istanbul cover _mocha"
},

@@ -43,3 +44,5 @@ "engines": {

},
"dependencies": {},
"dependencies": {
"nuid": ">=0.6.8"
},
"devDependencies": {

@@ -46,0 +49,0 @@ "jshint": "2.9.x",

@@ -6,3 +6,3 @@ # NATS - Node.js Client

[![License MIT](https://img.shields.io/npm/l/express.svg)](http://opensource.org/licenses/MIT)
[![Build Status](https://secure.travis-ci.org/nats-io/node-nats.png)](http://travis-ci.org/nats-io/node-nats) [![npm version](https://badge.fury.io/js/nats.svg)](http://badge.fury.io/js/nats)[![Coverage Status](https://coveralls.io/repos/nats-io/node-nats/badge.svg)](https://coveralls.io/r/nats-io/node-nats?branch=master)
[![Build Status](https://travis-ci.org/nats-io/node-nats.svg?branch=master)](http://travis-ci.org/nats-io/node-nats) [![npm version](https://badge.fury.io/js/nats.svg)](http://badge.fury.io/js/nats)[![Coverage Status](https://coveralls.io/repos/github/nats-io/node-nats/badge.svg?branch=master)](https://coveralls.io/github/nats-io/node-nats?branch=master)

@@ -137,3 +137,18 @@ ## Installation

```
## Authentication
```javascript
// Connect with username and password in the url
var nc = NATS.connect("nats://foo:bar@localhost:4222");
// Connect with username and password inside object
var nc = NATS.connect({'url':"nats://localhost:4222", 'user':'foo', 'pass':'bar'});
// Connect with token in url
var nc = NATS.connect("nats://mytoken@localhost:4222");
// Connect with token inside object
var nc = NATS.connect({'url':"nats://localhost:4222", 'token':'mytoken'});
```
## Advanced Usage

@@ -140,0 +155,0 @@

@@ -65,1 +65,58 @@ /* jslint node: true */

});
describe('Token Authorization', function() {
var PORT = 1421;
var flags = ['--auth', 'token1'];
var authUrl = 'nats://token1@localhost:' + PORT;
var noAuthUrl = 'nats://localhost:' + PORT;
var server;
// Start up our own nats-server
before(function(done) {
server = nsc.start_server(PORT, flags, done);
});
// Shutdown our server after we are done
after(function(){
server.kill();
});
it('should fail to connect with no credentials ', function(done) {
var nc = NATS.connect(PORT);
nc.on('error', function(err) {
should.exist(err);
should.exist(/Authorization/.exec(err));
nc.close();
done();
});
});
it('should connect with proper credentials in url', function(done) {
var nc = NATS.connect(authUrl);
nc.on('connect', function(/*nc*/) {
setTimeout(function() {
nc.close();
done();
}, 100);
});
});
it('should connect with proper credentials as options', function(done) {
var nc = NATS.connect({'url':noAuthUrl, 'token':'token1'});
nc.on('connect', function(/*nc*/) {
setTimeout(function() {
nc.close();
done();
}, 100);
});
});
it('should connect with proper credentials as server url', function(done) {
var nc = NATS.connect({'servers':[authUrl]});
nc.on('connect', function(/*nc*/) {
setTimeout(done, 100);
});
});
});

@@ -23,2 +23,7 @@ /* jslint node: true */

});
it('should throw errors on connect', function(done) {
(function() { var nc = NATS.connect({'url':'nats://localhost:' + PORT, 'token':'token1', 'user':'foo'}); }).should.throw(Error);
done();
});

@@ -25,0 +30,0 @@ it('should throw errors on publish', function(done) {

Sorry, the diff of this file is not supported yet

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