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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (736) hide show
  1. package/CHANGELOG.md +98 -0
  2. package/dist/api/index.d.ts +1 -0
  3. package/dist/api/index.js +1 -0
  4. package/dist/api/index.js.map +1 -1
  5. package/dist/api/middlewares/authenticate-customer.d.ts +2 -1
  6. package/dist/api/middlewares/authenticate-customer.js +1 -2
  7. package/dist/api/middlewares/authenticate-customer.js.map +1 -1
  8. package/dist/api/middlewares/authenticate.d.ts +2 -1
  9. package/dist/api/middlewares/authenticate.js.map +1 -1
  10. package/dist/api/middlewares/await-middleware.d.ts +3 -1
  11. package/dist/api/middlewares/await-middleware.js +2 -31
  12. package/dist/api/middlewares/await-middleware.js.map +1 -1
  13. package/dist/api/middlewares/batch-job/can-access-batch-job.d.ts +1 -0
  14. package/dist/api/middlewares/batch-job/can-access-batch-job.js +70 -0
  15. package/dist/api/middlewares/batch-job/can-access-batch-job.js.map +1 -0
  16. package/dist/api/middlewares/batch-job/get-requested-batch-job.d.ts +1 -0
  17. package/dist/api/middlewares/batch-job/get-requested-batch-job.js +67 -0
  18. package/dist/api/middlewares/batch-job/get-requested-batch-job.js.map +1 -0
  19. package/dist/api/middlewares/error-handler.d.ts +3 -1
  20. package/dist/api/middlewares/error-handler.js +4 -4
  21. package/dist/api/middlewares/error-handler.js.map +1 -1
  22. package/dist/api/middlewares/index.d.ts +12 -10
  23. package/dist/api/middlewares/index.js +9 -0
  24. package/dist/api/middlewares/index.js.map +1 -1
  25. package/dist/api/middlewares/normalized-query.d.ts +6 -1
  26. package/dist/api/middlewares/normalized-query.js +5 -2
  27. package/dist/api/middlewares/normalized-query.js.map +1 -1
  28. package/dist/api/middlewares/transform-body.d.ts +4 -0
  29. package/dist/api/middlewares/transform-body.js +66 -0
  30. package/dist/api/middlewares/transform-body.js.map +1 -0
  31. package/dist/api/middlewares/transform-query.d.ts +6 -0
  32. package/dist/api/middlewares/transform-query.js +86 -0
  33. package/dist/api/middlewares/transform-query.js.map +1 -0
  34. package/dist/api/routes/admin/auth/create-session.js +5 -5
  35. package/dist/api/routes/admin/auth/create-session.js.map +1 -1
  36. package/dist/api/routes/admin/batch/index.d.ts +13 -0
  37. package/dist/api/routes/admin/batch/index.js +50 -0
  38. package/dist/api/routes/admin/batch/index.js.map +1 -0
  39. package/dist/api/routes/admin/batch/list-batch-jobs.d.ts +48 -0
  40. package/dist/api/routes/admin/batch/list-batch-jobs.js +220 -0
  41. package/dist/api/routes/admin/batch/list-batch-jobs.js.map +1 -0
  42. package/dist/api/routes/admin/customer-groups/list-customer-groups.js +2 -2
  43. package/dist/api/routes/admin/customer-groups/list-customer-groups.js.map +1 -1
  44. package/dist/api/routes/admin/discounts/create-condition.d.ts +58 -0
  45. package/dist/api/routes/admin/discounts/create-condition.js +186 -0
  46. package/dist/api/routes/admin/discounts/create-condition.js.map +1 -0
  47. package/dist/api/routes/admin/discounts/create-discount.d.ts +14 -4
  48. package/dist/api/routes/admin/discounts/create-discount.js +72 -16
  49. package/dist/api/routes/admin/discounts/create-discount.js.map +1 -1
  50. package/dist/api/routes/admin/discounts/create-dynamic-code.d.ts +1 -0
  51. package/dist/api/routes/admin/discounts/create-dynamic-code.js +4 -1
  52. package/dist/api/routes/admin/discounts/create-dynamic-code.js.map +1 -1
  53. package/dist/api/routes/admin/discounts/delete-condition.d.ts +36 -0
  54. package/dist/api/routes/admin/discounts/delete-condition.js +151 -0
  55. package/dist/api/routes/admin/discounts/delete-condition.js.map +1 -0
  56. package/dist/api/routes/admin/discounts/delete-dynamic-code.js +3 -1
  57. package/dist/api/routes/admin/discounts/delete-dynamic-code.js.map +1 -1
  58. package/dist/api/routes/admin/discounts/get-condition.d.ts +31 -0
  59. package/dist/api/routes/admin/discounts/get-condition.js +125 -0
  60. package/dist/api/routes/admin/discounts/get-condition.js.map +1 -0
  61. package/dist/api/routes/admin/discounts/get-discount-by-code.d.ts +4 -0
  62. package/dist/api/routes/admin/discounts/get-discount-by-code.js +40 -6
  63. package/dist/api/routes/admin/discounts/get-discount-by-code.js.map +1 -1
  64. package/dist/api/routes/admin/discounts/get-discount.d.ts +7 -0
  65. package/dist/api/routes/admin/discounts/get-discount.js +43 -9
  66. package/dist/api/routes/admin/discounts/get-discount.js.map +1 -1
  67. package/dist/api/routes/admin/discounts/index.d.ts +11 -3
  68. package/dist/api/routes/admin/discounts/index.js +13 -7
  69. package/dist/api/routes/admin/discounts/index.js.map +1 -1
  70. package/dist/api/routes/admin/discounts/list-discounts.d.ts +2 -6
  71. package/dist/api/routes/admin/discounts/list-discounts.js +15 -28
  72. package/dist/api/routes/admin/discounts/list-discounts.js.map +1 -1
  73. package/dist/api/routes/admin/discounts/update-condition.d.ts +55 -0
  74. package/dist/api/routes/admin/discounts/update-condition.js +184 -0
  75. package/dist/api/routes/admin/discounts/update-condition.js.map +1 -0
  76. package/dist/api/routes/admin/discounts/update-discount.d.ts +18 -12
  77. package/dist/api/routes/admin/discounts/update-discount.js +79 -33
  78. package/dist/api/routes/admin/discounts/update-discount.js.map +1 -1
  79. package/dist/api/routes/admin/draft-orders/create-draft-order.d.ts +3 -3
  80. package/dist/api/routes/admin/draft-orders/create-draft-order.js.map +1 -1
  81. package/dist/api/routes/admin/draft-orders/create-line-item.d.ts +1 -1
  82. package/dist/api/routes/admin/draft-orders/create-line-item.js.map +1 -1
  83. package/dist/api/routes/admin/draft-orders/index.d.ts +1 -1
  84. package/dist/api/routes/admin/draft-orders/index.js +7 -1
  85. package/dist/api/routes/admin/draft-orders/index.js.map +1 -1
  86. package/dist/api/routes/admin/draft-orders/list-draft-orders.js +7 -6
  87. package/dist/api/routes/admin/draft-orders/list-draft-orders.js.map +1 -1
  88. package/dist/api/routes/admin/draft-orders/register-payment.js +0 -1
  89. package/dist/api/routes/admin/draft-orders/register-payment.js.map +1 -1
  90. package/dist/api/routes/admin/draft-orders/update-line-item.d.ts +1 -1
  91. package/dist/api/routes/admin/draft-orders/update-line-item.js.map +1 -1
  92. package/dist/api/routes/admin/index.js +23 -19
  93. package/dist/api/routes/admin/index.js.map +1 -1
  94. package/dist/api/routes/admin/notifications/index.js.map +1 -1
  95. package/dist/api/routes/admin/notifications/list-notifications.js.map +1 -1
  96. package/dist/api/routes/admin/notifications/resend-notification.js.map +1 -1
  97. package/dist/api/routes/admin/orders/add-shipping-method.d.ts +1 -1
  98. package/dist/api/routes/admin/orders/add-shipping-method.js.map +1 -1
  99. package/dist/api/routes/admin/orders/create-claim.d.ts +4 -14
  100. package/dist/api/routes/admin/orders/create-claim.js +9 -14
  101. package/dist/api/routes/admin/orders/create-claim.js.map +1 -1
  102. package/dist/api/routes/admin/orders/create-order.js.map +1 -1
  103. package/dist/api/routes/admin/orders/create-swap.js +7 -3
  104. package/dist/api/routes/admin/orders/create-swap.js.map +1 -1
  105. package/dist/api/routes/admin/orders/fulfill-claim.d.ts +1 -1
  106. package/dist/api/routes/admin/orders/fulfill-claim.js.map +1 -1
  107. package/dist/api/routes/admin/orders/index.d.ts +1 -1
  108. package/dist/api/routes/admin/orders/index.js +1 -3
  109. package/dist/api/routes/admin/orders/index.js.map +1 -1
  110. package/dist/api/routes/admin/orders/list-orders.js.map +1 -1
  111. package/dist/api/routes/admin/orders/update-claim.d.ts +1 -1
  112. package/dist/api/routes/admin/orders/update-claim.js.map +1 -1
  113. package/dist/api/routes/admin/orders/update-order.js.map +1 -1
  114. package/dist/api/routes/admin/price-lists/add-prices-batch.d.ts +70 -0
  115. package/dist/api/routes/admin/price-lists/add-prices-batch.js +158 -0
  116. package/dist/api/routes/admin/price-lists/add-prices-batch.js.map +1 -0
  117. package/dist/api/routes/admin/price-lists/create-price-list.d.ts +88 -0
  118. package/dist/api/routes/admin/price-lists/create-price-list.js +190 -0
  119. package/dist/api/routes/admin/price-lists/create-price-list.js.map +1 -0
  120. package/dist/api/routes/admin/price-lists/delete-price-list.d.ts +28 -0
  121. package/dist/api/routes/admin/price-lists/delete-price-list.js +84 -0
  122. package/dist/api/routes/admin/price-lists/delete-price-list.js.map +1 -0
  123. package/dist/api/routes/admin/price-lists/delete-prices-batch.d.ts +43 -0
  124. package/dist/api/routes/admin/price-lists/delete-prices-batch.js +118 -0
  125. package/dist/api/routes/admin/price-lists/delete-prices-batch.js.map +1 -0
  126. package/dist/api/routes/admin/price-lists/delete-product-prices.d.ts +32 -0
  127. package/dist/api/routes/admin/price-lists/delete-product-prices.js +105 -0
  128. package/dist/api/routes/admin/price-lists/delete-product-prices.js.map +1 -0
  129. package/dist/api/routes/admin/price-lists/delete-variant-prices.d.ts +32 -0
  130. package/dist/api/routes/admin/price-lists/delete-variant-prices.js +105 -0
  131. package/dist/api/routes/admin/price-lists/delete-variant-prices.js.map +1 -0
  132. package/dist/api/routes/admin/price-lists/get-price-list.d.ts +22 -0
  133. package/dist/api/routes/admin/price-lists/get-price-list.js +78 -0
  134. package/dist/api/routes/admin/price-lists/get-price-list.js.map +1 -0
  135. package/dist/api/routes/admin/price-lists/index.d.ts +30 -0
  136. package/dist/api/routes/admin/price-lists/index.js +76 -0
  137. package/dist/api/routes/admin/price-lists/index.js.map +1 -0
  138. package/dist/api/routes/admin/price-lists/list-price-list-products.d.ts +75 -0
  139. package/dist/api/routes/admin/price-lists/list-price-list-products.js +255 -0
  140. package/dist/api/routes/admin/price-lists/list-price-list-products.js.map +1 -0
  141. package/dist/api/routes/admin/price-lists/list-price-lists.d.ts +39 -0
  142. package/dist/api/routes/admin/price-lists/list-price-lists.js +165 -0
  143. package/dist/api/routes/admin/price-lists/list-price-lists.js.map +1 -0
  144. package/dist/api/routes/admin/price-lists/update-price-list.d.ts +92 -0
  145. package/dist/api/routes/admin/price-lists/update-price-list.js +211 -0
  146. package/dist/api/routes/admin/price-lists/update-price-list.js.map +1 -0
  147. package/dist/api/routes/admin/product-tags/list-product-tags.d.ts +2 -1
  148. package/dist/api/routes/admin/product-tags/list-product-tags.js +6 -3
  149. package/dist/api/routes/admin/product-tags/list-product-tags.js.map +1 -1
  150. package/dist/api/routes/admin/product-types/list-product-types.d.ts +2 -1
  151. package/dist/api/routes/admin/product-types/list-product-types.js +6 -3
  152. package/dist/api/routes/admin/product-types/list-product-types.js.map +1 -1
  153. package/dist/api/routes/admin/products/create-product.d.ts +2 -7
  154. package/dist/api/routes/admin/products/create-product.js +2 -24
  155. package/dist/api/routes/admin/products/create-product.js.map +1 -1
  156. package/dist/api/routes/admin/products/create-variant.d.ts +7 -9
  157. package/dist/api/routes/admin/products/create-variant.js +7 -26
  158. package/dist/api/routes/admin/products/create-variant.js.map +1 -1
  159. package/dist/api/routes/admin/products/index.d.ts +3 -2
  160. package/dist/api/routes/admin/products/index.js +8 -3
  161. package/dist/api/routes/admin/products/index.js.map +1 -1
  162. package/dist/api/routes/admin/products/list-products.d.ts +2 -1
  163. package/dist/api/routes/admin/products/list-products.js +31 -65
  164. package/dist/api/routes/admin/products/list-products.js.map +1 -1
  165. package/dist/api/routes/admin/products/list-variants.d.ts +35 -0
  166. package/dist/api/routes/admin/products/list-variants.js +173 -0
  167. package/dist/api/routes/admin/products/list-variants.js.map +1 -0
  168. package/dist/api/routes/admin/products/update-product.d.ts +2 -7
  169. package/dist/api/routes/admin/products/update-product.js +2 -24
  170. package/dist/api/routes/admin/products/update-product.js.map +1 -1
  171. package/dist/api/routes/admin/products/update-variant.d.ts +10 -9
  172. package/dist/api/routes/admin/products/update-variant.js +21 -33
  173. package/dist/api/routes/admin/products/update-variant.js.map +1 -1
  174. package/dist/api/routes/admin/regions/index.d.ts +1 -1
  175. package/dist/api/routes/admin/shipping-options/list-shipping-options.d.ts +2 -2
  176. package/dist/api/routes/admin/shipping-options/list-shipping-options.js +2 -2
  177. package/dist/api/routes/admin/shipping-options/list-shipping-options.js.map +1 -1
  178. package/dist/api/routes/admin/store/get-store.js +4 -2
  179. package/dist/api/routes/admin/store/get-store.js.map +1 -1
  180. package/dist/api/routes/admin/store/update-store.d.ts +1 -0
  181. package/dist/api/routes/admin/store/update-store.js +5 -0
  182. package/dist/api/routes/admin/store/update-store.js.map +1 -1
  183. package/dist/api/routes/admin/swaps/index.js +3 -0
  184. package/dist/api/routes/admin/swaps/index.js.map +1 -1
  185. package/dist/api/routes/admin/tax-rates/list-tax-rates.js.map +1 -1
  186. package/dist/api/routes/admin/tax-rates/utils/get-query-config.d.ts +1 -1
  187. package/dist/api/routes/admin/tax-rates/utils/get-query-config.js +4 -2
  188. package/dist/api/routes/admin/tax-rates/utils/get-query-config.js.map +1 -1
  189. package/dist/api/routes/admin/uploads/index.d.ts +1 -1
  190. package/dist/api/routes/admin/users/update-user.d.ts +1 -1
  191. package/dist/api/routes/admin/users/update-user.js.map +1 -1
  192. package/dist/api/routes/store/auth/create-session.js +4 -5
  193. package/dist/api/routes/store/auth/create-session.js.map +1 -1
  194. package/dist/api/routes/store/carts/create-cart.js +8 -5
  195. package/dist/api/routes/store/carts/create-cart.js.map +1 -1
  196. package/dist/api/routes/store/carts/create-line-item.d.ts +1 -1
  197. package/dist/api/routes/store/carts/create-line-item.js +9 -6
  198. package/dist/api/routes/store/carts/create-line-item.js.map +1 -1
  199. package/dist/api/routes/store/carts/index.d.ts +0 -1
  200. package/dist/api/routes/store/carts/index.js +1 -3
  201. package/dist/api/routes/store/carts/index.js.map +1 -1
  202. package/dist/api/routes/store/carts/update-cart.js +8 -8
  203. package/dist/api/routes/store/carts/update-cart.js.map +1 -1
  204. package/dist/api/routes/store/collections/list-collections.d.ts +3 -0
  205. package/dist/api/routes/store/collections/list-collections.js +33 -16
  206. package/dist/api/routes/store/collections/list-collections.js.map +1 -1
  207. package/dist/api/routes/store/customers/create-customer.js +3 -4
  208. package/dist/api/routes/store/customers/create-customer.js.map +1 -1
  209. package/dist/api/routes/store/customers/get-payment-methods.js +6 -7
  210. package/dist/api/routes/store/customers/get-payment-methods.js.map +1 -1
  211. package/dist/api/routes/store/orders/index.js +0 -2
  212. package/dist/api/routes/store/orders/index.js.map +1 -1
  213. package/dist/api/routes/store/products/get-product.js +17 -5
  214. package/dist/api/routes/store/products/get-product.js.map +1 -1
  215. package/dist/api/routes/store/products/index.d.ts +2 -2
  216. package/dist/api/routes/store/products/list-products.d.ts +2 -2
  217. package/dist/api/routes/store/products/list-products.js +21 -14
  218. package/dist/api/routes/store/products/list-products.js.map +1 -1
  219. package/dist/api/routes/store/products/search.d.ts +1 -1
  220. package/dist/api/routes/store/products/search.js.map +1 -1
  221. package/dist/api/routes/store/regions/list-regions.d.ts +3 -0
  222. package/dist/api/routes/store/regions/list-regions.js +22 -7
  223. package/dist/api/routes/store/regions/list-regions.js.map +1 -1
  224. package/dist/api/routes/store/shipping-options/list-options.js.map +1 -1
  225. package/dist/api/routes/store/swaps/create-swap.js +7 -3
  226. package/dist/api/routes/store/swaps/create-swap.js.map +1 -1
  227. package/dist/api/routes/store/variants/get-variant.js +17 -5
  228. package/dist/api/routes/store/variants/get-variant.js.map +1 -1
  229. package/dist/api/routes/store/variants/list-variants.d.ts +2 -1
  230. package/dist/api/routes/store/variants/list-variants.js +38 -9
  231. package/dist/api/routes/store/variants/list-variants.js.map +1 -1
  232. package/dist/commands/develop.js +2 -2
  233. package/dist/commands/develop.js.map +1 -1
  234. package/dist/commands/migrate.js +17 -6
  235. package/dist/commands/migrate.js.map +1 -1
  236. package/dist/commands/start.js +6 -0
  237. package/dist/commands/start.js.map +1 -1
  238. package/dist/controllers/customers/index.d.ts +1 -1
  239. package/dist/controllers/customers/list-customers.d.ts +1 -1
  240. package/dist/controllers/customers/list-customers.js +34 -37
  241. package/dist/controllers/customers/list-customers.js.map +1 -1
  242. package/dist/controllers/products/admin-list-products.d.ts +16 -0
  243. package/dist/controllers/products/admin-list-products.js +103 -0
  244. package/dist/controllers/products/admin-list-products.js.map +1 -0
  245. package/dist/helpers/test-request.js +26 -17
  246. package/dist/helpers/test-request.js.map +1 -1
  247. package/dist/index.d.ts +4 -58
  248. package/dist/index.js +4 -61
  249. package/dist/index.js.map +1 -1
  250. package/dist/interfaces/base-service.d.ts +66 -0
  251. package/dist/interfaces/base-service.js +377 -0
  252. package/dist/interfaces/base-service.js.map +1 -0
  253. package/dist/interfaces/batch-job-strategy.d.ts +28 -0
  254. package/dist/interfaces/batch-job-strategy.js +75 -0
  255. package/dist/interfaces/batch-job-strategy.js.map +1 -0
  256. package/dist/interfaces/file-service.d.ts +62 -0
  257. package/dist/interfaces/file-service.js +32 -0
  258. package/dist/interfaces/file-service.js.map +1 -0
  259. package/dist/interfaces/index.d.ts +4 -0
  260. package/dist/interfaces/index.js +4 -0
  261. package/dist/interfaces/index.js.map +1 -1
  262. package/dist/interfaces/models/base-entity.d.ts +8 -0
  263. package/dist/interfaces/models/base-entity.js +36 -0
  264. package/dist/interfaces/models/base-entity.js.map +1 -0
  265. package/dist/interfaces/models/soft-deletable-entity.d.ts +4 -0
  266. package/dist/interfaces/models/soft-deletable-entity.js +43 -0
  267. package/dist/interfaces/models/soft-deletable-entity.js.map +1 -0
  268. package/dist/interfaces/price-selection-strategy.d.ts +50 -0
  269. package/dist/interfaces/price-selection-strategy.js +34 -0
  270. package/dist/interfaces/price-selection-strategy.js.map +1 -0
  271. package/dist/interfaces/tax-service.d.ts +6 -0
  272. package/dist/interfaces/tax-service.js +31 -0
  273. package/dist/interfaces/tax-service.js.map +1 -1
  274. package/dist/interfaces/transaction-base-service.d.ts +23 -0
  275. package/dist/interfaces/transaction-base-service.js +200 -0
  276. package/dist/interfaces/transaction-base-service.js.map +1 -0
  277. package/dist/loaders/api.d.ts +9 -5
  278. package/dist/loaders/api.js +2 -6
  279. package/dist/loaders/api.js.map +1 -1
  280. package/dist/loaders/config.d.ts +3 -0
  281. package/dist/loaders/config.js +47 -0
  282. package/dist/loaders/config.js.map +1 -0
  283. package/dist/loaders/database.d.ts +8 -4
  284. package/dist/loaders/database.js.map +1 -1
  285. package/dist/loaders/defaults.d.ts +4 -3
  286. package/dist/loaders/defaults.js +39 -31
  287. package/dist/loaders/defaults.js.map +1 -1
  288. package/dist/loaders/express.d.ts +7 -4
  289. package/dist/loaders/express.js +7 -5
  290. package/dist/loaders/express.js.map +1 -1
  291. package/dist/loaders/index.d.ts +13 -8
  292. package/dist/loaders/index.js +29 -54
  293. package/dist/loaders/index.js.map +1 -1
  294. package/dist/loaders/logger.d.ts +1 -0
  295. package/dist/loaders/logger.js.map +1 -1
  296. package/dist/loaders/models.d.ts +8 -3
  297. package/dist/loaders/models.js +19 -17
  298. package/dist/loaders/models.js.map +1 -1
  299. package/dist/loaders/passport.d.ts +7 -4
  300. package/dist/loaders/passport.js +23 -21
  301. package/dist/loaders/passport.js.map +1 -1
  302. package/dist/loaders/plugins.d.ts +38 -10
  303. package/dist/loaders/plugins.js +43 -30
  304. package/dist/loaders/plugins.js.map +1 -1
  305. package/dist/loaders/redis.d.ts +8 -5
  306. package/dist/loaders/redis.js +3 -3
  307. package/dist/loaders/redis.js.map +1 -1
  308. package/dist/loaders/repositories.d.ts +7 -3
  309. package/dist/loaders/repositories.js +1 -1
  310. package/dist/loaders/repositories.js.map +1 -1
  311. package/dist/loaders/search-index.d.ts +4 -3
  312. package/dist/loaders/search-index.js.map +1 -1
  313. package/dist/loaders/services.d.ts +10 -5
  314. package/dist/loaders/services.js.map +1 -1
  315. package/dist/loaders/strategies.d.ts +1 -1
  316. package/dist/loaders/subscribers.d.ts +7 -3
  317. package/dist/loaders/subscribers.js.map +1 -1
  318. package/dist/migrations/1646324713514-discount_conditions.d.ts +6 -0
  319. package/dist/migrations/1646324713514-discount_conditions.js +335 -0
  320. package/dist/migrations/1646324713514-discount_conditions.js.map +1 -0
  321. package/dist/migrations/1646915480108-update_money_amount_add_price_list.d.ts +6 -0
  322. package/dist/migrations/1646915480108-update_money_amount_add_price_list.js +143 -0
  323. package/dist/migrations/1646915480108-update_money_amount_add_price_list.js.map +1 -0
  324. package/dist/migrations/1648600574750-add_line_item_adjustments.d.ts +6 -0
  325. package/dist/migrations/1648600574750-add_line_item_adjustments.js +101 -0
  326. package/dist/migrations/1648600574750-add_line_item_adjustments.js.map +1 -0
  327. package/dist/migrations/1648641130007-tax_line_constraints.d.ts +6 -0
  328. package/dist/migrations/1648641130007-tax_line_constraints.js +77 -0
  329. package/dist/migrations/1648641130007-tax_line_constraints.js.map +1 -0
  330. package/dist/migrations/1649775522087-add_batch_job_model.d.ts +6 -0
  331. package/dist/migrations/1649775522087-add_batch_job_model.js +77 -0
  332. package/dist/migrations/1649775522087-add_batch_job_model.js.map +1 -0
  333. package/dist/models/address.d.ts +3 -6
  334. package/dist/models/address.js +23 -24
  335. package/dist/models/address.js.map +1 -1
  336. package/dist/models/batch-job.d.ts +55 -0
  337. package/dist/models/batch-job.js +118 -0
  338. package/dist/models/batch-job.js.map +1 -0
  339. package/dist/models/cart.d.ts +5 -8
  340. package/dist/models/cart.js +35 -36
  341. package/dist/models/cart.js.map +1 -1
  342. package/dist/models/claim-image.d.ts +3 -6
  343. package/dist/models/claim-image.js +22 -23
  344. package/dist/models/claim-image.js.map +1 -1
  345. package/dist/models/claim-item.d.ts +3 -6
  346. package/dist/models/claim-item.js +25 -24
  347. package/dist/models/claim-item.js.map +1 -1
  348. package/dist/models/claim-order.d.ts +4 -4
  349. package/dist/models/claim-order.js +28 -13
  350. package/dist/models/claim-order.js.map +1 -1
  351. package/dist/models/claim-tag.d.ts +3 -6
  352. package/dist/models/claim-tag.js +22 -23
  353. package/dist/models/claim-tag.js.map +1 -1
  354. package/dist/models/country.d.ts +1 -1
  355. package/dist/models/country.js +1 -1
  356. package/dist/models/country.js.map +1 -1
  357. package/dist/models/custom-shipping-option.d.ts +3 -6
  358. package/dist/models/custom-shipping-option.js +23 -24
  359. package/dist/models/custom-shipping-option.js.map +1 -1
  360. package/dist/models/customer-group.d.ts +6 -7
  361. package/dist/models/customer-group.js +30 -36
  362. package/dist/models/customer-group.js.map +1 -1
  363. package/dist/models/customer.d.ts +3 -6
  364. package/dist/models/customer.js +23 -25
  365. package/dist/models/customer.js.map +1 -1
  366. package/dist/models/discount-condition-customer-group.d.ts +39 -0
  367. package/dist/models/discount-condition-customer-group.js +84 -0
  368. package/dist/models/discount-condition-customer-group.js.map +1 -0
  369. package/dist/models/discount-condition-product-collection.d.ts +39 -0
  370. package/dist/models/discount-condition-product-collection.js +84 -0
  371. package/dist/models/discount-condition-product-collection.js.map +1 -0
  372. package/dist/models/discount-condition-product-tag.d.ts +39 -0
  373. package/dist/models/discount-condition-product-tag.js +84 -0
  374. package/dist/models/discount-condition-product-tag.js.map +1 -0
  375. package/dist/models/discount-condition-product-type.d.ts +39 -0
  376. package/dist/models/discount-condition-product-type.js +84 -0
  377. package/dist/models/discount-condition-product-type.js.map +1 -0
  378. package/dist/models/discount-condition-product.d.ts +39 -0
  379. package/dist/models/discount-condition-product.js +84 -0
  380. package/dist/models/discount-condition-product.js.map +1 -0
  381. package/dist/models/discount-condition.d.ts +65 -0
  382. package/dist/models/discount-condition.js +209 -0
  383. package/dist/models/discount-condition.js.map +1 -0
  384. package/dist/models/discount-rule.d.ts +8 -11
  385. package/dist/models/discount-rule.js +28 -38
  386. package/dist/models/discount-rule.js.map +1 -1
  387. package/dist/models/discount.d.ts +7 -10
  388. package/dist/models/discount.js +30 -30
  389. package/dist/models/discount.js.map +1 -1
  390. package/dist/models/draft-order.d.ts +4 -7
  391. package/dist/models/draft-order.js +25 -22
  392. package/dist/models/draft-order.js.map +1 -1
  393. package/dist/models/fulfillment-item.js.map +1 -1
  394. package/dist/models/fulfillment-provider.js.map +1 -1
  395. package/dist/models/fulfillment.d.ts +5 -7
  396. package/dist/models/fulfillment.js +29 -21
  397. package/dist/models/fulfillment.js.map +1 -1
  398. package/dist/models/gift-card-transaction.js +2 -5
  399. package/dist/models/gift-card-transaction.js.map +1 -1
  400. package/dist/models/gift-card.d.ts +3 -6
  401. package/dist/models/gift-card.js +22 -23
  402. package/dist/models/gift-card.js.map +1 -1
  403. package/dist/models/idempotency-key.d.ts +2 -2
  404. package/dist/models/idempotency-key.js +2 -3
  405. package/dist/models/idempotency-key.js.map +1 -1
  406. package/dist/models/image.d.ts +3 -6
  407. package/dist/models/image.js +22 -23
  408. package/dist/models/image.js.map +1 -1
  409. package/dist/models/index.d.ts +67 -0
  410. package/dist/models/index.js +80 -0
  411. package/dist/models/index.js.map +1 -0
  412. package/dist/models/invite.d.ts +3 -6
  413. package/dist/models/invite.js +22 -24
  414. package/dist/models/invite.js.map +1 -1
  415. package/dist/models/line-item-adjustment.d.ts +13 -0
  416. package/dist/models/line-item-adjustment.js +76 -0
  417. package/dist/models/line-item-adjustment.js.map +1 -0
  418. package/dist/models/line-item-tax-line.js +4 -6
  419. package/dist/models/line-item-tax-line.js.map +1 -1
  420. package/dist/models/line-item.d.ts +5 -5
  421. package/dist/models/line-item.js +29 -19
  422. package/dist/models/line-item.js.map +1 -1
  423. package/dist/models/money-amount.d.ts +12 -8
  424. package/dist/models/money-amount.js +47 -30
  425. package/dist/models/money-amount.js.map +1 -1
  426. package/dist/models/note.d.ts +3 -6
  427. package/dist/models/note.js +22 -23
  428. package/dist/models/note.js.map +1 -1
  429. package/dist/models/notification.d.ts +3 -5
  430. package/dist/models/notification.js +22 -19
  431. package/dist/models/notification.js.map +1 -1
  432. package/dist/models/oauth.d.ts +1 -1
  433. package/dist/models/oauth.js +2 -5
  434. package/dist/models/oauth.js.map +1 -1
  435. package/dist/models/order.d.ts +3 -5
  436. package/dist/models/order.js +25 -21
  437. package/dist/models/order.js.map +1 -1
  438. package/dist/models/payment-provider.js.map +1 -1
  439. package/dist/models/payment-session.d.ts +3 -5
  440. package/dist/models/payment-session.js +22 -19
  441. package/dist/models/payment-session.js.map +1 -1
  442. package/dist/models/payment.d.ts +4 -6
  443. package/dist/models/payment.js +22 -19
  444. package/dist/models/payment.js.map +1 -1
  445. package/dist/models/price-list.d.ts +54 -0
  446. package/dist/models/price-list.js +144 -0
  447. package/dist/models/price-list.js.map +1 -0
  448. package/dist/models/product-collection.d.ts +4 -7
  449. package/dist/models/product-collection.js +25 -24
  450. package/dist/models/product-collection.js.map +1 -1
  451. package/dist/models/product-option-value.d.ts +3 -6
  452. package/dist/models/product-option-value.js +24 -26
  453. package/dist/models/product-option-value.js.map +1 -1
  454. package/dist/models/product-option.d.ts +3 -6
  455. package/dist/models/product-option.js +23 -24
  456. package/dist/models/product-option.js.map +1 -1
  457. package/dist/models/product-tag.d.ts +3 -6
  458. package/dist/models/product-tag.js +22 -23
  459. package/dist/models/product-tag.js.map +1 -1
  460. package/dist/models/product-tax-rate.d.ts +1 -1
  461. package/dist/models/product-tax-rate.js.map +1 -1
  462. package/dist/models/product-type-tax-rate.d.ts +1 -1
  463. package/dist/models/product-type-tax-rate.js.map +1 -1
  464. package/dist/models/product-type.d.ts +3 -6
  465. package/dist/models/product-type.js +22 -23
  466. package/dist/models/product-type.js.map +1 -1
  467. package/dist/models/product-variant.d.ts +3 -6
  468. package/dist/models/product-variant.js +30 -26
  469. package/dist/models/product-variant.js.map +1 -1
  470. package/dist/models/product.d.ts +3 -6
  471. package/dist/models/product.js +25 -22
  472. package/dist/models/product.js.map +1 -1
  473. package/dist/models/refund.d.ts +3 -5
  474. package/dist/models/refund.js +22 -17
  475. package/dist/models/refund.js.map +1 -1
  476. package/dist/models/region.d.ts +3 -6
  477. package/dist/models/region.js +23 -24
  478. package/dist/models/region.js.map +1 -1
  479. package/dist/models/return-item.d.ts +1 -1
  480. package/dist/models/return-item.js.map +1 -1
  481. package/dist/models/return-reason.d.ts +3 -6
  482. package/dist/models/return-reason.js +24 -25
  483. package/dist/models/return-reason.js.map +1 -1
  484. package/dist/models/return.d.ts +5 -7
  485. package/dist/models/return.js +29 -21
  486. package/dist/models/return.js.map +1 -1
  487. package/dist/models/shipping-method-tax-line.js +4 -6
  488. package/dist/models/shipping-method-tax-line.js.map +1 -1
  489. package/dist/models/shipping-method.d.ts +2 -2
  490. package/dist/models/shipping-method.js +3 -6
  491. package/dist/models/shipping-method.js.map +1 -1
  492. package/dist/models/shipping-option-requirement.js +2 -5
  493. package/dist/models/shipping-option-requirement.js.map +1 -1
  494. package/dist/models/shipping-option.d.ts +5 -8
  495. package/dist/models/shipping-option.js +26 -25
  496. package/dist/models/shipping-option.js.map +1 -1
  497. package/dist/models/shipping-profile.d.ts +3 -6
  498. package/dist/models/shipping-profile.js +22 -23
  499. package/dist/models/shipping-profile.js.map +1 -1
  500. package/dist/models/shipping-tax-rate.d.ts +1 -1
  501. package/dist/models/shipping-tax-rate.js.map +1 -1
  502. package/dist/models/staged-job.d.ts +1 -1
  503. package/dist/models/staged-job.js +2 -3
  504. package/dist/models/staged-job.js.map +1 -1
  505. package/dist/models/store.d.ts +3 -5
  506. package/dist/models/store.js +22 -17
  507. package/dist/models/store.js.map +1 -1
  508. package/dist/models/swap.d.ts +9 -12
  509. package/dist/models/swap.js +55 -52
  510. package/dist/models/swap.js.map +1 -1
  511. package/dist/models/tax-line.d.ts +3 -5
  512. package/dist/models/tax-line.js +20 -14
  513. package/dist/models/tax-line.js.map +1 -1
  514. package/dist/models/tax-rate.d.ts +3 -5
  515. package/dist/models/tax-rate.js +22 -19
  516. package/dist/models/tax-rate.js.map +1 -1
  517. package/dist/models/tracking-link.d.ts +3 -6
  518. package/dist/models/tracking-link.js +26 -27
  519. package/dist/models/tracking-link.js.map +1 -1
  520. package/dist/models/user.d.ts +3 -6
  521. package/dist/models/user.js +22 -23
  522. package/dist/models/user.js.map +1 -1
  523. package/dist/repositories/batch-job.d.ts +4 -0
  524. package/dist/repositories/batch-job.js +38 -0
  525. package/dist/repositories/batch-job.js.map +1 -0
  526. package/dist/repositories/cart.d.ts +2 -2
  527. package/dist/repositories/cart.js.map +1 -1
  528. package/dist/repositories/customer.d.ts +1 -1
  529. package/dist/repositories/customer.js +7 -9
  530. package/dist/repositories/customer.js.map +1 -1
  531. package/dist/repositories/discount-condition.d.ts +38 -0
  532. package/dist/repositories/discount-condition.js +398 -0
  533. package/dist/repositories/discount-condition.js.map +1 -0
  534. package/dist/repositories/line-item-adjustment.d.ts +4 -0
  535. package/dist/repositories/line-item-adjustment.js +38 -0
  536. package/dist/repositories/line-item-adjustment.js.map +1 -0
  537. package/dist/repositories/line-item-tax-line.d.ts +2 -0
  538. package/dist/repositories/line-item-tax-line.js +80 -0
  539. package/dist/repositories/line-item-tax-line.js.map +1 -1
  540. package/dist/repositories/line-item.js +1 -0
  541. package/dist/repositories/line-item.js.map +1 -1
  542. package/dist/repositories/money-amount.d.ts +8 -2
  543. package/dist/repositories/money-amount.js +177 -2
  544. package/dist/repositories/money-amount.js.map +1 -1
  545. package/dist/repositories/order.d.ts +1 -1
  546. package/dist/repositories/price-list.d.ts +11 -0
  547. package/dist/repositories/price-list.js +247 -0
  548. package/dist/repositories/price-list.js.map +1 -0
  549. package/dist/repositories/product.d.ts +5 -1
  550. package/dist/repositories/product.js +96 -18
  551. package/dist/repositories/product.js.map +1 -1
  552. package/dist/repositories/shipping-method-tax-line.d.ts +2 -0
  553. package/dist/repositories/shipping-method-tax-line.js +80 -0
  554. package/dist/repositories/shipping-method-tax-line.js.map +1 -1
  555. package/dist/scripts/discount-rule-migration.d.ts +4 -0
  556. package/dist/scripts/discount-rule-migration.js +189 -0
  557. package/dist/scripts/discount-rule-migration.js.map +1 -0
  558. package/dist/scripts/line-item-adjustment-migration.d.ts +4 -0
  559. package/dist/scripts/line-item-adjustment-migration.js +173 -0
  560. package/dist/scripts/line-item-adjustment-migration.js.map +1 -0
  561. package/dist/services/batch-job.d.ts +24 -0
  562. package/dist/services/batch-job.js +126 -0
  563. package/dist/services/batch-job.js.map +1 -0
  564. package/dist/services/cart.d.ts +66 -55
  565. package/dist/services/cart.js +1315 -1405
  566. package/dist/services/cart.js.map +1 -1
  567. package/dist/services/claim-item.d.ts +23 -27
  568. package/dist/services/claim-item.js +217 -247
  569. package/dist/services/claim-item.js.map +1 -1
  570. package/dist/services/claim.d.ts +89 -71
  571. package/dist/services/claim.js +915 -840
  572. package/dist/services/claim.js.map +1 -1
  573. package/dist/services/customer.d.ts +0 -7
  574. package/dist/services/customer.js +8 -35
  575. package/dist/services/customer.js.map +1 -1
  576. package/dist/services/discount-condition.d.ts +31 -0
  577. package/dist/services/discount-condition.js +232 -0
  578. package/dist/services/discount-condition.js.map +1 -0
  579. package/dist/services/discount.d.ts +50 -59
  580. package/dist/services/discount.js +274 -176
  581. package/dist/services/discount.js.map +1 -1
  582. package/dist/services/draft-order.d.ts +69 -66
  583. package/dist/services/draft-order.js +375 -352
  584. package/dist/services/draft-order.js.map +1 -1
  585. package/dist/services/event-bus.d.ts +72 -56
  586. package/dist/services/event-bus.js +122 -99
  587. package/dist/services/event-bus.js.map +1 -1
  588. package/dist/services/file.d.ts +14 -0
  589. package/dist/services/file.js +43 -0
  590. package/dist/services/file.js.map +1 -0
  591. package/dist/services/fulfillment-provider.js +23 -17
  592. package/dist/services/fulfillment-provider.js.map +1 -1
  593. package/dist/services/invite.d.ts +4 -2
  594. package/dist/services/invite.js +11 -9
  595. package/dist/services/invite.js.map +1 -1
  596. package/dist/services/line-item-adjustment.d.ts +87 -0
  597. package/dist/services/line-item-adjustment.js +434 -0
  598. package/dist/services/line-item-adjustment.js.map +1 -0
  599. package/dist/services/line-item.d.ts +48 -40
  600. package/dist/services/line-item.js +226 -193
  601. package/dist/services/line-item.js.map +1 -1
  602. package/dist/services/order.d.ts +0 -13
  603. package/dist/services/order.js +4 -30
  604. package/dist/services/order.js.map +1 -1
  605. package/dist/services/payment-provider.js +23 -17
  606. package/dist/services/payment-provider.js.map +1 -1
  607. package/dist/services/price-list.d.ts +107 -0
  608. package/dist/services/price-list.js +740 -0
  609. package/dist/services/price-list.js.map +1 -0
  610. package/dist/services/pricing.d.ts +87 -0
  611. package/dist/services/pricing.js +443 -0
  612. package/dist/services/pricing.js.map +1 -0
  613. package/dist/services/product-tag.d.ts +2 -2
  614. package/dist/services/product-tag.js +15 -2
  615. package/dist/services/product-tag.js.map +1 -1
  616. package/dist/services/product-type.d.ts +1 -1
  617. package/dist/services/product-type.js +14 -1
  618. package/dist/services/product-type.js.map +1 -1
  619. package/dist/services/product-variant.d.ts +40 -16
  620. package/dist/services/product-variant.js +259 -109
  621. package/dist/services/product-variant.js.map +1 -1
  622. package/dist/services/product.d.ts +22 -11
  623. package/dist/services/product.js +251 -87
  624. package/dist/services/product.js.map +1 -1
  625. package/dist/services/region.js +12 -8
  626. package/dist/services/region.js.map +1 -1
  627. package/dist/services/return.js +2 -1
  628. package/dist/services/return.js.map +1 -1
  629. package/dist/services/shipping-option.d.ts +44 -109
  630. package/dist/services/shipping-option.js +309 -353
  631. package/dist/services/shipping-option.js.map +1 -1
  632. package/dist/services/store.d.ts +36 -45
  633. package/dist/services/store.js +207 -217
  634. package/dist/services/store.js.map +1 -1
  635. package/dist/services/swap.d.ts +4 -1
  636. package/dist/services/swap.js +29 -16
  637. package/dist/services/swap.js.map +1 -1
  638. package/dist/services/system-tax.d.ts +2 -3
  639. package/dist/services/system-tax.js +2 -2
  640. package/dist/services/system-tax.js.map +1 -1
  641. package/dist/services/tax-provider.d.ts +2 -0
  642. package/dist/services/tax-provider.js +96 -7
  643. package/dist/services/tax-provider.js.map +1 -1
  644. package/dist/services/tax-rate.d.ts +3 -3
  645. package/dist/services/tax-rate.js +1 -1
  646. package/dist/services/tax-rate.js.map +1 -1
  647. package/dist/services/totals.d.ts +9 -8
  648. package/dist/services/totals.js +41 -88
  649. package/dist/services/totals.js.map +1 -1
  650. package/dist/strategies/cart-completion.js.map +1 -1
  651. package/dist/strategies/price-selection.d.ts +13 -0
  652. package/dist/strategies/price-selection.js +185 -0
  653. package/dist/strategies/price-selection.js.map +1 -0
  654. package/dist/subscribers/order.js +1 -7
  655. package/dist/subscribers/order.js.map +1 -1
  656. package/dist/types/batch-job.d.ts +15 -0
  657. package/dist/types/batch-job.js +63 -0
  658. package/dist/types/batch-job.js.map +1 -0
  659. package/dist/types/cart.d.ts +2 -2
  660. package/dist/types/claim.d.ts +67 -0
  661. package/dist/types/claim.js +3 -0
  662. package/dist/types/claim.js.map +1 -0
  663. package/dist/types/common.d.ts +53 -13
  664. package/dist/types/common.js +1 -0
  665. package/dist/types/common.js.map +1 -1
  666. package/dist/types/discount.d.ts +68 -1
  667. package/dist/types/discount.js +129 -5
  668. package/dist/types/discount.js.map +1 -1
  669. package/dist/types/global.d.ts +53 -0
  670. package/dist/types/global.js +3 -0
  671. package/dist/types/global.js.map +1 -0
  672. package/dist/types/line-item-adjustment.d.ts +9 -0
  673. package/dist/types/line-item-adjustment.js +50 -0
  674. package/dist/types/line-item-adjustment.js.map +1 -0
  675. package/dist/types/note.d.ts +1 -1
  676. package/dist/types/price-list.d.ts +73 -0
  677. package/dist/types/price-list.js +157 -0
  678. package/dist/types/price-list.js.map +1 -0
  679. package/dist/types/price-selection.d.ts +5 -0
  680. package/dist/types/price-selection.js +35 -0
  681. package/dist/types/price-selection.js.map +1 -0
  682. package/dist/types/pricing.d.ts +25 -0
  683. package/dist/types/pricing.js +3 -0
  684. package/dist/types/pricing.js.map +1 -0
  685. package/dist/types/product-variant.d.ts +24 -1
  686. package/dist/types/product-variant.js +65 -1
  687. package/dist/types/product-variant.js.map +1 -1
  688. package/dist/types/product.d.ts +18 -0
  689. package/dist/types/product.js +104 -5
  690. package/dist/types/product.js.map +1 -1
  691. package/dist/types/shipping-options.d.ts +56 -0
  692. package/dist/types/shipping-options.js +3 -0
  693. package/dist/types/shipping-options.js.map +1 -0
  694. package/dist/types/store.d.ts +9 -0
  695. package/dist/types/store.js +3 -0
  696. package/dist/types/store.js.map +1 -0
  697. package/dist/types/tax-service.d.ts +2 -2
  698. package/dist/types/user.d.ts +2 -2
  699. package/dist/types/validators/exactly-one.d.ts +6 -0
  700. package/dist/types/validators/exactly-one.js +37 -0
  701. package/dist/types/validators/exactly-one.js.map +1 -0
  702. package/dist/utils/build-query.d.ts +8 -0
  703. package/dist/utils/build-query.js +114 -0
  704. package/dist/utils/build-query.js.map +1 -0
  705. package/dist/utils/countries.d.ts +3 -2
  706. package/dist/utils/countries.js.map +1 -1
  707. package/dist/utils/currencies.d.ts +10 -1899
  708. package/dist/utils/currencies.js.map +1 -1
  709. package/dist/utils/date-helpers.d.ts +2 -0
  710. package/dist/utils/date-helpers.js +15 -0
  711. package/dist/utils/date-helpers.js.map +1 -0
  712. package/dist/utils/format-registration-name.d.ts +4 -4
  713. package/dist/utils/format-registration-name.js +7 -10
  714. package/dist/utils/format-registration-name.js.map +1 -1
  715. package/dist/utils/generate-entity-id.d.ts +6 -0
  716. package/dist/utils/generate-entity-id.js +19 -0
  717. package/dist/utils/generate-entity-id.js.map +1 -0
  718. package/dist/utils/get-query-config.d.ts +9 -0
  719. package/dist/utils/get-query-config.js +133 -0
  720. package/dist/utils/get-query-config.js.map +1 -0
  721. package/dist/utils/index.d.ts +4 -0
  722. package/dist/utils/index.js +17 -0
  723. package/dist/utils/index.js.map +1 -0
  724. package/dist/utils/set-metadata.d.ts +9 -0
  725. package/dist/utils/set-metadata.js +72 -0
  726. package/dist/utils/set-metadata.js.map +1 -0
  727. package/dist/utils/sleep.d.ts +1 -0
  728. package/dist/utils/sleep.js +50 -0
  729. package/dist/utils/sleep.js.map +1 -0
  730. package/dist/utils/validate-id.d.ts +4 -0
  731. package/dist/utils/validate-id.js +47 -0
  732. package/dist/utils/validate-id.js.map +1 -0
  733. package/jest.config.js +6 -0
  734. package/package.json +11 -9
  735. package/tsconfig.spec.json +10 -0
  736. package/yarn-error.log +23292 -1023
