account-lookup-service 17.9.0-snapshot.0 → 17.9.0

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/CHANGELOG.md CHANGED
@@ -2,6 +2,20 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
4
4
 
5
+ ## [17.9.0](https://github.com/mojaloop/account-lookup-service/compare/v17.8.1...v17.9.0) (2025-04-08)
6
+
7
+
8
+ ### Features
9
+
10
+ * **csi-1350:** refactored oracleRequest ([#546](https://github.com/mojaloop/account-lookup-service/issues/546)) ([3f76ef7](https://github.com/mojaloop/account-lookup-service/commit/3f76ef7f712590e82bcb5bf7e49a643b2aae63f3))
11
+
12
+ ### [17.8.1](https://github.com/mojaloop/account-lookup-service/compare/v17.8.0...v17.8.1) (2025-04-07)
13
+
14
+
15
+ ### Bug Fixes
16
+
17
+ * **csi-1386:** delete participant audit ([#547](https://github.com/mojaloop/account-lookup-service/issues/547)) ([5ecf562](https://github.com/mojaloop/account-lookup-service/commit/5ecf562db8f48cf688f1ee19e901d46671d16ce9))
18
+
5
19
  ## [17.8.0](https://github.com/mojaloop/account-lookup-service/compare/v17.7.1...v17.8.0) (2025-04-03)
6
20
 
7
21
 
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.9.0-snapshot.0",
4
+ "version": "17.9.0",
5
5
  "license": "Apache-2.0",
6
6
  "author": "ModusBox",
7
7
  "contributors": [
@@ -175,7 +175,7 @@ module.exports = {
175
175
  ['success']
176
176
  ).startTimer()
177
177
 
178
- const { headers, payload, method, path, params, span } = request
178
+ const { headers, method, path, params, span } = request
179
179
  const spanTags = LibUtil.getSpanTags(request, Enum.Events.Event.Type.PARTICIPANT, Enum.Events.Event.Action.DELETE)
180
180
  span.setTags(spanTags)
181
181
  const queryTags = EventFrameworkUtil.Tags.getQueryTags(
@@ -193,7 +193,7 @@ module.exports = {
193
193
  span.setTags(queryTags)
194
194
  await span.audit({
195
195
  headers,
196
- payload
196
+ payload: undefined
197
197
  }, EventSdk.AuditEventAction.start)
198
198
 
199
199
  const metadata = `${request.method} ${request.path}`
@@ -40,6 +40,12 @@ const oracleEndpointCached = require('../oracle/oracleEndpointCached')
40
40
 
41
41
  const { Headers, RestMethods, ReturnCodes } = Enums.Http
42
42
 
43
+ const sendHttpRequest = ({ method, ...restArgs }) => request.sendRequest({
44
+ ...restArgs,
45
+ method: method.toUpperCase(),
46
+ hubNameRegex
47
+ })
48
+
43
49
  /**
44
50
  * Sends a request to the oracles that are registered to the ALS
45
51
  *
@@ -67,7 +73,6 @@ const oracleRequest = async (headers, method, params = {}, query = {}, payload =
67
73
  const url = await determineOracleEndpoint({
68
74
  method, params, query, payload, assertPendingAcquire
69
75
  })
70
- log.verbose(`Oracle endpoint: ${url}`)
71
76
 
72
77
  if (method.toUpperCase() === RestMethods.GET) {
73
78
  step = 'sendOracleGetRequest'
@@ -80,20 +85,17 @@ const oracleRequest = async (headers, method, params = {}, query = {}, payload =
80
85
 
81
86
  if (method.toUpperCase() === RestMethods.DELETE && Config.DELETE_PARTICIPANT_VALIDATION_ENABLED) {
82
87
  step = 'validatePartyDeletion'
83
- await validatePartyDeletion({
84
- url, source, destination, headers, method, params, payload
85
- })
88
+ await validatePartyDeletion({ url, source, destination, headers, params })
86
89
  }
87
90
 
88
- step = 'sendRequest'
89
- return await request.sendRequest({
91
+ step = 'sendHttpRequest'
92
+ return await sendHttpRequest({
90
93
  url,
91
94
  headers,
92
95
  source,
93
96
  destination,
94
97
  method,
95
- payload,
96
- hubNameRegex
98
+ payload
97
99
  })
98
100
  } catch (err) {
99
101
  log.error('error in oracleRequest: ', err)
@@ -120,6 +122,8 @@ const determineOracleEndpoint = async ({
120
122
  } else {
121
123
  url = await _getOracleEndpointByType(partyIdType, partyIdentifier, assertPendingAcquire)
122
124
  }
125
+
126
+ logger.verbose(`Oracle endpoint: ${url}`, { currency, params, partySubIdOrType, url })
123
127
  return url
124
128
  }
125
129
 
@@ -138,13 +142,12 @@ const sendOracleGetRequest = async ({
138
142
  cachedOracleFspResponse = cache && cache.get(cache.createKey(`oracleSendRequest_${url}`))
139
143
 
140
144
  if (!cachedOracleFspResponse) {
141
- cachedOracleFspResponse = await request.sendRequest({
145
+ cachedOracleFspResponse = await sendHttpRequest({
142
146
  url,
143
147
  headers,
144
148
  source,
145
149
  destination,
146
- method,
147
- hubNameRegex
150
+ method
148
151
  })
149
152
  // Trying to cache the whole response object will fail because it contains circular references
150
153
  // so we'll just cache the data property of the response.
@@ -204,19 +207,15 @@ const sendOracleGetRequest = async ({
204
207
  }
205
208
  }
206
209
 
207
- const validatePartyDeletion = async ({
208
- url, source, destination, headers, method, params, payload
209
- }) => {
210
+ const validatePartyDeletion = async ({ url, source, destination, headers, params }) => {
210
211
  const log = logger.child({ component: 'validatePartyDeletion', params })
211
212
  // If the request is a DELETE request, we need to ensure that the participant belongs to the requesting FSP
212
- const getParticipantResponse = await request.sendRequest({
213
+ const getParticipantResponse = await sendHttpRequest({
213
214
  url,
214
215
  headers,
215
216
  source,
216
217
  destination,
217
- method,
218
- payload,
219
- hubNameRegex
218
+ method: RestMethods.GET
220
219
  })
221
220
 
222
221
  if (getParticipantResponse.status !== ReturnCodes.OK.CODE) {
@@ -274,7 +273,7 @@ const _getOracleEndpointByTypeAndCurrency = async (partyIdType, partyIdentifier,
274
273
  }
275
274
  } else {
276
275
  const errMessage = `Oracle type:${partyIdType} and currency:${currency} not found`
277
- logger.error(errMessage)
276
+ logger.warn(errMessage)
278
277
  throw ErrorHandler.Factory.createFSPIOPError(ErrorHandler.Enums.FSPIOPErrorCodes.ADD_PARTY_INFO_ERROR, errMessage)
279
278
  .toApiErrorObject(Config.ERROR_HANDLING)
280
279
  }
@@ -312,7 +311,7 @@ const _getOracleEndpointByType = async (partyIdType, partyIdentifier, assertPend
312
311
  }
313
312
  } else {
314
313
  const errMessage = `Oracle type:${partyIdType} not found`
315
- logger.error(errMessage)
314
+ logger.warn(errMessage)
316
315
  throw ErrorHandler.Factory.createFSPIOPError(ErrorHandler.Enums.FSPIOPErrorCodes.ADD_PARTY_INFO_ERROR, errMessage)
317
316
  }
318
317
  return url
@@ -350,7 +349,7 @@ const _getOracleEndpointByTypeAndSubId = async (partyIdType, partyIdentifier, pa
350
349
  }
351
350
  } else {
352
351
  const errMessage = `Oracle type: ${partyIdType} and subId: ${partySubIdOrType} not found`
353
- logger.error(errMessage)
352
+ logger.warn(errMessage)
354
353
  throw ErrorHandler.Factory.createFSPIOPError(ErrorHandler.Enums.FSPIOPErrorCodes.ADD_PARTY_INFO_ERROR, errMessage)
355
354
  .toApiErrorObject(Config.ERROR_HANDLING)
356
355
  }
@@ -390,7 +389,7 @@ const _getOracleEndpointByTypeCurrencyAndSubId = async (partyIdType, partyIdenti
390
389
  }
391
390
  } else {
392
391
  const errMessage = `Oracle type: ${partyIdType}, currency: ${currency} and subId: ${partySubIdOrType} not found`
393
- logger.error(errMessage)
392
+ logger.warn(errMessage)
394
393
  throw ErrorHandler.Factory.createFSPIOPError(ErrorHandler.Enums.FSPIOPErrorCodes.ADD_PARTY_INFO_ERROR, errMessage)
395
394
  .toApiErrorObject(Config.ERROR_HANDLING)
396
395
  }
@@ -409,6 +408,7 @@ const _getOracleEndpointByTypeCurrencyAndSubId = async (partyIdType, partyIdenti
409
408
  * @returns {object} - response from the oracle
410
409
  */
411
410
  const oracleBatchRequest = async (headers, method, requestPayload, type, payload) => {
411
+ let step = 'getOracleEndpoint'
412
412
  try {
413
413
  let oracleEndpointModel
414
414
  let url
@@ -417,34 +417,37 @@ const oracleBatchRequest = async (headers, method, requestPayload, type, payload
417
417
  } else {
418
418
  oracleEndpointModel = await oracleEndpointCached.getOracleEndpointByType(type)
419
419
  }
420
- if (oracleEndpointModel.length > 0) {
421
- if (oracleEndpointModel.length > 1) {
422
- for (const record of oracleEndpointModel) {
423
- if (record.isDefault) {
424
- url = record.value + Enums.EndPoints.FspEndpointTemplates.ORACLE_PARTICIPANTS_BATCH
425
- break
426
- }
420
+
421
+ if (!Array.isArray(oracleEndpointModel) || oracleEndpointModel.length === 0) {
422
+ const errMessage = `Oracle type:${type} not found`
423
+ logger.warn(errMessage)
424
+ throw ErrorHandler.Factory.createFSPIOPError(ErrorHandler.Enums.FSPIOPErrorCodes.ADD_PARTY_INFO_ERROR, errMessage)
425
+ }
426
+
427
+ if (oracleEndpointModel.length > 1) {
428
+ for (const record of oracleEndpointModel) {
429
+ if (record.isDefault) {
430
+ url = record.value + Enums.EndPoints.FspEndpointTemplates.ORACLE_PARTICIPANTS_BATCH
431
+ break
427
432
  }
428
- } else {
429
- url = oracleEndpointModel[0].value + Enums.EndPoints.FspEndpointTemplates.ORACLE_PARTICIPANTS_BATCH
430
433
  }
431
- logger.debug(`Oracle endpoints: ${url}`)
432
- return await request.sendRequest({
433
- url,
434
- headers,
435
- source: headers[Headers.FSPIOP.SOURCE],
436
- destination: headers[Headers.FSPIOP.DESTINATION] || Config.HUB_NAME,
437
- method,
438
- payload,
439
- hubNameRegex
440
- })
441
434
  } else {
442
- logger.error(`Oracle type:${type} not found`)
443
- throw ErrorHandler.Factory.createFSPIOPError(ErrorHandler.Enums.FSPIOPErrorCodes.ADD_PARTY_INFO_ERROR, `Oracle type:${type} not found`)
435
+ url = oracleEndpointModel[0].value + Enums.EndPoints.FspEndpointTemplates.ORACLE_PARTICIPANTS_BATCH
444
436
  }
437
+ logger.verbose(`Oracle endpoint: ${url}`)
438
+
439
+ step = 'sendHttpRequest'
440
+ return await sendHttpRequest({
441
+ url,
442
+ headers,
443
+ source: headers[Headers.FSPIOP.SOURCE],
444
+ destination: headers[Headers.FSPIOP.DESTINATION] || Config.HUB_NAME,
445
+ method,
446
+ payload
447
+ })
445
448
  } catch (err) {
446
449
  logger.error('error in oracleBatchRequest: ', err)
447
- throw ErrorHandler.Factory.reformatFSPIOPError(err)
450
+ throw countFspiopError(err, { operation: 'oracleBatchRequest', step })
448
451
  }
449
452
  }
450
453
 
@@ -30,14 +30,15 @@
30
30
  const Sinon = require('sinon')
31
31
  const Enums = require('@mojaloop/central-services-shared').Enum
32
32
  const request = require('@mojaloop/central-services-shared').Util.Request
33
+ const errorHandling = require('@mojaloop/central-services-error-handling')
33
34
 
34
- const OracleFacade = require('../../../../src/models/oracle/facade')
35
- const oracleEndpointCached = require('../../../../src/models/oracle/oracleEndpointCached')
36
- const Logger = require('@mojaloop/central-services-logger')
35
+ const OracleFacade = require('#src/models/oracle/facade')
36
+ const oracleEndpointCached = require('#src/models/oracle/oracleEndpointCached')
37
+ const fixtures = require('#test/fixtures/index')
38
+
39
+ const { createFSPIOPError } = errorHandling.Factory
40
+ const { FSPIOPErrorCodes } = errorHandling.Enums
37
41
 
38
- Logger.isDebugEnabled = jest.fn(() => true)
39
- Logger.isErrorEnabled = jest.fn(() => true)
40
- Logger.isInfoEnabled = jest.fn(() => true)
41
42
  let sandbox
42
43
 
43
44
  describe('Oracle Facade', () => {
@@ -443,6 +444,21 @@ describe('Oracle Facade', () => {
443
444
  // Assert
444
445
  await expect(action()).rejects.toThrowError(/(Oracle type:.*not found)/)
445
446
  })
447
+
448
+ it('should return proper error on adding existing party [CSI-1352]', async () => {
449
+ expect.hasAssertions()
450
+ const ERROR = FSPIOPErrorCodes.ADD_PARTY_INFO_ERROR
451
+ request.sendRequest = sandbox.stub().rejects(createFSPIOPError(ERROR))
452
+ sandbox.stub(oracleEndpointCached, 'getOracleEndpointByType').resolves([{}])
453
+ const method = Enums.Http.RestMethods.POST
454
+ const headers = fixtures.partiesCallHeadersDto()
455
+ const params = fixtures.partiesParamsDto()
456
+
457
+ await OracleFacade.oracleRequest(headers, method, params)
458
+ .catch(err => {
459
+ expect(err.apiErrorCode.code).toBe(ERROR.code)
460
+ })
461
+ })
446
462
  })
447
463
 
448
464
  describe('oracleBatchRequest', () => {