@unchainedshop/plugins 1.1.7 → 1.2.1

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 (314) hide show
  1. package/jest.config.js +5 -0
  2. package/package.json +31 -25
  3. package/src/files/gridfs/gridfs-adapter.ts +1 -1
  4. package/src/files/gridfs/gridfs-webhook.ts +62 -0
  5. package/src/files/gridfs/{index.js → index.ts} +0 -0
  6. package/src/files/gridfs/{promisePipe.js → promisePipe.ts} +0 -0
  7. package/src/files/gridfs/{sign.js → sign.ts} +0 -0
  8. package/src/files/minio/minio-adapter.ts +1 -2
  9. package/src/files/minio/minio-webhook.js +33 -30
  10. package/src/payment/apple-iap/adapter.ts +113 -110
  11. package/src/payment/apple-iap/index.ts +2 -1
  12. package/src/payment/bity/adapter.ts +53 -51
  13. package/src/payment/bity/index.ts +2 -1
  14. package/src/payment/braintree.ts +2 -2
  15. package/src/payment/cryptopay.ts +69 -67
  16. package/src/payment/datatrans-v2/index.ts +3 -1
  17. package/src/payment/datatrans-v2/middleware.ts +129 -123
  18. package/src/payment/paypal-checkout.ts +1 -1
  19. package/src/payment/postfinance-checkout/index.ts +3 -1
  20. package/src/payment/postfinance-checkout/middleware.ts +42 -40
  21. package/src/payment/stripe.ts +82 -74
  22. package/src/payment/worldline-saferpay/worldline-saferpay-client/index.ts +3 -3
  23. package/src/pricing/product-discount.ts +1 -1
  24. package/src/pricing/product-price-ECB-interbank-exchange.ts +1 -1
  25. package/src/pricing/product-price-cryptopay.ts +20 -18
  26. package/src/worker/email.ts +1 -0
  27. package/tsconfig.json +26 -5
  28. package/lib/delivery/pick-mup.d.ts +0 -1
  29. package/lib/delivery/pick-mup.js +0 -98
  30. package/lib/delivery/pick-mup.js.map +0 -1
  31. package/lib/delivery/post.d.ts +0 -1
  32. package/lib/delivery/post.js +0 -23
  33. package/lib/delivery/post.js.map +0 -1
  34. package/lib/delivery/send-message.d.ts +0 -1
  35. package/lib/delivery/send-message.js +0 -41
  36. package/lib/delivery/send-message.js.map +0 -1
  37. package/lib/delivery/stores.d.ts +0 -1
  38. package/lib/delivery/stores.js +0 -39
  39. package/lib/delivery/stores.js.map +0 -1
  40. package/lib/enrollments/licensed.d.ts +0 -1
  41. package/lib/enrollments/licensed.js +0 -40
  42. package/lib/enrollments/licensed.js.map +0 -1
  43. package/lib/events/node-event-emitter.d.ts +0 -1
  44. package/lib/events/node-event-emitter.js +0 -16
  45. package/lib/events/node-event-emitter.js.map +0 -1
  46. package/lib/events/redis.d.ts +0 -1
  47. package/lib/events/redis.js +0 -24
  48. package/lib/events/redis.js.map +0 -1
  49. package/lib/files/gridfs/gridfs-adapter.d.ts +0 -2
  50. package/lib/files/gridfs/gridfs-adapter.js +0 -106
  51. package/lib/files/gridfs/gridfs-adapter.js.map +0 -1
  52. package/lib/files/gridfs/gridfs-webhook.d.ts +0 -1
  53. package/lib/files/gridfs/gridfs-webhook.js +0 -54
  54. package/lib/files/gridfs/gridfs-webhook.js.map +0 -1
  55. package/lib/files/gridfs/index.d.ts +0 -8
  56. package/lib/files/gridfs/index.js +0 -21
  57. package/lib/files/gridfs/index.js.map +0 -1
  58. package/lib/files/gridfs/promisePipe.d.ts +0 -2
  59. package/lib/files/gridfs/promisePipe.js +0 -21
  60. package/lib/files/gridfs/promisePipe.js.map +0 -1
  61. package/lib/files/gridfs/sign.d.ts +0 -2
  62. package/lib/files/gridfs/sign.js +0 -12
  63. package/lib/files/gridfs/sign.js.map +0 -1
  64. package/lib/files/minio/minio-adapter.d.ts +0 -4
  65. package/lib/files/minio/minio-adapter.js +0 -166
  66. package/lib/files/minio/minio-adapter.js.map +0 -1
  67. package/lib/files/minio/minio-webhook.d.ts +0 -1
  68. package/lib/files/minio/minio-webhook.js +0 -45
  69. package/lib/files/minio/minio-webhook.js.map +0 -1
  70. package/lib/filters/local-search.d.ts +0 -3
  71. package/lib/filters/local-search.js +0 -84
  72. package/lib/filters/local-search.js.map +0 -1
  73. package/lib/filters/strict-equal.d.ts +0 -1
  74. package/lib/filters/strict-equal.js +0 -25
  75. package/lib/filters/strict-equal.js.map +0 -1
  76. package/lib/payment/apple-iap/adapter.d.ts +0 -1
  77. package/lib/payment/apple-iap/adapter.js +0 -284
  78. package/lib/payment/apple-iap/adapter.js.map +0 -1
  79. package/lib/payment/apple-iap/db/AppleTransactionsCollection.d.ts +0 -7
  80. package/lib/payment/apple-iap/db/AppleTransactionsCollection.js +0 -5
  81. package/lib/payment/apple-iap/db/AppleTransactionsCollection.js.map +0 -1
  82. package/lib/payment/apple-iap/index.d.ts +0 -2
  83. package/lib/payment/apple-iap/index.js +0 -3
  84. package/lib/payment/apple-iap/index.js.map +0 -1
  85. package/lib/payment/apple-iap/module/configureAppleTransactionsModule.d.ts +0 -9
  86. package/lib/payment/apple-iap/module/configureAppleTransactionsModule.js +0 -18
  87. package/lib/payment/apple-iap/module/configureAppleTransactionsModule.js.map +0 -1
  88. package/lib/payment/bity/adapter.d.ts +0 -1
  89. package/lib/payment/bity/adapter.js +0 -316
  90. package/lib/payment/bity/adapter.js.map +0 -1
  91. package/lib/payment/bity/db/BityCredentialsCollection.d.ts +0 -11
  92. package/lib/payment/bity/db/BityCredentialsCollection.js +0 -5
  93. package/lib/payment/bity/db/BityCredentialsCollection.js.map +0 -1
  94. package/lib/payment/bity/index.d.ts +0 -2
  95. package/lib/payment/bity/index.js +0 -3
  96. package/lib/payment/bity/index.js.map +0 -1
  97. package/lib/payment/bity/module/configureBityModule.d.ts +0 -11
  98. package/lib/payment/bity/module/configureBityModule.js +0 -33
  99. package/lib/payment/bity/module/configureBityModule.js.map +0 -1
  100. package/lib/payment/braintree.d.ts +0 -1
  101. package/lib/payment/braintree.js +0 -129
  102. package/lib/payment/braintree.js.map +0 -1
  103. package/lib/payment/cryptopay.d.ts +0 -1
  104. package/lib/payment/cryptopay.js +0 -159
  105. package/lib/payment/cryptopay.js.map +0 -1
  106. package/lib/payment/datatrans-v2/api/authorize.d.ts +0 -2
  107. package/lib/payment/datatrans-v2/api/authorize.js +0 -12
  108. package/lib/payment/datatrans-v2/api/authorize.js.map +0 -1
  109. package/lib/payment/datatrans-v2/api/authorizeAuthenticated.d.ts +0 -2
  110. package/lib/payment/datatrans-v2/api/authorizeAuthenticated.js +0 -11
  111. package/lib/payment/datatrans-v2/api/authorizeAuthenticated.js.map +0 -1
  112. package/lib/payment/datatrans-v2/api/cancel.d.ts +0 -2
  113. package/lib/payment/datatrans-v2/api/cancel.js +0 -10
  114. package/lib/payment/datatrans-v2/api/cancel.js.map +0 -1
  115. package/lib/payment/datatrans-v2/api/index.d.ts +0 -19
  116. package/lib/payment/datatrans-v2/api/index.js +0 -24
  117. package/lib/payment/datatrans-v2/api/index.js.map +0 -1
  118. package/lib/payment/datatrans-v2/api/init.d.ts +0 -2
  119. package/lib/payment/datatrans-v2/api/init.js +0 -31
  120. package/lib/payment/datatrans-v2/api/init.js.map +0 -1
  121. package/lib/payment/datatrans-v2/api/makeFetcher.d.ts +0 -2
  122. package/lib/payment/datatrans-v2/api/makeFetcher.js +0 -41
  123. package/lib/payment/datatrans-v2/api/makeFetcher.js.map +0 -1
  124. package/lib/payment/datatrans-v2/api/secureFields.d.ts +0 -2
  125. package/lib/payment/datatrans-v2/api/secureFields.js +0 -14
  126. package/lib/payment/datatrans-v2/api/secureFields.js.map +0 -1
  127. package/lib/payment/datatrans-v2/api/settle.d.ts +0 -2
  128. package/lib/payment/datatrans-v2/api/settle.js +0 -10
  129. package/lib/payment/datatrans-v2/api/settle.js.map +0 -1
  130. package/lib/payment/datatrans-v2/api/status.d.ts +0 -2
  131. package/lib/payment/datatrans-v2/api/status.js +0 -7
  132. package/lib/payment/datatrans-v2/api/status.js.map +0 -1
  133. package/lib/payment/datatrans-v2/api/validate.d.ts +0 -2
  134. package/lib/payment/datatrans-v2/api/validate.js +0 -10
  135. package/lib/payment/datatrans-v2/api/validate.js.map +0 -1
  136. package/lib/payment/datatrans-v2/generateSignature.d.ts +0 -10
  137. package/lib/payment/datatrans-v2/generateSignature.js +0 -19
  138. package/lib/payment/datatrans-v2/generateSignature.js.map +0 -1
  139. package/lib/payment/datatrans-v2/getPaths.d.ts +0 -9
  140. package/lib/payment/datatrans-v2/getPaths.js +0 -9
  141. package/lib/payment/datatrans-v2/getPaths.js.map +0 -1
  142. package/lib/payment/datatrans-v2/index.d.ts +0 -1
  143. package/lib/payment/datatrans-v2/index.js +0 -384
  144. package/lib/payment/datatrans-v2/index.js.map +0 -1
  145. package/lib/payment/datatrans-v2/middleware.d.ts +0 -1
  146. package/lib/payment/datatrans-v2/middleware.js +0 -111
  147. package/lib/payment/datatrans-v2/middleware.js.map +0 -1
  148. package/lib/payment/datatrans-v2/parseRegistrationData.d.ts +0 -11
  149. package/lib/payment/datatrans-v2/parseRegistrationData.js +0 -26
  150. package/lib/payment/datatrans-v2/parseRegistrationData.js.map +0 -1
  151. package/lib/payment/datatrans-v2/roundedAmountFromOrder.d.ts +0 -7
  152. package/lib/payment/datatrans-v2/roundedAmountFromOrder.js +0 -10
  153. package/lib/payment/datatrans-v2/roundedAmountFromOrder.js.map +0 -1
  154. package/lib/payment/datatrans-v2/splitProperties.d.ts +0 -8
  155. package/lib/payment/datatrans-v2/splitProperties.js +0 -58
  156. package/lib/payment/datatrans-v2/splitProperties.js.map +0 -1
  157. package/lib/payment/invoice-prepaid.d.ts +0 -1
  158. package/lib/payment/invoice-prepaid.js +0 -30
  159. package/lib/payment/invoice-prepaid.js.map +0 -1
  160. package/lib/payment/invoice.d.ts +0 -1
  161. package/lib/payment/invoice.js +0 -27
  162. package/lib/payment/invoice.js.map +0 -1
  163. package/lib/payment/paypal-checkout.d.ts +0 -1
  164. package/lib/payment/paypal-checkout.js +0 -82
  165. package/lib/payment/paypal-checkout.js.map +0 -1
  166. package/lib/payment/postfinance-checkout/api.d.ts +0 -11
  167. package/lib/payment/postfinance-checkout/api.js +0 -109
  168. package/lib/payment/postfinance-checkout/api.js.map +0 -1
  169. package/lib/payment/postfinance-checkout/index.d.ts +0 -1
  170. package/lib/payment/postfinance-checkout/index.js +0 -186
  171. package/lib/payment/postfinance-checkout/index.js.map +0 -1
  172. package/lib/payment/postfinance-checkout/middleware.d.ts +0 -1
  173. package/lib/payment/postfinance-checkout/middleware.js +0 -42
  174. package/lib/payment/postfinance-checkout/middleware.js.map +0 -1
  175. package/lib/payment/postfinance-checkout/types.d.ts +0 -23
  176. package/lib/payment/postfinance-checkout/types.js +0 -12
  177. package/lib/payment/postfinance-checkout/types.js.map +0 -1
  178. package/lib/payment/postfinance-checkout/utils.d.ts +0 -4
  179. package/lib/payment/postfinance-checkout/utils.js +0 -20
  180. package/lib/payment/postfinance-checkout/utils.js.map +0 -1
  181. package/lib/payment/stripe.d.ts +0 -1
  182. package/lib/payment/stripe.js +0 -214
  183. package/lib/payment/stripe.js.map +0 -1
  184. package/lib/payment/worldline-saferpay/index.d.ts +0 -1
  185. package/lib/payment/worldline-saferpay/index.js +0 -112
  186. package/lib/payment/worldline-saferpay/index.js.map +0 -1
  187. package/lib/payment/worldline-saferpay/worldline-saferpay-client/api/SaferpayClient.d.ts +0 -14
  188. package/lib/payment/worldline-saferpay/worldline-saferpay-client/api/SaferpayClient.js +0 -29
  189. package/lib/payment/worldline-saferpay/worldline-saferpay-client/api/SaferpayClient.js.map +0 -1
  190. package/lib/payment/worldline-saferpay/worldline-saferpay-client/api/SaferpayConnection.d.ts +0 -9
  191. package/lib/payment/worldline-saferpay/worldline-saferpay-client/api/SaferpayConnection.js +0 -28
  192. package/lib/payment/worldline-saferpay/worldline-saferpay-client/api/SaferpayConnection.js.map +0 -1
  193. package/lib/payment/worldline-saferpay/worldline-saferpay-client/index.d.ts +0 -4
  194. package/lib/payment/worldline-saferpay/worldline-saferpay-client/index.js +0 -2
  195. package/lib/payment/worldline-saferpay/worldline-saferpay-client/index.js.map +0 -1
  196. package/lib/payment/worldline-saferpay/worldline-saferpay-client/models/PaymentMethods.d.ts +0 -1
  197. package/lib/payment/worldline-saferpay/worldline-saferpay-client/models/PaymentMethods.js +0 -2
  198. package/lib/payment/worldline-saferpay/worldline-saferpay-client/models/PaymentMethods.js.map +0 -1
  199. package/lib/payment/worldline-saferpay/worldline-saferpay-client/models/PaymentPageAssert.d.ts +0 -73
  200. package/lib/payment/worldline-saferpay/worldline-saferpay-client/models/PaymentPageAssert.js +0 -2
  201. package/lib/payment/worldline-saferpay/worldline-saferpay-client/models/PaymentPageAssert.js.map +0 -1
  202. package/lib/payment/worldline-saferpay/worldline-saferpay-client/models/PaymentPageInitialize.d.ts +0 -53
  203. package/lib/payment/worldline-saferpay/worldline-saferpay-client/models/PaymentPageInitialize.js +0 -2
  204. package/lib/payment/worldline-saferpay/worldline-saferpay-client/models/PaymentPageInitialize.js.map +0 -1
  205. package/lib/payment/worldline-saferpay/worldline-saferpay-client/models/Request.d.ts +0 -13
  206. package/lib/payment/worldline-saferpay/worldline-saferpay-client/models/Request.js +0 -2
  207. package/lib/payment/worldline-saferpay/worldline-saferpay-client/models/Request.js.map +0 -1
  208. package/lib/payment/worldline-saferpay/worldline-saferpay-client/models/Response.d.ts +0 -9
  209. package/lib/payment/worldline-saferpay/worldline-saferpay-client/models/Response.js +0 -2
  210. package/lib/payment/worldline-saferpay/worldline-saferpay-client/models/Response.js.map +0 -1
  211. package/lib/payment/worldline-saferpay/worldline-saferpay-client/models/Transaction.d.ts +0 -5
  212. package/lib/payment/worldline-saferpay/worldline-saferpay-client/models/Transaction.js +0 -2
  213. package/lib/payment/worldline-saferpay/worldline-saferpay-client/models/Transaction.js.map +0 -1
  214. package/lib/payment/worldline-saferpay/worldline-saferpay-client/models/TransactionCancel.d.ts +0 -13
  215. package/lib/payment/worldline-saferpay/worldline-saferpay-client/models/TransactionCancel.js +0 -2
  216. package/lib/payment/worldline-saferpay/worldline-saferpay-client/models/TransactionCancel.js.map +0 -1
  217. package/lib/pricing/delivery-swiss-tax.d.ts +0 -15
  218. package/lib/pricing/delivery-swiss-tax.js +0 -98
  219. package/lib/pricing/delivery-swiss-tax.js.map +0 -1
  220. package/lib/pricing/discount-100-off.d.ts +0 -1
  221. package/lib/pricing/discount-100-off.js +0 -34
  222. package/lib/pricing/discount-100-off.js.map +0 -1
  223. package/lib/pricing/discount-half-price-manual.d.ts +0 -1
  224. package/lib/pricing/discount-half-price-manual.js +0 -34
  225. package/lib/pricing/discount-half-price-manual.js.map +0 -1
  226. package/lib/pricing/discount-half-price.d.ts +0 -1
  227. package/lib/pricing/discount-half-price.js +0 -37
  228. package/lib/pricing/discount-half-price.js.map +0 -1
  229. package/lib/pricing/free-delivery.d.ts +0 -2
  230. package/lib/pricing/free-delivery.js +0 -26
  231. package/lib/pricing/free-delivery.js.map +0 -1
  232. package/lib/pricing/free-payment.d.ts +0 -2
  233. package/lib/pricing/free-payment.js +0 -26
  234. package/lib/pricing/free-payment.js.map +0 -1
  235. package/lib/pricing/order-delivery.d.ts +0 -1
  236. package/lib/pricing/order-delivery.js +0 -33
  237. package/lib/pricing/order-delivery.js.map +0 -1
  238. package/lib/pricing/order-discount.d.ts +0 -1
  239. package/lib/pricing/order-discount.js +0 -110
  240. package/lib/pricing/order-discount.js.map +0 -1
  241. package/lib/pricing/order-items-discount.d.ts +0 -1
  242. package/lib/pricing/order-items-discount.js +0 -88
  243. package/lib/pricing/order-items-discount.js.map +0 -1
  244. package/lib/pricing/order-items.d.ts +0 -1
  245. package/lib/pricing/order-items.js +0 -44
  246. package/lib/pricing/order-items.js.map +0 -1
  247. package/lib/pricing/order-payment.d.ts +0 -1
  248. package/lib/pricing/order-payment.js +0 -33
  249. package/lib/pricing/order-payment.js.map +0 -1
  250. package/lib/pricing/product-catalog-price.d.ts +0 -1
  251. package/lib/pricing/product-catalog-price.js +0 -37
  252. package/lib/pricing/product-catalog-price.js.map +0 -1
  253. package/lib/pricing/product-discount.d.ts +0 -1
  254. package/lib/pricing/product-discount.js +0 -55
  255. package/lib/pricing/product-discount.js.map +0 -1
  256. package/lib/pricing/product-price-ECB-interbank-exchange.d.ts +0 -1
  257. package/lib/pricing/product-price-ECB-interbank-exchange.js +0 -90
  258. package/lib/pricing/product-price-ECB-interbank-exchange.js.map +0 -1
  259. package/lib/pricing/product-price-coinbase-exchange.d.ts +0 -1
  260. package/lib/pricing/product-price-coinbase-exchange.js +0 -60
  261. package/lib/pricing/product-price-coinbase-exchange.js.map +0 -1
  262. package/lib/pricing/product-price-cryptopay.d.ts +0 -1
  263. package/lib/pricing/product-price-cryptopay.js +0 -21
  264. package/lib/pricing/product-price-cryptopay.js.map +0 -1
  265. package/lib/pricing/product-price-rateconversion.d.ts +0 -1
  266. package/lib/pricing/product-price-rateconversion.js +0 -51
  267. package/lib/pricing/product-price-rateconversion.js.map +0 -1
  268. package/lib/pricing/product-price-round.d.ts +0 -11
  269. package/lib/pricing/product-price-round.js +0 -54
  270. package/lib/pricing/product-price-round.js.map +0 -1
  271. package/lib/pricing/product-swiss-tax.d.ts +0 -13
  272. package/lib/pricing/product-swiss-tax.js +0 -102
  273. package/lib/pricing/product-swiss-tax.js.map +0 -1
  274. package/lib/pricing/utils/cache.d.ts +0 -8
  275. package/lib/pricing/utils/cache.js +0 -28
  276. package/lib/pricing/utils/cache.js.map +0 -1
  277. package/lib/quotations/manual.d.ts +0 -1
  278. package/lib/quotations/manual.js +0 -21
  279. package/lib/quotations/manual.js.map +0 -1
  280. package/lib/warehousing/google-sheets.d.ts +0 -1
  281. package/lib/warehousing/google-sheets.js +0 -153
  282. package/lib/warehousing/google-sheets.js.map +0 -1
  283. package/lib/warehousing/store.d.ts +0 -1
  284. package/lib/warehousing/store.js +0 -33
  285. package/lib/warehousing/store.js.map +0 -1
  286. package/lib/worker/BulkImportWorker.d.ts +0 -2
  287. package/lib/worker/BulkImportWorker.js +0 -91
  288. package/lib/worker/BulkImportWorker.js.map +0 -1
  289. package/lib/worker/GenerateOrderWorker.d.ts +0 -1
  290. package/lib/worker/GenerateOrderWorker.js +0 -110
  291. package/lib/worker/GenerateOrderWorker.js.map +0 -1
  292. package/lib/worker/MessageWorker.js +0 -45
  293. package/lib/worker/MessageWorker.js.map +0 -1
  294. package/lib/worker/ZombieKillerWorker.d.ts +0 -7
  295. package/lib/worker/ZombieKillerWorker.js +0 -88
  296. package/lib/worker/ZombieKillerWorker.js.map +0 -1
  297. package/lib/worker/email.d.ts +0 -1
  298. package/lib/worker/email.js +0 -96
  299. package/lib/worker/email.js.map +0 -1
  300. package/lib/worker/external.d.ts +0 -2
  301. package/lib/worker/external.js +0 -13
  302. package/lib/worker/external.js.map +0 -1
  303. package/lib/worker/heartbeat.d.ts +0 -1
  304. package/lib/worker/heartbeat.js +0 -32
  305. package/lib/worker/heartbeat.js.map +0 -1
  306. package/lib/worker/http-request.d.ts +0 -8
  307. package/lib/worker/http-request.js +0 -61
  308. package/lib/worker/http-request.js.map +0 -1
  309. package/lib/worker/sms.d.ts +0 -1
  310. package/lib/worker/sms.js +0 -69
  311. package/lib/worker/sms.js.map +0 -1
  312. package/license +0 -274
  313. package/src/files/gridfs/gridfs-webhook.js +0 -60
  314. package/tsconfig.build.json +0 -26
