account-lookup-service 15.6.0-iso.2 → 15.6.0-iso.21

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 (53) hide show
  1. package/.circleci/config.yml +1 -1
  2. package/.ncurc.yaml +1 -2
  3. package/audit-ci.jsonc +3 -1
  4. package/jest.config.js +2 -0
  5. package/package.json +15 -17
  6. package/src/constants.js +2 -1
  7. package/src/domain/oracle/oracle.js +63 -4
  8. package/src/domain/participants/participants.js +259 -133
  9. package/src/domain/parties/getPartiesByTypeAndID.js +36 -15
  10. package/src/domain/parties/parties.js +44 -14
  11. package/src/domain/parties/utils.js +13 -6
  12. package/src/domain/timeout/dto.js +4 -10
  13. package/src/domain/timeout/index.js +12 -1
  14. package/src/handlers/index.js +4 -4
  15. package/src/handlers/monitoring/index.js +1 -1
  16. package/src/interface/api-swagger-iso20022-parties.yaml +7 -6
  17. package/src/interface/api-swagger.yaml +7 -6
  18. package/src/interface/fspiop-rest-v2.0-ISO20022_parties.yaml +2043 -1583
  19. package/src/lib/config.js +1 -1
  20. package/src/lib/index.js +1 -2
  21. package/src/models/currency/currency.js +10 -1
  22. package/src/models/endpointType/endpointType.js +10 -1
  23. package/src/models/oracle/facade.js +24 -3
  24. package/src/models/oracle/oracleEndpoint.js +64 -10
  25. package/src/models/oracle/oracleEndpointCached.js +22 -3
  26. package/src/models/participantEndpoint/facade.js +61 -23
  27. package/src/models/partyIdType/partyIdType.js +10 -1
  28. package/src/plugins.js +20 -9
  29. package/src/server.js +11 -19
  30. package/test/fixtures/index.js +30 -6
  31. package/test/fixtures/iso.js +1 -1
  32. package/test/unit/api/health.test.js +3 -0
  33. package/test/unit/api/participants/participants.test.js +5 -7
  34. package/test/unit/api/participants/{Type}/{ID}/{SubId}.test.js +0 -3
  35. package/test/unit/api/participants/{Type}/{ID}.test.js +0 -3
  36. package/test/unit/api/participants.test.js +36 -3
  37. package/test/unit/domain/oracle/oracle.test.js +8 -0
  38. package/test/unit/domain/participants/participants.test.js +83 -48
  39. package/test/unit/domain/parties/parties.test.js +11 -3
  40. package/test/unit/domain/parties/utils.test.js +60 -0
  41. package/test/unit/domain/timeout/dto.test.js +1 -2
  42. package/test/unit/domain/timeout/index.test.js +8 -0
  43. package/test/unit/lib/TransformFacades.test.js +2 -1
  44. package/test/unit/lib/config.test.js +7 -0
  45. package/test/unit/models/participantEndpoint/facade.test.js +25 -8
  46. package/test/unit/plugins.test.js +4 -2
  47. package/test/util/apiClients/BasicApiClient.js +2 -2
  48. package/src/handlers/monitoring/plugins/metrics.js +0 -48
  49. package/src/lib/requestLogger.js +0 -54
  50. package/src/metrics/handler.js +0 -33
  51. package/src/metrics/plugin.js +0 -52
  52. package/src/metrics/routes.js +0 -43
  53. package/test/unit/lib/requestLogger.test.js +0 -115
