@upyo/resend 0.5.0-dev.168 → 0.5.0-dev.172

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
@@ -160,7 +160,7 @@ var ResendHttpClient = class {
160
160
  throw new Error(`Invalid JSON response from Resend API: ${parseError instanceof Error ? parseError.message : String(parseError)}`);
161
161
  }
162
162
  } catch (error) {
163
- if (isCallerAbort(error, options.signal)) throw error;
163
+ if (isCallerAbort$1(error, options.signal)) throw error;
164
164
  lastError = error instanceof Error ? error : new Error(String(error));
165
165
  if (error instanceof ResendApiError && error.statusCode !== void 0 && error.statusCode >= 400 && error.statusCode < 500) throw error;
166
166
  if (error instanceof Error && error.name === "AbortError") throw error;
@@ -186,7 +186,7 @@ var ResendHttpClient = class {
186
186
  for (const [key, value] of Object.entries(this.config.headers)) headers.set(key, value);
187
187
  const controller = new AbortController();
188
188
  const timeoutId = setTimeout(() => controller.abort(), this.config.timeout);
189
- const combinedSignal = combineSignals(controller.signal, options.signal);
189
+ const combinedSignal = (0, __upyo_core.combineSignals)(controller.signal, options.signal);
190
190
  try {
191
191
  const response = await fetch(url, {
192
192
  ...options,
@@ -203,40 +203,10 @@ var ResendHttpClient = class {
203
203
  }
204
204
  }
205
205
  };
206
- function combineSignals(timeoutSignal, externalSignal) {
207
- if (externalSignal == null) return {
208
- signal: timeoutSignal,
209
- cleanup: () => {}
210
- };
211
- if (typeof AbortSignal.any === "function") return {
212
- signal: AbortSignal.any([timeoutSignal, externalSignal]),
213
- cleanup: () => {}
214
- };
215
- const controller = new AbortController();
216
- const abort = (signal) => {
217
- controller.abort(getAbortReason(signal));
218
- };
219
- const abortTimeout = () => abort(timeoutSignal);
220
- const abortExternal = () => abort(externalSignal);
221
- timeoutSignal.addEventListener("abort", abortTimeout, { once: true });
222
- externalSignal.addEventListener("abort", abortExternal, { once: true });
223
- if (timeoutSignal.aborted) abortTimeout();
224
- else if (externalSignal.aborted) abortExternal();
225
- return {
226
- signal: controller.signal,
227
- cleanup: () => {
228
- timeoutSignal.removeEventListener("abort", abortTimeout);
229
- externalSignal.removeEventListener("abort", abortExternal);
230
- }
231
- };
232
- }
233
- function getAbortReason(signal) {
234
- return signal.reason ?? new DOMException("The operation was aborted.", "AbortError");
235
- }
236
206
  function isAbortError$1(error) {
237
207
  return error instanceof Error && error.name === "AbortError";
238
208
  }
239
- function isCallerAbort(error, signal) {
209
+ function isCallerAbort$1(error, signal) {
240
210
  return signal?.aborted === true && (isAbortError$1(error) || error === signal.reason);
241
211
  }
242
212
  function truncateErrorBody(text) {
@@ -491,7 +461,7 @@ var ResendTransport = class {
491
461
  provider: "resend"
492
462
  };
493
463
  } catch (error) {
494
- if (isAbortError(error) && options?.signal?.aborted) throw error;
464
+ if (isCallerAbort(error, options?.signal)) throw error;
495
465
  const errorMessage = error instanceof Error ? error.message : String(error);
496
466
  return createResendFailure(errorMessage, error);
497
467
  }
@@ -606,7 +576,7 @@ var ResendTransport = class {
606
576
  provider: "resend"
607
577
  };
608
578
  } catch (error) {
609
- if (isAbortError(error) && options?.signal?.aborted) throw error;
579
+ if (isCallerAbort(error, options?.signal)) throw error;
610
580
  const errorMessage = error instanceof Error ? error.message : String(error);
611
581
  for (let i = 0; i < messages.length; i++) yield createResendFailure(errorMessage, error);
612
582
  }
@@ -650,6 +620,9 @@ function createResendFailure(message, error) {
650
620
  function isAbortError(error) {
651
621
  return error instanceof Error && error.name === "AbortError";
652
622
  }
623
+ function isCallerAbort(error, signal) {
624
+ return signal?.aborted === true && (isAbortError(error) || error === signal.reason);
625
+ }
653
626
 
654
627
  //#endregion
655
628
  exports.ResendTransport = ResendTransport;
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { createFailedReceipt, parseRetryAfter } from "@upyo/core";
1
+ import { combineSignals, createFailedReceipt, parseRetryAfter } from "@upyo/core";
2
2
 
3
3
  //#region src/config.ts
4
4
  /**
@@ -137,7 +137,7 @@ var ResendHttpClient = class {
137
137
  throw new Error(`Invalid JSON response from Resend API: ${parseError instanceof Error ? parseError.message : String(parseError)}`);
138
138
  }
139
139
  } catch (error) {
140
- if (isCallerAbort(error, options.signal)) throw error;
140
+ if (isCallerAbort$1(error, options.signal)) throw error;
141
141
  lastError = error instanceof Error ? error : new Error(String(error));
142
142
  if (error instanceof ResendApiError && error.statusCode !== void 0 && error.statusCode >= 400 && error.statusCode < 500) throw error;
143
143
  if (error instanceof Error && error.name === "AbortError") throw error;
@@ -180,40 +180,10 @@ var ResendHttpClient = class {
180
180
  }
181
181
  }
182
182
  };
183
- function combineSignals(timeoutSignal, externalSignal) {
184
- if (externalSignal == null) return {
185
- signal: timeoutSignal,
186
- cleanup: () => {}
187
- };
188
- if (typeof AbortSignal.any === "function") return {
189
- signal: AbortSignal.any([timeoutSignal, externalSignal]),
190
- cleanup: () => {}
191
- };
192
- const controller = new AbortController();
193
- const abort = (signal) => {
194
- controller.abort(getAbortReason(signal));
195
- };
196
- const abortTimeout = () => abort(timeoutSignal);
197
- const abortExternal = () => abort(externalSignal);
198
- timeoutSignal.addEventListener("abort", abortTimeout, { once: true });
199
- externalSignal.addEventListener("abort", abortExternal, { once: true });
200
- if (timeoutSignal.aborted) abortTimeout();
201
- else if (externalSignal.aborted) abortExternal();
202
- return {
203
- signal: controller.signal,
204
- cleanup: () => {
205
- timeoutSignal.removeEventListener("abort", abortTimeout);
206
- externalSignal.removeEventListener("abort", abortExternal);
207
- }
208
- };
209
- }
210
- function getAbortReason(signal) {
211
- return signal.reason ?? new DOMException("The operation was aborted.", "AbortError");
212
- }
213
183
  function isAbortError$1(error) {
214
184
  return error instanceof Error && error.name === "AbortError";
215
185
  }
216
- function isCallerAbort(error, signal) {
186
+ function isCallerAbort$1(error, signal) {
217
187
  return signal?.aborted === true && (isAbortError$1(error) || error === signal.reason);
218
188
  }
219
189
  function truncateErrorBody(text) {
@@ -468,7 +438,7 @@ var ResendTransport = class {
468
438
  provider: "resend"
469
439
  };
470
440
  } catch (error) {
471
- if (isAbortError(error) && options?.signal?.aborted) throw error;
441
+ if (isCallerAbort(error, options?.signal)) throw error;
472
442
  const errorMessage = error instanceof Error ? error.message : String(error);
473
443
  return createResendFailure(errorMessage, error);
474
444
  }
@@ -583,7 +553,7 @@ var ResendTransport = class {
583
553
  provider: "resend"
584
554
  };
585
555
  } catch (error) {
586
- if (isAbortError(error) && options?.signal?.aborted) throw error;
556
+ if (isCallerAbort(error, options?.signal)) throw error;
587
557
  const errorMessage = error instanceof Error ? error.message : String(error);
588
558
  for (let i = 0; i < messages.length; i++) yield createResendFailure(errorMessage, error);
589
559
  }
@@ -627,6 +597,9 @@ function createResendFailure(message, error) {
627
597
  function isAbortError(error) {
628
598
  return error instanceof Error && error.name === "AbortError";
629
599
  }
600
+ function isCallerAbort(error, signal) {
601
+ return signal?.aborted === true && (isAbortError(error) || error === signal.reason);
602
+ }
630
603
 
631
604
  //#endregion
632
605
  export { ResendTransport };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@upyo/resend",
3
- "version": "0.5.0-dev.168",
3
+ "version": "0.5.0-dev.172",
4
4
  "description": "Resend 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.168+1e808a3a"
56
+ "@upyo/core": "0.5.0-dev.172+1b1248e1"
57
57
  },
58
58
  "devDependencies": {
59
59
  "tsdown": "^0.12.7",