@unchainedshop/core 3.1.10 → 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
@@ -0,0 +1,73 @@
1
+ import { defaultLogger } from '@unchainedshop/logger';
2
+ import { subscribe } from '@unchainedshop/events';
3
+ import { Work, WorkData, WorkerEventTypes } from '@unchainedshop/core-worker';
4
+
5
+ export interface FailedReschedulerParams {
6
+ transformRetry?: (workData: WorkData) => Promise<WorkData | null>;
7
+ }
8
+
9
+ export interface IScheduler<P> {
10
+ key: string;
11
+ label: string;
12
+ version: string;
13
+
14
+ actions: (
15
+ params: P,
16
+ unchainedAPI,
17
+ ) => {
18
+ start: () => void;
19
+ stop: () => void;
20
+ };
21
+ }
22
+
23
+ export const FailedRescheduler: IScheduler<FailedReschedulerParams> = {
24
+ key: 'shop.unchained.scheduler.failed',
25
+ label: 'Reschedule failed works',
26
+ version: '1.0.0',
27
+
28
+ actions: ({ transformRetry }, unchainedAPI) => {
29
+ const handleFinishedWork = async ({ payload: work }: { payload: Work }) => {
30
+ if (!work.success && work.retries > 0) {
31
+ const now = new Date();
32
+ const workDelayMs = work.scheduled.getTime() - work.created.getTime();
33
+
34
+ // In short: Double the delay of the old work or delay for 5 seconds
35
+ const scheduled =
36
+ workDelayMs > 1000
37
+ ? new Date(now.getTime() + workDelayMs * 2)
38
+ : new Date(now.setSeconds(now.getSeconds() + 5));
39
+
40
+ defaultLogger.error(
41
+ `${FailedRescheduler.key} -> Reschedule failed work ${work._id} ${
42
+ work.type
43
+ } for ${scheduled.toISOString()} (in ${Math.round(workDelayMs / 1000)}). Remaining retries: ${
44
+ work.retries
45
+ }`,
46
+ );
47
+
48
+ const newWorkData = {
49
+ type: work.type,
50
+ priority: work.priority,
51
+ originalWorkId: work.originalWorkId || work._id,
52
+ retries: work.retries - 1,
53
+ timeout: work.timeout,
54
+ input: work.input,
55
+ scheduled,
56
+ };
57
+ await unchainedAPI.modules.worker.addWork(
58
+ transformRetry ? await transformRetry(newWorkData) : newWorkData,
59
+ );
60
+ }
61
+ };
62
+
63
+ return {
64
+ start() {
65
+ subscribe<Work>(WorkerEventTypes.FINISHED, handleFinishedWork);
66
+ },
67
+
68
+ stop() {
69
+ /* */
70
+ },
71
+ };
72
+ },
73
+ };
@@ -5,23 +5,23 @@ import { Product } from '@unchainedshop/core-products';
5
5
  import { Filter, SearchQuery } from '@unchainedshop/core-filters';
6
6
  import { Modules } from '../modules.js';
7
7
 
