@medusajs/medusa 1.2.2-dev.56 → 1.3.1-alpha.72

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 (627) 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/batch-job/can-access-batch-job.d.ts +1 -0
  6. package/dist/api/{routes/admin/discounts/add-valid-product.js → middlewares/batch-job/can-access-batch-job.js} +31 -43
  7. package/dist/api/middlewares/batch-job/can-access-batch-job.js.map +1 -0
  8. package/dist/api/middlewares/batch-job/get-requested-batch-job.d.ts +1 -0
  9. package/dist/api/{routes/admin/products/get-variants.js → middlewares/batch-job/get-requested-batch-job.js} +28 -37
  10. package/dist/api/middlewares/batch-job/get-requested-batch-job.js.map +1 -0
  11. package/dist/api/middlewares/error-handler.js +1 -1
  12. package/dist/api/middlewares/index.d.ts +2 -0
  13. package/dist/api/middlewares/index.js +5 -0
  14. package/dist/api/middlewares/index.js.map +1 -1
  15. package/dist/api/routes/admin/auth/create-session.js +5 -5
  16. package/dist/api/routes/admin/auth/create-session.js.map +1 -1
  17. package/dist/api/routes/admin/batch/index.d.ts +13 -0
  18. package/dist/api/routes/admin/batch/index.js +37 -0
  19. package/dist/api/routes/admin/batch/index.js.map +1 -0
  20. package/dist/api/routes/admin/batch/list-batch-jobs.d.ts +47 -0
  21. package/dist/api/routes/admin/batch/list-batch-jobs.js +245 -0
  22. package/dist/api/routes/admin/batch/list-batch-jobs.js.map +1 -0
  23. package/dist/api/routes/admin/customer-groups/list-customer-groups.js +2 -2
  24. package/dist/api/routes/admin/customer-groups/list-customer-groups.js.map +1 -1
  25. package/dist/api/routes/admin/discounts/create-condition.d.ts +58 -0
  26. package/dist/api/routes/admin/discounts/create-condition.js +186 -0
  27. package/dist/api/routes/admin/discounts/create-condition.js.map +1 -0
  28. package/dist/api/routes/admin/discounts/create-discount.d.ts +14 -4
  29. package/dist/api/routes/admin/discounts/create-discount.js +72 -16
  30. package/dist/api/routes/admin/discounts/create-discount.js.map +1 -1
  31. package/dist/api/routes/admin/discounts/create-dynamic-code.d.ts +1 -0
  32. package/dist/api/routes/admin/discounts/create-dynamic-code.js +4 -1
  33. package/dist/api/routes/admin/discounts/create-dynamic-code.js.map +1 -1
  34. package/dist/api/routes/admin/discounts/delete-condition.d.ts +36 -0
  35. package/dist/api/routes/admin/discounts/delete-condition.js +151 -0
  36. package/dist/api/routes/admin/discounts/delete-condition.js.map +1 -0
  37. package/dist/api/routes/admin/discounts/delete-dynamic-code.js +3 -1
  38. package/dist/api/routes/admin/discounts/delete-dynamic-code.js.map +1 -1
  39. package/dist/api/routes/admin/discounts/get-condition.d.ts +31 -0
  40. package/dist/api/routes/{store/carts/update-payment-method.js → admin/discounts/get-condition.js} +48 -45
  41. package/dist/api/routes/admin/discounts/get-condition.js.map +1 -0
  42. package/dist/api/routes/admin/discounts/get-discount-by-code.d.ts +4 -0
  43. package/dist/api/routes/admin/discounts/get-discount-by-code.js +40 -6
  44. package/dist/api/routes/admin/discounts/get-discount-by-code.js.map +1 -1
  45. package/dist/api/routes/admin/discounts/get-discount.d.ts +7 -0
  46. package/dist/api/routes/admin/discounts/get-discount.js +43 -9
  47. package/dist/api/routes/admin/discounts/get-discount.js.map +1 -1
  48. package/dist/api/routes/admin/discounts/index.d.ts +11 -3
  49. package/dist/api/routes/admin/discounts/index.js +13 -7
  50. package/dist/api/routes/admin/discounts/index.js.map +1 -1
  51. package/dist/api/routes/admin/discounts/list-discounts.d.ts +2 -6
  52. package/dist/api/routes/admin/discounts/list-discounts.js +15 -28
  53. package/dist/api/routes/admin/discounts/list-discounts.js.map +1 -1
  54. package/dist/api/routes/admin/discounts/update-condition.d.ts +55 -0
  55. package/dist/api/routes/admin/discounts/update-condition.js +184 -0
  56. package/dist/api/routes/admin/discounts/update-condition.js.map +1 -0
  57. package/dist/api/routes/admin/discounts/update-discount.d.ts +18 -12
  58. package/dist/api/routes/admin/discounts/update-discount.js +79 -33
  59. package/dist/api/routes/admin/discounts/update-discount.js.map +1 -1
  60. package/dist/api/routes/admin/draft-orders/create-draft-order.d.ts +3 -3
  61. package/dist/api/routes/admin/draft-orders/create-draft-order.js.map +1 -1
  62. package/dist/api/routes/admin/draft-orders/create-line-item.d.ts +1 -1
  63. package/dist/api/routes/admin/draft-orders/create-line-item.js.map +1 -1
  64. package/dist/api/routes/admin/draft-orders/index.js +7 -1
  65. package/dist/api/routes/admin/draft-orders/index.js.map +1 -1
  66. package/dist/api/routes/admin/draft-orders/register-payment.js +0 -1
  67. package/dist/api/routes/admin/draft-orders/register-payment.js.map +1 -1
  68. package/dist/api/routes/admin/draft-orders/update-line-item.d.ts +1 -1
  69. package/dist/api/routes/admin/draft-orders/update-line-item.js.map +1 -1
  70. package/dist/api/routes/admin/index.js +2 -0
  71. package/dist/api/routes/admin/index.js.map +1 -1
  72. package/dist/api/routes/admin/notifications/index.js.map +1 -1
  73. package/dist/api/routes/admin/notifications/list-notifications.js.map +1 -1
  74. package/dist/api/routes/admin/notifications/resend-notification.js.map +1 -1
  75. package/dist/api/routes/admin/orders/add-shipping-method.d.ts +1 -1
  76. package/dist/api/routes/admin/orders/add-shipping-method.js.map +1 -1
  77. package/dist/api/routes/admin/orders/create-claim.js +6 -0
  78. package/dist/api/routes/admin/orders/create-claim.js.map +1 -1
  79. package/dist/api/routes/admin/orders/create-order.js.map +1 -1
  80. package/dist/api/routes/admin/orders/create-swap.js +7 -3
  81. package/dist/api/routes/admin/orders/create-swap.js.map +1 -1
  82. package/dist/api/routes/admin/orders/index.d.ts +1 -1
  83. package/dist/api/routes/admin/orders/index.js +1 -3
  84. package/dist/api/routes/admin/orders/index.js.map +1 -1
  85. package/dist/api/routes/admin/orders/list-orders.js.map +1 -1
  86. package/dist/api/routes/admin/orders/update-order.js.map +1 -1
  87. package/dist/api/routes/admin/price-lists/delete-product-prices.d.ts +32 -0
  88. package/dist/api/routes/admin/{discounts/remove-valid-product.js → price-lists/delete-product-prices.js} +48 -25
  89. package/dist/api/routes/admin/price-lists/delete-product-prices.js.map +1 -0
  90. package/dist/api/routes/admin/price-lists/delete-variant-prices.d.ts +32 -0
  91. package/dist/api/routes/admin/price-lists/delete-variant-prices.js +105 -0
  92. package/dist/api/routes/admin/price-lists/delete-variant-prices.js.map +1 -0
  93. package/dist/api/routes/admin/price-lists/index.d.ts +9 -0
  94. package/dist/api/routes/admin/price-lists/index.js +6 -1
  95. package/dist/api/routes/admin/price-lists/index.js.map +1 -1
  96. package/dist/api/routes/admin/price-lists/list-price-list-products.d.ts +74 -0
  97. package/dist/api/routes/admin/price-lists/list-price-list-products.js +287 -0
  98. package/dist/api/routes/admin/price-lists/list-price-list-products.js.map +1 -0
  99. package/dist/api/routes/admin/price-lists/list-price-lists.js.map +1 -1
  100. package/dist/api/routes/admin/price-lists/update-price-list.d.ts +4 -4
  101. package/dist/api/routes/admin/price-lists/update-price-list.js +2 -2
  102. package/dist/api/routes/admin/price-lists/update-price-list.js.map +1 -1
  103. package/dist/api/routes/admin/product-tags/list-product-tags.d.ts +2 -1
  104. package/dist/api/routes/admin/product-tags/list-product-tags.js +6 -3
  105. package/dist/api/routes/admin/product-tags/list-product-tags.js.map +1 -1
  106. package/dist/api/routes/admin/product-types/list-product-types.d.ts +2 -1
  107. package/dist/api/routes/admin/product-types/list-product-types.js +6 -3
  108. package/dist/api/routes/admin/product-types/list-product-types.js.map +1 -1
  109. package/dist/api/routes/admin/products/index.d.ts +2 -1
  110. package/dist/api/routes/admin/products/index.js +7 -2
  111. package/dist/api/routes/admin/products/index.js.map +1 -1
  112. package/dist/api/routes/admin/products/list-products.d.ts +2 -1
  113. package/dist/api/routes/admin/products/list-products.js +31 -65
  114. package/dist/api/routes/admin/products/list-products.js.map +1 -1
  115. package/dist/api/routes/admin/products/list-variants.d.ts +35 -0
  116. package/dist/api/routes/admin/products/list-variants.js +173 -0
  117. package/dist/api/routes/admin/products/list-variants.js.map +1 -0
  118. package/dist/api/routes/admin/products/update-variant.js +11 -7
  119. package/dist/api/routes/admin/products/update-variant.js.map +1 -1
  120. package/dist/api/routes/admin/regions/index.d.ts +1 -1
  121. package/dist/api/routes/admin/shipping-options/list-shipping-options.d.ts +2 -2
  122. package/dist/api/routes/admin/shipping-options/list-shipping-options.js +2 -2
  123. package/dist/api/routes/admin/shipping-options/list-shipping-options.js.map +1 -1
  124. package/dist/api/routes/admin/store/get-store.js.map +1 -1
  125. package/dist/api/routes/admin/swaps/index.js +3 -0
  126. package/dist/api/routes/admin/swaps/index.js.map +1 -1
  127. package/dist/api/routes/admin/tax-rates/list-tax-rates.js.map +1 -1
  128. package/dist/api/routes/admin/tax-rates/utils/get-query-config.d.ts +1 -1
  129. package/dist/api/routes/admin/tax-rates/utils/get-query-config.js +4 -2
  130. package/dist/api/routes/admin/tax-rates/utils/get-query-config.js.map +1 -1
  131. package/dist/api/routes/admin/uploads/index.d.ts +1 -1
  132. package/dist/api/routes/admin/users/update-user.d.ts +1 -1
  133. package/dist/api/routes/admin/users/update-user.js.map +1 -1
  134. package/dist/api/routes/store/auth/create-session.js +4 -5
  135. package/dist/api/routes/store/auth/create-session.js.map +1 -1
  136. package/dist/api/routes/store/carts/create-cart.js +8 -5
  137. package/dist/api/routes/store/carts/create-cart.js.map +1 -1
  138. package/dist/api/routes/store/carts/create-line-item.d.ts +1 -1
  139. package/dist/api/routes/store/carts/create-line-item.js +9 -6
  140. package/dist/api/routes/store/carts/create-line-item.js.map +1 -1
  141. package/dist/api/routes/store/carts/index.d.ts +0 -1
  142. package/dist/api/routes/store/carts/index.js +1 -3
  143. package/dist/api/routes/store/carts/index.js.map +1 -1
  144. package/dist/api/routes/store/carts/update-cart.js +8 -8
  145. package/dist/api/routes/store/carts/update-cart.js.map +1 -1
  146. package/dist/api/routes/store/customers/create-customer.js +3 -4
  147. package/dist/api/routes/store/customers/create-customer.js.map +1 -1
  148. package/dist/api/routes/store/orders/index.js +0 -2
  149. package/dist/api/routes/store/orders/index.js.map +1 -1
  150. package/dist/api/routes/store/products/get-product.js +17 -5
  151. package/dist/api/routes/store/products/get-product.js.map +1 -1
  152. package/dist/api/routes/store/products/index.d.ts +2 -2
  153. package/dist/api/routes/store/products/list-products.d.ts +2 -1
  154. package/dist/api/routes/store/products/list-products.js +21 -8
  155. package/dist/api/routes/store/products/list-products.js.map +1 -1
  156. package/dist/api/routes/store/products/search.d.ts +1 -1
  157. package/dist/api/routes/store/products/search.js.map +1 -1
  158. package/dist/api/routes/store/shipping-options/list-options.js.map +1 -1
  159. package/dist/api/routes/store/swaps/create-swap.js +7 -3
  160. package/dist/api/routes/store/swaps/create-swap.js.map +1 -1
  161. package/dist/api/routes/store/variants/get-variant.js +17 -5
  162. package/dist/api/routes/store/variants/get-variant.js.map +1 -1
  163. package/dist/api/routes/store/variants/list-variants.d.ts +2 -1
  164. package/dist/api/routes/store/variants/list-variants.js +38 -9
  165. package/dist/api/routes/store/variants/list-variants.js.map +1 -1
  166. package/dist/commands/develop.js +2 -2
  167. package/dist/commands/develop.js.map +1 -1
  168. package/dist/commands/start.js +6 -0
  169. package/dist/commands/start.js.map +1 -1
  170. package/dist/controllers/customers/index.d.ts +1 -1
  171. package/dist/controllers/customers/list-customers.d.ts +1 -1
  172. package/dist/controllers/customers/list-customers.js +34 -37
  173. package/dist/controllers/customers/list-customers.js.map +1 -1
  174. package/dist/controllers/products/admin-list-products.d.ts +16 -0
  175. package/dist/controllers/products/admin-list-products.js +103 -0
  176. package/dist/controllers/products/admin-list-products.js.map +1 -0
  177. package/dist/helpers/test-request.js +26 -17
  178. package/dist/helpers/test-request.js.map +1 -1
  179. package/dist/index.d.ts +4 -59
  180. package/dist/index.js +4 -62
  181. package/dist/index.js.map +1 -1
  182. package/dist/interfaces/index.d.ts +3 -0
  183. package/dist/interfaces/index.js +3 -0
  184. package/dist/interfaces/index.js.map +1 -1
  185. package/dist/interfaces/models/base-entity.d.ts +8 -0
  186. package/dist/interfaces/models/base-entity.js +36 -0
  187. package/dist/interfaces/models/base-entity.js.map +1 -0
  188. package/dist/interfaces/models/soft-deletable-entity.d.ts +4 -0
  189. package/dist/interfaces/models/soft-deletable-entity.js +43 -0
  190. package/dist/interfaces/models/soft-deletable-entity.js.map +1 -0
  191. package/dist/interfaces/price-selection-strategy.d.ts +50 -0
  192. package/dist/interfaces/price-selection-strategy.js +34 -0
  193. package/dist/interfaces/price-selection-strategy.js.map +1 -0
  194. package/dist/interfaces/tax-service.d.ts +6 -0
  195. package/dist/interfaces/tax-service.js +31 -0
  196. package/dist/interfaces/tax-service.js.map +1 -1
  197. package/dist/interfaces/transaction-base-service.d.ts +23 -0
  198. package/dist/interfaces/transaction-base-service.js +200 -0
  199. package/dist/interfaces/transaction-base-service.js.map +1 -0
  200. package/dist/loaders/api.d.ts +9 -5
  201. package/dist/loaders/api.js +2 -6
  202. package/dist/loaders/api.js.map +1 -1
  203. package/dist/loaders/config.d.ts +3 -0
  204. package/dist/loaders/config.js +47 -0
  205. package/dist/loaders/config.js.map +1 -0
  206. package/dist/loaders/database.d.ts +8 -4
  207. package/dist/loaders/database.js.map +1 -1
  208. package/dist/loaders/defaults.d.ts +4 -3
  209. package/dist/loaders/defaults.js +39 -31
  210. package/dist/loaders/defaults.js.map +1 -1
  211. package/dist/loaders/express.d.ts +7 -4
  212. package/dist/loaders/express.js +7 -5
  213. package/dist/loaders/express.js.map +1 -1
  214. package/dist/loaders/index.d.ts +13 -8
  215. package/dist/loaders/index.js +29 -54
  216. package/dist/loaders/index.js.map +1 -1
  217. package/dist/loaders/logger.d.ts +1 -0
  218. package/dist/loaders/logger.js.map +1 -1
  219. package/dist/loaders/models.d.ts +8 -3
  220. package/dist/loaders/models.js +19 -17
  221. package/dist/loaders/models.js.map +1 -1
  222. package/dist/loaders/passport.d.ts +7 -4
  223. package/dist/loaders/passport.js +23 -21
  224. package/dist/loaders/passport.js.map +1 -1
  225. package/dist/loaders/plugins.d.ts +38 -10
  226. package/dist/loaders/plugins.js +30 -26
  227. package/dist/loaders/plugins.js.map +1 -1
  228. package/dist/loaders/redis.d.ts +8 -5
  229. package/dist/loaders/redis.js +3 -3
  230. package/dist/loaders/redis.js.map +1 -1
  231. package/dist/loaders/repositories.d.ts +7 -3
  232. package/dist/loaders/repositories.js +1 -1
  233. package/dist/loaders/repositories.js.map +1 -1
  234. package/dist/loaders/search-index.d.ts +4 -3
  235. package/dist/loaders/search-index.js.map +1 -1
  236. package/dist/loaders/services.d.ts +10 -5
  237. package/dist/loaders/services.js.map +1 -1
  238. package/dist/loaders/strategies.d.ts +1 -1
  239. package/dist/loaders/subscribers.d.ts +7 -3
  240. package/dist/loaders/subscribers.js.map +1 -1
  241. package/dist/migrations/1646324713514-discount_conditions.d.ts +6 -0
  242. package/dist/migrations/1646324713514-discount_conditions.js +335 -0
  243. package/dist/migrations/1646324713514-discount_conditions.js.map +1 -0
  244. package/dist/migrations/1648600574750-add_line_item_adjustments.d.ts +6 -0
  245. package/dist/migrations/1648600574750-add_line_item_adjustments.js +101 -0
  246. package/dist/migrations/1648600574750-add_line_item_adjustments.js.map +1 -0
  247. package/dist/migrations/1648641130007-tax_line_constraints.d.ts +6 -0
  248. package/dist/migrations/1648641130007-tax_line_constraints.js +77 -0
  249. package/dist/migrations/1648641130007-tax_line_constraints.js.map +1 -0
  250. package/dist/migrations/1649775522087-add_batch_job_model.d.ts +6 -0
  251. package/dist/migrations/1649775522087-add_batch_job_model.js +77 -0
  252. package/dist/migrations/1649775522087-add_batch_job_model.js.map +1 -0
  253. package/dist/models/address.d.ts +3 -6
  254. package/dist/models/address.js +23 -24
  255. package/dist/models/address.js.map +1 -1
  256. package/dist/models/batch-job.d.ts +55 -0
  257. package/dist/models/batch-job.js +118 -0
  258. package/dist/models/batch-job.js.map +1 -0
  259. package/dist/models/cart.d.ts +5 -8
  260. package/dist/models/cart.js +35 -36
  261. package/dist/models/cart.js.map +1 -1
  262. package/dist/models/claim-image.d.ts +3 -6
  263. package/dist/models/claim-image.js +22 -23
  264. package/dist/models/claim-image.js.map +1 -1
  265. package/dist/models/claim-item.d.ts +3 -6
  266. package/dist/models/claim-item.js +25 -24
  267. package/dist/models/claim-item.js.map +1 -1
  268. package/dist/models/claim-order.d.ts +4 -4
  269. package/dist/models/claim-order.js +28 -13
  270. package/dist/models/claim-order.js.map +1 -1
  271. package/dist/models/claim-tag.d.ts +3 -6
  272. package/dist/models/claim-tag.js +22 -23
  273. package/dist/models/claim-tag.js.map +1 -1
  274. package/dist/models/country.d.ts +1 -1
  275. package/dist/models/country.js +1 -1
  276. package/dist/models/country.js.map +1 -1
  277. package/dist/models/custom-shipping-option.d.ts +3 -6
  278. package/dist/models/custom-shipping-option.js +23 -24
  279. package/dist/models/custom-shipping-option.js.map +1 -1
  280. package/dist/models/customer-group.d.ts +3 -6
  281. package/dist/models/customer-group.js +26 -26
  282. package/dist/models/customer-group.js.map +1 -1
  283. package/dist/models/customer.d.ts +3 -6
  284. package/dist/models/customer.js +23 -25
  285. package/dist/models/customer.js.map +1 -1
  286. package/dist/models/discount-condition-customer-group.d.ts +39 -0
  287. package/dist/models/discount-condition-customer-group.js +84 -0
  288. package/dist/models/discount-condition-customer-group.js.map +1 -0
  289. package/dist/models/discount-condition-product-collection.d.ts +39 -0
  290. package/dist/models/discount-condition-product-collection.js +84 -0
  291. package/dist/models/discount-condition-product-collection.js.map +1 -0
  292. package/dist/models/discount-condition-product-tag.d.ts +39 -0
  293. package/dist/models/discount-condition-product-tag.js +84 -0
  294. package/dist/models/discount-condition-product-tag.js.map +1 -0
  295. package/dist/models/discount-condition-product-type.d.ts +39 -0
  296. package/dist/models/discount-condition-product-type.js +84 -0
  297. package/dist/models/discount-condition-product-type.js.map +1 -0
  298. package/dist/models/discount-condition-product.d.ts +39 -0
  299. package/dist/models/discount-condition-product.js +84 -0
  300. package/dist/models/discount-condition-product.js.map +1 -0
  301. package/dist/models/discount-condition.d.ts +65 -0
  302. package/dist/models/discount-condition.js +209 -0
  303. package/dist/models/discount-condition.js.map +1 -0
  304. package/dist/models/discount-rule.d.ts +8 -11
  305. package/dist/models/discount-rule.js +28 -38
  306. package/dist/models/discount-rule.js.map +1 -1
  307. package/dist/models/discount.d.ts +7 -10
  308. package/dist/models/discount.js +30 -30
  309. package/dist/models/discount.js.map +1 -1
  310. package/dist/models/draft-order.d.ts +3 -5
  311. package/dist/models/draft-order.js +23 -20
  312. package/dist/models/draft-order.js.map +1 -1
  313. package/dist/models/fulfillment-item.js.map +1 -1
  314. package/dist/models/fulfillment-provider.js.map +1 -1
  315. package/dist/models/fulfillment.d.ts +5 -7
  316. package/dist/models/fulfillment.js +29 -21
  317. package/dist/models/fulfillment.js.map +1 -1
  318. package/dist/models/gift-card-transaction.js +2 -5
  319. package/dist/models/gift-card-transaction.js.map +1 -1
  320. package/dist/models/gift-card.d.ts +3 -6
  321. package/dist/models/gift-card.js +22 -23
  322. package/dist/models/gift-card.js.map +1 -1
  323. package/dist/models/idempotency-key.d.ts +2 -2
  324. package/dist/models/idempotency-key.js +2 -3
  325. package/dist/models/idempotency-key.js.map +1 -1
  326. package/dist/models/image.d.ts +3 -6
  327. package/dist/models/image.js +22 -23
  328. package/dist/models/image.js.map +1 -1
  329. package/dist/models/index.d.ts +67 -0
  330. package/dist/models/index.js +80 -0
  331. package/dist/models/index.js.map +1 -0
  332. package/dist/models/invite.d.ts +3 -6
  333. package/dist/models/invite.js +22 -24
  334. package/dist/models/invite.js.map +1 -1
  335. package/dist/models/line-item-adjustment.d.ts +13 -0
  336. package/dist/models/line-item-adjustment.js +76 -0
  337. package/dist/models/line-item-adjustment.js.map +1 -0
  338. package/dist/models/line-item-tax-line.js +4 -6
  339. package/dist/models/line-item-tax-line.js.map +1 -1
  340. package/dist/models/line-item.d.ts +5 -5
  341. package/dist/models/line-item.js +29 -19
  342. package/dist/models/line-item.js.map +1 -1
  343. package/dist/models/money-amount.d.ts +2 -5
  344. package/dist/models/money-amount.js +26 -26
  345. package/dist/models/money-amount.js.map +1 -1
  346. package/dist/models/note.d.ts +3 -6
  347. package/dist/models/note.js +22 -23
  348. package/dist/models/note.js.map +1 -1
  349. package/dist/models/notification.d.ts +3 -5
  350. package/dist/models/notification.js +22 -19
  351. package/dist/models/notification.js.map +1 -1
  352. package/dist/models/oauth.d.ts +1 -1
  353. package/dist/models/oauth.js +2 -5
  354. package/dist/models/oauth.js.map +1 -1
  355. package/dist/models/order.d.ts +3 -5
  356. package/dist/models/order.js +25 -21
  357. package/dist/models/order.js.map +1 -1
  358. package/dist/models/payment-provider.js.map +1 -1
  359. package/dist/models/payment-session.d.ts +3 -5
  360. package/dist/models/payment-session.js +22 -19
  361. package/dist/models/payment-session.js.map +1 -1
  362. package/dist/models/payment.d.ts +4 -6
  363. package/dist/models/payment.js +22 -19
  364. package/dist/models/payment.js.map +1 -1
  365. package/dist/models/price-list.d.ts +4 -7
  366. package/dist/models/price-list.js +30 -28
  367. package/dist/models/price-list.js.map +1 -1
  368. package/dist/models/product-collection.d.ts +4 -7
  369. package/dist/models/product-collection.js +25 -24
  370. package/dist/models/product-collection.js.map +1 -1
  371. package/dist/models/product-option-value.d.ts +3 -6
  372. package/dist/models/product-option-value.js +24 -26
  373. package/dist/models/product-option-value.js.map +1 -1
  374. package/dist/models/product-option.d.ts +3 -6
  375. package/dist/models/product-option.js +23 -24
  376. package/dist/models/product-option.js.map +1 -1
  377. package/dist/models/product-tag.d.ts +3 -6
  378. package/dist/models/product-tag.js +22 -23
  379. package/dist/models/product-tag.js.map +1 -1
  380. package/dist/models/product-tax-rate.d.ts +1 -1
  381. package/dist/models/product-tax-rate.js.map +1 -1
  382. package/dist/models/product-type-tax-rate.d.ts +1 -1
  383. package/dist/models/product-type-tax-rate.js.map +1 -1
  384. package/dist/models/product-type.d.ts +3 -6
  385. package/dist/models/product-type.js +22 -23
  386. package/dist/models/product-type.js.map +1 -1
  387. package/dist/models/product-variant.d.ts +3 -6
  388. package/dist/models/product-variant.js +30 -26
  389. package/dist/models/product-variant.js.map +1 -1
  390. package/dist/models/product.d.ts +3 -6
  391. package/dist/models/product.js +25 -22
  392. package/dist/models/product.js.map +1 -1
  393. package/dist/models/refund.d.ts +3 -5
  394. package/dist/models/refund.js +22 -17
  395. package/dist/models/refund.js.map +1 -1
  396. package/dist/models/region.d.ts +3 -6
  397. package/dist/models/region.js +23 -24
  398. package/dist/models/region.js.map +1 -1
  399. package/dist/models/return-item.d.ts +1 -1
  400. package/dist/models/return-item.js.map +1 -1
  401. package/dist/models/return-reason.d.ts +3 -6
  402. package/dist/models/return-reason.js +24 -25
  403. package/dist/models/return-reason.js.map +1 -1
  404. package/dist/models/return.d.ts +5 -7
  405. package/dist/models/return.js +29 -21
  406. package/dist/models/return.js.map +1 -1
  407. package/dist/models/shipping-method-tax-line.js +4 -6
  408. package/dist/models/shipping-method-tax-line.js.map +1 -1
  409. package/dist/models/shipping-method.d.ts +1 -1
  410. package/dist/models/shipping-method.js +2 -5
  411. package/dist/models/shipping-method.js.map +1 -1
  412. package/dist/models/shipping-option-requirement.js +2 -5
  413. package/dist/models/shipping-option-requirement.js.map +1 -1
  414. package/dist/models/shipping-option.d.ts +4 -7
  415. package/dist/models/shipping-option.js +25 -24
  416. package/dist/models/shipping-option.js.map +1 -1
  417. package/dist/models/shipping-profile.d.ts +3 -6
  418. package/dist/models/shipping-profile.js +22 -23
  419. package/dist/models/shipping-profile.js.map +1 -1
  420. package/dist/models/shipping-tax-rate.d.ts +1 -1
  421. package/dist/models/shipping-tax-rate.js.map +1 -1
  422. package/dist/models/staged-job.d.ts +1 -1
  423. package/dist/models/staged-job.js +2 -3
  424. package/dist/models/staged-job.js.map +1 -1
  425. package/dist/models/store.d.ts +3 -5
  426. package/dist/models/store.js +22 -17
  427. package/dist/models/store.js.map +1 -1
  428. package/dist/models/swap.d.ts +9 -12
  429. package/dist/models/swap.js +55 -52
  430. package/dist/models/swap.js.map +1 -1
  431. package/dist/models/tax-line.d.ts +3 -5
  432. package/dist/models/tax-line.js +20 -14
  433. package/dist/models/tax-line.js.map +1 -1
  434. package/dist/models/tax-rate.d.ts +3 -5
  435. package/dist/models/tax-rate.js +22 -19
  436. package/dist/models/tax-rate.js.map +1 -1
  437. package/dist/models/tracking-link.d.ts +3 -6
  438. package/dist/models/tracking-link.js +26 -27
  439. package/dist/models/tracking-link.js.map +1 -1
  440. package/dist/models/user.d.ts +3 -6
  441. package/dist/models/user.js +22 -23
  442. package/dist/models/user.js.map +1 -1
  443. package/dist/repositories/batch-job.d.ts +4 -0
  444. package/dist/repositories/batch-job.js +38 -0
  445. package/dist/repositories/batch-job.js.map +1 -0
  446. package/dist/repositories/cart.d.ts +2 -2
  447. package/dist/repositories/cart.js.map +1 -1
  448. package/dist/repositories/customer.d.ts +1 -1
  449. package/dist/repositories/customer.js +7 -9
  450. package/dist/repositories/customer.js.map +1 -1
  451. package/dist/repositories/discount-condition.d.ts +38 -0
  452. package/dist/repositories/discount-condition.js +398 -0
  453. package/dist/repositories/discount-condition.js.map +1 -0
  454. package/dist/repositories/line-item-adjustment.d.ts +4 -0
  455. package/dist/repositories/line-item-adjustment.js +38 -0
  456. package/dist/repositories/line-item-adjustment.js.map +1 -0
  457. package/dist/repositories/line-item-tax-line.d.ts +2 -0
  458. package/dist/repositories/line-item-tax-line.js +80 -0
  459. package/dist/repositories/line-item-tax-line.js.map +1 -1
  460. package/dist/repositories/line-item.js +1 -0
  461. package/dist/repositories/line-item.js.map +1 -1
  462. package/dist/repositories/money-amount.d.ts +2 -0
  463. package/dist/repositories/money-amount.js +77 -2
  464. package/dist/repositories/money-amount.js.map +1 -1
  465. package/dist/repositories/order.d.ts +1 -1
  466. package/dist/repositories/price-list.d.ts +8 -1
  467. package/dist/repositories/price-list.js +209 -0
  468. package/dist/repositories/price-list.js.map +1 -1
  469. package/dist/repositories/product.d.ts +2 -0
  470. package/dist/repositories/product.js +35 -17
  471. package/dist/repositories/product.js.map +1 -1
  472. package/dist/repositories/shipping-method-tax-line.d.ts +2 -0
  473. package/dist/repositories/shipping-method-tax-line.js +80 -0
  474. package/dist/repositories/shipping-method-tax-line.js.map +1 -1
  475. package/dist/scripts/discount-rule-migration.d.ts +4 -0
  476. package/dist/scripts/discount-rule-migration.js +189 -0
  477. package/dist/scripts/discount-rule-migration.js.map +1 -0
  478. package/dist/scripts/line-item-adjustment-migration.d.ts +4 -0
  479. package/dist/scripts/line-item-adjustment-migration.js +173 -0
  480. package/dist/scripts/line-item-adjustment-migration.js.map +1 -0
  481. package/dist/services/batch-job.d.ts +24 -0
  482. package/dist/services/batch-job.js +126 -0
  483. package/dist/services/batch-job.js.map +1 -0
  484. package/dist/services/cart.d.ts +66 -55
  485. package/dist/services/cart.js +1301 -1410
  486. package/dist/services/cart.js.map +1 -1
  487. package/dist/services/claim.js +62 -19
  488. package/dist/services/claim.js.map +1 -1
  489. package/dist/services/customer.d.ts +0 -7
  490. package/dist/services/customer.js +8 -35
  491. package/dist/services/customer.js.map +1 -1
  492. package/dist/services/discount-condition.d.ts +31 -0
  493. package/dist/services/discount-condition.js +232 -0
  494. package/dist/services/discount-condition.js.map +1 -0
  495. package/dist/services/discount.d.ts +50 -59
  496. package/dist/services/discount.js +272 -174
  497. package/dist/services/discount.js.map +1 -1
  498. package/dist/services/draft-order.js +1 -0
  499. package/dist/services/draft-order.js.map +1 -1
  500. package/dist/services/fulfillment-provider.js +23 -17
  501. package/dist/services/fulfillment-provider.js.map +1 -1
  502. package/dist/services/invite.d.ts +4 -2
  503. package/dist/services/invite.js +11 -9
  504. package/dist/services/invite.js.map +1 -1
  505. package/dist/services/line-item-adjustment.d.ts +87 -0
  506. package/dist/services/line-item-adjustment.js +434 -0
  507. package/dist/services/line-item-adjustment.js.map +1 -0
  508. package/dist/services/line-item.d.ts +48 -40
  509. package/dist/services/line-item.js +226 -193
  510. package/dist/services/line-item.js.map +1 -1
  511. package/dist/services/order.d.ts +0 -13
  512. package/dist/services/order.js +4 -30
  513. package/dist/services/order.js.map +1 -1
  514. package/dist/services/payment-provider.js +23 -17
  515. package/dist/services/payment-provider.js.map +1 -1
  516. package/dist/services/price-list.d.ts +35 -14
  517. package/dist/services/price-list.js +327 -56
  518. package/dist/services/price-list.js.map +1 -1
  519. package/dist/services/product-tag.d.ts +2 -2
  520. package/dist/services/product-tag.js +15 -2
  521. package/dist/services/product-tag.js.map +1 -1
  522. package/dist/services/product-type.d.ts +1 -1
  523. package/dist/services/product-type.js +14 -1
  524. package/dist/services/product-type.js.map +1 -1
  525. package/dist/services/product-variant.d.ts +26 -9
  526. package/dist/services/product-variant.js +223 -77
  527. package/dist/services/product-variant.js.map +1 -1
  528. package/dist/services/product.d.ts +24 -5
  529. package/dist/services/product.js +247 -52
  530. package/dist/services/product.js.map +1 -1
  531. package/dist/services/region.js +8 -4
  532. package/dist/services/region.js.map +1 -1
  533. package/dist/services/return.js +2 -1
  534. package/dist/services/return.js.map +1 -1
  535. package/dist/services/shipping-option.d.ts +2 -2
  536. package/dist/services/shipping-option.js +7 -4
  537. package/dist/services/shipping-option.js.map +1 -1
  538. package/dist/services/swap.d.ts +4 -1
  539. package/dist/services/swap.js +29 -16
  540. package/dist/services/swap.js.map +1 -1
  541. package/dist/services/system-tax.d.ts +2 -3
  542. package/dist/services/system-tax.js +2 -2
  543. package/dist/services/system-tax.js.map +1 -1
  544. package/dist/services/tax-provider.d.ts +2 -0
  545. package/dist/services/tax-provider.js +96 -7
  546. package/dist/services/tax-provider.js.map +1 -1
  547. package/dist/services/tax-rate.d.ts +3 -3
  548. package/dist/services/tax-rate.js +1 -1
  549. package/dist/services/tax-rate.js.map +1 -1
  550. package/dist/services/totals.d.ts +9 -8
  551. package/dist/services/totals.js +41 -88
  552. package/dist/services/totals.js.map +1 -1
  553. package/dist/strategies/cart-completion.js.map +1 -1
  554. package/dist/strategies/price-selection.d.ts +13 -0
  555. package/dist/strategies/price-selection.js +185 -0
  556. package/dist/strategies/price-selection.js.map +1 -0
  557. package/dist/subscribers/order.js +1 -7
  558. package/dist/subscribers/order.js.map +1 -1
  559. package/dist/types/batch-job.d.ts +15 -0
  560. package/dist/types/batch-job.js +63 -0
  561. package/dist/types/batch-job.js.map +1 -0
  562. package/dist/types/cart.d.ts +2 -2
  563. package/dist/types/common.d.ts +32 -13
  564. package/dist/types/common.js +1 -0
  565. package/dist/types/common.js.map +1 -1
  566. package/dist/types/discount.d.ts +68 -1
  567. package/dist/types/discount.js +129 -5
  568. package/dist/types/discount.js.map +1 -1
  569. package/dist/types/global.d.ts +43 -0
  570. package/dist/types/global.js +3 -0
  571. package/dist/types/global.js.map +1 -0
  572. package/dist/types/line-item-adjustment.d.ts +9 -0
  573. package/dist/types/line-item-adjustment.js +50 -0
  574. package/dist/types/line-item-adjustment.js.map +1 -0
  575. package/dist/types/note.d.ts +1 -1
  576. package/dist/types/price-list.d.ts +1 -0
  577. package/dist/types/price-list.js +5 -0
  578. package/dist/types/price-list.js.map +1 -1
  579. package/dist/types/price-selection.d.ts +5 -0
  580. package/dist/types/price-selection.js +35 -0
  581. package/dist/types/price-selection.js.map +1 -0
  582. package/dist/types/product-variant.d.ts +6 -0
  583. package/dist/types/product-variant.js.map +1 -1
  584. package/dist/types/product.d.ts +18 -0
  585. package/dist/types/product.js +104 -5
  586. package/dist/types/product.js.map +1 -1
  587. package/dist/types/tax-service.d.ts +2 -2
  588. package/dist/types/user.d.ts +2 -2
  589. package/dist/types/validators/exactly-one.d.ts +6 -0
  590. package/dist/types/validators/exactly-one.js +37 -0
  591. package/dist/types/validators/exactly-one.js.map +1 -0
  592. package/dist/utils/build-query.d.ts +8 -0
  593. package/dist/utils/build-query.js +114 -0
  594. package/dist/utils/build-query.js.map +1 -0
  595. package/dist/utils/date-helpers.d.ts +2 -0
  596. package/dist/utils/date-helpers.js +15 -0
  597. package/dist/utils/date-helpers.js.map +1 -0
  598. package/dist/utils/generate-entity-id.d.ts +6 -0
  599. package/dist/utils/generate-entity-id.js +19 -0
  600. package/dist/utils/generate-entity-id.js.map +1 -0
  601. package/dist/utils/get-query-config.d.ts +11 -0
  602. package/dist/utils/get-query-config.js +88 -0
  603. package/dist/utils/get-query-config.js.map +1 -0
  604. package/dist/utils/index.d.ts +4 -0
  605. package/dist/utils/index.js +17 -0
  606. package/dist/utils/index.js.map +1 -0
  607. package/dist/utils/set-metadata.d.ts +9 -0
  608. package/dist/utils/set-metadata.js +72 -0
  609. package/dist/utils/set-metadata.js.map +1 -0
  610. package/dist/utils/validate-id.d.ts +4 -0
  611. package/dist/utils/validate-id.js +47 -0
  612. package/dist/utils/validate-id.js.map +1 -0
  613. package/jest.config.js +6 -0
  614. package/package.json +10 -9
  615. package/tsconfig.spec.json +10 -0
  616. package/dist/api/routes/admin/discounts/add-valid-product.d.ts +0 -23
  617. package/dist/api/routes/admin/discounts/add-valid-product.js.map +0 -1
  618. package/dist/api/routes/admin/discounts/remove-valid-product.d.ts +0 -23
  619. package/dist/api/routes/admin/discounts/remove-valid-product.js.map +0 -1
  620. package/dist/api/routes/admin/products/get-variants.d.ts +0 -24
  621. package/dist/api/routes/admin/products/get-variants.js.map +0 -1
  622. package/dist/api/routes/store/carts/update-payment-method.d.ts +0 -38
  623. package/dist/api/routes/store/carts/update-payment-method.js.map +0 -1
  624. package/dist/config/index.d.ts +0 -14
  625. package/dist/config/index.js +0 -40
  626. package/dist/config/index.js.map +0 -1
  627. package/yarn-error.log +0 -6769
