idea-toolbox
Advanced tools
Comparing version 0.8.7 to 0.8.8
44
index.js
@@ -148,12 +148,12 @@ 'use strict'; | ||
function IUID(dynamo, project, cb, attempt, maxAttempts) { | ||
if(!project) return cb(false); | ||
if(!project) return cb(false); | ||
attempt = attempt || 0; | ||
maxAttempts = maxAttempts || 3; | ||
if(attempt > maxAttempts) return cb(false); | ||
if(attempt > maxAttempts) return cb(false); | ||
let id = UUIDV4(); | ||
dynamo.getItem({ TableName: 'idea_IUID', Key: { project: project, id: id } }, | ||
dynamo.getItem({ TableName: 'idea_IUID', Key: { project: project, id: id } }, | ||
(err, data) => { | ||
if(data && data.Item) | ||
if(data && data.Item) | ||
return IUID(dynamo, project, cb, attempt+1, maxAttempts); // ID exists, try again | ||
else dynamo.putItem({ TableName: 'idea_IUID', Item: { project: project, id: id } }, | ||
else dynamo.putItem({ TableName: 'idea_IUID', Item: { project: project, id: id } }, | ||
(err, data) => { | ||
@@ -246,3 +246,3 @@ if(err) cb(false); | ||
* @param {*} emailData | ||
* toAddresses: Array<string>, ccAddresses?: Array<string>, bccAddresses?: Array<string>, | ||
* toAddresses: Array<string>, ccAddresses?: Array<string>, bccAddresses?: Array<string>, | ||
* replyToAddresses: Array<string>, subject: string, html?: string, text?: string, | ||
@@ -275,20 +275,20 @@ * attachments?: Array<any> (https://community.nodemailer.com/using-attachments/) | ||
sesData.SourceArn = sesParams.sourceArn; | ||
var ses = new AWS.SES({ region: sesParams.region }); | ||
sesData.Region = sesParams.region; | ||
// send email | ||
if(emailData.attachments && emailData.attachments.length) { | ||
// including attachments, through Nodemailer | ||
console.log('SES send email w/ attachments (Nodemailer)', | ||
console.log('SES send email w/ attachments (Nodemailer)', | ||
sesParams, sesData, emailData.attachments); | ||
sesSendEmailThroughNodemailer(ses, sesData, emailData.attachments, cb); | ||
sesSendEmailThroughNodemailer(sesData, emailData.attachments, cb); | ||
} else { | ||
// classic way, through SES | ||
console.log('SES send email', sesParams, sesData); | ||
ses.sendEmail(sesData, (err, data) => { cb(err, data); }); | ||
new AWS.SES({ region: sesData.Region }).sendEmail(sesData, (err, data) => { cb(err, data); }); | ||
} | ||
} | ||
/** | ||
* Helper function to send an email with attachments through Nodemailer; | ||
* SES only support attachments through a raw sending. | ||
* Helper function to send an email with attachments through Nodemailer; | ||
* SES only supports attachments through a raw sending. | ||
*/ | ||
function sesSendEmailThroughNodemailer(ses, sesData, attachments, cb) { | ||
function sesSendEmailThroughNodemailer(sesData, attachments, cb) { | ||
// set the mail options in Nodemailer's format | ||
@@ -300,10 +300,10 @@ let mailOptions = {}; | ||
if(sesData.Message.Body.bcc) mailOptions.bcc = sesData.Destination.BccAddresses.join(','); | ||
if(sesData.Message.Body.ReplyToAddresses) | ||
if(sesData.Message.Body.ReplyToAddresses) | ||
mailOptions.replyTo = sesData.ReplyToAddresses.join(','); | ||
mailOptions.subject = sesData.Message.Subject; | ||
if(sesData.Message.Body.Html) mailOptions.html = sesData.Message.Body.Html; | ||
if(sesData.Message.Body.Text) mailOptions.text = sesData.Message.Body.Text; | ||
mailOptions.subject = sesData.Message.Subject.Data; | ||
if(sesData.Message.Body.Html) mailOptions.html = sesData.Message.Body.Html.Data; | ||
if(sesData.Message.Body.Text) mailOptions.text = sesData.Message.Body.Text.Data; | ||
mailOptions.attachments = attachments; | ||
// create Nodemailer SES transporter | ||
let transporter = Nodemailer.createTransport({ SES: ses }); | ||
let transporter = Nodemailer.createTransport({ SES: new AWS.SES({ region: sesData.Region }) }); | ||
// send the email | ||
@@ -319,3 +319,3 @@ transporter.sendMail(mailOptions, (err, data) => { cb(err, data); }); | ||
* Download a file through an S3 signed url. | ||
* *Pratically*, it uploads the file on an S3 bucket (w/ automatic cleaning), | ||
* *Pratically*, it uploads the file on an S3 bucket (w/ automatic cleaning), | ||
* it generates a signed url, returning it. | ||
@@ -334,3 +334,3 @@ * @param {*} prefix a folder in which to put all the files of the same kind | ||
secToExp = secToExp || S3_DEFAULT_DOWNLOAD_BUCKET_SEC_TO_EXP; | ||
S3.upload({ Bucket: bucket, Key: key, Body: dataToUpload, ContentType: contentType }, | ||
S3.upload({ Bucket: bucket, Key: key, Body: dataToUpload, ContentType: contentType }, | ||
(err, data) => { | ||
@@ -362,3 +362,3 @@ console.log('Uploading file on S3...', err, data); | ||
* @param {*} str the string to clean | ||
* @param {*} separator separator char | ||
* @param {*} separator separator char | ||
*/ | ||
@@ -370,3 +370,3 @@ function cleanStr(str, separator) { | ||
/** | ||
* Join two arrays by a common column, selecting which data to extract. | ||
* Join two arrays by a common column, selecting which data to extract. | ||
* @param {Array<any>} mainTable the main array | ||
@@ -373,0 +373,0 @@ * @param {Array<any>} lookupTable the lookup array |
{ | ||
"name": "idea-toolbox", | ||
"version": "0.8.7", | ||
"version": "0.8.8", | ||
"description": "IDEA's utility functions", | ||
@@ -5,0 +5,0 @@ "engines": { |
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
18676