Skip to content

Commit

Permalink
fix(csi-498): added logs to incoming requests (#491)
Browse files Browse the repository at this point in the history
* fix(csi-498): added logs to incoming requests

* fix(csi-498): added logs to incoming requests

* fix(csi-498): added logs to incoming requests

* fix(csi-498): added logs to incoming requests

* fix(csi-498): added logs to incoming requests

* chore(snapshot): 23.6.0-snapshot.2

* fix(csi-498): updated central-services-shared version

* chore(snapshot): 23.6.0-snapshot.3
  • Loading branch information
geka-evk authored Aug 19, 2024
1 parent 35c7713 commit fa95843
Show file tree
Hide file tree
Showing 16 changed files with 855 additions and 414 deletions.
5 changes: 3 additions & 2 deletions .ncurc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ reject: [
'@mojaloop/logging-bc-client-lib',
## TODO: The new version of npm-check-updates uses new Glob v9.x and it is introducing a dependency Package "[email protected]" which is licensed under "BlueOak-1.0.0" which is not permitted by the Mojaloop License Policy
'npm-check-updates',
'@mojaloop/central-services-shared',
## TODO: The new version of nx causes submodules to be broken.
"nx",
## TODO: The new version of eslint requires migration of configuration files.
"eslint"
"eslint",
"@typescript-eslint/eslint-plugin",
"@typescript-eslint/parser"
]
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
18.20.3
18.20.4
3 changes: 2 additions & 1 deletion audit-ci.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
// https://github.com/advisories/GHSA-rm97-x556-q36h
"GHSA-rm97-x556-q36h",
"GHSA-wf5p-g6vw-rhxx", // https://github.com/advisories/GHSA-wf5p-g6vw-rhxx
"GHSA-2p57-rm9w-gvfp" // https://github.com/advisories/GHSA-2p57-rm9w-gvfp
"GHSA-2p57-rm9w-gvfp", // https://github.com/advisories/GHSA-2p57-rm9w-gvfp
"GHSA-8hc4-vh64-cxmj" // https://github.com/advisories/GHSA-8hc4-vh64-cxmj
]
}
24 changes: 12 additions & 12 deletions modules/api-svc/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@mojaloop/sdk-scheme-adapter-api-svc",
"version": "20.8.0-snapshot.2",
"version": "20.8.0-snapshot.4",
"description": "An adapter for connecting to Mojaloop API enabled switches.",
"main": "src/index.js",
"types": "src/index.d.ts",
Expand Down Expand Up @@ -65,14 +65,14 @@
"@koa/cors": "^5.0.0",
"@mojaloop/api-snippets": "17.5.1",
"@mojaloop/central-services-error-handling": "^13.0.1",
"@mojaloop/central-services-logger": "^11.3.1",
"@mojaloop/central-services-logger": "^11.5.0",
"@mojaloop/central-services-metrics": "^12.0.8",
"@mojaloop/central-services-shared": "18.4.0",
"@mojaloop/central-services-shared": "18.7.0",
"@mojaloop/event-sdk": "^14.1.1",
"@mojaloop/sdk-scheme-adapter-private-shared-lib": "workspace:^",
"@mojaloop/sdk-standard-components": "18.2.1",
"ajv": "8.16.0",
"axios": "^1.7.2",
"@mojaloop/sdk-standard-components": "18.4.0",
"ajv": "8.17.1",
"axios": "^1.7.4",
"co-body": "^6.2.0",
"dotenv": "^16.4.5",
"env-var": "^7.5.0",
Expand All @@ -91,25 +91,25 @@
"prom-client": "^15.1.3",
"promise-timeout": "^1.3.0",
"random-word-slugs": "^0.1.7",
"redis": "^4.6.14",
"ws": "^8.17.1"
"redis": "^4.7.0",
"ws": "^8.18.0"
},
"devDependencies": {
"@babel/core": "^7.24.7",
"@babel/preset-env": "^7.24.7",
"@babel/core": "^7.25.2",
"@babel/preset-env": "^7.25.3",
"@redocly/openapi-cli": "^1.0.0-beta.94",
"@types/jest": "^29.5.12",
"babel-jest": "^29.7.0",
"eslint": "^8.57.0",
"eslint-config-airbnb-base": "^15.0.0",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-jest": "^28.6.0",
"eslint-plugin-jest": "^28.8.0",
"jest": "^29.7.0",
"jest-junit": "^16.0.0",
"nock": "^13.5.4",
"npm-check-updates": "^16.7.10",
"openapi-response-validator": "^12.1.3",
"openapi-typescript": "^7.0.0",
"openapi-typescript": "^7.3.0",
"redis-mock": "^0.56.3",
"replace": "^1.2.2",
"standard-version": "^9.5.0",
Expand Down
2 changes: 1 addition & 1 deletion modules/api-svc/src/InboundServer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ class InboundApi extends EventEmitter {
const api = new Koa();

api.use(middlewares.createErrorHandler(logger));
api.use(middlewares.createRequestIdGenerator());
api.use(middlewares.createRequestIdGenerator(logger));
api.use(middlewares.createHeaderValidator(conf, logger));
if (conf.validateInboundJws) {
const jwsExclusions = conf.validateInboundPutPartiesJws ? [] : ['putParties'];
Expand Down
17 changes: 13 additions & 4 deletions modules/api-svc/src/InboundServer/middlewares.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,10 @@ const cacheRequest = (cache) => async (ctx, next) => {
* tag each incoming request with a unique identifier
* @return {Function}
*/
const createRequestIdGenerator = () => async (ctx, next) => {
const createRequestIdGenerator = (logger) => async (ctx, next) => {
ctx.request.id = generateSlug(4);
const { method, path, id } = ctx.request;
logger.info(`[==> req] ${method?.toUpperCase()} ${path} - requestId: ${id}`);
await next();
};

Expand All @@ -193,6 +195,7 @@ const createHeaderValidator = (conf, logger) => async (

// Only validate requests for the requested resources
if (!resources.includes(resource)) {
logger.info(`skip validation for ${resource}`);
return await next();
}

Expand All @@ -207,6 +210,7 @@ const createHeaderValidator = (conf, logger) => async (
null,
Errors.MojaloopApiErrorCodes.MISSING_ELEMENT
).toApiErrorObject();
logger.error('accept header is missing');
return;
}
const accept = parseAcceptHeader(resource, request.headers.accept);
Expand All @@ -218,6 +222,7 @@ const createHeaderValidator = (conf, logger) => async (
null,
Errors.MojaloopApiErrorCodes.MALFORMED_SYNTAX
).toApiErrorObject();
logger.error('accept header is invalid');
return;
}
if (!supportedProtocolVersions.some(supportedVer => accept.versions.has(supportedVer))) {
Expand All @@ -229,6 +234,7 @@ const createHeaderValidator = (conf, logger) => async (
Errors.MojaloopApiErrorCodes.UNACCEPTABLE_VERSION,
protocolVersionsMap
).toApiErrorObject();
logger.error('accept header has unacceptable version');
return;
}
}
Expand All @@ -243,6 +249,7 @@ const createHeaderValidator = (conf, logger) => async (
Errors.MojaloopApiErrorCodes.MISSING_ELEMENT,
protocolVersionsMap
).toApiErrorObject();
logger.error('contentType header is undefined');
return;
}

Expand All @@ -255,6 +262,7 @@ const createHeaderValidator = (conf, logger) => async (
null,
Errors.MojaloopApiErrorCodes.MALFORMED_SYNTAX
).toApiErrorObject();
logger.error('contentType header is invalid');
return;
}
if (!supportedProtocolVersions.includes(contentType.version)) {
Expand All @@ -266,6 +274,7 @@ const createHeaderValidator = (conf, logger) => async (
Errors.MojaloopApiErrorCodes.UNACCEPTABLE_VERSION,
protocolVersionsMap
).toApiErrorObject();
logger.error('contentType header has unacceptable version');
return;
}

Expand All @@ -274,7 +283,7 @@ const createHeaderValidator = (conf, logger) => async (
}
catch(err) {
// error parsing body
logger.isErrorEnabled && logger.push({ err }).error('Error parsing body');
logger.push({ err }).error('Error parsing body');
ctx.response.status = Errors.MojaloopApiErrorCodes.MALFORMED_SYNTAX.httpStatusCode;
ctx.response.body = new Errors.MojaloopFSPIOPError(err, err.message, null,
Errors.MojaloopApiErrorCodes.MALFORMED_SYNTAX).toApiErrorObject();
Expand Down Expand Up @@ -319,7 +328,7 @@ const createJwsValidator = (logger, keys, exclusions) => {

}
catch(err) {
logger.isErrorEnabled && logger.push({ err }).error('Inbound request failed JWS validation');
logger.push({ err }).error('Inbound request failed JWS validation');

ctx.response.status = ReturnCodes.BADREQUEST.CODE;
ctx.response.body = new Errors.MojaloopFSPIOPError(
Expand Down Expand Up @@ -397,7 +406,7 @@ const createRequestValidator = (validator) => async (ctx, next) => {
}
await next();
} catch (err) {
ctx.state.logger.isErrorEnabled && ctx.state.logger.push({ err }).error('Request failed validation.');
ctx.state.logger.push({ err }).error('Request failed validation.');
// send a mojaloop spec error response
ctx.response.status = err.httpStatusCode || ReturnCodes.BADREQUEST.CODE;

Expand Down
2 changes: 1 addition & 1 deletion modules/api-svc/src/OutboundServer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class OutboundApi extends EventEmitter {
this._metricsClient = metricsClient;

this._api.use(middlewares.createErrorHandler(this._logger));
this._api.use(middlewares.createRequestIdGenerator());
this._api.use(middlewares.createRequestIdGenerator(this._logger));
this._api.use(koaBody({
formidable: { maxFieldsSize: conf.backendApiServerMaxRequestBytes }
})); // outbound always expects application/json
Expand Down
2 changes: 1 addition & 1 deletion modules/api-svc/src/TestServer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class TestApi {
this._api = new Koa();

this._api.use(middlewares.createErrorHandler(logger));
this._api.use(middlewares.createRequestIdGenerator());
this._api.use(middlewares.createRequestIdGenerator(logger));
this._api.use(middlewares.applyState({ cache, logExcludePaths }));
this._api.use(middlewares.createLogger(logger));

Expand Down
5 changes: 5 additions & 0 deletions modules/api-svc/src/constants.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const SDK_LOGGER_HIERARCHY = ['verbose', 'trace', 'debug', 'info', 'warn', 'error', 'fatal'];

module.exports = {
SDK_LOGGER_HIERARCHY,
};
2 changes: 1 addition & 1 deletion modules/api-svc/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ const Validate = require('./lib/validate');
const Cache = require('./lib/cache');
const { SDKStateEnum } = require('./lib/model/common');
const { createAuthClient } = require('./lib/utils');
const { SDK_LOGGER_HIERARCHY } = require('./constants');

const LOG_ID = {
INBOUND: { app: 'mojaloop-connector-inbound-api' },
Expand All @@ -46,7 +47,6 @@ const LOG_ID = {
METRICS: { app: 'mojaloop-connector-metrics' },
CACHE: { component: 'cache' },
};
const SDK_LOGGER_HIERARCHY = ['verbose', 'trace', 'debug', 'info', 'warn', 'error', 'fatal'];

const createCache = (config, logger) => new Cache({
cacheUrl: config.cacheUrl,
Expand Down
4 changes: 2 additions & 2 deletions modules/api-svc/test/unit/api/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ const fs = require('fs');
const path = require('path');
const yaml = require('js-yaml');
const supertest = require('supertest');
const Validate = require('~/lib/validate');
const { Logger, WSO2Auth } = require('@mojaloop/sdk-standard-components');

const Validate = require('~/lib/validate');
const InboundServer = require('~/InboundServer');
const OutboundServer = require('~/OutboundServer');
const { MetricsClient } = require('~/lib/metrics');
const { Logger, WSO2Auth } = require('@mojaloop/sdk-standard-components');
const Cache = require('~/lib/cache');

const ServerType = {
Expand Down
14 changes: 7 additions & 7 deletions modules/outbound-command-event-handler/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@mojaloop/sdk-scheme-adapter-outbound-command-event-handler",
"version": "0.2.20-snapshot.13",
"version": "0.2.20-snapshot.15",
"description": "Mojaloop sdk scheme adapter command event handler",
"license": "Apache-2.0",
"homepage": "https://github.com/mojaloop/sdk-scheme-adapter/",
Expand Down Expand Up @@ -42,23 +42,23 @@
},
"dependencies": {
"@mojaloop/api-snippets": "17.5.1",
"@mojaloop/central-services-shared": "^18.2.0",
"@mojaloop/central-services-shared": "^18.7.0",
"@mojaloop/logging-bc-client-lib": "^0.1.17",
"@mojaloop/logging-bc-public-types-lib": "^0.5.4",
"@mojaloop/sdk-scheme-adapter-private-shared-lib": "workspace:^",
"ajv": "^8.16.0",
"ajv": "^8.17.1",
"convict": "^6.2.4",
"express": "^4.19.2",
"openapi-backend": "^5.10.6",
"redis": "^4.6.14",
"redis": "^4.7.0",
"swagger-ui-express": "^5.0.1",
"yamljs": "^0.3.0"
},
"devDependencies": {
"@types/convict": "^6.1.6",
"@types/express": "^4.17.21",
"@types/jest": "^29.5.12",
"@types/node": "^20.14.9",
"@types/node": "^22.3.0",
"@types/node-cache": "^4.2.5",
"@types/supertest": "^6.0.2",
"@types/swagger-ui-express": "^4.1.6",
Expand All @@ -72,9 +72,9 @@
"npm-check-updates": "^16.7.10",
"replace": "^1.2.2",
"standard-version": "^9.5.0",
"ts-jest": "^29.1.5",
"ts-jest": "^29.2.4",
"ts-node": "^10.9.2",
"typescript": "^5.5.3"
"typescript": "^5.5.4"
},
"nodemonConfig": {
"watch": [
Expand Down
10 changes: 5 additions & 5 deletions modules/outbound-domain-event-handler/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@mojaloop/sdk-scheme-adapter-outbound-domain-event-handler",
"version": "0.2.20-snapshot.13",
"version": "0.2.20-snapshot.15",
"description": "mojaloop sdk scheme adapter outbound domain event handler",
"license": "Apache-2.0",
"homepage": "https://github.com/mojaloop/sdk-scheme-adapter/",
Expand Down Expand Up @@ -48,15 +48,15 @@
"convict": "^6.2.4",
"express": "^4.19.2",
"openapi-backend": "^5.10.6",
"redis": "^4.6.14",
"redis": "^4.7.0",
"swagger-ui-express": "^5.0.1",
"yamljs": "^0.3.0"
},
"devDependencies": {
"@types/convict": "^6.1.6",
"@types/express": "^4.17.21",
"@types/jest": "^29.5.12",
"@types/node": "^20.14.9",
"@types/node": "^22.3.0",
"@types/node-cache": "^4.2.5",
"@types/supertest": "^6.0.2",
"@types/swagger-ui-express": "^4.1.6",
Expand All @@ -70,9 +70,9 @@
"npm-check-updates": "^16.7.10",
"replace": "^1.2.2",
"standard-version": "^9.5.0",
"ts-jest": "^29.1.5",
"ts-jest": "^29.2.4",
"ts-node": "^10.9.2",
"typescript": "^5.5.3"
"typescript": "^5.5.4"
},
"nodemonConfig": {
"watch": [
Expand Down
14 changes: 7 additions & 7 deletions modules/private-shared-lib/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@mojaloop/sdk-scheme-adapter-private-shared-lib",
"version": "0.3.20-snapshot.13",
"version": "0.3.20-snapshot.15",
"description": "SDK Scheme Adapter private shared library.",
"license": "Apache-2.0",
"homepage": "https://github.com/mojaloop/accounts-and-balances-bc/tree/main/modules/private-types",
Expand Down Expand Up @@ -28,24 +28,24 @@
},
"dependencies": {
"@mojaloop/api-snippets": "17.5.1",
"@mojaloop/central-services-shared": "^18.2.0",
"@mojaloop/central-services-shared": "^18.7.0",
"@mojaloop/logging-bc-public-types-lib": "^0.5.4",
"@mojaloop/platform-shared-lib-messaging-types-lib": "^0.6.2",
"@mojaloop/platform-shared-lib-nodejs-kafka-client-lib": "0.2.15",
"ajv": "^8.16.0",
"redis": "^4.6.14",
"ajv": "^8.17.1",
"redis": "^4.7.0",
"uuid": "^10.0.0"
},
"devDependencies": {
"@types/node": "^20.14.9",
"@types/node": "^22.3.0",
"@types/uuid": "^10.0.0",
"eslint": "^8.57.0",
"jest": "^29.7.0",
"npm-check-updates": "^16.7.10",
"replace": "^1.2.2",
"standard-version": "^9.5.0",
"ts-jest": "^29.1.5",
"typescript": "^5.5.3"
"ts-jest": "^29.2.4",
"typescript": "^5.5.4"
},
"standard-version": {
"scripts": {
Expand Down
Loading

0 comments on commit fa95843

Please sign in to comment.