package/jest.config.js ADDED
@@ -0,0 +1,5 @@
1
+ /** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */
2
+ export default {
3
+ preset: 'ts-jest',
4
+ testEnvironment: 'node',
5
+ };
package/package.json CHANGED
@@ -1,13 +1,16 @@
1
1
  {
2
2
  "name": "@unchainedshop/plugins",
3
- "version": "1.1.7",
4
- "main": "lib/index.js",
5
- "types": "lib/index.d.ts",
3
+ "version": "1.2.1",
4
+ "exports": {
5
+ "./*": "./lib/*"
6
+ },
6
7
  "type": "module",
7
8
  "scripts": {
9
+ "prepublishOnly": "npm install && npm run build || :",
8
10
  "clean": "rm -rf lib",
9
- "build": "npm run clean && tsc -p tsconfig.build.json",
10
- "watch": "tsc -p tsconfig.build.json --watch"
11
+ "build": "npm run clean && tsc",
12
+ "watch": "tsc -w",
13
+ "test": "jest --watch"
11
14
  },
12
15
  "repository": {
13
16
  "type": "git",
@@ -25,37 +28,40 @@
25
28
  },
26
29
  "homepage": "https://github.com/unchainedshop/unchained#readme",
27
30
  "devDependencies": {
28
- "@unchainedshop/api": "^1.1.7",
31
+ "@types/node": "^16.11.44",
32
+ "@unchainedshop/api": "^1.1.9",
29
33
  "@unchainedshop/client-oauth2": "^4.3.3",
30
- "@unchainedshop/core-delivery": "^1.1.7",
31
- "@unchainedshop/core-enrollments": "^1.1.7",
32
- "@unchainedshop/core-filters": "^1.1.7",
33
- "@unchainedshop/core-messaging": "^1.1.7",
34
- "@unchainedshop/core-orders": "^1.1.7",
35
- "@unchainedshop/core-payment": "^1.1.7",
36
- "@unchainedshop/core-products": "^1.1.7",
37
- "@unchainedshop/core-quotations": "^1.1.7",
38
- "@unchainedshop/core-warehousing": "^1.1.7",
39
- "@unchainedshop/core-worker": "^1.1.7",
40
- "@unchainedshop/events": "^1.1.7",
41
- "@unchainedshop/file-upload": "^1.1.7",
42
- "@unchainedshop/logger": "^1.1.7",
43
- "@unchainedshop/types": "^1.1.7",
44
- "@unchainedshop/utils": "^1.1.7",
45
- "JSONStream": "^1.3.5",
34
+ "@unchainedshop/core-delivery": "^1.1.9",
35
+ "@unchainedshop/core-enrollments": "^1.1.9",
36
+ "@unchainedshop/core-filters": "^1.1.9",
37
+ "@unchainedshop/core-messaging": "^1.1.9",
38
+ "@unchainedshop/core-orders": "^1.1.9",
39
+ "@unchainedshop/core-payment": "^1.1.9",
40
+ "@unchainedshop/core-products": "^1.1.9",
41
+ "@unchainedshop/core-quotations": "^1.1.9",
42
+ "@unchainedshop/core-warehousing": "^1.1.9",
43
+ "@unchainedshop/core-worker": "^1.1.9",
44
+ "@unchainedshop/events": "^1.1.9",
45
+ "@unchainedshop/file-upload": "^1.1.9",
46
+ "@unchainedshop/logger": "^1.1.9",
47
+ "@unchainedshop/types": "^1.1.9",
48
+ "@unchainedshop/utils": "^1.1.9",
46
49
  "bluebird": "^3.7.2",
47
50
  "body-parser": "^1.20.0",
48
51
  "event-iterator": "^2.0.0",
52
+ "jest": "^28.1.2",
53
+ "JSONStream": "^1.3.5",
49
54
  "minio": "^7.0.28",
50
55
  "moment": "^2.29.3",
51
56
  "mongodb": "^4.7.0",
52
- "node-sheets": "^1.2.0",
57
+ "node-sheets": "^1.1.9",
53
58
  "nodemailer": "^6.7.5",
54
59
  "open": "^8.4.0",
55
60
  "redis": "^4.1.0",
56
61
  "request": "^2.88.2",
62
+ "ts-jest": "^28.0.5",
57
63
  "typescript": "^4.7.4",
64
+ "xml-js": "^1.6.11",
58
65
  "xml2js": "0.4.23"
59
- },
60
- "gitHead": "06cd41a39f57481555c743836481b9190b2ec2b5"
66
+ }
61
67
  }
