@medusajs/order 0.1.3 → 1.0.0-rc-20241001083650

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 +20 -21
  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
@@ -0,0 +1,71 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.cancelExchange = cancelExchange;
4
+ const utils_1 = require("@medusajs/framework/utils");
5
+ async function createOrderChange(service, data, exchangeOrder, actions, sharedContext) {
6
+ return await service.createOrderChange_({
7
+ order_id: exchangeOrder.order_id,
8
+ exchange_id: exchangeOrder.id,
9
+ reference: "exchange",
10
+ reference_id: exchangeOrder.id,
11
+ description: data.description,
12
+ internal_note: data.internal_note,
13
+ created_by: data.created_by,
14
+ metadata: data.metadata,
15
+ actions,
16
+ }, sharedContext);
17
+ }
18
+ async function cancelExchange(data, sharedContext) {
19
+ const exchangeOrder = (await this.retrieveOrderExchange(data.exchange_id, {
20
+ select: [
21
+ "id",
22
+ "order_id",
23
+ "additional_items.id",
24
+ "additional_items.item_id",
25
+ "additional_items.quantity",
26
+ ],
27
+ relations: ["additional_items", "shipping_methods"],
28
+ }, sharedContext));
29
+ const actions = [];
30
+ exchangeOrder.additional_items.forEach((item) => {
31
+ actions.push({
32
+ action: utils_1.ChangeActionType.ITEM_REMOVE,
33
+ order_id: exchangeOrder.order_id,
34
+ exchange_id: exchangeOrder.id,
35
+ reference: "exchange",
36
+ reference_id: exchangeOrder.id,
37
+ details: {
38
+ order_id: exchangeOrder.order_id,
39
+ reference_id: item.item_id,
40
+ exchange_id: exchangeOrder.id,
41
+ quantity: item.quantity,
42
+ },
43
+ });
44
+ });
45
+ exchangeOrder.shipping_methods?.forEach((shipping) => {
46
+ actions.push({
47
+ action: utils_1.ChangeActionType.SHIPPING_REMOVE,
48
+ order_id: exchangeOrder.order_id,
49
+ exchange_id: exchangeOrder.id,
50
+ reference: "exchange",
51
+ reference_id: shipping.id,
52
+ amount: shipping.raw_amount ?? shipping.amount,
53
+ });
54
+ });
55
+ const [change] = await createOrderChange(this, data, exchangeOrder, actions, sharedContext);
56
+ await (0, utils_1.promiseAll)([
57
+ this.updateOrderExchanges([
58
+ {
59
+ data: {
60
+ canceled_at: new Date(),
61
+ },
62
+ selector: {
63
+ id: exchangeOrder.id,
64
+ },
65
+ },
66
+ ], sharedContext),
67
+ this.confirmOrderChange(change.id, sharedContext),
68
+ ]);
69
+ return exchangeOrder;
70
+ }
71
+ //# sourceMappingURL=cancel-exchange.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cancel-exchange.js","sourceRoot":"","sources":["../../../src/services/actions/cancel-exchange.ts"],"names":[],"mappings":";;AA+BA,wCA2EC;AApGD,qDAAwE;AAExE,KAAK,UAAU,iBAAiB,CAC9B,OAAO,EACP,IAAI,EACJ,aAAa,EACb,OAAO,EACP,aAAa;IAEb,OAAO,MAAM,OAAO,CAAC,kBAAkB,CACrC;QACE,QAAQ,EAAE,aAAa,CAAC,QAAQ;QAChC,WAAW,EAAE,aAAa,CAAC,EAAE;QAC7B,SAAS,EAAE,UAAU;QACrB,YAAY,EAAE,aAAa,CAAC,EAAE;QAC9B,WAAW,EAAE,IAAI,CAAC,WAAW;QAC7B,aAAa,EAAE,IAAI,CAAC,aAAa;QACjC,UAAU,EAAE,IAAI,CAAC,UAAU;QAC3B,QAAQ,EAAE,IAAI,CAAC,QAAQ;QACvB,OAAO;KACR,EACD,aAAa,CACd,CAAA;AACH,CAAC;AAEM,KAAK,UAAU,cAAc,CAElC,IAAuC,EACvC,aAAuB;IAEvB,MAAM,aAAa,GAAG,CAAC,MAAM,IAAI,CAAC,qBAAqB,CACrD,IAAI,CAAC,WAAW,EAChB;QACE,MAAM,EAAE;YACN,IAAI;YACJ,UAAU;YACV,qBAAqB;YACrB,0BAA0B;YAC1B,2BAA2B;SAC5B;QACD,SAAS,EAAE,CAAC,kBAAkB,EAAE,kBAAkB,CAAC;KACpD,EACD,aAAa,CACd,CAAqB,CAAA;IAEtB,MAAM,OAAO,GAAiC,EAAE,CAAA;IAEhD,aAAa,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE;QAC9C,OAAO,CAAC,IAAI,CAAC;YACX,MAAM,EAAE,wBA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
1
+ import { Context, OrderTypes } from "@medusajs/framework/types";
2
+ export declare function cancelFulfillment(this: any, data: OrderTypes.CancelOrderFulfillmentDTO, sharedContext?: Context): Promise<void>;
3
+ //# sourceMappingURL=cancel-fulfillment.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cancel-fulfillment.d.ts","sourceRoot":"","sources":["../../../src/services/actions/cancel-fulfillment.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAA;AAG/D,wBAAsB,iBAAiB,CACrC,IAAI,EAAE,GAAG,EACT,IAAI,EAAE,UAAU,CAAC,yBAAyB,EAC1C,aAAa,CAAC,EAAE,OAAO,GACtB,OAAO,CAAC,IAAI,CAAC,CA8Bf"}
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.cancelFulfillment = cancelFulfillment;
4
+ const utils_1 = require("@medusajs/framework/utils");
5
+ async function cancelFulfillment(data, sharedContext) {
6
+ const items = data.items.map((item) => {
7
+ return {
8
+ action: utils_1.ChangeActionType.CANCEL_ITEM_FULFILLMENT,
9
+ internal_note: item.internal_note,
10
+ reference: data.reference,
11
+ reference_id: data.reference_id,
12
+ claim_id: data.claim_id,
13
+ exchange_id: data.exchange_id,
14
+ details: {
15
+ reference_id: item.id,
16
+ quantity: item.quantity,
17
+ metadata: item.metadata,
18
+ },
19
+ };
20
+ });
21
+ const change = await this.createOrderChange_({
22
+ order_id: data.order_id,
23
+ description: data.description,
24
+ internal_note: data.internal_note,
25
+ created_by: data.created_by,
26
+ metadata: data.metadata,
27
+ actions: items,
28
+ }, sharedContext);
29
+ await this.confirmOrderChange(change[0].id, sharedContext);
30
+ }
31
+ //# sourceMappingURL=cancel-fulfillment.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cancel-fulfillment.js","sourceRoot":"","sources":["../../../src/services/actions/cancel-fulfillment.ts"],"names":[],"mappings":";;AAGA,8CAkCC;AApCD,qDAA4D;AAErD,KAAK,UAAU,iBAAiB,CAErC,IAA0C,EAC1C,aAAuB;IAEvB,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE;QACpC,OAAO;YACL,MAAM,EAAE,wBAAgB,CAAC,uBAAuB;YAChD,aAAa,EAAE,IAAI,CAAC,aAAa;YACjC,SAAS,EAAE,IAAI,CAAC,SAAS;YACzB,YAAY,EAAE,IAAI,CAAC,YAAY;YAC/B,QAAQ,EAAE,IAAI,CAAC,QAAQ;YACvB,WAAW,EAAE,IAAI,CAAC,WAAW;YAC7B,OAAO,EAAE;gBACP,YAAY,EAAE,IAAI,CAAC,EAAE;gBACrB,QAAQ,EAAE,IAAI,CAAC,QAAQ;gBACvB,QAAQ,EAAE,IAAI,CAAC,QAAQ;aACxB;SACF,CAAA;IACH,CAAC,CAAC,CAAA;IAEF,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,kBAAkB,CAC1C;QACE,QAAQ,EAAE,IAAI,CAAC,QAAQ;QACvB,WAAW,EAAE,IAAI,CAAC,WAAW;QAC7B,aAAa,EAAE,IAAI,CAAC,aAAa;QACjC,UAAU,EAAE,IAAI,CAAC,UAAU;QAC3B,QAAQ,EAAE,IAAI,CAAC,QAAQ;QACvB,OAAO,EAAE,KAAK;KACf,EACD,aAAa,CACd,CAAA;IAED,MAAM,IAAI,CAAC,kBAAkB,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,EAAE,EAAE,aAAa,CAAC,CAAA;AAC5D,CAAC"}
@@ -0,0 +1,3 @@
1
+ import { Context, OrderTypes } from "@medusajs/framework/types";
2
+ export declare function cancelReturn(this: any, data: OrderTypes.CancelOrderReturnDTO, sharedContext?: Context): Promise<OrderTypes.ReturnDTO>;
3
+ //# sourceMappingURL=cancel-return.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cancel-return.d.ts","sourceRoot":"","sources":["../../../src/services/actions/cancel-return.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,OAAO,EAEP,UAAU,EAEX,MAAM,2BAA2B,CAAA;AA0BlC,wBAAsB,YAAY,CAChC,IAAI,EAAE,GAAG,EACT,IAAI,EAAE,UAAU,CAAC,oBAAoB,EACrC,aAAa,CAAC,EAAE,OAAO,iCAsExB"}
@@ -0,0 +1,69 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.cancelReturn = cancelReturn;
4
+ const utils_1 = require("@medusajs/framework/utils");
5
+ async function createOrderChange(service, data, returnRef, actions, sharedContext) {
6
+ return await service.createOrderChange_({
7
+ order_id: returnRef.order_id,
8
+ return_id: returnRef.id,
9
+ reference: "return",
10
+ reference_id: returnRef.id,
11
+ description: data.description,
12
+ internal_note: data.internal_note,
13
+ created_by: data.created_by,
14
+ metadata: data.metadata,
15
+ actions,
16
+ }, sharedContext);
17
+ }
18
+ async function cancelReturn(data, sharedContext) {
19
+ const returnOrder = (await this.retrieveReturn(data.return_id, {
20
+ select: [
21
+ "id",
22
+ "order_id",
23
+ "items.item_id",
24
+ "items.quantity",
25
+ "items.received_quantity",
26
+ ],
27
+ relations: ["items", "shipping_methods"],
28
+ }, sharedContext));
29
+ const actions = [];
30
+ returnOrder.items.forEach((item) => {
31
+ actions.push({
32
+ action: utils_1.ChangeActionType.CANCEL_RETURN_ITEM,
33
+ order_id: returnOrder.order_id,
34
+ return_id: returnOrder.id,
35
+ reference: "return",
36
+ reference_id: returnOrder.id,
37
+ details: {
38
+ reference_id: item.item_id,
39
+ quantity: item.quantity,
40
+ },
41
+ });
42
+ });
43
+ returnOrder.shipping_methods?.forEach((shipping) => {
44
+ actions.push({
45
+ action: utils_1.ChangeActionType.SHIPPING_REMOVE,
46
+ order_id: returnOrder.order_id,
47
+ return_id: returnOrder.id,
48
+ reference: "return",
49
+ reference_id: shipping.id,
50
+ amount: shipping.raw_amount ?? shipping.amount,
51
+ });
52
+ });
53
+ const [change] = await createOrderChange(this, data, returnOrder, actions, sharedContext);
54
+ await (0, utils_1.promiseAll)([
55
+ this.updateReturns([
56
+ {
57
+ data: {
58
+ canceled_at: new Date(),
59
+ },
60
+ selector: {
61
+ id: returnOrder.id,
62
+ },
63
+ },
64
+ ], sharedContext),
65
+ this.confirmOrderChange(change.id, sharedContext),
66
+ ]);
67
+ return returnOrder;
68
+ }
69
+ //# sourceMappingURL=cancel-return.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cancel-return.js","sourceRoot":"","sources":["../../../src/services/actions/cancel-return.ts"],"names":[],"mappings":";;AA+BA,oCAyEC;AAlGD,qDAAwE;AAExE,KAAK,UAAU,iBAAiB,CAC9B,OAAO,EACP,IAAI,EACJ,SAAS,EACT,OAAO,EACP,aAAa;IAEb,OAAO,MAAM,OAAO,CAAC,kBAAkB,CACrC;QACE,QAAQ,EAAE,SAAS,CAAC,QAAQ;QAC5B,SAAS,EAAE,SAAS,CAAC,EAAE;QACvB,SAAS,EAAE,QAAQ;QACnB,YAAY,EAAE,SAAS,CAAC,EAAE;QAC1B,WAAW,EAAE,IAAI,CAAC,WAAW;QAC7B,aAAa,EAAE,IAAI,CAAC,aAAa;QACjC,UAAU,EAAE,IAAI,CAAC,UAAU;QAC3B,QAAQ,EAAE,IAAI,CAAC,QAAQ;QACvB,OAAO;KACR,EACD,aAAa,CACd,CAAA;AACH,CAAC;AAEM,KAAK,UAAU,YAAY,CAEhC,IAAqC,EACrC,aAAuB;IAEvB,MAAM,WAAW,GAAG,CAAC,MAAM,IAAI,CAAC,cAAc,CAC5C,IAAI,CAAC,SAAS,EACd;QACE,MAAM,EAAE;YACN,IAAI;YACJ,UAAU;YACV,eAAe;YACf,gBAAgB;YAChB,yBAAyB;SAC1B;QACD,SAAS,EAAE,CAAC,OAAO,EAAE,kBAAkB,CAAC;KACzC,EACD,aAAa,CACd,CAAc,CAAA;IAEf,MAAM,OAAO,GAAiC,EAAE,CAAA;IAEhD,WAAW,CAAC,KAAK,CAAC,OAAO,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,3 @@
1
+ import { Context, OrderTypes } from "@medusajs/framework/types";
2
+ export declare function createClaim(this: any, data: OrderTypes.CreateOrderClaimDTO, sharedContext?: Context): Promise<any>;
3
+ //# sourceMappingURL=create-claim.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create-claim.d.ts","sourceRoot":"","sources":["../../../src/services/actions/create-claim.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,OAAO,EAEP,UAAU,EACX,MAAM,2BAA2B,CAAA;AAsRlC,wBAAsB,WAAW,CAC/B,IAAI,EAAE,GAAG,EACT,IAAI,EAAE,UAAU,CAAC,mBAAmB,EACpC,aAAa,CAAC,EAAE,OAAO,gBA8ExB"}
@@ -0,0 +1,225 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createClaim = createClaim;
4
+ const utils_1 = require("@medusajs/framework/utils");
5
+ const _models_1 = require("../../models");
6
+ function createClaimAndReturnEntities(em, data, order) {
7
+ const claimReference = em.create(_models_1.OrderClaim, {
8
+ order_id: data.order_id,
9
+ order_version: order.version,
10
+ type: data.type,
11
+ no_notification: data.no_notification,
12
+ refund_amount: data.refund_amount ?? null,
13
+ });
14
+ const returnReference = data.type === utils_1.ClaimType.REPLACE
15
+ ? em.create(_models_1.Return, {
16
+ order_id: data.order_id,
17
+ order_version: order.version,
18
+ status: utils_1.ReturnStatus.REQUESTED,
19
+ claim_id: claimReference.id,
20
+ refund_amount: data.refund_amount ?? null,
21
+ })
22
+ : undefined;
23
+ claimReference.return_id = returnReference?.id;
24
+ return { claimReference, returnReference };
25
+ }
26
+ function createReturnItem(em, item, claimReference, returnReference, actions) {
27
+ actions.push({
28
+ action: utils_1.ChangeActionType.RETURN_ITEM,
29
+ reference: "return",
30
+ reference_id: returnReference.id,
31
+ details: {
32
+ reference_id: item.id,
33
+ quantity: item.quantity,
34
+ metadata: item.metadata,
35
+ },
36
+ });
37
+ return em.create(_models_1.ReturnItem, {
38
+ item_id: item.id,
39
+ return_id: returnReference.id,
40
+ quantity: item.quantity,
41
+ note: item.note,
42
+ metadata: item.metadata,
43
+ });
44
+ }
45
+ function createClaimAndReturnItems(em, data, claimReference, returnReference, actions) {
46
+ const returnItems = [];
47
+ const claimItems = data.claim_items?.map((item) => {
48
+ actions.push({
49
+ action: utils_1.ChangeActionType.WRITE_OFF_ITEM,
50
+ reference: "claim",
51
+ reference_id: claimReference.id,
52
+ details: {
53
+ reference_id: item.id,
54
+ quantity: item.quantity,
55
+ metadata: item.metadata,
56
+ },
57
+ });
58
+ returnItems.push(returnReference
59
+ ? createReturnItem(em, item, claimReference, returnReference, actions)
60
+ : undefined);
61
+ return em.create(_models_1.OrderClaimItem, {
62
+ item_id: item.id,
63
+ reason: item.reason,
64
+ quantity: item.quantity,
65
+ note: item.note,
66
+ metadata: item.metadata,
67
+ });
68
+ });
69
+ return [claimItems, returnItems];
70
+ }
71
+ async function processAdditionalItems(em, service, data, order, claimReference, actions, sharedContext) {
72
+ const itemsToAdd = [];
73
+ const additionalNewItems = [];
74
+ const additionalItems = [];
75
+ data.additional_items?.forEach((item) => {
76
+ const hasItem = item.id
77
+ ? order.items.find((o) => o.item.id === item.id)
78
+ : false;
79
+ if (hasItem) {
80
+ actions.push({
81
+ action: utils_1.ChangeActionType.ITEM_ADD,
82
+ claim_id: claimReference.id,
83
+ internal_note: item.internal_note,
84
+ reference: "claim",
85
+ reference_id: claimReference.id,
86
+ details: {
87
+ reference_id: item.id,
88
+ quantity: item.quantity,
89
+ unit_price: item.unit_price ?? hasItem.item.unit_price,
90
+ metadata: item.metadata,
91
+ },
92
+ });
93
+ additionalItems.push(em.create(_models_1.OrderClaimItem, {
94
+ item_id: item.id,
95
+ quantity: item.quantity,
96
+ note: item.note,
97
+ metadata: item.metadata,
98
+ is_additional_item: true,
99
+ }));
100
+ }
101
+ else {
102
+ itemsToAdd.push(item);
103
+ additionalNewItems.push(em.create(_models_1.OrderClaimItem, {
104
+ quantity: item.quantity,
105
+ unit_price: item.unit_price,
106
+ note: item.note,
107
+ metadata: item.metadata,
108
+ is_additional_item: true,
109
+ }));
110
+ }
111
+ });
112
+ const createItems = await service.orderLineItemService_.create(itemsToAdd, sharedContext);
113
+ createItems.forEach((item, index) => {
114
+ const addedItem = itemsToAdd[index];
115
+ additionalNewItems[index].item_id = item.id;
116
+ actions.push({
117
+ action: utils_1.ChangeActionType.ITEM_ADD,
118
+ claim_id: claimReference.id,
119
+ internal_note: addedItem.internal_note,
120
+ reference: "claim",
121
+ reference_id: claimReference.id,
122
+ details: {
123
+ reference_id: item.id,
124
+ claim_id: claimReference.id,
125
+ quantity: addedItem.quantity,
126
+ unit_price: item.unit_price,
127
+ metadata: addedItem.metadata,
128
+ },
129
+ });
130
+ });
131
+ return additionalNewItems.concat(additionalItems);
132
+ }
133
+ async function processShippingMethods(service, data, claimReference, actions, sharedContext) {
134
+ for (const shippingMethod of data.shipping_methods ?? []) {
135
+ let shippingMethodId;
136
+ if (!(0, utils_1.isString)(shippingMethod)) {
137
+ const methods = await service.createOrderShippingMethods([
138
+ {
139
+ ...shippingMethod,
140
+ order_id: data.order_id,
141
+ claim_id: claimReference.id,
142
+ },
143
+ ], sharedContext);
144
+ shippingMethodId = methods[0].id;
145
+ }
146
+ else {
147
+ shippingMethodId = shippingMethod;
148
+ }
149
+ const method = await service.retrieveOrderShippingMethod(shippingMethodId, { relations: ["tax_lines", "adjustments"] }, sharedContext);
150
+ const calculatedAmount = (0, utils_1.getShippingMethodsTotals)([method], {})[method.id];
151
+ actions.push({
152
+ action: utils_1.ChangeActionType.SHIPPING_ADD,
153
+ reference: "order_shipping_method",
154
+ reference_id: shippingMethodId,
155
+ claim_id: claimReference.id,
156
+ amount: calculatedAmount.total,
157
+ });
158
+ }
159
+ }
160
+ async function processReturnShipping(service, data, claimReference, returnReference, actions, sharedContext) {
161
+ if (!returnReference) {
162
+ return;
163
+ }
164
+ if (data.return_shipping) {
165
+ let returnShippingMethodId;
166
+ if (!(0, utils_1.isString)(data.return_shipping)) {
167
+ const methods = await service.createOrderShippingMethods([
168
+ {
169
+ ...data.return_shipping,
170
+ order_id: data.order_id,
171
+ claim_id: claimReference.id,
172
+ return_id: returnReference.id,
173
+ },
174
+ ], sharedContext);
175
+ returnShippingMethodId = methods[0].id;
176
+ }
177
+ else {
178
+ returnShippingMethodId = data.return_shipping;
179
+ }
180
+ const method = await service.retrieveOrderShippingMethod(returnShippingMethodId, { relations: ["tax_lines", "adjustments"] }, sharedContext);
181
+ const calculatedAmount = (0, utils_1.getShippingMethodsTotals)([method], {})[method.id];
182
+ actions.push({
183
+ action: utils_1.ChangeActionType.SHIPPING_ADD,
184
+ reference: "order_shipping_method",
185
+ reference_id: returnShippingMethodId,
186
+ return_id: returnReference.id,
187
+ claim_id: claimReference.id,
188
+ amount: calculatedAmount.total,
189
+ });
190
+ }
191
+ }
192
+ async function createClaim(data, sharedContext) {
193
+ const order = await this.orderService_.retrieve(data.order_id, { relations: ["items"] }, sharedContext);
194
+ const actions = [];
195
+ const em = sharedContext.transactionManager;
196
+ const { claimReference, returnReference } = createClaimAndReturnEntities(em, data, order);
197
+ const [claimItems, returnItems] = createClaimAndReturnItems(em, data, claimReference, returnReference, actions);
198
+ claimReference.claim_items = claimItems;
199
+ if (returnReference) {
200
+ returnReference.items = returnItems;
201
+ }
202
+ claimReference.additional_items = await processAdditionalItems(em, this, data, order, claimReference, actions, sharedContext);
203
+ await processShippingMethods(this, data, claimReference, actions, sharedContext);
204
+ await processReturnShipping(this, data, claimReference, returnReference, actions, sharedContext);
205
+ const change = await this.createOrderChange_({
206
+ order_id: data.order_id,
207
+ claim_id: claimReference.id,
208
+ return_id: returnReference.id,
209
+ change_type: utils_1.OrderChangeType.CLAIM,
210
+ reference: "claim",
211
+ reference_id: claimReference.id,
212
+ description: data.description,
213
+ internal_note: data.internal_note,
214
+ created_by: data.created_by,
215
+ metadata: data.metadata,
216
+ actions,
217
+ }, sharedContext);
218
+ await (0, utils_1.promiseAll)([
219
+ this.createReturns([returnReference], sharedContext),
220
+ this.createOrderClaims([claimReference], sharedContext),
221
+ this.confirmOrderChange(change[0].id, sharedContext),
222
+ ]);
223
+ return claimReference;
224
+ }
225
+ //# sourceMappingURL=create-claim.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create-claim.js","sourceRoot":"","sources":["../../../src/services/actions/create-claim.ts"],"names":[],"mappings":";;AA0RA,kCAiFC;AAtWD,qDAQkC;AAClC,qCAAwE;AAExE,SAAS,4BAA4B,CAAC,EAAE,EAAE,IAAI,EAAE,KAAK;IACnD,MAAM,cAAc,GAAG,EAAE,CAAC,MAAM,CAAC,oBAAU,EAAE;QAC3C,QAAQ,EAAE,IAAI,CAAC,QAAQ;QACvB,aAAa,EAAE,KAAK,CAAC,OAAO;QAC5B,IAAI,EAAE,IAAI,CAAC,IAAiB;QAC5B,eAAe,EAAE,IAAI,CAAC,eAAe;QACrC,aAAa,EAAG,IAAI,CAAC,aAAyB,IAAI,IAAI;KACvD,CAAC,CAAA;IAEF,MAAM,eAAe,GACnB,IAAI,CAAC,IAAI,KAAK,iBAAS,CAAC,OAAO;QAC7B,CAAC,CAAC,EAAE,CAAC,MAAM,CAAC,gBAAM,EAAE;YAChB,QAAQ,EAAE,IAAI,CAAC,QAAQ;YACvB,aAAa,EAAE,KAAK,CAAC,OAAO;YAC5B,MAAM,EAAE,oBAAY,CAAC,SAAS;YAC9B,QAAQ,EAAE,cAAc,CAAC,EAAE;YAC3B,aAAa,EAAG,IAAI,CAAC,aAAyB,IAAI,IAAI;SACvD,CAAC;QACJ,CAAC,CAAC,SAAS,CAAA;IAEf,cAAc,CAAC,SAAS,GAAG,eAAe,EAAE,EAAE,CAAA;IAE9C,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,CAAA;AAC5C,CAAC;AAED,SAAS,gBAAgB,CAAC,EAAE,EAAE,IAAI,EAAE,cAAc,EAAE,eAAe,EAAE,OAAO;IAC1E,OAAO,CAAC,IAAI,CAAC;QACX,MAAM,EAAE,wBAAgB,CAAC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K;QAClC,SAAS,EAAE,OAAO;QAClB,YAAY,EAAE,cAAc,CAAC,EAAE;QAC/B,WAAW,EAAE,IAAI,CAAC,WAAW;QAC7B,aAAa,EAAE,IAAI,CAAC,aAAa;QACjC,UAAU,EAAE,IAAI,CAAC,UAAU;QAC3B,QAAQ,EAAE,IAAI,CAAC,QAAQ;QACvB,OAAO;KACR,EACD,aAAa,CACd,CAAA;IAED,MAAM,IAAA,kBAAU,EAAC;QACf,IAAI,CAAC,aAAa,CAAC,CAAC,eAAe,CAAC,EAAE,aAAa,CAAC;QACpD,IAAI,CAAC,iBAAiB,CAAC,CAAC,cAAc,CAAC,EAAE,aAAa,CAAC;QACvD,IAAI,CAAC,kBAAkB,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,EAAE,EAAE,aAAa,CAAC;KACrD,CAAC,CAAA;IAEF,OAAO,cAAc,CAAA;AACvB,CAAC"}
@@ -0,0 +1,3 @@
1
+ import { Context, OrderTypes } from "@medusajs/framework/types";
2
+ export declare function createExchange(this: any, data: OrderTypes.CreateOrderExchangeDTO, sharedContext?: Context): Promise<any>;
3
+ //# sourceMappingURL=create-exchange.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create-exchange.d.ts","sourceRoot":"","sources":["../../../src/services/actions/create-exchange.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,OAAO,EAEP,UAAU,EACX,MAAM,2BAA2B,CAAA;AAiPlC,wBAAsB,cAAc,CAClC,IAAI,EAAE,GAAG,EACT,IAAI,EAAE,UAAU,CAAC,sBAAsB,EACvC,aAAa,CAAC,EAAE,OAAO,gBAqExB"}
@@ -0,0 +1,191 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createExchange = createExchange;
4
+ const utils_1 = require("@medusajs/framework/utils");
5
+ const _models_1 = require("../../models");
6
+ function createExchangeAndReturnEntities(em, data, order) {
7
+ const exchangeReference = em.create(_models_1.OrderExchange, {
8
+ order_id: data.order_id,
9
+ order_version: order.version,
10
+ no_notification: data.no_notification,
11
+ allow_backorder: data.allow_backorder,
12
+ difference_due: data.difference_due,
13
+ });
14
+ const returnReference = em.create(_models_1.Return, {
15
+ order_id: data.order_id,
16
+ order_version: order.version,
17
+ status: utils_1.ReturnStatus.REQUESTED,
18
+ exchange_id: exchangeReference.id,
19
+ refund_amount: data.refund_amount ?? null,
20
+ });
21
+ exchangeReference.return_id = returnReference.id;
22
+ return { exchangeReference, returnReference };
23
+ }
24
+ function createReturnItems(em, data, exchangeReference, returnReference, actions) {
25
+ return data.return_items?.map((item) => {
26
+ actions.push({
27
+ action: utils_1.ChangeActionType.RETURN_ITEM,
28
+ reference: "return",
29
+ reference_id: returnReference.id,
30
+ details: {
31
+ reference_id: item.id,
32
+ quantity: item.quantity,
33
+ metadata: item.metadata,
34
+ },
35
+ });
36
+ return em.create(_models_1.ReturnItem, {
37
+ item_id: item.id,
38
+ return_id: returnReference.id,
39
+ reason: item.reason,
40
+ quantity: item.quantity,
41
+ note: item.note,
42
+ metadata: item.metadata,
43
+ });
44
+ });
45
+ }
46
+ async function processAdditionalItems(em, service, data, order, exchangeReference, actions, sharedContext) {
47
+ const itemsToAdd = [];
48
+ const additionalNewItems = [];
49
+ const additionalItems = [];
50
+ data.additional_items?.forEach((item) => {
51
+ const hasItem = item.id
52
+ ? order.items.find((o) => o.item.id === item.id)
53
+ : false;
54
+ if (hasItem) {
55
+ actions.push({
56
+ action: utils_1.ChangeActionType.ITEM_ADD,
57
+ exchange_id: exchangeReference.id,
58
+ internal_note: item.internal_note,
59
+ reference: "exchange",
60
+ reference_id: exchangeReference.id,
61
+ details: {
62
+ reference_id: item.id,
63
+ quantity: item.quantity,
64
+ unit_price: item.unit_price ?? hasItem.item.unit_price,
65
+ metadata: item.metadata,
66
+ },
67
+ });
68
+ additionalItems.push(em.create(_models_1.OrderExchangeItem, {
69
+ item_id: item.id,
70
+ quantity: item.quantity,
71
+ note: item.note,
72
+ metadata: item.metadata,
73
+ is_additional_item: true,
74
+ }));
75
+ }
76
+ else {
77
+ itemsToAdd.push(item);
78
+ additionalNewItems.push(em.create(_models_1.OrderExchangeItem, {
79
+ quantity: item.quantity,
80
+ unit_price: item.unit_price,
81
+ note: item.note,
82
+ metadata: item.metadata,
83
+ is_additional_item: true,
84
+ }));
85
+ }
86
+ });
87
+ const createItems = await service.orderLineItemService_.create(itemsToAdd, sharedContext);
88
+ createItems.forEach((item, index) => {
89
+ const addedItem = itemsToAdd[index];
90
+ additionalNewItems[index].item_id = item.id;
91
+ actions.push({
92
+ action: utils_1.ChangeActionType.ITEM_ADD,
93
+ exchange_id: exchangeReference.id,
94
+ internal_note: addedItem.internal_note,
95
+ reference: "exchange",
96
+ reference_id: exchangeReference.id,
97
+ details: {
98
+ reference_id: item.id,
99
+ exchange_id: exchangeReference.id,
100
+ quantity: addedItem.quantity,
101
+ unit_price: item.unit_price,
102
+ metadata: addedItem.metadata,
103
+ },
104
+ });
105
+ });
106
+ return additionalNewItems.concat(additionalItems);
107
+ }
108
+ async function processShippingMethods(service, data, exchangeReference, actions, sharedContext) {
109
+ for (const shippingMethod of data.shipping_methods ?? []) {
110
+ let shippingMethodId;
111
+ if (!(0, utils_1.isString)(shippingMethod)) {
112
+ const methods = await service.createOrderShippingMethods([
113
+ {
114
+ ...shippingMethod,
115
+ order_id: data.order_id,
116
+ exchange_id: exchangeReference.id,
117
+ },
118
+ ], sharedContext);
119
+ shippingMethodId = methods[0].id;
120
+ }
121
+ else {
122
+ shippingMethodId = shippingMethod;
123
+ }
124
+ const method = await service.retrieveOrderShippingMethod(shippingMethodId, { relations: ["tax_lines", "adjustments"] }, sharedContext);
125
+ const calculatedAmount = (0, utils_1.getShippingMethodsTotals)([method], {})[method.id];
126
+ actions.push({
127
+ action: utils_1.ChangeActionType.SHIPPING_ADD,
128
+ reference: "order_shipping_method",
129
+ reference_id: shippingMethodId,
130
+ exchange_id: exchangeReference.id,
131
+ amount: calculatedAmount.total,
132
+ });
133
+ }
134
+ }
135
+ async function processReturnShipping(service, data, exchangeReference, returnReference, actions, sharedContext) {
136
+ let returnShippingMethodId;
137
+ if (!(0, utils_1.isString)(data.return_shipping)) {
138
+ const methods = await service.createOrderShippingMethods([
139
+ {
140
+ ...data.return_shipping,
141
+ order_id: data.order_id,
142
+ exchange_id: exchangeReference.id,
143
+ return_id: returnReference.id,
144
+ },
145
+ ], sharedContext);
146
+ returnShippingMethodId = methods[0].id;
147
+ }
148
+ else {
149
+ returnShippingMethodId = data.return_shipping;
150
+ }
151
+ const method = await service.retrieveOrderShippingMethod(returnShippingMethodId, { relations: ["tax_lines", "adjustments"] }, sharedContext);
152
+ const calculatedAmount = (0, utils_1.getShippingMethodsTotals)([method], {})[method.id];
153
+ actions.push({
154
+ action: utils_1.ChangeActionType.SHIPPING_ADD,
155
+ reference: "order_shipping_method",
156
+ reference_id: returnShippingMethodId,
157
+ return_id: returnReference.id,
158
+ exchange_id: exchangeReference.id,
159
+ amount: calculatedAmount.total,
160
+ });
161
+ }
162
+ async function createExchange(data, sharedContext) {
163
+ const order = await this.orderService_.retrieve(data.order_id, { relations: ["items"] }, sharedContext);
164
+ const actions = [];
165
+ const em = sharedContext.transactionManager;
166
+ const { exchangeReference, returnReference } = createExchangeAndReturnEntities(em, data, order);
167
+ returnReference.items = createReturnItems(em, data, exchangeReference, returnReference, actions);
168
+ exchangeReference.additional_items = await processAdditionalItems(em, this, data, order, exchangeReference, actions, sharedContext);
169
+ await processShippingMethods(this, data, exchangeReference, actions, sharedContext);
170
+ await processReturnShipping(this, data, exchangeReference, returnReference, actions, sharedContext);
171
+ const change = await this.createOrderChange_({
172
+ order_id: data.order_id,
173
+ exchange_id: exchangeReference.id,
174
+ return_id: returnReference.id,
175
+ change_type: utils_1.OrderChangeType.EXCHANGE,
176
+ reference: "exchange",
177
+ reference_id: exchangeReference.id,
178
+ description: data.description,
179
+ internal_note: data.internal_note,
180
+ created_by: data.created_by,
181
+ metadata: data.metadata,
182
+ actions,
183
+ }, sharedContext);
184
+ await (0, utils_1.promiseAll)([
185
+ this.createReturns([returnReference], sharedContext),
186
+ this.createOrderExchanges([exchangeReference], sharedContext),
187
+ this.confirmOrderChange(change[0].id, sharedContext),
188
+ ]);
189
+ return exchangeReference;
190
+ }
191
+ //# sourceMappingURL=create-exchange.js.map