@unchainedshop/core 3.1.11 → 4.0.0-rc.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (217) 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/BaseWorker.d.ts +30 -0
  15. package/lib/directors/BaseWorker.d.ts.map +1 -0
  16. package/lib/directors/BaseWorker.js +79 -0
  17. package/lib/directors/BaseWorker.js.map +1 -0
  18. package/lib/directors/DeliveryAdapter.d.ts +2 -2
  19. package/lib/directors/DeliveryAdapter.d.ts.map +1 -1
  20. package/lib/directors/DeliveryDirector.d.ts.map +1 -1
  21. package/lib/directors/DeliveryDirector.js +1 -3
  22. package/lib/directors/DeliveryDirector.js.map +1 -1
  23. package/lib/directors/DeliveryPricingAdapter.d.ts +3 -3
  24. package/lib/directors/DeliveryPricingAdapter.d.ts.map +1 -1
  25. package/lib/directors/DeliveryPricingAdapter.js +2 -2
  26. package/lib/directors/DeliveryPricingAdapter.js.map +1 -1
  27. package/lib/directors/DeliveryPricingDirector.d.ts +3 -3
  28. package/lib/directors/DeliveryPricingDirector.d.ts.map +1 -1
  29. package/lib/directors/DeliveryPricingDirector.js +6 -6
  30. package/lib/directors/DeliveryPricingDirector.js.map +1 -1
  31. package/lib/directors/DeliveryPricingSheet.js +2 -2
  32. package/lib/directors/DeliveryPricingSheet.js.map +1 -1
  33. package/lib/directors/EnrollmentAdapter.d.ts +3 -3
  34. package/lib/directors/EnrollmentAdapter.d.ts.map +1 -1
  35. package/lib/directors/EnrollmentAdapter.js.map +1 -1
  36. package/lib/directors/EventListenerWorker.d.ts +6 -0
  37. package/lib/directors/EventListenerWorker.d.ts.map +1 -0
  38. package/lib/directors/EventListenerWorker.js +46 -0
  39. package/lib/directors/EventListenerWorker.js.map +1 -0
  40. package/lib/directors/FailedRescheduler.d.ts +15 -0
  41. package/lib/directors/FailedRescheduler.d.ts.map +1 -0
  42. package/lib/directors/FailedRescheduler.js +40 -0
  43. package/lib/directors/FailedRescheduler.js.map +1 -0
  44. package/lib/directors/FilterAdapter.d.ts +9 -12
  45. package/lib/directors/FilterAdapter.d.ts.map +1 -1
  46. package/lib/directors/FilterAdapter.js +0 -4
  47. package/lib/directors/FilterAdapter.js.map +1 -1
  48. package/lib/directors/FilterDirector.d.ts +9 -9
  49. package/lib/directors/FilterDirector.d.ts.map +1 -1
  50. package/lib/directors/FilterDirector.js.map +1 -1
  51. package/lib/directors/IntervalWorker.d.ts +10 -0
  52. package/lib/directors/IntervalWorker.d.ts.map +1 -0
  53. package/lib/directors/IntervalWorker.js +37 -0
  54. package/lib/directors/IntervalWorker.js.map +1 -0
  55. package/lib/directors/MessagingDirector.d.ts +11 -15
  56. package/lib/directors/MessagingDirector.d.ts.map +1 -1
  57. package/lib/directors/OrderPricingAdapter.d.ts +3 -3
  58. package/lib/directors/OrderPricingAdapter.d.ts.map +1 -1
  59. package/lib/directors/OrderPricingAdapter.js +2 -2
  60. package/lib/directors/OrderPricingAdapter.js.map +1 -1
  61. package/lib/directors/OrderPricingDirector.d.ts +2 -2
  62. package/lib/directors/OrderPricingDirector.d.ts.map +1 -1
  63. package/lib/directors/OrderPricingDirector.js +4 -4
  64. package/lib/directors/OrderPricingDirector.js.map +1 -1
  65. package/lib/directors/OrderPricingSheet.js +2 -2
  66. package/lib/directors/OrderPricingSheet.js.map +1 -1
  67. package/lib/directors/PaymentAdapter.d.ts +2 -2
  68. package/lib/directors/PaymentAdapter.d.ts.map +1 -1
  69. package/lib/directors/PaymentPricingAdapter.d.ts +2 -2
  70. package/lib/directors/PaymentPricingAdapter.d.ts.map +1 -1
  71. package/lib/directors/PaymentPricingAdapter.js +2 -2
  72. package/lib/directors/PaymentPricingAdapter.js.map +1 -1
  73. package/lib/directors/PaymentPricingDirector.d.ts +3 -3
  74. package/lib/directors/PaymentPricingDirector.d.ts.map +1 -1
  75. package/lib/directors/PaymentPricingDirector.js +6 -6
  76. package/lib/directors/PaymentPricingDirector.js.map +1 -1
  77. package/lib/directors/PaymentPricingSheet.js +1 -1
  78. package/lib/directors/PaymentPricingSheet.js.map +1 -1
  79. package/lib/directors/ProductDiscountConfiguration.d.ts +1 -1
  80. package/lib/directors/ProductDiscountConfiguration.d.ts.map +1 -1
  81. package/lib/directors/ProductPricingAdapter.d.ts +3 -3
  82. package/lib/directors/ProductPricingAdapter.d.ts.map +1 -1
  83. package/lib/directors/ProductPricingAdapter.js +2 -2
  84. package/lib/directors/ProductPricingAdapter.js.map +1 -1
  85. package/lib/directors/ProductPricingDirector.d.ts +5 -5
  86. package/lib/directors/ProductPricingDirector.d.ts.map +1 -1
  87. package/lib/directors/ProductPricingDirector.js +6 -6
  88. package/lib/directors/ProductPricingDirector.js.map +1 -1
  89. package/lib/directors/ProductPricingSheet.js +2 -2
  90. package/lib/directors/ProductPricingSheet.js.map +1 -1
  91. package/lib/directors/QuotationAdapter.d.ts +2 -2
  92. package/lib/directors/QuotationAdapter.d.ts.map +1 -1
  93. package/lib/directors/WarehousingAdapter.d.ts +3 -3
  94. package/lib/directors/WarehousingAdapter.d.ts.map +1 -1
  95. package/lib/directors/WarehousingDirector.d.ts +3 -3
  96. package/lib/directors/WarehousingDirector.d.ts.map +1 -1
  97. package/lib/directors/WorkerDirector.d.ts +2 -2
  98. package/lib/directors/WorkerDirector.d.ts.map +1 -1
  99. package/lib/directors/index.d.ts +4 -0
  100. package/lib/directors/index.d.ts.map +1 -1
  101. package/lib/directors/index.js +4 -0
  102. package/lib/directors/index.js.map +1 -1
  103. package/lib/services/calculateDiscountTotal.d.ts +1 -1
  104. package/lib/services/calculateDiscountTotal.js +5 -5
  105. package/lib/services/calculateDiscountTotal.js.map +1 -1
  106. package/lib/services/createEnrollmentFromCheckout.d.ts +3 -3
  107. package/lib/services/createEnrollmentFromCheckout.d.ts.map +1 -1
  108. package/lib/services/createEnrollmentFromCheckout.js +1 -1
  109. package/lib/services/createEnrollmentFromCheckout.js.map +1 -1
  110. package/lib/services/discountedEntities.d.ts +1 -1
  111. package/lib/services/discountedEntities.d.ts.map +1 -1
  112. package/lib/services/discountedEntities.js +4 -4
  113. package/lib/services/discountedEntities.js.map +1 -1
  114. package/lib/services/ercMetadata.d.ts +5 -3
  115. package/lib/services/ercMetadata.d.ts.map +1 -1
  116. package/lib/services/ercMetadata.js +2 -11
  117. package/lib/services/ercMetadata.js.map +1 -1
  118. package/lib/services/index.d.ts +1 -3
  119. package/lib/services/index.d.ts.map +1 -1
  120. package/lib/services/index.js.map +1 -1
  121. package/lib/services/loadFilters.d.ts +1 -1
  122. package/lib/services/loadFilters.d.ts.map +1 -1
  123. package/lib/services/loadFilters.js.map +1 -1
  124. package/lib/services/migrateBookmarks.d.ts +1 -1
  125. package/lib/services/migrateBookmarks.d.ts.map +1 -1
  126. package/lib/services/migrateOrderCart.d.ts +2 -2
  127. package/lib/services/migrateOrderCart.d.ts.map +1 -1
  128. package/lib/services/migrateOrderCart.js +3 -3
  129. package/lib/services/migrateOrderCart.js.map +1 -1
  130. package/lib/services/migrateUserData.js +2 -2
  131. package/lib/services/migrateUserData.js.map +1 -1
  132. package/lib/services/nextUserCart.js +2 -2
  133. package/lib/services/nextUserCart.js.map +1 -1
  134. package/lib/services/processOrder.d.ts.map +1 -1
  135. package/lib/services/processOrder.js +1 -3
  136. package/lib/services/processOrder.js.map +1 -1
  137. package/lib/services/removeFiles.d.ts +1 -1
  138. package/lib/services/removeFiles.d.ts.map +1 -1
  139. package/lib/services/removeFiles.js +1 -1
  140. package/lib/services/removeFiles.js.map +1 -1
  141. package/lib/services/simulateProductDispatching.d.ts +1 -3
  142. package/lib/services/simulateProductDispatching.d.ts.map +1 -1
  143. package/lib/services/simulateProductDispatching.js +2 -1
  144. package/lib/services/simulateProductDispatching.js.map +1 -1
  145. package/lib/services/simulateProductInventory.d.ts +1 -3
  146. package/lib/services/simulateProductInventory.d.ts.map +1 -1
  147. package/lib/services/simulateProductInventory.js +2 -1
  148. package/lib/services/simulateProductInventory.js.map +1 -1
  149. package/lib/services/simulateProductPricing.d.ts +3 -3
  150. package/lib/services/simulateProductPricing.d.ts.map +1 -1
  151. package/lib/services/supportedDeliveryProviders.js +1 -1
  152. package/lib/services/supportedDeliveryProviders.js.map +1 -1
  153. package/lib/services/supportedPaymentProviders.js +1 -1
  154. package/lib/services/supportedPaymentProviders.js.map +1 -1
  155. package/lib/services/supportedWarehousingProviders.js +1 -1
  156. package/lib/services/supportedWarehousingProviders.js.map +1 -1
  157. package/lib/services/updateCalculation.d.ts.map +1 -1
  158. package/lib/services/updateCalculation.js +4 -5
  159. package/lib/services/updateCalculation.js.map +1 -1
  160. package/lib/services/updateScheduling.js +1 -1
  161. package/lib/services/updateScheduling.js.map +1 -1
  162. package/package.json +24 -23
  163. package/src/directors/BaseDiscountAdapter.ts +1 -1
  164. package/src/directors/BaseDiscountDirector.ts +1 -1
  165. package/src/directors/BasePricingAdapter.ts +4 -4
  166. package/src/directors/BasePricingDirector.ts +4 -10
  167. package/src/directors/BasePricingSheet.ts +12 -12
  168. package/src/directors/BaseWorker.ts +116 -0
  169. package/src/directors/DeliveryAdapter.ts +2 -2
  170. package/src/directors/DeliveryDirector.ts +1 -3
  171. package/src/directors/DeliveryPricingAdapter.ts +5 -5
  172. package/src/directors/DeliveryPricingDirector.ts +9 -9
  173. package/src/directors/DeliveryPricingSheet.ts +2 -2
  174. package/src/directors/EnrollmentAdapter.ts +3 -6
  175. package/src/directors/EventListenerWorker.ts +61 -0
  176. package/src/directors/FailedRescheduler.ts +73 -0
  177. package/src/directors/FilterAdapter.ts +11 -11
  178. package/src/directors/FilterDirector.ts +16 -16
  179. package/src/directors/IntervalWorker.ts +54 -0
  180. package/src/directors/MessagingDirector.ts +10 -10
  181. package/src/directors/OrderPricingAdapter.ts +5 -5
  182. package/src/directors/OrderPricingDirector.ts +6 -6
  183. package/src/directors/OrderPricingSheet.ts +2 -2
  184. package/src/directors/PaymentAdapter.ts +2 -2
  185. package/src/directors/PaymentPricingAdapter.ts +4 -4
  186. package/src/directors/PaymentPricingDirector.ts +9 -9
  187. package/src/directors/PaymentPricingSheet.ts +1 -1
  188. package/src/directors/ProductDiscountConfiguration.ts +1 -1
  189. package/src/directors/ProductPricingAdapter.ts +5 -5
  190. package/src/directors/ProductPricingDirector.ts +11 -11
  191. package/src/directors/ProductPricingSheet.test.ts +22 -13
  192. package/src/directors/ProductPricingSheet.ts +2 -2
  193. package/src/directors/QuotationAdapter.ts +2 -2
  194. package/src/directors/WarehousingAdapter.ts +3 -3
  195. package/src/directors/WarehousingDirector.ts +3 -3
  196. package/src/directors/WorkerDirector.ts +2 -2
  197. package/src/directors/index.ts +4 -0
  198. package/src/services/calculateDiscountTotal.ts +5 -5
  199. package/src/services/createEnrollmentFromCheckout.ts +4 -4
  200. package/src/services/discountedEntities.ts +5 -5
  201. package/src/services/ercMetadata.ts +6 -14
  202. package/src/services/index.ts +1 -3
  203. package/src/services/loadFilters.ts +1 -1
  204. package/src/services/migrateBookmarks.ts +1 -1
  205. package/src/services/migrateOrderCart.ts +4 -4
  206. package/src/services/migrateUserData.ts +2 -2
  207. package/src/services/nextUserCart.ts +2 -2
  208. package/src/services/processOrder.ts +4 -3
  209. package/src/services/removeFiles.ts +2 -2
  210. package/src/services/simulateProductDispatching.ts +3 -4
  211. package/src/services/simulateProductInventory.ts +3 -4
  212. package/src/services/simulateProductPricing.ts +3 -3
  213. package/src/services/supportedDeliveryProviders.ts +1 -1
  214. package/src/services/supportedPaymentProviders.ts +1 -1
  215. package/src/services/supportedWarehousingProviders.ts +1 -1
  216. package/src/services/updateCalculation.ts +4 -5
  217. package/src/services/updateScheduling.ts +2 -2
