@unchainedshop/core 3.1.13 → 4.0.0-rc.3

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 (205) hide show
  1. package/lib/directors/BaseDiscountAdapter.js +0 -1
  2. package/lib/directors/BaseDiscountAdapter.js.map +1 -1
  3. package/lib/directors/BaseDiscountDirector.d.ts +1 -1
  4. package/lib/directors/BaseDiscountDirector.d.ts.map +1 -1
  5. package/lib/directors/BasePricingAdapter.d.ts +4 -4
  6. package/lib/directors/BasePricingAdapter.d.ts.map +1 -1
  7. package/lib/directors/BasePricingDirector.d.ts +2 -2
  8. package/lib/directors/BasePricingDirector.d.ts.map +1 -1
  9. package/lib/directors/BasePricingDirector.js.map +1 -1
  10. package/lib/directors/BasePricingSheet.d.ts +10 -10
  11. package/lib/directors/BasePricingSheet.d.ts.map +1 -1
  12. package/lib/directors/BasePricingSheet.js +2 -2
  13. package/lib/directors/BasePricingSheet.js.map +1 -1
  14. package/lib/directors/DeliveryAdapter.d.ts +2 -2
  15. package/lib/directors/DeliveryAdapter.d.ts.map +1 -1
  16. package/lib/directors/DeliveryDirector.d.ts.map +1 -1
  17. package/lib/directors/DeliveryDirector.js +1 -3
  18. package/lib/directors/DeliveryDirector.js.map +1 -1
  19. package/lib/directors/DeliveryPricingAdapter.d.ts +3 -3
  20. package/lib/directors/DeliveryPricingAdapter.d.ts.map +1 -1
  21. package/lib/directors/DeliveryPricingAdapter.js +2 -2
  22. package/lib/directors/DeliveryPricingAdapter.js.map +1 -1
  23. package/lib/directors/DeliveryPricingDirector.d.ts +3 -3
  24. package/lib/directors/DeliveryPricingDirector.d.ts.map +1 -1
  25. package/lib/directors/DeliveryPricingDirector.js +6 -6
  26. package/lib/directors/DeliveryPricingDirector.js.map +1 -1
  27. package/lib/directors/DeliveryPricingSheet.js +2 -2
  28. package/lib/directors/DeliveryPricingSheet.js.map +1 -1
  29. package/lib/directors/EnrollmentAdapter.d.ts +3 -3
  30. package/lib/directors/EnrollmentAdapter.d.ts.map +1 -1
  31. package/lib/directors/EnrollmentAdapter.js.map +1 -1
  32. package/lib/directors/FilterAdapter.d.ts +9 -12
  33. package/lib/directors/FilterAdapter.d.ts.map +1 -1
  34. package/lib/directors/FilterAdapter.js +0 -4
  35. package/lib/directors/FilterAdapter.js.map +1 -1
  36. package/lib/directors/FilterDirector.d.ts +9 -9
  37. package/lib/directors/FilterDirector.d.ts.map +1 -1
  38. package/lib/directors/FilterDirector.js.map +1 -1
  39. package/lib/directors/MessagingDirector.d.ts +11 -15
  40. package/lib/directors/MessagingDirector.d.ts.map +1 -1
  41. package/lib/directors/OrderPricingAdapter.d.ts +3 -3
  42. package/lib/directors/OrderPricingAdapter.d.ts.map +1 -1
  43. package/lib/directors/OrderPricingAdapter.js +2 -2
  44. package/lib/directors/OrderPricingAdapter.js.map +1 -1
  45. package/lib/directors/OrderPricingDirector.d.ts +2 -2
  46. package/lib/directors/OrderPricingDirector.d.ts.map +1 -1
  47. package/lib/directors/OrderPricingDirector.js +4 -4
  48. package/lib/directors/OrderPricingDirector.js.map +1 -1
  49. package/lib/directors/OrderPricingSheet.js +2 -2
  50. package/lib/directors/OrderPricingSheet.js.map +1 -1
  51. package/lib/directors/PaymentAdapter.d.ts +2 -2
  52. package/lib/directors/PaymentAdapter.d.ts.map +1 -1
  53. package/lib/directors/PaymentPricingAdapter.d.ts +2 -2
  54. package/lib/directors/PaymentPricingAdapter.d.ts.map +1 -1
  55. package/lib/directors/PaymentPricingAdapter.js +2 -2
  56. package/lib/directors/PaymentPricingAdapter.js.map +1 -1
  57. package/lib/directors/PaymentPricingDirector.d.ts +3 -3
  58. package/lib/directors/PaymentPricingDirector.d.ts.map +1 -1
  59. package/lib/directors/PaymentPricingDirector.js +6 -6
  60. package/lib/directors/PaymentPricingDirector.js.map +1 -1
  61. package/lib/directors/PaymentPricingSheet.js +1 -1
  62. package/lib/directors/PaymentPricingSheet.js.map +1 -1
  63. package/lib/directors/ProductDiscountConfiguration.d.ts +1 -1
  64. package/lib/directors/ProductDiscountConfiguration.d.ts.map +1 -1
  65. package/lib/directors/ProductPricingAdapter.d.ts +3 -3
  66. package/lib/directors/ProductPricingAdapter.d.ts.map +1 -1
  67. package/lib/directors/ProductPricingAdapter.js +2 -2
  68. package/lib/directors/ProductPricingAdapter.js.map +1 -1
  69. package/lib/directors/ProductPricingDirector.d.ts +5 -5
  70. package/lib/directors/ProductPricingDirector.d.ts.map +1 -1
  71. package/lib/directors/ProductPricingDirector.js +6 -6
  72. package/lib/directors/ProductPricingDirector.js.map +1 -1
  73. package/lib/directors/ProductPricingSheet.js +2 -2
  74. package/lib/directors/ProductPricingSheet.js.map +1 -1
  75. package/lib/directors/QuotationAdapter.d.ts +2 -2
  76. package/lib/directors/QuotationAdapter.d.ts.map +1 -1
  77. package/lib/directors/WarehousingAdapter.d.ts +3 -3
  78. package/lib/directors/WarehousingAdapter.d.ts.map +1 -1
  79. package/lib/directors/WarehousingDirector.d.ts +3 -3
  80. package/lib/directors/WarehousingDirector.d.ts.map +1 -1
  81. package/lib/directors/WorkerDirector.d.ts +2 -2
  82. package/lib/directors/WorkerDirector.d.ts.map +1 -1
  83. package/lib/directors/index.d.ts +4 -0
  84. package/lib/directors/index.d.ts.map +1 -1
  85. package/lib/directors/index.js +4 -0
  86. package/lib/directors/index.js.map +1 -1
  87. package/lib/services/calculateDiscountTotal.d.ts +1 -1
  88. package/lib/services/calculateDiscountTotal.js +5 -5
  89. package/lib/services/calculateDiscountTotal.js.map +1 -1
  90. package/lib/services/createEnrollmentFromCheckout.d.ts +3 -3
  91. package/lib/services/createEnrollmentFromCheckout.d.ts.map +1 -1
  92. package/lib/services/createEnrollmentFromCheckout.js +1 -1
  93. package/lib/services/createEnrollmentFromCheckout.js.map +1 -1
  94. package/lib/services/discountedEntities.d.ts +1 -1
  95. package/lib/services/discountedEntities.d.ts.map +1 -1
  96. package/lib/services/discountedEntities.js +4 -4
  97. package/lib/services/discountedEntities.js.map +1 -1
  98. package/lib/services/ercMetadata.d.ts +5 -3
  99. package/lib/services/ercMetadata.d.ts.map +1 -1
  100. package/lib/services/ercMetadata.js +2 -11
  101. package/lib/services/ercMetadata.js.map +1 -1
  102. package/lib/services/index.d.ts +1 -3
  103. package/lib/services/index.d.ts.map +1 -1
  104. package/lib/services/index.js.map +1 -1
  105. package/lib/services/loadFilters.d.ts +1 -1
  106. package/lib/services/loadFilters.d.ts.map +1 -1
  107. package/lib/services/loadFilters.js.map +1 -1
  108. package/lib/services/migrateBookmarks.d.ts +1 -1
  109. package/lib/services/migrateBookmarks.d.ts.map +1 -1
  110. package/lib/services/migrateOrderCart.d.ts +2 -2
  111. package/lib/services/migrateOrderCart.d.ts.map +1 -1
  112. package/lib/services/migrateOrderCart.js +3 -3
  113. package/lib/services/migrateOrderCart.js.map +1 -1
  114. package/lib/services/migrateUserData.js +2 -2
  115. package/lib/services/migrateUserData.js.map +1 -1
  116. package/lib/services/nextUserCart.js +2 -2
  117. package/lib/services/nextUserCart.js.map +1 -1
  118. package/lib/services/processOrder.d.ts.map +1 -1
  119. package/lib/services/processOrder.js +1 -3
  120. package/lib/services/processOrder.js.map +1 -1
  121. package/lib/services/removeFiles.d.ts +1 -1
  122. package/lib/services/removeFiles.d.ts.map +1 -1
  123. package/lib/services/removeFiles.js +1 -1
  124. package/lib/services/removeFiles.js.map +1 -1
  125. package/lib/services/searchProducts.d.ts.map +1 -1
  126. package/lib/services/searchProducts.js +1 -2
  127. package/lib/services/searchProducts.js.map +1 -1
  128. package/lib/services/simulateProductDispatching.d.ts +1 -3
  129. package/lib/services/simulateProductDispatching.d.ts.map +1 -1
  130. package/lib/services/simulateProductDispatching.js +2 -1
  131. package/lib/services/simulateProductDispatching.js.map +1 -1
  132. package/lib/services/simulateProductInventory.d.ts +1 -3
  133. package/lib/services/simulateProductInventory.d.ts.map +1 -1
  134. package/lib/services/simulateProductInventory.js +2 -1
  135. package/lib/services/simulateProductInventory.js.map +1 -1
  136. package/lib/services/simulateProductPricing.d.ts +3 -3
  137. package/lib/services/simulateProductPricing.d.ts.map +1 -1
  138. package/lib/services/supportedDeliveryProviders.js +1 -1
  139. package/lib/services/supportedDeliveryProviders.js.map +1 -1
  140. package/lib/services/supportedPaymentProviders.js +1 -1
  141. package/lib/services/supportedPaymentProviders.js.map +1 -1
  142. package/lib/services/supportedWarehousingProviders.js +1 -1
  143. package/lib/services/supportedWarehousingProviders.js.map +1 -1
  144. package/lib/services/updateCalculation.d.ts.map +1 -1
  145. package/lib/services/updateCalculation.js +4 -5
  146. package/lib/services/updateCalculation.js.map +1 -1
  147. package/lib/services/updateScheduling.js +1 -1
  148. package/lib/services/updateScheduling.js.map +1 -1
  149. package/package.json +21 -20
  150. package/src/directors/BaseDiscountAdapter.ts +1 -1
  151. package/src/directors/BaseDiscountDirector.ts +1 -1
  152. package/src/directors/BasePricingAdapter.ts +4 -4
  153. package/src/directors/BasePricingDirector.ts +4 -10
  154. package/src/directors/BasePricingSheet.ts +12 -12
  155. package/src/directors/BaseWorker.ts +117 -0
  156. package/src/directors/DeliveryAdapter.ts +2 -2
  157. package/src/directors/DeliveryDirector.ts +1 -3
  158. package/src/directors/DeliveryPricingAdapter.ts +5 -5
  159. package/src/directors/DeliveryPricingDirector.ts +9 -9
  160. package/src/directors/DeliveryPricingSheet.ts +2 -2
  161. package/src/directors/EnrollmentAdapter.ts +3 -6
  162. package/src/directors/EventListenerWorker.ts +101 -0
  163. package/src/directors/FailedRescheduler.ts +73 -0
  164. package/src/directors/FilterAdapter.ts +11 -11
  165. package/src/directors/FilterDirector.ts +16 -16
  166. package/src/directors/IntervalWorker.ts +75 -0
  167. package/src/directors/MessagingDirector.ts +10 -10
  168. package/src/directors/OrderPricingAdapter.ts +5 -5
  169. package/src/directors/OrderPricingDirector.ts +6 -6
  170. package/src/directors/OrderPricingSheet.ts +2 -2
  171. package/src/directors/PaymentAdapter.ts +2 -2
  172. package/src/directors/PaymentPricingAdapter.ts +4 -4
  173. package/src/directors/PaymentPricingDirector.ts +9 -9
  174. package/src/directors/PaymentPricingSheet.ts +1 -1
  175. package/src/directors/ProductDiscountConfiguration.ts +1 -1
  176. package/src/directors/ProductPricingAdapter.ts +5 -5
  177. package/src/directors/ProductPricingDirector.ts +11 -11
  178. package/src/directors/ProductPricingSheet.test.ts +22 -13
  179. package/src/directors/ProductPricingSheet.ts +2 -2
  180. package/src/directors/QuotationAdapter.ts +2 -2
  181. package/src/directors/WarehousingAdapter.ts +3 -3
  182. package/src/directors/WarehousingDirector.ts +3 -3
  183. package/src/directors/WorkerDirector.ts +2 -2
  184. package/src/directors/index.ts +4 -0
  185. package/src/services/calculateDiscountTotal.ts +5 -5
  186. package/src/services/createEnrollmentFromCheckout.ts +4 -4
  187. package/src/services/discountedEntities.ts +5 -5
  188. package/src/services/ercMetadata.ts +6 -14
  189. package/src/services/index.ts +1 -3
  190. package/src/services/loadFilters.ts +1 -1
  191. package/src/services/migrateBookmarks.ts +1 -1
  192. package/src/services/migrateOrderCart.ts +4 -4
  193. package/src/services/migrateUserData.ts +2 -2
  194. package/src/services/nextUserCart.ts +2 -2
  195. package/src/services/processOrder.ts +4 -3
  196. package/src/services/removeFiles.ts +2 -2
  197. package/src/services/searchProducts.ts +1 -3
  198. package/src/services/simulateProductDispatching.ts +3 -4
  199. package/src/services/simulateProductInventory.ts +3 -4
  200. package/src/services/simulateProductPricing.ts +3 -3
  201. package/src/services/supportedDeliveryProviders.ts +1 -1
  202. package/src/services/supportedPaymentProviders.ts +1 -1
  203. package/src/services/supportedWarehousingProviders.ts +1 -1
  204. package/src/services/updateCalculation.ts +4 -5
  205. package/src/services/updateScheduling.ts +2 -2
