@unchainedshop/plugins 4.0.0-rc.8 → 4.0.0
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.d.ts.map +1 -1
- package/lib/files/gridfs/adapter.js +11 -8
- 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 +21 -25
- 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 +50 -13
- 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.d.ts.map +1 -1
- package/lib/files/minio/handler-express.js +4 -7
- package/lib/files/minio/handler-express.js.map +1 -1
- package/lib/files/minio/handler-fastify.js +2 -2
- 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 +7 -7
- 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/filters/strict-equal.js +0 -18
- package/lib/filters/strict-equal.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 +14 -10
- 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 +15 -8
- 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 +5 -3
- 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.d.ts.map +1 -1
- package/lib/payment/cryptopay/handler-express.js +4 -7
- 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 +13 -11
- 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 +11 -5
- 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 +15 -15
- package/lib/payment/payrexx/handler-express.js.map +1 -1
- package/lib/payment/payrexx/handler-fastify.js +23 -15
- 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/api-client.d.ts.map +1 -1
- package/lib/payment/postfinance-checkout/api-client.js +7 -7
- package/lib/payment/postfinance-checkout/api-client.js.map +1 -1
- package/lib/payment/postfinance-checkout/handler-express.js +7 -8
- 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 +6 -4
- 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 +10 -8
- 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 +11 -5
- 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.js +25 -17
- 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 +33 -12
- package/lib/payment/stripe/handler-fastify.js.map +1 -1
- package/lib/payment/stripe/index.js +21 -15
- 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 +8 -6
- package/lib/presets/all.d.ts.map +1 -1
- package/lib/presets/all.js +3 -1
- package/lib/presets/all.js.map +1 -1
- package/lib/pricing/delivery-swiss-tax.d.ts.map +1 -1
- package/lib/pricing/delivery-swiss-tax.js +13 -20
- 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-options.d.ts +2 -0
- package/lib/pricing/product-catalog-price-options.d.ts.map +1 -0
- package/lib/pricing/product-catalog-price-options.js +52 -0
- package/lib/pricing/product-catalog-price-options.js.map +1 -0
- package/lib/pricing/product-catalog-price.d.ts.map +1 -1
- package/lib/pricing/product-catalog-price.js +26 -2
- 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 -5
- package/lib/pricing/product-swiss-tax.d.ts.map +1 -1
- package/lib/pricing/product-swiss-tax.js +26 -22
- package/lib/pricing/product-swiss-tax.js.map +1 -1
- package/lib/pricing/tax/ch.d.ts +7 -2
- package/lib/pricing/tax/ch.d.ts.map +1 -1
- package/lib/pricing/tax/ch.js +16 -1
- package/lib/pricing/tax/ch.js.map +1 -1
- package/lib/pricing/utils/isDeliveryAddressInCountry.d.ts +7 -0
- package/lib/pricing/utils/isDeliveryAddressInCountry.d.ts.map +1 -0
- package/lib/pricing/utils/isDeliveryAddressInCountry.js +13 -0
- package/lib/pricing/utils/isDeliveryAddressInCountry.js.map +1 -0
- package/lib/warehousing/eth-minter.js +23 -11
- package/lib/warehousing/eth-minter.js.map +1 -1
- package/lib/worker/budgetsms.d.ts +10 -0
- package/lib/worker/budgetsms.d.ts.map +1 -0
- package/lib/worker/budgetsms.js +217 -0
- package/lib/worker/budgetsms.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 +11 -33
- package/lib/worker/bulk-import.js.map +1 -1
- package/lib/worker/bulkgate.d.ts +2 -0
- package/lib/worker/bulkgate.d.ts.map +1 -0
- package/lib/worker/bulkgate.js +104 -0
- package/lib/worker/bulkgate.js.map +1 -0
- package/lib/worker/email.d.ts.map +1 -1
- package/lib/worker/email.js +25 -7
- package/lib/worker/email.js.map +1 -1
- package/lib/worker/enrollment-order-generator.d.ts.map +1 -1
- package/lib/worker/enrollment-order-generator.js +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.js +17 -17
- package/lib/worker/sms.js.map +1 -1
- package/lib/worker/twilio.d.ts +2 -0
- package/lib/worker/twilio.d.ts.map +1 -0
- package/lib/worker/twilio.js +60 -0
- package/lib/worker/twilio.js.map +1 -0
- package/package.json +22 -33
- package/src/delivery/send-message.ts +1 -1
- package/src/enrollments/licensed.ts +15 -2
- package/src/files/gridfs/adapter.ts +12 -7
- package/src/files/gridfs/handler-express.ts +23 -25
- package/src/files/gridfs/handler-fastify.ts +53 -14
- package/src/files/minio/handler-express.ts +4 -7
- package/src/files/minio/handler-fastify.ts +2 -2
- package/src/files/minio/index.ts +16 -16
- package/src/filters/local-search.ts +1 -1
- package/src/filters/strict-equal.ts +0 -21
- 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 +17 -11
- package/src/payment/apple-iap/handler-fastify.ts +19 -9
- 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 +5 -3
- package/src/payment/cryptopay/handle-webhook.ts +6 -6
- package/src/payment/cryptopay/handler-express.ts +4 -7
- 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 +17 -12
- package/src/payment/datatrans-v2/handler-fastify.ts +15 -6
- 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 +24 -32
- package/src/payment/payrexx/handler-fastify.ts +33 -33
- package/src/payment/payrexx/index.ts +26 -16
- package/src/payment/postfinance-checkout/api-client.ts +13 -8
- package/src/payment/postfinance-checkout/handler-express.ts +8 -8
- package/src/payment/postfinance-checkout/handler-fastify.ts +7 -4
- package/src/payment/postfinance-checkout/index.ts +20 -8
- package/src/payment/saferpay/adapter.ts +14 -2
- package/src/payment/saferpay/handler-express.ts +14 -13
- package/src/payment/saferpay/handler-fastify.ts +14 -9
- package/src/payment/stripe/handler-express.ts +33 -33
- package/src/payment/stripe/handler-fastify.ts +40 -27
- package/src/payment/stripe/index.ts +18 -16
- package/src/payment/stripe/stripe.ts +17 -12
- package/src/presets/all.ts +3 -1
- package/src/pricing/delivery-swiss-tax.ts +16 -31
- package/src/pricing/order-discount.ts +6 -4
- package/src/pricing/order-round.ts +5 -4
- package/src/pricing/product-catalog-price-options.ts +67 -0
- package/src/pricing/product-catalog-price.ts +25 -2
- package/src/pricing/product-price-rateconversion.ts +3 -3
- package/src/pricing/product-swiss-tax.ts +39 -40
- package/src/pricing/tax/ch.ts +33 -7
- package/src/pricing/utils/isDeliveryAddressInCountry.test.ts +106 -0
- package/src/pricing/utils/isDeliveryAddressInCountry.ts +26 -0
- package/src/warehousing/eth-minter.ts +30 -11
- package/src/worker/budgetsms.ts +268 -0
- package/src/worker/bulk-import.ts +12 -53
- package/src/worker/bulkgate.ts +138 -0
- package/src/worker/email.ts +30 -8
- 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/{sms.ts → twilio.ts} +15 -26
- package/src/pricing/product-swiss-tax.test.ts +0 -139
|
@@ -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,
|
|
@@ -5,41 +5,29 @@ const { TWILIO_ACCOUNT_SID, TWILIO_AUTH_TOKEN, TWILIO_SMS_FROM } = process.env;
|
|
|
5
5
|
const SmsWorkerPlugin: IWorkerAdapter<
|
|
6
6
|
{
|
|
7
7
|
from?: string;
|
|
8
|
-
to
|
|
9
|
-
text
|
|
8
|
+
to: string;
|
|
9
|
+
text: string;
|
|
10
|
+
[key: string]: any; // Allow additional parameters
|
|
10
11
|
},
|
|
11
12
|
any
|
|
12
13
|
> = {
|
|
13
14
|
...WorkerAdapter,
|
|
14
15
|
|
|
15
|
-
key: 'shop.unchained.worker-plugin.
|
|
16
|
-
label: 'Send
|
|
16
|
+
key: 'shop.unchained.worker-plugin.twilio',
|
|
17
|
+
label: 'Send Messages through Twilio',
|
|
17
18
|
version: '1.0.0',
|
|
18
19
|
|
|
19
|
-
type: '
|
|
20
|
+
type: 'TWILIO',
|
|
20
21
|
|
|
21
|
-
doWork: async ({ from, to, text }) => {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
message: 'SMS requires a from, TWILIO_SMS_FROM not set',
|
|
28
|
-
},
|
|
29
|
-
};
|
|
30
|
-
}
|
|
22
|
+
doWork: async ({ from, to, text, ...params }) => {
|
|
23
|
+
try {
|
|
24
|
+
if (!TWILIO_SMS_FROM && !from)
|
|
25
|
+
throw new Error(
|
|
26
|
+
'Missing Twilio "from" number. Set TWILIO_SMS_FROM env var or provide "from" in input',
|
|
27
|
+
);
|
|
31
28
|
|
|
32
|
-
|
|
33
|
-
return {
|
|
34
|
-
success: false,
|
|
35
|
-
error: {
|
|
36
|
-
name: 'RECIPIENT_REQUIRED',
|
|
37
|
-
message: 'SMS requires a to',
|
|
38
|
-
},
|
|
39
|
-
};
|
|
40
|
-
}
|
|
29
|
+
if (!to) throw new Error('Missing "to" in input');
|
|
41
30
|
|
|
42
|
-
try {
|
|
43
31
|
const url = `https://api.twilio.com/2010-04-01/Accounts/${TWILIO_ACCOUNT_SID}/Messages.json`;
|
|
44
32
|
const response = await fetch(url, {
|
|
45
33
|
method: 'POST',
|
|
@@ -49,8 +37,9 @@ const SmsWorkerPlugin: IWorkerAdapter<
|
|
|
49
37
|
},
|
|
50
38
|
body: new URLSearchParams({
|
|
51
39
|
Body: text || '',
|
|
52
|
-
From: from || TWILIO_SMS_FROM
|
|
40
|
+
From: from || TWILIO_SMS_FROM!,
|
|
53
41
|
To: to,
|
|
42
|
+
...params, // Include any additional parameters passed
|
|
54
43
|
}),
|
|
55
44
|
});
|
|
56
45
|
|
|
@@ -1,139 +0,0 @@
|
|
|
1
|
-
import { describe, it } from 'node:test';
|
|
2
|
-
import assert from 'node:assert';
|
|
3
|
-
|
|
4
|
-
import { getTaxRate, isDeliveryAddressInSwitzerland } from './product-swiss-tax.js';
|
|
5
|
-
|
|
6
|
-
describe('ProductSwissTax', () => {
|
|
7
|
-
describe('getTaxRate', () => {
|
|
8
|
-
it('default rate', () => {
|
|
9
|
-
assert.strictEqual(
|
|
10
|
-
getTaxRate({
|
|
11
|
-
product: {} as any,
|
|
12
|
-
order: {} as any,
|
|
13
|
-
} as any),
|
|
14
|
-
0.081,
|
|
15
|
-
);
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
it('reduced rate', () => {
|
|
19
|
-
assert.strictEqual(
|
|
20
|
-
getTaxRate({
|
|
21
|
-
product: {
|
|
22
|
-
tags: ['swiss-tax-category:reduced'],
|
|
23
|
-
},
|
|
24
|
-
order: {},
|
|
25
|
-
} as any),
|
|
26
|
-
0.026,
|
|
27
|
-
);
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
it('special rate', () => {
|
|
31
|
-
assert.strictEqual(
|
|
32
|
-
getTaxRate({
|
|
33
|
-
product: {
|
|
34
|
-
tags: ['swiss-tax-category:special'],
|
|
35
|
-
},
|
|
36
|
-
order: {},
|
|
37
|
-
} as any),
|
|
38
|
-
0.038,
|
|
39
|
-
);
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
it('default rate', () => {
|
|
43
|
-
assert.strictEqual(
|
|
44
|
-
getTaxRate({
|
|
45
|
-
product: {
|
|
46
|
-
tags: ['swiss-tax-category:default'],
|
|
47
|
-
},
|
|
48
|
-
order: {},
|
|
49
|
-
} as any),
|
|
50
|
-
0.081,
|
|
51
|
-
);
|
|
52
|
-
});
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
describe('isDeliveryAddressInSwitzerland', () => {
|
|
56
|
-
const context = {
|
|
57
|
-
modules: {
|
|
58
|
-
orders: {
|
|
59
|
-
deliveries: {
|
|
60
|
-
findDelivery: async ({ orderDeliveryId }) => {
|
|
61
|
-
if (orderDeliveryId === 'CH' || orderDeliveryId === 'LI')
|
|
62
|
-
return { context: { address: { countryCode: 'CH' } } };
|
|
63
|
-
if (orderDeliveryId === null) return { context: { address: null } };
|
|
64
|
-
return { context: { address: { countryCode: 'RT' } } };
|
|
65
|
-
},
|
|
66
|
-
},
|
|
67
|
-
},
|
|
68
|
-
},
|
|
69
|
-
order: {
|
|
70
|
-
deliveryId: 'CH',
|
|
71
|
-
billingAddress: { countryCode: 'LI' },
|
|
72
|
-
},
|
|
73
|
-
countryCode: 'CH',
|
|
74
|
-
};
|
|
75
|
-
it('Should return true when passed country code CH', async () => {
|
|
76
|
-
assert.strictEqual(
|
|
77
|
-
await isDeliveryAddressInSwitzerland({ ...context, countryCode: 'ch', order: null } as any),
|
|
78
|
-
true,
|
|
79
|
-
);
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
it('Should return true when passed country code LI', async () => {
|
|
83
|
-
assert.strictEqual(
|
|
84
|
-
await isDeliveryAddressInSwitzerland({ ...context, countryCode: 'LI', order: null } as any),
|
|
85
|
-
true,
|
|
86
|
-
);
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
it('Should return false when country is neither CH nor LI and order is null', async () => {
|
|
90
|
-
assert.strictEqual(
|
|
91
|
-
await isDeliveryAddressInSwitzerland({ ...context, countryCode: 'ET', order: null } as any),
|
|
92
|
-
false,
|
|
93
|
-
);
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
it('Order should take precedence over country parameter', async () => {
|
|
97
|
-
// not CH or LI order so returns false
|
|
98
|
-
assert.strictEqual(
|
|
99
|
-
await isDeliveryAddressInSwitzerland({
|
|
100
|
-
...context,
|
|
101
|
-
countryCode: 'CH',
|
|
102
|
-
order: {
|
|
103
|
-
deliveryId: 'ET',
|
|
104
|
-
billingAddress: { countryCode: 'ET' },
|
|
105
|
-
},
|
|
106
|
-
} as any),
|
|
107
|
-
false,
|
|
108
|
-
);
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
it('If order is not from CH and LI but billingAddress is, it should take precedence over country ', async () => {
|
|
112
|
-
assert.strictEqual(
|
|
113
|
-
await isDeliveryAddressInSwitzerland({
|
|
114
|
-
...context,
|
|
115
|
-
countryCode: 'IT',
|
|
116
|
-
order: {
|
|
117
|
-
deliveryId: null,
|
|
118
|
-
billingAddress: { countryCode: 'CH' },
|
|
119
|
-
},
|
|
120
|
-
} as any),
|
|
121
|
-
true,
|
|
122
|
-
);
|
|
123
|
-
});
|
|
124
|
-
|
|
125
|
-
it('Should return false if billingAddress is neither CH or LI and order does not have address', async () => {
|
|
126
|
-
assert.strictEqual(
|
|
127
|
-
await isDeliveryAddressInSwitzerland({
|
|
128
|
-
...context,
|
|
129
|
-
country: null,
|
|
130
|
-
order: {
|
|
131
|
-
deliveryId: null,
|
|
132
|
-
billingAddress: { countryCode: 'HH' },
|
|
133
|
-
},
|
|
134
|
-
} as any),
|
|
135
|
-
false,
|
|
136
|
-
);
|
|
137
|
-
});
|
|
138
|
-
});
|
|
139
|
-
});
|