global-agent 3.0.0 → 4.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/.babelrc +23 -0
- package/.editorconfig +9 -0
- package/.eslintignore +1 -0
- package/.eslintrc +27 -0
- package/.github/FUNDING.yml +2 -0
- package/.github/workflows/feature.yaml +35 -0
- package/.github/workflows/main.yaml +50 -0
- package/.gitignore +14 -0
- package/LICENSE +2 -2
- package/README.md +101 -23
- package/package.json +47 -56
- package/src/Logger.ts +70 -0
- package/{dist/classes/Agent.js.flow → src/classes/Agent.ts} +124 -40
- package/src/classes/HttpProxyAgent.ts +45 -0
- package/src/classes/HttpsProxyAgent.ts +83 -0
- package/src/classes/index.ts +9 -0
- package/src/{errors.js → errors.ts} +2 -6
- package/src/factories/{createGlobalProxyAgent.js → createGlobalProxyAgent.ts} +45 -52
- package/src/factories/{createProxyController.js → createProxyController.ts} +12 -7
- package/src/factories/index.ts +6 -0
- package/src/index.ts +9 -0
- package/src/routines/bootstrap.ts +28 -0
- package/src/routines/index.ts +3 -0
- package/src/types.ts +70 -0
- package/src/utilities/{bindHttpMethod.js → bindHttpMethod.ts} +6 -7
- package/src/utilities/index.ts +9 -0
- package/{dist/utilities/isUrlMatchingNoProxy.js.flow → src/utilities/isUrlMatchingNoProxy.ts} +1 -6
- package/src/utilities/parseBoolean.ts +17 -0
- package/src/utilities/{parseProxyUrl.js → parseProxyUrl.ts} +12 -9
- package/test/.eslintrc +10 -0
- package/test/global-agent/factories/createGlobalProxyAgent.ts +760 -0
- package/test/global-agent/factories/createProxyController.ts +37 -0
- package/test/global-agent/utilities/isUrlMatchingNoProxy.ts +62 -0
- package/test/global-agent/utilities/parseProxyUrl.ts +38 -0
- package/tsconfig.json +25 -0
- package/.flowconfig +0 -3
- package/dist/Logger.js +0 -18
- package/dist/Logger.js.flow +0 -10
- package/dist/Logger.js.map +0 -1
- package/dist/classes/Agent.js +0 -174
- package/dist/classes/Agent.js.map +0 -1
- package/dist/classes/HttpProxyAgent.js +0 -33
- package/dist/classes/HttpProxyAgent.js.flow +0 -30
- package/dist/classes/HttpProxyAgent.js.map +0 -1
- package/dist/classes/HttpsProxyAgent.js +0 -53
- package/dist/classes/HttpsProxyAgent.js.flow +0 -54
- package/dist/classes/HttpsProxyAgent.js.map +0 -1
- package/dist/classes/index.js +0 -32
- package/dist/classes/index.js.flow +0 -5
- package/dist/classes/index.js.map +0 -1
- package/dist/errors.js +0 -22
- package/dist/errors.js.flow +0 -15
- package/dist/errors.js.map +0 -1
- package/dist/factories/createGlobalProxyAgent.js +0 -175
- package/dist/factories/createGlobalProxyAgent.js.flow +0 -197
- package/dist/factories/createGlobalProxyAgent.js.map +0 -1
- package/dist/factories/createProxyController.js +0 -45
- package/dist/factories/createProxyController.js.flow +0 -46
- package/dist/factories/createProxyController.js.map +0 -1
- package/dist/factories/index.js +0 -24
- package/dist/factories/index.js.flow +0 -4
- package/dist/factories/index.js.map +0 -1
- package/dist/index.js +0 -22
- package/dist/index.js.flow +0 -4
- package/dist/index.js.map +0 -1
- package/dist/routines/bootstrap.js +0 -30
- package/dist/routines/bootstrap.js.flow +0 -25
- package/dist/routines/bootstrap.js.map +0 -1
- package/dist/routines/index.js +0 -16
- package/dist/routines/index.js.flow +0 -3
- package/dist/routines/index.js.map +0 -1
- package/dist/types.js +0 -10
- package/dist/types.js.flow +0 -66
- package/dist/types.js.map +0 -1
- package/dist/utilities/bindHttpMethod.js +0 -62
- package/dist/utilities/bindHttpMethod.js.flow +0 -54
- package/dist/utilities/bindHttpMethod.js.map +0 -1
- package/dist/utilities/index.js +0 -32
- package/dist/utilities/index.js.flow +0 -5
- package/dist/utilities/index.js.map +0 -1
- package/dist/utilities/isUrlMatchingNoProxy.js +0 -43
- package/dist/utilities/isUrlMatchingNoProxy.js.map +0 -1
- package/dist/utilities/parseProxyUrl.js +0 -42
- package/dist/utilities/parseProxyUrl.js.flow +0 -36
- package/dist/utilities/parseProxyUrl.js.map +0 -1
- package/src/Logger.js +0 -10
- package/src/classes/Agent.js +0 -212
- package/src/classes/HttpProxyAgent.js +0 -30
- package/src/classes/HttpsProxyAgent.js +0 -54
- package/src/classes/index.js +0 -5
- package/src/factories/index.js +0 -4
- package/src/index.js +0 -4
- package/src/routines/bootstrap.js +0 -25
- package/src/routines/index.js +0 -3
- package/src/types.js +0 -66
- package/src/utilities/index.js +0 -5
- 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
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,35 @@
|
|
|
1
|
+
jobs:
|
|
2
|
+
test:
|
|
3
|
+
name: Test (Node ${{ matrix.node-version }})
|
|
4
|
+
runs-on: ubuntu-latest
|
|
5
|
+
strategy:
|
|
6
|
+
matrix:
|
|
7
|
+
node-version: ['20', '22', '24']
|
|
8
|
+
steps:
|
|
9
|
+
- name: setup repository
|
|
10
|
+
uses: actions/checkout@v3
|
|
11
|
+
with:
|
|
12
|
+
fetch-depth: 0
|
|
13
|
+
- name: setup node.js
|
|
14
|
+
uses: actions/setup-node@v4
|
|
15
|
+
with:
|
|
16
|
+
node-version: ${{ matrix.node-version }}
|
|
17
|
+
- name: setup npm
|
|
18
|
+
uses: npm/action-setup@v4
|
|
19
|
+
with:
|
|
20
|
+
version: 10
|
|
21
|
+
- run: npm install
|
|
22
|
+
- run: npm run lint
|
|
23
|
+
- run: npm run test
|
|
24
|
+
- run: npm run build
|
|
25
|
+
timeout-minutes: 10
|
|
26
|
+
name: Test
|
|
27
|
+
on:
|
|
28
|
+
pull_request:
|
|
29
|
+
branches:
|
|
30
|
+
- main
|
|
31
|
+
types:
|
|
32
|
+
- opened
|
|
33
|
+
- synchronize
|
|
34
|
+
- reopened
|
|
35
|
+
- ready_for_review
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
jobs:
|
|
2
|
+
test:
|
|
3
|
+
name: Test (Node ${{ matrix.node-version }})
|
|
4
|
+
runs-on: ubuntu-latest
|
|
5
|
+
strategy:
|
|
6
|
+
matrix:
|
|
7
|
+
node-version: ['20', '22', '24']
|
|
8
|
+
steps:
|
|
9
|
+
- name: setup repository
|
|
10
|
+
uses: actions/checkout@v3
|
|
11
|
+
with:
|
|
12
|
+
fetch-depth: 0
|
|
13
|
+
- name: setup node.js
|
|
14
|
+
uses: actions/setup-node@v4
|
|
15
|
+
with:
|
|
16
|
+
node-version: ${{ matrix.node-version }}
|
|
17
|
+
- run: npm install
|
|
18
|
+
- run: npm run lint
|
|
19
|
+
- run: npm run test
|
|
20
|
+
- run: npm run build
|
|
21
|
+
timeout-minutes: 10
|
|
22
|
+
release:
|
|
23
|
+
needs: test
|
|
24
|
+
environment: release
|
|
25
|
+
name: Release
|
|
26
|
+
permissions:
|
|
27
|
+
contents: write
|
|
28
|
+
id-token: write
|
|
29
|
+
issues: write
|
|
30
|
+
pull-requests: write
|
|
31
|
+
runs-on: ubuntu-latest
|
|
32
|
+
steps:
|
|
33
|
+
- name: setup repository
|
|
34
|
+
uses: actions/checkout@v3
|
|
35
|
+
with:
|
|
36
|
+
fetch-depth: 0
|
|
37
|
+
- name: setup node.js
|
|
38
|
+
uses: actions/setup-node@v4
|
|
39
|
+
with:
|
|
40
|
+
node-version: '24'
|
|
41
|
+
- run: npm install
|
|
42
|
+
- run: npm run build
|
|
43
|
+
- env:
|
|
44
|
+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
45
|
+
run: npx semantic-release
|
|
46
|
+
name: Release
|
|
47
|
+
on:
|
|
48
|
+
push:
|
|
49
|
+
branches:
|
|
50
|
+
- main
|
package/.gitignore
ADDED
package/LICENSE
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
Copyright (c)
|
|
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 (
|
|
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
|
-
[](https://gitspo.com/mentions/gajus/global-agent)
|
|
4
|
-
[](https://travis-ci.org/gajus/global-agent)
|
|
5
3
|
[](https://coveralls.io/github/gajus/global-agent)
|
|
6
4
|
[](https://www.npmjs.org/package/global-agent)
|
|
7
5
|
[](https://github.com/gajus/canonical)
|
|
@@ -14,7 +12,6 @@ Global HTTP/HTTPS proxy configurable using environment variables.
|
|
|
14
12
|
* [Setup proxy using `bootstrap` routine](#setup-proxy-using-bootstrap-routine)
|
|
15
13
|
* [Runtime configuration](#runtime-configuration)
|
|
16
14
|
* [Exclude URLs](#exclude-urls)
|
|
17
|
-
* [Enable logging](#enable-logging)
|
|
18
15
|
* [API](#api)
|
|
19
16
|
* [`createGlobalProxyAgent`](#createglobalproxyagent)
|
|
20
17
|
* [Environment variables](#environment-variables)
|
|
@@ -125,7 +122,7 @@ global.GLOBAL_AGENT.HTTP_PROXY = 'http://127.0.0.1:8002';
|
|
|
125
122
|
|
|
126
123
|
```
|
|
127
124
|
|
|
128
|
-
The first HTTP request is going to use http://127.0.0.1:8001 proxy and the
|
|
125
|
+
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
126
|
|
|
130
127
|
All `global-agent` configuration is available under `global.GLOBAL_AGENT` namespace.
|
|
131
128
|
|
|
@@ -144,20 +141,6 @@ says to contact all machines with the 'foo.com' TLD and 'baz.com' domains direct
|
|
|
144
141
|
|
|
145
142
|
The environment variable `GLOBAL_AGENT_HTTPS_PROXY` can be set to specify a separate proxy for HTTPS requests. When this variable is not set `GLOBAL_AGENT_HTTP_PROXY` is used for both HTTP and HTTPS requests.
|
|
146
143
|
|
|
147
|
-
### Enable logging
|
|
148
|
-
|
|
149
|
-
`global-agent` is using [`roarr`](https://www.npmjs.com/package/roarr) logger to log HTTP requests and response (HTTP status code and headers), e.g.
|
|
150
|
-
|
|
151
|
-
```json
|
|
152
|
-
{"context":{"program":"global-agent","namespace":"Agent","logLevel":10,"destination":"http://gajus.com","proxy":"http://127.0.0.1:8076"},"message":"proxying request","sequence":1,"time":1556269669663,"version":"1.0.0"}
|
|
153
|
-
{"context":{"program":"global-agent","namespace":"Agent","logLevel":10,"headers":{"content-type":"text/plain","content-length":"2","date":"Fri, 26 Apr 2019 12:07:50 GMT","connection":"close"},"requestId":6,"statusCode":200},"message":"proxying response","sequence":2,"time":1557133856955,"version":"1.0.0"}
|
|
154
|
-
|
|
155
|
-
```
|
|
156
|
-
|
|
157
|
-
Export `ROARR_LOG=true` environment variable to enable log printing to stdout.
|
|
158
|
-
|
|
159
|
-
Use [`roarr-cli`](https://github.com/gajus/roarr-cli) program to pretty-print the logs.
|
|
160
|
-
|
|
161
144
|
## API
|
|
162
145
|
|
|
163
146
|
### `createGlobalProxyAgent`
|
|
@@ -167,17 +150,53 @@ Use [`roarr-cli`](https://github.com/gajus/roarr-cli) program to pretty-print th
|
|
|
167
150
|
* @property environmentVariableNamespace Defines namespace of `HTTP_PROXY`, `HTTPS_PROXY` and `NO_PROXY` environment variables. (Default: `GLOBAL_AGENT_`)
|
|
168
151
|
* @property forceGlobalAgent Forces to use `global-agent` HTTP(S) agent even when request was explicitly constructed with another agent. (Default: `true`)
|
|
169
152
|
* @property socketConnectionTimeout Destroys socket if connection is not established within the timeout. (Default: `60000`)
|
|
153
|
+
* @property ca Single CA certificate or an array of CA certificates that is trusted for secure connections to the registry.
|
|
154
|
+
* @property logger Custom logger instance for debug logging. Must implement `child`, `debug`, `error`, `info`, `trace`, and `warn` methods.
|
|
170
155
|
*/
|
|
171
156
|
type ProxyAgentConfigurationInputType = {|
|
|
172
157
|
+environmentVariableNamespace?: string,
|
|
173
158
|
+forceGlobalAgent?: boolean,
|
|
174
159
|
+socketConnectionTimeout?: number,
|
|
160
|
+
+ca?: string[] | string,
|
|
161
|
+
+logger?: Logger,
|
|
175
162
|
|};
|
|
176
163
|
|
|
177
164
|
(configurationInput: ProxyAgentConfigurationInputType) => ProxyAgentConfigurationType;
|
|
178
165
|
|
|
179
166
|
```
|
|
180
167
|
|
|
168
|
+
### Custom Logger
|
|
169
|
+
|
|
170
|
+
You can provide a custom logger to `global-agent` for debugging purposes. The logger must implement the following interface:
|
|
171
|
+
|
|
172
|
+
```ts
|
|
173
|
+
type Logger = {
|
|
174
|
+
child: (context: object) => Logger,
|
|
175
|
+
debug: (context: object | string, message?: string) => void,
|
|
176
|
+
error: (context: object | string, message?: string) => void,
|
|
177
|
+
info: (context: object | string, message?: string) => void,
|
|
178
|
+
trace: (context: object | string, message?: string) => void,
|
|
179
|
+
warn: (context: object | string, message?: string) => void,
|
|
180
|
+
};
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
Example using a custom logger:
|
|
184
|
+
|
|
185
|
+
```js
|
|
186
|
+
import { createGlobalProxyAgent } from 'global-agent';
|
|
187
|
+
|
|
188
|
+
createGlobalProxyAgent({
|
|
189
|
+
logger: {
|
|
190
|
+
child: () => logger,
|
|
191
|
+
debug: console.debug,
|
|
192
|
+
error: console.error,
|
|
193
|
+
info: console.info,
|
|
194
|
+
trace: console.trace,
|
|
195
|
+
warn: console.warn,
|
|
196
|
+
},
|
|
197
|
+
});
|
|
198
|
+
```
|
|
199
|
+
|
|
181
200
|
### Environment variables
|
|
182
201
|
|
|
183
202
|
|Name|Description|Default|
|
|
@@ -185,9 +204,9 @@ type ProxyAgentConfigurationInputType = {|
|
|
|
185
204
|
|`GLOBAL_AGENT_ENVIRONMENT_VARIABLE_NAMESPACE`|Defines namespace of `HTTP_PROXY`, `HTTPS_PROXY` and `NO_PROXY` environment variables.|`GLOBAL_AGENT_`|
|
|
186
205
|
|`GLOBAL_AGENT_FORCE_GLOBAL_AGENT`|Forces to use `global-agent` HTTP(S) agent even when request was explicitly constructed with another agent.|`true`|
|
|
187
206
|
|`GLOBAL_AGENT_SOCKET_CONNECTION_TIMEOUT`|Destroys socket if connection is not established within the timeout.|`60000`|
|
|
188
|
-
|`${NAMESPACE}
|
|
189
|
-
|`${NAMESPACE}
|
|
190
|
-
|`${NAMESPACE}
|
|
207
|
+
|`${NAMESPACE}HTTP_PROXY`|Sets the initial proxy controller HTTP_PROXY value.|N/A|
|
|
208
|
+
|`${NAMESPACE}HTTPS_PROXY`|Sets the initial proxy controller HTTPS_PROXY value.|N/A|
|
|
209
|
+
|`${NAMESPACE}NO_PROXY`|Sets the initial proxy controller NO_PROXY value.|N/A|
|
|
191
210
|
|
|
192
211
|
### `global.GLOBAL_AGENT`
|
|
193
212
|
|
|
@@ -195,12 +214,71 @@ type ProxyAgentConfigurationInputType = {|
|
|
|
195
214
|
|
|
196
215
|
`global.GLOBAL_AGENT` has the following properties:
|
|
197
216
|
|
|
198
|
-
|Name|Description|
|
|
217
|
+
|Name|Configurable|Description|
|
|
199
218
|
|---|---|---|
|
|
200
219
|
|`HTTP_PROXY`|Yes|Sets HTTP proxy to use.|
|
|
201
220
|
|`HTTPS_PROXY`|Yes|Sets a distinct proxy to use for HTTPS requests.|
|
|
202
221
|
|`NO_PROXY`|Yes|Specifies a pattern of URLs that should be excluded from proxying. See [Exclude URLs](#exclude-urls).|
|
|
203
222
|
|
|
223
|
+
## Certificate Authority (CA)
|
|
224
|
+
|
|
225
|
+
### `addCACertificates`
|
|
226
|
+
This method can be accessed using https to add CA certificates to the global-agent.
|
|
227
|
+
|
|
228
|
+
Uses:
|
|
229
|
+
```js
|
|
230
|
+
if (typeof https.globalAgent.addCACertificates === 'function') {
|
|
231
|
+
//certificate - an array of ca certificates to be added to the global-agent
|
|
232
|
+
https.globalAgent.addCACertificates(certificate);
|
|
233
|
+
}
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
Method Definition:
|
|
237
|
+
```js
|
|
238
|
+
/**
|
|
239
|
+
* This method can be used to append new ca certificates to existing ca certificates
|
|
240
|
+
* @param {string[] | string} ca a ca certificate or an array of ca certificates
|
|
241
|
+
*/
|
|
242
|
+
public addCACertificates (ca: string[] | string) {
|
|
243
|
+
if (!ca) {
|
|
244
|
+
log.error('Invalid input ca certificate');
|
|
245
|
+
} else if (this.ca) {
|
|
246
|
+
if (typeof ca === typeof this.ca) {
|
|
247
|
+
// concat valid ca certificates with the existing certificates,
|
|
248
|
+
if (typeof this.ca === 'string') {
|
|
249
|
+
this.ca = this.ca.concat(ca as string);
|
|
250
|
+
} else {
|
|
251
|
+
this.ca = this.ca.concat(ca as string[]);
|
|
252
|
+
}
|
|
253
|
+
} else {
|
|
254
|
+
log.error('Input ca certificate type mismatched with existing ca certificate type');
|
|
255
|
+
}
|
|
256
|
+
} else {
|
|
257
|
+
this.ca = ca;
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
```
|
|
261
|
+
|
|
262
|
+
### `clearCACertificates`
|
|
263
|
+
This method can be accessed using https to clear existing CA certificates from global-agent.
|
|
264
|
+
|
|
265
|
+
Uses:
|
|
266
|
+
```js
|
|
267
|
+
if (typeof https.globalAgent.clearCACertificates === 'function') {
|
|
268
|
+
https.globalAgent.clearCACertificates();
|
|
269
|
+
}
|
|
270
|
+
```
|
|
271
|
+
Method Definition:
|
|
272
|
+
```js
|
|
273
|
+
/**
|
|
274
|
+
* This method clears existing CA Certificates.
|
|
275
|
+
* It sets ca to undefined
|
|
276
|
+
*/
|
|
277
|
+
public clearCACertificates () {
|
|
278
|
+
this.ca = undefined;
|
|
279
|
+
}
|
|
280
|
+
```
|
|
281
|
+
|
|
204
282
|
## Supported libraries
|
|
205
283
|
|
|
206
284
|
`global-agent` works with all libraries that internally use [`http.request`](https://nodejs.org/api/http.html#http_http_request_options_callback).
|
|
@@ -209,7 +287,7 @@ type ProxyAgentConfigurationInputType = {|
|
|
|
209
287
|
|
|
210
288
|
* [`got`](https://www.npmjs.com/package/got)
|
|
211
289
|
* [`axios`](https://www.npmjs.com/package/axios)
|
|
212
|
-
* [`request`](https://www.npmjs.com/package/
|
|
290
|
+
* [`request`](https://www.npmjs.com/package/request)
|
|
213
291
|
|
|
214
292
|
## FAQ
|
|
215
293
|
|
package/package.json
CHANGED
|
@@ -5,53 +5,60 @@
|
|
|
5
5
|
"url": "http://gajus.com"
|
|
6
6
|
},
|
|
7
7
|
"ava": {
|
|
8
|
-
"
|
|
9
|
-
"
|
|
10
|
-
|
|
11
|
-
]
|
|
12
|
-
},
|
|
8
|
+
"extensions": [
|
|
9
|
+
"ts"
|
|
10
|
+
],
|
|
13
11
|
"files": [
|
|
14
12
|
"test/global-agent/**/*"
|
|
15
13
|
],
|
|
16
14
|
"require": [
|
|
17
|
-
"
|
|
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
|
-
"
|
|
24
|
-
"
|
|
25
|
-
"
|
|
26
|
-
"
|
|
20
|
+
"globalthis": "^1.0.2",
|
|
21
|
+
"matcher": "^4.0.0",
|
|
22
|
+
"omit-undefined": "^1.0.1",
|
|
23
|
+
"semver": "^7.3.5",
|
|
24
|
+
"serialize-error": "^8.1.0"
|
|
27
25
|
},
|
|
28
26
|
"description": "Global HTTP/HTTPS proxy configurable using environment variables.",
|
|
29
27
|
"devDependencies": {
|
|
30
|
-
"@ava/babel": "^
|
|
31
|
-
"@babel/cli": "^7.
|
|
32
|
-
"@babel/core": "^7.
|
|
33
|
-
"@babel/node": "^7.
|
|
34
|
-
"@babel/plugin-transform-flow-strip-types": "^7.
|
|
35
|
-
"@babel/preset-env": "^7.
|
|
36
|
-
"@babel/register": "^7.
|
|
37
|
-
"
|
|
38
|
-
"
|
|
39
|
-
"
|
|
28
|
+
"@ava/babel": "^2.0.0",
|
|
29
|
+
"@babel/cli": "^7.14.8",
|
|
30
|
+
"@babel/core": "^7.14.8",
|
|
31
|
+
"@babel/node": "^7.14.7",
|
|
32
|
+
"@babel/plugin-transform-flow-strip-types": "^7.14.5",
|
|
33
|
+
"@babel/preset-env": "^7.14.8",
|
|
34
|
+
"@babel/register": "^7.14.5",
|
|
35
|
+
"@istanbuljs/nyc-config-typescript": "^1.0.1",
|
|
36
|
+
"@semantic-release/commit-analyzer": "^13.0.1",
|
|
37
|
+
"@semantic-release/github": "^12.0.3",
|
|
38
|
+
"@semantic-release/npm": "^13.1.3",
|
|
39
|
+
"@types/globalthis": "^1.0.1",
|
|
40
|
+
"@types/pem": "^1.14.4",
|
|
41
|
+
"@types/request": "^2.48.6",
|
|
42
|
+
"@types/semver": "^7.3.8",
|
|
43
|
+
"@types/sinon": "^10.0.2",
|
|
44
|
+
"ava": "^3.15.0",
|
|
45
|
+
"axios": "^0.21.1",
|
|
40
46
|
"babel-plugin-istanbul": "^6.0.0",
|
|
41
|
-
"babel-plugin-transform-export-default-name": "^2.0
|
|
42
|
-
"coveralls": "^3.1.
|
|
43
|
-
"
|
|
44
|
-
"eslint
|
|
45
|
-
"
|
|
46
|
-
"flow-copy-source": "^2.0.9",
|
|
47
|
+
"babel-plugin-transform-export-default-name": "^2.1.0",
|
|
48
|
+
"coveralls": "^3.1.1",
|
|
49
|
+
"del-cli": "^4.0.1",
|
|
50
|
+
"eslint": "^7.31.0",
|
|
51
|
+
"eslint-config-canonical": "^26.2.3",
|
|
47
52
|
"get-port": "^5.1.1",
|
|
48
|
-
"got": "^11.
|
|
49
|
-
"husky": "^
|
|
53
|
+
"got": "^11.8.2",
|
|
54
|
+
"husky": "^7.0.1",
|
|
50
55
|
"nyc": "^15.1.0",
|
|
51
56
|
"pem": "^1.14.4",
|
|
52
57
|
"request": "^2.88.2",
|
|
53
|
-
"semantic-release": "^
|
|
54
|
-
"sinon": "^
|
|
58
|
+
"semantic-release": "^25.0.3",
|
|
59
|
+
"sinon": "^11.1.2",
|
|
60
|
+
"ts-node": "^10.1.0",
|
|
61
|
+
"typescript": "^4.3.5"
|
|
55
62
|
},
|
|
56
63
|
"engines": {
|
|
57
64
|
"node": ">=10.0"
|
|
@@ -68,38 +75,22 @@
|
|
|
68
75
|
"agent"
|
|
69
76
|
],
|
|
70
77
|
"license": "BSD-3-Clause",
|
|
71
|
-
"main": "./dist/index.js",
|
|
78
|
+
"main": "./dist/src/index.js",
|
|
72
79
|
"name": "global-agent",
|
|
73
80
|
"nyc": {
|
|
74
|
-
"
|
|
75
|
-
"
|
|
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
|
|
81
|
+
"extends": "@istanbuljs/nyc-config-typescript",
|
|
82
|
+
"all": true
|
|
92
83
|
},
|
|
93
84
|
"repository": {
|
|
94
85
|
"type": "git",
|
|
95
86
|
"url": "https://github.com/gajus/global-agent"
|
|
96
87
|
},
|
|
97
88
|
"scripts": {
|
|
98
|
-
"build": "
|
|
99
|
-
"
|
|
100
|
-
"
|
|
101
|
-
"
|
|
102
|
-
"test": "NODE_TLS_REJECT_UNAUTHORIZED=false NODE_ENV=test nyc ava --verbose --serial"
|
|
89
|
+
"build": "del-cli ./dist && tsc",
|
|
90
|
+
"lint": "eslint ./src ./test && tsc",
|
|
91
|
+
"test": "ava --verbose --serial",
|
|
92
|
+
"create-readme": "gitdown ./.README/README.md --output-file ./README.md"
|
|
103
93
|
},
|
|
104
|
-
"
|
|
94
|
+
"typings": "./dist/src/index.d.ts",
|
|
95
|
+
"version": "4.1.0"
|
|
105
96
|
}
|
package/src/Logger.ts
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
export type LogMethod = (context: object | string, message?: string) => void;
|
|
2
|
+
|
|
3
|
+
export type Logger = {
|
|
4
|
+
child: (context: object) => Logger,
|
|
5
|
+
debug: LogMethod,
|
|
6
|
+
error: LogMethod,
|
|
7
|
+
info: LogMethod,
|
|
8
|
+
trace: LogMethod,
|
|
9
|
+
warn: LogMethod,
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
13
|
+
const noop = () => {};
|
|
14
|
+
|
|
15
|
+
const createNoopLogger = (): Logger => {
|
|
16
|
+
return {
|
|
17
|
+
child: () => {
|
|
18
|
+
return createNoopLogger();
|
|
19
|
+
},
|
|
20
|
+
debug: noop,
|
|
21
|
+
error: noop,
|
|
22
|
+
info: noop,
|
|
23
|
+
trace: noop,
|
|
24
|
+
warn: noop,
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
let currentLogger: Logger = createNoopLogger();
|
|
29
|
+
|
|
30
|
+
export const setLogger = (newLogger: Logger): void => {
|
|
31
|
+
currentLogger = newLogger;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
const createDelegatingLogger = (getContext: () => object): Logger => {
|
|
35
|
+
const getLogger = () => {
|
|
36
|
+
let targetLogger = currentLogger;
|
|
37
|
+
for (const [key, value] of Object.entries(getContext())) {
|
|
38
|
+
targetLogger = targetLogger.child({[key]: value});
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return targetLogger;
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
return {
|
|
45
|
+
child: (context: object) => {
|
|
46
|
+
return createDelegatingLogger(() => {
|
|
47
|
+
return {...getContext(), ...context};
|
|
48
|
+
});
|
|
49
|
+
},
|
|
50
|
+
debug: (context, message) => {
|
|
51
|
+
getLogger().debug(context, message);
|
|
52
|
+
},
|
|
53
|
+
error: (context, message) => {
|
|
54
|
+
getLogger().error(context, message);
|
|
55
|
+
},
|
|
56
|
+
info: (context, message) => {
|
|
57
|
+
getLogger().info(context, message);
|
|
58
|
+
},
|
|
59
|
+
trace: (context, message) => {
|
|
60
|
+
getLogger().trace(context, message);
|
|
61
|
+
},
|
|
62
|
+
warn: (context, message) => {
|
|
63
|
+
getLogger().warn(context, message);
|
|
64
|
+
},
|
|
65
|
+
};
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
export const logger = createDelegatingLogger(() => {
|
|
69
|
+
return {package: 'global-agent'};
|
|
70
|
+
});
|