rekwest 7.2.7 → 8.1.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/package.json CHANGED
@@ -1,76 +1,81 @@
1
- {
2
- "author": {
3
- "email": "yehor.sergeenko@gmail.com",
4
- "name": "Yehor Sergeenko",
5
- "url": "https://github.com/bricss"
6
- },
7
- "bugs": {
8
- "url": "https://github.com/bricss/rekwest/issues"
9
- },
10
- "description": "The robust request library that humanity deserves 🌐",
11
- "devDependencies": {
12
- "@babel/cli": "^7.28.6",
13
- "@babel/core": "^7.29.0",
14
- "@babel/preset-env": "^7.29.2",
15
- "@eslint/markdown": "^8.0.1",
16
- "c8": "^11.0.0",
17
- "eslint": "^10.2.0",
18
- "eslint-config-ultra-refined": "^4.1.6",
19
- "mocha": "^11.7.5"
20
- },
21
- "engines": {
22
- "node": ">=20.0.0"
23
- },
24
- "exports": {
25
- "import": "./src/index.js",
26
- "require": "./dist/index.cjs"
27
- },
28
- "files": [
29
- "dist",
30
- "src"
31
- ],
32
- "homepage": "https://github.com/bricss/rekwest#readme",
33
- "keywords": [
34
- "alpn",
35
- "backoff",
36
- "brotli",
37
- "cookies",
38
- "deflate",
39
- "deflate-raw",
40
- "fetch",
41
- "formdata",
42
- "gzip",
43
- "http",
44
- "https",
45
- "h2",
46
- "h2c",
47
- "http2",
48
- "multipart",
49
- "request",
50
- "redirect",
51
- "retry",
52
- "retry-after",
53
- "stream",
54
- "upload",
55
- "zstd"
56
- ],
57
- "license": "MIT",
58
- "name": "rekwest",
59
- "repository": {
60
- "type": "git",
61
- "url": "git+https://github.com/bricss/rekwest.git"
62
- },
63
- "scripts": {
64
- "build": "rm -rf dist && npx babel src --out-dir dist --out-file-extension .cjs && sh misc.sh",
65
- "cert:gen": "openssl req -days 365 -keyout localhost.key -newkey ec -nodes -pkeyopt ec_paramgen_curve:prime256v1 -subj //SKIP=1/CN=localhost -out localhost.cert -x509",
66
- "cert:ken": "openssl x509 -in localhost.cert -noout -text",
67
- "lint": "eslint --concurrency=auto",
68
- "prepack": "npm run build && npm run lint",
69
- "pretest": "rm -rf coverage && npm run cert:gen",
70
- "test": "mocha",
71
- "test:bail": "mocha --bail",
72
- "test:cover": "c8 --include=src --reporter=lcov --reporter=text npm test"
73
- },
74
- "type": "module",
75
- "version": "7.2.7"
76
- }
1
+ {
2
+ "author": {
3
+ "email": "yehor.sergeenko@gmail.com",
4
+ "name": "Yehor Sergeenko",
5
+ "url": "https://github.com/bricss"
6
+ },
7
+ "bugs": {
8
+ "url": "https://github.com/bricss/rekwest/issues"
9
+ },
10
+ "description": "The robust request library that humanity deserves 🌐",
11
+ "devDependencies": {
12
+ "@babel/cli": "^7.29.7",
13
+ "@babel/core": "^7.29.7",
14
+ "@babel/preset-env": "^7.29.7",
15
+ "@eslint/markdown": "^8.0.2",
16
+ "c8": "^11.0.0",
17
+ "eslint": "^10.4.1",
18
+ "eslint-config-ultra-refined": "^4.1.8",
19
+ "mocha": "^11.7.6"
20
+ },
21
+ "engines": {
22
+ "node": ">=22.0.0"
23
+ },
24
+ "exports": {
25
+ "import": "./src/index.js",
26
+ "require": "./dist/index.cjs"
27
+ },
28
+ "files": [
29
+ "dist",
30
+ "src"
31
+ ],
32
+ "homepage": "https://github.com/bricss/rekwest#readme",
33
+ "keywords": [
34
+ "alpn",
35
+ "backoff",
36
+ "brotli",
37
+ "cookies",
38
+ "deflate",
39
+ "deflate-raw",
40
+ "fetch",
41
+ "formdata",
42
+ "gzip",
43
+ "http",
44
+ "https",
45
+ "h2",
46
+ "h2c",
47
+ "http2",
48
+ "multipart",
49
+ "request",
50
+ "redirect",
51
+ "retry",
52
+ "retry-after",
53
+ "stream",
54
+ "upload",
55
+ "zstd"
56
+ ],
57
+ "license": "MIT",
58
+ "name": "rekwest",
59
+ "overrides": {
60
+ "c8": {
61
+ "yargs": "^18.0.0"
62
+ }
63
+ },
64
+ "repository": {
65
+ "type": "git",
66
+ "url": "git+https://github.com/bricss/rekwest.git"
67
+ },
68
+ "scripts": {
69
+ "build": "rm -rf dist && npx babel src --out-dir dist --out-file-extension .cjs && sh misc.sh",
70
+ "cert:gen": "openssl req -days 365 -keyout localhost.key -newkey ec -nodes -pkeyopt ec_paramgen_curve:prime256v1 -subj //SKIP=1/CN=localhost -out localhost.cert -x509",
71
+ "cert:ken": "openssl x509 -in localhost.cert -noout -text",
72
+ "lint": "eslint --concurrency=auto",
73
+ "prepack": "npm run build && npm run lint",
74
+ "pretest": "rm -rf coverage && npm run cert:gen",
75
+ "test": "mocha",
76
+ "test:bail": "mocha --bail",
77
+ "test:cover": "c8 --include=src --reporter=lcov --reporter=text npm test"
78
+ },
79
+ "type": "module",
80
+ "version": "8.1.0"
81
+ }
package/src/ackn.js CHANGED
@@ -1,33 +1,46 @@
1
- import { connect } from 'node:tls';
2
-
3
- export const ackn = (options = {}) => new Promise((resolve, reject) => {
4
- const url = new URL(options.url);
5
- const socket = connect({
6
- ...options,
7
- ALPNProtocols: [
8
- 'h2',
9
- 'http/1.1',
10
- ],
11
- host: url.hostname,
12
- port: parseInt(url.port, 10) || 443,
13
- servername: url.hostname,
14
- }, () => {
15
- socket.off('error', reject);
16
- socket.off('timeout', reject);
17
-
18
- const { alpnProtocol } = socket;
19
-
20
- resolve({
21
- ...options,
22
- alpnProtocol,
23
- createConnection() {
24
- return socket;
25
- },
26
- h2: /\bh2\b/i.test(alpnProtocol),
27
- protocol: url.protocol,
28
- });
29
- });
30
-
31
- socket.once('error', reject);
32
- socket.once('timeout', reject);
33
- });
1
+ import { connect } from 'node:tls';
2
+ import { RequestError } from './errors.js';
3
+
4
+ export const ackn = (options = {}) => new Promise((resolve, reject) => {
5
+ const url = new URL(options.url);
6
+ const socket = connect({
7
+ ...options,
8
+ ALPNProtocols: [
9
+ 'h2',
10
+ 'http/1.1',
11
+ ],
12
+ host: url.hostname,
13
+ port: parseInt(url.port, 10) || 443,
14
+ servername: url.hostname,
15
+ }, () => {
16
+ const cert = socket.getPeerCertificate();
17
+
18
+ if (options.certPins?.length) {
19
+ const fp = cert.fingerprint256;
20
+
21
+ if (!options.certPins.includes(fp) && !socket.isSessionReused()) {
22
+ socket.destroy();
23
+
24
+ return reject(new RequestError(`Certificate pins mismatch for ${ url.hostname }`));
25
+ }
26
+ }
27
+
28
+ socket.off('error', reject);
29
+ socket.off('timeout', reject);
30
+
31
+ const { alpnProtocol } = socket;
32
+
33
+ resolve({
34
+ ...options,
35
+ alpnProtocol,
36
+ createConnection() {
37
+ return socket;
38
+ },
39
+ h2: /\bh2\b/i.test(alpnProtocol),
40
+ protocol: url.protocol,
41
+ });
42
+ });
43
+
44
+ socket.once('error', reject);
45
+ socket.once('timeout', reject);
46
+ });
package/src/config.js CHANGED
@@ -1,90 +1,91 @@
1
- import http2 from 'node:http2';
2
- import zlib from 'node:zlib';
3
- import {
4
- requestCredentials,
5
- requestRedirect,
6
- } from './constants.js';
7
- import {
8
- APPLICATION_JSON,
9
- TEXT_PLAIN,
10
- WILDCARD,
11
- } from './mediatypes.js';
12
-
13
- export const isZstdSupported = !!zlib.constants.ZSTD_CLEVEL_DEFAULT;
14
-
15
- const {
16
- HTTP2_HEADER_ACCEPT,
17
- HTTP2_HEADER_ACCEPT_ENCODING,
18
- HTTP2_HEADER_USER_AGENT,
19
- HTTP2_METHOD_GET,
20
- HTTP_STATUS_BAD_GATEWAY,
21
- HTTP_STATUS_GATEWAY_TIMEOUT,
22
- HTTP_STATUS_INTERNAL_SERVER_ERROR,
23
- HTTP_STATUS_SERVICE_UNAVAILABLE,
24
- HTTP_STATUS_TOO_MANY_REQUESTS,
25
- } = http2.constants;
26
-
27
- const timeout = 3e5;
28
-
29
- const defaults = {
30
- allowDowngrade: false,
31
- bufferBody: false,
32
- cookiesTTL: false,
33
- credentials: requestCredentials.sameOrigin,
34
- decodersOptions: {},
35
- digest: true,
36
- encodersOptions: {
37
- brotli: {
38
- params: {
39
- [zlib.constants.BROTLI_PARAM_QUALITY]: 4,
40
- },
41
- },
42
- zstd: {
43
- params: {
44
- [zlib.constants.ZSTD_c_compressionLevel]: 6,
45
- },
46
- },
47
- },
48
- follow: 20,
49
- h2: false,
50
- headers: {
51
- [HTTP2_HEADER_ACCEPT]: `${ APPLICATION_JSON }, ${ TEXT_PLAIN }, ${ WILDCARD }`,
52
- [HTTP2_HEADER_ACCEPT_ENCODING]: `br,${ isZstdSupported ? ' zstd, ' : ' ' }gzip, deflate, deflate-raw`,
53
- [HTTP2_HEADER_USER_AGENT]: `node/${ process.versions.node } ${ process.platform }/${ process.arch }`,
54
- },
55
- method: HTTP2_METHOD_GET,
56
- parse: true,
57
- redirect: requestRedirect.follow,
58
- retry: {
59
- attempts: 0,
60
- backoffStrategy: 'interval * Math.log(Math.random() * (Math.E * Math.E - Math.E) + Math.E)',
61
- errorCodes: [
62
- 'ECONNREFUSED',
63
- 'ECONNRESET',
64
- 'EHOSTDOWN',
65
- 'EHOSTUNREACH',
66
- 'ENETDOWN',
67
- 'ENETUNREACH',
68
- 'ENOTFOUND',
69
- 'ERR_HTTP2_STREAM_ERROR',
70
- ],
71
- interval: 1e3,
72
- maxRetryAfter: timeout,
73
- retryAfter: true,
74
- statusCodes: [
75
- HTTP_STATUS_TOO_MANY_REQUESTS,
76
- HTTP_STATUS_INTERNAL_SERVER_ERROR,
77
- HTTP_STATUS_BAD_GATEWAY,
78
- HTTP_STATUS_SERVICE_UNAVAILABLE,
79
- HTTP_STATUS_GATEWAY_TIMEOUT,
80
- ],
81
- },
82
- stripTrailingSlash: false,
83
- thenable: false,
84
- timeout,
85
- trimTrailingSlashes: false,
86
- };
87
-
88
- export default {
89
- defaults,
90
- };
1
+ import http2 from 'node:http2';
2
+ import zlib from 'node:zlib';
3
+ import {
4
+ requestCredentials,
5
+ requestRedirect,
6
+ } from './constants.js';
7
+ import {
8
+ APPLICATION_JSON,
9
+ TEXT_PLAIN,
10
+ WILDCARD,
11
+ } from './mediatypes.js';
12
+
13
+ export const isZstdSupported = !!zlib.constants.ZSTD_CLEVEL_DEFAULT;
14
+
15
+ const {
16
+ HTTP2_HEADER_ACCEPT,
17
+ HTTP2_HEADER_ACCEPT_ENCODING,
18
+ HTTP2_HEADER_USER_AGENT,
19
+ HTTP2_METHOD_GET,
20
+ HTTP_STATUS_BAD_GATEWAY,
21
+ HTTP_STATUS_GATEWAY_TIMEOUT,
22
+ HTTP_STATUS_INTERNAL_SERVER_ERROR,
23
+ HTTP_STATUS_SERVICE_UNAVAILABLE,
24
+ HTTP_STATUS_TOO_MANY_REQUESTS,
25
+ } = http2.constants;
26
+
27
+ const timeout = 3e5;
28
+
29
+ const defaults = {
30
+ allowDowngrade: false,
31
+ bufferBody: false,
32
+ certPins: [],
33
+ cookiesTTL: false,
34
+ credentials: requestCredentials.sameOrigin,
35
+ decodersOptions: {},
36
+ digest: true,
37
+ encodersOptions: {
38
+ brotli: {
39
+ params: {
40
+ [zlib.constants.BROTLI_PARAM_QUALITY]: 4,
41
+ },
42
+ },
43
+ zstd: {
44
+ params: {
45
+ [zlib.constants.ZSTD_c_compressionLevel]: 6,
46
+ },
47
+ },
48
+ },
49
+ follow: 20,
50
+ h2: false,
51
+ headers: {
52
+ [HTTP2_HEADER_ACCEPT]: `${ APPLICATION_JSON }, ${ TEXT_PLAIN }, ${ WILDCARD }`,
53
+ [HTTP2_HEADER_ACCEPT_ENCODING]: `br,${ isZstdSupported ? ' zstd, ' : ' ' }gzip, deflate, deflate-raw`,
54
+ [HTTP2_HEADER_USER_AGENT]: navigator.userAgent,
55
+ },
56
+ method: HTTP2_METHOD_GET,
57
+ parse: true,
58
+ redirect: requestRedirect.follow,
59
+ retry: {
60
+ attempts: 0,
61
+ backoffStrategy: 'interval * Math.log(Math.random() * (Math.E * Math.E - Math.E) + Math.E)',
62
+ errorCodes: [
63
+ 'ECONNREFUSED',
64
+ 'ECONNRESET',
65
+ 'EHOSTDOWN',
66
+ 'EHOSTUNREACH',
67
+ 'ENETDOWN',
68
+ 'ENETUNREACH',
69
+ 'ENOTFOUND',
70
+ 'ERR_HTTP2_STREAM_ERROR',
71
+ ],
72
+ interval: 1e3,
73
+ maxRetryAfter: timeout,
74
+ retryAfter: true,
75
+ statusCodes: [
76
+ HTTP_STATUS_TOO_MANY_REQUESTS,
77
+ HTTP_STATUS_INTERNAL_SERVER_ERROR,
78
+ HTTP_STATUS_BAD_GATEWAY,
79
+ HTTP_STATUS_SERVICE_UNAVAILABLE,
80
+ HTTP_STATUS_GATEWAY_TIMEOUT,
81
+ ],
82
+ },
83
+ stripTrailingSlash: false,
84
+ thenable: false,
85
+ timeout,
86
+ trimTrailingSlashes: false,
87
+ };
88
+
89
+ export default {
90
+ defaults,
91
+ };
package/src/constants.js CHANGED
@@ -1,11 +1,11 @@
1
- export const requestCredentials = {
2
- include: 'include',
3
- omit: 'omit',
4
- sameOrigin: 'same-origin',
5
- };
6
-
7
- export const requestRedirect = {
8
- error: 'error',
9
- follow: 'follow',
10
- manual: 'manual',
11
- };
1
+ export const requestCredentials = {
2
+ include: 'include',
3
+ omit: 'omit',
4
+ sameOrigin: 'same-origin',
5
+ };
6
+
7
+ export const requestRedirect = {
8
+ error: 'error',
9
+ follow: 'follow',
10
+ manual: 'manual',
11
+ };