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

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.65",
3
+ "version": "21.0.0-snapshot.67",
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,7 @@ 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
80
  });
80
81
 
81
82
  const prepareResponse = ctx => {
@@ -55,6 +55,9 @@ class InboundApi extends EventEmitter {
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();
60
+
58
61
  if (conf.validateInboundJws) {
59
62
  // peerJWSKey is a special config option specifically for Payment Manager for Mojaloop
60
63
  // that is populated by a management api.
@@ -68,6 +71,7 @@ class InboundApi extends EventEmitter {
68
71
  cache,
69
72
  jwsVerificationKeys: this._jwsVerificationKeys,
70
73
  wso2,
74
+ sharedAgents: this.sharedAgents,
71
75
  });
72
76
  }
73
77
 
@@ -114,7 +118,7 @@ class InboundApi extends EventEmitter {
114
118
  }
115
119
  }
116
120
 
117
- static _SetupApi({ conf, logger, validator, cache, jwsVerificationKeys, wso2 }) {
121
+ static _SetupApi({ conf, logger, validator, cache, jwsVerificationKeys, wso2, sharedAgents }) {
118
122
  const api = new Koa();
119
123
 
120
124
  api.use(middlewares.createErrorHandler(logger));
@@ -126,7 +130,7 @@ class InboundApi extends EventEmitter {
126
130
  api.use(middlewares.createJwsValidator(logger, jwsVerificationKeys, jwsExclusions));
127
131
  }
128
132
 
129
- api.use(middlewares.applyState({ conf, cache, wso2, logExcludePaths }));
133
+ api.use(middlewares.applyState({ conf, cache, wso2, logExcludePaths, sharedAgents }));
130
134
  api.use(middlewares.createPingMiddleware(conf, jwsVerificationKeys));
131
135
  api.use(middlewares.createRequestValidator(validator));
132
136
  api.use(middlewares.assignFspiopIdentifier());
@@ -155,6 +159,33 @@ class InboundApi extends EventEmitter {
155
159
  }
156
160
  return keys;
157
161
  }
162
+
163
+ _createSharedAgents() {
164
+ const httpAgent = new http.Agent({
165
+ keepAlive: true,
166
+ maxSockets: this._conf.outbound?.maxSockets || 256,
167
+ });
168
+
169
+ // Create HTTPS agent based on TLS configuration
170
+ const httpsAgentOptions = {
171
+ keepAlive: true,
172
+ 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);
181
+
182
+ this._logger.isInfoEnabled && this._logger.info('Created shared HTTP and HTTPS agents with keepAlive enabled for InboundServer');
183
+
184
+ return {
185
+ httpAgent,
186
+ httpsAgent
187
+ };
188
+ }
158
189
  }
159
190
 
160
191
  class InboundServer extends EventEmitter {
@@ -83,7 +83,8 @@ class InboundTransfersModel {
83
83
  this._backendRequests = new BackendRequests({
84
84
  logger: this._logger,
85
85
  backendEndpoint: config.backendEndpoint,
86
- dfspId: config.dfspId
86
+ dfspId: config.dfspId,
87
+ sharedAgents: config.sharedAgents
87
88
  });
88
89
 
89
90
  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;
@@ -263,7 +283,7 @@ class BackendRequests {
263
283
  async sendRequest(reqOptions) {
264
284
  try {
265
285
  this.logger.isVerboseEnabled && this.logger.push({ reqOptions }).verbose(`Executing HTTP ${reqOptions?.method}...`);
266
- const res = await this.requester.sendRequest({ ...reqOptions, agent: this.agent });
286
+ const res = await this.requester.sendRequest({ ...reqOptions });
267
287
 
268
288
  const data = (res.headers['content-length'] === '0' || res.statusCode === 204)
269
289
  ? null
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mojaloop/sdk-scheme-adapter-outbound-command-event-handler",
3
- "version": "0.3.0-snapshot.60",
3
+ "version": "0.3.0-snapshot.62",
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.60",
3
+ "version": "0.3.0-snapshot.62",
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.60",
3
+ "version": "0.4.0-snapshot.62",
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.1",
3
+ "version": "24.12.0-snapshot.3",
4
4
  "description": "mojaloop sdk-scheme-adapter",
5
5
  "license": "Apache-2.0",
6
6
  "homepage": "https://github.com/mojaloop/sdk-scheme-adapter",