@unchainedshop/plugins 1.2.7 → 1.2.12

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.
Files changed (109) hide show
  1. package/lib/delivery/pick-mup.js +2 -3
  2. package/lib/delivery/pick-mup.js.map +1 -1
  3. package/lib/delivery/send-message.js +1 -2
  4. package/lib/delivery/send-message.js.map +1 -1
  5. package/lib/events/redis.js +3 -2
  6. package/lib/events/redis.js.map +1 -1
  7. package/lib/files/gridfs/gridfs-adapter.js +1 -2
  8. package/lib/files/gridfs/gridfs-adapter.js.map +1 -1
  9. package/lib/files/gridfs/gridfs-webhook.js +1 -1
  10. package/lib/files/gridfs/gridfs-webhook.js.map +1 -1
  11. package/lib/files/minio/minio-adapter.d.ts +1 -1
  12. package/lib/files/minio/minio-adapter.js +6 -4
  13. package/lib/files/minio/minio-adapter.js.map +1 -1
  14. package/lib/payment/apple-iap/adapter.js +1 -1
  15. package/lib/payment/apple-iap/adapter.js.map +1 -1
  16. package/lib/payment/bity/adapter.js +3 -1
  17. package/lib/payment/bity/adapter.js.map +1 -1
  18. package/lib/payment/braintree.js +5 -1
  19. package/lib/payment/braintree.js.map +1 -1
  20. package/lib/payment/cryptopay.js.map +1 -1
  21. package/lib/payment/datatrans-v2/api/index.d.ts +1 -1
  22. package/lib/payment/datatrans-v2/api/makeFetcher.d.ts +2 -1
  23. package/lib/payment/datatrans-v2/api/makeFetcher.js +11 -8
  24. package/lib/payment/datatrans-v2/api/makeFetcher.js.map +1 -1
  25. package/lib/payment/datatrans-v2/index.js +1 -1
  26. package/lib/payment/datatrans-v2/index.js.map +1 -1
  27. package/lib/payment/datatrans-v2/middleware.js.map +1 -1
  28. package/lib/payment/postfinance-checkout/api.d.ts +5 -5
  29. package/lib/payment/postfinance-checkout/api.js +3 -3
  30. package/lib/payment/postfinance-checkout/api.js.map +1 -1
  31. package/lib/payment/postfinance-checkout/index.js +11 -11
  32. package/lib/payment/postfinance-checkout/index.js.map +1 -1
  33. package/lib/payment/postfinance-checkout/utils.d.ts +3 -3
  34. package/lib/payment/postfinance-checkout/utils.js +4 -3
  35. package/lib/payment/postfinance-checkout/utils.js.map +1 -1
  36. package/lib/payment/stripe.js +3 -1
  37. package/lib/payment/stripe.js.map +1 -1
  38. package/lib/payment/worldline-saferpay/index.js +6 -2
  39. package/lib/payment/worldline-saferpay/index.js.map +1 -1
  40. package/lib/plugins-index.d.ts +0 -0
  41. package/lib/plugins-index.js +1 -0
  42. package/lib/plugins-index.js.map +1 -0
  43. package/lib/pricing/delivery-swiss-tax.d.ts +1 -1
  44. package/lib/pricing/delivery-swiss-tax.js +3 -9
  45. package/lib/pricing/delivery-swiss-tax.js.map +1 -1
  46. package/lib/pricing/free-delivery.js +2 -0
  47. package/lib/pricing/free-delivery.js.map +1 -1
  48. package/lib/pricing/free-payment.js +2 -0
  49. package/lib/pricing/free-payment.js.map +1 -1
  50. package/lib/pricing/order-discount.js +2 -0
  51. package/lib/pricing/order-discount.js.map +1 -1
  52. package/lib/pricing/order-items-discount.js +2 -0
  53. package/lib/pricing/order-items-discount.js.map +1 -1
  54. package/lib/pricing/product-price-ECB-interbank-exchange.js +1 -1
  55. package/lib/pricing/product-price-ECB-interbank-exchange.js.map +1 -1
  56. package/lib/pricing/product-price-coinbase-exchange.js +1 -1
  57. package/lib/pricing/product-price-coinbase-exchange.js.map +1 -1
  58. package/lib/pricing/product-swiss-tax.d.ts +1 -1
  59. package/lib/pricing/product-swiss-tax.js +2 -9
  60. package/lib/pricing/product-swiss-tax.js.map +1 -1
  61. package/lib/warehousing/store.js +2 -2
  62. package/lib/warehousing/store.js.map +1 -1
  63. package/lib/worker/BulkImportWorker.js +9 -9
  64. package/lib/worker/BulkImportWorker.js.map +1 -1
  65. package/lib/worker/GenerateOrderWorker.js +2 -2
  66. package/lib/worker/GenerateOrderWorker.js.map +1 -1
  67. package/lib/worker/MessageWorker.js +1 -1
  68. package/lib/worker/MessageWorker.js.map +1 -1
  69. package/lib/worker/email.js +3 -0
  70. package/lib/worker/email.js.map +1 -1
  71. package/lib/worker/http-request.js +1 -1
  72. package/lib/worker/http-request.js.map +1 -1
  73. package/package.json +37 -3
  74. package/readme.md +4 -0
  75. package/src/delivery/pick-mup.ts +3 -4
  76. package/src/delivery/send-message.ts +1 -2
  77. package/src/events/redis.ts +3 -2
  78. package/src/files/gridfs/gridfs-adapter.ts +7 -8
  79. package/src/files/gridfs/gridfs-webhook.ts +1 -1
  80. package/src/files/minio/minio-adapter.ts +10 -8
  81. package/src/payment/apple-iap/adapter.ts +2 -2
  82. package/src/payment/bity/adapter.ts +6 -4
  83. package/src/payment/braintree.ts +6 -1
  84. package/src/payment/cryptopay.ts +1 -1
  85. package/src/payment/datatrans-v2/api/makeFetcher.ts +7 -5
  86. package/src/payment/datatrans-v2/index.ts +1 -1
  87. package/src/payment/datatrans-v2/middleware.ts +2 -2
  88. package/src/payment/postfinance-checkout/api.ts +8 -9
  89. package/src/payment/postfinance-checkout/index.ts +19 -13
  90. package/src/payment/postfinance-checkout/silence-postfinancecheckout.d.ts +33 -0
  91. package/src/payment/postfinance-checkout/utils.ts +7 -6
  92. package/src/payment/stripe.ts +3 -1
  93. package/src/payment/worldline-saferpay/index.ts +7 -4
  94. package/src/plugins-index.ts +0 -0
  95. package/src/pricing/delivery-swiss-tax.ts +3 -10
  96. package/src/pricing/free-delivery.ts +2 -0
  97. package/src/pricing/free-payment.ts +2 -0
  98. package/src/pricing/order-discount.ts +2 -0
  99. package/src/pricing/order-items-discount.ts +2 -0
  100. package/src/pricing/product-price-ECB-interbank-exchange.ts +1 -1
  101. package/src/pricing/product-price-coinbase-exchange.ts +1 -1
  102. package/src/pricing/product-swiss-tax.ts +2 -9
  103. package/src/warehousing/store.ts +2 -2
  104. package/src/worker/BulkImportWorker.ts +24 -18
  105. package/src/worker/GenerateOrderWorker.ts +2 -2
  106. package/src/worker/MessageWorker.ts +3 -2
  107. package/src/worker/email.ts +4 -1
  108. package/src/worker/http-request.ts +1 -1
  109. package/tsconfig.json +10 -1