@@ -5,7 +5,7 @@ import http, { OutgoingHttpHeaders } from 'http';
5
5
  import mimeType from 'mime-types';
6
6
  import { URL } from 'url';
7
7
  import { Readable } from 'stream';
8
- import buildHashedFilename from '@unchainedshop/file-upload/lib/buildHashedFilename';
8
+ import { buildHashedFilename } from '@unchainedshop/file-upload';
9
9
  import sign from './sign';
10
10
  import promisePipe from './promisePipe';
11
11
 
@@ -0,0 +1,62 @@
1
+ import { useMiddlewareWithCurrentContext } from '@unchainedshop/api';
2
+ import { log, LogLevel } from '@unchainedshop/logger';
3
+ import { buildHashedFilename } from '@unchainedshop/file-upload';
4
+ import sign from './sign';
5
+ import promisePipe from './promisePipe';
6
+
7
+ const { ROOT_URL } = process.env;
8
+
9
+ /*
10
+ curl -vvv -X PUT -T /Users/pozylon/Downloads/grafik.png http://localhost:4010/gridfs/user-avatars/hans.png?e=1653059591506&s=df8626a1c9b9006249d7f1928fd530579fed57216f1bdcb83c28a8322cdc90b1
11
+ */
12
+
13
+ export default (app) =>
14
+ useMiddlewareWithCurrentContext(app, '/gridfs', async (req, res) => {
15
+ try {
16
+ const { services, modules } = req.unchainedContext;
17
+ const url = new URL(req.url, ROOT_URL);
18
+ const [, directoryName, fileName] = url.pathname.split('/');
19
+
20
+ if (req.method === 'PUT') {
21
+ const { s: signature, e: expiryTimestamp } = req.query;
22
+ const expiryDate = new Date(parseInt(expiryTimestamp, 10));
23
+ const fileId = buildHashedFilename(directoryName, fileName, expiryDate);
24
+ if (sign(directoryName, fileId, expiryDate.getTime()) === signature) {
25
+ const file = await modules.files.findFile({ fileId });
26
+ if (file.expires === null) {
27
+ res.writeHead(503);
28
+ res.end('File already linked');
29
+ return;
30
+ }
31
+ const writeStream = await modules.gridfsFileUploads.createWriteStream(
32
+ directoryName,
33
+ fileId,
34
+ fileName,
35
+ );
36
+ res.writeHead(200);
37
+ const { length } = await promisePipe(req, writeStream);
38
+ await services.files.linkFile({ fileId, size: length }, req.unchainedContext);
39
+ res.end();
40
+ return;
41
+ }
42
+ res.writeHead(403);
43
+ res.end();
44
+ return;
45
+ }
46
+ if (req.method === 'GET') {
47
+ const fileId = fileName;
48
+ const readStream = await modules.gridfsFileUploads.createReadStream(directoryName, fileId);
49
+ res.writeHead(200);
50
+ await promisePipe(readStream, res);
51
+ res.end();
52
+ return;
53
+ }
54
+ res.writeHead(404);
55
+ res.end();
56
+ return;
57
+ } catch (e) {
58
+ log(e.message, { level: LogLevel.Error });
59
+ res.writeHead(503);
60
+ res.end(JSON.stringify(e));
61
+ }
62
+ });
File without changes
File without changes
@@ -1,5 +1,5 @@
1
1
  import { IFileAdapter } from '@unchainedshop/types/files';
