@unchainedshop/plugins 4.0.0-rc.2 → 4.0.0-rc.21

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 (347) 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 +19 -11
  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 +27 -24
  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 +57 -14
  28. package/lib/files/gridfs/handler-fastify.js.map +1 -1
  29. package/lib/files/gridfs/module.d.ts +4 -4
  30. package/lib/files/gridfs/module.d.ts.map +1 -1
  31. package/lib/files/gridfs/module.js +2 -2
  32. package/lib/files/gridfs/module.js.map +1 -1
  33. package/lib/files/minio/handler-express.d.ts.map +1 -1
  34. package/lib/files/minio/handler-express.js +4 -7
  35. package/lib/files/minio/handler-express.js.map +1 -1
  36. package/lib/files/minio/handler-fastify.js +2 -2
  37. package/lib/files/minio/handler-fastify.js.map +1 -1
  38. package/lib/files/minio/index.d.ts +1 -1
  39. package/lib/files/minio/index.d.ts.map +1 -1
  40. package/lib/files/minio/index.js +7 -7
  41. package/lib/files/minio/index.js.map +1 -1
  42. package/lib/files/minio/minio-adapter.d.ts +6 -0
  43. package/lib/files/minio/minio-adapter.d.ts.map +1 -0
  44. package/lib/files/minio/minio-adapter.js +181 -0
  45. package/lib/files/minio/minio-adapter.js.map +1 -0
  46. package/lib/files/minio/minio-webhook.d.ts +2 -0
  47. package/lib/files/minio/minio-webhook.d.ts.map +1 -0
  48. package/lib/files/minio/minio-webhook.js +33 -0
  49. package/lib/files/minio/minio-webhook.js.map +1 -0
  50. package/lib/filters/local-search.js +1 -1
  51. package/lib/filters/local-search.js.map +1 -1
  52. package/lib/payment/apple-iap/adapter.js +12 -10
  53. package/lib/payment/apple-iap/adapter.js.map +1 -1
  54. package/lib/payment/apple-iap/db/AppleTransactionsCollection.d.ts +1 -1
  55. package/lib/payment/apple-iap/db/AppleTransactionsCollection.d.ts.map +1 -1
  56. package/lib/payment/apple-iap/handler-express.d.ts.map +1 -1
  57. package/lib/payment/apple-iap/handler-express.js +14 -10
  58. package/lib/payment/apple-iap/handler-express.js.map +1 -1
  59. package/lib/payment/apple-iap/handler-fastify.d.ts.map +1 -1
  60. package/lib/payment/apple-iap/handler-fastify.js +15 -8
  61. package/lib/payment/apple-iap/handler-fastify.js.map +1 -1
  62. package/lib/payment/apple-iap/module/configureAppleTransactionsModule.d.ts +9 -0
  63. package/lib/payment/apple-iap/module/configureAppleTransactionsModule.d.ts.map +1 -0
  64. package/lib/payment/apple-iap/module/configureAppleTransactionsModule.js +17 -0
  65. package/lib/payment/apple-iap/module/configureAppleTransactionsModule.js.map +1 -0
  66. package/lib/payment/apple-iap/module.d.ts +4 -4
  67. package/lib/payment/apple-iap/module.d.ts.map +1 -1
  68. package/lib/payment/apple-iap/module.js +4 -2
  69. package/lib/payment/apple-iap/module.js.map +1 -1
  70. package/lib/payment/braintree.js +3 -1
  71. package/lib/payment/braintree.js.map +1 -1
  72. package/lib/payment/cryptopay/db/CryptopayTransactions.d.ts +1 -1
  73. package/lib/payment/cryptopay/db/CryptopayTransactions.d.ts.map +1 -1
  74. package/lib/payment/cryptopay/derive-btc-address.d.ts.map +1 -1
  75. package/lib/payment/cryptopay/derive-btc-address.js +2 -3
  76. package/lib/payment/cryptopay/derive-btc-address.js.map +1 -1
  77. package/lib/payment/cryptopay/derive-eth-address.d.ts.map +1 -1
  78. package/lib/payment/cryptopay/derive-eth-address.js +5 -3
  79. package/lib/payment/cryptopay/derive-eth-address.js.map +1 -1
  80. package/lib/payment/cryptopay/handle-webhook.js +2 -2
  81. package/lib/payment/cryptopay/handle-webhook.js.map +1 -1
  82. package/lib/payment/cryptopay/handler-express.d.ts.map +1 -1
  83. package/lib/payment/cryptopay/handler-express.js +4 -7
  84. package/lib/payment/cryptopay/handler-express.js.map +1 -1
  85. package/lib/payment/cryptopay/handler-fastify.d.ts.map +1 -1
  86. package/lib/payment/cryptopay/handler-fastify.js +1 -1
  87. package/lib/payment/cryptopay/handler-fastify.js.map +1 -1
  88. package/lib/payment/cryptopay/middleware.d.ts +2 -0
  89. package/lib/payment/cryptopay/middleware.d.ts.map +1 -0
  90. package/lib/payment/cryptopay/middleware.js +75 -0
  91. package/lib/payment/cryptopay/middleware.js.map +1 -0
  92. package/lib/payment/cryptopay/module/configureCryptopayModule.d.ts +25 -0
  93. package/lib/payment/cryptopay/module/configureCryptopayModule.d.ts.map +1 -0
  94. package/lib/payment/cryptopay/module/configureCryptopayModule.js +75 -0
  95. package/lib/payment/cryptopay/module/configureCryptopayModule.js.map +1 -0
  96. package/lib/payment/cryptopay/module.d.ts +2 -2
  97. package/lib/payment/cryptopay/module.d.ts.map +1 -1
  98. package/lib/payment/cryptopay/module.js +4 -4
  99. package/lib/payment/cryptopay/module.js.map +1 -1
  100. package/lib/payment/cryptopay/plugin.d.ts.map +1 -1
  101. package/lib/payment/cryptopay/plugin.js +18 -4
  102. package/lib/payment/cryptopay/plugin.js.map +1 -1
  103. package/lib/payment/datatrans-v2/handler-express.d.ts.map +1 -1
  104. package/lib/payment/datatrans-v2/handler-express.js +13 -11
  105. package/lib/payment/datatrans-v2/handler-express.js.map +1 -1
  106. package/lib/payment/datatrans-v2/handler-fastify.d.ts.map +1 -1
  107. package/lib/payment/datatrans-v2/handler-fastify.js +11 -5
  108. package/lib/payment/datatrans-v2/handler-fastify.js.map +1 -1
  109. package/lib/payment/datatrans-v2/index.js +63 -37
  110. package/lib/payment/datatrans-v2/index.js.map +1 -1
  111. package/lib/payment/datatrans-v2/middleware.d.ts +2 -0
  112. package/lib/payment/datatrans-v2/middleware.d.ts.map +1 -0
  113. package/lib/payment/datatrans-v2/middleware.js +68 -0
  114. package/lib/payment/datatrans-v2/middleware.js.map +1 -0
  115. package/lib/payment/datatrans-v2/parseRegistrationData.d.ts +1 -1
  116. package/lib/payment/datatrans-v2/parseRegistrationData.d.ts.map +1 -1
  117. package/lib/payment/paypal-checkout.js +8 -8
  118. package/lib/payment/paypal-checkout.js.map +1 -1
  119. package/lib/payment/payrexx/api/index.d.ts +1 -1
  120. package/lib/payment/payrexx/api/index.d.ts.map +1 -1
  121. package/lib/payment/payrexx/api/makeFetcher.d.ts +1 -1
  122. package/lib/payment/payrexx/api/makeFetcher.d.ts.map +1 -1
  123. package/lib/payment/payrexx/api/makeFetcher.js +1 -1
  124. package/lib/payment/payrexx/api/makeFetcher.js.map +1 -1
  125. package/lib/payment/payrexx/handler-express.d.ts.map +1 -1
  126. package/lib/payment/payrexx/handler-express.js +15 -15
  127. package/lib/payment/payrexx/handler-express.js.map +1 -1
  128. package/lib/payment/payrexx/handler-fastify.js +23 -15
  129. package/lib/payment/payrexx/handler-fastify.js.map +1 -1
  130. package/lib/payment/payrexx/index.js +21 -15
  131. package/lib/payment/payrexx/index.js.map +1 -1
  132. package/lib/payment/payrexx/middleware.d.ts +2 -0
  133. package/lib/payment/payrexx/middleware.d.ts.map +1 -0
  134. package/lib/payment/payrexx/middleware.js +86 -0
  135. package/lib/payment/payrexx/middleware.js.map +1 -0
  136. package/lib/payment/postfinance-checkout/api-client.d.ts +16 -0
  137. package/lib/payment/postfinance-checkout/api-client.d.ts.map +1 -0
  138. package/lib/payment/postfinance-checkout/api-client.js +75 -0
  139. package/lib/payment/postfinance-checkout/api-client.js.map +1 -0
  140. package/lib/payment/postfinance-checkout/api-types.d.ts +98 -0
  141. package/lib/payment/postfinance-checkout/api-types.d.ts.map +1 -0
  142. package/lib/payment/postfinance-checkout/api-types.js +51 -0
  143. package/lib/payment/postfinance-checkout/api-types.js.map +1 -0
  144. package/lib/payment/postfinance-checkout/api.d.ts +5 -5
  145. package/lib/payment/postfinance-checkout/api.d.ts.map +1 -1
  146. package/lib/payment/postfinance-checkout/api.js +38 -62
  147. package/lib/payment/postfinance-checkout/api.js.map +1 -1
  148. package/lib/payment/postfinance-checkout/handler-express.d.ts.map +1 -1
  149. package/lib/payment/postfinance-checkout/handler-express.js +10 -11
  150. package/lib/payment/postfinance-checkout/handler-express.js.map +1 -1
  151. package/lib/payment/postfinance-checkout/handler-fastify.d.ts.map +1 -1
  152. package/lib/payment/postfinance-checkout/handler-fastify.js +10 -8
  153. package/lib/payment/postfinance-checkout/handler-fastify.js.map +1 -1
  154. package/lib/payment/postfinance-checkout/index.d.ts +2 -1
  155. package/lib/payment/postfinance-checkout/index.d.ts.map +1 -1
  156. package/lib/payment/postfinance-checkout/index.js +44 -32
  157. package/lib/payment/postfinance-checkout/index.js.map +1 -1
  158. package/lib/payment/postfinance-checkout/middleware.d.ts +2 -0
  159. package/lib/payment/postfinance-checkout/middleware.d.ts.map +1 -0
  160. package/lib/payment/postfinance-checkout/middleware.js +38 -0
  161. package/lib/payment/postfinance-checkout/middleware.js.map +1 -0
  162. package/lib/payment/postfinance-checkout/utils.d.ts +3 -3
  163. package/lib/payment/postfinance-checkout/utils.d.ts.map +1 -1
  164. package/lib/payment/postfinance-checkout/utils.js +3 -4
  165. package/lib/payment/postfinance-checkout/utils.js.map +1 -1
  166. package/lib/payment/saferpay/adapter.d.ts.map +1 -1
  167. package/lib/payment/saferpay/adapter.js +9 -0
  168. package/lib/payment/saferpay/adapter.js.map +1 -1
  169. package/lib/payment/saferpay/handler-express.d.ts.map +1 -1
  170. package/lib/payment/saferpay/handler-express.js +10 -8
  171. package/lib/payment/saferpay/handler-express.js.map +1 -1
  172. package/lib/payment/saferpay/handler-fastify.d.ts.map +1 -1
  173. package/lib/payment/saferpay/handler-fastify.js +11 -5
  174. package/lib/payment/saferpay/handler-fastify.js.map +1 -1
  175. package/lib/payment/saferpay/middleware.d.ts +2 -0
  176. package/lib/payment/saferpay/middleware.d.ts.map +1 -0
  177. package/lib/payment/saferpay/middleware.js +57 -0
  178. package/lib/payment/saferpay/middleware.js.map +1 -0
  179. package/lib/payment/saferpay/module/configureSaferpayTransactionsModule.d.ts +10 -0
  180. package/lib/payment/saferpay/module/configureSaferpayTransactionsModule.d.ts.map +1 -0
  181. package/lib/payment/saferpay/module/configureSaferpayTransactionsModule.js +24 -0
  182. package/lib/payment/saferpay/module/configureSaferpayTransactionsModule.js.map +1 -0
  183. package/lib/payment/saferpay/module.d.ts +2 -2
  184. package/lib/payment/stripe/handler-express.js +25 -17
  185. package/lib/payment/stripe/handler-express.js.map +1 -1
  186. package/lib/payment/stripe/handler-fastify.d.ts.map +1 -1
  187. package/lib/payment/stripe/handler-fastify.js +33 -12
  188. package/lib/payment/stripe/handler-fastify.js.map +1 -1
  189. package/lib/payment/stripe/index.js +19 -13
  190. package/lib/payment/stripe/index.js.map +1 -1
  191. package/lib/payment/stripe/middleware.d.ts +6 -0
  192. package/lib/payment/stripe/middleware.d.ts.map +1 -0
  193. package/lib/payment/stripe/middleware.js +114 -0
  194. package/lib/payment/stripe/middleware.js.map +1 -0
  195. package/lib/payment/stripe/stripe.d.ts +2 -2
  196. package/lib/payment/stripe/stripe.d.ts.map +1 -1
  197. package/lib/payment/stripe/stripe.js +14 -11
  198. package/lib/payment/stripe/stripe.js.map +1 -1
  199. package/lib/plugins-index.d.ts +48 -0
  200. package/lib/plugins-index.d.ts.map +1 -0
  201. package/lib/plugins-index.js +107 -0
  202. package/lib/plugins-index.js.map +1 -0
  203. package/lib/presets/all.d.ts +9 -7
  204. package/lib/presets/all.d.ts.map +1 -1
  205. package/lib/presets/all.js +3 -1
  206. package/lib/presets/all.js.map +1 -1
  207. package/lib/pricing/delivery-swiss-tax.d.ts.map +1 -1
  208. package/lib/pricing/delivery-swiss-tax.js +13 -20
  209. package/lib/pricing/delivery-swiss-tax.js.map +1 -1
  210. package/lib/pricing/order-discount.d.ts.map +1 -1
  211. package/lib/pricing/order-discount.js +5 -3
  212. package/lib/pricing/order-discount.js.map +1 -1
  213. package/lib/pricing/order-round.d.ts.map +1 -1
  214. package/lib/pricing/order-round.js +4 -3
  215. package/lib/pricing/order-round.js.map +1 -1
  216. package/lib/pricing/product-catalog-price.d.ts.map +1 -1
  217. package/lib/pricing/product-catalog-price.js +26 -2
  218. package/lib/pricing/product-catalog-price.js.map +1 -1
  219. package/lib/pricing/product-price-rateconversion.js +3 -3
  220. package/lib/pricing/product-price-rateconversion.js.map +1 -1
  221. package/lib/pricing/product-swiss-tax.d.ts +1 -5
  222. package/lib/pricing/product-swiss-tax.d.ts.map +1 -1
  223. package/lib/pricing/product-swiss-tax.js +26 -22
  224. package/lib/pricing/product-swiss-tax.js.map +1 -1
  225. package/lib/pricing/tax/ch.d.ts +7 -2
  226. package/lib/pricing/tax/ch.d.ts.map +1 -1
  227. package/lib/pricing/tax/ch.js +16 -1
  228. package/lib/pricing/tax/ch.js.map +1 -1
  229. package/lib/pricing/utils/isDeliveryAddressInCountry.d.ts +7 -0
  230. package/lib/pricing/utils/isDeliveryAddressInCountry.d.ts.map +1 -0
  231. package/lib/pricing/utils/isDeliveryAddressInCountry.js +13 -0
  232. package/lib/pricing/utils/isDeliveryAddressInCountry.js.map +1 -0
  233. package/lib/warehousing/eth-minter.js +23 -11
  234. package/lib/warehousing/eth-minter.js.map +1 -1
  235. package/lib/worker/budgetsms.d.ts +10 -0
  236. package/lib/worker/budgetsms.d.ts.map +1 -0
  237. package/lib/worker/budgetsms.js +217 -0
  238. package/lib/worker/budgetsms.js.map +1 -0
  239. package/lib/worker/bulk-import.d.ts +1 -1
  240. package/lib/worker/bulk-import.d.ts.map +1 -1
  241. package/lib/worker/bulk-import.js +11 -33
  242. package/lib/worker/bulk-import.js.map +1 -1
  243. package/lib/worker/bulkgate.d.ts +2 -0
  244. package/lib/worker/bulkgate.d.ts.map +1 -0
  245. package/lib/worker/bulkgate.js +104 -0
  246. package/lib/worker/bulkgate.js.map +1 -0
  247. package/lib/worker/email.d.ts.map +1 -1
  248. package/lib/worker/email.js +25 -7
  249. package/lib/worker/email.js.map +1 -1
  250. package/lib/worker/enrollment-order-generator.d.ts.map +1 -1
  251. package/lib/worker/enrollment-order-generator.js +7 -49
  252. package/lib/worker/enrollment-order-generator.js.map +1 -1
  253. package/lib/worker/error-notifications.js +1 -1
  254. package/lib/worker/error-notifications.js.map +1 -1
  255. package/lib/worker/export-token.d.ts.map +1 -1
  256. package/lib/worker/export-token.js +0 -1
  257. package/lib/worker/export-token.js.map +1 -1
  258. package/lib/worker/heartbeat.js +2 -8
  259. package/lib/worker/heartbeat.js.map +1 -1
  260. package/lib/worker/message.d.ts +1 -1
  261. package/lib/worker/message.d.ts.map +1 -1
  262. package/lib/worker/message.js +4 -2
  263. package/lib/worker/message.js.map +1 -1
  264. package/lib/worker/sms.js +16 -16
  265. package/lib/worker/sms.js.map +1 -1
  266. package/lib/worker/twilio.d.ts +2 -0
  267. package/lib/worker/twilio.d.ts.map +1 -0
  268. package/lib/worker/twilio.js +60 -0
  269. package/lib/worker/twilio.js.map +1 -0
  270. package/package.json +29 -45
  271. package/src/delivery/send-message.ts +1 -1
  272. package/src/enrollments/licensed.ts +15 -2
  273. package/src/files/gridfs/adapter.ts +24 -10
  274. package/src/files/gridfs/handler-express.ts +32 -24
  275. package/src/files/gridfs/handler-fastify.ts +63 -15
  276. package/src/files/gridfs/module.ts +7 -2
  277. package/src/files/minio/handler-express.ts +4 -7
  278. package/src/files/minio/handler-fastify.ts +2 -2
  279. package/src/files/minio/index.ts +16 -16
  280. package/src/filters/local-search.ts +1 -1
  281. package/src/payment/apple-iap/adapter.ts +12 -14
  282. package/src/payment/apple-iap/db/AppleTransactionsCollection.ts +1 -1
  283. package/src/payment/apple-iap/handler-express.ts +17 -11
  284. package/src/payment/apple-iap/handler-fastify.ts +19 -9
  285. package/src/payment/apple-iap/module.ts +9 -4
  286. package/src/payment/braintree.ts +4 -1
  287. package/src/payment/cryptopay/db/CryptopayTransactions.ts +1 -1
  288. package/src/payment/cryptopay/derive-btc-address.ts +1 -3
  289. package/src/payment/cryptopay/derive-eth-address.ts +5 -3
  290. package/src/payment/cryptopay/handle-webhook.ts +6 -6
  291. package/src/payment/cryptopay/handler-express.ts +4 -7
  292. package/src/payment/cryptopay/handler-fastify.ts +2 -2
  293. package/src/payment/cryptopay/module.ts +8 -5
  294. package/src/payment/cryptopay/plugin.ts +21 -4
  295. package/src/payment/datatrans-v2/handler-express.ts +17 -12
  296. package/src/payment/datatrans-v2/handler-fastify.ts +15 -6
  297. package/src/payment/datatrans-v2/index.ts +82 -50
  298. package/src/payment/paypal-checkout.ts +8 -11
  299. package/src/payment/payrexx/api/index.ts +1 -1
  300. package/src/payment/payrexx/api/makeFetcher.ts +2 -2
  301. package/src/payment/payrexx/handler-express.ts +24 -32
  302. package/src/payment/payrexx/handler-fastify.ts +33 -33
  303. package/src/payment/payrexx/index.ts +26 -16
  304. package/src/payment/postfinance-checkout/api-client.ts +111 -0
  305. package/src/payment/postfinance-checkout/api-types.ts +111 -0
  306. package/src/payment/postfinance-checkout/api.ts +58 -85
  307. package/src/payment/postfinance-checkout/handler-express.ts +11 -13
  308. package/src/payment/postfinance-checkout/handler-fastify.ts +11 -10
  309. package/src/payment/postfinance-checkout/index.ts +60 -38
  310. package/src/payment/postfinance-checkout/utils.ts +5 -10
  311. package/src/payment/saferpay/adapter.ts +14 -2
  312. package/src/payment/saferpay/handler-express.ts +14 -13
  313. package/src/payment/saferpay/handler-fastify.ts +14 -9
  314. package/src/payment/stripe/handler-express.ts +33 -33
  315. package/src/payment/stripe/handler-fastify.ts +40 -27
  316. package/src/payment/stripe/index.ts +17 -13
  317. package/src/payment/stripe/stripe.ts +17 -12
  318. package/src/presets/all.ts +3 -1
  319. package/src/pricing/delivery-swiss-tax.ts +16 -31
  320. package/src/pricing/order-discount.ts +6 -4
  321. package/src/pricing/order-round.ts +5 -4
  322. package/src/pricing/product-catalog-price.ts +25 -2
  323. package/src/pricing/product-price-rateconversion.ts +3 -3
  324. package/src/pricing/product-swiss-tax.ts +39 -40
  325. package/src/pricing/tax/ch.ts +33 -7
  326. package/src/pricing/utils/isDeliveryAddressInCountry.test.ts +106 -0
  327. package/src/pricing/utils/isDeliveryAddressInCountry.ts +26 -0
  328. package/src/warehousing/eth-minter.ts +30 -11
  329. package/src/worker/budgetsms.ts +268 -0
  330. package/src/worker/bulk-import.ts +12 -53
  331. package/src/worker/bulkgate.ts +138 -0
  332. package/src/worker/email.ts +30 -8
  333. package/src/worker/enrollment-order-generator.ts +14 -72
  334. package/src/worker/error-notifications.ts +2 -2
  335. package/src/worker/export-token.ts +0 -1
  336. package/src/worker/heartbeat.ts +2 -9
  337. package/src/worker/message.ts +5 -3
  338. package/src/worker/{sms.ts → twilio.ts} +15 -26
  339. package/lib/payment/cryptopay/de.d.ts +0 -2
  340. package/lib/payment/cryptopay/de.d.ts.map +0 -1
  341. package/lib/payment/cryptopay/de.js +0 -10
  342. package/lib/payment/cryptopay/de.js.map +0 -1
  343. package/lib/payment/cryptopay/derive-btc-address.test copy.d.ts +0 -2
  344. package/lib/payment/cryptopay/derive-btc-address.test copy.d.ts.map +0 -1
  345. package/lib/payment/cryptopay/derive-btc-address.test copy.js +0 -10
  346. package/lib/payment/cryptopay/derive-btc-address.test copy.js.map +0 -1
  347. package/src/pricing/product-swiss-tax.test.ts +0 -139
