vigor-fetch 1.0.5 → 1.0.7
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.d.mts +2 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +12 -4
- package/dist/index.mjs +12 -3
- package/package.json +11 -13
package/dist/index.d.mts
CHANGED
|
@@ -71,5 +71,6 @@ declare class Vigor {
|
|
|
71
71
|
fetch<T = any>(origin: string, config?: VigorFetchConfig): VigorFetch<T>;
|
|
72
72
|
all(config?: VigorAllConfig): VigorAll;
|
|
73
73
|
}
|
|
74
|
+
declare const vigor: Vigor;
|
|
74
75
|
|
|
75
|
-
export { type VigorAllConfig, type VigorErrorOptions, type VigorFetchConfig,
|
|
76
|
+
export { type VigorAllConfig, type VigorErrorOptions, type VigorFetchConfig, vigor as default };
|
package/dist/index.d.ts
CHANGED
|
@@ -71,5 +71,6 @@ declare class Vigor {
|
|
|
71
71
|
fetch<T = any>(origin: string, config?: VigorFetchConfig): VigorFetch<T>;
|
|
72
72
|
all(config?: VigorAllConfig): VigorAll;
|
|
73
73
|
}
|
|
74
|
+
declare const vigor: Vigor;
|
|
74
75
|
|
|
75
|
-
export { type VigorAllConfig, type VigorErrorOptions, type VigorFetchConfig,
|
|
76
|
+
export { type VigorAllConfig, type VigorErrorOptions, type VigorFetchConfig, vigor as default };
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
var __defProp = Object.defineProperty;
|
|
3
2
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
3
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
@@ -24,6 +23,9 @@ __export(index_exports, {
|
|
|
24
23
|
});
|
|
25
24
|
module.exports = __toCommonJS(index_exports);
|
|
26
25
|
var VigorError = class extends Error {
|
|
26
|
+
url;
|
|
27
|
+
status;
|
|
28
|
+
data;
|
|
27
29
|
constructor(text, { url = null, status = 0, message, data = null }) {
|
|
28
30
|
super(text);
|
|
29
31
|
this.name = "VigorError";
|
|
@@ -34,6 +36,8 @@ var VigorError = class extends Error {
|
|
|
34
36
|
}
|
|
35
37
|
};
|
|
36
38
|
var VigorFetch = class _VigorFetch {
|
|
39
|
+
_origin;
|
|
40
|
+
_config;
|
|
37
41
|
constructor(origin, config) {
|
|
38
42
|
this._origin = origin;
|
|
39
43
|
this._config = config || {
|
|
@@ -195,7 +199,7 @@ var VigorFetch = class _VigorFetch {
|
|
|
195
199
|
if (unretry.has(status)) throw new VigorError(`[vigor] ${url} >> Unretry ${status}`, { url, status, message: "Unretry", data: status });
|
|
196
200
|
const basic = Math.min(Math.pow(backoff, i) * 1e3, wait) + Math.random() * jitter;
|
|
197
201
|
if (status === 429) {
|
|
198
|
-
const rHeader = retryHeader.map((h) => req
|
|
202
|
+
const rHeader = retryHeader.map((h) => req == null ? void 0 : req.headers.get(h)).find(Boolean);
|
|
199
203
|
const delay = rHeader ? isNaN(Number(rHeader)) ? new Date(rHeader).getTime() - Date.now() : Number(rHeader) * 1e3 : 0;
|
|
200
204
|
const parsedDelay = Math.max(0, delay) + Math.random() * jitter;
|
|
201
205
|
if (parsedDelay > wait) throw new VigorError(`[vigor] ${url} >> Timeouted ${parsedDelay}ms`, { url, status, message: "Timeouted", data: parsedDelay });
|
|
@@ -238,6 +242,7 @@ var VigorFetch = class _VigorFetch {
|
|
|
238
242
|
}
|
|
239
243
|
};
|
|
240
244
|
var VigorAll = class _VigorAll {
|
|
245
|
+
_config;
|
|
241
246
|
constructor(config) {
|
|
242
247
|
this._config = config || { limit: 10, jitter: 1e3, promises: [] };
|
|
243
248
|
}
|
|
@@ -266,8 +271,9 @@ var VigorAll = class _VigorAll {
|
|
|
266
271
|
}
|
|
267
272
|
const ready = await Promise.allSettled(results);
|
|
268
273
|
return ready.map((i) => {
|
|
274
|
+
var _a, _b;
|
|
269
275
|
if (i.status === "fulfilled") return i.value;
|
|
270
|
-
return i.reason instanceof VigorError ? i.reason : new VigorError(i.reason
|
|
276
|
+
return i.reason instanceof VigorError ? i.reason : new VigorError(((_a = i.reason) == null ? void 0 : _a.message) || "Unknown", { message: ((_b = i.reason) == null ? void 0 : _b.message) || "Unknown" });
|
|
271
277
|
});
|
|
272
278
|
}
|
|
273
279
|
};
|
|
@@ -279,4 +285,6 @@ var Vigor = class {
|
|
|
279
285
|
return new VigorAll(config);
|
|
280
286
|
}
|
|
281
287
|
};
|
|
282
|
-
var
|
|
288
|
+
var vigor = new Vigor();
|
|
289
|
+
var index_default = vigor;
|
|
290
|
+
if (module.exports.default) module.exports = module.exports.default;
|
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
// src/index.ts
|
|
2
2
|
var VigorError = class extends Error {
|
|
3
|
+
url;
|
|
4
|
+
status;
|
|
5
|
+
data;
|
|
3
6
|
constructor(text, { url = null, status = 0, message, data = null }) {
|
|
4
7
|
super(text);
|
|
5
8
|
this.name = "VigorError";
|
|
@@ -10,6 +13,8 @@ var VigorError = class extends Error {
|
|
|
10
13
|
}
|
|
11
14
|
};
|
|
12
15
|
var VigorFetch = class _VigorFetch {
|
|
16
|
+
_origin;
|
|
17
|
+
_config;
|
|
13
18
|
constructor(origin, config) {
|
|
14
19
|
this._origin = origin;
|
|
15
20
|
this._config = config || {
|
|
@@ -171,7 +176,7 @@ var VigorFetch = class _VigorFetch {
|
|
|
171
176
|
if (unretry.has(status)) throw new VigorError(`[vigor] ${url} >> Unretry ${status}`, { url, status, message: "Unretry", data: status });
|
|
172
177
|
const basic = Math.min(Math.pow(backoff, i) * 1e3, wait) + Math.random() * jitter;
|
|
173
178
|
if (status === 429) {
|
|
174
|
-
const rHeader = retryHeader.map((h) => req
|
|
179
|
+
const rHeader = retryHeader.map((h) => req == null ? void 0 : req.headers.get(h)).find(Boolean);
|
|
175
180
|
const delay = rHeader ? isNaN(Number(rHeader)) ? new Date(rHeader).getTime() - Date.now() : Number(rHeader) * 1e3 : 0;
|
|
176
181
|
const parsedDelay = Math.max(0, delay) + Math.random() * jitter;
|
|
177
182
|
if (parsedDelay > wait) throw new VigorError(`[vigor] ${url} >> Timeouted ${parsedDelay}ms`, { url, status, message: "Timeouted", data: parsedDelay });
|
|
@@ -214,6 +219,7 @@ var VigorFetch = class _VigorFetch {
|
|
|
214
219
|
}
|
|
215
220
|
};
|
|
216
221
|
var VigorAll = class _VigorAll {
|
|
222
|
+
_config;
|
|
217
223
|
constructor(config) {
|
|
218
224
|
this._config = config || { limit: 10, jitter: 1e3, promises: [] };
|
|
219
225
|
}
|
|
@@ -242,8 +248,9 @@ var VigorAll = class _VigorAll {
|
|
|
242
248
|
}
|
|
243
249
|
const ready = await Promise.allSettled(results);
|
|
244
250
|
return ready.map((i) => {
|
|
251
|
+
var _a, _b;
|
|
245
252
|
if (i.status === "fulfilled") return i.value;
|
|
246
|
-
return i.reason instanceof VigorError ? i.reason : new VigorError(i.reason
|
|
253
|
+
return i.reason instanceof VigorError ? i.reason : new VigorError(((_a = i.reason) == null ? void 0 : _a.message) || "Unknown", { message: ((_b = i.reason) == null ? void 0 : _b.message) || "Unknown" });
|
|
247
254
|
});
|
|
248
255
|
}
|
|
249
256
|
};
|
|
@@ -255,7 +262,9 @@ var Vigor = class {
|
|
|
255
262
|
return new VigorAll(config);
|
|
256
263
|
}
|
|
257
264
|
};
|
|
258
|
-
var
|
|
265
|
+
var vigor = new Vigor();
|
|
266
|
+
var index_default = vigor;
|
|
259
267
|
export {
|
|
260
268
|
index_default as default
|
|
261
269
|
};
|
|
270
|
+
if (module.exports.default) module.exports = module.exports.default;
|
package/package.json
CHANGED
|
@@ -1,28 +1,23 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vigor-fetch",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.7",
|
|
4
4
|
"description": "Smart, zero-dependency HTTP client with self-healing retries for rate-limited servers.",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
|
+
"module": "./dist/index.mjs",
|
|
6
7
|
"types": "./dist/index.d.ts",
|
|
7
8
|
"exports": {
|
|
8
9
|
".": {
|
|
9
|
-
"
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
},
|
|
13
|
-
"import": {
|
|
14
|
-
"types": "./dist/index.d.mts",
|
|
15
|
-
"default": "./dist/index.mjs"
|
|
16
|
-
}
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.mjs",
|
|
12
|
+
"require": "./dist/index.js"
|
|
17
13
|
}
|
|
18
14
|
},
|
|
15
|
+
"scripts": {
|
|
16
|
+
"build": "tsup"
|
|
17
|
+
},
|
|
19
18
|
"files": [
|
|
20
19
|
"dist"
|
|
21
20
|
],
|
|
22
|
-
"scripts": {
|
|
23
|
-
"build": "tsup src/index.ts --format cjs,esm --dts --clean",
|
|
24
|
-
"dev": "tsup src/index.ts --format cjs,esm --watch --dts"
|
|
25
|
-
},
|
|
26
21
|
"keywords": [
|
|
27
22
|
"fetch",
|
|
28
23
|
"PromiseAll",
|
|
@@ -35,6 +30,9 @@
|
|
|
35
30
|
"author": "Uav1010",
|
|
36
31
|
"license": "MIT",
|
|
37
32
|
"devDependencies": {
|
|
33
|
+
"@rollup/plugin-typescript": "^11.1.6",
|
|
34
|
+
"rollup": "^4.59.0",
|
|
35
|
+
"tslib": "^2.8.1",
|
|
38
36
|
"tsup": "^8.5.1",
|
|
39
37
|
"typescript": "^5.9.3"
|
|
40
38
|
},
|