@superutils/fetch 1.2.2 → 1.3.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.
Files changed (4) hide show
  1. package/README.md +130 -61
  2. package/dist/index.d.ts +462 -245
  3. package/dist/index.js +256 -170
  4. package/package.json +5 -5
package/dist/index.js CHANGED
@@ -1,21 +1,24 @@
1
1
  // src/createClient.ts
2
- import PromisE3 from "@superutils/promise";
2
+ import { deferredCallback } from "@superutils/promise";
3
3
 
4
4
  // src/fetch.ts
5
5
  import {
6
- fallbackIfFails as fallbackIfFails2,
6
+ fallbackIfFails as fallbackIfFails3,
7
7
  isFn as isFn2,
8
8
  isPositiveNumber,
9
9
  isPromise,
10
10
  isUrlValid
11
11
  } from "@superutils/core";
12
- import PromisE2 from "@superutils/promise";
12
+ import {
13
+ timeout as PromisE_timeout
14
+ } from "@superutils/promise";
13
15
 
14
16
  // src/executeInterceptors.ts
15
17
  import { fallbackIfFails, isFn } from "@superutils/core";
16
- var executeInterceptors = async (value, interceptors = [], ...args) => {
18
+ var executeInterceptors = async (value, signal, interceptors, ...args) => {
17
19
  var _a;
18
- for (const interceptor of [...interceptors || []].filter(isFn)) {
20
+ for (const interceptor of [...interceptors != null ? interceptors : []].filter(isFn)) {
21
+ if (signal == null ? void 0 : signal.aborted) return value;
19
22
  value = (_a = await fallbackIfFails(
20
23
  interceptor,
21
24
  [value, ...args],
@@ -26,24 +29,48 @@ var executeInterceptors = async (value, interceptors = [], ...args) => {
26
29
  };
27
30
  var executeInterceptors_default = executeInterceptors;
28
31
 
32
+ // src/getAbortCtrl.ts
33
+ var getAbortCtrl = (options) => {
34
+ options != null ? options : options = {};
35
+ if (!(options.abortCtrl instanceof AbortController))
36
+ options.abortCtrl = new AbortController();
37
+ const { abortCtrl, signal } = options;
38
+ if (signal instanceof AbortSignal && !signal.aborted) {
39
+ const handleAbort = () => abortCtrl.abort();
40
+ signal.addEventListener("abort", handleAbort, { once: true });
41
+ abortCtrl.signal.addEventListener(
42
+ "abort",
43
+ () => signal.removeEventListener("abort", handleAbort),
44
+ { once: true }
45
+ );
46
+ }
47
+ return abortCtrl;
48
+ };
49
+
29
50
  // src/getResponse.ts
30
- import PromisE from "@superutils/promise";
31
- import { isPositiveInteger } from "@superutils/core";
32
- var getResponse = async (...[url, options = {}]) => {
33
- const fetchFunc = globalThis.fetch;
51
+ import { fallbackIfFails as fallbackIfFails2, isPositiveInteger } from "@superutils/core";
52
+ import { retry } from "@superutils/promise";
53
+ var getResponse = async (url, options = {}) => {
54
+ const { abortCtrl, fetchFunc = globalThis.fetch } = options;
34
55
  if (!isPositiveInteger(options.retry))
35
56
  return fetchFunc(url, options);
36
57
  let attemptCount = 0;
37
- const response = PromisE.retry(
58
+ const response = retry(
38
59
  () => {
39
60
  attemptCount++;
40
61
  return fetchFunc(url, options);
41
62
  },
42
63
  {
43
64
  ...options,
44
- retryIf: async (res, count) => {
45
- var _a;
46
- return (res == null ? void 0 : res.ok) === false || await ((_a = options == null ? void 0 : options.retryIf) == null ? void 0 : _a.call(options, res, count)) === true;
65
+ retryIf: async (res, count, error) => {
66
+ var _a, _b;
67
+ if (abortCtrl == null ? void 0 : abortCtrl.signal.aborted) return false;
68
+ const failed = !!error || !(res == null ? void 0 : res.ok);
69
+ return !!((_b = await fallbackIfFails2(
70
+ (_a = options == null ? void 0 : options.retryIf) != null ? _a : failed,
71
+ [res, count, error],
72
+ failed
73
+ )) != null ? _b : failed);
47
74
  }
48
75
  }
49
76
  ).catch(
@@ -58,21 +85,22 @@ var getResponse = async (...[url, options = {}]) => {
58
85
  var getResponse_default = getResponse;
59
86
 
60
87
  // src/mergeFetchOptions.ts
61
- import { isEmpty, objKeys } from "@superutils/core";
88
+ import { isEmpty, isObj, objKeys } from "@superutils/core";
62
89
  var mergeFetchOptions = (...allOptions) => allOptions.reduce(
63
- (o1, o2) => {
64
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
65
- const { errMsgs = {}, headers, interceptors: ints1 = {} } = o1;
66
- const { errMsgs: msgs2 = {}, interceptors: ints2 = {} } = o2;
67
- o2.headers && new Headers(o2.headers).forEach((value, key) => {
90
+ (merged, next) => {
91
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i;
92
+ next = isObj(next) ? next : {};
93
+ const { errMsgs = {}, headers, interceptors: ints1 = {} } = merged;
94
+ const { errMsgs: msgs2 = {}, interceptors: ints2 = {} } = next;
95
+ next.headers && new Headers(next.headers).forEach((value, key) => {
68
96
  headers && headers.set(key, value);
69
97
  });
70
98
  for (const key of objKeys(msgs2)) {
71
99
  if (!isEmpty(msgs2[key])) errMsgs[key] = msgs2[key];
72
100
  }
73
101
  return {
74
- ...o1,
75
- ...o2,
102
+ ...merged,
103
+ ...next,
76
104
  errMsgs,
77
105
  headers,
78
106
  interceptors: {
@@ -90,7 +118,7 @@ var mergeFetchOptions = (...allOptions) => allOptions.reduce(
90
118
  ...(_h = ints2 == null ? void 0 : ints2.result) != null ? _h : []
91
119
  ]
92
120
  },
93
- timeout: (_j = (_i = o2.timeout) != null ? _i : o1.timeout) != null ? _j : 0
121
+ timeout: (_i = next.timeout) != null ? _i : merged.timeout
94
122
  };
95
123
  },
96
124
  { headers: new Headers() }
@@ -101,11 +129,22 @@ var mergePartialOptions = (...optionsAr) => {
101
129
  return optionsAr.length <= 1 ? optionsAr[0] : mergeFetchOptions(...optionsAr);
102
130
  };
103
131
 
104
- // src/types.ts
105
- import {
106
- ResolveError,
107
- ResolveIgnored
108
- } from "@superutils/promise";
132
+ // src/types/constants.ts
133
+ var ContentType = {
134
+ APPLICATION_JAVASCRIPT: "application/javascript",
135
+ APPLICATION_JSON: "application/json",
136
+ APPLICATION_OCTET_STREAM: "application/octet-stream",
137
+ APPLICATION_PDF: "application/pdf",
138
+ APPLICATION_X_WWW_FORM_URLENCODED: "application/x-www-form-urlencoded",
139
+ APPLICATION_XML: "application/xml",
140
+ APPLICATION_ZIP: "application/zip",
141
+ AUDIO_MPEG: "audio/mpeg",
142
+ MULTIPART_FORM_DATA: "multipart/form-data",
143
+ TEXT_CSS: "text/css",
144
+ TEXT_HTML: "text/html",
145
+ TEXT_PLAIN: "text/plain",
146
+ VIDEO_MP4: "video/mp4"
147
+ };
109
148
  var FetchAs = /* @__PURE__ */ ((FetchAs2) => {
110
149
  FetchAs2["arrayBuffer"] = "arrayBuffer";
111
150
  FetchAs2["blob"] = "blob";
@@ -116,161 +155,195 @@ var FetchAs = /* @__PURE__ */ ((FetchAs2) => {
116
155
  FetchAs2["text"] = "text";
117
156
  return FetchAs2;
118
157
  })(FetchAs || {});
158
+
159
+ // src/types/FetchError.ts
119
160
  var FetchError = class _FetchError extends Error {
120
161
  constructor(message, options) {
121
162
  super(message, { cause: options.cause });
122
- this.clone = (newMessage) => new _FetchError(newMessage, {
123
- cause: this.cause,
124
- options: this.options,
125
- response: this.response,
126
- url: this.url
127
- });
128
163
  this.name = "FetchError";
129
- this.options = options.options;
130
- this.response = options.response;
131
- this.url = options.url;
164
+ Object.defineProperties(this, {
165
+ clone: {
166
+ get() {
167
+ return (newMessage) => new _FetchError(newMessage, {
168
+ cause: options.cause,
169
+ options: options.options,
170
+ response: options.response,
171
+ url: options.url
172
+ });
173
+ }
174
+ },
175
+ options: {
176
+ get() {
177
+ return options.options;
178
+ }
179
+ },
180
+ response: {
181
+ get() {
182
+ return options.response;
183
+ }
184
+ },
185
+ url: {
186
+ get() {
187
+ return options.url;
188
+ }
189
+ }
190
+ });
132
191
  }
133
192
  };
134
193
 
194
+ // src/types/options.ts
195
+ import {
196
+ ResolveError,
197
+ ResolveIgnored
198
+ } from "@superutils/promise";
199
+
135
200
  // src/fetch.ts
201
+ var MAX_TIMEOUT = 2147483647;
136
202
  var fetch = (url, options = {}) => {
137
- let abortCtrl;
138
- let timeoutId;
139
- const promise = new PromisE2(async (resolve, reject) => {
140
- var _a, _b, _c;
141
- let errResponse;
142
- const _options2 = mergeFetchOptions_default(fetch.defaults, options);
143
- (_a = _options2.as) != null ? _a : _options2.as = "json" /* json */;
144
- (_b = _options2.method) != null ? _b : _options2.method = "get";
145
- _options2.abortCtrl = _options2.abortCtrl instanceof AbortController ? _options2.abortCtrl : new AbortController();
146
- url = await executeInterceptors_default(
203
+ var _a, _b, _c;
204
+ let errResponse;
205
+ const _options = mergeFetchOptions_default(fetch.defaults, options);
206
+ _options.abortCtrl = getAbortCtrl(_options);
207
+ (_a = _options.as) != null ? _a : _options.as = "json" /* json */;
208
+ (_b = _options.method) != null ? _b : _options.method = "get";
209
+ (_c = _options.signal) != null ? _c : _options.signal = _options.abortCtrl.signal;
210
+ _options.timeout = Math.min(
211
+ isPositiveNumber(_options.timeout) ? _options.timeout : fetch.defaults.timeout,
212
+ MAX_TIMEOUT
213
+ );
214
+ const { abortCtrl, as: parseAs, headers, timeout } = _options;
215
+ let contentType = headers.get("content-type");
216
+ if (!contentType) {
217
+ headers.set("content-type", ContentType.APPLICATION_JSON);
218
+ contentType = ContentType.APPLICATION_JSON;
219
+ }
220
+ const processErr = (err) => {
221
+ var _a2, _b2, _c2, _d, _e;
222
+ let msg = (_a2 = err == null ? void 0 : err.message) != null ? _a2 : err;
223
+ if ((err == null ? void 0 : err.name) === "AbortError") msg = (_c2 = (_b2 = _options.errMsgs) == null ? void 0 : _b2.aborted) != null ? _c2 : msg;
224
+ return executeInterceptors_default(
225
+ new FetchError(msg, {
226
+ cause: (_d = err == null ? void 0 : err.cause) != null ? _d : err,
227
+ response: errResponse,
228
+ options: _options,
229
+ url
230
+ }),
231
+ void 0,
232
+ // should execute regardless of abort status
233
+ (_e = _options.interceptors) == null ? void 0 : _e.error,
147
234
  url,
148
- _options2.interceptors.request,
149
- _options2
150
- );
151
- const {
152
- as: parseAs,
153
- body,
154
- errMsgs,
155
- timeout,
156
- validateUrl = true
157
- } = _options2;
158
- if (isPositiveNumber(timeout)) {
159
- timeoutId = setTimeout(() => {
160
- var _a2;
161
- return (_a2 = _options2.abortCtrl) == null ? void 0 : _a2.abort();
162
- }, timeout);
163
- }
164
- abortCtrl = _options2.abortCtrl;
165
- if (_options2.abortCtrl) _options2.signal = _options2.abortCtrl.signal;
235
+ _options
236
+ ).then((err2) => Promise.reject(err2));
237
+ };
238
+ const start = async () => {
239
+ var _a2, _b2, _c2, _d;
166
240
  try {
241
+ url = await executeInterceptors_default(
242
+ url,
243
+ abortCtrl.signal,
244
+ (_a2 = _options.interceptors) == null ? void 0 : _a2.request,
245
+ _options
246
+ );
247
+ const { body, errMsgs, validateUrl = true } = _options;
248
+ (_b2 = _options.signal) != null ? _b2 : _options.signal = abortCtrl.signal;
167
249
  if (validateUrl && !isUrlValid(url, false))
168
- throw new Error(errMsgs.invalidUrl);
169
- if (!["undefined", "string"].includes(typeof body))
170
- _options2.body = JSON.stringify(
171
- isFn2(body) ? fallbackIfFails2(body, [], void 0) : body
250
+ return processErr(new Error(errMsgs.invalidUrl));
251
+ const shouldStringifyBody = [
252
+ ContentType.APPLICATION_JSON,
253
+ ContentType.APPLICATION_X_WWW_FORM_URLENCODED
254
+ ].find((x) => contentType.includes(x)) && !["undefined", "string"].includes(typeof body);
255
+ if (shouldStringifyBody)
256
+ _options.body = JSON.stringify(
257
+ isFn2(body) ? fallbackIfFails3(body, [], void 0) : body
172
258
  );
173
- let response = await getResponse_default(url, _options2);
259
+ let response = await getResponse_default(url, _options);
174
260
  response = await executeInterceptors_default(
175
261
  response,
176
- _options2.interceptors.response,
262
+ abortCtrl.signal,
263
+ (_c2 = _options.interceptors) == null ? void 0 : _c2.response,
177
264
  url,
178
- _options2
265
+ _options
179
266
  );
180
267
  errResponse = response;
181
268
  const { status = 0 } = response;
182
269
  const isSuccess = status >= 200 && status < 300;
183
270
  if (!isSuccess) {
184
- const fallbackMsg = `${errMsgs.requestFailed} ${status}`;
185
- const jsonError = await fallbackIfFails2(
271
+ const jsonError = await fallbackIfFails3(
186
272
  // try to parse error response as json first
187
273
  () => response.json(),
188
274
  [],
189
275
  void 0
190
276
  );
191
- const message = (jsonError == null ? void 0 : jsonError.message) || fallbackMsg;
192
- throw new Error(`${message}`.replace("Error: ", ""), {
193
- cause: jsonError
194
- });
277
+ throw new Error(
278
+ (jsonError == null ? void 0 : jsonError.message) || `${errMsgs.requestFailed} ${status}`,
279
+ { cause: jsonError }
280
+ );
195
281
  }
196
- let result = response;
197
282
  const parseFunc = response[parseAs];
198
- if (isFn2(parseFunc)) {
199
- const handleErr = (err) => {
200
- err = new Error(
201
- `${errMsgs.parseFailed} ${parseAs}. ${err == null ? void 0 : err.message}`,
202
- { cause: err }
203
- );
204
- return Promise.reject(err);
205
- };
206
- result = parseFunc.bind(response)();
207
- if (isPromise(result)) result = result.catch(handleErr);
208
- }
283
+ let result = !isFn2(parseFunc) ? response : parseFunc.bind(response)();
284
+ if (isPromise(result))
285
+ result = await result.catch(
286
+ (err) => Promise.reject(
287
+ new Error(
288
+ `${errMsgs.parseFailed} ${parseAs}. ${err == null ? void 0 : err.message}`,
289
+ { cause: err }
290
+ )
291
+ )
292
+ );
209
293
  result = await executeInterceptors_default(
210
294
  result,
211
- _options2.interceptors.result,
212
- url,
213
- _options2
214
- );
215
- resolve(result);
216
- } catch (err) {
217
- const errX = err;
218
- const msg = (errX == null ? void 0 : errX.name) === "AbortError" ? errMsgs.reqTimedout : err == null ? void 0 : err.message;
219
- let error = new FetchError(msg, {
220
- cause: (_c = errX == null ? void 0 : errX.cause) != null ? _c : err,
221
- response: errResponse,
222
- options: _options2,
223
- url
224
- });
225
- error = await executeInterceptors_default(
226
- error,
227
- _options2.interceptors.error,
295
+ abortCtrl.signal,
296
+ (_d = _options.interceptors) == null ? void 0 : _d.result,
228
297
  url,
229
- _options2
298
+ _options
230
299
  );
231
- reject(error);
300
+ return result;
301
+ } catch (_err) {
302
+ return processErr(_err);
232
303
  }
233
- timeoutId && clearTimeout(timeoutId);
234
- });
235
- promise.onEarlyFinalize.push(() => abortCtrl == null ? void 0 : abortCtrl.abort());
236
- return promise;
304
+ };
305
+ return PromisE_timeout(
306
+ {
307
+ ...options,
308
+ abortCtrl,
309
+ onAbort: () => processErr(new Error(_options.errMsgs.aborted)),
310
+ onTimeout: async () => processErr(new Error(_options.errMsgs.timedout)),
311
+ signal: _options.signal,
312
+ timeout
313
+ },
314
+ start
315
+ );
237
316
  };
238
317
  fetch.defaults = {
239
318
  errMsgs: {
319
+ aborted: "Request aborted",
240
320
  invalidUrl: "Invalid URL",
241
321
  parseFailed: "Failed to parse response as",
242
- reqTimedout: "Request timed out",
322
+ timedout: "Request timed out",
243
323
  requestFailed: "Request failed with status code:"
244
324
  },
245
325
  // all error messages must be defined here
246
- headers: new Headers([["content-type", "application/json"]]),
247
- /** Global interceptors for fetch requests */
326
+ headers: new Headers(),
248
327
  interceptors: {
249
- /**
250
- * Global error interceptors to be invoked whenever an exception occurs
251
- * Returning an
252
- */
253
328
  error: [],
254
- /** Interceptors to be invoked before making fetch requests */
255
329
  request: [],
256
330
  response: [],
257
331
  result: []
258
332
  },
259
- /** Request timeout duration in milliseconds. Default: `0` */
260
- timeout: 0,
333
+ timeout: 3e4,
261
334
  validateUrl: true
262
335
  };
263
336
  var fetch_default = fetch;
264
337
 
265
338
  // src/createClient.ts
266
- var createClient = (mandatoryOptions, commonOptions, commonDeferOptions) => {
339
+ var createClient = (fixedOptions, commonOptions, commonDeferOptions) => {
267
340
  const func = (url, options) => {
268
341
  return fetch_default(
269
342
  url,
270
343
  mergePartialOptions(
271
344
  commonOptions,
272
345
  options,
273
- mandatoryOptions
346
+ fixedOptions
274
347
  )
275
348
  );
276
349
  };
@@ -282,11 +355,10 @@ var createClient = (mandatoryOptions, commonOptions, commonDeferOptions) => {
282
355
  commonOptions,
283
356
  defaultOptions,
284
357
  defaultUrl === void 0 ? args[1] : args[0],
285
- mandatoryOptions
358
+ fixedOptions
286
359
  );
287
- (_a = options.abortCtrl) != null ? _a : options.abortCtrl = new AbortController();
288
- (_b = _abortCtrl == null ? void 0 : _abortCtrl.abort) == null ? void 0 : _b.call(_abortCtrl);
289
- _abortCtrl = options.abortCtrl;
360
+ ((_a = _abortCtrl == null ? void 0 : _abortCtrl.signal) == null ? void 0 : _a.aborted) === false && ((_b = _abortCtrl == null ? void 0 : _abortCtrl.abort) == null ? void 0 : _b.call(_abortCtrl));
361
+ _abortCtrl = getAbortCtrl(options);
290
362
  const promise = fetch_default(
291
363
  defaultUrl != null ? defaultUrl : args[0],
292
364
  options
@@ -294,7 +366,7 @@ var createClient = (mandatoryOptions, commonOptions, commonDeferOptions) => {
294
366
  promise.onEarlyFinalize.push(() => _abortCtrl == null ? void 0 : _abortCtrl.abort());
295
367
  return promise;
296
368
  };
297
- return PromisE3.deferredCallback(fetchCb, {
369
+ return deferredCallback(fetchCb, {
298
370
  ...commonDeferOptions,
299
371
  ...deferOptions
300
372
  });
@@ -304,20 +376,20 @@ var createClient = (mandatoryOptions, commonOptions, commonDeferOptions) => {
304
376
  var createClient_default = createClient;
305
377
 
306
378
  // src/createPostClient.ts
307
- import PromisE4 from "@superutils/promise";
308
- var createPostClient = (mandatoryOptions, commonOptions, commonDeferOptions) => {
309
- const func = (url, data, options) => {
379
+ import { deferredCallback as deferredCallback2 } from "@superutils/promise";
380
+ var createPostClient = (fixedOptions, commonOptions, commonDeferOptions) => {
381
+ const client = (url, data, options) => {
310
382
  var _a;
311
- const _options2 = mergePartialOptions(
383
+ const _options = mergePartialOptions(
312
384
  commonOptions,
313
385
  options,
314
- mandatoryOptions
386
+ fixedOptions
315
387
  );
316
- _options2.body = data;
317
- (_a = _options2.method) != null ? _a : _options2.method = "post";
318
- return fetch_default(url, _options2);
388
+ _options.body = data;
389
+ (_a = _options.method) != null ? _a : _options.method = "post";
390
+ return fetch_default(url, _options);
319
391
  };
320
- func.deferred = (deferOptions = {}, defaultUrl, defaultData, defaultOptions) => {
392
+ client.deferred = (deferOptions = {}, defaultUrl, defaultData, defaultOptions) => {
321
393
  let _abortCtrl;
322
394
  const postCb = (...args) => {
323
395
  var _a, _b, _c, _d;
@@ -327,45 +399,34 @@ var createPostClient = (mandatoryOptions, commonOptions, commonDeferOptions) =>
327
399
  commonOptions,
328
400
  defaultOptions,
329
401
  args[2],
330
- mandatoryOptions
402
+ fixedOptions
331
403
  );
332
- (_a = options.abortCtrl) != null ? _a : options.abortCtrl = new AbortController();
333
- (_b = _abortCtrl == null ? void 0 : _abortCtrl.abort) == null ? void 0 : _b.call(_abortCtrl);
334
- _abortCtrl = options.abortCtrl;
404
+ ((_a = _abortCtrl == null ? void 0 : _abortCtrl.signal) == null ? void 0 : _a.aborted) === false && ((_b = _abortCtrl == null ? void 0 : _abortCtrl.abort) == null ? void 0 : _b.call(_abortCtrl));
405
+ _abortCtrl = getAbortCtrl(options);
335
406
  options.body = (_c = args[1]) != null ? _c : options.body;
336
407
  (_d = options.method) != null ? _d : options.method = "post";
337
408
  const promise = fetch_default(args[0], options);
338
409
  promise.onEarlyFinalize.push(() => _abortCtrl == null ? void 0 : _abortCtrl.abort());
339
410
  return promise;
340
411
  };
341
- return PromisE4.deferredCallback(postCb, {
412
+ return deferredCallback2(postCb, {
342
413
  ...commonDeferOptions,
343
414
  ...deferOptions
344
415
  });
345
416
  };
346
- return func;
417
+ return client;
347
418
  };
348
419
  var createPostClient_default = createPostClient;
349
420
 
350
421
  // src/fetchResponse.ts
351
- var fetchResponse = (...args) => {
352
- var _a, _b, _c;
353
- (_a = args[1]) != null ? _a : args[1] = {};
354
- (_c = (_b = args[1]).as) != null ? _c : _b.as = "response" /* response */;
355
- return fetch_default(...args);
422
+ var fetchResponse = (url, options) => {
423
+ var _a;
424
+ options != null ? options : options = {};
425
+ (_a = options.as) != null ? _a : options.as = "response" /* response */;
426
+ return fetch_default(url, options);
356
427
  };
357
- var fetchResponse_default = fetchResponse;
358
-
359
- // src/fetchDefault.ts
360
- var _get = createClient_default({ method: "get" });
361
- var _head = createClient_default({ method: "head" });
362
- var _options = createClient_default({ method: "options" });
363
- var _delete = createPostClient_default({ method: "delete" });
364
- var _patch = createPostClient_default({ method: "patch" });
365
- var _post = createPostClient_default({ method: "post" });
366
- var _put = createPostClient_default({ method: "put" });
367
- var fetchDefault = fetchResponse_default;
368
- Object.defineProperty(fetchDefault, "defaults", {
428
+ fetchResponse.defaults = fetch_default.defaults;
429
+ Object.defineProperty(fetchResponse, "defaults", {
369
430
  get() {
370
431
  return fetch_default.defaults;
371
432
  },
@@ -373,27 +434,52 @@ Object.defineProperty(fetchDefault, "defaults", {
373
434
  fetch_default.defaults = newDefaults;
374
435
  }
375
436
  });
376
- fetchDefault.delete = _delete;
377
- fetchDefault.get = _get;
378
- fetchDefault.head = _head;
379
- fetchDefault.options = _options;
380
- fetchDefault.patch = _patch;
381
- fetchDefault.post = _post;
382
- fetchDefault.put = _put;
383
- var fetchDefault_default = fetchDefault;
437
+ var fetchResponse_default = fetchResponse;
438
+
439
+ // src/defaultFetch.ts
440
+ var methods = {
441
+ /** Make HTTP requests with method GET */
442
+ get: createClient_default({ method: "get" }),
443
+ /** Make HTTP requests with method HEAD */
444
+ head: createClient_default({ method: "head" }),
445
+ /** Make HTTP requests with method OPTIONS */
446
+ options: createClient_default({ method: "options" }),
447
+ /** Make HTTP requests with method DELETE */
448
+ delete: createPostClient_default({ method: "delete" }),
449
+ /** Make HTTP requests with method PATCH */
450
+ patch: createPostClient_default({ method: "patch" }),
451
+ /** Make HTTP requests with method POST */
452
+ post: createPostClient_default({ method: "post" }),
453
+ /** Make HTTP requests with method PUT */
454
+ put: createPostClient_default({ method: "put" })
455
+ };
456
+ var defaultFetch = fetchResponse_default;
457
+ defaultFetch.delete = methods.delete;
458
+ defaultFetch.get = methods.get;
459
+ defaultFetch.head = methods.head;
460
+ defaultFetch.options = methods.options;
461
+ defaultFetch.patch = methods.patch;
462
+ defaultFetch.post = methods.post;
463
+ defaultFetch.put = methods.put;
464
+ var defaultFetch_default = defaultFetch;
384
465
 
385
466
  // src/index.ts
386
- var index_default = fetchDefault_default;
467
+ var index_default = defaultFetch_default;
387
468
  export {
469
+ ContentType,
388
470
  FetchAs,
389
471
  FetchError,
472
+ MAX_TIMEOUT,
390
473
  ResolveError,
391
474
  ResolveIgnored,
392
475
  createClient,
393
476
  createPostClient,
394
477
  index_default as default,
478
+ executeInterceptors,
395
479
  fetch,
396
480
  fetchResponse,
481
+ getAbortCtrl,
482
+ getResponse,
397
483
  mergeFetchOptions,
398
484
  mergePartialOptions
399
485
  };
package/package.json CHANGED
@@ -5,8 +5,8 @@
5
5
  },
6
6
  "description": "A lightweight `fetch` wrapper for browsers and Node.js, designed to simplify data fetching and reduce boilerplate.",
7
7
  "dependencies": {
8
- "@superutils/core": "^1.1.5",
9
- "@superutils/promise": "^1.1.5"
8
+ "@superutils/core": "^1.1.8",
9
+ "@superutils/promise": "^1.2.0"
10
10
  },
11
11
  "files": [
12
12
  "dist",
@@ -24,8 +24,8 @@
24
24
  "main": "dist/index.js",
25
25
  "name": "@superutils/fetch",
26
26
  "peerDependencies": {
27
- "@superutils/core": "^1.1.5",
28
- "@superutils/promise": "^1.1.5"
27
+ "@superutils/core": "^1.2.0",
28
+ "@superutils/promise": "^1.1.7"
29
29
  },
30
30
  "publishConfig": {
31
31
  "access": "public"
@@ -45,5 +45,5 @@
45
45
  "sideEffects": false,
46
46
  "type": "module",
47
47
  "types": "dist/index.d.ts",
48
- "version": "1.2.2"
48
+ "version": "1.3.0"
49
49
  }