global-agent 4.0.0 → 4.1.1

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/src/index.ts CHANGED
@@ -4,3 +4,6 @@ export {
4
4
  export {
5
5
  createGlobalProxyAgent,
6
6
  } from './factories';
7
+ export type {
8
+ Logger,
9
+ } from './Logger';
@@ -1,5 +1,7 @@
1
1
  import createGlobalThis from 'globalthis';
2
- import Logger from '../Logger';
2
+ import {
3
+ logger,
4
+ } from '../Logger';
3
5
  import {
4
6
  createGlobalProxyAgent,
5
7
  } from '../factories';
@@ -9,7 +11,7 @@ import type {
9
11
 
10
12
  const globalThis: any = createGlobalThis();
11
13
 
12
- const log = Logger.child({
14
+ const log = logger.child({
13
15
  namespace: 'bootstrap',
14
16
  });
15
17
 
package/src/types.ts CHANGED
@@ -10,6 +10,9 @@ import type {
10
10
  import type {
11
11
  TLSSocket,
12
12
  } from 'tls';
13
+ import type {
14
+ Logger,
15
+ } from './Logger';
13
16
 
14
17
  export type ProxyConfigurationType = {
15
18
  authorization: string | null,
@@ -56,6 +59,7 @@ export type ProxyAgentConfigurationInputType = {
56
59
  forceGlobalAgent?: boolean,
57
60
  socketConnectionTimeout?: number,
58
61
  ca?: string[] | string,
62
+ logger?: Logger,
59
63
  };
60
64
 
61
65
  export type ProxyAgentConfigurationType = {
@@ -0,0 +1,77 @@
1
+ import {
2
+ expect,
3
+ test,
4
+ } from 'vitest';
5
+ import isUrlMatchingNoProxy from './isUrlMatchingNoProxy';
6
+
7
+ test('returns `true` if hosts match', () => {
8
+ expect(isUrlMatchingNoProxy('http://foo.com/', 'foo.com')).toBe(true);
9
+ });
10
+
11
+ test('returns `true` if hosts match (IP)', () => {
12
+ expect(isUrlMatchingNoProxy('http://127.0.0.1/', '127.0.0.1')).toBe(true);
13
+ });
14
+
15
+ test('returns `true` if hosts match (using asterisk wildcard)', () => {
16
+ expect(isUrlMatchingNoProxy('http://bar.foo.com/', '*.foo.com')).toBe(true);
17
+ });
18
+
19
+ test('returns `true` if domain matches (using dot wildcard)', () => {
20
+ expect(isUrlMatchingNoProxy('http://foo.com/', '.foo.com')).toBe(true);
21
+ });
22
+
23
+ test('returns `true` if subdomain matches (using dot wildcard)', () => {
24
+ expect(isUrlMatchingNoProxy('http://bar.foo.com/', '.foo.com')).toBe(true);
25
+ });
26
+
27
+ test('returns `true` if hosts match (*) and ports match', () => {
28
+ expect(isUrlMatchingNoProxy('http://foo.com:8080/', '*:8080')).toBe(true);
29
+ });
30
+
31
+ test('returns `true` if hosts and ports match', () => {
32
+ expect(isUrlMatchingNoProxy('http://foo.com:8080/', 'foo.com:8080')).toBe(true);
33
+ });
34
+
35
+ test('returns `true` if hosts match and NO_PROXY does not define port', () => {
36
+ expect(isUrlMatchingNoProxy('http://foo.com:8080/', 'foo.com')).toBe(true);
37
+ });
38
+
39
+ test('returns `true` if hosts (IP) and ports match', () => {
40
+ expect(isUrlMatchingNoProxy('http://127.0.0.1:8080/', '127.0.0.1:8080')).toBe(true);
41
+ });
42
+
43
+ test('returns `false` if hosts match and ports do not match (diffferent port)', () => {
44
+ expect(isUrlMatchingNoProxy('http://foo.com:8080/', 'foo.com:8000')).toBe(false);
45
+ });
46
+
47
+ test('returns `false` if hosts match and ports do not match (port not present subject)', () => {
48
+ expect(isUrlMatchingNoProxy('http://foo.com/', 'foo.com:8000')).toBe(false);
49
+ });
50
+
51
+ test('returns `true` if hosts match and ports do not match (port not present NO_PROXY)', () => {
52
+ expect(isUrlMatchingNoProxy('http://foo.com:8000/', 'foo.com')).toBe(true);
53
+ });
54
+
55
+ test('returns `true` if hosts match in one of multiple rules separated with a comma', () => {
56
+ expect(isUrlMatchingNoProxy('http://foo.com/', 'bar.org,foo.com,baz.io')).toBe(true);
57
+ });
58
+
59
+ test('returns `true` if hosts match in one of multiple rules separated with a comma and a space', () => {
60
+ expect(isUrlMatchingNoProxy('http://foo.com/', 'bar.org, foo.com, baz.io')).toBe(true);
61
+ });
62
+
63
+ test('returns `true` if hosts match in one of multiple rules separated with a space', () => {
64
+ expect(isUrlMatchingNoProxy('http://foo.com/', 'bar.org foo.com baz.io')).toBe(true);
65
+ });
66
+
67
+ test('handles trailing newline in NO_PROXY', () => {
68
+ expect(isUrlMatchingNoProxy('http://foo.com/', 'foo.com\n')).toBe(true);
69
+ });
70
+
71
+ test('handles trailing whitespace in NO_PROXY', () => {
72
+ expect(isUrlMatchingNoProxy('http://foo.com/', 'foo.com ')).toBe(true);
73
+ });
74
+
75
+ test('handles leading whitespace in NO_PROXY', () => {
76
+ expect(isUrlMatchingNoProxy('http://foo.com/', ' foo.com')).toBe(true);
77
+ });
@@ -6,7 +6,7 @@ import {
6
6
  export default (subjectUrl: string, noProxy: string) => {
7
7
  const subjectUrlTokens = new URL(subjectUrl);
8
8
 
9
- const rules = noProxy.split(/[\s,]+/);
9
+ const rules = noProxy.split(/[\s,]+/).filter(Boolean);
10
10
 
11
11
  for (const rule of rules) {
12
12
  const ruleMatch = rule
@@ -0,0 +1,35 @@
1
+ import {
2
+ expect,
3
+ test,
4
+ } from 'vitest';
5
+ import parseProxyUrl from './parseProxyUrl';
6
+
7
+ test('extracts hostname', () => {
8
+ expect(parseProxyUrl('http://0.0.0.0').hostname).toBe('0.0.0.0');
9
+ });
10
+
11
+ test('extracts port', () => {
12
+ expect(parseProxyUrl('http://0.0.0.0:3000').port).toBe(3_000);
13
+ });
14
+
15
+ test('extracts authorization', () => {
16
+ expect(parseProxyUrl('http://foo:bar@0.0.0.0').authorization).toBe('foo:bar');
17
+ });
18
+
19
+ test('throws an error if protocol is not "http:"', () => {
20
+ expect(() => {
21
+ parseProxyUrl('https://0.0.0.0:3000');
22
+ }).toThrow('Unsupported `GLOBAL_AGENT.HTTP_PROXY` configuration value: URL protocol must be "http:".');
23
+ });
24
+
25
+ test('throws an error if query is present', () => {
26
+ expect(() => {
27
+ parseProxyUrl('http://0.0.0.0:3000/?foo=bar');
28
+ }).toThrow('Unsupported `GLOBAL_AGENT.HTTP_PROXY` configuration value: URL must not have query.');
29
+ });
30
+
31
+ test('throws an error if hash is present', () => {
32
+ expect(() => {
33
+ parseProxyUrl('http://0.0.0.0:3000/#foo');
34
+ }).toThrow('Unsupported `GLOBAL_AGENT.HTTP_PROXY` configuration value: URL must not have hash.');
35
+ });
@@ -0,0 +1,11 @@
1
+ import {defineConfig} from 'vitest/config';
2
+
3
+ export default defineConfig({
4
+ test: {
5
+ include: ['src/**/*.test.ts'],
6
+ isolate: false,
7
+ sequence: {
8
+ concurrent: false,
9
+ },
10
+ },
11
+ });
package/.eslintignore DELETED
@@ -1 +0,0 @@
1
- /bootstrap.js
package/.eslintrc DELETED
@@ -1,27 +0,0 @@
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
- }
package/test/.eslintrc DELETED
@@ -1,10 +0,0 @@
1
- {
2
- "rules": {
3
- "ava/use-test": 0,
4
- "filenames/match-regex": 0,
5
- "flowtype/no-flow-fix-me-comments": 0,
6
- "flowtype/no-weak-types": 0,
7
- "id-length": 0,
8
- "node/no-unpublished-import": 0
9
- }
10
- }
@@ -1,37 +0,0 @@
1
- import test from 'ava';
2
- import createProxyController from '../../../src/factories/createProxyController';
3
-
4
- test('sets HTTP_PROXY', (t) => {
5
- const globalAgentGlobal = createProxyController();
6
-
7
- globalAgentGlobal.HTTP_PROXY = 'http://127.0.0.1';
8
-
9
- t.is(globalAgentGlobal.HTTP_PROXY, 'http://127.0.0.1');
10
- });
11
-
12
- test('sets HTTPS_PROXY', (t) => {
13
- const globalAgentGlobal = createProxyController();
14
-
15
- globalAgentGlobal.HTTPS_PROXY = 'http://127.0.0.1';
16
-
17
- t.is(globalAgentGlobal.HTTPS_PROXY, 'http://127.0.0.1');
18
- });
19
-
20
- test('sets NO_PROXY', (t) => {
21
- const globalAgentGlobal = createProxyController();
22
-
23
- globalAgentGlobal.NO_PROXY = '*';
24
-
25
- t.is(globalAgentGlobal.NO_PROXY, '*');
26
- });
27
-
28
- test('throws an error if unknown property is set', (t) => {
29
- const globalAgentGlobal = createProxyController();
30
-
31
- const error = t.throws(() => {
32
- // @ts-expect-error expected unknown property.
33
- globalAgentGlobal.FOO = 'BAR';
34
- });
35
-
36
- t.is(error.message, 'Cannot set an unmapped property "FOO".');
37
- });
@@ -1,62 +0,0 @@
1
- import test from 'ava';
2
- import isUrlMatchingNoProxy from '../../../src/utilities/isUrlMatchingNoProxy';
3
-
4
- test('returns `true` if hosts match', (t) => {
5
- t.assert(isUrlMatchingNoProxy('http://foo.com/', 'foo.com'));
6
- });
7
-
8
- test('returns `true` if hosts match (IP)', (t) => {
9
- t.assert(isUrlMatchingNoProxy('http://127.0.0.1/', '127.0.0.1'));
10
- });
11
-
12
- test('returns `true` if hosts match (using asterisk wildcard)', (t) => {
13
- t.assert(isUrlMatchingNoProxy('http://bar.foo.com/', '*.foo.com'));
14
- });
15
-
16
- test('returns `true` if domain matches (using dot wildcard)', (t) => {
17
- t.assert(isUrlMatchingNoProxy('http://foo.com/', '.foo.com'));
18
- });
19
-
20
- test('returns `true` if subdomain matches (using dot wildcard)', (t) => {
21
- t.assert(isUrlMatchingNoProxy('http://bar.foo.com/', '.foo.com'));
22
- });
23
-
24
- test('returns `true` if hosts match (*) and ports match', (t) => {
25
- t.assert(isUrlMatchingNoProxy('http://foo.com:8080/', '*:8080'));
26
- });
27
-
28
- test('returns `true` if hosts and ports match', (t) => {
29
- t.assert(isUrlMatchingNoProxy('http://foo.com:8080/', 'foo.com:8080'));
30
- });
31
-
32
- test('returns `true` if hosts match and NO_PROXY does not define port', (t) => {
33
- t.assert(isUrlMatchingNoProxy('http://foo.com:8080/', 'foo.com'));
34
- });
35
-
36
- test('returns `true` if hosts (IP) and ports match', (t) => {
37
- t.assert(isUrlMatchingNoProxy('http://127.0.0.1:8080/', '127.0.0.1:8080'));
38
- });
39
-
40
- test('returns `false` if hosts match and ports do not match (diffferent port)', (t) => {
41
- t.assert(isUrlMatchingNoProxy('http://foo.com:8080/', 'foo.com:8000') === false);
42
- });
43
-
44
- test('returns `false` if hosts match and ports do not match (port not present subject)', (t) => {
45
- t.assert(isUrlMatchingNoProxy('http://foo.com/', 'foo.com:8000') === false);
46
- });
47
-
48
- test('returns `true` if hosts match and ports do not match (port not present NO_PROXY)', (t) => {
49
- t.assert(isUrlMatchingNoProxy('http://foo.com:8000/', 'foo.com'));
50
- });
51
-
52
- test('returns `true` if hosts match in one of multiple rules separated with a comma', (t) => {
53
- t.assert(isUrlMatchingNoProxy('http://foo.com/', 'bar.org,foo.com,baz.io'));
54
- });
55
-
56
- test('returns `true` if hosts match in one of multiple rules separated with a comma and a space', (t) => {
57
- t.assert(isUrlMatchingNoProxy('http://foo.com/', 'bar.org, foo.com, baz.io'));
58
- });
59
-
60
- test('returns `true` if hosts match in one of multiple rules separated with a space', (t) => {
61
- t.assert(isUrlMatchingNoProxy('http://foo.com/', 'bar.org foo.com baz.io'));
62
- });
@@ -1,38 +0,0 @@
1
- import test from 'ava';
2
- import parseProxyUrl from '../../../src/utilities/parseProxyUrl';
3
-
4
- test('extracts hostname', (t) => {
5
- t.is(parseProxyUrl('http://0.0.0.0').hostname, '0.0.0.0');
6
- });
7
-
8
- test('extracts port', (t) => {
9
- t.is(parseProxyUrl('http://0.0.0.0:3000').port, 3_000);
10
- });
11
-
12
- test('extracts authorization', (t) => {
13
- t.is(parseProxyUrl('http://foo:bar@0.0.0.0').authorization, 'foo:bar');
14
- });
15
-
16
- test('throws an error if protocol is not "http:"', (t) => {
17
- const error = t.throws(() => {
18
- parseProxyUrl('https://0.0.0.0:3000');
19
- });
20
-
21
- t.is(error.message, 'Unsupported `GLOBAL_AGENT.HTTP_PROXY` configuration value: URL protocol must be "http:".');
22
- });
23
-
24
- test('throws an error if query is present', (t) => {
25
- const error = t.throws(() => {
26
- parseProxyUrl('http://0.0.0.0:3000/?foo=bar');
27
- });
28
-
29
- t.is(error.message, 'Unsupported `GLOBAL_AGENT.HTTP_PROXY` configuration value: URL must not have query.');
30
- });
31
-
32
- test('throws an error if hash is present', (t) => {
33
- const error = t.throws(() => {
34
- parseProxyUrl('http://0.0.0.0:3000/#foo');
35
- });
36
-
37
- t.is(error.message, 'Unsupported `GLOBAL_AGENT.HTTP_PROXY` configuration value: URL must not have hash.');
38
- });