account-lookup-service 17.4.1-csi-1300.2 → 17.4.1-csi-1300.4
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/getPartiesByTypeAndID.js +1 -1
- package/src/domain/parties/partiesUtils.js +1 -1
- package/src/domain/parties/putParties.js +30 -75
- package/src/domain/parties/services/BasePartiesService.js +11 -4
- package/src/domain/parties/services/PutPartiesErrorService.js +4 -6
- 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.4",
|
5
5
|
"license": "Apache-2.0",
|
6
6
|
"author": "ModusBox",
|
7
7
|
"contributors": [
|
@@ -26,8 +26,8 @@
|
|
26
26
|
const Metrics = require('@mojaloop/central-services-metrics')
|
27
27
|
const libUtil = require('../../lib/util')
|
28
28
|
const { logger } = require('../../lib')
|
29
|
-
const { GetPartiesService } = require('./services')
|
30
29
|
const { createDeps } = require('./deps')
|
30
|
+
const { GetPartiesService } = require('./services')
|
31
31
|
|
32
32
|
/**
|
33
33
|
* @function getPartiesByTypeAndID
|
@@ -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,21 +29,12 @@
|
|
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
|
-
|
37
|
-
const oracle = require('../../models/oracle/facade')
|
38
|
-
const participant = require('../../models/participantEndpoint/facade')
|
39
34
|
const libUtil = require('../../lib/util')
|
40
|
-
const Config = require('../../lib/config')
|
41
35
|
const { logger } = require('../../lib')
|
42
|
-
const { ERROR_MESSAGES } = require('../../constants')
|
43
|
-
|
44
|
-
const partiesUtils = require('./partiesUtils')
|
45
|
-
const services = require('./services')
|
46
36
|
const { createDeps } = require('./deps')
|
37
|
+
const services = require('./services')
|
47
38
|
|
48
39
|
/**
|
49
40
|
* @function putPartiesByTypeAndID
|
@@ -59,80 +50,44 @@ const { createDeps } = require('./deps')
|
|
59
50
|
* @param {IProxyCache} [proxyCache] - IProxyCache instance
|
60
51
|
*/
|
61
52
|
const putPartiesByTypeAndID = async (headers, params, method, payload, dataUri, cache, proxyCache = undefined) => {
|
62
|
-
|
53
|
+
// todo: think, if we need to pass span here
|
54
|
+
const component = putPartiesByTypeAndID.name
|
63
55
|
const histTimerEnd = Metrics.getHistogram(
|
64
|
-
|
56
|
+
component,
|
65
57
|
'Put parties by type and id',
|
66
58
|
['success']
|
67
59
|
).startTimer()
|
68
|
-
const
|
60
|
+
// const childSpan = span ? span.getChild(component) : undefined
|
61
|
+
const log = logger.child({ component, params })
|
62
|
+
const stepState = libUtil.initStepState()
|
63
|
+
|
64
|
+
const deps = createDeps({ cache, proxyCache, log, stepState })
|
65
|
+
const service = new services.PutPartiesService(deps)
|
66
|
+
const results = {}
|
67
|
+
|
69
68
|
const source = headers[Headers.FSPIOP.SOURCE]
|
70
69
|
const destination = headers[Headers.FSPIOP.DESTINATION]
|
71
70
|
const proxy = headers[Headers.FSPIOP.PROXY]
|
72
|
-
|
73
|
-
log.info('parties::putPartiesByTypeAndID start', { source, destination, proxy })
|
74
|
-
|
75
|
-
let sendTo
|
76
|
-
let step
|
71
|
+
log.info('putPartiesByTypeAndID start', { source, destination, proxy })
|
77
72
|
|
78
73
|
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
|
-
}
|
74
|
+
await service.validateSourceParticipant({ source, proxy })
|
92
75
|
|
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
|
76
|
+
if (proxy) {
|
77
|
+
await service.checkProxySuccessResponse({ destination, source, headers, params })
|
122
78
|
}
|
123
79
|
|
124
|
-
const
|
125
|
-
|
126
|
-
|
127
|
-
step = 'sendRequest-6'
|
128
|
-
await participant.sendRequest(headers, sendTo, callbackEndpointType, RestMethods.PUT, decodedPayload.body.toString(), options)
|
80
|
+
const sendTo = await service.identifyDestinationForSuccessCallback(destination)
|
81
|
+
results.requester = sendTo
|
82
|
+
await service.sendSuccessCallback({ sendTo, headers, params, dataUri })
|
129
83
|
|
130
|
-
log.info('
|
84
|
+
log.info('putPartiesByTypeAndID callback was sent', { sendTo })
|
131
85
|
histTimerEnd({ success: true })
|
132
|
-
} catch (
|
133
|
-
const
|
134
|
-
|
135
|
-
|
86
|
+
} catch (error) {
|
87
|
+
const { requester } = results
|
88
|
+
results.fspiopError = await service.handleError({ error, requester, headers, params })
|
89
|
+
if (results.fspiopError) {
|
90
|
+
libUtil.countFspiopError(results.fspiopError, { operation: component, step: stepState.step })
|
136
91
|
}
|
137
92
|
histTimerEnd({ success: false })
|
138
93
|
}
|
@@ -167,12 +122,12 @@ const putPartiesErrorByTypeAndID = async (headers, params, payload, dataUri, spa
|
|
167
122
|
const results = {}
|
168
123
|
|
169
124
|
const destination = headers[Headers.FSPIOP.DESTINATION]
|
170
|
-
const
|
171
|
-
const
|
172
|
-
log.info('
|
125
|
+
const proxy = headers[Headers.FSPIOP.PROXY]
|
126
|
+
const proxyEnabled = !!(deps.config.PROXY_CACHE_CONFIG.enabled && proxyCache)
|
127
|
+
log.info('putPartiesErrorByTypeAndID start', { destination, proxy, proxyEnabled })
|
173
128
|
|
174
129
|
try {
|
175
|
-
if (proxy) {
|
130
|
+
if (proxyEnabled && proxy) {
|
176
131
|
const notValid = await service.checkPayee({ headers, params, payload, proxy })
|
177
132
|
if (notValid) {
|
178
133
|
const getPartiesService = new services.GetPartiesService(deps)
|
@@ -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
|
@@ -38,9 +39,9 @@ class BasePartiesService {
|
|
38
39
|
this.proxyEnabled = !!(deps.config.PROXY_CACHE_CONFIG?.enabled && deps.proxyCache)
|
39
40
|
}
|
40
41
|
|
41
|
-
async handleRequest () {
|
42
|
-
|
43
|
-
}
|
42
|
+
// async handleRequest () {
|
43
|
+
// throw new Error('handleRequest must be implemented by subclass')
|
44
|
+
// }
|
44
45
|
|
45
46
|
async handleError ({ error, requester, headers, params }) {
|
46
47
|
const log = this.log.child({ method: 'handleError' })
|
@@ -66,15 +67,21 @@ class BasePartiesService {
|
|
66
67
|
|
67
68
|
async sendErrorCallback ({ sendTo, errorInfo, headers, params, payload = undefined }) {
|
68
69
|
const endpointType = this.deps.partiesUtils.errorPartyCbType(params.SubId)
|
69
|
-
|
70
|
+
await this.deps.participant.sendErrorToParticipant(
|
70
71
|
sendTo, endpointType, errorInfo, headers, params, payload, this.deps.childSpan
|
71
72
|
)
|
73
|
+
this.log.verbose('sendErrorCallback is done', { sendTo, errorInfo })
|
72
74
|
}
|
73
75
|
|
74
76
|
async sendDeleteOracleRequest (headers, params) {
|
75
77
|
return this.deps.oracle.oracleRequest(headers, RestMethods.DELETE, params, null, null, this.deps.cache)
|
76
78
|
}
|
77
79
|
|
80
|
+
static decodeDataUriPayload (dataUri) {
|
81
|
+
const decoded = decodePayload(dataUri, { asParsed: false })
|
82
|
+
return decoded.body.toString()
|
83
|
+
}
|
84
|
+
|
78
85
|
static enums () {
|
79
86
|
return {
|
80
87
|
FspEndpointTypes,
|
@@ -26,14 +26,13 @@
|
|
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
|
|
33
32
|
class PutPartiesErrorService extends BasePartiesService {
|
34
|
-
async handleRequest () {
|
35
|
-
|
36
|
-
}
|
33
|
+
// async handleRequest () {
|
34
|
+
// // todo: add impl.
|
35
|
+
// }
|
37
36
|
|
38
37
|
async checkPayee ({ headers, params, payload, proxy }) {
|
39
38
|
const notValid = this.deps.partiesUtils.isNotValidPayeeCase(payload)
|
@@ -70,8 +69,7 @@ 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
|
-
const errorInfo = decodedPayload.body.toString()
|
72
|
+
const errorInfo = PutPartiesErrorService.decodeDataUriPayload(dataUri)
|
75
73
|
return super.sendErrorCallback({
|
76
74
|
sendTo, errorInfo, headers, params
|
77
75
|
})
|
@@ -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
|
}
|