@mojaloop/central-services-shared 18.22.1 → 18.22.2-snapshot.0
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/audit-ci.jsonc +1 -0
- package/package.json +2 -2
- package/src/util/endpoints.js +29 -18
package/audit-ci.jsonc
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mojaloop/central-services-shared",
|
|
3
|
-
"version": "18.22.
|
|
3
|
+
"version": "18.22.2-snapshot.0",
|
|
4
4
|
"description": "Shared code for mojaloop central services",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": "ModusBox",
|
|
@@ -64,7 +64,7 @@
|
|
|
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.
|
|
67
|
+
"@mojaloop/sdk-standard-components": "19.10.0",
|
|
68
68
|
"axios": "1.8.2",
|
|
69
69
|
"clone": "2.1.2",
|
|
70
70
|
"dotenv": "16.4.7",
|
package/src/util/endpoints.js
CHANGED
|
@@ -29,7 +29,6 @@
|
|
|
29
29
|
|
|
30
30
|
'use strict'
|
|
31
31
|
|
|
32
|
-
const Logger = require('@mojaloop/central-services-logger')
|
|
33
32
|
const ErrorHandler = require('@mojaloop/central-services-error-handling')
|
|
34
33
|
const Metrics = require('@mojaloop/central-services-metrics')
|
|
35
34
|
const proxyLib = require('@mojaloop/inter-scheme-proxy-cache-lib')
|
|
@@ -38,6 +37,7 @@ const CatboxMemory = require('@hapi/catbox-memory')
|
|
|
38
37
|
const Mustache = require('mustache')
|
|
39
38
|
const { Map } = require('immutable')
|
|
40
39
|
|
|
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,8 +66,9 @@ const fetchEndpoints = async (fsp) => {
|
|
|
66
66
|
'fetchParticipants - Metrics for fetchParticipants',
|
|
67
67
|
['success']
|
|
68
68
|
).startTimer()
|
|
69
|
+
const log = logger.child({ fsp, method: 'fetchEndpoints' })
|
|
69
70
|
try {
|
|
70
|
-
|
|
71
|
+
log.debug('refreshing the cache for FSP')
|
|
71
72
|
if (!hubName) {
|
|
72
73
|
throw Error('"hubName" is not initialized. Initialize the cache first.')
|
|
73
74
|
}
|
|
@@ -76,7 +77,8 @@ const fetchEndpoints = async (fsp) => {
|
|
|
76
77
|
}
|
|
77
78
|
const defaultHeaders = Http.SwitchDefaultHeaders(hubName, Enum.Http.HeaderResources.PARTICIPANTS, hubName)
|
|
78
79
|
const url = Mustache.render(switchEndpoint + Enum.EndPoints.FspEndpointTemplates.PARTICIPANT_ENDPOINTS_GET, { fsp })
|
|
79
|
-
|
|
80
|
+
log.verbose('url for PARTICIPANT_ENDPOINTS_GET', { url })
|
|
81
|
+
|
|
80
82
|
const response = await request.sendRequest({
|
|
81
83
|
url,
|
|
82
84
|
headers: defaultHeaders,
|
|
@@ -84,8 +86,9 @@ const fetchEndpoints = async (fsp) => {
|
|
|
84
86
|
destination: hubName,
|
|
85
87
|
hubNameRegex
|
|
86
88
|
})
|
|
87
|
-
Logger.isDebugEnabled && Logger.debug(`[fsp=${fsp}] ~ Model::participantEndpoint::fetchEndpoints := successful with body: ${JSON.stringify(response.data)}`)
|
|
88
89
|
const endpoints = response.data
|
|
90
|
+
log.debug('fetchEndpoints raw response.data:', { endpoints })
|
|
91
|
+
|
|
89
92
|
const endpointMap = {}
|
|
90
93
|
if (Array.isArray(endpoints)) {
|
|
91
94
|
endpoints.forEach(item => {
|
|
@@ -93,12 +96,12 @@ const fetchEndpoints = async (fsp) => {
|
|
|
93
96
|
endpointMap[item.type] = item.value
|
|
94
97
|
})
|
|
95
98
|
}
|
|
96
|
-
|
|
99
|
+
log.verbose('returning the endpoints:', { endpointMap })
|
|
97
100
|
histTimer({ success: true })
|
|
101
|
+
|
|
98
102
|
return endpointMap
|
|
99
|
-
} catch (
|
|
100
|
-
|
|
101
|
-
Logger.isErrorEnabled && Logger.error(`participantEndpointCache::fetchEndpoints:: ERROR:'${e}'`)
|
|
103
|
+
} catch (err) {
|
|
104
|
+
log.error(`error in fetchEndpoints: ${err?.message}`, err)
|
|
102
105
|
}
|
|
103
106
|
}
|
|
104
107
|
|
|
@@ -116,18 +119,17 @@ const fetchEndpoints = async (fsp) => {
|
|
|
116
119
|
*/
|
|
117
120
|
exports.initializeCache = async (policyOptions, config) => {
|
|
118
121
|
try {
|
|
119
|
-
|
|
122
|
+
logger.debug('initializeCache start', { clientOptions, policyOptions })
|
|
120
123
|
client = new Catbox.Client(CatboxMemory, clientOptions)
|
|
121
124
|
await client.start()
|
|
122
125
|
policyOptions.generateFunc = fetchEndpoints
|
|
123
|
-
Logger.isDebugEnabled && Logger.debug(`participantEndpointCache::initializeCache::start::policyOptions - ${JSON.stringify(policyOptions)}`)
|
|
124
126
|
policy = new Catbox.Policy(policyOptions, client, partition)
|
|
125
|
-
Logger.isDebugEnabled && Logger.debug('participantEndpointCache::initializeCache::Cache initialized successfully')
|
|
126
127
|
hubName = config.hubName
|
|
127
128
|
hubNameRegex = config.hubNameRegex
|
|
129
|
+
logger.verbose('initializeCache is done successfully', { hubName, hubNameRegex })
|
|
128
130
|
return true
|
|
129
131
|
} catch (err) {
|
|
130
|
-
|
|
132
|
+
logger.error(`error in initializeCache: ${err?.message}`, err)
|
|
131
133
|
throw ErrorHandler.Factory.reformatFSPIOPError(err)
|
|
132
134
|
}
|
|
133
135
|
}
|
|
@@ -152,9 +154,11 @@ exports.getEndpoint = async (switchUrl, fsp, endpointType, options = {}, renderO
|
|
|
152
154
|
['success', 'hit']
|
|
153
155
|
).startTimer()
|
|
154
156
|
switchEndpoint = switchUrl
|
|
155
|
-
|
|
157
|
+
const log = logger.child({ fsp, endpointType, method: 'getEndpoint' })
|
|
158
|
+
log.debug('getEndpoint start', { switchUrl })
|
|
156
159
|
let proxyId
|
|
157
160
|
const result = url => proxyConfig?.enabled ? { url, proxyId } : url
|
|
161
|
+
|
|
158
162
|
try {
|
|
159
163
|
// If a service passes in `getDecoratedValue` as true, then an object
|
|
160
164
|
// { value, cached, report } is returned, where value is the cached value,
|
|
@@ -168,7 +172,11 @@ exports.getEndpoint = async (switchUrl, fsp, endpointType, options = {}, renderO
|
|
|
168
172
|
proxyId = await proxy.lookupProxyByDfspId(fsp)
|
|
169
173
|
endpoints = proxyId && await policy.get(proxyId)
|
|
170
174
|
}
|
|
171
|
-
if (!endpoints)
|
|
175
|
+
if (!endpoints) {
|
|
176
|
+
log.warn('no endpoints found for fsp')
|
|
177
|
+
throw ErrorHandler.CreateFSPIOPError(ErrorHandler.Enums.FSPIOPErrorCodes.PARTY_NOT_FOUND)
|
|
178
|
+
}
|
|
179
|
+
|
|
172
180
|
if ('value' in endpoints && 'cached' in endpoints) {
|
|
173
181
|
if (endpoints.cached === null) {
|
|
174
182
|
histTimer({ success: true, hit: false })
|
|
@@ -182,6 +190,7 @@ exports.getEndpoint = async (switchUrl, fsp, endpointType, options = {}, renderO
|
|
|
182
190
|
}
|
|
183
191
|
return result(Mustache.render(endpoint, options))
|
|
184
192
|
}
|
|
193
|
+
|
|
185
194
|
let endpoint = new Map(endpoints).get(endpointType)
|
|
186
195
|
if (renderOptions.path) {
|
|
187
196
|
endpoint = (endpoint === undefined) ? endpoint : endpoint + renderOptions.path
|
|
@@ -190,7 +199,7 @@ exports.getEndpoint = async (switchUrl, fsp, endpointType, options = {}, renderO
|
|
|
190
199
|
return result(Mustache.render(endpoint, options))
|
|
191
200
|
} catch (err) {
|
|
192
201
|
histTimer({ success: false, hit: false })
|
|
193
|
-
|
|
202
|
+
log.error(`error in getEndpoint: ${err?.message}`, err)
|
|
194
203
|
throw ErrorHandler.Factory.reformatFSPIOPError(err)
|
|
195
204
|
}
|
|
196
205
|
}
|
|
@@ -215,7 +224,8 @@ exports.getEndpointAndRender = async (switchUrl, fsp, endpointType, path = '', o
|
|
|
215
224
|
['success']
|
|
216
225
|
).startTimer()
|
|
217
226
|
switchEndpoint = switchUrl
|
|
218
|
-
|
|
227
|
+
const log = logger.child({ fsp, endpointType })
|
|
228
|
+
log.debug('getEndpointAndRender start', { switchUrl, path })
|
|
219
229
|
|
|
220
230
|
try {
|
|
221
231
|
const endpoint = exports.getEndpoint(switchUrl, fsp, endpointType, options, { path })
|
|
@@ -223,7 +233,7 @@ exports.getEndpointAndRender = async (switchUrl, fsp, endpointType, path = '', o
|
|
|
223
233
|
return endpoint
|
|
224
234
|
} catch (err) {
|
|
225
235
|
histTimer({ success: false })
|
|
226
|
-
|
|
236
|
+
log.error(`error in getEndpointAndRender: ${err?.message}`, err)
|
|
227
237
|
throw ErrorHandler.Factory.reformatFSPIOPError(err)
|
|
228
238
|
}
|
|
229
239
|
}
|
|
@@ -236,7 +246,7 @@ exports.getEndpointAndRender = async (switchUrl, fsp, endpointType, path = '', o
|
|
|
236
246
|
* @returns {boolean} - Returns the status
|
|
237
247
|
*/
|
|
238
248
|
exports.stopCache = async () => {
|
|
239
|
-
|
|
249
|
+
logger.verbose('stopping the cache')
|
|
240
250
|
if (client) {
|
|
241
251
|
return client.stop()
|
|
242
252
|
}
|
|
@@ -252,6 +262,7 @@ exports.stopCache = async () => {
|
|
|
252
262
|
exports.stopProxy = async () => {
|
|
253
263
|
const result = await proxy?.disconnect()
|
|
254
264
|
proxy = undefined
|
|
265
|
+
logger.verbose('proxy disconnected')
|
|
255
266
|
return result
|
|
256
267
|
}
|
|
257
268
|
|