@unchainedshop/core 4.0.0-rc.2 → 4.0.0-rc.21

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 (472) hide show
  1. package/lib/bulk-importer/createBulkImporter.d.ts +84 -0
  2. package/lib/bulk-importer/createBulkImporter.d.ts.map +1 -0
  3. package/lib/bulk-importer/createBulkImporter.js +142 -0
  4. package/lib/bulk-importer/createBulkImporter.js.map +1 -0
  5. package/lib/bulk-importer/handlers/assortment/create.d.ts +565 -0
  6. package/lib/bulk-importer/handlers/assortment/create.d.ts.map +1 -0
  7. package/lib/bulk-importer/handlers/assortment/create.js +89 -0
  8. package/lib/bulk-importer/handlers/assortment/create.js.map +1 -0
  9. package/lib/bulk-importer/handlers/assortment/index.d.ts +4 -0
  10. package/lib/bulk-importer/handlers/assortment/index.d.ts.map +1 -0
  11. package/lib/bulk-importer/handlers/assortment/index.js +4 -0
  12. package/lib/bulk-importer/handlers/assortment/index.js.map +1 -0
  13. package/lib/bulk-importer/handlers/assortment/remove.d.ts +30 -0
  14. package/lib/bulk-importer/handlers/assortment/remove.d.ts.map +1 -0
  15. package/lib/bulk-importer/handlers/assortment/remove.js +18 -0
  16. package/lib/bulk-importer/handlers/assortment/remove.js.map +1 -0
  17. package/lib/bulk-importer/handlers/assortment/update.d.ts +566 -0
  18. package/lib/bulk-importer/handlers/assortment/update.d.ts.map +1 -0
  19. package/lib/bulk-importer/handlers/assortment/update.js +98 -0
  20. package/lib/bulk-importer/handlers/assortment/update.js.map +1 -0
  21. package/lib/bulk-importer/handlers/assortment/upsertAssortmentChildren.d.ts +29 -0
  22. package/lib/bulk-importer/handlers/assortment/upsertAssortmentChildren.d.ts.map +1 -0
  23. package/lib/bulk-importer/handlers/assortment/upsertAssortmentChildren.js +45 -0
  24. package/lib/bulk-importer/handlers/assortment/upsertAssortmentChildren.js.map +1 -0
  25. package/lib/bulk-importer/handlers/assortment/upsertAssortmentFilters.d.ts +29 -0
  26. package/lib/bulk-importer/handlers/assortment/upsertAssortmentFilters.d.ts.map +1 -0
  27. package/lib/bulk-importer/handlers/assortment/upsertAssortmentFilters.js +41 -0
  28. package/lib/bulk-importer/handlers/assortment/upsertAssortmentFilters.js.map +1 -0
  29. package/lib/bulk-importer/handlers/assortment/upsertAssortmentProducts.d.ts +29 -0
  30. package/lib/bulk-importer/handlers/assortment/upsertAssortmentProducts.d.ts.map +1 -0
  31. package/lib/bulk-importer/handlers/assortment/upsertAssortmentProducts.js +46 -0
  32. package/lib/bulk-importer/handlers/assortment/upsertAssortmentProducts.js.map +1 -0
  33. package/lib/bulk-importer/handlers/assortment/upsertMedia.d.ts +76 -0
  34. package/lib/bulk-importer/handlers/assortment/upsertMedia.d.ts.map +1 -0
  35. package/lib/bulk-importer/handlers/assortment/upsertMedia.js +53 -0
  36. package/lib/bulk-importer/handlers/assortment/upsertMedia.js.map +1 -0
  37. package/lib/bulk-importer/handlers/filter/create.d.ts +138 -0
  38. package/lib/bulk-importer/handlers/filter/create.d.ts.map +1 -0
  39. package/lib/bulk-importer/handlers/filter/create.js +80 -0
  40. package/lib/bulk-importer/handlers/filter/create.js.map +1 -0
  41. package/lib/bulk-importer/handlers/filter/index.d.ts +4 -0
  42. package/lib/bulk-importer/handlers/filter/index.d.ts.map +1 -0
  43. package/lib/bulk-importer/handlers/filter/index.js +4 -0
  44. package/lib/bulk-importer/handlers/filter/index.js.map +1 -0
  45. package/lib/bulk-importer/handlers/filter/remove.d.ts +20 -0
  46. package/lib/bulk-importer/handlers/filter/remove.d.ts.map +1 -0
  47. package/lib/bulk-importer/handlers/filter/remove.js +18 -0
  48. package/lib/bulk-importer/handlers/filter/remove.js.map +1 -0
  49. package/lib/bulk-importer/handlers/filter/update.d.ts +138 -0
  50. package/lib/bulk-importer/handlers/filter/update.d.ts.map +1 -0
  51. package/lib/bulk-importer/handlers/filter/update.js +70 -0
  52. package/lib/bulk-importer/handlers/filter/update.js.map +1 -0
  53. package/lib/bulk-importer/handlers/product/create.d.ts +1330 -0
  54. package/lib/bulk-importer/handlers/product/create.d.ts.map +1 -0
  55. package/lib/bulk-importer/handlers/product/create.js +132 -0
  56. package/lib/bulk-importer/handlers/product/create.js.map +1 -0
  57. package/lib/bulk-importer/handlers/product/index.d.ts +4 -0
  58. package/lib/bulk-importer/handlers/product/index.d.ts.map +1 -0
  59. package/lib/bulk-importer/handlers/product/index.js +4 -0
  60. package/lib/bulk-importer/handlers/product/index.js.map +1 -0
  61. package/lib/bulk-importer/handlers/product/remove.d.ts +32 -0
  62. package/lib/bulk-importer/handlers/product/remove.d.ts.map +1 -0
  63. package/lib/bulk-importer/handlers/product/remove.js +18 -0
  64. package/lib/bulk-importer/handlers/product/remove.js.map +1 -0
  65. package/lib/bulk-importer/handlers/product/transformSpecificationToProductStructure.d.ts +280 -0
  66. package/lib/bulk-importer/handlers/product/transformSpecificationToProductStructure.d.ts.map +1 -0
  67. package/lib/bulk-importer/handlers/product/transformSpecificationToProductStructure.js +77 -0
  68. package/lib/bulk-importer/handlers/product/transformSpecificationToProductStructure.js.map +1 -0
  69. package/lib/bulk-importer/handlers/product/update.d.ts +1330 -0
  70. package/lib/bulk-importer/handlers/product/update.d.ts.map +1 -0
  71. package/lib/bulk-importer/handlers/product/update.js +132 -0
  72. package/lib/bulk-importer/handlers/product/update.js.map +1 -0
  73. package/lib/bulk-importer/handlers/product/upsertMedia.d.ts +75 -0
  74. package/lib/bulk-importer/handlers/product/upsertMedia.d.ts.map +1 -0
  75. package/lib/bulk-importer/handlers/product/upsertMedia.js +59 -0
  76. package/lib/bulk-importer/handlers/product/upsertMedia.js.map +1 -0
  77. package/lib/bulk-importer/handlers/product/upsertVariations.d.ts +79 -0
  78. package/lib/bulk-importer/handlers/product/upsertVariations.d.ts.map +1 -0
  79. package/lib/bulk-importer/handlers/product/upsertVariations.js +72 -0
  80. package/lib/bulk-importer/handlers/product/upsertVariations.js.map +1 -0
  81. package/lib/bulk-importer/handlers/utils/convertTagsToLowerCase.d.ts +3 -0
  82. package/lib/bulk-importer/handlers/utils/convertTagsToLowerCase.d.ts.map +1 -0
  83. package/lib/bulk-importer/handlers/utils/convertTagsToLowerCase.js +6 -0
  84. package/lib/bulk-importer/handlers/utils/convertTagsToLowerCase.js.map +1 -0
  85. package/lib/bulk-importer/handlers/utils/event-schema.d.ts +21 -0
  86. package/lib/bulk-importer/handlers/utils/event-schema.d.ts.map +1 -0
  87. package/lib/bulk-importer/handlers/utils/event-schema.js +64 -0
  88. package/lib/bulk-importer/handlers/utils/event-schema.js.map +1 -0
  89. package/lib/bulk-importer/index.d.ts +4 -0
  90. package/lib/bulk-importer/index.d.ts.map +1 -0
  91. package/lib/bulk-importer/index.js +4 -0
  92. package/lib/bulk-importer/index.js.map +1 -0
  93. package/lib/bulk-importer/upsertAsset.d.ts +28 -0
  94. package/lib/bulk-importer/upsertAsset.d.ts.map +1 -0
  95. package/lib/bulk-importer/upsertAsset.js +41 -0
  96. package/lib/bulk-importer/upsertAsset.js.map +1 -0
  97. package/lib/core-index.d.ts +9 -6
  98. package/lib/core-index.d.ts.map +1 -1
  99. package/lib/core-index.js +5 -1
  100. package/lib/core-index.js.map +1 -1
  101. package/lib/directors/BaseDiscountAdapter.d.ts +4 -4
  102. package/lib/directors/BaseDiscountAdapter.d.ts.map +1 -1
  103. package/lib/directors/BaseDiscountAdapter.js +1 -1
  104. package/lib/directors/BaseDiscountAdapter.js.map +1 -1
  105. package/lib/directors/BaseDiscountDirector.d.ts +1 -1
  106. package/lib/directors/BaseDiscountDirector.d.ts.map +1 -1
  107. package/lib/directors/BaseDiscountDirector.js +1 -1
  108. package/lib/directors/BaseDiscountDirector.js.map +1 -1
  109. package/lib/directors/BasePricingAdapter.d.ts +2 -2
  110. package/lib/directors/BasePricingAdapter.d.ts.map +1 -1
  111. package/lib/directors/BasePricingDirector.d.ts.map +1 -1
  112. package/lib/directors/BasePricingDirector.js +3 -3
  113. package/lib/directors/BasePricingDirector.js.map +1 -1
  114. package/lib/directors/BasePricingSheet.js.map +1 -1
  115. package/lib/directors/BaseWorker.d.ts +3 -3
  116. package/lib/directors/BaseWorker.d.ts.map +1 -1
  117. package/lib/directors/BaseWorker.js +12 -12
  118. package/lib/directors/BaseWorker.js.map +1 -1
  119. package/lib/directors/DeliveryAdapter.d.ts +4 -5
  120. package/lib/directors/DeliveryAdapter.d.ts.map +1 -1
  121. package/lib/directors/DeliveryAdapter.js.map +1 -1
  122. package/lib/directors/DeliveryDirector.d.ts +3 -3
  123. package/lib/directors/DeliveryDirector.d.ts.map +1 -1
  124. package/lib/directors/DeliveryDirector.js +29 -16
  125. package/lib/directors/DeliveryDirector.js.map +1 -1
  126. package/lib/directors/DeliveryPricingAdapter.d.ts +1 -1
  127. package/lib/directors/DeliveryPricingAdapter.d.ts.map +1 -1
  128. package/lib/directors/DeliveryPricingDirector.d.ts.map +1 -1
  129. package/lib/directors/DeliveryPricingDirector.js +3 -4
  130. package/lib/directors/DeliveryPricingDirector.js.map +1 -1
  131. package/lib/directors/DeliveryPricingSheet.d.ts.map +1 -1
  132. package/lib/directors/DeliveryPricingSheet.js +2 -1
  133. package/lib/directors/DeliveryPricingSheet.js.map +1 -1
  134. package/lib/directors/EnrollmentAdapter.d.ts +7 -4
  135. package/lib/directors/EnrollmentAdapter.d.ts.map +1 -1
  136. package/lib/directors/EnrollmentAdapter.js +1 -4
  137. package/lib/directors/EnrollmentAdapter.js.map +1 -1
  138. package/lib/directors/EnrollmentDirector.d.ts +1 -1
  139. package/lib/directors/EnrollmentDirector.d.ts.map +1 -1
  140. package/lib/directors/EnrollmentDirector.js +1 -5
  141. package/lib/directors/EnrollmentDirector.js.map +1 -1
  142. package/lib/directors/EventListenerWorker.d.ts.map +1 -1
  143. package/lib/directors/EventListenerWorker.js +50 -18
  144. package/lib/directors/EventListenerWorker.js.map +1 -1
  145. package/lib/directors/FailedRescheduler.d.ts +2 -2
  146. package/lib/directors/FailedRescheduler.d.ts.map +1 -1
  147. package/lib/directors/FailedRescheduler.js +1 -1
  148. package/lib/directors/FailedRescheduler.js.map +1 -1
  149. package/lib/directors/FilterAdapter.d.ts +4 -4
  150. package/lib/directors/FilterAdapter.d.ts.map +1 -1
  151. package/lib/directors/FilterDirector.d.ts +1 -1
  152. package/lib/directors/FilterDirector.d.ts.map +1 -1
  153. package/lib/directors/FilterDirector.js +7 -8
  154. package/lib/directors/FilterDirector.js.map +1 -1
  155. package/lib/directors/IntervalWorker.d.ts.map +1 -1
  156. package/lib/directors/IntervalWorker.js +27 -9
  157. package/lib/directors/IntervalWorker.js.map +1 -1
  158. package/lib/directors/MessagingDirector.d.ts +2 -2
  159. package/lib/directors/MessagingDirector.d.ts.map +1 -1
  160. package/lib/directors/OrderDiscountAdapter.d.ts +1 -1
  161. package/lib/directors/OrderDiscountAdapter.d.ts.map +1 -1
  162. package/lib/directors/OrderDiscountAdapter.js.map +1 -1
  163. package/lib/directors/OrderPricingAdapter.d.ts +2 -2
  164. package/lib/directors/OrderPricingAdapter.d.ts.map +1 -1
  165. package/lib/directors/OrderPricingDirector.d.ts +2 -2
  166. package/lib/directors/OrderPricingDirector.d.ts.map +1 -1
  167. package/lib/directors/OrderPricingDirector.js +1 -1
  168. package/lib/directors/OrderPricingDirector.js.map +1 -1
  169. package/lib/directors/OrderPricingSheet.d.ts.map +1 -1
  170. package/lib/directors/OrderPricingSheet.js +2 -1
  171. package/lib/directors/OrderPricingSheet.js.map +1 -1
  172. package/lib/directors/PaymentAdapter.d.ts +2 -2
  173. package/lib/directors/PaymentAdapter.d.ts.map +1 -1
  174. package/lib/directors/PaymentDirector.d.ts +4 -4
  175. package/lib/directors/PaymentDirector.d.ts.map +1 -1
  176. package/lib/directors/PaymentDirector.js +24 -6
  177. package/lib/directors/PaymentDirector.js.map +1 -1
  178. package/lib/directors/PaymentPricingAdapter.d.ts +2 -2
  179. package/lib/directors/PaymentPricingAdapter.d.ts.map +1 -1
  180. package/lib/directors/PaymentPricingDirector.d.ts +1 -1
  181. package/lib/directors/PaymentPricingDirector.d.ts.map +1 -1
  182. package/lib/directors/PaymentPricingDirector.js +3 -5
  183. package/lib/directors/PaymentPricingDirector.js.map +1 -1
  184. package/lib/directors/PaymentPricingSheet.d.ts.map +1 -1
  185. package/lib/directors/PaymentPricingSheet.js +2 -1
  186. package/lib/directors/PaymentPricingSheet.js.map +1 -1
  187. package/lib/directors/ProductDiscountAdapter.d.ts +1 -1
  188. package/lib/directors/ProductDiscountAdapter.d.ts.map +1 -1
  189. package/lib/directors/ProductDiscountAdapter.js.map +1 -1
  190. package/lib/directors/ProductDiscountConfiguration.d.ts +1 -1
  191. package/lib/directors/ProductDiscountConfiguration.d.ts.map +1 -1
  192. package/lib/directors/ProductPricingAdapter.d.ts +1 -1
  193. package/lib/directors/ProductPricingAdapter.d.ts.map +1 -1
  194. package/lib/directors/ProductPricingDirector.d.ts +2 -2
  195. package/lib/directors/ProductPricingDirector.d.ts.map +1 -1
  196. package/lib/directors/ProductPricingDirector.js +3 -3
  197. package/lib/directors/ProductPricingDirector.js.map +1 -1
  198. package/lib/directors/ProductPricingSheet.d.ts +2 -2
  199. package/lib/directors/ProductPricingSheet.d.ts.map +1 -1
  200. package/lib/directors/ProductPricingSheet.js +2 -1
  201. package/lib/directors/ProductPricingSheet.js.map +1 -1
  202. package/lib/directors/QuotationAdapter.d.ts +2 -2
  203. package/lib/directors/QuotationAdapter.d.ts.map +1 -1
  204. package/lib/directors/QuotationDirector.js +2 -2
  205. package/lib/directors/WarehousingAdapter.d.ts +3 -4
  206. package/lib/directors/WarehousingAdapter.d.ts.map +1 -1
  207. package/lib/directors/WarehousingAdapter.js.map +1 -1
  208. package/lib/directors/WarehousingDirector.d.ts +5 -5
  209. package/lib/directors/WarehousingDirector.d.ts.map +1 -1
  210. package/lib/directors/WarehousingDirector.js +10 -13
  211. package/lib/directors/WarehousingDirector.js.map +1 -1
  212. package/lib/directors/WorkerAdapter.d.ts +3 -2
  213. package/lib/directors/WorkerAdapter.d.ts.map +1 -1
  214. package/lib/directors/WorkerAdapter.js +1 -1
  215. package/lib/directors/WorkerAdapter.js.map +1 -1
  216. package/lib/directors/WorkerDirector.d.ts +2 -2
  217. package/lib/directors/WorkerDirector.d.ts.map +1 -1
  218. package/lib/directors/WorkerDirector.js +2 -3
  219. package/lib/directors/WorkerDirector.js.map +1 -1
  220. package/lib/factory/index.d.ts +3 -0
  221. package/lib/factory/index.d.ts.map +1 -0
  222. package/lib/factory/index.js +3 -0
  223. package/lib/factory/index.js.map +1 -0
  224. package/lib/factory/registerProductDiscoverabilityFilter.d.ts +5 -0
  225. package/lib/factory/registerProductDiscoverabilityFilter.d.ts.map +1 -0
  226. package/lib/factory/registerProductDiscoverabilityFilter.js +27 -0
  227. package/lib/factory/registerProductDiscoverabilityFilter.js.map +1 -0
  228. package/lib/modules.d.ts +4 -5
  229. package/lib/modules.d.ts.map +1 -1
  230. package/lib/modules.js +3 -3
  231. package/lib/modules.js.map +1 -1
  232. package/lib/services/activateEnrollment.d.ts.map +1 -1
  233. package/lib/services/activateEnrollment.js +8 -12
  234. package/lib/services/activateEnrollment.js.map +1 -1
  235. package/lib/services/addMessage.d.ts +4 -0
  236. package/lib/services/addMessage.d.ts.map +1 -0
  237. package/lib/services/addMessage.js +15 -0
  238. package/lib/services/addMessage.js.map +1 -0
  239. package/lib/services/calculateDiscountTotal.js +2 -2
  240. package/lib/services/calculateDiscountTotal.js.map +1 -1
  241. package/lib/services/checkoutOrder.d.ts +1 -1
  242. package/lib/services/checkoutOrder.d.ts.map +1 -1
  243. package/lib/services/checkoutOrder.js +10 -4
  244. package/lib/services/checkoutOrder.js.map +1 -1
  245. package/lib/services/confirmOrder.d.ts +1 -1
  246. package/lib/services/confirmOrder.d.ts.map +1 -1
  247. package/lib/services/createDownloadStream.d.ts +1 -1
  248. package/lib/services/createDownloadStream.d.ts.map +1 -1
  249. package/lib/services/createDownloadStream.js +2 -0
  250. package/lib/services/createDownloadStream.js.map +1 -1
  251. package/lib/services/createEnrollmentFromCheckout.d.ts.map +1 -1
  252. package/lib/services/createEnrollmentFromCheckout.js +2 -2
  253. package/lib/services/createEnrollmentFromCheckout.js.map +1 -1
  254. package/lib/services/createManualOrderDiscount.d.ts +2 -2
  255. package/lib/services/createManualOrderDiscount.d.ts.map +1 -1
  256. package/lib/services/createSignedURL.d.ts.map +1 -1
  257. package/lib/services/createSignedURL.js +2 -0
  258. package/lib/services/createSignedURL.js.map +1 -1
  259. package/lib/services/deleteUser.d.ts +1 -1
  260. package/lib/services/deleteUser.d.ts.map +1 -1
  261. package/lib/services/deleteUser.js +4 -2
  262. package/lib/services/deleteUser.js.map +1 -1
  263. package/lib/services/discountedEntities.js.map +1 -1
  264. package/lib/services/findOrInitCart.d.ts +1 -2
  265. package/lib/services/findOrInitCart.d.ts.map +1 -1
  266. package/lib/services/findOrInitCart.js.map +1 -1
  267. package/lib/services/fullfillQuotation.d.ts +1 -1
  268. package/lib/services/fullfillQuotation.d.ts.map +1 -1
  269. package/lib/services/fullfillQuotation.js.map +1 -1
  270. package/lib/services/generateOrderFromEnrollment.d.ts +7 -0
  271. package/lib/services/generateOrderFromEnrollment.d.ts.map +1 -0
  272. package/lib/services/generateOrderFromEnrollment.js +34 -0
  273. package/lib/services/generateOrderFromEnrollment.js.map +1 -0
  274. package/lib/services/index.d.ts +6 -0
  275. package/lib/services/index.d.ts.map +1 -1
  276. package/lib/services/index.js +6 -0
  277. package/lib/services/index.js.map +1 -1
  278. package/lib/services/initCartProviders.d.ts.map +1 -1
  279. package/lib/services/initCartProviders.js +6 -2
  280. package/lib/services/initCartProviders.js.map +1 -1
  281. package/lib/services/initializeEnrollment.d.ts +1 -1
  282. package/lib/services/initializeEnrollment.d.ts.map +1 -1
  283. package/lib/services/initializeEnrollment.js +11 -12
  284. package/lib/services/initializeEnrollment.js.map +1 -1
  285. package/lib/services/linkFileService.d.ts +1 -1
  286. package/lib/services/linkFileService.d.ts.map +1 -1
  287. package/lib/services/linkFileService.js +3 -1
  288. package/lib/services/linkFileService.js.map +1 -1
  289. package/lib/services/loadFilterOptions.d.ts +2 -2
  290. package/lib/services/loadFilterOptions.d.ts.map +1 -1
  291. package/lib/services/migrateOrderCart.d.ts +1 -1
  292. package/lib/services/migrateOrderCart.d.ts.map +1 -1
  293. package/lib/services/nextUserCart.d.ts +1 -1
  294. package/lib/services/nextUserCart.d.ts.map +1 -1
  295. package/lib/services/nextUserCart.js +1 -1
  296. package/lib/services/nextUserCart.js.map +1 -1
  297. package/lib/services/processEnrollment.d.ts.map +1 -1
  298. package/lib/services/processEnrollment.js +13 -5
  299. package/lib/services/processEnrollment.js.map +1 -1
  300. package/lib/services/processOrder.d.ts.map +1 -1
  301. package/lib/services/processOrder.js +30 -30
  302. package/lib/services/processOrder.js.map +1 -1
  303. package/lib/services/processQuotation.d.ts.map +1 -1
  304. package/lib/services/processQuotation.js +10 -14
  305. package/lib/services/processQuotation.js.map +1 -1
  306. package/lib/services/proposeQuotation.d.ts +1 -1
  307. package/lib/services/proposeQuotation.d.ts.map +1 -1
  308. package/lib/services/proposeQuotation.js +2 -2
  309. package/lib/services/proposeQuotation.js.map +1 -1
  310. package/lib/services/registerPaymentCredentials.d.ts +1 -2
  311. package/lib/services/registerPaymentCredentials.d.ts.map +1 -1
  312. package/lib/services/registerPaymentCredentials.js +4 -6
  313. package/lib/services/registerPaymentCredentials.js.map +1 -1
  314. package/lib/services/rejectOrder.d.ts +1 -1
  315. package/lib/services/rejectOrder.d.ts.map +1 -1
  316. package/lib/services/rejectQuotation.d.ts +1 -1
  317. package/lib/services/rejectQuotation.d.ts.map +1 -1
  318. package/lib/services/rejectQuotation.js +2 -2
  319. package/lib/services/rejectQuotation.js.map +1 -1
  320. package/lib/services/removeFiles.js +2 -2
  321. package/lib/services/removeFiles.js.map +1 -1
  322. package/lib/services/removeProduct.d.ts.map +1 -1
  323. package/lib/services/removeProduct.js +4 -3
  324. package/lib/services/removeProduct.js.map +1 -1
  325. package/lib/services/searchAssortments.d.ts.map +1 -1
  326. package/lib/services/searchAssortments.js +3 -2
  327. package/lib/services/searchAssortments.js.map +1 -1
  328. package/lib/services/searchProducts.js +3 -3
  329. package/lib/services/searchProducts.js.map +1 -1
  330. package/lib/services/simulateProductDispatching.d.ts +1 -1
  331. package/lib/services/simulateProductDispatching.d.ts.map +1 -1
  332. package/lib/services/simulateProductInventory.d.ts +1 -1
  333. package/lib/services/simulateProductInventory.d.ts.map +1 -1
  334. package/lib/services/simulateProductInventory.js.map +1 -1
  335. package/lib/services/simulateProductPricing.d.ts +7 -4
  336. package/lib/services/simulateProductPricing.d.ts.map +1 -1
  337. package/lib/services/simulateProductPricing.js.map +1 -1
  338. package/lib/services/terminateEnrollment.d.ts.map +1 -1
  339. package/lib/services/terminateEnrollment.js +5 -9
  340. package/lib/services/terminateEnrollment.js.map +1 -1
  341. package/lib/services/updateCalculation.d.ts +2 -1
  342. package/lib/services/updateCalculation.d.ts.map +1 -1
  343. package/lib/services/updateCalculation.js +20 -12
  344. package/lib/services/updateCalculation.js.map +1 -1
  345. package/lib/services/updateScheduling.d.ts +1 -1
  346. package/lib/services/updateScheduling.d.ts.map +1 -1
  347. package/lib/services/updateScheduling.js +7 -11
  348. package/lib/services/updateScheduling.js.map +1 -1
  349. package/lib/services/updateUserAvatarAfterUpload.d.ts +1 -1
  350. package/lib/services/updateUserAvatarAfterUpload.d.ts.map +1 -1
  351. package/lib/services/updateUserAvatarAfterUpload.js.map +1 -1
  352. package/lib/services/uploadFileFromStream.d.ts +2 -2
  353. package/lib/services/uploadFileFromStream.d.ts.map +1 -1
  354. package/lib/services/uploadFileFromStream.js +6 -3
  355. package/lib/services/uploadFileFromStream.js.map +1 -1
  356. package/lib/services/uploadFileFromURL.d.ts +1 -2
  357. package/lib/services/uploadFileFromURL.d.ts.map +1 -1
  358. package/lib/services/uploadFileFromURL.js.map +1 -1
  359. package/lib/services/validateOrder.d.ts +1 -1
  360. package/lib/services/validateOrder.d.ts.map +1 -1
  361. package/lib/services/validateOrder.js +17 -24
  362. package/lib/services/validateOrder.js.map +1 -1
  363. package/lib/services/verifyQuotation.d.ts +1 -1
  364. package/lib/services/verifyQuotation.d.ts.map +1 -1
  365. package/lib/services/verifyQuotation.js +2 -2
  366. package/lib/services/verifyQuotation.js.map +1 -1
  367. package/package.json +23 -22
  368. package/src/bulk-importer/createBulkImporter.ts +205 -0
  369. package/src/bulk-importer/handlers/assortment/create.ts +118 -0
  370. package/src/bulk-importer/handlers/assortment/index.ts +3 -0
  371. package/src/bulk-importer/handlers/assortment/remove.ts +26 -0
  372. package/src/bulk-importer/handlers/assortment/update.ts +133 -0
  373. package/src/bulk-importer/handlers/assortment/upsertAssortmentChildren.ts +77 -0
  374. package/src/bulk-importer/handlers/assortment/upsertAssortmentFilters.ts +70 -0
  375. package/src/bulk-importer/handlers/assortment/upsertAssortmentProducts.ts +76 -0
  376. package/src/bulk-importer/handlers/assortment/upsertMedia.ts +76 -0
  377. package/src/bulk-importer/handlers/filter/create.ts +104 -0
  378. package/src/bulk-importer/handlers/filter/index.ts +3 -0
  379. package/src/bulk-importer/handlers/filter/remove.ts +25 -0
  380. package/src/bulk-importer/handlers/filter/update.ts +94 -0
  381. package/src/bulk-importer/handlers/product/create.ts +170 -0
  382. package/src/bulk-importer/handlers/product/index.ts +3 -0
  383. package/src/bulk-importer/handlers/product/remove.ts +27 -0
  384. package/src/bulk-importer/handlers/product/update.ts +175 -0
  385. package/src/bulk-importer/handlers/product/upsertMedia.ts +81 -0
  386. package/src/bulk-importer/handlers/product/upsertVariations.ts +110 -0
  387. package/src/bulk-importer/handlers/utils/convertTagsToLowerCase.ts +4 -0
  388. package/src/bulk-importer/index.ts +3 -0
  389. package/src/bulk-importer/upsertAsset.ts +50 -0
  390. package/src/core-index.ts +10 -7
  391. package/src/directors/BaseDiscountAdapter.test.ts +1 -1
  392. package/src/directors/BaseDiscountAdapter.ts +5 -5
  393. package/src/directors/BaseDiscountDirector.ts +2 -2
  394. package/src/directors/BasePricingAdapter.ts +2 -2
  395. package/src/directors/BasePricingDirector.ts +47 -44
  396. package/src/directors/BasePricingSheet.ts +1 -1
  397. package/src/directors/BaseWorker.ts +14 -13
  398. package/src/directors/DeliveryAdapter.ts +3 -5
  399. package/src/directors/DeliveryDirector.ts +33 -23
  400. package/src/directors/DeliveryPricingAdapter.ts +1 -1
  401. package/src/directors/DeliveryPricingDirector.ts +5 -6
  402. package/src/directors/DeliveryPricingSheet.ts +3 -2
  403. package/src/directors/EnrollmentAdapter.ts +9 -6
  404. package/src/directors/EnrollmentDirector.ts +9 -8
  405. package/src/directors/EventListenerWorker.ts +59 -19
  406. package/src/directors/FailedRescheduler.ts +2 -2
  407. package/src/directors/FilterAdapter.ts +4 -4
  408. package/src/directors/FilterDirector.ts +11 -12
  409. package/src/directors/IntervalWorker.ts +30 -9
  410. package/src/directors/MessagingDirector.ts +1 -1
  411. package/src/directors/OrderDiscountAdapter.ts +2 -2
  412. package/src/directors/OrderPricingAdapter.ts +2 -2
  413. package/src/directors/OrderPricingDirector.ts +3 -3
  414. package/src/directors/OrderPricingSheet.ts +3 -2
  415. package/src/directors/PaymentAdapter.ts +2 -2
  416. package/src/directors/PaymentDirector.ts +34 -10
  417. package/src/directors/PaymentPricingAdapter.ts +2 -2
  418. package/src/directors/PaymentPricingDirector.ts +6 -8
  419. package/src/directors/PaymentPricingSheet.ts +3 -2
  420. package/src/directors/ProductDiscountAdapter.ts +2 -2
  421. package/src/directors/ProductDiscountConfiguration.ts +1 -1
  422. package/src/directors/ProductPricingAdapter.ts +1 -1
  423. package/src/directors/ProductPricingDirector.ts +7 -7
  424. package/src/directors/ProductPricingSheet.ts +4 -3
  425. package/src/directors/QuotationAdapter.ts +2 -2
  426. package/src/directors/QuotationDirector.ts +2 -2
  427. package/src/directors/WarehousingAdapter.ts +3 -4
  428. package/src/directors/WarehousingDirector.ts +20 -23
  429. package/src/directors/WorkerAdapter.ts +9 -4
  430. package/src/directors/WorkerDirector.ts +5 -6
  431. package/src/factory/index.ts +3 -0
  432. package/src/factory/registerProductDiscoverabilityFilter.ts +36 -0
  433. package/src/modules.ts +6 -7
  434. package/src/services/activateEnrollment.ts +9 -13
  435. package/src/services/addMessage.ts +20 -0
  436. package/src/services/calculateDiscountTotal.ts +4 -4
  437. package/src/services/checkoutOrder.ts +10 -5
  438. package/src/services/createDownloadStream.ts +1 -0
  439. package/src/services/createEnrollmentFromCheckout.ts +22 -20
  440. package/src/services/createManualOrderDiscount.ts +2 -2
  441. package/src/services/createSignedURL.ts +1 -0
  442. package/src/services/deleteUser.ts +7 -2
  443. package/src/services/discountedEntities.ts +6 -6
  444. package/src/services/findOrInitCart.ts +1 -2
  445. package/src/services/fullfillQuotation.ts +1 -1
  446. package/src/services/generateOrderFromEnrollment.ts +54 -0
  447. package/src/services/index.ts +8 -0
  448. package/src/services/initCartProviders.ts +8 -10
  449. package/src/services/initializeEnrollment.ts +16 -13
  450. package/src/services/linkFileService.ts +3 -1
  451. package/src/services/nextUserCart.ts +1 -1
  452. package/src/services/processEnrollment.ts +18 -6
  453. package/src/services/processOrder.ts +37 -36
  454. package/src/services/processQuotation.ts +10 -14
  455. package/src/services/proposeQuotation.ts +2 -2
  456. package/src/services/registerPaymentCredentials.ts +6 -8
  457. package/src/services/rejectQuotation.ts +2 -2
  458. package/src/services/removeFiles.ts +2 -2
  459. package/src/services/removeProduct.ts +5 -3
  460. package/src/services/searchAssortments.ts +3 -2
  461. package/src/services/searchProducts.ts +3 -3
  462. package/src/services/simulateProductDispatching.ts +1 -1
  463. package/src/services/simulateProductInventory.ts +7 -3
  464. package/src/services/simulateProductPricing.ts +6 -3
  465. package/src/services/terminateEnrollment.ts +5 -9
  466. package/src/services/updateCalculation.ts +37 -20
  467. package/src/services/updateScheduling.ts +19 -20
  468. package/src/services/updateUserAvatarAfterUpload.ts +4 -1
  469. package/src/services/uploadFileFromStream.ts +17 -5
  470. package/src/services/uploadFileFromURL.ts +2 -2
  471. package/src/services/validateOrder.ts +34 -38
  472. package/src/services/verifyQuotation.ts +2 -2
