@unchainedshop/core 5.0.0-alpha.1 → 5.0.0-alpha.11

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 (238) hide show
  1. package/README.md +92 -546
  2. package/lib/bulk-exporter/createBulkExporter.js +1 -1
  3. package/lib/bulk-exporter/handlers/exportProductsHandler.js +2 -2
  4. package/lib/bulk-exporter/handlers/exportUsersHandler.js +1 -0
  5. package/lib/bulk-importer/handlers/assortment/create.js +1 -3
  6. package/lib/bulk-importer/handlers/assortment/update.js +1 -1
  7. package/lib/bulk-importer/handlers/product/create.d.ts +150 -35
  8. package/lib/bulk-importer/handlers/product/create.js +35 -16
  9. package/lib/bulk-importer/handlers/product/update.d.ts +78 -36
  10. package/lib/bulk-importer/handlers/product/update.js +8 -48
  11. package/lib/core-index.d.ts +1 -2
  12. package/lib/core-index.js +2 -18
  13. package/lib/directors/BaseDiscountAdapter.d.ts +3 -0
  14. package/lib/directors/BaseDiscountDirector.d.ts +2 -2
  15. package/lib/directors/BaseDiscountDirector.js +7 -9
  16. package/lib/directors/BasePricingDirector.d.ts +2 -2
  17. package/lib/directors/BasePricingDirector.js +3 -6
  18. package/lib/directors/BasePricingSheet.d.ts +2 -0
  19. package/lib/directors/BaseWorker.js +3 -2
  20. package/lib/directors/DeliveryDirector.d.ts +1 -1
  21. package/lib/directors/DeliveryDirector.js +2 -12
  22. package/lib/directors/DeliveryPricingDirector.js +1 -10
  23. package/lib/directors/DeliveryPricingSheet.js +9 -4
  24. package/lib/directors/EnrollmentAdapter.d.ts +11 -1
  25. package/lib/directors/EnrollmentAdapter.js +7 -2
  26. package/lib/directors/EnrollmentDirector.d.ts +3 -2
  27. package/lib/directors/EnrollmentDirector.js +9 -19
  28. package/lib/directors/FileDirector.d.ts +4 -4
  29. package/lib/directors/FileDirector.js +2 -13
  30. package/lib/directors/FilterDirector.d.ts +1 -1
  31. package/lib/directors/FilterDirector.js +25 -32
  32. package/lib/directors/OrderDiscountDirector.d.ts +1 -15
  33. package/lib/directors/OrderDiscountDirector.js +1 -13
  34. package/lib/directors/OrderPricingDirector.js +1 -10
  35. package/lib/directors/OrderPricingSheet.d.ts +1 -0
  36. package/lib/directors/OrderPricingSheet.js +16 -17
  37. package/lib/directors/PaymentDirector.d.ts +1 -1
  38. package/lib/directors/PaymentDirector.js +2 -12
  39. package/lib/directors/PaymentPricingDirector.js +1 -10
  40. package/lib/directors/PaymentPricingSheet.js +9 -4
  41. package/lib/directors/ProductDiscountDirector.d.ts +1 -15
  42. package/lib/directors/ProductDiscountDirector.js +1 -13
  43. package/lib/directors/ProductPricingAdapter.d.ts +1 -0
  44. package/lib/directors/ProductPricingDirector.js +2 -10
  45. package/lib/directors/ProductPricingSheet.js +7 -4
  46. package/lib/directors/QuotationAdapter.js +5 -2
  47. package/lib/directors/QuotationDirector.d.ts +1 -1
  48. package/lib/directors/QuotationDirector.js +2 -14
  49. package/lib/directors/WarehousingDirector.js +16 -34
  50. package/lib/directors/WorkerDirector.d.ts +7 -1
  51. package/lib/directors/WorkerDirector.js +29 -29
  52. package/lib/directors/registryDirector.d.ts +2 -0
  53. package/lib/directors/registryDirector.js +6 -0
  54. package/lib/errors.d.ts +1 -0
  55. package/lib/errors.js +5 -0
  56. package/lib/factory/index.d.ts +12 -1
  57. package/lib/factory/index.js +12 -1
  58. package/lib/factory/registerAssortmentSearchFilter.d.ts +2 -1
  59. package/lib/factory/registerAssortmentSearchFilter.js +6 -3
  60. package/lib/factory/registerDeliveryPricing.d.ts +7 -0
  61. package/lib/factory/registerDeliveryPricing.js +30 -0
  62. package/lib/factory/registerDeliveryProvider.d.ts +12 -0
  63. package/lib/factory/registerDeliveryProvider.js +46 -0
  64. package/lib/factory/registerEnrollment.d.ts +25 -0
  65. package/lib/factory/registerEnrollment.js +41 -0
  66. package/lib/factory/registerFileAdapter.d.ts +17 -0
  67. package/lib/factory/registerFileAdapter.js +24 -0
  68. package/lib/factory/registerOrderDiscount.d.ts +13 -0
  69. package/lib/factory/registerOrderDiscount.js +39 -0
  70. package/lib/factory/registerOrderPricing.d.ts +7 -0
  71. package/lib/factory/registerOrderPricing.js +30 -0
  72. package/lib/factory/registerPaymentPricing.d.ts +7 -0
  73. package/lib/factory/registerPaymentPricing.js +30 -0
  74. package/lib/factory/registerPaymentProvider.d.ts +15 -0
  75. package/lib/factory/registerPaymentProvider.js +53 -0
  76. package/lib/factory/registerProductDiscount.d.ts +20 -0
  77. package/lib/factory/registerProductDiscount.js +47 -0
  78. package/lib/factory/registerProductDiscoverabilityFilter.d.ts +2 -1
  79. package/lib/factory/registerProductDiscoverabilityFilter.js +6 -3
  80. package/lib/factory/registerProductPricing.d.ts +7 -0
  81. package/lib/factory/registerProductPricing.js +30 -0
  82. package/lib/factory/registerProductSearchFilter.d.ts +2 -1
  83. package/lib/factory/registerProductSearchFilter.js +4 -3
  84. package/lib/factory/registerQuotation.d.ts +13 -0
  85. package/lib/factory/registerQuotation.js +53 -0
  86. package/lib/factory/registerVirtualWarehousing.js +1 -1
  87. package/lib/factory/registerWorker.js +1 -1
  88. package/lib/plugins/PluginRegistry.d.ts +2 -1
  89. package/lib/plugins/PluginRegistry.js +19 -4
  90. package/lib/services/addCartQuotation.d.ts +9 -13
  91. package/lib/services/addCartQuotation.js +43 -38
  92. package/lib/services/addMultipleCartProducts.js +3 -2
  93. package/lib/services/bulkAssignProductsToAssortment.d.ts +8 -0
  94. package/lib/services/bulkAssignProductsToAssortment.js +11 -0
  95. package/lib/services/bulkDeleteUsers.d.ts +7 -0
  96. package/lib/services/bulkDeleteUsers.js +11 -0
  97. package/lib/services/bulkRemoveFilters.d.ts +7 -0
  98. package/lib/services/bulkRemoveFilters.js +10 -0
  99. package/lib/services/bulkRemoveProducts.d.ts +7 -0
  100. package/lib/services/bulkRemoveProducts.js +23 -0
  101. package/lib/services/bulkSetFilterActive.d.ts +8 -0
  102. package/lib/services/bulkSetFilterActive.js +12 -0
  103. package/lib/services/calculateDiscountTotal.d.ts +5 -1
  104. package/lib/services/calculateDiscountTotal.js +36 -28
  105. package/lib/services/checkoutOrder.js +8 -0
  106. package/lib/services/createFilter.d.ts +3 -0
  107. package/lib/services/createFilter.js +6 -0
  108. package/lib/services/createFilterOption.d.ts +5 -0
  109. package/lib/services/createFilterOption.js +8 -0
  110. package/lib/services/createSignedURL.js +2 -1
  111. package/lib/services/deleteCart.d.ts +2 -0
  112. package/lib/services/deleteCart.js +7 -0
  113. package/lib/services/deleteUser.js +2 -5
  114. package/lib/services/index.d.ts +32 -1
  115. package/lib/services/index.js +32 -1
  116. package/lib/services/initCartProviders.js +1 -0
  117. package/lib/services/initializeEnrollment.d.ts +1 -1
  118. package/lib/services/initializeEnrollment.js +11 -0
  119. package/lib/services/isTokenInvalidateable.d.ts +3 -1
  120. package/lib/services/isTokenInvalidateable.js +2 -2
  121. package/lib/services/loadFilterOptions.js +3 -3
  122. package/lib/services/migrateOrderCart.js +2 -2
  123. package/lib/services/migrateUserData.js +3 -0
  124. package/lib/services/processEnrollment.js +8 -4
  125. package/lib/services/processOrder.js +7 -6
  126. package/lib/services/processQuotation.js +11 -13
  127. package/lib/services/proposeQuotation.js +3 -0
  128. package/lib/services/removeFilterOption.d.ts +6 -0
  129. package/lib/services/removeFilterOption.js +8 -0
  130. package/lib/services/removeProduct.js +2 -1
  131. package/lib/services/reserveOrderDiscountsForCheckout.d.ts +5 -0
  132. package/lib/services/reserveOrderDiscountsForCheckout.js +34 -0
  133. package/lib/services/reserveOrderQuotationsForCheckout.d.ts +8 -0
  134. package/lib/services/reserveOrderQuotationsForCheckout.js +49 -0
  135. package/lib/services/simulateConfigurablePriceRange.js +1 -1
  136. package/lib/services/simulateDeliveryPricing.js +1 -1
  137. package/lib/services/simulatePaymentPricing.js +1 -1
  138. package/lib/services/simulateProductDispatching.d.ts +3 -1
  139. package/lib/services/simulateProductDispatching.js +3 -3
  140. package/lib/services/simulateProductInventory.d.ts +3 -1
  141. package/lib/services/simulateProductInventory.js +3 -3
  142. package/lib/services/supportedDeliveryProviders.js +9 -0
  143. package/lib/services/supportedPaymentProviders.js +9 -0
  144. package/lib/services/supportedWarehousingProviders.js +9 -0
  145. package/lib/services/suspendEnrollment.d.ts +5 -0
  146. package/lib/services/suspendEnrollment.js +21 -0
  147. package/lib/services/terminateEnrollment.d.ts +6 -2
  148. package/lib/services/terminateEnrollment.js +27 -7
  149. package/lib/services/updateCalculation.js +2 -1
  150. package/lib/services/updateCartItem.d.ts +7 -7
  151. package/lib/services/updateCartItem.js +28 -25
  152. package/lib/services/updateEnrollmentPlan.d.ts +5 -0
  153. package/lib/services/updateEnrollmentPlan.js +26 -0
  154. package/lib/services/updateFilter.d.ts +3 -0
  155. package/lib/services/updateFilter.js +8 -0
  156. package/lib/services/uploadFileFromStream.js +2 -1
  157. package/lib/services/validateOrder.js +13 -9
  158. package/package.json +29 -23
  159. package/lib/errors/common.d.ts +0 -568
  160. package/lib/errors/common.js +0 -789
  161. package/lib/errors/index.d.ts +0 -1
  162. package/lib/errors/index.js +0 -1
  163. package/lib/services/addCartDiscount.d.ts +0 -10
  164. package/lib/services/addCartDiscount.js +0 -27
  165. package/lib/services/addCartItem.d.ts +0 -15
  166. package/lib/services/addCartItem.js +0 -41
  167. package/lib/services/addEmail.d.ts +0 -7
  168. package/lib/services/addEmail.js +0 -17
  169. package/lib/services/addProductAssignment.d.ts +0 -3
  170. package/lib/services/addProductAssignment.js +0 -63
  171. package/lib/services/authenticateWithPassword.d.ts +0 -15
  172. package/lib/services/authenticateWithPassword.js +0 -34
  173. package/lib/services/changePassword.d.ts +0 -10
  174. package/lib/services/changePassword.js +0 -19
  175. package/lib/services/countOrdersWithFilters.d.ts +0 -3
  176. package/lib/services/countOrdersWithFilters.js +0 -25
  177. package/lib/services/createAssortment.d.ts +0 -7
  178. package/lib/services/createAssortment.js +0 -10
  179. package/lib/services/createBookmark.d.ts +0 -8
  180. package/lib/services/createBookmark.js +0 -21
  181. package/lib/services/createDeliveryProvider.d.ts +0 -6
  182. package/lib/services/createDeliveryProvider.js +0 -19
  183. package/lib/services/createEnrollment.d.ts +0 -17
  184. package/lib/services/createEnrollment.js +0 -33
  185. package/lib/services/createProduct.d.ts +0 -7
  186. package/lib/services/createProduct.js +0 -8
  187. package/lib/services/createProductBundleItem.d.ts +0 -5
  188. package/lib/services/createProductBundleItem.js +0 -25
  189. package/lib/services/createProductReview.d.ts +0 -8
  190. package/lib/services/createProductReview.js +0 -12
  191. package/lib/services/deliverOrder.d.ts +0 -5
  192. package/lib/services/deliverOrder.js +0 -26
  193. package/lib/services/findActiveWorkTypes.d.ts +0 -2
  194. package/lib/services/findActiveWorkTypes.js +0 -6
  195. package/lib/services/findDeliveryInterfaces.d.ts +0 -7
  196. package/lib/services/findDeliveryInterfaces.js +0 -13
  197. package/lib/services/findOrdersWithFilters.d.ts +0 -9
  198. package/lib/services/findOrdersWithFilters.js +0 -25
  199. package/lib/services/findPaymentInterfaces.d.ts +0 -7
  200. package/lib/services/findPaymentInterfaces.js +0 -13
  201. package/lib/services/findWarehousingInterfaces.d.ts +0 -7
  202. package/lib/services/findWarehousingInterfaces.js +0 -13
  203. package/lib/services/getDeliveryDiscounts.d.ts +0 -8
  204. package/lib/services/getDeliveryDiscounts.js +0 -14
  205. package/lib/services/getPaymentDiscounts.d.ts +0 -8
  206. package/lib/services/getPaymentDiscounts.js +0 -14
  207. package/lib/services/getShopInfo.d.ts +0 -25
  208. package/lib/services/getShopInfo.js +0 -47
  209. package/lib/services/impersonateUser.d.ts +0 -8
  210. package/lib/services/impersonateUser.js +0 -20
  211. package/lib/services/loginAsGuest.d.ts +0 -10
  212. package/lib/services/loginAsGuest.js +0 -19
  213. package/lib/services/obfuscateWorkerData.d.ts +0 -4
  214. package/lib/services/obfuscateWorkerData.js +0 -4
  215. package/lib/services/orderPricingAccessors.d.ts +0 -18
  216. package/lib/services/orderPricingAccessors.js +0 -29
  217. package/lib/services/payOrder.d.ts +0 -5
  218. package/lib/services/payOrder.js +0 -25
  219. package/lib/services/registerUser.d.ts +0 -14
  220. package/lib/services/registerUser.js +0 -44
  221. package/lib/services/removeBookmark.d.ts +0 -6
  222. package/lib/services/removeBookmark.js +0 -10
  223. package/lib/services/removeCartItem.d.ts +0 -6
  224. package/lib/services/removeCartItem.js +0 -19
  225. package/lib/services/resetPasswordWithMigration.d.ts +0 -14
  226. package/lib/services/resetPasswordWithMigration.js +0 -31
  227. package/lib/services/resolveWorkType.d.ts +0 -1
  228. package/lib/services/resolveWorkType.js +0 -7
  229. package/lib/services/searchProductsWithAssortment.d.ts +0 -19
  230. package/lib/services/searchProductsWithAssortment.js +0 -17
  231. package/lib/services/toggleBookmark.d.ts +0 -8
  232. package/lib/services/toggleBookmark.js +0 -33
  233. package/lib/services/updateCart.d.ts +0 -15
  234. package/lib/services/updateCart.js +0 -27
  235. package/lib/services/updateEnrollment.d.ts +0 -13
  236. package/lib/services/updateEnrollment.js +0 -36
  237. package/lib/services/verifyEmailWithMigration.d.ts +0 -15
  238. package/lib/services/verifyEmailWithMigration.js +0 -23
