hmpo-model 5.0.0 → 6.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.
- package/.github/workflows/ci.yaml +3 -3
- package/.husky/pre-push +1 -0
- package/eslint.config.js +53 -0
- package/lib/remote-model.js +10 -20
- package/package.json +22 -18
- package/test/lib/spec.local-model.js +1 -0
- package/test/lib/spec.remote-model.js +38 -31
- package/test/spec.index.js +1 -0
- package/.eslintignore +0 -1
- package/.eslintrc +0 -25
- package/test/.eslintrc +0 -9
|
@@ -13,12 +13,12 @@ jobs:
|
|
|
13
13
|
|
|
14
14
|
strategy:
|
|
15
15
|
matrix:
|
|
16
|
-
node-version: [
|
|
16
|
+
node-version: [20.x, 22.x]
|
|
17
17
|
|
|
18
18
|
steps:
|
|
19
|
-
- uses: actions/checkout@
|
|
19
|
+
- uses: actions/checkout@v4
|
|
20
20
|
- name: Use Node.js ${{ matrix.node-version }}
|
|
21
|
-
uses: actions/setup-node@
|
|
21
|
+
uses: actions/setup-node@v4
|
|
22
22
|
with:
|
|
23
23
|
node-version: ${{ matrix.node-version }}
|
|
24
24
|
- name: Install dependencies
|
package/.husky/pre-push
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
npm test
|
package/eslint.config.js
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
const js = require('@eslint/js');
|
|
2
|
+
const globals = require('globals');
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
const styleRules = {
|
|
6
|
+
quotes: ['error', 'single', { avoidEscape: true }],
|
|
7
|
+
'no-trailing-spaces': 'error',
|
|
8
|
+
indent: 'error',
|
|
9
|
+
'linebreak-style': ['error', 'unix'],
|
|
10
|
+
semi: ['error', 'always'],
|
|
11
|
+
'brace-style': ['error', '1tbs', { allowSingleLine: true }],
|
|
12
|
+
'keyword-spacing': 'error',
|
|
13
|
+
'space-before-blocks': 'error',
|
|
14
|
+
'space-before-function-paren': [
|
|
15
|
+
'error',
|
|
16
|
+
{ anonymous: 'always', named: 'never' },
|
|
17
|
+
],
|
|
18
|
+
'no-mixed-spaces-and-tabs': 'error',
|
|
19
|
+
'comma-spacing': ['error', { before: false, after: true }],
|
|
20
|
+
'key-spacing': ['error', { beforeColon: false, afterColon: true }],
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
module.exports = [
|
|
25
|
+
js.configs.recommended,
|
|
26
|
+
{
|
|
27
|
+
languageOptions: {
|
|
28
|
+
ecmaVersion: 2022,
|
|
29
|
+
globals: {
|
|
30
|
+
...globals.node,
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
rules: {
|
|
34
|
+
'no-unused-vars': [
|
|
35
|
+
'error',
|
|
36
|
+
{ argsIgnorePattern: '^(err|req|res|next)$' },
|
|
37
|
+
],
|
|
38
|
+
'one-var': ['error', { initialized: 'never' }],
|
|
39
|
+
'no-var': 'error',
|
|
40
|
+
...styleRules,
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
// Unit tests
|
|
44
|
+
{
|
|
45
|
+
files: ['test/**'],
|
|
46
|
+
languageOptions: {
|
|
47
|
+
globals: {
|
|
48
|
+
...globals.mocha,
|
|
49
|
+
sinon: 'readonly',
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
];
|
package/lib/remote-model.js
CHANGED
|
@@ -6,7 +6,6 @@ const got = require('got');
|
|
|
6
6
|
const kebabCase = require('lodash.kebabcase');
|
|
7
7
|
const { URL } = require('url');
|
|
8
8
|
const ModelError = require('./model-error');
|
|
9
|
-
|
|
10
9
|
const DEFAULT_TIMEOUT = 60000;
|
|
11
10
|
|
|
12
11
|
const consoleLogger = { outbound: console.log, trimHtml: html => html };
|
|
@@ -22,7 +21,7 @@ class RemoteModel extends LocalModel {
|
|
|
22
21
|
setLogger() {
|
|
23
22
|
try {
|
|
24
23
|
this.logger = require('hmpo-logger');
|
|
25
|
-
} catch
|
|
24
|
+
} catch {
|
|
26
25
|
/* istanbul ignore next */
|
|
27
26
|
console.warn('Warning: ' + this.options.label + ': Unable to find hmpo-logger for logging, using console instead!');
|
|
28
27
|
}
|
|
@@ -131,31 +130,22 @@ class RemoteModel extends LocalModel {
|
|
|
131
130
|
|
|
132
131
|
const proxyUrl = new URL(proxy.uri);
|
|
133
132
|
|
|
134
|
-
const
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
const getPath = u => u.pathname + u.search + u.hash;
|
|
139
|
-
|
|
140
|
-
const options = Object.assign({
|
|
141
|
-
host: proxyUrl.hostname,
|
|
142
|
-
port: proxyUrl.port,
|
|
143
|
-
protocol: proxyUrl.protocol,
|
|
144
|
-
path: getPath(proxyUrl),
|
|
145
|
-
auth: getAuth(proxyUrl),
|
|
133
|
+
const options = {
|
|
134
|
+
headers: this.options.headers || {},
|
|
135
|
+
keepAlive: false,
|
|
146
136
|
maxSockets: 1,
|
|
147
|
-
|
|
148
|
-
}
|
|
137
|
+
...proxy
|
|
138
|
+
};
|
|
149
139
|
|
|
150
140
|
const isHttps = (new URL(url).protocol === 'https:');
|
|
151
141
|
|
|
152
142
|
if (isHttps) {
|
|
153
|
-
const HttpsProxyAgent = require('https-proxy-agent');
|
|
154
|
-
const agent = new HttpsProxyAgent(options);
|
|
143
|
+
const { HttpsProxyAgent } = require('https-proxy-agent');
|
|
144
|
+
const agent = new HttpsProxyAgent(proxyUrl, options);
|
|
155
145
|
return { https: agent };
|
|
156
146
|
} else {
|
|
157
|
-
const HttpProxyAgent = require('http-proxy-agent');
|
|
158
|
-
const agent = new HttpProxyAgent(options);
|
|
147
|
+
const { HttpProxyAgent } = require('http-proxy-agent');
|
|
148
|
+
const agent = new HttpProxyAgent(proxyUrl, options);
|
|
159
149
|
return { http: agent };
|
|
160
150
|
}
|
|
161
151
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "hmpo-model",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "6.0.0",
|
|
4
4
|
"description": "Simple model for interacting with http/rest apis.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -9,43 +9,47 @@
|
|
|
9
9
|
"posttest": "npm run check-coverage && npm audit --production",
|
|
10
10
|
"lint": "eslint .",
|
|
11
11
|
"unit": "nyc --reporter=lcov --reporter=text-summary _mocha test/ --recursive --require test/helper",
|
|
12
|
-
"check-coverage": "nyc check-coverage"
|
|
12
|
+
"check-coverage": "nyc check-coverage",
|
|
13
|
+
"prepare": "husky"
|
|
13
14
|
},
|
|
14
15
|
"repository": {
|
|
15
16
|
"type": "git",
|
|
16
|
-
"url": "https://github.com/
|
|
17
|
+
"url": "https://github.com/HMPO/hmpo-model.git"
|
|
17
18
|
},
|
|
18
19
|
"author": "PEX",
|
|
19
20
|
"license": "MIT",
|
|
20
21
|
"engines": {
|
|
21
|
-
"node": "
|
|
22
|
+
"node": "20.x || 22.x"
|
|
22
23
|
},
|
|
23
24
|
"bugs": {
|
|
24
|
-
"url": "https://github.com/
|
|
25
|
+
"url": "https://github.com/HMPO/hmpo-model/issues"
|
|
25
26
|
},
|
|
26
|
-
"homepage": "https://github.com/
|
|
27
|
+
"homepage": "https://github.com/HMPO/hmpo-model#readme",
|
|
27
28
|
"dependencies": {
|
|
28
|
-
"debug": "^4.3.
|
|
29
|
+
"debug": "^4.3.7",
|
|
29
30
|
"got": "<12",
|
|
30
|
-
"http-proxy-agent": "^
|
|
31
|
-
"https-proxy-agent": "^
|
|
31
|
+
"http-proxy-agent": "^7.0.2",
|
|
32
|
+
"https-proxy-agent": "^7.0.5",
|
|
32
33
|
"lodash.kebabcase": "^4.1.1"
|
|
33
34
|
},
|
|
34
35
|
"devDependencies": {
|
|
35
|
-
"chai": "^4.
|
|
36
|
-
"eslint": "^
|
|
37
|
-
"hmpo-logger": "
|
|
38
|
-
"mocha": "^10.
|
|
39
|
-
"nyc": "^
|
|
40
|
-
"proxyquire": "^2.
|
|
41
|
-
"sinon": "^
|
|
42
|
-
"sinon-chai": "^3.7.0"
|
|
36
|
+
"chai": "^4.5.0",
|
|
37
|
+
"eslint": "^9.12.0",
|
|
38
|
+
"hmpo-logger": "git+https://github.com/HMPO/hmpo-logger.git#DD-272-update-dependencies",
|
|
39
|
+
"mocha": "^10.7.3",
|
|
40
|
+
"nyc": "^17.1.0",
|
|
41
|
+
"proxyquire": "^2.1.3",
|
|
42
|
+
"sinon": "^19.0.2",
|
|
43
|
+
"sinon-chai": "^3.7.0",
|
|
44
|
+
"husky": "^9.1.6",
|
|
45
|
+
"globals": "^15.9.0"
|
|
43
46
|
},
|
|
44
47
|
"nyc": {
|
|
45
48
|
"all": true,
|
|
46
49
|
"exclude": [
|
|
47
50
|
"coverage/**",
|
|
48
|
-
"test/**"
|
|
51
|
+
"test/**",
|
|
52
|
+
"eslint.config.js"
|
|
49
53
|
],
|
|
50
54
|
"lines": 100,
|
|
51
55
|
"branches": 100,
|
|
@@ -4,9 +4,10 @@ const Model = require('../../lib/remote-model');
|
|
|
4
4
|
const ModelError = require('../../lib/model-error');
|
|
5
5
|
const BaseModel = require('../../lib/local-model');
|
|
6
6
|
const logger = require('hmpo-logger');
|
|
7
|
+
const { expect } = require('chai');
|
|
7
8
|
|
|
8
|
-
const
|
|
9
|
-
const
|
|
9
|
+
const { HttpProxyAgent } = require('http-proxy-agent');
|
|
10
|
+
const { HttpsProxyAgent } = require('https-proxy-agent');
|
|
10
11
|
|
|
11
12
|
describe('Remote Model', () => {
|
|
12
13
|
let model, cb, mocks;
|
|
@@ -400,16 +401,12 @@ describe('Remote Model', () => {
|
|
|
400
401
|
|
|
401
402
|
it('should set up http proxy if specified', () => {
|
|
402
403
|
const returnedConfig = model.requestConfig({
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
404
|
+
method: 'VERB',
|
|
405
|
+
url: 'http://example.net',
|
|
406
|
+
proxy: 'http://proxy.example.com:8000'
|
|
406
407
|
});
|
|
407
408
|
|
|
408
|
-
|
|
409
|
-
agent: {
|
|
410
|
-
http: sinon.match.instanceOf(HttpProxyAgent)
|
|
411
|
-
}
|
|
412
|
-
});
|
|
409
|
+
expect(returnedConfig.agent.http).to.be.an.instanceOf(HttpProxyAgent);
|
|
413
410
|
});
|
|
414
411
|
|
|
415
412
|
it('should set up https proxy if specified', () => {
|
|
@@ -428,46 +425,56 @@ describe('Remote Model', () => {
|
|
|
428
425
|
|
|
429
426
|
it('should pass proxy options to the new proxy', () => {
|
|
430
427
|
const returnedConfig = model.requestConfig({
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
428
|
+
method: 'VERB',
|
|
429
|
+
url: 'http://example.net',
|
|
430
|
+
proxy: {
|
|
434
431
|
uri: 'http://proxy.example.com:8000',
|
|
435
432
|
keepAlive: true,
|
|
436
433
|
maxSockets: 200
|
|
437
434
|
}
|
|
438
435
|
});
|
|
439
436
|
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
keepAlive: true,
|
|
445
|
-
maxSockets: 200
|
|
446
|
-
}
|
|
447
|
-
}
|
|
448
|
-
}
|
|
449
|
-
});
|
|
437
|
+
const agent = returnedConfig.agent.http;
|
|
438
|
+
expect(agent).to.be.instanceOf(require('http').Agent);
|
|
439
|
+
expect(agent.keepAlive).to.equal(true);
|
|
440
|
+
expect(agent.maxSockets).to.equal(200);
|
|
450
441
|
});
|
|
451
442
|
|
|
443
|
+
|
|
452
444
|
it('should process auth for the proxy', () => {
|
|
453
445
|
let agent;
|
|
454
446
|
|
|
455
447
|
agent = model.proxy('http://username:password@host:123/path', 'https://example.com');
|
|
456
448
|
sinon.assert.match(agent.https.proxy, {
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
449
|
+
href: 'http://username:password@host:123/path',
|
|
450
|
+
origin: 'http://host:123',
|
|
451
|
+
protocol: 'http:',
|
|
452
|
+
username: 'username',
|
|
453
|
+
password: 'password',
|
|
454
|
+
host: 'host:123',
|
|
455
|
+
hostname: 'host',
|
|
456
|
+
port: '123',
|
|
457
|
+
pathname: '/path',
|
|
458
|
+
search: '',
|
|
459
|
+
hash: ''
|
|
461
460
|
});
|
|
462
461
|
|
|
463
462
|
agent = model.proxy('http://username@host:123/path', 'https://example.com');
|
|
464
463
|
sinon.assert.match(agent.https.proxy, {
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
464
|
+
href: 'http://username@host:123/path',
|
|
465
|
+
origin: 'http://host:123',
|
|
466
|
+
protocol: 'http:',
|
|
467
|
+
username: 'username',
|
|
468
|
+
password: '',
|
|
469
|
+
host: 'host:123',
|
|
470
|
+
hostname: 'host',
|
|
471
|
+
port: '123',
|
|
472
|
+
pathname: '/path',
|
|
473
|
+
search: '',
|
|
474
|
+
hash: ''
|
|
469
475
|
});
|
|
470
476
|
});
|
|
477
|
+
|
|
471
478
|
});
|
|
472
479
|
|
|
473
480
|
describe('with headers supplied into the constructor', () => {
|
package/test/spec.index.js
CHANGED
package/.eslintignore
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
/coverage/**
|
package/.eslintrc
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"env": {
|
|
3
|
-
"node": true,
|
|
4
|
-
"es6": true
|
|
5
|
-
},
|
|
6
|
-
"extends": "eslint:recommended",
|
|
7
|
-
"rules": {
|
|
8
|
-
"no-unused-vars": ["error", { "argsIgnorePattern": "^(err|req|res|next)$" }],
|
|
9
|
-
"no-mixed-requires": ["error", { "allowCall": true }],
|
|
10
|
-
"quotes": ["error", "single"],
|
|
11
|
-
"no-trailing-spaces": "error",
|
|
12
|
-
"indent": "error",
|
|
13
|
-
"linebreak-style": ["error", "unix"],
|
|
14
|
-
"semi": ["error", "always"],
|
|
15
|
-
"brace-style": ["error", "1tbs", { "allowSingleLine": true }],
|
|
16
|
-
"keyword-spacing": "error",
|
|
17
|
-
"space-before-blocks": "error",
|
|
18
|
-
"space-before-function-paren": ["error", { "anonymous": "always", "named": "never" }],
|
|
19
|
-
"no-mixed-spaces-and-tabs": "error",
|
|
20
|
-
"comma-spacing": ["error", {"before": false, "after": true}],
|
|
21
|
-
"key-spacing": ["error", {"beforeColon": false, "afterColon": true}],
|
|
22
|
-
"one-var": ["off", { "initialized": "never" }],
|
|
23
|
-
"no-var": "error"
|
|
24
|
-
}
|
|
25
|
-
}
|