@medusajs/medusa 1.1.62 → 1.1.63-adminc.21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (150) hide show
  1. package/dist/api/routes/admin/collections/list-collections.d.ts +16 -3
  2. package/dist/api/routes/admin/collections/list-collections.js +88 -10
  3. package/dist/api/routes/admin/collections/list-collections.js.map +1 -1
  4. package/dist/api/routes/admin/discounts/list-discounts.d.ts +6 -0
  5. package/dist/api/routes/admin/discounts/list-discounts.js +45 -8
  6. package/dist/api/routes/admin/discounts/list-discounts.js.map +1 -1
  7. package/dist/api/routes/admin/orders/list-orders.js +1 -1
  8. package/dist/api/routes/admin/orders/list-orders.js.map +1 -1
  9. package/dist/api/routes/admin/products/list-products.js +1 -2
  10. package/dist/api/routes/admin/products/list-products.js.map +1 -1
  11. package/dist/api/routes/admin/tax-rates/add-to-product-types.d.ts +29 -0
  12. package/dist/api/routes/admin/tax-rates/add-to-product-types.js +177 -0
  13. package/dist/api/routes/admin/tax-rates/add-to-product-types.js.map +1 -0
  14. package/dist/api/routes/admin/tax-rates/add-to-products.d.ts +29 -0
  15. package/dist/api/routes/admin/tax-rates/add-to-products.js +173 -0
  16. package/dist/api/routes/admin/tax-rates/add-to-products.js.map +1 -0
  17. package/dist/api/routes/admin/tax-rates/add-to-shipping-options.d.ts +29 -0
  18. package/dist/api/routes/admin/tax-rates/add-to-shipping-options.js +177 -0
  19. package/dist/api/routes/admin/tax-rates/add-to-shipping-options.js.map +1 -0
  20. package/dist/api/routes/admin/tax-rates/create-tax-rate.d.ts +35 -0
  21. package/dist/api/routes/admin/tax-rates/create-tax-rate.js +286 -0
  22. package/dist/api/routes/admin/tax-rates/create-tax-rate.js.map +1 -0
  23. package/dist/api/routes/admin/tax-rates/delete-tax-rate.d.ts +28 -0
  24. package/dist/api/routes/admin/tax-rates/delete-tax-rate.js +84 -0
  25. package/dist/api/routes/admin/tax-rates/delete-tax-rate.js.map +1 -0
  26. package/dist/api/routes/admin/tax-rates/get-tax-rate.d.ts +26 -0
  27. package/dist/api/routes/admin/tax-rates/get-tax-rate.js +106 -0
  28. package/dist/api/routes/admin/tax-rates/get-tax-rate.js.map +1 -0
  29. package/dist/api/routes/admin/tax-rates/index.d.ts +21 -0
  30. package/dist/api/routes/admin/tax-rates/index.js +74 -0
  31. package/dist/api/routes/admin/tax-rates/index.js.map +1 -0
  32. package/dist/api/routes/admin/tax-rates/list-tax-rates.d.ts +44 -0
  33. package/dist/api/routes/admin/tax-rates/list-tax-rates.js +178 -0
  34. package/dist/api/routes/admin/tax-rates/list-tax-rates.js.map +1 -0
  35. package/dist/api/routes/admin/tax-rates/update-tax-rate.d.ts +35 -0
  36. package/dist/api/routes/admin/tax-rates/update-tax-rate.js +286 -0
  37. package/dist/api/routes/admin/tax-rates/update-tax-rate.js.map +1 -0
  38. package/dist/api/routes/admin/tax-rates/utils/get-query-config.d.ts +7 -0
  39. package/dist/api/routes/admin/tax-rates/utils/get-query-config.js +91 -0
  40. package/dist/api/routes/admin/tax-rates/utils/get-query-config.js.map +1 -0
  41. package/dist/api/routes/store/carts/calculate-taxes.d.ts +24 -0
  42. package/dist/api/routes/store/carts/calculate-taxes.js +153 -0
  43. package/dist/api/routes/store/carts/calculate-taxes.js.map +1 -0
  44. package/dist/interfaces/cart-completion-strategy.d.ts +20 -0
  45. package/dist/interfaces/cart-completion-strategy.js +10 -0
  46. package/dist/interfaces/cart-completion-strategy.js.map +1 -0
  47. package/dist/interfaces/index.d.ts +3 -0
  48. package/dist/interfaces/index.js +16 -0
  49. package/dist/interfaces/index.js.map +1 -0
  50. package/dist/interfaces/tax-calculation-strategy.d.ts +16 -0
  51. package/dist/interfaces/tax-calculation-strategy.js +10 -0
  52. package/dist/interfaces/tax-calculation-strategy.js.map +1 -0
  53. package/dist/interfaces/tax-service.d.ts +51 -0
  54. package/dist/interfaces/tax-service.js +3 -0
  55. package/dist/interfaces/tax-service.js.map +1 -0
  56. package/dist/loaders/strategies.d.ts +12 -0
  57. package/dist/loaders/strategies.js +32 -0
  58. package/dist/loaders/strategies.js.map +1 -0
  59. package/dist/migrations/1641636508055-new_tax_system.d.ts +6 -0
  60. package/dist/migrations/1641636508055-new_tax_system.js +248 -0
  61. package/dist/migrations/1641636508055-new_tax_system.js.map +1 -0
  62. package/dist/models/discount.js +2 -1
  63. package/dist/models/discount.js.map +1 -1
  64. package/dist/models/line-item-tax-line.d.ts +7 -0
  65. package/dist/models/line-item-tax-line.js +65 -0
  66. package/dist/models/line-item-tax-line.js.map +1 -0
  67. package/dist/models/product-tax-rate.d.ts +40 -0
  68. package/dist/models/product-tax-rate.js +88 -0
  69. package/dist/models/product-tax-rate.js.map +1 -0
  70. package/dist/models/product-type-tax-rate.d.ts +40 -0
  71. package/dist/models/product-type-tax-rate.js +88 -0
  72. package/dist/models/product-type-tax-rate.js.map +1 -0
  73. package/dist/models/shipping-method-tax-line.d.ts +7 -0
  74. package/dist/models/shipping-method-tax-line.js +65 -0
  75. package/dist/models/shipping-method-tax-line.js.map +1 -0
  76. package/dist/models/shipping-tax-rate.d.ts +40 -0
  77. package/dist/models/shipping-tax-rate.js +88 -0
  78. package/dist/models/shipping-tax-rate.js.map +1 -0
  79. package/dist/models/tax-line.d.ts +39 -0
  80. package/dist/models/tax-line.js +79 -0
  81. package/dist/models/tax-line.js.map +1 -0
  82. package/dist/models/tax-provider.d.ts +17 -0
  83. package/dist/models/tax-provider.js +44 -0
  84. package/dist/models/tax-provider.js.map +1 -0
  85. package/dist/models/tax-rate.d.ts +58 -0
  86. package/dist/models/tax-rate.js +159 -0
  87. package/dist/models/tax-rate.js.map +1 -0
  88. package/dist/repositories/line-item-tax-line.d.ts +4 -0
  89. package/dist/repositories/line-item-tax-line.js +38 -0
  90. package/dist/repositories/line-item-tax-line.js.map +1 -0
  91. package/dist/repositories/product-tax-rate.d.ts +4 -0
  92. package/dist/repositories/product-tax-rate.js +38 -0
  93. package/dist/repositories/product-tax-rate.js.map +1 -0
  94. package/dist/repositories/shipping-method-tax-line.d.ts +4 -0
  95. package/dist/repositories/shipping-method-tax-line.js +38 -0
  96. package/dist/repositories/shipping-method-tax-line.js.map +1 -0
  97. package/dist/repositories/shipping-tax-rate.d.ts +4 -0
  98. package/dist/repositories/shipping-tax-rate.js +38 -0
  99. package/dist/repositories/shipping-tax-rate.js.map +1 -0
  100. package/dist/repositories/tax-rate.d.ts +18 -0
  101. package/dist/repositories/tax-rate.js +359 -0
  102. package/dist/repositories/tax-rate.js.map +1 -0
  103. package/dist/services/product-tax-rate.d.ts +25 -0
  104. package/dist/services/product-tax-rate.js +104 -0
  105. package/dist/services/product-tax-rate.js.map +1 -0
  106. package/dist/services/product-type.d.ts +27 -0
  107. package/dist/services/product-type.js +112 -0
  108. package/dist/services/product-type.js.map +1 -0
  109. package/dist/services/shipping-tax-rate.d.ts +26 -0
  110. package/dist/services/shipping-tax-rate.js +105 -0
  111. package/dist/services/shipping-tax-rate.js.map +1 -0
  112. package/dist/services/system-tax.d.ts +9 -0
  113. package/dist/services/system-tax.js +89 -0
  114. package/dist/services/system-tax.js.map +1 -0
  115. package/dist/services/tax-provider.d.ts +105 -0
  116. package/dist/services/tax-provider.js +455 -0
  117. package/dist/services/tax-provider.js.map +1 -0
  118. package/dist/services/tax-rate.d.ts +31 -0
  119. package/dist/services/tax-rate.js +405 -0
  120. package/dist/services/tax-rate.js.map +1 -0
  121. package/dist/strategies/cart-completion.d.ts +17 -0
  122. package/dist/strategies/cart-completion.js +336 -0
  123. package/dist/strategies/cart-completion.js.map +1 -0
  124. package/dist/strategies/tax-calculation.d.ts +11 -0
  125. package/dist/strategies/tax-calculation.js +147 -0
  126. package/dist/strategies/tax-calculation.js.map +1 -0
  127. package/dist/types/discount.js.map +1 -1
  128. package/dist/types/orders.js +1 -1
  129. package/dist/types/orders.js.map +1 -1
  130. package/dist/types/product-tax-rate.d.ts +10 -0
  131. package/dist/types/product-tax-rate.js +13 -0
  132. package/dist/types/product-tax-rate.js.map +1 -0
  133. package/dist/types/request.d.ts +3 -0
  134. package/dist/types/request.js +3 -0
  135. package/dist/types/request.js.map +1 -0
  136. package/dist/types/shipping-tax-rate.d.ts +10 -0
  137. package/dist/types/shipping-tax-rate.js +13 -0
  138. package/dist/types/shipping-tax-rate.js.map +1 -0
  139. package/dist/types/tax-rate.d.ts +25 -0
  140. package/dist/types/tax-rate.js +3 -0
  141. package/dist/types/tax-rate.js.map +1 -0
  142. package/dist/types/tax-service.d.ts +34 -0
  143. package/dist/types/tax-service.js +3 -0
  144. package/dist/types/tax-service.js.map +1 -0
  145. package/dist/types/totals.d.ts +42 -0
  146. package/dist/types/totals.js +3 -0
  147. package/dist/types/totals.js.map +1 -0
  148. package/jest.config.js +17 -0
  149. package/package.json +3 -3
  150. package/yarn-error.log +79 -5
