account-lookup-service 17.8.0-snapshot.17 → 17.8.0-snapshot.19
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/constants.js +1 -0
- package/src/domain/parties/putParties.js +1 -9
- package/src/domain/parties/services/BasePartiesService.js +13 -3
- package/src/domain/parties/services/PutPartiesErrorService.js +22 -6
- package/src/handlers/index.js +3 -3
- package/test/unit/domain/parties/parties.test.js +10 -7
- package/test/unit/domain/parties/services/PutPartiesErrorService.test.js +12 -7
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.8.0-snapshot.
|
4
|
+
"version": "17.8.0-snapshot.19",
|
5
5
|
"license": "Apache-2.0",
|
6
6
|
"author": "ModusBox",
|
7
7
|
"contributors": [
|
package/src/constants.js
CHANGED
@@ -29,6 +29,7 @@ const { API_TYPES } = require('@mojaloop/central-services-shared').Util.Hapi
|
|
29
29
|
|
30
30
|
const ERROR_MESSAGES = Object.freeze({
|
31
31
|
emptyFilteredPartyList: 'Empty oracle partyList, filtered based on callbackEndpointType',
|
32
|
+
externalPartyError: 'External party error', // todo: think better message
|
32
33
|
failedToCacheSendToProxiesList: 'Failed to cache sendToProxiesList',
|
33
34
|
noDiscoveryRequestsForwarded: 'No discovery requests forwarded to participants',
|
34
35
|
sourceFspNotFound: 'Requester FSP not found',
|
@@ -97,15 +97,7 @@ const putPartiesErrorByTypeAndID = async (headers, params, payload, dataUri, spa
|
|
97
97
|
let fspiopError
|
98
98
|
|
99
99
|
try {
|
100
|
-
|
101
|
-
if (needDiscovery) {
|
102
|
-
const getPartiesService = new services.GetPartiesService(deps, inputs)
|
103
|
-
await getPartiesService.triggerInterSchemeDiscoveryFlow(
|
104
|
-
services.GetPartiesService.headersWithoutDestination(headers)
|
105
|
-
)
|
106
|
-
// think, if we need to start the whole processing with getPartiesService.handleRequest() ?
|
107
|
-
}
|
108
|
-
|
100
|
+
await service.handleRequest()
|
109
101
|
logger.info('putPartiesErrorByTypeAndID is done')
|
110
102
|
histTimerEnd({ success: true })
|
111
103
|
} catch (error) {
|
@@ -156,7 +156,7 @@ class BasePartiesService {
|
|
156
156
|
|
157
157
|
async sendErrorCallback ({ errorInfo, headers, params }) {
|
158
158
|
this.stepInProgress('sendErrorCallback')
|
159
|
-
const sendTo = this.state.requester || this.state.source
|
159
|
+
const sendTo = this.state.requester || headers[Headers.FSPIOP.DESTINATION] /* || this.state.source */
|
160
160
|
const endpointType = this.deps.partiesUtils.errorPartyCbType(params.SubId)
|
161
161
|
|
162
162
|
await this.deps.participant.sendErrorToParticipant(
|
@@ -171,6 +171,7 @@ class BasePartiesService {
|
|
171
171
|
}
|
172
172
|
|
173
173
|
async removeProxyGetPartiesTimeoutCache (alsReq) {
|
174
|
+
this.stepInProgress('removeProxyGetPartiesTimeoutCache')
|
174
175
|
const isRemoved = await this.deps.proxyCache.removeProxyGetPartiesTimeout(alsReq, this.state.proxy)
|
175
176
|
this.log.debug('removeProxyGetPartiesTimeoutCache is done', { isRemoved, alsReq })
|
176
177
|
return isRemoved
|
@@ -186,6 +187,11 @@ class BasePartiesService {
|
|
186
187
|
return ErrorHandler.Factory.createFSPIOPError(ErrorHandler.Enums.FSPIOPErrorCodes.PARTY_NOT_FOUND, errMessage)
|
187
188
|
}
|
188
189
|
|
190
|
+
createFspiopServiceUnavailableError (errMessage, log = this.log) {
|
191
|
+
log.warn(errMessage)
|
192
|
+
return ErrorHandler.Factory.createFSPIOPError(ErrorHandler.Enums.FSPIOPErrorCodes.SERVICE_CURRENTLY_UNAVAILABLE, errMessage)
|
193
|
+
}
|
194
|
+
|
189
195
|
stepInProgress (stepName) {
|
190
196
|
this.log.debug('step is in progress', { stepName })
|
191
197
|
this.state.stepState?.inProgress(stepName)
|
@@ -225,8 +231,8 @@ class BasePartiesService {
|
|
225
231
|
}
|
226
232
|
}
|
227
233
|
|
228
|
-
static createErrorCallbackHeaders (headers, params) {
|
229
|
-
|
234
|
+
static createErrorCallbackHeaders (headers, params, overrideDestination = '') {
|
235
|
+
const cbHeaders = createCallbackHeaders({
|
230
236
|
requestHeaders: headers,
|
231
237
|
partyIdType: params.Type,
|
232
238
|
partyIdentifier: params.ID,
|
@@ -234,6 +240,10 @@ class BasePartiesService {
|
|
234
240
|
? FspEndpointTemplates.PARTIES_SUB_ID_PUT_ERROR
|
235
241
|
: FspEndpointTemplates.PARTIES_PUT_ERROR
|
236
242
|
})
|
243
|
+
if (overrideDestination) {
|
244
|
+
cbHeaders[Headers.FSPIOP.DESTINATION] = overrideDestination
|
245
|
+
}
|
246
|
+
return cbHeaders
|
237
247
|
}
|
238
248
|
|
239
249
|
static createHubErrorCallbackHeaders (hubName, destination) {
|
@@ -26,9 +26,9 @@
|
|
26
26
|
******/
|
27
27
|
|
28
28
|
const BasePartiesService = require('./BasePartiesService')
|
29
|
+
const { ERROR_MESSAGES } = require('../../../constants')
|
29
30
|
|
30
31
|
class PutPartiesErrorService extends BasePartiesService {
|
31
|
-
/** @returns {Promise<true | undefined>} - If true, need to trigger inter-scheme discovery. */
|
32
32
|
async handleRequest () {
|
33
33
|
if (this.state.proxyEnabled && this.state.proxy) {
|
34
34
|
const alsReq = this.deps.partiesUtils.alsRequestDto(this.state.destination, this.inputs.params) // or source?
|
@@ -37,23 +37,24 @@ class PutPartiesErrorService extends BasePartiesService {
|
|
37
37
|
if (isInterSchemeDiscoveryCase) {
|
38
38
|
const isLast = await this.checkLastProxyCallback(alsReq)
|
39
39
|
if (!isLast) {
|
40
|
-
this.log.verbose('
|
40
|
+
this.log.verbose('proxy error callback was processed (not last)')
|
41
41
|
return
|
42
42
|
}
|
43
43
|
} else {
|
44
44
|
const schemeParticipant = await this.validateParticipant(this.state.destination)
|
45
45
|
if (schemeParticipant) {
|
46
|
-
this.log.
|
46
|
+
this.log.info('Need to cleanup oracle and forward SERVICE_CURRENTLY_UNAVAILABLE error')
|
47
47
|
await this.cleanupOracle()
|
48
48
|
await this.removeProxyGetPartiesTimeoutCache(alsReq)
|
49
|
-
|
49
|
+
await this.forwardServiceUnavailableErrorCallback()
|
50
|
+
return
|
50
51
|
}
|
51
52
|
}
|
52
53
|
}
|
53
54
|
|
54
|
-
await
|
55
|
+
await super.identifyDestinationForCallback()
|
55
56
|
await this.sendErrorCallbackToParticipant()
|
56
|
-
this.log.info('
|
57
|
+
this.log.info('handleRequest is done')
|
57
58
|
}
|
58
59
|
|
59
60
|
async cleanupOracle () {
|
@@ -77,6 +78,21 @@ class PutPartiesErrorService extends BasePartiesService {
|
|
77
78
|
const errorInfo = PutPartiesErrorService.decodeDataUriPayload(dataUri)
|
78
79
|
return super.sendErrorCallback({ errorInfo, headers, params })
|
79
80
|
}
|
81
|
+
|
82
|
+
async forwardServiceUnavailableErrorCallback () {
|
83
|
+
this.stepInProgress('forwardServiceUnavailableErrorCallback')
|
84
|
+
const { headers, params } = this.inputs
|
85
|
+
const error = super.createFspiopServiceUnavailableError(ERROR_MESSAGES.externalPartyError)
|
86
|
+
const callbackHeaders = BasePartiesService.createErrorCallbackHeaders(headers, params, this.state.destination)
|
87
|
+
const errorInfo = await this.deps.partiesUtils.makePutPartiesErrorPayload(this.deps.config, error, callbackHeaders, params)
|
88
|
+
|
89
|
+
await super.sendErrorCallback({
|
90
|
+
errorInfo,
|
91
|
+
headers: callbackHeaders,
|
92
|
+
params
|
93
|
+
})
|
94
|
+
this.log.verbose('#forwardServiceUnavailableErrorCallback is done', { callbackHeaders, errorInfo })
|
95
|
+
}
|
80
96
|
}
|
81
97
|
|
82
98
|
module.exports = PutPartiesErrorService
|
package/src/handlers/index.js
CHANGED
@@ -38,12 +38,12 @@ const { HANDLER_TYPES } = require('../constants')
|
|
38
38
|
const Config = require('../lib/config')
|
39
39
|
const log = require('../lib').logger.child('ALS-timeout-handler')
|
40
40
|
|
41
|
-
process.on('
|
42
|
-
log.error(`uncaughtException: ${
|
41
|
+
process.on('uncaughtException', (err, origin) => {
|
42
|
+
log.error(`uncaughtException event [origin: ${origin}]: `, err)
|
43
43
|
process.exit(2)
|
44
44
|
})
|
45
45
|
process.on('unhandledRejection', (err) => {
|
46
|
-
log.error(
|
46
|
+
log.error('unhandledRejection event: ', err)
|
47
47
|
process.exit(3)
|
48
48
|
})
|
49
49
|
|
@@ -927,13 +927,13 @@ describe('Parties Tests', () => {
|
|
927
927
|
expect(sendErrorCallArgs[1]).toBe(expectedCallbackEnpointType)
|
928
928
|
})
|
929
929
|
|
930
|
-
it('should handle
|
930
|
+
it('should handle external party error callback, and delete partyId from oracle', async () => {
|
931
931
|
Config.PROXY_CACHE_CONFIG.enabled = true
|
932
932
|
const errorCode = MojaloopApiErrorCodes.PAYEE_IDENTIFIER_NOT_VALID.code
|
933
933
|
const payload = fixtures.errorCallbackResponseDto({ errorCode })
|
934
|
-
const
|
934
|
+
const destination = `dest-${Date.now()}`
|
935
935
|
const proxy = `proxy-${Date.now()}`
|
936
|
-
const headers = fixtures.partiesCallHeadersDto({
|
936
|
+
const headers = fixtures.partiesCallHeadersDto({ destination, proxy })
|
937
937
|
const { params } = Helper.putByTypeIdRequest
|
938
938
|
participant.validateParticipant = sandbox.stub().resolves({})
|
939
939
|
participant.sendRequest = sandbox.stub().resolves()
|
@@ -945,11 +945,14 @@ describe('Parties Tests', () => {
|
|
945
945
|
|
946
946
|
await partiesDomain.putPartiesErrorByTypeAndID(headers, params, payload, '', null, null, proxyCache)
|
947
947
|
|
948
|
-
expect(participant.sendRequest.callCount).toBe(0)
|
949
948
|
expect(oracle.oracleRequest.callCount).toBe(1)
|
950
|
-
|
951
|
-
expect(
|
952
|
-
expect(
|
949
|
+
expect(oracle.oracleRequest.lastCall.args[1]).toBe(RestMethods.DELETE)
|
950
|
+
expect(participant.sendRequest.callCount).toBe(0)
|
951
|
+
expect(participant.sendErrorToParticipant.callCount).toBe(1)
|
952
|
+
// eslint-disable-next-line no-unused-vars
|
953
|
+
const [sentTo, _, data] = participant.sendErrorToParticipant.lastCall.args
|
954
|
+
expect(sentTo).toBe(destination)
|
955
|
+
expect(data.errorInformation.errorCode).toBe('2003')
|
953
956
|
})
|
954
957
|
})
|
955
958
|
})
|
@@ -37,16 +37,22 @@ describe('PutPartiesErrorService Tests -->', () => {
|
|
37
37
|
jest.clearAllMocks()
|
38
38
|
})
|
39
39
|
|
40
|
-
test('should cleanup oracle and
|
40
|
+
test('should cleanup oracle and forward SERVICE_CURRENTLY_UNAVAILABLE error for party from external dfsp', async () => {
|
41
41
|
participantMock.validateParticipant = jest.fn().mockResolvedValue({})
|
42
|
-
const
|
42
|
+
const destination = 'destFsp'
|
43
|
+
const headers = fixtures.partiesCallHeadersDto({ destination, proxy: 'proxyA' })
|
43
44
|
const params = fixtures.partiesParamsDto()
|
44
|
-
const
|
45
|
+
const dataUri = fixtures.dataUriDto()
|
46
|
+
const service = new PutPartiesErrorService(createMockDeps(), { headers, params, dataUri })
|
45
47
|
|
46
|
-
|
47
|
-
expect(needDiscovery).toBe(true)
|
48
|
+
await service.handleRequest()
|
48
49
|
expect(oracleMock.oracleRequest).toHaveBeenCalledTimes(1)
|
49
50
|
expect(oracleMock.oracleRequest.mock.lastCall[1]).toBe(RestMethods.DELETE)
|
51
|
+
expect(participantMock.sendErrorToParticipant).toHaveBeenCalledTimes(1)
|
52
|
+
// eslint-disable-next-line no-unused-vars
|
53
|
+
const [sentTo, _, payload] = participantMock.sendErrorToParticipant.mock.lastCall
|
54
|
+
expect(sentTo).toBe(destination)
|
55
|
+
expect(payload.errorInformation.errorCode).toBe('2003')
|
50
56
|
})
|
51
57
|
|
52
58
|
test('should NOT cleanup oracle if destination is external', async () => {
|
@@ -63,8 +69,7 @@ describe('PutPartiesErrorService Tests -->', () => {
|
|
63
69
|
const dataUri = fixtures.dataUriDto()
|
64
70
|
const service = new PutPartiesErrorService(deps, { headers, params, dataUri })
|
65
71
|
|
66
|
-
|
67
|
-
expect(needDiscovery).toBeUndefined()
|
72
|
+
await service.handleRequest()
|
68
73
|
expect(oracleMock.oracleRequest).not.toHaveBeenCalled()
|
69
74
|
expect(participantMock.sendErrorToParticipant).toHaveBeenCalledTimes(1)
|
70
75
|
expect(participantMock.sendErrorToParticipant.mock.lastCall[0]).toBe(proxyDest)
|