hmpo-model 4.2.0 → 5.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/lib/remote-model.js
CHANGED
|
@@ -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
|
-
|
|
23
|
-
this.logger = hmpoLogger.get(':' + this.options.label);
|
|
24
|
+
this.logger = require('hmpo-logger');
|
|
24
25
|
} catch (e) {
|
|
25
|
-
|
|
26
|
-
|
|
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.
|
|
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.
|
|
282
|
+
this.getLogger().outbound('Model request sent :outVerb :outRequest', this.logMeta.apply(this, arguments));
|
|
278
283
|
}
|
|
279
284
|
|
|
280
285
|
logSuccess() {
|
|
281
|
-
this.
|
|
286
|
+
this.getLogger().outbound('Model request success :outVerb :outRequest :outResponseCode', this.logMeta.apply(this, arguments));
|
|
282
287
|
}
|
|
283
288
|
|
|
284
289
|
logError() {
|
|
285
|
-
this.
|
|
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": "
|
|
3
|
+
"version": "5.0.0",
|
|
4
4
|
"description": "Simple model for interacting with http/rest apis.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
"author": "PEX",
|
|
19
19
|
"license": "MIT",
|
|
20
20
|
"engines": {
|
|
21
|
-
"node": ">=
|
|
21
|
+
"node": ">=14"
|
|
22
22
|
},
|
|
23
23
|
"bugs": {
|
|
24
24
|
"url": "https://github.com/UKHomeOffice/passports-model/issues"
|
|
@@ -34,11 +34,11 @@
|
|
|
34
34
|
"devDependencies": {
|
|
35
35
|
"chai": "^4.3.6",
|
|
36
36
|
"eslint": "^8.18.0",
|
|
37
|
-
"hmpo-logger": "^
|
|
37
|
+
"hmpo-logger": "^7.0.0",
|
|
38
38
|
"mocha": "^10.0.0",
|
|
39
39
|
"nyc": "^15.1.0",
|
|
40
40
|
"proxyquire": "^2.0.0",
|
|
41
|
-
"sinon": "^
|
|
41
|
+
"sinon": "^15.0.4",
|
|
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.
|
|
80
|
-
model.
|
|
78
|
+
model.getLogger().outbound.should.eql(console.log);
|
|
79
|
+
model.getLogger().trimHtml.should.be.a('function');
|
|
81
80
|
const html = {};
|
|
82
|
-
model.
|
|
81
|
+
model.getLogger().trimHtml(html).should.equal(html);
|
|
83
82
|
});
|
|
84
83
|
});
|
|
85
84
|
|