@medusajs/medusa 1.2.2-dev.53 → 1.3.1-next.14

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 (450) hide show
  1. package/CHANGELOG.md +48 -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/error-handler.js +1 -1
  6. package/dist/api/routes/admin/auth/create-session.js +5 -5
  7. package/dist/api/routes/admin/auth/create-session.js.map +1 -1
  8. package/dist/api/routes/admin/customer-groups/list-customer-groups.js +2 -2
  9. package/dist/api/routes/admin/customer-groups/list-customer-groups.js.map +1 -1
  10. package/dist/api/routes/admin/discounts/create-condition.d.ts +58 -0
  11. package/dist/api/routes/admin/discounts/create-condition.js +186 -0
  12. package/dist/api/routes/admin/discounts/create-condition.js.map +1 -0
  13. package/dist/api/routes/admin/discounts/create-discount.d.ts +11 -2
  14. package/dist/api/routes/admin/discounts/create-discount.js +65 -12
  15. package/dist/api/routes/admin/discounts/create-discount.js.map +1 -1
  16. package/dist/api/routes/admin/discounts/create-dynamic-code.d.ts +1 -0
  17. package/dist/api/routes/admin/discounts/create-dynamic-code.js +4 -1
  18. package/dist/api/routes/admin/discounts/create-dynamic-code.js.map +1 -1
  19. package/dist/api/routes/admin/discounts/delete-condition.d.ts +36 -0
  20. package/dist/api/routes/admin/discounts/delete-condition.js +151 -0
  21. package/dist/api/routes/admin/discounts/delete-condition.js.map +1 -0
  22. package/dist/api/routes/admin/discounts/delete-dynamic-code.js +3 -1
  23. package/dist/api/routes/admin/discounts/delete-dynamic-code.js.map +1 -1
  24. package/dist/api/routes/admin/discounts/get-discount.d.ts +7 -0
  25. package/dist/api/routes/admin/discounts/get-discount.js +43 -9
  26. package/dist/api/routes/admin/discounts/get-discount.js.map +1 -1
  27. package/dist/api/routes/admin/discounts/index.d.ts +4 -3
  28. package/dist/api/routes/admin/discounts/index.js +8 -6
  29. package/dist/api/routes/admin/discounts/index.js.map +1 -1
  30. package/dist/api/routes/admin/discounts/list-discounts.d.ts +2 -6
  31. package/dist/api/routes/admin/discounts/list-discounts.js +15 -28
  32. package/dist/api/routes/admin/discounts/list-discounts.js.map +1 -1
  33. package/dist/api/routes/admin/discounts/update-condition.d.ts +55 -0
  34. package/dist/api/routes/admin/discounts/update-condition.js +184 -0
  35. package/dist/api/routes/admin/discounts/update-condition.js.map +1 -0
  36. package/dist/api/routes/admin/discounts/update-discount.d.ts +12 -2
  37. package/dist/api/routes/admin/discounts/update-discount.js +70 -15
  38. package/dist/api/routes/admin/discounts/update-discount.js.map +1 -1
  39. package/dist/api/routes/admin/draft-orders/create-draft-order.d.ts +3 -3
  40. package/dist/api/routes/admin/draft-orders/create-draft-order.js.map +1 -1
  41. package/dist/api/routes/admin/draft-orders/create-line-item.d.ts +1 -1
  42. package/dist/api/routes/admin/draft-orders/create-line-item.js.map +1 -1
  43. package/dist/api/routes/admin/draft-orders/index.js +7 -1
  44. package/dist/api/routes/admin/draft-orders/index.js.map +1 -1
  45. package/dist/api/routes/admin/draft-orders/register-payment.js +0 -1
  46. package/dist/api/routes/admin/draft-orders/register-payment.js.map +1 -1
  47. package/dist/api/routes/admin/draft-orders/update-line-item.d.ts +1 -1
  48. package/dist/api/routes/admin/draft-orders/update-line-item.js.map +1 -1
  49. package/dist/api/routes/admin/index.js +21 -19
  50. package/dist/api/routes/admin/index.js.map +1 -1
  51. package/dist/api/routes/admin/notifications/index.js.map +1 -1
  52. package/dist/api/routes/admin/notifications/list-notifications.js.map +1 -1
  53. package/dist/api/routes/admin/notifications/resend-notification.js.map +1 -1
  54. package/dist/api/routes/admin/orders/add-shipping-method.d.ts +1 -1
  55. package/dist/api/routes/admin/orders/add-shipping-method.js.map +1 -1
  56. package/dist/api/routes/admin/orders/create-order.js.map +1 -1
  57. package/dist/api/routes/admin/orders/create-swap.js +7 -3
  58. package/dist/api/routes/admin/orders/create-swap.js.map +1 -1
  59. package/dist/api/routes/admin/orders/index.d.ts +1 -1
  60. package/dist/api/routes/admin/orders/index.js +1 -3
  61. package/dist/api/routes/admin/orders/index.js.map +1 -1
  62. package/dist/api/routes/admin/orders/list-orders.js.map +1 -1
  63. package/dist/api/routes/admin/orders/update-order.js.map +1 -1
  64. package/dist/api/routes/admin/price-lists/add-prices-batch.d.ts +70 -0
  65. package/dist/api/routes/admin/price-lists/add-prices-batch.js +158 -0
  66. package/dist/api/routes/admin/price-lists/add-prices-batch.js.map +1 -0
  67. package/dist/api/routes/admin/price-lists/create-price-list.d.ts +87 -0
  68. package/dist/api/routes/admin/price-lists/create-price-list.js +193 -0
  69. package/dist/api/routes/admin/price-lists/create-price-list.js.map +1 -0
  70. package/dist/api/routes/admin/price-lists/delete-price-list.d.ts +28 -0
  71. package/dist/api/routes/admin/{discounts/remove-valid-product.js → price-lists/delete-price-list.js} +27 -25
  72. package/dist/api/routes/admin/price-lists/delete-price-list.js.map +1 -0
  73. package/dist/api/routes/admin/price-lists/delete-prices-batch.d.ts +43 -0
  74. package/dist/api/routes/{store/carts/update-payment-method.js → admin/price-lists/delete-prices-batch.js} +42 -46
  75. package/dist/api/routes/admin/price-lists/delete-prices-batch.js.map +1 -0
  76. package/dist/api/routes/admin/price-lists/get-price-list.d.ts +22 -0
  77. package/dist/api/routes/admin/{discounts/add-valid-product.js → price-lists/get-price-list.js} +20 -24
  78. package/dist/api/routes/admin/price-lists/get-price-list.js.map +1 -0
  79. package/dist/api/routes/admin/price-lists/index.d.ts +28 -0
  80. package/dist/api/routes/admin/price-lists/index.js +55 -0
  81. package/dist/api/routes/admin/price-lists/index.js.map +1 -0
  82. package/dist/api/routes/admin/price-lists/list-price-list-products.d.ts +74 -0
  83. package/dist/api/routes/admin/price-lists/list-price-list-products.js +287 -0
  84. package/dist/api/routes/admin/price-lists/list-price-list-products.js.map +1 -0
  85. package/dist/api/routes/admin/price-lists/list-price-lists.d.ts +38 -0
  86. package/dist/api/routes/admin/price-lists/list-price-lists.js +197 -0
  87. package/dist/api/routes/admin/price-lists/list-price-lists.js.map +1 -0
  88. package/dist/api/routes/admin/price-lists/update-price-list.d.ts +92 -0
  89. package/dist/api/routes/admin/price-lists/update-price-list.js +211 -0
  90. package/dist/api/routes/admin/price-lists/update-price-list.js.map +1 -0
  91. package/dist/api/routes/admin/products/create-product.d.ts +2 -7
  92. package/dist/api/routes/admin/products/create-product.js +2 -24
  93. package/dist/api/routes/admin/products/create-product.js.map +1 -1
  94. package/dist/api/routes/admin/products/create-variant.d.ts +7 -9
  95. package/dist/api/routes/admin/products/create-variant.js +7 -26
  96. package/dist/api/routes/admin/products/create-variant.js.map +1 -1
  97. package/dist/api/routes/admin/products/index.d.ts +1 -1
  98. package/dist/api/routes/admin/products/index.js +1 -1
  99. package/dist/api/routes/admin/products/index.js.map +1 -1
  100. package/dist/api/routes/admin/products/list-products.d.ts +2 -1
  101. package/dist/api/routes/admin/products/list-products.js +31 -65
  102. package/dist/api/routes/admin/products/list-products.js.map +1 -1
  103. package/dist/api/routes/admin/products/update-product.d.ts +2 -7
  104. package/dist/api/routes/admin/products/update-product.js +2 -24
  105. package/dist/api/routes/admin/products/update-product.js.map +1 -1
  106. package/dist/api/routes/admin/products/update-variant.d.ts +10 -9
  107. package/dist/api/routes/admin/products/update-variant.js +21 -33
  108. package/dist/api/routes/admin/products/update-variant.js.map +1 -1
  109. package/dist/api/routes/admin/regions/index.d.ts +1 -1
  110. package/dist/api/routes/admin/store/get-store.js.map +1 -1
  111. package/dist/api/routes/admin/swaps/index.js +3 -0
  112. package/dist/api/routes/admin/swaps/index.js.map +1 -1
  113. package/dist/api/routes/admin/tax-rates/list-tax-rates.js.map +1 -1
  114. package/dist/api/routes/admin/tax-rates/utils/get-query-config.d.ts +1 -1
  115. package/dist/api/routes/admin/tax-rates/utils/get-query-config.js +4 -2
  116. package/dist/api/routes/admin/tax-rates/utils/get-query-config.js.map +1 -1
  117. package/dist/api/routes/admin/uploads/index.d.ts +1 -1
  118. package/dist/api/routes/store/auth/create-session.js +4 -5
  119. package/dist/api/routes/store/auth/create-session.js.map +1 -1
  120. package/dist/api/routes/store/carts/create-cart.js +8 -5
  121. package/dist/api/routes/store/carts/create-cart.js.map +1 -1
  122. package/dist/api/routes/store/carts/create-line-item.d.ts +1 -1
  123. package/dist/api/routes/store/carts/create-line-item.js +9 -6
  124. package/dist/api/routes/store/carts/create-line-item.js.map +1 -1
  125. package/dist/api/routes/store/carts/index.d.ts +0 -1
  126. package/dist/api/routes/store/carts/index.js +1 -3
  127. package/dist/api/routes/store/carts/index.js.map +1 -1
  128. package/dist/api/routes/store/carts/update-cart.js +7 -7
  129. package/dist/api/routes/store/carts/update-cart.js.map +1 -1
  130. package/dist/api/routes/store/collections/list-collections.d.ts +3 -0
  131. package/dist/api/routes/store/collections/list-collections.js +33 -16
  132. package/dist/api/routes/store/collections/list-collections.js.map +1 -1
  133. package/dist/api/routes/store/customers/create-customer.js +3 -4
  134. package/dist/api/routes/store/customers/create-customer.js.map +1 -1
  135. package/dist/api/routes/store/orders/index.js +0 -2
  136. package/dist/api/routes/store/orders/index.js.map +1 -1
  137. package/dist/api/routes/store/products/get-product.js +17 -5
  138. package/dist/api/routes/store/products/get-product.js.map +1 -1
  139. package/dist/api/routes/store/products/index.d.ts +2 -2
  140. package/dist/api/routes/store/products/list-products.d.ts +2 -2
  141. package/dist/api/routes/store/products/list-products.js +21 -14
  142. package/dist/api/routes/store/products/list-products.js.map +1 -1
  143. package/dist/api/routes/store/products/search.d.ts +1 -1
  144. package/dist/api/routes/store/products/search.js.map +1 -1
  145. package/dist/api/routes/store/regions/list-regions.d.ts +3 -0
  146. package/dist/api/routes/store/regions/list-regions.js +22 -7
  147. package/dist/api/routes/store/regions/list-regions.js.map +1 -1
  148. package/dist/api/routes/store/shipping-options/list-options.js.map +1 -1
  149. package/dist/api/routes/store/swaps/create-swap.js +7 -3
  150. package/dist/api/routes/store/swaps/create-swap.js.map +1 -1
  151. package/dist/api/routes/store/variants/get-variant.js +17 -5
  152. package/dist/api/routes/store/variants/get-variant.js.map +1 -1
  153. package/dist/api/routes/store/variants/list-variants.d.ts +2 -1
  154. package/dist/api/routes/store/variants/list-variants.js +38 -9
  155. package/dist/api/routes/store/variants/list-variants.js.map +1 -1
  156. package/dist/commands/develop.js +2 -2
  157. package/dist/commands/develop.js.map +1 -1
  158. package/dist/controllers/customers/index.d.ts +1 -1
  159. package/dist/controllers/customers/list-customers.d.ts +1 -1
  160. package/dist/controllers/customers/list-customers.js +34 -37
  161. package/dist/controllers/customers/list-customers.js.map +1 -1
  162. package/dist/controllers/products/admin-list-products.d.ts +16 -0
  163. package/dist/controllers/products/admin-list-products.js +103 -0
  164. package/dist/controllers/products/admin-list-products.js.map +1 -0
  165. package/dist/helpers/test-request.js +15 -7
  166. package/dist/helpers/test-request.js.map +1 -1
  167. package/dist/index.d.ts +3 -58
  168. package/dist/index.js +3 -61
  169. package/dist/index.js.map +1 -1
  170. package/dist/interfaces/index.d.ts +1 -0
  171. package/dist/interfaces/index.js +1 -0
  172. package/dist/interfaces/index.js.map +1 -1
  173. package/dist/interfaces/price-selection-strategy.d.ts +50 -0
  174. package/dist/interfaces/price-selection-strategy.js +34 -0
  175. package/dist/interfaces/price-selection-strategy.js.map +1 -0
  176. package/dist/interfaces/tax-service.d.ts +6 -0
  177. package/dist/interfaces/tax-service.js +31 -0
  178. package/dist/interfaces/tax-service.js.map +1 -1
  179. package/dist/interfaces/transaction-base-service.d.ts +23 -0
  180. package/dist/interfaces/transaction-base-service.js +200 -0
  181. package/dist/interfaces/transaction-base-service.js.map +1 -0
  182. package/dist/loaders/api.d.ts +9 -5
  183. package/dist/loaders/api.js +2 -6
  184. package/dist/loaders/api.js.map +1 -1
  185. package/dist/loaders/config.d.ts +3 -0
  186. package/dist/loaders/config.js +47 -0
  187. package/dist/loaders/config.js.map +1 -0
  188. package/dist/loaders/database.d.ts +8 -4
  189. package/dist/loaders/database.js.map +1 -1
  190. package/dist/loaders/defaults.d.ts +4 -3
  191. package/dist/loaders/defaults.js +39 -31
  192. package/dist/loaders/defaults.js.map +1 -1
  193. package/dist/loaders/express.d.ts +7 -4
  194. package/dist/loaders/express.js +7 -5
  195. package/dist/loaders/express.js.map +1 -1
  196. package/dist/loaders/index.d.ts +13 -8
  197. package/dist/loaders/index.js +29 -54
  198. package/dist/loaders/index.js.map +1 -1
  199. package/dist/loaders/logger.d.ts +1 -0
  200. package/dist/loaders/logger.js.map +1 -1
  201. package/dist/loaders/models.d.ts +8 -3
  202. package/dist/loaders/models.js +19 -17
  203. package/dist/loaders/models.js.map +1 -1
  204. package/dist/loaders/passport.d.ts +7 -4
  205. package/dist/loaders/passport.js +23 -21
  206. package/dist/loaders/passport.js.map +1 -1
  207. package/dist/loaders/plugins.d.ts +38 -10
  208. package/dist/loaders/plugins.js +30 -26
  209. package/dist/loaders/plugins.js.map +1 -1
  210. package/dist/loaders/redis.d.ts +8 -5
  211. package/dist/loaders/redis.js +3 -3
  212. package/dist/loaders/redis.js.map +1 -1
  213. package/dist/loaders/repositories.d.ts +7 -3
  214. package/dist/loaders/repositories.js +1 -1
  215. package/dist/loaders/repositories.js.map +1 -1
  216. package/dist/loaders/search-index.d.ts +4 -3
  217. package/dist/loaders/search-index.js.map +1 -1
  218. package/dist/loaders/services.d.ts +10 -5
  219. package/dist/loaders/services.js.map +1 -1
  220. package/dist/loaders/strategies.d.ts +1 -1
  221. package/dist/loaders/subscribers.d.ts +7 -3
  222. package/dist/loaders/subscribers.js.map +1 -1
  223. package/dist/migrations/1646324713514-discount_conditions.d.ts +6 -0
  224. package/dist/migrations/1646324713514-discount_conditions.js +335 -0
  225. package/dist/migrations/1646324713514-discount_conditions.js.map +1 -0
  226. package/dist/migrations/1646915480108-update_money_amount_add_price_list.d.ts +6 -0
  227. package/dist/migrations/1646915480108-update_money_amount_add_price_list.js +143 -0
  228. package/dist/migrations/1646915480108-update_money_amount_add_price_list.js.map +1 -0
  229. package/dist/migrations/1648600574750-add_line_item_adjustments.d.ts +6 -0
  230. package/dist/migrations/1648600574750-add_line_item_adjustments.js +101 -0
  231. package/dist/migrations/1648600574750-add_line_item_adjustments.js.map +1 -0
  232. package/dist/migrations/1648641130007-tax_line_constraints.d.ts +6 -0
  233. package/dist/migrations/1648641130007-tax_line_constraints.js +77 -0
  234. package/dist/migrations/1648641130007-tax_line_constraints.js.map +1 -0
  235. package/dist/migrations/1649775522087-add_batch_job_model.d.ts +6 -0
  236. package/dist/migrations/1649775522087-add_batch_job_model.js +77 -0
  237. package/dist/migrations/1649775522087-add_batch_job_model.js.map +1 -0
  238. package/dist/models/batch-job.d.ts +58 -0
  239. package/dist/models/batch-job.js +119 -0
  240. package/dist/models/batch-job.js.map +1 -0
  241. package/dist/models/country.d.ts +1 -1
  242. package/dist/models/country.js +1 -1
  243. package/dist/models/country.js.map +1 -1
  244. package/dist/models/customer-group.d.ts +3 -1
  245. package/dist/models/customer-group.js +9 -13
  246. package/dist/models/customer-group.js.map +1 -1
  247. package/dist/models/discount-condition-customer-group.d.ts +39 -0
  248. package/dist/models/discount-condition-customer-group.js +84 -0
  249. package/dist/models/discount-condition-customer-group.js.map +1 -0
  250. package/dist/models/discount-condition-product-collection.d.ts +39 -0
  251. package/dist/models/discount-condition-product-collection.js +84 -0
  252. package/dist/models/discount-condition-product-collection.js.map +1 -0
  253. package/dist/models/discount-condition-product-tag.d.ts +39 -0
  254. package/dist/models/discount-condition-product-tag.js +84 -0
  255. package/dist/models/discount-condition-product-tag.js.map +1 -0
  256. package/dist/models/discount-condition-product-type.d.ts +39 -0
  257. package/dist/models/discount-condition-product-type.js +84 -0
  258. package/dist/models/discount-condition-product-type.js.map +1 -0
  259. package/dist/models/discount-condition-product.d.ts +39 -0
  260. package/dist/models/discount-condition-product.js +84 -0
  261. package/dist/models/discount-condition-product.js.map +1 -0
  262. package/dist/models/discount-condition.d.ts +68 -0
  263. package/dist/models/discount-condition.js +211 -0
  264. package/dist/models/discount-condition.js.map +1 -0
  265. package/dist/models/discount-rule.d.ts +5 -5
  266. package/dist/models/discount-rule.js +6 -17
  267. package/dist/models/discount-rule.js.map +1 -1
  268. package/dist/models/discount.js.map +1 -1
  269. package/dist/models/index.d.ts +66 -0
  270. package/dist/models/index.js +79 -0
  271. package/dist/models/index.js.map +1 -0
  272. package/dist/models/line-item-adjustment.d.ts +13 -0
  273. package/dist/models/line-item-adjustment.js +79 -0
  274. package/dist/models/line-item-adjustment.js.map +1 -0
  275. package/dist/models/line-item-tax-line.js +2 -1
  276. package/dist/models/line-item-tax-line.js.map +1 -1
  277. package/dist/models/line-item.d.ts +2 -0
  278. package/dist/models/line-item.js +5 -0
  279. package/dist/models/line-item.js.map +1 -1
  280. package/dist/models/money-amount.d.ts +10 -3
  281. package/dist/models/money-amount.js +25 -5
  282. package/dist/models/money-amount.js.map +1 -1
  283. package/dist/models/price-list.d.ts +57 -0
  284. package/dist/models/price-list.js +146 -0
  285. package/dist/models/price-list.js.map +1 -0
  286. package/dist/models/product-variant.js +9 -3
  287. package/dist/models/product-variant.js.map +1 -1
  288. package/dist/models/shipping-method-tax-line.js +2 -1
  289. package/dist/models/shipping-method-tax-line.js.map +1 -1
  290. package/dist/models/swap.d.ts +4 -4
  291. package/dist/models/swap.js +23 -23
  292. package/dist/models/swap.js.map +1 -1
  293. package/dist/repositories/cart.d.ts +2 -2
  294. package/dist/repositories/cart.js.map +1 -1
  295. package/dist/repositories/customer.d.ts +1 -1
  296. package/dist/repositories/customer.js +7 -9
  297. package/dist/repositories/customer.js.map +1 -1
  298. package/dist/repositories/discount-condition.d.ts +38 -0
  299. package/dist/repositories/discount-condition.js +397 -0
  300. package/dist/repositories/discount-condition.js.map +1 -0
  301. package/dist/repositories/line-item-adjustment.d.ts +4 -0
  302. package/dist/repositories/line-item-adjustment.js +38 -0
  303. package/dist/repositories/line-item-adjustment.js.map +1 -0
  304. package/dist/repositories/line-item-tax-line.d.ts +2 -0
  305. package/dist/repositories/line-item-tax-line.js +80 -0
  306. package/dist/repositories/line-item-tax-line.js.map +1 -1
  307. package/dist/repositories/line-item.js +1 -0
  308. package/dist/repositories/line-item.js.map +1 -1
  309. package/dist/repositories/money-amount.d.ts +8 -2
  310. package/dist/repositories/money-amount.js +171 -2
  311. package/dist/repositories/money-amount.js.map +1 -1
  312. package/dist/repositories/order.d.ts +1 -1
  313. package/dist/repositories/price-list.d.ts +11 -0
  314. package/dist/repositories/price-list.js +247 -0
  315. package/dist/repositories/price-list.js.map +1 -0
  316. package/dist/repositories/product.d.ts +2 -0
  317. package/dist/repositories/product.js +35 -17
  318. package/dist/repositories/product.js.map +1 -1
  319. package/dist/repositories/shipping-method-tax-line.d.ts +2 -0
  320. package/dist/repositories/shipping-method-tax-line.js +80 -0
  321. package/dist/repositories/shipping-method-tax-line.js.map +1 -1
  322. package/dist/scripts/discount-rule-migration.d.ts +4 -0
  323. package/dist/scripts/discount-rule-migration.js +177 -0
  324. package/dist/scripts/discount-rule-migration.js.map +1 -0
  325. package/dist/scripts/line-item-adjustment-migration.d.ts +4 -0
  326. package/dist/scripts/line-item-adjustment-migration.js +173 -0
  327. package/dist/scripts/line-item-adjustment-migration.js.map +1 -0
  328. package/dist/services/cart.d.ts +64 -53
  329. package/dist/services/cart.js +1297 -1410
  330. package/dist/services/cart.js.map +1 -1
  331. package/dist/services/customer.js +4 -2
  332. package/dist/services/customer.js.map +1 -1
  333. package/dist/services/discount-condition.d.ts +31 -0
  334. package/dist/services/discount-condition.js +223 -0
  335. package/dist/services/discount-condition.js.map +1 -0
  336. package/dist/services/discount.d.ts +46 -58
  337. package/dist/services/discount.js +249 -140
  338. package/dist/services/discount.js.map +1 -1
  339. package/dist/services/draft-order.js +1 -0
  340. package/dist/services/draft-order.js.map +1 -1
  341. package/dist/services/fulfillment-provider.js +23 -17
  342. package/dist/services/fulfillment-provider.js.map +1 -1
  343. package/dist/services/invite.d.ts +4 -2
  344. package/dist/services/invite.js +11 -9
  345. package/dist/services/invite.js.map +1 -1
  346. package/dist/services/line-item-adjustment.d.ts +87 -0
  347. package/dist/services/line-item-adjustment.js +436 -0
  348. package/dist/services/line-item-adjustment.js.map +1 -0
  349. package/dist/services/line-item.d.ts +48 -40
  350. package/dist/services/line-item.js +226 -193
  351. package/dist/services/line-item.js.map +1 -1
  352. package/dist/services/order.js +4 -4
  353. package/dist/services/order.js.map +1 -1
  354. package/dist/services/payment-provider.js +23 -17
  355. package/dist/services/payment-provider.js.map +1 -1
  356. package/dist/services/price-list.d.ts +100 -0
  357. package/dist/services/price-list.js +626 -0
  358. package/dist/services/price-list.js.map +1 -0
  359. package/dist/services/product-variant.d.ts +40 -16
  360. package/dist/services/product-variant.js +259 -109
  361. package/dist/services/product-variant.js.map +1 -1
  362. package/dist/services/product.d.ts +22 -4
  363. package/dist/services/product.js +238 -50
  364. package/dist/services/product.js.map +1 -1
  365. package/dist/services/region.js +8 -4
  366. package/dist/services/region.js.map +1 -1
  367. package/dist/services/return.js +0 -1
  368. package/dist/services/return.js.map +1 -1
  369. package/dist/services/shipping-option.d.ts +2 -2
  370. package/dist/services/shipping-option.js +7 -4
  371. package/dist/services/shipping-option.js.map +1 -1
  372. package/dist/services/swap.d.ts +4 -1
  373. package/dist/services/swap.js +29 -16
  374. package/dist/services/swap.js.map +1 -1
  375. package/dist/services/system-tax.d.ts +2 -3
  376. package/dist/services/system-tax.js +2 -2
  377. package/dist/services/system-tax.js.map +1 -1
  378. package/dist/services/tax-provider.d.ts +2 -0
  379. package/dist/services/tax-provider.js +96 -7
  380. package/dist/services/tax-provider.js.map +1 -1
  381. package/dist/services/tax-rate.d.ts +3 -3
  382. package/dist/services/tax-rate.js +1 -1
  383. package/dist/services/tax-rate.js.map +1 -1
  384. package/dist/services/totals.d.ts +9 -8
  385. package/dist/services/totals.js +41 -88
  386. package/dist/services/totals.js.map +1 -1
  387. package/dist/strategies/price-selection.d.ts +13 -0
  388. package/dist/strategies/price-selection.js +185 -0
  389. package/dist/strategies/price-selection.js.map +1 -0
  390. package/dist/subscribers/order.js +1 -7
  391. package/dist/subscribers/order.js.map +1 -1
  392. package/dist/types/batch-job.d.ts +6 -0
  393. package/dist/types/batch-job.js +11 -0
  394. package/dist/types/batch-job.js.map +1 -0
  395. package/dist/types/cart.d.ts +1 -1
  396. package/dist/types/common.d.ts +20 -2
  397. package/dist/types/common.js.map +1 -1
  398. package/dist/types/discount.d.ts +70 -1
  399. package/dist/types/discount.js +129 -5
  400. package/dist/types/discount.js.map +1 -1
  401. package/dist/types/global.d.ts +34 -0
  402. package/dist/types/global.js +3 -0
  403. package/dist/types/global.js.map +1 -0
  404. package/dist/types/line-item-adjustment.d.ts +9 -0
  405. package/dist/types/line-item-adjustment.js +50 -0
  406. package/dist/types/line-item-adjustment.js.map +1 -0
  407. package/dist/types/price-list.d.ts +71 -0
  408. package/dist/types/price-list.js +157 -0
  409. package/dist/types/price-list.js.map +1 -0
  410. package/dist/types/price-selection.d.ts +5 -0
  411. package/dist/types/price-selection.js +35 -0
  412. package/dist/types/price-selection.js.map +1 -0
  413. package/dist/types/product-variant.d.ts +24 -1
  414. package/dist/types/product-variant.js +65 -1
  415. package/dist/types/product-variant.js.map +1 -1
  416. package/dist/types/product.d.ts +16 -0
  417. package/dist/types/product.js +86 -1
  418. package/dist/types/product.js.map +1 -1
  419. package/dist/types/validators/exactly-one.d.ts +6 -0
  420. package/dist/types/validators/exactly-one.js +37 -0
  421. package/dist/types/validators/exactly-one.js.map +1 -0
  422. package/dist/utils/build-query.d.ts +8 -0
  423. package/dist/utils/build-query.js +114 -0
  424. package/dist/utils/build-query.js.map +1 -0
  425. package/dist/utils/date-helpers.d.ts +2 -0
  426. package/dist/utils/date-helpers.js +15 -0
  427. package/dist/utils/date-helpers.js.map +1 -0
  428. package/dist/utils/get-query-config.d.ts +11 -0
  429. package/dist/utils/get-query-config.js +88 -0
  430. package/dist/utils/get-query-config.js.map +1 -0
  431. package/dist/utils/index.d.ts +3 -0
  432. package/dist/utils/index.js +16 -0
  433. package/dist/utils/index.js.map +1 -0
  434. package/dist/utils/set-metadata.d.ts +9 -0
  435. package/dist/utils/set-metadata.js +72 -0
  436. package/dist/utils/set-metadata.js.map +1 -0
  437. package/dist/utils/validate-id.d.ts +4 -0
  438. package/dist/utils/validate-id.js +47 -0
  439. package/dist/utils/validate-id.js.map +1 -0
  440. package/package.json +7 -8
  441. package/dist/api/routes/admin/discounts/add-valid-product.d.ts +0 -23
  442. package/dist/api/routes/admin/discounts/add-valid-product.js.map +0 -1
  443. package/dist/api/routes/admin/discounts/remove-valid-product.d.ts +0 -23
  444. package/dist/api/routes/admin/discounts/remove-valid-product.js.map +0 -1
  445. package/dist/api/routes/store/carts/update-payment-method.d.ts +0 -38
  446. package/dist/api/routes/store/carts/update-payment-method.js.map +0 -1
  447. package/dist/config/index.d.ts +0 -14
  448. package/dist/config/index.js +0 -40
  449. package/dist/config/index.js.map +0 -1
  450. package/yarn-error.log +0 -6769
