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

message-hub-rest

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

message-hub-rest - npm Package Compare versions

Comparing version 1.1.2 to 1.2.0

21

lib/messagehub.js

@@ -111,7 +111,11 @@ /**

*
* @param topic The topic name for the service to create.
* @returns Promise object which will be fulfilled when the request
* to the service resolves.
* @param topic The topic name for the service to create.
* @param partitions The number of partitions the topic should use.
* @param retentionHours The number of hours to retain messages on this topic. Minimum is
* 24 hours, if retentionHours is less than this, it will be set to
* the minimum.
* @returns Promise object which will be fulfilled when the request
* to the service resolves.
*/
Client.prototype.topics.create = function(topic, partitions) {
Client.prototype.topics.create = function(topic, partitions, retentionHours) {
if(topic && typeof(topic) === 'string' && topic.length > 0) {

@@ -122,2 +126,6 @@ if(!partitions || (partitions && typeof(partitions) !== 'number') || partitions < 1) {

if(!retentionHours || (retentionHours && typeof(retentionHours) !== 'number') || retentionHours < 24) {
retentionHours = 24;
}
var requestOptions = {

@@ -134,2 +142,4 @@ host: this.parent.url.hostname,

var retentionMs = retentionHours * 60 * 60 * 1000;
return Utils.request(

@@ -145,2 +155,5 @@ requestOptions,

partitions: partitions,
configs: {
retentionMs: retentionMs
}
});

@@ -147,0 +160,0 @@ } else {

2

package.json
{
"name": "message-hub-rest",
"version": "1.1.2",
"version": "1.2.0",
"description": "Node.js module for connecting to the Kafka REST interface of IBM Message Hub.",

@@ -5,0 +5,0 @@ "main": "lib/messagehub.js",

@@ -84,7 +84,8 @@ ## IBM Message Hub REST API Client Module

### MessageHub.prototype.topics.create(topic, partitions)
### MessageHub.prototype.topics.create(topic, partitions, retentionHours)
Creates a topic of the specified name. __Important Note__: Creating topics incurs a fee - check the Bluemix documentation
for more information.
* `topic` - (String) (required), the topic name for the service to create.
* `partitions` - (String) (optional), the number of partitions to use for this topic. Defaults to 1.
* `partitions` - (Number) (optional), the number of partitions to use for this topic. Defaults to 1.
* `retentionHours` - (Number) (optional), the number of hours to retain messages on this topic. Minimum is 24 hours, if retentionHours is less than this, it will be set to the minimum.

@@ -91,0 +92,0 @@ Returns a Promise object which will be fulfilled when the request to the service resolves.

@@ -65,4 +65,18 @@ /**

if(!inList) {
instance.topics.push({ name: request.body.name, partitions: request.body.partitions || 1 });
response.sendStatus(202);
var retentionMs = 3600000; // 24 hours
if(request.body.configs && request.body.configs.retentionMs) {
retentionMs = request.body.configs.retentionMs;
}
if(retentionMs < 3600000 || retentionMs > 30 * 24 * 3600000) {
response.status(422).send({ errorCode: 42212, errorMessage: "Invalid retention period specified. The minimum is an hour and the maximum is 30 days. This must be specified as a multiple of 3,600,000" });
} else {
instance.topics.push({
name: request.body.name,
partitions: request.body.partitions || 1,
retentionMs: retentionMs
});
response.sendStatus(202);
}
} else {

@@ -69,0 +83,0 @@ response.status(422).send({ errorCode: 42201, errorMessage: 'Topic already exists.' });

@@ -128,2 +128,34 @@ /**

it('Creates a topic successfully with more than 24 hours retention period', function(done) {
var input = TOPIC_PREFIX + 'mytopic';
var retentionHours = 35;
instance.topics.create(input, 1, retentionHours)
.then(function() {
return instance.topics.get();
})
.then(function(topics) {
var found = false;
var retentionMs = 0;
for(var j in topics) {
if(topics[j].name === input) {
found = true;
retentionMs = topics[j].retentionMs;
}
}
Expect(found).to.eql(true);
Expect(retentionMs).to.eql(retentionHours * 60 * 60 * 1000);
return instance.topics.delete(input);
})
.then(function(response) {
done();
})
.catch(function(error) {
done(new Error('Topic creation should have succeeded: ' + error.message));
});
});
it('Ignores 42201 error (topic exists)', function(done) {

@@ -254,2 +286,5 @@ var input = TOPIC_PREFIX + 'mytopic';

}
})
.catch(function(error) {
done(error);
});

@@ -297,2 +332,5 @@

}
})
.catch(function(error) {
done(error);
});

@@ -303,2 +341,46 @@ })();

it('Default retention period to 24 hours for invalid inputs', function(done) {
var input = [undefined, null, '', 'abc', -1, 0, 23, {}, []];
var promisesResolved = 0;
for(var index in input) {
(function() {
var i = index;
var topicName = TOPIC_PREFIX + 'retentionTopic' + i;
instance.topics.create(topicName, 1, input[i])
.then(function(data) {
return instance.topics.get();
})
.then(function(topics) {
var found = false;
var retentionMs = 0;
for(var j in topics) {
if(topics[j].name === topicName) {
found = true;
retentionMs = topics[j].retentionMs;
}
}
Expect(found).to.eql(true);
Expect(retentionMs).to.eql(86400000);
return instance.topics.delete(topicName);
})
.then(function() {
promisesResolved++;
if(promisesResolved === input.length) {
done();
}
})
.catch(function(error) {
done(error);
});
})();
}
});
it('Successfully retrieves a list of topics', function(done) {

@@ -321,2 +403,5 @@ var topicName = TOPIC_PREFIX + 'topic_to_create';

})
.catch(function(error) {
done(error);
})
.fin(function() {

@@ -323,0 +408,0 @@ done();

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