@upyo/maileroo 0.6.0-dev.223 → 0.6.0-dev.227

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
@@ -134,20 +134,23 @@ var MailerooHttpClient = class {
134
134
  return this.makeRequest(url, messageData, signal);
135
135
  }
136
136
  async makeRequest(url, body, signal) {
137
- let lastError = null;
137
+ let lastError;
138
138
  for (let attempt = 0; attempt <= this.config.retries; attempt++) {
139
139
  signal?.throwIfAborted();
140
+ let responseText;
140
141
  try {
141
142
  const { response, text } = await this.fetchWithAuth(url, body, signal);
142
143
  if (!response.ok) throw new MailerooApiError(parseErrorMessage(text, response.status), response.status, (0, __upyo_core.parseRetryAfter)(response.headers.get("Retry-After")), attempt + 1);
143
- return parseResponse(text);
144
+ responseText = text;
144
145
  } catch (error) {
145
146
  lastError = error instanceof Error ? error : new Error(String(error));
146
147
  if (signal?.aborted) throw error;
147
148
  if (error instanceof MailerooApiError && !isRetryable(error)) throw error;
148
149
  if (attempt === this.config.retries) throw withAttempts(lastError, attempt + 1);
149
150
  await sleep(calculateRetryDelay(attempt, lastError), signal);
151
+ continue;
150
152
  }
153
+ return parseResponse(responseText);
151
154
  }
152
155
  throw lastError ?? /* @__PURE__ */ new Error("Request failed after all retry attempts.");
153
156
  }
