@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,43 @@
|
|
|
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
|
+
* James Bush - james.bush@modusbox.com *
|
|
9
|
+
**************************************************************************/
|
|
10
|
+
|
|
11
|
+
'use strict';
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
const InboundTransfersModel = require('./InboundTransfersModel.js');
|
|
15
|
+
const OutboundTransfersModel = require('./OutboundTransfersModel.js');
|
|
16
|
+
const OutboundBulkQuotesModel = require('./OutboundBulkQuotesModel');
|
|
17
|
+
const OutboundBulkTransfersModel = require('./OutboundBulkTransfersModel.js');
|
|
18
|
+
const OutboundRequestToPayTransferModel = require('./OutboundRequestToPayTransferModel.js');
|
|
19
|
+
const AccountsModel = require('./AccountsModel');
|
|
20
|
+
const ProxyModel = require('./ProxyModel');
|
|
21
|
+
const OutboundRequestToPayModel = require('./OutboundRequestToPayModel');
|
|
22
|
+
const { BackendError, PersistentStateMachine } = require('./common');
|
|
23
|
+
const PartiesModel = require('./PartiesModel');
|
|
24
|
+
const QuotesModel = require('./QuotesModel');
|
|
25
|
+
const TransfersModel = require('./TransfersModel');
|
|
26
|
+
const AuthorizationsModel = require('./AuthorizationsModel');
|
|
27
|
+
|
|
28
|
+
module.exports = {
|
|
29
|
+
AccountsModel,
|
|
30
|
+
BackendError,
|
|
31
|
+
OutboundBulkQuotesModel,
|
|
32
|
+
OutboundBulkTransfersModel,
|
|
33
|
+
OutboundRequestToPayTransferModel,
|
|
34
|
+
OutboundRequestToPayModel,
|
|
35
|
+
InboundTransfersModel,
|
|
36
|
+
OutboundTransfersModel,
|
|
37
|
+
ProxyModel,
|
|
38
|
+
PersistentStateMachine,
|
|
39
|
+
PartiesModel,
|
|
40
|
+
QuotesModel,
|
|
41
|
+
TransfersModel,
|
|
42
|
+
AuthorizationsModel
|
|
43
|
+
};
|
|
@@ -0,0 +1,113 @@
|
|
|
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 pr = require('promise-timeout');
|
|
13
|
+
|
|
14
|
+
class InitAndJobRequiredByWait extends Error {
|
|
15
|
+
constructor(channel) {
|
|
16
|
+
super(`'init' & 'job' methods of ObservedJob(cache, channel:'${channel}') should be called before 'wait' method`);
|
|
17
|
+
this.channel = channel;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
class DeferredJob {
|
|
22
|
+
|
|
23
|
+
constructor(cache, channel, defaultTimeoutInMs) {
|
|
24
|
+
this.cache = cache;
|
|
25
|
+
this.channel = channel;
|
|
26
|
+
this.defaultTimeoutInMs = defaultTimeoutInMs || deferredJob.defaultTimeoutInMs;
|
|
27
|
+
this.sid = this.tailInit = this.listenerJob = null;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
init(tailInit) {
|
|
31
|
+
this.tailInit = tailInit;
|
|
32
|
+
return this;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
job(job) {
|
|
36
|
+
this.listenerJob = job;
|
|
37
|
+
return this;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
async wait(timeout) {
|
|
41
|
+
// mvp validation
|
|
42
|
+
if (!(this.tailInit || this.listenerJob)) {
|
|
43
|
+
throw new InitAndJobRequiredByWait(this.channel);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// eslint-disable-next-line no-async-promise-executor
|
|
47
|
+
const promise = new Promise(async (resolve, reject) => {
|
|
48
|
+
try {
|
|
49
|
+
// subscribe to the channel to execute the jobCb when the message arrive
|
|
50
|
+
this.sid = await this.cache.subscribe(this.channel, async (channel, message) => {
|
|
51
|
+
// consume message
|
|
52
|
+
try {
|
|
53
|
+
// unsubscribe first to be sure the jobCb will be executed only once
|
|
54
|
+
// and system resources are preserved
|
|
55
|
+
this.unsubscribe();
|
|
56
|
+
|
|
57
|
+
// messages comes as stringified JSON
|
|
58
|
+
// and we don't want to bother listener about de-serialization
|
|
59
|
+
const parsed = JSON.parse(message);
|
|
60
|
+
|
|
61
|
+
// invoke deferred job
|
|
62
|
+
this.listenerJob(parsed);
|
|
63
|
+
} catch (err) {
|
|
64
|
+
return reject(err);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// done
|
|
68
|
+
resolve();
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
// invoke the async task which should effects in the future
|
|
72
|
+
// by publishing the message to channel via trigger method
|
|
73
|
+
// so the jobCb will be invoked
|
|
74
|
+
await this.tailInit(this.channel, this.sid);
|
|
75
|
+
} catch (err) {
|
|
76
|
+
this.unsubscribe();
|
|
77
|
+
reject(err);
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
// ensure the whole process will finish in specified timeout
|
|
82
|
+
// throws error if timeout happens
|
|
83
|
+
return pr.timeout(promise, timeout || this.defaultTimeoutInMs)
|
|
84
|
+
.catch(async (err) => {
|
|
85
|
+
await this.unsubscribe();
|
|
86
|
+
throw err;
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
async unsubscribe() {
|
|
91
|
+
if (this.sid && this.cache && this.channel) {
|
|
92
|
+
await this.cache.unsubscribe(this.channel, this.sid);
|
|
93
|
+
this.sid = null;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// trigger the deferred job
|
|
98
|
+
async trigger(message) {
|
|
99
|
+
// message must be stringified before passing via channel
|
|
100
|
+
const stringified = JSON.stringify(message);
|
|
101
|
+
return this.cache.publish(this.channel, stringified);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
function deferredJob(cache, channel, defaultTimeoutInMs) {
|
|
108
|
+
return new DeferredJob(cache, channel, defaultTimeoutInMs);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
deferredJob.defaultTimeoutInMs = 2000;
|
|
112
|
+
|
|
113
|
+
module.exports = deferredJob;
|
|
@@ -0,0 +1,227 @@
|
|
|
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
|
+
* James Bush - james.bush@modusbox.com *
|
|
9
|
+
**************************************************************************/
|
|
10
|
+
|
|
11
|
+
'use strict';
|
|
12
|
+
|
|
13
|
+
const http = require('http');
|
|
14
|
+
const { request } = require('@mojaloop/sdk-standard-components');
|
|
15
|
+
const { buildUrl, throwOrJson, HTTPResponseError } = require('./common');
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* A class for making requests to DFSP backend API
|
|
20
|
+
*/
|
|
21
|
+
class BackendRequests {
|
|
22
|
+
constructor(config) {
|
|
23
|
+
this.config = config;
|
|
24
|
+
this.logger = config.logger;
|
|
25
|
+
|
|
26
|
+
// FSPID of THIS DFSP
|
|
27
|
+
this.dfspId = config.dfspId;
|
|
28
|
+
|
|
29
|
+
// make sure we keep alive connections to the backend
|
|
30
|
+
this.agent = new http.Agent({
|
|
31
|
+
keepAlive: true
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
this.transportScheme = 'http';
|
|
35
|
+
|
|
36
|
+
// Switch or peer DFSP endpoint
|
|
37
|
+
this.backendEndpoint = `${this.transportScheme}://${config.backendEndpoint}`;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Executes a GET /otp request for the specified transaction request id
|
|
42
|
+
*
|
|
43
|
+
* @returns {object} - JSON response body if one was received
|
|
44
|
+
*/
|
|
45
|
+
async getOTP(transactionRequestId) {
|
|
46
|
+
const url = `otp/${transactionRequestId}`;
|
|
47
|
+
return this._get(url);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Executes a GET /parties request for the specified identifier type and identifier
|
|
53
|
+
*
|
|
54
|
+
* @returns {object} - JSON response body if one was received
|
|
55
|
+
*/
|
|
56
|
+
async getParties(idType, idValue, idSubValue) {
|
|
57
|
+
const url = `parties/${idType}/${idValue}`
|
|
58
|
+
+ (idSubValue ? `/${idSubValue}` : '');
|
|
59
|
+
return this._get(url);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Executes a GET /transfers request for the specified transfer ID
|
|
64
|
+
*
|
|
65
|
+
* @returns {object} - JSON response body if one was received
|
|
66
|
+
*/
|
|
67
|
+
async getTransfers(transferId) {
|
|
68
|
+
const url = `transfers/${transferId}`;
|
|
69
|
+
return this._get(url);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Executes a POST /quotes request for the specified quote request
|
|
75
|
+
*
|
|
76
|
+
* @returns {object} - JSON response body if one was received
|
|
77
|
+
*/
|
|
78
|
+
async postQuoteRequests(quoteRequest) {
|
|
79
|
+
return this._post('quoterequests', quoteRequest);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Executes a POST /transfers request for the specified transfer prepare
|
|
85
|
+
*
|
|
86
|
+
* @returns {object} - JSON response body if one was received
|
|
87
|
+
*/
|
|
88
|
+
async postTransfers(prepare) {
|
|
89
|
+
return this._post('transfers', prepare);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Executes a POST /transactionRequests request for the specified transaction request
|
|
94
|
+
*
|
|
95
|
+
* @returns {object} - JSON response body if one was received
|
|
96
|
+
*/
|
|
97
|
+
async postTransactionRequests(transactionRequest) {
|
|
98
|
+
return this._post('transactionrequests', transactionRequest);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Executes a POST /bulkQuotes request for the specified bulk quotes request
|
|
103
|
+
*
|
|
104
|
+
* @returns {object} - JSON response body if one was received
|
|
105
|
+
*/
|
|
106
|
+
async postBulkQuotes(bulkQuotesRequest) {
|
|
107
|
+
return this._post('bulkQuotes', bulkQuotesRequest);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Executes a GET /bulkQuotes/{ID} request for the specified bulk quote ID
|
|
112
|
+
*
|
|
113
|
+
* @returns {object} - JSON response body if one was received
|
|
114
|
+
*/
|
|
115
|
+
async getBulkQuotes(bulkQuoteId) {
|
|
116
|
+
const url = `bulkQuotes/${bulkQuoteId}`;
|
|
117
|
+
return this._get(url);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Executes a POST /bulkTransfers request for the specified bulk transfer prepare
|
|
122
|
+
*
|
|
123
|
+
* @returns {object} - JSON response body if one was received
|
|
124
|
+
*/
|
|
125
|
+
async postBulkTransfers(prepare) {
|
|
126
|
+
return this._post('bulkTransfers', prepare);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Executes a GET /bulkTransfers/{ID} request for the specified bulk transfer ID
|
|
131
|
+
*
|
|
132
|
+
* @returns {object} - JSON response body if one was received
|
|
133
|
+
*/
|
|
134
|
+
async getBulkTransfers(bulkTransferId) {
|
|
135
|
+
const url = `bulkTransfers/${bulkTransferId}`;
|
|
136
|
+
return this._get(url);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Executes a PUT /transfers/{ID} request to forward notification for success
|
|
141
|
+
*
|
|
142
|
+
* @returns {object} - JSON response body if one was received
|
|
143
|
+
*/
|
|
144
|
+
|
|
145
|
+
async putTransfersNotification(notifcation, transferId) {
|
|
146
|
+
const url = `transfers/${transferId}`;
|
|
147
|
+
return this._put(url, notifcation);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Utility function for building outgoing request headers as required by the mojaloop api spec
|
|
152
|
+
*
|
|
153
|
+
* @returns {object} - headers object for use in requests to mojaloop api endpoints
|
|
154
|
+
*/
|
|
155
|
+
_buildHeaders () {
|
|
156
|
+
const headers = {
|
|
157
|
+
'Content-Type': 'application/json',
|
|
158
|
+
'Accept': 'application/json',
|
|
159
|
+
'Date': new Date().toUTCString()
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
return headers;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
_get(url) {
|
|
166
|
+
const reqOpts = {
|
|
167
|
+
method: 'GET',
|
|
168
|
+
uri: buildUrl(this.backendEndpoint, url),
|
|
169
|
+
headers: this._buildHeaders(),
|
|
170
|
+
};
|
|
171
|
+
|
|
172
|
+
// Note we do not JWS sign requests with no body i.e. GET requests
|
|
173
|
+
|
|
174
|
+
try {
|
|
175
|
+
this.logger.push({ reqOpts }).log('Executing HTTP GET');
|
|
176
|
+
return request({...reqOpts, agent: this.agent}).then(throwOrJson);
|
|
177
|
+
}
|
|
178
|
+
catch (e) {
|
|
179
|
+
this.logger.push({ e }).log('Error attempting HTTP GET');
|
|
180
|
+
throw e;
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
_put(url, body) {
|
|
186
|
+
const reqOpts = {
|
|
187
|
+
method: 'PUT',
|
|
188
|
+
uri: buildUrl(this.backendEndpoint, url),
|
|
189
|
+
headers: this._buildHeaders(),
|
|
190
|
+
body: JSON.stringify(body)
|
|
191
|
+
};
|
|
192
|
+
|
|
193
|
+
try {
|
|
194
|
+
this.logger.push({ reqOpts }).log('Executing HTTP PUT');
|
|
195
|
+
return request({...reqOpts, agent: this.agent}).then(throwOrJson);
|
|
196
|
+
}
|
|
197
|
+
catch (e) {
|
|
198
|
+
this.logger.push({ e }).log('Error attempting HTTP PUT');
|
|
199
|
+
throw e;
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
|
|
204
|
+
_post(url, body) {
|
|
205
|
+
const reqOpts = {
|
|
206
|
+
method: 'POST',
|
|
207
|
+
uri: buildUrl(this.backendEndpoint, url),
|
|
208
|
+
headers: this._buildHeaders(),
|
|
209
|
+
body: JSON.stringify(body),
|
|
210
|
+
};
|
|
211
|
+
|
|
212
|
+
try {
|
|
213
|
+
this.logger.push({ reqOpts }).log('Executing HTTP POST');
|
|
214
|
+
return request({...reqOpts, agent: this.agent}).then(throwOrJson);
|
|
215
|
+
}
|
|
216
|
+
catch (e) {
|
|
217
|
+
this.logger.push({ e }).log('Error attempting POST.');
|
|
218
|
+
throw e;
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
|
|
224
|
+
module.exports = {
|
|
225
|
+
BackendRequests,
|
|
226
|
+
HTTPResponseError,
|
|
227
|
+
};
|
|
@@ -0,0 +1,76 @@
|
|
|
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
|
+
* James Bush - james.bush@modusbox.com *
|
|
9
|
+
**************************************************************************/
|
|
10
|
+
|
|
11
|
+
'use strict';
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
const util = require('util');
|
|
15
|
+
const respErrSym = Symbol('ResponseErrorDataSym');
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* An HTTPResponseError class
|
|
20
|
+
*/
|
|
21
|
+
class HTTPResponseError extends Error {
|
|
22
|
+
constructor(params) {
|
|
23
|
+
super(params.msg);
|
|
24
|
+
this[respErrSym] = params;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
getData() {
|
|
28
|
+
return this[respErrSym];
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
toString() {
|
|
32
|
+
return util.inspect(this[respErrSym]);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
toJSON() {
|
|
36
|
+
return JSON.stringify(this[respErrSym]);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
// Strip all beginning and end forward-slashes from each of the arguments, then join all the
|
|
42
|
+
// stripped strings with a forward-slash between them. If the last string ended with a
|
|
43
|
+
// forward-slash, append that to the result.
|
|
44
|
+
const buildUrl = (...args) => {
|
|
45
|
+
return args
|
|
46
|
+
.filter(e => e !== undefined)
|
|
47
|
+
.map(s => s.replace(/(^\/*|\/*$)/g, '')) /* This comment works around a problem with editor syntax highglighting */
|
|
48
|
+
.join('/')
|
|
49
|
+
+ ((args[args.length - 1].slice(-1) === '/') ? '/' : '');
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
const throwOrJson = async (res) => {
|
|
54
|
+
// TODO: will a 503 or 500 with content-length zero generate an error?
|
|
55
|
+
// or a 404 for that matter?!
|
|
56
|
+
|
|
57
|
+
if (res.headers['content-length'] === '0' || res.statusCode === 204) {
|
|
58
|
+
// success but no content, return null
|
|
59
|
+
return null;
|
|
60
|
+
}
|
|
61
|
+
if(res.statusCode < 200 || res.statusCode >= 300) {
|
|
62
|
+
// not a successful request
|
|
63
|
+
throw new HTTPResponseError({ msg: `Request returned non-success status code ${res.statusCode}`,
|
|
64
|
+
res
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
return res.data;
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
module.exports = {
|
|
73
|
+
HTTPResponseError,
|
|
74
|
+
buildUrl,
|
|
75
|
+
throwOrJson,
|
|
76
|
+
};
|