@mojaloop/sdk-scheme-adapter 24.14.0 → 24.15.1
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.
- package/CHANGELOG.md +20 -0
- package/CLAUDE.md +2 -0
- package/README.md +17 -0
- package/modules/api-svc/src/InboundServer/handlers.js +1 -1
- package/modules/api-svc/src/SdkServer.js +560 -0
- package/modules/api-svc/src/config.js +4 -0
- package/modules/api-svc/src/index.js +8 -529
- package/modules/api-svc/src/lib/model/OutboundTransfersModel.js +2 -1
- package/modules/api-svc/src/lib/utils.js +27 -3
- package/modules/api-svc/test/unit/{index.configPolling.test.js → SdkServer.configPolling.test.js} +11 -11
- package/modules/api-svc/test/unit/lib/utils.test.js +71 -1
- package/package.json +1 -1
- package/{sbom-v24.13.0.csv → sbom-v24.15.0.csv} +37 -37
package/CHANGELOG.md
CHANGED
|
@@ -1,4 +1,24 @@
|
|
|
1
1
|
# Changelog: [mojaloop/sdk-scheme-adapter](https://github.com/mojaloop/sdk-scheme-adapter)
|
|
2
|
+
### [24.15.1](https://github.com/mojaloop/sdk-scheme-adapter/compare/v24.15.0...v24.15.1) (2025-10-08)
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
### Chore
|
|
6
|
+
|
|
7
|
+
* created a separate file for SdkServer ([#619](https://github.com/mojaloop/sdk-scheme-adapter/issues/619)) ([063087e](https://github.com/mojaloop/sdk-scheme-adapter/commit/063087eefcf63dd293d29d6fb45020490f887daf))
|
|
8
|
+
* **sbom:** update sbom [skip ci] ([b2cf810](https://github.com/mojaloop/sdk-scheme-adapter/commit/b2cf8101be59023e3be7a5da5510eff26c0b7648))
|
|
9
|
+
|
|
10
|
+
## [24.15.0](https://github.com/mojaloop/sdk-scheme-adapter/compare/v24.14.0...v24.15.0) (2025-10-08)
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
### Features
|
|
14
|
+
|
|
15
|
+
* added trace_flags param ([#620](https://github.com/mojaloop/sdk-scheme-adapter/issues/620)) ([f19d92f](https://github.com/mojaloop/sdk-scheme-adapter/commit/f19d92f9b56b7a0f90120c3dc519218927bec0e2))
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
### Chore
|
|
19
|
+
|
|
20
|
+
* **sbom:** update sbom [skip ci] ([7f5f7a5](https://github.com/mojaloop/sdk-scheme-adapter/commit/7f5f7a568085edcf04a5d9ca6103b1e949ba52cf))
|
|
21
|
+
|
|
2
22
|
## [24.14.0](https://github.com/mojaloop/sdk-scheme-adapter/compare/v24.13.0...v24.14.0) (2025-10-08)
|
|
3
23
|
|
|
4
24
|
|
package/CLAUDE.md
CHANGED
|
@@ -21,6 +21,8 @@ The project consists of multiple modules organized using Nx workspace.
|
|
|
21
21
|
|
|
22
22
|
|
|
23
23
|
**Critical File Locations:**
|
|
24
|
+
- Main server class: `modules/api-svc/src/SdkServer.js`
|
|
25
|
+
- Entry point: `modules/api-svc/src/index.js`
|
|
24
26
|
- Models: `modules/api-svc/src/lib/model/`
|
|
25
27
|
- Handlers: `modules/api-svc/src/{Inbound,Outbound}Server/handlers.js`
|
|
26
28
|
- Config: `modules/*/src/config/default.json`
|
package/README.md
CHANGED
|
@@ -159,6 +159,23 @@ _Note that these instructions are for Linux based systems. For Mac and/or Window
|
|
|
159
159
|
|
|
160
160
|
You can now examine the code of the Mock DFSP backend to understand how it implements the scheme-adapter simplified inbound API.
|
|
161
161
|
|
|
162
|
+
|
|
163
|
+
## Observability Configuration
|
|
164
|
+
|
|
165
|
+
### TRACE_FLAGS
|
|
166
|
+
|
|
167
|
+
Controls the trace flags value in the W3C Trace Context `traceparent` header generated by the SDK.
|
|
168
|
+
|
|
169
|
+
- **Environment Variable**: `TRACE_FLAGS`
|
|
170
|
+
- **Format**: Two-character lowercase hexadecimal string (00-ff)
|
|
171
|
+
- **Default**: `01` (sampled flag set)
|
|
172
|
+
- **Example**: `TRACE_FLAGS=00` or `TRACE_FLAGS=01`
|
|
173
|
+
|
|
174
|
+
The trace flags field indicates trace sampling options according to the [W3C Trace Context specification](https://www.w3.org/TR/trace-context/):
|
|
175
|
+
- `00`: No flags set (not sampled)
|
|
176
|
+
- `01`: Sampled flag set (trace should be sampled)
|
|
177
|
+
- Custom values can be used for specific observability requirements
|
|
178
|
+
|
|
162
179
|
## Testing
|
|
163
180
|
|
|
164
181
|
### Unit Tests
|
|
@@ -51,7 +51,7 @@ const extractBodyHeadersSourceFspId = ctx => ({
|
|
|
51
51
|
});
|
|
52
52
|
|
|
53
53
|
const extractTraceHeaders = ctx => {
|
|
54
|
-
const { traceparent = generateTraceparent(), tracestate } = ctx.request.headers;
|
|
54
|
+
const { traceparent = generateTraceparent(undefined, ctx.state.conf.traceFlags), tracestate } = ctx.request.headers;
|
|
55
55
|
|
|
56
56
|
const traceHeaders = {
|
|
57
57
|
traceparent,
|
|
@@ -0,0 +1,560 @@
|
|
|
1
|
+
/*****
|
|
2
|
+
License
|
|
3
|
+
--------------
|
|
4
|
+
Copyright © 2020-2025 Mojaloop Foundation
|
|
5
|
+
The Mojaloop files are made available by the Mojaloop 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
|
+
Mojaloop Foundation 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
|
+
* Mojaloop Foundation
|
|
23
|
+
* Eugen Klymniuk <eugen.klymniuk@infitx.com>
|
|
24
|
+
|
|
25
|
+
--------------
|
|
26
|
+
******/
|
|
27
|
+
|
|
28
|
+
'use strict';
|
|
29
|
+
|
|
30
|
+
const EventEmitter = require('node:events');
|
|
31
|
+
const http = require('node:http');
|
|
32
|
+
const https = require('node:https');
|
|
33
|
+
const _ = require('lodash');
|
|
34
|
+
|
|
35
|
+
const InboundServer = require('./InboundServer');
|
|
36
|
+
const OutboundServer = require('./OutboundServer');
|
|
37
|
+
const OAuthTestServer = require('./OAuthTestServer');
|
|
38
|
+
const { BackendEventHandler } = require('./BackendEventHandler');
|
|
39
|
+
const { FSPIOPEventHandler } = require('./FSPIOPEventHandler');
|
|
40
|
+
const { MetricsServer, MetricsClient } = require('./lib/metrics');
|
|
41
|
+
const TestServer = require('./TestServer');
|
|
42
|
+
const ControlAgent = require('./ControlAgent');
|
|
43
|
+
|
|
44
|
+
const Cache = require('./lib/cache');
|
|
45
|
+
const { createAuthClient } = require('./lib/utils');
|
|
46
|
+
const { logger } = require('./lib/logger');
|
|
47
|
+
|
|
48
|
+
const PING_INTERVAL_MS = 30_000;
|
|
49
|
+
|
|
50
|
+
const createCache = (config) => new Cache({
|
|
51
|
+
logger,
|
|
52
|
+
cacheUrl: config.cacheUrl,
|
|
53
|
+
enableTestFeatures: config.enableTestFeatures,
|
|
54
|
+
subscribeTimeoutSeconds: config.requestProcessingTimeoutSeconds,
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Class that creates and manages http servers that expose the SDK Scheme Adapter APIs.
|
|
59
|
+
*/
|
|
60
|
+
class SdkServer extends EventEmitter {
|
|
61
|
+
constructor(conf, logger) {
|
|
62
|
+
super({ captureExceptions: true });
|
|
63
|
+
this.conf = conf;
|
|
64
|
+
this.logger = logger;
|
|
65
|
+
this.cache = createCache(conf);
|
|
66
|
+
|
|
67
|
+
this.metricsClient = new MetricsClient();
|
|
68
|
+
this.metricsServer = new MetricsServer({
|
|
69
|
+
port: this.conf.metrics.port,
|
|
70
|
+
logger: this.logger
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
// Create shared Mojaloop agents for switch communication (used by both servers)
|
|
74
|
+
this.mojaloopSharedAgents = this._createMojaloopSharedAgents(this.conf);
|
|
75
|
+
|
|
76
|
+
this.oidc = createAuthClient(conf, logger);
|
|
77
|
+
this.oidc.auth.on('error', (msg) => {
|
|
78
|
+
this.emit('error', 'OIDC auth error in InboundApi', msg);
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
this.inboundServer = new InboundServer(
|
|
82
|
+
this.conf,
|
|
83
|
+
this.logger,
|
|
84
|
+
this.cache,
|
|
85
|
+
this.oidc,
|
|
86
|
+
this.mojaloopSharedAgents,
|
|
87
|
+
);
|
|
88
|
+
this.inboundServer.on('error', (...args) => {
|
|
89
|
+
this.logger.isErrorEnabled && this.logger.push({ args }).error('Unhandled error in Inbound Server');
|
|
90
|
+
this.emit('error', 'Unhandled error in Inbound Server');
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
this.outboundServer = new OutboundServer(
|
|
94
|
+
this.conf,
|
|
95
|
+
this.logger,
|
|
96
|
+
this.cache,
|
|
97
|
+
this.metricsClient,
|
|
98
|
+
this.oidc,
|
|
99
|
+
this.mojaloopSharedAgents,
|
|
100
|
+
);
|
|
101
|
+
this.outboundServer.on('error', (...args) => {
|
|
102
|
+
this.logger.isErrorEnabled && this.logger.push({ args }).error('Unhandled error in Outbound Server');
|
|
103
|
+
this.emit('error', 'Unhandled error in Outbound Server');
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
if (this.conf.oauthTestServer.enabled) {
|
|
107
|
+
this.oauthTestServer = new OAuthTestServer({
|
|
108
|
+
clientKey: this.conf.oauthTestServer.clientKey,
|
|
109
|
+
clientSecret: this.conf.oauthTestServer.clientSecret,
|
|
110
|
+
port: this.conf.oauthTestServer.listenPort,
|
|
111
|
+
logger: this.logger,
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
if (this.conf.enableTestFeatures) {
|
|
116
|
+
this.testServer = new TestServer({
|
|
117
|
+
config: this.conf,
|
|
118
|
+
port: this.conf.test.port,
|
|
119
|
+
logger: this.logger,
|
|
120
|
+
cache: this.cache,
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
if (this.conf.backendEventHandler.enabled) {
|
|
125
|
+
this.backendEventHandler = new BackendEventHandler({
|
|
126
|
+
config: this.conf,
|
|
127
|
+
logger: this.logger,
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
if (this.conf.fspiopEventHandler.enabled) {
|
|
132
|
+
this.fspiopEventHandler = new FSPIOPEventHandler({
|
|
133
|
+
config: this.conf,
|
|
134
|
+
logger: this.logger,
|
|
135
|
+
cache: this.cache,
|
|
136
|
+
oidc: this.oidc,
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
_shouldUpdateInboundServer(newConf) {
|
|
142
|
+
const isInboundDifferent = !_.isEqual(this.conf.inbound, newConf.inbound);
|
|
143
|
+
const isOutboundDifferent = !_.isEqual(this.conf.outbound, newConf.outbound);
|
|
144
|
+
const isPeerJWSKeysDifferent = !_.isEqual(this.conf.peerJWSKeys, newConf.peerJWSKeys);
|
|
145
|
+
const isJwsSigningKeyDifferent = !_.isEqual(this.conf.jwsSigningKey, newConf.jwsSigningKey);
|
|
146
|
+
|
|
147
|
+
if (isInboundDifferent) {
|
|
148
|
+
this.logger.debug('Inbound config is different', {
|
|
149
|
+
oldInbound: this.conf.inbound,
|
|
150
|
+
newInbound: newConf.inbound
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
if (isOutboundDifferent) {
|
|
154
|
+
this.logger.debug('Outbound config is different (checked in inbound update)', {
|
|
155
|
+
oldOutbound: this.conf.outbound,
|
|
156
|
+
newOutbound: newConf.outbound
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
if (isPeerJWSKeysDifferent) {
|
|
161
|
+
this.logger.debug('Peer JWS Keys config is different', {
|
|
162
|
+
oldPeerJWSKeys: this.conf.peerJWSKeys,
|
|
163
|
+
newPeerJWSKeys: newConf.peerJWSKeys
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
if (isJwsSigningKeyDifferent) {
|
|
168
|
+
this.logger.debug('JWS Signing Key config is different', {
|
|
169
|
+
oldJwsSigningKey: this.conf.jwsSigningKey,
|
|
170
|
+
newJwsSigningKey: newConf.jwsSigningKey
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
return isInboundDifferent || isOutboundDifferent || isPeerJWSKeysDifferent || isJwsSigningKeyDifferent;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
_shouldUpdateOutboundServer(newConf) {
|
|
178
|
+
const isOutboundDifferent = !_.isEqual(this.conf.outbound, newConf.outbound);
|
|
179
|
+
const isJwsSigningKeyDifferent = !_.isEqual(this.conf.jwsSigningKey, newConf.jwsSigningKey);
|
|
180
|
+
|
|
181
|
+
if (isOutboundDifferent) {
|
|
182
|
+
this.logger.debug('Outbound config is different', {
|
|
183
|
+
oldOutbound: this.conf.outbound,
|
|
184
|
+
newOutbound: newConf.outbound
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
if (isJwsSigningKeyDifferent) {
|
|
189
|
+
this.logger.debug('JWS Signing Key config is different', {
|
|
190
|
+
oldJwsSigningKey: this.conf.jwsSigningKey,
|
|
191
|
+
newJwsSigningKey: newConf.jwsSigningKey
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
return isOutboundDifferent || isJwsSigningKeyDifferent;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* Starts periodic polling of Management API for configuration updates.
|
|
200
|
+
* Only runs if PM4ML enabled and a polling interval configured.
|
|
201
|
+
*/
|
|
202
|
+
_startConfigPolling() {
|
|
203
|
+
if (!this.conf.pm4mlEnabled || !this.conf.control.mgmtAPIPollIntervalMs) {
|
|
204
|
+
this.logger.info('No failsafe config polling configured');
|
|
205
|
+
return;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
this.logger.info('starting failsafe config polling from Management API...', { intervalMs: this.conf.control.mgmtAPIPollIntervalMs });
|
|
209
|
+
|
|
210
|
+
this._configPollInterval = setInterval(
|
|
211
|
+
() => this._pollConfigFromMgmtAPI(),
|
|
212
|
+
this.conf.control.mgmtAPIPollIntervalMs
|
|
213
|
+
);
|
|
214
|
+
|
|
215
|
+
// Unref so it doesn't prevent process exit
|
|
216
|
+
this._configPollInterval.unref();
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
/**
|
|
220
|
+
* Polls Management API for configuration updates.
|
|
221
|
+
* Reuses the existing persistent WebSocket client (this.controlClient).
|
|
222
|
+
* Skips polling if:
|
|
223
|
+
* - Another config update is in progress
|
|
224
|
+
* - WebSocket client is not connected
|
|
225
|
+
*/
|
|
226
|
+
async _pollConfigFromMgmtAPI() {
|
|
227
|
+
// Race condition prevention: skip if restart in progress
|
|
228
|
+
if (this._configUpdateInProgress) {
|
|
229
|
+
this.logger.info('config updating already in progress, skipping poll');
|
|
230
|
+
return;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
// WebSocket readyState: 0=CONNECTING, 1=OPEN, 2=CLOSING, 3=CLOSED
|
|
234
|
+
if (this.controlClient?.readyState !== 1) {
|
|
235
|
+
this.logger.warn('Control client not ready (not OPEN), skipping poll', { readyState: this.controlClient?.readyState });
|
|
236
|
+
return;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
try {
|
|
240
|
+
const newConfig = await this.controlClient.getUpdatedConfig();
|
|
241
|
+
if (!newConfig) {
|
|
242
|
+
this.logger.warn('No config received from polling');
|
|
243
|
+
return;
|
|
244
|
+
}
|
|
245
|
+
this.logger.verbose('polling config from mgmt-api is done, checking for config changes...');
|
|
246
|
+
|
|
247
|
+
const mergedConfig = _.merge({}, this.conf, newConfig);
|
|
248
|
+
await this.restart(mergedConfig, { source: 'polling' });
|
|
249
|
+
} catch (err) {
|
|
250
|
+
this.logger.error('error in polling config from Management API: ', err);
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
/** Stops the config polling interval. */
|
|
255
|
+
_stopConfigPolling() {
|
|
256
|
+
if (this._configPollInterval) {
|
|
257
|
+
this.logger.verbose('stopping config polling');
|
|
258
|
+
clearInterval(this._configPollInterval);
|
|
259
|
+
this._configPollInterval = null;
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
async start() {
|
|
264
|
+
await this.cache.connect();
|
|
265
|
+
await this.oidc.auth.start();
|
|
266
|
+
|
|
267
|
+
// We only start the control client if we're running within Mojaloop Payment Manager.
|
|
268
|
+
// The control server is the Payment Manager Management API Service.
|
|
269
|
+
// We only start the client to connect to and listen to the Management API service for
|
|
270
|
+
// management protocol messages e.g configuration changes, certificate updates etc.
|
|
271
|
+
if (this.conf.pm4mlEnabled) {
|
|
272
|
+
const RESTART_INTERVAL_MS = 10000;
|
|
273
|
+
this.controlClient = await ControlAgent.createConnectedControlAgentWs(this.conf, this.logger);
|
|
274
|
+
this.controlClient.on(ControlAgent.EVENT.RECONFIGURE, this.restart.bind(this));
|
|
275
|
+
|
|
276
|
+
const schedulePing = () => {
|
|
277
|
+
clearTimeout(this.pingTimeout);
|
|
278
|
+
this.pingTimeout = setTimeout(() => {
|
|
279
|
+
this.logger.error('Ping timeout, possible broken connection. Restarting server...');
|
|
280
|
+
this.restart(_.merge({}, this.conf, {
|
|
281
|
+
control: { stopped: Date.now() }
|
|
282
|
+
}));
|
|
283
|
+
}, PING_INTERVAL_MS + this.conf.control.mgmtAPILatencyAssumption);
|
|
284
|
+
};
|
|
285
|
+
|
|
286
|
+
this.controlClient.on('ping', () => {
|
|
287
|
+
this.logger.debug('Received ping from control server');
|
|
288
|
+
schedulePing();
|
|
289
|
+
});
|
|
290
|
+
|
|
291
|
+
this.controlClient.on('close', () => {
|
|
292
|
+
clearTimeout(this.pingTimeout);
|
|
293
|
+
setTimeout(() => {
|
|
294
|
+
this.logger.debug('Control client closed. Restarting server...');
|
|
295
|
+
this.restart(_.merge({}, this.conf, {
|
|
296
|
+
control: { stopped: Date.now() }
|
|
297
|
+
}));
|
|
298
|
+
}, RESTART_INTERVAL_MS);
|
|
299
|
+
});
|
|
300
|
+
|
|
301
|
+
schedulePing();
|
|
302
|
+
this._startConfigPolling();
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
await Promise.all([
|
|
306
|
+
this.inboundServer.start(),
|
|
307
|
+
this.outboundServer.start(),
|
|
308
|
+
this.metricsServer.start(),
|
|
309
|
+
this.testServer?.start(),
|
|
310
|
+
this.oauthTestServer?.start(),
|
|
311
|
+
this.backendEventHandler?.start(),
|
|
312
|
+
this.fspiopEventHandler?.start(),
|
|
313
|
+
]);
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
async restart(newConf, options = {}) {
|
|
317
|
+
const source = options.source || 'websocket'; // Track source of restart call - websocket or polling
|
|
318
|
+
|
|
319
|
+
// Race condition prevention
|
|
320
|
+
if (this._configUpdateInProgress) {
|
|
321
|
+
this.logger.info('restart already in progress, skipping', { source });
|
|
322
|
+
return;
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
const restartActionsTaken = {};
|
|
326
|
+
this.logger.debug('Server is restarting...', { source });
|
|
327
|
+
this._configUpdateInProgress = true;
|
|
328
|
+
|
|
329
|
+
try {
|
|
330
|
+
let oldCache;
|
|
331
|
+
const updateCache = !_.isEqual(this.conf.cacheUrl, newConf.cacheUrl)
|
|
332
|
+
|| !_.isEqual(this.conf.enableTestFeatures, newConf.enableTestFeatures);
|
|
333
|
+
if (updateCache) {
|
|
334
|
+
oldCache = this.cache;
|
|
335
|
+
await this.cache.disconnect();
|
|
336
|
+
this.cache = createCache(newConf);
|
|
337
|
+
await this.cache.connect();
|
|
338
|
+
restartActionsTaken.updateCache = true;
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
const updateOIDC = !_.isEqual(this.conf.oidc, newConf.oidc)
|
|
342
|
+
|| !_.isEqual(this.conf.outbound.tls, newConf.outbound.tls);
|
|
343
|
+
if (updateOIDC) {
|
|
344
|
+
this.oidc.auth.stop();
|
|
345
|
+
this.oidc = createAuthClient(newConf, this.logger);
|
|
346
|
+
this.oidc.auth.on('error', (msg) => {
|
|
347
|
+
this.emit('error', 'OIDC auth error in InboundApi', msg);
|
|
348
|
+
});
|
|
349
|
+
await this.oidc.auth.start();
|
|
350
|
+
restartActionsTaken.updateOIDC = true;
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
this.logger.isDebugEnabled && this.logger.push({ oldConf: this.conf.inbound, newConf: newConf.inbound }).debug('Inbound server configuration');
|
|
354
|
+
const updateInboundServer = this._shouldUpdateInboundServer(newConf);
|
|
355
|
+
if (updateInboundServer) {
|
|
356
|
+
const stopStartLabel = 'InboundServer stop/start duration';
|
|
357
|
+
// eslint-disable-next-line no-console
|
|
358
|
+
console.time(stopStartLabel); // todo: remove console.time
|
|
359
|
+
await this.inboundServer.stop();
|
|
360
|
+
|
|
361
|
+
this.mojaloopSharedAgents = this._createMojaloopSharedAgents(newConf);
|
|
362
|
+
this.inboundServer = new InboundServer(
|
|
363
|
+
newConf,
|
|
364
|
+
this.logger,
|
|
365
|
+
this.cache,
|
|
366
|
+
this.oidc,
|
|
367
|
+
this.mojaloopSharedAgents,
|
|
368
|
+
);
|
|
369
|
+
this.inboundServer.on('error', (...args) => {
|
|
370
|
+
const errMessage = 'Unhandled error in Inbound Server';
|
|
371
|
+
this.logger.push({ args }).error(errMessage);
|
|
372
|
+
this.emit('error', errMessage);
|
|
373
|
+
});
|
|
374
|
+
await this.inboundServer.start();
|
|
375
|
+
// eslint-disable-next-line no-console
|
|
376
|
+
console.timeEnd(stopStartLabel);
|
|
377
|
+
restartActionsTaken.updateInboundServer = true;
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
this.logger.isDebugEnabled && this.logger.push({ oldConf: this.conf.outbound, newConf: newConf.outbound }).debug('Outbound server configuration');
|
|
381
|
+
const updateOutboundServer = this._shouldUpdateOutboundServer(newConf);
|
|
382
|
+
if (updateOutboundServer) {
|
|
383
|
+
const stopStartLabel = 'OutboundServer stop/start duration';
|
|
384
|
+
// eslint-disable-next-line no-console
|
|
385
|
+
console.time(stopStartLabel);
|
|
386
|
+
await this.outboundServer.stop();
|
|
387
|
+
|
|
388
|
+
this.mojaloopSharedAgents = this._createMojaloopSharedAgents(newConf);
|
|
389
|
+
this.outboundServer = new OutboundServer(
|
|
390
|
+
newConf,
|
|
391
|
+
this.logger,
|
|
392
|
+
this.cache,
|
|
393
|
+
this.metricsClient,
|
|
394
|
+
this.oidc,
|
|
395
|
+
this.mojaloopSharedAgents,
|
|
396
|
+
);
|
|
397
|
+
this.outboundServer.on('error', (...args) => {
|
|
398
|
+
const errMessage = 'Unhandled error in Outbound Server';
|
|
399
|
+
this.logger.push({ args }).error(errMessage);
|
|
400
|
+
this.emit('error', errMessage);
|
|
401
|
+
});
|
|
402
|
+
await this.outboundServer.start();
|
|
403
|
+
// eslint-disable-next-line no-console
|
|
404
|
+
console.timeEnd(stopStartLabel);
|
|
405
|
+
restartActionsTaken.updateOutboundServer = true;
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
const updateFspiopEventHandler = !_.isEqual(this.conf.outbound, newConf.outbound)
|
|
409
|
+
&& this.conf.fspiopEventHandler.enabled;
|
|
410
|
+
if (updateFspiopEventHandler) {
|
|
411
|
+
await this.fspiopEventHandler.stop();
|
|
412
|
+
this.fspiopEventHandler = new FSPIOPEventHandler({
|
|
413
|
+
config: newConf,
|
|
414
|
+
logger: this.logger,
|
|
415
|
+
cache: this.cache,
|
|
416
|
+
oidc: this.oidc,
|
|
417
|
+
});
|
|
418
|
+
await this.fspiopEventHandler.start();
|
|
419
|
+
restartActionsTaken.updateFspiopEventHandler = true;
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
const updateControlClient = !_.isEqual(this.conf.control, newConf.control);
|
|
423
|
+
if (updateControlClient) {
|
|
424
|
+
await this.controlClient?.stop();
|
|
425
|
+
if (this.conf.pm4mlEnabled) {
|
|
426
|
+
const RESTART_INTERVAL_MS = 10000;
|
|
427
|
+
|
|
428
|
+
const schedulePing = () => {
|
|
429
|
+
clearTimeout(this.pingTimeout);
|
|
430
|
+
this.pingTimeout = setTimeout(() => {
|
|
431
|
+
this.logger.error('Ping timeout, possible broken connection. Restarting server...');
|
|
432
|
+
this.restart(_.merge({}, newConf, {
|
|
433
|
+
control: { stopped: Date.now() }
|
|
434
|
+
}));
|
|
435
|
+
}, PING_INTERVAL_MS + this.conf.control.mgmtAPILatencyAssumption);
|
|
436
|
+
};
|
|
437
|
+
|
|
438
|
+
schedulePing();
|
|
439
|
+
|
|
440
|
+
this.controlClient = await ControlAgent.createConnectedControlAgentWs(newConf, this.logger);
|
|
441
|
+
this.controlClient.on(ControlAgent.EVENT.RECONFIGURE, this.restart.bind(this));
|
|
442
|
+
|
|
443
|
+
this.controlClient.on('ping', () => {
|
|
444
|
+
this.logger.debug('Received ping from control server');
|
|
445
|
+
schedulePing();
|
|
446
|
+
});
|
|
447
|
+
|
|
448
|
+
this.controlClient.on('close', () => {
|
|
449
|
+
clearTimeout(this.pingTimeout);
|
|
450
|
+
setTimeout(() => {
|
|
451
|
+
this.logger.debug('Control client closed. Restarting server...');
|
|
452
|
+
this.restart(_.merge({}, newConf, {
|
|
453
|
+
control: { stopped: Date.now() }
|
|
454
|
+
}));
|
|
455
|
+
}, RESTART_INTERVAL_MS);
|
|
456
|
+
});
|
|
457
|
+
|
|
458
|
+
restartActionsTaken.updateControlClient = true;
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
const updateOAuthTestServer = !_.isEqual(newConf.oauthTestServer, this.conf.oauthTestServer);
|
|
463
|
+
if (updateOAuthTestServer) {
|
|
464
|
+
await this.oauthTestServer?.stop();
|
|
465
|
+
if (this.conf.oauthTestServer.enabled) {
|
|
466
|
+
this.oauthTestServer = new OAuthTestServer({
|
|
467
|
+
clientKey: newConf.oauthTestServer.clientKey,
|
|
468
|
+
clientSecret: newConf.oauthTestServer.clientSecret,
|
|
469
|
+
port: newConf.oauthTestServer.listenPort,
|
|
470
|
+
logger: this.logger,
|
|
471
|
+
});
|
|
472
|
+
await this.oauthTestServer.start();
|
|
473
|
+
restartActionsTaken.updateOAuthTestServer = true;
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
const updateTestServer = !_.isEqual(newConf.test.port, this.conf.test.port);
|
|
478
|
+
if (updateTestServer) {
|
|
479
|
+
await this.testServer?.stop();
|
|
480
|
+
if (this.conf.enableTestFeatures) {
|
|
481
|
+
this.testServer = new TestServer({
|
|
482
|
+
port: newConf.test.port,
|
|
483
|
+
logger: this.logger,
|
|
484
|
+
cache: this.cache,
|
|
485
|
+
config: newConf.test,
|
|
486
|
+
});
|
|
487
|
+
await this.testServer.start();
|
|
488
|
+
restartActionsTaken.updateTestServer = true;
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
this.conf = newConf;
|
|
493
|
+
|
|
494
|
+
await oldCache?.disconnect();
|
|
495
|
+
|
|
496
|
+
if (Object.keys(restartActionsTaken).length > 0) {
|
|
497
|
+
this.logger.info('Server is restarted', { restartActionsTaken, source });
|
|
498
|
+
} else {
|
|
499
|
+
this.logger.verbose('Server not restarted, no config changes detected', { source });
|
|
500
|
+
}
|
|
501
|
+
} catch (err) {
|
|
502
|
+
this.logger.error('error in Server restart: ', err);
|
|
503
|
+
} finally {
|
|
504
|
+
this._configUpdateInProgress = false;
|
|
505
|
+
}
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
stop() {
|
|
509
|
+
this._stopConfigPolling();
|
|
510
|
+
|
|
511
|
+
clearTimeout(this.pingTimeout);
|
|
512
|
+
this.oidc.auth.stop();
|
|
513
|
+
this.controlClient?.removeAllListeners();
|
|
514
|
+
this.inboundServer.removeAllListeners();
|
|
515
|
+
return Promise.all([
|
|
516
|
+
this.cache.disconnect(),
|
|
517
|
+
this.inboundServer.stop(),
|
|
518
|
+
this.outboundServer.stop(),
|
|
519
|
+
this.metricsServer.stop(),
|
|
520
|
+
this.oauthTestServer?.stop(),
|
|
521
|
+
this.testServer?.stop(),
|
|
522
|
+
this.controlClient?.stop(),
|
|
523
|
+
this.backendEventHandler?.stop(),
|
|
524
|
+
this.fspiopEventHandler?.stop(),
|
|
525
|
+
]);
|
|
526
|
+
}
|
|
527
|
+
|
|
528
|
+
_createMojaloopSharedAgents(conf) {
|
|
529
|
+
const httpAgent = new http.Agent({
|
|
530
|
+
keepAlive: true,
|
|
531
|
+
maxSockets: conf.outbound?.maxSockets || 256,
|
|
532
|
+
});
|
|
533
|
+
|
|
534
|
+
// Create HTTPS agent based on TLS configuration for Mojaloop switch communication
|
|
535
|
+
const httpsAgentOptions = {
|
|
536
|
+
keepAlive: true,
|
|
537
|
+
maxSockets: conf.outbound?.maxSockets || 256,
|
|
538
|
+
};
|
|
539
|
+
|
|
540
|
+
// Apply TLS configuration if mTLS is enabled for switch communication
|
|
541
|
+
if (conf.outbound?.tls?.mutualTLS?.enabled && conf.outbound?.tls?.creds) {
|
|
542
|
+
Object.assign(httpsAgentOptions, conf.outbound.tls.creds);
|
|
543
|
+
}
|
|
544
|
+
|
|
545
|
+
const httpsAgent = new https.Agent(httpsAgentOptions);
|
|
546
|
+
|
|
547
|
+
// Prevent accidental logging of agent internals
|
|
548
|
+
httpAgent.toJSON = () => ({ type: 'HttpAgent', keepAlive: httpAgent.keepAlive });
|
|
549
|
+
httpsAgent.toJSON = () => ({ type: 'HttpsAgent', keepAlive: httpsAgent.keepAlive });
|
|
550
|
+
|
|
551
|
+
this.logger.isInfoEnabled && this.logger.info('Created shared HTTP and HTTPS agents for Mojaloop switch communication');
|
|
552
|
+
|
|
553
|
+
return {
|
|
554
|
+
httpAgent,
|
|
555
|
+
httpsAgent
|
|
556
|
+
};
|
|
557
|
+
}
|
|
558
|
+
}
|
|
559
|
+
|
|
560
|
+
module.exports = SdkServer;
|
|
@@ -282,4 +282,8 @@ module.exports = {
|
|
|
282
282
|
backoffFactor: env.get('GET_TRANSFER_REQUEST_RETRY_BACKOFF_FACTOR').default('2').asIntPositive(),
|
|
283
283
|
},
|
|
284
284
|
patchNotificationGraceTimeMs: env.get('PATCH_NOTIFICATION_GRACE_TIME_MS').default('15000').asIntPositive(),
|
|
285
|
+
|
|
286
|
+
// W3C Trace Context specification - trace flags for traceparent header
|
|
287
|
+
// Must be a two-character lowercase hex string (00-ff)
|
|
288
|
+
traceFlags: env.get('TRACE_FLAGS').default('01').asString(),
|
|
285
289
|
};
|