@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.
Files changed (277) hide show
  1. package/.env.example +140 -0
  2. package/.eslintignore +2 -0
  3. package/.eslintrc.json +30 -0
  4. package/.nvmrc +1 -0
  5. package/.versionrc +15 -0
  6. package/CHANGELOG.md +118 -0
  7. package/InboundServer/api.yaml +3594 -0
  8. package/InboundServer/api_template.yaml +69 -0
  9. package/InboundServer/handlers.js +940 -0
  10. package/InboundServer/index.js +205 -0
  11. package/InboundServer/middlewares.js +426 -0
  12. package/OAuthTestServer/index.js +66 -0
  13. package/OAuthTestServer/model.js +70 -0
  14. package/OutboundServer/api.yaml +2732 -0
  15. package/OutboundServer/api_interfaces/index.d.ts +117 -0
  16. package/OutboundServer/api_interfaces/openapi.d.ts +1475 -0
  17. package/OutboundServer/api_template/components/parameters/bulkQuoteId.yaml +9 -0
  18. package/OutboundServer/api_template/components/parameters/bulkTransferId.yaml +9 -0
  19. package/OutboundServer/api_template/components/parameters/requestToPayTransactionId.yaml +9 -0
  20. package/OutboundServer/api_template/components/parameters/transferId.yaml +9 -0
  21. package/OutboundServer/api_template/components/responses/accountsCreationCompleted.yaml +5 -0
  22. package/OutboundServer/api_template/components/responses/accountsCreationError.yaml +5 -0
  23. package/OutboundServer/api_template/components/responses/accountsCreationTimeout.yaml +5 -0
  24. package/OutboundServer/api_template/components/responses/authorizationPostSuccess.yaml +5 -0
  25. package/OutboundServer/api_template/components/responses/authorizationsServerError.yaml +5 -0
  26. package/OutboundServer/api_template/components/responses/bulkQuoteBadRequest.yaml +5 -0
  27. package/OutboundServer/api_template/components/responses/bulkQuoteServerError.yaml +5 -0
  28. package/OutboundServer/api_template/components/responses/bulkQuoteSuccess.yaml +5 -0
  29. package/OutboundServer/api_template/components/responses/bulkQuoteTimeout.yaml +5 -0
  30. package/OutboundServer/api_template/components/responses/bulkTransferBadRequest.yaml +5 -0
  31. package/OutboundServer/api_template/components/responses/bulkTransferServerError.yaml +5 -0
  32. package/OutboundServer/api_template/components/responses/bulkTransferSuccess.yaml +5 -0
  33. package/OutboundServer/api_template/components/responses/bulkTransferTimeout.yaml +5 -0
  34. package/OutboundServer/api_template/components/responses/partiesByIdError404.yaml +9 -0
  35. package/OutboundServer/api_template/components/responses/partiesByIdSuccess.yaml +5 -0
  36. package/OutboundServer/api_template/components/responses/quotesPostSuccess.yaml +5 -0
  37. package/OutboundServer/api_template/components/responses/quotesServerError.yaml +5 -0
  38. package/OutboundServer/api_template/components/responses/requestToPaySuccess.yaml +5 -0
  39. package/OutboundServer/api_template/components/responses/requestToPayTransferBadRequest.yaml +5 -0
  40. package/OutboundServer/api_template/components/responses/requestToPayTransferSuccess.yaml +5 -0
  41. package/OutboundServer/api_template/components/responses/simpleTransfersPostSuccess.yaml +5 -0
  42. package/OutboundServer/api_template/components/responses/simpleTransfersServerError.yaml +5 -0
  43. package/OutboundServer/api_template/components/responses/transferBadRequest.yaml +5 -0
  44. package/OutboundServer/api_template/components/responses/transferServerError.yaml +5 -0
  45. package/OutboundServer/api_template/components/responses/transferSuccess.yaml +5 -0
  46. package/OutboundServer/api_template/components/responses/transferTimeout.yaml +5 -0
  47. package/OutboundServer/api_template/components/schemas/accountCreationStatus.yaml +18 -0
  48. package/OutboundServer/api_template/components/schemas/accountsCreationState.yaml +4 -0
  49. package/OutboundServer/api_template/components/schemas/accountsRequest.yaml +20 -0
  50. package/OutboundServer/api_template/components/schemas/accountsResponse.yaml +15 -0
  51. package/OutboundServer/api_template/components/schemas/async2SyncCurrentState.yaml +5 -0
  52. package/OutboundServer/api_template/components/schemas/authorizationsPostRequest.yaml +15 -0
  53. package/OutboundServer/api_template/components/schemas/authorizationsPostResponse.yaml +19 -0
  54. package/OutboundServer/api_template/components/schemas/bulkQuoteErrorResponse.yaml +8 -0
  55. package/OutboundServer/api_template/components/schemas/bulkQuoteRequest.yaml +26 -0
  56. package/OutboundServer/api_template/components/schemas/bulkQuoteResponse.yaml +21 -0
  57. package/OutboundServer/api_template/components/schemas/bulkQuoteStatus.yaml +4 -0
  58. package/OutboundServer/api_template/components/schemas/bulkQuoteStatusResponse.yaml +17 -0
  59. package/OutboundServer/api_template/components/schemas/bulkTransferErrorResponse.yaml +8 -0
  60. package/OutboundServer/api_template/components/schemas/bulkTransferRequest.yaml +26 -0
  61. package/OutboundServer/api_template/components/schemas/bulkTransferResponse.yaml +16 -0
  62. package/OutboundServer/api_template/components/schemas/bulkTransferStatus.yaml +4 -0
  63. package/OutboundServer/api_template/components/schemas/bulkTransferStatusResponse.yaml +17 -0
  64. package/OutboundServer/api_template/components/schemas/errorAccountsResponse.yaml +8 -0
  65. package/OutboundServer/api_template/components/schemas/errorAuthorizationsResponse.yaml +3 -0
  66. package/OutboundServer/api_template/components/schemas/errorQuotesResponse.yaml +9 -0
  67. package/OutboundServer/api_template/components/schemas/errorResponse.yaml +8 -0
  68. package/OutboundServer/api_template/components/schemas/errorSimpleTransfersResponse.yaml +3 -0
  69. package/OutboundServer/api_template/components/schemas/errorTransferResponse.yaml +8 -0
  70. package/OutboundServer/api_template/components/schemas/extensionListEmptiable.yaml +6 -0
  71. package/OutboundServer/api_template/components/schemas/individualQuote.yaml +32 -0
  72. package/OutboundServer/api_template/components/schemas/individualQuoteResult.yaml +28 -0
  73. package/OutboundServer/api_template/components/schemas/individualTransfer.yaml +32 -0
  74. package/OutboundServer/api_template/components/schemas/individualTransferFulfilment.yaml +13 -0
  75. package/OutboundServer/api_template/components/schemas/individualTransferResult.yaml +41 -0
  76. package/OutboundServer/api_template/components/schemas/mojaloopError.yaml +5 -0
  77. package/OutboundServer/api_template/components/schemas/mojaloopTransactionRequestState.yaml +2 -0
  78. package/OutboundServer/api_template/components/schemas/partiesByIdResponse.yaml +13 -0
  79. package/OutboundServer/api_template/components/schemas/quote.yaml +3 -0
  80. package/OutboundServer/api_template/components/schemas/quoteError.yaml +16 -0
  81. package/OutboundServer/api_template/components/schemas/quotesPostRequest.yaml +13 -0
  82. package/OutboundServer/api_template/components/schemas/quotesPostResponse.yaml +48 -0
  83. package/OutboundServer/api_template/components/schemas/requestToPayRequest.yaml +39 -0
  84. package/OutboundServer/api_template/components/schemas/requestToPayResponse.yaml +41 -0
  85. package/OutboundServer/api_template/components/schemas/requestToPayTransferRequest.yaml +42 -0
  86. package/OutboundServer/api_template/components/schemas/requestToPayTransferResponse.yaml +58 -0
  87. package/OutboundServer/api_template/components/schemas/simpleTransferServerError.yaml +5 -0
  88. package/OutboundServer/api_template/components/schemas/simpleTransfersPostRequest.yaml +12 -0
  89. package/OutboundServer/api_template/components/schemas/simpleTransfersPostResponse.yaml +11 -0
  90. package/OutboundServer/api_template/components/schemas/transactionType.yaml +4 -0
  91. package/OutboundServer/api_template/components/schemas/transferContinuationAcceptOTP.yaml +9 -0
  92. package/OutboundServer/api_template/components/schemas/transferContinuationAcceptParty.yaml +8 -0
  93. package/OutboundServer/api_template/components/schemas/transferContinuationAcceptQuote.yaml +9 -0
  94. package/OutboundServer/api_template/components/schemas/transferError.yaml +16 -0
  95. package/OutboundServer/api_template/components/schemas/transferFulfilment.yaml +3 -0
  96. package/OutboundServer/api_template/components/schemas/transferParty.yaml +40 -0
  97. package/OutboundServer/api_template/components/schemas/transferRequest.yaml +37 -0
  98. package/OutboundServer/api_template/components/schemas/transferResponse.yaml +58 -0
  99. package/OutboundServer/api_template/components/schemas/transferStatus.yaml +6 -0
  100. package/OutboundServer/api_template/components/schemas/transferStatusResponse.yaml +13 -0
  101. package/OutboundServer/api_template/health.yaml +12 -0
  102. package/OutboundServer/api_template/openapi.yaml +55 -0
  103. package/OutboundServer/api_template/paths/accounts.yaml +26 -0
  104. package/OutboundServer/api_template/paths/authorizations.yaml +19 -0
  105. package/OutboundServer/api_template/paths/bulkQuotes.yaml +23 -0
  106. package/OutboundServer/api_template/paths/bulkQuotes_bulkQuoteId.yaml +24 -0
  107. package/OutboundServer/api_template/paths/bulkTransfers.yaml +23 -0
  108. package/OutboundServer/api_template/paths/bulkTransfers_bulkTransferId.yaml +24 -0
  109. package/OutboundServer/api_template/paths/parties_Type_ID.yaml +20 -0
  110. package/OutboundServer/api_template/paths/parties_Type_ID_SubId.yaml +22 -0
  111. package/OutboundServer/api_template/paths/quotes.yaml +20 -0
  112. package/OutboundServer/api_template/paths/requestToPay.yaml +22 -0
  113. package/OutboundServer/api_template/paths/requestToPayTransfer.yaml +57 -0
  114. package/OutboundServer/api_template/paths/requestToPayTransfer_requestToPayTransactionId.yaml +34 -0
  115. package/OutboundServer/api_template/paths/simpleTransfers.yaml +19 -0
  116. package/OutboundServer/api_template/paths/transfers.yaml +55 -0
  117. package/OutboundServer/api_template/paths/transfers_transferId.yaml +58 -0
  118. package/OutboundServer/handlers.js +622 -0
  119. package/OutboundServer/index.js +137 -0
  120. package/OutboundServer/middlewares.js +67 -0
  121. package/TestServer/api.yaml +62 -0
  122. package/TestServer/handlers.js +63 -0
  123. package/TestServer/index.js +215 -0
  124. package/audit-resolve.json +65 -0
  125. package/babel.config.js +3 -0
  126. package/config.js +158 -0
  127. package/index.d.ts +1 -0
  128. package/index.js +149 -0
  129. package/jest.config.js +15 -0
  130. package/lib/api/index.js +12 -0
  131. package/lib/cache.js +352 -0
  132. package/lib/check.js +25 -0
  133. package/lib/model/AccountsModel.js +396 -0
  134. package/lib/model/Async2SyncModel.js +283 -0
  135. package/lib/model/AuthorizationsModel.js +86 -0
  136. package/lib/model/InboundTransfersModel.js +730 -0
  137. package/lib/model/OutboundBulkQuotesModel.js +485 -0
  138. package/lib/model/OutboundBulkTransfersModel.js +479 -0
  139. package/lib/model/OutboundRequestToPayModel.js +517 -0
  140. package/lib/model/OutboundRequestToPayTransferModel.js +893 -0
  141. package/lib/model/OutboundTransfersModel.js +823 -0
  142. package/lib/model/PartiesModel.js +70 -0
  143. package/lib/model/ProxyModel/MatchRules/Expression.js +48 -0
  144. package/lib/model/ProxyModel/MatchRules/Headers.js +65 -0
  145. package/lib/model/ProxyModel/MatchRules/MatchRule.js +27 -0
  146. package/lib/model/ProxyModel/MatchRules/Path.js +36 -0
  147. package/lib/model/ProxyModel/MatchRules/Query.js +65 -0
  148. package/lib/model/ProxyModel/MatchRules/index.js +19 -0
  149. package/lib/model/ProxyModel/Route.js +82 -0
  150. package/lib/model/ProxyModel/configSchema.json +118 -0
  151. package/lib/model/ProxyModel/index.js +138 -0
  152. package/lib/model/QuotesModel.js +94 -0
  153. package/lib/model/TransfersModel.js +81 -0
  154. package/lib/model/common/BackendError.js +26 -0
  155. package/lib/model/common/PersistentStateMachine.js +93 -0
  156. package/lib/model/common/index.js +18 -0
  157. package/lib/model/index.js +43 -0
  158. package/lib/model/lib/deferredJob.js +113 -0
  159. package/lib/model/lib/index.js +9 -0
  160. package/lib/model/lib/requests/backendRequests.js +227 -0
  161. package/lib/model/lib/requests/common.js +76 -0
  162. package/lib/model/lib/requests/index.js +19 -0
  163. package/lib/model/lib/shared.js +468 -0
  164. package/lib/randomphrase/index.js +21 -0
  165. package/lib/randomphrase/words.json +3397 -0
  166. package/lib/router.js +28 -0
  167. package/lib/validate.js +205 -0
  168. package/package.json +102 -0
  169. package/test/__mocks__/@mojaloop/sdk-standard-components.js +152 -0
  170. package/test/__mocks__/javascript-state-machine.js +21 -0
  171. package/test/__mocks__/redis.js +49 -0
  172. package/test/__mocks__/uuidv4.js +16 -0
  173. package/test/config/integration.env +136 -0
  174. package/test/integration/lib/Outbound/authorizations.test.js +58 -0
  175. package/test/integration/lib/Outbound/data/authorizationsPostRequest.json +43 -0
  176. package/test/integration/lib/Outbound/data/quotesPostRequest.json +52 -0
  177. package/test/integration/lib/Outbound/data/transfersPostRequest.json +24 -0
  178. package/test/integration/lib/Outbound/parties.test.js +28 -0
  179. package/test/integration/lib/Outbound/quotes.test.js +58 -0
  180. package/test/integration/lib/Outbound/simpleTransfers.test.js +67 -0
  181. package/test/integration/lib/cache.test.js +80 -0
  182. package/test/integration/testEnv.js +7 -0
  183. package/test/unit/InboundServer.test.js +443 -0
  184. package/test/unit/TestServer.test.js +394 -0
  185. package/test/unit/api/accounts/accounts.test.js +128 -0
  186. package/test/unit/api/accounts/data/postAccountsBody.json +7 -0
  187. package/test/unit/api/accounts/data/postAccountsErrorMojaloopResponse.json +25 -0
  188. package/test/unit/api/accounts/data/postAccountsErrorTimeoutResponse.json +19 -0
  189. package/test/unit/api/accounts/data/postAccountsSuccessResponse.json +17 -0
  190. package/test/unit/api/accounts/data/postAccountsSuccessResponseWithError1.json +21 -0
  191. package/test/unit/api/accounts/data/postAccountsSuccessResponseWithError2.json +21 -0
  192. package/test/unit/api/accounts/utils.js +65 -0
  193. package/test/unit/api/proxy/data/proxyConfig.yaml +82 -0
  194. package/test/unit/api/proxy/data/requestBody.json +22 -0
  195. package/test/unit/api/proxy/data/requestHeaders.json +5 -0
  196. package/test/unit/api/proxy/data/requestQuery.json +6 -0
  197. package/test/unit/api/proxy/data/responseBody.json +21 -0
  198. package/test/unit/api/proxy/data/responseHeaders.json +5 -0
  199. package/test/unit/api/proxy/proxy.test.js +220 -0
  200. package/test/unit/api/proxy/utils.js +79 -0
  201. package/test/unit/api/transfers/data/getTransfersCommittedResponse.json +21 -0
  202. package/test/unit/api/transfers/data/getTransfersErrorNotFound.json +17 -0
  203. package/test/unit/api/transfers/data/postQuotesBody.json +52 -0
  204. package/test/unit/api/transfers/data/postTransfersBadBody.json +17 -0
  205. package/test/unit/api/transfers/data/postTransfersBody.json +24 -0
  206. package/test/unit/api/transfers/data/postTransfersErrorMojaloopResponse.json +53 -0
  207. package/test/unit/api/transfers/data/postTransfersErrorTimeoutResponse.json +47 -0
  208. package/test/unit/api/transfers/data/postTransfersSimpleBody.json +26 -0
  209. package/test/unit/api/transfers/data/postTransfersSuccessResponse.json +101 -0
  210. package/test/unit/api/transfers/data/putPartiesBody.json +20 -0
  211. package/test/unit/api/transfers/data/putQuotesBody.json +37 -0
  212. package/test/unit/api/transfers/data/putTransfersBody.json +17 -0
  213. package/test/unit/api/transfers/transfers.test.js +191 -0
  214. package/test/unit/api/transfers/utils.js +183 -0
  215. package/test/unit/api/utils.js +75 -0
  216. package/test/unit/config.test.js +119 -0
  217. package/test/unit/data/commonHttpHeaders.json +6 -0
  218. package/test/unit/data/defaultConfig.json +58 -0
  219. package/test/unit/data/postQuotesBody.json +52 -0
  220. package/test/unit/data/putParticipantsBody.json +12 -0
  221. package/test/unit/data/putPartiesBody.json +20 -0
  222. package/test/unit/data/testFile.json +29 -0
  223. package/test/unit/data/testFile.yaml +14 -0
  224. package/test/unit/inboundApi/data/mockArguments.json +117 -0
  225. package/test/unit/inboundApi/data/mockTransactionRequest.json +42 -0
  226. package/test/unit/inboundApi/handlers.test.js +799 -0
  227. package/test/unit/index.test.js +55 -0
  228. package/test/unit/lib/cache.test.js +146 -0
  229. package/test/unit/lib/model/AccountsModel.test.js +121 -0
  230. package/test/unit/lib/model/AuthorizationsModel.test.js +460 -0
  231. package/test/unit/lib/model/InboundTransfersModel.test.js +628 -0
  232. package/test/unit/lib/model/OutboundBulkQuotesModel.test.js +249 -0
  233. package/test/unit/lib/model/OutboundBulkTransfersModel.test.js +244 -0
  234. package/test/unit/lib/model/OutboundRequestToPayModel.test.js +166 -0
  235. package/test/unit/lib/model/OutboundRequestToPayTransferModel.test.js +245 -0
  236. package/test/unit/lib/model/OutboundTransfersModel.test.js +836 -0
  237. package/test/unit/lib/model/PartiesModel.test.js +468 -0
  238. package/test/unit/lib/model/QuotesModel.test.js +470 -0
  239. package/test/unit/lib/model/TransfersModel.test.js +474 -0
  240. package/test/unit/lib/model/common/PersistentStateMachine.test.js +179 -0
  241. package/test/unit/lib/model/data/authorizationsResponse.json +13 -0
  242. package/test/unit/lib/model/data/bulkQuoteRequest.json +27 -0
  243. package/test/unit/lib/model/data/bulkQuoteResponse.json +35 -0
  244. package/test/unit/lib/model/data/bulkTransferFulfil.json +13 -0
  245. package/test/unit/lib/model/data/bulkTransferRequest.json +29 -0
  246. package/test/unit/lib/model/data/defaultConfig.json +47 -0
  247. package/test/unit/lib/model/data/getBulkTransfersBackendResponse.json +42 -0
  248. package/test/unit/lib/model/data/getBulkTransfersMojaloopResponse.json +22 -0
  249. package/test/unit/lib/model/data/getTransfersBackendResponse.json +34 -0
  250. package/test/unit/lib/model/data/getTransfersMojaloopResponse.json +17 -0
  251. package/test/unit/lib/model/data/mockArguments.json +131 -0
  252. package/test/unit/lib/model/data/mockTxnRequestsArguments.json +63 -0
  253. package/test/unit/lib/model/data/notificationToPayee.json +10 -0
  254. package/test/unit/lib/model/data/payeeParty.json +16 -0
  255. package/test/unit/lib/model/data/putAuthorizationsResponse.json +10 -0
  256. package/test/unit/lib/model/data/putQuotesResponse.json +33 -0
  257. package/test/unit/lib/model/data/putTransfersResponse.json +5 -0
  258. package/test/unit/lib/model/data/quoteResponse.json +31 -0
  259. package/test/unit/lib/model/data/requestToPayRequest.json +20 -0
  260. package/test/unit/lib/model/data/requestToPayTransferRequest.json +27 -0
  261. package/test/unit/lib/model/data/transactionRequestResponse.json +18 -0
  262. package/test/unit/lib/model/data/transferFulfil.json +8 -0
  263. package/test/unit/lib/model/data/transferRequest.json +26 -0
  264. package/test/unit/lib/model/mockedLibRequests.js +74 -0
  265. package/test/unit/mockLogger.js +39 -0
  266. package/test/unit/outboundApi/data/bulkQuoteRequest.json +28 -0
  267. package/test/unit/outboundApi/data/bulkTransferRequest.json +28 -0
  268. package/test/unit/outboundApi/data/mockBulkQuoteError.json +45 -0
  269. package/test/unit/outboundApi/data/mockBulkTransferError.json +48 -0
  270. package/test/unit/outboundApi/data/mockError.json +41 -0
  271. package/test/unit/outboundApi/data/mockGetPartiesError.json +4 -0
  272. package/test/unit/outboundApi/data/mockRequestToPayError.json +32 -0
  273. package/test/unit/outboundApi/data/mockRequestToPayTransferError.json +39 -0
  274. package/test/unit/outboundApi/data/requestToPay.json +21 -0
  275. package/test/unit/outboundApi/data/requestToPayTransferRequest.json +20 -0
  276. package/test/unit/outboundApi/data/transferRequest.json +21 -0
  277. package/test/unit/outboundApi/handlers.test.js +986 -0
