@upyo/jmap 0.5.0-dev.164 → 0.5.0-dev.170

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
@@ -92,13 +92,13 @@ async function uploadBlob(config, uploadUrl, accountId, blob, signal) {
92
92
  for (const [key, value] of Object.entries(config.headers)) headers[key] = value;
93
93
  const controller = new AbortController();
94
94
  const timeoutId = setTimeout(() => controller.abort(), config.timeout);
95
- const combinedSignal = signal ? combineSignals(signal, controller.signal) : controller.signal;
95
+ const combinedSignal = (0, __upyo_core.combineSignals)(controller.signal, signal);
96
96
  try {
97
97
  const response = await fetch(url, {
98
98
  method: "POST",
99
99
  headers,
100
100
  body: blob,
101
- signal: combinedSignal
101
+ signal: combinedSignal.signal
102
102
  });
103
103
  if (!response.ok) {
104
104
  const body = await response.text();
@@ -107,23 +107,10 @@ async function uploadBlob(config, uploadUrl, accountId, blob, signal) {
107
107
  const result = await response.json();
108
108
  return result;
109
109
  } finally {
110
+ combinedSignal.cleanup();
110
111
  clearTimeout(timeoutId);
111
112
  }
112
113
  }
113
- /**
114
- * Combine multiple abort signals into one.
115
- */
116
- function combineSignals(...signals) {
117
- const controller = new AbortController();
118
- for (const signal of signals) {
119
- if (signal.aborted) {
120
- controller.abort(signal.reason);
121
- break;
122
- }
123
- signal.addEventListener("abort", () => controller.abort(signal.reason), { once: true });
124
- }
125
- return controller.signal;
126
- }
127
114
 
128
115
  //#endregion
129
116
  //#region src/config.ts
@@ -208,12 +195,16 @@ var JmapHttpClient = class {
208
195
  if (error.statusCode >= 400 && error.statusCode < 500) throw error;
209
196
  }
210
197
  lastError = error instanceof Error ? error : new Error(String(error));
211
- if (attempt === this.config.retries) throw error;
198
+ if (attempt === this.config.retries) {
199
+ if (error instanceof JmapApiError) throw error;
200
+ throw new JmapApiError(lastError.message, void 0, void 0, void 0, void 0, attempt + 1);
201
+ }
212
202
  const delay = Math.pow(2, attempt) * 1e3;
213
203
  await new Promise((resolve) => setTimeout(resolve, delay));
214
204
  }
215
205
  }
216
- throw lastError || /* @__PURE__ */ new Error("Request failed after all retries");
206
+ if (lastError != null) throw lastError;
207
+ throw new Error("Request failed after all retries");
217
208
  }
218
209
  /**
219
210
  * Makes an authenticated fetch request.
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/errors.ts
4
4
  /**
@@ -69,13 +69,13 @@ async function uploadBlob(config, uploadUrl, accountId, blob, signal) {
69
69
  for (const [key, value] of Object.entries(config.headers)) headers[key] = value;
70
70
  const controller = new AbortController();
71
71
  const timeoutId = setTimeout(() => controller.abort(), config.timeout);
72
- const combinedSignal = signal ? combineSignals(signal, controller.signal) : controller.signal;
72
+ const combinedSignal = combineSignals(controller.signal, signal);
73
73
  try {
74
74
  const response = await fetch(url, {
75
75
  method: "POST",
76
76
  headers,
77
77
  body: blob,
78
- signal: combinedSignal
78
+ signal: combinedSignal.signal
79
79
  });
80
80
  if (!response.ok) {
81
81
  const body = await response.text();
@@ -84,23 +84,10 @@ async function uploadBlob(config, uploadUrl, accountId, blob, signal) {
84
84
  const result = await response.json();
85
85
  return result;
86
86
  } finally {
87
+ combinedSignal.cleanup();
87
88
  clearTimeout(timeoutId);
88
89
  }
89
90
  }
90
- /**
91
- * Combine multiple abort signals into one.
92
- */
93
- function combineSignals(...signals) {
94
- const controller = new AbortController();
95
- for (const signal of signals) {
96
- if (signal.aborted) {
97
- controller.abort(signal.reason);
98
- break;
99
- }
100
- signal.addEventListener("abort", () => controller.abort(signal.reason), { once: true });
101
- }
102
- return controller.signal;
103
- }
104
91
 
105
92
  //#endregion
106
93
  //#region src/config.ts
@@ -185,12 +172,16 @@ var JmapHttpClient = class {
185
172
  if (error.statusCode >= 400 && error.statusCode < 500) throw error;
186
173
  }
187
174
  lastError = error instanceof Error ? error : new Error(String(error));
188
- if (attempt === this.config.retries) throw error;
175
+ if (attempt === this.config.retries) {
176
+ if (error instanceof JmapApiError) throw error;
177
+ throw new JmapApiError(lastError.message, void 0, void 0, void 0, void 0, attempt + 1);
178
+ }
189
179
  const delay = Math.pow(2, attempt) * 1e3;
190
180
  await new Promise((resolve) => setTimeout(resolve, delay));
191
181
  }
192
182
  }
193
- throw lastError || /* @__PURE__ */ new Error("Request failed after all retries");
183
+ if (lastError != null) throw lastError;
184
+ throw new Error("Request failed after all retries");
194
185
  }
195
186
  /**
196
187
  * Makes an authenticated fetch request.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@upyo/jmap",
3
- "version": "0.5.0-dev.164",
3
+ "version": "0.5.0-dev.170",
4
4
  "description": "JMAP 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.164+5e283c64"
56
+ "@upyo/core": "0.5.0-dev.170+643994fd"
57
57
  },
58
58
  "devDependencies": {
59
59
  "jmap-rfc-types": "^0.1.2",