hmpo-model 4.1.0 → 4.3.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,7 +13,7 @@ jobs:
13
13
 
14
14
  strategy:
15
15
  matrix:
16
- node-version: [12.x, 14.x, 15.x]
16
+ node-version: [12.x, 14.x, 16.x, 18.x]
17
17
 
18
18
  steps:
19
19
  - uses: actions/checkout@v2
@@ -9,6 +9,8 @@ const ModelError = require('./model-error');
9
9
 
10
10
  const DEFAULT_TIMEOUT = 60000;
11
11
 
12
+ const consoleLogger = { outbound: console.log, trimHtml: html => html };
13
+
12
14
  class RemoteModel extends LocalModel {
13
15
  constructor(attributes, options) {
14
16
  super(attributes, options);
@@ -19,14 +21,17 @@ class RemoteModel extends LocalModel {
19
21
 
20
22
  setLogger() {
21
23
  try {
22
- const hmpoLogger = require('hmpo-logger');
23
- this.logger = hmpoLogger.get(':' + this.options.label);
24
+ this.logger = require('hmpo-logger');
24
25
  } catch (e) {
25
- console.error('Error setting logger, using console instead!', e);
26
- this.logger = { outbound: console.log, trimHtml: html => html };
26
+ /* istanbul ignore next */
27
+ console.warn('Warning: ' + this.options.label + ': Unable to find hmpo-logger for logging, using console instead!');
27
28
  }
28
29
  }
29
30
 
31
+ getLogger() {
32
+ return this.logger ? this.logger.get(':' + this.options.label) : consoleLogger;
33
+ }
34
+
30
35
  fetch(args, callback) {
31
36
  if (typeof args === 'function') {
32
37
  callback = args;
@@ -264,7 +269,7 @@ class RemoteModel extends LocalModel {
264
269
  if (outError) data.outError = outError;
265
270
 
266
271
  if (tokenData.err) {
267
- data.outErrorBody = this.logger.trimHtml(tokenData.err.body);
272
+ data.outErrorBody = this.getLogger().trimHtml(tokenData.err.body);
268
273
  }
269
274
 
270
275
  Object.assign(data, this.options.logging);
@@ -274,15 +279,15 @@ class RemoteModel extends LocalModel {
274
279
 
275
280
 
276
281
  logSync() {
277
- this.logger.outbound('Model request sent :outVerb :outRequest', this.logMeta.apply(this, arguments));
282
+ this.getLogger().outbound('Model request sent :outVerb :outRequest', this.logMeta.apply(this, arguments));
278
283
  }
279
284
 
280
285
  logSuccess() {
281
- this.logger.outbound('Model request success :outVerb :outRequest :outResponseCode', this.logMeta.apply(this, arguments));
286
+ this.getLogger().outbound('Model request success :outVerb :outRequest :outResponseCode', this.logMeta.apply(this, arguments));
282
287
  }
283
288
 
284
289
  logError() {
285
- this.logger.outbound('Model request failed :outVerb :outRequest :outResponseCode :outError', this.logMeta.apply(this, arguments));
290
+ this.getLogger().outbound('Model request failed :outVerb :outRequest :outResponseCode :outError', this.logMeta.apply(this, arguments));
286
291
  }
287
292
 
288
293
  hookSync() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hmpo-model",
3
- "version": "4.1.0",
3
+ "version": "4.3.0",
4
4
  "description": "Simple model for interacting with http/rest apis.",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -25,20 +25,20 @@
25
25
  },
26
26
  "homepage": "https://github.com/UKHomeOffice/passports-model",
27
27
  "dependencies": {
28
- "debug": "^4.3.3",
29
- "got": "^11.8.3",
28
+ "debug": "^4.3.4",
29
+ "got": "<12",
30
30
  "http-proxy-agent": "^5.0.0",
31
- "https-proxy-agent": "^5.0.0",
31
+ "https-proxy-agent": "^5.0.1",
32
32
  "lodash.kebabcase": "^4.1.1"
33
33
  },
34
34
  "devDependencies": {
35
35
  "chai": "^4.3.6",
36
- "eslint": "^8.10.0",
37
- "hmpo-logger": "^4.1.5",
38
- "mocha": "^9.2.1",
36
+ "eslint": "^8.18.0",
37
+ "hmpo-logger": "^6.1.0",
38
+ "mocha": "^10.0.0",
39
39
  "nyc": "^15.1.0",
40
40
  "proxyquire": "^2.0.0",
41
- "sinon": "^13.0.1",
41
+ "sinon": "^14.0.0",
42
42
  "sinon-chai": "^3.7.0"
43
43
  },
44
44
  "nyc": {
@@ -67,19 +67,18 @@ describe('Remote Model', () => {
67
67
  it('should set up a new hmpo-logger', () => {
68
68
  model = new Model();
69
69
 
70
+ model.getLogger().should.equal('logger');
70
71
  logger.get.should.have.been.calledWithExactly(':remote-model');
71
- model.logger.should.equal('logger');
72
72
  });
73
73
 
74
74
  it('should use console log and a trimHtml pass-through if hmpo-logger is not available', () => {
75
- logger.get.throws({ message: 'test error' });
76
-
77
75
  model = new Model();
76
+ model.logger = null;
78
77
 
79
- model.logger.outbound.should.eql(console.log);
80
- model.logger.trimHtml.should.be.a('function');
78
+ model.getLogger().outbound.should.eql(console.log);
79
+ model.getLogger().trimHtml.should.be.a('function');
81
80
  const html = {};
82
- model.logger.trimHtml(html).should.equal(html);
81
+ model.getLogger().trimHtml(html).should.equal(html);
83
82
  });
84
83
  });
85
84