Skip to content
Draft
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
2 changes: 1 addition & 1 deletion audit-ci.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// Only use one of ["low": true, "moderate": true, "high": true, "critical": true]
"moderate": true,
"allowlist": [
// dev dependencies our third party dependencies use
// dev dependencies
"GHSA-v88g-cgmw-v5xw",
"GHSA-93q8-gq69-wqmw",
"GHSA-phwq-j96m-2c2q",
Expand Down
56 changes: 38 additions & 18 deletions package-lock.json

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

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "sims",
"version": "12.1.0",
"version": "12.2.1-snapshot.1",
"description": "A super-simple fsp simulator",
"main": "src/index.js",
"author": "ModusBox",
Expand Down Expand Up @@ -51,7 +51,7 @@
"@mojaloop/central-services-shared": "18.2.0",
"@mojaloop/event-sdk": "^14.0.0",
"@mojaloop/sdk-standard-components": "17.1.3",
"axios": "1.6.2",
"axios": "1.6.4",
"base64url": "3.0.1",
"blipp": "4.0.2",
"glob": "10.3.10",
Expand Down
134 changes: 134 additions & 0 deletions src/backend/handler.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
/*****
License
--------------
Copyright © 2017 Bill & Melinda Gates Foundation
The Mojaloop files are made available by the Bill & Melinda Gates Foundation under the Apache License, Version 2.0 (the "License") and you may not use these files except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, the Mojaloop files are distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Contributors
--------------
This is the official list of the Mojaloop project contributors for this file.
Names of the original copyright holders (individuals or organizations)
should be listed with a '*' in the first column. People who have
contributed from an organization can be listed under the organization
that actually holds the copyright for their contributions (see the
Gates Foundation organization for an example). Those individuals should have
their names indented and be marked with a '-'. Email address can be added
optionally within square brackets <email>.
* Gates Foundation
- Aaron Reynoza <[email protected]>
--------------
******/

'use strict'
const NodeCache = require('node-cache')
const requestCache = new NodeCache()
const Logger = require('@mojaloop/central-services-logger')
const Enums = require('@mojaloop/central-services-shared').Enum
const Metrics = require('../lib/metrics')

const transfersFulfilResponseDisabled = (process.env.TRANSFERS_FULFIL_RESPONSE_DISABLED !== undefined && process.env.TRANSFERS_FULFIL_RESPONSE_DISABLED !== 'false')

exports.postQuoteRequest = function (req, h) {
const histTimerEnd = Metrics.getHistogram(
'sim_request',
'Histogram for Simulator http operations',
['success', 'fsp', 'operation', 'source', 'destination']
).startTimer()

const metadata = `${req.method} ${req.path}`
const quotesRequest = req.payload
Logger.isInfoEnabled && Logger.info((new Date().toISOString()), ['IN /backend/quoteRequest::'], `received: ${metadata}. `)
Logger.isInfoEnabled && Logger.info(`incoming request: ${quotesRequest.quoteId}`)

// Saving Incoming request
const incomingRequest = {
headers: req.headers,
data: req.payload
}
requestCache.set(quotesRequest.quoteId, incomingRequest)

const quotesResponse = {
payeeFspCommissionAmount: quotesRequest.feesCurrency,
payeeFspCommissionAmountCurrency: quotesRequest.feesCurrency,
payeeFspFeeAmount: quotesRequest.feesAmount,
payeeFspFeeAmountCurrency: quotesRequest.feesCurrency,
// Fee currency and currency should be the same in order to have the right value
payeeReceiveAmount: (Number(quotesRequest.amount) - Number(quotesRequest.feesAmount)),
payeeReceiveAmountCurrency: quotesRequest.currency,
quoteId: quotesRequest.quoteId,
transactionId: quotesRequest.transactionId,
transferAmount: quotesRequest.amount,
transferAmountCurrency: quotesRequest.currency,
expiration: new Date(new Date().getTime() + 10000)
}

histTimerEnd({ success: true, fsp: req.headers['fspiop-destination'], operation: 'postQuoteRequest', source: req.headers['fspiop-source'], destination: req.headers['fspiop-destination'] })
return h.response(quotesResponse).code(Enums.Http.ReturnCodes.ACCEPTED.CODE)
}

exports.putQuotes = function (req, h) {
return h.response().code(Enums.Http.ReturnCodes.ACCEPTED.CODE)
}

exports.postTransfers = async function (req, h) {
const histTimerEnd = Metrics.getHistogram(
'sim_request',
'Histogram for Simulator http operations',
['success', 'fsp', 'operation', 'source', 'destination']
).startTimer()

Logger.isDebugEnabled && Logger.debug(`[cid=${req.payload.transferId}, fsp=${req.headers['fspiop-source']}, source=${req.headers['fspiop-source']}, dest=${req.headers['fspiop-destination']}] ~ Simulator::api::payee::postTransfers - START`)

const metadata = `${req.method} ${req.path} ${req.payload.transferId}`
Logger.isInfoEnabled && Logger.info(`IN backend/transfers:: received: ${metadata}.`)

const quotesResponse = {
completedTimestamp: new Date(new Date().getTime() + 10000),
fulfilment: 'string',
homeTransactionId: req.payload.homeR2PTransactionId,
transferState: 'RECEIVED'
}

if (!transfersFulfilResponseDisabled) {
// Saving Incoming request
const incomingRequest = {
headers: req.headers,
data: req.payload
}
requestCache.set(req.payload.transferId, incomingRequest)

histTimerEnd({
success: true,
fsp: req.headers['fspiop-destination'],
operation: 'postTransfers',
source: req.headers['fspiop-source'],
destination: req.headers['fspiop-destination']
})
} else {
// Logger.isPerfEnabled && Logger.perf(`[cid=${req.payload.transferId}, fsp=${req.headers['fspiop-source']}, source=${req.headers['fspiop-source']}, dest=${req.headers['fspiop-destination']}] ~ Simulator::api::payee::postTransfers - END`)
histTimerEnd({
success: true,
fsp: req.headers['fspiop-destination'],
operation: 'postTransfers',
source: req.headers['fspiop-source'],
destination: req.headers['fspiop-destination']
})
}

return h.response(quotesResponse).code(Enums.Http.ReturnCodes.ACCEPTED.CODE)
}

exports.putTransfers = function (req, h) {
return h.response().code(Enums.Http.ReturnCodes.ACCEPTED.CODE)
}

exports.getPartiesByTypeAndId = function (req, h) {
return h.response({
fspId: 'string'
}).code(Enums.Http.ReturnCodes.ACCEPTED.CODE)
}

exports.putPartiesByTypeAndId = function (req, h) {
return h.response().code(Enums.Http.ReturnCodes.ACCEPTED.CODE)
}
89 changes: 89 additions & 0 deletions src/backend/routes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/*****
License
--------------
Copyright © 2017 Bill & Melinda Gates Foundation
The Mojaloop files are made available by the Bill & Melinda Gates Foundation under the Apache License, Version 2.0 (the "License") and you may not use these files except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, the Mojaloop files are distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Contributors
--------------
This is the official list of the Mojaloop project contributors for this file.
Names of the original copyright holders (individuals or organizations)
should be listed with a '*' in the first column. People who have
contributed from an organization can be listed under the organization
that actually holds the copyright for their contributions (see the
Gates Foundation organization for an example). Those individuals should have
their names indented and be marked with a '-'. Email address can be added
optionally within square brackets <email>.

* Gates Foundation
- Aaron Reynoza <[email protected]>
--------------
******/

const Handler = require('./handler')
const Enum = require('@mojaloop/central-services-shared').Enum
const tags = ['api', 'metadata', Enum.Tags.RouteTags.SAMPLED]

module.exports = [
{
method: 'POST',
path: '/backend/quoterequests',
handler: Handler.postQuoteRequest,
options: {
id: `simulator_${__dirname.split('/').pop()}_postQuoteRequest`,
tags,
description: 'Metadata'
}
},
{
method: 'PUT',
path: '/backend/quotes/{id}',
handler: Handler.putQuotes,
options: {
id: `simulator_${__dirname.split('/').pop()}_putQuotes`,
tags,
description: 'Metadata'
}
},
{
method: 'POST',
path: '/backend/transfers',
handler: Handler.postTransfers,
options: {
id: `simulator_${__dirname.split('/').pop()}_postTransfers`,
tags,
description: 'Metadata'
}
},
{
method: 'PUT',
path: '/backend/transfers/{id}',
handler: Handler.putTransfers,
options: {
id: `simulator_${__dirname.split('/').pop()}_putTransfers`,
tags,
description: 'Metadata'
}
},
{
method: 'GET',
path: '/backend/parties/{type}/{id}',
handler: Handler.getPartiesByTypeAndId,
options: {
id: `simulator_${__dirname.split('/').pop()}_getParty`,
tags,
description: 'Metadata'
}
},
{
method: 'PUT',
path: '/backend/parties/{type}/{id}',
handler: Handler.putPartiesByTypeAndId,
options: {
id: `simulator_${__dirname.split('/').pop()}_putParty`,
tags,
description: 'Metadata'
}
}
]