@@ -219,20 +222,20 @@ function parseResponse(text) {
219
222
  function truncateErrorMessage(message) {
220
223
  return message.length > maxErrorMessageLength ? `${message.slice(0, maxErrorMessageLength)}...` : message;
221
224
  }
222
- function abortReason(signal) {
225
+ function abortReason$1(signal) {
223
226
  return signal?.reason ?? new DOMException("The operation was aborted.", "AbortError");
224
227
  }
225
228
  function sleep(ms, signal) {
226
229
  return new Promise((resolve, reject) => {
227
230
  if (signal?.aborted) {
228
- reject(abortReason(signal));
231
+ reject(abortReason$1(signal));
229
232
  return;
230
233
  }
231
234
  const timeoutState = {};
232
235
  const onAbort = () => {
233
236
  if (timeoutState.id !== void 0) clearTimeout(timeoutState.id);
234
237
  signal?.removeEventListener("abort", onAbort);
235
- reject(abortReason(signal));
238
+ reject(abortReason$1(signal));
236
239
  };
237
240
  signal?.addEventListener("abort", onAbort, { once: true });
238
241
  if (signal?.aborted) {
@@ -331,7 +334,7 @@ function convertHeaders(message) {
331
334
  }
332
335
  async function convertAttachment(attachment, signal) {
333
336
  signal?.throwIfAborted();
334
- const content = await attachment.content;
337
+ const content = await waitForAttachmentContent(attachment.content, signal);
335
338
  signal?.throwIfAborted();
336
339
  return {
337
340
  file_name: getAttachmentFileName(attachment),
@@ -340,14 +343,35 @@ async function convertAttachment(attachment, signal) {
340
343
  inline: attachment.inline || void 0
341
344
  };
342
345
  }
346
+ function waitForAttachmentContent(content, signal) {
347
+ if (signal == null) return Promise.resolve(content);
348
+ if (signal.aborted) return Promise.reject(abortReason(signal));
349
+ return new Promise((resolve, reject) => {
350
+ const onAbort = () => {
351
+ signal.removeEventListener("abort", onAbort);
352
+ reject(abortReason(signal));
353
+ };
354
+ signal.addEventListener("abort", onAbort, { once: true });
355
+ Promise.resolve(content).then((value) => {
356
+ signal.removeEventListener("abort", onAbort);
357
+ resolve(value);
358
+ }, (error) => {
359
+ signal.removeEventListener("abort", onAbort);
360
+ reject(error);
361
+ });
362
+ });
363
+ }
364
+ function abortReason(signal) {
365
+ return signal.reason ?? new DOMException("The operation was aborted.", "AbortError");
366
+ }
343
367
  function getAttachmentFileName(attachment) {
344
368
  return attachment.inline && typeof attachment.contentId === "string" && attachment.contentId !== "" ? attachment.contentId : attachment.filename;
345
369
  }
346
370
  function uint8ArrayToBase64(bytes) {
347
371
  const nativeToBase64 = getNativeToBase64(bytes);
348
372
  if (nativeToBase64 != null) return nativeToBase64();
349
- const bufferConverter = getBufferBase64Converter();
350
- if (bufferConverter != null) return bufferConverter.from(bytes.buffer, bytes.byteOffset, bytes.byteLength).toString("base64");
373
+ const bufferBase64 = getBufferBase64(bytes);
374
+ if (bufferBase64 != null) return bufferBase64;
351
375
  const chunkSize = 4096;
352
376
  const chunks = [];
353
377
  for (let offset = 0; offset < bytes.length; offset += chunkSize) chunks.push(String.fromCharCode(...bytes.subarray(offset, offset + chunkSize)));
@@ -359,9 +383,17 @@ function getNativeToBase64(bytes) {
359
383
  if (typeof toBase64 !== "function") return void 0;
360
384
  return () => toBase64.call(bytes);
361
385
  }
362
- function getBufferBase64Converter() {
386
+ function getBufferBase64(bytes) {
363
387
  const candidate = globalThis.Buffer;
364
- return typeof candidate?.from === "function" ? candidate : void 0;
388
+ if (typeof candidate?.from !== "function") return void 0;
389
+ try {
390
+ const buffer = candidate.from(bytes.buffer, bytes.byteOffset, bytes.byteLength);
391
+ if (buffer == null || typeof buffer.toString !== "function") return void 0;
392
+ const base64 = buffer.toString("base64");
393
+ return typeof base64 === "string" ? base64 : void 0;
394
+ } catch {
395
+ return void 0;
396
+ }
365
397
  }
366
398
  function isStandardHeader(headerName) {
367
399
  return STANDARD_HEADERS.has(headerName.toLowerCase());
package/dist/index.js CHANGED
@@ -111,20 +111,23 @@ var MailerooHttpClient = class {
111
111
  return this.makeRequest(url, messageData, signal);
112
112
  }
113
113
  async makeRequest(url, body, signal) {
114
- let lastError = null;
114
+ let lastError;
115
115
  for (let attempt = 0; attempt <= this.config.retries; attempt++) {
116
116
  signal?.throwIfAborted();
117
+ let responseText;
117
118
  try {
118
119
  const { response, text } = await this.fetchWithAuth(url, body, signal);
119
120
  if (!response.ok) throw new MailerooApiError(parseErrorMessage(text, response.status), response.status, parseRetryAfter(response.headers.get("Retry-After")), attempt + 1);
120
- return parseResponse(text);
121
+ responseText = text;
121
122
  } catch (error) {
122
123
  lastError = error instanceof Error ? error : new Error(String(error));
123
124
  if (signal?.aborted) throw error;
124
125
  if (error instanceof MailerooApiError && !isRetryable(error)) throw error;
125
126
  if (attempt === this.config.retries) throw withAttempts(lastError, attempt + 1);
126
127
  await sleep(calculateRetryDelay(attempt, lastError), signal);
128
+ continue;
127
129
  }
130
+ return parseResponse(responseText);
128
131
  }
129
132
  throw lastError ?? /* @__PURE__ */ new Error("Request failed after all retry attempts.");
130
133
  }
@@ -196,20 +199,20 @@ function parseResponse(text) {
196
199
  function truncateErrorMessage(message) {
197
200
  return message.length > maxErrorMessageLength ? `${message.slice(0, maxErrorMessageLength)}...` : message;
198
201
  }
199
- function abortReason(signal) {
202
+ function abortReason$1(signal) {
200
203
  return signal?.reason ?? new DOMException("The operation was aborted.", "AbortError");
201
204
  }
202
205
  function sleep(ms, signal) {
203
206
  return new Promise((resolve, reject) => {
204
207
  if (signal?.aborted) {
205
- reject(abortReason(signal));
208
+ reject(abortReason$1(signal));
206
209
  return;
207
210
  }
208
211
  const timeoutState = {};
209
212
  const onAbort = () => {
210
213
  if (timeoutState.id !== void 0) clearTimeout(timeoutState.id);
211
214
  signal?.removeEventListener("abort", onAbort);
212
- reject(abortReason(signal));
215
+ reject(abortReason$1(signal));
213
216
  };
214
217
  signal?.addEventListener("abort", onAbort, { once: true });
215
218
  if (signal?.aborted) {
@@ -308,7 +311,7 @@ function convertHeaders(message) {
308
311
  }
309
312
  async function convertAttachment(attachment, signal) {
310
313
  signal?.throwIfAborted();
311
- const content = await attachment.content;
314
+ const content = await waitForAttachmentContent(attachment.content, signal);
312
315
  signal?.throwIfAborted();
313
316
  return {
314
317
  file_name: getAttachmentFileName(attachment),
@@ -317,14 +320,35 @@ async function convertAttachment(attachment, signal) {
317
320
  inline: attachment.inline || void 0
318
321
  };
319
322
  }
323
+ function waitForAttachmentContent(content, signal) {
324
+ if (signal == null) return Promise.resolve(content);
325
+ if (signal.aborted) return Promise.reject(abortReason(signal));
326
+ return new Promise((resolve, reject) => {
327
+ const onAbort = () => {
328
+ signal.removeEventListener("abort", onAbort);
329
+ reject(abortReason(signal));
330
+ };
331
+ signal.addEventListener("abort", onAbort, { once: true });
332
+ Promise.resolve(content).then((value) => {
333
+ signal.removeEventListener("abort", onAbort);
334
+ resolve(value);
335
+ }, (error) => {
336
+ signal.removeEventListener("abort", onAbort);
337
+ reject(error);
338
+ });
339
+ });
340
+ }
341
+ function abortReason(signal) {
342
+ return signal.reason ?? new DOMException("The operation was aborted.", "AbortError");
343
+ }
320
344
  function getAttachmentFileName(attachment) {
321
345
  return attachment.inline && typeof attachment.contentId === "string" && attachment.contentId !== "" ? attachment.contentId : attachment.filename;
322
346
  }
323
347
  function uint8ArrayToBase64(bytes) {
324
348
  const nativeToBase64 = getNativeToBase64(bytes);
325
349
  if (nativeToBase64 != null) return nativeToBase64();
326
- const bufferConverter = getBufferBase64Converter();
327
- if (bufferConverter != null) return bufferConverter.from(bytes.buffer, bytes.byteOffset, bytes.byteLength).toString("base64");
350
+ const bufferBase64 = getBufferBase64(bytes);
351
+ if (bufferBase64 != null) return bufferBase64;
328
352
  const chunkSize = 4096;
329
353
  const chunks = [];
330
354
  for (let offset = 0; offset < bytes.length; offset += chunkSize) chunks.push(String.fromCharCode(...bytes.subarray(offset, offset + chunkSize)));
@@ -336,9 +360,17 @@ function getNativeToBase64(bytes) {
336
360
  if (typeof toBase64 !== "function") return void 0;
337
361
  return () => toBase64.call(bytes);
338
362
  }
339
- function getBufferBase64Converter() {
363
+ function getBufferBase64(bytes) {
340
364
  const candidate = globalThis.Buffer;
341
- return typeof candidate?.from === "function" ? candidate : void 0;
365
+ if (typeof candidate?.from !== "function") return void 0;
366
+ try {
367
+ const buffer = candidate.from(bytes.buffer, bytes.byteOffset, bytes.byteLength);
368
+ if (buffer == null || typeof buffer.toString !== "function") return void 0;
369
+ const base64 = buffer.toString("base64");
370
+ return typeof base64 === "string" ? base64 : void 0;
371
+ } catch {
372
+ return void 0;
373
+ }
342
374
  }
343
375
  function isStandardHeader(headerName) {
344
376
  return STANDARD_HEADERS.has(headerName.toLowerCase());
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@upyo/maileroo",
3
- "version": "0.6.0-dev.223",
3
+ "version": "0.6.0-dev.227",
4
4
  "description": "Maileroo 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.223+8fde224e"
56
+ "@upyo/core": "0.6.0-dev.227+4166cf34"
57
57
  },
58
58
  "devDependencies": {
59
59
  "tsdown": "^0.12.7",