rekwest 7.2.6 → 8.0.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.
package/README.md CHANGED
@@ -22,7 +22,7 @@ and [http2.request](https://nodejs.org/api/http2.html#clienthttp2sessionrequesth
22
22
 
23
23
  ## Prerequisites
24
24
 
25
- * Node.js `>=20.0.0`
25
+ * Node.js `>=22.0.0`
26
26
 
27
27
  ## Installation
28
28
 
package/dist/config.cjs CHANGED
@@ -13,6 +13,7 @@ const isZstdSupported = exports.isZstdSupported = !!_nodeZlib.default.constants.
13
13
  const {
14
14
  HTTP2_HEADER_ACCEPT,
15
15
  HTTP2_HEADER_ACCEPT_ENCODING,
16
+ HTTP2_HEADER_USER_AGENT,
16
17
  HTTP2_METHOD_GET,
17
18
  HTTP_STATUS_BAD_GATEWAY,
18
19
  HTTP_STATUS_GATEWAY_TIMEOUT,
@@ -44,7 +45,8 @@ const defaults = {
44
45
  h2: false,
45
46
  headers: {
46
47
  [HTTP2_HEADER_ACCEPT]: `${_mediatypes.APPLICATION_JSON}, ${_mediatypes.TEXT_PLAIN}, ${_mediatypes.WILDCARD}`,
47
- [HTTP2_HEADER_ACCEPT_ENCODING]: `br,${isZstdSupported ? ' zstd, ' : ' '}gzip, deflate, deflate-raw`
48
+ [HTTP2_HEADER_ACCEPT_ENCODING]: `br,${isZstdSupported ? ' zstd, ' : ' '}gzip, deflate, deflate-raw`,
49
+ [HTTP2_HEADER_USER_AGENT]: navigator.userAgent
48
50
  },
49
51
  method: HTTP2_METHOD_GET,
50
52
  parse: true,
package/dist/cookies.cjs CHANGED
@@ -5,14 +5,14 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.splitCookie = exports.maxCookieSize = exports.maxCookieLifetimeCap = exports.isValidCookie = exports.illegalCookieChars = exports.cookieRex = exports.cookiePairRex = exports.Cookies = void 0;
7
7
  var _utils = require("./utils.cjs");
8
- const cookieRex = exports.cookieRex = /^[\w-]+=(?:"[^"]*"|[^\p{Control};]*)(?:;\s*(?:[\w-]+=(?:"[^"]*"|[^\p{Control};]*)|[\w-]+))*$/u;
9
- const cookiePairRex = exports.cookiePairRex = /(?:[^;"\s]+="[^"]*"|[^;]+)(?=;|$)/g;
8
+ const cookieRex = exports.cookieRex = /^[^=]+=(?:"[^"]*"|[^\p{Control};]*)(?:;\s*(?:[^=]+=(?:"[^"]*"|[^\p{Control};]*)|[^=]+))*$/u;
9
+ const cookiePairRex = exports.cookiePairRex = /[^;\s]+=(?:"[^"]*"|[^;\s]*)/g;
10
10
  const illegalCookieChars = exports.illegalCookieChars = /\p{Control}/u;
11
11
  const isValidCookie = str => str?.constructor === String && cookieRex.test(str);
12
12
  exports.isValidCookie = isValidCookie;
13
13
  const maxCookieLifetimeCap = exports.maxCookieLifetimeCap = 3456e7; // 400 days
14
14
  const maxCookieSize = exports.maxCookieSize = 4096;
15
- const splitCookie = str => str.match(cookiePairRex).map(str => str.trim());
15
+ const splitCookie = str => str.match(cookiePairRex);
16
16
  exports.splitCookie = splitCookie;
17
17
  class Cookies extends URLSearchParams {
18
18
  static #finalizers = new Set();
@@ -42,25 +42,28 @@ class Cookies extends URLSearchParams {
42
42
  if (input.every(it => isValidCookie(it))) {
43
43
  input = input.filter(it => !illegalCookieChars.test(it) && it.length <= maxCookieSize);
44
44
  input = input.map(splitCookie).map(([cookie, ...attrs]) => {
45
- try {
46
- cookie = cookie.split('=').map(it => decodeURIComponent(it.trim()));
47
- return cookie;
48
- } finally {
49
- if (cookiesTTL) {
50
- for (const attr of attrs) {
51
- if (/(?:expires|max-age)=/i.test(attr)) {
52
- const [key, val] = attr.toLowerCase().split('=');
53
- let interval = val * 1e3 || Date.parse(val) - Date.now();
54
- if (interval < 0 || Number.isNaN(interval)) {
55
- interval = 0;
56
- }
57
- ttlMap.set(cookie[0], {
58
- [(0, _utils.toCamelCase)(key.trim())]: Math.min(interval, maxCookieLifetimeCap)
59
- });
45
+ cookie = cookie.split(/=(?<v>.*)/s, 2).map(it => {
46
+ try {
47
+ return decodeURIComponent(it);
48
+ } catch {
49
+ return it;
50
+ }
51
+ });
52
+ if (cookiesTTL) {
53
+ for (const attr of attrs) {
54
+ if (/(?:expires|max-age)=/i.test(attr)) {
55
+ const [key, val] = attr.split(/=(?<v>.*)/s, 2);
56
+ let interval = val * 1e3 || Date.parse(val) - Date.now();
57
+ if (interval < 0 || Number.isNaN(interval)) {
58
+ interval = 0;
60
59
  }
60
+ ttlMap.set(cookie[0], {
61
+ [(0, _utils.toCamelCase)(key)]: Math.min(interval, maxCookieLifetimeCap)
62
+ });
61
63
  }
62
64
  }
63
65
  }
66
+ return cookie;
64
67
  });
65
68
  }
66
69
  }
@@ -96,7 +99,7 @@ class Cookies extends URLSearchParams {
96
99
  }
97
100
  toString() {
98
101
  (0, _utils.brandCheck)(this, Cookies);
99
- return super.toString().split('&').join('; ').trim();
102
+ return super.toString().split('&').join('; ');
100
103
  }
101
104
  }
102
105
  exports.Cookies = Cookies;
package/dist/utils.cjs CHANGED
@@ -75,6 +75,10 @@ const deepMerge = (target, ...rest) => {
75
75
  for (const key of Object.getOwnPropertyNames(source)) {
76
76
  const sv = source[key];
77
77
  const tv = target[key];
78
+ if (sv instanceof Function) {
79
+ target[key] = source[key];
80
+ continue;
81
+ }
78
82
  if (Object(sv) === sv && Object(tv) === tv) {
79
83
  target[key] = deepMerge(tv, sv);
80
84
  continue;
package/package.json CHANGED
@@ -11,15 +11,15 @@
11
11
  "devDependencies": {
12
12
  "@babel/cli": "^7.28.6",
13
13
  "@babel/core": "^7.29.0",
14
- "@babel/preset-env": "^7.29.2",
15
- "@eslint/markdown": "^8.0.0",
14
+ "@babel/preset-env": "^7.29.5",
15
+ "@eslint/markdown": "^8.0.1",
16
16
  "c8": "^11.0.0",
17
- "eslint": "^10.1.0",
18
- "eslint-config-ultra-refined": "^4.1.5",
17
+ "eslint": "^10.3.0",
18
+ "eslint-config-ultra-refined": "^4.1.7",
19
19
  "mocha": "^11.7.5"
20
20
  },
21
21
  "engines": {
22
- "node": ">=20.0.0"
22
+ "node": ">=22.0.0"
23
23
  },
24
24
  "exports": {
25
25
  "import": "./src/index.js",
@@ -72,5 +72,5 @@
72
72
  "test:cover": "c8 --include=src --reporter=lcov --reporter=text npm test"
73
73
  },
74
74
  "type": "module",
75
- "version": "7.2.6"
75
+ "version": "8.0.0"
76
76
  }
package/src/config.js CHANGED
@@ -15,6 +15,7 @@ export const isZstdSupported = !!zlib.constants.ZSTD_CLEVEL_DEFAULT;
15
15
  const {
16
16
  HTTP2_HEADER_ACCEPT,
17
17
  HTTP2_HEADER_ACCEPT_ENCODING,
18
+ HTTP2_HEADER_USER_AGENT,
18
19
  HTTP2_METHOD_GET,
19
20
  HTTP_STATUS_BAD_GATEWAY,
20
21
  HTTP_STATUS_GATEWAY_TIMEOUT,
@@ -49,6 +50,7 @@ const defaults = {
49
50
  headers: {
50
51
  [HTTP2_HEADER_ACCEPT]: `${ APPLICATION_JSON }, ${ TEXT_PLAIN }, ${ WILDCARD }`,
51
52
  [HTTP2_HEADER_ACCEPT_ENCODING]: `br,${ isZstdSupported ? ' zstd, ' : ' ' }gzip, deflate, deflate-raw`,
53
+ [HTTP2_HEADER_USER_AGENT]: navigator.userAgent,
52
54
  },
53
55
  method: HTTP2_METHOD_GET,
54
56
  parse: true,
package/src/cookies.js CHANGED
@@ -3,13 +3,13 @@ import {
3
3
  toCamelCase,
4
4
  } from './utils.js';
5
5
 
6
- export const cookieRex = /^[\w-]+=(?:"[^"]*"|[^\p{Control};]*)(?:;\s*(?:[\w-]+=(?:"[^"]*"|[^\p{Control};]*)|[\w-]+))*$/u;
7
- export const cookiePairRex = /(?:[^;"\s]+="[^"]*"|[^;]+)(?=;|$)/g;
6
+ export const cookieRex = /^[^=]+=(?:"[^"]*"|[^\p{Control};]*)(?:;\s*(?:[^=]+=(?:"[^"]*"|[^\p{Control};]*)|[^=]+))*$/u;
7
+ export const cookiePairRex = /[^;\s]+=(?:"[^"]*"|[^;\s]*)/g;
8
8
  export const illegalCookieChars = /\p{Control}/u;
9
9
  export const isValidCookie = (str) => str?.constructor === String && cookieRex.test(str);
10
10
  export const maxCookieLifetimeCap = 3456e7; // 400 days
11
11
  export const maxCookieSize = 4096;
12
- export const splitCookie = (str) => str.match(cookiePairRex).map((str) => str.trim());
12
+ export const splitCookie = (str) => str.match(cookiePairRex);
13
13
 
14
14
  export class Cookies extends URLSearchParams {
15
15
 
@@ -43,29 +43,33 @@ export class Cookies extends URLSearchParams {
43
43
  if (input.every((it) => isValidCookie(it))) {
44
44
  input = input.filter((it) => !illegalCookieChars.test(it) && it.length <= maxCookieSize);
45
45
  input = input.map(splitCookie).map(([cookie, ...attrs]) => {
46
- try {
47
- cookie = cookie.split('=').map((it) => decodeURIComponent(it.trim()));
48
-
49
- return cookie;
50
- } finally {
51
- if (cookiesTTL) {
52
- for (const attr of attrs) {
53
- if (/(?:expires|max-age)=/i.test(attr)) {
54
- const [key, val] = attr.toLowerCase().split('=');
55
- let interval = val * 1e3 || Date.parse(val) - Date.now();
56
-
57
- if (interval < 0 || Number.isNaN(interval)) {
58
- interval = 0;
59
- }
60
-
61
- ttlMap.set(
62
- cookie[0],
63
- { [toCamelCase(key.trim())]: Math.min(interval, maxCookieLifetimeCap) },
64
- );
46
+ cookie = cookie.split(/=(?<v>.*)/s, 2).map((it) => {
47
+ try {
48
+ return decodeURIComponent(it);
49
+ } catch {
50
+ return it;
51
+ }
52
+ });
53
+
54
+ if (cookiesTTL) {
55
+ for (const attr of attrs) {
56
+ if (/(?:expires|max-age)=/i.test(attr)) {
57
+ const [key, val] = attr.split(/=(?<v>.*)/s, 2);
58
+ let interval = val * 1e3 || Date.parse(val) - Date.now();
59
+
60
+ if (interval < 0 || Number.isNaN(interval)) {
61
+ interval = 0;
65
62
  }
63
+
64
+ ttlMap.set(
65
+ cookie[0],
66
+ { [toCamelCase(key)]: Math.min(interval, maxCookieLifetimeCap) },
67
+ );
66
68
  }
67
69
  }
68
70
  }
71
+
72
+ return cookie;
69
73
  });
70
74
  }
71
75
  }
@@ -111,7 +115,7 @@ export class Cookies extends URLSearchParams {
111
115
  toString() {
112
116
  brandCheck(this, Cookies);
113
117
 
114
- return super.toString().split('&').join('; ').trim();
118
+ return super.toString().split('&').join('; ');
115
119
  }
116
120
 
117
121
  }
package/src/utils.js CHANGED
@@ -78,6 +78,11 @@ export const deepMerge = (target, ...rest) => {
78
78
  const sv = source[key];
79
79
  const tv = target[key];
80
80
 
81
+ if (sv instanceof Function) {
82
+ target[key] = source[key];
83
+ continue;
84
+ }
85
+
81
86
  if (Object(sv) === sv && Object(tv) === tv) {
82
87
  target[key] = deepMerge(tv, sv);
83
88
  continue;