@medusajs/order 0.1.3-snapshot-20240607093839 → 0.1.3-snapshot-20240701122250

Sign up to get free protection for your applications and to get access to all the features.
Files changed (179) hide show
  1. package/dist/index.d.ts +2 -1
  2. package/dist/index.js +7 -2
  3. package/dist/index.js.map +1 -1
  4. package/dist/joiner-config.d.ts +1 -3
  5. package/dist/joiner-config.js +4 -42
  6. package/dist/joiner-config.js.map +1 -1
  7. package/dist/migrations/Migration20240604100512.d.ts +4 -0
  8. package/dist/migrations/Migration20240604100512.js +364 -0
  9. package/dist/migrations/Migration20240604100512.js.map +1 -0
  10. package/dist/models/claim-item-image.d.ts +18 -0
  11. package/dist/models/claim-item-image.js +108 -0
  12. package/dist/models/claim-item-image.js.map +1 -0
  13. package/dist/models/claim-item.d.ts +28 -0
  14. package/dist/models/claim-item.js +156 -0
  15. package/dist/models/claim-item.js.map +1 -0
  16. package/dist/models/claim.d.ts +35 -0
  17. package/dist/models/claim.js +196 -0
  18. package/dist/models/claim.js.map +1 -0
  19. package/dist/models/exchange-item.d.ts +23 -0
  20. package/dist/models/exchange-item.js +138 -0
  21. package/dist/models/exchange-item.js.map +1 -0
  22. package/dist/models/exchange.d.ts +33 -0
  23. package/dist/models/exchange.js +189 -0
  24. package/dist/models/exchange.js.map +1 -0
  25. package/dist/models/index.d.ts +7 -0
  26. package/dist/models/index.js +15 -1
  27. package/dist/models/index.js.map +1 -1
  28. package/dist/models/line-item-adjustment.d.ts +2 -1
  29. package/dist/models/line-item-adjustment.js +1 -1
  30. package/dist/models/line-item-adjustment.js.map +1 -1
  31. package/dist/models/line-item-tax-line.d.ts +2 -1
  32. package/dist/models/line-item-tax-line.js +1 -1
  33. package/dist/models/line-item-tax-line.js.map +1 -1
  34. package/dist/models/line-item.d.ts +1 -1
  35. package/dist/models/line-item.js +3 -3
  36. package/dist/models/line-item.js.map +1 -1
  37. package/dist/models/order-change-action.d.ts +13 -3
  38. package/dist/models/order-change-action.js +94 -0
  39. package/dist/models/order-change-action.js.map +1 -1
  40. package/dist/models/order-change.d.ts +14 -3
  41. package/dist/models/order-change.js +107 -3
  42. package/dist/models/order-change.js.map +1 -1
  43. package/dist/models/order-item.d.ts +3 -3
  44. package/dist/models/order-item.js +7 -7
  45. package/dist/models/order-item.js.map +1 -1
  46. package/dist/models/order-shipping-method.d.ts +12 -3
  47. package/dist/models/order-shipping-method.js +83 -7
  48. package/dist/models/order-shipping-method.js.map +1 -1
  49. package/dist/models/order-summary.d.ts +3 -2
  50. package/dist/models/order-summary.js +7 -4
  51. package/dist/models/order-summary.js.map +1 -1
  52. package/dist/models/order.d.ts +3 -3
  53. package/dist/models/order.js +1 -1
  54. package/dist/models/order.js.map +1 -1
  55. package/dist/models/return-item.d.ts +28 -0
  56. package/dist/models/return-item.js +170 -0
  57. package/dist/models/return-item.js.map +1 -0
  58. package/dist/models/return-reason.d.ts +3 -3
  59. package/dist/models/return-reason.js.map +1 -1
  60. package/dist/models/return.d.ts +38 -0
  61. package/dist/models/return.js +213 -0
  62. package/dist/models/return.js.map +1 -0
  63. package/dist/models/shipping-method-adjustment.d.ts +2 -1
  64. package/dist/models/shipping-method-adjustment.js +1 -1
  65. package/dist/models/shipping-method-adjustment.js.map +1 -1
  66. package/dist/models/shipping-method-tax-line.d.ts +2 -1
  67. package/dist/models/shipping-method-tax-line.js +1 -1
  68. package/dist/models/shipping-method-tax-line.js.map +1 -1
  69. package/dist/models/shipping-method.js +1 -1
  70. package/dist/models/shipping-method.js.map +1 -1
  71. package/dist/models/tax-line.js.map +1 -1
  72. package/dist/models/transaction.d.ts +11 -2
  73. package/dist/models/transaction.js +80 -1
  74. package/dist/models/transaction.js.map +1 -1
  75. package/dist/repositories/claim.d.ts +8 -0
  76. package/dist/repositories/claim.js +11 -0
  77. package/dist/repositories/claim.js.map +1 -0
  78. package/dist/repositories/exchange.d.ts +8 -0
  79. package/dist/repositories/exchange.js +11 -0
  80. package/dist/repositories/exchange.js.map +1 -0
  81. package/dist/repositories/index.d.ts +3 -1
  82. package/dist/repositories/index.js +7 -16
  83. package/dist/repositories/index.js.map +1 -1
  84. package/dist/repositories/order.d.ts +0 -3
  85. package/dist/repositories/order.js +2 -83
  86. package/dist/repositories/order.js.map +1 -1
  87. package/dist/repositories/return.d.ts +8 -0
  88. package/dist/repositories/return.js +11 -0
  89. package/dist/repositories/return.js.map +1 -0
  90. package/dist/services/actions/cancel-fulfillment.d.ts +2 -0
  91. package/dist/services/actions/cancel-fulfillment.js +32 -0
  92. package/dist/services/actions/cancel-fulfillment.js.map +1 -0
  93. package/dist/services/actions/create-claim.d.ts +2 -0
  94. package/dist/services/actions/create-claim.js +229 -0
  95. package/dist/services/actions/create-claim.js.map +1 -0
  96. package/dist/services/actions/create-exchange.d.ts +2 -0
  97. package/dist/services/actions/create-exchange.js +194 -0
  98. package/dist/services/actions/create-exchange.js.map +1 -0
  99. package/dist/services/actions/create-return.d.ts +2 -0
  100. package/dist/services/actions/create-return.js +98 -0
  101. package/dist/services/actions/create-return.js.map +1 -0
  102. package/dist/services/actions/index.d.ts +7 -0
  103. package/dist/services/actions/index.js +24 -0
  104. package/dist/services/actions/index.js.map +1 -0
  105. package/dist/services/actions/receive-return.d.ts +2 -0
  106. package/dist/services/actions/receive-return.js +75 -0
  107. package/dist/services/actions/receive-return.js.map +1 -0
  108. package/dist/services/actions/register-fulfillment.d.ts +2 -0
  109. package/dist/services/actions/register-fulfillment.js +30 -0
  110. package/dist/services/actions/register-fulfillment.js.map +1 -0
  111. package/dist/services/actions/register-shipment.d.ts +2 -0
  112. package/dist/services/actions/register-shipment.js +38 -0
  113. package/dist/services/actions/register-shipment.js.map +1 -0
  114. package/dist/services/order-change-service.d.ts +6 -6
  115. package/dist/services/order-change-service.js +4 -3
  116. package/dist/services/order-change-service.js.map +1 -1
  117. package/dist/services/order-module-service.d.ts +101 -64
  118. package/dist/services/order-module-service.js +458 -295
  119. package/dist/services/order-module-service.js.map +1 -1
  120. package/dist/services/order-service.d.ts +4 -4
  121. package/dist/services/order-service.js +1 -1
  122. package/dist/services/order-service.js.map +1 -1
  123. package/dist/types/index.d.ts +1 -0
  124. package/dist/types/index.js +1 -0
  125. package/dist/types/index.js.map +1 -1
  126. package/dist/types/order-change.d.ts +32 -0
  127. package/dist/types/order-change.js +34 -0
  128. package/dist/types/order-change.js.map +1 -0
  129. package/dist/types/utils/index.d.ts +25 -1
  130. package/dist/types/utils/index.js.map +1 -1
  131. package/dist/utils/actions/cancel-item-fulfillment.js +2 -0
  132. package/dist/utils/actions/cancel-item-fulfillment.js.map +1 -1
  133. package/dist/utils/actions/cancel-return.js +2 -0
  134. package/dist/utils/actions/cancel-return.js.map +1 -1
  135. package/dist/utils/actions/fulfill-item.js +2 -0
  136. package/dist/utils/actions/fulfill-item.js.map +1 -1
  137. package/dist/utils/actions/index.d.ts +1 -0
  138. package/dist/utils/actions/index.js +1 -0
  139. package/dist/utils/actions/index.js.map +1 -1
  140. package/dist/utils/actions/item-add.js +10 -7
  141. package/dist/utils/actions/item-add.js.map +1 -1
  142. package/dist/utils/actions/item-remove.js +6 -4
  143. package/dist/utils/actions/item-remove.js.map +1 -1
  144. package/dist/utils/actions/receive-damaged-return-item.js +2 -0
  145. package/dist/utils/actions/receive-damaged-return-item.js.map +1 -1
  146. package/dist/utils/actions/receive-return-item.js +2 -0
  147. package/dist/utils/actions/receive-return-item.js.map +1 -1
  148. package/dist/utils/actions/return-item.js +2 -0
  149. package/dist/utils/actions/return-item.js.map +1 -1
  150. package/dist/utils/actions/ship-item.js +2 -0
  151. package/dist/utils/actions/ship-item.js.map +1 -1
  152. package/dist/utils/actions/shipping-add.js +6 -2
  153. package/dist/utils/actions/shipping-add.js.map +1 -1
  154. package/dist/utils/actions/write-off-item.js +2 -0
  155. package/dist/utils/actions/write-off-item.js.map +1 -1
  156. package/dist/utils/apply-order-changes.d.ts +14 -0
  157. package/dist/utils/apply-order-changes.js +74 -0
  158. package/dist/utils/apply-order-changes.js.map +1 -0
  159. package/dist/utils/base-repository-find.d.ts +2 -0
  160. package/dist/utils/base-repository-find.js +117 -0
  161. package/dist/utils/base-repository-find.js.map +1 -0
  162. package/dist/utils/calculate-order-change.js +5 -1
  163. package/dist/utils/calculate-order-change.js.map +1 -1
  164. package/dist/utils/index.d.ts +3 -0
  165. package/dist/utils/index.js +3 -0
  166. package/dist/utils/index.js.map +1 -1
  167. package/dist/utils/set-action-reference.d.ts +1 -0
  168. package/dist/utils/set-action-reference.js +11 -0
  169. package/dist/utils/set-action-reference.js.map +1 -0
  170. package/dist/utils/transform-order.d.ts +3 -2
  171. package/dist/utils/transform-order.js +84 -17
  172. package/dist/utils/transform-order.js.map +1 -1
  173. package/package.json +7 -11
  174. package/dist/module-definition.d.ts +0 -2
  175. package/dist/module-definition.js +0 -9
  176. package/dist/module-definition.js.map +0 -1
  177. package/dist/scripts/bin/run-seed.d.ts +0 -3
  178. package/dist/scripts/bin/run-seed.js +0 -49
  179. package/dist/scripts/bin/run-seed.js.map +0 -1
