@upyo/lettermint 0.6.0-dev.309 → 0.6.0-dev.312
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 +16 -6
- package/dist/index.js +17 -7
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -263,7 +263,7 @@ const STANDARD_HEADERS = new Set([
|
|
|
263
263
|
* @throws {RangeError} If the message has more than one tag.
|
|
264
264
|
* @since 0.5.0
|
|
265
265
|
*/
|
|
266
|
-
async function convertMessage(message, config) {
|
|
266
|
+
async function convertMessage(message, config, signal) {
|
|
267
267
|
if (message.tags.length > 1) throw new RangeError("Lettermint supports at most one tag per message.");
|
|
268
268
|
const emailData = {
|
|
269
269
|
from: formatAddress(message.sender),
|
|
@@ -294,7 +294,16 @@ async function convertMessage(message, config) {
|
|
|
294
294
|
}
|
|
295
295
|
for (const [key, value] of message.headers.entries()) if (!isStandardHeader(key)) headers[key] = value;
|
|
296
296
|
if (Object.keys(headers).length > 0) emailData.headers = headers;
|
|
297
|
-
if (message.attachments.length > 0)
|
|
297
|
+
if (message.attachments.length > 0) {
|
|
298
|
+
const cancellation = new AbortController();
|
|
299
|
+
const combined = (0, __upyo_core.combineSignals)(cancellation.signal, signal);
|
|
300
|
+
try {
|
|
301
|
+
emailData.attachments = await Promise.all(message.attachments.map((attachment) => convertAttachment(attachment, combined.signal)));
|
|
302
|
+
} finally {
|
|
303
|
+
cancellation.abort();
|
|
304
|
+
combined.cleanup();
|
|
305
|
+
}
|
|
306
|
+
}
|
|
298
307
|
return emailData;
|
|
299
308
|
}
|
|
300
309
|
function convertSettings(config) {
|
|
@@ -311,8 +320,8 @@ function formatAddress(address) {
|
|
|
311
320
|
}
|
|
312
321
|
return address.address;
|
|
313
322
|
}
|
|
314
|
-
async function convertAttachment(attachment) {
|
|
315
|
-
const content = await attachment.content;
|
|
323
|
+
async function convertAttachment(attachment, signal) {
|
|
324
|
+
const content = await (0, __upyo_core.readAttachmentContent)(attachment.content, signal);
|
|
316
325
|
const converted = {
|
|
317
326
|
filename: attachment.filename,
|
|
318
327
|
content: uint8ArrayToBase64(content),
|
|
@@ -399,7 +408,7 @@ var LettermintTransport = class {
|
|
|
399
408
|
async send(message, options) {
|
|
400
409
|
try {
|
|
401
410
|
options?.signal?.throwIfAborted();
|
|
402
|
-
const emailData = await convertMessage(message, this.config);
|
|
411
|
+
const emailData = await convertMessage(message, this.config, options?.signal);
|
|
403
412
|
const idempotencyKey = normalizeIdempotencyKey(message.idempotencyKey);
|
|
404
413
|
options?.signal?.throwIfAborted();
|
|
405
414
|
const response = await this.httpClient.sendMessage(emailData, options?.signal, idempotencyKey);
|
|
@@ -441,9 +450,10 @@ var LettermintTransport = class {
|
|
|
441
450
|
const batchData = [];
|
|
442
451
|
const receipts = [];
|
|
443
452
|
for (const message of messages) try {
|
|
444
|
-
batchData.push(await convertMessage(message, this.config));
|
|
453
|
+
batchData.push(await convertMessage(message, this.config, options?.signal));
|
|
445
454
|
receipts.push(void 0);
|
|
446
455
|
} catch (error) {
|
|
456
|
+
if (isCallerAbort(error, options?.signal)) throw error;
|
|
447
457
|
receipts.push(createLettermintFailure(error instanceof Error ? error.message : String(error), error));
|
|
448
458
|
}
|
|
449
459
|
if (batchData.length === 0) {
|
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
|
/**
|
|
@@ -240,7 +240,7 @@ const STANDARD_HEADERS = new Set([
|
|
|
240
240
|
* @throws {RangeError} If the message has more than one tag.
|
|
241
241
|
* @since 0.5.0
|
|
242
242
|
*/
|
|
243
|
-
async function convertMessage(message, config) {
|
|
243
|
+
async function convertMessage(message, config, signal) {
|
|
244
244
|
if (message.tags.length > 1) throw new RangeError("Lettermint supports at most one tag per message.");
|
|
245
245
|
const emailData = {
|
|
246
246
|
from: formatAddress(message.sender),
|
|
@@ -271,7 +271,16 @@ async function convertMessage(message, config) {
|
|
|
271
271
|
}
|
|
272
272
|
for (const [key, value] of message.headers.entries()) if (!isStandardHeader(key)) headers[key] = value;
|
|
273
273
|
if (Object.keys(headers).length > 0) emailData.headers = headers;
|
|
274
|
-
if (message.attachments.length > 0)
|
|
274
|
+
if (message.attachments.length > 0) {
|
|
275
|
+
const cancellation = new AbortController();
|
|
276
|
+
const combined = combineSignals(cancellation.signal, signal);
|
|
277
|
+
try {
|
|
278
|
+
emailData.attachments = await Promise.all(message.attachments.map((attachment) => convertAttachment(attachment, combined.signal)));
|
|
279
|
+
} finally {
|
|
280
|
+
cancellation.abort();
|
|
281
|
+
combined.cleanup();
|
|
282
|
+
}
|
|
283
|
+
}
|
|
275
284
|
return emailData;
|
|
276
285
|
}
|
|
277
286
|
function convertSettings(config) {
|
|
@@ -288,8 +297,8 @@ function formatAddress(address) {
|
|
|
288
297
|
}
|
|
289
298
|
return address.address;
|
|
290
299
|
}
|
|
291
|
-
async function convertAttachment(attachment) {
|
|
292
|
-
const content = await attachment.content;
|
|
300
|
+
async function convertAttachment(attachment, signal) {
|
|
301
|
+
const content = await readAttachmentContent(attachment.content, signal);
|
|
293
302
|
const converted = {
|
|
294
303
|
filename: attachment.filename,
|
|
295
304
|
content: uint8ArrayToBase64(content),
|
|
@@ -376,7 +385,7 @@ var LettermintTransport = class {
|
|
|
376
385
|
async send(message, options) {
|
|
377
386
|
try {
|
|
378
387
|
options?.signal?.throwIfAborted();
|
|
379
|
-
const emailData = await convertMessage(message, this.config);
|
|
388
|
+
const emailData = await convertMessage(message, this.config, options?.signal);
|
|
380
389
|
const idempotencyKey = normalizeIdempotencyKey(message.idempotencyKey);
|
|
381
390
|
options?.signal?.throwIfAborted();
|
|
382
391
|
const response = await this.httpClient.sendMessage(emailData, options?.signal, idempotencyKey);
|
|
@@ -418,9 +427,10 @@ var LettermintTransport = class {
|
|
|
418
427
|
const batchData = [];
|
|
419
428
|
const receipts = [];
|
|
420
429
|
for (const message of messages) try {
|
|
421
|
-
batchData.push(await convertMessage(message, this.config));
|
|
430
|
+
batchData.push(await convertMessage(message, this.config, options?.signal));
|
|
422
431
|
receipts.push(void 0);
|
|
423
432
|
} catch (error) {
|
|
433
|
+
if (isCallerAbort(error, options?.signal)) throw error;
|
|
424
434
|
receipts.push(createLettermintFailure(error instanceof Error ? error.message : String(error), error));
|
|
425
435
|
}
|
|
426
436
|
if (batchData.length === 0) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@upyo/lettermint",
|
|
3
|
-
"version": "0.6.0-dev.
|
|
3
|
+
"version": "0.6.0-dev.312",
|
|
4
4
|
"description": "Lettermint 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.312+646e2370"
|
|
57
57
|
},
|
|
58
58
|
"devDependencies": {
|
|
59
59
|
"tsdown": "^0.12.7",
|