@@ -0,0 +1,138 @@
1
+ import { IWorkerAdapter, WorkerAdapter, WorkerDirector } from '@unchainedshop/core';
2
+
3
+ const { BULKGATE_APPLICATION_ID, BULKGATE_APPLICATION_TOKEN } = process.env;
4
+
5
+ // BulkGate Simple API for SMS (transactional by default, promotional via boolean)
6
+ const BulkGateWorker: IWorkerAdapter<
7
+ {
8
+ from?: string;
9
+ to?: string;
10
+ text?: string;
11
+ unicode?: boolean;
12
+ country?: string;
13
+ schedule?: string | number; // ISO 8601 format or Unix timestamp
14
+ promotional?: boolean; // Set to true for promotional SMS, defaults to transactional
15
+ [key: string]: any;
16
+ },
17
+ any
18
+ > = {
19
+ ...WorkerAdapter,
20
+
21
+ key: 'shop.unchained.worker-plugin.bulkgate',
22
+ label: 'Send SMS through BulkGate',
23
+ version: '1.0.0',
24
+
25
+ type: 'BULKGATE',
26
+
27
+ doWork: async ({
28
+ from,
29
+ to,
30
+ text,
31
+ unicode = false,
32
+ country,
33
+ schedule,
34
+ promotional = false,
35
+ ...params
36
+ }) => {
37
+ try {
38
+ // Choose API endpoint based on promotional flag
39
+ const url = promotional
40
+ ? 'https://portal.bulkgate.com/api/1.0/simple/promotional'
41
+ : 'https://portal.bulkgate.com/api/1.0/simple/transactional';
42
+
43
+ // Prepare the request body
44
+ const requestBody = {
45
+ application_id: BULKGATE_APPLICATION_ID,
46
+ application_token: BULKGATE_APPLICATION_TOKEN,
47
+ number: to, // Phone number in international format (or semicolon-separated for promotional)
48
+ text: text || '',
49
+ unicode: unicode, // Boolean value for unicode support
50
+ sender_id: from ? 'gText' : 'gSystem', // Use text sender if 'from' is provided
51
+ sender_id_value: from || '', // Custom sender name if using gText
52
+ ...(country && { country }), // Optional country code
53
+ ...(schedule && { schedule }), // Optional scheduled time
54
+ ...params, // Any additional parameters
55
+ };
56
+
57
+ const response = await fetch(url, {
58
+ method: 'POST',
59
+ headers: {
60
+ 'Content-Type': 'application/json',
61
+ 'Cache-Control': 'no-cache',
62
+ },
63
+ body: JSON.stringify(requestBody),
64
+ });
65
+
66
+ const responseData = await response.json();
67
+
68
+ // Check if we have an error response
69
+ if (responseData.error || responseData.type) {
70
+ return {
71
+ success: false,
72
+ error: {
73
+ name: 'BULKGATE_ERROR',
74
+ message:
75
+ responseData.error ||
76
+ `Failed to send ${promotional ? 'promotional' : 'transactional'} SMS`,
77
+ type: responseData.type || null,
78
+ code: responseData.code || response.status,
79
+ detail: responseData.detail || null,
80
+ },
81
+ };
82
+ }
83
+
84
+ // Success response (transactional has specific structure, promotional might vary)
85
+ if (responseData.data) {
86
+ // For transactional SMS, check for specific accepted status
87
+ if (!promotional && responseData.data.status === 'accepted') {
88
+ return {
89
+ success: true,
90
+ result: {
91
+ sms_id: responseData.data.sms_id,
92
+ price: responseData.data.price,
93
+ credit: responseData.data.credit,
94
+ number: responseData.data.number,
95
+ status: responseData.data.status,
96
+ },
97
+ error: null,
98
+ };
99
+ }
100
+
101
+ // For promotional SMS or other successful responses
102
+ if (promotional || responseData.data.status) {
103
+ return {
104
+ success: true,
105
+ result: responseData.data,
106
+ error: null,
107
+ };
108
+ }
109
+ }
110
+
111
+ // Unexpected response format
112
+ return {
113
+ success: false,
114
+ error: {
115
+ name: 'BULKGATE_ERROR',
116
+ message: 'Unexpected response format from BulkGate API',
117
+ response: responseData,
118
+ },
119
+ };
120
+ } catch (err) {
121
+ return {
122
+ success: false,
123
+ error: {
124
+ name: err.name,
125
+ message: err.message,
126
+ stack: err.stack,
127
+ },
128
+ };
129
+ }
130
+ },
131
+ };
132
+
133
+ // Register the plugin
134
+ WorkerDirector.registerAdapter(BulkGateWorker);
135
+
136
+ // Environment variables needed:
137
+ // BULKGATE_APPLICATION_ID=your_application_id
138
+ // BULKGATE_APPLICATION_TOKEN=your_application_token
@@ -1,5 +1,9 @@
1
1
  import { WorkerDirector, WorkerAdapter, IWorkerAdapter } from '@unchainedshop/core';
