Skip to content

Commit

Permalink
feat: allow optional dfspId to be in the endpoint path (#526)
Browse files Browse the repository at this point in the history
  • Loading branch information
kalinkrustev authored Jan 10, 2025
1 parent 4f5d281 commit 0763a93
Show file tree
Hide file tree
Showing 13 changed files with 422 additions and 421 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,5 @@ devspace*
**/dist/*
.DS_Store
dist

.rush
5 changes: 4 additions & 1 deletion docker-compose.pm4ml.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ services:
sdk-scheme-adapter-api-svc:
env_file: ./modules/api-svc/test/config/integration-pm4ml.env
depends_on:
- mock-management-svc
mock-management-svc:
condition: service_healthy
init-kafka:
condition: service_completed_successfully
command: yarn nx run modules-api-svc:start

mock-management-svc:
Expand Down
22 changes: 12 additions & 10 deletions modules/api-svc/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,17 +64,19 @@
},
"dependencies": {
"@koa/cors": "^5.0.0",
"@mojaloop/api-snippets": "17.7.7",
"@mojaloop/central-services-error-handling": "^13.0.2",
"@mojaloop/central-services-logger": "^11.5.1",
"@mojaloop/central-services-metrics": "^12.4.2",
"@mojaloop/central-services-shared": "18.14.1",
"@mojaloop/event-sdk": "^14.1.1",
"@mojaloop/ml-schema-transformer-lib": "2.4.1",
"@mojaloop/api-snippets": "17.7.8",
"@mojaloop/central-services-error-handling": "^13.0.3",
"@mojaloop/central-services-logger": "^11.5.2",
"@mojaloop/central-services-metrics": "^12.4.3",
"@mojaloop/central-services-shared": "^18.15.1",
"@mojaloop/event-sdk": "^14.1.2",
"@mojaloop/logging-bc-client-lib": "0.5.8",
"@mojaloop/ml-schema-transformer-lib": "^2.5.1",
"@mojaloop/sdk-scheme-adapter-private-shared-lib": "workspace:^",
"@mojaloop/sdk-standard-components": "^19.6.2",
"@mojaloop/sdk-standard-components": "^19.6.3",
"ajv": "8.17.1",
"axios": "^1.7.9",
"body-parser": "^1.20.3",
"co-body": "^6.2.0",
"dotenv": "^16.4.7",
"env-var": "^7.5.0",
Expand Down Expand Up @@ -107,12 +109,12 @@
"eslint": "^9.15.0",
"eslint-config-airbnb-base": "^15.0.0",
"eslint-plugin-import": "^2.31.0",
"eslint-plugin-jest": "^28.9.0",
"eslint-plugin-jest": "^28.10.0",
"jest": "^29.7.0",
"jest-junit": "^16.0.0",
"npm-check-updates": "^16.7.10",
"openapi-response-validator": "^12.1.3",
"openapi-typescript": "^7.4.4",
"openapi-typescript": "^7.5.2",
"redis-mock": "^0.56.3",
"replace": "^1.2.2",
"standard-version": "^9.5.0",
Expand Down
13 changes: 13 additions & 0 deletions modules/api-svc/src/OutboundServer/handlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ const handleRequestSimpleTransfersInformationError = (method, err, ctx) =>

const createOutboundTransfersModel = (ctx) => new OutboundTransfersModel({
...ctx.state.conf,
...ctx.state.path?.params?.dfspId && {dfspId: ctx.state.path.params.dfspId},
cache: ctx.state.cache,
logger: ctx.state.logger,
wso2: ctx.state.wso2,
Expand Down Expand Up @@ -206,6 +207,7 @@ const postBulkTransfers = async (ctx) => {
// use the bulk transfers model to execute asynchronous stages with the switch
const model = new OutboundBulkTransfersModel({
...ctx.state.conf,
...ctx.state.path?.params?.dfspId && {dfspId: ctx.state.path.params.dfspId},
cache: ctx.state.cache,
logger: ctx.state.logger,
wso2: ctx.state.wso2,
Expand Down Expand Up @@ -237,6 +239,7 @@ const getBulkTransfers = async (ctx) => {
// use the bulk transfers model to execute asynchronous stages with the switch
const model = new OutboundBulkTransfersModel({
...ctx.state.conf,
...ctx.state.path?.params?.dfspId && {dfspId: ctx.state.path.params.dfspId},
cache: ctx.state.cache,
logger: ctx.state.logger,
wso2: ctx.state.wso2,
Expand Down Expand Up @@ -321,6 +324,7 @@ const postBulkQuotes = async (ctx) => {
// use the bulk quotes model to execute asynchronous request with the switch
const model = new OutboundBulkQuotesModel({
...ctx.state.conf,
...ctx.state.path?.params?.dfspId && {dfspId: ctx.state.path.params.dfspId},
cache: ctx.state.cache,
logger: ctx.state.logger,
wso2: ctx.state.wso2,
Expand Down Expand Up @@ -352,6 +356,7 @@ const getBulkQuoteById = async (ctx) => {
// use the bulk quotes model to execute asynchronous stages with the switch
const model = new OutboundBulkQuotesModel({
...ctx.state.conf,
...ctx.state.path?.params?.dfspId && {dfspId: ctx.state.path.params.dfspId},
cache: ctx.state.cache,
logger: ctx.state.logger,
wso2: ctx.state.wso2,
Expand Down Expand Up @@ -382,6 +387,7 @@ const postRequestToPayTransfer = async (ctx) => {
// use the merchant transfers model to execute asynchronous stages with the switch
const model = new OutboundRequestToPayTransferModel({
...ctx.state.conf,
...ctx.state.path?.params?.dfspId && {dfspId: ctx.state.path.params.dfspId},
cache: ctx.state.cache,
logger: ctx.state.logger,
wso2: ctx.state.wso2,
Expand Down Expand Up @@ -409,6 +415,7 @@ const putRequestToPayTransfer = async (ctx) => {
// use the transfers model to execute asynchronous stages with the switch
const model = new OutboundRequestToPayTransferModel({
...ctx.state.conf,
...ctx.state.path?.params?.dfspId && {dfspId: ctx.state.path.params.dfspId},
cache: ctx.state.cache,
logger: ctx.state.logger,
wso2: ctx.state.wso2,
Expand Down Expand Up @@ -442,6 +449,7 @@ const postAccounts = async (ctx) => {
try {
const model = new AccountsModel({
...ctx.state.conf,
...ctx.state.path?.params?.dfspId && {dfspId: ctx.state.path.params.dfspId},
cache: ctx.state.cache,
logger: ctx.state.logger,
wso2: ctx.state.wso2,
Expand Down Expand Up @@ -474,6 +482,7 @@ const postRequestToPay = async (ctx) => {
// use the transfers model to execute asynchronous stages with the switch
const model = new OutboundRequestToPayModel({
...ctx.state.conf,
...ctx.state.path?.params?.dfspId && {dfspId: ctx.state.path.params.dfspId},
cache: ctx.state.cache,
logger: ctx.state.logger,
wso2: ctx.state.wso2,
Expand Down Expand Up @@ -502,6 +511,7 @@ const putRequestToPay = async (ctx) => {
// use the transfers model to execute asynchronous stages with the switch
const model = new OutboundRequestToPayModel({
...ctx.state.conf,
...ctx.state.path?.params?.dfspId && {dfspId: ctx.state.path.params.dfspId},
cache: ctx.state.cache,
logger: ctx.state.logger,
wso2: ctx.state.wso2,
Expand Down Expand Up @@ -543,6 +553,7 @@ const getPartiesByTypeAndId = async (ctx) => {
// prepare config
const modelConfig = {
...ctx.state.conf,
...ctx.state.path?.params?.dfspId && {dfspId: ctx.state.path.params.dfspId},
cache: ctx.state.cache,
logger: ctx.state.logger,
wso2: ctx.state.wso2,
Expand Down Expand Up @@ -577,6 +588,7 @@ const postQuotes = async (ctx) => {
// prepare config
const modelConfig = {
...ctx.state.conf,
...ctx.state.path?.params?.dfspId && {dfspId: ctx.state.path.params.dfspId},
cache: ctx.state.cache,
logger: ctx.state.logger,
wso2: ctx.state.wso2,
Expand Down Expand Up @@ -607,6 +619,7 @@ const postSimpleTransfers = async (ctx) => {
// prepare config
const modelConfig = {
...ctx.state.conf,
...ctx.state.path?.params?.dfspId && {dfspId: ctx.state.path.params.dfspId},
cache: ctx.state.cache,
logger: ctx.state.logger,
wso2: ctx.state.wso2,
Expand Down
8 changes: 7 additions & 1 deletion modules/api-svc/src/OutboundServer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,13 @@ class OutboundApi extends EventEmitter {
}

this._api.use(middlewares.createRequestValidator(validator));
this._api.use(router(handlers));
function mount(routes) {
if (!conf.multiDfsp) return routes;
return Object.fromEntries(Object.entries(routes).map(([path, route]) => {
return [`/{dfspId}${path}`, route];
}));
}
this._api.use(router(mount(handlers)));

this._api.use(middlewares.createResponseLogging(this._logger));
}
Expand Down
1 change: 1 addition & 0 deletions modules/api-svc/src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ module.exports = {
getServicesFxpResponse: env.get('GET_SERVICES_FXP_RESPONSE').default('').asArray(),

dfspId: env.get('DFSP_ID').default('mojaloop').asString(),
multiDfsp: env.get('MULTI_DFSP').default('false').asBool(),
ilpSecret: env.get('ILP_SECRET').default('mojaloop-sdk').asString(),
checkIlp: env.get('CHECK_ILP').default('true').asBool(),
expirySeconds: env.get('EXPIRY_SECONDS').default('60').asIntPositive(),
Expand Down
76 changes: 40 additions & 36 deletions modules/api-svc/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -343,44 +343,46 @@ async function _GetUpdatedConfigFromMgmtAPI(conf, logger, client) {
return responseRead.data;
}

if (require.main === module) {
(async () => {
// this module is main i.e. we were started as a server;
// not used in unit test or "require" scenarios
const logger = createLogger(config);

if (config.pm4mlEnabled) {
const controlClient = await ControlAgent.Client.Create({
address: config.control.mgmtAPIWsUrl,
port: config.control.mgmtAPIWsPort,
logger: logger,
appConfig: config,
});
const updatedConfigFromMgmtAPI = await _GetUpdatedConfigFromMgmtAPI(config, logger, controlClient);
logger.isInfoEnabled && logger.push({ updatedConfigFromMgmtAPI }).info('updatedConfigFromMgmtAPI:');
_.merge(config, updatedConfigFromMgmtAPI);
controlClient.terminate();
}
const svr = new Server(config, logger);
svr.on('error', (err) => {
logger.push({ err }).error('Unhandled server error');
process.exit(2);
});

// handle SIGTERM to exit gracefully
process.on('SIGTERM', async () => {
logger.isInfoEnabled && logger.info('SIGTERM received. Shutting down APIs...');
await svr.stop();
process.exit(0);
});

await svr.start().catch(err => {
logger.push({ err }).error('Error starting server');
process.exit(1);
async function start(config) {
const logger = createLogger(config);

if (config.pm4mlEnabled) {
const controlClient = await ControlAgent.Client.Create({
address: config.control.mgmtAPIWsUrl,
port: config.control.mgmtAPIWsPort,
logger: logger,
appConfig: config,
});
const updatedConfigFromMgmtAPI = await _GetUpdatedConfigFromMgmtAPI(config, logger, controlClient);
logger.isInfoEnabled && logger.push({ updatedConfigFromMgmtAPI }).info('updatedConfigFromMgmtAPI:');
_.merge(config, updatedConfigFromMgmtAPI);
controlClient.terminate();
}
const svr = new Server(config, logger);
svr.on('error', (err) => {
logger.push({ err }).error('Unhandled server error');
process.exit(2);
});

// handle SIGTERM to exit gracefully
process.on('SIGTERM', async () => {
logger.isInfoEnabled && logger.info('SIGTERM received. Shutting down APIs...');
await svr.stop();
process.exit(0);
});

await svr.start().catch(err => {
logger.push({ err }).error('Error starting server');
process.exit(1);
});

logger.isInfoEnabled && logger.push({ name, version }).info('SDK server is started!');
}

logger.isInfoEnabled && logger.push({ name, version }).info('SDK server is started!');
})();
if (require.main === module) {
// this module is main i.e. we were started as a server;
// not used in unit test or "require" scenarios
start(config);
}


Expand All @@ -395,4 +397,6 @@ module.exports = {
Server,
Validate,
SDKStateEnum,
start,
config,
};
18 changes: 9 additions & 9 deletions modules/outbound-command-event-handler/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@
"snapshot": "standard-version --no-verify --skip.changelog --prerelease snapshot --releaseCommitMessageFormat 'chore(snapshot): {{currentTag}}'"
},
"dependencies": {
"@mojaloop/api-snippets": "17.7.7",
"@mojaloop/central-services-shared": "^18.14.1",
"@mojaloop/logging-bc-client-lib": "^0.1.17",
"@mojaloop/api-snippets": "17.7.8",
"@mojaloop/central-services-shared": "^18.15.1",
"@mojaloop/logging-bc-client-lib": "^0.5.8",
"@mojaloop/logging-bc-public-types-lib": "^0.5.4",
"@mojaloop/sdk-scheme-adapter-private-shared-lib": "workspace:^",
"ajv": "^8.17.1",
Expand All @@ -56,27 +56,27 @@
"yamljs": "^0.3.0"
},
"devDependencies": {
"@eslint/compat": "^1.2.4",
"@eslint/compat": "^1.2.5",
"@types/convict": "^6.1.6",
"@types/express": "^5.0.0",
"@types/jest": "^29.5.14",
"@types/node": "^22.10.2",
"@types/node": "^22.10.5",
"@types/node-cache": "^4.2.5",
"@types/supertest": "^6.0.2",
"@types/swagger-ui-express": "4.1.7",
"@types/yamljs": "^0.2.34",
"@typescript-eslint/eslint-plugin": "^8.18.0",
"@typescript-eslint/parser": "^8.18.0",
"@typescript-eslint/eslint-plugin": "^8.19.1",
"@typescript-eslint/parser": "^8.19.1",
"copyfiles": "^2.4.1",
"eslint": "^9.15.0",
"jest": "^29.7.0",
"nodemon": "^3.1.7",
"nodemon": "^3.1.9",
"npm-check-updates": "^16.7.10",
"replace": "^1.2.2",
"standard-version": "^9.5.0",
"ts-jest": "^29.2.5",
"ts-node": "^10.9.2",
"typescript": "^5.7.2"
"typescript": "^5.7.3"
},
"nodemonConfig": {
"watch": [
Expand Down
14 changes: 7 additions & 7 deletions modules/outbound-domain-event-handler/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@
"snapshot": "standard-version --no-verify --skip.changelog --prerelease snapshot --releaseCommitMessageFormat 'chore(snapshot): {{currentTag}}'"
},
"dependencies": {
"@mojaloop/api-snippets": "17.7.7",
"@mojaloop/logging-bc-client-lib": "^0.1.17",
"@mojaloop/api-snippets": "17.7.8",
"@mojaloop/logging-bc-client-lib": "^0.5.8",
"@mojaloop/logging-bc-public-types-lib": "^0.5.4",
"@mojaloop/sdk-scheme-adapter-private-shared-lib": "workspace:^",
"convict": "^6.2.4",
Expand All @@ -57,23 +57,23 @@
"@types/convict": "^6.1.6",
"@types/express": "^5.0.0",
"@types/jest": "^29.5.14",
"@types/node": "^22.10.2",
"@types/node": "^22.10.5",
"@types/node-cache": "^4.2.5",
"@types/supertest": "^6.0.2",
"@types/swagger-ui-express": "^4.1.7",
"@types/yamljs": "^0.2.34",
"@typescript-eslint/eslint-plugin": "^8.18.0",
"@typescript-eslint/parser": "^8.18.0",
"@typescript-eslint/eslint-plugin": "^8.19.1",
"@typescript-eslint/parser": "^8.19.1",
"copyfiles": "^2.4.1",
"eslint": "^9.15.0",
"jest": "^29.7.0",
"nodemon": "^3.1.7",
"nodemon": "^3.1.9",
"npm-check-updates": "^16.7.10",
"replace": "^1.2.2",
"standard-version": "^9.5.0",
"ts-jest": "^29.2.5",
"ts-node": "^10.9.2",
"typescript": "^5.7.2"
"typescript": "^5.7.3"
},
"nodemonConfig": {
"watch": [
Expand Down
Loading

0 comments on commit 0763a93

Please sign in to comment.