@unchainedshop/plugins 4.6.2 → 4.7.2
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/README.md +0 -2
- package/lib/events/node-event-emitter.d.ts +3 -1
- package/lib/events/node-event-emitter.js +3 -3
- package/lib/files/gridfs/adapter.d.ts +2 -2
- package/lib/files/gridfs/adapter.js +2 -5
- package/lib/files/gridfs/index.d.ts +5 -4
- package/lib/files/gridfs/index.js +30 -3
- package/lib/files/minio/index.d.ts +4 -5
- package/lib/files/minio/index.js +18 -157
- package/lib/payment/apple-iap/adapter.d.ts +2 -1
- package/lib/payment/apple-iap/adapter.js +2 -3
- package/lib/payment/apple-iap/index.d.ts +6 -4
- package/lib/payment/apple-iap/index.js +28 -3
- package/lib/payment/cryptopay/index.d.ts +5 -4
- package/lib/payment/cryptopay/index.js +31 -3
- package/lib/payment/datatrans-v2/index.d.ts +4 -1
- package/lib/payment/datatrans-v2/index.js +17 -400
- package/lib/payment/payrexx/index.d.ts +4 -1
- package/lib/payment/payrexx/index.js +19 -158
- package/lib/payment/postfinance-checkout/index.d.ts +5 -0
- package/lib/payment/postfinance-checkout/index.js +25 -186
- package/lib/payment/saferpay/adapter.js +1 -2
- package/lib/payment/saferpay/index.d.ts +5 -4
- package/lib/payment/saferpay/index.js +29 -3
- package/lib/payment/stripe/index.d.ts +4 -1
- package/lib/payment/stripe/index.js +22 -116
- package/lib/payment/stripe/stripe.js +2 -5
- package/lib/presets/all.d.ts +1 -70
- package/lib/presets/all.js +41 -27
- package/lib/presets/base.d.ts +1 -25
- package/lib/presets/base.js +56 -25
- package/lib/presets/countries/ch.d.ts +1 -2
- package/lib/presets/countries/ch.js +7 -2
- package/lib/presets/crypto.d.ts +3 -7
- package/lib/presets/crypto.js +18 -7
- package/package.json +15 -10
- package/lib/delivery/post.d.ts +0 -1
- package/lib/delivery/post.js +0 -23
- package/lib/delivery/send-message.d.ts +0 -1
- package/lib/delivery/send-message.js +0 -40
- package/lib/delivery/stores.d.ts +0 -1
- package/lib/delivery/stores.js +0 -43
- package/lib/enrollments/licensed.d.ts +0 -4
- package/lib/enrollments/licensed.js +0 -52
- package/lib/files/gridfs/handler-express.d.ts +0 -9
- package/lib/files/gridfs/handler-express.js +0 -110
- package/lib/files/gridfs/handler-fastify.d.ts +0 -3
- package/lib/files/gridfs/handler-fastify.js +0 -138
- package/lib/files/minio/handler-express.d.ts +0 -2
- package/lib/files/minio/handler-express.js +0 -36
- package/lib/files/minio/handler-fastify.d.ts +0 -3
- package/lib/files/minio/handler-fastify.js +0 -40
- package/lib/filters/local-search.d.ts +0 -3
- package/lib/filters/local-search.js +0 -66
- package/lib/filters/strict-equal.d.ts +0 -1
- package/lib/filters/strict-equal.js +0 -24
- package/lib/payment/apple-iap/handler-express.d.ts +0 -2
- package/lib/payment/apple-iap/handler-express.js +0 -103
- package/lib/payment/apple-iap/handler-fastify.d.ts +0 -3
- package/lib/payment/apple-iap/handler-fastify.js +0 -102
- package/lib/payment/braintree.d.ts +0 -1
- package/lib/payment/braintree.js +0 -138
- package/lib/payment/cryptopay/handler-express.d.ts +0 -2
- package/lib/payment/cryptopay/handler-express.js +0 -19
- package/lib/payment/cryptopay/handler-fastify.d.ts +0 -3
- package/lib/payment/cryptopay/handler-fastify.js +0 -17
- package/lib/payment/cryptopay/plugin.d.ts +0 -3
- package/lib/payment/cryptopay/plugin.js +0 -159
- package/lib/payment/datatrans-v2/handler-express.d.ts +0 -1
- package/lib/payment/datatrans-v2/handler-express.js +0 -71
- package/lib/payment/datatrans-v2/handler-fastify.d.ts +0 -2
- package/lib/payment/datatrans-v2/handler-fastify.js +0 -71
- package/lib/payment/invoice-prepaid.d.ts +0 -1
- package/lib/payment/invoice-prepaid.js +0 -30
- package/lib/payment/invoice.d.ts +0 -1
- package/lib/payment/invoice.js +0 -27
- package/lib/payment/paypal-checkout.d.ts +0 -1
- package/lib/payment/paypal-checkout.js +0 -87
- package/lib/payment/payrexx/handler-express.d.ts +0 -1
- package/lib/payment/payrexx/handler-express.js +0 -85
- package/lib/payment/payrexx/handler-fastify.d.ts +0 -2
- package/lib/payment/payrexx/handler-fastify.js +0 -91
- package/lib/payment/postfinance-checkout/handler-express.d.ts +0 -1
- package/lib/payment/postfinance-checkout/handler-express.js +0 -37
- package/lib/payment/postfinance-checkout/handler-fastify.d.ts +0 -2
- package/lib/payment/postfinance-checkout/handler-fastify.js +0 -40
- package/lib/payment/saferpay/handler-express.d.ts +0 -1
- package/lib/payment/saferpay/handler-express.js +0 -59
- package/lib/payment/saferpay/handler-fastify.d.ts +0 -2
- package/lib/payment/saferpay/handler-fastify.js +0 -62
- package/lib/payment/stripe/handler-express.d.ts +0 -5
- package/lib/payment/stripe/handler-express.js +0 -121
- package/lib/payment/stripe/handler-fastify.d.ts +0 -6
- package/lib/payment/stripe/handler-fastify.js +0 -131
- package/lib/presets/all-express.d.ts +0 -6
- package/lib/presets/all-express.js +0 -26
- package/lib/presets/all-fastify.d.ts +0 -6
- package/lib/presets/all-fastify.js +0 -49
- package/lib/presets/base-express.d.ts +0 -2
- package/lib/presets/base-express.js +0 -5
- package/lib/presets/base-fastify.d.ts +0 -3
- package/lib/presets/base-fastify.js +0 -16
- package/lib/presets/crypto-express.d.ts +0 -3
- package/lib/presets/crypto-express.js +0 -8
- package/lib/presets/crypto-fastify.d.ts +0 -3
- package/lib/presets/crypto-fastify.js +0 -11
- package/lib/pricing/delivery-swiss-tax.d.ts +0 -2
- package/lib/pricing/delivery-swiss-tax.js +0 -62
- package/lib/pricing/discount-100-off.d.ts +0 -2
- package/lib/pricing/discount-100-off.js +0 -30
- package/lib/pricing/discount-half-price-manual.d.ts +0 -2
- package/lib/pricing/discount-half-price-manual.js +0 -30
- package/lib/pricing/discount-half-price.d.ts +0 -2
- package/lib/pricing/discount-half-price.js +0 -33
- package/lib/pricing/free-delivery.d.ts +0 -2
- package/lib/pricing/free-delivery.js +0 -27
- package/lib/pricing/free-payment.d.ts +0 -2
- package/lib/pricing/free-payment.js +0 -27
- package/lib/pricing/order-delivery.d.ts +0 -2
- package/lib/pricing/order-delivery.js +0 -33
- package/lib/pricing/order-discount.d.ts +0 -2
- package/lib/pricing/order-discount.js +0 -74
- package/lib/pricing/order-items-discount.d.ts +0 -2
- package/lib/pricing/order-items-discount.js +0 -50
- package/lib/pricing/order-items.d.ts +0 -2
- package/lib/pricing/order-items.js +0 -43
- package/lib/pricing/order-payment.d.ts +0 -2
- package/lib/pricing/order-payment.js +0 -33
- package/lib/pricing/order-round.d.ts +0 -10
- package/lib/pricing/order-round.js +0 -135
- package/lib/pricing/product-catalog-price-options.d.ts +0 -2
- package/lib/pricing/product-catalog-price-options.js +0 -51
- package/lib/pricing/product-catalog-price.d.ts +0 -2
- package/lib/pricing/product-catalog-price.js +0 -60
- package/lib/pricing/product-discount.d.ts +0 -2
- package/lib/pricing/product-discount.js +0 -69
- package/lib/pricing/product-price-rateconversion.d.ts +0 -2
- package/lib/pricing/product-price-rateconversion.js +0 -53
- package/lib/pricing/product-round.d.ts +0 -10
- package/lib/pricing/product-round.js +0 -44
- package/lib/pricing/product-swiss-tax.d.ts +0 -2
- package/lib/pricing/product-swiss-tax.js +0 -76
- package/lib/quotations/manual.d.ts +0 -1
- package/lib/quotations/manual.js +0 -20
- package/lib/warehousing/eth-minter.d.ts +0 -1
- package/lib/warehousing/eth-minter.js +0 -120
- package/lib/warehousing/store.d.ts +0 -1
- package/lib/warehousing/store.js +0 -34
- package/lib/worker/budgetsms.d.ts +0 -9
- package/lib/worker/budgetsms.js +0 -169
- package/lib/worker/bulk-export.d.ts +0 -2
- package/lib/worker/bulk-export.js +0 -64
- package/lib/worker/bulk-import.d.ts +0 -2
- package/lib/worker/bulk-import.js +0 -65
- package/lib/worker/bulkgate.d.ts +0 -1
- package/lib/worker/bulkgate.js +0 -91
- package/lib/worker/email.d.ts +0 -1
- package/lib/worker/email.js +0 -136
- package/lib/worker/enrollment-order-generator.d.ts +0 -1
- package/lib/worker/enrollment-order-generator.js +0 -77
- package/lib/worker/error-notifications.d.ts +0 -9
- package/lib/worker/error-notifications.js +0 -61
- package/lib/worker/export-token.d.ts +0 -4
- package/lib/worker/export-token.js +0 -26
- package/lib/worker/external.d.ts +0 -2
- package/lib/worker/external.js +0 -13
- package/lib/worker/heartbeat.d.ts +0 -1
- package/lib/worker/heartbeat.js +0 -26
- package/lib/worker/http-request.d.ts +0 -8
- package/lib/worker/http-request.js +0 -56
- package/lib/worker/message.d.ts +0 -10
- package/lib/worker/message.js +0 -42
- package/lib/worker/push-notification.d.ts +0 -1
- package/lib/worker/push-notification.js +0 -87
- package/lib/worker/twilio.d.ts +0 -1
- package/lib/worker/twilio.js +0 -59
- package/lib/worker/update-coinbase-rates.d.ts +0 -1
- package/lib/worker/update-coinbase-rates.js +0 -59
- package/lib/worker/update-ecb-rates.d.ts +0 -1
- package/lib/worker/update-ecb-rates.js +0 -92
- package/lib/worker/update-token-ownership.d.ts +0 -3
- package/lib/worker/update-token-ownership.js +0 -57
- package/lib/worker/zombie-killer.d.ts +0 -13
- package/lib/worker/zombie-killer.js +0 -91
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import { ProductPricingDirector, ProductPricingAdapter, } from '@unchainedshop/core';
|
|
2
|
-
export const ProductPriceOptions = {
|
|
3
|
-
...ProductPricingAdapter,
|
|
4
|
-
key: 'shop.unchained.pricing.product-price-options',
|
|
5
|
-
version: '1.0',
|
|
6
|
-
label: 'Add Gross Price of Options',
|
|
7
|
-
orderIndex: 1,
|
|
8
|
-
isActivatedFor: () => {
|
|
9
|
-
return true;
|
|
10
|
-
},
|
|
11
|
-
actions: (params) => {
|
|
12
|
-
const pricingAdapter = ProductPricingAdapter.actions(params);
|
|
13
|
-
const { countryCode, currencyCode, quantity, modules } = params.context;
|
|
14
|
-
return {
|
|
15
|
-
...pricingAdapter,
|
|
16
|
-
async calculatePriceForProduct(product) {
|
|
17
|
-
const price = await modules.products.prices.price(product, {
|
|
18
|
-
countryCode,
|
|
19
|
-
currencyCode,
|
|
20
|
-
quantity,
|
|
21
|
-
});
|
|
22
|
-
if (price) {
|
|
23
|
-
const itemTotal = price.amount * quantity;
|
|
24
|
-
pricingAdapter.resultSheet().addItem({
|
|
25
|
-
amount: itemTotal,
|
|
26
|
-
isTaxable: Boolean(price.isTaxable),
|
|
27
|
-
isNetPrice: Boolean(price.isNetPrice),
|
|
28
|
-
meta: { adapter: ProductPriceOptions.key },
|
|
29
|
-
});
|
|
30
|
-
}
|
|
31
|
-
},
|
|
32
|
-
async calculate() {
|
|
33
|
-
const { configuration } = params.context;
|
|
34
|
-
const productIds = configuration?.flatMap(({ key, value }) => {
|
|
35
|
-
if (key === 'option')
|
|
36
|
-
return [value];
|
|
37
|
-
return [];
|
|
38
|
-
});
|
|
39
|
-
if (!productIds?.length) {
|
|
40
|
-
return pricingAdapter.calculate();
|
|
41
|
-
}
|
|
42
|
-
const options = await modules.products.findProducts({
|
|
43
|
-
productIds,
|
|
44
|
-
});
|
|
45
|
-
await Promise.all(options.map(this.calculatePriceForProduct));
|
|
46
|
-
return pricingAdapter.calculate();
|
|
47
|
-
},
|
|
48
|
-
};
|
|
49
|
-
},
|
|
50
|
-
};
|
|
51
|
-
ProductPricingDirector.registerAdapter(ProductPriceOptions);
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import { ProductPricingDirector, ProductPricingAdapter, } from '@unchainedshop/core';
|
|
2
|
-
import { ProductType } from '@unchainedshop/core-products';
|
|
3
|
-
export const ProductPrice = {
|
|
4
|
-
...ProductPricingAdapter,
|
|
5
|
-
key: 'shop.unchained.pricing.product-price',
|
|
6
|
-
version: '1.0.0',
|
|
7
|
-
label: 'Add Gross Price to Product',
|
|
8
|
-
orderIndex: 0,
|
|
9
|
-
isActivatedFor: () => {
|
|
10
|
-
return true;
|
|
11
|
-
},
|
|
12
|
-
actions: (params) => {
|
|
13
|
-
const pricingAdapter = ProductPricingAdapter.actions(params);
|
|
14
|
-
return {
|
|
15
|
-
...pricingAdapter,
|
|
16
|
-
calculate: async () => {
|
|
17
|
-
const { product, countryCode, currencyCode, quantity, modules } = params.context;
|
|
18
|
-
const price = await modules.products.prices.price(product, {
|
|
19
|
-
countryCode,
|
|
20
|
-
currencyCode,
|
|
21
|
-
quantity,
|
|
22
|
-
});
|
|
23
|
-
if (price) {
|
|
24
|
-
const itemTotal = price.amount * quantity;
|
|
25
|
-
pricingAdapter.resultSheet().addItem({
|
|
26
|
-
amount: itemTotal,
|
|
27
|
-
isTaxable: Boolean(price.isTaxable),
|
|
28
|
-
isNetPrice: Boolean(price.isNetPrice),
|
|
29
|
-
meta: { adapter: ProductPrice.key },
|
|
30
|
-
});
|
|
31
|
-
}
|
|
32
|
-
else if (product.type === ProductType.BUNDLE_PRODUCT) {
|
|
33
|
-
for (const bundleItem of product.bundleItems || []) {
|
|
34
|
-
const bundledProduct = await modules.products.findProduct({
|
|
35
|
-
productId: bundleItem.productId,
|
|
36
|
-
});
|
|
37
|
-
if (bundledProduct) {
|
|
38
|
-
const bundleItemPrice = await modules.products.prices.price(bundledProduct, {
|
|
39
|
-
countryCode,
|
|
40
|
-
currencyCode,
|
|
41
|
-
quantity: bundleItem.quantity * quantity,
|
|
42
|
-
});
|
|
43
|
-
if (bundleItemPrice) {
|
|
44
|
-
const bundleItemTotal = bundleItemPrice.amount * bundleItem.quantity * quantity;
|
|
45
|
-
pricingAdapter.resultSheet().addItem({
|
|
46
|
-
amount: bundleItemTotal,
|
|
47
|
-
isTaxable: Boolean(bundleItemPrice.isTaxable),
|
|
48
|
-
isNetPrice: Boolean(bundleItemPrice.isNetPrice),
|
|
49
|
-
meta: { adapter: ProductPrice.key },
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
return pricingAdapter.calculate();
|
|
56
|
-
},
|
|
57
|
-
};
|
|
58
|
-
},
|
|
59
|
-
};
|
|
60
|
-
ProductPricingDirector.registerAdapter(ProductPrice);
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
import { calculation as calcUtils } from '@unchainedshop/utils';
|
|
2
|
-
import { ProductPricingDirector, ProductPricingAdapter, ProductPricingRowCategory, } from '@unchainedshop/core';
|
|
3
|
-
export const ProductDiscount = {
|
|
4
|
-
...ProductPricingAdapter,
|
|
5
|
-
key: 'shop.unchained.pricing.product-discount',
|
|
6
|
-
version: '1.0.0',
|
|
7
|
-
label: 'Apply Discounts on Product Price',
|
|
8
|
-
orderIndex: 30,
|
|
9
|
-
isActivatedFor: () => {
|
|
10
|
-
return true;
|
|
11
|
-
},
|
|
12
|
-
actions: (params) => {
|
|
13
|
-
const pricingAdapter = ProductPricingAdapter.actions(params);
|
|
14
|
-
const addDiscounts = (discount, total, resolvedConfiguration) => {
|
|
15
|
-
const { discountId } = discount;
|
|
16
|
-
const { isNetPrice = false, taxRate, ...meta } = resolvedConfiguration;
|
|
17
|
-
const amount = calcUtils.applyRate(resolvedConfiguration, total);
|
|
18
|
-
const isTaxable = taxRate === undefined || taxRate === null;
|
|
19
|
-
pricingAdapter.resultSheet().addDiscount({
|
|
20
|
-
amount: amount * -1,
|
|
21
|
-
discountId,
|
|
22
|
-
isNetPrice,
|
|
23
|
-
isTaxable,
|
|
24
|
-
meta: { adapter: ProductDiscount.key, ...meta },
|
|
25
|
-
});
|
|
26
|
-
if (!isTaxable && taxRate) {
|
|
27
|
-
const taxAmount = calcUtils.getTaxAmount(amount, taxRate, isNetPrice);
|
|
28
|
-
pricingAdapter.resultSheet().addTax({
|
|
29
|
-
amount: taxAmount * -1,
|
|
30
|
-
rate: taxRate,
|
|
31
|
-
discountId,
|
|
32
|
-
baseCategory: ProductPricingRowCategory.Discount,
|
|
33
|
-
meta: { adapter: ProductDiscount.key, discountId, ...meta },
|
|
34
|
-
});
|
|
35
|
-
if (!isNetPrice) {
|
|
36
|
-
pricingAdapter.resultSheet().addDiscount({
|
|
37
|
-
amount: taxAmount,
|
|
38
|
-
discountId,
|
|
39
|
-
isNetPrice: false,
|
|
40
|
-
isTaxable: false,
|
|
41
|
-
meta: { adapter: ProductDiscount.key, discountId, ...meta },
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
};
|
|
46
|
-
return {
|
|
47
|
-
...pricingAdapter,
|
|
48
|
-
calculate: async () => {
|
|
49
|
-
params.discounts.forEach((discount) => {
|
|
50
|
-
if (!discount)
|
|
51
|
-
return;
|
|
52
|
-
const { configuration } = discount;
|
|
53
|
-
const resolvedConfiguration = configuration.customPriceConfigurationResolver
|
|
54
|
-
? configuration.customPriceConfigurationResolver(params.context.product, params.context.quantity, params.context.configuration)
|
|
55
|
-
: configuration;
|
|
56
|
-
if (!resolvedConfiguration)
|
|
57
|
-
return;
|
|
58
|
-
const total = params.calculationSheet.total({
|
|
59
|
-
category: ProductPricingRowCategory.Item,
|
|
60
|
-
useNetPrice: resolvedConfiguration.isNetPrice,
|
|
61
|
-
});
|
|
62
|
-
addDiscounts(discount, total.amount, resolvedConfiguration);
|
|
63
|
-
});
|
|
64
|
-
return pricingAdapter.calculate();
|
|
65
|
-
},
|
|
66
|
-
};
|
|
67
|
-
},
|
|
68
|
-
};
|
|
69
|
-
ProductPricingDirector.registerAdapter(ProductDiscount);
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import { ProductPricingDirector, ProductPricingAdapter, } from '@unchainedshop/core';
|
|
2
|
-
export const ProductPriceRateConversion = {
|
|
3
|
-
...ProductPricingAdapter,
|
|
4
|
-
key: 'shop.unchained.pricing.rate-conversion',
|
|
5
|
-
version: '1.0.0',
|
|
6
|
-
label: 'Generic rate conversion plugin that converts between rates if entry in DB exists.',
|
|
7
|
-
orderIndex: 10,
|
|
8
|
-
isActivatedFor: () => {
|
|
9
|
-
return true;
|
|
10
|
-
},
|
|
11
|
-
actions: (params) => {
|
|
12
|
-
const pricingAdapter = ProductPricingAdapter.actions(params);
|
|
13
|
-
const { modules } = params.context;
|
|
14
|
-
return {
|
|
15
|
-
...pricingAdapter,
|
|
16
|
-
calculate: async () => {
|
|
17
|
-
const { product, countryCode, quantity, currencyCode: targetCurrency } = params.context;
|
|
18
|
-
const { calculation = [] } = params.calculationSheet;
|
|
19
|
-
if (calculation?.length) {
|
|
20
|
-
return pricingAdapter.calculate();
|
|
21
|
-
}
|
|
22
|
-
const productPrice = await modules.products.prices.price(product, {
|
|
23
|
-
countryCode,
|
|
24
|
-
quantity,
|
|
25
|
-
});
|
|
26
|
-
if (!productPrice) {
|
|
27
|
-
return pricingAdapter.calculate();
|
|
28
|
-
}
|
|
29
|
-
const fromCurrencyObj = await modules.currencies.findCurrency({
|
|
30
|
-
isoCode: productPrice.currencyCode,
|
|
31
|
-
});
|
|
32
|
-
const targetCurrencyObj = await modules.currencies.findCurrency({
|
|
33
|
-
isoCode: targetCurrency,
|
|
34
|
-
});
|
|
35
|
-
if (!targetCurrencyObj?.isActive || !fromCurrencyObj?.isActive)
|
|
36
|
-
return pricingAdapter.calculate();
|
|
37
|
-
const rateData = await modules.products.prices.rates.getRate(fromCurrencyObj, targetCurrencyObj);
|
|
38
|
-
if (rateData && rateData.rate > 0) {
|
|
39
|
-
const convertedAmount = Math.round(productPrice.amount * rateData.rate);
|
|
40
|
-
pricingAdapter.resultSheet().resetCalculation(params.calculationSheet);
|
|
41
|
-
pricingAdapter.resultSheet().addItem({
|
|
42
|
-
amount: convertedAmount * quantity,
|
|
43
|
-
isTaxable: Boolean(productPrice?.isTaxable),
|
|
44
|
-
isNetPrice: Boolean(productPrice?.isNetPrice),
|
|
45
|
-
meta: { adapter: ProductPriceRateConversion.key, rate: rateData.rate },
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
|
-
return pricingAdapter.calculate();
|
|
49
|
-
},
|
|
50
|
-
};
|
|
51
|
-
},
|
|
52
|
-
};
|
|
53
|
-
ProductPricingDirector.registerAdapter(ProductPriceRateConversion);
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { type IProductPricingAdapter } from '@unchainedshop/core';
|
|
2
|
-
interface PriceRoundSettings {
|
|
3
|
-
defaultPrecision: number;
|
|
4
|
-
roundTo: (value: number, precision: number, currencyCode: string) => number;
|
|
5
|
-
}
|
|
6
|
-
export declare const ProductRound: IProductPricingAdapter & {
|
|
7
|
-
configure: (params: PriceRoundSettings) => void;
|
|
8
|
-
settings: PriceRoundSettings;
|
|
9
|
-
};
|
|
10
|
-
export {};
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import { ProductPricingAdapter, ProductPricingDirector, } from '@unchainedshop/core';
|
|
2
|
-
export const ProductRound = {
|
|
3
|
-
...ProductPricingAdapter,
|
|
4
|
-
key: 'shop.unchained.pricing.product-round',
|
|
5
|
-
version: '1.0.0',
|
|
6
|
-
label: 'Round product price',
|
|
7
|
-
orderIndex: 90,
|
|
8
|
-
isActivatedFor: () => {
|
|
9
|
-
return true;
|
|
10
|
-
},
|
|
11
|
-
settings: {
|
|
12
|
-
defaultPrecision: 5,
|
|
13
|
-
roundTo: (value, precision) => Math.round(value / precision) * precision,
|
|
14
|
-
},
|
|
15
|
-
configure({ defaultPrecision, roundTo }) {
|
|
16
|
-
if (defaultPrecision)
|
|
17
|
-
this.settings.defaultPrecision = defaultPrecision;
|
|
18
|
-
if (roundTo)
|
|
19
|
-
this.settings.roundTo = roundTo;
|
|
20
|
-
},
|
|
21
|
-
actions: (params) => {
|
|
22
|
-
const pricingAdapter = ProductPricingAdapter.actions(params);
|
|
23
|
-
return {
|
|
24
|
-
...pricingAdapter,
|
|
25
|
-
calculate: async () => {
|
|
26
|
-
const { currencyCode } = params.context;
|
|
27
|
-
const { defaultPrecision, roundTo } = ProductRound.settings;
|
|
28
|
-
const { calculation = [] } = params.calculationSheet;
|
|
29
|
-
if (calculation?.length) {
|
|
30
|
-
pricingAdapter.resultSheet().resetCalculation(params.calculationSheet);
|
|
31
|
-
calculation.forEach((item) => {
|
|
32
|
-
const newAmount = roundTo(item.amount, defaultPrecision, currencyCode);
|
|
33
|
-
pricingAdapter.resultSheet().calculation.push({
|
|
34
|
-
...item,
|
|
35
|
-
amount: newAmount,
|
|
36
|
-
});
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
return pricingAdapter.calculate();
|
|
40
|
-
},
|
|
41
|
-
};
|
|
42
|
-
},
|
|
43
|
-
};
|
|
44
|
-
ProductPricingDirector.registerAdapter(ProductRound);
|
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
import { ProductPricingDirector, ProductPricingAdapter, ProductPricingRowCategory, } from '@unchainedshop/core';
|
|
2
|
-
import { resolveTaxCategoryFromDeliveryProvider, resolveTaxCategoryFromProduct, SwissTaxCategories, } from "./tax/ch.js";
|
|
3
|
-
import isDeliveryAddressInCountry from "./utils/isDeliveryAddressInCountry.js";
|
|
4
|
-
export const ProductSwissTax = {
|
|
5
|
-
...ProductPricingAdapter,
|
|
6
|
-
key: 'shop.unchained.pricing.product-swiss-tax',
|
|
7
|
-
version: '1.0.0',
|
|
8
|
-
label: 'Apply Swiss Tax on Product',
|
|
9
|
-
orderIndex: 80,
|
|
10
|
-
isActivatedFor: () => {
|
|
11
|
-
return true;
|
|
12
|
-
},
|
|
13
|
-
actions: (params) => {
|
|
14
|
-
const pricingAdapter = ProductPricingAdapter.actions(params);
|
|
15
|
-
const { context } = params;
|
|
16
|
-
return {
|
|
17
|
-
...pricingAdapter,
|
|
18
|
-
calculate: async () => {
|
|
19
|
-
const orderDelivery = context.order?.deliveryId
|
|
20
|
-
? await context.modules.orders.deliveries.findDelivery({
|
|
21
|
-
orderDeliveryId: context.order?.deliveryId,
|
|
22
|
-
})
|
|
23
|
-
: null;
|
|
24
|
-
if (!isDeliveryAddressInCountry({
|
|
25
|
-
...context,
|
|
26
|
-
orderDelivery,
|
|
27
|
-
}, ['CH', 'LI'])) {
|
|
28
|
-
return pricingAdapter.calculate();
|
|
29
|
-
}
|
|
30
|
-
let taxCategory = resolveTaxCategoryFromProduct(context.product);
|
|
31
|
-
if (!taxCategory) {
|
|
32
|
-
const provider = orderDelivery?.deliveryProviderId
|
|
33
|
-
? await context.modules.delivery.findProvider({
|
|
34
|
-
deliveryProviderId: orderDelivery?.deliveryProviderId,
|
|
35
|
-
})
|
|
36
|
-
: null;
|
|
37
|
-
if (provider)
|
|
38
|
-
taxCategory = resolveTaxCategoryFromDeliveryProvider(provider);
|
|
39
|
-
}
|
|
40
|
-
if (!taxCategory)
|
|
41
|
-
taxCategory = SwissTaxCategories.DEFAULT;
|
|
42
|
-
const taxRate = taxCategory.rate(context.order?.ordered);
|
|
43
|
-
ProductPricingAdapter.log(`ProductSwissTax -> Tax Multiplicator: ${taxRate}`);
|
|
44
|
-
params.calculationSheet.filterBy({ isTaxable: true }).forEach(({ isNetPrice, ...row }) => {
|
|
45
|
-
if (!isNetPrice) {
|
|
46
|
-
const taxAmount = row.amount - row.amount / (1 + taxRate);
|
|
47
|
-
pricingAdapter.resultSheet().calculation.push({
|
|
48
|
-
...row,
|
|
49
|
-
amount: -taxAmount,
|
|
50
|
-
isTaxable: false,
|
|
51
|
-
isNetPrice: false,
|
|
52
|
-
meta: { adapter: ProductSwissTax.key },
|
|
53
|
-
});
|
|
54
|
-
pricingAdapter.resultSheet().addTax({
|
|
55
|
-
amount: taxAmount,
|
|
56
|
-
rate: taxRate,
|
|
57
|
-
baseCategory: ProductPricingRowCategory.Item,
|
|
58
|
-
meta: { adapter: ProductSwissTax.key },
|
|
59
|
-
});
|
|
60
|
-
}
|
|
61
|
-
else {
|
|
62
|
-
const taxAmount = row.amount * taxRate;
|
|
63
|
-
pricingAdapter.resultSheet().addTax({
|
|
64
|
-
amount: taxAmount,
|
|
65
|
-
rate: taxRate,
|
|
66
|
-
baseCategory: ProductPricingRowCategory.Item,
|
|
67
|
-
meta: { adapter: ProductSwissTax.key },
|
|
68
|
-
});
|
|
69
|
-
}
|
|
70
|
-
});
|
|
71
|
-
return pricingAdapter.calculate();
|
|
72
|
-
},
|
|
73
|
-
};
|
|
74
|
-
},
|
|
75
|
-
};
|
|
76
|
-
ProductPricingDirector.registerAdapter(ProductSwissTax);
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/lib/quotations/manual.js
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { QuotationDirector, QuotationAdapter } from '@unchainedshop/core';
|
|
2
|
-
const ManualOffering = {
|
|
3
|
-
...QuotationAdapter,
|
|
4
|
-
key: 'shop.unchained.quotations.manual',
|
|
5
|
-
version: '1.0.0',
|
|
6
|
-
label: 'Manual Offerings',
|
|
7
|
-
orderIndex: 0,
|
|
8
|
-
isActivatedFor: () => true,
|
|
9
|
-
actions: (params) => {
|
|
10
|
-
return {
|
|
11
|
-
...QuotationAdapter.actions(params),
|
|
12
|
-
quote: async () => {
|
|
13
|
-
return {
|
|
14
|
-
expires: new Date(new Date().getTime() + 3600 * 1000),
|
|
15
|
-
};
|
|
16
|
-
},
|
|
17
|
-
};
|
|
18
|
-
},
|
|
19
|
-
};
|
|
20
|
-
QuotationDirector.registerAdapter(ManualOffering);
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
import { WarehousingError, WarehousingDirector, WarehousingAdapter, } from '@unchainedshop/core';
|
|
2
|
-
import { WarehousingProviderType } from '@unchainedshop/core-warehousing';
|
|
3
|
-
import { ProductContractStandard, ProductType } from '@unchainedshop/core-products';
|
|
4
|
-
import { systemLocale } from '@unchainedshop/utils';
|
|
5
|
-
import { generateDbObjectId } from '@unchainedshop/mongodb';
|
|
6
|
-
import { getFileAdapter } from '@unchainedshop/core-files';
|
|
7
|
-
import { createLogger } from '@unchainedshop/logger';
|
|
8
|
-
const logger = createLogger('unchained:eth-minter');
|
|
9
|
-
const ETHMinter = {
|
|
10
|
-
...WarehousingAdapter,
|
|
11
|
-
key: 'shop.unchained.warehousing.infinite-minter',
|
|
12
|
-
version: '1.0',
|
|
13
|
-
label: 'Infinite Minter',
|
|
14
|
-
orderIndex: 0,
|
|
15
|
-
initialConfiguration: [{ key: 'chainId', value: '0' }],
|
|
16
|
-
typeSupported: (type) => {
|
|
17
|
-
return type === WarehousingProviderType.VIRTUAL;
|
|
18
|
-
},
|
|
19
|
-
actions: (configuration, context) => {
|
|
20
|
-
const { MINTER_TOKEN_OFFSET = '0', ROOT_URL = 'http://localhost:4010' } = process.env;
|
|
21
|
-
const { product, orderPosition, token, modules, locale } = context;
|
|
22
|
-
const { contractAddress, contractStandard, tokenId, supply, ercMetadataProperties } = product?.tokenization || {};
|
|
23
|
-
const getTokensCreated = async () => {
|
|
24
|
-
const existingTokens = await modules.warehousing.findTokens(contractStandard === ProductContractStandard.ERC721
|
|
25
|
-
? { contractAddress: contractStandard }
|
|
26
|
-
: {
|
|
27
|
-
contractAddress: contractStandard,
|
|
28
|
-
tokenSerialNumber: tokenId,
|
|
29
|
-
});
|
|
30
|
-
const tokensCreated = existingTokens.reduce((acc, curToken) => {
|
|
31
|
-
return acc + curToken.quantity;
|
|
32
|
-
}, 0);
|
|
33
|
-
return tokensCreated;
|
|
34
|
-
};
|
|
35
|
-
return {
|
|
36
|
-
...WarehousingAdapter.actions(configuration, context),
|
|
37
|
-
isActive() {
|
|
38
|
-
return product?.type === ProductType.TOKENIZED_PRODUCT;
|
|
39
|
-
},
|
|
40
|
-
configurationError() {
|
|
41
|
-
if (contractStandard === 'ERC1155' && !tokenId) {
|
|
42
|
-
logger.error(`Token ID is required for ERC1155 contract standard (productId: ${product._id})`);
|
|
43
|
-
return WarehousingError.INCOMPLETE_CONFIGURATION;
|
|
44
|
-
}
|
|
45
|
-
return null;
|
|
46
|
-
},
|
|
47
|
-
stock: async () => {
|
|
48
|
-
const tokensCreated = await getTokensCreated();
|
|
49
|
-
return supply ? supply - tokensCreated : 0;
|
|
50
|
-
},
|
|
51
|
-
tokenize: async () => {
|
|
52
|
-
const chainId = configuration.find(({ key }) => key === 'chainId')?.value || undefined;
|
|
53
|
-
const meta = { contractStandard };
|
|
54
|
-
const tokensCreated = await getTokensCreated();
|
|
55
|
-
if (!orderPosition) {
|
|
56
|
-
throw new Error('Order position not found in context');
|
|
57
|
-
}
|
|
58
|
-
if (contractStandard === 'ERC721') {
|
|
59
|
-
const items = new Array(orderPosition.quantity).fill(null).map((_, i) => ({
|
|
60
|
-
_id: generateDbObjectId(),
|
|
61
|
-
tokenSerialNumber: Number(parseInt(MINTER_TOKEN_OFFSET, 10) + tokensCreated + (i + 1)).toString(),
|
|
62
|
-
contractAddress,
|
|
63
|
-
quantity: 1,
|
|
64
|
-
chainId,
|
|
65
|
-
meta,
|
|
66
|
-
}));
|
|
67
|
-
return items;
|
|
68
|
-
}
|
|
69
|
-
return [
|
|
70
|
-
{
|
|
71
|
-
_id: generateDbObjectId(),
|
|
72
|
-
tokenSerialNumber: tokenId,
|
|
73
|
-
contractAddress,
|
|
74
|
-
quantity: orderPosition.quantity,
|
|
75
|
-
chainId,
|
|
76
|
-
meta,
|
|
77
|
-
},
|
|
78
|
-
];
|
|
79
|
-
},
|
|
80
|
-
tokenMetadata: async (tokenSerialNumber) => {
|
|
81
|
-
if (!product) {
|
|
82
|
-
throw new Error('Product not found in context');
|
|
83
|
-
}
|
|
84
|
-
const allLanguages = await modules.languages.findLanguages({
|
|
85
|
-
includeInactive: false,
|
|
86
|
-
});
|
|
87
|
-
const [firstMedia] = await modules.products.media.findProductMedias({
|
|
88
|
-
productId: product._id,
|
|
89
|
-
limit: 1,
|
|
90
|
-
});
|
|
91
|
-
const file = firstMedia && (await modules.files.findFile({ fileId: firstMedia.mediaId }));
|
|
92
|
-
const fileAdapter = file && getFileAdapter();
|
|
93
|
-
const signedUrl = await fileAdapter?.createDownloadURL(file);
|
|
94
|
-
const url = signedUrl && (await modules.files.normalizeUrl(signedUrl, {}));
|
|
95
|
-
const text = await modules.products.texts.findLocalizedText({
|
|
96
|
-
productId: product._id,
|
|
97
|
-
locale: locale || systemLocale,
|
|
98
|
-
});
|
|
99
|
-
const name = `${text.title} #${tokenSerialNumber}`;
|
|
100
|
-
const isDefaultLanguageActive = locale ? locale.language === systemLocale.language : true;
|
|
101
|
-
const localization = isDefaultLanguageActive
|
|
102
|
-
? {
|
|
103
|
-
uri: `${ROOT_URL}/erc-metadata/${product._id}/${locale}/${tokenId}.json`,
|
|
104
|
-
default: systemLocale.language,
|
|
105
|
-
locales: allLanguages.map((lang) => lang.isoCode),
|
|
106
|
-
}
|
|
107
|
-
: undefined;
|
|
108
|
-
return {
|
|
109
|
-
name,
|
|
110
|
-
description: text.description,
|
|
111
|
-
image: url,
|
|
112
|
-
properties: ercMetadataProperties,
|
|
113
|
-
localization,
|
|
114
|
-
...(token?.meta || {}),
|
|
115
|
-
};
|
|
116
|
-
},
|
|
117
|
-
};
|
|
118
|
-
},
|
|
119
|
-
};
|
|
120
|
-
WarehousingDirector.registerAdapter(ETHMinter);
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/lib/warehousing/store.js
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { WarehousingDirector, WarehousingAdapter } from '@unchainedshop/core';
|
|
2
|
-
import { WarehousingProviderType } from '@unchainedshop/core-warehousing';
|
|
3
|
-
const Store = {
|
|
4
|
-
...WarehousingAdapter,
|
|
5
|
-
key: 'shop.unchained.warehousing.store',
|
|
6
|
-
label: 'Store',
|
|
7
|
-
version: '1.0.0',
|
|
8
|
-
orderIndex: 0,
|
|
9
|
-
initialConfiguration: [{ key: 'name', value: 'Flagship Store' }],
|
|
10
|
-
typeSupported: (type) => {
|
|
11
|
-
return type === WarehousingProviderType.PHYSICAL;
|
|
12
|
-
},
|
|
13
|
-
actions: (configuration, context) => {
|
|
14
|
-
return {
|
|
15
|
-
...WarehousingAdapter.actions(configuration, context),
|
|
16
|
-
isActive() {
|
|
17
|
-
return true;
|
|
18
|
-
},
|
|
19
|
-
configurationError() {
|
|
20
|
-
return null;
|
|
21
|
-
},
|
|
22
|
-
stock: async () => {
|
|
23
|
-
return 99999;
|
|
24
|
-
},
|
|
25
|
-
productionTime: async () => {
|
|
26
|
-
return 0;
|
|
27
|
-
},
|
|
28
|
-
commissioningTime: async () => {
|
|
29
|
-
return 0;
|
|
30
|
-
},
|
|
31
|
-
};
|
|
32
|
-
},
|
|
33
|
-
};
|
|
34
|
-
WarehousingDirector.registerAdapter(Store);
|