@@ -15,6 +15,7 @@ import { initCartProvidersService } from './initCartProviders.ts';
15
15
  import { updateCalculationService } from './updateCalculation.ts';
16
16
  import { supportedDeliveryProvidersService } from './supportedDeliveryProviders.ts';
17
17
  import { deleteUserService } from './deleteUser.ts';
18
+ import { deleteCartService } from './deleteCart.ts';
18
19
  import { supportedPaymentProvidersService } from './supportedPaymentProviders.ts';
19
20
  import { supportedWarehousingProvidersService } from './supportedWarehousingProviders.ts';
20
21
  import { createEnrollmentFromCheckoutService } from './createEnrollmentFromCheckout.ts';
@@ -23,12 +24,15 @@ import { searchProductsService } from './searchProducts.ts';
23
24
  import { calculateDiscountTotalService } from './calculateDiscountTotal.ts';
24
25
  import { registerPaymentCredentialsService } from './registerPaymentCredentials.ts';
25
26
  import { processOrderService } from './processOrder.ts';
27
+ import { processEnrollmentService } from './processEnrollment.ts';
26
28
  import { checkoutOrderService } from './checkoutOrder.ts';
27
29
  import { confirmOrderService } from './confirmOrder.ts';
28
30
  import { rejectOrderService } from './rejectOrder.ts';
