@medusajs/medusa 1.3.7 → 1.3.8

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 (778) hide show
  1. package/.turbo/turbo-build.log +1 -1
  2. package/CHANGELOG.md +13 -0
  3. package/dist/api/middlewares/await-middleware.d.ts +14 -0
  4. package/dist/api/middlewares/await-middleware.js +14 -0
  5. package/dist/api/middlewares/await-middleware.js.map +1 -1
  6. package/dist/api/middlewares/error-handler.d.ts +15 -0
  7. package/dist/api/middlewares/error-handler.js +15 -0
  8. package/dist/api/middlewares/error-handler.js.map +1 -1
  9. package/dist/api/routes/admin/apps/authorize-app.d.ts +27 -0
  10. package/dist/api/routes/admin/apps/authorize-app.js +27 -0
  11. package/dist/api/routes/admin/apps/authorize-app.js.map +1 -1
  12. package/dist/api/routes/admin/apps/list.d.ts +21 -0
  13. package/dist/api/routes/admin/apps/list.js +21 -0
  14. package/dist/api/routes/admin/apps/list.js.map +1 -1
  15. package/dist/api/routes/admin/auth/create-session.d.ts +32 -1
  16. package/dist/api/routes/admin/auth/create-session.js +32 -1
  17. package/dist/api/routes/admin/auth/create-session.js.map +1 -1
  18. package/dist/api/routes/admin/auth/delete-session.d.ts +28 -0
  19. package/dist/api/routes/admin/auth/delete-session.js +28 -0
  20. package/dist/api/routes/admin/auth/delete-session.js.map +1 -1
  21. package/dist/api/routes/admin/auth/get-session.d.ts +30 -1
  22. package/dist/api/routes/admin/auth/get-session.js +30 -1
  23. package/dist/api/routes/admin/auth/get-session.js.map +1 -1
  24. package/dist/api/routes/admin/batch/cancel-batch-job.d.ts +31 -0
  25. package/dist/api/routes/admin/batch/cancel-batch-job.js +31 -0
  26. package/dist/api/routes/admin/batch/cancel-batch-job.js.map +1 -1
  27. package/dist/api/routes/admin/batch/confirm-batch-job.d.ts +31 -0
  28. package/dist/api/routes/admin/batch/confirm-batch-job.js +31 -0
  29. package/dist/api/routes/admin/batch/confirm-batch-job.js.map +1 -1
  30. package/dist/api/routes/admin/batch/create-batch-job.d.ts +39 -0
  31. package/dist/api/routes/admin/batch/create-batch-job.js +39 -0
  32. package/dist/api/routes/admin/batch/create-batch-job.js.map +1 -1
  33. package/dist/api/routes/admin/batch/get-batch-job.d.ts +31 -0
  34. package/dist/api/routes/admin/batch/get-batch-job.js +31 -0
  35. package/dist/api/routes/admin/batch/get-batch-job.js.map +1 -1
  36. package/dist/api/routes/admin/batch/list-batch-jobs.d.ts +31 -0
  37. package/dist/api/routes/admin/batch/list-batch-jobs.js +31 -0
  38. package/dist/api/routes/admin/batch/list-batch-jobs.js.map +1 -1
  39. package/dist/api/routes/admin/collections/add-products.d.ts +27 -0
  40. package/dist/api/routes/admin/collections/add-products.js +27 -0
  41. package/dist/api/routes/admin/collections/add-products.js.map +1 -1
  42. package/dist/api/routes/admin/collections/create-collection.d.ts +37 -0
  43. package/dist/api/routes/admin/collections/create-collection.js +37 -0
  44. package/dist/api/routes/admin/collections/create-collection.js.map +1 -1
  45. package/dist/api/routes/admin/collections/delete-collection.d.ts +31 -0
  46. package/dist/api/routes/admin/collections/delete-collection.js +31 -0
  47. package/dist/api/routes/admin/collections/delete-collection.js.map +1 -1
  48. package/dist/api/routes/admin/collections/get-collection.d.ts +31 -0
  49. package/dist/api/routes/admin/collections/get-collection.js +31 -0
  50. package/dist/api/routes/admin/collections/get-collection.js.map +1 -1
  51. package/dist/api/routes/admin/collections/list-collections.d.ts +31 -0
  52. package/dist/api/routes/admin/collections/list-collections.js +31 -0
  53. package/dist/api/routes/admin/collections/list-collections.js.map +1 -1
  54. package/dist/api/routes/admin/collections/remove-products.d.ts +27 -0
  55. package/dist/api/routes/admin/collections/remove-products.js +27 -0
  56. package/dist/api/routes/admin/collections/remove-products.js.map +1 -1
  57. package/dist/api/routes/admin/collections/update-collection.d.ts +37 -0
  58. package/dist/api/routes/admin/collections/update-collection.js +37 -0
  59. package/dist/api/routes/admin/collections/update-collection.js.map +1 -1
  60. package/dist/api/routes/admin/customer-groups/add-customers-batch.d.ts +45 -0
  61. package/dist/api/routes/admin/customer-groups/add-customers-batch.js +45 -0
  62. package/dist/api/routes/admin/customer-groups/add-customers-batch.js.map +1 -1
  63. package/dist/api/routes/admin/customer-groups/create-customer-group.d.ts +37 -0
  64. package/dist/api/routes/admin/customer-groups/create-customer-group.js +37 -0
  65. package/dist/api/routes/admin/customer-groups/create-customer-group.js.map +1 -1
  66. package/dist/api/routes/admin/customer-groups/delete-customer-group.d.ts +31 -0
  67. package/dist/api/routes/admin/customer-groups/delete-customer-group.js +31 -0
  68. package/dist/api/routes/admin/customer-groups/delete-customer-group.js.map +1 -1
  69. package/dist/api/routes/admin/customer-groups/delete-customers-batch.d.ts +45 -0
  70. package/dist/api/routes/admin/customer-groups/delete-customers-batch.js +45 -0
  71. package/dist/api/routes/admin/customer-groups/delete-customers-batch.js.map +1 -1
  72. package/dist/api/routes/admin/customer-groups/get-customer-group-customers.d.ts +31 -0
  73. package/dist/api/routes/admin/customer-groups/get-customer-group-customers.js +31 -0
  74. package/dist/api/routes/admin/customer-groups/get-customer-group-customers.js.map +1 -1
  75. package/dist/api/routes/admin/customer-groups/get-customer-group.d.ts +31 -0
  76. package/dist/api/routes/admin/customer-groups/get-customer-group.js +31 -0
  77. package/dist/api/routes/admin/customer-groups/get-customer-group.js.map +1 -1
  78. package/dist/api/routes/admin/customer-groups/list-customer-groups.d.ts +31 -1
  79. package/dist/api/routes/admin/customer-groups/list-customer-groups.js +31 -1
  80. package/dist/api/routes/admin/customer-groups/list-customer-groups.js.map +1 -1
  81. package/dist/api/routes/admin/customer-groups/update-customer-group.d.ts +37 -0
  82. package/dist/api/routes/admin/customer-groups/update-customer-group.js +37 -0
  83. package/dist/api/routes/admin/customer-groups/update-customer-group.js.map +1 -1
  84. package/dist/api/routes/admin/customers/create-customer.d.ts +43 -0
  85. package/dist/api/routes/admin/customers/create-customer.js +43 -0
  86. package/dist/api/routes/admin/customers/create-customer.js.map +1 -1
  87. package/dist/api/routes/admin/customers/get-customer.d.ts +31 -0
  88. package/dist/api/routes/admin/customers/get-customer.js +31 -0
  89. package/dist/api/routes/admin/customers/get-customer.js.map +1 -1
  90. package/dist/api/routes/admin/customers/list-customers.d.ts +31 -0
  91. package/dist/api/routes/admin/customers/list-customers.js +31 -0
  92. package/dist/api/routes/admin/customers/list-customers.js.map +1 -1
  93. package/dist/api/routes/admin/customers/update-customer.d.ts +37 -0
  94. package/dist/api/routes/admin/customers/update-customer.js +37 -0
  95. package/dist/api/routes/admin/customers/update-customer.js.map +1 -1
  96. package/dist/api/routes/admin/discounts/add-region.d.ts +31 -0
  97. package/dist/api/routes/admin/discounts/add-region.js +31 -0
  98. package/dist/api/routes/admin/discounts/add-region.js.map +1 -1
  99. package/dist/api/routes/admin/discounts/create-condition.d.ts +38 -1
  100. package/dist/api/routes/admin/discounts/create-condition.js +38 -1
  101. package/dist/api/routes/admin/discounts/create-condition.js.map +1 -1
  102. package/dist/api/routes/admin/discounts/create-discount.d.ts +50 -0
  103. package/dist/api/routes/admin/discounts/create-discount.js +50 -0
  104. package/dist/api/routes/admin/discounts/create-discount.js.map +1 -1
  105. package/dist/api/routes/admin/discounts/create-dynamic-code.d.ts +38 -0
  106. package/dist/api/routes/admin/discounts/create-dynamic-code.js +38 -0
  107. package/dist/api/routes/admin/discounts/create-dynamic-code.js.map +1 -1
  108. package/dist/api/routes/admin/discounts/delete-condition.d.ts +31 -0
  109. package/dist/api/routes/admin/discounts/delete-condition.js +31 -0
  110. package/dist/api/routes/admin/discounts/delete-condition.js.map +1 -1
  111. package/dist/api/routes/admin/discounts/delete-discount.d.ts +31 -0
  112. package/dist/api/routes/admin/discounts/delete-discount.js +31 -0
  113. package/dist/api/routes/admin/discounts/delete-discount.js.map +1 -1
  114. package/dist/api/routes/admin/discounts/delete-dynamic-code.d.ts +31 -0
  115. package/dist/api/routes/admin/discounts/delete-dynamic-code.js +31 -0
  116. package/dist/api/routes/admin/discounts/delete-dynamic-code.js.map +1 -1
  117. package/dist/api/routes/admin/discounts/get-condition.d.ts +32 -2
  118. package/dist/api/routes/admin/discounts/get-condition.js +32 -2
  119. package/dist/api/routes/admin/discounts/get-condition.js.map +1 -1
  120. package/dist/api/routes/admin/discounts/get-discount-by-code.d.ts +31 -0
  121. package/dist/api/routes/admin/discounts/get-discount-by-code.js +31 -0
  122. package/dist/api/routes/admin/discounts/get-discount-by-code.js.map +1 -1
  123. package/dist/api/routes/admin/discounts/get-discount.d.ts +31 -0
  124. package/dist/api/routes/admin/discounts/get-discount.js +31 -0
  125. package/dist/api/routes/admin/discounts/get-discount.js.map +1 -1
  126. package/dist/api/routes/admin/discounts/list-discounts.d.ts +31 -0
  127. package/dist/api/routes/admin/discounts/list-discounts.js +31 -0
  128. package/dist/api/routes/admin/discounts/list-discounts.js.map +1 -1
  129. package/dist/api/routes/admin/discounts/remove-region.d.ts +31 -0
  130. package/dist/api/routes/admin/discounts/remove-region.js +31 -0
  131. package/dist/api/routes/admin/discounts/remove-region.js.map +1 -1
  132. package/dist/api/routes/admin/discounts/update-condition.d.ts +41 -0
  133. package/dist/api/routes/admin/discounts/update-condition.js +41 -0
  134. package/dist/api/routes/admin/discounts/update-condition.js.map +1 -1
  135. package/dist/api/routes/admin/discounts/update-discount.d.ts +37 -0
  136. package/dist/api/routes/admin/discounts/update-discount.js +37 -0
  137. package/dist/api/routes/admin/discounts/update-discount.js.map +1 -1
  138. package/dist/api/routes/admin/draft-orders/create-draft-order.d.ts +59 -0
  139. package/dist/api/routes/admin/draft-orders/create-draft-order.js +59 -0
  140. package/dist/api/routes/admin/draft-orders/create-draft-order.js.map +1 -1
  141. package/dist/api/routes/admin/draft-orders/create-line-item.d.ts +37 -0
  142. package/dist/api/routes/admin/draft-orders/create-line-item.js +37 -0
  143. package/dist/api/routes/admin/draft-orders/create-line-item.js.map +1 -1
  144. package/dist/api/routes/admin/draft-orders/delete-draft-order.d.ts +31 -0
  145. package/dist/api/routes/admin/draft-orders/delete-draft-order.js +31 -0
  146. package/dist/api/routes/admin/draft-orders/delete-draft-order.js.map +1 -1
  147. package/dist/api/routes/admin/draft-orders/delete-line-item.d.ts +31 -0
  148. package/dist/api/routes/admin/draft-orders/delete-line-item.js +31 -0
  149. package/dist/api/routes/admin/draft-orders/delete-line-item.js.map +1 -1
  150. package/dist/api/routes/admin/draft-orders/get-draft-order.d.ts +31 -0
  151. package/dist/api/routes/admin/draft-orders/get-draft-order.js +31 -0
  152. package/dist/api/routes/admin/draft-orders/get-draft-order.js.map +1 -1
  153. package/dist/api/routes/admin/draft-orders/list-draft-orders.d.ts +31 -0
  154. package/dist/api/routes/admin/draft-orders/list-draft-orders.js +31 -0
  155. package/dist/api/routes/admin/draft-orders/list-draft-orders.js.map +1 -1
  156. package/dist/api/routes/admin/draft-orders/register-payment.d.ts +31 -0
  157. package/dist/api/routes/admin/draft-orders/register-payment.js +31 -0
  158. package/dist/api/routes/admin/draft-orders/register-payment.js.map +1 -1
  159. package/dist/api/routes/admin/draft-orders/update-draft-order.d.ts +37 -0
  160. package/dist/api/routes/admin/draft-orders/update-draft-order.js +37 -0
  161. package/dist/api/routes/admin/draft-orders/update-draft-order.js.map +1 -1
  162. package/dist/api/routes/admin/draft-orders/update-line-item.d.ts +37 -0
  163. package/dist/api/routes/admin/draft-orders/update-line-item.js +37 -0
  164. package/dist/api/routes/admin/draft-orders/update-line-item.js.map +1 -1
  165. package/dist/api/routes/admin/gift-cards/create-gift-card.d.ts +37 -0
  166. package/dist/api/routes/admin/gift-cards/create-gift-card.js +37 -0
  167. package/dist/api/routes/admin/gift-cards/create-gift-card.js.map +1 -1
  168. package/dist/api/routes/admin/gift-cards/delete-gift-card.d.ts +31 -0
  169. package/dist/api/routes/admin/gift-cards/delete-gift-card.js +31 -0
  170. package/dist/api/routes/admin/gift-cards/delete-gift-card.js.map +1 -1
  171. package/dist/api/routes/admin/gift-cards/get-gift-card.d.ts +31 -0
  172. package/dist/api/routes/admin/gift-cards/get-gift-card.js +31 -0
  173. package/dist/api/routes/admin/gift-cards/get-gift-card.js.map +1 -1
  174. package/dist/api/routes/admin/gift-cards/list-gift-cards.d.ts +31 -0
  175. package/dist/api/routes/admin/gift-cards/list-gift-cards.js +31 -0
  176. package/dist/api/routes/admin/gift-cards/list-gift-cards.js.map +1 -1
  177. package/dist/api/routes/admin/gift-cards/update-gift-card.d.ts +37 -0
  178. package/dist/api/routes/admin/gift-cards/update-gift-card.js +37 -0
  179. package/dist/api/routes/admin/gift-cards/update-gift-card.js.map +1 -1
  180. package/dist/api/routes/admin/invites/accept-invite.d.ts +50 -0
  181. package/dist/api/routes/admin/invites/accept-invite.js +50 -0
  182. package/dist/api/routes/admin/invites/accept-invite.js.map +1 -1
  183. package/dist/api/routes/admin/invites/create-invite.d.ts +42 -0
  184. package/dist/api/routes/admin/invites/create-invite.js +42 -0
  185. package/dist/api/routes/admin/invites/create-invite.js.map +1 -1
  186. package/dist/api/routes/admin/invites/delete-invite.d.ts +31 -0
  187. package/dist/api/routes/admin/invites/delete-invite.js +31 -0
  188. package/dist/api/routes/admin/invites/delete-invite.js.map +1 -1
  189. package/dist/api/routes/admin/invites/list-invites.d.ts +31 -0
  190. package/dist/api/routes/admin/invites/list-invites.js +31 -0
  191. package/dist/api/routes/admin/invites/list-invites.js.map +1 -1
  192. package/dist/api/routes/admin/invites/resend-invite.d.ts +34 -0
  193. package/dist/api/routes/admin/invites/resend-invite.js +34 -0
  194. package/dist/api/routes/admin/invites/resend-invite.js.map +1 -1
  195. package/dist/api/routes/admin/notes/create-note.d.ts +41 -0
  196. package/dist/api/routes/admin/notes/create-note.js +41 -0
  197. package/dist/api/routes/admin/notes/create-note.js.map +1 -1
  198. package/dist/api/routes/admin/notes/delete-note.d.ts +31 -0
  199. package/dist/api/routes/admin/notes/delete-note.js +31 -0
  200. package/dist/api/routes/admin/notes/delete-note.js.map +1 -1
  201. package/dist/api/routes/admin/notes/get-note.d.ts +31 -0
  202. package/dist/api/routes/admin/notes/get-note.js +31 -0
  203. package/dist/api/routes/admin/notes/get-note.js.map +1 -1
  204. package/dist/api/routes/admin/notes/list-notes.d.ts +31 -0
  205. package/dist/api/routes/admin/notes/list-notes.js +31 -0
  206. package/dist/api/routes/admin/notes/list-notes.js.map +1 -1
  207. package/dist/api/routes/admin/notes/update-note.d.ts +37 -1
  208. package/dist/api/routes/admin/notes/update-note.js +37 -1
  209. package/dist/api/routes/admin/notes/update-note.js.map +1 -1
  210. package/dist/api/routes/admin/notifications/list-notifications.d.ts +31 -0
  211. package/dist/api/routes/admin/notifications/list-notifications.js +31 -0
  212. package/dist/api/routes/admin/notifications/list-notifications.js.map +1 -1
  213. package/dist/api/routes/admin/notifications/resend-notification.d.ts +31 -0
  214. package/dist/api/routes/admin/notifications/resend-notification.js +31 -0
  215. package/dist/api/routes/admin/notifications/resend-notification.js.map +1 -1
  216. package/dist/api/routes/admin/orders/add-shipping-method.d.ts +39 -0
  217. package/dist/api/routes/admin/orders/add-shipping-method.js +39 -0
  218. package/dist/api/routes/admin/orders/add-shipping-method.js.map +1 -1
  219. package/dist/api/routes/admin/orders/archive-order.d.ts +31 -0
  220. package/dist/api/routes/admin/orders/archive-order.js +31 -0
  221. package/dist/api/routes/admin/orders/archive-order.js.map +1 -1
  222. package/dist/api/routes/admin/orders/cancel-claim.d.ts +31 -0
  223. package/dist/api/routes/admin/orders/cancel-claim.js +31 -0
  224. package/dist/api/routes/admin/orders/cancel-claim.js.map +1 -1
  225. package/dist/api/routes/admin/orders/cancel-fulfillment-claim.d.ts +31 -0
  226. package/dist/api/routes/admin/orders/cancel-fulfillment-claim.js +31 -0
  227. package/dist/api/routes/admin/orders/cancel-fulfillment-claim.js.map +1 -1
  228. package/dist/api/routes/admin/orders/cancel-fulfillment-swap.d.ts +31 -0
  229. package/dist/api/routes/admin/orders/cancel-fulfillment-swap.js +31 -0
  230. package/dist/api/routes/admin/orders/cancel-fulfillment-swap.js.map +1 -1
  231. package/dist/api/routes/admin/orders/cancel-fulfillment.d.ts +31 -0
  232. package/dist/api/routes/admin/orders/cancel-fulfillment.js +31 -0
  233. package/dist/api/routes/admin/orders/cancel-fulfillment.js.map +1 -1
  234. package/dist/api/routes/admin/orders/cancel-order.d.ts +31 -0
  235. package/dist/api/routes/admin/orders/cancel-order.js +31 -0
  236. package/dist/api/routes/admin/orders/cancel-order.js.map +1 -1
  237. package/dist/api/routes/admin/orders/cancel-swap.d.ts +31 -0
  238. package/dist/api/routes/admin/orders/cancel-swap.js +31 -0
  239. package/dist/api/routes/admin/orders/cancel-swap.js.map +1 -1
  240. package/dist/api/routes/admin/orders/capture-payment.d.ts +31 -0
  241. package/dist/api/routes/admin/orders/capture-payment.js +31 -0
  242. package/dist/api/routes/admin/orders/capture-payment.js.map +1 -1
  243. package/dist/api/routes/admin/orders/complete-order.d.ts +31 -0
  244. package/dist/api/routes/admin/orders/complete-order.js +31 -0
  245. package/dist/api/routes/admin/orders/complete-order.js.map +1 -1
  246. package/dist/api/routes/admin/orders/create-claim-shipment.d.ts +37 -0
  247. package/dist/api/routes/admin/orders/create-claim-shipment.js +37 -0
  248. package/dist/api/routes/admin/orders/create-claim-shipment.js.map +1 -1
  249. package/dist/api/routes/admin/orders/create-claim.d.ts +49 -0
  250. package/dist/api/routes/admin/orders/create-claim.js +49 -0
  251. package/dist/api/routes/admin/orders/create-claim.js.map +1 -1
  252. package/dist/api/routes/admin/orders/create-fulfillment.d.ts +47 -0
  253. package/dist/api/routes/admin/orders/create-fulfillment.js +47 -0
  254. package/dist/api/routes/admin/orders/create-fulfillment.js.map +1 -1
  255. package/dist/api/routes/admin/orders/create-shipment.d.ts +37 -0
  256. package/dist/api/routes/admin/orders/create-shipment.js +37 -0
  257. package/dist/api/routes/admin/orders/create-shipment.js.map +1 -1
  258. package/dist/api/routes/admin/orders/create-swap-shipment.d.ts +38 -1
  259. package/dist/api/routes/admin/orders/create-swap-shipment.js +38 -1
  260. package/dist/api/routes/admin/orders/create-swap-shipment.js.map +1 -1
  261. package/dist/api/routes/admin/orders/create-swap.d.ts +47 -0
  262. package/dist/api/routes/admin/orders/create-swap.js +47 -0
  263. package/dist/api/routes/admin/orders/create-swap.js.map +1 -1
  264. package/dist/api/routes/admin/orders/fulfill-claim.d.ts +31 -0
  265. package/dist/api/routes/admin/orders/fulfill-claim.js +31 -0
  266. package/dist/api/routes/admin/orders/fulfill-claim.js.map +1 -1
  267. package/dist/api/routes/admin/orders/fulfill-swap.d.ts +32 -1
  268. package/dist/api/routes/admin/orders/fulfill-swap.js +31 -0
  269. package/dist/api/routes/admin/orders/fulfill-swap.js.map +1 -1
  270. package/dist/api/routes/admin/orders/get-order.d.ts +31 -0
  271. package/dist/api/routes/admin/orders/get-order.js +31 -0
  272. package/dist/api/routes/admin/orders/get-order.js.map +1 -1
  273. package/dist/api/routes/admin/orders/list-orders.d.ts +31 -0
  274. package/dist/api/routes/admin/orders/list-orders.js +31 -0
  275. package/dist/api/routes/admin/orders/list-orders.js.map +1 -1
  276. package/dist/api/routes/admin/orders/process-swap-payment.d.ts +31 -0
  277. package/dist/api/routes/admin/orders/process-swap-payment.js +31 -0
  278. package/dist/api/routes/admin/orders/process-swap-payment.js.map +1 -1
  279. package/dist/api/routes/admin/orders/refund-payment.d.ts +39 -0
  280. package/dist/api/routes/admin/orders/refund-payment.js +39 -0
  281. package/dist/api/routes/admin/orders/refund-payment.js.map +1 -1
  282. package/dist/api/routes/admin/orders/request-return.d.ts +47 -0
  283. package/dist/api/routes/admin/orders/request-return.js +47 -0
  284. package/dist/api/routes/admin/orders/request-return.js.map +1 -1
  285. package/dist/api/routes/admin/orders/update-claim.d.ts +37 -0
  286. package/dist/api/routes/admin/orders/update-claim.js +37 -0
  287. package/dist/api/routes/admin/orders/update-claim.js.map +1 -1
  288. package/dist/api/routes/admin/orders/update-order.d.ts +37 -0
  289. package/dist/api/routes/admin/orders/update-order.js +37 -0
  290. package/dist/api/routes/admin/orders/update-order.js.map +1 -1
  291. package/dist/api/routes/admin/price-lists/add-prices-batch.d.ts +49 -0
  292. package/dist/api/routes/admin/price-lists/add-prices-batch.js +49 -0
  293. package/dist/api/routes/admin/price-lists/add-prices-batch.js.map +1 -1
  294. package/dist/api/routes/admin/price-lists/create-price-list.d.ts +56 -0
  295. package/dist/api/routes/admin/price-lists/create-price-list.js +56 -0
  296. package/dist/api/routes/admin/price-lists/create-price-list.js.map +1 -1
  297. package/dist/api/routes/admin/price-lists/delete-price-list.d.ts +31 -0
  298. package/dist/api/routes/admin/price-lists/delete-price-list.js +31 -0
  299. package/dist/api/routes/admin/price-lists/delete-price-list.js.map +1 -1
  300. package/dist/api/routes/admin/price-lists/delete-prices-batch.d.ts +41 -0
  301. package/dist/api/routes/admin/price-lists/delete-prices-batch.js +41 -0
  302. package/dist/api/routes/admin/price-lists/delete-prices-batch.js.map +1 -1
  303. package/dist/api/routes/admin/price-lists/delete-product-prices.d.ts +31 -0
  304. package/dist/api/routes/admin/price-lists/delete-product-prices.js +31 -0
  305. package/dist/api/routes/admin/price-lists/delete-product-prices.js.map +1 -1
  306. package/dist/api/routes/admin/price-lists/delete-variant-prices.d.ts +31 -0
  307. package/dist/api/routes/admin/price-lists/delete-variant-prices.js +31 -0
  308. package/dist/api/routes/admin/price-lists/delete-variant-prices.js.map +1 -1
  309. package/dist/api/routes/admin/price-lists/get-price-list.d.ts +31 -0
  310. package/dist/api/routes/admin/price-lists/get-price-list.js +31 -0
  311. package/dist/api/routes/admin/price-lists/get-price-list.js.map +1 -1
  312. package/dist/api/routes/admin/price-lists/list-price-list-products.d.ts +31 -0
  313. package/dist/api/routes/admin/price-lists/list-price-list-products.js +31 -0
  314. package/dist/api/routes/admin/price-lists/list-price-list-products.js.map +1 -1
  315. package/dist/api/routes/admin/price-lists/list-price-lists.d.ts +31 -0
  316. package/dist/api/routes/admin/price-lists/list-price-lists.js +31 -0
  317. package/dist/api/routes/admin/price-lists/list-price-lists.js.map +1 -1
  318. package/dist/api/routes/admin/price-lists/update-price-list.d.ts +37 -0
  319. package/dist/api/routes/admin/price-lists/update-price-list.js +37 -0
  320. package/dist/api/routes/admin/price-lists/update-price-list.js.map +1 -1
  321. package/dist/api/routes/admin/product-tags/list-product-tags.d.ts +31 -0
  322. package/dist/api/routes/admin/product-tags/list-product-tags.js +31 -0
  323. package/dist/api/routes/admin/product-tags/list-product-tags.js.map +1 -1
  324. package/dist/api/routes/admin/product-types/list-product-types.d.ts +31 -0
  325. package/dist/api/routes/admin/product-types/list-product-types.js +31 -0
  326. package/dist/api/routes/admin/product-types/list-product-types.js.map +1 -1
  327. package/dist/api/routes/admin/products/add-option.d.ts +37 -0
  328. package/dist/api/routes/admin/products/add-option.js +37 -0
  329. package/dist/api/routes/admin/products/add-option.js.map +1 -1
  330. package/dist/api/routes/admin/products/create-product.d.ts +40 -1
  331. package/dist/api/routes/admin/products/create-product.js +40 -1
  332. package/dist/api/routes/admin/products/create-product.js.map +1 -1
  333. package/dist/api/routes/admin/products/create-variant.d.ts +62 -0
  334. package/dist/api/routes/admin/products/create-variant.js +62 -0
  335. package/dist/api/routes/admin/products/create-variant.js.map +1 -1
  336. package/dist/api/routes/admin/products/delete-option.d.ts +31 -0
  337. package/dist/api/routes/admin/products/delete-option.js +31 -0
  338. package/dist/api/routes/admin/products/delete-option.js.map +1 -1
  339. package/dist/api/routes/admin/products/delete-product.d.ts +31 -0
  340. package/dist/api/routes/admin/products/delete-product.js +31 -0
  341. package/dist/api/routes/admin/products/delete-product.js.map +1 -1
  342. package/dist/api/routes/admin/products/delete-variant.d.ts +31 -0
  343. package/dist/api/routes/admin/products/delete-variant.js +31 -0
  344. package/dist/api/routes/admin/products/delete-variant.js.map +1 -1
  345. package/dist/api/routes/admin/products/get-product.d.ts +31 -0
  346. package/dist/api/routes/admin/products/get-product.js +31 -0
  347. package/dist/api/routes/admin/products/get-product.js.map +1 -1
  348. package/dist/api/routes/admin/products/list-products.d.ts +31 -0
  349. package/dist/api/routes/admin/products/list-products.js +31 -0
  350. package/dist/api/routes/admin/products/list-products.js.map +1 -1
  351. package/dist/api/routes/admin/products/list-tag-usage-count.d.ts +31 -0
  352. package/dist/api/routes/admin/products/list-tag-usage-count.js +31 -0
  353. package/dist/api/routes/admin/products/list-tag-usage-count.js.map +1 -1
  354. package/dist/api/routes/admin/products/list-types.d.ts +31 -0
  355. package/dist/api/routes/admin/products/list-types.js +31 -0
  356. package/dist/api/routes/admin/products/list-types.js.map +1 -1
  357. package/dist/api/routes/admin/products/list-variants.d.ts +21 -0
  358. package/dist/api/routes/admin/products/list-variants.js +21 -0
  359. package/dist/api/routes/admin/products/list-variants.js.map +1 -1
  360. package/dist/api/routes/admin/products/set-metadata.d.ts +39 -0
  361. package/dist/api/routes/admin/products/set-metadata.js +39 -0
  362. package/dist/api/routes/admin/products/set-metadata.js.map +1 -1
  363. package/dist/api/routes/admin/products/update-option.d.ts +37 -0
  364. package/dist/api/routes/admin/products/update-option.js +37 -0
  365. package/dist/api/routes/admin/products/update-option.js.map +1 -1
  366. package/dist/api/routes/admin/products/update-product.d.ts +38 -0
  367. package/dist/api/routes/admin/products/update-product.js +38 -0
  368. package/dist/api/routes/admin/products/update-product.js.map +1 -1
  369. package/dist/api/routes/admin/products/update-variant.d.ts +59 -1
  370. package/dist/api/routes/admin/products/update-variant.js +59 -1
  371. package/dist/api/routes/admin/products/update-variant.js.map +1 -1
  372. package/dist/api/routes/admin/regions/add-country.d.ts +37 -0
  373. package/dist/api/routes/admin/regions/add-country.js +37 -0
  374. package/dist/api/routes/admin/regions/add-country.js.map +1 -1
  375. package/dist/api/routes/admin/regions/add-fulfillment-provider.d.ts +37 -0
  376. package/dist/api/routes/admin/regions/add-fulfillment-provider.js +37 -0
  377. package/dist/api/routes/admin/regions/add-fulfillment-provider.js.map +1 -1
  378. package/dist/api/routes/admin/regions/add-payment-provider.d.ts +37 -0
  379. package/dist/api/routes/admin/regions/add-payment-provider.js +37 -0
  380. package/dist/api/routes/admin/regions/add-payment-provider.js.map +1 -1
  381. package/dist/api/routes/admin/regions/create-region.d.ts +59 -0
  382. package/dist/api/routes/admin/regions/create-region.js +59 -0
  383. package/dist/api/routes/admin/regions/create-region.js.map +1 -1
  384. package/dist/api/routes/admin/regions/delete-region.d.ts +31 -0
  385. package/dist/api/routes/admin/regions/delete-region.js +31 -0
  386. package/dist/api/routes/admin/regions/delete-region.js.map +1 -1
  387. package/dist/api/routes/admin/regions/get-fulfillment-options.d.ts +31 -0
  388. package/dist/api/routes/admin/regions/get-fulfillment-options.js +31 -0
  389. package/dist/api/routes/admin/regions/get-fulfillment-options.js.map +1 -1
  390. package/dist/api/routes/admin/regions/get-region.d.ts +31 -0
  391. package/dist/api/routes/admin/regions/get-region.js +31 -0
  392. package/dist/api/routes/admin/regions/get-region.js.map +1 -1
  393. package/dist/api/routes/admin/regions/list-regions.d.ts +31 -0
  394. package/dist/api/routes/admin/regions/list-regions.js +31 -0
  395. package/dist/api/routes/admin/regions/list-regions.js.map +1 -1
  396. package/dist/api/routes/admin/regions/remove-country.d.ts +31 -0
  397. package/dist/api/routes/admin/regions/remove-country.js +31 -0
  398. package/dist/api/routes/admin/regions/remove-country.js.map +1 -1
  399. package/dist/api/routes/admin/regions/remove-fulfillment-provider.d.ts +31 -0
  400. package/dist/api/routes/admin/regions/remove-fulfillment-provider.js +31 -0
  401. package/dist/api/routes/admin/regions/remove-fulfillment-provider.js.map +1 -1
  402. package/dist/api/routes/admin/regions/remove-payment-provider.d.ts +31 -0
  403. package/dist/api/routes/admin/regions/remove-payment-provider.js +31 -0
  404. package/dist/api/routes/admin/regions/remove-payment-provider.js.map +1 -1
  405. package/dist/api/routes/admin/regions/update-region.d.ts +37 -0
  406. package/dist/api/routes/admin/regions/update-region.js +37 -0
  407. package/dist/api/routes/admin/regions/update-region.js.map +1 -1
  408. package/dist/api/routes/admin/return-reasons/create-reason.d.ts +39 -0
  409. package/dist/api/routes/admin/return-reasons/create-reason.js +39 -0
  410. package/dist/api/routes/admin/return-reasons/create-reason.js.map +1 -1
  411. package/dist/api/routes/admin/return-reasons/delete-reason.d.ts +31 -0
  412. package/dist/api/routes/admin/return-reasons/delete-reason.js +31 -0
  413. package/dist/api/routes/admin/return-reasons/delete-reason.js.map +1 -1
  414. package/dist/api/routes/admin/return-reasons/get-reason.d.ts +31 -0
  415. package/dist/api/routes/admin/return-reasons/get-reason.js +31 -0
  416. package/dist/api/routes/admin/return-reasons/get-reason.js.map +1 -1
  417. package/dist/api/routes/admin/return-reasons/list-reasons.d.ts +31 -0
  418. package/dist/api/routes/admin/return-reasons/list-reasons.js +31 -0
  419. package/dist/api/routes/admin/return-reasons/list-reasons.js.map +1 -1
  420. package/dist/api/routes/admin/return-reasons/update-reason.d.ts +37 -0
  421. package/dist/api/routes/admin/return-reasons/update-reason.js +37 -0
  422. package/dist/api/routes/admin/return-reasons/update-reason.js.map +1 -1
  423. package/dist/api/routes/admin/returns/cancel-return.d.ts +31 -0
  424. package/dist/api/routes/admin/returns/cancel-return.js +31 -0
  425. package/dist/api/routes/admin/returns/cancel-return.js.map +1 -1
  426. package/dist/api/routes/admin/returns/list-returns.d.ts +31 -0
  427. package/dist/api/routes/admin/returns/list-returns.js +31 -0
  428. package/dist/api/routes/admin/returns/list-returns.js.map +1 -1
  429. package/dist/api/routes/admin/returns/receive-return.d.ts +47 -0
  430. package/dist/api/routes/admin/returns/receive-return.js +47 -0
  431. package/dist/api/routes/admin/returns/receive-return.js.map +1 -1
  432. package/dist/api/routes/admin/sales-channels/add-product-batch.d.ts +45 -0
  433. package/dist/api/routes/admin/sales-channels/add-product-batch.js +45 -0
  434. package/dist/api/routes/admin/sales-channels/add-product-batch.js.map +1 -1
  435. package/dist/api/routes/admin/sales-channels/create-sales-channel.d.ts +38 -0
  436. package/dist/api/routes/admin/sales-channels/create-sales-channel.js +38 -0
  437. package/dist/api/routes/admin/sales-channels/create-sales-channel.js.map +1 -1
  438. package/dist/api/routes/admin/sales-channels/delete-products-batch.d.ts +45 -0
  439. package/dist/api/routes/admin/sales-channels/delete-products-batch.js +45 -0
  440. package/dist/api/routes/admin/sales-channels/delete-products-batch.js.map +1 -1
  441. package/dist/api/routes/admin/sales-channels/delete-sales-channel.d.ts +31 -0
  442. package/dist/api/routes/admin/sales-channels/delete-sales-channel.js +31 -0
  443. package/dist/api/routes/admin/sales-channels/delete-sales-channel.js.map +1 -1
  444. package/dist/api/routes/admin/sales-channels/get-sales-channel.d.ts +31 -0
  445. package/dist/api/routes/admin/sales-channels/get-sales-channel.js +31 -0
  446. package/dist/api/routes/admin/sales-channels/get-sales-channel.js.map +1 -1
  447. package/dist/api/routes/admin/sales-channels/list-sales-channels.d.ts +31 -0
  448. package/dist/api/routes/admin/sales-channels/list-sales-channels.js +31 -0
  449. package/dist/api/routes/admin/sales-channels/list-sales-channels.js.map +1 -1
  450. package/dist/api/routes/admin/sales-channels/update-sales-channel.d.ts +37 -0
  451. package/dist/api/routes/admin/sales-channels/update-sales-channel.js +37 -0
  452. package/dist/api/routes/admin/sales-channels/update-sales-channel.js.map +1 -1
  453. package/dist/api/routes/admin/shipping-options/create-shipping-option.d.ts +46 -0
  454. package/dist/api/routes/admin/shipping-options/create-shipping-option.js +46 -0
  455. package/dist/api/routes/admin/shipping-options/create-shipping-option.js.map +1 -1
  456. package/dist/api/routes/admin/shipping-options/delete-shipping-option.d.ts +31 -0
  457. package/dist/api/routes/admin/shipping-options/delete-shipping-option.js +31 -0
  458. package/dist/api/routes/admin/shipping-options/delete-shipping-option.js.map +1 -1
  459. package/dist/api/routes/admin/shipping-options/get-shipping-option.d.ts +31 -0
  460. package/dist/api/routes/admin/shipping-options/get-shipping-option.js +31 -0
  461. package/dist/api/routes/admin/shipping-options/get-shipping-option.js.map +1 -1
  462. package/dist/api/routes/admin/shipping-options/list-shipping-options.d.ts +31 -0
  463. package/dist/api/routes/admin/shipping-options/list-shipping-options.js +31 -0
  464. package/dist/api/routes/admin/shipping-options/list-shipping-options.js.map +1 -1
  465. package/dist/api/routes/admin/shipping-options/update-shipping-option.d.ts +49 -0
  466. package/dist/api/routes/admin/shipping-options/update-shipping-option.js +49 -0
  467. package/dist/api/routes/admin/shipping-options/update-shipping-option.js.map +1 -1
  468. package/dist/api/routes/admin/shipping-profiles/create-shipping-profile.d.ts +37 -0
  469. package/dist/api/routes/admin/shipping-profiles/create-shipping-profile.js +37 -0
  470. package/dist/api/routes/admin/shipping-profiles/create-shipping-profile.js.map +1 -1
  471. package/dist/api/routes/admin/shipping-profiles/delete-shipping-profile.d.ts +31 -0
  472. package/dist/api/routes/admin/shipping-profiles/delete-shipping-profile.js +31 -0
  473. package/dist/api/routes/admin/shipping-profiles/delete-shipping-profile.js.map +1 -1
  474. package/dist/api/routes/admin/shipping-profiles/get-shipping-profile.d.ts +31 -0
  475. package/dist/api/routes/admin/shipping-profiles/get-shipping-profile.js +31 -0
  476. package/dist/api/routes/admin/shipping-profiles/get-shipping-profile.js.map +1 -1
  477. package/dist/api/routes/admin/shipping-profiles/list-shipping-profiles.d.ts +31 -0
  478. package/dist/api/routes/admin/shipping-profiles/list-shipping-profiles.js +31 -0
  479. package/dist/api/routes/admin/shipping-profiles/list-shipping-profiles.js.map +1 -1
  480. package/dist/api/routes/admin/shipping-profiles/update-shipping-profile.d.ts +37 -0
  481. package/dist/api/routes/admin/shipping-profiles/update-shipping-profile.js +37 -0
  482. package/dist/api/routes/admin/shipping-profiles/update-shipping-profile.js.map +1 -1
  483. package/dist/api/routes/admin/store/add-currency.d.ts +31 -0
  484. package/dist/api/routes/admin/store/add-currency.js +31 -0
  485. package/dist/api/routes/admin/store/add-currency.js.map +1 -1
  486. package/dist/api/routes/admin/store/get-store.d.ts +31 -0
  487. package/dist/api/routes/admin/store/get-store.js +31 -0
  488. package/dist/api/routes/admin/store/get-store.js.map +1 -1
  489. package/dist/api/routes/admin/store/list-payment-providers.d.ts +31 -0
  490. package/dist/api/routes/admin/store/list-payment-providers.js +31 -0
  491. package/dist/api/routes/admin/store/list-payment-providers.js.map +1 -1
  492. package/dist/api/routes/admin/store/list-tax-providers.d.ts +31 -0
  493. package/dist/api/routes/admin/store/list-tax-providers.js +31 -0
  494. package/dist/api/routes/admin/store/list-tax-providers.js.map +1 -1
  495. package/dist/api/routes/admin/store/remove-currency.d.ts +31 -0
  496. package/dist/api/routes/admin/store/remove-currency.js +31 -0
  497. package/dist/api/routes/admin/store/remove-currency.js.map +1 -1
  498. package/dist/api/routes/admin/store/update-store.d.ts +37 -0
  499. package/dist/api/routes/admin/store/update-store.js +37 -0
  500. package/dist/api/routes/admin/store/update-store.js.map +1 -1
  501. package/dist/api/routes/admin/swaps/get-swap.d.ts +31 -0
  502. package/dist/api/routes/admin/swaps/get-swap.js +31 -0
  503. package/dist/api/routes/admin/swaps/get-swap.js.map +1 -1
  504. package/dist/api/routes/admin/swaps/list-swaps.d.ts +31 -0
  505. package/dist/api/routes/admin/swaps/list-swaps.js +32 -1
  506. package/dist/api/routes/admin/swaps/list-swaps.js.map +1 -1
  507. package/dist/api/routes/admin/tax-rates/add-to-product-types.d.ts +41 -0
  508. package/dist/api/routes/admin/tax-rates/add-to-product-types.js +41 -0
  509. package/dist/api/routes/admin/tax-rates/add-to-product-types.js.map +1 -1
  510. package/dist/api/routes/admin/tax-rates/add-to-products.d.ts +41 -0
  511. package/dist/api/routes/admin/tax-rates/add-to-products.js +41 -0
  512. package/dist/api/routes/admin/tax-rates/add-to-products.js.map +1 -1
  513. package/dist/api/routes/admin/tax-rates/add-to-shipping-options.d.ts +41 -0
  514. package/dist/api/routes/admin/tax-rates/add-to-shipping-options.js +41 -0
  515. package/dist/api/routes/admin/tax-rates/add-to-shipping-options.js.map +1 -1
  516. package/dist/api/routes/admin/tax-rates/create-tax-rate.d.ts +41 -0
  517. package/dist/api/routes/admin/tax-rates/create-tax-rate.js +41 -0
  518. package/dist/api/routes/admin/tax-rates/create-tax-rate.js.map +1 -1
  519. package/dist/api/routes/admin/tax-rates/delete-tax-rate.d.ts +31 -0
  520. package/dist/api/routes/admin/tax-rates/delete-tax-rate.js +31 -0
  521. package/dist/api/routes/admin/tax-rates/delete-tax-rate.js.map +1 -1
  522. package/dist/api/routes/admin/tax-rates/get-tax-rate.d.ts +31 -0
  523. package/dist/api/routes/admin/tax-rates/get-tax-rate.js +31 -0
  524. package/dist/api/routes/admin/tax-rates/get-tax-rate.js.map +1 -1
  525. package/dist/api/routes/admin/tax-rates/list-tax-rates.d.ts +31 -0
  526. package/dist/api/routes/admin/tax-rates/list-tax-rates.js +31 -0
  527. package/dist/api/routes/admin/tax-rates/list-tax-rates.js.map +1 -1
  528. package/dist/api/routes/admin/tax-rates/remove-from-product-types.d.ts +41 -0
  529. package/dist/api/routes/admin/tax-rates/remove-from-product-types.js +41 -0
  530. package/dist/api/routes/admin/tax-rates/remove-from-product-types.js.map +1 -1
  531. package/dist/api/routes/admin/tax-rates/remove-from-products.d.ts +41 -0
  532. package/dist/api/routes/admin/tax-rates/remove-from-products.js +41 -0
  533. package/dist/api/routes/admin/tax-rates/remove-from-products.js.map +1 -1
  534. package/dist/api/routes/admin/tax-rates/remove-from-shipping-options.d.ts +41 -0
  535. package/dist/api/routes/admin/tax-rates/remove-from-shipping-options.js +41 -0
  536. package/dist/api/routes/admin/tax-rates/remove-from-shipping-options.js.map +1 -1
  537. package/dist/api/routes/admin/tax-rates/update-tax-rate.d.ts +37 -0
  538. package/dist/api/routes/admin/tax-rates/update-tax-rate.js +37 -0
  539. package/dist/api/routes/admin/tax-rates/update-tax-rate.js.map +1 -1
  540. package/dist/api/routes/admin/uploads/create-upload.d.ts +35 -2
  541. package/dist/api/routes/admin/uploads/create-upload.js +35 -2
  542. package/dist/api/routes/admin/uploads/create-upload.js.map +1 -1
  543. package/dist/api/routes/admin/uploads/delete-upload.d.ts +37 -0
  544. package/dist/api/routes/admin/uploads/delete-upload.js +37 -0
  545. package/dist/api/routes/admin/uploads/delete-upload.js.map +1 -1
  546. package/dist/api/routes/admin/uploads/get-download-url.d.ts +37 -0
  547. package/dist/api/routes/admin/uploads/get-download-url.js +37 -0
  548. package/dist/api/routes/admin/uploads/get-download-url.js.map +1 -1
  549. package/dist/api/routes/admin/users/create-user.d.ts +39 -0
  550. package/dist/api/routes/admin/users/create-user.js +39 -0
  551. package/dist/api/routes/admin/users/create-user.js.map +1 -1
  552. package/dist/api/routes/admin/users/delete-user.d.ts +31 -0
  553. package/dist/api/routes/admin/users/delete-user.js +31 -0
  554. package/dist/api/routes/admin/users/delete-user.js.map +1 -1
  555. package/dist/api/routes/admin/users/get-user.d.ts +31 -0
  556. package/dist/api/routes/admin/users/get-user.js +31 -0
  557. package/dist/api/routes/admin/users/get-user.js.map +1 -1
  558. package/dist/api/routes/admin/users/list-users.d.ts +31 -0
  559. package/dist/api/routes/admin/users/list-users.js +31 -0
  560. package/dist/api/routes/admin/users/list-users.js.map +1 -1
  561. package/dist/api/routes/admin/users/reset-password-token.d.ts +40 -0
  562. package/dist/api/routes/admin/users/reset-password-token.js +40 -0
  563. package/dist/api/routes/admin/users/reset-password-token.js.map +1 -1
  564. package/dist/api/routes/admin/users/reset-password.d.ts +39 -0
  565. package/dist/api/routes/admin/users/reset-password.js +39 -0
  566. package/dist/api/routes/admin/users/reset-password.js.map +1 -1
  567. package/dist/api/routes/admin/users/update-user.d.ts +37 -1
  568. package/dist/api/routes/admin/users/update-user.js +37 -1
  569. package/dist/api/routes/admin/users/update-user.js.map +1 -1
  570. package/dist/api/routes/admin/variants/list-variants.d.ts +31 -0
  571. package/dist/api/routes/admin/variants/list-variants.js +31 -0
  572. package/dist/api/routes/admin/variants/list-variants.js.map +1 -1
  573. package/dist/api/routes/store/auth/create-session.d.ts +34 -0
  574. package/dist/api/routes/store/auth/create-session.js +34 -0
  575. package/dist/api/routes/store/auth/create-session.js.map +1 -1
  576. package/dist/api/routes/store/auth/delete-session.d.ts +21 -0
  577. package/dist/api/routes/store/auth/delete-session.js +21 -0
  578. package/dist/api/routes/store/auth/delete-session.js.map +1 -1
  579. package/dist/api/routes/store/auth/exists.d.ts +22 -0
  580. package/dist/api/routes/store/auth/exists.js +22 -0
  581. package/dist/api/routes/store/auth/exists.js.map +1 -1
  582. package/dist/api/routes/store/auth/get-session.d.ts +30 -2
  583. package/dist/api/routes/store/auth/get-session.js +30 -2
  584. package/dist/api/routes/store/auth/get-session.js.map +1 -1
  585. package/dist/api/routes/store/carts/add-shipping-method.d.ts +32 -2
  586. package/dist/api/routes/store/carts/add-shipping-method.js +32 -2
  587. package/dist/api/routes/store/carts/add-shipping-method.js.map +1 -1
  588. package/dist/api/routes/store/carts/calculate-taxes.d.ts +15 -0
  589. package/dist/api/routes/store/carts/calculate-taxes.js +15 -0
  590. package/dist/api/routes/store/carts/calculate-taxes.js.map +1 -1
  591. package/dist/api/routes/store/carts/complete-cart.d.ts +24 -0
  592. package/dist/api/routes/store/carts/complete-cart.js +24 -0
  593. package/dist/api/routes/store/carts/complete-cart.js.map +1 -1
  594. package/dist/api/routes/store/carts/create-cart.d.ts +24 -0
  595. package/dist/api/routes/store/carts/create-cart.js +24 -0
  596. package/dist/api/routes/store/carts/create-cart.js.map +1 -1
  597. package/dist/api/routes/store/carts/create-line-item.d.ts +32 -0
  598. package/dist/api/routes/store/carts/create-line-item.js +32 -0
  599. package/dist/api/routes/store/carts/create-line-item.js.map +1 -1
  600. package/dist/api/routes/store/carts/create-payment-sessions.d.ts +24 -0
  601. package/dist/api/routes/store/carts/create-payment-sessions.js +24 -0
  602. package/dist/api/routes/store/carts/create-payment-sessions.js.map +1 -1
  603. package/dist/api/routes/store/carts/delete-discount.d.ts +24 -0
  604. package/dist/api/routes/store/carts/delete-discount.js +24 -0
  605. package/dist/api/routes/store/carts/delete-discount.js.map +1 -1
  606. package/dist/api/routes/store/carts/delete-line-item.d.ts +24 -0
  607. package/dist/api/routes/store/carts/delete-line-item.js +24 -0
  608. package/dist/api/routes/store/carts/delete-line-item.js.map +1 -1
  609. package/dist/api/routes/store/carts/delete-payment-session.d.ts +24 -0
  610. package/dist/api/routes/store/carts/delete-payment-session.js +24 -0
  611. package/dist/api/routes/store/carts/delete-payment-session.js.map +1 -1
  612. package/dist/api/routes/store/carts/get-cart.d.ts +24 -0
  613. package/dist/api/routes/store/carts/get-cart.js +24 -0
  614. package/dist/api/routes/store/carts/get-cart.js.map +1 -1
  615. package/dist/api/routes/store/carts/refresh-payment-session.d.ts +24 -0
  616. package/dist/api/routes/store/carts/refresh-payment-session.js +24 -0
  617. package/dist/api/routes/store/carts/refresh-payment-session.js.map +1 -1
  618. package/dist/api/routes/store/carts/set-payment-session.d.ts +30 -0
  619. package/dist/api/routes/store/carts/set-payment-session.js +30 -0
  620. package/dist/api/routes/store/carts/set-payment-session.js.map +1 -1
  621. package/dist/api/routes/store/carts/update-cart.d.ts +30 -0
  622. package/dist/api/routes/store/carts/update-cart.js +30 -0
  623. package/dist/api/routes/store/carts/update-cart.js.map +1 -1
  624. package/dist/api/routes/store/carts/update-line-item.d.ts +30 -0
  625. package/dist/api/routes/store/carts/update-line-item.js +30 -0
  626. package/dist/api/routes/store/carts/update-line-item.js.map +1 -1
  627. package/dist/api/routes/store/carts/update-payment-session.d.ts +32 -0
  628. package/dist/api/routes/store/carts/update-payment-session.js +32 -0
  629. package/dist/api/routes/store/carts/update-payment-session.js.map +1 -1
  630. package/dist/api/routes/store/collections/get-collection.d.ts +24 -0
  631. package/dist/api/routes/store/collections/get-collection.js +24 -0
  632. package/dist/api/routes/store/collections/get-collection.js.map +1 -1
  633. package/dist/api/routes/store/collections/list-collections.d.ts +24 -0
  634. package/dist/api/routes/store/collections/list-collections.js +24 -0
  635. package/dist/api/routes/store/collections/list-collections.js.map +1 -1
  636. package/dist/api/routes/store/customers/create-address.d.ts +55 -0
  637. package/dist/api/routes/store/customers/create-address.js +55 -0
  638. package/dist/api/routes/store/customers/create-address.js.map +1 -1
  639. package/dist/api/routes/store/customers/create-customer.d.ts +34 -0
  640. package/dist/api/routes/store/customers/create-customer.js +34 -0
  641. package/dist/api/routes/store/customers/create-customer.js.map +1 -1
  642. package/dist/api/routes/store/customers/delete-address.d.ts +30 -0
  643. package/dist/api/routes/store/customers/delete-address.js +30 -0
  644. package/dist/api/routes/store/customers/delete-address.js.map +1 -1
  645. package/dist/api/routes/store/customers/get-customer.d.ts +30 -0
  646. package/dist/api/routes/store/customers/get-customer.js +30 -0
  647. package/dist/api/routes/store/customers/get-customer.js.map +1 -1
  648. package/dist/api/routes/store/customers/get-payment-methods.d.ts +30 -0
  649. package/dist/api/routes/store/customers/get-payment-methods.js +30 -0
  650. package/dist/api/routes/store/customers/get-payment-methods.js.map +1 -1
  651. package/dist/api/routes/store/customers/list-orders.d.ts +30 -0
  652. package/dist/api/routes/store/customers/list-orders.js +30 -0
  653. package/dist/api/routes/store/customers/list-orders.js.map +1 -1
  654. package/dist/api/routes/store/customers/reset-password-token.d.ts +35 -0
  655. package/dist/api/routes/store/customers/reset-password-token.js +35 -0
  656. package/dist/api/routes/store/customers/reset-password-token.js.map +1 -1
  657. package/dist/api/routes/store/customers/reset-password.d.ts +36 -0
  658. package/dist/api/routes/store/customers/reset-password.js +36 -0
  659. package/dist/api/routes/store/customers/reset-password.js.map +1 -1
  660. package/dist/api/routes/store/customers/update-address.d.ts +36 -0
  661. package/dist/api/routes/store/customers/update-address.js +36 -0
  662. package/dist/api/routes/store/customers/update-address.js.map +1 -1
  663. package/dist/api/routes/store/customers/update-customer.d.ts +36 -0
  664. package/dist/api/routes/store/customers/update-customer.js +36 -0
  665. package/dist/api/routes/store/customers/update-customer.js.map +1 -1
  666. package/dist/api/routes/store/gift-cards/get-gift-card.d.ts +24 -0
  667. package/dist/api/routes/store/gift-cards/get-gift-card.js +24 -0
  668. package/dist/api/routes/store/gift-cards/get-gift-card.js.map +1 -1
  669. package/dist/api/routes/store/orders/get-order-by-cart.d.ts +24 -0
  670. package/dist/api/routes/store/orders/get-order-by-cart.js +24 -0
  671. package/dist/api/routes/store/orders/get-order-by-cart.js.map +1 -1
  672. package/dist/api/routes/store/orders/get-order.d.ts +24 -0
  673. package/dist/api/routes/store/orders/get-order.js +24 -0
  674. package/dist/api/routes/store/orders/get-order.js.map +1 -1
  675. package/dist/api/routes/store/orders/lookup-order.d.ts +27 -0
  676. package/dist/api/routes/store/orders/lookup-order.js +27 -0
  677. package/dist/api/routes/store/orders/lookup-order.js.map +1 -1
  678. package/dist/api/routes/store/products/get-product.d.ts +24 -0
  679. package/dist/api/routes/store/products/get-product.js +24 -0
  680. package/dist/api/routes/store/products/get-product.js.map +1 -1
  681. package/dist/api/routes/store/products/list-products.d.ts +24 -0
  682. package/dist/api/routes/store/products/list-products.js +24 -0
  683. package/dist/api/routes/store/products/list-products.js.map +1 -1
  684. package/dist/api/routes/store/products/search.d.ts +28 -2
  685. package/dist/api/routes/store/products/search.js +28 -2
  686. package/dist/api/routes/store/products/search.js.map +1 -1
  687. package/dist/api/routes/store/regions/get-region.d.ts +24 -0
  688. package/dist/api/routes/store/regions/get-region.js +24 -0
  689. package/dist/api/routes/store/regions/get-region.js.map +1 -1
  690. package/dist/api/routes/store/regions/list-regions.d.ts +24 -0
  691. package/dist/api/routes/store/regions/list-regions.js +24 -0
  692. package/dist/api/routes/store/regions/list-regions.js.map +1 -1
  693. package/dist/api/routes/store/return-reasons/get-reason.d.ts +24 -0
  694. package/dist/api/routes/store/return-reasons/get-reason.js +24 -0
  695. package/dist/api/routes/store/return-reasons/get-reason.js.map +1 -1
  696. package/dist/api/routes/store/return-reasons/list-reasons.d.ts +24 -0
  697. package/dist/api/routes/store/return-reasons/list-reasons.js +24 -0
  698. package/dist/api/routes/store/return-reasons/list-reasons.js.map +1 -1
  699. package/dist/api/routes/store/returns/create-return.d.ts +42 -0
  700. package/dist/api/routes/store/returns/create-return.js +42 -0
  701. package/dist/api/routes/store/returns/create-return.js.map +1 -1
  702. package/dist/api/routes/store/shipping-options/list-options.d.ts +24 -0
  703. package/dist/api/routes/store/shipping-options/list-options.js +24 -0
  704. package/dist/api/routes/store/shipping-options/list-options.js.map +1 -1
  705. package/dist/api/routes/store/shipping-options/list-shipping-options.d.ts +24 -0
  706. package/dist/api/routes/store/shipping-options/list-shipping-options.js +24 -0
  707. package/dist/api/routes/store/shipping-options/list-shipping-options.js.map +1 -1
  708. package/dist/api/routes/store/swaps/create-swap.d.ts +54 -0
  709. package/dist/api/routes/store/swaps/create-swap.js +54 -0
  710. package/dist/api/routes/store/swaps/create-swap.js.map +1 -1
  711. package/dist/api/routes/store/swaps/get-swap-by-cart.d.ts +24 -0
  712. package/dist/api/routes/store/swaps/get-swap-by-cart.js +24 -0
  713. package/dist/api/routes/store/swaps/get-swap-by-cart.js.map +1 -1
  714. package/dist/api/routes/store/swaps/index.d.ts +2 -1
  715. package/dist/api/routes/store/swaps/index.js.map +1 -1
  716. package/dist/api/routes/store/variants/get-variant.d.ts +15 -0
  717. package/dist/api/routes/store/variants/get-variant.js +15 -0
  718. package/dist/api/routes/store/variants/get-variant.js.map +1 -1
  719. package/dist/api/routes/store/variants/list-variants.d.ts +15 -0
  720. package/dist/api/routes/store/variants/list-variants.js +15 -0
  721. package/dist/api/routes/store/variants/list-variants.js.map +1 -1
  722. package/dist/loaders/strategies.js +9 -1
  723. package/dist/loaders/strategies.js.map +1 -1
  724. package/dist/migrations/1661863940645-swap_fulfillment_status_requires_action.d.ts +6 -0
  725. package/dist/migrations/1661863940645-swap_fulfillment_status_requires_action.js +89 -0
  726. package/dist/migrations/1661863940645-swap_fulfillment_status_requires_action.js.map +1 -0
  727. package/dist/models/swap.d.ts +2 -1
  728. package/dist/models/swap.js +2 -1
  729. package/dist/models/swap.js.map +1 -1
  730. package/dist/repositories/sales-channel.d.ts +3 -1
  731. package/dist/repositories/sales-channel.js +123 -0
  732. package/dist/repositories/sales-channel.js.map +1 -1
  733. package/dist/services/batch-job.js.map +1 -1
  734. package/dist/services/cart.d.ts +0 -7
  735. package/dist/services/cart.js +10 -58
  736. package/dist/services/cart.js.map +1 -1
  737. package/dist/services/csv-parser.d.ts +1 -3
  738. package/dist/services/csv-parser.js +4 -4
  739. package/dist/services/csv-parser.js.map +1 -1
  740. package/dist/services/event-bus.d.ts +4 -4
  741. package/dist/services/line-item.d.ts +8 -0
  742. package/dist/services/line-item.js +9 -0
  743. package/dist/services/line-item.js.map +1 -1
  744. package/dist/services/product-variant.d.ts +2 -2
  745. package/dist/services/product-variant.js +43 -35
  746. package/dist/services/product-variant.js.map +1 -1
  747. package/dist/services/product.d.ts +9 -1
  748. package/dist/services/product.js +36 -15
  749. package/dist/services/product.js.map +1 -1
  750. package/dist/services/region.d.ts +7 -0
  751. package/dist/services/region.js +22 -0
  752. package/dist/services/region.js.map +1 -1
  753. package/dist/services/sales-channel.d.ts +19 -1
  754. package/dist/services/sales-channel.js +64 -14
  755. package/dist/services/sales-channel.js.map +1 -1
  756. package/dist/services/swap.d.ts +152 -168
  757. package/dist/services/swap.js +898 -878
  758. package/dist/services/swap.js.map +1 -1
  759. package/dist/services/tax-provider.d.ts +1 -1
  760. package/dist/services/user.d.ts +1 -7
  761. package/dist/services/user.js +3 -15
  762. package/dist/services/user.js.map +1 -1
  763. package/dist/strategies/batch-jobs/product/import.d.ts +140 -0
  764. package/dist/strategies/batch-jobs/product/import.js +1162 -0
  765. package/dist/strategies/batch-jobs/product/import.js.map +1 -0
  766. package/dist/strategies/batch-jobs/product/types.d.ts +47 -0
  767. package/dist/strategies/batch-jobs/product/types.js +14 -0
  768. package/dist/strategies/batch-jobs/product/types.js.map +1 -0
  769. package/dist/strategies/batch-jobs/product/utils.d.ts +15 -0
  770. package/dist/strategies/batch-jobs/product/utils.js +44 -0
  771. package/dist/strategies/batch-jobs/product/utils.js.map +1 -0
  772. package/dist/subscribers/batch-job.js +28 -8
  773. package/dist/subscribers/batch-job.js.map +1 -1
  774. package/dist/types/fulfillment.d.ts +4 -2
  775. package/dist/utils/is-email.d.ts +6 -0
  776. package/dist/utils/is-email.js +19 -0
  777. package/dist/utils/is-email.js.map +1 -0
  778. package/package.json +3 -5
