@medusajs/order 0.1.3 → 1.0.0-rc-20241003153304

Sign up to get free protection for your applications and to get access to all the features.
Files changed (379) hide show
  1. package/dist/index.d.ts +6 -8
  2. package/dist/index.d.ts.map +1 -0
  3. package/dist/index.js +4 -26
  4. package/dist/index.js.map +1 -1
  5. package/dist/joiner-config.d.ts +2 -5
  6. package/dist/joiner-config.d.ts.map +1 -0
  7. package/dist/joiner-config.js +21 -28
  8. package/dist/joiner-config.js.map +1 -1
  9. package/dist/migrations/Migration20240219102530.d.ts +1 -0
  10. package/dist/migrations/Migration20240219102530.d.ts.map +1 -0
  11. package/dist/migrations/Migration20240219102530.js +53 -19
  12. package/dist/migrations/Migration20240219102530.js.map +1 -1
  13. package/dist/migrations/Migration20240604100512.d.ts +5 -0
  14. package/dist/migrations/Migration20240604100512.d.ts.map +1 -0
  15. package/dist/migrations/Migration20240604100512.js +371 -0
  16. package/dist/migrations/Migration20240604100512.js.map +1 -0
  17. package/dist/migrations/Migration20240715102100.d.ts +5 -0
  18. package/dist/migrations/Migration20240715102100.d.ts.map +1 -0
  19. package/dist/migrations/Migration20240715102100.js +15 -0
  20. package/dist/migrations/Migration20240715102100.js.map +1 -0
  21. package/dist/migrations/Migration20240715174100.d.ts +5 -0
  22. package/dist/migrations/Migration20240715174100.d.ts.map +1 -0
  23. package/dist/migrations/Migration20240715174100.js +21 -0
  24. package/dist/migrations/Migration20240715174100.js.map +1 -0
  25. package/dist/migrations/Migration20240716081800.d.ts +5 -0
  26. package/dist/migrations/Migration20240716081800.d.ts.map +1 -0
  27. package/dist/migrations/Migration20240716081800.js +67 -0
  28. package/dist/migrations/Migration20240716081800.js.map +1 -0
  29. package/dist/migrations/Migration20240801085921.d.ts +5 -0
  30. package/dist/migrations/Migration20240801085921.d.ts.map +1 -0
  31. package/dist/migrations/Migration20240801085921.js +30 -0
  32. package/dist/migrations/Migration20240801085921.js.map +1 -0
  33. package/dist/migrations/Migration20240821164505.d.ts +6 -0
  34. package/dist/migrations/Migration20240821164505.d.ts.map +1 -0
  35. package/dist/migrations/Migration20240821164505.js +26 -0
  36. package/dist/migrations/Migration20240821164505.js.map +1 -0
  37. package/dist/migrations/Migration20240821170920.d.ts +6 -0
  38. package/dist/migrations/Migration20240821170920.d.ts.map +1 -0
  39. package/dist/migrations/Migration20240821170920.js +18 -0
  40. package/dist/migrations/Migration20240821170920.js.map +1 -0
  41. package/dist/migrations/Migration20240827133639.d.ts +6 -0
  42. package/dist/migrations/Migration20240827133639.d.ts.map +1 -0
  43. package/dist/migrations/Migration20240827133639.js +17 -0
  44. package/dist/migrations/Migration20240827133639.js.map +1 -0
  45. package/dist/migrations/Migration20240902195921.d.ts +6 -0
  46. package/dist/migrations/Migration20240902195921.d.ts.map +1 -0
  47. package/dist/migrations/Migration20240902195921.js +16 -0
  48. package/dist/migrations/Migration20240902195921.js.map +1 -0
  49. package/dist/migrations/Migration20240913092514.d.ts +6 -0
  50. package/dist/migrations/Migration20240913092514.d.ts.map +1 -0
  51. package/dist/migrations/Migration20240913092514.js +17 -0
  52. package/dist/migrations/Migration20240913092514.js.map +1 -0
  53. package/dist/models/address.d.ts +4 -3
  54. package/dist/models/address.d.ts.map +1 -0
  55. package/dist/models/address.js +22 -22
  56. package/dist/models/address.js.map +1 -1
  57. package/dist/models/adjustment-line.d.ts +5 -3
  58. package/dist/models/adjustment-line.d.ts.map +1 -0
  59. package/dist/models/adjustment-line.js +6 -1
  60. package/dist/models/adjustment-line.js.map +1 -1
  61. package/dist/models/claim-item-image.d.ts +19 -0
  62. package/dist/models/claim-item-image.d.ts.map +1 -0
  63. package/dist/models/claim-item-image.js +109 -0
  64. package/dist/models/claim-item-image.js.map +1 -0
  65. package/dist/models/claim-item.d.ts +29 -0
  66. package/dist/models/claim-item.d.ts.map +1 -0
  67. package/dist/models/claim-item.js +157 -0
  68. package/dist/models/claim-item.js.map +1 -0
  69. package/dist/models/claim.d.ts +37 -0
  70. package/dist/models/claim.d.ts.map +1 -0
  71. package/dist/models/claim.js +201 -0
  72. package/dist/models/claim.js.map +1 -0
  73. package/dist/models/exchange-item.d.ts +24 -0
  74. package/dist/models/exchange-item.d.ts.map +1 -0
  75. package/dist/models/exchange-item.js +138 -0
  76. package/dist/models/exchange-item.js.map +1 -0
  77. package/dist/models/exchange.d.ts +35 -0
  78. package/dist/models/exchange.d.ts.map +1 -0
  79. package/dist/models/exchange.js +194 -0
  80. package/dist/models/exchange.js.map +1 -0
  81. package/dist/models/index.d.ts +18 -9
  82. package/dist/models/index.d.ts.map +1 -0
  83. package/dist/models/index.js +26 -10
  84. package/dist/models/index.js.map +1 -1
  85. package/dist/models/line-item-adjustment.d.ts +5 -3
  86. package/dist/models/line-item-adjustment.d.ts.map +1 -0
  87. package/dist/models/line-item-adjustment.js +12 -12
  88. package/dist/models/line-item-adjustment.js.map +1 -1
  89. package/dist/models/line-item-tax-line.d.ts +5 -3
  90. package/dist/models/line-item-tax-line.d.ts.map +1 -0
  91. package/dist/models/line-item-tax-line.js +12 -12
  92. package/dist/models/line-item-tax-line.js.map +1 -1
  93. package/dist/models/line-item.d.ts +11 -8
  94. package/dist/models/line-item.d.ts.map +1 -0
  95. package/dist/models/line-item.js +58 -39
  96. package/dist/models/line-item.js.map +1 -1
  97. package/dist/models/order-change-action.d.ts +17 -6
  98. package/dist/models/order-change-action.d.ts.map +1 -0
  99. package/dist/models/order-change-action.js +110 -8
  100. package/dist/models/order-change-action.js.map +1 -1
  101. package/dist/models/order-change.d.ts +18 -6
  102. package/dist/models/order-change.d.ts.map +1 -0
  103. package/dist/models/order-change.js +108 -6
  104. package/dist/models/order-change.js.map +1 -1
  105. package/dist/models/order-item.d.ts +10 -7
  106. package/dist/models/order-item.d.ts.map +1 -0
  107. package/dist/models/order-item.js +29 -19
  108. package/dist/models/order-item.js.map +1 -1
  109. package/dist/models/order-shipping-method.d.ts +17 -7
  110. package/dist/models/order-shipping-method.d.ts.map +1 -0
  111. package/dist/models/order-shipping-method.js +113 -33
  112. package/dist/models/order-shipping-method.js.map +1 -1
  113. package/dist/models/order-summary.d.ts +7 -8
  114. package/dist/models/order-summary.d.ts.map +1 -0
  115. package/dist/models/order-summary.js +14 -10
  116. package/dist/models/order-summary.js.map +1 -1
  117. package/dist/models/order.d.ts +13 -11
  118. package/dist/models/order.d.ts.map +1 -0
  119. package/dist/models/order.js +12 -2
  120. package/dist/models/order.js.map +1 -1
  121. package/dist/models/return-item.d.ts +31 -0
  122. package/dist/models/return-item.d.ts.map +1 -0
  123. package/dist/models/return-item.js +180 -0
  124. package/dist/models/return-item.js.map +1 -0
  125. package/dist/models/return-reason.d.ts +22 -0
  126. package/dist/models/return-reason.d.ts.map +1 -0
  127. package/dist/models/return-reason.js +122 -0
  128. package/dist/models/return-reason.js.map +1 -0
  129. package/dist/models/return.d.ts +41 -0
  130. package/dist/models/return.d.ts.map +1 -0
  131. package/dist/models/return.js +227 -0
  132. package/dist/models/return.js.map +1 -0
  133. package/dist/models/shipping-method-adjustment.d.ts +5 -3
  134. package/dist/models/shipping-method-adjustment.d.ts.map +1 -0
  135. package/dist/models/shipping-method-adjustment.js +12 -12
  136. package/dist/models/shipping-method-adjustment.js.map +1 -1
  137. package/dist/models/shipping-method-tax-line.d.ts +5 -3
  138. package/dist/models/shipping-method-tax-line.d.ts.map +1 -0
  139. package/dist/models/shipping-method-tax-line.js +12 -12
  140. package/dist/models/shipping-method-tax-line.js.map +1 -1
  141. package/dist/models/shipping-method.d.ts +10 -7
  142. package/dist/models/shipping-method.d.ts.map +1 -0
  143. package/dist/models/shipping-method.js +42 -24
  144. package/dist/models/shipping-method.js.map +1 -1
  145. package/dist/models/tax-line.d.ts +4 -2
  146. package/dist/models/tax-line.d.ts.map +1 -0
  147. package/dist/models/tax-line.js +8 -1
  148. package/dist/models/tax-line.js.map +1 -1
  149. package/dist/models/transaction.d.ts +18 -6
  150. package/dist/models/transaction.d.ts.map +1 -0
  151. package/dist/models/transaction.js +133 -24
  152. package/dist/models/transaction.js.map +1 -1
  153. package/dist/repositories/claim.d.ts +9 -0
  154. package/dist/repositories/claim.d.ts.map +1 -0
  155. package/dist/repositories/claim.js +11 -0
  156. package/dist/repositories/claim.js.map +1 -0
  157. package/dist/repositories/exchange.d.ts +9 -0
  158. package/dist/repositories/exchange.d.ts.map +1 -0
  159. package/dist/repositories/exchange.js +11 -0
  160. package/dist/repositories/exchange.js.map +1 -0
  161. package/dist/repositories/index.d.ts +5 -2
  162. package/dist/repositories/index.d.ts.map +1 -0
  163. package/dist/repositories/index.js +8 -17
  164. package/dist/repositories/index.js.map +1 -1
  165. package/dist/repositories/order.d.ts +2 -4
  166. package/dist/repositories/order.d.ts.map +1 -0
  167. package/dist/repositories/order.js +3 -86
  168. package/dist/repositories/order.js.map +1 -1
  169. package/dist/repositories/return.d.ts +9 -0
  170. package/dist/repositories/return.d.ts.map +1 -0
  171. package/dist/repositories/return.js +11 -0
  172. package/dist/repositories/return.js.map +1 -0
  173. package/dist/schema/index.d.ts +3 -0
  174. package/dist/schema/index.d.ts.map +1 -0
  175. package/dist/schema/index.js +556 -0
  176. package/dist/schema/index.js.map +1 -0
  177. package/dist/services/actions/cancel-claim.d.ts +3 -0
  178. package/dist/services/actions/cancel-claim.d.ts.map +1 -0
  179. package/dist/services/actions/cancel-claim.js +85 -0
  180. package/dist/services/actions/cancel-claim.js.map +1 -0
  181. package/dist/services/actions/cancel-exchange.d.ts +3 -0
  182. package/dist/services/actions/cancel-exchange.d.ts.map +1 -0
  183. package/dist/services/actions/cancel-exchange.js +71 -0
  184. package/dist/services/actions/cancel-exchange.js.map +1 -0
  185. package/dist/services/actions/cancel-fulfillment.d.ts +3 -0
  186. package/dist/services/actions/cancel-fulfillment.d.ts.map +1 -0
  187. package/dist/services/actions/cancel-fulfillment.js +31 -0
  188. package/dist/services/actions/cancel-fulfillment.js.map +1 -0
  189. package/dist/services/actions/cancel-return.d.ts +3 -0
  190. package/dist/services/actions/cancel-return.d.ts.map +1 -0
  191. package/dist/services/actions/cancel-return.js +69 -0
  192. package/dist/services/actions/cancel-return.js.map +1 -0
  193. package/dist/services/actions/create-claim.d.ts +3 -0
  194. package/dist/services/actions/create-claim.d.ts.map +1 -0
  195. package/dist/services/actions/create-claim.js +225 -0
  196. package/dist/services/actions/create-claim.js.map +1 -0
  197. package/dist/services/actions/create-exchange.d.ts +3 -0
  198. package/dist/services/actions/create-exchange.d.ts.map +1 -0
  199. package/dist/services/actions/create-exchange.js +191 -0
  200. package/dist/services/actions/create-exchange.js.map +1 -0
  201. package/dist/services/actions/create-return.d.ts +3 -0
  202. package/dist/services/actions/create-return.d.ts.map +1 -0
  203. package/dist/services/actions/create-return.js +100 -0
  204. package/dist/services/actions/create-return.js.map +1 -0
  205. package/dist/services/actions/index.d.ts +12 -0
  206. package/dist/services/actions/index.d.ts.map +1 -0
  207. package/dist/services/actions/index.js +28 -0
  208. package/dist/services/actions/index.js.map +1 -0
  209. package/dist/services/actions/receive-return.d.ts +3 -0
  210. package/dist/services/actions/receive-return.d.ts.map +1 -0
  211. package/dist/services/actions/receive-return.js +71 -0
  212. package/dist/services/actions/receive-return.js.map +1 -0
  213. package/dist/services/actions/register-delivery.d.ts +3 -0
  214. package/dist/services/actions/register-delivery.d.ts.map +1 -0
  215. package/dist/services/actions/register-delivery.js +29 -0
  216. package/dist/services/actions/register-delivery.js.map +1 -0
  217. package/dist/services/actions/register-fulfillment.d.ts +3 -0
  218. package/dist/services/actions/register-fulfillment.d.ts.map +1 -0
  219. package/dist/services/actions/register-fulfillment.js +29 -0
  220. package/dist/services/actions/register-fulfillment.js.map +1 -0
  221. package/dist/services/actions/register-shipment.d.ts +3 -0
  222. package/dist/services/actions/register-shipment.d.ts.map +1 -0
  223. package/dist/services/actions/register-shipment.js +37 -0
  224. package/dist/services/actions/register-shipment.js.map +1 -0
  225. package/dist/services/index.d.ts +1 -1
  226. package/dist/services/index.d.ts.map +1 -0
  227. package/dist/services/index.js +1 -3
  228. package/dist/services/index.js.map +1 -1
  229. package/dist/services/order-module-service.d.ts +191 -109
  230. package/dist/services/order-module-service.d.ts.map +1 -0
  231. package/dist/services/order-module-service.js +1165 -425
  232. package/dist/services/order-module-service.js.map +1 -1
  233. package/dist/services/order-service.d.ts +6 -5
  234. package/dist/services/order-service.d.ts.map +1 -0
  235. package/dist/services/order-service.js +2 -2
  236. package/dist/services/order-service.js.map +1 -1
  237. package/dist/tsconfig.tsbuildinfo +1 -0
  238. package/dist/types/address.d.ts +2 -1
  239. package/dist/types/address.d.ts.map +1 -0
  240. package/dist/types/index.d.ts +5 -2
  241. package/dist/types/index.d.ts.map +1 -0
  242. package/dist/types/index.js +2 -0
  243. package/dist/types/index.js.map +1 -1
  244. package/dist/types/line-item-adjustment.d.ts +2 -1
  245. package/dist/types/line-item-adjustment.d.ts.map +1 -0
  246. package/dist/types/line-item-tax-line.d.ts +1 -0
  247. package/dist/types/line-item-tax-line.d.ts.map +1 -0
  248. package/dist/types/line-item.d.ts +2 -1
  249. package/dist/types/line-item.d.ts.map +1 -0
  250. package/dist/types/order-change.d.ts +4 -0
  251. package/dist/types/order-change.d.ts.map +1 -0
  252. package/dist/types/order-change.js +3 -0
  253. package/dist/types/order-change.js.map +1 -0
  254. package/dist/types/order-detail.d.ts +3 -2
  255. package/dist/types/order-detail.d.ts.map +1 -0
  256. package/dist/types/order.d.ts +4 -3
  257. package/dist/types/order.d.ts.map +1 -0
  258. package/dist/types/return-reason.d.ts +5 -0
  259. package/dist/types/return-reason.d.ts.map +1 -0
  260. package/dist/types/return-reason.js +3 -0
  261. package/dist/types/return-reason.js.map +1 -0
  262. package/dist/types/shipping-method-adjustment.d.ts +2 -1
  263. package/dist/types/shipping-method-adjustment.d.ts.map +1 -0
  264. package/dist/types/shipping-method-tax-line.d.ts +1 -0
  265. package/dist/types/shipping-method-tax-line.d.ts.map +1 -0
  266. package/dist/types/shipping-method.d.ts +5 -1
  267. package/dist/types/shipping-method.d.ts.map +1 -0
  268. package/dist/types/tax-line.d.ts +2 -1
  269. package/dist/types/tax-line.d.ts.map +1 -0
  270. package/dist/types/transaction.d.ts +2 -1
  271. package/dist/types/transaction.d.ts.map +1 -0
  272. package/dist/types/utils/index.d.ts +41 -23
  273. package/dist/types/utils/index.d.ts.map +1 -0
  274. package/dist/types/utils/index.js +0 -1
  275. package/dist/types/utils/index.js.map +1 -1
  276. package/dist/utils/actions/cancel-item-fulfillment.d.ts +2 -0
  277. package/dist/utils/actions/cancel-item-fulfillment.d.ts.map +1 -0
  278. package/dist/utils/actions/cancel-item-fulfillment.js +34 -0
  279. package/dist/utils/actions/cancel-item-fulfillment.js.map +1 -0
  280. package/dist/utils/actions/cancel-return.d.ts +1 -0
  281. package/dist/utils/actions/cancel-return.d.ts.map +1 -0
  282. package/dist/utils/actions/cancel-return.js +9 -16
  283. package/dist/utils/actions/cancel-return.js.map +1 -1
  284. package/dist/utils/actions/deliver-item.d.ts +2 -0
  285. package/dist/utils/actions/deliver-item.d.ts.map +1 -0
  286. package/dist/utils/actions/deliver-item.js +38 -0
  287. package/dist/utils/actions/deliver-item.js.map +1 -0
  288. package/dist/utils/actions/fulfill-item.d.ts +1 -0
  289. package/dist/utils/actions/fulfill-item.d.ts.map +1 -0
  290. package/dist/utils/actions/fulfill-item.js +8 -12
  291. package/dist/utils/actions/fulfill-item.js.map +1 -1
  292. package/dist/utils/actions/index.d.ts +7 -1
  293. package/dist/utils/actions/index.d.ts.map +1 -0
  294. package/dist/utils/actions/index.js +6 -1
  295. package/dist/utils/actions/index.js.map +1 -1
  296. package/dist/utils/actions/item-add.d.ts +1 -0
  297. package/dist/utils/actions/item-add.d.ts.map +1 -0
  298. package/dist/utils/actions/item-add.js +17 -26
  299. package/dist/utils/actions/item-add.js.map +1 -1
  300. package/dist/utils/actions/item-remove.d.ts +1 -0
  301. package/dist/utils/actions/item-remove.d.ts.map +1 -0
  302. package/dist/utils/actions/item-remove.js +10 -30
  303. package/dist/utils/actions/item-remove.js.map +1 -1
  304. package/dist/utils/actions/item-update.d.ts +2 -0
  305. package/dist/utils/actions/item-update.d.ts.map +1 -0
  306. package/dist/utils/actions/item-update.js +37 -0
  307. package/dist/utils/actions/item-update.js.map +1 -0
  308. package/dist/utils/actions/receive-damaged-return-item.d.ts +1 -0
  309. package/dist/utils/actions/receive-damaged-return-item.d.ts.map +1 -0
  310. package/dist/utils/actions/receive-damaged-return-item.js +11 -37
  311. package/dist/utils/actions/receive-damaged-return-item.js.map +1 -1
  312. package/dist/utils/actions/receive-return-item.d.ts +1 -0
  313. package/dist/utils/actions/receive-return-item.d.ts.map +1 -0
  314. package/dist/utils/actions/receive-return-item.js +9 -38
  315. package/dist/utils/actions/receive-return-item.js.map +1 -1
  316. package/dist/utils/actions/reinstate-item.d.ts +2 -0
  317. package/dist/utils/actions/reinstate-item.d.ts.map +1 -0
  318. package/dist/utils/actions/reinstate-item.js +32 -0
  319. package/dist/utils/actions/reinstate-item.js.map +1 -0
  320. package/dist/utils/actions/return-item.d.ts +1 -0
  321. package/dist/utils/actions/return-item.d.ts.map +1 -0
  322. package/dist/utils/actions/return-item.js +10 -15
  323. package/dist/utils/actions/return-item.js.map +1 -1
  324. package/dist/utils/actions/ship-item.d.ts +1 -0
  325. package/dist/utils/actions/ship-item.d.ts.map +1 -0
  326. package/dist/utils/actions/ship-item.js +8 -12
  327. package/dist/utils/actions/ship-item.js.map +1 -1
  328. package/dist/utils/actions/shipping-add.d.ts +1 -0
  329. package/dist/utils/actions/shipping-add.d.ts.map +1 -0
  330. package/dist/utils/actions/shipping-add.js +18 -18
  331. package/dist/utils/actions/shipping-add.js.map +1 -1
  332. package/dist/utils/actions/shipping-remove.d.ts +2 -0
  333. package/dist/utils/actions/shipping-remove.d.ts.map +1 -0
  334. package/dist/utils/actions/shipping-remove.js +22 -0
  335. package/dist/utils/actions/shipping-remove.js.map +1 -0
  336. package/dist/utils/actions/write-off-item.d.ts +1 -0
  337. package/dist/utils/actions/write-off-item.d.ts.map +1 -0
  338. package/dist/utils/actions/write-off-item.js +8 -12
  339. package/dist/utils/actions/write-off-item.js.map +1 -1
  340. package/dist/utils/apply-order-changes.d.ts +18 -0
  341. package/dist/utils/apply-order-changes.d.ts.map +1 -0
  342. package/dist/utils/apply-order-changes.js +98 -0
  343. package/dist/utils/apply-order-changes.js.map +1 -0
  344. package/dist/utils/base-repository-find.d.ts +3 -0
  345. package/dist/utils/base-repository-find.d.ts.map +1 -0
  346. package/dist/utils/base-repository-find.js +154 -0
  347. package/dist/utils/base-repository-find.js.map +1 -0
  348. package/dist/utils/calculate-order-change.d.ts +12 -6
  349. package/dist/utils/calculate-order-change.d.ts.map +1 -0
  350. package/dist/utils/calculate-order-change.js +56 -187
  351. package/dist/utils/calculate-order-change.js.map +1 -1
  352. package/dist/utils/index.d.ts +4 -1
  353. package/dist/utils/index.d.ts.map +1 -0
  354. package/dist/utils/index.js +3 -1
  355. package/dist/utils/index.js.map +1 -1
  356. package/dist/utils/set-action-reference.d.ts +2 -0
  357. package/dist/utils/set-action-reference.d.ts.map +1 -0
  358. package/dist/utils/set-action-reference.js +10 -0
  359. package/dist/utils/set-action-reference.js.map +1 -0
  360. package/dist/utils/transform-order.d.ts +5 -4
  361. package/dist/utils/transform-order.d.ts.map +1 -0
  362. package/dist/utils/transform-order.js +138 -21
  363. package/dist/utils/transform-order.js.map +1 -1
  364. package/package.json +25 -26
  365. package/dist/module-definition.d.ts +0 -2
  366. package/dist/module-definition.js +0 -59
  367. package/dist/module-definition.js.map +0 -1
  368. package/dist/scripts/bin/run-seed.d.ts +0 -3
  369. package/dist/scripts/bin/run-seed.js +0 -49
  370. package/dist/scripts/bin/run-seed.js.map +0 -1
  371. package/dist/services/order-change-service.d.ts +0 -15
  372. package/dist/services/order-change-service.js +0 -96
  373. package/dist/services/order-change-service.js.map +0 -1
  374. package/dist/utils/action-key.d.ts +0 -13
  375. package/dist/utils/action-key.js +0 -18
  376. package/dist/utils/action-key.js.map +0 -1
  377. package/dist/utils/actions/cancel.d.ts +0 -1
  378. package/dist/utils/actions/cancel.js +0 -8
  379. package/dist/utils/actions/cancel.js.map +0 -1
