global-agent 3.0.0 → 4.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.
Files changed (95) hide show
  1. package/.babelrc +23 -0
  2. package/.editorconfig +9 -0
  3. package/.eslintignore +1 -0
  4. package/.eslintrc +27 -0
  5. package/.github/FUNDING.yml +2 -0
  6. package/.github/workflows/feature.yaml +32 -0
  7. package/.github/workflows/main.yaml +31 -0
  8. package/.gitignore +14 -0
  9. package/LICENSE +2 -2
  10. package/README.md +67 -8
  11. package/package.json +48 -56
  12. package/src/{Logger.js → Logger.ts} +3 -3
  13. package/{dist/classes/Agent.js.flow → src/classes/Agent.ts} +121 -39
  14. package/src/classes/HttpProxyAgent.ts +45 -0
  15. package/src/classes/HttpsProxyAgent.ts +83 -0
  16. package/src/classes/index.ts +9 -0
  17. package/src/{errors.js → errors.ts} +2 -6
  18. package/src/factories/{createGlobalProxyAgent.js → createGlobalProxyAgent.ts} +36 -50
  19. package/{dist/factories/createProxyController.js.flow → src/factories/createProxyController.ts} +8 -5
  20. package/src/factories/index.ts +6 -0
  21. package/src/index.ts +6 -0
  22. package/{dist/routines/bootstrap.js.flow → src/routines/bootstrap.ts} +6 -5
  23. package/src/routines/index.ts +3 -0
  24. package/src/types.ts +66 -0
  25. package/src/utilities/{bindHttpMethod.js → bindHttpMethod.ts} +6 -7
  26. package/src/utilities/index.ts +9 -0
  27. package/{dist/utilities/isUrlMatchingNoProxy.js.flow → src/utilities/isUrlMatchingNoProxy.ts} +1 -6
  28. package/src/utilities/parseBoolean.ts +17 -0
  29. package/src/utilities/{parseProxyUrl.js → parseProxyUrl.ts} +12 -9
  30. package/test/.eslintrc +10 -0
  31. package/test/global-agent/factories/createGlobalProxyAgent.ts +760 -0
  32. package/test/global-agent/factories/createProxyController.ts +37 -0
  33. package/test/global-agent/utilities/isUrlMatchingNoProxy.ts +62 -0
  34. package/test/global-agent/utilities/parseProxyUrl.ts +38 -0
  35. package/tsconfig.json +25 -0
  36. package/.flowconfig +0 -3
  37. package/dist/Logger.js +0 -18
  38. package/dist/Logger.js.flow +0 -10
  39. package/dist/Logger.js.map +0 -1
  40. package/dist/classes/Agent.js +0 -174
  41. package/dist/classes/Agent.js.map +0 -1
  42. package/dist/classes/HttpProxyAgent.js +0 -33
  43. package/dist/classes/HttpProxyAgent.js.flow +0 -30
  44. package/dist/classes/HttpProxyAgent.js.map +0 -1
  45. package/dist/classes/HttpsProxyAgent.js +0 -53
  46. package/dist/classes/HttpsProxyAgent.js.flow +0 -54
  47. package/dist/classes/HttpsProxyAgent.js.map +0 -1
  48. package/dist/classes/index.js +0 -32
  49. package/dist/classes/index.js.flow +0 -5
  50. package/dist/classes/index.js.map +0 -1
  51. package/dist/errors.js +0 -22
  52. package/dist/errors.js.flow +0 -15
  53. package/dist/errors.js.map +0 -1
  54. package/dist/factories/createGlobalProxyAgent.js +0 -175
  55. package/dist/factories/createGlobalProxyAgent.js.flow +0 -197
  56. package/dist/factories/createGlobalProxyAgent.js.map +0 -1
  57. package/dist/factories/createProxyController.js +0 -45
  58. package/dist/factories/createProxyController.js.map +0 -1
  59. package/dist/factories/index.js +0 -24
  60. package/dist/factories/index.js.flow +0 -4
  61. package/dist/factories/index.js.map +0 -1
  62. package/dist/index.js +0 -22
  63. package/dist/index.js.flow +0 -4
  64. package/dist/index.js.map +0 -1
  65. package/dist/routines/bootstrap.js +0 -30
  66. package/dist/routines/bootstrap.js.map +0 -1
  67. package/dist/routines/index.js +0 -16
  68. package/dist/routines/index.js.flow +0 -3
  69. package/dist/routines/index.js.map +0 -1
  70. package/dist/types.js +0 -10
  71. package/dist/types.js.flow +0 -66
  72. package/dist/types.js.map +0 -1
  73. package/dist/utilities/bindHttpMethod.js +0 -62
  74. package/dist/utilities/bindHttpMethod.js.flow +0 -54
  75. package/dist/utilities/bindHttpMethod.js.map +0 -1
  76. package/dist/utilities/index.js +0 -32
  77. package/dist/utilities/index.js.flow +0 -5
  78. package/dist/utilities/index.js.map +0 -1
  79. package/dist/utilities/isUrlMatchingNoProxy.js +0 -43
  80. package/dist/utilities/isUrlMatchingNoProxy.js.map +0 -1
  81. package/dist/utilities/parseProxyUrl.js +0 -42
  82. package/dist/utilities/parseProxyUrl.js.flow +0 -36
  83. package/dist/utilities/parseProxyUrl.js.map +0 -1
  84. package/src/classes/Agent.js +0 -212
  85. package/src/classes/HttpProxyAgent.js +0 -30
  86. package/src/classes/HttpsProxyAgent.js +0 -54
  87. package/src/classes/index.js +0 -5
  88. package/src/factories/createProxyController.js +0 -46
  89. package/src/factories/index.js +0 -4
  90. package/src/index.js +0 -4
  91. package/src/routines/bootstrap.js +0 -25
  92. package/src/routines/index.js +0 -3
  93. package/src/types.js +0 -66
  94. package/src/utilities/index.js +0 -5
  95. package/src/utilities/isUrlMatchingNoProxy.js +0 -37
