@upyo/plunk 0.5.0-dev.158 → 0.5.0-dev.168
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 +41 -3
- package/dist/index.js +41 -3
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -118,6 +118,7 @@ var PlunkHttpClient = class {
|
|
|
118
118
|
const response = await this.makeRequest(url, emailData, signal);
|
|
119
119
|
return await this.parseResponse(response);
|
|
120
120
|
} catch (error) {
|
|
121
|
+
if (isCallerAbort$1(error, signal)) throw error;
|
|
121
122
|
lastError = error instanceof Error ? error : new Error(String(error));
|
|
122
123
|
if (error instanceof Error && error.name === "AbortError") throw error;
|
|
123
124
|
if (error instanceof PlunkApiError && error.statusCode !== void 0 && error.statusCode >= 400 && error.statusCode < 500) throw new PlunkApiError(error.message, error.statusCode, error.retryAfterMilliseconds, attempt + 1);
|
|
@@ -146,19 +147,20 @@ var PlunkHttpClient = class {
|
|
|
146
147
|
};
|
|
147
148
|
const timeoutController = new AbortController();
|
|
148
149
|
const timeoutId = this.config.timeout > 0 ? setTimeout(() => timeoutController.abort(), this.config.timeout) : void 0;
|
|
149
|
-
const
|
|
150
|
+
const combinedSignal = combineSignals(timeoutController.signal, signal);
|
|
150
151
|
let response;
|
|
151
152
|
try {
|
|
152
153
|
response = await fetch(url, {
|
|
153
154
|
method: "POST",
|
|
154
155
|
headers,
|
|
155
156
|
body: JSON.stringify(emailData),
|
|
156
|
-
signal:
|
|
157
|
+
signal: combinedSignal.signal
|
|
157
158
|
});
|
|
158
159
|
} catch (error) {
|
|
159
160
|
if (isAbortError$1(error) && timeoutController.signal.aborted && !signal?.aborted) throw new Error(`Plunk API request timed out after ${this.config.timeout} ms.`);
|
|
160
161
|
throw error;
|
|
161
162
|
} finally {
|
|
163
|
+
combinedSignal.cleanup();
|
|
162
164
|
if (timeoutId !== void 0) clearTimeout(timeoutId);
|
|
163
165
|
}
|
|
164
166
|
if (!response.ok) {
|
|
@@ -203,6 +205,39 @@ var PlunkHttpClient = class {
|
|
|
203
205
|
function isAbortError$1(error) {
|
|
204
206
|
return error instanceof Error && error.name === "AbortError";
|
|
205
207
|
}
|
|
208
|
+
function isCallerAbort$1(error, signal) {
|
|
209
|
+
return signal?.aborted === true && (isAbortError$1(error) || error === signal.reason);
|
|
210
|
+
}
|
|
211
|
+
function combineSignals(timeoutSignal, externalSignal) {
|
|
212
|
+
if (externalSignal == null) return {
|
|
213
|
+
signal: timeoutSignal,
|
|
214
|
+
cleanup: () => {}
|
|
215
|
+
};
|
|
216
|
+
if (typeof AbortSignal.any === "function") return {
|
|
217
|
+
signal: AbortSignal.any([timeoutSignal, externalSignal]),
|
|
218
|
+
cleanup: () => {}
|
|
219
|
+
};
|
|
220
|
+
const controller = new AbortController();
|
|
221
|
+
const abort = (signal) => {
|
|
222
|
+
controller.abort(getAbortReason(signal));
|
|
223
|
+
};
|
|
224
|
+
const abortTimeout = () => abort(timeoutSignal);
|
|
225
|
+
const abortExternal = () => abort(externalSignal);
|
|
226
|
+
timeoutSignal.addEventListener("abort", abortTimeout, { once: true });
|
|
227
|
+
externalSignal.addEventListener("abort", abortExternal, { once: true });
|
|
228
|
+
if (timeoutSignal.aborted) abortTimeout();
|
|
229
|
+
else if (externalSignal.aborted) abortExternal();
|
|
230
|
+
return {
|
|
231
|
+
signal: controller.signal,
|
|
232
|
+
cleanup: () => {
|
|
233
|
+
timeoutSignal.removeEventListener("abort", abortTimeout);
|
|
234
|
+
externalSignal.removeEventListener("abort", abortExternal);
|
|
235
|
+
}
|
|
236
|
+
};
|
|
237
|
+
}
|
|
238
|
+
function getAbortReason(signal) {
|
|
239
|
+
return signal.reason ?? new DOMException("The operation was aborted.", "AbortError");
|
|
240
|
+
}
|
|
206
241
|
function truncateErrorBody(text) {
|
|
207
242
|
return text.length > 500 ? `${text.slice(0, 500)}...` : text;
|
|
208
243
|
}
|
|
@@ -398,7 +433,7 @@ var PlunkTransport = class {
|
|
|
398
433
|
provider: "plunk"
|
|
399
434
|
};
|
|
400
435
|
} catch (error) {
|
|
401
|
-
if (
|
|
436
|
+
if (isCallerAbort(error, options?.signal)) throw error;
|
|
402
437
|
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
403
438
|
return createPlunkFailure(errorMessage, error);
|
|
404
439
|
}
|
|
@@ -501,6 +536,9 @@ function createPlunkFailure(message, error) {
|
|
|
501
536
|
function isAbortError(error) {
|
|
502
537
|
return error instanceof Error && error.name === "AbortError";
|
|
503
538
|
}
|
|
539
|
+
function isCallerAbort(error, signal) {
|
|
540
|
+
return signal?.aborted === true && (isAbortError(error) || error === signal.reason);
|
|
541
|
+
}
|
|
504
542
|
|
|
505
543
|
//#endregion
|
|
506
544
|
exports.PlunkTransport = PlunkTransport;
|
package/dist/index.js
CHANGED
|
@@ -95,6 +95,7 @@ var PlunkHttpClient = class {
|
|
|
95
95
|
const response = await this.makeRequest(url, emailData, signal);
|
|
96
96
|
return await this.parseResponse(response);
|
|
97
97
|
} catch (error) {
|
|
98
|
+
if (isCallerAbort$1(error, signal)) throw error;
|
|
98
99
|
lastError = error instanceof Error ? error : new Error(String(error));
|
|
99
100
|
if (error instanceof Error && error.name === "AbortError") throw error;
|
|
100
101
|
if (error instanceof PlunkApiError && error.statusCode !== void 0 && error.statusCode >= 400 && error.statusCode < 500) throw new PlunkApiError(error.message, error.statusCode, error.retryAfterMilliseconds, attempt + 1);
|
|
@@ -123,19 +124,20 @@ var PlunkHttpClient = class {
|
|
|
123
124
|
};
|
|
124
125
|
const timeoutController = new AbortController();
|
|
125
126
|
const timeoutId = this.config.timeout > 0 ? setTimeout(() => timeoutController.abort(), this.config.timeout) : void 0;
|
|
126
|
-
const
|
|
127
|
+
const combinedSignal = combineSignals(timeoutController.signal, signal);
|
|
127
128
|
let response;
|
|
128
129
|
try {
|
|
129
130
|
response = await fetch(url, {
|
|
130
131
|
method: "POST",
|
|
131
132
|
headers,
|
|
132
133
|
body: JSON.stringify(emailData),
|
|
133
|
-
signal:
|
|
134
|
+
signal: combinedSignal.signal
|
|
134
135
|
});
|
|
135
136
|
} catch (error) {
|
|
136
137
|
if (isAbortError$1(error) && timeoutController.signal.aborted && !signal?.aborted) throw new Error(`Plunk API request timed out after ${this.config.timeout} ms.`);
|
|
137
138
|
throw error;
|
|
138
139
|
} finally {
|
|
140
|
+
combinedSignal.cleanup();
|
|
139
141
|
if (timeoutId !== void 0) clearTimeout(timeoutId);
|
|
140
142
|
}
|
|
141
143
|
if (!response.ok) {
|
|
@@ -180,6 +182,39 @@ var PlunkHttpClient = class {
|
|
|
180
182
|
function isAbortError$1(error) {
|
|
181
183
|
return error instanceof Error && error.name === "AbortError";
|
|
182
184
|
}
|
|
185
|
+
function isCallerAbort$1(error, signal) {
|
|
186
|
+
return signal?.aborted === true && (isAbortError$1(error) || error === signal.reason);
|
|
187
|
+
}
|
|
188
|
+
function combineSignals(timeoutSignal, externalSignal) {
|
|
189
|
+
if (externalSignal == null) return {
|
|
190
|
+
signal: timeoutSignal,
|
|
191
|
+
cleanup: () => {}
|
|
192
|
+
};
|
|
193
|
+
if (typeof AbortSignal.any === "function") return {
|
|
194
|
+
signal: AbortSignal.any([timeoutSignal, externalSignal]),
|
|
195
|
+
cleanup: () => {}
|
|
196
|
+
};
|
|
197
|
+
const controller = new AbortController();
|
|
198
|
+
const abort = (signal) => {
|
|
199
|
+
controller.abort(getAbortReason(signal));
|
|
200
|
+
};
|
|
201
|
+
const abortTimeout = () => abort(timeoutSignal);
|
|
202
|
+
const abortExternal = () => abort(externalSignal);
|
|
203
|
+
timeoutSignal.addEventListener("abort", abortTimeout, { once: true });
|
|
204
|
+
externalSignal.addEventListener("abort", abortExternal, { once: true });
|
|
205
|
+
if (timeoutSignal.aborted) abortTimeout();
|
|
206
|
+
else if (externalSignal.aborted) abortExternal();
|
|
207
|
+
return {
|
|
208
|
+
signal: controller.signal,
|
|
209
|
+
cleanup: () => {
|
|
210
|
+
timeoutSignal.removeEventListener("abort", abortTimeout);
|
|
211
|
+
externalSignal.removeEventListener("abort", abortExternal);
|
|
212
|
+
}
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
function getAbortReason(signal) {
|
|
216
|
+
return signal.reason ?? new DOMException("The operation was aborted.", "AbortError");
|
|
217
|
+
}
|
|
183
218
|
function truncateErrorBody(text) {
|
|
184
219
|
return text.length > 500 ? `${text.slice(0, 500)}...` : text;
|
|
185
220
|
}
|
|
@@ -375,7 +410,7 @@ var PlunkTransport = class {
|
|
|
375
410
|
provider: "plunk"
|
|
376
411
|
};
|
|
377
412
|
} catch (error) {
|
|
378
|
-
if (
|
|
413
|
+
if (isCallerAbort(error, options?.signal)) throw error;
|
|
379
414
|
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
380
415
|
return createPlunkFailure(errorMessage, error);
|
|
381
416
|
}
|
|
@@ -478,6 +513,9 @@ function createPlunkFailure(message, error) {
|
|
|
478
513
|
function isAbortError(error) {
|
|
479
514
|
return error instanceof Error && error.name === "AbortError";
|
|
480
515
|
}
|
|
516
|
+
function isCallerAbort(error, signal) {
|
|
517
|
+
return signal?.aborted === true && (isAbortError(error) || error === signal.reason);
|
|
518
|
+
}
|
|
481
519
|
|
|
482
520
|
//#endregion
|
|
483
521
|
export { PlunkTransport };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@upyo/plunk",
|
|
3
|
-
"version": "0.5.0-dev.
|
|
3
|
+
"version": "0.5.0-dev.168",
|
|
4
4
|
"description": "Plunk 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.5.0-dev.
|
|
56
|
+
"@upyo/core": "0.5.0-dev.168+1e808a3a"
|
|
57
57
|
},
|
|
58
58
|
"devDependencies": {
|
|
59
59
|
"tsdown": "^0.12.7",
|