@@ -84,18 +84,23 @@ var __values = (this && this.__values) || function(o) {
84
84
  throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
85
85
  };
86
86
  Object.defineProperty(exports, "__esModule", { value: true });
87
+ var models_1 = require("../models");
87
88
  var medusa_core_utils_1 = require("medusa-core-utils");
88
- var medusa_interfaces_1 = require("medusa-interfaces");
89
+ var interfaces_1 = require("../interfaces");
90
+ var utils_1 = require("../utils");
89
91
  var ClaimService = /** @class */ (function (_super) {
90
92
  __extends(ClaimService, _super);
91
93
  function ClaimService(_a) {
92
- var manager = _a.manager, addressRepository = _a.addressRepository, claimItemService = _a.claimItemService, claimRepository = _a.claimRepository, eventBusService = _a.eventBusService, fulfillmentProviderService = _a.fulfillmentProviderService, fulfillmentService = _a.fulfillmentService, inventoryService = _a.inventoryService, lineItemService = _a.lineItemService, paymentProviderService = _a.paymentProviderService, regionService = _a.regionService, returnService = _a.returnService, shippingOptionService = _a.shippingOptionService, taxProviderService = _a.taxProviderService, totalsService = _a.totalsService;
93
- var _this = _super.call(this) || this;
94
- /** @private @constant {EntityManager} */
94
+ var manager = _a.manager, addressRepository = _a.addressRepository, claimRepository = _a.claimRepository, shippingMethodRepository = _a.shippingMethodRepository, lineItemRepository = _a.lineItemRepository, claimItemService = _a.claimItemService, eventBusService = _a.eventBusService, fulfillmentProviderService = _a.fulfillmentProviderService, fulfillmentService = _a.fulfillmentService, inventoryService = _a.inventoryService, lineItemService = _a.lineItemService, paymentProviderService = _a.paymentProviderService, regionService = _a.regionService, returnService = _a.returnService, shippingOptionService = _a.shippingOptionService, taxProviderService = _a.taxProviderService, totalsService = _a.totalsService;
95
+ var _this =
96
+ // eslint-disable-next-line prefer-rest-params
97
+ _super.call(this, arguments[0]) || this;
95
98
  _this.manager_ = manager;
96
- _this.addressRepo_ = addressRepository;
97
- _this.claimItemService_ = claimItemService;
99
+ _this.addressRepository_ = addressRepository;
98
100
  _this.claimRepository_ = claimRepository;
101
+ _this.shippingMethodRepository_ = shippingMethodRepository;
102
+ _this.lineItemRepository_ = lineItemRepository;
103
+ _this.claimItemService_ = claimItemService;
99
104
  _this.eventBus_ = eventBusService;
100
105
  _this.fulfillmentProviderService_ = fulfillmentProviderService;
101
106
  _this.fulfillmentService_ = fulfillmentService;
@@ -109,641 +114,696 @@ var ClaimService = /** @class */ (function (_super) {
109
114
  _this.totalsService_ = totalsService;
110
115
  return _this;
111
116
  }
112
- ClaimService.prototype.withTransaction = function (manager) {
113
- if (!manager) {
114
- return this;
115
- }
116
- var cloned = new ClaimService({
117
- manager: manager,
118
- addressRepository: this.addressRepo_,
119
- claimItemService: this.claimItemService_,
120
- claimRepository: this.claimRepository_,
121
- eventBusService: this.eventBus_,
122
- fulfillmentProviderService: this.fulfillmentProviderService_,
123
- fulfillmentService: this.fulfillmentService_,
124
- inventoryService: this.inventoryService_,
125
- lineItemService: this.lineItemService_,
126
- paymentProviderService: this.paymentProviderService_,
127
- regionService: this.regionService_,
128
- returnService: this.returnService_,
129
- shippingOptionService: this.shippingOptionService_,
130
- totalsService: this.totalsService_,
131
- taxProviderService: this.taxProviderService_,
132
- });
133
- cloned.transactionManager_ = manager;
134
- return cloned;
135
- };
136
117
  ClaimService.prototype.update = function (id, data) {
137
- var _this = this;
138
- return this.atomicPhase_(function (manager) { return __awaiter(_this, void 0, void 0, function () {
139
- var claimRepo, claim, claim_items, shipping_methods, metadata, no_notification, _a, _b, m, e_1_1, shipping_methods_1, shipping_methods_1_1, method, e_2_1, claim_items_1, claim_items_1_1, i, e_3_1;
140
- var e_1, _c, e_2, _d, e_3, _e;
141
- return __generator(this, function (_f) {
142
- switch (_f.label) {
143
- case 0:
144
- claimRepo = manager.getCustomRepository(this.claimRepository_);
145
- return [4 /*yield*/, this.retrieve(id, { relations: ["shipping_methods"] })];
146
- case 1:
147
- claim = _f.sent();
148
- if (claim.canceled_at) {
149
- throw new medusa_core_utils_1.MedusaError(medusa_core_utils_1.MedusaError.Types.NOT_ALLOWED, "Canceled claim cannot be updated");
150
- }
151
- claim_items = data.claim_items, shipping_methods = data.shipping_methods, metadata = data.metadata, no_notification = data.no_notification;
152
- if (!metadata) return [3 /*break*/, 3];
153
- claim.metadata = this.setMetadata_(claim, metadata);
154
- return [4 /*yield*/, claimRepo.save(claim)];
155
- case 2:
156
- _f.sent();
157
- _f.label = 3;
158
- case 3:
159
- if (!shipping_methods) return [3 /*break*/, 20];
160
- _f.label = 4;
161
- case 4:
162
- _f.trys.push([4, 9, 10, 11]);
163
- _a = __values(claim.shipping_methods), _b = _a.next();
164
- _f.label = 5;
165
- case 5:
166
- if (!!_b.done) return [3 /*break*/, 8];
167
- m = _b.value;
168
- return [4 /*yield*/, this.shippingOptionService_
169
- .withTransaction(manager)
170
- .updateShippingMethod(m.id, {
171
- claim_order_id: null,
172
- })];
173
- case 6:
174
- _f.sent();
175
- _f.label = 7;
176
- case 7:
177
- _b = _a.next();
178
- return [3 /*break*/, 5];
179
- case 8: return [3 /*break*/, 11];
180
- case 9:
181
- e_1_1 = _f.sent();
182
- e_1 = { error: e_1_1 };
183
- return [3 /*break*/, 11];
184
- case 10:
185
- try {
186
- if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
187
- }
188
- finally { if (e_1) throw e_1.error; }
189
- return [7 /*endfinally*/];
190
- case 11:
191
- _f.trys.push([11, 18, 19, 20]);
192
- shipping_methods_1 = __values(shipping_methods), shipping_methods_1_1 = shipping_methods_1.next();
193
- _f.label = 12;
194
- case 12:
195
- if (!!shipping_methods_1_1.done) return [3 /*break*/, 17];
196
- method = shipping_methods_1_1.value;
197
- if (!method.id) return [3 /*break*/, 14];
198
- return [4 /*yield*/, this.shippingOptionService_
199
- .withTransaction(manager)
200
- .updateShippingMethod(method.id, {
201
- claim_order_id: claim.id,
202
- })];
203
- case 13:
204
- _f.sent();
205
- return [3 /*break*/, 16];
206
- case 14: return [4 /*yield*/, this.shippingOptionService_
207
- .withTransaction(manager)
208
- .createShippingMethod(method.option_id, method.data, {
209
- claim_order_id: claim.id,
210
- price: method.price,
211
- })];
212
- case 15:
213
- _f.sent();
214
- _f.label = 16;
215
- case 16:
216
- shipping_methods_1_1 = shipping_methods_1.next();
217
- return [3 /*break*/, 12];
218
- case 17: return [3 /*break*/, 20];
219
- case 18:
220
- e_2_1 = _f.sent();
221
- e_2 = { error: e_2_1 };
222
- return [3 /*break*/, 20];
223
- case 19:
224
- try {
225
- if (shipping_methods_1_1 && !shipping_methods_1_1.done && (_d = shipping_methods_1.return)) _d.call(shipping_methods_1);
226
- }
227
- finally { if (e_2) throw e_2.error; }
228
- return [7 /*endfinally*/];
229
- case 20:
230
- if (!(no_notification !== undefined)) return [3 /*break*/, 22];
231
- claim.no_notification = no_notification;
232
- return [4 /*yield*/, claimRepo.save(claim)];
233
- case 21:
234
- _f.sent();
235
- _f.label = 22;
236
- case 22:
237
- if (!claim_items) return [3 /*break*/, 30];
238
- _f.label = 23;
239
- case 23:
240
- _f.trys.push([23, 28, 29, 30]);
241
- claim_items_1 = __values(claim_items), claim_items_1_1 = claim_items_1.next();
242
- _f.label = 24;
243
- case 24:
244
- if (!!claim_items_1_1.done) return [3 /*break*/, 27];
245
- i = claim_items_1_1.value;
246
- if (!i.id) return [3 /*break*/, 26];
247
- return [4 /*yield*/, this.claimItemService_
248
- .withTransaction(manager)
249
- .update(i.id, i)];
250
- case 25:
251
- _f.sent();
252
- _f.label = 26;
253
- case 26:
254
- claim_items_1_1 = claim_items_1.next();
255
- return [3 /*break*/, 24];
256
- case 27: return [3 /*break*/, 30];
257
- case 28:
258
- e_3_1 = _f.sent();
259
- e_3 = { error: e_3_1 };
260
- return [3 /*break*/, 30];
261
- case 29:
262
- try {
263
- if (claim_items_1_1 && !claim_items_1_1.done && (_e = claim_items_1.return)) _e.call(claim_items_1);
264
- }
265
- finally { if (e_3) throw e_3.error; }
266
- return [7 /*endfinally*/];
267
- case 30: return [4 /*yield*/, this.eventBus_
268
- .withTransaction(manager)
269
- .emit(ClaimService.Events.UPDATED, {
270
- id: claim.id,
271
- no_notification: claim.no_notification,
272
- })];
273
- case 31:
274
- _f.sent();
275
- return [2 /*return*/, claim];
118
+ return __awaiter(this, void 0, void 0, function () {
119
+ var _this = this;
120
+ return __generator(this, function (_a) {
121
+ switch (_a.label) {
122
+ case 0: return [4 /*yield*/, this.atomicPhase_(function (transactionManager) { return __awaiter(_this, void 0, void 0, function () {
123
+ var claimRepo, claim, claim_items, shipping_methods, metadata, no_notification, _a, _b, m, e_1_1, shipping_methods_1, shipping_methods_1_1, method, e_2_1, claim_items_1, claim_items_1_1, i, e_3_1;
124
+ var e_1, _c, e_2, _d, e_3, _e;
125
+ return __generator(this, function (_f) {
126
+ switch (_f.label) {
127
+ case 0:
128
+ claimRepo = transactionManager.getCustomRepository(this.claimRepository_);
129
+ return [4 /*yield*/, this.retrieve(id, {
130
+ relations: ["shipping_methods"],
131
+ })];
132
+ case 1:
133
+ claim = _f.sent();
134
+ if (claim.canceled_at) {
135
+ throw new medusa_core_utils_1.MedusaError(medusa_core_utils_1.MedusaError.Types.NOT_ALLOWED, "Canceled claim cannot be updated");
136
+ }
137
+ claim_items = data.claim_items, shipping_methods = data.shipping_methods, metadata = data.metadata, no_notification = data.no_notification;
138
+ if (!metadata) return [3 /*break*/, 3];
139
+ claim.metadata = (0, utils_1.setMetadata)(claim, metadata);
140
+ return [4 /*yield*/, claimRepo.save(claim)];
141
+ case 2:
142
+ _f.sent();
143
+ _f.label = 3;
144
+ case 3:
145
+ if (!shipping_methods) return [3 /*break*/, 20];
146
+ _f.label = 4;
147
+ case 4:
148
+ _f.trys.push([4, 9, 10, 11]);
149
+ _a = __values(claim.shipping_methods), _b = _a.next();
150
+ _f.label = 5;
151
+ case 5:
152
+ if (!!_b.done) return [3 /*break*/, 8];
153
+ m = _b.value;
154
+ return [4 /*yield*/, this.shippingOptionService_
155
+ .withTransaction(transactionManager)
156
+ .updateShippingMethod(m.id, {
157
+ claim_order_id: null,
158
+ })];
159
+ case 6:
160
+ _f.sent();
161
+ _f.label = 7;
162
+ case 7:
163
+ _b = _a.next();
164
+ return [3 /*break*/, 5];
165
+ case 8: return [3 /*break*/, 11];
166
+ case 9:
167
+ e_1_1 = _f.sent();
168
+ e_1 = { error: e_1_1 };
169
+ return [3 /*break*/, 11];
170
+ case 10:
171
+ try {
172
+ if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
173
+ }
174
+ finally { if (e_1) throw e_1.error; }
175
+ return [7 /*endfinally*/];
176
+ case 11:
177
+ _f.trys.push([11, 18, 19, 20]);
178
+ shipping_methods_1 = __values(shipping_methods), shipping_methods_1_1 = shipping_methods_1.next();
179
+ _f.label = 12;
180
+ case 12:
181
+ if (!!shipping_methods_1_1.done) return [3 /*break*/, 17];
182
+ method = shipping_methods_1_1.value;
183
+ if (!method.id) return [3 /*break*/, 14];
184
+ return [4 /*yield*/, this.shippingOptionService_
185
+ .withTransaction(transactionManager)
186
+ .updateShippingMethod(method.id, {
187
+ claim_order_id: claim.id,
188
+ })];
189
+ case 13:
190
+ _f.sent();
191
+ return [3 /*break*/, 16];
192
+ case 14: return [4 /*yield*/, this.shippingOptionService_
193
+ .withTransaction(transactionManager)
194
+ .createShippingMethod(method.option_id, method.data, {
195
+ claim_order_id: claim.id,
196
+ price: method.price,
197
+ })];
198
+ case 15:
199
+ _f.sent();
200
+ _f.label = 16;
201
+ case 16:
202
+ shipping_methods_1_1 = shipping_methods_1.next();
203
+ return [3 /*break*/, 12];
204
+ case 17: return [3 /*break*/, 20];
205
+ case 18:
206
+ e_2_1 = _f.sent();
207
+ e_2 = { error: e_2_1 };
208
+ return [3 /*break*/, 20];
209
+ case 19:
210
+ try {
211
+ if (shipping_methods_1_1 && !shipping_methods_1_1.done && (_d = shipping_methods_1.return)) _d.call(shipping_methods_1);
212
+ }
213
+ finally { if (e_2) throw e_2.error; }
214
+ return [7 /*endfinally*/];
215
+ case 20:
216
+ if (!(no_notification !== undefined)) return [3 /*break*/, 22];
217
+ claim.no_notification = no_notification;
218
+ return [4 /*yield*/, claimRepo.save(claim)];
219
+ case 21:
220
+ _f.sent();
221
+ _f.label = 22;
222
+ case 22:
223
+ if (!claim_items) return [3 /*break*/, 30];
224
+ _f.label = 23;
225
+ case 23:
226
+ _f.trys.push([23, 28, 29, 30]);
227
+ claim_items_1 = __values(claim_items), claim_items_1_1 = claim_items_1.next();
228
+ _f.label = 24;
229
+ case 24:
230
+ if (!!claim_items_1_1.done) return [3 /*break*/, 27];
231
+ i = claim_items_1_1.value;
232
+ if (!i.id) return [3 /*break*/, 26];
233
+ return [4 /*yield*/, this.claimItemService_
234
+ .withTransaction(transactionManager)
235
+ .update(i.id, i)];
236
+ case 25:
237
+ _f.sent();
238
+ _f.label = 26;
239
+ case 26:
240
+ claim_items_1_1 = claim_items_1.next();
241
+ return [3 /*break*/, 24];
242
+ case 27: return [3 /*break*/, 30];
243
+ case 28:
244
+ e_3_1 = _f.sent();
245
+ e_3 = { error: e_3_1 };
246
+ return [3 /*break*/, 30];
247
+ case 29:
248
+ try {
249
+ if (claim_items_1_1 && !claim_items_1_1.done && (_e = claim_items_1.return)) _e.call(claim_items_1);
250
+ }
251
+ finally { if (e_3) throw e_3.error; }
252
+ return [7 /*endfinally*/];
253
+ case 30: return [4 /*yield*/, this.eventBus_
254
+ .withTransaction(transactionManager)
255
+ .emit(ClaimService.Events.UPDATED, {
256
+ id: claim.id,
257
+ no_notification: claim.no_notification,
258
+ })];
259
+ case 31:
260
+ _f.sent();
261
+ return [2 /*return*/, claim];
262
+ }
263
+ });
264
+ }); })];
265
+ case 1: return [2 /*return*/, _a.sent()];
276
266
  }
277
267
  });
278
- }); });
268
+ });
279
269
  };
280
270
  /**
281
271
  * Creates a Claim on an Order. Claims consists of items that are claimed and
282
272
  * optionally items to be sent as replacement for the claimed items. The
283
273
  * shipping address that the new items will be shipped to
284
- * @param {Object} data - the object containing all data required to create a claim
285
- * @return {Object} created claim
274
+ * @param data - the object containing all data required to create a claim
275
+ * @return created claim
286
276
  */
287
277
  ClaimService.prototype.create = function (data) {
288
- var _this = this;
289
- return this.atomicPhase_(function (manager) { return __awaiter(_this, void 0, void 0, function () {
290
- var claimRepo, type, claim_items, order, return_shipping, additional_items, shipping_methods, refund_amount, shipping_address, shipping_address_id, no_notification, rest, claim_items_2, claim_items_2_1, item, line, e_4_1, addressId, addressRepo, created_1, saved, toRefund, lines, newItems, additional_items_1, additional_items_1_1, item, e_5_1, newItems_1, newItems_1_1, newItem, e_6_1, evaluatedNoNotification, created, result, calcContext, lineItems, shipping_methods_2, shipping_methods_2_1, method, e_7_1, claim_items_3, claim_items_3_1, ci, e_8_1;
291
- var e_4, _a, e_5, _b, e_6, _c, e_7, _d, e_8, _e;
278
+ return __awaiter(this, void 0, void 0, function () {
292
279
  var _this = this;
293
- var _f, _g, _h;
294
- return __generator(this, function (_j) {
295
- switch (_j.label) {
296
- case 0:
297
- claimRepo = manager.getCustomRepository(this.claimRepository_);
298
- type = data.type, claim_items = data.claim_items, order = data.order, return_shipping = data.return_shipping, additional_items = data.additional_items, shipping_methods = data.shipping_methods, refund_amount = data.refund_amount, shipping_address = data.shipping_address, shipping_address_id = data.shipping_address_id, no_notification = data.no_notification, rest = __rest(data, ["type", "claim_items", "order", "return_shipping", "additional_items", "shipping_methods", "refund_amount", "shipping_address", "shipping_address_id", "no_notification"]);
299
- _j.label = 1;
300
- case 1:
301
- _j.trys.push([1, 6, 7, 8]);
302
- claim_items_2 = __values(claim_items), claim_items_2_1 = claim_items_2.next();
303
- _j.label = 2;
304
- case 2:
305
- if (!!claim_items_2_1.done) return [3 /*break*/, 5];
306
- item = claim_items_2_1.value;
307
- return [4 /*yield*/, this.lineItemService_.retrieve(item.item_id, {
308
- relations: ["order", "swap", "claim_order", "tax_lines"],
309
- })];
310
- case 3:
311
- line = _j.sent();
312
- if (((_f = line.order) === null || _f === void 0 ? void 0 : _f.canceled_at) ||
313
- ((_g = line.swap) === null || _g === void 0 ? void 0 : _g.canceled_at) ||
314
- ((_h = line.claim_order) === null || _h === void 0 ? void 0 : _h.canceled_at)) {
315
- throw new medusa_core_utils_1.MedusaError(medusa_core_utils_1.MedusaError.Types.INVALID_DATA, "Cannot create a claim on a canceled item.");
316
- }
317
- _j.label = 4;
318
- case 4:
319
- claim_items_2_1 = claim_items_2.next();
320
- return [3 /*break*/, 2];
321
- case 5: return [3 /*break*/, 8];
322
- case 6:
323
- e_4_1 = _j.sent();
324
- e_4 = { error: e_4_1 };
325
- return [3 /*break*/, 8];
326
- case 7:
327
- try {
328
- if (claim_items_2_1 && !claim_items_2_1.done && (_a = claim_items_2.return)) _a.call(claim_items_2);
329
- }
330
- finally { if (e_4) throw e_4.error; }
331
- return [7 /*endfinally*/];
332
- case 8:
333
- addressId = shipping_address_id || order.shipping_address_id;
334
- if (!shipping_address) return [3 /*break*/, 10];
335
- addressRepo = manager.getCustomRepository(this.addressRepo_);
336
- created_1 = addressRepo.create(shipping_address);
337
- return [4 /*yield*/, addressRepo.save(created_1)];
338
- case 9:
339
- saved = _j.sent();
340
- addressId = saved.id;
341
- _j.label = 10;
342
- case 10:
343
- if (type !== "refund" && type !== "replace") {
344
- throw new medusa_core_utils_1.MedusaError(medusa_core_utils_1.MedusaError.Types.INVALID_DATA, "Claim type must be one of \"refund\" or \"replace\".");
345
- }
346
- if (type === "replace" && !(additional_items === null || additional_items === void 0 ? void 0 : additional_items.length)) {
347
- throw new medusa_core_utils_1.MedusaError(medusa_core_utils_1.MedusaError.Types.INVALID_DATA, "Claims with type \"replace\" must have at least one additional item.");
348
- }
349
- if (!(claim_items === null || claim_items === void 0 ? void 0 : claim_items.length)) {
350
- throw new medusa_core_utils_1.MedusaError(medusa_core_utils_1.MedusaError.Types.INVALID_DATA, "Claims must have at least one claim item.");
351
- }
352
- if (refund_amount && type !== "refund") {
353
- throw new medusa_core_utils_1.MedusaError(medusa_core_utils_1.MedusaError.Types.INVALID_DATA, "Claim has type \"".concat(type, "\" but must be type \"refund\" to have a refund_amount."));
354
- }
355
- toRefund = refund_amount;
356
- if (!(type === "refund" && typeof refund_amount === "undefined")) return [3 /*break*/, 12];
357
- lines = claim_items.map(function (ci) {
358
- var orderItem = order.items.find(function (oi) { return oi.id === ci.item_id; });
359
- return __assign(__assign({}, orderItem), { quantity: ci.quantity });
360
- });
361
- return [4 /*yield*/, this.totalsService_.getRefundTotal(order, lines)];
362
- case 11:
363
- toRefund = _j.sent();
364
- _j.label = 12;
365
- case 12:
366
- newItems = [];
367
- if (!(typeof additional_items !== "undefined")) return [3 /*break*/, 29];
368
- _j.label = 13;
369
- case 13:
370
- _j.trys.push([13, 18, 19, 20]);
371
- additional_items_1 = __values(additional_items), additional_items_1_1 = additional_items_1.next();
372
- _j.label = 14;
373
- case 14:
374
- if (!!additional_items_1_1.done) return [3 /*break*/, 17];
375
- item = additional_items_1_1.value;
376
- return [4 /*yield*/, this.inventoryService_
377
- .withTransaction(manager)
378
- .confirmInventory(item.variant_id, item.quantity)];
379
- case 15:
380
- _j.sent();
381
- _j.label = 16;
382
- case 16:
383
- additional_items_1_1 = additional_items_1.next();
384
- return [3 /*break*/, 14];
385
- case 17: return [3 /*break*/, 20];
386
- case 18:
387
- e_5_1 = _j.sent();
388
- e_5 = { error: e_5_1 };
389
- return [3 /*break*/, 20];
390
- case 19:
391
- try {
392
- if (additional_items_1_1 && !additional_items_1_1.done && (_b = additional_items_1.return)) _b.call(additional_items_1);
393
- }
394
- finally { if (e_5) throw e_5.error; }
395
- return [7 /*endfinally*/];
396
- case 20: return [4 /*yield*/, Promise.all(additional_items.map(function (i) {
397
- return _this.lineItemService_
398
- .withTransaction(manager)
399
- .generate(i.variant_id, order.region_id, i.quantity);
400
- }))];
401
- case 21:
402
- newItems = _j.sent();
403
- _j.label = 22;
404
- case 22:
405
- _j.trys.push([22, 27, 28, 29]);
406
- newItems_1 = __values(newItems), newItems_1_1 = newItems_1.next();
407
- _j.label = 23;
408
- case 23:
409
- if (!!newItems_1_1.done) return [3 /*break*/, 26];
410
- newItem = newItems_1_1.value;
411
- return [4 /*yield*/, this.inventoryService_
412
- .withTransaction(manager)
413
- .adjustInventory(newItem.variant_id, -newItem.quantity)];
414
- case 24:
415
- _j.sent();
416
- _j.label = 25;
417
- case 25:
418
- newItems_1_1 = newItems_1.next();
419
- return [3 /*break*/, 23];
420
- case 26: return [3 /*break*/, 29];
421
- case 27:
422
- e_6_1 = _j.sent();
423
- e_6 = { error: e_6_1 };
424
- return [3 /*break*/, 29];
425
- case 28:
426
- try {
427
- if (newItems_1_1 && !newItems_1_1.done && (_c = newItems_1.return)) _c.call(newItems_1);
428
- }
429
- finally { if (e_6) throw e_6.error; }
430
- return [7 /*endfinally*/];
431
- case 29:
432
- evaluatedNoNotification = no_notification !== undefined ? no_notification : order.no_notification;
433
- created = claimRepo.create(__assign(__assign({ shipping_address_id: addressId, payment_status: type === "refund" ? "not_refunded" : "na" }, rest), { refund_amount: toRefund, type: type, additional_items: newItems, order_id: order.id, no_notification: evaluatedNoNotification }));
434
- return [4 /*yield*/, claimRepo.save(created)];
435
- case 30:
436
- result = _j.sent();
437
- if (!(result.additional_items && result.additional_items.length)) return [3 /*break*/, 33];
438
- calcContext = this.totalsService_.getCalculationContext(order);
439
- return [4 /*yield*/, this.lineItemService_
440
- .withTransaction(manager)
441
- .list({
442
- id: result.additional_items.map(function (i) { return i.id; }),
443
- })];
444
- case 31:
445
- lineItems = _j.sent();
446
- return [4 /*yield*/, this.taxProviderService_
447
- .withTransaction(manager)
448
- .createTaxLines(lineItems, calcContext)];
449
- case 32:
450
- _j.sent();
451
- _j.label = 33;
452
- case 33:
453
- if (!shipping_methods) return [3 /*break*/, 43];
454
- _j.label = 34;
455
- case 34:
456
- _j.trys.push([34, 41, 42, 43]);
457
- shipping_methods_2 = __values(shipping_methods), shipping_methods_2_1 = shipping_methods_2.next();
458
- _j.label = 35;
459
- case 35:
460
- if (!!shipping_methods_2_1.done) return [3 /*break*/, 40];
461
- method = shipping_methods_2_1.value;
462
- if (!method.id) return [3 /*break*/, 37];
463
- return [4 /*yield*/, this.shippingOptionService_
464
- .withTransaction(manager)
465
- .updateShippingMethod(method.id, {
466
- claim_order_id: result.id,
467
- })];
468
- case 36:
469
- _j.sent();
470
- return [3 /*break*/, 39];
471
- case 37: return [4 /*yield*/, this.shippingOptionService_
472
- .withTransaction(manager)
473
- .createShippingMethod(method.option_id, method.data, {
474
- claim_order_id: result.id,
475
- price: method.price,
476
- })];
477
- case 38:
478
- _j.sent();
479
- _j.label = 39;
480
- case 39:
481
- shipping_methods_2_1 = shipping_methods_2.next();
482
- return [3 /*break*/, 35];
483
- case 40: return [3 /*break*/, 43];
484
- case 41:
485
- e_7_1 = _j.sent();
486
- e_7 = { error: e_7_1 };
487
- return [3 /*break*/, 43];
488
- case 42:
489
- try {
490
- if (shipping_methods_2_1 && !shipping_methods_2_1.done && (_d = shipping_methods_2.return)) _d.call(shipping_methods_2);
491
- }
492
- finally { if (e_7) throw e_7.error; }
493
- return [7 /*endfinally*/];
494
- case 43:
495
- _j.trys.push([43, 48, 49, 50]);
496
- claim_items_3 = __values(claim_items), claim_items_3_1 = claim_items_3.next();
497
- _j.label = 44;
498
- case 44:
499
- if (!!claim_items_3_1.done) return [3 /*break*/, 47];
500
- ci = claim_items_3_1.value;
501
- return [4 /*yield*/, this.claimItemService_.withTransaction(manager).create(__assign(__assign({}, ci), { claim_order_id: result.id }))];
502
- case 45:
503
- _j.sent();
504
- _j.label = 46;
505
- case 46:
506
- claim_items_3_1 = claim_items_3.next();
507
- return [3 /*break*/, 44];
508
- case 47: return [3 /*break*/, 50];
509
- case 48:
510
- e_8_1 = _j.sent();
511
- e_8 = { error: e_8_1 };
512
- return [3 /*break*/, 50];
513
- case 49:
514
- try {
515
- if (claim_items_3_1 && !claim_items_3_1.done && (_e = claim_items_3.return)) _e.call(claim_items_3);
516
- }
517
- finally { if (e_8) throw e_8.error; }
518
- return [7 /*endfinally*/];
519
- case 50:
520
- if (!return_shipping) return [3 /*break*/, 52];
521
- return [4 /*yield*/, this.returnService_.withTransaction(manager).create({
522
- order_id: order.id,
523
- claim_order_id: result.id,
524
- items: claim_items.map(function (ci) { return ({
525
- item_id: ci.item_id,
526
- quantity: ci.quantity,
527
- metadata: ci.metadata,
528
- }); }),
529
- shipping_method: return_shipping,
530
- no_notification: evaluatedNoNotification,
531
- })];
532
- case 51:
533
- _j.sent();
534
- _j.label = 52;
535
- case 52: return [4 /*yield*/, this.eventBus_
536
- .withTransaction(manager)
537
- .emit(ClaimService.Events.CREATED, {
538
- id: result.id,
539
- no_notification: result.no_notification,
540
- })];
541
- case 53:
542
- _j.sent();
543
- return [2 /*return*/, result];
280
+ return __generator(this, function (_a) {
281
+ switch (_a.label) {
282
+ case 0: return [4 /*yield*/, this.atomicPhase_(function (transactionManager) { return __awaiter(_this, void 0, void 0, function () {
283
+ var claimRepo, type, claim_items, order, return_shipping, additional_items, shipping_methods, refund_amount, shipping_address, shipping_address_id, no_notification, rest, claim_items_2, claim_items_2_1, item, line, e_4_1, addressId, addressRepo, created_1, saved, toRefund, lines, newItems, additional_items_1, additional_items_1_1, item, e_5_1, newItems_1, newItems_1_1, newItem, e_6_1, evaluatedNoNotification, created, result, calcContext, lineItems, shipping_methods_2, shipping_methods_2_1, method, e_7_1, claim_items_3, claim_items_3_1, ci, e_8_1;
284
+ var e_4, _a, e_5, _b, e_6, _c, e_7, _d, e_8, _e;
285
+ var _this = this;
286
+ var _f, _g, _h;
287
+ return __generator(this, function (_j) {
288
+ switch (_j.label) {
289
+ case 0:
290
+ claimRepo = transactionManager.getCustomRepository(this.claimRepository_);
291
+ type = data.type, claim_items = data.claim_items, order = data.order, return_shipping = data.return_shipping, additional_items = data.additional_items, shipping_methods = data.shipping_methods, refund_amount = data.refund_amount, shipping_address = data.shipping_address, shipping_address_id = data.shipping_address_id, no_notification = data.no_notification, rest = __rest(data, ["type", "claim_items", "order", "return_shipping", "additional_items", "shipping_methods", "refund_amount", "shipping_address", "shipping_address_id", "no_notification"]);
292
+ _j.label = 1;
293
+ case 1:
294
+ _j.trys.push([1, 6, 7, 8]);
295
+ claim_items_2 = __values(claim_items), claim_items_2_1 = claim_items_2.next();
296
+ _j.label = 2;
297
+ case 2:
298
+ if (!!claim_items_2_1.done) return [3 /*break*/, 5];
299
+ item = claim_items_2_1.value;
300
+ return [4 /*yield*/, this.lineItemService_
301
+ .withTransaction(transactionManager)
302
+ .retrieve(item.item_id, {
303
+ relations: ["order", "swap", "claim_order", "tax_lines"],
304
+ })];
305
+ case 3:
306
+ line = _j.sent();
307
+ if (((_f = line.order) === null || _f === void 0 ? void 0 : _f.canceled_at) ||
308
+ ((_g = line.swap) === null || _g === void 0 ? void 0 : _g.canceled_at) ||
309
+ ((_h = line.claim_order) === null || _h === void 0 ? void 0 : _h.canceled_at)) {
310
+ throw new medusa_core_utils_1.MedusaError(medusa_core_utils_1.MedusaError.Types.INVALID_DATA, "Cannot create a claim on a canceled item.");
311
+ }
312
+ _j.label = 4;
313
+ case 4:
314
+ claim_items_2_1 = claim_items_2.next();
315
+ return [3 /*break*/, 2];
316
+ case 5: return [3 /*break*/, 8];
317
+ case 6:
318
+ e_4_1 = _j.sent();
319
+ e_4 = { error: e_4_1 };
320
+ return [3 /*break*/, 8];
321
+ case 7:
322
+ try {
323
+ if (claim_items_2_1 && !claim_items_2_1.done && (_a = claim_items_2.return)) _a.call(claim_items_2);
324
+ }
325
+ finally { if (e_4) throw e_4.error; }
326
+ return [7 /*endfinally*/];
327
+ case 8:
328
+ addressId = shipping_address_id || order.shipping_address_id;
329
+ if (!shipping_address) return [3 /*break*/, 10];
330
+ addressRepo = transactionManager.getCustomRepository(this.addressRepository_);
331
+ created_1 = addressRepo.create(shipping_address);
332
+ return [4 /*yield*/, addressRepo.save(created_1)];
333
+ case 9:
334
+ saved = _j.sent();
335
+ addressId = saved.id;
336
+ _j.label = 10;
337
+ case 10:
338
+ if (type !== models_1.ClaimType.REFUND && type !== models_1.ClaimType.REPLACE) {
339
+ throw new medusa_core_utils_1.MedusaError(medusa_core_utils_1.MedusaError.Types.INVALID_DATA, "Claim type must be one of \"refund\" or \"replace\".");
340
+ }
341
+ if (type === models_1.ClaimType.REPLACE && !(additional_items === null || additional_items === void 0 ? void 0 : additional_items.length)) {
342
+ throw new medusa_core_utils_1.MedusaError(medusa_core_utils_1.MedusaError.Types.INVALID_DATA, "Claims with type \"replace\" must have at least one additional item.");
343
+ }
344
+ if (!(claim_items === null || claim_items === void 0 ? void 0 : claim_items.length)) {
345
+ throw new medusa_core_utils_1.MedusaError(medusa_core_utils_1.MedusaError.Types.INVALID_DATA, "Claims must have at least one claim item.");
346
+ }
347
+ if (refund_amount && type !== models_1.ClaimType.REFUND) {
348
+ throw new medusa_core_utils_1.MedusaError(medusa_core_utils_1.MedusaError.Types.INVALID_DATA, "Claim has type \"".concat(type, "\" but must be type \"refund\" to have a refund_amount."));
349
+ }
350
+ toRefund = refund_amount;
351
+ if (!(type === models_1.ClaimType.REFUND && typeof refund_amount === "undefined")) return [3 /*break*/, 12];
352
+ lines = claim_items.map(function (ci) {
353
+ var e_9, _a, e_10, _b;
354
+ var _c, _d;
355
+ var allOrderItems = order.items;
356
+ if ((_c = order.swaps) === null || _c === void 0 ? void 0 : _c.length) {
357
+ try {
358
+ for (var _e = __values(order.swaps), _f = _e.next(); !_f.done; _f = _e.next()) {
359
+ var swap = _f.value;
360
+ swap.additional_items.forEach(function (it) {
361
+ if (it.shipped_quantity ||
362
+ it.shipped_quantity === it.fulfilled_quantity) {
363
+ allOrderItems.push(it);
364
+ }
365
+ });
366
+ }
367
+ }
368
+ catch (e_9_1) { e_9 = { error: e_9_1 }; }
369
+ finally {
370
+ try {
371
+ if (_f && !_f.done && (_a = _e.return)) _a.call(_e);
372
+ }
373
+ finally { if (e_9) throw e_9.error; }
374
+ }
375
+ }
376
+ if ((_d = order.claims) === null || _d === void 0 ? void 0 : _d.length) {
377
+ try {
378
+ for (var _g = __values(order.claims), _h = _g.next(); !_h.done; _h = _g.next()) {
379
+ var claim = _h.value;
380
+ claim.additional_items.forEach(function (it) {
381
+ if (it.shipped_quantity ||
382
+ it.shipped_quantity === it.fulfilled_quantity) {
383
+ allOrderItems.push(it);
384
+ }
385
+ });
386
+ }
387
+ }
388
+ catch (e_10_1) { e_10 = { error: e_10_1 }; }
389
+ finally {
390
+ try {
391
+ if (_h && !_h.done && (_b = _g.return)) _b.call(_g);
392
+ }
393
+ finally { if (e_10) throw e_10.error; }
394
+ }
395
+ }
396
+ var orderItem = allOrderItems.find(function (oi) { return oi.id === ci.item_id; });
397
+ return __assign(__assign({}, orderItem), { quantity: ci.quantity });
398
+ });
399
+ return [4 /*yield*/, this.totalsService_.getRefundTotal(order, lines)];
400
+ case 11:
401
+ toRefund = _j.sent();
402
+ _j.label = 12;
403
+ case 12:
404
+ newItems = [];
405
+ if (!(typeof additional_items !== "undefined")) return [3 /*break*/, 29];
406
+ _j.label = 13;
407
+ case 13:
408
+ _j.trys.push([13, 18, 19, 20]);
409
+ additional_items_1 = __values(additional_items), additional_items_1_1 = additional_items_1.next();
410
+ _j.label = 14;
411
+ case 14:
412
+ if (!!additional_items_1_1.done) return [3 /*break*/, 17];
413
+ item = additional_items_1_1.value;
414
+ return [4 /*yield*/, this.inventoryService_
415
+ .withTransaction(transactionManager)
416
+ .confirmInventory(item.variant_id, item.quantity)];
417
+ case 15:
418
+ _j.sent();
419
+ _j.label = 16;
420
+ case 16:
421
+ additional_items_1_1 = additional_items_1.next();
422
+ return [3 /*break*/, 14];
423
+ case 17: return [3 /*break*/, 20];
424
+ case 18:
425
+ e_5_1 = _j.sent();
426
+ e_5 = { error: e_5_1 };
427
+ return [3 /*break*/, 20];
428
+ case 19:
429
+ try {
430
+ if (additional_items_1_1 && !additional_items_1_1.done && (_b = additional_items_1.return)) _b.call(additional_items_1);
431
+ }
432
+ finally { if (e_5) throw e_5.error; }
433
+ return [7 /*endfinally*/];
434
+ case 20: return [4 /*yield*/, Promise.all(additional_items.map(function (i) {
435
+ return _this.lineItemService_
436
+ .withTransaction(transactionManager)
437
+ .generate(i.variant_id, order.region_id, i.quantity);
438
+ }))];
439
+ case 21:
440
+ newItems = _j.sent();
441
+ _j.label = 22;
442
+ case 22:
443
+ _j.trys.push([22, 27, 28, 29]);
444
+ newItems_1 = __values(newItems), newItems_1_1 = newItems_1.next();
445
+ _j.label = 23;
446
+ case 23:
447
+ if (!!newItems_1_1.done) return [3 /*break*/, 26];
448
+ newItem = newItems_1_1.value;
449
+ return [4 /*yield*/, this.inventoryService_
450
+ .withTransaction(transactionManager)
451
+ .adjustInventory(newItem.variant_id, -newItem.quantity)];
452
+ case 24:
453
+ _j.sent();
454
+ _j.label = 25;
455
+ case 25:
456
+ newItems_1_1 = newItems_1.next();
457
+ return [3 /*break*/, 23];
458
+ case 26: return [3 /*break*/, 29];
459
+ case 27:
460
+ e_6_1 = _j.sent();
461
+ e_6 = { error: e_6_1 };
462
+ return [3 /*break*/, 29];
463
+ case 28:
464
+ try {
465
+ if (newItems_1_1 && !newItems_1_1.done && (_c = newItems_1.return)) _c.call(newItems_1);
466
+ }
467
+ finally { if (e_6) throw e_6.error; }
468
+ return [7 /*endfinally*/];
469
+ case 29:
470
+ evaluatedNoNotification = no_notification !== undefined
471
+ ? no_notification
472
+ : order.no_notification;
473
+ created = claimRepo.create(__assign({ shipping_address_id: addressId, payment_status: type === models_1.ClaimType.REFUND ? "not_refunded" : "na", refund_amount: toRefund, type: type, additional_items: newItems, order_id: order.id, no_notification: evaluatedNoNotification }, rest));
474
+ return [4 /*yield*/, claimRepo.save(created)];
475
+ case 30:
476
+ result = _j.sent();
477
+ if (!(result.additional_items && result.additional_items.length)) return [3 /*break*/, 33];
478
+ calcContext = this.totalsService_.getCalculationContext(order);
479
+ return [4 /*yield*/, this.lineItemService_
480
+ .withTransaction(transactionManager)
481
+ .list({
482
+ id: result.additional_items.map(function (i) { return i.id; }),
483
+ })];
484
+ case 31:
485
+ lineItems = _j.sent();
486
+ return [4 /*yield*/, this.taxProviderService_
487
+ .withTransaction(transactionManager)
488
+ .createTaxLines(lineItems, calcContext)];
489
+ case 32:
490
+ _j.sent();
491
+ _j.label = 33;
492
+ case 33:
493
+ if (!shipping_methods) return [3 /*break*/, 43];
494
+ _j.label = 34;
495
+ case 34:
496
+ _j.trys.push([34, 41, 42, 43]);
497
+ shipping_methods_2 = __values(shipping_methods), shipping_methods_2_1 = shipping_methods_2.next();
498
+ _j.label = 35;
499
+ case 35:
500
+ if (!!shipping_methods_2_1.done) return [3 /*break*/, 40];
501
+ method = shipping_methods_2_1.value;
502
+ if (!method.id) return [3 /*break*/, 37];
503
+ return [4 /*yield*/, this.shippingOptionService_
504
+ .withTransaction(transactionManager)
505
+ .updateShippingMethod(method.id, {
506
+ claim_order_id: result.id,
507
+ })];
508
+ case 36:
509
+ _j.sent();
510
+ return [3 /*break*/, 39];
511
+ case 37: return [4 /*yield*/, this.shippingOptionService_
512
+ .withTransaction(transactionManager)
513
+ .createShippingMethod(method.option_id, method.data, {
514
+ claim_order_id: result.id,
515
+ price: method.price,
516
+ })];
517
+ case 38:
518
+ _j.sent();
519
+ _j.label = 39;
520
+ case 39:
521
+ shipping_methods_2_1 = shipping_methods_2.next();
522
+ return [3 /*break*/, 35];
523
+ case 40: return [3 /*break*/, 43];
524
+ case 41:
525
+ e_7_1 = _j.sent();
526
+ e_7 = { error: e_7_1 };
527
+ return [3 /*break*/, 43];
528
+ case 42:
529
+ try {
530
+ if (shipping_methods_2_1 && !shipping_methods_2_1.done && (_d = shipping_methods_2.return)) _d.call(shipping_methods_2);
531
+ }
532
+ finally { if (e_7) throw e_7.error; }
533
+ return [7 /*endfinally*/];
534
+ case 43:
535
+ _j.trys.push([43, 48, 49, 50]);
536
+ claim_items_3 = __values(claim_items), claim_items_3_1 = claim_items_3.next();
537
+ _j.label = 44;
538
+ case 44:
539
+ if (!!claim_items_3_1.done) return [3 /*break*/, 47];
540
+ ci = claim_items_3_1.value;
541
+ return [4 /*yield*/, this.claimItemService_
542
+ .withTransaction(transactionManager)
543
+ .create(__assign(__assign({}, ci), { claim_order_id: result.id }))];
544
+ case 45:
545
+ _j.sent();
546
+ _j.label = 46;
547
+ case 46:
548
+ claim_items_3_1 = claim_items_3.next();
549
+ return [3 /*break*/, 44];
550
+ case 47: return [3 /*break*/, 50];
551
+ case 48:
552
+ e_8_1 = _j.sent();
553
+ e_8 = { error: e_8_1 };
554
+ return [3 /*break*/, 50];
555
+ case 49:
556
+ try {
557
+ if (claim_items_3_1 && !claim_items_3_1.done && (_e = claim_items_3.return)) _e.call(claim_items_3);
558
+ }
559
+ finally { if (e_8) throw e_8.error; }
560
+ return [7 /*endfinally*/];
561
+ case 50:
562
+ if (!return_shipping) return [3 /*break*/, 52];
563
+ return [4 /*yield*/, this.returnService_.withTransaction(transactionManager).create({
564
+ order_id: order.id,
565
+ claim_order_id: result.id,
566
+ items: claim_items.map(function (ci) { return ({
567
+ item_id: ci.item_id,
568
+ quantity: ci.quantity,
569
+ metadata: ci.metadata,
570
+ }); }),
571
+ shipping_method: return_shipping,
572
+ no_notification: evaluatedNoNotification,
573
+ })];
574
+ case 51:
575
+ _j.sent();
576
+ _j.label = 52;
577
+ case 52: return [4 /*yield*/, this.eventBus_
578
+ .withTransaction(transactionManager)
579
+ .emit(ClaimService.Events.CREATED, {
580
+ id: result.id,
581
+ no_notification: result.no_notification,
582
+ })];
583
+ case 53:
584
+ _j.sent();
585
+ return [2 /*return*/, result];
586
+ }
587
+ });
588
+ }); })];
589
+ case 1: return [2 /*return*/, _a.sent()];
544
590
  }
545
591
  });
546
- }); });
592
+ });
547
593
  };
548
594
  /**
549
- * @param {string} id - the object containing all data required to create a claim
550
- * @param {Object} config - config object
551
- * @param {Object | undefined} config.metadata - config metadata
552
- * @param {boolean|undefined} config.no_notification - config no notification
553
- * @return {Claim} created claim
595
+ * @param id - the object containing all data required to create a claim
596
+ * @param config - config object
597
+ * @param config.metadata - config metadata
598
+ * @param config.no_notification - config no notification
599
+ * @return created claim
554
600
  */
555
601
  ClaimService.prototype.createFulfillment = function (id, config) {
556
- var _this = this;
557
602
  if (config === void 0) { config = {
558
603
  metadata: {},
559
- no_notification: undefined,
560
604
  }; }
561
- var metadata = config.metadata, no_notification = config.no_notification;
562
- return this.atomicPhase_(function (manager) { return __awaiter(_this, void 0, void 0, function () {
563
- var claim, order, evaluatedNoNotification, fulfillments, successfullyFulfilled, fulfillments_1, fulfillments_1_1, f, _loop_1, this_1, _a, _b, item, e_9_1, claimRepo, result, fulfillments_2, fulfillments_2_1, fulfillment, e_10_1;
564
- var e_11, _c, e_9, _d, e_10, _e;
565
- var _f;
566
- return __generator(this, function (_g) {
567
- switch (_g.label) {
568
- case 0: return [4 /*yield*/, this.retrieve(id, {
569
- relations: [
570
- "additional_items",
571
- "additional_items.tax_lines",
572
- "shipping_methods",
573
- "shipping_methods.tax_lines",
574
- "shipping_address",
575
- "order",
576
- "order.billing_address",
577
- "order.discounts",
578
- "order.discounts.rule",
579
- "order.payments",
580
- ],
581
- })];
582
- case 1:
583
- claim = _g.sent();
584
- if (claim.canceled_at) {
585
- throw new medusa_core_utils_1.MedusaError(medusa_core_utils_1.MedusaError.Types.NOT_ALLOWED, "Canceled claim cannot be fulfilled");
586
- }
587
- order = claim.order;
588
- if (claim.fulfillment_status !== "not_fulfilled" &&
589
- claim.fulfillment_status !== "canceled") {
590
- throw new medusa_core_utils_1.MedusaError(medusa_core_utils_1.MedusaError.Types.NOT_ALLOWED, "The claim has already been fulfilled.");
591
- }
592
- if (claim.type !== "replace") {
593
- throw new medusa_core_utils_1.MedusaError(medusa_core_utils_1.MedusaError.Types.NOT_ALLOWED, "Claims with the type \"".concat(claim.type, "\" can not be fulfilled."));
594
- }
595
- if (!((_f = claim.shipping_methods) === null || _f === void 0 ? void 0 : _f.length)) {
596
- throw new medusa_core_utils_1.MedusaError(medusa_core_utils_1.MedusaError.Types.NOT_ALLOWED, "Cannot fulfill a claim without a shipping method.");
597
- }
598
- evaluatedNoNotification = no_notification !== undefined ? no_notification : claim.no_notification;
599
- return [4 /*yield*/, this.fulfillmentService_
600
- .withTransaction(manager)
601
- .createFulfillment(__assign(__assign({}, claim), { email: order.email, payments: order.payments, discounts: order.discounts, currency_code: order.currency_code, tax_rate: order.tax_rate, region_id: order.region_id, display_id: order.display_id, billing_address: order.billing_address, items: claim.additional_items, shipping_methods: claim.shipping_methods, is_claim: true, no_notification: evaluatedNoNotification }), claim.additional_items.map(function (i) { return ({
602
- item_id: i.id,
603
- quantity: i.quantity,
604
- }); }), { claim_order_id: id, metadata: metadata })];
605
- case 2:
606
- fulfillments = _g.sent();
607
- successfullyFulfilled = [];
608
- try {
609
- for (fulfillments_1 = __values(fulfillments), fulfillments_1_1 = fulfillments_1.next(); !fulfillments_1_1.done; fulfillments_1_1 = fulfillments_1.next()) {
610
- f = fulfillments_1_1.value;
611
- successfullyFulfilled = successfullyFulfilled.concat(f.items);
612
- }
613
- }
614
- catch (e_11_1) { e_11 = { error: e_11_1 }; }
615
- finally {
616
- try {
617
- if (fulfillments_1_1 && !fulfillments_1_1.done && (_c = fulfillments_1.return)) _c.call(fulfillments_1);
618
- }
619
- finally { if (e_11) throw e_11.error; }
620
- }
621
- claim.fulfillment_status = "fulfilled";
622
- _loop_1 = function (item) {
623
- var fulfillmentItem, fulfilledQuantity;
624
- return __generator(this, function (_h) {
625
- switch (_h.label) {
626
- case 0:
627
- fulfillmentItem = successfullyFulfilled.find(function (f) { return item.id === f.item_id; });
628
- if (!fulfillmentItem) return [3 /*break*/, 2];
629
- fulfilledQuantity = (item.fulfilled_quantity || 0) + fulfillmentItem.quantity;
630
- // Update the fulfilled quantity
631
- return [4 /*yield*/, this_1.lineItemService_.withTransaction(manager).update(item.id, {
632
- fulfilled_quantity: fulfilledQuantity,
605
+ return __awaiter(this, void 0, void 0, function () {
606
+ var metadata, no_notification;
607
+ var _this = this;
608
+ return __generator(this, function (_a) {
609
+ switch (_a.label) {
610
+ case 0:
611
+ metadata = config.metadata, no_notification = config.no_notification;
612
+ return [4 /*yield*/, this.atomicPhase_(function (transactionManager) { return __awaiter(_this, void 0, void 0, function () {
613
+ var claim, order, evaluatedNoNotification, fulfillments, successfullyFulfilledItems, fulfillments_1, fulfillments_1_1, fulfillment, _loop_1, this_1, _a, _b, item, e_11_1, claimRepo, claimOrder, fulfillments_2, fulfillments_2_1, fulfillment, e_12_1;
614
+ var e_13, _c, e_11, _d, e_12, _e;
615
+ var _f;
616
+ return __generator(this, function (_g) {
617
+ switch (_g.label) {
618
+ case 0: return [4 /*yield*/, this.retrieve(id, {
619
+ relations: [
620
+ "additional_items",
621
+ "additional_items.tax_lines",
622
+ "shipping_methods",
623
+ "shipping_methods.tax_lines",
624
+ "shipping_address",
625
+ "order",
626
+ "order.billing_address",
627
+ "order.discounts",
628
+ "order.discounts.rule",
629
+ "order.payments",
630
+ ],
633
631
  })];
634
- case 1:
635
- // Update the fulfilled quantity
636
- _h.sent();
637
- if (item.quantity !== fulfilledQuantity) {
638
- claim.fulfillment_status = "requires_action";
639
- }
640
- return [3 /*break*/, 3];
641
- case 2:
642
- if (item.quantity !== item.fulfilled_quantity) {
643
- claim.fulfillment_status = "requires_action";
644
- }
645
- _h.label = 3;
646
- case 3: return [2 /*return*/];
647
- }
648
- });
649
- };
650
- this_1 = this;
651
- _g.label = 3;
652
- case 3:
653
- _g.trys.push([3, 8, 9, 10]);
654
- _a = __values(claim.additional_items), _b = _a.next();
655
- _g.label = 4;
656
- case 4:
657
- if (!!_b.done) return [3 /*break*/, 7];
658
- item = _b.value;
659
- return [5 /*yield**/, _loop_1(item)];
660
- case 5:
661
- _g.sent();
662
- _g.label = 6;
663
- case 6:
664
- _b = _a.next();
665
- return [3 /*break*/, 4];
666
- case 7: return [3 /*break*/, 10];
667
- case 8:
668
- e_9_1 = _g.sent();
669
- e_9 = { error: e_9_1 };
670
- return [3 /*break*/, 10];
671
- case 9:
672
- try {
673
- if (_b && !_b.done && (_d = _a.return)) _d.call(_a);
674
- }
675
- finally { if (e_9) throw e_9.error; }
676
- return [7 /*endfinally*/];
677
- case 10:
678
- claimRepo = manager.getCustomRepository(this.claimRepository_);
679
- return [4 /*yield*/, claimRepo.save(claim)];
680
- case 11:
681
- result = _g.sent();
682
- _g.label = 12;
683
- case 12:
684
- _g.trys.push([12, 17, 18, 19]);
685
- fulfillments_2 = __values(fulfillments), fulfillments_2_1 = fulfillments_2.next();
686
- _g.label = 13;
687
- case 13:
688
- if (!!fulfillments_2_1.done) return [3 /*break*/, 16];
689
- fulfillment = fulfillments_2_1.value;
690
- return [4 /*yield*/, this.eventBus_
691
- .withTransaction(manager)
692
- .emit(ClaimService.Events.FULFILLMENT_CREATED, {
693
- id: id,
694
- fulfillment_id: fulfillment.id,
695
- no_notification: claim.no_notification,
696
- })];
697
- case 14:
698
- _g.sent();
699
- _g.label = 15;
700
- case 15:
701
- fulfillments_2_1 = fulfillments_2.next();
702
- return [3 /*break*/, 13];
703
- case 16: return [3 /*break*/, 19];
704
- case 17:
705
- e_10_1 = _g.sent();
706
- e_10 = { error: e_10_1 };
707
- return [3 /*break*/, 19];
708
- case 18:
709
- try {
710
- if (fulfillments_2_1 && !fulfillments_2_1.done && (_e = fulfillments_2.return)) _e.call(fulfillments_2);
711
- }
712
- finally { if (e_10) throw e_10.error; }
713
- return [7 /*endfinally*/];
714
- case 19: return [2 /*return*/, result];
632
+ case 1:
633
+ claim = _g.sent();
634
+ if (claim.canceled_at) {
635
+ throw new medusa_core_utils_1.MedusaError(medusa_core_utils_1.MedusaError.Types.NOT_ALLOWED, "Canceled claim cannot be fulfilled");
636
+ }
637
+ order = claim.order;
638
+ if (claim.fulfillment_status !== "not_fulfilled" &&
639
+ claim.fulfillment_status !== "canceled") {
640
+ throw new medusa_core_utils_1.MedusaError(medusa_core_utils_1.MedusaError.Types.NOT_ALLOWED, "The claim has already been fulfilled.");
641
+ }
642
+ if (claim.type !== "replace") {
643
+ throw new medusa_core_utils_1.MedusaError(medusa_core_utils_1.MedusaError.Types.NOT_ALLOWED, "Claims with the type \"".concat(claim.type, "\" can not be fulfilled."));
644
+ }
645
+ if (!((_f = claim.shipping_methods) === null || _f === void 0 ? void 0 : _f.length)) {
646
+ throw new medusa_core_utils_1.MedusaError(medusa_core_utils_1.MedusaError.Types.NOT_ALLOWED, "Cannot fulfill a claim without a shipping method.");
647
+ }
648
+ evaluatedNoNotification = no_notification !== undefined
649
+ ? no_notification
650
+ : claim.no_notification;
651
+ return [4 /*yield*/, this.fulfillmentService_
652
+ .withTransaction(transactionManager)
653
+ .createFulfillment(__assign(__assign({}, claim), { email: order.email, payments: order.payments, discounts: order.discounts, currency_code: order.currency_code, tax_rate: order.tax_rate, region_id: order.region_id, display_id: order.display_id, billing_address: order.billing_address, items: claim.additional_items, shipping_methods: claim.shipping_methods, is_claim: true, no_notification: evaluatedNoNotification }), claim.additional_items.map(function (i) { return ({
654
+ item_id: i.id,
655
+ quantity: i.quantity,
656
+ }); }), { claim_order_id: id, metadata: metadata })];
657
+ case 2:
658
+ fulfillments = _g.sent();
659
+ successfullyFulfilledItems = [];
660
+ try {
661
+ for (fulfillments_1 = __values(fulfillments), fulfillments_1_1 = fulfillments_1.next(); !fulfillments_1_1.done; fulfillments_1_1 = fulfillments_1.next()) {
662
+ fulfillment = fulfillments_1_1.value;
663
+ successfullyFulfilledItems = successfullyFulfilledItems.concat(fulfillment.items);
664
+ }
665
+ }
666
+ catch (e_13_1) { e_13 = { error: e_13_1 }; }
667
+ finally {
668
+ try {
669
+ if (fulfillments_1_1 && !fulfillments_1_1.done && (_c = fulfillments_1.return)) _c.call(fulfillments_1);
670
+ }
671
+ finally { if (e_13) throw e_13.error; }
672
+ }
673
+ claim.fulfillment_status = models_1.ClaimFulfillmentStatus.FULFILLED;
674
+ _loop_1 = function (item) {
675
+ var fulfillmentItem, fulfilledQuantity;
676
+ return __generator(this, function (_h) {
677
+ switch (_h.label) {
678
+ case 0:
679
+ fulfillmentItem = successfullyFulfilledItems.find(function (successfullyFulfilledItem) {
680
+ return successfullyFulfilledItem.item_id === item.id;
681
+ });
682
+ if (!fulfillmentItem) return [3 /*break*/, 2];
683
+ fulfilledQuantity = (item.fulfilled_quantity || 0) + fulfillmentItem.quantity;
684
+ // Update the fulfilled quantity
685
+ return [4 /*yield*/, this_1.lineItemService_
686
+ .withTransaction(transactionManager)
687
+ .update(item.id, {
688
+ fulfilled_quantity: fulfilledQuantity,
689
+ })];
690
+ case 1:
691
+ // Update the fulfilled quantity
692
+ _h.sent();
693
+ if (item.quantity !== fulfilledQuantity) {
694
+ claim.fulfillment_status = models_1.ClaimFulfillmentStatus.REQUIRES_ACTION;
695
+ }
696
+ return [3 /*break*/, 3];
697
+ case 2:
698
+ if (item.quantity !== item.fulfilled_quantity) {
699
+ claim.fulfillment_status = models_1.ClaimFulfillmentStatus.REQUIRES_ACTION;
700
+ }
701
+ _h.label = 3;
702
+ case 3: return [2 /*return*/];
703
+ }
704
+ });
705
+ };
706
+ this_1 = this;
707
+ _g.label = 3;
708
+ case 3:
709
+ _g.trys.push([3, 8, 9, 10]);
710
+ _a = __values(claim.additional_items), _b = _a.next();
711
+ _g.label = 4;
712
+ case 4:
713
+ if (!!_b.done) return [3 /*break*/, 7];
714
+ item = _b.value;
715
+ return [5 /*yield**/, _loop_1(item)];
716
+ case 5:
717
+ _g.sent();
718
+ _g.label = 6;
719
+ case 6:
720
+ _b = _a.next();
721
+ return [3 /*break*/, 4];
722
+ case 7: return [3 /*break*/, 10];
723
+ case 8:
724
+ e_11_1 = _g.sent();
725
+ e_11 = { error: e_11_1 };
726
+ return [3 /*break*/, 10];
727
+ case 9:
728
+ try {
729
+ if (_b && !_b.done && (_d = _a.return)) _d.call(_a);
730
+ }
731
+ finally { if (e_11) throw e_11.error; }
732
+ return [7 /*endfinally*/];
733
+ case 10:
734
+ claimRepo = transactionManager.getCustomRepository(this.claimRepository_);
735
+ return [4 /*yield*/, claimRepo.save(claim)];
736
+ case 11:
737
+ claimOrder = _g.sent();
738
+ _g.label = 12;
739
+ case 12:
740
+ _g.trys.push([12, 17, 18, 19]);
741
+ fulfillments_2 = __values(fulfillments), fulfillments_2_1 = fulfillments_2.next();
742
+ _g.label = 13;
743
+ case 13:
744
+ if (!!fulfillments_2_1.done) return [3 /*break*/, 16];
745
+ fulfillment = fulfillments_2_1.value;
746
+ return [4 /*yield*/, this.eventBus_
747
+ .withTransaction(transactionManager)
748
+ .emit(ClaimService.Events.FULFILLMENT_CREATED, {
749
+ id: id,
750
+ fulfillment_id: fulfillment.id,
751
+ no_notification: claim.no_notification,
752
+ })];
753
+ case 14:
754
+ _g.sent();
755
+ _g.label = 15;
756
+ case 15:
757
+ fulfillments_2_1 = fulfillments_2.next();
758
+ return [3 /*break*/, 13];
759
+ case 16: return [3 /*break*/, 19];
760
+ case 17:
761
+ e_12_1 = _g.sent();
762
+ e_12 = { error: e_12_1 };
763
+ return [3 /*break*/, 19];
764
+ case 18:
765
+ try {
766
+ if (fulfillments_2_1 && !fulfillments_2_1.done && (_e = fulfillments_2.return)) _e.call(fulfillments_2);
767
+ }
768
+ finally { if (e_12) throw e_12.error; }
769
+ return [7 /*endfinally*/];
770
+ case 19: return [2 /*return*/, claimOrder];
771
+ }
772
+ });
773
+ }); })];
774
+ case 1: return [2 /*return*/, _a.sent()];
715
775
  }
716
776
  });
717
- }); });
777
+ });
718
778
  };
719
779
  ClaimService.prototype.cancelFulfillment = function (fulfillmentId) {
720
780
  return __awaiter(this, void 0, void 0, function () {
721
781
  var _this = this;
722
782
  return __generator(this, function (_a) {
723
- return [2 /*return*/, this.atomicPhase_(function (manager) { return __awaiter(_this, void 0, void 0, function () {
724
- var canceled, claim, claimRepo, updated;
725
- return __generator(this, function (_a) {
726
- switch (_a.label) {
727
- case 0: return [4 /*yield*/, this.fulfillmentService_
728
- .withTransaction(manager)
729
- .cancelFulfillment(fulfillmentId)];
730
- case 1:
731
- canceled = _a.sent();
732
- if (!canceled.claim_order_id) {
733
- throw new medusa_core_utils_1.MedusaError(medusa_core_utils_1.MedusaError.Types.NOT_ALLOWED, "Fufillment not related to a claim");
734
- }
735
- return [4 /*yield*/, this.retrieve(canceled.claim_order_id)];
736
- case 2:
737
- claim = _a.sent();
738
- claim.fulfillment_status = "canceled";
739
- claimRepo = manager.getCustomRepository(this.claimRepository_);
740
- return [4 /*yield*/, claimRepo.save(claim)];
741
- case 3:
742
- updated = _a.sent();
743
- return [2 /*return*/, updated];
744
- }
745
- });
746
- }); })];
783
+ switch (_a.label) {
784
+ case 0: return [4 /*yield*/, this.atomicPhase_(function (transactionManager) { return __awaiter(_this, void 0, void 0, function () {
785
+ var canceled, claim, claimRepo;
786
+ return __generator(this, function (_a) {
787
+ switch (_a.label) {
788
+ case 0: return [4 /*yield*/, this.fulfillmentService_
789
+ .withTransaction(transactionManager)
790
+ .cancelFulfillment(fulfillmentId)];
791
+ case 1:
792
+ canceled = _a.sent();
793
+ if (!canceled.claim_order_id) {
794
+ throw new medusa_core_utils_1.MedusaError(medusa_core_utils_1.MedusaError.Types.NOT_ALLOWED, "Fufillment not related to a claim");
795
+ }
796
+ return [4 /*yield*/, this.retrieve(canceled.claim_order_id)];
797
+ case 2:
798
+ claim = _a.sent();
799
+ claim.fulfillment_status = models_1.ClaimFulfillmentStatus.CANCELED;
800
+ claimRepo = transactionManager.getCustomRepository(this.claimRepository_);
801
+ return [2 /*return*/, claimRepo.save(claim)];
802
+ }
803
+ });
804
+ }); })];
805
+ case 1: return [2 /*return*/, _a.sent()];
806
+ }
747
807
  });
748
808
  });
749
809
  };
@@ -751,50 +811,54 @@ var ClaimService = /** @class */ (function (_super) {
751
811
  return __awaiter(this, void 0, void 0, function () {
752
812
  var _this = this;
753
813
  return __generator(this, function (_a) {
754
- return [2 /*return*/, this.atomicPhase_(function (manager) { return __awaiter(_this, void 0, void 0, function () {
755
- var claim, claimRepo, result;
756
- return __generator(this, function (_a) {
757
- switch (_a.label) {
758
- case 0: return [4 /*yield*/, this.retrieve(id, {
759
- relations: ["order", "order.payments"],
760
- })];
761
- case 1:
762
- claim = _a.sent();
763
- if (claim.canceled_at) {
764
- throw new medusa_core_utils_1.MedusaError(medusa_core_utils_1.MedusaError.Types.NOT_ALLOWED, "Canceled claim cannot be processed");
765
- }
766
- if (claim.type !== "refund") {
767
- throw new medusa_core_utils_1.MedusaError(medusa_core_utils_1.MedusaError.Types.NOT_ALLOWED, "Claim must have type \"refund\" to create a refund.");
768
- }
769
- if (!claim.refund_amount) return [3 /*break*/, 3];
770
- return [4 /*yield*/, this.paymentProviderService_
771
- .withTransaction(manager)
772
- .refundPayment(claim.order.payments, claim.refund_amount, "claim")];
773
- case 2:
774
- _a.sent();
775
- _a.label = 3;
776
- case 3:
777
- claim.payment_status = "refunded";
778
- claimRepo = manager.getCustomRepository(this.claimRepository_);
779
- return [4 /*yield*/, claimRepo.save(claim)];
780
- case 4:
781
- result = _a.sent();
782
- return [4 /*yield*/, this.eventBus_
783
- .withTransaction(manager)
784
- .emit(ClaimService.Events.REFUND_PROCESSED, {
785
- id: id,
786
- no_notification: result.no_notification,
814
+ switch (_a.label) {
815
+ case 0: return [4 /*yield*/, this.atomicPhase_(function (transactionManager) { return __awaiter(_this, void 0, void 0, function () {
816
+ var claim, claimRepo, claimOrder;
817
+ return __generator(this, function (_a) {
818
+ switch (_a.label) {
819
+ case 0: return [4 /*yield*/, this.retrieve(id, {
820
+ relations: ["order", "order.payments"],
787
821
  })];
788
- case 5:
789
- _a.sent();
790
- return [2 /*return*/, result];
791
- }
792
- });
793
- }); })];
822
+ case 1:
823
+ claim = _a.sent();
824
+ if (claim.canceled_at) {
825
+ throw new medusa_core_utils_1.MedusaError(medusa_core_utils_1.MedusaError.Types.NOT_ALLOWED, "Canceled claim cannot be processed");
826
+ }
827
+ if (claim.type !== "refund") {
828
+ throw new medusa_core_utils_1.MedusaError(medusa_core_utils_1.MedusaError.Types.NOT_ALLOWED, "Claim must have type \"refund\" to create a refund.");
829
+ }
830
+ if (!claim.refund_amount) return [3 /*break*/, 3];
831
+ return [4 /*yield*/, this.paymentProviderService_
832
+ .withTransaction(transactionManager)
833
+ .refundPayment(claim.order.payments, claim.refund_amount, "claim")];
834
+ case 2:
835
+ _a.sent();
836
+ _a.label = 3;
837
+ case 3:
838
+ claim.payment_status = models_1.ClaimPaymentStatus.REFUNDED;
839
+ claimRepo = transactionManager.getCustomRepository(this.claimRepository_);
840
+ return [4 /*yield*/, claimRepo.save(claim)];
841
+ case 4:
842
+ claimOrder = _a.sent();
843
+ return [4 /*yield*/, this.eventBus_
844
+ .withTransaction(transactionManager)
845
+ .emit(ClaimService.Events.REFUND_PROCESSED, {
846
+ id: id,
847
+ no_notification: claimOrder.no_notification,
848
+ })];
849
+ case 5:
850
+ _a.sent();
851
+ return [2 /*return*/, claimOrder];
852
+ }
853
+ });
854
+ }); })];
855
+ case 1: return [2 /*return*/, _a.sent()];
856
+ }
794
857
  });
795
858
  });
796
859
  };
797
860
  ClaimService.prototype.createShipment = function (id, fulfillmentId, trackingLinks, config) {
861
+ if (trackingLinks === void 0) { trackingLinks = []; }
798
862
  if (config === void 0) { config = {
799
863
  metadata: {},
800
864
  no_notification: undefined,
@@ -803,101 +867,110 @@ var ClaimService = /** @class */ (function (_super) {
803
867
  var metadata, no_notification;
804
868
  var _this = this;
805
869
  return __generator(this, function (_a) {
806
- metadata = config.metadata, no_notification = config.no_notification;
807
- return [2 /*return*/, this.atomicPhase_(function (manager) { return __awaiter(_this, void 0, void 0, function () {
808
- var claim, evaluatedNoNotification, shipment, _loop_2, this_2, _a, _b, i, e_12_1, claimRepo, result;
809
- var e_12, _c;
810
- return __generator(this, function (_d) {
811
- switch (_d.label) {
812
- case 0: return [4 /*yield*/, this.retrieve(id, {
813
- relations: ["additional_items"],
814
- })];
815
- case 1:
816
- claim = _d.sent();
817
- if (claim.canceled_at) {
818
- throw new medusa_core_utils_1.MedusaError(medusa_core_utils_1.MedusaError.Types.NOT_ALLOWED, "Canceled claim cannot be fulfilled as shipped");
819
- }
820
- evaluatedNoNotification = no_notification !== undefined ? no_notification : claim.no_notification;
821
- return [4 /*yield*/, this.fulfillmentService_
822
- .withTransaction(manager)
823
- .createShipment(fulfillmentId, trackingLinks, {
824
- metadata: metadata,
825
- no_notification: evaluatedNoNotification,
826
- })];
827
- case 2:
828
- shipment = _d.sent();
829
- claim.fulfillment_status = "shipped";
830
- _loop_2 = function (i) {
831
- var shipped, shippedQty;
832
- return __generator(this, function (_e) {
833
- switch (_e.label) {
834
- case 0:
835
- shipped = shipment.items.find(function (si) { return si.item_id === i.id; });
836
- if (!shipped) return [3 /*break*/, 2];
837
- shippedQty = (i.shipped_quantity || 0) + shipped.quantity;
838
- return [4 /*yield*/, this_2.lineItemService_.withTransaction(manager).update(i.id, {
839
- shipped_quantity: shippedQty,
840
- })];
841
- case 1:
842
- _e.sent();
843
- if (shippedQty !== i.quantity) {
844
- claim.fulfillment_status = "partially_shipped";
845
- }
846
- return [3 /*break*/, 3];
847
- case 2:
848
- if (i.shipped_quantity !== i.quantity) {
849
- claim.fulfillment_status = "partially_shipped";
870
+ switch (_a.label) {
871
+ case 0:
872
+ metadata = config.metadata, no_notification = config.no_notification;
873
+ return [4 /*yield*/, this.atomicPhase_(function (transactionManager) { return __awaiter(_this, void 0, void 0, function () {
874
+ var claim, evaluatedNoNotification, shipment, _loop_2, this_2, _a, _b, additionalItem, e_14_1, claimRepo, claimOrder;
875
+ var e_14, _c;
876
+ return __generator(this, function (_d) {
877
+ switch (_d.label) {
878
+ case 0: return [4 /*yield*/, this.retrieve(id, {
879
+ relations: ["additional_items"],
880
+ })];
881
+ case 1:
882
+ claim = _d.sent();
883
+ if (claim.canceled_at) {
884
+ throw new medusa_core_utils_1.MedusaError(medusa_core_utils_1.MedusaError.Types.NOT_ALLOWED, "Canceled claim cannot be fulfilled as shipped");
885
+ }
886
+ evaluatedNoNotification = no_notification !== undefined
887
+ ? no_notification
888
+ : claim.no_notification;
889
+ return [4 /*yield*/, this.fulfillmentService_
890
+ .withTransaction(transactionManager)
891
+ .createShipment(fulfillmentId, trackingLinks, {
892
+ metadata: metadata,
893
+ no_notification: evaluatedNoNotification,
894
+ })];
895
+ case 2:
896
+ shipment = _d.sent();
897
+ claim.fulfillment_status = models_1.ClaimFulfillmentStatus.SHIPPED;
898
+ _loop_2 = function (additionalItem) {
899
+ var shipped, shippedQty;
900
+ return __generator(this, function (_e) {
901
+ switch (_e.label) {
902
+ case 0:
903
+ shipped = shipment.items.find(function (si) { return si.item_id === additionalItem.id; });
904
+ if (!shipped) return [3 /*break*/, 2];
905
+ shippedQty = (additionalItem.shipped_quantity || 0) + shipped.quantity;
906
+ return [4 /*yield*/, this_2.lineItemService_
907
+ .withTransaction(transactionManager)
908
+ .update(additionalItem.id, {
909
+ shipped_quantity: shippedQty,
910
+ })];
911
+ case 1:
912
+ _e.sent();
913
+ if (shippedQty !== additionalItem.quantity) {
914
+ claim.fulfillment_status =
915
+ models_1.ClaimFulfillmentStatus.PARTIALLY_SHIPPED;
916
+ }
917
+ return [3 /*break*/, 3];
918
+ case 2:
919
+ if (additionalItem.shipped_quantity !== additionalItem.quantity) {
920
+ claim.fulfillment_status = models_1.ClaimFulfillmentStatus.PARTIALLY_SHIPPED;
921
+ }
922
+ _e.label = 3;
923
+ case 3: return [2 /*return*/];
850
924
  }
851
- _e.label = 3;
852
- case 3: return [2 /*return*/];
925
+ });
926
+ };
927
+ this_2 = this;
928
+ _d.label = 3;
929
+ case 3:
930
+ _d.trys.push([3, 8, 9, 10]);
931
+ _a = __values(claim.additional_items), _b = _a.next();
932
+ _d.label = 4;
933
+ case 4:
934
+ if (!!_b.done) return [3 /*break*/, 7];
935
+ additionalItem = _b.value;
936
+ return [5 /*yield**/, _loop_2(additionalItem)];
937
+ case 5:
938
+ _d.sent();
939
+ _d.label = 6;
940
+ case 6:
941
+ _b = _a.next();
942
+ return [3 /*break*/, 4];
943
+ case 7: return [3 /*break*/, 10];
944
+ case 8:
945
+ e_14_1 = _d.sent();
946
+ e_14 = { error: e_14_1 };
947
+ return [3 /*break*/, 10];
948
+ case 9:
949
+ try {
950
+ if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
853
951
  }
854
- });
855
- };
856
- this_2 = this;
857
- _d.label = 3;
858
- case 3:
859
- _d.trys.push([3, 8, 9, 10]);
860
- _a = __values(claim.additional_items), _b = _a.next();
861
- _d.label = 4;
862
- case 4:
863
- if (!!_b.done) return [3 /*break*/, 7];
864
- i = _b.value;
865
- return [5 /*yield**/, _loop_2(i)];
866
- case 5:
867
- _d.sent();
868
- _d.label = 6;
869
- case 6:
870
- _b = _a.next();
871
- return [3 /*break*/, 4];
872
- case 7: return [3 /*break*/, 10];
873
- case 8:
874
- e_12_1 = _d.sent();
875
- e_12 = { error: e_12_1 };
876
- return [3 /*break*/, 10];
877
- case 9:
878
- try {
879
- if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
952
+ finally { if (e_14) throw e_14.error; }
953
+ return [7 /*endfinally*/];
954
+ case 10:
955
+ claimRepo = transactionManager.getCustomRepository(this.claimRepository_);
956
+ return [4 /*yield*/, claimRepo.save(claim)];
957
+ case 11:
958
+ claimOrder = _d.sent();
959
+ return [4 /*yield*/, this.eventBus_
960
+ .withTransaction(transactionManager)
961
+ .emit(ClaimService.Events.SHIPMENT_CREATED, {
962
+ id: id,
963
+ fulfillment_id: shipment.id,
964
+ no_notification: evaluatedNoNotification,
965
+ })];
966
+ case 12:
967
+ _d.sent();
968
+ return [2 /*return*/, claimOrder];
880
969
  }
881
- finally { if (e_12) throw e_12.error; }
882
- return [7 /*endfinally*/];
883
- case 10:
884
- claimRepo = manager.getCustomRepository(this.claimRepository_);
885
- return [4 /*yield*/, claimRepo.save(claim)];
886
- case 11:
887
- result = _d.sent();
888
- return [4 /*yield*/, this.eventBus_
889
- .withTransaction(manager)
890
- .emit(ClaimService.Events.SHIPMENT_CREATED, {
891
- id: id,
892
- fulfillment_id: shipment.id,
893
- no_notification: evaluatedNoNotification,
894
- })];
895
- case 12:
896
- _d.sent();
897
- return [2 /*return*/, result];
898
- }
899
- });
900
- }); })];
970
+ });
971
+ }); })];
972
+ case 1: return [2 /*return*/, _a.sent()];
973
+ }
901
974
  });
902
975
  });
903
976
  };
@@ -905,124 +978,126 @@ var ClaimService = /** @class */ (function (_super) {
905
978
  return __awaiter(this, void 0, void 0, function () {
906
979
  var _this = this;
907
980
  return __generator(this, function (_a) {
908
- return [2 /*return*/, this.atomicPhase_(function (manager) { return __awaiter(_this, void 0, void 0, function () {
909
- var claim, _a, _b, f, claimRepo, result;
910
- var e_13, _c;
911
- return __generator(this, function (_d) {
912
- switch (_d.label) {
913
- case 0: return [4 /*yield*/, this.retrieve(id, {
914
- relations: ["return_order", "fulfillments", "order", "order.refunds"],
915
- })];
916
- case 1:
917
- claim = _d.sent();
918
- if (claim.refund_amount) {
919
- throw new medusa_core_utils_1.MedusaError(medusa_core_utils_1.MedusaError.Types.NOT_ALLOWED, "Claim with a refund cannot be canceled");
920
- }
921
- if (claim.fulfillments) {
922
- try {
923
- for (_a = __values(claim.fulfillments), _b = _a.next(); !_b.done; _b = _a.next()) {
924
- f = _b.value;
925
- if (!f.canceled_at) {
926
- throw new medusa_core_utils_1.MedusaError(medusa_core_utils_1.MedusaError.Types.NOT_ALLOWED, "All fulfillments must be canceled before the claim can be canceled");
927
- }
928
- }
981
+ switch (_a.label) {
982
+ case 0: return [4 /*yield*/, this.atomicPhase_(function (transactionManager) { return __awaiter(_this, void 0, void 0, function () {
983
+ var claim, _a, _b, f, claimRepo, claimOrder;
984
+ var e_15, _c;
985
+ return __generator(this, function (_d) {
986
+ switch (_d.label) {
987
+ case 0: return [4 /*yield*/, this.retrieve(id, {
988
+ relations: ["return_order", "fulfillments", "order", "order.refunds"],
989
+ })];
990
+ case 1:
991
+ claim = _d.sent();
992
+ if (claim.refund_amount) {
993
+ throw new medusa_core_utils_1.MedusaError(medusa_core_utils_1.MedusaError.Types.NOT_ALLOWED, "Claim with a refund cannot be canceled");
929
994
  }
930
- catch (e_13_1) { e_13 = { error: e_13_1 }; }
931
- finally {
995
+ if (claim.fulfillments) {
932
996
  try {
933
- if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
997
+ for (_a = __values(claim.fulfillments), _b = _a.next(); !_b.done; _b = _a.next()) {
998
+ f = _b.value;
999
+ if (!f.canceled_at) {
1000
+ throw new medusa_core_utils_1.MedusaError(medusa_core_utils_1.MedusaError.Types.NOT_ALLOWED, "All fulfillments must be canceled before the claim can be canceled");
1001
+ }
1002
+ }
1003
+ }
1004
+ catch (e_15_1) { e_15 = { error: e_15_1 }; }
1005
+ finally {
1006
+ try {
1007
+ if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
1008
+ }
1009
+ finally { if (e_15) throw e_15.error; }
934
1010
  }
935
- finally { if (e_13) throw e_13.error; }
936
1011
  }
937
- }
938
- if (claim.return_order && claim.return_order.status !== "canceled") {
939
- throw new medusa_core_utils_1.MedusaError(medusa_core_utils_1.MedusaError.Types.NOT_ALLOWED, "Return must be canceled before the claim can be canceled");
940
- }
941
- claim.fulfillment_status = "canceled";
942
- claim.canceled_at = new Date();
943
- claimRepo = manager.getCustomRepository(this.claimRepository_);
944
- return [4 /*yield*/, claimRepo.save(claim)];
945
- case 2:
946
- result = _d.sent();
947
- return [4 /*yield*/, this.eventBus_
948
- .withTransaction(manager)
949
- .emit(ClaimService.Events.CANCELED, {
950
- id: result.id,
951
- no_notification: result.no_notification,
952
- })];
953
- case 3:
954
- _d.sent();
955
- return [2 /*return*/, result];
956
- }
957
- });
958
- }); })];
1012
+ if (claim.return_order && claim.return_order.status !== "canceled") {
1013
+ throw new medusa_core_utils_1.MedusaError(medusa_core_utils_1.MedusaError.Types.NOT_ALLOWED, "Return must be canceled before the claim can be canceled");
1014
+ }
1015
+ claim.fulfillment_status = models_1.ClaimFulfillmentStatus.CANCELED;
1016
+ claim.canceled_at = new Date();
1017
+ claimRepo = transactionManager.getCustomRepository(this.claimRepository_);
1018
+ return [4 /*yield*/, claimRepo.save(claim)];
1019
+ case 2:
1020
+ claimOrder = _d.sent();
1021
+ return [4 /*yield*/, this.eventBus_
1022
+ .withTransaction(transactionManager)
1023
+ .emit(ClaimService.Events.CANCELED, {
1024
+ id: claimOrder.id,
1025
+ no_notification: claimOrder.no_notification,
1026
+ })];
1027
+ case 3:
1028
+ _d.sent();
1029
+ return [2 /*return*/, claimOrder];
1030
+ }
1031
+ });
1032
+ }); })];
1033
+ case 1: return [2 /*return*/, _a.sent()];
1034
+ }
959
1035
  });
960
1036
  });
961
1037
  };
962
1038
  /**
963
- * @param {Object} selector - the query object for find
964
- * @param {Object} config - the config object containing query settings
965
- * @return {Promise} the result of the find operation
1039
+ * @param selector - the query object for find
1040
+ * @param config - the config object containing query settings
1041
+ * @return the result of the find operation
966
1042
  */
967
1043
  ClaimService.prototype.list = function (selector, config) {
968
- if (config === void 0) { config = { skip: 0, take: 50, order: { created_at: "DESC" } }; }
1044
+ if (config === void 0) { config = {
1045
+ skip: 0,
1046
+ take: 50,
1047
+ order: { created_at: "DESC" },
1048
+ }; }
969
1049
  return __awaiter(this, void 0, void 0, function () {
970
- var claimRepo, query;
1050
+ var _this = this;
971
1051
  return __generator(this, function (_a) {
972
- claimRepo = this.manager_.getCustomRepository(this.claimRepository_);
973
- query = this.buildQuery_(selector, config);
974
- return [2 /*return*/, claimRepo.find(query)];
1052
+ switch (_a.label) {
1053
+ case 0: return [4 /*yield*/, this.atomicPhase_(function (transactionManager) { return __awaiter(_this, void 0, void 0, function () {
1054
+ var claimRepo, query;
1055
+ return __generator(this, function (_a) {
1056
+ switch (_a.label) {
1057
+ case 0:
1058
+ claimRepo = transactionManager.getCustomRepository(this.claimRepository_);
1059
+ query = (0, utils_1.buildQuery)(selector, config);
1060
+ return [4 /*yield*/, claimRepo.find(query)];
1061
+ case 1: return [2 /*return*/, _a.sent()];
1062
+ }
1063
+ });
1064
+ }); })];
1065
+ case 1: return [2 /*return*/, _a.sent()];
1066
+ }
975
1067
  });
976
1068
  });
977
1069
  };
978
1070
  /**
979
1071
  * Gets an order by id.
980
- * @param {string} claimId - id of order to retrieve
981
- * @param {Object} config - the config object containing query settings
982
- * @return {Promise<Order>} the order document
1072
+ * @param id - id of the claim order to retrieve
1073
+ * @param config - the config object containing query settings
1074
+ * @return the order document
983
1075
  */
984
- ClaimService.prototype.retrieve = function (claimId, config) {
1076
+ ClaimService.prototype.retrieve = function (id, config) {
985
1077
  if (config === void 0) { config = {}; }
986
1078
  return __awaiter(this, void 0, void 0, function () {
987
- var claimRepo, validatedId, query, claim;
1079
+ var _this = this;
988
1080
  return __generator(this, function (_a) {
989
1081
  switch (_a.label) {
990
- case 0:
991
- claimRepo = this.manager_.getCustomRepository(this.claimRepository_);
992
- validatedId = this.validateId_(claimId);
993
- query = this.buildQuery_({ id: validatedId }, config);
994
- return [4 /*yield*/, claimRepo.findOne(query)];
995
- case 1:
996
- claim = _a.sent();
997
- if (!claim) {
998
- throw new medusa_core_utils_1.MedusaError(medusa_core_utils_1.MedusaError.Types.NOT_FOUND, "Claim with ".concat(claimId, " was not found"));
999
- }
1000
- return [2 /*return*/, claim];
1001
- }
1002
- });
1003
- });
1004
- };
1005
- /**
1006
- * Dedicated method to delete metadata for an order.
1007
- * @param {string} orderId - the order to delete metadata from.
1008
- * @param {string} key - key for metadata field
1009
- * @return {Promise} resolves to the updated result.
1010
- */
1011
- ClaimService.prototype.deleteMetadata = function (orderId, key) {
1012
- return __awaiter(this, void 0, void 0, function () {
1013
- var validatedId, keyPath;
1014
- var _a;
1015
- return __generator(this, function (_b) {
1016
- validatedId = this.validateId_(orderId);
1017
- if (typeof key !== "string") {
1018
- throw new medusa_core_utils_1.MedusaError(medusa_core_utils_1.MedusaError.Types.INVALID_ARGUMENT, "Key type is invalid. Metadata keys must be strings");
1082
+ case 0: return [4 /*yield*/, this.atomicPhase_(function (transactionManager) { return __awaiter(_this, void 0, void 0, function () {
1083
+ var claimRepo, query, claim;
1084
+ return __generator(this, function (_a) {
1085
+ switch (_a.label) {
1086
+ case 0:
1087
+ claimRepo = transactionManager.getCustomRepository(this.claimRepository_);
1088
+ query = (0, utils_1.buildQuery)({ id: id }, config);
1089
+ return [4 /*yield*/, claimRepo.findOne(query)];
1090
+ case 1:
1091
+ claim = _a.sent();
1092
+ if (!claim) {
1093
+ throw new medusa_core_utils_1.MedusaError(medusa_core_utils_1.MedusaError.Types.NOT_FOUND, "Claim with ".concat(id, " was not found"));
1094
+ }
1095
+ return [2 /*return*/, claim];
1096
+ }
1097
+ });
1098
+ }); })];
1099
+ case 1: return [2 /*return*/, _a.sent()];
1019
1100
  }
1020
- keyPath = "metadata.".concat(key);
1021
- return [2 /*return*/, this.orderModel_
1022
- .updateOne({ _id: validatedId }, { $unset: (_a = {}, _a[keyPath] = "", _a) })
1023
- .catch(function (err) {
1024
- throw new medusa_core_utils_1.MedusaError(medusa_core_utils_1.MedusaError.Types.DB_ERROR, err.message);
1025
- })];
1026
1101
  });
1027
1102
  });
1028
1103
  };
@@ -1035,6 +1110,6 @@ var ClaimService = /** @class */ (function (_super) {
1035
1110
  REFUND_PROCESSED: "claim.refund_processed",
1036
1111
  };
1037
1112
  return ClaimService;
1038
- }(medusa_interfaces_1.BaseService));
1113
+ }(interfaces_1.TransactionBaseService));
1039
1114
  exports.default = ClaimService;
1040
1115
  //# sourceMappingURL=claim.js.map