@medusajs/medusa 1.3.3 → 1.3.6-next.0

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 (1329) hide show
  1. package/.turbo/turbo-build.log +1 -0
  2. package/CHANGELOG.md +207 -180
  3. package/dist/api/index.d.ts +1 -0
  4. package/dist/api/index.js +6 -1
  5. package/dist/api/index.js.map +1 -1
  6. package/dist/api/middlewares/await-middleware.js +7 -0
  7. package/dist/api/middlewares/await-middleware.js.map +1 -1
  8. package/dist/api/middlewares/error-handler.d.ts +1 -1
  9. package/dist/api/middlewares/error-handler.js +1 -0
  10. package/dist/api/middlewares/error-handler.js.map +1 -1
  11. package/dist/api/middlewares/normalized-query.d.ts +1 -1
  12. package/dist/api/middlewares/transform-query.d.ts +1 -1
  13. package/dist/api/middlewares/transform-query.js +2 -0
  14. package/dist/api/middlewares/transform-query.js.map +1 -1
  15. package/dist/api/middlewares/validators/product-existence.d.ts +3 -0
  16. package/dist/api/middlewares/validators/product-existence.js +86 -0
  17. package/dist/api/middlewares/validators/product-existence.js.map +1 -0
  18. package/dist/api/middlewares/validators/sales-channel-existence.d.ts +3 -0
  19. package/dist/api/middlewares/validators/sales-channel-existence.js +86 -0
  20. package/dist/api/middlewares/validators/sales-channel-existence.js.map +1 -0
  21. package/dist/api/routes/admin/apps/authorize-app.d.ts +3 -3
  22. package/dist/api/routes/admin/apps/authorize-app.js +2 -2
  23. package/dist/api/routes/admin/apps/authorize-app.js.map +1 -1
  24. package/dist/api/routes/admin/apps/list.d.ts +6 -4
  25. package/dist/api/routes/admin/apps/list.js +5 -3
  26. package/dist/api/routes/admin/apps/list.js.map +1 -1
  27. package/dist/api/routes/admin/auth/create-session.d.ts +19 -1
  28. package/dist/api/routes/admin/auth/create-session.js +30 -4
  29. package/dist/api/routes/admin/auth/create-session.js.map +1 -1
  30. package/dist/api/routes/admin/auth/delete-session.d.ts +2 -2
  31. package/dist/api/routes/admin/auth/delete-session.js +1 -1
  32. package/dist/api/routes/admin/auth/get-session.d.ts +3 -1
  33. package/dist/api/routes/admin/auth/get-session.js +2 -0
  34. package/dist/api/routes/admin/auth/get-session.js.map +1 -1
  35. package/dist/api/routes/admin/auth/index.js +5 -1
  36. package/dist/api/routes/admin/auth/index.js.map +1 -1
  37. package/dist/api/routes/admin/batch/cancel-batch-job.d.ts +2 -2
  38. package/dist/api/routes/admin/batch/cancel-batch-job.js +13 -3
  39. package/dist/api/routes/admin/batch/cancel-batch-job.js.map +1 -1
  40. package/dist/api/routes/admin/batch/confirm-batch-job.d.ts +3 -3
  41. package/dist/api/routes/admin/batch/confirm-batch-job.js +14 -4
  42. package/dist/api/routes/admin/batch/confirm-batch-job.js.map +1 -1
  43. package/dist/api/routes/admin/batch/create-batch-job.d.ts +37 -6
  44. package/dist/api/routes/admin/batch/create-batch-job.js +46 -7
  45. package/dist/api/routes/admin/batch/create-batch-job.js.map +1 -1
  46. package/dist/api/routes/admin/batch/get-batch-job.d.ts +2 -2
  47. package/dist/api/routes/admin/batch/get-batch-job.js +1 -1
  48. package/dist/api/routes/admin/batch/index.js +5 -1
  49. package/dist/api/routes/admin/batch/index.js.map +1 -1
  50. package/dist/api/routes/admin/batch/list-batch-jobs.d.ts +209 -17
  51. package/dist/api/routes/admin/batch/list-batch-jobs.js +214 -19
  52. package/dist/api/routes/admin/batch/list-batch-jobs.js.map +1 -1
  53. package/dist/api/routes/admin/collections/add-products.d.ts +12 -6
  54. package/dist/api/routes/admin/collections/add-products.js +23 -7
  55. package/dist/api/routes/admin/collections/add-products.js.map +1 -1
  56. package/dist/api/routes/admin/collections/create-collection.d.ts +2 -2
  57. package/dist/api/routes/admin/collections/create-collection.js +12 -2
  58. package/dist/api/routes/admin/collections/create-collection.js.map +1 -1
  59. package/dist/api/routes/admin/collections/delete-collection.d.ts +6 -3
  60. package/dist/api/routes/admin/collections/delete-collection.js +15 -4
  61. package/dist/api/routes/admin/collections/delete-collection.js.map +1 -1
  62. package/dist/api/routes/admin/collections/get-collection.d.ts +2 -2
  63. package/dist/api/routes/admin/collections/get-collection.js +1 -1
  64. package/dist/api/routes/admin/collections/get-collection.js.map +1 -1
  65. package/dist/api/routes/admin/collections/index.js +5 -1
  66. package/dist/api/routes/admin/collections/index.js.map +1 -1
  67. package/dist/api/routes/admin/collections/list-collections.d.ts +84 -9
  68. package/dist/api/routes/admin/collections/list-collections.js +88 -9
  69. package/dist/api/routes/admin/collections/list-collections.js.map +1 -1
  70. package/dist/api/routes/admin/collections/remove-products.d.ts +23 -6
  71. package/dist/api/routes/admin/collections/remove-products.js +32 -7
  72. package/dist/api/routes/admin/collections/remove-products.js.map +1 -1
  73. package/dist/api/routes/admin/collections/update-collection.d.ts +3 -3
  74. package/dist/api/routes/admin/collections/update-collection.js +13 -3
  75. package/dist/api/routes/admin/collections/update-collection.js.map +1 -1
  76. package/dist/api/routes/admin/customer-groups/add-customers-batch.d.ts +23 -7
  77. package/dist/api/routes/admin/customer-groups/add-customers-batch.js +37 -11
  78. package/dist/api/routes/admin/customer-groups/add-customers-batch.js.map +1 -1
  79. package/dist/api/routes/admin/customer-groups/create-customer-group.d.ts +2 -2
  80. package/dist/api/routes/admin/customer-groups/create-customer-group.js +13 -3
  81. package/dist/api/routes/admin/customer-groups/create-customer-group.js.map +1 -1
  82. package/dist/api/routes/admin/customer-groups/delete-customer-group.d.ts +7 -4
  83. package/dist/api/routes/admin/customer-groups/delete-customer-group.js +18 -5
  84. package/dist/api/routes/admin/customer-groups/delete-customer-group.js.map +1 -1
  85. package/dist/api/routes/admin/customer-groups/delete-customers-batch.d.ts +23 -7
  86. package/dist/api/routes/admin/customer-groups/delete-customers-batch.js +37 -11
  87. package/dist/api/routes/admin/customer-groups/delete-customers-batch.js.map +1 -1
  88. package/dist/api/routes/admin/customer-groups/get-customer-group-customers.d.ts +18 -5
  89. package/dist/api/routes/admin/customer-groups/get-customer-group-customers.js +17 -4
  90. package/dist/api/routes/admin/customer-groups/get-customer-group-customers.js.map +1 -1
  91. package/dist/api/routes/admin/customer-groups/get-customer-group.d.ts +6 -4
  92. package/dist/api/routes/admin/customer-groups/get-customer-group.js +4 -2
  93. package/dist/api/routes/admin/customer-groups/get-customer-group.js.map +1 -1
  94. package/dist/api/routes/admin/customer-groups/index.js +5 -1
  95. package/dist/api/routes/admin/customer-groups/index.js.map +1 -1
  96. package/dist/api/routes/admin/customer-groups/list-customer-groups.d.ts +102 -13
  97. package/dist/api/routes/admin/customer-groups/list-customer-groups.js +101 -12
  98. package/dist/api/routes/admin/customer-groups/list-customer-groups.js.map +1 -1
  99. package/dist/api/routes/admin/customer-groups/update-customer-group.d.ts +14 -5
  100. package/dist/api/routes/admin/customer-groups/update-customer-group.js +26 -7
  101. package/dist/api/routes/admin/customer-groups/update-customer-group.js.map +1 -1
  102. package/dist/api/routes/admin/customers/create-customer.d.ts +32 -8
  103. package/dist/api/routes/admin/customers/create-customer.js +43 -9
  104. package/dist/api/routes/admin/customers/create-customer.js.map +1 -1
  105. package/dist/api/routes/admin/customers/get-customer.d.ts +4 -2
  106. package/dist/api/routes/admin/customers/get-customer.js +4 -2
  107. package/dist/api/routes/admin/customers/get-customer.js.map +1 -1
  108. package/dist/api/routes/admin/customers/index.js +5 -1
  109. package/dist/api/routes/admin/customers/index.js.map +1 -1
  110. package/dist/api/routes/admin/customers/list-customers.d.ts +20 -3
  111. package/dist/api/routes/admin/customers/list-customers.js +24 -7
  112. package/dist/api/routes/admin/customers/list-customers.js.map +1 -1
  113. package/dist/api/routes/admin/customers/update-customer.d.ts +10 -6
  114. package/dist/api/routes/admin/customers/update-customer.js +24 -10
  115. package/dist/api/routes/admin/customers/update-customer.js.map +1 -1
  116. package/dist/api/routes/admin/discounts/add-region.d.ts +3 -3
  117. package/dist/api/routes/admin/discounts/add-region.js +14 -4
  118. package/dist/api/routes/admin/discounts/add-region.js.map +1 -1
  119. package/dist/api/routes/admin/discounts/create-condition.d.ts +34 -22
  120. package/dist/api/routes/admin/discounts/create-condition.js +45 -23
  121. package/dist/api/routes/admin/discounts/create-condition.js.map +1 -1
  122. package/dist/api/routes/admin/discounts/create-discount.d.ts +72 -9
  123. package/dist/api/routes/admin/discounts/create-discount.js +87 -14
  124. package/dist/api/routes/admin/discounts/create-discount.js.map +1 -1
  125. package/dist/api/routes/admin/discounts/create-dynamic-code.d.ts +3 -3
  126. package/dist/api/routes/admin/discounts/create-dynamic-code.js +14 -4
  127. package/dist/api/routes/admin/discounts/create-dynamic-code.js.map +1 -1
  128. package/dist/api/routes/admin/discounts/delete-condition.d.ts +11 -6
  129. package/dist/api/routes/admin/discounts/delete-condition.js +23 -8
  130. package/dist/api/routes/admin/discounts/delete-condition.js.map +1 -1
  131. package/dist/api/routes/admin/discounts/delete-discount.d.ts +6 -3
  132. package/dist/api/routes/admin/discounts/delete-discount.js +17 -4
  133. package/dist/api/routes/admin/discounts/delete-discount.js.map +1 -1
  134. package/dist/api/routes/admin/discounts/delete-dynamic-code.d.ts +3 -3
  135. package/dist/api/routes/admin/discounts/delete-dynamic-code.js +14 -4
  136. package/dist/api/routes/admin/discounts/delete-dynamic-code.js.map +1 -1
  137. package/dist/api/routes/admin/discounts/get-condition.d.ts +6 -7
  138. package/dist/api/routes/admin/discounts/get-condition.js +6 -7
  139. package/dist/api/routes/admin/discounts/get-condition.js.map +1 -1
  140. package/dist/api/routes/admin/discounts/get-discount-by-code.d.ts +3 -1
  141. package/dist/api/routes/admin/discounts/get-discount-by-code.js +2 -0
  142. package/dist/api/routes/admin/discounts/get-discount-by-code.js.map +1 -1
  143. package/dist/api/routes/admin/discounts/get-discount.d.ts +4 -5
  144. package/dist/api/routes/admin/discounts/get-discount.js +3 -4
  145. package/dist/api/routes/admin/discounts/get-discount.js.map +1 -1
  146. package/dist/api/routes/admin/discounts/index.js +5 -1
  147. package/dist/api/routes/admin/discounts/index.js.map +1 -1
  148. package/dist/api/routes/admin/discounts/list-discounts.d.ts +31 -6
  149. package/dist/api/routes/admin/discounts/list-discounts.js +38 -8
  150. package/dist/api/routes/admin/discounts/list-discounts.js.map +1 -1
  151. package/dist/api/routes/admin/discounts/remove-region.d.ts +3 -3
  152. package/dist/api/routes/admin/discounts/remove-region.js +14 -4
  153. package/dist/api/routes/admin/discounts/remove-region.js.map +1 -1
  154. package/dist/api/routes/admin/discounts/update-condition.d.ts +31 -24
  155. package/dist/api/routes/admin/discounts/update-condition.js +42 -25
  156. package/dist/api/routes/admin/discounts/update-condition.js.map +1 -1
  157. package/dist/api/routes/admin/discounts/update-discount.d.ts +75 -9
  158. package/dist/api/routes/admin/discounts/update-discount.js +90 -14
  159. package/dist/api/routes/admin/discounts/update-discount.js.map +1 -1
  160. package/dist/api/routes/admin/draft-orders/create-draft-order.d.ts +18 -9
  161. package/dist/api/routes/admin/draft-orders/create-draft-order.js +31 -12
  162. package/dist/api/routes/admin/draft-orders/create-draft-order.js.map +1 -1
  163. package/dist/api/routes/admin/draft-orders/create-line-item.d.ts +7 -4
  164. package/dist/api/routes/admin/draft-orders/create-line-item.js +11 -6
  165. package/dist/api/routes/admin/draft-orders/create-line-item.js.map +1 -1
  166. package/dist/api/routes/admin/draft-orders/delete-draft-order.d.ts +6 -3
  167. package/dist/api/routes/admin/draft-orders/delete-draft-order.js +17 -4
  168. package/dist/api/routes/admin/draft-orders/delete-draft-order.js.map +1 -1
  169. package/dist/api/routes/admin/draft-orders/delete-line-item.d.ts +3 -3
  170. package/dist/api/routes/admin/draft-orders/delete-line-item.js +3 -3
  171. package/dist/api/routes/admin/draft-orders/delete-line-item.js.map +1 -1
  172. package/dist/api/routes/admin/draft-orders/get-draft-order.d.ts +2 -2
  173. package/dist/api/routes/admin/draft-orders/get-draft-order.js +1 -1
  174. package/dist/api/routes/admin/draft-orders/get-draft-order.js.map +1 -1
  175. package/dist/api/routes/admin/draft-orders/index.js +5 -1
  176. package/dist/api/routes/admin/draft-orders/index.js.map +1 -1
  177. package/dist/api/routes/admin/draft-orders/list-draft-orders.d.ts +18 -3
  178. package/dist/api/routes/admin/draft-orders/list-draft-orders.js +19 -4
  179. package/dist/api/routes/admin/draft-orders/list-draft-orders.js.map +1 -1
  180. package/dist/api/routes/admin/draft-orders/register-payment.d.ts +3 -3
  181. package/dist/api/routes/admin/draft-orders/register-payment.js +8 -5
  182. package/dist/api/routes/admin/draft-orders/register-payment.js.map +1 -1
  183. package/dist/api/routes/admin/draft-orders/update-draft-order.d.ts +16 -8
  184. package/dist/api/routes/admin/draft-orders/update-draft-order.js +46 -22
  185. package/dist/api/routes/admin/draft-orders/update-draft-order.js.map +1 -1
  186. package/dist/api/routes/admin/draft-orders/update-line-item.d.ts +4 -1
  187. package/dist/api/routes/admin/draft-orders/update-line-item.js +4 -1
  188. package/dist/api/routes/admin/draft-orders/update-line-item.js.map +1 -1
  189. package/dist/api/routes/admin/gift-cards/create-gift-card.d.ts +5 -5
  190. package/dist/api/routes/admin/gift-cards/create-gift-card.js +15 -7
  191. package/dist/api/routes/admin/gift-cards/create-gift-card.js.map +1 -1
  192. package/dist/api/routes/admin/gift-cards/delete-gift-card.d.ts +6 -3
  193. package/dist/api/routes/admin/gift-cards/delete-gift-card.js +15 -4
  194. package/dist/api/routes/admin/gift-cards/delete-gift-card.js.map +1 -1
  195. package/dist/api/routes/admin/gift-cards/get-gift-card.d.ts +2 -2
  196. package/dist/api/routes/admin/gift-cards/get-gift-card.js +1 -1
  197. package/dist/api/routes/admin/gift-cards/index.js +5 -1
  198. package/dist/api/routes/admin/gift-cards/index.js.map +1 -1
  199. package/dist/api/routes/admin/gift-cards/list-gift-cards.d.ts +14 -1
  200. package/dist/api/routes/admin/gift-cards/list-gift-cards.js +16 -2
  201. package/dist/api/routes/admin/gift-cards/list-gift-cards.js.map +1 -1
  202. package/dist/api/routes/admin/gift-cards/update-gift-card.d.ts +4 -6
  203. package/dist/api/routes/admin/gift-cards/update-gift-card.js +16 -8
  204. package/dist/api/routes/admin/gift-cards/update-gift-card.js.map +1 -1
  205. package/dist/api/routes/admin/index.js +27 -20
  206. package/dist/api/routes/admin/index.js.map +1 -1
  207. package/dist/api/routes/admin/invites/accept-invite.d.ts +3 -2
  208. package/dist/api/routes/admin/invites/accept-invite.js +15 -4
  209. package/dist/api/routes/admin/invites/accept-invite.js.map +1 -1
  210. package/dist/api/routes/admin/invites/create-invite.d.ts +4 -2
  211. package/dist/api/routes/admin/invites/create-invite.js +15 -3
  212. package/dist/api/routes/admin/invites/create-invite.js.map +1 -1
  213. package/dist/api/routes/admin/invites/delete-invite.d.ts +18 -3
  214. package/dist/api/routes/admin/invites/delete-invite.js +29 -4
  215. package/dist/api/routes/admin/invites/delete-invite.js.map +1 -1
  216. package/dist/api/routes/admin/invites/index.js +5 -1
  217. package/dist/api/routes/admin/invites/index.js.map +1 -1
  218. package/dist/api/routes/admin/invites/list-invites.d.ts +2 -2
  219. package/dist/api/routes/admin/invites/list-invites.js +1 -1
  220. package/dist/api/routes/admin/invites/resend-invite.d.ts +3 -3
  221. package/dist/api/routes/admin/invites/resend-invite.js +14 -4
  222. package/dist/api/routes/admin/invites/resend-invite.js.map +1 -1
  223. package/dist/api/routes/admin/notes/create-note.d.ts +6 -2
  224. package/dist/api/routes/admin/notes/create-note.js +20 -8
  225. package/dist/api/routes/admin/notes/create-note.js.map +1 -1
  226. package/dist/api/routes/admin/notes/delete-note.d.ts +8 -3
  227. package/dist/api/routes/admin/notes/delete-note.js +17 -4
  228. package/dist/api/routes/admin/notes/delete-note.js.map +1 -1
  229. package/dist/api/routes/admin/notes/get-note.d.ts +2 -2
  230. package/dist/api/routes/admin/notes/get-note.js +1 -1
  231. package/dist/api/routes/admin/notes/index.js +5 -1
  232. package/dist/api/routes/admin/notes/index.js.map +1 -1
  233. package/dist/api/routes/admin/notes/list-notes.d.ts +14 -5
  234. package/dist/api/routes/admin/notes/list-notes.js +14 -5
  235. package/dist/api/routes/admin/notes/list-notes.js.map +1 -1
  236. package/dist/api/routes/admin/notes/update-note.d.ts +2 -2
  237. package/dist/api/routes/admin/notes/update-note.js +13 -3
  238. package/dist/api/routes/admin/notes/update-note.js.map +1 -1
  239. package/dist/api/routes/admin/notifications/index.js +5 -1
  240. package/dist/api/routes/admin/notifications/index.js.map +1 -1
  241. package/dist/api/routes/admin/notifications/list-notifications.d.ts +8 -8
  242. package/dist/api/routes/admin/notifications/list-notifications.js +17 -16
  243. package/dist/api/routes/admin/notifications/list-notifications.js.map +1 -1
  244. package/dist/api/routes/admin/notifications/resend-notification.d.ts +3 -3
  245. package/dist/api/routes/admin/notifications/resend-notification.js +17 -7
  246. package/dist/api/routes/admin/notifications/resend-notification.js.map +1 -1
  247. package/dist/api/routes/admin/orders/add-shipping-method.d.ts +4 -4
  248. package/dist/api/routes/admin/orders/add-shipping-method.js +17 -7
  249. package/dist/api/routes/admin/orders/add-shipping-method.js.map +1 -1
  250. package/dist/api/routes/admin/orders/archive-order.d.ts +2 -2
  251. package/dist/api/routes/admin/orders/archive-order.js +11 -3
  252. package/dist/api/routes/admin/orders/archive-order.js.map +1 -1
  253. package/dist/api/routes/admin/orders/cancel-claim.d.ts +4 -4
  254. package/dist/api/routes/admin/orders/cancel-claim.js +16 -6
  255. package/dist/api/routes/admin/orders/cancel-claim.js.map +1 -1
  256. package/dist/api/routes/admin/orders/cancel-fulfillment-claim.d.ts +6 -6
  257. package/dist/api/routes/admin/orders/cancel-fulfillment-claim.js +18 -8
  258. package/dist/api/routes/admin/orders/cancel-fulfillment-claim.js.map +1 -1
  259. package/dist/api/routes/admin/orders/cancel-fulfillment-swap.d.ts +6 -6
  260. package/dist/api/routes/admin/orders/cancel-fulfillment-swap.js +18 -8
  261. package/dist/api/routes/admin/orders/cancel-fulfillment-swap.js.map +1 -1
  262. package/dist/api/routes/admin/orders/cancel-fulfillment.d.ts +5 -5
  263. package/dist/api/routes/admin/orders/cancel-fulfillment.js +17 -7
  264. package/dist/api/routes/admin/orders/cancel-fulfillment.js.map +1 -1
  265. package/dist/api/routes/admin/orders/cancel-order.d.ts +2 -2
  266. package/dist/api/routes/admin/orders/cancel-order.js +11 -3
  267. package/dist/api/routes/admin/orders/cancel-order.js.map +1 -1
  268. package/dist/api/routes/admin/orders/cancel-swap.d.ts +4 -4
  269. package/dist/api/routes/admin/orders/cancel-swap.js +14 -6
  270. package/dist/api/routes/admin/orders/cancel-swap.js.map +1 -1
  271. package/dist/api/routes/admin/orders/capture-payment.d.ts +2 -2
  272. package/dist/api/routes/admin/orders/capture-payment.js +13 -3
  273. package/dist/api/routes/admin/orders/capture-payment.js.map +1 -1
  274. package/dist/api/routes/admin/orders/complete-order.d.ts +2 -2
  275. package/dist/api/routes/admin/orders/complete-order.js +13 -3
  276. package/dist/api/routes/admin/orders/complete-order.js.map +1 -1
  277. package/dist/api/routes/admin/orders/create-claim-shipment.d.ts +5 -5
  278. package/dist/api/routes/admin/orders/create-claim-shipment.js +22 -12
  279. package/dist/api/routes/admin/orders/create-claim-shipment.js.map +1 -1
  280. package/dist/api/routes/admin/orders/create-claim.d.ts +23 -16
  281. package/dist/api/routes/admin/orders/create-claim.js +223 -157
  282. package/dist/api/routes/admin/orders/create-claim.js.map +1 -1
  283. package/dist/api/routes/admin/orders/create-fulfillment.d.ts +9 -6
  284. package/dist/api/routes/admin/orders/create-fulfillment.js +23 -10
  285. package/dist/api/routes/admin/orders/create-fulfillment.js.map +1 -1
  286. package/dist/api/routes/admin/orders/create-shipment.d.ts +3 -3
  287. package/dist/api/routes/admin/orders/create-shipment.js +25 -10
  288. package/dist/api/routes/admin/orders/create-shipment.js.map +1 -1
  289. package/dist/api/routes/admin/orders/create-swap-shipment.d.ts +5 -5
  290. package/dist/api/routes/admin/orders/create-swap-shipment.js +20 -12
  291. package/dist/api/routes/admin/orders/create-swap-shipment.js.map +1 -1
  292. package/dist/api/routes/admin/orders/create-swap.d.ts +16 -7
  293. package/dist/api/routes/admin/orders/create-swap.js +167 -109
  294. package/dist/api/routes/admin/orders/create-swap.js.map +1 -1
  295. package/dist/api/routes/admin/orders/fulfill-claim.d.ts +4 -4
  296. package/dist/api/routes/admin/orders/fulfill-claim.js +3 -3
  297. package/dist/api/routes/admin/orders/fulfill-claim.js.map +1 -1
  298. package/dist/api/routes/admin/orders/fulfill-swap.d.ts +4 -4
  299. package/dist/api/routes/admin/orders/fulfill-swap.js +11 -12
  300. package/dist/api/routes/admin/orders/fulfill-swap.js.map +1 -1
  301. package/dist/api/routes/admin/orders/get-order.d.ts +2 -2
  302. package/dist/api/routes/admin/orders/get-order.js +2 -6
  303. package/dist/api/routes/admin/orders/get-order.js.map +1 -1
  304. package/dist/api/routes/admin/orders/index.d.ts +3 -4
  305. package/dist/api/routes/admin/orders/index.js +63 -17
  306. package/dist/api/routes/admin/orders/index.js.map +1 -1
  307. package/dist/api/routes/admin/orders/list-orders.d.ts +144 -14
  308. package/dist/api/routes/admin/orders/list-orders.js +154 -51
  309. package/dist/api/routes/admin/orders/list-orders.js.map +1 -1
  310. package/dist/api/routes/admin/orders/process-swap-payment.d.ts +4 -4
  311. package/dist/api/routes/admin/orders/process-swap-payment.js +3 -3
  312. package/dist/api/routes/admin/orders/process-swap-payment.js.map +1 -1
  313. package/dist/api/routes/admin/orders/refund-payment.d.ts +4 -4
  314. package/dist/api/routes/admin/orders/refund-payment.js +17 -7
  315. package/dist/api/routes/admin/orders/refund-payment.js.map +1 -1
  316. package/dist/api/routes/admin/orders/request-return.d.ts +14 -6
  317. package/dist/api/routes/admin/orders/request-return.js +196 -138
  318. package/dist/api/routes/admin/orders/request-return.js.map +1 -1
  319. package/dist/api/routes/admin/orders/update-claim.d.ts +32 -10
  320. package/dist/api/routes/admin/orders/update-claim.js +44 -12
  321. package/dist/api/routes/admin/orders/update-claim.js.map +1 -1
  322. package/dist/api/routes/admin/orders/update-order.d.ts +21 -15
  323. package/dist/api/routes/admin/orders/update-order.js +28 -12
  324. package/dist/api/routes/admin/orders/update-order.js.map +1 -1
  325. package/dist/api/routes/admin/price-lists/add-prices-batch.d.ts +42 -45
  326. package/dist/api/routes/admin/price-lists/add-prices-batch.js +54 -47
  327. package/dist/api/routes/admin/price-lists/add-prices-batch.js.map +1 -1
  328. package/dist/api/routes/admin/price-lists/create-price-list.d.ts +54 -32
  329. package/dist/api/routes/admin/price-lists/create-price-list.js +67 -35
  330. package/dist/api/routes/admin/price-lists/create-price-list.js.map +1 -1
  331. package/dist/api/routes/admin/price-lists/delete-price-list.d.ts +6 -3
  332. package/dist/api/routes/admin/price-lists/delete-price-list.js +15 -4
  333. package/dist/api/routes/admin/price-lists/delete-price-list.js.map +1 -1
  334. package/dist/api/routes/admin/price-lists/delete-prices-batch.d.ts +17 -14
  335. package/dist/api/routes/admin/price-lists/delete-prices-batch.js +28 -15
  336. package/dist/api/routes/admin/price-lists/delete-prices-batch.js.map +1 -1
  337. package/dist/api/routes/admin/price-lists/delete-product-prices.d.ts +14 -12
  338. package/dist/api/routes/admin/price-lists/delete-product-prices.js +25 -15
  339. package/dist/api/routes/admin/price-lists/delete-product-prices.js.map +1 -1
  340. package/dist/api/routes/admin/price-lists/delete-variant-prices.d.ts +14 -12
  341. package/dist/api/routes/admin/price-lists/delete-variant-prices.js +25 -15
  342. package/dist/api/routes/admin/price-lists/delete-variant-prices.js.map +1 -1
  343. package/dist/api/routes/admin/price-lists/get-price-list.d.ts +2 -2
  344. package/dist/api/routes/admin/price-lists/get-price-list.js +1 -1
  345. package/dist/api/routes/admin/price-lists/get-price-list.js.map +1 -1
  346. package/dist/api/routes/admin/price-lists/index.js +5 -1
  347. package/dist/api/routes/admin/price-lists/index.js.map +1 -1
  348. package/dist/api/routes/admin/price-lists/list-price-list-products.d.ts +113 -25
  349. package/dist/api/routes/admin/price-lists/list-price-list-products.js +115 -27
  350. package/dist/api/routes/admin/price-lists/list-price-list-products.js.map +1 -1
  351. package/dist/api/routes/admin/price-lists/list-price-lists.d.ts +107 -4
  352. package/dist/api/routes/admin/price-lists/list-price-lists.js +107 -4
  353. package/dist/api/routes/admin/price-lists/list-price-lists.js.map +1 -1
  354. package/dist/api/routes/admin/price-lists/update-price-list.d.ts +53 -36
  355. package/dist/api/routes/admin/price-lists/update-price-list.js +66 -39
  356. package/dist/api/routes/admin/price-lists/update-price-list.js.map +1 -1
  357. package/dist/api/routes/admin/product-tags/index.js +5 -1
  358. package/dist/api/routes/admin/product-tags/index.js.map +1 -1
  359. package/dist/api/routes/admin/product-tags/list-product-tags.d.ts +77 -8
  360. package/dist/api/routes/admin/product-tags/list-product-tags.js +82 -12
  361. package/dist/api/routes/admin/product-tags/list-product-tags.js.map +1 -1
  362. package/dist/api/routes/admin/product-types/index.js +5 -1
  363. package/dist/api/routes/admin/product-types/index.js.map +1 -1
  364. package/dist/api/routes/admin/product-types/list-product-types.d.ts +79 -10
  365. package/dist/api/routes/admin/product-types/list-product-types.js +84 -14
  366. package/dist/api/routes/admin/product-types/list-product-types.js.map +1 -1
  367. package/dist/api/routes/admin/products/add-option.d.ts +2 -2
  368. package/dist/api/routes/admin/products/add-option.js +14 -4
  369. package/dist/api/routes/admin/products/add-option.js.map +1 -1
  370. package/dist/api/routes/admin/products/create-product.d.ts +59 -27
  371. package/dist/api/routes/admin/products/create-product.js +85 -56
  372. package/dist/api/routes/admin/products/create-product.js.map +1 -1
  373. package/dist/api/routes/admin/products/create-variant.d.ts +23 -11
  374. package/dist/api/routes/admin/products/create-variant.js +35 -13
  375. package/dist/api/routes/admin/products/create-variant.js.map +1 -1
  376. package/dist/api/routes/admin/products/delete-option.d.ts +8 -5
  377. package/dist/api/routes/admin/products/delete-option.js +19 -6
  378. package/dist/api/routes/admin/products/delete-option.js.map +1 -1
  379. package/dist/api/routes/admin/products/delete-product.d.ts +6 -3
  380. package/dist/api/routes/admin/products/delete-product.js +15 -4
  381. package/dist/api/routes/admin/products/delete-product.js.map +1 -1
  382. package/dist/api/routes/admin/products/delete-variant.d.ts +10 -5
  383. package/dist/api/routes/admin/products/delete-variant.js +23 -6
  384. package/dist/api/routes/admin/products/delete-variant.js.map +1 -1
  385. package/dist/api/routes/admin/products/get-product.d.ts +2 -2
  386. package/dist/api/routes/admin/products/get-product.js +2 -6
  387. package/dist/api/routes/admin/products/get-product.js.map +1 -1
  388. package/dist/api/routes/admin/products/index.d.ts +4 -3
  389. package/dist/api/routes/admin/products/index.js +41 -11
  390. package/dist/api/routes/admin/products/index.js.map +1 -1
  391. package/dist/api/routes/admin/products/list-products.d.ts +143 -44
  392. package/dist/api/routes/admin/products/list-products.js +192 -155
  393. package/dist/api/routes/admin/products/list-products.js.map +1 -1
  394. package/dist/api/routes/admin/products/list-tag-usage-count.d.ts +29 -0
  395. package/dist/api/routes/admin/products/list-tag-usage-count.js +29 -0
  396. package/dist/api/routes/admin/products/list-tag-usage-count.js.map +1 -1
  397. package/dist/api/routes/admin/products/list-types.d.ts +1 -1
  398. package/dist/api/routes/admin/products/list-variants.d.ts +13 -4
  399. package/dist/api/routes/admin/products/list-variants.js +14 -5
  400. package/dist/api/routes/admin/products/list-variants.js.map +1 -1
  401. package/dist/api/routes/admin/products/set-metadata.d.ts +2 -2
  402. package/dist/api/routes/admin/products/set-metadata.js +20 -12
  403. package/dist/api/routes/admin/products/set-metadata.js.map +1 -1
  404. package/dist/api/routes/admin/products/update-option.d.ts +5 -5
  405. package/dist/api/routes/admin/products/update-option.js +17 -7
  406. package/dist/api/routes/admin/products/update-option.js.map +1 -1
  407. package/dist/api/routes/admin/products/update-product.d.ts +55 -31
  408. package/dist/api/routes/admin/products/update-product.js +85 -56
  409. package/dist/api/routes/admin/products/update-product.js.map +1 -1
  410. package/dist/api/routes/admin/products/update-variant.d.ts +19 -11
  411. package/dist/api/routes/admin/products/update-variant.js +33 -13
  412. package/dist/api/routes/admin/products/update-variant.js.map +1 -1
  413. package/dist/api/routes/admin/regions/add-country.d.ts +5 -2
  414. package/dist/api/routes/admin/regions/add-country.js +17 -4
  415. package/dist/api/routes/admin/regions/add-country.js.map +1 -1
  416. package/dist/api/routes/admin/regions/add-fulfillment-provider.d.ts +5 -5
  417. package/dist/api/routes/admin/regions/add-fulfillment-provider.js +17 -7
  418. package/dist/api/routes/admin/regions/add-fulfillment-provider.js.map +1 -1
  419. package/dist/api/routes/admin/regions/add-payment-provider.d.ts +5 -5
  420. package/dist/api/routes/admin/regions/add-payment-provider.js +17 -7
  421. package/dist/api/routes/admin/regions/add-payment-provider.js.map +1 -1
  422. package/dist/api/routes/admin/regions/create-region.d.ts +15 -8
  423. package/dist/api/routes/admin/regions/create-region.js +26 -9
  424. package/dist/api/routes/admin/regions/create-region.js.map +1 -1
  425. package/dist/api/routes/admin/regions/delete-region.d.ts +6 -3
  426. package/dist/api/routes/admin/regions/delete-region.js +17 -4
  427. package/dist/api/routes/admin/regions/delete-region.js.map +1 -1
  428. package/dist/api/routes/admin/regions/get-fulfillment-options.d.ts +13 -3
  429. package/dist/api/routes/admin/regions/get-fulfillment-options.js +12 -2
  430. package/dist/api/routes/admin/regions/get-fulfillment-options.js.map +1 -1
  431. package/dist/api/routes/admin/regions/get-region.d.ts +2 -2
  432. package/dist/api/routes/admin/regions/get-region.js +1 -1
  433. package/dist/api/routes/admin/regions/get-region.js.map +1 -1
  434. package/dist/api/routes/admin/regions/index.d.ts +0 -1
  435. package/dist/api/routes/admin/regions/index.js +5 -10
  436. package/dist/api/routes/admin/regions/index.js.map +1 -1
  437. package/dist/api/routes/admin/regions/list-regions.d.ts +18 -7
  438. package/dist/api/routes/admin/regions/list-regions.js +25 -10
  439. package/dist/api/routes/admin/regions/list-regions.js.map +1 -1
  440. package/dist/api/routes/admin/regions/remove-country.d.ts +11 -3
  441. package/dist/api/routes/admin/regions/remove-country.js +22 -4
  442. package/dist/api/routes/admin/regions/remove-country.js.map +1 -1
  443. package/dist/api/routes/admin/regions/remove-fulfillment-provider.d.ts +3 -3
  444. package/dist/api/routes/admin/regions/remove-fulfillment-provider.js +14 -4
  445. package/dist/api/routes/admin/regions/remove-fulfillment-provider.js.map +1 -1
  446. package/dist/api/routes/admin/regions/remove-payment-provider.d.ts +3 -3
  447. package/dist/api/routes/admin/regions/remove-payment-provider.js +14 -4
  448. package/dist/api/routes/admin/regions/remove-payment-provider.js.map +1 -1
  449. package/dist/api/routes/admin/regions/update-region.d.ts +9 -6
  450. package/dist/api/routes/admin/regions/update-region.js +20 -7
  451. package/dist/api/routes/admin/regions/update-region.js.map +1 -1
  452. package/dist/api/routes/admin/return-reasons/create-reason.d.ts +4 -4
  453. package/dist/api/routes/admin/return-reasons/create-reason.js +14 -4
  454. package/dist/api/routes/admin/return-reasons/create-reason.js.map +1 -1
  455. package/dist/api/routes/admin/return-reasons/delete-reason.d.ts +6 -3
  456. package/dist/api/routes/admin/return-reasons/delete-reason.js +17 -4
  457. package/dist/api/routes/admin/return-reasons/delete-reason.js.map +1 -1
  458. package/dist/api/routes/admin/return-reasons/get-reason.d.ts +2 -2
  459. package/dist/api/routes/admin/return-reasons/get-reason.js +1 -1
  460. package/dist/api/routes/admin/return-reasons/get-reason.js.map +1 -1
  461. package/dist/api/routes/admin/return-reasons/index.d.ts +2 -2
  462. package/dist/api/routes/admin/return-reasons/index.js +5 -1
  463. package/dist/api/routes/admin/return-reasons/index.js.map +1 -1
  464. package/dist/api/routes/admin/return-reasons/list-reasons.d.ts +1 -1
  465. package/dist/api/routes/admin/return-reasons/list-reasons.js.map +1 -1
  466. package/dist/api/routes/admin/return-reasons/update-reason.d.ts +6 -3
  467. package/dist/api/routes/admin/return-reasons/update-reason.js +16 -3
  468. package/dist/api/routes/admin/return-reasons/update-reason.js.map +1 -1
  469. package/dist/api/routes/admin/returns/cancel-return.d.ts +3 -3
  470. package/dist/api/routes/admin/returns/cancel-return.js +12 -4
  471. package/dist/api/routes/admin/returns/cancel-return.js.map +1 -1
  472. package/dist/api/routes/admin/returns/index.js +5 -1
  473. package/dist/api/routes/admin/returns/index.js.map +1 -1
  474. package/dist/api/routes/admin/returns/list-returns.d.ts +12 -3
  475. package/dist/api/routes/admin/returns/list-returns.js +12 -3
  476. package/dist/api/routes/admin/returns/list-returns.js.map +1 -1
  477. package/dist/api/routes/admin/returns/receive-return.d.ts +7 -4
  478. package/dist/api/routes/admin/returns/receive-return.js +9 -5
  479. package/dist/api/routes/admin/returns/receive-return.js.map +1 -1
  480. package/dist/api/routes/admin/sales-channels/add-product-batch.d.ts +45 -0
  481. package/dist/api/routes/admin/sales-channels/add-product-batch.js +128 -0
  482. package/dist/api/routes/admin/sales-channels/add-product-batch.js.map +1 -0
  483. package/dist/api/routes/admin/sales-channels/create-sales-channel.d.ts +42 -0
  484. package/dist/api/routes/{store/carts/update-payment-method.js → admin/sales-channels/create-sales-channel.js} +48 -41
  485. package/dist/api/routes/admin/sales-channels/create-sales-channel.js.map +1 -0
  486. package/dist/api/routes/admin/sales-channels/delete-products-batch.d.ts +45 -0
  487. package/dist/api/routes/admin/sales-channels/delete-products-batch.js +128 -0
  488. package/dist/api/routes/admin/sales-channels/delete-products-batch.js.map +1 -0
  489. package/dist/api/routes/admin/sales-channels/delete-sales-channel.d.ts +32 -0
  490. package/dist/api/routes/admin/{orders/delete-metadata.js → sales-channels/delete-sales-channel.js} +40 -23
  491. package/dist/api/routes/admin/sales-channels/delete-sales-channel.js.map +1 -0
  492. package/dist/api/routes/admin/sales-channels/get-sales-channel.d.ts +23 -0
  493. package/dist/api/routes/admin/{products/get-variants.js → sales-channels/get-sales-channel.js} +14 -16
  494. package/dist/api/routes/admin/sales-channels/get-sales-channel.js.map +1 -0
  495. package/dist/api/routes/admin/sales-channels/index.d.ts +19 -0
  496. package/dist/api/routes/admin/sales-channels/index.js +63 -0
  497. package/dist/api/routes/admin/sales-channels/index.js.map +1 -0
  498. package/dist/api/routes/admin/sales-channels/list-sales-channels.d.ts +120 -0
  499. package/dist/api/routes/admin/sales-channels/list-sales-channels.js +260 -0
  500. package/dist/api/routes/admin/sales-channels/list-sales-channels.js.map +1 -0
  501. package/dist/api/routes/admin/sales-channels/update-sales-channel.d.ts +42 -0
  502. package/dist/api/routes/admin/{regions/set-metadata.js → sales-channels/update-sales-channel.js} +53 -34
  503. package/dist/api/routes/admin/sales-channels/update-sales-channel.js.map +1 -0
  504. package/dist/api/routes/admin/shipping-options/create-shipping-option.d.ts +15 -4
  505. package/dist/api/routes/admin/shipping-options/create-shipping-option.js +28 -6
  506. package/dist/api/routes/admin/shipping-options/create-shipping-option.js.map +1 -1
  507. package/dist/api/routes/admin/shipping-options/delete-shipping-option.d.ts +6 -3
  508. package/dist/api/routes/admin/shipping-options/delete-shipping-option.js +17 -4
  509. package/dist/api/routes/admin/shipping-options/delete-shipping-option.js.map +1 -1
  510. package/dist/api/routes/admin/shipping-options/get-shipping-option.d.ts +2 -2
  511. package/dist/api/routes/admin/shipping-options/get-shipping-option.js +1 -1
  512. package/dist/api/routes/admin/shipping-options/index.js +5 -1
  513. package/dist/api/routes/admin/shipping-options/index.js.map +1 -1
  514. package/dist/api/routes/admin/shipping-options/list-shipping-options.d.ts +9 -9
  515. package/dist/api/routes/admin/shipping-options/list-shipping-options.js +10 -10
  516. package/dist/api/routes/admin/shipping-options/list-shipping-options.js.map +1 -1
  517. package/dist/api/routes/admin/shipping-options/update-shipping-option.d.ts +10 -2
  518. package/dist/api/routes/admin/shipping-options/update-shipping-option.js +22 -4
  519. package/dist/api/routes/admin/shipping-options/update-shipping-option.js.map +1 -1
  520. package/dist/api/routes/admin/shipping-profiles/create-shipping-profile.d.ts +1 -1
  521. package/dist/api/routes/admin/shipping-profiles/create-shipping-profile.js +12 -2
  522. package/dist/api/routes/admin/shipping-profiles/create-shipping-profile.js.map +1 -1
  523. package/dist/api/routes/admin/shipping-profiles/delete-shipping-profile.d.ts +6 -3
  524. package/dist/api/routes/admin/shipping-profiles/delete-shipping-profile.js +17 -4
  525. package/dist/api/routes/admin/shipping-profiles/delete-shipping-profile.js.map +1 -1
  526. package/dist/api/routes/admin/shipping-profiles/get-shipping-profile.d.ts +2 -2
  527. package/dist/api/routes/admin/shipping-profiles/get-shipping-profile.js +1 -1
  528. package/dist/api/routes/admin/shipping-profiles/get-shipping-profile.js.map +1 -1
  529. package/dist/api/routes/admin/shipping-profiles/index.d.ts +2 -2
  530. package/dist/api/routes/admin/shipping-profiles/index.js +6 -5
  531. package/dist/api/routes/admin/shipping-profiles/index.js.map +1 -1
  532. package/dist/api/routes/admin/shipping-profiles/list-shipping-profiles.d.ts +1 -1
  533. package/dist/api/routes/admin/shipping-profiles/update-shipping-profile.d.ts +3 -3
  534. package/dist/api/routes/admin/shipping-profiles/update-shipping-profile.js +14 -4
  535. package/dist/api/routes/admin/shipping-profiles/update-shipping-profile.js.map +1 -1
  536. package/dist/api/routes/admin/store/add-currency.d.ts +10 -2
  537. package/dist/api/routes/admin/store/add-currency.js +21 -3
  538. package/dist/api/routes/admin/store/add-currency.js.map +1 -1
  539. package/dist/api/routes/admin/store/get-store.d.ts +1 -1
  540. package/dist/api/routes/admin/store/get-store.js +8 -2
  541. package/dist/api/routes/admin/store/get-store.js.map +1 -1
  542. package/dist/api/routes/admin/store/index.js +5 -1
  543. package/dist/api/routes/admin/store/index.js.map +1 -1
  544. package/dist/api/routes/admin/store/list-payment-providers.d.ts +2 -2
  545. package/dist/api/routes/admin/store/list-payment-providers.js +1 -1
  546. package/dist/api/routes/admin/store/list-tax-providers.d.ts +2 -2
  547. package/dist/api/routes/admin/store/list-tax-providers.js +1 -1
  548. package/dist/api/routes/admin/store/remove-currency.d.ts +10 -2
  549. package/dist/api/routes/admin/store/remove-currency.js +21 -3
  550. package/dist/api/routes/admin/store/remove-currency.js.map +1 -1
  551. package/dist/api/routes/admin/store/update-store.d.ts +12 -1
  552. package/dist/api/routes/admin/store/update-store.js +23 -2
  553. package/dist/api/routes/admin/store/update-store.js.map +1 -1
  554. package/dist/api/routes/admin/swaps/get-swap.d.ts +2 -2
  555. package/dist/api/routes/admin/swaps/get-swap.js +1 -1
  556. package/dist/api/routes/admin/swaps/get-swap.js.map +1 -1
  557. package/dist/api/routes/admin/swaps/index.js +5 -1
  558. package/dist/api/routes/admin/swaps/index.js.map +1 -1
  559. package/dist/api/routes/admin/swaps/list-swaps.d.ts +13 -1
  560. package/dist/api/routes/admin/swaps/list-swaps.js +13 -1
  561. package/dist/api/routes/admin/swaps/list-swaps.js.map +1 -1
  562. package/dist/api/routes/admin/tax-rates/add-to-product-types.d.ts +34 -5
  563. package/dist/api/routes/admin/tax-rates/add-to-product-types.js +46 -7
  564. package/dist/api/routes/admin/tax-rates/add-to-product-types.js.map +1 -1
  565. package/dist/api/routes/admin/tax-rates/add-to-products.d.ts +34 -5
  566. package/dist/api/routes/admin/tax-rates/add-to-products.js +46 -7
  567. package/dist/api/routes/admin/tax-rates/add-to-products.js.map +1 -1
  568. package/dist/api/routes/admin/tax-rates/add-to-shipping-options.d.ts +35 -6
  569. package/dist/api/routes/admin/tax-rates/add-to-shipping-options.js +47 -8
  570. package/dist/api/routes/admin/tax-rates/add-to-shipping-options.js.map +1 -1
  571. package/dist/api/routes/admin/tax-rates/create-tax-rate.d.ts +58 -5
  572. package/dist/api/routes/admin/tax-rates/create-tax-rate.js +64 -10
  573. package/dist/api/routes/admin/tax-rates/create-tax-rate.js.map +1 -1
  574. package/dist/api/routes/admin/tax-rates/delete-tax-rate.d.ts +7 -4
  575. package/dist/api/routes/admin/tax-rates/delete-tax-rate.js +16 -5
  576. package/dist/api/routes/admin/tax-rates/delete-tax-rate.js.map +1 -1
  577. package/dist/api/routes/admin/tax-rates/get-tax-rate.d.ts +22 -5
  578. package/dist/api/routes/admin/tax-rates/get-tax-rate.js +22 -5
  579. package/dist/api/routes/admin/tax-rates/get-tax-rate.js.map +1 -1
  580. package/dist/api/routes/admin/tax-rates/index.js +5 -1
  581. package/dist/api/routes/admin/tax-rates/index.js.map +1 -1
  582. package/dist/api/routes/admin/tax-rates/list-tax-rates.d.ts +68 -14
  583. package/dist/api/routes/admin/tax-rates/list-tax-rates.js +70 -16
  584. package/dist/api/routes/admin/tax-rates/list-tax-rates.js.map +1 -1
  585. package/dist/api/routes/admin/tax-rates/remove-from-product-types.d.ts +34 -5
  586. package/dist/api/routes/admin/tax-rates/remove-from-product-types.js +46 -7
  587. package/dist/api/routes/admin/tax-rates/remove-from-product-types.js.map +1 -1
  588. package/dist/api/routes/admin/tax-rates/remove-from-products.d.ts +34 -5
  589. package/dist/api/routes/admin/tax-rates/remove-from-products.js +46 -7
  590. package/dist/api/routes/admin/tax-rates/remove-from-products.js.map +1 -1
  591. package/dist/api/routes/admin/tax-rates/remove-from-shipping-options.d.ts +34 -5
  592. package/dist/api/routes/admin/tax-rates/remove-from-shipping-options.js +46 -7
  593. package/dist/api/routes/admin/tax-rates/remove-from-shipping-options.js.map +1 -1
  594. package/dist/api/routes/admin/tax-rates/update-tax-rate.d.ts +54 -5
  595. package/dist/api/routes/admin/tax-rates/update-tax-rate.js +59 -9
  596. package/dist/api/routes/admin/tax-rates/update-tax-rate.js.map +1 -1
  597. package/dist/api/routes/admin/tax-rates/utils/get-query-config.js +5 -4
  598. package/dist/api/routes/admin/tax-rates/utils/get-query-config.js.map +1 -1
  599. package/dist/api/routes/admin/uploads/create-upload.d.ts +23 -6
  600. package/dist/api/routes/admin/uploads/create-upload.js +22 -5
  601. package/dist/api/routes/admin/uploads/create-upload.js.map +1 -1
  602. package/dist/api/routes/admin/uploads/delete-upload.d.ts +27 -2
  603. package/dist/api/routes/admin/uploads/delete-upload.js +26 -1
  604. package/dist/api/routes/admin/uploads/delete-upload.js.map +1 -1
  605. package/dist/api/routes/admin/uploads/get-download-url.d.ts +9 -3
  606. package/dist/api/routes/admin/uploads/get-download-url.js +8 -2
  607. package/dist/api/routes/admin/uploads/get-download-url.js.map +1 -1
  608. package/dist/api/routes/admin/uploads/index.js +5 -1
  609. package/dist/api/routes/admin/uploads/index.js.map +1 -1
  610. package/dist/api/routes/admin/users/create-user.d.ts +5 -2
  611. package/dist/api/routes/admin/users/create-user.js +17 -4
  612. package/dist/api/routes/admin/users/create-user.js.map +1 -1
  613. package/dist/api/routes/admin/users/delete-user.d.ts +7 -4
  614. package/dist/api/routes/admin/users/delete-user.js +16 -5
  615. package/dist/api/routes/admin/users/delete-user.js.map +1 -1
  616. package/dist/api/routes/admin/users/get-user.d.ts +3 -3
  617. package/dist/api/routes/admin/users/get-user.js +2 -2
  618. package/dist/api/routes/admin/users/index.js +5 -1
  619. package/dist/api/routes/admin/users/index.js.map +1 -1
  620. package/dist/api/routes/admin/users/list-users.d.ts +2 -2
  621. package/dist/api/routes/admin/users/list-users.js +1 -1
  622. package/dist/api/routes/admin/users/reset-password-token.d.ts +3 -2
  623. package/dist/api/routes/admin/users/reset-password-token.js +14 -5
  624. package/dist/api/routes/admin/users/reset-password-token.js.map +1 -1
  625. package/dist/api/routes/admin/users/reset-password.d.ts +5 -4
  626. package/dist/api/routes/admin/users/reset-password.js +23 -13
  627. package/dist/api/routes/admin/users/reset-password.js.map +1 -1
  628. package/dist/api/routes/admin/users/update-user.d.ts +27 -9
  629. package/dist/api/routes/admin/users/update-user.js +38 -10
  630. package/dist/api/routes/admin/users/update-user.js.map +1 -1
  631. package/dist/api/routes/admin/variants/index.js +5 -1
  632. package/dist/api/routes/admin/variants/index.js.map +1 -1
  633. package/dist/api/routes/admin/variants/list-variants.d.ts +12 -3
  634. package/dist/api/routes/admin/variants/list-variants.js +13 -4
  635. package/dist/api/routes/admin/variants/list-variants.js.map +1 -1
  636. package/dist/api/routes/store/auth/create-session.d.ts +1 -1
  637. package/dist/api/routes/store/auth/create-session.js +12 -2
  638. package/dist/api/routes/store/auth/create-session.js.map +1 -1
  639. package/dist/api/routes/store/auth/delete-session.d.ts +1 -1
  640. package/dist/api/routes/store/auth/exists.d.ts +9 -2
  641. package/dist/api/routes/store/auth/exists.js +8 -1
  642. package/dist/api/routes/store/auth/exists.js.map +1 -1
  643. package/dist/api/routes/store/auth/get-session.d.ts +3 -1
  644. package/dist/api/routes/store/auth/get-session.js +2 -0
  645. package/dist/api/routes/store/auth/get-session.js.map +1 -1
  646. package/dist/api/routes/store/auth/index.js +5 -1
  647. package/dist/api/routes/store/auth/index.js.map +1 -1
  648. package/dist/api/routes/store/carts/add-shipping-method.d.ts +4 -4
  649. package/dist/api/routes/store/carts/add-shipping-method.js +4 -4
  650. package/dist/api/routes/store/carts/add-shipping-method.js.map +1 -1
  651. package/dist/api/routes/store/carts/calculate-taxes.d.ts +6 -8
  652. package/dist/api/routes/store/carts/calculate-taxes.js +89 -56
  653. package/dist/api/routes/store/carts/calculate-taxes.js.map +1 -1
  654. package/dist/api/routes/store/carts/complete-cart.d.ts +25 -14
  655. package/dist/api/routes/store/carts/complete-cart.js +34 -15
  656. package/dist/api/routes/store/carts/complete-cart.js.map +1 -1
  657. package/dist/api/routes/store/carts/create-cart.d.ts +15 -2
  658. package/dist/api/routes/store/carts/create-cart.js +86 -89
  659. package/dist/api/routes/store/carts/create-cart.js.map +1 -1
  660. package/dist/api/routes/store/carts/create-line-item.d.ts +1 -1
  661. package/dist/api/routes/store/carts/create-line-item.js +6 -3
  662. package/dist/api/routes/store/carts/create-line-item.js.map +1 -1
  663. package/dist/api/routes/store/carts/create-payment-sessions.d.ts +1 -1
  664. package/dist/api/routes/store/carts/create-payment-sessions.js +121 -13
  665. package/dist/api/routes/store/carts/create-payment-sessions.js.map +1 -1
  666. package/dist/api/routes/store/carts/decorate-line-items-with-totals.d.ts +2 -0
  667. package/dist/api/routes/store/carts/decorate-line-items-with-totals.js +46 -17
  668. package/dist/api/routes/store/carts/decorate-line-items-with-totals.js.map +1 -1
  669. package/dist/api/routes/store/carts/delete-discount.d.ts +1 -1
  670. package/dist/api/routes/store/carts/delete-line-item.d.ts +1 -1
  671. package/dist/api/routes/store/carts/delete-payment-session.d.ts +1 -1
  672. package/dist/api/routes/store/carts/delete-payment-session.js +10 -2
  673. package/dist/api/routes/store/carts/delete-payment-session.js.map +1 -1
  674. package/dist/api/routes/store/carts/get-cart.d.ts +1 -1
  675. package/dist/api/routes/store/carts/get-cart.js +1 -5
  676. package/dist/api/routes/store/carts/get-cart.js.map +1 -1
  677. package/dist/api/routes/store/carts/index.js +32 -8
  678. package/dist/api/routes/store/carts/index.js.map +1 -1
  679. package/dist/api/routes/store/carts/refresh-payment-session.d.ts +1 -1
  680. package/dist/api/routes/store/carts/refresh-payment-session.js +10 -2
  681. package/dist/api/routes/store/carts/refresh-payment-session.js.map +1 -1
  682. package/dist/api/routes/store/carts/set-payment-session.d.ts +3 -3
  683. package/dist/api/routes/store/carts/set-payment-session.js +15 -7
  684. package/dist/api/routes/store/carts/set-payment-session.js.map +1 -1
  685. package/dist/api/routes/store/carts/update-cart.d.ts +21 -4
  686. package/dist/api/routes/store/carts/update-cart.js +66 -68
  687. package/dist/api/routes/store/carts/update-cart.js.map +1 -1
  688. package/dist/api/routes/store/carts/update-line-item.d.ts +1 -1
  689. package/dist/api/routes/store/carts/update-line-item.js +1 -1
  690. package/dist/api/routes/store/carts/update-line-item.js.map +1 -1
  691. package/dist/api/routes/store/carts/update-payment-session.d.ts +2 -2
  692. package/dist/api/routes/store/carts/update-payment-session.js +17 -7
  693. package/dist/api/routes/store/carts/update-payment-session.js.map +1 -1
  694. package/dist/api/routes/store/collections/get-collection.d.ts +1 -1
  695. package/dist/api/routes/store/collections/index.js +5 -1
  696. package/dist/api/routes/store/collections/index.js.map +1 -1
  697. package/dist/api/routes/store/collections/list-collections.d.ts +58 -3
  698. package/dist/api/routes/store/collections/list-collections.js +59 -4
  699. package/dist/api/routes/store/collections/list-collections.js.map +1 -1
  700. package/dist/api/routes/store/customers/create-address.d.ts +3 -3
  701. package/dist/api/routes/store/customers/create-address.js +15 -5
  702. package/dist/api/routes/store/customers/create-address.js.map +1 -1
  703. package/dist/api/routes/store/customers/create-customer.d.ts +47 -7
  704. package/dist/api/routes/store/customers/create-customer.js +59 -9
  705. package/dist/api/routes/store/customers/create-customer.js.map +1 -1
  706. package/dist/api/routes/store/customers/delete-address.d.ts +2 -2
  707. package/dist/api/routes/store/customers/delete-address.js +13 -3
  708. package/dist/api/routes/store/customers/delete-address.js.map +1 -1
  709. package/dist/api/routes/store/customers/get-customer.d.ts +1 -1
  710. package/dist/api/routes/store/customers/get-payment-methods.d.ts +1 -1
  711. package/dist/api/routes/store/customers/index.js +5 -1
  712. package/dist/api/routes/store/customers/index.js.map +1 -1
  713. package/dist/api/routes/store/customers/list-orders.d.ts +12 -12
  714. package/dist/api/routes/store/customers/list-orders.js +13 -13
  715. package/dist/api/routes/store/customers/list-orders.js.map +1 -1
  716. package/dist/api/routes/store/customers/reset-password-token.d.ts +12 -3
  717. package/dist/api/routes/store/customers/reset-password-token.js +23 -6
  718. package/dist/api/routes/store/customers/reset-password-token.js.map +1 -1
  719. package/dist/api/routes/store/customers/reset-password.d.ts +22 -6
  720. package/dist/api/routes/store/customers/reset-password.js +35 -9
  721. package/dist/api/routes/store/customers/reset-password.js.map +1 -1
  722. package/dist/api/routes/store/customers/update-address.d.ts +3 -6
  723. package/dist/api/routes/store/customers/update-address.js +14 -7
  724. package/dist/api/routes/store/customers/update-address.js.map +1 -1
  725. package/dist/api/routes/store/customers/update-customer.d.ts +4 -1
  726. package/dist/api/routes/store/customers/update-customer.js +15 -2
  727. package/dist/api/routes/store/customers/update-customer.js.map +1 -1
  728. package/dist/api/routes/store/gift-cards/get-gift-card.d.ts +3 -11
  729. package/dist/api/routes/store/gift-cards/get-gift-card.js +2 -10
  730. package/dist/api/routes/store/gift-cards/get-gift-card.js.map +1 -1
  731. package/dist/api/routes/store/gift-cards/index.js +5 -1
  732. package/dist/api/routes/store/gift-cards/index.js.map +1 -1
  733. package/dist/api/routes/store/orders/get-order-by-cart.d.ts +2 -2
  734. package/dist/api/routes/store/orders/get-order-by-cart.js +1 -1
  735. package/dist/api/routes/store/orders/get-order-by-cart.js.map +1 -1
  736. package/dist/api/routes/store/orders/get-order.d.ts +3 -3
  737. package/dist/api/routes/store/orders/get-order.js +2 -2
  738. package/dist/api/routes/store/orders/get-order.js.map +1 -1
  739. package/dist/api/routes/store/orders/index.d.ts +1 -1
  740. package/dist/api/routes/store/orders/index.js +5 -1
  741. package/dist/api/routes/store/orders/index.js.map +1 -1
  742. package/dist/api/routes/store/orders/lookup-order.d.ts +22 -3
  743. package/dist/api/routes/store/orders/lookup-order.js +22 -3
  744. package/dist/api/routes/store/orders/lookup-order.js.map +1 -1
  745. package/dist/api/routes/store/products/get-product.d.ts +1 -1
  746. package/dist/api/routes/store/products/index.js +5 -1
  747. package/dist/api/routes/store/products/index.js.map +1 -1
  748. package/dist/api/routes/store/products/list-products.d.ts +91 -22
  749. package/dist/api/routes/store/products/list-products.js +96 -26
  750. package/dist/api/routes/store/products/list-products.js.map +1 -1
  751. package/dist/api/routes/store/products/search.d.ts +23 -0
  752. package/dist/api/routes/store/products/search.js +24 -1
  753. package/dist/api/routes/store/products/search.js.map +1 -1
  754. package/dist/api/routes/store/regions/get-region.d.ts +1 -1
  755. package/dist/api/routes/store/regions/index.js +5 -1
  756. package/dist/api/routes/store/regions/index.js.map +1 -1
  757. package/dist/api/routes/store/regions/list-regions.d.ts +48 -10
  758. package/dist/api/routes/store/regions/list-regions.js +49 -11
  759. package/dist/api/routes/store/regions/list-regions.js.map +1 -1
  760. package/dist/api/routes/store/return-reasons/get-reason.d.ts +1 -1
  761. package/dist/api/routes/store/return-reasons/index.d.ts +2 -2
  762. package/dist/api/routes/store/return-reasons/index.js +5 -1
  763. package/dist/api/routes/store/return-reasons/index.js.map +1 -1
  764. package/dist/api/routes/store/return-reasons/list-reasons.d.ts +1 -1
  765. package/dist/api/routes/store/returns/create-return.d.ts +18 -12
  766. package/dist/api/routes/store/returns/create-return.js +163 -112
  767. package/dist/api/routes/store/returns/create-return.js.map +1 -1
  768. package/dist/api/routes/store/returns/index.js +5 -1
  769. package/dist/api/routes/store/returns/index.js.map +1 -1
  770. package/dist/api/routes/store/shipping-options/index.js +5 -1
  771. package/dist/api/routes/store/shipping-options/index.js.map +1 -1
  772. package/dist/api/routes/store/shipping-options/list-options.d.ts +1 -1
  773. package/dist/api/routes/store/shipping-options/list-shipping-options.d.ts +1 -1
  774. package/dist/api/routes/store/shipping-options/list-shipping-options.js +7 -1
  775. package/dist/api/routes/store/shipping-options/list-shipping-options.js.map +1 -1
  776. package/dist/api/routes/store/swaps/create-swap.d.ts +9 -13
  777. package/dist/api/routes/store/swaps/create-swap.js +158 -113
  778. package/dist/api/routes/store/swaps/create-swap.js.map +1 -1
  779. package/dist/api/routes/store/swaps/get-swap-by-cart.d.ts +1 -1
  780. package/dist/api/routes/store/swaps/index.js +5 -1
  781. package/dist/api/routes/store/swaps/index.js.map +1 -1
  782. package/dist/api/routes/store/variants/get-variant.d.ts +13 -1
  783. package/dist/api/routes/store/variants/get-variant.js +13 -1
  784. package/dist/api/routes/store/variants/get-variant.js.map +1 -1
  785. package/dist/api/routes/store/variants/index.js +5 -1
  786. package/dist/api/routes/store/variants/index.js.map +1 -1
  787. package/dist/api/routes/store/variants/list-variants.d.ts +38 -3
  788. package/dist/api/routes/store/variants/list-variants.js +41 -6
  789. package/dist/api/routes/store/variants/list-variants.js.map +1 -1
  790. package/dist/controllers/customers/list-customers.js +2 -1
  791. package/dist/controllers/customers/list-customers.js.map +1 -1
  792. package/dist/index.js +5 -1
  793. package/dist/index.js.map +1 -1
  794. package/dist/interfaces/batch-job-strategy.d.ts +3 -3
  795. package/dist/interfaces/batch-job-strategy.js.map +1 -1
  796. package/dist/interfaces/cart-completion-strategy.d.ts +5 -2
  797. package/dist/interfaces/cart-completion-strategy.js +10 -5
  798. package/dist/interfaces/cart-completion-strategy.js.map +1 -1
  799. package/dist/interfaces/file-service.d.ts +3 -2
  800. package/dist/interfaces/file-service.js.map +1 -1
  801. package/dist/interfaces/index.d.ts +4 -0
  802. package/dist/interfaces/index.js +9 -1
  803. package/dist/interfaces/index.js.map +1 -1
  804. package/dist/interfaces/notification-service.d.ts +18 -0
  805. package/dist/interfaces/notification-service.js +40 -0
  806. package/dist/interfaces/notification-service.js.map +1 -0
  807. package/dist/interfaces/payment-service.d.ts +44 -0
  808. package/dist/interfaces/payment-service.js +43 -0
  809. package/dist/interfaces/payment-service.js.map +1 -0
  810. package/dist/interfaces/search-service.d.ts +78 -0
  811. package/dist/interfaces/search-service.js +42 -0
  812. package/dist/interfaces/search-service.js.map +1 -0
  813. package/dist/interfaces/transaction-base-service.d.ts +5 -5
  814. package/dist/interfaces/transaction-base-service.js +6 -7
  815. package/dist/interfaces/transaction-base-service.js.map +1 -1
  816. package/dist/loaders/defaults.d.ts +1 -1
  817. package/dist/loaders/defaults.js +15 -3
  818. package/dist/loaders/defaults.js.map +1 -1
  819. package/dist/loaders/feature-flags/index.d.ts +2 -2
  820. package/dist/loaders/feature-flags/index.js +22 -21
  821. package/dist/loaders/feature-flags/index.js.map +1 -1
  822. package/dist/loaders/feature-flags/sales-channels.d.ts +3 -0
  823. package/dist/loaders/feature-flags/sales-channels.js +10 -0
  824. package/dist/loaders/feature-flags/sales-channels.js.map +1 -0
  825. package/dist/loaders/index.d.ts +1 -1
  826. package/dist/loaders/index.js +14 -9
  827. package/dist/loaders/index.js.map +1 -1
  828. package/dist/loaders/models.d.ts +3 -3
  829. package/dist/loaders/plugins.d.ts +1 -1
  830. package/dist/loaders/plugins.js +23 -13
  831. package/dist/loaders/plugins.js.map +1 -1
  832. package/dist/loaders/repositories.d.ts +3 -3
  833. package/dist/loaders/search-index.d.ts +1 -0
  834. package/dist/loaders/search-index.js +7 -64
  835. package/dist/loaders/search-index.js.map +1 -1
  836. package/dist/loaders/services.d.ts +1 -1
  837. package/dist/loaders/services.js +2 -1
  838. package/dist/loaders/services.js.map +1 -1
  839. package/dist/loaders/strategies.d.ts +1 -1
  840. package/dist/loaders/strategies.js +2 -1
  841. package/dist/loaders/strategies.js.map +1 -1
  842. package/dist/loaders/subscribers.d.ts +3 -3
  843. package/dist/migrations/1649775522087-add_batch_job_model.js.map +1 -1
  844. package/dist/migrations/1656949291839-sales_channel.d.ts +7 -0
  845. package/dist/migrations/1656949291839-sales_channel.js +126 -0
  846. package/dist/migrations/1656949291839-sales_channel.js.map +1 -0
  847. package/dist/migrations/1657098186554-taxed_gift_card_transactions.d.ts +6 -0
  848. package/dist/{api/routes/admin/discounts/add-valid-product.js → migrations/1657098186554-taxed_gift_card_transactions.js} +39 -44
  849. package/dist/migrations/1657098186554-taxed_gift_card_transactions.js.map +1 -0
  850. package/dist/migrations/1657267320181-extended_batch_job.d.ts +6 -0
  851. package/dist/migrations/1657267320181-extended_batch_job.js +75 -0
  852. package/dist/migrations/1657267320181-extended_batch_job.js.map +1 -0
  853. package/dist/migrations/1660040729000-payment_session_uniq_cartId_providerId.d.ts +6 -0
  854. package/dist/{services/transaction.js → migrations/1660040729000-payment_session_uniq_cartId_providerId.js} +27 -30
  855. package/dist/migrations/1660040729000-payment_session_uniq_cartId_providerId.js.map +1 -0
  856. package/dist/models/address.d.ts +58 -2
  857. package/dist/models/address.js +59 -3
  858. package/dist/models/address.js.map +1 -1
  859. package/dist/models/batch-job.d.ts +87 -14
  860. package/dist/models/batch-job.js +88 -15
  861. package/dist/models/batch-job.js.map +1 -1
  862. package/dist/models/cart.d.ts +94 -4
  863. package/dist/models/cart.js +103 -4
  864. package/dist/models/cart.js.map +1 -1
  865. package/dist/models/claim-image.d.ts +16 -0
  866. package/dist/models/claim-image.js +17 -1
  867. package/dist/models/claim-image.js.map +1 -1
  868. package/dist/models/claim-item.d.ts +30 -6
  869. package/dist/models/claim-item.js +31 -7
  870. package/dist/models/claim-item.js.map +1 -1
  871. package/dist/models/claim-order.d.ts +36 -10
  872. package/dist/models/claim-order.js +36 -10
  873. package/dist/models/claim-order.js.map +1 -1
  874. package/dist/models/claim-tag.d.ts +11 -6
  875. package/dist/models/claim-tag.js +12 -7
  876. package/dist/models/claim-tag.js.map +1 -1
  877. package/dist/models/country.d.ts +46 -18
  878. package/dist/models/country.js +46 -18
  879. package/dist/models/country.js.map +1 -1
  880. package/dist/models/currency.d.ts +12 -0
  881. package/dist/models/currency.js +12 -0
  882. package/dist/models/currency.js.map +1 -1
  883. package/dist/models/custom-shipping-option.d.ts +23 -11
  884. package/dist/models/custom-shipping-option.js +24 -12
  885. package/dist/models/custom-shipping-option.js.map +1 -1
  886. package/dist/models/customer-group.d.ts +44 -0
  887. package/dist/models/customer-group.js +45 -1
  888. package/dist/models/customer-group.js.map +1 -1
  889. package/dist/models/customer.d.ts +39 -7
  890. package/dist/models/customer.js +40 -8
  891. package/dist/models/customer.js.map +1 -1
  892. package/dist/models/discount-condition-customer-group.d.ts +17 -9
  893. package/dist/models/discount-condition-customer-group.js +17 -9
  894. package/dist/models/discount-condition-customer-group.js.map +1 -1
  895. package/dist/models/discount-condition-product-collection.d.ts +17 -9
  896. package/dist/models/discount-condition-product-collection.js +17 -9
  897. package/dist/models/discount-condition-product-collection.js.map +1 -1
  898. package/dist/models/discount-condition-product-tag.d.ts +17 -9
  899. package/dist/models/discount-condition-product-tag.js +17 -9
  900. package/dist/models/discount-condition-product-tag.js.map +1 -1
  901. package/dist/models/discount-condition-product-type.d.ts +17 -9
  902. package/dist/models/discount-condition-product-type.js +17 -9
  903. package/dist/models/discount-condition-product-type.js.map +1 -1
  904. package/dist/models/discount-condition-product.d.ts +17 -9
  905. package/dist/models/discount-condition-product.js +17 -9
  906. package/dist/models/discount-condition-product.js.map +1 -1
  907. package/dist/models/discount-condition.d.ts +55 -6
  908. package/dist/models/discount-condition.js +56 -7
  909. package/dist/models/discount-condition.js.map +1 -1
  910. package/dist/models/discount-rule.d.ts +18 -8
  911. package/dist/models/discount-rule.js +18 -8
  912. package/dist/models/discount-rule.js.map +1 -1
  913. package/dist/models/discount.d.ts +34 -11
  914. package/dist/models/discount.js +34 -11
  915. package/dist/models/discount.js.map +1 -1
  916. package/dist/models/draft-order.d.ts +35 -12
  917. package/dist/models/draft-order.js +37 -14
  918. package/dist/models/draft-order.js.map +1 -1
  919. package/dist/models/fulfillment-item.d.ts +12 -3
  920. package/dist/models/fulfillment-item.js +12 -3
  921. package/dist/models/fulfillment-item.js.map +1 -1
  922. package/dist/models/fulfillment-provider.d.ts +2 -0
  923. package/dist/models/fulfillment-provider.js +2 -0
  924. package/dist/models/fulfillment-provider.js.map +1 -1
  925. package/dist/models/fulfillment.d.ts +46 -11
  926. package/dist/models/fulfillment.js +46 -11
  927. package/dist/models/fulfillment.js.map +1 -1
  928. package/dist/models/gift-card-transaction.d.ts +25 -6
  929. package/dist/models/gift-card-transaction.js +32 -7
  930. package/dist/models/gift-card-transaction.js.map +1 -1
  931. package/dist/models/gift-card.d.ts +26 -11
  932. package/dist/models/gift-card.js +26 -11
  933. package/dist/models/gift-card.js.map +1 -1
  934. package/dist/models/idempotency-key.d.ts +53 -0
  935. package/dist/models/idempotency-key.js +53 -0
  936. package/dist/models/idempotency-key.js.map +1 -1
  937. package/dist/models/image.d.ts +11 -6
  938. package/dist/models/image.js +12 -7
  939. package/dist/models/image.js.map +1 -1
  940. package/dist/models/index.d.ts +2 -0
  941. package/dist/models/index.js +7 -1
  942. package/dist/models/index.js.map +1 -1
  943. package/dist/models/invite.d.ts +53 -1
  944. package/dist/models/invite.js +53 -1
  945. package/dist/models/invite.js.map +1 -1
  946. package/dist/models/line-item-adjustment.d.ts +41 -0
  947. package/dist/models/line-item-adjustment.js +41 -0
  948. package/dist/models/line-item-adjustment.js.map +1 -1
  949. package/dist/models/line-item-tax-line.d.ts +47 -1
  950. package/dist/models/line-item-tax-line.js +47 -1
  951. package/dist/models/line-item-tax-line.js.map +1 -1
  952. package/dist/models/line-item.d.ts +98 -17
  953. package/dist/models/line-item.js +98 -17
  954. package/dist/models/line-item.js.map +1 -1
  955. package/dist/models/money-amount.d.ts +38 -9
  956. package/dist/models/money-amount.js +38 -9
  957. package/dist/models/money-amount.js.map +1 -1
  958. package/dist/models/note.d.ts +22 -10
  959. package/dist/models/note.js +23 -11
  960. package/dist/models/note.js.map +1 -1
  961. package/dist/models/notification-provider.d.ts +4 -0
  962. package/dist/models/notification-provider.js +4 -0
  963. package/dist/models/notification-provider.js.map +1 -1
  964. package/dist/models/notification.d.ts +50 -18
  965. package/dist/models/notification.js +51 -19
  966. package/dist/models/notification.js.map +1 -1
  967. package/dist/models/oauth.d.ts +35 -0
  968. package/dist/models/oauth.js +35 -0
  969. package/dist/models/oauth.js.map +1 -1
  970. package/dist/models/order.d.ts +144 -49
  971. package/dist/models/order.js +155 -49
  972. package/dist/models/order.js.map +1 -1
  973. package/dist/models/payment-provider.d.ts +4 -0
  974. package/dist/models/payment-provider.js +4 -0
  975. package/dist/models/payment-provider.js.map +1 -1
  976. package/dist/models/payment-session.d.ts +23 -4
  977. package/dist/models/payment-session.js +28 -8
  978. package/dist/models/payment-session.js.map +1 -1
  979. package/dist/models/payment.d.ts +47 -13
  980. package/dist/models/payment.js +47 -13
  981. package/dist/models/payment.js.map +1 -1
  982. package/dist/models/price-list.d.ts +36 -8
  983. package/dist/models/price-list.js +37 -9
  984. package/dist/models/price-list.js.map +1 -1
  985. package/dist/models/product-collection.d.ts +13 -6
  986. package/dist/models/product-collection.js +15 -8
  987. package/dist/models/product-collection.js.map +1 -1
  988. package/dist/models/product-option-value.d.ts +22 -7
  989. package/dist/models/product-option-value.js +23 -8
  990. package/dist/models/product-option-value.js.map +1 -1
  991. package/dist/models/product-option.d.ts +17 -7
  992. package/dist/models/product-option.js +18 -8
  993. package/dist/models/product-option.js.map +1 -1
  994. package/dist/models/product-tag.d.ts +11 -6
  995. package/dist/models/product-tag.js +12 -7
  996. package/dist/models/product-tag.js.map +1 -1
  997. package/dist/models/product-tax-rate.d.ts +17 -9
  998. package/dist/models/product-tax-rate.js +17 -9
  999. package/dist/models/product-tax-rate.js.map +1 -1
  1000. package/dist/models/product-type-tax-rate.d.ts +16 -8
  1001. package/dist/models/product-type-tax-rate.js +16 -8
  1002. package/dist/models/product-type-tax-rate.js.map +1 -1
  1003. package/dist/models/product-type.d.ts +11 -6
  1004. package/dist/models/product-type.js +12 -7
  1005. package/dist/models/product-type.js.map +1 -1
  1006. package/dist/models/product-variant.d.ts +43 -13
  1007. package/dist/models/product-variant.js +44 -14
  1008. package/dist/models/product-variant.js.map +1 -1
  1009. package/dist/models/product.d.ts +80 -30
  1010. package/dist/models/product.js +98 -31
  1011. package/dist/models/product.js.map +1 -1
  1012. package/dist/models/refund.d.ts +23 -4
  1013. package/dist/models/refund.js +23 -4
  1014. package/dist/models/refund.js.map +1 -1
  1015. package/dist/models/region.d.ts +49 -13
  1016. package/dist/models/region.js +50 -14
  1017. package/dist/models/region.js.map +1 -1
  1018. package/dist/models/return-item.d.ts +25 -9
  1019. package/dist/models/return-item.js +25 -9
  1020. package/dist/models/return-item.js.map +1 -1
  1021. package/dist/models/return-reason.d.ts +25 -7
  1022. package/dist/models/return-reason.js +26 -8
  1023. package/dist/models/return-reason.js.map +1 -1
  1024. package/dist/models/return.d.ts +45 -17
  1025. package/dist/models/return.js +45 -17
  1026. package/dist/models/return.js.map +1 -1
  1027. package/dist/models/sales-channel.d.ts +44 -0
  1028. package/dist/models/sales-channel.js +101 -0
  1029. package/dist/models/sales-channel.js.map +1 -0
  1030. package/dist/models/shipping-method-tax-line.d.ts +47 -1
  1031. package/dist/models/shipping-method-tax-line.js +47 -1
  1032. package/dist/models/shipping-method-tax-line.js.map +1 -1
  1033. package/dist/models/shipping-method.d.ts +38 -7
  1034. package/dist/models/shipping-method.js +39 -8
  1035. package/dist/models/shipping-method.js.map +1 -1
  1036. package/dist/models/shipping-option-requirement.d.ts +17 -2
  1037. package/dist/models/shipping-option-requirement.js +17 -2
  1038. package/dist/models/shipping-option-requirement.js.map +1 -1
  1039. package/dist/models/shipping-option.d.ts +34 -13
  1040. package/dist/models/shipping-option.js +34 -13
  1041. package/dist/models/shipping-option.js.map +1 -1
  1042. package/dist/models/shipping-profile.d.ts +18 -11
  1043. package/dist/models/shipping-profile.js +18 -11
  1044. package/dist/models/shipping-profile.js.map +1 -1
  1045. package/dist/models/shipping-tax-rate.d.ts +17 -9
  1046. package/dist/models/shipping-tax-rate.js +17 -9
  1047. package/dist/models/shipping-tax-rate.js.map +1 -1
  1048. package/dist/models/staged-job.d.ts +21 -0
  1049. package/dist/models/staged-job.js +21 -0
  1050. package/dist/models/staged-job.js.map +1 -1
  1051. package/dist/models/store.d.ts +32 -11
  1052. package/dist/models/store.js +43 -12
  1053. package/dist/models/store.js.map +1 -1
  1054. package/dist/models/swap.d.ts +59 -30
  1055. package/dist/models/swap.js +59 -30
  1056. package/dist/models/swap.js.map +1 -1
  1057. package/dist/models/tax-line.d.ts +12 -4
  1058. package/dist/models/tax-line.js +13 -5
  1059. package/dist/models/tax-line.js.map +1 -1
  1060. package/dist/models/tax-provider.d.ts +2 -0
  1061. package/dist/models/tax-provider.js +2 -0
  1062. package/dist/models/tax-provider.js.map +1 -1
  1063. package/dist/models/tax-rate.d.ts +49 -10
  1064. package/dist/models/tax-rate.js +49 -10
  1065. package/dist/models/tax-rate.js.map +1 -1
  1066. package/dist/models/tracking-link.d.ts +22 -5
  1067. package/dist/models/tracking-link.js +23 -6
  1068. package/dist/models/tracking-link.js.map +1 -1
  1069. package/dist/models/user.d.ts +19 -4
  1070. package/dist/models/user.js +19 -4
  1071. package/dist/models/user.js.map +1 -1
  1072. package/dist/repositories/claim.js.map +1 -1
  1073. package/dist/repositories/order.d.ts +3 -3
  1074. package/dist/repositories/order.js +2 -2
  1075. package/dist/repositories/order.js.map +1 -1
  1076. package/dist/repositories/price-list.js.map +1 -1
  1077. package/dist/repositories/product.d.ts +2 -2
  1078. package/dist/repositories/product.js +19 -11
  1079. package/dist/repositories/product.js.map +1 -1
  1080. package/dist/repositories/sales-channel.d.ts +8 -0
  1081. package/dist/repositories/sales-channel.js +154 -0
  1082. package/dist/repositories/sales-channel.js.map +1 -0
  1083. package/dist/repositories/tax-rate.js +3 -2
  1084. package/dist/repositories/tax-rate.js.map +1 -1
  1085. package/dist/scripts/sales-channels-migration.d.ts +4 -0
  1086. package/dist/scripts/sales-channels-migration.js +144 -0
  1087. package/dist/scripts/sales-channels-migration.js.map +1 -0
  1088. package/dist/services/auth.d.ts +1 -1
  1089. package/dist/services/auth.js.map +1 -1
  1090. package/dist/services/batch-job.d.ts +1 -1
  1091. package/dist/services/batch-job.js +18 -32
  1092. package/dist/services/batch-job.js.map +1 -1
  1093. package/dist/services/cart.d.ts +39 -12
  1094. package/dist/services/cart.js +361 -216
  1095. package/dist/services/cart.js.map +1 -1
  1096. package/dist/services/claim-item.d.ts +1 -1
  1097. package/dist/services/claim-item.js.map +1 -1
  1098. package/dist/services/claim.d.ts +1 -1
  1099. package/dist/services/claim.js +64 -98
  1100. package/dist/services/claim.js.map +1 -1
  1101. package/dist/services/custom-shipping-option.d.ts +1 -1
  1102. package/dist/services/custom-shipping-option.js +28 -53
  1103. package/dist/services/custom-shipping-option.js.map +1 -1
  1104. package/dist/services/customer-group.js +3 -2
  1105. package/dist/services/customer-group.js.map +1 -1
  1106. package/dist/services/customer.d.ts +1 -1
  1107. package/dist/services/customer.js +35 -80
  1108. package/dist/services/customer.js.map +1 -1
  1109. package/dist/services/discount-condition.d.ts +1 -1
  1110. package/dist/services/discount-condition.js +12 -19
  1111. package/dist/services/discount-condition.js.map +1 -1
  1112. package/dist/services/discount.d.ts +1 -1
  1113. package/dist/services/discount.js +67 -91
  1114. package/dist/services/discount.js.map +1 -1
  1115. package/dist/services/draft-order.d.ts +1 -1
  1116. package/dist/services/draft-order.js +66 -104
  1117. package/dist/services/draft-order.js.map +1 -1
  1118. package/dist/services/event-bus.js +1 -1
  1119. package/dist/services/event-bus.js.map +1 -1
  1120. package/dist/services/file.d.ts +1 -1
  1121. package/dist/services/file.js.map +1 -1
  1122. package/dist/services/fulfillment.d.ts +2 -2
  1123. package/dist/services/fulfillment.js +17 -24
  1124. package/dist/services/fulfillment.js.map +1 -1
  1125. package/dist/services/gift-card.d.ts +1 -1
  1126. package/dist/services/gift-card.js +68 -117
  1127. package/dist/services/gift-card.js.map +1 -1
  1128. package/dist/services/idempotency-key.d.ts +42 -32
  1129. package/dist/services/idempotency-key.js +125 -124
  1130. package/dist/services/idempotency-key.js.map +1 -1
  1131. package/dist/services/index.d.ts +1 -0
  1132. package/dist/services/index.js +3 -1
  1133. package/dist/services/index.js.map +1 -1
  1134. package/dist/services/inventory.d.ts +22 -21
  1135. package/dist/services/inventory.js +57 -55
  1136. package/dist/services/inventory.js.map +1 -1
  1137. package/dist/services/line-item.js +19 -33
  1138. package/dist/services/line-item.js.map +1 -1
  1139. package/dist/services/middleware.d.ts +24 -17
  1140. package/dist/services/middleware.js +5 -5
  1141. package/dist/services/middleware.js.map +1 -1
  1142. package/dist/services/note.d.ts +43 -48
  1143. package/dist/services/note.js +106 -118
  1144. package/dist/services/note.js.map +1 -1
  1145. package/dist/services/notification.d.ts +54 -51
  1146. package/dist/services/notification.js +118 -113
  1147. package/dist/services/notification.js.map +1 -1
  1148. package/dist/services/oauth.d.ts +30 -16
  1149. package/dist/services/oauth.js +121 -40
  1150. package/dist/services/oauth.js.map +1 -1
  1151. package/dist/services/order.d.ts +163 -184
  1152. package/dist/services/order.js +1250 -1323
  1153. package/dist/services/order.js.map +1 -1
  1154. package/dist/services/payment-provider.d.ts +67 -47
  1155. package/dist/services/payment-provider.js +385 -335
  1156. package/dist/services/payment-provider.js.map +1 -1
  1157. package/dist/services/price-list.d.ts +1 -1
  1158. package/dist/services/price-list.js +38 -49
  1159. package/dist/services/price-list.js.map +1 -1
  1160. package/dist/services/pricing.d.ts +1 -1
  1161. package/dist/services/pricing.js +32 -35
  1162. package/dist/services/pricing.js.map +1 -1
  1163. package/dist/services/product-collection.d.ts +53 -48
  1164. package/dist/services/product-collection.js +157 -155
  1165. package/dist/services/product-collection.js.map +1 -1
  1166. package/dist/services/product-variant.js +2 -1
  1167. package/dist/services/product-variant.js.map +1 -1
  1168. package/dist/services/product.d.ts +7 -4
  1169. package/dist/services/product.js +180 -187
  1170. package/dist/services/product.js.map +1 -1
  1171. package/dist/services/return-reason.d.ts +21 -18
  1172. package/dist/services/return-reason.js +84 -64
  1173. package/dist/services/return-reason.js.map +1 -1
  1174. package/dist/services/return.js +8 -10
  1175. package/dist/services/return.js.map +1 -1
  1176. package/dist/services/sales-channel.d.ts +79 -0
  1177. package/dist/services/sales-channel.js +405 -0
  1178. package/dist/services/sales-channel.js.map +1 -0
  1179. package/dist/services/search.d.ts +23 -19
  1180. package/dist/services/search.js +10 -9
  1181. package/dist/services/search.js.map +1 -1
  1182. package/dist/services/shipping-option.d.ts +2 -2
  1183. package/dist/services/shipping-option.js +85 -93
  1184. package/dist/services/shipping-option.js.map +1 -1
  1185. package/dist/services/shipping-profile.d.ts +67 -74
  1186. package/dist/services/shipping-profile.js +351 -382
  1187. package/dist/services/shipping-profile.js.map +1 -1
  1188. package/dist/services/store.d.ts +6 -6
  1189. package/dist/services/store.js +13 -20
  1190. package/dist/services/store.js.map +1 -1
  1191. package/dist/services/strategy-resolver.d.ts +3 -2
  1192. package/dist/services/strategy-resolver.js +1 -0
  1193. package/dist/services/strategy-resolver.js.map +1 -1
  1194. package/dist/services/swap.js +51 -52
  1195. package/dist/services/swap.js.map +1 -1
  1196. package/dist/services/system-payment-provider.d.ts +2 -3
  1197. package/dist/services/system-payment-provider.js +3 -3
  1198. package/dist/services/system-payment-provider.js.map +1 -1
  1199. package/dist/services/tax-provider.d.ts +18 -19
  1200. package/dist/services/tax-provider.js +81 -61
  1201. package/dist/services/tax-provider.js.map +1 -1
  1202. package/dist/services/tax-rate.js +25 -47
  1203. package/dist/services/tax-rate.js.map +1 -1
  1204. package/dist/services/totals.d.ts +19 -5
  1205. package/dist/services/totals.js +102 -23
  1206. package/dist/services/totals.js.map +1 -1
  1207. package/dist/services/user.d.ts +4 -1
  1208. package/dist/services/user.js +67 -75
  1209. package/dist/services/user.js.map +1 -1
  1210. package/dist/strategies/__fixtures__/order-export-data.js +11 -0
  1211. package/dist/strategies/__fixtures__/order-export-data.js.map +1 -1
  1212. package/dist/strategies/__fixtures__/product-export-data.d.ts +10 -0
  1213. package/dist/strategies/__fixtures__/product-export-data.js +7 -0
  1214. package/dist/strategies/__fixtures__/product-export-data.js.map +1 -1
  1215. package/dist/strategies/batch-jobs/order/export.d.ts +12 -6
  1216. package/dist/strategies/batch-jobs/order/export.js +53 -26
  1217. package/dist/strategies/batch-jobs/order/export.js.map +1 -1
  1218. package/dist/strategies/batch-jobs/order/index.js +1 -1
  1219. package/dist/strategies/batch-jobs/order/index.js.map +1 -1
  1220. package/dist/strategies/batch-jobs/product/export.d.ts +17 -4
  1221. package/dist/strategies/batch-jobs/product/export.js +193 -101
  1222. package/dist/strategies/batch-jobs/product/export.js.map +1 -1
  1223. package/dist/strategies/batch-jobs/product/index.d.ts +1 -0
  1224. package/dist/strategies/batch-jobs/product/index.js.map +1 -1
  1225. package/dist/strategies/cart-completion.d.ts +21 -13
  1226. package/dist/strategies/cart-completion.js +300 -217
  1227. package/dist/strategies/cart-completion.js.map +1 -1
  1228. package/dist/strategies/price-selection.js +2 -2
  1229. package/dist/strategies/price-selection.js.map +1 -1
  1230. package/dist/strategies/tax-calculation.js +0 -4
  1231. package/dist/strategies/tax-calculation.js.map +1 -1
  1232. package/dist/subscribers/batch-job.js +1 -1
  1233. package/dist/subscribers/batch-job.js.map +1 -1
  1234. package/dist/subscribers/notification.js +1 -1
  1235. package/dist/subscribers/notification.js.map +1 -1
  1236. package/dist/subscribers/order.js +1 -1
  1237. package/dist/subscribers/order.js.map +1 -1
  1238. package/dist/subscribers/product.js +1 -1
  1239. package/dist/subscribers/product.js.map +1 -1
  1240. package/dist/subscribers/search-indexing.d.ts +18 -0
  1241. package/dist/subscribers/search-indexing.js +126 -0
  1242. package/dist/subscribers/search-indexing.js.map +1 -0
  1243. package/dist/types/cart.d.ts +7 -4
  1244. package/dist/types/common.d.ts +13 -2
  1245. package/dist/types/common.js +69 -1
  1246. package/dist/types/common.js.map +1 -1
  1247. package/dist/types/feature-flags.d.ts +5 -0
  1248. package/dist/types/gift-card.d.ts +3 -1
  1249. package/dist/types/global.d.ts +6 -1
  1250. package/dist/types/idempotency-key.d.ts +6 -0
  1251. package/dist/types/idempotency-key.js +3 -0
  1252. package/dist/types/idempotency-key.js.map +1 -0
  1253. package/dist/types/oauth.d.ts +9 -0
  1254. package/dist/types/oauth.js +3 -0
  1255. package/dist/types/oauth.js.map +1 -0
  1256. package/dist/types/orders.d.ts +80 -3
  1257. package/dist/types/orders.js +8 -2
  1258. package/dist/types/orders.js.map +1 -1
  1259. package/dist/types/product-collection.d.ts +10 -0
  1260. package/dist/types/product-collection.js +3 -0
  1261. package/dist/types/product-collection.js.map +1 -0
  1262. package/dist/types/product.d.ts +16 -0
  1263. package/dist/types/product.js +46 -1
  1264. package/dist/types/product.js.map +1 -1
  1265. package/dist/types/return-reason.d.ts +13 -0
  1266. package/dist/types/return-reason.js +3 -0
  1267. package/dist/types/return-reason.js.map +1 -0
  1268. package/dist/types/sales-channels.d.ts +9 -0
  1269. package/dist/types/sales-channels.js +24 -0
  1270. package/dist/types/sales-channels.js.map +1 -0
  1271. package/dist/types/shipping-options.d.ts +1 -0
  1272. package/dist/types/shipping-profile.d.ts +11 -0
  1273. package/dist/types/shipping-profile.js +3 -0
  1274. package/dist/types/shipping-profile.js.map +1 -0
  1275. package/dist/types/store.d.ts +1 -0
  1276. package/dist/utils/feature-flag-decorators.d.ts +1 -1
  1277. package/dist/utils/feature-flag-decorators.js +34 -19
  1278. package/dist/utils/feature-flag-decorators.js.map +1 -1
  1279. package/dist/utils/flag-router.d.ts +2 -1
  1280. package/dist/utils/flag-router.js +25 -0
  1281. package/dist/utils/flag-router.js.map +1 -1
  1282. package/dist/utils/get-query-config.js +11 -9
  1283. package/dist/utils/get-query-config.js.map +1 -1
  1284. package/dist/utils/index.d.ts +6 -4
  1285. package/dist/utils/index.js +7 -1
  1286. package/dist/utils/index.js.map +1 -1
  1287. package/dist/utils/is-defined.d.ts +1 -0
  1288. package/dist/utils/is-defined.js +8 -0
  1289. package/dist/utils/is-defined.js.map +1 -0
  1290. package/dist/utils/remove-undefined-properties.d.ts +1 -0
  1291. package/dist/utils/remove-undefined-properties.js +47 -0
  1292. package/dist/utils/remove-undefined-properties.js.map +1 -0
  1293. package/jest.config.js +6 -5
  1294. package/package.json +8 -11
  1295. package/setupTests.js +3 -0
  1296. package/LICENSE +0 -21
  1297. package/dist/api/routes/admin/discounts/add-valid-product.d.ts +0 -23
  1298. package/dist/api/routes/admin/discounts/add-valid-product.js.map +0 -1
  1299. package/dist/api/routes/admin/discounts/remove-valid-product.d.ts +0 -23
  1300. package/dist/api/routes/admin/discounts/remove-valid-product.js +0 -82
  1301. package/dist/api/routes/admin/discounts/remove-valid-product.js.map +0 -1
  1302. package/dist/api/routes/admin/orders/create-order.d.ts +0 -123
  1303. package/dist/api/routes/admin/orders/create-order.js +0 -278
  1304. package/dist/api/routes/admin/orders/create-order.js.map +0 -1
  1305. package/dist/api/routes/admin/orders/delete-metadata.d.ts +0 -23
  1306. package/dist/api/routes/admin/orders/delete-metadata.js.map +0 -1
  1307. package/dist/api/routes/admin/products/get-variants.d.ts +0 -24
  1308. package/dist/api/routes/admin/products/get-variants.js.map +0 -1
  1309. package/dist/api/routes/admin/regions/delete-metadata.d.ts +0 -23
  1310. package/dist/api/routes/admin/regions/delete-metadata.js +0 -82
  1311. package/dist/api/routes/admin/regions/delete-metadata.js.map +0 -1
  1312. package/dist/api/routes/admin/regions/set-metadata.d.ts +0 -28
  1313. package/dist/api/routes/admin/regions/set-metadata.js.map +0 -1
  1314. package/dist/api/routes/store/carts/update-payment-method.d.ts +0 -38
  1315. package/dist/api/routes/store/carts/update-payment-method.js.map +0 -1
  1316. package/dist/config/index.d.ts +0 -14
  1317. package/dist/config/index.js +0 -40
  1318. package/dist/config/index.js.map +0 -1
  1319. package/dist/controllers/products/admin-list-products.d.ts +0 -16
  1320. package/dist/controllers/products/admin-list-products.js +0 -111
  1321. package/dist/controllers/products/admin-list-products.js.map +0 -1
  1322. package/dist/interfaces/base-service.d.ts +0 -66
  1323. package/dist/interfaces/base-service.js +0 -377
  1324. package/dist/interfaces/base-service.js.map +0 -1
  1325. package/dist/scripts/mongo-sql-migration.d.ts +0 -2
  1326. package/dist/scripts/mongo-sql-migration.js +0 -1603
  1327. package/dist/scripts/mongo-sql-migration.js.map +0 -1
  1328. package/dist/services/transaction.d.ts +0 -6
  1329. package/dist/services/transaction.js.map +0 -1