@@ -53,6 +53,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
53
53
  Object.defineProperty(exports, "__esModule", { value: true });
54
54
  var medusa_core_utils_1 = require("medusa-core-utils");
55
55
  var medusa_interfaces_1 = require("medusa-interfaces");
56
+ var typeorm_1 = require("typeorm");
56
57
  /**
57
58
  * Provides layer to manipulate products.
58
59
  * @extends BaseService
@@ -138,12 +139,24 @@ var ProductTypeService = /** @class */ (function (_super) {
138
139
  if (selector === void 0) { selector = {}; }
139
140
  if (config === void 0) { config = { skip: 0, take: 20 }; }
140
141
  return __awaiter(this, void 0, void 0, function () {
141
- var typeRepo, query;
142
+ var typeRepo, q, query, where_1;
142
143
  return __generator(this, function (_a) {
143
144
  switch (_a.label) {
144
145
  case 0:
145
146
  typeRepo = this.manager_.getCustomRepository(this.typeRepository_);
147
+ q = undefined;
148
+ if ("q" in selector) {
149
+ q = selector.q;
150
+ delete selector.q;
151
+ }
146
152
  query = this.buildQuery_(selector, config);
153
+ if (q) {
154
+ where_1 = query.where;
155
+ delete where_1.value;
156
+ query.where = function (qb) {
157
+ qb.where(where_1).andWhere([{ value: (0, typeorm_1.ILike)("%".concat(q, "%")) }]);
158
+ };
159
+ }
147
160
  return [4 /*yield*/, typeRepo.findAndCount(query)];
148
161
  case 1: return [2 /*return*/, _a.sent()];
149
162
  }
@@ -1 +1 @@
1
- {"version":3,"file":"product-type.js","sourceRoot":"","sources":["../../src/services/product-type.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,uDAA+C;AAC/C,uDAA+C;AAO/C;;;GAGG;AACH;IAAiC,sCAAW;IAG1C,4BAAY,EAAkC;YAAhC,OAAO,aAAA,EAAE,qBAAqB,2BAAA;QAA5C,YACE,iBAAO,SAIR;QAFC,KAAI,CAAC,QAAQ,GAAG,OAAO,CAAA;QACvB,KAAI,CAAC,eAAe,GAAG,qBAAqB,CAAA;;IAC9C,CAAC;IAED,4CAAe,GAAf,UAAgB,kBAAiC;QAC/C,IAAI,CAAC,kBAAkB,EAAE;YACvB,OAAO,IAAI,CAAA;SACZ;QAED,IAAM,MAAM,GAAG,IAAI,kBAAkB,CAAC;YACpC,OAAO,EAAE,kBAAkB;YAC3B,qBAAqB,EAAE,IAAI,CAAC,eAAe;SAC5C,CAAC,CAAA;QAEF,MAAM,CAAC,mBAAmB,GAAG,kBAAkB,CAAA;QAC/C,MAAM,CAAC,QAAQ,GAAG,kBAAkB,CAAA;QAEpC,OAAO,MAAM,CAAA;IACf,CAAC;IAED;;;;;;;OAOG;IACG,qCAAQ,GAAd,UACE,EAAU,EACV,MAAoC;QAApC,uBAAA,EAAA,WAAoC;;;;;;wBAE9B,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC,mBAAmB,CAAC,IAAI,CAAC,eAAe,CAAC,CAAA;wBAElE,KAAK,GAAG,IAAI,CAAC,WAAW,CAAC,EAAE,EAAE,IAAA,EAAE,EAAE,MAAM,CAAC,CAAA;wBACjC,qBAAM,QAAQ,CAAC,OAAO,CAAC,KAAK,CAAC,EAAA;;wBAApC,IAAI,GAAG,SAA6B;wBAE1C,IAAI,CAAC,IAAI,EAAE;4BACT,MAAM,IAAI,+BAAW,CACnB,+BAAW,CAAC,KAAK,CAAC,SAAS,EAC3B,2BAAoB,EAAE,mBAAgB,CACvC,CAAA;yBACF;wBAED,sBAAO,IAAI,EAAA;;;;KACZ;IAED;;;;;OAKG;IACG,iCAAI,GAAV,UACE,QAAyC,EACzC,MAAuD;QADvD,yBAAA,EAAA,aAAyC;QACzC,uBAAA,EAAA,WAAoC,IAAI,EAAE,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE;;;;;;wBAEjD,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC,mBAAmB,CAAC,IAAI,CAAC,eAAe,CAAC,CAAA;wBAElE,KAAK,GAAG,IAAI,CAAC,WAAW,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAA;wBACzC,qBAAM,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,EAAA;4BAAjC,sBAAO,SAA0B,EAAA;;;;KAClC;IAED;;;;;OAKG;IACG,yCAAY,GAAlB,UACE,QAAyC,EACzC,MAAuD;QADvD,yBAAA,EAAA,aAAyC;QACzC,uBAAA,EAAA,WAAoC,IAAI,EAAE,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE;;;;;;wBAEjD,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC,mBAAmB,CAAC,IAAI,CAAC,eAAe,CAAC,CAAA;wBAElE,KAAK,GAAG,IAAI,CAAC,WAAW,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAA;wBACzC,qBAAM,QAAQ,CAAC,YAAY,CAAC,KAAK,CAAC,EAAA;4BAAzC,sBAAO,SAAkC,EAAA;;;;KAC1C;IACH,yBAAC;AAAD,CAAC,AApFD,CAAiC,+BAAW,GAoF3C;AAED,kBAAe,kBAAkB,CAAA"}
1
+ {"version":3,"file":"product-type.js","sourceRoot":"","sources":["../../src/services/product-type.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,uDAA+C;AAC/C,uDAA+C;AAC/C,mCAAkE;AAMlE;;;GAGG;AACH;IAAiC,sCAAW;IAG1C,4BAAY,EAAkC;YAAhC,OAAO,aAAA,EAAE,qBAAqB,2BAAA;QAA5C,YACE,iBAAO,SAIR;QAFC,KAAI,CAAC,QAAQ,GAAG,OAAO,CAAA;QACvB,KAAI,CAAC,eAAe,GAAG,qBAAqB,CAAA;;IAC9C,CAAC;IAED,4CAAe,GAAf,UAAgB,kBAAiC;QAC/C,IAAI,CAAC,kBAAkB,EAAE;YACvB,OAAO,IAAI,CAAA;SACZ;QAED,IAAM,MAAM,GAAG,IAAI,kBAAkB,CAAC;YACpC,OAAO,EAAE,kBAAkB;YAC3B,qBAAqB,EAAE,IAAI,CAAC,eAAe;SAC5C,CAAC,CAAA;QAEF,MAAM,CAAC,mBAAmB,GAAG,kBAAkB,CAAA;QAC/C,MAAM,CAAC,QAAQ,GAAG,kBAAkB,CAAA;QAEpC,OAAO,MAAM,CAAA;IACf,CAAC;IAED;;;;;;;OAOG;IACG,qCAAQ,GAAd,UACE,EAAU,EACV,MAAoC;QAApC,uBAAA,EAAA,WAAoC;;;;;;wBAE9B,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC,mBAAmB,CAAC,IAAI,CAAC,eAAe,CAAC,CAAA;wBAElE,KAAK,GAAG,IAAI,CAAC,WAAW,CAAC,EAAE,EAAE,IAAA,EAAE,EAAE,MAAM,CAAC,CAAA;wBACjC,qBAAM,QAAQ,CAAC,OAAO,CAAC,KAAK,CAAC,EAAA;;wBAApC,IAAI,GAAG,SAA6B;wBAE1C,IAAI,CAAC,IAAI,EAAE;4BACT,MAAM,IAAI,+BAAW,CACnB,+BAAW,CAAC,KAAK,CAAC,SAAS,EAC3B,2BAAoB,EAAE,mBAAgB,CACvC,CAAA;yBACF;wBAED,sBAAO,IAAI,EAAA;;;;KACZ;IAED;;;;;OAKG;IACG,iCAAI,GAAV,UACE,QAAyC,EACzC,MAAuD;QADvD,yBAAA,EAAA,aAAyC;QACzC,uBAAA,EAAA,WAAoC,IAAI,EAAE,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE;;;;;;wBAEjD,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC,mBAAmB,CAAC,IAAI,CAAC,eAAe,CAAC,CAAA;wBAElE,KAAK,GAAG,IAAI,CAAC,WAAW,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAA;wBACzC,qBAAM,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,EAAA;4BAAjC,sBAAO,SAA0B,EAAA;;;;KAClC;IAED;;;;;OAKG;IACG,yCAAY,GAAlB,UACE,QAAyC,EACzC,MAAuD;QADvD,yBAAA,EAAA,aAAyC;QACzC,uBAAA,EAAA,WAAoC,IAAI,EAAE,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE;;;;;;wBAEjD,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC,mBAAmB,CAAC,IAAI,CAAC,eAAe,CAAC,CAAA;wBAEpE,CAAC,GAAuB,SAAS,CAAA;wBACrC,IAAI,GAAG,IAAI,QAAQ,EAAE;4BACnB,CAAC,GAAG,QAAQ,CAAC,CAAC,CAAA;4BACd,OAAO,QAAQ,CAAC,CAAC,CAAA;yBAClB;wBAEK,KAAK,GAAG,IAAI,CAAC,WAAW,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAA;wBAEhD,IAAI,CAAC,EAAE;4BACC,UAAQ,KAAK,CAAC,KAAK,CAAA;4BAEzB,OAAO,OAAK,CAAC,KAAK,CAAA;4BAElB,KAAK,CAAC,KAAK,GAAG,UAAC,EAAmC;gCAChD,EAAE,CAAC,KAAK,CAAC,OAAK,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,KAAK,EAAE,IAAA,eAAK,EAAC,WAAI,CAAC,MAAG,CAAC,EAAE,CAAC,CAAC,CAAA;4BACxD,CAAC,CAAA;yBACF;wBAEM,qBAAM,QAAQ,CAAC,YAAY,CAAC,KAAK,CAAC,EAAA;4BAAzC,sBAAO,SAAkC,EAAA;;;;KAC1C;IACH,yBAAC;AAAD,CAAC,AArGD,CAAiC,+BAAW,GAqG3C;AAED,kBAAe,kBAAkB,CAAA"}
@@ -1,12 +1,13 @@
1
1
  import { BaseService } from "medusa-interfaces";
2
2
  import { EntityManager, SelectQueryBuilder } from "typeorm";
3
- import { MoneyAmount } from "..";
3
+ import { PriceSelectionContext } from "../interfaces/price-selection-strategy";
4
+ import { MoneyAmount } from "../models/money-amount";
4
5
  import { Product } from "../models/product";
5
6
  import { ProductOptionValue } from "../models/product-option-value";
6
7
  import { ProductVariant } from "../models/product-variant";
7
8
  import { FindWithRelationsOptions, ProductVariantRepository } from "../repositories/product-variant";
8
9
  import { FindConfig } from "../types/common";
9
- import { CreateProductVariantInput, FilterableProductVariantProps, ProductVariantPrice, UpdateProductVariantInput } from "../types/product-variant";
10
+ import { CreateProductVariantInput, FilterableProductVariantProps, GetRegionPriceContext, ProductVariantPrice, UpdateProductVariantInput } from "../types/product-variant";
10
11
  /**
11
12
  * Provides layer to manipulate product variants.
12
13
  * @extends BaseService
@@ -22,9 +23,11 @@ declare class ProductVariantService extends BaseService {
22
23
  private productRepository_;
23
24
  private eventBus_;
24
25
  private regionService_;
26
+ private priceSelectionStrategy_;
25
27
  private moneyAmountRepository_;
26
28
  private productOptionValueRepository_;
27
- constructor({ manager, productVariantRepository, productRepository, eventBusService, regionService, moneyAmountRepository, productOptionValueRepository, }: {
29
+ private cartRepository_;
30
+ constructor({ manager, productVariantRepository, productRepository, eventBusService, regionService, moneyAmountRepository, productOptionValueRepository, cartRepository, priceSelectionStrategy, }: {
28
31
  manager: any;
29
32
  productVariantRepository: any;
30
33
  productRepository: any;
@@ -32,6 +35,8 @@ declare class ProductVariantService extends BaseService {
32
35
  regionService: any;
33
36
  moneyAmountRepository: any;
34
37
  productOptionValueRepository: any;
38
+ cartRepository: any;
39
+ priceSelectionStrategy: any;
35
40
  });
36
41
  withTransaction(transactionManager: EntityManager): ProductVariantService;
37
42
  /**
@@ -40,14 +45,14 @@ declare class ProductVariantService extends BaseService {
40
45
  * @param {FindConfig<ProductVariant>} config - query config object for variant retrieval.
41
46
  * @return {Promise<Product>} the product document.
42
47
  */
43
- retrieve(variantId: string, config?: FindConfig<ProductVariant>): Promise<ProductVariant>;
48
+ retrieve(variantId: string, config?: FindConfig<ProductVariant> & PriceSelectionContext): Promise<ProductVariant>;
44
49
  /**
45
50
  * Gets a product variant by id.
46
51
  * @param {string} sku - The unique stock keeping unit used to identify the product variant.
47
52
  * @param {FindConfig<ProductVariant>} config - query config object for variant retrieval.
48
53
  * @return {Promise<Product>} the product document.
49
54
  */
50
- retrieveBySKU(sku: string, config?: FindConfig<ProductVariant>): Promise<ProductVariant>;
55
+ retrieveBySKU(sku: string, config?: FindConfig<ProductVariant> & PriceSelectionContext): Promise<ProductVariant>;
51
56
  /**
52
57
  * Creates an unpublished product variant. Will validate against parent product
53
58
  * to ensure that the variant can in fact be created.
@@ -62,6 +67,7 @@ declare class ProductVariantService extends BaseService {
62
67
  * The function will throw, if price updates are attempted.
63
68
  * @param {string | ProductVariant} variantOrVariantId - variant or id of a variant.
64
69
  * @param {object} update - an object with the update values.
70
+ * @param {object} config - an object with the config values for returning the variant.
65
71
  * @return {Promise} resolves to the update result.
66
72
  */
67
73
  update(variantOrVariantId: string | Partial<ProductVariant>, update: UpdateProductVariantInput): Promise<ProductVariant>;
@@ -78,10 +84,10 @@ declare class ProductVariantService extends BaseService {
78
84
  * exists the function will try to use a currency price. If no default
79
85
  * currency price exists the function will throw an error.
80
86
  * @param {string} variantId - the id of the variant to get price from
81
- * @param {string} regionId - the id of the region to get price for
87
+ * @param {GetRegionPriceContext} context - context for getting region price
82
88
  * @return {number} the price specific to the region
83
89
  */
84
- getRegionPrice(variantId: string, regionId: string): Promise<number>;
90
+ getRegionPrice(variantId: string, context: GetRegionPriceContext): Promise<number>;
85
91
  /**
86
92
  * Sets the default price of a specific region
87
93
  * @param {string} variantId - the id of the variant to update
@@ -130,13 +136,13 @@ declare class ProductVariantService extends BaseService {
130
136
  * @param {FindConfig<ProductVariant>} config - query config object for variant retrieval
131
137
  * @return {Promise} the result of the find operation
132
138
  */
133
- listAndCount(selector: FilterableProductVariantProps, config?: FindConfig<ProductVariant>): Promise<[ProductVariant[], number]>;
139
+ listAndCount(selector: FilterableProductVariantProps, config?: FindConfig<ProductVariant> & PriceSelectionContext): Promise<[ProductVariant[], number]>;
134
140
  /**
135
141
  * @param {FilterableProductVariantProps} selector - the query object for find
136
142
  * @param {FindConfig<ProductVariant>} config - query config object for variant retrieval
137
143
  * @return {Promise} the result of the find operation
138
144
  */
139
- list(selector: FilterableProductVariantProps, config?: FindConfig<ProductVariant>): Promise<ProductVariant[]>;
145
+ list(selector: FilterableProductVariantProps, config?: FindConfig<ProductVariant> & PriceSelectionContext): Promise<ProductVariant[]>;
140
146
  /**
141
147
  * Deletes variant.
142
148
  * Will never fail due to delete being idempotent.
@@ -174,5 +180,16 @@ declare class ProductVariantService extends BaseService {
174
180
  * count of products that matches the query as the second element.
175
181
  */
176
182
  getFreeTextQueryBuilder_(variantRepo: ProductVariantRepository, query: FindWithRelationsOptions, q?: string): SelectQueryBuilder<ProductVariant>;
183
+ /**
184
+ * Set additional prices on a list of variants.
185
+ * @param {ProductVariant | ProductVariant[] } variant variant on which to set additional prices
186
+ * @param {string} currency_code currency code to fetch prices for
187
+ * @param {string} region_id region to fetch prices for
188
+ * @param {string} cart_id string of cart to use as a basis for getting currency and region
189
+ * @param {string} customer_id id of potentially logged in customer, used to get prices valid for their customer groups
190
+ * @param {boolean} include_discount_prices should result include discount pricing
191
+ * @return {Promise<ProductVariant | ProductVariant[]>} A list of variants with variants decorated with "additional_prices"
192
+ */
193
+ setAdditionalPrices(variant: any, currency_code: any, region_id: any, cart_id: any, customer_id: any, include_discount_prices?: boolean): Promise<ProductVariant | ProductVariant[]>;
177
194
  }
178
195
  export default ProductVariantService;
@@ -72,17 +72,6 @@ var __rest = (this && this.__rest) || function (s, e) {
72
72
  }
73
73
  return t;
74
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
75
  var __read = (this && this.__read) || function (o, n) {
87
76
  var m = typeof Symbol === "function" && o[Symbol.iterator];
88
77
  if (!m) return o;
@@ -99,6 +88,26 @@ var __read = (this && this.__read) || function (o, n) {
99
88
  }
100
89
  return ar;
101
90
  };
91
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
92
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
93
+ if (ar || !(i in from)) {
94
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
95
+ ar[i] = from[i];
96
+ }
97
+ }
98
+ return to.concat(ar || Array.prototype.slice.call(from));
99
+ };
100
+ var __values = (this && this.__values) || function(o) {
101
+ var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
102
+ if (m) return m.call(o);
103
+ if (o && typeof o.length === "number") return {
104
+ next: function () {
105
+ if (o && i >= o.length) o = void 0;
106
+ return { value: o && o[i++], done: !o };
107
+ }
108
+ };
109
+ throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
110
+ };
102
111
  Object.defineProperty(exports, "__esModule", { value: true });
103
112
  var medusa_core_utils_1 = require("medusa-core-utils");
104
113
  var medusa_interfaces_1 = require("medusa-interfaces");
@@ -110,7 +119,7 @@ var typeorm_1 = require("typeorm");
110
119
  var ProductVariantService = /** @class */ (function (_super) {
111
120
  __extends(ProductVariantService, _super);
112
121
  function ProductVariantService(_a) {
113
- var manager = _a.manager, productVariantRepository = _a.productVariantRepository, productRepository = _a.productRepository, eventBusService = _a.eventBusService, regionService = _a.regionService, moneyAmountRepository = _a.moneyAmountRepository, productOptionValueRepository = _a.productOptionValueRepository;
122
+ var manager = _a.manager, productVariantRepository = _a.productVariantRepository, productRepository = _a.productRepository, eventBusService = _a.eventBusService, regionService = _a.regionService, moneyAmountRepository = _a.moneyAmountRepository, productOptionValueRepository = _a.productOptionValueRepository, cartRepository = _a.cartRepository, priceSelectionStrategy = _a.priceSelectionStrategy;
114
123
  var _this = _super.call(this) || this;
115
124
  /** @private @const {EntityManager} */
116
125
  _this.manager_ = manager;
@@ -124,6 +133,8 @@ var ProductVariantService = /** @class */ (function (_super) {
124
133
  _this.regionService_ = regionService;
125
134
  _this.moneyAmountRepository_ = moneyAmountRepository;
126
135
  _this.productOptionValueRepository_ = productOptionValueRepository;
136
+ _this.cartRepository_ = cartRepository;
137
+ _this.priceSelectionStrategy_ = priceSelectionStrategy;
127
138
  return _this;
128
139
  }
129
140
  ProductVariantService.prototype.withTransaction = function (transactionManager) {
@@ -138,6 +149,8 @@ var ProductVariantService = /** @class */ (function (_super) {
138
149
  regionService: this.regionService_,
139
150
  moneyAmountRepository: this.moneyAmountRepository_,
140
151
  productOptionValueRepository: this.productOptionValueRepository_,
152
+ cartRepository: this.cartRepository_,
153
+ priceSelectionStrategy: this.priceSelectionStrategy_,
141
154
  });
142
155
  cloned.transactionManager_ = transactionManager;
143
156
  return cloned;
@@ -149,22 +162,38 @@ var ProductVariantService = /** @class */ (function (_super) {
149
162
  * @return {Promise<Product>} the product document.
150
163
  */
151
164
  ProductVariantService.prototype.retrieve = function (variantId, config) {
152
- if (config === void 0) { config = {}; }
165
+ var _a, _b;
166
+ if (config === void 0) { config = {
167
+ include_discount_prices: false,
168
+ }; }
153
169
  return __awaiter(this, void 0, void 0, function () {
154
- var variantRepo, validatedId, query, variant;
155
- return __generator(this, function (_a) {
156
- switch (_a.label) {
170
+ var variantRepo, validatedId, priceIndex, query, variant, _c;
171
+ return __generator(this, function (_d) {
172
+ switch (_d.label) {
157
173
  case 0:
158
174
  variantRepo = this.manager_.getCustomRepository(this.productVariantRepository_);
159
175
  validatedId = this.validateId_(variantId);
176
+ priceIndex = (_b = (_a = config.relations) === null || _a === void 0 ? void 0 : _a.indexOf("prices")) !== null && _b !== void 0 ? _b : -1;
177
+ if (priceIndex >= 0 && config.relations) {
178
+ config.relations = __spreadArray([], __read(config.relations), false);
179
+ config.relations.splice(priceIndex, 1);
180
+ }
160
181
  query = this.buildQuery_({ id: validatedId }, config);
161
182
  return [4 /*yield*/, variantRepo.findOne(query)];
162
183
  case 1:
163
- variant = _a.sent();
184
+ variant = _d.sent();
164
185
  if (!variant) {
165
186
  throw new medusa_core_utils_1.MedusaError(medusa_core_utils_1.MedusaError.Types.NOT_FOUND, "Variant with id: ".concat(variantId, " was not found"));
166
187
  }
167
- return [2 /*return*/, variant];
188
+ if (!(priceIndex >= 0)) return [3 /*break*/, 3];
189
+ return [4 /*yield*/, this.setAdditionalPrices(variant, config.currency_code, config.region_id, config.cart_id, config.customer_id, config.include_discount_prices)];
190
+ case 2:
191
+ _c = (_d.sent());
192
+ return [3 /*break*/, 4];
193
+ case 3:
194
+ _c = variant;
195
+ _d.label = 4;
196
+ case 4: return [2 /*return*/, _c];
168
197
  }
169
198
  });
170
199
  });
@@ -176,21 +205,37 @@ var ProductVariantService = /** @class */ (function (_super) {
176
205
  * @return {Promise<Product>} the product document.
177
206
  */
178
207
  ProductVariantService.prototype.retrieveBySKU = function (sku, config) {
179
- if (config === void 0) { config = {}; }
208
+ var _a, _b;
209
+ if (config === void 0) { config = {
210
+ include_discount_prices: false,
211
+ }; }
180
212
  return __awaiter(this, void 0, void 0, function () {
181
- var variantRepo, query, variant;
182
- return __generator(this, function (_a) {
183
- switch (_a.label) {
213
+ var variantRepo, priceIndex, query, variant, _c;
214
+ return __generator(this, function (_d) {
215
+ switch (_d.label) {
184
216
  case 0:
185
217
  variantRepo = this.manager_.getCustomRepository(this.productVariantRepository_);
218
+ priceIndex = (_b = (_a = config.relations) === null || _a === void 0 ? void 0 : _a.indexOf("prices")) !== null && _b !== void 0 ? _b : -1;
219
+ if (priceIndex >= 0 && config.relations) {
220
+ config.relations = __spreadArray([], __read(config.relations), false);
221
+ config.relations.splice(priceIndex, 1);
222
+ }
186
223
  query = this.buildQuery_({ sku: sku }, config);
187
224
  return [4 /*yield*/, variantRepo.findOne(query)];
188
225
  case 1:
189
- variant = _a.sent();
226
+ variant = _d.sent();
190
227
  if (!variant) {
191
228
  throw new medusa_core_utils_1.MedusaError(medusa_core_utils_1.MedusaError.Types.NOT_FOUND, "Variant with sku: ".concat(sku, " was not found"));
192
229
  }
193
- return [2 /*return*/, variant];
230
+ if (!(priceIndex >= 0)) return [3 /*break*/, 3];
231
+ return [4 /*yield*/, this.setAdditionalPrices(variant, config.currency_code, config.region_id, config.cart_id, config.customer_id, config.include_discount_prices)];
232
+ case 2:
233
+ _c = (_d.sent());
234
+ return [3 /*break*/, 4];
235
+ case 3:
236
+ _c = variant;
237
+ _d.label = 4;
238
+ case 4: return [2 /*return*/, _c];
194
239
  }
195
240
  });
196
241
  });
@@ -311,6 +356,7 @@ var ProductVariantService = /** @class */ (function (_super) {
311
356
  * The function will throw, if price updates are attempted.
312
357
  * @param {string | ProductVariant} variantOrVariantId - variant or id of a variant.
313
358
  * @param {object} update - an object with the update values.
359
+ * @param {object} config - an object with the config values for returning the variant.
314
360
  * @return {Promise} resolves to the update result.
315
361
  */
316
362
  ProductVariantService.prototype.update = function (variantOrVariantId, update) {
@@ -318,7 +364,7 @@ var ProductVariantService = /** @class */ (function (_super) {
318
364
  var _this = this;
319
365
  return __generator(this, function (_a) {
320
366
  return [2 /*return*/, this.atomicPhase_(function (manager) { return __awaiter(_this, void 0, void 0, function () {
321
- var variantRepo, variant, prices, options, metadata, inventory_quantity, rest, options_1, options_1_1, option, e_2_1, _a, _b, _c, key, value, result;
367
+ var variantRepo, variant, variantRes, prices, options, metadata, inventory_quantity, rest, options_1, options_1_1, option, e_2_1, _a, _b, _c, key, value, result;
322
368
  var e_2, _d, e_3, _e;
323
369
  return __generator(this, function (_f) {
324
370
  switch (_f.label) {
@@ -326,9 +372,17 @@ var ProductVariantService = /** @class */ (function (_super) {
326
372
  variantRepo = manager.getCustomRepository(this.productVariantRepository_);
327
373
  variant = variantOrVariantId;
328
374
  if (!(typeof variant === "string")) return [3 /*break*/, 2];
329
- return [4 /*yield*/, this.retrieve(variantOrVariantId)];
375
+ return [4 /*yield*/, variantRepo.findOne({
376
+ where: { id: variantOrVariantId },
377
+ })];
330
378
  case 1:
331
- variant = _f.sent();
379
+ variantRes = _f.sent();
380
+ if (typeof variant === "undefined") {
381
+ throw new medusa_core_utils_1.MedusaError(medusa_core_utils_1.MedusaError.Types.NOT_FOUND, "Variant with id ".concat(variantOrVariantId, " was not found"));
382
+ }
383
+ else {
384
+ variant = variantRes;
385
+ }
332
386
  return [3 /*break*/, 3];
333
387
  case 2:
334
388
  if (!variant.id) {
@@ -371,7 +425,7 @@ var ProductVariantService = /** @class */ (function (_super) {
371
425
  finally { if (e_2) throw e_2.error; }
372
426
  return [7 /*endfinally*/];
373
427
  case 13:
374
- if (metadata) {
428
+ if (typeof metadata === "object") {
375
429
  variant.metadata = this.setMetadata_(variant, metadata);
376
430
  }
377
431
  if (typeof inventory_quantity === "number") {
@@ -479,47 +533,34 @@ var ProductVariantService = /** @class */ (function (_super) {
479
533
  * exists the function will try to use a currency price. If no default
480
534
  * currency price exists the function will throw an error.
481
535
  * @param {string} variantId - the id of the variant to get price from
482
- * @param {string} regionId - the id of the region to get price for
536
+ * @param {GetRegionPriceContext} context - context for getting region price
483
537
  * @return {number} the price specific to the region
484
538
  */
485
- ProductVariantService.prototype.getRegionPrice = function (variantId, regionId) {
539
+ ProductVariantService.prototype.getRegionPrice = function (variantId, context) {
486
540
  return __awaiter(this, void 0, void 0, function () {
487
541
  var _this = this;
488
542
  return __generator(this, function (_a) {
489
543
  return [2 /*return*/, this.atomicPhase_(function (manager) { return __awaiter(_this, void 0, void 0, function () {
490
- var moneyAmountRepo, region, moneyAmount;
544
+ var region, prices;
491
545
  return __generator(this, function (_a) {
492
546
  switch (_a.label) {
493
- case 0:
494
- moneyAmountRepo = manager.getCustomRepository(this.moneyAmountRepository_);
495
- return [4 /*yield*/, this.regionService_
496
- .withTransaction(manager)
497
- .retrieve(regionId)
498
- // Find region price based on region id
499
- ];
547
+ case 0: return [4 /*yield*/, this.regionService_
548
+ .withTransaction(manager)
549
+ .retrieve(context.regionId)];
500
550
  case 1:
501
551
  region = _a.sent();
502
- return [4 /*yield*/, moneyAmountRepo.findOne({
503
- where: { region_id: regionId, variant_id: variantId },
504
- })
505
- // If no price could be find based on region id, we try to fetch
506
- // based on the region currency code
507
- ];
508
- case 2:
509
- moneyAmount = _a.sent();
510
- if (!!moneyAmount) return [3 /*break*/, 4];
511
- return [4 /*yield*/, moneyAmountRepo.findOne({
512
- where: { variant_id: variantId, currency_code: region.currency_code },
552
+ return [4 /*yield*/, this.priceSelectionStrategy_
553
+ .withTransaction(manager)
554
+ .calculateVariantPrice(variantId, {
555
+ region_id: context.regionId,
556
+ currency_code: region.currency_code,
557
+ quantity: context.quantity,
558
+ customer_id: context.customer_id,
559
+ include_discount_prices: !!context.include_discount_prices,
513
560
  })];
514
- case 3:
515
- moneyAmount = _a.sent();
516
- _a.label = 4;
517
- case 4:
518
- // Still, if no price is found, we throw
519
- if (!moneyAmount) {
520
- throw new medusa_core_utils_1.MedusaError(medusa_core_utils_1.MedusaError.Types.NOT_FOUND, "A price for region: ".concat(region.name, " could not be found"));
521
- }
522
- return [2 /*return*/, moneyAmount.amount];
561
+ case 2:
562
+ prices = _a.sent();
563
+ return [2 /*return*/, prices.calculatedPrice];
523
564
  }
524
565
  });
525
566
  }); })];
@@ -704,26 +745,48 @@ var ProductVariantService = /** @class */ (function (_super) {
704
745
  * @return {Promise} the result of the find operation
705
746
  */
706
747
  ProductVariantService.prototype.listAndCount = function (selector, config) {
707
- var _a;
708
- if (config === void 0) { config = { relations: [], skip: 0, take: 20 }; }
748
+ var _a, _b, _c;
749
+ if (config === void 0) { config = {
750
+ relations: [],
751
+ skip: 0,
752
+ take: 20,
753
+ include_discount_prices: false,
754
+ }; }
709
755
  return __awaiter(this, void 0, void 0, function () {
710
- var variantRepo, _b, q, query, relations, qb, _c, raw, count, variants;
711
- return __generator(this, function (_d) {
712
- switch (_d.label) {
756
+ var variantRepo, priceIndex, _d, q, query, relations, qb, _e, raw, count_1, variants_1, res, _f, variants, count, res;
757
+ return __generator(this, function (_g) {
758
+ switch (_g.label) {
713
759
  case 0:
714
760
  variantRepo = this.manager_.getCustomRepository(this.productVariantRepository_);
715
- _b = this.prepareListQuery_(selector, config), q = _b.q, query = _b.query, relations = _b.relations;
716
- if (!q) return [3 /*break*/, 3];
761
+ priceIndex = (_b = (_a = config.relations) === null || _a === void 0 ? void 0 : _a.indexOf("prices")) !== null && _b !== void 0 ? _b : -1;
762
+ if (priceIndex >= 0 && config.relations) {
763
+ config.relations = __spreadArray([], __read(config.relations), false);
764
+ config.relations.splice(priceIndex, 1);
765
+ }
766
+ _d = this.prepareListQuery_(selector, config), q = _d.q, query = _d.query, relations = _d.relations;
767
+ if (!q) return [3 /*break*/, 5];
717
768
  qb = this.getFreeTextQueryBuilder_(variantRepo, query, q);
718
769
  return [4 /*yield*/, qb.getManyAndCount()];
719
770
  case 1:
720
- _c = __read.apply(void 0, [_d.sent(), 2]), raw = _c[0], count = _c[1];
721
- return [4 /*yield*/, variantRepo.findWithRelations(relations, raw.map(function (i) { return i.id; }), (_a = query.withDeleted) !== null && _a !== void 0 ? _a : false)];
771
+ _e = __read.apply(void 0, [_g.sent(), 2]), raw = _e[0], count_1 = _e[1];
772
+ return [4 /*yield*/, variantRepo.findWithRelations(relations, raw.map(function (i) { return i.id; }), (_c = query.withDeleted) !== null && _c !== void 0 ? _c : false)];
722
773
  case 2:
723
- variants = _d.sent();
724
- return [2 /*return*/, [variants, count]];
725
- case 3: return [4 /*yield*/, variantRepo.findWithRelationsAndCount(relations, query)];
726
- case 4: return [2 /*return*/, _d.sent()];
774
+ variants_1 = _g.sent();
775
+ if (!(priceIndex >= 0)) return [3 /*break*/, 4];
776
+ return [4 /*yield*/, this.setAdditionalPrices(variants_1, config.currency_code, config.region_id, config.cart_id, config.customer_id, config.include_discount_prices)];
777
+ case 3:
778
+ res = _g.sent();
779
+ return [2 /*return*/, [res, count_1]];
780
+ case 4: return [2 /*return*/, [variants_1, count_1]];
781
+ case 5: return [4 /*yield*/, variantRepo.findWithRelationsAndCount(relations, query)];
782
+ case 6:
783
+ _f = __read.apply(void 0, [_g.sent(), 2]), variants = _f[0], count = _f[1];
784
+ if (!(priceIndex >= 0)) return [3 /*break*/, 8];
785
+ return [4 /*yield*/, this.setAdditionalPrices(variants, config.currency_code, config.region_id, config.cart_id, config.customer_id, config.include_discount_prices)];
786
+ case 7:
787
+ res = _g.sent();
788
+ return [2 /*return*/, [res, count]];
789
+ case 8: return [2 /*return*/, [variants, count]];
727
790
  }
728
791
  });
729
792
  });
@@ -734,13 +797,23 @@ var ProductVariantService = /** @class */ (function (_super) {
734
797
  * @return {Promise} the result of the find operation
735
798
  */
736
799
  ProductVariantService.prototype.list = function (selector, config) {
737
- if (config === void 0) { config = { relations: [], skip: 0, take: 20 }; }
800
+ var _a, _b;
801
+ if (config === void 0) { config = {
802
+ relations: [],
803
+ skip: 0,
804
+ take: 20,
805
+ }; }
738
806
  return __awaiter(this, void 0, void 0, function () {
739
- var productVariantRepo, q, query, where_1;
740
- return __generator(this, function (_a) {
741
- switch (_a.label) {
807
+ var productVariantRepo, priceIndex, q, query, where_1, variants, _c;
808
+ return __generator(this, function (_d) {
809
+ switch (_d.label) {
742
810
  case 0:
743
811
  productVariantRepo = this.manager_.getCustomRepository(this.productVariantRepository_);
812
+ priceIndex = (_b = (_a = config.relations) === null || _a === void 0 ? void 0 : _a.indexOf("prices")) !== null && _b !== void 0 ? _b : -1;
813
+ if (priceIndex >= 0 && config.relations) {
814
+ config.relations = __spreadArray([], __read(config.relations), false);
815
+ config.relations.splice(priceIndex, 1);
816
+ }
744
817
  if ("q" in selector) {
745
818
  q = selector.q;
746
819
  delete selector.q;
@@ -765,7 +838,17 @@ var ProductVariantService = /** @class */ (function (_super) {
765
838
  };
766
839
  }
767
840
  return [4 /*yield*/, productVariantRepo.find(query)];
768
- case 1: return [2 /*return*/, _a.sent()];
841
+ case 1:
842
+ variants = _d.sent();
843
+ if (!(priceIndex >= 0)) return [3 /*break*/, 3];
844
+ return [4 /*yield*/, this.setAdditionalPrices(variants, config.currency_code, config.region_id, config.cart_id, config.customer_id, config.include_discount_prices)];
845
+ case 2:
846
+ _c = (_d.sent());
847
+ return [3 /*break*/, 4];
848
+ case 3:
849
+ _c = variants;
850
+ _d.label = 4;
851
+ case 4: return [2 /*return*/, _c];
769
852
  }
770
853
  });
771
854
  });
@@ -789,7 +872,7 @@ var ProductVariantService = /** @class */ (function (_super) {
789
872
  variantRepo = manager.getCustomRepository(this.productVariantRepository_);
790
873
  return [4 /*yield*/, variantRepo.findOne({
791
874
  where: { id: variantId },
792
- relations: ["prices"],
875
+ relations: ["prices", "options"],
793
876
  })];
794
877
  case 1:
795
878
  variant = _a.sent();
@@ -906,6 +989,69 @@ var ProductVariantService = /** @class */ (function (_super) {
906
989
  }
907
990
  return qb;
908
991
  };
992
+ /**
993
+ * Set additional prices on a list of variants.
994
+ * @param {ProductVariant | ProductVariant[] } variant variant on which to set additional prices
995
+ * @param {string} currency_code currency code to fetch prices for
996
+ * @param {string} region_id region to fetch prices for
997
+ * @param {string} cart_id string of cart to use as a basis for getting currency and region
998
+ * @param {string} customer_id id of potentially logged in customer, used to get prices valid for their customer groups
999
+ * @param {boolean} include_discount_prices should result include discount pricing
1000
+ * @return {Promise<ProductVariant | ProductVariant[]>} A list of variants with variants decorated with "additional_prices"
1001
+ */
1002
+ ProductVariantService.prototype.setAdditionalPrices = function (variant, currency_code, region_id, cart_id, customer_id, include_discount_prices) {
1003
+ if (include_discount_prices === void 0) { include_discount_prices = false; }
1004
+ return __awaiter(this, void 0, void 0, function () {
1005
+ var _this = this;
1006
+ return __generator(this, function (_a) {
1007
+ return [2 /*return*/, this.atomicPhase_(function (manager) { return __awaiter(_this, void 0, void 0, function () {
1008
+ var cartRepo, regionId, currencyCode, cart, variantArray, priceSelectionStrategy, variantsWithPrices;
1009
+ var _this = this;
1010
+ return __generator(this, function (_a) {
1011
+ switch (_a.label) {
1012
+ case 0:
1013
+ cartRepo = manager.getCustomRepository(this.cartRepository_);
1014
+ regionId = region_id;
1015
+ currencyCode = currency_code;
1016
+ if (!cart_id) return [3 /*break*/, 2];
1017
+ return [4 /*yield*/, cartRepo.findOne({
1018
+ where: { id: cart_id },
1019
+ relations: ["region"],
1020
+ })];
1021
+ case 1:
1022
+ cart = _a.sent();
1023
+ regionId = cart.region.id;
1024
+ currencyCode = cart.region.currency_code;
1025
+ _a.label = 2;
1026
+ case 2:
1027
+ variantArray = Array.isArray(variant) ? variant : [variant];
1028
+ priceSelectionStrategy = this.priceSelectionStrategy_.withTransaction(manager);
1029
+ return [4 /*yield*/, Promise.all(variantArray.map(function (v) { return __awaiter(_this, void 0, void 0, function () {
1030
+ var prices;
1031
+ return __generator(this, function (_a) {
1032
+ switch (_a.label) {
1033
+ case 0: return [4 /*yield*/, priceSelectionStrategy.calculateVariantPrice(v.id, {
1034
+ region_id: regionId,
1035
+ currency_code: currencyCode,
1036
+ cart_id: cart_id,
1037
+ customer_id: customer_id,
1038
+ include_discount_prices: include_discount_prices,
1039
+ })];
1040
+ case 1:
1041
+ prices = _a.sent();
1042
+ return [2 /*return*/, __assign(__assign({}, v), { prices: prices.prices, original_price: prices.originalPrice, calculated_price: prices.calculatedPrice, calculated_price_type: prices.calculatedPriceType })];
1043
+ }
1044
+ });
1045
+ }); }))];
1046
+ case 3:
1047
+ variantsWithPrices = _a.sent();
1048
+ return [2 /*return*/, Array.isArray(variant) ? variantsWithPrices : variantsWithPrices[0]];
1049
+ }
1050
+ });
1051
+ }); })];
1052
+ });
1053
+ });
1054
+ };
909
1055
  ProductVariantService.Events = {
910
1056
  UPDATED: "product-variant.updated",
911
1057
  CREATED: "product-variant.created",