@@ -1,7 +1,6 @@
1
- import { PostFinanceCheckout } from 'postfinancecheckout';
2
- import { RefundCreate } from 'postfinancecheckout/src/models/RefundCreate';
3
- import { RefundType } from 'postfinancecheckout/src/models/RefundType';
1
+ import * as pf from 'postfinancecheckout';
4
2
 
3
+ const { PostFinanceCheckout } = pf;
5
4
  const { PFCHECKOUT_SPACE_ID, PFCHECKOUT_USER_ID, PFCHECKOUT_SECRET } = process.env;
6
5
  const SPACE_ID = parseInt(PFCHECKOUT_SPACE_ID as string, 10);
7
6
  const USER_ID = parseInt(PFCHECKOUT_USER_ID as string, 10);
@@ -48,7 +47,7 @@ const getTokenService = () => {
48
47
 
49
48
  export const getTransaction = async (
50
49
  transactionId: string,
51
- ): Promise<PostFinanceCheckout.model.Transaction> => {
50
+ ): Promise<pf.PostFinanceCheckout.model.Transaction> => {
52
51
  const transactionService = getTransactionService();
53
52
  const transaction = await transactionService.read(SPACE_ID, parseInt(transactionId, 10));
54
53
  return transaction.body;
@@ -56,7 +55,7 @@ export const getTransaction = async (
56
55
 
57
56
  export const getTransactionCompletion = async (
58
57
  entityId: string,
59
- ): Promise<PostFinanceCheckout.model.TransactionCompletion> => {
58
+ ): Promise<pf.PostFinanceCheckout.model.TransactionCompletion> => {
60
59
  const transactionCompletionService = getTransactionCompletionService();
61
60
  const transactionCompletion = await transactionCompletionService.read(
62
61
  SPACE_ID,
@@ -68,14 +67,14 @@ export const getTransactionCompletion = async (
68
67
  export const getToken = async (
69
68
  spaceId: number,
70
69
  tokenId: number,
71
- ): Promise<PostFinanceCheckout.model.Token> => {
70
+ ): Promise<pf.PostFinanceCheckout.model.Token> => {
72
71
  const tokenService = getTokenService();
73
72
  const token = await tokenService.read(spaceId || SPACE_ID, tokenId);
74
73
  return token.body;
75
74
  };
76
75
 
77
76
  export const createTransaction = async (
78
- transaction: PostFinanceCheckout.model.TransactionCreate,
77
+ transaction: pf.PostFinanceCheckout.model.TransactionCreate,
79
78
  ): Promise<number | null> => {
80
79
  const transactionService = getTransactionService();
81
80
  const transactionCreateRes = await transactionService.create(SPACE_ID, transaction);
@@ -99,11 +98,11 @@ export const refundTransaction = async (
99
98
  amount: number,
100
99
  ): Promise<boolean> => {
101
100
  const refundService = getRefundService();
102
- const refund: RefundCreate = {
101
+ const refund: pf.PostFinanceCheckout.model.RefundCreate = {
103
102
  transaction: parseInt(transactionId, 10),
104
103
  externalId: orderId,
105
104
  amount,
106
- type: RefundType.MERCHANT_INITIATED_ONLINE,
105
+ type: PostFinanceCheckout.model.RefundType.MERCHANT_INITIATED_ONLINE,
107
106
  };
108
107
  try {
109
108
  await refundService.refund(SPACE_ID, refund);
@@ -1,10 +1,12 @@
1
- import { IPaymentActions, IPaymentAdapter } from '@unchainedshop/types/payments';
1
+ import {
2
+ IPaymentActions,
3
+ IPaymentAdapter,
4
+ PaymentChargeActionResult,
5
+ } from '@unchainedshop/types/payments';
2
6
  import { PaymentAdapter, PaymentDirector, PaymentError } from '@unchainedshop/core-payment';
3
- import { TransactionCompletionBehavior } from 'postfinancecheckout/src/models/TransactionCompletionBehavior';
4
- import { PostFinanceCheckout } from 'postfinancecheckout';
5
7
  import { createLogger } from '@unchainedshop/logger';
6
- import { CreationEntityState } from 'postfinancecheckout/src/models/CreationEntityState';
7
- import { TransactionState } from 'postfinancecheckout/src/models/TransactionState';
8
+
9
+ import * as pf from 'postfinancecheckout';
8
10
  import {
9
11
  confirmDeferredTransaction,
10
12
  createTransaction,
@@ -20,6 +22,8 @@ import { orderIsPaid } from './utils';
20
22
  import setupPostfinance from './middleware';
21
23
  import { CompletionModes, IntegrationModes, SignResponse } from './types';
22
24
 
25
+ const { PostFinanceCheckout } = pf;
26
+
23
27
  export default setupPostfinance;
24
28
 
25
29
  const {
@@ -92,7 +96,7 @@ const PostfinanceCheckout: IPaymentAdapter = {
92
96
  if (!credentials.meta) return false;
93
97
  const { linkedSpaceId } = credentials.meta;
94
98
  const tokenData = await getToken(linkedSpaceId, credentials.token);
95
- return tokenData.state === CreationEntityState.ACTIVE;
99
+ return tokenData.state === PostFinanceCheckout.model.CreationEntityState.ACTIVE;
96
100
  },
97
101
 
98
102
  sign: async (transactionContext: any = {}) => {
@@ -120,9 +124,11 @@ const PostfinanceCheckout: IPaymentAdapter = {
120
124
  transaction.tokenizationMode =
121
125
  PostFinanceCheckout.model.TokenizationMode.ALLOW_ONE_CLICK_PAYMENT;
122
126
  if (completionMode === CompletionModes.Immediate) {
123
- transaction.completionBehavior = TransactionCompletionBehavior.COMPLETE_IMMEDIATELY;
127
+ transaction.completionBehavior =
128
+ PostFinanceCheckout.model.TransactionCompletionBehavior.COMPLETE_IMMEDIATELY;
124
129
  } else if (completionMode === CompletionModes.Deferred) {
125
- transaction.completionBehavior = TransactionCompletionBehavior.COMPLETE_DEFERRED;
130
+ transaction.completionBehavior =
131
+ PostFinanceCheckout.model.TransactionCompletionBehavior.COMPLETE_DEFERRED;
126
132
  }
127
133
  if (totalAmount) {
128
134
  const lineItemSum = new PostFinanceCheckout.model.LineItemCreate();
@@ -190,16 +196,16 @@ const PostfinanceCheckout: IPaymentAdapter = {
190
196
  });
191
197
  }
192
198
 
193
- const { token: { id, ...tokenMeta } = {} } = transaction;
199
+ const { id, ...tokenMeta } = transaction.token || {};
194
200
 
195
201
  return {
196
202
  transaction,
197
203
  transactionId,
198
204
  credentials: id && {
199
205
  ...tokenMeta,
200
- token: id,
206
+ token: id.toString(),
201
207
  },
202
- };
208
+ } as PaymentChargeActionResult;
203
209
  },
204
210
 
205
211
  cancel: async () => {
@@ -209,7 +215,7 @@ const PostfinanceCheckout: IPaymentAdapter = {
209
215
  return false;
210
216
  }
211
217
  const transaction = await getTransaction(transactionId);
212
- const refund = transaction.state === TransactionState.FULFILL;
218
+ const refund = transaction.state === PostFinanceCheckout.model.TransactionState.FULFILL;
213
219
  const order = await modules.orders.findOrder({
214
220
  orderId: orderPayment.orderId,
215
221
  });
@@ -229,7 +235,7 @@ const PostfinanceCheckout: IPaymentAdapter = {
229
235
  return false;
230
236
  }
231
237
  const transaction = await getTransaction(transactionId);
232
- if (transaction.state === TransactionState.AUTHORIZED) {
238
+ if (transaction.state === PostFinanceCheckout.model.TransactionState.AUTHORIZED) {
233
239
  return confirmDeferredTransaction(transactionId);
234
240
  }
235
241
  return false;
@@ -0,0 +1,33 @@
1
+ export declare namespace PostFinanceCheckout {
2
+ namespace model {
3
+ const Transaction;
4
+ type Transaction = any;
5
+ const TransactionCompletion;
6
+ type TransactionCompletion = any;
7
+ const Token;
8
+ type Token = any;
9
+ const TransactionCreate;
10
+ type TransactionCreate = any;
11
+ const RefundCreate;
12
+ type RefundCreate = any;
13
+ const TransactionState: any;
14
+ const LineItemType: any;
15
+ const LineItemCreate: any;
16
+ const RefundType: any;
17
+ const CreationEntityState: any;
18
+ const TokenizationMode: any;
19
+ const TransactionCompletionBehavior: any;
20
+ const TransactionCompletionBehavior: any;
21
+ }
22
+ namespace api {
23
+ const [string]: any;
24
+ const TransactionService: any;
25
+ const TransactionCompletionService: any;
26
+ const TransactionVoidService: any;
27
+ const RefundService: any;
28
+ const TransactionPaymentPageService: any;
29
+ const TransactionIframeService: any;
30
+ const TransactionLightboxService: any;
31
+ const TokenService: any;
32
+ }
33
+ }
@@ -1,20 +1,21 @@
1
1
  import { Order, OrdersModule } from '@unchainedshop/types/orders';
2
- import { Transaction } from 'postfinancecheckout/src/models/Transaction';
3
- import { TransactionState } from 'postfinancecheckout/src/models/TransactionState';
2
+ import * as pf from 'postfinancecheckout';
3
+
4
+ const { PostFinanceCheckout } = pf;
4
5
 
5
6
  export const transactionIsPaid = async (
6
- transaction: Transaction,
7
+ transaction: pf.PostFinanceCheckout.model.Transaction,
7
8
  expectedCurrency: string,
8
9
  expectedAmount: number,
9
10
  ): Promise<boolean> => {
10
- if (transaction.state === TransactionState.FULFILL) {
11
+ if (transaction.state === PostFinanceCheckout.model.TransactionState.FULFILL) {
11
12
  return (
12
13
  transaction.completedAmount !== undefined &&
13
14
  transaction.completedAmount.toFixed(2) === expectedAmount.toFixed(2) &&
14
15
  transaction.currency === expectedCurrency
15
16
  );
16
17
  }
17
- if (transaction.state === TransactionState.AUTHORIZED) {
18
+ if (transaction.state === PostFinanceCheckout.model.TransactionState.AUTHORIZED) {
18
19
  return (
19
20
  transaction.authorizationAmount !== undefined &&
20
21
  transaction.authorizationAmount.toFixed(2) === expectedAmount.toFixed(2) &&
@@ -26,7 +27,7 @@ export const transactionIsPaid = async (
26
27
 
27
28
  export const orderIsPaid = async (
28
29
  order: Order,
29
- transaction: Transaction,
30
+ transaction: pf.PostFinanceCheckout.model.Transaction,
30
31
  orderModule: OrdersModule,
31
32
  ): Promise<boolean> => {
32
33
  const pricing = orderModule.pricingSheet(order);
@@ -10,7 +10,7 @@ Test Webhooks:
10
10
 
11
11
  brew install stripe/stripe-cli/stripe
12
12
  stripe login --api-key sk_....
13
- stripe listen --forward-to http://localhost:3000/payment/stripe
13
+ stripe listen --forward-to http://localhost:4010/payment/stripe
14
14
  stripe trigger payment_intent.succeeded
15
15
  */
16
16
 
@@ -25,6 +25,8 @@ const {
25
25
  STRIPE_WEBHOOK_PATH = '/payment/stripe',
26
26
  } = process.env;
27
27
 
28
+ // eslint-disable-next-line
29
+ // @ts-ignore
28
30
  const stripe = createStripeClient(STRIPE_SECRET);
29
31
 
30
32
  export default (app) => {
@@ -1,4 +1,4 @@
1
- import { IPaymentAdapter } from '@unchainedshop/types/payments';
1
+ import { IPaymentAdapter, PaymentChargeActionResult } from '@unchainedshop/types/payments';
2
2
  import { PaymentAdapter, PaymentDirector, PaymentError } from '@unchainedshop/core-payment';
3
3
  import { PaymentPageInitializeInput, SaferpayClient } from './worldline-saferpay-client';
4
4
 
@@ -103,13 +103,16 @@ const WordlineSaferpay: IPaymentAdapter = {
103
103
  RequestHeader: saferpayClient.buildRequestHeader(orderPayment._id, 0),
104
104
  Token: transactionId,
105
105
  });
106
- return (
106
+ const success =
107
107
  !paymentPageAssert.ErrorMessage &&
108
108
  paymentPageAssert.Transaction.Amount.Value === totalAmount.toString() &&
109
109
  paymentPageAssert.Transaction.Amount.CurrencyCode === order.currency &&
110
110
  (paymentPageAssert.Transaction.Status === 'AUTHORIZED' ||
111
- paymentPageAssert.Transaction.Status === 'CAPTURED')
112
- );
111
+ paymentPageAssert.Transaction.Status === 'CAPTURED');
112
+ if (success) {
113
+ return paymentPageAssert.Transaction as PaymentChargeActionResult;
114
+ }
115
+ return false;
113
116
  },
114
117
 
115
118
  cancel: async () => {
File without changes
@@ -1,4 +1,3 @@
1
- import moment from 'moment';
2
1
  import { DeliveryPricingAdapter, DeliveryPricingDirector } from '@unchainedshop/core-delivery';
3
2
  import {
4
3
  DeliveryPricingAdapterContext,
@@ -8,11 +7,7 @@ import {
8
7
  // https://www.ch.ch/de/mehrwertsteuersatz-schweiz/
9
8
  export const SwissTaxCategories = {
10
9
  DEFAULT: {
11
- rate: (date) => {
12
- const referenceDate = moment(date);
13
- if (referenceDate.isBefore('2018-01-01')) {
14
- return 0.08;
15
- }
10
+ rate: () => {
16
11
  return 0.077;
17
12
  },
18
13
  },
@@ -31,9 +26,7 @@ export const SwissTaxCategories = {
31
26
  };
32
27
 
33
28
  const getTaxRate = (context: DeliveryPricingAdapterContext) => {
34
- const date = context.order && context.order.ordered ? new Date(context.order.ordered) : new Date();
35
-
36
- const taxCategoryFromProvider = context.deliveryProvider?.configuration?.find(({ key }) => {
29
+ const taxCategoryFromProvider = context.provider?.configuration?.find(({ key }) => {
37
30
  if (key === 'swiss-tax-category') return true;
38
31
  return null;
39
32
  })?.value;
@@ -44,7 +37,7 @@ const getTaxRate = (context: DeliveryPricingAdapterContext) => {
44
37
  if (taxCategoryFromProvider === SwissTaxCategories.SPECIAL.value) {
45
38
  return SwissTaxCategories.SPECIAL.rate();
46
39
  }
47
- return SwissTaxCategories.DEFAULT.rate(date);
40
+ return SwissTaxCategories.DEFAULT.rate();
48
41
  };
49
42
 
50
43
  const isDeliveryAddressInSwitzerland = ({ orderDelivery, order, country = null }) => {
@@ -20,6 +20,8 @@ export const DeliveryFreePrice: IDeliveryPricingAdapter = {
20
20
  calculate: async () => {
21
21
  pricingAdapter.resultSheet().addFee({
22
22
  amount: 0,
23
+ isTaxable: false,
24
+ isNetPrice: false,
23
25
  meta: { adapter: DeliveryFreePrice.key },
24
26
  });
25
27
  return pricingAdapter.calculate();
@@ -21,6 +21,8 @@ export const PaymentFreePrice: IPaymentPricingAdapter = {
21
21
  calculate: async () => {
22
22
  pricingAdapter.resultSheet().addFee({
23
23
  amount: 0,
24
+ isNetPrice: false,
25
+ isTaxable: false,
24
26
  meta: { adapter: PaymentFreePrice.key },
25
27
  });
26
28
  return pricingAdapter.calculate();
@@ -133,6 +133,8 @@ const OrderDiscount: IOrderPricingAdapter = {
133
133
  pricingAdapter.resultSheet().addDiscount({
134
134
  amount: discountAmount * -1,
135
135
  discountId,
136
+ isTaxable: false,
137
+ isNetPrice: false,
136
138
  meta: {
137
139
  adapter: OrderDiscount.key,
138
140
  },
@@ -91,6 +91,8 @@ const OrderItemsDiscount: IOrderPricingAdapter = {
91
91
  pricingAdapter.resultSheet().addDiscount({
92
92
  amount: discountAmount * -1,
93
93
  discountId,
94
+ isTaxable: false,
95
+ isNetPrice: false,
94
96
  meta: {
95
97
  adapter: OrderItemsDiscount.key,
96
98
  },
@@ -1,5 +1,5 @@
1
1
  import { IProductPricingAdapter } from '@unchainedshop/types/products.pricing';
2
- import fetch from 'isomorphic-unfetch';
2
+ import fetch from 'node-fetch';
3
3
  import { ProductPricingDirector, ProductPricingAdapter } from '@unchainedshop/core-products';
4
4
  import xmlJs from 'xml-js';
5
5
 
@@ -1,5 +1,5 @@
1
1
  import { IProductPricingAdapter } from '@unchainedshop/types/products.pricing';
2
- import fetch from 'isomorphic-unfetch';
2
+ import fetch from 'node-fetch';
3
3
  import { ProductPricingDirector, ProductPricingAdapter } from '@unchainedshop/core-products';
4
4
 
5
5
  import Cache from './utils/cache';
@@ -1,18 +1,12 @@
1
- import moment from 'moment';
2
1
  import { ProductPricingDirector, ProductPricingAdapter } from '@unchainedshop/core-products';
3
2
  import {
4
3
  IProductPricingAdapter,
5
4
  ProductPricingAdapterContext,
6
5
  } from '@unchainedshop/types/products.pricing';
7
6
 
8
- // https://www.ch.ch/de/mehrwertsteuersatz-schweiz/
9
7
  export const SwissTaxCategories = {
10
8
  DEFAULT: {
11
- rate: (date) => {
12
- const referenceDate = moment(date);
13
- if (referenceDate.isBefore('2018-01-01')) {
14
- return 0.08;
15
- }
9
+ rate: () => {
16
10
  return 0.077;
17
11
  },
18
12
  },
@@ -31,7 +25,6 @@ export const SwissTaxCategories = {
31
25
  };
32
26
 
33
27
  const getTaxRate = (context: ProductPricingAdapterContext) => {
34
- const date = context.order && context.order.ordered ? new Date(context.order.ordered) : new Date();
35
28
  const { product } = context;
36
29
 
37
30
  if (product.tags?.includes(SwissTaxCategories.REDUCED.tag)) {
@@ -40,7 +33,7 @@ const getTaxRate = (context: ProductPricingAdapterContext) => {
40
33
  if (product.tags?.includes(SwissTaxCategories.SPECIAL.tag)) {
41
34
  return SwissTaxCategories.SPECIAL.rate();
42
35
  }
43
- return SwissTaxCategories.DEFAULT.rate(date);
36
+ return SwissTaxCategories.DEFAULT.rate();
44
37
  };
45
38
 
46
39
  const isDeliveryAddressInSwitzerland = async ({ order, country, modules }) => {
@@ -21,11 +21,11 @@ const Store: IWarehousingAdapter = {
21
21
 
22
22
  actions: () => {
23
23
  return {
24
- isActive: async () => {
24
+ isActive() {
25
25
  return true;
26
26
  },
27
27
 
28
- configurationError: async () => {
28
+ configurationError() {
29
29
  return null;
30
30
  },
31
31
 
@@ -5,10 +5,15 @@ import { BaseAdapter } from '@unchainedshop/utils';
5
5
  import fs from 'fs';
6
6
  import JSONStream from 'JSONStream';
7
7
  import { EventIterator } from 'event-iterator';
8
+ import { UnchainedCore } from '@unchainedshop/types/core';
8
9
 
9
10
  const logger = createLogger('unchained:platform:bulk-import');
10
11
 
11
- const streamPayloadToBulkImporter = async (bulkImporter, createReadStream) => {
12
+ const streamPayloadToBulkImporter = async (
13
+ bulkImporter,
14
+ createReadStream,
15
+ unchainedAPI: UnchainedCore,
16
+ ) => {
12
17
  logger.profile(`parseAsync`, { level: LogLevel.Verbose, message: 'parseAsync' });
13
18
 
14
19
  const eventIterator = new EventIterator(
@@ -34,7 +39,7 @@ const streamPayloadToBulkImporter = async (bulkImporter, createReadStream) => {
34
39
  );
35
40
 
36
41
  for await (const event of eventIterator) { // eslint-disable-line
37
- await bulkImporter.prepare(event);
42
+ await bulkImporter.prepare(event, unchainedAPI);
38
43
  }
39
44
 
40
45
  logger.profile(`parseAsync`, { level: LogLevel.Verbose, message: 'parseAsync' });
@@ -48,7 +53,7 @@ export const BulkImportWorker: IWorkerAdapter<any, Record<string, unknown>> = {
48
53
  version: '1.0',
49
54
  type: 'BULK_IMPORT',
50
55
 
51
- doWork: async (rawPayload, context) => {
56
+ doWork: async (rawPayload, unchainedAPI) => {
52
57
  try {
53
58
  const {
54
59
  createShouldUpsertIfIDExists = false,
@@ -56,25 +61,26 @@ export const BulkImportWorker: IWorkerAdapter<any, Record<string, unknown>> = {
56
61
  authorId = 'root',
57
62
  } = rawPayload;
58
63
 
59
- const bulkImporter = context.bulkImporter.createBulkImporter(
60
- {
61
- logger,
62
- authorId,
63
- createShouldUpsertIfIDExists,
64
- skipCacheInvalidation,
65
- },
66
- context,
67
- );
64
+ const bulkImporter = unchainedAPI.bulkImporter.createBulkImporter({
65
+ logger,
66
+ authorId,
67
+ createShouldUpsertIfIDExists,
68
+ skipCacheInvalidation,
69
+ });
68
70
 
69
71
  if (rawPayload.payloadFilePath) {
70
72
  // stream payload from file system
71
- await streamPayloadToBulkImporter(bulkImporter, () =>
72
- fs.createReadStream(rawPayload.payloadFilePath),
73
+ await streamPayloadToBulkImporter(
74
+ bulkImporter,
75
+ () => fs.createReadStream(rawPayload.payloadFilePath),
76
+ unchainedAPI,
73
77
  );
74
78
  } else if (rawPayload.payloadId) {
75
79
  // stream payload from gridfs
76
- await streamPayloadToBulkImporter(bulkImporter, () =>
77
- context.bulkImporter.BulkImportPayloads.openDownloadStream(rawPayload.payloadId),
80
+ await streamPayloadToBulkImporter(
81
+ bulkImporter,
82
+ () => unchainedAPI.bulkImporter.BulkImportPayloads.openDownloadStream(rawPayload.payloadId),
83
+ unchainedAPI,
78
84
  );
79
85
  } else {
80
86
  const { events } = rawPayload;
@@ -82,12 +88,12 @@ export const BulkImportWorker: IWorkerAdapter<any, Record<string, unknown>> = {
82
88
 
83
89
  await events.reduce(async (currentEventPromise, nextEvent) => {
84
90
  await currentEventPromise;
85
- return bulkImporter.prepare(nextEvent);
91
+ return bulkImporter.prepare(nextEvent, unchainedAPI);
86
92
  }, Promise.resolve());
87
93
  }
88
94
 
89
95
  const [result, error] = await bulkImporter.execute();
90
- await bulkImporter.invalidateCaches();
96
+ await bulkImporter.invalidateCaches(unchainedAPI);
91
97
 
92
98
  if (error) {
93
99
  return {
@@ -97,7 +97,7 @@ const GenerateOrderWorker: IWorkerAdapter<any, any> = {
97
97
  await Promise.all(
98
98
  enrollments.map(async (enrollment) => {
99
99
  try {
100
- const director = await EnrollmentDirector.actions({ enrollment }, requestContext);
100
+ const director = await EnrollmentDirector.actions({ enrollment }, requestContext as Context); // TODO: Type Refactor
101
101
  const period = await director.nextPeriod();
102
102
  if (period) {
103
103
  const configuration = await director.configurationForOrder({
@@ -105,7 +105,7 @@ const GenerateOrderWorker: IWorkerAdapter<any, any> = {
105
105
  period,
106
106
  });
107
107
  if (configuration) {
108
- const order = await generateOrder(enrollment, configuration, requestContext);
108
+ const order = await generateOrder(enrollment, configuration, requestContext as Context); // TODO: Type Refactor
109
109
  if (order) {
110
110
  await modules.enrollments.addEnrollmentPeriod(enrollment._id, {
111
111
  ...period,
@@ -2,6 +2,7 @@ import { IWorkerAdapter, Work } from '@unchainedshop/types/worker';
2
2
  import { MessagingDirector } from '@unchainedshop/core-messaging';
3
3
  import { WorkerAdapter, WorkerDirector } from '@unchainedshop/core-worker';
4
4
  import { createLogger } from '@unchainedshop/logger';
5
+ import { Context } from '@unchainedshop/types/api';
5
6
 
6
7
  export const messagingLogger = createLogger('unchained:core-messaging');
7
8
 
@@ -25,7 +26,7 @@ export const MessageWorker: IWorkerAdapter<
25
26
  template,
26
27
  ...payload,
27
28
  },
28
- requestContext,
29
+ requestContext as Context, // TODO: Type Refactor
29
30
  );
30
31
 
31
32
  if (workConfigurations.length > 0) {
@@ -36,7 +37,7 @@ export const MessageWorker: IWorkerAdapter<
36
37
  ...workConfiguration,
37
38
  originalWorkId: workId,
38
39
  },
39
- requestContext.userId,
40
+ null,
40
41
  );
41
42
  delete work.input;
42
43
  return work;
@@ -60,7 +60,7 @@ const EmailWorkerPlugin: IWorkerAdapter<
60
60
  subject?: string;
61
61
  [x: string]: any;
62
62
  },
63
- void
63
+ any
64
64
  > = {
65
65
  ...WorkerAdapter,
66
66
 
@@ -94,6 +94,9 @@ const EmailWorkerPlugin: IWorkerAdapter<
94
94
  openInBrowser(sendMailOptions);
95
95
  return { success: true, result: { intercepted: true } };
96
96
  }
97
+ if (!process.env.MAIL_URL) {
98
+ return { success: false, error: { name: 'NO_MAIL_URL_SET', message: 'MAIL_URL is not set' } };
99
+ }
97
100
  const transporter = nodemailer.createTransport(process.env.MAIL_URL);
98
101
  const result = await transporter.sendMail(sendMailOptions);
99
102
  return { success: true, result };
@@ -1,5 +1,5 @@
1
1
  import { IWorkerAdapter } from '@unchainedshop/types/worker';
2
- import fetch from 'isomorphic-unfetch';
2
+ import fetch from 'node-fetch';
3
3
  import { WorkerDirector, WorkerAdapter } from '@unchainedshop/core-worker';
4
4
  import { log, LogLevel } from '@unchainedshop/logger';
5
5
 
package/tsconfig.json CHANGED
@@ -6,6 +6,7 @@
6
6
  "esModuleInterop": true,
7
7
  "experimentalDecorators": true,
8
8
  "forceConsistentCasingInFileNames": true,
9
+ "rootDir": "src",
9
10
  "lib": [
10
11
  "esnext"
11
12
  ],
@@ -21,8 +22,16 @@
21
22
  "types": [
22
23
  "node",
23
24
  "jest"
24
- ]
25
+ ],
26
+ "paths": {
27
+ "postfinancecheckout": [
28
+ "./src/payment/postfinance-checkout/silence-postfinancecheckout.d.ts"
29
+ ],
30
+ }
25
31
  },
32
+ // "exclude": [
33
+ // "./src/payment/postfinance-checkout/*"
34
+ // ],
26
35
  "include": [
27
36
  "src"
28
37
  ]