@mojaloop/sdk-scheme-adapter 24.12.0-snapshot.2 → 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.66",
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",
@@ -56,7 +56,8 @@ class BackendEventHandler {
56
56
  this._backendRequests = new BackendRequests({
57
57
  logger: this._logger,
58
58
  backendEndpoint: config.backendEndpoint,
59
- dfspId: config.dfspId
59
+ dfspId: config.dfspId,
60
+ sharedAgents: config.sharedAgents
60
61
  });
61
62
  }
62
63
 
@@ -76,6 +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
+ backendSharedAgents: ctx.state.backendSharedAgents,
80
+ mojaloopSharedAgents: ctx.state.mojaloopSharedAgents,
79
81
  });
80
82
 
81
83
  const prepareResponse = ctx => {
@@ -48,13 +48,18 @@ 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 only
59
+ this.backendSharedAgents = this._createBackendSharedAgents();
60
+ // Use provided shared Mojaloop agents
61
+ this.mojaloopSharedAgents = mojaloopSharedAgents;
62
+
58
63
  if (conf.validateInboundJws) {
59
64
  // peerJWSKey is a special config option specifically for Payment Manager for Mojaloop
60
65
  // that is populated by a management api.
@@ -68,6 +73,8 @@ class InboundApi extends EventEmitter {
68
73
  cache,
69
74
  jwsVerificationKeys: this._jwsVerificationKeys,
70
75
  wso2,
76
+ backendSharedAgents: this.backendSharedAgents,
77
+ mojaloopSharedAgents: this.mojaloopSharedAgents,
71
78
  });
72
79
  }
73
80
 
@@ -114,7 +121,7 @@ class InboundApi extends EventEmitter {
114
121
  }
115
122
  }
116
123
 
117
- static _SetupApi({ conf, logger, validator, cache, jwsVerificationKeys, wso2 }) {
124
+ static _SetupApi({ conf, logger, validator, cache, jwsVerificationKeys, wso2, backendSharedAgents, mojaloopSharedAgents }) {
118
125
  const api = new Koa();
119
126
 
120
127
  api.use(middlewares.createErrorHandler(logger));
@@ -126,7 +133,7 @@ class InboundApi extends EventEmitter {
126
133
  api.use(middlewares.createJwsValidator(logger, jwsVerificationKeys, jwsExclusions));
127
134
  }
128
135
 
129
- api.use(middlewares.applyState({ conf, cache, wso2, logExcludePaths }));
136
+ api.use(middlewares.applyState({ conf, cache, wso2, logExcludePaths, backendSharedAgents, mojaloopSharedAgents }));
130
137
  api.use(middlewares.createPingMiddleware(conf, jwsVerificationKeys));
131
138
  api.use(middlewares.createRequestValidator(validator));
132
139
  api.use(middlewares.assignFspiopIdentifier());
@@ -155,10 +162,30 @@ class InboundApi extends EventEmitter {
155
162
  }
156
163
  return keys;
157
164
  }
165
+
166
+ _createBackendSharedAgents() {
167
+ const httpAgent = new http.Agent({
168
+ keepAlive: true,
169
+ maxSockets: this._conf.outbound?.maxSockets || 256,
170
+ });
171
+
172
+ const httpsAgent = new https.Agent({
173
+ keepAlive: true,
174
+ maxSockets: this._conf.outbound?.maxSockets || 256,
175
+ });
176
+
177
+ this._logger.isInfoEnabled && this._logger.info('Created shared HTTP and HTTPS agents for backend requests');
178
+
179
+ return {
180
+ httpAgent,
181
+ httpsAgent
182
+ };
183
+ }
184
+
158
185
  }
159
186
 
160
187
  class InboundServer extends EventEmitter {
161
- constructor(conf, logger, cache, wso2) {
188
+ constructor(conf, logger, cache, wso2, mojaloopSharedAgents) {
162
189
  super({ captureExceptions: true });
163
190
  this._conf = conf;
164
191
  this._logger = logger.push({ app: this.constructor.name });
@@ -168,6 +195,7 @@ class InboundServer extends EventEmitter {
168
195
  cache,
169
196
  _validator,
170
197
  wso2,
198
+ mojaloopSharedAgents,
171
199
  );
172
200
  this._api.on('error', (...args) => {
173
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,12 +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
- dfspId: config.dfspId
95
+ dfspId: config.dfspId,
96
+ sharedAgents: config.backendSharedAgents
87
97
  });
88
98
 
89
99
  this._checkIlp = config.checkIlp;
@@ -37,7 +37,27 @@ class BackendRequests {
37
37
  constructor(config) {
38
38
  this.config = config;
39
39
  this.logger = config.logger.push({ component: this.constructor.name });
40
- this.requester = createHttpRequester({ logger: this.logger });
40
+
41
+ // Create HTTP requester with shared agents if available
42
+ const httpConfig = {
43
+ timeout: 65000,
44
+ withCredentials: false,
45
+ transitional: {
46
+ clarifyTimeoutError: true,
47
+ }
48
+ };
49
+
50
+ // Add shared agents to prevent connection recreation per request
51
+ if (config.sharedAgents) {
52
+ httpConfig.httpAgent = config.sharedAgents.httpAgent;
53
+ httpConfig.httpsAgent = config.sharedAgents.httpsAgent;
54
+ this.logger.isDebugEnabled && this.logger.debug('Using shared HTTP/HTTPS agents for BackendRequests');
55
+ }
56
+
57
+ this.requester = createHttpRequester({
58
+ logger: this.logger,
59
+ httpConfig
60
+ });
41
61
 
42
62
  // FSPID of THIS DFSP
43
63
  this.dfspId = config.dfspId;
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mojaloop/sdk-scheme-adapter-outbound-command-event-handler",
3
- "version": "0.3.0-snapshot.61",
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.61",
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.61",
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.2",
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",