Skip to content

Commit

Permalink
Merge pull request #23 from mojaloop/ft/core-connector-template
Browse files Browse the repository at this point in the history
feat: core connector template documentation
  • Loading branch information
elijah0kello authored Sep 10, 2024
2 parents 574d133 + 078f31e commit aaa87c2
Show file tree
Hide file tree
Showing 33 changed files with 766 additions and 141 deletions.
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,8 @@
.idea/

# Node
node_modules/
node_modules/

#Environment
dist/
.env
2 changes: 2 additions & 0 deletions .husky/commit-msg
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
#!/bin/bash

npx --no -- commitlint --edit $1
2 changes: 2 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/bin/bash

for dir in */; do
if [[ $dir == *-core-connector/ ]]; then
cd $dir
Expand Down
2 changes: 2 additions & 0 deletions .husky/pre-push
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/bin/bash

for dir in */; do
if [[ $dir == *-core-connector/ ]]; then
cd $dir
Expand Down
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,5 @@ npm i
```

# Building the core connector
To build a new core connector refer to the core connector template guide [here](./TEMPLATE.md) to refactor your newly created connector for the new dfsp

To build a new core connector refer to the core connector template guide [here](./docs/README.md) to refactor your newly created connector for the new dfsp

78 changes: 0 additions & 78 deletions TEMPLATE.md

This file was deleted.

33 changes: 17 additions & 16 deletions airtel-core-connector/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion airtel-core-connector/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
"eslint-plugin-promise": "^6.1.1",
"husky": "^9.0.11",
"jest": "^29.7.0",
"lint-staged": "^15.2.9",
"lint-staged": "^15.2.10",
"nodemon": "^3.0.3",
"npm-check-updates": "^16.14.20",
"npm-run-all": "^4.1.5",
Expand Down
2 changes: 2 additions & 0 deletions core-connector-template/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ DFSP_SERVER_HOST=0.0.0.0
DFSP_SERVER_PORT=3004
SDK_SERVER_HOST=0.0.0.0
SDK_SERVER_PORT=3003
DFSP_API_SPEC_FILE=./src/api-spec/core-connector-api-spec-dfsp.yml
SDK_API_SPEC_FILE=./src/api-spec/core-connector-api-spec-sdk.yml

#Mojaloop Connector
#Do not put the trailing slash on the url
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ paths:
/send-money:
post:
summary: Send Money endpoint
operationId: sendMoney
description: >-
The Endpoint used by the DFSP Operations application to initiate send money
requests to the mojaloop connector
Expand Down Expand Up @@ -76,6 +77,7 @@ paths:
/send-money/{id}:
put:
summary: Confirm send money
operationId: sendMoneyUpdate
parameters:
- name: id
in: path
Expand Down Expand Up @@ -249,7 +251,6 @@ components:
example: "1.10"
expiryDateTime:
type: string
format: date-time
example: "2024-08-01T12:00:00Z"
sendMoneyResponse:
type: object
Expand All @@ -274,7 +275,6 @@ components:
example: "1.10"
expiryDateTime:
type: string
format: date-time
example: "2024-08-01T12:00:00Z"
sendMoneyRequest:
type: object
Expand Down Expand Up @@ -311,7 +311,6 @@ components:
example: "9876543210"
dateOfBirth:
type: string
format: date
example: "1985-04-12"
geoLocationData:
description: >-
Expand Down
19 changes: 17 additions & 2 deletions core-connector-template/src/config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import "dotenv/config";
import Convict from 'convict';
import { TSDKSchemeAdapterConfig } from './domain/SDKClient';
import { TCBSConfig } from "./domain/CBSClient";

interface IConfigSchema {
Expand All @@ -9,8 +8,12 @@ interface IConfigSchema {
SDK_SERVER_PORT: number;
DFSP_SERVER_HOST: string;
DFSP_SERVER_PORT: number;
DFSP_API_SPEC_FILE: string;
SDK_API_SPEC_FILE: string;
};
sdkSchemeAdapter: TSDKSchemeAdapterConfig;
sdkSchemeAdapter: {
SDK_BASE_URL: string;
}
cbs:TCBSConfig;
}

Expand Down Expand Up @@ -40,6 +43,18 @@ const config = Convict<IConfigSchema>({
default: null, // required
env: 'DFSP_SERVER_PORT',
},
DFSP_API_SPEC_FILE: {
doc: 'DFSP operations app Server host',
format: String,
default: null, // required
env: 'DFSP_API_SPEC_FILE',
},
SDK_API_SPEC_FILE: {
doc: 'DFSP operations app Server host',
format: String,
default: null, // required
env: 'SDK_API_SPEC_FILE',
},
},
sdkSchemeAdapter: {
SDK_BASE_URL: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,23 @@ import { Request, ResponseToolkit, ServerRoute } from '@hapi/hapi';
import OpenAPIBackend, { Context } from 'openapi-backend';
import { BaseRoutes } from './BaseRoutes';
import { TCbsSendMoneyRequest, TCBSUpdateSendMoneyRequest } from 'src/domain/CBSClient';
import config from '../config';

const API_SPEC_FILE = './src/api-spec/core-connector-api-spec-dfsp.yml';
const API_SPEC_FILE = config.get("server.DFSP_API_SPEC_FILE");

export class DFSPCoreConnectorRoutes extends BaseRoutes {
private readonly aggregate: CoreConnectorAggregate;
private readonly routes: ServerRoute[] = [];
private readonly logger: ILogger;

// Register openapi spec operationIds and route handler functions here
private readonly handlers = {
sendMoney: this.initiateTransfer.bind(this),
sendMoneyUpdate: this.updateInitiatedTransfer.bind(this),
validationFail: async (context: Context, req: Request, h: ResponseToolkit) => h.response({ error: context.validation.errors }).code(412),
notFound: async (context: Context, req: Request, h: ResponseToolkit) => h.response({ error: 'Not found' }).code(404),
};

constructor(aggregate: CoreConnectorAggregate, logger: ILogger) {
super();
this.aggregate = aggregate;
Expand All @@ -49,12 +58,7 @@ export class DFSPCoreConnectorRoutes extends BaseRoutes {
async init() {
const api = new OpenAPIBackend({
definition: API_SPEC_FILE,
handlers: {
transfers: this.initiateTransfer.bind(this),
updateTransfer: this.updateInitiatedTransfer.bind(this),
validationFail: async (context, req, h) => h.response({ error: context.validation.errors }).code(412),
notFound: async (context, req, h) => h.response({ error: 'Not found' }).code(404),
},
handlers: this.getHandlers(),
});

await api.init();
Expand Down Expand Up @@ -90,6 +94,10 @@ export class DFSPCoreConnectorRoutes extends BaseRoutes {
return this.routes;
}

private getHandlers(){
return this.handlers;
}

private async initiateTransfer(context: Context, request: Request, h: ResponseToolkit) {
const transfer = request.payload as TCbsSendMoneyRequest;
try {
Expand Down
Loading

0 comments on commit aaa87c2

Please sign in to comment.