@@ -1 +1 @@
1
- {"version":3,"file":"customer.js","sourceRoot":"","sources":["../../src/repositories/customer.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,mCAAsD;AACtD,+CAA6C;AAG7C;IAAwC,sCAAoB;IAA5D;;IAwBA,CAAC;IAvBO,yCAAY,GAAlB,UAAmB,KAAK;;;;;;;wBAChB,MAAM,GAAG,MAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,KAAK,0CAAE,MAAM,CAAA;wBAC5B,MAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,KAAK,+CAAE,MAAM,CAAA;wBAEvB,EAAE,GAAG,IAAI,CAAC,kBAAkB,CAAC,UAAU,CAAC;6BACzC,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC;6BAClB,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC;6BAChB,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;wBAEnB,IAAI,MAAM,EAAE;4BACV,EAAE,GAAG,EAAE;iCACJ,iBAAiB,CAAC,iBAAiB,EAAE,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;wBAED,IAAI,MAAA,KAAK,CAAC,SAAS,0CAAE,MAAM,EAAE;4BAC3B,KAAK,CAAC,SAAS,CAAC,OAAO,CAAC,UAAC,GAAG;gCAC1B,EAAE,GAAG,EAAE,CAAC,iBAAiB,CAAC,mBAAY,GAAG,CAAE,EAAE,GAAG,CAAC,CAAA;4BACnD,CAAC,CAAC,CAAA;yBACH;wBAEM,qBAAM,EAAE,CAAC,eAAe,EAAE,EAAA;4BAAjC,sBAAO,SAA0B,EAAA;;;;KAClC;IApBU,kBAAkB;QAD9B,IAAA,0BAAgB,EAAC,mBAAQ,CAAC;OACd,kBAAkB,CAqB9B;IAAD,yBAAC;CAAA,AArBD,CAAwC,oBAAU,GAqBjD;AArBY,gDAAkB"}
@@ -0,0 +1,38 @@
1
+ import { DeleteResult, EntityTarget, Repository } from "typeorm";
2
+ import { Discount } from "../models";
3
+ import { DiscountCondition, DiscountConditionType } from "../models/discount-condition";
4
+ import { DiscountConditionCustomerGroup } from "../models/discount-condition-customer-group";
5
+ import { DiscountConditionProduct } from "../models/discount-condition-product";
6
+ import { DiscountConditionProductCollection } from "../models/discount-condition-product-collection";
7
+ import { DiscountConditionProductTag } from "../models/discount-condition-product-tag";
8
+ import { DiscountConditionProductType } from "../models/discount-condition-product-type";
9
+ export declare enum DiscountConditionJoinTableForeignKey {
10
+ PRODUCT_ID = "product_id",
11
+ PRODUCT_TYPE_ID = "product_type_id",
12
+ PRODUCT_COLLECTION_ID = "product_collection_id",
13
+ PRODUCT_TAG_ID = "product_tag_id",
14
+ CUSTOMER_GROUP_ID = "customer_group_id"
15
+ }
16
+ declare type DiscountConditionResourceType = EntityTarget<DiscountConditionProduct | DiscountConditionProductType | DiscountConditionProductCollection | DiscountConditionProductTag | DiscountConditionCustomerGroup>;
17
+ export declare class DiscountConditionRepository extends Repository<DiscountCondition> {
18
+ findOneWithDiscount(conditionId: string, discountId: string): Promise<(DiscountCondition & {
19
+ discount: Discount;
20
+ }) | undefined>;
21
+ getJoinTableResourceIdentifiers(type: string): {
22
+ joinTable: string;
23
+ resourceKey: string;
24
+ joinTableForeignKey: DiscountConditionJoinTableForeignKey;
25
+ conditionTable: DiscountConditionResourceType;
26
+ joinTableKey: string;
27
+ };
28
+ removeConditionResources(id: string, type: DiscountConditionType, resourceIds: string[]): Promise<DeleteResult | void>;
29
+ addConditionResources(conditionId: string, resourceIds: string[], type: DiscountConditionType, overrideExisting?: boolean): Promise<(DiscountConditionProduct | DiscountConditionProductType | DiscountConditionProductCollection | DiscountConditionProductTag | DiscountConditionCustomerGroup)[]>;
30
+ queryConditionTable({ type, condId, resourceId }: {
31
+ type: any;
32
+ condId: any;
33
+ resourceId: any;
34
+ }): Promise<number>;
35
+ isValidForProduct(discountRuleId: string, productId: string): Promise<boolean>;
36
+ canApplyForCustomer(discountRuleId: string, customerId: string): Promise<boolean>;
37
+ }
38
+ export {};
@@ -0,0 +1,397 @@
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 __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
18
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
19
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
20
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
21
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
22
+ };
23
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
24
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
25
+ return new (P || (P = Promise))(function (resolve, reject) {
26
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
27
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
28
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
29
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
30
+ });
31
+ };
32
+ var __generator = (this && this.__generator) || function (thisArg, body) {
33
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
34
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
35
+ function verb(n) { return function (v) { return step([n, v]); }; }
36
+ function step(op) {
37
+ if (f) throw new TypeError("Generator is already executing.");
38
+ while (_) try {
39
+ 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;
40
+ if (y = 0, t) op = [op[0] & 2, t.value];
41
+ switch (op[0]) {
42
+ case 0: case 1: t = op; break;
43
+ case 4: _.label++; return { value: op[1], done: false };
44
+ case 5: _.label++; y = op[1]; op = [0]; continue;
45
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
46
+ default:
47
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
48
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
49
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
50
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
51
+ if (t[2]) _.ops.pop();
52
+ _.trys.pop(); continue;
53
+ }
54
+ op = body.call(thisArg, _);
55
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
56
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
57
+ }
58
+ };
59
+ var __values = (this && this.__values) || function(o) {
60
+ var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
61
+ if (m) return m.call(o);
62
+ if (o && typeof o.length === "number") return {
63
+ next: function () {
64
+ if (o && i >= o.length) o = void 0;
65
+ return { value: o && o[i++], done: !o };
66
+ }
67
+ };
68
+ throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
69
+ };
70
+ Object.defineProperty(exports, "__esModule", { value: true });
71
+ exports.DiscountConditionRepository = exports.DiscountConditionJoinTableForeignKey = void 0;
72
+ var typeorm_1 = require("typeorm");
73
+ var models_1 = require("../models");
74
+ var discount_condition_1 = require("../models/discount-condition");
75
+ var discount_condition_customer_group_1 = require("../models/discount-condition-customer-group");
76
+ var discount_condition_product_1 = require("../models/discount-condition-product");
77
+ var discount_condition_product_collection_1 = require("../models/discount-condition-product-collection");
78
+ var discount_condition_product_tag_1 = require("../models/discount-condition-product-tag");
79
+ var discount_condition_product_type_1 = require("../models/discount-condition-product-type");
80
+ var DiscountConditionJoinTableForeignKey;
81
+ (function (DiscountConditionJoinTableForeignKey) {
82
+ DiscountConditionJoinTableForeignKey["PRODUCT_ID"] = "product_id";
83
+ DiscountConditionJoinTableForeignKey["PRODUCT_TYPE_ID"] = "product_type_id";
84
+ DiscountConditionJoinTableForeignKey["PRODUCT_COLLECTION_ID"] = "product_collection_id";
85
+ DiscountConditionJoinTableForeignKey["PRODUCT_TAG_ID"] = "product_tag_id";
86
+ DiscountConditionJoinTableForeignKey["CUSTOMER_GROUP_ID"] = "customer_group_id";
87
+ })(DiscountConditionJoinTableForeignKey = exports.DiscountConditionJoinTableForeignKey || (exports.DiscountConditionJoinTableForeignKey = {}));
88
+ var DiscountConditionRepository = /** @class */ (function (_super) {
89
+ __extends(DiscountConditionRepository, _super);
90
+ function DiscountConditionRepository() {
91
+ return _super !== null && _super.apply(this, arguments) || this;
92
+ }
93
+ DiscountConditionRepository.prototype.findOneWithDiscount = function (conditionId, discountId) {
94
+ return __awaiter(this, void 0, void 0, function () {
95
+ return __generator(this, function (_a) {
96
+ switch (_a.label) {
97
+ case 0: return [4 /*yield*/, this.createQueryBuilder("condition")
98
+ .leftJoinAndMapOne("condition.discount", models_1.Discount, "discount", "condition.discount_rule_id = discount.rule_id and discount.id = :discId and condition.id = :dcId", { discId: discountId, dcId: conditionId })
99
+ .getOne()];
100
+ case 1: return [2 /*return*/, (_a.sent())];
101
+ }
102
+ });
103
+ });
104
+ };
105
+ DiscountConditionRepository.prototype.getJoinTableResourceIdentifiers = function (type) {
106
+ var conditionTable = discount_condition_product_1.DiscountConditionProduct;
107
+ var joinTable = "product";
108
+ var joinTableForeignKey = DiscountConditionJoinTableForeignKey.PRODUCT_ID;
109
+ var joinTableKey = "id";
110
+ // On the joined table (e.g. `product`), what key should be match on
111
+ // (e.g `type_id` for product types and `id` for products)
112
+ var resourceKey;
113
+ switch (type) {
114
+ case discount_condition_1.DiscountConditionType.PRODUCTS: {
115
+ resourceKey = "id";
116
+ joinTableForeignKey = DiscountConditionJoinTableForeignKey.PRODUCT_ID;
117
+ joinTable = "product";
118
+ conditionTable = discount_condition_product_1.DiscountConditionProduct;
119
+ break;
120
+ }
121
+ case discount_condition_1.DiscountConditionType.PRODUCT_TYPES: {
122
+ resourceKey = "type_id";
123
+ joinTableForeignKey =
124
+ DiscountConditionJoinTableForeignKey.PRODUCT_TYPE_ID;
125
+ joinTable = "product";
126
+ conditionTable = discount_condition_product_type_1.DiscountConditionProductType;
127
+ break;
128
+ }
129
+ case discount_condition_1.DiscountConditionType.PRODUCT_COLLECTIONS: {
130
+ resourceKey = "collection_id";
131
+ joinTableForeignKey =
132
+ DiscountConditionJoinTableForeignKey.PRODUCT_COLLECTION_ID;
133
+ joinTable = "product";
134
+ conditionTable = discount_condition_product_collection_1.DiscountConditionProductCollection;
135
+ break;
136
+ }
137
+ case discount_condition_1.DiscountConditionType.PRODUCT_TAGS: {
138
+ joinTableKey = "product_id";
139
+ resourceKey = "product_tag_id";
140
+ joinTableForeignKey =
141
+ DiscountConditionJoinTableForeignKey.PRODUCT_TAG_ID;
142
+ joinTable = "product_tags";
143
+ conditionTable = discount_condition_product_tag_1.DiscountConditionProductTag;
144
+ break;
145
+ }
146
+ case discount_condition_1.DiscountConditionType.CUSTOMER_GROUPS: {
147
+ joinTableKey = "customer_id";
148
+ resourceKey = "customer_group_id";
149
+ joinTable = "customer_group_customers";
150
+ joinTableForeignKey =
151
+ DiscountConditionJoinTableForeignKey.CUSTOMER_GROUP_ID;
152
+ conditionTable = discount_condition_customer_group_1.DiscountConditionCustomerGroup;
153
+ break;
154
+ }
155
+ default:
156
+ break;
157
+ }
158
+ return {
159
+ joinTable: joinTable,
160
+ joinTableKey: joinTableKey,
161
+ resourceKey: resourceKey,
162
+ joinTableForeignKey: joinTableForeignKey,
163
+ conditionTable: conditionTable,
164
+ };
165
+ };
166
+ DiscountConditionRepository.prototype.removeConditionResources = function (id, type, resourceIds) {
167
+ return __awaiter(this, void 0, void 0, function () {
168
+ var _a, conditionTable, joinTableForeignKey;
169
+ var _b;
170
+ return __generator(this, function (_c) {
171
+ switch (_c.label) {
172
+ case 0:
173
+ _a = this.getJoinTableResourceIdentifiers(type), conditionTable = _a.conditionTable, joinTableForeignKey = _a.joinTableForeignKey;
174
+ if (!conditionTable || !joinTableForeignKey) {
175
+ return [2 /*return*/, Promise.resolve()];
176
+ }
177
+ return [4 /*yield*/, this.createQueryBuilder()
178
+ .delete()
179
+ .from(conditionTable)
180
+ .where((_b = { condition_id: id }, _b[joinTableForeignKey] = (0, typeorm_1.In)(resourceIds), _b))
181
+ .execute()];
182
+ case 1: return [2 /*return*/, _c.sent()];
183
+ }
184
+ });
185
+ });
186
+ };
187
+ DiscountConditionRepository.prototype.addConditionResources = function (conditionId, resourceIds, type, overrideExisting) {
188
+ if (overrideExisting === void 0) { overrideExisting = false; }
189
+ return __awaiter(this, void 0, void 0, function () {
190
+ var toInsert, _a, conditionTable, joinTableForeignKey, insertResult;
191
+ var _b;
192
+ return __generator(this, function (_c) {
193
+ switch (_c.label) {
194
+ case 0:
195
+ toInsert = [];
196
+ _a = this.getJoinTableResourceIdentifiers(type), conditionTable = _a.conditionTable, joinTableForeignKey = _a.joinTableForeignKey;
197
+ if (!conditionTable || !joinTableForeignKey) {
198
+ return [2 /*return*/, Promise.resolve([])];
199
+ }
200
+ toInsert = resourceIds.map(function (rId) {
201
+ var _a;
202
+ return (_a = {
203
+ condition_id: conditionId
204
+ },
205
+ _a[joinTableForeignKey] = rId,
206
+ _a);
207
+ });
208
+ return [4 /*yield*/, this.createQueryBuilder()
209
+ .insert()
210
+ .orIgnore(true)
211
+ .into(conditionTable)
212
+ .values(toInsert)
213
+ .execute()];
214
+ case 1:
215
+ insertResult = _c.sent();
216
+ if (!overrideExisting) return [3 /*break*/, 3];
217
+ return [4 /*yield*/, this.createQueryBuilder()
218
+ .delete()
219
+ .from(conditionTable)
220
+ .where((_b = {
221
+ condition_id: conditionId
222
+ },
223
+ _b[joinTableForeignKey] = (0, typeorm_1.Not)((0, typeorm_1.In)(resourceIds)),
224
+ _b))
225
+ .execute()];
226
+ case 2:
227
+ _c.sent();
228
+ _c.label = 3;
229
+ case 3: return [4 /*yield*/, this.manager
230
+ .createQueryBuilder(conditionTable, "discon")
231
+ .select()
232
+ .where(insertResult.identifiers)
233
+ .getMany()];
234
+ case 4: return [2 /*return*/, _c.sent()];
235
+ }
236
+ });
237
+ });
238
+ };
239
+ DiscountConditionRepository.prototype.queryConditionTable = function (_a) {
240
+ var type = _a.type, condId = _a.condId, resourceId = _a.resourceId;
241
+ return __awaiter(this, void 0, void 0, function () {
242
+ var _b, conditionTable, joinTable, joinTableForeignKey, resourceKey, joinTableKey;
243
+ return __generator(this, function (_c) {
244
+ switch (_c.label) {
245
+ case 0:
246
+ _b = this.getJoinTableResourceIdentifiers(type), conditionTable = _b.conditionTable, joinTable = _b.joinTable, joinTableForeignKey = _b.joinTableForeignKey, resourceKey = _b.resourceKey, joinTableKey = _b.joinTableKey;
247
+ return [4 /*yield*/, this.manager
248
+ .createQueryBuilder(conditionTable, "dc")
249
+ .innerJoin(joinTable, "resource", "dc.".concat(joinTableForeignKey, " = resource.").concat(resourceKey, " and resource.").concat(joinTableKey, " = :resourceId "), {
250
+ resourceId: resourceId,
251
+ })
252
+ .where("dc.condition_id = :conditionId", {
253
+ conditionId: condId,
254
+ })
255
+ .getCount()];
256
+ case 1: return [2 /*return*/, _c.sent()];
257
+ }
258
+ });
259
+ });
260
+ };
261
+ DiscountConditionRepository.prototype.isValidForProduct = function (discountRuleId, productId) {
262
+ return __awaiter(this, void 0, void 0, function () {
263
+ var discountConditions, discountConditions_1, discountConditions_1_1, condition, numConditions, e_1_1;
264
+ var e_1, _a;
265
+ return __generator(this, function (_b) {
266
+ switch (_b.label) {
267
+ case 0: return [4 /*yield*/, this.createQueryBuilder("discon")
268
+ .select(["discon.id", "discon.type", "discon.operator"])
269
+ .where("discon.discount_rule_id = :discountRuleId", {
270
+ discountRuleId: discountRuleId,
271
+ })
272
+ .getMany()
273
+ // in case of no discount conditions, we assume that the discount
274
+ // is valid for all
275
+ ];
276
+ case 1:
277
+ discountConditions = _b.sent();
278
+ // in case of no discount conditions, we assume that the discount
279
+ // is valid for all
280
+ if (!discountConditions.length) {
281
+ return [2 /*return*/, true];
282
+ }
283
+ _b.label = 2;
284
+ case 2:
285
+ _b.trys.push([2, 7, 8, 9]);
286
+ discountConditions_1 = __values(discountConditions), discountConditions_1_1 = discountConditions_1.next();
287
+ _b.label = 3;
288
+ case 3:
289
+ if (!!discountConditions_1_1.done) return [3 /*break*/, 6];
290
+ condition = discountConditions_1_1.value;
291
+ return [4 /*yield*/, this.queryConditionTable({
292
+ type: condition.type,
293
+ condId: condition.id,
294
+ resourceId: productId,
295
+ })];
296
+ case 4:
297
+ numConditions = _b.sent();
298
+ if (condition.operator === discount_condition_1.DiscountConditionOperator.IN &&
299
+ numConditions === 0) {
300
+ return [2 /*return*/, false];
301
+ }
302
+ if (condition.operator === discount_condition_1.DiscountConditionOperator.NOT_IN &&
303
+ numConditions > 0) {
304
+ return [2 /*return*/, false];
305
+ }
306
+ _b.label = 5;
307
+ case 5:
308
+ discountConditions_1_1 = discountConditions_1.next();
309
+ return [3 /*break*/, 3];
310
+ case 6: return [3 /*break*/, 9];
311
+ case 7:
312
+ e_1_1 = _b.sent();
313
+ e_1 = { error: e_1_1 };
314
+ return [3 /*break*/, 9];
315
+ case 8:
316
+ try {
317
+ if (discountConditions_1_1 && !discountConditions_1_1.done && (_a = discountConditions_1.return)) _a.call(discountConditions_1);
318
+ }
319
+ finally { if (e_1) throw e_1.error; }
320
+ return [7 /*endfinally*/];
321
+ case 9: return [2 /*return*/, true];
322
+ }
323
+ });
324
+ });
325
+ };
326
+ DiscountConditionRepository.prototype.canApplyForCustomer = function (discountRuleId, customerId) {
327
+ return __awaiter(this, void 0, void 0, function () {
328
+ var discountConditions, discountConditions_2, discountConditions_2_1, condition, numConditions, e_2_1;
329
+ var e_2, _a;
330
+ return __generator(this, function (_b) {
331
+ switch (_b.label) {
332
+ case 0: return [4 /*yield*/, this.createQueryBuilder("discon")
333
+ .select(["discon.id", "discon.type", "discon.operator"])
334
+ .where("discon.discount_rule_id = :discountRuleId", {
335
+ discountRuleId: discountRuleId,
336
+ })
337
+ .getMany()
338
+ // in case of no discount conditions, we assume that the discount
339
+ // is valid for all
340
+ ];
341
+ case 1:
342
+ discountConditions = _b.sent();
343
+ // in case of no discount conditions, we assume that the discount
344
+ // is valid for all
345
+ if (!discountConditions.length) {
346
+ return [2 /*return*/, true];
347
+ }
348
+ _b.label = 2;
349
+ case 2:
350
+ _b.trys.push([2, 7, 8, 9]);
351
+ discountConditions_2 = __values(discountConditions), discountConditions_2_1 = discountConditions_2.next();
352
+ _b.label = 3;
353
+ case 3:
354
+ if (!!discountConditions_2_1.done) return [3 /*break*/, 6];
355
+ condition = discountConditions_2_1.value;
356
+ return [4 /*yield*/, this.queryConditionTable({
357
+ type: "customer_groups",
358
+ condId: condition.id,
359
+ resourceId: customerId,
360
+ })];
361
+ case 4:
362
+ numConditions = _b.sent();
363
+ if (condition.operator === discount_condition_1.DiscountConditionOperator.IN &&
364
+ numConditions === 0) {
365
+ return [2 /*return*/, false];
366
+ }
367
+ if (condition.operator === discount_condition_1.DiscountConditionOperator.NOT_IN &&
368
+ numConditions > 0) {
369
+ return [2 /*return*/, false];
370
+ }
371
+ _b.label = 5;
372
+ case 5:
373
+ discountConditions_2_1 = discountConditions_2.next();
374
+ return [3 /*break*/, 3];
375
+ case 6: return [3 /*break*/, 9];
376
+ case 7:
377
+ e_2_1 = _b.sent();
378
+ e_2 = { error: e_2_1 };
379
+ return [3 /*break*/, 9];
380
+ case 8:
381
+ try {
382
+ if (discountConditions_2_1 && !discountConditions_2_1.done && (_a = discountConditions_2.return)) _a.call(discountConditions_2);
383
+ }
384
+ finally { if (e_2) throw e_2.error; }
385
+ return [7 /*endfinally*/];
386
+ case 9: return [2 /*return*/, true];
387
+ }
388
+ });
389
+ });
390
+ };
391
+ DiscountConditionRepository = __decorate([
392
+ (0, typeorm_1.EntityRepository)(discount_condition_1.DiscountCondition)
393
+ ], DiscountConditionRepository);
394
+ return DiscountConditionRepository;
395
+ }(typeorm_1.Repository));
396
+ exports.DiscountConditionRepository = DiscountConditionRepository;
397
+ //# sourceMappingURL=discount-condition.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"discount-condition.js","sourceRoot":"","sources":["../../src/repositories/discount-condition.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,mCAOgB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UAAU,EAAE,UAAU;6BACvB,CAAC,EAAA;;wBAJI,aAAa,GAAG,SAIpB;wBAEF,IACE,SAAS,CAAC,QAAQ,KAAK,8CAAyB,CAAC,EAAE;4BACnD,aAAa,KAAK,CAAC,EACnB;4BACA,sBAAO,KAAK,EAAA;yBACb;wBAED,IACE,SAAS,CAAC,QAAQ,KAAK,8CAAyB,CAAC,MAAM;4BACvD,aAAa,GAAG,CAAC,EACjB;4BACA,sBAAO,KAAK,EAAA;yBACb;;;;;;;;;;;;;;;;4BAGH,sBAAO,IAAI,EAAA;;;;KACZ;IA1RU,2BAA2B;QADvC,IAAA,0BAAgB,EAAC,sCAAiB,CAAC;OACvB,2BAA2B,CA2RvC;IAAD,kCAAC;CAAA,AA3RD,CAAiD,oBAAU,GA2R1D;AA3RY,kEAA2B"}
@@ -0,0 +1,4 @@
1
+ import { Repository } from "typeorm";
2
+ import { LineItemAdjustment } from "../models/line-item-adjustment";
3
+ export declare class LineItemAdjustmentRepository extends Repository<LineItemAdjustment> {
4
+ }
@@ -0,0 +1,38 @@
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 __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
18
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
19
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
20
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
21
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
22
+ };
23
+ Object.defineProperty(exports, "__esModule", { value: true });
24
+ exports.LineItemAdjustmentRepository = void 0;
25
+ var typeorm_1 = require("typeorm");
26
+ var line_item_adjustment_1 = require("../models/line-item-adjustment");
27
+ var LineItemAdjustmentRepository = /** @class */ (function (_super) {
28
+ __extends(LineItemAdjustmentRepository, _super);
29
+ function LineItemAdjustmentRepository() {
30
+ return _super !== null && _super.apply(this, arguments) || this;
31
+ }
32
+ LineItemAdjustmentRepository = __decorate([
33
+ (0, typeorm_1.EntityRepository)(line_item_adjustment_1.LineItemAdjustment)
34
+ ], LineItemAdjustmentRepository);
35
+ return LineItemAdjustmentRepository;
36
+ }(typeorm_1.Repository));
37
+ exports.LineItemAdjustmentRepository = LineItemAdjustmentRepository;
38
+ //# sourceMappingURL=line-item-adjustment.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"line-item-adjustment.js","sourceRoot":"","sources":["../../src/repositories/line-item-adjustment.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAAA,mCAAsD;AACtD,uEAAmE;AAGnE;IAAkD,gDAA8B;IAAhF;;IAAkF,CAAC;IAAtE,4BAA4B;QADxC,IAAA,0BAAgB,EAAC,yCAAkB,CAAC;OACxB,4BAA4B,CAA0C;IAAD,mCAAC;CAAA,AAAnF,CAAkD,oBAAU,GAAuB;AAAtE,oEAA4B"}
@@ -1,4 +1,6 @@
1
1
  import { Repository } from "typeorm";
