account-lookup-service 17.7.1 → 17.8.0-snapshot.10

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 (38) hide show
  1. package/CHANGELOG.md +0 -7
  2. package/docker/mock-proxy/src/server.ts +13 -4
  3. package/package.json +10 -7
  4. package/src/constants.js +35 -2
  5. package/src/domain/parties/deps.js +11 -4
  6. package/src/domain/parties/getPartiesByTypeAndID.js +9 -13
  7. package/src/domain/parties/partiesUtils.js +4 -34
  8. package/src/domain/parties/putParties.js +26 -71
  9. package/src/domain/parties/services/BasePartiesService.js +143 -15
  10. package/src/domain/parties/services/GetPartiesService.js +210 -165
  11. package/src/domain/parties/services/PutPartiesErrorService.js +52 -28
  12. package/src/domain/parties/services/PutPartiesService.js +51 -33
  13. package/src/domain/parties/services/TimeoutPartiesService.js +84 -0
  14. package/src/domain/parties/services/index.js +3 -1
  15. package/src/domain/timeout/createSpan.js +55 -0
  16. package/src/domain/timeout/index.js +27 -36
  17. package/src/handlers/TimeoutHandler.js +2 -2
  18. package/src/index.js +3 -0
  19. package/src/lib/util.js +11 -3
  20. package/test/fixtures/index.js +53 -3
  21. package/test/integration/api/parties.test.js +1 -0
  22. package/test/integration/domain/timeout/index.test.js +83 -28
  23. package/test/unit/domain/parties/parties.test.js +26 -18
  24. package/test/unit/domain/parties/partiesUtils.test.js +51 -0
  25. package/test/unit/domain/parties/services/BasePartiesService.test.js +71 -0
  26. package/test/unit/domain/parties/services/GetPartiesService.test.js +316 -0
  27. package/test/unit/domain/parties/services/PutPartiesErrorService.test.js +50 -0
  28. package/test/unit/domain/parties/services/TimeoutPartiesService.test.js +72 -0
  29. package/test/unit/domain/parties/services/deps.js +51 -0
  30. package/test/unit/domain/timeout/index.test.js +17 -12
  31. package/test/util/apiClients/AlsApiClient.js +6 -4
  32. package/test/util/apiClients/BasicApiClient.js +33 -6
  33. package/test/util/apiClients/ProxyApiClient.js +46 -1
  34. package/test/util/index.js +5 -6
  35. package/test/util/mockDeps.js +72 -0
  36. package/src/domain/timeout/dto.js +0 -54
  37. package/test/unit/domain/parties/utils.test.js +0 -60
  38. package/test/unit/domain/timeout/dto.test.js +0 -24
@@ -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,72 @@
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
+ // @mojaloop/central-services-shared/Util/proxies
60
+ /** @returns {Proxies} */
61
+ const createProxiesUtilMock = ({
62
+ getAllProxiesNames = jest.fn().mockResolvedValue([]),
63
+ invalidateProxiesCache = jest.fn()
64
+ } = {}) => ({
65
+ getAllProxiesNames,
66
+ invalidateProxiesCache
67
+ })
68
+
69
+ module.exports = {
70
+ createProxyCacheMock,
71
+ createProxiesUtilMock
72
+ }
@@ -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
- })