@unchainedshop/plugins 4.0.0-rc.8 → 4.0.0

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 (321) 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.d.ts.map +1 -1
  13. package/lib/files/gridfs/adapter.js +11 -8
  14. package/lib/files/gridfs/adapter.js.map +1 -1
  15. package/lib/files/gridfs/gridfs-adapter.d.ts +3 -0
  16. package/lib/files/gridfs/gridfs-adapter.d.ts.map +1 -0
  17. package/lib/files/gridfs/gridfs-adapter.js +97 -0
  18. package/lib/files/gridfs/gridfs-adapter.js.map +1 -0
  19. package/lib/files/gridfs/gridfs-webhook.d.ts +11 -0
  20. package/lib/files/gridfs/gridfs-webhook.d.ts.map +1 -0
  21. package/lib/files/gridfs/gridfs-webhook.js +84 -0
  22. package/lib/files/gridfs/gridfs-webhook.js.map +1 -0
  23. package/lib/files/gridfs/handler-express.d.ts.map +1 -1
  24. package/lib/files/gridfs/handler-express.js +21 -25
  25. package/lib/files/gridfs/handler-express.js.map +1 -1
  26. package/lib/files/gridfs/handler-fastify.d.ts.map +1 -1
  27. package/lib/files/gridfs/handler-fastify.js +50 -13
  28. package/lib/files/gridfs/handler-fastify.js.map +1 -1
  29. package/lib/files/gridfs/module.d.ts +2 -2
  30. package/lib/files/minio/handler-express.d.ts.map +1 -1
  31. package/lib/files/minio/handler-express.js +4 -7
  32. package/lib/files/minio/handler-express.js.map +1 -1
  33. package/lib/files/minio/handler-fastify.js +2 -2
  34. package/lib/files/minio/handler-fastify.js.map +1 -1
  35. package/lib/files/minio/index.d.ts +1 -1
  36. package/lib/files/minio/index.d.ts.map +1 -1
  37. package/lib/files/minio/index.js +7 -7
  38. package/lib/files/minio/index.js.map +1 -1
  39. package/lib/files/minio/minio-adapter.d.ts +6 -0
  40. package/lib/files/minio/minio-adapter.d.ts.map +1 -0
  41. package/lib/files/minio/minio-adapter.js +181 -0
  42. package/lib/files/minio/minio-adapter.js.map +1 -0
  43. package/lib/files/minio/minio-webhook.d.ts +2 -0
  44. package/lib/files/minio/minio-webhook.d.ts.map +1 -0
  45. package/lib/files/minio/minio-webhook.js +33 -0
  46. package/lib/files/minio/minio-webhook.js.map +1 -0
  47. package/lib/filters/local-search.js +1 -1
  48. package/lib/filters/local-search.js.map +1 -1
  49. package/lib/filters/strict-equal.js +0 -18
  50. package/lib/filters/strict-equal.js.map +1 -1
  51. package/lib/payment/apple-iap/adapter.js +12 -10
  52. package/lib/payment/apple-iap/adapter.js.map +1 -1
  53. package/lib/payment/apple-iap/db/AppleTransactionsCollection.d.ts +1 -1
  54. package/lib/payment/apple-iap/db/AppleTransactionsCollection.d.ts.map +1 -1
  55. package/lib/payment/apple-iap/handler-express.d.ts.map +1 -1
  56. package/lib/payment/apple-iap/handler-express.js +14 -10
  57. package/lib/payment/apple-iap/handler-express.js.map +1 -1
  58. package/lib/payment/apple-iap/handler-fastify.d.ts.map +1 -1
  59. package/lib/payment/apple-iap/handler-fastify.js +15 -8
  60. package/lib/payment/apple-iap/handler-fastify.js.map +1 -1
  61. package/lib/payment/apple-iap/module/configureAppleTransactionsModule.d.ts +9 -0
  62. package/lib/payment/apple-iap/module/configureAppleTransactionsModule.d.ts.map +1 -0
  63. package/lib/payment/apple-iap/module/configureAppleTransactionsModule.js +17 -0
  64. package/lib/payment/apple-iap/module/configureAppleTransactionsModule.js.map +1 -0
  65. package/lib/payment/apple-iap/module.d.ts +4 -4
  66. package/lib/payment/apple-iap/module.d.ts.map +1 -1
  67. package/lib/payment/apple-iap/module.js +4 -2
  68. package/lib/payment/apple-iap/module.js.map +1 -1
  69. package/lib/payment/braintree.js +3 -1
  70. package/lib/payment/braintree.js.map +1 -1
  71. package/lib/payment/cryptopay/db/CryptopayTransactions.d.ts +1 -1
  72. package/lib/payment/cryptopay/db/CryptopayTransactions.d.ts.map +1 -1
  73. package/lib/payment/cryptopay/derive-btc-address.d.ts.map +1 -1
  74. package/lib/payment/cryptopay/derive-btc-address.js +2 -3
  75. package/lib/payment/cryptopay/derive-btc-address.js.map +1 -1
  76. package/lib/payment/cryptopay/derive-eth-address.d.ts.map +1 -1
  77. package/lib/payment/cryptopay/derive-eth-address.js +5 -3
  78. package/lib/payment/cryptopay/derive-eth-address.js.map +1 -1
  79. package/lib/payment/cryptopay/handle-webhook.js +2 -2
  80. package/lib/payment/cryptopay/handle-webhook.js.map +1 -1
  81. package/lib/payment/cryptopay/handler-express.d.ts.map +1 -1
  82. package/lib/payment/cryptopay/handler-express.js +4 -7
  83. package/lib/payment/cryptopay/handler-express.js.map +1 -1
  84. package/lib/payment/cryptopay/handler-fastify.js +1 -1
  85. package/lib/payment/cryptopay/handler-fastify.js.map +1 -1
  86. package/lib/payment/cryptopay/middleware.d.ts +2 -0
  87. package/lib/payment/cryptopay/middleware.d.ts.map +1 -0
  88. package/lib/payment/cryptopay/middleware.js +75 -0
  89. package/lib/payment/cryptopay/middleware.js.map +1 -0
  90. package/lib/payment/cryptopay/module/configureCryptopayModule.d.ts +25 -0
  91. package/lib/payment/cryptopay/module/configureCryptopayModule.d.ts.map +1 -0
  92. package/lib/payment/cryptopay/module/configureCryptopayModule.js +75 -0
  93. package/lib/payment/cryptopay/module/configureCryptopayModule.js.map +1 -0
  94. package/lib/payment/cryptopay/module.d.ts +2 -2
  95. package/lib/payment/cryptopay/module.d.ts.map +1 -1
  96. package/lib/payment/cryptopay/module.js +4 -4
  97. package/lib/payment/cryptopay/module.js.map +1 -1
  98. package/lib/payment/cryptopay/plugin.d.ts.map +1 -1
  99. package/lib/payment/cryptopay/plugin.js +18 -4
  100. package/lib/payment/cryptopay/plugin.js.map +1 -1
  101. package/lib/payment/datatrans-v2/handler-express.d.ts.map +1 -1
  102. package/lib/payment/datatrans-v2/handler-express.js +13 -11
  103. package/lib/payment/datatrans-v2/handler-express.js.map +1 -1
  104. package/lib/payment/datatrans-v2/handler-fastify.d.ts.map +1 -1
  105. package/lib/payment/datatrans-v2/handler-fastify.js +11 -5
  106. package/lib/payment/datatrans-v2/handler-fastify.js.map +1 -1
  107. package/lib/payment/datatrans-v2/index.js +63 -37
  108. package/lib/payment/datatrans-v2/index.js.map +1 -1
  109. package/lib/payment/datatrans-v2/middleware.d.ts +2 -0
  110. package/lib/payment/datatrans-v2/middleware.d.ts.map +1 -0
  111. package/lib/payment/datatrans-v2/middleware.js +68 -0
  112. package/lib/payment/datatrans-v2/middleware.js.map +1 -0
  113. package/lib/payment/datatrans-v2/parseRegistrationData.d.ts +1 -1
  114. package/lib/payment/datatrans-v2/parseRegistrationData.d.ts.map +1 -1
  115. package/lib/payment/paypal-checkout.js +4 -2
  116. package/lib/payment/paypal-checkout.js.map +1 -1
  117. package/lib/payment/payrexx/api/index.d.ts +1 -1
  118. package/lib/payment/payrexx/api/index.d.ts.map +1 -1
  119. package/lib/payment/payrexx/api/makeFetcher.d.ts +1 -1
  120. package/lib/payment/payrexx/api/makeFetcher.d.ts.map +1 -1
  121. package/lib/payment/payrexx/api/makeFetcher.js +1 -1
  122. package/lib/payment/payrexx/api/makeFetcher.js.map +1 -1
  123. package/lib/payment/payrexx/handler-express.d.ts.map +1 -1
  124. package/lib/payment/payrexx/handler-express.js +15 -15
  125. package/lib/payment/payrexx/handler-express.js.map +1 -1
  126. package/lib/payment/payrexx/handler-fastify.js +23 -15
  127. package/lib/payment/payrexx/handler-fastify.js.map +1 -1
  128. package/lib/payment/payrexx/index.js +21 -15
  129. package/lib/payment/payrexx/index.js.map +1 -1
  130. package/lib/payment/payrexx/middleware.d.ts +2 -0
  131. package/lib/payment/payrexx/middleware.d.ts.map +1 -0
  132. package/lib/payment/payrexx/middleware.js +86 -0
  133. package/lib/payment/payrexx/middleware.js.map +1 -0
  134. package/lib/payment/postfinance-checkout/api-client.d.ts.map +1 -1
  135. package/lib/payment/postfinance-checkout/api-client.js +7 -7
  136. package/lib/payment/postfinance-checkout/api-client.js.map +1 -1
  137. package/lib/payment/postfinance-checkout/handler-express.js +7 -8
  138. package/lib/payment/postfinance-checkout/handler-express.js.map +1 -1
  139. package/lib/payment/postfinance-checkout/handler-fastify.d.ts.map +1 -1
  140. package/lib/payment/postfinance-checkout/handler-fastify.js +6 -4
  141. package/lib/payment/postfinance-checkout/handler-fastify.js.map +1 -1
  142. package/lib/payment/postfinance-checkout/index.d.ts.map +1 -1
  143. package/lib/payment/postfinance-checkout/index.js +20 -7
  144. package/lib/payment/postfinance-checkout/index.js.map +1 -1
  145. package/lib/payment/postfinance-checkout/middleware.d.ts +2 -0
  146. package/lib/payment/postfinance-checkout/middleware.d.ts.map +1 -0
  147. package/lib/payment/postfinance-checkout/middleware.js +38 -0
  148. package/lib/payment/postfinance-checkout/middleware.js.map +1 -0
  149. package/lib/payment/saferpay/adapter.d.ts.map +1 -1
  150. package/lib/payment/saferpay/adapter.js +9 -0
  151. package/lib/payment/saferpay/adapter.js.map +1 -1
  152. package/lib/payment/saferpay/handler-express.d.ts.map +1 -1
  153. package/lib/payment/saferpay/handler-express.js +10 -8
  154. package/lib/payment/saferpay/handler-express.js.map +1 -1
  155. package/lib/payment/saferpay/handler-fastify.d.ts.map +1 -1
  156. package/lib/payment/saferpay/handler-fastify.js +11 -5
  157. package/lib/payment/saferpay/handler-fastify.js.map +1 -1
  158. package/lib/payment/saferpay/middleware.d.ts +2 -0
  159. package/lib/payment/saferpay/middleware.d.ts.map +1 -0
  160. package/lib/payment/saferpay/middleware.js +57 -0
  161. package/lib/payment/saferpay/middleware.js.map +1 -0
  162. package/lib/payment/saferpay/module/configureSaferpayTransactionsModule.d.ts +10 -0
  163. package/lib/payment/saferpay/module/configureSaferpayTransactionsModule.d.ts.map +1 -0
  164. package/lib/payment/saferpay/module/configureSaferpayTransactionsModule.js +24 -0
  165. package/lib/payment/saferpay/module/configureSaferpayTransactionsModule.js.map +1 -0
  166. package/lib/payment/saferpay/module.d.ts +2 -2
  167. package/lib/payment/stripe/handler-express.js +25 -17
  168. package/lib/payment/stripe/handler-express.js.map +1 -1
  169. package/lib/payment/stripe/handler-fastify.d.ts.map +1 -1
  170. package/lib/payment/stripe/handler-fastify.js +33 -12
  171. package/lib/payment/stripe/handler-fastify.js.map +1 -1
  172. package/lib/payment/stripe/index.js +21 -15
  173. package/lib/payment/stripe/index.js.map +1 -1
  174. package/lib/payment/stripe/middleware.d.ts +6 -0
  175. package/lib/payment/stripe/middleware.d.ts.map +1 -0
  176. package/lib/payment/stripe/middleware.js +114 -0
  177. package/lib/payment/stripe/middleware.js.map +1 -0
  178. package/lib/payment/stripe/stripe.d.ts +2 -2
  179. package/lib/payment/stripe/stripe.d.ts.map +1 -1
  180. package/lib/payment/stripe/stripe.js +14 -11
  181. package/lib/payment/stripe/stripe.js.map +1 -1
  182. package/lib/plugins-index.d.ts +48 -0
  183. package/lib/plugins-index.d.ts.map +1 -0
  184. package/lib/plugins-index.js +107 -0
  185. package/lib/plugins-index.js.map +1 -0
  186. package/lib/presets/all.d.ts +8 -6
  187. package/lib/presets/all.d.ts.map +1 -1
  188. package/lib/presets/all.js +3 -1
  189. package/lib/presets/all.js.map +1 -1
  190. package/lib/pricing/delivery-swiss-tax.d.ts.map +1 -1
  191. package/lib/pricing/delivery-swiss-tax.js +13 -20
  192. package/lib/pricing/delivery-swiss-tax.js.map +1 -1
  193. package/lib/pricing/order-discount.d.ts.map +1 -1
  194. package/lib/pricing/order-discount.js +5 -3
  195. package/lib/pricing/order-discount.js.map +1 -1
  196. package/lib/pricing/order-round.d.ts.map +1 -1
  197. package/lib/pricing/order-round.js +4 -3
  198. package/lib/pricing/order-round.js.map +1 -1
  199. package/lib/pricing/product-catalog-price-options.d.ts +2 -0
  200. package/lib/pricing/product-catalog-price-options.d.ts.map +1 -0
  201. package/lib/pricing/product-catalog-price-options.js +52 -0
  202. package/lib/pricing/product-catalog-price-options.js.map +1 -0
  203. package/lib/pricing/product-catalog-price.d.ts.map +1 -1
  204. package/lib/pricing/product-catalog-price.js +26 -2
  205. package/lib/pricing/product-catalog-price.js.map +1 -1
  206. package/lib/pricing/product-price-rateconversion.js +3 -3
  207. package/lib/pricing/product-price-rateconversion.js.map +1 -1
  208. package/lib/pricing/product-swiss-tax.d.ts +1 -5
  209. package/lib/pricing/product-swiss-tax.d.ts.map +1 -1
  210. package/lib/pricing/product-swiss-tax.js +26 -22
  211. package/lib/pricing/product-swiss-tax.js.map +1 -1
  212. package/lib/pricing/tax/ch.d.ts +7 -2
  213. package/lib/pricing/tax/ch.d.ts.map +1 -1
  214. package/lib/pricing/tax/ch.js +16 -1
  215. package/lib/pricing/tax/ch.js.map +1 -1
  216. package/lib/pricing/utils/isDeliveryAddressInCountry.d.ts +7 -0
  217. package/lib/pricing/utils/isDeliveryAddressInCountry.d.ts.map +1 -0
  218. package/lib/pricing/utils/isDeliveryAddressInCountry.js +13 -0
  219. package/lib/pricing/utils/isDeliveryAddressInCountry.js.map +1 -0
  220. package/lib/warehousing/eth-minter.js +23 -11
  221. package/lib/warehousing/eth-minter.js.map +1 -1
  222. package/lib/worker/budgetsms.d.ts +10 -0
  223. package/lib/worker/budgetsms.d.ts.map +1 -0
  224. package/lib/worker/budgetsms.js +217 -0
  225. package/lib/worker/budgetsms.js.map +1 -0
  226. package/lib/worker/bulk-import.d.ts +1 -1
  227. package/lib/worker/bulk-import.d.ts.map +1 -1
  228. package/lib/worker/bulk-import.js +11 -33
  229. package/lib/worker/bulk-import.js.map +1 -1
  230. package/lib/worker/bulkgate.d.ts +2 -0
  231. package/lib/worker/bulkgate.d.ts.map +1 -0
  232. package/lib/worker/bulkgate.js +104 -0
  233. package/lib/worker/bulkgate.js.map +1 -0
  234. package/lib/worker/email.d.ts.map +1 -1
  235. package/lib/worker/email.js +25 -7
  236. package/lib/worker/email.js.map +1 -1
  237. package/lib/worker/enrollment-order-generator.d.ts.map +1 -1
  238. package/lib/worker/enrollment-order-generator.js +7 -49
  239. package/lib/worker/enrollment-order-generator.js.map +1 -1
  240. package/lib/worker/error-notifications.js +1 -1
  241. package/lib/worker/error-notifications.js.map +1 -1
  242. package/lib/worker/export-token.d.ts.map +1 -1
  243. package/lib/worker/export-token.js +0 -1
  244. package/lib/worker/export-token.js.map +1 -1
  245. package/lib/worker/message.d.ts +1 -1
  246. package/lib/worker/message.d.ts.map +1 -1
  247. package/lib/worker/message.js +4 -2
  248. package/lib/worker/message.js.map +1 -1
  249. package/lib/worker/sms.js +17 -17
  250. package/lib/worker/sms.js.map +1 -1
  251. package/lib/worker/twilio.d.ts +2 -0
  252. package/lib/worker/twilio.d.ts.map +1 -0
  253. package/lib/worker/twilio.js +60 -0
  254. package/lib/worker/twilio.js.map +1 -0
  255. package/package.json +22 -33
  256. package/src/delivery/send-message.ts +1 -1
  257. package/src/enrollments/licensed.ts +15 -2
  258. package/src/files/gridfs/adapter.ts +12 -7
  259. package/src/files/gridfs/handler-express.ts +23 -25
  260. package/src/files/gridfs/handler-fastify.ts +53 -14
  261. package/src/files/minio/handler-express.ts +4 -7
  262. package/src/files/minio/handler-fastify.ts +2 -2
  263. package/src/files/minio/index.ts +16 -16
  264. package/src/filters/local-search.ts +1 -1
  265. package/src/filters/strict-equal.ts +0 -21
  266. package/src/payment/apple-iap/adapter.ts +12 -14
  267. package/src/payment/apple-iap/db/AppleTransactionsCollection.ts +1 -1
  268. package/src/payment/apple-iap/handler-express.ts +17 -11
  269. package/src/payment/apple-iap/handler-fastify.ts +19 -9
  270. package/src/payment/apple-iap/module.ts +9 -4
  271. package/src/payment/braintree.ts +4 -1
  272. package/src/payment/cryptopay/db/CryptopayTransactions.ts +1 -1
  273. package/src/payment/cryptopay/derive-btc-address.ts +1 -3
  274. package/src/payment/cryptopay/derive-eth-address.ts +5 -3
  275. package/src/payment/cryptopay/handle-webhook.ts +6 -6
  276. package/src/payment/cryptopay/handler-express.ts +4 -7
  277. package/src/payment/cryptopay/handler-fastify.ts +1 -1
  278. package/src/payment/cryptopay/module.ts +8 -5
  279. package/src/payment/cryptopay/plugin.ts +21 -4
  280. package/src/payment/datatrans-v2/handler-express.ts +17 -12
  281. package/src/payment/datatrans-v2/handler-fastify.ts +15 -6
  282. package/src/payment/datatrans-v2/index.ts +82 -50
  283. package/src/payment/paypal-checkout.ts +4 -2
  284. package/src/payment/payrexx/api/index.ts +1 -1
  285. package/src/payment/payrexx/api/makeFetcher.ts +2 -2
  286. package/src/payment/payrexx/handler-express.ts +24 -32
  287. package/src/payment/payrexx/handler-fastify.ts +33 -33
  288. package/src/payment/payrexx/index.ts +26 -16
  289. package/src/payment/postfinance-checkout/api-client.ts +13 -8
  290. package/src/payment/postfinance-checkout/handler-express.ts +8 -8
  291. package/src/payment/postfinance-checkout/handler-fastify.ts +7 -4
  292. package/src/payment/postfinance-checkout/index.ts +20 -8
  293. package/src/payment/saferpay/adapter.ts +14 -2
  294. package/src/payment/saferpay/handler-express.ts +14 -13
  295. package/src/payment/saferpay/handler-fastify.ts +14 -9
  296. package/src/payment/stripe/handler-express.ts +33 -33
  297. package/src/payment/stripe/handler-fastify.ts +40 -27
  298. package/src/payment/stripe/index.ts +18 -16
  299. package/src/payment/stripe/stripe.ts +17 -12
  300. package/src/presets/all.ts +3 -1
  301. package/src/pricing/delivery-swiss-tax.ts +16 -31
  302. package/src/pricing/order-discount.ts +6 -4
  303. package/src/pricing/order-round.ts +5 -4
  304. package/src/pricing/product-catalog-price-options.ts +67 -0
  305. package/src/pricing/product-catalog-price.ts +25 -2
  306. package/src/pricing/product-price-rateconversion.ts +3 -3
  307. package/src/pricing/product-swiss-tax.ts +39 -40
  308. package/src/pricing/tax/ch.ts +33 -7
  309. package/src/pricing/utils/isDeliveryAddressInCountry.test.ts +106 -0
  310. package/src/pricing/utils/isDeliveryAddressInCountry.ts +26 -0
  311. package/src/warehousing/eth-minter.ts +30 -11
  312. package/src/worker/budgetsms.ts +268 -0
  313. package/src/worker/bulk-import.ts +12 -53
  314. package/src/worker/bulkgate.ts +138 -0
  315. package/src/worker/email.ts +30 -8
  316. package/src/worker/enrollment-order-generator.ts +14 -72
  317. package/src/worker/error-notifications.ts +2 -2
  318. package/src/worker/export-token.ts +0 -1
  319. package/src/worker/message.ts +5 -3
  320. package/src/worker/{sms.ts → twilio.ts} +15 -26
  321. package/src/pricing/product-swiss-tax.test.ts +0 -139
