@unchainedshop/plugins 3.0.0-rc.13 → 3.0.0-rc.15

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 (268) hide show
  1. package/lib/files/gridfs/{gridfs-adapter.d.ts → adapter.d.ts} +2 -4
  2. package/lib/files/gridfs/adapter.d.ts.map +1 -0
  3. package/lib/files/gridfs/{gridfs-adapter.js → adapter.js} +1 -1
  4. package/lib/files/gridfs/adapter.js.map +1 -0
  5. package/lib/files/gridfs/handler-express.d.ts +10 -0
  6. package/lib/files/gridfs/handler-express.d.ts.map +1 -0
  7. package/lib/files/gridfs/{gridfs-webhook.js → handler-express.js} +3 -2
  8. package/lib/files/gridfs/handler-express.js.map +1 -0
  9. package/lib/files/gridfs/handler-fastify.d.ts +4 -0
  10. package/lib/files/gridfs/handler-fastify.d.ts.map +1 -0
  11. package/lib/files/gridfs/handler-fastify.js +91 -0
  12. package/lib/files/gridfs/handler-fastify.js.map +1 -0
  13. package/lib/files/gridfs/index.d.ts +4 -10
  14. package/lib/files/gridfs/index.d.ts.map +1 -1
  15. package/lib/files/gridfs/index.js +3 -27
  16. package/lib/files/gridfs/index.js.map +1 -1
  17. package/lib/files/gridfs/module.d.ts +26 -0
  18. package/lib/files/gridfs/module.d.ts.map +1 -0
  19. package/lib/files/gridfs/module.js +33 -0
  20. package/lib/files/gridfs/module.js.map +1 -0
  21. package/lib/files/minio/handler-express.d.ts +3 -0
  22. package/lib/files/minio/handler-express.d.ts.map +1 -0
  23. package/lib/files/minio/{minio-webhook.js → handler-express.js} +3 -2
  24. package/lib/files/minio/handler-express.js.map +1 -0
  25. package/lib/files/minio/handler-fastify.d.ts +4 -0
  26. package/lib/files/minio/handler-fastify.d.ts.map +1 -0
  27. package/lib/files/minio/handler-fastify.js +34 -0
  28. package/lib/files/minio/handler-fastify.js.map +1 -0
  29. package/lib/files/minio/{minio-adapter.d.ts → index.d.ts} +1 -1
  30. package/lib/files/minio/index.d.ts.map +1 -0
  31. package/lib/files/minio/{minio-adapter.js → index.js} +1 -1
  32. package/lib/files/minio/index.js.map +1 -0
  33. package/lib/payment/apple-iap/adapter.d.ts +1 -1
  34. package/lib/payment/apple-iap/adapter.d.ts.map +1 -1
  35. package/lib/payment/apple-iap/adapter.js +5 -155
  36. package/lib/payment/apple-iap/adapter.js.map +1 -1
  37. package/lib/payment/apple-iap/fix-periods.d.ts +8 -0
  38. package/lib/payment/apple-iap/fix-periods.d.ts.map +1 -0
  39. package/lib/payment/apple-iap/fix-periods.js +22 -0
  40. package/lib/payment/apple-iap/fix-periods.js.map +1 -0
  41. package/lib/payment/apple-iap/handler-express.d.ts +3 -0
  42. package/lib/payment/apple-iap/handler-express.d.ts.map +1 -0
  43. package/lib/payment/apple-iap/handler-express.js +110 -0
  44. package/lib/payment/apple-iap/handler-express.js.map +1 -0
  45. package/lib/payment/apple-iap/handler-fastify.d.ts +4 -0
  46. package/lib/payment/apple-iap/handler-fastify.d.ts.map +1 -0
  47. package/lib/payment/apple-iap/handler-fastify.js +104 -0
  48. package/lib/payment/apple-iap/handler-fastify.js.map +1 -0
  49. package/lib/payment/apple-iap/index.d.ts +3 -1
  50. package/lib/payment/apple-iap/index.d.ts.map +1 -1
  51. package/lib/payment/apple-iap/index.js +2 -1
  52. package/lib/payment/apple-iap/index.js.map +1 -1
  53. package/lib/payment/apple-iap/module.d.ts +22 -0
  54. package/lib/payment/apple-iap/module.d.ts.map +1 -0
  55. package/lib/payment/apple-iap/{module/configureAppleTransactionsModule.js → module.js} +7 -2
  56. package/lib/payment/apple-iap/module.js.map +1 -0
  57. package/lib/payment/apple-iap/verify-receipt.d.ts +5 -0
  58. package/lib/payment/apple-iap/verify-receipt.d.ts.map +1 -0
  59. package/lib/payment/apple-iap/verify-receipt.js +26 -0
  60. package/lib/payment/apple-iap/verify-receipt.js.map +1 -0
  61. package/lib/payment/cryptopay/handler-express.d.ts +3 -0
  62. package/lib/payment/cryptopay/handler-express.d.ts.map +1 -0
  63. package/lib/payment/cryptopay/{middleware.js → handler-express.js} +3 -2
  64. package/lib/payment/cryptopay/{middleware.js.map → handler-express.js.map} +1 -1
  65. package/lib/payment/cryptopay/handler-fastify.d.ts +4 -0
  66. package/lib/payment/cryptopay/handler-fastify.d.ts.map +1 -0
  67. package/lib/payment/cryptopay/handler-fastify.js +69 -0
  68. package/lib/payment/cryptopay/handler-fastify.js.map +1 -0
  69. package/lib/payment/cryptopay/index.d.ts +4 -4
  70. package/lib/payment/cryptopay/index.d.ts.map +1 -1
  71. package/lib/payment/cryptopay/index.js +3 -4
  72. package/lib/payment/cryptopay/index.js.map +1 -1
  73. package/lib/payment/cryptopay/module.d.ts +54 -0
  74. package/lib/payment/cryptopay/module.d.ts.map +1 -0
  75. package/lib/payment/cryptopay/{module/configureCryptopayModule.js → module.js} +8 -3
  76. package/lib/payment/cryptopay/module.js.map +1 -0
  77. package/lib/payment/cryptopay/plugin.js +1 -1
  78. package/lib/payment/cryptopay/plugin.js.map +1 -1
  79. package/lib/payment/datatrans-v2/{middleware.d.ts → handler-express.d.ts} +1 -1
  80. package/lib/payment/datatrans-v2/handler-express.d.ts.map +1 -0
  81. package/lib/payment/datatrans-v2/{middleware.js → handler-express.js} +2 -2
  82. package/lib/payment/datatrans-v2/handler-express.js.map +1 -0
  83. package/lib/payment/datatrans-v2/handler-fastify.d.ts +3 -0
  84. package/lib/payment/datatrans-v2/handler-fastify.d.ts.map +1 -0
  85. package/lib/payment/datatrans-v2/handler-fastify.js +66 -0
  86. package/lib/payment/datatrans-v2/handler-fastify.js.map +1 -0
  87. package/lib/payment/datatrans-v2/index.d.ts +1 -1
  88. package/lib/payment/datatrans-v2/index.d.ts.map +1 -1
  89. package/lib/payment/datatrans-v2/index.js +0 -1
  90. package/lib/payment/datatrans-v2/index.js.map +1 -1
  91. package/lib/payment/payrexx/{middleware.d.ts → handler-express.d.ts} +1 -1
  92. package/lib/payment/payrexx/handler-express.d.ts.map +1 -0
  93. package/lib/payment/payrexx/{middleware.js → handler-express.js} +2 -2
  94. package/lib/payment/payrexx/handler-express.js.map +1 -0
  95. package/lib/payment/payrexx/handler-fastify.d.ts +3 -0
  96. package/lib/payment/payrexx/handler-fastify.d.ts.map +1 -0
  97. package/lib/payment/payrexx/handler-fastify.js +87 -0
  98. package/lib/payment/payrexx/handler-fastify.js.map +1 -0
  99. package/lib/payment/payrexx/index.d.ts +1 -1
  100. package/lib/payment/payrexx/index.d.ts.map +1 -1
  101. package/lib/payment/payrexx/index.js +0 -1
  102. package/lib/payment/payrexx/index.js.map +1 -1
  103. package/lib/payment/postfinance-checkout/{middleware.d.ts → handler-express.d.ts} +1 -1
  104. package/lib/payment/postfinance-checkout/handler-express.d.ts.map +1 -0
  105. package/lib/payment/postfinance-checkout/{middleware.js → handler-express.js} +1 -1
  106. package/lib/payment/postfinance-checkout/handler-express.js.map +1 -0
  107. package/lib/payment/postfinance-checkout/handler-fastify.d.ts +3 -0
  108. package/lib/payment/postfinance-checkout/handler-fastify.d.ts.map +1 -0
  109. package/lib/payment/postfinance-checkout/handler-fastify.js +39 -0
  110. package/lib/payment/postfinance-checkout/handler-fastify.js.map +1 -0
  111. package/lib/payment/postfinance-checkout/index.d.ts +1 -1
  112. package/lib/payment/postfinance-checkout/index.d.ts.map +1 -1
  113. package/lib/payment/postfinance-checkout/index.js +0 -1
  114. package/lib/payment/postfinance-checkout/index.js.map +1 -1
  115. package/lib/payment/saferpay/adapter.d.ts +0 -1
  116. package/lib/payment/saferpay/adapter.d.ts.map +1 -1
  117. package/lib/payment/saferpay/adapter.js +0 -1
  118. package/lib/payment/saferpay/adapter.js.map +1 -1
  119. package/lib/payment/saferpay/{middleware.d.ts → handler-express.d.ts} +1 -1
  120. package/lib/payment/saferpay/handler-express.d.ts.map +1 -0
  121. package/lib/payment/saferpay/{middleware.js → handler-express.js} +2 -2
  122. package/lib/payment/saferpay/handler-express.js.map +1 -0
  123. package/lib/payment/saferpay/handler-fastify.d.ts +3 -0
  124. package/lib/payment/saferpay/handler-fastify.d.ts.map +1 -0
  125. package/lib/payment/saferpay/handler-fastify.js +56 -0
  126. package/lib/payment/saferpay/handler-fastify.js.map +1 -0
  127. package/lib/payment/saferpay/index.d.ts +3 -2
  128. package/lib/payment/saferpay/index.d.ts.map +1 -1
  129. package/lib/payment/saferpay/index.js +2 -2
  130. package/lib/payment/saferpay/index.js.map +1 -1
  131. package/lib/payment/saferpay/module.d.ts +24 -0
  132. package/lib/payment/saferpay/module.d.ts.map +1 -0
  133. package/lib/payment/saferpay/{module/configureSaferpayTransactionsModule.js → module.js} +8 -3
  134. package/lib/payment/saferpay/module.js.map +1 -0
  135. package/lib/payment/stripe/{middleware.d.ts → handler-express.d.ts} +1 -1
  136. package/lib/payment/stripe/handler-express.d.ts.map +1 -0
  137. package/lib/payment/stripe/{middleware.js → handler-express.js} +2 -2
  138. package/lib/payment/stripe/handler-express.js.map +1 -0
  139. package/lib/payment/stripe/handler-fastify.d.ts +7 -0
  140. package/lib/payment/stripe/handler-fastify.d.ts.map +1 -0
  141. package/lib/payment/stripe/handler-fastify.js +112 -0
  142. package/lib/payment/stripe/handler-fastify.js.map +1 -0
  143. package/lib/payment/stripe/index.d.ts +1 -1
  144. package/lib/payment/stripe/index.d.ts.map +1 -1
  145. package/lib/payment/stripe/index.js +0 -1
  146. package/lib/payment/stripe/index.js.map +1 -1
  147. package/lib/presets/all-express.d.ts +7 -0
  148. package/lib/presets/all-express.d.ts.map +1 -0
  149. package/lib/presets/all-express.js +27 -0
  150. package/lib/presets/all-express.js.map +1 -0
  151. package/lib/presets/all-fastify.d.ts +7 -0
  152. package/lib/presets/all-fastify.d.ts.map +1 -0
  153. package/lib/presets/all-fastify.js +64 -0
  154. package/lib/presets/all-fastify.js.map +1 -0
  155. package/lib/presets/all.d.ts +69 -0
  156. package/lib/presets/all.d.ts.map +1 -0
  157. package/lib/presets/all.js +30 -0
  158. package/lib/presets/all.js.map +1 -0
  159. package/lib/presets/base-express.js +2 -2
  160. package/lib/presets/base-express.js.map +1 -1
  161. package/lib/presets/base-fastify.d.ts +4 -0
  162. package/lib/presets/base-fastify.d.ts.map +1 -0
  163. package/lib/presets/base-fastify.js +18 -0
  164. package/lib/presets/base-fastify.js.map +1 -0
  165. package/lib/presets/{base-modules.d.ts → base.d.ts} +3 -7
  166. package/lib/presets/base.d.ts.map +1 -0
  167. package/lib/presets/{base-modules.js → base.js} +3 -9
  168. package/lib/presets/base.js.map +1 -0
  169. package/lib/presets/crypto-express.js +2 -2
  170. package/lib/presets/crypto-express.js.map +1 -1
  171. package/lib/presets/crypto-fastify.d.ts +4 -0
  172. package/lib/presets/crypto-fastify.d.ts.map +1 -0
  173. package/lib/presets/crypto-fastify.js +12 -0
  174. package/lib/presets/crypto-fastify.js.map +1 -0
  175. package/lib/presets/crypto.d.ts +8 -0
  176. package/lib/presets/crypto.d.ts.map +1 -0
  177. package/lib/presets/crypto.js +9 -0
  178. package/lib/presets/crypto.js.map +1 -0
  179. package/package.json +18 -14
  180. package/src/files/gridfs/{gridfs-adapter.ts → adapter.ts} +1 -3
  181. package/src/files/gridfs/{gridfs-webhook.ts → handler-express.ts} +5 -3
  182. package/src/files/gridfs/handler-fastify.ts +122 -0
  183. package/src/files/gridfs/index.ts +4 -29
  184. package/src/files/gridfs/module.ts +39 -0
  185. package/src/files/minio/{minio-webhook.ts → handler-express.ts} +3 -1
  186. package/src/files/minio/handler-fastify.ts +44 -0
  187. package/src/payment/apple-iap/adapter.ts +6 -193
  188. package/src/payment/apple-iap/fix-periods.ts +34 -0
  189. package/src/payment/apple-iap/handler-express.ts +134 -0
  190. package/src/payment/apple-iap/handler-fastify.ts +137 -0
  191. package/src/payment/apple-iap/index.ts +5 -1
  192. package/src/payment/apple-iap/{module/configureAppleTransactionsModule.ts → module.ts} +10 -2
  193. package/src/payment/apple-iap/verify-receipt.ts +27 -0
  194. package/src/payment/cryptopay/{middleware.ts → handler-express.ts} +5 -5
  195. package/src/payment/cryptopay/handler-fastify.ts +89 -0
  196. package/src/payment/cryptopay/index.ts +5 -4
  197. package/src/payment/cryptopay/{module/configureCryptopayModule.ts → module.ts} +11 -3
  198. package/src/payment/cryptopay/plugin.ts +3 -3
  199. package/src/payment/datatrans-v2/{middleware.ts → handler-express.ts} +1 -1
  200. package/src/payment/datatrans-v2/handler-fastify.ts +88 -0
  201. package/src/payment/datatrans-v2/index.ts +0 -2
  202. package/src/payment/payrexx/{middleware.ts → handler-express.ts} +1 -1
  203. package/src/payment/payrexx/handler-fastify.ts +105 -0
  204. package/src/payment/payrexx/index.ts +0 -2
  205. package/src/payment/postfinance-checkout/handler-fastify.ts +52 -0
  206. package/src/payment/postfinance-checkout/index.ts +0 -2
  207. package/src/payment/saferpay/adapter.ts +2 -4
  208. package/src/payment/saferpay/{middleware.ts → handler-express.ts} +3 -3
  209. package/src/payment/saferpay/handler-fastify.ts +75 -0
  210. package/src/payment/saferpay/index.ts +5 -2
  211. package/src/payment/saferpay/{module/configureSaferpayTransactionsModule.ts → module.ts} +11 -3
  212. package/src/payment/stripe/{middleware.ts → handler-express.ts} +1 -1
  213. package/src/payment/stripe/handler-fastify.ts +139 -0
  214. package/src/payment/stripe/index.ts +0 -2
  215. package/src/presets/all-express.ts +51 -0
  216. package/src/presets/all-fastify.ts +87 -0
  217. package/src/presets/all.ts +35 -0
  218. package/src/presets/base-express.ts +2 -2
  219. package/src/presets/base-fastify.ts +20 -0
  220. package/src/presets/{base-modules.ts → base.ts} +3 -17
  221. package/src/presets/crypto-express.ts +2 -2
  222. package/src/presets/crypto-fastify.ts +15 -0
  223. package/src/presets/crypto.ts +11 -0
  224. package/lib/files/gridfs/gridfs-adapter.d.ts.map +0 -1
  225. package/lib/files/gridfs/gridfs-adapter.js.map +0 -1
  226. package/lib/files/gridfs/gridfs-webhook.d.ts +0 -11
  227. package/lib/files/gridfs/gridfs-webhook.d.ts.map +0 -1
  228. package/lib/files/gridfs/gridfs-webhook.js.map +0 -1
  229. package/lib/files/minio/minio-adapter.d.ts.map +0 -1
  230. package/lib/files/minio/minio-adapter.js.map +0 -1
  231. package/lib/files/minio/minio-webhook.d.ts +0 -2
  232. package/lib/files/minio/minio-webhook.d.ts.map +0 -1
  233. package/lib/files/minio/minio-webhook.js.map +0 -1
  234. package/lib/payment/apple-iap/module/configureAppleTransactionsModule.d.ts +0 -9
  235. package/lib/payment/apple-iap/module/configureAppleTransactionsModule.d.ts.map +0 -1
  236. package/lib/payment/apple-iap/module/configureAppleTransactionsModule.js.map +0 -1
  237. package/lib/payment/cryptopay/middleware.d.ts +0 -2
  238. package/lib/payment/cryptopay/middleware.d.ts.map +0 -1
  239. package/lib/payment/cryptopay/module/configureCryptopayModule.d.ts +0 -25
  240. package/lib/payment/cryptopay/module/configureCryptopayModule.d.ts.map +0 -1
  241. package/lib/payment/cryptopay/module/configureCryptopayModule.js.map +0 -1
  242. package/lib/payment/datatrans-v2/middleware.d.ts.map +0 -1
  243. package/lib/payment/datatrans-v2/middleware.js.map +0 -1
  244. package/lib/payment/payrexx/middleware.d.ts.map +0 -1
  245. package/lib/payment/payrexx/middleware.js.map +0 -1
  246. package/lib/payment/postfinance-checkout/middleware.d.ts.map +0 -1
  247. package/lib/payment/postfinance-checkout/middleware.js.map +0 -1
  248. package/lib/payment/saferpay/middleware.d.ts.map +0 -1
  249. package/lib/payment/saferpay/middleware.js.map +0 -1
  250. package/lib/payment/saferpay/module/configureSaferpayTransactionsModule.d.ts +0 -10
  251. package/lib/payment/saferpay/module/configureSaferpayTransactionsModule.d.ts.map +0 -1
  252. package/lib/payment/saferpay/module/configureSaferpayTransactionsModule.js.map +0 -1
  253. package/lib/payment/stripe/middleware.d.ts.map +0 -1
  254. package/lib/payment/stripe/middleware.js.map +0 -1
  255. package/lib/plugins-index.d.ts +0 -18
  256. package/lib/plugins-index.d.ts.map +0 -1
  257. package/lib/plugins-index.js +0 -52
  258. package/lib/plugins-index.js.map +0 -1
  259. package/lib/presets/base-modules.d.ts.map +0 -1
  260. package/lib/presets/base-modules.js.map +0 -1
  261. package/lib/presets/crypto-modules.d.ts +0 -11
  262. package/lib/presets/crypto-modules.d.ts.map +0 -1
  263. package/lib/presets/crypto-modules.js +0 -14
  264. package/lib/presets/crypto-modules.js.map +0 -1
  265. package/src/plugins-index.ts +0 -90
  266. package/src/presets/crypto-modules.ts +0 -23
  267. /package/src/files/minio/{minio-adapter.ts → index.ts} +0 -0
  268. /package/src/payment/postfinance-checkout/{middleware.ts → handler-express.ts} +0 -0