2
2
  import { LineItemTaxLine } from "../models/line-item-tax-line";
3
3
  export declare class LineItemTaxLineRepository extends Repository<LineItemTaxLine> {
4
+ upsertLines(lines: LineItemTaxLine[]): Promise<LineItemTaxLine[]>;
5
+ deleteForCart(cartId: string): Promise<void>;
4
6
  }
@@ -20,6 +20,42 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
20
20
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
21
21
  return c > 3 && r && Object.defineProperty(target, key, r), r;
22
22
  };
23
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
24
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
25
+ return new (P || (P = Promise))(function (resolve, reject) {
26
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
27
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
28
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
29
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
30
+ });
31
+ };
32
+ var __generator = (this && this.__generator) || function (thisArg, body) {
33
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
34
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
35
+ function verb(n) { return function (v) { return step([n, v]); }; }
36
+ function step(op) {
37
+ if (f) throw new TypeError("Generator is already executing.");
38
+ while (_) try {
39
+ 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;
40
+ if (y = 0, t) op = [op[0] & 2, t.value];
41
+ switch (op[0]) {
42
+ case 0: case 1: t = op; break;
43
+ case 4: _.label++; return { value: op[1], done: false };
44
+ case 5: _.label++; y = op[1]; op = [0]; continue;
45
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
46
+ default:
47
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
48
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
49
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
50
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
51
+ if (t[2]) _.ops.pop();
52
+ _.trys.pop(); continue;
53
+ }
54
+ op = body.call(thisArg, _);
55
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
56
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
57
+ }
58
+ };
23
59
  Object.defineProperty(exports, "__esModule", { value: true });
24
60
  exports.LineItemTaxLineRepository = void 0;
25
61
  var typeorm_1 = require("typeorm");
@@ -29,6 +65,50 @@ var LineItemTaxLineRepository = /** @class */ (function (_super) {
29
65
  function LineItemTaxLineRepository() {
30
66
  return _super !== null && _super.apply(this, arguments) || this;
31
67
  }
68
+ LineItemTaxLineRepository.prototype.upsertLines = function (lines) {
69
+ return __awaiter(this, void 0, void 0, function () {
70
+ var insertResult;
71
+ return __generator(this, function (_a) {
72
+ switch (_a.label) {
73
+ case 0: return [4 /*yield*/, this.createQueryBuilder()
74
+ .insert()
75
+ .values(lines)
76
+ .orUpdate({
77
+ conflict_target: ["item_id", "code"],
78
+ overwrite: ["rate", "name", "updated_at"],
79
+ })
80
+ .execute()];
81
+ case 1:
82
+ insertResult = _a.sent();
83
+ return [2 /*return*/, insertResult.identifiers];
84
+ }
85
+ });
86
+ });
87
+ };
88
+ LineItemTaxLineRepository.prototype.deleteForCart = function (cartId) {
89
+ return __awaiter(this, void 0, void 0, function () {
90
+ var qb, toDelete;
91
+ return __generator(this, function (_a) {
92
+ switch (_a.label) {
93
+ case 0:
94
+ qb = this.createQueryBuilder("line")
95
+ .select(["line.id"])
96
+ .innerJoin("line_item", "i", "i.id = line.item_id")
97
+ .innerJoin("cart", "c", "i.cart_id = :cartId AND c.completed_at is NULL", { cartId: cartId });
98
+ return [4 /*yield*/, qb.getMany()];
99
+ case 1:
100
+ toDelete = _a.sent();
101
+ return [4 /*yield*/, this.createQueryBuilder()
102
+ .delete()
103
+ .whereInIds(toDelete.map(function (d) { return d.id; }))
104
+ .execute()];
105
+ case 2:
106
+ _a.sent();
107
+ return [2 /*return*/];
108
+ }
109
+ });
110
+ });
111
+ };
32
112
  LineItemTaxLineRepository = __decorate([
33
113
  (0, typeorm_1.EntityRepository)(line_item_tax_line_1.LineItemTaxLine)
34
114
  ], LineItemTaxLineRepository);
@@ -1 +1 @@
1
- {"version":3,"file":"line-item-tax-line.js","sourceRoot":"","sources":["../../src/repositories/line-item-tax-line.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAAA,mCAAsD;AACtD,mEAA8D;AAG9D;IAA+C,6CAA2B;IAA1E;;IAA4E,CAAC;IAAhE,yBAAyB;QADrC,IAAA,0BAAgB,EAAC,oCAAe,CAAC;OACrB,yBAAyB,CAAuC;IAAD,gCAAC;CAAA,AAA7E,CAA+C,oBAAU,GAAoB;AAAhE,8DAAyB"}
1
+ {"version":3,"file":"line-item-tax-line.js","sourceRoot":"","sources":["../../src/repositories/line-item-tax-line.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,mCAAsD;AACtD,mEAA8D;AAG9D;IAA+C,6CAA2B;IAA1E;;IAgCA,CAAC;IA/BO,+CAAW,GAAjB,UAAkB,KAAwB;;;;;4BACnB,qBAAM,IAAI,CAAC,kBAAkB,EAAE;6BACjD,MAAM,EAAE;6BACR,MAAM,CAAC,KAAK,CAAC;6BACb,QAAQ,CAAC;4BACR,eAAe,EAAE,CAAC,SAAS,EAAE,MAAM,CAAC;4BACpC,SAAS,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,YAAY,CAAC;yBAC1C,CAAC;6BACD,OAAO,EAAE,EAAA;;wBAPN,YAAY,GAAG,SAOT;wBAEZ,sBAAO,YAAY,CAAC,WAAgC,EAAA;;;;KACrD;IAEK,iDAAa,GAAnB,UAAoB,MAAc;;;;;;wBAC1B,EAAE,GAAG,IAAI,CAAC,kBAAkB,CAAC,MAAM,CAAC;6BACvC,MAAM,CAAC,CAAC,SAAS,CAAC,CAAC;6BACnB,SAAS,CAAC,WAAW,EAAE,GAAG,EAAE,qBAAqB,CAAC;6BAClD,SAAS,CACR,MAAM,EACN,GAAG,EACH,gDAAgD,EAChD,EAAE,MAAM,QAAA,EAAE,CACX,CAAA;wBAEc,qBAAM,EAAE,CAAC,OAAO,EAAE,EAAA;;wBAA7B,QAAQ,GAAG,SAAkB;wBAEnC,qBAAM,IAAI,CAAC,kBAAkB,EAAE;iCAC5B,MAAM,EAAE;iCACR,UAAU,CAAC,QAAQ,CAAC,GAAG,CAAC,UAAC,CAAC,IAAK,OAAA,CAAC,CAAC,EAAE,EAAJ,CAAI,CAAC,CAAC;iCACrC,OAAO,EAAE,EAAA;;wBAHZ,SAGY,CAAA;;;;;KACb;IA/BU,yBAAyB;QADrC,IAAA,0BAAgB,EAAC,oCAAe,CAAC;OACrB,yBAAyB,CAgCrC;IAAD,gCAAC;CAAA,AAhCD,CAA+C,oBAAU,GAgCxD;AAhCY,8DAAyB"}
@@ -82,6 +82,7 @@ var LineItemRepository = /** @class */ (function (_super) {
82
82
  case 0:
83
83
  qb = this.createQueryBuilder("li")
84
84
  .leftJoinAndSelect("li.tax_lines", "tax_lines")
85
+ .leftJoinAndSelect("li.adjustments", "adjustments")
85
86
  .leftJoinAndMapOne("li.return_item", return_item_1.ReturnItem, "ri", "ri.item_id = li.id")
86
87
  .where("ri.return_id = :returnId", { returnId: returnId });
87
88
  return [4 /*yield*/, qb.getMany()];
@@ -1 +1 @@
1
- {"version":3,"file":"line-item.js","sourceRoot":"","sources":["../../src/repositories/line-item.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,mCAAsD;AACtD,iDAA8C;AAC9C,qDAA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