@unchainedshop/plugins 4.0.0-rc.16 → 4.0.0-rc.18
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/accounts/google-oauth.d.ts +4 -0
- package/lib/accounts/google-oauth.d.ts.map +1 -0
- package/lib/accounts/google-oauth.js +145 -0
- package/lib/accounts/google-oauth.js.map +1 -0
- package/lib/accounts/linkedin-oauth.d.ts +4 -0
- package/lib/accounts/linkedin-oauth.d.ts.map +1 -0
- package/lib/accounts/linkedin-oauth.js +82 -0
- package/lib/accounts/linkedin-oauth.js.map +1 -0
- package/lib/delivery/send-message.js.map +1 -1
- package/lib/enrollments/licensed.js +15 -2
- package/lib/enrollments/licensed.js.map +1 -1
- package/lib/files/gridfs/adapter.js +1 -1
- package/lib/files/gridfs/adapter.js.map +1 -1
- package/lib/files/gridfs/gridfs-adapter.d.ts +3 -0
- package/lib/files/gridfs/gridfs-adapter.d.ts.map +1 -0
- package/lib/files/gridfs/gridfs-adapter.js +97 -0
- package/lib/files/gridfs/gridfs-adapter.js.map +1 -0
- package/lib/files/gridfs/gridfs-webhook.d.ts +11 -0
- package/lib/files/gridfs/gridfs-webhook.d.ts.map +1 -0
- package/lib/files/gridfs/gridfs-webhook.js +84 -0
- package/lib/files/gridfs/gridfs-webhook.js.map +1 -0
- package/lib/files/gridfs/handler-express.d.ts.map +1 -1
- package/lib/files/gridfs/handler-express.js +6 -2
- package/lib/files/gridfs/handler-express.js.map +1 -1
- package/lib/files/gridfs/handler-fastify.d.ts.map +1 -1
- package/lib/files/gridfs/handler-fastify.js +11 -2
- package/lib/files/gridfs/handler-fastify.js.map +1 -1
- package/lib/files/gridfs/module.d.ts +2 -2
- package/lib/files/minio/handler-express.js +1 -1
- package/lib/files/minio/handler-express.js.map +1 -1
- package/lib/files/minio/handler-fastify.js +1 -1
- package/lib/files/minio/handler-fastify.js.map +1 -1
- package/lib/files/minio/index.d.ts +1 -1
- package/lib/files/minio/index.d.ts.map +1 -1
- package/lib/files/minio/index.js +3 -3
- package/lib/files/minio/index.js.map +1 -1
- package/lib/files/minio/minio-adapter.d.ts +6 -0
- package/lib/files/minio/minio-adapter.d.ts.map +1 -0
- package/lib/files/minio/minio-adapter.js +181 -0
- package/lib/files/minio/minio-adapter.js.map +1 -0
- package/lib/files/minio/minio-webhook.d.ts +2 -0
- package/lib/files/minio/minio-webhook.d.ts.map +1 -0
- package/lib/files/minio/minio-webhook.js +33 -0
- package/lib/files/minio/minio-webhook.js.map +1 -0
- package/lib/filters/local-search.js +1 -1
- package/lib/filters/local-search.js.map +1 -1
- package/lib/payment/apple-iap/adapter.js +12 -10
- 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/handler-express.d.ts.map +1 -1
- package/lib/payment/apple-iap/handler-express.js +11 -4
- package/lib/payment/apple-iap/handler-express.js.map +1 -1
- package/lib/payment/apple-iap/handler-fastify.d.ts.map +1 -1
- package/lib/payment/apple-iap/handler-fastify.js +13 -6
- package/lib/payment/apple-iap/handler-fastify.js.map +1 -1
- package/lib/payment/apple-iap/module/configureAppleTransactionsModule.d.ts +9 -0
- package/lib/payment/apple-iap/module/configureAppleTransactionsModule.d.ts.map +1 -0
- package/lib/payment/apple-iap/module/configureAppleTransactionsModule.js +17 -0
- package/lib/payment/apple-iap/module/configureAppleTransactionsModule.js.map +1 -0
- package/lib/payment/apple-iap/module.d.ts +4 -4
- package/lib/payment/apple-iap/module.d.ts.map +1 -1
- package/lib/payment/apple-iap/module.js +4 -2
- package/lib/payment/apple-iap/module.js.map +1 -1
- package/lib/payment/braintree.js +3 -1
- 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/derive-btc-address.d.ts.map +1 -1
- package/lib/payment/cryptopay/derive-btc-address.js +2 -3
- package/lib/payment/cryptopay/derive-btc-address.js.map +1 -1
- package/lib/payment/cryptopay/derive-eth-address.d.ts.map +1 -1
- package/lib/payment/cryptopay/derive-eth-address.js +2 -0
- package/lib/payment/cryptopay/derive-eth-address.js.map +1 -1
- package/lib/payment/cryptopay/handle-webhook.js +2 -2
- package/lib/payment/cryptopay/handle-webhook.js.map +1 -1
- package/lib/payment/cryptopay/handler-express.js +1 -1
- package/lib/payment/cryptopay/handler-express.js.map +1 -1
- package/lib/payment/cryptopay/handler-fastify.js +1 -1
- package/lib/payment/cryptopay/handler-fastify.js.map +1 -1
- package/lib/payment/cryptopay/middleware.d.ts +2 -0
- package/lib/payment/cryptopay/middleware.d.ts.map +1 -0
- package/lib/payment/cryptopay/middleware.js +75 -0
- package/lib/payment/cryptopay/middleware.js.map +1 -0
- package/lib/payment/cryptopay/module/configureCryptopayModule.d.ts +25 -0
- package/lib/payment/cryptopay/module/configureCryptopayModule.d.ts.map +1 -0
- package/lib/payment/cryptopay/module/configureCryptopayModule.js +75 -0
- package/lib/payment/cryptopay/module/configureCryptopayModule.js.map +1 -0
- package/lib/payment/cryptopay/module.d.ts +2 -2
- package/lib/payment/cryptopay/module.d.ts.map +1 -1
- package/lib/payment/cryptopay/module.js +4 -4
- package/lib/payment/cryptopay/module.js.map +1 -1
- package/lib/payment/cryptopay/plugin.d.ts.map +1 -1
- package/lib/payment/cryptopay/plugin.js +18 -4
- package/lib/payment/cryptopay/plugin.js.map +1 -1
- package/lib/payment/datatrans-v2/handler-express.d.ts.map +1 -1
- package/lib/payment/datatrans-v2/handler-express.js +8 -1
- package/lib/payment/datatrans-v2/handler-express.js.map +1 -1
- package/lib/payment/datatrans-v2/handler-fastify.d.ts.map +1 -1
- package/lib/payment/datatrans-v2/handler-fastify.js +7 -1
- package/lib/payment/datatrans-v2/handler-fastify.js.map +1 -1
- package/lib/payment/datatrans-v2/index.js +63 -37
- package/lib/payment/datatrans-v2/index.js.map +1 -1
- package/lib/payment/datatrans-v2/middleware.d.ts +2 -0
- package/lib/payment/datatrans-v2/middleware.d.ts.map +1 -0
- package/lib/payment/datatrans-v2/middleware.js +68 -0
- package/lib/payment/datatrans-v2/middleware.js.map +1 -0
- package/lib/payment/datatrans-v2/parseRegistrationData.d.ts +1 -1
- package/lib/payment/datatrans-v2/parseRegistrationData.d.ts.map +1 -1
- package/lib/payment/paypal-checkout.js +4 -2
- package/lib/payment/paypal-checkout.js.map +1 -1
- package/lib/payment/payrexx/api/index.d.ts +1 -1
- package/lib/payment/payrexx/api/index.d.ts.map +1 -1
- package/lib/payment/payrexx/api/makeFetcher.d.ts +1 -1
- package/lib/payment/payrexx/api/makeFetcher.d.ts.map +1 -1
- package/lib/payment/payrexx/api/makeFetcher.js +1 -1
- package/lib/payment/payrexx/api/makeFetcher.js.map +1 -1
- package/lib/payment/payrexx/handler-express.d.ts.map +1 -1
- package/lib/payment/payrexx/handler-express.js +3 -1
- package/lib/payment/payrexx/handler-express.js.map +1 -1
- package/lib/payment/payrexx/handler-fastify.d.ts.map +1 -1
- package/lib/payment/payrexx/handler-fastify.js +3 -1
- package/lib/payment/payrexx/handler-fastify.js.map +1 -1
- package/lib/payment/payrexx/index.js +21 -15
- package/lib/payment/payrexx/index.js.map +1 -1
- package/lib/payment/payrexx/middleware.d.ts +2 -0
- package/lib/payment/payrexx/middleware.d.ts.map +1 -0
- package/lib/payment/payrexx/middleware.js +86 -0
- package/lib/payment/payrexx/middleware.js.map +1 -0
- package/lib/payment/postfinance-checkout/handler-express.d.ts.map +1 -1
- package/lib/payment/postfinance-checkout/handler-express.js +4 -2
- package/lib/payment/postfinance-checkout/handler-express.js.map +1 -1
- package/lib/payment/postfinance-checkout/handler-fastify.d.ts.map +1 -1
- package/lib/payment/postfinance-checkout/handler-fastify.js +4 -2
- package/lib/payment/postfinance-checkout/handler-fastify.js.map +1 -1
- package/lib/payment/postfinance-checkout/index.d.ts.map +1 -1
- package/lib/payment/postfinance-checkout/index.js +20 -7
- package/lib/payment/postfinance-checkout/index.js.map +1 -1
- package/lib/payment/postfinance-checkout/middleware.d.ts +2 -0
- package/lib/payment/postfinance-checkout/middleware.d.ts.map +1 -0
- package/lib/payment/postfinance-checkout/middleware.js +38 -0
- package/lib/payment/postfinance-checkout/middleware.js.map +1 -0
- package/lib/payment/saferpay/adapter.d.ts.map +1 -1
- package/lib/payment/saferpay/adapter.js +9 -0
- package/lib/payment/saferpay/adapter.js.map +1 -1
- package/lib/payment/saferpay/handler-express.d.ts.map +1 -1
- package/lib/payment/saferpay/handler-express.js +3 -1
- package/lib/payment/saferpay/handler-express.js.map +1 -1
- package/lib/payment/saferpay/handler-fastify.d.ts.map +1 -1
- package/lib/payment/saferpay/handler-fastify.js +3 -1
- package/lib/payment/saferpay/handler-fastify.js.map +1 -1
- package/lib/payment/saferpay/middleware.d.ts +2 -0
- package/lib/payment/saferpay/middleware.d.ts.map +1 -0
- package/lib/payment/saferpay/middleware.js +57 -0
- package/lib/payment/saferpay/middleware.js.map +1 -0
- package/lib/payment/saferpay/module/configureSaferpayTransactionsModule.d.ts +10 -0
- package/lib/payment/saferpay/module/configureSaferpayTransactionsModule.d.ts.map +1 -0
- package/lib/payment/saferpay/module/configureSaferpayTransactionsModule.js +24 -0
- package/lib/payment/saferpay/module/configureSaferpayTransactionsModule.js.map +1 -0
- package/lib/payment/saferpay/module.d.ts +2 -2
- package/lib/payment/stripe/handler-express.d.ts.map +1 -1
- package/lib/payment/stripe/handler-express.js +9 -1
- package/lib/payment/stripe/handler-express.js.map +1 -1
- package/lib/payment/stripe/handler-fastify.d.ts.map +1 -1
- package/lib/payment/stripe/handler-fastify.js +9 -1
- package/lib/payment/stripe/handler-fastify.js.map +1 -1
- package/lib/payment/stripe/index.js +19 -13
- package/lib/payment/stripe/index.js.map +1 -1
- package/lib/payment/stripe/middleware.d.ts +6 -0
- package/lib/payment/stripe/middleware.d.ts.map +1 -0
- package/lib/payment/stripe/middleware.js +114 -0
- package/lib/payment/stripe/middleware.js.map +1 -0
- package/lib/payment/stripe/stripe.d.ts +2 -2
- package/lib/payment/stripe/stripe.d.ts.map +1 -1
- package/lib/payment/stripe/stripe.js +14 -11
- package/lib/payment/stripe/stripe.js.map +1 -1
- package/lib/plugins-index.d.ts +48 -0
- package/lib/plugins-index.d.ts.map +1 -0
- package/lib/plugins-index.js +107 -0
- package/lib/plugins-index.js.map +1 -0
- package/lib/presets/all.d.ts +5 -5
- package/lib/presets/all.d.ts.map +1 -1
- package/lib/pricing/delivery-swiss-tax.d.ts.map +1 -1
- package/lib/pricing/delivery-swiss-tax.js +13 -11
- package/lib/pricing/delivery-swiss-tax.js.map +1 -1
- package/lib/pricing/order-discount.d.ts.map +1 -1
- package/lib/pricing/order-discount.js +5 -3
- package/lib/pricing/order-discount.js.map +1 -1
- package/lib/pricing/order-round.d.ts.map +1 -1
- package/lib/pricing/order-round.js +4 -3
- package/lib/pricing/order-round.js.map +1 -1
- package/lib/pricing/product-catalog-price.js +4 -4
- package/lib/pricing/product-catalog-price.js.map +1 -1
- package/lib/pricing/product-price-rateconversion.js +3 -3
- package/lib/pricing/product-price-rateconversion.js.map +1 -1
- package/lib/pricing/product-swiss-tax.d.ts +1 -4
- package/lib/pricing/product-swiss-tax.d.ts.map +1 -1
- package/lib/pricing/product-swiss-tax.js +9 -15
- package/lib/pricing/product-swiss-tax.js.map +1 -1
- package/lib/pricing/tax/ch.d.ts +6 -0
- package/lib/pricing/tax/ch.d.ts.map +1 -1
- package/lib/pricing/tax/ch.js +10 -0
- package/lib/pricing/tax/ch.js.map +1 -1
- package/lib/warehousing/eth-minter.js +23 -11
- package/lib/warehousing/eth-minter.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 +79 -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 +5 -4
- package/lib/worker/bulk-import.js.map +1 -1
- package/lib/worker/enrollment-order-generator.d.ts.map +1 -1
- package/lib/worker/enrollment-order-generator.js +7 -49
- package/lib/worker/enrollment-order-generator.js.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.map +1 -1
- package/lib/worker/export-token.js +0 -1
- package/lib/worker/export-token.js.map +1 -1
- package/lib/worker/message.d.ts +1 -1
- package/lib/worker/message.d.ts.map +1 -1
- package/lib/worker/message.js +4 -2
- package/lib/worker/message.js.map +1 -1
- package/lib/worker/sms.d.ts +2 -0
- package/lib/worker/sms.d.ts.map +1 -0
- package/lib/worker/sms.js +73 -0
- package/lib/worker/sms.js.map +1 -0
- package/lib/worker/twilio.js +4 -0
- package/lib/worker/twilio.js.map +1 -1
- package/package.json +15 -15
- package/src/delivery/send-message.ts +1 -1
- package/src/enrollments/licensed.ts +15 -2
- package/src/files/gridfs/adapter.ts +1 -1
- package/src/files/gridfs/handler-express.ts +8 -2
- package/src/files/gridfs/handler-fastify.ts +13 -2
- package/src/files/minio/handler-express.ts +1 -1
- package/src/files/minio/handler-fastify.ts +1 -1
- package/src/files/minio/index.ts +12 -12
- package/src/filters/local-search.ts +1 -1
- package/src/payment/apple-iap/adapter.ts +12 -14
- package/src/payment/apple-iap/db/AppleTransactionsCollection.ts +1 -1
- package/src/payment/apple-iap/handler-express.ts +14 -5
- package/src/payment/apple-iap/handler-fastify.ts +17 -7
- package/src/payment/apple-iap/module.ts +9 -4
- package/src/payment/braintree.ts +4 -1
- package/src/payment/cryptopay/db/CryptopayTransactions.ts +1 -1
- package/src/payment/cryptopay/derive-btc-address.ts +1 -3
- package/src/payment/cryptopay/derive-eth-address.ts +2 -0
- package/src/payment/cryptopay/handle-webhook.ts +6 -6
- package/src/payment/cryptopay/handler-express.ts +1 -1
- package/src/payment/cryptopay/handler-fastify.ts +1 -1
- package/src/payment/cryptopay/module.ts +8 -5
- package/src/payment/cryptopay/plugin.ts +21 -4
- package/src/payment/datatrans-v2/handler-express.ts +12 -2
- package/src/payment/datatrans-v2/handler-fastify.ts +11 -2
- package/src/payment/datatrans-v2/index.ts +82 -50
- package/src/payment/paypal-checkout.ts +4 -2
- package/src/payment/payrexx/api/index.ts +1 -1
- package/src/payment/payrexx/api/makeFetcher.ts +2 -2
- package/src/payment/payrexx/handler-express.ts +3 -1
- package/src/payment/payrexx/handler-fastify.ts +5 -4
- package/src/payment/payrexx/index.ts +26 -16
- package/src/payment/postfinance-checkout/handler-express.ts +5 -2
- package/src/payment/postfinance-checkout/handler-fastify.ts +5 -2
- package/src/payment/postfinance-checkout/index.ts +20 -8
- package/src/payment/saferpay/adapter.ts +14 -2
- package/src/payment/saferpay/handler-express.ts +4 -1
- package/src/payment/saferpay/handler-fastify.ts +4 -1
- package/src/payment/stripe/handler-express.ts +9 -1
- package/src/payment/stripe/handler-fastify.ts +9 -1
- package/src/payment/stripe/index.ts +17 -13
- package/src/payment/stripe/stripe.ts +17 -12
- package/src/pricing/delivery-swiss-tax.ts +11 -19
- package/src/pricing/order-discount.ts +6 -4
- package/src/pricing/order-round.ts +5 -4
- package/src/pricing/product-catalog-price.ts +4 -4
- package/src/pricing/product-price-rateconversion.ts +3 -3
- package/src/pricing/product-swiss-tax.test.ts +1 -86
- package/src/pricing/product-swiss-tax.ts +11 -24
- package/src/pricing/tax/ch.test.ts +86 -1
- package/src/pricing/tax/ch.ts +23 -0
- package/src/warehousing/eth-minter.ts +30 -11
- package/src/worker/budgetsms.ts +1 -1
- package/src/worker/bulk-import.ts +6 -7
- package/src/worker/enrollment-order-generator.ts +14 -72
- package/src/worker/error-notifications.ts +2 -2
- package/src/worker/export-token.ts +0 -1
- package/src/worker/message.ts +5 -3
- package/src/worker/twilio.ts +10 -3
package/src/pricing/tax/ch.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { Order, OrderDelivery } from '@unchainedshop/core-orders';
|
|
2
|
+
|
|
1
3
|
const startOf2024 = new Date('2024-01-01T00:00:00.000+0100');
|
|
2
4
|
|
|
3
5
|
// https://www.estv.admin.ch/estv/en/home/value-added-tax/vat-rates-switzerland.html
|
|
@@ -37,3 +39,24 @@ export const SwissTaxCategories: Record<
|
|
|
37
39
|
},
|
|
38
40
|
},
|
|
39
41
|
};
|
|
42
|
+
|
|
43
|
+
export const isDeliveryAddressInSwitzerland = ({
|
|
44
|
+
orderDelivery,
|
|
45
|
+
order,
|
|
46
|
+
countryCode: forceCountryCode = null,
|
|
47
|
+
}: {
|
|
48
|
+
orderDelivery?: OrderDelivery | null;
|
|
49
|
+
order?: Order | null;
|
|
50
|
+
countryCode?: string | null;
|
|
51
|
+
}) => {
|
|
52
|
+
let countryCode = forceCountryCode?.toUpperCase().trim() || order?.countryCode;
|
|
53
|
+
|
|
54
|
+
if (orderDelivery || order) {
|
|
55
|
+
const address = orderDelivery?.context?.address || order?.billingAddress;
|
|
56
|
+
if (address?.countryCode > '') {
|
|
57
|
+
countryCode = address.countryCode?.toUpperCase().trim();
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
return countryCode === 'CH' || countryCode === 'LI';
|
|
62
|
+
};
|
|
@@ -11,9 +11,12 @@ import { ProductContractStandard, ProductTypes } from '@unchainedshop/core-produ
|
|
|
11
11
|
import { systemLocale } from '@unchainedshop/utils';
|
|
12
12
|
import { generateDbObjectId } from '@unchainedshop/mongodb';
|
|
13
13
|
import { getFileAdapter } from '@unchainedshop/core-files';
|
|
14
|
+
import { createLogger } from '@unchainedshop/logger';
|
|
14
15
|
|
|
15
16
|
const { MINTER_TOKEN_OFFSET = '0', ROOT_URL = 'http://localhost:4010' } = process.env;
|
|
16
17
|
|
|
18
|
+
const logger = createLogger('unchained:eth-minter');
|
|
19
|
+
|
|
17
20
|
const ETHMinter: IWarehousingAdapter = {
|
|
18
21
|
...WarehousingAdapter,
|
|
19
22
|
|
|
@@ -40,7 +43,7 @@ const ETHMinter: IWarehousingAdapter = {
|
|
|
40
43
|
? { contractAddress: contractStandard }
|
|
41
44
|
: {
|
|
42
45
|
contractAddress: contractStandard,
|
|
43
|
-
|
|
46
|
+
tokenSerialNumber: tokenId,
|
|
44
47
|
},
|
|
45
48
|
);
|
|
46
49
|
const tokensCreated = existingTokens.reduce((acc, curToken) => {
|
|
@@ -57,7 +60,13 @@ const ETHMinter: IWarehousingAdapter = {
|
|
|
57
60
|
},
|
|
58
61
|
|
|
59
62
|
configurationError() {
|
|
60
|
-
|
|
63
|
+
if (contractStandard === 'ERC1155' && !tokenId) {
|
|
64
|
+
logger.error(
|
|
65
|
+
`Token ID is required for ERC1155 contract standard (productId: ${product!._id})`,
|
|
66
|
+
);
|
|
67
|
+
return WarehousingError.INCOMPLETE_CONFIGURATION;
|
|
68
|
+
}
|
|
69
|
+
return null;
|
|
61
70
|
},
|
|
62
71
|
|
|
63
72
|
stock: async () => {
|
|
@@ -74,11 +83,17 @@ const ETHMinter: IWarehousingAdapter = {
|
|
|
74
83
|
const meta = { contractStandard };
|
|
75
84
|
const tokensCreated = await getTokensCreated();
|
|
76
85
|
|
|
86
|
+
if (!orderPosition) {
|
|
87
|
+
throw new Error('Order position not found in context');
|
|
88
|
+
}
|
|
89
|
+
|
|
77
90
|
if (contractStandard === 'ERC721') {
|
|
78
|
-
// ERC721 is non-fungible, thus every
|
|
79
|
-
const items = new Array(orderPosition
|
|
91
|
+
// ERC721 is non-fungible, thus every tokenSerialNumber unique!
|
|
92
|
+
const items = new Array(orderPosition.quantity).fill(null).map((_, i) => ({
|
|
80
93
|
_id: generateDbObjectId(),
|
|
81
|
-
|
|
94
|
+
tokenSerialNumber: Number(
|
|
95
|
+
parseInt(MINTER_TOKEN_OFFSET, 10) + tokensCreated + (i + 1),
|
|
96
|
+
).toString(),
|
|
82
97
|
contractAddress,
|
|
83
98
|
quantity: 1,
|
|
84
99
|
chainId,
|
|
@@ -90,20 +105,24 @@ const ETHMinter: IWarehousingAdapter = {
|
|
|
90
105
|
return [
|
|
91
106
|
{
|
|
92
107
|
_id: generateDbObjectId(),
|
|
93
|
-
|
|
108
|
+
tokenSerialNumber: tokenId!,
|
|
94
109
|
contractAddress,
|
|
95
|
-
quantity: orderPosition
|
|
110
|
+
quantity: orderPosition.quantity,
|
|
96
111
|
chainId,
|
|
97
112
|
meta,
|
|
98
113
|
},
|
|
99
114
|
];
|
|
100
115
|
},
|
|
101
116
|
|
|
102
|
-
tokenMetadata: async (
|
|
117
|
+
tokenMetadata: async (tokenSerialNumber) => {
|
|
103
118
|
// Metadata standards supported
|
|
104
119
|
// https://eips.ethereum.org/EIPS/eip-1155 (backward compatible with 721)
|
|
105
120
|
// https://eips.ethereum.org/EIPS/eip-721
|
|
106
121
|
|
|
122
|
+
if (!product) {
|
|
123
|
+
throw new Error('Product not found in context');
|
|
124
|
+
}
|
|
125
|
+
|
|
107
126
|
const allLanguages = await modules.languages.findLanguages({
|
|
108
127
|
includeInactive: false,
|
|
109
128
|
});
|
|
@@ -114,15 +133,15 @@ const ETHMinter: IWarehousingAdapter = {
|
|
|
114
133
|
});
|
|
115
134
|
const file = firstMedia && (await modules.files.findFile({ fileId: firstMedia.mediaId }));
|
|
116
135
|
|
|
117
|
-
const
|
|
118
|
-
const signedUrl = await
|
|
136
|
+
const fileAdapter = file && getFileAdapter();
|
|
137
|
+
const signedUrl = await fileAdapter?.createDownloadURL(file!);
|
|
119
138
|
const url = signedUrl && (await modules.files.normalizeUrl(signedUrl, {}));
|
|
120
139
|
const text = await modules.products.texts.findLocalizedText({
|
|
121
140
|
productId: product._id,
|
|
122
141
|
locale: locale || systemLocale,
|
|
123
142
|
});
|
|
124
143
|
|
|
125
|
-
const name = `${text.title} #${
|
|
144
|
+
const name = `${text.title} #${tokenSerialNumber}`;
|
|
126
145
|
|
|
127
146
|
const isDefaultLanguageActive = locale ? locale.language === systemLocale.language : true;
|
|
128
147
|
const localization = isDefaultLanguageActive
|
package/src/worker/budgetsms.ts
CHANGED
|
@@ -8,7 +8,7 @@ const { BUDGETSMS_USERNAME, BUDGETSMS_USERID, BUDGETSMS_HANDLE } = process.env;
|
|
|
8
8
|
const BudgetSMSWorker: IWorkerAdapter<
|
|
9
9
|
{
|
|
10
10
|
from?: string;
|
|
11
|
-
to
|
|
11
|
+
to: string;
|
|
12
12
|
text?: string;
|
|
13
13
|
test?: boolean; // If true, uses test endpoint (no credit deducted)
|
|
14
14
|
customid?: string;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { WorkerDirector, WorkerAdapter, IWorkerAdapter } from '@unchainedshop/core';
|
|
2
2
|
import { createLogger } from '@unchainedshop/logger';
|
|
3
3
|
|
|
4
|
-
const logger = createLogger('unchained:
|
|
4
|
+
const logger = createLogger('unchained:bulk-import');
|
|
5
5
|
|
|
6
|
-
export const BulkImportWorker: IWorkerAdapter<any, Record<string,
|
|
6
|
+
export const BulkImportWorker: IWorkerAdapter<any, Record<string, any>> = {
|
|
7
7
|
...WorkerAdapter,
|
|
8
8
|
|
|
9
9
|
key: 'shop.unchained.worker-plugin.bulk-import',
|
|
@@ -32,9 +32,7 @@ export const BulkImportWorker: IWorkerAdapter<any, Record<string, unknown>> = {
|
|
|
32
32
|
fileId: rawPayload.payloadId,
|
|
33
33
|
});
|
|
34
34
|
if (!readStream) {
|
|
35
|
-
throw new Error(
|
|
36
|
-
'The current file adapter does not support streams when downloading required for streamed events. Please use a different file adapter.',
|
|
37
|
-
);
|
|
35
|
+
throw new Error('Could not create download stream from uploaded file');
|
|
38
36
|
}
|
|
39
37
|
await unchainedAPI.bulkImporter.pipeEventStream(readStream, bulkImporter, unchainedAPI);
|
|
40
38
|
} else {
|
|
@@ -43,6 +41,7 @@ export const BulkImportWorker: IWorkerAdapter<any, Record<string, unknown>> = {
|
|
|
43
41
|
|
|
44
42
|
await events.reduce(async (currentEventPromise, nextEvent) => {
|
|
45
43
|
await currentEventPromise;
|
|
44
|
+
await bulkImporter.validate(nextEvent);
|
|
46
45
|
return bulkImporter.prepare(nextEvent, unchainedAPI);
|
|
47
46
|
}, Promise.resolve());
|
|
48
47
|
}
|
|
@@ -53,13 +52,13 @@ export const BulkImportWorker: IWorkerAdapter<any, Record<string, unknown>> = {
|
|
|
53
52
|
if (error) {
|
|
54
53
|
return {
|
|
55
54
|
success: false,
|
|
56
|
-
result
|
|
55
|
+
result: result!,
|
|
57
56
|
error,
|
|
58
57
|
};
|
|
59
58
|
}
|
|
60
59
|
return {
|
|
61
60
|
success: true,
|
|
62
|
-
result
|
|
61
|
+
result: result!,
|
|
63
62
|
};
|
|
64
63
|
} catch (err) {
|
|
65
64
|
logger.error(err);
|
|
@@ -1,73 +1,7 @@
|
|
|
1
|
-
import { Enrollment } from '@unchainedshop/core-enrollments';
|
|
2
|
-
import { OrderPosition } from '@unchainedshop/core-orders';
|
|
3
1
|
import { enrollmentsSettings, EnrollmentStatus } from '@unchainedshop/core-enrollments';
|
|
4
|
-
import {
|
|
5
|
-
EnrollmentDirector,
|
|
6
|
-
UnchainedCore,
|
|
7
|
-
WorkerDirector,
|
|
8
|
-
WorkerAdapter,
|
|
9
|
-
IWorkerAdapter,
|
|
10
|
-
} from '@unchainedshop/core';
|
|
2
|
+
import { EnrollmentDirector, WorkerDirector, WorkerAdapter, IWorkerAdapter } from '@unchainedshop/core';
|
|
11
3
|
|
|
12
|
-
const
|
|
13
|
-
enrollment: Enrollment,
|
|
14
|
-
params: {
|
|
15
|
-
orderPositions: OrderPosition[];
|
|
16
|
-
} & Record<string, any>,
|
|
17
|
-
unchainedAPI: Pick<UnchainedCore, 'modules' | 'services'>,
|
|
18
|
-
) => {
|
|
19
|
-
if (!enrollment.payment || !enrollment.delivery) return null;
|
|
20
|
-
|
|
21
|
-
const { modules, services } = unchainedAPI;
|
|
22
|
-
const { orderPositions, ...configuration } = params;
|
|
23
|
-
let order = await modules.orders.create({
|
|
24
|
-
userId: enrollment.userId,
|
|
25
|
-
currencyCode: enrollment.currencyCode,
|
|
26
|
-
countryCode: enrollment.countryCode,
|
|
27
|
-
contact: enrollment.contact,
|
|
28
|
-
billingAddress: enrollment.billingAddress,
|
|
29
|
-
originEnrollmentId: enrollment._id,
|
|
30
|
-
...configuration,
|
|
31
|
-
});
|
|
32
|
-
const orderId = order._id;
|
|
33
|
-
|
|
34
|
-
if (orderPositions) {
|
|
35
|
-
await Promise.all(
|
|
36
|
-
orderPositions.map((orderPosition) => modules.orders.positions.addProductItem(orderPosition)),
|
|
37
|
-
);
|
|
38
|
-
} else {
|
|
39
|
-
const product = await modules.products.findProduct({
|
|
40
|
-
productId: enrollment.productId,
|
|
41
|
-
});
|
|
42
|
-
await modules.orders.positions.addProductItem({
|
|
43
|
-
quantity: 1,
|
|
44
|
-
productId: product._id,
|
|
45
|
-
originalProductId: product._id,
|
|
46
|
-
orderId: order._id,
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
const { paymentProviderId, context: paymentContext } = enrollment.payment;
|
|
51
|
-
if (paymentProviderId) {
|
|
52
|
-
await modules.orders.setPaymentProvider(orderId, paymentProviderId);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
const { deliveryProviderId, context: deliveryContext } = enrollment.delivery;
|
|
56
|
-
if (deliveryProviderId) {
|
|
57
|
-
await modules.orders.setDeliveryProvider(orderId, deliveryProviderId);
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
await services.orders.updateCalculation(orderId);
|
|
61
|
-
|
|
62
|
-
order = await services.orders.checkoutOrder(order._id, {
|
|
63
|
-
paymentContext,
|
|
64
|
-
deliveryContext,
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
return order;
|
|
68
|
-
};
|
|
69
|
-
|
|
70
|
-
const GenerateOrderWorker: IWorkerAdapter<any, any> = {
|
|
4
|
+
const GenerateOrderWorker: IWorkerAdapter<never, any> = {
|
|
71
5
|
...WorkerAdapter,
|
|
72
6
|
|
|
73
7
|
key: 'shop.unchained.worker-plugin.generate-enrollment-orders',
|
|
@@ -76,7 +10,7 @@ const GenerateOrderWorker: IWorkerAdapter<any, any> = {
|
|
|
76
10
|
type: 'ENROLLMENT_ORDER_GENERATOR',
|
|
77
11
|
|
|
78
12
|
doWork: async (input, unchainedAPI) => {
|
|
79
|
-
const { modules } = unchainedAPI;
|
|
13
|
+
const { modules, services } = unchainedAPI;
|
|
80
14
|
|
|
81
15
|
const enrollments = await modules.enrollments.findEnrollments({
|
|
82
16
|
status: [EnrollmentStatus.ACTIVE, EnrollmentStatus.PAUSED],
|
|
@@ -86,7 +20,13 @@ const GenerateOrderWorker: IWorkerAdapter<any, any> = {
|
|
|
86
20
|
await Promise.all(
|
|
87
21
|
enrollments.map(async (enrollment) => {
|
|
88
22
|
try {
|
|
89
|
-
const
|
|
23
|
+
const product = await unchainedAPI.modules.products.findProduct({
|
|
24
|
+
productId: enrollment.productId,
|
|
25
|
+
});
|
|
26
|
+
const director = await EnrollmentDirector.actions(
|
|
27
|
+
{ enrollment, product: product! },
|
|
28
|
+
unchainedAPI,
|
|
29
|
+
);
|
|
90
30
|
const period = await director.nextPeriod();
|
|
91
31
|
if (period) {
|
|
92
32
|
if (period.isTrial) {
|
|
@@ -96,11 +36,13 @@ const GenerateOrderWorker: IWorkerAdapter<any, any> = {
|
|
|
96
36
|
return null;
|
|
97
37
|
}
|
|
98
38
|
const configuration = await director.configurationForOrder({
|
|
99
|
-
...input,
|
|
100
39
|
period,
|
|
101
40
|
});
|
|
102
41
|
if (configuration) {
|
|
103
|
-
const order = await
|
|
42
|
+
const order = await services.enrollments.generateOrderFromEnrollment(
|
|
43
|
+
enrollment,
|
|
44
|
+
configuration,
|
|
45
|
+
);
|
|
104
46
|
if (order) {
|
|
105
47
|
await modules.enrollments.addEnrollmentPeriod(enrollment._id, {
|
|
106
48
|
...period,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { WorkStatus } from '@unchainedshop/core-worker';
|
|
1
|
+
import { Work, WorkStatus } from '@unchainedshop/core-worker';
|
|
2
2
|
import { IWorkerAdapter, WorkerDirector, WorkerAdapter } from '@unchainedshop/core';
|
|
3
3
|
import later from '@breejs/later';
|
|
4
4
|
|
|
@@ -22,7 +22,7 @@ export const ErrorNotifications: IWorkerAdapter<Arg, Result> = {
|
|
|
22
22
|
type: 'ERROR_NOTIFICATIONS',
|
|
23
23
|
|
|
24
24
|
doWork: async (args, context, workId) => {
|
|
25
|
-
const work = await context.modules.worker.findWork({ workId });
|
|
25
|
+
const work = (await context.modules.worker.findWork({ workId })) as Work;
|
|
26
26
|
const secondsPassed = args?.secondsPassed || 60;
|
|
27
27
|
const to = new Date();
|
|
28
28
|
const from = new Date(new Date(work.scheduled).getTime() - secondsPassed * 1000);
|
|
@@ -21,7 +21,6 @@ export const configureExportToken = (unchainedAPI: UnchainedCore) => {
|
|
|
21
21
|
if (work.type === 'EXPORT_TOKEN' && work.success) {
|
|
22
22
|
await unchainedAPI.modules.warehousing.updateTokenOwnership({
|
|
23
23
|
tokenId: work.input.token._id,
|
|
24
|
-
userId: null,
|
|
25
24
|
walletAddress: work.input.recipientWalletAddress,
|
|
26
25
|
});
|
|
27
26
|
}
|
package/src/worker/message.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { MessagingDirector, IWorkerAdapter, WorkerAdapter, WorkerDirector } from
|
|
|
2
2
|
import { Work } from '@unchainedshop/core-worker';
|
|
3
3
|
|
|
4
4
|
export const MessageWorker: IWorkerAdapter<
|
|
5
|
-
{ template: string; _id
|
|
5
|
+
{ template: string; _id: string; [x: string]: any },
|
|
6
6
|
{ info?: string; forked?: Work[] }
|
|
7
7
|
> = {
|
|
8
8
|
...WorkerAdapter,
|
|
@@ -16,6 +16,8 @@ export const MessageWorker: IWorkerAdapter<
|
|
|
16
16
|
try {
|
|
17
17
|
const templateResolver = MessagingDirector.getTemplate(template);
|
|
18
18
|
|
|
19
|
+
if (!templateResolver) throw new Error(`No template resolver found for template ${template}`);
|
|
20
|
+
|
|
19
21
|
const workConfigurations = await templateResolver(
|
|
20
22
|
{
|
|
21
23
|
template,
|
|
@@ -31,13 +33,13 @@ export const MessageWorker: IWorkerAdapter<
|
|
|
31
33
|
...workConfiguration,
|
|
32
34
|
originalWorkId: workId,
|
|
33
35
|
});
|
|
34
|
-
delete work.input;
|
|
36
|
+
delete (work as any).input; // Remove input from returned work for privacy
|
|
35
37
|
return work;
|
|
36
38
|
}),
|
|
37
39
|
);
|
|
38
40
|
return { success: true, result: { forked } };
|
|
39
41
|
}
|
|
40
|
-
return { success: true, result: {
|
|
42
|
+
return { success: true, result: { forked: [] } };
|
|
41
43
|
} catch (err) {
|
|
42
44
|
return {
|
|
43
45
|
success: false,
|
package/src/worker/twilio.ts
CHANGED
|
@@ -5,8 +5,8 @@ const { TWILIO_ACCOUNT_SID, TWILIO_AUTH_TOKEN, TWILIO_SMS_FROM } = process.env;
|
|
|
5
5
|
const SmsWorkerPlugin: IWorkerAdapter<
|
|
6
6
|
{
|
|
7
7
|
from?: string;
|
|
8
|
-
to
|
|
9
|
-
text
|
|
8
|
+
to: string;
|
|
9
|
+
text: string;
|
|
10
10
|
[key: string]: any; // Allow additional parameters
|
|
11
11
|
},
|
|
12
12
|
any
|
|
@@ -21,6 +21,13 @@ const SmsWorkerPlugin: IWorkerAdapter<
|
|
|
21
21
|
|
|
22
22
|
doWork: async ({ from, to, text, ...params }) => {
|
|
23
23
|
try {
|
|
24
|
+
if (!TWILIO_SMS_FROM && !from)
|
|
25
|
+
throw new Error(
|
|
26
|
+
'Missing Twilio "from" number. Set TWILIO_SMS_FROM env var or provide "from" in input',
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
if (!to) throw new Error('Missing "to" in input');
|
|
30
|
+
|
|
24
31
|
const url = `https://api.twilio.com/2010-04-01/Accounts/${TWILIO_ACCOUNT_SID}/Messages.json`;
|
|
25
32
|
const response = await fetch(url, {
|
|
26
33
|
method: 'POST',
|
|
@@ -30,7 +37,7 @@ const SmsWorkerPlugin: IWorkerAdapter<
|
|
|
30
37
|
},
|
|
31
38
|
body: new URLSearchParams({
|
|
32
39
|
Body: text || '',
|
|
33
|
-
From: from || TWILIO_SMS_FROM
|
|
40
|
+
From: from || TWILIO_SMS_FROM!,
|
|
34
41
|
To: to,
|
|
35
42
|
...params, // Include any additional parameters passed
|
|
36
43
|
}),
|