global-agent 4.1.2 → 4.1.3
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/dist/Logger.d.ts +11 -0
- package/dist/Logger.js +56 -0
- package/dist/classes/Agent.d.ts +46 -0
- package/dist/classes/Agent.js +216 -0
- package/dist/classes/HttpProxyAgent.d.ts +7 -0
- package/dist/classes/HttpProxyAgent.js +20 -0
- package/dist/classes/HttpsProxyAgent.d.ts +7 -0
- package/dist/classes/HttpsProxyAgent.js +48 -0
- package/dist/classes/index.d.ts +3 -0
- package/dist/classes/index.js +12 -0
- package/dist/errors.d.ts +4 -0
- package/dist/errors.js +10 -0
- package/dist/factories/createGlobalProxyAgent.d.ts +7 -0
- package/dist/factories/createGlobalProxyAgent.js +131 -0
- package/dist/factories/createGlobalProxyAgent.test.d.ts +1 -0
- package/dist/factories/createGlobalProxyAgent.test.js +539 -0
- package/dist/factories/createProxyController.d.ts +7 -0
- package/dist/factories/createProxyController.js +38 -0
- package/dist/factories/createProxyController.test.d.ts +1 -0
- package/dist/factories/createProxyController.test.js +29 -0
- package/dist/factories/index.d.ts +2 -0
- package/dist/factories/index.js +10 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +7 -0
- package/dist/routines/bootstrap.d.ts +3 -0
- package/dist/routines/bootstrap.js +20 -0
- package/dist/routines/index.d.ts +1 -0
- package/dist/routines/index.js +8 -0
- package/dist/types.d.ts +57 -0
- package/dist/types.js +2 -0
- package/dist/utilities/bindHttpMethod.d.ts +7 -0
- package/dist/utilities/bindHttpMethod.js +50 -0
- package/dist/utilities/index.d.ts +3 -0
- package/dist/utilities/index.js +12 -0
- package/dist/utilities/isUrlMatchingNoProxy.d.ts +2 -0
- package/dist/utilities/isUrlMatchingNoProxy.js +27 -0
- package/dist/utilities/isUrlMatchingNoProxy.test.d.ts +1 -0
- package/dist/utilities/isUrlMatchingNoProxy.test.js +61 -0
- package/dist/utilities/parseBoolean.d.ts +1 -0
- package/dist/utilities/parseBoolean.js +16 -0
- package/dist/utilities/parseProxyUrl.d.ts +6 -0
- package/dist/utilities/parseProxyUrl.js +31 -0
- package/dist/utilities/parseProxyUrl.test.d.ts +1 -0
- package/dist/utilities/parseProxyUrl.test.js +31 -0
- package/package.json +5 -2
- package/.babelrc +0 -23
- package/.editorconfig +0 -9
- package/.github/FUNDING.yml +0 -2
- package/.github/workflows/feature.yaml +0 -35
- package/.github/workflows/main.yaml +0 -50
- package/.gitignore +0 -12
- package/bootstrap.js +0 -1
- package/src/Logger.ts +0 -70
- package/src/classes/Agent.ts +0 -296
- package/src/classes/HttpProxyAgent.ts +0 -45
- package/src/classes/HttpsProxyAgent.ts +0 -83
- package/src/classes/index.ts +0 -9
- package/src/errors.ts +0 -9
- package/src/factories/createGlobalProxyAgent.test.ts +0 -761
- package/src/factories/createGlobalProxyAgent.ts +0 -187
- package/src/factories/createProxyController.test.ts +0 -38
- package/src/factories/createProxyController.ts +0 -51
- package/src/factories/index.ts +0 -6
- package/src/index.ts +0 -9
- package/src/routines/bootstrap.ts +0 -28
- package/src/routines/index.ts +0 -3
- package/src/types.ts +0 -70
- package/src/utilities/bindHttpMethod.ts +0 -53
- package/src/utilities/index.ts +0 -9
- package/src/utilities/isUrlMatchingNoProxy.test.ts +0 -77
- package/src/utilities/isUrlMatchingNoProxy.ts +0 -32
- package/src/utilities/parseBoolean.ts +0 -17
- package/src/utilities/parseProxyUrl.test.ts +0 -35
- package/src/utilities/parseProxyUrl.ts +0 -39
- package/tsconfig.json +0 -25
- package/vitest.config.ts +0 -11
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as bootstrap, } from './bootstrap';
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.bootstrap = void 0;
|
|
7
|
+
var bootstrap_1 = require("./bootstrap");
|
|
8
|
+
Object.defineProperty(exports, "bootstrap", { enumerable: true, get: function () { return __importDefault(bootstrap_1).default; } });
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
/// <reference types="node" />
|
|
3
|
+
/// <reference types="node" />
|
|
4
|
+
/// <reference types="node" />
|
|
5
|
+
import type { Agent as HttpAgent } from 'http';
|
|
6
|
+
import type { Agent as HttpsAgent } from 'https';
|
|
7
|
+
import type { Socket } from 'net';
|
|
8
|
+
import type { TLSSocket } from 'tls';
|
|
9
|
+
import type { Logger } from './Logger';
|
|
10
|
+
export type ProxyConfigurationType = {
|
|
11
|
+
authorization: string | null;
|
|
12
|
+
hostname: string;
|
|
13
|
+
port: number;
|
|
14
|
+
};
|
|
15
|
+
export type TlsConfigurationType = {
|
|
16
|
+
ca?: string[] | string;
|
|
17
|
+
cert?: string;
|
|
18
|
+
ciphers?: string;
|
|
19
|
+
clientCertEngine?: string;
|
|
20
|
+
crl?: string;
|
|
21
|
+
dhparam?: string;
|
|
22
|
+
ecdhCurve?: string;
|
|
23
|
+
honorCipherOrder?: boolean;
|
|
24
|
+
key?: string;
|
|
25
|
+
passphrase?: string;
|
|
26
|
+
pfx?: string;
|
|
27
|
+
rejectUnauthorized?: boolean;
|
|
28
|
+
secureOptions?: number;
|
|
29
|
+
secureProtocol?: string;
|
|
30
|
+
servername?: string;
|
|
31
|
+
sessionIdContext?: string;
|
|
32
|
+
};
|
|
33
|
+
export type ConnectionConfigurationType = {
|
|
34
|
+
host: string;
|
|
35
|
+
port: number;
|
|
36
|
+
tls?: TlsConfigurationType;
|
|
37
|
+
proxy: ProxyConfigurationType;
|
|
38
|
+
};
|
|
39
|
+
export type ConnectionCallbackType = (error: Error | null, socket?: Socket | TLSSocket) => void;
|
|
40
|
+
export type AgentType = HttpAgent | HttpsAgent;
|
|
41
|
+
export type IsProxyConfiguredMethodType = () => boolean;
|
|
42
|
+
export type MustUrlUseProxyMethodType = (url: string) => boolean;
|
|
43
|
+
export type GetUrlProxyMethodType = (url: string) => ProxyConfigurationType;
|
|
44
|
+
export type ProtocolType = 'http:' | 'https:';
|
|
45
|
+
export type ProxyAgentConfigurationInputType = {
|
|
46
|
+
environmentVariableNamespace?: string;
|
|
47
|
+
forceGlobalAgent?: boolean;
|
|
48
|
+
socketConnectionTimeout?: number;
|
|
49
|
+
ca?: string[] | string;
|
|
50
|
+
logger?: Logger;
|
|
51
|
+
};
|
|
52
|
+
export type ProxyAgentConfigurationType = {
|
|
53
|
+
environmentVariableNamespace: string;
|
|
54
|
+
forceGlobalAgent: boolean;
|
|
55
|
+
socketConnectionTimeout: number;
|
|
56
|
+
ca?: string[] | string;
|
|
57
|
+
};
|
package/dist/types.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
/// <reference types="node" />
|
|
3
|
+
import http from 'http';
|
|
4
|
+
import https from 'https';
|
|
5
|
+
type AgentType = http.Agent | https.Agent;
|
|
6
|
+
declare const _default: (originalMethod: Function, agent: AgentType, forceGlobalAgent: boolean) => (...args: any[]) => any;
|
|
7
|
+
export default _default;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const http_1 = __importDefault(require("http"));
|
|
7
|
+
const https_1 = __importDefault(require("https"));
|
|
8
|
+
exports.default = (originalMethod, agent, forceGlobalAgent) => {
|
|
9
|
+
return (...args) => {
|
|
10
|
+
let url;
|
|
11
|
+
let options;
|
|
12
|
+
let callback;
|
|
13
|
+
if (typeof args[0] === 'string' || args[0] instanceof URL) {
|
|
14
|
+
url = args[0];
|
|
15
|
+
if (typeof args[1] === 'function') {
|
|
16
|
+
options = {};
|
|
17
|
+
callback = args[1];
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
options = {
|
|
21
|
+
...args[1],
|
|
22
|
+
};
|
|
23
|
+
callback = args[2];
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
options = {
|
|
28
|
+
...args[0],
|
|
29
|
+
};
|
|
30
|
+
callback = args[1];
|
|
31
|
+
}
|
|
32
|
+
if (forceGlobalAgent) {
|
|
33
|
+
options.agent = agent;
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
if (!options.agent) {
|
|
37
|
+
options.agent = agent;
|
|
38
|
+
}
|
|
39
|
+
if (options.agent === http_1.default.globalAgent || options.agent === https_1.default.globalAgent) {
|
|
40
|
+
options.agent = agent;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
if (url) {
|
|
44
|
+
return originalMethod(url, options, callback);
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
return originalMethod(options, callback);
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.parseProxyUrl = exports.isUrlMatchingNoProxy = exports.bindHttpMethod = void 0;
|
|
7
|
+
var bindHttpMethod_1 = require("./bindHttpMethod");
|
|
8
|
+
Object.defineProperty(exports, "bindHttpMethod", { enumerable: true, get: function () { return __importDefault(bindHttpMethod_1).default; } });
|
|
9
|
+
var isUrlMatchingNoProxy_1 = require("./isUrlMatchingNoProxy");
|
|
10
|
+
Object.defineProperty(exports, "isUrlMatchingNoProxy", { enumerable: true, get: function () { return __importDefault(isUrlMatchingNoProxy_1).default; } });
|
|
11
|
+
var parseProxyUrl_1 = require("./parseProxyUrl");
|
|
12
|
+
Object.defineProperty(exports, "parseProxyUrl", { enumerable: true, get: function () { return __importDefault(parseProxyUrl_1).default; } });
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const matcher_1 = __importDefault(require("matcher"));
|
|
7
|
+
const errors_1 = require("../errors");
|
|
8
|
+
exports.default = (subjectUrl, noProxy) => {
|
|
9
|
+
const subjectUrlTokens = new URL(subjectUrl);
|
|
10
|
+
const rules = noProxy.split(/[\s,]+/).filter(Boolean);
|
|
11
|
+
for (const rule of rules) {
|
|
12
|
+
const ruleMatch = rule
|
|
13
|
+
.replace(/^(?<leadingDot>\.)/, '*')
|
|
14
|
+
.match(/^(?<hostname>.+?)(?::(?<port>\d+))?$/);
|
|
15
|
+
if (!ruleMatch || !ruleMatch.groups) {
|
|
16
|
+
throw new errors_1.UnexpectedStateError('Invalid NO_PROXY pattern.');
|
|
17
|
+
}
|
|
18
|
+
if (!ruleMatch.groups.hostname) {
|
|
19
|
+
throw new errors_1.UnexpectedStateError('NO_PROXY entry pattern must include hostname. Use * to match any hostname.');
|
|
20
|
+
}
|
|
21
|
+
const hostnameIsMatch = matcher_1.default.isMatch(subjectUrlTokens.hostname, ruleMatch.groups.hostname);
|
|
22
|
+
if (hostnameIsMatch && (!ruleMatch.groups || !ruleMatch.groups.port || subjectUrlTokens.port && subjectUrlTokens.port === ruleMatch.groups.port)) {
|
|
23
|
+
return true;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return false;
|
|
27
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const vitest_1 = require("vitest");
|
|
7
|
+
const isUrlMatchingNoProxy_1 = __importDefault(require("./isUrlMatchingNoProxy"));
|
|
8
|
+
(0, vitest_1.test)('returns `true` if hosts match', () => {
|
|
9
|
+
(0, vitest_1.expect)((0, isUrlMatchingNoProxy_1.default)('http://foo.com/', 'foo.com')).toBe(true);
|
|
10
|
+
});
|
|
11
|
+
(0, vitest_1.test)('returns `true` if hosts match (IP)', () => {
|
|
12
|
+
(0, vitest_1.expect)((0, isUrlMatchingNoProxy_1.default)('http://127.0.0.1/', '127.0.0.1')).toBe(true);
|
|
13
|
+
});
|
|
14
|
+
(0, vitest_1.test)('returns `true` if hosts match (using asterisk wildcard)', () => {
|
|
15
|
+
(0, vitest_1.expect)((0, isUrlMatchingNoProxy_1.default)('http://bar.foo.com/', '*.foo.com')).toBe(true);
|
|
16
|
+
});
|
|
17
|
+
(0, vitest_1.test)('returns `true` if domain matches (using dot wildcard)', () => {
|
|
18
|
+
(0, vitest_1.expect)((0, isUrlMatchingNoProxy_1.default)('http://foo.com/', '.foo.com')).toBe(true);
|
|
19
|
+
});
|
|
20
|
+
(0, vitest_1.test)('returns `true` if subdomain matches (using dot wildcard)', () => {
|
|
21
|
+
(0, vitest_1.expect)((0, isUrlMatchingNoProxy_1.default)('http://bar.foo.com/', '.foo.com')).toBe(true);
|
|
22
|
+
});
|
|
23
|
+
(0, vitest_1.test)('returns `true` if hosts match (*) and ports match', () => {
|
|
24
|
+
(0, vitest_1.expect)((0, isUrlMatchingNoProxy_1.default)('http://foo.com:8080/', '*:8080')).toBe(true);
|
|
25
|
+
});
|
|
26
|
+
(0, vitest_1.test)('returns `true` if hosts and ports match', () => {
|
|
27
|
+
(0, vitest_1.expect)((0, isUrlMatchingNoProxy_1.default)('http://foo.com:8080/', 'foo.com:8080')).toBe(true);
|
|
28
|
+
});
|
|
29
|
+
(0, vitest_1.test)('returns `true` if hosts match and NO_PROXY does not define port', () => {
|
|
30
|
+
(0, vitest_1.expect)((0, isUrlMatchingNoProxy_1.default)('http://foo.com:8080/', 'foo.com')).toBe(true);
|
|
31
|
+
});
|
|
32
|
+
(0, vitest_1.test)('returns `true` if hosts (IP) and ports match', () => {
|
|
33
|
+
(0, vitest_1.expect)((0, isUrlMatchingNoProxy_1.default)('http://127.0.0.1:8080/', '127.0.0.1:8080')).toBe(true);
|
|
34
|
+
});
|
|
35
|
+
(0, vitest_1.test)('returns `false` if hosts match and ports do not match (diffferent port)', () => {
|
|
36
|
+
(0, vitest_1.expect)((0, isUrlMatchingNoProxy_1.default)('http://foo.com:8080/', 'foo.com:8000')).toBe(false);
|
|
37
|
+
});
|
|
38
|
+
(0, vitest_1.test)('returns `false` if hosts match and ports do not match (port not present subject)', () => {
|
|
39
|
+
(0, vitest_1.expect)((0, isUrlMatchingNoProxy_1.default)('http://foo.com/', 'foo.com:8000')).toBe(false);
|
|
40
|
+
});
|
|
41
|
+
(0, vitest_1.test)('returns `true` if hosts match and ports do not match (port not present NO_PROXY)', () => {
|
|
42
|
+
(0, vitest_1.expect)((0, isUrlMatchingNoProxy_1.default)('http://foo.com:8000/', 'foo.com')).toBe(true);
|
|
43
|
+
});
|
|
44
|
+
(0, vitest_1.test)('returns `true` if hosts match in one of multiple rules separated with a comma', () => {
|
|
45
|
+
(0, vitest_1.expect)((0, isUrlMatchingNoProxy_1.default)('http://foo.com/', 'bar.org,foo.com,baz.io')).toBe(true);
|
|
46
|
+
});
|
|
47
|
+
(0, vitest_1.test)('returns `true` if hosts match in one of multiple rules separated with a comma and a space', () => {
|
|
48
|
+
(0, vitest_1.expect)((0, isUrlMatchingNoProxy_1.default)('http://foo.com/', 'bar.org, foo.com, baz.io')).toBe(true);
|
|
49
|
+
});
|
|
50
|
+
(0, vitest_1.test)('returns `true` if hosts match in one of multiple rules separated with a space', () => {
|
|
51
|
+
(0, vitest_1.expect)((0, isUrlMatchingNoProxy_1.default)('http://foo.com/', 'bar.org foo.com baz.io')).toBe(true);
|
|
52
|
+
});
|
|
53
|
+
(0, vitest_1.test)('handles trailing newline in NO_PROXY', () => {
|
|
54
|
+
(0, vitest_1.expect)((0, isUrlMatchingNoProxy_1.default)('http://foo.com/', 'foo.com\n')).toBe(true);
|
|
55
|
+
});
|
|
56
|
+
(0, vitest_1.test)('handles trailing whitespace in NO_PROXY', () => {
|
|
57
|
+
(0, vitest_1.expect)((0, isUrlMatchingNoProxy_1.default)('http://foo.com/', 'foo.com ')).toBe(true);
|
|
58
|
+
});
|
|
59
|
+
(0, vitest_1.test)('handles leading whitespace in NO_PROXY', () => {
|
|
60
|
+
(0, vitest_1.expect)((0, isUrlMatchingNoProxy_1.default)('http://foo.com/', ' foo.com')).toBe(true);
|
|
61
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const parseBoolean: (value: any) => boolean;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parseBoolean = void 0;
|
|
4
|
+
const parseBoolean = function (value) {
|
|
5
|
+
switch (Object.prototype.toString.call(value)) {
|
|
6
|
+
case '[object String]':
|
|
7
|
+
return ['true', 't', 'yes', 'y', 'on', '1'].includes(value.trim().toLowerCase());
|
|
8
|
+
case '[object Number]':
|
|
9
|
+
return value.valueOf() === 1;
|
|
10
|
+
case '[object Boolean]':
|
|
11
|
+
return value.valueOf();
|
|
12
|
+
default:
|
|
13
|
+
return false;
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
exports.parseBoolean = parseBoolean;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const errors_1 = require("../errors");
|
|
4
|
+
exports.default = (url) => {
|
|
5
|
+
const urlTokens = new URL(url);
|
|
6
|
+
if (urlTokens.search !== '') {
|
|
7
|
+
throw new errors_1.UnexpectedStateError('Unsupported `GLOBAL_AGENT.HTTP_PROXY` configuration value: URL must not have query.');
|
|
8
|
+
}
|
|
9
|
+
if (urlTokens.hash !== '') {
|
|
10
|
+
throw new errors_1.UnexpectedStateError('Unsupported `GLOBAL_AGENT.HTTP_PROXY` configuration value: URL must not have hash.');
|
|
11
|
+
}
|
|
12
|
+
if (urlTokens.protocol !== 'http:') {
|
|
13
|
+
throw new errors_1.UnexpectedStateError('Unsupported `GLOBAL_AGENT.HTTP_PROXY` configuration value: URL protocol must be "http:".');
|
|
14
|
+
}
|
|
15
|
+
let port = 80;
|
|
16
|
+
if (urlTokens.port) {
|
|
17
|
+
port = Number.parseInt(urlTokens.port, 10);
|
|
18
|
+
}
|
|
19
|
+
let authorization = null;
|
|
20
|
+
if (urlTokens.username && urlTokens.password) {
|
|
21
|
+
authorization = urlTokens.username + ':' + urlTokens.password;
|
|
22
|
+
}
|
|
23
|
+
else if (urlTokens.username) {
|
|
24
|
+
authorization = urlTokens.username;
|
|
25
|
+
}
|
|
26
|
+
return {
|
|
27
|
+
authorization,
|
|
28
|
+
hostname: urlTokens.hostname,
|
|
29
|
+
port,
|
|
30
|
+
};
|
|
31
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const vitest_1 = require("vitest");
|
|
7
|
+
const parseProxyUrl_1 = __importDefault(require("./parseProxyUrl"));
|
|
8
|
+
(0, vitest_1.test)('extracts hostname', () => {
|
|
9
|
+
(0, vitest_1.expect)((0, parseProxyUrl_1.default)('http://0.0.0.0').hostname).toBe('0.0.0.0');
|
|
10
|
+
});
|
|
11
|
+
(0, vitest_1.test)('extracts port', () => {
|
|
12
|
+
(0, vitest_1.expect)((0, parseProxyUrl_1.default)('http://0.0.0.0:3000').port).toBe(3000);
|
|
13
|
+
});
|
|
14
|
+
(0, vitest_1.test)('extracts authorization', () => {
|
|
15
|
+
(0, vitest_1.expect)((0, parseProxyUrl_1.default)('http://foo:bar@0.0.0.0').authorization).toBe('foo:bar');
|
|
16
|
+
});
|
|
17
|
+
(0, vitest_1.test)('throws an error if protocol is not "http:"', () => {
|
|
18
|
+
(0, vitest_1.expect)(() => {
|
|
19
|
+
(0, parseProxyUrl_1.default)('https://0.0.0.0:3000');
|
|
20
|
+
}).toThrow('Unsupported `GLOBAL_AGENT.HTTP_PROXY` configuration value: URL protocol must be "http:".');
|
|
21
|
+
});
|
|
22
|
+
(0, vitest_1.test)('throws an error if query is present', () => {
|
|
23
|
+
(0, vitest_1.expect)(() => {
|
|
24
|
+
(0, parseProxyUrl_1.default)('http://0.0.0.0:3000/?foo=bar');
|
|
25
|
+
}).toThrow('Unsupported `GLOBAL_AGENT.HTTP_PROXY` configuration value: URL must not have query.');
|
|
26
|
+
});
|
|
27
|
+
(0, vitest_1.test)('throws an error if hash is present', () => {
|
|
28
|
+
(0, vitest_1.expect)(() => {
|
|
29
|
+
(0, parseProxyUrl_1.default)('http://0.0.0.0:3000/#foo');
|
|
30
|
+
}).toThrow('Unsupported `GLOBAL_AGENT.HTTP_PROXY` configuration value: URL must not have hash.');
|
|
31
|
+
});
|
package/package.json
CHANGED
|
@@ -41,6 +41,9 @@
|
|
|
41
41
|
"typescript": "^4.3.5",
|
|
42
42
|
"vitest": "^4.0.18"
|
|
43
43
|
},
|
|
44
|
+
"files": [
|
|
45
|
+
"dist"
|
|
46
|
+
],
|
|
44
47
|
"engines": {
|
|
45
48
|
"node": ">=10.0"
|
|
46
49
|
},
|
|
@@ -56,7 +59,7 @@
|
|
|
56
59
|
"agent"
|
|
57
60
|
],
|
|
58
61
|
"license": "BSD-3-Clause",
|
|
59
|
-
"main": "./dist/
|
|
62
|
+
"main": "./dist/index.js",
|
|
60
63
|
"name": "global-agent",
|
|
61
64
|
"repository": {
|
|
62
65
|
"type": "git",
|
|
@@ -69,5 +72,5 @@
|
|
|
69
72
|
"create-readme": "gitdown ./.README/README.md --output-file ./README.md"
|
|
70
73
|
},
|
|
71
74
|
"typings": "./dist/src/index.d.ts",
|
|
72
|
-
"version": "4.1.
|
|
75
|
+
"version": "4.1.3"
|
|
73
76
|
}
|
package/.babelrc
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
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
DELETED
package/.github/FUNDING.yml
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
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
|
|
@@ -1,50 +0,0 @@
|
|
|
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
DELETED
package/bootstrap.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
require('./dist/index').bootstrap();
|
package/src/Logger.ts
DELETED
|
@@ -1,70 +0,0 @@
|
|
|
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
|
-
// oxlint-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
|
-
});
|