@@ -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
  }
@@ -12,16 +12,16 @@ export async function createEnrollmentFromCheckoutService(
12
12
  items,
13
13
  context,
14
14
  }: {
15
- items: Array<{
15
+ items: {
16
16
  orderPosition: OrderPosition;
17
17
  product: Product;
18
- }>;
18
+ }[];
19
19
  context: {
20
20
  paymentContext?: any;
21
21
  deliveryContext?: any;
22
22
  };
23
23
  },
24
- ): Promise<Array<Enrollment>> {
24
+ ): Promise<Enrollment[]> {
25
25
  const orderId = order._id;
26
26
 
27
27
  const payment = await this.orders.payments.findOrderPayment({
@@ -35,7 +35,7 @@ export async function createEnrollmentFromCheckoutService(
35
35
  billingAddress: order.billingAddress,
36
36
  contact: order.contact,
37
37
  countryCode: order.countryCode,
38
- currencyCode: order.currency,
38
+ currencyCode: order.currencyCode,
39
39
  delivery: {
40
40
  deliveryProviderId: delivery.deliveryProviderId,
41
41
  context: delivery.context,
@@ -12,7 +12,7 @@ export async function discountedEntitiesService(
12
12
  this: Modules,
13
13
  order: Order,
14
14
  orderDiscount: OrderDiscount,
15
- ): Promise<Array<OrderPricingDiscount>> {
15
+ ): Promise<OrderPricingDiscount[]> {
16
16
  // Delivery discounts
17
17
  const orderDelivery = await this.orders.deliveries.findDelivery({
18
18
  orderDeliveryId: order.deliveryId,
@@ -20,7 +20,7 @@ export async function discountedEntitiesService(
20
20
 
21
21
  const deliveryPricingSheet = DeliveryPricingSheet({
22
22
  calculation: orderDelivery.calculation || [],
23
- currency: order.currency,
23
+ currencyCode: order.currencyCode,
24
24
  });
25
25
  const orderDeliveryDiscounts = deliveryPricingSheet
26
26
  .discountPrices(orderDiscount._id)
@@ -35,7 +35,7 @@ export async function discountedEntitiesService(
35
35
  });
36
36
  const paymentPricingSheet = PaymentPricingSheet({
37
37
  calculation: orderPayment.calculation || [],
38
- currency: order.currency,
38
+ currencyCode: order.currencyCode,
39
39
  });
40
40
  const orderPaymentDiscounts = paymentPricingSheet
41
41
  .discountPrices(orderDiscount._id)
@@ -51,7 +51,7 @@ export async function discountedEntitiesService(
51
51
  const orderPositionDiscounts = orderPositions.flatMap((orderPosition) =>
52
52
  ProductPricingSheet({
53
53
  calculation: orderPosition.calculation,
54
- currency: order.currency,
54
+ currencyCode: order.currencyCode,
55
55
  quantity: orderPosition.quantity,
56
56
  })
57
57
  .discountPrices(orderDiscount._id)
@@ -64,7 +64,7 @@ export async function discountedEntitiesService(
64
64
  // order discounts
65
65
  const orderDiscounts = OrderPricingSheet({
66
66
  calculation: order.calculation || [],
67
- currency: order.currency,
67
+ currencyCode: order.currencyCode,
68
68
  })
69
69
  .discountPrices(orderDiscount._id)
70
70
  .map((discount) => ({ order, ...discount }));
@@ -1,23 +1,15 @@
1
- import { WarehousingProviderType } from '@unchainedshop/core-warehousing';
1
+ import { TokenSurrogate, WarehousingProviderType } from '@unchainedshop/core-warehousing';
2
+ import { Product } from '@unchainedshop/core-products';
2
3
  import { WarehousingDirector } from '../directors/WarehousingDirector.js';
3
4
  import { Modules } from '../modules.js';
4
5
 
5
6
  export async function ercMetadataService(
6
7
  this: Modules,
7
- { productId, chainTokenId, locale }: { productId: string; chainTokenId: string; locale: Intl.Locale },
8
+ { product, token, locale }: { product: Product; token: TokenSurrogate; locale: Intl.Locale },
8
9
  ) {
9
- const product = await this.products.findProduct({
10
- productId,
11
- });
12
-
13
- const [token] = await this.warehousing.findTokens({
14
- chainTokenId,
15
- contractAddress: product?.tokenization?.contractAddress,
16
- });
17
-
18
- const virtualProviders = await this.warehousing.findProviders({
19
- type: WarehousingProviderType.VIRTUAL,
20
- });
10
+ const virtualProviders = (await this.warehousing.allProviders()).filter(
11
+ ({ type }) => type === WarehousingProviderType.VIRTUAL,
12
+ );
21
13
 
22
14
  return await WarehousingDirector.tokenMetadata(
23
15
  virtualProviders,
@@ -62,9 +62,7 @@ function bindMethodsToModules(modules: Modules) {
62
62
  };
63
63
  }
64
64
 
65
- export interface ServiceInterface {
66
- (this: Modules, ...args: any[]): Promise<any> | any;
67
- }
65
+ export type ServiceInterface = (this: Modules, ...args: any[]) => Promise<any> | any;
68
66
 
69
67
  export type Bound<T extends ServiceInterface> = OmitThisParameter<T>;
70
68
 
@@ -5,7 +5,7 @@ import { FilterDirector } from '../directors/FilterDirector.js';
5
5
  export async function loadFiltersService(
6
6
  this: Modules,
7
7
  searchQuery: SearchQuery,
8
- { productIds, forceLiveCollection }: { productIds: Array<string>; forceLiveCollection: boolean },
8
+ { productIds, forceLiveCollection }: { productIds: string[]; forceLiveCollection: boolean },
9
9
  ) {
10
10
  const filterActions = await FilterDirector.actions({ searchQuery }, { modules: this });
11
11
  const filterSelector = await filterActions.transformFilterSelector(defaultFilterSelector(searchQuery));
@@ -14,7 +14,7 @@ export async function migrateBookmarksService(
14
14
  fromUserId: string;
15
15
  toUserId: string;
16
16
  shouldMerge: boolean;
17
- countryContext: string;
17
+ countryCode: string;
18
18
  },
19
19
  ) {
20
20
  const fromBookmarks = await this.bookmarks.findBookmarks({ userId: fromUserId });
@@ -7,20 +7,20 @@ export async function migrateOrderCartsService(
7
7
  fromUserId,
8
8
  toUserId,
9
9
  shouldMerge,
10
- countryContext,
10
+ countryCode,
11
11
  }: {
12
12
  fromUserId: string;
13
13
  toUserId: string;
14
14
  shouldMerge: boolean;
15
- countryContext: string;
15
+ countryCode: string;
16
16
  },
17
17
  ) {
18
18
  const fromCart = await this.orders.cart({
19
- countryCode: countryContext,
19
+ countryCode,
20
20
  userId: fromUserId,
21
21
  });
22
22
  const toCart = await this.orders.cart({
23
- countryCode: countryContext,
23
+ countryCode,
24
24
  userId: toUserId,
25
25
  });
26
26
 
@@ -10,13 +10,13 @@ export async function migrateUserDataService(userIdBeforeLogin: string, userId:
10
10
  fromUserId: userIdBeforeLogin,
11
11
  toUserId: userId,
12
12
  shouldMerge: userSettings.mergeUserCartsOnLogin,
13
- countryContext: userBeforeLogin?.lastLogin?.countryCode || user?.lastLogin?.countryCode,
13
+ countryCode: userBeforeLogin?.lastLogin?.countryCode || user?.lastLogin?.countryCode,
14
14
  });
15
15
 
16
16
  await migrateBookmarksService.bind(this)({
17
17
  fromUserId: userIdBeforeLogin,
18
18
  toUserId: userId,
19
19
  shouldMerge: userSettings.mergeUserCartsOnLogin,
20
- countryContext: userBeforeLogin?.lastLogin?.countryCode || user?.lastLogin?.countryCode,
20
+ countryCode: userBeforeLogin?.lastLogin?.countryCode || user?.lastLogin?.countryCode,
21
21
  });
22
22
  }
@@ -30,12 +30,12 @@ export async function nextUserCartService(
30
30
 
31
31
  const countryObject = await this.countries.findCountry({ isoCode: countryCode });
32
32
  const currencies = await this.currencies.findCurrencies({ includeInactive: false });
33
- const currency = resolveBestCurrency(countryObject.defaultCurrencyCode, currencies);
33
+ const currencyCode = resolveBestCurrency(countryObject.defaultCurrencyCode, currencies);
34
34
 
35
35
  const order = await this.orders.create({
36
36
  userId: user._id,
37
37
  orderNumber,
38
- currency,
38
+ currencyCode,
39
39
  countryCode,
40
40
  billingAddress: user.lastBillingAddress || user.profile?.address,
41
41
  contact:
@@ -175,9 +175,10 @@ export async function processOrderService(
175
175
  );
176
176
  if (tokenizedItems.length > 0) {
177
177
  // Give virtual warehouse a chance to instantiate new virtual objects
178
- const virtualProviders = await this.warehousing.findProviders({
179
- type: WarehousingProviderType.VIRTUAL,
180
- });
178
+ const virtualProviders = (await this.warehousing.allProviders()).filter(
179
+ ({ type }) => type === WarehousingProviderType.VIRTUAL,
180
+ );
181
+
181
182
  // It's very important to do this in a series and not in Promise.all
182
183
  // TODO: Actually, only createTokens should decide on the unique chainTokenId
183
184
  // and the tokens should be created with a distributed Lock to not assign the same id multiple times!
@@ -1,7 +1,7 @@
1
1
  import { getFileAdapter } from '@unchainedshop/core-files';
2
2
  import { Modules } from '../modules.js';
3
3
 
4
- export async function removeFilesService(this: Modules, { fileIds }: { fileIds: Array<string> }) {
4
+ export async function removeFilesService(this: Modules, { fileIds }: { fileIds: string[] }) {
5
5
  if (fileIds && typeof fileIds !== 'string' && !Array.isArray(fileIds))
6
6
  throw Error('Media id/s to be removed not provided as a string or array');
7
7
 
@@ -14,7 +14,7 @@ export async function removeFilesService(this: Modules, { fileIds }: { fileIds:
14
14
  try {
15
15
  await fileUploadAdapter.removeFiles(fileObjects, { modules: this });
16
16
  } catch (e) {
17
- console.warn(e); // eslint-disable-line
17
+ console.warn(e);
18
18
  }
19
19
 
20
20
  const fileIdsToDelete = fileObjects.map((f) => f._id).filter(Boolean);
@@ -1,4 +1,3 @@
1
- import { DeliveryProvider } from '@unchainedshop/core-delivery';
2
1
  import { Modules } from '../modules.js';
3
2
  import { supportedWarehousingProvidersService } from './supportedWarehousingProviders.js';
4
3
  import { Product } from '@unchainedshop/core-products';
@@ -9,19 +8,19 @@ import { WarehousingProvider } from '@unchainedshop/core-warehousing';
9
8
  export async function simulateProductDispatchingService(
10
9
  this: Modules,
11
10
  {
12
- deliveryProviders,
13
11
  product,
14
12
  quantity,
15
13
  referenceDate,
16
14
  }: {
17
15
  product: Product;
18
- deliveryProviders: DeliveryProvider[];
19
16
  quantity?: number;
20
17
  referenceDate?: Date;
21
18
  },
22
19
  ) {
20
+ const deliveryProviders = await this.delivery.allProviders();
21
+
23
22
  return deliveryProviders.reduce<
24
- Promise<Array<WarehousingContext & EstimatedDispatch & { warehousingProvider: WarehousingProvider }>>
23
+ Promise<(WarehousingContext & EstimatedDispatch & { warehousingProvider: WarehousingProvider })[]>
25
24
  >(async (oldResult, deliveryProvider) => {
26
25
  const result = await oldResult;
27
26
 
@@ -1,4 +1,3 @@
1
- import { DeliveryProvider } from '@unchainedshop/core-delivery';
2
1
  import { Modules } from '../modules.js';
3
2
  import { supportedWarehousingProvidersService } from './supportedWarehousingProviders.js';
4
3
  import { Product } from '@unchainedshop/core-products';
@@ -9,17 +8,17 @@ import { WarehousingProvider } from '@unchainedshop/core-warehousing';
9
8
  export async function simulateProductInventoryService(
10
9
  this: Modules,
11
10
  {
12
- deliveryProviders,
13
11
  product,
14
12
  referenceDate,
15
13
  }: {
16
14
  product: Product;
17
- deliveryProviders: DeliveryProvider[];
18
15
  referenceDate?: Date;
19
16
  },
20
17
  ) {
18
+ const deliveryProviders = await this.delivery.allProviders();
19
+
21
20
  return deliveryProviders.reduce<
22
- Promise<Array<WarehousingContext & EstimatedStock & { warehousingProvider: WarehousingProvider }>>
21
+ Promise<(WarehousingContext & EstimatedStock & { warehousingProvider: WarehousingProvider })[]>
23
22
  >(async (oldResult, deliveryProvider) => {
24
23
  const result = await oldResult;
25
24
 
@@ -8,10 +8,10 @@ export async function simulateProductPricingService(
8
8
  pricingContext: {
9
9
  product: Product;
10
10
  user: User;
11
- country: string;
12
- currency: string;
11
+ countryCode: string;
12
+ currencyCode: string;
13
13
  quantity: number;
14
- configuration?: Array<ProductConfiguration>;
14
+ configuration?: ProductConfiguration[];
15
15
  },
16
16
  ) {
17
17
  const calculated = await ProductPricingDirector.rebuildCalculation(pricingContext, { modules: this });
@@ -3,7 +3,7 @@ import { Modules } from '../modules.js';
3
3
  import { DeliveryContext, DeliveryDirector } from '../directors/index.js';
4
4
 
5
5
  export async function supportedDeliveryProvidersService(this: Modules, params: DeliveryContext) {
6
- const allProviders = await this.delivery.findProviders({});
6
+ const allProviders = await this.delivery.allProviders();
7
7
 
8
8
  const providers = (
9
9
  await Promise.all(
@@ -4,7 +4,7 @@ import { PaymentContext } from '../directors/PaymentAdapter.js';
4
4
  import { Modules } from '../modules.js';
5
5
 
6
6
  export async function supportedPaymentProvidersService(this: Modules, params: PaymentContext) {
7
- const allProviders = await this.payment.paymentProviders.findProviders({});
7
+ const allProviders = await this.payment.paymentProviders.allProviders();
8
8
 
9
9
  const providers = (
10
10
  await Promise.all(
@@ -3,7 +3,7 @@ import { WarehousingContext, WarehousingDirector } from '../directors/index.js';
3
3
  import { Modules } from '../modules.js';
4
4
 
5
5
  export async function supportedWarehousingProvidersService(this: Modules, params: WarehousingContext) {
6
- const allProviders = await this.warehousing.findProviders({});
6
+ const allProviders = await this.warehousing.allProviders();
7
7
 
8
8
  const providers = (
9
9
  await Promise.all(
@@ -73,10 +73,9 @@ export async function updateCalculationService(this: Modules, orderId: string) {
73
73
  orderPositions.map(async (orderPosition) => {
74
74
  const positionCalculation = await ProductPricingDirector.rebuildCalculation(
75
75
  {
76
- currency: order.currency,
76
+ currencyCode: order.currencyCode,
77
77
  quantity: orderPosition.quantity,
78
78
  item: orderPosition,
79
- configuration: orderPosition.configuration,
80
79
  },
81
80
  { modules: this },
82
81
  );
@@ -90,7 +89,7 @@ export async function updateCalculationService(this: Modules, orderId: string) {
90
89
  if (orderDelivery) {
91
90
  const deliveryCalculation = await DeliveryPricingDirector.rebuildCalculation(
92
91
  {
93
- currency: order.currency,
92
+ currencyCode: order.currencyCode,
94
93
  item: orderDelivery,
95
94
  },
96
95
  { modules: this },
@@ -106,7 +105,7 @@ export async function updateCalculationService(this: Modules, orderId: string) {
106
105
  if (orderPayment) {
107
106
  const paymentCalculation = await PaymentPricingDirector.rebuildCalculation(
108
107
  {
109
- currency: order.currency,
108
+ currencyCode: order.currencyCode,
110
109
  item: orderPayment,
111
110
  },
112
111
  { modules: this },
@@ -121,7 +120,7 @@ export async function updateCalculationService(this: Modules, orderId: string) {
121
120
  });
122
121
 
123
122
  const calculation = await OrderPricingDirector.rebuildCalculation(
124
- { currency: order.currency, order, orderPositions, orderDelivery, orderPayment },
123
+ { currencyCode: order.currencyCode, order, orderPositions, orderDelivery, orderPayment },
125
124
  { modules: this },
126
125
  );
127
126
 
@@ -41,7 +41,7 @@ export async function updateSchedulingService(
41
41
  delivery: deliveryProvider,
42
42
  order,
43
43
  userId,
44
- country: countryCode,
44
+ countryCode,
45
45
  referenceDate: order.ordered,
46
46
  quantity: orderPosition.quantity,
47
47
  };
@@ -60,5 +60,5 @@ export async function updateSchedulingService(
60
60
 
61
61
  return this.orders.positions.updateScheduling(orderPosition._id, scheduling);
62
62
  }),
63
- )) as Array<OrderPosition>;
63
+ )) as OrderPosition[];
64
64
  }