Skip to content

Commit

Permalink
refactor: refactor getEndpoint and render (#36)
Browse files Browse the repository at this point in the history
* refactor: refactor getEndpoint and render

* chore: update ambient

* refactor: update function

* chore: update packages
  • Loading branch information
kleyow authored Oct 5, 2020
1 parent 0ac7225 commit 64a810c
Show file tree
Hide file tree
Showing 11 changed files with 654 additions and 901 deletions.
373 changes: 1 addition & 372 deletions ambient.d.ts

Large diffs are not rendered by default.

730 changes: 410 additions & 320 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@
"@mojaloop/central-services-health": "10.6.0",
"@mojaloop/central-services-logger": "10.6.0",
"@mojaloop/central-services-metrics": "9.5.0",
"@mojaloop/central-services-shared": "11.3.4",
"@mojaloop/central-services-shared": "11.4.0",
"@mojaloop/central-services-stream": "10.6.0",
"@mojaloop/event-sdk": "^10.6.0",
"@types/hapi": "^18.0.3",
Expand Down
27 changes: 12 additions & 15 deletions src/domain/consentRequests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
--------------
******/
import { Util as HapiUtil } from '@hapi/hapi'
import Mustache from 'mustache'
import Logger from '@mojaloop/central-services-logger'

import {
Expand Down Expand Up @@ -71,12 +70,12 @@ export async function forwardConsentRequestsIdRequestError (
const endpointType = Enum.EndPoints.FspEndpointTypes.TP_CB_URL_CONSENT_REQUEST_PUT_ERROR

try {
const endpoint = await Util.Endpoints.getEndpoint(
const url = await Util.Endpoints.getEndpointAndRender(
Config.ENDPOINT_SERVICE_URL,
destinationDfspId,
endpointType)
Logger.info(`consentRequest::forwardConsentRequestsRequest - Resolved destinationDfsp endpoint: ${endpointType}to: ${inspect(endpoint)}`)
const url: string = Mustache.render(endpoint + path, { ID: consentRequestsRequestId })
endpointType,
path,
{ ID: consentRequestsRequestId })
Logger.info(`consentRequest::forwardConsentRequestsRequest - Forwarding consentRequest error callback to endpoint: ${url}`)

await Util.Request.sendRequest(
Expand Down Expand Up @@ -129,13 +128,12 @@ export async function forwardConsentRequestsRequest (
const sourceDfspId = headers[Enum.Http.Headers.FSPIOP.SOURCE]
const destinationDfspId = headers[Enum.Http.Headers.FSPIOP.DESTINATION]
try {
const endpoint = await Util.Endpoints.getEndpoint(
const url = await Util.Endpoints.getEndpointAndRender(
Config.ENDPOINT_SERVICE_URL,
destinationDfspId,
endpointType
)
Logger.info(`consentRequest::forwardConsentRequestsRequest - Resolved destination party ${endpointType} endpoint to: ${inspect(endpoint)}`)
const url: string = Mustache.render(endpoint + path, {})
endpointType,
path,
{})
Logger.info(`consentRequest::forwardConsentRequestsRequest - Forwarding consentRequest to endpoint: ${url}`)

await Util.Request.sendRequest(
Expand Down Expand Up @@ -204,13 +202,12 @@ export async function forwardConsentRequestsIdRequest (
const destinationDfspId = headers[Enum.Http.Headers.FSPIOP.DESTINATION]

try {
const endpoint = await Util.Endpoints.getEndpoint(
const url = await Util.Endpoints.getEndpointAndRender(
Config.ENDPOINT_SERVICE_URL,
destinationDfspId,
endpointType
)
Logger.info(`consentRequest::forwardConsentRequestsIdRequest - Resolved destination party ${endpointType} for consentRequest ${consentRequestsRequestId} endpoint to: ${inspect(endpoint)}`)
const url: string = Mustache.render(endpoint + path, { ID: consentRequestsRequestId })
endpointType,
path,
{ ID: consentRequestsRequestId })
Logger.info(`consentRequest::forwardConsentRequestsIdRequest - Forwarding consentRequest to endpoint: ${url}`)

await Util.Request.sendRequest(
Expand Down
18 changes: 8 additions & 10 deletions src/domain/consents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
--------------
******/
import { Util as HapiUtil } from '@hapi/hapi'
import Mustache from 'mustache'
import Logger from '@mojaloop/central-services-logger'

import {
Expand Down Expand Up @@ -70,12 +69,12 @@ export async function forwardConsentsIdRequestError (
const endpointType = Enum.EndPoints.FspEndpointTypes.TP_CB_URL_CONSENT_PUT_ERROR

try {
const endpoint = await Util.Endpoints.getEndpoint(
const url = await Util.Endpoints.getEndpointAndRender(
Config.ENDPOINT_SERVICE_URL,
destinationDfspId,
endpointType)
Logger.info(`consents::forwardConsentsRequestError - Resolved destinationDfsp endpoint: ${endpointType}to: ${inspect(endpoint)}`)
const url: string = Mustache.render(endpoint + path, { ID: consentsId })
endpointType,
path,
{ ID: consentsId })
Logger.info(`consents::forwardConsentsRequestError - Forwarding consents error callback to endpoint: ${url}`)

await Util.Request.sendRequest(
Expand Down Expand Up @@ -128,14 +127,13 @@ export async function forwardConsentsRequest (
const sourceDfspId = headers[Enum.Http.Headers.FSPIOP.SOURCE]
const destinationDfspId = headers[Enum.Http.Headers.FSPIOP.DESTINATION]
try {
const endpoint = await Util.Endpoints.getEndpoint(
const url = await Util.Endpoints.getEndpointAndRender(
Config.ENDPOINT_SERVICE_URL,
destinationDfspId,
endpointType
endpointType,
path
)
Logger.info(`consents::forwardConsentsRequest - Resolved destination party ${endpointType} endpoint to: ${inspect(endpoint)}`)
const url: string = Mustache.render(endpoint + path, {})
Logger.info(`consents::forwardConsentsRequest - Forwarding consents to endpoint: ${url}`)
Logger.info(`consents::forwardConsentsRequestError - Forwarding consents error callback to endpoint: ${url}`)

await Util.Request.sendRequest(
url,
Expand Down
18 changes: 9 additions & 9 deletions src/domain/thirdpartyRequests/authorizations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
******/

import { Util as HapiUtil } from '@hapi/hapi'
import Mustache from 'mustache'
import Logger from '@mojaloop/central-services-logger'

import {
Expand Down Expand Up @@ -70,13 +69,13 @@ export async function forwardAuthorizationRequest(
const sourceDfspId = headers[Enum.Http.Headers.FSPIOP.SOURCE]
const destinationDfspId = headers[Enum.Http.Headers.FSPIOP.DESTINATION]
try {
const endpoint = await Util.Endpoints.getEndpoint(
const url = await Util.Endpoints.getEndpointAndRender(
Config.ENDPOINT_SERVICE_URL,
destinationDfspId,
endpointType
endpointType,
path,
{ ID: transactionRequestId }
)
Logger.info(`authorizations::forwardAuthorizationRequest - Resolved destination party ${endpointType} endpoint for thirdpartyTransaction: ${transactionRequestId} to: ${inspect(endpoint)}`)
const url: string = Mustache.render(endpoint + path, { ID: transactionRequestId })
Logger.info(`authorizations::forwardAuthorizationRequest - Forwarding authorization to endpoint: ${url}`)

await Util.Request.sendRequest(
Expand Down Expand Up @@ -142,12 +141,13 @@ export async function forwardAuthorizationRequestError(path: string,
const endpointType = Enum.EndPoints.FspEndpointTypes.TP_CB_URL_TRANSACTION_REQUEST_AUTH_PUT_ERROR

try {
const endpoint = await Util.Endpoints.getEndpoint(
const url = await Util.Endpoints.getEndpointAndRender(
Config.ENDPOINT_SERVICE_URL,
destinationDfspId,
endpointType)
Logger.info(`authorizations::forwardAuthorizationRequestError - Resolved destinationDfsp endpoint: ${endpointType} for transactionRequest${transactionRequestId} to: ${inspect(endpoint)}`)
const url: string = Mustache.render(endpoint + path, { ID: transactionRequestId })
endpointType,
path,
{ ID: transactionRequestId }
)
Logger.info(`authorizations::forwardAuthorizationRequestError - Forwarding thirdpartyTransaction authorization error callback to endpoint: ${url}`)

await Util.Request.sendRequest(
Expand Down
34 changes: 15 additions & 19 deletions src/domain/thirdpartyRequests/transactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ import {
Util,
RestMethodsEnum
} from '@mojaloop/central-services-shared'
import Mustache from 'mustache'
import Config from '~/shared/config'
import inspect from '~/shared/inspect'
import { getStackOrInspect, finishChildSpan } from '~/shared/util'
Expand Down Expand Up @@ -71,13 +70,13 @@ async function forwardTransactionRequest(
const transactionRequestId: string = (payload && payload.transactionRequestId) || params.ID
const endpointType = Enum.EndPoints.FspEndpointTypes.TP_CB_URL_TRANSACTION_REQUEST_POST
try {
const endpoint = await Util.Endpoints.getEndpoint(
const fullUrl = await Util.Endpoints.getEndpointAndRender(
Config.ENDPOINT_SERVICE_URL,
fspiopDest,
endpointType)
Logger.info(`transactions::forwardTransactionRequest - Resolved PAYER party ${endpointType} endpoint for transactionRequest
${transactionRequestId} to: ${inspect(endpoint)}`)
const fullUrl: string = Mustache.render(endpoint + path, { ID: transactionRequestId })
endpointType,
path,
{}
)
Logger.info(`transactions::forwardTransactionRequest - Forwarding transaction request to endpoint: ${fullUrl}`)
await Util.Request.sendRequest(
fullUrl,
Expand Down Expand Up @@ -142,14 +141,13 @@ async function forwardTransactionRequestError(
const endpointType = Enum.EndPoints.FspEndpointTypes.TP_CB_URL_TRANSACTION_REQUEST_PUT_ERROR

try {
const endpoint = await Util.Endpoints.getEndpoint(
const fullUrl = await Util.Endpoints.getEndpointAndRender(
Config.ENDPOINT_SERVICE_URL,
fspiopDestination,
endpointType)
Logger.info(`transactions::forwardTransactionRequestError - Resolved PAYER party ${endpointType} endpoint for transactionRequest
${transactionRequestId} to: ${inspect(endpoint)}`)

const fullUrl: string = Mustache.render(endpoint + path, { ID: transactionRequestId })
endpointType,
path,
{ ID: transactionRequestId }
)
Logger.info(`transactions::forwardTransactionRequestError - Forwarding transaction request error to endpoint: ${fullUrl}`)

await Util.Request.sendRequest(
Expand Down Expand Up @@ -202,15 +200,13 @@ async function forwardTransactionRequestNotification(
const decodedPayload: object = Util.StreamingProtocol.decodePayload(payload, { asParsed: true })

try {
const endpoint = await Util.Endpoints.getEndpoint(
const fullUrl = await Util.Endpoints.getEndpointAndRender(
Config.ENDPOINT_SERVICE_URL,
fspiopDestination,
endpointType)
Logger.info(`transactions::forwardTransactionRequestNotification -
Resolved PISP party ${endpointType} endpoint for transactionRequest
${transactionRequestId} to: ${inspect(endpoint)}`)

const fullUrl: string = Mustache.render(endpoint + path, { ID: transactionRequestId })
endpointType,
path,
{ ID: transactionRequestId }
)
Logger.info(`transactions::forwardTransactionRequestNotification -
Forwarding transaction request to endpoint: ${fullUrl}`)

Expand Down
Loading

0 comments on commit 64a810c

Please sign in to comment.