@mojaloop/sdk-scheme-adapter 24.12.0-snapshot.4 → 24.12.0-snapshot.5

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.
Binary file
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mojaloop/sdk-scheme-adapter-api-svc",
3
- "version": "21.0.0-snapshot.68",
3
+ "version": "21.0.0-snapshot.69",
4
4
  "description": "An adapter for connecting to Mojaloop API enabled switches.",
5
5
  "main": "src/index.js",
6
6
  "types": "src/index.d.ts",
@@ -68,7 +68,7 @@
68
68
  "@mojaloop/central-services-error-handling": "13.1.2",
69
69
  "@mojaloop/central-services-logger": "11.10.0",
70
70
  "@mojaloop/central-services-metrics": "12.7.1",
71
- "@mojaloop/central-services-shared": "18.33.2",
71
+ "@mojaloop/central-services-shared": "18.33.3",
72
72
  "@mojaloop/event-sdk": "14.7.0",
73
73
  "@mojaloop/logging-bc-client-lib": "0.5.8",
74
74
  "@mojaloop/ml-schema-transformer-lib": "2.7.8",
@@ -174,6 +174,10 @@ class InboundApi extends EventEmitter {
174
174
  maxSockets: this._conf.outbound?.maxSockets || 256,
175
175
  });
176
176
 
177
+ // Prevent accidental logging of agent internals
178
+ httpAgent.toJSON = () => ({ type: 'BackendHttpAgent', keepAlive: httpAgent.keepAlive });
179
+ httpsAgent.toJSON = () => ({ type: 'BackendHttpsAgent', keepAlive: httpsAgent.keepAlive });
180
+
177
181
  this._logger.isInfoEnabled && this._logger.info('Created shared HTTP and HTTPS agents for backend requests');
178
182
 
