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
@@ -1,46 +0,0 @@
1
- // @flow
2
-
3
- import Logger from '../Logger';
4
-
5
- type ProxyControllerType = {|
6
- HTTP_PROXY: string | null,
7
- HTTPS_PROXY: string | null,
8
- NO_PROXY: string | null,
9
- |};
10
-
11
- const log = Logger.child({
12
- namespace: 'createProxyController',
13
- });
14
-
15
- const KNOWN_PROPERTY_NAMES = [
16
- 'HTTP_PROXY',
17
- 'HTTPS_PROXY',
18
- 'NO_PROXY',
19
- ];
20
-
21
- export default (): ProxyControllerType => {
22
- // eslint-disable-next-line fp/no-proxy
23
- return new Proxy({
24
- HTTP_PROXY: null,
25
- HTTPS_PROXY: null,
26
- NO_PROXY: null,
27
- }, {
28
- set: (subject, name, value) => {
29
- if (!KNOWN_PROPERTY_NAMES.includes(name)) {
30
- throw new Error('Cannot set an unmapped property "' + name + '".');
31
- }
32
-
33
- subject[name] = value;
34
-
35
- log.info({
36
- change: {
37
- name,
38
- value,
39
- },
40
- newConfiguration: subject,
41
- }, 'configuration changed');
42
-
43
- return true;
44
- },
45
- });
46
- };
@@ -1,4 +0,0 @@
1
- // @flow
2
-
3
- export {default as createGlobalProxyAgent} from './createGlobalProxyAgent';
4
- export {default as createProxyController} from './createProxyController';
package/src/index.js DELETED
@@ -1,4 +0,0 @@
1
- // @flow
2
-
3
- export {bootstrap} from './routines';
4
- export {createGlobalProxyAgent} from './factories';
@@ -1,25 +0,0 @@
1
- // @flow
2
-
3
- import Logger from '../Logger';
4
- import {
5
- createGlobalProxyAgent,
6
- } from '../factories';
7
- import type {
8
- ProxyAgentConfigurationInputType,
9
- } from '../types';
10
-
11
- const log = Logger.child({
12
- namespace: 'bootstrap',
13
- });
14
-
15
- export default (configurationInput?: ProxyAgentConfigurationInputType): boolean => {
16
- if (global.GLOBAL_AGENT) {
17
- log.warn('found global.GLOBAL_AGENT; second attempt to bootstrap global-agent was ignored');
18
-
19
- return false;
20
- }
21
-
22
- global.GLOBAL_AGENT = createGlobalProxyAgent(configurationInput);
23
-
24
- return true;
25
- };
@@ -1,3 +0,0 @@
1
- // @flow
2
-
3
- export {default as bootstrap} from './bootstrap';
package/src/types.js DELETED
@@ -1,66 +0,0 @@
1
- // @flow
2
-
3
- import {
4
- Socket,
5
- } from 'net';
6
- import {
7
- TLSSocket,
8
- } from 'tls';
9
- import {
10
- Agent as HttpAgent,
11
- } from 'http';
12
- import {
13
- Agent as HttpsAgent,
14
- } from 'https';
15
-
16
- export type ProxyConfigurationType = {|
17
- +authorization: string,
18
- +hostname: string,
19
- +port: number,
20
- |};
21
-
22
- export type TlsConfigurationType = {|
23
- +ca?: string,
24
- +cert?: string,
25
- +ciphers?: string,
26
- +clientCertEngine?: string,
27
- +crl?: string,
28
- +dhparam?: string,
29
- +ecdhCurve?: string,
30
- +honorCipherOrder?: boolean,
31
- +key?: string,
32
- +passphrase?: string,
33
- +pfx?: string,
34
- +rejectUnauthorized?: boolean,
35
- +secureOptions?: number,
36
- +secureProtocol?: string,
37
- +servername?: string,
38
- +sessionIdContext?: string,
39
- |};
40
-
41
- export type ConnectionConfigurationType = {|
42
- +host: string,
43
- +port: number,
44
- +tls?: TlsConfigurationType,
45
- +proxy: ProxyConfigurationType,
46
- |};
47
-
48
- export type ConnectionCallbackType = (error: Error | null, socket?: Socket | TLSSocket) => void;
49
-
50
- export type AgentType = HttpAgent | HttpsAgent;
51
- export type IsProxyConfiguredMethodType = () => boolean;
52
- export type MustUrlUseProxyMethodType = (url: string) => boolean;
53
- export type GetUrlProxyMethodType = (url: string) => ProxyConfigurationType;
54
- export type ProtocolType = 'http:' | 'https:';
55
-
56
- export type ProxyAgentConfigurationInputType = {|
57
- +environmentVariableNamespace?: string,
58
- +forceGlobalAgent?: boolean,
59
- +socketConnectionTimeout?: number,
60
- |};
61
-
62
- export type ProxyAgentConfigurationType = {|
63
- +environmentVariableNamespace: string,
64
- +forceGlobalAgent: boolean,
65
- +socketConnectionTimeout: number,
66
- |};
@@ -1,5 +0,0 @@
1
- // @flow
2
-
3
- export {default as bindHttpMethod} from './bindHttpMethod';
4
- export {default as isUrlMatchingNoProxy} from './isUrlMatchingNoProxy';
5
- export {default as parseProxyUrl} from './parseProxyUrl';
@@ -1,37 +0,0 @@
1
- // @flow
2
-
3
- import {
4
- parse as parseUrl,
5
- } from 'url';
6
- import matcher from 'matcher';
7
- import {
8
- UnexpectedStateError,
9
- } from '../errors';
10
-
11
- export default (subjectUrl: string, noProxy: string) => {
12
- const subjectUrlTokens = parseUrl(subjectUrl);
13
-
14
- const rules = noProxy.split(/[\s,]+/);
15
-
16
- for (const rule of rules) {
17
- const ruleMatch = rule
18
- .replace(/^(?<leadingDot>\.)/, '*')
19
- .match(/^(?<hostname>.+?)(?::(?<port>\d+))?$/);
20
-
21
- if (!ruleMatch || !ruleMatch.groups) {
22
- throw new UnexpectedStateError('Invalid NO_PROXY pattern.');
23
- }
24
-
25
- if (!ruleMatch.groups.hostname) {
26
- throw new UnexpectedStateError('NO_PROXY entry pattern must include hostname. Use * to match any hostname.');
27
- }
28
-
29
- const hostnameIsMatch = matcher.isMatch(subjectUrlTokens.hostname, ruleMatch.groups.hostname);
30
-
31
- if (hostnameIsMatch && (!ruleMatch.groups || !ruleMatch.groups.port || subjectUrlTokens.port && subjectUrlTokens.port === ruleMatch.groups.port)) {
32
- return true;
33
- }
34
- }
35
-
36
- return false;
37
- };