@@ -0,0 +1,175 @@
1
+ import { z } from 'zod';
2
+ import { Modules } from '../../../modules.js';
3
+ import { Services } from '../../../services/index.js';
4
+ import upsertVariations, { ProductVariationSchema } from './upsertVariations.js';
5
+ import upsertMedia, { MediaSchema } from './upsertMedia.js';
6
+ import createProduct, { ProductCreatePayloadSchema } from './create.js';
7
+ import convertTagsToLowerCase from '../utils/convertTagsToLowerCase.js';
8
+
9
+ export const ProductUpdateSpecificationSchema = z.object({
10
+ type: z.string().optional(),
11
+ sequence: z.number().optional(),
12
+ status: z.string().optional().nullable(), // or null!
13
+ published: z.string().datetime().optional().nullable(), // or null!
14
+ tags: z.array(z.string()).optional(),
15
+ commerce: z
16
+ .object({
17
+ pricing: z.array(
18
+ z.object({
19
+ amount: z.number(),
20
+ maxQuantity: z.number().optional(),
21
+ isTaxable: z.boolean().optional(),
22
+ isNetPrice: z.boolean().optional(),
23
+ currencyCode: z.string(),
24
+ countryCode: z.string(),
25
+ }),
26
+ ),
27
+ })
28
+ .optional(),
29
+ warehousing: z
30
+ .object({
31
+ sku: z.string().optional(),
32
+ baseUnit: z.string().optional(),
33
+ })
34
+ .optional(),
35
+ supply: z
36
+ .object({
37
+ weightInGram: z.number().optional(),
38
+ heightInMillimeters: z.number().optional(),
39
+ lengthInMillimeters: z.number().optional(),
40
+ widthInMillimeters: z.number().optional(),
41
+ })
42
+ .optional(),
43
+ bundleItems: z
44
+ .array(
45
+ z.object({
46
+ productId: z.string(),
47
+ quantity: z.number(),
48
+ configuration: z.array(
49
+ z.object({
50
+ key: z.string(),
51
+ value: z.string(),
52
+ }),
53
+ ),
54
+ }),
55
+ )
56
+ .optional(),
57
+ meta: z.record(z.unknown()).optional(),
58
+ content: z
59
+ .record(
60
+ z.string(), // locale
61
+ z.object({
62
+ title: z.string().optional(),
63
+ subtitle: z.string().optional(),
64
+ slug: z.string().optional(),
65
+ description: z.string().optional(),
66
+ brand: z.string().optional(),
67
+ vendor: z.string().optional(),
68
+ labels: z.array(z.string()).optional(),
69
+ }),
70
+ )
71
+ .optional(),
72
+ variationResolvers: z
73
+ .array(
74
+ z.object({
75
+ vector: z.record(z.string()),
76
+ productId: z.string(),
77
+ }),
78
+ )
79
+ .optional(),
80
+ });
81
+
82
+ export const ProductUpdatePayloadSchema = z.object({
83
+ _id: z.string(),
84
+ specification: ProductUpdateSpecificationSchema.optional(),
85
+ media: z.array(MediaSchema).optional(),
86
+ variations: z.array(ProductVariationSchema).optional(),
87
+ });
88
+
89
+ const transformSpecification = (specification: z.infer<typeof ProductUpdateSpecificationSchema>) => {
90
+ const {
91
+ variationResolvers: assignments,
92
+ content, // eslint-disable-line
93
+ supply,
94
+ warehousing,
95
+ ...productData
96
+ } = specification;
97
+
98
+ const tags = productData?.tags ? convertTagsToLowerCase(productData.tags!)! : [];
99
+ const proxy = assignments ? { assignments } : undefined;
100
+
101
+ return {
102
+ ...productData,
103
+ published: productData.published ? new Date(productData.published) : undefined,
104
+ tags,
105
+ warehousing,
106
+ supply,
107
+ proxy,
108
+ };
109
+ };
110
+
111
+ export default async function updateProduct(
112
+ payload: z.infer<typeof ProductUpdatePayloadSchema>,
113
+ { logger, updateShouldUpsertIfIDNotExists },
114
+ unchainedAPI: { modules: Modules; services: Services },
115
+ ) {
116
+ const { modules } = unchainedAPI;
117
+ const { specification, media, variations, _id } = payload;
118
+
119
+ if (!(await modules.products.productExists({ productId: _id }))) {
120
+ if (updateShouldUpsertIfIDNotExists && payload.specification) {
121
+ return createProduct(
122
+ payload as z.infer<typeof ProductCreatePayloadSchema>,
123
+ { logger, createShouldUpsertIfIDExists: false },
124
+ unchainedAPI,
125
+ );
126
+ }
127
+ throw new Error(`Can't update non-existing product ${_id}`);
128
+ }
129
+
130
+ if (specification) {
131
+ const productData = transformSpecification(specification);
132
+ logger.debug('update product object', productData);
133
+ await modules.products.update(_id, {
134
+ ...productData,
135
+ });
136
+
137
+ if (specification.content) {
138
+ logger.debug('replace localized content for product', specification.content);
139
+ await modules.products.texts.updateTexts(
140
+ _id,
141
+ Object.entries(specification.content).map(([locale, localizedData]: [string, any]) => {
142
+ return {
143
+ locale,
144
+ ...localizedData,
145
+ };
146
+ }),
147
+ );
148
+ }
149
+ }
150
+
151
+ if (variations) {
152
+ logger.debug('replace variations', variations);
153
+ await upsertVariations(
154
+ {
155
+ variations: variations || [],
156
+ productId: _id,
157
+ },
158
+ unchainedAPI,
159
+ );
160
+ }
161
+
162
+ if (media) {
163
+ logger.debug('replace product media', media);
164
+ await upsertMedia({ media, productId: _id }, unchainedAPI);
165
+ }
166
+
167
+ return {
168
+ entity: 'PRODUCT',
169
+ operation: 'update',
170
+ _id,
171
+ success: true,
172
+ };
173
+ }
174
+
175
+ updateProduct.payloadSchema = ProductUpdatePayloadSchema;
@@ -0,0 +1,81 @@
1
+ import { z } from 'zod';
2
+ import { ProductMedia } from '@unchainedshop/core-products';
3
+ import { Modules } from '../../../modules.js';
4
+ import { Services } from '../../../services/index.js';
5
+ import convertTagsToLowerCase from '../utils/convertTagsToLowerCase.js';
6
+ import upsertAsset, { AssetSchema } from '../../upsertAsset.js';
7
+
8
+ export const MediaSchema = z.object({
9
+ _id: z.string().optional(),
10
+ asset: AssetSchema,
11
+ content: z
12
+ .record(
13
+ z.string(), // locale
14
+ z.object({
15
+ title: z.string().optional(),
16
+ subtitle: z.string().optional(),
17
+ }),
18
+ )
19
+ .optional(),
20
+ tags: z.array(z.string()).optional(),
21
+ sortKey: z.number().optional(),
22
+ });
23
+
24
+ const upsertProductMedia = async (productMedia: ProductMedia, { modules }: { modules: Modules }) => {
25
+ try {
26
+ const productMediaObj = await modules.products.media.create(productMedia);
27
+ return productMediaObj;
28
+ } catch {
29
+ const { _id, ...productMediaData } = productMedia;
30
+ const productMediaId = _id;
31
+ return modules.products.media.update(productMediaId, productMediaData);
32
+ }
33
+ };
34
+
35
+ export default async function upsertMedia(
36
+ { media, productId }: { media: z.infer<typeof MediaSchema>[]; productId: string },
37
+ unchainedAPI: { modules: Modules; services: Services },
38
+ ) {
39
+ const { modules } = unchainedAPI;
40
+
41
+ const productMediaObjects = await Promise.all(
42
+ media.map(async ({ asset, content, ...mediaData }) => {
43
+ const tags = mediaData?.tags ? convertTagsToLowerCase(mediaData?.tags)! : [];
44
+ const file = await upsertAsset(
45
+ 'product-media',
46
+ { meta: { ...(asset.meta || {}), productId }, ...asset },
47
+ unchainedAPI,
48
+ );
49
+ if (!file) throw new Error(`Unable to create binary ${asset._id}`);
50
+ const fileId = file._id;
51
+ const productMedia = await upsertProductMedia(
52
+ {
53
+ ...mediaData,
54
+ tags,
55
+ productId,
56
+ mediaId: file._id,
57
+ } as ProductMedia,
58
+ unchainedAPI,
59
+ );
60
+ if (!productMedia) throw new Error(`Unable to create product media object for file ${fileId}`);
61
+
62
+ if (content) {
63
+ await modules.products.media.texts.updateMediaTexts(
64
+ productMedia._id,
65
+ Object.entries(content).map(([locale, localizedData]: [string, any]) => {
66
+ return {
67
+ locale,
68
+ ...localizedData,
69
+ };
70
+ }),
71
+ );
72
+ }
73
+ return productMedia;
74
+ }),
75
+ );
76
+
77
+ await modules.products.media.deleteMediaFiles({
78
+ productId,
79
+ excludedProductMediaIds: productMediaObjects.map((obj) => obj._id),
80
+ });
81
+ }
@@ -0,0 +1,110 @@
1
+ import { z } from 'zod';
2
+ import { ProductVariation } from '@unchainedshop/core-products';
3
+ import { Modules } from '../../../modules.js';
4
+
5
+ const ProductVariationOptionSchema = z.object({
6
+ value: z.string(),
7
+ content: z
8
+ .record(
9
+ z.string(), // locale
10
+ z.object({
11
+ title: z.string().optional(),
12
+ subtitle: z.string().optional(),
13
+ }),
14
+ )
15
+ .optional(),
16
+ });
17
+
18
+ export const ProductVariationSchema = z.object({
19
+ _id: z.string().optional(),
20
+ key: z.string(),
21
+ type: z.string(),
22
+ options: z.array(ProductVariationOptionSchema),
23
+ content: z
24
+ .record(
25
+ z.string(), // locale
26
+ z.object({
27
+ title: z.string().optional(),
28
+ subtitle: z.string().optional(),
29
+ }),
30
+ )
31
+ .optional(),
32
+ });
33
+
34
+ const upsert = async (
35
+ productVariation: Omit<ProductVariation, '_id' | 'created'> &
36
+ Pick<Partial<ProductVariation>, '_id' | 'created'>,
37
+ unchainedAPI: { modules: Modules },
38
+ ) => {
39
+ const { modules } = unchainedAPI;
40
+ try {
41
+ const newVariation = (await modules.products.variations.create(
42
+ productVariation,
43
+ )) as ProductVariation;
44
+ return newVariation;
45
+ } catch {
46
+ return (await modules.products.variations.update(
47
+ productVariation._id!,
48
+ productVariation,
49
+ )) as ProductVariation;
50
+ }
51
+ };
52
+
53
+ export default async function upsertVariations(
54
+ { variations, productId }: { variations: z.infer<typeof ProductVariationSchema>[]; productId: string },
55
+ unchainedAPI: { modules: Modules },
56
+ ) {
57
+ const { modules } = unchainedAPI;
58
+
59
+ const upsertedProductVariationIds = await Promise.all(
60
+ variations.map(async ({ content, options, ...variationsRest }) => {
61
+ const variation = await upsert(
62
+ {
63
+ ...variationsRest,
64
+ options: options.map((option) => option.value),
65
+ productId,
66
+ },
67
+ unchainedAPI,
68
+ );
69
+
70
+ await Promise.all(
71
+ options.map(async ({ content: optionContent, value: optionValue }) => {
72
+ if (optionContent) {
73
+ await modules.products.variations.texts.updateVariationTexts(
74
+ variation._id,
75
+ Object.entries(optionContent).map(([locale, localizedData]: [string, any]) => {
76
+ return {
77
+ locale,
78
+ ...localizedData,
79
+ };
80
+ }),
81
+ optionValue,
82
+ );
83
+ }
84
+ }),
85
+ );
86
+ if (content) {
87
+ await modules.products.variations.texts.updateVariationTexts(
88
+ variation._id,
89
+ Object.entries(content).map(([locale, localizedData]: [string, any]) => {
90
+ return {
91
+ locale,
92
+ ...localizedData,
93
+ };
94
+ }),
95
+ );
96
+ }
97
+ return variation._id;
98
+ }),
99
+ );
100
+ const allVariations = await modules.products.variations.findProductVariations({
101
+ productId,
102
+ });
103
+ await Promise.all(
104
+ allVariations.map(async (variation) => {
105
+ if (!upsertedProductVariationIds.includes(variation._id)) {
106
+ await modules.products.variations.delete(variation._id);
107
+ }
108
+ }),
109
+ );
110
+ }
@@ -0,0 +1,4 @@
1
+ export default (tags: string[]): string[] | null => {
2
+ if (Array.isArray(tags)) return tags.map((tag) => tag.toLowerCase());
3
+ return null;
4
+ };
@@ -0,0 +1,3 @@
1
+ import { default as createBulkImporterFactory } from './createBulkImporter.js';
2
+ export * from './createBulkImporter.js';
3
+ export default createBulkImporterFactory;
@@ -0,0 +1,50 @@
1
+ import { Modules } from '../modules.js';
2
+ import { Services } from '../services/index.js';
3
+ import { z } from 'zod';
4
+
5
+ export const AssetSchema = z.object({
6
+ _id: z.string().optional(),
7
+ url: z.string(),
8
+ meta: z.record(z.unknown()).optional(),
9
+ fileName: z.string(),
10
+ headers: z.record(z.string()).optional(),
11
+ });
12
+
13
+ const upsertAsset = async (
14
+ directoryName: string,
15
+ asset: z.infer<typeof AssetSchema>,
16
+ unchainedAPI: { modules: Modules; services: Services },
17
+ ) => {
18
+ const { modules, services } = unchainedAPI;
19
+ const { _id: fileId, fileName, url, meta, headers, ...assetData } = asset;
20
+
21
+ try {
22
+ const existingFile = fileId && (await modules.files.findFile({ fileId }));
23
+ if (existingFile) {
24
+ if (JSON.stringify(meta) === JSON.stringify(existingFile.meta)) {
25
+ return existingFile;
26
+ }
27
+ await modules.files.update(fileId, { meta, ...assetData });
28
+ const updatedFile = await modules.files.findFile({ fileId });
29
+ return updatedFile;
30
+ }
31
+
32
+ const assetObject = await services.files.uploadFileFromURL({
33
+ directoryName,
34
+ fileInput: {
35
+ fileLink: url,
36
+ fileName,
37
+ fileId,
38
+ headers,
39
+ },
40
+ meta,
41
+ });
42
+
43
+ if (!assetObject) throw new Error('Media not created');
44
+ return assetObject;
45
+ } catch {
46
+ return null;
47
+ }
48
+ };
49
+
50
+ export default upsertAsset;
package/src/core-index.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import { mongodb, MigrationRepository, ModuleInput } from '@unchainedshop/mongodb';
2
2
  import initServices, { CustomServices, Services } from './services/index.js';
