account-lookup-service 17.7.0 → 17.8.0-snapshot.6

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.
Files changed (33) hide show
  1. package/package.json +9 -6
  2. package/src/constants.js +34 -2
  3. package/src/domain/parties/deps.js +4 -3
  4. package/src/domain/parties/getPartiesByTypeAndID.js +9 -13
  5. package/src/domain/parties/partiesUtils.js +4 -34
  6. package/src/domain/parties/putParties.js +26 -71
  7. package/src/domain/parties/services/BasePartiesService.js +143 -15
  8. package/src/domain/parties/services/GetPartiesService.js +189 -164
  9. package/src/domain/parties/services/PutPartiesErrorService.js +50 -27
  10. package/src/domain/parties/services/PutPartiesService.js +51 -33
  11. package/src/domain/parties/services/TimeoutPartiesService.js +84 -0
  12. package/src/domain/parties/services/index.js +3 -1
  13. package/src/domain/timeout/createSpan.js +55 -0
  14. package/src/domain/timeout/index.js +27 -36
  15. package/src/handlers/TimeoutHandler.js +2 -2
  16. package/src/lib/util.js +11 -3
  17. package/test/fixtures/index.js +46 -0
  18. package/test/integration/domain/timeout/index.test.js +83 -28
  19. package/test/unit/domain/parties/parties.test.js +26 -18
  20. package/test/unit/domain/parties/partiesUtils.test.js +51 -0
  21. package/test/unit/domain/parties/services/BasePartiesService.test.js +71 -0
  22. package/test/unit/domain/parties/services/GetPartiesService.test.js +224 -0
  23. package/test/unit/domain/parties/services/PutPartiesErrorService.test.js +50 -0
  24. package/test/unit/domain/parties/services/TimeoutPartiesService.test.js +72 -0
  25. package/test/unit/domain/parties/services/deps.js +49 -0
  26. package/test/unit/domain/timeout/index.test.js +17 -12
  27. package/test/util/apiClients/BasicApiClient.js +33 -6
  28. package/test/util/apiClients/ProxyApiClient.js +46 -1
  29. package/test/util/index.js +5 -6
  30. package/test/util/mockDeps.js +61 -0
  31. package/src/domain/timeout/dto.js +0 -54
  32. package/test/unit/domain/parties/utils.test.js +0 -60
  33. package/test/unit/domain/timeout/dto.test.js +0 -24
@@ -31,11 +31,13 @@
31
31
 
32
32
  'use strict'
33
33
 
34
- const Participant = require('../../../../src/models/participantEndpoint/facade')
35
- const TimeoutDomain = require('../../../../src/domain/timeout')
36
34
  const Metrics = require('@mojaloop/central-services-metrics')
35
+ const Participant = require('#src/models/participantEndpoint/facade')
36
+ const TimeoutDomain = require('#src/domain/timeout/index')
37
+ const { mockDeps } = require('#test/util/index')
37
38
 
