@mojaloop/central-services-shared 18.34.1 → 18.34.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/package.json +3 -3
- package/src/index.d.ts +1 -1
- package/src/util/proxies.js +6 -4
- package/test/unit/util/proxies.test.js +134 -0
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.34.2](https://github.com/mojaloop/central-services-shared/compare/v18.34.1...v18.34.2) (2025-10-10)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Bug Fixes
|
|
9
|
+
|
|
10
|
+
* **csi-1259:** update getAllProxiesNames to return only isActive proxies ([#488](https://github.com/mojaloop/central-services-shared/issues/488)) ([5d05786](https://github.com/mojaloop/central-services-shared/commit/5d05786a18740a90f851d4d80c8835fdde260a32))
|
|
11
|
+
|
|
5
12
|
### [18.34.1](https://github.com/mojaloop/central-services-shared/compare/v18.34.0...v18.34.1) (2025-10-06)
|
|
6
13
|
|
|
7
14
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mojaloop/central-services-shared",
|
|
3
|
-
"version": "18.34.
|
|
3
|
+
"version": "18.34.2",
|
|
4
4
|
"description": "Shared code for mojaloop central services",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": "ModusBox",
|
|
@@ -97,9 +97,9 @@
|
|
|
97
97
|
"@mojaloop/central-services-error-handling": "13.1.3",
|
|
98
98
|
"@mojaloop/central-services-logger": "11.10.1",
|
|
99
99
|
"@mojaloop/central-services-metrics": "12.8.0",
|
|
100
|
-
"@mojaloop/event-sdk": "14.8.
|
|
100
|
+
"@mojaloop/event-sdk": "14.8.1",
|
|
101
101
|
"@mojaloop/sdk-standard-components": "19.18.0",
|
|
102
|
-
"@opentelemetry/auto-instrumentations-node": "^0.
|
|
102
|
+
"@opentelemetry/auto-instrumentations-node": "^0.65.0",
|
|
103
103
|
"@types/hapi__joi": "17.1.15",
|
|
104
104
|
"ajv": "^8.17.1",
|
|
105
105
|
"ajv-formats": "^3.0.1",
|
package/src/index.d.ts
CHANGED
|
@@ -647,7 +647,7 @@ declare namespace CentralServicesShared {
|
|
|
647
647
|
|
|
648
648
|
type ProxyNames = string[]
|
|
649
649
|
interface Proxies extends Cacheable {
|
|
650
|
-
getAllProxiesNames(switchUrl: string): Promise<ProxyNames>
|
|
650
|
+
getAllProxiesNames(switchUrl: string, onlyActive?: boolean): Promise<ProxyNames>
|
|
651
651
|
invalidateProxiesCache(): Promise<void>
|
|
652
652
|
}
|
|
653
653
|
|
package/src/util/proxies.js
CHANGED
|
@@ -111,14 +111,13 @@ exports.initializeCache = async (policyOptions, config) => {
|
|
|
111
111
|
}
|
|
112
112
|
|
|
113
113
|
/**
|
|
114
|
-
*
|
|
115
|
-
* @description It returns a list of allProxies names from the cache if the cache is still valid, otherwise it will refresh the cache and return the value
|
|
114
|
+
* Returns a list of allProxies names from the cache if the cache is still valid, otherwise it will refresh the cache and return the value
|
|
116
115
|
*
|
|
117
116
|
* @param {string} switchUrl the endpoint for the switch
|
|
118
|
-
*
|
|
117
|
+
* @param {boolean} [onlyActive] if true, returns only active proxies (isActive === 1), defaults to false
|
|
119
118
|
* @returns {string[]} - Returns list of allProxies names, throws error if failure occurs
|
|
120
119
|
*/
|
|
121
|
-
exports.getAllProxiesNames = async (switchUrl) => {
|
|
120
|
+
exports.getAllProxiesNames = async (switchUrl, onlyActive = false) => {
|
|
122
121
|
const histTimer = Metrics.getHistogram(
|
|
123
122
|
'getAllProxiesNames',
|
|
124
123
|
'getAllProxiesNames - Metrics for getAllProxies with cache hit rate',
|
|
@@ -148,6 +147,9 @@ exports.getAllProxiesNames = async (switchUrl) => {
|
|
|
148
147
|
await policy.drop(cacheKey)
|
|
149
148
|
throw ErrorHandler.Factory.createFSPIOPErrorFromErrorInformation(proxies.errorInformation)
|
|
150
149
|
}
|
|
150
|
+
if (onlyActive) {
|
|
151
|
+
proxies = proxies.filter(p => p.isActive === 1)
|
|
152
|
+
}
|
|
151
153
|
return proxies.map(p => p.name)
|
|
152
154
|
} catch (err) {
|
|
153
155
|
histTimer({ success: false, hit: false })
|
|
@@ -0,0 +1,134 @@
|
|
|
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 Test = require('tapes')(require('tape'))
|
|
31
|
+
const Sinon = require('sinon')
|
|
32
|
+
|
|
33
|
+
const proxies = require('#src/util/proxies')
|
|
34
|
+
const request = require('#src/util/request')
|
|
35
|
+
const Http = require('#src/util/index').Http
|
|
36
|
+
const Config = require('#test/util/config')
|
|
37
|
+
const Helper = require('#test/util/helper')
|
|
38
|
+
|
|
39
|
+
Test('Proxies Participants Test', proxiesTest => {
|
|
40
|
+
let sandbox
|
|
41
|
+
const hubName = 'Hub'
|
|
42
|
+
const hubNameRegex = /^Hub$/i
|
|
43
|
+
|
|
44
|
+
const mockProxiesResponse = {
|
|
45
|
+
data: [
|
|
46
|
+
{ name: 'proxy1', isActive: 1 },
|
|
47
|
+
{ name: 'proxy2', isActive: 0 },
|
|
48
|
+
{ name: 'proxy3', isActive: 1 },
|
|
49
|
+
{ name: 'proxy4', isActive: 0 }
|
|
50
|
+
]
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
proxiesTest.beforeEach(async test => {
|
|
54
|
+
sandbox = Sinon.createSandbox()
|
|
55
|
+
sandbox.stub(request, 'sendRequest')
|
|
56
|
+
sandbox.stub(Http, 'SwitchDefaultHeaders').returns(Helper.defaultHeaders())
|
|
57
|
+
test.end()
|
|
58
|
+
})
|
|
59
|
+
|
|
60
|
+
proxiesTest.afterEach(async test => {
|
|
61
|
+
sandbox.restore()
|
|
62
|
+
test.end()
|
|
63
|
+
})
|
|
64
|
+
|
|
65
|
+
proxiesTest.test('getAllProxiesNames method Tests', async (getAllProxiesNamesTest) => {
|
|
66
|
+
getAllProxiesNamesTest.test('should return all proxy names when onlyActive is false', async (test) => {
|
|
67
|
+
await proxies.initializeCache(Config.ENDPOINT_CACHE_CONFIG, { hubName, hubNameRegex })
|
|
68
|
+
request.sendRequest.returns(Promise.resolve(mockProxiesResponse))
|
|
69
|
+
|
|
70
|
+
try {
|
|
71
|
+
const result = await proxies.getAllProxiesNames(Config.ENDPOINT_SOURCE_URL, false)
|
|
72
|
+
test.equal(result.length, 4, 'Should return all 4 proxies')
|
|
73
|
+
test.deepEqual(result, ['proxy1', 'proxy2', 'proxy3', 'proxy4'], 'Should return all proxy names')
|
|
74
|
+
await proxies.stopCache()
|
|
75
|
+
test.end()
|
|
76
|
+
} catch (err) {
|
|
77
|
+
test.fail('Error thrown', err)
|
|
78
|
+
test.end()
|
|
79
|
+
}
|
|
80
|
+
})
|
|
81
|
+
|
|
82
|
+
getAllProxiesNamesTest.test('should return all proxy names when onlyActive is not provided (default)', async (test) => {
|
|
83
|
+
await proxies.initializeCache(Config.ENDPOINT_CACHE_CONFIG, { hubName, hubNameRegex })
|
|
84
|
+
request.sendRequest.returns(Promise.resolve(mockProxiesResponse))
|
|
85
|
+
|
|
86
|
+
try {
|
|
87
|
+
const result = await proxies.getAllProxiesNames(Config.ENDPOINT_SOURCE_URL)
|
|
88
|
+
test.equal(result.length, 4, 'Should return all 4 proxies')
|
|
89
|
+
test.deepEqual(result, ['proxy1', 'proxy2', 'proxy3', 'proxy4'], 'Should return all proxy names')
|
|
90
|
+
await proxies.stopCache()
|
|
91
|
+
test.end()
|
|
92
|
+
} catch (err) {
|
|
93
|
+
test.fail('Error thrown', err)
|
|
94
|
+
test.end()
|
|
95
|
+
}
|
|
96
|
+
})
|
|
97
|
+
|
|
98
|
+
getAllProxiesNamesTest.test('should return only active proxy names when onlyActive is true', async (test) => {
|
|
99
|
+
await proxies.initializeCache(Config.ENDPOINT_CACHE_CONFIG, { hubName, hubNameRegex })
|
|
100
|
+
request.sendRequest.returns(Promise.resolve(mockProxiesResponse))
|
|
101
|
+
|
|
102
|
+
try {
|
|
103
|
+
const result = await proxies.getAllProxiesNames(Config.ENDPOINT_SOURCE_URL, true)
|
|
104
|
+
test.equal(result.length, 2, 'Should return only 2 active proxies')
|
|
105
|
+
test.deepEqual(result, ['proxy1', 'proxy3'], 'Should return only active proxy names')
|
|
106
|
+
await proxies.stopCache()
|
|
107
|
+
test.end()
|
|
108
|
+
} catch (err) {
|
|
109
|
+
test.fail('Error thrown', err)
|
|
110
|
+
test.end()
|
|
111
|
+
}
|
|
112
|
+
})
|
|
113
|
+
|
|
114
|
+
await getAllProxiesNamesTest.end()
|
|
115
|
+
})
|
|
116
|
+
|
|
117
|
+
proxiesTest.test('initializeCache method Tests', async (initCacheTest) => {
|
|
118
|
+
initCacheTest.test('should initialize cache and return true', async (test) => {
|
|
119
|
+
try {
|
|
120
|
+
const result = await proxies.initializeCache(Config.ENDPOINT_CACHE_CONFIG, { hubName, hubNameRegex })
|
|
121
|
+
test.equal(result, true, 'The results match')
|
|
122
|
+
await proxies.stopCache()
|
|
123
|
+
test.end()
|
|
124
|
+
} catch (err) {
|
|
125
|
+
test.fail('Error thrown', err)
|
|
126
|
+
test.end()
|
|
127
|
+
}
|
|
128
|
+
})
|
|
129
|
+
|
|
130
|
+
await initCacheTest.end()
|
|
131
|
+
})
|
|
132
|
+
|
|
133
|
+
proxiesTest.end()
|
|
134
|
+
})
|