@@ -108,79 +108,51 @@ var __values = (this && this.__values) || function(o) {
108
108
  };
109
109
  throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
110
110
  };
111
+ var __importDefault = (this && this.__importDefault) || function (mod) {
112
+ return (mod && mod.__esModule) ? mod : { "default": mod };
113
+ };
111
114
  Object.defineProperty(exports, "__esModule", { value: true });
112
115
  var medusa_core_utils_1 = require("medusa-core-utils");
113
- var medusa_interfaces_1 = require("medusa-interfaces");
114
116
  var utils_1 = require("../utils");
117
+ var interfaces_1 = require("../interfaces");
118
+ var cart_1 = __importDefault(require("./cart"));
119
+ var models_1 = require("../models");
115
120
  /**
116
121
  * Handles swaps
117
- * @extends BaseService
118
122
  */
119
123
  var SwapService = /** @class */ (function (_super) {
120
124
  __extends(SwapService, _super);
121
125
  function SwapService(_a) {
122
- var manager = _a.manager, swapRepository = _a.swapRepository, eventBusService = _a.eventBusService, cartService = _a.cartService, totalsService = _a.totalsService, returnService = _a.returnService, lineItemService = _a.lineItemService, paymentProviderService = _a.paymentProviderService, shippingMethodTaxLineRepository = _a.shippingMethodTaxLineRepository, shippingOptionService = _a.shippingOptionService, fulfillmentService = _a.fulfillmentService, orderService = _a.orderService, inventoryService = _a.inventoryService, customShippingOptionService = _a.customShippingOptionService, lineItemAdjustmentService = _a.lineItemAdjustmentService;
123
- var _this = _super.call(this) || this;
124
- /** @private @const {EntityManager} */
126
+ var manager = _a.manager, swapRepository = _a.swapRepository, eventBusService = _a.eventBusService, cartService = _a.cartService, totalsService = _a.totalsService, returnService = _a.returnService, lineItemService = _a.lineItemService, paymentProviderService = _a.paymentProviderService, shippingOptionService = _a.shippingOptionService, fulfillmentService = _a.fulfillmentService, orderService = _a.orderService, inventoryService = _a.inventoryService, customShippingOptionService = _a.customShippingOptionService, lineItemAdjustmentService = _a.lineItemAdjustmentService;
127
+ var _this =
128
+ // eslint-disable-next-line prefer-rest-params
129
+ _super.call(this, arguments[0]) || this;
125
130
  _this.manager_ = manager;
126
- /** @private @const {SwapModel} */
127
131
  _this.swapRepository_ = swapRepository;
128
- /** @private @const {TotalsService} */
129
132
  _this.totalsService_ = totalsService;
130
- /** @private @const {LineItemService} */
131
133
  _this.lineItemService_ = lineItemService;
132
- /** @private @const {ReturnService} */
133
134
  _this.returnService_ = returnService;
134
- /** @private @const {PaymentProviderService} */
135
135
  _this.paymentProviderService_ = paymentProviderService;
136
- /** @private @const {CartService} */
137
136
  _this.cartService_ = cartService;
138
- /** @private @const {FulfillmentService} */
139
137
  _this.fulfillmentService_ = fulfillmentService;
140
- /** @private @const {OrderService} */
141
138
  _this.orderService_ = orderService;
142
- /** @private @const {ShippingOptionService} */
143
139
  _this.shippingOptionService_ = shippingOptionService;
144
- /** @private @const {InventoryService} */
145
140
  _this.inventoryService_ = inventoryService;
146
- /** @private @const {EventBusService} */
147
141
  _this.eventBus_ = eventBusService;
148
- /** @private @const {typeof ShippingMethodTaxLineRepository} */
149
- _this.shippingTaxLineRepo_ = shippingMethodTaxLineRepository;
150
- /** @private @const {CustomShippingOptionService} */
151
142
  _this.customShippingOptionService_ = customShippingOptionService;
152
- /** @private @const {LineItemAdjustmentService} */
153
143
  _this.lineItemAdjustmentService_ = lineItemAdjustmentService;
154
144
  return _this;
155
145
  }
156
- SwapService.prototype.withTransaction = function (transactionManager) {
157
- if (!transactionManager) {
158
- return this;
159
- }
160
- var cloned = new SwapService({
161
- manager: transactionManager,
162
- swapRepository: this.swapRepository_,
163
- eventBusService: this.eventBus_,
164
- cartService: this.cartService_,
165
- totalsService: this.totalsService_,
166
- returnService: this.returnService_,
167
- lineItemService: this.lineItemService_,
168
- shippingMethodTaxLineRepository: this.shippingTaxLineRepo_,
169
- paymentProviderService: this.paymentProviderService_,
170
- shippingOptionService: this.shippingOptionService_,
171
- orderService: this.orderService_,
172
- inventoryService: this.inventoryService_,
173
- fulfillmentService: this.fulfillmentService_,
174
- customShippingOptionService: this.customShippingOptionService_,
175
- lineItemAdjustmentService: this.lineItemAdjustmentService_,
176
- });
177
- cloned.transactionManager_ = transactionManager;
178
- return cloned;
179
- };
180
- SwapService.prototype.transformQueryForCart_ = function (config) {
146
+ /**
147
+ * Transform find config object for retrieval.
148
+ *
149
+ * @param config parsed swap find config
150
+ * @return transformed find swap config
151
+ */
152
+ SwapService.prototype.transformQueryForCart = function (config) {
181
153
  var select = config.select, relations = config.relations;
182
- var cartSelects = null;
183
- var cartRelations = null;
154
+ var cartSelects;
155
+ var cartRelations;
184
156
  if ((0, utils_1.isDefined)(relations) && relations.includes("cart")) {
185
157
  var _a = __read(relations.reduce(function (acc, next) {
186
158
  if (next === "cart") {
@@ -220,30 +192,31 @@ var SwapService = /** @class */ (function (_super) {
220
192
  };
221
193
  /**
222
194
  * Retrieves a swap with the given id.
223
- * @param {string} id - the id of the swap to retrieve
224
- * @param {Object} config - the configuration to retrieve the swap
225
- * @return {Promise<Swap>} the swap
195
+ *
196
+ * @param id - the id of the swap to retrieve
197
+ * @param config - the configuration to retrieve the swap
198
+ * @return the swap
226
199
  */
227
200
  SwapService.prototype.retrieve = function (id, config) {
228
201
  if (config === void 0) { config = {}; }
229
202
  return __awaiter(this, void 0, void 0, function () {
230
- var swapRepo, validatedId, _a, cartSelects, cartRelations, newConfig, query, rels, swap, cart;
231
- return __generator(this, function (_b) {
232
- switch (_b.label) {
203
+ var swapRepo, _a, cartSelects, cartRelations, newConfig, query, relations, swap, _b;
204
+ return __generator(this, function (_c) {
205
+ switch (_c.label) {
233
206
  case 0:
234
207
  swapRepo = this.manager_.getCustomRepository(this.swapRepository_);
235
- validatedId = this.validateId_(id);
236
- _a = this.transformQueryForCart_(config), cartSelects = _a.cartSelects, cartRelations = _a.cartRelations, newConfig = __rest(_a, ["cartSelects", "cartRelations"]);
237
- query = this.buildQuery_({ id: validatedId }, newConfig);
238
- rels = query.relations;
208
+ _a = this.transformQueryForCart(config), cartSelects = _a.cartSelects, cartRelations = _a.cartRelations, newConfig = __rest(_a, ["cartSelects", "cartRelations"]);
209
+ query = (0, utils_1.buildQuery)({ id: id }, newConfig);
210
+ relations = query.relations;
239
211
  delete query.relations;
240
- return [4 /*yield*/, swapRepo.findOneWithRelations(rels, query)];
212
+ return [4 /*yield*/, swapRepo.findOneWithRelations(relations, query)];
241
213
  case 1:
242
- swap = _b.sent();
214
+ swap = _c.sent();
243
215
  if (!swap) {
244
216
  throw new medusa_core_utils_1.MedusaError(medusa_core_utils_1.MedusaError.Types.NOT_FOUND, "Swap was not found");
245
217
  }
246
218
  if (!(cartRelations || cartSelects)) return [3 /*break*/, 3];
219
+ _b = swap;
247
220
  return [4 /*yield*/, this.cartService_
248
221
  .withTransaction(this.manager_)
249
222
  .retrieve(swap.cart_id, {
@@ -251,9 +224,8 @@ var SwapService = /** @class */ (function (_super) {
251
224
  relations: cartRelations,
252
225
  })];
253
226
  case 2:
254
- cart = _b.sent();
255
- swap.cart = cart;
256
- _b.label = 3;
227
+ _b.cart = _c.sent();
228
+ _c.label = 3;
257
229
  case 3: return [2 /*return*/, swap];
258
230
  }
259
231
  });
@@ -261,9 +233,10 @@ var SwapService = /** @class */ (function (_super) {
261
233
  };
262
234
  /**
263
235
  * Retrieves a swap based on its associated cart id
264
- * @param {string} cartId - the cart id that the swap's cart has
265
- * @param {string[]} relations - the relations to retrieve swap
266
- * @return {Promise<Swap>} the swap
236
+ *
237
+ * @param cartId - the cart id that the swap's cart has
238
+ * @param relations - the relations to retrieve swap
239
+ * @return the swap
267
240
  */
268
241
  SwapService.prototype.retrieveByCartId = function (cartId, relations) {
269
242
  if (relations === void 0) { relations = []; }
@@ -290,497 +263,505 @@ var SwapService = /** @class */ (function (_super) {
290
263
  });
291
264
  };
292
265
  /**
293
- * @param {Object} selector - the query object for find
294
- * @param {Object} config - the configuration used to find the objects. contains relations, skip, and take.
295
- * @return {Promise} the result of the find operation
266
+ * List swaps.
267
+ *
268
+ * @param selector - the query object for find
269
+ * @param config - the configuration used to find the objects. contains relations, skip, and take.
270
+ * @return the result of the find operation
296
271
  */
297
272
  SwapService.prototype.list = function (selector, config) {
298
- if (config === void 0) { config = { skip: 0, take: 50, order: { created_at: "DESC" } }; }
299
- var swapRepo = this.manager_.getCustomRepository(this.swapRepository_);
300
- var query = this.buildQuery_(selector, config);
301
- var rels = query.relations;
302
- delete query.relations;
303
- return swapRepo.findWithRelations(rels, query);
304
- };
305
- /**
306
- * @typedef OrderLike
307
- * @property {Array<LineItem>} items - the items on the order
308
- */
309
- /**
310
- * @typedef ReturnItem
311
- * @property {string} item_id - the id of the item in the order to return from.
312
- * @property {number} quantity - the amount of the item to return.
313
- */
314
- /**
315
- * Goes through a list of return items to ensure that they exist on the
316
- * original order. If the item exists it is verified that the quantity to
317
- * return is not higher than the original quantity ordered.
318
- * @param {OrderLike} order - the order to return from
319
- * @param {Array<ReturnItem>} returnItems - the items to return
320
- * @return {Array<ReturnItems>} the validated returnItems
321
- */
322
- SwapService.prototype.validateReturnItems_ = function (order, returnItems) {
323
- return returnItems.map(function (_a) {
324
- var item_id = _a.item_id, quantity = _a.quantity;
325
- var item = order.items.find(function (i) { return i.id === item_id; });
326
- // The item must exist in the order
327
- if (!item) {
328
- throw new medusa_core_utils_1.MedusaError(medusa_core_utils_1.MedusaError.Types.INVALID_DATA, "Item does not exist on order");
329
- }
330
- // Item's cannot be returned multiple times
331
- if (item.quantity < item.returned_quantity + quantity) {
332
- throw new medusa_core_utils_1.MedusaError(medusa_core_utils_1.MedusaError.Types.INVALID_DATA, "Cannot return more items than have been ordered");
333
- }
334
- return { item_id: item_id, quantity: quantity };
273
+ if (config === void 0) { config = {
274
+ skip: 0,
275
+ take: 50,
276
+ order: { created_at: "DESC" },
277
+ }; }
278
+ return __awaiter(this, void 0, void 0, function () {
279
+ var swapRepo, query, relations;
280
+ return __generator(this, function (_a) {
281
+ switch (_a.label) {
282
+ case 0:
283
+ swapRepo = this.manager_.getCustomRepository(this.swapRepository_);
284
+ query = (0, utils_1.buildQuery)(selector, config);
285
+ relations = query.relations;
286
+ delete query.relations;
287
+ return [4 /*yield*/, swapRepo.findWithRelations(relations, query)];
288
+ case 1: return [2 /*return*/, _a.sent()];
289
+ }
290
+ });
335
291
  });
336
292
  };
337
- /**
338
- * @typedef PreliminaryLineItem
339
- * @property {string} variant_id - the id of the variant to create an item from
340
- * @property {number} quantity - the amount of the variant to add to the line item
341
- */
342
293
  /**
343
294
  * Creates a swap from an order, with given return items, additional items
344
295
  * and an optional return shipping method.
345
- * @param {Order} order - the order to base the swap off.
346
- * @param {Array<ReturnItem>} returnItems - the items to return in the swap.
347
- * @param {Array<PreliminaryLineItem> | undefined} additionalItems - the items to send to
348
- * the customer.
349
- * @param {ReturnShipping?} returnShipping - an optional shipping method for
350
- * returning the returnItems.
351
- * @param {Object} custom - contains relevant custom information. This object may
296
+ *
297
+ * @param order - the order to base the swap off
298
+ * @param returnItems - the items to return in the swap
299
+ * @param additionalItems - the items to send to the customer
300
+ * @param returnShipping - an optional shipping method for returning the returnItems
301
+ * @param custom - contains relevant custom information. This object may
352
302
  * include no_notification which will disable sending notification when creating
353
- * swap. If set, it overrules the attribute inherited from the order.
354
- * @return {Promise<Swap>} the newly created swap.
303
+ * swap. If set, it overrules the attribute inherited from the order
304
+ * @return the newly created swap
355
305
  */
356
306
  SwapService.prototype.create = function (order, returnItems, additionalItems, returnShipping, custom) {
357
- if (custom === void 0) { custom = {
358
- no_notification: undefined,
359
- }; }
307
+ if (custom === void 0) { custom = { no_notification: undefined }; }
360
308
  return __awaiter(this, void 0, void 0, function () {
361
309
  var no_notification, rest;
362
310
  var _this = this;
363
311
  return __generator(this, function (_a) {
364
- no_notification = custom.no_notification, rest = __rest(custom, ["no_notification"]);
365
- return [2 /*return*/, this.atomicPhase_(function (manager) { return __awaiter(_this, void 0, void 0, function () {
366
- var returnItems_1, returnItems_1_1, item, line, e_1_1, newItems, evaluatedNoNotification, swapRepo, created, result;
367
- var e_1, _a;
368
- var _this = this;
369
- var _b, _c, _d;
370
- return __generator(this, function (_e) {
371
- switch (_e.label) {
372
- case 0:
373
- if (order.fulfillment_status === "not_fulfilled" ||
374
- order.payment_status !== "captured") {
375
- throw new medusa_core_utils_1.MedusaError(medusa_core_utils_1.MedusaError.Types.NOT_ALLOWED, "Order cannot be swapped");
376
- }
377
- _e.label = 1;
378
- case 1:
379
- _e.trys.push([1, 6, 7, 8]);
380
- returnItems_1 = __values(returnItems), returnItems_1_1 = returnItems_1.next();
381
- _e.label = 2;
382
- case 2:
383
- if (!!returnItems_1_1.done) return [3 /*break*/, 5];
384
- item = returnItems_1_1.value;
385
- return [4 /*yield*/, this.lineItemService_.retrieve(item.item_id, {
386
- relations: ["order", "swap", "claim_order"],
387
- })];
388
- case 3:
389
- line = _e.sent();
390
- if (((_b = line.order) === null || _b === void 0 ? void 0 : _b.canceled_at) ||
391
- ((_c = line.swap) === null || _c === void 0 ? void 0 : _c.canceled_at) ||
392
- ((_d = line.claim_order) === null || _d === void 0 ? void 0 : _d.canceled_at)) {
393
- throw new medusa_core_utils_1.MedusaError(medusa_core_utils_1.MedusaError.Types.INVALID_DATA, "Cannot create a swap on a canceled item.");
394
- }
395
- _e.label = 4;
396
- case 4:
397
- returnItems_1_1 = returnItems_1.next();
398
- return [3 /*break*/, 2];
399
- case 5: return [3 /*break*/, 8];
400
- case 6:
401
- e_1_1 = _e.sent();
402
- e_1 = { error: e_1_1 };
403
- return [3 /*break*/, 8];
404
- case 7:
405
- try {
406
- if (returnItems_1_1 && !returnItems_1_1.done && (_a = returnItems_1.return)) _a.call(returnItems_1);
312
+ switch (_a.label) {
313
+ case 0:
314
+ no_notification = custom.no_notification, rest = __rest(custom, ["no_notification"]);
315
+ return [4 /*yield*/, this.atomicPhase_(function (manager) { return __awaiter(_this, void 0, void 0, function () {
316
+ var lineItemServiceTx, returnItems_1, returnItems_1_1, item, line, e_1_1, newItems, evaluatedNoNotification, swapRepo, created, result;
317
+ var e_1, _a;
318
+ var _this = this;
319
+ var _b, _c, _d;
320
+ return __generator(this, function (_e) {
321
+ switch (_e.label) {
322
+ case 0:
323
+ if (order.fulfillment_status === "not_fulfilled" ||
324
+ order.payment_status !== "captured") {
325
+ throw new medusa_core_utils_1.MedusaError(medusa_core_utils_1.MedusaError.Types.NOT_ALLOWED, "Order cannot be swapped");
326
+ }
327
+ lineItemServiceTx = this.lineItemService_.withTransaction(manager);
328
+ _e.label = 1;
329
+ case 1:
330
+ _e.trys.push([1, 6, 7, 8]);
331
+ returnItems_1 = __values(returnItems), returnItems_1_1 = returnItems_1.next();
332
+ _e.label = 2;
333
+ case 2:
334
+ if (!!returnItems_1_1.done) return [3 /*break*/, 5];
335
+ item = returnItems_1_1.value;
336
+ return [4 /*yield*/, lineItemServiceTx.retrieve(item.item_id, {
337
+ relations: ["order", "swap", "claim_order"],
338
+ })];
339
+ case 3:
340
+ line = _e.sent();
341
+ if (((_b = line.order) === null || _b === void 0 ? void 0 : _b.canceled_at) ||
342
+ ((_c = line.swap) === null || _c === void 0 ? void 0 : _c.canceled_at) ||
343
+ ((_d = line.claim_order) === null || _d === void 0 ? void 0 : _d.canceled_at)) {
344
+ throw new medusa_core_utils_1.MedusaError(medusa_core_utils_1.MedusaError.Types.INVALID_DATA, "Cannot create a swap on a canceled item.");
345
+ }
346
+ _e.label = 4;
347
+ case 4:
348
+ returnItems_1_1 = returnItems_1.next();
349
+ return [3 /*break*/, 2];
350
+ case 5: return [3 /*break*/, 8];
351
+ case 6:
352
+ e_1_1 = _e.sent();
353
+ e_1 = { error: e_1_1 };
354
+ return [3 /*break*/, 8];
355
+ case 7:
356
+ try {
357
+ if (returnItems_1_1 && !returnItems_1_1.done && (_a = returnItems_1.return)) _a.call(returnItems_1);
358
+ }
359
+ finally { if (e_1) throw e_1.error; }
360
+ return [7 /*endfinally*/];
361
+ case 8:
362
+ newItems = [];
363
+ if (!additionalItems) return [3 /*break*/, 10];
364
+ return [4 /*yield*/, Promise.all(additionalItems.map(function (_a) {
365
+ var variant_id = _a.variant_id, quantity = _a.quantity;
366
+ return _this.lineItemService_
367
+ .withTransaction(manager)
368
+ .generate(variant_id, order.region_id, quantity);
369
+ }))];
370
+ case 9:
371
+ newItems = _e.sent();
372
+ _e.label = 10;
373
+ case 10:
374
+ evaluatedNoNotification = no_notification !== undefined ? no_notification : order.no_notification;
375
+ swapRepo = manager.getCustomRepository(this.swapRepository_);
376
+ created = swapRepo.create(__assign(__assign({}, rest), { fulfillment_status: models_1.SwapFulfillmentStatus.NOT_FULFILLED, payment_status: models_1.SwapPaymentStatus.NOT_PAID, order_id: order.id, additional_items: newItems, no_notification: evaluatedNoNotification }));
377
+ return [4 /*yield*/, swapRepo.save(created)];
378
+ case 11:
379
+ result = _e.sent();
380
+ return [4 /*yield*/, this.returnService_.withTransaction(manager).create({
381
+ swap_id: result.id,
382
+ order_id: order.id,
383
+ items: returnItems,
384
+ shipping_method: returnShipping,
385
+ no_notification: evaluatedNoNotification,
386
+ })];
387
+ case 12:
388
+ _e.sent();
389
+ return [4 /*yield*/, this.eventBus_
390
+ .withTransaction(manager)
391
+ .emit(SwapService.Events.CREATED, {
392
+ id: result.id,
393
+ no_notification: evaluatedNoNotification,
394
+ })];
395
+ case 13:
396
+ _e.sent();
397
+ return [2 /*return*/, result];
407
398
  }
408
- finally { if (e_1) throw e_1.error; }
409
- return [7 /*endfinally*/];
410
- case 8: return [4 /*yield*/, Promise.all(additionalItems.map(function (_a) {
411
- var variant_id = _a.variant_id, quantity = _a.quantity;
412
- return _this.lineItemService_.generate(variant_id, order.region_id, quantity);
413
- }))];
414
- case 9:
415
- newItems = _e.sent();
416
- evaluatedNoNotification = no_notification !== undefined ? no_notification : order.no_notification;
417
- swapRepo = manager.getCustomRepository(this.swapRepository_);
418
- created = swapRepo.create(__assign(__assign({}, rest), { fulfillment_status: "not_fulfilled", payment_status: "not_paid", order_id: order.id, additional_items: newItems, no_notification: evaluatedNoNotification }));
419
- return [4 /*yield*/, swapRepo.save(created)];
420
- case 10:
421
- result = _e.sent();
422
- return [4 /*yield*/, this.returnService_.withTransaction(manager).create({
423
- swap_id: result.id,
424
- order_id: order.id,
425
- items: returnItems,
426
- shipping_method: returnShipping,
427
- no_notification: evaluatedNoNotification,
428
- })];
429
- case 11:
430
- _e.sent();
431
- return [4 /*yield*/, this.eventBus_
432
- .withTransaction(manager)
433
- .emit(SwapService.Events.CREATED, {
434
- id: result.id,
435
- no_notification: evaluatedNoNotification,
436
- })];
437
- case 12:
438
- _e.sent();
439
- return [2 /*return*/, result];
440
- }
441
- });
442
- }); })];
399
+ });
400
+ }); })];
401
+ case 1: return [2 /*return*/, _a.sent()];
402
+ }
443
403
  });
444
404
  });
445
405
  };
406
+ /**
407
+ * Process difference for the requested swap.
408
+ *
409
+ * @param swapId id of a swap being processed
410
+ * @return processed swap
411
+ */
446
412
  SwapService.prototype.processDifference = function (swapId) {
447
413
  return __awaiter(this, void 0, void 0, function () {
448
414
  var _this = this;
449
415
  return __generator(this, function (_a) {
450
- return [2 /*return*/, this.atomicPhase_(function (manager) { return __awaiter(_this, void 0, void 0, function () {
451
- var swap, swapRepo, err_1, result_1, result_2, result_3, err_2, result_4, result;
452
- return __generator(this, function (_a) {
453
- switch (_a.label) {
454
- case 0: return [4 /*yield*/, this.retrieve(swapId, {
455
- relations: ["payment", "order", "order.payments"],
456
- })];
457
- case 1:
458
- swap = _a.sent();
459
- if (swap.canceled_at) {
460
- throw new medusa_core_utils_1.MedusaError(medusa_core_utils_1.MedusaError.Types.NOT_ALLOWED, "Canceled swap cannot be processed");
461
- }
462
- if (!swap.confirmed_at) {
463
- throw new medusa_core_utils_1.MedusaError(medusa_core_utils_1.MedusaError.Types.NOT_ALLOWED, "Cannot process a swap that hasn't been confirmed by the customer");
464
- }
465
- swapRepo = manager.getCustomRepository(this.swapRepository_);
466
- if (!(swap.difference_due < 0)) return [3 /*break*/, 10];
467
- if (swap.payment_status === "difference_refunded") {
468
- return [2 /*return*/, swap];
469
- }
470
- _a.label = 2;
471
- case 2:
472
- _a.trys.push([2, 4, , 7]);
473
- return [4 /*yield*/, this.paymentProviderService_
474
- .withTransaction(manager)
475
- .refundPayment(swap.order.payments, -1 * swap.difference_due, "swap")];
476
- case 3:
477
- _a.sent();
478
- return [3 /*break*/, 7];
479
- case 4:
480
- err_1 = _a.sent();
481
- swap.payment_status = "requires_action";
482
- return [4 /*yield*/, swapRepo.save(swap)];
483
- case 5:
484
- result_1 = _a.sent();
485
- return [4 /*yield*/, this.eventBus_
486
- .withTransaction(manager)
487
- .emit(SwapService.Events.PROCESS_REFUND_FAILED, {
488
- id: result_1.id,
489
- no_notification: swap.no_notification,
490
- })];
491
- case 6:
492
- _a.sent();
493
- return [2 /*return*/, result_1];
494
- case 7:
495
- swap.payment_status = "difference_refunded";
496
- return [4 /*yield*/, swapRepo.save(swap)];
497
- case 8:
498
- result_2 = _a.sent();
499
- return [4 /*yield*/, this.eventBus_
500
- .withTransaction(manager)
501
- .emit(SwapService.Events.REFUND_PROCESSED, {
502
- id: result_2.id,
503
- no_notification: swap.no_notification,
504
- })];
505
- case 9:
506
- _a.sent();
507
- return [2 /*return*/, result_2];
508
- case 10:
509
- if (!(swap.difference_due === 0)) return [3 /*break*/, 13];
510
- if (swap.payment_status === "difference_refunded") {
511
- return [2 /*return*/, swap];
512
- }
513
- swap.payment_status = "difference_refunded";
514
- return [4 /*yield*/, swapRepo.save(swap)];
515
- case 11:
516
- result_3 = _a.sent();
517
- return [4 /*yield*/, this.eventBus_
518
- .withTransaction(manager)
519
- .emit(SwapService.Events.REFUND_PROCESSED, {
520
- id: result_3.id,
521
- no_notification: swap.no_notification,
522
- })];
523
- case 12:
524
- _a.sent();
525
- return [2 /*return*/, result_3];
526
- case 13:
527
- _a.trys.push([13, 15, , 18]);
528
- if (swap.payment_status === "captured") {
529
- return [2 /*return*/, swap];
530
- }
531
- return [4 /*yield*/, this.paymentProviderService_
532
- .withTransaction(manager)
533
- .capturePayment(swap.payment)];
534
- case 14:
535
- _a.sent();
536
- return [3 /*break*/, 18];
537
- case 15:
538
- err_2 = _a.sent();
539
- swap.payment_status = "requires_action";
540
- return [4 /*yield*/, swapRepo.save(swap)];
541
- case 16:
542
- result_4 = _a.sent();
543
- return [4 /*yield*/, this.eventBus_
544
- .withTransaction(manager)
545
- .emit(SwapService.Events.PAYMENT_CAPTURE_FAILED, {
546
- id: swap.id,
547
- no_notification: swap.no_notification,
548
- })];
549
- case 17:
550
- _a.sent();
551
- return [2 /*return*/, result_4];
552
- case 18:
553
- swap.payment_status = "captured";
554
- return [4 /*yield*/, swapRepo.save(swap)];
555
- case 19:
556
- result = _a.sent();
557
- return [4 /*yield*/, this.eventBus_
558
- .withTransaction(manager)
559
- .emit(SwapService.Events.PAYMENT_CAPTURED, {
560
- id: result.id,
561
- no_notification: swap.no_notification,
416
+ switch (_a.label) {
417
+ case 0: return [4 /*yield*/, this.atomicPhase_(function (manager) { return __awaiter(_this, void 0, void 0, function () {
418
+ var swap, swapRepo, err_1, result_1, result_2, result_3, err_2, result_4, result;
419
+ return __generator(this, function (_a) {
420
+ switch (_a.label) {
421
+ case 0: return [4 /*yield*/, this.retrieve(swapId, {
422
+ relations: ["payment", "order", "order.payments"],
562
423
  })];
563
- case 20:
564
- _a.sent();
565
- return [2 /*return*/, result];
566
- }
567
- });
568
- }); })];
424
+ case 1:
425
+ swap = _a.sent();
426
+ if (swap.canceled_at) {
427
+ throw new medusa_core_utils_1.MedusaError(medusa_core_utils_1.MedusaError.Types.NOT_ALLOWED, "Canceled swap cannot be processed");
428
+ }
429
+ if (!swap.confirmed_at) {
430
+ throw new medusa_core_utils_1.MedusaError(medusa_core_utils_1.MedusaError.Types.NOT_ALLOWED, "Cannot process a swap that hasn't been confirmed by the customer");
431
+ }
432
+ swapRepo = manager.getCustomRepository(this.swapRepository_);
433
+ if (!(swap.difference_due < 0)) return [3 /*break*/, 10];
434
+ if (swap.payment_status === "difference_refunded") {
435
+ return [2 /*return*/, swap];
436
+ }
437
+ _a.label = 2;
438
+ case 2:
439
+ _a.trys.push([2, 4, , 7]);
440
+ return [4 /*yield*/, this.paymentProviderService_
441
+ .withTransaction(manager)
442
+ .refundPayment(swap.order.payments, -1 * swap.difference_due, "swap")];
443
+ case 3:
444
+ _a.sent();
445
+ return [3 /*break*/, 7];
446
+ case 4:
447
+ err_1 = _a.sent();
448
+ swap.payment_status = models_1.SwapPaymentStatus.REQUIRES_ACTION;
449
+ return [4 /*yield*/, swapRepo.save(swap)];
450
+ case 5:
451
+ result_1 = _a.sent();
452
+ return [4 /*yield*/, this.eventBus_
453
+ .withTransaction(manager)
454
+ .emit(SwapService.Events.PROCESS_REFUND_FAILED, {
455
+ id: result_1.id,
456
+ no_notification: swap.no_notification,
457
+ })];
458
+ case 6:
459
+ _a.sent();
460
+ return [2 /*return*/, result_1];
461
+ case 7:
462
+ swap.payment_status = models_1.SwapPaymentStatus.DIFFERENCE_REFUNDED;
463
+ return [4 /*yield*/, swapRepo.save(swap)];
464
+ case 8:
465
+ result_2 = _a.sent();
466
+ return [4 /*yield*/, this.eventBus_
467
+ .withTransaction(manager)
468
+ .emit(SwapService.Events.REFUND_PROCESSED, {
469
+ id: result_2.id,
470
+ no_notification: swap.no_notification,
471
+ })];
472
+ case 9:
473
+ _a.sent();
474
+ return [2 /*return*/, result_2];
475
+ case 10:
476
+ if (!(swap.difference_due === 0)) return [3 /*break*/, 13];
477
+ if (swap.payment_status === models_1.SwapPaymentStatus.DIFFERENCE_REFUNDED) {
478
+ return [2 /*return*/, swap];
479
+ }
480
+ swap.payment_status = models_1.SwapPaymentStatus.DIFFERENCE_REFUNDED;
481
+ return [4 /*yield*/, swapRepo.save(swap)];
482
+ case 11:
483
+ result_3 = _a.sent();
484
+ return [4 /*yield*/, this.eventBus_
485
+ .withTransaction(manager)
486
+ .emit(SwapService.Events.REFUND_PROCESSED, {
487
+ id: result_3.id,
488
+ no_notification: swap.no_notification,
489
+ })];
490
+ case 12:
491
+ _a.sent();
492
+ return [2 /*return*/, result_3];
493
+ case 13:
494
+ _a.trys.push([13, 15, , 18]);
495
+ if (swap.payment_status === models_1.SwapPaymentStatus.CAPTURED) {
496
+ return [2 /*return*/, swap];
497
+ }
498
+ return [4 /*yield*/, this.paymentProviderService_
499
+ .withTransaction(manager)
500
+ .capturePayment(swap.payment)];
501
+ case 14:
502
+ _a.sent();
503
+ return [3 /*break*/, 18];
504
+ case 15:
505
+ err_2 = _a.sent();
506
+ swap.payment_status = models_1.SwapPaymentStatus.REQUIRES_ACTION;
507
+ return [4 /*yield*/, swapRepo.save(swap)];
508
+ case 16:
509
+ result_4 = _a.sent();
510
+ return [4 /*yield*/, this.eventBus_
511
+ .withTransaction(manager)
512
+ .emit(SwapService.Events.PAYMENT_CAPTURE_FAILED, {
513
+ id: swap.id,
514
+ no_notification: swap.no_notification,
515
+ })];
516
+ case 17:
517
+ _a.sent();
518
+ return [2 /*return*/, result_4];
519
+ case 18:
520
+ swap.payment_status = models_1.SwapPaymentStatus.CAPTURED;
521
+ return [4 /*yield*/, swapRepo.save(swap)];
522
+ case 19:
523
+ result = _a.sent();
524
+ return [4 /*yield*/, this.eventBus_
525
+ .withTransaction(manager)
526
+ .emit(SwapService.Events.PAYMENT_CAPTURED, {
527
+ id: result.id,
528
+ no_notification: swap.no_notification,
529
+ })];
530
+ case 20:
531
+ _a.sent();
532
+ return [2 /*return*/, result];
533
+ }
534
+ });
535
+ }); })];
536
+ case 1: return [2 /*return*/, _a.sent()];
537
+ }
569
538
  });
570
539
  });
571
540
  };
541
+ /**
542
+ * Update the swap record.
543
+ *
544
+ * @param swapId id of a swap to update
545
+ * @param update new data
546
+ * @return updated swap record
547
+ */
572
548
  SwapService.prototype.update = function (swapId, update) {
573
549
  return __awaiter(this, void 0, void 0, function () {
574
550
  var _this = this;
575
551
  return __generator(this, function (_a) {
576
- return [2 /*return*/, this.atomicPhase_(function (manager) { return __awaiter(_this, void 0, void 0, function () {
577
- var swap, swapRepo, result;
578
- return __generator(this, function (_a) {
579
- switch (_a.label) {
580
- case 0: return [4 /*yield*/, this.retrieve(swapId)];
581
- case 1:
582
- swap = _a.sent();
583
- if ("metadata" in update) {
584
- swap.metadata = this.setMetadata_(swap, update.metadata);
585
- }
586
- if ("no_notification" in update) {
587
- swap.no_notification = update.no_notification;
588
- }
589
- if (!("shipping_address" in update)) return [3 /*break*/, 3];
590
- return [4 /*yield*/, this.updateShippingAddress_(swap, update.shipping_address)];
591
- case 2:
592
- _a.sent();
593
- _a.label = 3;
594
- case 3:
595
- swapRepo = manager.getCustomRepository(this.swapRepository_);
596
- return [4 /*yield*/, swapRepo.save(swap)];
597
- case 4:
598
- result = _a.sent();
599
- return [2 /*return*/, result];
600
- }
601
- });
602
- }); })];
552
+ switch (_a.label) {
553
+ case 0: return [4 /*yield*/, this.atomicPhase_(function (manager) { return __awaiter(_this, void 0, void 0, function () {
554
+ var swap, swapRepo;
555
+ return __generator(this, function (_a) {
556
+ switch (_a.label) {
557
+ case 0: return [4 /*yield*/, this.retrieve(swapId)];
558
+ case 1:
559
+ swap = _a.sent();
560
+ if ("metadata" in update) {
561
+ swap.metadata = (0, utils_1.setMetadata)(swap, update.metadata);
562
+ }
563
+ if ("no_notification" in update) {
564
+ swap.no_notification = update.no_notification;
565
+ }
566
+ if ("shipping_address" in update) {
567
+ // TODO: Check this - calling method that doesn't exist
568
+ // also it seems that update swap isn't call anywhere
569
+ // await this.updateShippingAddress_(swap, update.shipping_address)
570
+ }
571
+ swapRepo = manager.getCustomRepository(this.swapRepository_);
572
+ return [4 /*yield*/, swapRepo.save(swap)];
573
+ case 2: return [2 /*return*/, _a.sent()];
574
+ }
575
+ });
576
+ }); })];
577
+ case 1: return [2 /*return*/, _a.sent()];
578
+ }
603
579
  });
604
580
  });
605
581
  };
606
582
  /**
607
- * Creates a cart from the given swap and order. The cart can be used to pay
583
+ * Creates a cart from the given swap. The cart can be used to pay
608
584
  * for differences associated with the swap. The swap represented by the
609
585
  * swapId must belong to the order. Fails if there is already a cart on the
610
586
  * swap.
611
- * @param {string} swapId - the id of the swap to create the cart from
612
- * @param {object[]} customShippingOptions - the shipping options
613
- * @param {Order} order - the order to create the cart from
614
- * @return {Promise<Swap>} the swap with its cart_id prop set to the id of
615
- * the new cart.
587
+ *
588
+ * @param swapId - the id of the swap to create the cart from
589
+ * @param customShippingOptions - the shipping options
590
+ * @return the swap with its cart_id prop set to the id of the new cart.
616
591
  */
617
592
  SwapService.prototype.createCart = function (swapId, customShippingOptions) {
618
593
  if (customShippingOptions === void 0) { customShippingOptions = []; }
619
594
  return __awaiter(this, void 0, void 0, function () {
620
595
  var _this = this;
621
596
  return __generator(this, function (_a) {
622
- return [2 /*return*/, this.atomicPhase_(function (manager) { return __awaiter(_this, void 0, void 0, function () {
623
- var swap, order, discounts, cart, customShippingOptionServiceTx, customShippingOptions_1, customShippingOptions_1_1, customShippingOption, e_2_1, lineItemServiceTx, lineItemAdjustmentServiceTx, _a, _b, item, e_3_1, shippingTaxLineRepo_1, swapRepo;
624
- var e_2, _c, e_3, _d;
625
- var _e;
626
- return __generator(this, function (_f) {
627
- switch (_f.label) {
628
- case 0: return [4 /*yield*/, this.retrieve(swapId, {
629
- relations: [
630
- "order",
631
- "order.items",
632
- "order.swaps",
633
- "order.swaps.additional_items",
634
- "order.discounts",
635
- "order.discounts.rule",
636
- "order.claims",
637
- "order.claims.additional_items",
638
- "additional_items",
639
- "additional_items.variant",
640
- "return_order",
641
- "return_order.items",
642
- "return_order.shipping_method",
643
- "return_order.shipping_method.tax_lines",
644
- ],
645
- })];
646
- case 1:
647
- swap = _f.sent();
648
- if (swap.canceled_at) {
649
- throw new medusa_core_utils_1.MedusaError(medusa_core_utils_1.MedusaError.Types.NOT_ALLOWED, "Canceled swap cannot be used to create a cart");
650
- }
651
- if (swap.cart_id) {
652
- throw new medusa_core_utils_1.MedusaError(medusa_core_utils_1.MedusaError.Types.DUPLICATE_ERROR, "A cart has already been created for the swap");
653
- }
654
- order = swap.order;
655
- discounts = ((_e = order === null || order === void 0 ? void 0 : order.discounts) === null || _e === void 0 ? void 0 : _e.filter(function (_a) {
656
- var rule = _a.rule;
657
- return rule.type !== "free_shipping";
658
- })) ||
659
- undefined;
660
- return [4 /*yield*/, this.cartService_.withTransaction(manager).create({
661
- discounts: discounts,
662
- email: order.email,
663
- billing_address_id: order.billing_address_id,
664
- shipping_address_id: order.shipping_address_id,
665
- region_id: order.region_id,
666
- customer_id: order.customer_id,
667
- type: "swap",
668
- metadata: {
669
- swap_id: swap.id,
670
- parent_order_id: order.id,
671
- },
672
- })];
673
- case 2:
674
- cart = _f.sent();
675
- customShippingOptionServiceTx = this.customShippingOptionService_.withTransaction(manager);
676
- _f.label = 3;
677
- case 3:
678
- _f.trys.push([3, 8, 9, 10]);
679
- customShippingOptions_1 = __values(customShippingOptions), customShippingOptions_1_1 = customShippingOptions_1.next();
680
- _f.label = 4;
681
- case 4:
682
- if (!!customShippingOptions_1_1.done) return [3 /*break*/, 7];
683
- customShippingOption = customShippingOptions_1_1.value;
684
- return [4 /*yield*/, customShippingOptionServiceTx.create({
685
- cart_id: cart.id,
686
- shipping_option_id: customShippingOption.option_id,
687
- price: customShippingOption.price,
688
- })];
689
- case 5:
690
- _f.sent();
691
- _f.label = 6;
692
- case 6:
693
- customShippingOptions_1_1 = customShippingOptions_1.next();
694
- return [3 /*break*/, 4];
695
- case 7: return [3 /*break*/, 10];
696
- case 8:
697
- e_2_1 = _f.sent();
698
- e_2 = { error: e_2_1 };
699
- return [3 /*break*/, 10];
700
- case 9:
701
- try {
702
- if (customShippingOptions_1_1 && !customShippingOptions_1_1.done && (_c = customShippingOptions_1.return)) _c.call(customShippingOptions_1);
703
- }
704
- finally { if (e_2) throw e_2.error; }
705
- return [7 /*endfinally*/];
706
- case 10:
707
- lineItemServiceTx = this.lineItemService_.withTransaction(manager);
708
- lineItemAdjustmentServiceTx = this.lineItemAdjustmentService_.withTransaction(manager);
709
- _f.label = 11;
710
- case 11:
711
- _f.trys.push([11, 17, 18, 19]);
712
- _a = __values(swap.additional_items), _b = _a.next();
713
- _f.label = 12;
714
- case 12:
715
- if (!!_b.done) return [3 /*break*/, 16];
716
- item = _b.value;
717
- return [4 /*yield*/, lineItemServiceTx.update(item.id, {
718
- cart_id: cart.id,
719
- })
597
+ switch (_a.label) {
598
+ case 0: return [4 /*yield*/, this.atomicPhase_(function (manager) { return __awaiter(_this, void 0, void 0, function () {
599
+ var swapRepo, swap, order, discounts, cart, customShippingOptionServiceTx, customShippingOptions_1, customShippingOptions_1_1, customShippingOption, e_2_1, lineItemServiceTx, lineItemAdjustmentServiceTx, _a, _b, item, e_3_1;
600
+ var e_2, _c, e_3, _d;
601
+ var _e;
602
+ return __generator(this, function (_f) {
603
+ switch (_f.label) {
604
+ case 0:
605
+ swapRepo = manager.getCustomRepository(this.swapRepository_);
606
+ return [4 /*yield*/, this.retrieve(swapId, {
607
+ relations: [
608
+ "order",
609
+ "order.items",
610
+ "order.swaps",
611
+ "order.swaps.additional_items",
612
+ "order.discounts",
613
+ "order.discounts.rule",
614
+ "order.claims",
615
+ "order.claims.additional_items",
616
+ "additional_items",
617
+ "additional_items.variant",
618
+ "return_order",
619
+ "return_order.items",
620
+ "return_order.shipping_method",
621
+ "return_order.shipping_method.tax_lines",
622
+ ],
623
+ })];
624
+ case 1:
625
+ swap = _f.sent();
626
+ if (swap.canceled_at) {
627
+ throw new medusa_core_utils_1.MedusaError(medusa_core_utils_1.MedusaError.Types.NOT_ALLOWED, "Canceled swap cannot be used to create a cart");
628
+ }
629
+ if (swap.cart_id) {
630
+ throw new medusa_core_utils_1.MedusaError(medusa_core_utils_1.MedusaError.Types.DUPLICATE_ERROR, "A cart has already been created for the swap");
631
+ }
632
+ order = swap.order;
633
+ discounts = ((_e = order === null || order === void 0 ? void 0 : order.discounts) === null || _e === void 0 ? void 0 : _e.filter(function (_a) {
634
+ var rule = _a.rule;
635
+ return rule.type !== "free_shipping";
636
+ })) ||
637
+ undefined;
638
+ return [4 /*yield*/, this.cartService_.withTransaction(manager).create({
639
+ discounts: discounts,
640
+ email: order.email,
641
+ billing_address_id: order.billing_address_id,
642
+ shipping_address_id: order.shipping_address_id,
643
+ region_id: order.region_id,
644
+ customer_id: order.customer_id,
645
+ type: models_1.CartType.SWAP,
646
+ metadata: {
647
+ swap_id: swap.id,
648
+ parent_order_id: order.id,
649
+ },
650
+ })];
651
+ case 2:
652
+ cart = _f.sent();
653
+ customShippingOptionServiceTx = this.customShippingOptionService_.withTransaction(manager);
654
+ _f.label = 3;
655
+ case 3:
656
+ _f.trys.push([3, 8, 9, 10]);
657
+ customShippingOptions_1 = __values(customShippingOptions), customShippingOptions_1_1 = customShippingOptions_1.next();
658
+ _f.label = 4;
659
+ case 4:
660
+ if (!!customShippingOptions_1_1.done) return [3 /*break*/, 7];
661
+ customShippingOption = customShippingOptions_1_1.value;
662
+ return [4 /*yield*/, customShippingOptionServiceTx.create({
663
+ cart_id: cart.id,
664
+ shipping_option_id: customShippingOption.option_id,
665
+ price: customShippingOption.price,
666
+ })];
667
+ case 5:
668
+ _f.sent();
669
+ _f.label = 6;
670
+ case 6:
671
+ customShippingOptions_1_1 = customShippingOptions_1.next();
672
+ return [3 /*break*/, 4];
673
+ case 7: return [3 /*break*/, 10];
674
+ case 8:
675
+ e_2_1 = _f.sent();
676
+ e_2 = { error: e_2_1 };
677
+ return [3 /*break*/, 10];
678
+ case 9:
679
+ try {
680
+ if (customShippingOptions_1_1 && !customShippingOptions_1_1.done && (_c = customShippingOptions_1.return)) _c.call(customShippingOptions_1);
681
+ }
682
+ finally { if (e_2) throw e_2.error; }
683
+ return [7 /*endfinally*/];
684
+ case 10:
685
+ lineItemServiceTx = this.lineItemService_.withTransaction(manager);
686
+ lineItemAdjustmentServiceTx = this.lineItemAdjustmentService_.withTransaction(manager);
687
+ _f.label = 11;
688
+ case 11:
689
+ _f.trys.push([11, 17, 18, 19]);
690
+ _a = __values(swap.additional_items), _b = _a.next();
691
+ _f.label = 12;
692
+ case 12:
693
+ if (!!_b.done) return [3 /*break*/, 16];
694
+ item = _b.value;
695
+ return [4 /*yield*/, lineItemServiceTx.update(item.id, {
696
+ cart_id: cart.id,
697
+ })
698
+ // we generate adjustments in case the cart has any discounts that should be applied to the additional items
699
+ ];
700
+ case 13:
701
+ _f.sent();
720
702
  // we generate adjustments in case the cart has any discounts that should be applied to the additional items
721
- ];
722
- case 13:
723
- _f.sent();
724
- // we generate adjustments in case the cart has any discounts that should be applied to the additional items
725
- return [4 /*yield*/, lineItemAdjustmentServiceTx.createAdjustmentForLineItem(cart, item)];
726
- case 14:
727
- // we generate adjustments in case the cart has any discounts that should be applied to the additional items
728
- _f.sent();
729
- _f.label = 15;
730
- case 15:
731
- _b = _a.next();
732
- return [3 /*break*/, 12];
733
- case 16: return [3 /*break*/, 19];
734
- case 17:
735
- e_3_1 = _f.sent();
736
- e_3 = { error: e_3_1 };
737
- return [3 /*break*/, 19];
738
- case 18:
739
- try {
740
- if (_b && !_b.done && (_d = _a.return)) _d.call(_a);
741
- }
742
- finally { if (e_3) throw e_3.error; }
743
- return [7 /*endfinally*/];
744
- case 19:
745
- if (!(swap.return_order && swap.return_order.shipping_method)) return [3 /*break*/, 21];
746
- shippingTaxLineRepo_1 = this.manager_.getCustomRepository(this.shippingTaxLineRepo_);
747
- return [4 /*yield*/, this.lineItemService_.withTransaction(manager).create({
748
- cart_id: cart.id,
749
- title: "Return shipping",
750
- quantity: 1,
751
- has_shipping: true,
752
- allow_discounts: false,
753
- unit_price: swap.return_order.shipping_method.price,
754
- is_return: true,
755
- tax_lines: swap.return_order.shipping_method.tax_lines.map(function (tl) {
756
- return shippingTaxLineRepo_1.create({
757
- name: tl.name,
758
- code: tl.code,
759
- rate: tl.rate,
760
- metadata: tl.metadata,
761
- });
762
- }),
763
- })];
764
- case 20:
765
- _f.sent();
766
- _f.label = 21;
767
- case 21: return [4 /*yield*/, this.lineItemService_
768
- .withTransaction(manager)
769
- .createReturnLines(swap.return_order.id, cart.id)];
770
- case 22:
771
- _f.sent();
772
- swap.cart_id = cart.id;
773
- swapRepo = manager.getCustomRepository(this.swapRepository_);
774
- return [4 /*yield*/, swapRepo.save(swap)];
775
- case 23: return [2 /*return*/, _f.sent()];
776
- }
777
- });
778
- }); })];
703
+ return [4 /*yield*/, lineItemAdjustmentServiceTx.createAdjustmentForLineItem(cart, item)];
704
+ case 14:
705
+ // we generate adjustments in case the cart has any discounts that should be applied to the additional items
706
+ _f.sent();
707
+ _f.label = 15;
708
+ case 15:
709
+ _b = _a.next();
710
+ return [3 /*break*/, 12];
711
+ case 16: return [3 /*break*/, 19];
712
+ case 17:
713
+ e_3_1 = _f.sent();
714
+ e_3 = { error: e_3_1 };
715
+ return [3 /*break*/, 19];
716
+ case 18:
717
+ try {
718
+ if (_b && !_b.done && (_d = _a.return)) _d.call(_a);
719
+ }
720
+ finally { if (e_3) throw e_3.error; }
721
+ return [7 /*endfinally*/];
722
+ case 19:
723
+ if (!(swap.return_order && swap.return_order.shipping_method)) return [3 /*break*/, 21];
724
+ return [4 /*yield*/, this.lineItemService_.withTransaction(manager).create({
725
+ cart_id: cart.id,
726
+ title: "Return shipping",
727
+ quantity: 1,
728
+ has_shipping: true,
729
+ allow_discounts: false,
730
+ unit_price: swap.return_order.shipping_method.price,
731
+ is_return: true,
732
+ tax_lines: swap.return_order.shipping_method.tax_lines.map(function (tl) {
733
+ return lineItemServiceTx.createTaxLine({
734
+ name: tl.name,
735
+ code: tl.code,
736
+ rate: tl.rate,
737
+ metadata: tl.metadata,
738
+ });
739
+ }),
740
+ })];
741
+ case 20:
742
+ _f.sent();
743
+ _f.label = 21;
744
+ case 21: return [4 /*yield*/, this.lineItemService_
745
+ .withTransaction(manager)
746
+ .createReturnLines(swap.return_order.id, cart.id)];
747
+ case 22:
748
+ _f.sent();
749
+ swap.cart_id = cart.id;
750
+ return [4 /*yield*/, swapRepo.save(swap)];
751
+ case 23: return [2 /*return*/, _f.sent()];
752
+ }
753
+ });
754
+ }); })];
755
+ case 1: return [2 /*return*/, _a.sent()];
756
+ }
779
757
  });
780
758
  });
781
759
  };
782
760
  /**
783
- *@param {string} swapId - The id of the swap
761
+ * Register a cart completion
762
+ *
763
+ * @param swapId - The id of the swap
764
+ * @return swap related to the cart
784
765
  */
785
766
  SwapService.prototype.registerCartCompletion = function (swapId) {
786
767
  return __awaiter(this, void 0, void 0, function () {
@@ -788,7 +769,7 @@ var SwapService = /** @class */ (function (_super) {
788
769
  return __generator(this, function (_a) {
789
770
  switch (_a.label) {
790
771
  case 0: return [4 /*yield*/, this.atomicPhase_(function (manager) { return __awaiter(_this, void 0, void 0, function () {
791
- var swap, cart, payment, items, inventoryServiceTx, paymentProviderServiceTx, cartServiceTx, items_1, items_1_1, item, err_3, e_4_1, total, paymentStatus, inventoryServiceTx, items_2, items_2_1, item, e_5_1, now, swapRepo, result, shippingOptionServiceTx, _a, _b, method, e_6_1;
772
+ var swap, cart, payment, items, inventoryServiceTx, paymentProviderServiceTx, cartServiceTx, items_1, items_1_1, item, err_3, e_4_1, total, paymentStatus, inventoryServiceTx, items_2, items_2_1, item, e_5_1, swapRepo, result, shippingOptionServiceTx, _a, _b, method, e_6_1;
792
773
  var e_4, _c, e_5, _d, e_6, _e;
793
774
  return __generator(this, function (_f) {
794
775
  switch (_f.label) {
@@ -814,7 +795,9 @@ var SwapService = /** @class */ (function (_super) {
814
795
  if (swap.canceled_at) {
815
796
  throw new medusa_core_utils_1.MedusaError(medusa_core_utils_1.MedusaError.Types.NOT_ALLOWED, "Cart related to canceled swap cannot be completed");
816
797
  }
817
- return [4 /*yield*/, this.cartService_.retrieve(swap.cart_id, {
798
+ return [4 /*yield*/, this.cartService_
799
+ .withTransaction(manager)
800
+ .retrieve(swap.cart_id, {
818
801
  select: ["total"],
819
802
  relations: [
820
803
  "payment",
@@ -885,7 +868,9 @@ var SwapService = /** @class */ (function (_super) {
885
868
  case 16:
886
869
  paymentStatus = _f.sent();
887
870
  // If payment status is not authorized, we throw
888
- if (paymentStatus !== "authorized" && paymentStatus !== "succeeded") {
871
+ if (paymentStatus !== models_1.PaymentSessionStatus.AUTHORIZED &&
872
+ // @ts-ignore TODO: check why this is not in the enum
873
+ paymentStatus !== "succeeded") {
889
874
  throw new medusa_core_utils_1.MedusaError(medusa_core_utils_1.MedusaError.Types.INVALID_ARGUMENT, "Payment method is not authorized");
890
875
  }
891
876
  return [4 /*yield*/, this.paymentProviderService_
@@ -924,12 +909,12 @@ var SwapService = /** @class */ (function (_super) {
924
909
  finally { if (e_5) throw e_5.error; }
925
910
  return [7 /*endfinally*/];
926
911
  case 25:
927
- now = new Date();
928
912
  swap.difference_due = total;
929
913
  swap.shipping_address_id = cart.shipping_address_id;
930
914
  swap.shipping_methods = cart.shipping_methods;
931
- swap.confirmed_at = now.toISOString();
932
- swap.payment_status = total === 0 ? "confirmed" : "awaiting";
915
+ swap.confirmed_at = new Date();
916
+ swap.payment_status =
917
+ total === 0 ? models_1.SwapPaymentStatus.CONFIRMED : models_1.SwapPaymentStatus.AWAITING;
933
918
  swapRepo = manager.getCustomRepository(this.swapRepository_);
934
919
  return [4 /*yield*/, swapRepo.save(swap)];
935
920
  case 26:
@@ -963,17 +948,18 @@ var SwapService = /** @class */ (function (_super) {
963
948
  }
964
949
  finally { if (e_6) throw e_6.error; }
965
950
  return [7 /*endfinally*/];
966
- case 34:
967
- this.eventBus_
951
+ case 34: return [4 /*yield*/, this.eventBus_
968
952
  .withTransaction(manager)
969
953
  .emit(SwapService.Events.PAYMENT_COMPLETED, {
970
954
  id: swap.id,
971
955
  no_notification: swap.no_notification,
972
- });
956
+ })];
957
+ case 35:
958
+ _f.sent();
973
959
  return [4 /*yield*/, this.cartService_
974
960
  .withTransaction(manager)
975
961
  .update(cart.id, { completed_at: new Date() })];
976
- case 35:
962
+ case 36:
977
963
  _f.sent();
978
964
  return [2 /*return*/, result];
979
965
  }
@@ -988,73 +974,77 @@ var SwapService = /** @class */ (function (_super) {
988
974
  * Cancels a given swap if possible. A swap can only be canceled if all
989
975
  * related returns, fulfillments, and payments have been canceled. If a swap
990
976
  * is associated with a refund, it cannot be canceled.
991
- * @param {string} swapId - the id of the swap to cancel.
992
- * @return {Promise<Swap>} the canceled swap.
977
+ *
978
+ * @param swapId - the id of the swap to cancel.
979
+ * @return the canceled swap.
993
980
  */
994
981
  SwapService.prototype.cancel = function (swapId) {
995
982
  return __awaiter(this, void 0, void 0, function () {
996
983
  var _this = this;
997
984
  return __generator(this, function (_a) {
998
- return [2 /*return*/, this.atomicPhase_(function (manager) { return __awaiter(_this, void 0, void 0, function () {
999
- var swap, _a, _b, f, swapRepo, result;
1000
- var e_7, _c;
1001
- return __generator(this, function (_d) {
1002
- switch (_d.label) {
1003
- case 0: return [4 /*yield*/, this.retrieve(swapId, {
1004
- relations: ["payment", "fulfillments", "return_order"],
1005
- })];
1006
- case 1:
1007
- swap = _d.sent();
1008
- if (swap.payment_status === "difference_refunded" ||
1009
- swap.payment_status === "partially_refunded" ||
1010
- swap.payment_status === "refunded") {
1011
- throw new medusa_core_utils_1.MedusaError(medusa_core_utils_1.MedusaError.Types.NOT_ALLOWED, "Swap with a refund cannot be canceled");
1012
- }
1013
- if (swap.fulfillments) {
1014
- try {
1015
- for (_a = __values(swap.fulfillments), _b = _a.next(); !_b.done; _b = _a.next()) {
1016
- f = _b.value;
1017
- if (!f.canceled_at) {
1018
- throw new medusa_core_utils_1.MedusaError(medusa_core_utils_1.MedusaError.Types.NOT_ALLOWED, "All fulfillments must be canceled before the swap can be canceled");
1019
- }
1020
- }
985
+ switch (_a.label) {
986
+ case 0: return [4 /*yield*/, this.atomicPhase_(function (manager) { return __awaiter(_this, void 0, void 0, function () {
987
+ var swapRepo, swap, _a, _b, f;
988
+ var e_7, _c;
989
+ return __generator(this, function (_d) {
990
+ switch (_d.label) {
991
+ case 0:
992
+ swapRepo = manager.getCustomRepository(this.swapRepository_);
993
+ return [4 /*yield*/, this.retrieve(swapId, {
994
+ relations: ["payment", "fulfillments", "return_order"],
995
+ })];
996
+ case 1:
997
+ swap = _d.sent();
998
+ if (swap.payment_status === models_1.SwapPaymentStatus.DIFFERENCE_REFUNDED ||
999
+ swap.payment_status === models_1.SwapPaymentStatus.PARTIALLY_REFUNDED ||
1000
+ swap.payment_status === models_1.SwapPaymentStatus.REFUNDED) {
1001
+ throw new medusa_core_utils_1.MedusaError(medusa_core_utils_1.MedusaError.Types.NOT_ALLOWED, "Swap with a refund cannot be canceled");
1021
1002
  }
1022
- catch (e_7_1) { e_7 = { error: e_7_1 }; }
1023
- finally {
1003
+ if (swap.fulfillments) {
1024
1004
  try {
1025
- if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
1005
+ for (_a = __values(swap.fulfillments), _b = _a.next(); !_b.done; _b = _a.next()) {
1006
+ f = _b.value;
1007
+ if (!f.canceled_at) {
1008
+ throw new medusa_core_utils_1.MedusaError(medusa_core_utils_1.MedusaError.Types.NOT_ALLOWED, "All fulfillments must be canceled before the swap can be canceled");
1009
+ }
1010
+ }
1011
+ }
1012
+ catch (e_7_1) { e_7 = { error: e_7_1 }; }
1013
+ finally {
1014
+ try {
1015
+ if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
1016
+ }
1017
+ finally { if (e_7) throw e_7.error; }
1026
1018
  }
1027
- finally { if (e_7) throw e_7.error; }
1028
1019
  }
1029
- }
1030
- if (swap.return_order && swap.return_order.status !== "canceled") {
1031
- throw new medusa_core_utils_1.MedusaError(medusa_core_utils_1.MedusaError.Types.NOT_ALLOWED, "Return must be canceled before the swap can be canceled");
1032
- }
1033
- swap.payment_status = "canceled";
1034
- swap.fulfillment_status = "canceled";
1035
- swap.canceled_at = new Date();
1036
- if (!swap.payment) return [3 /*break*/, 3];
1037
- return [4 /*yield*/, this.paymentProviderService_
1038
- .withTransaction(manager)
1039
- .cancelPayment(swap.payment)];
1040
- case 2:
1041
- _d.sent();
1042
- _d.label = 3;
1043
- case 3:
1044
- swapRepo = manager.getCustomRepository(this.swapRepository_);
1045
- return [4 /*yield*/, swapRepo.save(swap)];
1046
- case 4:
1047
- result = _d.sent();
1048
- return [2 /*return*/, result];
1049
- }
1050
- });
1051
- }); })];
1020
+ if (swap.return_order &&
1021
+ swap.return_order.status !== models_1.ReturnStatus.CANCELED) {
1022
+ throw new medusa_core_utils_1.MedusaError(medusa_core_utils_1.MedusaError.Types.NOT_ALLOWED, "Return must be canceled before the swap can be canceled");
1023
+ }
1024
+ swap.payment_status = models_1.SwapPaymentStatus.CANCELED;
1025
+ swap.fulfillment_status = models_1.SwapFulfillmentStatus.CANCELED;
1026
+ swap.canceled_at = new Date();
1027
+ if (!swap.payment) return [3 /*break*/, 3];
1028
+ return [4 /*yield*/, this.paymentProviderService_
1029
+ .withTransaction(manager)
1030
+ .cancelPayment(swap.payment)];
1031
+ case 2:
1032
+ _d.sent();
1033
+ _d.label = 3;
1034
+ case 3: return [4 /*yield*/, swapRepo.save(swap)];
1035
+ case 4: return [2 /*return*/, _d.sent()];
1036
+ }
1037
+ });
1038
+ }); })];
1039
+ case 1: return [2 /*return*/, _a.sent()];
1040
+ }
1052
1041
  });
1053
1042
  });
1054
1043
  };
1055
1044
  /**
1056
- * Fulfills the addtional items associated with the swap. Will call the
1045
+ * Fulfills the additional items associated with the swap. Will call the
1057
1046
  * fulfillment providers associated with the shipping methods.
1047
+ *
1058
1048
  * @param {string} swapId - the id of the swap to fulfill,
1059
1049
  * @param {object} config - optional configurations, includes optional metadata to attach to the shipment, and a no_notification flag.
1060
1050
  * @return {Promise<Swap>} the updated swap with new status and fulfillments.
@@ -1065,189 +1055,193 @@ var SwapService = /** @class */ (function (_super) {
1065
1055
  no_notification: undefined,
1066
1056
  }; }
1067
1057
  return __awaiter(this, void 0, void 0, function () {
1068
- var metadata, no_notification;
1069
1058
  var _this = this;
1070
1059
  return __generator(this, function (_a) {
1071
- metadata = config.metadata, no_notification = config.no_notification;
1072
- return [2 /*return*/, this.atomicPhase_(function (manager) { return __awaiter(_this, void 0, void 0, function () {
1073
- var swap, order, evaluatedNoNotification, _a, successfullyFulfilled, _b, _c, f, lineItemServiceTx, _loop_1, _d, _e, item, e_8_1, swapRepo, result;
1074
- var e_9, _f, e_8, _g;
1075
- var _h;
1076
- return __generator(this, function (_j) {
1077
- switch (_j.label) {
1078
- case 0: return [4 /*yield*/, this.retrieve(swapId, {
1079
- relations: [
1080
- "payment",
1081
- "shipping_address",
1082
- "additional_items",
1083
- "additional_items.tax_lines",
1084
- "shipping_methods",
1085
- "shipping_methods.tax_lines",
1086
- "order",
1087
- "order.region",
1088
- "order.billing_address",
1089
- "order.discounts",
1090
- "order.discounts.rule",
1091
- "order.payments",
1092
- ],
1093
- })];
1094
- case 1:
1095
- swap = _j.sent();
1096
- order = swap.order;
1097
- if (swap.canceled_at) {
1098
- throw new medusa_core_utils_1.MedusaError(medusa_core_utils_1.MedusaError.Types.NOT_ALLOWED, "Canceled swap cannot be fulfilled");
1099
- }
1100
- if (swap.fulfillment_status !== "not_fulfilled" &&
1101
- swap.fulfillment_status !== "canceled") {
1102
- throw new medusa_core_utils_1.MedusaError(medusa_core_utils_1.MedusaError.Types.NOT_ALLOWED, "The swap was already fulfilled");
1103
- }
1104
- if (!((_h = swap.shipping_methods) === null || _h === void 0 ? void 0 : _h.length)) {
1105
- throw new medusa_core_utils_1.MedusaError(medusa_core_utils_1.MedusaError.Types.NOT_ALLOWED, "Cannot fulfill an swap that doesn't have shipping methods");
1106
- }
1107
- evaluatedNoNotification = no_notification !== undefined ? no_notification : swap.no_notification;
1108
- _a = swap;
1109
- return [4 /*yield*/, this.fulfillmentService_
1110
- .withTransaction(manager)
1111
- .createFulfillment(__assign(__assign({}, swap), { payments: swap.payment ? [swap.payment] : order.payments, email: order.email, discounts: order.discounts, currency_code: order.currency_code, tax_rate: order.tax_rate, region_id: order.region_id, region: order.region, display_id: order.display_id, billing_address: order.billing_address, items: swap.additional_items, shipping_methods: swap.shipping_methods, is_swap: true, no_notification: evaluatedNoNotification }), swap.additional_items.map(function (i) { return ({
1112
- item_id: i.id,
1113
- quantity: i.quantity,
1114
- }); }), { swap_id: swapId, metadata: metadata })];
1115
- case 2:
1116
- _a.fulfillments = _j.sent();
1117
- successfullyFulfilled = [];
1118
- try {
1119
- for (_b = __values(swap.fulfillments), _c = _b.next(); !_c.done; _c = _b.next()) {
1120
- f = _c.value;
1121
- successfullyFulfilled = successfullyFulfilled.concat(f.items);
1060
+ switch (_a.label) {
1061
+ case 0: return [4 /*yield*/, this.atomicPhase_(function (manager) { return __awaiter(_this, void 0, void 0, function () {
1062
+ var metadata, no_notification, swapRepo, swap, order, evaluatedNoNotification, _a, successfullyFulfilled, _b, _c, f, lineItemServiceTx, _loop_1, _d, _e, item, e_8_1, result;
1063
+ var e_9, _f, e_8, _g;
1064
+ var _h;
1065
+ return __generator(this, function (_j) {
1066
+ switch (_j.label) {
1067
+ case 0:
1068
+ metadata = config.metadata, no_notification = config.no_notification;
1069
+ swapRepo = manager.getCustomRepository(this.swapRepository_);
1070
+ return [4 /*yield*/, this.retrieve(swapId, {
1071
+ relations: [
1072
+ "payment",
1073
+ "shipping_address",
1074
+ "additional_items",
1075
+ "additional_items.tax_lines",
1076
+ "shipping_methods",
1077
+ "shipping_methods.tax_lines",
1078
+ "order",
1079
+ "order.region",
1080
+ "order.billing_address",
1081
+ "order.discounts",
1082
+ "order.discounts.rule",
1083
+ "order.payments",
1084
+ ],
1085
+ })];
1086
+ case 1:
1087
+ swap = _j.sent();
1088
+ order = swap.order;
1089
+ if (swap.canceled_at) {
1090
+ throw new medusa_core_utils_1.MedusaError(medusa_core_utils_1.MedusaError.Types.NOT_ALLOWED, "Canceled swap cannot be fulfilled");
1122
1091
  }
1123
- }
1124
- catch (e_9_1) { e_9 = { error: e_9_1 }; }
1125
- finally {
1092
+ if (swap.fulfillment_status !== "not_fulfilled" &&
1093
+ swap.fulfillment_status !== "canceled") {
1094
+ throw new medusa_core_utils_1.MedusaError(medusa_core_utils_1.MedusaError.Types.NOT_ALLOWED, "The swap was already fulfilled");
1095
+ }
1096
+ if (!((_h = swap.shipping_methods) === null || _h === void 0 ? void 0 : _h.length)) {
1097
+ throw new medusa_core_utils_1.MedusaError(medusa_core_utils_1.MedusaError.Types.NOT_ALLOWED, "Cannot fulfill an swap that doesn't have shipping methods");
1098
+ }
1099
+ evaluatedNoNotification = no_notification !== undefined ? no_notification : swap.no_notification;
1100
+ _a = swap;
1101
+ return [4 /*yield*/, this.fulfillmentService_
1102
+ .withTransaction(manager)
1103
+ .createFulfillment(__assign(__assign({}, swap), { payments: swap.payment ? [swap.payment] : order.payments, email: order.email, discounts: order.discounts, currency_code: order.currency_code, tax_rate: order.tax_rate, region_id: order.region_id, region: order.region, display_id: order.display_id, billing_address: order.billing_address, items: swap.additional_items, shipping_methods: swap.shipping_methods, is_swap: true, no_notification: evaluatedNoNotification }), swap.additional_items.map(function (i) { return ({
1104
+ item_id: i.id,
1105
+ quantity: i.quantity,
1106
+ }); }), { swap_id: swapId, metadata: metadata })];
1107
+ case 2:
1108
+ _a.fulfillments = _j.sent();
1109
+ successfullyFulfilled = [];
1126
1110
  try {
1127
- if (_c && !_c.done && (_f = _b.return)) _f.call(_b);
1111
+ for (_b = __values(swap.fulfillments), _c = _b.next(); !_c.done; _c = _b.next()) {
1112
+ f = _c.value;
1113
+ successfullyFulfilled = successfullyFulfilled.concat(f.items);
1114
+ }
1128
1115
  }
1129
- finally { if (e_9) throw e_9.error; }
1130
- }
1131
- swap.fulfillment_status = "fulfilled";
1132
- lineItemServiceTx = this.lineItemService_.withTransaction(manager);
1133
- _loop_1 = function (item) {
1134
- var fulfillmentItem, fulfilledQuantity;
1135
- return __generator(this, function (_k) {
1136
- switch (_k.label) {
1137
- case 0:
1138
- fulfillmentItem = successfullyFulfilled.find(function (f) { return item.id === f.item_id; });
1139
- if (!fulfillmentItem) return [3 /*break*/, 2];
1140
- fulfilledQuantity = (item.fulfilled_quantity || 0) + fulfillmentItem.quantity;
1141
- // Update the fulfilled quantity
1142
- return [4 /*yield*/, lineItemServiceTx.update(item.id, {
1143
- fulfilled_quantity: fulfilledQuantity,
1144
- })];
1145
- case 1:
1146
- // Update the fulfilled quantity
1147
- _k.sent();
1148
- if (item.quantity !== fulfilledQuantity) {
1149
- swap.fulfillment_status = "requires_action";
1150
- }
1151
- return [3 /*break*/, 3];
1152
- case 2:
1153
- if (item.quantity !== item.fulfilled_quantity) {
1154
- swap.fulfillment_status = "requires_action";
1155
- }
1156
- _k.label = 3;
1157
- case 3: return [2 /*return*/];
1116
+ catch (e_9_1) { e_9 = { error: e_9_1 }; }
1117
+ finally {
1118
+ try {
1119
+ if (_c && !_c.done && (_f = _b.return)) _f.call(_b);
1158
1120
  }
1159
- });
1160
- };
1161
- _j.label = 3;
1162
- case 3:
1163
- _j.trys.push([3, 8, 9, 10]);
1164
- _d = __values(swap.additional_items), _e = _d.next();
1165
- _j.label = 4;
1166
- case 4:
1167
- if (!!_e.done) return [3 /*break*/, 7];
1168
- item = _e.value;
1169
- return [5 /*yield**/, _loop_1(item)];
1170
- case 5:
1171
- _j.sent();
1172
- _j.label = 6;
1173
- case 6:
1174
- _e = _d.next();
1175
- return [3 /*break*/, 4];
1176
- case 7: return [3 /*break*/, 10];
1177
- case 8:
1178
- e_8_1 = _j.sent();
1179
- e_8 = { error: e_8_1 };
1180
- return [3 /*break*/, 10];
1181
- case 9:
1182
- try {
1183
- if (_e && !_e.done && (_g = _d.return)) _g.call(_d);
1184
- }
1185
- finally { if (e_8) throw e_8.error; }
1186
- return [7 /*endfinally*/];
1187
- case 10:
1188
- swapRepo = manager.getCustomRepository(this.swapRepository_);
1189
- return [4 /*yield*/, swapRepo.save(swap)];
1190
- case 11:
1191
- result = _j.sent();
1192
- return [4 /*yield*/, this.eventBus_.withTransaction(manager).emit(SwapService.Events.FULFILLMENT_CREATED, {
1193
- id: swapId,
1194
- fulfillment_id: result.id,
1195
- no_notification: evaluatedNoNotification,
1196
- })];
1197
- case 12:
1198
- _j.sent();
1199
- return [2 /*return*/, result];
1200
- }
1201
- });
1202
- }); })];
1121
+ finally { if (e_9) throw e_9.error; }
1122
+ }
1123
+ swap.fulfillment_status = models_1.SwapFulfillmentStatus.FULFILLED;
1124
+ lineItemServiceTx = this.lineItemService_.withTransaction(manager);
1125
+ _loop_1 = function (item) {
1126
+ var fulfillmentItem, fulfilledQuantity;
1127
+ return __generator(this, function (_k) {
1128
+ switch (_k.label) {
1129
+ case 0:
1130
+ fulfillmentItem = successfullyFulfilled.find(function (f) { return item.id === f.item_id; });
1131
+ if (!fulfillmentItem) return [3 /*break*/, 2];
1132
+ fulfilledQuantity = (item.fulfilled_quantity || 0) + fulfillmentItem.quantity;
1133
+ // Update the fulfilled quantity
1134
+ return [4 /*yield*/, lineItemServiceTx.update(item.id, {
1135
+ fulfilled_quantity: fulfilledQuantity,
1136
+ })];
1137
+ case 1:
1138
+ // Update the fulfilled quantity
1139
+ _k.sent();
1140
+ if (item.quantity !== fulfilledQuantity) {
1141
+ swap.fulfillment_status = models_1.SwapFulfillmentStatus.REQUIRES_ACTION;
1142
+ }
1143
+ return [3 /*break*/, 3];
1144
+ case 2:
1145
+ if (item.quantity !== item.fulfilled_quantity) {
1146
+ swap.fulfillment_status = models_1.SwapFulfillmentStatus.REQUIRES_ACTION;
1147
+ }
1148
+ _k.label = 3;
1149
+ case 3: return [2 /*return*/];
1150
+ }
1151
+ });
1152
+ };
1153
+ _j.label = 3;
1154
+ case 3:
1155
+ _j.trys.push([3, 8, 9, 10]);
1156
+ _d = __values(swap.additional_items), _e = _d.next();
1157
+ _j.label = 4;
1158
+ case 4:
1159
+ if (!!_e.done) return [3 /*break*/, 7];
1160
+ item = _e.value;
1161
+ return [5 /*yield**/, _loop_1(item)];
1162
+ case 5:
1163
+ _j.sent();
1164
+ _j.label = 6;
1165
+ case 6:
1166
+ _e = _d.next();
1167
+ return [3 /*break*/, 4];
1168
+ case 7: return [3 /*break*/, 10];
1169
+ case 8:
1170
+ e_8_1 = _j.sent();
1171
+ e_8 = { error: e_8_1 };
1172
+ return [3 /*break*/, 10];
1173
+ case 9:
1174
+ try {
1175
+ if (_e && !_e.done && (_g = _d.return)) _g.call(_d);
1176
+ }
1177
+ finally { if (e_8) throw e_8.error; }
1178
+ return [7 /*endfinally*/];
1179
+ case 10: return [4 /*yield*/, swapRepo.save(swap)];
1180
+ case 11:
1181
+ result = _j.sent();
1182
+ return [4 /*yield*/, this.eventBus_.withTransaction(manager).emit(SwapService.Events.FULFILLMENT_CREATED, {
1183
+ id: swapId,
1184
+ fulfillment_id: result.id,
1185
+ no_notification: evaluatedNoNotification,
1186
+ })];
1187
+ case 12:
1188
+ _j.sent();
1189
+ return [2 /*return*/, result];
1190
+ }
1191
+ });
1192
+ }); })];
1193
+ case 1: return [2 /*return*/, _a.sent()];
1194
+ }
1203
1195
  });
1204
1196
  });
1205
1197
  };
1206
1198
  /**
1207
1199
  * Cancels a fulfillment (if related to a swap)
1208
- * @param {string} fulfillmentId - the ID of the fulfillment to cancel
1209
- * @return {Swap} updated swap
1200
+ *
1201
+ * @param fulfillmentId - the ID of the fulfillment to cancel
1202
+ * @return updated swap
1210
1203
  */
1211
1204
  SwapService.prototype.cancelFulfillment = function (fulfillmentId) {
1212
1205
  return __awaiter(this, void 0, void 0, function () {
1213
1206
  var _this = this;
1214
1207
  return __generator(this, function (_a) {
1215
- return [2 /*return*/, this.atomicPhase_(function (manager) { return __awaiter(_this, void 0, void 0, function () {
1216
- var canceled, swap, swapRepo, updated;
1217
- return __generator(this, function (_a) {
1218
- switch (_a.label) {
1219
- case 0: return [4 /*yield*/, this.fulfillmentService_
1220
- .withTransaction(manager)
1221
- .cancelFulfillment(fulfillmentId)];
1222
- case 1:
1223
- canceled = _a.sent();
1224
- if (!canceled.swap_id) {
1225
- throw new medusa_core_utils_1.MedusaError(medusa_core_utils_1.MedusaError.Types.NOT_ALLOWED, "Fufillment not related to a swap");
1226
- }
1227
- return [4 /*yield*/, this.retrieve(canceled.swap_id)];
1228
- case 2:
1229
- swap = _a.sent();
1230
- swap.fulfillment_status = "canceled";
1231
- swapRepo = manager.getCustomRepository(this.swapRepository_);
1232
- return [4 /*yield*/, swapRepo.save(swap)];
1233
- case 3:
1234
- updated = _a.sent();
1235
- return [2 /*return*/, updated];
1236
- }
1237
- });
1238
- }); })];
1208
+ switch (_a.label) {
1209
+ case 0: return [4 /*yield*/, this.atomicPhase_(function (manager) { return __awaiter(_this, void 0, void 0, function () {
1210
+ var swapRepo, canceled, swap;
1211
+ return __generator(this, function (_a) {
1212
+ switch (_a.label) {
1213
+ case 0:
1214
+ swapRepo = manager.getCustomRepository(this.swapRepository_);
1215
+ return [4 /*yield*/, this.fulfillmentService_
1216
+ .withTransaction(manager)
1217
+ .cancelFulfillment(fulfillmentId)];
1218
+ case 1:
1219
+ canceled = _a.sent();
1220
+ if (!canceled.swap_id) {
1221
+ throw new medusa_core_utils_1.MedusaError(medusa_core_utils_1.MedusaError.Types.NOT_ALLOWED, "Fufillment not related to a swap");
1222
+ }
1223
+ return [4 /*yield*/, this.retrieve(canceled.swap_id)];
1224
+ case 2:
1225
+ swap = _a.sent();
1226
+ swap.fulfillment_status = models_1.SwapFulfillmentStatus.CANCELED;
1227
+ return [4 /*yield*/, swapRepo.save(swap)];
1228
+ case 3: return [2 /*return*/, _a.sent()];
1229
+ }
1230
+ });
1231
+ }); })];
1232
+ case 1: return [2 /*return*/, _a.sent()];
1233
+ }
1239
1234
  });
1240
1235
  });
1241
1236
  };
1242
1237
  /**
1243
1238
  * Marks a fulfillment as shipped and attaches tracking numbers.
1244
- * @param {string} swapId - the id of the swap that has been shipped.
1245
- * @param {string} fulfillmentId - the id of the specific fulfillment that
1246
- * has been shipped
1247
- * @param {TrackingLink[] | undefined} trackingLinks - the tracking numbers associated
1248
- * with the shipment
1249
- * @param {object} config - optional configurations, includes optional metadata to attach to the shipment, and a noNotification flag.
1250
- * @return {Promise<Swap>} the updated swap with new fulfillments and status.
1239
+ *
1240
+ * @param swapId - the id of the swap that has been shipped.
1241
+ * @param fulfillmentId - the id of the specific fulfillment that has been shipped
1242
+ * @param trackingLinks - the tracking numbers associated with the shipment
1243
+ * @param config - optional configurations, includes optional metadata to attach to the shipment, and a noNotification flag.
1244
+ * @return the updated swap with new fulfillments and status.
1251
1245
  */
1252
1246
  SwapService.prototype.createShipment = function (swapId, fulfillmentId, trackingLinks, config) {
1253
1247
  if (config === void 0) { config = {
@@ -1255,173 +1249,199 @@ var SwapService = /** @class */ (function (_super) {
1255
1249
  no_notification: undefined,
1256
1250
  }; }
1257
1251
  return __awaiter(this, void 0, void 0, function () {
1258
- var metadata, no_notification;
1259
1252
  var _this = this;
1260
1253
  return __generator(this, function (_a) {
1261
- metadata = config.metadata, no_notification = config.no_notification;
1262
- return [2 /*return*/, this.atomicPhase_(function (manager) { return __awaiter(_this, void 0, void 0, function () {
1263
- var swap, evaluatedNoNotification, shipment, lineItemServiceTx, _loop_2, _a, _b, i, e_10_1, swapRepo, result;
1264
- var e_10, _c;
1265
- return __generator(this, function (_d) {
1266
- switch (_d.label) {
1267
- case 0: return [4 /*yield*/, this.retrieve(swapId, {
1268
- relations: ["additional_items"],
1269
- })];
1270
- case 1:
1271
- swap = _d.sent();
1272
- if (swap.canceled_at) {
1273
- throw new medusa_core_utils_1.MedusaError(medusa_core_utils_1.MedusaError.Types.NOT_ALLOWED, "Canceled swap cannot be fulfilled as shipped");
1274
- }
1275
- evaluatedNoNotification = no_notification !== undefined ? no_notification : swap.no_notification;
1276
- return [4 /*yield*/, this.fulfillmentService_
1277
- .withTransaction(manager)
1278
- .createShipment(fulfillmentId, trackingLinks, {
1279
- metadata: metadata,
1280
- no_notification: evaluatedNoNotification,
1281
- })];
1282
- case 2:
1283
- shipment = _d.sent();
1284
- swap.fulfillment_status = "shipped";
1285
- lineItemServiceTx = this.lineItemService_.withTransaction(manager);
1286
- _loop_2 = function (i) {
1287
- var shipped, shippedQty;
1288
- return __generator(this, function (_e) {
1289
- switch (_e.label) {
1290
- case 0:
1291
- shipped = shipment.items.find(function (si) { return si.item_id === i.id; });
1292
- if (!shipped) return [3 /*break*/, 2];
1293
- shippedQty = (i.shipped_quantity || 0) + shipped.quantity;
1294
- return [4 /*yield*/, lineItemServiceTx.update(i.id, {
1295
- shipped_quantity: shippedQty,
1296
- })];
1297
- case 1:
1298
- _e.sent();
1299
- if (shippedQty !== i.quantity) {
1300
- swap.fulfillment_status = "partially_shipped";
1301
- }
1302
- return [3 /*break*/, 3];
1303
- case 2:
1304
- if (i.shipped_quantity !== i.quantity) {
1305
- swap.fulfillment_status = "partially_shipped";
1306
- }
1307
- _e.label = 3;
1308
- case 3: return [2 /*return*/];
1309
- }
1310
- });
1311
- };
1312
- _d.label = 3;
1313
- case 3:
1314
- _d.trys.push([3, 8, 9, 10]);
1315
- _a = __values(swap.additional_items), _b = _a.next();
1316
- _d.label = 4;
1317
- case 4:
1318
- if (!!_b.done) return [3 /*break*/, 7];
1319
- i = _b.value;
1320
- return [5 /*yield**/, _loop_2(i)];
1321
- case 5:
1322
- _d.sent();
1323
- _d.label = 6;
1324
- case 6:
1325
- _b = _a.next();
1326
- return [3 /*break*/, 4];
1327
- case 7: return [3 /*break*/, 10];
1328
- case 8:
1329
- e_10_1 = _d.sent();
1330
- e_10 = { error: e_10_1 };
1331
- return [3 /*break*/, 10];
1332
- case 9:
1333
- try {
1334
- if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
1335
- }
1336
- finally { if (e_10) throw e_10.error; }
1337
- return [7 /*endfinally*/];
1338
- case 10:
1339
- swapRepo = manager.getCustomRepository(this.swapRepository_);
1340
- return [4 /*yield*/, swapRepo.save(swap)];
1341
- case 11:
1342
- result = _d.sent();
1343
- return [4 /*yield*/, this.eventBus_
1344
- .withTransaction(manager)
1345
- .emit(SwapService.Events.SHIPMENT_CREATED, {
1346
- id: swapId,
1347
- fulfillment_id: shipment.id,
1348
- no_notification: swap.no_notification,
1349
- })];
1350
- case 12:
1351
- _d.sent();
1352
- return [2 /*return*/, result];
1353
- }
1354
- });
1355
- }); })];
1254
+ switch (_a.label) {
1255
+ case 0: return [4 /*yield*/, this.atomicPhase_(function (manager) { return __awaiter(_this, void 0, void 0, function () {
1256
+ var metadata, no_notification, swapRepo, swap, evaluatedNoNotification, shipment, lineItemServiceTx, _loop_2, _a, _b, i, e_10_1, result;
1257
+ var e_10, _c;
1258
+ return __generator(this, function (_d) {
1259
+ switch (_d.label) {
1260
+ case 0:
1261
+ metadata = config.metadata, no_notification = config.no_notification;
1262
+ swapRepo = manager.getCustomRepository(this.swapRepository_);
1263
+ return [4 /*yield*/, this.retrieve(swapId, {
1264
+ relations: ["additional_items"],
1265
+ })];
1266
+ case 1:
1267
+ swap = _d.sent();
1268
+ if (swap.canceled_at) {
1269
+ throw new medusa_core_utils_1.MedusaError(medusa_core_utils_1.MedusaError.Types.NOT_ALLOWED, "Canceled swap cannot be fulfilled as shipped");
1270
+ }
1271
+ evaluatedNoNotification = no_notification !== undefined ? no_notification : swap.no_notification;
1272
+ return [4 /*yield*/, this.fulfillmentService_
1273
+ .withTransaction(manager)
1274
+ .createShipment(fulfillmentId, trackingLinks, {
1275
+ metadata: metadata,
1276
+ no_notification: evaluatedNoNotification,
1277
+ })];
1278
+ case 2:
1279
+ shipment = _d.sent();
1280
+ swap.fulfillment_status = models_1.SwapFulfillmentStatus.SHIPPED;
1281
+ lineItemServiceTx = this.lineItemService_.withTransaction(manager);
1282
+ _loop_2 = function (i) {
1283
+ var shipped, shippedQty;
1284
+ return __generator(this, function (_e) {
1285
+ switch (_e.label) {
1286
+ case 0:
1287
+ shipped = shipment.items.find(function (si) { return si.item_id === i.id; });
1288
+ if (!shipped) return [3 /*break*/, 2];
1289
+ shippedQty = (i.shipped_quantity || 0) + shipped.quantity;
1290
+ return [4 /*yield*/, lineItemServiceTx.update(i.id, {
1291
+ shipped_quantity: shippedQty,
1292
+ })];
1293
+ case 1:
1294
+ _e.sent();
1295
+ if (shippedQty !== i.quantity) {
1296
+ swap.fulfillment_status = models_1.SwapFulfillmentStatus.PARTIALLY_SHIPPED;
1297
+ }
1298
+ return [3 /*break*/, 3];
1299
+ case 2:
1300
+ if (i.shipped_quantity !== i.quantity) {
1301
+ swap.fulfillment_status = models_1.SwapFulfillmentStatus.PARTIALLY_SHIPPED;
1302
+ }
1303
+ _e.label = 3;
1304
+ case 3: return [2 /*return*/];
1305
+ }
1306
+ });
1307
+ };
1308
+ _d.label = 3;
1309
+ case 3:
1310
+ _d.trys.push([3, 8, 9, 10]);
1311
+ _a = __values(swap.additional_items), _b = _a.next();
1312
+ _d.label = 4;
1313
+ case 4:
1314
+ if (!!_b.done) return [3 /*break*/, 7];
1315
+ i = _b.value;
1316
+ return [5 /*yield**/, _loop_2(i)];
1317
+ case 5:
1318
+ _d.sent();
1319
+ _d.label = 6;
1320
+ case 6:
1321
+ _b = _a.next();
1322
+ return [3 /*break*/, 4];
1323
+ case 7: return [3 /*break*/, 10];
1324
+ case 8:
1325
+ e_10_1 = _d.sent();
1326
+ e_10 = { error: e_10_1 };
1327
+ return [3 /*break*/, 10];
1328
+ case 9:
1329
+ try {
1330
+ if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
1331
+ }
1332
+ finally { if (e_10) throw e_10.error; }
1333
+ return [7 /*endfinally*/];
1334
+ case 10: return [4 /*yield*/, swapRepo.save(swap)];
1335
+ case 11:
1336
+ result = _d.sent();
1337
+ return [4 /*yield*/, this.eventBus_
1338
+ .withTransaction(manager)
1339
+ .emit(SwapService.Events.SHIPMENT_CREATED, {
1340
+ id: swapId,
1341
+ fulfillment_id: shipment.id,
1342
+ no_notification: swap.no_notification,
1343
+ })];
1344
+ case 12:
1345
+ _d.sent();
1346
+ return [2 /*return*/, result];
1347
+ }
1348
+ });
1349
+ }); })];
1350
+ case 1: return [2 /*return*/, _a.sent()];
1351
+ }
1356
1352
  });
1357
1353
  });
1358
1354
  };
1359
1355
  /**
1360
1356
  * Dedicated method to delete metadata for a swap.
1361
- * @param {string} swapId - the order to delete metadata from.
1362
- * @param {string} key - key for metadata field
1363
- * @return {Promise} resolves to the updated result.
1357
+ *
1358
+ * @param swapId - the order to delete metadata from.
1359
+ * @param key - key for metadata field
1360
+ * @return resolves to the updated result.
1364
1361
  */
1365
1362
  SwapService.prototype.deleteMetadata = function (swapId, key) {
1366
1363
  return __awaiter(this, void 0, void 0, function () {
1367
- var validatedId, keyPath;
1368
- var _a;
1369
- return __generator(this, function (_b) {
1370
- validatedId = this.validateId_(swapId);
1371
- if (typeof key !== "string") {
1372
- throw new medusa_core_utils_1.MedusaError(medusa_core_utils_1.MedusaError.Types.INVALID_ARGUMENT, "Key type is invalid. Metadata keys must be strings");
1364
+ var _this = this;
1365
+ return __generator(this, function (_a) {
1366
+ switch (_a.label) {
1367
+ case 0: return [4 /*yield*/, this.atomicPhase_(function (transactionManager) { return __awaiter(_this, void 0, void 0, function () {
1368
+ var validatedId, swapRepo, swap, updated, updatedSwap;
1369
+ return __generator(this, function (_a) {
1370
+ switch (_a.label) {
1371
+ case 0:
1372
+ validatedId = (0, utils_1.validateId)(swapId);
1373
+ swapRepo = transactionManager.getCustomRepository(this.swapRepository_);
1374
+ return [4 /*yield*/, swapRepo.findOne(validatedId)];
1375
+ case 1:
1376
+ swap = _a.sent();
1377
+ if (!swap) {
1378
+ throw new medusa_core_utils_1.MedusaError(medusa_core_utils_1.MedusaError.Types.NOT_FOUND, "Swap with id: ".concat(validatedId, " was not found"));
1379
+ }
1380
+ updated = swap.metadata || {};
1381
+ delete updated[key];
1382
+ swap.metadata = updated;
1383
+ return [4 /*yield*/, swapRepo.save(swap)];
1384
+ case 2:
1385
+ updatedSwap = _a.sent();
1386
+ return [4 /*yield*/, this.eventBus_
1387
+ .withTransaction(transactionManager)
1388
+ .emit(cart_1.default.Events.UPDATED, updatedSwap)];
1389
+ case 3:
1390
+ _a.sent();
1391
+ return [2 /*return*/, updatedSwap];
1392
+ }
1393
+ });
1394
+ }); })];
1395
+ case 1: return [2 /*return*/, _a.sent()];
1373
1396
  }
1374
- keyPath = "metadata.".concat(key);
1375
- return [2 /*return*/, this.swapModel_
1376
- .updateOne({ _id: validatedId }, { $unset: (_a = {}, _a[keyPath] = "", _a) })
1377
- .catch(function (err) {
1378
- throw new medusa_core_utils_1.MedusaError(medusa_core_utils_1.MedusaError.Types.DB_ERROR, err.message);
1379
- })];
1380
1397
  });
1381
1398
  });
1382
1399
  };
1383
1400
  /**
1384
1401
  * Registers the swap return items as received so that they cannot be used
1385
1402
  * as a part of other swaps/returns.
1386
- * @param {string} id - the id of the order with the swap.
1387
- * @param {string} swapId - the id of the swap that has been received.
1388
- * @return {Promise<Order>} the resulting order
1403
+ *
1404
+ * @param id - the id of the order with the swap.
1405
+ * @return the resulting order
1389
1406
  */
1390
1407
  SwapService.prototype.registerReceived = function (id) {
1391
1408
  return __awaiter(this, void 0, void 0, function () {
1392
1409
  var _this = this;
1393
1410
  return __generator(this, function (_a) {
1394
- return [2 /*return*/, this.atomicPhase_(function (manager) { return __awaiter(_this, void 0, void 0, function () {
1395
- var swap, result;
1396
- return __generator(this, function (_a) {
1397
- switch (_a.label) {
1398
- case 0: return [4 /*yield*/, this.retrieve(id, {
1399
- relations: ["return_order", "return_order.items"],
1400
- })];
1401
- case 1:
1402
- swap = _a.sent();
1403
- if (swap.canceled_at) {
1404
- throw new medusa_core_utils_1.MedusaError(medusa_core_utils_1.MedusaError.Types.NOT_ALLOWED, "Canceled swap cannot be registered as received");
1405
- }
1406
- if (swap.return_order.status !== "received") {
1407
- throw new medusa_core_utils_1.MedusaError(medusa_core_utils_1.MedusaError.Types.NOT_ALLOWED, "Swap is not received");
1408
- }
1409
- return [4 /*yield*/, this.retrieve(id)];
1410
- case 2:
1411
- result = _a.sent();
1412
- return [4 /*yield*/, this.eventBus_
1413
- .withTransaction(manager)
1414
- .emit(SwapService.Events.RECEIVED, {
1415
- id: id,
1416
- order_id: result.order_id,
1417
- no_notification: swap.no_notification,
1411
+ switch (_a.label) {
1412
+ case 0: return [4 /*yield*/, this.atomicPhase_(function (manager) { return __awaiter(_this, void 0, void 0, function () {
1413
+ var swap, result;
1414
+ return __generator(this, function (_a) {
1415
+ switch (_a.label) {
1416
+ case 0: return [4 /*yield*/, this.retrieve(id, {
1417
+ relations: ["return_order", "return_order.items"],
1418
1418
  })];
1419
- case 3:
1420
- _a.sent();
1421
- return [2 /*return*/, result];
1422
- }
1423
- });
1424
- }); })];
1419
+ case 1:
1420
+ swap = _a.sent();
1421
+ if (swap.canceled_at) {
1422
+ throw new medusa_core_utils_1.MedusaError(medusa_core_utils_1.MedusaError.Types.NOT_ALLOWED, "Canceled swap cannot be registered as received");
1423
+ }
1424
+ if (swap.return_order.status !== "received") {
1425
+ throw new medusa_core_utils_1.MedusaError(medusa_core_utils_1.MedusaError.Types.NOT_ALLOWED, "Swap is not received");
1426
+ }
1427
+ return [4 /*yield*/, this.retrieve(id)];
1428
+ case 2:
1429
+ result = _a.sent();
1430
+ return [4 /*yield*/, this.eventBus_
1431
+ .withTransaction(manager)
1432
+ .emit(SwapService.Events.RECEIVED, {
1433
+ id: id,
1434
+ order_id: result.order_id,
1435
+ no_notification: swap.no_notification,
1436
+ })];
1437
+ case 3:
1438
+ _a.sent();
1439
+ return [2 /*return*/, result];
1440
+ }
1441
+ });
1442
+ }); })];
1443
+ case 1: return [2 /*return*/, _a.sent()];
1444
+ }
1425
1445
  });
1426
1446
  });
1427
1447
  };
@@ -1437,6 +1457,6 @@ var SwapService = /** @class */ (function (_super) {
1437
1457
  FULFILLMENT_CREATED: "swap.fulfillment_created",
1438
1458
  };
1439
1459
  return SwapService;
1440
- }(medusa_interfaces_1.BaseService));
1460
+ }(interfaces_1.TransactionBaseService));
1441
1461
  exports.default = SwapService;
1442
1462
  //# sourceMappingURL=swap.js.map