mail-time
Advanced tools
Comparing version 1.2.1 to 1.2.2
154
index.js
@@ -20,2 +20,8 @@ const JoSk = require('josk'); | ||
const defaultWriteConcern = { | ||
w: 1, | ||
j: true, | ||
wtimeout: 10240 | ||
}; | ||
let equals; | ||
@@ -115,5 +121,5 @@ equals = (a, b) => { | ||
this.revolvingInterval = opts.revolvingInterval || 256; | ||
this.minRevolvingDelay = opts.minRevolvingDelay || 64; | ||
this.maxRevolvingDelay = opts.maxRevolvingDelay || 512; | ||
this.revolvingInterval = opts.revolvingInterval || 1536; | ||
this.minRevolvingDelay = opts.minRevolvingDelay || 512; | ||
this.maxRevolvingDelay = opts.maxRevolvingDelay || 2048; | ||
@@ -279,3 +285,4 @@ if (this.interval < 2048 || isNaN(this.interval)) { | ||
___send(ready) { | ||
this.collection.findOneAndUpdate({ | ||
let finished = 0; | ||
const cursor = this.collection.find({ | ||
$or: [{ | ||
@@ -299,11 +306,2 @@ isSent: false, | ||
}, { | ||
$set: { | ||
isSent: true, | ||
sendAt: new Date(Date.now() + (this.zombieTime * 2)) | ||
}, | ||
$inc: { | ||
tries: 1 | ||
} | ||
}, { | ||
returnOriginal: false, | ||
projection: { | ||
@@ -317,70 +315,90 @@ _id: 1, | ||
} | ||
}, (findUpdateError, result) => { | ||
process.nextTick(() => { | ||
}); | ||
cursor.count((countError, count) => { | ||
if (countError) { | ||
ready(); | ||
}); | ||
const task = (result !== null && typeof result === 'object') ? result.value : null; | ||
if (findUpdateError) { | ||
this.___handleError(task, findUpdateError, {}); | ||
_logError('[___send] [count] [countError]', countError); | ||
return; | ||
} | ||
if (!task) { | ||
return; | ||
} | ||
if (count) { | ||
cursor.forEach((task) => { | ||
this.collection.updateOne({ | ||
_id: task._id | ||
}, { | ||
$set: { | ||
isSent: true, | ||
sendAt: new Date(Date.now() + (this.zombieTime * 2)) | ||
}, | ||
$inc: { | ||
tries: 1 | ||
} | ||
}, defaultWriteConcern, (updateError) => { | ||
if (count === ++finished) { | ||
ready(); | ||
} | ||
process.nextTick(() => { | ||
let transport; | ||
let transportIndex; | ||
if (this.strategy === 'balancer') { | ||
this.transport = this.transport + 1; | ||
if (this.transport >= this.transports.length) { | ||
this.transport = 0; | ||
} | ||
transportIndex = this.transport; | ||
transport = this.transports[this.transport]; | ||
} else { | ||
transportIndex = task.transport; | ||
transport = this.transports[task.transport]; | ||
} | ||
if (updateError) { | ||
this.___handleError(task, updateError, {}); | ||
} else { | ||
let transport; | ||
let transportIndex; | ||
if (this.strategy === 'balancer') { | ||
this.transport = this.transport + 1; | ||
if (this.transport >= this.transports.length) { | ||
this.transport = 0; | ||
} | ||
transportIndex = this.transport; | ||
transport = this.transports[this.transport]; | ||
} else { | ||
transportIndex = task.transport; | ||
transport = this.transports[task.transport]; | ||
} | ||
try { | ||
const _mailOpts = this.___compileMailOpts(transport, task); | ||
try { | ||
const _mailOpts = this.___compileMailOpts(transport, task); | ||
_debug(this.debug, '[sendMail] [sending] To:', _mailOpts.to); | ||
transport.sendMail(_mailOpts, (error, info) => { | ||
if (error) { | ||
this.___handleError(task, error, info); | ||
return; | ||
} | ||
_debug(this.debug, '[sendMail] [sending] To:', _mailOpts.to); | ||
transport.sendMail(_mailOpts, (error, info) => { | ||
if (error) { | ||
this.___handleError(task, error, info); | ||
return; | ||
} | ||
if (info.accepted && !info.accepted.length) { | ||
this.___handleError(task, 'Message not accepted or Greeting never received', info); | ||
return; | ||
} | ||
if (info.accepted && !info.accepted.length) { | ||
this.___handleError(task, 'Message not accepted or Greeting never received', info); | ||
return; | ||
} | ||
this.collection.deleteOne({ | ||
_id: task._id | ||
}, () => { | ||
_debug(this.debug, `email successfully sent, attempts: #${task.tries}, transport #${transportIndex} to: `, _mailOpts.to); | ||
this.collection.deleteOne({ | ||
_id: task._id | ||
}, defaultWriteConcern, () => { | ||
_debug(this.debug, `email successfully sent, attempts: #${task.tries}, transport #${transportIndex} to: `, _mailOpts.to); | ||
const _id = task._id.toHexString(); | ||
if (this.callbacks[_id] && this.callbacks[_id].length) { | ||
this.callbacks[_id].forEach((cb, i) => { | ||
cb(void 0, info, task.mailOptions[i]); | ||
const _id = task._id.toHexString(); | ||
if (this.callbacks[_id] && this.callbacks[_id].length) { | ||
this.callbacks[_id].forEach((cb, i) => { | ||
cb(void 0, info, task.mailOptions[i]); | ||
}); | ||
} | ||
delete this.callbacks[_id]; | ||
}); | ||
return; | ||
}); | ||
} catch (e) { | ||
_logError('Exception during runtime:', e); | ||
this.___handleError(task, e, {}); | ||
} | ||
delete this.callbacks[_id]; | ||
}); | ||
return; | ||
} | ||
}); | ||
} catch (e) { | ||
_logError('Exception during runtime:', e); | ||
this.___handleError(task, e, {}); | ||
} | ||
}); | ||
return; | ||
}, (forEachError) => { | ||
if (forEachError) { | ||
_logError('[___send] [forEach] [forEachError]', forEachError); | ||
} | ||
}); | ||
} else { | ||
ready(); | ||
} | ||
}); | ||
@@ -387,0 +405,0 @@ } |
{ | ||
"name": "mail-time", | ||
"version": "1.2.1", | ||
"version": "1.2.2", | ||
"description": "Bulletproof email queue on top of NodeMailer with support of multiple clusters and servers setup", | ||
@@ -51,4 +51,4 @@ "main": "index.js", | ||
"dependencies": { | ||
"deepmerge": "^4.1.1", | ||
"josk": "^2.2.0" | ||
"deepmerge": "^4.2.2", | ||
"josk": "^2.2.2" | ||
}, | ||
@@ -60,3 +60,3 @@ "devDependencies": { | ||
"mocha": "^6.2.2", | ||
"mongodb": "^3.3.3", | ||
"mongodb": "^3.3.5", | ||
"nodemailer": "^6.3.1", | ||
@@ -63,0 +63,0 @@ "nodemailer-direct-transport": "^3.3.2" |
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 3 instances in 1 package
1
43420
6
569
Updateddeepmerge@^4.2.2
Updatedjosk@^2.2.2