@tellimer/mailer
Advanced tools
Comparing version 1.0.1 to 1.0.2
@@ -29,2 +29,3 @@ "use strict"; | ||
const POOL_LIMIT = 10; | ||
const BATCH_SIZE = parseInt(process.env.SENDGRID_BATCH_SIZE || '1000'); | ||
function isPersonalizationList(x) { | ||
@@ -142,12 +143,15 @@ return typeof x[0] !== 'string'; | ||
const personalizations = [...data.personalizations]; | ||
const senders = []; | ||
const sendgridData = []; | ||
while (personalizations.length > 0) { | ||
data.personalizations = personalizations.splice(0, 1000); | ||
// data.mailSettings = { sandboxMode: { enable: true } } | ||
// console.log(JSON.stringify(data, undefined, 2)) | ||
sendgridData.push(data); | ||
const _data = Object.assign({}, data); | ||
_data.personalizations = personalizations.splice(0, BATCH_SIZE); | ||
sendgridData.push(_data); | ||
} | ||
const senders = []; | ||
try { | ||
for (var _b = __asyncValues((0, tiny_async_pool_1.default)(POOL_LIMIT, sendgridData, mail_1.default.send)), _c; _c = yield _b.next(), !_c.done;) { | ||
for (var _b = __asyncValues((0, tiny_async_pool_1.default)(POOL_LIMIT, sendgridData, d => { | ||
var _a; | ||
console.log(`Sending batch of ${(_a = d.personalizations) === null || _a === void 0 ? void 0 : _a.length} emails.`); | ||
return mail_1.default.send(d); | ||
})), _c; _c = yield _b.next(), !_c.done;) { | ||
const value = _c.value; | ||
@@ -154,0 +158,0 @@ senders.push(value); |
{ | ||
"name": "@tellimer/mailer", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"license": "MIT", | ||
@@ -8,3 +8,4 @@ "main": "dist/index.js", | ||
"scripts": { | ||
"test": "ts-mocha --paths './__tests__/**/*.test.ts' --exit", | ||
"test": "ts-mocha --paths './__tests__/**/*.unit.test.ts' --exit", | ||
"test:integration": "ts-mocha --paths './__tests__/**/*.integration.test.ts' --exit", | ||
"build": "rm -rf ./dist && tsc -p tsconfig.json", | ||
@@ -18,3 +19,3 @@ "lint": "eslint src --fix", | ||
"dependencies": { | ||
"@tellimer/mailable": "workspace:@tellimer/mailable@*", | ||
"@tellimer/mailable": "workspace:^", | ||
"tiny-async-pool": "^2.0.1" | ||
@@ -21,0 +22,0 @@ }, |
@@ -14,2 +14,3 @@ import sendgrid from '@sendgrid/mail' | ||
const POOL_LIMIT = 10 | ||
const BATCH_SIZE = parseInt(process.env.SENDGRID_BATCH_SIZE || '1000') | ||
@@ -164,14 +165,17 @@ export type Person = string | PersonObj | ||
const personalizations = [...data.personalizations] | ||
const senders: [sendgrid.ClientResponse, Record<any, any>][] = [] | ||
const sendgridData = [] | ||
const sendgridData: sendgrid.MailDataRequired[] = [] | ||
while (personalizations.length > 0) { | ||
data.personalizations = personalizations.splice(0, 1000) | ||
// data.mailSettings = { sandboxMode: { enable: true } } | ||
// console.log(JSON.stringify(data, undefined, 2)) | ||
sendgridData.push(data) | ||
const _data = { | ||
...data, | ||
} | ||
_data.personalizations = personalizations.splice(0, BATCH_SIZE) | ||
sendgridData.push(_data) | ||
} | ||
for await (const value of asyncPool(POOL_LIMIT, sendgridData, sendgrid.send)) { | ||
const senders: [sendgrid.ClientResponse, Record<any, any>][] = [] | ||
for await (const value of asyncPool(POOL_LIMIT, sendgridData, d => { | ||
console.log(`Sending batch of ${d.personalizations?.length} emails.`) | ||
return sendgrid.send(d) | ||
})) { | ||
senders.push(value) | ||
@@ -178,0 +182,0 @@ } |
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
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
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
GitHub dependency
Supply chain riskContains a dependency which resolves to a GitHub URL. Dependencies fetched from GitHub specifiers are not immutable can be used to inject untrusted code or reduce the likelihood of a reproducible install.
Found 1 instance in 1 package
30
1010
0
635290
2