179
183
  return {
@@ -25,7 +25,6 @@
25
25
  --------------
26
26
  ******/
27
27
  const http = require('http');
28
- const https = require('https');
29
28
 
30
29
  const Koa = require('koa');
31
30
  const koaBody = require('koa-body').default;
@@ -113,33 +112,9 @@ class OutboundServer extends EventEmitter {
113
112
  this._logger = logger.push({ app: this.constructor.name });
114
113
  this._server = null;
115
114
 
116
- // Use provided shared Mojaloop agents or create fallback ones
117
- if (mojaloopSharedAgents) {
118
- this._httpAgent = mojaloopSharedAgents.httpAgent;
119
- this._httpsAgent = mojaloopSharedAgents.httpsAgent;
120
- this._logger.isInfoEnabled && this._logger.info('Using shared Mojaloop HTTP and HTTPS agents for OutboundServer');
121
- } else {
122
- // Fallback: Create shared HTTP and HTTPS agents to prevent agent recreation per request
123
- this._httpAgent = new http.Agent({
124
- keepAlive: true,
125
- maxSockets: conf.outbound.maxSockets || 256,
126
- });
127
-
128
- // Create HTTPS agent based on TLS configuration
129
- const httpsAgentOptions = {
130
- keepAlive: true,
131
- maxSockets: conf.outbound.maxSockets || 256,
132
- };
133
-
134
- // Apply TLS configuration if mTLS is enabled
135
- if (conf.outbound.tls.mutualTLS.enabled && conf.outbound.tls.creds) {
136
- Object.assign(httpsAgentOptions, conf.outbound.tls.creds);
137
- }
138
-
139
- this._httpsAgent = new https.Agent(httpsAgentOptions);
140
-
141
- this._logger.isInfoEnabled && this._logger.info('Created fallback shared HTTP and HTTPS agents with keepAlive enabled');
142
- }
115
+ this._httpAgent = mojaloopSharedAgents.httpAgent;
116
+ this._httpsAgent = mojaloopSharedAgents.httpsAgent;
117
+ this._logger.isInfoEnabled && this._logger.info('Using shared Mojaloop HTTP and HTTPS agents for OutboundServer');
143
118
  if (conf.backendEventHandler.enabled) {
144
119
  this._eventLogger = new DefaultLogger(BC_CONFIG.bcName, 'backend-api-handler', '0.0.1', conf.logLevel);
145
120
  this._eventProducer = new KafkaDomainEventProducer(conf.backendEventHandler.domainEventProducer, this._eventLogger);
@@ -299,6 +299,7 @@ class Server extends EventEmitter {
299
299
  this.logger,
300
300
  this.cache,
301
301
  this.wso2,
302
+ this.mojaloopSharedAgents,
302
303
  );
303
304
  this.inboundServer.on('error', (...args) => {
304
305
  const errMessage = 'Unhandled error in Inbound Server';
@@ -324,6 +325,7 @@ class Server extends EventEmitter {
324
325
  this.cache,
325
326
  this.metricsClient,
326
327
  this.wso2,
328
+ this.mojaloopSharedAgents,
327
329
  );
328
330
  this.outboundServer.on('error', (...args) => {
329
331
  const errMessage = 'Unhandled error in Outbound Server';
@@ -474,6 +476,10 @@ class Server extends EventEmitter {
474
476
 
475
477
  const httpsAgent = new https.Agent(httpsAgentOptions);
476
478
 
479
+ // Prevent accidental logging of agent internals
480
+ httpAgent.toJSON = () => ({ type: 'HttpAgent', keepAlive: httpAgent.keepAlive });
481
+ httpsAgent.toJSON = () => ({ type: 'HttpsAgent', keepAlive: httpsAgent.keepAlive });
482
+
477
483
  this.logger.isInfoEnabled && this.logger.info('Created shared HTTP and HTTPS agents for Mojaloop switch communication');
478
484
 
479
485
  return {
@@ -40,6 +40,7 @@ const supertest = require('supertest');
40
40
  const InboundServer = require('../../src/InboundServer');
41
41
  const Cache = require('../../src/lib/cache');
42
42
  const config = require('../../src/config');
43
+ const { createMockSharedAgents } = require('./api/utils');
43
44
  const helpers = require('../helpers');
44
45
  const { logger } = require('../../src/lib/logger');
45
46
 
@@ -56,7 +57,7 @@ describe('Inbound Server ISO-20022 Tests -->', () => {
56
57
  let server;
57
58
 
58
59
  beforeEach(async () => {
59
- server = new InboundServer(config, logger, new Cache(config));
60
+ server = new InboundServer(config, logger, new Cache(config), null, createMockSharedAgents());
60
61
  await server?.start();
61
62
  });
62
63
 
@@ -42,6 +42,7 @@ const postQuotesBody = require('./data/postQuotesBody');
42
42
  const putParticipantsBody = require('./data/putParticipantsBody');
43
43
  const commonHttpHeaders = require('./data/commonHttpHeaders');
44
44
  const isoBodies = require('./inboundApi/data/isoBodies.json');
45
+ const { createMockSharedAgents } = require('./api/utils');
45
46
 
46
47
  jest.mock('@mojaloop/sdk-standard-components');
47
48
  jest.mock('~/lib/cache');
@@ -51,6 +52,9 @@ const { Jws } = require('@mojaloop/sdk-standard-components');
51
52
  const { logger } = require('~/lib/logger');
52
53
  const InboundServer = require('~/InboundServer');
53
54
  const Cache = require('~/lib/cache');
55
+
56
+ // Create shared mock agents for all tests
57
+ const mockSharedAgents = createMockSharedAgents();
54
58
  const path = require('path');
55
59
  const fs = require('fs');
56
60
  const os = require('os');
@@ -74,7 +78,7 @@ describe('Inbound Server', () => {
74
78
  logger: logger.push({ component: 'cache' }),
75
79
  unsubscribeTimeoutMs: serverConfig.unsubscribeTimeoutMs,
76
80
  });
77
- const svr = new InboundServer(serverConfig, logger, cache);
81
+ const svr = new InboundServer(serverConfig, logger, cache, null, mockSharedAgents);
78
82
  await svr.start();
79
83
  await supertest(svr._server)
80
84
  .put('/parties/MSISDN/123456789')
@@ -96,7 +100,7 @@ describe('Inbound Server', () => {
96
100
  const body = contentType.includes(ISO_20022_HEADER_PART)
97
101
  ? isoBodies.putPartiesRequest
98
102
  : putPartiesBody;
99
- const svr = new InboundServer(serverConfig, logger, cache);
103
+ const svr = new InboundServer(serverConfig, logger, cache, null, mockSharedAgents);
100
104
  await svr.start();
101
105
  const result = await supertest(svr._server)
102
106
  .put('/parties/MSISDN/123456789')
@@ -179,7 +183,7 @@ describe('Inbound Server', () => {
179
183
  logger: logger.push({ component: 'cache' }),
180
184
  unsubscribeTimeoutMs: serverConfig.unsubscribeTimeoutMs,
181
185
  });
182
- const svr = new InboundServer(serverConfig, logger, cache);
186
+ const svr = new InboundServer(serverConfig, logger, cache, null, mockSharedAgents);
183
187
  await svr.start();
184
188
  await supertest(svr._server)
185
189
  .post('/quotes')
@@ -199,7 +203,7 @@ describe('Inbound Server', () => {
199
203
  logger: logger.push({ component: 'cache' }),
200
204
  unsubscribeTimeoutMs: serverConfig.unsubscribeTimeoutMs,
201
205
  });
202
- const svr = new InboundServer(serverConfig, logger, cache);
206
+ const svr = new InboundServer(serverConfig, logger, cache, null, mockSharedAgents);
203
207
  await svr.start();
204
208
  const result = await supertest(svr._server)
205
209
  .post('/quotes')
@@ -276,7 +280,7 @@ describe('Inbound Server', () => {
276
280
  logger: logger.push({ component: 'cache' }),
277
281
  unsubscribeTimeoutMs: serverConfig.unsubscribeTimeoutMs,
278
282
  });
279
- const svr = new InboundServer(serverConfig, logger, cache);
283
+ const svr = new InboundServer(serverConfig, logger, cache, null, mockSharedAgents);
280
284
  await svr.start();
281
285
  await supertest(svr._server)
282
286
  .put('/participants/00000000-0000-1000-a000-000000000002')
@@ -296,7 +300,7 @@ describe('Inbound Server', () => {
296
300
  logger: logger.push({ component: 'cache' }),
297
301
  unsubscribeTimeoutMs: serverConfig.unsubscribeTimeoutMs,
298
302
  });
299
- const svr = new InboundServer(serverConfig, logger, cache);
303
+ const svr = new InboundServer(serverConfig, logger, cache, null, mockSharedAgents);
300
304
  await svr.start();
301
305
  const result = await supertest(svr._server)
302
306
  .put('/participants/00000000-0000-1000-a000-000000000002')
@@ -386,7 +390,7 @@ describe('Inbound Server', () => {
386
390
  logger: logger.push({ component: 'cache' }),
387
391
  unsubscribeTimeoutMs: defConfig.unsubscribeTimeoutMs,
388
392
  });
389
- const server = new InboundServer(defConfig, logger, cache);
393
+ const server = new InboundServer(defConfig, logger, cache, null, mockSharedAgents);
390
394
  await server.start();
391
395
  if (enableTls) {
392
396
  expect(httpsServerSpy).toHaveBeenCalled();
@@ -421,7 +425,7 @@ describe('Inbound Server', () => {
421
425
  logger: logger.push({ component: 'cache' }),
422
426
  unsubscribeTimeoutMs: serverConfig.unsubscribeTimeoutMs,
423
427
  });
424
- svr = new InboundServer(serverConfig, logger, cache);
428
+ svr = new InboundServer(serverConfig, logger, cache, null, mockSharedAgents);
425
429
  await svr.start();
426
430
  });
427
431
 
@@ -43,6 +43,7 @@ const TestServer = require('~/TestServer');
43
43
  const Cache = require('~/lib/cache');
44
44
  const InboundServer = require('~/InboundServer');
45
45
  const { logger } = require('~/lib/logger');
46
+ const { createMockSharedAgents } = require('./api/utils');
46
47
 
47
48
  const defaultConfig = require('./data/defaultConfig');
48
49
  const putPartiesBody = require('./data/putPartiesBody');
@@ -83,7 +84,7 @@ describe('Test Server', () => {
83
84
  expect(testServer._server.listening).toBe(true);
84
85
  testReq = supertest.agent(testServer._server);
85
86
 
86
- inboundServer = new InboundServer(serverConfig, logger, cache);
87
+ inboundServer = new InboundServer(serverConfig, logger, cache, null, createMockSharedAgents());
87
88
  await inboundServer.start();
88
89
  inboundReq = supertest(inboundServer._server);
89
90
 
@@ -1,5 +1,7 @@
1
1
  const fs = require('fs');
2
2
  const path = require('path');
3
+ const http = require('http');
4
+ const https = require('https');
3
5
  const yaml = require('js-yaml');
4
6
  const supertest = require('supertest');
5
7
  const { WSO2Auth } = require('@mojaloop/sdk-standard-components');
@@ -16,6 +18,20 @@ const ServerType = {
16
18
  Outbound: 'Outbound',
17
19
  };
18
20
 
21
+ /**
22
+ * Create mock shared agents for testing
23
+ */
24
+ function createMockSharedAgents() {
25
+ const httpAgent = new http.Agent({ keepAlive: true });
26
+ const httpsAgent = new https.Agent({ keepAlive: true });
27
+
28
+ // Prevent logging of agent internals in tests
29
+ httpAgent.toJSON = () => ({ type: 'MockHttpAgent', keepAlive: true });
30
+ httpsAgent.toJSON = () => ({ type: 'MockHttpsAgent', keepAlive: true });
31
+
32
+ return { httpAgent, httpsAgent };
33
+ }
34
+
19
35
  /**
20
36
  * Get OpenAPI spec and Validator for specified server
21
37
  * @param {ServerType} serverType
@@ -69,11 +85,13 @@ const createTestServers = async (config) => {
69
85
  }),
70
86
  retryWso2AuthFailureTimes: defConfig.wso2.requestAuthFailureRetryTimes,
71
87
  };
72
- const serverOutbound = new OutboundServer(defConfig, logger, cache, metricsClient, wso2);
88
+ const mockSharedAgents = createMockSharedAgents();
89
+
90
+ const serverOutbound = new OutboundServer(defConfig, logger, cache, metricsClient, wso2, mockSharedAgents);
73
91
  await serverOutbound.start();
74
92
  const reqOutbound = supertest(serverOutbound._server);
75
93
 
76
- const serverInbound = new InboundServer(defConfig, logger, cache, wso2);
94
+ const serverInbound = new InboundServer(defConfig, logger, cache, wso2, mockSharedAgents);
77
95
  await serverInbound.start();
78
96
  const reqInbound = supertest(serverInbound._server);
79
97
 
@@ -94,4 +112,5 @@ module.exports = {
94
112
  createValidators,
95
113
  createTestServers,
96
114
  destroyTestServers,
115
+ createMockSharedAgents,
97
116
  };
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mojaloop/sdk-scheme-adapter-outbound-command-event-handler",
3
- "version": "0.3.0-snapshot.63",
3
+ "version": "0.3.0-snapshot.64",
4
4
  "description": "Mojaloop sdk scheme adapter command event handler",
5
5
  "license": "Apache-2.0",
6
6
  "homepage": "https://github.com/mojaloop/sdk-scheme-adapter/",
@@ -42,7 +42,7 @@
42
42
  },
43
43
  "dependencies": {
44
44
  "@mojaloop/api-snippets": "18.1.1",
45
- "@mojaloop/central-services-shared": "18.33.2",
45
+ "@mojaloop/central-services-shared": "18.33.3",
46
46
  "@mojaloop/logging-bc-client-lib": "0.5.8",
47
47
  "@mojaloop/logging-bc-public-types-lib": "0.5.6",
48
48
  "@mojaloop/sdk-scheme-adapter-private-shared-lib": "workspace:^",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mojaloop/sdk-scheme-adapter-outbound-domain-event-handler",
3
- "version": "0.3.0-snapshot.63",
3
+ "version": "0.3.0-snapshot.64",
4
4
  "description": "mojaloop sdk scheme adapter outbound domain event handler",
5
5
  "license": "Apache-2.0",
6
6
  "homepage": "https://github.com/mojaloop/sdk-scheme-adapter/",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mojaloop/sdk-scheme-adapter-private-shared-lib",
3
- "version": "0.4.0-snapshot.63",
3
+ "version": "0.4.0-snapshot.64",
4
4
  "description": "SDK Scheme Adapter private shared library.",
5
5
  "license": "Apache-2.0",
6
6
  "homepage": "https://github.com/mojaloop/accounts-and-balances-bc/tree/main/modules/private-types",
@@ -30,7 +30,7 @@
30
30
  },
31
31
  "dependencies": {
32
32
  "@mojaloop/api-snippets": "18.1.1",
33
- "@mojaloop/central-services-shared": "18.33.2",
33
+ "@mojaloop/central-services-shared": "18.33.3",
34
34
  "@mojaloop/logging-bc-public-types-lib": "0.5.6",
35
35
  "@mojaloop/platform-shared-lib-messaging-types-lib": "0.7.3",
36
36
  "@mojaloop/platform-shared-lib-nodejs-kafka-client-lib": "0.5.18",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mojaloop/sdk-scheme-adapter",
3
- "version": "24.12.0-snapshot.4",
3
+ "version": "24.12.0-snapshot.5",
4
4
  "description": "mojaloop sdk-scheme-adapter",
5
5
  "license": "Apache-2.0",
6
6
  "homepage": "https://github.com/mojaloop/sdk-scheme-adapter",