@medusajs/medusa 1.3.0 → 1.3.1-next.26
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.
- package/dist/api/routes/admin/discounts/create-condition.d.ts +58 -0
- package/dist/api/routes/admin/discounts/create-condition.js +186 -0
- package/dist/api/routes/admin/discounts/create-condition.js.map +1 -0
- package/dist/api/routes/admin/discounts/create-discount.js +0 -1
- package/dist/api/routes/admin/discounts/create-discount.js.map +1 -1
- package/dist/api/routes/admin/discounts/delete-condition.d.ts +36 -0
- package/dist/api/routes/admin/discounts/delete-condition.js +151 -0
- package/dist/api/routes/admin/discounts/delete-condition.js.map +1 -0
- package/dist/api/routes/admin/discounts/get-condition.d.ts +31 -0
- package/dist/api/routes/admin/discounts/get-condition.js +125 -0
- package/dist/api/routes/admin/discounts/get-condition.js.map +1 -0
- package/dist/api/routes/admin/discounts/index.d.ts +10 -0
- package/dist/api/routes/admin/discounts/index.js +12 -1
- package/dist/api/routes/admin/discounts/index.js.map +1 -1
- package/dist/api/routes/admin/discounts/update-condition.d.ts +55 -0
- package/dist/api/routes/admin/discounts/update-condition.js +184 -0
- package/dist/api/routes/admin/discounts/update-condition.js.map +1 -0
- package/dist/api/routes/admin/orders/create-claim.js +6 -0
- package/dist/api/routes/admin/orders/create-claim.js.map +1 -1
- package/dist/api/routes/admin/price-lists/index.js +1 -1
- package/dist/api/routes/admin/price-lists/index.js.map +1 -1
- package/dist/api/routes/admin/price-lists/list-price-list-products.js +62 -21
- package/dist/api/routes/admin/price-lists/list-price-list-products.js.map +1 -1
- package/dist/api/routes/admin/product-tags/list-product-tags.d.ts +2 -1
- package/dist/api/routes/admin/product-tags/list-product-tags.js +6 -3
- package/dist/api/routes/admin/product-tags/list-product-tags.js.map +1 -1
- package/dist/api/routes/admin/product-types/list-product-types.d.ts +2 -1
- package/dist/api/routes/admin/product-types/list-product-types.js +6 -3
- package/dist/api/routes/admin/product-types/list-product-types.js.map +1 -1
- package/dist/api/routes/admin/products/index.d.ts +2 -1
- package/dist/api/routes/admin/products/index.js +7 -2
- package/dist/api/routes/admin/products/index.js.map +1 -1
- package/dist/api/routes/admin/products/list-variants.d.ts +35 -0
- package/dist/api/routes/admin/products/list-variants.js +173 -0
- package/dist/api/routes/admin/products/list-variants.js.map +1 -0
- package/dist/api/routes/admin/shipping-options/list-shipping-options.d.ts +2 -2
- package/dist/api/routes/admin/shipping-options/list-shipping-options.js +2 -2
- package/dist/api/routes/admin/shipping-options/list-shipping-options.js.map +1 -1
- package/dist/commands/develop.js +1 -1
- package/dist/commands/develop.js.map +1 -1
- package/dist/helpers/test-request.js +11 -10
- package/dist/helpers/test-request.js.map +1 -1
- package/dist/interfaces/index.d.ts +1 -1
- package/dist/interfaces/index.js +1 -1
- package/dist/interfaces/index.js.map +1 -1
- package/dist/interfaces/transaction-base-service.d.ts +23 -0
- package/dist/interfaces/{base-service.js → transaction-base-service.js} +38 -216
- package/dist/interfaces/transaction-base-service.js.map +1 -0
- package/dist/loaders/plugins.d.ts +20 -0
- package/dist/loaders/plugins.js +3 -2
- package/dist/loaders/plugins.js.map +1 -1
- package/dist/models/discount-condition.js +3 -0
- package/dist/models/discount-condition.js.map +1 -1
- package/dist/repositories/discount-condition.d.ts +4 -0
- package/dist/repositories/discount-condition.js +13 -0
- package/dist/repositories/discount-condition.js.map +1 -1
- package/dist/repositories/money-amount.d.ts +1 -0
- package/dist/repositories/money-amount.js +28 -6
- package/dist/repositories/money-amount.js.map +1 -1
- package/dist/repositories/order.d.ts +1 -1
- package/dist/repositories/price-list.d.ts +8 -1
- package/dist/repositories/price-list.js +209 -0
- package/dist/repositories/price-list.js.map +1 -1
- package/dist/services/cart.d.ts +12 -12
- package/dist/services/cart.js +130 -157
- package/dist/services/cart.js.map +1 -1
- package/dist/services/claim.js +62 -19
- package/dist/services/claim.js.map +1 -1
- package/dist/services/customer.d.ts +0 -7
- package/dist/services/customer.js +4 -33
- package/dist/services/customer.js.map +1 -1
- package/dist/services/discount-condition.d.ts +31 -0
- package/dist/services/discount-condition.js +223 -0
- package/dist/services/discount-condition.js.map +1 -0
- package/dist/services/discount.d.ts +4 -8
- package/dist/services/discount.js +73 -175
- package/dist/services/discount.js.map +1 -1
- package/dist/services/line-item.js +3 -3
- package/dist/services/line-item.js.map +1 -1
- package/dist/services/order.d.ts +0 -13
- package/dist/services/order.js +0 -26
- package/dist/services/order.js.map +1 -1
- package/dist/services/price-list.d.ts +16 -2
- package/dist/services/price-list.js +181 -24
- package/dist/services/price-list.js.map +1 -1
- package/dist/services/product-tag.d.ts +2 -2
- package/dist/services/product-tag.js +15 -2
- package/dist/services/product-tag.js.map +1 -1
- package/dist/services/product-type.d.ts +1 -1
- package/dist/services/product-type.js +14 -1
- package/dist/services/product-type.js.map +1 -1
- package/dist/services/product-variant.js +1 -1
- package/dist/services/product-variant.js.map +1 -1
- package/dist/services/product.d.ts +2 -1
- package/dist/services/product.js +14 -7
- package/dist/services/product.js.map +1 -1
- package/dist/services/return.js +2 -0
- package/dist/services/return.js.map +1 -1
- package/dist/types/cart.d.ts +1 -1
- package/dist/types/common.d.ts +31 -11
- package/dist/types/common.js +1 -0
- package/dist/types/common.js.map +1 -1
- package/dist/types/discount.d.ts +1 -0
- package/dist/types/global.d.ts +9 -0
- package/dist/types/price-list.d.ts +1 -0
- package/dist/types/price-list.js +5 -0
- package/dist/types/price-list.js.map +1 -1
- package/dist/types/product.d.ts +2 -0
- package/dist/types/product.js +18 -4
- package/dist/types/product.js.map +1 -1
- package/dist/utils/build-query.d.ts +8 -0
- package/dist/utils/build-query.js +114 -0
- package/dist/utils/build-query.js.map +1 -0
- package/dist/utils/get-query-config.js +4 -4
- package/dist/utils/get-query-config.js.map +1 -1
- package/dist/utils/index.d.ts +3 -0
- package/dist/utils/index.js +16 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/set-metadata.d.ts +9 -0
- package/dist/utils/set-metadata.js +72 -0
- package/dist/utils/set-metadata.js.map +1 -0
- package/dist/utils/validate-id.d.ts +4 -0
- package/dist/utils/validate-id.js +47 -0
- package/dist/utils/validate-id.js.map +1 -0
- package/package.json +7 -7
- package/dist/api/routes/admin/products/get-variants.d.ts +0 -24
- package/dist/api/routes/admin/products/get-variants.js +0 -76
- package/dist/api/routes/admin/products/get-variants.js.map +0 -1
- package/dist/interfaces/base-service.d.ts +0 -66
- package/dist/interfaces/base-service.js.map +0 -1
package/dist/services/cart.js
CHANGED
|
@@ -103,8 +103,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
103
103
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
104
104
|
var lodash_1 = __importDefault(require("lodash"));
|
|
105
105
|
var medusa_core_utils_1 = require("medusa-core-utils");
|
|
106
|
-
var medusa_interfaces_1 = require("medusa-interfaces");
|
|
107
106
|
var typeorm_1 = require("typeorm");
|
|
107
|
+
var interfaces_1 = require("../interfaces");
|
|
108
|
+
var utils_1 = require("../utils");
|
|
108
109
|
/* Provides layer to manipulate carts.
|
|
109
110
|
* @implements BaseService
|
|
110
111
|
*/
|
|
@@ -112,7 +113,9 @@ var CartService = /** @class */ (function (_super) {
|
|
|
112
113
|
__extends(CartService, _super);
|
|
113
114
|
function CartService(_a) {
|
|
114
115
|
var manager = _a.manager, cartRepository = _a.cartRepository, shippingMethodRepository = _a.shippingMethodRepository, lineItemRepository = _a.lineItemRepository, eventBusService = _a.eventBusService, paymentProviderService = _a.paymentProviderService, productService = _a.productService, productVariantService = _a.productVariantService, taxProviderService = _a.taxProviderService, regionService = _a.regionService, lineItemService = _a.lineItemService, shippingOptionService = _a.shippingOptionService, customerService = _a.customerService, discountService = _a.discountService, giftCardService = _a.giftCardService, totalsService = _a.totalsService, addressRepository = _a.addressRepository, paymentSessionRepository = _a.paymentSessionRepository, inventoryService = _a.inventoryService, customShippingOptionService = _a.customShippingOptionService, lineItemAdjustmentService = _a.lineItemAdjustmentService, priceSelectionStrategy = _a.priceSelectionStrategy;
|
|
115
|
-
var _this =
|
|
116
|
+
var _this =
|
|
117
|
+
// eslint-disable-next-line prefer-rest-params
|
|
118
|
+
_super.call(this, arguments[0]) || this;
|
|
116
119
|
_this.manager_ = manager;
|
|
117
120
|
_this.shippingMethodRepository_ = shippingMethodRepository;
|
|
118
121
|
_this.cartRepository_ = cartRepository;
|
|
@@ -137,37 +140,6 @@ var CartService = /** @class */ (function (_super) {
|
|
|
137
140
|
_this.priceSelectionStrategy_ = priceSelectionStrategy;
|
|
138
141
|
return _this;
|
|
139
142
|
}
|
|
140
|
-
CartService.prototype.withTransaction = function (transactionManager) {
|
|
141
|
-
if (!transactionManager) {
|
|
142
|
-
return this;
|
|
143
|
-
}
|
|
144
|
-
var cloned = new CartService({
|
|
145
|
-
manager: transactionManager,
|
|
146
|
-
taxProviderService: this.taxProviderService_,
|
|
147
|
-
cartRepository: this.cartRepository_,
|
|
148
|
-
lineItemRepository: this.lineItemRepository_,
|
|
149
|
-
eventBusService: this.eventBus_,
|
|
150
|
-
paymentProviderService: this.paymentProviderService_,
|
|
151
|
-
paymentSessionRepository: this.paymentSessionRepository_,
|
|
152
|
-
shippingMethodRepository: this.shippingMethodRepository_,
|
|
153
|
-
productService: this.productService_,
|
|
154
|
-
productVariantService: this.productVariantService_,
|
|
155
|
-
regionService: this.regionService_,
|
|
156
|
-
lineItemService: this.lineItemService_,
|
|
157
|
-
shippingOptionService: this.shippingOptionService_,
|
|
158
|
-
customerService: this.customerService_,
|
|
159
|
-
discountService: this.discountService_,
|
|
160
|
-
totalsService: this.totalsService_,
|
|
161
|
-
addressRepository: this.addressRepository_,
|
|
162
|
-
giftCardService: this.giftCardService_,
|
|
163
|
-
inventoryService: this.inventoryService_,
|
|
164
|
-
customShippingOptionService: this.customShippingOptionService_,
|
|
165
|
-
lineItemAdjustmentService: this.lineItemAdjustmentService_,
|
|
166
|
-
priceSelectionStrategy: this.priceSelectionStrategy_,
|
|
167
|
-
});
|
|
168
|
-
cloned.transactionManager_ = transactionManager;
|
|
169
|
-
return cloned;
|
|
170
|
-
};
|
|
171
143
|
CartService.prototype.transformQueryForTotals_ = function (config) {
|
|
172
144
|
var select = config.select, relations = config.relations;
|
|
173
145
|
if (!select) {
|
|
@@ -303,7 +275,7 @@ var CartService = /** @class */ (function (_super) {
|
|
|
303
275
|
switch (_a.label) {
|
|
304
276
|
case 0:
|
|
305
277
|
cartRepo = transactionManager.getCustomRepository(this.cartRepository_);
|
|
306
|
-
query =
|
|
278
|
+
query = (0, utils_1.buildQuery)(selector, config);
|
|
307
279
|
return [4 /*yield*/, cartRepo.find(query)];
|
|
308
280
|
case 1: return [2 /*return*/, _a.sent()];
|
|
309
281
|
}
|
|
@@ -334,9 +306,9 @@ var CartService = /** @class */ (function (_super) {
|
|
|
334
306
|
switch (_b.label) {
|
|
335
307
|
case 0:
|
|
336
308
|
cartRepo = transactionManager.getCustomRepository(this.cartRepository_);
|
|
337
|
-
validatedId =
|
|
309
|
+
validatedId = (0, utils_1.validateId)(cartId);
|
|
338
310
|
_a = this.transformQueryForTotals_(options), select = _a.select, relations = _a.relations, totalsToSelect = _a.totalsToSelect;
|
|
339
|
-
query =
|
|
311
|
+
query = (0, utils_1.buildQuery)({ id: validatedId }, __assign(__assign({}, options), { select: select, relations: relations }));
|
|
340
312
|
if (relations && relations.length > 0) {
|
|
341
313
|
query.relations = relations;
|
|
342
314
|
}
|
|
@@ -375,10 +347,10 @@ var CartService = /** @class */ (function (_super) {
|
|
|
375
347
|
return __generator(this, function (_a) {
|
|
376
348
|
switch (_a.label) {
|
|
377
349
|
case 0: return [4 /*yield*/, this.atomicPhase_(function (transactionManager) { return __awaiter(_this, void 0, void 0, function () {
|
|
378
|
-
var cartRepo, addressRepo, region_id, rawCart, customer, region, regCountries,
|
|
379
|
-
var e_2,
|
|
380
|
-
return __generator(this, function (
|
|
381
|
-
switch (
|
|
350
|
+
var cartRepo, addressRepo, region_id, rawCart, customer, region, regCountries, addr, remainingFields, remainingFields_1, remainingFields_1_1, remainingField, createdCart, cart;
|
|
351
|
+
var e_2, _a;
|
|
352
|
+
return __generator(this, function (_b) {
|
|
353
|
+
switch (_b.label) {
|
|
382
354
|
case 0:
|
|
383
355
|
cartRepo = transactionManager.getCustomRepository(this.cartRepository_);
|
|
384
356
|
addressRepo = transactionManager.getCustomRepository(this.addressRepository_);
|
|
@@ -390,56 +362,47 @@ var CartService = /** @class */ (function (_super) {
|
|
|
390
362
|
if (!data.email) return [3 /*break*/, 2];
|
|
391
363
|
return [4 /*yield*/, this.createOrFetchUserFromEmail_(data.email)];
|
|
392
364
|
case 1:
|
|
393
|
-
customer =
|
|
365
|
+
customer = _b.sent();
|
|
394
366
|
rawCart.customer = customer;
|
|
395
367
|
rawCart.customer_id = customer.id;
|
|
396
368
|
rawCart.email = customer.email;
|
|
397
|
-
|
|
369
|
+
_b.label = 2;
|
|
398
370
|
case 2: return [4 /*yield*/, this.regionService_
|
|
399
371
|
.withTransaction(transactionManager)
|
|
400
372
|
.retrieve(region_id, {
|
|
401
373
|
relations: ["countries"],
|
|
402
374
|
})];
|
|
403
375
|
case 3:
|
|
404
|
-
region =
|
|
376
|
+
region = _b.sent();
|
|
405
377
|
regCountries = region.countries.map(function (_a) {
|
|
406
378
|
var iso_2 = _a.iso_2;
|
|
407
379
|
return iso_2;
|
|
408
380
|
});
|
|
409
381
|
rawCart.region_id = region.id;
|
|
410
|
-
if (!(data.
|
|
411
|
-
if (
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
return [3 /*break*/, 6];
|
|
416
|
-
case 5:
|
|
417
|
-
_a = null;
|
|
418
|
-
_c.label = 6;
|
|
419
|
-
case 6:
|
|
420
|
-
shippingAddress = _a;
|
|
421
|
-
if (shippingAddress &&
|
|
422
|
-
!regCountries.includes(shippingAddress.country_code)) {
|
|
423
|
-
throw new medusa_core_utils_1.MedusaError(medusa_core_utils_1.MedusaError.Types.NOT_ALLOWED, "Shipping country not in region");
|
|
424
|
-
}
|
|
425
|
-
rawCart.shipping_address = shippingAddress;
|
|
426
|
-
_c.label = 7;
|
|
427
|
-
case 7:
|
|
428
|
-
if (!data.shipping_address) {
|
|
429
|
-
if (region.countries.length === 1) {
|
|
430
|
-
// Preselect the country if the region only has 1
|
|
431
|
-
// and create address entity
|
|
432
|
-
rawCart.shipping_address = addressRepo.create({
|
|
433
|
-
country_code: regCountries[0],
|
|
434
|
-
});
|
|
435
|
-
}
|
|
382
|
+
if (!(!data.shipping_address && !data.shipping_address_id)) return [3 /*break*/, 4];
|
|
383
|
+
if (region.countries.length === 1) {
|
|
384
|
+
rawCart.shipping_address = addressRepo.create({
|
|
385
|
+
country_code: regCountries[0],
|
|
386
|
+
});
|
|
436
387
|
}
|
|
437
|
-
|
|
388
|
+
return [3 /*break*/, 6];
|
|
389
|
+
case 4:
|
|
390
|
+
if (data.shipping_address) {
|
|
438
391
|
if (!regCountries.includes(data.shipping_address.country_code)) {
|
|
439
392
|
throw new medusa_core_utils_1.MedusaError(medusa_core_utils_1.MedusaError.Types.NOT_ALLOWED, "Shipping country not in region");
|
|
440
393
|
}
|
|
441
394
|
rawCart.shipping_address = data.shipping_address;
|
|
442
395
|
}
|
|
396
|
+
if (!data.shipping_address_id) return [3 /*break*/, 6];
|
|
397
|
+
return [4 /*yield*/, addressRepo.findOne(data.shipping_address_id)];
|
|
398
|
+
case 5:
|
|
399
|
+
addr = _b.sent();
|
|
400
|
+
if (addr && !regCountries.includes(addr.country_code)) {
|
|
401
|
+
throw new medusa_core_utils_1.MedusaError(medusa_core_utils_1.MedusaError.Types.NOT_ALLOWED, "Shipping country not in region");
|
|
402
|
+
}
|
|
403
|
+
rawCart.shipping_address_id = data.shipping_address_id;
|
|
404
|
+
_b.label = 6;
|
|
405
|
+
case 6:
|
|
443
406
|
remainingFields = [
|
|
444
407
|
"billing_address_id",
|
|
445
408
|
"context",
|
|
@@ -460,21 +423,21 @@ var CartService = /** @class */ (function (_super) {
|
|
|
460
423
|
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
461
424
|
finally {
|
|
462
425
|
try {
|
|
463
|
-
if (remainingFields_1_1 && !remainingFields_1_1.done && (
|
|
426
|
+
if (remainingFields_1_1 && !remainingFields_1_1.done && (_a = remainingFields_1.return)) _a.call(remainingFields_1);
|
|
464
427
|
}
|
|
465
428
|
finally { if (e_2) throw e_2.error; }
|
|
466
429
|
}
|
|
467
430
|
createdCart = cartRepo.create(rawCart);
|
|
468
431
|
return [4 /*yield*/, cartRepo.save(createdCart)];
|
|
469
|
-
case
|
|
470
|
-
cart =
|
|
432
|
+
case 7:
|
|
433
|
+
cart = _b.sent();
|
|
471
434
|
return [4 /*yield*/, this.eventBus_
|
|
472
435
|
.withTransaction(transactionManager)
|
|
473
436
|
.emit(CartService.Events.CREATED, {
|
|
474
437
|
id: cart.id,
|
|
475
438
|
})];
|
|
476
|
-
case
|
|
477
|
-
|
|
439
|
+
case 8:
|
|
440
|
+
_b.sent();
|
|
478
441
|
return [2 /*return*/, cart];
|
|
479
442
|
}
|
|
480
443
|
});
|
|
@@ -759,22 +722,26 @@ var CartService = /** @class */ (function (_super) {
|
|
|
759
722
|
* @return void
|
|
760
723
|
*/
|
|
761
724
|
CartService.prototype.adjustFreeShipping_ = function (cart, shouldAdd) {
|
|
762
|
-
var _a;
|
|
725
|
+
var _a, _b;
|
|
763
726
|
return __awaiter(this, void 0, void 0, function () {
|
|
764
|
-
var shippingMethodRepository_1;
|
|
727
|
+
var transactionManager, shippingMethodRepository_1;
|
|
765
728
|
var _this = this;
|
|
766
|
-
return __generator(this, function (
|
|
767
|
-
switch (
|
|
729
|
+
return __generator(this, function (_c) {
|
|
730
|
+
switch (_c.label) {
|
|
768
731
|
case 0:
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
return [
|
|
732
|
+
transactionManager = (_a = this.transactionManager_) !== null && _a !== void 0 ? _a : this.manager_;
|
|
733
|
+
if (!((_b = cart.shipping_methods) === null || _b === void 0 ? void 0 : _b.length)) return [3 /*break*/, 4];
|
|
734
|
+
shippingMethodRepository_1 = transactionManager.getCustomRepository(this.shippingMethodRepository_);
|
|
735
|
+
if (!shouldAdd) return [3 /*break*/, 2];
|
|
736
|
+
return [4 /*yield*/, shippingMethodRepository_1.update({
|
|
773
737
|
id: (0, typeorm_1.In)(cart.shipping_methods.map(function (shippingMethod) { return shippingMethod.id; })),
|
|
774
738
|
}, {
|
|
775
739
|
price: 0,
|
|
776
740
|
})];
|
|
777
|
-
case 1:
|
|
741
|
+
case 1:
|
|
742
|
+
_c.sent();
|
|
743
|
+
return [3 /*break*/, 4];
|
|
744
|
+
case 2: return [4 /*yield*/, Promise.all(cart.shipping_methods.map(function (shippingMethod) { return __awaiter(_this, void 0, void 0, function () {
|
|
778
745
|
return __generator(this, function (_a) {
|
|
779
746
|
// if free shipping discount is removed, we adjust the shipping
|
|
780
747
|
// back to its original amount
|
|
@@ -782,10 +749,10 @@ var CartService = /** @class */ (function (_super) {
|
|
|
782
749
|
return [2 /*return*/, shippingMethodRepository_1.save(shippingMethod)];
|
|
783
750
|
});
|
|
784
751
|
}); }))];
|
|
785
|
-
case
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
case
|
|
752
|
+
case 3:
|
|
753
|
+
_c.sent();
|
|
754
|
+
_c.label = 4;
|
|
755
|
+
case 4: return [2 /*return*/];
|
|
789
756
|
}
|
|
790
757
|
});
|
|
791
758
|
});
|
|
@@ -798,9 +765,9 @@ var CartService = /** @class */ (function (_super) {
|
|
|
798
765
|
case 0: return [4 /*yield*/, this.atomicPhase_(function (transactionManager) { return __awaiter(_this, void 0, void 0, function () {
|
|
799
766
|
var cartRepo, cart, customer, countryCode, addrRepo, billingAddress, shippingAddress, previousDiscounts, hasFreeShipping, prevContext, updatedCart;
|
|
800
767
|
var _this = this;
|
|
801
|
-
var _a, _b, _c, _d, _e
|
|
802
|
-
return __generator(this, function (
|
|
803
|
-
switch (
|
|
768
|
+
var _a, _b, _c, _d, _e;
|
|
769
|
+
return __generator(this, function (_f) {
|
|
770
|
+
switch (_f.label) {
|
|
804
771
|
case 0:
|
|
805
772
|
cartRepo = transactionManager.getCustomRepository(this.cartRepository_);
|
|
806
773
|
return [4 /*yield*/, this.retrieve(cartId, {
|
|
@@ -827,52 +794,52 @@ var CartService = /** @class */ (function (_super) {
|
|
|
827
794
|
],
|
|
828
795
|
})];
|
|
829
796
|
case 1:
|
|
830
|
-
cart =
|
|
797
|
+
cart = _f.sent();
|
|
831
798
|
if (!data.customer_id) return [3 /*break*/, 3];
|
|
832
799
|
return [4 /*yield*/, this.updateCustomerId_(cart, data.customer_id)];
|
|
833
800
|
case 2:
|
|
834
|
-
|
|
801
|
+
_f.sent();
|
|
835
802
|
return [3 /*break*/, 5];
|
|
836
803
|
case 3:
|
|
837
804
|
if (!(typeof data.email !== "undefined")) return [3 /*break*/, 5];
|
|
838
805
|
return [4 /*yield*/, this.createOrFetchUserFromEmail_(data.email)];
|
|
839
806
|
case 4:
|
|
840
|
-
customer =
|
|
807
|
+
customer = _f.sent();
|
|
841
808
|
cart.customer = customer;
|
|
842
809
|
cart.customer_id = customer.id;
|
|
843
810
|
cart.email = customer.email;
|
|
844
|
-
|
|
811
|
+
_f.label = 5;
|
|
845
812
|
case 5:
|
|
846
813
|
if (!(typeof data.region_id !== "undefined")) return [3 /*break*/, 7];
|
|
847
814
|
countryCode = (_b = (data.country_code || ((_a = data.shipping_address) === null || _a === void 0 ? void 0 : _a.country_code))) !== null && _b !== void 0 ? _b : null;
|
|
848
815
|
return [4 /*yield*/, this.setRegion_(cart, data.region_id, countryCode)];
|
|
849
816
|
case 6:
|
|
850
|
-
|
|
851
|
-
|
|
817
|
+
_f.sent();
|
|
818
|
+
_f.label = 7;
|
|
852
819
|
case 7:
|
|
853
820
|
if (!(typeof data.customer_id !== "undefined" ||
|
|
854
821
|
typeof data.region_id !== "undefined")) return [3 /*break*/, 9];
|
|
855
822
|
return [4 /*yield*/, this.updateUnitPrices_(cart, data.region_id, data.customer_id)];
|
|
856
823
|
case 8:
|
|
857
|
-
|
|
858
|
-
|
|
824
|
+
_f.sent();
|
|
825
|
+
_f.label = 9;
|
|
859
826
|
case 9:
|
|
860
827
|
addrRepo = transactionManager.getCustomRepository(this.addressRepository_);
|
|
861
828
|
billingAddress = (_c = data.billing_address_id) !== null && _c !== void 0 ? _c : data.billing_address;
|
|
862
829
|
if (!(billingAddress !== undefined)) return [3 /*break*/, 11];
|
|
863
830
|
return [4 /*yield*/, this.updateBillingAddress_(cart, billingAddress, addrRepo)];
|
|
864
831
|
case 10:
|
|
865
|
-
|
|
866
|
-
|
|
832
|
+
_f.sent();
|
|
833
|
+
_f.label = 11;
|
|
867
834
|
case 11:
|
|
868
835
|
shippingAddress = (_d = data.shipping_address_id) !== null && _d !== void 0 ? _d : data.shipping_address;
|
|
869
836
|
if (!(shippingAddress !== undefined)) return [3 /*break*/, 13];
|
|
870
837
|
return [4 /*yield*/, this.updateShippingAddress_(cart, shippingAddress, addrRepo)];
|
|
871
838
|
case 12:
|
|
872
|
-
|
|
873
|
-
|
|
839
|
+
_f.sent();
|
|
840
|
+
_f.label = 13;
|
|
874
841
|
case 13:
|
|
875
|
-
if (!(
|
|
842
|
+
if (!(typeof data.discounts !== "undefined")) return [3 /*break*/, 18];
|
|
876
843
|
previousDiscounts = __spreadArray([], __read(cart.discounts), false);
|
|
877
844
|
cart.discounts.length = 0;
|
|
878
845
|
return [4 /*yield*/, Promise.all(data.discounts.map(function (_a) {
|
|
@@ -880,39 +847,39 @@ var CartService = /** @class */ (function (_super) {
|
|
|
880
847
|
return _this.applyDiscount(cart, code);
|
|
881
848
|
}))];
|
|
882
849
|
case 14:
|
|
883
|
-
|
|
850
|
+
_f.sent();
|
|
884
851
|
hasFreeShipping = cart.discounts.some(function (_a) {
|
|
885
852
|
var rule = _a.rule;
|
|
886
853
|
return (rule === null || rule === void 0 ? void 0 : rule.type) === "free_shipping";
|
|
887
854
|
});
|
|
888
855
|
if (!(previousDiscounts.some(function (_a) {
|
|
889
856
|
var rule = _a.rule;
|
|
890
|
-
return
|
|
857
|
+
return rule.type === "free_shipping";
|
|
891
858
|
}) &&
|
|
892
859
|
!hasFreeShipping)) return [3 /*break*/, 16];
|
|
893
860
|
return [4 /*yield*/, this.adjustFreeShipping_(cart, false)];
|
|
894
861
|
case 15:
|
|
895
|
-
|
|
896
|
-
|
|
862
|
+
_f.sent();
|
|
863
|
+
_f.label = 16;
|
|
897
864
|
case 16:
|
|
898
865
|
if (!hasFreeShipping) return [3 /*break*/, 18];
|
|
899
866
|
return [4 /*yield*/, this.adjustFreeShipping_(cart, true)];
|
|
900
867
|
case 17:
|
|
901
|
-
|
|
902
|
-
|
|
868
|
+
_f.sent();
|
|
869
|
+
_f.label = 18;
|
|
903
870
|
case 18:
|
|
904
871
|
if (!("gift_cards" in data)) return [3 /*break*/, 20];
|
|
905
872
|
cart.gift_cards = [];
|
|
906
|
-
return [4 /*yield*/, Promise.all(((
|
|
873
|
+
return [4 /*yield*/, Promise.all(((_e = data.gift_cards) !== null && _e !== void 0 ? _e : []).map(function (_a) {
|
|
907
874
|
var code = _a.code;
|
|
908
875
|
return _this.applyGiftCard_(cart, code);
|
|
909
876
|
}))];
|
|
910
877
|
case 19:
|
|
911
|
-
|
|
912
|
-
|
|
878
|
+
_f.sent();
|
|
879
|
+
_f.label = 20;
|
|
913
880
|
case 20:
|
|
914
|
-
if (
|
|
915
|
-
cart.metadata =
|
|
881
|
+
if (data === null || data === void 0 ? void 0 : data.metadata) {
|
|
882
|
+
cart.metadata = (0, utils_1.setMetadata)(cart, data.metadata);
|
|
916
883
|
}
|
|
917
884
|
if ("context" in data) {
|
|
918
885
|
prevContext = cart.context || {};
|
|
@@ -926,19 +893,19 @@ var CartService = /** @class */ (function (_super) {
|
|
|
926
893
|
}
|
|
927
894
|
return [4 /*yield*/, cartRepo.save(cart)];
|
|
928
895
|
case 21:
|
|
929
|
-
updatedCart =
|
|
896
|
+
updatedCart = _f.sent();
|
|
930
897
|
if (!("email" in data || "customer_id" in data)) return [3 /*break*/, 23];
|
|
931
898
|
return [4 /*yield*/, this.eventBus_
|
|
932
899
|
.withTransaction(transactionManager)
|
|
933
900
|
.emit(CartService.Events.CUSTOMER_UPDATED, updatedCart.id)];
|
|
934
901
|
case 22:
|
|
935
|
-
|
|
936
|
-
|
|
902
|
+
_f.sent();
|
|
903
|
+
_f.label = 23;
|
|
937
904
|
case 23: return [4 /*yield*/, this.eventBus_
|
|
938
905
|
.withTransaction(transactionManager)
|
|
939
906
|
.emit(CartService.Events.UPDATED, updatedCart)];
|
|
940
907
|
case 24:
|
|
941
|
-
|
|
908
|
+
_f.sent();
|
|
942
909
|
return [2 /*return*/, updatedCart];
|
|
943
910
|
}
|
|
944
911
|
});
|
|
@@ -1510,6 +1477,7 @@ var CartService = /** @class */ (function (_super) {
|
|
|
1510
1477
|
],
|
|
1511
1478
|
relations: [
|
|
1512
1479
|
"items",
|
|
1480
|
+
"items.adjustments",
|
|
1513
1481
|
"discounts",
|
|
1514
1482
|
"discounts.rule",
|
|
1515
1483
|
"gift_cards",
|
|
@@ -1847,28 +1815,29 @@ var CartService = /** @class */ (function (_super) {
|
|
|
1847
1815
|
return customOption;
|
|
1848
1816
|
};
|
|
1849
1817
|
CartService.prototype.updateUnitPrices_ = function (cart, regionId, customer_id) {
|
|
1850
|
-
var _a;
|
|
1818
|
+
var _a, _b;
|
|
1851
1819
|
return __awaiter(this, void 0, void 0, function () {
|
|
1852
|
-
var region_1,
|
|
1820
|
+
var transactionManager, region_1, _c;
|
|
1853
1821
|
var _this = this;
|
|
1854
|
-
return __generator(this, function (
|
|
1855
|
-
switch (
|
|
1822
|
+
return __generator(this, function (_d) {
|
|
1823
|
+
switch (_d.label) {
|
|
1856
1824
|
case 0:
|
|
1857
|
-
|
|
1825
|
+
transactionManager = (_a = this.transactionManager_) !== null && _a !== void 0 ? _a : this.manager_;
|
|
1826
|
+
if (!((_b = cart.items) === null || _b === void 0 ? void 0 : _b.length)) return [3 /*break*/, 3];
|
|
1858
1827
|
return [4 /*yield*/, this.regionService_
|
|
1859
1828
|
.withTransaction(this.transactionManager_)
|
|
1860
1829
|
.retrieve(regionId || cart.region_id, {
|
|
1861
1830
|
relations: ["countries"],
|
|
1862
1831
|
})];
|
|
1863
1832
|
case 1:
|
|
1864
|
-
region_1 =
|
|
1865
|
-
|
|
1833
|
+
region_1 = _d.sent();
|
|
1834
|
+
_c = cart;
|
|
1866
1835
|
return [4 /*yield*/, Promise.all(cart.items.map(function (item) { return __awaiter(_this, void 0, void 0, function () {
|
|
1867
1836
|
var availablePrice;
|
|
1868
1837
|
return __generator(this, function (_a) {
|
|
1869
1838
|
switch (_a.label) {
|
|
1870
1839
|
case 0: return [4 /*yield*/, this.priceSelectionStrategy_
|
|
1871
|
-
.withTransaction(
|
|
1840
|
+
.withTransaction(transactionManager)
|
|
1872
1841
|
.calculateVariantPrice(item.variant_id, {
|
|
1873
1842
|
region_id: region_1.id,
|
|
1874
1843
|
currency_code: region_1.currency_code,
|
|
@@ -1882,13 +1851,13 @@ var CartService = /** @class */ (function (_super) {
|
|
|
1882
1851
|
if (!(availablePrice !== undefined &&
|
|
1883
1852
|
availablePrice.calculatedPrice !== null)) return [3 /*break*/, 2];
|
|
1884
1853
|
return [2 /*return*/, this.lineItemService_
|
|
1885
|
-
.withTransaction(
|
|
1854
|
+
.withTransaction(transactionManager)
|
|
1886
1855
|
.update(item.id, {
|
|
1887
1856
|
has_shipping: false,
|
|
1888
1857
|
unit_price: availablePrice.calculatedPrice,
|
|
1889
1858
|
})];
|
|
1890
1859
|
case 2: return [4 /*yield*/, this.lineItemService_
|
|
1891
|
-
.withTransaction(
|
|
1860
|
+
.withTransaction(transactionManager)
|
|
1892
1861
|
.delete(item.id)];
|
|
1893
1862
|
case 3:
|
|
1894
1863
|
_a.sent();
|
|
@@ -1897,8 +1866,8 @@ var CartService = /** @class */ (function (_super) {
|
|
|
1897
1866
|
});
|
|
1898
1867
|
}); }))];
|
|
1899
1868
|
case 2:
|
|
1900
|
-
|
|
1901
|
-
|
|
1869
|
+
_c.items = (_d.sent()).filter(function (item) { return !!item; });
|
|
1870
|
+
_d.label = 3;
|
|
1902
1871
|
case 3: return [2 /*return*/];
|
|
1903
1872
|
}
|
|
1904
1873
|
});
|
|
@@ -1912,11 +1881,13 @@ var CartService = /** @class */ (function (_super) {
|
|
|
1912
1881
|
* @return the result of the update operation
|
|
1913
1882
|
*/
|
|
1914
1883
|
CartService.prototype.setRegion_ = function (cart, regionId, countryCode) {
|
|
1884
|
+
var _a;
|
|
1915
1885
|
return __awaiter(this, void 0, void 0, function () {
|
|
1916
|
-
var region, addrRepo, shippingAddress, updated, updated, paymentSessionRepo;
|
|
1917
|
-
return __generator(this, function (
|
|
1918
|
-
switch (
|
|
1886
|
+
var transactionManager, region, addrRepo, shippingAddress, updated, updated, paymentSessionRepo;
|
|
1887
|
+
return __generator(this, function (_b) {
|
|
1888
|
+
switch (_b.label) {
|
|
1919
1889
|
case 0:
|
|
1890
|
+
transactionManager = (_a = this.transactionManager_) !== null && _a !== void 0 ? _a : this.manager_;
|
|
1920
1891
|
if (cart.completed_at || cart.payment_authorized_at) {
|
|
1921
1892
|
throw new medusa_core_utils_1.MedusaError(medusa_core_utils_1.MedusaError.Types.NOT_ALLOWED, "Cannot change the region of a completed cart");
|
|
1922
1893
|
}
|
|
@@ -1926,8 +1897,8 @@ var CartService = /** @class */ (function (_super) {
|
|
|
1926
1897
|
relations: ["countries"],
|
|
1927
1898
|
})];
|
|
1928
1899
|
case 1:
|
|
1929
|
-
region =
|
|
1930
|
-
addrRepo =
|
|
1900
|
+
region = _b.sent();
|
|
1901
|
+
addrRepo = transactionManager.getCustomRepository(this.addressRepository_);
|
|
1931
1902
|
cart.region = region;
|
|
1932
1903
|
cart.region_id = region.id;
|
|
1933
1904
|
shippingAddress = {};
|
|
@@ -1936,8 +1907,8 @@ var CartService = /** @class */ (function (_super) {
|
|
|
1936
1907
|
where: { id: cart.shipping_address_id },
|
|
1937
1908
|
})];
|
|
1938
1909
|
case 2:
|
|
1939
|
-
shippingAddress = (
|
|
1940
|
-
|
|
1910
|
+
shippingAddress = (_b.sent());
|
|
1911
|
+
_b.label = 3;
|
|
1941
1912
|
case 3:
|
|
1942
1913
|
if (!(countryCode !== null)) return [3 /*break*/, 5];
|
|
1943
1914
|
if (!region.countries.find(function (_a) {
|
|
@@ -1949,7 +1920,7 @@ var CartService = /** @class */ (function (_super) {
|
|
|
1949
1920
|
updated = __assign(__assign({}, shippingAddress), { country_code: countryCode.toLowerCase() });
|
|
1950
1921
|
return [4 /*yield*/, addrRepo.save(updated)];
|
|
1951
1922
|
case 4:
|
|
1952
|
-
|
|
1923
|
+
_b.sent();
|
|
1953
1924
|
return [3 /*break*/, 7];
|
|
1954
1925
|
case 5:
|
|
1955
1926
|
updated = __assign({}, shippingAddress);
|
|
@@ -1963,16 +1934,16 @@ var CartService = /** @class */ (function (_super) {
|
|
|
1963
1934
|
}
|
|
1964
1935
|
return [4 /*yield*/, this.updateShippingAddress_(cart, updated, addrRepo)];
|
|
1965
1936
|
case 6:
|
|
1966
|
-
|
|
1967
|
-
|
|
1937
|
+
_b.sent();
|
|
1938
|
+
_b.label = 7;
|
|
1968
1939
|
case 7:
|
|
1969
1940
|
if (!(cart.shipping_methods && cart.shipping_methods.length)) return [3 /*break*/, 9];
|
|
1970
1941
|
return [4 /*yield*/, this.shippingOptionService_
|
|
1971
|
-
.withTransaction(
|
|
1942
|
+
.withTransaction(transactionManager)
|
|
1972
1943
|
.deleteShippingMethods(cart.shipping_methods)];
|
|
1973
1944
|
case 8:
|
|
1974
|
-
|
|
1975
|
-
|
|
1945
|
+
_b.sent();
|
|
1946
|
+
_b.label = 9;
|
|
1976
1947
|
case 9:
|
|
1977
1948
|
if (cart.discounts && cart.discounts.length) {
|
|
1978
1949
|
cart.discounts = cart.discounts.filter(function (discount) {
|
|
@@ -1984,15 +1955,15 @@ var CartService = /** @class */ (function (_super) {
|
|
|
1984
1955
|
}
|
|
1985
1956
|
cart.gift_cards = [];
|
|
1986
1957
|
if (!(cart.payment_sessions && cart.payment_sessions.length)) return [3 /*break*/, 11];
|
|
1987
|
-
paymentSessionRepo =
|
|
1958
|
+
paymentSessionRepo = transactionManager.getCustomRepository(this.paymentSessionRepository_);
|
|
1988
1959
|
return [4 /*yield*/, paymentSessionRepo.delete({
|
|
1989
1960
|
id: (0, typeorm_1.In)(cart.payment_sessions.map(function (paymentSession) { return paymentSession.id; })),
|
|
1990
1961
|
})];
|
|
1991
1962
|
case 10:
|
|
1992
|
-
|
|
1963
|
+
_b.sent();
|
|
1993
1964
|
cart.payment_sessions.length = 0;
|
|
1994
1965
|
cart.payment_session = null;
|
|
1995
|
-
|
|
1966
|
+
_b.label = 11;
|
|
1996
1967
|
case 11: return [2 /*return*/];
|
|
1997
1968
|
}
|
|
1998
1969
|
});
|
|
@@ -2059,7 +2030,7 @@ var CartService = /** @class */ (function (_super) {
|
|
|
2059
2030
|
switch (_b.label) {
|
|
2060
2031
|
case 0:
|
|
2061
2032
|
cartRepo = transactionManager.getCustomRepository(this.cartRepository_);
|
|
2062
|
-
validatedId =
|
|
2033
|
+
validatedId = (0, utils_1.validateId)(cartId);
|
|
2063
2034
|
if (typeof key !== "string") {
|
|
2064
2035
|
throw new medusa_core_utils_1.MedusaError(medusa_core_utils_1.MedusaError.Types.INVALID_ARGUMENT, "Key type is invalid. Metadata keys must be strings");
|
|
2065
2036
|
}
|
|
@@ -2126,17 +2097,19 @@ var CartService = /** @class */ (function (_super) {
|
|
|
2126
2097
|
});
|
|
2127
2098
|
};
|
|
2128
2099
|
CartService.prototype.refreshAdjustments_ = function (cart) {
|
|
2100
|
+
var _a;
|
|
2129
2101
|
return __awaiter(this, void 0, void 0, function () {
|
|
2130
|
-
var nonReturnLineIDs;
|
|
2131
|
-
return __generator(this, function (
|
|
2132
|
-
switch (
|
|
2102
|
+
var transactionManager, nonReturnLineIDs;
|
|
2103
|
+
return __generator(this, function (_b) {
|
|
2104
|
+
switch (_b.label) {
|
|
2133
2105
|
case 0:
|
|
2106
|
+
transactionManager = (_a = this.transactionManager_) !== null && _a !== void 0 ? _a : this.manager_;
|
|
2134
2107
|
nonReturnLineIDs = cart.items
|
|
2135
2108
|
.filter(function (item) { return !item.is_return; })
|
|
2136
2109
|
.map(function (i) { return i.id; });
|
|
2137
2110
|
// delete all old non return line item adjustments
|
|
2138
2111
|
return [4 /*yield*/, this.lineItemAdjustmentService_
|
|
2139
|
-
.withTransaction(
|
|
2112
|
+
.withTransaction(transactionManager)
|
|
2140
2113
|
.delete({
|
|
2141
2114
|
item_id: nonReturnLineIDs,
|
|
2142
2115
|
})
|
|
@@ -2144,14 +2117,14 @@ var CartService = /** @class */ (function (_super) {
|
|
|
2144
2117
|
];
|
|
2145
2118
|
case 1:
|
|
2146
2119
|
// delete all old non return line item adjustments
|
|
2147
|
-
|
|
2120
|
+
_b.sent();
|
|
2148
2121
|
// potentially create/update line item adjustments
|
|
2149
2122
|
return [4 /*yield*/, this.lineItemAdjustmentService_
|
|
2150
|
-
.withTransaction(
|
|
2123
|
+
.withTransaction(transactionManager)
|
|
2151
2124
|
.createAdjustments(cart)];
|
|
2152
2125
|
case 2:
|
|
2153
2126
|
// potentially create/update line item adjustments
|
|
2154
|
-
|
|
2127
|
+
_b.sent();
|
|
2155
2128
|
return [2 /*return*/];
|
|
2156
2129
|
}
|
|
2157
2130
|
});
|
|
@@ -2174,7 +2147,7 @@ var CartService = /** @class */ (function (_super) {
|
|
|
2174
2147
|
switch (_a.label) {
|
|
2175
2148
|
case 0:
|
|
2176
2149
|
cartRepo = transactionManager.getCustomRepository(this.cartRepository_);
|
|
2177
|
-
validatedId =
|
|
2150
|
+
validatedId = (0, utils_1.validateId)(cartId);
|
|
2178
2151
|
if (typeof key !== "string") {
|
|
2179
2152
|
throw new medusa_core_utils_1.MedusaError(medusa_core_utils_1.MedusaError.Types.INVALID_ARGUMENT, "Key type is invalid. Metadata keys must be strings");
|
|
2180
2153
|
}
|
|
@@ -2208,6 +2181,6 @@ var CartService = /** @class */ (function (_super) {
|
|
|
2208
2181
|
UPDATED: "cart.updated",
|
|
2209
2182
|
};
|
|
2210
2183
|
return CartService;
|
|
2211
|
-
}(
|
|
2184
|
+
}(interfaces_1.TransactionBaseService));
|
|
2212
2185
|
exports.default = CartService;
|
|
2213
2186
|
//# sourceMappingURL=cart.js.map
|