@upyo/maileroo 0.6.0-dev.225 → 0.6.0-dev.229

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
  }
@@ -341,7 +344,8 @@ async function convertAttachment(attachment, signal) {
341
344
  };
342
345
  }
343
346
  function waitForAttachmentContent(content, signal) {
344
- if (signal == null) return Promise.resolve(content);
347
+ if (content instanceof Uint8Array) return signal?.aborted ? Promise.reject(abortReason(signal)) : Promise.resolve(content);
348
+ if (signal == null) return content;
345
349
  if (signal.aborted) return Promise.reject(abortReason(signal));
346
350
  return new Promise((resolve, reject) => {
347
351
  const onAbort = () => {
@@ -367,8 +371,8 @@ function getAttachmentFileName(attachment) {
367
371
  function uint8ArrayToBase64(bytes) {
368
372
  const nativeToBase64 = getNativeToBase64(bytes);
369
373
  if (nativeToBase64 != null) return nativeToBase64();
370
- const bufferConverter = getBufferBase64Converter();
371
- if (bufferConverter != null) return bufferConverter.from(bytes.buffer, bytes.byteOffset, bytes.byteLength).toString("base64");
374
+ const bufferBase64 = getBufferBase64(bytes);
375
+ if (bufferBase64 != null) return bufferBase64;
372
376
  const chunkSize = 4096;
373
377
  const chunks = [];
374
378
  for (let offset = 0; offset < bytes.length; offset += chunkSize) chunks.push(String.fromCharCode(...bytes.subarray(offset, offset + chunkSize)));
@@ -380,9 +384,17 @@ function getNativeToBase64(bytes) {
380
384
  if (typeof toBase64 !== "function") return void 0;
381
385
  return () => toBase64.call(bytes);
382
386
  }
383
- function getBufferBase64Converter() {
387
+ function getBufferBase64(bytes) {
384
388
  const candidate = globalThis.Buffer;
385
- return typeof candidate?.from === "function" ? candidate : void 0;
389
+ if (typeof candidate?.from !== "function") return void 0;
390
+ try {
391
+ const buffer = candidate.from(bytes.buffer, bytes.byteOffset, bytes.byteLength);
392
+ if (buffer == null || typeof buffer.toString !== "function") return void 0;
393
+ const base64 = buffer.toString("base64");
394
+ return typeof base64 === "string" ? base64 : void 0;
395
+ } catch {
396
+ return void 0;
397
+ }
386
398
  }
387
399
  function isStandardHeader(headerName) {
388
400
  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
  }
@@ -318,7 +321,8 @@ async function convertAttachment(attachment, signal) {
318
321
  };
319
322
  }
320
323
  function waitForAttachmentContent(content, signal) {
321
- if (signal == null) return Promise.resolve(content);
324
+ if (content instanceof Uint8Array) return signal?.aborted ? Promise.reject(abortReason(signal)) : Promise.resolve(content);
325
+ if (signal == null) return content;
322
326
  if (signal.aborted) return Promise.reject(abortReason(signal));
323
327
  return new Promise((resolve, reject) => {
324
328
  const onAbort = () => {
@@ -344,8 +348,8 @@ function getAttachmentFileName(attachment) {
344
348
  function uint8ArrayToBase64(bytes) {
345
349
  const nativeToBase64 = getNativeToBase64(bytes);
346
350
  if (nativeToBase64 != null) return nativeToBase64();
347
- const bufferConverter = getBufferBase64Converter();
348
- if (bufferConverter != null) return bufferConverter.from(bytes.buffer, bytes.byteOffset, bytes.byteLength).toString("base64");
351
+ const bufferBase64 = getBufferBase64(bytes);
352
+ if (bufferBase64 != null) return bufferBase64;
349
353
  const chunkSize = 4096;
350
354
  const chunks = [];
351
355
  for (let offset = 0; offset < bytes.length; offset += chunkSize) chunks.push(String.fromCharCode(...bytes.subarray(offset, offset + chunkSize)));
@@ -357,9 +361,17 @@ function getNativeToBase64(bytes) {
357
361
  if (typeof toBase64 !== "function") return void 0;
358
362
  return () => toBase64.call(bytes);
359
363
  }
360
- function getBufferBase64Converter() {
364
+ function getBufferBase64(bytes) {
361
365
  const candidate = globalThis.Buffer;
362
- return typeof candidate?.from === "function" ? candidate : void 0;
366
+ if (typeof candidate?.from !== "function") return void 0;
367
+ try {
368
+ const buffer = candidate.from(bytes.buffer, bytes.byteOffset, bytes.byteLength);
369
+ if (buffer == null || typeof buffer.toString !== "function") return void 0;
370
+ const base64 = buffer.toString("base64");
371
+ return typeof base64 === "string" ? base64 : void 0;
372
+ } catch {
373
+ return void 0;
374
+ }
363
375
  }
364
376
  function isStandardHeader(headerName) {
365
377
  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.225",
3
+ "version": "0.6.0-dev.229",
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.225+1a4bf2e0"
56
+ "@upyo/core": "0.6.0-dev.229+754d6612"
57
57
  },
58
58
  "devDependencies": {
59
59
  "tsdown": "^0.12.7",