@medusajs/order 0.1.3-snapshot-20240718083016 → 0.1.3-snapshot-20240719080828

Sign up to get free protection for your applications and to get access to all the features.
Files changed (331) 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/migrations/Migration20240219102530.d.ts +1 -0
  6. package/dist/migrations/Migration20240219102530.d.ts.map +1 -0
  7. package/dist/migrations/Migration20240219102530.js +38 -4
  8. package/dist/migrations/Migration20240219102530.js.map +1 -1
  9. package/dist/migrations/Migration20240604100512.d.ts +5 -0
  10. package/dist/migrations/Migration20240604100512.d.ts.map +1 -0
  11. package/dist/migrations/Migration20240604100512.js +364 -0
  12. package/dist/migrations/Migration20240604100512.js.map +1 -0
  13. package/dist/migrations/Migration20240715102100.d.ts +5 -0
  14. package/dist/migrations/Migration20240715102100.d.ts.map +1 -0
  15. package/dist/migrations/Migration20240715102100.js +15 -0
  16. package/dist/migrations/Migration20240715102100.js.map +1 -0
  17. package/dist/migrations/Migration20240715174100.d.ts +5 -0
  18. package/dist/migrations/Migration20240715174100.d.ts.map +1 -0
  19. package/dist/migrations/Migration20240715174100.js +21 -0
  20. package/dist/migrations/Migration20240715174100.js.map +1 -0
  21. package/dist/migrations/Migration20240716081800.d.ts +5 -0
  22. package/dist/migrations/Migration20240716081800.d.ts.map +1 -0
  23. package/dist/migrations/Migration20240716081800.js +67 -0
  24. package/dist/migrations/Migration20240716081800.js.map +1 -0
  25. package/dist/models/address.d.ts +2 -1
  26. package/dist/models/address.d.ts.map +1 -0
  27. package/dist/models/adjustment-line.d.ts +3 -1
  28. package/dist/models/adjustment-line.d.ts.map +1 -0
  29. package/dist/models/adjustment-line.js +5 -0
  30. package/dist/models/adjustment-line.js.map +1 -1
  31. package/dist/models/claim-item-image.d.ts +19 -0
  32. package/dist/models/claim-item-image.d.ts.map +1 -0
  33. package/dist/models/claim-item-image.js +109 -0
  34. package/dist/models/claim-item-image.js.map +1 -0
  35. package/dist/models/claim-item.d.ts +29 -0
  36. package/dist/models/claim-item.d.ts.map +1 -0
  37. package/dist/models/claim-item.js +156 -0
  38. package/dist/models/claim-item.js.map +1 -0
  39. package/dist/models/claim.d.ts +36 -0
  40. package/dist/models/claim.d.ts.map +1 -0
  41. package/dist/models/claim.js +195 -0
  42. package/dist/models/claim.js.map +1 -0
  43. package/dist/models/exchange-item.d.ts +24 -0
  44. package/dist/models/exchange-item.d.ts.map +1 -0
  45. package/dist/models/exchange-item.js +138 -0
  46. package/dist/models/exchange-item.js.map +1 -0
  47. package/dist/models/exchange.d.ts +34 -0
  48. package/dist/models/exchange.d.ts.map +1 -0
  49. package/dist/models/exchange.js +188 -0
  50. package/dist/models/exchange.js.map +1 -0
  51. package/dist/models/index.d.ts +9 -0
  52. package/dist/models/index.d.ts.map +1 -0
  53. package/dist/models/index.js +17 -1
  54. package/dist/models/index.js.map +1 -1
  55. package/dist/models/line-item-adjustment.d.ts +3 -1
  56. package/dist/models/line-item-adjustment.d.ts.map +1 -0
  57. package/dist/models/line-item-adjustment.js +3 -3
  58. package/dist/models/line-item-adjustment.js.map +1 -1
  59. package/dist/models/line-item-tax-line.d.ts +3 -1
  60. package/dist/models/line-item-tax-line.d.ts.map +1 -0
  61. package/dist/models/line-item-tax-line.js +3 -3
  62. package/dist/models/line-item-tax-line.js.map +1 -1
  63. package/dist/models/line-item.d.ts +3 -1
  64. package/dist/models/line-item.d.ts.map +1 -0
  65. package/dist/models/line-item.js +18 -4
  66. package/dist/models/line-item.js.map +1 -1
  67. package/dist/models/order-change-action.d.ts +15 -4
  68. package/dist/models/order-change-action.d.ts.map +1 -0
  69. package/dist/models/order-change-action.js +102 -7
  70. package/dist/models/order-change-action.js.map +1 -1
  71. package/dist/models/order-change.d.ts +17 -5
  72. package/dist/models/order-change.d.ts.map +1 -0
  73. package/dist/models/order-change.js +109 -4
  74. package/dist/models/order-change.js.map +1 -1
  75. package/dist/models/order-item.d.ts +5 -4
  76. package/dist/models/order-item.d.ts.map +1 -0
  77. package/dist/models/order-item.js +13 -13
  78. package/dist/models/order-item.js.map +1 -1
  79. package/dist/models/order-shipping-method.d.ts +14 -4
  80. package/dist/models/order-shipping-method.d.ts.map +1 -0
  81. package/dist/models/order-shipping-method.js +89 -13
  82. package/dist/models/order-shipping-method.js.map +1 -1
  83. package/dist/models/order-summary.d.ts +6 -7
  84. package/dist/models/order-summary.d.ts.map +1 -0
  85. package/dist/models/order-summary.js +9 -6
  86. package/dist/models/order-summary.js.map +1 -1
  87. package/dist/models/order.d.ts +6 -4
  88. package/dist/models/order.d.ts.map +1 -0
  89. package/dist/models/order.js +11 -1
  90. package/dist/models/order.js.map +1 -1
  91. package/dist/models/return-item.d.ts +29 -0
  92. package/dist/models/return-item.d.ts.map +1 -0
  93. package/dist/models/return-item.js +170 -0
  94. package/dist/models/return-item.js.map +1 -0
  95. package/dist/models/return-reason.d.ts +21 -0
  96. package/dist/models/return-reason.d.ts.map +1 -0
  97. package/dist/models/return-reason.js +120 -0
  98. package/dist/models/return-reason.js.map +1 -0
  99. package/dist/models/return.d.ts +39 -0
  100. package/dist/models/return.d.ts.map +1 -0
  101. package/dist/models/return.js +216 -0
  102. package/dist/models/return.js.map +1 -0
  103. package/dist/models/shipping-method-adjustment.d.ts +3 -1
  104. package/dist/models/shipping-method-adjustment.d.ts.map +1 -0
  105. package/dist/models/shipping-method-adjustment.js +3 -3
  106. package/dist/models/shipping-method-adjustment.js.map +1 -1
  107. package/dist/models/shipping-method-tax-line.d.ts +3 -1
  108. package/dist/models/shipping-method-tax-line.d.ts.map +1 -0
  109. package/dist/models/shipping-method-tax-line.js +3 -3
  110. package/dist/models/shipping-method-tax-line.js.map +1 -1
  111. package/dist/models/shipping-method.d.ts +2 -0
  112. package/dist/models/shipping-method.d.ts.map +1 -0
  113. package/dist/models/shipping-method.js +17 -4
  114. package/dist/models/shipping-method.js.map +1 -1
  115. package/dist/models/tax-line.d.ts +2 -0
  116. package/dist/models/tax-line.d.ts.map +1 -0
  117. package/dist/models/tax-line.js +7 -0
  118. package/dist/models/tax-line.js.map +1 -1
  119. package/dist/models/transaction.d.ts +15 -3
  120. package/dist/models/transaction.d.ts.map +1 -0
  121. package/dist/models/transaction.js +109 -4
  122. package/dist/models/transaction.js.map +1 -1
  123. package/dist/repositories/claim.d.ts +9 -0
  124. package/dist/repositories/claim.d.ts.map +1 -0
  125. package/dist/repositories/claim.js +11 -0
  126. package/dist/repositories/claim.js.map +1 -0
  127. package/dist/repositories/exchange.d.ts +9 -0
  128. package/dist/repositories/exchange.d.ts.map +1 -0
  129. package/dist/repositories/exchange.js +11 -0
  130. package/dist/repositories/exchange.js.map +1 -0
  131. package/dist/repositories/index.d.ts +4 -1
  132. package/dist/repositories/index.d.ts.map +1 -0
  133. package/dist/repositories/index.js +7 -16
  134. package/dist/repositories/index.js.map +1 -1
  135. package/dist/repositories/order.d.ts +1 -3
  136. package/dist/repositories/order.d.ts.map +1 -0
  137. package/dist/repositories/order.js +2 -85
  138. package/dist/repositories/order.js.map +1 -1
  139. package/dist/repositories/return.d.ts +9 -0
  140. package/dist/repositories/return.d.ts.map +1 -0
  141. package/dist/repositories/return.js +11 -0
  142. package/dist/repositories/return.js.map +1 -0
  143. package/dist/services/actions/cancel-claim.d.ts +3 -0
  144. package/dist/services/actions/cancel-claim.d.ts.map +1 -0
  145. package/dist/services/actions/cancel-claim.js +107 -0
  146. package/dist/services/actions/cancel-claim.js.map +1 -0
  147. package/dist/services/actions/cancel-exchange.d.ts +3 -0
  148. package/dist/services/actions/cancel-exchange.d.ts.map +1 -0
  149. package/dist/services/actions/cancel-exchange.js +92 -0
  150. package/dist/services/actions/cancel-exchange.js.map +1 -0
  151. package/dist/services/actions/cancel-fulfillment.d.ts +3 -0
  152. package/dist/services/actions/cancel-fulfillment.d.ts.map +1 -0
  153. package/dist/services/actions/cancel-fulfillment.js +32 -0
  154. package/dist/services/actions/cancel-fulfillment.js.map +1 -0
  155. package/dist/services/actions/cancel-return.d.ts +3 -0
  156. package/dist/services/actions/cancel-return.d.ts.map +1 -0
  157. package/dist/services/actions/cancel-return.js +72 -0
  158. package/dist/services/actions/cancel-return.js.map +1 -0
  159. package/dist/services/actions/create-claim.d.ts +3 -0
  160. package/dist/services/actions/create-claim.d.ts.map +1 -0
  161. package/dist/services/actions/create-claim.js +228 -0
  162. package/dist/services/actions/create-claim.js.map +1 -0
  163. package/dist/services/actions/create-exchange.d.ts +3 -0
  164. package/dist/services/actions/create-exchange.d.ts.map +1 -0
  165. package/dist/services/actions/create-exchange.js +193 -0
  166. package/dist/services/actions/create-exchange.js.map +1 -0
  167. package/dist/services/actions/create-return.d.ts +3 -0
  168. package/dist/services/actions/create-return.d.ts.map +1 -0
  169. package/dist/services/actions/create-return.js +102 -0
  170. package/dist/services/actions/create-return.js.map +1 -0
  171. package/dist/services/actions/index.d.ts +11 -0
  172. package/dist/services/actions/index.d.ts.map +1 -0
  173. package/dist/services/actions/index.js +27 -0
  174. package/dist/services/actions/index.js.map +1 -0
  175. package/dist/services/actions/receive-return.d.ts +3 -0
  176. package/dist/services/actions/receive-return.d.ts.map +1 -0
  177. package/dist/services/actions/receive-return.js +72 -0
  178. package/dist/services/actions/receive-return.js.map +1 -0
  179. package/dist/services/actions/register-fulfillment.d.ts +3 -0
  180. package/dist/services/actions/register-fulfillment.d.ts.map +1 -0
  181. package/dist/services/actions/register-fulfillment.js +30 -0
  182. package/dist/services/actions/register-fulfillment.js.map +1 -0
  183. package/dist/services/actions/register-shipment.d.ts +3 -0
  184. package/dist/services/actions/register-shipment.d.ts.map +1 -0
  185. package/dist/services/actions/register-shipment.js +38 -0
  186. package/dist/services/actions/register-shipment.js.map +1 -0
  187. package/dist/services/index.d.ts +1 -1
  188. package/dist/services/index.d.ts.map +1 -0
  189. package/dist/services/index.js +1 -3
  190. package/dist/services/index.js.map +1 -1
  191. package/dist/services/order-module-service.d.ts +138 -67
  192. package/dist/services/order-module-service.d.ts.map +1 -0
  193. package/dist/services/order-module-service.js +992 -240
  194. package/dist/services/order-module-service.js.map +1 -1
  195. package/dist/services/order-service.d.ts +5 -4
  196. package/dist/services/order-service.d.ts.map +1 -0
  197. package/dist/services/order-service.js +1 -1
  198. package/dist/services/order-service.js.map +1 -1
  199. package/dist/types/address.d.ts +1 -0
  200. package/dist/types/address.d.ts.map +1 -0
  201. package/dist/types/index.d.ts +3 -1
  202. package/dist/types/index.d.ts.map +1 -0
  203. package/dist/types/index.js +1 -0
  204. package/dist/types/index.js.map +1 -1
  205. package/dist/types/line-item-adjustment.d.ts +1 -0
  206. package/dist/types/line-item-adjustment.d.ts.map +1 -0
  207. package/dist/types/line-item-tax-line.d.ts +1 -0
  208. package/dist/types/line-item-tax-line.d.ts.map +1 -0
  209. package/dist/types/line-item.d.ts +1 -0
  210. package/dist/types/line-item.d.ts.map +1 -0
  211. package/dist/types/order-change.d.ts +6 -0
  212. package/dist/types/order-change.d.ts.map +1 -0
  213. package/dist/types/order-change.js +3 -0
  214. package/dist/types/order-change.js.map +1 -0
  215. package/dist/types/order-detail.d.ts +2 -1
  216. package/dist/types/order-detail.d.ts.map +1 -0
  217. package/dist/types/order.d.ts +3 -2
  218. package/dist/types/order.d.ts.map +1 -0
  219. package/dist/types/shipping-method-adjustment.d.ts +1 -0
  220. package/dist/types/shipping-method-adjustment.d.ts.map +1 -0
  221. package/dist/types/shipping-method-tax-line.d.ts +1 -0
  222. package/dist/types/shipping-method-tax-line.d.ts.map +1 -0
  223. package/dist/types/shipping-method.d.ts +4 -0
  224. package/dist/types/shipping-method.d.ts.map +1 -0
  225. package/dist/types/tax-line.d.ts +1 -0
  226. package/dist/types/tax-line.d.ts.map +1 -0
  227. package/dist/types/transaction.d.ts +1 -0
  228. package/dist/types/transaction.d.ts.map +1 -0
  229. package/dist/types/utils/index.d.ts +40 -21
  230. package/dist/types/utils/index.d.ts.map +1 -0
  231. package/dist/types/utils/index.js +0 -1
  232. package/dist/types/utils/index.js.map +1 -1
  233. package/dist/utils/actions/cancel-item-fulfillment.d.ts +2 -0
  234. package/dist/utils/actions/cancel-item-fulfillment.d.ts.map +1 -0
  235. package/dist/utils/actions/cancel-item-fulfillment.js +34 -0
  236. package/dist/utils/actions/cancel-item-fulfillment.js.map +1 -0
  237. package/dist/utils/actions/cancel-return.d.ts +1 -0
  238. package/dist/utils/actions/cancel-return.d.ts.map +1 -0
  239. package/dist/utils/actions/cancel-return.js +6 -10
  240. package/dist/utils/actions/cancel-return.js.map +1 -1
  241. package/dist/utils/actions/fulfill-item.d.ts +1 -0
  242. package/dist/utils/actions/fulfill-item.d.ts.map +1 -0
  243. package/dist/utils/actions/fulfill-item.js +6 -10
  244. package/dist/utils/actions/fulfill-item.js.map +1 -1
  245. package/dist/utils/actions/index.d.ts +4 -1
  246. package/dist/utils/actions/index.d.ts.map +1 -0
  247. package/dist/utils/actions/index.js +3 -1
  248. package/dist/utils/actions/index.js.map +1 -1
  249. package/dist/utils/actions/item-add.d.ts +1 -0
  250. package/dist/utils/actions/item-add.d.ts.map +1 -0
  251. package/dist/utils/actions/item-add.js +15 -24
  252. package/dist/utils/actions/item-add.js.map +1 -1
  253. package/dist/utils/actions/item-remove.d.ts +1 -0
  254. package/dist/utils/actions/item-remove.d.ts.map +1 -0
  255. package/dist/utils/actions/item-remove.js +8 -22
  256. package/dist/utils/actions/item-remove.js.map +1 -1
  257. package/dist/utils/actions/receive-damaged-return-item.d.ts +1 -0
  258. package/dist/utils/actions/receive-damaged-return-item.d.ts.map +1 -0
  259. package/dist/utils/actions/receive-damaged-return-item.js +9 -35
  260. package/dist/utils/actions/receive-damaged-return-item.js.map +1 -1
  261. package/dist/utils/actions/receive-return-item.d.ts +1 -0
  262. package/dist/utils/actions/receive-return-item.d.ts.map +1 -0
  263. package/dist/utils/actions/receive-return-item.js +7 -36
  264. package/dist/utils/actions/receive-return-item.js.map +1 -1
  265. package/dist/utils/actions/reinstate-item.d.ts +2 -0
  266. package/dist/utils/actions/reinstate-item.d.ts.map +1 -0
  267. package/dist/utils/actions/reinstate-item.js +32 -0
  268. package/dist/utils/actions/reinstate-item.js.map +1 -0
  269. package/dist/utils/actions/return-item.d.ts +1 -0
  270. package/dist/utils/actions/return-item.d.ts.map +1 -0
  271. package/dist/utils/actions/return-item.js +8 -12
  272. package/dist/utils/actions/return-item.js.map +1 -1
  273. package/dist/utils/actions/ship-item.d.ts +1 -0
  274. package/dist/utils/actions/ship-item.d.ts.map +1 -0
  275. package/dist/utils/actions/ship-item.js +6 -10
  276. package/dist/utils/actions/ship-item.js.map +1 -1
  277. package/dist/utils/actions/shipping-add.d.ts +1 -0
  278. package/dist/utils/actions/shipping-add.d.ts.map +1 -0
  279. package/dist/utils/actions/shipping-add.js +16 -16
  280. package/dist/utils/actions/shipping-add.js.map +1 -1
  281. package/dist/utils/actions/shipping-remove.d.ts +2 -0
  282. package/dist/utils/actions/shipping-remove.d.ts.map +1 -0
  283. package/dist/utils/actions/shipping-remove.js +25 -0
  284. package/dist/utils/actions/shipping-remove.js.map +1 -0
  285. package/dist/utils/actions/write-off-item.d.ts +1 -0
  286. package/dist/utils/actions/write-off-item.d.ts.map +1 -0
  287. package/dist/utils/actions/write-off-item.js +6 -10
  288. package/dist/utils/actions/write-off-item.js.map +1 -1
  289. package/dist/utils/apply-order-changes.d.ts +18 -0
  290. package/dist/utils/apply-order-changes.d.ts.map +1 -0
  291. package/dist/utils/apply-order-changes.js +95 -0
  292. package/dist/utils/apply-order-changes.js.map +1 -0
  293. package/dist/utils/base-repository-find.d.ts +3 -0
  294. package/dist/utils/base-repository-find.d.ts.map +1 -0
  295. package/dist/utils/base-repository-find.js +142 -0
  296. package/dist/utils/base-repository-find.js.map +1 -0
  297. package/dist/utils/calculate-order-change.d.ts +11 -5
  298. package/dist/utils/calculate-order-change.d.ts.map +1 -0
  299. package/dist/utils/calculate-order-change.js +57 -182
  300. package/dist/utils/calculate-order-change.js.map +1 -1
  301. package/dist/utils/index.d.ts +4 -1
  302. package/dist/utils/index.d.ts.map +1 -0
  303. package/dist/utils/index.js +3 -1
  304. package/dist/utils/index.js.map +1 -1
  305. package/dist/utils/set-action-reference.d.ts +2 -0
  306. package/dist/utils/set-action-reference.d.ts.map +1 -0
  307. package/dist/utils/set-action-reference.js +11 -0
  308. package/dist/utils/set-action-reference.js.map +1 -0
  309. package/dist/utils/transform-order.d.ts +4 -2
  310. package/dist/utils/transform-order.d.ts.map +1 -0
  311. package/dist/utils/transform-order.js +131 -17
  312. package/dist/utils/transform-order.js.map +1 -1
  313. package/package.json +8 -14
  314. package/dist/joiner-config.d.ts +0 -5
  315. package/dist/joiner-config.js +0 -36
  316. package/dist/joiner-config.js.map +0 -1
  317. package/dist/module-definition.d.ts +0 -2
  318. package/dist/module-definition.js +0 -59
  319. package/dist/module-definition.js.map +0 -1
  320. package/dist/scripts/bin/run-seed.d.ts +0 -3
  321. package/dist/scripts/bin/run-seed.js +0 -49
  322. package/dist/scripts/bin/run-seed.js.map +0 -1
  323. package/dist/services/order-change-service.d.ts +0 -15
  324. package/dist/services/order-change-service.js +0 -96
  325. package/dist/services/order-change-service.js.map +0 -1
  326. package/dist/utils/action-key.d.ts +0 -13
  327. package/dist/utils/action-key.js +0 -18
  328. package/dist/utils/action-key.js.map +0 -1
  329. package/dist/utils/actions/cancel.d.ts +0 -1
  330. package/dist/utils/actions/cancel.js +0 -8
  331. package/dist/utils/actions/cancel.js.map +0 -1
