Socket
Socket
Sign inDemoInstall

sqs-producer

Package Overview
Dependencies
Maintainers
2
Versions
41
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sqs-producer - npm Package Compare versions

Comparing version 1.2.0 to 1.3.0

56

lib/producer.js

@@ -8,3 +8,5 @@ var AWS = require('aws-sdk');

this.queueUrl = options.queueUrl;
this.sqs = options.sqs || new AWS.SQS({region: options.region});
this.sqs = options.sqs || new AWS.SQS({
region: options.region
});
}

@@ -16,2 +18,12 @@

function isMessageAttributeValid(messageAttribute) {
if (!messageAttribute.DataType) {
throw new Error('A MessageAttribute must have a DataType key');
}
if (typeof messageAttribute.DataType !== 'string') {
throw new Error('The DataType key of a MessageAttribute must be a String');
}
return true;
}
function entryFromObject(message) {

@@ -22,6 +34,31 @@ if (!message.id || !message.body) {

return {
var entry = {
Id: message.id,
MessageBody: message.body
};
if (message.delaySeconds) {
if (
(typeof message.delaySeconds !== 'number') ||
(message.delaySeconds < 0 || message.delaySeconds > 900)
) {
throw new Error('Message.delaySeconds value must be a number contained within [0 - 900]');
}
entry.DelaySeconds = message.delaySeconds;
}
if (message.messageAttributes) {
if (typeof message.messageAttributes !== 'object') {
throw new Error('Message.messageAttributes must be an object');
}
Object.keys(message.messageAttributes).every(function (key) {
return isMessageAttributeValid(message.messageAttributes[key]);
});
entry.MessageAttributes = message.messageAttributes;
}
return entry;
}

@@ -39,4 +76,3 @@

return entryFromString(message);
}
else if (typeof message === 'object') {
} else if (typeof message === 'object') {
return entryFromObject(message);

@@ -56,4 +92,3 @@ }

Producer.prototype._sendBatch = function(failedMessages, messages, startIndex, cb) {
Producer.prototype._sendBatch = function (failedMessages, messages, startIndex, cb) {
var producer = this;

@@ -68,4 +103,3 @@ var endIndex = startIndex + BATCH_SIZE;

params.Entries = batch.map(entryFromMessage);
}
catch (err) {
} catch (err) {
cb(err);

@@ -88,3 +122,3 @@ return;

Producer.prototype.send = function(messages, cb) {
Producer.prototype.send = function (messages, cb) {
var failedMessages = [];

@@ -108,4 +142,4 @@ var startIndex = 0;

module.exports.create = function(options) {
module.exports.create = function (options) {
return new Producer(options);
};
};

2

package.json
{
"name": "sqs-producer",
"version": "1.2.0",
"version": "1.3.0",
"description": "Enqueues messages onto a given SQS queue",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -43,2 +43,23 @@ sqs-producer

// send a message to the queue with
// - delaySeconds (must be an number contained within 0 and 900)
// - messageAttributes
producer.send([
{
id: 'id1',
body: 'Hello world with two string attributes: attr1 and attr2',
messageAttributes: {
attr1: { DataType: 'String', StringValue: 'stringValue' }
attr2: { DataType: 'BinaryValue', BinaryValue: new Buffer('binaryValue') }
}
},
{
id: 'id2',
body: 'Hello world delayed by 5 seconds',
delaySeconds: 5
}
], function(err) {
if (err) console.log(err);
});
```

@@ -45,0 +66,0 @@

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