Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Story #357 cleanup ml-api-adapter project #57

Merged
merged 3 commits into from
Oct 3, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions jsdoc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"tags": {
"allowUnknownTags": true
},
"source": {
"include": [
"src"
],
"includePattern": ".js$",
"excludePattern": "(node_modules/|docs)"
},
"plugins": [
"plugins/markdown"
],
"opts": {
"template": "node_modules/docdash",
"encoding": "utf8",
"destination": "docs/",
"recurse": true,
"verbose": true
},
"markdown": {
"parser": "gfm",
"hardwrap": true
},
"templates": {
"cleverLinks": false,
"monospaceLinks": false,
"default": {
"outputSourceFiles": true,
"includeDate": false
}
},
"docdash": {
"static": false,
"sort": true
}
}
72 changes: 30 additions & 42 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
},
"standard": {
"ignore": [
"/migrations/**"
"/migrations/**",
"/docs/**"
]
},
"scripts": {
Expand All @@ -43,7 +44,8 @@
"docker:build:admin_DONOTRUN": "docker build --no-cache -f admin.Dockerfile -t $npm_package_config_images_admin:latest .",
"docker:stop": "docker-compose -f docker-compose.yml -f docker-compose.dev.yml -f docker-compose.functional.yml stop",
"docker:rm": "docker-compose -f docker-compose.yml -f docker-compose.dev.yml -f docker-compose.functional.yml rm -f -v",
"docker:clean": "docker-compose -f docker-compose.yml -f docker-compose.dev.yml -f docker-compose.functional.yml down --rmi local"
"docker:clean": "docker-compose -f docker-compose.yml -f docker-compose.dev.yml -f docker-compose.functional.yml down --rmi local",
"generate-docs": "node_modules/.bin/jsdoc -c jsdoc.json"
},
"dependencies": {
"@mojaloop/central-services-auth": "0.2.0",
Expand All @@ -52,68 +54,54 @@
"@mojaloop/central-services-shared": "3.1.0-snapshot",
"@mojaloop/forensic-logging-client": "0.5.1",
"@now-ims/hapi-now-auth": "1.0.1",
"argon2": "0.17.1",
"bcrypt": "1.0.3",
"blipp": "3.0.0",
"bluebird": "3.5.0",
"boom": "^7.2.0",
"commander": "^2.16.0",
"continuation-local-storage": "3.2.0",
"deasync-promise": "1.0.1",
"decimal.js": "9.0.1",
"boom": "7.2.0",
"commander": "2.18.0",
"docdash": "1.0.0",
"flat": "4.0.0",
"glob": "7.1.1",
"good": "^8.1.0",
"good-squeeze": "^5.0.2",
"good-winston": "4.0.0",
"hapi": "^17.5.3",
"good": "8.1.1",
"hapi": "17.6.0",
"hapi-auth-basic": "5.0.0",
"hapi-auth-bearer-token": "^6.0.1",
"hapi-auth-bearer-token": "6.1.0",
"hapi-swagger": "9.0.2",
"immutable": "^3.8.2",
"immutable": "3.8.2",
"inert": "5.1.0",
"joi": "13.1.2",
"joi-currency-code": "^1.2.1",
"joi-date-extensions": "^1.2.0",
"json2csv": "3.11.5",
"jsonwebtoken": "8.1.1",
"joi-currency-code": "1.2.1",
"joi-date-extensions": "1.2.0",
"jsdoc": "3.5.5",
"knex": "0.14.2",
"lodash": "4.17.4",
"moment": "2.21.0",
"mustache": "^2.3.0",
"node-gyp": "^3.6.2",
"nodemailer": "4.4.2",
"npm": "^6.3.0",
"mustache": "3.0.0",
"npm": "6.4.1",
"rc": "1.2.5",
"sinon": "^6.3.4",
"sodium": "^2.0.3",
"timplan": "^1.2.0",
"sinon": "6.3.5",
"urlsafe-base64": "1.0.0",
"uuid4": "1.0.0",
"vision": "5.3.1",
"winston": "2.4.0",
"ws": "4.0.0"
"vision": "5.4.0"
},
"optionalDependencies": {
"pg": "7.4.1"
},
"devDependencies": {
"async-request": "^1.2.0",
"async-request": "1.2.0",
"aws-sdk": "2.16.0",
"faucet": "0.0.1",
"istanbul": "^1.1.0-alpha.1",
"jsonpath": "^1.0.0",
"istanbul": "1.1.0-alpha.1",
"jsonpath": "1.0.0",
"mag": "0.9.1",
"mag-hub": "0.1.1",
"npm-run-all": "^4.1.2",
"pre-commit": "1.1.3",
"proxyquire": "1.7.10",
"request": "^2.85.0",
"rewire": "^4.0.1",
"standard": "8.5.0",
"supertest": "2.0.1",
"tap-xunit": "1.4.0",
"tape": "^4.9.1",
"npm-run-all": "4.1.3",
"pre-commit": "1.2.2",
"proxyquire": "2.1.0",
"request": "2.88.0",
"rewire": "4.0.1",
"standard": "11.0.0",
"supertest": "3.3.0",
"tap-xunit": "2.3.0",
"tape": "4.9.1",
"tapes": "4.1.0"
}
}
13 changes: 13 additions & 0 deletions src/api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,19 @@ const Config = require('../lib/config')
const Routes = require('./routes')
const Setup = require('../shared/setup')

