@unchainedshop/plugins 4.0.0-rc.15 → 4.0.0-rc.17

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 (302) hide show
  1. package/lib/accounts/google-oauth.d.ts +4 -0
  2. package/lib/accounts/google-oauth.d.ts.map +1 -0
  3. package/lib/accounts/google-oauth.js +145 -0
  4. package/lib/accounts/google-oauth.js.map +1 -0
  5. package/lib/accounts/linkedin-oauth.d.ts +4 -0
  6. package/lib/accounts/linkedin-oauth.d.ts.map +1 -0
  7. package/lib/accounts/linkedin-oauth.js +82 -0
  8. package/lib/accounts/linkedin-oauth.js.map +1 -0
  9. package/lib/delivery/send-message.js.map +1 -1
  10. package/lib/enrollments/licensed.js +15 -2
  11. package/lib/enrollments/licensed.js.map +1 -1
  12. package/lib/files/gridfs/adapter.js +1 -1
  13. package/lib/files/gridfs/adapter.js.map +1 -1
  14. package/lib/files/gridfs/gridfs-adapter.d.ts +3 -0
  15. package/lib/files/gridfs/gridfs-adapter.d.ts.map +1 -0
  16. package/lib/files/gridfs/gridfs-adapter.js +97 -0
  17. package/lib/files/gridfs/gridfs-adapter.js.map +1 -0
  18. package/lib/files/gridfs/gridfs-webhook.d.ts +11 -0
  19. package/lib/files/gridfs/gridfs-webhook.d.ts.map +1 -0
  20. package/lib/files/gridfs/gridfs-webhook.js +84 -0
  21. package/lib/files/gridfs/gridfs-webhook.js.map +1 -0
  22. package/lib/files/gridfs/handler-express.d.ts.map +1 -1
  23. package/lib/files/gridfs/handler-express.js +17 -24
  24. package/lib/files/gridfs/handler-express.js.map +1 -1
  25. package/lib/files/gridfs/handler-fastify.d.ts.map +1 -1
  26. package/lib/files/gridfs/handler-fastify.js +45 -11
  27. package/lib/files/gridfs/handler-fastify.js.map +1 -1
  28. package/lib/files/gridfs/module.d.ts +2 -2
  29. package/lib/files/minio/handler-express.d.ts.map +1 -1
  30. package/lib/files/minio/handler-express.js +4 -7
  31. package/lib/files/minio/handler-express.js.map +1 -1
  32. package/lib/files/minio/handler-fastify.js +2 -2
  33. package/lib/files/minio/handler-fastify.js.map +1 -1
  34. package/lib/files/minio/index.d.ts +1 -1
  35. package/lib/files/minio/index.d.ts.map +1 -1
  36. package/lib/files/minio/index.js +3 -3
  37. package/lib/files/minio/index.js.map +1 -1
  38. package/lib/files/minio/minio-adapter.d.ts +6 -0
  39. package/lib/files/minio/minio-adapter.d.ts.map +1 -0
  40. package/lib/files/minio/minio-adapter.js +181 -0
  41. package/lib/files/minio/minio-adapter.js.map +1 -0
  42. package/lib/files/minio/minio-webhook.d.ts +2 -0
  43. package/lib/files/minio/minio-webhook.d.ts.map +1 -0
  44. package/lib/files/minio/minio-webhook.js +33 -0
  45. package/lib/files/minio/minio-webhook.js.map +1 -0
  46. package/lib/filters/local-search.js +1 -1
  47. package/lib/filters/local-search.js.map +1 -1
  48. package/lib/payment/apple-iap/adapter.js +12 -10
  49. package/lib/payment/apple-iap/adapter.js.map +1 -1
  50. package/lib/payment/apple-iap/db/AppleTransactionsCollection.d.ts +1 -1
  51. package/lib/payment/apple-iap/db/AppleTransactionsCollection.d.ts.map +1 -1
  52. package/lib/payment/apple-iap/handler-express.d.ts.map +1 -1
  53. package/lib/payment/apple-iap/handler-express.js +14 -10
  54. package/lib/payment/apple-iap/handler-express.js.map +1 -1
  55. package/lib/payment/apple-iap/handler-fastify.d.ts.map +1 -1
  56. package/lib/payment/apple-iap/handler-fastify.js +15 -8
  57. package/lib/payment/apple-iap/handler-fastify.js.map +1 -1
  58. package/lib/payment/apple-iap/module/configureAppleTransactionsModule.d.ts +9 -0
  59. package/lib/payment/apple-iap/module/configureAppleTransactionsModule.d.ts.map +1 -0
  60. package/lib/payment/apple-iap/module/configureAppleTransactionsModule.js +17 -0
  61. package/lib/payment/apple-iap/module/configureAppleTransactionsModule.js.map +1 -0
  62. package/lib/payment/apple-iap/module.d.ts +4 -4
  63. package/lib/payment/apple-iap/module.d.ts.map +1 -1
  64. package/lib/payment/apple-iap/module.js +4 -2
  65. package/lib/payment/apple-iap/module.js.map +1 -1
  66. package/lib/payment/braintree.js +3 -1
  67. package/lib/payment/braintree.js.map +1 -1
  68. package/lib/payment/cryptopay/db/CryptopayTransactions.d.ts +1 -1
  69. package/lib/payment/cryptopay/db/CryptopayTransactions.d.ts.map +1 -1
  70. package/lib/payment/cryptopay/derive-btc-address.d.ts.map +1 -1
  71. package/lib/payment/cryptopay/derive-btc-address.js +2 -3
  72. package/lib/payment/cryptopay/derive-btc-address.js.map +1 -1
  73. package/lib/payment/cryptopay/derive-eth-address.d.ts.map +1 -1
  74. package/lib/payment/cryptopay/derive-eth-address.js +2 -0
  75. package/lib/payment/cryptopay/derive-eth-address.js.map +1 -1
  76. package/lib/payment/cryptopay/handle-webhook.js +2 -2
  77. package/lib/payment/cryptopay/handle-webhook.js.map +1 -1
  78. package/lib/payment/cryptopay/handler-express.d.ts.map +1 -1
  79. package/lib/payment/cryptopay/handler-express.js +4 -7
  80. package/lib/payment/cryptopay/handler-express.js.map +1 -1
  81. package/lib/payment/cryptopay/handler-fastify.js +1 -1
  82. package/lib/payment/cryptopay/handler-fastify.js.map +1 -1
  83. package/lib/payment/cryptopay/middleware.d.ts +2 -0
  84. package/lib/payment/cryptopay/middleware.d.ts.map +1 -0
  85. package/lib/payment/cryptopay/middleware.js +75 -0
  86. package/lib/payment/cryptopay/middleware.js.map +1 -0
  87. package/lib/payment/cryptopay/module/configureCryptopayModule.d.ts +25 -0
  88. package/lib/payment/cryptopay/module/configureCryptopayModule.d.ts.map +1 -0
  89. package/lib/payment/cryptopay/module/configureCryptopayModule.js +75 -0
  90. package/lib/payment/cryptopay/module/configureCryptopayModule.js.map +1 -0
  91. package/lib/payment/cryptopay/module.d.ts +2 -2
  92. package/lib/payment/cryptopay/module.d.ts.map +1 -1
  93. package/lib/payment/cryptopay/module.js +4 -4
  94. package/lib/payment/cryptopay/module.js.map +1 -1
  95. package/lib/payment/cryptopay/plugin.d.ts.map +1 -1
  96. package/lib/payment/cryptopay/plugin.js +18 -4
  97. package/lib/payment/cryptopay/plugin.js.map +1 -1
  98. package/lib/payment/datatrans-v2/handler-express.d.ts.map +1 -1
  99. package/lib/payment/datatrans-v2/handler-express.js +13 -11
  100. package/lib/payment/datatrans-v2/handler-express.js.map +1 -1
  101. package/lib/payment/datatrans-v2/handler-fastify.d.ts.map +1 -1
  102. package/lib/payment/datatrans-v2/handler-fastify.js +11 -5
  103. package/lib/payment/datatrans-v2/handler-fastify.js.map +1 -1
  104. package/lib/payment/datatrans-v2/index.js +63 -37
  105. package/lib/payment/datatrans-v2/index.js.map +1 -1
  106. package/lib/payment/datatrans-v2/middleware.d.ts +2 -0
  107. package/lib/payment/datatrans-v2/middleware.d.ts.map +1 -0
  108. package/lib/payment/datatrans-v2/middleware.js +68 -0
  109. package/lib/payment/datatrans-v2/middleware.js.map +1 -0
  110. package/lib/payment/datatrans-v2/parseRegistrationData.d.ts +1 -1
  111. package/lib/payment/datatrans-v2/parseRegistrationData.d.ts.map +1 -1
  112. package/lib/payment/paypal-checkout.js +4 -2
  113. package/lib/payment/paypal-checkout.js.map +1 -1
  114. package/lib/payment/payrexx/api/index.d.ts +1 -1
  115. package/lib/payment/payrexx/api/index.d.ts.map +1 -1
  116. package/lib/payment/payrexx/api/makeFetcher.d.ts +1 -1
  117. package/lib/payment/payrexx/api/makeFetcher.d.ts.map +1 -1
  118. package/lib/payment/payrexx/api/makeFetcher.js +1 -1
  119. package/lib/payment/payrexx/api/makeFetcher.js.map +1 -1
  120. package/lib/payment/payrexx/handler-express.d.ts.map +1 -1
  121. package/lib/payment/payrexx/handler-express.js +15 -15
  122. package/lib/payment/payrexx/handler-express.js.map +1 -1
  123. package/lib/payment/payrexx/handler-fastify.js +23 -15
  124. package/lib/payment/payrexx/handler-fastify.js.map +1 -1
  125. package/lib/payment/payrexx/index.js +21 -15
  126. package/lib/payment/payrexx/index.js.map +1 -1
  127. package/lib/payment/payrexx/middleware.d.ts +2 -0
  128. package/lib/payment/payrexx/middleware.d.ts.map +1 -0
  129. package/lib/payment/payrexx/middleware.js +86 -0
  130. package/lib/payment/payrexx/middleware.js.map +1 -0
  131. package/lib/payment/postfinance-checkout/handler-express.js +7 -8
  132. package/lib/payment/postfinance-checkout/handler-express.js.map +1 -1
  133. package/lib/payment/postfinance-checkout/handler-fastify.d.ts.map +1 -1
  134. package/lib/payment/postfinance-checkout/handler-fastify.js +6 -4
  135. package/lib/payment/postfinance-checkout/handler-fastify.js.map +1 -1
  136. package/lib/payment/postfinance-checkout/index.d.ts.map +1 -1
  137. package/lib/payment/postfinance-checkout/index.js +20 -7
  138. package/lib/payment/postfinance-checkout/index.js.map +1 -1
  139. package/lib/payment/postfinance-checkout/middleware.d.ts +2 -0
  140. package/lib/payment/postfinance-checkout/middleware.d.ts.map +1 -0
  141. package/lib/payment/postfinance-checkout/middleware.js +38 -0
  142. package/lib/payment/postfinance-checkout/middleware.js.map +1 -0
  143. package/lib/payment/saferpay/adapter.d.ts.map +1 -1
  144. package/lib/payment/saferpay/adapter.js +9 -0
  145. package/lib/payment/saferpay/adapter.js.map +1 -1
  146. package/lib/payment/saferpay/handler-express.d.ts.map +1 -1
  147. package/lib/payment/saferpay/handler-express.js +10 -8
  148. package/lib/payment/saferpay/handler-express.js.map +1 -1
  149. package/lib/payment/saferpay/handler-fastify.d.ts.map +1 -1
  150. package/lib/payment/saferpay/handler-fastify.js +11 -5
  151. package/lib/payment/saferpay/handler-fastify.js.map +1 -1
  152. package/lib/payment/saferpay/middleware.d.ts +2 -0
  153. package/lib/payment/saferpay/middleware.d.ts.map +1 -0
  154. package/lib/payment/saferpay/middleware.js +57 -0
  155. package/lib/payment/saferpay/middleware.js.map +1 -0
  156. package/lib/payment/saferpay/module/configureSaferpayTransactionsModule.d.ts +10 -0
  157. package/lib/payment/saferpay/module/configureSaferpayTransactionsModule.d.ts.map +1 -0
  158. package/lib/payment/saferpay/module/configureSaferpayTransactionsModule.js +24 -0
  159. package/lib/payment/saferpay/module/configureSaferpayTransactionsModule.js.map +1 -0
  160. package/lib/payment/saferpay/module.d.ts +2 -2
  161. package/lib/payment/stripe/handler-express.js +25 -17
  162. package/lib/payment/stripe/handler-express.js.map +1 -1
  163. package/lib/payment/stripe/handler-fastify.d.ts.map +1 -1
  164. package/lib/payment/stripe/handler-fastify.js +33 -12
  165. package/lib/payment/stripe/handler-fastify.js.map +1 -1
  166. package/lib/payment/stripe/index.js +19 -13
  167. package/lib/payment/stripe/index.js.map +1 -1
  168. package/lib/payment/stripe/middleware.d.ts +6 -0
  169. package/lib/payment/stripe/middleware.d.ts.map +1 -0
  170. package/lib/payment/stripe/middleware.js +114 -0
  171. package/lib/payment/stripe/middleware.js.map +1 -0
  172. package/lib/payment/stripe/stripe.d.ts +2 -2
  173. package/lib/payment/stripe/stripe.d.ts.map +1 -1
  174. package/lib/payment/stripe/stripe.js +14 -11
  175. package/lib/payment/stripe/stripe.js.map +1 -1
  176. package/lib/plugins-index.d.ts +48 -0
  177. package/lib/plugins-index.d.ts.map +1 -0
  178. package/lib/plugins-index.js +107 -0
  179. package/lib/plugins-index.js.map +1 -0
  180. package/lib/presets/all.d.ts +5 -5
  181. package/lib/presets/all.d.ts.map +1 -1
  182. package/lib/pricing/delivery-swiss-tax.d.ts.map +1 -1
  183. package/lib/pricing/delivery-swiss-tax.js +13 -11
  184. package/lib/pricing/delivery-swiss-tax.js.map +1 -1
  185. package/lib/pricing/order-discount.d.ts.map +1 -1
  186. package/lib/pricing/order-discount.js +5 -3
  187. package/lib/pricing/order-discount.js.map +1 -1
  188. package/lib/pricing/order-round.d.ts.map +1 -1
  189. package/lib/pricing/order-round.js +4 -3
  190. package/lib/pricing/order-round.js.map +1 -1
  191. package/lib/pricing/product-catalog-price.js +4 -4
  192. package/lib/pricing/product-catalog-price.js.map +1 -1
  193. package/lib/pricing/product-price-rateconversion.js +3 -3
  194. package/lib/pricing/product-price-rateconversion.js.map +1 -1
  195. package/lib/pricing/product-swiss-tax.d.ts +1 -4
  196. package/lib/pricing/product-swiss-tax.d.ts.map +1 -1
  197. package/lib/pricing/product-swiss-tax.js +9 -15
  198. package/lib/pricing/product-swiss-tax.js.map +1 -1
  199. package/lib/pricing/tax/ch.d.ts +6 -0
  200. package/lib/pricing/tax/ch.d.ts.map +1 -1
  201. package/lib/pricing/tax/ch.js +10 -0
  202. package/lib/pricing/tax/ch.js.map +1 -1
  203. package/lib/warehousing/eth-minter.js +23 -11
  204. package/lib/warehousing/eth-minter.js.map +1 -1
  205. package/lib/worker/BaseWorker.d.ts +30 -0
  206. package/lib/worker/BaseWorker.d.ts.map +1 -0
  207. package/lib/worker/BaseWorker.js +79 -0
  208. package/lib/worker/BaseWorker.js.map +1 -0
  209. package/lib/worker/EventListenerWorker.d.ts +6 -0
  210. package/lib/worker/EventListenerWorker.d.ts.map +1 -0
  211. package/lib/worker/EventListenerWorker.js +46 -0
  212. package/lib/worker/EventListenerWorker.js.map +1 -0
  213. package/lib/worker/FailedRescheduler.d.ts +15 -0
  214. package/lib/worker/FailedRescheduler.d.ts.map +1 -0
  215. package/lib/worker/FailedRescheduler.js +45 -0
  216. package/lib/worker/FailedRescheduler.js.map +1 -0
  217. package/lib/worker/IntervalWorker.d.ts +10 -0
  218. package/lib/worker/IntervalWorker.d.ts.map +1 -0
  219. package/lib/worker/IntervalWorker.js +37 -0
  220. package/lib/worker/IntervalWorker.js.map +1 -0
  221. package/lib/worker/bulk-import.d.ts +1 -1
  222. package/lib/worker/bulk-import.d.ts.map +1 -1
  223. package/lib/worker/bulk-import.js +11 -33
  224. package/lib/worker/bulk-import.js.map +1 -1
  225. package/lib/worker/enrollment-order-generator.d.ts.map +1 -1
  226. package/lib/worker/enrollment-order-generator.js +7 -49
  227. package/lib/worker/enrollment-order-generator.js.map +1 -1
  228. package/lib/worker/error-notifications.js +1 -1
  229. package/lib/worker/error-notifications.js.map +1 -1
  230. package/lib/worker/export-token.d.ts.map +1 -1
  231. package/lib/worker/export-token.js +0 -1
  232. package/lib/worker/export-token.js.map +1 -1
  233. package/lib/worker/message.d.ts +1 -1
  234. package/lib/worker/message.d.ts.map +1 -1
  235. package/lib/worker/message.js +4 -2
  236. package/lib/worker/message.js.map +1 -1
  237. package/lib/worker/sms.d.ts +2 -0
  238. package/lib/worker/sms.d.ts.map +1 -0
  239. package/lib/worker/sms.js +73 -0
  240. package/lib/worker/sms.js.map +1 -0
  241. package/lib/worker/twilio.js +4 -0
  242. package/lib/worker/twilio.js.map +1 -1
  243. package/package.json +15 -17
  244. package/src/delivery/send-message.ts +1 -1
  245. package/src/enrollments/licensed.ts +15 -2
  246. package/src/files/gridfs/adapter.ts +1 -1
  247. package/src/files/gridfs/handler-express.ts +19 -24
  248. package/src/files/gridfs/handler-fastify.ts +48 -12
  249. package/src/files/minio/handler-express.ts +4 -7
  250. package/src/files/minio/handler-fastify.ts +2 -2
  251. package/src/files/minio/index.ts +12 -12
  252. package/src/filters/local-search.ts +1 -1
  253. package/src/payment/apple-iap/adapter.ts +12 -14
  254. package/src/payment/apple-iap/db/AppleTransactionsCollection.ts +1 -1
  255. package/src/payment/apple-iap/handler-express.ts +17 -11
  256. package/src/payment/apple-iap/handler-fastify.ts +19 -9
  257. package/src/payment/apple-iap/module.ts +9 -4
  258. package/src/payment/braintree.ts +4 -1
  259. package/src/payment/cryptopay/db/CryptopayTransactions.ts +1 -1
  260. package/src/payment/cryptopay/derive-btc-address.ts +1 -3
  261. package/src/payment/cryptopay/derive-eth-address.ts +2 -0
  262. package/src/payment/cryptopay/handle-webhook.ts +6 -6
  263. package/src/payment/cryptopay/handler-express.ts +4 -7
  264. package/src/payment/cryptopay/handler-fastify.ts +1 -1
  265. package/src/payment/cryptopay/module.ts +8 -5
  266. package/src/payment/cryptopay/plugin.ts +21 -4
  267. package/src/payment/datatrans-v2/handler-express.ts +17 -12
  268. package/src/payment/datatrans-v2/handler-fastify.ts +15 -6
  269. package/src/payment/datatrans-v2/index.ts +82 -50
  270. package/src/payment/paypal-checkout.ts +4 -2
  271. package/src/payment/payrexx/api/index.ts +1 -1
  272. package/src/payment/payrexx/api/makeFetcher.ts +2 -2
  273. package/src/payment/payrexx/handler-express.ts +24 -32
  274. package/src/payment/payrexx/handler-fastify.ts +33 -33
  275. package/src/payment/payrexx/index.ts +26 -16
  276. package/src/payment/postfinance-checkout/handler-express.ts +8 -8
  277. package/src/payment/postfinance-checkout/handler-fastify.ts +7 -4
  278. package/src/payment/postfinance-checkout/index.ts +20 -8
  279. package/src/payment/saferpay/adapter.ts +14 -2
  280. package/src/payment/saferpay/handler-express.ts +14 -13
  281. package/src/payment/saferpay/handler-fastify.ts +14 -9
  282. package/src/payment/stripe/handler-express.ts +33 -33
  283. package/src/payment/stripe/handler-fastify.ts +40 -27
  284. package/src/payment/stripe/index.ts +17 -13
  285. package/src/payment/stripe/stripe.ts +17 -12
  286. package/src/pricing/delivery-swiss-tax.ts +11 -19
  287. package/src/pricing/order-discount.ts +6 -4
  288. package/src/pricing/order-round.ts +5 -4
  289. package/src/pricing/product-catalog-price.ts +4 -4
  290. package/src/pricing/product-price-rateconversion.ts +3 -3
  291. package/src/pricing/product-swiss-tax.test.ts +1 -86
  292. package/src/pricing/product-swiss-tax.ts +11 -24
  293. package/src/pricing/tax/ch.test.ts +86 -1
  294. package/src/pricing/tax/ch.ts +23 -0
  295. package/src/warehousing/eth-minter.ts +30 -11
  296. package/src/worker/budgetsms.ts +1 -1
  297. package/src/worker/bulk-import.ts +12 -53
  298. package/src/worker/enrollment-order-generator.ts +14 -72
  299. package/src/worker/error-notifications.ts +2 -2
  300. package/src/worker/export-token.ts +0 -1
  301. package/src/worker/message.ts +5 -3
  302. package/src/worker/twilio.ts +10 -3