29
31
  import { discountedEntitiesService } from './discountedEntities.ts';
30
32
  import { createManualOrderDiscountService } from './createManualOrderDiscount.ts';
31
33
  import { initializeEnrollmentService } from './initializeEnrollment.ts';
34
+ import { suspendEnrollmentService } from './suspendEnrollment.ts';
35
+ import { updateEnrollmentPlanService } from './updateEnrollmentPlan.ts';
32
36
  import { activateEnrollmentService } from './activateEnrollment.ts';
33
37
  import { terminateEnrollmentService } from './terminateEnrollment.ts';
34
38
  import { invalidateFilterCacheService } from './invalidateFilterCache.ts';
@@ -40,8 +44,14 @@ import { verifyQuotationService } from './verifyQuotation.ts';
40
44
  import { loadFiltersService } from './loadFilters.ts';
41
45
  import { loadFilterOptionsService } from './loadFilterOptions.ts';
42
46
  import { removeFilterService } from './removeFilter.ts';
47
+ import { createFilterService } from './createFilter.ts';
48
+ import { updateFilterService } from './updateFilter.ts';
49
+ import { createFilterOptionService } from './createFilterOption.ts';
50
+ import { removeFilterOptionService } from './removeFilterOption.ts';
43
51
  import { removeCartDiscountService } from './removeCartDiscount.ts';
44
52
  import { addMultipleCartProductsService } from './addMultipleCartProducts.ts';
53
+ import { addCartQuotationService } from './addCartQuotation.ts';
54
+ import { updateCartItemService } from './updateCartItem.ts';
45
55
  import { ercMetadataService } from './ercMetadata.ts';
46
56
  import { simulateProductPricingService } from './simulateProductPricing.ts';
47
57
  import { simulateProductDispatchingService } from './simulateProductDispatching.ts';
@@ -57,6 +67,11 @@ import { simulateConfigurablePriceRangeService } from './simulateConfigurablePri
57
67
  import { createFileDownloadURLService } from './createFileDownloadURL.ts';
58
68
  import { resolveTokenStatusService } from './resolveTokenStatus.ts';
59
69
  import { isTokenInvalidateableService } from './isTokenInvalidateable.ts';
70
+ import { bulkRemoveProductsService } from './bulkRemoveProducts.ts';
71
+ import { bulkRemoveFiltersService } from './bulkRemoveFilters.ts';
72
+ import { bulkDeleteUsersService } from './bulkDeleteUsers.ts';
73
+ import { bulkSetFilterActiveService } from './bulkSetFilterActive.ts';
74
+ import { bulkAssignProductsToAssortmentService } from './bulkAssignProductsToAssortment.ts';
60
75
  export type ServiceInterface = (this: Modules, ...args: any[]) => Promise<any> | any;
61
76
  export type Bound<T extends ServiceInterface> = OmitThisParameter<T>;
62
77
  export type CustomServices = Record<string, ServiceInterface | Record<string, ServiceInterface>>;