@@ -1,10 +1,33 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
2
18
  var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
19
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
20
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
21
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
22
  return c > 3 && r && Object.defineProperty(target, key, r), r;
7
23
  };
24
+ var __importStar = (this && this.__importStar) || function (mod) {
25
+ if (mod && mod.__esModule) return mod;
26
+ var result = {};
27
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
28
+ __setModuleDefault(result, mod);
29
+ return result;
30
+ };
8
31
  var __metadata = (this && this.__metadata) || function (k, v) {
9
32
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
33
  };
@@ -12,47 +35,63 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
12
35
  return function (target, key) { decorator(target, key, paramIndex); }
13
36
  };
14
37
  Object.defineProperty(exports, "__esModule", { value: true });
15
- const types_1 = require("@medusajs/types");
16
- const utils_1 = require("@medusajs/utils");
38
+ const types_1 = require("@medusajs/framework/types");
39
+ const utils_1 = require("@medusajs/framework/utils");
17
40
  const _models_1 = require("../models");
18
41
  const joiner_config_1 = require("../joiner-config");
19
42
  const utils_2 = require("../utils");
20
- const transform_order_1 = require("../utils/transform-order");
21
- const generateMethodForModels = [
22
- _models_1.Address,
23
- _models_1.LineItem,
24
- _models_1.LineItemAdjustment,
25
- _models_1.LineItemTaxLine,
26
- _models_1.ShippingMethod,
27
- _models_1.ShippingMethodAdjustment,
28
- _models_1.ShippingMethodTaxLine,
29
- _models_1.Transaction,
30
- _models_1.OrderChange,
31
- _models_1.OrderChangeAction,
32
- _models_1.OrderItem,
33
- _models_1.OrderSummary,
34
- _models_1.OrderShippingMethod,
35
- ];
36
- class OrderModuleService extends utils_1.ModulesSdkUtils.abstractModuleServiceFactory(_models_1.Order, generateMethodForModels, joiner_config_1.entityNameToLinkableKeysMap) {
37
- constructor({ baseRepository, orderService, addressService, lineItemService, shippingMethodAdjustmentService, shippingMethodService, lineItemAdjustmentService, shippingMethodTaxLineService, lineItemTaxLineService, transactionService, orderChangeService, orderChangeActionService, orderItemService, orderSummaryService, orderShippingMethodService, }, moduleDeclaration) {
43
+ const BundledActions = __importStar(require("./actions"));
44
+ const generateMethodForModels = {
45
+ Order: _models_1.Order,
46
+ OrderAddress: _models_1.OrderAddress,
47
+ OrderLineItem: _models_1.OrderLineItem,
48
+ OrderLineItemAdjustment: _models_1.OrderLineItemAdjustment,
49
+ OrderLineItemTaxLine: _models_1.OrderLineItemTaxLine,
50
+ OrderShippingMethod: _models_1.OrderShippingMethod,
51
+ OrderShippingMethodAdjustment: _models_1.OrderShippingMethodAdjustment,
52
+ OrderShippingMethodTaxLine: _models_1.OrderShippingMethodTaxLine,
53
+ OrderTransaction: _models_1.OrderTransaction,
54
+ OrderChange: _models_1.OrderChange,
55
+ OrderChangeAction: _models_1.OrderChangeAction,
56
+ OrderItem: _models_1.OrderItem,
57
+ OrderSummary: _models_1.OrderSummary,
58
+ OrderShipping: _models_1.OrderShipping,
59
+ ReturnReason: _models_1.ReturnReason,
60
+ Return: _models_1.Return,
61
+ ReturnItem: _models_1.ReturnItem,
62
+ OrderClaim: _models_1.OrderClaim,
63
+ OrderClaimItem: _models_1.OrderClaimItem,
64
+ OrderClaimItemImage: _models_1.OrderClaimItemImage,
65
+ OrderExchange: _models_1.OrderExchange,
66
+ OrderExchangeItem: _models_1.OrderExchangeItem,
67
+ };
68
+ // TODO: rm template args here, keep it for later to not collide with carlos work at least as little as possible
69
+ class OrderModuleService extends utils_1.ModulesSdkUtils.MedusaService(generateMethodForModels) {
70
+ constructor({ baseRepository, orderService, orderAddressService, orderLineItemService, orderShippingMethodAdjustmentService, orderShippingMethodService, orderLineItemAdjustmentService, orderShippingMethodTaxLineService, orderLineItemTaxLineService, orderTransactionService, orderChangeService, orderChangeActionService, orderItemService, orderSummaryService, orderShippingService, returnReasonService, returnService, returnItemService, orderClaimService, orderExchangeService, }, moduleDeclaration) {
38
71
  // @ts-ignore
39
72
  super(...arguments);
40
73
  this.moduleDeclaration = moduleDeclaration;
41
74
  this.baseRepository_ = baseRepository;
42
75
  this.orderService_ = orderService;
43
- this.addressService_ = addressService;
44
- this.lineItemService_ = lineItemService;
45
- this.shippingMethodAdjustmentService_ = shippingMethodAdjustmentService;
46
- this.shippingMethodService_ = shippingMethodService;
47
- this.lineItemAdjustmentService_ = lineItemAdjustmentService;
48
- this.shippingMethodTaxLineService_ = shippingMethodTaxLineService;
49
- this.lineItemTaxLineService_ = lineItemTaxLineService;
50
- this.transactionService_ = transactionService;
76
+ this.orderAddressService_ = orderAddressService;
77
+ this.orderLineItemService_ = orderLineItemService;
78
+ this.orderShippingMethodAdjustmentService_ =
79
+ orderShippingMethodAdjustmentService;
80
+ this.orderShippingMethodService_ = orderShippingMethodService;
81
+ this.orderLineItemAdjustmentService_ = orderLineItemAdjustmentService;
82
+ this.orderShippingMethodTaxLineService_ = orderShippingMethodTaxLineService;
83
+ this.orderLineItemTaxLineService_ = orderLineItemTaxLineService;
84
+ this.orderTransactionService_ = orderTransactionService;
51
85
  this.orderChangeService_ = orderChangeService;
52
86
  this.orderChangeActionService_ = orderChangeActionService;
53
87
  this.orderItemService_ = orderItemService;
54
88
  this.orderSummaryService_ = orderSummaryService;
55
- this.orderShippingMethodService_ = orderShippingMethodService;
89
+ this.orderShippingService_ = orderShippingService;
90
+ this.returnReasonService_ = returnReasonService;
91
+ this.returnService_ = returnService;
92
+ this.returnItemService_ = returnItemService;
93
+ this.orderClaimService_ = orderClaimService;
94
+ this.orderExchangeService_ = orderExchangeService;
56
95
  }
57
96
  __joinerConfig() {
58
97
  return joiner_config_1.joinerConfig;
@@ -76,7 +115,7 @@ class OrderModuleService extends utils_1.ModulesSdkUtils.abstractModuleServiceFa
76
115
  "shipping_subtotal",
77
116
  "shipping_tax_total",
78
117
  "original_shipping_tax_total",
79
- "original_shipping_tax_subtotal",
118
+ "original_shipping_subtotal",
80
119
  "original_shipping_total",
81
120
  ];
82
121
  const includeTotals = (config?.select ?? []).some((field) => totalFields.includes(field));
@@ -86,9 +125,9 @@ class OrderModuleService extends utils_1.ModulesSdkUtils.abstractModuleServiceFa
86
125
  return includeTotals;
87
126
  }
88
127
  addRelationsToCalculateTotals(config, totalFields) {
89
- config.relations ?? (config.relations = []);
90
- config.select ?? (config.select = []);
91
- const requiredFieldsForTotals = [
128
+ config.relations ??= [];
129
+ config.select ??= [];
130
+ const requiredRelationsForTotals = [
92
131
  "items",
93
132
  "items.tax_lines",
94
133
  "items.adjustments",
@@ -98,39 +137,150 @@ class OrderModuleService extends utils_1.ModulesSdkUtils.abstractModuleServiceFa
98
137
  ];
99
138
  config.relations = (0, utils_1.deduplicate)([
100
139
  ...config.relations,
101
- ...requiredFieldsForTotals,
140
+ ...requiredRelationsForTotals,
102
141
  ]);
103
142
  config.select = config.select.filter((field) => {
104
- return (!requiredFieldsForTotals.some((val) => val.startsWith(field)) && !totalFields.includes(field));
143
+ return (!requiredRelationsForTotals.some((val) => val.startsWith(field)) && !totalFields.includes(field));
144
+ });
145
+ }
146
+ // @ts-expect-error
147
+ async retrieveOrder(id, config, sharedContext) {
148
+ config ??= {};
149
+ const includeTotals = this.shouldIncludeTotals(config);
150
+ const order = await super.retrieveOrder(id, config, sharedContext);
151
+ const orderChange = await this.getActiveOrderChange_(order.id, false, sharedContext);
152
+ order.order_change = orderChange;
153
+ return (0, utils_2.formatOrder)(order, {
154
+ entity: _models_1.Order,
155
+ includeTotals,
156
+ });
157
+ }
158
+ // @ts-expect-error
159
+ async listOrders(filters, config, sharedContext) {
160
+ config ??= {};
161
+ const includeTotals = this.shouldIncludeTotals(config);
162
+ const orders = await super.listOrders(filters, config, sharedContext);
163
+ return (0, utils_2.formatOrder)(orders, {
164
+ entity: _models_1.Order,
165
+ includeTotals,
166
+ });
167
+ }
168
+ // @ts-expect-error
169
+ async listAndCountOrders(filters, config, sharedContext) {
170
+ config ??= {};
171
+ const includeTotals = this.shouldIncludeTotals(config);
172
+ const [orders, count] = await super.listAndCountOrders(filters, config, sharedContext);
173
+ return [
174
+ (0, utils_2.formatOrder)(orders, {
175
+ entity: _models_1.Order,
176
+ includeTotals,
177
+ }),
178
+ count,
179
+ ];
180
+ }
181
+ // @ts-ignore
182
+ async retrieveReturn(id, config, sharedContext) {
183
+ config ??= {};
184
+ const includeTotals = this.shouldIncludeTotals(config);
185
+ const returnOrder = await super.retrieveReturn(id, config, sharedContext);
186
+ return (0, utils_2.formatOrder)(returnOrder, {
187
+ entity: _models_1.Return,
188
+ includeTotals,
189
+ });
190
+ }
191
+ // @ts-ignore
192
+ async listReturns(filters, config, sharedContext) {
193
+ config ??= {};
194
+ const includeTotals = this.shouldIncludeTotals(config);
195
+ const returnOrders = await super.listReturns(filters, config, sharedContext);
196
+ return (0, utils_2.formatOrder)(returnOrders, {
197
+ entity: _models_1.Return,
198
+ includeTotals,
199
+ });
200
+ }
201
+ // @ts-ignore
202
+ async listAndCountReturns(filters, config, sharedContext) {
203
+ config ??= {};
204
+ const includeTotals = this.shouldIncludeTotals(config);
205
+ const [returnOrders, count] = await super.listAndCountReturns(filters, config, sharedContext);
206
+ return [
207
+ (0, utils_2.formatOrder)(returnOrders, {
208
+ entity: _models_1.Return,
209
+ includeTotals,
210
+ }),
211
+ count,
212
+ ];
213
+ }
214
+ // @ts-ignore
215
+ async retrieveOrderClaim(id, config, sharedContext) {
216
+ config ??= {};
217
+ const includeTotals = this.shouldIncludeTotals(config);
218
+ const returnOrder = await super.retrieveOrderClaim(id, config, sharedContext);
219
+ return (0, utils_2.formatOrder)(returnOrder, {
220
+ entity: _models_1.OrderClaim,
221
+ includeTotals,
222
+ });
223
+ }
224
+ // @ts-ignore
225
+ async listOrderClaims(filters, config, sharedContext) {
226
+ config ??= {};
227
+ const includeTotals = this.shouldIncludeTotals(config);
228
+ const returnOrders = await super.listOrderClaims(filters, config, sharedContext);
229
+ return (0, utils_2.formatOrder)(returnOrders, {
230
+ entity: _models_1.OrderClaim,
231
+ includeTotals,
105
232
  });
106
233
  }
107
- async retrieve(id, config, sharedContext) {
108
- config ?? (config = {});
234
+ // @ts-ignore
235
+ async listAndCountOrderClaims(filters, config, sharedContext) {
236
+ config ??= {};
237
+ const includeTotals = this.shouldIncludeTotals(config);
238
+ const [returnOrders, count] = await super.listAndCountOrderClaims(filters, config, sharedContext);
239
+ return [
240
+ (0, utils_2.formatOrder)(returnOrders, {
241
+ entity: _models_1.OrderClaim,
242
+ includeTotals,
243
+ }),
244
+ count,
245
+ ];
246
+ }
247
+ // @ts-ignore
248
+ async retrieveOrderExchange(id, config, sharedContext) {
249
+ config ??= {};
109
250
  const includeTotals = this.shouldIncludeTotals(config);
110
- const order = await super.retrieve(id, config, sharedContext);
111
- return (0, transform_order_1.formatOrder)(order, { includeTotals });
251
+ const returnOrder = await super.retrieveOrderExchange(id, config, sharedContext);
252
+ return (0, utils_2.formatOrder)(returnOrder, {
253
+ entity: _models_1.OrderExchange,
254
+ includeTotals,
255
+ });
112
256
  }
113
- async list(filters, config, sharedContext) {
114
- config ?? (config = {});
257
+ // @ts-ignore
258
+ async listOrderExchanges(filters, config, sharedContext) {
259
+ config ??= {};
115
260
  const includeTotals = this.shouldIncludeTotals(config);
116
- const orders = await super.list(filters, config, sharedContext);
117
- return (0, transform_order_1.formatOrder)(orders, {
261
+ const returnOrders = await super.listOrderExchanges(filters, config, sharedContext);
262
+ return (0, utils_2.formatOrder)(returnOrders, {
263
+ entity: _models_1.OrderExchange,
118
264
  includeTotals,
119
265
  });
120
266
  }
121
- async listAndCount(filters, config, sharedContext) {
122
- config ?? (config = {});
267
+ // @ts-ignore
268
+ async listAndCountOrderExchanges(filters, config, sharedContext) {
269
+ config ??= {};
123
270
  const includeTotals = this.shouldIncludeTotals(config);
124
- const [orders, count] = await super.listAndCount(filters, config, sharedContext);
271
+ const [returnOrders, count] = await super.listAndCountOrderExchanges(filters, config, sharedContext);
125
272
  return [
126
- (0, transform_order_1.formatOrder)(orders, { includeTotals }),
273
+ (0, utils_2.formatOrder)(returnOrders, {
274
+ entity: _models_1.OrderExchange,
275
+ includeTotals,
276
+ }),
127
277
  count,
128
278
  ];
129
279
  }
130
- async create(data, sharedContext = {}) {
280
+ async createOrders(data, sharedContext = {}) {
131
281
  const input = Array.isArray(data) ? data : [data];
132
- const orders = await this.create_(input, sharedContext);
133
- const result = await this.list({
282
+ const orders = await this.createOrders_(input, sharedContext);
283
+ const result = await this.listOrders({
134
284
  id: orders.map((p) => p.id),
135
285
  }, {
136
286
  relations: [
@@ -148,7 +298,7 @@ class OrderModuleService extends utils_1.ModulesSdkUtils.abstractModuleServiceFa
148
298
  }, sharedContext);
149
299
  return (Array.isArray(data) ? result : result[0]);
150
300
  }
151
- async create_(data, sharedContext = {}) {
301
+ async createOrders_(data, sharedContext = {}) {
152
302
  const lineItemsToCreate = [];
153
303
  const createdOrders = [];
154
304
  for (const { items, shipping_methods, ...order } of data) {
@@ -161,6 +311,7 @@ class OrderModuleService extends utils_1.ModulesSdkUtils.abstractModuleServiceFa
161
311
  ord.shipping_methods = shippingMethods;
162
312
  const orderWithTotals = (0, utils_1.decorateCartTotals)({
163
313
  ...ord,
314
+ shipping_methods,
164
315
  items,
165
316
  });
166
317
  const calculated = (0, utils_2.calculateOrderChange)({
@@ -185,18 +336,18 @@ class OrderModuleService extends utils_1.ModulesSdkUtils.abstractModuleServiceFa
185
336
  }
186
337
  }
187
338
  if (lineItemsToCreate.length) {
188
- await this.createLineItemsBulk_(lineItemsToCreate, sharedContext);
339
+ await this.createOrderLineItemsBulk_(lineItemsToCreate, sharedContext);
189
340
  }
190
341
  return createdOrders;
191
342
  }
192
- async update(dataOrIdOrSelector, data, sharedContext = {}) {
193
- const result = await this.update_(dataOrIdOrSelector, data, sharedContext);
343
+ async updateOrders(dataOrIdOrSelector, data, sharedContext = {}) {
344
+ const result = await this.updateOrders_(dataOrIdOrSelector, data, sharedContext);
194
345
  const serializedResult = await this.baseRepository_.serialize(result, {
195
346
  populate: true,
196
347
  });
197
348
  return (0, utils_1.isString)(dataOrIdOrSelector) ? serializedResult[0] : serializedResult;
198
349
  }
199
- async update_(dataOrIdOrSelector, data, sharedContext = {}) {
350
+ async updateOrders_(dataOrIdOrSelector, data, sharedContext = {}) {
200
351
  let toUpdate = [];
201
352
  if ((0, utils_1.isString)(dataOrIdOrSelector)) {
202
353
  toUpdate = [
@@ -221,17 +372,17 @@ class OrderModuleService extends utils_1.ModulesSdkUtils.abstractModuleServiceFa
221
372
  const result = await this.orderService_.update(toUpdate, sharedContext);
222
373
  return result;
223
374
  }
224
- async createLineItems(orderIdOrData, data, sharedContext = {}) {
375
+ async createOrderLineItems(orderIdOrData, data, sharedContext = {}) {
225
376
  let items = [];
226
377
  if ((0, utils_1.isString)(orderIdOrData)) {
227
- items = await this.createLineItems_(orderIdOrData, data, sharedContext);
378
+ items = await this.createOrderLineItems_(orderIdOrData, data, sharedContext);
228
379
  }
229
380
  else {
230
381
  const data = Array.isArray(orderIdOrData)
231
382
  ? orderIdOrData
232
383
  : [orderIdOrData];
233
384
  const allOrderIds = data.map((dt) => dt.order_id);
234
- const order = await this.list({ id: allOrderIds }, { select: ["id", "version"] }, sharedContext);
385
+ const order = await this.listOrders({ id: allOrderIds }, { select: ["id", "version"] }, sharedContext);
235
386
  const mapOrderVersion = order.reduce((acc, curr) => {
236
387
  acc[curr.id] = curr.version;
237
388
  return acc;
@@ -242,14 +393,14 @@ class OrderModuleService extends utils_1.ModulesSdkUtils.abstractModuleServiceFa
242
393
  version: mapOrderVersion[dt.order_id],
243
394
  };
244
395
  });
245
- items = await this.createLineItemsBulk_(lineItems, sharedContext);
396
+ items = await this.createOrderLineItemsBulk_(lineItems, sharedContext);
246
397
  }
247
398
  return await this.baseRepository_.serialize(items, {
248
399
  populate: true,
249
400
  });
250
401
  }
251
- async createLineItems_(orderId, items, sharedContext = {}) {
252
- const order = await this.retrieve(orderId, { select: ["id", "version"] }, sharedContext);
402
+ async createOrderLineItems_(orderId, items, sharedContext = {}) {
403
+ const order = await this.retrieveOrder(orderId, { select: ["id", "version"] }, sharedContext);
253
404
  const toUpdate = items.map((item) => {
254
405
  return {
255
406
  ...item,
@@ -257,11 +408,11 @@ class OrderModuleService extends utils_1.ModulesSdkUtils.abstractModuleServiceFa
257
408
  version: order.version,
258
409
  };
259
410
  });
260
- return await this.createLineItemsBulk_(toUpdate, sharedContext);
411
+ return await this.createOrderLineItemsBulk_(toUpdate, sharedContext);
261
412
  }
262
- async createLineItemsBulk_(data, sharedContext = {}) {
413
+ async createOrderLineItemsBulk_(data, sharedContext = {}) {
263
414
  const orderItemToCreate = [];
264
- const lineItems = await this.lineItemService_.create(data, sharedContext);
415
+ const lineItems = await this.orderLineItemService_.create(data, sharedContext);
265
416
  for (let i = 0; i < lineItems.length; i++) {
266
417
  const item = lineItems[i];
267
418
  const toCreate = data[i];
@@ -279,10 +430,10 @@ class OrderModuleService extends utils_1.ModulesSdkUtils.abstractModuleServiceFa
279
430
  }
280
431
  return lineItems;
281
432
  }
282
- async updateLineItems(lineItemIdOrDataOrSelector, data, sharedContext = {}) {
433
+ async updateOrderLineItems(lineItemIdOrDataOrSelector, data, sharedContext = {}) {
283
434
  let items = [];
284
435
  if ((0, utils_1.isString)(lineItemIdOrDataOrSelector)) {
285
- const item = await this.updateLineItem_(lineItemIdOrDataOrSelector, data, sharedContext);
436
+ const item = await this.updateOrderLineItem_(lineItemIdOrDataOrSelector, data, sharedContext);
286
437
  return await this.baseRepository_.serialize(item, {
287
438
  populate: true,
288
439
  });
@@ -295,13 +446,13 @@ class OrderModuleService extends utils_1.ModulesSdkUtils.abstractModuleServiceFa
295
446
  data: data,
296
447
  },
297
448
  ];
298
- items = await this.updateLineItemsWithSelector_(toUpdate, sharedContext);
449
+ items = await this.updateOrderLineItemsWithSelector_(toUpdate, sharedContext);
299
450
  return await this.baseRepository_.serialize(items, {
300
451
  populate: true,
301
452
  });
302
453
  }
303
- async updateLineItem_(lineItemId, data, sharedContext = {}) {
304
- const [item] = await this.lineItemService_.update([{ id: lineItemId, ...data }], sharedContext);
454
+ async updateOrderLineItem_(lineItemId, data, sharedContext = {}) {
455
+ const [item] = await this.orderLineItemService_.update([{ id: lineItemId, ...data }], sharedContext);
305
456
  if ("quantity" in data) {
306
457
  await this.updateOrderItemWithSelector_([
307
458
  {
@@ -312,11 +463,11 @@ class OrderModuleService extends utils_1.ModulesSdkUtils.abstractModuleServiceFa
312
463
  }
313
464
  return item;
314
465
  }
315
- async updateLineItemsWithSelector_(updates, sharedContext = {}) {
466
+ async updateOrderLineItemsWithSelector_(updates, sharedContext = {}) {
316
467
  let toUpdate = [];
317
468
  const detailsToUpdate = [];
318
469
  for (const { selector, data } of updates) {
319
- const items = await this.listLineItems({ ...selector }, {}, sharedContext);
470
+ const items = await this.listOrderLineItems({ ...selector }, {}, sharedContext);
320
471
  items.forEach((item) => {
321
472
  toUpdate.push({
322
473
  ...data,
@@ -333,7 +484,7 @@ class OrderModuleService extends utils_1.ModulesSdkUtils.abstractModuleServiceFa
333
484
  if (detailsToUpdate.length) {
334
485
  await this.updateOrderItemWithSelector_(detailsToUpdate, sharedContext);
335
486
  }
336
- return await this.lineItemService_.update(toUpdate, sharedContext);
487
+ return await this.orderLineItemService_.update(toUpdate, sharedContext);
337
488
  }
338
489
  async updateOrderItem(orderItemIdOrDataOrSelector, data, sharedContext = {}) {
339
490
  let items = [];
@@ -373,35 +524,17 @@ class OrderModuleService extends utils_1.ModulesSdkUtils.abstractModuleServiceFa
373
524
  }
374
525
  return await this.orderItemService_.update(toUpdate, sharedContext);
375
526
  }
376
- async createAddresses(data, sharedContext = {}) {
377
- const input = Array.isArray(data) ? data : [data];
378
- const addresses = await this.createAddresses_(input, sharedContext);
379
- const result = await this.listAddresses({ id: addresses.map((p) => p.id) }, {}, sharedContext);
380
- return (Array.isArray(data) ? result : result[0]);
381
- }
382
- async createAddresses_(data, sharedContext = {}) {
383
- return await this.addressService_.create(data, sharedContext);
384
- }
385
- async updateAddresses(data, sharedContext = {}) {
386
- const input = Array.isArray(data) ? data : [data];
387
- const addresses = await this.updateAddresses_(input, sharedContext);
388
- const result = await this.listAddresses({ id: addresses.map((p) => p.id) }, {}, sharedContext);
389
- return (Array.isArray(data) ? result : result[0]);
390
- }
391
- async updateAddresses_(data, sharedContext = {}) {
392
- return await this.addressService_.update(data, sharedContext);
393
- }
394
- async createShippingMethods(orderIdOrData, data, sharedContext = {}) {
527
+ async createOrderShippingMethods(orderIdOrData, data, sharedContext = {}) {
395
528
  let methods;
396
529
  if ((0, utils_1.isString)(orderIdOrData)) {
397
- methods = await this.createShippingMethods_(orderIdOrData, data, sharedContext);
530
+ methods = await this.createOrderShippingMethods_(orderIdOrData, data, sharedContext);
398
531
  }
399
532
  else {
400
533
  const data = Array.isArray(orderIdOrData)
401
534
  ? orderIdOrData
402
535
  : [orderIdOrData];
403
536
  const allOrderIds = data.map((dt) => dt.order_id);
404
- const order = await this.list({ id: allOrderIds }, { select: ["id", "version"] }, sharedContext);
537
+ const order = await this.listOrders({ id: allOrderIds }, { select: ["id", "version"] }, sharedContext);
405
538
  const mapOrderVersion = order.reduce((acc, curr) => {
406
539
  acc[curr.id] = curr.version;
407
540
  return acc;
@@ -410,52 +543,86 @@ class OrderModuleService extends utils_1.ModulesSdkUtils.abstractModuleServiceFa
410
543
  return {
411
544
  shipping_method: dt,
412
545
  order_id: dt.order_id,
413
- version: mapOrderVersion[dt.order_id],
546
+ return_id: dt.return_id,
547
+ claim_id: dt.claim_id,
548
+ exchange_id: dt.exchange_id,
549
+ version: dt.version ?? mapOrderVersion[dt.order_id],
414
550
  };
415
551
  });
416
- methods = await this.createShippingMethodsBulk_(orderShippingMethodData, sharedContext);
552
+ methods = await this.createOrderShippingMethodsBulk_(orderShippingMethodData, sharedContext);
417
553
  }
418
554
  return await this.baseRepository_.serialize(methods, { populate: true });
419
555
  }
420
- async createShippingMethods_(orderId, data, sharedContext = {}) {
421
- const order = await this.retrieve(orderId, { select: ["id", "version"] }, sharedContext);
422
- const methods = data.map((method) => {
556
+ async createOrderShippingMethods_(orderId, data, sharedContext = {}) {
557
+ const order = await this.retrieveOrder(orderId, { select: ["id", "version"] }, sharedContext);
558
+ const methods = data.map((methodData) => {
423
559
  return {
424
- shipping_method: method,
560
+ shipping_method: methodData,
425
561
  order_id: order.id,
426
- version: method.version ?? order.version ?? 1,
562
+ return_id: methodData.return_id,
563
+ claim_id: methodData.claim_id,
564
+ exchange_id: methodData.exchange_id,
565
+ version: methodData.version ?? order.version ?? 1,
427
566
  };
428
567
  });
429
- return await this.createShippingMethodsBulk_(methods, sharedContext);
568
+ return await this.createOrderShippingMethodsBulk_(methods, sharedContext);
430
569
  }
431
- async createShippingMethodsBulk_(data, sharedContext = {}) {
432
- const sm = await this.orderShippingMethodService_.create(data, sharedContext);
570
+ async createOrderShippingMethodsBulk_(data, sharedContext = {}) {
571
+ const sm = await this.orderShippingService_.create(data, sharedContext);
433
572
  return sm.map((s) => s.shipping_method);
434
573
  }
435
- async createLineItemAdjustments(orderIdOrData, adjustments, sharedContext = {}) {
574
+ // @ts-ignore
575
+ async softDeleteOrderShippingMethods(ids, config, sharedContext) {
576
+ const rel = await super.listOrderShippings({
577
+ shipping_method_id: ids,
578
+ }, {
579
+ select: ["id"],
580
+ }, sharedContext);
581
+ const orderShippingIds = rel.map((r) => r.id);
582
+ const [returned] = await (0, utils_1.promiseAll)([
583
+ super.softDeleteOrderShippingMethods(ids, config, sharedContext),
584
+ super.softDeleteOrderShippings(orderShippingIds, config, sharedContext),
585
+ ]);
586
+ return returned;
587
+ }
588
+ // @ts-ignore
589
+ async restoreOrderShippingMethods(ids, config, sharedContext) {
590
+ const rel = await super.listOrderShippings({
591
+ shipping_method_id: ids,
592
+ }, {
593
+ select: ["id"],
594
+ }, sharedContext);
595
+ const shippingIds = rel.map((r) => r.id);
596
+ const [returned] = await (0, utils_1.promiseAll)([
597
+ super.restoreOrderShippingMethods(ids, config, sharedContext),
598
+ super.restoreOrderShippings(shippingIds, config, sharedContext),
599
+ ]);
600
+ return returned;
601
+ }
602
+ async createOrderLineItemAdjustments(orderIdOrData, adjustments, sharedContext = {}) {
436
603
  let addedAdjustments = [];
437
604
  if ((0, utils_1.isString)(orderIdOrData)) {
438
- const order = await this.retrieve(orderIdOrData, { select: ["id"], relations: ["items.item"] }, sharedContext);
605
+ const order = await this.retrieveOrder(orderIdOrData, { select: ["id"], relations: ["items.item"] }, sharedContext);
439
606
  const lineIds = order.items?.map((item) => item.id);
440
607
  for (const adj of adjustments || []) {
441
608
  if (!lineIds?.includes(adj.item_id)) {
442
609
  throw new utils_1.MedusaError(utils_1.MedusaError.Types.INVALID_DATA, `Line item with id ${adj.item_id} does not exist on order with id ${orderIdOrData}`);
443
610
  }
444
611
  }
445
- addedAdjustments = await this.lineItemAdjustmentService_.create(adjustments, sharedContext);
612
+ addedAdjustments = await this.orderLineItemAdjustmentService_.create(adjustments, sharedContext);
446
613
  }
447
614
  else {
448
615
  const data = Array.isArray(orderIdOrData)
449
616
  ? orderIdOrData
450
617
  : [orderIdOrData];
451
- addedAdjustments = await this.lineItemAdjustmentService_.create(data, sharedContext);
618
+ addedAdjustments = await this.orderLineItemAdjustmentService_.create(data, sharedContext);
452
619
  }
453
620
  return await this.baseRepository_.serialize(addedAdjustments, {
454
621
  populate: true,
455
622
  });
456
623
  }
457
- async setLineItemAdjustments(orderId, adjustments, sharedContext = {}) {
458
- const order = await this.retrieve(orderId, { select: ["id"], relations: ["items.item.adjustments"] }, sharedContext);
624
+ async setOrderLineItemAdjustments(orderId, adjustments, sharedContext = {}) {
625
+ const order = await this.retrieveOrder(orderId, { select: ["id"], relations: ["items.item.adjustments"] }, sharedContext);
459
626
  const existingAdjustments = (order.items ?? [])
460
627
  .map((item) => item.adjustments ?? [])
461
628
  .flat()
@@ -471,15 +638,15 @@ class OrderModuleService extends utils_1.ModulesSdkUtils.abstractModuleServiceFa
471
638
  }
472
639
  });
473
640
  if (toDelete.length) {
474
- await this.lineItemAdjustmentService_.delete(toDelete, sharedContext);
641
+ await this.orderLineItemAdjustmentService_.delete(toDelete, sharedContext);
475
642
  }
476
- let result = await this.lineItemAdjustmentService_.upsert(adjustments, sharedContext);
643
+ let result = await this.orderLineItemAdjustmentService_.upsert(adjustments, sharedContext);
477
644
  return await this.baseRepository_.serialize(result, {
478
645
  populate: true,
479
646
  });
480
647
  }
481
- async setShippingMethodAdjustments(orderId, adjustments, sharedContext = {}) {
482
- const order = await this.retrieve(orderId, { select: ["id"], relations: ["shipping_methods.adjustments"] }, sharedContext);
648
+ async setOrderShippingMethodAdjustments(orderId, adjustments, sharedContext = {}) {
649
+ const order = await this.retrieveOrder(orderId, { select: ["id"], relations: ["shipping_methods.adjustments"] }, sharedContext);
483
650
  const existingAdjustments = (order.shipping_methods ?? [])
484
651
  .map((shippingMethod) => shippingMethod.adjustments ?? [])
485
652
  .flat()
@@ -495,30 +662,32 @@ class OrderModuleService extends utils_1.ModulesSdkUtils.abstractModuleServiceFa
495
662
  }
496
663
  });
497
664
  if (toDelete.length) {
498
- await this.shippingMethodAdjustmentService_.delete(toDelete, sharedContext);
665
+ await this.orderShippingMethodAdjustmentService_.delete(toDelete, sharedContext);
499
666
  }
500
- const result = await this.shippingMethodAdjustmentService_.upsert(adjustments, sharedContext);
667
+ const result = await this.orderShippingMethodAdjustmentService_.upsert(adjustments, sharedContext);
501
668
  return await this.baseRepository_.serialize(result, {
502
669
  populate: true,
503
670
  });
504
671
  }
505
- async createShippingMethodAdjustments(orderIdOrData, adjustments, sharedContext = {}) {
672
+ async createOrderShippingMethodAdjustments(orderIdOrData, adjustments, sharedContext = {}) {
506
673
  let addedAdjustments = [];
507
674
  if ((0, utils_1.isString)(orderIdOrData)) {
508
- const order = await this.retrieve(orderIdOrData, { select: ["id"], relations: ["shipping_methods"] }, sharedContext);
675
+ const order = await this.retrieveOrder(orderIdOrData, { select: ["id"], relations: ["shipping_methods"] }, sharedContext);
509
676
  const methodIds = order.shipping_methods?.map((method) => method.id);
510
677
  for (const adj of adjustments || []) {
511
678
  if (!methodIds?.includes(adj.shipping_method_id)) {
512
679
  throw new utils_1.MedusaError(utils_1.MedusaError.Types.INVALID_DATA, `Shipping method with id ${adj.shipping_method_id} does not exist on order with id ${orderIdOrData}`);
513
680
  }
514
681
  }
515
- addedAdjustments = await this.shippingMethodAdjustmentService_.create(adjustments, sharedContext);
682
+ addedAdjustments =
683
+ await this.orderShippingMethodAdjustmentService_.create(adjustments, sharedContext);
516
684
  }
517
685
  else {
518
686
  const data = Array.isArray(orderIdOrData)
519
687
  ? orderIdOrData
520
688
  : [orderIdOrData];
521
- addedAdjustments = await this.shippingMethodAdjustmentService_.create(data, sharedContext);
689
+ addedAdjustments =
690
+ await this.orderShippingMethodAdjustmentService_.create(data, sharedContext);
522
691
  }
523
692
  if ((0, utils_1.isObject)(orderIdOrData)) {
524
693
  return await this.baseRepository_.serialize(addedAdjustments[0], {
@@ -529,17 +698,17 @@ class OrderModuleService extends utils_1.ModulesSdkUtils.abstractModuleServiceFa
529
698
  populate: true,
530
699
  });
531
700
  }
532
- async createLineItemTaxLines(orderIdOrData, taxLines, sharedContext = {}) {
701
+ async createOrderLineItemTaxLines(orderIdOrData, taxLines, sharedContext = {}) {
533
702
  let addedTaxLines;
534
703
  if ((0, utils_1.isString)(orderIdOrData)) {
535
704
  const lines = Array.isArray(taxLines) ? taxLines : [taxLines];
536
- addedTaxLines = await this.lineItemTaxLineService_.create(lines, sharedContext);
705
+ addedTaxLines = await this.orderLineItemTaxLineService_.create(lines, sharedContext);
537
706
  }
538
707
  else {
539
708
  const data = Array.isArray(orderIdOrData)
540
709
  ? orderIdOrData
541
710
  : [orderIdOrData];
542
- addedTaxLines = await this.lineItemTaxLineService_.create(data, sharedContext);
711
+ addedTaxLines = await this.orderLineItemTaxLineService_.create(data, sharedContext);
543
712
  }
544
713
  const serialized = await this.baseRepository_.serialize(addedTaxLines, {
545
714
  populate: true,
@@ -549,8 +718,8 @@ class OrderModuleService extends utils_1.ModulesSdkUtils.abstractModuleServiceFa
549
718
  }
550
719
  return serialized;
551
720
  }
552
- async setLineItemTaxLines(orderId, taxLines, sharedContext = {}) {
553
- const order = await this.retrieve(orderId, { select: ["id"], relations: ["items.item.tax_lines"] }, sharedContext);
721
+ async setOrderLineItemTaxLines(orderId, taxLines, sharedContext = {}) {
722
+ const order = await this.retrieveOrder(orderId, { select: ["id"], relations: ["items.item.tax_lines"] }, sharedContext);
554
723
  const existingTaxLines = (order.items ?? [])
555
724
  .map((item) => item.tax_lines ?? [])
556
725
  .flat()
@@ -565,21 +734,21 @@ class OrderModuleService extends utils_1.ModulesSdkUtils.abstractModuleServiceFa
565
734
  }
566
735
  });
567
736
  if (toDelete.length) {
568
- await this.lineItemTaxLineService_.delete(toDelete, sharedContext);
737
+ await this.orderLineItemTaxLineService_.delete(toDelete, sharedContext);
569
738
  }
570
- const result = await this.lineItemTaxLineService_.upsert(taxLines, sharedContext);
739
+ const result = await this.orderLineItemTaxLineService_.upsert(taxLines, sharedContext);
571
740
  return await this.baseRepository_.serialize(result, {
572
741
  populate: true,
573
742
  });
574
743
  }
575
- async createShippingMethodTaxLines(orderIdOrData, taxLines, sharedContext = {}) {
744
+ async createOrderShippingMethodTaxLines(orderIdOrData, taxLines, sharedContext = {}) {
576
745
  let addedTaxLines;
577
746
  if ((0, utils_1.isString)(orderIdOrData)) {
578
747
  const lines = Array.isArray(taxLines) ? taxLines : [taxLines];
579
- addedTaxLines = await this.shippingMethodTaxLineService_.create(lines, sharedContext);
748
+ addedTaxLines = await this.orderShippingMethodTaxLineService_.create(lines, sharedContext);
580
749
  }
581
750
  else {
582
- addedTaxLines = await this.shippingMethodTaxLineService_.create(taxLines, sharedContext);
751
+ addedTaxLines = await this.orderShippingMethodTaxLineService_.create(taxLines, sharedContext);
583
752
  }
584
753
  const serialized = await this.baseRepository_.serialize(addedTaxLines[0], {
585
754
  populate: true,
@@ -589,8 +758,8 @@ class OrderModuleService extends utils_1.ModulesSdkUtils.abstractModuleServiceFa
589
758
  }
590
759
  return serialized;
591
760
  }
592
- async setShippingMethodTaxLines(orderId, taxLines, sharedContext = {}) {
593
- const order = await this.retrieve(orderId, { select: ["id"], relations: ["shipping_methods.tax_lines"] }, sharedContext);
761
+ async setOrderShippingMethodTaxLines(orderId, taxLines, sharedContext = {}) {
762
+ const order = await this.retrieveOrder(orderId, { select: ["id"], relations: ["shipping_methods.tax_lines"] }, sharedContext);
594
763
  const existingTaxLines = (order.shipping_methods ?? [])
595
764
  .map((shippingMethod) => shippingMethod.tax_lines ?? [])
596
765
  .flat()
@@ -605,13 +774,49 @@ class OrderModuleService extends utils_1.ModulesSdkUtils.abstractModuleServiceFa
605
774
  }
606
775
  });
607
776
  if (toDelete.length) {
608
- await this.shippingMethodTaxLineService_.delete(toDelete, sharedContext);
777
+ await this.orderShippingMethodTaxLineService_.delete(toDelete, sharedContext);
609
778
  }
610
- const result = await this.shippingMethodTaxLineService_.upsert(taxLines, sharedContext);
779
+ const result = await this.orderShippingMethodTaxLineService_.upsert(taxLines, sharedContext);
611
780
  return await this.baseRepository_.serialize(result, {
612
781
  populate: true,
613
782
  });
614
783
  }
784
+ async createReturns(data, sharedContext) {
785
+ const created = await this.createOrderRelatedEntity_(data, this.returnService_, sharedContext);
786
+ return await this.baseRepository_.serialize(!Array.isArray(data) ? created[0] : created, {
787
+ populate: true,
788
+ });
789
+ }
790
+ async createOrderClaims(data, sharedContext) {
791
+ const created = await this.createOrderRelatedEntity_(data, this.orderClaimService_, sharedContext);
792
+ return await this.baseRepository_.serialize(!Array.isArray(data) ? created[0] : created, {
793
+ populate: true,
794
+ });
795
+ }
796
+ async createOrderExchanges(data, sharedContext) {
797
+ const created = await this.createOrderRelatedEntity_(data, this.orderExchangeService_, sharedContext);
798
+ return await this.baseRepository_.serialize(!Array.isArray(data) ? created[0] : created, {
799
+ populate: true,
800
+ });
801
+ }
802
+ async createOrderRelatedEntity_(data, service, sharedContext) {
803
+ const data_ = Array.isArray(data) ? data : [data];
804
+ const inputDataMap = data_.reduce((acc, curr) => {
805
+ acc[curr.order_id] = curr;
806
+ return acc;
807
+ }, {});
808
+ const orderIds = data_.map((d) => d.order_id);
809
+ const orders = await this.orderService_.list({ id: orderIds }, { select: ["id", "version"] }, sharedContext);
810
+ if (orders.length !== orderIds.length) {
811
+ const foundOrders = orders.map((o) => o.id);
812
+ const missing = orderIds.filter((id) => !foundOrders.includes(id));
813
+ throw new utils_1.MedusaError(utils_1.MedusaError.Types.INVALID_DATA, `Order could not be found: ${missing.join(", ")}`);
814
+ }
815
+ for (const order of orders) {
816
+ inputDataMap[order.id].order_version = order.version;
817
+ }
818
+ return await service.create(data_, sharedContext);
819
+ }
615
820
  async createOrderChange(data, sharedContext) {
616
821
  const changes = await this.createOrderChange_(data, sharedContext);
617
822
  return await this.baseRepository_.serialize(Array.isArray(data) ? changes : changes[0], {
@@ -622,21 +827,26 @@ class OrderModuleService extends utils_1.ModulesSdkUtils.abstractModuleServiceFa
622
827
  const dataArr = Array.isArray(data) ? data : [data];
623
828
  const orderIds = [];
624
829
  const dataMap = {};
830
+ const orderChanges = await this.listOrderChanges({
831
+ order_id: dataArr.map((data) => data.order_id),
832
+ status: [utils_1.OrderChangeStatus.PENDING, utils_1.OrderChangeStatus.REQUESTED],
833
+ }, {}, sharedContext);
834
+ const orderChangesMap = new Map(orderChanges.map((item) => [item.order_id, item]));
625
835
  for (const change of dataArr) {
626
836
  orderIds.push(change.order_id);
627
837
  dataMap[change.order_id] = change;
628
838
  }
629
- const orders = await this.list({
630
- id: orderIds,
631
- }, {
632
- select: ["id", "version"],
633
- }, sharedContext);
839
+ const orders = await this.orderService_.list({ id: orderIds }, { select: ["id", "version"] }, sharedContext);
634
840
  if (orders.length !== orderIds.length) {
635
841
  const foundOrders = orders.map((o) => o.id);
636
842
  const missing = orderIds.filter((id) => !foundOrders.includes(id));
637
843
  throw new utils_1.MedusaError(utils_1.MedusaError.Types.INVALID_DATA, `Order could not be found: ${missing.join(", ")}`);
638
844
  }
639
845
  const input = orders.map((order) => {
846
+ const existingOrderChange = orderChangesMap.get(order.id);
847
+ if (existingOrderChange) {
848
+ throw new utils_1.MedusaError(utils_1.MedusaError.Types.INVALID_DATA, `Order (${order.id}) already has an existing active order change`);
849
+ }
640
850
  return {
641
851
  ...dataMap[order.id],
642
852
  version: order.version + 1,
@@ -644,6 +854,83 @@ class OrderModuleService extends utils_1.ModulesSdkUtils.abstractModuleServiceFa
644
854
  });
645
855
  return await this.orderChangeService_.create(input, sharedContext);
646
856
  }
857
+ async previewOrderChange(orderId, sharedContext) {
858
+ const order = await this.retrieveOrder(orderId, {
859
+ select: ["id", "version", "items.detail", "summary", "total"],
860
+ relations: ["transactions", "items", "shipping_methods"],
861
+ }, sharedContext);
862
+ if (!order.order_change) {
863
+ return order;
864
+ }
865
+ const orderChange = await super.retrieveOrderChange(order.order_change.id, { relations: ["actions"] }, sharedContext);
866
+ const { itemsToUpsert, shippingMethodsToUpsert, calculatedOrders } = (0, utils_2.applyChangesToOrder)([order], { [order.id]: orderChange.actions }, { addActionReferenceToObject: true });
867
+ const calculated = calculatedOrders[order.id];
868
+ const addedItems = {};
869
+ const addedShippingMethods = {};
870
+ for (const item of calculated.order.items) {
871
+ const isExistingItem = item.id === item.detail?.item_id;
872
+ if (!isExistingItem) {
873
+ addedItems[item.id] = item;
874
+ }
875
+ }
876
+ for (const sm of calculated.order.shipping_methods) {
877
+ if (!(0, utils_1.isDefined)(sm.shipping_option_id)) {
878
+ addedShippingMethods[sm.id] = sm;
879
+ }
880
+ }
881
+ if (Object.keys(addedItems).length > 0) {
882
+ const addedItemDetails = await this.listOrderLineItems({ id: Object.keys(addedItems) }, {
883
+ relations: ["adjustments", "tax_lines"],
884
+ }, sharedContext);
885
+ calculated.order.items.forEach((item, idx) => {
886
+ if (!addedItems[item.id]) {
887
+ return;
888
+ }
889
+ const lineItem = addedItemDetails.find((d) => d.id === item.id);
890
+ const actions = item.actions;
891
+ delete item.actions;
892
+ const newItem = itemsToUpsert.find((d) => d.item_id === item.id);
893
+ calculated.order.items[idx] = {
894
+ ...lineItem,
895
+ actions,
896
+ quantity: newItem.quantity,
897
+ detail: {
898
+ ...newItem,
899
+ ...item,
900
+ },
901
+ };
902
+ });
903
+ }
904
+ if (Object.keys(addedShippingMethods).length > 0) {
905
+ const addedShippingDetails = await this.listOrderShippingMethods({ id: Object.keys(addedShippingMethods) }, {
906
+ relations: ["adjustments", "tax_lines"],
907
+ }, sharedContext);
908
+ calculated.order.shipping_methods.forEach((sm, idx) => {
909
+ if (!addedShippingMethods[sm.id]) {
910
+ return;
911
+ }
912
+ const shippingMethod = addedShippingDetails.find((d) => d.id === sm.id);
913
+ const actions = sm.actions;
914
+ delete sm.actions;
915
+ const newItem = shippingMethodsToUpsert.find((d) => d.id === sm.id);
916
+ sm.shipping_method_id = sm.id;
917
+ delete sm.id;
918
+ calculated.order.shipping_methods[idx] = {
919
+ ...shippingMethod,
920
+ actions,
921
+ detail: {
922
+ ...sm,
923
+ ...newItem,
924
+ },
925
+ };
926
+ });
927
+ }
928
+ const calcOrder = calculated.order;
929
+ (0, utils_1.decorateCartTotals)(calcOrder);
930
+ calcOrder.summary = calculated.summary;
931
+ (0, utils_1.createRawPropertiesFromBigNumber)(calcOrder);
932
+ return calcOrder;
933
+ }
647
934
  async cancelOrderChange(orderChangeIdOrData, sharedContext) {
648
935
  const data = Array.isArray(orderChangeIdOrData)
649
936
  ? orderChangeIdOrData
@@ -678,16 +965,9 @@ class OrderModuleService extends utils_1.ModulesSdkUtils.abstractModuleServiceFa
678
965
  });
679
966
  await this.orderChangeService_.update(updates, sharedContext);
680
967
  const orderChanges = orderChange.map((change) => {
681
- change.actions = change.actions.map((action) => {
682
- return {
683
- ...action,
684
- version: change.version,
685
- order_id: change.order_id,
686
- };
687
- });
688
968
  return change.actions;
689
969
  });
690
- await this.applyOrderChanges_(orderChanges.flat(), sharedContext);
970
+ return await this.applyOrderChanges_(orderChanges.flat(), sharedContext);
691
971
  }
692
972
  async declineOrderChange(orderChangeIdOrData, sharedContext) {
693
973
  const data = Array.isArray(orderChangeIdOrData)
@@ -708,7 +988,7 @@ class OrderModuleService extends utils_1.ModulesSdkUtils.abstractModuleServiceFa
708
988
  }
709
989
  async applyPendingOrderActions(orderId, sharedContext) {
710
990
  const orderIds = Array.isArray(orderId) ? orderId : [orderId];
711
- const orders = await this.list({ id: orderIds }, {
991
+ const orders = await this.orderService_.list({ id: orderIds }, {
712
992
  select: ["id", "version"],
713
993
  }, sharedContext);
714
994
  const changes = await this.orderChangeActionService_.list({
@@ -719,6 +999,9 @@ class OrderModuleService extends utils_1.ModulesSdkUtils.abstractModuleServiceFa
719
999
  select: [
720
1000
  "id",
721
1001
  "order_id",
1002
+ "return_id",
1003
+ "exchange_id",
1004
+ "claim_id",
722
1005
  "ordering",
723
1006
  "version",
724
1007
  "applied",
@@ -734,10 +1017,10 @@ class OrderModuleService extends utils_1.ModulesSdkUtils.abstractModuleServiceFa
734
1017
  ordering: "ASC",
735
1018
  },
736
1019
  }, sharedContext);
737
- await this.applyOrderChanges_(changes, sharedContext);
1020
+ return await this.applyOrderChanges_(changes, sharedContext);
738
1021
  }
739
1022
  async revertLastVersion(orderId, sharedContext) {
740
- const order = await super.retrieve(orderId, {
1023
+ const order = await super.retrieveOrder(orderId, {
741
1024
  select: ["id", "version"],
742
1025
  }, sharedContext);
743
1026
  if (order.version < 2) {
@@ -775,13 +1058,13 @@ class OrderModuleService extends utils_1.ModulesSdkUtils.abstractModuleServiceFa
775
1058
  }, { select: ["id", "version"] }, sharedContext);
776
1059
  const orderItemIds = orderItems.map((summary) => summary.id);
777
1060
  await this.orderItemService_.softDelete(orderItemIds, sharedContext);
778
- // Shipping Methods
779
- const orderShippingMethods = await this.orderShippingMethodService_.list({
1061
+ // Order Shipping
1062
+ const orderShippings = await this.orderShippingService_.list({
780
1063
  order_id: order.id,
781
1064
  version: currentVersion,
782
1065
  }, { select: ["id", "version"] }, sharedContext);
783
- const orderShippingMethodIds = orderShippingMethods.map((summary) => summary.id);
784
- await this.orderShippingMethodService_.softDelete(orderShippingMethodIds, sharedContext);
1066
+ const orderShippingIds = orderShippings.map((sh) => sh.id);
1067
+ await this.orderShippingService_.softDelete(orderShippingIds, sharedContext);
785
1068
  // Order
786
1069
  await this.orderService_.update({
787
1070
  selector: {
@@ -791,10 +1074,58 @@ class OrderModuleService extends utils_1.ModulesSdkUtils.abstractModuleServiceFa
791
1074
  version: order.version - 1,
792
1075
  },
793
1076
  }, sharedContext);
1077
+ // Returns
1078
+ await this.returnService_.delete({
1079
+ order_id: order.id,
1080
+ order_version: currentVersion,
1081
+ }, sharedContext);
1082
+ }
1083
+ async getActiveOrderChange_(orderId, includeActions, sharedContext) {
1084
+ const options = {
1085
+ select: [
1086
+ "id",
1087
+ "change_type",
1088
+ "order_id",
1089
+ "return_id",
1090
+ "claim_id",
1091
+ "exchange_id",
1092
+ "version",
1093
+ "requested_at",
1094
+ "requested_by",
1095
+ "status",
1096
+ "description",
1097
+ "internal_note",
1098
+ ],
1099
+ relations: [],
1100
+ order: {},
1101
+ };
1102
+ if (includeActions) {
1103
+ options.select.push("actions");
1104
+ options.relations.push("actions");
1105
+ options.order = {
1106
+ actions: {
1107
+ ordering: "ASC",
1108
+ },
1109
+ };
1110
+ }
1111
+ const [orderChange] = await this.listOrderChanges({
1112
+ order_id: orderId,
1113
+ status: [utils_1.OrderChangeStatus.PENDING, utils_1.OrderChangeStatus.REQUESTED],
1114
+ }, options, sharedContext);
1115
+ return orderChange;
794
1116
  }
795
1117
  async getAndValidateOrderChange_(orderChangeIds, includeActions, sharedContext) {
1118
+ orderChangeIds = (0, utils_1.deduplicate)(orderChangeIds);
796
1119
  const options = {
797
- select: ["id", "order_id", "version", "status"],
1120
+ select: [
1121
+ "id",
1122
+ "order_id",
1123
+ "return_id",
1124
+ "claim_id",
1125
+ "exchange_id",
1126
+ "version",
1127
+ "status",
1128
+ ],
798
1129
  relations: [],
799
1130
  order: {},
800
1131
  };
@@ -832,9 +1163,8 @@ class OrderModuleService extends utils_1.ModulesSdkUtils.abstractModuleServiceFa
832
1163
  const orderChangeMap = {};
833
1164
  const orderChangeIds = dataArr
834
1165
  .map((data, idx) => {
835
- var _a;
836
1166
  if (data.order_change_id) {
837
- orderChangeMap[_a = data.order_change_id] ?? (orderChangeMap[_a] = []);
1167
+ orderChangeMap[data.order_change_id] ??= [];
838
1168
  orderChangeMap[data.order_change_id].push(dataArr[idx]);
839
1169
  }
840
1170
  return data.order_change_id;
@@ -855,7 +1185,6 @@ class OrderModuleService extends utils_1.ModulesSdkUtils.abstractModuleServiceFa
855
1185
  return Array.isArray(data) ? actions : actions[0];
856
1186
  }
857
1187
  async applyOrderChanges_(changeActions, sharedContext) {
858
- var _a;
859
1188
  const actionsMap = {};
860
1189
  const ordersIds = [];
861
1190
  const usedActions = [];
@@ -864,7 +1193,7 @@ class OrderModuleService extends utils_1.ModulesSdkUtils.abstractModuleServiceFa
864
1193
  continue;
865
1194
  }
866
1195
  ordersIds.push(action.order_id);
867
- actionsMap[_a = action.order_id] ?? (actionsMap[_a] = []);
1196
+ actionsMap[action.order_id] ??= [];
868
1197
  actionsMap[action.order_id].push(action);
869
1198
  usedActions.push({
870
1199
  selector: {
@@ -876,74 +1205,29 @@ class OrderModuleService extends utils_1.ModulesSdkUtils.abstractModuleServiceFa
876
1205
  });
877
1206
  }
878
1207
  if (!ordersIds.length) {
879
- return;
1208
+ return {
1209
+ items: [],
1210
+ shippingMethods: [],
1211
+ };
880
1212
  }
881
- const orders = await this.list({ id: (0, utils_1.deduplicate)(ordersIds) }, {
882
- select: [
883
- "id",
884
- "version",
885
- "items.detail",
1213
+ let orders = await this.listOrders({ id: (0, utils_1.deduplicate)(ordersIds) }, {
1214
+ select: ["id", "version", "items.detail", "summary", "total"],
1215
+ relations: [
886
1216
  "transactions",
887
- "summary",
888
- "total",
1217
+ "items",
1218
+ "items.detail",
1219
+ "shipping_methods",
889
1220
  ],
890
- relations: ["transactions", "items", "items.detail"],
891
- }, sharedContext);
892
- const itemsToUpsert = [];
893
- const shippingMethodsToInsert = [];
894
- const summariesToUpsert = [];
895
- const orderToUpdate = [];
896
- for (const order of orders) {
897
- const calculated = (0, utils_2.calculateOrderChange)({
898
- order: order,
899
- actions: actionsMap[order.id],
900
- transactions: order.transactions,
901
- });
902
- (0, utils_1.createRawPropertiesFromBigNumber)(calculated);
903
- const version = actionsMap[order.id][0].version;
904
- for (const item of calculated.order.items) {
905
- const orderItem = item.detail;
906
- itemsToUpsert.push({
907
- id: orderItem.version === version ? orderItem.id : undefined,
908
- item_id: item.id,
909
- order_id: order.id,
910
- version,
911
- quantity: item.detail.quantity,
912
- fulfilled_quantity: item.detail.fulfilled_quantity,
913
- shipped_quantity: item.detail.shipped_quantity,
914
- return_requested_quantity: item.detail.return_requested_quantity,
915
- return_received_quantity: item.detail.return_received_quantity,
916
- return_dismissed_quantity: item.detail.return_dismissed_quantity,
917
- written_off_quantity: item.detail.written_off_quantity,
918
- metadata: item.detail.metadata,
919
- });
920
- }
921
- const orderSummary = order.summary;
922
- summariesToUpsert.push({
923
- id: orderSummary.version === version ? orderSummary.id : undefined,
924
- order_id: order.id,
925
- version,
926
- totals: calculated.summary,
927
- });
928
- if (version > order.version) {
929
- for (const shippingMethod of order.shipping_methods ?? []) {
930
- const sm = {
931
- ...shippingMethod.detail,
932
- version,
933
- };
934
- delete sm.id;
935
- shippingMethodsToInsert.push(sm);
936
- }
937
- orderToUpdate.push({
938
- selector: {
939
- id: order.id,
940
- },
941
- data: {
942
- version,
943
- },
944
- });
945
- }
946
1221
  }
1222
+ // sharedContext
1223
+ // TODO: investigate issue while using sharedContext in receive return action
1224
+ );
1225
+ orders = (0, utils_2.formatOrder)(orders, {
1226
+ entity: _models_1.Order,
1227
+ });
1228
+ const { itemsToUpsert, shippingMethodsToUpsert, summariesToUpsert, orderToUpdate, } = (0, utils_2.applyChangesToOrder)(orders, actionsMap, {
1229
+ addActionReferenceToObject: true,
1230
+ });
947
1231
  await (0, utils_1.promiseAll)([
948
1232
  orderToUpdate.length
949
1233
  ? this.orderService_.update(orderToUpdate, sharedContext)
@@ -957,391 +1241,847 @@ class OrderModuleService extends utils_1.ModulesSdkUtils.abstractModuleServiceFa
957
1241
  summariesToUpsert.length
958
1242
  ? this.orderSummaryService_.upsert(summariesToUpsert, sharedContext)
959
1243
  : null,
960
- shippingMethodsToInsert.length
961
- ? this.orderShippingMethodService_.create(shippingMethodsToInsert, sharedContext)
1244
+ shippingMethodsToUpsert.length
1245
+ ? this.orderShippingService_.upsert(shippingMethodsToUpsert, sharedContext)
962
1246
  : null,
963
1247
  ]);
1248
+ return {
1249
+ items: itemsToUpsert,
1250
+ shippingMethods: shippingMethodsToUpsert,
1251
+ };
964
1252
  }
965
- async registerFulfillment(data, sharedContext) {
966
- const items = data.items.map((item) => {
967
- return {
968
- action: utils_2.ChangeActionType.FULFILL_ITEM,
969
- internal_note: item.internal_note,
970
- reference: data.reference,
971
- reference_id: data.reference_id,
972
- details: {
973
- reference_id: item.id,
974
- quantity: item.quantity,
975
- metadata: item.metadata,
976
- },
977
- };
1253
+ async addOrderTransactions(transactionData, sharedContext) {
1254
+ const orders = await this.orderService_.list({
1255
+ id: Array.isArray(transactionData)
1256
+ ? transactionData.map((t) => t.order_id)
1257
+ : transactionData.order_id,
1258
+ }, {
1259
+ select: ["id", "version"],
1260
+ }, sharedContext);
1261
+ const data = Array.isArray(transactionData)
1262
+ ? transactionData
1263
+ : [transactionData];
1264
+ for (const order of orders) {
1265
+ const trxs = data.filter((t) => t.order_id === order.id);
1266
+ for (const trx of trxs) {
1267
+ ;
1268
+ trx.version = order.version;
1269
+ }
1270
+ }
1271
+ const created = await this.orderTransactionService_.create(data, sharedContext);
1272
+ await this.updateOrderPaidRefundableAmount_(created, false, sharedContext);
1273
+ return await this.baseRepository_.serialize(!Array.isArray(transactionData) ? created[0] : created, {
1274
+ populate: true,
978
1275
  });
979
- const change = await this.createOrderChange_({
980
- order_id: data.order_id,
981
- description: data.description,
982
- internal_note: data.internal_note,
983
- created_by: data.created_by,
984
- metadata: data.metadata,
985
- actions: items,
1276
+ }
1277
+ // @ts-ignore
1278
+ async deleteOrderTransactions(transactionIds, sharedContext) {
1279
+ const data = Array.isArray(transactionIds)
1280
+ ? transactionIds
1281
+ : [transactionIds];
1282
+ const transactions = await super.listOrderTransactions({
1283
+ id: data,
1284
+ }, {
1285
+ select: ["order_id", "version", "amount"],
986
1286
  }, sharedContext);
987
- await this.confirmOrderChange(change[0].id, sharedContext);
1287
+ await this.orderTransactionService_.delete(data, sharedContext);
1288
+ await this.updateOrderPaidRefundableAmount_(transactions, true, sharedContext);
988
1289
  }
989
- async registerShipment(data, sharedContext) {
990
- let shippingMethodId;
991
- if (!(0, utils_1.isString)(data.shipping_method)) {
992
- const methods = await this.createShippingMethods(data.order_id, data.shipping_method, sharedContext);
993
- shippingMethodId = methods[0].id;
994
- }
995
- else {
996
- shippingMethodId = data.shipping_method;
997
- }
998
- const method = await this.shippingMethodService_.retrieve(shippingMethodId, {
999
- relations: ["tax_lines", "adjustments"],
1290
+ // @ts-ignore
1291
+ async softDeleteOrderTransactions(transactionIds, config, sharedContext) {
1292
+ const transactions = await super.listOrderTransactions({
1293
+ id: transactionIds,
1294
+ }, {
1295
+ select: ["order_id", "amount"],
1000
1296
  }, sharedContext);
1001
- const calculatedAmount = (0, utils_1.getShippingMethodsTotals)([method], {})[method.id];
1002
- const actions = data.items.map((item) => {
1003
- return {
1004
- action: utils_2.ChangeActionType.SHIP_ITEM,
1005
- internal_note: item.internal_note,
1006
- reference: data.reference,
1007
- reference_id: shippingMethodId,
1008
- details: {
1009
- reference_id: item.id,
1010
- quantity: item.quantity,
1011
- metadata: item.metadata,
1012
- },
1013
- };
1297
+ const returned = await super.softDeleteOrderTransactions(transactionIds, config, sharedContext);
1298
+ await this.updateOrderPaidRefundableAmount_(transactions, true, sharedContext);
1299
+ return returned;
1300
+ }
1301
+ // @ts-ignore
1302
+ async restoreOrderTransactions(transactionIds, config, sharedContext) {
1303
+ const transactions = await super.listOrderTransactions({
1304
+ id: transactionIds,
1305
+ }, {
1306
+ select: ["order_id", "amount"],
1307
+ withDeleted: true,
1308
+ }, sharedContext);
1309
+ const returned = await super.restoreOrderTransactions(transactionIds, config, sharedContext);
1310
+ await this.updateOrderPaidRefundableAmount_(transactions, false, sharedContext);
1311
+ return returned;
1312
+ }
1313
+ async updateOrderPaidRefundableAmount_(transactionData, isRemoved, sharedContext) {
1314
+ const summaries = await super.listOrderSummaries({
1315
+ order_id: transactionData.map((trx) => trx.order_id),
1316
+ }, {}, sharedContext);
1317
+ summaries.forEach((summary) => {
1318
+ let trxs = transactionData.filter((trx) => trx.order_id === summary.order_id);
1319
+ if (!trxs.length) {
1320
+ return;
1321
+ }
1322
+ (0, utils_1.transformPropertiesToBigNumber)(trxs);
1323
+ const op = isRemoved ? utils_1.MathBN.sub : utils_1.MathBN.add;
1324
+ for (const trx of trxs) {
1325
+ if (utils_1.MathBN.gt(trx.amount, 0)) {
1326
+ summary.totals.paid_total = new utils_1.BigNumber(op(summary.totals.paid_total, trx.amount));
1327
+ }
1328
+ else {
1329
+ summary.totals.refunded_total = new utils_1.BigNumber(op(summary.totals.refunded_total, utils_1.MathBN.abs(trx.amount)));
1330
+ }
1331
+ summary.totals.transaction_total = new utils_1.BigNumber(op(summary.totals.transaction_total, trx.amount));
1332
+ }
1333
+ summary.totals.pending_difference = new utils_1.BigNumber(utils_1.MathBN.sub(summary.totals.current_order_total, summary.totals.transaction_total));
1014
1334
  });
1015
- if (shippingMethodId) {
1016
- actions.push({
1017
- action: utils_2.ChangeActionType.SHIPPING_ADD,
1018
- reference: data.reference,
1019
- reference_id: shippingMethodId,
1020
- amount: calculatedAmount.total,
1021
- });
1335
+ (0, utils_1.createRawPropertiesFromBigNumber)(summaries);
1336
+ await this.orderSummaryService_.update(summaries, sharedContext);
1337
+ }
1338
+ async archive(orderId, sharedContext) {
1339
+ const orderIds = Array.isArray(orderId) ? orderId : [orderId];
1340
+ const orders = await this.listOrders({
1341
+ id: orderIds,
1342
+ }, {}, sharedContext);
1343
+ const notAllowed = [];
1344
+ for (const order of orders) {
1345
+ if (![
1346
+ utils_1.OrderStatus.COMPLETED,
1347
+ utils_1.OrderStatus.CANCELED,
1348
+ utils_1.OrderStatus.DRAFT,
1349
+ ].includes(order.status)) {
1350
+ notAllowed.push(order.id);
1351
+ }
1352
+ order.status = utils_1.OrderStatus.ARCHIVED;
1022
1353
  }
1023
- const change = await this.createOrderChange_({
1024
- order_id: data.order_id,
1025
- description: data.description,
1026
- internal_note: data.internal_note,
1027
- created_by: data.created_by,
1028
- metadata: data.metadata,
1029
- actions,
1354
+ if (notAllowed.length) {
1355
+ throw new utils_1.MedusaError(utils_1.MedusaError.Types.INVALID_DATA, `Orders ${notAllowed.join(", ")} are completed, canceled, or in draft and cannot be archived`);
1356
+ }
1357
+ await this.orderService_.update({
1358
+ id: orderIds,
1359
+ status: utils_1.OrderStatus.ARCHIVED,
1030
1360
  }, sharedContext);
1031
- await this.confirmOrderChange(change[0].id, sharedContext);
1361
+ return Array.isArray(orderId) ? orders : orders[0];
1032
1362
  }
1033
- async createReturn(data, sharedContext) {
1034
- let shippingMethodId;
1035
- if (!(0, utils_1.isString)(data.shipping_method)) {
1036
- const methods = await this.createShippingMethods(data.order_id, data.shipping_method, sharedContext);
1037
- shippingMethodId = methods[0].id;
1363
+ async completeOrder(orderId, sharedContext) {
1364
+ const orderIds = Array.isArray(orderId) ? orderId : [orderId];
1365
+ const orders = await this.listOrders({
1366
+ id: orderIds,
1367
+ }, {}, sharedContext);
1368
+ const notAllowed = [];
1369
+ for (const order of orders) {
1370
+ if ([utils_1.OrderStatus.CANCELED].includes(order.status)) {
1371
+ notAllowed.push(order.id);
1372
+ }
1373
+ order.status = utils_1.OrderStatus.COMPLETED;
1038
1374
  }
1039
- else {
1040
- shippingMethodId = data.shipping_method;
1375
+ if (notAllowed.length) {
1376
+ throw new utils_1.MedusaError(utils_1.MedusaError.Types.INVALID_DATA, `Orders ${notAllowed.join(", ")} are canceled and cannot be completed`);
1041
1377
  }
1042
- const method = await this.shippingMethodService_.retrieve(shippingMethodId, {
1043
- relations: ["tax_lines", "adjustments"],
1044
- }, sharedContext);
1045
- const calculatedAmount = (0, utils_1.getShippingMethodsTotals)([method], {})[method.id];
1046
- const actions = data.items.map((item) => {
1378
+ await this.orderService_.update(orderIds.map((id) => {
1047
1379
  return {
1048
- action: utils_2.ChangeActionType.RETURN_ITEM,
1049
- internal_note: item.internal_note,
1050
- reference: data.reference,
1051
- reference_id: shippingMethodId,
1052
- details: {
1053
- reference_id: item.id,
1054
- quantity: item.quantity,
1055
- metadata: item.metadata,
1056
- },
1380
+ id,
1381
+ status: utils_1.OrderStatus.COMPLETED,
1057
1382
  };
1058
- });
1059
- if (shippingMethodId) {
1060
- actions.push({
1061
- action: utils_2.ChangeActionType.SHIPPING_ADD,
1062
- reference: data.reference,
1063
- reference_id: shippingMethodId,
1064
- amount: calculatedAmount.total,
1065
- });
1383
+ }), sharedContext);
1384
+ return Array.isArray(orderId) ? orders : orders[0];
1385
+ }
1386
+ async cancel(orderId, sharedContext) {
1387
+ const orderIds = Array.isArray(orderId) ? orderId : [orderId];
1388
+ const orders = await this.listOrders({
1389
+ id: orderIds,
1390
+ }, {}, sharedContext);
1391
+ const canceled_at = new Date();
1392
+ for (const order of orders) {
1393
+ order.status = utils_1.OrderStatus.CANCELED;
1394
+ order.canceled_at = canceled_at;
1066
1395
  }
1067
- const change = await this.createOrderChange_({
1068
- order_id: data.order_id,
1069
- description: data.description,
1070
- internal_note: data.internal_note,
1071
- created_by: data.created_by,
1072
- metadata: data.metadata,
1073
- actions,
1396
+ await this.orderService_.update(orderIds.map((id) => {
1397
+ return {
1398
+ id,
1399
+ status: utils_1.OrderStatus.CANCELED,
1400
+ canceled_at,
1401
+ };
1402
+ }), sharedContext);
1403
+ return Array.isArray(orderId) ? orders : orders[0];
1404
+ }
1405
+ // ------------------- Bundled Order Actions
1406
+ async createReturn(data, sharedContext) {
1407
+ const ret = await BundledActions.createReturn.bind(this)(data, sharedContext);
1408
+ return await this.retrieveReturn(ret.id, {
1409
+ relations: [
1410
+ "items",
1411
+ "shipping_methods",
1412
+ "shipping_methods.tax_lines",
1413
+ "shipping_methods.adjustments",
1414
+ ],
1074
1415
  }, sharedContext);
1075
- await this.confirmOrderChange(change[0].id, sharedContext);
1076
1416
  }
1077
- }
1078
- exports.default = OrderModuleService;
1079
- __decorate([
1080
- (0, utils_1.InjectManager)("baseRepository_"),
1081
- __param(1, (0, utils_1.MedusaContext)()),
1082
- __metadata("design:type", Function),
1083
- __metadata("design:paramtypes", [Object, Object]),
1084
- __metadata("design:returntype", Promise)
1085
- ], OrderModuleService.prototype, "create", null);
1086
- __decorate([
1087
- (0, utils_1.InjectTransactionManager)("baseRepository_"),
1088
- __param(1, (0, utils_1.MedusaContext)()),
1089
- __metadata("design:type", Function),
1090
- __metadata("design:paramtypes", [Array, Object]),
1091
- __metadata("design:returntype", Promise)
1092
- ], OrderModuleService.prototype, "create_", null);
1093
- __decorate([
1094
- (0, utils_1.InjectManager)("baseRepository_"),
1095
- __param(2, (0, utils_1.MedusaContext)()),
1096
- __metadata("design:type", Function),
1097
- __metadata("design:paramtypes", [Object, Object, Object]),
1098
- __metadata("design:returntype", Promise)
1099
- ], OrderModuleService.prototype, "update", null);
1100
- __decorate([
1101
- (0, utils_1.InjectTransactionManager)("baseRepository_"),
1102
- __param(2, (0, utils_1.MedusaContext)()),
1103
- __metadata("design:type", Function),
1104
- __metadata("design:paramtypes", [Object, Object, Object]),
1105
- __metadata("design:returntype", Promise)
1106
- ], OrderModuleService.prototype, "update_", null);
1107
- __decorate([
1108
- (0, utils_1.InjectManager)("baseRepository_"),
1109
- __param(2, (0, utils_1.MedusaContext)()),
1110
- __metadata("design:type", Function),
1111
- __metadata("design:paramtypes", [Object, Object, Object]),
1112
- __metadata("design:returntype", Promise)
1113
- ], OrderModuleService.prototype, "createLineItems", null);
1417
+ async receiveReturn(data, sharedContext) {
1418
+ const ret = await this.receiveReturn_(data, sharedContext);
1419
+ return await this.retrieveReturn(ret.id, {
1420
+ relations: [
1421
+ "items",
1422
+ "shipping_methods",
1423
+ "shipping_methods.tax_lines",
1424
+ "shipping_methods.adjustments",
1425
+ ],
1426
+ });
1427
+ }
1428
+ async receiveReturn_(data, sharedContext) {
1429
+ return await BundledActions.receiveReturn.bind(this)(data, sharedContext);
1430
+ }
1431
+ async cancelReturn(data, sharedContext) {
1432
+ const ret = await this.cancelReturn_(data, sharedContext);
1433
+ return await this.retrieveReturn(ret.id, {
1434
+ relations: [
1435
+ "items",
1436
+ "shipping_methods",
1437
+ "shipping_methods.tax_lines",
1438
+ "shipping_methods.adjustments",
1439
+ ],
1440
+ });
1441
+ }
1442
+ async cancelReturn_(data, sharedContext) {
1443
+ return await BundledActions.cancelReturn.bind(this)(data, sharedContext);
1444
+ }
1445
+ async createClaim(data, sharedContext) {
1446
+ const ret = await this.createClaim_(data, sharedContext);
1447
+ const claim = await this.retrieveOrderClaim(ret.id, {
1448
+ relations: [
1449
+ "additional_items",
1450
+ "additional_items.item",
1451
+ "claim_items",
1452
+ "claim_items.item",
1453
+ "return",
1454
+ "return.items",
1455
+ "shipping_methods",
1456
+ "shipping_methods.tax_lines",
1457
+ "shipping_methods.adjustments",
1458
+ "transactions",
1459
+ ],
1460
+ }, sharedContext);
1461
+ return await this.baseRepository_.serialize(claim, {
1462
+ populate: true,
1463
+ });
1464
+ }
1465
+ async createClaim_(data, sharedContext) {
1466
+ return await BundledActions.createClaim.bind(this)(data, sharedContext);
1467
+ }
1468
+ async cancelClaim(data, sharedContext) {
1469
+ const ret = await this.cancelClaim_(data, sharedContext);
1470
+ return await this.retrieveOrderClaim(ret.id, {
1471
+ relations: ["additional_items", "claim_items", "return", "return.items"],
1472
+ });
1473
+ }
1474
+ async cancelClaim_(data, sharedContext) {
1475
+ return await BundledActions.cancelClaim.bind(this)(data, sharedContext);
1476
+ }
1477
+ async createExchange(data, sharedContext) {
1478
+ const ret = await this.createExchange_(data, sharedContext);
1479
+ const claim = await this.retrieveOrderExchange(ret.id, {
1480
+ relations: [
1481
+ "additional_items",
1482
+ "additional_items.item",
1483
+ "return",
1484
+ "return.items",
1485
+ "shipping_methods",
1486
+ "shipping_methods.tax_lines",
1487
+ "shipping_methods.adjustments",
1488
+ "transactions",
1489
+ ],
1490
+ }, sharedContext);
1491
+ return await this.baseRepository_.serialize(claim, {
1492
+ populate: true,
1493
+ });
1494
+ }
1495
+ async updateReturnReasons(idOrSelector, data, sharedContext = {}) {
1496
+ let normalizedInput = [];
1497
+ if ((0, utils_1.isString)(idOrSelector)) {
1498
+ // Check if the return reason exists in the first place
1499
+ await this.returnReasonService_.retrieve(idOrSelector, {}, sharedContext);
1500
+ normalizedInput = [{ id: idOrSelector, ...data }];
1501
+ }
1502
+ else {
1503
+ const reasons = await this.returnReasonService_.list(idOrSelector, {}, sharedContext);
1504
+ normalizedInput = reasons.map((reason) => ({
1505
+ id: reason.id,
1506
+ ...data,
1507
+ }));
1508
+ }
1509
+ const reasons = await this.returnReasonService_.update(normalizedInput, sharedContext);
1510
+ const updatedReturnReasons = await this.baseRepository_.serialize(reasons);
1511
+ return (0, utils_1.isString)(idOrSelector)
1512
+ ? updatedReturnReasons[0]
1513
+ : updatedReturnReasons;
1514
+ }
1515
+ async createExchange_(data, sharedContext) {
1516
+ return await BundledActions.createExchange.bind(this)(data, sharedContext);
1517
+ }
1518
+ async cancelExchange(data, sharedContext) {
1519
+ const ret = await this.cancelExchange_(data, sharedContext);
1520
+ return await this.retrieveOrderExchange(ret.id, {
1521
+ relations: ["additional_items", "return", "return.items"],
1522
+ });
1523
+ }
1524
+ async cancelExchange_(data, sharedContext) {
1525
+ return await BundledActions.cancelExchange.bind(this)(data, sharedContext);
1526
+ }
1527
+ async registerFulfillment(data, sharedContext) {
1528
+ return await BundledActions.registerFulfillment.bind(this)(data, sharedContext);
1529
+ }
1530
+ async cancelFulfillment(data, sharedContext) {
1531
+ return await BundledActions.cancelFulfillment.bind(this)(data, sharedContext);
1532
+ }
1533
+ async registerShipment(data, sharedContext) {
1534
+ return await BundledActions.registerShipment.bind(this)(data, sharedContext);
1535
+ }
1536
+ async registerDelivery(data, sharedContext) {
1537
+ return await BundledActions.registerDelivery.bind(this)(data, sharedContext);
1538
+ }
1539
+ }
1540
+ exports.default = OrderModuleService;
1114
1541
  __decorate([
1115
- (0, utils_1.InjectTransactionManager)("baseRepository_"),
1116
1542
  __param(2, (0, utils_1.MedusaContext)()),
1117
1543
  __metadata("design:type", Function),
1118
- __metadata("design:paramtypes", [String, Array, Object]),
1544
+ __metadata("design:paramtypes", [String, Object, Object]),
1119
1545
  __metadata("design:returntype", Promise)
1120
- ], OrderModuleService.prototype, "createLineItems_", null);
1546
+ ], OrderModuleService.prototype, "retrieveOrder", null);
1121
1547
  __decorate([
1122
- (0, utils_1.InjectTransactionManager)("baseRepository_"),
1123
- __param(1, (0, utils_1.MedusaContext)()),
1548
+ __param(2, (0, utils_1.MedusaContext)()),
1124
1549
  __metadata("design:type", Function),
1125
- __metadata("design:paramtypes", [Array, Object]),
1550
+ __metadata("design:paramtypes", [Object, Object, Object]),
1126
1551
  __metadata("design:returntype", Promise)
1127
- ], OrderModuleService.prototype, "createLineItemsBulk_", null);
1552
+ ], OrderModuleService.prototype, "listOrders", null);
1128
1553
  __decorate([
1129
- (0, utils_1.InjectManager)("baseRepository_"),
1130
1554
  __param(2, (0, utils_1.MedusaContext)()),
1131
1555
  __metadata("design:type", Function),
1132
1556
  __metadata("design:paramtypes", [Object, Object, Object]),
1133
1557
  __metadata("design:returntype", Promise)
1134
- ], OrderModuleService.prototype, "updateLineItems", null);
1558
+ ], OrderModuleService.prototype, "listAndCountOrders", null);
1135
1559
  __decorate([
1136
- (0, utils_1.InjectTransactionManager)("baseRepository_"),
1137
1560
  __param(2, (0, utils_1.MedusaContext)()),
1138
1561
  __metadata("design:type", Function),
1139
1562
  __metadata("design:paramtypes", [String, Object, Object]),
1140
1563
  __metadata("design:returntype", Promise)
1141
- ], OrderModuleService.prototype, "updateLineItem_", null);
1564
+ ], OrderModuleService.prototype, "retrieveReturn", null);
1142
1565
  __decorate([
1143
- (0, utils_1.InjectTransactionManager)("baseRepository_"),
1144
- __param(1, (0, utils_1.MedusaContext)()),
1566
+ __param(2, (0, utils_1.MedusaContext)()),
1145
1567
  __metadata("design:type", Function),
1146
- __metadata("design:paramtypes", [Array, Object]),
1568
+ __metadata("design:paramtypes", [Object, Object, Object]),
1147
1569
  __metadata("design:returntype", Promise)
1148
- ], OrderModuleService.prototype, "updateLineItemsWithSelector_", null);
1570
+ ], OrderModuleService.prototype, "listReturns", null);
1149
1571
  __decorate([
1150
- (0, utils_1.InjectManager)("baseRepository_"),
1151
1572
  __param(2, (0, utils_1.MedusaContext)()),
1152
1573
  __metadata("design:type", Function),
1153
1574
  __metadata("design:paramtypes", [Object, Object, Object]),
1154
1575
  __metadata("design:returntype", Promise)
1155
- ], OrderModuleService.prototype, "updateOrderItem", null);
1576
+ ], OrderModuleService.prototype, "listAndCountReturns", null);
1156
1577
  __decorate([
1157
- (0, utils_1.InjectTransactionManager)("baseRepository_"),
1158
1578
  __param(2, (0, utils_1.MedusaContext)()),
1159
1579
  __metadata("design:type", Function),
1160
1580
  __metadata("design:paramtypes", [String, Object, Object]),
1161
1581
  __metadata("design:returntype", Promise)
1162
- ], OrderModuleService.prototype, "updateOrderItem_", null);
1582
+ ], OrderModuleService.prototype, "retrieveOrderClaim", null);
1163
1583
  __decorate([
1164
- (0, utils_1.InjectTransactionManager)("baseRepository_"),
1165
- __param(1, (0, utils_1.MedusaContext)()),
1584
+ __param(2, (0, utils_1.MedusaContext)()),
1166
1585
  __metadata("design:type", Function),
1167
- __metadata("design:paramtypes", [Array, Object]),
1586
+ __metadata("design:paramtypes", [Object, Object, Object]),
1168
1587
  __metadata("design:returntype", Promise)
1169
- ], OrderModuleService.prototype, "updateOrderItemWithSelector_", null);
1588
+ ], OrderModuleService.prototype, "listOrderClaims", null);
1589
+ __decorate([
1590
+ __param(2, (0, utils_1.MedusaContext)()),
1591
+ __metadata("design:type", Function),
1592
+ __metadata("design:paramtypes", [Object, Object, Object]),
1593
+ __metadata("design:returntype", Promise)
1594
+ ], OrderModuleService.prototype, "listAndCountOrderClaims", null);
1595
+ __decorate([
1596
+ __param(2, (0, utils_1.MedusaContext)()),
1597
+ __metadata("design:type", Function),
1598
+ __metadata("design:paramtypes", [String, Object, Object]),
1599
+ __metadata("design:returntype", Promise)
1600
+ ], OrderModuleService.prototype, "retrieveOrderExchange", null);
1601
+ __decorate([
1602
+ __param(2, (0, utils_1.MedusaContext)()),
1603
+ __metadata("design:type", Function),
1604
+ __metadata("design:paramtypes", [Object, Object, Object]),
1605
+ __metadata("design:returntype", Promise)
1606
+ ], OrderModuleService.prototype, "listOrderExchanges", null);
1607
+ __decorate([
1608
+ __param(2, (0, utils_1.MedusaContext)()),
1609
+ __metadata("design:type", Function),
1610
+ __metadata("design:paramtypes", [Object, Object, Object]),
1611
+ __metadata("design:returntype", Promise)
1612
+ ], OrderModuleService.prototype, "listAndCountOrderExchanges", null);
1170
1613
  __decorate([
1171
- (0, utils_1.InjectManager)("baseRepository_"),
1614
+ (0, utils_1.InjectManager)(),
1172
1615
  __param(1, (0, utils_1.MedusaContext)()),
1173
1616
  __metadata("design:type", Function),
1174
1617
  __metadata("design:paramtypes", [Object, Object]),
1175
1618
  __metadata("design:returntype", Promise)
1176
- ], OrderModuleService.prototype, "createAddresses", null);
1619
+ ], OrderModuleService.prototype, "createOrders", null);
1177
1620
  __decorate([
1178
- (0, utils_1.InjectTransactionManager)("baseRepository_"),
1621
+ (0, utils_1.InjectTransactionManager)(),
1179
1622
  __param(1, (0, utils_1.MedusaContext)()),
1180
1623
  __metadata("design:type", Function),
1181
1624
  __metadata("design:paramtypes", [Array, Object]),
1182
1625
  __metadata("design:returntype", Promise)
1183
- ], OrderModuleService.prototype, "createAddresses_", null);
1626
+ ], OrderModuleService.prototype, "createOrders_", null);
1184
1627
  __decorate([
1185
- (0, utils_1.InjectManager)("baseRepository_"),
1628
+ (0, utils_1.InjectManager)(),
1629
+ __param(2, (0, utils_1.MedusaContext)()),
1630
+ __metadata("design:type", Function),
1631
+ __metadata("design:paramtypes", [Object, Object, Object]),
1632
+ __metadata("design:returntype", Promise)
1633
+ ], OrderModuleService.prototype, "updateOrders", null);
1634
+ __decorate([
1635
+ (0, utils_1.InjectTransactionManager)(),
1636
+ __param(2, (0, utils_1.MedusaContext)()),
1637
+ __metadata("design:type", Function),
1638
+ __metadata("design:paramtypes", [Object, Object, Object]),
1639
+ __metadata("design:returntype", Promise)
1640
+ ], OrderModuleService.prototype, "updateOrders_", null);
1641
+ __decorate([
1642
+ (0, utils_1.InjectManager)(),
1643
+ __param(2, (0, utils_1.MedusaContext)()),
1644
+ __metadata("design:type", Function),
1645
+ __metadata("design:paramtypes", [Object, Object, Object]),
1646
+ __metadata("design:returntype", Promise)
1647
+ ], OrderModuleService.prototype, "createOrderLineItems", null);
1648
+ __decorate([
1649
+ (0, utils_1.InjectTransactionManager)(),
1650
+ __param(2, (0, utils_1.MedusaContext)()),
1651
+ __metadata("design:type", Function),
1652
+ __metadata("design:paramtypes", [String, Array, Object]),
1653
+ __metadata("design:returntype", Promise)
1654
+ ], OrderModuleService.prototype, "createOrderLineItems_", null);
1655
+ __decorate([
1656
+ (0, utils_1.InjectTransactionManager)(),
1186
1657
  __param(1, (0, utils_1.MedusaContext)()),
1187
1658
  __metadata("design:type", Function),
1188
- __metadata("design:paramtypes", [Object, Object]),
1659
+ __metadata("design:paramtypes", [Array, Object]),
1660
+ __metadata("design:returntype", Promise)
1661
+ ], OrderModuleService.prototype, "createOrderLineItemsBulk_", null);
1662
+ __decorate([
1663
+ (0, utils_1.InjectManager)(),
1664
+ __param(2, (0, utils_1.MedusaContext)()),
1665
+ __metadata("design:type", Function),
1666
+ __metadata("design:paramtypes", [Object, Object, Object]),
1667
+ __metadata("design:returntype", Promise)
1668
+ ], OrderModuleService.prototype, "updateOrderLineItems", null);
1669
+ __decorate([
1670
+ (0, utils_1.InjectTransactionManager)(),
1671
+ __param(2, (0, utils_1.MedusaContext)()),
1672
+ __metadata("design:type", Function),
1673
+ __metadata("design:paramtypes", [String, Object, Object]),
1674
+ __metadata("design:returntype", Promise)
1675
+ ], OrderModuleService.prototype, "updateOrderLineItem_", null);
1676
+ __decorate([
1677
+ (0, utils_1.InjectTransactionManager)(),
1678
+ __param(1, (0, utils_1.MedusaContext)()),
1679
+ __metadata("design:type", Function),
1680
+ __metadata("design:paramtypes", [Array, Object]),
1681
+ __metadata("design:returntype", Promise)
1682
+ ], OrderModuleService.prototype, "updateOrderLineItemsWithSelector_", null);
1683
+ __decorate([
1684
+ (0, utils_1.InjectManager)(),
1685
+ __param(2, (0, utils_1.MedusaContext)()),
1686
+ __metadata("design:type", Function),
1687
+ __metadata("design:paramtypes", [Object, Object, Object]),
1688
+ __metadata("design:returntype", Promise)
1689
+ ], OrderModuleService.prototype, "updateOrderItem", null);
1690
+ __decorate([
1691
+ (0, utils_1.InjectTransactionManager)(),
1692
+ __param(2, (0, utils_1.MedusaContext)()),
1693
+ __metadata("design:type", Function),
1694
+ __metadata("design:paramtypes", [String, Object, Object]),
1189
1695
  __metadata("design:returntype", Promise)
1190
- ], OrderModuleService.prototype, "updateAddresses", null);
1696
+ ], OrderModuleService.prototype, "updateOrderItem_", null);
1191
1697
  __decorate([
1192
- (0, utils_1.InjectTransactionManager)("baseRepository_"),
1698
+ (0, utils_1.InjectTransactionManager)(),
1193
1699
  __param(1, (0, utils_1.MedusaContext)()),
1194
1700
  __metadata("design:type", Function),
1195
1701
  __metadata("design:paramtypes", [Array, Object]),
1196
1702
  __metadata("design:returntype", Promise)
1197
- ], OrderModuleService.prototype, "updateAddresses_", null);
1703
+ ], OrderModuleService.prototype, "updateOrderItemWithSelector_", null);
1198
1704
  __decorate([
1199
- (0, utils_1.InjectManager)("baseRepository_"),
1705
+ (0, utils_1.InjectManager)(),
1200
1706
  __param(2, (0, utils_1.MedusaContext)()),
1201
1707
  __metadata("design:type", Function),
1202
1708
  __metadata("design:paramtypes", [Object, Array, Object]),
1203
1709
  __metadata("design:returntype", Promise)
1204
- ], OrderModuleService.prototype, "createShippingMethods", null);
1710
+ ], OrderModuleService.prototype, "createOrderShippingMethods", null);
1205
1711
  __decorate([
1206
- (0, utils_1.InjectTransactionManager)("baseRepository_"),
1712
+ (0, utils_1.InjectTransactionManager)(),
1207
1713
  __param(2, (0, utils_1.MedusaContext)()),
1208
1714
  __metadata("design:type", Function),
1209
1715
  __metadata("design:paramtypes", [String, Array, Object]),
1210
1716
  __metadata("design:returntype", Promise)
1211
- ], OrderModuleService.prototype, "createShippingMethods_", null);
1717
+ ], OrderModuleService.prototype, "createOrderShippingMethods_", null);
1212
1718
  __decorate([
1213
- (0, utils_1.InjectTransactionManager)("baseRepository_"),
1719
+ (0, utils_1.InjectTransactionManager)(),
1214
1720
  __param(1, (0, utils_1.MedusaContext)()),
1215
1721
  __metadata("design:type", Function),
1216
1722
  __metadata("design:paramtypes", [Array, Object]),
1217
1723
  __metadata("design:returntype", Promise)
1218
- ], OrderModuleService.prototype, "createShippingMethodsBulk_", null);
1724
+ ], OrderModuleService.prototype, "createOrderShippingMethodsBulk_", null);
1725
+ __decorate([
1726
+ (0, utils_1.InjectManager)()
1727
+ // @ts-ignore
1728
+ ,
1729
+ __param(2, (0, utils_1.MedusaContext)()),
1730
+ __metadata("design:type", Function),
1731
+ __metadata("design:paramtypes", [Object, Object, Object]),
1732
+ __metadata("design:returntype", Promise)
1733
+ ], OrderModuleService.prototype, "softDeleteOrderShippingMethods", null);
1734
+ __decorate([
1735
+ (0, utils_1.InjectManager)()
1736
+ // @ts-ignore
1737
+ ,
1738
+ __param(2, (0, utils_1.MedusaContext)()),
1739
+ __metadata("design:type", Function),
1740
+ __metadata("design:paramtypes", [Object, Object, Object]),
1741
+ __metadata("design:returntype", Promise)
1742
+ ], OrderModuleService.prototype, "restoreOrderShippingMethods", null);
1219
1743
  __decorate([
1220
- (0, utils_1.InjectTransactionManager)("baseRepository_"),
1744
+ (0, utils_1.InjectTransactionManager)(),
1221
1745
  __param(2, (0, utils_1.MedusaContext)()),
1222
1746
  __metadata("design:type", Function),
1223
1747
  __metadata("design:paramtypes", [Object, Array, Object]),
1224
1748
  __metadata("design:returntype", Promise)
1225
- ], OrderModuleService.prototype, "createLineItemAdjustments", null);
1749
+ ], OrderModuleService.prototype, "createOrderLineItemAdjustments", null);
1226
1750
  __decorate([
1227
- (0, utils_1.InjectTransactionManager)("baseRepository_"),
1751
+ (0, utils_1.InjectTransactionManager)(),
1228
1752
  __param(2, (0, utils_1.MedusaContext)()),
1229
1753
  __metadata("design:type", Function),
1230
1754
  __metadata("design:paramtypes", [String, Array, Object]),
1231
1755
  __metadata("design:returntype", Promise)
1232
- ], OrderModuleService.prototype, "setLineItemAdjustments", null);
1756
+ ], OrderModuleService.prototype, "setOrderLineItemAdjustments", null);
1233
1757
  __decorate([
1234
- (0, utils_1.InjectTransactionManager)("baseRepository_"),
1758
+ (0, utils_1.InjectTransactionManager)(),
1235
1759
  __param(2, (0, utils_1.MedusaContext)()),
1236
1760
  __metadata("design:type", Function),
1237
1761
  __metadata("design:paramtypes", [String, Array, Object]),
1238
1762
  __metadata("design:returntype", Promise)
1239
- ], OrderModuleService.prototype, "setShippingMethodAdjustments", null);
1763
+ ], OrderModuleService.prototype, "setOrderShippingMethodAdjustments", null);
1240
1764
  __decorate([
1241
- (0, utils_1.InjectTransactionManager)("baseRepository_"),
1765
+ (0, utils_1.InjectTransactionManager)(),
1242
1766
  __param(2, (0, utils_1.MedusaContext)()),
1243
1767
  __metadata("design:type", Function),
1244
1768
  __metadata("design:paramtypes", [Object, Array, Object]),
1245
1769
  __metadata("design:returntype", Promise)
1246
- ], OrderModuleService.prototype, "createShippingMethodAdjustments", null);
1770
+ ], OrderModuleService.prototype, "createOrderShippingMethodAdjustments", null);
1247
1771
  __decorate([
1248
- (0, utils_1.InjectTransactionManager)("baseRepository_"),
1772
+ (0, utils_1.InjectTransactionManager)(),
1249
1773
  __param(2, (0, utils_1.MedusaContext)()),
1250
1774
  __metadata("design:type", Function),
1251
1775
  __metadata("design:paramtypes", [Object, Object, Object]),
1252
1776
  __metadata("design:returntype", Promise)
1253
- ], OrderModuleService.prototype, "createLineItemTaxLines", null);
1777
+ ], OrderModuleService.prototype, "createOrderLineItemTaxLines", null);
1254
1778
  __decorate([
1255
- (0, utils_1.InjectTransactionManager)("baseRepository_"),
1779
+ (0, utils_1.InjectTransactionManager)(),
1256
1780
  __param(2, (0, utils_1.MedusaContext)()),
1257
1781
  __metadata("design:type", Function),
1258
1782
  __metadata("design:paramtypes", [String, Array, Object]),
1259
1783
  __metadata("design:returntype", Promise)
1260
- ], OrderModuleService.prototype, "setLineItemTaxLines", null);
1784
+ ], OrderModuleService.prototype, "setOrderLineItemTaxLines", null);
1261
1785
  __decorate([
1262
- (0, utils_1.InjectTransactionManager)("baseRepository_"),
1786
+ (0, utils_1.InjectTransactionManager)(),
1263
1787
  __param(2, (0, utils_1.MedusaContext)()),
1264
1788
  __metadata("design:type", Function),
1265
1789
  __metadata("design:paramtypes", [Object, Object, Object]),
1266
1790
  __metadata("design:returntype", Promise)
1267
- ], OrderModuleService.prototype, "createShippingMethodTaxLines", null);
1791
+ ], OrderModuleService.prototype, "createOrderShippingMethodTaxLines", null);
1268
1792
  __decorate([
1269
- (0, utils_1.InjectTransactionManager)("baseRepository_"),
1793
+ (0, utils_1.InjectTransactionManager)(),
1270
1794
  __param(2, (0, utils_1.MedusaContext)()),
1271
1795
  __metadata("design:type", Function),
1272
1796
  __metadata("design:paramtypes", [String, Array, Object]),
1273
1797
  __metadata("design:returntype", Promise)
1274
- ], OrderModuleService.prototype, "setShippingMethodTaxLines", null);
1798
+ ], OrderModuleService.prototype, "setOrderShippingMethodTaxLines", null);
1799
+ __decorate([
1800
+ (0, utils_1.InjectTransactionManager)(),
1801
+ __param(1, (0, utils_1.MedusaContext)()),
1802
+ __metadata("design:type", Function),
1803
+ __metadata("design:paramtypes", [Object, Object]),
1804
+ __metadata("design:returntype", Promise)
1805
+ ], OrderModuleService.prototype, "createReturns", null);
1806
+ __decorate([
1807
+ (0, utils_1.InjectTransactionManager)(),
1808
+ __param(1, (0, utils_1.MedusaContext)()),
1809
+ __metadata("design:type", Function),
1810
+ __metadata("design:paramtypes", [Object, Object]),
1811
+ __metadata("design:returntype", Promise)
1812
+ ], OrderModuleService.prototype, "createOrderClaims", null);
1275
1813
  __decorate([
1276
- (0, utils_1.InjectManager)("baseRepository_"),
1814
+ (0, utils_1.InjectTransactionManager)(),
1815
+ __param(1, (0, utils_1.MedusaContext)()),
1816
+ __metadata("design:type", Function),
1817
+ __metadata("design:paramtypes", [Object, Object]),
1818
+ __metadata("design:returntype", Promise)
1819
+ ], OrderModuleService.prototype, "createOrderExchanges", null);
1820
+ __decorate([
1821
+ (0, utils_1.InjectTransactionManager)(),
1822
+ __metadata("design:type", Function),
1823
+ __metadata("design:paramtypes", [Object, Object, Object]),
1824
+ __metadata("design:returntype", Promise)
1825
+ ], OrderModuleService.prototype, "createOrderRelatedEntity_", null);
1826
+ __decorate([
1827
+ (0, utils_1.InjectManager)(),
1828
+ __param(1, (0, utils_1.MedusaContext)()),
1277
1829
  __metadata("design:type", Function),
1278
1830
  __metadata("design:paramtypes", [Object, Object]),
1279
1831
  __metadata("design:returntype", Promise)
1280
1832
  ], OrderModuleService.prototype, "createOrderChange", null);
1281
1833
  __decorate([
1282
- (0, utils_1.InjectTransactionManager)("baseRepository_"),
1834
+ (0, utils_1.InjectTransactionManager)(),
1835
+ __param(1, (0, utils_1.MedusaContext)()),
1283
1836
  __metadata("design:type", Function),
1284
1837
  __metadata("design:paramtypes", [Object, Object]),
1285
1838
  __metadata("design:returntype", Promise)
1286
1839
  ], OrderModuleService.prototype, "createOrderChange_", null);
1287
1840
  __decorate([
1288
- (0, utils_1.InjectTransactionManager)("baseRepository_"),
1841
+ (0, utils_1.InjectManager)(),
1842
+ __metadata("design:type", Function),
1843
+ __metadata("design:paramtypes", [String, Object]),
1844
+ __metadata("design:returntype", Promise)
1845
+ ], OrderModuleService.prototype, "previewOrderChange", null);
1846
+ __decorate([
1847
+ (0, utils_1.InjectTransactionManager)(),
1848
+ __param(1, (0, utils_1.MedusaContext)()),
1289
1849
  __metadata("design:type", Function),
1290
1850
  __metadata("design:paramtypes", [Object, Object]),
1291
1851
  __metadata("design:returntype", Promise)
1292
1852
  ], OrderModuleService.prototype, "cancelOrderChange", null);
1293
1853
  __decorate([
1294
- (0, utils_1.InjectTransactionManager)("baseRepository_"),
1854
+ (0, utils_1.InjectManager)(),
1855
+ __param(1, (0, utils_1.MedusaContext)()),
1295
1856
  __metadata("design:type", Function),
1296
1857
  __metadata("design:paramtypes", [Object, Object]),
1297
1858
  __metadata("design:returntype", Promise)
1298
1859
  ], OrderModuleService.prototype, "confirmOrderChange", null);
1299
1860
  __decorate([
1300
- (0, utils_1.InjectTransactionManager)("baseRepository_"),
1861
+ (0, utils_1.InjectTransactionManager)(),
1862
+ __param(1, (0, utils_1.MedusaContext)()),
1301
1863
  __metadata("design:type", Function),
1302
1864
  __metadata("design:paramtypes", [Object, Object]),
1303
1865
  __metadata("design:returntype", Promise)
1304
1866
  ], OrderModuleService.prototype, "declineOrderChange", null);
1305
1867
  __decorate([
1306
- (0, utils_1.InjectManager)("baseRepository_"),
1868
+ (0, utils_1.InjectManager)(),
1869
+ __param(1, (0, utils_1.MedusaContext)()),
1307
1870
  __metadata("design:type", Function),
1308
1871
  __metadata("design:paramtypes", [Object, Object]),
1309
1872
  __metadata("design:returntype", Promise)
1310
1873
  ], OrderModuleService.prototype, "applyPendingOrderActions", null);
1311
1874
  __decorate([
1312
- (0, utils_1.InjectManager)("baseRepository_"),
1875
+ (0, utils_1.InjectManager)(),
1876
+ __param(1, (0, utils_1.MedusaContext)()),
1313
1877
  __metadata("design:type", Function),
1314
1878
  __metadata("design:paramtypes", [String, Object]),
1315
1879
  __metadata("design:returntype", Promise)
1316
1880
  ], OrderModuleService.prototype, "revertLastVersion", null);
1317
1881
  __decorate([
1318
- (0, utils_1.InjectTransactionManager)("baseRepository_"),
1882
+ (0, utils_1.InjectTransactionManager)(),
1319
1883
  __metadata("design:type", Function),
1320
1884
  __metadata("design:paramtypes", [Object, Object]),
1321
1885
  __metadata("design:returntype", Promise)
1322
1886
  ], OrderModuleService.prototype, "revertLastChange_", null);
1323
1887
  __decorate([
1324
- (0, utils_1.InjectTransactionManager)("baseRepository_"),
1888
+ (0, utils_1.InjectTransactionManager)(),
1889
+ __param(1, (0, utils_1.MedusaContext)()),
1325
1890
  __metadata("design:type", Function),
1326
1891
  __metadata("design:paramtypes", [Object, Object]),
1327
1892
  __metadata("design:returntype", Promise)
1328
1893
  ], OrderModuleService.prototype, "addOrderAction", null);
1329
1894
  __decorate([
1330
- (0, utils_1.InjectTransactionManager)("baseRepository_"),
1895
+ (0, utils_1.InjectTransactionManager)(),
1896
+ __metadata("design:type", Function),
1897
+ __metadata("design:paramtypes", [Array, Object]),
1898
+ __metadata("design:returntype", Promise)
1899
+ ], OrderModuleService.prototype, "applyOrderChanges_", null);
1900
+ __decorate([
1901
+ (0, utils_1.InjectManager)(),
1902
+ __param(1, (0, utils_1.MedusaContext)()),
1903
+ __metadata("design:type", Function),
1904
+ __metadata("design:paramtypes", [Object, Object]),
1905
+ __metadata("design:returntype", Promise)
1906
+ ], OrderModuleService.prototype, "addOrderTransactions", null);
1907
+ __decorate([
1908
+ (0, utils_1.InjectManager)()
1909
+ // @ts-ignore
1910
+ ,
1911
+ __param(1, (0, utils_1.MedusaContext)()),
1912
+ __metadata("design:type", Function),
1913
+ __metadata("design:paramtypes", [Object, Object]),
1914
+ __metadata("design:returntype", Promise)
1915
+ ], OrderModuleService.prototype, "deleteOrderTransactions", null);
1916
+ __decorate([
1917
+ (0, utils_1.InjectManager)()
1918
+ // @ts-ignore
1919
+ ,
1920
+ __param(2, (0, utils_1.MedusaContext)()),
1921
+ __metadata("design:type", Function),
1922
+ __metadata("design:paramtypes", [Object, Object, Object]),
1923
+ __metadata("design:returntype", Promise)
1924
+ ], OrderModuleService.prototype, "softDeleteOrderTransactions", null);
1925
+ __decorate([
1926
+ (0, utils_1.InjectManager)()
1927
+ // @ts-ignore
1928
+ ,
1929
+ __param(2, (0, utils_1.MedusaContext)()),
1930
+ __metadata("design:type", Function),
1931
+ __metadata("design:paramtypes", [Object, Object, Object]),
1932
+ __metadata("design:returntype", Promise)
1933
+ ], OrderModuleService.prototype, "restoreOrderTransactions", null);
1934
+ __decorate([
1935
+ (0, utils_1.InjectTransactionManager)(),
1936
+ __metadata("design:type", Function),
1937
+ __metadata("design:paramtypes", [Array, Boolean, Object]),
1938
+ __metadata("design:returntype", Promise)
1939
+ ], OrderModuleService.prototype, "updateOrderPaidRefundableAmount_", null);
1940
+ __decorate([
1941
+ (0, utils_1.InjectTransactionManager)(),
1942
+ __param(1, (0, utils_1.MedusaContext)()),
1943
+ __metadata("design:type", Function),
1944
+ __metadata("design:paramtypes", [Object, Object]),
1945
+ __metadata("design:returntype", Promise)
1946
+ ], OrderModuleService.prototype, "archive", null);
1947
+ __decorate([
1948
+ (0, utils_1.InjectTransactionManager)(),
1949
+ __param(1, (0, utils_1.MedusaContext)()),
1950
+ __metadata("design:type", Function),
1951
+ __metadata("design:paramtypes", [Object, Object]),
1952
+ __metadata("design:returntype", Promise)
1953
+ ], OrderModuleService.prototype, "completeOrder", null);
1954
+ __decorate([
1955
+ (0, utils_1.InjectTransactionManager)(),
1956
+ __param(1, (0, utils_1.MedusaContext)()),
1957
+ __metadata("design:type", Function),
1958
+ __metadata("design:paramtypes", [Object, Object]),
1959
+ __metadata("design:returntype", Promise)
1960
+ ], OrderModuleService.prototype, "cancel", null);
1961
+ __decorate([
1962
+ (0, utils_1.InjectTransactionManager)(),
1963
+ __param(1, (0, utils_1.MedusaContext)()),
1964
+ __metadata("design:type", Function),
1965
+ __metadata("design:paramtypes", [Object, Object]),
1966
+ __metadata("design:returntype", Promise)
1967
+ ], OrderModuleService.prototype, "createReturn", null);
1968
+ __decorate([
1969
+ (0, utils_1.InjectManager)(),
1970
+ __param(1, (0, utils_1.MedusaContext)()),
1971
+ __metadata("design:type", Function),
1972
+ __metadata("design:paramtypes", [Object, Object]),
1973
+ __metadata("design:returntype", Promise)
1974
+ ], OrderModuleService.prototype, "receiveReturn", null);
1975
+ __decorate([
1976
+ (0, utils_1.InjectTransactionManager)(),
1977
+ __param(1, (0, utils_1.MedusaContext)()),
1978
+ __metadata("design:type", Function),
1979
+ __metadata("design:paramtypes", [Object, Object]),
1980
+ __metadata("design:returntype", Promise)
1981
+ ], OrderModuleService.prototype, "receiveReturn_", null);
1982
+ __decorate([
1983
+ (0, utils_1.InjectManager)(),
1984
+ __param(1, (0, utils_1.MedusaContext)()),
1985
+ __metadata("design:type", Function),
1986
+ __metadata("design:paramtypes", [Object, Object]),
1987
+ __metadata("design:returntype", Promise)
1988
+ ], OrderModuleService.prototype, "cancelReturn", null);
1989
+ __decorate([
1990
+ (0, utils_1.InjectTransactionManager)(),
1991
+ __param(1, (0, utils_1.MedusaContext)()),
1992
+ __metadata("design:type", Function),
1993
+ __metadata("design:paramtypes", [Object, Object]),
1994
+ __metadata("design:returntype", Promise)
1995
+ ], OrderModuleService.prototype, "cancelReturn_", null);
1996
+ __decorate([
1997
+ (0, utils_1.InjectManager)(),
1998
+ __param(1, (0, utils_1.MedusaContext)()),
1999
+ __metadata("design:type", Function),
2000
+ __metadata("design:paramtypes", [Object, Object]),
2001
+ __metadata("design:returntype", Promise)
2002
+ ], OrderModuleService.prototype, "createClaim", null);
2003
+ __decorate([
2004
+ (0, utils_1.InjectTransactionManager)(),
2005
+ __param(1, (0, utils_1.MedusaContext)()),
2006
+ __metadata("design:type", Function),
2007
+ __metadata("design:paramtypes", [Object, Object]),
2008
+ __metadata("design:returntype", Promise)
2009
+ ], OrderModuleService.prototype, "createClaim_", null);
2010
+ __decorate([
2011
+ (0, utils_1.InjectManager)(),
2012
+ __param(1, (0, utils_1.MedusaContext)()),
2013
+ __metadata("design:type", Function),
2014
+ __metadata("design:paramtypes", [Object, Object]),
2015
+ __metadata("design:returntype", Promise)
2016
+ ], OrderModuleService.prototype, "cancelClaim", null);
2017
+ __decorate([
2018
+ (0, utils_1.InjectTransactionManager)(),
2019
+ __param(1, (0, utils_1.MedusaContext)()),
2020
+ __metadata("design:type", Function),
2021
+ __metadata("design:paramtypes", [Object, Object]),
2022
+ __metadata("design:returntype", Promise)
2023
+ ], OrderModuleService.prototype, "cancelClaim_", null);
2024
+ __decorate([
2025
+ (0, utils_1.InjectManager)(),
2026
+ __param(1, (0, utils_1.MedusaContext)()),
2027
+ __metadata("design:type", Function),
2028
+ __metadata("design:paramtypes", [Object, Object]),
2029
+ __metadata("design:returntype", Promise)
2030
+ ], OrderModuleService.prototype, "createExchange", null);
2031
+ __decorate([
2032
+ (0, utils_1.InjectManager)(),
2033
+ __param(2, (0, utils_1.MedusaContext)()),
2034
+ __metadata("design:type", Function),
2035
+ __metadata("design:paramtypes", [Object, Object, Object]),
2036
+ __metadata("design:returntype", Promise)
2037
+ ], OrderModuleService.prototype, "updateReturnReasons", null);
2038
+ __decorate([
2039
+ (0, utils_1.InjectTransactionManager)(),
2040
+ __param(1, (0, utils_1.MedusaContext)()),
2041
+ __metadata("design:type", Function),
2042
+ __metadata("design:paramtypes", [Object, Object]),
2043
+ __metadata("design:returntype", Promise)
2044
+ ], OrderModuleService.prototype, "createExchange_", null);
2045
+ __decorate([
2046
+ (0, utils_1.InjectManager)(),
2047
+ __param(1, (0, utils_1.MedusaContext)()),
2048
+ __metadata("design:type", Function),
2049
+ __metadata("design:paramtypes", [Object, Object]),
2050
+ __metadata("design:returntype", Promise)
2051
+ ], OrderModuleService.prototype, "cancelExchange", null);
2052
+ __decorate([
2053
+ (0, utils_1.InjectTransactionManager)(),
2054
+ __param(1, (0, utils_1.MedusaContext)()),
2055
+ __metadata("design:type", Function),
2056
+ __metadata("design:paramtypes", [Object, Object]),
2057
+ __metadata("design:returntype", Promise)
2058
+ ], OrderModuleService.prototype, "cancelExchange_", null);
2059
+ __decorate([
2060
+ (0, utils_1.InjectTransactionManager)(),
2061
+ __param(1, (0, utils_1.MedusaContext)()),
1331
2062
  __metadata("design:type", Function),
1332
2063
  __metadata("design:paramtypes", [Object, Object]),
1333
2064
  __metadata("design:returntype", Promise)
1334
2065
  ], OrderModuleService.prototype, "registerFulfillment", null);
1335
2066
  __decorate([
1336
- (0, utils_1.InjectTransactionManager)("baseRepository_"),
2067
+ (0, utils_1.InjectTransactionManager)(),
2068
+ __param(1, (0, utils_1.MedusaContext)()),
2069
+ __metadata("design:type", Function),
2070
+ __metadata("design:paramtypes", [Object, Object]),
2071
+ __metadata("design:returntype", Promise)
2072
+ ], OrderModuleService.prototype, "cancelFulfillment", null);
2073
+ __decorate([
2074
+ (0, utils_1.InjectTransactionManager)(),
2075
+ __param(1, (0, utils_1.MedusaContext)()),
1337
2076
  __metadata("design:type", Function),
1338
2077
  __metadata("design:paramtypes", [Object, Object]),
1339
2078
  __metadata("design:returntype", Promise)
1340
2079
  ], OrderModuleService.prototype, "registerShipment", null);
1341
2080
  __decorate([
1342
- (0, utils_1.InjectTransactionManager)("baseRepository_"),
2081
+ (0, utils_1.InjectTransactionManager)(),
2082
+ __param(1, (0, utils_1.MedusaContext)()),
1343
2083
  __metadata("design:type", Function),
1344
2084
  __metadata("design:paramtypes", [Object, Object]),
1345
2085
  __metadata("design:returntype", Promise)
1346
- ], OrderModuleService.prototype, "createReturn", null);
2086
+ ], OrderModuleService.prototype, "registerDelivery", null);
1347
2087
  //# sourceMappingURL=order-module-service.js.map