@upyo/mailtrap 0.6.0-dev.368 → 0.6.0
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/README.md +2 -0
- package/dist/index.cjs +44 -4
- package/dist/index.d.cts +22 -1
- package/dist/index.d.ts +22 -1
- package/dist/index.js +44 -5
- package/package.json +2 -2
package/README.md
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -127,6 +127,31 @@ var MailtrapTimeoutError = class extends Error {
|
|
|
127
127
|
}
|
|
128
128
|
};
|
|
129
129
|
/**
|
|
130
|
+
* Failure to read a successful Mailtrap response after the request was accepted.
|
|
131
|
+
* Retrying the request could send the message again.
|
|
132
|
+
*
|
|
133
|
+
* @since 0.6.0
|
|
134
|
+
*/
|
|
135
|
+
var MailtrapResponseError = class extends Error {
|
|
136
|
+
/**
|
|
137
|
+
* Number of attempts made before this error was produced.
|
|
138
|
+
*
|
|
139
|
+
* @since 0.6.0
|
|
140
|
+
*/
|
|
141
|
+
attempts;
|
|
142
|
+
/**
|
|
143
|
+
* Creates an error for an unreadable successful response.
|
|
144
|
+
*
|
|
145
|
+
* @param cause The response body error, including a possible timeout.
|
|
146
|
+
* @param attempts Number of attempts made before this error.
|
|
147
|
+
*/
|
|
148
|
+
constructor(cause, attempts) {
|
|
149
|
+
super(cause instanceof Error ? cause.message : String(cause), { cause });
|
|
150
|
+
this.name = "MailtrapResponseError";
|
|
151
|
+
this.attempts = attempts;
|
|
152
|
+
}
|
|
153
|
+
};
|
|
154
|
+
/**
|
|
130
155
|
* HTTP client wrapper for Mailtrap API requests.
|
|
131
156
|
*
|
|
132
157
|
* @since 0.6.0
|
|
@@ -182,6 +207,7 @@ var MailtrapHttpClient = class {
|
|
|
182
207
|
}
|
|
183
208
|
} catch (error) {
|
|
184
209
|
lastError = error instanceof Error ? error : new Error(String(error));
|
|
210
|
+
if (error instanceof MailtrapResponseError) throw new MailtrapResponseError(error.cause, attempt + 1);
|
|
185
211
|
if (error instanceof MailtrapApiError && !isRetryable(error)) throw error;
|
|
186
212
|
if (error instanceof Error && error.name === "AbortError" && signal?.aborted) throw error;
|
|
187
213
|
if (attempt === this.config.retries) throw withAttempts(lastError, attempt + 1);
|
|
@@ -206,8 +232,9 @@ var MailtrapHttpClient = class {
|
|
|
206
232
|
const timeoutController = new AbortController();
|
|
207
233
|
const timeoutId = this.config.timeout > 0 ? setTimeout(() => timeoutController.abort(), this.config.timeout) : void 0;
|
|
208
234
|
const requestSignal = (0, __upyo_core.combineSignals)(timeoutController.signal, signal);
|
|
235
|
+
let response;
|
|
209
236
|
try {
|
|
210
|
-
|
|
237
|
+
response = await globalThis.fetch(url, {
|
|
211
238
|
method: "POST",
|
|
212
239
|
headers,
|
|
213
240
|
body: JSON.stringify(body),
|
|
@@ -219,8 +246,11 @@ var MailtrapHttpClient = class {
|
|
|
219
246
|
text
|
|
220
247
|
};
|
|
221
248
|
} catch (error) {
|
|
222
|
-
|
|
223
|
-
|
|
249
|
+
signal?.throwIfAborted();
|
|
250
|
+
let cause = error;
|
|
251
|
+
if (error instanceof Error && error.name === "AbortError" && timeoutController.signal.aborted && !signal?.aborted) cause = new MailtrapTimeoutError(this.config.timeout);
|
|
252
|
+
if (response?.ok) throw new MailtrapResponseError(cause);
|
|
253
|
+
throw cause;
|
|
224
254
|
} finally {
|
|
225
255
|
requestSignal.cleanup();
|
|
226
256
|
if (timeoutId !== void 0) clearTimeout(timeoutId);
|
|
@@ -401,7 +431,7 @@ function uint8ArrayToBase64(bytes) {
|
|
|
401
431
|
if (nativeToBase64 != null) return nativeToBase64();
|
|
402
432
|
const bufferBase64 = getBufferBase64(bytes);
|
|
403
433
|
if (bufferBase64 != null) return bufferBase64;
|
|
404
|
-
const chunkSize =
|
|
434
|
+
const chunkSize = 4096;
|
|
405
435
|
const chunks = [];
|
|
406
436
|
for (let offset = 0; offset < bytes.length; offset += chunkSize) chunks.push(String.fromCharCode(...bytes.subarray(offset, offset + chunkSize)));
|
|
407
437
|
return btoa(chunks.join(""));
|
|
@@ -608,6 +638,15 @@ function toReceipt(response, options) {
|
|
|
608
638
|
};
|
|
609
639
|
}
|
|
610
640
|
function createMailtrapFailure(message, error) {
|
|
641
|
+
if (error instanceof MailtrapResponseError) return (0, __upyo_core.createFailedReceipt)(message, {
|
|
642
|
+
provider: "mailtrap",
|
|
643
|
+
...error.cause instanceof MailtrapTimeoutError ? {
|
|
644
|
+
category: "timeout",
|
|
645
|
+
code: "timeout"
|
|
646
|
+
} : {},
|
|
647
|
+
retryable: false,
|
|
648
|
+
attempts: error.attempts
|
|
649
|
+
});
|
|
611
650
|
if (error instanceof MailtrapApiError) return (0, __upyo_core.createFailedReceipt)(message, {
|
|
612
651
|
provider: "mailtrap",
|
|
613
652
|
statusCode: error.statusCode,
|
|
@@ -644,6 +683,7 @@ function isCallerAbort(error, signal) {
|
|
|
644
683
|
|
|
645
684
|
//#endregion
|
|
646
685
|
exports.MailtrapApiError = MailtrapApiError;
|
|
686
|
+
exports.MailtrapResponseError = MailtrapResponseError;
|
|
647
687
|
exports.MailtrapTimeoutError = MailtrapTimeoutError;
|
|
648
688
|
exports.MailtrapTransport = MailtrapTransport;
|
|
649
689
|
exports.createMailtrapConfig = createMailtrapConfig;
|
package/dist/index.d.cts
CHANGED
|
@@ -315,10 +315,31 @@ declare class MailtrapTimeoutError extends Error {
|
|
|
315
315
|
*/
|
|
316
316
|
constructor(timeout: number, attempts?: number);
|
|
317
317
|
}
|
|
318
|
+
/**
|
|
319
|
+
* Failure to read a successful Mailtrap response after the request was accepted.
|
|
320
|
+
* Retrying the request could send the message again.
|
|
321
|
+
*
|
|
322
|
+
* @since 0.6.0
|
|
323
|
+
*/
|
|
324
|
+
declare class MailtrapResponseError extends Error {
|
|
325
|
+
/**
|
|
326
|
+
* Number of attempts made before this error was produced.
|
|
327
|
+
*
|
|
328
|
+
* @since 0.6.0
|
|
329
|
+
*/
|
|
330
|
+
readonly attempts?: number;
|
|
331
|
+
/**
|
|
332
|
+
* Creates an error for an unreadable successful response.
|
|
333
|
+
*
|
|
334
|
+
* @param cause The response body error, including a possible timeout.
|
|
335
|
+
* @param attempts Number of attempts made before this error.
|
|
336
|
+
*/
|
|
337
|
+
constructor(cause: unknown, attempts?: number);
|
|
338
|
+
}
|
|
318
339
|
/**
|
|
319
340
|
* HTTP client wrapper for Mailtrap API requests.
|
|
320
341
|
*
|
|
321
342
|
* @since 0.6.0
|
|
322
343
|
*/
|
|
323
344
|
//#endregion
|
|
324
|
-
export { MailtrapAddress, MailtrapApiError, MailtrapAttachment, MailtrapBatchItemResponse, MailtrapBatchResponse, MailtrapConfig, MailtrapEmail, MailtrapError, MailtrapSendResponse, MailtrapTimeoutError, MailtrapTransport, ResolvedMailtrapConfig, createMailtrapConfig };
|
|
345
|
+
export { MailtrapAddress, MailtrapApiError, MailtrapAttachment, MailtrapBatchItemResponse, MailtrapBatchResponse, MailtrapConfig, MailtrapEmail, MailtrapError, MailtrapResponseError, MailtrapSendResponse, MailtrapTimeoutError, MailtrapTransport, ResolvedMailtrapConfig, createMailtrapConfig };
|
package/dist/index.d.ts
CHANGED
|
@@ -315,10 +315,31 @@ declare class MailtrapTimeoutError extends Error {
|
|
|
315
315
|
*/
|
|
316
316
|
constructor(timeout: number, attempts?: number);
|
|
317
317
|
}
|
|
318
|
+
/**
|
|
319
|
+
* Failure to read a successful Mailtrap response after the request was accepted.
|
|
320
|
+
* Retrying the request could send the message again.
|
|
321
|
+
*
|
|
322
|
+
* @since 0.6.0
|
|
323
|
+
*/
|
|
324
|
+
declare class MailtrapResponseError extends Error {
|
|
325
|
+
/**
|
|
326
|
+
* Number of attempts made before this error was produced.
|
|
327
|
+
*
|
|
328
|
+
* @since 0.6.0
|
|
329
|
+
*/
|
|
330
|
+
readonly attempts?: number;
|
|
331
|
+
/**
|
|
332
|
+
* Creates an error for an unreadable successful response.
|
|
333
|
+
*
|
|
334
|
+
* @param cause The response body error, including a possible timeout.
|
|
335
|
+
* @param attempts Number of attempts made before this error.
|
|
336
|
+
*/
|
|
337
|
+
constructor(cause: unknown, attempts?: number);
|
|
338
|
+
}
|
|
318
339
|
/**
|
|
319
340
|
* HTTP client wrapper for Mailtrap API requests.
|
|
320
341
|
*
|
|
321
342
|
* @since 0.6.0
|
|
322
343
|
*/
|
|
323
344
|
//#endregion
|
|
324
|
-
export { MailtrapAddress, MailtrapApiError, MailtrapAttachment, MailtrapBatchItemResponse, MailtrapBatchResponse, MailtrapConfig, MailtrapEmail, MailtrapError, MailtrapSendResponse, MailtrapTimeoutError, MailtrapTransport, ResolvedMailtrapConfig, createMailtrapConfig };
|
|
345
|
+
export { MailtrapAddress, MailtrapApiError, MailtrapAttachment, MailtrapBatchItemResponse, MailtrapBatchResponse, MailtrapConfig, MailtrapEmail, MailtrapError, MailtrapResponseError, MailtrapSendResponse, MailtrapTimeoutError, MailtrapTransport, ResolvedMailtrapConfig, createMailtrapConfig };
|
package/dist/index.js
CHANGED
|
@@ -104,6 +104,31 @@ var MailtrapTimeoutError = class extends Error {
|
|
|
104
104
|
}
|
|
105
105
|
};
|
|
106
106
|
/**
|
|
107
|
+
* Failure to read a successful Mailtrap response after the request was accepted.
|
|
108
|
+
* Retrying the request could send the message again.
|
|
109
|
+
*
|
|
110
|
+
* @since 0.6.0
|
|
111
|
+
*/
|
|
112
|
+
var MailtrapResponseError = class extends Error {
|
|
113
|
+
/**
|
|
114
|
+
* Number of attempts made before this error was produced.
|
|
115
|
+
*
|
|
116
|
+
* @since 0.6.0
|
|
117
|
+
*/
|
|
118
|
+
attempts;
|
|
119
|
+
/**
|
|
120
|
+
* Creates an error for an unreadable successful response.
|
|
121
|
+
*
|
|
122
|
+
* @param cause The response body error, including a possible timeout.
|
|
123
|
+
* @param attempts Number of attempts made before this error.
|
|
124
|
+
*/
|
|
125
|
+
constructor(cause, attempts) {
|
|
126
|
+
super(cause instanceof Error ? cause.message : String(cause), { cause });
|
|
127
|
+
this.name = "MailtrapResponseError";
|
|
128
|
+
this.attempts = attempts;
|
|
129
|
+
}
|
|
130
|
+
};
|
|
131
|
+
/**
|
|
107
132
|
* HTTP client wrapper for Mailtrap API requests.
|
|
108
133
|
*
|
|
109
134
|
* @since 0.6.0
|
|
@@ -159,6 +184,7 @@ var MailtrapHttpClient = class {
|
|
|
159
184
|
}
|
|
160
185
|
} catch (error) {
|
|
161
186
|
lastError = error instanceof Error ? error : new Error(String(error));
|
|
187
|
+
if (error instanceof MailtrapResponseError) throw new MailtrapResponseError(error.cause, attempt + 1);
|
|
162
188
|
if (error instanceof MailtrapApiError && !isRetryable(error)) throw error;
|
|
163
189
|
if (error instanceof Error && error.name === "AbortError" && signal?.aborted) throw error;
|
|
164
190
|
if (attempt === this.config.retries) throw withAttempts(lastError, attempt + 1);
|
|
@@ -183,8 +209,9 @@ var MailtrapHttpClient = class {
|
|
|
183
209
|
const timeoutController = new AbortController();
|
|
184
210
|
const timeoutId = this.config.timeout > 0 ? setTimeout(() => timeoutController.abort(), this.config.timeout) : void 0;
|
|
185
211
|
const requestSignal = combineSignals(timeoutController.signal, signal);
|
|
212
|
+
let response;
|
|
186
213
|
try {
|
|
187
|
-
|
|
214
|
+
response = await globalThis.fetch(url, {
|
|
188
215
|
method: "POST",
|
|
189
216
|
headers,
|
|
190
217
|
body: JSON.stringify(body),
|
|
@@ -196,8 +223,11 @@ var MailtrapHttpClient = class {
|
|
|
196
223
|
text
|
|
197
224
|
};
|
|
198
225
|
} catch (error) {
|
|
199
|
-
|
|
200
|
-
|
|
226
|
+
signal?.throwIfAborted();
|
|
227
|
+
let cause = error;
|
|
228
|
+
if (error instanceof Error && error.name === "AbortError" && timeoutController.signal.aborted && !signal?.aborted) cause = new MailtrapTimeoutError(this.config.timeout);
|
|
229
|
+
if (response?.ok) throw new MailtrapResponseError(cause);
|
|
230
|
+
throw cause;
|
|
201
231
|
} finally {
|
|
202
232
|
requestSignal.cleanup();
|
|
203
233
|
if (timeoutId !== void 0) clearTimeout(timeoutId);
|
|
@@ -378,7 +408,7 @@ function uint8ArrayToBase64(bytes) {
|
|
|
378
408
|
if (nativeToBase64 != null) return nativeToBase64();
|
|
379
409
|
const bufferBase64 = getBufferBase64(bytes);
|
|
380
410
|
if (bufferBase64 != null) return bufferBase64;
|
|
381
|
-
const chunkSize =
|
|
411
|
+
const chunkSize = 4096;
|
|
382
412
|
const chunks = [];
|
|
383
413
|
for (let offset = 0; offset < bytes.length; offset += chunkSize) chunks.push(String.fromCharCode(...bytes.subarray(offset, offset + chunkSize)));
|
|
384
414
|
return btoa(chunks.join(""));
|
|
@@ -585,6 +615,15 @@ function toReceipt(response, options) {
|
|
|
585
615
|
};
|
|
586
616
|
}
|
|
587
617
|
function createMailtrapFailure(message, error) {
|
|
618
|
+
if (error instanceof MailtrapResponseError) return createFailedReceipt(message, {
|
|
619
|
+
provider: "mailtrap",
|
|
620
|
+
...error.cause instanceof MailtrapTimeoutError ? {
|
|
621
|
+
category: "timeout",
|
|
622
|
+
code: "timeout"
|
|
623
|
+
} : {},
|
|
624
|
+
retryable: false,
|
|
625
|
+
attempts: error.attempts
|
|
626
|
+
});
|
|
588
627
|
if (error instanceof MailtrapApiError) return createFailedReceipt(message, {
|
|
589
628
|
provider: "mailtrap",
|
|
590
629
|
statusCode: error.statusCode,
|
|
@@ -620,4 +659,4 @@ function isCallerAbort(error, signal) {
|
|
|
620
659
|
}
|
|
621
660
|
|
|
622
661
|
//#endregion
|
|
623
|
-
export { MailtrapApiError, MailtrapTimeoutError, MailtrapTransport, createMailtrapConfig };
|
|
662
|
+
export { MailtrapApiError, MailtrapResponseError, MailtrapTimeoutError, MailtrapTransport, createMailtrapConfig };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@upyo/mailtrap",
|
|
3
|
-
"version": "0.6.0
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"description": "Mailtrap 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
|
|
56
|
+
"@upyo/core": "0.6.0"
|
|
57
57
|
},
|
|
58
58
|
"devDependencies": {
|
|
59
59
|
"tsdown": "^0.12.7",
|