8
- export type FilterInputText = { locale: string; title: string; subtitle?: string };
9
-
10
- export enum FilterError {
11
- NOT_IMPLEMENTED = 'NOT_IMPLEMENTED',
8
+ export interface FilterInputText {
9
+ locale: string;
10
+ title: string;
11
+ subtitle?: string;
12
12
  }
13
13
 
14
- export type FilterContext = {
14
+ export interface FilterContext {
15
15
  filter?: Filter;
16
16
  searchQuery: SearchQuery;
17
- };
17
+ }
18
18
 
19
19
  export interface FilterAdapterActions {
20
- aggregateProductIds: (params: { productIds: Array<string> }) => Array<string>;
20
+ aggregateProductIds: (params: { productIds: string[] }) => string[];
21
21
 
22
22
  searchAssortments: (
23
23
  params: {
24
- assortmentIds: Array<string>;
24
+ assortmentIds: string[];
25
25
  },
26
26
  options: {
27
27
  filterSelector: mongodb.Filter<Filter>;
@@ -29,11 +29,11 @@ export interface FilterAdapterActions {
29
29
  sortStage: mongodb.FindOptions['sort'];
30
30
  locale: Intl.Locale;
31
31
  },
32
- ) => Promise<Array<string>>;
32
+ ) => Promise<string[]>;
33
33
 
34
34
  searchProducts: (
35
35
  params: {
36
- productIds: Array<string>;
36
+ productIds: string[];
37
37
  },
38
38
  options: {
39
39
  filterSelector: mongodb.Filter<Filter>;
@@ -41,7 +41,7 @@ export interface FilterAdapterActions {
41
41
  sortStage: mongodb.FindOptions['sort'];
42
42
  locale: Intl.Locale;
43
43
  },
44
- ) => Promise<Array<string>>;
44
+ ) => Promise<string[]>;
45
45
 
46
46
  transformFilterSelector: (
47
47
  query: mongodb.Filter<Filter>,
@@ -12,7 +12,7 @@ import {
12
12
  import { Product } from '@unchainedshop/core-products';
13
13
  import { Modules } from '../modules.js';
14
14
 
15
- export const parseQueryArray = (query: SearchFilterQuery): Record<string, Array<string>> =>
15
+ export const parseQueryArray = (query: SearchFilterQuery): Record<string, string[]> =>
16
16
  (query || []).reduce(
17
17
  (accumulator, { key, value }) => ({
18
18
  ...accumulator,
@@ -31,24 +31,24 @@ export type IFilterDirector = IBaseDirector<IFilterAdapter> & {
31
31
  filter: Filter,
32
32
  { value }: { value?: boolean | string },
33
33
  unchainedAPI: { modules: Modules },
34
- ) => Promise<Array<string>>;
34
+ ) => Promise<string[]>;
35
35
  buildProductIdMap: (
36
36
  filter: Filter,
37
37
  unchainedAPI: { modules: Modules },
38
- ) => Promise<[Array<string>, Record<string, Array<string>>]>;
38
+ ) => Promise<[string[], Record<string, string[]>]>;
39
39
  filterProductIds: (
40
40
  filter: Filter,
41
- { values, forceLiveCollection }: { values: Array<string>; forceLiveCollection?: boolean },
41
+ { values, forceLiveCollection }: { values: string[]; forceLiveCollection?: boolean },
42
42
  unchainedAPI: { modules: Modules },
43
- ) => Promise<Array<string>>;
43
+ ) => Promise<string[]>;
44
44
 
45
45
  filterFacets: (
46
46
  filter: Filter,
47
47
  params: {
48
48
  searchQuery: SearchQuery;
49
49
  forceLiveCollection?: boolean;
50
- allProductIds: Array<string>;
51
- otherFilters: Array<Filter>;
50
+ allProductIds: string[];
51
+ otherFilters: Filter[];
52
52
  },
53
53
  unchainedAPI: { modules: Modules },
54
54
  ) => Promise<{
@@ -58,10 +58,10 @@ export type IFilterDirector = IBaseDirector<IFilterAdapter> & {
58
58
  }>;
59
59
 
60
60
  productFacetedSearch: (
61
- productIds: Array<string>,
61
+ productIds: string[],
62
62
  searchConfiguration: SearchConfiguration,
63
63
  unchainedAPI: { modules: Modules },
64
- ) => Promise<Array<string>>;
64
+ ) => Promise<string[]>;
65
65
  };
66
66
 
67
67
  const baseDirector = BaseDirector<IFilterAdapter>('FilterDirector', {
@@ -97,14 +97,14 @@ export const FilterDirector: IFilterDirector = {
97
97
  },
98
98
 
99
99
  searchAssortments: async (params, options) => {
100
- return reduceAdapters<Array<string>>(async (lastSearchPromise, adapter) => {
100
+ return reduceAdapters<string[]>(async (lastSearchPromise, adapter) => {
101
101
  const assortmentIds = await lastSearchPromise;
102
102
  return adapter.searchAssortments({ assortmentIds }, options);
103
103
  }, params.assortmentIds);
104
104
  },
105
105
 
106
106
  searchProducts: async (params, options) => {
107
- return reduceAdapters<Array<string>>(async (lastSearchPromise, adapter) => {
107
+ return reduceAdapters<string[]>(async (lastSearchPromise, adapter) => {
108
108
  const productIds = await lastSearchPromise;
109
109
  return adapter.searchProducts({ productIds }, options);
110
110
  }, params.productIds);
@@ -155,7 +155,7 @@ export const FilterDirector: IFilterDirector = {
155
155
  async buildProductIdMap(
156
156
  filter: Filter,
157
157
  unchainedAPI: { modules: Modules },
158
- ): Promise<[Array<string>, Record<string, Array<string>>]> {
158
+ ): Promise<[string[], Record<string, string[]>]> {
159
159
  const allProductIds = await this.findProductIds(filter, {}, unchainedAPI);
160
160
  const productIdsMap =
161
161
  filter.type === FilterType.SWITCH
@@ -176,10 +176,10 @@ export const FilterDirector: IFilterDirector = {
176
176
 
177
177
  async filterProductIds(
178
178
  filter: Filter,
179
- { values, forceLiveCollection }: { values: Array<string>; forceLiveCollection?: boolean },
179
+ { values, forceLiveCollection }: { values: string[]; forceLiveCollection?: boolean },
180
180
  unchainedAPI: { modules: Modules },
181
181
  ) {
182
- const [allProductIds, keyToProductIdMap]: [Array<string>, Record<string, Array<string>>] =
182
+ const [allProductIds, keyToProductIdMap]: [string[], Record<string, string[]>] =
183
183
  (!forceLiveCollection && (await filtersSettings.getCachedProductIds(filter._id))) ||
184
184
  (await this.buildProductIdMap(filter, unchainedAPI));
185
185
 
@@ -199,10 +199,10 @@ export const FilterDirector: IFilterDirector = {
199
199
  },
200
200
 
201
201
  async productFacetedSearch(
202
- productIds: Array<string>,
202
+ productIds: string[],
203
203
  searchConfiguration: SearchConfiguration,
204
204
  unchainedAPI: { modules: Modules },
205
- ): Promise<Array<string>> {
205
+ ): Promise<string[]> {
206
206
  const { searchQuery, filterSelector, forceLiveCollection } = searchConfiguration;
207
207
  const { modules } = unchainedAPI;
208
208
  if (!searchQuery || !searchQuery.filterQuery) return productIds;
@@ -0,0 +1,54 @@
1
+ import later, { ScheduleData } from '@breejs/later';
2
+ import { BaseWorker, IWorker } from './BaseWorker.js';
3
+
4
+ const { NODE_ENV } = process.env;
5
+
6
+ export interface IntervalWorkerParams {
7
+ workerId?: string;
8
+ batchCount?: number;
9
+ schedule?: ScheduleData;
10
+ }
11
+
12
+ const defaultSchedule = later.parse.text(
13
+ NODE_ENV !== 'production' ? 'every 2 seconds' : 'every 30 seconds',
14
+ );
15
+
16
+ export const scheduleToInterval = (schedule: ScheduleData) => {
17
+ const referenceDate = new Date(1000);
18
+ const [one, two] = later.schedule(schedule).next(2, referenceDate) as Date[];
19
+ const diff = new Date(two).getTime() - new Date(one).getTime();
20
+ return Math.min(1000 * 60 * 60, diff); // at least once every hour!
21
+ };
22
+
23
+ export const IntervalWorker: IWorker<IntervalWorkerParams> = {
24
+ ...BaseWorker,
25
+
26
+ key: 'shop.unchained.worker.cron',
27
+ label: 'Allocates work on fixed intervals with native node setInterval',
28
+ version: '1.0.0',
29
+ type: 'CRON',
30
+
31
+ actions: ({ workerId, batchCount = 0, schedule = defaultSchedule }, unchainedAPI) => {
32
+ const baseWorkerActions = BaseWorker.actions({ workerId, worker: IntervalWorker }, unchainedAPI);
33
+
34
+ const intervalDelay = scheduleToInterval(schedule);
35
+ let intervalHandle: NodeJS.Timeout;
36
+
37
+ return {
38
+ ...baseWorkerActions,
39
+
40
+ start() {
41
+ intervalHandle = setInterval(() => {
42
+ baseWorkerActions.process({
43
+ maxWorkItemCount: batchCount,
44
+ referenceDate: IntervalWorker.getFloorDate(),
45
+ });
46
+ }, intervalDelay);
47
+ },
48
+
49
+ stop() {
50
+ clearInterval(intervalHandle);
51
+ },
52
+ };
53
+ },
54
+ };
@@ -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
  },