@medusajs/medusa 1.2.2-dev.53 → 1.3.1-alpha.63

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 (736) hide show
  1. package/CHANGELOG.md +98 -0
  2. package/dist/api/index.d.ts +1 -0
  3. package/dist/api/index.js +1 -0
  4. package/dist/api/index.js.map +1 -1
  5. package/dist/api/middlewares/authenticate-customer.d.ts +2 -1
  6. package/dist/api/middlewares/authenticate-customer.js +1 -2
  7. package/dist/api/middlewares/authenticate-customer.js.map +1 -1
  8. package/dist/api/middlewares/authenticate.d.ts +2 -1
  9. package/dist/api/middlewares/authenticate.js.map +1 -1
  10. package/dist/api/middlewares/await-middleware.d.ts +3 -1
  11. package/dist/api/middlewares/await-middleware.js +2 -31
  12. package/dist/api/middlewares/await-middleware.js.map +1 -1
  13. package/dist/api/middlewares/batch-job/can-access-batch-job.d.ts +1 -0
  14. package/dist/api/middlewares/batch-job/can-access-batch-job.js +70 -0
  15. package/dist/api/middlewares/batch-job/can-access-batch-job.js.map +1 -0
  16. package/dist/api/middlewares/batch-job/get-requested-batch-job.d.ts +1 -0
  17. package/dist/api/middlewares/batch-job/get-requested-batch-job.js +67 -0
  18. package/dist/api/middlewares/batch-job/get-requested-batch-job.js.map +1 -0
  19. package/dist/api/middlewares/error-handler.d.ts +3 -1
  20. package/dist/api/middlewares/error-handler.js +4 -4
  21. package/dist/api/middlewares/error-handler.js.map +1 -1
  22. package/dist/api/middlewares/index.d.ts +12 -10
  23. package/dist/api/middlewares/index.js +9 -0
  24. package/dist/api/middlewares/index.js.map +1 -1
  25. package/dist/api/middlewares/normalized-query.d.ts +6 -1
  26. package/dist/api/middlewares/normalized-query.js +5 -2
  27. package/dist/api/middlewares/normalized-query.js.map +1 -1
  28. package/dist/api/middlewares/transform-body.d.ts +4 -0
  29. package/dist/api/middlewares/transform-body.js +66 -0
  30. package/dist/api/middlewares/transform-body.js.map +1 -0
  31. package/dist/api/middlewares/transform-query.d.ts +6 -0
  32. package/dist/api/middlewares/transform-query.js +86 -0
  33. package/dist/api/middlewares/transform-query.js.map +1 -0
  34. package/dist/api/routes/admin/auth/create-session.js +5 -5
  35. package/dist/api/routes/admin/auth/create-session.js.map +1 -1
  36. package/dist/api/routes/admin/batch/index.d.ts +13 -0
  37. package/dist/api/routes/admin/batch/index.js +50 -0
  38. package/dist/api/routes/admin/batch/index.js.map +1 -0
  39. package/dist/api/routes/admin/batch/list-batch-jobs.d.ts +48 -0
  40. package/dist/api/routes/admin/batch/list-batch-jobs.js +220 -0
  41. package/dist/api/routes/admin/batch/list-batch-jobs.js.map +1 -0
  42. package/dist/api/routes/admin/customer-groups/list-customer-groups.js +2 -2
  43. package/dist/api/routes/admin/customer-groups/list-customer-groups.js.map +1 -1
  44. package/dist/api/routes/admin/discounts/create-condition.d.ts +58 -0
  45. package/dist/api/routes/admin/discounts/create-condition.js +186 -0
  46. package/dist/api/routes/admin/discounts/create-condition.js.map +1 -0
  47. package/dist/api/routes/admin/discounts/create-discount.d.ts +14 -4
  48. package/dist/api/routes/admin/discounts/create-discount.js +72 -16
  49. package/dist/api/routes/admin/discounts/create-discount.js.map +1 -1
  50. package/dist/api/routes/admin/discounts/create-dynamic-code.d.ts +1 -0
  51. package/dist/api/routes/admin/discounts/create-dynamic-code.js +4 -1
  52. package/dist/api/routes/admin/discounts/create-dynamic-code.js.map +1 -1
  53. package/dist/api/routes/admin/discounts/delete-condition.d.ts +36 -0
  54. package/dist/api/routes/admin/discounts/delete-condition.js +151 -0
  55. package/dist/api/routes/admin/discounts/delete-condition.js.map +1 -0
  56. package/dist/api/routes/admin/discounts/delete-dynamic-code.js +3 -1
  57. package/dist/api/routes/admin/discounts/delete-dynamic-code.js.map +1 -1
  58. package/dist/api/routes/admin/discounts/get-condition.d.ts +31 -0
  59. package/dist/api/routes/admin/discounts/get-condition.js +125 -0
  60. package/dist/api/routes/admin/discounts/get-condition.js.map +1 -0
  61. package/dist/api/routes/admin/discounts/get-discount-by-code.d.ts +4 -0
  62. package/dist/api/routes/admin/discounts/get-discount-by-code.js +40 -6
  63. package/dist/api/routes/admin/discounts/get-discount-by-code.js.map +1 -1
  64. package/dist/api/routes/admin/discounts/get-discount.d.ts +7 -0
  65. package/dist/api/routes/admin/discounts/get-discount.js +43 -9
  66. package/dist/api/routes/admin/discounts/get-discount.js.map +1 -1
  67. package/dist/api/routes/admin/discounts/index.d.ts +11 -3
  68. package/dist/api/routes/admin/discounts/index.js +13 -7
  69. package/dist/api/routes/admin/discounts/index.js.map +1 -1
  70. package/dist/api/routes/admin/discounts/list-discounts.d.ts +2 -6
  71. package/dist/api/routes/admin/discounts/list-discounts.js +15 -28
  72. package/dist/api/routes/admin/discounts/list-discounts.js.map +1 -1
  73. package/dist/api/routes/admin/discounts/update-condition.d.ts +55 -0
  74. package/dist/api/routes/admin/discounts/update-condition.js +184 -0
  75. package/dist/api/routes/admin/discounts/update-condition.js.map +1 -0
  76. package/dist/api/routes/admin/discounts/update-discount.d.ts +18 -12
  77. package/dist/api/routes/admin/discounts/update-discount.js +79 -33
  78. package/dist/api/routes/admin/discounts/update-discount.js.map +1 -1
  79. package/dist/api/routes/admin/draft-orders/create-draft-order.d.ts +3 -3
  80. package/dist/api/routes/admin/draft-orders/create-draft-order.js.map +1 -1
  81. package/dist/api/routes/admin/draft-orders/create-line-item.d.ts +1 -1
  82. package/dist/api/routes/admin/draft-orders/create-line-item.js.map +1 -1
  83. package/dist/api/routes/admin/draft-orders/index.d.ts +1 -1
  84. package/dist/api/routes/admin/draft-orders/index.js +7 -1
  85. package/dist/api/routes/admin/draft-orders/index.js.map +1 -1
  86. package/dist/api/routes/admin/draft-orders/list-draft-orders.js +7 -6
  87. package/dist/api/routes/admin/draft-orders/list-draft-orders.js.map +1 -1
  88. package/dist/api/routes/admin/draft-orders/register-payment.js +0 -1
  89. package/dist/api/routes/admin/draft-orders/register-payment.js.map +1 -1
  90. package/dist/api/routes/admin/draft-orders/update-line-item.d.ts +1 -1
  91. package/dist/api/routes/admin/draft-orders/update-line-item.js.map +1 -1
  92. package/dist/api/routes/admin/index.js +23 -19
  93. package/dist/api/routes/admin/index.js.map +1 -1
  94. package/dist/api/routes/admin/notifications/index.js.map +1 -1
  95. package/dist/api/routes/admin/notifications/list-notifications.js.map +1 -1
  96. package/dist/api/routes/admin/notifications/resend-notification.js.map +1 -1
  97. package/dist/api/routes/admin/orders/add-shipping-method.d.ts +1 -1
  98. package/dist/api/routes/admin/orders/add-shipping-method.js.map +1 -1
  99. package/dist/api/routes/admin/orders/create-claim.d.ts +4 -14
  100. package/dist/api/routes/admin/orders/create-claim.js +9 -14
  101. package/dist/api/routes/admin/orders/create-claim.js.map +1 -1
  102. package/dist/api/routes/admin/orders/create-order.js.map +1 -1
  103. package/dist/api/routes/admin/orders/create-swap.js +7 -3
  104. package/dist/api/routes/admin/orders/create-swap.js.map +1 -1
  105. package/dist/api/routes/admin/orders/fulfill-claim.d.ts +1 -1
  106. package/dist/api/routes/admin/orders/fulfill-claim.js.map +1 -1
  107. package/dist/api/routes/admin/orders/index.d.ts +1 -1
  108. package/dist/api/routes/admin/orders/index.js +1 -3
  109. package/dist/api/routes/admin/orders/index.js.map +1 -1
  110. package/dist/api/routes/admin/orders/list-orders.js.map +1 -1
  111. package/dist/api/routes/admin/orders/update-claim.d.ts +1 -1
  112. package/dist/api/routes/admin/orders/update-claim.js.map +1 -1
  113. package/dist/api/routes/admin/orders/update-order.js.map +1 -1
  114. package/dist/api/routes/admin/price-lists/add-prices-batch.d.ts +70 -0
  115. package/dist/api/routes/admin/price-lists/add-prices-batch.js +158 -0
  116. package/dist/api/routes/admin/price-lists/add-prices-batch.js.map +1 -0
  117. package/dist/api/routes/admin/price-lists/create-price-list.d.ts +88 -0
  118. package/dist/api/routes/admin/price-lists/create-price-list.js +190 -0
  119. package/dist/api/routes/admin/price-lists/create-price-list.js.map +1 -0
  120. package/dist/api/routes/admin/price-lists/delete-price-list.d.ts +28 -0
  121. package/dist/api/routes/admin/price-lists/delete-price-list.js +84 -0
  122. package/dist/api/routes/admin/price-lists/delete-price-list.js.map +1 -0
  123. package/dist/api/routes/admin/price-lists/delete-prices-batch.d.ts +43 -0
  124. package/dist/api/routes/admin/price-lists/delete-prices-batch.js +118 -0
  125. package/dist/api/routes/admin/price-lists/delete-prices-batch.js.map +1 -0
  126. package/dist/api/routes/admin/price-lists/delete-product-prices.d.ts +32 -0
  127. package/dist/api/routes/admin/price-lists/delete-product-prices.js +105 -0
  128. package/dist/api/routes/admin/price-lists/delete-product-prices.js.map +1 -0
  129. package/dist/api/routes/admin/price-lists/delete-variant-prices.d.ts +32 -0
  130. package/dist/api/routes/admin/price-lists/delete-variant-prices.js +105 -0
  131. package/dist/api/routes/admin/price-lists/delete-variant-prices.js.map +1 -0
  132. package/dist/api/routes/admin/price-lists/get-price-list.d.ts +22 -0
  133. package/dist/api/routes/admin/price-lists/get-price-list.js +78 -0
  134. package/dist/api/routes/admin/price-lists/get-price-list.js.map +1 -0
  135. package/dist/api/routes/admin/price-lists/index.d.ts +30 -0
  136. package/dist/api/routes/admin/price-lists/index.js +76 -0
  137. package/dist/api/routes/admin/price-lists/index.js.map +1 -0
  138. package/dist/api/routes/admin/price-lists/list-price-list-products.d.ts +75 -0
  139. package/dist/api/routes/admin/price-lists/list-price-list-products.js +255 -0
  140. package/dist/api/routes/admin/price-lists/list-price-list-products.js.map +1 -0
  141. package/dist/api/routes/admin/price-lists/list-price-lists.d.ts +39 -0
  142. package/dist/api/routes/admin/price-lists/list-price-lists.js +165 -0
  143. package/dist/api/routes/admin/price-lists/list-price-lists.js.map +1 -0
  144. package/dist/api/routes/admin/price-lists/update-price-list.d.ts +92 -0
  145. package/dist/api/routes/admin/price-lists/update-price-list.js +211 -0
  146. package/dist/api/routes/admin/price-lists/update-price-list.js.map +1 -0
  147. package/dist/api/routes/admin/product-tags/list-product-tags.d.ts +2 -1
  148. package/dist/api/routes/admin/product-tags/list-product-tags.js +6 -3
  149. package/dist/api/routes/admin/product-tags/list-product-tags.js.map +1 -1
  150. package/dist/api/routes/admin/product-types/list-product-types.d.ts +2 -1
  151. package/dist/api/routes/admin/product-types/list-product-types.js +6 -3
  152. package/dist/api/routes/admin/product-types/list-product-types.js.map +1 -1
  153. package/dist/api/routes/admin/products/create-product.d.ts +2 -7
  154. package/dist/api/routes/admin/products/create-product.js +2 -24
  155. package/dist/api/routes/admin/products/create-product.js.map +1 -1
  156. package/dist/api/routes/admin/products/create-variant.d.ts +7 -9
  157. package/dist/api/routes/admin/products/create-variant.js +7 -26
  158. package/dist/api/routes/admin/products/create-variant.js.map +1 -1
  159. package/dist/api/routes/admin/products/index.d.ts +3 -2
  160. package/dist/api/routes/admin/products/index.js +8 -3
  161. package/dist/api/routes/admin/products/index.js.map +1 -1
  162. package/dist/api/routes/admin/products/list-products.d.ts +2 -1
  163. package/dist/api/routes/admin/products/list-products.js +31 -65
  164. package/dist/api/routes/admin/products/list-products.js.map +1 -1
  165. package/dist/api/routes/admin/products/list-variants.d.ts +35 -0
  166. package/dist/api/routes/admin/products/list-variants.js +173 -0
  167. package/dist/api/routes/admin/products/list-variants.js.map +1 -0
  168. package/dist/api/routes/admin/products/update-product.d.ts +2 -7
  169. package/dist/api/routes/admin/products/update-product.js +2 -24
  170. package/dist/api/routes/admin/products/update-product.js.map +1 -1
  171. package/dist/api/routes/admin/products/update-variant.d.ts +10 -9
  172. package/dist/api/routes/admin/products/update-variant.js +21 -33
  173. package/dist/api/routes/admin/products/update-variant.js.map +1 -1
  174. package/dist/api/routes/admin/regions/index.d.ts +1 -1
  175. package/dist/api/routes/admin/shipping-options/list-shipping-options.d.ts +2 -2
  176. package/dist/api/routes/admin/shipping-options/list-shipping-options.js +2 -2
  177. package/dist/api/routes/admin/shipping-options/list-shipping-options.js.map +1 -1
  178. package/dist/api/routes/admin/store/get-store.js +4 -2
  179. package/dist/api/routes/admin/store/get-store.js.map +1 -1
  180. package/dist/api/routes/admin/store/update-store.d.ts +1 -0
  181. package/dist/api/routes/admin/store/update-store.js +5 -0
  182. package/dist/api/routes/admin/store/update-store.js.map +1 -1
  183. package/dist/api/routes/admin/swaps/index.js +3 -0
  184. package/dist/api/routes/admin/swaps/index.js.map +1 -1
  185. package/dist/api/routes/admin/tax-rates/list-tax-rates.js.map +1 -1
  186. package/dist/api/routes/admin/tax-rates/utils/get-query-config.d.ts +1 -1
  187. package/dist/api/routes/admin/tax-rates/utils/get-query-config.js +4 -2
  188. package/dist/api/routes/admin/tax-rates/utils/get-query-config.js.map +1 -1
  189. package/dist/api/routes/admin/uploads/index.d.ts +1 -1
  190. package/dist/api/routes/admin/users/update-user.d.ts +1 -1
  191. package/dist/api/routes/admin/users/update-user.js.map +1 -1
  192. package/dist/api/routes/store/auth/create-session.js +4 -5
  193. package/dist/api/routes/store/auth/create-session.js.map +1 -1
  194. package/dist/api/routes/store/carts/create-cart.js +8 -5
  195. package/dist/api/routes/store/carts/create-cart.js.map +1 -1
  196. package/dist/api/routes/store/carts/create-line-item.d.ts +1 -1
  197. package/dist/api/routes/store/carts/create-line-item.js +9 -6
  198. package/dist/api/routes/store/carts/create-line-item.js.map +1 -1
  199. package/dist/api/routes/store/carts/index.d.ts +0 -1
  200. package/dist/api/routes/store/carts/index.js +1 -3
  201. package/dist/api/routes/store/carts/index.js.map +1 -1
  202. package/dist/api/routes/store/carts/update-cart.js +8 -8
  203. package/dist/api/routes/store/carts/update-cart.js.map +1 -1
  204. package/dist/api/routes/store/collections/list-collections.d.ts +3 -0
  205. package/dist/api/routes/store/collections/list-collections.js +33 -16
  206. package/dist/api/routes/store/collections/list-collections.js.map +1 -1
  207. package/dist/api/routes/store/customers/create-customer.js +3 -4
  208. package/dist/api/routes/store/customers/create-customer.js.map +1 -1
  209. package/dist/api/routes/store/customers/get-payment-methods.js +6 -7
  210. package/dist/api/routes/store/customers/get-payment-methods.js.map +1 -1
  211. package/dist/api/routes/store/orders/index.js +0 -2
  212. package/dist/api/routes/store/orders/index.js.map +1 -1
  213. package/dist/api/routes/store/products/get-product.js +17 -5
  214. package/dist/api/routes/store/products/get-product.js.map +1 -1
  215. package/dist/api/routes/store/products/index.d.ts +2 -2
  216. package/dist/api/routes/store/products/list-products.d.ts +2 -2
  217. package/dist/api/routes/store/products/list-products.js +21 -14
  218. package/dist/api/routes/store/products/list-products.js.map +1 -1
  219. package/dist/api/routes/store/products/search.d.ts +1 -1
  220. package/dist/api/routes/store/products/search.js.map +1 -1
  221. package/dist/api/routes/store/regions/list-regions.d.ts +3 -0
  222. package/dist/api/routes/store/regions/list-regions.js +22 -7
  223. package/dist/api/routes/store/regions/list-regions.js.map +1 -1
  224. package/dist/api/routes/store/shipping-options/list-options.js.map +1 -1
  225. package/dist/api/routes/store/swaps/create-swap.js +7 -3
  226. package/dist/api/routes/store/swaps/create-swap.js.map +1 -1
  227. package/dist/api/routes/store/variants/get-variant.js +17 -5
  228. package/dist/api/routes/store/variants/get-variant.js.map +1 -1
  229. package/dist/api/routes/store/variants/list-variants.d.ts +2 -1
  230. package/dist/api/routes/store/variants/list-variants.js +38 -9
  231. package/dist/api/routes/store/variants/list-variants.js.map +1 -1
  232. package/dist/commands/develop.js +2 -2
  233. package/dist/commands/develop.js.map +1 -1
  234. package/dist/commands/migrate.js +17 -6
  235. package/dist/commands/migrate.js.map +1 -1
  236. package/dist/commands/start.js +6 -0
  237. package/dist/commands/start.js.map +1 -1
  238. package/dist/controllers/customers/index.d.ts +1 -1
  239. package/dist/controllers/customers/list-customers.d.ts +1 -1
  240. package/dist/controllers/customers/list-customers.js +34 -37
  241. package/dist/controllers/customers/list-customers.js.map +1 -1
  242. package/dist/controllers/products/admin-list-products.d.ts +16 -0
  243. package/dist/controllers/products/admin-list-products.js +103 -0
  244. package/dist/controllers/products/admin-list-products.js.map +1 -0
  245. package/dist/helpers/test-request.js +26 -17
  246. package/dist/helpers/test-request.js.map +1 -1
  247. package/dist/index.d.ts +4 -58
  248. package/dist/index.js +4 -61
  249. package/dist/index.js.map +1 -1
  250. package/dist/interfaces/base-service.d.ts +66 -0
  251. package/dist/interfaces/base-service.js +377 -0
  252. package/dist/interfaces/base-service.js.map +1 -0
  253. package/dist/interfaces/batch-job-strategy.d.ts +28 -0
  254. package/dist/interfaces/batch-job-strategy.js +75 -0
  255. package/dist/interfaces/batch-job-strategy.js.map +1 -0
  256. package/dist/interfaces/file-service.d.ts +62 -0
  257. package/dist/interfaces/file-service.js +32 -0
  258. package/dist/interfaces/file-service.js.map +1 -0
  259. package/dist/interfaces/index.d.ts +4 -0
  260. package/dist/interfaces/index.js +4 -0
  261. package/dist/interfaces/index.js.map +1 -1
  262. package/dist/interfaces/models/base-entity.d.ts +8 -0
  263. package/dist/interfaces/models/base-entity.js +36 -0
  264. package/dist/interfaces/models/base-entity.js.map +1 -0
  265. package/dist/interfaces/models/soft-deletable-entity.d.ts +4 -0
  266. package/dist/interfaces/models/soft-deletable-entity.js +43 -0
  267. package/dist/interfaces/models/soft-deletable-entity.js.map +1 -0
  268. package/dist/interfaces/price-selection-strategy.d.ts +50 -0
  269. package/dist/interfaces/price-selection-strategy.js +34 -0
  270. package/dist/interfaces/price-selection-strategy.js.map +1 -0
  271. package/dist/interfaces/tax-service.d.ts +6 -0
  272. package/dist/interfaces/tax-service.js +31 -0
  273. package/dist/interfaces/tax-service.js.map +1 -1
  274. package/dist/interfaces/transaction-base-service.d.ts +23 -0
  275. package/dist/interfaces/transaction-base-service.js +200 -0
  276. package/dist/interfaces/transaction-base-service.js.map +1 -0
  277. package/dist/loaders/api.d.ts +9 -5
  278. package/dist/loaders/api.js +2 -6
  279. package/dist/loaders/api.js.map +1 -1
  280. package/dist/loaders/config.d.ts +3 -0
  281. package/dist/loaders/config.js +47 -0
  282. package/dist/loaders/config.js.map +1 -0
  283. package/dist/loaders/database.d.ts +8 -4
  284. package/dist/loaders/database.js.map +1 -1
  285. package/dist/loaders/defaults.d.ts +4 -3
  286. package/dist/loaders/defaults.js +39 -31
  287. package/dist/loaders/defaults.js.map +1 -1
  288. package/dist/loaders/express.d.ts +7 -4
  289. package/dist/loaders/express.js +7 -5
  290. package/dist/loaders/express.js.map +1 -1
  291. package/dist/loaders/index.d.ts +13 -8
  292. package/dist/loaders/index.js +29 -54
  293. package/dist/loaders/index.js.map +1 -1
  294. package/dist/loaders/logger.d.ts +1 -0
  295. package/dist/loaders/logger.js.map +1 -1
  296. package/dist/loaders/models.d.ts +8 -3
  297. package/dist/loaders/models.js +19 -17
  298. package/dist/loaders/models.js.map +1 -1
  299. package/dist/loaders/passport.d.ts +7 -4
  300. package/dist/loaders/passport.js +23 -21
  301. package/dist/loaders/passport.js.map +1 -1
  302. package/dist/loaders/plugins.d.ts +38 -10
  303. package/dist/loaders/plugins.js +43 -30
  304. package/dist/loaders/plugins.js.map +1 -1
  305. package/dist/loaders/redis.d.ts +8 -5
  306. package/dist/loaders/redis.js +3 -3
  307. package/dist/loaders/redis.js.map +1 -1
  308. package/dist/loaders/repositories.d.ts +7 -3
  309. package/dist/loaders/repositories.js +1 -1
  310. package/dist/loaders/repositories.js.map +1 -1
  311. package/dist/loaders/search-index.d.ts +4 -3
  312. package/dist/loaders/search-index.js.map +1 -1
  313. package/dist/loaders/services.d.ts +10 -5
  314. package/dist/loaders/services.js.map +1 -1
  315. package/dist/loaders/strategies.d.ts +1 -1
  316. package/dist/loaders/subscribers.d.ts +7 -3
  317. package/dist/loaders/subscribers.js.map +1 -1
  318. package/dist/migrations/1646324713514-discount_conditions.d.ts +6 -0
  319. package/dist/migrations/1646324713514-discount_conditions.js +335 -0
  320. package/dist/migrations/1646324713514-discount_conditions.js.map +1 -0
  321. package/dist/migrations/1646915480108-update_money_amount_add_price_list.d.ts +6 -0
  322. package/dist/migrations/1646915480108-update_money_amount_add_price_list.js +143 -0
  323. package/dist/migrations/1646915480108-update_money_amount_add_price_list.js.map +1 -0
  324. package/dist/migrations/1648600574750-add_line_item_adjustments.d.ts +6 -0
  325. package/dist/migrations/1648600574750-add_line_item_adjustments.js +101 -0
  326. package/dist/migrations/1648600574750-add_line_item_adjustments.js.map +1 -0
  327. package/dist/migrations/1648641130007-tax_line_constraints.d.ts +6 -0
  328. package/dist/migrations/1648641130007-tax_line_constraints.js +77 -0
  329. package/dist/migrations/1648641130007-tax_line_constraints.js.map +1 -0
  330. package/dist/migrations/1649775522087-add_batch_job_model.d.ts +6 -0
  331. package/dist/migrations/1649775522087-add_batch_job_model.js +77 -0
  332. package/dist/migrations/1649775522087-add_batch_job_model.js.map +1 -0
  333. package/dist/models/address.d.ts +3 -6
  334. package/dist/models/address.js +23 -24
  335. package/dist/models/address.js.map +1 -1
  336. package/dist/models/batch-job.d.ts +55 -0
  337. package/dist/models/batch-job.js +118 -0
  338. package/dist/models/batch-job.js.map +1 -0
  339. package/dist/models/cart.d.ts +5 -8
  340. package/dist/models/cart.js +35 -36
  341. package/dist/models/cart.js.map +1 -1
  342. package/dist/models/claim-image.d.ts +3 -6
  343. package/dist/models/claim-image.js +22 -23
  344. package/dist/models/claim-image.js.map +1 -1
  345. package/dist/models/claim-item.d.ts +3 -6
  346. package/dist/models/claim-item.js +25 -24
  347. package/dist/models/claim-item.js.map +1 -1
  348. package/dist/models/claim-order.d.ts +4 -4
  349. package/dist/models/claim-order.js +28 -13
  350. package/dist/models/claim-order.js.map +1 -1
  351. package/dist/models/claim-tag.d.ts +3 -6
  352. package/dist/models/claim-tag.js +22 -23
  353. package/dist/models/claim-tag.js.map +1 -1
  354. package/dist/models/country.d.ts +1 -1
  355. package/dist/models/country.js +1 -1
  356. package/dist/models/country.js.map +1 -1
  357. package/dist/models/custom-shipping-option.d.ts +3 -6
  358. package/dist/models/custom-shipping-option.js +23 -24
  359. package/dist/models/custom-shipping-option.js.map +1 -1
  360. package/dist/models/customer-group.d.ts +6 -7
  361. package/dist/models/customer-group.js +30 -36
  362. package/dist/models/customer-group.js.map +1 -1
  363. package/dist/models/customer.d.ts +3 -6
  364. package/dist/models/customer.js +23 -25
  365. package/dist/models/customer.js.map +1 -1
  366. package/dist/models/discount-condition-customer-group.d.ts +39 -0
  367. package/dist/models/discount-condition-customer-group.js +84 -0
  368. package/dist/models/discount-condition-customer-group.js.map +1 -0
  369. package/dist/models/discount-condition-product-collection.d.ts +39 -0
  370. package/dist/models/discount-condition-product-collection.js +84 -0
  371. package/dist/models/discount-condition-product-collection.js.map +1 -0
  372. package/dist/models/discount-condition-product-tag.d.ts +39 -0
  373. package/dist/models/discount-condition-product-tag.js +84 -0
  374. package/dist/models/discount-condition-product-tag.js.map +1 -0
  375. package/dist/models/discount-condition-product-type.d.ts +39 -0
  376. package/dist/models/discount-condition-product-type.js +84 -0
  377. package/dist/models/discount-condition-product-type.js.map +1 -0
  378. package/dist/models/discount-condition-product.d.ts +39 -0
  379. package/dist/models/discount-condition-product.js +84 -0
  380. package/dist/models/discount-condition-product.js.map +1 -0
  381. package/dist/models/discount-condition.d.ts +65 -0
  382. package/dist/models/discount-condition.js +209 -0
  383. package/dist/models/discount-condition.js.map +1 -0
  384. package/dist/models/discount-rule.d.ts +8 -11
  385. package/dist/models/discount-rule.js +28 -38
  386. package/dist/models/discount-rule.js.map +1 -1
  387. package/dist/models/discount.d.ts +7 -10
  388. package/dist/models/discount.js +30 -30
  389. package/dist/models/discount.js.map +1 -1
  390. package/dist/models/draft-order.d.ts +4 -7
  391. package/dist/models/draft-order.js +25 -22
  392. package/dist/models/draft-order.js.map +1 -1
  393. package/dist/models/fulfillment-item.js.map +1 -1
  394. package/dist/models/fulfillment-provider.js.map +1 -1
  395. package/dist/models/fulfillment.d.ts +5 -7
  396. package/dist/models/fulfillment.js +29 -21
  397. package/dist/models/fulfillment.js.map +1 -1
  398. package/dist/models/gift-card-transaction.js +2 -5
  399. package/dist/models/gift-card-transaction.js.map +1 -1
  400. package/dist/models/gift-card.d.ts +3 -6
  401. package/dist/models/gift-card.js +22 -23
  402. package/dist/models/gift-card.js.map +1 -1
  403. package/dist/models/idempotency-key.d.ts +2 -2
  404. package/dist/models/idempotency-key.js +2 -3
  405. package/dist/models/idempotency-key.js.map +1 -1
  406. package/dist/models/image.d.ts +3 -6
  407. package/dist/models/image.js +22 -23
  408. package/dist/models/image.js.map +1 -1
  409. package/dist/models/index.d.ts +67 -0
  410. package/dist/models/index.js +80 -0
  411. package/dist/models/index.js.map +1 -0
  412. package/dist/models/invite.d.ts +3 -6
  413. package/dist/models/invite.js +22 -24
  414. package/dist/models/invite.js.map +1 -1
  415. package/dist/models/line-item-adjustment.d.ts +13 -0
  416. package/dist/models/line-item-adjustment.js +76 -0
  417. package/dist/models/line-item-adjustment.js.map +1 -0
  418. package/dist/models/line-item-tax-line.js +4 -6
  419. package/dist/models/line-item-tax-line.js.map +1 -1
  420. package/dist/models/line-item.d.ts +5 -5
  421. package/dist/models/line-item.js +29 -19
  422. package/dist/models/line-item.js.map +1 -1
  423. package/dist/models/money-amount.d.ts +12 -8
  424. package/dist/models/money-amount.js +47 -30
  425. package/dist/models/money-amount.js.map +1 -1
  426. package/dist/models/note.d.ts +3 -6
  427. package/dist/models/note.js +22 -23
  428. package/dist/models/note.js.map +1 -1
  429. package/dist/models/notification.d.ts +3 -5
  430. package/dist/models/notification.js +22 -19
  431. package/dist/models/notification.js.map +1 -1
  432. package/dist/models/oauth.d.ts +1 -1
  433. package/dist/models/oauth.js +2 -5
  434. package/dist/models/oauth.js.map +1 -1
  435. package/dist/models/order.d.ts +3 -5
  436. package/dist/models/order.js +25 -21
  437. package/dist/models/order.js.map +1 -1
  438. package/dist/models/payment-provider.js.map +1 -1
  439. package/dist/models/payment-session.d.ts +3 -5
  440. package/dist/models/payment-session.js +22 -19
  441. package/dist/models/payment-session.js.map +1 -1
  442. package/dist/models/payment.d.ts +4 -6
  443. package/dist/models/payment.js +22 -19
  444. package/dist/models/payment.js.map +1 -1
  445. package/dist/models/price-list.d.ts +54 -0
  446. package/dist/models/price-list.js +144 -0
  447. package/dist/models/price-list.js.map +1 -0
  448. package/dist/models/product-collection.d.ts +4 -7
  449. package/dist/models/product-collection.js +25 -24
  450. package/dist/models/product-collection.js.map +1 -1
  451. package/dist/models/product-option-value.d.ts +3 -6
  452. package/dist/models/product-option-value.js +24 -26
  453. package/dist/models/product-option-value.js.map +1 -1
  454. package/dist/models/product-option.d.ts +3 -6
  455. package/dist/models/product-option.js +23 -24
  456. package/dist/models/product-option.js.map +1 -1
  457. package/dist/models/product-tag.d.ts +3 -6
  458. package/dist/models/product-tag.js +22 -23
  459. package/dist/models/product-tag.js.map +1 -1
  460. package/dist/models/product-tax-rate.d.ts +1 -1
  461. package/dist/models/product-tax-rate.js.map +1 -1
  462. package/dist/models/product-type-tax-rate.d.ts +1 -1
  463. package/dist/models/product-type-tax-rate.js.map +1 -1
  464. package/dist/models/product-type.d.ts +3 -6
  465. package/dist/models/product-type.js +22 -23
  466. package/dist/models/product-type.js.map +1 -1
  467. package/dist/models/product-variant.d.ts +3 -6
  468. package/dist/models/product-variant.js +30 -26
  469. package/dist/models/product-variant.js.map +1 -1
  470. package/dist/models/product.d.ts +3 -6
  471. package/dist/models/product.js +25 -22
  472. package/dist/models/product.js.map +1 -1
  473. package/dist/models/refund.d.ts +3 -5
  474. package/dist/models/refund.js +22 -17
  475. package/dist/models/refund.js.map +1 -1
  476. package/dist/models/region.d.ts +3 -6
  477. package/dist/models/region.js +23 -24
  478. package/dist/models/region.js.map +1 -1
  479. package/dist/models/return-item.d.ts +1 -1
  480. package/dist/models/return-item.js.map +1 -1
  481. package/dist/models/return-reason.d.ts +3 -6
  482. package/dist/models/return-reason.js +24 -25
  483. package/dist/models/return-reason.js.map +1 -1
  484. package/dist/models/return.d.ts +5 -7
  485. package/dist/models/return.js +29 -21
  486. package/dist/models/return.js.map +1 -1
  487. package/dist/models/shipping-method-tax-line.js +4 -6
  488. package/dist/models/shipping-method-tax-line.js.map +1 -1
  489. package/dist/models/shipping-method.d.ts +2 -2
  490. package/dist/models/shipping-method.js +3 -6
  491. package/dist/models/shipping-method.js.map +1 -1
  492. package/dist/models/shipping-option-requirement.js +2 -5
  493. package/dist/models/shipping-option-requirement.js.map +1 -1
  494. package/dist/models/shipping-option.d.ts +5 -8
  495. package/dist/models/shipping-option.js +26 -25
  496. package/dist/models/shipping-option.js.map +1 -1
  497. package/dist/models/shipping-profile.d.ts +3 -6
  498. package/dist/models/shipping-profile.js +22 -23
  499. package/dist/models/shipping-profile.js.map +1 -1
  500. package/dist/models/shipping-tax-rate.d.ts +1 -1
  501. package/dist/models/shipping-tax-rate.js.map +1 -1
  502. package/dist/models/staged-job.d.ts +1 -1
  503. package/dist/models/staged-job.js +2 -3
  504. package/dist/models/staged-job.js.map +1 -1
  505. package/dist/models/store.d.ts +3 -5
  506. package/dist/models/store.js +22 -17
  507. package/dist/models/store.js.map +1 -1
  508. package/dist/models/swap.d.ts +9 -12
  509. package/dist/models/swap.js +55 -52
  510. package/dist/models/swap.js.map +1 -1
  511. package/dist/models/tax-line.d.ts +3 -5
  512. package/dist/models/tax-line.js +20 -14
  513. package/dist/models/tax-line.js.map +1 -1
  514. package/dist/models/tax-rate.d.ts +3 -5
  515. package/dist/models/tax-rate.js +22 -19
  516. package/dist/models/tax-rate.js.map +1 -1
  517. package/dist/models/tracking-link.d.ts +3 -6
  518. package/dist/models/tracking-link.js +26 -27
  519. package/dist/models/tracking-link.js.map +1 -1
  520. package/dist/models/user.d.ts +3 -6
  521. package/dist/models/user.js +22 -23
  522. package/dist/models/user.js.map +1 -1
  523. package/dist/repositories/batch-job.d.ts +4 -0
  524. package/dist/repositories/batch-job.js +38 -0
  525. package/dist/repositories/batch-job.js.map +1 -0
  526. package/dist/repositories/cart.d.ts +2 -2
  527. package/dist/repositories/cart.js.map +1 -1
  528. package/dist/repositories/customer.d.ts +1 -1
  529. package/dist/repositories/customer.js +7 -9
  530. package/dist/repositories/customer.js.map +1 -1
  531. package/dist/repositories/discount-condition.d.ts +38 -0
  532. package/dist/repositories/discount-condition.js +398 -0
  533. package/dist/repositories/discount-condition.js.map +1 -0
  534. package/dist/repositories/line-item-adjustment.d.ts +4 -0
  535. package/dist/repositories/line-item-adjustment.js +38 -0
  536. package/dist/repositories/line-item-adjustment.js.map +1 -0
  537. package/dist/repositories/line-item-tax-line.d.ts +2 -0
  538. package/dist/repositories/line-item-tax-line.js +80 -0
  539. package/dist/repositories/line-item-tax-line.js.map +1 -1
  540. package/dist/repositories/line-item.js +1 -0
  541. package/dist/repositories/line-item.js.map +1 -1
  542. package/dist/repositories/money-amount.d.ts +8 -2
  543. package/dist/repositories/money-amount.js +177 -2
  544. package/dist/repositories/money-amount.js.map +1 -1
  545. package/dist/repositories/order.d.ts +1 -1
  546. package/dist/repositories/price-list.d.ts +11 -0
  547. package/dist/repositories/price-list.js +247 -0
  548. package/dist/repositories/price-list.js.map +1 -0
  549. package/dist/repositories/product.d.ts +5 -1
  550. package/dist/repositories/product.js +96 -18
  551. package/dist/repositories/product.js.map +1 -1
  552. package/dist/repositories/shipping-method-tax-line.d.ts +2 -0
  553. package/dist/repositories/shipping-method-tax-line.js +80 -0
  554. package/dist/repositories/shipping-method-tax-line.js.map +1 -1
  555. package/dist/scripts/discount-rule-migration.d.ts +4 -0
  556. package/dist/scripts/discount-rule-migration.js +189 -0
  557. package/dist/scripts/discount-rule-migration.js.map +1 -0
  558. package/dist/scripts/line-item-adjustment-migration.d.ts +4 -0
  559. package/dist/scripts/line-item-adjustment-migration.js +173 -0
  560. package/dist/scripts/line-item-adjustment-migration.js.map +1 -0
  561. package/dist/services/batch-job.d.ts +24 -0
  562. package/dist/services/batch-job.js +126 -0
  563. package/dist/services/batch-job.js.map +1 -0
  564. package/dist/services/cart.d.ts +66 -55
  565. package/dist/services/cart.js +1315 -1405
  566. package/dist/services/cart.js.map +1 -1
  567. package/dist/services/claim-item.d.ts +23 -27
  568. package/dist/services/claim-item.js +217 -247
  569. package/dist/services/claim-item.js.map +1 -1
  570. package/dist/services/claim.d.ts +89 -71
  571. package/dist/services/claim.js +915 -840
  572. package/dist/services/claim.js.map +1 -1
  573. package/dist/services/customer.d.ts +0 -7
  574. package/dist/services/customer.js +8 -35
  575. package/dist/services/customer.js.map +1 -1
  576. package/dist/services/discount-condition.d.ts +31 -0
  577. package/dist/services/discount-condition.js +232 -0
  578. package/dist/services/discount-condition.js.map +1 -0
  579. package/dist/services/discount.d.ts +50 -59
  580. package/dist/services/discount.js +274 -176
  581. package/dist/services/discount.js.map +1 -1
  582. package/dist/services/draft-order.d.ts +69 -66
  583. package/dist/services/draft-order.js +375 -352
  584. package/dist/services/draft-order.js.map +1 -1
  585. package/dist/services/event-bus.d.ts +72 -56
  586. package/dist/services/event-bus.js +122 -99
  587. package/dist/services/event-bus.js.map +1 -1
  588. package/dist/services/file.d.ts +14 -0
  589. package/dist/services/file.js +43 -0
  590. package/dist/services/file.js.map +1 -0
  591. package/dist/services/fulfillment-provider.js +23 -17
  592. package/dist/services/fulfillment-provider.js.map +1 -1
  593. package/dist/services/invite.d.ts +4 -2
  594. package/dist/services/invite.js +11 -9
  595. package/dist/services/invite.js.map +1 -1
  596. package/dist/services/line-item-adjustment.d.ts +87 -0
  597. package/dist/services/line-item-adjustment.js +434 -0
  598. package/dist/services/line-item-adjustment.js.map +1 -0
  599. package/dist/services/line-item.d.ts +48 -40
  600. package/dist/services/line-item.js +226 -193
  601. package/dist/services/line-item.js.map +1 -1
  602. package/dist/services/order.d.ts +0 -13
  603. package/dist/services/order.js +4 -30
  604. package/dist/services/order.js.map +1 -1
  605. package/dist/services/payment-provider.js +23 -17
  606. package/dist/services/payment-provider.js.map +1 -1
  607. package/dist/services/price-list.d.ts +107 -0
  608. package/dist/services/price-list.js +740 -0
  609. package/dist/services/price-list.js.map +1 -0
  610. package/dist/services/pricing.d.ts +87 -0
  611. package/dist/services/pricing.js +443 -0
  612. package/dist/services/pricing.js.map +1 -0
  613. package/dist/services/product-tag.d.ts +2 -2
  614. package/dist/services/product-tag.js +15 -2
  615. package/dist/services/product-tag.js.map +1 -1
  616. package/dist/services/product-type.d.ts +1 -1
  617. package/dist/services/product-type.js +14 -1
  618. package/dist/services/product-type.js.map +1 -1
  619. package/dist/services/product-variant.d.ts +40 -16
  620. package/dist/services/product-variant.js +259 -109
  621. package/dist/services/product-variant.js.map +1 -1
  622. package/dist/services/product.d.ts +22 -11
  623. package/dist/services/product.js +251 -87
  624. package/dist/services/product.js.map +1 -1
  625. package/dist/services/region.js +12 -8
  626. package/dist/services/region.js.map +1 -1
  627. package/dist/services/return.js +2 -1
  628. package/dist/services/return.js.map +1 -1
  629. package/dist/services/shipping-option.d.ts +44 -109
  630. package/dist/services/shipping-option.js +309 -353
  631. package/dist/services/shipping-option.js.map +1 -1
  632. package/dist/services/store.d.ts +36 -45
  633. package/dist/services/store.js +207 -217
  634. package/dist/services/store.js.map +1 -1
  635. package/dist/services/swap.d.ts +4 -1
  636. package/dist/services/swap.js +29 -16
  637. package/dist/services/swap.js.map +1 -1
  638. package/dist/services/system-tax.d.ts +2 -3
  639. package/dist/services/system-tax.js +2 -2
  640. package/dist/services/system-tax.js.map +1 -1
  641. package/dist/services/tax-provider.d.ts +2 -0
  642. package/dist/services/tax-provider.js +96 -7
  643. package/dist/services/tax-provider.js.map +1 -1
  644. package/dist/services/tax-rate.d.ts +3 -3
  645. package/dist/services/tax-rate.js +1 -1
  646. package/dist/services/tax-rate.js.map +1 -1
  647. package/dist/services/totals.d.ts +9 -8
  648. package/dist/services/totals.js +41 -88
  649. package/dist/services/totals.js.map +1 -1
  650. package/dist/strategies/cart-completion.js.map +1 -1
  651. package/dist/strategies/price-selection.d.ts +13 -0
  652. package/dist/strategies/price-selection.js +185 -0
  653. package/dist/strategies/price-selection.js.map +1 -0
  654. package/dist/subscribers/order.js +1 -7
  655. package/dist/subscribers/order.js.map +1 -1
  656. package/dist/types/batch-job.d.ts +15 -0
  657. package/dist/types/batch-job.js +63 -0
  658. package/dist/types/batch-job.js.map +1 -0
  659. package/dist/types/cart.d.ts +2 -2
  660. package/dist/types/claim.d.ts +67 -0
  661. package/dist/types/claim.js +3 -0
  662. package/dist/types/claim.js.map +1 -0
  663. package/dist/types/common.d.ts +53 -13
  664. package/dist/types/common.js +1 -0
  665. package/dist/types/common.js.map +1 -1
  666. package/dist/types/discount.d.ts +68 -1
  667. package/dist/types/discount.js +129 -5
  668. package/dist/types/discount.js.map +1 -1
  669. package/dist/types/global.d.ts +53 -0
  670. package/dist/types/global.js +3 -0
  671. package/dist/types/global.js.map +1 -0
  672. package/dist/types/line-item-adjustment.d.ts +9 -0
  673. package/dist/types/line-item-adjustment.js +50 -0
  674. package/dist/types/line-item-adjustment.js.map +1 -0
  675. package/dist/types/note.d.ts +1 -1
  676. package/dist/types/price-list.d.ts +73 -0
  677. package/dist/types/price-list.js +157 -0
  678. package/dist/types/price-list.js.map +1 -0
  679. package/dist/types/price-selection.d.ts +5 -0
  680. package/dist/types/price-selection.js +35 -0
  681. package/dist/types/price-selection.js.map +1 -0
  682. package/dist/types/pricing.d.ts +25 -0
  683. package/dist/types/pricing.js +3 -0
  684. package/dist/types/pricing.js.map +1 -0
  685. package/dist/types/product-variant.d.ts +24 -1
  686. package/dist/types/product-variant.js +65 -1
  687. package/dist/types/product-variant.js.map +1 -1
  688. package/dist/types/product.d.ts +18 -0
  689. package/dist/types/product.js +104 -5
  690. package/dist/types/product.js.map +1 -1
  691. package/dist/types/shipping-options.d.ts +56 -0
  692. package/dist/types/shipping-options.js +3 -0
  693. package/dist/types/shipping-options.js.map +1 -0
  694. package/dist/types/store.d.ts +9 -0
  695. package/dist/types/store.js +3 -0
  696. package/dist/types/store.js.map +1 -0
  697. package/dist/types/tax-service.d.ts +2 -2
  698. package/dist/types/user.d.ts +2 -2
  699. package/dist/types/validators/exactly-one.d.ts +6 -0
  700. package/dist/types/validators/exactly-one.js +37 -0
  701. package/dist/types/validators/exactly-one.js.map +1 -0
  702. package/dist/utils/build-query.d.ts +8 -0
  703. package/dist/utils/build-query.js +114 -0
  704. package/dist/utils/build-query.js.map +1 -0
  705. package/dist/utils/countries.d.ts +3 -2
  706. package/dist/utils/countries.js.map +1 -1
  707. package/dist/utils/currencies.d.ts +10 -1899
  708. package/dist/utils/currencies.js.map +1 -1
  709. package/dist/utils/date-helpers.d.ts +2 -0
  710. package/dist/utils/date-helpers.js +15 -0
  711. package/dist/utils/date-helpers.js.map +1 -0
  712. package/dist/utils/format-registration-name.d.ts +4 -4
  713. package/dist/utils/format-registration-name.js +7 -10
  714. package/dist/utils/format-registration-name.js.map +1 -1
  715. package/dist/utils/generate-entity-id.d.ts +6 -0
  716. package/dist/utils/generate-entity-id.js +19 -0
  717. package/dist/utils/generate-entity-id.js.map +1 -0
  718. package/dist/utils/get-query-config.d.ts +9 -0
  719. package/dist/utils/get-query-config.js +133 -0
  720. package/dist/utils/get-query-config.js.map +1 -0
  721. package/dist/utils/index.d.ts +4 -0
  722. package/dist/utils/index.js +17 -0
  723. package/dist/utils/index.js.map +1 -0
  724. package/dist/utils/set-metadata.d.ts +9 -0
  725. package/dist/utils/set-metadata.js +72 -0
  726. package/dist/utils/set-metadata.js.map +1 -0
  727. package/dist/utils/sleep.d.ts +1 -0
  728. package/dist/utils/sleep.js +50 -0
  729. package/dist/utils/sleep.js.map +1 -0
  730. package/dist/utils/validate-id.d.ts +4 -0
  731. package/dist/utils/validate-id.js +47 -0
  732. package/dist/utils/validate-id.js.map +1 -0
  733. package/jest.config.js +6 -0
  734. package/package.json +11 -9
  735. package/tsconfig.spec.json +10 -0
  736. package/yarn-error.log +23292 -1023
