@upyo/resend 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 +18 -6
- package/dist/index.js +19 -7
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -249,7 +249,16 @@ async function convertMessage(message, _config, options = {}) {
|
|
|
249
249
|
emailData.html = message.content.html;
|
|
250
250
|
if (message.content.text) emailData.text = message.content.text;
|
|
251
251
|
} else emailData.text = message.content.text;
|
|
252
|
-
if (message.attachments.length > 0)
|
|
252
|
+
if (message.attachments.length > 0) {
|
|
253
|
+
const cancellation = new AbortController();
|
|
254
|
+
const combined = (0, __upyo_core.combineSignals)(cancellation.signal, options.signal);
|
|
255
|
+
try {
|
|
256
|
+
emailData.attachments = await Promise.all(message.attachments.map((attachment) => convertAttachment(attachment, combined.signal)));
|
|
257
|
+
} finally {
|
|
258
|
+
cancellation.abort();
|
|
259
|
+
combined.cleanup();
|
|
260
|
+
}
|
|
261
|
+
}
|
|
253
262
|
if (message.tags.length > 0) emailData.tags = message.tags.map((tag, index) => ({
|
|
254
263
|
name: `tag${index + 1}`,
|
|
255
264
|
value: tag
|
|
@@ -306,8 +315,8 @@ function formatAddress(address) {
|
|
|
306
315
|
* @param attachment - The Upyo attachment to convert
|
|
307
316
|
* @returns Resend attachment object
|
|
308
317
|
*/
|
|
309
|
-
async function convertAttachment(attachment) {
|
|
310
|
-
const content = await attachment.content;
|
|
318
|
+
async function convertAttachment(attachment, signal) {
|
|
319
|
+
const content = await (0, __upyo_core.readAttachmentContent)(attachment.content, signal);
|
|
311
320
|
const resendAttachment = {
|
|
312
321
|
filename: attachment.filename,
|
|
313
322
|
content: await uint8ArrayToBase64(content)
|
|
@@ -333,8 +342,11 @@ function uint8ArrayToBase64(bytes) {
|
|
|
333
342
|
const bitmap = a << 16 | b << 8 | c;
|
|
334
343
|
result += chars.charAt(bitmap >> 18 & 63) + chars.charAt(bitmap >> 12 & 63) + chars.charAt(bitmap >> 6 & 63) + chars.charAt(bitmap & 63);
|
|
335
344
|
}
|
|
336
|
-
const
|
|
337
|
-
if (
|
|
345
|
+
const remainder = bytes.length % 3;
|
|
346
|
+
if (remainder !== 0) {
|
|
347
|
+
const padding = 3 - remainder;
|
|
348
|
+
result = result.slice(0, -padding) + "=".repeat(padding);
|
|
349
|
+
}
|
|
338
350
|
return result;
|
|
339
351
|
}
|
|
340
352
|
/**
|
|
@@ -452,7 +464,7 @@ var ResendTransport = class {
|
|
|
452
464
|
try {
|
|
453
465
|
options?.signal?.throwIfAborted();
|
|
454
466
|
const idempotencyKey = message.idempotencyKey ?? generateIdempotencyKey();
|
|
455
|
-
const emailData = await convertMessage(message, this.config);
|
|
467
|
+
const emailData = await convertMessage(message, this.config, { signal: options?.signal });
|
|
456
468
|
options?.signal?.throwIfAborted();
|
|
457
469
|
const response = await this.httpClient.sendMessage(emailData, options?.signal, idempotencyKey);
|
|
458
470
|
return {
|
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
|
/**
|
|
@@ -226,7 +226,16 @@ async function convertMessage(message, _config, options = {}) {
|
|
|
226
226
|
emailData.html = message.content.html;
|
|
227
227
|
if (message.content.text) emailData.text = message.content.text;
|
|
228
228
|
} else emailData.text = message.content.text;
|
|
229
|
-
if (message.attachments.length > 0)
|
|
229
|
+
if (message.attachments.length > 0) {
|
|
230
|
+
const cancellation = new AbortController();
|
|
231
|
+
const combined = combineSignals(cancellation.signal, options.signal);
|
|
232
|
+
try {
|
|
233
|
+
emailData.attachments = await Promise.all(message.attachments.map((attachment) => convertAttachment(attachment, combined.signal)));
|
|
234
|
+
} finally {
|
|
235
|
+
cancellation.abort();
|
|
236
|
+
combined.cleanup();
|
|
237
|
+
}
|
|
238
|
+
}
|
|
230
239
|
if (message.tags.length > 0) emailData.tags = message.tags.map((tag, index) => ({
|
|
231
240
|
name: `tag${index + 1}`,
|
|
232
241
|
value: tag
|
|
@@ -283,8 +292,8 @@ function formatAddress(address) {
|
|
|
283
292
|
* @param attachment - The Upyo attachment to convert
|
|
284
293
|
* @returns Resend attachment object
|
|
285
294
|
*/
|
|
286
|
-
async function convertAttachment(attachment) {
|
|
287
|
-
const content = await attachment.content;
|
|
295
|
+
async function convertAttachment(attachment, signal) {
|
|
296
|
+
const content = await readAttachmentContent(attachment.content, signal);
|
|
288
297
|
const resendAttachment = {
|
|
289
298
|
filename: attachment.filename,
|
|
290
299
|
content: await uint8ArrayToBase64(content)
|
|
@@ -310,8 +319,11 @@ function uint8ArrayToBase64(bytes) {
|
|
|
310
319
|
const bitmap = a << 16 | b << 8 | c;
|
|
311
320
|
result += chars.charAt(bitmap >> 18 & 63) + chars.charAt(bitmap >> 12 & 63) + chars.charAt(bitmap >> 6 & 63) + chars.charAt(bitmap & 63);
|
|
312
321
|
}
|
|
313
|
-
const
|
|
314
|
-
if (
|
|
322
|
+
const remainder = bytes.length % 3;
|
|
323
|
+
if (remainder !== 0) {
|
|
324
|
+
const padding = 3 - remainder;
|
|
325
|
+
result = result.slice(0, -padding) + "=".repeat(padding);
|
|
326
|
+
}
|
|
315
327
|
return result;
|
|
316
328
|
}
|
|
317
329
|
/**
|
|
@@ -429,7 +441,7 @@ var ResendTransport = class {
|
|
|
429
441
|
try {
|
|
430
442
|
options?.signal?.throwIfAborted();
|
|
431
443
|
const idempotencyKey = message.idempotencyKey ?? generateIdempotencyKey();
|
|
432
|
-
const emailData = await convertMessage(message, this.config);
|
|
444
|
+
const emailData = await convertMessage(message, this.config, { signal: options?.signal });
|
|
433
445
|
options?.signal?.throwIfAborted();
|
|
434
446
|
const response = await this.httpClient.sendMessage(emailData, options?.signal, idempotencyKey);
|
|
435
447
|
return {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@upyo/resend",
|
|
3
|
-
"version": "0.6.0-dev.
|
|
3
|
+
"version": "0.6.0-dev.314",
|
|
4
4
|
"description": "Resend 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",
|