Skip to content

Commit

Permalink
fix: fx notify (#544)
Browse files Browse the repository at this point in the history
* fix: fx notify

* fix: lint

* fix: refactor

* fix: lint

* fix: refactor

* fix: int tests

* fix: content type

* chore(snapshot): 14.1.0-snapshot.24

* chore(snapshot): 14.1.0-snapshot.25
  • Loading branch information
vijayg10 authored Oct 9, 2024
1 parent d25044f commit ba9a896
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 22 deletions.
55 changes: 42 additions & 13 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": "@mojaloop/ml-api-adapter",
"version": "14.1.0-snapshot.23",
"version": "14.1.0-snapshot.25",
"description": "Convert from ML API to/from internal Central Services messaging format",
"license": "Apache-2.0",
"private": true,
Expand Down Expand Up @@ -85,7 +85,7 @@
"@mojaloop/central-services-shared": "18.9.0",
"@mojaloop/central-services-stream": "11.3.1",
"@mojaloop/event-sdk": "14.1.1",
"@mojaloop/sdk-standard-components": "18.4.1",
"@mojaloop/sdk-standard-components": "19.0.0",
"@now-ims/hapi-now-auth": "2.1.0",
"axios": "1.7.7",
"blipp": "4.0.2",
Expand Down
20 changes: 15 additions & 5 deletions src/handlers/notification/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -625,7 +625,7 @@ const processMessage = async (msg, span) => {
return true
}

if ([Action.FX_NOTIFY].includes(action)) {
if (action === Action.FX_NOTIFY) {
if (!isSuccess) {
throw ErrorHandler.Factory.createFSPIOPError(
ErrorHandler.Enums.FSPIOPErrorCodes.INTERNAL_SERVER_ERROR,
Expand All @@ -635,17 +635,27 @@ const processMessage = async (msg, span) => {

const { url: callbackURLTo } = await getEndpointFn(destination, REQUEST_TYPE.PATCH, true)
const endpointTemplate = getEndpointTemplate(REQUEST_TYPE.PATCH)
headers = createCallbackHeaders({ headers: content.headers, httpMethod: PATCH, endpointTemplate })
logger.debug(`Notification::processMessage - Callback.sendRequest({ ${callbackURLTo}, ${PATCH}, ${JSON.stringify(content.headers)}, ${payload}, ${id}, ${source}, ${destination} ${hubNameRegex} })`)

let payloadForFXP = JSON.parse(payload)
if (payloadForFXP.fulfilment) {
delete payloadForFXP.fulfilment
}
payloadForFXP = JSON.stringify(payloadForFXP)
const method = PATCH
headers = createCallbackHeaders({ dfspId: destination, transferId: id, headers: content.headers, httpMethod: method, endpointTemplate }, fromSwitch)
headers['content-type'] = `application/vnd.interoperability.fxTransfers+json;version=${Util.resourceVersions[Enum.Http.HeaderResources.FX_TRANSFERS].contentVersion}`

logger.debug(`Notification::processMessage - Callback.sendRequest({ ${callbackURLTo}, ${method}, ${JSON.stringify(headers)}, ${payloadForFXP}, ${id}, ${Config.HUB_NAME}, ${source} ${hubNameRegex} })`)
let response = { status: 'unknown' }
const histTimerEndSendRequest = Metrics.getHistogram(
'notification_event_delivery',
'notification_event_delivery - metric for sending notification requests to FSPs',
['success', 'from', 'to', 'dest', 'action', 'status']
['success', 'from', 'dest', 'action', 'status']
).startTimer()

try {
response = await Callback.sendRequest({ url: callbackURLTo, headers, source, destination, method: PATCH, payload, responseType, span, protocolVersions, hubNameRegex })
jwsSigner = getJWSSigner(Config.HUB_NAME)
response = await Callback.sendRequest({ url: callbackURLTo, headers, source, destination, method, payload: payloadForFXP, responseType, span, jwsSigner, protocolVersions, hubNameRegex })
} catch (err) {
logger.error(err)
histTimerEndSendRequest({ success: false, from: source, dest: destination, action, status: response.status })
Expand Down
9 changes: 7 additions & 2 deletions test/integration/handlers/notification/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1500,7 +1500,10 @@ Test('Notification Handler', notificationHandlerTest => {

const response = await testNotification(messageProtocol, 'patch', commitRequestId, kafkaConfig, topicConfig)

test.deepEqual(response.payload, messageProtocol.content.payload, 'Notification sent successfully to FXP')
const payloadWithoutFulfilment = JSON.parse(JSON.stringify(messageProtocol.content.payload))
delete payloadWithoutFulfilment.fulfilment

test.deepEqual(response.payload, payloadWithoutFulfilment, 'Notification sent successfully to FXP')
test.end()
})

Expand All @@ -1525,7 +1528,9 @@ Test('Notification Handler', notificationHandlerTest => {

const response = await testNotification(messageProtocol, 'patch', commitRequestId, kafkaConfig, topicConfig, undefined, undefined, 'proxyFsp')

test.deepEqual(response.payload, messageProtocol.content.payload, 'Notification sent successfully to FXP')
const payloadWithoutFulfilment = JSON.parse(JSON.stringify(messageProtocol.content.payload))
delete payloadWithoutFulfilment.fulfilment
test.deepEqual(response.payload, payloadWithoutFulfilment, 'Notification sent successfully to FXP')
test.end()
})

Expand Down

0 comments on commit ba9a896

Please sign in to comment.