@mojaloop/sdk-scheme-adapter 16.0.0 → 17.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/CHANGELOG.md +17 -0
- package/audit-resolve.json +0 -25
- package/package.json +1 -1
- package/src/InboundServer/index.js +4 -2
- package/src/InboundServer/middlewares.js +12 -4
- package/src/OutboundServer/index.js +3 -2
- package/src/OutboundServer/middlewares.js +6 -2
- package/src/TestServer/index.js +4 -2
- package/src/lib/metrics.js +0 -2
- package/src/lib/router.js +3 -1
- package/src/lib/validate.js +10 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,4 +1,21 @@
|
|
|
1
1
|
# Changelog: [mojaloop/thirdparty-api-svc](https://github.com/mojaloop/thirdparty-api-svc)
|
|
2
|
+
## [17.0.0](https://github.com/mojaloop/sdk-scheme-adapter/compare/v15.0.1...v17.0.0) (2022-07-04)
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
### ⚠ BREAKING CHANGES
|
|
6
|
+
|
|
7
|
+
* add dummy pr to major version bump due to unsquashed title (#327)
|
|
8
|
+
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
* suppress health check logs ([#328](https://github.com/mojaloop/sdk-scheme-adapter/issues/328)) ([64fadde](https://github.com/mojaloop/sdk-scheme-adapter/commit/64faddea8307aa0c19d56466d0afe8f8208c4d66))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
### Chore
|
|
15
|
+
|
|
16
|
+
* add dummy pr to major version bump due to unsquashed title ([#327](https://github.com/mojaloop/sdk-scheme-adapter/issues/327)) ([ff0f29b](https://github.com/mojaloop/sdk-scheme-adapter/commit/ff0f29b7ce560565ee21cf6ae84118e1b391b5b5))
|
|
17
|
+
* **release:** 16.0.0 [skip ci] ([0071c65](https://github.com/mojaloop/sdk-scheme-adapter/commit/0071c65c3665239d0a482e76498f9eec5c288043))
|
|
18
|
+
|
|
2
19
|
## [16.0.0](https://github.com/mojaloop/sdk-scheme-adapter/compare/v15.0.1...v16.0.0) (2022-07-01)
|
|
3
20
|
|
|
4
21
|
|
package/audit-resolve.json
CHANGED
|
@@ -95,31 +95,6 @@
|
|
|
95
95
|
"1068310|widdershins>markdown-it>yargs>yargs-parser": {
|
|
96
96
|
"decision": "ignore",
|
|
97
97
|
"madeAt": 1656681883038
|
|
98
|
-
},
|
|
99
|
-
"1070030|@mojaloop/central-services-shared>@mojaloop/event-sdk>grpc>protobufjs>widdershins>markdown-it": {
|
|
100
|
-
"decision": "ignore",
|
|
101
|
-
"madeAt": 1656691882275,
|
|
102
|
-
"expiresAt": 1659283873047
|
|
103
|
-
},
|
|
104
|
-
"1070030|shins>markdown-it": {
|
|
105
|
-
"decision": "ignore",
|
|
106
|
-
"madeAt": 1656691882275,
|
|
107
|
-
"expiresAt": 1659283873047
|
|
108
|
-
},
|
|
109
|
-
"1068310|@mojaloop/central-services-shared>@mojaloop/event-sdk>grpc>protobufjs>widdershins>markdown-it>yargs>yargs-parser": {
|
|
110
|
-
"decision": "ignore",
|
|
111
|
-
"madeAt": 1656691883964,
|
|
112
|
-
"expiresAt": 1659283873047
|
|
113
|
-
},
|
|
114
|
-
"1068155|shins>markdown-it>sanitize-html": {
|
|
115
|
-
"decision": "ignore",
|
|
116
|
-
"madeAt": 1656691885077,
|
|
117
|
-
"expiresAt": 1659283873047
|
|
118
|
-
},
|
|
119
|
-
"1070260|shins>markdown-it>sanitize-html": {
|
|
120
|
-
"decision": "ignore",
|
|
121
|
-
"madeAt": 1656691886045,
|
|
122
|
-
"expiresAt": 1659283873047
|
|
123
98
|
}
|
|
124
99
|
},
|
|
125
100
|
"rules": {},
|
package/package.json
CHANGED
|
@@ -23,6 +23,8 @@ const router = require('../lib/router');
|
|
|
23
23
|
const handlers = require('./handlers');
|
|
24
24
|
const middlewares = require('./middlewares');
|
|
25
25
|
|
|
26
|
+
const logExcludePaths = ['/'];
|
|
27
|
+
|
|
26
28
|
class InboundApi extends EventEmitter {
|
|
27
29
|
constructor(conf, logger, cache, validator, wso2) {
|
|
28
30
|
super({ captureExceptions: true });
|
|
@@ -99,7 +101,7 @@ class InboundApi extends EventEmitter {
|
|
|
99
101
|
api.use(middlewares.createJwsValidator(logger, jwsVerificationKeys, jwsExclusions));
|
|
100
102
|
}
|
|
101
103
|
|
|
102
|
-
api.use(middlewares.applyState({ cache, wso2, conf }));
|
|
104
|
+
api.use(middlewares.applyState({ cache, wso2, conf, logExcludePaths }));
|
|
103
105
|
api.use(middlewares.createLogger(logger));
|
|
104
106
|
api.use(middlewares.createRequestValidator(validator));
|
|
105
107
|
api.use(middlewares.assignFspiopIdentifier());
|
|
@@ -133,7 +135,7 @@ class InboundServer extends EventEmitter {
|
|
|
133
135
|
constructor(conf, logger, cache, wso2) {
|
|
134
136
|
super({ captureExceptions: true });
|
|
135
137
|
this._conf = conf;
|
|
136
|
-
this._validator = new Validate();
|
|
138
|
+
this._validator = new Validate({ logExcludePaths });
|
|
137
139
|
this._logger = logger;
|
|
138
140
|
this._api = new InboundApi(
|
|
139
141
|
conf,
|
|
@@ -353,13 +353,17 @@ const createLogger = (logger) => async (ctx, next) => {
|
|
|
353
353
|
path: ctx.path,
|
|
354
354
|
method: ctx.method
|
|
355
355
|
}});
|
|
356
|
-
ctx.state.
|
|
356
|
+
if (!ctx.state.logExcludePaths.includes(ctx.path)) {
|
|
357
|
+
ctx.state.logger.push({body: ctx.request.body}).log('Request received');
|
|
358
|
+
}
|
|
357
359
|
try {
|
|
358
360
|
await next();
|
|
359
361
|
} catch (err) {
|
|
360
362
|
ctx.state.logger.push(err).log('Error');
|
|
361
363
|
}
|
|
362
|
-
|
|
364
|
+
if (!ctx.state.logExcludePaths.includes(ctx.path)) {
|
|
365
|
+
await ctx.state.logger.log('Request processed');
|
|
366
|
+
}
|
|
363
367
|
};
|
|
364
368
|
|
|
365
369
|
|
|
@@ -369,10 +373,14 @@ const createLogger = (logger) => async (ctx, next) => {
|
|
|
369
373
|
* @return {Function}
|
|
370
374
|
*/
|
|
371
375
|
const createRequestValidator = (validator) => async (ctx, next) => {
|
|
372
|
-
ctx.state.
|
|
376
|
+
if (!ctx.state.logExcludePaths.includes(ctx.path)) {
|
|
377
|
+
ctx.state.logger.log('Validating request');
|
|
378
|
+
}
|
|
373
379
|
try {
|
|
374
380
|
ctx.state.path = validator.validateRequest(ctx, ctx.state.logger);
|
|
375
|
-
ctx.state.
|
|
381
|
+
if (!ctx.state.logExcludePaths.includes(ctx.path)) {
|
|
382
|
+
ctx.state.logger.log('Request passed validation');
|
|
383
|
+
}
|
|
376
384
|
await next();
|
|
377
385
|
} catch (err) {
|
|
378
386
|
ctx.state.logger.push({ err }).log('Request failed validation.');
|
|
@@ -23,6 +23,7 @@ const handlers = require('./handlers');
|
|
|
23
23
|
const middlewares = require('./middlewares');
|
|
24
24
|
|
|
25
25
|
const endpointRegex = /\/.*/g;
|
|
26
|
+
const logExcludePaths = ['/'];
|
|
26
27
|
|
|
27
28
|
class OutboundApi extends EventEmitter {
|
|
28
29
|
constructor(conf, logger, cache, validator, metricsClient, wso2) {
|
|
@@ -36,7 +37,7 @@ class OutboundApi extends EventEmitter {
|
|
|
36
37
|
this._api.use(middlewares.createErrorHandler(this._logger));
|
|
37
38
|
this._api.use(middlewares.createRequestIdGenerator());
|
|
38
39
|
this._api.use(koaBody()); // outbound always expects application/json
|
|
39
|
-
this._api.use(middlewares.applyState({ cache, wso2, conf, metricsClient }));
|
|
40
|
+
this._api.use(middlewares.applyState({ cache, wso2, conf, metricsClient, logExcludePaths }));
|
|
40
41
|
this._api.use(middlewares.createLogger(this._logger));
|
|
41
42
|
|
|
42
43
|
//Note that we strip off any path on peerEndpoint config after the origin.
|
|
@@ -69,7 +70,7 @@ class OutboundApi extends EventEmitter {
|
|
|
69
70
|
class OutboundServer extends EventEmitter {
|
|
70
71
|
constructor(conf, logger, cache, metricsClient, wso2) {
|
|
71
72
|
super({ captureExceptions: true });
|
|
72
|
-
this._validator = new Validate();
|
|
73
|
+
this._validator = new Validate({ logExcludePaths });
|
|
73
74
|
this._conf = conf;
|
|
74
75
|
this._logger = logger;
|
|
75
76
|
this._server = null;
|
|
@@ -20,10 +20,14 @@ const { applyState, createErrorHandler, createLogger, createRequestIdGenerator }
|
|
|
20
20
|
* @return {Function}
|
|
21
21
|
*/
|
|
22
22
|
const createRequestValidator = (validator) => async (ctx, next) => {
|
|
23
|
-
ctx.state.
|
|
23
|
+
if (!ctx.state.logExcludePaths.includes(ctx.path)) {
|
|
24
|
+
ctx.state.logger.log('Validating request');
|
|
25
|
+
}
|
|
24
26
|
try {
|
|
25
27
|
ctx.state.path = validator.validateRequest(ctx, ctx.state.logger);
|
|
26
|
-
ctx.state.
|
|
28
|
+
if (!ctx.state.logExcludePaths.includes(ctx.path)) {
|
|
29
|
+
ctx.state.logger.log('Request passed validation');
|
|
30
|
+
}
|
|
27
31
|
await next();
|
|
28
32
|
} catch (err) {
|
|
29
33
|
ctx.state.logger.push({ err }).log('Request failed validation.');
|
package/src/TestServer/index.js
CHANGED
|
@@ -21,6 +21,8 @@ const router = require('../lib/router');
|
|
|
21
21
|
const handlers = require('./handlers');
|
|
22
22
|
const middlewares = require('../InboundServer/middlewares');
|
|
23
23
|
|
|
24
|
+
const logExcludePaths = ['/'];
|
|
25
|
+
|
|
24
26
|
const getWsIp = (req) => [
|
|
25
27
|
req.socket.remoteAddress,
|
|
26
28
|
...(
|
|
@@ -36,7 +38,7 @@ class TestApi {
|
|
|
36
38
|
|
|
37
39
|
this._api.use(middlewares.createErrorHandler(logger));
|
|
38
40
|
this._api.use(middlewares.createRequestIdGenerator());
|
|
39
|
-
this._api.use(middlewares.applyState({ cache }));
|
|
41
|
+
this._api.use(middlewares.applyState({ cache, logExcludePaths }));
|
|
40
42
|
this._api.use(middlewares.createLogger(logger));
|
|
41
43
|
|
|
42
44
|
this._api.use(middlewares.createRequestValidator(validator));
|
|
@@ -174,7 +176,7 @@ class TestServer {
|
|
|
174
176
|
constructor({ port, logger, cache }) {
|
|
175
177
|
this._port = port;
|
|
176
178
|
this._logger = logger;
|
|
177
|
-
this._validator = new Validate();
|
|
179
|
+
this._validator = new Validate({ logExcludePaths });
|
|
178
180
|
this._api = new TestApi(this._logger.push({ component: 'api' }), this._validator, cache);
|
|
179
181
|
this._server = http.createServer(this._api.callback());
|
|
180
182
|
// TODO: why does this appear to need to be called after creating this._server (try reorder
|
package/src/lib/metrics.js
CHANGED
|
@@ -131,8 +131,6 @@ class MetricsServer {
|
|
|
131
131
|
|
|
132
132
|
result.use(koaBody());
|
|
133
133
|
result.use(async ctx => {
|
|
134
|
-
this._logger.log('Metrics request received');
|
|
135
|
-
|
|
136
134
|
ctx.response.set('Content-Type', this._prometheusRegister.contentType);
|
|
137
135
|
ctx.response.body = await this._prometheusRegister.metrics();
|
|
138
136
|
});
|
package/src/lib/router.js
CHANGED
|
@@ -21,7 +21,9 @@ module.exports = (handlerMap) => async (ctx, next) => {
|
|
|
21
21
|
ctx.response.body = { statusCode: 404, message: 'Not found' };
|
|
22
22
|
}
|
|
23
23
|
else {
|
|
24
|
-
ctx.state.
|
|
24
|
+
if (!ctx.state.logExcludePaths.includes(ctx.path)) {
|
|
25
|
+
ctx.state.logger.push({handler}).log('Found handler');
|
|
26
|
+
}
|
|
25
27
|
await handler(ctx);
|
|
26
28
|
}
|
|
27
29
|
await next();
|
package/src/lib/validate.js
CHANGED
|
@@ -125,6 +125,13 @@ const transformApiDoc = apiDoc => ({
|
|
|
125
125
|
});
|
|
126
126
|
|
|
127
127
|
class Validator {
|
|
128
|
+
/**
|
|
129
|
+
* @param {{logExcludePaths: string[]}} [opts]
|
|
130
|
+
*/
|
|
131
|
+
|
|
132
|
+
constructor(opts) {
|
|
133
|
+
this.logExcludePaths = opts?.logExcludePaths || [];
|
|
134
|
+
}
|
|
128
135
|
// apiDoc
|
|
129
136
|
// POJO representing apiDoc API spec. Example:
|
|
130
137
|
// const v = new Validator(require('./apiDoc.json'));
|
|
@@ -163,7 +170,9 @@ class Validator {
|
|
|
163
170
|
}
|
|
164
171
|
result.params = Object.assign({}, ...path.match(result.matcher.regex).slice(1).map((m, i) => ({ [result.matcher.params[i]]: m})));
|
|
165
172
|
|
|
166
|
-
|
|
173
|
+
if (!this.logExcludePaths.includes(path)) {
|
|
174
|
+
logger.push({path, result}).log('Matched path');
|
|
175
|
+
}
|
|
167
176
|
return result;
|
|
168
177
|
}
|
|
169
178
|
|