@@ -21,11 +21,12 @@ const LicensedEnrollments: IEnrollmentAdapter = {
21
21
  },
22
22
 
23
23
  actions: (params) => {
24
+ const { enrollment } = params;
24
25
  return {
25
26
  ...EnrollmentAdapter.actions(params),
26
27
 
27
28
  isValidForActivation: async () => {
28
- const periods = params.enrollment?.periods || [];
29
+ const periods = enrollment?.periods || [];
29
30
  return periods.findIndex(rangeMatcher()) !== -1;
30
31
  },
31
32
 
@@ -36,8 +37,20 @@ const LicensedEnrollments: IEnrollmentAdapter = {
36
37
  configurationForOrder: async (context) => {
37
38
  const { period } = context;
38
39
  const beginningOfPeriod = period.start.getTime() <= new Date().getTime();
40
+
41
+ if (!enrollment) throw new Error('Enrollment missing in context');
39
42
  if (beginningOfPeriod) {
40
- return context;
43
+ return {
44
+ period,
45
+ orderContext: {},
46
+ orderPositionTemplates: [
47
+ {
48
+ quantity: 1,
49
+ productId: enrollment.productId,
50
+ originalProductId: enrollment.productId,
51
+ },
52
+ ],
53
+ };
41
54
  }
42
55
  return null;
43
56
  },
@@ -36,7 +36,7 @@ export const GridFSAdapter: IFileAdapter<
36
36
  ...FileAdapter,
37
37
  async createDownloadURL(file, expiry) {
38
38
  // If public, just return the stored path from the db
39
- if (!file?.meta?.isPrivate) return file?.url;
39
+ if (!file?.meta?.isPrivate) return file?.url || null;
40
40
 
41
41
  const expiryTimestamp =
42
42
  expiry ||
@@ -10,7 +10,7 @@ import { getFileAdapter } from '@unchainedshop/core-files';
10
10
 
11
11
  const { ROOT_URL } = process.env;
12
12
 
13
- const logger = createLogger('unchained:plugins:gridfs');
13
+ const logger = createLogger('unchained:gridfs');
14
14
 
15
15
  const gridfsHandler = async (
16
16
  req: express.Request & {
@@ -34,8 +34,7 @@ const gridfsHandler = async (
34
34
  res.setHeader('Access-Control-Allow-Origin', '*');
35
35
 
36
36
  if (req.method === 'OPTIONS') {
37
- res.statusCode = 200;
38
- res.end();
37
+ res.status(200).end();
39
38
  return;
40
39
  }
41
40
 
@@ -45,9 +44,14 @@ const gridfsHandler = async (
45
44
  const fileId = await buildHashedFilename(directoryName, fileName, expiryDate);
46
45
  if ((await sign(directoryName, fileId, expiryDate.getTime())) === signature) {
47
46
  const file = await modules.files.findFile({ fileId });
47
+
48
+ if (!file) {
49
+ res.status(404).send('File not found');
50
+ return;
51
+ }
52
+
48
53
  if (file.expires === null) {
49
- res.statusCode = 400;
50
- res.end('File already linked');
54
+ res.status(400).send('File already linked');
51
55
  return;
52
56
  }
53
57
  // If the type is octet-stream, prefer mimetype lookup from the filename
@@ -77,12 +81,10 @@ const gridfsHandler = async (
77
81
  const { length } = writeStream;
78
82
  await services.files.linkFile({ fileId, size: length, type });
79
83
 
80
- res.statusCode = 200;
81
- res.end();
84
+ res.status(200).end();
82
85
  return;
83
86
  }
84
- res.statusCode = 403;
85
- res.end();
87
+ res.status(403).end();
86
88
  return;
87
89
  }
88
90
 
@@ -94,22 +96,19 @@ const gridfsHandler = async (
94
96
  if (fileDocument?.meta?.isPrivate) {
95
97
  const expiry = parseInt(expiryTimestamp as string, 10);
96
98
  if (expiry <= Date.now()) {
97
- res.statusCode = 403;
98
- res.end('Access restricted: Expired.');
99
+ res.status(403).send('Access restricted: Expired.');
99
100
  return;
100
101
  }
101
102
 
102
103
  const fileUploadAdapter = getFileAdapter();
103
104
  const signedUrl = await fileUploadAdapter.createDownloadURL(fileDocument, expiry);
104
105
 
105
- if (new URL(signedUrl, 'file://').searchParams.get('s') !== signature) {
106
- res.statusCode = 403;
107
- res.end('Access restricted: Invalid signature.');
106
+ if (!signedUrl || new URL(signedUrl, 'file://').searchParams.get('s') !== signature) {
107
+ res.status(403).send('Access restricted: Invalid signature.');
108
108
  return;
109
109
  }
110
110
  } else if (!fileDocument) {
111
- res.statusCode = 404;
112
- res.end();
111
+ res.status(404).end();
113
112
  return;
114
113
  }
115
114
  if (file?.metadata?.['content-type']) {
@@ -122,21 +121,17 @@ const gridfsHandler = async (
122
121
  const readStream = await modules.gridfsFileUploads.createReadStream(directoryName, fileId);
123
122
  readStream.pipe(res, { end: false });
124
123
  await finished(readStream);
125
- res.statusCode = 200;
126
- res.end();
124
+ res.status(200).end();
127
125
  return;
128
126
  }
129
- res.statusCode = 404;
130
- res.end();
127
+ res.status(404).end();
131
128
  } catch (e) {
132
129
  if (e.code === 'ENOENT') {
133
130
  logger.warn(e);
134
- res.statusCode = 404;
135
- res.end(e.message);
131
+ res.status(404).send();
136
132
  } else {
137
133
  logger.warn(e);
138
- res.statusCode = 503;
139
- res.end(JSON.stringify({ name: e.name, code: e.code, message: e.message }));
134
+ res.status(503).send({ name: e.name, code: e.code, message: e.message });
140
135
  }
141
136
  }
142
137
  };
@@ -8,7 +8,7 @@ import { Context } from '@unchainedshop/api';
8
8
  import { createLogger } from '@unchainedshop/logger';
9
9
  import { getFileAdapter } from '@unchainedshop/core-files';
10
10
 
11
- const logger = createLogger('unchained:plugins:gridfs');
11
+ const logger = createLogger('unchained:gridfs');
12
12
 
13
13
  const gridfsHandler: RouteHandlerMethod = async (
14
14
  req: FastifyRequest & {
@@ -39,9 +39,25 @@ const gridfsHandler: RouteHandlerMethod = async (
39
39
  const fileId = await buildHashedFilename(directoryName, fileName, expiryDate);
40
40
  if ((await sign(directoryName, fileId, expiryDate.getTime())) === signature) {
41
41
  const file = await modules.files.findFile({ fileId });
42
+
43
+ if (!file) {
44
+ reply.status(404);
45
+ logger.error('File not found', { fileId });
46
+ return reply.send({
47
+ success: false,
48
+ message: 'File not found',
49
+ name: 'FILE_NOT_FOUND',
50
+ });
51
+ }
52
+
42
53
  if (file.expires === null) {
43
54
  reply.status(400);
44
- return reply.send('File already linked');
55
+ logger.error('File already linked', { fileId });
56
+ return reply.send({
57
+ success: false,
58
+ message: 'File already linked',
59
+ name: 'FILE_ALREADY_LINKED',
60
+ });
45
61
  }
46
62
  // If the type is octet-stream, prefer mimetype lookup from the filename
47
63
  // Else prefer the content-type header
@@ -72,11 +88,20 @@ const gridfsHandler: RouteHandlerMethod = async (
72
88
  await services.files.linkFile({ fileId, size: length, type });
73
89
 
74
90
  reply.status(200);
75
- return reply.send();
91
+ return reply.send({
92
+ success: true,
93
+ fileId,
94
+ size: length,
95
+ type,
96
+ });
76
97
  }
77
-
98
+ logger.error('Invalid signature', { fileId, expiryDate });
78
99
  reply.status(403);
79
- return reply.send();
100
+ return reply.send({
101
+ success: false,
102
+ message: 'Access restricted: Invalid signature.',
103
+ name: 'INVALID_SIGNATURE',
104
+ });
80
105
  }
81
106
 
82
107
  if (req.method === 'GET') {
@@ -87,18 +112,29 @@ const gridfsHandler: RouteHandlerMethod = async (
87
112
  if (fileDocument?.meta?.isPrivate) {
88
113
  const expiry = parseInt(expiryTimestamp as string, 10);
89
114
  if (expiry <= Date.now()) {
115
+ logger.error('URL Expired', { fileId, expiry });
90
116
  reply.status(403);
91
- return reply.send('Access restricted: Expired.');
117
+ return reply.send({
118
+ success: false,
119
+ message: 'Access restricted: URL expired.',
120
+ name: 'URL_EXPIRED',
121
+ });
92
122
  }
93
123
 
94
124
  const fileUploadAdapter = getFileAdapter();
95
125
  const signedUrl = await fileUploadAdapter.createDownloadURL(fileDocument, expiry);
96
126
 
97
- if (new URL(signedUrl, 'file://').searchParams.get('s') !== signature) {
127
+ if (!signedUrl || new URL(signedUrl, 'file://').searchParams.get('s') !== signature) {
98
128
  reply.status(403);
99
- return reply.send('Access restricted: Invalid signature.');
129
+ logger.error('Invalid signature', { fileId, expiry });
130
+ return reply.send({
131
+ success: false,
132
+ message: 'Access restricted: Invalid signature.',
133
+ name: 'INVALID_SIGNATURE',
134
+ });
100
135
  }
101
136
  } else if (!fileDocument) {
137
+ logger.error('File not found', { fileId });
102
138
  reply.status(404);
103
139
  return reply.send();
104
140
  }
@@ -119,14 +155,14 @@ const gridfsHandler: RouteHandlerMethod = async (
119
155
  reply.status(404);
120
156
  return reply.send();
121
157
  } catch (e) {
158
+ logger.error(e);
159
+
122
160
  if (e.code === 'ENOENT') {
123
- logger.warn(e);
124
161
  reply.status(404);
125
- return reply.send({ name: e.name, code: e.code, message: e.message });
162
+ return reply.send();
126
163
  } else {
127
- logger.warn(e);
128
164
  reply.status(504);
129
- return reply.send({ name: e.name, code: e.code, message: e.message });
165
+ return reply.send({ success: false, name: e.name, code: e.code, message: e.message });
130
166
  }
131
167
  }
132
168
  };
@@ -1,6 +1,6 @@
1
1
  import { createLogger } from '@unchainedshop/logger';
2
2
 
3
- const logger = createLogger('unchained:plugins:minio');
3
+ const logger = createLogger('unchained:minio');
4
4
 
5
5
  const { MINIO_WEBHOOK_AUTH_TOKEN } = process.env;
6
6
 
@@ -21,17 +21,14 @@ const minioHandler = async (req, res) => {
21
21
  const [fileId] = object.key.split('.');
22
22
  const { services } = req.unchainedContext;
23
23
  await services.files.linkFile({ fileId, type, size });
24
- res.writeHead(200);
25
- res.end();
24
+ res.status(200).end();
26
25
  return;
27
26
  }
28
27
  }
29
- res.writeHead(404);
30
- res.end();
28
+ res.status(404).end();
31
29
  } catch (e) {
32
30
  logger.error(e);
33
- res.writeHead(503);
34
- res.end(JSON.stringify({ name: e.name, code: e.code, message: e.message }));
31
+ res.status(503).send({ name: e.name, code: e.code, message: e.message });
35
32
  }
36
33
  };
37
34
 
@@ -2,7 +2,7 @@ import { Context } from '@unchainedshop/api';
2
2
  import { createLogger } from '@unchainedshop/logger';
3
3
  import { FastifyRequest, RouteHandlerMethod } from 'fastify';
4
4
 
5
- const logger = createLogger('unchained:plugins:minio');
5
+ const logger = createLogger('unchained:minio');
6
6
 
7
7
  const { MINIO_WEBHOOK_AUTH_TOKEN } = process.env;
8
8
 
@@ -37,7 +37,7 @@ const minioHandler: RouteHandlerMethod = async (
37
37
  } catch (e) {
38
38
  logger.error(e);
39
39
  res.status(503);
40
- return res.send(JSON.stringify({ name: e.name, code: e.code, message: e.message }));
40
+ return res.send({ name: e.name, code: e.code, message: e.message });
41
41
  }
42
42
  };
43
43
 
@@ -14,7 +14,7 @@ import { AssumeRoleProvider } from 'minio/dist/esm/AssumeRoleProvider.mjs';
14
14
  import { expiryOffsetInMs } from '@unchainedshop/file-upload/lib/put-expiration.js';
15
15
  import { createLogger } from '@unchainedshop/logger';
16
16
 
17
- const logger = createLogger('unchained:plugins:minio');
17
+ const logger = createLogger('unchained:minio');
18
18
 
19
19
  const {
20
20
  MINIO_ACCESS_KEY,
@@ -28,7 +28,7 @@ const {
28
28
  AMAZON_S3_SESSION_TOKEN,
29
29
  } = process.env;
30
30
 
31
- let client: Client;
31
+ let client: Client | null = null;
32
32
 
33
33
  export async function connectToMinio() {
34
34
  if (!MINIO_ENDPOINT || !MINIO_BUCKET_NAME) {
@@ -56,8 +56,8 @@ export async function connectToMinio() {
56
56
  if (MINIO_STS_ENDPOINT) {
57
57
  const ap = new AssumeRoleProvider({
58
58
  stsEndpoint: MINIO_STS_ENDPOINT,
59
- accessKey: MINIO_ACCESS_KEY,
60
- secretKey: MINIO_SECRET_KEY,
59
+ accessKey: MINIO_ACCESS_KEY!,
60
+ secretKey: MINIO_SECRET_KEY!,
61
61
  });
62
62
  // eslint-disable-next-line
63
63
  // @ts-ignore
@@ -76,17 +76,17 @@ const generateMinioPath = (directoryName: string, fileName: string) => {
76
76
  };
77
77
 
78
78
  const generateMinioUrl = (directoryName: string, hashedFilename: string) => {
79
- return `${MINIO_ENDPOINT}/${MINIO_BUCKET_NAME}/${generateMinioPath(directoryName, hashedFilename)}`;
79
+ return `${MINIO_ENDPOINT}/${MINIO_BUCKET_NAME!}/${generateMinioPath(directoryName, hashedFilename)}`;
80
80
  };
81
81
 
82
82
  connectToMinio().then(function setClient(c) {
83
- client = c;
83
+ client = c || client;
84
84
  });
85
85
 
86
86
  const getObjectStats = async (fileName: string) => {
87
87
  if (!client) throw new Error('Minio not connected, check env variables');
88
88
 
89
- return client.statObject(MINIO_BUCKET_NAME, fileName);
89
+ return client.statObject(MINIO_BUCKET_NAME!, fileName);
90
90
  };
91
91
 
92
92
  const bufferToStream = (buffer: any) => {
@@ -116,7 +116,7 @@ export const MinioAdapter: IFileAdapter = {
116
116
  const _id = await buildHashedFilename(directoryName, fileName, expiryDate);
117
117
 
118
118
  const url = await client.presignedPutObject(
119
- MINIO_BUCKET_NAME,
119
+ MINIO_BUCKET_NAME!,
120
120
  generateMinioPath(directoryName, _id),
121
121
  expiryOffsetInMs() / 1000,
122
122
  );
@@ -139,7 +139,7 @@ export const MinioAdapter: IFileAdapter = {
139
139
  return `${path}/${_id}`;
140
140
  });
141
141
 
142
- await client.removeObjects(MINIO_BUCKET_NAME, fileIds);
142
+ await client.removeObjects(MINIO_BUCKET_NAME!, fileIds);
143
143
  },
144
144
 
145
145
  async uploadFileFromStream(directoryName: string, rawFile: any) {
@@ -164,7 +164,7 @@ export const MinioAdapter: IFileAdapter = {
164
164
  };
165
165
 
166
166
  await client.putObject(
167
- MINIO_BUCKET_NAME,
167
+ MINIO_BUCKET_NAME!,
168
168
  generateMinioPath(directoryName, _id),
169
169
  stream,
170
170
  undefined,
@@ -200,7 +200,7 @@ export const MinioAdapter: IFileAdapter = {
200
200
  };
201
201
 
202
202
  await client.putObject(
203
- MINIO_BUCKET_NAME,
203
+ MINIO_BUCKET_NAME!,
204
204
  generateMinioPath(directoryName, hashedFilename),
205
205
  readable,
206
206
  undefined,
@@ -222,7 +222,7 @@ export const MinioAdapter: IFileAdapter = {
222
222
  async createDownloadStream(file) {
223
223
  if (!client) throw new Error('Minio not connected, check env variables');
224
224
 
225
- const stream = await client.getObject(MINIO_BUCKET_NAME, generateMinioPath(file.path, file._id));
225
+ const stream = await client.getObject(MINIO_BUCKET_NAME!, generateMinioPath(file.path, file._id));
226
226
  return stream;
227
227
  },
228
228
  };
@@ -5,7 +5,7 @@ import { FilterDirector, FilterAdapter, IFilterAdapter } from '@unchainedshop/co
5
5
  import { createLogger } from '@unchainedshop/logger';
6
6
  import { isDocumentDBCompatModeEnabled } from '@unchainedshop/mongodb';
7
7
 
8
- const logger = createLogger('unchained:core-filters:local-search');
8
+ const logger = createLogger('unchained:local-search');
9
9
 
10
10
  const LocalSearch: IFilterAdapter = {
11
11
  ...FilterAdapter,
@@ -3,7 +3,7 @@ import { createLogger } from '@unchainedshop/logger';
3
3
  import { AppleTransactionsModule } from './module.js';
4
4
  import { verifyReceipt } from './verify-receipt.js';
5
5
 
6
- const logger = createLogger('unchained:core-payment:apple-iap');
6
+ const logger = createLogger('unchained:apple-iap');
7
7
 
8
8
  const { APPLE_IAP_SHARED_SECRET } = process.env;
9
9
 
@@ -42,7 +42,7 @@ const AppleIAP: IPaymentAdapter = {
42
42
  },
43
43
 
44
44
  async sign() {
45
- throw new Error('Apple IAP does not support payment signing');
45
+ throw new Error('Payment signing not supported');
46
46
  },
47
47
 
48
48
  async validate() {
@@ -60,7 +60,7 @@ const AppleIAP: IPaymentAdapter = {
60
60
  const { status, latest_receipt_info: latestReceiptInfo } = response;
61
61
 
62
62
  if (status === 0) {
63
- logger.debug('Apple IAP Plugin: Receipt validated and updated for the user');
63
+ logger.debug('Receipt validated and updated for the user');
64
64
  const latestTransaction = latestReceiptInfo[latestReceiptInfo.length - 1];
65
65
  return {
66
66
  token: latestTransaction.web_order_line_item_id,
@@ -68,7 +68,7 @@ const AppleIAP: IPaymentAdapter = {
68
68
  };
69
69
  }
70
70
 
71
- logger.warn('Apple IAP Plugin: Receipt invalid', {
71
+ logger.warn('Receipt invalid', {
72
72
  status: response.status,
73
73
  });
74
74
  return null;
@@ -79,9 +79,11 @@ const AppleIAP: IPaymentAdapter = {
79
79
  const { transactionIdentifier } = meta || {};
80
80
 
81
81
  if (!transactionIdentifier) {
82
- throw new Error('Apple IAP Plugin: You have to set the transaction id on the order payment');
82
+ throw new Error('You have to set the transaction id on the order payment');
83
83
  }
84
84
 
85
+ if (!order) throw new Error('Order not found');
86
+
85
87
  const receiptResponse =
86
88
  receiptData &&
87
89
  (await verifyReceipt({
@@ -90,7 +92,7 @@ const AppleIAP: IPaymentAdapter = {
90
92
  }));
91
93
 
92
94
  if (receiptResponse && receiptResponse.status !== 0) {
93
- throw new Error('Apple IAP Plugin: Receipt invalid');
95
+ throw new Error('Receipt invalid');
94
96
  }
95
97
 
96
98
  const transactions =
@@ -99,9 +101,7 @@ const AppleIAP: IPaymentAdapter = {
99
101
  (transaction) => transaction?.transaction_id === transactionIdentifier,
100
102
  );
101
103
  if (!matchedTransaction) {
102
- throw new Error(
103
- `Apple IAP Plugin: Cannot match transaction with identifier ${transactionIdentifier}`,
104
- );
104
+ throw new Error(`Cannot match transaction with identifier ${transactionIdentifier}`);
105
105
  }
106
106
 
107
107
  const orderPositions = await modules.orders.positions.findOrderPositions({
@@ -117,7 +117,7 @@ const AppleIAP: IPaymentAdapter = {
117
117
  );
118
118
 
119
119
  if (items.length !== 1) {
120
- throw new Error('Apple IAP Plugin: You can only checkout 1 unique product at once');
120
+ throw new Error('You can only checkout 1 unique product at once');
121
121
  }
122
122
 
123
123
  const [[productId, quantity]] = items;
@@ -126,14 +126,12 @@ const AppleIAP: IPaymentAdapter = {
126
126
  parseInt(matchedTransaction.quantity, 10) === quantity &&
127
127
  matchedTransaction.product_id === productId;
128
128
 
129
- if (!isMatchesTransaction)
130
- throw new Error('Apple IAP Plugin: Product in order does not match transaction');
129
+ if (!isMatchesTransaction) throw new Error('Product in order does not match transaction');
131
130
 
132
131
  const alreadyProcessedTransaction =
133
132
  await modules.appleTransactions.findTransactionById(transactionIdentifier);
134
133
 
135
- if (alreadyProcessedTransaction)
136
- throw new Error('Apple IAP Plugin: Transaction already processed');
134
+ if (alreadyProcessedTransaction) throw new Error('Transaction already processed');
137
135
 
138
136
  // All good
139
137
  await modules.appleTransactions.createTransaction({
@@ -2,7 +2,7 @@ import { mongodb } from '@unchainedshop/mongodb';
2
2
  import { TimestampFields } from '@unchainedshop/mongodb';
3
3
 
4
4
  export type AppleTransaction = {
5
- _id?: string;
5
+ _id: string;
6
6
  matchedTransaction: any;
7
7
  orderId: string;
8
8
  } & TimestampFields;
@@ -3,7 +3,7 @@ import { EnrollmentStatus } from '@unchainedshop/core-enrollments';
3
3
  import { createLogger } from '@unchainedshop/logger';
4
4
  import { fixPeriods } from './fix-periods.js';
5
5
 
6
- const logger = createLogger('unchained:core-payment:apple-iap:handler');
6
+ const logger = createLogger('unchained:apple-iap:handler');
7
7
 
8
8
  const { APPLE_IAP_SHARED_SECRET } = process.env;
9
9
 
@@ -43,10 +43,16 @@ export const appleIAPHandler = async (req, res) => {
43
43
  receiptData: responseBody?.unified_receipt?.latest_receipt,
44
44
  },
45
45
  });
46
+
47
+ if (!order) throw new Error(`Order with id ${orderPayment.orderId} not found`);
48
+
46
49
  const orderId = order._id;
47
50
  const enrollment = await modules.enrollments.findEnrollment({
48
51
  orderId,
49
52
  });
53
+
54
+ if (!enrollment) throw new Error('Could not find any matching enrollment');
55
+
50
56
  await fixPeriods(
51
57
  {
52
58
  transactionId: latestTransaction.original_transaction_id,
@@ -72,9 +78,12 @@ export const appleIAPHandler = async (req, res) => {
72
78
  const originalOrder = await modules.orders.findOrder({
73
79
  orderId: originalOrderPayment.orderId,
74
80
  });
75
- const enrollment = await modules.enrollments.findEnrollment({
76
- orderId: originalOrder._id,
77
- });
81
+ const enrollment =
82
+ originalOrder &&
83
+ (await modules.enrollments.findEnrollment({
84
+ orderId: originalOrder._id,
85
+ }));
86
+ if (!enrollment?.payment) throw new Error('Could not find a valid enrollment payment method');
78
87
 
79
88
  await services.orders.registerPaymentCredentials(enrollment.payment.paymentProviderId, {
80
89
  transactionContext: {
@@ -88,7 +97,7 @@ export const appleIAPHandler = async (req, res) => {
88
97
  transactionId: latestTransaction.original_transaction_id,
89
98
  transactions,
90
99
  enrollmentId: enrollment._id,
91
- orderId: originalOrder._id,
100
+ orderId: originalOrder!._id,
92
101
  },
93
102
  resolvedContext,
94
103
  );
@@ -117,18 +126,15 @@ export const appleIAPHandler = async (req, res) => {
117
126
  logger.info(`Apple IAP Webhook: Updated enrollment from Apple`);
118
127
  }
119
128
 
120
- res.writeHead(200);
121
- res.end();
129
+ res.status(200).end();
122
130
  return;
123
131
  } catch (e) {
124
132
  logger.warn(`Apple IAP Webhook: ${e.message}`, e);
125
- res.writeHead(503);
126
- res.end(JSON.stringify({ name: e.name, code: e.code, message: e.message }));
133
+ res.status(503).send({ name: e.name, code: e.code, message: e.message });
127
134
  return;
128
135
  }
129
136
  }
130
- res.writeHead(404);
131
- res.end();
137
+ res.status(404).end();
132
138
  };
133
139
 
134
140
  export default appleIAPHandler;
@@ -5,7 +5,7 @@ import { fixPeriods } from './fix-periods.js';
5
5
  import { FastifyRequest, RouteHandlerMethod } from 'fastify';
6
6
  import { AppleTransactionsModule } from './module.js';
7
7
 
8
- const logger = createLogger('unchained:core-payment:apple-iap:handler');
8
+ const logger = createLogger('unchained:apple-iap:handler');
9
9
 
10
10
  const { APPLE_IAP_SHARED_SECRET } = process.env;
11
11
 
@@ -51,10 +51,16 @@ export const appleIAPHandler: RouteHandlerMethod = async (
51
51
  receiptData: responseBody?.unified_receipt?.latest_receipt,
52
52
  },
53
53
  });
54
+
55
+ if (!order) throw new Error(`Order with id ${orderPayment.orderId} not found`);
56
+
54
57
  const orderId = order._id;
55
58
  const enrollment = await modules.enrollments.findEnrollment({
56
59
  orderId,
57
60
  });
61
+
62
+ if (!enrollment) throw new Error('Enrollent not found');
63
+
58
64
  await fixPeriods(
59
65
  {
60
66
  transactionId: latestTransaction.original_transaction_id,
@@ -65,7 +71,7 @@ export const appleIAPHandler: RouteHandlerMethod = async (
65
71
  resolvedContext,
66
72
  );
67
73
 
68
- logger.info(`Apple IAP Webhook: Confirmed checkout for order ${order.orderNumber}`, {
74
+ logger.info(`Webhook confirmed checkout for order ${order.orderNumber}`, {
69
75
  orderId: order._id,
70
76
  });
71
77
  } else {
@@ -80,9 +86,13 @@ export const appleIAPHandler: RouteHandlerMethod = async (
80
86
  const originalOrder = await modules.orders.findOrder({
81
87
  orderId: originalOrderPayment.orderId,
82
88
  });
83
- const enrollment = await modules.enrollments.findEnrollment({
84
- orderId: originalOrder._id,
85
- });
89
+ const enrollment =
90
+ originalOrder &&
91
+ (await modules.enrollments.findEnrollment({
92
+ orderId: originalOrder._id,
93
+ }));
94
+
95
+ if (!enrollment?.payment) throw new Error('Could not find a valid enrollment payment method');
86
96
 
87
97
  await services.orders.registerPaymentCredentials(enrollment.payment.paymentProviderId, {
88
98
  transactionContext: {
@@ -96,13 +106,13 @@ export const appleIAPHandler: RouteHandlerMethod = async (
96
106
  transactionId: latestTransaction.original_transaction_id,
97
107
  transactions,
98
108
  enrollmentId: enrollment._id,
99
- orderId: originalOrder._id,
109
+ orderId: originalOrder!._id,
100
110
  },
101
111
  resolvedContext,
102
112
  );
103
113
 
104
114
  logger.info(
105
- `Apple IAP Webhook: Processed notification for ${latestTransaction.original_transaction_id} and type ${responseBody.notification_type}`,
115
+ `Webhook rocessed notification for ${latestTransaction.original_transaction_id} and type ${responseBody.notification_type}`,
106
116
  );
107
117
 
108
118
  if (responseBody.notification_type === AppleNotificationTypes.DID_RECOVER) {
@@ -128,9 +138,9 @@ export const appleIAPHandler: RouteHandlerMethod = async (
128
138
  reply.status(200);
129
139
  return reply.send();
130
140
  } catch (e) {
131
- logger.warn(`Apple IAP Webhook: ${e.message}`, e);
141
+ logger.error(e);
132
142
  reply.status(503);
133
- return reply.send({ name: e.name, code: e.code, message: e.message });
143
+ return reply.send({ success: false, name: e.name, code: e.code, message: e.message });
134
144
  }
135
145
  };
136
146