Skip to content

Commit

Permalink
#24 Update development dependencies to more recent versions. Fix esli…
Browse files Browse the repository at this point in the history
…nt warnings/errors.
  • Loading branch information
rdawemsys committed Jun 21, 2019
1 parent 2a6e000 commit 79fadcd
Show file tree
Hide file tree
Showing 6 changed files with 677 additions and 827 deletions.
2 changes: 2 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
dist/
test/reports/
8 changes: 4 additions & 4 deletions examples/sendmail.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
'use strict';

/* eslint-disable no-console */
const nodemailer = require('nodemailer')
, sparkPostTransport = require('nodemailer-sparkpost-transport')
, transporter = nodemailer.createTransport(sparkPostTransport({
const nodemailer = require('nodemailer');
const sparkPostTransport = require('nodemailer-sparkpost-transport');
const transporter = nodemailer.createTransport(sparkPostTransport({
'sparkPostApiKey': '<YOUR_API_KEY>',
'options': {
'open_tracking': true,
Expand All @@ -19,7 +19,7 @@ transporter.sendMail({
subject: 'Nodemailer + SparkPost = Sheer Awe',
text: 'Plain text email content',
html: '<p>Richly <strong>marked up</strong> email content</p>'
}, function(err, info) {
}, (err, info) => {
if (err) {
console.error(err);
} else {
Expand Down
66 changes: 33 additions & 33 deletions lib/sparkPostTransport.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
'use strict';

// Dependencies
const pkg = require('../package')
, SparkPost = require('sparkpost');
const pkg = require('../package');
const SparkPost = require('sparkpost');

// Constructor
function SparkPostTransport(options) {
Expand All @@ -29,11 +29,11 @@ function SparkPostTransport(options) {
}

function populateCustomFields(message, defaults, request) {
const data = message.data
, customFields = ['campaign_id', 'metadata', 'substitution_data', 'options', 'content', 'recipients'];
const data = message.data;
const customFields = ['campaign_id', 'metadata', 'substitution_data', 'options', 'content', 'recipients'];

// Apply default SP-centric options and override if provided in mail object
customFields.forEach(function(fld) {
customFields.forEach((fld) => {
if (data.hasOwnProperty(fld)) {
request[fld] = data[fld];
} else if (defaults.hasOwnProperty(fld)) {
Expand All @@ -56,25 +56,25 @@ function populateFrom(inreq, outreq) {
}

function populateInlineStdFields(message, resolveme, request) {
const data = message.data
, resolveKeys = ['html', 'text']
, contentFlds = {
'subject': 'subject',
'headers': 'headers',
'replyTo': 'reply_to'
};
const data = message.data;
const resolveKeys = ['html', 'text'];
const contentFlds = {
'subject': 'subject',
'headers': 'headers',
'replyTo': 'reply_to'
};

populateFrom(data, request);

// content fields that get transferred to request
Object.keys(contentFlds).map(function(key) {
Object.keys(contentFlds).map((key) => {
if (data.hasOwnProperty(key)) {
request.content[contentFlds[key]] = data[key];
}
});

// content that gets resloved
resolveKeys.map(function(key) {
resolveKeys.map((key) => {
if (data.hasOwnProperty(key)) {
resolveme[key] = key;
}
Expand All @@ -84,7 +84,7 @@ function populateInlineStdFields(message, resolveme, request) {
if (data.attachments) {
const spAttachments = [];

data.attachments.map(function(att) {
data.attachments.map((att) => {
spAttachments.push({
name: att.filename,
type: att.contentType,
Expand All @@ -111,11 +111,11 @@ function populateRecipients(request, msgData) {
}

SparkPostTransport.prototype.send = function send(message, callback) {
const data = message.data
, request = {
const data = message.data;
const request = {
content: {}
}
, resolveme = {};
};
const resolveme = {};

// Conventional nodemailer fields override SparkPost-specific ones and defaults
populateCustomFields(message, this, request);
Expand All @@ -131,43 +131,43 @@ SparkPostTransport.prototype.send = function send(message, callback) {
this.resolveAndSend(message, resolveme, request, callback);
};

SparkPostTransport.prototype.resolveAndSend = function(mail, toresolve, request, callback) {
const self = this
, keys = Object.keys(toresolve);
// eslint-disable-next-line max-params
SparkPostTransport.prototype.resolveAndSend = function resolveAndSend(mail, toresolve, request, callback) {
const self = this;
const keys = Object.keys(toresolve);

if (keys.length === 0) {
return this.sendWithSparkPost(request, callback);
}

// eslint-disable-next-line one-var
const srckey = keys[0]
, dstkey = toresolve[keys[0]];
const srckey = keys[0];
const dstkey = toresolve[keys[0]];

delete toresolve[srckey];

this.loadContent(mail, srckey, function(err, content) {
this.loadContent(mail, srckey, (err, content) => {
request.content[dstkey] = content;
self.resolveAndSend(mail, toresolve, request, callback);
});
};

SparkPostTransport.prototype.loadContent = function(mail, key, callback) {
SparkPostTransport.prototype.loadContent = function loadContent(mail, key, callback) {
const content = mail.data[key];
if (typeof content === 'string') {
return process.nextTick(function() {
return process.nextTick(() => {
callback(null, content);
});
}
mail.resolveContent(mail.data, key, function(err, res) {
mail.resolveContent(mail.data, key, (err, res) => {
if (err) {
return callback(err);
}
callback(null, res.toString());
});
};

SparkPostTransport.prototype.sendWithSparkPost = function(transBody, callback) {
this.sparkPostEmailClient.transmissions.send(transBody, function(err, res) {
SparkPostTransport.prototype.sendWithSparkPost = function sendWithSparkPost(transBody, callback) {
this.sparkPostEmailClient.transmissions.send(transBody, (err, res) => {
if (err) {
return callback(err);
}
Expand All @@ -187,7 +187,7 @@ function emailList(strOrLst) {
lst = strOrLst.split(',');
}

return lst.map(function(addr) {
return lst.map((addr) => {
if (typeof addr === 'string') {
return {address: addr};
}
Expand All @@ -199,6 +199,6 @@ function emailList(strOrLst) {
});
}

module.exports = function(options) {
module.exports = function exporter(options) {
return new SparkPostTransport(options);
};
Loading

0 comments on commit 79fadcd

Please sign in to comment.