@upyo/maileroo 0.6.0-dev.225 → 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 +17 -6
- package/dist/index.js +17 -6
- package/package.json +2 -2
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
|
|
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
|
-
|
|
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
|
}
|
|
@@ -367,8 +370,8 @@ function getAttachmentFileName(attachment) {
|
|
|
367
370
|
function uint8ArrayToBase64(bytes) {
|
|
368
371
|
const nativeToBase64 = getNativeToBase64(bytes);
|
|
369
372
|
if (nativeToBase64 != null) return nativeToBase64();
|
|
370
|
-
const
|
|
371
|
-
if (
|
|
373
|
+
const bufferBase64 = getBufferBase64(bytes);
|
|
374
|
+
if (bufferBase64 != null) return bufferBase64;
|
|
372
375
|
const chunkSize = 4096;
|
|
373
376
|
const chunks = [];
|
|
374
377
|
for (let offset = 0; offset < bytes.length; offset += chunkSize) chunks.push(String.fromCharCode(...bytes.subarray(offset, offset + chunkSize)));
|
|
@@ -380,9 +383,17 @@ function getNativeToBase64(bytes) {
|
|
|
380
383
|
if (typeof toBase64 !== "function") return void 0;
|
|
381
384
|
return () => toBase64.call(bytes);
|
|
382
385
|
}
|
|
383
|
-
function
|
|
386
|
+
function getBufferBase64(bytes) {
|
|
384
387
|
const candidate = globalThis.Buffer;
|
|
385
|
-
|
|
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
|
+
}
|
|
386
397
|
}
|
|
387
398
|
function isStandardHeader(headerName) {
|
|
388
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
|
|
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
|
-
|
|
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
|
}
|
|
@@ -344,8 +347,8 @@ function getAttachmentFileName(attachment) {
|
|
|
344
347
|
function uint8ArrayToBase64(bytes) {
|
|
345
348
|
const nativeToBase64 = getNativeToBase64(bytes);
|
|
346
349
|
if (nativeToBase64 != null) return nativeToBase64();
|
|
347
|
-
const
|
|
348
|
-
if (
|
|
350
|
+
const bufferBase64 = getBufferBase64(bytes);
|
|
351
|
+
if (bufferBase64 != null) return bufferBase64;
|
|
349
352
|
const chunkSize = 4096;
|
|
350
353
|
const chunks = [];
|
|
351
354
|
for (let offset = 0; offset < bytes.length; offset += chunkSize) chunks.push(String.fromCharCode(...bytes.subarray(offset, offset + chunkSize)));
|
|
@@ -357,9 +360,17 @@ function getNativeToBase64(bytes) {
|
|
|
357
360
|
if (typeof toBase64 !== "function") return void 0;
|
|
358
361
|
return () => toBase64.call(bytes);
|
|
359
362
|
}
|
|
360
|
-
function
|
|
363
|
+
function getBufferBase64(bytes) {
|
|
361
364
|
const candidate = globalThis.Buffer;
|
|
362
|
-
|
|
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
|
+
}
|
|
363
374
|
}
|
|
364
375
|
function isStandardHeader(headerName) {
|
|
365
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.
|
|
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.
|
|
56
|
+
"@upyo/core": "0.6.0-dev.227+4166cf34"
|
|
57
57
|
},
|
|
58
58
|
"devDependencies": {
|
|
59
59
|
"tsdown": "^0.12.7",
|