hmpo-model 4.0.2 → 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/.github/workflows/ci.yaml +27 -0
- package/lib/remote-model.js +25 -17
- package/package.json +8 -7
- package/test/helper.js +2 -0
- package/test/lib/spec.remote-model.js +30 -6
- package/.circleci/config.yml +0 -21
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
name: Node.js CI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [ master ]
|
|
6
|
+
pull_request:
|
|
7
|
+
branches: [ master ]
|
|
8
|
+
|
|
9
|
+
jobs:
|
|
10
|
+
build:
|
|
11
|
+
|
|
12
|
+
runs-on: ubuntu-latest
|
|
13
|
+
|
|
14
|
+
strategy:
|
|
15
|
+
matrix:
|
|
16
|
+
node-version: [12.x, 14.x, 15.x]
|
|
17
|
+
|
|
18
|
+
steps:
|
|
19
|
+
- uses: actions/checkout@v2
|
|
20
|
+
- name: Use Node.js ${{ matrix.node-version }}
|
|
21
|
+
uses: actions/setup-node@v2
|
|
22
|
+
with:
|
|
23
|
+
node-version: ${{ matrix.node-version }}
|
|
24
|
+
- name: Install dependencies
|
|
25
|
+
run: npm ci
|
|
26
|
+
- name: Run tests
|
|
27
|
+
run: npm test
|
package/lib/remote-model.js
CHANGED
|
@@ -122,28 +122,36 @@ class RemoteModel extends LocalModel {
|
|
|
122
122
|
proxy(proxy = this.options.proxy, url) {
|
|
123
123
|
if (!proxy || !url) return;
|
|
124
124
|
|
|
125
|
-
if (typeof proxy === 'string') proxy = { proxy };
|
|
125
|
+
if (typeof proxy === 'string') proxy = { uri: proxy };
|
|
126
|
+
|
|
127
|
+
const proxyUrl = new URL(proxy.uri);
|
|
128
|
+
|
|
129
|
+
const getAuth = u =>
|
|
130
|
+
u.username && u.password ? decodeURIComponent(`${u.username}:${u.password}`) :
|
|
131
|
+
u.username ? decodeURIComponent(u.username) : null;
|
|
132
|
+
|
|
133
|
+
const getPath = u => u.pathname + u.search + u.hash;
|
|
134
|
+
|
|
135
|
+
const options = Object.assign({
|
|
136
|
+
host: proxyUrl.hostname,
|
|
137
|
+
port: proxyUrl.port,
|
|
138
|
+
protocol: proxyUrl.protocol,
|
|
139
|
+
path: getPath(proxyUrl),
|
|
140
|
+
auth: getAuth(proxyUrl),
|
|
141
|
+
maxSockets: 1,
|
|
142
|
+
keepAlive: false
|
|
143
|
+
}, proxy);
|
|
126
144
|
|
|
127
145
|
const isHttps = (new URL(url).protocol === 'https:');
|
|
128
146
|
|
|
129
147
|
if (isHttps) {
|
|
130
|
-
const
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
keepAlive: false,
|
|
134
|
-
maxSockets: 1,
|
|
135
|
-
maxFreeSockets: 1,
|
|
136
|
-
}, proxy))
|
|
137
|
-
};
|
|
148
|
+
const HttpsProxyAgent = require('https-proxy-agent');
|
|
149
|
+
const agent = new HttpsProxyAgent(options);
|
|
150
|
+
return { https: agent };
|
|
138
151
|
} else {
|
|
139
|
-
const
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
keepAlive: false,
|
|
143
|
-
maxSockets: 1,
|
|
144
|
-
maxFreeSockets: 1,
|
|
145
|
-
}, proxy))
|
|
146
|
-
};
|
|
152
|
+
const HttpProxyAgent = require('http-proxy-agent');
|
|
153
|
+
const agent = new HttpProxyAgent(options);
|
|
154
|
+
return { http: agent };
|
|
147
155
|
}
|
|
148
156
|
}
|
|
149
157
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "hmpo-model",
|
|
3
|
-
"version": "4.0
|
|
3
|
+
"version": "4.1.0",
|
|
4
4
|
"description": "Simple model for interacting with http/rest apis.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -27,17 +27,18 @@
|
|
|
27
27
|
"dependencies": {
|
|
28
28
|
"debug": "^4.3.3",
|
|
29
29
|
"got": "^11.8.3",
|
|
30
|
-
"
|
|
30
|
+
"http-proxy-agent": "^5.0.0",
|
|
31
|
+
"https-proxy-agent": "^5.0.0",
|
|
31
32
|
"lodash.kebabcase": "^4.1.1"
|
|
32
33
|
},
|
|
33
34
|
"devDependencies": {
|
|
34
|
-
"chai": "^4.3.
|
|
35
|
-
"eslint": "^8.
|
|
36
|
-
"hmpo-logger": "^4.1.
|
|
37
|
-
"mocha": "^9.1
|
|
35
|
+
"chai": "^4.3.6",
|
|
36
|
+
"eslint": "^8.10.0",
|
|
37
|
+
"hmpo-logger": "^4.1.5",
|
|
38
|
+
"mocha": "^9.2.1",
|
|
38
39
|
"nyc": "^15.1.0",
|
|
39
40
|
"proxyquire": "^2.0.0",
|
|
40
|
-
"sinon": "^
|
|
41
|
+
"sinon": "^13.0.1",
|
|
41
42
|
"sinon-chai": "^3.7.0"
|
|
42
43
|
},
|
|
43
44
|
"nyc": {
|
package/test/helper.js
CHANGED
|
@@ -5,7 +5,8 @@ const ModelError = require('../../lib/model-error');
|
|
|
5
5
|
const BaseModel = require('../../lib/local-model');
|
|
6
6
|
const logger = require('hmpo-logger');
|
|
7
7
|
|
|
8
|
-
const
|
|
8
|
+
const HttpsProxyAgent = require('https-proxy-agent');
|
|
9
|
+
const HttpProxyAgent = require('http-proxy-agent');
|
|
9
10
|
|
|
10
11
|
describe('Remote Model', () => {
|
|
11
12
|
let model, cb, mocks;
|
|
@@ -71,7 +72,7 @@ describe('Remote Model', () => {
|
|
|
71
72
|
});
|
|
72
73
|
|
|
73
74
|
it('should use console log and a trimHtml pass-through if hmpo-logger is not available', () => {
|
|
74
|
-
logger.get.throws(
|
|
75
|
+
logger.get.throws({ message: 'test error' });
|
|
75
76
|
|
|
76
77
|
model = new Model();
|
|
77
78
|
|
|
@@ -431,19 +432,43 @@ describe('Remote Model', () => {
|
|
|
431
432
|
'method': 'VERB',
|
|
432
433
|
'url': 'http://example.net',
|
|
433
434
|
'proxy': {
|
|
434
|
-
|
|
435
|
-
keepAlive: true
|
|
435
|
+
uri: 'http://proxy.example.com:8000',
|
|
436
|
+
keepAlive: true,
|
|
437
|
+
maxSockets: 200
|
|
436
438
|
}
|
|
437
439
|
});
|
|
438
440
|
|
|
439
441
|
sinon.assert.match(returnedConfig, {
|
|
440
442
|
agent: {
|
|
441
443
|
http: {
|
|
442
|
-
|
|
444
|
+
proxy: {
|
|
445
|
+
keepAlive: true,
|
|
446
|
+
maxSockets: 200
|
|
447
|
+
}
|
|
443
448
|
}
|
|
444
449
|
}
|
|
445
450
|
});
|
|
446
451
|
});
|
|
452
|
+
|
|
453
|
+
it('should process auth for the proxy', () => {
|
|
454
|
+
let agent;
|
|
455
|
+
|
|
456
|
+
agent = model.proxy('http://username:password@host:123/path', 'https://example.com');
|
|
457
|
+
sinon.assert.match(agent.https.proxy, {
|
|
458
|
+
auth: 'username:password',
|
|
459
|
+
host: 'host',
|
|
460
|
+
port: 123,
|
|
461
|
+
protocol: 'http:'
|
|
462
|
+
});
|
|
463
|
+
|
|
464
|
+
agent = model.proxy('http://username@host:123/path', 'https://example.com');
|
|
465
|
+
sinon.assert.match(agent.https.proxy, {
|
|
466
|
+
auth: 'username',
|
|
467
|
+
host: 'host',
|
|
468
|
+
port: 123,
|
|
469
|
+
protocol: 'http:'
|
|
470
|
+
});
|
|
471
|
+
});
|
|
447
472
|
});
|
|
448
473
|
|
|
449
474
|
describe('with headers supplied into the constructor', () => {
|
|
@@ -742,7 +767,6 @@ describe('Remote Model', () => {
|
|
|
742
767
|
};
|
|
743
768
|
|
|
744
769
|
model.request(settings, cb);
|
|
745
|
-
console.log(model.logError.args[0][0]);
|
|
746
770
|
model.logError.should.have.been.calledWithExactly({
|
|
747
771
|
settings: settings,
|
|
748
772
|
statusCode: 404,
|
package/.circleci/config.yml
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
# This config is equivalent to both the '.circleci/extended/orb-free.yml' and the base '.circleci/config.yml'
|
|
2
|
-
version: 2.1
|
|
3
|
-
|
|
4
|
-
# Orbs are reusable packages of CircleCI configuration that you may share across projects, enabling you to create encapsulated, parameterized commands, jobs, and executors that can be used across multiple projects.
|
|
5
|
-
# See: https://circleci.com/docs/2.0/orb-intro/
|
|
6
|
-
orbs:
|
|
7
|
-
node: circleci/node@4.7
|
|
8
|
-
|
|
9
|
-
# Invoke jobs via workflows
|
|
10
|
-
# See: https://circleci.com/docs/2.0/configuration-reference/#workflows
|
|
11
|
-
workflows:
|
|
12
|
-
sample: # This is the name of the workflow, feel free to change it to better match your workflow.
|
|
13
|
-
# Inside the workflow, you define the jobs you want to run.
|
|
14
|
-
jobs:
|
|
15
|
-
- node/test:
|
|
16
|
-
# This is the node version to use for the `cimg/node` tag
|
|
17
|
-
# Relevant tags can be found on the CircleCI Developer Hub
|
|
18
|
-
# https://circleci.com/developer/images/image/cimg/node
|
|
19
|
-
version: '16.10'
|
|
20
|
-
# If you are using yarn, change the line below from "npm" to "yarn"
|
|
21
|
-
pkg-manager: npm
|