@upyo/ses 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 CHANGED
@@ -275,7 +275,7 @@ var SesApiError = class extends Error {
275
275
 
276
276
  //#endregion
277
277
  //#region src/message-converter.ts
278
- async function convertMessage(message, config) {
278
+ async function convertMessage(message, config, signal) {
279
279
  const destination = {};
280
280
  if (message.recipients.length > 0) destination.ToAddresses = message.recipients.map(formatAddress);
281
281
  if (message.ccRecipients.length > 0) destination.CcAddresses = message.ccRecipients.map(formatAddress);
@@ -287,7 +287,7 @@ async function convertMessage(message, config) {
287
287
  };
288
288
  if (message.replyRecipients.length > 0) sesMessage.ReplyToAddresses = message.replyRecipients.map(formatAddress);
289
289
  if (config.configurationSetName) sesMessage.ConfigurationSetName = config.configurationSetName;
290
- sesMessage.Content.Simple = await createSimpleContent(message);
290
+ sesMessage.Content.Simple = await createSimpleContent(message, signal);
291
291
  const tags = [];
292
292
  if (message.tags.length > 0) for (const tag of message.tags) tags.push({
293
293
  Name: "category",
@@ -304,7 +304,7 @@ async function convertMessage(message, config) {
304
304
  if (tags.length > 0) sesMessage.Tags = tags;
305
305
  return sesMessage;
306
306
  }
307
- async function createSimpleContent(message) {
307
+ async function createSimpleContent(message, signal) {
308
308
  const content = {
309
309
  Subject: {
310
310
  Data: message.subject,
@@ -325,18 +325,29 @@ async function createSimpleContent(message) {
325
325
  Data: message.content.text,
326
326
  Charset: "UTF-8"
327
327
  };
328
- if (message.attachments.length > 0) content.Attachments = await Promise.all(message.attachments.map(async (attachment) => {
329
- const contentBytes = await attachment.content;
330
- const base64Content = btoa(String.fromCharCode(...contentBytes));
331
- return {
332
- FileName: attachment.filename,
333
- ContentType: attachment.contentType || "application/octet-stream",
334
- ContentDisposition: attachment.inline ? "INLINE" : "ATTACHMENT",
335
- ContentId: attachment.contentId,
336
- ContentTransferEncoding: "BASE64",
337
- RawContent: base64Content
338
- };
339
- }));
328
+ if (message.attachments.length > 0) {
329
+ const cancellation = new AbortController();
330
+ const combined = (0, __upyo_core.combineSignals)(cancellation.signal, signal);
331
+ try {
332
+ content.Attachments = await Promise.all(message.attachments.map(async (attachment) => {
333
+ const contentBytes = await (0, __upyo_core.readAttachmentContent)(attachment.content, combined.signal);
334
+ const parts = [];
335
+ for (let offset = 0; offset < contentBytes.length; offset += 8192) parts.push(String.fromCharCode(...contentBytes.subarray(offset, offset + 8192)));
336
+ const base64Content = btoa(parts.join(""));
337
+ return {
338
+ FileName: attachment.filename,
339
+ ContentType: attachment.contentType || "application/octet-stream",
340
+ ContentDisposition: attachment.inline ? "INLINE" : "ATTACHMENT",
341
+ ContentId: attachment.contentId,
342
+ ContentTransferEncoding: "BASE64",
343
+ RawContent: base64Content
344
+ };
345
+ }));
346
+ } finally {
347
+ cancellation.abort();
348
+ combined.cleanup();
349
+ }
350
+ }
340
351
  return content;
341
352
  }
342
353
  function formatAddress(address) {
@@ -427,7 +438,7 @@ var SesTransport = class {
427
438
  async send(message, options) {
428
439
  options?.signal?.throwIfAborted();
429
440
  try {
430
- const sesMessage = await convertMessage(message, this.config);
441
+ const sesMessage = await convertMessage(message, this.config, options?.signal);
431
442
  options?.signal?.throwIfAborted();
432
443
  const response = await this.httpClient.sendMessage(sesMessage, options?.signal);
433
444
  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
  /**
@@ -252,7 +252,7 @@ var SesApiError = class extends Error {
252
252
 
253
253
  //#endregion
254
254
  //#region src/message-converter.ts
255
- async function convertMessage(message, config) {
255
+ async function convertMessage(message, config, signal) {
256
256
  const destination = {};
257
257
  if (message.recipients.length > 0) destination.ToAddresses = message.recipients.map(formatAddress);
258
258
  if (message.ccRecipients.length > 0) destination.CcAddresses = message.ccRecipients.map(formatAddress);
@@ -264,7 +264,7 @@ async function convertMessage(message, config) {
264
264
  };
265
265
  if (message.replyRecipients.length > 0) sesMessage.ReplyToAddresses = message.replyRecipients.map(formatAddress);
266
266
  if (config.configurationSetName) sesMessage.ConfigurationSetName = config.configurationSetName;
267
- sesMessage.Content.Simple = await createSimpleContent(message);
267
+ sesMessage.Content.Simple = await createSimpleContent(message, signal);
268
268
  const tags = [];
269
269
  if (message.tags.length > 0) for (const tag of message.tags) tags.push({
270
270
  Name: "category",
@@ -281,7 +281,7 @@ async function convertMessage(message, config) {
281
281
  if (tags.length > 0) sesMessage.Tags = tags;
282
282
  return sesMessage;
283
283
  }
284
- async function createSimpleContent(message) {
284
+ async function createSimpleContent(message, signal) {
285
285
  const content = {
286
286
  Subject: {
287
287
  Data: message.subject,
@@ -302,18 +302,29 @@ async function createSimpleContent(message) {
302
302
  Data: message.content.text,
303
303
  Charset: "UTF-8"
304
304
  };
305
- if (message.attachments.length > 0) content.Attachments = await Promise.all(message.attachments.map(async (attachment) => {
306
- const contentBytes = await attachment.content;
307
- const base64Content = btoa(String.fromCharCode(...contentBytes));
308
- return {
309
- FileName: attachment.filename,
310
- ContentType: attachment.contentType || "application/octet-stream",
311
- ContentDisposition: attachment.inline ? "INLINE" : "ATTACHMENT",
312
- ContentId: attachment.contentId,
313
- ContentTransferEncoding: "BASE64",
314
- RawContent: base64Content
315
- };
316
- }));
305
+ if (message.attachments.length > 0) {
306
+ const cancellation = new AbortController();
307
+ const combined = combineSignals(cancellation.signal, signal);
308
+ try {
309
+ content.Attachments = await Promise.all(message.attachments.map(async (attachment) => {
310
+ const contentBytes = await readAttachmentContent(attachment.content, combined.signal);
311
+ const parts = [];
312
+ for (let offset = 0; offset < contentBytes.length; offset += 8192) parts.push(String.fromCharCode(...contentBytes.subarray(offset, offset + 8192)));
313
+ const base64Content = btoa(parts.join(""));
314
+ return {
315
+ FileName: attachment.filename,
316
+ ContentType: attachment.contentType || "application/octet-stream",
317
+ ContentDisposition: attachment.inline ? "INLINE" : "ATTACHMENT",
318
+ ContentId: attachment.contentId,
319
+ ContentTransferEncoding: "BASE64",
320
+ RawContent: base64Content
321
+ };
322
+ }));
323
+ } finally {
324
+ cancellation.abort();
325
+ combined.cleanup();
326
+ }
327
+ }
317
328
  return content;
318
329
  }
319
330
  function formatAddress(address) {
@@ -404,7 +415,7 @@ var SesTransport = class {
404
415
  async send(message, options) {
405
416
  options?.signal?.throwIfAborted();
406
417
  try {
407
- const sesMessage = await convertMessage(message, this.config);
418
+ const sesMessage = await convertMessage(message, this.config, options?.signal);
408
419
  options?.signal?.throwIfAborted();
409
420
  const response = await this.httpClient.sendMessage(sesMessage, options?.signal);
410
421
  const messageId = this.extractMessageId(response);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@upyo/ses",
3
- "version": "0.6.0-dev.311",
3
+ "version": "0.6.0-dev.312",
4
4
  "description": "Amazon SES transport for Upyo email library",
5
5
  "keywords": [
6
6
  "email",
@@ -55,7 +55,7 @@
55
55
  },
56
56
  "sideEffects": false,
57
57
  "peerDependencies": {
58
- "@upyo/core": "0.6.0-dev.311+375af6f4"
58
+ "@upyo/core": "0.6.0-dev.312+646e2370"
59
59
  },
60
60
  "devDependencies": {
61
61
  "tsdown": "^0.12.7",