@@ -58,6 +58,18 @@ jest.mock('@mojaloop/central-services-shared', () => ({
58
58
  const Logger = require('@mojaloop/central-services-logger')
59
59
  const fixtures = require('../../../fixtures')
60
60
 
61
+ const mockConfigDto = ({
62
+ apiType = 'fspiop', // todo: use API_TYPES
63
+ jwsSign = false
64
+ } = {}) => ({
65
+ API_TYPE: apiType,
66
+ JWS_SIGN: jwsSign,
67
+ FSPIOP_SOURCE_TO_SIGN: mockHubName,
68
+ JWS_SIGNING_KEY_PATH: 'secrets/jwsSigningKey.key',
69
+ JWS_SIGNING_KEY: 'somekey',
70
+ PROTOCOL_VERSIONS: fixtures.protocolVersionsDto()
71
+ })
72
+
61
73
  Logger.isDebugEnabled = jest.fn(() => true)
62
74
  Logger.isErrorEnabled = jest.fn(() => true)
63
75
  Logger.isInfoEnabled = jest.fn(() => true)
@@ -190,14 +202,6 @@ describe('participantEndpoint Facade', () => {
190
202
  })
191
203
 
192
204
  describe('sendErrorToParticipant', () => {
193
- const mockConfigDto = ({ jwsSign = false } = {}) => ({
194
- JWS_SIGN: jwsSign,
195
- FSPIOP_SOURCE_TO_SIGN: mockHubName,
196
- JWS_SIGNING_KEY_PATH: 'secrets/jwsSigningKey.key',
197
- JWS_SIGNING_KEY: 'somekey',
198
- PROTOCOL_VERSIONS: fixtures.protocolVersionsDto()
199
- })
200
-
201
205
  it('throws an error when the request fails', async () => {
202
206
  // Arrange
203
207
  jest.mock('../../../../src/lib/config', () => mockConfigDto())
@@ -291,5 +295,18 @@ describe('participantEndpoint Facade', () => {
291
295
  })
292
296
  spy.mockRestore()
293
297
  })
298
+
299
+ it('should send error response with apiType from config [ISO20022]', async () => {
300
+ const apiType = 'iso20022'
301
+ jest.mock('../../../../src/lib/config', () => mockConfigDto({ apiType }))
302
+ mockGetEndpoint.mockImplementation(() => 'http://example.com/12345')
303
+
304
+ const { sendErrorToParticipant } = require(`${src}/models/participantEndpoint/facade`)
305
+ await sendErrorToParticipant('participantName', 'URL', fixtures.errorCallbackResponseDto(), {})
306
+
307
+ expect(mockSendRequest).toHaveBeenCalledTimes(1)
308
+ const args = mockSendRequest.mock.calls[0][0]
309
+ expect(args.apiType).toBe(apiType)
310
+ })
294
311
  })
295
312
  })
@@ -50,6 +50,7 @@ describe('Plugin Tests', () => {
50
50
  // Arrange
51
51
  const server = {
52
52
  register: sandbox.spy(),
53
+ ext: sandbox.spy(),
53
54
  info: {
54
55
  port: '8000'
55
56
  }
@@ -63,7 +64,7 @@ describe('Plugin Tests', () => {
63
64
  await registerPlugins(server, api)
64
65
 
65
66
  // Assert
66
- expect(server.register.callCount).toBe(10)
67
+ expect(server.register.callCount).toBe(11)
67
68
  const firstCallArgs = server.register.getCall(1).args
68
69
  expect(firstCallArgs[0].options.document.info.title.includes('Open API for FSP Interoperability (FSPIOP) (Implementation Friendly Version)')).toBe(true)
69
70
  })
@@ -72,6 +73,7 @@ describe('Plugin Tests', () => {
72
73
  // Arrange
73
74
  const server = {
74
75
  register: sandbox.spy(),
76
+ ext: sandbox.spy(),
75
77
  info: {
76
78
  port: '8000'
77
79
  }
@@ -84,6 +86,6 @@ describe('Plugin Tests', () => {
84
86
  await registerPlugins(server, api)
85
87
 
86
88
  // Assert
87
- expect(server.register.callCount).toBe(9)
89
+ expect(server.register.callCount).toBe(10)
88
90
  })
89
91
  })
@@ -1,12 +1,12 @@
1
1
  const axiosLib = require('axios')
2
- const { loggerFactory } = require('../../../src/lib')
2
+ const lib = require('../../../src/lib')
3
3
  const fixtures = require('../../fixtures')
4
4
 
5
5
  class BasicApiClient {
6
6
  constructor ({
7
7
  baseURL,
8
8
  axios = axiosLib.create({ baseURL }),
9
- logger = loggerFactory(this.constructor.name)
9
+ logger = lib.logger.child(this.constructor.name)
10
10
  } = {}) {
11
11
  this.baseURL = baseURL
12
12
  this.axios = axios
@@ -1,48 +0,0 @@
1
- /*****
2
- LICENSE
3
-
4
- Copyright © 2020 Mojaloop Foundation
5
-
6
- The Mojaloop files are made available by the Mojaloop Foundation under the Apache License, Version 2.0
7
- (the "License") and you may not use these files except in compliance with the [License](http://www.apache.org/licenses/LICENSE-2.0).
8
-
9
- You may obtain a copy of the License at [http://www.apache.org/licenses/LICENSE-2.0](http://www.apache.org/licenses/LICENSE-2.0)
10
-
11
- 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,
12
- either express or implied. See the License for the specific language governing permissions and limitations under the [License](http://www.apache.org/licenses/LICENSE-2.0).
13
-
14
- * Infitx
15
- - Steven Oderayi <steven.oderayi@infitx.com>
16
- --------------
17
- ******/
18
-
19
- 'use strict'
20
-
21
- const HTTPENUM = require('@mojaloop/central-services-shared').Enum.Http
22
- const Metrics = require('@mojaloop/central-services-metrics')
23
-
24
- const handler = {
25
- get: async (_request, reply) => {
26
- return reply.response(await Metrics.getMetricsForPrometheus()).code(HTTPENUM.ReturnCodes.OK.CODE)
27
- }
28
- }
29
-
30
- const routes = [
31
- {
32
- method: 'GET',
33
- path: '/metrics',
34
- handler: handler.get
35
- }
36
- ]
37
-
38
- const plugin = {
39
- name: 'Metrics',
40
- register (server) {
41
- server.route(routes)
42
- }
43
- }
44
-
45
- module.exports = {
46
- plugin,
47
- handler
48
- }
@@ -1,54 +0,0 @@
1
- /*****
2
- License
3
- --------------
4
- Copyright © 2017 Bill & Melinda Gates Foundation
5
- The Mojaloop files are made available by the Bill & Melinda Gates 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
- Contributors
9
- --------------
10
- This is the official list of the Mojaloop project contributors for this file.
11
- Names of the original copyright holders (individuals or organizations)
12
- should be listed with a '*' in the first column. People who have
13
- contributed from an organization can be listed under the organization
14
- that actually holds the copyright for their contributions (see the
15
- Gates Foundation organization for an example). Those individuals should have
16
- their names indented and be marked with a '-'. Email address can be added
17
- optionally within square brackets <email>.
18
- * Gates Foundation
19
-
20
- * Rajiv Mothilal <rajiv.mothilal@modusbox.com>
21
-
22
- --------------
23
- ******/
24
-
25
- 'use strict'
26
-
27
- const { logger, asyncStorage } = require('./index')
28
-
29
- const logRequest = function (request) {
30
- const { path, method, headers, payload, query } = request
31
- const requestId = request.info.id = `${request.info.id}__${headers.traceid}`
32
- asyncStorage.enterWith({ requestId })
33
-
34
- logger.isInfoEnabled && logger.info(`[==> req] ${method.toUpperCase()} ${path}`, { headers, payload, query })
35
- }
36
-
37
- const logResponse = function (request) {
38
- if (logger.isInfoEnabled) {
39
- const { path, method, headers, payload, query, response } = request
40
- const { received } = request.info
41
-
42
- const statusCode = response instanceof Error
43
- ? response.output?.statusCode
44
- : response.statusCode
45
- const respTimeSec = ((Date.now() - received) / 1000).toFixed(3)
46
-
47
- logger.info(`[<== ${statusCode}][${respTimeSec} s] ${method.toUpperCase()} ${path}`, { headers, payload, query })
48
- }
49
- }
50
-
51
- module.exports = {
52
- logRequest,
53
- logResponse
54
- }
@@ -1,33 +0,0 @@
1
- /*****
2
- License
3
- --------------
4
- Copyright © 2017 Bill & Melinda Gates Foundation
5
- The Mojaloop files are made available by the Bill & Melinda Gates 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
- Contributors
9
- --------------
10
- This is the official list of the Mojaloop project contributors for this file.
11
- Names of the original copyright holders (individuals or organizations)
12
- should be listed with a '*' in the first column. People who have
13
- contributed from an organization can be listed under the organization
14
- that actually holds the copyright for their contributions (see the
15
- Gates Foundation organization for an example). Those individuals should have
16
- their names indented and be marked with a '-'. Email address can be added
17
- optionally within square brackets <email>.
18
- * Gates Foundation
19
- - Name Surname <name.surname@gatesfoundation.com>
20
-
21
- - Pedro Barreto <pedrob@crosslaketech.com>
22
- - Rajiv Mothilal <rajivmothilal@gmail.com>
23
- - Shashikant Hirugade <shashikant.hirugade@modusbox.com>
24
- --------------
25
- ******/
26
-
27
- 'use strict'
28
-
29
- const Metrics = require('@mojaloop/central-services-metrics')
30
-
31
- exports.metrics = async function (request, h) {
32
- return h.response(await Metrics.getMetricsForPrometheus()).code(200)
33
- }
@@ -1,52 +0,0 @@
1
- /*****
2
- License
3
- --------------
4
- Copyright © 2017 Bill & Melinda Gates Foundation
5
- The Mojaloop files are made available by the Bill & Melinda Gates 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
- Gates Foundation organization 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
- * Gates Foundation
23
- - Name Surname <name.surname@gatesfoundation.com>
24
-
25
- * Lazola Lucas <lazola.lucas@modusbox.com>
26
- * Rajiv Mothilal <rajiv.mothilal@modusbox.com>
27
- * Miguel de Barros <miguel.debarros@modusbox.com>
28
- * Shashikant Hirugade <shashikant.hirugade@modusbox.com>
29
-
30
- --------------
31
-
32
- ******/
33
- 'use strict'
34
-
35
- /**
36
- * @module src/metrics/plugin
37
- */
38
-
39
- /**
40
- * @function Register Handler Routes HAPI
41
- *
42
- * @async
43
- * @description Registers registers plugins on HAPI server. This retrieves all routes to be exposed from the routes.js file
44
- * @returns {Promise} - Returns a promise: resolve if successful, or rejection if failed
45
- */
46
-
47
- exports.plugin = {
48
- name: 'handler metrics routes',
49
- register: function (server) {
50
- server.route(require('./routes'))
51
- }
52
- }
@@ -1,43 +0,0 @@
1
- /*****
2
- License
3
- --------------
4
- Copyright © 2017 Bill & Melinda Gates Foundation
5
- The Mojaloop files are made available by the Bill & Melinda Gates 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
- Contributors
9
- --------------
10
- This is the official list of the Mojaloop project contributors for this file.
11
- Names of the original copyright holders (individuals or organizations)
12
- should be listed with a '*' in the first column. People who have
13
- contributed from an organization can be listed under the organization
14
- that actually holds the copyright for their contributions (see the
15
- Gates Foundation organization for an example). Those individuals should have
16
- their names indented and be marked with a '-'. Email address can be added
17
- optionally within square brackets <email>.
18
- * Gates Foundation
19
- - Name Surname <name.surname@gatesfoundation.com>
20
-
21
- - Pedro Barreto <pedrob@crosslaketech.com>
22
- - Rajiv Mothilal <rajivmothilal@gmail.com>
23
- - Shashikant Hirugade <shashikant.hirugade@modusbox.com>
24
- --------------
25
- ******/
26
-
27
- 'use strict'
28
-
29
- const Handler = require('./handler')
30
- const tags = ['api', 'metrics']
31
-
32
- module.exports = [
33
- {
34
- method: 'GET',
35
- path: '/metrics',
36
- handler: Handler.metrics,
37
- config: {
38
- tags,
39
- description: 'Prometheus metrics endpoint',
40
- id: 'metrics'
41
- }
42
- }
43
- ]
@@ -1,115 +0,0 @@
1
- /*****
2
- License
3
- --------------
4
- Copyright © 2017 Bill & Melinda Gates Foundation
5
- The Mojaloop files are made available by the Bill & Melinda Gates 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
- Contributors
9
- --------------
10
- This is the official list of the Mojaloop project contributors for this file.
11
- Names of the original copyright holders (individuals or organizations)
12
- should be listed with a '*' in the first column. People who have
13
- contributed from an organization can be listed under the organization
14
- that actually holds the copyright for their contributions (see the
15
- Gates Foundation organization for an example). Those individuals should have
16
- their names indented and be marked with a '-'. Email address can be added
17
- optionally within square brackets <email>.
18
- * Gates Foundation
19
- - Name Surname <name.surname@gatesfoundation.com>
20
-
21
- * Crosslake
22
- - Lewis Daly <lewisd@crosslaketech.com>
23
-
24
- --------------
25
- ******/
26
-
27
- 'use strict'
28
-
29
- const Sinon = require('sinon')
30
- const ErrorHandler = require('@mojaloop/central-services-error-handling')
31
-
32
- const requestLogger = require('../../../src/lib/requestLogger')
33
- const { logger } = require('../../../src/lib')
34
- const fixtures = require('../../fixtures')
35
-
36
- let sandbox
37
-
38
- describe('requestLogger', () => {
39
- beforeEach(() => {
40
- sandbox = Sinon.createSandbox()
41
- })
42
-
43
- afterEach(() => {
44
- sandbox.restore()
45
- })
46
-
47
- describe('logRequest', () => {
48
- it('prints the request.payload if it exists', async () => {
49
- // Arrange
50
- const infoSpy = sandbox.spy(logger.mlLogger, 'info')
51
- const req = {
52
- ...fixtures.mockHapiRequestDto(),
53
- url: {
54
- path: '/123/456'
55
- },
56
- query: {},
57
- payload: {
58
- itemA: 123,
59
- itemB: 456
60
- }
61
- }
62
-
63
- // Act
64
- requestLogger.logRequest(req)
65
-
66
- // Assert
67
- expect(infoSpy.calledOnce).toBe(true)
68
- const logLine = infoSpy.firstCall.args[0]
69
- expect(logLine).toContain(JSON.stringify(req.headers))
70
- expect(logLine).toContain(JSON.stringify(req.query))
71
- expect(logLine).toContain(JSON.stringify(req.payload))
72
- })
73
- })
74
-
75
- describe('logResponse', () => {
76
- it('should log response statusCode', async () => {
77
- // Arrange
78
- const infoSpy = sandbox.spy(logger.mlLogger, 'info')
79
- const req = {
80
- ...fixtures.mockHapiRequestDto(),
81
- response: {
82
- statusCode: 500
83
- }
84
- }
85
-
86
- // Act
87
- requestLogger.logResponse(req)
88
-
89
- // Assert
90
- const logLine = infoSpy.firstCall.args[0]
91
- expect(logLine).toContain(JSON.stringify(req.response.statusCode))
92
- })
93
-
94
- it('handles valid json error response', async () => {
95
- // Arrange
96
- const infoSpy = sandbox.spy(logger.mlLogger, 'info')
97
- const response = ErrorHandler.Factory.createFSPIOPError(ErrorHandler.Enums.FSPIOPErrorCodes.VALIDATION_ERROR, 'Invalid currency code')
98
- const statusCode = 123
99
- response.output = {
100
- statusCode
101
- }
102
- const req = {
103
- ...fixtures.mockHapiRequestDto(),
104
- response
105
- }
106
-
107
- // Act
108
- requestLogger.logResponse(req)
109
-
110
- // Assert
111
- const logLine = infoSpy.firstCall.args[0]
112
- expect(logLine).toContain(JSON.stringify(statusCode))
113
- })
114
- })
115
- })