@@ -77,6 +92,7 @@ export default function initServices(modules: Modules, customServices?: CustomSe
77
92
  registerPaymentCredentials: Bound<typeof registerPaymentCredentialsService>;
78
93
  calculateDiscountTotal: Bound<typeof calculateDiscountTotalService>;
79
94
  migrateOrderCarts: Bound<typeof migrateOrderCartsService>;
95
+ deleteCart: Bound<typeof deleteCartService>;
80
96
  nextUserCart: Bound<typeof nextUserCartService>;
81
97
  findOrInitCart: Bound<typeof findOrInitCartService>;
82
98
  initCartProviders: Bound<typeof initCartProvidersService>;
@@ -93,27 +109,36 @@ export default function initServices(modules: Modules, customServices?: CustomSe
93
109
  resolveOrderItemDispatches: Bound<typeof resolveOrderItemDispatchesService>;
94
110
  removeCartDiscount: Bound<typeof removeCartDiscountService>;
95
111
  addMultipleCartProducts: Bound<typeof addMultipleCartProductsService>;
112
+ addCartQuotation: Bound<typeof addCartQuotationService>;
113
+ updateCartItem: Bound<typeof updateCartItemService>;
96
114
  };
97
115
  products: {
98
116
  simulateProductPricing: Bound<typeof simulateProductPricingService>;
99
117
  simulateProductDispatching: Bound<typeof simulateProductDispatchingService>;
100
118
  simulateProductInventory: Bound<typeof simulateProductInventoryService>;
101
119
  removeProduct: Bound<typeof removeProductService>;
120
+ bulkRemoveProducts: Bound<typeof bulkRemoveProductsService>;
102
121
  findProductSiblings: Bound<typeof findProductSiblingsService>;
103
122
  simulateConfigurablePriceRange: Bound<typeof simulateConfigurablePriceRangeService>;
104
123
  };
124
+ assortments: {
125
+ bulkAssignProductsToAssortment: Bound<typeof bulkAssignProductsToAssortmentService>;
126
+ };
105
127
  users: {
106
128
  migrateUserData: Bound<typeof migrateUserDataService>;
107
129
  updateUserAvatarAfterUpload: Bound<typeof updateUserAvatarAfterUploadService>;
108
130
  deleteUser: Bound<typeof deleteUserService>;
131
+ bulkDeleteUsers: Bound<typeof bulkDeleteUsersService>;
109
132
  };
110
133
  enrollments: {
111
134
  createEnrollmentFromCheckout: Bound<typeof createEnrollmentFromCheckoutService>;
112
135
  generateOrderFromEnrollment: Bound<typeof generateOrderFromEnrollmentService>;
113
- processEnrollment: Bound<typeof processOrderService>;
136
+ processEnrollment: Bound<typeof processEnrollmentService>;
114
137
  initializeEnrollment: Bound<typeof initializeEnrollmentService>;
115
138
  activateEnrollment: Bound<typeof activateEnrollmentService>;
116
139
  terminateEnrollment: Bound<typeof terminateEnrollmentService>;
140
+ suspendEnrollment: Bound<typeof suspendEnrollmentService>;
141
+ updateEnrollmentPlan: Bound<typeof updateEnrollmentPlanService>;
117
142
  };
118
143
  quotations: {
119
144
  fulfillQuotation: Bound<typeof fulfillQuotationService>;
@@ -129,6 +154,12 @@ export default function initServices(modules: Modules, customServices?: CustomSe
129
154
  loadFilters: Bound<typeof loadFiltersService>;
130
155
  loadFilterOptions: Bound<typeof loadFilterOptionsService>;
131
156
  removeFilter: Bound<typeof removeFilterService>;
157
+ createFilter: Bound<typeof createFilterService>;
158
+ updateFilter: Bound<typeof updateFilterService>;
159
+ createFilterOption: Bound<typeof createFilterOptionService>;
160
+ removeFilterOption: Bound<typeof removeFilterOptionService>;
161
+ bulkRemoveFilters: Bound<typeof bulkRemoveFiltersService>;
162
+ bulkSetFilterActive: Bound<typeof bulkSetFilterActiveService>;
132
163
  };
133
164
  warehousing: {
134
165
  ercMetadata: Bound<typeof ercMetadataService>;
@@ -14,6 +14,7 @@ import { initCartProvidersService } from "./initCartProviders.js";
14
14
  import { updateCalculationService } from "./updateCalculation.js";
15
15
  import { supportedDeliveryProvidersService } from "./supportedDeliveryProviders.js";
16
16
  import { deleteUserService } from "./deleteUser.js";
17
+ import { deleteCartService } from "./deleteCart.js";
17
18
  import { supportedPaymentProvidersService } from "./supportedPaymentProviders.js";
18
19
  import { supportedWarehousingProvidersService } from "./supportedWarehousingProviders.js";
19
20
  import { createEnrollmentFromCheckoutService } from "./createEnrollmentFromCheckout.js";
@@ -22,12 +23,15 @@ import { searchProductsService } from "./searchProducts.js";
22
23
  import { calculateDiscountTotalService } from "./calculateDiscountTotal.js";
23
24
  import { registerPaymentCredentialsService } from "./registerPaymentCredentials.js";
24
25
  import { processOrderService } from "./processOrder.js";
26
+ import { processEnrollmentService } from "./processEnrollment.js";
25
27
  import { checkoutOrderService } from "./checkoutOrder.js";
26
28
  import { confirmOrderService } from "./confirmOrder.js";
27
29
  import { rejectOrderService } from "./rejectOrder.js";
28
30
  import { discountedEntitiesService } from "./discountedEntities.js";
29
31
  import { createManualOrderDiscountService } from "./createManualOrderDiscount.js";
30
32
  import { initializeEnrollmentService } from "./initializeEnrollment.js";
33
+ import { suspendEnrollmentService } from "./suspendEnrollment.js";
34
+ import { updateEnrollmentPlanService } from "./updateEnrollmentPlan.js";
31
35
  import { activateEnrollmentService } from "./activateEnrollment.js";
32
36
  import { terminateEnrollmentService } from "./terminateEnrollment.js";
33
37
  import { invalidateFilterCacheService } from "./invalidateFilterCache.js";
@@ -39,8 +43,14 @@ import { verifyQuotationService } from "./verifyQuotation.js";
39
43
  import { loadFiltersService } from "./loadFilters.js";
40
44
  import { loadFilterOptionsService } from "./loadFilterOptions.js";
41
45
  import { removeFilterService } from "./removeFilter.js";
46
+ import { createFilterService } from "./createFilter.js";
47
+ import { updateFilterService } from "./updateFilter.js";
48
+ import { createFilterOptionService } from "./createFilterOption.js";
49
+ import { removeFilterOptionService } from "./removeFilterOption.js";
42
50
  import { removeCartDiscountService } from "./removeCartDiscount.js";
43
51
  import { addMultipleCartProductsService } from "./addMultipleCartProducts.js";
52
+ import { addCartQuotationService } from "./addCartQuotation.js";
53
+ import { updateCartItemService } from "./updateCartItem.js";
44
54
  import { ercMetadataService } from "./ercMetadata.js";
45
55
  import { simulateProductPricingService } from "./simulateProductPricing.js";
46
56
  import { simulateProductDispatchingService } from "./simulateProductDispatching.js";
@@ -56,6 +66,11 @@ import { simulateConfigurablePriceRangeService } from "./simulateConfigurablePri
56
66
  import { createFileDownloadURLService } from "./createFileDownloadURL.js";
57
67
  import { resolveTokenStatusService } from "./resolveTokenStatus.js";
58
68
  import { isTokenInvalidateableService } from "./isTokenInvalidateable.js";
69
+ import { bulkRemoveProductsService } from "./bulkRemoveProducts.js";
70
+ import { bulkRemoveFiltersService } from "./bulkRemoveFilters.js";
71
+ import { bulkDeleteUsersService } from "./bulkDeleteUsers.js";
72
+ import { bulkSetFilterActiveService } from "./bulkSetFilterActive.js";
73
+ import { bulkAssignProductsToAssortmentService } from "./bulkAssignProductsToAssortment.js";
59
74
  function bindMethodsToModules(modules) {
60
75
  return {
61
76
  get(target, prop, receiver) {
@@ -88,6 +103,7 @@ export default function initServices(modules, customServices = {}) {
88
103
  registerPaymentCredentials: registerPaymentCredentialsService,
89
104
  calculateDiscountTotal: calculateDiscountTotalService,
90
105
  migrateOrderCarts: migrateOrderCartsService,
106
+ deleteCart: deleteCartService,
91
107
  nextUserCart: nextUserCartService,
92
108
  findOrInitCart: findOrInitCartService,
93
109
  initCartProviders: initCartProvidersService,
@@ -104,27 +120,36 @@ export default function initServices(modules, customServices = {}) {
104
120
  resolveOrderItemDispatches: resolveOrderItemDispatchesService,
105
121
  removeCartDiscount: removeCartDiscountService,
106
122
  addMultipleCartProducts: addMultipleCartProductsService,
123
+ addCartQuotation: addCartQuotationService,
124
+ updateCartItem: updateCartItemService,
107
125
  },
108
126
  products: {
109
127
  simulateProductPricing: simulateProductPricingService,
110
128
  simulateProductDispatching: simulateProductDispatchingService,
111
129
  simulateProductInventory: simulateProductInventoryService,
112
130
  removeProduct: removeProductService,
131
+ bulkRemoveProducts: bulkRemoveProductsService,
113
132
  findProductSiblings: findProductSiblingsService,
114
133
  simulateConfigurablePriceRange: simulateConfigurablePriceRangeService,
115
134
  },
135
+ assortments: {
136
+ bulkAssignProductsToAssortment: bulkAssignProductsToAssortmentService,
137
+ },
116
138
  users: {
117
139
  migrateUserData: migrateUserDataService,
118
140
  updateUserAvatarAfterUpload: updateUserAvatarAfterUploadService,
119
141
  deleteUser: deleteUserService,
142
+ bulkDeleteUsers: bulkDeleteUsersService,
120
143
  },
121
144
  enrollments: {
122
145
  createEnrollmentFromCheckout: createEnrollmentFromCheckoutService,
123
146
  generateOrderFromEnrollment: generateOrderFromEnrollmentService,
124
- processEnrollment: processOrderService,
147
+ processEnrollment: processEnrollmentService,
125
148
  initializeEnrollment: initializeEnrollmentService,
126
149
  activateEnrollment: activateEnrollmentService,
127
150
  terminateEnrollment: terminateEnrollmentService,
151
+ suspendEnrollment: suspendEnrollmentService,
152
+ updateEnrollmentPlan: updateEnrollmentPlanService,
128
153
  },
129
154
  quotations: {
130
155
  fulfillQuotation: fulfillQuotationService,
@@ -140,6 +165,12 @@ export default function initServices(modules, customServices = {}) {
140
165
  loadFilters: loadFiltersService,
141
166
  loadFilterOptions: loadFilterOptionsService,
142
167
  removeFilter: removeFilterService,
168
+ createFilter: createFilterService,
169
+ updateFilter: updateFilterService,
170
+ createFilterOption: createFilterOptionService,
171
+ removeFilterOption: removeFilterOptionService,
172
+ bulkRemoveFilters: bulkRemoveFiltersService,
173
+ bulkSetFilterActive: bulkSetFilterActiveService,
143
174
  },
144
175
  warehousing: {
145
176
  ercMetadata: ercMetadataService,
@@ -39,6 +39,7 @@ export async function initCartProvidersService(order) {
39
39
  const paymentCredentials = await this.payment.paymentCredentials.findPaymentCredentials({ userId: updatedOrder.userId, isPreferred: true }, {
40
40
  sort: {
41
41
  created: -1,
42
+ _id: -1,
42
43
  },
43
44
  });
44
45
  const defaultOrderPaymentProvider = await paymentSettings.determineDefaultProvider({
@@ -1,4 +1,4 @@
1
- import type { Enrollment } from '@unchainedshop/core-enrollments';
1
+ import { type Enrollment } from '@unchainedshop/core-enrollments';
2
2
  import type { Modules } from '../modules.ts';
3
3
  export declare function initializeEnrollmentService(this: Modules, enrollment: Enrollment, params: {
4
4
  orderIdForFirstPeriod?: string;
@@ -1,3 +1,4 @@
1
+ import { addToDate } from '@unchainedshop/core-enrollments';
1
2
  import { EnrollmentDirector } from "../core-index.js";
2
3
  import { processEnrollmentService } from "./processEnrollment.js";
3
4
  import { addMessageService } from "./addMessage.js";
@@ -14,6 +15,16 @@ export async function initializeEnrollmentService(enrollment, params) {
14
15
  orderId: params.orderIdForFirstPeriod,
15
16
  }));
16
17
  }
18
+ const { minimumCommitmentPeriods, billingInterval, billingIntervalCount } = product?.plan || {};
19
+ if (minimumCommitmentPeriods && billingInterval) {
20
+ const contractStartDate = updatedEnrollment.periods.find(({ isTrial }) => !isTrial)?.start || new Date();
21
+ updatedEnrollment = (await this.enrollments.updateCommitment(enrollment._id, {
22
+ contractStartDate,
23
+ minimumCommitmentEnd: addToDate(contractStartDate, {
24
+ [billingInterval.toLowerCase()]: (billingIntervalCount || 1) * minimumCommitmentPeriods,
25
+ }),
26
+ }));
27
+ }
17
28
  const processedEnrollment = await processEnrollmentService.bind(this)(updatedEnrollment);
18
29
  const user = await this.users.findUserById(enrollment.userId);
19
30
  const locale = this.users.userLocale(user);
@@ -1,5 +1,7 @@
1
1
  import type { TokenSurrogate } from '@unchainedshop/core-warehousing';
2
+ import type { Product } from '@unchainedshop/core-products';
2
3
  import type { Modules } from '../modules.ts';
3
- export declare function isTokenInvalidateableService(this: Modules, { token, }: {
4
+ export declare function isTokenInvalidateableService(this: Modules, { token, product: providedProduct, }: {
4
5
  token: TokenSurrogate;
6
+ product?: Product;
5
7
  }): Promise<boolean>;
@@ -1,7 +1,7 @@
1
1
  import { WarehousingProviderType } from '@unchainedshop/core-warehousing';
2
2
  import { WarehousingDirector } from "../directors/WarehousingDirector.js";
3
- export async function isTokenInvalidateableService({ token, }) {
4
- const product = await this.products.findProduct({ productId: token.productId });
3
+ export async function isTokenInvalidateableService({ token, product: providedProduct, }) {
4
+ const product = providedProduct || (await this.products.findProduct({ productId: token.productId }));
5
5
  if (!product)
6
6
  return false;
7
7
  const virtualProviders = (await this.warehousing.allProviders()).filter(({ type }) => type === WarehousingProviderType.VIRTUAL);
@@ -1,10 +1,10 @@
1
- import { FilterType } from '@unchainedshop/core-filters';
1
+ import { filterOptionValues } from '@unchainedshop/core-filters';
2
2
  import { FilterDirector, parseQueryArray } from "../directors/FilterDirector.js";
3
3
  export async function loadFilterOptionsService(filter, params) {
4
4
  const { forceLiveCollection, productIdSet, searchQuery } = params;
5
5
  const filterQueryParsed = parseQueryArray(searchQuery?.filterQuery);
6
6
  const values = filterQueryParsed[filter.key];
7
- const allOptions = (filter.type === FilterType.SWITCH && ['true', 'false']) || filter.options || [];
7
+ const allOptions = filterOptionValues(filter);
8
8
  const mappedOptions = await Promise.all(allOptions.map(async (value) => {
9
9
  const filterOptionProductIds = await FilterDirector.filterProductIds(filter, {
10
10
  values: [value],
@@ -12,7 +12,7 @@ export async function loadFilterOptionsService(filter, params) {
12
12
  }, { modules: this });
13
13
  const filteredProductIdSet = productIdSet.intersection(filterOptionProductIds);
14
14
  const normalizedValues = values && this.filters.parse(filter, values, [value]);
15
- const isSelected = normalizedValues && normalizedValues.indexOf(value) !== -1;
15
+ const isSelected = Boolean(normalizedValues && normalizedValues.indexOf(value) !== -1);
16
16
  if (!filteredProductIdSet.size && !isSelected) {
17
17
  return null;
18
18
  }
@@ -12,10 +12,10 @@ export async function migrateOrderCartsService({ fromUserId, toUserId, shouldMer
12
12
  return toCart;
13
13
  }
14
14
  if (!toCart || !shouldMerge) {
15
- this.orders.setCartOwner({ orderId: fromCart._id, userId: toUserId });
15
+ await this.orders.setCartOwner({ orderId: fromCart._id, userId: toUserId });
16
16
  return updateCalculationService.bind(this)(fromCart._id);
17
17
  }
18
- this.orders.moveCartPositions({ fromOrderId: fromCart._id, toOrderId: toCart._id });
18
+ await this.orders.moveCartPositions({ fromOrderId: fromCart._id, toOrderId: toCart._id });
19
19
  if (fromCart.billingAddress && !toCart.billingAddress) {
20
20
  await this.orders.updateBillingAddress(toCart._id, fromCart.billingAddress);
21
21
  }
@@ -4,6 +4,9 @@ import { migrateOrderCartsService } from "./migrateOrderCart.js";
4
4
  export async function migrateUserDataService(userIdBeforeLogin, userId) {
5
5
  const user = await this.users.findUserById(userId);
6
6
  const userBeforeLogin = await this.users.findUserById(userIdBeforeLogin);
7
+ if (userBeforeLogin?.guest) {
8
+ await this.quotations.replaceUserIdOfOpenQuotations(userIdBeforeLogin, userId);
9
+ }
7
10
  await migrateOrderCartsService.bind(this)({
8
11
  fromUserId: userIdBeforeLogin,
9
12
  toUserId: userId,
@@ -1,12 +1,19 @@
1
1
  import { EnrollmentStatus } from '@unchainedshop/core-enrollments';
2
2
  import { EnrollmentDirector } from "../core-index.js";
3
+ import { createServiceError } from "../errors.js";
3
4
  const findNextStatus = async (enrollment, modules) => {
4
5
  let status = enrollment.status;
6
+ if (modules.enrollments.isExpired(enrollment, {}))
7
+ return EnrollmentStatus.TERMINATED;
8
+ if (status === EnrollmentStatus.SUSPENDED) {
9
+ const resumeDue = enrollment.resumeAt && new Date(enrollment.resumeAt).getTime() <= Date.now();
10
+ return resumeDue ? EnrollmentStatus.ACTIVE : status;
11
+ }
5
12
  const product = await modules.products.findProduct({
6
13
  productId: enrollment.productId,
7
14
  });
8
15
  if (!product)
9
- throw new Error('Product not found for enrollment');
16
+ throw createServiceError('ProductNotFoundError', 'Product not found for enrollment');
10
17
  const director = await EnrollmentDirector.actions({ enrollment, product }, { modules });
11
18
  if (status === EnrollmentStatus.INITIAL || status === EnrollmentStatus.PAUSED) {
12
19
  if (await director.isValidForActivation()) {
@@ -18,9 +25,6 @@ const findNextStatus = async (enrollment, modules) => {
18
25
  status = EnrollmentStatus.PAUSED;
19
26
  }
20
27
  }
21
- else if (modules.enrollments.isExpired(enrollment, {})) {
22
- status = EnrollmentStatus.TERMINATED;
23
- }
24
28
  return status;
25
29
  };
26
30
  export async function processEnrollmentService(enrollment) {
@@ -5,15 +5,16 @@ import { WarehousingProviderType } from '@unchainedshop/core-warehousing';
5
5
  import { WarehousingDirector, DeliveryDirector, PaymentDirector } from "../directors/index.js";
6
6
  import { fulfillQuotationService } from "./fulfillQuotation.js";
7
7
  import { createLogger } from '@unchainedshop/logger';
8
+ import { createServiceError } from "../errors.js";
8
9
  const logger = createLogger('unchained:core:processOrder');
9
- const isAutoConfirmationEnabled = async ({ orderPayment, orderDelivery, }, modules) => {
10
+ const isAutoConfirmationEnabled = async ({ order, orderPayment, orderDelivery, }, modules) => {
10
11
  if (orderPayment.status !== OrderPaymentStatus.PAID) {
11
12
  const paymentProvider = await modules.payment.paymentProviders.findProvider({
12
13
  paymentProviderId: orderPayment.paymentProviderId,
13
14
  });
14
15
  if (!paymentProvider)
15
- throw new Error(`Payment provider not found: ${orderPayment.paymentProviderId}`);
16
- const actions = await PaymentDirector.actions(paymentProvider, {}, { modules });
16
+ throw createServiceError('PaymentProviderNotFoundError', `Payment provider not found: ${orderPayment.paymentProviderId}`);
17
+ const actions = await PaymentDirector.actions(paymentProvider, { order, orderPayment, userId: order.userId }, { modules });
17
18
  if (!actions.isPayLaterAllowed())
18
19
  return false;
19
20
  }
@@ -22,8 +23,8 @@ const isAutoConfirmationEnabled = async ({ orderPayment, orderDelivery, }, modul
22
23
  deliveryProviderId: orderDelivery.deliveryProviderId,
23
24
  });
24
25
  if (!deliveryProvider)
25
- throw new Error(`Delivery provider not found: ${orderDelivery.deliveryProviderId}`);
26
- const director = await DeliveryDirector.actions(deliveryProvider, {}, { modules });
26
+ throw createServiceError('DeliveryProviderNotFoundError', `Delivery provider not found: ${orderDelivery.deliveryProviderId}`);
27
+ const director = await DeliveryDirector.actions(deliveryProvider, { order, orderDelivery }, { modules });
27
28
  if (!director.isAutoReleaseAllowed())
28
29
  return false;
29
30
  }
@@ -49,7 +50,7 @@ const findNextStatus = async (status, order, modules) => {
49
50
  if (!orderDelivery)
50
51
  return status;
51
52
  if (status === OrderStatus.PENDING) {
52
- if (await isAutoConfirmationEnabled({ orderPayment, orderDelivery }, modules)) {
53
+ if (await isAutoConfirmationEnabled({ order, orderPayment, orderDelivery }, modules)) {
53
54
  return OrderStatus.CONFIRMED;
54
55
  }
55
56
  }
@@ -1,9 +1,8 @@
1
1
  import { QuotationStatus } from '@unchainedshop/core-quotations';
2
2
  import { QuotationDirector } from "../core-index.js";
3
3
  import { addMessageService } from "./addMessage.js";
4
- const findNextStatus = async (quotation, modules) => {
4
+ const findNextStatus = async (director, quotation) => {
5
5
  let status = quotation.status;
6
- const director = await QuotationDirector.actions({ quotation }, { modules });
7
6
  if (status === QuotationStatus.REQUESTED) {
8
7
  if (!(await director.isManualRequestVerificationRequired())) {
9
8
  status = QuotationStatus.PROCESSING;
@@ -19,27 +18,26 @@ const findNextStatus = async (quotation, modules) => {
19
18
  export async function processQuotationService(initialQuotation, params) {
20
19
  const quotationId = initialQuotation._id;
21
20
  let quotation = initialQuotation;
22
- let nextStatus = await findNextStatus(quotation, this);
23
21
  const director = await QuotationDirector.actions({ quotation }, { modules: this });
22
+ const runHook = async (hook) => {
23
+ await hook(params.quotationContext);
24
+ quotation = (await this.quotations.findQuotation({ quotationId }));
25
+ return findNextStatus(director, quotation);
26
+ };
27
+ let nextStatus = await findNextStatus(director, quotation);
24
28
  if (quotation.status === QuotationStatus.REQUESTED && nextStatus !== QuotationStatus.REQUESTED) {
25
- await director.submitRequest(params.quotationContext);
29
+ nextStatus = await runHook(director.submitRequest);
26
30
  }
27
- quotation = (await this.quotations.findQuotation({ quotationId }));
28
- nextStatus = await findNextStatus(quotation, this);
29
31
  if (nextStatus !== QuotationStatus.PROCESSING) {
30
- await director.verifyRequest(params.quotationContext);
32
+ nextStatus = await runHook(director.verifyRequest);
31
33
  }
32
- quotation = (await this.quotations.findQuotation({ quotationId }));
33
- nextStatus = await findNextStatus(quotation, this);
34
34
  if (nextStatus === QuotationStatus.REJECTED) {
35
- await director.rejectRequest(params.quotationContext);
35
+ nextStatus = await runHook(director.rejectRequest);
36
36
  }
37
- quotation = (await this.quotations.findQuotation({ quotationId }));
38
- nextStatus = await findNextStatus(quotation, this);
39
37
  if (nextStatus === QuotationStatus.PROPOSED) {
40
38
  const proposal = await director.quote();
41
39
  quotation = (await this.quotations.updateProposal(quotation._id, proposal));
42
- nextStatus = await findNextStatus(quotation, this);
40
+ nextStatus = await findNextStatus(director, quotation);
43
41
  }
44
42
  const updatedQuotation = (await this.quotations.updateStatus(quotation._id, {
45
43
  status: nextStatus,
@@ -3,6 +3,9 @@ import { processQuotationService } from "./processQuotation.js";
3
3
  export async function proposeQuotationService(quotation, { quotationContext }) {
4
4
  if (quotation.status !== QuotationStatus.PROCESSING)
5
5
  return quotation;
6
+ if (quotationContext) {
7
+ await this.quotations.updateContext(quotation._id, { context: quotationContext });
8
+ }
6
9
  const updatedQuotation = (await this.quotations.updateStatus(quotation._id, {
7
10
  status: QuotationStatus.PROPOSED,
8
11
  info: 'proposed manually',
@@ -0,0 +1,6 @@
1
+ import type { Filter } from '@unchainedshop/core-filters';
2
+ import type { Modules } from '../modules.ts';
3
+ export declare function removeFilterOptionService(this: Modules, { filterId, filterOptionValue }: {
4
+ filterId: string;
5
+ filterOptionValue: string;
6
+ }): Promise<Filter | null>;
@@ -0,0 +1,8 @@
1
+ import { FilterDirector } from "../core-index.js";
2
+ export async function removeFilterOptionService({ filterId, filterOptionValue }) {
3
+ const filter = await this.filters.removeFilterOption({ filterId, filterOptionValue });
4
+ if (filter) {
5
+ await FilterDirector.invalidateProductIdCache(filter, { modules: this });
6
+ }
7
+ return filter;
8
+ }
@@ -1,5 +1,6 @@
1
1
  import { ProductStatus } from '@unchainedshop/core-products';
2
2
  import { updateCalculationService } from "./updateCalculation.js";
3
+ import { createServiceError } from "../errors.js";
3
4
  export async function removeProductService({ productId }) {
4
5
  const product = await this.products.findProduct({ productId });
5
6
  switch (product?.status) {
@@ -21,7 +22,7 @@ export async function removeProductService({ productId }) {
21
22
  case ProductStatus.DELETED:
22
23
  return false;
23
24
  default:
24
- throw new Error(`Invalid status: ${product?.status}`);
25
+ throw createServiceError('ProductWrongStatusError', `Invalid status: ${product?.status}`);
25
26
  }
26
27
  return true;
27
28
  }
@@ -0,0 +1,5 @@
1
+ import type { Order } from '@unchainedshop/core-orders';
2
+ import type { Modules } from '../modules.ts';
3
+ export declare function reserveOrderDiscountsForCheckout(this: Modules, order: Order): Promise<{
4
+ release: () => Promise<void>;
5
+ }>;
@@ -0,0 +1,34 @@
1
+ import { createLogger } from '@unchainedshop/logger';
2
+ import { OrderDiscountDirector } from "../directors/OrderDiscountDirector.js";
3
+ const logger = createLogger('unchained:core:checkoutOrder');
4
+ export async function reserveOrderDiscountsForCheckout(order) {
5
+ const reservations = [];
6
+ const release = async () => {
7
+ const results = await Promise.allSettled(reservations.map((reservation) => reservation.release()));
8
+ for (const result of results) {
9
+ if (result.status === 'rejected') {
10
+ logger.error(`Could not release a discount reservation of order ${order._id}`, {
11
+ error: result.reason,
12
+ });
13
+ }
14
+ }
15
+ };
16
+ try {
17
+ const discounts = await this.orders.discounts.findOrderDiscounts({ orderId: order._id });
18
+ for (const orderDiscount of discounts) {
19
+ const Adapter = OrderDiscountDirector.getAdapter(orderDiscount.discountKey);
20
+ if (!Adapter)
21
+ continue;
22
+ const adapter = await Adapter.actions({
23
+ context: { order, orderDiscount, code: orderDiscount.code, modules: this },
24
+ });
25
+ if (adapter.reserveForCheckout)
26
+ reservations.push(await adapter.reserveForCheckout());
27
+ }
28
+ return { release };
29
+ }
30
+ catch (error) {
31
+ await release();
32
+ throw error;
33
+ }
34
+ }
@@ -0,0 +1,8 @@
1
+ import { type Order } from '@unchainedshop/core-orders';
2
+ import type { Modules } from '../modules.ts';
3
+ export declare function isQuotationReserved(this: Modules, quotationId: string, { exceptOrderId }?: {
4
+ exceptOrderId?: string;
5
+ }): Promise<boolean>;
6
+ export declare function reserveOrderQuotationsForCheckout(this: Modules, order: Order): Promise<{
7
+ release: () => Promise<void>;
8
+ }>;
@@ -0,0 +1,49 @@
1
+ import { OrderStatus } from '@unchainedshop/core-orders';
2
+ import { createServiceError } from "../errors.js";
3
+ const RESERVATION_LOCK_TTL = 60000;
4
+ export async function isQuotationReserved(quotationId, { exceptOrderId } = {}) {
5
+ const orderIds = (await this.orders.positions.findOrderPositions({ quotationId }))
6
+ .map(({ orderId }) => orderId)
7
+ .filter((orderId) => orderId !== exceptOrderId);
8
+ if (!orderIds.length)
9
+ return false;
10
+ const count = await this.orders.count({
11
+ orderIds,
12
+ status: [OrderStatus.PENDING, OrderStatus.CONFIRMED, OrderStatus.FULFILLED],
13
+ });
14
+ return count > 0;
15
+ }
16
+ export async function reserveOrderQuotationsForCheckout(order) {
17
+ const locks = [];
18
+ const release = async () => {
19
+ await Promise.all(locks.map((lock) => lock.release()));
20
+ };
21
+ try {
22
+ const positions = await this.orders.positions.findOrderPositions({ orderId: order._id });
23
+ const quotationIds = [
24
+ ...new Set(positions.map(({ quotationId }) => quotationId).filter(Boolean)),
25
+ ].sort();
26
+ for (const quotationId of quotationIds) {
27
+ try {
28
+ locks.push(await this.orders.acquireLock(quotationId, 'quotation', RESERVATION_LOCK_TTL));
29
+ }
30
+ catch (error) {
31
+ if (!error?.message?.startsWith('Could not acquire lock'))
32
+ throw error;
33
+ throw createServiceError('QuotationInvalidError', 'Quotation is being ordered by another order');
34
+ }
35
+ const quotation = await this.quotations.findQuotation({ quotationId });
36
+ if (!quotation || !this.quotations.isProposalValid(quotation)) {
37
+ throw createServiceError('QuotationInvalidError', 'Quotation expired, fulfilled or not valid for this order, please request a new offer');
38
+ }
39
+ if (await isQuotationReserved.call(this, quotationId, { exceptOrderId: order._id })) {
40
+ throw createServiceError('QuotationInvalidError', 'Quotation is reserved by another order');
41
+ }
42
+ }
43
+ return { release };
44
+ }
45
+ catch (error) {
46
+ await release();
47
+ throw error;
48
+ }
49
+ }
@@ -22,7 +22,7 @@ export async function simulateConfigurablePriceRangeService({ product, currencyC
22
22
  return {
23
23
  ...unitPrice,
24
24
  isNetPrice: useNetPrice,
25
- isTaxable: pricing.taxSum() > 0,
25
+ isTaxable: pricing.taxSum() !== 0,
26
26
  currencyCode: pricing.currencyCode,
27
27
  };
28
28
  }))).filter(Boolean);
@@ -17,7 +17,7 @@ export async function simulateDeliveryPricingService(pricingContext, options = {
17
17
  amount: orderPrice.amount,
18
18
  currencyCode: orderPrice.currencyCode,
19
19
  countryCode: pricingContext.countryCode,
20
- isTaxable: pricing.taxSum() > 0,
20
+ isTaxable: pricing.taxSum() !== 0,
21
21
  isNetPrice: options.useNetPrice || false,
22
22
  };
23
23
  }
@@ -17,7 +17,7 @@ export async function simulatePaymentPricingService(pricingContext, options = {}
17
17
  amount: orderPrice.amount,
18
18
  currencyCode: orderPrice.currencyCode,
19
19
  countryCode: pricingContext.countryCode,
20
- isTaxable: pricing.taxSum() > 0,
20
+ isTaxable: pricing.taxSum() !== 0,
21
21
  isNetPrice: options.useNetPrice || false,
22
22
  };
23
23
  }
@@ -3,10 +3,12 @@ import type { Product } from '@unchainedshop/core-products';
3
3
  import { type EstimatedDispatch } from '../directors/WarehousingDirector.ts';
4
4
  import type { WarehousingContext } from '../directors/WarehousingAdapter.ts';
5
5
  import type { WarehousingProvider } from '@unchainedshop/core-warehousing';
6
- export declare function simulateProductDispatchingService(this: Modules, { product, quantity, referenceDate, }: {
6
+ import type { DeliveryProviderType } from '@unchainedshop/core-delivery';
7
+ export declare function simulateProductDispatchingService(this: Modules, { product, quantity, referenceDate, deliveryProviderType, }: {
7
8
  product: Product;
8
9
  quantity: number;
9
10
  referenceDate?: Date;
11
+ deliveryProviderType?: DeliveryProviderType | null;
10
12
  }): Promise<(WarehousingContext & EstimatedDispatch & {
11
13
  warehousingProvider: WarehousingProvider;
12
14
  })[]>;