@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
@@ -1,35 +1,41 @@
1
1
  import { OrderSummaryDTO } from "@medusajs/types";
2
2
  import { ActionTypeDefinition, InternalOrderChangeEvent, OrderChangeEvent, OrderTransaction, VirtualOrder } from "../types";
3
+ interface ProcessOptions {
4
+ addActionReferenceToObject?: boolean;
5
+ [key: string]: any;
6
+ }
3
7
  export declare class OrderChangeProcessing {
4
8
  private static typeDefinition;
5
9
  private static defaultConfig;
6
10
  private order;
7
11
  private transactions;
8
12
  private actions;
13
+ private options;
9
14
  private actionsProcessed;
10
15
  private groupTotal;
11
16
  private summary;
12
17
  static registerActionType(key: string, type: ActionTypeDefinition): void;
13
- constructor({ order, transactions, actions, }: {
18
+ constructor({ order, transactions, actions, options, }: {
14
19
  order: VirtualOrder;
15
20
  transactions: OrderTransaction[];
16
21
  actions: InternalOrderChangeEvent[];
22
+ options: ProcessOptions;
17
23
  });
18
24
  private isEventActive;
19
25
  private isEventDone;
20
- private isEventPending;
21
26
  processActions(): void;
22
27
  private processAction_;
23
- private resolveReferences;
24
- private resolveGroup;
25
28
  getSummary(): OrderSummaryDTO;
26
29
  getCurrentOrder(): VirtualOrder;
27
30
  }
28
- export declare function calculateOrderChange({ order, transactions, actions, }: {
31
+ export declare function calculateOrderChange({ order, transactions, actions, options, }: {
29
32
  order: VirtualOrder;
30
33
  transactions?: OrderTransaction[];
31
34
  actions?: OrderChangeEvent[];
35
+ options?: ProcessOptions;
32
36
  }): {
33
37
  summary: OrderSummaryDTO;
34
38
  order: VirtualOrder;
35
39
  };
40
+ export {};
41
+ //# sourceMappingURL=calculate-order-change.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"calculate-order-change.d.ts","sourceRoot":"","sources":["../../src/utils/calculate-order-change.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkB,eAAe,EAAE,MAAM,iBAAiB,CAAA;AAQjE,OAAO,EACL,oBAAoB,EAEpB,wBAAwB,EACxB,gBAAgB,EAEhB,gBAAgB,EAChB,YAAY,EACb,MAAM,QAAQ,CAAA;AAEf,UAAU,cAAc;IACtB,0BAA0B,CAAC,EAAE,OAAO,CAAA;IACpC,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;CACnB;AAED,qBAAa,qBAAqB;IAChC,OAAO,CAAC,MAAM,CAAC,cAAc,CAA8C;IAC3E,OAAO,CAAC,MAAM,CAAC,aAAa,CAE3B;IAED,OAAO,CAAC,KAAK,CAAc;IAC3B,OAAO,CAAC,YAAY,CAAoB;IACxC,OAAO,CAAC,OAAO,CAA4B;IAC3C,OAAO,CAAC,OAAO,CAAqB;IAEpC,OAAO,CAAC,gBAAgB,CAAoD;IAC5E,OAAO,CAAC,UAAU,CAAqC;IACvD,OAAO,CAAC,OAAO,CAAwB;WAEzB,kBAAkB,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,oBAAoB;gBAI5D,EACV,KAAK,EACL,YAAY,EACZ,OAAO,EACP,OAAO,GACR,EAAE;QACD,KAAK,EAAE,YAAY,CAAA;QACnB,YAAY,EAAE,gBAAgB,EAAE,CAAA;QAChC,OAAO,EAAE,wBAAwB,EAAE,CAAA;QACnC,OAAO,EAAE,cAAc,CAAA;KACxB;IAiCD,OAAO,CAAC,aAAa;IAQrB,OAAO,CAAC,WAAW;IAKZ,cAAc;IA6DrB,OAAO,CAAC,cAAc;IA8Cf,UAAU,IAAI,eAAe;IAgB7B,eAAe,IAAI,YAAY;CAGvC;AAED,wBAAgB,oBAAoB,CAAC,EACnC,KAAK,EACL,YAAiB,EACjB,OAAY,EACZ,OAAY,GACb,EAAE;IACD,KAAK,EAAE,YAAY,CAAA;IACnB,YAAY,CAAC,EAAE,gBAAgB,EAAE,CAAA;IACjC,OAAO,CAAC,EAAE,gBAAgB,EAAE,CAAA;IAC5B,OAAO,CAAC,EAAE,cAAc,CAAA;CACzB;;;EAaA"}
@@ -7,24 +7,36 @@ class OrderChangeProcessing {
7
7
  static registerActionType(key, type) {
8
8
  OrderChangeProcessing.typeDefinition[key] = type;
9
9
  }
10
- constructor({ order, transactions, actions, }) {
10
+ constructor({ order, transactions, actions, options, }) {
11
+ this.options = {};
11
12
  this.actionsProcessed = {};
12
13
  this.groupTotal = {};
13
14
  this.order = JSON.parse(JSON.stringify(order));
14
15
  this.transactions = JSON.parse(JSON.stringify(transactions ?? []));
15
16
  this.actions = JSON.parse(JSON.stringify(actions ?? []));
16
- const transactionTotal = utils_1.MathBN.add(...transactions.map((tr) => tr.amount));
17
+ this.options = options;
18
+ let paid = utils_1.MathBN.convert(0);
19
+ let refunded = utils_1.MathBN.convert(0);
20
+ let transactionTotal = utils_1.MathBN.convert(0);
21
+ for (const tr of transactions) {
22
+ if (utils_1.MathBN.lt(tr.amount, 0)) {
23
+ refunded = utils_1.MathBN.add(refunded, utils_1.MathBN.abs(tr.amount));
24
+ }
25
+ else {
26
+ paid = utils_1.MathBN.add(paid, tr.amount);
27
+ }
28
+ transactionTotal = utils_1.MathBN.add(transactionTotal, tr.amount);
29
+ }
17
30
  (0, utils_1.transformPropertiesToBigNumber)(this.order.metadata);
18
31
  this.summary = {
19
- futureDifference: 0,
20
- futureTemporaryDifference: 0,
21
- temporaryDifference: 0,
22
- pendingDifference: 0,
23
- futureTemporarySum: 0,
24
- differenceSum: 0,
25
- currentOrderTotal: this.order.total ?? 0,
26
- originalOrderTotal: this.order.total ?? 0,
27
- transactionTotal,
32
+ temporary_difference: 0,
33
+ pending_difference: 0,
34
+ difference_sum: 0,
35
+ current_order_total: this.order.total ?? 0,
36
+ original_order_total: this.order.total ?? 0,
37
+ transaction_total: transactionTotal,
38
+ paid_total: paid,
39
+ refunded_total: refunded,
28
40
  };
29
41
  }
30
42
  isEventActive(action) {
@@ -37,12 +49,7 @@ class OrderChangeProcessing {
37
49
  const status = action.status;
38
50
  return status === _types_1.EVENT_STATUS.DONE;
39
51
  }
40
- isEventPending(action) {
41
- const status = action.status;
42
- return status === undefined || status === _types_1.EVENT_STATUS.PENDING;
43
- }
44
52
  processActions() {
45
- var _a, _b;
46
53
  for (const action of this.actions) {
47
54
  this.processAction_(action);
48
55
  }
@@ -56,59 +63,46 @@ class OrderChangeProcessing {
56
63
  ...OrderChangeProcessing.typeDefinition[action.action],
57
64
  };
58
65
  const amount = utils_1.MathBN.mult(action.amount, type.isDeduction ? -1 : 1);
59
- if (action.group_id && !action.evaluationOnly) {
60
- (_a = this.groupTotal)[_b = action.group_id] ?? (_a[_b] = 0);
61
- this.groupTotal[action.group_id] = utils_1.MathBN.add(this.groupTotal[action.group_id], amount);
66
+ if (action.change_id) {
67
+ this.groupTotal[action.change_id] ??= 0;
68
+ this.groupTotal[action.change_id] = utils_1.MathBN.add(this.groupTotal[action.change_id], amount);
62
69
  }
63
- if (type.awaitRequired && !this.isEventDone(action)) {
64
- if (action.evaluationOnly) {
65
- summary.futureTemporarySum = utils_1.MathBN.add(summary.futureTemporarySum, amount);
66
- }
67
- else {
68
- summary.temporaryDifference = utils_1.MathBN.add(summary.temporaryDifference, amount);
69
- }
70
+ if (type.awaitRequired) {
71
+ summary.temporary_difference = utils_1.MathBN.add(summary.temporary_difference, amount);
70
72
  }
71
- if (action.evaluationOnly) {
72
- summary.futureDifference = utils_1.MathBN.add(summary.futureDifference, amount);
73
- }
74
- else {
75
- if (!this.isEventDone(action) && !action.group_id) {
76
- summary.differenceSum = utils_1.MathBN.add(summary.differenceSum, amount);
77
- }
78
- summary.currentOrderTotal = utils_1.MathBN.add(summary.currentOrderTotal, amount);
73
+ if (!this.isEventDone(action) && !action.change_id) {
74
+ summary.difference_sum = utils_1.MathBN.add(summary.difference_sum, amount);
79
75
  }
76
+ summary.current_order_total = utils_1.MathBN.add(summary.current_order_total, amount);
80
77
  }
81
78
  const groupSum = utils_1.MathBN.add(...Object.values(this.groupTotal));
82
- summary.differenceSum = utils_1.MathBN.add(summary.differenceSum, groupSum);
83
- summary.transactionTotal = utils_1.MathBN.sum(...this.transactions.map((tr) => tr.amount));
84
- summary.futureTemporaryDifference = utils_1.MathBN.sub(summary.futureDifference, summary.futureTemporarySum);
85
- summary.temporaryDifference = utils_1.MathBN.sub(summary.differenceSum, summary.temporaryDifference);
86
- summary.pendingDifference = utils_1.MathBN.sub(summary.currentOrderTotal, summary.transactionTotal);
79
+ summary.difference_sum = utils_1.MathBN.add(summary.difference_sum, groupSum);
80
+ summary.transaction_total = utils_1.MathBN.sum(...this.transactions.map((tr) => tr.amount));
81
+ summary.temporary_difference = utils_1.MathBN.sub(summary.difference_sum, summary.temporary_difference);
82
+ summary.pending_difference = utils_1.MathBN.sub(summary.current_order_total, summary.transaction_total);
87
83
  }
88
84
  processAction_(action, isReplay = false) {
89
- var _a, _b, _c;
85
+ const definedType = OrderChangeProcessing.typeDefinition[action.action];
86
+ if (!(0, utils_1.isPresent)(definedType)) {
87
+ throw new Error(`Action type ${action.action} is not defined`);
88
+ }
90
89
  const type = {
91
90
  ...OrderChangeProcessing.defaultConfig,
92
- ...OrderChangeProcessing.typeDefinition[action.action],
91
+ ...definedType,
93
92
  };
94
- (_a = this.actionsProcessed)[_b = action.action] ?? (_a[_b] = []);
93
+ this.actionsProcessed[action.action] ??= [];
95
94
  if (!isReplay) {
96
95
  this.actionsProcessed[action.action].push(action);
97
96
  }
98
- let previousEvents;
99
- if (type.commitsAction) {
100
- previousEvents = (this.actionsProcessed[type.commitsAction] ?? []).filter((ac_) => ac_.reference_id === action.reference_id &&
101
- ac_.status !== _types_1.EVENT_STATUS.VOIDED);
102
- }
103
97
  let calculatedAmount = action.amount ?? 0;
104
98
  const params = {
105
99
  actions: this.actions,
106
100
  action,
107
- previousEvents,
108
101
  currentOrder: this.order,
109
102
  summary: this.summary,
110
103
  transactions: this.transactions,
111
104
  type,
105
+ options: this.options,
112
106
  };
113
107
  if (typeof type.validate === "function") {
114
108
  type.validate(params);
@@ -120,143 +114,20 @@ class OrderChangeProcessing {
120
114
  action.amount = calculatedAmount ?? 0;
121
115
  }
122
116
  }
123
- // If an action commits previous ones, replay them with updated values
124
- if (type.commitsAction) {
125
- for (const previousEvent of previousEvents ?? []) {
126
- this.processAction_(previousEvent, true);
127
- }
128
- }
129
- if (action.resolve) {
130
- if (action.resolve.reference_id) {
131
- this.resolveReferences(action);
132
- }
133
- const groupId = action.resolve.group_id ?? "__default";
134
- if (action.resolve.group_id) {
135
- // resolve all actions in the same group
136
- this.resolveGroup(action);
137
- }
138
- if (action.resolve.amount && !action.evaluationOnly) {
139
- (_c = this.groupTotal)[groupId] ?? (_c[groupId] = 0);
140
- this.groupTotal[groupId] = utils_1.MathBN.sub(this.groupTotal[groupId], action.resolve.amount);
141
- }
142
- }
143
117
  return calculatedAmount;
144
118
  }
145
- resolveReferences(self) {
146
- const resolve = self.resolve;
147
- const resolveType = OrderChangeProcessing.typeDefinition[self.action];
148
- Object.keys(this.actionsProcessed).forEach((actionKey) => {
149
- const type = OrderChangeProcessing.typeDefinition[actionKey];
150
- const actions = this.actionsProcessed[actionKey];
151
- for (const action of actions) {
152
- if (action === self ||
153
- !this.isEventPending(action) ||
154
- action.reference_id !== resolve?.reference_id) {
155
- continue;
156
- }
157
- if (type.revert && (action.evaluationOnly || resolveType.void)) {
158
- let previousEvents;
159
- if (type.commitsAction) {
160
- previousEvents = (this.actionsProcessed[type.commitsAction] ?? []).filter((ac_) => ac_.reference_id === action.reference_id &&
161
- ac_.status !== _types_1.EVENT_STATUS.VOIDED);
162
- }
163
- type.revert({
164
- actions: this.actions,
165
- action,
166
- previousEvents,
167
- currentOrder: this.order,
168
- summary: this.summary,
169
- transactions: this.transactions,
170
- type,
171
- });
172
- for (const previousEvent of previousEvents ?? []) {
173
- this.processAction_(previousEvent, true);
174
- }
175
- action.status =
176
- action.evaluationOnly || resolveType.void
177
- ? _types_1.EVENT_STATUS.VOIDED
178
- : _types_1.EVENT_STATUS.DONE;
179
- }
180
- }
181
- });
182
- }
183
- resolveGroup(self) {
184
- const resolve = self.resolve;
185
- Object.keys(this.actionsProcessed).forEach((actionKey) => {
186
- const type = OrderChangeProcessing.typeDefinition[actionKey];
187
- const actions = this.actionsProcessed[actionKey];
188
- for (const action of actions) {
189
- if (!resolve?.group_id || action?.group_id !== resolve.group_id) {
190
- continue;
191
- }
192
- if (type.revert &&
193
- action.status !== _types_1.EVENT_STATUS.DONE &&
194
- action.status !== _types_1.EVENT_STATUS.VOIDED &&
195
- (action.evaluationOnly || type.void)) {
196
- let previousEvents;
197
- if (type.commitsAction) {
198
- previousEvents = (this.actionsProcessed[type.commitsAction] ?? []).filter((ac_) => ac_.reference_id === action.reference_id &&
199
- ac_.status !== _types_1.EVENT_STATUS.VOIDED);
200
- }
201
- type.revert({
202
- actions: this.actions,
203
- action: action,
204
- previousEvents,
205
- currentOrder: this.order,
206
- summary: this.summary,
207
- transactions: this.transactions,
208
- type: OrderChangeProcessing.typeDefinition[action.action],
209
- });
210
- for (const previousEvent of previousEvents ?? []) {
211
- this.processAction_(previousEvent, true);
212
- }
213
- action.status =
214
- action.evaluationOnly || type.void
215
- ? _types_1.EVENT_STATUS.VOIDED
216
- : _types_1.EVENT_STATUS.DONE;
217
- }
218
- }
219
- });
220
- }
221
119
  getSummary() {
222
120
  const summary = this.summary;
223
121
  const orderSummary = {
224
- transactionTotal: new utils_1.BigNumber(summary.transactionTotal),
225
- originalOrderTotal: new utils_1.BigNumber(summary.originalOrderTotal),
226
- currentOrderTotal: new utils_1.BigNumber(summary.currentOrderTotal),
227
- temporaryDifference: new utils_1.BigNumber(summary.temporaryDifference),
228
- futureDifference: new utils_1.BigNumber(summary.futureDifference),
229
- futureTemporaryDifference: new utils_1.BigNumber(summary.futureTemporaryDifference),
230
- pendingDifference: new utils_1.BigNumber(summary.pendingDifference),
231
- differenceSum: new utils_1.BigNumber(summary.differenceSum),
122
+ transaction_total: new utils_1.BigNumber(summary.transaction_total),
123
+ original_order_total: new utils_1.BigNumber(summary.original_order_total),
124
+ current_order_total: new utils_1.BigNumber(summary.current_order_total),
125
+ temporary_difference: new utils_1.BigNumber(summary.temporary_difference),
126
+ pending_difference: new utils_1.BigNumber(summary.pending_difference),
127
+ difference_sum: new utils_1.BigNumber(summary.difference_sum),
128
+ paid_total: new utils_1.BigNumber(summary.paid_total),
129
+ refunded_total: new utils_1.BigNumber(summary.refunded_total),
232
130
  };
233
- /*
234
- {
235
- total: summary.currentOrderTotal
236
-
237
- subtotal: number
238
- total_tax: number
239
-
240
- ordered_total: summary.originalOrderTotal
241
- fulfilled_total: number
242
- returned_total: number
243
- return_request_total: number
244
- write_off_total: number
245
- projected_total: number
246
-
247
- net_total: number
248
- net_subtotal: number
249
- net_total_tax: number
250
-
251
- future_total: number
252
- future_subtotal: number
253
- future_total_tax: number
254
- future_projected_total: number
255
-
256
- balance: summary.pendingDifference
257
- future_balance: number
258
- }
259
- */
260
131
  return orderSummary;
261
132
  }
262
133
  getCurrentOrder() {
@@ -266,11 +137,15 @@ class OrderChangeProcessing {
266
137
  exports.OrderChangeProcessing = OrderChangeProcessing;
267
138
  OrderChangeProcessing.typeDefinition = {};
268
139
  OrderChangeProcessing.defaultConfig = {
269
- awaitRequired: false,
270
140
  isDeduction: false,
271
141
  };
272
- function calculateOrderChange({ order, transactions = [], actions = [], }) {
273
- const calc = new OrderChangeProcessing({ order, transactions, actions });
142
+ function calculateOrderChange({ order, transactions = [], actions = [], options = {}, }) {
143
+ const calc = new OrderChangeProcessing({
144
+ order,
145
+ transactions,
146
+ actions,
147
+ options,
148
+ });
274
149
  calc.processActions();
275
150
  return {
276
151
  summary: calc.getSummary(),
@@ -1 +1 @@
1
- {"version":3,"file":"calculate-order-change.js","sourceRoot":"","sources":["../../src/utils/calculate-order-change.ts"],"names":[],"mappings":";;;AACA,2CAKwB;AACxB,mCAQe;AAMf,MAAa,qBAAqB;IAezB,MAAM,CAAC,kBAAkB,CAAC,GAAW,EAAE,IAA0B;QACtE,qBAAqB,CAAC,cAAc,CAAC,GAAG,CAAC,GAAG,IAAI,CAAA;IAClD,CAAC;IAED,YAAY,EACV,KAAK,EACL,YAAY,EACZ,OAAO,GAKR;QAhBO,qBAAgB,GAAkD,EAAE,CAAA;QACpE,eAAU,GAAmC,EAAE,CAAA;QAgBrD,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,CAAA;QAC9C,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,YAAY,IAAI,EAAE,CAAC,CAAC,CAAA;QAClE,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,OAAO,IAAI,EAAE,CAAC,CAAC,CAAA;QAExD,MAAM,gBAAgB,GAAG,cAAM,CAAC,GAAG,C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,OAAO,CAAC,oBAAoB,CAAC;YACjE,kBAAkB,EAAE,IAAI,iBAAS,CAAC,OAAO,CAAC,kBAAkB,CAAC;YAC7D,cAAc,EAAE,IAAI,iBAAS,CAAC,OAAO,CAAC,cAAc,CAAC;YACrD,UAAU,EAAE,IAAI,iBAAS,CAAC,OAAO,CAAC,UAAU,CAAC;YAC7C,cAAc,EAAE,IAAI,iBAAS,CAAC,OAAO,CAAC,cAAc,CAAC;SACxB,CAAA;QAE/B,OAAO,YAAY,CAAA;IACrB,CAAC;IAEM,eAAe;QACpB,OAAO,IAAI,CAAC,KAAK,CAAA;IACnB,CAAC;;AAxMH,sDAyMC;AAxMgB,oCAAc,GAA4C,EAAE,AAA9C,CAA8C;AAC5D,mCAAa,GAAG;IAC7B,WAAW,EAAE,KAAK;CACnB,AAF2B,CAE3B;AAuMH,SAAgB,oBAAoB,CAAC,EACnC,KAAK,EACL,YAAY,GAAG,EAAE,EACjB,OAAO,GAAG,EAAE,EACZ,OAAO,GAAG,EAAE,GAMb;IACC,MAAM,IAAI,GAAG,IAAI,qBAAqB,CAAC;QACrC,KAAK;QACL,YAAY;QACZ,OAAO;QACP,OAAO;KACR,CAAC,CAAA;IACF,IAAI,CAAC,cAAc,EAAE,CAAA;IAErB,OAAO;QACL,OAAO,EAAE,IAAI,CAAC,UAAU,EAAE;QAC1B,KAAK,EAAE,IAAI,CAAC,eAAe,EAAE;KAC9B,CAAA;AACH,CAAC;AAvBD,oDAuBC"}
@@ -1,3 +1,6 @@
1
- export * from "./action-key";
2
1
  export * from "./actions";
2
+ export * from "./apply-order-changes";
3
3
  export * from "./calculate-order-change";
4
+ export * from "./set-action-reference";
5
+ export * from "./transform-order";
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAA;AACzB,cAAc,uBAAuB,CAAA;AACrC,cAAc,0BAA0B,CAAA;AACxC,cAAc,wBAAwB,CAAA;AACtC,cAAc,mBAAmB,CAAA"}
@@ -14,7 +14,9 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./action-key"), exports);
18
17
  __exportStar(require("./actions"), exports);
18
+ __exportStar(require("./apply-order-changes"), exports);
19
19
  __exportStar(require("./calculate-order-change"), exports);
20
+ __exportStar(require("./set-action-reference"), exports);
21
+ __exportStar(require("./transform-order"), exports);
20
22
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,+CAA4B;AAC5B,4CAAyB;AACzB,2DAAwC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,4CAAyB;AACzB,wDAAqC;AACrC,2DAAwC;AACxC,yDAAsC;AACtC,oDAAiC"}
@@ -0,0 +1,2 @@
1
+ export declare function setActionReference(existing: any, action: any, options: any): void;
2
+ //# sourceMappingURL=set-action-reference.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"set-action-reference.d.ts","sourceRoot":"","sources":["../../src/utils/set-action-reference.ts"],"names":[],"mappings":"AAAA,wBAAgB,kBAAkB,CAAC,QAAQ,KAAA,EAAE,MAAM,KAAA,EAAE,OAAO,KAAA,QAK3D"}
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.setActionReference = void 0;
4
+ function setActionReference(existing, action, options) {
5
+ if (options?.addActionReferenceToObject) {
6
+ existing.actions ??= [];
7
+ existing.actions.push(action);
8
+ }
9
+ }
10
+ exports.setActionReference = setActionReference;
11
+ //# sourceMappingURL=set-action-reference.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"set-action-reference.js","sourceRoot":"","sources":["../../src/utils/set-action-reference.ts"],"names":[],"mappings":";;;AAAA,SAAgB,kBAAkB,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO;IAC1D,IAAI,OAAO,EAAE,0BAA0B,EAAE,CAAC;QACxC,QAAQ,CAAC,OAAO,KAAK,EAAE,CAAA;QACvB,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;IAC/B,CAAC;AACH,CAAC;AALD,gDAKC"}
@@ -1,5 +1,7 @@
1
1
  import { OrderTypes } from "@medusajs/types";
2
2
  export declare function formatOrder(order: any, options: {
3
+ entity: any;
3
4
  includeTotals?: boolean;
4
- }): OrderTypes.OrderDTO | OrderTypes.OrderDTO[];
5
- export declare function mapRepositoryToOrderModel(config: any): any;
5
+ }): Partial<OrderTypes.OrderDTO> | Partial<OrderTypes.OrderDTO>[];
6
+ export declare function mapRepositoryToOrderModel(config: any, isRelatedEntity?: boolean): any;
7
+ //# sourceMappingURL=transform-order.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transform-order.d.ts","sourceRoot":"","sources":["../../src/utils/transform-order.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAU5C,wBAAgB,WAAW,CACzB,KAAK,KAAA,EACL,OAAO,EAAE;IACP,MAAM,EAAE,GAAG,CAAA;IACX,aAAa,CAAC,EAAE,OAAO,CAAA;CACxB,GACA,OAAO,CAAC,UAAU,CAAC,QAAQ,CAAC,GAAG,OAAO,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE,CAkF/D;AAmFD,wBAAgB,yBAAyB,CAAC,MAAM,KAAA,EAAE,eAAe,UAAQ,OAwExE"}
@@ -2,11 +2,26 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.mapRepositoryToOrderModel = exports.formatOrder = void 0;
4
4
  const utils_1 = require("@medusajs/utils");
5
+ // Reshape the order object to match the OrderDTO
6
+ // This function is used to format the order object before returning to the main module methods
5
7
  function formatOrder(order, options) {
6
8
  const isArray = Array.isArray(order);
7
9
  const orders = [...(isArray ? order : [order])];
8
10
  orders.map((order) => {
9
- order.items = order.items?.map((orderItem) => {
11
+ let mainOrder = order;
12
+ const isRelatedEntity = options?.entity?.name !== "Order";
13
+ // If the entity is a related entity, the original order is located in the order property
14
+ if (isRelatedEntity) {
15
+ if (!order.order) {
16
+ return order;
17
+ }
18
+ mainOrder = order.order;
19
+ }
20
+ mainOrder.items = mainOrder.items?.map((orderItem) => {
21
+ const isFormatted = (0, utils_1.isDefined)(orderItem.detail?.fulfilled_quantity);
22
+ if (isFormatted) {
23
+ return orderItem;
24
+ }
10
25
  const detail = { ...orderItem };
11
26
  delete detail.order;
12
27
  delete detail.item;
@@ -17,26 +32,105 @@ function formatOrder(order, options) {
17
32
  detail,
18
33
  };
19
34
  });
20
- order.shipping_methods = order.shipping_methods?.map((shippingMethod) => {
21
- const sm = { ...shippingMethod.shipping_method };
22
- delete shippingMethod.shipping_method;
23
- return {
24
- ...sm,
25
- order_id: shippingMethod.order_id,
26
- detail: {
27
- ...shippingMethod,
28
- },
29
- };
30
- });
31
- order.summary = order.summary?.[0]?.totals;
32
- return options?.includeTotals
33
- ? (0, utils_1.createRawPropertiesFromBigNumber)((0, utils_1.decorateCartTotals)(order))
34
- : order;
35
+ if (isRelatedEntity) {
36
+ if (order.return) {
37
+ formatOrderReturn(order.return, mainOrder);
38
+ }
39
+ const entityName = options.entity.name;
40
+ if (entityName === "OrderClaim") {
41
+ formatClaim(order);
42
+ }
43
+ else if (entityName === "OrderExchange") {
44
+ formatExchange(order);
45
+ }
46
+ else if (entityName === "Return") {
47
+ formatReturn(order);
48
+ }
49
+ }
50
+ if (order.shipping_methods) {
51
+ order.shipping_methods = order.shipping_methods?.map((shippingMethod) => {
52
+ if (shippingMethod.detail) {
53
+ return shippingMethod;
54
+ }
55
+ const sm = { ...shippingMethod.shipping_method };
56
+ delete shippingMethod.shipping_method;
57
+ cleanNestedRelations(shippingMethod);
58
+ return {
59
+ ...sm,
60
+ order_id: shippingMethod.order_id,
61
+ detail: {
62
+ ...shippingMethod,
63
+ },
64
+ };
65
+ });
66
+ }
67
+ if (mainOrder.summary) {
68
+ mainOrder.summary = mainOrder.summary?.[0]?.totals;
69
+ }
70
+ return (0, utils_1.createRawPropertiesFromBigNumber)(options?.includeTotals ? (0, utils_1.decorateCartTotals)(order) : order);
35
71
  });
36
72
  return isArray ? orders : orders[0];
37
73
  }
38
74
  exports.formatOrder = formatOrder;
39
- function mapRepositoryToOrderModel(config) {
75
+ function cleanNestedRelations(obj) {
76
+ delete obj.order;
77
+ delete obj.return;
78
+ delete obj.claim;
79
+ delete obj.exchange;
80
+ }
81
+ function formatOrderReturn(orderReturn, mainOrder) {
82
+ orderReturn.items?.forEach((orderItem) => {
83
+ const item = mainOrder.items?.find((item) => item.id === orderItem.item_id);
84
+ orderItem.detail = item?.detail;
85
+ });
86
+ }
87
+ function formatClaim(claim) {
88
+ if (claim.additional_items) {
89
+ claim.additional_items = claim.additional_items.filter((item) => item.is_additional_item);
90
+ claim.additional_items.forEach((orderItem) => {
91
+ const item = claim.order.items?.find((item) => item.id === orderItem.item_id);
92
+ cleanNestedRelations(item);
93
+ orderItem.detail = item?.detail;
94
+ });
95
+ }
96
+ if (!claim.claim_items) {
97
+ return;
98
+ }
99
+ claim.claim_items = claim.claim_items.filter((item) => !item.is_additional_item);
100
+ claim.claim_items.forEach((orderItem) => {
101
+ const item = claim.order.items?.find((item) => item.id === orderItem.item_id);
102
+ cleanNestedRelations(item);
103
+ orderItem.detail = item?.detail;
104
+ });
105
+ }
106
+ function formatExchange(exchange) {
107
+ if (!exchange.additional_items) {
108
+ return;
109
+ }
110
+ exchange.additional_items.forEach((orderItem) => {
111
+ const item = exchange.order.items?.find((item) => item.id === orderItem.item_id);
112
+ cleanNestedRelations(item);
113
+ orderItem.detail = item?.detail;
114
+ });
115
+ }
116
+ function formatReturn(returnOrder) {
117
+ if (!returnOrder.items) {
118
+ return;
119
+ }
120
+ returnOrder.items.forEach((orderItem) => {
121
+ const item = returnOrder.order.items?.find((item) => item.id === orderItem.item_id);
122
+ cleanNestedRelations(item);
123
+ orderItem.detail = item?.detail;
124
+ });
125
+ }
126
+ // Map the public order model to the repository model format
127
+ // As the public responses have a different shape than the repository responses, this function is used to map the public properties to the internal db entities
128
+ // e.g "items" is the relation between "line-item" and "order" + "version", The line item itself is in "items.item"
129
+ // This helper maps to the correct repository to query the DB, and the function "formatOrder" remap the response to the public shape
130
+ function mapRepositoryToOrderModel(config, isRelatedEntity = false) {
131
+ if (isRelatedEntity) {
132
+ return mapRepositoryToRelatedEntity(config);
133
+ }
40
134
  const conf = { ...config };
41
135
  function replace(obj, type) {
42
136
  if (!(0, utils_1.isDefined)(obj[type])) {
@@ -94,4 +188,24 @@ function mapRepositoryToOrderModel(config) {
94
188
  return conf;
95
189
  }
96
190
  exports.mapRepositoryToOrderModel = mapRepositoryToOrderModel;
191
+ // This function has the same purpose as "mapRepositoryToOrderModel" but for returns, claims and exchanges
192
+ function mapRepositoryToRelatedEntity(config) {
193
+ const conf = { ...config };
194
+ function replace(obj, type) {
195
+ if (!(0, utils_1.isDefined)(obj[type])) {
196
+ return;
197
+ }
198
+ return (0, utils_1.deduplicate)(obj[type].sort().map((rel) => {
199
+ if (rel.includes("shipping_methods") &&
200
+ !rel.includes("shipping_methods.shipping_method")) {
201
+ obj.populate.push("shipping_methods.shipping_method");
202
+ return rel.replace("shipping_methods", "shipping_methods.shipping_method");
203
+ }
204
+ return rel;
205
+ }));
206
+ }
207
+ conf.options.fields = replace(config.options, "fields");
208
+ conf.options.populate = replace(config.options, "populate");
209
+ return conf;
210
+ }
97
211
  //# sourceMappingURL=transform-order.js.map