@mojaloop/sdk-scheme-adapter 11.18.8
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/.env.example +140 -0
- package/.eslintignore +2 -0
- package/.eslintrc.json +30 -0
- package/.nvmrc +1 -0
- package/.versionrc +15 -0
- package/CHANGELOG.md +118 -0
- package/InboundServer/api.yaml +3594 -0
- package/InboundServer/api_template.yaml +69 -0
- package/InboundServer/handlers.js +940 -0
- package/InboundServer/index.js +205 -0
- package/InboundServer/middlewares.js +426 -0
- package/OAuthTestServer/index.js +66 -0
- package/OAuthTestServer/model.js +70 -0
- package/OutboundServer/api.yaml +2732 -0
- package/OutboundServer/api_interfaces/index.d.ts +117 -0
- package/OutboundServer/api_interfaces/openapi.d.ts +1475 -0
- package/OutboundServer/api_template/components/parameters/bulkQuoteId.yaml +9 -0
- package/OutboundServer/api_template/components/parameters/bulkTransferId.yaml +9 -0
- package/OutboundServer/api_template/components/parameters/requestToPayTransactionId.yaml +9 -0
- package/OutboundServer/api_template/components/parameters/transferId.yaml +9 -0
- package/OutboundServer/api_template/components/responses/accountsCreationCompleted.yaml +5 -0
- package/OutboundServer/api_template/components/responses/accountsCreationError.yaml +5 -0
- package/OutboundServer/api_template/components/responses/accountsCreationTimeout.yaml +5 -0
- package/OutboundServer/api_template/components/responses/authorizationPostSuccess.yaml +5 -0
- package/OutboundServer/api_template/components/responses/authorizationsServerError.yaml +5 -0
- package/OutboundServer/api_template/components/responses/bulkQuoteBadRequest.yaml +5 -0
- package/OutboundServer/api_template/components/responses/bulkQuoteServerError.yaml +5 -0
- package/OutboundServer/api_template/components/responses/bulkQuoteSuccess.yaml +5 -0
- package/OutboundServer/api_template/components/responses/bulkQuoteTimeout.yaml +5 -0
- package/OutboundServer/api_template/components/responses/bulkTransferBadRequest.yaml +5 -0
- package/OutboundServer/api_template/components/responses/bulkTransferServerError.yaml +5 -0
- package/OutboundServer/api_template/components/responses/bulkTransferSuccess.yaml +5 -0
- package/OutboundServer/api_template/components/responses/bulkTransferTimeout.yaml +5 -0
- package/OutboundServer/api_template/components/responses/partiesByIdError404.yaml +9 -0
- package/OutboundServer/api_template/components/responses/partiesByIdSuccess.yaml +5 -0
- package/OutboundServer/api_template/components/responses/quotesPostSuccess.yaml +5 -0
- package/OutboundServer/api_template/components/responses/quotesServerError.yaml +5 -0
- package/OutboundServer/api_template/components/responses/requestToPaySuccess.yaml +5 -0
- package/OutboundServer/api_template/components/responses/requestToPayTransferBadRequest.yaml +5 -0
- package/OutboundServer/api_template/components/responses/requestToPayTransferSuccess.yaml +5 -0
- package/OutboundServer/api_template/components/responses/simpleTransfersPostSuccess.yaml +5 -0
- package/OutboundServer/api_template/components/responses/simpleTransfersServerError.yaml +5 -0
- package/OutboundServer/api_template/components/responses/transferBadRequest.yaml +5 -0
- package/OutboundServer/api_template/components/responses/transferServerError.yaml +5 -0
- package/OutboundServer/api_template/components/responses/transferSuccess.yaml +5 -0
- package/OutboundServer/api_template/components/responses/transferTimeout.yaml +5 -0
- package/OutboundServer/api_template/components/schemas/accountCreationStatus.yaml +18 -0
- package/OutboundServer/api_template/components/schemas/accountsCreationState.yaml +4 -0
- package/OutboundServer/api_template/components/schemas/accountsRequest.yaml +20 -0
- package/OutboundServer/api_template/components/schemas/accountsResponse.yaml +15 -0
- package/OutboundServer/api_template/components/schemas/async2SyncCurrentState.yaml +5 -0
- package/OutboundServer/api_template/components/schemas/authorizationsPostRequest.yaml +15 -0
- package/OutboundServer/api_template/components/schemas/authorizationsPostResponse.yaml +19 -0
- package/OutboundServer/api_template/components/schemas/bulkQuoteErrorResponse.yaml +8 -0
- package/OutboundServer/api_template/components/schemas/bulkQuoteRequest.yaml +26 -0
- package/OutboundServer/api_template/components/schemas/bulkQuoteResponse.yaml +21 -0
- package/OutboundServer/api_template/components/schemas/bulkQuoteStatus.yaml +4 -0
- package/OutboundServer/api_template/components/schemas/bulkQuoteStatusResponse.yaml +17 -0
- package/OutboundServer/api_template/components/schemas/bulkTransferErrorResponse.yaml +8 -0
- package/OutboundServer/api_template/components/schemas/bulkTransferRequest.yaml +26 -0
- package/OutboundServer/api_template/components/schemas/bulkTransferResponse.yaml +16 -0
- package/OutboundServer/api_template/components/schemas/bulkTransferStatus.yaml +4 -0
- package/OutboundServer/api_template/components/schemas/bulkTransferStatusResponse.yaml +17 -0
- package/OutboundServer/api_template/components/schemas/errorAccountsResponse.yaml +8 -0
- package/OutboundServer/api_template/components/schemas/errorAuthorizationsResponse.yaml +3 -0
- package/OutboundServer/api_template/components/schemas/errorQuotesResponse.yaml +9 -0
- package/OutboundServer/api_template/components/schemas/errorResponse.yaml +8 -0
- package/OutboundServer/api_template/components/schemas/errorSimpleTransfersResponse.yaml +3 -0
- package/OutboundServer/api_template/components/schemas/errorTransferResponse.yaml +8 -0
- package/OutboundServer/api_template/components/schemas/extensionListEmptiable.yaml +6 -0
- package/OutboundServer/api_template/components/schemas/individualQuote.yaml +32 -0
- package/OutboundServer/api_template/components/schemas/individualQuoteResult.yaml +28 -0
- package/OutboundServer/api_template/components/schemas/individualTransfer.yaml +32 -0
- package/OutboundServer/api_template/components/schemas/individualTransferFulfilment.yaml +13 -0
- package/OutboundServer/api_template/components/schemas/individualTransferResult.yaml +41 -0
- package/OutboundServer/api_template/components/schemas/mojaloopError.yaml +5 -0
- package/OutboundServer/api_template/components/schemas/mojaloopTransactionRequestState.yaml +2 -0
- package/OutboundServer/api_template/components/schemas/partiesByIdResponse.yaml +13 -0
- package/OutboundServer/api_template/components/schemas/quote.yaml +3 -0
- package/OutboundServer/api_template/components/schemas/quoteError.yaml +16 -0
- package/OutboundServer/api_template/components/schemas/quotesPostRequest.yaml +13 -0
- package/OutboundServer/api_template/components/schemas/quotesPostResponse.yaml +48 -0
- package/OutboundServer/api_template/components/schemas/requestToPayRequest.yaml +39 -0
- package/OutboundServer/api_template/components/schemas/requestToPayResponse.yaml +41 -0
- package/OutboundServer/api_template/components/schemas/requestToPayTransferRequest.yaml +42 -0
- package/OutboundServer/api_template/components/schemas/requestToPayTransferResponse.yaml +58 -0
- package/OutboundServer/api_template/components/schemas/simpleTransferServerError.yaml +5 -0
- package/OutboundServer/api_template/components/schemas/simpleTransfersPostRequest.yaml +12 -0
- package/OutboundServer/api_template/components/schemas/simpleTransfersPostResponse.yaml +11 -0
- package/OutboundServer/api_template/components/schemas/transactionType.yaml +4 -0
- package/OutboundServer/api_template/components/schemas/transferContinuationAcceptOTP.yaml +9 -0
- package/OutboundServer/api_template/components/schemas/transferContinuationAcceptParty.yaml +8 -0
- package/OutboundServer/api_template/components/schemas/transferContinuationAcceptQuote.yaml +9 -0
- package/OutboundServer/api_template/components/schemas/transferError.yaml +16 -0
- package/OutboundServer/api_template/components/schemas/transferFulfilment.yaml +3 -0
- package/OutboundServer/api_template/components/schemas/transferParty.yaml +40 -0
- package/OutboundServer/api_template/components/schemas/transferRequest.yaml +37 -0
- package/OutboundServer/api_template/components/schemas/transferResponse.yaml +58 -0
- package/OutboundServer/api_template/components/schemas/transferStatus.yaml +6 -0
- package/OutboundServer/api_template/components/schemas/transferStatusResponse.yaml +13 -0
- package/OutboundServer/api_template/health.yaml +12 -0
- package/OutboundServer/api_template/openapi.yaml +55 -0
- package/OutboundServer/api_template/paths/accounts.yaml +26 -0
- package/OutboundServer/api_template/paths/authorizations.yaml +19 -0
- package/OutboundServer/api_template/paths/bulkQuotes.yaml +23 -0
- package/OutboundServer/api_template/paths/bulkQuotes_bulkQuoteId.yaml +24 -0
- package/OutboundServer/api_template/paths/bulkTransfers.yaml +23 -0
- package/OutboundServer/api_template/paths/bulkTransfers_bulkTransferId.yaml +24 -0
- package/OutboundServer/api_template/paths/parties_Type_ID.yaml +20 -0
- package/OutboundServer/api_template/paths/parties_Type_ID_SubId.yaml +22 -0
- package/OutboundServer/api_template/paths/quotes.yaml +20 -0
- package/OutboundServer/api_template/paths/requestToPay.yaml +22 -0
- package/OutboundServer/api_template/paths/requestToPayTransfer.yaml +57 -0
- package/OutboundServer/api_template/paths/requestToPayTransfer_requestToPayTransactionId.yaml +34 -0
- package/OutboundServer/api_template/paths/simpleTransfers.yaml +19 -0
- package/OutboundServer/api_template/paths/transfers.yaml +55 -0
- package/OutboundServer/api_template/paths/transfers_transferId.yaml +58 -0
- package/OutboundServer/handlers.js +622 -0
- package/OutboundServer/index.js +137 -0
- package/OutboundServer/middlewares.js +67 -0
- package/TestServer/api.yaml +62 -0
- package/TestServer/handlers.js +63 -0
- package/TestServer/index.js +215 -0
- package/audit-resolve.json +65 -0
- package/babel.config.js +3 -0
- package/config.js +158 -0
- package/index.d.ts +1 -0
- package/index.js +149 -0
- package/jest.config.js +15 -0
- package/lib/api/index.js +12 -0
- package/lib/cache.js +352 -0
- package/lib/check.js +25 -0
- package/lib/model/AccountsModel.js +396 -0
- package/lib/model/Async2SyncModel.js +283 -0
- package/lib/model/AuthorizationsModel.js +86 -0
- package/lib/model/InboundTransfersModel.js +730 -0
- package/lib/model/OutboundBulkQuotesModel.js +485 -0
- package/lib/model/OutboundBulkTransfersModel.js +479 -0
- package/lib/model/OutboundRequestToPayModel.js +517 -0
- package/lib/model/OutboundRequestToPayTransferModel.js +893 -0
- package/lib/model/OutboundTransfersModel.js +823 -0
- package/lib/model/PartiesModel.js +70 -0
- package/lib/model/ProxyModel/MatchRules/Expression.js +48 -0
- package/lib/model/ProxyModel/MatchRules/Headers.js +65 -0
- package/lib/model/ProxyModel/MatchRules/MatchRule.js +27 -0
- package/lib/model/ProxyModel/MatchRules/Path.js +36 -0
- package/lib/model/ProxyModel/MatchRules/Query.js +65 -0
- package/lib/model/ProxyModel/MatchRules/index.js +19 -0
- package/lib/model/ProxyModel/Route.js +82 -0
- package/lib/model/ProxyModel/configSchema.json +118 -0
- package/lib/model/ProxyModel/index.js +138 -0
- package/lib/model/QuotesModel.js +94 -0
- package/lib/model/TransfersModel.js +81 -0
- package/lib/model/common/BackendError.js +26 -0
- package/lib/model/common/PersistentStateMachine.js +93 -0
- package/lib/model/common/index.js +18 -0
- package/lib/model/index.js +43 -0
- package/lib/model/lib/deferredJob.js +113 -0
- package/lib/model/lib/index.js +9 -0
- package/lib/model/lib/requests/backendRequests.js +227 -0
- package/lib/model/lib/requests/common.js +76 -0
- package/lib/model/lib/requests/index.js +19 -0
- package/lib/model/lib/shared.js +468 -0
- package/lib/randomphrase/index.js +21 -0
- package/lib/randomphrase/words.json +3397 -0
- package/lib/router.js +28 -0
- package/lib/validate.js +205 -0
- package/package.json +102 -0
- package/test/__mocks__/@mojaloop/sdk-standard-components.js +152 -0
- package/test/__mocks__/javascript-state-machine.js +21 -0
- package/test/__mocks__/redis.js +49 -0
- package/test/__mocks__/uuidv4.js +16 -0
- package/test/config/integration.env +136 -0
- package/test/integration/lib/Outbound/authorizations.test.js +58 -0
- package/test/integration/lib/Outbound/data/authorizationsPostRequest.json +43 -0
- package/test/integration/lib/Outbound/data/quotesPostRequest.json +52 -0
- package/test/integration/lib/Outbound/data/transfersPostRequest.json +24 -0
- package/test/integration/lib/Outbound/parties.test.js +28 -0
- package/test/integration/lib/Outbound/quotes.test.js +58 -0
- package/test/integration/lib/Outbound/simpleTransfers.test.js +67 -0
- package/test/integration/lib/cache.test.js +80 -0
- package/test/integration/testEnv.js +7 -0
- package/test/unit/InboundServer.test.js +443 -0
- package/test/unit/TestServer.test.js +394 -0
- package/test/unit/api/accounts/accounts.test.js +128 -0
- package/test/unit/api/accounts/data/postAccountsBody.json +7 -0
- package/test/unit/api/accounts/data/postAccountsErrorMojaloopResponse.json +25 -0
- package/test/unit/api/accounts/data/postAccountsErrorTimeoutResponse.json +19 -0
- package/test/unit/api/accounts/data/postAccountsSuccessResponse.json +17 -0
- package/test/unit/api/accounts/data/postAccountsSuccessResponseWithError1.json +21 -0
- package/test/unit/api/accounts/data/postAccountsSuccessResponseWithError2.json +21 -0
- package/test/unit/api/accounts/utils.js +65 -0
- package/test/unit/api/proxy/data/proxyConfig.yaml +82 -0
- package/test/unit/api/proxy/data/requestBody.json +22 -0
- package/test/unit/api/proxy/data/requestHeaders.json +5 -0
- package/test/unit/api/proxy/data/requestQuery.json +6 -0
- package/test/unit/api/proxy/data/responseBody.json +21 -0
- package/test/unit/api/proxy/data/responseHeaders.json +5 -0
- package/test/unit/api/proxy/proxy.test.js +220 -0
- package/test/unit/api/proxy/utils.js +79 -0
- package/test/unit/api/transfers/data/getTransfersCommittedResponse.json +21 -0
- package/test/unit/api/transfers/data/getTransfersErrorNotFound.json +17 -0
- package/test/unit/api/transfers/data/postQuotesBody.json +52 -0
- package/test/unit/api/transfers/data/postTransfersBadBody.json +17 -0
- package/test/unit/api/transfers/data/postTransfersBody.json +24 -0
- package/test/unit/api/transfers/data/postTransfersErrorMojaloopResponse.json +53 -0
- package/test/unit/api/transfers/data/postTransfersErrorTimeoutResponse.json +47 -0
- package/test/unit/api/transfers/data/postTransfersSimpleBody.json +26 -0
- package/test/unit/api/transfers/data/postTransfersSuccessResponse.json +101 -0
- package/test/unit/api/transfers/data/putPartiesBody.json +20 -0
- package/test/unit/api/transfers/data/putQuotesBody.json +37 -0
- package/test/unit/api/transfers/data/putTransfersBody.json +17 -0
- package/test/unit/api/transfers/transfers.test.js +191 -0
- package/test/unit/api/transfers/utils.js +183 -0
- package/test/unit/api/utils.js +75 -0
- package/test/unit/config.test.js +119 -0
- package/test/unit/data/commonHttpHeaders.json +6 -0
- package/test/unit/data/defaultConfig.json +58 -0
- package/test/unit/data/postQuotesBody.json +52 -0
- package/test/unit/data/putParticipantsBody.json +12 -0
- package/test/unit/data/putPartiesBody.json +20 -0
- package/test/unit/data/testFile.json +29 -0
- package/test/unit/data/testFile.yaml +14 -0
- package/test/unit/inboundApi/data/mockArguments.json +117 -0
- package/test/unit/inboundApi/data/mockTransactionRequest.json +42 -0
- package/test/unit/inboundApi/handlers.test.js +799 -0
- package/test/unit/index.test.js +55 -0
- package/test/unit/lib/cache.test.js +146 -0
- package/test/unit/lib/model/AccountsModel.test.js +121 -0
- package/test/unit/lib/model/AuthorizationsModel.test.js +460 -0
- package/test/unit/lib/model/InboundTransfersModel.test.js +628 -0
- package/test/unit/lib/model/OutboundBulkQuotesModel.test.js +249 -0
- package/test/unit/lib/model/OutboundBulkTransfersModel.test.js +244 -0
- package/test/unit/lib/model/OutboundRequestToPayModel.test.js +166 -0
- package/test/unit/lib/model/OutboundRequestToPayTransferModel.test.js +245 -0
- package/test/unit/lib/model/OutboundTransfersModel.test.js +836 -0
- package/test/unit/lib/model/PartiesModel.test.js +468 -0
- package/test/unit/lib/model/QuotesModel.test.js +470 -0
- package/test/unit/lib/model/TransfersModel.test.js +474 -0
- package/test/unit/lib/model/common/PersistentStateMachine.test.js +179 -0
- package/test/unit/lib/model/data/authorizationsResponse.json +13 -0
- package/test/unit/lib/model/data/bulkQuoteRequest.json +27 -0
- package/test/unit/lib/model/data/bulkQuoteResponse.json +35 -0
- package/test/unit/lib/model/data/bulkTransferFulfil.json +13 -0
- package/test/unit/lib/model/data/bulkTransferRequest.json +29 -0
- package/test/unit/lib/model/data/defaultConfig.json +47 -0
- package/test/unit/lib/model/data/getBulkTransfersBackendResponse.json +42 -0
- package/test/unit/lib/model/data/getBulkTransfersMojaloopResponse.json +22 -0
- package/test/unit/lib/model/data/getTransfersBackendResponse.json +34 -0
- package/test/unit/lib/model/data/getTransfersMojaloopResponse.json +17 -0
- package/test/unit/lib/model/data/mockArguments.json +131 -0
- package/test/unit/lib/model/data/mockTxnRequestsArguments.json +63 -0
- package/test/unit/lib/model/data/notificationToPayee.json +10 -0
- package/test/unit/lib/model/data/payeeParty.json +16 -0
- package/test/unit/lib/model/data/putAuthorizationsResponse.json +10 -0
- package/test/unit/lib/model/data/putQuotesResponse.json +33 -0
- package/test/unit/lib/model/data/putTransfersResponse.json +5 -0
- package/test/unit/lib/model/data/quoteResponse.json +31 -0
- package/test/unit/lib/model/data/requestToPayRequest.json +20 -0
- package/test/unit/lib/model/data/requestToPayTransferRequest.json +27 -0
- package/test/unit/lib/model/data/transactionRequestResponse.json +18 -0
- package/test/unit/lib/model/data/transferFulfil.json +8 -0
- package/test/unit/lib/model/data/transferRequest.json +26 -0
- package/test/unit/lib/model/mockedLibRequests.js +74 -0
- package/test/unit/mockLogger.js +39 -0
- package/test/unit/outboundApi/data/bulkQuoteRequest.json +28 -0
- package/test/unit/outboundApi/data/bulkTransferRequest.json +28 -0
- package/test/unit/outboundApi/data/mockBulkQuoteError.json +45 -0
- package/test/unit/outboundApi/data/mockBulkTransferError.json +48 -0
- package/test/unit/outboundApi/data/mockError.json +41 -0
- package/test/unit/outboundApi/data/mockGetPartiesError.json +4 -0
- package/test/unit/outboundApi/data/mockRequestToPayError.json +32 -0
- package/test/unit/outboundApi/data/mockRequestToPayTransferError.json +39 -0
- package/test/unit/outboundApi/data/requestToPay.json +21 -0
- package/test/unit/outboundApi/data/requestToPayTransferRequest.json +20 -0
- package/test/unit/outboundApi/data/transferRequest.json +21 -0
- package/test/unit/outboundApi/handlers.test.js +986 -0
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
/**************************************************************************
|
|
2
|
+
* (C) Copyright ModusBox Inc. 2020 - All rights reserved. *
|
|
3
|
+
* *
|
|
4
|
+
* This file is made available under the terms of the license agreement *
|
|
5
|
+
* specified in the corresponding source code repository. *
|
|
6
|
+
* *
|
|
7
|
+
* ORIGINAL AUTHOR: *
|
|
8
|
+
* Yevhen Kyriukha - yevhen.kyriukha@modusbox.com *
|
|
9
|
+
**************************************************************************/
|
|
10
|
+
|
|
11
|
+
const { BackendError } = require('../common');
|
|
12
|
+
const { MojaloopRequests } = require('@mojaloop/sdk-standard-components');
|
|
13
|
+
const Ajv = require('ajv');
|
|
14
|
+
const configSchema = require('./configSchema');
|
|
15
|
+
const util = require('util');
|
|
16
|
+
const Route = require('./Route');
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* ProxyModel forwards request to corresponding endpoint based on provided route config
|
|
20
|
+
*/
|
|
21
|
+
class ProxyModel {
|
|
22
|
+
/**
|
|
23
|
+
*
|
|
24
|
+
* @param config
|
|
25
|
+
* @param config.logger {Object}
|
|
26
|
+
* @param config.proxyConfig {Object}
|
|
27
|
+
* @param config.peerEndpoint {string}
|
|
28
|
+
* @param config.dfspId {string}
|
|
29
|
+
* @param config.tls {Object}
|
|
30
|
+
* @param config.wso2Auth {Object}
|
|
31
|
+
*/
|
|
32
|
+
constructor(config) {
|
|
33
|
+
this._logger = config.logger;
|
|
34
|
+
|
|
35
|
+
this._requests = new MojaloopRequests({
|
|
36
|
+
logger: this._logger,
|
|
37
|
+
peerEndpoint: config.peerEndpoint,
|
|
38
|
+
dfspId: config.dfspId,
|
|
39
|
+
tls: config.tls,
|
|
40
|
+
jwsSign: config.jwsSign,
|
|
41
|
+
jwsSigningKey: config.jwsSigningKey,
|
|
42
|
+
wso2Auth: config.wso2Auth
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
this._validateConfig(config.proxyConfig);
|
|
46
|
+
this._routes = this._createRoutes(config.proxyConfig);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
async _executePostRequest(request) {
|
|
50
|
+
const res = await this._requests.postCustom(request.url, request.body, request.headers, request.query, true);
|
|
51
|
+
await this._logger.push({statusCode: res.statusCode, headers: res.headers}).log('POST request sent successfully');
|
|
52
|
+
return res;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
async _executePutRequest(request) {
|
|
56
|
+
const res = await this._requests.putCustom(request.url, request.body, request.headers, request.query, true);
|
|
57
|
+
await this._logger.push({statusCode: res.statusCode, headers: res.headers}).log('PUT request sent successfully');
|
|
58
|
+
return res;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
async _executeGetRequest(request) {
|
|
62
|
+
const res = await this._requests.getCustom(request.url, request.headers, request.query, true);
|
|
63
|
+
await this._logger.push({statusCode: res.statusCode, headers: res.headers}).log('GET request sent successfully');
|
|
64
|
+
return res;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
_validateConfig(config) {
|
|
68
|
+
const ajv = new Ajv();
|
|
69
|
+
const validate = ajv.compile(configSchema);
|
|
70
|
+
const valid = validate(config);
|
|
71
|
+
if (!valid) {
|
|
72
|
+
const errors = util.inspect(validate.errors);
|
|
73
|
+
this._logger.push({ errors }).error('Proxy config is invalid');
|
|
74
|
+
throw new Error(`Proxy config is invalid: ${errors}`);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
*
|
|
80
|
+
* @param config
|
|
81
|
+
* @returns {Array.<Object>} myObjects
|
|
82
|
+
* @private
|
|
83
|
+
*/
|
|
84
|
+
_createRoutes(config) {
|
|
85
|
+
try {
|
|
86
|
+
return config.routes.map(routeConfig => new Route(routeConfig));
|
|
87
|
+
} catch (e) {
|
|
88
|
+
this._logger.push({ e }).error('Failed to create route');
|
|
89
|
+
throw e;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
_getMatchingDestination(request) {
|
|
94
|
+
for (const route of this._routes) {
|
|
95
|
+
// Destructure request object to show what we are expecting
|
|
96
|
+
const {path, query, headers} = request;
|
|
97
|
+
if (route.matchRequest({path, query, headers})) {
|
|
98
|
+
return route.destination;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Perform request forwarding
|
|
105
|
+
* @param request {object}
|
|
106
|
+
* @param request.method {string}
|
|
107
|
+
* @param request.url {string}
|
|
108
|
+
* @param request.body {object}
|
|
109
|
+
* @param request.headers {object}
|
|
110
|
+
* @return {Promise<object>}
|
|
111
|
+
*/
|
|
112
|
+
async proxyRequest(request) {
|
|
113
|
+
const allowedMethods = ['GET', 'POST', 'PUT'];
|
|
114
|
+
const method = request.method.toUpperCase();
|
|
115
|
+
if (!allowedMethods.includes(method)) {
|
|
116
|
+
throw new BackendError(`Unsupported HTTP method "${request.method}"`, 400);
|
|
117
|
+
}
|
|
118
|
+
const url = this._getMatchingDestination(request);
|
|
119
|
+
if (!url) {
|
|
120
|
+
this._logger.log(`No proxy rule found for ${request.url}`);
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
const destReq = {
|
|
124
|
+
url,
|
|
125
|
+
body: request.body,
|
|
126
|
+
headers: request.headers,
|
|
127
|
+
query: request.query,
|
|
128
|
+
};
|
|
129
|
+
switch (method) {
|
|
130
|
+
case 'GET': return this._executeGetRequest(destReq);
|
|
131
|
+
case 'POST': return this._executePostRequest(destReq);
|
|
132
|
+
case 'PUT': return this._executePutRequest(destReq);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
module.exports = ProxyModel;
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/**************************************************************************
|
|
2
|
+
* (C) Copyright ModusBox Inc. 2020 - All rights reserved. *
|
|
3
|
+
* *
|
|
4
|
+
* This file is made available under the terms of the license agreement *
|
|
5
|
+
* specified in the corresponding source code repository. *
|
|
6
|
+
* *
|
|
7
|
+
* ORIGINAL AUTHOR: *
|
|
8
|
+
* Paweł Marzec - pawel.marzec@modusbox.com *
|
|
9
|
+
**************************************************************************/
|
|
10
|
+
|
|
11
|
+
'use strict';
|
|
12
|
+
|
|
13
|
+
const Async2SyncModel = require('./Async2SyncModel');
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
// delegated methods for QuotesModel
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* @name channelName
|
|
20
|
+
* @description generates the pub/sub channel name
|
|
21
|
+
* @param {object} - args
|
|
22
|
+
* @param {string} args.quoteId - the quote payload
|
|
23
|
+
* @param {string} [args.fspId] - ignored if passed - the destination fsp id
|
|
24
|
+
* @param {string} [args.quote] - ignored if passed - the quote payload
|
|
25
|
+
* @returns {string} - the pub/sub channel name
|
|
26
|
+
*/
|
|
27
|
+
function channelName({ quoteId /* ,fspId, quote - are not used here */ }) {
|
|
28
|
+
const tokens = ['quotes', quoteId ];
|
|
29
|
+
return tokens.map(x => `${x}`).join('-');
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* @name requestAction
|
|
34
|
+
* @description invokes the call to switch
|
|
35
|
+
* @param {object} requests - MojaloopRequests instance
|
|
36
|
+
* @param {array} args - the arguments passed as object to `run` method
|
|
37
|
+
* @param {string} [args.quoteId] - ignored if passed - the quote I=id
|
|
38
|
+
* @param {string} args.fspId - the destination fsp id
|
|
39
|
+
* @param {string} args.quote - the quote payload
|
|
40
|
+
*/
|
|
41
|
+
function requestAction(requests, { /* quoteId - is not used here */ fspId, quote }) {
|
|
42
|
+
if ( !fspId ) {
|
|
43
|
+
throw new Error('QuotesModel args requires \'fspId\' to be nonempty string');
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
if ( !(quote && typeof(quote) === 'object') ) {
|
|
47
|
+
throw new Error('QuotesModel.requestAction args requires \'quote\' to be specified');
|
|
48
|
+
}
|
|
49
|
+
return requests.postQuotes(quote, fspId);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* @name argsValidationMethod
|
|
54
|
+
* @description makes validation of args object, invoked in `run, triggerDeferredJob, generateKey` methods to ensure everything is going well
|
|
55
|
+
* @param {array} args - the arguments passed as object to `run` method
|
|
56
|
+
* @param {string} args.quoteId - the party type
|
|
57
|
+
* @param {string} [args.fspId] - the destination fsp id
|
|
58
|
+
* @param {string} [args.quote] - the quote payload
|
|
59
|
+
*/
|
|
60
|
+
function argsValidation({ quoteId, fspId, quote }) {
|
|
61
|
+
if (!(quoteId && typeof(quoteId) === 'string' && quoteId.length > 0)) {
|
|
62
|
+
throw new Error('QuotesModel args requires \'quoteId\' is nonempty string and mandatory property');
|
|
63
|
+
}
|
|
64
|
+
if (fspId && !(typeof (fspId) === 'string' && fspId.length > 0)) {
|
|
65
|
+
throw new Error('QuotesModel args requires \'fspId\' to be nonempty string');
|
|
66
|
+
}
|
|
67
|
+
if (quote && quote.quoteId !== quoteId) {
|
|
68
|
+
throw new Error('QuotesModel args requires properties \'quote.quoteId\' and \'quoteId\' to be the equal in value');
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* @name reformatMessage
|
|
74
|
+
* @description reformats message received from PUB/SUB channel, it is optional method, if not specified identify function is used by default
|
|
75
|
+
* @param {object} message - message received
|
|
76
|
+
* @returns {object} - reformatted message
|
|
77
|
+
*/
|
|
78
|
+
function reformatMessage(message) {
|
|
79
|
+
return {
|
|
80
|
+
quotes: { ...message }
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// generate model
|
|
85
|
+
const QuotesModel = Async2SyncModel.generate({
|
|
86
|
+
modelName: 'QuotesModel',
|
|
87
|
+
channelNameMethod: channelName,
|
|
88
|
+
requestActionMethod: requestAction,
|
|
89
|
+
argsValidationMethod: argsValidation,
|
|
90
|
+
reformatMessageMethod: reformatMessage
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
module.exports = QuotesModel;
|
|
94
|
+
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const Async2SyncModel = require('./Async2SyncModel');
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
// delegated methods for TransfersModel
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* @name channelName
|
|
10
|
+
* @description generates the pub/sub channel name
|
|
11
|
+
* @param {object} - args
|
|
12
|
+
* @param {string} args.transferId - the transfer id
|
|
13
|
+
* @returns {string} - the pub/sub channel name
|
|
14
|
+
*/
|
|
15
|
+
function channelName({ transferId }) {
|
|
16
|
+
const tokens = ['transfers', transferId ];
|
|
17
|
+
return tokens.map(x => `${x}`).join('-');
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* @name requestAction
|
|
22
|
+
* @description invokes the call to switch
|
|
23
|
+
* @param {object} requests - MojaloopRequests instance
|
|
24
|
+
* @param {array} args - the arguments passed as object to `run` method
|
|
25
|
+
* @param {string} [args.transferId] - ignored if passed - the transfer I=id
|
|
26
|
+
* @param {string} args.fspId - the destination fsp id
|
|
27
|
+
* @param {string} args.transfer - the transfer payload
|
|
28
|
+
*/
|
|
29
|
+
function requestAction(requests, { /* transferId - is not used here */ fspId, transfer }) {
|
|
30
|
+
if ( !fspId ) {
|
|
31
|
+
throw new Error('TransfersModel args requires \'fspId\' to be nonempty string');
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
if ( !(transfer && typeof(transfer) === 'object') ) {
|
|
35
|
+
throw new Error('TransfersModel.requestAction args requires \'transfer\' to be specified');
|
|
36
|
+
}
|
|
37
|
+
return requests.postTransfers(transfer, fspId);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* @name argsValidationMethod
|
|
42
|
+
* @description makes validation of args object, invoked in `run, triggerDeferredJob, generateKey` methods to ensure everything is going well
|
|
43
|
+
* @param {array} args - the arguments passed as object to `run` method
|
|
44
|
+
* @param {string} args.transferId - the party type
|
|
45
|
+
* @param {string} [args.fspId] - the destination fsp id
|
|
46
|
+
* @param {string} [args.transfer] - the transfer payload
|
|
47
|
+
*/
|
|
48
|
+
function argsValidation({ transferId, fspId, transfer }) {
|
|
49
|
+
if (!(transferId && typeof(transferId) === 'string' && transferId.length > 0)) {
|
|
50
|
+
throw new Error('TransfersModel args requires \'transferId\' is nonempty string and mandatory property');
|
|
51
|
+
}
|
|
52
|
+
if (fspId && !(typeof (fspId) === 'string' && fspId.length > 0)) {
|
|
53
|
+
throw new Error('TransfersModel args requires \'fspId\' to be nonempty string');
|
|
54
|
+
}
|
|
55
|
+
if (transfer && transfer.transferId !== transferId) {
|
|
56
|
+
throw new Error('TransfersModel args requires properties \'transfer.transferId\' and \'transferId\' to be the equal in value');
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* @name reformatMessage
|
|
62
|
+
* @description reformats message received from PUB/SUB channel, it is optional method, if not specified identify function is used by default
|
|
63
|
+
* @param {object} message - message received
|
|
64
|
+
* @returns {object} - reformatted message
|
|
65
|
+
*/
|
|
66
|
+
function reformatMessage(message) {
|
|
67
|
+
return {
|
|
68
|
+
transfer: { ...message }
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// generate model
|
|
73
|
+
const TransfersModel = Async2SyncModel.generate({
|
|
74
|
+
modelName: 'TransfersModel',
|
|
75
|
+
channelNameMethod: channelName,
|
|
76
|
+
requestActionMethod: requestAction,
|
|
77
|
+
argsValidationMethod: argsValidation,
|
|
78
|
+
reformatMessageMethod: reformatMessage
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
module.exports = TransfersModel;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**************************************************************************
|
|
2
|
+
* (C) Copyright ModusBox Inc. 2019 - All rights reserved. *
|
|
3
|
+
* *
|
|
4
|
+
* This file is made available under the terms of the license agreement *
|
|
5
|
+
* specified in the corresponding source code repository. *
|
|
6
|
+
* *
|
|
7
|
+
* ORIGINAL AUTHOR: *
|
|
8
|
+
* Yevhen Kyriukha - yevhen.kyriukha@modusbox.com *
|
|
9
|
+
**************************************************************************/
|
|
10
|
+
|
|
11
|
+
'use strict';
|
|
12
|
+
|
|
13
|
+
class BackendError extends Error {
|
|
14
|
+
constructor(msg, httpStatusCode) {
|
|
15
|
+
super(msg);
|
|
16
|
+
this.httpStatusCode = httpStatusCode;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
toJSON() {
|
|
20
|
+
// return shallow clone of `this`, from `this` are only taken enumerable owned properties
|
|
21
|
+
return Object.assign({}, this);
|
|
22
|
+
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
module.exports = BackendError;
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/**************************************************************************
|
|
2
|
+
* (C) Copyright ModusBox Inc. 2020 - All rights reserved. *
|
|
3
|
+
* *
|
|
4
|
+
* This file is made available under the terms of the license agreement *
|
|
5
|
+
* specified in the corresponding source code repository. *
|
|
6
|
+
* *
|
|
7
|
+
* ORIGINAL AUTHOR: *
|
|
8
|
+
* Paweł Marzec - pawel.marzec@modusbox.com *
|
|
9
|
+
**************************************************************************/
|
|
10
|
+
|
|
11
|
+
'use strict';
|
|
12
|
+
const StateMachine = require('javascript-state-machine');
|
|
13
|
+
|
|
14
|
+
async function saveToCache() {
|
|
15
|
+
const { data, cache, key, logger } = this.context;
|
|
16
|
+
try {
|
|
17
|
+
const res = await cache.set(key, data);
|
|
18
|
+
logger.push({ res }).log(`Persisted model in cache: ${key}`);
|
|
19
|
+
}
|
|
20
|
+
catch(err) {
|
|
21
|
+
logger.push({ err }).log(`Error saving model: ${key}`);
|
|
22
|
+
throw err;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
async function onAfterTransition(transition) {
|
|
27
|
+
const { logger } = this.context;
|
|
28
|
+
logger.log(`State machine transitioned '${transition.transition}': ${transition.from} -> ${transition.to}`);
|
|
29
|
+
this.context.data.currentState = transition.to;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function onPendingTransition(transition) {
|
|
33
|
+
// allow transitions to 'error' state while other transitions are in progress
|
|
34
|
+
if(transition !== 'error') {
|
|
35
|
+
throw new Error(`Transition '${transition}' requested while another transition is in progress.`);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
async function create(data, cache, key, logger, stateMachineSpec ) {
|
|
40
|
+
let initState = stateMachineSpec.init || 'init';
|
|
41
|
+
|
|
42
|
+
if(!data.hasOwnProperty('currentState')) {
|
|
43
|
+
data.currentState = initState;
|
|
44
|
+
} else {
|
|
45
|
+
initState = stateMachineSpec.init = data.currentState;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
stateMachineSpec.data = Object.assign(
|
|
49
|
+
stateMachineSpec.data || {},
|
|
50
|
+
{
|
|
51
|
+
context: {
|
|
52
|
+
data, cache, key, logger
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
);
|
|
56
|
+
|
|
57
|
+
stateMachineSpec.methods = Object.assign(
|
|
58
|
+
stateMachineSpec.methods || {},
|
|
59
|
+
{
|
|
60
|
+
onAfterTransition,
|
|
61
|
+
onPendingTransition,
|
|
62
|
+
saveToCache
|
|
63
|
+
}
|
|
64
|
+
);
|
|
65
|
+
|
|
66
|
+
const stateMachine = new StateMachine(stateMachineSpec);
|
|
67
|
+
await stateMachine[initState];
|
|
68
|
+
return stateMachine;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
async function loadFromCache(cache, key, logger, stateMachineSpec, optCreate) {
|
|
73
|
+
try {
|
|
74
|
+
const data = await cache.get(key);
|
|
75
|
+
if(!data) {
|
|
76
|
+
throw new Error(`No cached data found for: ${key}`);
|
|
77
|
+
}
|
|
78
|
+
logger.push({ cache: data }).log('data loaded from cache');
|
|
79
|
+
|
|
80
|
+
// use delegation to allow customization of 'create'
|
|
81
|
+
const createPSM = optCreate || create;
|
|
82
|
+
return createPSM(data, cache, key, logger, stateMachineSpec);
|
|
83
|
+
}
|
|
84
|
+
catch(err) {
|
|
85
|
+
logger.push({ err }).log(`Error loading data: ${key}`);
|
|
86
|
+
throw err;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
module.exports = {
|
|
91
|
+
loadFromCache,
|
|
92
|
+
create
|
|
93
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**************************************************************************
|
|
2
|
+
* (C) Copyright ModusBox Inc. 2019 - All rights reserved. *
|
|
3
|
+
* *
|
|
4
|
+
* This file is made available under the terms of the license agreement *
|
|
5
|
+
* specified in the corresponding source code repository. *
|
|
6
|
+
* *
|
|
7
|
+
* ORIGINAL AUTHOR: *
|
|
8
|
+
* Paweł Marzec - pawel.marzec@modusbox.com *
|
|
9
|
+
**************************************************************************/
|
|
10
|
+
|
|
11
|
+
'use strict';
|
|
12
|
+
const BackendError = require('./BackendError');
|
|
13
|
+
const PersistentStateMachine = require('./PersistentStateMachine');
|
|
14
|
+
|
|
15
|
+
module.exports = {
|
|
16
|
+
BackendError,
|
|
17
|
+
PersistentStateMachine
|
|
18
|
+
};
|