@mojaloop/central-services-shared 18.22.2-snapshot.2 → 18.22.2
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 +7 -0
- package/audit-ci.jsonc +1 -1
- package/package.json +3 -3
- package/src/util/endpoints.js +18 -29
- package/src/util/participants.js +24 -30
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
|
4
4
|
|
|
5
|
+
### [18.22.2](https://github.com/mojaloop/central-services-shared/compare/v18.22.1...v18.22.2) (2025-03-12)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Chore
|
|
9
|
+
|
|
10
|
+
* fix dependency loop ([#441](https://github.com/mojaloop/central-services-shared/issues/441)) ([13fa3a5](https://github.com/mojaloop/central-services-shared/commit/13fa3a533f96503ba8dce56c26846b5014f9e103))
|
|
11
|
+
|
|
5
12
|
### [18.22.1](https://github.com/mojaloop/central-services-shared/compare/v18.22.0...v18.22.1) (2025-03-07)
|
|
6
13
|
|
|
7
14
|
|
package/audit-ci.jsonc
CHANGED
|
@@ -5,6 +5,6 @@
|
|
|
5
5
|
"moderate": true,
|
|
6
6
|
"allowlist": [ // NOTE: Please add as much information as possible to any items added to the allowList
|
|
7
7
|
// e.g. Currently no fixes available for the following
|
|
8
|
-
"GHSA-jr5f-v2jv-69x6" //
|
|
8
|
+
"GHSA-jr5f-v2jv-69x6" // temporarily add for fixing the dependency loop central-services-shared => sdk-standard-components => ml-schema-transformer-lib
|
|
9
9
|
]
|
|
10
10
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mojaloop/central-services-shared",
|
|
3
|
-
"version": "18.22.2
|
|
3
|
+
"version": "18.22.2",
|
|
4
4
|
"description": "Shared code for mojaloop central services",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": "ModusBox",
|
|
@@ -64,7 +64,6 @@
|
|
|
64
64
|
"@hapi/hapi": "21.4.0",
|
|
65
65
|
"@hapi/joi-date": "2.0.1",
|
|
66
66
|
"@mojaloop/inter-scheme-proxy-cache-lib": "2.3.7",
|
|
67
|
-
"@mojaloop/sdk-standard-components": "19.10.0",
|
|
68
67
|
"axios": "1.8.2",
|
|
69
68
|
"clone": "2.1.2",
|
|
70
69
|
"dotenv": "16.4.7",
|
|
@@ -86,13 +85,14 @@
|
|
|
86
85
|
"yaml": "2.7.0"
|
|
87
86
|
},
|
|
88
87
|
"devDependencies": {
|
|
88
|
+
"@mojaloop/sdk-standard-components": "19.10.0",
|
|
89
89
|
"@types/hapi__joi": "17.1.15",
|
|
90
90
|
"audit-ci": "7.1.0",
|
|
91
91
|
"base64url": "3.0.1",
|
|
92
92
|
"chance": "1.1.12",
|
|
93
93
|
"npm-check-updates": "17.1.15",
|
|
94
94
|
"nyc": "17.1.0",
|
|
95
|
-
"portfinder": "1.0.
|
|
95
|
+
"portfinder": "1.0.34",
|
|
96
96
|
"pre-commit": "1.2.2",
|
|
97
97
|
"proxyquire": "2.1.3",
|
|
98
98
|
"replace": "1.2.2",
|
package/src/util/endpoints.js
CHANGED
|
@@ -29,6 +29,7 @@
|
|
|
29
29
|
|
|
30
30
|
'use strict'
|
|
31
31
|
|
|
32
|
+
const Logger = require('@mojaloop/central-services-logger')
|
|
32
33
|
const ErrorHandler = require('@mojaloop/central-services-error-handling')
|
|
33
34
|
const Metrics = require('@mojaloop/central-services-metrics')
|
|
34
35
|
const proxyLib = require('@mojaloop/inter-scheme-proxy-cache-lib')
|
|
@@ -37,7 +38,6 @@ const CatboxMemory = require('@hapi/catbox-memory')
|
|
|
37
38
|
const Mustache = require('mustache')
|
|
38
39
|
const { Map } = require('immutable')
|
|
39
40
|
|
|
40
|
-
const logger = require('../logger').logger.child({ component: 'participantEndpointCache' })
|
|
41
41
|
const Enum = require('../enums')
|
|
42
42
|
const Http = require('./http')
|
|
43
43
|
const request = require('./request')
|
|
@@ -66,9 +66,8 @@ const fetchEndpoints = async (fsp) => {
|
|
|
66
66
|
'fetchParticipants - Metrics for fetchParticipants',
|
|
67
67
|
['success']
|
|
68
68
|
).startTimer()
|
|
69
|
-
const log = logger.child({ fsp, method: 'fetchEndpoints' })
|
|
70
69
|
try {
|
|
71
|
-
|
|
70
|
+
Logger.isDebugEnabled && Logger.debug(`[fsp=${fsp}] ~ participantEndpointCache::fetchEndpoints := Refreshing the cache for FSP: ${fsp}`)
|
|
72
71
|
if (!hubName) {
|
|
73
72
|
throw Error('"hubName" is not initialized. Initialize the cache first.')
|
|
74
73
|
}
|
|
@@ -77,8 +76,7 @@ const fetchEndpoints = async (fsp) => {
|
|
|
77
76
|
}
|
|
78
77
|
const defaultHeaders = Http.SwitchDefaultHeaders(hubName, Enum.Http.HeaderResources.PARTICIPANTS, hubName)
|
|
79
78
|
const url = Mustache.render(switchEndpoint + Enum.EndPoints.FspEndpointTemplates.PARTICIPANT_ENDPOINTS_GET, { fsp })
|
|
80
|
-
|
|
81
|
-
|
|
79
|
+
Logger.isDebugEnabled && Logger.debug(`[fsp=${fsp}] ~ participantEndpointCache::fetchEndpoints := URL for FSP: ${url}`)
|
|
82
80
|
const response = await request.sendRequest({
|
|
83
81
|
url,
|
|
84
82
|
headers: defaultHeaders,
|
|
@@ -86,9 +84,8 @@ const fetchEndpoints = async (fsp) => {
|
|
|
86
84
|
destination: hubName,
|
|
87
85
|
hubNameRegex
|
|
88
86
|
})
|
|
87
|
+
Logger.isDebugEnabled && Logger.debug(`[fsp=${fsp}] ~ Model::participantEndpoint::fetchEndpoints := successful with body: ${JSON.stringify(response.data)}`)
|
|
89
88
|
const endpoints = response.data
|
|
90
|
-
log.debug('fetchEndpoints raw response.data:', { endpoints })
|
|
91
|
-
|
|
92
89
|
const endpointMap = {}
|
|
93
90
|
if (Array.isArray(endpoints)) {
|
|
94
91
|
endpoints.forEach(item => {
|
|
@@ -96,12 +93,12 @@ const fetchEndpoints = async (fsp) => {
|
|
|
96
93
|
endpointMap[item.type] = item.value
|
|
97
94
|
})
|
|
98
95
|
}
|
|
99
|
-
|
|
96
|
+
Logger.isDebugEnabled && Logger.debug(`[fsp=${fsp}] ~ participantEndpointCache::fetchEndpoints := Returning the endpoints: ${JSON.stringify(endpointMap)}`)
|
|
100
97
|
histTimer({ success: true })
|
|
101
|
-
|
|
102
98
|
return endpointMap
|
|
103
|
-
} catch (
|
|
104
|
-
|
|
99
|
+
} catch (e) {
|
|
100
|
+
histTimer({ success: false })
|
|
101
|
+
Logger.isErrorEnabled && Logger.error(`participantEndpointCache::fetchEndpoints:: ERROR:'${e}'`)
|
|
105
102
|
}
|
|
106
103
|
}
|
|
107
104
|
|
|
@@ -119,17 +116,18 @@ const fetchEndpoints = async (fsp) => {
|
|
|
119
116
|
*/
|
|
120
117
|
exports.initializeCache = async (policyOptions, config) => {
|
|
121
118
|
try {
|
|
122
|
-
|
|
119
|
+
Logger.isDebugEnabled && Logger.debug(`participantEndpointCache::initializeCache::start::clientOptions - ${JSON.stringify(clientOptions)}`)
|
|
123
120
|
client = new Catbox.Client(CatboxMemory, clientOptions)
|
|
124
121
|
await client.start()
|
|
125
122
|
policyOptions.generateFunc = fetchEndpoints
|
|
123
|
+
Logger.isDebugEnabled && Logger.debug(`participantEndpointCache::initializeCache::start::policyOptions - ${JSON.stringify(policyOptions)}`)
|
|
126
124
|
policy = new Catbox.Policy(policyOptions, client, partition)
|
|
125
|
+
Logger.isDebugEnabled && Logger.debug('participantEndpointCache::initializeCache::Cache initialized successfully')
|
|
127
126
|
hubName = config.hubName
|
|
128
127
|
hubNameRegex = config.hubNameRegex
|
|
129
|
-
logger.verbose('initializeCache is done successfully', { hubName, hubNameRegex })
|
|
130
128
|
return true
|
|
131
129
|
} catch (err) {
|
|
132
|
-
|
|
130
|
+
Logger.isErrorEnabled && Logger.error(`participantEndpointCache::Cache error:: ERROR:'${err}'`)
|
|
133
131
|
throw ErrorHandler.Factory.reformatFSPIOPError(err)
|
|
134
132
|
}
|
|
135
133
|
}
|
|
@@ -154,11 +152,9 @@ exports.getEndpoint = async (switchUrl, fsp, endpointType, options = {}, renderO
|
|
|
154
152
|
['success', 'hit']
|
|
155
153
|
).startTimer()
|
|
156
154
|
switchEndpoint = switchUrl
|
|
157
|
-
|
|
158
|
-
log.debug('getEndpoint start', { switchUrl })
|
|
155
|
+
Logger.isDebugEnabled && Logger.debug(`participantEndpointCache::getEndpoint::endpointType - ${endpointType}`)
|
|
159
156
|
let proxyId
|
|
160
157
|
const result = url => proxyConfig?.enabled ? { url, proxyId } : url
|
|
161
|
-
|
|
162
158
|
try {
|
|
163
159
|
// If a service passes in `getDecoratedValue` as true, then an object
|
|
164
160
|
// { value, cached, report } is returned, where value is the cached value,
|
|
@@ -172,11 +168,7 @@ exports.getEndpoint = async (switchUrl, fsp, endpointType, options = {}, renderO
|
|
|
172
168
|
proxyId = await proxy.lookupProxyByDfspId(fsp)
|
|
173
169
|
endpoints = proxyId && await policy.get(proxyId)
|
|
174
170
|
}
|
|
175
|
-
if (!endpoints)
|
|
176
|
-
log.warn('no endpoints found for fsp')
|
|
177
|
-
throw ErrorHandler.CreateFSPIOPError(ErrorHandler.Enums.FSPIOPErrorCodes.PARTY_NOT_FOUND)
|
|
178
|
-
}
|
|
179
|
-
|
|
171
|
+
if (!endpoints) throw ErrorHandler.CreateFSPIOPError(ErrorHandler.Enums.FSPIOPErrorCodes.PARTY_NOT_FOUND)
|
|
180
172
|
if ('value' in endpoints && 'cached' in endpoints) {
|
|
181
173
|
if (endpoints.cached === null) {
|
|
182
174
|
histTimer({ success: true, hit: false })
|
|
@@ -190,7 +182,6 @@ exports.getEndpoint = async (switchUrl, fsp, endpointType, options = {}, renderO
|
|
|
190
182
|
}
|
|
191
183
|
return result(Mustache.render(endpoint, options))
|
|
192
184
|
}
|
|
193
|
-
|
|
194
185
|
let endpoint = new Map(endpoints).get(endpointType)
|
|
195
186
|
if (renderOptions.path) {
|
|
196
187
|
endpoint = (endpoint === undefined) ? endpoint : endpoint + renderOptions.path
|
|
@@ -199,7 +190,7 @@ exports.getEndpoint = async (switchUrl, fsp, endpointType, options = {}, renderO
|
|
|
199
190
|
return result(Mustache.render(endpoint, options))
|
|
200
191
|
} catch (err) {
|
|
201
192
|
histTimer({ success: false, hit: false })
|
|
202
|
-
|
|
193
|
+
Logger.isErrorEnabled && Logger.error(`participantEndpointCache::getEndpoint:: ERROR:'${err}'`)
|
|
203
194
|
throw ErrorHandler.Factory.reformatFSPIOPError(err)
|
|
204
195
|
}
|
|
205
196
|
}
|
|
@@ -224,8 +215,7 @@ exports.getEndpointAndRender = async (switchUrl, fsp, endpointType, path = '', o
|
|
|
224
215
|
['success']
|
|
225
216
|
).startTimer()
|
|
226
217
|
switchEndpoint = switchUrl
|
|
227
|
-
|
|
228
|
-
log.debug('getEndpointAndRender start', { switchUrl, path })
|
|
218
|
+
Logger.isDebugEnabled && Logger.debug(`participantEndpointCache::getEndpointAndRender::endpointType - ${endpointType}`)
|
|
229
219
|
|
|
230
220
|
try {
|
|
231
221
|
const endpoint = exports.getEndpoint(switchUrl, fsp, endpointType, options, { path })
|
|
@@ -233,7 +223,7 @@ exports.getEndpointAndRender = async (switchUrl, fsp, endpointType, path = '', o
|
|
|
233
223
|
return endpoint
|
|
234
224
|
} catch (err) {
|
|
235
225
|
histTimer({ success: false })
|
|
236
|
-
|
|
226
|
+
Logger.isErrorEnabled && Logger.error(`participantEndpointCache::getEndpointAndRender:: ERROR:'${err}'`)
|
|
237
227
|
throw ErrorHandler.Factory.reformatFSPIOPError(err)
|
|
238
228
|
}
|
|
239
229
|
}
|
|
@@ -246,7 +236,7 @@ exports.getEndpointAndRender = async (switchUrl, fsp, endpointType, path = '', o
|
|
|
246
236
|
* @returns {boolean} - Returns the status
|
|
247
237
|
*/
|
|
248
238
|
exports.stopCache = async () => {
|
|
249
|
-
|
|
239
|
+
Logger.isDebugEnabled && Logger.debug('participantEndpointCache::stopCache::Stopping the cache')
|
|
250
240
|
if (client) {
|
|
251
241
|
return client.stop()
|
|
252
242
|
}
|
|
@@ -262,7 +252,6 @@ exports.stopCache = async () => {
|
|
|
262
252
|
exports.stopProxy = async () => {
|
|
263
253
|
const result = await proxy?.disconnect()
|
|
264
254
|
proxy = undefined
|
|
265
|
-
logger.verbose('proxy disconnected')
|
|
266
255
|
return result
|
|
267
256
|
}
|
|
268
257
|
|
package/src/util/participants.js
CHANGED
|
@@ -28,19 +28,17 @@
|
|
|
28
28
|
|
|
29
29
|
'use strict'
|
|
30
30
|
|
|
31
|
-
const
|
|
32
|
-
const Metrics = require('@mojaloop/central-services-metrics')
|
|
31
|
+
const Logger = require('@mojaloop/central-services-logger')
|
|
33
32
|
const Catbox = require('@hapi/catbox')
|
|
34
33
|
const CatboxMemory = require('@hapi/catbox-memory')
|
|
35
|
-
const Mustache = require('mustache')
|
|
36
|
-
|
|
37
|
-
const logger = require('../logger').logger.child({ component: 'participantCache' })
|
|
38
|
-
const Enum = require('../enums')
|
|
39
34
|
const Http = require('./http')
|
|
40
|
-
const
|
|
41
|
-
|
|
35
|
+
const Enum = require('../enums')
|
|
42
36
|
const partition = 'participant-cache'
|
|
43
37
|
const clientOptions = { partition }
|
|
38
|
+
const Mustache = require('mustache')
|
|
39
|
+
const request = require('./request')
|
|
40
|
+
const ErrorHandler = require('@mojaloop/central-services-error-handling')
|
|
41
|
+
const Metrics = require('@mojaloop/central-services-metrics')
|
|
44
42
|
|
|
45
43
|
let client
|
|
46
44
|
let policy
|
|
@@ -63,10 +61,8 @@ const fetchParticipant = async (fsp) => {
|
|
|
63
61
|
'fetchParticipant - Metrics for fetchParticipant',
|
|
64
62
|
['success']
|
|
65
63
|
).startTimer()
|
|
66
|
-
const log = logger.child({ fsp, method: 'fetchParticipant' })
|
|
67
|
-
|
|
68
64
|
try {
|
|
69
|
-
|
|
65
|
+
Logger.isDebugEnabled && Logger.debug('participantCache::fetchParticipant := Refreshing participant cache')
|
|
70
66
|
if (!hubName) {
|
|
71
67
|
throw Error('"hubName" is not initialized. Initialize the cache first.')
|
|
72
68
|
}
|
|
@@ -75,8 +71,7 @@ const fetchParticipant = async (fsp) => {
|
|
|
75
71
|
}
|
|
76
72
|
const defaultHeaders = Http.SwitchDefaultHeaders(hubName, Enum.Http.HeaderResources.PARTICIPANTS, hubName)
|
|
77
73
|
const url = Mustache.render(switchEndpoint + Enum.EndPoints.FspEndpointTemplates.PARTICIPANTS_GET, { fsp })
|
|
78
|
-
|
|
79
|
-
|
|
74
|
+
Logger.isDebugEnabled && Logger.debug(`participantCache::fetchParticipant := URL: ${url}`)
|
|
80
75
|
const response = await request.sendRequest({
|
|
81
76
|
url,
|
|
82
77
|
headers: defaultHeaders,
|
|
@@ -85,14 +80,12 @@ const fetchParticipant = async (fsp) => {
|
|
|
85
80
|
hubNameRegex
|
|
86
81
|
})
|
|
87
82
|
const participant = response.data
|
|
88
|
-
log.verbose('returning the participant', { participant })
|
|
89
83
|
histTimer({ success: true })
|
|
90
|
-
|
|
91
84
|
return participant
|
|
92
|
-
} catch (
|
|
85
|
+
} catch (e) {
|
|
93
86
|
histTimer({ success: false })
|
|
94
87
|
// We're logging this as a "warning" rather than "error" because the participant might be a proxied participant
|
|
95
|
-
|
|
88
|
+
Logger.isWarnEnabled && Logger.warn(`participantCache::fetchParticipants:: WARNING:'${e}'`)
|
|
96
89
|
}
|
|
97
90
|
}
|
|
98
91
|
|
|
@@ -106,17 +99,18 @@ const fetchParticipant = async (fsp) => {
|
|
|
106
99
|
*/
|
|
107
100
|
exports.initializeCache = async (policyOptions, config) => {
|
|
108
101
|
try {
|
|
109
|
-
|
|
102
|
+
Logger.isDebugEnabled && Logger.debug(`participantCache::initializeCache::start::clientOptions - ${JSON.stringify(clientOptions)}`)
|
|
110
103
|
client = new Catbox.Client(CatboxMemory, clientOptions)
|
|
111
104
|
await client.start()
|
|
112
105
|
policyOptions.generateFunc = fetchParticipant
|
|
106
|
+
Logger.isDebugEnabled && Logger.debug(`participantCache::initializeCache::start::policyOptions - ${JSON.stringify(policyOptions)}`)
|
|
113
107
|
policy = new Catbox.Policy(policyOptions, client, partition)
|
|
108
|
+
Logger.isDebugEnabled && Logger.debug('participantCache::initializeCache::Cache initialized successfully')
|
|
114
109
|
hubName = config.hubName
|
|
115
110
|
hubNameRegex = config.hubNameRegex
|
|
116
|
-
logger.verbose('participantCache::initializeCache is done', { hubName })
|
|
117
111
|
return true
|
|
118
112
|
} catch (err) {
|
|
119
|
-
|
|
113
|
+
Logger.isErrorEnabled && Logger.error(`participantCache::Cache error:: ERROR:'${err}'`)
|
|
120
114
|
throw ErrorHandler.Factory.reformatFSPIOPError(err)
|
|
121
115
|
}
|
|
122
116
|
}
|
|
@@ -138,8 +132,7 @@ exports.getParticipant = async (switchUrl, fsp) => {
|
|
|
138
132
|
['success', 'hit']
|
|
139
133
|
).startTimer()
|
|
140
134
|
switchEndpoint = switchUrl
|
|
141
|
-
|
|
142
|
-
log.debug('getParticipant start', { switchUrl })
|
|
135
|
+
Logger.isDebugEnabled && Logger.debug('participantCache::getParticipant')
|
|
143
136
|
try {
|
|
144
137
|
// If a service passes in `getDecoratedValue` as true, then an object
|
|
145
138
|
// { value, cached, report } is returned, where value is the cached value,
|
|
@@ -147,7 +140,11 @@ exports.getParticipant = async (switchUrl, fsp) => {
|
|
|
147
140
|
let participant = await policy.get(fsp)
|
|
148
141
|
|
|
149
142
|
if ('value' in participant && 'cached' in participant) {
|
|
150
|
-
|
|
143
|
+
if (participant.cached === null) {
|
|
144
|
+
histTimer({ success: true, hit: false })
|
|
145
|
+
} else {
|
|
146
|
+
histTimer({ success: true, hit: true })
|
|
147
|
+
}
|
|
151
148
|
participant = participant.value
|
|
152
149
|
} else {
|
|
153
150
|
histTimer({ success: true, hit: false })
|
|
@@ -155,10 +152,9 @@ exports.getParticipant = async (switchUrl, fsp) => {
|
|
|
155
152
|
|
|
156
153
|
/* istanbul ignore next */
|
|
157
154
|
if (!participant) {
|
|
158
|
-
|
|
155
|
+
Logger.isWarnEnabled && Logger.warn('participantCache::getParticipant - no participant found')
|
|
159
156
|
return null
|
|
160
157
|
}
|
|
161
|
-
log.verbose('getParticipant result:', { participant })
|
|
162
158
|
|
|
163
159
|
if (participant.errorInformation) {
|
|
164
160
|
// Drop error from cache
|
|
@@ -168,7 +164,7 @@ exports.getParticipant = async (switchUrl, fsp) => {
|
|
|
168
164
|
return participant
|
|
169
165
|
} catch (err) {
|
|
170
166
|
histTimer({ success: false, hit: false })
|
|
171
|
-
|
|
167
|
+
Logger.isErrorEnabled && Logger.error(`participantCache::getParticipant:: ERROR:'${err}'`)
|
|
172
168
|
throw ErrorHandler.Factory.reformatFSPIOPError(err)
|
|
173
169
|
}
|
|
174
170
|
}
|
|
@@ -180,9 +176,8 @@ exports.getParticipant = async (switchUrl, fsp) => {
|
|
|
180
176
|
*
|
|
181
177
|
* @returns {void}
|
|
182
178
|
*/
|
|
183
|
-
/* istanbul ignore next */
|
|
184
179
|
exports.invalidateParticipantCache = async (fsp) => {
|
|
185
|
-
|
|
180
|
+
Logger.isDebugEnabled && Logger.debug('participantCache::invalidateParticipantCache::Invalidating the cache')
|
|
186
181
|
if (policy) {
|
|
187
182
|
return policy.drop(fsp)
|
|
188
183
|
}
|
|
@@ -195,9 +190,8 @@ exports.invalidateParticipantCache = async (fsp) => {
|
|
|
195
190
|
*
|
|
196
191
|
* @returns {boolean} - Returns the status
|
|
197
192
|
*/
|
|
198
|
-
/* istanbul ignore next */
|
|
199
193
|
exports.stopCache = async () => {
|
|
200
|
-
|
|
194
|
+
Logger.isDebugEnabled && Logger.debug('participantCache::stopCache::Stopping the cache')
|
|
201
195
|
if (client) {
|
|
202
196
|
return client.stop()
|
|
203
197
|
}
|