@upyo/sendgrid 0.6.0-dev.311 → 0.6.0-dev.314
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +17 -6
- package/dist/index.js +18 -7
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -244,7 +244,7 @@ function createAbortError(signal) {
|
|
|
244
244
|
* const response = await httpClient.sendMessage(mailData);
|
|
245
245
|
* ```
|
|
246
246
|
*/
|
|
247
|
-
async function convertMessage(message, config) {
|
|
247
|
+
async function convertMessage(message, config, signal) {
|
|
248
248
|
const sendGridMail = {
|
|
249
249
|
personalizations: [],
|
|
250
250
|
from: formatAddress(message.sender)
|
|
@@ -299,7 +299,16 @@ async function convertMessage(message, config) {
|
|
|
299
299
|
...sendGridMail.headers,
|
|
300
300
|
...customHeaders
|
|
301
301
|
};
|
|
302
|
-
if (message.attachments.length > 0)
|
|
302
|
+
if (message.attachments.length > 0) {
|
|
303
|
+
const cancellation = new AbortController();
|
|
304
|
+
const combined = (0, __upyo_core.combineSignals)(cancellation.signal, signal);
|
|
305
|
+
try {
|
|
306
|
+
sendGridMail.attachments = await Promise.all(message.attachments.map((attachment) => convertAttachment(attachment, combined.signal)));
|
|
307
|
+
} finally {
|
|
308
|
+
cancellation.abort();
|
|
309
|
+
combined.cleanup();
|
|
310
|
+
}
|
|
311
|
+
}
|
|
303
312
|
const trackingSettings = {};
|
|
304
313
|
if (config.clickTracking !== void 0) trackingSettings.click_tracking = {
|
|
305
314
|
enable: config.clickTracking,
|
|
@@ -328,9 +337,11 @@ function formatAddress(address) {
|
|
|
328
337
|
* @param attachment - The attachment to convert
|
|
329
338
|
* @returns Promise that resolves to a SendGrid attachment object
|
|
330
339
|
*/
|
|
331
|
-
async function convertAttachment(attachment) {
|
|
332
|
-
const contentBytes = await attachment.content;
|
|
333
|
-
const
|
|
340
|
+
async function convertAttachment(attachment, signal) {
|
|
341
|
+
const contentBytes = await (0, __upyo_core.readAttachmentContent)(attachment.content, signal);
|
|
342
|
+
const parts = [];
|
|
343
|
+
for (let offset = 0; offset < contentBytes.length; offset += 8192) parts.push(String.fromCharCode(...contentBytes.subarray(offset, offset + 8192)));
|
|
344
|
+
const base64Content = btoa(parts.join(""));
|
|
334
345
|
const sendGridAttachment = {
|
|
335
346
|
content: base64Content,
|
|
336
347
|
filename: attachment.filename
|
|
@@ -446,7 +457,7 @@ var SendGridTransport = class {
|
|
|
446
457
|
async send(message, options) {
|
|
447
458
|
options?.signal?.throwIfAborted();
|
|
448
459
|
try {
|
|
449
|
-
const mailData = await convertMessage(message, this.config);
|
|
460
|
+
const mailData = await convertMessage(message, this.config, options?.signal);
|
|
450
461
|
options?.signal?.throwIfAborted();
|
|
451
462
|
const response = await this.httpClient.sendMessage(mailData, options?.signal);
|
|
452
463
|
const messageId = this.extractMessageId(response);
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { combineSignals, createFailedReceipt, parseRetryAfter } from "@upyo/core";
|
|
1
|
+
import { combineSignals, createFailedReceipt, parseRetryAfter, readAttachmentContent } from "@upyo/core";
|
|
2
2
|
|
|
3
3
|
//#region src/config.ts
|
|
4
4
|
/**
|
|
@@ -221,7 +221,7 @@ function createAbortError(signal) {
|
|
|
221
221
|
* const response = await httpClient.sendMessage(mailData);
|
|
222
222
|
* ```
|
|
223
223
|
*/
|
|
224
|
-
async function convertMessage(message, config) {
|
|
224
|
+
async function convertMessage(message, config, signal) {
|
|
225
225
|
const sendGridMail = {
|
|
226
226
|
personalizations: [],
|
|
227
227
|
from: formatAddress(message.sender)
|
|
@@ -276,7 +276,16 @@ async function convertMessage(message, config) {
|
|
|
276
276
|
...sendGridMail.headers,
|
|
277
277
|
...customHeaders
|
|
278
278
|
};
|
|
279
|
-
if (message.attachments.length > 0)
|
|
279
|
+
if (message.attachments.length > 0) {
|
|
280
|
+
const cancellation = new AbortController();
|
|
281
|
+
const combined = combineSignals(cancellation.signal, signal);
|
|
282
|
+
try {
|
|
283
|
+
sendGridMail.attachments = await Promise.all(message.attachments.map((attachment) => convertAttachment(attachment, combined.signal)));
|
|
284
|
+
} finally {
|
|
285
|
+
cancellation.abort();
|
|
286
|
+
combined.cleanup();
|
|
287
|
+
}
|
|
288
|
+
}
|
|
280
289
|
const trackingSettings = {};
|
|
281
290
|
if (config.clickTracking !== void 0) trackingSettings.click_tracking = {
|
|
282
291
|
enable: config.clickTracking,
|
|
@@ -305,9 +314,11 @@ function formatAddress(address) {
|
|
|
305
314
|
* @param attachment - The attachment to convert
|
|
306
315
|
* @returns Promise that resolves to a SendGrid attachment object
|
|
307
316
|
*/
|
|
308
|
-
async function convertAttachment(attachment) {
|
|
309
|
-
const contentBytes = await attachment.content;
|
|
310
|
-
const
|
|
317
|
+
async function convertAttachment(attachment, signal) {
|
|
318
|
+
const contentBytes = await readAttachmentContent(attachment.content, signal);
|
|
319
|
+
const parts = [];
|
|
320
|
+
for (let offset = 0; offset < contentBytes.length; offset += 8192) parts.push(String.fromCharCode(...contentBytes.subarray(offset, offset + 8192)));
|
|
321
|
+
const base64Content = btoa(parts.join(""));
|
|
311
322
|
const sendGridAttachment = {
|
|
312
323
|
content: base64Content,
|
|
313
324
|
filename: attachment.filename
|
|
@@ -423,7 +434,7 @@ var SendGridTransport = class {
|
|
|
423
434
|
async send(message, options) {
|
|
424
435
|
options?.signal?.throwIfAborted();
|
|
425
436
|
try {
|
|
426
|
-
const mailData = await convertMessage(message, this.config);
|
|
437
|
+
const mailData = await convertMessage(message, this.config, options?.signal);
|
|
427
438
|
options?.signal?.throwIfAborted();
|
|
428
439
|
const response = await this.httpClient.sendMessage(mailData, options?.signal);
|
|
429
440
|
const messageId = this.extractMessageId(response);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@upyo/sendgrid",
|
|
3
|
-
"version": "0.6.0-dev.
|
|
3
|
+
"version": "0.6.0-dev.314",
|
|
4
4
|
"description": "SendGrid transport for Upyo email library",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"email",
|
|
@@ -53,7 +53,7 @@
|
|
|
53
53
|
},
|
|
54
54
|
"sideEffects": false,
|
|
55
55
|
"peerDependencies": {
|
|
56
|
-
"@upyo/core": "0.6.0-dev.
|
|
56
|
+
"@upyo/core": "0.6.0-dev.314+70a7c9c7"
|
|
57
57
|
},
|
|
58
58
|
"devDependencies": {
|
|
59
59
|
"tsdown": "^0.12.7",
|