38
39
  describe('Timeout Domain', () => {
40
+ const proxyCache = mockDeps.createProxyCacheMock()
39
41
  // Initialize Metrics for testing
40
42
  Metrics.getCounter(
41
43
  'errorCount',
@@ -56,24 +58,25 @@ describe('Timeout Domain', () => {
56
58
  describe('timeoutInterschemePartiesLookups', () => {
57
59
  describe('timeoutInterschemePartiesLookups', () => {
58
60
  it('should process expired ALS keys', async () => {
59
- const mockCache = { processExpiredAlsKeys: jest.fn() }
60
- await TimeoutDomain.timeoutInterschemePartiesLookups({ proxyCache: mockCache, batchSize: 10 })
61
- expect(mockCache.processExpiredAlsKeys).toHaveBeenCalledWith(TimeoutDomain.sendTimeoutCallback, 10)
61
+ const batchSize = 10
62
+ await TimeoutDomain.timeoutInterschemePartiesLookups({ proxyCache, batchSize })
63
+ expect(proxyCache.processExpiredAlsKeys).toHaveBeenCalledWith(expect.any(Function), batchSize)
64
+ expect(Participant.sendErrorToParticipant).toHaveBeenCalled()
62
65
  })
63
66
  })
64
67
 
65
68
  describe('sendTimeoutCallback', () => {
66
69
  it('should send error to participant', async () => {
67
- jest.spyOn(Participant, 'validateParticipant').mockResolvedValue({ fspId: 'sourceId' })
70
+ const SOURCE_ID = 'sourceId'
71
+ jest.spyOn(Participant, 'validateParticipant').mockResolvedValue({ fspId: SOURCE_ID })
68
72
 
69
- const cacheKey = 'als:sourceId:2:3:expiresAt'
70
- const [, destination] = cacheKey.split(':')
73
+ const cacheKey = `als:${SOURCE_ID}:2:3` // ':expiresAt' part is removed inside proxyCache.processExpiryKey()
71
74
 
72
- await TimeoutDomain.sendTimeoutCallback(cacheKey)
75
+ await TimeoutDomain.sendTimeoutCallback(cacheKey, proxyCache)
73
76
 
74
- expect(Participant.validateParticipant).toHaveBeenCalledWith('sourceId')
77
+ expect(Participant.validateParticipant).toHaveBeenCalledWith(SOURCE_ID)
75
78
  expect(Participant.sendErrorToParticipant).toHaveBeenCalledWith(
76
- destination,
79
+ SOURCE_ID,
77
80
  'FSPIOP_CALLBACK_URL_PARTIES_PUT_ERROR',
78
81
  { errorInformation: { errorCode: '3300', errorDescription: 'Generic expired error' } },
79
82
  expect.any(Object), expect.any(Object), undefined, expect.any(Object)
@@ -82,7 +85,9 @@ describe('Timeout Domain', () => {
82
85
 
83
86
  it('should throw error if participant validation fails', async () => {
84
87
  Participant.validateParticipant.mockResolvedValue(null)
85
- await expect(TimeoutDomain.sendTimeoutCallback('als:sourceId:2:3:expiresAt')).rejects.toThrow()
88
+ await expect(
89
+ TimeoutDomain.sendTimeoutCallback('als:sourceId:2:3:expiresAt', proxyCache)
90
+ ).rejects.toThrow()
86
91
  })
87
92
  })
88
93
  })
@@ -1,16 +1,43 @@
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
+
1
28
  const axiosLib = require('axios')
2
- const lib = require('../../../src/lib')
3
- const fixtures = require('../../fixtures')
29
+ const { logger } = require('#src/lib/index')
30
+ const fixtures = require('#test/fixtures/index')
4
31
 
5
32
  class BasicApiClient {
6
33
  constructor ({
7
34
  baseURL,
8
35
  axios = axiosLib.create({ baseURL }),
9
- logger = lib.logger.child(this.constructor.name)
36
+ log = logger.child({ component: this.constructor.name })
10
37
  } = {}) {
11
38
  this.baseURL = baseURL
12
39
  this.axios = axios
13
- this.logger = logger
40
+ this.log = log
14
41
  this.fixtures = fixtures
15
42
  }
16
43
 
@@ -22,10 +49,10 @@ class BasicApiClient {
22
49
  headers,
23
50
  data: body
24
51
  })
25
- this.logger.info('sendRequest is done:', { method, url, body, headers, response: { status, data } })
52
+ this.log.info(`sendRequest is done [${method} ${url}]:`, { method, url, body, headers, response: { status, data } })
26
53
  return { data, status }
27
54
  } catch (err) {
28
- this.logger.error('error in sendRequest: ', err)
55
+ this.log.error('error in sendRequest: ', err)
29
56
  throw err
30
57
  }
31
58
  }
@@ -1,4 +1,32 @@
1
- const { PROXY_PORT } = require('../../integration/constants')
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 { setTimeout: sleep } = require('node:timers/promises')
29
+ const { PROXY_PORT } = require('#test/integration/constants')
2
30
  const BasicApiClient = require('./BasicApiClient')
3
31
 
4
32
  const baseURL = `http://localhost:${PROXY_PORT}`
@@ -10,6 +38,7 @@ class ProxyApiClient extends BasicApiClient {
10
38
 
11
39
  async getHistory () {
12
40
  const { data } = await this.sendRequest({ url: '/history' })
41
+ this.log.verbose('getHistory response data: ', { data })
13
42
  return data.history
14
43
  }
15
44
 
@@ -20,6 +49,22 @@ class ProxyApiClient extends BasicApiClient {
20
49
  })
21
50
  return data.history
22
51
  }
52
+
53
+ async waitForNHistoryCalls (N, retryMaxCount = 20, retryIntervalSec = 2) {
54
+ // check that the callbacks are sent and received at the FSP
55
+ // for test resilience, we will retry the history check a few times
56
+ let retryCount = 0
57
+ let history = []
58
+
59
+ while (history.length < N && retryCount < retryMaxCount) {
60
+ await sleep(retryIntervalSec * 1000)
61
+ history = await this.getHistory()
62
+ retryCount++
63
+ }
64
+ this.log.info('waitForNHistoryCalls is done: ', { history })
65
+
66
+ return history
67
+ }
23
68
  }
24
69
 
25
70
  module.exports = ProxyApiClient
@@ -1,11 +1,10 @@
1
+ const { AlsApiClient, ProxyApiClient } = require('./apiClients')
2
+ const mockDeps = require('./mockDeps')
1
3
  const onboarding = require('./onboarding')
2
- const {
3
- AlsApiClient,
4
- ProxyApiClient
5
- } = require('./apiClients')
6
4
 
7
5
  module.exports = {
8
- onboarding,
9
6
  AlsApiClient,
10
- ProxyApiClient
7
+ ProxyApiClient,
8
+ mockDeps,
9
+ onboarding
11
10
  }
@@ -0,0 +1,61 @@
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 fixtures = require('../fixtures')
29
+
30
+ // eslint-disable-next-line n/no-callback-literal
31
+ const processExpierdKeysFn = async (cb) => cb(fixtures.expiredCacheKeyDto())
32
+
33
+ const createProxyCacheMock = ({
34
+ addDfspIdToProxyMapping = jest.fn(async () => true),
35
+ isPendingCallback = jest.fn(async () => false),
36
+ lookupProxyByDfspId = jest.fn(async () => null),
37
+ processExpiredAlsKeys = jest.fn(processExpierdKeysFn),
38
+ processExpiredProxyGetPartiesKeys = jest.fn(processExpierdKeysFn),
39
+ receivedErrorResponse = jest.fn(async () => false),
40
+ receivedSuccessResponse = jest.fn(async () => true),
41
+ removeDfspIdFromProxyMapping = jest.fn(async () => true),
42
+ removeProxyGetPartiesTimeout = jest.fn(async () => true),
43
+ setProxyGetPartiesTimeout = jest.fn(async () => true),
44
+ setSendToProxiesList = jest.fn(async () => true)
45
+ } = {}) => ({
46
+ addDfspIdToProxyMapping,
47
+ isPendingCallback,
48
+ lookupProxyByDfspId,
49
+ processExpiredAlsKeys,
50
+ processExpiredProxyGetPartiesKeys,
51
+ receivedErrorResponse,
52
+ receivedSuccessResponse,
53
+ removeDfspIdFromProxyMapping,
54
+ removeProxyGetPartiesTimeout,
55
+ setProxyGetPartiesTimeout,
56
+ setSendToProxiesList
57
+ })
58
+
59
+ module.exports = {
60
+ createProxyCacheMock
61
+ }
@@ -1,54 +0,0 @@
1
- const {
2
- Factory: { createFSPIOPError },
3
- Enums: { FSPIOPErrorCodes }
4
- } = require('@mojaloop/central-services-error-handling')
5
- const {
6
- Http: { Headers: { FSPIOP: FSPIOPHeaders } },
7
- Events: { Event: { Type: EventType, Action: EventAction } },
8
- EndPoints: { FspEndpointTypes },
9
- Tags: { QueryTags: QueryTagsEnum }
10
- } = require('@mojaloop/central-services-shared').Enum
11
- const { Tracer } = require('@mojaloop/event-sdk')
12
- const EventFrameworkUtil = require('@mojaloop/central-services-shared').Util.EventFramework
13
-
14
- const LibUtil = require('../../lib/util')
15
- const Config = require('../../lib/config')
16
- const partiesUtils = require('../parties/partiesUtils')
17
-
18
- const timeoutCallbackDto = async ({ destination, partyId, partyType }) => {
19
- const headers = {
20
- [FSPIOPHeaders.SOURCE]: Config.HUB_NAME,
21
- [FSPIOPHeaders.DESTINATION]: destination
22
- }
23
- const params = {
24
- ID: partyId,
25
- Type: partyType
26
- }
27
- const error = createFSPIOPError(FSPIOPErrorCodes.EXPIRED_ERROR)
28
-
29
- const dto = {
30
- errorInformation: await partiesUtils.makePutPartiesErrorPayload(Config, error, headers, params),
31
- headers,
32
- params,
33
- endpointType: FspEndpointTypes.FSPIOP_CALLBACK_URL_PARTIES_PUT_ERROR
34
- }
35
- const span = Tracer.createSpan('timeoutInterschemePartiesLookups', { headers: dto.headers })
36
- const spanTags = LibUtil.getSpanTags({ headers: dto.headers }, EventType.PARTY, EventAction.PUT)
37
- span.setTags(spanTags)
38
- const queryTags = EventFrameworkUtil.Tags.getQueryTags(
39
- QueryTagsEnum.serviceName.accountLookupService,
40
- QueryTagsEnum.auditType.transactionFlow,
41
- QueryTagsEnum.contentType.httpRequest,
42
- QueryTagsEnum.operation.timeoutInterschemePartiesLookups,
43
- {
44
- partyIdType: params.Type,
45
- partyIdentifier: params.ID
46
- }
47
- )
48
- span.setTags(queryTags)
49
- return { ...dto, span }
50
- }
51
-
52
- module.exports = {
53
- timeoutCallbackDto
54
- }
@@ -1,60 +0,0 @@
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
- http://www.apache.org/licenses/LICENSE-2.0
7
- 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.
8
-
9
- Contributors
10
- --------------
11
- This is the official list of the Mojaloop project contributors for this file.
12
- Names of the original copyright holders (individuals or organizations)
13
- should be listed with a '*' in the first column. People who have
14
- contributed from an organization can be listed under the organization
15
- that actually holds the copyright for their contributions (see the
16
- Mojaloop Foundation organization for an example). Those individuals should have
17
- their names indented and be marked with a '-'. Email address can be added
18
- optionally within square brackets <email>.
19
- * Mojaloop Foundation
20
- - Name Surname <name.surname@mojaloop.io>
21
-
22
- * Eugen Klymniuk <eugen.klymniuk@infitx.com>
23
- --------------
24
- **********/
25
-
26
- const mockSendRequest = jest.fn()
27
-
28
- jest.mock('@mojaloop/central-services-shared', () => ({
29
- ...jest.requireActual('@mojaloop/central-services-shared'),
30
- Util: {
31
- ...jest.requireActual('@mojaloop/central-services-shared').Util,
32
- Endpoints: { getEndpoint: jest.fn() },
33
- Request: { sendRequest: mockSendRequest }
34
- }
35
- }))
36
-
37
- const { API_TYPES } = require('@mojaloop/central-services-shared').Util.Hapi
38
- const { logger } = require('../../../../src/lib')
39
- const partiesUtils = require('../../../../src/domain/parties/partiesUtils')
40
- const config = require('../../../../src/lib/config')
41
- const fixtures = require('../../../fixtures')
42
-
43
- describe('parties utils Tests -->', () => {
44
- test('should send error party callback in ISO format', async () => {
45
- const isoConfig = { ...config, API_TYPE: API_TYPES.iso20022 }
46
- const err = new Error('test error')
47
- const source = 'dfsp1'
48
- const headers = fixtures.partiesCallHeadersDto({ source })
49
- const params = { ID: '1234', Type: 'MSISDN' }
50
-
51
- const handleError = partiesUtils.createErrorHandlerOnSendingCallback(isoConfig, logger)
52
- await handleError(err, headers, params, source)
53
-
54
- expect(mockSendRequest).toHaveBeenCalledTimes(1)
55
- const { payload } = mockSendRequest.mock.calls[0][0]
56
- expect(payload.Rpt.Rsn.Cd).toBe('2001')
57
- expect(payload.Rpt.OrgnlId).toBe(`${params.Type}/${params.ID}`)
58
- expect(payload.Assgnmt.Assgnr.Agt.FinInstnId.Othr.Id).toBe(source)
59
- })
60
- })
@@ -1,24 +0,0 @@
1
- const { API_TYPES } = require('@mojaloop/central-services-shared').Util.Hapi
2
- const { timeoutCallbackDto } = require('../../../../src/domain/timeout/dto')
3
- const config = require('../../../../src/lib/config')
4
-
5
- const realApiType = config.API_TYPE
6
-
7
- describe('timeoutCallbackDto Tests -->', () => {
8
- afterAll(() => {
9
- config.API_TYPE = realApiType
10
- })
11
-
12
- test('should produce ISO payload', async () => {
13
- config.API_TYPE = API_TYPES.iso20022
14
- const destination = 'D1'
15
- const partyId = 'P1'
16
- const partyType = 'XXX'
17
- const dto = await timeoutCallbackDto({ destination, partyId, partyType })
18
- expect(dto.errorInformation).toBeTruthy()
19
-
20
- const { Assgnr, Assgne } = dto.errorInformation.Assgnmt
21
- expect(Assgnr.Agt.FinInstnId.Othr.Id).toBe(config.HUB_NAME)
22
- expect(Assgne.Agt.FinInstnId.Othr.Id).toBe(destination)
23
- })
24
- })