@@ -0,0 +1,405 @@
1
+ "use strict";
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ if (typeof b !== "function" && b !== null)
11
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
+ extendStatics(d, b);
13
+ function __() { this.constructor = d; }
14
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
+ };
16
+ })();
17
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
18
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
19
+ return new (P || (P = Promise))(function (resolve, reject) {
20
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
21
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
22
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
23
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
24
+ });
25
+ };
26
+ var __generator = (this && this.__generator) || function (thisArg, body) {
27
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
28
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
29
+ function verb(n) { return function (v) { return step([n, v]); }; }
30
+ function step(op) {
31
+ if (f) throw new TypeError("Generator is already executing.");
32
+ while (_) try {
33
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
34
+ if (y = 0, t) op = [op[0] & 2, t.value];
35
+ switch (op[0]) {
36
+ case 0: case 1: t = op; break;
37
+ case 4: _.label++; return { value: op[1], done: false };
38
+ case 5: _.label++; y = op[1]; op = [0]; continue;
39
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
40
+ default:
41
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
42
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
43
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
44
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
45
+ if (t[2]) _.ops.pop();
46
+ _.trys.pop(); continue;
47
+ }
48
+ op = body.call(thisArg, _);
49
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
50
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
51
+ }
52
+ };
53
+ var __values = (this && this.__values) || function(o) {
54
+ var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
55
+ if (m) return m.call(o);
56
+ if (o && typeof o.length === "number") return {
57
+ next: function () {
58
+ if (o && i >= o.length) o = void 0;
59
+ return { value: o && o[i++], done: !o };
60
+ }
61
+ };
62
+ throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
63
+ };
64
+ var __read = (this && this.__read) || function (o, n) {
65
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
66
+ if (!m) return o;
67
+ var i = m.call(o), r, ar = [], e;
68
+ try {
69
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
70
+ }
71
+ catch (error) { e = { error: error }; }
72
+ finally {
73
+ try {
74
+ if (r && !r.done && (m = i["return"])) m.call(i);
75
+ }
76
+ finally { if (e) throw e.error; }
77
+ }
78
+ return ar;
79
+ };
80
+ Object.defineProperty(exports, "__esModule", { value: true });
81
+ var medusa_interfaces_1 = require("medusa-interfaces");
82
+ var medusa_core_utils_1 = require("medusa-core-utils");
83
+ var TaxRateService = /** @class */ (function (_super) {
84
+ __extends(TaxRateService, _super);
85
+ function TaxRateService(_a) {
86
+ var manager = _a.manager, taxRateRepository = _a.taxRateRepository, shippingOptionRepository = _a.shippingOptionRepository;
87
+ var _this = _super.call(this) || this;
88
+ _this.manager_ = manager;
89
+ _this.taxRateRepository_ = taxRateRepository;
90
+ _this.shippingOptionRepository_ = shippingOptionRepository;
91
+ return _this;
92
+ }
93
+ TaxRateService.prototype.withTransaction = function (transactionManager) {
94
+ if (!transactionManager) {
95
+ return this;
96
+ }
97
+ var cloned = new TaxRateService({
98
+ manager: transactionManager,
99
+ taxRateRepository: this.taxRateRepository_,
100
+ shippingOptionRepository: this.shippingOptionRepository_,
101
+ });
102
+ cloned.transactionManager_ = transactionManager;
103
+ cloned.manager_ = transactionManager;
104
+ return cloned;
105
+ };
106
+ TaxRateService.prototype.list = function (selector, config) {
107
+ if (config === void 0) { config = {}; }
108
+ return __awaiter(this, void 0, void 0, function () {
109
+ var taxRateRepo, query;
110
+ return __generator(this, function (_a) {
111
+ switch (_a.label) {
112
+ case 0:
113
+ taxRateRepo = this.manager_.getCustomRepository(this.taxRateRepository_);
114
+ query = this.buildQuery_(selector, config);
115
+ return [4 /*yield*/, taxRateRepo.findWithResolution(query)];
116
+ case 1: return [2 /*return*/, _a.sent()];
117
+ }
118
+ });
119
+ });
120
+ };
121
+ TaxRateService.prototype.listAndCount = function (selector, config) {
122
+ if (config === void 0) { config = {}; }
123
+ return __awaiter(this, void 0, void 0, function () {
124
+ var taxRateRepo, query;
125
+ return __generator(this, function (_a) {
126
+ switch (_a.label) {
127
+ case 0:
128
+ taxRateRepo = this.manager_.getCustomRepository(this.taxRateRepository_);
129
+ query = this.buildQuery_(selector, config);
130
+ return [4 /*yield*/, taxRateRepo.findAndCountWithResolution(query)];
131
+ case 1: return [2 /*return*/, _a.sent()];
132
+ }
133
+ });
134
+ });
135
+ };
136
+ TaxRateService.prototype.retrieve = function (id, config) {
137
+ if (config === void 0) { config = {}; }
138
+ return __awaiter(this, void 0, void 0, function () {
139
+ var _this = this;
140
+ return __generator(this, function (_a) {
141
+ switch (_a.label) {
142
+ case 0: return [4 /*yield*/, this.atomicPhase_(function (manager) { return __awaiter(_this, void 0, void 0, function () {
143
+ var taxRateRepo, query, taxRate;
144
+ return __generator(this, function (_a) {
145
+ switch (_a.label) {
146
+ case 0:
147
+ taxRateRepo = manager.getCustomRepository(this.taxRateRepository_);
148
+ query = this.buildQuery_({ id: id }, config);
149
+ return [4 /*yield*/, taxRateRepo.findOneWithResolution(query)];
150
+ case 1:
151
+ taxRate = _a.sent();
152
+ if (!taxRate) {
153
+ throw new medusa_core_utils_1.MedusaError(medusa_core_utils_1.MedusaError.Types.NOT_FOUND, "TaxRate with ".concat(id, " was not found"));
154
+ }
155
+ return [2 /*return*/, taxRate];
156
+ }
157
+ });
158
+ }); })];
159
+ case 1: return [2 /*return*/, _a.sent()];
160
+ }
161
+ });
162
+ });
163
+ };
164
+ TaxRateService.prototype.create = function (data) {
165
+ return __awaiter(this, void 0, void 0, function () {
166
+ var _this = this;
167
+ return __generator(this, function (_a) {
168
+ switch (_a.label) {
169
+ case 0: return [4 /*yield*/, this.atomicPhase_(function (manager) { return __awaiter(_this, void 0, void 0, function () {
170
+ var taxRateRepo, taxRate;
171
+ return __generator(this, function (_a) {
172
+ switch (_a.label) {
173
+ case 0:
174
+ taxRateRepo = manager.getCustomRepository(this.taxRateRepository_);
175
+ if (typeof data.region_id === "undefined") {
176
+ throw new medusa_core_utils_1.MedusaError(medusa_core_utils_1.MedusaError.Types.INVALID_DATA, "TaxRates must belong to a Region");
177
+ }
178
+ taxRate = taxRateRepo.create(data);
179
+ return [4 /*yield*/, taxRateRepo.save(taxRate)];
180
+ case 1: return [2 /*return*/, _a.sent()];
181
+ }
182
+ });
183
+ }); })];
184
+ case 1: return [2 /*return*/, _a.sent()];
185
+ }
186
+ });
187
+ });
188
+ };
189
+ TaxRateService.prototype.update = function (id, data) {
190
+ return __awaiter(this, void 0, void 0, function () {
191
+ var _this = this;
192
+ return __generator(this, function (_a) {
193
+ switch (_a.label) {
194
+ case 0: return [4 /*yield*/, this.atomicPhase_(function (manager) { return __awaiter(_this, void 0, void 0, function () {
195
+ var taxRateRepo, taxRate, _a, _b, _c, k, v;
196
+ var e_1, _d;
197
+ return __generator(this, function (_e) {
198
+ switch (_e.label) {
199
+ case 0:
200
+ taxRateRepo = manager.getCustomRepository(this.taxRateRepository_);
201
+ return [4 /*yield*/, this.retrieve(id)];
202
+ case 1:
203
+ taxRate = _e.sent();
204
+ try {
205
+ for (_a = __values(Object.entries(data)), _b = _a.next(); !_b.done; _b = _a.next()) {
206
+ _c = __read(_b.value, 2), k = _c[0], v = _c[1];
207
+ if (typeof v !== "undefined") {
208
+ taxRate[k] = v;
209
+ }
210
+ }
211
+ }
212
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
213
+ finally {
214
+ try {
215
+ if (_b && !_b.done && (_d = _a.return)) _d.call(_a);
216
+ }
217
+ finally { if (e_1) throw e_1.error; }
218
+ }
219
+ return [4 /*yield*/, taxRateRepo.save(taxRate)];
220
+ case 2: return [2 /*return*/, _e.sent()];
221
+ }
222
+ });
223
+ }); })];
224
+ case 1: return [2 /*return*/, _a.sent()];
225
+ }
226
+ });
227
+ });
228
+ };
229
+ TaxRateService.prototype.delete = function (id) {
230
+ return __awaiter(this, void 0, void 0, function () {
231
+ var _this = this;
232
+ return __generator(this, function (_a) {
233
+ switch (_a.label) {
234
+ case 0: return [4 /*yield*/, this.atomicPhase_(function (manager) { return __awaiter(_this, void 0, void 0, function () {
235
+ var taxRateRepo, query;
236
+ return __generator(this, function (_a) {
237
+ switch (_a.label) {
238
+ case 0:
239
+ taxRateRepo = manager.getCustomRepository(this.taxRateRepository_);
240
+ query = this.buildQuery_({ id: id });
241
+ return [4 /*yield*/, taxRateRepo.delete(query.where)];
242
+ case 1:
243
+ _a.sent();
244
+ return [2 /*return*/];
245
+ }
246
+ });
247
+ }); })];
248
+ case 1: return [2 /*return*/, _a.sent()];
249
+ }
250
+ });
251
+ });
252
+ };
253
+ TaxRateService.prototype.addToProduct = function (id, productIds) {
254
+ return __awaiter(this, void 0, void 0, function () {
255
+ var _this = this;
256
+ return __generator(this, function (_a) {
257
+ switch (_a.label) {
258
+ case 0: return [4 /*yield*/, this.atomicPhase_(function (manager) { return __awaiter(_this, void 0, void 0, function () {
259
+ var taxRateRepo, ids;
260
+ return __generator(this, function (_a) {
261
+ switch (_a.label) {
262
+ case 0:
263
+ taxRateRepo = manager.getCustomRepository(this.taxRateRepository_);
264
+ if (typeof productIds === "string") {
265
+ ids = [productIds];
266
+ }
267
+ else {
268
+ ids = productIds;
269
+ }
270
+ return [4 /*yield*/, taxRateRepo.addToProduct(id, ids)];
271
+ case 1: return [2 /*return*/, _a.sent()];
272
+ }
273
+ });
274
+ }); })];
275
+ case 1: return [2 /*return*/, _a.sent()];
276
+ }
277
+ });
278
+ });
279
+ };
280
+ TaxRateService.prototype.addToProductType = function (id, productTypeIds) {
281
+ return __awaiter(this, void 0, void 0, function () {
282
+ var _this = this;
283
+ return __generator(this, function (_a) {
284
+ switch (_a.label) {
285
+ case 0: return [4 /*yield*/, this.atomicPhase_(function (manager) { return __awaiter(_this, void 0, void 0, function () {
286
+ var taxRateRepo, ids;
287
+ return __generator(this, function (_a) {
288
+ switch (_a.label) {
289
+ case 0:
290
+ taxRateRepo = manager.getCustomRepository(this.taxRateRepository_);
291
+ if (typeof productTypeIds === "string") {
292
+ ids = [productTypeIds];
293
+ }
294
+ else {
295
+ ids = productTypeIds;
296
+ }
297
+ return [4 /*yield*/, taxRateRepo.addToProductType(id, ids)];
298
+ case 1: return [2 /*return*/, _a.sent()];
299
+ }
300
+ });
301
+ }); })];
302
+ case 1: return [2 /*return*/, _a.sent()];
303
+ }
304
+ });
305
+ });
306
+ };
307
+ TaxRateService.prototype.addToShippingOption = function (id, optionIds) {
308
+ return __awaiter(this, void 0, void 0, function () {
309
+ var _this = this;
310
+ return __generator(this, function (_a) {
311
+ switch (_a.label) {
312
+ case 0: return [4 /*yield*/, this.atomicPhase_(function (manager) { return __awaiter(_this, void 0, void 0, function () {
313
+ var taxRateRepo, shippingOptionRepo, ids, taxRate, query, options, options_1, options_1_1, o;
314
+ var e_2, _a;
315
+ return __generator(this, function (_b) {
316
+ switch (_b.label) {
317
+ case 0:
318
+ taxRateRepo = manager.getCustomRepository(this.taxRateRepository_);
319
+ shippingOptionRepo = manager.getCustomRepository(this.shippingOptionRepository_);
320
+ if (typeof optionIds === "string") {
321
+ ids = [optionIds];
322
+ }
323
+ else {
324
+ ids = optionIds;
325
+ }
326
+ return [4 /*yield*/, this.retrieve(id, { select: ["id", "region_id"] })];
327
+ case 1:
328
+ taxRate = _b.sent();
329
+ query = this.buildQuery_({ id: ids }, { select: ["id", "region_id"] });
330
+ return [4 /*yield*/, shippingOptionRepo.find(query)];
331
+ case 2:
332
+ options = _b.sent();
333
+ try {
334
+ for (options_1 = __values(options), options_1_1 = options_1.next(); !options_1_1.done; options_1_1 = options_1.next()) {
335
+ o = options_1_1.value;
336
+ if (o.region_id !== taxRate.region_id) {
337
+ throw new medusa_core_utils_1.MedusaError(medusa_core_utils_1.MedusaError.Types.NOT_ALLOWED, "Shipping Option and Tax Rate must belong to the same Region to be associated. Shipping Option with id: ".concat(o.id, " belongs to Region with id: ").concat(o.region_id, " and Tax Rate with id: ").concat(taxRate.id, " belongs to Region with id: ").concat(taxRate.region_id));
338
+ }
339
+ }
340
+ }
341
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
342
+ finally {
343
+ try {
344
+ if (options_1_1 && !options_1_1.done && (_a = options_1.return)) _a.call(options_1);
345
+ }
346
+ finally { if (e_2) throw e_2.error; }
347
+ }
348
+ return [4 /*yield*/, taxRateRepo.addToShippingOption(id, ids)];
349
+ case 3: return [2 /*return*/, _b.sent()];
350
+ }
351
+ });
352
+ }); })];
353
+ case 1: return [2 /*return*/, _a.sent()];
354
+ }
355
+ });
356
+ });
357
+ };
358
+ TaxRateService.prototype.listByProduct = function (productId, config) {
359
+ return __awaiter(this, void 0, void 0, function () {
360
+ var _this = this;
361
+ return __generator(this, function (_a) {
362
+ switch (_a.label) {
363
+ case 0: return [4 /*yield*/, this.atomicPhase_(function (manager) { return __awaiter(_this, void 0, void 0, function () {
364
+ var taxRateRepo;
365
+ return __generator(this, function (_a) {
366
+ switch (_a.label) {
367
+ case 0:
368
+ taxRateRepo = manager.getCustomRepository(this.taxRateRepository_);
369
+ return [4 /*yield*/, taxRateRepo.listByProduct(productId, config)];
370
+ case 1: return [2 /*return*/, _a.sent()];
371
+ }
372
+ });
373
+ }); })];
374
+ case 1:
375
+ // Check both ProductTaxRate + ProductTypeTaxRate
376
+ return [2 /*return*/, _a.sent()];
377
+ }
378
+ });
379
+ });
380
+ };
381
+ TaxRateService.prototype.listByShippingOption = function (shippingOptionId, config) {
382
+ return __awaiter(this, void 0, void 0, function () {
383
+ var _this = this;
384
+ return __generator(this, function (_a) {
385
+ switch (_a.label) {
386
+ case 0: return [4 /*yield*/, this.atomicPhase_(function (manager) { return __awaiter(_this, void 0, void 0, function () {
387
+ var taxRateRepo;
388
+ return __generator(this, function (_a) {
389
+ switch (_a.label) {
390
+ case 0:
391
+ taxRateRepo = manager.getCustomRepository(this.taxRateRepository_);
392
+ return [4 /*yield*/, taxRateRepo.listByShippingOption(shippingOptionId, config)];
393
+ case 1: return [2 /*return*/, _a.sent()];
394
+ }
395
+ });
396
+ }); })];
397
+ case 1: return [2 /*return*/, _a.sent()];
398
+ }
399
+ });
400
+ });
401
+ };
402
+ return TaxRateService;
403
+ }(medusa_interfaces_1.BaseService));
404
+ exports.default = TaxRateService;
405
+ //# sourceMappingURL=tax-rate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tax-rate.js","sourceRoot":"","sources":["../../src/services/tax-rate.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,uDAA+C;AAE/C,uDAA+C;AAe/C;IAA6B,kCAAW;IAKtC,wBAAY,EAAwD;YAAtD,OAAO,aAAA,EAAE,iBAAiB,uBAAA,EAAE,wBAAwB,8BAAA;QAAlE,YACE,iBAAO,SAKR;QAHC,KAAI,CAAC,QAAQ,GAAG,OAAO,CAAA;QACvB,KAAI,CAAC,kBAAkB,GAAG,iBAAiB,CAAA;QAC3C,KAAI,CAAC,yBAAyB,GAAG,wBAAwB,CAAA;;IAC3D,CAAC;IAED,wCAAe,GAAf,UAAgB,kBAAiC;QAC/C,IAAI,CAAC,kBAAkB,EAAE;YACvB,OAAO,IAAI,CAAA;SACZ;QAED,IAAM,MAAM,GAAG,IAAI,cAAc,CAAC;YAChC,OAAO,EAAE,kBAAkB;YAC3B,iBAAiB,EAAE,IAAI,CAAC,kBAAkB;YAC1C,wBAAwB,EAAE,IAAI,CAAC,yBAAyB;SACzD,CAAC,CAAA;QAEF,MAAM,CAAC,mBAAmB,GAAG,kBAAkB,CAAA;QAC/C,MAAM,CAAC,QAAQ,GAAG,kBAAkB,CAAA;QAEpC,OAAO,MAAM,CAAA;IACf,CA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B,OAAO,CAAC,SAAS,CAAE,CAC/O,CAAA;iDACF;6CACF;;;;;;;;;wCAEM,qBAAM,WAAW,CAAC,mBAAmB,CAAC,EAAE,EAAE,GAAG,CAAC,EAAA;4CAArD,sBAAO,SAA8C,EAAA;;;6BACtD,CAAC,EAAA;4BA7BF,sBAAO,SA6BL,EAAA;;;;KACH;IAEK,sCAAa,GAAnB,UACE,SAAiB,EACjB,MAA2B;;;;;4BAGpB,qBAAM,IAAI,CAAC,YAAY,CAAC,UAAO,OAAsB;;;;;wCACpD,WAAW,GAAG,OAAO,CAAC,mBAAmB,CAAC,IAAI,CAAC,kBAAkB,CAAC,CAAA;wCACjE,qBAAM,WAAW,CAAC,aAAa,CAAC,SAAS,EAAE,MAAM,CAAC,EAAA;4CAAzD,sBAAO,SAAkD,EAAA;;;6BAC1D,CAAC,EAAA;;oBAJF,iDAAiD;oBACjD,sBAAO,SAGL,EAAA;;;;KACH;IAEK,6CAAoB,GAA1B,UACE,gBAAwB,EACxB,MAA2B;;;;;4BAEpB,qBAAM,IAAI,CAAC,YAAY,CAAC,UAAO,OAAsB;;;;;wCACpD,WAAW,GAAG,OAAO,CAAC,mBAAmB,CAAC,IAAI,CAAC,kBAAkB,CAAC,CAAA;wCACjE,qBAAM,WAAW,CAAC,oBAAoB,CAAC,gBAAgB,EAAE,MAAM,CAAC,EAAA;4CAAvE,sBAAO,SAAgE,EAAA;;;6BACxE,CAAC,EAAA;4BAHF,sBAAO,SAGL,EAAA;;;;KACH;IACH,qBAAC;AAAD,CAAC,AA3MD,CAA6B,+BAAW,GA2MvC;AAED,kBAAe,cAAc,CAAA"}
@@ -0,0 +1,17 @@
1
+ import { IdempotencyKey } from "../models/idempotency-key";
2
+ import { RequestContext } from "../types/request";
3
+ import { ICartCompletionStrategy, CartCompletionResponse } from "../interfaces";
4
+ declare class CartCompletionStrategy implements ICartCompletionStrategy {
5
+ private idempotencyKeyService_;
6
+ private cartService_;
7
+ private orderService_;
8
+ private swapService_;
9
+ constructor({ idempotencyKeyService, cartService, orderService, swapService, }: {
10
+ idempotencyKeyService: any;
11
+ cartService: any;
12
+ orderService: any;
13
+ swapService: any;
14
+ });
15
+ complete(id: string, ikey: IdempotencyKey, context: RequestContext): Promise<CartCompletionResponse>;
16
+ }
17
+ export default CartCompletionStrategy;