@@ -0,0 +1,20 @@
1
+ {
2
+ "party": {
3
+ "partyIdInfo": {
4
+ "partyIdType": "PERSONAL_ID",
5
+ "partyIdentifier": "987654321",
6
+ "partySubIdOrType": "PASSPORT",
7
+ "fspId": "sim"
8
+ },
9
+ "personalInfo": {
10
+ "complexName": {
11
+ "firstName": "John",
12
+ "middleName": "Someone",
13
+ "lastName": "Doe"
14
+ },
15
+ "dateOfBirth": "1980-01-01"
16
+ },
17
+ "name": "John Doe",
18
+ "merchantClassificationCode": "1234"
19
+ }
20
+ }
@@ -0,0 +1,37 @@
1
+ {
2
+ "transferAmount": {
3
+ "amount": "500",
4
+ "currency": "USD"
5
+ },
6
+ "payeeReceiveAmount": {
7
+ "amount": "490",
8
+ "currency": "USD"
9
+ },
10
+ "payeeFspFee": {
11
+ "amount": "5",
12
+ "currency": "USD"
13
+ },
14
+ "payeeFspCommission": {
15
+ "amount": "5",
16
+ "currency": "USD"
17
+ },
18
+ "geoCode": {
19
+ "latitude": "53.295971",
20
+ "longitude": "-0.038500"
21
+ },
22
+ "expiration": "2017-11-15T14:17:09.663+01:00",
23
+ "ilpPacket": "AQAAAAAAACasIWcuc2UubW9iaWxlbW9uZXkubXNpc2RuLjEyMzQ1Njc4OYIEIXsNCiAgICAidHJhbnNhY3Rpb25JZCI6ICI4NWZlYWMyZi0zOWIyLTQ5MWItODE3ZS00YTAzMjAzZDRmMTQiLA0KICAgICJxdW90ZUlkIjogIjdjMjNlODBjLWQwNzgtNDA3Ny04MjYzLTJjMDQ3ODc2ZmNmNiIsDQogICAgInBheWVlIjogew0KICAgICAgICAicGFydHlJZEluZm8iOiB7DQogICAgICAgICAgICAicGFydHlJZFR5cGUiOiAiTVNJU0ROIiwNCiAgICAgICAgICAgICJwYXJ0eUlkZW50aWZpZXIiOiAiMTIzNDU2Nzg5IiwNCiAgICAgICAgICAgICJmc3BJZCI6ICJNb2JpbGVNb25leSINCiAgICAgICAgfSwNCiAgICAgICAgInBlcnNvbmFsSW5mbyI6IHsNCiAgICAgICAgICAgICJjb21wbGV4TmFtZSI6IHsNCiAgICAgICAgICAgICAgICAiZmlyc3ROYW1lIjogIkhlbnJpayIsDQogICAgICAgICAgICAgICAgImxhc3ROYW1lIjogIkthcmxzc29uIg0KICAgICAgICAgICAgfQ0KICAgICAgICB9DQogICAgfSwNCiAgICAicGF5ZXIiOiB7DQogICAgICAgICJwZXJzb25hbEluZm8iOiB7DQogICAgICAgICAgICAiY29tcGxleE5hbWUiOiB7DQogICAgICAgICAgICAgICAgImZpcnN0TmFtZSI6ICJNYXRzIiwNCiAgICAgICAgICAgICAgICAibGFzdE5hbWUiOiAiSGFnbWFuIg0KICAgICAgICAgICAgfQ0KICAgICAgICB9LA0KICAgICAgICAicGFydHlJZEluZm8iOiB7DQogICAgICAgICAgICAicGFydHlJZFR5cGUiOiAiSUJBTiIsDQogICAgICAgICAgICAicGFydHlJZGVudGlmaWVyIjogIlNFNDU1MDAwMDAwMDA1ODM5ODI1NzQ2NiIsDQogICAgICAgICAgICAiZnNwSWQiOiAiQmFua05yT25lIg0KICAgICAgICB9DQogICAgfSwNCiAgICAiYW1vdW50Ijogew0KICAgICAgICAiYW1vdW50IjogIjEwMCIsDQogICAgICAgICJjdXJyZW5jeSI6ICJVU0QiDQogICAgfSwNCiAgICAidHJhbnNhY3Rpb25UeXBlIjogew0KICAgICAgICAic2NlbmFyaW8iOiAiVFJBTlNGRVIiLA0KICAgICAgICAiaW5pdGlhdG9yIjogIlBBWUVSIiwNCiAgICAgICAgImluaXRpYXRvclR5cGUiOiAiQ09OU1VNRVIiDQogICAgfSwNCiAgICAibm90ZSI6ICJGcm9tIE1hdHMiDQp9DQo\u003d\u003d",
24
+ "condition": "fH9pAYDQbmoZLPbvv3CSW2RfjU4jvM4ApG_fqGnR7Xs",
25
+ "extensionList": {
26
+ "extension": [
27
+ {
28
+ "key": "qreskey1",
29
+ "value": "qresvalue1"
30
+ },
31
+ {
32
+ "key": "qreskey2",
33
+ "value": "qresvalue2"
34
+ }
35
+ ]
36
+ }
37
+ }
@@ -0,0 +1,17 @@
1
+ {
2
+ "fulfilment": "87mm1reS3SAi8oIWXgBkLmgWc1MkZ_yLbFDX5XAdo5o",
3
+ "completedTimestamp": "2017-11-15T14:16:09.663+01:00",
4
+ "transferState": "COMMITTED",
5
+ "extensionList": {
6
+ "extension": [
7
+ {
8
+ "key": "treskey1",
9
+ "value": "tresvalue1"
10
+ },
11
+ {
12
+ "key": "treskey2",
13
+ "value": "tresvalue2"
14
+ }
15
+ ]
16
+ }
17
+ }
@@ -0,0 +1,191 @@
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
+ jest.unmock('@mojaloop/sdk-standard-components');
14
+ jest.mock('redis');
15
+
16
+ const redis = require('redis');
17
+ const uuidv4 = require('uuidv4');
18
+ const {createValidators, createTestServers, destroyTestServers} = require('../utils');
19
+ const {createPostTransfersTester, createGetTransfersTester} = require('./utils');
20
+
21
+ const defaultConfig = require('../../data/defaultConfig');
22
+
23
+ // Transfers
24
+ const postQuotesBody = require('./data/postQuotesBody');
25
+ const postTransfersBody = require('./data/postTransfersBody');
26
+ const putPartiesBody = require('./data/putPartiesBody');
27
+ const putQuotesBody = require('./data/putQuotesBody');
28
+ const putTransfersBody = require('./data/putTransfersBody');
29
+ const postTransfersBadBody = require('./data/postTransfersBadBody');
30
+ const postTransfersSuccessResponse = require('./data/postTransfersSuccessResponse');
31
+ const postTransfersErrorTimeoutResponse = require('./data/postTransfersErrorTimeoutResponse');
32
+ const postTransfersErrorMojaloopResponse = require('./data/postTransfersErrorMojaloopResponse');
33
+ const getTransfersCommittedResponse = require('./data/getTransfersCommittedResponse');
34
+ const getTransfersErrorNotFound = require('./data/getTransfersErrorNotFound');
35
+
36
+ describe('Outbound Transfers API', () => {
37
+ let testPostTransfers;
38
+ let testGetTransfers;
39
+ let validatorsInfo;
40
+ let serversInfo;
41
+ let redisClient;
42
+
43
+ beforeAll(async () => {
44
+ validatorsInfo = await createValidators();
45
+ redisClient = redis.createClient();
46
+ });
47
+
48
+ beforeEach(async () => {
49
+ serversInfo = await createTestServers({
50
+ ...defaultConfig,
51
+ alsEndpoint: null,
52
+ });
53
+ testPostTransfers = createPostTransfersTester({
54
+ reqInbound: serversInfo.reqInbound,
55
+ reqOutbound: serversInfo.reqOutbound,
56
+ requestValidatorInbound: validatorsInfo.requestValidatorInbound,
57
+ apiSpecsOutbound: validatorsInfo.apiSpecsOutbound,
58
+ });
59
+ testGetTransfers = createGetTransfersTester({
60
+ reqInbound: serversInfo.reqInbound,
61
+ reqOutbound: serversInfo.reqOutbound,
62
+ apiSpecsOutbound: validatorsInfo.apiSpecsOutbound,
63
+ });
64
+ });
65
+
66
+ afterEach(async () => {
67
+ await destroyTestServers(serversInfo);
68
+ });
69
+
70
+ afterAll(async () => {
71
+ redisClient.end();
72
+ });
73
+
74
+ describe('POST /transfers', () => {
75
+ beforeEach(() => {
76
+ uuidv4.__reset();
77
+ redisClient.flushdb();
78
+ });
79
+
80
+ test(
81
+ 'fails validation on invalid request and gives detailed error message indicating source of failure',
82
+ (done) => {
83
+ serversInfo.reqOutbound.post('/transfers').
84
+ send(postTransfersBadBody).
85
+ expect(400, {
86
+ message: 'must be equal to one of the allowed values',
87
+ statusCode: 400,
88
+ }).
89
+ end((err) => {
90
+ if (err) {
91
+ return done(err);
92
+ }
93
+ return done();
94
+ });
95
+ });
96
+
97
+ test('should return success response', () => {
98
+ const bodyFn = {
99
+ parties: {
100
+ put: () => putPartiesBody,
101
+ },
102
+ quotes: {
103
+ post: (body) => ({
104
+ ...postQuotesBody,
105
+ expiration: body.expiration,
106
+ }),
107
+ put: () => putQuotesBody,
108
+ },
109
+ transfers: {
110
+ post: (body) => ({
111
+ ...postTransfersBody,
112
+ expiration: body.expiration,
113
+ }),
114
+ put: () => putTransfersBody,
115
+ },
116
+ };
117
+ return testPostTransfers(bodyFn, 200, postTransfersSuccessResponse);
118
+ });
119
+
120
+ test('should return timeout error response on party resolution', () => {
121
+ const putBodyFn = {
122
+ parties: {
123
+ put: () => new Promise(
124
+ resolve => setTimeout(() => resolve(putPartiesBody),
125
+ 2000)),
126
+ },
127
+ };
128
+ return testPostTransfers(putBodyFn, 504,
129
+ postTransfersErrorTimeoutResponse);
130
+ });
131
+
132
+ test('should return mojaloop error response on party resolution', () => {
133
+ const putBodyFn = {
134
+ parties: {
135
+ put: () => ({
136
+ errorInformation: {
137
+ errorCode: '3204',
138
+ errorDescription: 'Party not found',
139
+ },
140
+ }),
141
+ },
142
+ };
143
+ return testPostTransfers(putBodyFn, 500,
144
+ postTransfersErrorMojaloopResponse);
145
+ });
146
+ });
147
+
148
+
149
+ describe('GET /transfers', () => {
150
+ beforeEach(() => {
151
+ uuidv4.__reset();
152
+ redisClient.flushdb();
153
+ });
154
+
155
+ test('should return COMMITTED transaction state', async () => {
156
+ const bodyFn = {
157
+ parties: {
158
+ put: () => putPartiesBody,
159
+ },
160
+ quotes: {
161
+ post: (body) => ({
162
+ ...postQuotesBody,
163
+ expiration: body.expiration,
164
+ }),
165
+ put: () => putQuotesBody,
166
+ },
167
+ transfers: {
168
+ post: (body) => ({
169
+ ...postTransfersBody,
170
+ expiration: body.expiration,
171
+ }),
172
+ put: () => putTransfersBody,
173
+ },
174
+ };
175
+ await testPostTransfers(bodyFn, 200, postTransfersSuccessResponse);
176
+
177
+ const putBodyFn = () => putTransfersBody;
178
+ return testGetTransfers(putBodyFn, 200, getTransfersCommittedResponse);
179
+ });
180
+
181
+ test('should return transfer not found error', () => {
182
+ const putBodyFn = () => ({
183
+ errorInformation: {
184
+ errorCode: '3208',
185
+ errorDescription: 'Transaction not found',
186
+ },
187
+ });
188
+ return testGetTransfers(putBodyFn, 500, getTransfersErrorNotFound);
189
+ });
190
+ });
191
+ });
@@ -0,0 +1,183 @@
1
+ const nock = require('nock');
2
+ const OpenAPIResponseValidator = require('openapi-response-validator').default;
3
+
4
+ const { Logger } = require('@mojaloop/sdk-standard-components');
5
+ const defaultConfig = require('../../data/defaultConfig');
6
+ const postTransfersSimpleBody = require('./data/postTransfersSimpleBody');
7
+
8
+ /**
9
+ *
10
+ * @param reqInbound
11
+ * @param reqOutbound
12
+ * @param apiSpecsOutbound
13
+ * @returns Function(putBodyFn:function, responseCode:number, responseBody:object) => Promise
14
+ */
15
+ function createGetTransfersTester({ reqInbound, reqOutbound, apiSpecsOutbound }) {
16
+ /**
17
+ *
18
+ * @param putBodyFn {function}
19
+ * @param responseCode {number}
20
+ * @param responseBody {object}
21
+
22
+ * @return {Promise<any>}
23
+ */
24
+ return async (putBodyFn, responseCode, responseBody) => {
25
+ const TRANSFER_ID = '00000000-0000-1000-8000-000000000001';
26
+ const endpoint = new URL(`http://${defaultConfig.peerEndpoint}`).host;
27
+ const switchEndpoint = `http://${endpoint}`;
28
+
29
+ const sendPutTransfers = async () => {
30
+ const putBody = await Promise.resolve(putBodyFn());
31
+ let putUrl = `/transfers/${TRANSFER_ID}`;
32
+ if (putBody.errorInformation) {
33
+ putUrl += '/error';
34
+ }
35
+
36
+ return reqInbound.put(putUrl)
37
+ .send(putBody)
38
+ .set('content-type', 'application/vnd.interoperability.transfers+json;version=1.0')
39
+ .set('Date', new Date().toISOString())
40
+ .set('fspiop-source', 'mojaloop-sdk')
41
+ .expect(200);
42
+ };
43
+
44
+ await nock(switchEndpoint)
45
+ .get(`/transfers/${TRANSFER_ID}`)
46
+ .reply(202, () => {
47
+ sendPutTransfers().then();
48
+ });
49
+
50
+ const res = await reqOutbound.get(`/transfers/${TRANSFER_ID}`);
51
+ const {body} = res;
52
+ expect(res.statusCode).toEqual(responseCode);
53
+ delete body.initiatedTimestamp;
54
+ if (body.transferState) {
55
+ delete body.transferState.initiatedTimestamp;
56
+ }
57
+ expect(body).toEqual(responseBody);
58
+ const responseValidator = new OpenAPIResponseValidator(apiSpecsOutbound.paths['/transfers/{transferId}'].get);
59
+ const err = responseValidator.validateResponse(responseCode, body);
60
+ if (err) {
61
+ throw err;
62
+ }
63
+ };
64
+ }
65
+
66
+ /**
67
+ *
68
+ * @param requestValidatorInbound
69
+ * @param reqInbound
70
+ * @param reqOutbound
71
+ * @param apiSpecsOutbound
72
+ * @returns Function(bodyFn:object, responseCode:number, responseBody:object) => Promise
73
+ */
74
+ function createPostTransfersTester(
75
+ { requestValidatorInbound, reqInbound, reqOutbound, apiSpecsOutbound }) {
76
+
77
+ const logger = new Logger.Logger({ context: { app: 'outbound-model-unit-tests' }, stringify: () => '' });
78
+
79
+ /**
80
+ *
81
+ * @param bodyFn {Object}
82
+ * @param responseCode {number}
83
+ * @param bodyFn.parties {object}
84
+ * @param bodyFn.parties.put {function}
85
+ * @param bodyFn.quotes {object}
86
+ * @param bodyFn.quotes.put {function}
87
+ * @param bodyFn.quotes.post {function}
88
+ * @param bodyFn.transfers {object}
89
+ * @param bodyFn.transfers.put {function}
90
+ * @param bodyFn.transfers.post {function}
91
+ * @param responseBody {object}
92
+
93
+ * @return {Promise<any>}
94
+ */
95
+ return async (bodyFn, responseCode, responseBody) => {
96
+ let pendingRequest = Promise.resolve();
97
+ let currentRequest = Promise.resolve();
98
+ const handleRequest = async (req) => {
99
+ const urlPath = req.path;
100
+ const body = req.body && JSON.parse(req.body);
101
+ const headers = req.headers;
102
+ const method = req.method;
103
+ let putBody;
104
+ let putUrl;
105
+ let contentType;
106
+ requestValidatorInbound.validateRequest(
107
+ {method, path: urlPath, request: {headers, body}}, logger);
108
+ if (urlPath.startsWith('/parties/')) {
109
+ putBody = await Promise.resolve(bodyFn.parties.put());
110
+ putUrl = urlPath;
111
+ contentType = 'application/vnd.interoperability.parties+json;version=1.0';
112
+ } else if (urlPath === '/quotes') {
113
+ expect(body).toEqual(bodyFn.quotes.post(body));
114
+ putBody = await Promise.resolve(bodyFn.quotes.put(body));
115
+ putUrl = `/quotes/${body.quoteId}`;
116
+ contentType = 'application/vnd.interoperability.quotes+json;version=1.0';
117
+ } else if (urlPath === '/transfers') {
118
+ expect(body).toEqual(bodyFn.transfers.post(body));
119
+ putBody = await Promise.resolve(bodyFn.transfers.put(body));
120
+ putUrl = `/transfers/${body.transferId}`;
121
+ contentType = 'application/vnd.interoperability.transfers+json;version=1.0';
122
+ } else {
123
+ throw new Error(`Unexpected url ${urlPath}`);
124
+ }
125
+ if (putBody.errorInformation) {
126
+ putUrl += '/error';
127
+ }
128
+ // supertest experiencing issues handling simultaneous requests,
129
+ // so just wait for the previous request to finish
130
+ await currentRequest;
131
+ currentRequest = reqInbound.put(putUrl)
132
+ .send(putBody)
133
+ .set('Date', new Date().toISOString())
134
+ .set('content-type', contentType)
135
+ .set('fspiop-source', 'mojaloop-sdk')
136
+ .expect(200);
137
+ return currentRequest;
138
+ };
139
+
140
+ function handleNockRequest(uri, body) {
141
+ pendingRequest = handleRequest({
142
+ method: this.method.toLowerCase(),
143
+ path: uri,
144
+ body,
145
+ headers: this.req.headers,
146
+ }).then();
147
+ }
148
+
149
+ const endpoint = new URL(`http://${defaultConfig.peerEndpoint}`).host;
150
+ const switchEndpoint = `http://${endpoint}`;
151
+
152
+ const nockMock = nock(switchEndpoint);
153
+ if (bodyFn.parties) {
154
+ nockMock.get(/^\/parties\//).reply(202, handleNockRequest);
155
+ }
156
+ if (bodyFn.quotes) {
157
+ nockMock.post('/quotes').reply(202, handleNockRequest);
158
+ }
159
+ if (bodyFn.transfers) {
160
+ nockMock.post('/transfers').reply(202, handleNockRequest);
161
+ }
162
+
163
+ const res = await reqOutbound.post('/transfers').send(postTransfersSimpleBody);
164
+ const {body} = res;
165
+ expect(res.statusCode).toEqual(responseCode);
166
+ delete body.initiatedTimestamp;
167
+ if (body.transferState) {
168
+ delete body.transferState.initiatedTimestamp;
169
+ }
170
+ expect(body).toEqual(responseBody);
171
+ const responseValidator = new OpenAPIResponseValidator(apiSpecsOutbound.paths['/transfers'].post);
172
+ const err = responseValidator.validateResponse(responseCode, body);
173
+ if (err) {
174
+ throw err;
175
+ }
176
+ await pendingRequest;
177
+ };
178
+ }
179
+
180
+ module.exports = {
181
+ createGetTransfersTester,
182
+ createPostTransfersTester,
183
+ };