Comparing version 0.1.1 to 0.1.2
@@ -128,18 +128,11 @@ 'use strict'; | ||
//render body | ||
self.render.render(options, function (err) { | ||
if(err) { | ||
//add to queue | ||
self.queue.add(message, function (err, message) { | ||
if (err) { | ||
return callback(err); | ||
} | ||
//add to queue | ||
self.queue.add(message, function (err, message) { | ||
if (err) { | ||
return callback(err); | ||
} | ||
callback(null, { | ||
messageId: message._id, | ||
status: 'queued', | ||
createdAt: message.createdAt | ||
}); | ||
callback(null, { | ||
messageId: message._id, | ||
status: 'queued', | ||
createdAt: message.createdAt | ||
}); | ||
@@ -146,0 +139,0 @@ }); |
var events = require('events'); | ||
var _ = require('lodash'); | ||
@@ -8,21 +9,108 @@ var eventsName = { | ||
module.exports = function (mailer, options) { | ||
if (!options) { | ||
options = {}; | ||
function Dispatcher (mailer, options) { | ||
this.mailer = mailer; | ||
this.options = {}; | ||
this.eventEmitter = new events.EventEmitter(); | ||
if (options) { | ||
this.init(options); | ||
} | ||
var eventEmitter = new events.EventEmitter(); | ||
return { | ||
newMessage: function (message) { | ||
//console.log(eventsName.newMessage + '_' + message.provider.name, message); | ||
eventEmitter.emit(eventsName.newMessage + '_' + message.provider.name, message); | ||
}, | ||
} | ||
registerAdapter: function (providerName, adapter) { | ||
if (options.sendWrapper) { | ||
eventEmitter.on(eventsName.newMessage + '_' + providerName, options.sendWrapper(adapter)); | ||
} else { | ||
eventEmitter.on(eventsName.newMessage + '_' + providerName, adapter.send); | ||
} | ||
}, | ||
}; | ||
/** | ||
* Sets dispatcher options | ||
* | ||
* # Example: | ||
* | ||
* dispatcher.set('debug', true) | ||
* | ||
* @param {String} key | ||
* @param {String|Function} value | ||
* @api public | ||
*/ | ||
Dispatcher.prototype.set = function(key, value) { | ||
if (arguments.length == 1) { | ||
return this.options[key]; | ||
} | ||
this.options[key] = value; | ||
return this; | ||
}; | ||
/** | ||
* Gets dispatcher options | ||
* | ||
* # Example: | ||
* | ||
* dispatcher.get('test') // returns the 'test' value | ||
* | ||
* @param {String} key | ||
* @api public | ||
*/ | ||
Dispatcher.prototype.get = Dispatcher.prototype.set; | ||
/** | ||
* Init Dispatcher | ||
* | ||
* # Example: | ||
* | ||
* dispatcher.init() | ||
* | ||
* dispatcher.init({..}) | ||
* | ||
* @param {Object} options | ||
* @method init | ||
* @api public | ||
*/ | ||
Dispatcher.prototype.init = function (options) { | ||
this.options = _.merge(options, this.options); | ||
}; | ||
/** | ||
* Rigister an adapter | ||
* | ||
* # Example: | ||
* | ||
* dispatcher.registerAdapter('test', adapter) | ||
* | ||
* @param {String} providerName | ||
* @param {Object} adapter | ||
* @api public | ||
*/ | ||
Dispatcher.prototype.registerAdapter = function (providerName, adapter) { | ||
if (this.options.sendWrapper) { | ||
this.eventEmitter.on(eventsName.newMessage + '_' + providerName, this.options.sendWrapper(adapter)); | ||
} else { | ||
this.eventEmitter.on(eventsName.newMessage + '_' + providerName, adapter.send); | ||
} | ||
if(this.options.debug) { | ||
console.log(new Date() + ' - Registered ' + providerName + 'adapter' + (this.mailer.options.sendWrapper ? 'with wrapper' : '')); | ||
} | ||
}; | ||
/** | ||
* Trigger new message event to right adapter | ||
* | ||
* # Example: | ||
* | ||
* dispatcher.newMessage(message) | ||
* | ||
* @param {Object} message | ||
* @api public | ||
*/ | ||
Dispatcher.prototype.newMessage = function (message) { | ||
if(this.options.debug) { | ||
console.log(eventsName.newMessage + '_' + message.provider.name, message); | ||
} | ||
this.eventEmitter.emit(eventsName.newMessage + '_' + message.provider.name, message); | ||
}; | ||
module.exports = function (mailer, options) { | ||
return new Dispatcher(mailer, options); | ||
}; |
@@ -251,4 +251,7 @@ 'use strict'; | ||
Queue.prototype.Model = require('./model'); | ||
module.exports = function (mailer) { | ||
return new Queue(mailer); | ||
}; |
@@ -5,3 +5,3 @@ module.exports = { | ||
uri: 'mongodb://localhost/mailer-dev', | ||
debug: true, | ||
debug: false, | ||
options: {}, | ||
@@ -8,0 +8,0 @@ }, |
@@ -9,3 +9,4 @@ var should = require('should'); | ||
describe('Send', function() { | ||
this.timeout(10000); | ||
this.timeout(5000); | ||
it('send', function(done) { | ||
@@ -12,0 +13,0 @@ var fakeProviderInstance = fakeProvider(); |
{ | ||
"name": "posteon", | ||
"description": " ", | ||
"version": "0.1.1", | ||
"version": "0.1.2", | ||
"keywords": [ | ||
@@ -33,3 +33,3 @@ "mailer", | ||
}, | ||
"main": "./index.js", | ||
"main": "./lib/index.js", | ||
"scripts": { | ||
@@ -36,0 +36,0 @@ "test": "mocha ./lib/**/*.test.js ./test/**/*.test.js" |
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
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
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 2 instances in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
0
22980
20
814