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

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.
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mojaloop/sdk-scheme-adapter-api-svc",
3
- "version": "21.0.0-snapshot.67",
3
+ "version": "21.0.0-snapshot.68",
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",
@@ -76,7 +76,8 @@ const createInboundTransfersModel = (ctx) => new InboundTransfersModel({
76
76
  logger: ctx.state.logger,
77
77
  wso2: ctx.state.wso2,
78
78
  resourceVersions: ctx.resourceVersions,
79
- sharedAgents: ctx.state.sharedAgents,
79
+ backendSharedAgents: ctx.state.backendSharedAgents,
80
+ mojaloopSharedAgents: ctx.state.mojaloopSharedAgents,
80
81
  });
81
82
 
82
83
  const prepareResponse = ctx => {
@@ -48,15 +48,17 @@ const _validator = new Validate({ logExcludePaths });
48
48
  let _initialize;
49
49
 
50
50
  class InboundApi extends EventEmitter {
51
- constructor(conf, logger, cache, validator, wso2) {
51
+ constructor(conf, logger, cache, validator, wso2, mojaloopSharedAgents) {
52
52
  super({ captureExceptions: true });
53
53
  this._conf = conf;
54
54
  this._cache = cache;
55
55
  this._logger = logger;
56
56
  _initialize ||= _validator.initialise(apiSpecs, conf);
57
57
 
58
- // Create shared HTTP and HTTPS agents for backend requests
59
- this.sharedAgents = this._createSharedAgents();
58
+ // Create shared HTTP and HTTPS agents for backend requests only
59
+ this.backendSharedAgents = this._createBackendSharedAgents();
60
+ // Use provided shared Mojaloop agents
61
+ this.mojaloopSharedAgents = mojaloopSharedAgents;
60
62
 
61
63
  if (conf.validateInboundJws) {
62
64
  // peerJWSKey is a special config option specifically for Payment Manager for Mojaloop
@@ -71,7 +73,8 @@ class InboundApi extends EventEmitter {
71
73
  cache,
72
74
  jwsVerificationKeys: this._jwsVerificationKeys,
73
75
  wso2,
74
- sharedAgents: this.sharedAgents,
76
+ backendSharedAgents: this.backendSharedAgents,
77
+ mojaloopSharedAgents: this.mojaloopSharedAgents,
75
78
  });
76
79
  }
77
80
 
@@ -118,7 +121,7 @@ class InboundApi extends EventEmitter {
118
121
  }
119
122
  }
120
123
 
121
- static _SetupApi({ conf, logger, validator, cache, jwsVerificationKeys, wso2, sharedAgents }) {
124
+ static _SetupApi({ conf, logger, validator, cache, jwsVerificationKeys, wso2, backendSharedAgents, mojaloopSharedAgents }) {
122
125
  const api = new Koa();
123
126
 
124
127
  api.use(middlewares.createErrorHandler(logger));
@@ -130,7 +133,7 @@ class InboundApi extends EventEmitter {
130
133
  api.use(middlewares.createJwsValidator(logger, jwsVerificationKeys, jwsExclusions));
131
134
  }
132
135
 
133
- api.use(middlewares.applyState({ conf, cache, wso2, logExcludePaths, sharedAgents }));
136
+ api.use(middlewares.applyState({ conf, cache, wso2, logExcludePaths, backendSharedAgents, mojaloopSharedAgents }));
134
137
  api.use(middlewares.createPingMiddleware(conf, jwsVerificationKeys));
135
138
  api.use(middlewares.createRequestValidator(validator));
136
139
  api.use(middlewares.assignFspiopIdentifier());
@@ -160,36 +163,29 @@ class InboundApi extends EventEmitter {
160
163
  return keys;
161
164
  }
162
165
 
163
- _createSharedAgents() {
166
+ _createBackendSharedAgents() {
164
167
  const httpAgent = new http.Agent({
165
168
  keepAlive: true,
166
169
  maxSockets: this._conf.outbound?.maxSockets || 256,
167
170
  });
168
171
 
169
- // Create HTTPS agent based on TLS configuration
170
- const httpsAgentOptions = {
172
+ const httpsAgent = new https.Agent({
171
173
  keepAlive: true,
172
174
  maxSockets: this._conf.outbound?.maxSockets || 256,
173
- };
174
-
175
- // Apply TLS configuration if mTLS is enabled
176
- if (this._conf.outbound?.tls?.mutualTLS?.enabled && this._conf.outbound?.tls?.creds) {
177
- Object.assign(httpsAgentOptions, this._conf.outbound.tls.creds);
178
- }
179
-
180
- const httpsAgent = new https.Agent(httpsAgentOptions);
175
+ });
181
176
 
182
- this._logger.isInfoEnabled && this._logger.info('Created shared HTTP and HTTPS agents with keepAlive enabled for InboundServer');
177
+ this._logger.isInfoEnabled && this._logger.info('Created shared HTTP and HTTPS agents for backend requests');
183
178
 
184
179
  return {
185
180
  httpAgent,
186
181
  httpsAgent
187
182
  };
188
183
  }
184
+
189
185
  }
190
186
 
191
187
  class InboundServer extends EventEmitter {
192
- constructor(conf, logger, cache, wso2) {
188
+ constructor(conf, logger, cache, wso2, mojaloopSharedAgents) {
193
189
  super({ captureExceptions: true });
194
190
  this._conf = conf;
195
191
  this._logger = logger.push({ app: this.constructor.name });
@@ -199,6 +195,7 @@ class InboundServer extends EventEmitter {
199
195
  cache,
200
196
  _validator,
201
197
  wso2,
198
+ mojaloopSharedAgents,
202
199
  );
203
200
  this._api.on('error', (...args) => {
204
201
  this.emit('error', ...args);
@@ -107,32 +107,39 @@ class OutboundApi extends EventEmitter {
107
107
  }
108
108
 
109
109
  class OutboundServer extends EventEmitter {
110
- constructor(conf, logger, cache, metricsClient, wso2) {
110
+ constructor(conf, logger, cache, metricsClient, wso2, mojaloopSharedAgents) {
111
111
  super({ captureExceptions: true });
112
112
  this._conf = conf;
113
113
  this._logger = logger.push({ app: this.constructor.name });
114
114
  this._server = null;
115
115
 
116
- // Create shared HTTP and HTTPS agents to prevent agent recreation per request
117
- this._httpAgent = new http.Agent({
118
- keepAlive: true,
119
- maxSockets: conf.outbound.maxSockets || 256,
120
- });
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
+ }
121
138
 
122
- // Create HTTPS agent based on TLS configuration
123
- const httpsAgentOptions = {
124
- keepAlive: true,
125
- maxSockets: conf.outbound.maxSockets || 256,
126
- };
139
+ this._httpsAgent = new https.Agent(httpsAgentOptions);
127
140
 
128
- // Apply TLS configuration if mTLS is enabled
129
- if (conf.outbound.tls.mutualTLS.enabled && conf.outbound.tls.creds) {
130
- Object.assign(httpsAgentOptions, conf.outbound.tls.creds);
141
+ this._logger.isInfoEnabled && this._logger.info('Created fallback shared HTTP and HTTPS agents with keepAlive enabled');
131
142
  }
132
-
133
- this._httpsAgent = new https.Agent(httpsAgentOptions);
134
-
135
- this._logger.isInfoEnabled && this._logger.info('Created shared HTTP and HTTPS agents with keepAlive enabled');
136
143
  if (conf.backendEventHandler.enabled) {
137
144
  this._eventLogger = new DefaultLogger(BC_CONFIG.bcName, 'backend-api-handler', '0.0.1', conf.logLevel);
138
145
  this._eventProducer = new KafkaDomainEventProducer(conf.backendEventHandler.domainEventProducer, this._eventLogger);
@@ -27,6 +27,8 @@
27
27
  'use strict';
28
28
 
29
29
  const EventEmitter = require('node:events');
30
+ const http = require('http');
31
+ const https = require('https');
30
32
  const _ = require('lodash');
31
33
  const { name, version } = require('../../../package.json');
32
34
 
@@ -76,6 +78,9 @@ class Server extends EventEmitter {
76
78
  logger: this.logger
77
79
  });
78
80
 
81
+ // Create shared Mojaloop agents for switch communication (used by both servers)
82
+ this.mojaloopSharedAgents = this._createMojaloopSharedAgents();
83
+
79
84
  this.wso2 = createAuthClient(conf, logger);
80
85
  this.wso2.auth.on('error', (msg) => {
81
86
  this.emit('error', 'WSO2 auth error in InboundApi', msg);
@@ -86,6 +91,7 @@ class Server extends EventEmitter {
86
91
  this.logger,
87
92
  this.cache,
88
93
  this.wso2,
94
+ this.mojaloopSharedAgents,
89
95
  );
90
96
  this.inboundServer.on('error', (...args) => {
91
97
  this.logger.isErrorEnabled && this.logger.push({ args }).error('Unhandled error in Inbound Server');
@@ -98,6 +104,7 @@ class Server extends EventEmitter {
98
104
  this.cache,
99
105
  this.metricsClient,
100
106
  this.wso2,
107
+ this.mojaloopSharedAgents,
101
108
  );
102
109
  this.outboundServer.on('error', (...args) => {
103
110
  this.logger.isErrorEnabled && this.logger.push({ args }).error('Unhandled error in Outbound Server');
@@ -447,6 +454,33 @@ class Server extends EventEmitter {
447
454
  this.fspiopEventHandler?.stop(),
448
455
  ]);
449
456
  }
457
+
458
+ _createMojaloopSharedAgents() {
459
+ const httpAgent = new http.Agent({
460
+ keepAlive: true,
461
+ maxSockets: this.conf.outbound?.maxSockets || 256,
462
+ });
463
+
464
+ // Create HTTPS agent based on TLS configuration for Mojaloop switch communication
465
+ const httpsAgentOptions = {
466
+ keepAlive: true,
467
+ maxSockets: this.conf.outbound?.maxSockets || 256,
468
+ };
469
+
470
+ // Apply TLS configuration if mTLS is enabled for switch communication
471
+ if (this.conf.outbound?.tls?.mutualTLS?.enabled && this.conf.outbound?.tls?.creds) {
472
+ Object.assign(httpsAgentOptions, this.conf.outbound.tls.creds);
473
+ }
474
+
475
+ const httpsAgent = new https.Agent(httpsAgentOptions);
476
+
477
+ this.logger.isInfoEnabled && this.logger.info('Created shared HTTP and HTTPS agents for Mojaloop switch communication');
478
+
479
+ return {
480
+ httpAgent,
481
+ httpsAgent
482
+ };
483
+ }
450
484
  }
451
485
 
452
486
  /*
@@ -57,7 +57,7 @@ class InboundTransfersModel {
57
57
  this._getTransferRequestRetry = config.getTransferRequestRetry;
58
58
  this._backendRequestRetry = config.backendRequestRetry;
59
59
 
60
- this._mojaloopRequests = new MojaloopRequests({
60
+ const mojaloopRequestsConfig = {
61
61
  logger: this._logger,
62
62
  peerEndpoint: config.peerEndpoint,
63
63
  alsEndpoint: config.alsEndpoint,
@@ -78,13 +78,22 @@ class InboundTransfersModel {
78
78
  wso2: config.wso2,
79
79
  resourceVersions: config.resourceVersions,
80
80
  apiType: config.apiType,
81
- });
81
+ };
82
+
83
+ // Add shared agents to prevent HTTPS agent recreation per request
84
+ if (config.mojaloopSharedAgents) {
85
+ mojaloopRequestsConfig.httpAgent = config.mojaloopSharedAgents.httpAgent;
86
+ mojaloopRequestsConfig.httpsAgent = config.mojaloopSharedAgents.httpsAgent;
87
+ this._logger.isDebugEnabled && this._logger.debug('Using shared HTTP/HTTPS agents for InboundTransfersModel MojaloopRequests');
88
+ }
89
+
90
+ this._mojaloopRequests = new MojaloopRequests(mojaloopRequestsConfig);
82
91
 
83
92
  this._backendRequests = new BackendRequests({
84
93
  logger: this._logger,
85
94
  backendEndpoint: config.backendEndpoint,
86
95
  dfspId: config.dfspId,
87
- sharedAgents: config.sharedAgents
96
+ sharedAgents: config.backendSharedAgents
88
97
  });
89
98
 
90
99
  this._checkIlp = config.checkIlp;
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mojaloop/sdk-scheme-adapter-outbound-command-event-handler",
3
- "version": "0.3.0-snapshot.62",
3
+ "version": "0.3.0-snapshot.63",
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/",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mojaloop/sdk-scheme-adapter-outbound-domain-event-handler",
3
- "version": "0.3.0-snapshot.62",
3
+ "version": "0.3.0-snapshot.63",
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.62",
3
+ "version": "0.4.0-snapshot.63",
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",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mojaloop/sdk-scheme-adapter",
3
- "version": "24.12.0-snapshot.3",
3
+ "version": "24.12.0-snapshot.4",
4
4
  "description": "mojaloop sdk-scheme-adapter",
5
5
  "license": "Apache-2.0",
6
6
  "homepage": "https://github.com/mojaloop/sdk-scheme-adapter",