2
2
  import nodemailer from 'nodemailer';
3
+ import { spawn } from 'node:child_process';
4
+ import { writeFile, mkdtemp } from 'node:fs/promises';
5
+ import { tmpdir } from 'node:os';
6
+ import { join } from 'node:path';
3
7
 
4
8
  export const checkEmailInterceptionEnabled = () => {
5
9
  return process.env.NODE_ENV !== 'production' && !process.env.UNCHAINED_DISABLE_EMAIL_INTERCEPTION;
@@ -18,10 +22,16 @@ const buildLink = async ({ filename, content, href, contentType, encoding, path
18
22
  return '';
19
23
  };
20
24
 
21
- const openInBrowser = async (options) => {
22
- // eslint-disable-next-line
23
- // @ts-ignore
24
- const { default: open, apps } = await import('open');
25
+ const openInBrowser = async (options): Promise<boolean> => {
26
+ const command = {
27
+ darwin: 'open',
28
+ win32: 'explorer.exe',
29
+ linux: 'xdg-open',
30
+ }[process.platform];
31
+
32
+ if (!command) {
33
+ return false;
34
+ }
25
35
 
26
36
  const messageBody = options.html || options.text.replace(/(\r\n|\n|\r)/gm, '<br/>');
27
37
  const attachmentLinks = await Promise.all((options.attachments || []).map(buildLink));
@@ -46,11 +56,23 @@ const openInBrowser = async (options) => {
46
56
  </body>
47
57
  </html>`;
48
58
 
49
- const base64 = Buffer.from(content).toString('base64');
50
- const dataUri = `data:text/html;base64,${base64}`;
59
+ // Create a temporary directory and file
60
+ const tempDir = await mkdtemp(join(tmpdir(), 'unchained-email-'));
61
+ const tempFile = join(tempDir, 'email-preview.html');
62
+
63
+ await writeFile(tempFile, content, 'utf8');
64
+
65
+ return new Promise((resolve) => {
66
+ const child = spawn(command, [tempFile], {
67
+ detached: true,
68
+ stdio: 'ignore',
69
+ });
70
+
71
+ child.unref();
51
72
 
52
- await open(dataUri, { app: [{ name: apps.chrome }, { name: apps.firefox }, { name: apps.browser }] });
53
- return true;
73
+ // Resolve immediately after spawning since process is detached
74
+ resolve(true);
75
+ });
54
76
  };
55
77
 
56
78
  const EmailWorkerPlugin: IWorkerAdapter<
@@ -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
  }
@@ -1,12 +1,5 @@
1
1
  import { IWorkerAdapter, WorkerAdapter, WorkerDirector } from '@unchainedshop/core';
2
-
3
- const wait = async (time: number) => {
4
- return new Promise((resolve) => {
5
- setTimeout(() => {
6
- resolve(true);
7
- }, time);
8
- });
9
- };
2
+ import { setTimeout } from 'node:timers/promises';
10
3
 
11
4
  interface Arg {
12
5
  wait?: number;
@@ -26,7 +19,7 @@ const Heartbeat: IWorkerAdapter<Arg, Result> = {
26
19
 
27
20
  doWork: async (input: Arg): Promise<{ success: boolean; result: Result }> => {
28
21
  if (input?.wait) {
29
- await wait(input.wait);
22
+ await setTimeout(input.wait);
30
23
  }
31
24
  if (input?.fails) {
32
25
  return {
@@ -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,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=de.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"de.d.ts","sourceRoot":"","sources":["../../../src/payment/cryptopay/de.ts"],"names":[],"mappings":""}
@@ -1,10 +0,0 @@
1
- import { describe, it } from 'node:test';
2
- import assert from 'node:assert';
3
- import deriveBtcAddress from './derive-btc-address.js';
4
- describe('BTC Address Derivation', () => {
5
- it('returns a deterministic BIP44 child address', () => {
6
- assert.equal(deriveBtcAddress('zpub6qpRm6gMdkrXvVKw7qgayHnqJGJkpE4rnYQdyJfZW87ed4Fk6HjVaThN12hv2rrL3EzfvvBW6ZpbMEe5UxZYEjhgeMigyvAbS5LiXPkKrys', 1), 'bc1qspcam3ntdpvhgz4vnxfdhas6qr8hf8tjfaz5p4');
7
- assert.equal(deriveBtcAddress('zpub6qpRm6gMdkrXvVKw7qgayHnqJGJkpE4rnYQdyJfZW87ed4Fk6HjVaThN12hv2rrL3EzfvvBW6ZpbMEe5UxZYEjhgeMigyvAbS5LiXPkKrys', 2), 'bc1qd0a7znq3pz3sc4armthddkyam57ey7qjc4v6vn');
8
- });
9
- });
10
- //# sourceMappingURL=de.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"de.js","sourceRoot":"","sources":["../../../src/payment/cryptopay/de.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,MAAM,MAAM,aAAa,CAAC;AACjC,OAAO,gBAAgB,MAAM,yBAAyB,CAAC;AAEvD,QAAQ,CAAC,wBAAwB,EAAE,GAAG,EAAE;IACtC,EAAE,CAAC,6CAA6C,EAAE,GAAG,EAAE;QACrD,MAAM,CAAC,KAAK,CACV,gBAAgB,CACd,iHAAiH,EACjH,CAAC,CACF,EACD,4CAA4C,CAC7C,CAAC;QACF,MAAM,CAAC,KAAK,CACV,gBAAgB,CACd,iHAAiH,EACjH,CAAC,CACF,EACD,4CAA4C,CAC7C,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=derive-btc-address.test%20copy.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"derive-btc-address.test copy.d.ts","sourceRoot":"","sources":["../../../src/payment/cryptopay/derive-btc-address.test copy.ts"],"names":[],"mappings":""}
@@ -1,10 +0,0 @@
1
- import { describe, it } from 'node:test';
2
- import assert from 'node:assert';
3
- import deriveBtcAddress from './derive-btc-address.js';
4
- describe('BTC Address Derivation', () => {
5
- it('returns a deterministic BIP44 child address', () => {
6
- assert.equal(deriveBtcAddress('zpub6qpRm6gMdkrXvVKw7qgayHnqJGJkpE4rnYQdyJfZW87ed4Fk6HjVaThN12hv2rrL3EzfvvBW6ZpbMEe5UxZYEjhgeMigyvAbS5LiXPkKrys', 1), 'bc1qspcam3ntdpvhgz4vnxfdhas6qr8hf8tjfaz5p4');
7
- assert.equal(deriveBtcAddress('zpub6qpRm6gMdkrXvVKw7qgayHnqJGJkpE4rnYQdyJfZW87ed4Fk6HjVaThN12hv2rrL3EzfvvBW6ZpbMEe5UxZYEjhgeMigyvAbS5LiXPkKrys', 2), 'bc1qd0a7znq3pz3sc4armthddkyam57ey7qjc4v6vn');
8
- });
9
- });
10
- //# sourceMappingURL=derive-btc-address.test%20copy.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"derive-btc-address.test copy.js","sourceRoot":"","sources":["../../../src/payment/cryptopay/derive-btc-address.test copy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,MAAM,MAAM,aAAa,CAAC;AACjC,OAAO,gBAAgB,MAAM,yBAAyB,CAAC;AAEvD,QAAQ,CAAC,wBAAwB,EAAE,GAAG,EAAE;IACtC,EAAE,CAAC,6CAA6C,EAAE,GAAG,EAAE;QACrD,MAAM,CAAC,KAAK,CACV,gBAAgB,CACd,iHAAiH,EACjH,CAAC,CACF,EACD,4CAA4C,CAC7C,CAAC;QACF,MAAM,CAAC,KAAK,CACV,gBAAgB,CACd,iHAAiH,EACjH,CAAC,CACF,EACD,4CAA4C,CAC7C,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
@@ -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
- });