account-lookup-service 17.4.1-csi-1300.2 → 17.4.1-csi-1300.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/domain/parties/partiesUtils.js +1 -1
- package/src/domain/parties/putParties.js +24 -66
- package/src/domain/parties/services/BasePartiesService.js +6 -0
- package/src/domain/parties/services/PutPartiesErrorService.js +3 -4
- package/src/domain/parties/services/PutPartiesService.js +108 -0
- package/src/domain/parties/services/index.js +2 -0
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "account-lookup-service",
|
3
3
|
"description": "Account Lookup Service is used to validate Party and Participant lookups.",
|
4
|
-
"version": "17.4.1-csi-1300.
|
4
|
+
"version": "17.4.1-csi-1300.3",
|
5
5
|
"license": "Apache-2.0",
|
6
6
|
"author": "ModusBox",
|
7
7
|
"contributors": [
|
@@ -81,7 +81,7 @@ const swapSourceDestinationHeaders = (headers) => {
|
|
81
81
|
}
|
82
82
|
}
|
83
83
|
|
84
|
-
//
|
84
|
+
// todo: check if we need this function
|
85
85
|
const createErrorHandlerOnSendingCallback = (config, logger) => async (err, headers, params, requester) => {
|
86
86
|
try {
|
87
87
|
logger.error('error in sending parties callback: ', err)
|
@@ -29,19 +29,13 @@
|
|
29
29
|
|
30
30
|
'use strict'
|
31
31
|
|
32
|
-
const { Headers
|
33
|
-
const { decodePayload } = require('@mojaloop/central-services-shared').Util.StreamingProtocol
|
34
|
-
const ErrorHandler = require('@mojaloop/central-services-error-handling')
|
32
|
+
const { Headers } = require('@mojaloop/central-services-shared').Enum.Http
|
35
33
|
const Metrics = require('@mojaloop/central-services-metrics')
|
36
34
|
|
37
|
-
const oracle = require('../../models/oracle/facade')
|
38
|
-
const participant = require('../../models/participantEndpoint/facade')
|
39
35
|
const libUtil = require('../../lib/util')
|
40
36
|
const Config = require('../../lib/config')
|
41
37
|
const { logger } = require('../../lib')
|
42
|
-
const { ERROR_MESSAGES } = require('../../constants')
|
43
38
|
|
44
|
-
const partiesUtils = require('./partiesUtils')
|
45
39
|
const services = require('./services')
|
46
40
|
const { createDeps } = require('./deps')
|
47
41
|
|
@@ -59,80 +53,44 @@ const { createDeps } = require('./deps')
|
|
59
53
|
* @param {IProxyCache} [proxyCache] - IProxyCache instance
|
60
54
|
*/
|
61
55
|
const putPartiesByTypeAndID = async (headers, params, method, payload, dataUri, cache, proxyCache = undefined) => {
|
62
|
-
|
56
|
+
// todo: think, if we need to pass span here
|
57
|
+
const component = putPartiesByTypeAndID.name
|
63
58
|
const histTimerEnd = Metrics.getHistogram(
|
64
|
-
|
59
|
+
component,
|
65
60
|
'Put parties by type and id',
|
66
61
|
['success']
|
67
62
|
).startTimer()
|
68
|
-
const
|
63
|
+
// const childSpan = span ? span.getChild(component) : undefined
|
64
|
+
const log = logger.child({ component, params })
|
65
|
+
const stepState = libUtil.initStepState()
|
66
|
+
|
67
|
+
const deps = createDeps({ cache, proxyCache, log, stepState })
|
68
|
+
const service = new services.PutPartiesService(deps)
|
69
|
+
const results = {}
|
70
|
+
|
69
71
|
const source = headers[Headers.FSPIOP.SOURCE]
|
70
72
|
const destination = headers[Headers.FSPIOP.DESTINATION]
|
71
73
|
const proxy = headers[Headers.FSPIOP.PROXY]
|
72
|
-
const proxyEnabled = !!(Config.PROXY_CACHE_CONFIG.enabled && proxyCache)
|
73
74
|
log.info('parties::putPartiesByTypeAndID start', { source, destination, proxy })
|
74
75
|
|
75
|
-
let sendTo
|
76
|
-
let step
|
77
|
-
|
78
76
|
try {
|
79
|
-
|
80
|
-
const requesterParticipant = await participant.validateParticipant(source)
|
81
|
-
if (!requesterParticipant) {
|
82
|
-
if (!proxyEnabled || !proxy) {
|
83
|
-
const errMessage = ERROR_MESSAGES.sourceFspNotFound
|
84
|
-
log.warn(`${errMessage} and no proxy`)
|
85
|
-
throw ErrorHandler.Factory.createFSPIOPError(ErrorHandler.Enums.FSPIOPErrorCodes.ID_NOT_FOUND, errMessage)
|
86
|
-
}
|
87
|
-
step = 'addDfspIdToProxyMapping-1'
|
88
|
-
const isCached = await proxyCache.addDfspIdToProxyMapping(source, proxy)
|
89
|
-
// think,if we should throw error if isCached === false?
|
90
|
-
log.info('addDfspIdToProxyMapping is done', { source, proxy, isCached })
|
91
|
-
}
|
77
|
+
await service.validateSourceParticipant({ source, proxy })
|
92
78
|
|
93
|
-
if (
|
94
|
-
|
95
|
-
step = 'receivedSuccessResponse-2'
|
96
|
-
const isExists = await proxyCache.receivedSuccessResponse(alsReq)
|
97
|
-
if (!isExists) {
|
98
|
-
log.warn('destination is NOT in scheme, and no cached sendToProxiesList', { destination, alsReq })
|
99
|
-
// todo: think, if we need to throw an error here
|
100
|
-
} else {
|
101
|
-
const mappingPayload = {
|
102
|
-
fspId: source
|
103
|
-
}
|
104
|
-
step = 'oracleRequest-3'
|
105
|
-
await oracle.oracleRequest(headers, RestMethods.POST, params, null, mappingPayload, cache)
|
106
|
-
log.info('oracle was updated with mappingPayload', { mappingPayload })
|
107
|
-
}
|
108
|
-
}
|
109
|
-
step = 'validateParticipant-4'
|
110
|
-
const destinationParticipant = await participant.validateParticipant(destination)
|
111
|
-
if (!destinationParticipant) {
|
112
|
-
step = 'lookupProxyByDfspId-5'
|
113
|
-
const proxyName = proxyEnabled && await proxyCache.lookupProxyByDfspId(destination)
|
114
|
-
if (!proxyName) {
|
115
|
-
const errMessage = ERROR_MESSAGES.partyDestinationFspNotFound
|
116
|
-
log.warn(errMessage)
|
117
|
-
throw ErrorHandler.Factory.createFSPIOPError(ErrorHandler.Enums.FSPIOPErrorCodes.DESTINATION_FSP_ERROR, errMessage)
|
118
|
-
}
|
119
|
-
sendTo = proxyName
|
120
|
-
} else {
|
121
|
-
sendTo = destinationParticipant.name
|
79
|
+
if (proxy) {
|
80
|
+
await service.checkProxySuccessResponse({ destination, source, headers, params })
|
122
81
|
}
|
123
82
|
|
124
|
-
const
|
125
|
-
|
126
|
-
|
127
|
-
step = 'sendRequest-6'
|
128
|
-
await participant.sendRequest(headers, sendTo, callbackEndpointType, RestMethods.PUT, decodedPayload.body.toString(), options)
|
83
|
+
const sendTo = await service.identifyDestinationForSuccessCallback(destination)
|
84
|
+
results.requester = sendTo
|
85
|
+
await service.sendSuccessCallback({ sendTo, headers, params, dataUri })
|
129
86
|
|
130
|
-
log.info('
|
87
|
+
log.info('putPartiesByTypeAndID callback was sent', { sendTo })
|
131
88
|
histTimerEnd({ success: true })
|
132
|
-
} catch (
|
133
|
-
const
|
134
|
-
|
135
|
-
|
89
|
+
} catch (error) {
|
90
|
+
const { requester } = results
|
91
|
+
results.fspiopError = await service.handleError({ error, requester, headers, params })
|
92
|
+
if (results.fspiopError) {
|
93
|
+
libUtil.countFspiopError(results.fspiopError, { operation: component, step: stepState.step })
|
136
94
|
}
|
137
95
|
histTimerEnd({ success: false })
|
138
96
|
}
|
@@ -26,6 +26,7 @@
|
|
26
26
|
******/
|
27
27
|
|
28
28
|
const ErrorHandler = require('@mojaloop/central-services-error-handling')
|
29
|
+
const { decodePayload } = require('@mojaloop/central-services-shared').Util.StreamingProtocol
|
29
30
|
const { Enum } = require('@mojaloop/central-services-shared')
|
30
31
|
|
31
32
|
const { FspEndpointTypes, FspEndpointTemplates } = Enum.EndPoints
|
@@ -75,6 +76,11 @@ class BasePartiesService {
|
|
75
76
|
return this.deps.oracle.oracleRequest(headers, RestMethods.DELETE, params, null, null, this.deps.cache)
|
76
77
|
}
|
77
78
|
|
79
|
+
static decodeDataUriPayload (dataUri) {
|
80
|
+
const decoded = decodePayload(dataUri, { asParsed: false })
|
81
|
+
return decoded.body.toString()
|
82
|
+
}
|
83
|
+
|
78
84
|
static enums () {
|
79
85
|
return {
|
80
86
|
FspEndpointTypes,
|
@@ -26,7 +26,6 @@
|
|
26
26
|
******/
|
27
27
|
|
28
28
|
const ErrorHandler = require('@mojaloop/central-services-error-handling')
|
29
|
-
const { decodePayload } = require('@mojaloop/central-services-shared').Util.StreamingProtocol
|
30
29
|
const { ERROR_MESSAGES } = require('../../../constants')
|
31
30
|
const BasePartiesService = require('./BasePartiesService')
|
32
31
|
|
@@ -70,11 +69,11 @@ class PutPartiesErrorService extends BasePartiesService {
|
|
70
69
|
|
71
70
|
async sendErrorCallbackToParticipant ({ sendTo, headers, params, dataUri }) {
|
72
71
|
this.deps.stepState.inProgress('sendErrorToParticipant-5')
|
73
|
-
const
|
74
|
-
|
75
|
-
return super.sendErrorCallback({
|
72
|
+
const errorInfo = PutPartiesErrorService.decodeDataUriPayload(dataUri)
|
73
|
+
await super.sendErrorCallback({
|
76
74
|
sendTo, errorInfo, headers, params
|
77
75
|
})
|
76
|
+
this.log.verbose('sendErrorCallbackToParticipant is done', { sendTo, errorInfo })
|
78
77
|
}
|
79
78
|
}
|
80
79
|
|
@@ -0,0 +1,108 @@
|
|
1
|
+
/*****
|
2
|
+
License
|
3
|
+
--------------
|
4
|
+
Copyright © 2020-2025 Mojaloop Foundation
|
5
|
+
The Mojaloop files are made available by the Mojaloop 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
|
6
|
+
|
7
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
|
9
|
+
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.
|
10
|
+
|
11
|
+
Contributors
|
12
|
+
--------------
|
13
|
+
This is the official list of the Mojaloop project contributors for this file.
|
14
|
+
Names of the original copyright holders (individuals or organizations)
|
15
|
+
should be listed with a '*' in the first column. People who have
|
16
|
+
contributed from an organization can be listed under the organization
|
17
|
+
that actually holds the copyright for their contributions (see the
|
18
|
+
Mojaloop Foundation for an example). Those individuals should have
|
19
|
+
their names indented and be marked with a '-'. Email address can be added
|
20
|
+
optionally within square brackets <email>.
|
21
|
+
|
22
|
+
* Mojaloop Foundation
|
23
|
+
* Eugen Klymniuk <eugen.klymniuk@infitx.com>
|
24
|
+
|
25
|
+
--------------
|
26
|
+
******/
|
27
|
+
|
28
|
+
const ErrorHandler = require('@mojaloop/central-services-error-handling')
|
29
|
+
const { ERROR_MESSAGES } = require('../../../constants')
|
30
|
+
const BasePartiesService = require('./BasePartiesService')
|
31
|
+
|
32
|
+
const { RestMethods } = BasePartiesService.enums()
|
33
|
+
|
34
|
+
class PutPartiesService extends BasePartiesService {
|
35
|
+
async handleRequest () {
|
36
|
+
// todo: add impl.
|
37
|
+
}
|
38
|
+
|
39
|
+
async validateSourceParticipant ({ source, proxy }) {
|
40
|
+
this.deps.stepState.inProgress('validateSourceParticipant-1')
|
41
|
+
const requesterParticipant = await super.validateParticipant(source)
|
42
|
+
|
43
|
+
if (!requesterParticipant) {
|
44
|
+
if (!this.proxyEnabled || !proxy) {
|
45
|
+
const errMessage = ERROR_MESSAGES.sourceFspNotFound
|
46
|
+
this.log.warn(`${errMessage} and no proxy`, { source })
|
47
|
+
throw ErrorHandler.Factory.createFSPIOPError(ErrorHandler.Enums.FSPIOPErrorCodes.ID_NOT_FOUND, errMessage)
|
48
|
+
}
|
49
|
+
const isCached = await this.deps.proxyCache.addDfspIdToProxyMapping(source, proxy)
|
50
|
+
// todo: think,if we should throw error if isCached === false?
|
51
|
+
this.log.info('addDfspIdToProxyMapping is done', { source, proxy, isCached })
|
52
|
+
}
|
53
|
+
}
|
54
|
+
|
55
|
+
async checkProxySuccessResponse ({ destination, source, headers, params }) {
|
56
|
+
if (this.proxyEnabled) {
|
57
|
+
this.deps.stepState.inProgress('checkProxySuccessResponse-2')
|
58
|
+
const alsReq = this.deps.partiesUtils.alsRequestDto(destination, params)
|
59
|
+
|
60
|
+
const isExists = await this.deps.proxyCache.receivedSuccessResponse(alsReq)
|
61
|
+
if (isExists) {
|
62
|
+
await this.#updateOracleWithParticipantMapping({ source, headers, params })
|
63
|
+
return
|
64
|
+
}
|
65
|
+
this.log.warn('destination is NOT in scheme, and no cached sendToProxiesList', { destination, alsReq })
|
66
|
+
// todo: think, if we need to throw an error here
|
67
|
+
}
|
68
|
+
}
|
69
|
+
|
70
|
+
async identifyDestinationForSuccessCallback (destination) {
|
71
|
+
this.deps.stepState.inProgress('validateDestinationParticipant-4')
|
72
|
+
const destinationParticipant = await super.validateParticipant(destination)
|
73
|
+
if (destinationParticipant) {
|
74
|
+
return destinationParticipant.name
|
75
|
+
}
|
76
|
+
|
77
|
+
const proxyName = this.proxyEnabled && await this.deps.proxyCache.lookupProxyByDfspId(destination)
|
78
|
+
if (!proxyName) {
|
79
|
+
const errMessage = ERROR_MESSAGES.partyDestinationFspNotFound
|
80
|
+
this.log.warn(`${errMessage} and no proxy`, { destination })
|
81
|
+
throw ErrorHandler.Factory.createFSPIOPError(ErrorHandler.Enums.FSPIOPErrorCodes.DESTINATION_FSP_ERROR, errMessage)
|
82
|
+
}
|
83
|
+
return proxyName
|
84
|
+
}
|
85
|
+
|
86
|
+
async sendSuccessCallback ({ sendTo, headers, params, dataUri }) {
|
87
|
+
this.deps.stepState.inProgress('#sendSuccessCallback-6')
|
88
|
+
const payload = PutPartiesService.decodeDataUriPayload(dataUri)
|
89
|
+
const callbackEndpointType = this.deps.partiesUtils.putPartyCbType(params.SubId)
|
90
|
+
const options = this.deps.partiesUtils.partiesRequestOptionsDto(params)
|
91
|
+
|
92
|
+
await this.deps.participant.sendRequest(
|
93
|
+
headers, sendTo, callbackEndpointType, RestMethods.PUT, payload, options
|
94
|
+
)
|
95
|
+
this.log.verbose('sendSuccessCallback is done', { sendTo, payload })
|
96
|
+
}
|
97
|
+
|
98
|
+
async #updateOracleWithParticipantMapping ({ source, headers, params }) {
|
99
|
+
this.deps.stepState.inProgress('#updateOracleWithParticipantMapping-3')
|
100
|
+
const mappingPayload = {
|
101
|
+
fspId: source
|
102
|
+
}
|
103
|
+
await this.deps.oracle.oracleRequest(headers, RestMethods.POST, params, null, mappingPayload, this.deps.cache)
|
104
|
+
this.log.info('oracle was updated with mappingPayload', { mappingPayload })
|
105
|
+
}
|
106
|
+
}
|
107
|
+
|
108
|
+
module.exports = PutPartiesService
|
@@ -26,9 +26,11 @@
|
|
26
26
|
******/
|
27
27
|
|
28
28
|
const GetPartiesService = require('./GetPartiesService')
|
29
|
+
const PutPartiesService = require('./PutPartiesService')
|
29
30
|
const PutPartiesErrorService = require('./PutPartiesErrorService')
|
30
31
|
|
31
32
|
module.exports = {
|
32
33
|
GetPartiesService,
|
34
|
+
PutPartiesService,
|
33
35
|
PutPartiesErrorService
|
34
36
|
}
|