@unchainedshop/plugins 3.0.0-alpha7 → 3.0.0-rc2
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.
- package/lib/delivery/pick-mup.js +1 -2
- package/lib/delivery/pick-mup.js.map +1 -1
- package/lib/delivery/post.js +2 -1
- package/lib/delivery/post.js.map +1 -1
- package/lib/delivery/send-message.js +2 -1
- package/lib/delivery/send-message.js.map +1 -1
- package/lib/delivery/stores.js +2 -1
- package/lib/delivery/stores.js.map +1 -1
- package/lib/enrollments/licensed.d.ts.map +1 -1
- package/lib/enrollments/licensed.js +1 -1
- package/lib/enrollments/licensed.js.map +1 -1
- package/lib/events/aws-eventbridge.d.ts +2 -0
- package/lib/events/aws-eventbridge.d.ts.map +1 -0
- package/lib/events/aws-eventbridge.js +36 -0
- package/lib/events/aws-eventbridge.js.map +1 -0
- package/lib/events/node-event-emitter.js +1 -2
- package/lib/events/node-event-emitter.js.map +1 -1
- package/lib/events/redis.js +4 -2
- package/lib/events/redis.js.map +1 -1
- package/lib/files/gridfs/gridfs-adapter.d.ts.map +1 -1
- package/lib/files/gridfs/gridfs-adapter.js +14 -5
- package/lib/files/gridfs/gridfs-adapter.js.map +1 -1
- package/lib/files/gridfs/gridfs-webhook.d.ts +1 -1
- package/lib/files/gridfs/gridfs-webhook.d.ts.map +1 -1
- package/lib/files/gridfs/gridfs-webhook.js +25 -6
- package/lib/files/gridfs/gridfs-webhook.js.map +1 -1
- package/lib/files/gridfs/sign.d.ts +1 -1
- package/lib/files/gridfs/sign.d.ts.map +1 -1
- package/lib/files/gridfs/sign.js +8 -7
- package/lib/files/gridfs/sign.js.map +1 -1
- package/lib/files/minio/minio-adapter.d.ts.map +1 -1
- package/lib/files/minio/minio-adapter.js +13 -9
- package/lib/files/minio/minio-adapter.js.map +1 -1
- package/lib/files/minio/minio-webhook.d.ts.map +1 -1
- package/lib/files/minio/minio-webhook.js +4 -3
- package/lib/files/minio/minio-webhook.js.map +1 -1
- package/lib/filters/local-search.d.ts +1 -1
- package/lib/filters/local-search.d.ts.map +1 -1
- package/lib/filters/local-search.js +1 -1
- package/lib/filters/local-search.js.map +1 -1
- package/lib/filters/strict-equal.js +1 -1
- package/lib/filters/strict-equal.js.map +1 -1
- package/lib/payment/apple-iap/adapter.d.ts.map +1 -1
- package/lib/payment/apple-iap/adapter.js +15 -20
- package/lib/payment/apple-iap/adapter.js.map +1 -1
- package/lib/payment/apple-iap/db/AppleTransactionsCollection.d.ts +1 -1
- package/lib/payment/apple-iap/db/AppleTransactionsCollection.d.ts.map +1 -1
- package/lib/payment/apple-iap/module/configureAppleTransactionsModule.d.ts +1 -1
- package/lib/payment/apple-iap/module/configureAppleTransactionsModule.d.ts.map +1 -1
- package/lib/payment/braintree.js +10 -8
- package/lib/payment/braintree.js.map +1 -1
- package/lib/payment/cryptopay/db/CryptopayTransactions.d.ts +1 -1
- package/lib/payment/cryptopay/db/CryptopayTransactions.d.ts.map +1 -1
- package/lib/payment/cryptopay/middleware.d.ts.map +1 -1
- package/lib/payment/cryptopay/middleware.js +4 -4
- package/lib/payment/cryptopay/middleware.js.map +1 -1
- package/lib/payment/cryptopay/plugin.d.ts +1 -1
- package/lib/payment/cryptopay/plugin.d.ts.map +1 -1
- package/lib/payment/cryptopay/plugin.js +8 -9
- package/lib/payment/cryptopay/plugin.js.map +1 -1
- package/lib/payment/datatrans-v2/api/authorize.d.ts +1 -1
- package/lib/payment/datatrans-v2/api/authorize.d.ts.map +1 -1
- package/lib/payment/datatrans-v2/api/authorizeAuthenticated.d.ts +1 -1
- package/lib/payment/datatrans-v2/api/authorizeAuthenticated.d.ts.map +1 -1
- package/lib/payment/datatrans-v2/api/cancel.d.ts +1 -1
- package/lib/payment/datatrans-v2/api/cancel.d.ts.map +1 -1
- package/lib/payment/datatrans-v2/api/init.d.ts +1 -1
- package/lib/payment/datatrans-v2/api/init.d.ts.map +1 -1
- package/lib/payment/datatrans-v2/api/makeFetcher.d.ts.map +1 -1
- package/lib/payment/datatrans-v2/api/makeFetcher.js +0 -1
- package/lib/payment/datatrans-v2/api/makeFetcher.js.map +1 -1
- package/lib/payment/datatrans-v2/api/secureFields.d.ts +1 -1
- package/lib/payment/datatrans-v2/api/secureFields.d.ts.map +1 -1
- package/lib/payment/datatrans-v2/api/settle.d.ts +1 -1
- package/lib/payment/datatrans-v2/api/settle.d.ts.map +1 -1
- package/lib/payment/datatrans-v2/api/status.d.ts +1 -1
- package/lib/payment/datatrans-v2/api/status.d.ts.map +1 -1
- package/lib/payment/datatrans-v2/api/types.d.ts +260 -0
- package/lib/payment/datatrans-v2/api/types.d.ts.map +1 -0
- package/lib/payment/datatrans-v2/api/types.js +2 -0
- package/lib/payment/datatrans-v2/api/types.js.map +1 -0
- package/lib/payment/datatrans-v2/api/validate.d.ts +1 -1
- package/lib/payment/datatrans-v2/api/validate.d.ts.map +1 -1
- package/lib/payment/datatrans-v2/generateSignature copy.d.ts +11 -0
- package/lib/payment/datatrans-v2/generateSignature copy.d.ts.map +1 -0
- package/lib/payment/datatrans-v2/generateSignature copy.js +19 -0
- package/lib/payment/datatrans-v2/generateSignature copy.js.map +1 -0
- package/lib/payment/datatrans-v2/generateSignature.d.ts +1 -1
- package/lib/payment/datatrans-v2/generateSignature.d.ts.map +1 -1
- package/lib/payment/datatrans-v2/generateSignature.js +7 -4
- package/lib/payment/datatrans-v2/generateSignature.js.map +1 -1
- package/lib/payment/datatrans-v2/index.d.ts.map +1 -1
- package/lib/payment/datatrans-v2/index.js +31 -29
- package/lib/payment/datatrans-v2/index.js.map +1 -1
- package/lib/payment/datatrans-v2/middleware.d.ts.map +1 -1
- package/lib/payment/datatrans-v2/middleware.js +7 -5
- package/lib/payment/datatrans-v2/middleware.js.map +1 -1
- package/lib/payment/datatrans-v2/parseRegistrationData.d.ts +4 -4
- package/lib/payment/datatrans-v2/parseRegistrationData.d.ts.map +1 -1
- package/lib/payment/datatrans-v2/parseRegistrationData.js +5 -3
- package/lib/payment/datatrans-v2/parseRegistrationData.js.map +1 -1
- package/lib/payment/datatrans-v2/roundedAmountFromOrder.d.ts +1 -2
- package/lib/payment/datatrans-v2/roundedAmountFromOrder.d.ts.map +1 -1
- package/lib/payment/datatrans-v2/roundedAmountFromOrder.js +6 -2
- package/lib/payment/datatrans-v2/roundedAmountFromOrder.js.map +1 -1
- package/lib/payment/datatrans-v2/splitProperties.d.ts +0 -1
- package/lib/payment/datatrans-v2/splitProperties.d.ts.map +1 -1
- package/lib/payment/datatrans-v2/splitProperties.js +0 -3
- package/lib/payment/datatrans-v2/splitProperties.js.map +1 -1
- package/lib/payment/invoice-prepaid.js +4 -3
- package/lib/payment/invoice-prepaid.js.map +1 -1
- package/lib/payment/invoice.js +4 -3
- package/lib/payment/invoice.js.map +1 -1
- package/lib/payment/paypal-checkout.js +10 -6
- package/lib/payment/paypal-checkout.js.map +1 -1
- package/lib/payment/payrexx/api/makeFetcher.d.ts.map +1 -1
- package/lib/payment/payrexx/api/makeFetcher.js +2 -3
- package/lib/payment/payrexx/api/makeFetcher.js.map +1 -1
- package/lib/payment/payrexx/index.d.ts.map +1 -1
- package/lib/payment/payrexx/index.js +20 -14
- package/lib/payment/payrexx/index.js.map +1 -1
- package/lib/payment/payrexx/middleware.d.ts.map +1 -1
- package/lib/payment/payrexx/middleware.js +12 -9
- package/lib/payment/payrexx/middleware.js.map +1 -1
- package/lib/payment/postfinance-checkout/index.d.ts.map +1 -1
- package/lib/payment/postfinance-checkout/index.js +18 -13
- package/lib/payment/postfinance-checkout/index.js.map +1 -1
- package/lib/payment/postfinance-checkout/middleware.d.ts.map +1 -1
- package/lib/payment/postfinance-checkout/middleware.js +4 -3
- package/lib/payment/postfinance-checkout/middleware.js.map +1 -1
- package/lib/payment/postfinance-checkout/utils.d.ts +2 -2
- package/lib/payment/postfinance-checkout/utils.d.ts.map +1 -1
- package/lib/payment/postfinance-checkout/utils.js +6 -2
- package/lib/payment/postfinance-checkout/utils.js.map +1 -1
- package/lib/payment/saferpay/adapter.d.ts +1 -1
- package/lib/payment/saferpay/adapter.d.ts.map +1 -1
- package/lib/payment/saferpay/adapter.js +17 -11
- package/lib/payment/saferpay/adapter.js.map +1 -1
- package/lib/payment/saferpay/api/api/SaferpayConnection.d.ts.map +1 -1
- package/lib/payment/saferpay/api/api/SaferpayConnection.js +0 -1
- package/lib/payment/saferpay/api/api/SaferpayConnection.js.map +1 -1
- package/lib/payment/saferpay/api/models/TransactionCapture.d.ts +1 -1
- package/lib/payment/saferpay/api/models/TransactionCapture.d.ts.map +1 -1
- package/lib/payment/saferpay/db/SaferpayTransactionsCollection.d.ts +1 -1
- package/lib/payment/saferpay/db/SaferpayTransactionsCollection.d.ts.map +1 -1
- package/lib/payment/saferpay/middleware.d.ts.map +1 -1
- package/lib/payment/saferpay/middleware.js +4 -4
- package/lib/payment/saferpay/middleware.js.map +1 -1
- package/lib/payment/stripe/index.d.ts.map +1 -1
- package/lib/payment/stripe/index.js +17 -11
- package/lib/payment/stripe/index.js.map +1 -1
- package/lib/payment/stripe/middleware.d.ts.map +1 -1
- package/lib/payment/stripe/middleware.js +10 -10
- package/lib/payment/stripe/middleware.js.map +1 -1
- package/lib/payment/stripe/stripe.d.ts +3 -4
- package/lib/payment/stripe/stripe.d.ts.map +1 -1
- package/lib/payment/stripe/stripe.js +3 -1
- package/lib/payment/stripe/stripe.js.map +1 -1
- package/lib/pricing/delivery-swiss-tax.d.ts +1 -1
- package/lib/pricing/delivery-swiss-tax.d.ts.map +1 -1
- package/lib/pricing/delivery-swiss-tax.js +1 -2
- package/lib/pricing/delivery-swiss-tax.js.map +1 -1
- package/lib/pricing/discount-100-off.d.ts +2 -3
- package/lib/pricing/discount-100-off.d.ts.map +1 -1
- package/lib/pricing/discount-100-off.js +1 -1
- package/lib/pricing/discount-100-off.js.map +1 -1
- package/lib/pricing/discount-half-price-manual.d.ts +2 -3
- package/lib/pricing/discount-half-price-manual.d.ts.map +1 -1
- package/lib/pricing/discount-half-price-manual.js +1 -1
- package/lib/pricing/discount-half-price-manual.js.map +1 -1
- package/lib/pricing/discount-half-price.d.ts +2 -3
- package/lib/pricing/discount-half-price.d.ts.map +1 -1
- package/lib/pricing/discount-half-price.js +1 -1
- package/lib/pricing/discount-half-price.js.map +1 -1
- package/lib/pricing/free-delivery.d.ts +1 -1
- package/lib/pricing/free-delivery.d.ts.map +1 -1
- package/lib/pricing/free-delivery.js +1 -1
- package/lib/pricing/free-delivery.js.map +1 -1
- package/lib/pricing/free-payment.d.ts +1 -1
- package/lib/pricing/free-payment.d.ts.map +1 -1
- package/lib/pricing/free-payment.js +1 -1
- package/lib/pricing/free-payment.js.map +1 -1
- package/lib/pricing/order-delivery.d.ts +1 -1
- package/lib/pricing/order-delivery.d.ts.map +1 -1
- package/lib/pricing/order-delivery.js +6 -3
- package/lib/pricing/order-delivery.js.map +1 -1
- package/lib/pricing/order-discount.d.ts +1 -2
- package/lib/pricing/order-discount.d.ts.map +1 -1
- package/lib/pricing/order-discount.js +15 -8
- package/lib/pricing/order-discount.js.map +1 -1
- package/lib/pricing/order-items-discount.js +7 -4
- package/lib/pricing/order-items-discount.js.map +1 -1
- package/lib/pricing/order-items.js +7 -3
- package/lib/pricing/order-items.js.map +1 -1
- package/lib/pricing/order-payment.js +6 -3
- package/lib/pricing/order-payment.js.map +1 -1
- package/lib/pricing/order-round.d.ts +1 -1
- package/lib/pricing/order-round.d.ts.map +1 -1
- package/lib/pricing/order-round.js +1 -2
- package/lib/pricing/order-round.js.map +1 -1
- package/lib/pricing/product-catalog-price.d.ts +2 -2
- package/lib/pricing/product-catalog-price.d.ts.map +1 -1
- package/lib/pricing/product-catalog-price.js +7 -6
- package/lib/pricing/product-catalog-price.js.map +1 -1
- package/lib/pricing/product-discount.js +1 -2
- package/lib/pricing/product-discount.js.map +1 -1
- package/lib/pricing/product-price-rateconversion.d.ts +1 -1
- package/lib/pricing/product-price-rateconversion.d.ts.map +1 -1
- package/lib/pricing/product-price-rateconversion.js +1 -1
- package/lib/pricing/product-price-rateconversion.js.map +1 -1
- package/lib/pricing/product-round.d.ts +1 -1
- package/lib/pricing/product-round.d.ts.map +1 -1
- package/lib/pricing/product-round.js +1 -1
- package/lib/pricing/product-round.js.map +1 -1
- package/lib/pricing/product-swiss-tax.d.ts +4 -3
- package/lib/pricing/product-swiss-tax.d.ts.map +1 -1
- package/lib/pricing/product-swiss-tax.js +1 -2
- package/lib/pricing/product-swiss-tax.js.map +1 -1
- package/lib/quotations/manual.js +1 -1
- package/lib/quotations/manual.js.map +1 -1
- package/lib/warehousing/eth-minter.js +7 -4
- package/lib/warehousing/eth-minter.js.map +1 -1
- package/lib/warehousing/store.js +2 -1
- package/lib/warehousing/store.js.map +1 -1
- package/lib/worker/BaseWorker.d.ts +30 -0
- package/lib/worker/BaseWorker.d.ts.map +1 -0
- package/lib/worker/BaseWorker.js +81 -0
- package/lib/worker/BaseWorker.js.map +1 -0
- package/lib/worker/EventListenerWorker.d.ts +6 -0
- package/lib/worker/EventListenerWorker.d.ts.map +1 -0
- package/lib/worker/EventListenerWorker.js +46 -0
- package/lib/worker/EventListenerWorker.js.map +1 -0
- package/lib/worker/FailedRescheduler.d.ts +15 -0
- package/lib/worker/FailedRescheduler.d.ts.map +1 -0
- package/lib/worker/FailedRescheduler.js +45 -0
- package/lib/worker/FailedRescheduler.js.map +1 -0
- package/lib/worker/IntervalWorker.d.ts +10 -0
- package/lib/worker/IntervalWorker.d.ts.map +1 -0
- package/lib/worker/IntervalWorker.js +37 -0
- package/lib/worker/IntervalWorker.js.map +1 -0
- package/lib/worker/bulk-import.d.ts +1 -1
- package/lib/worker/bulk-import.d.ts.map +1 -1
- package/lib/worker/bulk-import.js +7 -8
- package/lib/worker/bulk-import.js.map +1 -1
- package/lib/worker/email.d.ts.map +1 -1
- package/lib/worker/email.js +1 -5
- package/lib/worker/email.js.map +1 -1
- package/lib/worker/enrollment-order-generator.d.ts.map +1 -1
- package/lib/worker/enrollment-order-generator.js +17 -15
- package/lib/worker/enrollment-order-generator.js.map +1 -1
- package/lib/worker/error-notifications.d.ts +1 -1
- package/lib/worker/error-notifications.d.ts.map +1 -1
- package/lib/worker/error-notifications.js +1 -1
- package/lib/worker/error-notifications.js.map +1 -1
- package/lib/worker/export-token.d.ts +1 -2
- package/lib/worker/export-token.d.ts.map +1 -1
- package/lib/worker/export-token.js +2 -1
- package/lib/worker/export-token.js.map +1 -1
- package/lib/worker/external.d.ts +1 -1
- package/lib/worker/external.d.ts.map +1 -1
- package/lib/worker/external.js +1 -1
- package/lib/worker/external.js.map +1 -1
- package/lib/worker/heartbeat.js +1 -1
- package/lib/worker/heartbeat.js.map +1 -1
- package/lib/worker/http-request.d.ts +1 -1
- package/lib/worker/http-request.d.ts.map +1 -1
- package/lib/worker/http-request.js +1 -5
- package/lib/worker/http-request.js.map +1 -1
- package/lib/worker/message.d.ts +2 -2
- package/lib/worker/message.d.ts.map +1 -1
- package/lib/worker/message.js +1 -5
- package/lib/worker/message.js.map +1 -1
- package/lib/worker/push-notification.js +1 -4
- package/lib/worker/push-notification.js.map +1 -1
- package/lib/worker/sms.js +1 -4
- package/lib/worker/sms.js.map +1 -1
- package/lib/worker/update-coinbase-rates.js +1 -1
- package/lib/worker/update-coinbase-rates.js.map +1 -1
- package/lib/worker/update-ecb-rates.js +1 -1
- package/lib/worker/update-ecb-rates.js.map +1 -1
- package/lib/worker/update-token-ownership.d.ts +1 -1
- package/lib/worker/update-token-ownership.d.ts.map +1 -1
- package/lib/worker/update-token-ownership.js +1 -1
- package/lib/worker/update-token-ownership.js.map +1 -1
- package/lib/worker/zombie-killer.d.ts +8 -2
- package/lib/worker/zombie-killer.d.ts.map +1 -1
- package/lib/worker/zombie-killer.js +12 -9
- package/lib/worker/zombie-killer.js.map +1 -1
- package/package.json +37 -82
- package/src/delivery/pick-mup.ts +2 -3
- package/src/delivery/post.ts +2 -2
- package/src/delivery/send-message.ts +2 -2
- package/src/delivery/stores.ts +2 -2
- package/src/enrollments/licensed.ts +1 -2
- package/src/events/aws-eventbridge.ts +43 -0
- package/src/events/node-event-emitter.ts +1 -2
- package/src/events/redis.ts +4 -2
- package/src/files/gridfs/gridfs-adapter.ts +15 -5
- package/src/files/gridfs/gridfs-webhook.ts +29 -9
- package/src/files/gridfs/sign.ts +20 -8
- package/src/files/minio/minio-adapter.ts +14 -11
- package/src/files/minio/minio-webhook.ts +5 -3
- package/src/filters/local-search.ts +1 -2
- package/src/filters/strict-equal.ts +1 -2
- package/src/payment/apple-iap/adapter.ts +22 -40
- package/src/payment/apple-iap/db/AppleTransactionsCollection.ts +1 -1
- package/src/payment/apple-iap/module/configureAppleTransactionsModule.ts +1 -1
- package/src/payment/braintree.ts +16 -9
- package/src/payment/cryptopay/db/CryptopayTransactions.ts +1 -1
- package/src/payment/cryptopay/middleware.ts +11 -8
- package/src/payment/cryptopay/plugin.ts +14 -11
- package/src/payment/datatrans-v2/api/authorize.ts +1 -1
- package/src/payment/datatrans-v2/api/authorizeAuthenticated.ts +1 -1
- package/src/payment/datatrans-v2/api/cancel.ts +1 -1
- package/src/payment/datatrans-v2/api/init.ts +1 -1
- package/src/payment/datatrans-v2/api/makeFetcher.ts +0 -1
- package/src/payment/datatrans-v2/api/secureFields.ts +1 -1
- package/src/payment/datatrans-v2/api/settle.ts +1 -1
- package/src/payment/datatrans-v2/api/status.ts +1 -1
- package/src/payment/datatrans-v2/api/validate.ts +1 -1
- package/src/payment/datatrans-v2/generateSignature.test.ts +15 -0
- package/src/payment/datatrans-v2/generateSignature.ts +18 -6
- package/src/payment/datatrans-v2/index.ts +41 -36
- package/src/payment/datatrans-v2/middleware.ts +8 -12
- package/src/payment/datatrans-v2/parseRegistrationData.ts +7 -5
- package/src/payment/datatrans-v2/roundedAmountFromOrder.ts +6 -6
- package/src/payment/datatrans-v2/splitProperties.ts +0 -5
- package/src/payment/invoice-prepaid.ts +4 -4
- package/src/payment/invoice.ts +4 -4
- package/src/payment/paypal-checkout.ts +16 -7
- package/src/payment/payrexx/api/makeFetcher.ts +2 -3
- package/src/payment/payrexx/index.ts +26 -15
- package/src/payment/payrexx/middleware.ts +14 -19
- package/src/payment/postfinance-checkout/index.ts +26 -17
- package/src/payment/postfinance-checkout/middleware.ts +6 -9
- package/src/payment/postfinance-checkout/utils.ts +6 -3
- package/src/payment/saferpay/adapter.ts +23 -13
- package/src/payment/saferpay/api/api/SaferpayConnection.ts +0 -1
- package/src/payment/saferpay/api/models/TransactionCapture.ts +1 -1
- package/src/payment/saferpay/db/SaferpayTransactionsCollection.ts +1 -1
- package/src/payment/saferpay/middleware.ts +6 -10
- package/src/payment/stripe/index.ts +23 -12
- package/src/payment/stripe/middleware.ts +15 -23
- package/src/payment/stripe/stripe.ts +6 -5
- package/src/pricing/delivery-swiss-tax.ts +6 -2
- package/src/pricing/discount-100-off.ts +4 -3
- package/src/pricing/discount-half-price-manual.ts +9 -5
- package/src/pricing/discount-half-price.ts +9 -5
- package/src/pricing/free-delivery.ts +1 -1
- package/src/pricing/free-payment.ts +1 -1
- package/src/pricing/order-delivery.ts +11 -8
- package/src/pricing/order-discount.ts +26 -11
- package/src/pricing/order-items-discount.ts +12 -5
- package/src/pricing/order-items.ts +12 -8
- package/src/pricing/order-payment.ts +11 -8
- package/src/pricing/order-round.ts +6 -2
- package/src/pricing/product-catalog-price.ts +12 -7
- package/src/pricing/product-discount.ts +5 -4
- package/src/pricing/product-price-rateconversion.ts +5 -2
- package/src/pricing/product-round.ts +5 -2
- package/src/pricing/product-swiss-tax.ts +5 -3
- package/src/quotations/manual.ts +1 -2
- package/src/warehousing/eth-minter.ts +11 -10
- package/src/warehousing/store.ts +2 -6
- package/src/worker/BaseWorker.ts +119 -0
- package/src/worker/EventListenerWorker.ts +61 -0
- package/src/worker/FailedRescheduler.ts +80 -0
- package/src/worker/IntervalWorker.ts +54 -0
- package/src/worker/bulk-import.ts +12 -13
- package/src/worker/email.ts +1 -8
- package/src/worker/enrollment-order-generator.ts +25 -34
- package/src/worker/error-notifications.ts +2 -2
- package/src/worker/export-token.ts +2 -8
- package/src/worker/external.ts +1 -2
- package/src/worker/heartbeat.ts +1 -2
- package/src/worker/http-request.ts +1 -8
- package/src/worker/message.ts +2 -6
- package/src/worker/push-notification.ts +1 -6
- package/src/worker/sms.ts +1 -7
- package/src/worker/update-coinbase-rates.ts +1 -3
- package/src/worker/update-ecb-rates.ts +1 -3
- package/src/worker/update-token-ownership.ts +1 -2
- package/src/worker/zombie-killer.ts +23 -23
- package/tsconfig.json +4 -5
- /package/src/payment/datatrans-v2/api/{types.d.ts → types.ts} +0 -0
|
@@ -1,9 +1,14 @@
|
|
|
1
|
-
import { IOrderPricingAdapter, OrderPricingRowCategory } from '@unchainedshop/core-orders';
|
|
2
1
|
import {
|
|
2
|
+
IOrderPricingAdapter,
|
|
3
|
+
OrderPricingRowCategory,
|
|
3
4
|
OrderPricingDirector,
|
|
4
5
|
OrderPricingAdapter,
|
|
5
6
|
OrderDiscountConfiguration,
|
|
6
|
-
|
|
7
|
+
DeliveryPricingSheet,
|
|
8
|
+
PaymentPricingSheet,
|
|
9
|
+
ProductPricingSheet,
|
|
10
|
+
resolveRatioAndTaxDivisorForPricingSheet,
|
|
11
|
+
} from '@unchainedshop/core';
|
|
7
12
|
import { calculation as calcUtils } from '@unchainedshop/utils';
|
|
8
13
|
|
|
9
14
|
export const OrderDiscount: IOrderPricingAdapter<OrderDiscountConfiguration> = {
|
|
@@ -20,7 +25,7 @@ export const OrderDiscount: IOrderPricingAdapter<OrderDiscountConfiguration> = {
|
|
|
20
25
|
|
|
21
26
|
actions: (params) => {
|
|
22
27
|
const pricingAdapter = OrderPricingAdapter.actions(params);
|
|
23
|
-
const { order, orderDelivery, orderPositions, orderPayment
|
|
28
|
+
const { order, orderDelivery, orderPositions, orderPayment } = params.context;
|
|
24
29
|
|
|
25
30
|
return {
|
|
26
31
|
...pricingAdapter,
|
|
@@ -40,19 +45,29 @@ export const OrderDiscount: IOrderPricingAdapter<OrderDiscountConfiguration> = {
|
|
|
40
45
|
useNetPrice: false,
|
|
41
46
|
}).amount;
|
|
42
47
|
const itemShares = orderPositions.map((orderPosition) =>
|
|
43
|
-
|
|
44
|
-
|
|
48
|
+
resolveRatioAndTaxDivisorForPricingSheet(
|
|
49
|
+
ProductPricingSheet({
|
|
50
|
+
calculation: orderPosition.calculation,
|
|
51
|
+
currency: order.currency,
|
|
52
|
+
quantity: orderPosition.quantity,
|
|
53
|
+
}),
|
|
45
54
|
totalAmountOfItems,
|
|
46
55
|
),
|
|
47
56
|
);
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
57
|
+
|
|
58
|
+
const deliveryShare = resolveRatioAndTaxDivisorForPricingSheet(
|
|
59
|
+
DeliveryPricingSheet({
|
|
60
|
+
calculation: orderDelivery.calculation || [],
|
|
61
|
+
currency: order.currency,
|
|
62
|
+
}),
|
|
51
63
|
totalAmountOfPaymentAndDelivery,
|
|
52
64
|
);
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
65
|
+
|
|
66
|
+
const paymentShare = resolveRatioAndTaxDivisorForPricingSheet(
|
|
67
|
+
PaymentPricingSheet({
|
|
68
|
+
calculation: orderPayment.calculation || [],
|
|
69
|
+
currency: order.currency,
|
|
70
|
+
}),
|
|
56
71
|
totalAmountOfPaymentAndDelivery,
|
|
57
72
|
);
|
|
58
73
|
let amountLeft = totalAmountOfPaymentAndDelivery + totalAmountOfItems;
|
|
@@ -1,9 +1,12 @@
|
|
|
1
|
-
import { IOrderPricingAdapter, OrderPricingRowCategory } from '@unchainedshop/core-orders';
|
|
2
1
|
import {
|
|
2
|
+
ProductPricingSheet,
|
|
3
3
|
OrderPricingDirector,
|
|
4
4
|
OrderPricingAdapter,
|
|
5
5
|
OrderDiscountConfiguration,
|
|
6
|
-
|
|
6
|
+
IOrderPricingAdapter,
|
|
7
|
+
OrderPricingRowCategory,
|
|
8
|
+
resolveRatioAndTaxDivisorForPricingSheet,
|
|
9
|
+
} from '@unchainedshop/core';
|
|
7
10
|
import { calculation as calcUtils } from '@unchainedshop/utils';
|
|
8
11
|
|
|
9
12
|
const OrderItemsDiscount: IOrderPricingAdapter<OrderDiscountConfiguration> = {
|
|
@@ -20,7 +23,7 @@ const OrderItemsDiscount: IOrderPricingAdapter<OrderDiscountConfiguration> = {
|
|
|
20
23
|
|
|
21
24
|
actions: (params) => {
|
|
22
25
|
const pricingAdapter = OrderPricingAdapter.actions(params);
|
|
23
|
-
const { order, orderPositions
|
|
26
|
+
const { order, orderPositions } = params.context;
|
|
24
27
|
|
|
25
28
|
return {
|
|
26
29
|
...pricingAdapter,
|
|
@@ -36,8 +39,12 @@ const OrderItemsDiscount: IOrderPricingAdapter<OrderDiscountConfiguration> = {
|
|
|
36
39
|
}).amount;
|
|
37
40
|
|
|
38
41
|
const itemShares = orderPositions.map((orderPosition) =>
|
|
39
|
-
|
|
40
|
-
|
|
42
|
+
resolveRatioAndTaxDivisorForPricingSheet(
|
|
43
|
+
ProductPricingSheet({
|
|
44
|
+
calculation: orderPosition.calculation,
|
|
45
|
+
currency: order.currency,
|
|
46
|
+
quantity: orderPosition.quantity,
|
|
47
|
+
}),
|
|
41
48
|
totalAmountOfItems,
|
|
42
49
|
),
|
|
43
50
|
);
|
|
@@ -1,5 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import {
|
|
2
|
+
IOrderPricingAdapter,
|
|
3
|
+
OrderPricingDirector,
|
|
4
|
+
OrderPricingAdapter,
|
|
5
|
+
ProductPricingSheet,
|
|
6
|
+
} from '@unchainedshop/core';
|
|
3
7
|
|
|
4
8
|
const OrderItems: IOrderPricingAdapter = {
|
|
5
9
|
...OrderPricingAdapter,
|
|
@@ -15,7 +19,7 @@ const OrderItems: IOrderPricingAdapter = {
|
|
|
15
19
|
|
|
16
20
|
actions: (params) => {
|
|
17
21
|
const pricingAdapter = OrderPricingAdapter.actions(params);
|
|
18
|
-
const { order, orderPositions
|
|
22
|
+
const { order, orderPositions } = params.context;
|
|
19
23
|
|
|
20
24
|
return {
|
|
21
25
|
...pricingAdapter,
|
|
@@ -24,11 +28,11 @@ const OrderItems: IOrderPricingAdapter = {
|
|
|
24
28
|
// just sum up all products items prices, taxes & fees
|
|
25
29
|
const totalAndTaxesOfAllItems = orderPositions.reduce(
|
|
26
30
|
(current, orderPosition) => {
|
|
27
|
-
const pricing =
|
|
28
|
-
orderPosition,
|
|
29
|
-
order.currency,
|
|
30
|
-
|
|
31
|
-
);
|
|
31
|
+
const pricing = ProductPricingSheet({
|
|
32
|
+
calculation: orderPosition.calculation,
|
|
33
|
+
currency: order.currency,
|
|
34
|
+
quantity: orderPosition.quantity,
|
|
35
|
+
});
|
|
32
36
|
const tax = pricing.taxSum();
|
|
33
37
|
const items = pricing.gross();
|
|
34
38
|
return {
|
|
@@ -1,5 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import {
|
|
2
|
+
IOrderPricingAdapter,
|
|
3
|
+
OrderPricingDirector,
|
|
4
|
+
OrderPricingAdapter,
|
|
5
|
+
PaymentPricingSheet,
|
|
6
|
+
} from '@unchainedshop/core';
|
|
3
7
|
|
|
4
8
|
const OrderPayment: IOrderPricingAdapter = {
|
|
5
9
|
...OrderPricingAdapter,
|
|
@@ -15,7 +19,7 @@ const OrderPayment: IOrderPricingAdapter = {
|
|
|
15
19
|
|
|
16
20
|
actions: (params) => {
|
|
17
21
|
const pricingAdapter = OrderPricingAdapter.actions(params);
|
|
18
|
-
const { order, orderPayment
|
|
22
|
+
const { order, orderPayment } = params.context;
|
|
19
23
|
|
|
20
24
|
return {
|
|
21
25
|
...pricingAdapter,
|
|
@@ -24,11 +28,10 @@ const OrderPayment: IOrderPricingAdapter = {
|
|
|
24
28
|
// just add tax + net price to order pricing
|
|
25
29
|
if (!orderPayment) return null;
|
|
26
30
|
|
|
27
|
-
const pricing =
|
|
28
|
-
orderPayment,
|
|
29
|
-
order.currency,
|
|
30
|
-
|
|
31
|
-
);
|
|
31
|
+
const pricing = PaymentPricingSheet({
|
|
32
|
+
calculation: orderPayment.calculation,
|
|
33
|
+
currency: order.currency,
|
|
34
|
+
});
|
|
32
35
|
const tax = pricing.taxSum();
|
|
33
36
|
const paymentFees = pricing.gross();
|
|
34
37
|
|
|
@@ -1,5 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import {
|
|
2
|
+
OrderPricingAdapter,
|
|
3
|
+
OrderPricingDirector,
|
|
4
|
+
IOrderPricingAdapter,
|
|
5
|
+
OrderPricingRowCategory,
|
|
6
|
+
} from '@unchainedshop/core';
|
|
3
7
|
|
|
4
8
|
interface PriceRoundSettings {
|
|
5
9
|
defaultPrecision: number;
|
|
@@ -1,11 +1,17 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import {
|
|
2
|
+
ProductPricingDirector,
|
|
3
|
+
ProductPricingAdapter,
|
|
4
|
+
IProductPricingAdapter,
|
|
5
|
+
} from '@unchainedshop/core';
|
|
3
6
|
import { resolveBestCurrency } from '@unchainedshop/utils';
|
|
4
|
-
import
|
|
7
|
+
import pMemoize from 'p-memoize';
|
|
8
|
+
import ExpiryMap from 'expiry-map';
|
|
5
9
|
|
|
6
10
|
const { NODE_ENV } = process.env;
|
|
7
11
|
|
|
8
|
-
|
|
12
|
+
const memoizeCache = new ExpiryMap(NODE_ENV === 'production' ? 1000 * 60 : 100); // Cached values expire after 10 seconds
|
|
13
|
+
|
|
14
|
+
export const resolveCurrency = pMemoize(
|
|
9
15
|
async (context) => {
|
|
10
16
|
const { country, currency: forcedCurrency, modules } = context;
|
|
11
17
|
const countryObject = await modules.countries.findCountry({ isoCode: country });
|
|
@@ -15,9 +21,8 @@ export const resolveCurrency = memoizee(
|
|
|
15
21
|
return currency;
|
|
16
22
|
},
|
|
17
23
|
{
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
normalizer(args) {
|
|
24
|
+
cache: memoizeCache,
|
|
25
|
+
cacheKey(args) {
|
|
21
26
|
return `${args[0].currency}-${args[0].country}`;
|
|
22
27
|
},
|
|
23
28
|
},
|
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { IProductPricingAdapter, ProductPricingRowCategory } from '@unchainedshop/core-products';
|
|
1
|
+
import { calculation as calcUtils } from '@unchainedshop/utils';
|
|
3
2
|
import {
|
|
4
3
|
ProductPricingDirector,
|
|
5
4
|
ProductPricingAdapter,
|
|
6
5
|
ProductDiscountConfiguration,
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
IProductPricingAdapter,
|
|
7
|
+
ProductPricingRowCategory,
|
|
8
|
+
Discount,
|
|
9
|
+
} from '@unchainedshop/core';
|
|
9
10
|
|
|
10
11
|
const ProductDiscount: IProductPricingAdapter<ProductDiscountConfiguration> = {
|
|
11
12
|
...ProductPricingAdapter,
|
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import {
|
|
2
|
+
IProductPricingAdapter,
|
|
3
|
+
ProductPricingDirector,
|
|
4
|
+
ProductPricingAdapter,
|
|
5
|
+
} from '@unchainedshop/core';
|
|
3
6
|
|
|
4
7
|
export const ProductPriceRateConversion: IProductPricingAdapter = {
|
|
5
8
|
...ProductPricingAdapter,
|
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import {
|
|
2
|
+
ProductPricingAdapter,
|
|
3
|
+
ProductPricingDirector,
|
|
4
|
+
IProductPricingAdapter,
|
|
5
|
+
} from '@unchainedshop/core';
|
|
3
6
|
|
|
4
7
|
interface PriceRoundSettings {
|
|
5
8
|
defaultPrecision: number;
|
|
@@ -2,8 +2,10 @@ import {
|
|
|
2
2
|
ProductPricingDirector,
|
|
3
3
|
ProductPricingAdapter,
|
|
4
4
|
ProductPricingAdapterContext,
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
IProductPricingAdapter,
|
|
6
|
+
ProductPricingRowCategory,
|
|
7
|
+
UnchainedCore,
|
|
8
|
+
} from '@unchainedshop/core';
|
|
7
9
|
import { SwissTaxCategories } from './tax/ch.js';
|
|
8
10
|
|
|
9
11
|
export const getTaxRate = (context: ProductPricingAdapterContext) => {
|
|
@@ -24,7 +26,7 @@ export const isDeliveryAddressInSwitzerland = async ({
|
|
|
24
26
|
order,
|
|
25
27
|
country,
|
|
26
28
|
modules,
|
|
27
|
-
}: ProductPricingAdapterContext) => {
|
|
29
|
+
}: ProductPricingAdapterContext & { modules: UnchainedCore['modules'] }) => {
|
|
28
30
|
let countryCode = country?.toUpperCase().trim();
|
|
29
31
|
|
|
30
32
|
if (order) {
|
package/src/quotations/manual.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { IQuotationAdapter } from '@unchainedshop/core
|
|
2
|
-
import { QuotationDirector, QuotationAdapter } from '@unchainedshop/core-quotations';
|
|
1
|
+
import { IQuotationAdapter, QuotationDirector, QuotationAdapter } from '@unchainedshop/core';
|
|
3
2
|
|
|
4
3
|
const ManualOffering: IQuotationAdapter = {
|
|
5
4
|
...QuotationAdapter,
|
|
@@ -1,18 +1,16 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
WarehousingAdapter,
|
|
4
|
-
WarehousingProviderType,
|
|
5
|
-
} from '@unchainedshop/core-warehousing';
|
|
6
|
-
import { ProductContractStandard } from '@unchainedshop/core-products';
|
|
7
|
-
import {
|
|
2
|
+
UnchainedCore,
|
|
8
3
|
IWarehousingAdapter,
|
|
9
4
|
WarehousingContext,
|
|
10
5
|
WarehousingError,
|
|
11
|
-
|
|
6
|
+
WarehousingDirector,
|
|
7
|
+
WarehousingAdapter,
|
|
8
|
+
} from '@unchainedshop/core';
|
|
9
|
+
import { WarehousingProviderType } from '@unchainedshop/core-warehousing';
|
|
10
|
+
import { ProductContractStandard, ProductTypes } from '@unchainedshop/core-products';
|
|
12
11
|
import { systemLocale } from '@unchainedshop/utils';
|
|
13
12
|
import { generateDbObjectId } from '@unchainedshop/mongodb';
|
|
14
|
-
import {
|
|
15
|
-
import { ProductTypes } from '@unchainedshop/core-products';
|
|
13
|
+
import { getFileAdapter } from '@unchainedshop/core-files';
|
|
16
14
|
|
|
17
15
|
const { MINTER_TOKEN_OFFSET = '0' } = process.env;
|
|
18
16
|
|
|
@@ -115,7 +113,10 @@ const ETHMinter: IWarehousingAdapter = {
|
|
|
115
113
|
limit: 1,
|
|
116
114
|
});
|
|
117
115
|
const file = firstMedia && (await modules.files.findFile({ fileId: firstMedia.mediaId }));
|
|
118
|
-
|
|
116
|
+
|
|
117
|
+
const fileUploadAdapter = getFileAdapter();
|
|
118
|
+
const signedUrl = await fileUploadAdapter.createDownloadURL(file);
|
|
119
|
+
const url = signedUrl && (await modules.files.normalizeUrl(signedUrl, {}));
|
|
119
120
|
const text = await modules.products.texts.findLocalizedText({
|
|
120
121
|
productId: product._id,
|
|
121
122
|
locale: locale?.baseName || systemLocale.baseName,
|
package/src/warehousing/store.ts
CHANGED
|
@@ -1,9 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
WarehousingAdapter,
|
|
4
|
-
WarehousingProviderType,
|
|
5
|
-
} from '@unchainedshop/core-warehousing';
|
|
6
|
-
import { IWarehousingAdapter } from '@unchainedshop/core-warehousing';
|
|
1
|
+
import { WarehousingDirector, WarehousingAdapter, IWarehousingAdapter } from '@unchainedshop/core';
|
|
2
|
+
import { WarehousingProviderType } from '@unchainedshop/core-warehousing';
|
|
7
3
|
|
|
8
4
|
const Store: IWarehousingAdapter = {
|
|
9
5
|
...WarehousingAdapter,
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import later from '@breejs/later';
|
|
2
|
+
import { log } from '@unchainedshop/logger';
|
|
3
|
+
import { Work, WorkData } from '@unchainedshop/core-worker';
|
|
4
|
+
import { WorkerDirector } from '@unchainedshop/core';
|
|
5
|
+
|
|
6
|
+
export type IWorker<P extends { workerId?: string }> = {
|
|
7
|
+
key: string;
|
|
8
|
+
label: string;
|
|
9
|
+
version: string;
|
|
10
|
+
type: string;
|
|
11
|
+
external: boolean;
|
|
12
|
+
|
|
13
|
+
getFloorDate: (date?: Date) => Date;
|
|
14
|
+
|
|
15
|
+
actions: (
|
|
16
|
+
params: P,
|
|
17
|
+
unchainedAPI,
|
|
18
|
+
) => {
|
|
19
|
+
autorescheduleTypes: (options: { referenceDate: Date }) => Promise<Array<Work | null>>;
|
|
20
|
+
process: (options: { maxWorkItemCount?: number; referenceDate?: Date }) => Promise<void>;
|
|
21
|
+
reset: () => Promise<void>;
|
|
22
|
+
start: () => void;
|
|
23
|
+
stop: () => void;
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
interface WorkerParams {
|
|
28
|
+
workerId?: string;
|
|
29
|
+
worker: IWorker<any>;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export const BaseWorker: IWorker<WorkerParams> = {
|
|
33
|
+
key: 'shop.unchained.worker.base',
|
|
34
|
+
label: 'Base worker. Do not use this directly.',
|
|
35
|
+
version: '1.0.0',
|
|
36
|
+
type: 'BASE',
|
|
37
|
+
external: false,
|
|
38
|
+
|
|
39
|
+
getFloorDate: (date = new Date()) => {
|
|
40
|
+
const floored = new Date(Math.floor(date.getTime() / 1000) * 1000);
|
|
41
|
+
return floored;
|
|
42
|
+
},
|
|
43
|
+
|
|
44
|
+
actions: ({ workerId, worker }: WorkerParams, unchainedAPI) => {
|
|
45
|
+
log(`${worker.key} -> Initialized ${worker.type}`);
|
|
46
|
+
|
|
47
|
+
const workerActions = {
|
|
48
|
+
start() {
|
|
49
|
+
throw new Error(`Not implemented on ${this.constructor.key}`);
|
|
50
|
+
},
|
|
51
|
+
|
|
52
|
+
stop() {
|
|
53
|
+
throw new Error(`Not implemented on ${this.constructor.key}`);
|
|
54
|
+
},
|
|
55
|
+
|
|
56
|
+
reset: async (referenceDate = new Date()) => {
|
|
57
|
+
await unchainedAPI.modules.worker.markOldWorkAsFailed({
|
|
58
|
+
types: WorkerDirector.getActivePluginTypes({ external: false }),
|
|
59
|
+
worker: workerId,
|
|
60
|
+
referenceDate,
|
|
61
|
+
});
|
|
62
|
+
},
|
|
63
|
+
|
|
64
|
+
autorescheduleTypes: async ({ referenceDate }) => {
|
|
65
|
+
return Promise.all(
|
|
66
|
+
WorkerDirector.getAutoSchedules().map(async ([scheduleId, workConfig]) => {
|
|
67
|
+
if (!workConfig.schedule) {
|
|
68
|
+
await unchainedAPI.modules.worker.ensureNoWork({
|
|
69
|
+
type: workConfig.type,
|
|
70
|
+
priority: workConfig.priority || 0,
|
|
71
|
+
scheduleId,
|
|
72
|
+
});
|
|
73
|
+
return null;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const fixedSchedule = { ...workConfig.schedule };
|
|
77
|
+
fixedSchedule.schedules[0].s = [0]; // ignore seconds, always run on second 0
|
|
78
|
+
const nextDate = later.schedule(fixedSchedule).next(1, referenceDate) as Date;
|
|
79
|
+
nextDate.setMilliseconds(0);
|
|
80
|
+
const workData: WorkData = {
|
|
81
|
+
type: workConfig.type,
|
|
82
|
+
scheduleId,
|
|
83
|
+
scheduled: nextDate,
|
|
84
|
+
timeout: workConfig.timeout,
|
|
85
|
+
priority: workConfig.priority || 0,
|
|
86
|
+
retries: workConfig.retries || 0,
|
|
87
|
+
};
|
|
88
|
+
if (workConfig.input) {
|
|
89
|
+
workData.input = await workConfig.input(workData);
|
|
90
|
+
// A work input fn can skip auto scheduling a new record
|
|
91
|
+
// when it explicitly returns a falsish input instead of a dictionary
|
|
92
|
+
if (!workData.input) return null;
|
|
93
|
+
}
|
|
94
|
+
return unchainedAPI.modules.worker.ensureOneWork(workData);
|
|
95
|
+
}),
|
|
96
|
+
);
|
|
97
|
+
},
|
|
98
|
+
|
|
99
|
+
process: async ({ maxWorkItemCount, referenceDate }) => {
|
|
100
|
+
await workerActions.autorescheduleTypes({
|
|
101
|
+
referenceDate,
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
const processRecursively = async (recursionCounter = 0) => {
|
|
105
|
+
if (maxWorkItemCount && maxWorkItemCount < recursionCounter) return null;
|
|
106
|
+
const doneWork = await WorkerDirector.processNextWork(unchainedAPI, workerId);
|
|
107
|
+
if (doneWork) return processRecursively(recursionCounter + 1);
|
|
108
|
+
return null;
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
await processRecursively();
|
|
112
|
+
},
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
workerActions.reset();
|
|
116
|
+
|
|
117
|
+
return workerActions;
|
|
118
|
+
},
|
|
119
|
+
};
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { subscribe } from '@unchainedshop/events';
|
|
2
|
+
import { BaseWorker, IWorker } from './BaseWorker.js';
|
|
3
|
+
import { WorkerEventTypes } from '@unchainedshop/core-worker';
|
|
4
|
+
|
|
5
|
+
function debounce<T extends (...args: any) => any>(func: T, wait) {
|
|
6
|
+
let timeout;
|
|
7
|
+
return (...args) => {
|
|
8
|
+
clearTimeout(timeout);
|
|
9
|
+
timeout = setTimeout(() => {
|
|
10
|
+
timeout = null;
|
|
11
|
+
func(...args);
|
|
12
|
+
}, wait);
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface EventListenerWorkerParams {
|
|
17
|
+
workerId?: string;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export const EventListenerWorker: IWorker<EventListenerWorkerParams> = {
|
|
21
|
+
...BaseWorker,
|
|
22
|
+
|
|
23
|
+
key: 'shop.unchained.worker.event-listener',
|
|
24
|
+
label: 'Allocates work on events. This worker does not make sense on multiple containers.',
|
|
25
|
+
version: '1.0.0',
|
|
26
|
+
type: 'EVENT_LISTENER',
|
|
27
|
+
|
|
28
|
+
actions: ({ workerId }, unchainedAPI) => {
|
|
29
|
+
const baseWorkerActions = BaseWorker.actions(
|
|
30
|
+
{ workerId, worker: EventListenerWorker },
|
|
31
|
+
unchainedAPI,
|
|
32
|
+
);
|
|
33
|
+
|
|
34
|
+
// Debounce in the event of many work queue events conflicting with each other
|
|
35
|
+
const processWorkQueue = debounce<() => Promise<void>>(async () => {
|
|
36
|
+
await baseWorkerActions.process({
|
|
37
|
+
maxWorkItemCount: 1, // only one work item at a time, else we could end up in a loop
|
|
38
|
+
referenceDate: EventListenerWorker.getFloorDate(),
|
|
39
|
+
});
|
|
40
|
+
}, 300);
|
|
41
|
+
|
|
42
|
+
return {
|
|
43
|
+
...baseWorkerActions,
|
|
44
|
+
|
|
45
|
+
start() {
|
|
46
|
+
subscribe(WorkerEventTypes.ADDED, processWorkQueue);
|
|
47
|
+
subscribe(WorkerEventTypes.FINISHED, processWorkQueue);
|
|
48
|
+
|
|
49
|
+
setTimeout(async () => {
|
|
50
|
+
await baseWorkerActions.autorescheduleTypes({
|
|
51
|
+
referenceDate: EventListenerWorker.getFloorDate(),
|
|
52
|
+
});
|
|
53
|
+
}, 300);
|
|
54
|
+
},
|
|
55
|
+
|
|
56
|
+
stop() {
|
|
57
|
+
/* */
|
|
58
|
+
},
|
|
59
|
+
};
|
|
60
|
+
},
|
|
61
|
+
};
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { log } from '@unchainedshop/logger';
|
|
2
|
+
import { subscribe } from '@unchainedshop/events';
|
|
3
|
+
import { Work, WorkData, WorkerEventTypes } from '@unchainedshop/core-worker';
|
|
4
|
+
|
|
5
|
+
export interface FailedReschedulerParams {
|
|
6
|
+
retryInput?: (
|
|
7
|
+
workData: WorkData,
|
|
8
|
+
priorInput: Record<string, any>,
|
|
9
|
+
) => Promise<Record<string, any> | null>;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export type IScheduler<P> = {
|
|
13
|
+
key: string;
|
|
14
|
+
label: string;
|
|
15
|
+
version: string;
|
|
16
|
+
|
|
17
|
+
actions: (
|
|
18
|
+
params: P,
|
|
19
|
+
unchainedAPI,
|
|
20
|
+
) => {
|
|
21
|
+
start: () => void;
|
|
22
|
+
stop: () => void;
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export const FailedRescheduler: IScheduler<FailedReschedulerParams> = {
|
|
27
|
+
key: 'shop.unchained.scheduler.failed',
|
|
28
|
+
label: 'Reschedule failed works',
|
|
29
|
+
version: '1.0.0',
|
|
30
|
+
|
|
31
|
+
actions: ({ retryInput }, unchainedAPI) => {
|
|
32
|
+
const handleFinishedWork = async ({ payload: work }: { payload: Work }) => {
|
|
33
|
+
if (!work.success && work.retries > 0) {
|
|
34
|
+
const now = new Date();
|
|
35
|
+
const workDelayMs = work.scheduled.getTime() - work.created.getTime();
|
|
36
|
+
|
|
37
|
+
// In short: Double the delay of the old work or delay for 5 seconds
|
|
38
|
+
const scheduled =
|
|
39
|
+
workDelayMs > 1000
|
|
40
|
+
? new Date(now.getTime() + workDelayMs * 2)
|
|
41
|
+
: new Date(now.setSeconds(now.getSeconds() + 5));
|
|
42
|
+
|
|
43
|
+
log(
|
|
44
|
+
`${FailedRescheduler.key} -> Reschedule failed work ${work._id} ${
|
|
45
|
+
work.type
|
|
46
|
+
} for ${scheduled.toISOString()} (in ${Math.round(workDelayMs / 1000)}). Remaining retries: ${
|
|
47
|
+
work.retries
|
|
48
|
+
}`,
|
|
49
|
+
);
|
|
50
|
+
|
|
51
|
+
const workData: WorkData = {
|
|
52
|
+
type: work.type,
|
|
53
|
+
priority: work.priority,
|
|
54
|
+
originalWorkId: work.originalWorkId || work._id,
|
|
55
|
+
retries: work.retries - 1,
|
|
56
|
+
timeout: work.timeout,
|
|
57
|
+
scheduled,
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
if (retryInput) {
|
|
61
|
+
workData.input = await retryInput(workData, work.input);
|
|
62
|
+
} else {
|
|
63
|
+
workData.input = work.input;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
unchainedAPI.modules.worker.addWork(workData);
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
return {
|
|
71
|
+
start() {
|
|
72
|
+
subscribe<Work>(WorkerEventTypes.FINISHED, handleFinishedWork);
|
|
73
|
+
},
|
|
74
|
+
|
|
75
|
+
stop() {
|
|
76
|
+
/* */
|
|
77
|
+
},
|
|
78
|
+
};
|
|
79
|
+
},
|
|
80
|
+
};
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import later, { ScheduleData } from '@breejs/later';
|
|
2
|
+
import { BaseWorker, IWorker } from './BaseWorker.js';
|
|
3
|
+
|
|
4
|
+
const { NODE_ENV } = process.env;
|
|
5
|
+
|
|
6
|
+
export interface IntervalWorkerParams {
|
|
7
|
+
workerId?: string;
|
|
8
|
+
batchCount?: number;
|
|
9
|
+
schedule?: ScheduleData;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const defaultSchedule = later.parse.text(
|
|
13
|
+
NODE_ENV !== 'production' ? 'every 2 seconds' : 'every 30 seconds',
|
|
14
|
+
);
|
|
15
|
+
|
|
16
|
+
export const scheduleToInterval = (schedule: ScheduleData) => {
|
|
17
|
+
const referenceDate = new Date(1000);
|
|
18
|
+
const [one, two] = later.schedule(schedule).next(2, referenceDate) as Date[];
|
|
19
|
+
const diff = new Date(two).getTime() - new Date(one).getTime();
|
|
20
|
+
return Math.min(1000 * 60 * 60, diff); // at least once every hour!
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export const IntervalWorker: IWorker<IntervalWorkerParams> = {
|
|
24
|
+
...BaseWorker,
|
|
25
|
+
|
|
26
|
+
key: 'shop.unchained.worker.cron',
|
|
27
|
+
label: 'Allocates work on fixed intervals with native node setInterval',
|
|
28
|
+
version: '1.0.0',
|
|
29
|
+
type: 'CRON',
|
|
30
|
+
|
|
31
|
+
actions: ({ workerId, batchCount = 0, schedule = defaultSchedule }, unchainedAPI) => {
|
|
32
|
+
const baseWorkerActions = BaseWorker.actions({ workerId, worker: IntervalWorker }, unchainedAPI);
|
|
33
|
+
|
|
34
|
+
const intervalDelay = scheduleToInterval(schedule);
|
|
35
|
+
let intervalHandle: NodeJS.Timeout;
|
|
36
|
+
|
|
37
|
+
return {
|
|
38
|
+
...baseWorkerActions,
|
|
39
|
+
|
|
40
|
+
start() {
|
|
41
|
+
intervalHandle = setInterval(() => {
|
|
42
|
+
baseWorkerActions.process({
|
|
43
|
+
maxWorkItemCount: batchCount,
|
|
44
|
+
referenceDate: IntervalWorker.getFloorDate(),
|
|
45
|
+
});
|
|
46
|
+
}, intervalDelay);
|
|
47
|
+
},
|
|
48
|
+
|
|
49
|
+
stop() {
|
|
50
|
+
clearInterval(intervalHandle);
|
|
51
|
+
},
|
|
52
|
+
};
|
|
53
|
+
},
|
|
54
|
+
};
|