package/.babelrc ADDED
@@ -0,0 +1,23 @@
1
+ {
2
+ "env": {
3
+ "test": {
4
+ "plugins": [
5
+ "istanbul"
6
+ ]
7
+ }
8
+ },
9
+ "plugins": [
10
+ "transform-export-default-name",
11
+ "@babel/transform-flow-strip-types"
12
+ ],
13
+ "presets": [
14
+ [
15
+ "@babel/env",
16
+ {
17
+ "targets": {
18
+ "node": "12"
19
+ }
20
+ }
21
+ ]
22
+ ]
23
+ }
package/.editorconfig ADDED
@@ -0,0 +1,9 @@
1
+ root = true
2
+
3
+ [*]
4
+ charset = utf-8
5
+ end_of_line = lf
6
+ indent_size = 2
7
+ indent_style = space
8
+ insert_final_newline = true
9
+ trim_trailing_whitespace = true
package/.eslintignore ADDED
@@ -0,0 +1 @@
1
+ /bootstrap.js
package/.eslintrc ADDED
@@ -0,0 +1,27 @@
1
+ {
2
+ "extends": [
3
+ "canonical",
4
+ "canonical/node",
5
+ "canonical/typescript"
6
+ ],
7
+ "parserOptions": {
8
+ "project": "./tsconfig.json"
9
+ },
10
+ "root": true,
11
+ "rules": {
12
+ "@typescript-eslint/prefer-regexp-exec": 0,
13
+ "class-methods-use-this": 0,
14
+ "fp/no-class": 0,
15
+ "fp/no-events": 0,
16
+ "fp/no-this": 0,
17
+ "import/no-cycle": 0,
18
+ "no-continue": 0,
19
+ "no-restricted-syntax": 0,
20
+ "no-unused-expressions": [
21
+ 2,
22
+ {
23
+ "allowTaggedTemplates": true
24
+ }
25
+ ]
26
+ }
27
+ }
@@ -0,0 +1,2 @@
1
+ github: gajus
2
+ patreon: gajus
@@ -0,0 +1,32 @@
1
+ jobs:
2
+ test:
3
+ name: Test
4
+ runs-on: ubuntu-latest
5
+ steps:
6
+ - name: setup repository
7
+ uses: actions/checkout@v3
8
+ with:
9
+ fetch-depth: 0
10
+ - name: setup node.js
11
+ uses: actions/setup-node@v4
12
+ with:
13
+ node-version: '24'
14
+ - name: setup npm
15
+ uses: npm/action-setup@v4
16
+ with:
17
+ version: 10
18
+ - run: npm install
19
+ - run: npm run lint
20
+ - run: npm run test
21
+ - run: npm run build
22
+ timeout-minutes: 10
23
+ name: Test
24
+ on:
25
+ pull_request:
26
+ branches:
27
+ - main
28
+ types:
29
+ - opened
30
+ - synchronize
31
+ - reopened
32
+ - ready_for_review
@@ -0,0 +1,31 @@
1
+ jobs:
2
+ release:
3
+ environment: release
4
+ name: Release
5
+ permissions:
6
+ contents: write
7
+ id-token: write
8
+ issues: write
9
+ pull-requests: write
10
+ runs-on: ubuntu-latest
11
+ steps:
12
+ - name: setup repository
13
+ uses: actions/checkout@v3
14
+ with:
15
+ fetch-depth: 0
16
+ - name: setup node.js
17
+ uses: actions/setup-node@v4
18
+ with:
19
+ node-version: '24'
20
+ - run: npm install
21
+ - run: npm run lint
22
+ - run: npm run test
23
+ - run: npm run build
24
+ - env:
25
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
26
+ run: npx semantic-release
27
+ name: Release
28
+ on:
29
+ push:
30
+ branches:
31
+ - main
package/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ coverage
2
+ dist
3
+ node_modules
4
+ *.log
5
+ .*
6
+ !.babelrc
7
+ !.editorconfig
8
+ !.eslintignore
9
+ !.eslintrc
10
+ !.github
11
+ !.gitignore
12
+ !.npmignore
13
+ !.npmrc
14
+ !.README
package/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2019, Gajus Kuizinas (http://gajus.com/)
1
+ Copyright (c) 2026, Gajus Kuizinas (https://gajus.com/)
2
2
  All rights reserved.
3
3
 
4
4
  Redistribution and use in source and binary forms, with or without
@@ -8,7 +8,7 @@ modification, are permitted provided that the following conditions are met:
8
8
  * Redistributions in binary form must reproduce the above copyright
9
9
  notice, this list of conditions and the following disclaimer in the
10
10
  documentation and/or other materials provided with the distribution.
11
- * Neither the name of the Gajus Kuizinas (http://gajus.com/) nor the
11
+ * Neither the name of the Gajus Kuizinas (https://gajus.com/) nor the
12
12
  names of its contributors may be used to endorse or promote products
13
13
  derived from this software without specific prior written permission.
14
14
 
package/README.md CHANGED
@@ -1,7 +1,5 @@
1
1
  # global-agent
2
2
 
3
- [![GitSpo Mentions](https://gitspo.com/badges/mentions/gajus/global-agent?style=flat-square)](https://gitspo.com/mentions/gajus/global-agent)
4
- [![Travis build status](http://img.shields.io/travis/gajus/global-agent/master.svg?style=flat-square)](https://travis-ci.org/gajus/global-agent)
5
3
  [![Coveralls](https://img.shields.io/coveralls/gajus/global-agent.svg?style=flat-square)](https://coveralls.io/github/gajus/global-agent)
6
4
  [![NPM version](http://img.shields.io/npm/v/global-agent.svg?style=flat-square)](https://www.npmjs.org/package/global-agent)
7
5
  [![Canonical Code Style](https://img.shields.io/badge/code%20style-canonical-blue.svg?style=flat-square)](https://github.com/gajus/canonical)
@@ -125,7 +123,7 @@ global.GLOBAL_AGENT.HTTP_PROXY = 'http://127.0.0.1:8002';
125
123
 
126
124
  ```
127
125
 
128
- The first HTTP request is going to use http://127.0.0.1:8001 proxy and the secord request is going to use http://127.0.0.1:8002.
126
+ The first HTTP request is going to use http://127.0.0.1:8001 proxy and the second request is going to use http://127.0.0.1:8002.
129
127
 
130
128
  All `global-agent` configuration is available under `global.GLOBAL_AGENT` namespace.
131
129
 
@@ -167,11 +165,13 @@ Use [`roarr-cli`](https://github.com/gajus/roarr-cli) program to pretty-print th
167
165
  * @property environmentVariableNamespace Defines namespace of `HTTP_PROXY`, `HTTPS_PROXY` and `NO_PROXY` environment variables. (Default: `GLOBAL_AGENT_`)
168
166
  * @property forceGlobalAgent Forces to use `global-agent` HTTP(S) agent even when request was explicitly constructed with another agent. (Default: `true`)
169
167
  * @property socketConnectionTimeout Destroys socket if connection is not established within the timeout. (Default: `60000`)
168
+ * @property ca Single CA certificate or an array of CA certificates that is trusted for secure connections to the registry.
170
169
  */
171
170
  type ProxyAgentConfigurationInputType = {|
172
171
  +environmentVariableNamespace?: string,
173
172
  +forceGlobalAgent?: boolean,
174
173
  +socketConnectionTimeout?: number,
174
+ +ca?: string[] | string,
175
175
  |};
176
176
 
177
177
  (configurationInput: ProxyAgentConfigurationInputType) => ProxyAgentConfigurationType;
@@ -185,9 +185,9 @@ type ProxyAgentConfigurationInputType = {|
185
185
  |`GLOBAL_AGENT_ENVIRONMENT_VARIABLE_NAMESPACE`|Defines namespace of `HTTP_PROXY`, `HTTPS_PROXY` and `NO_PROXY` environment variables.|`GLOBAL_AGENT_`|
186
186
  |`GLOBAL_AGENT_FORCE_GLOBAL_AGENT`|Forces to use `global-agent` HTTP(S) agent even when request was explicitly constructed with another agent.|`true`|
187
187
  |`GLOBAL_AGENT_SOCKET_CONNECTION_TIMEOUT`|Destroys socket if connection is not established within the timeout.|`60000`|
188
- |`${NAMESPACE}_HTTP_PROXY`|Sets the initial proxy controller HTTP_PROXY value.|N/A|
189
- |`${NAMESPACE}_HTTPS_PROXY`|Sets the initial proxy controller HTTPS_PROXY value.|N/A|
190
- |`${NAMESPACE}_NO_PROXY`|Sets the initial proxy controller NO_PROXY value.|N/A|
188
+ |`${NAMESPACE}HTTP_PROXY`|Sets the initial proxy controller HTTP_PROXY value.|N/A|
189
+ |`${NAMESPACE}HTTPS_PROXY`|Sets the initial proxy controller HTTPS_PROXY value.|N/A|
190
+ |`${NAMESPACE}NO_PROXY`|Sets the initial proxy controller NO_PROXY value.|N/A|
191
191
 
192
192
  ### `global.GLOBAL_AGENT`
193
193
 
@@ -195,12 +195,71 @@ type ProxyAgentConfigurationInputType = {|
195
195
 
196
196
  `global.GLOBAL_AGENT` has the following properties:
197
197
 
198
- |Name|Description|Configurable|
198
+ |Name|Configurable|Description|
199
199
  |---|---|---|
200
200
  |`HTTP_PROXY`|Yes|Sets HTTP proxy to use.|
201
201
  |`HTTPS_PROXY`|Yes|Sets a distinct proxy to use for HTTPS requests.|
202
202
  |`NO_PROXY`|Yes|Specifies a pattern of URLs that should be excluded from proxying. See [Exclude URLs](#exclude-urls).|
203
203
 
204
+ ## Certificate Authority (CA)
205
+
206
+ ### `addCACertificates`
207
+ This method can be accessed using https to add CA certificates to the global-agent.
208
+
209
+ Uses:
210
+ ```js
211
+ if (typeof https.globalAgent.addCACertificates === 'function') {
212
+ //certificate - an array of ca certificates to be added to the global-agent
213
+ https.globalAgent.addCACertificates(certificate);
214
+ }
215
+ ```
216
+
217
+ Method Definition:
218
+ ```js
219
+ /**
220
+ * This method can be used to append new ca certificates to existing ca certificates
221
+ * @param {string[] | string} ca a ca certificate or an array of ca certificates
222
+ */
223
+ public addCACertificates (ca: string[] | string) {
224
+ if (!ca) {
225
+ log.error('Invalid input ca certificate');
226
+ } else if (this.ca) {
227
+ if (typeof ca === typeof this.ca) {
228
+ // concat valid ca certificates with the existing certificates,
229
+ if (typeof this.ca === 'string') {
230
+ this.ca = this.ca.concat(ca as string);
231
+ } else {
232
+ this.ca = this.ca.concat(ca as string[]);
233
+ }
234
+ } else {
235
+ log.error('Input ca certificate type mismatched with existing ca certificate type');
236
+ }
237
+ } else {
238
+ this.ca = ca;
239
+ }
240
+ }
241
+ ```
242
+
243
+ ### `clearCACertificates`
244
+ This method can be accessed using https to clear existing CA certificates from global-agent.
245
+
246
+ Uses:
247
+ ```js
248
+ if (typeof https.globalAgent.clearCACertificates === 'function') {
249
+ https.globalAgent.clearCACertificates();
250
+ }
251
+ ```
252
+ Method Definition:
253
+ ```js
254
+ /**
255
+ * This method clears existing CA Certificates.
256
+ * It sets ca to undefined
257
+ */
258
+ public clearCACertificates () {
259
+ this.ca = undefined;
260
+ }
261
+ ```
262
+
204
263
  ## Supported libraries
205
264
 
206
265
  `global-agent` works with all libraries that internally use [`http.request`](https://nodejs.org/api/http.html#http_http_request_options_callback).
@@ -209,7 +268,7 @@ type ProxyAgentConfigurationInputType = {|
209
268
 
210
269
  * [`got`](https://www.npmjs.com/package/got)
211
270
  * [`axios`](https://www.npmjs.com/package/axios)
212
- * [`request`](https://www.npmjs.com/package/axios)
271
+ * [`request`](https://www.npmjs.com/package/request)
213
272
 
214
273
  ## FAQ
215
274
 
package/package.json CHANGED
@@ -5,53 +5,61 @@
5
5
  "url": "http://gajus.com"
6
6
  },
7
7
  "ava": {
8
- "babel": {
9
- "compileAsTests": [
10
- "test/helpers/**/*"
11
- ]
12
- },
8
+ "extensions": [
9
+ "ts"
10
+ ],
13
11
  "files": [
14
12
  "test/global-agent/**/*"
15
13
  ],
16
14
  "require": [
17
- "@babel/register"
15
+ "ts-node/register/transpile-only"
18
16
  ]
19
17
  },
20
18
  "dependencies": {
21
- "boolean": "^3.0.1",
22
19
  "es6-error": "^4.1.1",
23
- "matcher": "^3.0.0",
24
- "roarr": "^2.15.3",
25
- "semver": "^7.3.2",
26
- "serialize-error": "^7.0.1"
20
+ "globalthis": "^1.0.2",
21
+ "matcher": "^4.0.0",
22
+ "omit-undefined": "^1.0.1",
23
+ "roarr": "^7.0.3",
24
+ "semver": "^7.3.5",
25
+ "serialize-error": "^8.1.0"
27
26
  },
28
27
  "description": "Global HTTP/HTTPS proxy configurable using environment variables.",
29
28
  "devDependencies": {
30
- "@ava/babel": "^1.0.1",
31
- "@babel/cli": "^7.10.1",
32
- "@babel/core": "^7.10.2",
33
- "@babel/node": "^7.10.1",
34
- "@babel/plugin-transform-flow-strip-types": "^7.10.1",
35
- "@babel/preset-env": "^7.10.2",
36
- "@babel/register": "^7.10.1",
37
- "anyproxy": "^4.1.2",
38
- "ava": "^3.8.2",
39
- "axios": "^0.19.2",
29
+ "@ava/babel": "^2.0.0",
30
+ "@babel/cli": "^7.14.8",
31
+ "@babel/core": "^7.14.8",
32
+ "@babel/node": "^7.14.7",
33
+ "@babel/plugin-transform-flow-strip-types": "^7.14.5",
34
+ "@babel/preset-env": "^7.14.8",
35
+ "@babel/register": "^7.14.5",
36
+ "@istanbuljs/nyc-config-typescript": "^1.0.1",
37
+ "@semantic-release/commit-analyzer": "^13.0.1",
38
+ "@semantic-release/github": "^12.0.3",
39
+ "@semantic-release/npm": "^13.1.3",
40
+ "@types/globalthis": "^1.0.1",
41
+ "@types/pem": "^1.14.4",
42
+ "@types/request": "^2.48.6",
43
+ "@types/semver": "^7.3.8",
44
+ "@types/sinon": "^10.0.2",
45
+ "ava": "^3.15.0",
46
+ "axios": "^0.21.1",
40
47
  "babel-plugin-istanbul": "^6.0.0",
41
- "babel-plugin-transform-export-default-name": "^2.0.4",
42
- "coveralls": "^3.1.0",
43
- "eslint": "^7.1.0",
44
- "eslint-config-canonical": "^20.0.5",
45
- "flow-bin": "^0.125.1",
46
- "flow-copy-source": "^2.0.9",
48
+ "babel-plugin-transform-export-default-name": "^2.1.0",
49
+ "coveralls": "^3.1.1",
50
+ "del-cli": "^4.0.1",
51
+ "eslint": "^7.31.0",
52
+ "eslint-config-canonical": "^26.2.3",
47
53
  "get-port": "^5.1.1",
48
- "got": "^11.1.4",
49
- "husky": "^4.2.5",
54
+ "got": "^11.8.2",
55
+ "husky": "^7.0.1",
50
56
  "nyc": "^15.1.0",
51
57
  "pem": "^1.14.4",
52
58
  "request": "^2.88.2",
53
- "semantic-release": "^17.0.8",
54
- "sinon": "^9.0.2"
59
+ "semantic-release": "^25.0.3",
60
+ "sinon": "^11.1.2",
61
+ "ts-node": "^10.1.0",
62
+ "typescript": "^4.3.5"
55
63
  },
56
64
  "engines": {
57
65
  "node": ">=10.0"
@@ -68,38 +76,22 @@
68
76
  "agent"
69
77
  ],
70
78
  "license": "BSD-3-Clause",
71
- "main": "./dist/index.js",
79
+ "main": "./dist/src/index.js",
72
80
  "name": "global-agent",
73
81
  "nyc": {
74
- "all": true,
75
- "exclude": [
76
- "src/bin",
77
- "src/queries/*.js"
78
- ],
79
- "include": [
80
- "src/**/*.js"
81
- ],
82
- "instrument": false,
83
- "reporter": [
84
- "html",
85
- "text-summary"
86
- ],
87
- "require": [
88
- "@babel/register"
89
- ],
90
- "silent": true,
91
- "sourceMap": false
82
+ "extends": "@istanbuljs/nyc-config-typescript",
83
+ "all": true
92
84
  },
93
85
  "repository": {
94
86
  "type": "git",
95
87
  "url": "https://github.com/gajus/global-agent"
96
88
  },
97
89
  "scripts": {
98
- "build": "rm -fr ./dist && NODE_ENV=production babel ./src --out-dir ./dist --copy-files --source-maps && flow-copy-source src dist",
99
- "create-readme": "gitdown ./.README/README.md --output-file ./README.md",
100
- "dev": "NODE_ENV=development babel ./src --out-dir ./dist --copy-files --source-maps --watch",
101
- "lint": "eslint ./src ./test && flow",
102
- "test": "NODE_TLS_REJECT_UNAUTHORIZED=false NODE_ENV=test nyc ava --verbose --serial"
90
+ "build": "del-cli ./dist && tsc",
91
+ "lint": "eslint ./src ./test && tsc",
92
+ "test": "ava --verbose --serial",
93
+ "create-readme": "gitdown ./.README/README.md --output-file ./README.md"
103
94
  },
104
- "version": "3.0.0"
95
+ "typings": "./dist/src/index.d.ts",
96
+ "version": "4.0.0"
105
97
  }
@@ -1,6 +1,6 @@
1
- // @flow
2
-
3
- import Roarr from 'roarr';
1
+ import {
2
+ Roarr,
3
+ } from 'roarr';
4
4
 
5
5
  const Logger = Roarr
6
6
  .child({