@@ -0,0 +1,193 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createExchange = void 0;
4
+ const utils_1 = require("@medusajs/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
+ return_id: returnReference.id,
33
+ exchange_id: exchangeReference.id,
34
+ quantity: item.quantity,
35
+ metadata: item.metadata,
36
+ },
37
+ });
38
+ return em.create(_models_1.ReturnItem, {
39
+ item_id: item.id,
40
+ return_id: returnReference.id,
41
+ reason: item.reason,
42
+ quantity: item.quantity,
43
+ note: item.note,
44
+ metadata: item.metadata,
45
+ });
46
+ });
47
+ }
48
+ async function processAdditionalItems(em, service, data, order, exchangeReference, actions, sharedContext) {
49
+ const itemsToAdd = [];
50
+ const additionalNewItems = [];
51
+ const additionalItems = [];
52
+ data.additional_items?.forEach((item) => {
53
+ const hasItem = item.id
54
+ ? order.items.find((o) => o.item.id === item.id)
55
+ : false;
56
+ if (hasItem) {
57
+ actions.push({
58
+ action: utils_1.ChangeActionType.ITEM_ADD,
59
+ exchange_id: exchangeReference.id,
60
+ internal_note: item.internal_note,
61
+ reference: "exchange",
62
+ reference_id: exchangeReference.id,
63
+ details: {
64
+ reference_id: item.id,
65
+ exchange_id: exchangeReference.id,
66
+ quantity: item.quantity,
67
+ metadata: item.metadata,
68
+ },
69
+ });
70
+ additionalItems.push(em.create(_models_1.ExchangeItem, {
71
+ item_id: item.id,
72
+ quantity: item.quantity,
73
+ note: item.note,
74
+ metadata: item.metadata,
75
+ is_additional_item: true,
76
+ }));
77
+ }
78
+ else {
79
+ itemsToAdd.push(item);
80
+ additionalNewItems.push(em.create(_models_1.ExchangeItem, {
81
+ quantity: item.quantity,
82
+ note: item.note,
83
+ metadata: item.metadata,
84
+ is_additional_item: true,
85
+ }));
86
+ }
87
+ });
88
+ const createItems = await service.lineItemService_.create(itemsToAdd, sharedContext);
89
+ createItems.forEach((item, index) => {
90
+ const addedItem = itemsToAdd[index];
91
+ additionalNewItems[index].item_id = item.id;
92
+ actions.push({
93
+ action: utils_1.ChangeActionType.ITEM_ADD,
94
+ exchange_id: exchangeReference.id,
95
+ internal_note: addedItem.internal_note,
96
+ reference: "exchange",
97
+ reference_id: exchangeReference.id,
98
+ details: {
99
+ reference_id: item.id,
100
+ exchange_id: exchangeReference.id,
101
+ quantity: addedItem.quantity,
102
+ unit_price: item.unit_price,
103
+ metadata: addedItem.metadata,
104
+ },
105
+ });
106
+ });
107
+ return additionalNewItems.concat(additionalItems);
108
+ }
109
+ async function processShippingMethods(service, data, exchangeReference, actions, sharedContext) {
110
+ for (const shippingMethod of data.shipping_methods ?? []) {
111
+ let shippingMethodId;
112
+ if (!(0, utils_1.isString)(shippingMethod)) {
113
+ const methods = await service.createShippingMethods([
114
+ {
115
+ ...shippingMethod,
116
+ order_id: data.order_id,
117
+ exchange_id: exchangeReference.id,
118
+ },
119
+ ], sharedContext);
120
+ shippingMethodId = methods[0].id;
121
+ }
122
+ else {
123
+ shippingMethodId = shippingMethod;
124
+ }
125
+ const method = await service.retrieveShippingMethod(shippingMethodId, { relations: ["tax_lines", "adjustments"] }, sharedContext);
126
+ const calculatedAmount = (0, utils_1.getShippingMethodsTotals)([method], {})[method.id];
127
+ actions.push({
128
+ action: utils_1.ChangeActionType.SHIPPING_ADD,
129
+ reference: "order_shipping_method",
130
+ reference_id: shippingMethodId,
131
+ exchange_id: exchangeReference.id,
132
+ amount: calculatedAmount.total,
133
+ });
134
+ }
135
+ }
136
+ async function processReturnShipping(service, data, exchangeReference, returnReference, actions, sharedContext) {
137
+ let returnShippingMethodId;
138
+ if (!(0, utils_1.isString)(data.return_shipping)) {
139
+ const methods = await service.createShippingMethods([
140
+ {
141
+ ...data.return_shipping,
142
+ order_id: data.order_id,
143
+ exchange_id: exchangeReference.id,
144
+ return_id: returnReference.id,
145
+ },
146
+ ], sharedContext);
147
+ returnShippingMethodId = methods[0].id;
148
+ }
149
+ else {
150
+ returnShippingMethodId = data.return_shipping;
151
+ }
152
+ const method = await service.retrieveShippingMethod(returnShippingMethodId, { relations: ["tax_lines", "adjustments"] }, sharedContext);
153
+ const calculatedAmount = (0, utils_1.getShippingMethodsTotals)([method], {})[method.id];
154
+ actions.push({
155
+ action: utils_1.ChangeActionType.SHIPPING_ADD,
156
+ reference: "order_shipping_method",
157
+ reference_id: returnShippingMethodId,
158
+ return_id: returnReference.id,
159
+ exchange_id: exchangeReference.id,
160
+ amount: calculatedAmount.total,
161
+ });
162
+ }
163
+ async function createExchange(data, sharedContext) {
164
+ const order = await this.orderService_.retrieve(data.order_id, { relations: ["items"] }, sharedContext);
165
+ const actions = [];
166
+ const em = sharedContext.transactionManager;
167
+ const { exchangeReference, returnReference } = createExchangeAndReturnEntities(em, data, order);
168
+ returnReference.items = createReturnItems(em, data, exchangeReference, returnReference, actions);
169
+ exchangeReference.additional_items = await processAdditionalItems(em, this, data, order, exchangeReference, actions, sharedContext);
170
+ await processShippingMethods(this, data, exchangeReference, actions, sharedContext);
171
+ await processReturnShipping(this, data, exchangeReference, returnReference, actions, sharedContext);
172
+ const change = await this.createOrderChange_({
173
+ order_id: data.order_id,
174
+ exchange_id: exchangeReference.id,
175
+ return_id: returnReference.id,
176
+ change_type: utils_1.OrderChangeType.EXCHANGE,
177
+ reference: "exchange",
178
+ reference_id: exchangeReference.id,
179
+ description: data.description,
180
+ internal_note: data.internal_note,
181
+ created_by: data.created_by,
182
+ metadata: data.metadata,
183
+ actions,
184
+ }, sharedContext);
185
+ await (0, utils_1.promiseAll)([
186
+ this.createReturns([returnReference], sharedContext),
187
+ this.createOrderExchanges([exchangeReference], sharedContext),
188
+ this.confirmOrderChange(change[0].id, sharedContext),
189
+ ]);
190
+ return exchangeReference;
191
+ }
192
+ exports.createExchange = createExchange;
193
+ //# sourceMappingURL=create-exchange.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create-exchange.js","sourceRoot":"","sources":["../../../src/services/actions/create-exchange.ts"],"names":[],"mappings":";;;AAKA,2CAOwB;AACxB,qCAAyE;AAEzE,SAAS,+BAA+B,CAAC,EAAE,EAAE,IAAI,EAAE,KAAK;IACtD,MAAM,iBAAiB,GAAG,EAAE,CAAC,MAAM,CAAC,uBAAa,EAAE;QACjD,QAAQ,EAAE,IAAI,CAAC,QAAQ;QACvB,aAAa,EAAE,KAAK,CAAC,OAAO;QAC5B,eAAe,EAAE,IAAI,CAAC,eAAe;QACrC,eAAe,EAAE,IAAI,CAAC,eAAe;QACrC,cAAc,EAAE,IAAI,CAAC,cAAc;KACpC,CAAC,CAAA;IAEF,MAAM,eAAe,GAAG,EAAE,CAAC,MAAM,CAAC,gBAAM,EAAE;QACxC,QAAQ,EAAE,IAAI,CAAC,QAAQ;QACvB,aAAa,EAAE,KAAK,CAAC,OAAO;QAC5B,MAAM,EAAE,oBAAY,CAAC,SAAS;QAC9B,WAAW,EAAE,iBAAiB,CAAC,EAAE;QACjC,aAAa,EAAG,IAAI,CAAC,aAAyB,IAAI,IAAI;KACvD,CAAC,CAAA;IAEF,iBAAiB,CAAC,SAAS,GAAG,eAAe,CAAC,EAAE,CAAA;IAEhD,OAAO,EAAE,iBAAiB,EAAE,eAAe,EAAE,CAAA;AAC/C,CAAC;AAED,SAAS,iBAAiB,CACxB,EAAE,EACF,IAAI,EACJ,iBAAiB,EACjB,eAAe,EACf,OAAO;IAEP,OAAO,IAAI,CAAC,YAAY,EAAE,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE;QACrC,OAAO,CAAC,IAAI,CAAC;YACX,MAAM,EAAE,wBAAgB,CAAC,WAAW;YACpC,SAAS,EAAE,QAAQ;YACnB,YAAY,EAAE,eAAe,CAAC,EAAE;YAChC,OAAO,EAAE;gBACP,YAAY,EAAE,IAAI,CAAC,EAAE;gBACrB,SAAS,EAAE,eAAe,CA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AiB,CAAC,EAAE;QAClC,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,oBAAoB,CAAC,CAAC,iBAAiB,CAAC,EAAE,aAAa,CAAC;QAC7D,IAAI,CAAC,kBAAkB,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,EAAE,EAAE,aAAa,CAAC;KACrD,CAAC,CAAA;IAEF,OAAO,iBAAiB,CAAA;AAC1B,CAAC;AAxED,wCAwEC"}
@@ -0,0 +1,3 @@
1
+ import { Context, OrderTypes } from "@medusajs/types";
2
+ export declare function createReturn(this: any, data: OrderTypes.CreateOrderReturnDTO, sharedContext?: Context): Promise<any>;
3
+ //# sourceMappingURL=create-return.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create-return.d.ts","sourceRoot":"","sources":["../../../src/services/actions/create-return.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,OAAO,EAEP,UAAU,EACX,MAAM,iBAAiB,CAAA;AA8HxB,wBAAsB,YAAY,CAChC,IAAI,EAAE,GAAG,EACT,IAAI,EAAE,UAAU,CAAC,oBAAoB,EACrC,aAAa,CAAC,EAAE,OAAO,gBA8BxB"}
@@ -0,0 +1,102 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createReturn = void 0;
4
+ const utils_1 = require("@medusajs/utils");
5
+ const _models_1 = require("../../models");
6
+ function createReturnReference(em, data, order) {
7
+ return em.create(_models_1.Return, {
8
+ order_id: data.order_id,
9
+ order_version: order.version,
10
+ status: utils_1.ReturnStatus.REQUESTED,
11
+ no_notification: data.no_notification,
12
+ refund_amount: data.refund_amount ?? null,
13
+ });
14
+ }
15
+ function createReturnItems(em, data, returnRef, actions) {
16
+ return data.items.map((item) => {
17
+ actions.push({
18
+ action: utils_1.ChangeActionType.RETURN_ITEM,
19
+ return_id: returnRef.id,
20
+ internal_note: item.internal_note,
21
+ reference: "return",
22
+ reference_id: returnRef.id,
23
+ details: {
24
+ reference_id: item.id,
25
+ return_id: returnRef.id,
26
+ quantity: item.quantity,
27
+ metadata: item.metadata,
28
+ },
29
+ });
30
+ return em.create(_models_1.ReturnItem, {
31
+ reason_id: item.reason_id,
32
+ return_id: returnRef.id,
33
+ item_id: item.id,
34
+ quantity: item.quantity,
35
+ note: item.note,
36
+ metadata: item.metadata,
37
+ });
38
+ });
39
+ }
40
+ async function processShippingMethod(service, data, returnRef, actions, sharedContext) {
41
+ let shippingMethodId;
42
+ if (!(0, utils_1.isDefined)(data.shipping_method)) {
43
+ return;
44
+ }
45
+ if (!(0, utils_1.isString)(data.shipping_method)) {
46
+ const methods = await service.createShippingMethods([
47
+ {
48
+ ...data.shipping_method,
49
+ order_id: data.order_id,
50
+ return_id: returnRef.id,
51
+ },
52
+ ], sharedContext);
53
+ shippingMethodId = methods[0].id;
54
+ }
55
+ else {
56
+ shippingMethodId = data.shipping_method;
57
+ }
58
+ const method = await service.retrieveShippingMethod(shippingMethodId, { relations: ["tax_lines", "adjustments"] }, sharedContext);
59
+ const calculatedAmount = (0, utils_1.getShippingMethodsTotals)([method], {})[method.id];
60
+ if (shippingMethodId) {
61
+ actions.push({
62
+ action: utils_1.ChangeActionType.SHIPPING_ADD,
63
+ reference: "order_shipping_method",
64
+ reference_id: shippingMethodId,
65
+ amount: calculatedAmount.total,
66
+ details: {
67
+ order_id: returnRef.order_id,
68
+ return_id: returnRef.id,
69
+ },
70
+ });
71
+ }
72
+ }
73
+ async function createOrderChange(service, data, returnRef, actions, sharedContext) {
74
+ return await service.createOrderChange_({
75
+ order_id: data.order_id,
76
+ return_id: returnRef.id,
77
+ change_type: utils_1.OrderChangeType.RETURN,
78
+ reference: "return",
79
+ reference_id: returnRef.id,
80
+ description: data.description,
81
+ internal_note: data.internal_note,
82
+ created_by: data.created_by,
83
+ metadata: data.metadata,
84
+ actions,
85
+ }, sharedContext);
86
+ }
87
+ async function createReturn(data, sharedContext) {
88
+ const order = await this.orderService_.retrieve(data.order_id, { relations: ["items"] }, sharedContext);
89
+ const em = sharedContext.transactionManager;
90
+ const returnRef = createReturnReference(em, data, order);
91
+ const actions = [];
92
+ returnRef.items = createReturnItems(em, data, returnRef, actions);
93
+ await processShippingMethod(this, data, returnRef, actions, sharedContext);
94
+ const change = await createOrderChange(this, data, returnRef, actions, sharedContext);
95
+ await (0, utils_1.promiseAll)([
96
+ this.createReturns([returnRef], sharedContext),
97
+ this.confirmOrderChange(change[0].id, sharedContext),
98
+ ]);
99
+ return returnRef;
100
+ }
101
+ exports.createReturn = createReturn;
102
+ //# sourceMappingURL=create-return.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create-return.js","sourceRoot":"","sources":["../../../src/services/actions/create-return.ts"],"names":[],"mappings":";;;AAKA,2CAQwB;AACxB,qCAA4C;AAE5C,SAAS,qBAAqB,CAAC,EAAE,EAAE,IAAI,EAAE,KAAK;IAC5C,OAAO,EAAE,CAAC,MAAM,CAAC,gBAAM,EAAE;QACvB,QAAQ,EAAE,IAAI,CAAC,QAAQ;QACvB,aAAa,EAAE,KAAK,CAAC,OAAO;QAC5B,MAAM,EAAE,oBAAY,CAAC,SAAS;QAC9B,eAAe,EAAE,IAAI,CAAC,eAAe;QACrC,aAAa,EAAG,IAAI,CAAC,aAAyB,IAAI,IAAI;KACvD,CAAC,CAAA;AACJ,CAAC;AAED,SAAS,iBAAiB,CAAC,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,OAAO;IACrD,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE;QAC7B,OAAO,CAAC,IAAI,CAAC;YACX,MAAM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KAAK,GAAG,MAAM,IAAI,CAAC,aAAa,CAAC,QAAQ,CAC7C,IAAI,CAAC,QAAQ,EACb,EAAE,SAAS,EAAE,CAAC,OAAO,CAAC,EAAE,EACxB,aAAa,CACd,CAAA;IAED,MAAM,EAAE,GAAG,aAAc,CAAC,kBAAyB,CAAA;IACnD,MAAM,SAAS,GAAG,qBAAqB,CAAC,EAAE,EAAE,IAAI,EAAE,KAAK,CAAC,CAAA;IACxD,MAAM,OAAO,GAAiC,EAAE,CAAA;IAEhD,SAAS,CAAC,KAAK,GAAG,iBAAiB,CAAC,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,OAAO,CAAC,CAAA;IAEjE,MAAM,qBAAqB,CAAC,IAAI,EAAE,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,aAAa,CAAC,CAAA;IAE1E,MAAM,MAAM,GAAG,MAAM,iBAAiB,CACpC,IAAI,EACJ,IAAI,EACJ,SAAS,EACT,OAAO,EACP,aAAa,CACd,CAAA;IAED,MAAM,IAAA,kBAAU,EAAC;QACf,IAAI,CAAC,aAAa,CAAC,CAAC,SAAS,CAAC,EAAE,aAAa,CAAC;QAC9C,IAAI,CAAC,kBAAkB,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,EAAE,EAAE,aAAa,CAAC;KACrD,CAAC,CAAA;IAEF,OAAO,SAAS,CAAA;AAClB,CAAC;AAjCD,oCAiCC"}
@@ -0,0 +1,11 @@
1
+ export * from "./cancel-claim";
2
+ export * from "./cancel-exchange";
3
+ export * from "./cancel-fulfillment";
4
+ export * from "./cancel-return";
5
+ export * from "./create-claim";
6
+ export * from "./create-exchange";
7
+ export * from "./create-return";
8
+ export * from "./receive-return";
9
+ export * from "./register-fulfillment";
10
+ export * from "./register-shipment";
11
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/services/actions/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAA;AAC9B,cAAc,mBAAmB,CAAA;AACjC,cAAc,sBAAsB,CAAA;AACpC,cAAc,iBAAiB,CAAA;AAC/B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,mBAAmB,CAAA;AACjC,cAAc,iBAAiB,CAAA;AAC/B,cAAc,kBAAkB,CAAA;AAChC,cAAc,wBAAwB,CAAA;AACtC,cAAc,qBAAqB,CAAA"}
@@ -0,0 +1,27 @@
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./cancel-claim"), exports);
18
+ __exportStar(require("./cancel-exchange"), exports);
19
+ __exportStar(require("./cancel-fulfillment"), exports);
20
+ __exportStar(require("./cancel-return"), exports);
21
+ __exportStar(require("./create-claim"), exports);
22
+ __exportStar(require("./create-exchange"), exports);
23
+ __exportStar(require("./create-return"), exports);
24
+ __exportStar(require("./receive-return"), exports);
25
+ __exportStar(require("./register-fulfillment"), exports);
26
+ __exportStar(require("./register-shipment"), exports);
27
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/services/actions/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,iDAA8B;AAC9B,oDAAiC;AACjC,uDAAoC;AACpC,kDAA+B;AAC/B,iDAA8B;AAC9B,oDAAiC;AACjC,kDAA+B;AAC/B,mDAAgC;AAChC,yDAAsC;AACtC,sDAAmC"}
@@ -0,0 +1,3 @@
1
+ import { Context, OrderTypes } from "@medusajs/types";
2
+ export declare function receiveReturn(this: any, data: OrderTypes.ReceiveOrderReturnDTO, sharedContext?: Context): Promise<any>;
3
+ //# sourceMappingURL=receive-return.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"receive-return.d.ts","sourceRoot":"","sources":["../../../src/services/actions/receive-return.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AA8ErD,wBAAsB,aAAa,CACjC,IAAI,EAAE,GAAG,EACT,IAAI,EAAE,UAAU,CAAC,qBAAqB,EACtC,aAAa,CAAC,EAAE,OAAO,gBAmCxB"}
@@ -0,0 +1,72 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.receiveReturn = void 0;
4
+ const utils_1 = require("@medusajs/utils");
5
+ function createReturnItems(data) {
6
+ return data.items.map((item) => ({
7
+ action: utils_1.ChangeActionType.RECEIVE_RETURN_ITEM,
8
+ internal_note: item.internal_note,
9
+ reference: data.reference,
10
+ reference_id: data.reference_id,
11
+ details: {
12
+ reference_id: item.id,
13
+ quantity: item.quantity,
14
+ },
15
+ }));
16
+ }
17
+ async function createOrderChange(service, data, returnEntry, items, sharedContext) {
18
+ return await service.createOrderChange_({
19
+ order_id: returnEntry.order_id,
20
+ return_id: returnEntry.id,
21
+ reference: "return",
22
+ reference_id: returnEntry.id,
23
+ change_type: utils_1.OrderChangeType.RETURN,
24
+ description: data.description,
25
+ internal_note: data.internal_note,
26
+ created_by: data.created_by,
27
+ metadata: data.metadata,
28
+ actions: items,
29
+ }, sharedContext);
30
+ }
31
+ function updateReturnItems(returnEntry, items) {
32
+ return returnEntry.items
33
+ .map((item) => {
34
+ const data = items.find((i) => i.details.reference_id === item.item_id);
35
+ if (!data)
36
+ return;
37
+ const receivedQuantity = utils_1.MathBN.add(item.received_quantity || 0, data.details.quantity);
38
+ item.received_quantity = receivedQuantity;
39
+ return {
40
+ id: item.id,
41
+ received_quantity: receivedQuantity,
42
+ };
43
+ })
44
+ .filter(Boolean);
45
+ }
46
+ function checkAllItemsReceived(returnEntry) {
47
+ return returnEntry.items.every((item) => utils_1.MathBN.eq(item.received_quantity, item.quantity));
48
+ }
49
+ function getReturnUpdateData(hasReceivedAllItems) {
50
+ return hasReceivedAllItems
51
+ ? { status: utils_1.ReturnStatus.RECEIVED, received_at: new Date() }
52
+ : { status: utils_1.ReturnStatus.PARTIALLY_RECEIVED };
53
+ }
54
+ async function receiveReturn(data, sharedContext) {
55
+ const returnEntry = await this.retrieveReturn(data.return_id, {
56
+ select: ["id", "order_id"],
57
+ relations: ["items"],
58
+ }, sharedContext);
59
+ const items = createReturnItems(data);
60
+ const change = await createOrderChange(this, data, returnEntry, items, sharedContext);
61
+ await this.confirmOrderChange(change[0].id, sharedContext);
62
+ const retItemsToUpdate = updateReturnItems(returnEntry, items);
63
+ const hasReceivedAllItems = checkAllItemsReceived(returnEntry);
64
+ const retData = getReturnUpdateData(hasReceivedAllItems);
65
+ const [returnRef] = await (0, utils_1.promiseAll)([
66
+ this.updateReturns({ selector: { id: returnEntry.id }, data: retData }, sharedContext),
67
+ this.updateReturnItems(retItemsToUpdate, sharedContext),
68
+ ]);
69
+ return returnRef;
70
+ }
71
+ exports.receiveReturn = receiveReturn;
72
+ //# sourceMappingURL=receive-return.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"receive-return.js","sourceRoot":"","sources":["../../../src/services/actions/receive-return.ts"],"names":[],"mappings":";;;AACA,2CAMwB;AAExB,SAAS,iBAAiB,CAAC,IAAI;IAC7B,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;QAC/B,MAAM,EAAE,wBAAgB,CAAC,mBAAmB;QAC5C,aAAa,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OAAO,GAAG,mBAAmB,CAAC,mBAAmB,CAAC,CAAA;IAExD,MAAM,CAAC,SAAS,CAAC,GAAG,MAAM,IAAA,kBAAU,EAAC;QACnC,IAAI,CAAC,aAAa,CAChB,EAAE,QAAQ,EAAE,EAAE,EAAE,EAAE,WAAW,CAAC,EAAE,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,EACnD,aAAa,CACd;QACD,IAAI,CAAC,iBAAiB,CAAC,gBAAgB,EAAE,aAAa,CAAC;KACxD,CAAC,CAAA;IAEF,OAAO,SAAS,CAAA;AAClB,CAAC;AAtCD,sCAsCC"}
@@ -0,0 +1,3 @@
1
+ import { Context, OrderTypes } from "@medusajs/types";
2
+ export declare function registerFulfillment(this: any, data: OrderTypes.RegisterOrderFulfillmentDTO, sharedContext?: Context): Promise<void>;
3
+ //# sourceMappingURL=register-fulfillment.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"register-fulfillment.d.ts","sourceRoot":"","sources":["../../../src/services/actions/register-fulfillment.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAGrD,wBAAsB,mBAAmB,CACvC,IAAI,EAAE,GAAG,EACT,IAAI,EAAE,UAAU,CAAC,2BAA2B,EAC5C,aAAa,CAAC,EAAE,OAAO,GACtB,OAAO,CAAC,IAAI,CAAC,CA4Bf"}
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.registerFulfillment = void 0;
4
+ const utils_1 = require("@medusajs/utils");
5
+ async function registerFulfillment(data, sharedContext) {
6
+ const items = data.items.map((item) => {
7
+ return {
8
+ action: utils_1.ChangeActionType.FULFILL_ITEM,
9
+ internal_note: item.internal_note,
10
+ reference: data.reference,
11
+ reference_id: data.reference_id,
12
+ details: {
13
+ reference_id: item.id,
14
+ quantity: item.quantity,
15
+ metadata: item.metadata,
16
+ },
17
+ };
18
+ });
19
+ const change = await this.createOrderChange_({
20
+ order_id: data.order_id,
21
+ description: data.description,
22
+ internal_note: data.internal_note,
23
+ created_by: data.created_by,
24
+ metadata: data.metadata,
25
+ actions: items,
26
+ }, sharedContext);
27
+ await this.confirmOrderChange(change[0].id, sharedContext);
28
+ }
29
+ exports.registerFulfillment = registerFulfillment;
30
+ //# sourceMappingURL=register-fulfillment.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"register-fulfillment.js","sourceRoot":"","sources":["../../../src/services/actions/register-fulfillment.ts"],"names":[],"mappings":";;;AACA,2CAAkD;AAE3C,KAAK,UAAU,mBAAmB,CAEvC,IAA4C,EAC5C,aAAuB;IAEvB,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE;QACpC,OAAO;YACL,MAAM,EAAE,wBAAgB,CAAC,YAAY;YACrC,aAAa,EAAE,IAAI,CAAC,aAAa;YACjC,SAAS,EAAE,IAAI,CAAC,SAAS;YACzB,YAAY,EAAE,IAAI,CAAC,YAAY;YAC/B,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;AAhCD,kDAgCC"}
@@ -0,0 +1,3 @@
1
+ import { Context, OrderTypes } from "@medusajs/types";
2
+ export declare function registerShipment(this: any, data: OrderTypes.RegisterOrderShipmentDTO, sharedContext?: Context): Promise<void>;
3
+ //# sourceMappingURL=register-shipment.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"register-shipment.d.ts","sourceRoot":"","sources":["../../../src/services/actions/register-shipment.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,OAAO,EAEP,UAAU,EACX,MAAM,iBAAiB,CAAA;AAGxB,wBAAsB,gBAAgB,CACpC,IAAI,EAAE,GAAG,EACT,IAAI,EAAE,UAAU,CAAC,wBAAwB,EACzC,aAAa,CAAC,EAAE,OAAO,GACtB,OAAO,CAAC,IAAI,CAAC,CAsCf"}
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.registerShipment = void 0;
4
+ const utils_1 = require("@medusajs/utils");
5
+ async function registerShipment(data, sharedContext) {
6
+ let shippingMethodId;
7
+ const actions = data.items.map((item) => {
8
+ return {
9
+ action: utils_1.ChangeActionType.SHIP_ITEM,
10
+ internal_note: item.internal_note,
11
+ reference: data.reference,
12
+ reference_id: data.reference_id,
13
+ details: {
14
+ reference_id: item.id,
15
+ quantity: item.quantity,
16
+ metadata: item.metadata,
17
+ },
18
+ };
19
+ });
20
+ if (shippingMethodId) {
21
+ actions.push({
22
+ action: utils_1.ChangeActionType.SHIPPING_ADD,
23
+ reference: data.reference,
24
+ reference_id: shippingMethodId,
25
+ });
26
+ }
27
+ const change = await this.createOrderChange_({
28
+ order_id: data.order_id,
29
+ description: data.description,
30
+ internal_note: data.internal_note,
31
+ created_by: data.created_by,
32
+ metadata: data.metadata,
33
+ actions,
34
+ }, sharedContext);
35
+ await this.confirmOrderChange(change[0].id, sharedContext);
36
+ }
37
+ exports.registerShipment = registerShipment;
38
+ //# sourceMappingURL=register-shipment.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"register-shipment.js","sourceRoot":"","sources":["../../../src/services/actions/register-shipment.ts"],"names":[],"mappings":";;;AAKA,2CAAkD;AAE3C,KAAK,UAAU,gBAAgB,CAEpC,IAAyC,EACzC,aAAuB;IAEvB,IAAI,gBAAgB,CAAA;IAEpB,MAAM,OAAO,GAAiC,IAAI,CAAC,KAAM,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE;QACrE,OAAO;YACL,MAAM,EAAE,wBAAgB,CAAC,SAAS;YAClC,aAAa,EAAE,IAAI,CAAC,aAAa;YACjC,SAAS,EAAE,IAAI,CAAC,SAAS;YACzB,YAAY,EAAE,IAAI,CAAC,YAAY;YAC/B,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,IAAI,gBAAgB,EAAE,CAAC;QACrB,OAAO,CAAC,IAAI,CAAC;YACX,MAAM,EAAE,wBAAgB,CAAC,YAAY;YACrC,SAAS,EAAE,IAAI,CAAC,SAAS;YACzB,YAAY,EAAE,gBAAgB;SAC/B,CAAC,CAAA;IACJ,CAAC;IAED,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;KACR,EACD,aAAa,CACd,CAAA;IAED,MAAM,IAAI,CAAC,kBAAkB,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,EAAE,EAAE,aAAa,CAAC,CAAA;AAC5D,CAAC;AA1CD,4CA0CC"}
@@ -1,3 +1,3 @@
1
- export { default as OrderChangeService } from "./order-change-service";
2
1
  export { default as OrderModuleService } from "./order-module-service";