2
- import { FileAdapter, FileDirector } from '@unchainedshop/file-upload';
2
+ import { FileAdapter, FileDirector, buildHashedFilename } from '@unchainedshop/file-upload';
3
3
 
4
4
  import https from 'https';
5
5
  import http, { OutgoingHttpHeaders } from 'http';
@@ -8,7 +8,6 @@ import mimeType from 'mime-types';
8
8
  import Minio from 'minio';
9
9
  import { Readable } from 'stream';
10
10
  import { URL } from 'url';
11
- import buildHashedFilename from '@unchainedshop/file-upload/lib/buildHashedFilename';
12
11
 
13
12
  const {
14
13
  MINIO_ACCESS_KEY,
@@ -9,39 +9,42 @@ const isAuthorized = ({ authorization = '' }) => {
9
9
  return type === 'Bearer' && token === MINIO_WEBHOOK_AUTH_TOKEN;
10
10
  };
11
11
 
12
- useMiddlewareWithCurrentContext(
13
- '/minio/',
14
- bodyParser.json({
15
- strict: false,
16
- }),
17
- );
12
+ export default (app) => {
13
+ useMiddlewareWithCurrentContext(
14
+ app,
15
+ '/minio/',
16
+ bodyParser.json({
17
+ strict: false,
18
+ }),
19
+ );
18
20
 
19
- useMiddlewareWithCurrentContext('/minio/', async (req, res) => {
20
- try {
21
- if (req.method === 'POST' && req.body) {
22
- const { headers } = req;
23
- const { Records = [], EventName } = req.body;
24
- if (EventName === 's3:ObjectCreated:Put' && isAuthorized(headers)) {
25
- const [{ s3 }] = Records;
26
- const { object } = s3;
27
- const { size, contentType: type } = object;
28
- const [fileId] = object.key.split('.');
29
- const { services } = req.unchainedContext;
30
- await services.files.linkFile({ fileId, type, size }, req.unchainedContext);
31
- res.writeHead(200);
32
- res.end();
33
- return;
21
+ useMiddlewareWithCurrentContext(app, '/minio/', async (req, res) => {
22
+ try {
23
+ if (req.method === 'POST' && req.body) {
24
+ const { headers } = req;
25
+ const { Records = [], EventName } = req.body;
26
+ if (EventName === 's3:ObjectCreated:Put' && isAuthorized(headers)) {
27
+ const [{ s3 }] = Records;
28
+ const { object } = s3;
29
+ const { size, contentType: type } = object;
30
+ const [fileId] = object.key.split('.');
31
+ const { services } = req.unchainedContext;
32
+ await services.files.linkFile({ fileId, type, size }, req.unchainedContext);
33
+ res.writeHead(200);
34
+ res.end();
35
+ return;
36
+ }
34
37
  }
38
+ res.writeHead(404);
39
+ res.end();
40
+ return;
41
+ } catch (e) {
42
+ log(e.message, { level: LogLevel.Error });
43
+ res.writeHead(503);
44
+ res.end(JSON.stringify(e));
35
45
  }
36
- res.writeHead(404);
37
- res.end();
38
- return;
39
- } catch (e) {
40
- log(e.message, { level: LogLevel.Error });
41
- res.writeHead(503);
42
- res.end(JSON.stringify(e));
43
- }
44
- });
46
+ });
47
+ };
45
48
 
46
49
  /*
47
50
 
@@ -13,7 +13,7 @@ const logger = createLogger('unchained:core-payment:iap');
13
13
  const {
14
14
  APPLE_IAP_SHARED_SECRET,
15
15
  APPLE_IAP_ENVIRONMENT = 'sandbox',
16
- APPLE_IAP_WEBHOOK_PATH = '/graphql/apple-iap',
16
+ APPLE_IAP_WEBHOOK_PATH = '/payment/apple-iap',
17
17
  } = process.env;
18
18
 
19
19
  // https://developer.apple.com/documentation/storekit/in-app_purchase/validating_receipts_with_the_app_store
@@ -88,44 +88,89 @@ const fixPeriods = async (
88
88
  );
89
89
  };
90
90
 
91
- useMiddlewareWithCurrentContext(
92
- APPLE_IAP_WEBHOOK_PATH,
93
- bodyParser.json({
94
- strict: false,
95
- }),
96
- );
97
-
98
- useMiddlewareWithCurrentContext(APPLE_IAP_WEBHOOK_PATH, async (req, res) => {
99
- if (req.method === 'POST') {
100
- try {
101
- const resolvedContext = req.unchainedContext as Context;
102
- const { modules, services } = resolvedContext;
103
- const responseBody = req.body || {};
104
- if (responseBody.password !== APPLE_IAP_SHARED_SECRET) {
105
- throw new Error('shared secret not valid');
106
- }
91
+ export default (app) => {
92
+ useMiddlewareWithCurrentContext(
93
+ app,
94
+ APPLE_IAP_WEBHOOK_PATH,
95
+ bodyParser.json({
96
+ strict: false,
97
+ }),
98
+ );
107
99
 
108
- const transactions = responseBody?.unified_receipt?.latest_receipt_info; // eslint-disable-line
109
- const latestTransaction = transactions[0];
100
+ useMiddlewareWithCurrentContext(app, APPLE_IAP_WEBHOOK_PATH, async (req, res) => {
101
+ if (req.method === 'POST') {
102
+ try {
103
+ const resolvedContext = req.unchainedContext as Context;
104
+ const { modules, services } = resolvedContext;
105
+ const responseBody = req.body || {};
106
+ if (responseBody.password !== APPLE_IAP_SHARED_SECRET) {
107
+ throw new Error('shared secret not valid');
108
+ }
110
109
 
111
- if (responseBody.notification_type === AppleNotificationTypes.INITIAL_BUY) {
112
- // Find the cart to checkout
113
- const orderPayment = await modules.orders.payments.findOrderPaymentByContextData({
114
- context: {
115
- 'meta.transactionIdentifier': latestTransaction.transaction_id,
116
- },
117
- });
110
+ const transactions = responseBody?.unified_receipt?.latest_receipt_info; // eslint-disable-line
111
+ const latestTransaction = transactions[0];
118
112
 
119
- if (!orderPayment) throw new Error('Could not find any matching order payment');
120
- const order = await modules.orders.findOrder({
121
- orderId: orderPayment.orderId,
122
- });
113
+ if (responseBody.notification_type === AppleNotificationTypes.INITIAL_BUY) {
114
+ // Find the cart to checkout
115
+ const orderPayment = await modules.orders.payments.findOrderPaymentByContextData({
116
+ context: {
117
+ 'meta.transactionIdentifier': latestTransaction.transaction_id,
118
+ },
119
+ });
120
+
121
+ if (!orderPayment) throw new Error('Could not find any matching order payment');
122
+ const order = await modules.orders.findOrder({
123
+ orderId: orderPayment.orderId,
124
+ });
125
+
126
+ if (modules.orders.isCart(order)) {
127
+ // checkout if is cart, else just ignore because the cart is already checked out
128
+ // through submission of the receipt with GraphQL
129
+ const checkedOut = await modules.orders.checkout(
130
+ order._id,
131
+ {
132
+ paymentContext: {
133
+ receiptData: responseBody?.unified_receipt?.latest_receipt, // eslint-disable-line
134
+ },
135
+ },
136
+ resolvedContext,
137
+ );
138
+ const orderId = checkedOut._id;
139
+ const enrollment = await modules.enrollments.findEnrollment({
140
+ orderId,
141
+ });
142
+ await fixPeriods(
143
+ {
144
+ transactionId: latestTransaction.original_transaction_id,
145
+ transactions,
146
+ enrollmentId: enrollment._id,
147
+ orderId,
148
+ },
149
+ resolvedContext,
150
+ );
123
151
 
124
- if (modules.orders.isCart(order)) {
125
- // checkout if is cart, else just ignore because the cart is already checked out
126
- // through submission of the receipt with GraphQL
127
- const checkedOut = await modules.orders.checkout(
128
- order._id,
152
+ logger.info(`Apple IAP Webhook: Confirmed checkout for order ${checkedOut.orderNumber}`, {
153
+ orderId: checkedOut._id,
154
+ });
155
+ }
156
+ } else {
157
+ // Just store payment credentials, use the enrollments paymentProvider reference and
158
+ // let the job do the rest
159
+ const originalOrderPayment = await modules.orders.payments.findOrderPaymentByContextData({
160
+ context: {
161
+ 'meta.transactionIdentifier': latestTransaction.original_transaction_id,
162
+ },
163
+ });
164
+ if (!originalOrderPayment) throw new Error('Could not find any matching order payment');
165
+ const originalOrder = await modules.orders.findOrder({
166
+ orderId: originalOrderPayment.orderId,
167
+ });
168
+ const enrollment = await modules.enrollments.findEnrollment({
169
+ orderId: originalOrder._id,
170
+ });
171
+
172
+ await services.payment.registerPaymentCredentials(
173
+ enrollment.payment.paymentProviderId,
129
174
  {
130
175
  transactionContext: {
131
176
  receiptData: responseBody?.unified_receipt?.latest_receipt, // eslint-disable-line
@@ -133,97 +178,55 @@ useMiddlewareWithCurrentContext(APPLE_IAP_WEBHOOK_PATH, async (req, res) => {
133
178
  },
134
179
  resolvedContext,
135
180
  );
136
- const orderId = checkedOut._id;
137
- const enrollment = await modules.enrollments.findEnrollment({
138
- orderId,
139
- });
181
+
140
182
  await fixPeriods(
141
183
  {
142
184
  transactionId: latestTransaction.original_transaction_id,
143
185
  transactions,
144
186
  enrollmentId: enrollment._id,
145
- orderId,
187
+ orderId: originalOrder._id,
146
188
  },
147
189
  resolvedContext,
148
190
  );
149
191
 
150
- logger.info(`Apple IAP Webhook: Confirmed checkout for order ${checkedOut.orderNumber}`, {
151
- orderId: checkedOut._id,
152
- });
153
- }
154
- } else {
155
- // Just store payment credentials, use the enrollments paymentProvider reference and
156
- // let the job do the rest
157
- const originalOrderPayment = await modules.orders.payments.findOrderPaymentByContextData({
158
- context: {
159
- 'meta.transactionIdentifier': latestTransaction.original_transaction_id,
160
- },
161
- });
162
- if (!originalOrderPayment) throw new Error('Could not find any matching order payment');
163
- const originalOrder = await modules.orders.findOrder({
164
- orderId: originalOrderPayment.orderId,
165
- });
166
- const enrollment = await modules.enrollments.findEnrollment({
167
- orderId: originalOrder._id,
168
- });
169
-
170
- await services.payment.registerPaymentCredentials(
171
- enrollment.payment.paymentProviderId,
172
- {
173
- transactionContext: {
174
- receiptData: responseBody?.unified_receipt?.latest_receipt, // eslint-disable-line
175
- },
176
- },
177
- resolvedContext,
178
- );
179
-
180
- await fixPeriods(
181
- {
182
- transactionId: latestTransaction.original_transaction_id,
183
- transactions,
184
- enrollmentId: enrollment._id,
185
- orderId: originalOrder._id,
186
- },
187
- resolvedContext,
188
- );
189
-
190
- logger.info(
191
- `Apple IAP Webhook: Processed notification for ${latestTransaction.original_transaction_id} and type ${responseBody.notification_type}`,
192
- );
192
+ logger.info(
193
+ `Apple IAP Webhook: Processed notification for ${latestTransaction.original_transaction_id} and type ${responseBody.notification_type}`,
194
+ );
193
195
 
194
- if (responseBody.notification_type === AppleNotificationTypes.DID_RECOVER) {
195
- if (
196
- enrollment.status !== EnrollmentStatus.TERMINATED &&
197
- responseBody.auto_renew_status === 'false'
198
- ) {
199
- await modules.enrollments.terminateEnrollment(enrollment, {}, resolvedContext);
196
+ if (responseBody.notification_type === AppleNotificationTypes.DID_RECOVER) {
197
+ if (
198
+ enrollment.status !== EnrollmentStatus.TERMINATED &&
199
+ responseBody.auto_renew_status === 'false'
200
+ ) {
201
+ await modules.enrollments.terminateEnrollment(enrollment, {}, resolvedContext);
202
+ }
200
203
  }
201
- }
202
204
 
203
- if (responseBody.notification_type === AppleNotificationTypes.DID_CHANGE_RENEWAL_STATUS) {
204
- if (
205
- enrollment.status !== EnrollmentStatus.TERMINATED &&
206
- responseBody.auto_renew_status === 'false'
207
- ) {
208
- await modules.enrollments.terminateEnrollment(enrollment, {}, resolvedContext);
205
+ if (responseBody.notification_type === AppleNotificationTypes.DID_CHANGE_RENEWAL_STATUS) {
206
+ if (
207
+ enrollment.status !== EnrollmentStatus.TERMINATED &&
208
+ responseBody.auto_renew_status === 'false'
209
+ ) {
210
+ await modules.enrollments.terminateEnrollment(enrollment, {}, resolvedContext);
211
+ }
209
212
  }
213
+ logger.info(`Apple IAP Webhook: Updated enrollment from Apple`);
210
214
  }
211
- logger.info(`Apple IAP Webhook: Updated enrollment from Apple`);
212
- }
213
215
 
214
- res.writeHead(200);
215
- res.end();
216
- return;
217
- } catch (e) {
218
- logger.warn(`Apple IAP Webhook: ${e.message}`, e);
219
- res.writeHead(503);
220
- res.end(JSON.stringify(e));
221
- return;
216
+ res.writeHead(200);
217
+ res.end();
218
+ return;
219
+ } catch (e) {
220
+ logger.warn(`Apple IAP Webhook: ${e.message}`, e);
221
+ res.writeHead(503);
222
+ res.end(JSON.stringify(e));
223
+ return;
224
+ }
222
225
  }
223
- }
224
- res.writeHead(404);
225
- res.end();
226
- });
226
+ res.writeHead(404);
227
+ res.end();
228
+ });
229
+ };
227
230
 
228
231
  const AppleIAP: IPaymentAdapter = {
229
232
  ...PaymentAdapter,
@@ -1,3 +1,4 @@
1
- import './adapter';
1
+ import setupAppleIAP from './adapter';
2
2
 
3
+ export default setupAppleIAP;
3
4
  export { configureAppleTransactionsModule } from './module/configureAppleTransactionsModule';
@@ -29,10 +29,10 @@ const {
29
29
  BITY_BANK_ACCOUNT_NAME,
30
30
  BITY_BANK_ACCOUNT_ZIP,
31
31
  BITY_API_ENDPOINT = 'https://exchange.api.bity.com',
32
- BITY_OAUTH_INIT_PATH = '/graphql/bity-auth',
33
- BITY_OAUTH_REDIRECT_URI = 'http://localhost:4010/graphql/bity',
32
+ BITY_OAUTH_INIT_PATH = '/payment/bity-auth',
33
+ BITY_OAUTH_REDIRECT_URI = 'http://localhost:4010/payment/bity',
34
34
  BITY_OAUTH_STATE = 'unchained',
35
- BITY_OAUTH_PATH = '/graphql/bity',
35
+ BITY_OAUTH_PATH = '/payment/bity',
36
36
  } = process.env;
37
37
 
38
38
  const createBityAuth = () => {
@@ -185,56 +185,58 @@ const estimateBityOrder = async (data: any, context: Context) => {
185
185
  return response.json();
186
186
  };
187
187
 
188
- useMiddlewareWithCurrentContext(BITY_OAUTH_INIT_PATH, async (req, res) => {
189
- if (req.method === 'GET') {
190
- try {
191
- const resolvedContext = req.unchainedContext;
192
- await checkAction(resolvedContext, actions.managePaymentProviders);
193
-
194
- const bityAuthClient = createBityAuth();
195
- const uri = bityAuthClient.code.getUri();
196
- logger.info(`Bity Webhook: Login ${uri}`);
197
- res.writeHead(302, {
198
- Location: uri,
199
- });
200
- res.end();
201
- return;
202
- } catch (e) {
203
- logger.warn(`Bity Webhook: Failed with ${e.message}`);
204
- res.writeHead(503);
205
- res.end(JSON.stringify(e));
206
- return;
188
+ export default (app) => {
189
+ useMiddlewareWithCurrentContext(app, BITY_OAUTH_INIT_PATH, async (req, res) => {
190
+ if (req.method === 'GET') {
191
+ try {
192
+ const resolvedContext = req.unchainedContext;
193
+ await checkAction(resolvedContext, actions.managePaymentProviders);
194
+
195
+ const bityAuthClient = createBityAuth();
196
+ const uri = bityAuthClient.code.getUri();
197
+ logger.info(`Bity Webhook: Login ${uri}`);
198
+ res.writeHead(302, {
199
+ Location: uri,
200
+ });
201
+ res.end();
202
+ return;
203
+ } catch (e) {
204
+ logger.warn(`Bity Webhook: Failed with ${e.message}`);
205
+ res.writeHead(503);
206
+ res.end(JSON.stringify(e));
207
+ return;
208
+ }
207
209
  }
208
- }
209
- res.writeHead(404);
210
- res.end();
211
- });
212
-
213
- useMiddlewareWithCurrentContext(BITY_OAUTH_PATH, async (req, res, next) => {
214
- bodyParser.urlencoded({ extended: false })(req, res, next);
215
- });
216
-
217
- useMiddlewareWithCurrentContext(BITY_OAUTH_PATH, async (req, res) => {
218
- if (req.method === 'GET') {
219
- try {
220
- const resolvedContext = req.unchainedContext as Context;
221
- await checkAction(resolvedContext, actions.managePaymentProviders);
222
- const bityAuthClient = createBityAuth();
223
- const user = await bityAuthClient.code.getToken(req.originalUrl);
224
- await upsertBityCredentials(user, resolvedContext);
225
- res.writeHead(200);
226
- res.end('Bity Credentials Setup Complete');
227
- return;
228
- } catch (e) {
229
- logger.warn(`Bity Webhook: Failed with ${e.message}`);
230
- res.writeHead(503);
231
- res.end(JSON.stringify(e));
232
- return;
210
+ res.writeHead(404);
211
+ res.end();
212
+ });
213
+
214
+ useMiddlewareWithCurrentContext(app, BITY_OAUTH_PATH, async (req, res, next) => {
215
+ bodyParser.urlencoded({ extended: false })(req, res, next);
216
+ });
217
+
218
+ useMiddlewareWithCurrentContext(app, BITY_OAUTH_PATH, async (req, res) => {
219
+ if (req.method === 'GET') {
220
+ try {
221
+ const resolvedContext = req.unchainedContext as Context;
222
+ await checkAction(resolvedContext, actions.managePaymentProviders);
223
+ const bityAuthClient = createBityAuth();
224
+ const user = await bityAuthClient.code.getToken(req.originalUrl);
225
+ await upsertBityCredentials(user, resolvedContext);
226
+ res.writeHead(200);
227
+ res.end('Bity Credentials Setup Complete');
228
+ return;
229
+ } catch (e) {
230
+ logger.warn(`Bity Webhook: Failed with ${e.message}`);
231
+ res.writeHead(503);
232
+ res.end(JSON.stringify(e));
233
+ return;
234
+ }
233
235
  }
234
- }
235
- res.writeHead(404);
236
- res.end();
237
- });
236
+ res.writeHead(404);
237
+ res.end();
238
+ });
239
+ };
238
240
 
239
241
  let bityAuthClient;
240
242
  const loadToken = async (context: Context) => {
@@ -1,3 +1,4 @@
1
- import './adapter';
1
+ import setupBity from './adapter';
2
2
 
3
+ export default setupBity;
3
4
  export { configureBityModule } from './module/configureBityModule';