@upyo/sendgrid 0.5.0-dev.156 → 0.5.0-dev.164

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
@@ -85,6 +85,9 @@ var SendGridHttpClient = class {
85
85
  * @param url The URL to make the request to.
86
86
  * @param options Fetch options.
87
87
  * @returns Promise that resolves to the parsed response.
88
+ * @throws {DOMException} If the caller aborts the request.
89
+ * @throws {SendGridApiError} If SendGrid returns a client error or all retry
90
+ * attempts are exhausted.
88
91
  */
89
92
  async makeRequest(url, options) {
90
93
  let lastError = null;
@@ -112,7 +115,7 @@ var SendGridHttpClient = class {
112
115
  throw new SendGridApiError(lastError.message, void 0, void 0, void 0, attempt + 1);
113
116
  }
114
117
  const delay = Math.pow(2, attempt) * 1e3;
115
- await new Promise((resolve) => setTimeout(resolve, delay));
118
+ await sleep(delay, options.signal);
116
119
  }
117
120
  throw lastError || /* @__PURE__ */ new Error("Request failed after all retries");
118
121
  }
@@ -122,6 +125,8 @@ var SendGridHttpClient = class {
122
125
  * @param url The URL to make the request to.
123
126
  * @param options Fetch options.
124
127
  * @returns Promise that resolves to the fetch response.
128
+ * @throws {Error} If the configured request timeout is reached.
129
+ * @throws {DOMException} If the caller aborts the request.
125
130
  */
126
131
  async fetchWithAuth(url, options) {
127
132
  const headers = new Headers(options.headers);
@@ -198,6 +203,24 @@ var SendGridApiError = class extends Error {
198
203
  function isAbortError$1(error) {
199
204
  return error instanceof Error && error.name === "AbortError";
200
205
  }
206
+ function sleep(milliseconds, signal) {
207
+ if (signal?.aborted) return Promise.reject(createAbortError());
208
+ return new Promise((resolve, reject) => {
209
+ function abort() {
210
+ clearTimeout(timeoutId);
211
+ signal?.removeEventListener("abort", abort);
212
+ reject(createAbortError());
213
+ }
214
+ const timeoutId = setTimeout(() => {
215
+ signal?.removeEventListener("abort", abort);
216
+ resolve();
217
+ }, milliseconds);
218
+ signal?.addEventListener("abort", abort, { once: true });
219
+ });
220
+ }
221
+ function createAbortError() {
222
+ return new DOMException("The operation was aborted.", "AbortError");
223
+ }
201
224
 
202
225
  //#endregion
203
226
  //#region src/message-converter.ts
package/dist/index.js CHANGED
@@ -62,6 +62,9 @@ var SendGridHttpClient = class {
62
62
  * @param url The URL to make the request to.
63
63
  * @param options Fetch options.
64
64
  * @returns Promise that resolves to the parsed response.
65
+ * @throws {DOMException} If the caller aborts the request.
66
+ * @throws {SendGridApiError} If SendGrid returns a client error or all retry
67
+ * attempts are exhausted.
65
68
  */
66
69
  async makeRequest(url, options) {
67
70
  let lastError = null;
@@ -89,7 +92,7 @@ var SendGridHttpClient = class {
89
92
  throw new SendGridApiError(lastError.message, void 0, void 0, void 0, attempt + 1);
90
93
  }
91
94
  const delay = Math.pow(2, attempt) * 1e3;
92
- await new Promise((resolve) => setTimeout(resolve, delay));
95
+ await sleep(delay, options.signal);
93
96
  }
94
97
  throw lastError || /* @__PURE__ */ new Error("Request failed after all retries");
95
98
  }
@@ -99,6 +102,8 @@ var SendGridHttpClient = class {
99
102
  * @param url The URL to make the request to.
100
103
  * @param options Fetch options.
101
104
  * @returns Promise that resolves to the fetch response.
105
+ * @throws {Error} If the configured request timeout is reached.
106
+ * @throws {DOMException} If the caller aborts the request.
102
107
  */
103
108
  async fetchWithAuth(url, options) {
104
109
  const headers = new Headers(options.headers);
@@ -175,6 +180,24 @@ var SendGridApiError = class extends Error {
175
180
  function isAbortError$1(error) {
176
181
  return error instanceof Error && error.name === "AbortError";
177
182
  }
183
+ function sleep(milliseconds, signal) {
184
+ if (signal?.aborted) return Promise.reject(createAbortError());
185
+ return new Promise((resolve, reject) => {
186
+ function abort() {
187
+ clearTimeout(timeoutId);
188
+ signal?.removeEventListener("abort", abort);
189
+ reject(createAbortError());
190
+ }
191
+ const timeoutId = setTimeout(() => {
192
+ signal?.removeEventListener("abort", abort);
193
+ resolve();
194
+ }, milliseconds);
195
+ signal?.addEventListener("abort", abort, { once: true });
196
+ });
197
+ }
198
+ function createAbortError() {
199
+ return new DOMException("The operation was aborted.", "AbortError");
200
+ }
178
201
 
179
202
  //#endregion
180
203
  //#region src/message-converter.ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@upyo/sendgrid",
3
- "version": "0.5.0-dev.156",
3
+ "version": "0.5.0-dev.164",
4
4
  "description": "SendGrid 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.156+edad9790"
56
+ "@upyo/core": "0.5.0-dev.164+5e283c64"
57
57
  },
58
58
  "devDependencies": {
59
59
  "tsdown": "^0.12.7",