@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,455 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
54
+ var medusa_core_utils_1 = require("medusa-core-utils");
55
+ var medusa_interfaces_1 = require("medusa-interfaces");
56
+ var cart_1 = require("../types/cart");
57
+ var CACHE_TIME = 30; // seconds
58
+ /**
59
+ * Finds tax providers and assists in tax related operations.
60
+ */
61
+ var TaxProviderService = /** @class */ (function (_super) {
62
+ __extends(TaxProviderService, _super);
63
+ function TaxProviderService(container) {
64
+ var _this = _super.call(this) || this;
65
+ _this.container_ = container;
66
+ _this.taxLineRepo_ = container["lineItemTaxLineRepository"];
67
+ _this.smTaxLineRepo_ = container["shippingMethodTaxLineRepository"];
68
+ _this.taxRateService_ = container["taxRateService"];
69
+ _this.eventBus_ = container["eventBusService"];
70
+ _this.manager_ = container["manager"];
71
+ _this.redis_ = container["redisClient"];
72
+ return _this;
73
+ }
74
+ TaxProviderService.prototype.withTransaction = function (transactionManager) {
75
+ if (!transactionManager) {
76
+ return this;
77
+ }
78
+ var cloned = new TaxProviderService(this.container_);
79
+ cloned.transactionManager_ = transactionManager;
80
+ cloned.manager_ = transactionManager;
81
+ return cloned;
82
+ };
83
+ /**
84
+ * Retrieves the relevant tax provider for the given region.
85
+ * @param region - the region to get tax provider for.
86
+ * @return the region specific tax provider
87
+ */
88
+ TaxProviderService.prototype.retrieveProvider = function (region) {
89
+ var provider;
90
+ if (region.tax_provider_id) {
91
+ provider = this.container_["tp_".concat(region.tax_provider_id)];
92
+ }
93
+ else {
94
+ provider = this.container_["systemTaxService"];
95
+ }
96
+ if (!provider) {
97
+ throw new medusa_core_utils_1.MedusaError(medusa_core_utils_1.MedusaError.Types.NOT_FOUND, "Could not find a tax provider with id: ".concat(region.tax_provider_id));
98
+ }
99
+ return provider;
100
+ };
101
+ /**
102
+ * Persists the tax lines relevant for an order to the database.
103
+ * @param cartOrLineItems - the cart or line items to create tax lines for
104
+ * @param calculationContext - the calculation context to get tax lines by
105
+ * @return the newly created tax lines
106
+ */
107
+ TaxProviderService.prototype.createTaxLines = function (cartOrLineItems, calculationContext) {
108
+ return __awaiter(this, void 0, void 0, function () {
109
+ var taxLines;
110
+ return __generator(this, function (_a) {
111
+ switch (_a.label) {
112
+ case 0:
113
+ taxLines = [];
114
+ if (!(0, cart_1.isCart)(cartOrLineItems)) return [3 /*break*/, 2];
115
+ return [4 /*yield*/, this.getTaxLines(cartOrLineItems.items, calculationContext)];
116
+ case 1:
117
+ taxLines = _a.sent();
118
+ return [3 /*break*/, 4];
119
+ case 2: return [4 /*yield*/, this.getTaxLines(cartOrLineItems, calculationContext)];
120
+ case 3:
121
+ taxLines = _a.sent();
122
+ _a.label = 4;
123
+ case 4: return [2 /*return*/, this.manager_.save(taxLines)];
124
+ }
125
+ });
126
+ });
127
+ };
128
+ /**
129
+ * Persists the tax lines relevant for a shipping method to the database. Used
130
+ * for return shipping methods.
131
+ * @param shippingMethod - the shipping method to create tax lines for
132
+ * @param calculationContext - the calculation context to get tax lines by
133
+ * @return the newly created tax lines
134
+ */
135
+ TaxProviderService.prototype.createShippingTaxLines = function (shippingMethod, calculationContext) {
136
+ return __awaiter(this, void 0, void 0, function () {
137
+ var taxLines;
138
+ return __generator(this, function (_a) {
139
+ switch (_a.label) {
140
+ case 0: return [4 /*yield*/, this.getShippingTaxLines(shippingMethod, calculationContext)];
141
+ case 1:
142
+ taxLines = _a.sent();
143
+ return [2 /*return*/, this.manager_.save(taxLines)];
144
+ }
145
+ });
146
+ });
147
+ };
148
+ /**
149
+ * Gets the relevant tax lines for a shipping method. Note: this method
150
+ * doesn't persist the tax lines. Use createShippingTaxLines if you wish to
151
+ * persist the tax lines to the DB layer.
152
+ * @param shippingMethod - the shipping method to get tax lines for
153
+ * @param calculationContext - the calculation context to get tax lines by
154
+ * @return the computed tax lines
155
+ */
156
+ TaxProviderService.prototype.getShippingTaxLines = function (shippingMethod, calculationContext) {
157
+ return __awaiter(this, void 0, void 0, function () {
158
+ var calculationLines, taxProvider, providerLines, smTaxLineRepo;
159
+ var _a;
160
+ return __generator(this, function (_b) {
161
+ switch (_b.label) {
162
+ case 0:
163
+ _a = {
164
+ shipping_method: shippingMethod
165
+ };
166
+ return [4 /*yield*/, this.getRegionRatesForShipping(shippingMethod.shipping_option_id, calculationContext.region)];
167
+ case 1:
168
+ calculationLines = [
169
+ (_a.rates = _b.sent(),
170
+ _a)
171
+ ];
172
+ taxProvider = this.retrieveProvider(calculationContext.region);
173
+ return [4 /*yield*/, taxProvider.getTaxLines([], calculationLines, calculationContext)];
174
+ case 2:
175
+ providerLines = _b.sent();
176
+ smTaxLineRepo = this.manager_.getCustomRepository(this.smTaxLineRepo_);
177
+ // .create only creates entities nothing is persisted in DB
178
+ return [2 /*return*/, providerLines.map(function (pl) {
179
+ if (!("shipping_method_id" in pl)) {
180
+ throw new medusa_core_utils_1.MedusaError(medusa_core_utils_1.MedusaError.Types.UNEXPECTED_STATE, "Expected only shipping method tax lines");
181
+ }
182
+ return smTaxLineRepo.create({
183
+ shipping_method_id: pl.shipping_method_id,
184
+ rate: pl.rate,
185
+ name: pl.name,
186
+ code: pl.code,
187
+ metadata: pl.metadata,
188
+ });
189
+ })];
190
+ }
191
+ });
192
+ });
193
+ };
194
+ /**
195
+ * Gets the relevant tax lines for an order or cart. If an order is provided
196
+ * the order's tax lines will be returned. If a cart is provided the tax lines
197
+ * will be computed from the tax rules and potentially a 3rd party tax plugin.
198
+ * Note: this method doesn't persist the tax lines. Use createTaxLines if you
199
+ * wish to persist the tax lines to the DB layer.
200
+ * @param lineItems - the cart or order to get tax lines for
201
+ * @param calculationContext - the calculation context to get tax lines by
202
+ * @return the computed tax lines
203
+ */
204
+ TaxProviderService.prototype.getTaxLines = function (lineItems, calculationContext) {
205
+ return __awaiter(this, void 0, void 0, function () {
206
+ var calculationLines, shippingCalculationLines, taxProvider, providerLines, liTaxLineRepo, smTaxLineRepo;
207
+ var _this = this;
208
+ return __generator(this, function (_a) {
209
+ switch (_a.label) {
210
+ case 0: return [4 /*yield*/, Promise.all(lineItems.map(function (l) { return __awaiter(_this, void 0, void 0, function () {
211
+ var _a;
212
+ return __generator(this, function (_b) {
213
+ switch (_b.label) {
214
+ case 0:
215
+ if (l.is_return) {
216
+ return [2 /*return*/, null];
217
+ }
218
+ if (!(l.variant && l.variant.product_id)) return [3 /*break*/, 2];
219
+ _a = {
220
+ item: l
221
+ };
222
+ return [4 /*yield*/, this.getRegionRatesForProduct(l.variant.product_id, calculationContext.region)];
223
+ case 1: return [2 /*return*/, (_a.rates = _b.sent(),
224
+ _a)];
225
+ case 2:
226
+ /*
227
+ * If the line item is custom and therefore not associated with a
228
+ * product we assume no taxes - we should consider adding rate overrides
229
+ * to custom lines at some point
230
+ */
231
+ return [2 /*return*/, {
232
+ item: l,
233
+ rates: [],
234
+ }];
235
+ }
236
+ });
237
+ }); }))];
238
+ case 1:
239
+ calculationLines = _a.sent();
240
+ return [4 /*yield*/, Promise.all(calculationContext.shipping_methods.map(function (sm) { return __awaiter(_this, void 0, void 0, function () {
241
+ var _a;
242
+ return __generator(this, function (_b) {
243
+ switch (_b.label) {
244
+ case 0:
245
+ _a = {
246
+ shipping_method: sm
247
+ };
248
+ return [4 /*yield*/, this.getRegionRatesForShipping(sm.shipping_option_id, calculationContext.region)];
249
+ case 1: return [2 /*return*/, (_a.rates = _b.sent(),
250
+ _a)];
251
+ }
252
+ });
253
+ }); }))];
254
+ case 2:
255
+ shippingCalculationLines = _a.sent();
256
+ taxProvider = this.retrieveProvider(calculationContext.region);
257
+ return [4 /*yield*/, taxProvider.getTaxLines(calculationLines.filter(function (v) { return v !== null; }), shippingCalculationLines, calculationContext)];
258
+ case 3:
259
+ providerLines = _a.sent();
260
+ liTaxLineRepo = this.manager_.getCustomRepository(this.taxLineRepo_);
261
+ smTaxLineRepo = this.manager_.getCustomRepository(this.smTaxLineRepo_);
262
+ // .create only creates entities nothing is persisted in DB
263
+ return [2 /*return*/, providerLines.map(function (pl) {
264
+ if ("shipping_method_id" in pl) {
265
+ return smTaxLineRepo.create({
266
+ shipping_method_id: pl.shipping_method_id,
267
+ rate: pl.rate,
268
+ name: pl.name,
269
+ code: pl.code,
270
+ metadata: pl.metadata,
271
+ });
272
+ }
273
+ if (!("item_id" in pl)) {
274
+ throw new medusa_core_utils_1.MedusaError(medusa_core_utils_1.MedusaError.Types.UNEXPECTED_STATE, "Tax Provider returned invalid tax lines");
275
+ }
276
+ return liTaxLineRepo.create({
277
+ item_id: pl.item_id,
278
+ rate: pl.rate,
279
+ name: pl.name,
280
+ code: pl.code,
281
+ metadata: pl.metadata,
282
+ });
283
+ })];
284
+ }
285
+ });
286
+ });
287
+ };
288
+ /**
289
+ * Gets the tax rates configured for a shipping option. The rates are cached
290
+ * between calls.
291
+ * @param optionId - the option id of the shipping method.
292
+ * @param region - the region to get configured rates for.
293
+ * @return the tax rates configured for the shipping option.
294
+ */
295
+ TaxProviderService.prototype.getRegionRatesForShipping = function (optionId, region) {
296
+ return __awaiter(this, void 0, void 0, function () {
297
+ var cacheHit, toReturn, optionRates;
298
+ return __generator(this, function (_a) {
299
+ switch (_a.label) {
300
+ case 0: return [4 /*yield*/, this.getCacheEntry(optionId, region.id)];
301
+ case 1:
302
+ cacheHit = _a.sent();
303
+ if (cacheHit) {
304
+ return [2 /*return*/, cacheHit];
305
+ }
306
+ toReturn = [];
307
+ return [4 /*yield*/, this.taxRateService_.listByShippingOption(optionId, { region_id: region.id })];
308
+ case 2:
309
+ optionRates = _a.sent();
310
+ if (optionRates.length > 0) {
311
+ toReturn = optionRates.map(function (pr) {
312
+ return {
313
+ rate: pr.rate,
314
+ name: pr.name,
315
+ code: pr.code,
316
+ };
317
+ });
318
+ }
319
+ if (toReturn.length === 0) {
320
+ toReturn = [
321
+ {
322
+ rate: region.tax_rate,
323
+ name: "default",
324
+ code: "default",
325
+ },
326
+ ];
327
+ }
328
+ return [4 /*yield*/, this.setCache(optionId, region.id, toReturn)];
329
+ case 3:
330
+ _a.sent();
331
+ return [2 /*return*/, toReturn];
332
+ }
333
+ });
334
+ });
335
+ };
336
+ /**
337
+ * Gets the tax rates configured for a product. The rates are cached between
338
+ * calls.
339
+ * @param productId - the product id to get rates for
340
+ * @param region - the region to get configured rates for.
341
+ * @return the tax rates configured for the shipping option.
342
+ */
343
+ TaxProviderService.prototype.getRegionRatesForProduct = function (productId, region) {
344
+ return __awaiter(this, void 0, void 0, function () {
345
+ var cacheHit, toReturn, productRates;
346
+ return __generator(this, function (_a) {
347
+ switch (_a.label) {
348
+ case 0: return [4 /*yield*/, this.getCacheEntry(productId, region.id)];
349
+ case 1:
350
+ cacheHit = _a.sent();
351
+ if (cacheHit) {
352
+ return [2 /*return*/, cacheHit];
353
+ }
354
+ toReturn = [];
355
+ return [4 /*yield*/, this.taxRateService_.listByProduct(productId, {
356
+ region_id: region.id,
357
+ })];
358
+ case 2:
359
+ productRates = _a.sent();
360
+ if (productRates.length > 0) {
361
+ toReturn = productRates.map(function (pr) {
362
+ return {
363
+ rate: pr.rate,
364
+ name: pr.name,
365
+ code: pr.code,
366
+ };
367
+ });
368
+ }
369
+ if (toReturn.length === 0) {
370
+ toReturn = [
371
+ {
372
+ rate: region.tax_rate,
373
+ name: "default",
374
+ code: "default",
375
+ },
376
+ ];
377
+ }
378
+ return [4 /*yield*/, this.setCache(productId, region.id, toReturn)];
379
+ case 3:
380
+ _a.sent();
381
+ return [2 /*return*/, toReturn];
382
+ }
383
+ });
384
+ });
385
+ };
386
+ /**
387
+ * The cache key to get cache hits by.
388
+ * @param productId - the product id to cache
389
+ * @param regionId - the region id to cache
390
+ * @return the cache key to use for the id set
391
+ */
392
+ TaxProviderService.prototype.getCacheKey = function (productId, regionId) {
393
+ return "txrtcache:".concat(productId, ":").concat(regionId);
394
+ };
395
+ /**
396
+ * Sets the cache results for a set of ids
397
+ * @param productId - the product id to cache
398
+ * @param regionId - the region id to cache
399
+ * @param value - tax rates to cache
400
+ * @return promise that resolves after the cache has been set
401
+ */
402
+ TaxProviderService.prototype.setCache = function (productId, regionId, value) {
403
+ return __awaiter(this, void 0, void 0, function () {
404
+ var cacheKey;
405
+ return __generator(this, function (_a) {
406
+ switch (_a.label) {
407
+ case 0:
408
+ cacheKey = this.getCacheKey(productId, regionId);
409
+ return [4 /*yield*/, this.redis_.set(cacheKey, JSON.stringify(value), "EX", CACHE_TIME)];
410
+ case 1: return [2 /*return*/, _a.sent()];
411
+ }
412
+ });
413
+ });
414
+ };
415
+ /**
416
+ * Gets the cache results for a set of ids
417
+ * @param productId - the product id to cache
418
+ * @param regionId - the region id to cache
419
+ * @return the cached result or null
420
+ */
421
+ TaxProviderService.prototype.getCacheEntry = function (productId, regionId) {
422
+ return __awaiter(this, void 0, void 0, function () {
423
+ var cacheKey, cacheHit, parsedResults, _1;
424
+ return __generator(this, function (_a) {
425
+ switch (_a.label) {
426
+ case 0:
427
+ cacheKey = this.getCacheKey(productId, regionId);
428
+ _a.label = 1;
429
+ case 1:
430
+ _a.trys.push([1, 3, , 5]);
431
+ return [4 /*yield*/, this.redis_.get(cacheKey)];
432
+ case 2:
433
+ cacheHit = _a.sent();
434
+ if (cacheHit) {
435
+ parsedResults = JSON.parse(cacheHit);
436
+ return [2 /*return*/, parsedResults];
437
+ }
438
+ return [3 /*break*/, 5];
439
+ case 3:
440
+ _1 = _a.sent();
441
+ // noop - cache parse failed
442
+ return [4 /*yield*/, this.redis_.del(cacheKey)];
443
+ case 4:
444
+ // noop - cache parse failed
445
+ _a.sent();
446
+ return [3 /*break*/, 5];
447
+ case 5: return [2 /*return*/, null];
448
+ }
449
+ });
450
+ });
451
+ };
452
+ return TaxProviderService;
453
+ }(medusa_interfaces_1.BaseService));
454
+ exports.default = TaxProviderService;
455
+ //# sourceMappingURL=tax-provider.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tax-provider.js","sourceRoot":"","sources":["../../src/services/tax-provider.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,uDAA+C;AAE/C,uDAA+C;AAY/C,sCAAsC;AAWtC,IAAM,UAAU,GAAG,EAAE,CAAA,CAAC,UAAU;AAEhC;;GAEG;AACH;IAAiC,sCAAW;IAS1C,4BAAY,SAA0B;QAAtC,YACE,iBAAO,SASR;QAPC,KAAI,CAAC,UAAU,GAAG,SAAS,CAAA;Q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EjB,QAAQ,GAAG,IAAI,CAAC,WAAW,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAA;wBAC/C,qBAAM,IAAI,CAAC,MAAM,CAAC,GAAG,CAC1B,QAAQ,EACR,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,EACrB,IAAI,EACJ,UAAU,CACX,EAAA;4BALD,sBAAO,SAKN,EAAA;;;;KACF;IAED;;;;;OAKG;IACW,0CAAa,GAA3B,UACE,SAAiB,EACjB,QAAgB;;;;;;wBAEV,QAAQ,GAAG,IAAI,CAAC,WAAW,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAA;;;;wBAGnC,qBAAM,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAA;;wBAA1C,QAAQ,GAAG,SAA+B;wBAChD,IAAI,QAAQ,EAAE;4BAEN,aAAa,GAAG,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAqB,CAAA;4BAC9D,sBAAO,aAAa,EAAA;yBACrB;;;;wBAED,4BAA4B;wBAC5B,qBAAM,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAA;;wBAD/B,4BAA4B;wBAC5B,SAA+B,CAAA;;4BAGjC,sBAAO,IAAI,EAAA;;;;KACZ;IACH,yBAAC;AAAD,CAAC,AAvYD,CAAiC,+BAAW,GAuY3C;AAED,kBAAe,kBAAkB,CAAA"}
@@ -0,0 +1,31 @@
1
+ import { BaseService } from "medusa-interfaces";
2
+ import { EntityManager } from "typeorm";
3
+ import { TaxRate } from "../models/tax-rate";
4
+ import { ShippingTaxRate } from "../models/shipping-tax-rate";
5
+ import { ProductTaxRate } from "../models/product-tax-rate";
6
+ import { ProductTypeTaxRate } from "../models/product-type-tax-rate";
7
+ import { FindConfig } from "../types/common";
8
+ import { CreateTaxRateInput, UpdateTaxRateInput, TaxRateListByConfig, FilterableTaxRateProps } from "../types/tax-rate";
9
+ declare class TaxRateService extends BaseService {
10
+ private manager_;
11
+ private taxRateRepository_;
12
+ private shippingOptionRepository_;
13
+ constructor({ manager, taxRateRepository, shippingOptionRepository }: {
14
+ manager: any;
15
+ taxRateRepository: any;
16
+ shippingOptionRepository: any;
17
+ });
18
+ withTransaction(transactionManager: EntityManager): TaxRateService;
19
+ list(selector: FilterableTaxRateProps, config?: FindConfig<TaxRate>): Promise<TaxRate[]>;
20
+ listAndCount(selector: FilterableTaxRateProps, config?: FindConfig<TaxRate>): Promise<[TaxRate[], number]>;
21
+ retrieve(id: string, config?: FindConfig<TaxRate>): Promise<TaxRate>;
22
+ create(data: CreateTaxRateInput): Promise<TaxRate>;
23
+ update(id: string, data: UpdateTaxRateInput): Promise<TaxRate>;
24
+ delete(id: string | string[]): Promise<void>;
25
+ addToProduct(id: string, productIds: string | string[]): Promise<ProductTaxRate | ProductTaxRate[]>;
26
+ addToProductType(id: string, productTypeIds: string | string[]): Promise<ProductTypeTaxRate[]>;
27
+ addToShippingOption(id: string, optionIds: string | string[]): Promise<ShippingTaxRate>;
28
+ listByProduct(productId: string, config: TaxRateListByConfig): Promise<TaxRate[]>;
29
+ listByShippingOption(shippingOptionId: string, config: TaxRateListByConfig): Promise<TaxRate[]>;
30
+ }
31
+ export default TaxRateService;