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.
@@ -13,12 +13,12 @@ jobs:
13
13
 
14
14
  strategy:
15
15
  matrix:
16
- node-version: [14.x, 16.x, 18.x, 20.x]
16
+ node-version: [20.x, 22.x]
17
17
 
18
18
  steps:
19
- - uses: actions/checkout@v2
19
+ - uses: actions/checkout@v4
20
20
  - name: Use Node.js ${{ matrix.node-version }}
21
- uses: actions/setup-node@v2
21
+ uses: actions/setup-node@v4
22
22
  with:
23
23
  node-version: ${{ matrix.node-version }}
24
24
  - name: Install dependencies
@@ -0,0 +1 @@
1
+ npm test
@@ -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
+ ];
@@ -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 (e) {
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 getAuth = u =>
135
- u.username && u.password ? decodeURIComponent(`${u.username}:${u.password}`) :
136
- u.username ? decodeURIComponent(u.username) : null;
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
- keepAlive: false
148
- }, proxy);
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": "5.0.0",
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/UKHomeOffice/passports-model.git"
17
+ "url": "https://github.com/HMPO/hmpo-model.git"
17
18
  },
18
19
  "author": "PEX",
19
20
  "license": "MIT",
20
21
  "engines": {
21
- "node": ">=14"
22
+ "node": "20.x || 22.x"
22
23
  },
23
24
  "bugs": {
24
- "url": "https://github.com/UKHomeOffice/passports-model/issues"
25
+ "url": "https://github.com/HMPO/hmpo-model/issues"
25
26
  },
26
- "homepage": "https://github.com/UKHomeOffice/passports-model",
27
+ "homepage": "https://github.com/HMPO/hmpo-model#readme",
27
28
  "dependencies": {
28
- "debug": "^4.3.4",
29
+ "debug": "^4.3.7",
29
30
  "got": "<12",
30
- "http-proxy-agent": "^5.0.0",
31
- "https-proxy-agent": "^5.0.1",
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.3.6",
36
- "eslint": "^8.18.0",
37
- "hmpo-logger": "^7.0.0",
38
- "mocha": "^10.0.0",
39
- "nyc": "^15.1.0",
40
- "proxyquire": "^2.0.0",
41
- "sinon": "^15.0.4",
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,
@@ -1,6 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  const Model = require('../../lib/local-model');
4
+ const { expect } = require('chai');
4
5
 
5
6
  describe('Local Model', () => {
6
7
  let model;
@@ -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 HttpsProxyAgent = require('https-proxy-agent');
9
- const HttpProxyAgent = require('http-proxy-agent');
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
- 'method': 'VERB',
404
- 'url': 'http://example.net',
405
- 'proxy': 'http://proxy.example.com:8000'
404
+ method: 'VERB',
405
+ url: 'http://example.net',
406
+ proxy: 'http://proxy.example.com:8000'
406
407
  });
407
408
 
408
- sinon.assert.match(returnedConfig, {
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
- 'method': 'VERB',
432
- 'url': 'http://example.net',
433
- 'proxy': {
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
- sinon.assert.match(returnedConfig, {
441
- agent: {
442
- http: {
443
- proxy: {
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
- auth: 'username:password',
458
- host: 'host',
459
- port: 123,
460
- protocol: 'http:'
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
- auth: 'username',
466
- host: 'host',
467
- port: 123,
468
- protocol: 'http:'
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', () => {
@@ -1,4 +1,5 @@
1
1
  'use strict';
2
+ const { expect } = require('chai');
2
3
 
3
4
  describe('hmpo-model', () => {
4
5
 
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
- }
package/test/.eslintrc DELETED
@@ -1,9 +0,0 @@
1
- {
2
- "env": {
3
- "mocha": true
4
- },
5
- "globals": {
6
- "sinon": true,
7
- "expect": true
8
- }
9
- }