3
2
  export { default as OrderService } from "./order-service";
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/services/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,kBAAkB,EAAE,MAAM,wBAAwB,CAAA;AACtE,OAAO,EAAE,OAAO,IAAI,YAAY,EAAE,MAAM,iBAAiB,CAAA"}
@@ -3,9 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.OrderService = exports.OrderModuleService = exports.OrderChangeService = void 0;
7
- var order_change_service_1 = require("./order-change-service");
8
- Object.defineProperty(exports, "OrderChangeService", { enumerable: true, get: function () { return __importDefault(order_change_service_1).default; } });
6
+ exports.OrderService = exports.OrderModuleService = void 0;
9
7
  var order_module_service_1 = require("./order-module-service");
10
8
  Object.defineProperty(exports, "OrderModuleService", { enumerable: true, get: function () { return __importDefault(order_module_service_1).default; } });
11
9
  var order_service_1 = require("./order-service");
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/services/index.ts"],"names":[],"mappings":";;;;;;AAAA,+DAAsE;AAA7D,2IAAA,OAAO,OAAsB;AACtC,+DAAsE;AAA7D,2IAAA,OAAO,OAAsB;AACtC,iDAAyD;AAAhD,8HAAA,OAAO,OAAgB"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/services/index.ts"],"names":[],"mappings":";;;;;;AAAA,+DAAsE;AAA7D,2IAAA,OAAO,OAAsB;AACtC,iDAAyD;AAAhD,8HAAA,OAAO,OAAgB"}