@upyo/mailtrap 0.6.0-dev.311 → 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 +14 -27
- package/dist/index.js +15 -28
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -263,20 +263,20 @@ function parseErrorMessage(text, statusCode) {
|
|
|
263
263
|
function truncateErrorMessage(message) {
|
|
264
264
|
return message.length > maxErrorMessageLength ? `${message.slice(0, maxErrorMessageLength)}...` : message;
|
|
265
265
|
}
|
|
266
|
-
function abortReason
|
|
266
|
+
function abortReason(signal) {
|
|
267
267
|
return signal?.reason ?? new DOMException("The operation was aborted.", "AbortError");
|
|
268
268
|
}
|
|
269
269
|
function sleep(ms, signal) {
|
|
270
270
|
return new Promise((resolve, reject) => {
|
|
271
271
|
if (signal?.aborted) {
|
|
272
|
-
reject(abortReason
|
|
272
|
+
reject(abortReason(signal));
|
|
273
273
|
return;
|
|
274
274
|
}
|
|
275
275
|
const timeoutState = {};
|
|
276
276
|
const onAbort = () => {
|
|
277
277
|
if (timeoutState.id !== void 0) clearTimeout(timeoutState.id);
|
|
278
278
|
signal?.removeEventListener("abort", onAbort);
|
|
279
|
-
reject(abortReason
|
|
279
|
+
reject(abortReason(signal));
|
|
280
280
|
};
|
|
281
281
|
signal?.addEventListener("abort", onAbort, { once: true });
|
|
282
282
|
if (signal?.aborted) {
|
|
@@ -346,7 +346,16 @@ async function convertMessage(message, config, signal) {
|
|
|
346
346
|
}
|
|
347
347
|
for (const [key, value] of message.headers.entries()) if (!isStandardHeader(key)) headers[key] = value;
|
|
348
348
|
if (Object.keys(headers).length > 0) emailData.headers = headers;
|
|
349
|
-
if (message.attachments.length > 0)
|
|
349
|
+
if (message.attachments.length > 0) {
|
|
350
|
+
const cancellation = new AbortController();
|
|
351
|
+
const combined = (0, __upyo_core.combineSignals)(cancellation.signal, signal);
|
|
352
|
+
try {
|
|
353
|
+
emailData.attachments = await Promise.all(message.attachments.map((attachment) => convertAttachment(attachment, combined.signal)));
|
|
354
|
+
} finally {
|
|
355
|
+
cancellation.abort();
|
|
356
|
+
combined.cleanup();
|
|
357
|
+
}
|
|
358
|
+
}
|
|
350
359
|
signal?.throwIfAborted();
|
|
351
360
|
return emailData;
|
|
352
361
|
}
|
|
@@ -368,7 +377,7 @@ function formatAddress(address) {
|
|
|
368
377
|
}
|
|
369
378
|
async function convertAttachment(attachment, signal) {
|
|
370
379
|
signal?.throwIfAborted();
|
|
371
|
-
const contentBytes = await
|
|
380
|
+
const contentBytes = await (0, __upyo_core.readAttachmentContent)(attachment.content, signal);
|
|
372
381
|
signal?.throwIfAborted();
|
|
373
382
|
const converted = {
|
|
374
383
|
content: uint8ArrayToBase64(contentBytes),
|
|
@@ -381,28 +390,6 @@ async function convertAttachment(attachment, signal) {
|
|
|
381
390
|
} else converted.disposition = "attachment";
|
|
382
391
|
return converted;
|
|
383
392
|
}
|
|
384
|
-
function waitForAttachmentContent(content, signal) {
|
|
385
|
-
if (content instanceof Uint8Array) return signal?.aborted ? Promise.reject(abortReason(signal)) : Promise.resolve(content);
|
|
386
|
-
if (signal == null) return content;
|
|
387
|
-
if (signal.aborted) return Promise.reject(abortReason(signal));
|
|
388
|
-
return new Promise((resolve, reject) => {
|
|
389
|
-
const onAbort = () => {
|
|
390
|
-
signal.removeEventListener("abort", onAbort);
|
|
391
|
-
reject(abortReason(signal));
|
|
392
|
-
};
|
|
393
|
-
signal.addEventListener("abort", onAbort, { once: true });
|
|
394
|
-
content.then((value) => {
|
|
395
|
-
signal.removeEventListener("abort", onAbort);
|
|
396
|
-
resolve(value);
|
|
397
|
-
}, (error) => {
|
|
398
|
-
signal.removeEventListener("abort", onAbort);
|
|
399
|
-
reject(error);
|
|
400
|
-
});
|
|
401
|
-
});
|
|
402
|
-
}
|
|
403
|
-
function abortReason(signal) {
|
|
404
|
-
return signal.reason ?? new DOMException("The operation was aborted.", "AbortError");
|
|
405
|
-
}
|
|
406
393
|
function uint8ArrayToBase64(bytes) {
|
|
407
394
|
const nativeToBase64 = getNativeToBase64(bytes);
|
|
408
395
|
if (nativeToBase64 != null) return nativeToBase64();
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { combineSignals, createFailedReceipt } from "@upyo/core";
|
|
1
|
+
import { combineSignals, createFailedReceipt, readAttachmentContent } from "@upyo/core";
|
|
2
2
|
|
|
3
3
|
//#region src/config.ts
|
|
4
4
|
const DEFAULT_SEND_BASE_URL = "https://send.api.mailtrap.io";
|
|
@@ -240,20 +240,20 @@ function parseErrorMessage(text, statusCode) {
|
|
|
240
240
|
function truncateErrorMessage(message) {
|
|
241
241
|
return message.length > maxErrorMessageLength ? `${message.slice(0, maxErrorMessageLength)}...` : message;
|
|
242
242
|
}
|
|
243
|
-
function abortReason
|
|
243
|
+
function abortReason(signal) {
|
|
244
244
|
return signal?.reason ?? new DOMException("The operation was aborted.", "AbortError");
|
|
245
245
|
}
|
|
246
246
|
function sleep(ms, signal) {
|
|
247
247
|
return new Promise((resolve, reject) => {
|
|
248
248
|
if (signal?.aborted) {
|
|
249
|
-
reject(abortReason
|
|
249
|
+
reject(abortReason(signal));
|
|
250
250
|
return;
|
|
251
251
|
}
|
|
252
252
|
const timeoutState = {};
|
|
253
253
|
const onAbort = () => {
|
|
254
254
|
if (timeoutState.id !== void 0) clearTimeout(timeoutState.id);
|
|
255
255
|
signal?.removeEventListener("abort", onAbort);
|
|
256
|
-
reject(abortReason
|
|
256
|
+
reject(abortReason(signal));
|
|
257
257
|
};
|
|
258
258
|
signal?.addEventListener("abort", onAbort, { once: true });
|
|
259
259
|
if (signal?.aborted) {
|
|
@@ -323,7 +323,16 @@ async function convertMessage(message, config, signal) {
|
|
|
323
323
|
}
|
|
324
324
|
for (const [key, value] of message.headers.entries()) if (!isStandardHeader(key)) headers[key] = value;
|
|
325
325
|
if (Object.keys(headers).length > 0) emailData.headers = headers;
|
|
326
|
-
if (message.attachments.length > 0)
|
|
326
|
+
if (message.attachments.length > 0) {
|
|
327
|
+
const cancellation = new AbortController();
|
|
328
|
+
const combined = combineSignals(cancellation.signal, signal);
|
|
329
|
+
try {
|
|
330
|
+
emailData.attachments = await Promise.all(message.attachments.map((attachment) => convertAttachment(attachment, combined.signal)));
|
|
331
|
+
} finally {
|
|
332
|
+
cancellation.abort();
|
|
333
|
+
combined.cleanup();
|
|
334
|
+
}
|
|
335
|
+
}
|
|
327
336
|
signal?.throwIfAborted();
|
|
328
337
|
return emailData;
|
|
329
338
|
}
|
|
@@ -345,7 +354,7 @@ function formatAddress(address) {
|
|
|
345
354
|
}
|
|
346
355
|
async function convertAttachment(attachment, signal) {
|
|
347
356
|
signal?.throwIfAborted();
|
|
348
|
-
const contentBytes = await
|
|
357
|
+
const contentBytes = await readAttachmentContent(attachment.content, signal);
|
|
349
358
|
signal?.throwIfAborted();
|
|
350
359
|
const converted = {
|
|
351
360
|
content: uint8ArrayToBase64(contentBytes),
|
|
@@ -358,28 +367,6 @@ async function convertAttachment(attachment, signal) {
|
|
|
358
367
|
} else converted.disposition = "attachment";
|
|
359
368
|
return converted;
|
|
360
369
|
}
|
|
361
|
-
function waitForAttachmentContent(content, signal) {
|
|
362
|
-
if (content instanceof Uint8Array) return signal?.aborted ? Promise.reject(abortReason(signal)) : Promise.resolve(content);
|
|
363
|
-
if (signal == null) return content;
|
|
364
|
-
if (signal.aborted) return Promise.reject(abortReason(signal));
|
|
365
|
-
return new Promise((resolve, reject) => {
|
|
366
|
-
const onAbort = () => {
|
|
367
|
-
signal.removeEventListener("abort", onAbort);
|
|
368
|
-
reject(abortReason(signal));
|
|
369
|
-
};
|
|
370
|
-
signal.addEventListener("abort", onAbort, { once: true });
|
|
371
|
-
content.then((value) => {
|
|
372
|
-
signal.removeEventListener("abort", onAbort);
|
|
373
|
-
resolve(value);
|
|
374
|
-
}, (error) => {
|
|
375
|
-
signal.removeEventListener("abort", onAbort);
|
|
376
|
-
reject(error);
|
|
377
|
-
});
|
|
378
|
-
});
|
|
379
|
-
}
|
|
380
|
-
function abortReason(signal) {
|
|
381
|
-
return signal.reason ?? new DOMException("The operation was aborted.", "AbortError");
|
|
382
|
-
}
|
|
383
370
|
function uint8ArrayToBase64(bytes) {
|
|
384
371
|
const nativeToBase64 = getNativeToBase64(bytes);
|
|
385
372
|
if (nativeToBase64 != null) return nativeToBase64();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@upyo/mailtrap",
|
|
3
|
-
"version": "0.6.0-dev.
|
|
3
|
+
"version": "0.6.0-dev.312",
|
|
4
4
|
"description": "Mailtrap 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",
|