@@ -110,94 +110,48 @@ var __values = (this && this.__values) || function(o) {
110
110
  };
111
111
  Object.defineProperty(exports, "__esModule", { value: true });
112
112
  var medusa_core_utils_1 = require("medusa-core-utils");
113
- var medusa_interfaces_1 = require("medusa-interfaces");
114
113
  var typeorm_1 = require("typeorm");
114
+ var interfaces_1 = require("../interfaces");
115
+ var models_1 = require("../models");
116
+ var utils_1 = require("../utils");
115
117
  var OrderService = /** @class */ (function (_super) {
116
118
  __extends(OrderService, _super);
117
119
  function OrderService(_a) {
118
120
  var manager = _a.manager, orderRepository = _a.orderRepository, customerService = _a.customerService, paymentProviderService = _a.paymentProviderService, shippingOptionService = _a.shippingOptionService, shippingProfileService = _a.shippingProfileService, discountService = _a.discountService, fulfillmentProviderService = _a.fulfillmentProviderService, fulfillmentService = _a.fulfillmentService, lineItemService = _a.lineItemService, totalsService = _a.totalsService, regionService = _a.regionService, cartService = _a.cartService, addressRepository = _a.addressRepository, giftCardService = _a.giftCardService, draftOrderService = _a.draftOrderService, inventoryService = _a.inventoryService, eventBusService = _a.eventBusService;
119
- var _this = _super.call(this) || this;
120
- /** @private @constant {EntityManager} */
121
+ var _this =
122
+ // eslint-disable-next-line prefer-rest-params
123
+ _super.call(this, arguments[0]) || this;
121
124
  _this.manager_ = manager;
122
- /** @private @constant {OrderRepository} */
123
125
  _this.orderRepository_ = orderRepository;
124
- /** @private @constant {CustomerService} */
125
126
  _this.customerService_ = customerService;
126
- /** @private @constant {PaymentProviderService} */
127
127
  _this.paymentProviderService_ = paymentProviderService;
128
- /** @private @constant {ShippingProvileService} */
129
128
  _this.shippingProfileService_ = shippingProfileService;
130
- /** @private @constant {FulfillmentProviderService} */
131
129
  _this.fulfillmentProviderService_ = fulfillmentProviderService;
132
- /** @private @constant {LineItemService} */
133
130
  _this.lineItemService_ = lineItemService;
134
- /** @private @constant {TotalsService} */
135
131
  _this.totalsService_ = totalsService;
136
- /** @private @constant {RegionService} */
137
132
  _this.regionService_ = regionService;
138
- /** @private @constant {FulfillmentService} */
139
133
  _this.fulfillmentService_ = fulfillmentService;
140
- /** @private @constant {DiscountService} */
141
134
  _this.discountService_ = discountService;
142
- /** @private @constant {DiscountService} */
143
135
  _this.giftCardService_ = giftCardService;
144
- /** @private @constant {EventBus} */
145
136
  _this.eventBus_ = eventBusService;
146
- /** @private @constant {ShippingOptionService} */
147
137
  _this.shippingOptionService_ = shippingOptionService;
148
- /** @private @constant {CartService} */
149
138
  _this.cartService_ = cartService;
150
- /** @private @constant {AddressRepository} */
151
139
  _this.addressRepository_ = addressRepository;
152
- /** @private @constant {DraftOrderService} */
153
140
  _this.draftOrderService_ = draftOrderService;
154
- /** @private @constant {InventoryService} */
155
141
  _this.inventoryService_ = inventoryService;
156
142
  return _this;
157
143
  }
158
- OrderService.prototype.withTransaction = function (manager) {
159
- if (!manager) {
160
- return this;
161
- }
162
- var cloned = new OrderService({
163
- manager: manager,
164
- orderRepository: this.orderRepository_,
165
- eventBusService: this.eventBus_,
166
- paymentProviderService: this.paymentProviderService_,
167
- regionService: this.regionService_,
168
- lineItemService: this.lineItemService_,
169
- shippingOptionService: this.shippingOptionService_,
170
- shippingProfileService: this.shippingProfileService_,
171
- fulfillmentProviderService: this.fulfillmentProviderService_,
172
- fulfillmentService: this.fulfillmentService_,
173
- customerService: this.customerService_,
174
- discountService: this.discountService_,
175
- totalsService: this.totalsService_,
176
- cartService: this.cartService_,
177
- giftCardService: this.giftCardService_,
178
- addressRepository: this.addressRepository_,
179
- draftOrderService: this.draftOrderService_,
180
- inventoryService: this.inventoryService_,
181
- });
182
- cloned.transactionManager_ = manager;
183
- cloned.manager_ = manager;
184
- return cloned;
185
- };
186
144
  /**
187
- * Used to validate order ids. Throws an error if the cast fails
188
- * @param {string} rawId - the raw order id to validate.
189
- * @return {string} the validated id
190
- */
191
- OrderService.prototype.validateId_ = function (rawId) {
192
- return rawId;
193
- };
194
- /**
195
- * @param {Object} selector - the query object for find
196
- * @param {Object} config - the config to be used for find
197
- * @return {Promise} the result of the find operation
145
+ * @param selector the query object for find
146
+ * @param config the config to be used for find
147
+ * @return the result of the find operation
198
148
  */
199
149
  OrderService.prototype.list = function (selector, config) {
200
- if (config === void 0) { config = { skip: 0, take: 50, order: { created_at: "DESC" } }; }
150
+ if (config === void 0) { config = {
151
+ skip: 0,
152
+ take: 50,
153
+ order: { created_at: "DESC" },
154
+ }; }
201
155
  return __awaiter(this, void 0, void 0, function () {
202
156
  var orderRepo, query, _a, select, relations, totalsToSelect, raw;
203
157
  var _this = this;
@@ -205,8 +159,8 @@ var OrderService = /** @class */ (function (_super) {
205
159
  switch (_b.label) {
206
160
  case 0:
207
161
  orderRepo = this.manager_.getCustomRepository(this.orderRepository_);
208
- query = this.buildQuery_(selector, config);
209
- _a = this.transformQueryForTotals_(config), select = _a.select, relations = _a.relations, totalsToSelect = _a.totalsToSelect;
162
+ query = (0, utils_1.buildQuery)(selector, config);
163
+ _a = this.transformQueryForTotals(config), select = _a.select, relations = _a.relations, totalsToSelect = _a.totalsToSelect;
210
164
  if (select && select.length) {
211
165
  query.select = select;
212
166
  }
@@ -218,7 +172,7 @@ var OrderService = /** @class */ (function (_super) {
218
172
  raw = _b.sent();
219
173
  return [4 /*yield*/, Promise.all(raw.map(function (r) { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) {
220
174
  switch (_a.label) {
221
- case 0: return [4 /*yield*/, this.decorateTotals_(r, totalsToSelect)];
175
+ case 0: return [4 /*yield*/, this.decorateTotals(r, totalsToSelect)];
222
176
  case 1: return [2 /*return*/, _a.sent()];
223
177
  }
224
178
  }); }); }))];
@@ -228,7 +182,11 @@ var OrderService = /** @class */ (function (_super) {
228
182
  });
229
183
  };
230
184
  OrderService.prototype.listAndCount = function (selector, config) {
231
- if (config === void 0) { config = { skip: 0, take: 50, order: { created_at: "DESC" } }; }
185
+ if (config === void 0) { config = {
186
+ skip: 0,
187
+ take: 50,
188
+ order: { created_at: "DESC" },
189
+ }; }
232
190
  return __awaiter(this, void 0, void 0, function () {
233
191
  var orderRepo, q, query, where_1, _a, select, relations, totalsToSelect, rels, raw, count, orders;
234
192
  var _this = this;
@@ -240,7 +198,7 @@ var OrderService = /** @class */ (function (_super) {
240
198
  q = selector.q;
241
199
  delete selector.q;
242
200
  }
243
- query = this.buildQuery_(selector, config);
201
+ query = (0, utils_1.buildQuery)(selector, config);
244
202
  if (q) {
245
203
  where_1 = query.where;
246
204
  delete where_1.display_id;
@@ -262,7 +220,7 @@ var OrderService = /** @class */ (function (_super) {
262
220
  }));
263
221
  };
264
222
  }
265
- _a = this.transformQueryForTotals_(config), select = _a.select, relations = _a.relations, totalsToSelect = _a.totalsToSelect;
223
+ _a = this.transformQueryForTotals(config), select = _a.select, relations = _a.relations, totalsToSelect = _a.totalsToSelect;
266
224
  if (select && select.length) {
267
225
  query.select = select;
268
226
  }
@@ -276,7 +234,7 @@ var OrderService = /** @class */ (function (_super) {
276
234
  count = _b.sent();
277
235
  return [4 /*yield*/, Promise.all(raw.map(function (r) { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) {
278
236
  switch (_a.label) {
279
- case 0: return [4 /*yield*/, this.decorateTotals_(r, totalsToSelect)];
237
+ case 0: return [4 /*yield*/, this.decorateTotals(r, totalsToSelect)];
280
238
  case 1: return [2 /*return*/, _a.sent()];
281
239
  }
282
240
  }); }); }))];
@@ -287,7 +245,7 @@ var OrderService = /** @class */ (function (_super) {
287
245
  });
288
246
  });
289
247
  };
290
- OrderService.prototype.transformQueryForTotals_ = function (config) {
248
+ OrderService.prototype.transformQueryForTotals = function (config) {
291
249
  var select = config.select, relations = config.relations;
292
250
  if (!select) {
293
251
  return {
@@ -347,22 +305,21 @@ var OrderService = /** @class */ (function (_super) {
347
305
  };
348
306
  /**
349
307
  * Gets an order by id.
350
- * @param {string} orderId - id of order to retrieve
351
- * @param {Object} config - config of order to retrieve
352
- * @return {Promise<Order>} the order document
308
+ * @param orderId - id of order to retrieve
309
+ * @param config - config of order to retrieve
310
+ * @return the order document
353
311
  */
354
312
  OrderService.prototype.retrieve = function (orderId, config) {
355
313
  if (config === void 0) { config = {}; }
356
314
  return __awaiter(this, void 0, void 0, function () {
357
- var orderRepo, validatedId, _a, select, relations, totalsToSelect, query, rels, raw;
315
+ var orderRepo, _a, select, relations, totalsToSelect, query, rels, raw;
358
316
  return __generator(this, function (_b) {
359
317
  switch (_b.label) {
360
318
  case 0:
361
319
  orderRepo = this.manager_.getCustomRepository(this.orderRepository_);
362
- validatedId = this.validateId_(orderId);
363
- _a = this.transformQueryForTotals_(config), select = _a.select, relations = _a.relations, totalsToSelect = _a.totalsToSelect;
320
+ _a = this.transformQueryForTotals(config), select = _a.select, relations = _a.relations, totalsToSelect = _a.totalsToSelect;
364
321
  query = {
365
- where: { id: validatedId },
322
+ where: { id: orderId },
366
323
  };
367
324
  if (relations && relations.length > 0) {
368
325
  query.relations = relations;
@@ -378,7 +335,7 @@ var OrderService = /** @class */ (function (_super) {
378
335
  if (!raw) {
379
336
  throw new medusa_core_utils_1.MedusaError(medusa_core_utils_1.MedusaError.Types.NOT_FOUND, "Order with ".concat(orderId, " was not found"));
380
337
  }
381
- return [4 /*yield*/, this.decorateTotals_(raw, totalsToSelect)];
338
+ return [4 /*yield*/, this.decorateTotals(raw, totalsToSelect)];
382
339
  case 2: return [2 /*return*/, _b.sent()];
383
340
  }
384
341
  });
@@ -386,19 +343,19 @@ var OrderService = /** @class */ (function (_super) {
386
343
  };
387
344
  /**
388
345
  * Gets an order by cart id.
389
- * @param {string} cartId - cart id to find order
390
- * @param {Object} config - the config to be used to find order
391
- * @return {Promise<Order>} the order document
346
+ * @param cartId - cart id to find order
347
+ * @param config - the config to be used to find order
348
+ * @return the order document
392
349
  */
393
350
  OrderService.prototype.retrieveByCartId = function (cartId, config) {
394
351
  if (config === void 0) { config = {}; }
395
352
  return __awaiter(this, void 0, void 0, function () {
396
- var orderRepo, _a, select, relations, totalsToSelect, query, raw, order;
353
+ var orderRepo, _a, select, relations, totalsToSelect, query, raw;
397
354
  return __generator(this, function (_b) {
398
355
  switch (_b.label) {
399
356
  case 0:
400
357
  orderRepo = this.manager_.getCustomRepository(this.orderRepository_);
401
- _a = this.transformQueryForTotals_(config), select = _a.select, relations = _a.relations, totalsToSelect = _a.totalsToSelect;
358
+ _a = this.transformQueryForTotals(config), select = _a.select, relations = _a.relations, totalsToSelect = _a.totalsToSelect;
402
359
  query = {
403
360
  where: { cart_id: cartId },
404
361
  };
@@ -414,29 +371,27 @@ var OrderService = /** @class */ (function (_super) {
414
371
  if (!raw) {
415
372
  throw new medusa_core_utils_1.MedusaError(medusa_core_utils_1.MedusaError.Types.NOT_FOUND, "Order with cart id: ".concat(cartId, " was not found"));
416
373
  }
417
- return [4 /*yield*/, this.decorateTotals_(raw, totalsToSelect)];
418
- case 2:
419
- order = _b.sent();
420
- return [2 /*return*/, order];
374
+ return [4 /*yield*/, this.decorateTotals(raw, totalsToSelect)];
375
+ case 2: return [2 /*return*/, _b.sent()];
421
376
  }
422
377
  });
423
378
  });
424
379
  };
425
380
  /**
426
381
  * Gets an order by id.
427
- * @param {string} externalId - id of order to retrieve
428
- * @param {object} config - query config to get order by
429
- * @return {Promise<Order>} the order document
382
+ * @param externalId - id of order to retrieve
383
+ * @param config - query config to get order by
384
+ * @return the order document
430
385
  */
431
386
  OrderService.prototype.retrieveByExternalId = function (externalId, config) {
432
387
  if (config === void 0) { config = {}; }
433
388
  return __awaiter(this, void 0, void 0, function () {
434
- var orderRepo, _a, select, relations, totalsToSelect, query, rels, raw, order;
389
+ var orderRepo, _a, select, relations, totalsToSelect, query, rels, raw;
435
390
  return __generator(this, function (_b) {
436
391
  switch (_b.label) {
437
392
  case 0:
438
393
  orderRepo = this.manager_.getCustomRepository(this.orderRepository_);
439
- _a = this.transformQueryForTotals_(config), select = _a.select, relations = _a.relations, totalsToSelect = _a.totalsToSelect;
394
+ _a = this.transformQueryForTotals(config), select = _a.select, relations = _a.relations, totalsToSelect = _a.totalsToSelect;
440
395
  query = {
441
396
  where: { external_id: externalId },
442
397
  };
@@ -454,355 +409,348 @@ var OrderService = /** @class */ (function (_super) {
454
409
  if (!raw) {
455
410
  throw new medusa_core_utils_1.MedusaError(medusa_core_utils_1.MedusaError.Types.NOT_FOUND, "Order with external id ".concat(externalId, " was not found"));
456
411
  }
457
- return [4 /*yield*/, this.decorateTotals_(raw, totalsToSelect)];
458
- case 2:
459
- order = _b.sent();
460
- return [2 /*return*/, order];
412
+ return [4 /*yield*/, this.decorateTotals(raw, totalsToSelect)];
413
+ case 2: return [2 /*return*/, _b.sent()];
461
414
  }
462
415
  });
463
416
  });
464
417
  };
465
418
  /**
466
419
  * Checks the existence of an order by cart id.
467
- * @param {string} cartId - cart id to find order
468
- * @return {Promise<Order>} the order document
420
+ * @param cartId - cart id to find order
421
+ * @return the order document
469
422
  */
470
423
  OrderService.prototype.existsByCartId = function (cartId) {
471
424
  return __awaiter(this, void 0, void 0, function () {
472
425
  var order;
473
426
  return __generator(this, function (_a) {
474
427
  switch (_a.label) {
475
- case 0: return [4 /*yield*/, this.retrieveByCartId(cartId).catch(function (_) { return undefined; })];
428
+ case 0: return [4 /*yield*/, this.retrieveByCartId(cartId).catch(function () { return undefined; })];
476
429
  case 1:
477
430
  order = _a.sent();
478
- if (!order) {
479
- return [2 /*return*/, false];
480
- }
481
- return [2 /*return*/, true];
431
+ return [2 /*return*/, !!order];
482
432
  }
483
433
  });
484
434
  });
485
435
  };
486
436
  /**
487
- * @param {string} orderId - id of the order to complete
488
- * @return {Promise} the result of the find operation
437
+ * @param orderId - id of the order to complete
438
+ * @return the result of the find operation
489
439
  */
490
440
  OrderService.prototype.completeOrder = function (orderId) {
491
441
  return __awaiter(this, void 0, void 0, function () {
492
442
  var _this = this;
493
443
  return __generator(this, function (_a) {
494
- return [2 /*return*/, this.atomicPhase_(function (manager) { return __awaiter(_this, void 0, void 0, function () {
495
- var order, completeOrderJob, orderRepo;
496
- return __generator(this, function (_a) {
497
- switch (_a.label) {
498
- case 0: return [4 /*yield*/, this.retrieve(orderId)];
499
- case 1:
500
- order = _a.sent();
501
- if (order.status === "canceled") {
502
- throw new medusa_core_utils_1.MedusaError(medusa_core_utils_1.MedusaError.Types.NOT_ALLOWED, "A canceled order cannot be completed");
503
- }
504
- return [4 /*yield*/, this.eventBus_.emit(OrderService.Events.COMPLETED, {
505
- id: orderId,
506
- no_notification: order.no_notification,
507
- })];
508
- case 2:
509
- completeOrderJob = _a.sent();
510
- return [4 /*yield*/, completeOrderJob.finished().catch(function (error) {
511
- throw error;
512
- })];
513
- case 3:
514
- _a.sent();
515
- order.status = "completed";
516
- orderRepo = manager.getCustomRepository(this.orderRepository_);
517
- return [2 /*return*/, orderRepo.save(order)];
518
- }
519
- });
520
- }); })];
444
+ switch (_a.label) {
445
+ case 0: return [4 /*yield*/, this.atomicPhase_(function (manager) { return __awaiter(_this, void 0, void 0, function () {
446
+ var order, orderRepo;
447
+ return __generator(this, function (_a) {
448
+ switch (_a.label) {
449
+ case 0: return [4 /*yield*/, this.retrieve(orderId)];
450
+ case 1:
451
+ order = _a.sent();
452
+ if (order.status === "canceled") {
453
+ throw new medusa_core_utils_1.MedusaError(medusa_core_utils_1.MedusaError.Types.NOT_ALLOWED, "A canceled order cannot be completed");
454
+ }
455
+ return [4 /*yield*/, this.eventBus_.emit(OrderService.Events.COMPLETED, {
456
+ id: orderId,
457
+ no_notification: order.no_notification,
458
+ })];
459
+ case 2:
460
+ _a.sent();
461
+ order.status = models_1.OrderStatus.COMPLETED;
462
+ orderRepo = manager.getCustomRepository(this.orderRepository_);
463
+ return [2 /*return*/, orderRepo.save(order)];
464
+ }
465
+ });
466
+ }); })];
467
+ case 1: return [2 /*return*/, _a.sent()];
468
+ }
521
469
  });
522
470
  });
523
471
  };
524
472
  /**
525
473
  * Creates an order from a cart
526
- * @param {string} cartId - id of the cart to create an order from
527
- * @return {Promise} resolves to the creation result.
474
+ * @param cartId - id of the cart to create an order from
475
+ * @return resolves to the creation result.
528
476
  */
529
477
  OrderService.prototype.createFromCart = function (cartId) {
530
478
  return __awaiter(this, void 0, void 0, function () {
531
479
  var _this = this;
532
480
  return __generator(this, function (_a) {
533
- return [2 /*return*/, this.atomicPhase_(function (manager) { return __awaiter(_this, void 0, void 0, function () {
534
- var cart, payment, region, total, _a, _b, item, err_1, e_1_1, exists, paymentStatus, orderRepo, toCreate, draft, o, result, gcBalance, _c, _d, g, newBalance, usage, e_2_1, _e, _f, method, e_3_1, _g, _h, item, e_4_1, _j, _k, item, e_5_1;
535
- var e_1, _l, e_2, _m, e_3, _o, e_4, _p, e_5, _q;
536
- return __generator(this, function (_r) {
537
- switch (_r.label) {
538
- case 0: return [4 /*yield*/, this.cartService_
539
- .withTransaction(manager)
540
- .retrieve(cartId, {
541
- select: ["subtotal", "total"],
542
- relations: [
543
- "region",
544
- "payment",
545
- "items",
546
- "discounts",
547
- "discounts.rule",
548
- "gift_cards",
549
- "shipping_methods",
550
- ],
551
- })];
552
- case 1:
553
- cart = _r.sent();
554
- if (cart.items.length === 0) {
555
- throw new medusa_core_utils_1.MedusaError(medusa_core_utils_1.MedusaError.Types.INVALID_DATA, "Cannot create order from empty cart");
556
- }
557
- payment = cart.payment, region = cart.region, total = cart.total;
558
- _r.label = 2;
559
- case 2:
560
- _r.trys.push([2, 12, 13, 14]);
561
- _a = __values(cart.items), _b = _a.next();
562
- _r.label = 3;
563
- case 3:
564
- if (!!_b.done) return [3 /*break*/, 11];
565
- item = _b.value;
566
- _r.label = 4;
567
- case 4:
568
- _r.trys.push([4, 6, , 10]);
569
- return [4 /*yield*/, this.inventoryService_
570
- .withTransaction(manager)
571
- .confirmInventory(item.variant_id, item.quantity)];
572
- case 5:
573
- _r.sent();
574
- return [3 /*break*/, 10];
575
- case 6:
576
- err_1 = _r.sent();
577
- if (!payment) return [3 /*break*/, 8];
578
- return [4 /*yield*/, this.paymentProviderService_
579
- .withTransaction(manager)
580
- .cancelPayment(payment)];
581
- case 7:
582
- _r.sent();
583
- _r.label = 8;
584
- case 8: return [4 /*yield*/, this.cartService_
585
- .withTransaction(manager)
586
- .update(cart.id, { payment_authorized_at: null })];
587
- case 9:
588
- _r.sent();
589
- throw err_1;
590
- case 10:
591
- _b = _a.next();
592
- return [3 /*break*/, 3];
593
- case 11: return [3 /*break*/, 14];
594
- case 12:
595
- e_1_1 = _r.sent();
596
- e_1 = { error: e_1_1 };
597
- return [3 /*break*/, 14];
598
- case 13:
599
- try {
600
- if (_b && !_b.done && (_l = _a.return)) _l.call(_a);
601
- }
602
- finally { if (e_1) throw e_1.error; }
603
- return [7 /*endfinally*/];
604
- case 14: return [4 /*yield*/, this.existsByCartId(cart.id)];
605
- case 15:
606
- exists = _r.sent();
607
- if (exists) {
608
- throw new medusa_core_utils_1.MedusaError(medusa_core_utils_1.MedusaError.Types.DUPLICATE_ERROR, "Order from cart already exists");
609
- }
610
- if (!(total !== 0)) return [3 /*break*/, 17];
611
- // Throw if payment method does not exist
612
- if (!payment) {
613
- throw new medusa_core_utils_1.MedusaError(medusa_core_utils_1.MedusaError.Types.INVALID_ARGUMENT, "Cart does not contain a payment method");
614
- }
615
- return [4 /*yield*/, this.paymentProviderService_
616
- .withTransaction(manager)
617
- .getStatus(payment)
618
- // If payment status is not authorized, we throw
619
- ];
620
- case 16:
621
- paymentStatus = _r.sent();
622
- // If payment status is not authorized, we throw
623
- if (paymentStatus !== "authorized" && paymentStatus !== "succeeded") {
624
- throw new medusa_core_utils_1.MedusaError(medusa_core_utils_1.MedusaError.Types.INVALID_ARGUMENT, "Payment method is not authorized");
625
- }
626
- _r.label = 17;
627
- case 17:
628
- orderRepo = manager.getCustomRepository(this.orderRepository_);
629
- toCreate = {
630
- payment_status: "awaiting",
631
- discounts: cart.discounts,
632
- gift_cards: cart.gift_cards,
633
- shipping_methods: cart.shipping_methods,
634
- shipping_address_id: cart.shipping_address_id,
635
- billing_address_id: cart.billing_address_id,
636
- region_id: cart.region_id,
637
- email: cart.email,
638
- customer_id: cart.customer_id,
639
- cart_id: cart.id,
640
- currency_code: region.currency_code,
641
- metadata: cart.metadata || {},
642
- };
643
- if (!(cart.type === "draft_order")) return [3 /*break*/, 19];
644
- return [4 /*yield*/, this.draftOrderService_
645
- .withTransaction(manager)
646
- .retrieveByCartId(cart.id)];
647
- case 18:
648
- draft = _r.sent();
649
- toCreate.draft_order_id = draft.id;
650
- toCreate.no_notification = draft.no_notification_order;
651
- _r.label = 19;
652
- case 19: return [4 /*yield*/, orderRepo.create(toCreate)];
653
- case 20:
654
- o = _r.sent();
655
- return [4 /*yield*/, orderRepo.save(o)];
656
- case 21:
657
- result = _r.sent();
658
- if (!(total !== 0)) return [3 /*break*/, 23];
659
- return [4 /*yield*/, this.paymentProviderService_
481
+ switch (_a.label) {
482
+ case 0: return [4 /*yield*/, this.atomicPhase_(function (manager) { return __awaiter(_this, void 0, void 0, function () {
483
+ var cartServiceTx, inventoryServiceTx, cart, payment, region, total, _a, _b, item, err_1, e_1_1, exists, paymentStatus, orderRepo, toCreate, draft, o, result, gcBalance, gcService, _c, _d, g, newBalance, usage, e_2_1, _e, _f, method, e_3_1, lineItemServiceTx, _g, _h, item, e_4_1, _j, _k, item, e_5_1;
484
+ var e_1, _l, e_2, _m, e_3, _o, e_4, _p, e_5, _q;
485
+ return __generator(this, function (_r) {
486
+ switch (_r.label) {
487
+ case 0:
488
+ cartServiceTx = this.cartService_.withTransaction(manager);
489
+ inventoryServiceTx = this.inventoryService_.withTransaction(manager);
490
+ return [4 /*yield*/, cartServiceTx.retrieve(cartId, {
491
+ select: ["subtotal", "total"],
492
+ relations: [
493
+ "region",
494
+ "payment",
495
+ "items",
496
+ "discounts",
497
+ "discounts.rule",
498
+ "gift_cards",
499
+ "shipping_methods",
500
+ "items",
501
+ "items.adjustments",
502
+ ],
503
+ })];
504
+ case 1:
505
+ cart = _r.sent();
506
+ if (cart.items.length === 0) {
507
+ throw new medusa_core_utils_1.MedusaError(medusa_core_utils_1.MedusaError.Types.INVALID_DATA, "Cannot create order from empty cart");
508
+ }
509
+ payment = cart.payment, region = cart.region, total = cart.total;
510
+ _r.label = 2;
511
+ case 2:
512
+ _r.trys.push([2, 12, 13, 14]);
513
+ _a = __values(cart.items), _b = _a.next();
514
+ _r.label = 3;
515
+ case 3:
516
+ if (!!_b.done) return [3 /*break*/, 11];
517
+ item = _b.value;
518
+ _r.label = 4;
519
+ case 4:
520
+ _r.trys.push([4, 6, , 10]);
521
+ return [4 /*yield*/, inventoryServiceTx.confirmInventory(item.variant_id, item.quantity)];
522
+ case 5:
523
+ _r.sent();
524
+ return [3 /*break*/, 10];
525
+ case 6:
526
+ err_1 = _r.sent();
527
+ if (!payment) return [3 /*break*/, 8];
528
+ return [4 /*yield*/, this.paymentProviderService_
529
+ .withTransaction(manager)
530
+ .cancelPayment(payment)];
531
+ case 7:
532
+ _r.sent();
533
+ _r.label = 8;
534
+ case 8: return [4 /*yield*/, cartServiceTx.update(cart.id, { payment_authorized_at: null })];
535
+ case 9:
536
+ _r.sent();
537
+ throw err_1;
538
+ case 10:
539
+ _b = _a.next();
540
+ return [3 /*break*/, 3];
541
+ case 11: return [3 /*break*/, 14];
542
+ case 12:
543
+ e_1_1 = _r.sent();
544
+ e_1 = { error: e_1_1 };
545
+ return [3 /*break*/, 14];
546
+ case 13:
547
+ try {
548
+ if (_b && !_b.done && (_l = _a.return)) _l.call(_a);
549
+ }
550
+ finally { if (e_1) throw e_1.error; }
551
+ return [7 /*endfinally*/];
552
+ case 14: return [4 /*yield*/, this.existsByCartId(cart.id)];
553
+ case 15:
554
+ exists = _r.sent();
555
+ if (exists) {
556
+ throw new medusa_core_utils_1.MedusaError(medusa_core_utils_1.MedusaError.Types.DUPLICATE_ERROR, "Order from cart already exists");
557
+ }
558
+ if (!(total !== 0)) return [3 /*break*/, 17];
559
+ if (!payment) {
560
+ throw new medusa_core_utils_1.MedusaError(medusa_core_utils_1.MedusaError.Types.INVALID_ARGUMENT, "Cart does not contain a payment method");
561
+ }
562
+ return [4 /*yield*/, this.paymentProviderService_
563
+ .withTransaction(manager)
564
+ .getStatus(payment)];
565
+ case 16:
566
+ paymentStatus = _r.sent();
567
+ if (paymentStatus !== "authorized") {
568
+ throw new medusa_core_utils_1.MedusaError(medusa_core_utils_1.MedusaError.Types.INVALID_ARGUMENT, "Payment method is not authorized");
569
+ }
570
+ _r.label = 17;
571
+ case 17:
572
+ orderRepo = manager.getCustomRepository(this.orderRepository_);
573
+ toCreate = {
574
+ payment_status: "awaiting",
575
+ discounts: cart.discounts,
576
+ gift_cards: cart.gift_cards,
577
+ shipping_methods: cart.shipping_methods,
578
+ shipping_address_id: cart.shipping_address_id,
579
+ billing_address_id: cart.billing_address_id,
580
+ region_id: cart.region_id,
581
+ email: cart.email,
582
+ customer_id: cart.customer_id,
583
+ cart_id: cart.id,
584
+ currency_code: region.currency_code,
585
+ metadata: cart.metadata || {},
586
+ };
587
+ if (!(cart.type === "draft_order")) return [3 /*break*/, 19];
588
+ return [4 /*yield*/, this.draftOrderService_
589
+ .withTransaction(manager)
590
+ .retrieveByCartId(cart.id)];
591
+ case 18:
592
+ draft = _r.sent();
593
+ toCreate.draft_order_id = draft.id;
594
+ toCreate.no_notification = draft.no_notification_order;
595
+ _r.label = 19;
596
+ case 19:
597
+ o = orderRepo.create(toCreate);
598
+ return [4 /*yield*/, orderRepo.save(o)];
599
+ case 20:
600
+ result = _r.sent();
601
+ if (!(total !== 0 && payment)) return [3 /*break*/, 22];
602
+ return [4 /*yield*/, this.paymentProviderService_
603
+ .withTransaction(manager)
604
+ .updatePayment(payment.id, {
605
+ order_id: result.id,
606
+ })];
607
+ case 21:
608
+ _r.sent();
609
+ _r.label = 22;
610
+ case 22: return [4 /*yield*/, this.totalsService_.getGiftCardableAmount(cart)];
611
+ case 23:
612
+ gcBalance = _r.sent();
613
+ gcService = this.giftCardService_.withTransaction(manager);
614
+ _r.label = 24;
615
+ case 24:
616
+ _r.trys.push([24, 30, 31, 32]);
617
+ _c = __values(cart.gift_cards), _d = _c.next();
618
+ _r.label = 25;
619
+ case 25:
620
+ if (!!_d.done) return [3 /*break*/, 29];
621
+ g = _d.value;
622
+ newBalance = Math.max(0, g.balance - gcBalance);
623
+ usage = g.balance - newBalance;
624
+ return [4 /*yield*/, gcService.update(g.id, {
625
+ balance: newBalance,
626
+ is_disabled: newBalance === 0,
627
+ })];
628
+ case 26:
629
+ _r.sent();
630
+ return [4 /*yield*/, gcService.createTransaction({
631
+ gift_card_id: g.id,
632
+ order_id: result.id,
633
+ amount: usage,
634
+ is_taxable: cart.region.gift_cards_taxable,
635
+ tax_rate: cart.region.gift_cards_taxable
636
+ ? cart.region.tax_rate
637
+ : null,
638
+ })];
639
+ case 27:
640
+ _r.sent();
641
+ gcBalance = gcBalance - usage;
642
+ _r.label = 28;
643
+ case 28:
644
+ _d = _c.next();
645
+ return [3 /*break*/, 25];
646
+ case 29: return [3 /*break*/, 32];
647
+ case 30:
648
+ e_2_1 = _r.sent();
649
+ e_2 = { error: e_2_1 };
650
+ return [3 /*break*/, 32];
651
+ case 31:
652
+ try {
653
+ if (_d && !_d.done && (_m = _c.return)) _m.call(_c);
654
+ }
655
+ finally { if (e_2) throw e_2.error; }
656
+ return [7 /*endfinally*/];
657
+ case 32:
658
+ _r.trys.push([32, 37, 38, 39]);
659
+ _e = __values(cart.shipping_methods), _f = _e.next();
660
+ _r.label = 33;
661
+ case 33:
662
+ if (!!_f.done) return [3 /*break*/, 36];
663
+ method = _f.value;
664
+ return [4 /*yield*/, this.shippingOptionService_
665
+ .withTransaction(manager)
666
+ .updateShippingMethod(method.id, { order_id: result.id })];
667
+ case 34:
668
+ _r.sent();
669
+ _r.label = 35;
670
+ case 35:
671
+ _f = _e.next();
672
+ return [3 /*break*/, 33];
673
+ case 36: return [3 /*break*/, 39];
674
+ case 37:
675
+ e_3_1 = _r.sent();
676
+ e_3 = { error: e_3_1 };
677
+ return [3 /*break*/, 39];
678
+ case 38:
679
+ try {
680
+ if (_f && !_f.done && (_o = _e.return)) _o.call(_e);
681
+ }
682
+ finally { if (e_3) throw e_3.error; }
683
+ return [7 /*endfinally*/];
684
+ case 39:
685
+ lineItemServiceTx = this.lineItemService_.withTransaction(manager);
686
+ _r.label = 40;
687
+ case 40:
688
+ _r.trys.push([40, 45, 46, 47]);
689
+ _g = __values(cart.items), _h = _g.next();
690
+ _r.label = 41;
691
+ case 41:
692
+ if (!!_h.done) return [3 /*break*/, 44];
693
+ item = _h.value;
694
+ return [4 /*yield*/, lineItemServiceTx.update(item.id, { order_id: result.id })];
695
+ case 42:
696
+ _r.sent();
697
+ _r.label = 43;
698
+ case 43:
699
+ _h = _g.next();
700
+ return [3 /*break*/, 41];
701
+ case 44: return [3 /*break*/, 47];
702
+ case 45:
703
+ e_4_1 = _r.sent();
704
+ e_4 = { error: e_4_1 };
705
+ return [3 /*break*/, 47];
706
+ case 46:
707
+ try {
708
+ if (_h && !_h.done && (_p = _g.return)) _p.call(_g);
709
+ }
710
+ finally { if (e_4) throw e_4.error; }
711
+ return [7 /*endfinally*/];
712
+ case 47:
713
+ _r.trys.push([47, 52, 53, 54]);
714
+ _j = __values(cart.items), _k = _j.next();
715
+ _r.label = 48;
716
+ case 48:
717
+ if (!!_k.done) return [3 /*break*/, 51];
718
+ item = _k.value;
719
+ return [4 /*yield*/, inventoryServiceTx.adjustInventory(item.variant_id, -item.quantity)];
720
+ case 49:
721
+ _r.sent();
722
+ _r.label = 50;
723
+ case 50:
724
+ _k = _j.next();
725
+ return [3 /*break*/, 48];
726
+ case 51: return [3 /*break*/, 54];
727
+ case 52:
728
+ e_5_1 = _r.sent();
729
+ e_5 = { error: e_5_1 };
730
+ return [3 /*break*/, 54];
731
+ case 53:
732
+ try {
733
+ if (_k && !_k.done && (_q = _j.return)) _q.call(_j);
734
+ }
735
+ finally { if (e_5) throw e_5.error; }
736
+ return [7 /*endfinally*/];
737
+ case 54: return [4 /*yield*/, this.eventBus_
660
738
  .withTransaction(manager)
661
- .updatePayment(payment.id, {
662
- order_id: result.id,
663
- })];
664
- case 22:
665
- _r.sent();
666
- _r.label = 23;
667
- case 23:
668
- gcBalance = cart.subtotal;
669
- _r.label = 24;
670
- case 24:
671
- _r.trys.push([24, 30, 31, 32]);
672
- _c = __values(cart.gift_cards), _d = _c.next();
673
- _r.label = 25;
674
- case 25:
675
- if (!!_d.done) return [3 /*break*/, 29];
676
- g = _d.value;
677
- newBalance = Math.max(0, g.balance - gcBalance);
678
- usage = g.balance - newBalance;
679
- return [4 /*yield*/, this.giftCardService_.withTransaction(manager).update(g.id, {
680
- balance: newBalance,
681
- disabled: newBalance === 0,
682
- })];
683
- case 26:
684
- _r.sent();
685
- return [4 /*yield*/, this.giftCardService_.withTransaction(manager).createTransaction({
686
- gift_card_id: g.id,
687
- order_id: result.id,
688
- amount: usage,
739
+ .emit(OrderService.Events.PLACED, {
740
+ id: result.id,
741
+ no_notification: result.no_notification,
689
742
  })];
690
- case 27:
691
- _r.sent();
692
- gcBalance = gcBalance - usage;
693
- _r.label = 28;
694
- case 28:
695
- _d = _c.next();
696
- return [3 /*break*/, 25];
697
- case 29: return [3 /*break*/, 32];
698
- case 30:
699
- e_2_1 = _r.sent();
700
- e_2 = { error: e_2_1 };
701
- return [3 /*break*/, 32];
702
- case 31:
703
- try {
704
- if (_d && !_d.done && (_m = _c.return)) _m.call(_c);
705
- }
706
- finally { if (e_2) throw e_2.error; }
707
- return [7 /*endfinally*/];
708
- case 32:
709
- _r.trys.push([32, 37, 38, 39]);
710
- _e = __values(cart.shipping_methods), _f = _e.next();
711
- _r.label = 33;
712
- case 33:
713
- if (!!_f.done) return [3 /*break*/, 36];
714
- method = _f.value;
715
- return [4 /*yield*/, this.shippingOptionService_
716
- .withTransaction(manager)
717
- .updateShippingMethod(method.id, { order_id: result.id })];
718
- case 34:
719
- _r.sent();
720
- _r.label = 35;
721
- case 35:
722
- _f = _e.next();
723
- return [3 /*break*/, 33];
724
- case 36: return [3 /*break*/, 39];
725
- case 37:
726
- e_3_1 = _r.sent();
727
- e_3 = { error: e_3_1 };
728
- return [3 /*break*/, 39];
729
- case 38:
730
- try {
731
- if (_f && !_f.done && (_o = _e.return)) _o.call(_e);
732
- }
733
- finally { if (e_3) throw e_3.error; }
734
- return [7 /*endfinally*/];
735
- case 39:
736
- _r.trys.push([39, 44, 45, 46]);
737
- _g = __values(cart.items), _h = _g.next();
738
- _r.label = 40;
739
- case 40:
740
- if (!!_h.done) return [3 /*break*/, 43];
741
- item = _h.value;
742
- return [4 /*yield*/, this.lineItemService_
743
- .withTransaction(manager)
744
- .update(item.id, { order_id: result.id })];
745
- case 41:
746
- _r.sent();
747
- _r.label = 42;
748
- case 42:
749
- _h = _g.next();
750
- return [3 /*break*/, 40];
751
- case 43: return [3 /*break*/, 46];
752
- case 44:
753
- e_4_1 = _r.sent();
754
- e_4 = { error: e_4_1 };
755
- return [3 /*break*/, 46];
756
- case 45:
757
- try {
758
- if (_h && !_h.done && (_p = _g.return)) _p.call(_g);
759
- }
760
- finally { if (e_4) throw e_4.error; }
761
- return [7 /*endfinally*/];
762
- case 46:
763
- _r.trys.push([46, 51, 52, 53]);
764
- _j = __values(cart.items), _k = _j.next();
765
- _r.label = 47;
766
- case 47:
767
- if (!!_k.done) return [3 /*break*/, 50];
768
- item = _k.value;
769
- return [4 /*yield*/, this.inventoryService_
770
- .withTransaction(manager)
771
- .adjustInventory(item.variant_id, -item.quantity)];
772
- case 48:
773
- _r.sent();
774
- _r.label = 49;
775
- case 49:
776
- _k = _j.next();
777
- return [3 /*break*/, 47];
778
- case 50: return [3 /*break*/, 53];
779
- case 51:
780
- e_5_1 = _r.sent();
781
- e_5 = { error: e_5_1 };
782
- return [3 /*break*/, 53];
783
- case 52:
784
- try {
785
- if (_k && !_k.done && (_q = _j.return)) _q.call(_j);
786
- }
787
- finally { if (e_5) throw e_5.error; }
788
- return [7 /*endfinally*/];
789
- case 53: return [4 /*yield*/, this.eventBus_
790
- .withTransaction(manager)
791
- .emit(OrderService.Events.PLACED, {
792
- id: result.id,
793
- no_notification: result.no_notification,
794
- })];
795
- case 54:
796
- _r.sent();
797
- return [4 /*yield*/, this.cartService_
798
- .withTransaction(manager)
799
- .update(cart.id, { completed_at: new Date() })];
800
- case 55:
801
- _r.sent();
802
- return [2 /*return*/, result];
803
- }
804
- });
805
- }); })];
743
+ case 55:
744
+ _r.sent();
745
+ return [4 /*yield*/, cartServiceTx.update(cart.id, { completed_at: new Date() })];
746
+ case 56:
747
+ _r.sent();
748
+ return [2 /*return*/, result];
749
+ }
750
+ });
751
+ }); })];
752
+ case 1: return [2 /*return*/, _a.sent()];
753
+ }
806
754
  });
807
755
  });
808
756
  };
@@ -810,14 +758,12 @@ var OrderService = /** @class */ (function (_super) {
810
758
  * Adds a shipment to the order to indicate that an order has left the
811
759
  * warehouse. Will ask the fulfillment provider for any documents that may
812
760
  * have been created in regards to the shipment.
813
- * @param {string} orderId - the id of the order that has been shipped
814
- * @param {string} fulfillmentId - the fulfillment that has now been shipped
815
- * @param {TrackingLink[] | undefined} trackingLinks - array of tracking numebers
761
+ * @param orderId - the id of the order that has been shipped
762
+ * @param fulfillmentId - the fulfillment that has now been shipped
763
+ * @param trackingLinks - array of tracking numebers
816
764
  * associated with the shipment
817
- * @param {Object} config - the config of the order that has been shipped
818
- * @param {Dictionary<String, String>} metadata - optional metadata to add to
819
- * the fulfillment
820
- * @return {order} the resulting order following the update.
765
+ * @param config - the config of the order that has been shipped
766
+ * @return the resulting order following the update.
821
767
  */
822
768
  OrderService.prototype.createShipment = function (orderId, fulfillmentId, trackingLinks, config) {
823
769
  if (config === void 0) { config = {
@@ -828,187 +774,162 @@ var OrderService = /** @class */ (function (_super) {
828
774
  var metadata, no_notification;
829
775
  var _this = this;
830
776
  return __generator(this, function (_a) {
831
- metadata = config.metadata, no_notification = config.no_notification;
832
- return [2 /*return*/, this.atomicPhase_(function (manager) { return __awaiter(_this, void 0, void 0, function () {
833
- var order, shipment, evaluatedNoNotification, shipmentRes, _loop_1, this_1, _a, _b, item, e_6_1, orderRepo, result;
834
- var e_6, _c;
835
- return __generator(this, function (_d) {
836
- switch (_d.label) {
837
- case 0: return [4 /*yield*/, this.retrieve(orderId, { relations: ["items"] })];
838
- case 1:
839
- order = _d.sent();
840
- return [4 /*yield*/, this.fulfillmentService_.retrieve(fulfillmentId)];
841
- case 2:
842
- shipment = _d.sent();
843
- if (order.status === "canceled") {
844
- throw new medusa_core_utils_1.MedusaError(medusa_core_utils_1.MedusaError.Types.NOT_ALLOWED, "A canceled order cannot be fulfilled as shipped");
845
- }
846
- if (!shipment || shipment.order_id !== orderId) {
847
- throw new medusa_core_utils_1.MedusaError(medusa_core_utils_1.MedusaError.Types.NOT_FOUND, "Could not find fulfillment");
848
- }
849
- evaluatedNoNotification = no_notification !== undefined
850
- ? no_notification
851
- : shipment.no_notification;
852
- return [4 /*yield*/, this.fulfillmentService_
853
- .withTransaction(manager)
854
- .createShipment(fulfillmentId, trackingLinks, {
855
- metadata: metadata,
856
- no_notification: evaluatedNoNotification,
857
- })];
858
- case 3:
859
- shipmentRes = _d.sent();
860
- order.fulfillment_status = "shipped";
861
- _loop_1 = function (item) {
862
- var shipped, shippedQty;
863
- return __generator(this, function (_e) {
864
- switch (_e.label) {
865
- case 0:
866
- shipped = shipmentRes.items.find(function (si) { return si.item_id === item.id; });
867
- if (!shipped) return [3 /*break*/, 2];
868
- shippedQty = (item.shipped_quantity || 0) + shipped.quantity;
869
- if (shippedQty !== item.quantity) {
870
- order.fulfillment_status = "partially_shipped";
871
- }
872
- return [4 /*yield*/, this_1.lineItemService_.withTransaction(manager).update(item.id, {
873
- shipped_quantity: shippedQty,
874
- })];
875
- case 1:
876
- _e.sent();
877
- return [3 /*break*/, 3];
878
- case 2:
879
- if (item.shipped_quantity !== item.quantity) {
880
- order.fulfillment_status = "partially_shipped";
777
+ switch (_a.label) {
778
+ case 0:
779
+ metadata = config.metadata, no_notification = config.no_notification;
780
+ return [4 /*yield*/, this.atomicPhase_(function (manager) { return __awaiter(_this, void 0, void 0, function () {
781
+ var order, shipment, evaluatedNoNotification, shipmentRes, lineItemServiceTx, _loop_1, _a, _b, item, e_6_1, orderRepo, result;
782
+ var e_6, _c;
783
+ return __generator(this, function (_d) {
784
+ switch (_d.label) {
785
+ case 0: return [4 /*yield*/, this.retrieve(orderId, { relations: ["items"] })];
786
+ case 1:
787
+ order = _d.sent();
788
+ return [4 /*yield*/, this.fulfillmentService_
789
+ .withTransaction(manager)
790
+ .retrieve(fulfillmentId)];
791
+ case 2:
792
+ shipment = _d.sent();
793
+ if (order.status === "canceled") {
794
+ throw new medusa_core_utils_1.MedusaError(medusa_core_utils_1.MedusaError.Types.NOT_ALLOWED, "A canceled order cannot be fulfilled as shipped");
795
+ }
796
+ if (!shipment || shipment.order_id !== orderId) {
797
+ throw new medusa_core_utils_1.MedusaError(medusa_core_utils_1.MedusaError.Types.NOT_FOUND, "Could not find fulfillment");
798
+ }
799
+ evaluatedNoNotification = no_notification !== undefined
800
+ ? no_notification
801
+ : shipment.no_notification;
802
+ return [4 /*yield*/, this.fulfillmentService_
803
+ .withTransaction(manager)
804
+ .createShipment(fulfillmentId, trackingLinks, {
805
+ metadata: metadata,
806
+ no_notification: evaluatedNoNotification,
807
+ })];
808
+ case 3:
809
+ shipmentRes = _d.sent();
810
+ lineItemServiceTx = this.lineItemService_.withTransaction(manager);
811
+ order.fulfillment_status = models_1.FulfillmentStatus.SHIPPED;
812
+ _loop_1 = function (item) {
813
+ var shipped, shippedQty;
814
+ return __generator(this, function (_e) {
815
+ switch (_e.label) {
816
+ case 0:
817
+ shipped = shipmentRes.items.find(function (si) { return si.item_id === item.id; });
818
+ if (!shipped) return [3 /*break*/, 2];
819
+ shippedQty = (item.shipped_quantity || 0) + shipped.quantity;
820
+ if (shippedQty !== item.quantity) {
821
+ order.fulfillment_status = models_1.FulfillmentStatus.PARTIALLY_SHIPPED;
822
+ }
823
+ return [4 /*yield*/, lineItemServiceTx.update(item.id, {
824
+ shipped_quantity: shippedQty,
825
+ })];
826
+ case 1:
827
+ _e.sent();
828
+ return [3 /*break*/, 3];
829
+ case 2:
830
+ if (item.shipped_quantity !== item.quantity) {
831
+ order.fulfillment_status = models_1.FulfillmentStatus.PARTIALLY_SHIPPED;
832
+ }
833
+ _e.label = 3;
834
+ case 3: return [2 /*return*/];
881
835
  }
882
- _e.label = 3;
883
- case 3: return [2 /*return*/];
836
+ });
837
+ };
838
+ _d.label = 4;
839
+ case 4:
840
+ _d.trys.push([4, 9, 10, 11]);
841
+ _a = __values(order.items), _b = _a.next();
842
+ _d.label = 5;
843
+ case 5:
844
+ if (!!_b.done) return [3 /*break*/, 8];
845
+ item = _b.value;
846
+ return [5 /*yield**/, _loop_1(item)];
847
+ case 6:
848
+ _d.sent();
849
+ _d.label = 7;
850
+ case 7:
851
+ _b = _a.next();
852
+ return [3 /*break*/, 5];
853
+ case 8: return [3 /*break*/, 11];
854
+ case 9:
855
+ e_6_1 = _d.sent();
856
+ e_6 = { error: e_6_1 };
857
+ return [3 /*break*/, 11];
858
+ case 10:
859
+ try {
860
+ if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
884
861
  }
885
- });
886
- };
887
- this_1 = this;
888
- _d.label = 4;
889
- case 4:
890
- _d.trys.push([4, 9, 10, 11]);
891
- _a = __values(order.items), _b = _a.next();
892
- _d.label = 5;
893
- case 5:
894
- if (!!_b.done) return [3 /*break*/, 8];
895
- item = _b.value;
896
- return [5 /*yield**/, _loop_1(item)];
897
- case 6:
898
- _d.sent();
899
- _d.label = 7;
900
- case 7:
901
- _b = _a.next();
902
- return [3 /*break*/, 5];
903
- case 8: return [3 /*break*/, 11];
904
- case 9:
905
- e_6_1 = _d.sent();
906
- e_6 = { error: e_6_1 };
907
- return [3 /*break*/, 11];
908
- case 10:
909
- try {
910
- if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
862
+ finally { if (e_6) throw e_6.error; }
863
+ return [7 /*endfinally*/];
864
+ case 11:
865
+ orderRepo = manager.getCustomRepository(this.orderRepository_);
866
+ return [4 /*yield*/, orderRepo.save(order)];
867
+ case 12:
868
+ result = _d.sent();
869
+ return [4 /*yield*/, this.eventBus_
870
+ .withTransaction(manager)
871
+ .emit(OrderService.Events.SHIPMENT_CREATED, {
872
+ id: orderId,
873
+ fulfillment_id: shipmentRes.id,
874
+ no_notification: evaluatedNoNotification,
875
+ })];
876
+ case 13:
877
+ _d.sent();
878
+ return [2 /*return*/, result];
911
879
  }
912
- finally { if (e_6) throw e_6.error; }
913
- return [7 /*endfinally*/];
914
- case 11:
915
- orderRepo = manager.getCustomRepository(this.orderRepository_);
916
- return [4 /*yield*/, orderRepo.save(order)];
917
- case 12:
918
- result = _d.sent();
919
- return [4 /*yield*/, this.eventBus_
920
- .withTransaction(manager)
921
- .emit(OrderService.Events.SHIPMENT_CREATED, {
922
- id: orderId,
923
- fulfillment_id: shipmentRes.id,
924
- no_notification: evaluatedNoNotification,
925
- })];
926
- case 13:
927
- _d.sent();
928
- return [2 /*return*/, result];
929
- }
930
- });
931
- }); })];
932
- });
933
- });
934
- };
935
- /**
936
- * Creates an order
937
- * @param {object} data - the data to create an order
938
- * @return {Promise} resolves to the creation result.
939
- */
940
- OrderService.prototype.create = function (data) {
941
- return __awaiter(this, void 0, void 0, function () {
942
- var _this = this;
943
- return __generator(this, function (_a) {
944
- return [2 /*return*/, this.atomicPhase_(function (manager) { return __awaiter(_this, void 0, void 0, function () {
945
- var orderRepo, order, result;
946
- return __generator(this, function (_a) {
947
- switch (_a.label) {
948
- case 0:
949
- orderRepo = manager.getCustomRepository(this.orderRepository_);
950
- order = orderRepo.create(data);
951
- return [4 /*yield*/, orderRepo.save(order)];
952
- case 1:
953
- result = _a.sent();
954
- return [4 /*yield*/, this.eventBus_
955
- .withTransaction(manager)
956
- .emit(OrderService.Events.PLACED, {
957
- id: result.id,
958
- no_notification: order.no_notification,
959
- })];
960
- case 2:
961
- _a.sent();
962
- return [2 /*return*/, result];
963
- }
964
- });
965
- }); })];
880
+ });
881
+ }); })];
882
+ case 1: return [2 /*return*/, _a.sent()];
883
+ }
966
884
  });
967
885
  });
968
886
  };
969
887
  /**
970
888
  * Updates the order's billing address.
971
- * @param {object} order - the order to update
972
- * @param {object} address - the value to set the billing address to
973
- * @return {Promise} the result of the update operation
889
+ * @param order - the order to update
890
+ * @param address - the value to set the billing address to
891
+ * @return the result of the update operation
974
892
  */
975
- OrderService.prototype.updateBillingAddress_ = function (order, address) {
893
+ OrderService.prototype.updateBillingAddress = function (order, address) {
894
+ var _a, _b, _c, _d;
976
895
  return __awaiter(this, void 0, void 0, function () {
977
896
  var addrRepo, region, addr, created;
978
- return __generator(this, function (_a) {
979
- switch (_a.label) {
897
+ return __generator(this, function (_e) {
898
+ switch (_e.label) {
980
899
  case 0:
981
900
  addrRepo = this.manager_.getCustomRepository(this.addressRepository_);
982
- address.country_code = address.country_code.toLowerCase();
983
- return [4 /*yield*/, this.regionService_.retrieve(order.region_id, {
901
+ address.country_code = (_b = (_a = address.country_code) === null || _a === void 0 ? void 0 : _a.toLowerCase()) !== null && _b !== void 0 ? _b : null;
902
+ return [4 /*yield*/, this.regionService_
903
+ .withTransaction(this.manager_)
904
+ .retrieve(order.region_id, {
984
905
  relations: ["countries"],
985
906
  })];
986
907
  case 1:
987
- region = _a.sent();
908
+ region = _e.sent();
988
909
  if (!region.countries.find(function (_a) {
989
910
  var iso_2 = _a.iso_2;
990
911
  return address.country_code === iso_2;
991
912
  })) {
992
913
  throw new medusa_core_utils_1.MedusaError(medusa_core_utils_1.MedusaError.Types.INVALID_DATA, "Shipping country must be in the order region");
993
914
  }
994
- address.country_code = address.country_code.toLowerCase();
915
+ address.country_code = (_d = (_c = address.country_code) === null || _c === void 0 ? void 0 : _c.toLowerCase()) !== null && _d !== void 0 ? _d : null;
995
916
  if (!order.billing_address_id) return [3 /*break*/, 4];
996
917
  return [4 /*yield*/, addrRepo.findOne({
997
918
  where: { id: order.billing_address_id },
998
919
  })];
999
920
  case 2:
1000
- addr = _a.sent();
921
+ addr = _e.sent();
1001
922
  return [4 /*yield*/, addrRepo.save(__assign(__assign({}, addr), address))];
1002
923
  case 3:
1003
- _a.sent();
924
+ _e.sent();
1004
925
  return [3 /*break*/, 7];
1005
926
  case 4: return [4 /*yield*/, addrRepo.create(__assign({}, address))];
1006
927
  case 5:
1007
- created = _a.sent();
928
+ created = _e.sent();
1008
929
  return [4 /*yield*/, addrRepo.save(created)];
1009
930
  case 6:
1010
- _a.sent();
1011
- _a.label = 7;
931
+ _e.sent();
932
+ _e.label = 7;
1012
933
  case 7: return [2 /*return*/];
1013
934
  }
1014
935
  });
@@ -1016,23 +937,26 @@ var OrderService = /** @class */ (function (_super) {
1016
937
  };
1017
938
  /**
1018
939
  * Updates the order's shipping address.
1019
- * @param {object} order - the order to update
1020
- * @param {object} address - the value to set the shipping address to
1021
- * @return {Promise} the result of the update operation
940
+ * @param order - the order to update
941
+ * @param address - the value to set the shipping address to
942
+ * @return the result of the update operation
1022
943
  */
1023
- OrderService.prototype.updateShippingAddress_ = function (order, address) {
944
+ OrderService.prototype.updateShippingAddress = function (order, address) {
945
+ var _a, _b;
1024
946
  return __awaiter(this, void 0, void 0, function () {
1025
947
  var addrRepo, region, addr, created;
1026
- return __generator(this, function (_a) {
1027
- switch (_a.label) {
948
+ return __generator(this, function (_c) {
949
+ switch (_c.label) {
1028
950
  case 0:
1029
951
  addrRepo = this.manager_.getCustomRepository(this.addressRepository_);
1030
- address.country_code = address.country_code.toLowerCase();
1031
- return [4 /*yield*/, this.regionService_.retrieve(order.region_id, {
952
+ address.country_code = (_b = (_a = address.country_code) === null || _a === void 0 ? void 0 : _a.toLowerCase()) !== null && _b !== void 0 ? _b : null;
953
+ return [4 /*yield*/, this.regionService_
954
+ .withTransaction(this.manager_)
955
+ .retrieve(order.region_id, {
1032
956
  relations: ["countries"],
1033
957
  })];
1034
958
  case 1:
1035
- region = _a.sent();
959
+ region = _c.sent();
1036
960
  if (!region.countries.find(function (_a) {
1037
961
  var iso_2 = _a.iso_2;
1038
962
  return address.country_code === iso_2;
@@ -1044,17 +968,17 @@ var OrderService = /** @class */ (function (_super) {
1044
968
  where: { id: order.shipping_address_id },
1045
969
  })];
1046
970
  case 2:
1047
- addr = _a.sent();
971
+ addr = _c.sent();
1048
972
  return [4 /*yield*/, addrRepo.save(__assign(__assign({}, addr), address))];
1049
973
  case 3:
1050
- _a.sent();
974
+ _c.sent();
1051
975
  return [3 /*break*/, 6];
1052
976
  case 4:
1053
977
  created = addrRepo.create(__assign({}, address));
1054
978
  return [4 /*yield*/, addrRepo.save(created)];
1055
979
  case 5:
1056
- _a.sent();
1057
- _a.label = 6;
980
+ _c.sent();
981
+ _c.label = 6;
1058
982
  case 6: return [2 /*return*/];
1059
983
  }
1060
984
  });
@@ -1065,79 +989,81 @@ var OrderService = /** @class */ (function (_super) {
1065
989
  return __awaiter(this, void 0, void 0, function () {
1066
990
  var _this = this;
1067
991
  return __generator(this, function (_a) {
1068
- return [2 /*return*/, this.atomicPhase_(function (manager) { return __awaiter(_this, void 0, void 0, function () {
1069
- var order, shipping_methods, newMethod, methods, shipping_methods_1, shipping_methods_1_1, sm, e_7_1, result;
1070
- var e_7, _a;
1071
- return __generator(this, function (_b) {
1072
- switch (_b.label) {
1073
- case 0: return [4 /*yield*/, this.retrieve(orderId, {
1074
- select: ["subtotal"],
1075
- relations: [
1076
- "shipping_methods",
1077
- "shipping_methods.shipping_option",
1078
- "items",
1079
- "items.variant",
1080
- "items.variant.product",
1081
- ],
1082
- })];
1083
- case 1:
1084
- order = _b.sent();
1085
- shipping_methods = order.shipping_methods;
1086
- if (order.status === "canceled") {
1087
- throw new medusa_core_utils_1.MedusaError(medusa_core_utils_1.MedusaError.Types.NOT_ALLOWED, "A shipping method cannot be added to a canceled order");
1088
- }
1089
- return [4 /*yield*/, this.shippingOptionService_
1090
- .withTransaction(manager)
1091
- .createShippingMethod(optionId, data, __assign({ order: order }, config))];
1092
- case 2:
1093
- newMethod = _b.sent();
1094
- methods = [newMethod];
1095
- if (!shipping_methods.length) return [3 /*break*/, 11];
1096
- _b.label = 3;
1097
- case 3:
1098
- _b.trys.push([3, 9, 10, 11]);
1099
- shipping_methods_1 = __values(shipping_methods), shipping_methods_1_1 = shipping_methods_1.next();
1100
- _b.label = 4;
1101
- case 4:
1102
- if (!!shipping_methods_1_1.done) return [3 /*break*/, 8];
1103
- sm = shipping_methods_1_1.value;
1104
- if (!(sm.shipping_option.profile_id ===
1105
- newMethod.shipping_option.profile_id)) return [3 /*break*/, 6];
1106
- return [4 /*yield*/, this.shippingOptionService_
1107
- .withTransaction(manager)
1108
- .deleteShippingMethods(sm)];
1109
- case 5:
1110
- _b.sent();
1111
- return [3 /*break*/, 7];
1112
- case 6:
1113
- methods.push(sm);
1114
- _b.label = 7;
1115
- case 7:
1116
- shipping_methods_1_1 = shipping_methods_1.next();
1117
- return [3 /*break*/, 4];
1118
- case 8: return [3 /*break*/, 11];
1119
- case 9:
1120
- e_7_1 = _b.sent();
1121
- e_7 = { error: e_7_1 };
1122
- return [3 /*break*/, 11];
1123
- case 10:
1124
- try {
1125
- if (shipping_methods_1_1 && !shipping_methods_1_1.done && (_a = shipping_methods_1.return)) _a.call(shipping_methods_1);
1126
- }
1127
- finally { if (e_7) throw e_7.error; }
1128
- return [7 /*endfinally*/];
1129
- case 11: return [4 /*yield*/, this.retrieve(orderId)];
1130
- case 12:
1131
- result = _b.sent();
1132
- return [4 /*yield*/, this.eventBus_
1133
- .withTransaction(manager)
1134
- .emit(OrderService.Events.UPDATED, { id: result.id })];
1135
- case 13:
1136
- _b.sent();
1137
- return [2 /*return*/, result];
1138
- }
1139
- });
1140
- }); })];
992
+ switch (_a.label) {
993
+ case 0: return [4 /*yield*/, this.atomicPhase_(function (manager) { return __awaiter(_this, void 0, void 0, function () {
994
+ var order, shipping_methods, newMethod, shippingOptionServiceTx, methods, shipping_methods_1, shipping_methods_1_1, sm, e_7_1, result;
995
+ var e_7, _a;
996
+ return __generator(this, function (_b) {
997
+ switch (_b.label) {
998
+ case 0: return [4 /*yield*/, this.retrieve(orderId, {
999
+ select: ["subtotal"],
1000
+ relations: [
1001
+ "shipping_methods",
1002
+ "shipping_methods.shipping_option",
1003
+ "items",
1004
+ "items.variant",
1005
+ "items.variant.product",
1006
+ ],
1007
+ })];
1008
+ case 1:
1009
+ order = _b.sent();
1010
+ shipping_methods = order.shipping_methods;
1011
+ if (order.status === "canceled") {
1012
+ throw new medusa_core_utils_1.MedusaError(medusa_core_utils_1.MedusaError.Types.NOT_ALLOWED, "A shipping method cannot be added to a canceled order");
1013
+ }
1014
+ return [4 /*yield*/, this.shippingOptionService_
1015
+ .withTransaction(manager)
1016
+ .createShippingMethod(optionId, data !== null && data !== void 0 ? data : {}, __assign({ order: order }, config))];
1017
+ case 2:
1018
+ newMethod = _b.sent();
1019
+ shippingOptionServiceTx = this.shippingOptionService_.withTransaction(manager);
1020
+ methods = [newMethod];
1021
+ if (!shipping_methods.length) return [3 /*break*/, 11];
1022
+ _b.label = 3;
1023
+ case 3:
1024
+ _b.trys.push([3, 9, 10, 11]);
1025
+ shipping_methods_1 = __values(shipping_methods), shipping_methods_1_1 = shipping_methods_1.next();
1026
+ _b.label = 4;
1027
+ case 4:
1028
+ if (!!shipping_methods_1_1.done) return [3 /*break*/, 8];
1029
+ sm = shipping_methods_1_1.value;
1030
+ if (!(sm.shipping_option.profile_id ===
1031
+ newMethod.shipping_option.profile_id)) return [3 /*break*/, 6];
1032
+ return [4 /*yield*/, shippingOptionServiceTx.deleteShippingMethods(sm)];
1033
+ case 5:
1034
+ _b.sent();
1035
+ return [3 /*break*/, 7];
1036
+ case 6:
1037
+ methods.push(sm);
1038
+ _b.label = 7;
1039
+ case 7:
1040
+ shipping_methods_1_1 = shipping_methods_1.next();
1041
+ return [3 /*break*/, 4];
1042
+ case 8: return [3 /*break*/, 11];
1043
+ case 9:
1044
+ e_7_1 = _b.sent();
1045
+ e_7 = { error: e_7_1 };
1046
+ return [3 /*break*/, 11];
1047
+ case 10:
1048
+ try {
1049
+ if (shipping_methods_1_1 && !shipping_methods_1_1.done && (_a = shipping_methods_1.return)) _a.call(shipping_methods_1);
1050
+ }
1051
+ finally { if (e_7) throw e_7.error; }
1052
+ return [7 /*endfinally*/];
1053
+ case 11: return [4 /*yield*/, this.retrieve(orderId)];
1054
+ case 12:
1055
+ result = _b.sent();
1056
+ return [4 /*yield*/, this.eventBus_
1057
+ .withTransaction(manager)
1058
+ .emit(OrderService.Events.UPDATED, { id: result.id })];
1059
+ case 13:
1060
+ _b.sent();
1061
+ return [2 /*return*/, result];
1062
+ }
1063
+ });
1064
+ }); })];
1065
+ case 1: return [2 /*return*/, _a.sent()];
1066
+ }
1141
1067
  });
1142
1068
  });
1143
1069
  };
@@ -1145,111 +1071,115 @@ var OrderService = /** @class */ (function (_super) {
1145
1071
  * Updates an order. Metadata updates should
1146
1072
  * use dedicated method, e.g. `setMetadata` etc. The function
1147
1073
  * will throw errors if metadata updates are attempted.
1148
- * @param {string} orderId - the id of the order. Must be a string that
1074
+ * @param orderId - the id of the order. Must be a string that
1149
1075
  * can be casted to an ObjectId
1150
- * @param {object} update - an object with the update values.
1151
- * @return {Promise} resolves to the update result.
1076
+ * @param update - an object with the update values.
1077
+ * @return resolves to the update result.
1152
1078
  */
1153
1079
  OrderService.prototype.update = function (orderId, update) {
1154
1080
  return __awaiter(this, void 0, void 0, function () {
1155
1081
  var _this = this;
1156
1082
  return __generator(this, function (_a) {
1157
- return [2 /*return*/, this.atomicPhase_(function (manager) { return __awaiter(_this, void 0, void 0, function () {
1158
- var order, metadata, shipping_address, billing_address, no_notification, items, rest, items_1, items_1_1, item, e_8_1, _a, _b, _c, key, value, orderRepo, result;
1159
- var e_8, _d, e_9, _e;
1160
- return __generator(this, function (_f) {
1161
- switch (_f.label) {
1162
- case 0: return [4 /*yield*/, this.retrieve(orderId)];
1163
- case 1:
1164
- order = _f.sent();
1165
- if (order.status === "canceled") {
1166
- throw new medusa_core_utils_1.MedusaError(medusa_core_utils_1.MedusaError.Types.NOT_ALLOWED, "A canceled order cannot be updated");
1167
- }
1168
- if ((update.payment || update.items) &&
1169
- (order.fulfillment_status !== "not_fulfilled" ||
1170
- order.payment_status !== "awaiting" ||
1171
- order.status !== "pending")) {
1172
- throw new medusa_core_utils_1.MedusaError(medusa_core_utils_1.MedusaError.Types.NOT_ALLOWED, "Can't update shipping, billing, items and payment method when order is processed");
1173
- }
1174
- if (update.status || update.fulfillment_status || update.payment_status) {
1175
- throw new medusa_core_utils_1.MedusaError(medusa_core_utils_1.MedusaError.Types.NOT_ALLOWED, "Can't update order statuses. This will happen automatically. Use metadata in order for additional statuses");
1176
- }
1177
- metadata = update.metadata, shipping_address = update.shipping_address, billing_address = update.billing_address, no_notification = update.no_notification, items = update.items, rest = __rest(update, ["metadata", "shipping_address", "billing_address", "no_notification", "items"]);
1178
- if (update.metadata) {
1179
- order.metadata = this.setMetadata_(order, metadata);
1180
- }
1181
- if (!update.shipping_address) return [3 /*break*/, 3];
1182
- return [4 /*yield*/, this.updateShippingAddress_(order, shipping_address)];
1183
- case 2:
1184
- _f.sent();
1185
- _f.label = 3;
1186
- case 3:
1187
- if (!update.billing_address) return [3 /*break*/, 5];
1188
- return [4 /*yield*/, this.updateBillingAddress_(order, billing_address)];
1189
- case 4:
1190
- _f.sent();
1191
- _f.label = 5;
1192
- case 5:
1193
- if (update.no_notification) {
1194
- order.no_notification = no_notification;
1195
- }
1196
- if (!update.items) return [3 /*break*/, 13];
1197
- _f.label = 6;
1198
- case 6:
1199
- _f.trys.push([6, 11, 12, 13]);
1200
- items_1 = __values(items), items_1_1 = items_1.next();
1201
- _f.label = 7;
1202
- case 7:
1203
- if (!!items_1_1.done) return [3 /*break*/, 10];
1204
- item = items_1_1.value;
1205
- return [4 /*yield*/, this.lineItemService_.withTransaction(manager).create(__assign(__assign({}, item), { order_id: orderId }))];
1206
- case 8:
1207
- _f.sent();
1208
- _f.label = 9;
1209
- case 9:
1210
- items_1_1 = items_1.next();
1211
- return [3 /*break*/, 7];
1212
- case 10: return [3 /*break*/, 13];
1213
- case 11:
1214
- e_8_1 = _f.sent();
1215
- e_8 = { error: e_8_1 };
1216
- return [3 /*break*/, 13];
1217
- case 12:
1218
- try {
1219
- if (items_1_1 && !items_1_1.done && (_d = items_1.return)) _d.call(items_1);
1220
- }
1221
- finally { if (e_8) throw e_8.error; }
1222
- return [7 /*endfinally*/];
1223
- case 13:
1224
- try {
1225
- for (_a = __values(Object.entries(rest)), _b = _a.next(); !_b.done; _b = _a.next()) {
1226
- _c = __read(_b.value, 2), key = _c[0], value = _c[1];
1227
- order[key] = value;
1083
+ switch (_a.label) {
1084
+ case 0: return [4 /*yield*/, this.atomicPhase_(function (manager) { return __awaiter(_this, void 0, void 0, function () {
1085
+ var order, metadata, shipping_address, billing_address, no_notification, items, rest, lineItemServiceTx, _a, _b, item, e_8_1, _c, _d, _e, key, value, orderRepo, result;
1086
+ var e_8, _f, e_9, _g;
1087
+ return __generator(this, function (_h) {
1088
+ switch (_h.label) {
1089
+ case 0: return [4 /*yield*/, this.retrieve(orderId)];
1090
+ case 1:
1091
+ order = _h.sent();
1092
+ if (order.status === "canceled") {
1093
+ throw new medusa_core_utils_1.MedusaError(medusa_core_utils_1.MedusaError.Types.NOT_ALLOWED, "A canceled order cannot be updated");
1228
1094
  }
1229
- }
1230
- catch (e_9_1) { e_9 = { error: e_9_1 }; }
1231
- finally {
1095
+ if ((update.payment || update.items) &&
1096
+ (order.fulfillment_status !== "not_fulfilled" ||
1097
+ order.payment_status !== "awaiting" ||
1098
+ order.status !== "pending")) {
1099
+ throw new medusa_core_utils_1.MedusaError(medusa_core_utils_1.MedusaError.Types.NOT_ALLOWED, "Can't update shipping, billing, items and payment method when order is processed");
1100
+ }
1101
+ if (update.status || update.fulfillment_status || update.payment_status) {
1102
+ throw new medusa_core_utils_1.MedusaError(medusa_core_utils_1.MedusaError.Types.NOT_ALLOWED, "Can't update order statuses. This will happen automatically. Use metadata in order for additional statuses");
1103
+ }
1104
+ metadata = update.metadata, shipping_address = update.shipping_address, billing_address = update.billing_address, no_notification = update.no_notification, items = update.items, rest = __rest(update, ["metadata", "shipping_address", "billing_address", "no_notification", "items"]);
1105
+ if (update.metadata) {
1106
+ order.metadata = (0, utils_1.setMetadata)(order, metadata !== null && metadata !== void 0 ? metadata : {});
1107
+ }
1108
+ if (!update.shipping_address) return [3 /*break*/, 3];
1109
+ return [4 /*yield*/, this.updateShippingAddress(order, shipping_address)];
1110
+ case 2:
1111
+ _h.sent();
1112
+ _h.label = 3;
1113
+ case 3:
1114
+ if (!update.billing_address) return [3 /*break*/, 5];
1115
+ return [4 /*yield*/, this.updateBillingAddress(order, billing_address)];
1116
+ case 4:
1117
+ _h.sent();
1118
+ _h.label = 5;
1119
+ case 5:
1120
+ if (update.no_notification) {
1121
+ order.no_notification = no_notification !== null && no_notification !== void 0 ? no_notification : false;
1122
+ }
1123
+ lineItemServiceTx = this.lineItemService_.withTransaction(manager);
1124
+ if (!update.items) return [3 /*break*/, 13];
1125
+ _h.label = 6;
1126
+ case 6:
1127
+ _h.trys.push([6, 11, 12, 13]);
1128
+ _a = __values(items), _b = _a.next();
1129
+ _h.label = 7;
1130
+ case 7:
1131
+ if (!!_b.done) return [3 /*break*/, 10];
1132
+ item = _b.value;
1133
+ return [4 /*yield*/, lineItemServiceTx.create(__assign(__assign({}, item), { order_id: orderId }))];
1134
+ case 8:
1135
+ _h.sent();
1136
+ _h.label = 9;
1137
+ case 9:
1138
+ _b = _a.next();
1139
+ return [3 /*break*/, 7];
1140
+ case 10: return [3 /*break*/, 13];
1141
+ case 11:
1142
+ e_8_1 = _h.sent();
1143
+ e_8 = { error: e_8_1 };
1144
+ return [3 /*break*/, 13];
1145
+ case 12:
1232
1146
  try {
1233
- if (_b && !_b.done && (_e = _a.return)) _e.call(_a);
1147
+ if (_b && !_b.done && (_f = _a.return)) _f.call(_a);
1234
1148
  }
1235
- finally { if (e_9) throw e_9.error; }
1236
- }
1237
- orderRepo = manager.getCustomRepository(this.orderRepository_);
1238
- return [4 /*yield*/, orderRepo.save(order)];
1239
- case 14:
1240
- result = _f.sent();
1241
- return [4 /*yield*/, this.eventBus_
1242
- .withTransaction(manager)
1243
- .emit(OrderService.Events.UPDATED, {
1244
- id: orderId,
1245
- no_notification: order.no_notification,
1246
- })];
1247
- case 15:
1248
- _f.sent();
1249
- return [2 /*return*/, result];
1250
- }
1251
- });
1252
- }); })];
1149
+ finally { if (e_8) throw e_8.error; }
1150
+ return [7 /*endfinally*/];
1151
+ case 13:
1152
+ try {
1153
+ for (_c = __values(Object.entries(rest)), _d = _c.next(); !_d.done; _d = _c.next()) {
1154
+ _e = __read(_d.value, 2), key = _e[0], value = _e[1];
1155
+ order[key] = value;
1156
+ }
1157
+ }
1158
+ catch (e_9_1) { e_9 = { error: e_9_1 }; }
1159
+ finally {
1160
+ try {
1161
+ if (_d && !_d.done && (_g = _c.return)) _g.call(_c);
1162
+ }
1163
+ finally { if (e_9) throw e_9.error; }
1164
+ }
1165
+ orderRepo = manager.getCustomRepository(this.orderRepository_);
1166
+ return [4 /*yield*/, orderRepo.save(order)];
1167
+ case 14:
1168
+ result = _h.sent();
1169
+ return [4 /*yield*/, this.eventBus_
1170
+ .withTransaction(manager)
1171
+ .emit(OrderService.Events.UPDATED, {
1172
+ id: orderId,
1173
+ no_notification: order.no_notification,
1174
+ })];
1175
+ case 15:
1176
+ _h.sent();
1177
+ return [2 /*return*/, result];
1178
+ }
1179
+ });
1180
+ }); })];
1181
+ case 1: return [2 /*return*/, _a.sent()];
1182
+ }
1253
1183
  });
1254
1184
  });
1255
1185
  };
@@ -1257,229 +1187,234 @@ var OrderService = /** @class */ (function (_super) {
1257
1187
  * Cancels an order.
1258
1188
  * Throws if fulfillment process has been initiated.
1259
1189
  * Throws if payment process has been initiated.
1260
- * @param {string} orderId - id of order to cancel.
1261
- * @return {Promise} result of the update operation.
1190
+ * @param orderId - id of order to cancel.
1191
+ * @return result of the update operation.
1262
1192
  */
1263
1193
  OrderService.prototype.cancel = function (orderId) {
1264
1194
  return __awaiter(this, void 0, void 0, function () {
1265
1195
  var _this = this;
1266
1196
  return __generator(this, function (_a) {
1267
- return [2 /*return*/, this.atomicPhase_(function (manager) { return __awaiter(_this, void 0, void 0, function () {
1268
- var order, throwErrorIf, notCanceled, _a, _b, item, e_10_1, _c, _d, p, e_11_1, orderRepo, result;
1269
- var e_10, _e, e_11, _f;
1270
- var _g;
1271
- return __generator(this, function (_h) {
1272
- switch (_h.label) {
1273
- case 0: return [4 /*yield*/, this.retrieve(orderId, {
1274
- relations: [
1275
- "fulfillments",
1276
- "payments",
1277
- "returns",
1278
- "claims",
1279
- "swaps",
1280
- "items",
1281
- ],
1282
- })];
1283
- case 1:
1284
- order = _h.sent();
1285
- if (((_g = order.refunds) === null || _g === void 0 ? void 0 : _g.length) > 0) {
1286
- throw new medusa_core_utils_1.MedusaError(medusa_core_utils_1.MedusaError.Types.NOT_ALLOWED, "Order with refund(s) cannot be canceled");
1287
- }
1288
- throwErrorIf = function (arr, pred, type) {
1289
- return arr === null || arr === void 0 ? void 0 : arr.filter(pred).find(function (_) {
1290
- throw new medusa_core_utils_1.MedusaError(medusa_core_utils_1.MedusaError.Types.NOT_ALLOWED, "All ".concat(type, " must be canceled before canceling an order"));
1291
- });
1292
- };
1293
- notCanceled = function (o) { return !o.canceled_at; };
1294
- throwErrorIf(order.fulfillments, notCanceled, "fulfillments");
1295
- throwErrorIf(order.returns, function (r) { return r.status !== "canceled"; }, "returns");
1296
- throwErrorIf(order.swaps, notCanceled, "swaps");
1297
- throwErrorIf(order.claims, notCanceled, "claims");
1298
- _h.label = 2;
1299
- case 2:
1300
- _h.trys.push([2, 7, 8, 9]);
1301
- _a = __values(order.items), _b = _a.next();
1302
- _h.label = 3;
1303
- case 3:
1304
- if (!!_b.done) return [3 /*break*/, 6];
1305
- item = _b.value;
1306
- return [4 /*yield*/, this.inventoryService_
1307
- .withTransaction(manager)
1308
- .adjustInventory(item.variant_id, item.quantity)];
1309
- case 4:
1310
- _h.sent();
1311
- _h.label = 5;
1312
- case 5:
1313
- _b = _a.next();
1314
- return [3 /*break*/, 3];
1315
- case 6: return [3 /*break*/, 9];
1316
- case 7:
1317
- e_10_1 = _h.sent();
1318
- e_10 = { error: e_10_1 };
1319
- return [3 /*break*/, 9];
1320
- case 8:
1321
- try {
1322
- if (_b && !_b.done && (_e = _a.return)) _e.call(_a);
1323
- }
1324
- finally { if (e_10) throw e_10.error; }
1325
- return [7 /*endfinally*/];
1326
- case 9:
1327
- _h.trys.push([9, 14, 15, 16]);
1328
- _c = __values(order.payments), _d = _c.next();
1329
- _h.label = 10;
1330
- case 10:
1331
- if (!!_d.done) return [3 /*break*/, 13];
1332
- p = _d.value;
1333
- return [4 /*yield*/, this.paymentProviderService_
1334
- .withTransaction(manager)
1335
- .cancelPayment(p)];
1336
- case 11:
1337
- _h.sent();
1338
- _h.label = 12;
1339
- case 12:
1340
- _d = _c.next();
1341
- return [3 /*break*/, 10];
1342
- case 13: return [3 /*break*/, 16];
1343
- case 14:
1344
- e_11_1 = _h.sent();
1345
- e_11 = { error: e_11_1 };
1346
- return [3 /*break*/, 16];
1347
- case 15:
1348
- try {
1349
- if (_d && !_d.done && (_f = _c.return)) _f.call(_c);
1350
- }
1351
- finally { if (e_11) throw e_11.error; }
1352
- return [7 /*endfinally*/];
1353
- case 16:
1354
- order.status = "canceled";
1355
- order.fulfillment_status = "canceled";
1356
- order.payment_status = "canceled";
1357
- order.canceled_at = new Date();
1358
- orderRepo = manager.getCustomRepository(this.orderRepository_);
1359
- return [4 /*yield*/, orderRepo.save(order)];
1360
- case 17:
1361
- result = _h.sent();
1362
- return [4 /*yield*/, this.eventBus_
1363
- .withTransaction(manager)
1364
- .emit(OrderService.Events.CANCELED, {
1365
- id: order.id,
1366
- no_notification: order.no_notification,
1197
+ switch (_a.label) {
1198
+ case 0: return [4 /*yield*/, this.atomicPhase_(function (manager) { return __awaiter(_this, void 0, void 0, function () {
1199
+ var order, throwErrorIf, notCanceled, inventoryServiceTx, _a, _b, item, e_10_1, paymentProviderServiceTx, _c, _d, p, e_11_1, orderRepo, result;
1200
+ var e_10, _e, e_11, _f;
1201
+ var _g;
1202
+ return __generator(this, function (_h) {
1203
+ switch (_h.label) {
1204
+ case 0: return [4 /*yield*/, this.retrieve(orderId, {
1205
+ relations: [
1206
+ "fulfillments",
1207
+ "payments",
1208
+ "returns",
1209
+ "claims",
1210
+ "swaps",
1211
+ "items",
1212
+ ],
1367
1213
  })];
1368
- case 18:
1369
- _h.sent();
1370
- return [2 /*return*/, result];
1371
- }
1372
- });
1373
- }); })];
1214
+ case 1:
1215
+ order = _h.sent();
1216
+ if (((_g = order.refunds) === null || _g === void 0 ? void 0 : _g.length) > 0) {
1217
+ throw new medusa_core_utils_1.MedusaError(medusa_core_utils_1.MedusaError.Types.NOT_ALLOWED, "Order with refund(s) cannot be canceled");
1218
+ }
1219
+ throwErrorIf = function (arr, pred, type) {
1220
+ if (arr === null || arr === void 0 ? void 0 : arr.filter(pred).length) {
1221
+ throw new medusa_core_utils_1.MedusaError(medusa_core_utils_1.MedusaError.Types.NOT_ALLOWED, "All ".concat(type, " must be canceled before canceling an order"));
1222
+ }
1223
+ };
1224
+ notCanceled = function (o) { return !o.canceled_at; };
1225
+ throwErrorIf(order.fulfillments, notCanceled, "fulfillments");
1226
+ throwErrorIf(order.returns, function (r) { return r.status !== "canceled"; }, "returns");
1227
+ throwErrorIf(order.swaps, notCanceled, "swaps");
1228
+ throwErrorIf(order.claims, notCanceled, "claims");
1229
+ inventoryServiceTx = this.inventoryService_.withTransaction(manager);
1230
+ _h.label = 2;
1231
+ case 2:
1232
+ _h.trys.push([2, 7, 8, 9]);
1233
+ _a = __values(order.items), _b = _a.next();
1234
+ _h.label = 3;
1235
+ case 3:
1236
+ if (!!_b.done) return [3 /*break*/, 6];
1237
+ item = _b.value;
1238
+ return [4 /*yield*/, inventoryServiceTx.adjustInventory(item.variant_id, item.quantity)];
1239
+ case 4:
1240
+ _h.sent();
1241
+ _h.label = 5;
1242
+ case 5:
1243
+ _b = _a.next();
1244
+ return [3 /*break*/, 3];
1245
+ case 6: return [3 /*break*/, 9];
1246
+ case 7:
1247
+ e_10_1 = _h.sent();
1248
+ e_10 = { error: e_10_1 };
1249
+ return [3 /*break*/, 9];
1250
+ case 8:
1251
+ try {
1252
+ if (_b && !_b.done && (_e = _a.return)) _e.call(_a);
1253
+ }
1254
+ finally { if (e_10) throw e_10.error; }
1255
+ return [7 /*endfinally*/];
1256
+ case 9:
1257
+ paymentProviderServiceTx = this.paymentProviderService_.withTransaction(manager);
1258
+ _h.label = 10;
1259
+ case 10:
1260
+ _h.trys.push([10, 15, 16, 17]);
1261
+ _c = __values(order.payments), _d = _c.next();
1262
+ _h.label = 11;
1263
+ case 11:
1264
+ if (!!_d.done) return [3 /*break*/, 14];
1265
+ p = _d.value;
1266
+ return [4 /*yield*/, paymentProviderServiceTx.cancelPayment(p)];
1267
+ case 12:
1268
+ _h.sent();
1269
+ _h.label = 13;
1270
+ case 13:
1271
+ _d = _c.next();
1272
+ return [3 /*break*/, 11];
1273
+ case 14: return [3 /*break*/, 17];
1274
+ case 15:
1275
+ e_11_1 = _h.sent();
1276
+ e_11 = { error: e_11_1 };
1277
+ return [3 /*break*/, 17];
1278
+ case 16:
1279
+ try {
1280
+ if (_d && !_d.done && (_f = _c.return)) _f.call(_c);
1281
+ }
1282
+ finally { if (e_11) throw e_11.error; }
1283
+ return [7 /*endfinally*/];
1284
+ case 17:
1285
+ order.status = models_1.OrderStatus.CANCELED;
1286
+ order.fulfillment_status = models_1.FulfillmentStatus.CANCELED;
1287
+ order.payment_status = models_1.PaymentStatus.CANCELED;
1288
+ order.canceled_at = new Date();
1289
+ orderRepo = manager.getCustomRepository(this.orderRepository_);
1290
+ return [4 /*yield*/, orderRepo.save(order)];
1291
+ case 18:
1292
+ result = _h.sent();
1293
+ return [4 /*yield*/, this.eventBus_
1294
+ .withTransaction(manager)
1295
+ .emit(OrderService.Events.CANCELED, {
1296
+ id: order.id,
1297
+ no_notification: order.no_notification,
1298
+ })];
1299
+ case 19:
1300
+ _h.sent();
1301
+ return [2 /*return*/, result];
1302
+ }
1303
+ });
1304
+ }); })];
1305
+ case 1: return [2 /*return*/, _a.sent()];
1306
+ }
1374
1307
  });
1375
1308
  });
1376
1309
  };
1377
1310
  /**
1378
1311
  * Captures payment for an order.
1379
- * @param {string} orderId - id of order to capture payment for.
1380
- * @return {Promise} result of the update operation.
1312
+ * @param orderId - id of order to capture payment for.
1313
+ * @return result of the update operation.
1381
1314
  */
1382
1315
  OrderService.prototype.capturePayment = function (orderId) {
1383
1316
  return __awaiter(this, void 0, void 0, function () {
1384
1317
  var _this = this;
1385
1318
  return __generator(this, function (_a) {
1386
- return [2 /*return*/, this.atomicPhase_(function (manager) { return __awaiter(_this, void 0, void 0, function () {
1387
- var orderRepo, order, payments, _loop_2, this_2, _a, _b, p, e_12_1, result;
1388
- var e_12, _c;
1389
- var _this = this;
1390
- return __generator(this, function (_d) {
1391
- switch (_d.label) {
1392
- case 0:
1393
- orderRepo = manager.getCustomRepository(this.orderRepository_);
1394
- return [4 /*yield*/, this.retrieve(orderId, { relations: ["payments"] })];
1395
- case 1:
1396
- order = _d.sent();
1397
- if (order.status === "canceled") {
1398
- throw new medusa_core_utils_1.MedusaError(medusa_core_utils_1.MedusaError.Types.NOT_ALLOWED, "A canceled order cannot capture payment");
1399
- }
1400
- payments = [];
1401
- _loop_2 = function (p) {
1402
- var result_1;
1403
- return __generator(this, function (_e) {
1404
- switch (_e.label) {
1405
- case 0:
1406
- if (!(p.captured_at === null)) return [3 /*break*/, 2];
1407
- return [4 /*yield*/, this_2.paymentProviderService_
1408
- .withTransaction(manager)
1409
- .capturePayment(p)
1410
- .catch(function (err) {
1411
- _this.eventBus_
1412
- .withTransaction(manager)
1413
- .emit(OrderService.Events.PAYMENT_CAPTURE_FAILED, {
1414
- id: orderId,
1415
- payment_id: p.id,
1416
- error: err,
1417
- no_notification: order.no_notification,
1418
- });
1419
- })];
1420
- case 1:
1421
- result_1 = _e.sent();
1422
- if (result_1) {
1423
- payments.push(result_1);
1424
- }
1425
- else {
1319
+ switch (_a.label) {
1320
+ case 0: return [4 /*yield*/, this.atomicPhase_(function (manager) { return __awaiter(_this, void 0, void 0, function () {
1321
+ var orderRepo, order, paymentProviderServiceTx, payments, _loop_2, _a, _b, p, e_12_1, result;
1322
+ var e_12, _c;
1323
+ var _this = this;
1324
+ return __generator(this, function (_d) {
1325
+ switch (_d.label) {
1326
+ case 0:
1327
+ orderRepo = manager.getCustomRepository(this.orderRepository_);
1328
+ return [4 /*yield*/, this.retrieve(orderId, { relations: ["payments"] })];
1329
+ case 1:
1330
+ order = _d.sent();
1331
+ if (order.status === "canceled") {
1332
+ throw new medusa_core_utils_1.MedusaError(medusa_core_utils_1.MedusaError.Types.NOT_ALLOWED, "A canceled order cannot capture payment");
1333
+ }
1334
+ paymentProviderServiceTx = this.paymentProviderService_.withTransaction(manager);
1335
+ payments = [];
1336
+ _loop_2 = function (p) {
1337
+ var result_1;
1338
+ return __generator(this, function (_e) {
1339
+ switch (_e.label) {
1340
+ case 0:
1341
+ if (!(p.captured_at === null)) return [3 /*break*/, 2];
1342
+ return [4 /*yield*/, paymentProviderServiceTx
1343
+ .capturePayment(p)
1344
+ .catch(function (err) {
1345
+ _this.eventBus_
1346
+ .withTransaction(manager)
1347
+ .emit(OrderService.Events.PAYMENT_CAPTURE_FAILED, {
1348
+ id: orderId,
1349
+ payment_id: p.id,
1350
+ error: err,
1351
+ no_notification: order.no_notification,
1352
+ });
1353
+ })];
1354
+ case 1:
1355
+ result_1 = _e.sent();
1356
+ if (result_1) {
1357
+ payments.push(result_1);
1358
+ }
1359
+ else {
1360
+ payments.push(p);
1361
+ }
1362
+ return [3 /*break*/, 3];
1363
+ case 2:
1426
1364
  payments.push(p);
1427
- }
1428
- return [3 /*break*/, 3];
1429
- case 2:
1430
- payments.push(p);
1431
- _e.label = 3;
1432
- case 3: return [2 /*return*/];
1433
- }
1434
- });
1435
- };
1436
- this_2 = this;
1437
- _d.label = 2;
1438
- case 2:
1439
- _d.trys.push([2, 7, 8, 9]);
1440
- _a = __values(order.payments), _b = _a.next();
1441
- _d.label = 3;
1442
- case 3:
1443
- if (!!_b.done) return [3 /*break*/, 6];
1444
- p = _b.value;
1445
- return [5 /*yield**/, _loop_2(p)];
1446
- case 4:
1447
- _d.sent();
1448
- _d.label = 5;
1449
- case 5:
1450
- _b = _a.next();
1451
- return [3 /*break*/, 3];
1452
- case 6: return [3 /*break*/, 9];
1453
- case 7:
1454
- e_12_1 = _d.sent();
1455
- e_12 = { error: e_12_1 };
1456
- return [3 /*break*/, 9];
1457
- case 8:
1458
- try {
1459
- if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
1460
- }
1461
- finally { if (e_12) throw e_12.error; }
1462
- return [7 /*endfinally*/];
1463
- case 9:
1464
- order.payments = payments;
1465
- order.payment_status = payments.every(function (p) { return p.captured_at !== null; })
1466
- ? "captured"
1467
- : "requires_action";
1468
- return [4 /*yield*/, orderRepo.save(order)];
1469
- case 10:
1470
- result = _d.sent();
1471
- if (order.payment_status === "captured") {
1472
- this.eventBus_
1473
- .withTransaction(manager)
1474
- .emit(OrderService.Events.PAYMENT_CAPTURED, {
1475
- id: result.id,
1476
- no_notification: order.no_notification,
1477
- });
1478
- }
1479
- return [2 /*return*/, result];
1480
- }
1481
- });
1482
- }); })];
1365
+ _e.label = 3;
1366
+ case 3: return [2 /*return*/];
1367
+ }
1368
+ });
1369
+ };
1370
+ _d.label = 2;
1371
+ case 2:
1372
+ _d.trys.push([2, 7, 8, 9]);
1373
+ _a = __values(order.payments), _b = _a.next();
1374
+ _d.label = 3;
1375
+ case 3:
1376
+ if (!!_b.done) return [3 /*break*/, 6];
1377
+ p = _b.value;
1378
+ return [5 /*yield**/, _loop_2(p)];
1379
+ case 4:
1380
+ _d.sent();
1381
+ _d.label = 5;
1382
+ case 5:
1383
+ _b = _a.next();
1384
+ return [3 /*break*/, 3];
1385
+ case 6: return [3 /*break*/, 9];
1386
+ case 7:
1387
+ e_12_1 = _d.sent();
1388
+ e_12 = { error: e_12_1 };
1389
+ return [3 /*break*/, 9];
1390
+ case 8:
1391
+ try {
1392
+ if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
1393
+ }
1394
+ finally { if (e_12) throw e_12.error; }
1395
+ return [7 /*endfinally*/];
1396
+ case 9:
1397
+ order.payments = payments;
1398
+ order.payment_status = payments.every(function (p) { return p.captured_at !== null; })
1399
+ ? models_1.PaymentStatus.CAPTURED
1400
+ : models_1.PaymentStatus.REQUIRES_ACTION;
1401
+ return [4 /*yield*/, orderRepo.save(order)];
1402
+ case 10:
1403
+ result = _d.sent();
1404
+ if (order.payment_status === models_1.PaymentStatus.CAPTURED) {
1405
+ this.eventBus_
1406
+ .withTransaction(manager)
1407
+ .emit(OrderService.Events.PAYMENT_CAPTURED, {
1408
+ id: result.id,
1409
+ no_notification: order.no_notification,
1410
+ });
1411
+ }
1412
+ return [2 /*return*/, result];
1413
+ }
1414
+ });
1415
+ }); })];
1416
+ case 1: return [2 /*return*/, _a.sent()];
1417
+ }
1483
1418
  });
1484
1419
  });
1485
1420
  };
@@ -1488,13 +1423,13 @@ var OrderService = /** @class */ (function (_super) {
1488
1423
  * fulfillable quantity is lower than the requested fulfillment quantity.
1489
1424
  * Fulfillable quantity is calculated by subtracting the already fulfilled
1490
1425
  * quantity from the quantity that was originally purchased.
1491
- * @param {LineItem} item - the line item to check has sufficient fulfillable
1426
+ * @param item - the line item to check has sufficient fulfillable
1492
1427
  * quantity.
1493
- * @param {number} quantity - the quantity that is requested to be fulfilled.
1494
- * @return {LineItem} a line item that has the requested fulfillment quantity
1428
+ * @param quantity - the quantity that is requested to be fulfilled.
1429
+ * @return a line item that has the requested fulfillment quantity
1495
1430
  * set.
1496
1431
  */
1497
- OrderService.prototype.validateFulfillmentLineItem_ = function (item, quantity) {
1432
+ OrderService.prototype.validateFulfillmentLineItem = function (item, quantity) {
1498
1433
  if (!item) {
1499
1434
  // This will in most cases be called by a webhook so to ensure that
1500
1435
  // things go through smoothly in instances where extra items outside
@@ -1511,10 +1446,10 @@ var OrderService = /** @class */ (function (_super) {
1511
1446
  * In a situation where the order has more than one shipping method,
1512
1447
  * we need to partition the order items, such that they can be sent
1513
1448
  * to their respective fulfillment provider.
1514
- * @param {string} orderId - id of order to cancel.
1515
- * @param {Object} itemsToFulfill - items to fulfil.
1516
- * @param {Object} config - the config to cancel.
1517
- * @return {Promise} result of the update operation.
1449
+ * @param orderId - id of order to cancel.
1450
+ * @param itemsToFulfill - items to fulfil.
1451
+ * @param config - the config to cancel.
1452
+ * @return result of the update operation.
1518
1453
  */
1519
1454
  OrderService.prototype.createFulfillment = function (orderId, itemsToFulfill, config) {
1520
1455
  if (config === void 0) { config = {
@@ -1525,228 +1460,234 @@ var OrderService = /** @class */ (function (_super) {
1525
1460
  var metadata, no_notification;
1526
1461
  var _this = this;
1527
1462
  return __generator(this, function (_a) {
1528
- metadata = config.metadata, no_notification = config.no_notification;
1529
- return [2 /*return*/, this.atomicPhase_(function (manager) { return __awaiter(_this, void 0, void 0, function () {
1530
- var order, fulfillments, successfullyFulfilled, fulfillments_1, fulfillments_1_1, f, _loop_3, this_3, _a, _b, item, e_13_1, orderRepo, result, evaluatedNoNotification, fulfillments_2, fulfillments_2_1, fulfillment, e_14_1;
1531
- var e_15, _c, e_13, _d, e_14, _e;
1532
- var _f;
1533
- return __generator(this, function (_g) {
1534
- switch (_g.label) {
1535
- case 0: return [4 /*yield*/, this.retrieve(orderId, {
1536
- select: [
1537
- "subtotal",
1538
- "shipping_total",
1539
- "discount_total",
1540
- "tax_total",
1541
- "gift_card_total",
1542
- "total",
1543
- ],
1544
- relations: [
1545
- "discounts",
1546
- "discounts.rule",
1547
- "region",
1548
- "fulfillments",
1549
- "shipping_address",
1550
- "billing_address",
1551
- "shipping_methods",
1552
- "shipping_methods.shipping_option",
1553
- "items",
1554
- "items.variant",
1555
- "items.variant.product",
1556
- "payments",
1557
- ],
1558
- })];
1559
- case 1:
1560
- order = _g.sent();
1561
- if (order.status === "canceled") {
1562
- throw new medusa_core_utils_1.MedusaError(medusa_core_utils_1.MedusaError.Types.NOT_ALLOWED, "A canceled order cannot be fulfilled");
1563
- }
1564
- if (!((_f = order.shipping_methods) === null || _f === void 0 ? void 0 : _f.length)) {
1565
- throw new medusa_core_utils_1.MedusaError(medusa_core_utils_1.MedusaError.Types.NOT_ALLOWED, "Cannot fulfill an order that lacks shipping methods");
1566
- }
1567
- return [4 /*yield*/, this.fulfillmentService_
1568
- .withTransaction(manager)
1569
- .createFulfillment(order, itemsToFulfill, {
1570
- metadata: metadata,
1571
- no_notification: no_notification,
1572
- order_id: orderId,
1573
- })];
1574
- case 2:
1575
- fulfillments = _g.sent();
1576
- successfullyFulfilled = [];
1577
- try {
1578
- for (fulfillments_1 = __values(fulfillments), fulfillments_1_1 = fulfillments_1.next(); !fulfillments_1_1.done; fulfillments_1_1 = fulfillments_1.next()) {
1579
- f = fulfillments_1_1.value;
1580
- successfullyFulfilled = __spreadArray(__spreadArray([], __read(successfullyFulfilled), false), __read(f.items), false);
1581
- }
1582
- }
1583
- catch (e_15_1) { e_15 = { error: e_15_1 }; }
1584
- finally {
1585
- try {
1586
- if (fulfillments_1_1 && !fulfillments_1_1.done && (_c = fulfillments_1.return)) _c.call(fulfillments_1);
1587
- }
1588
- finally { if (e_15) throw e_15.error; }
1589
- }
1590
- order.fulfillment_status = "fulfilled";
1591
- _loop_3 = function (item) {
1592
- var fulfillmentItem, fulfilledQuantity;
1593
- return __generator(this, function (_h) {
1594
- switch (_h.label) {
1595
- case 0:
1596
- fulfillmentItem = successfullyFulfilled.find(function (f) { return item.id === f.item_id; });
1597
- if (!fulfillmentItem) return [3 /*break*/, 2];
1598
- fulfilledQuantity = (item.fulfilled_quantity || 0) + fulfillmentItem.quantity;
1599
- // Update the fulfilled quantity
1600
- return [4 /*yield*/, this_3.lineItemService_.withTransaction(manager).update(item.id, {
1601
- fulfilled_quantity: fulfilledQuantity,
1602
- })];
1603
- case 1:
1604
- // Update the fulfilled quantity
1605
- _h.sent();
1606
- if (item.quantity !== fulfilledQuantity) {
1607
- order.fulfillment_status = "partially_fulfilled";
1608
- }
1609
- return [3 /*break*/, 3];
1610
- case 2:
1611
- if (item.quantity !== item.fulfilled_quantity) {
1612
- order.fulfillment_status = "partially_fulfilled";
1463
+ switch (_a.label) {
1464
+ case 0:
1465
+ metadata = config.metadata, no_notification = config.no_notification;
1466
+ return [4 /*yield*/, this.atomicPhase_(function (manager) { return __awaiter(_this, void 0, void 0, function () {
1467
+ var order, fulfillments, successfullyFulfilled, fulfillments_1, fulfillments_1_1, f, _loop_3, this_1, _a, _b, item, e_13_1, orderRepo, result, evaluatedNoNotification, eventBusTx, fulfillments_2, fulfillments_2_1, fulfillment, e_14_1;
1468
+ var e_15, _c, e_13, _d, e_14, _e;
1469
+ var _f;
1470
+ return __generator(this, function (_g) {
1471
+ switch (_g.label) {
1472
+ case 0: return [4 /*yield*/, this.retrieve(orderId, {
1473
+ select: [
1474
+ "subtotal",
1475
+ "shipping_total",
1476
+ "discount_total",
1477
+ "tax_total",
1478
+ "gift_card_total",
1479
+ "total",
1480
+ ],
1481
+ relations: [
1482
+ "discounts",
1483
+ "discounts.rule",
1484
+ "region",
1485
+ "fulfillments",
1486
+ "shipping_address",
1487
+ "billing_address",
1488
+ "shipping_methods",
1489
+ "shipping_methods.shipping_option",
1490
+ "items",
1491
+ "items.adjustments",
1492
+ "items.variant",
1493
+ "items.variant.product",
1494
+ "payments",
1495
+ ],
1496
+ })];
1497
+ case 1:
1498
+ order = _g.sent();
1499
+ if (order.status === models_1.OrderStatus.CANCELED) {
1500
+ throw new medusa_core_utils_1.MedusaError(medusa_core_utils_1.MedusaError.Types.NOT_ALLOWED, "A canceled order cannot be fulfilled");
1501
+ }
1502
+ if (!((_f = order.shipping_methods) === null || _f === void 0 ? void 0 : _f.length)) {
1503
+ throw new medusa_core_utils_1.MedusaError(medusa_core_utils_1.MedusaError.Types.NOT_ALLOWED, "Cannot fulfill an order that lacks shipping methods");
1504
+ }
1505
+ return [4 /*yield*/, this.fulfillmentService_
1506
+ .withTransaction(manager)
1507
+ .createFulfillment(order, itemsToFulfill, {
1508
+ metadata: metadata,
1509
+ no_notification: no_notification,
1510
+ order_id: orderId,
1511
+ })];
1512
+ case 2:
1513
+ fulfillments = _g.sent();
1514
+ successfullyFulfilled = [];
1515
+ try {
1516
+ for (fulfillments_1 = __values(fulfillments), fulfillments_1_1 = fulfillments_1.next(); !fulfillments_1_1.done; fulfillments_1_1 = fulfillments_1.next()) {
1517
+ f = fulfillments_1_1.value;
1518
+ successfullyFulfilled = __spreadArray(__spreadArray([], __read(successfullyFulfilled), false), __read(f.items), false);
1519
+ }
1520
+ }
1521
+ catch (e_15_1) { e_15 = { error: e_15_1 }; }
1522
+ finally {
1523
+ try {
1524
+ if (fulfillments_1_1 && !fulfillments_1_1.done && (_c = fulfillments_1.return)) _c.call(fulfillments_1);
1525
+ }
1526
+ finally { if (e_15) throw e_15.error; }
1527
+ }
1528
+ order.fulfillment_status = models_1.FulfillmentStatus.FULFILLED;
1529
+ _loop_3 = function (item) {
1530
+ var fulfillmentItem, fulfilledQuantity;
1531
+ return __generator(this, function (_h) {
1532
+ switch (_h.label) {
1533
+ case 0:
1534
+ fulfillmentItem = successfullyFulfilled.find(function (f) { return item.id === f.item_id; });
1535
+ if (!fulfillmentItem) return [3 /*break*/, 2];
1536
+ fulfilledQuantity = (item.fulfilled_quantity || 0) + fulfillmentItem.quantity;
1537
+ // Update the fulfilled quantity
1538
+ return [4 /*yield*/, this_1.lineItemService_.withTransaction(manager).update(item.id, {
1539
+ fulfilled_quantity: fulfilledQuantity,
1540
+ })];
1541
+ case 1:
1542
+ // Update the fulfilled quantity
1543
+ _h.sent();
1544
+ if (item.quantity !== fulfilledQuantity) {
1545
+ order.fulfillment_status = models_1.FulfillmentStatus.PARTIALLY_FULFILLED;
1546
+ }
1547
+ return [3 /*break*/, 3];
1548
+ case 2:
1549
+ if (item.quantity !== item.fulfilled_quantity) {
1550
+ order.fulfillment_status = models_1.FulfillmentStatus.PARTIALLY_FULFILLED;
1551
+ }
1552
+ _h.label = 3;
1553
+ case 3: return [2 /*return*/];
1613
1554
  }
1614
- _h.label = 3;
1615
- case 3: return [2 /*return*/];
1555
+ });
1556
+ };
1557
+ this_1 = this;
1558
+ _g.label = 3;
1559
+ case 3:
1560
+ _g.trys.push([3, 8, 9, 10]);
1561
+ _a = __values(order.items), _b = _a.next();
1562
+ _g.label = 4;
1563
+ case 4:
1564
+ if (!!_b.done) return [3 /*break*/, 7];
1565
+ item = _b.value;
1566
+ return [5 /*yield**/, _loop_3(item)];
1567
+ case 5:
1568
+ _g.sent();
1569
+ _g.label = 6;
1570
+ case 6:
1571
+ _b = _a.next();
1572
+ return [3 /*break*/, 4];
1573
+ case 7: return [3 /*break*/, 10];
1574
+ case 8:
1575
+ e_13_1 = _g.sent();
1576
+ e_13 = { error: e_13_1 };
1577
+ return [3 /*break*/, 10];
1578
+ case 9:
1579
+ try {
1580
+ if (_b && !_b.done && (_d = _a.return)) _d.call(_a);
1616
1581
  }
1617
- });
1618
- };
1619
- this_3 = this;
1620
- _g.label = 3;
1621
- case 3:
1622
- _g.trys.push([3, 8, 9, 10]);
1623
- _a = __values(order.items), _b = _a.next();
1624
- _g.label = 4;
1625
- case 4:
1626
- if (!!_b.done) return [3 /*break*/, 7];
1627
- item = _b.value;
1628
- return [5 /*yield**/, _loop_3(item)];
1629
- case 5:
1630
- _g.sent();
1631
- _g.label = 6;
1632
- case 6:
1633
- _b = _a.next();
1634
- return [3 /*break*/, 4];
1635
- case 7: return [3 /*break*/, 10];
1636
- case 8:
1637
- e_13_1 = _g.sent();
1638
- e_13 = { error: e_13_1 };
1639
- return [3 /*break*/, 10];
1640
- case 9:
1641
- try {
1642
- if (_b && !_b.done && (_d = _a.return)) _d.call(_a);
1643
- }
1644
- finally { if (e_13) throw e_13.error; }
1645
- return [7 /*endfinally*/];
1646
- case 10:
1647
- orderRepo = manager.getCustomRepository(this.orderRepository_);
1648
- order.fulfillments = __spreadArray(__spreadArray([], __read(order.fulfillments), false), __read(fulfillments), false);
1649
- return [4 /*yield*/, orderRepo.save(order)];
1650
- case 11:
1651
- result = _g.sent();
1652
- evaluatedNoNotification = no_notification !== undefined ? no_notification : order.no_notification;
1653
- _g.label = 12;
1654
- case 12:
1655
- _g.trys.push([12, 17, 18, 19]);
1656
- fulfillments_2 = __values(fulfillments), fulfillments_2_1 = fulfillments_2.next();
1657
- _g.label = 13;
1658
- case 13:
1659
- if (!!fulfillments_2_1.done) return [3 /*break*/, 16];
1660
- fulfillment = fulfillments_2_1.value;
1661
- return [4 /*yield*/, this.eventBus_
1662
- .withTransaction(manager)
1663
- .emit(OrderService.Events.FULFILLMENT_CREATED, {
1664
- id: orderId,
1665
- fulfillment_id: fulfillment.id,
1666
- no_notification: evaluatedNoNotification,
1667
- })];
1668
- case 14:
1669
- _g.sent();
1670
- _g.label = 15;
1671
- case 15:
1672
- fulfillments_2_1 = fulfillments_2.next();
1673
- return [3 /*break*/, 13];
1674
- case 16: return [3 /*break*/, 19];
1675
- case 17:
1676
- e_14_1 = _g.sent();
1677
- e_14 = { error: e_14_1 };
1678
- return [3 /*break*/, 19];
1679
- case 18:
1680
- try {
1681
- if (fulfillments_2_1 && !fulfillments_2_1.done && (_e = fulfillments_2.return)) _e.call(fulfillments_2);
1582
+ finally { if (e_13) throw e_13.error; }
1583
+ return [7 /*endfinally*/];
1584
+ case 10:
1585
+ orderRepo = manager.getCustomRepository(this.orderRepository_);
1586
+ order.fulfillments = __spreadArray(__spreadArray([], __read(order.fulfillments), false), __read(fulfillments), false);
1587
+ return [4 /*yield*/, orderRepo.save(order)];
1588
+ case 11:
1589
+ result = _g.sent();
1590
+ evaluatedNoNotification = no_notification !== undefined ? no_notification : order.no_notification;
1591
+ eventBusTx = this.eventBus_.withTransaction(manager);
1592
+ _g.label = 12;
1593
+ case 12:
1594
+ _g.trys.push([12, 17, 18, 19]);
1595
+ fulfillments_2 = __values(fulfillments), fulfillments_2_1 = fulfillments_2.next();
1596
+ _g.label = 13;
1597
+ case 13:
1598
+ if (!!fulfillments_2_1.done) return [3 /*break*/, 16];
1599
+ fulfillment = fulfillments_2_1.value;
1600
+ return [4 /*yield*/, eventBusTx.emit(OrderService.Events.FULFILLMENT_CREATED, {
1601
+ id: orderId,
1602
+ fulfillment_id: fulfillment.id,
1603
+ no_notification: evaluatedNoNotification,
1604
+ })];
1605
+ case 14:
1606
+ _g.sent();
1607
+ _g.label = 15;
1608
+ case 15:
1609
+ fulfillments_2_1 = fulfillments_2.next();
1610
+ return [3 /*break*/, 13];
1611
+ case 16: return [3 /*break*/, 19];
1612
+ case 17:
1613
+ e_14_1 = _g.sent();
1614
+ e_14 = { error: e_14_1 };
1615
+ return [3 /*break*/, 19];
1616
+ case 18:
1617
+ try {
1618
+ if (fulfillments_2_1 && !fulfillments_2_1.done && (_e = fulfillments_2.return)) _e.call(fulfillments_2);
1619
+ }
1620
+ finally { if (e_14) throw e_14.error; }
1621
+ return [7 /*endfinally*/];
1622
+ case 19: return [2 /*return*/, result];
1682
1623
  }
1683
- finally { if (e_14) throw e_14.error; }
1684
- return [7 /*endfinally*/];
1685
- case 19: return [2 /*return*/, result];
1686
- }
1687
- });
1688
- }); })];
1624
+ });
1625
+ }); })];
1626
+ case 1: return [2 /*return*/, _a.sent()];
1627
+ }
1689
1628
  });
1690
1629
  });
1691
1630
  };
1692
1631
  /**
1693
1632
  * Cancels a fulfillment (if related to an order)
1694
- * @param {string} fulfillmentId - the ID of the fulfillment to cancel
1695
- * @return {Promise} updated order
1633
+ * @param fulfillmentId - the ID of the fulfillment to cancel
1634
+ * @return updated order
1696
1635
  */
1697
1636
  OrderService.prototype.cancelFulfillment = function (fulfillmentId) {
1698
1637
  return __awaiter(this, void 0, void 0, function () {
1699
1638
  var _this = this;
1700
1639
  return __generator(this, function (_a) {
1701
- return [2 /*return*/, this.atomicPhase_(function (manager) { return __awaiter(_this, void 0, void 0, function () {
1702
- var canceled, order, orderRepo, updated;
1703
- return __generator(this, function (_a) {
1704
- switch (_a.label) {
1705
- case 0: return [4 /*yield*/, this.fulfillmentService_
1706
- .withTransaction(manager)
1707
- .cancelFulfillment(fulfillmentId)];
1708
- case 1:
1709
- canceled = _a.sent();
1710
- if (!canceled.order_id) {
1711
- throw new medusa_core_utils_1.MedusaError(medusa_core_utils_1.MedusaError.Types.NOT_ALLOWED, "Fufillment not related to an order");
1712
- }
1713
- return [4 /*yield*/, this.retrieve(canceled.order_id)];
1714
- case 2:
1715
- order = _a.sent();
1716
- order.fulfillment_status = "canceled";
1717
- orderRepo = manager.getCustomRepository(this.orderRepository_);
1718
- return [4 /*yield*/, orderRepo.save(order)];
1719
- case 3:
1720
- updated = _a.sent();
1721
- return [4 /*yield*/, this.eventBus_
1640
+ switch (_a.label) {
1641
+ case 0: return [4 /*yield*/, this.atomicPhase_(function (manager) { return __awaiter(_this, void 0, void 0, function () {
1642
+ var canceled, order, orderRepo, updated;
1643
+ return __generator(this, function (_a) {
1644
+ switch (_a.label) {
1645
+ case 0: return [4 /*yield*/, this.fulfillmentService_
1722
1646
  .withTransaction(manager)
1723
- .emit(OrderService.Events.FULFILLMENT_CANCELED, {
1724
- id: order.id,
1725
- fulfillment_id: canceled.id,
1726
- no_notification: canceled.no_notification,
1727
- })];
1728
- case 4:
1729
- _a.sent();
1730
- return [2 /*return*/, updated];
1731
- }
1732
- });
1733
- }); })];
1647
+ .cancelFulfillment(fulfillmentId)];
1648
+ case 1:
1649
+ canceled = _a.sent();
1650
+ if (!canceled.order_id) {
1651
+ throw new medusa_core_utils_1.MedusaError(medusa_core_utils_1.MedusaError.Types.NOT_ALLOWED, "Fufillment not related to an order");
1652
+ }
1653
+ return [4 /*yield*/, this.retrieve(canceled.order_id)];
1654
+ case 2:
1655
+ order = _a.sent();
1656
+ order.fulfillment_status = models_1.FulfillmentStatus.CANCELED;
1657
+ orderRepo = manager.getCustomRepository(this.orderRepository_);
1658
+ return [4 /*yield*/, orderRepo.save(order)];
1659
+ case 3:
1660
+ updated = _a.sent();
1661
+ return [4 /*yield*/, this.eventBus_
1662
+ .withTransaction(manager)
1663
+ .emit(OrderService.Events.FULFILLMENT_CANCELED, {
1664
+ id: order.id,
1665
+ fulfillment_id: canceled.id,
1666
+ no_notification: canceled.no_notification,
1667
+ })];
1668
+ case 4:
1669
+ _a.sent();
1670
+ return [2 /*return*/, updated];
1671
+ }
1672
+ });
1673
+ }); })];
1674
+ case 1: return [2 /*return*/, _a.sent()];
1675
+ }
1734
1676
  });
1735
1677
  });
1736
1678
  };
1737
1679
  /**
1738
1680
  * Retrieves the order line items, given an array of items.
1739
- * @param {Order} order - the order to get line items from
1740
- * @param {{ item_id: string, quantity: number }} items - the items to get
1741
- * @param {function} transformer - a function to apply to each of the items
1681
+ * @param order - the order to get line items from
1682
+ * @param items - the items to get
1683
+ * @param transformer - a function to apply to each of the items
1742
1684
  * retrieved from the order, should return a line item. If the transformer
1743
1685
  * returns an undefined value the line item will be filtered from the
1744
1686
  * returned array.
1745
- * @return {Promise<Array<LineItem>>} the line items generated by the transformer.
1687
+ * @return the line items generated by the transformer.
1746
1688
  */
1747
- OrderService.prototype.getFulfillmentItems_ = function (order, items, transformer) {
1689
+ OrderService.prototype.getFulfillmentItems = function (order, items, transformer) {
1748
1690
  return __awaiter(this, void 0, void 0, function () {
1749
- var toReturn;
1750
1691
  var _this = this;
1751
1692
  return __generator(this, function (_a) {
1752
1693
  switch (_a.label) {
@@ -1755,14 +1696,12 @@ var OrderService = /** @class */ (function (_super) {
1755
1696
  return __awaiter(_this, void 0, void 0, function () {
1756
1697
  var item;
1757
1698
  return __generator(this, function (_b) {
1758
- item = order.items.find(function (i) { return i.id.equals(item_id); });
1699
+ item = order.items.find(function (i) { return i.id === item_id; });
1759
1700
  return [2 /*return*/, transformer(item, quantity)];
1760
1701
  });
1761
1702
  });
1762
1703
  }))];
1763
- case 1:
1764
- toReturn = _a.sent();
1765
- return [2 /*return*/, toReturn.filter(function (i) { return !!i; })];
1704
+ case 1: return [2 /*return*/, (_a.sent()).filter(function (i) { return !!i; })];
1766
1705
  }
1767
1706
  });
1768
1707
  });
@@ -1770,43 +1709,44 @@ var OrderService = /** @class */ (function (_super) {
1770
1709
  /**
1771
1710
  * Archives an order. It only alloved, if the order has been fulfilled
1772
1711
  * and payment has been captured.
1773
- * @param {string} orderId - the order to archive
1774
- * @return {Promise} the result of the update operation
1712
+ * @param orderId - the order to archive
1713
+ * @return the result of the update operation
1775
1714
  */
1776
1715
  OrderService.prototype.archive = function (orderId) {
1777
1716
  return __awaiter(this, void 0, void 0, function () {
1778
1717
  var _this = this;
1779
1718
  return __generator(this, function (_a) {
1780
- return [2 /*return*/, this.atomicPhase_(function (manager) { return __awaiter(_this, void 0, void 0, function () {
1781
- var order, orderRepo, result;
1782
- return __generator(this, function (_a) {
1783
- switch (_a.label) {
1784
- case 0: return [4 /*yield*/, this.retrieve(orderId)];
1785
- case 1:
1786
- order = _a.sent();
1787
- if (order.status !== ("completed" || "refunded")) {
1788
- throw new medusa_core_utils_1.MedusaError(medusa_core_utils_1.MedusaError.Types.NOT_ALLOWED, "Can't archive an unprocessed order");
1789
- }
1790
- order.status = "archived";
1791
- orderRepo = manager.getCustomRepository(this.orderRepository_);
1792
- return [4 /*yield*/, orderRepo.save(order)];
1793
- case 2:
1794
- result = _a.sent();
1795
- return [2 /*return*/, result];
1796
- }
1797
- });
1798
- }); })];
1719
+ switch (_a.label) {
1720
+ case 0: return [4 /*yield*/, this.atomicPhase_(function (manager) { return __awaiter(_this, void 0, void 0, function () {
1721
+ var order, orderRepo;
1722
+ return __generator(this, function (_a) {
1723
+ switch (_a.label) {
1724
+ case 0: return [4 /*yield*/, this.retrieve(orderId)];
1725
+ case 1:
1726
+ order = _a.sent();
1727
+ if (order.status !== ("completed" || "refunded")) {
1728
+ throw new medusa_core_utils_1.MedusaError(medusa_core_utils_1.MedusaError.Types.NOT_ALLOWED, "Can't archive an unprocessed order");
1729
+ }
1730
+ order.status = models_1.OrderStatus.ARCHIVED;
1731
+ orderRepo = manager.getCustomRepository(this.orderRepository_);
1732
+ return [4 /*yield*/, orderRepo.save(order)];
1733
+ case 2: return [2 /*return*/, _a.sent()];
1734
+ }
1735
+ });
1736
+ }); })];
1737
+ case 1: return [2 /*return*/, _a.sent()];
1738
+ }
1799
1739
  });
1800
1740
  });
1801
1741
  };
1802
1742
  /**
1803
1743
  * Refunds a given amount back to the customer.
1804
- * @param {string} orderId - id of the order to refund.
1805
- * @param {float} refundAmount - the amount to refund.
1806
- * @param {string} reason - the reason to refund.
1807
- * @param {string | undefined} note - note for refund.
1808
- * @param {Object} config - the config for refund.
1809
- * @return {Promise} the result of the refund operation.
1744
+ * @param orderId - id of the order to refund.
1745
+ * @param refundAmount - the amount to refund.
1746
+ * @param reason - the reason to refund.
1747
+ * @param note - note for refund.
1748
+ * @param config - the config for refund.
1749
+ * @return the result of the refund operation.
1810
1750
  */
1811
1751
  OrderService.prototype.createRefund = function (orderId, refundAmount, reason, note, config) {
1812
1752
  if (config === void 0) { config = {
@@ -1816,48 +1756,52 @@ var OrderService = /** @class */ (function (_super) {
1816
1756
  var no_notification;
1817
1757
  var _this = this;
1818
1758
  return __generator(this, function (_a) {
1819
- no_notification = config.no_notification;
1820
- return [2 /*return*/, this.atomicPhase_(function (manager) { return __awaiter(_this, void 0, void 0, function () {
1821
- var order, refund, result, evaluatedNoNotification;
1822
- return __generator(this, function (_a) {
1823
- switch (_a.label) {
1824
- case 0: return [4 /*yield*/, this.retrieve(orderId, {
1825
- select: ["refundable_amount", "total", "refunded_total"],
1826
- relations: ["payments"],
1827
- })];
1828
- case 1:
1829
- order = _a.sent();
1830
- if (order.status === "canceled") {
1831
- throw new medusa_core_utils_1.MedusaError(medusa_core_utils_1.MedusaError.Types.NOT_ALLOWED, "A canceled order cannot be refunded");
1832
- }
1833
- if (refundAmount > order.refundable_amount) {
1834
- throw new medusa_core_utils_1.MedusaError(medusa_core_utils_1.MedusaError.Types.NOT_ALLOWED, "Cannot refund more than the original order amount");
1759
+ switch (_a.label) {
1760
+ case 0:
1761
+ no_notification = config.no_notification;
1762
+ return [4 /*yield*/, this.atomicPhase_(function (manager) { return __awaiter(_this, void 0, void 0, function () {
1763
+ var order, refund, result, evaluatedNoNotification;
1764
+ return __generator(this, function (_a) {
1765
+ switch (_a.label) {
1766
+ case 0: return [4 /*yield*/, this.retrieve(orderId, {
1767
+ select: ["refundable_amount", "total", "refunded_total"],
1768
+ relations: ["payments"],
1769
+ })];
1770
+ case 1:
1771
+ order = _a.sent();
1772
+ if (order.status === "canceled") {
1773
+ throw new medusa_core_utils_1.MedusaError(medusa_core_utils_1.MedusaError.Types.NOT_ALLOWED, "A canceled order cannot be refunded");
1774
+ }
1775
+ if (refundAmount > order.refundable_amount) {
1776
+ throw new medusa_core_utils_1.MedusaError(medusa_core_utils_1.MedusaError.Types.NOT_ALLOWED, "Cannot refund more than the original order amount");
1777
+ }
1778
+ return [4 /*yield*/, this.paymentProviderService_
1779
+ .withTransaction(manager)
1780
+ .refundPayment(order.payments, refundAmount, reason, note)];
1781
+ case 2:
1782
+ refund = _a.sent();
1783
+ return [4 /*yield*/, this.retrieve(orderId)];
1784
+ case 3:
1785
+ result = _a.sent();
1786
+ evaluatedNoNotification = no_notification !== undefined ? no_notification : order.no_notification;
1787
+ this.eventBus_.emit(OrderService.Events.REFUND_CREATED, {
1788
+ id: result.id,
1789
+ refund_id: refund.id,
1790
+ no_notification: evaluatedNoNotification,
1791
+ });
1792
+ return [2 /*return*/, result];
1835
1793
  }
1836
- return [4 /*yield*/, this.paymentProviderService_
1837
- .withTransaction(manager)
1838
- .refundPayment(order.payments, refundAmount, reason, note)];
1839
- case 2:
1840
- refund = _a.sent();
1841
- return [4 /*yield*/, this.retrieve(orderId)];
1842
- case 3:
1843
- result = _a.sent();
1844
- evaluatedNoNotification = no_notification !== undefined ? no_notification : order.no_notification;
1845
- this.eventBus_.emit(OrderService.Events.REFUND_CREATED, {
1846
- id: result.id,
1847
- refund_id: refund.id,
1848
- no_notification: evaluatedNoNotification,
1849
- });
1850
- return [2 /*return*/, result];
1851
- }
1852
- });
1853
- }); })];
1794
+ });
1795
+ }); })];
1796
+ case 1: return [2 /*return*/, _a.sent()];
1797
+ }
1854
1798
  });
1855
1799
  });
1856
1800
  };
1857
- OrderService.prototype.decorateTotals_ = function (order, totalsFields) {
1801
+ OrderService.prototype.decorateTotals = function (order, totalsFields) {
1858
1802
  if (totalsFields === void 0) { totalsFields = []; }
1859
1803
  return __awaiter(this, void 0, void 0, function () {
1860
- var totalsFields_1, totalsFields_1_1, totalField, _a, _b, _c, paid_total, refunded_total, _d, _e, s, _f, _g, c, e_16_1;
1804
+ var totalsFields_1, totalsFields_1_1, totalField, _a, giftCardBreakdown, _b, _c, paid_total, refunded_total, _d, _e, s, _f, _g, c, e_16_1;
1861
1805
  var e_16, _h, e_17, _j, e_18, _k;
1862
1806
  var _this = this;
1863
1807
  return __generator(this, function (_l) {
@@ -1893,7 +1837,9 @@ var OrderService = /** @class */ (function (_super) {
1893
1837
  _l.label = 3;
1894
1838
  case 3:
1895
1839
  {
1896
- order.gift_card_total = this.totalsService_.getGiftCardTotal(order);
1840
+ giftCardBreakdown = this.totalsService_.getGiftCardTotal(order);
1841
+ order.gift_card_total = giftCardBreakdown.total;
1842
+ order.gift_card_tax_total = giftCardBreakdown.tax_total;
1897
1843
  return [3 /*break*/, 17];
1898
1844
  }
1899
1845
  _l.label = 4;
@@ -1917,7 +1863,9 @@ var OrderService = /** @class */ (function (_super) {
1917
1863
  _l.label = 8;
1918
1864
  case 8:
1919
1865
  _c = order;
1920
- return [4 /*yield*/, this.totalsService_.getTotal(order)];
1866
+ return [4 /*yield*/, this.totalsService_
1867
+ .withTransaction(this.manager_)
1868
+ .getTotal(order)];
1921
1869
  case 9:
1922
1870
  _c.total = _l.sent();
1923
1871
  return [3 /*break*/, 17];
@@ -2015,119 +1963,98 @@ var OrderService = /** @class */ (function (_super) {
2015
1963
  * retuned items are not matching the requested items. Setting the
2016
1964
  * allowMismatch argument to true, will process the return, ignoring any
2017
1965
  * mismatches.
2018
- * @param {string} orderId - the order to return.
2019
- * @param {object} receivedReturn - the received return
2020
- * @param {float} customRefundAmount - the custom refund amount return
2021
- * @return {Promise} the result of the update operation
1966
+ * @param orderId - the order to return.
1967
+ * @param receivedReturn - the received return
1968
+ * @param customRefundAmount - the custom refund amount return
1969
+ * @return the result of the update operation
2022
1970
  */
2023
1971
  OrderService.prototype.registerReturnReceived = function (orderId, receivedReturn, customRefundAmount) {
2024
1972
  return __awaiter(this, void 0, void 0, function () {
2025
1973
  var _this = this;
2026
1974
  return __generator(this, function (_a) {
2027
- return [2 /*return*/, this.atomicPhase_(function (manager) { return __awaiter(_this, void 0, void 0, function () {
2028
- var order, refundAmount, orderRepo, result_2, isFullReturn, _a, _b, i, refund, result;
2029
- var e_19, _c;
2030
- return __generator(this, function (_d) {
2031
- switch (_d.label) {
2032
- case 0: return [4 /*yield*/, this.retrieve(orderId, {
2033
- select: ["total", "refunded_total", "refundable_amount"],
2034
- relations: ["items", "returns", "payments"],
2035
- })];
2036
- case 1:
2037
- order = _d.sent();
2038
- if (order.status === "canceled") {
2039
- throw new medusa_core_utils_1.MedusaError(medusa_core_utils_1.MedusaError.Types.NOT_ALLOWED, "A canceled order cannot be registered as received");
2040
- }
2041
- if (!receivedReturn || receivedReturn.order_id !== orderId) {
2042
- throw new medusa_core_utils_1.MedusaError(medusa_core_utils_1.MedusaError.Types.NOT_FOUND, "Received return does not exist");
2043
- }
2044
- refundAmount = customRefundAmount || receivedReturn.refund_amount;
2045
- orderRepo = manager.getCustomRepository(this.orderRepository_);
2046
- if (!(refundAmount > order.refundable_amount)) return [3 /*break*/, 3];
2047
- order.fulfillment_status = "requires_action";
2048
- return [4 /*yield*/, orderRepo.save(order)];
2049
- case 2:
2050
- result_2 = _d.sent();
2051
- this.eventBus_
2052
- .withTransaction(manager)
2053
- .emit(OrderService.Events.RETURN_ACTION_REQUIRED, {
2054
- id: result_2.id,
2055
- return_id: receivedReturn.id,
2056
- no_notification: receivedReturn.no_notification,
2057
- });
2058
- return [2 /*return*/, result_2];
2059
- case 3:
2060
- isFullReturn = true;
2061
- try {
2062
- for (_a = __values(order.items), _b = _a.next(); !_b.done; _b = _a.next()) {
2063
- i = _b.value;
2064
- if (i.returned_quantity !== i.quantity) {
2065
- isFullReturn = false;
2066
- }
1975
+ switch (_a.label) {
1976
+ case 0: return [4 /*yield*/, this.atomicPhase_(function (manager) { return __awaiter(_this, void 0, void 0, function () {
1977
+ var order, refundAmount, orderRepo, result_2, isFullReturn, _a, _b, i, refund, result;
1978
+ var e_19, _c;
1979
+ return __generator(this, function (_d) {
1980
+ switch (_d.label) {
1981
+ case 0: return [4 /*yield*/, this.retrieve(orderId, {
1982
+ select: ["total", "refunded_total", "refundable_amount"],
1983
+ relations: ["items", "returns", "payments"],
1984
+ })];
1985
+ case 1:
1986
+ order = _d.sent();
1987
+ if (order.status === "canceled") {
1988
+ throw new medusa_core_utils_1.MedusaError(medusa_core_utils_1.MedusaError.Types.NOT_ALLOWED, "A canceled order cannot be registered as received");
2067
1989
  }
2068
- }
2069
- catch (e_19_1) { e_19 = { error: e_19_1 }; }
2070
- finally {
2071
- try {
2072
- if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
1990
+ if (!receivedReturn || receivedReturn.order_id !== orderId) {
1991
+ throw new medusa_core_utils_1.MedusaError(medusa_core_utils_1.MedusaError.Types.NOT_FOUND, "Received return does not exist");
2073
1992
  }
2074
- finally { if (e_19) throw e_19.error; }
2075
- }
2076
- if (!(receivedReturn.refund_amount > 0)) return [3 /*break*/, 5];
2077
- return [4 /*yield*/, this.paymentProviderService_
2078
- .withTransaction(manager)
2079
- .refundPayment(order.payments, receivedReturn.refund_amount, "return")];
2080
- case 4:
2081
- refund = _d.sent();
2082
- order.refunds = __spreadArray(__spreadArray([], __read((order.refunds || [])), false), [refund], false);
2083
- _d.label = 5;
2084
- case 5:
2085
- if (isFullReturn) {
2086
- order.fulfillment_status = "returned";
2087
- }
2088
- else {
2089
- order.fulfillment_status = "partially_returned";
2090
- }
2091
- return [4 /*yield*/, orderRepo.save(order)];
2092
- case 6:
2093
- result = _d.sent();
2094
- return [4 /*yield*/, this.eventBus_
1993
+ refundAmount = customRefundAmount || receivedReturn.refund_amount;
1994
+ orderRepo = manager.getCustomRepository(this.orderRepository_);
1995
+ if (!(refundAmount > order.refundable_amount)) return [3 /*break*/, 3];
1996
+ order.fulfillment_status = models_1.FulfillmentStatus.REQUIRES_ACTION;
1997
+ return [4 /*yield*/, orderRepo.save(order)];
1998
+ case 2:
1999
+ result_2 = _d.sent();
2000
+ this.eventBus_
2095
2001
  .withTransaction(manager)
2096
- .emit(OrderService.Events.ITEMS_RETURNED, {
2097
- id: order.id,
2002
+ .emit(OrderService.Events.RETURN_ACTION_REQUIRED, {
2003
+ id: result_2.id,
2098
2004
  return_id: receivedReturn.id,
2099
2005
  no_notification: receivedReturn.no_notification,
2100
- })];
2101
- case 7:
2102
- _d.sent();
2103
- return [2 /*return*/, result];
2104
- }
2105
- });
2106
- }); })];
2107
- });
2108
- });
2109
- };
2110
- /**
2111
- * Dedicated method to delete metadata for an order.
2112
- * @param {string} orderId - the order to delete metadata from.
2113
- * @param {string} key - key for metadata field
2114
- * @return {Promise} resolves to the updated result.
2115
- */
2116
- OrderService.prototype.deleteMetadata = function (orderId, key) {
2117
- return __awaiter(this, void 0, void 0, function () {
2118
- var validatedId, keyPath;
2119
- var _a;
2120
- return __generator(this, function (_b) {
2121
- validatedId = this.validateId_(orderId);
2122
- if (typeof key !== "string") {
2123
- throw new medusa_core_utils_1.MedusaError(medusa_core_utils_1.MedusaError.Types.INVALID_ARGUMENT, "Key type is invalid. Metadata keys must be strings");
2006
+ });
2007
+ return [2 /*return*/, result_2];
2008
+ case 3:
2009
+ isFullReturn = true;
2010
+ try {
2011
+ for (_a = __values(order.items), _b = _a.next(); !_b.done; _b = _a.next()) {
2012
+ i = _b.value;
2013
+ if (i.returned_quantity !== i.quantity) {
2014
+ isFullReturn = false;
2015
+ }
2016
+ }
2017
+ }
2018
+ catch (e_19_1) { e_19 = { error: e_19_1 }; }
2019
+ finally {
2020
+ try {
2021
+ if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
2022
+ }
2023
+ finally { if (e_19) throw e_19.error; }
2024
+ }
2025
+ if (!(receivedReturn.refund_amount > 0)) return [3 /*break*/, 5];
2026
+ return [4 /*yield*/, this.paymentProviderService_
2027
+ .withTransaction(manager)
2028
+ .refundPayment(order.payments, receivedReturn.refund_amount, "return")];
2029
+ case 4:
2030
+ refund = _d.sent();
2031
+ order.refunds = __spreadArray(__spreadArray([], __read((order.refunds || [])), false), [refund], false);
2032
+ _d.label = 5;
2033
+ case 5:
2034
+ if (isFullReturn) {
2035
+ order.fulfillment_status = models_1.FulfillmentStatus.RETURNED;
2036
+ }
2037
+ else {
2038
+ order.fulfillment_status = models_1.FulfillmentStatus.PARTIALLY_RETURNED;
2039
+ }
2040
+ return [4 /*yield*/, orderRepo.save(order)];
2041
+ case 6:
2042
+ result = _d.sent();
2043
+ return [4 /*yield*/, this.eventBus_
2044
+ .withTransaction(manager)
2045
+ .emit(OrderService.Events.ITEMS_RETURNED, {
2046
+ id: order.id,
2047
+ return_id: receivedReturn.id,
2048
+ no_notification: receivedReturn.no_notification,
2049
+ })];
2050
+ case 7:
2051
+ _d.sent();
2052
+ return [2 /*return*/, result];
2053
+ }
2054
+ });
2055
+ }); })];
2056
+ case 1: return [2 /*return*/, _a.sent()];
2124
2057
  }
2125
- keyPath = "metadata.".concat(key);
2126
- return [2 /*return*/, this.orderModel_
2127
- .updateOne({ _id: validatedId }, { $unset: (_a = {}, _a[keyPath] = "", _a) })
2128
- .catch(function (err) {
2129
- throw new medusa_core_utils_1.MedusaError(medusa_core_utils_1.MedusaError.Types.DB_ERROR, err.message);
2130
- })];
2131
2058
  });
2132
2059
  });
2133
2060
  };
@@ -2150,6 +2077,6 @@ var OrderService = /** @class */ (function (_super) {
2150
2077
  COMPLETED: "order.completed",
2151
2078
  };
2152
2079
  return OrderService;
2153
- }(medusa_interfaces_1.BaseService));
2080
+ }(interfaces_1.TransactionBaseService));
2154
2081
  exports.default = OrderService;
2155
2082
  //# sourceMappingURL=order.js.map