account-lookup-service 15.6.0-iso.23 → 15.6.0-iso.25
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/config/default.json +1 -0
- package/package.json +12 -9
- package/src/domain/participants/participants.js +1 -1
- package/src/lib/config.js +1 -0
- package/src/lib/db.js +2 -1
- package/src/models/oracle/facade.js +18 -13
- package/src/models/oracle/oracleEndpoint.js +1 -0
- package/src/models/oracle/oracleEndpointCached.js +7 -6
- package/test/unit/models/oracle/oracleEndpointCached.test.js +32 -0
package/config/default.json
CHANGED
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "account-lookup-service",
|
3
3
|
"description": "Account Lookup Service is used to validate Party and Participant lookups.",
|
4
|
-
"version": "15.6.0-iso.
|
4
|
+
"version": "15.6.0-iso.25",
|
5
5
|
"license": "Apache-2.0",
|
6
6
|
"author": "ModusBox",
|
7
7
|
"contributors": [
|
@@ -90,23 +90,23 @@
|
|
90
90
|
"@hapi/hapi": "21.3.12",
|
91
91
|
"@hapi/inert": "7.1.0",
|
92
92
|
"@hapi/vision": "7.0.3",
|
93
|
-
"@mojaloop/central-services-error-handling": "13.0.
|
93
|
+
"@mojaloop/central-services-error-handling": "13.0.3",
|
94
94
|
"@mojaloop/central-services-health": "15.0.0",
|
95
95
|
"@mojaloop/central-services-logger": "11.5.1",
|
96
|
-
"@mojaloop/central-services-metrics": "12.4.
|
97
|
-
"@mojaloop/central-services-shared": "18.
|
98
|
-
"@mojaloop/central-services-stream": "11.4.
|
96
|
+
"@mojaloop/central-services-metrics": "12.4.3",
|
97
|
+
"@mojaloop/central-services-shared": "18.15.1",
|
98
|
+
"@mojaloop/central-services-stream": "11.4.2",
|
99
99
|
"@mojaloop/database-lib": "11.1.0",
|
100
100
|
"@mojaloop/event-sdk": "14.1.1",
|
101
101
|
"@mojaloop/inter-scheme-proxy-cache-lib": "2.3.1",
|
102
|
-
"@mojaloop/ml-schema-transformer-lib": "2.5.
|
102
|
+
"@mojaloop/ml-schema-transformer-lib": "2.5.1",
|
103
103
|
"@mojaloop/sdk-standard-components": "19.6.2",
|
104
104
|
"@now-ims/hapi-now-auth": "2.1.0",
|
105
105
|
"ajv": "8.17.1",
|
106
106
|
"ajv-keywords": "5.1.0",
|
107
107
|
"blipp": "4.0.2",
|
108
|
-
"commander": "
|
109
|
-
"cron": "3.3.
|
108
|
+
"commander": "13.0.0",
|
109
|
+
"cron": "3.3.2",
|
110
110
|
"fast-safe-stringify": "^2.1.1",
|
111
111
|
"hapi-auth-bearer-token": "8.0.0",
|
112
112
|
"joi": "17.13.3",
|
@@ -118,6 +118,9 @@
|
|
118
118
|
"rc": "1.2.8"
|
119
119
|
},
|
120
120
|
"overrides": {
|
121
|
+
"postcss": {
|
122
|
+
"nanoid": "^3.3.8"
|
123
|
+
},
|
121
124
|
"@mojaloop/central-services-health": {
|
122
125
|
"@mojaloop/central-services-logger": ">=11.4.0"
|
123
126
|
},
|
@@ -158,7 +161,7 @@
|
|
158
161
|
"jest-junit": "16.0.0",
|
159
162
|
"jsdoc": "4.0.4",
|
160
163
|
"nodemon": "3.1.9",
|
161
|
-
"npm-check-updates": "17.1.
|
164
|
+
"npm-check-updates": "17.1.13",
|
162
165
|
"nyc": "17.1.0",
|
163
166
|
"pre-commit": "1.2.2",
|
164
167
|
"replace": "^1.2.2",
|
@@ -84,7 +84,7 @@ const getParticipantsByTypeAndID = async (headers, params, method, query, span,
|
|
84
84
|
throw ErrorHandler.Factory.createFSPIOPError(ErrorHandler.Enums.FSPIOPErrorCodes.ID_NOT_FOUND, errMessage)
|
85
85
|
}
|
86
86
|
step = 'oracleRequest-2'
|
87
|
-
const response = await oracle.oracleRequest(headers, method, params, query, undefined, cache)
|
87
|
+
const response = await oracle.oracleRequest(headers, method, params, query, undefined, cache, true)
|
88
88
|
if (response?.data && Array.isArray(response.data.partyList) && response.data.partyList.length > 0) {
|
89
89
|
const options = {
|
90
90
|
partyIdType: type,
|
package/src/lib/config.js
CHANGED
package/src/lib/db.js
CHANGED
@@ -47,10 +47,11 @@ const { hubNameRegex } = require('../../lib/util').hubNameConfig
|
|
47
47
|
* @param {object} params - uri parameters of the http request
|
48
48
|
* @param {object} query - the query parameter on the uri of the http request
|
49
49
|
* @param {object} payload - payload of the request being sent out
|
50
|
+
* @param {object} assertPendingAcquire - flag to check DB pool pending acquire limit
|
50
51
|
*
|
51
52
|
* @returns {object} returns the response from the oracle
|
52
53
|
*/
|
53
|
-
exports.oracleRequest = async (headers, method, params = {}, query = {}, payload = undefined, cache) => {
|
54
|
+
exports.oracleRequest = async (headers, method, params = {}, query = {}, payload = undefined, cache, assertPendingAcquire) => {
|
54
55
|
try {
|
55
56
|
let url
|
56
57
|
const partyIdType = params.Type
|
@@ -59,13 +60,13 @@ exports.oracleRequest = async (headers, method, params = {}, query = {}, payload
|
|
59
60
|
const partySubIdOrType = (params && params.SubId) ? params.SubId : (query && query.partySubIdOrType) ? query.partySubIdOrType : undefined
|
60
61
|
const isGetRequest = method.toUpperCase() === Enums.Http.RestMethods.GET
|
61
62
|
if (currency && partySubIdOrType && isGetRequest) {
|
62
|
-
url = await _getOracleEndpointByTypeCurrencyAndSubId(partyIdType, partyIdentifier, currency, partySubIdOrType)
|
63
|
+
url = await _getOracleEndpointByTypeCurrencyAndSubId(partyIdType, partyIdentifier, currency, partySubIdOrType, assertPendingAcquire)
|
63
64
|
} else if (currency && isGetRequest) {
|
64
|
-
url = await _getOracleEndpointByTypeAndCurrency(partyIdType, partyIdentifier, currency)
|
65
|
+
url = await _getOracleEndpointByTypeAndCurrency(partyIdType, partyIdentifier, currency, assertPendingAcquire)
|
65
66
|
} else if (partySubIdOrType && isGetRequest) {
|
66
|
-
url = await _getOracleEndpointByTypeAndSubId(partyIdType, partyIdentifier, partySubIdOrType)
|
67
|
+
url = await _getOracleEndpointByTypeAndSubId(partyIdType, partyIdentifier, partySubIdOrType, assertPendingAcquire)
|
67
68
|
} else {
|
68
|
-
url = await _getOracleEndpointByType(partyIdType, partyIdentifier)
|
69
|
+
url = await _getOracleEndpointByType(partyIdType, partyIdentifier, assertPendingAcquire)
|
69
70
|
if (partySubIdOrType) {
|
70
71
|
payload = { ...payload, partySubIdOrType }
|
71
72
|
}
|
@@ -172,12 +173,13 @@ exports.oracleRequest = async (headers, method, params = {}, query = {}, payload
|
|
172
173
|
* @param {string} partyIdType - party ID type (e.g MSISDN)
|
173
174
|
* @param {string} partyIdentifier - party ID
|
174
175
|
* @param {string} currency - currency ID
|
176
|
+
* @param {object} assertPendingAcquire - flag to check DB pool pending acquire limit
|
175
177
|
*
|
176
178
|
* @returns {string} returns the endpoint to the oracle
|
177
179
|
*/
|
178
|
-
const _getOracleEndpointByTypeAndCurrency = async (partyIdType, partyIdentifier, currency) => {
|
180
|
+
const _getOracleEndpointByTypeAndCurrency = async (partyIdType, partyIdentifier, currency, assertPendingAcquire) => {
|
179
181
|
let url
|
180
|
-
const oracleEndpointModel = await oracleEndpointCached.getOracleEndpointByTypeAndCurrency(partyIdType, currency)
|
182
|
+
const oracleEndpointModel = await oracleEndpointCached.getOracleEndpointByTypeAndCurrency(partyIdType, currency, assertPendingAcquire)
|
181
183
|
if (oracleEndpointModel.length > 0) {
|
182
184
|
if (oracleEndpointModel.length > 1) {
|
183
185
|
const defautOracle = oracleEndpointModel.filter(oracle => oracle.isDefault).pop()
|
@@ -207,12 +209,13 @@ const _getOracleEndpointByTypeAndCurrency = async (partyIdType, partyIdentifier,
|
|
207
209
|
*
|
208
210
|
* @param {string} partyIdType - party ID type (e.g MSISDN)
|
209
211
|
* @param {string} partyIdentifier - party ID
|
212
|
+
* @param {object} assertPendingAcquire - flag to check DB pool pending acquire limit
|
210
213
|
*
|
211
214
|
* @returns {string} returns the endpoint to the oracle
|
212
215
|
*/
|
213
|
-
const _getOracleEndpointByType = async (partyIdType, partyIdentifier) => {
|
216
|
+
const _getOracleEndpointByType = async (partyIdType, partyIdentifier, assertPendingAcquire) => {
|
214
217
|
let url
|
215
|
-
const oracleEndpointModel = await oracleEndpointCached.getOracleEndpointByType(partyIdType)
|
218
|
+
const oracleEndpointModel = await oracleEndpointCached.getOracleEndpointByType(partyIdType, assertPendingAcquire)
|
216
219
|
if (oracleEndpointModel.length > 0) {
|
217
220
|
if (oracleEndpointModel.length > 1) {
|
218
221
|
const defaultOracle = oracleEndpointModel.filter(oracle => oracle.isDefault).pop()
|
@@ -243,12 +246,13 @@ const _getOracleEndpointByType = async (partyIdType, partyIdentifier) => {
|
|
243
246
|
* @param {string} partyIdType - party ID type (e.g MSISDN)
|
244
247
|
* @param {string} partyIdentifier - party ID
|
245
248
|
* @param {string} partySubIdOrType - party subId
|
249
|
+
* @param {object} assertPendingAcquire - flag to check DB pool pending acquire limit
|
246
250
|
*
|
247
251
|
* @returns {string} returns the endpoint to the oracle
|
248
252
|
*/
|
249
|
-
const _getOracleEndpointByTypeAndSubId = async (partyIdType, partyIdentifier, partySubIdOrType) => {
|
253
|
+
const _getOracleEndpointByTypeAndSubId = async (partyIdType, partyIdentifier, partySubIdOrType, assertPendingAcquire) => {
|
250
254
|
let url
|
251
|
-
const oracleEndpointModel = await oracleEndpointCached.getOracleEndpointByType(partyIdType)
|
255
|
+
const oracleEndpointModel = await oracleEndpointCached.getOracleEndpointByType(partyIdType, assertPendingAcquire)
|
252
256
|
if (oracleEndpointModel.length > 0) {
|
253
257
|
if (oracleEndpointModel.length > 1) {
|
254
258
|
const defautOracle = oracleEndpointModel.filter(oracle => oracle.isDefault).pop()
|
@@ -280,12 +284,13 @@ const _getOracleEndpointByTypeAndSubId = async (partyIdType, partyIdentifier, pa
|
|
280
284
|
* @param {string} partyIdentifier - party ID
|
281
285
|
* @param {string} currency - currency ID
|
282
286
|
* @param {string} partySubIdOrType - party subId
|
287
|
+
* @param {object} assertPendingAcquire - flag to check DB pool pending acquire limit
|
283
288
|
*
|
284
289
|
* @returns {string} returns the endpoint to the oracle
|
285
290
|
*/
|
286
|
-
const _getOracleEndpointByTypeCurrencyAndSubId = async (partyIdType, partyIdentifier, currency, partySubIdOrType) => {
|
291
|
+
const _getOracleEndpointByTypeCurrencyAndSubId = async (partyIdType, partyIdentifier, currency, partySubIdOrType, assertPendingAcquire) => {
|
287
292
|
let url
|
288
|
-
const oracleEndpointModel = await oracleEndpointCached.getOracleEndpointByTypeAndCurrency(partyIdType, currency)
|
293
|
+
const oracleEndpointModel = await oracleEndpointCached.getOracleEndpointByTypeAndCurrency(partyIdType, currency, assertPendingAcquire)
|
289
294
|
if (oracleEndpointModel.length > 0) {
|
290
295
|
if (oracleEndpointModel.length > 1) {
|
291
296
|
const defautOracle = oracleEndpointModel.filter(oracle => oracle.isDefault).pop()
|
@@ -53,6 +53,7 @@ const getOracleEndpointCached = async (params) => {
|
|
53
53
|
const cacheKey = getCacheKey(params)
|
54
54
|
let cachedEndpoints = cacheClient.get(cacheKey)
|
55
55
|
if (!cachedEndpoints) {
|
56
|
+
if (params.assertPendingAcquire) OracleEndpointUncached.assertPendingAcquires()
|
56
57
|
// No oracleEndpoint in the cache, so fetch from participant API
|
57
58
|
let oracleEndpoints
|
58
59
|
if (partyIdType && currency) {
|
@@ -87,9 +88,9 @@ exports.initialize = async () => {
|
|
87
88
|
cacheClient = Cache.registerCacheClient(oracleEndpointCacheClientMeta)
|
88
89
|
}
|
89
90
|
|
90
|
-
exports.getOracleEndpointByTypeAndCurrency = async (partyIdType, currency) => {
|
91
|
+
exports.getOracleEndpointByTypeAndCurrency = async (partyIdType, currency, assertPendingAcquire) => {
|
91
92
|
try {
|
92
|
-
return await getOracleEndpointCached({ partyIdType, currency })
|
93
|
+
return await getOracleEndpointCached({ partyIdType, currency, assertPendingAcquire })
|
93
94
|
} catch (err) {
|
94
95
|
throw ErrorHandler.Factory.reformatFSPIOPError(
|
95
96
|
err,
|
@@ -100,9 +101,9 @@ exports.getOracleEndpointByTypeAndCurrency = async (partyIdType, currency) => {
|
|
100
101
|
}
|
101
102
|
}
|
102
103
|
|
103
|
-
exports.getOracleEndpointByType = async (partyIdType) => {
|
104
|
+
exports.getOracleEndpointByType = async (partyIdType, assertPendingAcquire) => {
|
104
105
|
try {
|
105
|
-
return await getOracleEndpointCached({ partyIdType })
|
106
|
+
return await getOracleEndpointCached({ partyIdType, assertPendingAcquire })
|
106
107
|
} catch (err) {
|
107
108
|
throw ErrorHandler.Factory.reformatFSPIOPError(
|
108
109
|
err,
|
@@ -113,9 +114,9 @@ exports.getOracleEndpointByType = async (partyIdType) => {
|
|
113
114
|
}
|
114
115
|
}
|
115
116
|
|
116
|
-
exports.getOracleEndpointByCurrency = async (currency) => {
|
117
|
+
exports.getOracleEndpointByCurrency = async (currency, assertPendingAcquire) => {
|
117
118
|
try {
|
118
|
-
return await getOracleEndpointCached({ currency })
|
119
|
+
return await getOracleEndpointCached({ currency, assertPendingAcquire })
|
119
120
|
} catch (err) {
|
120
121
|
throw ErrorHandler.Factory.reformatFSPIOPError(
|
121
122
|
err,
|
@@ -58,6 +58,7 @@ describe('ParticipantCurrency cached model', () => {
|
|
58
58
|
sandbox.stub(OracleEndpointUncached, 'getOracleEndpointByTypeAndCurrency').returns(oracleEndpoints)
|
59
59
|
sandbox.stub(OracleEndpointUncached, 'getOracleEndpointByCurrency').returns(oracleEndpoints)
|
60
60
|
sandbox.stub(OracleEndpointUncached, 'getOracleEndpointByType').returns(oracleEndpoints)
|
61
|
+
sandbox.stub(OracleEndpointUncached, 'assertPendingAcquires').returns()
|
61
62
|
})
|
62
63
|
|
63
64
|
afterEach(() => {
|
@@ -150,4 +151,35 @@ describe('ParticipantCurrency cached model', () => {
|
|
150
151
|
await Model.getOracleEndpointByTypeAndCurrency('MSISDN', 'USD')
|
151
152
|
expect(cacheClient.get.called).toBeTruthy()
|
152
153
|
})
|
154
|
+
it('getOracleEndpointCached calls assertPendingAcquire when assertPendingAcquire is true', async () => {
|
155
|
+
let cache = null
|
156
|
+
const cacheClient = {
|
157
|
+
createKey: sandbox.stub().returns({}),
|
158
|
+
get: () => cache,
|
159
|
+
set: (key, x) => {
|
160
|
+
cache = { item: x } // the cache returns {item: <data>} structure
|
161
|
+
}
|
162
|
+
}
|
163
|
+
Cache.registerCacheClient.returns(cacheClient)
|
164
|
+
await Model.initialize()
|
165
|
+
|
166
|
+
await Model.getOracleEndpointByTypeAndCurrency('MSISDN', 'USD', true)
|
167
|
+
expect(OracleEndpointUncached.assertPendingAcquires.calledOnce).toBeTruthy()
|
168
|
+
})
|
169
|
+
|
170
|
+
it('getOracleEndpointCached does not call assertPendingAcquire when assertPendingAcquire is false', async () => {
|
171
|
+
let cache = null
|
172
|
+
const cacheClient = {
|
173
|
+
createKey: sandbox.stub().returns({}),
|
174
|
+
get: () => cache,
|
175
|
+
set: (key, x) => {
|
176
|
+
cache = { item: x } // the cache returns {item: <data>} structure
|
177
|
+
}
|
178
|
+
}
|
179
|
+
Cache.registerCacheClient.returns(cacheClient)
|
180
|
+
await Model.initialize()
|
181
|
+
|
182
|
+
await Model.getOracleEndpointByTypeAndCurrency('MSISDN', 'USD', false)
|
183
|
+
expect(OracleEndpointUncached.assertPendingAcquires.called).toBeFalsy()
|
184
|
+
})
|
153
185
|
})
|