@@ -0,0 +1,75 @@
1
+ import later, { ScheduleData } from '@breejs/later';
2
+ import { BaseWorker, IWorker } from './BaseWorker.js';
3
+ import { createLogger } from '@unchainedshop/logger';
4
+
5
+ const { NODE_ENV } = process.env;
6
+
7
+ const logger = createLogger('unchained:worker');
8
+
9
+ export interface IntervalWorkerParams {
10
+ workerId?: string;
11
+ batchCount?: number;
12
+ schedule?: ScheduleData;
13
+ }
14
+
15
+ const defaultSchedule = later.parse.text(
16
+ NODE_ENV !== 'production' ? 'every 2 seconds' : 'every 30 seconds',
17
+ );
18
+
19
+ export const scheduleToInterval = (schedule: ScheduleData) => {
20
+ const referenceDate = new Date(1000);
21
+ const nextDates = later.schedule(schedule).next(2, referenceDate) as Date[];
22
+
23
+ if (!nextDates || nextDates.length < 2) {
24
+ throw new Error('Schedule must produce at least 2 consecutive dates');
25
+ }
26
+
27
+ const [one, two] = nextDates;
28
+ const diff = new Date(two).getTime() - new Date(one).getTime();
29
+ return Math.min(1000 * 60 * 60, diff); // at least once every hour!
30
+ };
31
+
32
+ export const IntervalWorker: IWorker<IntervalWorkerParams> = {
33
+ ...BaseWorker,
34
+
35
+ key: 'shop.unchained.worker.cron',
36
+ label: 'Allocates work on fixed intervals with native node setInterval',
37
+ version: '1.0.0',
38
+ type: 'CRON',
39
+
40
+ actions: ({ workerId, batchCount = 10, schedule = defaultSchedule }, unchainedAPI) => {
41
+ const baseWorkerActions = BaseWorker.actions({ workerId, worker: IntervalWorker }, unchainedAPI);
42
+
43
+ const intervalDelay = scheduleToInterval(schedule);
44
+ let intervalHandle: NodeJS.Timeout | null = null;
45
+
46
+ return {
47
+ ...baseWorkerActions,
48
+
49
+ start() {
50
+ // Prevent multiple intervals from running
51
+ if (intervalHandle) {
52
+ return;
53
+ }
54
+
55
+ intervalHandle = setInterval(async () => {
56
+ try {
57
+ await baseWorkerActions.process({
58
+ maxWorkItemCount: batchCount,
59
+ referenceDate: IntervalWorker.getFloorDate(),
60
+ });
61
+ } catch (error) {
62
+ logger.error(error);
63
+ }
64
+ }, intervalDelay);
65
+ },
66
+
67
+ stop() {
68
+ if (intervalHandle) {
69
+ clearInterval(intervalHandle);
70
+ intervalHandle = null;
71
+ }
72
+ },
73
+ };
74
+ },
75
+ };
@@ -1,4 +1,4 @@
1
- export type EmailTemplateType = {
1
+ export interface EmailTemplateType {
2
2
  type: 'EMAIL';
3
3
  input: {
4
4
  from: string;
@@ -7,7 +7,7 @@ export type EmailTemplateType = {
7
7
  subject: string;
8
8
  text: string;
9
9
  html?: string;
10
- attachments?: Array<
10
+ attachments?: (
11
11
  | { filename: string; path: string }
12
12
  | {
13
13
  filename: string;
@@ -16,28 +16,28 @@ export type EmailTemplateType = {
16
16
  encoding: string;
17
17
  }
18
18
  | { href: string; filename: string }
19
- >;
19
+ )[];
20
20
  };
21
- };
21
+ }
22
22
 
23
- export type SMSTemplateType = {
23
+ export interface SMSTemplateType {
24
24
  type: 'SMS';
25
25
  input: {
26
26
  from: string;
27
27
  to: string;
28
28
  text: string;
29
29
  };
30
- };
30
+ }
31
31
 
32
- export type ArbitraryTemplateType = {
32
+ export interface ArbitraryTemplateType {
33
33
  type: string;
34
34
  input: any;
35
- };
35
+ }
36
36
 
37
- export type TemplateResolver<T = { [x: string]: any }> = (
37
+ export type TemplateResolver<T = Record<string, any>> = (
38
38
  params: { template: string } & T,
39
39
  unchainedAPI,
40
- ) => Promise<Array<EmailTemplateType | SMSTemplateType | ArbitraryTemplateType>>;
40
+ ) => Promise<(EmailTemplateType | SMSTemplateType | ArbitraryTemplateType)[]>;
41
41
 
42
42
  const TemplateResolvers = new Map<string, TemplateResolver>();
43
43
 
@@ -17,11 +17,11 @@ import { User } from '@unchainedshop/core-users';
17
17
  import { Modules } from '../modules.js';
18
18
 
19
19
  export interface OrderPricingAdapterContext extends BasePricingAdapterContext {
20
- currency?: string;
21
- discounts: Array<OrderDiscount>;
20
+ currencyCode?: string;
21
+ discounts: OrderDiscount[];
22
22
  order: Order;
23
23
  orderDelivery: OrderDelivery;
24
- orderPositions: Array<OrderPosition>;
24
+ orderPositions: OrderPosition[];
25
25
  orderPayment: OrderPayment;
26
26
  user: User;
27
27
  }
@@ -44,9 +44,9 @@ export const OrderPricingAdapter: IOrderPricingAdapter = {
44
44
 
45
45
  actions: (params) => {
46
46
  const { context } = params;
47
- const { currency } = context;
47
+ const { currencyCode } = context;
48
48
  const baseActions = basePricingAdapter.actions(params);
49
- const resultSheet = OrderPricingSheet({ currency });
49
+ const resultSheet = OrderPricingSheet({ currencyCode });
50
50
 
51
51
  return {
52
52
  ...baseActions,
@@ -11,10 +11,10 @@ import {
11
11
  import { Order, OrderDelivery, OrderPayment, OrderPosition } from '@unchainedshop/core-orders';
12
12
 
13
13
  export interface OrderPricingContext {
14
- currency: string;
14
+ currencyCode: string;
15
15
  order: Order;
16
16
  orderDelivery: OrderDelivery;
17
- orderPositions: Array<OrderPosition>;
17
+ orderPositions: OrderPosition[];
18
18
  orderPayment: OrderPayment;
19
19
  }
20
20
 
@@ -45,7 +45,7 @@ export const OrderPricingDirector: IOrderPricingDirector<any> = {
45
45
 
46
46
  buildPricingContext: async (context, unchainedAPI) => {
47
47
  const { modules } = unchainedAPI;
48
- const { order, currency } = context;
48
+ const { order, currencyCode } = context;
49
49
 
50
50
  const user = await modules.users.findUserById(order.userId);
51
51
  const discounts = await modules.orders.discounts.findOrderDiscounts({
@@ -54,8 +54,8 @@ export const OrderPricingDirector: IOrderPricingDirector<any> = {
54
54
 
55
55
  return {
56
56
  ...unchainedAPI,
57
- country: order.countryCode,
58
- currency,
57
+ countryCode: order.countryCode,
58
+ currencyCode,
59
59
  discounts,
60
60
  order,
61
61
  orderDelivery: context.orderDelivery,
@@ -68,7 +68,7 @@ export const OrderPricingDirector: IOrderPricingDirector<any> = {
68
68
  calculationSheet(pricingContext, calculation) {
69
69
  return OrderPricingSheet({
70
70
  calculation,
71
- currency: pricingContext.currency,
71
+ currencyCode: pricingContext.currencyCode,
72
72
  });
73
73
  },
74
74
  };
@@ -112,7 +112,7 @@ export const OrderPricingSheet = (
112
112
 
113
113
  return {
114
114
  amount: Math.round(useNetPrice ? netAmount : netAmount + taxAmount),
115
- currency: this.currency,
115
+ currencyCode: this.currencyCode,
116
116
  };
117
117
  },
118
118
 
@@ -136,7 +136,7 @@ export const OrderPricingSheet = (
136
136
  return {
137
137
  discountId,
138
138
  amount: Math.round(amount),
139
- currency: basePricingSheet.currency,
139
+ currencyCode: basePricingSheet.currencyCode,
140
140
  };
141
141
  })
142
142
  .filter(Boolean);
@@ -10,10 +10,10 @@ export enum PaymentError {
10
10
  WRONG_CREDENTIALS = 'WRONG_CREDENTIALS',
11
11
  }
12
12
 
13
- export type ChargeResult = {
13
+ export interface ChargeResult {
14
14
  transactionId?: string;
15
15
  [key: string]: any;
16
- };
16
+ }
17
17
 
18
18
  export type PaymentChargeActionResult = ChargeResult & {
19
19
  credentials?: {
@@ -18,13 +18,13 @@ export interface PaymentPricingCalculation extends PricingCalculation {
18
18
  rate?: number;
19
19
  }
20
20
  export interface PaymentPricingAdapterContext extends BasePricingAdapterContext {
21
- country?: string;
21
+ countryCode?: string;
22
22
  currency?: string;
23
23
  user: User;
24
24
  orderPayment: OrderPayment;
25
25
  order: Order;
26
26
  provider: PaymentProvider;
27
- discounts: Array<OrderDiscount>;
27
+ discounts: OrderDiscount[];
28
28
  }
29
29
 
30
30
  export type IPaymentPricingSheet = IPricingSheet<PaymentPricingCalculation> & {
@@ -67,9 +67,9 @@ export const PaymentPricingAdapter: IPricingAdapter<
67
67
 
68
68
  actions: (params) => {
69
69
  const { context } = params;
70
- const { currency } = context.order;
70
+ const { currencyCode } = context.order;
71
71
  const baseActions = basePricingAdapter.actions(params);
72
- const resultSheet = PaymentPricingSheet({ currency });
72
+ const resultSheet = PaymentPricingSheet({ currencyCode });
73
73
 
74
74
  return {
75
75
  ...baseActions,
@@ -13,15 +13,15 @@ import { User } from '@unchainedshop/core-users';
13
13
 
14
14
  export type PaymentPricingContext =
15
15
  | {
16
- country?: string;
17
- currency?: string;
16
+ countryCode?: string;
17
+ currencyCode?: string;
18
18
  user: User;
19
19
  order: Order;
20
20
  provider: PaymentProvider;
21
21
  providerContext?: any;
22
22
  }
23
23
  | {
24
- currency: string;
24
+ currencyCode: string;
25
25
  item: OrderPayment;
26
26
  };
27
27
 
@@ -47,7 +47,7 @@ export const PaymentPricingDirector: IPaymentPricingDirector<any> = {
47
47
  const { modules } = unchainedAPI;
48
48
 
49
49
  if ('item' in context) {
50
- const { item, currency } = context;
50
+ const { item, currencyCode } = context;
51
51
  const order = await modules.orders.findOrder({
52
52
  orderId: item.orderId,
53
53
  });
@@ -61,8 +61,8 @@ export const PaymentPricingDirector: IPaymentPricingDirector<any> = {
61
61
 
62
62
  return {
63
63
  ...unchainedAPI,
64
- country: order.countryCode,
65
- currency,
64
+ countryCode: order.countryCode,
65
+ currencyCode,
66
66
  order,
67
67
  provider,
68
68
  user,
@@ -74,8 +74,8 @@ export const PaymentPricingDirector: IPaymentPricingDirector<any> = {
74
74
 
75
75
  return {
76
76
  ...unchainedAPI,
77
- country: context.country,
78
- currency: context.currency,
77
+ countryCode: context.countryCode,
78
+ currencyCode: context.currencyCode,
79
79
  order: context.order,
80
80
  provider: context.provider,
81
81
  user: context.user,
@@ -88,7 +88,7 @@ export const PaymentPricingDirector: IPaymentPricingDirector<any> = {
88
88
  calculationSheet(pricingContext, calculation) {
89
89
  return PaymentPricingSheet({
90
90
  calculation,
91
- currency: pricingContext.currency,
91
+ currencyCode: pricingContext.currencyCode,
92
92
  });
93
93
  },
94
94
  };
@@ -80,7 +80,7 @@ export const PaymentPricingSheet = (
80
80
  return {
81
81
  discountId,
82
82
  amount: Math.round(amount),
83
- currency: basePricingSheet.currency,
83
+ currencyCode: basePricingSheet.currencyCode,
84
84
  };
85
85
  })
86
86
  .filter(Boolean);
@@ -10,7 +10,7 @@ type ResolvedConfiguration = {
10
10
  export type PriceConfigurationResolver = (
11
11
  product: Product,
12
12
  quantity: number,
13
- configuration: Array<ProductConfiguration>,
13
+ configuration: ProductConfiguration[],
14
14
  ) => ResolvedConfiguration | null;
15
15
 
16
16
  export interface ProductDiscountConfiguration extends ResolvedConfiguration {
@@ -12,11 +12,11 @@ import { Modules } from '../modules.js';
12
12
  import { User } from '@unchainedshop/core-users';
13
13
 
14
14
  export interface ProductPricingAdapterContext extends BasePricingAdapterContext {
15
- country: string;
16
- currency: string;
15
+ countryCode: string;
16
+ currencyCode: string;
17
17
  product: Product;
18
18
  quantity: number;
19
- configuration: Array<ProductConfiguration>;
19
+ configuration: ProductConfiguration[];
20
20
  order?: Order;
21
21
  user?: User;
22
22
  }
@@ -39,9 +39,9 @@ export const ProductPricingAdapter: IProductPricingAdapter = {
39
39
 
40
40
  actions: (params) => {
41
41
  const { context } = params;
42
- const { currency, quantity } = context;
42
+ const { currencyCode, quantity } = context;
43
43
  const baseActions = basePricingAdapter.actions(params);
44
- const resultSheet = ProductPricingSheet({ currency, quantity });
44
+ const resultSheet = ProductPricingSheet({ currencyCode, quantity });
45
45
 
46
46
  return {
47
47
  ...baseActions,
@@ -13,17 +13,17 @@ import {
13
13
 
14
14
  export type ProductPricingContext =
15
15
  | {
16
- currency: string;
16
+ currencyCode: string;
17
+ countryCode: string;
17
18
  quantity: number;
18
- country?: string;
19
- discounts?: Array<OrderDiscount>;
19
+ discounts?: OrderDiscount[];
20
20
  order?: Order;
21
21
  product?: Product;
22
- configuration?: Array<ProductConfiguration>;
22
+ configuration?: ProductConfiguration[];
23
23
  user?: User;
24
24
  }
25
25
  | {
26
- currency: string;
26
+ currencyCode: string;
27
27
  quantity: number;
28
28
  item: OrderPosition;
29
29
  };
@@ -48,7 +48,7 @@ export const ProductPricingDirector: IProductPricingDirector<any> = {
48
48
 
49
49
  async buildPricingContext(context, unchainedAPI) {
50
50
  const { modules } = unchainedAPI;
51
- const { quantity = 1, currency } = context;
51
+ const { quantity = 1, currencyCode } = context;
52
52
 
53
53
  if ('item' in context) {
54
54
  const { item } = context;
@@ -66,8 +66,8 @@ export const ProductPricingDirector: IProductPricingDirector<any> = {
66
66
 
67
67
  return {
68
68
  ...unchainedAPI,
69
- country: order.countryCode,
70
- currency,
69
+ countryCode: order.countryCode,
70
+ currencyCode,
71
71
  discounts,
72
72
  order,
73
73
  product,
@@ -79,8 +79,8 @@ export const ProductPricingDirector: IProductPricingDirector<any> = {
79
79
 
80
80
  return {
81
81
  ...unchainedAPI,
82
- country: context.country,
83
- currency,
82
+ countryCode: context.countryCode,
83
+ currencyCode,
84
84
  discounts: [],
85
85
  order: context.order,
86
86
  product: context.product,
@@ -93,7 +93,7 @@ export const ProductPricingDirector: IProductPricingDirector<any> = {
93
93
  calculationSheet(pricingContext, calculation) {
94
94
  return ProductPricingSheet({
95
95
  calculation,
96
- currency: pricingContext.currency,
96
+ currencyCode: pricingContext.currencyCode,
97
97
  quantity: pricingContext.quantity ?? 1,
98
98
  });
99
99
  },
@@ -34,7 +34,7 @@ describe('ProductPricingSheet', () => {
34
34
 
35
35
  const pricingSheetParams = {
36
36
  calculation: calculations,
37
- currency: 'CHF',
37
+ currencyCode: 'CHF',
38
38
  quantity: 2,
39
39
  };
40
40
  beforeEach(() => {
@@ -44,7 +44,7 @@ describe('ProductPricingSheet', () => {
44
44
  it('should return an object that implements the IProductPricingSheet interface', () => {
45
45
  assert(pricingSheet);
46
46
  assert.equal(pricingSheet.quantity, 2);
47
- assert.equal(pricingSheet.currency, 'CHF');
47
+ assert.equal(pricingSheet.currencyCode, 'CHF');
48
48
  assert.equal(typeof pricingSheet.addItem, 'function');
49
49
  assert.equal(typeof pricingSheet.addDiscount, 'function');
50
50
  assert.equal(typeof pricingSheet.addTax, 'function');
@@ -63,22 +63,25 @@ describe('ProductPricingSheet', () => {
63
63
 
64
64
  describe('total()', () => {
65
65
  it('should return sum of all ProductPricingCalculations ', () => {
66
- assert.deepEqual(pricingSheet.total(), { amount: 535, currency: 'CHF' });
67
- assert.deepEqual(pricingSheet.total(), { amount: pricingSheet.gross(), currency: 'CHF' });
66
+ assert.deepEqual(pricingSheet.total(), { amount: 535, currencyCode: 'CHF' });
67
+ assert.deepEqual(pricingSheet.total(), { amount: pricingSheet.gross(), currencyCode: 'CHF' });
68
68
  });
69
69
 
70
70
  it('should return sum of all ProductPricingCalculations ', () => {
71
- assert.deepEqual(pricingSheet.total({ useNetPrice: true }), { amount: 460, currency: 'CHF' });
71
+ assert.deepEqual(pricingSheet.total({ useNetPrice: true }), { amount: 460, currencyCode: 'CHF' });
72
72
  assert.deepEqual(pricingSheet.total({ useNetPrice: true }), {
73
73
  amount: pricingSheet.net(),
74
- currency: 'CHF',
74
+ currencyCode: 'CHF',
75
75
  });
76
76
  });
77
77
 
78
78
  it('should return sum of all ProductPricingCalculations for the provided category ', () => {
79
- assert.deepEqual(pricingSheet.total({ category: 'ITEM' }), { amount: 400, currency: 'CHF' });
80
- assert.deepEqual(pricingSheet.total({ category: 'DISCOUNT' }), { amount: 60, currency: 'CHF' });
81
- assert.deepEqual(pricingSheet.total({ category: 'TAX' }), { amount: 75, currency: 'CHF' });
79
+ assert.deepEqual(pricingSheet.total({ category: 'ITEM' }), { amount: 400, currencyCode: 'CHF' });
80
+ assert.deepEqual(pricingSheet.total({ category: 'DISCOUNT' }), {
81
+ amount: 60,
82
+ currencyCode: 'CHF',
83
+ });
84
+ assert.deepEqual(pricingSheet.total({ category: 'TAX' }), { amount: 75, currencyCode: 'CHF' });
82
85
  });
83
86
  });
84
87
 
@@ -106,21 +109,27 @@ describe('ProductPricingSheet', () => {
106
109
 
107
110
  describe('unitPrice', () => {
108
111
  it('should return the GROSS sum for a product price useNetPrice:false', () => {
109
- assert.deepEqual(pricingSheet.unitPrice({ useNetPrice: false }), { amount: 268, currency: 'CHF' });
112
+ assert.deepEqual(pricingSheet.unitPrice({ useNetPrice: false }), {
113
+ amount: 268,
114
+ currencyCode: 'CHF',
115
+ });
110
116
  });
111
117
 
112
118
  it('should return the NET sum for a product price when useNetPrice:true', () => {
113
- assert.deepEqual(pricingSheet.unitPrice({ useNetPrice: true }), { amount: 230, currency: 'CHF' });
119
+ assert.deepEqual(pricingSheet.unitPrice({ useNetPrice: true }), {
120
+ amount: 230,
121
+ currencyCode: 'CHF',
122
+ });
114
123
  });
115
124
  });
116
125
 
117
126
  describe('discountPrices', () => {
118
127
  it('should return the sum of all discounts registered on the price sheet based on discountId', () => {
119
128
  assert.deepEqual(pricingSheet.discountPrices('for-all'), [
120
- { amount: 40, currency: 'CHF', discountId: 'for-all' },
129
+ { amount: 40, currencyCode: 'CHF', discountId: 'for-all' },
121
130
  ]);
122
131
  assert.deepEqual(pricingSheet.discountPrices('special'), [
123
- { amount: 20, currency: 'CHF', discountId: 'special' },
132
+ { amount: 20, currencyCode: 'CHF', discountId: 'special' },
124
133
  ]);
125
134
  });
126
135
 
@@ -89,7 +89,7 @@ export const ProductPricingSheet = (
89
89
  const amount = unitPriceParams?.useNetPrice ? this.net() : this.gross();
90
90
  return {
91
91
  amount: Math.round(amount / (this.quantity ?? 1)),
92
- currency: this.currency,
92
+ currencyCode: this.currencyCode,
93
93
  };
94
94
  },
95
95
 
@@ -113,7 +113,7 @@ export const ProductPricingSheet = (
113
113
  return {
114
114
  discountId,
115
115
  amount: Math.round(amount),
116
- currency: basePricingSheet.currency,
116
+ currencyCode: basePricingSheet.currencyCode,
117
117
  };
118
118
  })
119
119
  .filter(Boolean);
@@ -5,9 +5,9 @@ import {
5
5
  } from '@unchainedshop/core-quotations';
6
6
  import { BaseAdapter, IBaseAdapter } from '@unchainedshop/utils';
7
7
 
8
- export type QuotationContext = {
8
+ export interface QuotationContext {
9
9
  quotation?: Quotation;
10
- };
10
+ }
11
11
 
12
12
  export interface QuotationAdapterActions {
13
13
  configurationError: () => QuotationError;
@@ -15,16 +15,16 @@ export enum WarehousingError {
15
15
  WRONG_CREDENTIALS = 'WRONG_CREDENTIALS',
16
16
  }
17
17
 
18
- export type WarehousingAdapterActions = {
18
+ export interface WarehousingAdapterActions {
19
19
  configurationError: () => WarehousingError;
20
20
  isActive: () => boolean;
21
21
  stock: (referenceDate: Date) => Promise<number>;
22
22
  productionTime: (quantityToProduce: number) => Promise<number>;
23
23
  commissioningTime: (quantity: number) => Promise<number>;
24
- tokenize: () => Promise<Array<Omit<TokenSurrogate, 'userId' | 'productId' | 'orderPositionId'>>>;
24
+ tokenize: () => Promise<Omit<TokenSurrogate, 'userId' | 'productId' | 'orderPositionId'>[]>;
25
25
  tokenMetadata: (chainTokenId: string, referenceDate: Date) => Promise<any>;
26
26
  isInvalidateable: (chainTokenId: string, referenceDate: Date) => Promise<boolean>;
27
- };
27
+ }
28
28
 
29
29
  export interface WarehousingContext {
30
30
  deliveryProvider?: DeliveryProvider;
@@ -12,10 +12,10 @@ import {
12
12
  } from '../directors/index.js';
13
13
  import { Modules } from '../modules.js';
14
14
 
15
- export type EstimatedDispatch = {
15
+ export interface EstimatedDispatch {
16
16
  shipping?: Date;
17
17
  earliestDelivery?: Date;
18
- };
18
+ }
19
19
 
20
20
  export type EstimatedStock = { quantity: number } | null;
21
21
 
@@ -47,7 +47,7 @@ export type IWarehousingDirector = IBaseDirector<IWarehousingAdapter> & {
47
47
  isActive: () => boolean;
48
48
  estimatedStock: () => Promise<EstimatedStock>;
49
49
  estimatedDispatch: () => Promise<EstimatedDispatch>;
50
- tokenize: () => Promise<Array<TokenSurrogate>>;
50
+ tokenize: () => Promise<TokenSurrogate[]>;
51
51
  tokenMetadata: (chainTokenId: string) => Promise<any>;
52
52
  isInvalidateable: (chainTokenId: string) => Promise<boolean>;
53
53
  }>;
@@ -18,11 +18,11 @@ export type WorkScheduleConfiguration = Pick<
18
18
  };
19
19
 
20
20
  export type IWorkerDirector = IBaseDirector<IWorkerAdapter<any, any>> & {
21
- getActivePluginTypes: (options?: { external?: boolean }) => Array<string>;
21
+ getActivePluginTypes: (options?: { external?: boolean }) => string[];
22
22
  getAdapterByType: (type: string) => IWorkerAdapter<any, any>;
23
23
  disableAutoscheduling: (scheduleId: string) => void;
24
24
  configureAutoscheduling: (workScheduleConfiguration: WorkScheduleConfiguration) => void;
25
- getAutoSchedules: () => Array<[string, WorkScheduleConfiguration]>;
25
+ getAutoSchedules: () => [string, WorkScheduleConfiguration][];
26
26
  doWork: (work: Work, unchainedAPI) => Promise<WorkResult>;
27
27
  processNextWork: (unchainedAPI: { modules: Modules }, workerId?: string) => Promise<Work>;
28
28
  };
@@ -42,6 +42,10 @@ export * from './WarehousingAdapter.js';
42
42
 
43
43
  export * from './WorkerAdapter.js';
44
44
  export * from './WorkerDirector.js';
45
+ export * from './EventListenerWorker.js';
46
+ export * from './IntervalWorker.js';
47
+ export * from './FailedRescheduler.js';
48
+ export * from './BaseWorker.js';
45
49
 
46
50
  export * from './QuotationAdapter.js';
47
51
  export * from './QuotationDirector.js';
@@ -24,7 +24,7 @@ export async function calculateDiscountTotalService(
24
24
  });
25
25
  const orderDeliveryDiscountSum = DeliveryPricingSheet({
26
26
  calculation: orderDelivery.calculation || [],
27
- currency: order.currency,
27
+ currencyCode: order.currencyCode,
28
28
  }).total({ category: DeliveryPricingRowCategory.Discount, discountId: orderDiscountId });
29
29
 
30
30
  // Payment discounts
@@ -33,7 +33,7 @@ export async function calculateDiscountTotalService(
33
33
  });
34
34
  const orderPaymentDiscountSum = PaymentPricingSheet({
35
35
  calculation: orderPayment.calculation || [],
36
- currency: order.currency,
36
+ currencyCode: order.currencyCode,
37
37
  }).total({ category: PaymentPricingRowCategory.Discount, discountId: orderDiscountId });
38
38
 
39
39
  // Position discounts
@@ -43,7 +43,7 @@ export async function calculateDiscountTotalService(
43
43
  const orderPositionDiscounts = orderPositions.map((orderPosition) =>
44
44
  ProductPricingSheet({
45
45
  calculation: orderPosition.calculation || [],
46
- currency: order.currency,
46
+ currencyCode: order.currencyCode,
47
47
  quantity: orderPosition.quantity,
48
48
  }).total({
49
49
  category: ProductPricingRowCategory.Discount,
@@ -54,7 +54,7 @@ export async function calculateDiscountTotalService(
54
54
  // order discounts
55
55
  const orderDiscountSum = OrderPricingSheet({
56
56
  calculation: order.calculation,
57
- currency: order.currency,
57
+ currencyCode: order.currencyCode,
58
58
  }).total({ category: OrderPricingRowCategory.Discounts, discountId: orderDiscountId });
59
59
 
60
60
  const prices = [
@@ -66,6 +66,6 @@ export async function calculateDiscountTotalService(
66
66
  const amount = prices.reduce((oldValue, price) => oldValue + (price || 0), 0);
67
67
  return {
68
68
  amount,
69
- currency: order.currency,
69
+ currencyCode: order.currencyCode,
70
70
  };
71
71
  }