package/package.json CHANGED
@@ -1,10 +1,9 @@
1
1
  {
2
2
  "name": "@unchainedshop/plugins",
3
- "version": "3.0.0-rc.13",
3
+ "version": "3.0.0-rc.15",
4
4
  "main": "lib/plugins-index.js",
5
5
  "types": "lib/plugins-index.d.ts",
6
6
  "exports": {
7
- ".": "./lib/plugins-index.js",
8
7
  "./*": "./lib/*"
9
8
  },
10
9
  "type": "module",
@@ -36,22 +35,23 @@
36
35
  "homepage": "https://github.com/unchainedshop/unchained#readme",
37
36
  "dependencies": {
38
37
  "@breejs/later": "^4.2.0",
39
- "@unchainedshop/api": "^3.0.0-rc.13",
40
- "@unchainedshop/core-delivery": "^3.0.0-rc.13",
41
- "@unchainedshop/core-enrollments": "^3.0.0-rc.13",
42
- "@unchainedshop/core-orders": "^3.0.0-rc.13",
43
- "@unchainedshop/core-payment": "^3.0.0-rc.13",
44
- "@unchainedshop/core-products": "^3.0.0-rc.13",
45
- "@unchainedshop/core-warehousing": "^3.0.0-rc.13",
46
- "@unchainedshop/core-worker": "^3.0.0-rc.13",
47
- "@unchainedshop/events": "^3.0.0-rc.13",
48
- "@unchainedshop/file-upload": "^3.0.0-rc.13",
49
- "@unchainedshop/logger": "^3.0.0-rc.13",
50
- "@unchainedshop/utils": "^3.0.0-rc.13",
38
+ "@unchainedshop/api": "^3.0.0-rc.15",
39
+ "@unchainedshop/core-delivery": "^3.0.0-rc.15",
40
+ "@unchainedshop/core-enrollments": "^3.0.0-rc.15",
41
+ "@unchainedshop/core-orders": "^3.0.0-rc.15",
42
+ "@unchainedshop/core-payment": "^3.0.0-rc.15",
43
+ "@unchainedshop/core-products": "^3.0.0-rc.15",
44
+ "@unchainedshop/core-warehousing": "^3.0.0-rc.15",
45
+ "@unchainedshop/core-worker": "^3.0.0-rc.15",
46
+ "@unchainedshop/events": "^3.0.0-rc.15",
47
+ "@unchainedshop/file-upload": "^3.0.0-rc.15",
48
+ "@unchainedshop/logger": "^3.0.0-rc.15",
49
+ "@unchainedshop/utils": "^3.0.0-rc.15",
51
50
  "event-iterator": "^2.0.0",
52
51
  "JSONStream": "^1.3.5"
53
52
  },
54
53
  "peerDependencies": {
54
+ "fastify": ">= 5.2 < 6",
55
55
  "@aws-sdk/client-eventbridge": ">= 3.714 < 4",
56
56
  "@paypal/checkout-server-sdk": "1.x",
57
57
  "@redis/client": "1.x",
@@ -97,6 +97,9 @@
97
97
  "express": {
98
98
  "optional": true
99
99
  },
100
+ "fastify": {
101
+ "optional": true
102
+ },
100
103
  "mime-types": {
101
104
  "optional": true
102
105
  },
@@ -143,6 +146,7 @@
143
146
  "ethers": "^6.13.4",
144
147
  "expiry-map": "^2.0.0",
145
148
  "express": "^5.0.1",
149
+ "fastify": "^5.2.0",
146
150
  "jest": "^29.7.0",
147
151
  "mime-types": "^2.1.35",
148
152
  "minio": "^8.0.3",
@@ -26,9 +26,7 @@ const bufferToStream = (buffer: any) => {
26
26
 
27
27
  export const GridFSAdapter: IFileAdapter<
28
28
  UnchainedCore & {
29
- modules: {
30
- gridfsFileUploads: GridFSFileUploadsModule;
31
- };
29
+ modules: GridFSFileUploadsModule;
32
30
  }
33
31
  > = {
34
32
  key: 'shop.unchained.file-upload-plugin.gridfs',
@@ -3,7 +3,7 @@ import { PassThrough } from 'node:stream';
3
3
  import { buildHashedFilename } from '@unchainedshop/file-upload';
4
4
  import express from 'express';
5
5
  import sign from './sign.js';
6
- import { configureGridFSFileUploadModule } from './index.js';
6
+ import { GridFSFileUploadsModule } from './module.js';
7
7
  import { Context } from '@unchainedshop/api';
8
8
  import { createLogger } from '@unchainedshop/logger';
9
9
  import { getFileAdapter } from '@unchainedshop/core-files';
@@ -12,10 +12,10 @@ const { ROOT_URL } = process.env;
12
12
 
13
13
  const logger = createLogger('unchained:plugins:gridfs');
14
14
 
15
- export const gridfsHandler = async (
15
+ const gridfsHandler = async (
16
16
  req: express.Request & {
17
17
  unchainedContext: Context & {
18
- modules: { gridfsFileUploads: ReturnType<typeof configureGridFSFileUploadModule> };
18
+ modules: GridFSFileUploadsModule;
19
19
  };
20
20
  },
21
21
  res: express.Response,
@@ -127,3 +127,5 @@ export const gridfsHandler = async (
127
127
  }
128
128
  }
129
129
  };
130
+
131
+ export default gridfsHandler;
@@ -0,0 +1,122 @@
1
+ import { pipeline } from 'node:stream/promises';
2
+ import { PassThrough } from 'node:stream';
3
+ import { FastifyRequest, RouteHandlerMethod } from 'fastify';
4
+ import { buildHashedFilename } from '@unchainedshop/file-upload';
5
+ import sign from './sign.js';
6
+ import { GridFSFileUploadsModule } from './module.js';
7
+ import { Context } from '@unchainedshop/api';
8
+ import { createLogger } from '@unchainedshop/logger';
9
+ import { getFileAdapter } from '@unchainedshop/core-files';
10
+
11
+ const logger = createLogger('unchained:plugins:gridfs');
12
+
13
+ const gridfsHandler: RouteHandlerMethod = async (
14
+ req: FastifyRequest & {
15
+ unchainedContext: Context & {
16
+ modules: GridFSFileUploadsModule;
17
+ };
18
+ },
19
+ reply,
20
+ ) => {
21
+ try {
22
+ const { services, modules } = req.unchainedContext;
23
+ const { directoryName, fileName } = req.params as any;
24
+
25
+ /* This is a file upload endpoint, and thus we need to allow CORS.
26
+ else we'd need proxies for all kinds of things for storefronts */
27
+ reply.header('Access-Control-Allow-Methods', 'GET, PUT');
28
+ reply.header('Access-Control-Allow-Headers', 'content-type');
29
+ reply.header('Access-Control-Allow-Origin', '*');
30
+
31
+ if (req.method === 'OPTIONS') {
32
+ reply.status(200);
33
+ return reply.send();
34
+ }
35
+
36
+ if (req.method === 'PUT') {
37
+ const { s: signature, e: expiryTimestamp } = req.query as Record<string, string>;
38
+ const expiryDate = new Date(parseInt(expiryTimestamp as string, 10));
39
+ const fileId = await buildHashedFilename(directoryName, fileName, expiryDate);
40
+ if ((await sign(directoryName, fileId, expiryDate.getTime())) === signature) {
41
+ const file = await modules.files.findFile({ fileId });
42
+ if (file.expires === null) {
43
+ reply.status(400);
44
+ return reply.send('File already linked');
45
+ }
46
+ // If the type is octet-stream, prefer mimetype lookup from the filename
47
+ // Else prefer the content-type header
48
+ const type =
49
+ req.headers['content-type'] === 'application/octet-stream'
50
+ ? file.type || (req.headers['content-type'] as string)
51
+ : (req.headers['content-type'] as string) || file.type;
52
+
53
+ const writeStream = await modules.gridfsFileUploads.createWriteStream(
54
+ directoryName,
55
+ fileId,
56
+ fileName,
57
+ { 'content-type': type },
58
+ );
59
+
60
+ await pipeline(req.raw, new PassThrough(), writeStream);
61
+
62
+ const { length } = writeStream;
63
+ await services.files.linkFile({ fileId, size: length, type });
64
+
65
+ reply.status(200);
66
+ return reply.send();
67
+ }
68
+
69
+ reply.status(403);
70
+ return reply.send();
71
+ }
72
+
73
+ if (req.method === 'GET') {
74
+ const fileId = fileName;
75
+ const { s: signature, e: expiryTimestamp } = req.query as Record<string, string>;
76
+ const file = await modules.gridfsFileUploads.getFileInfo(directoryName, fileId);
77
+ const fileDocument = await modules.files.findFile({ fileId });
78
+ if (fileDocument?.meta?.isPrivate) {
79
+ const expiry = parseInt(expiryTimestamp as string, 10);
80
+ if (expiry <= Date.now()) {
81
+ reply.status(403);
82
+ return reply.send('Access restricted: Expired.');
83
+ }
84
+
85
+ const fileUploadAdapter = getFileAdapter();
86
+ const signedUrl = await fileUploadAdapter.createDownloadURL(fileDocument, expiry);
87
+
88
+ if (new URL(signedUrl, 'file://').searchParams.get('s') !== signature) {
89
+ reply.status(403);
90
+ return reply.send('Access restricted: Invalid signature.');
91
+ }
92
+ }
93
+
94
+ if (file?.metadata?.['content-type']) {
95
+ reply.header('content-type', file.metadata['content-type']);
96
+ }
97
+ if (file?.length) {
98
+ reply.header('content-length', file?.length.toString());
99
+ }
100
+
101
+ const readStream = await modules.gridfsFileUploads.createReadStream(directoryName, fileId);
102
+
103
+ reply.status(200);
104
+ return reply.send(readStream);
105
+ }
106
+
107
+ reply.status(404);
108
+ return reply.send();
109
+ } catch (e) {
110
+ if (e.code === 'ENOENT') {
111
+ logger.warn(e);
112
+ reply.status(404);
113
+ return reply.send({ name: e.name, code: e.code, message: e.message });
114
+ } else {
115
+ logger.warn(e);
116
+ reply.status(504);
117
+ return reply.send({ name: e.name, code: e.code, message: e.message });
118
+ }
119
+ }
120
+ };
121
+
122
+ export default gridfsHandler;
@@ -1,31 +1,6 @@
1
- import { mongodb } from '@unchainedshop/mongodb';
1
+ import './adapter.js';
2
2
 
3
- export const configureGridFSFileUploadModule = ({ db }) => {
4
- // eslint-disable-next-line
5
- let { GridFSBucket } = mongodb;
3
+ import gridfsModules, { type GridFSFileUploadsModule } from './module.js';
6
4
 
7
- return {
8
- createWriteStream: async (directoryName, fileId, fileName, metadata) => {
9
- const options = { bucketName: `file_uploads_${directoryName}` };
10
- const bucket = new GridFSBucket(db, options);
11
- return bucket.openUploadStreamWithId(fileId, fileName, { metadata });
12
- },
13
- getFileInfo: async (directoryName, fileId) => {
14
- const options = { bucketName: `file_uploads_${directoryName}` };
15
- const bucket = new GridFSBucket(db, options);
16
- return bucket.find({ _id: fileId }).next();
17
- },
18
- createReadStream: async (directoryName, fileId) => {
19
- const options = { bucketName: `file_uploads_${directoryName}` };
20
- const bucket = new GridFSBucket(db, options);
21
- return bucket.openDownloadStream(fileId);
22
- },
23
- removeFileFromBucket: async (directoryName, fileId) => {
24
- const options = { bucketName: `file_uploads_${directoryName}` };
25
- const bucket = new GridFSBucket(db, options);
26
- return bucket.delete(fileId);
27
- },
28
- };
29
- };
30
-
31
- export type GridFSFileUploadsModule = ReturnType<typeof configureGridFSFileUploadModule>;
5
+ export type { GridFSFileUploadsModule };
6
+ export default gridfsModules;
@@ -0,0 +1,39 @@
1
+ import { mongodb } from '@unchainedshop/mongodb';
2
+
3
+ export const configureGridFSFileUploadModule = ({ db }) => {
4
+ // eslint-disable-next-line
5
+ let { GridFSBucket } = mongodb;
6
+
7
+ return {
8
+ createWriteStream: async (directoryName, fileId, fileName, metadata) => {
9
+ const options = { bucketName: `file_uploads_${directoryName}` };
10
+ const bucket = new GridFSBucket(db, options);
11
+ return bucket.openUploadStreamWithId(fileId, fileName, { metadata });
12
+ },
13
+ getFileInfo: async (directoryName, fileId) => {
14
+ const options = { bucketName: `file_uploads_${directoryName}` };
15
+ const bucket = new GridFSBucket(db, options);
16
+ return bucket.find({ _id: fileId }).next();
17
+ },
18
+ createReadStream: async (directoryName, fileId) => {
19
+ const options = { bucketName: `file_uploads_${directoryName}` };
20
+ const bucket = new GridFSBucket(db, options);
21
+ return bucket.openDownloadStream(fileId);
22
+ },
23
+ removeFileFromBucket: async (directoryName, fileId) => {
24
+ const options = { bucketName: `file_uploads_${directoryName}` };
25
+ const bucket = new GridFSBucket(db, options);
26
+ return bucket.delete(fileId);
27
+ },
28
+ };
29
+ };
30
+
31
+ export default {
32
+ gridfsFileUploads: {
33
+ configure: configureGridFSFileUploadModule,
34
+ },
35
+ };
36
+
37
+ export type GridFSFileUploadsModule = {
38
+ gridfsFileUploads: ReturnType<typeof configureGridFSFileUploadModule>;
39
+ };
@@ -9,7 +9,7 @@ const isAuthorized = ({ authorization = '' }) => {
9
9
  return type === 'Bearer' && token === MINIO_WEBHOOK_AUTH_TOKEN;
10
10
  };
11
11
 
12
- export const minioHandler = async (req, res) => {
12
+ const minioHandler = async (req, res) => {
13
13
  try {
14
14
  if (req.method === 'POST' && req.body) {
15
15
  const { headers } = req;
@@ -34,3 +34,5 @@ export const minioHandler = async (req, res) => {
34
34
  res.end(JSON.stringify({ name: e.name, code: e.code, message: e.message }));
35
35
  }
36
36
  };
37
+
38
+ export default minioHandler;
@@ -0,0 +1,44 @@
1
+ import { Context } from '@unchainedshop/api';
2
+ import { createLogger } from '@unchainedshop/logger';
3
+ import { FastifyRequest, RouteHandlerMethod } from 'fastify';
4
+
5
+ const logger = createLogger('unchained:plugins:minio');
6
+
7
+ const { MINIO_WEBHOOK_AUTH_TOKEN } = process.env;
8
+
9
+ const isAuthorized = ({ authorization = '' }) => {
10
+ const [type, token] = authorization.split(' ');
11
+ return type === 'Bearer' && token === MINIO_WEBHOOK_AUTH_TOKEN;
12
+ };
13
+
14
+ const minioHandler: RouteHandlerMethod = async (
15
+ req: FastifyRequest & {
16
+ unchainedContext: Context;
17
+ },
18
+ res,
19
+ ) => {
20
+ try {
21
+ if (req.body) {
22
+ const { headers } = req;
23
+ const { Records = [], EventName } = req.body as Record<string, any>;
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 });
31
+ res.status(200);
32
+ return res.send();
33
+ }
34
+ }
35
+ res.status(404);
36
+ return res.send();
37
+ } catch (e) {
38
+ logger.error(e);
39
+ res.status(503);
40
+ return res.send(JSON.stringify({ name: e.name, code: e.code, message: e.message }));
41
+ }
42
+ };
43
+
44
+ export default minioHandler;
@@ -1,196 +1,11 @@
1
- import { Context } from '@unchainedshop/api';
2
- import { EnrollmentStatus } from '@unchainedshop/core-enrollments';
3
1
  import { IPaymentAdapter, PaymentAdapter, PaymentDirector, PaymentError } from '@unchainedshop/core';
4
2
  import { createLogger } from '@unchainedshop/logger';
5
- import { UnchainedCore } from '@unchainedshop/core';
6
- import { AppleTransactionsModule } from './module/configureAppleTransactionsModule.js';
3
+ import { AppleTransactionsModule } from './module.js';
4
+ import { verifyReceipt } from './verify-receipt.js';
7
5
 
8
6
  const logger = createLogger('unchained:core-payment:iap');
9
7
 
10
- const { APPLE_IAP_SHARED_SECRET, APPLE_IAP_ENVIRONMENT = 'sandbox' } = process.env;
11
-
12
- // https://developer.apple.com/documentation/storekit/in-app_purchase/validating_receipts_with_the_app_store
13
- const environments = {
14
- sandbox: 'https://sandbox.itunes.apple.com/verifyReceipt',
15
- production: 'https://buy.itunes.apple.com/verifyReceipt',
16
- };
17
-
18
- const verifyReceipt = async ({ receiptData, password }): Promise<any> => {
19
- const payload: any = {
20
- 'receipt-data': receiptData,
21
- };
22
- if (password) {
23
- payload.password = password;
24
- }
25
- const result = await fetch(environments[APPLE_IAP_ENVIRONMENT], {
26
- body: JSON.stringify(payload),
27
- method: 'POST',
28
- // eslint-disable-next-line
29
- // @ts-ignore
30
- duplex: 'half',
31
- headers: {
32
- 'Content-Type': 'application/json',
33
- },
34
- });
35
- return result.json();
36
- };
37
-
38
- const AppleNotificationTypes = {
39
- INITIAL_BUY: 'INITIAL_BUY',
40
- DID_RECOVER: 'DID_RECOVER',
41
- DID_CHANGE_RENEWAL_STATUS: 'DID_CHANGE_RENEWAL_STATUS',
42
- DID_FAIL_TO_RENEW: 'DID_FAIL_TO_RENEW',
43
- DID_CHANGE_RENEWAL_PREF: 'DID_CHANGE_RENEWAL_PREF',
44
- };
45
-
46
- const fixPeriods = async (
47
- { transactionId, enrollmentId, orderId, transactions },
48
- unchainedAPI: UnchainedCore,
49
- ) => {
50
- const relevantTransactions = transactions.filter(
51
- // eslint-disable-next-line
52
- ({ original_transaction_id }) => {
53
- return original_transaction_id === transactionId; // eslint-disable-line
54
- },
55
- );
56
-
57
- const adjustedEnrollmentPeriods = relevantTransactions
58
- .map((transaction) => {
59
- return {
60
- isTrial: transaction.is_trial_period === 'true', // eslint-disable-line
61
- start: new Date(parseInt(transaction.purchase_date_ms, 10)),
62
- end: new Date(parseInt(transaction.expires_date_ms, 10)),
63
- orderId: transaction.transaction_id === transactionId ? orderId : null,
64
- };
65
- })
66
- .toSorted((left, right) => {
67
- return left.end.getTime() - right.end.getTime();
68
- });
69
-
70
- await unchainedAPI.modules.enrollments.removeEnrollmentPeriodByOrderId(enrollmentId, orderId);
71
-
72
- return Promise.all(
73
- adjustedEnrollmentPeriods.map((period) =>
74
- unchainedAPI.modules.enrollments.addEnrollmentPeriod(enrollmentId, period),
75
- ),
76
- );
77
- };
78
-
79
- export const appleIAPHandler = async (req, res) => {
80
- if (req.method === 'POST') {
81
- try {
82
- const resolvedContext = req.unchainedContext as Context;
83
- const { modules, services } = resolvedContext;
84
- const responseBody = req.body || {};
85
- if (responseBody.password !== APPLE_IAP_SHARED_SECRET) {
86
- throw new Error('shared secret not valid');
87
- }
88
-
89
- const transactions = responseBody?.unified_receipt?.latest_receipt_info; // eslint-disable-line
90
- const latestTransaction = transactions[0];
91
-
92
- if (responseBody.notification_type === AppleNotificationTypes.INITIAL_BUY) {
93
- // Find the cart to checkout
94
- const orderPayment = await modules.orders.payments.findOrderPaymentByContextData({
95
- context: {
96
- 'meta.transactionIdentifier': latestTransaction.transaction_id,
97
- },
98
- });
99
-
100
- if (!orderPayment) throw new Error('Could not find any matching order payment');
101
-
102
- const order = await services.orders.checkoutOrder(orderPayment.orderId, {
103
- paymentContext: {
104
- receiptData: responseBody?.unified_receipt?.latest_receipt, // eslint-disable-line
105
- },
106
- });
107
- const orderId = order._id;
108
- const enrollment = await modules.enrollments.findEnrollment({
109
- orderId,
110
- });
111
- await fixPeriods(
112
- {
113
- transactionId: latestTransaction.original_transaction_id,
114
- transactions,
115
- enrollmentId: enrollment._id,
116
- orderId,
117
- },
118
- resolvedContext,
119
- );
120
-
121
- logger.info(`Apple IAP Webhook: Confirmed checkout for order ${order.orderNumber}`, {
122
- orderId: order._id,
123
- });
124
- } else {
125
- // Just store payment credentials, use the enrollments paymentProvider reference and
126
- // let the job do the rest
127
- const originalOrderPayment = await modules.orders.payments.findOrderPaymentByContextData({
128
- context: {
129
- 'meta.transactionIdentifier': latestTransaction.original_transaction_id,
130
- },
131
- });
132
- if (!originalOrderPayment) throw new Error('Could not find any matching order payment');
133
- const originalOrder = await modules.orders.findOrder({
134
- orderId: originalOrderPayment.orderId,
135
- });
136
- const enrollment = await modules.enrollments.findEnrollment({
137
- orderId: originalOrder._id,
138
- });
139
-
140
- await services.orders.registerPaymentCredentials(enrollment.payment.paymentProviderId, {
141
- transactionContext: {
142
- receiptData: responseBody?.unified_receipt?.latest_receipt, // eslint-disable-line
143
- },
144
- userId: enrollment.userId,
145
- });
146
-
147
- await fixPeriods(
148
- {
149
- transactionId: latestTransaction.original_transaction_id,
150
- transactions,
151
- enrollmentId: enrollment._id,
152
- orderId: originalOrder._id,
153
- },
154
- resolvedContext,
155
- );
156
-
157
- logger.info(
158
- `Apple IAP Webhook: Processed notification for ${latestTransaction.original_transaction_id} and type ${responseBody.notification_type}`,
159
- );
160
-
161
- if (responseBody.notification_type === AppleNotificationTypes.DID_RECOVER) {
162
- if (
163
- enrollment.status !== EnrollmentStatus.TERMINATED &&
164
- responseBody.auto_renew_status === 'false'
165
- ) {
166
- await services.enrollments.terminateEnrollment(enrollment);
167
- }
168
- }
169
-
170
- if (responseBody.notification_type === AppleNotificationTypes.DID_CHANGE_RENEWAL_STATUS) {
171
- if (
172
- enrollment.status !== EnrollmentStatus.TERMINATED &&
173
- responseBody.auto_renew_status === 'false'
174
- ) {
175
- await services.enrollments.terminateEnrollment(enrollment);
176
- }
177
- }
178
- logger.info(`Apple IAP Webhook: Updated enrollment from Apple`);
179
- }
180
-
181
- res.writeHead(200);
182
- res.end();
183
- return;
184
- } catch (e) {
185
- logger.warn(`Apple IAP Webhook: ${e.message}`, e);
186
- res.writeHead(503);
187
- res.end(JSON.stringify({ name: e.name, code: e.code, message: e.message }));
188
- return;
189
- }
190
- }
191
- res.writeHead(404);
192
- res.end();
193
- };
8
+ const { APPLE_IAP_SHARED_SECRET } = process.env;
194
9
 
195
10
  const AppleIAP: IPaymentAdapter = {
196
11
  ...PaymentAdapter,
@@ -205,7 +20,7 @@ const AppleIAP: IPaymentAdapter = {
205
20
  },
206
21
 
207
22
  actions: (params, context) => {
208
- const { modules } = context;
23
+ const { order, modules } = context as typeof context & { modules: AppleTransactionsModule };
209
24
 
210
25
  const adapterActions = {
211
26
  ...PaymentAdapter.actions(params, context),
@@ -266,10 +81,8 @@ const AppleIAP: IPaymentAdapter = {
266
81
 
267
82
  // eslint-disable-next-line
268
83
  async charge(transactionContext) {
269
- const { order } = context;
270
84
  const { meta, paymentCredentials, receiptData } = transactionContext || {};
271
85
  const { transactionIdentifier } = meta || {};
272
- const appleTransactions = (context.modules as any).appleTransactions as AppleTransactionsModule;
273
86
 
274
87
  if (!transactionIdentifier) {
275
88
  throw new Error('Apple IAP Plugin: You have to set the transaction id on the order payment');
@@ -324,13 +137,13 @@ const AppleIAP: IPaymentAdapter = {
324
137
  throw new Error('Apple IAP Plugin: Product in order does not match transaction');
325
138
 
326
139
  const alreadyProcessedTransaction =
327
- await appleTransactions.findTransactionById(transactionIdentifier);
140
+ await modules.appleTransactions.findTransactionById(transactionIdentifier);
328
141
 
329
142
  if (alreadyProcessedTransaction)
330
143
  throw new Error('Apple IAP Plugin: Transaction already processed');
331
144
 
332
145
  // All good
333
- await appleTransactions.createTransaction({
146
+ await modules.appleTransactions.createTransaction({
334
147
  _id: transactionIdentifier,
335
148
  matchedTransaction,
336
149
  orderId: order._id,
@@ -0,0 +1,34 @@
1
+ import { UnchainedCore } from '@unchainedshop/core';
2
+
3
+ export const fixPeriods = async (
4
+ { transactionId, enrollmentId, orderId, transactions },
5
+ unchainedAPI: UnchainedCore,
6
+ ) => {
7
+ const relevantTransactions = transactions.filter(
8
+ // eslint-disable-next-line
9
+ ({ original_transaction_id }) => {
10
+ return original_transaction_id === transactionId; // eslint-disable-line
11
+ },
12
+ );
13
+
14
+ const adjustedEnrollmentPeriods = relevantTransactions
15
+ .map((transaction) => {
16
+ return {
17
+ isTrial: transaction.is_trial_period === 'true', // eslint-disable-line
18
+ start: new Date(parseInt(transaction.purchase_date_ms, 10)),
19
+ end: new Date(parseInt(transaction.expires_date_ms, 10)),
20
+ orderId: transaction.transaction_id === transactionId ? orderId : null,
21
+ };
22
+ })
23
+ .toSorted((left, right) => {
24
+ return left.end.getTime() - right.end.getTime();
25
+ });
26
+
27
+ await unchainedAPI.modules.enrollments.removeEnrollmentPeriodByOrderId(enrollmentId, orderId);
28
+
29
+ return Promise.all(
30
+ adjustedEnrollmentPeriods.map((period) =>
31
+ unchainedAPI.modules.enrollments.addEnrollmentPeriod(enrollmentId, period),
32
+ ),
33
+ );
34
+ };