3
3
  import initModules, { Modules, ModuleOptions } from './modules.js';
4
+ import createBulkImporterFactory, { BulkImporter, BulkImportHandler } from './bulk-importer/index.js';
4
5
 
5
6
  import {
6
7
  WorkerDirector,
@@ -17,18 +18,19 @@ import {
17
18
  QuotationDirector,
18
19
  WarehousingDirector,
19
20
  } from './directors/index.js';
21
+ import { IBaseAdapter } from '@unchainedshop/utils';
20
22
 
23
+ export * from './bulk-importer/index.js';
21
24
  export * from './services/index.js';
22
25
  export * from './directors/index.js';
23
-
24
- export interface BulkImporter {
25
- createBulkImporter: (options: any) => any;
26
- }
26
+ export * from './factory/index.js';
27
27
 
28
28
  export interface UnchainedCoreOptions {
29
29
  db: mongodb.Db;
30
30
  migrationRepository: MigrationRepository<UnchainedCore>;
31
- bulkImporter: any;
31
+ bulkImporter?: {
32
+ handlers?: Record<string, BulkImportHandler<UnchainedCore>>;
33
+ };
32
34
  modules?: Record<
33
35
  string,
34
36
  {
@@ -49,13 +51,14 @@ export interface UnchainedCore {
49
51
  export const initCore = async ({
50
52
  db,
51
53
  migrationRepository,
52
- bulkImporter,
54
+ bulkImporter: bulkImporterOptions = {},
53
55
  modules: customModules = {},
54
56
  services: customServices = {},
55
57
  options = {},
56
58
  }: UnchainedCoreOptions): Promise<UnchainedCore> => {
57
59
  // Configure custom modules
58
60
 
61
+ const bulkImporter = createBulkImporterFactory(db, bulkImporterOptions);
59
62
  const modules = await initModules({ db, migrationRepository, options }, customModules);
60
63
  const services = initServices(modules, customServices);
61
64
 
@@ -82,7 +85,7 @@ export const getAllAdapters = () => {
82
85
  const quotation = QuotationDirector.getAdapters();
83
86
  const warehousing = WarehousingDirector.getAdapters();
84
87
 
85
- return [].concat(
88
+ return ([] as IBaseAdapter[]).concat(
86
89
  worker,
87
90
  delivery,
88
91
  deliveryPricing,
@@ -32,7 +32,7 @@ describe('BaseDiscountAdapter instantiation', () => {
32
32
 
33
33
  it('release', async () => {
34
34
  const result = await adapter.actions(context);
35
- assert.equal(await result.release(), null);
35
+ assert.equal(await result.release(), undefined);
36
36
  });
37
37
 
38
38
  it('isValidForCodeTriggering', async () => {
@@ -6,13 +6,13 @@ import { Modules } from '../modules.js';
6
6
  export interface DiscountContext {
7
7
  code?: string;
8
8
  orderDiscount?: OrderDiscount;
9
- order?: Order;
9
+ order: Order;
10
10
  }
11
11
 
12
12
  export type IDiscountAdapter<DiscountConfiguration> = IBaseAdapter & {
13
13
  orderIndex: number;
14
14
 
15
- isManualAdditionAllowed: (code: string) => Promise<boolean>;
15
+ isManualAdditionAllowed: (code?: string) => Promise<boolean>;
16
16
  isManualRemovalAllowed: () => Promise<boolean>;
17
17
 
18
18
  actions: (params: {
@@ -27,9 +27,9 @@ export interface DiscountAdapterActions<DiscountConfiguration> {
27
27
  discountForPricingAdapterKey: (params: {
28
28
  pricingAdapterKey: string;
29
29
  calculationSheet: IPricingSheet<PricingCalculation>;
30
- }) => DiscountConfiguration;
30
+ }) => DiscountConfiguration | null;
31
31
 
32
- reserve: (params: { code: string }) => Promise<any>;
32
+ reserve: (params: { code?: string }) => Promise<any>;
33
33
  release: () => Promise<void>;
34
34
  }
35
35
 
@@ -67,7 +67,7 @@ export const BaseDiscountAdapter: Omit<IDiscountAdapter<unknown>, 'key' | 'label
67
67
 
68
68
  // return void, allows you to free up any reservations in backend systems
69
69
  release: async () => {
70
- return null;
70
+ return;
71
71
  },
72
72
 
73
73
  // return true if a discount is valid to be part of the order.
@@ -11,7 +11,7 @@ export type IDiscountDirector<DiscountConfiguration> = IBaseDirector<
11
11
  ) => Promise<{
12
12
  resolveDiscountAdapterFromStaticCode: (params: {
13
13
  code: string;
14
- }) => Promise<IDiscountAdapter<DiscountConfiguration>>;
14
+ }) => Promise<IDiscountAdapter<DiscountConfiguration> | null>;
15
15
  findSystemDiscounts: () => Promise<string[]>;
16
16
  }>;
17
17
  };
@@ -46,7 +46,7 @@ export const BaseDiscountDirector = <DiscountConfigurationType>(
46
46
  }),
47
47
  );
48
48
 
49
- return discounts.find(({ isValid }) => isValid === true)?.Adapter;
49
+ return discounts.find(({ isValid }) => isValid === true)?.Adapter || null;
50
50
  },
51
51
 
52
52
  async findSystemDiscounts() {
@@ -4,7 +4,7 @@ import { Discount } from './BasePricingDirector.js';
4
4
  import { Order, OrderDiscount } from '@unchainedshop/core-orders';
5
5
 
6
6
  interface IDiscountableItem {
7
- _id?: string;
7
+ _id: string;
8
8
  orderId?: string;
9
9
  }
10
10
 
@@ -26,7 +26,7 @@ export interface IPricingAdapterActions<
26
26
  Calculation extends PricingCalculation,
27
27
  Sheet extends IPricingSheet<Calculation>,
28
28
  > {
29
- calculate: () => Promise<Calculation[]>;
29
+ calculate: () => Promise<Calculation[] | null>;
30
30
  resultSheet: () => Sheet;
31
31
  }
32
32
 
@@ -70,7 +70,7 @@ export const BasePricingDirector = <
70
70
  async rebuildCalculation(this: typeof director, pricingContext, unchainedAPI) {
71
71
  const context = await this.buildPricingContext(pricingContext, unchainedAPI);
72
72
 
73
- let calculation: Calculation[] = [];
73
+ let calculation: Calculation[] | null = [];
74
74
 
75
75
  const Adapters = baseDirector.getAdapters({
76
76
  adapterFilter: (Adapter) => {
@@ -78,52 +78,55 @@ export const BasePricingDirector = <
78
78
  },
79
79
  });
80
80
 
81
- calculation = await Adapters.reduce(async (previousPromise, Adapter) => {
82
- const resolvedCalculation = await previousPromise;
83
- if (!resolvedCalculation) return null;
84
-
85
- const discounts: Discount<any>[] = await Promise.all(
86
- context.discounts.map(async (orderDiscount) => {
87
- const order = await unchainedAPI.modules.orders.findOrder({
88
- orderId: orderDiscount.orderId,
89
- });
90
- const DiscountAdapter = OrderDiscountDirector.getAdapter(orderDiscount.discountKey);
91
- if (!DiscountAdapter) return null;
92
-
93
- const adapter = await DiscountAdapter.actions({
94
- context: { order, orderDiscount, code: orderDiscount.code, ...unchainedAPI },
81
+ calculation = await Adapters.reduce(
82
+ async (previousPromise, Adapter) => {
83
+ const resolvedCalculation = await previousPromise;
84
+ if (!resolvedCalculation) return null;
85
+
86
+ const discounts: (Discount<any> | null)[] = await Promise.all(
87
+ context.discounts.map(async (orderDiscount) => {
88
+ const order = await unchainedAPI.modules.orders.findOrder({
89
+ orderId: orderDiscount.orderId,
90
+ });
91
+ const DiscountAdapter = OrderDiscountDirector.getAdapter(orderDiscount.discountKey);
92
+ if (!DiscountAdapter) return null;
93
+
94
+ const adapter = await DiscountAdapter.actions({
95
+ context: { order, orderDiscount, code: orderDiscount.code, ...unchainedAPI },
96
+ });
97
+
98
+ const configuration = adapter.discountForPricingAdapterKey({
99
+ pricingAdapterKey: Adapter.key,
100
+ calculationSheet: this.calculationSheet(pricingContext, resolvedCalculation),
101
+ });
102
+
103
+ return {
104
+ discountId: orderDiscount._id,
105
+ configuration,
106
+ };
107
+ }),
108
+ );
109
+
110
+ try {
111
+ const adapter = Adapter.actions({
112
+ context,
113
+ calculationSheet: this.calculationSheet(pricingContext, resolvedCalculation),
114
+ discounts: discounts.filter((d) => d?.configuration !== null) as Discount<any>[],
95
115
  });
96
116
 
97
- const configuration = adapter.discountForPricingAdapterKey({
98
- pricingAdapterKey: Adapter.key,
99
- calculationSheet: this.calculationSheet(pricingContext, calculation),
100
- });
117
+ const nextCalculationResult = await adapter.calculate();
118
+ if (!nextCalculationResult) return null;
119
+ calculation = resolvedCalculation.concat(nextCalculationResult);
120
+ return calculation;
121
+ } catch (error) {
122
+ logger.error(error);
123
+ }
124
+ return resolvedCalculation;
125
+ },
126
+ Promise.resolve([] as Calculation[]),
127
+ );
101
128
 
102
- return {
103
- discountId: orderDiscount._id,
104
- configuration,
105
- };
106
- }),
107
- );
108
-
109
- try {
110
- const adapter = Adapter.actions({
111
- context,
112
- calculationSheet: this.calculationSheet(pricingContext, calculation),
113
- discounts: discounts.filter((d) => d?.configuration !== null),
114
- });
115
-
116
- const nextCalculationResult = await adapter.calculate();
117
- if (!nextCalculationResult) return null;
118
- calculation = resolvedCalculation.concat(nextCalculationResult);
119
- return calculation;
120
- } catch (error) {
121
- logger.error(error);
122
- }
123
- return resolvedCalculation;
124
- }, Promise.resolve([]));
125
-
126
- return calculation;
129
+ return calculation || ([] as Calculation[]);
127
130
  },
128
131
  };
129
132
 
@@ -93,7 +93,7 @@ export const BasePricingSheet = <Calculation extends PricingCalculation>(
93
93
  (oldCalculation, filterKey) =>
94
94
  oldCalculation.filter(
95
95
  (row: Calculation) =>
96
- !!row && (filter[filterKey] === undefined || row[filterKey] === filter[filterKey]),
96
+ !!row && (filter![filterKey] === undefined || row[filterKey] === filter![filterKey]),
97
97
  ),
98
98
  this.calculation,
99
99
  );