-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(csi-22): add proxy lib to handlers (#1060)
* feat(csi-22): add proxy lib to handlers * diff * add * int tests * fix hanging int tests * fixes? * unit fixes? * coverage * feat: refactor proxy cache integration * feat: restore default * feat: minor optimization * test: update coverage * test: remove try-catch * fix: fix disconnect error * feat: proxy cache update (#1061) * addressed comments --------- Co-authored-by: Steven Oderayi <[email protected]>
- Loading branch information
Showing
52 changed files
with
757 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
'use strict' | ||
const { createProxyCache } = require('@mojaloop/inter-scheme-proxy-cache-lib') | ||
const Config = require('./config.js') | ||
const ParticipantService = require('../../src/domain/participant') | ||
|
||
let proxyCache | ||
|
||
const connect = async () => { | ||
return getCache().connect() | ||
} | ||
|
||
const disconnect = async () => { | ||
return proxyCache?.isConnected && proxyCache.disconnect() | ||
} | ||
|
||
const getCache = () => { | ||
if (!proxyCache) { | ||
proxyCache = Object.freeze(createProxyCache( | ||
Config.PROXY_CACHE_CONFIG.type, | ||
Config.PROXY_CACHE_CONFIG.proxyConfig | ||
)) | ||
} | ||
return proxyCache | ||
} | ||
|
||
const getFSPProxy = async (dfspId) => { | ||
const participant = await ParticipantService.getByName(dfspId) | ||
return { | ||
inScheme: !!participant, | ||
proxyId: !participant ? await getCache().lookupProxyByDfspId(dfspId) : null | ||
} | ||
} | ||
|
||
const checkSameCreditorDebtorProxy = async (debtorDfspId, creditorDfspId) => { | ||
const [debtorProxyId, creditorProxyId] = await Promise.all([ | ||
await getCache().lookupProxyByDfspId(debtorDfspId), | ||
await getCache().lookupProxyByDfspId(creditorDfspId) | ||
]) | ||
return debtorProxyId && creditorProxyId ? debtorProxyId === creditorProxyId : false | ||
} | ||
|
||
module.exports = { | ||
connect, | ||
disconnect, | ||
getCache, | ||
getFSPProxy, | ||
checkSameCreditorDebtorProxy | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.