rekwest 5.1.0 → 5.2.1

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/src/cookies.mjs CHANGED
@@ -1,100 +1,100 @@
1
- import {
2
- brandCheck,
3
- toCamelCase,
4
- } from './utils.mjs';
5
-
6
- const lifetimeCap = 3456e7; // 400 days
7
-
8
- export class Cookies extends URLSearchParams {
9
-
10
- static #finalizers = new Set();
11
- static jar = new Map();
12
-
13
- static #register(target, value) {
14
- const finalizer = new FinalizationRegistry((heldValue) => {
15
- clearTimeout(heldValue);
16
- this.#finalizers.delete(finalizer);
17
- });
18
-
19
- finalizer.register(target, value);
20
- this.#finalizers.add(finalizer);
21
- }
22
-
23
- #chronometry = new Map();
24
-
25
- get [Symbol.toStringTag]() {
26
- return this.constructor.name;
27
- }
28
-
29
- constructor(input, { cookiesTTL } = { cookiesTTL: false }) {
30
- if (Array.isArray(input) && input.every((it) => !Array.isArray(it))) {
31
- input = input.map((it) => {
32
- if (!cookiesTTL) {
33
- return [it.split(';').at(0).trim()];
34
- }
35
-
36
- const [cookie, ...attrs] = it.split(';').map((it) => it.trim());
37
- const ttl = {};
38
-
39
- for (const val of attrs) {
40
- if (/(?:Expires|Max-Age)=/i.test(val)) {
41
- const [key, value] = val.toLowerCase().split('=');
42
- const ms = Number.isFinite(Number(value)) ? value * 1e3 : Date.parse(value) - Date.now();
43
-
44
- ttl[toCamelCase(key)] = Math.min(ms, lifetimeCap);
45
- }
46
- }
47
-
48
- return [
49
- cookie.replace(/\u0022/g, ''),
50
- Object.keys(ttl).length ? ttl : null,
51
- ];
52
- });
53
- }
54
-
55
- super(Array.isArray(input) ? input.map((it) => it.at(0)).join('&') : input);
56
-
57
- if (Array.isArray(input) && cookiesTTL) {
58
- for (const [cookie, ttl] of input.filter((it) => it.at(1))) {
59
- const key = cookie.split('=').at(0);
60
-
61
- if (this.#chronometry.has(key)) {
62
- clearTimeout(this.#chronometry.get(key));
63
- this.#chronometry.delete(key);
64
- }
65
-
66
- const { expires, maxAge } = ttl;
67
-
68
- for (const ms of [
69
- maxAge,
70
- expires,
71
- ]) {
72
- if (!Number.isInteger(ms)) {
73
- continue;
74
- }
75
-
76
- const ref = new WeakRef(this);
77
- const tid = setTimeout(() => {
78
- const ctx = ref.deref();
79
-
80
- if (ctx) {
81
- ctx.#chronometry.delete(key);
82
- ctx.delete(key);
83
- }
84
- }, Math.max(ms, 0));
85
-
86
- this.constructor.#register(this, tid);
87
- this.#chronometry.set(key, tid);
88
- break;
89
- }
90
- }
91
- }
92
- }
93
-
94
- toString() {
95
- brandCheck(this, Cookies);
96
-
97
- return super.toString().split('&').join('; ').trim();
98
- }
99
-
100
- }
1
+ import {
2
+ brandCheck,
3
+ toCamelCase,
4
+ } from './utils.mjs';
5
+
6
+ const lifetimeCap = 3456e7; // 400 days
7
+
8
+ export class Cookies extends URLSearchParams {
9
+
10
+ static #finalizers = new Set();
11
+ static jar = new Map();
12
+
13
+ static #register(target, value) {
14
+ const finalizer = new FinalizationRegistry((heldValue) => {
15
+ clearTimeout(heldValue);
16
+ this.#finalizers.delete(finalizer);
17
+ });
18
+
19
+ finalizer.register(target, value);
20
+ this.#finalizers.add(finalizer);
21
+ }
22
+
23
+ #chronometry = new Map();
24
+
25
+ get [Symbol.toStringTag]() {
26
+ return this.constructor.name;
27
+ }
28
+
29
+ constructor(input, { cookiesTTL } = { cookiesTTL: false }) {
30
+ if (Array.isArray(input) && input.every((it) => !Array.isArray(it))) {
31
+ input = input.map((it) => {
32
+ if (!cookiesTTL) {
33
+ return [it.split(';').at(0).trim()];
34
+ }
35
+
36
+ const [cookie, ...attrs] = it.split(';').map((it) => it.trim());
37
+ const ttl = {};
38
+
39
+ for (const val of attrs) {
40
+ if (/(?:Expires|Max-Age)=/i.test(val)) {
41
+ const [key, value] = val.toLowerCase().split('=');
42
+ const ms = Number.isFinite(Number(value)) ? value * 1e3 : Date.parse(value) - Date.now();
43
+
44
+ ttl[toCamelCase(key)] = Math.min(ms, lifetimeCap);
45
+ }
46
+ }
47
+
48
+ return [
49
+ cookie.replace(/\u0022/g, ''),
50
+ Object.keys(ttl).length ? ttl : null,
51
+ ];
52
+ });
53
+ }
54
+
55
+ super(Array.isArray(input) ? input.map((it) => it.at(0)).join('&') : input);
56
+
57
+ if (Array.isArray(input) && cookiesTTL) {
58
+ for (const [cookie, ttl] of input.filter((it) => it.at(1))) {
59
+ const key = cookie.split('=').at(0);
60
+
61
+ if (this.#chronometry.has(key)) {
62
+ clearTimeout(this.#chronometry.get(key));
63
+ this.#chronometry.delete(key);
64
+ }
65
+
66
+ const { expires, maxAge } = ttl;
67
+
68
+ for (const ms of [
69
+ maxAge,
70
+ expires,
71
+ ]) {
72
+ if (!Number.isInteger(ms)) {
73
+ continue;
74
+ }
75
+
76
+ const ref = new WeakRef(this);
77
+ const tid = setTimeout(() => {
78
+ const ctx = ref.deref();
79
+
80
+ if (ctx) {
81
+ ctx.#chronometry.delete(key);
82
+ ctx.delete(key);
83
+ }
84
+ }, Math.max(ms, 0));
85
+
86
+ this.constructor.#register(this, tid);
87
+ this.#chronometry.set(key, tid);
88
+ break;
89
+ }
90
+ }
91
+ }
92
+ }
93
+
94
+ toString() {
95
+ brandCheck(this, Cookies);
96
+
97
+ return super.toString().split('&').join('; ').trim();
98
+ }
99
+
100
+ }
package/src/defaults.mjs CHANGED
@@ -7,6 +7,9 @@ import { maxRetryAfter } from './utils.mjs';
7
7
 