@@ -1,73 +1,7 @@
1
- import { Enrollment } from '@unchainedshop/core-enrollments';
2
- import { OrderPosition } from '@unchainedshop/core-orders';
3
1
  import { enrollmentsSettings, EnrollmentStatus } from '@unchainedshop/core-enrollments';
4
- import {
5
- EnrollmentDirector,
6
- UnchainedCore,
7
- WorkerDirector,
8
- WorkerAdapter,
9
- IWorkerAdapter,
10
- } from '@unchainedshop/core';
2
+ import { EnrollmentDirector, WorkerDirector, WorkerAdapter, IWorkerAdapter } from '@unchainedshop/core';
11
3
 
12
- const generateOrder = async (
13
- enrollment: Enrollment,
14
- params: {
15
- orderPositions: OrderPosition[];
16
- } & Record<string, any>,
17
- unchainedAPI: Pick<UnchainedCore, 'modules' | 'services'>,
18
- ) => {
19
- if (!enrollment.payment || !enrollment.delivery) return null;
20
-
21
- const { modules, services } = unchainedAPI;
22
- const { orderPositions, ...configuration } = params;
23
- let order = await modules.orders.create({
24
- userId: enrollment.userId,
25
- currencyCode: enrollment.currencyCode,
26
- countryCode: enrollment.countryCode,
27
- contact: enrollment.contact,
28
- billingAddress: enrollment.billingAddress,
29
- originEnrollmentId: enrollment._id,
30
- ...configuration,
31
- });
32
- const orderId = order._id;
33
-
34
- if (orderPositions) {
35
- await Promise.all(
36
- orderPositions.map((orderPosition) => modules.orders.positions.addProductItem(orderPosition)),
37
- );
38
- } else {
39
- const product = await modules.products.findProduct({
40
- productId: enrollment.productId,
41
- });
42
- await modules.orders.positions.addProductItem({
43
- quantity: 1,
44
- productId: product._id,
45
- originalProductId: product._id,
46
- orderId: order._id,
47
- });
48
- }
49
-
50
- const { paymentProviderId, context: paymentContext } = enrollment.payment;
51
- if (paymentProviderId) {
52
- await modules.orders.setPaymentProvider(orderId, paymentProviderId);
53
- }
54
-
55
- const { deliveryProviderId, context: deliveryContext } = enrollment.delivery;
56
- if (deliveryProviderId) {
57
- await modules.orders.setDeliveryProvider(orderId, deliveryProviderId);
58
- }
59
-
60
- await services.orders.updateCalculation(orderId);
61
-
62
- order = await services.orders.checkoutOrder(order._id, {
63
- paymentContext,
64
- deliveryContext,
65
- });
66
-
67
- return order;
68
- };
69
-
70
- const GenerateOrderWorker: IWorkerAdapter<any, any> = {
4
+ const GenerateOrderWorker: IWorkerAdapter<never, any> = {
71
5
  ...WorkerAdapter,
72
6
 
73
7
  key: 'shop.unchained.worker-plugin.generate-enrollment-orders',
@@ -76,7 +10,7 @@ const GenerateOrderWorker: IWorkerAdapter<any, any> = {
76
10
  type: 'ENROLLMENT_ORDER_GENERATOR',
77
11
 
78
12
  doWork: async (input, unchainedAPI) => {
79
- const { modules } = unchainedAPI;
13
+ const { modules, services } = unchainedAPI;
80
14
 
81
15
  const enrollments = await modules.enrollments.findEnrollments({
82
16
  status: [EnrollmentStatus.ACTIVE, EnrollmentStatus.PAUSED],
@@ -86,7 +20,13 @@ const GenerateOrderWorker: IWorkerAdapter<any, any> = {
86
20
  await Promise.all(
87
21
  enrollments.map(async (enrollment) => {
88
22
  try {
89
- const director = await EnrollmentDirector.actions({ enrollment }, unchainedAPI);
23
+ const product = await unchainedAPI.modules.products.findProduct({
24
+ productId: enrollment.productId,
25
+ });
26
+ const director = await EnrollmentDirector.actions(
27
+ { enrollment, product: product! },
28
+ unchainedAPI,
29
+ );
90
30
  const period = await director.nextPeriod();
91
31
  if (period) {
92
32
  if (period.isTrial) {
@@ -96,11 +36,13 @@ const GenerateOrderWorker: IWorkerAdapter<any, any> = {
96
36
  return null;
97
37
  }
98
38
  const configuration = await director.configurationForOrder({
99
- ...input,
100
39
  period,
101
40
  });
102
41
  if (configuration) {
103
- const order = await generateOrder(enrollment, configuration, unchainedAPI);
42
+ const order = await services.enrollments.generateOrderFromEnrollment(
43
+ enrollment,
44
+ configuration,
45
+ );
104
46
  if (order) {
105
47
  await modules.enrollments.addEnrollmentPeriod(enrollment._id, {
106
48
  ...period,
@@ -1,4 +1,4 @@
1
- import { WorkStatus } from '@unchainedshop/core-worker';
1
+ import { Work, WorkStatus } from '@unchainedshop/core-worker';
2
2
  import { IWorkerAdapter, WorkerDirector, WorkerAdapter } from '@unchainedshop/core';
3
3
  import later from '@breejs/later';
4
4
 
@@ -22,7 +22,7 @@ export const ErrorNotifications: IWorkerAdapter<Arg, Result> = {
22
22
  type: 'ERROR_NOTIFICATIONS',
23
23
 
24
24
  doWork: async (args, context, workId) => {
25
- const work = await context.modules.worker.findWork({ workId });
25
+ const work = (await context.modules.worker.findWork({ workId })) as Work;
26
26
  const secondsPassed = args?.secondsPassed || 60;
27
27
  const to = new Date();
28
28
  const from = new Date(new Date(work.scheduled).getTime() - secondsPassed * 1000);
@@ -21,7 +21,6 @@ export const configureExportToken = (unchainedAPI: UnchainedCore) => {
21
21
  if (work.type === 'EXPORT_TOKEN' && work.success) {
22
22
  await unchainedAPI.modules.warehousing.updateTokenOwnership({
23
23
  tokenId: work.input.token._id,
24
- userId: null,
25
24
  walletAddress: work.input.recipientWalletAddress,
26
25
  });
27
26
  }
@@ -2,7 +2,7 @@ import { MessagingDirector, IWorkerAdapter, WorkerAdapter, WorkerDirector } from
2
2
  import { Work } from '@unchainedshop/core-worker';
3
3
 
4
4
  export const MessageWorker: IWorkerAdapter<
5
- { template: string; _id?: string; [x: string]: any },
5
+ { template: string; _id: string; [x: string]: any },
6
6
  { info?: string; forked?: Work[] }
7
7
  > = {
8
8
  ...WorkerAdapter,
@@ -16,6 +16,8 @@ export const MessageWorker: IWorkerAdapter<
16
16
  try {
17
17
  const templateResolver = MessagingDirector.getTemplate(template);
18
18
 
19
+ if (!templateResolver) throw new Error(`No template resolver found for template ${template}`);
20
+
19
21
  const workConfigurations = await templateResolver(
20
22
  {
21
23
  template,
@@ -31,13 +33,13 @@ export const MessageWorker: IWorkerAdapter<
31
33
  ...workConfiguration,
32
34
  originalWorkId: workId,
33
35
  });
34
- delete work.input;
36
+ delete (work as any).input; // Remove input from returned work for privacy
35
37
  return work;
36
38
  }),
37
39
  );
38
40
  return { success: true, result: { forked } };
39
41
  }
40
- return { success: true, result: { info: 'Skipped Message' } };
42
+ return { success: true, result: { forked: [] } };
41
43
  } catch (err) {
42
44
  return {
43
45
  success: false,
@@ -5,41 +5,29 @@ const { TWILIO_ACCOUNT_SID, TWILIO_AUTH_TOKEN, TWILIO_SMS_FROM } = process.env;
5
5
  const SmsWorkerPlugin: IWorkerAdapter<
6
6
  {
7
7
  from?: string;
8
- to?: string;
9
- text?: string;
8
+ to: string;
9
+ text: string;
10
+ [key: string]: any; // Allow additional parameters
10
11
  },
11
12
  any
12
13
  > = {
13
14
  ...WorkerAdapter,
14
15
 
15
- key: 'shop.unchained.worker-plugin.sms',
16
- label: 'Send a SMS through Twilio',
16
+ key: 'shop.unchained.worker-plugin.twilio',
17
+ label: 'Send Messages through Twilio',
17
18
  version: '1.0.0',
18
19
 
19
- type: 'SMS',
20
+ type: 'TWILIO',
20
21
 
21
- doWork: async ({ from, to, text }) => {
22
- if (!TWILIO_SMS_FROM && !from) {
23
- return {
24
- success: false,
25
- error: {
26
- name: 'SENDER_REQUIRED',
27
- message: 'SMS requires a from, TWILIO_SMS_FROM not set',
28
- },
29
- };
30
- }
22
+ doWork: async ({ from, to, text, ...params }) => {
23
+ try {
24
+ if (!TWILIO_SMS_FROM && !from)
25
+ throw new Error(
26
+ 'Missing Twilio "from" number. Set TWILIO_SMS_FROM env var or provide "from" in input',
27
+ );
31
28
 
32
- if (!to) {
33
- return {
34
- success: false,
35
- error: {
36
- name: 'RECIPIENT_REQUIRED',
37
- message: 'SMS requires a to',
38
- },
39
- };
40
- }
29
+ if (!to) throw new Error('Missing "to" in input');
41
30
 
42
- try {
43
31
  const url = `https://api.twilio.com/2010-04-01/Accounts/${TWILIO_ACCOUNT_SID}/Messages.json`;
44
32
  const response = await fetch(url, {
45
33
  method: 'POST',
@@ -49,8 +37,9 @@ const SmsWorkerPlugin: IWorkerAdapter<
49
37
  },
50
38
  body: new URLSearchParams({
51
39
  Body: text || '',
52
- From: from || TWILIO_SMS_FROM,
40
+ From: from || TWILIO_SMS_FROM!,
53
41
  To: to,
42
+ ...params, // Include any additional parameters passed
54
43
  }),
55
44
  });
56
45
 
@@ -1,139 +0,0 @@
1
- import { describe, it } from 'node:test';
2
- import assert from 'node:assert';
3
-
4
- import { getTaxRate, isDeliveryAddressInSwitzerland } from './product-swiss-tax.js';
5
-
6
- describe('ProductSwissTax', () => {
7
- describe('getTaxRate', () => {
8
- it('default rate', () => {
9
- assert.strictEqual(
10
- getTaxRate({
11
- product: {} as any,
12
- order: {} as any,
13
- } as any),
14
- 0.081,
15
- );
16
- });
17
-
18
- it('reduced rate', () => {
19
- assert.strictEqual(
20
- getTaxRate({
21
- product: {
22
- tags: ['swiss-tax-category:reduced'],
23
- },
24
- order: {},
25
- } as any),
26
- 0.026,
27
- );
28
- });
29
-
30
- it('special rate', () => {
31
- assert.strictEqual(
32
- getTaxRate({
33
- product: {
34
- tags: ['swiss-tax-category:special'],
35
- },
36
- order: {},
37
- } as any),
38
- 0.038,
39
- );
40
- });
41
-
42
- it('default rate', () => {
43
- assert.strictEqual(
44
- getTaxRate({
45
- product: {
46
- tags: ['swiss-tax-category:default'],
47
- },
48
- order: {},
49
- } as any),
50
- 0.081,
51
- );
52
- });
53
- });
54
-
55
- describe('isDeliveryAddressInSwitzerland', () => {
56
- const context = {
57
- modules: {
58
- orders: {
59
- deliveries: {
60
- findDelivery: async ({ orderDeliveryId }) => {
61
- if (orderDeliveryId === 'CH' || orderDeliveryId === 'LI')
62
- return { context: { address: { countryCode: 'CH' } } };
63
- if (orderDeliveryId === null) return { context: { address: null } };
64
- return { context: { address: { countryCode: 'RT' } } };
65
- },
66
- },
67
- },
68
- },
69
- order: {
70
- deliveryId: 'CH',
71
- billingAddress: { countryCode: 'LI' },
72
- },
73
- countryCode: 'CH',
74
- };
75
- it('Should return true when passed country code CH', async () => {
76
- assert.strictEqual(
77
- await isDeliveryAddressInSwitzerland({ ...context, countryCode: 'ch', order: null } as any),
78
- true,
79
- );
80
- });
81
-
82
- it('Should return true when passed country code LI', async () => {
83
- assert.strictEqual(
84
- await isDeliveryAddressInSwitzerland({ ...context, countryCode: 'LI', order: null } as any),
85
- true,
86
- );
87
- });
88
-
89
- it('Should return false when country is neither CH nor LI and order is null', async () => {
90
- assert.strictEqual(
91
- await isDeliveryAddressInSwitzerland({ ...context, countryCode: 'ET', order: null } as any),
92
- false,
93
- );
94
- });
95
-
96
- it('Order should take precedence over country parameter', async () => {
97
- // not CH or LI order so returns false
98
- assert.strictEqual(
99
- await isDeliveryAddressInSwitzerland({
100
- ...context,
101
- countryCode: 'CH',
102
- order: {
103
- deliveryId: 'ET',
104
- billingAddress: { countryCode: 'ET' },
105
- },
106
- } as any),
107
- false,
108
- );
109
- });
110
-
111
- it('If order is not from CH and LI but billingAddress is, it should take precedence over country ', async () => {
112
- assert.strictEqual(
113
- await isDeliveryAddressInSwitzerland({
114
- ...context,
115
- countryCode: 'IT',
116
- order: {
117
- deliveryId: null,
118
- billingAddress: { countryCode: 'CH' },
119
- },
120
- } as any),
121
- true,
122
- );
123
- });
124
-
125
- it('Should return false if billingAddress is neither CH or LI and order does not have address', async () => {
126
- assert.strictEqual(
127
- await isDeliveryAddressInSwitzerland({
128
- ...context,
129
- country: null,
130
- order: {
131
- deliveryId: null,
132
- billingAddress: { countryCode: 'HH' },
133
- },
134
- } as any),
135
- false,
136
- );
137
- });
138
- });
139
- });