@unchainedshop/plugins 1.1.3 → 1.1.4
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.d.ts +1 -0
- package/lib/delivery/pick-mup.js +98 -0
- package/lib/delivery/pick-mup.js.map +1 -0
- package/lib/delivery/post.d.ts +1 -0
- package/lib/delivery/post.js +23 -0
- package/lib/delivery/post.js.map +1 -0
- package/lib/delivery/send-message.d.ts +1 -0
- package/lib/delivery/send-message.js +41 -0
- package/lib/delivery/send-message.js.map +1 -0
- package/lib/delivery/stores.d.ts +1 -0
- package/lib/delivery/stores.js +39 -0
- package/lib/delivery/stores.js.map +1 -0
- package/lib/enrollments/licensed.d.ts +1 -0
- package/lib/enrollments/licensed.js +40 -0
- package/lib/enrollments/licensed.js.map +1 -0
- package/lib/filters/local-search.d.ts +3 -0
- package/lib/filters/local-search.js +84 -0
- package/lib/filters/local-search.js.map +1 -0
- package/lib/filters/strict-equal.d.ts +1 -0
- package/lib/filters/strict-equal.js +25 -0
- package/lib/filters/strict-equal.js.map +1 -0
- package/lib/payment/apple-iap/adapter.d.ts +1 -0
- package/lib/payment/apple-iap/adapter.js +284 -0
- package/lib/payment/apple-iap/adapter.js.map +1 -0
- package/lib/payment/apple-iap/db/AppleTransactionsCollection.d.ts +7 -0
- package/lib/payment/apple-iap/db/AppleTransactionsCollection.js +5 -0
- package/lib/payment/apple-iap/db/AppleTransactionsCollection.js.map +1 -0
- package/lib/payment/apple-iap/index.d.ts +2 -0
- package/lib/payment/apple-iap/index.js +3 -0
- package/lib/payment/apple-iap/index.js.map +1 -0
- package/lib/payment/apple-iap/module/configureAppleTransactionsModule.d.ts +9 -0
- package/lib/payment/apple-iap/module/configureAppleTransactionsModule.js +18 -0
- package/lib/payment/apple-iap/module/configureAppleTransactionsModule.js.map +1 -0
- package/lib/payment/bity/adapter.d.ts +1 -0
- package/lib/payment/bity/adapter.js +316 -0
- package/lib/payment/bity/adapter.js.map +1 -0
- package/lib/payment/bity/db/BityCredentialsCollection.d.ts +11 -0
- package/lib/payment/bity/db/BityCredentialsCollection.js +5 -0
- package/lib/payment/bity/db/BityCredentialsCollection.js.map +1 -0
- package/lib/payment/bity/index.d.ts +2 -0
- package/lib/payment/bity/index.js +3 -0
- package/lib/payment/bity/index.js.map +1 -0
- package/lib/payment/bity/module/configureBityModule.d.ts +11 -0
- package/lib/payment/bity/module/configureBityModule.js +33 -0
- package/lib/payment/bity/module/configureBityModule.js.map +1 -0
- package/lib/payment/braintree.d.ts +1 -0
- package/lib/payment/braintree.js +129 -0
- package/lib/payment/braintree.js.map +1 -0
- package/lib/payment/cryptopay.d.ts +1 -0
- package/lib/payment/cryptopay.js +159 -0
- package/lib/payment/cryptopay.js.map +1 -0
- package/lib/payment/datatrans-v2/api/authorize.d.ts +2 -0
- package/lib/payment/datatrans-v2/api/authorize.js +12 -0
- package/lib/payment/datatrans-v2/api/authorize.js.map +1 -0
- package/lib/payment/datatrans-v2/api/authorizeAuthenticated.d.ts +2 -0
- package/lib/payment/datatrans-v2/api/authorizeAuthenticated.js +11 -0
- package/lib/payment/datatrans-v2/api/authorizeAuthenticated.js.map +1 -0
- package/lib/payment/datatrans-v2/api/cancel.d.ts +2 -0
- package/lib/payment/datatrans-v2/api/cancel.js +10 -0
- package/lib/payment/datatrans-v2/api/cancel.js.map +1 -0
- package/lib/payment/datatrans-v2/api/index.d.ts +19 -0
- package/lib/payment/datatrans-v2/api/index.js +24 -0
- package/lib/payment/datatrans-v2/api/index.js.map +1 -0
- package/lib/payment/datatrans-v2/api/init.d.ts +2 -0
- package/lib/payment/datatrans-v2/api/init.js +31 -0
- package/lib/payment/datatrans-v2/api/init.js.map +1 -0
- package/lib/payment/datatrans-v2/api/makeFetcher.d.ts +2 -0
- package/lib/payment/datatrans-v2/api/makeFetcher.js +41 -0
- package/lib/payment/datatrans-v2/api/makeFetcher.js.map +1 -0
- package/lib/payment/datatrans-v2/api/secureFields.d.ts +2 -0
- package/lib/payment/datatrans-v2/api/secureFields.js +14 -0
- package/lib/payment/datatrans-v2/api/secureFields.js.map +1 -0
- package/lib/payment/datatrans-v2/api/settle.d.ts +2 -0
- package/lib/payment/datatrans-v2/api/settle.js +10 -0
- package/lib/payment/datatrans-v2/api/settle.js.map +1 -0
- package/lib/payment/datatrans-v2/api/status.d.ts +2 -0
- package/lib/payment/datatrans-v2/api/status.js +7 -0
- package/lib/payment/datatrans-v2/api/status.js.map +1 -0
- package/lib/payment/datatrans-v2/api/validate.d.ts +2 -0
- package/lib/payment/datatrans-v2/api/validate.js +10 -0
- package/lib/payment/datatrans-v2/api/validate.js.map +1 -0
- package/lib/payment/datatrans-v2/generateSignature.d.ts +10 -0
- package/lib/payment/datatrans-v2/generateSignature.js +19 -0
- package/lib/payment/datatrans-v2/generateSignature.js.map +1 -0
- package/lib/payment/datatrans-v2/getPaths.d.ts +9 -0
- package/lib/payment/datatrans-v2/getPaths.js +9 -0
- package/lib/payment/datatrans-v2/getPaths.js.map +1 -0
- package/lib/payment/datatrans-v2/index.d.ts +1 -0
- package/lib/payment/datatrans-v2/index.js +384 -0
- package/lib/payment/datatrans-v2/index.js.map +1 -0
- package/lib/payment/datatrans-v2/middleware.d.ts +1 -0
- package/lib/payment/datatrans-v2/middleware.js +111 -0
- package/lib/payment/datatrans-v2/middleware.js.map +1 -0
- package/lib/payment/datatrans-v2/parseRegistrationData.d.ts +11 -0
- package/lib/payment/datatrans-v2/parseRegistrationData.js +26 -0
- package/lib/payment/datatrans-v2/parseRegistrationData.js.map +1 -0
- package/lib/payment/datatrans-v2/roundedAmountFromOrder.d.ts +7 -0
- package/lib/payment/datatrans-v2/roundedAmountFromOrder.js +10 -0
- package/lib/payment/datatrans-v2/roundedAmountFromOrder.js.map +1 -0
- package/lib/payment/datatrans-v2/splitProperties.d.ts +8 -0
- package/lib/payment/datatrans-v2/splitProperties.js +58 -0
- package/lib/payment/datatrans-v2/splitProperties.js.map +1 -0
- package/lib/payment/invoice-prepaid.d.ts +1 -0
- package/lib/payment/invoice-prepaid.js +30 -0
- package/lib/payment/invoice-prepaid.js.map +1 -0
- package/lib/payment/invoice.d.ts +1 -0
- package/lib/payment/invoice.js +27 -0
- package/lib/payment/invoice.js.map +1 -0
- package/lib/payment/paypal-checkout.d.ts +1 -0
- package/lib/payment/paypal-checkout.js +82 -0
- package/lib/payment/paypal-checkout.js.map +1 -0
- package/lib/payment/postfinance-checkout/api.d.ts +11 -0
- package/lib/payment/postfinance-checkout/api.js +109 -0
- package/lib/payment/postfinance-checkout/api.js.map +1 -0
- package/lib/payment/postfinance-checkout/index.d.ts +1 -0
- package/lib/payment/postfinance-checkout/index.js +186 -0
- package/lib/payment/postfinance-checkout/index.js.map +1 -0
- package/lib/payment/postfinance-checkout/middleware.d.ts +1 -0
- package/lib/payment/postfinance-checkout/middleware.js +42 -0
- package/lib/payment/postfinance-checkout/middleware.js.map +1 -0
- package/lib/payment/postfinance-checkout/types.d.ts +23 -0
- package/lib/payment/postfinance-checkout/types.js +12 -0
- package/lib/payment/postfinance-checkout/types.js.map +1 -0
- package/lib/payment/postfinance-checkout/utils.d.ts +4 -0
- package/lib/payment/postfinance-checkout/utils.js +20 -0
- package/lib/payment/postfinance-checkout/utils.js.map +1 -0
- package/lib/payment/stripe.d.ts +1 -0
- package/lib/payment/stripe.js +214 -0
- package/lib/payment/stripe.js.map +1 -0
- package/lib/payment/worldline-saferpay/index.d.ts +1 -0
- package/lib/payment/worldline-saferpay/index.js +112 -0
- package/lib/payment/worldline-saferpay/index.js.map +1 -0
- package/lib/payment/worldline-saferpay/worldline-saferpay-client/api/SaferpayClient.d.ts +14 -0
- package/lib/payment/worldline-saferpay/worldline-saferpay-client/api/SaferpayClient.js +29 -0
- package/lib/payment/worldline-saferpay/worldline-saferpay-client/api/SaferpayClient.js.map +1 -0
- package/lib/payment/worldline-saferpay/worldline-saferpay-client/api/SaferpayConnection.d.ts +9 -0
- package/lib/payment/worldline-saferpay/worldline-saferpay-client/api/SaferpayConnection.js +28 -0
- package/lib/payment/worldline-saferpay/worldline-saferpay-client/api/SaferpayConnection.js.map +1 -0
- package/lib/payment/worldline-saferpay/worldline-saferpay-client/index.d.ts +4 -0
- package/lib/payment/worldline-saferpay/worldline-saferpay-client/index.js +2 -0
- package/lib/payment/worldline-saferpay/worldline-saferpay-client/index.js.map +1 -0
- package/lib/payment/worldline-saferpay/worldline-saferpay-client/models/PaymentMethods.d.ts +1 -0
- package/lib/payment/worldline-saferpay/worldline-saferpay-client/models/PaymentMethods.js +2 -0
- package/lib/payment/worldline-saferpay/worldline-saferpay-client/models/PaymentMethods.js.map +1 -0
- package/lib/payment/worldline-saferpay/worldline-saferpay-client/models/PaymentPageAssert.d.ts +73 -0
- package/lib/payment/worldline-saferpay/worldline-saferpay-client/models/PaymentPageAssert.js +2 -0
- package/lib/payment/worldline-saferpay/worldline-saferpay-client/models/PaymentPageAssert.js.map +1 -0
- package/lib/payment/worldline-saferpay/worldline-saferpay-client/models/PaymentPageInitialize.d.ts +53 -0
- package/lib/payment/worldline-saferpay/worldline-saferpay-client/models/PaymentPageInitialize.js +2 -0
- package/lib/payment/worldline-saferpay/worldline-saferpay-client/models/PaymentPageInitialize.js.map +1 -0
- package/lib/payment/worldline-saferpay/worldline-saferpay-client/models/Request.d.ts +13 -0
- package/lib/payment/worldline-saferpay/worldline-saferpay-client/models/Request.js +2 -0
- package/lib/payment/worldline-saferpay/worldline-saferpay-client/models/Request.js.map +1 -0
- package/lib/payment/worldline-saferpay/worldline-saferpay-client/models/Response.d.ts +9 -0
- package/lib/payment/worldline-saferpay/worldline-saferpay-client/models/Response.js +2 -0
- package/lib/payment/worldline-saferpay/worldline-saferpay-client/models/Response.js.map +1 -0
- package/lib/payment/worldline-saferpay/worldline-saferpay-client/models/Transaction.d.ts +5 -0
- package/lib/payment/worldline-saferpay/worldline-saferpay-client/models/Transaction.js +2 -0
- package/lib/payment/worldline-saferpay/worldline-saferpay-client/models/Transaction.js.map +1 -0
- package/lib/payment/worldline-saferpay/worldline-saferpay-client/models/TransactionCancel.d.ts +13 -0
- package/lib/payment/worldline-saferpay/worldline-saferpay-client/models/TransactionCancel.js +2 -0
- package/lib/payment/worldline-saferpay/worldline-saferpay-client/models/TransactionCancel.js.map +1 -0
- package/lib/pricing/delivery-swiss-tax.d.ts +15 -0
- package/lib/pricing/delivery-swiss-tax.js +98 -0
- package/lib/pricing/delivery-swiss-tax.js.map +1 -0
- package/lib/pricing/discount-100-off.d.ts +1 -0
- package/lib/pricing/discount-100-off.js +34 -0
- package/lib/pricing/discount-100-off.js.map +1 -0
- package/lib/pricing/discount-half-price-manual.d.ts +1 -0
- package/lib/pricing/discount-half-price-manual.js +34 -0
- package/lib/pricing/discount-half-price-manual.js.map +1 -0
- package/lib/pricing/discount-half-price.d.ts +1 -0
- package/lib/pricing/discount-half-price.js +37 -0
- package/lib/pricing/discount-half-price.js.map +1 -0
- package/lib/pricing/free-delivery.d.ts +2 -0
- package/lib/pricing/free-delivery.js +26 -0
- package/lib/pricing/free-delivery.js.map +1 -0
- package/lib/pricing/free-payment.d.ts +2 -0
- package/lib/pricing/free-payment.js +26 -0
- package/lib/pricing/free-payment.js.map +1 -0
- package/lib/pricing/order-delivery.d.ts +1 -0
- package/lib/pricing/order-delivery.js +33 -0
- package/lib/pricing/order-delivery.js.map +1 -0
- package/lib/pricing/order-discount.d.ts +1 -0
- package/lib/pricing/order-discount.js +110 -0
- package/lib/pricing/order-discount.js.map +1 -0
- package/lib/pricing/order-items-discount.d.ts +1 -0
- package/lib/pricing/order-items-discount.js +88 -0
- package/lib/pricing/order-items-discount.js.map +1 -0
- package/lib/pricing/order-items.d.ts +1 -0
- package/lib/pricing/order-items.js +44 -0
- package/lib/pricing/order-items.js.map +1 -0
- package/lib/pricing/order-payment.d.ts +1 -0
- package/lib/pricing/order-payment.js +33 -0
- package/lib/pricing/order-payment.js.map +1 -0
- package/lib/pricing/product-catalog-price.d.ts +1 -0
- package/lib/pricing/product-catalog-price.js +37 -0
- package/lib/pricing/product-catalog-price.js.map +1 -0
- package/lib/pricing/product-discount.d.ts +1 -0
- package/lib/pricing/product-discount.js +55 -0
- package/lib/pricing/product-discount.js.map +1 -0
- package/lib/pricing/product-price-ECB-interbank-exchange.d.ts +1 -0
- package/lib/pricing/product-price-ECB-interbank-exchange.js +90 -0
- package/lib/pricing/product-price-ECB-interbank-exchange.js.map +1 -0
- package/lib/pricing/product-price-coinbase-exchange.d.ts +1 -0
- package/lib/pricing/product-price-coinbase-exchange.js +60 -0
- package/lib/pricing/product-price-coinbase-exchange.js.map +1 -0
- package/lib/pricing/product-price-cryptopay.d.ts +1 -0
- package/lib/pricing/product-price-cryptopay.js +21 -0
- package/lib/pricing/product-price-cryptopay.js.map +1 -0
- package/lib/pricing/product-price-rateconversion.d.ts +1 -0
- package/lib/pricing/product-price-rateconversion.js +51 -0
- package/lib/pricing/product-price-rateconversion.js.map +1 -0
- package/lib/pricing/product-price-round.d.ts +11 -0
- package/lib/pricing/product-price-round.js +54 -0
- package/lib/pricing/product-price-round.js.map +1 -0
- package/lib/pricing/product-swiss-tax.d.ts +13 -0
- package/lib/pricing/product-swiss-tax.js +102 -0
- package/lib/pricing/product-swiss-tax.js.map +1 -0
- package/lib/pricing/utils/cache.d.ts +9 -0
- package/lib/pricing/utils/cache.js +28 -0
- package/lib/pricing/utils/cache.js.map +1 -0
- package/lib/quotations/manual.d.ts +1 -0
- package/lib/quotations/manual.js +21 -0
- package/lib/quotations/manual.js.map +1 -0
- package/lib/warehousing/google-sheets.d.ts +1 -0
- package/lib/warehousing/google-sheets.js +153 -0
- package/lib/warehousing/google-sheets.js.map +1 -0
- package/lib/warehousing/store.d.ts +1 -0
- package/lib/warehousing/store.js +33 -0
- package/lib/warehousing/store.js.map +1 -0
- package/lib/worker/BulkImportWorker.js +3 -3
- package/lib/worker/BulkImportWorker.js.map +1 -1
- package/lib/worker/GenerateOrderWorker.js +1 -1
- package/lib/worker/GenerateOrderWorker.js.map +1 -1
- package/lib/worker/email.js +55 -4
- package/lib/worker/email.js.map +1 -1
- package/package.json +18 -2
- package/src/delivery/pick-mup.ts +119 -0
- package/src/delivery/post.ts +30 -0
- package/src/delivery/send-message.ts +54 -0
- package/src/delivery/stores.ts +49 -0
- package/src/enrollments/licensed.ts +49 -0
- package/src/filters/local-search.ts +105 -0
- package/src/filters/strict-equal.ts +31 -0
- package/src/payment/apple-iap/adapter.ts +390 -0
- package/src/payment/apple-iap/db/AppleTransactionsCollection.ts +13 -0
- package/src/payment/apple-iap/index.ts +3 -0
- package/src/payment/apple-iap/module/configureAppleTransactionsModule.ts +31 -0
- package/src/payment/bity/adapter.ts +417 -0
- package/src/payment/bity/db/BityCredentialsCollection.ts +17 -0
- package/src/payment/bity/index.ts +3 -0
- package/src/payment/bity/module/configureBityModule.ts +46 -0
- package/src/payment/braintree.ts +147 -0
- package/src/payment/cryptopay.ts +195 -0
- package/src/payment/datatrans-v2/api/authorize.ts +17 -0
- package/src/payment/datatrans-v2/api/authorizeAuthenticated.ts +20 -0
- package/src/payment/datatrans-v2/api/cancel.ts +13 -0
- package/src/payment/datatrans-v2/api/index.ts +24 -0
- package/src/payment/datatrans-v2/api/init.ts +40 -0
- package/src/payment/datatrans-v2/api/makeFetcher.ts +49 -0
- package/src/payment/datatrans-v2/api/secureFields.ts +19 -0
- package/src/payment/datatrans-v2/api/settle.ts +13 -0
- package/src/payment/datatrans-v2/api/status.ts +8 -0
- package/src/payment/datatrans-v2/api/types.d.ts +378 -0
- package/src/payment/datatrans-v2/api/validate.ts +13 -0
- package/src/payment/datatrans-v2/generateSignature.ts +24 -0
- package/src/payment/datatrans-v2/getPaths.ts +24 -0
- package/src/payment/datatrans-v2/index.ts +476 -0
- package/src/payment/datatrans-v2/middleware.ts +147 -0
- package/src/payment/datatrans-v2/parseRegistrationData.ts +32 -0
- package/src/payment/datatrans-v2/roundedAmountFromOrder.ts +16 -0
- package/src/payment/datatrans-v2/splitProperties.ts +63 -0
- package/src/payment/invoice-prepaid.ts +40 -0
- package/src/payment/invoice.ts +36 -0
- package/src/payment/paypal-checkout.ts +107 -0
- package/src/payment/postfinance-checkout/api.ts +142 -0
- package/src/payment/postfinance-checkout/index.ts +241 -0
- package/src/payment/postfinance-checkout/middleware.ts +54 -0
- package/src/payment/postfinance-checkout/types.ts +27 -0
- package/src/payment/postfinance-checkout/utils.ts +35 -0
- package/src/payment/stripe.ts +278 -0
- package/src/payment/worldline-saferpay/index.ts +140 -0
- package/src/payment/worldline-saferpay/worldline-saferpay-client/api/SaferpayClient.ts +54 -0
- package/src/payment/worldline-saferpay/worldline-saferpay-client/api/SaferpayConnection.ts +36 -0
- package/src/payment/worldline-saferpay/worldline-saferpay-client/index.ts +8 -0
- package/src/payment/worldline-saferpay/worldline-saferpay-client/models/PaymentMethods.ts +26 -0
- package/src/payment/worldline-saferpay/worldline-saferpay-client/models/PaymentPageAssert.ts +75 -0
- package/src/payment/worldline-saferpay/worldline-saferpay-client/models/PaymentPageInitialize.ts +55 -0
- package/src/payment/worldline-saferpay/worldline-saferpay-client/models/Request.ts +14 -0
- package/src/payment/worldline-saferpay/worldline-saferpay-client/models/Response.ts +9 -0
- package/src/payment/worldline-saferpay/worldline-saferpay-client/models/Transaction.ts +6 -0
- package/src/payment/worldline-saferpay/worldline-saferpay-client/models/TransactionCancel.ts +15 -0
- package/src/pricing/delivery-swiss-tax.ts +115 -0
- package/src/pricing/discount-100-off.ts +44 -0
- package/src/pricing/discount-half-price-manual.ts +43 -0
- package/src/pricing/discount-half-price.ts +46 -0
- package/src/pricing/free-delivery.ts +31 -0
- package/src/pricing/free-payment.ts +32 -0
- package/src/pricing/order-delivery.ts +45 -0
- package/src/pricing/order-discount.ts +158 -0
- package/src/pricing/order-items-discount.ts +116 -0
- package/src/pricing/order-items.ts +61 -0
- package/src/pricing/order-payment.ts +46 -0
- package/src/pricing/product-catalog-price.ts +56 -0
- package/src/pricing/product-discount.ts +69 -0
- package/src/pricing/product-price-ECB-interbank-exchange.ts +108 -0
- package/src/pricing/product-price-coinbase-exchange.ts +82 -0
- package/src/pricing/product-price-cryptopay.ts +25 -0
- package/src/pricing/product-price-rateconversion.ts +73 -0
- package/src/pricing/product-price-round.ts +78 -0
- package/src/pricing/product-swiss-tax.ts +117 -0
- package/src/pricing/utils/cache.js +32 -0
- package/src/quotations/manual.ts +27 -0
- package/src/warehousing/google-sheets.ts +165 -0
- package/src/warehousing/store.ts +47 -0
- package/src/worker/BulkImportWorker.ts +3 -3
- package/src/worker/GenerateOrderWorker.ts +1 -1
- package/src/worker/email.ts +56 -4
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { IProductPricingAdapter } from '@unchainedshop/types/products.pricing';
|
|
2
|
+
import { ProductPricingAdapter } from '@unchainedshop/core-products';
|
|
3
|
+
|
|
4
|
+
const roundToNext = (value, precision) =>
|
|
5
|
+
value % precision === precision / 2
|
|
6
|
+
? value + precision / 2
|
|
7
|
+
: value + (precision - (value % precision));
|
|
8
|
+
|
|
9
|
+
// String is referencing to a currency
|
|
10
|
+
interface PriceRoundSettings {
|
|
11
|
+
configurations: Record<string, number>;
|
|
12
|
+
defaultPrecision: number;
|
|
13
|
+
skip: Array<string>;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const ProductPriceRoundSettings: PriceRoundSettings = {
|
|
17
|
+
configurations: {},
|
|
18
|
+
defaultPrecision: 50,
|
|
19
|
+
skip: [],
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export const configureProductPriceRounding = ({
|
|
23
|
+
configurations,
|
|
24
|
+
defaultPrecision,
|
|
25
|
+
skip,
|
|
26
|
+
}: PriceRoundSettings) => {
|
|
27
|
+
if (defaultPrecision) ProductPriceRoundSettings.defaultPrecision = defaultPrecision;
|
|
28
|
+
if (configurations) ProductPriceRoundSettings.configurations = configurations;
|
|
29
|
+
if (skip?.length) ProductPriceRoundSettings.skip = skip;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export const ProductPriceRound: IProductPricingAdapter & {
|
|
33
|
+
configure: (params: PriceRoundSettings) => void;
|
|
34
|
+
} = {
|
|
35
|
+
...ProductPricingAdapter,
|
|
36
|
+
|
|
37
|
+
key: 'shop.unchained.pricing.price-round',
|
|
38
|
+
version: '1.0',
|
|
39
|
+
label: 'Round product price to the next precision number',
|
|
40
|
+
orderIndex: 2,
|
|
41
|
+
|
|
42
|
+
isActivatedFor: () => {
|
|
43
|
+
return true;
|
|
44
|
+
},
|
|
45
|
+
|
|
46
|
+
configure: configureProductPriceRounding,
|
|
47
|
+
|
|
48
|
+
actions: (params) => {
|
|
49
|
+
const pricingAdapter = ProductPricingAdapter.actions(params);
|
|
50
|
+
|
|
51
|
+
return {
|
|
52
|
+
...pricingAdapter,
|
|
53
|
+
|
|
54
|
+
calculate: async () => {
|
|
55
|
+
const { currency, quantity } = params.context;
|
|
56
|
+
const { configurations, skip, defaultPrecision } = ProductPriceRoundSettings;
|
|
57
|
+
const { calculation = [] } = params.calculationSheet;
|
|
58
|
+
|
|
59
|
+
if (skip?.indexOf(currency) !== -1) return pricingAdapter.calculate();
|
|
60
|
+
|
|
61
|
+
const roundPrecision = configurations?.[currency] || defaultPrecision;
|
|
62
|
+
|
|
63
|
+
if (calculation?.length && roundPrecision) {
|
|
64
|
+
const [productPrice] = calculation;
|
|
65
|
+
pricingAdapter.resultSheet().resetCalculation(params.calculationSheet);
|
|
66
|
+
pricingAdapter.resultSheet().addItem({
|
|
67
|
+
amount: roundToNext(productPrice.amount, roundPrecision) * quantity,
|
|
68
|
+
isTaxable: productPrice.isTaxable,
|
|
69
|
+
isNetPrice: productPrice.isNetPrice,
|
|
70
|
+
meta: { adapter: ProductPriceRound.key },
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
return pricingAdapter.calculate();
|
|
75
|
+
},
|
|
76
|
+
};
|
|
77
|
+
},
|
|
78
|
+
};
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import moment from 'moment';
|
|
2
|
+
import { ProductPricingDirector, ProductPricingAdapter } from '@unchainedshop/core-products';
|
|
3
|
+
import {
|
|
4
|
+
IProductPricingAdapter,
|
|
5
|
+
ProductPricingAdapterContext,
|
|
6
|
+
} from '@unchainedshop/types/products.pricing';
|
|
7
|
+
|
|
8
|
+
// https://www.ch.ch/de/mehrwertsteuersatz-schweiz/
|
|
9
|
+
export const SwissTaxCategories = {
|
|
10
|
+
DEFAULT: {
|
|
11
|
+
rate: (date) => {
|
|
12
|
+
const referenceDate = moment(date);
|
|
13
|
+
if (referenceDate.isBefore('2018-01-01')) {
|
|
14
|
+
return 0.08;
|
|
15
|
+
}
|
|
16
|
+
return 0.077;
|
|
17
|
+
},
|
|
18
|
+
},
|
|
19
|
+
REDUCED: {
|
|
20
|
+
tag: 'swiss-tax-category:reduced',
|
|
21
|
+
rate: () => {
|
|
22
|
+
return 0.025;
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
SPECIAL: {
|
|
26
|
+
tag: 'swiss-tax-category:special',
|
|
27
|
+
rate: () => {
|
|
28
|
+
return 0.037;
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
const getTaxRate = (context: ProductPricingAdapterContext) => {
|
|
34
|
+
const date = context.order && context.order.ordered ? new Date(context.order.ordered) : new Date();
|
|
35
|
+
const { product } = context;
|
|
36
|
+
|
|
37
|
+
if (product.tags?.includes(SwissTaxCategories.REDUCED.tag)) {
|
|
38
|
+
return SwissTaxCategories.REDUCED.rate();
|
|
39
|
+
}
|
|
40
|
+
if (product.tags?.includes(SwissTaxCategories.SPECIAL.tag)) {
|
|
41
|
+
return SwissTaxCategories.SPECIAL.rate();
|
|
42
|
+
}
|
|
43
|
+
return SwissTaxCategories.DEFAULT.rate(date);
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
const isDeliveryAddressInSwitzerland = async ({ order, country, modules }) => {
|
|
47
|
+
let countryCode = country?.toUpperCase().trim();
|
|
48
|
+
|
|
49
|
+
if (order) {
|
|
50
|
+
const orderDelivery = await modules.orders.deliveries.findDelivery({
|
|
51
|
+
orderDeliveryId: order.deliveryId,
|
|
52
|
+
});
|
|
53
|
+
const address = orderDelivery?.context?.address || order.billingAddress;
|
|
54
|
+
|
|
55
|
+
if (address?.countryCode > '') {
|
|
56
|
+
countryCode = address.countryCode?.toUpperCase().trim();
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return countryCode === 'CH' || countryCode === 'LI';
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
const ProductSwissTax: IProductPricingAdapter = {
|
|
64
|
+
...ProductPricingAdapter,
|
|
65
|
+
|
|
66
|
+
key: 'shop.unchained.pricing.product-swiss-tax',
|
|
67
|
+
version: '1.0',
|
|
68
|
+
label: 'Apply Swiss Tax on Product',
|
|
69
|
+
orderIndex: 20,
|
|
70
|
+
|
|
71
|
+
isActivatedFor: () => {
|
|
72
|
+
return true;
|
|
73
|
+
},
|
|
74
|
+
|
|
75
|
+
actions: (params) => {
|
|
76
|
+
const pricingAdapter = ProductPricingAdapter.actions(params);
|
|
77
|
+
const { context } = params;
|
|
78
|
+
return {
|
|
79
|
+
...pricingAdapter,
|
|
80
|
+
|
|
81
|
+
calculate: async () => {
|
|
82
|
+
if (!(await isDeliveryAddressInSwitzerland(context))) {
|
|
83
|
+
return pricingAdapter.calculate();
|
|
84
|
+
}
|
|
85
|
+
const taxRate = getTaxRate(context);
|
|
86
|
+
ProductPricingAdapter.log(`ProductSwissTax -> Tax Multiplicator: ${taxRate}`);
|
|
87
|
+
params.calculationSheet.filterBy({ isTaxable: true }).forEach(({ isNetPrice, ...row }) => {
|
|
88
|
+
if (!isNetPrice) {
|
|
89
|
+
const taxAmount = row.amount - row.amount / (1 + taxRate);
|
|
90
|
+
pricingAdapter.resultSheet().calculation.push({
|
|
91
|
+
...row,
|
|
92
|
+
amount: -taxAmount,
|
|
93
|
+
isTaxable: false,
|
|
94
|
+
isNetPrice: false,
|
|
95
|
+
meta: { adapter: ProductSwissTax.key },
|
|
96
|
+
});
|
|
97
|
+
pricingAdapter.resultSheet().addTax({
|
|
98
|
+
amount: taxAmount,
|
|
99
|
+
rate: taxRate,
|
|
100
|
+
meta: { adapter: ProductSwissTax.key },
|
|
101
|
+
});
|
|
102
|
+
} else {
|
|
103
|
+
const taxAmount = row.amount * taxRate;
|
|
104
|
+
pricingAdapter.resultSheet().addTax({
|
|
105
|
+
amount: taxAmount,
|
|
106
|
+
rate: taxRate,
|
|
107
|
+
meta: { adapter: ProductSwissTax.key },
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
return pricingAdapter.calculate();
|
|
112
|
+
},
|
|
113
|
+
};
|
|
114
|
+
},
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
ProductPricingDirector.registerAdapter(ProductSwissTax);
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import 'abort-controller/polyfill';
|
|
2
|
+
import LRUCache from 'lru-cache';
|
|
3
|
+
|
|
4
|
+
class Cache {
|
|
5
|
+
constructor(ttlSeconds = 60) {
|
|
6
|
+
this.cache = new LRUCache({
|
|
7
|
+
max: 500,
|
|
8
|
+
ttl: ttlSeconds * 1000,
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
get(key, currentFuntion) {
|
|
13
|
+
const value = this.cache.get(key);
|
|
14
|
+
if (value) {
|
|
15
|
+
return Promise.resolve(value);
|
|
16
|
+
}
|
|
17
|
+
return currentFuntion().then((result) => {
|
|
18
|
+
this.cache.set(key, result);
|
|
19
|
+
return result;
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
del(keys) {
|
|
24
|
+
this.cache.del(keys);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
flushAll() {
|
|
28
|
+
this.cache.reset();
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export default Cache;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { IQuotationAdapter } from '@unchainedshop/types/quotations';
|
|
2
|
+
import { QuotationDirector, QuotationAdapter } from '@unchainedshop/core-quotations';
|
|
3
|
+
|
|
4
|
+
const ManualOffering: IQuotationAdapter = {
|
|
5
|
+
...QuotationAdapter,
|
|
6
|
+
|
|
7
|
+
key: 'shop.unchained.quotations.manual',
|
|
8
|
+
version: '1.0',
|
|
9
|
+
label: 'Manual Offerings',
|
|
10
|
+
orderIndex: 0,
|
|
11
|
+
|
|
12
|
+
isActivatedFor: () => true,
|
|
13
|
+
|
|
14
|
+
actions: (params) => {
|
|
15
|
+
return {
|
|
16
|
+
...QuotationAdapter.actions(params),
|
|
17
|
+
|
|
18
|
+
quote: async () => {
|
|
19
|
+
return {
|
|
20
|
+
expires: new Date(new Date().getTime() + 3600 * 1000),
|
|
21
|
+
};
|
|
22
|
+
},
|
|
23
|
+
};
|
|
24
|
+
},
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
QuotationDirector.registerAdapter(ManualOffering);
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import {
|
|
2
|
+
WarehousingDirector,
|
|
3
|
+
WarehousingAdapter,
|
|
4
|
+
WarehousingProviderType,
|
|
5
|
+
} from '@unchainedshop/core-warehousing';
|
|
6
|
+
import Sheets from 'node-sheets';
|
|
7
|
+
import { log, LogLevel } from '@unchainedshop/logger';
|
|
8
|
+
import 'abort-controller/polyfill';
|
|
9
|
+
import LRU from 'lru-cache';
|
|
10
|
+
import { IWarehousingAdapter } from '@unchainedshop/types/warehousing';
|
|
11
|
+
|
|
12
|
+
const { NODE_ENV, GOOGLE_SHEETS_ID, GOOGLE_SHEETS_PRIVATE_KEY_DATA } = process.env;
|
|
13
|
+
|
|
14
|
+
const ttl = NODE_ENV === 'production' ? 1000 * 60 * 60 : 0; // 1 hour or 1 second
|
|
15
|
+
|
|
16
|
+
const downloadSpreadsheet = async () => {
|
|
17
|
+
if (!GOOGLE_SHEETS_PRIVATE_KEY_DATA || !GOOGLE_SHEETS_ID) return null;
|
|
18
|
+
try {
|
|
19
|
+
// https://docs.google.com/spreadsheets/d/GOOGLE_SHEETS_ID/edit?usp=sharing
|
|
20
|
+
const gs = new Sheets(GOOGLE_SHEETS_ID);
|
|
21
|
+
const authData = JSON.parse(GOOGLE_SHEETS_PRIVATE_KEY_DATA);
|
|
22
|
+
await gs.authorizeJWT(authData);
|
|
23
|
+
const delivery = await gs.tables('delivery!A:ZZZ');
|
|
24
|
+
const inventory = await gs.tables('inventory!A:ZZZ');
|
|
25
|
+
log(`GoogleSheet: Updated cache with TTL: ${ttl}`, {
|
|
26
|
+
level: LogLevel.Verbose,
|
|
27
|
+
});
|
|
28
|
+
return {
|
|
29
|
+
delivery,
|
|
30
|
+
inventory,
|
|
31
|
+
};
|
|
32
|
+
} catch (err) {
|
|
33
|
+
log(err, { level: LogLevel.Error });
|
|
34
|
+
throw err;
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
const updateGoogleCache = async (cache) => {
|
|
39
|
+
try {
|
|
40
|
+
const sheet = await downloadSpreadsheet();
|
|
41
|
+
if (sheet) {
|
|
42
|
+
cache.set('tables', sheet);
|
|
43
|
+
return sheet;
|
|
44
|
+
}
|
|
45
|
+
} catch (e) {
|
|
46
|
+
log(e, { level: LogLevel.Error });
|
|
47
|
+
}
|
|
48
|
+
return null;
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
const googleCache = new LRU({
|
|
52
|
+
max: 500,
|
|
53
|
+
ttl, // 1 second in dev
|
|
54
|
+
allowStale: true,
|
|
55
|
+
dispose: () => {
|
|
56
|
+
updateGoogleCache(googleCache);
|
|
57
|
+
},
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
updateGoogleCache(googleCache);
|
|
61
|
+
|
|
62
|
+
const getRows = async (name: string) => {
|
|
63
|
+
const cachedTables = googleCache.get('tables');
|
|
64
|
+
let tables = cachedTables;
|
|
65
|
+
if (!cachedTables) {
|
|
66
|
+
tables = await updateGoogleCache(googleCache);
|
|
67
|
+
}
|
|
68
|
+
if (!tables || !tables[name] || !tables[name].rows) return [];
|
|
69
|
+
return tables[name].rows;
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
const getRemoteTime = async (sku: string, quantity: number, selector: string) => {
|
|
73
|
+
const rows = await getRows('delivery');
|
|
74
|
+
const resolvedRow = rows.reduce((result, row) => {
|
|
75
|
+
const parsedQuantity = parseInt(row.Quantity.value, 10);
|
|
76
|
+
const parsedSKU = row.SKU.value.toUpperCase();
|
|
77
|
+
if (parsedSKU === sku && parsedQuantity <= quantity) {
|
|
78
|
+
return row;
|
|
79
|
+
}
|
|
80
|
+
return result;
|
|
81
|
+
}, null);
|
|
82
|
+
if (!resolvedRow) return null;
|
|
83
|
+
const time = parseInt(resolvedRow[selector].value, 10) || 0;
|
|
84
|
+
log(`GoogleSheet: Resolve Time ${selector} (${quantity}) for ${sku}: ${time}`, {
|
|
85
|
+
level: LogLevel.Verbose,
|
|
86
|
+
});
|
|
87
|
+
return time;
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
const getRemoteInventory = async (sku: string) => {
|
|
91
|
+
const rows = await getRows('inventory');
|
|
92
|
+
const resolvedRow = [].concat(rows).reduce((result, row) => {
|
|
93
|
+
if (result || !row) return result;
|
|
94
|
+
const parsedSKU = row.SKU.value.toUpperCase();
|
|
95
|
+
if (parsedSKU === sku) {
|
|
96
|
+
return row;
|
|
97
|
+
}
|
|
98
|
+
return result;
|
|
99
|
+
}, null);
|
|
100
|
+
if (!resolvedRow) return null;
|
|
101
|
+
const amount = parseInt(resolvedRow.Stock.value, 10) || 0;
|
|
102
|
+
log(`GoogleSheet: Resolve Inventory for ${sku}: ${amount}`, {
|
|
103
|
+
level: LogLevel.Verbose,
|
|
104
|
+
});
|
|
105
|
+
return amount;
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
const GoogleSheets: IWarehousingAdapter = {
|
|
109
|
+
...WarehousingAdapter,
|
|
110
|
+
|
|
111
|
+
key: 'shop.unchained.warehousing.google-sheets',
|
|
112
|
+
version: '1.0',
|
|
113
|
+
label: 'Google Sheets',
|
|
114
|
+
orderIndex: 0,
|
|
115
|
+
|
|
116
|
+
typeSupported: (type) => {
|
|
117
|
+
return type === WarehousingProviderType.PHYSICAL;
|
|
118
|
+
},
|
|
119
|
+
|
|
120
|
+
initialConfiguration: [
|
|
121
|
+
{
|
|
122
|
+
key: 'sheetId',
|
|
123
|
+
value: null,
|
|
124
|
+
},
|
|
125
|
+
],
|
|
126
|
+
|
|
127
|
+
actions: (_, context) => {
|
|
128
|
+
return {
|
|
129
|
+
isActive: () => {
|
|
130
|
+
return true;
|
|
131
|
+
},
|
|
132
|
+
|
|
133
|
+
configurationError: () => {
|
|
134
|
+
return null;
|
|
135
|
+
},
|
|
136
|
+
|
|
137
|
+
stock: async () => {
|
|
138
|
+
const { sku } = context.product.warehousing || {};
|
|
139
|
+
return getRemoteInventory(sku);
|
|
140
|
+
},
|
|
141
|
+
|
|
142
|
+
productionTime: async (quantity: number) => {
|
|
143
|
+
const { sku } = context.product.warehousing || {};
|
|
144
|
+
if (!sku) return null;
|
|
145
|
+
const selector = 'WAREHOUSE_HOURS';
|
|
146
|
+
const timeInHours = await getRemoteTime(sku.toUpperCase(), quantity, selector);
|
|
147
|
+
if (!timeInHours) return null;
|
|
148
|
+
return timeInHours * 60 * 60 * 1000;
|
|
149
|
+
},
|
|
150
|
+
|
|
151
|
+
commissioningTime: async (quantity) => {
|
|
152
|
+
const { product, deliveryProvider } = context;
|
|
153
|
+
const { sku } = product.warehousing || {};
|
|
154
|
+
if (!sku) return null;
|
|
155
|
+
const { type } = deliveryProvider;
|
|
156
|
+
const selector = `DELIVERY_HOURS:${type}`;
|
|
157
|
+
const timeInHours = await getRemoteTime(sku.toUpperCase(), quantity, selector);
|
|
158
|
+
if (!timeInHours) return null;
|
|
159
|
+
return timeInHours * 60 * 60 * 1000;
|
|
160
|
+
},
|
|
161
|
+
};
|
|
162
|
+
},
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
WarehousingDirector.registerAdapter(GoogleSheets);
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import {
|
|
2
|
+
WarehousingDirector,
|
|
3
|
+
WarehousingAdapter,
|
|
4
|
+
WarehousingProviderType,
|
|
5
|
+
} from '@unchainedshop/core-warehousing';
|
|
6
|
+
import { IWarehousingAdapter } from '@unchainedshop/types/warehousing';
|
|
7
|
+
|
|
8
|
+
const Store: IWarehousingAdapter = {
|
|
9
|
+
...WarehousingAdapter,
|
|
10
|
+
|
|
11
|
+
key: 'shop.unchained.warehousing.store',
|
|
12
|
+
version: '1.0',
|
|
13
|
+
label: 'Store',
|
|
14
|
+
orderIndex: 0,
|
|
15
|
+
|
|
16
|
+
initialConfiguration: [{ key: 'name', value: 'Flagship Store' }],
|
|
17
|
+
|
|
18
|
+
typeSupported: (type) => {
|
|
19
|
+
return type === WarehousingProviderType.PHYSICAL;
|
|
20
|
+
},
|
|
21
|
+
|
|
22
|
+
actions: () => {
|
|
23
|
+
return {
|
|
24
|
+
isActive: async () => {
|
|
25
|
+
return true;
|
|
26
|
+
},
|
|
27
|
+
|
|
28
|
+
configurationError: async () => {
|
|
29
|
+
return null;
|
|
30
|
+
},
|
|
31
|
+
|
|
32
|
+
stock: async () => {
|
|
33
|
+
return 99999;
|
|
34
|
+
},
|
|
35
|
+
|
|
36
|
+
productionTime: async () => {
|
|
37
|
+
return 0;
|
|
38
|
+
},
|
|
39
|
+
|
|
40
|
+
commissioningTime: async () => {
|
|
41
|
+
return 0;
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
},
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
WarehousingDirector.registerAdapter(Store);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { IWorkerAdapter } from '@unchainedshop/types/worker';
|
|
2
2
|
import { WorkerDirector } from '@unchainedshop/core-worker';
|
|
3
|
-
import { createLogger } from '@unchainedshop/logger';
|
|
3
|
+
import { createLogger, LogLevel } from '@unchainedshop/logger';
|
|
4
4
|
import { BaseAdapter } from '@unchainedshop/utils';
|
|
5
5
|
import fs from 'fs';
|
|
6
6
|
import JSONStream from 'JSONStream';
|
|
@@ -9,7 +9,7 @@ import { EventIterator } from 'event-iterator';
|
|
|
9
9
|
const logger = createLogger('unchained:platform:bulk-import');
|
|
10
10
|
|
|
11
11
|
const streamPayloadToBulkImporter = async (bulkImporter, createReadStream) => {
|
|
12
|
-
logger.profile(`parseAsync`, { level: '
|
|
12
|
+
logger.profile(`parseAsync`, { level: LogLevel.Verbose, message: 'parseAsync' });
|
|
13
13
|
|
|
14
14
|
const eventIterator = new EventIterator(
|
|
15
15
|
(queue) => {
|
|
@@ -37,7 +37,7 @@ const streamPayloadToBulkImporter = async (bulkImporter, createReadStream) => {
|
|
|
37
37
|
await bulkImporter.prepare(event);
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
-
logger.profile(`parseAsync`, { level: '
|
|
40
|
+
logger.profile(`parseAsync`, { level: LogLevel.Verbose, message: 'parseAsync' });
|
|
41
41
|
};
|
|
42
42
|
|
|
43
43
|
export const BulkImportWorker: IWorkerAdapter<any, Record<string, unknown>> = {
|
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
EnrollmentDirector,
|
|
8
8
|
enrollmentsSettings,
|
|
9
9
|
EnrollmentStatus,
|
|
10
|
-
} from '
|
|
10
|
+
} from '@unchainedshop/core-enrollments';
|
|
11
11
|
import { WorkerAdapter, WorkerDirector } from '@unchainedshop/core-worker';
|
|
12
12
|
|
|
13
13
|
const generateOrder = async (
|
package/src/worker/email.ts
CHANGED
|
@@ -1,10 +1,57 @@
|
|
|
1
1
|
import { WorkerDirector, WorkerAdapter } from '@unchainedshop/core-worker';
|
|
2
2
|
import { createLogger } from '@unchainedshop/logger';
|
|
3
|
-
import { Email } from 'meteor/email';
|
|
4
3
|
import { IWorkerAdapter } from '@unchainedshop/types/worker';
|
|
4
|
+
import fs from 'fs';
|
|
5
|
+
import path from 'path';
|
|
6
|
+
import os from 'os';
|
|
7
|
+
import open from 'open';
|
|
5
8
|
|
|
6
9
|
const logger = createLogger('unchained:plugins:worker:email');
|
|
7
10
|
|
|
11
|
+
const checkEmailInterceptionEnabled = () => {
|
|
12
|
+
return process.env.NODE_ENV !== 'production' && !process.env.UNCHAINED_DISABLE_EMAIL_INTERCEPTION;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
function writeFile(filename, data, done) {
|
|
16
|
+
fs.mkdtemp(path.join(os.tmpdir(), 'email-'), (err1, folder) => {
|
|
17
|
+
if (err1) return done(err1);
|
|
18
|
+
const temporaryFolderPath = `${folder}/${filename}`;
|
|
19
|
+
return fs.writeFile(temporaryFolderPath, data, (err2) => {
|
|
20
|
+
if (err2) return done(err2);
|
|
21
|
+
return done(null, temporaryFolderPath);
|
|
22
|
+
});
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const openInBrowser = (options) => {
|
|
27
|
+
const filename = `${Date.now()}.html`;
|
|
28
|
+
const content = `
|
|
29
|
+
<b>From: </b>${options.from}<br/>
|
|
30
|
+
<b>To: </b>${options.to}<br/>
|
|
31
|
+
<b>Cc: </b>${options.cc}<br/>
|
|
32
|
+
<b>Bcc: </b>${options.bcc}<br/>
|
|
33
|
+
<b>Reply-To: </b>${options.replyTo}<br/>
|
|
34
|
+
<br/>
|
|
35
|
+
<b>subject: </b>${options.subject}<br/>
|
|
36
|
+
<b>attachments: </b>${(options.attachments || [])
|
|
37
|
+
.map(({ filename: attachmentFilename, path: attachmentPath }) => {
|
|
38
|
+
const absoluteFilePath = path.join(process.cwd(), attachmentPath);
|
|
39
|
+
return `<a href="${absoluteFilePath}">${attachmentFilename}</a>`;
|
|
40
|
+
})
|
|
41
|
+
.join(', ')}<br/>
|
|
42
|
+
<hr/>
|
|
43
|
+
${(options.html || options.text).replace(/(\r\n|\n|\r)/gm, '<br/>')}
|
|
44
|
+
`;
|
|
45
|
+
writeFile(filename, content, (err, filePath) => {
|
|
46
|
+
if (err) {
|
|
47
|
+
logger.error(err);
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
logger.verbose('unchained:platform -> Mailman detected an outgoing email');
|
|
51
|
+
open(filePath);
|
|
52
|
+
});
|
|
53
|
+
};
|
|
54
|
+
|
|
8
55
|
const EmailWorkerPlugin: IWorkerAdapter<
|
|
9
56
|
{
|
|
10
57
|
from?: string;
|
|
@@ -36,13 +83,18 @@ const EmailWorkerPlugin: IWorkerAdapter<
|
|
|
36
83
|
}
|
|
37
84
|
|
|
38
85
|
try {
|
|
39
|
-
|
|
40
|
-
const result = Email.send({
|
|
86
|
+
const sendMailOptions = {
|
|
41
87
|
from,
|
|
42
88
|
to,
|
|
43
89
|
subject,
|
|
44
90
|
...rest,
|
|
45
|
-
}
|
|
91
|
+
};
|
|
92
|
+
if (checkEmailInterceptionEnabled()) {
|
|
93
|
+
openInBrowser(sendMailOptions);
|
|
94
|
+
return { success: true, result: { intercepted: true } };
|
|
95
|
+
}
|
|
96
|
+
const transporter = nodemailer.createTransport(process.env.MAIL_URL);
|
|
97
|
+
const result = await transporter.sendMail(sendMailOptions);
|
|
46
98
|
return { success: true, result };
|
|
47
99
|
} catch (err) {
|
|
48
100
|
return {
|