/**
* @module src/api/transfers
*/

/**
* @function Initialize
* @async
*
* @description This will initialize the api service by calling Setup.initialize
*
* @returns {object} - Returns the server object on success, throws error if failure occurs
*/

module.exports = Setup.initialize({
service: 'api',
port: Config.PORT,
Expand Down
37 changes: 37 additions & 0 deletions src/api/metadata/handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,21 @@

const Config = require('../../lib/config')

/**
* @module src/api/metadata/handler
*/

/**
* @function ExtractUrls
* @async
*
* @description This function returns the registered URLs on this server
*
* @param {object} request - the http request object
*
* @returns {object} - Returns the object containing all the registered URLs
*/

const extractUrls = (request) => {
const urls = {}
request.server.table()[0].table.filter(route => {
Expand All @@ -14,10 +29,32 @@ const extractUrls = (request) => {
return urls
}

/**
* @function health
* @async
*
* @description This is the handler for /health endpoint
*
* @param {object} request - the http request object
* @param {object} h - the http response object
*
* @returns {object} - Returns the object containing the OK status and 200 status code
*/
exports.health = function (request, h) {
return h.response({ status: 'OK' }).code(200)
}

/**
* @function metadata
* @async
*
* @description This is the handler for / endpoint
*
* @param {object} request - the http request object
* @param {object} h - the http response object
*
* @returns {object} - Returns the object containing the hostname, registered URLs and 200 status code
*/
exports.metadata = function (request, h) {
return h.response({
directory: Config.HOSTNAME,
Expand Down
53 changes: 47 additions & 6 deletions src/api/transfers/handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
optionally within square brackets <email>.
* Gates Foundation
- Name Surname <[email protected]>

- Shashikant Hirugade <[email protected]>
--------------
******/

Expand All @@ -26,21 +28,60 @@ const TransferService = require('../../domain/transfer')
const Logger = require('@mojaloop/central-services-shared').Logger
const Boom = require('boom')

exports.create = async function (request, h) {
/**
* @module src/api/transfers/handler
*/

/**
* @function Create
* @async
*
* @description This will call prepare method of transfer service, which will produce a transfer message on prepare kafka topic
*
* @param {object} request - the http request object, containing headers and transfer request as payload
* @param {objecct} h - the http response object, the response code will be sent using this object methods.
*
* @returns {integer} - Returns the response code 202 on success, throws error if failure occurs
*/

const create = async function (request, h) {
try {
Logger.debug('create::start(%s)', JSON.stringify(request.payload))
Logger.debug('create::payload(%s)', JSON.stringify(request.payload))
Logger.debug('create::headers(%s)', JSON.stringify(request.headers))
await TransferService.prepare(request.headers, request.payload)
return h.response().code(202)
} catch (err) {
throw Boom.boomify(err, {message: 'An error has occurred'})
Logger.error(err)
throw Boom.boomify(err, { message: 'An error has occurred' })
}
}
exports.fulfilTransfer = async function (request, h) {

/**
* @function FulfilTransfer
* @async
*
* @description This will call fulfil method of transfer service, which will produce a transfer fulfil message on fulfil kafka topic
*
* @param {object} request - the http request object, containing headers and transfer fulfilment request as payload. It also contains transferId as param
* @param {objecct} h - the http response object, the response code will be sent using this object methods.
*
* @returns {integer} - Returns the response code 200 on success, throws error if failure occurs
*/

const fulfilTransfer = async function (request, h) {
try {
Logger.debug('fulfilTransfer::start(%s)', JSON.stringify(request.payload))
Logger.debug('fulfilTransfer::payload(%s)', JSON.stringify(request.payload))
Logger.debug('fulfilTransfer::headers(%s)', JSON.stringify(request.headers))
Logger.debug('fulfilTransfer::id(%s)', request.params.id)
await TransferService.fulfil(request.params.id, request.headers, request.payload)
return h.response().code(200)
} catch (err) {
throw Boom.boomify(err, {message: 'An error has occurred'})
Logger.error(err)
throw Boom.boomify(err, { message: 'An error has occurred' })
}
}

module.exports = {
create,
fulfilTransfer
}
9 changes: 8 additions & 1 deletion src/domain/participant/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@

const Logger = require('@mojaloop/central-services-shared').Logger
const Facade = require('../../models/participant/facade')
/**
* @module src/domain/participant
*/

/**
* @function GetEndpoint
Expand All @@ -39,10 +42,14 @@ const Facade = require('../../models/participant/facade')
* @returns {string} - Returns the endpoint, throws error if failure occurs
*/
const getEndpoint = async (fsp, enpointType, transferId = null) => {
Logger.debug(`domain::participant::getEndpoint::fsp - ${fsp}`)
Logger.debug(`domain::participant::getEndpoint::enpointType - ${enpointType}`)
Logger.debug(`domain::participant::getEndpoint::transferId - ${transferId}`)

try {
return Facade.getEndpoint(fsp, enpointType, transferId)
} catch (e) {
Logger.error(e)
Logger.error(`participantEndpointCache::getEndpoint:: ERROR:'${e}'`)
throw e
}
}
Expand Down
10 changes: 9 additions & 1 deletion src/domain/participant/lib/cache/participantEndpoint.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ const policyOptions = Config.ENDPOINT_CACHE_CONFIG
let client
let policy

/**
* @module src/domain/participant/lib/cache
*/

/**
* @function initializeCache
*
Expand All @@ -47,9 +51,11 @@ let policy
const initializeCache = async () => {
Logger.info('participantEndpointCache::initializeCache::start')
try {
Logger.debug(`participantEndpointCache::initializeCache::start::clientOptions - ${clientOptions}`)
client = new Catbox.Client(require('catbox-memory'), clientOptions)
await client.start()
policyOptions.generateFunc = fetchEndpoints
Logger.debug(`participantEndpointCache::initializeCache::start::policyOptions - ${policyOptions}`)
policy = new Catbox.Policy(policyOptions, client, partition)
Logger.info('participantEndpointCache::initializeCache::Cache initialized successfully')
return true
Expand Down Expand Up @@ -88,12 +94,14 @@ const fetchEndpoints = async (id) => {
* @returns {string} - Returns the endpoint, throws error if failure occurs
*/
const getEndpoint = async (fsp, enpointType) => {
Logger.debug(`participantEndpointCache::getEndpoint::fsp - ${fsp}`)
Logger.debug(`participantEndpointCache::getEndpoint::enpointType - ${enpointType}`)
try {
let endpoints = await policy.get(fsp)
let url = new Map(endpoints).get(enpointType)
return url
} catch (e) {
Logger.error(e)
Logger.error(`participantEndpointCache::getEndpoint:: ERROR:'${e}'`)
throw e
}
}
Expand Down
Loading