8
8
  const {
9
9
  HTTP2_METHOD_GET,
10
+ HTTP_STATUS_BAD_GATEWAY,
11
+ HTTP_STATUS_GATEWAY_TIMEOUT,
12
+ HTTP_STATUS_INTERNAL_SERVER_ERROR,
10
13
  HTTP_STATUS_SERVICE_UNAVAILABLE,
11
14
  HTTP_STATUS_TOO_MANY_REQUESTS,
12
15
  } = http2.constants;
@@ -30,11 +33,26 @@ const stash = {
30
33
  retry: {
31
34
  attempts: 0,
32
35
  backoffStrategy: 'interval * Math.log(Math.random() * (Math.E * Math.E - Math.E) + Math.E)',
36
+ errorCodes: [
37
+ 'EAI_AGAIN',
38
+ 'ECONNREFUSED',
39
+ 'ECONNRESET',
40
+ 'EHOSTDOWN',
41
+ 'EHOSTUNREACH',
42
+ 'ENETDOWN',
43
+ 'ENETUNREACH',
44
+ 'ENOTFOUND',
45
+ 'EPIPE',
46
+ 'ERR_HTTP2_STREAM_ERROR',
47
+ ],
33
48
  interval: 1e3,
34
49
  retryAfter: true,
35
50
  statusCodes: [
36
51
  HTTP_STATUS_TOO_MANY_REQUESTS,
52
+ HTTP_STATUS_INTERNAL_SERVER_ERROR,
53
+ HTTP_STATUS_BAD_GATEWAY,
37
54
  HTTP_STATUS_SERVICE_UNAVAILABLE,
55
+ HTTP_STATUS_GATEWAY_TIMEOUT,
38
56
  ],
39
57
  },
40
58
  stripTrailingSlash: false,