@@ -1,10 +1,33 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
2
18
  var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
19
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
20
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
21
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
22
  return c > 3 && r && Object.defineProperty(target, key, r), r;
7
23
  };
24
+ var __importStar = (this && this.__importStar) || function (mod) {
25
+ if (mod && mod.__esModule) return mod;
26
+ var result = {};
27
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
28
+ __setModuleDefault(result, mod);
29
+ return result;
30
+ };
8
31
  var __metadata = (this && this.__metadata) || function (k, v) {
9
32
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
33
  };
@@ -15,27 +38,34 @@ Object.defineProperty(exports, "__esModule", { value: true });
15
38
  const types_1 = require("@medusajs/types");
16
39
  const utils_1 = require("@medusajs/utils");
17
40
  const _models_1 = require("../models");
41
+ const _types_1 = require("../types");
18
42
  const joiner_config_1 = require("../joiner-config");
19
43
  const utils_2 = require("../utils");
20
- const transform_order_1 = require("../utils/transform-order");
21
- const generateMethodForModels = [
22
- _models_1.Address,
23
- _models_1.LineItem,
24
- _models_1.LineItemAdjustment,
25
- _models_1.LineItemTaxLine,
26
- _models_1.ShippingMethod,
27
- _models_1.ShippingMethodAdjustment,
28
- _models_1.ShippingMethodTaxLine,
29
- _models_1.Transaction,
30
- _models_1.OrderChange,
31
- _models_1.OrderChangeAction,
32
- _models_1.OrderItem,
33
- _models_1.OrderSummary,
34
- _models_1.OrderShippingMethod,
35
- _models_1.ReturnReason,
36
- ];
37
- class OrderModuleService extends utils_1.ModulesSdkUtils.abstractModuleServiceFactory(_models_1.Order, generateMethodForModels, joiner_config_1.entityNameToLinkableKeysMap) {
38
- constructor({ baseRepository, orderService, addressService, lineItemService, shippingMethodAdjustmentService, shippingMethodService, lineItemAdjustmentService, shippingMethodTaxLineService, lineItemTaxLineService, transactionService, orderChangeService, orderChangeActionService, orderItemService, orderSummaryService, orderShippingMethodService, returnReasonService, }, moduleDeclaration) {
44
+ const BundledActions = __importStar(require("./actions"));
45
+ const generateMethodForModels = {
46
+ Order: _models_1.Order,
47
+ Address: _models_1.Address,
48
+ LineItem: _models_1.LineItem,
49
+ LineItemAdjustment: _models_1.LineItemAdjustment,
50
+ LineItemTaxLine: _models_1.LineItemTaxLine,
51
+ ShippingMethod: _models_1.ShippingMethod,
52
+ ShippingMethodAdjustment: _models_1.ShippingMethodAdjustment,
53
+ ShippingMethodTaxLine: _models_1.ShippingMethodTaxLine,
54
+ Transaction: _models_1.Transaction,
55
+ OrderChange: _models_1.OrderChange,
56
+ OrderChangeAction: _models_1.OrderChangeAction,
57
+ OrderItem: _models_1.OrderItem,
58
+ OrderSummary: _models_1.OrderSummary,
59
+ OrderShippingMethod: _models_1.OrderShippingMethod,
60
+ ReturnReason: _models_1.ReturnReason,
61
+ Return: _models_1.Return,
62
+ ReturnItem: _models_1.ReturnItem,
63
+ OrderClaim: _models_1.OrderClaim,
64
+ OrderExchange: _models_1.OrderExchange,
65
+ };
66
+ // TODO: rm template args here, keep it for later to not collide with carlos work at least as little as possible
67
+ class OrderModuleService extends utils_1.ModulesSdkUtils.MedusaService(generateMethodForModels, joiner_config_1.entityNameToLinkableKeysMap) {
68
+ constructor({ baseRepository, orderService, addressService, lineItemService, shippingMethodAdjustmentService, shippingMethodService, lineItemAdjustmentService, shippingMethodTaxLineService, lineItemTaxLineService, transactionService, orderChangeService, orderChangeActionService, orderItemService, orderSummaryService, orderShippingMethodService, returnReasonService, returnService, returnItemService, orderClaimService, orderExchangeService, }, moduleDeclaration) {
39
69
  // @ts-ignore
40
70
  super(...arguments);
41
71
  this.moduleDeclaration = moduleDeclaration;
@@ -55,6 +85,10 @@ class OrderModuleService extends utils_1.ModulesSdkUtils.abstractModuleServiceFa
55
85
  this.orderSummaryService_ = orderSummaryService;
56
86
  this.orderShippingMethodService_ = orderShippingMethodService;
57
87
  this.returnReasonService_ = returnReasonService;
88
+ this.returnService_ = returnService;
89
+ this.returnItemService_ = returnItemService;
90
+ this.orderClaimService_ = orderClaimService;
91
+ this.orderExchangeService_ = orderExchangeService;
58
92
  }
59
93
  __joinerConfig() {
60
94
  return joiner_config_1.joinerConfig;
@@ -106,33 +140,142 @@ class OrderModuleService extends utils_1.ModulesSdkUtils.abstractModuleServiceFa
106
140
  return (!requiredFieldsForTotals.some((val) => val.startsWith(field)) && !totalFields.includes(field));
107
141
  });
108
142
  }
109
- async retrieve(id, config, sharedContext) {
143
+ // @ts-expect-error
144
+ async retrieveOrder(id, config, sharedContext) {
145
+ config ??= {};
146
+ const includeTotals = this.shouldIncludeTotals(config);
147
+ const order = await super.retrieveOrder(id, config, sharedContext);
148
+ return (0, utils_2.formatOrder)(order, {
149
+ entity: _models_1.Order,
150
+ includeTotals,
151
+ });
152
+ }
153
+ // @ts-expect-error
154
+ async listOrders(filters, config, sharedContext) {
155
+ config ??= {};
156
+ const includeTotals = this.shouldIncludeTotals(config);
157
+ const orders = await super.listOrders(filters, config, sharedContext);
158
+ return (0, utils_2.formatOrder)(orders, {
159
+ entity: _models_1.Order,
160
+ includeTotals,
161
+ });
162
+ }
163
+ // @ts-expect-error
164
+ async listAndCountOrders(filters, config, sharedContext) {
165
+ config ??= {};
166
+ const includeTotals = this.shouldIncludeTotals(config);
167
+ const [orders, count] = await super.listAndCountOrders(filters, config, sharedContext);
168
+ return [
169
+ (0, utils_2.formatOrder)(orders, {
170
+ entity: _models_1.Order,
171
+ includeTotals,
172
+ }),
173
+ count,
174
+ ];
175
+ }
176
+ // @ts-ignore
177
+ async retrieveReturn(id, config, sharedContext) {
178
+ config ??= {};
179
+ const includeTotals = this.shouldIncludeTotals(config);
180
+ const returnOrder = await super.retrieveReturn(id, config, sharedContext);
181
+ return (0, utils_2.formatOrder)(returnOrder, {
182
+ entity: _models_1.Return,
183
+ includeTotals,
184
+ });
185
+ }
186
+ // @ts-ignore
187
+ async listReturns(filters, config, sharedContext) {
188
+ config ??= {};
189
+ const includeTotals = this.shouldIncludeTotals(config);
190
+ const returnOrders = await super.listReturns(filters, config, sharedContext);
191
+ return (0, utils_2.formatOrder)(returnOrders, {
192
+ entity: _models_1.Return,
193
+ includeTotals,
194
+ });
195
+ }
196
+ // @ts-ignore
197
+ async listAndCountReturns(filters, config, sharedContext) {
198
+ config ??= {};
199
+ const includeTotals = this.shouldIncludeTotals(config);
200
+ const [returnOrders, count] = await super.listAndCountReturns(filters, config, sharedContext);
201
+ return [
202
+ (0, utils_2.formatOrder)(returnOrders, {
203
+ entity: _models_1.Return,
204
+ includeTotals,
205
+ }),
206
+ count,
207
+ ];
208
+ }
209
+ // @ts-ignore
210
+ async retrieveOrderClaim(id, config, sharedContext) {
211
+ config ??= {};
212
+ const includeTotals = this.shouldIncludeTotals(config);
213
+ const returnOrder = await super.retrieveOrderClaim(id, config, sharedContext);
214
+ return (0, utils_2.formatOrder)(returnOrder, {
215
+ entity: _models_1.OrderClaim,
216
+ includeTotals,
217
+ });
218
+ }
219
+ // @ts-ignore
220
+ async listOrderClaims(filters, config, sharedContext) {
110
221
  config ??= {};
111
222
  const includeTotals = this.shouldIncludeTotals(config);
112
- const order = await super.retrieve(id, config, sharedContext);
113
- return (0, transform_order_1.formatOrder)(order, { includeTotals });
223
+ const returnOrders = await super.listOrderClaims(filters, config, sharedContext);
224
+ return (0, utils_2.formatOrder)(returnOrders, {
225
+ entity: _models_1.OrderClaim,
226
+ includeTotals,
227
+ });
114
228
  }
115
- async list(filters, config, sharedContext) {
229
+ // @ts-ignore
230
+ async listAndCountOrderClaims(filters, config, sharedContext) {
116
231
  config ??= {};
117
232
  const includeTotals = this.shouldIncludeTotals(config);
118
- const orders = await super.list(filters, config, sharedContext);
119
- return (0, transform_order_1.formatOrder)(orders, {
233
+ const [returnOrders, count] = await super.listAndCountOrderClaims(filters, config, sharedContext);
234
+ return [
235
+ (0, utils_2.formatOrder)(returnOrders, {
236
+ entity: _models_1.OrderClaim,
237
+ includeTotals,
238
+ }),
239
+ count,
240
+ ];
241
+ }
242
+ // @ts-ignore
243
+ async retrieveOrderExchange(id, config, sharedContext) {
244
+ config ??= {};
245
+ const includeTotals = this.shouldIncludeTotals(config);
246
+ const returnOrder = await super.retrieveOrderExchange(id, config, sharedContext);
247
+ return (0, utils_2.formatOrder)(returnOrder, {
248
+ entity: _models_1.OrderExchange,
249
+ includeTotals,
250
+ });
251
+ }
252
+ // @ts-ignore
253
+ async listOrderExchanges(filters, config, sharedContext) {
254
+ config ??= {};
255
+ const includeTotals = this.shouldIncludeTotals(config);
256
+ const returnOrders = await super.listOrderExchanges(filters, config, sharedContext);
257
+ return (0, utils_2.formatOrder)(returnOrders, {
258
+ entity: _models_1.OrderExchange,
120
259
  includeTotals,
121
260
  });
122
261
  }
123
- async listAndCount(filters, config, sharedContext) {
262
+ // @ts-ignore
263
+ async listAndCountOrderExchanges(filters, config, sharedContext) {
124
264
  config ??= {};
125
265
  const includeTotals = this.shouldIncludeTotals(config);
126
- const [orders, count] = await super.listAndCount(filters, config, sharedContext);
266
+ const [returnOrders, count] = await super.listAndCountOrderExchanges(filters, config, sharedContext);
127
267
  return [
128
- (0, transform_order_1.formatOrder)(orders, { includeTotals }),
268
+ (0, utils_2.formatOrder)(returnOrders, {
269
+ entity: _models_1.OrderExchange,
270
+ includeTotals,
271
+ }),
129
272
  count,
130
273
  ];
131
274
  }
132
- async create(data, sharedContext = {}) {
275
+ async createOrders(data, sharedContext = {}) {
133
276
  const input = Array.isArray(data) ? data : [data];
134
- const orders = await this.create_(input, sharedContext);
135
- const result = await this.list({
277
+ const orders = await this.createOrders_(input, sharedContext);
278
+ const result = await this.listOrders({
136
279
  id: orders.map((p) => p.id),
137
280
  }, {
138
281
  relations: [
@@ -150,7 +293,7 @@ class OrderModuleService extends utils_1.ModulesSdkUtils.abstractModuleServiceFa
150
293
  }, sharedContext);
151
294
  return (Array.isArray(data) ? result : result[0]);
152
295
  }
153
- async create_(data, sharedContext = {}) {
296
+ async createOrders_(data, sharedContext = {}) {
154
297
  const lineItemsToCreate = [];
155
298
  const createdOrders = [];
156
299
  for (const { items, shipping_methods, ...order } of data) {
@@ -191,14 +334,14 @@ class OrderModuleService extends utils_1.ModulesSdkUtils.abstractModuleServiceFa
191
334
  }
192
335
  return createdOrders;
193
336
  }
194
- async update(dataOrIdOrSelector, data, sharedContext = {}) {
195
- const result = await this.update_(dataOrIdOrSelector, data, sharedContext);
337
+ async updateOrders(dataOrIdOrSelector, data, sharedContext = {}) {
338
+ const result = await this.updateOrders_(dataOrIdOrSelector, data, sharedContext);
196
339
  const serializedResult = await this.baseRepository_.serialize(result, {
197
340
  populate: true,
198
341
  });
199
342
  return (0, utils_1.isString)(dataOrIdOrSelector) ? serializedResult[0] : serializedResult;
200
343
  }
201
- async update_(dataOrIdOrSelector, data, sharedContext = {}) {
344
+ async updateOrders_(dataOrIdOrSelector, data, sharedContext = {}) {
202
345
  let toUpdate = [];
203
346
  if ((0, utils_1.isString)(dataOrIdOrSelector)) {
204
347
  toUpdate = [
@@ -233,7 +376,7 @@ class OrderModuleService extends utils_1.ModulesSdkUtils.abstractModuleServiceFa
233
376
  ? orderIdOrData
234
377
  : [orderIdOrData];
235
378
  const allOrderIds = data.map((dt) => dt.order_id);
236
- const order = await this.list({ id: allOrderIds }, { select: ["id", "version"] }, sharedContext);
379
+ const order = await this.listOrders({ id: allOrderIds }, { select: ["id", "version"] }, sharedContext);
237
380
  const mapOrderVersion = order.reduce((acc, curr) => {
238
381
  acc[curr.id] = curr.version;
239
382
  return acc;
@@ -251,7 +394,7 @@ class OrderModuleService extends utils_1.ModulesSdkUtils.abstractModuleServiceFa
251
394
  });
252
395
  }
253
396
  async createLineItems_(orderId, items, sharedContext = {}) {
254
- const order = await this.retrieve(orderId, { select: ["id", "version"] }, sharedContext);
397
+ const order = await this.retrieveOrder(orderId, { select: ["id", "version"] }, sharedContext);
255
398
  const toUpdate = items.map((item) => {
256
399
  return {
257
400
  ...item,
@@ -403,7 +546,7 @@ class OrderModuleService extends utils_1.ModulesSdkUtils.abstractModuleServiceFa
403
546
  ? orderIdOrData
404
547
  : [orderIdOrData];
405
548
  const allOrderIds = data.map((dt) => dt.order_id);
406
- const order = await this.list({ id: allOrderIds }, { select: ["id", "version"] }, sharedContext);
549
+ const order = await this.listOrders({ id: allOrderIds }, { select: ["id", "version"] }, sharedContext);
407
550
  const mapOrderVersion = order.reduce((acc, curr) => {
408
551
  acc[curr.id] = curr.version;
409
552
  return acc;
@@ -420,7 +563,7 @@ class OrderModuleService extends utils_1.ModulesSdkUtils.abstractModuleServiceFa
420
563
  return await this.baseRepository_.serialize(methods, { populate: true });
421
564
  }
422
565
  async createShippingMethods_(orderId, data, sharedContext = {}) {
423
- const order = await this.retrieve(orderId, { select: ["id", "version"] }, sharedContext);
566
+ const order = await this.retrieveOrder(orderId, { select: ["id", "version"] }, sharedContext);
424
567
  const methods = data.map((method) => {
425
568
  return {
426
569
  shipping_method: method,
@@ -437,7 +580,7 @@ class OrderModuleService extends utils_1.ModulesSdkUtils.abstractModuleServiceFa
437
580
  async createLineItemAdjustments(orderIdOrData, adjustments, sharedContext = {}) {
438
581
  let addedAdjustments = [];
439
582
  if ((0, utils_1.isString)(orderIdOrData)) {
440
- const order = await this.retrieve(orderIdOrData, { select: ["id"], relations: ["items.item"] }, sharedContext);
583
+ const order = await this.retrieveOrder(orderIdOrData, { select: ["id"], relations: ["items.item"] }, sharedContext);
441
584
  const lineIds = order.items?.map((item) => item.id);
442
585
  for (const adj of adjustments || []) {
443
586
  if (!lineIds?.includes(adj.item_id)) {
@@ -457,7 +600,7 @@ class OrderModuleService extends utils_1.ModulesSdkUtils.abstractModuleServiceFa
457
600
  });
458
601
  }
459
602
  async setLineItemAdjustments(orderId, adjustments, sharedContext = {}) {
460
- const order = await this.retrieve(orderId, { select: ["id"], relations: ["items.item.adjustments"] }, sharedContext);
603
+ const order = await this.retrieveOrder(orderId, { select: ["id"], relations: ["items.item.adjustments"] }, sharedContext);
461
604
  const existingAdjustments = (order.items ?? [])
462
605
  .map((item) => item.adjustments ?? [])
463
606
  .flat()
@@ -481,7 +624,7 @@ class OrderModuleService extends utils_1.ModulesSdkUtils.abstractModuleServiceFa
481
624
  });
482
625
  }
483
626
  async setShippingMethodAdjustments(orderId, adjustments, sharedContext = {}) {
484
- const order = await this.retrieve(orderId, { select: ["id"], relations: ["shipping_methods.adjustments"] }, sharedContext);
627
+ const order = await this.retrieveOrder(orderId, { select: ["id"], relations: ["shipping_methods.adjustments"] }, sharedContext);
485
628
  const existingAdjustments = (order.shipping_methods ?? [])
486
629
  .map((shippingMethod) => shippingMethod.adjustments ?? [])
487
630
  .flat()
@@ -507,7 +650,7 @@ class OrderModuleService extends utils_1.ModulesSdkUtils.abstractModuleServiceFa
507
650
  async createShippingMethodAdjustments(orderIdOrData, adjustments, sharedContext = {}) {
508
651
  let addedAdjustments = [];
509
652
  if ((0, utils_1.isString)(orderIdOrData)) {
510
- const order = await this.retrieve(orderIdOrData, { select: ["id"], relations: ["shipping_methods"] }, sharedContext);
653
+ const order = await this.retrieveOrder(orderIdOrData, { select: ["id"], relations: ["shipping_methods"] }, sharedContext);
511
654
  const methodIds = order.shipping_methods?.map((method) => method.id);
512
655
  for (const adj of adjustments || []) {
513
656
  if (!methodIds?.includes(adj.shipping_method_id)) {
@@ -552,7 +695,7 @@ class OrderModuleService extends utils_1.ModulesSdkUtils.abstractModuleServiceFa
552
695
  return serialized;
553
696
  }
554
697
  async setLineItemTaxLines(orderId, taxLines, sharedContext = {}) {
555
- const order = await this.retrieve(orderId, { select: ["id"], relations: ["items.item.tax_lines"] }, sharedContext);
698
+ const order = await this.retrieveOrder(orderId, { select: ["id"], relations: ["items.item.tax_lines"] }, sharedContext);
556
699
  const existingTaxLines = (order.items ?? [])
557
700
  .map((item) => item.tax_lines ?? [])
558
701
  .flat()
@@ -592,7 +735,7 @@ class OrderModuleService extends utils_1.ModulesSdkUtils.abstractModuleServiceFa
592
735
  return serialized;
593
736
  }
594
737
  async setShippingMethodTaxLines(orderId, taxLines, sharedContext = {}) {
595
- const order = await this.retrieve(orderId, { select: ["id"], relations: ["shipping_methods.tax_lines"] }, sharedContext);
738
+ const order = await this.retrieveOrder(orderId, { select: ["id"], relations: ["shipping_methods.tax_lines"] }, sharedContext);
596
739
  const existingTaxLines = (order.shipping_methods ?? [])
597
740
  .map((shippingMethod) => shippingMethod.tax_lines ?? [])
598
741
  .flat()
@@ -628,7 +771,7 @@ class OrderModuleService extends utils_1.ModulesSdkUtils.abstractModuleServiceFa
628
771
  orderIds.push(change.order_id);
629
772
  dataMap[change.order_id] = change;
630
773
  }
631
- const orders = await this.list({
774
+ const orders = await this.listOrders({
632
775
  id: orderIds,
633
776
  }, {
634
777
  select: ["id", "version"],
@@ -658,7 +801,7 @@ class OrderModuleService extends utils_1.ModulesSdkUtils.abstractModuleServiceFa
658
801
  return {
659
802
  ...((0, utils_1.isString)(dt) ? { id: dt } : dt),
660
803
  canceled_at: new Date(),
661
- status: utils_1.OrderChangeStatus.CANCELED,
804
+ status: _types_1.OrderChangeStatus.CANCELED,
662
805
  };
663
806
  });
664
807
  await this.orderChangeService_.update(updates, sharedContext);
@@ -675,7 +818,7 @@ class OrderModuleService extends utils_1.ModulesSdkUtils.abstractModuleServiceFa
675
818
  return {
676
819
  ...((0, utils_1.isString)(dt) ? { id: dt } : dt),
677
820
  confirmed_at: new Date(),
678
- status: utils_1.OrderChangeStatus.CONFIRMED,
821
+ status: _types_1.OrderChangeStatus.CONFIRMED,
679
822
  };
680
823
  });
681
824
  await this.orderChangeService_.update(updates, sharedContext);
@@ -685,11 +828,14 @@ class OrderModuleService extends utils_1.ModulesSdkUtils.abstractModuleServiceFa
685
828
  ...action,
686
829
  version: change.version,
687
830
  order_id: change.order_id,
831
+ return_id: change.return_id,
832
+ claim_id: change.claim_id,
833
+ exchange_id: change.exchange_id,
688
834
  };
689
835
  });
690
836
  return change.actions;
691
837
  });
692
- await this.applyOrderChanges_(orderChanges.flat(), sharedContext);
838
+ return await this.applyOrderChanges_(orderChanges.flat(), sharedContext);
693
839
  }
694
840
  async declineOrderChange(orderChangeIdOrData, sharedContext) {
695
841
  const data = Array.isArray(orderChangeIdOrData)
@@ -703,14 +849,14 @@ class OrderModuleService extends utils_1.ModulesSdkUtils.abstractModuleServiceFa
703
849
  return {
704
850
  ...((0, utils_1.isString)(dt) ? { id: dt } : dt),
705
851
  declined_at: new Date(),
706
- status: utils_1.OrderChangeStatus.DECLINED,
852
+ status: _types_1.OrderChangeStatus.DECLINED,
707
853
  };
708
854
  });
709
855
  await this.orderChangeService_.update(updates, sharedContext);
710
856
  }
711
857
  async applyPendingOrderActions(orderId, sharedContext) {
712
858
  const orderIds = Array.isArray(orderId) ? orderId : [orderId];
713
- const orders = await this.list({ id: orderIds }, {
859
+ const orders = await this.listOrders({ id: orderIds }, {
714
860
  select: ["id", "version"],
715
861
  }, sharedContext);
716
862
  const changes = await this.orderChangeActionService_.list({
@@ -736,10 +882,10 @@ class OrderModuleService extends utils_1.ModulesSdkUtils.abstractModuleServiceFa
736
882
  ordering: "ASC",
737
883
  },
738
884
  }, sharedContext);
739
- await this.applyOrderChanges_(changes, sharedContext);
885
+ return await this.applyOrderChanges_(changes, sharedContext);
740
886
  }
741
887
  async revertLastVersion(orderId, sharedContext) {
742
- const order = await super.retrieve(orderId, {
888
+ const order = await super.retrieveOrder(orderId, {
743
889
  select: ["id", "version"],
744
890
  }, sharedContext);
745
891
  if (order.version < 2) {
@@ -793,6 +939,11 @@ class OrderModuleService extends utils_1.ModulesSdkUtils.abstractModuleServiceFa
793
939
  version: order.version - 1,
794
940
  },
795
941
  }, sharedContext);
942
+ // Returns
943
+ await this.returnService_.delete({
944
+ order_id: order.id,
945
+ order_version: currentVersion,
946
+ }, sharedContext);
796
947
  }
797
948
  async getAndValidateOrderChange_(orderChangeIds, includeActions, sharedContext) {
798
949
  const options = {
@@ -819,8 +970,8 @@ class OrderModuleService extends utils_1.ModulesSdkUtils.abstractModuleServiceFa
819
970
  }
820
971
  for (const orderChange of orderChanges) {
821
972
  const notAllowed = [];
822
- if (!(orderChange.status === utils_1.OrderChangeStatus.PENDING ||
823
- orderChange.status === utils_1.OrderChangeStatus.REQUESTED)) {
973
+ if (!(orderChange.status === _types_1.OrderChangeStatus.PENDING ||
974
+ orderChange.status === _types_1.OrderChangeStatus.REQUESTED)) {
824
975
  notAllowed.push(orderChange.id);
825
976
  }
826
977
  if (notAllowed.length) {
@@ -876,74 +1027,32 @@ class OrderModuleService extends utils_1.ModulesSdkUtils.abstractModuleServiceFa
876
1027
  });
877
1028
  }
878
1029
  if (!ordersIds.length) {
879
- return;
1030
+ return {
1031
+ items: [],
1032
+ shippingMethods: [],
1033
+ };
880
1034
  }
881
- const orders = await this.list({ id: (0, utils_1.deduplicate)(ordersIds) }, {
1035
+ let orders = await super.listOrders({ id: (0, utils_1.deduplicate)(ordersIds) }, {
882
1036
  select: [
883
1037
  "id",
884
1038
  "version",
885
1039
  "items.detail",
886
1040
  "transactions",
1041
+ "shipping_methods",
887
1042
  "summary",
888
1043
  "total",
889
1044
  ],
890
- relations: ["transactions", "items", "items.detail"],
1045
+ relations: [
1046
+ "transactions",
1047
+ "items",
1048
+ "items.detail",
1049
+ "shipping_methods",
1050
+ ],
891
1051
  }, sharedContext);
892
- const itemsToUpsert = [];
893
- const shippingMethodsToInsert = [];
894
- const summariesToUpsert = [];
895
- const orderToUpdate = [];
896
- for (const order of orders) {
897
- const calculated = (0, utils_2.calculateOrderChange)({
898
- order: order,
899
- actions: actionsMap[order.id],
900
- transactions: order.transactions,
901
- });
902
- (0, utils_1.createRawPropertiesFromBigNumber)(calculated);
903
- const version = actionsMap[order.id][0].version;
904
- for (const item of calculated.order.items) {
905
- const orderItem = item.detail;
906
- itemsToUpsert.push({
907
- id: orderItem.version === version ? orderItem.id : undefined,
908
- item_id: item.id,
909
- order_id: order.id,
910
- version,
911
- quantity: item.detail.quantity,
912
- fulfilled_quantity: item.detail.fulfilled_quantity,
913
- shipped_quantity: item.detail.shipped_quantity,
914
- return_requested_quantity: item.detail.return_requested_quantity,
915
- return_received_quantity: item.detail.return_received_quantity,
916
- return_dismissed_quantity: item.detail.return_dismissed_quantity,
917
- written_off_quantity: item.detail.written_off_quantity,
918
- metadata: item.detail.metadata,
919
- });
920
- }
921
- const orderSummary = order.summary;
922
- summariesToUpsert.push({
923
- id: orderSummary.version === version ? orderSummary.id : undefined,
924
- order_id: order.id,
925
- version,
926
- totals: calculated.summary,
927
- });
928
- if (version > order.version) {
929
- for (const shippingMethod of order.shipping_methods ?? []) {
930
- const sm = {
931
- ...shippingMethod.detail,
932
- version,
933
- };
934
- delete sm.id;
935
- shippingMethodsToInsert.push(sm);
936
- }
937
- orderToUpdate.push({
938
- selector: {
939
- id: order.id,
940
- },
941
- data: {
942
- version,
943
- },
944
- });
945
- }
946
- }
1052
+ orders = (0, utils_2.formatOrder)(orders, {
1053
+ entity: _models_1.Order,
1054
+ });
1055
+ const { itemsToUpsert, shippingMethodsToInsert, summariesToUpsert, orderToUpdate, } = (0, utils_2.applyChangesToOrder)(orders, actionsMap);
947
1056
  await (0, utils_1.promiseAll)([
948
1057
  orderToUpdate.length
949
1058
  ? this.orderService_.update(orderToUpdate, sharedContext)
@@ -961,130 +1070,10 @@ class OrderModuleService extends utils_1.ModulesSdkUtils.abstractModuleServiceFa
961
1070
  ? this.orderShippingMethodService_.create(shippingMethodsToInsert, sharedContext)
962
1071
  : null,
963
1072
  ]);
964
- }
965
- async registerFulfillment(data, sharedContext) {
966
- const items = data.items.map((item) => {
967
- return {
968
- action: utils_2.ChangeActionType.FULFILL_ITEM,
969
- internal_note: item.internal_note,
970
- reference: data.reference,
971
- reference_id: data.reference_id,
972
- details: {
973
- reference_id: item.id,
974
- quantity: item.quantity,
975
- metadata: item.metadata,
976
- },
977
- };
978
- });
979
- const change = await this.createOrderChange_({
980
- order_id: data.order_id,
981
- description: data.description,
982
- internal_note: data.internal_note,
983
- created_by: data.created_by,
984
- metadata: data.metadata,
985
- actions: items,
986
- }, sharedContext);
987
- await this.confirmOrderChange(change[0].id, sharedContext);
988
- }
989
- async cancelFulfillment(data, sharedContext) {
990
- const items = data.items.map((item) => {
991
- return {
992
- action: utils_2.ChangeActionType.CANCEL_ITEM_FULFILLMENT,
993
- internal_note: item.internal_note,
994
- reference: data.reference,
995
- reference_id: data.reference_id,
996
- details: {
997
- reference_id: item.id,
998
- quantity: item.quantity,
999
- metadata: item.metadata,
1000
- },
1001
- };
1002
- });
1003
- const change = await this.createOrderChange_({
1004
- order_id: data.order_id,
1005
- description: data.description,
1006
- internal_note: data.internal_note,
1007
- created_by: data.created_by,
1008
- metadata: data.metadata,
1009
- actions: items,
1010
- }, sharedContext);
1011
- await this.confirmOrderChange(change[0].id, sharedContext);
1012
- }
1013
- async registerShipment(data, sharedContext) {
1014
- let shippingMethodId;
1015
- const actions = data.items.map((item) => {
1016
- return {
1017
- action: utils_2.ChangeActionType.SHIP_ITEM,
1018
- internal_note: item.internal_note,
1019
- reference: data.reference,
1020
- reference_id: data.reference_id,
1021
- details: {
1022
- reference_id: item.id,
1023
- quantity: item.quantity,
1024
- metadata: item.metadata,
1025
- },
1026
- };
1027
- });
1028
- if (shippingMethodId) {
1029
- actions.push({
1030
- action: utils_2.ChangeActionType.SHIPPING_ADD,
1031
- reference: data.reference,
1032
- reference_id: shippingMethodId,
1033
- });
1034
- }
1035
- const change = await this.createOrderChange_({
1036
- order_id: data.order_id,
1037
- description: data.description,
1038
- internal_note: data.internal_note,
1039
- created_by: data.created_by,
1040
- metadata: data.metadata,
1041
- actions,
1042
- }, sharedContext);
1043
- await this.confirmOrderChange(change[0].id, sharedContext);
1044
- }
1045
- async createReturn(data, sharedContext) {
1046
- let shippingMethodId;
1047
- if (!(0, utils_1.isString)(data.shipping_method)) {
1048
- const methods = await this.createShippingMethods(data.order_id, [{ order_id: data.order_id, ...data.shipping_method }], sharedContext);
1049
- shippingMethodId = methods[0].id;
1050
- }
1051
- else {
1052
- shippingMethodId = data.shipping_method;
1053
- }
1054
- const method = await this.shippingMethodService_.retrieve(shippingMethodId, {
1055
- relations: ["tax_lines", "adjustments"],
1056
- }, sharedContext);
1057
- const calculatedAmount = (0, utils_1.getShippingMethodsTotals)([method], {})[method.id];
1058
- const actions = data.items.map((item) => {
1059
- return {
1060
- action: utils_2.ChangeActionType.RETURN_ITEM,
1061
- internal_note: item.internal_note,
1062
- reference: data.reference ?? "fulfillment",
1063
- reference_id: data.reference_id ?? shippingMethodId,
1064
- details: {
1065
- reference_id: item.id,
1066
- quantity: item.quantity,
1067
- metadata: item.metadata,
1068
- },
1069
- };
1070
- });
1071
- if (shippingMethodId) {
1072
- actions.push({
1073
- action: utils_2.ChangeActionType.SHIPPING_ADD,
1074
- reference: data.reference ?? "fulfillment",
1075
- reference_id: data.reference_id ?? shippingMethodId,
1076
- amount: calculatedAmount.total,
1077
- });
1078
- }
1079
- const change = await this.createOrderChange_({
1080
- order_id: data.order_id,
1081
- description: data.description,
1082
- internal_note: data.internal_note,
1083
- created_by: data.created_by,
1084
- metadata: data.metadata,
1085
- actions,
1086
- }, sharedContext);
1087
- await this.confirmOrderChange(change[0].id, sharedContext);
1073
+ return {
1074
+ items: itemsToUpsert,
1075
+ shippingMethods: shippingMethodsToInsert,
1076
+ };
1088
1077
  }
1089
1078
  async addTransactions(transactionData, sharedContext) {
1090
1079
  const orders = await this.orderService_.list({
@@ -1216,33 +1205,9 @@ class OrderModuleService extends utils_1.ModulesSdkUtils.abstractModuleServiceFa
1216
1205
  }
1217
1206
  return await this.returnReasonService_.update(toUpdate, sharedContext);
1218
1207
  }
1219
- async receiveReturn(data, sharedContext) {
1220
- const items = data.items.map((item) => {
1221
- return {
1222
- action: utils_2.ChangeActionType.RECEIVE_RETURN_ITEM,
1223
- internal_note: item.internal_note,
1224
- reference: data.reference,
1225
- reference_id: data.reference_id,
1226
- details: {
1227
- reference_id: item.id,
1228
- quantity: item.quantity,
1229
- metadata: item.metadata,
1230
- },
1231
- };
1232
- });
1233
- const change = await this.createOrderChange_({
1234
- order_id: data.order_id,
1235
- description: data.description,
1236
- internal_note: data.internal_note,
1237
- created_by: data.created_by,
1238
- metadata: data.metadata,
1239
- actions: items,
1240
- }, sharedContext);
1241
- await this.confirmOrderChange(change[0].id, sharedContext);
1242
- }
1243
1208
  async archive(orderId, sharedContext) {
1244
1209
  const orderIds = Array.isArray(orderId) ? orderId : [orderId];
1245
- const orders = await this.list({
1210
+ const orders = await this.listOrders({
1246
1211
  id: orderIds,
1247
1212
  }, {}, sharedContext);
1248
1213
  const notAllowed = [];
@@ -1267,7 +1232,7 @@ class OrderModuleService extends utils_1.ModulesSdkUtils.abstractModuleServiceFa
1267
1232
  }
1268
1233
  async completeOrder(orderId, sharedContext) {
1269
1234
  const orderIds = Array.isArray(orderId) ? orderId : [orderId];
1270
- const orders = await this.list({
1235
+ const orders = await this.listOrders({
1271
1236
  id: orderIds,
1272
1237
  }, {}, sharedContext);
1273
1238
  const notAllowed = [];
@@ -1290,7 +1255,7 @@ class OrderModuleService extends utils_1.ModulesSdkUtils.abstractModuleServiceFa
1290
1255
  }
1291
1256
  async cancel(orderId, sharedContext) {
1292
1257
  const orderIds = Array.isArray(orderId) ? orderId : [orderId];
1293
- const orders = await this.list({
1258
+ const orders = await this.listOrders({
1294
1259
  id: orderIds,
1295
1260
  }, {}, sharedContext);
1296
1261
  const canceled_at = new Date();
@@ -1307,36 +1272,178 @@ class OrderModuleService extends utils_1.ModulesSdkUtils.abstractModuleServiceFa
1307
1272
  }), sharedContext);
1308
1273
  return Array.isArray(orderId) ? orders : orders[0];
1309
1274
  }
1275
+ // ------------------- Bundled Order Actions
1276
+ async createReturn(data, sharedContext) {
1277
+ // TODO: type ReturnDTO
1278
+ const ret = await BundledActions.createReturn.bind(this)(data, sharedContext);
1279
+ return await this.retrieveReturn(ret.id, {
1280
+ relations: ["items"],
1281
+ }, sharedContext);
1282
+ }
1283
+ async receiveReturn(data, sharedContext) {
1284
+ const ret = await this.receiveReturn_(data, sharedContext);
1285
+ return await this.retrieveReturn(ret.id, {
1286
+ relations: ["items"],
1287
+ });
1288
+ }
1289
+ async receiveReturn_(data, sharedContext) {
1290
+ return await BundledActions.receiveReturn.bind(this)(data, sharedContext);
1291
+ }
1292
+ async createClaim(data, sharedContext) {
1293
+ const ret = await this.createClaim_(data, sharedContext);
1294
+ const claim = await this.retrieveOrderClaim(ret.id, {
1295
+ relations: [
1296
+ "additional_items",
1297
+ "additional_items.item",
1298
+ "claim_items",
1299
+ "claim_items.item",
1300
+ "return",
1301
+ "return.items",
1302
+ "shipping_methods",
1303
+ "shipping_methods.tax_lines",
1304
+ "shipping_methods.adjustments",
1305
+ "transactions",
1306
+ ],
1307
+ }, sharedContext);
1308
+ return await this.baseRepository_.serialize(claim, {
1309
+ populate: true,
1310
+ });
1311
+ }
1312
+ async createExchange_(data, sharedContext) {
1313
+ return await BundledActions.createExchange.bind(this)(data, sharedContext);
1314
+ }
1315
+ async createExchange(data, sharedContext) {
1316
+ const ret = await this.createExchange_(data, sharedContext);
1317
+ const claim = await this.retrieveOrderExchange(ret.id, {
1318
+ relations: [
1319
+ "additional_items",
1320
+ "additional_items.item",
1321
+ "return",
1322
+ "return.items",
1323
+ "shipping_methods",
1324
+ "shipping_methods.tax_lines",
1325
+ "shipping_methods.adjustments",
1326
+ "transactions",
1327
+ ],
1328
+ }, sharedContext);
1329
+ return await this.baseRepository_.serialize(claim, {
1330
+ populate: true,
1331
+ });
1332
+ }
1333
+ async createClaim_(data, sharedContext) {
1334
+ return await BundledActions.createClaim.bind(this)(data, sharedContext);
1335
+ }
1336
+ async registerFulfillment(data, sharedContext) {
1337
+ return await BundledActions.registerFulfillment.bind(this)(data, sharedContext);
1338
+ }
1339
+ async cancelFulfillment(data, sharedContext) {
1340
+ return await BundledActions.cancelFulfillment.bind(this)(data, sharedContext);
1341
+ }
1342
+ async registerShipment(data, sharedContext) {
1343
+ return await BundledActions.registerShipment.bind(this)(data, sharedContext);
1344
+ }
1310
1345
  }
1311
1346
  exports.default = OrderModuleService;
1347
+ __decorate([
1348
+ __param(2, (0, utils_1.MedusaContext)()),
1349
+ __metadata("design:type", Function),
1350
+ __metadata("design:paramtypes", [String, Object, Object]),
1351
+ __metadata("design:returntype", Promise)
1352
+ ], OrderModuleService.prototype, "retrieveOrder", null);
1353
+ __decorate([
1354
+ __param(2, (0, utils_1.MedusaContext)()),
1355
+ __metadata("design:type", Function),
1356
+ __metadata("design:paramtypes", [Object, Object, Object]),
1357
+ __metadata("design:returntype", Promise)
1358
+ ], OrderModuleService.prototype, "listOrders", null);
1359
+ __decorate([
1360
+ __param(2, (0, utils_1.MedusaContext)()),
1361
+ __metadata("design:type", Function),
1362
+ __metadata("design:paramtypes", [Object, Object, Object]),
1363
+ __metadata("design:returntype", Promise)
1364
+ ], OrderModuleService.prototype, "listAndCountOrders", null);
1365
+ __decorate([
1366
+ __param(2, (0, utils_1.MedusaContext)()),
1367
+ __metadata("design:type", Function),
1368
+ __metadata("design:paramtypes", [String, Object, Object]),
1369
+ __metadata("design:returntype", Promise)
1370
+ ], OrderModuleService.prototype, "retrieveReturn", null);
1371
+ __decorate([
1372
+ __param(2, (0, utils_1.MedusaContext)()),
1373
+ __metadata("design:type", Function),
1374
+ __metadata("design:paramtypes", [Object, Object, Object]),
1375
+ __metadata("design:returntype", Promise)
1376
+ ], OrderModuleService.prototype, "listReturns", null);
1377
+ __decorate([
1378
+ __param(2, (0, utils_1.MedusaContext)()),
1379
+ __metadata("design:type", Function),
1380
+ __metadata("design:paramtypes", [Object, Object, Object]),
1381
+ __metadata("design:returntype", Promise)
1382
+ ], OrderModuleService.prototype, "listAndCountReturns", null);
1383
+ __decorate([
1384
+ __param(2, (0, utils_1.MedusaContext)()),
1385
+ __metadata("design:type", Function),
1386
+ __metadata("design:paramtypes", [String, Object, Object]),
1387
+ __metadata("design:returntype", Promise)
1388
+ ], OrderModuleService.prototype, "retrieveOrderClaim", null);
1389
+ __decorate([
1390
+ __param(2, (0, utils_1.MedusaContext)()),
1391
+ __metadata("design:type", Function),
1392
+ __metadata("design:paramtypes", [Object, Object, Object]),
1393
+ __metadata("design:returntype", Promise)
1394
+ ], OrderModuleService.prototype, "listOrderClaims", null);
1395
+ __decorate([
1396
+ __param(2, (0, utils_1.MedusaContext)()),
1397
+ __metadata("design:type", Function),
1398
+ __metadata("design:paramtypes", [Object, Object, Object]),
1399
+ __metadata("design:returntype", Promise)
1400
+ ], OrderModuleService.prototype, "listAndCountOrderClaims", null);
1401
+ __decorate([
1402
+ __param(2, (0, utils_1.MedusaContext)()),
1403
+ __metadata("design:type", Function),
1404
+ __metadata("design:paramtypes", [String, Object, Object]),
1405
+ __metadata("design:returntype", Promise)
1406
+ ], OrderModuleService.prototype, "retrieveOrderExchange", null);
1407
+ __decorate([
1408
+ __param(2, (0, utils_1.MedusaContext)()),
1409
+ __metadata("design:type", Function),
1410
+ __metadata("design:paramtypes", [Object, Object, Object]),
1411
+ __metadata("design:returntype", Promise)
1412
+ ], OrderModuleService.prototype, "listOrderExchanges", null);
1413
+ __decorate([
1414
+ __param(2, (0, utils_1.MedusaContext)()),
1415
+ __metadata("design:type", Function),
1416
+ __metadata("design:paramtypes", [Object, Object, Object]),
1417
+ __metadata("design:returntype", Promise)
1418
+ ], OrderModuleService.prototype, "listAndCountOrderExchanges", null);
1312
1419
  __decorate([
1313
1420
  (0, utils_1.InjectManager)("baseRepository_"),
1314
1421
  __param(1, (0, utils_1.MedusaContext)()),
1315
1422
  __metadata("design:type", Function),
1316
1423
  __metadata("design:paramtypes", [Object, Object]),
1317
1424
  __metadata("design:returntype", Promise)
1318
- ], OrderModuleService.prototype, "create", null);
1425
+ ], OrderModuleService.prototype, "createOrders", null);
1319
1426
  __decorate([
1320
1427
  (0, utils_1.InjectTransactionManager)("baseRepository_"),
1321
1428
  __param(1, (0, utils_1.MedusaContext)()),
1322
1429
  __metadata("design:type", Function),
1323
1430
  __metadata("design:paramtypes", [Array, Object]),
1324
1431
  __metadata("design:returntype", Promise)
1325
- ], OrderModuleService.prototype, "create_", null);
1432
+ ], OrderModuleService.prototype, "createOrders_", null);
1326
1433
  __decorate([
1327
1434
  (0, utils_1.InjectManager)("baseRepository_"),
1328
1435
  __param(2, (0, utils_1.MedusaContext)()),
1329
1436
  __metadata("design:type", Function),
1330
1437
  __metadata("design:paramtypes", [Object, Object, Object]),
1331
1438
  __metadata("design:returntype", Promise)
1332
- ], OrderModuleService.prototype, "update", null);
1439
+ ], OrderModuleService.prototype, "updateOrders", null);
1333
1440
  __decorate([
1334
1441
  (0, utils_1.InjectTransactionManager)("baseRepository_"),
1335
1442
  __param(2, (0, utils_1.MedusaContext)()),
1336
1443
  __metadata("design:type", Function),
1337
1444
  __metadata("design:paramtypes", [Object, Object, Object]),
1338
1445
  __metadata("design:returntype", Promise)
1339
- ], OrderModuleService.prototype, "update_", null);
1446
+ ], OrderModuleService.prototype, "updateOrders_", null);
1340
1447
  __decorate([
1341
1448
  (0, utils_1.InjectManager)("baseRepository_"),
1342
1449
  __param(2, (0, utils_1.MedusaContext)()),
@@ -1507,42 +1614,49 @@ __decorate([
1507
1614
  ], OrderModuleService.prototype, "setShippingMethodTaxLines", null);
1508
1615
  __decorate([
1509
1616
  (0, utils_1.InjectManager)("baseRepository_"),
1617
+ __param(1, (0, utils_1.MedusaContext)()),
1510
1618
  __metadata("design:type", Function),
1511
1619
  __metadata("design:paramtypes", [Object, Object]),
1512
1620
  __metadata("design:returntype", Promise)
1513
1621
  ], OrderModuleService.prototype, "createOrderChange", null);
1514
1622
  __decorate([
1515
1623
  (0, utils_1.InjectTransactionManager)("baseRepository_"),
1624
+ __param(1, (0, utils_1.MedusaContext)()),
1516
1625
  __metadata("design:type", Function),
1517
1626
  __metadata("design:paramtypes", [Object, Object]),
1518
1627
  __metadata("design:returntype", Promise)
1519
1628
  ], OrderModuleService.prototype, "createOrderChange_", null);
1520
1629
  __decorate([
1521
1630
  (0, utils_1.InjectTransactionManager)("baseRepository_"),
1631
+ __param(1, (0, utils_1.MedusaContext)()),
1522
1632
  __metadata("design:type", Function),
1523
1633
  __metadata("design:paramtypes", [Object, Object]),
1524
1634
  __metadata("design:returntype", Promise)
1525
1635
  ], OrderModuleService.prototype, "cancelOrderChange", null);
1526
1636
  __decorate([
1527
1637
  (0, utils_1.InjectTransactionManager)("baseRepository_"),
1638
+ __param(1, (0, utils_1.MedusaContext)()),
1528
1639
  __metadata("design:type", Function),
1529
1640
  __metadata("design:paramtypes", [Object, Object]),
1530
1641
  __metadata("design:returntype", Promise)
1531
1642
  ], OrderModuleService.prototype, "confirmOrderChange", null);
1532
1643
  __decorate([
1533
1644
  (0, utils_1.InjectTransactionManager)("baseRepository_"),
1645
+ __param(1, (0, utils_1.MedusaContext)()),
1534
1646
  __metadata("design:type", Function),
1535
1647
  __metadata("design:paramtypes", [Object, Object]),
1536
1648
  __metadata("design:returntype", Promise)
1537
1649
  ], OrderModuleService.prototype, "declineOrderChange", null);
1538
1650
  __decorate([
1539
1651
  (0, utils_1.InjectManager)("baseRepository_"),
1652
+ __param(1, (0, utils_1.MedusaContext)()),
1540
1653
  __metadata("design:type", Function),
1541
1654
  __metadata("design:paramtypes", [Object, Object]),
1542
1655
  __metadata("design:returntype", Promise)
1543
1656
  ], OrderModuleService.prototype, "applyPendingOrderActions", null);
1544
1657
  __decorate([
1545
1658
  (0, utils_1.InjectManager)("baseRepository_"),
1659
+ __param(1, (0, utils_1.MedusaContext)()),
1546
1660
  __metadata("design:type", Function),
1547
1661
  __metadata("design:paramtypes", [String, Object]),
1548
1662
  __metadata("design:returntype", Promise)
@@ -1555,36 +1669,14 @@ __decorate([
1555
1669
  ], OrderModuleService.prototype, "revertLastChange_", null);
1556
1670
  __decorate([
1557
1671
  (0, utils_1.InjectTransactionManager)("baseRepository_"),
1672
+ __param(1, (0, utils_1.MedusaContext)()),
1558
1673
  __metadata("design:type", Function),
1559
1674
  __metadata("design:paramtypes", [Object, Object]),
1560
1675
  __metadata("design:returntype", Promise)
1561
1676
  ], OrderModuleService.prototype, "addOrderAction", null);
1562
- __decorate([
1563
- (0, utils_1.InjectTransactionManager)("baseRepository_"),
1564
- __metadata("design:type", Function),
1565
- __metadata("design:paramtypes", [Object, Object]),
1566
- __metadata("design:returntype", Promise)
1567
- ], OrderModuleService.prototype, "registerFulfillment", null);
1568
- __decorate([
1569
- (0, utils_1.InjectTransactionManager)("baseRepository_"),
1570
- __metadata("design:type", Function),
1571
- __metadata("design:paramtypes", [Object, Object]),
1572
- __metadata("design:returntype", Promise)
1573
- ], OrderModuleService.prototype, "cancelFulfillment", null);
1574
- __decorate([
1575
- (0, utils_1.InjectTransactionManager)("baseRepository_"),
1576
- __metadata("design:type", Function),
1577
- __metadata("design:paramtypes", [Object, Object]),
1578
- __metadata("design:returntype", Promise)
1579
- ], OrderModuleService.prototype, "registerShipment", null);
1580
- __decorate([
1581
- (0, utils_1.InjectTransactionManager)("baseRepository_"),
1582
- __metadata("design:type", Function),
1583
- __metadata("design:paramtypes", [Object, Object]),
1584
- __metadata("design:returntype", Promise)
1585
- ], OrderModuleService.prototype, "createReturn", null);
1586
1677
  __decorate([
1587
1678
  (0, utils_1.InjectManager)("baseRepository_"),
1679
+ __param(1, (0, utils_1.MedusaContext)()),
1588
1680
  __metadata("design:type", Function),
1589
1681
  __metadata("design:paramtypes", [Object, Object]),
1590
1682
  __metadata("design:returntype", Promise)
@@ -1593,6 +1685,7 @@ __decorate([
1593
1685
  (0, utils_1.InjectManager)("baseRepository_")
1594
1686
  // @ts-ignore
1595
1687
  ,
1688
+ __param(1, (0, utils_1.MedusaContext)()),
1596
1689
  __metadata("design:type", Function),
1597
1690
  __metadata("design:paramtypes", [Object, Object]),
1598
1691
  __metadata("design:returntype", Promise)
@@ -1601,6 +1694,7 @@ __decorate([
1601
1694
  (0, utils_1.InjectManager)("baseRepository_")
1602
1695
  // @ts-ignore
1603
1696
  ,
1697
+ __param(2, (0, utils_1.MedusaContext)()),
1604
1698
  __metadata("design:type", Function),
1605
1699
  __metadata("design:paramtypes", [Object, Object, Object]),
1606
1700
  __metadata("design:returntype", Promise)
@@ -1609,6 +1703,7 @@ __decorate([
1609
1703
  (0, utils_1.InjectManager)("baseRepository_")
1610
1704
  // @ts-ignore
1611
1705
  ,
1706
+ __param(2, (0, utils_1.MedusaContext)()),
1612
1707
  __metadata("design:type", Function),
1613
1708
  __metadata("design:paramtypes", [Object, Object, Object]),
1614
1709
  __metadata("design:returntype", Promise)
@@ -1621,6 +1716,7 @@ __decorate([
1621
1716
  ], OrderModuleService.prototype, "updateOrderPaidRefundableAmount_", null);
1622
1717
  __decorate([
1623
1718
  (0, utils_1.InjectTransactionManager)("baseRepository_"),
1719
+ __param(1, (0, utils_1.MedusaContext)()),
1624
1720
  __metadata("design:type", Function),
1625
1721
  __metadata("design:paramtypes", [Object, Object]),
1626
1722
  __metadata("design:returntype", Promise)
@@ -1648,26 +1744,93 @@ __decorate([
1648
1744
  ], OrderModuleService.prototype, "updateReturnReasonsWithSelector_", null);
1649
1745
  __decorate([
1650
1746
  (0, utils_1.InjectTransactionManager)("baseRepository_"),
1747
+ __param(1, (0, utils_1.MedusaContext)()),
1748
+ __metadata("design:type", Function),
1749
+ __metadata("design:paramtypes", [Object, Object]),
1750
+ __metadata("design:returntype", Promise)
1751
+ ], OrderModuleService.prototype, "archive", null);
1752
+ __decorate([
1753
+ (0, utils_1.InjectTransactionManager)("baseRepository_"),
1754
+ __param(1, (0, utils_1.MedusaContext)()),
1755
+ __metadata("design:type", Function),
1756
+ __metadata("design:paramtypes", [Object, Object]),
1757
+ __metadata("design:returntype", Promise)
1758
+ ], OrderModuleService.prototype, "completeOrder", null);
1759
+ __decorate([
1760
+ (0, utils_1.InjectTransactionManager)("baseRepository_"),
1761
+ __param(1, (0, utils_1.MedusaContext)()),
1762
+ __metadata("design:type", Function),
1763
+ __metadata("design:paramtypes", [Object, Object]),
1764
+ __metadata("design:returntype", Promise)
1765
+ ], OrderModuleService.prototype, "cancel", null);
1766
+ __decorate([
1767
+ (0, utils_1.InjectTransactionManager)("baseRepository_"),
1768
+ __param(1, (0, utils_1.MedusaContext)()),
1769
+ __metadata("design:type", Function),
1770
+ __metadata("design:paramtypes", [Object, Object]),
1771
+ __metadata("design:returntype", Promise)
1772
+ ], OrderModuleService.prototype, "createReturn", null);
1773
+ __decorate([
1774
+ (0, utils_1.InjectManager)("baseRepository_"),
1775
+ __param(1, (0, utils_1.MedusaContext)()),
1651
1776
  __metadata("design:type", Function),
1652
1777
  __metadata("design:paramtypes", [Object, Object]),
1653
1778
  __metadata("design:returntype", Promise)
1654
1779
  ], OrderModuleService.prototype, "receiveReturn", null);
1655
1780
  __decorate([
1656
1781
  (0, utils_1.InjectTransactionManager)("baseRepository_"),
1782
+ __param(1, (0, utils_1.MedusaContext)()),
1657
1783
  __metadata("design:type", Function),
1658
1784
  __metadata("design:paramtypes", [Object, Object]),
1659
1785
  __metadata("design:returntype", Promise)
1660
- ], OrderModuleService.prototype, "archive", null);
1786
+ ], OrderModuleService.prototype, "receiveReturn_", null);
1787
+ __decorate([
1788
+ (0, utils_1.InjectManager)("baseRepository_"),
1789
+ __param(1, (0, utils_1.MedusaContext)()),
1790
+ __metadata("design:type", Function),
1791
+ __metadata("design:paramtypes", [Object, Object]),
1792
+ __metadata("design:returntype", Promise)
1793
+ ], OrderModuleService.prototype, "createClaim", null);
1661
1794
  __decorate([
1662
1795
  (0, utils_1.InjectTransactionManager)("baseRepository_"),
1796
+ __param(1, (0, utils_1.MedusaContext)()),
1663
1797
  __metadata("design:type", Function),
1664
1798
  __metadata("design:paramtypes", [Object, Object]),
1665
1799
  __metadata("design:returntype", Promise)
1666
- ], OrderModuleService.prototype, "completeOrder", null);
1800
+ ], OrderModuleService.prototype, "createExchange_", null);
1801
+ __decorate([
1802
+ (0, utils_1.InjectManager)("baseRepository_"),
1803
+ __param(1, (0, utils_1.MedusaContext)()),
1804
+ __metadata("design:type", Function),
1805
+ __metadata("design:paramtypes", [Object, Object]),
1806
+ __metadata("design:returntype", Promise)
1807
+ ], OrderModuleService.prototype, "createExchange", null);
1667
1808
  __decorate([
1668
1809
  (0, utils_1.InjectTransactionManager)("baseRepository_"),
1810
+ __param(1, (0, utils_1.MedusaContext)()),
1669
1811
  __metadata("design:type", Function),
1670
1812
  __metadata("design:paramtypes", [Object, Object]),
1671
1813
  __metadata("design:returntype", Promise)
1672
- ], OrderModuleService.prototype, "cancel", null);
1814
+ ], OrderModuleService.prototype, "createClaim_", null);
1815
+ __decorate([
1816
+ (0, utils_1.InjectTransactionManager)("baseRepository_"),
1817
+ __param(1, (0, utils_1.MedusaContext)()),
1818
+ __metadata("design:type", Function),
1819
+ __metadata("design:paramtypes", [Object, Object]),
1820
+ __metadata("design:returntype", Promise)
1821
+ ], OrderModuleService.prototype, "registerFulfillment", null);
1822
+ __decorate([
1823
+ (0, utils_1.InjectTransactionManager)("baseRepository_"),
1824
+ __param(1, (0, utils_1.MedusaContext)()),
1825
+ __metadata("design:type", Function),
1826
+ __metadata("design:paramtypes", [Object, Object]),
1827
+ __metadata("design:returntype", Promise)
1828
+ ], OrderModuleService.prototype, "cancelFulfillment", null);
1829
+ __decorate([
1830
+ (0, utils_1.InjectTransactionManager)("baseRepository_"),
1831
+ __param(1, (0, utils_1.MedusaContext)()),
1832
+ __metadata("design:type", Function),
1833
+ __metadata("design:paramtypes", [Object, Object]),
1834
+ __metadata("design:returntype", Promise)
1835
+ ], OrderModuleService.prototype, "registerShipment", null);
1673
1836
  //# sourceMappingURL=order-module-service.js.map