@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
package/lib/router.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
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
|
+
* Matt Kingston - matt.kingston@modusbox.com *
|
|
9
|
+
**************************************************************************/
|
|
10
|
+
|
|
11
|
+
'use strict';
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
module.exports = (handlerMap) => async (ctx, next) => {
|
|
15
|
+
const handlers = handlerMap[ctx.state.path.pattern];
|
|
16
|
+
const handler = handlers ? handlers[ctx.method.toLowerCase()] : undefined;
|
|
17
|
+
if (!handlers || !handler) {
|
|
18
|
+
ctx.state.logger.log('No handler found');
|
|
19
|
+
ctx.response.status = 404;
|
|
20
|
+
// TODO: response content according to API spec. Should probably actually be a 404 here.
|
|
21
|
+
ctx.response.body = { statusCode: 404, message: 'Not found' };
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
ctx.state.logger.push({ handler }).log('Found handler');
|
|
25
|
+
await handler(ctx);
|
|
26
|
+
}
|
|
27
|
+
await next();
|
|
28
|
+
};
|
package/lib/validate.js
ADDED
|
@@ -0,0 +1,205 @@
|
|
|
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
|
+
* Matt Kingston - matt.kingston@modusbox.com *
|
|
9
|
+
**************************************************************************/
|
|
10
|
+
|
|
11
|
+
'use strict';
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
// TODO: is it worth bringing in an external lib just for converting params to JSON schema?
|
|
15
|
+
// Consider replacing this.
|
|
16
|
+
const paramsToJsonSchema = require('openapi-jsonschema-parameters').convertParametersToJSONSchema;
|
|
17
|
+
const jsrp = require('json-schema-ref-parser');
|
|
18
|
+
const util = require('util');
|
|
19
|
+
|
|
20
|
+
const { Errors } = require('@mojaloop/sdk-standard-components');
|
|
21
|
+
|
|
22
|
+
// Don't stop at the first error, we'll let the user know what all their errors are. Also, when we
|
|
23
|
+
// validate, coerce types to those we're interested in where possible.
|
|
24
|
+
const Ajv = require('ajv');
|
|
25
|
+
const ajv = new Ajv({ allErrors: true, coerceTypes: true, strict: false });
|
|
26
|
+
|
|
27
|
+
const httpMethods = ['get', 'head', 'post', 'put', 'delete', 'connnect', 'options', 'trace', 'patch'];
|
|
28
|
+
|
|
29
|
+
// Create a json schema in the format we've chosen to use
|
|
30
|
+
const createSchema = (pathValue, methodValue) => {
|
|
31
|
+
let properties = {
|
|
32
|
+
...paramsToJsonSchema([ ...(pathValue.parameters || []), ...(methodValue.parameters || []) ]),
|
|
33
|
+
body: extractBody(methodValue.requestBody) || {}
|
|
34
|
+
};
|
|
35
|
+
// Make all header keys lower-case
|
|
36
|
+
if ('headers' in properties && 'properties' in properties.headers) {
|
|
37
|
+
properties.headers.properties = Object.assign(
|
|
38
|
+
...Object.entries(properties.headers.properties).map(([headerName, value]) => ({ [headerName.toLowerCase()]: value })));
|
|
39
|
+
properties.headers.required = properties.headers.required.map(r => r.toLowerCase());
|
|
40
|
+
}
|
|
41
|
+
const required = Object.entries(properties)
|
|
42
|
+
.filter(([, value]) => value.required && value.required.length > 0)
|
|
43
|
+
.map(([prop,]) => prop);
|
|
44
|
+
return {
|
|
45
|
+
type: 'object',
|
|
46
|
+
properties,
|
|
47
|
+
required
|
|
48
|
+
};
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
// Extract the body schema if it's nested within content.'application/json'
|
|
52
|
+
const extractBody = rqBody => {
|
|
53
|
+
if (rqBody && 'content' in rqBody) {
|
|
54
|
+
if ('application/json' in rqBody.content) {
|
|
55
|
+
return rqBody.content['application/json'].schema;
|
|
56
|
+
}
|
|
57
|
+
// TODO: handle more content types
|
|
58
|
+
throw new Error('Unhandled content type');
|
|
59
|
+
}
|
|
60
|
+
return rqBody;
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
// Here we're transforming the incoming openapi spec to combine path-level parameters and
|
|
64
|
+
// method-level parameters, to get everything in the format we'll validate with.
|
|
65
|
+
//
|
|
66
|
+
// Input:
|
|
67
|
+
// {
|
|
68
|
+
// /path/to/resource: {
|
|
69
|
+
// parameters: { required: true, in: "headers", name: "content-type", type: "integer" },
|
|
70
|
+
// get": {
|
|
71
|
+
// parameters: { required: true, in: "query", name: "length", type: "integer" },
|
|
72
|
+
// requestBody: { "$ref": "#/components/requestBodies/someBodyObj" }
|
|
73
|
+
// }
|
|
74
|
+
// }
|
|
75
|
+
// }
|
|
76
|
+
//
|
|
77
|
+
// Output:
|
|
78
|
+
// {
|
|
79
|
+
// /path/to/resource: {
|
|
80
|
+
// get: {
|
|
81
|
+
// validator: {
|
|
82
|
+
// [ Function validate ]
|
|
83
|
+
// schema: {
|
|
84
|
+
// query: { properties: { length: { type: "string" } }, required: ["length"] },
|
|
85
|
+
// body: { "$ref": "#/components/requestBodies/someBodyObj" },
|
|
86
|
+
// headers: { properties: { "content-type": { type: "integer" } }, required: ["content-type"] }
|
|
87
|
+
// }
|
|
88
|
+
// }
|
|
89
|
+
// }
|
|
90
|
+
// }
|
|
91
|
+
// }
|
|
92
|
+
const transformApiDoc = apiDoc => ({
|
|
93
|
+
...apiDoc,
|
|
94
|
+
// TODO: as we now discard most of the extra information, it probably makes sense to explicitly
|
|
95
|
+
// return the object form we're interested in, rather than do all of this awkward object
|
|
96
|
+
// mapping. I.e.:
|
|
97
|
+
// return { get: { validator: [Function validator] }, put: { validator: [Function validator] } };
|
|
98
|
+
paths: Object.assign(...Object.entries(apiDoc.paths).map(([pathName, pathValue]) => ({
|
|
99
|
+
[pathName]: Object.assign(
|
|
100
|
+
...Object.entries(pathValue)
|
|
101
|
+
.filter(([method,]) => httpMethods.includes(method))
|
|
102
|
+
.map(([method, methodValue]) => {
|
|
103
|
+
const schema = createSchema(pathValue, methodValue);
|
|
104
|
+
const validatorF = ajv.compile(schema);
|
|
105
|
+
return {
|
|
106
|
+
[method]: {
|
|
107
|
+
validator: (ctx, path) => {
|
|
108
|
+
const result = validatorF({
|
|
109
|
+
body: ctx.request.body,
|
|
110
|
+
headers: ctx.request.headers,
|
|
111
|
+
params: ctx.params,
|
|
112
|
+
query: ctx.request.query,
|
|
113
|
+
path
|
|
114
|
+
});
|
|
115
|
+
if (result === true) {
|
|
116
|
+
return undefined;
|
|
117
|
+
}
|
|
118
|
+
return validatorF.errors;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
};
|
|
122
|
+
})
|
|
123
|
+
)
|
|
124
|
+
})))
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
class Validator {
|
|
128
|
+
// apiDoc
|
|
129
|
+
// POJO representing apiDoc API spec. Example:
|
|
130
|
+
// const v = new Validator(require('./apiDoc.json'));
|
|
131
|
+
async initialise(apiDoc) {
|
|
132
|
+
// Dereferencing the api doc makes it much easier to work with. Specifically, it allows us
|
|
133
|
+
// to compile a validator for each path.
|
|
134
|
+
const pojoApiDoc = await jsrp.dereference(apiDoc);
|
|
135
|
+
|
|
136
|
+
this.apiDoc = transformApiDoc(pojoApiDoc);
|
|
137
|
+
const pathParamMatch = /\{[^{}]+\}/g;
|
|
138
|
+
this.paths = Object.entries(this.apiDoc.paths).map(([path, pathSpec]) => ({
|
|
139
|
+
pattern: path,
|
|
140
|
+
matcher: {
|
|
141
|
+
// If we were using node 10, instead of having this awkward params object, we could
|
|
142
|
+
// replace the path parameters with named regex matches corresponding to the path
|
|
143
|
+
// names.
|
|
144
|
+
regex: new RegExp(`^${path.replace(pathParamMatch, '([^{}/]+)')}$`),
|
|
145
|
+
params: (path.match(pathParamMatch) || []).map(s => s.replace(/(^{|}$)/g, ''))
|
|
146
|
+
},
|
|
147
|
+
methods: { ...pathSpec }
|
|
148
|
+
}));
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
// TODO: roll the entire validation functionality into a single function? Or split it out into
|
|
152
|
+
// path, headers, body, query? Or neither? If we validate the body separately, we can avoid
|
|
153
|
+
// parsing the body until (and unless) it comes time for body validation. BUT this means we
|
|
154
|
+
// won't tell the user everything that's wrong with their request in a single response, which
|
|
155
|
+
// is probably more valuable, given the purpose of the simulator. However; having the lib
|
|
156
|
+
// support this option would be good.
|
|
157
|
+
validatePath(path, logger) {
|
|
158
|
+
let result = this.paths.find(p => path.match(p.matcher.regex) !== null);
|
|
159
|
+
|
|
160
|
+
if (result === undefined) {
|
|
161
|
+
throw new Errors.MojaloopFSPIOPError(null, `Couldn't match path ${path}`, null,
|
|
162
|
+
Errors.MojaloopApiErrorCodes.UNKNOWN_URI);
|
|
163
|
+
}
|
|
164
|
+
result.params = Object.assign({}, ...path.match(result.matcher.regex).slice(1).map((m, i) => ({ [result.matcher.params[i]]: m})));
|
|
165
|
+
|
|
166
|
+
logger.push({ path, result }).log('Matched path');
|
|
167
|
+
return result;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
validateRequest(ctx, logger) {
|
|
172
|
+
const path = this.validatePath(ctx.path, logger);
|
|
173
|
+
if (!(ctx.method.toLowerCase() in path.methods)) {
|
|
174
|
+
const err = new Error(`Method ${ctx.method} not supported for path ${ctx.path}`);
|
|
175
|
+
err.httpStatusCode = 405;
|
|
176
|
+
throw err;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
const validationResult = path.methods[ctx.method.toLowerCase()].validator(ctx, path.params);
|
|
180
|
+
|
|
181
|
+
if (validationResult !== undefined && validationResult.length > 0) {
|
|
182
|
+
logger.push({ validationResult }).log('Validation result');
|
|
183
|
+
|
|
184
|
+
let err;
|
|
185
|
+
const firstError = validationResult[0];
|
|
186
|
+
|
|
187
|
+
if(firstError.keyword === 'required') {
|
|
188
|
+
// this is a missing required property; there is a specific mojaloop api spec error code for this
|
|
189
|
+
err = new Errors.MojaloopFSPIOPError(firstError, util.format('Request failed validation',
|
|
190
|
+
validationResult), null, Errors.MojaloopApiErrorCodes.MISSING_ELEMENT);
|
|
191
|
+
|
|
192
|
+
// overwrite the defaul error message with something more useful
|
|
193
|
+
err.apiErrorCode.message = `${firstError.dataPath} ${firstError.message}`;
|
|
194
|
+
throw err;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
err = new Error(util.format('Request failed validation', validationResult));
|
|
198
|
+
Object.assign(err, firstError);
|
|
199
|
+
throw err;
|
|
200
|
+
}
|
|
201
|
+
return path;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
module.exports = Validator;
|
package/package.json
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@mojaloop/sdk-scheme-adapter",
|
|
3
|
+
"version": "11.18.8",
|
|
4
|
+
"description": "An adapter for connecting to Mojaloop API enabled switches.",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"types": "index.d.ts",
|
|
7
|
+
"engines": {
|
|
8
|
+
"node": ">=14.15"
|
|
9
|
+
},
|
|
10
|
+
"scripts": {
|
|
11
|
+
"audit:resolve": "SHELL=sh resolve-audit --production",
|
|
12
|
+
"audit:check": "SHELL=sh check-audit --production",
|
|
13
|
+
"build": "npm run build:openapi; npm run build:dto:outbound",
|
|
14
|
+
"build:openapi": "npm run build:openapi:inbound && npm run build:openapi:outbound",
|
|
15
|
+
"build:openapi:inbound": "openapi bundle --output ./InboundServer/api.yaml --ext yaml ./InboundServer/api_template.yaml",
|
|
16
|
+
"build:openapi:outbound": "openapi bundle --output ./OutboundServer/api.yaml --ext yaml ./OutboundServer/api_template/openapi.yaml",
|
|
17
|
+
"build:dto:outbound": "openapi-typescript ./OutboundServer/api.yaml --output ./OutboundServer/api_interfaces/openapi.d.ts",
|
|
18
|
+
"lint": "eslint .",
|
|
19
|
+
"lint:fix": "eslint . --fix",
|
|
20
|
+
"test": "jest --ci --reporters=default --reporters=jest-junit --env=node test/unit/",
|
|
21
|
+
"test:int": "jest --ci --reporters=default --reporters=jest-junit --env=node test/integration",
|
|
22
|
+
"validate:api": "npm run validate:api:in; npm run validate:api:out",
|
|
23
|
+
"validate:api:in": "swagger-cli validate ./InboundServer/api.yaml",
|
|
24
|
+
"validate:api:out": "swagger-cli validate ./OutboundServer/api.yaml",
|
|
25
|
+
"updates:check": "npm run dep:check",
|
|
26
|
+
"updates:update": "npm run dep:update && npm install",
|
|
27
|
+
"dep:check": "npx ncu -e 2",
|
|
28
|
+
"dep:update": "npx ncu -u",
|
|
29
|
+
"release": "standard-version --releaseCommitMessageFormat 'chore(release): {{currentTag}} [skip ci]'"
|
|
30
|
+
},
|
|
31
|
+
"author": "Matt Kingston, James Bush, ModusBox Inc.",
|
|
32
|
+
"contributors": [
|
|
33
|
+
"Kamuela Franco <kamuela.franco@modusbox.com>",
|
|
34
|
+
"Steven Oderayi <steven.oderayi@modusbox.com>",
|
|
35
|
+
"Valentin Genev <valentin.genev@modusbox.com>",
|
|
36
|
+
"Shashikant Hirugade <shashikant.hirugade@modusbox.com>",
|
|
37
|
+
"Paweł Marzec <pawel.marzec@modusbox.com>",
|
|
38
|
+
"Kevin Leyow <kevin.leyow@modusbox.com",
|
|
39
|
+
"Miguel de Barros <miguel.debarros@modusbox.com>"
|
|
40
|
+
],
|
|
41
|
+
"license": "Apache-2.0",
|
|
42
|
+
"licenses": [
|
|
43
|
+
{
|
|
44
|
+
"type": "Apache-2.0",
|
|
45
|
+
"url": "http://www.apache.org/licenses/LICENSE-2.0"
|
|
46
|
+
}
|
|
47
|
+
],
|
|
48
|
+
"repository": {
|
|
49
|
+
"type": "git",
|
|
50
|
+
"url": "git@github.com:mojaloop/sdk-scheme-adapter.git"
|
|
51
|
+
},
|
|
52
|
+
"dependencies": {
|
|
53
|
+
"@koa/cors": "^3.1.0",
|
|
54
|
+
"@mojaloop/central-services-error-handling": "11.3.0",
|
|
55
|
+
"@mojaloop/central-services-health": "13.0.0",
|
|
56
|
+
"@mojaloop/central-services-logger": "10.6.1",
|
|
57
|
+
"@mojaloop/central-services-metrics": "11.0.0",
|
|
58
|
+
"@mojaloop/central-services-shared": "14.0.0",
|
|
59
|
+
"@mojaloop/event-sdk": "10.7.1",
|
|
60
|
+
"@mojaloop/sdk-standard-components": "15.13.0",
|
|
61
|
+
"ajv": "8.6.3",
|
|
62
|
+
"ajv-keywords": "5.0.0",
|
|
63
|
+
"axios": "^0.21.4",
|
|
64
|
+
"co-body": "^6.1.0",
|
|
65
|
+
"dotenv": "^10.0.0",
|
|
66
|
+
"env-var": "^7.0.1",
|
|
67
|
+
"javascript-state-machine": "^3.1.0",
|
|
68
|
+
"js-yaml": "^4.1.0",
|
|
69
|
+
"json-schema-ref-parser": "^9.0.9",
|
|
70
|
+
"koa": "^2.13.1",
|
|
71
|
+
"koa-body": "^4.2.0",
|
|
72
|
+
"koa2-oauth-server": "^1.0.0",
|
|
73
|
+
"openapi-jsonschema-parameters": "^9.3.0",
|
|
74
|
+
"promise-timeout": "^1.3.0",
|
|
75
|
+
"redis": "^3.1.2",
|
|
76
|
+
"uuidv4": "^6.2.12",
|
|
77
|
+
"ws": "^7.5.5"
|
|
78
|
+
},
|
|
79
|
+
"devDependencies": {
|
|
80
|
+
"@babel/core": "^7.15.5",
|
|
81
|
+
"@babel/preset-env": "^7.15.6",
|
|
82
|
+
"@mojaloop/api-snippets": "^12.6.6",
|
|
83
|
+
"@redocly/openapi-cli": "^1.0.0-beta.59",
|
|
84
|
+
"@types/jest": "^27.0.1",
|
|
85
|
+
"babel-jest": "^27.2.0",
|
|
86
|
+
"eslint": "^7.32.0",
|
|
87
|
+
"eslint-config-airbnb-base": "^14.2.1",
|
|
88
|
+
"eslint-plugin-import": "^2.24.2",
|
|
89
|
+
"eslint-plugin-jest": "^24.4.0",
|
|
90
|
+
"jest": "^27.2.0",
|
|
91
|
+
"jest-junit": "^12.2.0",
|
|
92
|
+
"nock": "^13.1.3",
|
|
93
|
+
"npm-audit-resolver": "^2.3.1",
|
|
94
|
+
"npm-check-updates": "^11.8.5",
|
|
95
|
+
"openapi-response-validator": "^9.3.0",
|
|
96
|
+
"openapi-typescript": "^4.0.2",
|
|
97
|
+
"redis-mock": "^0.56.3",
|
|
98
|
+
"standard-version": "^9.3.1",
|
|
99
|
+
"supertest": "^6.1.6",
|
|
100
|
+
"swagger-cli": "^4.0.4"
|
|
101
|
+
}
|
|
102
|
+
}
|
|
@@ -0,0 +1,152 @@
|
|
|
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 assert = require('assert').strict;
|
|
14
|
+
const util = require('util');
|
|
15
|
+
const { MojaloopRequests, Errors, WSO2Auth, Jws, Logger } = jest.requireActual('@mojaloop/sdk-standard-components');
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class MockMojaloopRequests extends MojaloopRequests {
|
|
19
|
+
constructor(...args) {
|
|
20
|
+
super(...args);
|
|
21
|
+
MockMojaloopRequests.__instance = this;
|
|
22
|
+
this.postParticipants = MockMojaloopRequests.__postParticipants;
|
|
23
|
+
this.getParties = MockMojaloopRequests.__getParties;
|
|
24
|
+
this.postTransactionRequests = MockMojaloopRequests.__postTransactionRequests;
|
|
25
|
+
this.postQuotes = MockMojaloopRequests.__postQuotes;
|
|
26
|
+
this.putQuotes = MockMojaloopRequests.__putQuotes;
|
|
27
|
+
this.putQuotesError = MockMojaloopRequests.__putQuotesError;
|
|
28
|
+
this.getAuthorizations = MockMojaloopRequests.__getAuthorizations;
|
|
29
|
+
this.postAuthorizations = MockMojaloopRequests.__postAuthorizations;
|
|
30
|
+
this.putAuthorizations = MockMojaloopRequests.__putAuthorizations;
|
|
31
|
+
this.getTransfers = MockMojaloopRequests.__getTransfers;
|
|
32
|
+
this.putTransactionRequests = MockMojaloopRequests.__putTransactionRequests;
|
|
33
|
+
this.postTransfers = MockMojaloopRequests.__postTransfers;
|
|
34
|
+
this.putTransfers = MockMojaloopRequests.__putTransfers;
|
|
35
|
+
this.putTransfersError = MockMojaloopRequests.__putTransfersError;
|
|
36
|
+
this.getBulkQuotes = MockMojaloopRequests.__getBulkQuotes;
|
|
37
|
+
this.postBulkQuotes = MockMojaloopRequests.__postBulkQuotes;
|
|
38
|
+
this.putBulkQuotes = MockMojaloopRequests.__putBulkQuotes;
|
|
39
|
+
this.putBulkQuotesError = MockMojaloopRequests.__putBulkQuotesError;
|
|
40
|
+
this.getBulkTransfers = MockMojaloopRequests.__getBulkTransfers;
|
|
41
|
+
this.postBulkTransfers = MockMojaloopRequests.__postBulkTransfers;
|
|
42
|
+
this.putBulkTransfers = MockMojaloopRequests.__putBulkTransfers;
|
|
43
|
+
this.putBulkTransfersError = MockMojaloopRequests.__putBulkTransfersError;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
MockMojaloopRequests.__postParticipants = jest.fn(() => Promise.resolve());
|
|
47
|
+
MockMojaloopRequests.__getParties = jest.fn(() => Promise.resolve());
|
|
48
|
+
MockMojaloopRequests.__postTransactionRequests = jest.fn(() => Promise.resolve());
|
|
49
|
+
MockMojaloopRequests.__postQuotes = jest.fn(() => Promise.resolve());
|
|
50
|
+
MockMojaloopRequests.__putQuotes = jest.fn(() => Promise.resolve());
|
|
51
|
+
MockMojaloopRequests.__putQuotesError = jest.fn(() => Promise.resolve());
|
|
52
|
+
MockMojaloopRequests.__getAuthorizations = jest.fn(() => Promise.resolve());
|
|
53
|
+
MockMojaloopRequests.__postAuthorizations = jest.fn(() => Promise.resolve());
|
|
54
|
+
MockMojaloopRequests.__putAuthorizations = jest.fn(() => Promise.resolve());
|
|
55
|
+
MockMojaloopRequests.__getTransfers = jest.fn(() => Promise.resolve());
|
|
56
|
+
MockMojaloopRequests.__putTransactionRequests = jest.fn(() => Promise.resolve());
|
|
57
|
+
MockMojaloopRequests.__postTransfers = jest.fn(() => Promise.resolve());
|
|
58
|
+
MockMojaloopRequests.__putTransfers = jest.fn(() => Promise.resolve());
|
|
59
|
+
MockMojaloopRequests.__putTransfersError = jest.fn(() => Promise.resolve());
|
|
60
|
+
MockMojaloopRequests.__getBulkQuotes = jest.fn(() => Promise.resolve());
|
|
61
|
+
MockMojaloopRequests.__postBulkQuotes = jest.fn(() => Promise.resolve());
|
|
62
|
+
MockMojaloopRequests.__putBulkQuotes = jest.fn(() => Promise.resolve());
|
|
63
|
+
MockMojaloopRequests.__putBulkQuotesError = jest.fn(() => Promise.resolve());
|
|
64
|
+
MockMojaloopRequests.__getBulkTransfers = jest.fn(() => Promise.resolve());
|
|
65
|
+
MockMojaloopRequests.__postBulkTransfers = jest.fn(() => Promise.resolve());
|
|
66
|
+
MockMojaloopRequests.__putBulkTransfers = jest.fn(() => Promise.resolve());
|
|
67
|
+
MockMojaloopRequests.__putBulkTransfersError = jest.fn(() => Promise.resolve());
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
class MockIlp {
|
|
71
|
+
constructor(config) {
|
|
72
|
+
assert(config.logger, 'Must supply a logger to Ilp constructor');
|
|
73
|
+
this.logger = config.logger;
|
|
74
|
+
this.logger.log('MockIlp constructed');
|
|
75
|
+
this.config = config;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
calculateFulfil(ilpPacket) {
|
|
79
|
+
this.logger.log(`Mock ILP not calculating fulfil from ilp packet ${ilpPacket}`);
|
|
80
|
+
return 'mockGeneratedFulfilment';
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
calculateConditionFromFulfil(fulfil) {
|
|
84
|
+
this.logger.log(`Mock ILP not calculating condition from fulfil ${fulfil}`);
|
|
85
|
+
return 'mockGeneratedCondition';
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
validateFulfil(fulfil, condition) {
|
|
89
|
+
this.logger.log(`Mock ILP not checking fulfil ${fulfil} against condition ${condition}`);
|
|
90
|
+
return true;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
getResponseIlp(...args) {
|
|
94
|
+
this.logger.log(`MockIlp.getResponseIlp called with args: ${util.inspect(args)}`);
|
|
95
|
+
|
|
96
|
+
return MockIlp.__response;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
getQuoteResponseIlp(...args) {
|
|
100
|
+
this.logger.log(`MockIlp.getQuoteResponseIlp called with args: ${util.inspect(args)}`);
|
|
101
|
+
|
|
102
|
+
return this.getResponseIlp(...args);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
getTransactionObject(...args) {
|
|
107
|
+
this.logger.log(`MockIlp.getTrasnactionObject called with args: ${util.inspect(args)}`);
|
|
108
|
+
|
|
109
|
+
return MockIlp.__transactionObject;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
MockIlp.__response = {
|
|
113
|
+
fulfilment: 'mockGeneratedFulfilment',
|
|
114
|
+
ilpPacket: 'mockBase64encodedIlpPacket',
|
|
115
|
+
condition: 'mockGeneratedCondition'
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
MockIlp.__transactionObject = {
|
|
119
|
+
transactionId: 'mockTransactionId'
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
class MockJwsValidator extends Jws.validator {
|
|
124
|
+
constructor(config) {
|
|
125
|
+
super(config);
|
|
126
|
+
MockJwsValidator.__validationKeys = config.validationKeys;
|
|
127
|
+
this.validate = MockJwsValidator.__validate;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
MockJwsValidator.__validate = jest.fn(() => true);
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
class MockJwsSigner {
|
|
134
|
+
constructor(config) {
|
|
135
|
+
assert(config.logger, 'Must supply a logger to JWS signer constructor');
|
|
136
|
+
this.config = config;
|
|
137
|
+
config.logger.log(`MockJwsSigner constructed with config: ${util.inspect(config)}`);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
module.exports = {
|
|
143
|
+
MojaloopRequests: MockMojaloopRequests,
|
|
144
|
+
Ilp: MockIlp,
|
|
145
|
+
Jws: {
|
|
146
|
+
validator: MockJwsValidator,
|
|
147
|
+
signer: MockJwsSigner
|
|
148
|
+
},
|
|
149
|
+
Errors,
|
|
150
|
+
WSO2Auth,
|
|
151
|
+
Logger
|
|
152
|
+
};
|