@@ -0,0 +1,740 @@
1
+ "use strict";
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ if (typeof b !== "function" && b !== null)
11
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
+ extendStatics(d, b);
13
+ function __() { this.constructor = d; }
14
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
+ };
16
+ })();
17
+ var __assign = (this && this.__assign) || function () {
18
+ __assign = Object.assign || function(t) {
19
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
20
+ s = arguments[i];
21
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
22
+ t[p] = s[p];
23
+ }
24
+ return t;
25
+ };
26
+ return __assign.apply(this, arguments);
27
+ };
28
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
29
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
30
+ return new (P || (P = Promise))(function (resolve, reject) {
31
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
32
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
33
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
34
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
35
+ });
36
+ };
37
+ var __generator = (this && this.__generator) || function (thisArg, body) {
38
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
39
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
40
+ function verb(n) { return function (v) { return step([n, v]); }; }
41
+ function step(op) {
42
+ if (f) throw new TypeError("Generator is already executing.");
43
+ while (_) try {
44
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
45
+ if (y = 0, t) op = [op[0] & 2, t.value];
46
+ switch (op[0]) {
47
+ case 0: case 1: t = op; break;
48
+ case 4: _.label++; return { value: op[1], done: false };
49
+ case 5: _.label++; y = op[1]; op = [0]; continue;
50
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
51
+ default:
52
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
53
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
54
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
55
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
56
+ if (t[2]) _.ops.pop();
57
+ _.trys.pop(); continue;
58
+ }
59
+ op = body.call(thisArg, _);
60
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
61
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
62
+ }
63
+ };
64
+ var __rest = (this && this.__rest) || function (s, e) {
65
+ var t = {};
66
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
67
+ t[p] = s[p];
68
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
69
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
70
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
71
+ t[p[i]] = s[p[i]];
72
+ }
73
+ return t;
74
+ };
75
+ var __values = (this && this.__values) || function(o) {
76
+ var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
77
+ if (m) return m.call(o);
78
+ if (o && typeof o.length === "number") return {
79
+ next: function () {
80
+ if (o && i >= o.length) o = void 0;
81
+ return { value: o && o[i++], done: !o };
82
+ }
83
+ };
84
+ throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
85
+ };
86
+ var __read = (this && this.__read) || function (o, n) {
87
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
88
+ if (!m) return o;
89
+ var i = m.call(o), r, ar = [], e;
90
+ try {
91
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
92
+ }
93
+ catch (error) { e = { error: error }; }
94
+ finally {
95
+ try {
96
+ if (r && !r.done && (m = i["return"])) m.call(i);
97
+ }
98
+ finally { if (e) throw e.error; }
99
+ }
100
+ return ar;
101
+ };
102
+ Object.defineProperty(exports, "__esModule", { value: true });
103
+ var medusa_core_utils_1 = require("medusa-core-utils");
104
+ var exception_formatter_1 = require("../utils/exception-formatter");
105
+ var interfaces_1 = require("../interfaces");
106
+ var utils_1 = require("../utils");
107
+ /**
108
+ * Provides layer to manipulate product tags.
109
+ * @extends BaseService
110
+ */
111
+ var PriceListService = /** @class */ (function (_super) {
112
+ __extends(PriceListService, _super);
113
+ function PriceListService(_a) {
114
+ var manager = _a.manager, customerGroupService = _a.customerGroupService, regionService = _a.regionService, productService = _a.productService, productVariantService = _a.productVariantService, priceListRepository = _a.priceListRepository, moneyAmountRepository = _a.moneyAmountRepository;
115
+ var _this =
116
+ // eslint-disable-next-line prefer-rest-params
117
+ _super.call(this, arguments[0]) || this;
118
+ _this.manager_ = manager;
119
+ _this.customerGroupService_ = customerGroupService;
120
+ _this.productService_ = productService;
121
+ _this.variantService_ = productVariantService;
122
+ _this.regionService_ = regionService;
123
+ _this.priceListRepo_ = priceListRepository;
124
+ _this.moneyAmountRepo_ = moneyAmountRepository;
125
+ return _this;
126
+ }
127
+ /**
128
+ * Retrieves a product tag by id.
129
+ * @param {string} priceListId - the id of the product tag to retrieve
130
+ * @param {Object} config - the config to retrieve the tag by
131
+ * @return {Promise<PriceList>} the collection.
132
+ */
133
+ PriceListService.prototype.retrieve = function (priceListId, config) {
134
+ if (config === void 0) { config = {}; }
135
+ return __awaiter(this, void 0, void 0, function () {
136
+ var priceListRepo, query, priceList;
137
+ return __generator(this, function (_a) {
138
+ switch (_a.label) {
139
+ case 0:
140
+ priceListRepo = this.manager_.getCustomRepository(this.priceListRepo_);
141
+ query = (0, utils_1.buildQuery)({ id: priceListId }, config);
142
+ return [4 /*yield*/, priceListRepo.findOne(query)];
143
+ case 1:
144
+ priceList = _a.sent();
145
+ if (!priceList) {
146
+ throw new medusa_core_utils_1.MedusaError(medusa_core_utils_1.MedusaError.Types.NOT_FOUND, "Price list with id: ".concat(priceListId, " was not found"));
147
+ }
148
+ return [2 /*return*/, priceList];
149
+ }
150
+ });
151
+ });
152
+ };
153
+ /**
154
+ * Creates a Price List
155
+ * @param {CreatePriceListInput} priceListObject - the Price List to create
156
+ * @return {Promise<PriceList>} created Price List
157
+ */
158
+ PriceListService.prototype.create = function (priceListObject) {
159
+ return __awaiter(this, void 0, void 0, function () {
160
+ var _this = this;
161
+ return __generator(this, function (_a) {
162
+ switch (_a.label) {
163
+ case 0: return [4 /*yield*/, this.atomicPhase_(function (manager) { return __awaiter(_this, void 0, void 0, function () {
164
+ var priceListRepo, moneyAmountRepo, prices, customer_groups, rest, entity, priceList, result, error_1;
165
+ return __generator(this, function (_a) {
166
+ switch (_a.label) {
167
+ case 0:
168
+ priceListRepo = manager.getCustomRepository(this.priceListRepo_);
169
+ moneyAmountRepo = manager.getCustomRepository(this.moneyAmountRepo_);
170
+ prices = priceListObject.prices, customer_groups = priceListObject.customer_groups, rest = __rest(priceListObject, ["prices", "customer_groups"]);
171
+ _a.label = 1;
172
+ case 1:
173
+ _a.trys.push([1, 8, , 9]);
174
+ entity = priceListRepo.create(rest);
175
+ return [4 /*yield*/, priceListRepo.save(entity)];
176
+ case 2:
177
+ priceList = _a.sent();
178
+ if (!prices) return [3 /*break*/, 4];
179
+ return [4 /*yield*/, moneyAmountRepo.addPriceListPrices(priceList.id, prices)];
180
+ case 3:
181
+ _a.sent();
182
+ _a.label = 4;
183
+ case 4:
184
+ if (!customer_groups) return [3 /*break*/, 6];
185
+ return [4 /*yield*/, this.upsertCustomerGroups_(priceList.id, customer_groups)];
186
+ case 5:
187
+ _a.sent();
188
+ _a.label = 6;
189
+ case 6: return [4 /*yield*/, this.retrieve(priceList.id, {
190
+ relations: ["prices", "customer_groups"],
191
+ })];
192
+ case 7:
193
+ result = _a.sent();
194
+ return [2 /*return*/, result];
195
+ case 8:
196
+ error_1 = _a.sent();
197
+ throw (0, exception_formatter_1.formatException)(error_1);
198
+ case 9: return [2 /*return*/];
199
+ }
200
+ });
201
+ }); })];
202
+ case 1: return [2 /*return*/, _a.sent()];
203
+ }
204
+ });
205
+ });
206
+ };
207
+ /**
208
+ * Updates a Price List
209
+ * @param {string} id - the id of the Product List to update
210
+ * @param {UpdatePriceListInput} update - the update to apply
211
+ * @returns {Promise<PriceList>} updated Price List
212
+ */
213
+ PriceListService.prototype.update = function (id, update) {
214
+ return __awaiter(this, void 0, void 0, function () {
215
+ var _this = this;
216
+ return __generator(this, function (_a) {
217
+ switch (_a.label) {
218
+ case 0: return [4 /*yield*/, this.atomicPhase_(function (manager) { return __awaiter(_this, void 0, void 0, function () {
219
+ var priceListRepo, moneyAmountRepo, priceList, prices, customer_groups, rest, prices_, _a, _b, _c, key, value;
220
+ var e_1, _d;
221
+ return __generator(this, function (_e) {
222
+ switch (_e.label) {
223
+ case 0:
224
+ priceListRepo = manager.getCustomRepository(this.priceListRepo_);
225
+ moneyAmountRepo = manager.getCustomRepository(this.moneyAmountRepo_);
226
+ return [4 /*yield*/, this.retrieve(id, { select: ["id"] })];
227
+ case 1:
228
+ priceList = _e.sent();
229
+ prices = update.prices, customer_groups = update.customer_groups, rest = __rest(update, ["prices", "customer_groups"]);
230
+ if (!prices) return [3 /*break*/, 4];
231
+ return [4 /*yield*/, this.addCurrencyFromRegion(prices)];
232
+ case 2:
233
+ prices_ = _e.sent();
234
+ return [4 /*yield*/, moneyAmountRepo.updatePriceListPrices(id, prices_)];
235
+ case 3:
236
+ _e.sent();
237
+ _e.label = 4;
238
+ case 4:
239
+ if (!customer_groups) return [3 /*break*/, 6];
240
+ return [4 /*yield*/, this.upsertCustomerGroups_(id, customer_groups)];
241
+ case 5:
242
+ _e.sent();
243
+ _e.label = 6;
244
+ case 6:
245
+ try {
246
+ for (_a = __values(Object.entries(rest)), _b = _a.next(); !_b.done; _b = _a.next()) {
247
+ _c = __read(_b.value, 2), key = _c[0], value = _c[1];
248
+ if (typeof value === "undefined") {
249
+ continue;
250
+ }
251
+ priceList[key] = value;
252
+ }
253
+ }
254
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
255
+ finally {
256
+ try {
257
+ if (_b && !_b.done && (_d = _a.return)) _d.call(_a);
258
+ }
259
+ finally { if (e_1) throw e_1.error; }
260
+ }
261
+ return [4 /*yield*/, priceListRepo.save(priceList)];
262
+ case 7:
263
+ _e.sent();
264
+ return [4 /*yield*/, this.retrieve(id, {
265
+ relations: ["prices", "customer_groups"],
266
+ })];
267
+ case 8: return [2 /*return*/, _e.sent()];
268
+ }
269
+ });
270
+ }); })];
271
+ case 1: return [2 /*return*/, _a.sent()];
272
+ }
273
+ });
274
+ });
275
+ };
276
+ /**
277
+ * Adds prices to a price list in bulk, optionally replacing all existing prices
278
+ * @param id - id of the price list
279
+ * @param prices - prices to add
280
+ * @param replace - whether to replace existing prices
281
+ * @returns {Promise<PriceList>} updated Price List
282
+ */
283
+ PriceListService.prototype.addPrices = function (id, prices, replace) {
284
+ if (replace === void 0) { replace = false; }
285
+ return __awaiter(this, void 0, void 0, function () {
286
+ var _this = this;
287
+ return __generator(this, function (_a) {
288
+ switch (_a.label) {
289
+ case 0: return [4 /*yield*/, this.atomicPhase_(function (manager) { return __awaiter(_this, void 0, void 0, function () {
290
+ var moneyAmountRepo, priceList, prices_;
291
+ return __generator(this, function (_a) {
292
+ switch (_a.label) {
293
+ case 0:
294
+ moneyAmountRepo = manager.getCustomRepository(this.moneyAmountRepo_);
295
+ return [4 /*yield*/, this.retrieve(id, { select: ["id"] })];
296
+ case 1:
297
+ priceList = _a.sent();
298
+ return [4 /*yield*/, this.addCurrencyFromRegion(prices)];
299
+ case 2:
300
+ prices_ = _a.sent();
301
+ return [4 /*yield*/, moneyAmountRepo.addPriceListPrices(priceList.id, prices_, replace)];
302
+ case 3:
303
+ _a.sent();
304
+ return [4 /*yield*/, this.retrieve(priceList.id, {
305
+ relations: ["prices"],
306
+ })];
307
+ case 4: return [2 /*return*/, _a.sent()];
308
+ }
309
+ });
310
+ }); })];
311
+ case 1: return [2 /*return*/, _a.sent()];
312
+ }
313
+ });
314
+ });
315
+ };
316
+ /**
317
+ * Removes prices from a price list and deletes the removed prices in bulk
318
+ * @param id - id of the price list
319
+ * @param priceIds - ids of the prices to delete
320
+ * @returns {Promise<void>} updated Price List
321
+ */
322
+ PriceListService.prototype.deletePrices = function (id, priceIds) {
323
+ return __awaiter(this, void 0, void 0, function () {
324
+ var _this = this;
325
+ return __generator(this, function (_a) {
326
+ switch (_a.label) {
327
+ case 0: return [4 /*yield*/, this.atomicPhase_(function (manager) { return __awaiter(_this, void 0, void 0, function () {
328
+ var moneyAmountRepo, priceList;
329
+ return __generator(this, function (_a) {
330
+ switch (_a.label) {
331
+ case 0:
332
+ moneyAmountRepo = manager.getCustomRepository(this.moneyAmountRepo_);
333
+ return [4 /*yield*/, this.retrieve(id, { select: ["id"] })];
334
+ case 1:
335
+ priceList = _a.sent();
336
+ return [4 /*yield*/, moneyAmountRepo.deletePriceListPrices(priceList.id, priceIds)];
337
+ case 2:
338
+ _a.sent();
339
+ return [2 /*return*/];
340
+ }
341
+ });
342
+ }); })];
343
+ case 1: return [2 /*return*/, _a.sent()];
344
+ }
345
+ });
346
+ });
347
+ };
348
+ /**
349
+ * Deletes a Price List
350
+ * Will never fail due to delete being idempotent.
351
+ * @param id - id of the price list
352
+ * @returns {Promise<void>} empty promise
353
+ */
354
+ PriceListService.prototype.delete = function (id) {
355
+ return __awaiter(this, void 0, void 0, function () {
356
+ var _this = this;
357
+ return __generator(this, function (_a) {
358
+ switch (_a.label) {
359
+ case 0: return [4 /*yield*/, this.atomicPhase_(function (manager) { return __awaiter(_this, void 0, void 0, function () {
360
+ var priceListRepo, priceList;
361
+ return __generator(this, function (_a) {
362
+ switch (_a.label) {
363
+ case 0:
364
+ priceListRepo = manager.getCustomRepository(this.priceListRepo_);
365
+ return [4 /*yield*/, priceListRepo.findOne({ where: { id: id } })];
366
+ case 1:
367
+ priceList = _a.sent();
368
+ if (!priceList) {
369
+ return [2 /*return*/, Promise.resolve()];
370
+ }
371
+ return [4 /*yield*/, priceListRepo.remove(priceList)];
372
+ case 2:
373
+ _a.sent();
374
+ return [2 /*return*/];
375
+ }
376
+ });
377
+ }); })];
378
+ case 1: return [2 /*return*/, _a.sent()];
379
+ }
380
+ });
381
+ });
382
+ };
383
+ /**
384
+ * Lists Price Lists
385
+ * @param {Object} selector - the query object for find
386
+ * @param {Object} config - the config to be used for find
387
+ * @return {Promise<PriceList[]>} the result of the find operation
388
+ */
389
+ PriceListService.prototype.list = function (selector, config) {
390
+ if (selector === void 0) { selector = {}; }
391
+ if (config === void 0) { config = { skip: 0, take: 20 }; }
392
+ return __awaiter(this, void 0, void 0, function () {
393
+ var _this = this;
394
+ return __generator(this, function (_a) {
395
+ switch (_a.label) {
396
+ case 0: return [4 /*yield*/, this.atomicPhase_(function (manager) { return __awaiter(_this, void 0, void 0, function () {
397
+ var priceListRepo, q, priceListSelector, query, groups, _a, priceLists;
398
+ return __generator(this, function (_b) {
399
+ switch (_b.label) {
400
+ case 0:
401
+ priceListRepo = manager.getCustomRepository(this.priceListRepo_);
402
+ q = selector.q, priceListSelector = __rest(selector, ["q"]);
403
+ query = (0, utils_1.buildQuery)(priceListSelector, config);
404
+ groups = query.where.customer_groups;
405
+ query.where.customer_groups = undefined;
406
+ return [4 /*yield*/, priceListRepo.listAndCount(query, groups)];
407
+ case 1:
408
+ _a = __read.apply(void 0, [_b.sent(), 1]), priceLists = _a[0];
409
+ return [2 /*return*/, priceLists];
410
+ }
411
+ });
412
+ }); })];
413
+ case 1: return [2 /*return*/, _a.sent()];
414
+ }
415
+ });
416
+ });
417
+ };
418
+ /**
419
+ * Lists Price Lists and adds count
420
+ * @param {Object} selector - the query object for find
421
+ * @param {Object} config - the config to be used for find
422
+ * @return {Promise} the result of the find operation
423
+ */
424
+ PriceListService.prototype.listAndCount = function (selector, config) {
425
+ if (selector === void 0) { selector = {}; }
426
+ if (config === void 0) { config = {
427
+ skip: 0,
428
+ take: 20,
429
+ }; }
430
+ return __awaiter(this, void 0, void 0, function () {
431
+ var _this = this;
432
+ return __generator(this, function (_a) {
433
+ switch (_a.label) {
434
+ case 0: return [4 /*yield*/, this.atomicPhase_(function (manager) { return __awaiter(_this, void 0, void 0, function () {
435
+ var priceListRepo, q, priceListSelector, _a, relations, query, groups;
436
+ return __generator(this, function (_b) {
437
+ switch (_b.label) {
438
+ case 0:
439
+ priceListRepo = manager.getCustomRepository(this.priceListRepo_);
440
+ q = selector.q, priceListSelector = __rest(selector, ["q"]);
441
+ _a = (0, utils_1.buildQuery)(priceListSelector, config), relations = _a.relations, query = __rest(_a, ["relations"]);
442
+ groups = query.where.customer_groups;
443
+ delete query.where.customer_groups;
444
+ if (!q) return [3 /*break*/, 2];
445
+ return [4 /*yield*/, priceListRepo.getFreeTextSearchResultsAndCount(q, query, groups, relations)];
446
+ case 1: return [2 /*return*/, _b.sent()];
447
+ case 2: return [4 /*yield*/, priceListRepo.listAndCount(__assign(__assign({}, query), { relations: relations }), groups)];
448
+ case 3: return [2 /*return*/, _b.sent()];
449
+ }
450
+ });
451
+ }); })];
452
+ case 1: return [2 /*return*/, _a.sent()];
453
+ }
454
+ });
455
+ });
456
+ };
457
+ PriceListService.prototype.upsertCustomerGroups_ = function (priceListId, customerGroups) {
458
+ return __awaiter(this, void 0, void 0, function () {
459
+ var priceListRepo, priceList, groups, customerGroups_1, customerGroups_1_1, cg, customerGroup, e_2_1;
460
+ var e_2, _a;
461
+ return __generator(this, function (_b) {
462
+ switch (_b.label) {
463
+ case 0:
464
+ priceListRepo = this.manager_.getCustomRepository(this.priceListRepo_);
465
+ return [4 /*yield*/, this.retrieve(priceListId, { select: ["id"] })];
466
+ case 1:
467
+ priceList = _b.sent();
468
+ groups = [];
469
+ _b.label = 2;
470
+ case 2:
471
+ _b.trys.push([2, 7, 8, 9]);
472
+ customerGroups_1 = __values(customerGroups), customerGroups_1_1 = customerGroups_1.next();
473
+ _b.label = 3;
474
+ case 3:
475
+ if (!!customerGroups_1_1.done) return [3 /*break*/, 6];
476
+ cg = customerGroups_1_1.value;
477
+ return [4 /*yield*/, this.customerGroupService_.retrieve(cg.id)];
478
+ case 4:
479
+ customerGroup = _b.sent();
480
+ groups.push(customerGroup);
481
+ _b.label = 5;
482
+ case 5:
483
+ customerGroups_1_1 = customerGroups_1.next();
484
+ return [3 /*break*/, 3];
485
+ case 6: return [3 /*break*/, 9];
486
+ case 7:
487
+ e_2_1 = _b.sent();
488
+ e_2 = { error: e_2_1 };
489
+ return [3 /*break*/, 9];
490
+ case 8:
491
+ try {
492
+ if (customerGroups_1_1 && !customerGroups_1_1.done && (_a = customerGroups_1.return)) _a.call(customerGroups_1);
493
+ }
494
+ finally { if (e_2) throw e_2.error; }
495
+ return [7 /*endfinally*/];
496
+ case 9:
497
+ priceList.customer_groups = groups;
498
+ return [4 /*yield*/, priceListRepo.save(priceList)];
499
+ case 10:
500
+ _b.sent();
501
+ return [2 /*return*/];
502
+ }
503
+ });
504
+ });
505
+ };
506
+ PriceListService.prototype.listProducts = function (priceListId, selector, config, requiresPriceList) {
507
+ if (selector === void 0) { selector = {}; }
508
+ if (config === void 0) { config = {
509
+ relations: [],
510
+ skip: 0,
511
+ take: 20,
512
+ }; }
513
+ if (requiresPriceList === void 0) { requiresPriceList = false; }
514
+ return __awaiter(this, void 0, void 0, function () {
515
+ var _this = this;
516
+ return __generator(this, function (_a) {
517
+ switch (_a.label) {
518
+ case 0: return [4 /*yield*/, this.atomicPhase_(function (manager) { return __awaiter(_this, void 0, void 0, function () {
519
+ var _a, products, count, moneyAmountRepo, productsWithPrices;
520
+ var _this = this;
521
+ return __generator(this, function (_b) {
522
+ switch (_b.label) {
523
+ case 0: return [4 /*yield*/, this.productService_.listAndCount(selector, config)];
524
+ case 1:
525
+ _a = __read.apply(void 0, [_b.sent(), 2]), products = _a[0], count = _a[1];
526
+ moneyAmountRepo = manager.getCustomRepository(this.moneyAmountRepo_);
527
+ return [4 /*yield*/, Promise.all(products.map(function (p) { return __awaiter(_this, void 0, void 0, function () {
528
+ var _a;
529
+ var _this = this;
530
+ var _b;
531
+ return __generator(this, function (_c) {
532
+ switch (_c.label) {
533
+ case 0:
534
+ if (!((_b = p.variants) === null || _b === void 0 ? void 0 : _b.length)) return [3 /*break*/, 2];
535
+ _a = p;
536
+ return [4 /*yield*/, Promise.all(p.variants.map(function (v) { return __awaiter(_this, void 0, void 0, function () {
537
+ var _a, prices;
538
+ return __generator(this, function (_b) {
539
+ switch (_b.label) {
540
+ case 0: return [4 /*yield*/, moneyAmountRepo.findManyForVariantInPriceList(v.id, priceListId, requiresPriceList)];
541
+ case 1:
542
+ _a = __read.apply(void 0, [_b.sent(), 1]), prices = _a[0];
543
+ return [2 /*return*/, __assign(__assign({}, v), { prices: prices })];
544
+ }
545
+ });
546
+ }); }))];
547
+ case 1:
548
+ _a.variants = _c.sent();
549
+ _c.label = 2;
550
+ case 2: return [2 /*return*/, p];
551
+ }
552
+ });
553
+ }); }))];
554
+ case 2:
555
+ productsWithPrices = _b.sent();
556
+ return [2 /*return*/, [productsWithPrices, count]];
557
+ }
558
+ });
559
+ }); })];
560
+ case 1: return [2 /*return*/, _a.sent()];
561
+ }
562
+ });
563
+ });
564
+ };
565
+ PriceListService.prototype.listVariants = function (priceListId, selector, config, requiresPriceList) {
566
+ if (selector === void 0) { selector = {}; }
567
+ if (config === void 0) { config = {
568
+ relations: [],
569
+ skip: 0,
570
+ take: 20,
571
+ }; }
572
+ if (requiresPriceList === void 0) { requiresPriceList = false; }
573
+ return __awaiter(this, void 0, void 0, function () {
574
+ var _this = this;
575
+ return __generator(this, function (_a) {
576
+ switch (_a.label) {
577
+ case 0: return [4 /*yield*/, this.atomicPhase_(function (manager) { return __awaiter(_this, void 0, void 0, function () {
578
+ var _a, variants, count, moneyAmountRepo, variantsWithPrices;
579
+ var _this = this;
580
+ return __generator(this, function (_b) {
581
+ switch (_b.label) {
582
+ case 0: return [4 /*yield*/, this.variantService_.listAndCount(selector, config)];
583
+ case 1:
584
+ _a = __read.apply(void 0, [_b.sent(), 2]), variants = _a[0], count = _a[1];
585
+ moneyAmountRepo = manager.getCustomRepository(this.moneyAmountRepo_);
586
+ return [4 /*yield*/, Promise.all(variants.map(function (variant) { return __awaiter(_this, void 0, void 0, function () {
587
+ var _a, prices;
588
+ return __generator(this, function (_b) {
589
+ switch (_b.label) {
590
+ case 0: return [4 /*yield*/, moneyAmountRepo.findManyForVariantInPriceList(variant.id, priceListId, requiresPriceList)];
591
+ case 1:
592
+ _a = __read.apply(void 0, [_b.sent(), 1]), prices = _a[0];
593
+ variant.prices = prices;
594
+ return [2 /*return*/, variant];
595
+ }
596
+ });
597
+ }); }))];
598
+ case 2:
599
+ variantsWithPrices = _b.sent();
600
+ return [2 /*return*/, [variantsWithPrices, count]];
601
+ }
602
+ });
603
+ }); })];
604
+ case 1: return [2 /*return*/, _a.sent()];
605
+ }
606
+ });
607
+ });
608
+ };
609
+ PriceListService.prototype.deleteProductPrices = function (priceListId, productIds) {
610
+ return __awaiter(this, void 0, void 0, function () {
611
+ var _this = this;
612
+ return __generator(this, function (_a) {
613
+ switch (_a.label) {
614
+ case 0: return [4 /*yield*/, this.atomicPhase_(function () { return __awaiter(_this, void 0, void 0, function () {
615
+ var _a, products, count, priceIds;
616
+ return __generator(this, function (_b) {
617
+ switch (_b.label) {
618
+ case 0: return [4 /*yield*/, this.listProducts(priceListId, {
619
+ id: productIds,
620
+ }, {
621
+ relations: ["variants"],
622
+ }, true)];
623
+ case 1:
624
+ _a = __read.apply(void 0, [_b.sent(), 2]), products = _a[0], count = _a[1];
625
+ if (count === 0) {
626
+ return [2 /*return*/, [[], count]];
627
+ }
628
+ priceIds = products
629
+ .map(function (_a) {
630
+ var variants = _a.variants;
631
+ return variants
632
+ .map(function (variant) { return variant.prices.map(function (price) { return price.id; }); })
633
+ .flat();
634
+ })
635
+ .flat();
636
+ if (!priceIds.length) {
637
+ return [2 /*return*/, [[], 0]];
638
+ }
639
+ return [4 /*yield*/, this.deletePrices(priceListId, priceIds)];
640
+ case 2:
641
+ _b.sent();
642
+ return [2 /*return*/, [priceIds, priceIds.length]];
643
+ }
644
+ });
645
+ }); })];
646
+ case 1: return [2 /*return*/, _a.sent()];
647
+ }
648
+ });
649
+ });
650
+ };
651
+ PriceListService.prototype.deleteVariantPrices = function (priceListId, variantIds) {
652
+ return __awaiter(this, void 0, void 0, function () {
653
+ var _this = this;
654
+ return __generator(this, function (_a) {
655
+ switch (_a.label) {
656
+ case 0: return [4 /*yield*/, this.atomicPhase_(function () { return __awaiter(_this, void 0, void 0, function () {
657
+ var _a, variants, count, priceIds;
658
+ return __generator(this, function (_b) {
659
+ switch (_b.label) {
660
+ case 0: return [4 /*yield*/, this.listVariants(priceListId, {
661
+ id: variantIds,
662
+ }, {}, true)];
663
+ case 1:
664
+ _a = __read.apply(void 0, [_b.sent(), 2]), variants = _a[0], count = _a[1];
665
+ if (count === 0) {
666
+ return [2 /*return*/, [[], count]];
667
+ }
668
+ priceIds = variants
669
+ .map(function (variant) { return variant.prices.map(function (price) { return price.id; }); })
670
+ .flat();
671
+ if (!priceIds.length) {
672
+ return [2 /*return*/, [[], 0]];
673
+ }
674
+ return [4 /*yield*/, this.deletePrices(priceListId, priceIds)];
675
+ case 2:
676
+ _b.sent();
677
+ return [2 /*return*/, [priceIds, priceIds.length]];
678
+ }
679
+ });
680
+ }); })];
681
+ case 1: return [2 /*return*/, _a.sent()];
682
+ }
683
+ });
684
+ });
685
+ };
686
+ /**
687
+ * Add `currency_code` to an MA record if `region_id`is passed.
688
+ * @param prices - a list of PriceListPrice(Create/Update)Input records
689
+ * @return {Promise} updated `prices` list
690
+ */
691
+ PriceListService.prototype.addCurrencyFromRegion = function (prices) {
692
+ return __awaiter(this, void 0, void 0, function () {
693
+ var prices_, prices_1, prices_1_1, p, region, e_3_1;
694
+ var e_3, _a;
695
+ return __generator(this, function (_b) {
696
+ switch (_b.label) {
697
+ case 0:
698
+ prices_ = [];
699
+ _b.label = 1;
700
+ case 1:
701
+ _b.trys.push([1, 7, 8, 9]);
702
+ prices_1 = __values(prices), prices_1_1 = prices_1.next();
703
+ _b.label = 2;
704
+ case 2:
705
+ if (!!prices_1_1.done) return [3 /*break*/, 6];
706
+ p = prices_1_1.value;
707
+ if (!p.region_id) return [3 /*break*/, 4];
708
+ return [4 /*yield*/, this.regionService_
709
+ .withTransaction(this.manager_)
710
+ .retrieve(p.region_id)];
711
+ case 3:
712
+ region = _b.sent();
713
+ p.currency_code = region.currency_code;
714
+ _b.label = 4;
715
+ case 4:
716
+ prices_.push(p);
717
+ _b.label = 5;
718
+ case 5:
719
+ prices_1_1 = prices_1.next();
720
+ return [3 /*break*/, 2];
721
+ case 6: return [3 /*break*/, 9];
722
+ case 7:
723
+ e_3_1 = _b.sent();
724
+ e_3 = { error: e_3_1 };
725
+ return [3 /*break*/, 9];
726
+ case 8:
727
+ try {
728
+ if (prices_1_1 && !prices_1_1.done && (_a = prices_1.return)) _a.call(prices_1);
729
+ }
730
+ finally { if (e_3) throw e_3.error; }
731
+ return [7 /*endfinally*/];
732
+ case 9: return [2 /*return*/, prices_];
733
+ }
734
+ });
735
+ });
736
+ };
737
+ return PriceListService;
738
+ }(interfaces_1.TransactionBaseService));
739
+ exports.default = PriceListService;
740
+ //# sourceMappingURL=price-list.js.map