@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,69 @@
1
+ openapi: 3.0.0
2
+ info:
3
+ version: '1.1'
4
+ title: Open API for FSP Interoperability (FSPIOP)
5
+ description: >-
6
+ Based on API Definition.docx updated on 2020-05-19 Version 1.1.
7
+ API supports a maximum size of 65536 bytes (64 Kilobytes) in the HTTP
8
+ header.
9
+ license:
10
+ name: Open API for FSP Interoperability (FSPIOP)
11
+ paths:
12
+ '/participants/{ID}/error':
13
+ $ref: '../node_modules/@mojaloop/api-snippets/fspiop/v1_1/openapi3/paths/participants_ID_error.yaml'
14
+ '/participants/{ID}':
15
+ $ref: '../node_modules/@mojaloop/api-snippets/fspiop/v1_1/openapi3/paths/participants_ID.yaml'
16
+ '/participants/{Type}/{ID}/error':
17
+ $ref: '../node_modules/@mojaloop/api-snippets/fspiop/v1_1/openapi3/paths/participants_Type_ID_error.yaml'
18
+ '/participants/{Type}/{ID}/{SubId}/error':
19
+ $ref: '../node_modules/@mojaloop/api-snippets/fspiop/v1_1/openapi3/paths/participants_Type_ID_SubId_error.yaml'
20
+ '/participants/{Type}/{ID}/{SubId}':
21
+ $ref: '../node_modules/@mojaloop/api-snippets/fspiop/v1_1/openapi3/paths/participants_Type_ID_SubId.yaml'
22
+ '/participants/{Type}/{ID}':
23
+ $ref: '../node_modules/@mojaloop/api-snippets/fspiop/v1_1/openapi3/paths/participants_Type_ID.yaml'
24
+ '/participants':
25
+ $ref: '../node_modules/@mojaloop/api-snippets/fspiop/v1_1/openapi3/paths/participants.yaml'
26
+ '/parties/{Type}/{ID}':
27
+ $ref: '../node_modules/@mojaloop/api-snippets/fspiop/v1_1/openapi3/paths/parties_Type_ID.yaml'
28
+ '/parties/{Type}/{ID}/error':
29
+ $ref: '../node_modules/@mojaloop/api-snippets/fspiop/v1_1/openapi3/paths/parties_Type_ID_error.yaml'
30
+ '/parties/{Type}/{ID}/{SubId}':
31
+ $ref: '../node_modules/@mojaloop/api-snippets/fspiop/v1_1/openapi3/paths/parties_Type_ID_SubId.yaml'
32
+ '/parties/{Type}/{ID}/{SubId}/error':
33
+ $ref: '../node_modules/@mojaloop/api-snippets/fspiop/v1_1/openapi3/paths/parties_Type_ID_SubId_error.yaml'
34
+ '/transactionRequests/{ID}/error':
35
+ $ref: '../node_modules/@mojaloop/api-snippets/fspiop/v1_1/openapi3/paths/transactionRequests_ID_error.yaml'
36
+ '/transactionRequests/{ID}':
37
+ $ref: '../node_modules/@mojaloop/api-snippets/fspiop/v1_1/openapi3/paths/transactionRequests_ID.yaml'
38
+ '/transactionRequests':
39
+ $ref: '../node_modules/@mojaloop/api-snippets/fspiop/v1_1/openapi3/paths/transactionRequests.yaml'
40
+ '/quotes/{ID}/error':
41
+ $ref: '../node_modules/@mojaloop/api-snippets/fspiop/v1_1/openapi3/paths/quotes_ID_error.yaml'
42
+ '/quotes/{ID}':
43
+ $ref: '../node_modules/@mojaloop/api-snippets/fspiop/v1_1/openapi3/paths/quotes_ID.yaml'
44
+ '/quotes':
45
+ $ref: '../node_modules/@mojaloop/api-snippets/fspiop/v1_1/openapi3/paths/quotes.yaml'
46
+ '/authorizations/{ID}':
47
+ $ref: '../node_modules/@mojaloop/api-snippets/fspiop/v1_1/openapi3/paths/authorizations_ID.yaml'
48
+ '/authorizations/{ID}/error':
49
+ $ref: '../node_modules/@mojaloop/api-snippets/fspiop/v1_1/openapi3/paths/authorizations_ID_error.yaml'
50
+ '/transfers/{ID}/error':
51
+ $ref: '../node_modules/@mojaloop/api-snippets/fspiop/v1_1/openapi3/paths/transfers_ID_error.yaml'
52
+ '/transfers/{ID}':
53
+ $ref: '../node_modules/@mojaloop/api-snippets/fspiop/v1_1/openapi3/paths/transfers_ID.yaml'
54
+ '/transfers':
55
+ $ref: '../node_modules/@mojaloop/api-snippets/fspiop/v1_1/openapi3/paths/transfers.yaml'
56
+ '/transactions/{ID}':
57
+ $ref: '../node_modules/@mojaloop/api-snippets/fspiop/v1_1/openapi3/paths/transactions_ID.yaml'
58
+ '/transactions/{ID}/error':
59
+ $ref: '../node_modules/@mojaloop/api-snippets/fspiop/v1_1/openapi3/paths/transactions_ID_error.yaml'
60
+ '/bulkQuotes/{ID}/error':
61
+ $ref: '../node_modules/@mojaloop/api-snippets/fspiop/v1_1/openapi3/paths/bulkQuotes_ID_error.yaml'
62
+ '/bulkQuotes/{ID}':
63
+ $ref: '../node_modules/@mojaloop/api-snippets/fspiop/v1_1/openapi3/paths/bulkQuotes_ID.yaml'
64
+ '/bulkTransfers/{ID}':
65
+ $ref: '../node_modules/@mojaloop/api-snippets/fspiop/v1_1/openapi3/paths/bulkTransfers_ID.yaml'
66
+ '/bulkTransfers':
67
+ $ref: '../node_modules/@mojaloop/api-snippets/fspiop/v1_1/openapi3/paths/bulkTransfers.yaml'
68
+ '/bulkTransfers/{ID}/error':
69
+ $ref: '../node_modules/@mojaloop/api-snippets/fspiop/v1_1/openapi3/paths/bulkTransfers_ID_error.yaml'
@@ -0,0 +1,940 @@
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
+ * CONTRIBUTORS: *
10
+ * Steven Oderayi - steven.oderayi@modusbox.com *
11
+ * Paweł Marzec - pawel.marzec@modusbox.com *
12
+ **************************************************************************/
13
+
14
+ 'use strict';
15
+
16
+ const Model = require('../lib/model').InboundTransfersModel;
17
+ const PartiesModel = require('../lib/model').PartiesModel;
18
+ const QuotesModel = require('../lib/model').QuotesModel;
19
+ const TransfersModel = require('../lib/model').TransfersModel;
20
+ const AuthorizationsModel = require('../lib/model').AuthorizationsModel;
21
+
22
+ /**
23
+ * Handles a GET /authorizations/{id} request
24
+ */
25
+ const getAuthorizationsById = async (ctx) => {
26
+ // kick off an asyncronous operation to handle the request
27
+ (async () => {
28
+ try {
29
+ // use the transfers model to execute asynchronous stages with the switch
30
+ const model = new Model({
31
+ ...ctx.state.conf,
32
+ cache: ctx.state.cache,
33
+ logger: ctx.state.logger,
34
+ wso2: ctx.state.wso2,
35
+ resourceVersions: ctx.resourceVersions,
36
+ });
37
+
38
+ const sourceFspId = ctx.request.headers['fspiop-source'];
39
+
40
+ // use the model to handle the request
41
+ const response = await model.getAuthorizations(ctx.state.path.params.ID, sourceFspId);
42
+
43
+ // log the result
44
+ ctx.state.logger.push({ response }).log('Inbound transfers model handled GET /parties/{idType}/{idValue} request');
45
+ }
46
+ catch(err) {
47
+ // nothing we can do if an error gets thrown back to us here apart from log it and continue
48
+ ctx.state.logger.push({ err }).log('Error handling GET /parties/{idType}/{idValue}');
49
+ }
50
+ })();
51
+
52
+ // Note that we will have passed request validation, JWS etc... by this point
53
+ // so it is safe to return 202
54
+ ctx.response.status = 202;
55
+ ctx.response.body = '';
56
+ };
57
+
58
+ /**
59
+ * Handles a GET /participants/{idType}/{idValue} request
60
+ */
61
+ const getParticipantsByTypeAndId = async (ctx) => {
62
+ // kick off an asynchronous operation to handle the request
63
+ (async () => {
64
+ try {
65
+ // use the transfers model to execute asynchronous stages with the switch
66
+ const model = new Model({
67
+ ...ctx.state.conf,
68
+ cache: ctx.state.cache,
69
+ logger: ctx.state.logger,
70
+ wso2: ctx.state.wso2,
71
+ resourceVersions: ctx.resourceVersions,
72
+ });
73
+
74
+ const sourceFspId = ctx.request.headers['fspiop-source'];
75
+
76
+ // use the model to handle the request
77
+ const response = await model.getParticipants(ctx.state.path.params.Type,
78
+ ctx.state.path.params.ID, ctx.state.path.params.SubId, sourceFspId);
79
+
80
+ // log the result
81
+ ctx.state.logger.push({ response }).log('Inbound transfers model handled GET /participants/{idType}/{idValue}');
82
+ }
83
+ catch(err) {
84
+ // nothing we can do if an error gets thrown back to us here apart from log it and continue
85
+ ctx.state.logger.push({ err }).log('Error handling GET /participants/{idType}/{idValue}');
86
+ }
87
+ })();
88
+
89
+ // Note that we will have passed request validation, JWS etc... by this point
90
+ // so it is safe to return 202
91
+ ctx.response.status = 202;
92
+ ctx.response.body = '';
93
+ };
94
+
95
+
96
+ /**
97
+ * Handles a GET /parties/{idType}/{idValue} request
98
+ */
99
+ const getPartiesByTypeAndId = async (ctx) => {
100
+ // kick off an asyncronous operation to handle the request
101
+ (async () => {
102
+ try {
103
+ // use the transfers model to execute asynchronous stages with the switch
104
+ const model = new Model({
105
+ ...ctx.state.conf,
106
+ cache: ctx.state.cache,
107
+ logger: ctx.state.logger,
108
+ wso2: ctx.state.wso2,
109
+ resourceVersions: ctx.resourceVersions,
110
+ });
111
+
112
+ const sourceFspId = ctx.request.headers['fspiop-source'];
113
+
114
+ // use the model to handle the request
115
+ const response = await model.getParties(ctx.state.path.params.Type, ctx.state.path.params.ID,
116
+ ctx.state.path.params.SubId, sourceFspId);
117
+
118
+ // log the result
119
+ ctx.state.logger.push({ response }).log('Inbound transfers model handled GET /parties/{idType}/{idValue} request');
120
+ }
121
+ catch(err) {
122
+ // nothing we can do if an error gets thrown back to us here apart from log it and continue
123
+ ctx.state.logger.push({ err }).log('Error handling GET /parties/{idType}/{idValue}');
124
+ }
125
+ })();
126
+
127
+ // Note that we will have passed request validation, JWS etc... by this point
128
+ // so it is safe to return 202
129
+ ctx.response.status = 202;
130
+ ctx.response.body = '';
131
+ };
132
+
133
+
134
+ /**
135
+ * Handles a POST /parties/{idType}/{idValue} request
136
+ */
137
+ const postPartiesByTypeAndId = (ctx) => {
138
+ // creation of parties not supported by SDK
139
+ ctx.response.status = 501;
140
+ ctx.response.body = '';
141
+ };
142
+
143
+
144
+ /**
145
+ * Handles a POST /quotes request
146
+ */
147
+ const postQuotes = async (ctx) => {
148
+ // kick off an asyncronous operation to handle the request
149
+ (async () => {
150
+ try {
151
+ // use the transfers model to execute asynchronous stages with the switch
152
+ const model = new Model({
153
+ ...ctx.state.conf,
154
+ cache: ctx.state.cache,
155
+ logger: ctx.state.logger,
156
+ wso2: ctx.state.wso2,
157
+ resourceVersions: ctx.resourceVersions,
158
+ });
159
+
160
+ const sourceFspId = ctx.request.headers['fspiop-source'];
161
+
162
+ // use the model to handle the request
163
+ const response = await model.quoteRequest(ctx.request.body, sourceFspId);
164
+
165
+ // log the result
166
+ ctx.state.logger.push({ response }).log('Inbound transfers model handled POST /quotes request');
167
+ }
168
+ catch(err) {
169
+ // nothing we can do if an error gets thrown back to us here apart from log it and continue
170
+ ctx.state.logger.push({ err }).log('Error handling POST /quotes');
171
+ }
172
+ })();
173
+
174
+ // Note that we will have passed request validation, JWS etc... by this point
175
+ // so it is safe to return 202
176
+ ctx.response.status = 202;
177
+ ctx.response.body = '';
178
+ };
179
+
180
+
181
+ /**
182
+ * Handles a POST /transfers request
183
+ */
184
+ const postTransfers = async (ctx) => {
185
+ // kick off an asyncronous operation to handle the request
186
+ (async () => {
187
+ try {
188
+ // use the transfers model to execute asynchronous stages with the switch
189
+ const model = new Model({
190
+ ...ctx.state.conf,
191
+ cache: ctx.state.cache,
192
+ logger: ctx.state.logger,
193
+ wso2: ctx.state.wso2,
194
+ resourceVersions: ctx.resourceVersions,
195
+ });
196
+
197
+ const sourceFspId = ctx.request.headers['fspiop-source'];
198
+
199
+ // use the model to handle the request
200
+ const response = await model.prepareTransfer(ctx.request.body, sourceFspId);
201
+
202
+ // log the result
203
+ ctx.state.logger.push({ response }).log('Inbound transfers model handled POST /transfers request');
204
+ }
205
+ catch(err) {
206
+ // nothing we can do if an error gets thrown back to us here apart from log it and continue
207
+ ctx.state.logger.push({ err }).log('Error handling POST /transfers');
208
+ }
209
+ })();
210
+
211
+ // Note that we will have passed request validation, JWS etc... by this point
212
+ // so it is safe to return 202
213
+ ctx.response.status = 202;
214
+ ctx.response.body = '';
215
+ };
216
+
217
+ /**
218
+ * Handles a GET /transfers/{ID} request
219
+ */
220
+ const getTransfersById = async (ctx) => {
221
+ // kick off an asyncronous operation to handle the request
222
+ (async () => {
223
+ try {
224
+ // use the transfers model to execute asynchronous stages with the switch
225
+ const model = new Model({
226
+ ...ctx.state.conf,
227
+ cache: ctx.state.cache,
228
+ logger: ctx.state.logger,
229
+ wso2: ctx.state.wso2,
230
+ resourceVersions: ctx.resourceVersions,
231
+ });
232
+
233
+ const sourceFspId = ctx.request.headers['fspiop-source'];
234
+
235
+ // use the model to handle the request
236
+ const response = await model.getTransfer(ctx.state.path.params.ID,
237
+ sourceFspId);
238
+
239
+ // log the result
240
+ ctx.state.logger.push({response}).
241
+ log('Inbound transfers model handled GET /transfers/{ID} request');
242
+ }
243
+ catch(err) {
244
+ // nothing we can do if an error gets thrown back to us here apart from log it and continue
245
+ ctx.state.logger.push({ err }).log('Error handling GET /transfers/{ID}');
246
+ }
247
+ })();
248
+
249
+ // Note that we will have passed request validation, JWS etc... by this point
250
+ // so it is safe to return 202
251
+ ctx.response.status = 202;
252
+ ctx.response.body = '';
253
+ };
254
+
255
+ /**
256
+ * Handles a POST /transactionRequests request
257
+ */
258
+ const postTransactionRequests = async (ctx) => {
259
+ // kick off an asyncronous operation to handle the request
260
+ (async () => {
261
+ try {
262
+ // use the transfers model to execute asynchronous stages with the switch
263
+ const model = new Model({
264
+ ...ctx.state.conf,
265
+ cache: ctx.state.cache,
266
+ logger: ctx.state.logger,
267
+ wso2: ctx.state.wso2,
268
+ resourceVersions: ctx.resourceVersions,
269
+ });
270
+
271
+ const sourceFspId = ctx.request.headers['fspiop-source'];
272
+
273
+ // use the model to handle the request
274
+ const response = await model.transactionRequest(ctx.request.body, sourceFspId);
275
+
276
+ // log the result
277
+ ctx.state.logger.push({ response }).log('Inbound transfers model handled POST /transactionRequests request');
278
+ }
279
+ catch(err) {
280
+ // nothing we can do if an error gets thrown back to us here apart from log it and continue
281
+ ctx.state.logger.push({ err }).log('Error handling POST /transactionRequests');
282
+ }
283
+ })();
284
+
285
+ // Note that we will have passed request validation, JWS etc... by this point
286
+ // so it is safe to return 202
287
+ ctx.response.status = 202;
288
+ ctx.response.body = '';
289
+ };
290
+
291
+ /**
292
+ * Handles a PUT /authorizations/{id}. This is a response to a GET /authorizations/{ID}
293
+ * request.
294
+ */
295
+ const putAuthorizationsById = async (ctx) => {
296
+ const idValue = ctx.state.path.params.ID;
297
+
298
+ // publish an event onto the cache for subscribers to action
299
+ const cacheId = `otp_${idValue}`;
300
+ // publish an event onto the cache for subscribers to action
301
+ await ctx.state.cache.publish(cacheId, {
302
+ type: 'authorizationsResponse',
303
+ data: ctx.request.body,
304
+ headers: ctx.request.headers
305
+ });
306
+
307
+ // duplicate publication until legacy code refactored
308
+ await AuthorizationsModel.triggerDeferredJob({
309
+ cache: ctx.state.cache,
310
+ message: ctx.request.body,
311
+ args: {
312
+ transactionRequestId: ctx.state.path.params.ID
313
+ }
314
+ });
315
+
316
+ ctx.response.status = 200;
317
+ };
318
+
319
+ /**
320
+ * Handles a PUT /authorizations/{ID}/error request.
321
+ * This is an error response to a POST /authorizations request
322
+ */
323
+ const putAuthorizationsByIdError = async (ctx) => {
324
+
325
+ // publish an event onto the cache for subscribers to action
326
+ await ctx.state.cache.publish(`otp_${ctx.state.path.params.ID}`, {
327
+ type: 'authorizationResponseError',
328
+ data: ctx.request.body,
329
+ });
330
+
331
+ // duplicate publication until legacy code refactored
332
+ await AuthorizationsModel.triggerDeferredJob({
333
+ cache: ctx.state.cache,
334
+ message: ctx.request.body,
335
+ args: {
336
+ transactionRequestId: ctx.state.path.params.ID
337
+ }
338
+ });
339
+
340
+ ctx.response.status = 200;
341
+ ctx.response.body = '';
342
+ };
343
+
344
+ /**
345
+ * Handles a PUT /participants/{ID}. This is a response to a POST /participants request
346
+ */
347
+ const putParticipantsById = async (ctx) => {
348
+ // publish an event onto the cache for subscribers to action
349
+ await ctx.state.cache.publish(`ac_${ctx.state.path.params.ID}`, {
350
+ type: 'accountsCreationSuccessfulResponse',
351
+ data: ctx.request.body
352
+ });
353
+
354
+ ctx.response.status = 200;
355
+ };
356
+
357
+
358
+ /**
359
+ * Handles a PUT /participants/{ID}/error. This is an error response to a POST /participants request
360
+ */
361
+ const putParticipantsByIdError = async (ctx) => {
362
+ // publish an event onto the cache for subscribers to action
363
+ await ctx.state.cache.publish(`ac_${ctx.state.path.params.ID}`, {
364
+ type: 'accountsCreationErrorResponse',
365
+ data: ctx.request.body
366
+ });
367
+
368
+ ctx.response.status = 200;
369
+ ctx.response.body = '';
370
+ };
371
+
372
+
373
+ /**
374
+ * Handles a PUT /participants/{idType}/{idValue} request
375
+ */
376
+ const putParticipantsByTypeAndId = async (ctx) => {
377
+ // Allow putParticipants only for testing purpose when `AUTO_ACCEPT_PARTICIPANTS_PUT` env variable is set to true.
378
+ if(ctx.state.conf.autoAcceptParticipantsPut){
379
+ const idType = ctx.state.path.params.Type;
380
+ const idValue = ctx.state.path.params.ID;
381
+ const idSubValue = ctx.state.path.params.SubId;
382
+
383
+ // publish an event onto the cache for subscribers to action
384
+ const cacheId = `${idType}_${idValue}` + (idSubValue ? `_${idSubValue}` : '');
385
+ await ctx.state.cache.publish(cacheId, ctx.request.body);
386
+ ctx.response.status = 200;
387
+ } else {
388
+ // SDK does not make participants requests so we should not expect any calls to this method
389
+ ctx.response.status = 501;
390
+ ctx.response.body = '';
391
+ }
392
+ };
393
+
394
+
395
+ /**
396
+ * Handles a PUT /participants/{Type}/{ID}/{SubId}/error request. This is an error response to a GET /participants/{Type}/{ID}/{SubId} request
397
+ */
398
+ const putParticipantsByTypeAndIdError = async(ctx) => {
399
+ const idType = ctx.state.path.params.Type;
400
+ const idValue = ctx.state.path.params.ID;
401
+ const idSubValue = ctx.state.path.params.SubId;
402
+
403
+ // publish an event onto the cache for subscribers to action
404
+ // note that we publish the event the same way we publish a success PUT
405
+ // the subscriber will notice the body contains an errorInformation property
406
+ // and recognise it as an error response
407
+ const cacheId = `${idType}_${idValue}` + (idSubValue ? `_${idSubValue}` : '');
408
+ await ctx.state.cache.publish(cacheId, ctx.request.body);
409
+
410
+ ctx.response.status = 200;
411
+ ctx.response.body = '';
412
+ };
413
+
414
+
415
+ /**
416
+ * Handles a PUT /parties/{idType}/{IdValue}. This is a response to a GET /parties
417
+ * request.
418
+ */
419
+ const putPartiesByTypeAndId = async (ctx) => {
420
+ const idType = ctx.state.path.params.Type;
421
+ const idValue = ctx.state.path.params.ID;
422
+ const idSubValue = ctx.state.path.params.SubId;
423
+
424
+ // publish an event onto the cache for subscribers to finish the action
425
+ await PartiesModel.triggerDeferredJob({
426
+ cache: ctx.state.cache,
427
+ message: ctx.request.body,
428
+ args: {
429
+ type: idType,
430
+ id: idValue,
431
+ subId: idSubValue
432
+ }
433
+ });
434
+
435
+ ctx.response.status = 200;
436
+ };
437
+
438
+ /**
439
+ * Handles a PUT /parties/{Type}/{ID}/error request. This is an error response to a GET /parties/{Type}/{ID} request
440
+ */
441
+ const putPartiesByTypeAndIdError = async(ctx) => {
442
+ const idType = ctx.state.path.params.Type;
443
+ const idValue = ctx.state.path.params.ID;
444
+ const idSubValue = ctx.state.path.params.SubId;
445
+
446
+ // publish an event onto the cache for subscribers to action
447
+ // note that we publish the event the same way we publish a success PUT
448
+ // the subscriber will notice the body contains an errorInformation property
449
+ // and recognizes it as an error response
450
+ await PartiesModel.triggerDeferredJob({
451
+ cache: ctx.state.cache,
452
+ message: ctx.request.body,
453
+ args: {
454
+ type: idType,
455
+ id: idValue,
456
+ subId: idSubValue
457
+ }
458
+ });
459
+
460
+ ctx.response.status = 200;
461
+ ctx.response.body = '';
462
+ };
463
+
464
+
465
+ /**
466
+ * Handles a PUT /quotes/{ID}. This is a response to a POST /quotes request
467
+ */
468
+ const putQuoteById = async (ctx) => {
469
+ // TODO: refactor legacy models to use QuotesModel
470
+ // - OutboundRequestToPayTransferModel
471
+ // - OutboundTransfersModel
472
+ // publish an event onto the cache for subscribers to action
473
+ await ctx.state.cache.publish(`qt_${ctx.state.path.params.ID}`, {
474
+ type: 'quoteResponse',
475
+ data: ctx.request.body,
476
+ headers: ctx.request.headers
477
+ });
478
+
479
+ // duplicate publication until legacy code refactored
480
+ await QuotesModel.triggerDeferredJob({
481
+ cache: ctx.state.cache,
482
+ message: ctx.request.body,
483
+ args: {
484
+ quoteId: ctx.state.path.params.ID
485
+ }
486
+ });
487
+
488
+ ctx.response.status = 200;
489
+ };
490
+
491
+
492
+ /**
493
+ * Handles a PUT /quotes/{ID}/error request. This is an error response to a POST /quotes request
494
+ */
495
+ const putQuotesByIdError = async (ctx) => {
496
+ // TODO: refactor legacy models to use QuotesModel
497
+ // - OutboundRequestToPayTransferModel
498
+ // - OutboundTransfersModel
499
+ // publish an event onto the cache for subscribers to action
500
+ await ctx.state.cache.publish(`qt_${ctx.state.path.params.ID}`, {
501
+ type: 'quoteResponseError',
502
+ data: ctx.request.body
503
+ });
504
+
505
+ // duplicate publication until legacy code refactored
506
+ await QuotesModel.triggerDeferredJob({
507
+ cache: ctx.state.cache,
508
+ message: ctx.request.body,
509
+ args: {
510
+ quoteId: ctx.state.path.params.ID
511
+ }
512
+ });
513
+
514
+ ctx.response.status = 200;
515
+ ctx.response.body = '';
516
+ };
517
+
518
+
519
+ /**
520
+ * Handles a GET /quotes/{ID}
521
+ */
522
+ const getQuoteById = async (ctx) => {
523
+ // kick off an asyncronous operation to handle the request
524
+ (async () => {
525
+ try {
526
+ // use the transfers model to execute asynchronous stages with the switch
527
+ const model = new Model({
528
+ ...ctx.state.conf,
529
+ cache: ctx.state.cache,
530
+ logger: ctx.state.logger,
531
+ wso2: ctx.state.wso2,
532
+ resourceVersions: ctx.resourceVersions,
533
+ });
534
+
535
+ const sourceFspId = ctx.request.headers['fspiop-source'];
536
+
537
+ // use the model to handle the request
538
+ const response = await model.getQuoteRequest(ctx.state.path.params.ID, sourceFspId);
539
+
540
+ // log the result
541
+ ctx.state.logger.push({ response }).log('Inbound transfers model handled GET /quotes request');
542
+ }
543
+ catch(err) {
544
+ // nothing we can do if an error gets thrown back to us here apart from log it and continue
545
+ ctx.state.logger.push({ err }).log('Error handling GET /quotes');
546
+ }
547
+ })();
548
+
549
+ // Note that we will have passed request validation, JWS etc... by this point
550
+ // so it is safe to return 200
551
+ ctx.response.status = 200;
552
+
553
+ };
554
+
555
+ /**
556
+ * Handles a PUT /quotes/{ID}. This is a response to a POST /quotes request
557
+ */
558
+ const putTransactionRequestsById = async (ctx) => {
559
+ // publish an event onto the cache for subscribers to action
560
+ await ctx.state.cache.publish(`txnreq_${ctx.state.path.params.ID}`, {
561
+ type: 'transactionRequestResponse',
562
+ data: ctx.request.body,
563
+ headers: ctx.request.headers
564
+ });
565
+
566
+ ctx.response.status = 200;
567
+ };
568
+
569
+ /**
570
+ * Handles a PUT /transfers/{ID}. This is a response to a POST|GET /transfers request
571
+ */
572
+ const putTransfersById = async (ctx) => {
573
+ // TODO: refactor legacy models to use TransfersModel
574
+ // - OutboundRequestToPayTransferModel
575
+ // - OutboundTransfersModel
576
+ // publish an event onto the cache for subscribers to action
577
+ await ctx.state.cache.publish(`tf_${ctx.state.path.params.ID}`, {
578
+ type: 'transferFulfil',
579
+ data: ctx.request.body
580
+ });
581
+
582
+ await TransfersModel.triggerDeferredJob({
583
+ cache: ctx.state.cache,
584
+ message: ctx.request.body,
585
+ args: {
586
+ transferId: ctx.state.path.params.ID,
587
+ }
588
+ });
589
+
590
+ ctx.response.status = 200;
591
+ };
592
+
593
+ /**
594
+ * Handles a PATCH /transfers/{ID} from the Switch to Payee for successful transfer
595
+ */
596
+ const patchTransfersById = async (ctx) => {
597
+ const req = {
598
+ headers: ctx.request.headers,
599
+ data: ctx.request.body
600
+ };
601
+
602
+ const idValue = ctx.state.path.params.ID;
603
+
604
+ // use the transfers model to execute asynchronous stages with the switch
605
+ const model = new Model({
606
+ ...ctx.state.conf,
607
+ cache: ctx.state.cache,
608
+ logger: ctx.state.logger,
609
+ wso2: ctx.state.wso2,
610
+ resourceVersions: ctx.resourceVersions,
611
+ });
612
+
613
+ // sends notification to the payee fsp
614
+ const response = await model.sendNotificationToPayee(req.data, idValue);
615
+
616
+ // log the result
617
+ ctx.state.logger.push({response}).
618
+ log('Inbound transfers model handled PATCH /transfers/{ID} request');
619
+ };
620
+
621
+ /**
622
+ * Handles a PUT /transfers/{ID}/error. This is an error response to a POST /transfers request
623
+ */
624
+ const putTransfersByIdError = async (ctx) => {
625
+ // TODO: refactor legacy models to use TransfersModel
626
+ // - OutboundRequestToPayTransferModel
627
+ // - OutboundTransfersModel
628
+ // publish an event onto the cache for subscribers to action
629
+ await ctx.state.cache.publish(`tf_${ctx.state.path.params.ID}`, {
630
+ type: 'transferError',
631
+ data: ctx.request.body
632
+ });
633
+
634
+ await TransfersModel.triggerDeferredJob({
635
+ cache: ctx.state.cache,
636
+ message: ctx.request.body,
637
+ args: {
638
+ transferId: ctx.state.path.params.ID,
639
+ }
640
+ });
641
+
642
+ ctx.response.status = 200;
643
+ ctx.response.body = '';
644
+ };
645
+
646
+ /**
647
+ * Handles a GET /bulkQuotes/{ID} request
648
+ */
649
+ const getBulkQuotesById = async (ctx) => {
650
+ // kick off an asyncronous operation to handle the request
651
+ (async () => {
652
+ try {
653
+ // use the transfers model to execute asynchronous stages with the switch
654
+ const model = new Model({
655
+ ...ctx.state.conf,
656
+ cache: ctx.state.cache,
657
+ logger: ctx.state.logger,
658
+ wso2: ctx.state.wso2,
659
+ resourceVersions: ctx.resourceVersions,
660
+ });
661
+
662
+ const sourceFspId = ctx.request.headers['fspiop-source'];
663
+
664
+ // use the model to handle the request
665
+ const response = await model.getBulkQuote(ctx.state.path.params.ID,
666
+ sourceFspId);
667
+
668
+ // log the result
669
+ ctx.state.logger.push({response}).
670
+ log('Inbound transfers model handled GET /bulkQuotes/{ID} request');
671
+ }
672
+ catch(err) {
673
+ // nothing we can do if an error gets thrown back to us here apart from log it and continue
674
+ ctx.state.logger.push({ err }).log('Error handling GET /bulkQuotes/{ID}');
675
+ }
676
+ })();
677
+
678
+ // Note that we will have passed request validation, JWS etc... by this point
679
+ // so it is safe to return 202
680
+ ctx.response.status = 202;
681
+ ctx.response.body = '';
682
+ };
683
+
684
+ /**
685
+ * Handles a POST /bulkQuotes request
686
+ */
687
+ const postBulkQuotes = async (ctx) => {
688
+ (async () => {
689
+ try {
690
+ // use the transfers model to execute asynchronous stages with the switch
691
+ const model = new Model({
692
+ ...ctx.state.conf,
693
+ cache: ctx.state.cache,
694
+ logger: ctx.state.logger,
695
+ wso2: ctx.state.wso2,
696
+ resourceVersions: ctx.resourceVersions,
697
+ });
698
+
699
+ const sourceFspId = ctx.request.headers['fspiop-source'];
700
+
701
+ // use the model to handle the request
702
+ const response = await model.bulkQuoteRequest(ctx.request.body, sourceFspId);
703
+
704
+ // log the result
705
+ ctx.state.logger.push({ response }).log('Inbound transfers model handled POST /bulkQuotes request');
706
+ }
707
+ catch(err) {
708
+ // nothing we can do if an error gets thrown back to us here apart from log it and continue
709
+ ctx.state.logger.push({ err }).log('Error handling POST /bulkQuotes');
710
+ }
711
+ })();
712
+
713
+ ctx.response.status = 202;
714
+ ctx.response.body = '';
715
+ };
716
+
717
+ /**
718
+ * Handles a PUT /bulkQuotes/{ID}. This is a response to a POST /bulkQuotes request
719
+ */
720
+ const putBulkQuotesById = async (ctx) => {
721
+ // publish an event onto the cache for subscribers to action
722
+ await ctx.state.cache.publish(`bulkQuotes_${ctx.state.path.params.ID}`, {
723
+ type: 'bulkQuoteResponse',
724
+ data: ctx.request.body,
725
+ headers: ctx.request.headers
726
+ });
727
+
728
+ ctx.response.status = 200;
729
+ };
730
+
731
+ /**
732
+ * Handles a PUT /bulkQuotes/{ID}/error request. This is an error response to a POST /bulkQuotes request
733
+ */
734
+ const putBulkQuotesByIdError = async(ctx) => {
735
+ // publish an event onto the cache for subscribers to action
736
+ await ctx.state.cache.publish(`bulkQuotes_${ctx.state.path.params.ID}`, {
737
+ type: 'bulkQuoteResponseError',
738
+ data: ctx.request.body
739
+ });
740
+
741
+ ctx.response.status = 200;
742
+ ctx.response.body = '';
743
+ };
744
+
745
+ /**
746
+ * Handles a GET /bulkTransfers/{ID} request
747
+ */
748
+ const getBulkTransfersById = async (ctx) => {
749
+ // kick off an asyncronous operation to handle the request
750
+ (async () => {
751
+ try {
752
+ // use the transfers model to execute asynchronous stages with the switch
753
+ const model = new Model({
754
+ ...ctx.state.conf,
755
+ cache: ctx.state.cache,
756
+ logger: ctx.state.logger,
757
+ wso2: ctx.state.wso2,
758
+ resourceVersions: ctx.resourceVersions,
759
+ });
760
+
761
+ const sourceFspId = ctx.request.headers['fspiop-source'];
762
+
763
+ // use the model to handle the request
764
+ const response = await model.getBulkTransfer(ctx.state.path.params.ID,
765
+ sourceFspId);
766
+
767
+ // log the result
768
+ ctx.state.logger.push({response}).
769
+ log('Inbound transfers model handled GET /bulkTransfers/{ID} request');
770
+ }
771
+ catch(err) {
772
+ // nothing we can do if an error gets thrown back to us here apart from log it and continue
773
+ ctx.state.logger.push({ err }).log('Error handling GET /bulkTransfers/{ID}');
774
+ }
775
+ })();
776
+
777
+ // Note that we will have passed request validation, JWS etc... by this point
778
+ // so it is safe to return 202
779
+ ctx.response.status = 202;
780
+ ctx.response.body = '';
781
+ };
782
+
783
+ /**
784
+ * Handles a POST /bulkTransfers request
785
+ */
786
+ const postBulkTransfers = async (ctx) => {
787
+ (async () => {
788
+ try {
789
+ // use the transfers model to execute asynchronous stages with the switch
790
+ const model = new Model({
791
+ ...ctx.state.conf,
792
+ cache: ctx.state.cache,
793
+ logger: ctx.state.logger,
794
+ wso2: ctx.state.wso2,
795
+ resourceVersions: ctx.resourceVersions,
796
+ });
797
+
798
+ const sourceFspId = ctx.request.headers['fspiop-source'];
799
+
800
+ // use the model to handle the request
801
+ const response = await model.prepareBulkTransfer(ctx.request.body, sourceFspId);
802
+
803
+ // log the result
804
+ ctx.state.logger.push({ response }).log('Inbound transfers model handled POST /bulkTransfers request');
805
+ }
806
+ catch(err) {
807
+ // nothing we can do if an error gets thrown back to us here apart from log it and continue
808
+ ctx.state.logger.push({ err }).log('Error handling POST /bulkTransfers');
809
+ }
810
+ })();
811
+
812
+ ctx.response.status = 202;
813
+ ctx.response.body = '';
814
+ };
815
+
816
+ /**
817
+ * Handles a PUT /bulkTransfers/{ID}. This is a response to a POST /bulkTransfers request
818
+ */
819
+ const putBulkTransfersById = async (ctx) => {
820
+ // publish an event onto the cache for subscribers to action
821
+ await ctx.state.cache.publish(`bulkTransfer_${ctx.state.path.params.ID}`, {
822
+ type: 'bulkTransferResponse',
823
+ data: ctx.request.body,
824
+ headers: ctx.request.headers
825
+ });
826
+
827
+ ctx.response.status = 200;
828
+ };
829
+
830
+ /**
831
+ * Handles a PUT /bulkTransfers/{ID}/error request. This is an error response to a POST /bulkTransfers request
832
+ */
833
+ const putBulkTransfersByIdError = async(ctx) => {
834
+ // publish an event onto the cache for subscribers to action
835
+ await ctx.state.cache.publish(`bulkTransfer_${ctx.state.path.params.ID}`, {
836
+ type: 'bulkTransferResponseError',
837
+ data: ctx.request.body
838
+ });
839
+
840
+ ctx.response.status = 200;
841
+ ctx.response.body = '';
842
+ };
843
+
844
+ const healthCheck = async(ctx) => {
845
+ ctx.response.status = 200;
846
+ ctx.response.body = '';
847
+ };
848
+
849
+ module.exports = {
850
+ '/': {
851
+ get: healthCheck
852
+ },
853
+ '/authorizations/{ID}': {
854
+ get: getAuthorizationsById,
855
+ put: putAuthorizationsById
856
+ },
857
+ '/authorizations/{ID}/error': {
858
+ put: putAuthorizationsByIdError
859
+ },
860
+ '/bulkQuotes': {
861
+ post: postBulkQuotes
862
+ },
863
+ '/bulkQuotes/{ID}': {
864
+ get: getBulkQuotesById,
865
+ put: putBulkQuotesById
866
+ },
867
+ '/bulkQuotes/{ID}/error': {
868
+ put: putBulkQuotesByIdError
869
+ },
870
+ '/bulkTransfers': {
871
+ post: postBulkTransfers
872
+ },
873
+ '/bulkTransfers/{ID}': {
874
+ get: getBulkTransfersById,
875
+ put: putBulkTransfersById
876
+ },
877
+ '/bulkTransfers/{ID}/error': {
878
+ put: putBulkTransfersByIdError
879
+ },
880
+ '/participants/{ID}': {
881
+ put: putParticipantsById
882
+ },
883
+ '/participants/{Type}/{ID}': {
884
+ put: putParticipantsByTypeAndId,
885
+ get: getParticipantsByTypeAndId
886
+ },
887
+ '/participants/{Type}/{ID}/{SubId}': {
888
+ put: putParticipantsByTypeAndId,
889
+ get: getParticipantsByTypeAndId
890
+ },
891
+ '/participants/{Type}/{ID}/{SubId}/error': {
892
+ put: putParticipantsByTypeAndIdError
893
+ },
894
+ '/participants/{ID}/error': {
895
+ put: putParticipantsByIdError
896
+ },
897
+ '/parties/{Type}/{ID}': {
898
+ post: postPartiesByTypeAndId,
899
+ get: getPartiesByTypeAndId,
900
+ put: putPartiesByTypeAndId
901
+ },
902
+ '/parties/{Type}/{ID}/{SubId}': {
903
+ post: postPartiesByTypeAndId,
904
+ get: getPartiesByTypeAndId,
905
+ put: putPartiesByTypeAndId
906
+ },
907
+ '/parties/{Type}/{ID}/error': {
908
+ put: putPartiesByTypeAndIdError
909
+ },
910
+ '/parties/{Type}/{ID}/{SubId}/error': {
911
+ put: putPartiesByTypeAndIdError
912
+ },
913
+ '/quotes': {
914
+ post: postQuotes
915
+ },
916
+ '/quotes/{ID}': {
917
+ put: putQuoteById,
918
+ get: getQuoteById
919
+ },
920
+ '/quotes/{ID}/error': {
921
+ put: putQuotesByIdError
922
+ },
923
+ '/transfers': {
924
+ post: postTransfers
925
+ },
926
+ '/transfers/{ID}': {
927
+ get: getTransfersById,
928
+ put: putTransfersById,
929
+ patch: patchTransfersById
930
+ },
931
+ '/transfers/{ID}/error': {
932
+ put: putTransfersByIdError
933
+ },
934
+ '/transactionRequests': {
935
+ post: postTransactionRequests
936
+ },
937
+ '/transactionRequests/{ID}': {
938
+ put: putTransactionRequestsById
939
+ }
940
+ };