@medusajs/medusa 1.7.2 → 1.7.3-alpha.0
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/.turbo/turbo-test.log +0 -75
- package/CHANGELOG.md +50 -0
- package/dist/api/index.d.ts +1 -0
- package/dist/api/index.js +1 -0
- package/dist/api/index.js.map +1 -1
- package/dist/api/middlewares/check-registered-modules.d.ts +4 -0
- package/dist/api/middlewares/check-registered-modules.js +78 -0
- package/dist/api/middlewares/check-registered-modules.js.map +1 -0
- package/dist/api/routes/admin/discounts/add-resources-to-condition-batch.d.ts +1 -1
- package/dist/api/routes/admin/discounts/add-resources-to-condition-batch.js +1 -1
- package/dist/api/routes/admin/discounts/delete-resources-from-condition-batch.d.ts +1 -1
- package/dist/api/routes/admin/discounts/delete-resources-from-condition-batch.js +1 -1
- package/dist/api/routes/admin/discounts/list-discounts.d.ts +1 -1
- package/dist/api/routes/admin/index.js +4 -0
- package/dist/api/routes/admin/index.js.map +1 -1
- package/dist/api/routes/admin/order-edits/add-line-item.d.ts +1 -1
- package/dist/api/routes/admin/order-edits/add-line-item.js +1 -1
- package/dist/api/routes/admin/order-edits/delete-line-item.d.ts +1 -1
- package/dist/api/routes/admin/order-edits/delete-line-item.js +1 -1
- package/dist/api/routes/admin/order-edits/delete-order-edit-item-change.d.ts +1 -1
- package/dist/api/routes/admin/order-edits/delete-order-edit-item-change.js +1 -1
- package/dist/api/routes/admin/order-edits/delete-order-edit.d.ts +1 -1
- package/dist/api/routes/admin/order-edits/delete-order-edit.js +1 -1
- package/dist/api/routes/admin/order-edits/get-order-edit.d.ts +1 -1
- package/dist/api/routes/admin/order-edits/get-order-edit.js +1 -1
- package/dist/api/routes/admin/order-edits/list-order-edit.d.ts +1 -1
- package/dist/api/routes/admin/order-edits/request-confirmation.d.ts +1 -1
- package/dist/api/routes/admin/order-edits/request-confirmation.js +1 -1
- package/dist/api/routes/admin/order-edits/update-order-edit-line-item.d.ts +1 -1
- package/dist/api/routes/admin/order-edits/update-order-edit-line-item.js +1 -1
- package/dist/api/routes/admin/order-edits/update-order-edit.d.ts +1 -1
- package/dist/api/routes/admin/order-edits/update-order-edit.js +1 -1
- package/dist/api/routes/admin/orders/cancel-fulfillment.d.ts +5 -0
- package/dist/api/routes/admin/orders/cancel-fulfillment.js +46 -2
- package/dist/api/routes/admin/orders/cancel-fulfillment.js.map +1 -1
- package/dist/api/routes/admin/orders/create-fulfillment.d.ts +1 -0
- package/dist/api/routes/admin/orders/create-fulfillment.js +87 -5
- package/dist/api/routes/admin/orders/create-fulfillment.js.map +1 -1
- package/dist/api/routes/admin/orders/index.js +3 -7
- package/dist/api/routes/admin/orders/index.js.map +1 -1
- package/dist/api/routes/admin/payment-collections/delete-payment-collection.d.ts +1 -1
- package/dist/api/routes/admin/payment-collections/delete-payment-collection.js +1 -1
- package/dist/api/routes/admin/payment-collections/get-payment-collection.d.ts +1 -1
- package/dist/api/routes/admin/payment-collections/get-payment-collection.js +1 -1
- package/dist/api/routes/admin/payment-collections/mark-authorized-payment-collection.d.ts +1 -1
- package/dist/api/routes/admin/payment-collections/mark-authorized-payment-collection.js +1 -1
- package/dist/api/routes/admin/payment-collections/update-payment-collection.d.ts +1 -1
- package/dist/api/routes/admin/payment-collections/update-payment-collection.js +1 -1
- package/dist/api/routes/admin/price-lists/list-price-list-products.d.ts +2 -2
- package/dist/api/routes/admin/price-lists/list-price-list-products.js +1 -1
- package/dist/api/routes/admin/product-categories/delete-product-category.d.ts +64 -0
- package/dist/api/routes/admin/product-categories/delete-product-category.js +129 -0
- package/dist/api/routes/admin/product-categories/delete-product-category.js.map +1 -0
- package/dist/api/routes/admin/product-categories/get-product-category.d.ts +58 -0
- package/dist/api/routes/admin/product-categories/get-product-category.js +134 -0
- package/dist/api/routes/admin/product-categories/get-product-category.js.map +1 -0
- package/dist/api/routes/admin/product-categories/index.d.ts +7 -0
- package/dist/api/routes/admin/product-categories/index.js +68 -0
- package/dist/api/routes/admin/product-categories/index.js.map +1 -0
- package/dist/api/routes/admin/product-categories/list-product-categories.d.ts +78 -0
- package/dist/api/routes/admin/product-categories/list-product-categories.js +206 -0
- package/dist/api/routes/admin/product-categories/list-product-categories.js.map +1 -0
- package/dist/api/routes/admin/publishable-api-keys/add-channels-batch.d.ts +1 -1
- package/dist/api/routes/admin/publishable-api-keys/add-channels-batch.js +1 -1
- package/dist/api/routes/admin/publishable-api-keys/create-publishable-api-key.d.ts +1 -1
- package/dist/api/routes/admin/publishable-api-keys/create-publishable-api-key.js +1 -1
- package/dist/api/routes/admin/publishable-api-keys/delete-channels-batch.d.ts +1 -1
- package/dist/api/routes/admin/publishable-api-keys/delete-channels-batch.js +1 -1
- package/dist/api/routes/admin/publishable-api-keys/delete-publishable-api-key.d.ts +1 -1
- package/dist/api/routes/admin/publishable-api-keys/delete-publishable-api-key.js +1 -1
- package/dist/api/routes/admin/publishable-api-keys/get-publishable-api-key.d.ts +1 -1
- package/dist/api/routes/admin/publishable-api-keys/get-publishable-api-key.js +1 -1
- package/dist/api/routes/admin/publishable-api-keys/list-publishable-api-key-sales-channels.d.ts +2 -2
- package/dist/api/routes/admin/publishable-api-keys/list-publishable-api-key-sales-channels.js +1 -1
- package/dist/api/routes/admin/publishable-api-keys/list-publishable-api-keys.d.ts +1 -1
- package/dist/api/routes/admin/publishable-api-keys/revoke-publishable-api-key.d.ts +1 -1
- package/dist/api/routes/admin/publishable-api-keys/revoke-publishable-api-key.js +1 -1
- package/dist/api/routes/admin/publishable-api-keys/update-publishable-api-key.d.ts +1 -1
- package/dist/api/routes/admin/publishable-api-keys/update-publishable-api-key.js +1 -1
- package/dist/api/routes/admin/returns/cancel-return.js.map +1 -1
- package/dist/api/routes/admin/returns/receive-return.d.ts +1 -0
- package/dist/api/routes/admin/returns/receive-return.js +8 -1
- package/dist/api/routes/admin/returns/receive-return.js.map +1 -1
- package/dist/api/routes/admin/sales-channels/associate-stock-location.d.ts +79 -0
- package/dist/api/routes/admin/sales-channels/associate-stock-location.js +163 -0
- package/dist/api/routes/admin/sales-channels/associate-stock-location.js.map +1 -0
- package/dist/api/routes/admin/sales-channels/index.d.ts +2 -0
- package/dist/api/routes/admin/sales-channels/index.js +6 -0
- package/dist/api/routes/admin/sales-channels/index.js.map +1 -1
- package/dist/api/routes/admin/sales-channels/list-sales-channels.d.ts +1 -1
- package/dist/api/routes/admin/sales-channels/remove-stock-location.d.ts +88 -0
- package/dist/api/routes/admin/sales-channels/remove-stock-location.js +174 -0
- package/dist/api/routes/admin/sales-channels/remove-stock-location.js.map +1 -0
- package/dist/api/routes/admin/stock-locations/create-stock-location.d.ts +105 -0
- package/dist/api/routes/admin/stock-locations/create-stock-location.js +240 -0
- package/dist/api/routes/admin/stock-locations/create-stock-location.js.map +1 -0
- package/dist/api/routes/admin/stock-locations/get-stock-location.d.ts +48 -0
- package/dist/api/routes/admin/stock-locations/get-stock-location.js +121 -0
- package/dist/api/routes/admin/stock-locations/get-stock-location.js.map +1 -0
- package/dist/api/routes/admin/stock-locations/index.d.ts +18 -0
- package/dist/api/routes/admin/stock-locations/index.js +78 -0
- package/dist/api/routes/admin/stock-locations/index.js.map +1 -0
- package/dist/api/routes/admin/stock-locations/list-stock-locations.d.ts +144 -0
- package/dist/api/routes/admin/stock-locations/list-stock-locations.js +265 -0
- package/dist/api/routes/admin/stock-locations/list-stock-locations.js.map +1 -0
- package/dist/api/routes/admin/stock-locations/update-stock-location.d.ts +103 -0
- package/dist/api/routes/admin/stock-locations/update-stock-location.js +240 -0
- package/dist/api/routes/admin/stock-locations/update-stock-location.js.map +1 -0
- package/dist/api/routes/admin/uploads/create-protected-upload.d.ts +2 -2
- package/dist/api/routes/admin/uploads/create-protected-upload.js +2 -2
- package/dist/api/routes/admin/uploads/delete-upload.d.ts +1 -1
- package/dist/api/routes/admin/uploads/delete-upload.js +1 -1
- package/dist/api/routes/admin/uploads/get-download-url.d.ts +1 -1
- package/dist/api/routes/admin/uploads/get-download-url.js +1 -1
- package/dist/api/routes/store/order-edits/complete-order-edit.js +35 -34
- package/dist/api/routes/store/order-edits/complete-order-edit.js.map +1 -1
- package/dist/api/routes/store/orders/confirm-order-request.d.ts +2 -2
- package/dist/api/routes/store/orders/confirm-order-request.js +2 -2
- package/dist/api/routes/store/orders/request-order.d.ts +1 -1
- package/dist/api/routes/store/orders/request-order.js +1 -1
- package/dist/api/routes/store/payment-collections/authorize-batch-payment-sessions.d.ts +2 -2
- package/dist/api/routes/store/payment-collections/authorize-batch-payment-sessions.js +2 -2
- package/dist/api/routes/store/payment-collections/authorize-payment-session.d.ts +2 -2
- package/dist/api/routes/store/payment-collections/authorize-payment-session.js +2 -2
- package/dist/api/routes/store/payment-collections/get-payment-collection.d.ts +2 -2
- package/dist/api/routes/store/payment-collections/get-payment-collection.js +2 -2
- package/dist/api/routes/store/payment-collections/manage-batch-payment-sessions.d.ts +2 -2
- package/dist/api/routes/store/payment-collections/manage-batch-payment-sessions.js +2 -2
- package/dist/api/routes/store/payment-collections/manage-payment-session.d.ts +2 -2
- package/dist/api/routes/store/payment-collections/manage-payment-session.js +2 -2
- package/dist/api/routes/store/payment-collections/refresh-payment-session.d.ts +1 -1
- package/dist/api/routes/store/payment-collections/refresh-payment-session.js +1 -1
- package/dist/commands/develop.js +24 -0
- package/dist/commands/develop.js.map +1 -1
- package/dist/index.d.ts +6 -2
- package/dist/index.js +6 -2
- package/dist/index.js.map +1 -1
- package/dist/interfaces/payment-processor.d.ts +102 -0
- package/dist/interfaces/payment-processor.js +31 -0
- package/dist/interfaces/payment-processor.js.map +1 -0
- package/dist/interfaces/payment-service.d.ts +92 -1
- package/dist/interfaces/payment-service.js +10 -0
- package/dist/interfaces/payment-service.js.map +1 -1
- package/dist/interfaces/services/event-bus.d.ts +3 -0
- package/dist/interfaces/services/event-bus.js +3 -0
- package/dist/interfaces/services/event-bus.js.map +1 -0
- package/dist/interfaces/services/index.d.ts +3 -0
- package/dist/interfaces/services/index.js +3 -0
- package/dist/interfaces/services/index.js.map +1 -1
- package/dist/interfaces/services/inventory.d.ts +24 -0
- package/dist/interfaces/services/inventory.js +3 -0
- package/dist/interfaces/services/inventory.js.map +1 -0
- package/dist/interfaces/services/stock-location.d.ts +9 -0
- package/dist/interfaces/services/stock-location.js +3 -0
- package/dist/interfaces/services/stock-location.js.map +1 -0
- package/dist/loaders/feature-flags/product-categories.d.ts +3 -0
- package/dist/loaders/feature-flags/product-categories.js +10 -0
- package/dist/loaders/feature-flags/product-categories.js.map +1 -0
- package/dist/loaders/feature-flags/publishable-api-keys.js +1 -1
- package/dist/loaders/feature-flags/publishable-api-keys.js.map +1 -1
- package/dist/loaders/feature-flags/sales-channels.js +1 -1
- package/dist/loaders/feature-flags/sales-channels.js.map +1 -1
- package/dist/loaders/plugins.d.ts +1 -0
- package/dist/loaders/plugins.js +3 -1
- package/dist/loaders/plugins.js.map +1 -1
- package/dist/migrations/1671711415179-multi_location.d.ts +6 -0
- package/dist/migrations/1671711415179-multi_location.js +119 -0
- package/dist/migrations/1671711415179-multi_location.js.map +1 -0
- package/dist/migrations/1672906846559-product-category.d.ts +6 -0
- package/dist/migrations/1672906846559-product-category.js +83 -0
- package/dist/migrations/1672906846559-product-category.js.map +1 -0
- package/dist/migrations/1672906846560-payment-session-is-initiated.d.ts +6 -0
- package/dist/migrations/1672906846560-payment-session-is-initiated.js +81 -0
- package/dist/migrations/1672906846560-payment-session-is-initiated.js.map +1 -0
- package/dist/migrations/1673003729870-staged_job_options.d.ts +6 -0
- package/dist/migrations/1673003729870-staged_job_options.js +71 -0
- package/dist/migrations/1673003729870-staged_job_options.js.map +1 -0
- package/dist/models/fulfillment.d.ts +5 -0
- package/dist/models/fulfillment.js +8 -0
- package/dist/models/fulfillment.js.map +1 -1
- package/dist/models/index.d.ts +4 -0
- package/dist/models/index.js +4 -0
- package/dist/models/index.js.map +1 -1
- package/dist/models/line-item.d.ts +6 -6
- package/dist/models/line-item.js +9 -9
- package/dist/models/line-item.js.map +1 -1
- package/dist/models/payment-session.d.ts +6 -0
- package/dist/models/payment-session.js +9 -0
- package/dist/models/payment-session.js.map +1 -1
- package/dist/models/product-category.d.ts +67 -0
- package/dist/models/product-category.js +144 -0
- package/dist/models/product-category.js.map +1 -0
- package/dist/models/product-variant-inventory-item.d.ts +7 -0
- package/dist/models/product-variant-inventory-item.js +66 -0
- package/dist/models/product-variant-inventory-item.js.map +1 -0
- package/dist/models/return.d.ts +7 -6
- package/dist/models/return.js +14 -9
- package/dist/models/return.js.map +1 -1
- package/dist/models/sales-channel-location.d.ts +6 -0
- package/dist/models/sales-channel-location.js +62 -0
- package/dist/models/sales-channel-location.js.map +1 -0
- package/dist/models/staged-job.d.ts +1 -0
- package/dist/models/staged-job.js +4 -0
- package/dist/models/staged-job.js.map +1 -1
- package/dist/models/store.d.ts +6 -5
- package/dist/models/store.js +11 -7
- package/dist/models/store.js.map +1 -1
- package/dist/repositories/customer-group.js +18 -2
- package/dist/repositories/customer-group.js.map +1 -1
- package/dist/repositories/product-category.d.ts +6 -0
- package/dist/repositories/product-category.js +125 -0
- package/dist/repositories/product-category.js.map +1 -0
- package/dist/repositories/product-variant.js +30 -5
- package/dist/repositories/product-variant.js.map +1 -1
- package/dist/repositories/product.js +7 -2
- package/dist/repositories/product.js.map +1 -1
- package/dist/scripts/migrate-inventory-items.d.ts +1 -0
- package/dist/scripts/migrate-inventory-items.js +197 -0
- package/dist/scripts/migrate-inventory-items.js.map +1 -0
- package/dist/services/cache.js +2 -5
- package/dist/services/cache.js.map +1 -1
- package/dist/services/cart.d.ts +9 -26
- package/dist/services/cart.js +276 -182
- package/dist/services/cart.js.map +1 -1
- package/dist/services/claim-item.js +3 -0
- package/dist/services/claim-item.js.map +1 -1
- package/dist/services/claim.d.ts +4 -4
- package/dist/services/claim.js +132 -166
- package/dist/services/claim.js.map +1 -1
- package/dist/services/event-bus.d.ts +23 -10
- package/dist/services/event-bus.js +106 -42
- package/dist/services/event-bus.js.map +1 -1
- package/dist/services/fulfillment.d.ts +7 -3
- package/dist/services/fulfillment.js +79 -90
- package/dist/services/fulfillment.js.map +1 -1
- package/dist/services/index.d.ts +4 -1
- package/dist/services/index.js +10 -4
- package/dist/services/index.js.map +1 -1
- package/dist/services/line-item.d.ts +5 -5
- package/dist/services/line-item.js +2 -1
- package/dist/services/line-item.js.map +1 -1
- package/dist/services/order.d.ts +5 -19
- package/dist/services/order.js +146 -181
- package/dist/services/order.js.map +1 -1
- package/dist/services/payment-collection.d.ts +2 -2
- package/dist/services/payment-collection.js +88 -128
- package/dist/services/payment-collection.js.map +1 -1
- package/dist/services/payment-provider.d.ts +2 -1
- package/dist/services/payment-provider.js +32 -27
- package/dist/services/payment-provider.js.map +1 -1
- package/dist/services/product-category.d.ts +41 -0
- package/dist/services/product-category.js +190 -0
- package/dist/services/product-category.js.map +1 -0
- package/dist/services/product-variant-inventory.d.ts +115 -0
- package/dist/services/product-variant-inventory.js +747 -0
- package/dist/services/product-variant-inventory.js.map +1 -0
- package/dist/services/return.d.ts +7 -12
- package/dist/services/return.js +12 -9
- package/dist/services/return.js.map +1 -1
- package/dist/services/sales-channel-inventory.d.ts +24 -0
- package/dist/services/sales-channel-inventory.js +70 -0
- package/dist/services/sales-channel-inventory.js.map +1 -0
- package/dist/services/sales-channel-location.d.ts +41 -0
- package/dist/services/sales-channel-location.js +159 -0
- package/dist/services/sales-channel-location.js.map +1 -0
- package/dist/services/swap.d.ts +4 -4
- package/dist/services/swap.js +78 -127
- package/dist/services/swap.js.map +1 -1
- package/dist/services/totals.d.ts +2 -2
- package/dist/services/totals.js +2 -2
- package/dist/services/totals.js.map +1 -1
- package/dist/strategies/batch-jobs/product/import.d.ts +1 -1
- package/dist/strategies/batch-jobs/product/import.js +4 -3
- package/dist/strategies/batch-jobs/product/import.js.map +1 -1
- package/dist/strategies/cart-completion.d.ts +14 -9
- package/dist/strategies/cart-completion.js +111 -48
- package/dist/strategies/cart-completion.js.map +1 -1
- package/dist/subscribers/cart.d.ts +2 -4
- package/dist/subscribers/cart.js +8 -21
- package/dist/subscribers/cart.js.map +1 -1
- package/dist/subscribers/product.d.ts +1 -5
- package/dist/subscribers/product.js +15 -5
- package/dist/subscribers/product.js.map +1 -1
- package/dist/types/inventory.d.ts +106 -0
- package/dist/types/inventory.js +3 -0
- package/dist/types/inventory.js.map +1 -0
- package/dist/types/payment.d.ts +1 -0
- package/dist/types/product.d.ts +1 -0
- package/dist/types/product.js.map +1 -1
- package/dist/types/stock-location.d.ts +245 -0
- package/dist/types/stock-location.js +3 -0
- package/dist/types/stock-location.js.map +1 -0
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.js +1 -0
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/repository.d.ts +4 -3
- package/dist/utils/repository.js +43 -23
- package/dist/utils/repository.js.map +1 -1
- package/package.json +2 -2
- package/dist/services/inventory.d.ts +0 -31
- package/dist/services/inventory.js +0 -151
- package/dist/services/inventory.js.map +0 -1
package/dist/services/cart.js
CHANGED
|
@@ -116,7 +116,7 @@ var is_email_1 = require("../utils/is-email");
|
|
|
116
116
|
var CartService = /** @class */ (function (_super) {
|
|
117
117
|
__extends(CartService, _super);
|
|
118
118
|
function CartService(_a) {
|
|
119
|
-
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, newTotalsService = _a.newTotalsService, addressRepository = _a.addressRepository, paymentSessionRepository = _a.paymentSessionRepository,
|
|
119
|
+
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, newTotalsService = _a.newTotalsService, addressRepository = _a.addressRepository, paymentSessionRepository = _a.paymentSessionRepository, customShippingOptionService = _a.customShippingOptionService, lineItemAdjustmentService = _a.lineItemAdjustmentService, priceSelectionStrategy = _a.priceSelectionStrategy, salesChannelService = _a.salesChannelService, featureFlagRouter = _a.featureFlagRouter, storeService = _a.storeService, productVariantInventoryService = _a.productVariantInventoryService;
|
|
120
120
|
var _this =
|
|
121
121
|
// eslint-disable-next-line prefer-rest-params
|
|
122
122
|
_super.call(this, arguments[0]) || this;
|
|
@@ -138,7 +138,6 @@ var CartService = /** @class */ (function (_super) {
|
|
|
138
138
|
_this.newTotalsService_ = newTotalsService;
|
|
139
139
|
_this.addressRepository_ = addressRepository;
|
|
140
140
|
_this.paymentSessionRepository_ = paymentSessionRepository;
|
|
141
|
-
_this.inventoryService_ = inventoryService;
|
|
142
141
|
_this.customShippingOptionService_ = customShippingOptionService;
|
|
143
142
|
_this.taxProviderService_ = taxProviderService;
|
|
144
143
|
_this.lineItemAdjustmentService_ = lineItemAdjustmentService;
|
|
@@ -146,6 +145,7 @@ var CartService = /** @class */ (function (_super) {
|
|
|
146
145
|
_this.salesChannelService_ = salesChannelService;
|
|
147
146
|
_this.featureFlagRouter_ = featureFlagRouter;
|
|
148
147
|
_this.storeService_ = storeService;
|
|
148
|
+
_this.productVariantInventoryService_ = productVariantInventoryService;
|
|
149
149
|
return _this;
|
|
150
150
|
}
|
|
151
151
|
/**
|
|
@@ -568,7 +568,7 @@ var CartService = /** @class */ (function (_super) {
|
|
|
568
568
|
return __generator(this, function (_d) {
|
|
569
569
|
switch (_d.label) {
|
|
570
570
|
case 0:
|
|
571
|
-
if (!sales_channel_id) {
|
|
571
|
+
if (!sales_channel_id || !lineItem.variant_id) {
|
|
572
572
|
return [2 /*return*/, true];
|
|
573
573
|
}
|
|
574
574
|
if (!((_b = lineItem.variant) === null || _b === void 0 ? void 0 : _b.product_id)) return [3 /*break*/, 1];
|
|
@@ -613,7 +613,7 @@ var CartService = /** @class */ (function (_super) {
|
|
|
613
613
|
select.push("sales_channel_id");
|
|
614
614
|
}
|
|
615
615
|
return [4 /*yield*/, this.atomicPhase_(function (transactionManager) { return __awaiter(_this, void 0, void 0, function () {
|
|
616
|
-
var cart, lineItemServiceTx, currentItem, _a, existingItem, quantity;
|
|
616
|
+
var cart, lineItemIsValid, lineItemServiceTx, currentItem, _a, existingItem, quantity, isCovered;
|
|
617
617
|
return __generator(this, function (_b) {
|
|
618
618
|
switch (_b.label) {
|
|
619
619
|
case 0: return [4 /*yield*/, this.retrieve(cartId, { select: select })];
|
|
@@ -621,9 +621,11 @@ var CartService = /** @class */ (function (_super) {
|
|
|
621
621
|
cart = _b.sent();
|
|
622
622
|
if (!this.featureFlagRouter_.isFeatureEnabled("sales_channels")) return [3 /*break*/, 3];
|
|
623
623
|
if (!config.validateSalesChannels) return [3 /*break*/, 3];
|
|
624
|
+
if (!lineItem.variant_id) return [3 /*break*/, 3];
|
|
624
625
|
return [4 /*yield*/, this.validateLineItem(cart, lineItem)];
|
|
625
626
|
case 2:
|
|
626
|
-
|
|
627
|
+
lineItemIsValid = _b.sent();
|
|
628
|
+
if (!lineItemIsValid) {
|
|
627
629
|
throw new medusa_core_utils_1.MedusaError(medusa_core_utils_1.MedusaError.Types.INVALID_DATA, "The product \"".concat(lineItem.title, "\" must belongs to the sales channel on which the cart has been created."));
|
|
628
630
|
}
|
|
629
631
|
_b.label = 3;
|
|
@@ -646,25 +648,27 @@ var CartService = /** @class */ (function (_super) {
|
|
|
646
648
|
quantity = currentItem
|
|
647
649
|
? (currentItem.quantity += lineItem.quantity)
|
|
648
650
|
: lineItem.quantity;
|
|
649
|
-
|
|
650
|
-
return [4 /*yield*/, this.
|
|
651
|
-
.withTransaction(transactionManager)
|
|
652
|
-
.confirmInventory(lineItem.variant_id, quantity)];
|
|
651
|
+
if (!lineItem.variant_id) return [3 /*break*/, 7];
|
|
652
|
+
return [4 /*yield*/, this.productVariantInventoryService_.confirmInventory(lineItem.variant_id, quantity, { salesChannelId: cart.sales_channel_id })];
|
|
653
653
|
case 6:
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
654
|
+
isCovered = _b.sent();
|
|
655
|
+
if (!isCovered) {
|
|
656
|
+
throw new medusa_core_utils_1.MedusaError(medusa_core_utils_1.MedusaError.Types.NOT_ALLOWED, "Variant with id: ".concat(lineItem.variant_id, " does not have the required inventory"), medusa_core_utils_1.MedusaError.Codes.INSUFFICIENT_INVENTORY);
|
|
657
|
+
}
|
|
658
|
+
_b.label = 7;
|
|
659
|
+
case 7:
|
|
660
|
+
if (!currentItem) return [3 /*break*/, 9];
|
|
657
661
|
return [4 /*yield*/, lineItemServiceTx.update(currentItem.id, {
|
|
658
662
|
quantity: currentItem.quantity,
|
|
659
663
|
})];
|
|
660
|
-
case
|
|
664
|
+
case 8:
|
|
661
665
|
_b.sent();
|
|
662
|
-
return [3 /*break*/,
|
|
663
|
-
case
|
|
664
|
-
case
|
|
666
|
+
return [3 /*break*/, 11];
|
|
667
|
+
case 9: return [4 /*yield*/, lineItemServiceTx.create(__assign(__assign({}, lineItem), { has_shipping: false, cart_id: cart.id }))];
|
|
668
|
+
case 10:
|
|
665
669
|
_b.sent();
|
|
666
|
-
_b.label =
|
|
667
|
-
case
|
|
670
|
+
_b.label = 11;
|
|
671
|
+
case 11: return [4 /*yield*/, lineItemServiceTx
|
|
668
672
|
.update({ cart_id: cartId, has_shipping: true }, { has_shipping: false })
|
|
669
673
|
.catch(function (err) {
|
|
670
674
|
// We only want to catch the errors related to not found items since we don't care if there is not item to update
|
|
@@ -673,20 +677,20 @@ var CartService = /** @class */ (function (_super) {
|
|
|
673
677
|
}
|
|
674
678
|
throw err;
|
|
675
679
|
})];
|
|
676
|
-
case
|
|
680
|
+
case 12:
|
|
677
681
|
_b.sent();
|
|
678
682
|
return [4 /*yield*/, this.retrieve(cart.id, {
|
|
679
683
|
relations: ["items", "discounts", "discounts.rule", "region"],
|
|
680
684
|
})];
|
|
681
|
-
case
|
|
685
|
+
case 13:
|
|
682
686
|
cart = _b.sent();
|
|
683
687
|
return [4 /*yield*/, this.refreshAdjustments_(cart)];
|
|
684
|
-
case
|
|
688
|
+
case 14:
|
|
685
689
|
_b.sent();
|
|
686
690
|
return [4 /*yield*/, this.eventBus_
|
|
687
691
|
.withTransaction(transactionManager)
|
|
688
692
|
.emit(CartService.Events.UPDATED, { id: cart.id })];
|
|
689
|
-
case
|
|
693
|
+
case 15:
|
|
690
694
|
_b.sent();
|
|
691
695
|
return [2 /*return*/];
|
|
692
696
|
}
|
|
@@ -721,7 +725,7 @@ var CartService = /** @class */ (function (_super) {
|
|
|
721
725
|
select.push("sales_channel_id");
|
|
722
726
|
}
|
|
723
727
|
return [4 /*yield*/, this.atomicPhase_(function (transactionManager) { return __awaiter(_this, void 0, void 0, function () {
|
|
724
|
-
var cart, areValid, invalidProducts, lineItemServiceTx,
|
|
728
|
+
var cart, areValid, invalidProducts, lineItemServiceTx, productVariantInventoryServiceTx, existingItems, existingItemsVariantMap, lineItemsToCreate, lineItemsToUpdate, items_1, items_1_1, item, currentItem, existingItem, isSufficient, e_2_1, itemKeysToUpdate;
|
|
725
729
|
var e_2, _a;
|
|
726
730
|
var _this = this;
|
|
727
731
|
return __generator(this, function (_b) {
|
|
@@ -734,8 +738,11 @@ var CartService = /** @class */ (function (_super) {
|
|
|
734
738
|
return [4 /*yield*/, Promise.all(items.map(function (item) { return __awaiter(_this, void 0, void 0, function () {
|
|
735
739
|
return __generator(this, function (_a) {
|
|
736
740
|
switch (_a.label) {
|
|
737
|
-
case 0:
|
|
741
|
+
case 0:
|
|
742
|
+
if (!item.variant_id) return [3 /*break*/, 2];
|
|
743
|
+
return [4 /*yield*/, this.validateLineItem(cart, item)];
|
|
738
744
|
case 1: return [2 /*return*/, _a.sent()];
|
|
745
|
+
case 2: return [2 /*return*/, true];
|
|
739
746
|
}
|
|
740
747
|
});
|
|
741
748
|
}); }))];
|
|
@@ -754,7 +761,7 @@ var CartService = /** @class */ (function (_super) {
|
|
|
754
761
|
_b.label = 3;
|
|
755
762
|
case 3:
|
|
756
763
|
lineItemServiceTx = this.lineItemService_.withTransaction(transactionManager);
|
|
757
|
-
|
|
764
|
+
productVariantInventoryServiceTx = this.productVariantInventoryService_.withTransaction(transactionManager);
|
|
758
765
|
return [4 /*yield*/, lineItemServiceTx.list({
|
|
759
766
|
cart_id: cart.id,
|
|
760
767
|
variant_id: (0, typeorm_1.In)([items.map(function (item) { return item.variant_id; })]),
|
|
@@ -770,11 +777,11 @@ var CartService = /** @class */ (function (_super) {
|
|
|
770
777
|
lineItemsToUpdate = [];
|
|
771
778
|
_b.label = 5;
|
|
772
779
|
case 5:
|
|
773
|
-
_b.trys.push([5,
|
|
780
|
+
_b.trys.push([5, 11, 12, 13]);
|
|
774
781
|
items_1 = __values(items), items_1_1 = items_1.next();
|
|
775
782
|
_b.label = 6;
|
|
776
783
|
case 6:
|
|
777
|
-
if (!!items_1_1.done) return [3 /*break*/,
|
|
784
|
+
if (!!items_1_1.done) return [3 /*break*/, 10];
|
|
778
785
|
item = items_1_1.value;
|
|
779
786
|
currentItem = void 0;
|
|
780
787
|
existingItem = existingItemsVariantMap.get(item.variant_id);
|
|
@@ -788,9 +795,15 @@ var CartService = /** @class */ (function (_super) {
|
|
|
788
795
|
item.quantity = currentItem
|
|
789
796
|
? (currentItem.quantity += item.quantity)
|
|
790
797
|
: item.quantity;
|
|
791
|
-
return [
|
|
798
|
+
if (!item.variant_id) return [3 /*break*/, 8];
|
|
799
|
+
return [4 /*yield*/, productVariantInventoryServiceTx.confirmInventory(item.variant_id, item.quantity, { salesChannelId: cart.sales_channel_id })];
|
|
792
800
|
case 7:
|
|
793
|
-
_b.sent();
|
|
801
|
+
isSufficient = _b.sent();
|
|
802
|
+
if (!isSufficient) {
|
|
803
|
+
throw new medusa_core_utils_1.MedusaError(medusa_core_utils_1.MedusaError.Types.NOT_ALLOWED, "Variant with id: ".concat(item.variant_id, " does not have the required inventory"), medusa_core_utils_1.MedusaError.Codes.INSUFFICIENT_INVENTORY);
|
|
804
|
+
}
|
|
805
|
+
_b.label = 8;
|
|
806
|
+
case 8:
|
|
794
807
|
if (currentItem) {
|
|
795
808
|
lineItemsToUpdate[currentItem.id] = {
|
|
796
809
|
quantity: item.quantity,
|
|
@@ -804,24 +817,24 @@ var CartService = /** @class */ (function (_super) {
|
|
|
804
817
|
item.cart_id = cart.id;
|
|
805
818
|
lineItemsToCreate.push(item);
|
|
806
819
|
}
|
|
807
|
-
_b.label =
|
|
808
|
-
case
|
|
820
|
+
_b.label = 9;
|
|
821
|
+
case 9:
|
|
809
822
|
items_1_1 = items_1.next();
|
|
810
823
|
return [3 /*break*/, 6];
|
|
811
|
-
case
|
|
812
|
-
case
|
|
824
|
+
case 10: return [3 /*break*/, 13];
|
|
825
|
+
case 11:
|
|
813
826
|
e_2_1 = _b.sent();
|
|
814
827
|
e_2 = { error: e_2_1 };
|
|
815
|
-
return [3 /*break*/,
|
|
816
|
-
case
|
|
828
|
+
return [3 /*break*/, 13];
|
|
829
|
+
case 12:
|
|
817
830
|
try {
|
|
818
831
|
if (items_1_1 && !items_1_1.done && (_a = items_1.return)) _a.call(items_1);
|
|
819
832
|
}
|
|
820
833
|
finally { if (e_2) throw e_2.error; }
|
|
821
834
|
return [7 /*endfinally*/];
|
|
822
|
-
case
|
|
835
|
+
case 13:
|
|
823
836
|
itemKeysToUpdate = Object.keys(lineItemsToUpdate);
|
|
824
|
-
if (!itemKeysToUpdate.length) return [3 /*break*/,
|
|
837
|
+
if (!itemKeysToUpdate.length) return [3 /*break*/, 15];
|
|
825
838
|
return [4 /*yield*/, Promise.all(itemKeysToUpdate.map(function (id) { return __awaiter(_this, void 0, void 0, function () {
|
|
826
839
|
return __generator(this, function (_a) {
|
|
827
840
|
switch (_a.label) {
|
|
@@ -830,13 +843,13 @@ var CartService = /** @class */ (function (_super) {
|
|
|
830
843
|
}
|
|
831
844
|
});
|
|
832
845
|
}); }))];
|
|
833
|
-
case
|
|
846
|
+
case 14:
|
|
834
847
|
_b.sent();
|
|
835
|
-
_b.label =
|
|
836
|
-
case
|
|
848
|
+
_b.label = 15;
|
|
849
|
+
case 15:
|
|
837
850
|
// Create all items that needs to be created
|
|
838
851
|
return [4 /*yield*/, lineItemServiceTx.create(lineItemsToCreate)];
|
|
839
|
-
case
|
|
852
|
+
case 16:
|
|
840
853
|
// Create all items that needs to be created
|
|
841
854
|
_b.sent();
|
|
842
855
|
return [4 /*yield*/, lineItemServiceTx
|
|
@@ -851,20 +864,20 @@ var CartService = /** @class */ (function (_super) {
|
|
|
851
864
|
}
|
|
852
865
|
throw err;
|
|
853
866
|
})];
|
|
854
|
-
case
|
|
867
|
+
case 17:
|
|
855
868
|
_b.sent();
|
|
856
869
|
return [4 /*yield*/, this.retrieve(cart.id, {
|
|
857
870
|
relations: ["items", "discounts", "discounts.rule", "region"],
|
|
858
871
|
})];
|
|
859
|
-
case
|
|
872
|
+
case 18:
|
|
860
873
|
cart = _b.sent();
|
|
861
874
|
return [4 /*yield*/, this.refreshAdjustments_(cart)];
|
|
862
|
-
case
|
|
875
|
+
case 19:
|
|
863
876
|
_b.sent();
|
|
864
877
|
return [4 /*yield*/, this.eventBus_
|
|
865
878
|
.withTransaction(transactionManager)
|
|
866
879
|
.emit(CartService.Events.UPDATED, { id: cart.id })];
|
|
867
|
-
case
|
|
880
|
+
case 20:
|
|
868
881
|
_b.sent();
|
|
869
882
|
return [2 /*return*/];
|
|
870
883
|
}
|
|
@@ -888,50 +901,54 @@ var CartService = /** @class */ (function (_super) {
|
|
|
888
901
|
return __generator(this, function (_a) {
|
|
889
902
|
switch (_a.label) {
|
|
890
903
|
case 0: return [4 /*yield*/, this.atomicPhase_(function (transactionManager) { return __awaiter(_this, void 0, void 0, function () {
|
|
891
|
-
var
|
|
904
|
+
var lineItem, select, cart, hasInventory, updatedCart;
|
|
892
905
|
return __generator(this, function (_a) {
|
|
893
906
|
switch (_a.label) {
|
|
894
|
-
case 0: return [4 /*yield*/, this.retrieve(
|
|
895
|
-
|
|
896
|
-
})
|
|
897
|
-
// Ensure that the line item exists in the cart
|
|
898
|
-
];
|
|
907
|
+
case 0: return [4 /*yield*/, this.lineItemService_.retrieve(lineItemId, {
|
|
908
|
+
select: ["id", "quantity", "variant_id", "cart_id"],
|
|
909
|
+
})];
|
|
899
910
|
case 1:
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
911
|
+
lineItem = _a.sent();
|
|
912
|
+
if (lineItem.cart_id !== cartId) {
|
|
913
|
+
// Ensure that the line item exists in the cart
|
|
903
914
|
throw new medusa_core_utils_1.MedusaError(medusa_core_utils_1.MedusaError.Types.INVALID_DATA, "A line item with the provided id doesn't exist in the cart");
|
|
904
915
|
}
|
|
905
|
-
if (!lineItemUpdate.quantity) return [3 /*break*/,
|
|
906
|
-
return [
|
|
907
|
-
|
|
908
|
-
|
|
916
|
+
if (!lineItemUpdate.quantity) return [3 /*break*/, 4];
|
|
917
|
+
if (!lineItem.variant_id) return [3 /*break*/, 4];
|
|
918
|
+
select = ["id"];
|
|
919
|
+
if (this.featureFlagRouter_.isFeatureEnabled(sales_channels_1.default.key)) {
|
|
920
|
+
select.push("sales_channel_id");
|
|
921
|
+
}
|
|
922
|
+
return [4 /*yield*/, this.retrieve(cartId, { select: select })];
|
|
909
923
|
case 2:
|
|
924
|
+
cart = _a.sent();
|
|
925
|
+
return [4 /*yield*/, this.productVariantInventoryService_.confirmInventory(lineItem.variant_id, lineItemUpdate.quantity, { salesChannelId: cart.sales_channel_id })];
|
|
926
|
+
case 3:
|
|
910
927
|
hasInventory = _a.sent();
|
|
911
928
|
if (!hasInventory) {
|
|
912
929
|
throw new medusa_core_utils_1.MedusaError(medusa_core_utils_1.MedusaError.Types.NOT_ALLOWED, "Inventory doesn't cover the desired quantity");
|
|
913
930
|
}
|
|
914
|
-
_a.label =
|
|
915
|
-
case
|
|
931
|
+
_a.label = 4;
|
|
932
|
+
case 4: return [4 /*yield*/, this.lineItemService_
|
|
916
933
|
.withTransaction(transactionManager)
|
|
917
934
|
.update(lineItemId, lineItemUpdate)];
|
|
918
|
-
case
|
|
935
|
+
case 5:
|
|
919
936
|
_a.sent();
|
|
920
937
|
return [4 /*yield*/, this.retrieve(cartId, {
|
|
921
938
|
relations: ["items", "discounts", "discounts.rule", "region"],
|
|
922
939
|
})];
|
|
923
|
-
case
|
|
940
|
+
case 6:
|
|
924
941
|
updatedCart = _a.sent();
|
|
925
942
|
return [4 /*yield*/, this.refreshAdjustments_(updatedCart)
|
|
926
943
|
// Update the line item
|
|
927
944
|
];
|
|
928
|
-
case
|
|
945
|
+
case 7:
|
|
929
946
|
_a.sent();
|
|
930
947
|
// Update the line item
|
|
931
948
|
return [4 /*yield*/, this.eventBus_
|
|
932
949
|
.withTransaction(transactionManager)
|
|
933
950
|
.emit(CartService.Events.UPDATED, updatedCart)];
|
|
934
|
-
case
|
|
951
|
+
case 8:
|
|
935
952
|
// Update the line item
|
|
936
953
|
_a.sent();
|
|
937
954
|
return [2 /*return*/, updatedCart];
|
|
@@ -1703,10 +1720,9 @@ var CartService = /** @class */ (function (_super) {
|
|
|
1703
1720
|
});
|
|
1704
1721
|
};
|
|
1705
1722
|
/**
|
|
1706
|
-
*
|
|
1723
|
+
* Selects a payment session for a cart and creates a payment object in the external provider system
|
|
1707
1724
|
* @param cartId - the id of the cart to add payment method to
|
|
1708
1725
|
* @param providerId - the id of the provider to be set to the cart
|
|
1709
|
-
* @return result of update operation
|
|
1710
1726
|
*/
|
|
1711
1727
|
CartService.prototype.setPaymentSession = function (cartId, providerId) {
|
|
1712
1728
|
return __awaiter(this, void 0, void 0, function () {
|
|
@@ -1714,52 +1730,73 @@ var CartService = /** @class */ (function (_super) {
|
|
|
1714
1730
|
return __generator(this, function (_a) {
|
|
1715
1731
|
switch (_a.label) {
|
|
1716
1732
|
case 0: return [4 /*yield*/, this.atomicPhase_(function (transactionManager) { return __awaiter(_this, void 0, void 0, function () {
|
|
1717
|
-
var psRepo, cart, paymentSession,
|
|
1718
|
-
var _this = this;
|
|
1733
|
+
var psRepo, cart, isProviderPresent, cartPaymentSessionIds, paymentSession, sessionInput;
|
|
1719
1734
|
return __generator(this, function (_a) {
|
|
1720
1735
|
switch (_a.label) {
|
|
1721
1736
|
case 0:
|
|
1722
1737
|
psRepo = transactionManager.getCustomRepository(this.paymentSessionRepository_);
|
|
1723
1738
|
return [4 /*yield*/, this.retrieveWithTotals(cartId, {
|
|
1724
|
-
relations: [
|
|
1725
|
-
|
|
1726
|
-
|
|
1727
|
-
|
|
1739
|
+
relations: [
|
|
1740
|
+
"customer",
|
|
1741
|
+
"region",
|
|
1742
|
+
"region.payment_providers",
|
|
1743
|
+
"payment_sessions",
|
|
1744
|
+
],
|
|
1745
|
+
})];
|
|
1728
1746
|
case 1:
|
|
1729
1747
|
cart = _a.sent();
|
|
1730
|
-
|
|
1731
|
-
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
return providerId === id;
|
|
1736
|
-
}))) {
|
|
1748
|
+
isProviderPresent = cart.region.payment_providers.find(function (_a) {
|
|
1749
|
+
var id = _a.id;
|
|
1750
|
+
return providerId === id;
|
|
1751
|
+
});
|
|
1752
|
+
if (providerId !== "system" && !isProviderPresent) {
|
|
1737
1753
|
throw new medusa_core_utils_1.MedusaError(medusa_core_utils_1.MedusaError.Types.NOT_ALLOWED, "The payment method is not available in this region");
|
|
1738
1754
|
}
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
|
|
1743
|
-
}); }))];
|
|
1755
|
+
cartPaymentSessionIds = cart.payment_sessions.map(function (p) { return p.id; });
|
|
1756
|
+
return [4 /*yield*/, psRepo.update({ id: (0, typeorm_1.In)(cartPaymentSessionIds) }, {
|
|
1757
|
+
is_selected: null,
|
|
1758
|
+
})];
|
|
1744
1759
|
case 2:
|
|
1745
1760
|
_a.sent();
|
|
1746
1761
|
paymentSession = cart.payment_sessions.find(function (ps) { return ps.provider_id === providerId; });
|
|
1747
1762
|
if (!paymentSession) {
|
|
1748
1763
|
throw new medusa_core_utils_1.MedusaError(medusa_core_utils_1.MedusaError.Types.UNEXPECTED_STATE, "Could not find payment session");
|
|
1749
1764
|
}
|
|
1750
|
-
|
|
1751
|
-
|
|
1765
|
+
sessionInput = {
|
|
1766
|
+
cart: cart,
|
|
1767
|
+
customer: cart.customer,
|
|
1768
|
+
amount: cart.total,
|
|
1769
|
+
currency_code: cart.region.currency_code,
|
|
1770
|
+
provider_id: providerId,
|
|
1771
|
+
payment_session_id: paymentSession.id,
|
|
1772
|
+
};
|
|
1773
|
+
if (!paymentSession.is_selected) return [3 /*break*/, 4];
|
|
1774
|
+
// update the session remotely
|
|
1775
|
+
return [4 /*yield*/, this.paymentProviderService_
|
|
1776
|
+
.withTransaction(transactionManager)
|
|
1777
|
+
.updateSession(paymentSession, sessionInput)];
|
|
1752
1778
|
case 3:
|
|
1779
|
+
// update the session remotely
|
|
1753
1780
|
_a.sent();
|
|
1754
|
-
|
|
1781
|
+
_a.label = 4;
|
|
1755
1782
|
case 4:
|
|
1756
|
-
|
|
1757
|
-
return [4 /*yield*/, this.
|
|
1783
|
+
if (!!paymentSession.is_initiated) return [3 /*break*/, 6];
|
|
1784
|
+
return [4 /*yield*/, this.paymentProviderService_
|
|
1758
1785
|
.withTransaction(transactionManager)
|
|
1759
|
-
.
|
|
1786
|
+
.createSession(sessionInput)];
|
|
1760
1787
|
case 5:
|
|
1788
|
+
// Create the session remotely
|
|
1789
|
+
paymentSession = _a.sent();
|
|
1790
|
+
_a.label = 6;
|
|
1791
|
+
case 6: return [4 /*yield*/, psRepo.update(paymentSession.id, { is_selected: true })];
|
|
1792
|
+
case 7:
|
|
1761
1793
|
_a.sent();
|
|
1762
|
-
return [
|
|
1794
|
+
return [4 /*yield*/, this.eventBus_
|
|
1795
|
+
.withTransaction(transactionManager)
|
|
1796
|
+
.emit(CartService.Events.UPDATED, { id: cartId })];
|
|
1797
|
+
case 8:
|
|
1798
|
+
_a.sent();
|
|
1799
|
+
return [2 /*return*/];
|
|
1763
1800
|
}
|
|
1764
1801
|
});
|
|
1765
1802
|
}); }, "SERIALIZABLE")];
|
|
@@ -1783,13 +1820,13 @@ var CartService = /** @class */ (function (_super) {
|
|
|
1783
1820
|
return __generator(this, function (_a) {
|
|
1784
1821
|
switch (_a.label) {
|
|
1785
1822
|
case 0: return [4 /*yield*/, this.atomicPhase_(function (transactionManager) { return __awaiter(_this, void 0, void 0, function () {
|
|
1786
|
-
var psRepo, cartId, cart, total, region, partialSessionInput,
|
|
1823
|
+
var psRepo, paymentProviderServiceTx, cartId, cart, total, region, deleteSessionAppropriately, providerSet, alreadyConsumedProviderIds, partialSessionInput, partialPaymentSessionData, paymentProvider, paymentSessionInput, paymentSession;
|
|
1787
1824
|
var _this = this;
|
|
1788
|
-
|
|
1789
|
-
|
|
1790
|
-
switch (_b.label) {
|
|
1825
|
+
return __generator(this, function (_a) {
|
|
1826
|
+
switch (_a.label) {
|
|
1791
1827
|
case 0:
|
|
1792
1828
|
psRepo = transactionManager.getCustomRepository(this.paymentSessionRepository_);
|
|
1829
|
+
paymentProviderServiceTx = this.paymentProviderService_.withTransaction(transactionManager);
|
|
1793
1830
|
cartId = typeof cartOrCartId === "string" ? cartOrCartId : cartOrCartId.id;
|
|
1794
1831
|
return [4 /*yield*/, this.retrieveWithTotals(cartId, {
|
|
1795
1832
|
relations: [
|
|
@@ -1809,72 +1846,118 @@ var CartService = /** @class */ (function (_super) {
|
|
|
1809
1846
|
],
|
|
1810
1847
|
}, { force_taxes: true })];
|
|
1811
1848
|
case 1:
|
|
1812
|
-
cart =
|
|
1849
|
+
cart = _a.sent();
|
|
1813
1850
|
total = cart.total, region = cart.region;
|
|
1851
|
+
deleteSessionAppropriately = function (session) { return __awaiter(_this, void 0, void 0, function () {
|
|
1852
|
+
return __generator(this, function (_a) {
|
|
1853
|
+
if (session.is_selected || session.is_initiated) {
|
|
1854
|
+
return [2 /*return*/, paymentProviderServiceTx.deleteSession(session)];
|
|
1855
|
+
}
|
|
1856
|
+
return [2 /*return*/, psRepo.delete(session)];
|
|
1857
|
+
});
|
|
1858
|
+
}); };
|
|
1859
|
+
if (!(total <= 0)) return [3 /*break*/, 3];
|
|
1860
|
+
return [4 /*yield*/, Promise.all(cart.payment_sessions.map(function (session) { return __awaiter(_this, void 0, void 0, function () {
|
|
1861
|
+
return __generator(this, function (_a) {
|
|
1862
|
+
return [2 /*return*/, deleteSessionAppropriately(session)];
|
|
1863
|
+
});
|
|
1864
|
+
}); }))];
|
|
1865
|
+
case 2:
|
|
1866
|
+
_a.sent();
|
|
1867
|
+
return [2 /*return*/];
|
|
1868
|
+
case 3:
|
|
1869
|
+
providerSet = new Set(region.payment_providers.map(function (p) { return p.id; }));
|
|
1870
|
+
alreadyConsumedProviderIds = new Set();
|
|
1814
1871
|
partialSessionInput = {
|
|
1815
1872
|
cart: cart,
|
|
1816
1873
|
customer: cart.customer,
|
|
1817
|
-
amount:
|
|
1874
|
+
amount: total,
|
|
1818
1875
|
currency_code: cart.region.currency_code,
|
|
1819
1876
|
};
|
|
1820
|
-
|
|
1821
|
-
|
|
1822
|
-
|
|
1823
|
-
|
|
1877
|
+
partialPaymentSessionData = {
|
|
1878
|
+
cart_id: cartId,
|
|
1879
|
+
data: {},
|
|
1880
|
+
status: models_1.PaymentSessionStatus.PENDING,
|
|
1881
|
+
amount: total,
|
|
1882
|
+
};
|
|
1883
|
+
return [4 /*yield*/, Promise.all(cart.payment_sessions.map(function (session) { return __awaiter(_this, void 0, void 0, function () {
|
|
1884
|
+
var paymentSessionInput, updatedSession;
|
|
1824
1885
|
return __generator(this, function (_a) {
|
|
1825
|
-
|
|
1826
|
-
|
|
1827
|
-
|
|
1828
|
-
return
|
|
1829
|
-
|
|
1830
|
-
|
|
1831
|
-
|
|
1832
|
-
|
|
1886
|
+
switch (_a.label) {
|
|
1887
|
+
case 0:
|
|
1888
|
+
if (!!providerSet.has(session.provider_id)) return [3 /*break*/, 2];
|
|
1889
|
+
return [4 /*yield*/, deleteSessionAppropriately(session)];
|
|
1890
|
+
case 1:
|
|
1891
|
+
/**
|
|
1892
|
+
* if the provider does not belong to the region then delete the session.
|
|
1893
|
+
* The deletion occurs locally if there is no external data or if it is not selected
|
|
1894
|
+
* otherwise the deletion will also occur remotely through the external provider.
|
|
1895
|
+
*/
|
|
1896
|
+
return [2 /*return*/, _a.sent()];
|
|
1897
|
+
case 2:
|
|
1898
|
+
/**
|
|
1899
|
+
* if the provider belongs to the region then update or delete the session.
|
|
1900
|
+
* The update occurs locally if it is not selected
|
|
1901
|
+
* otherwise the update will also occur remotely through the external provider.
|
|
1902
|
+
* In case the session is not selected but contains an external provider data, we delete the external provider
|
|
1903
|
+
* session to be in a clean state.
|
|
1904
|
+
*/
|
|
1905
|
+
// We are saving the provider id on which the work below will be done. That way,
|
|
1906
|
+
// when handling the providers from the cart region at a later point below, we do not double the work on the sessions that already
|
|
1907
|
+
// exists for the same provider.
|
|
1908
|
+
alreadyConsumedProviderIds.add(session.provider_id);
|
|
1909
|
+
// Update remotely
|
|
1910
|
+
if (session.is_selected) {
|
|
1911
|
+
paymentSessionInput = __assign(__assign({}, partialSessionInput), { provider_id: session.provider_id });
|
|
1912
|
+
return [2 /*return*/, paymentProviderServiceTx.updateSession(session, paymentSessionInput)];
|
|
1913
|
+
}
|
|
1914
|
+
if (!session.is_initiated) return [3 /*break*/, 4];
|
|
1915
|
+
return [4 /*yield*/, paymentProviderServiceTx.deleteSession(session)];
|
|
1916
|
+
case 3:
|
|
1917
|
+
_a.sent();
|
|
1918
|
+
updatedSession = psRepo.create(__assign(__assign({}, partialPaymentSessionData), { provider_id: session.provider_id }));
|
|
1919
|
+
return [3 /*break*/, 5];
|
|
1920
|
+
case 4:
|
|
1921
|
+
updatedSession = __assign(__assign({}, session), { amount: total });
|
|
1922
|
+
_a.label = 5;
|
|
1923
|
+
case 5: return [2 /*return*/, psRepo.save(updatedSession)];
|
|
1833
1924
|
}
|
|
1834
|
-
else {
|
|
1835
|
-
seen.push(paymentSession.provider_id);
|
|
1836
|
-
paymentSessionInput = __assign(__assign({}, partialSessionInput), { provider_id: paymentSession.provider_id });
|
|
1837
|
-
return [2 /*return*/, this.paymentProviderService_
|
|
1838
|
-
.withTransaction(transactionManager)
|
|
1839
|
-
.updateSession(paymentSession, paymentSessionInput)];
|
|
1840
|
-
}
|
|
1841
|
-
return [2 /*return*/];
|
|
1842
1925
|
});
|
|
1843
|
-
}); }))
|
|
1844
|
-
|
|
1845
|
-
|
|
1846
|
-
|
|
1847
|
-
|
|
1848
|
-
|
|
1849
|
-
|
|
1926
|
+
}); }))
|
|
1927
|
+
/**
|
|
1928
|
+
* From now on, the sessions have been cleanup. We can now
|
|
1929
|
+
* - Set the provider session as selected if it is the only one existing and there is no payment session on the cart
|
|
1930
|
+
* - Create a session per provider locally if it does not already exists on the cart as per the previous step
|
|
1931
|
+
*/
|
|
1932
|
+
// If only one provider exists and there is no session on the cart, create the session and select it.
|
|
1933
|
+
];
|
|
1934
|
+
case 4:
|
|
1935
|
+
_a.sent();
|
|
1936
|
+
if (!(region.payment_providers.length === 1 && !cart.payment_session)) return [3 /*break*/, 7];
|
|
1850
1937
|
paymentProvider = region.payment_providers[0];
|
|
1851
1938
|
paymentSessionInput = __assign(__assign({}, partialSessionInput), { provider_id: paymentProvider.id });
|
|
1852
1939
|
return [4 /*yield*/, this.paymentProviderService_
|
|
1853
1940
|
.withTransaction(transactionManager)
|
|
1854
1941
|
.createSession(paymentSessionInput)];
|
|
1855
|
-
case 4:
|
|
1856
|
-
paymentSession = _b.sent();
|
|
1857
|
-
paymentSession.is_selected = true;
|
|
1858
|
-
return [4 /*yield*/, psRepo.save(paymentSession)];
|
|
1859
1942
|
case 5:
|
|
1860
|
-
|
|
1861
|
-
return [
|
|
1862
|
-
case 6:
|
|
1863
|
-
|
|
1943
|
+
paymentSession = _a.sent();
|
|
1944
|
+
return [4 /*yield*/, psRepo.update(paymentSession.id, { is_selected: true })];
|
|
1945
|
+
case 6:
|
|
1946
|
+
_a.sent();
|
|
1947
|
+
return [2 /*return*/];
|
|
1948
|
+
case 7: return [4 /*yield*/, Promise.all(region.payment_providers.map(function (paymentProvider) { return __awaiter(_this, void 0, void 0, function () {
|
|
1949
|
+
var paymentSession;
|
|
1864
1950
|
return __generator(this, function (_a) {
|
|
1865
|
-
if (
|
|
1866
|
-
|
|
1867
|
-
return [2 /*return*/, this.paymentProviderService_
|
|
1868
|
-
.withTransaction(transactionManager)
|
|
1869
|
-
.createSession(paymentSessionInput)];
|
|
1951
|
+
if (alreadyConsumedProviderIds.has(paymentProvider.id)) {
|
|
1952
|
+
return [2 /*return*/];
|
|
1870
1953
|
}
|
|
1871
|
-
|
|
1954
|
+
paymentSession = psRepo.create(__assign(__assign({}, partialPaymentSessionData), { provider_id: paymentProvider.id }));
|
|
1955
|
+
return [2 /*return*/, psRepo.save(paymentSession)];
|
|
1872
1956
|
});
|
|
1873
1957
|
}); }))];
|
|
1874
|
-
case
|
|
1875
|
-
|
|
1876
|
-
|
|
1877
|
-
case 8: return [2 /*return*/];
|
|
1958
|
+
case 8:
|
|
1959
|
+
_a.sent();
|
|
1960
|
+
return [2 /*return*/];
|
|
1878
1961
|
}
|
|
1879
1962
|
});
|
|
1880
1963
|
}); })];
|
|
@@ -1896,7 +1979,7 @@ var CartService = /** @class */ (function (_super) {
|
|
|
1896
1979
|
return __generator(this, function (_a) {
|
|
1897
1980
|
switch (_a.label) {
|
|
1898
1981
|
case 0: return [4 /*yield*/, this.atomicPhase_(function (transactionManager) { return __awaiter(_this, void 0, void 0, function () {
|
|
1899
|
-
var cart, cartRepo, paymentSession;
|
|
1982
|
+
var cart, cartRepo, paymentSession, psRepo;
|
|
1900
1983
|
return __generator(this, function (_a) {
|
|
1901
1984
|
switch (_a.label) {
|
|
1902
1985
|
case 0: return [4 /*yield*/, this.retrieve(cartId, {
|
|
@@ -1905,7 +1988,7 @@ var CartService = /** @class */ (function (_super) {
|
|
|
1905
1988
|
case 1:
|
|
1906
1989
|
cart = _a.sent();
|
|
1907
1990
|
cartRepo = transactionManager.getCustomRepository(this.cartRepository_);
|
|
1908
|
-
if (!cart.payment_sessions) return [3 /*break*/,
|
|
1991
|
+
if (!cart.payment_sessions) return [3 /*break*/, 5];
|
|
1909
1992
|
paymentSession = cart.payment_sessions.find(function (_a) {
|
|
1910
1993
|
var provider_id = _a.provider_id;
|
|
1911
1994
|
return provider_id === providerId;
|
|
@@ -1914,24 +1997,28 @@ var CartService = /** @class */ (function (_super) {
|
|
|
1914
1997
|
var provider_id = _a.provider_id;
|
|
1915
1998
|
return provider_id !== providerId;
|
|
1916
1999
|
});
|
|
1917
|
-
|
|
1918
|
-
|
|
2000
|
+
psRepo = transactionManager.getCustomRepository(this.paymentSessionRepository_);
|
|
2001
|
+
if (!paymentSession) return [3 /*break*/, 5];
|
|
2002
|
+
if (!(paymentSession.is_selected || paymentSession.is_initiated)) return [3 /*break*/, 3];
|
|
1919
2003
|
return [4 /*yield*/, this.paymentProviderService_
|
|
1920
2004
|
.withTransaction(transactionManager)
|
|
1921
2005
|
.deleteSession(paymentSession)];
|
|
1922
2006
|
case 2:
|
|
1923
|
-
// Delete the session with the provider
|
|
1924
2007
|
_a.sent();
|
|
1925
|
-
|
|
1926
|
-
case 3: return [4 /*yield*/,
|
|
2008
|
+
return [3 /*break*/, 5];
|
|
2009
|
+
case 3: return [4 /*yield*/, psRepo.delete(paymentSession)];
|
|
1927
2010
|
case 4:
|
|
2011
|
+
_a.sent();
|
|
2012
|
+
_a.label = 5;
|
|
2013
|
+
case 5: return [4 /*yield*/, cartRepo.save(cart)];
|
|
2014
|
+
case 6:
|
|
1928
2015
|
_a.sent();
|
|
1929
2016
|
return [4 /*yield*/, this.eventBus_
|
|
1930
2017
|
.withTransaction(transactionManager)
|
|
1931
|
-
.emit(CartService.Events.UPDATED, cart)];
|
|
1932
|
-
case
|
|
2018
|
+
.emit(CartService.Events.UPDATED, { id: cart.id })];
|
|
2019
|
+
case 7:
|
|
1933
2020
|
_a.sent();
|
|
1934
|
-
return [2 /*return
|
|
2021
|
+
return [2 /*return*/];
|
|
1935
2022
|
}
|
|
1936
2023
|
});
|
|
1937
2024
|
}); })];
|
|
@@ -1945,7 +2032,7 @@ var CartService = /** @class */ (function (_super) {
|
|
|
1945
2032
|
* @param cartId - the id of the cart to remove from
|
|
1946
2033
|
* @param providerId - the id of the provider whoose payment session
|
|
1947
2034
|
* should be removed.
|
|
1948
|
-
* @return {Promise<
|
|
2035
|
+
* @return {Promise<void>} the resulting cart.
|
|
1949
2036
|
*/
|
|
1950
2037
|
CartService.prototype.refreshPaymentSession = function (cartId, providerId) {
|
|
1951
2038
|
return __awaiter(this, void 0, void 0, function () {
|
|
@@ -1953,7 +2040,7 @@ var CartService = /** @class */ (function (_super) {
|
|
|
1953
2040
|
return __generator(this, function (_a) {
|
|
1954
2041
|
switch (_a.label) {
|
|
1955
2042
|
case 0: return [4 /*yield*/, this.atomicPhase_(function (transactionManager) { return __awaiter(_this, void 0, void 0, function () {
|
|
1956
|
-
var cart, paymentSession,
|
|
2043
|
+
var cart, paymentSession, psRepo;
|
|
1957
2044
|
return __generator(this, function (_a) {
|
|
1958
2045
|
switch (_a.label) {
|
|
1959
2046
|
case 0: return [4 /*yield*/, this.retrieveWithTotals(cartId, {
|
|
@@ -1961,13 +2048,13 @@ var CartService = /** @class */ (function (_super) {
|
|
|
1961
2048
|
})];
|
|
1962
2049
|
case 1:
|
|
1963
2050
|
cart = _a.sent();
|
|
1964
|
-
if (!cart.payment_sessions) return [3 /*break*/,
|
|
2051
|
+
if (!cart.payment_sessions) return [3 /*break*/, 5];
|
|
1965
2052
|
paymentSession = cart.payment_sessions.find(function (_a) {
|
|
1966
2053
|
var provider_id = _a.provider_id;
|
|
1967
2054
|
return provider_id === providerId;
|
|
1968
2055
|
});
|
|
1969
|
-
if (!paymentSession) return [3 /*break*/,
|
|
1970
|
-
|
|
2056
|
+
if (!paymentSession) return [3 /*break*/, 5];
|
|
2057
|
+
if (!paymentSession.is_selected) return [3 /*break*/, 3];
|
|
1971
2058
|
return [4 /*yield*/, this.paymentProviderService_
|
|
1972
2059
|
.withTransaction(transactionManager)
|
|
1973
2060
|
.refreshSession(paymentSession, {
|
|
@@ -1978,18 +2065,22 @@ var CartService = /** @class */ (function (_super) {
|
|
|
1978
2065
|
provider_id: providerId,
|
|
1979
2066
|
})];
|
|
1980
2067
|
case 2:
|
|
1981
|
-
// Delete the session with the provider
|
|
1982
2068
|
_a.sent();
|
|
1983
|
-
|
|
1984
|
-
case 3:
|
|
2069
|
+
return [3 /*break*/, 5];
|
|
2070
|
+
case 3:
|
|
2071
|
+
psRepo = transactionManager.getCustomRepository(this.paymentSessionRepository_);
|
|
2072
|
+
return [4 /*yield*/, psRepo.update(paymentSession.id, {
|
|
2073
|
+
amount: cart.total,
|
|
2074
|
+
})];
|
|
1985
2075
|
case 4:
|
|
1986
|
-
updatedCart = _a.sent();
|
|
1987
|
-
return [4 /*yield*/, this.eventBus_
|
|
1988
|
-
.withTransaction(transactionManager)
|
|
1989
|
-
.emit(CartService.Events.UPDATED, updatedCart)];
|
|
1990
|
-
case 5:
|
|
1991
2076
|
_a.sent();
|
|
1992
|
-
|
|
2077
|
+
_a.label = 5;
|
|
2078
|
+
case 5: return [4 /*yield*/, this.eventBus_
|
|
2079
|
+
.withTransaction(transactionManager)
|
|
2080
|
+
.emit(CartService.Events.UPDATED, { id: cartId })];
|
|
2081
|
+
case 6:
|
|
2082
|
+
_a.sent();
|
|
2083
|
+
return [2 /*return*/];
|
|
1993
2084
|
}
|
|
1994
2085
|
});
|
|
1995
2086
|
}); })];
|
|
@@ -2166,28 +2257,31 @@ var CartService = /** @class */ (function (_super) {
|
|
|
2166
2257
|
var availablePrice;
|
|
2167
2258
|
return __generator(this, function (_a) {
|
|
2168
2259
|
switch (_a.label) {
|
|
2169
|
-
case 0:
|
|
2170
|
-
|
|
2171
|
-
|
|
2172
|
-
|
|
2173
|
-
|
|
2174
|
-
|
|
2175
|
-
|
|
2176
|
-
|
|
2177
|
-
|
|
2178
|
-
|
|
2260
|
+
case 0:
|
|
2261
|
+
if (!item.variant_id) {
|
|
2262
|
+
return [2 /*return*/, item];
|
|
2263
|
+
}
|
|
2264
|
+
return [4 /*yield*/, this.priceSelectionStrategy_
|
|
2265
|
+
.withTransaction(transactionManager)
|
|
2266
|
+
.calculateVariantPrice(item.variant_id, {
|
|
2267
|
+
region_id: region_1.id,
|
|
2268
|
+
currency_code: region_1.currency_code,
|
|
2269
|
+
quantity: item.quantity,
|
|
2270
|
+
customer_id: customer_id || cart.customer_id,
|
|
2271
|
+
include_discount_prices: true,
|
|
2272
|
+
})
|
|
2273
|
+
.catch(function () { return undefined; })];
|
|
2179
2274
|
case 1:
|
|
2180
2275
|
availablePrice = _a.sent();
|
|
2181
2276
|
if (!(availablePrice !== undefined &&
|
|
2182
|
-
availablePrice.calculatedPrice !== null)) return [3 /*break*/,
|
|
2183
|
-
return [
|
|
2277
|
+
availablePrice.calculatedPrice !== null)) return [3 /*break*/, 3];
|
|
2278
|
+
return [4 /*yield*/, lineItemServiceTx_2.update(item.id, {
|
|
2184
2279
|
has_shipping: false,
|
|
2185
2280
|
unit_price: availablePrice.calculatedPrice,
|
|
2186
2281
|
})];
|
|
2187
|
-
case 2: return [
|
|
2188
|
-
case 3:
|
|
2189
|
-
|
|
2190
|
-
return [2 /*return*/];
|
|
2282
|
+
case 2: return [2 /*return*/, _a.sent()];
|
|
2283
|
+
case 3: return [4 /*yield*/, lineItemServiceTx_2.delete(item.id)];
|
|
2284
|
+
case 4: return [2 /*return*/, _a.sent()];
|
|
2191
2285
|
}
|
|
2192
2286
|
});
|
|
2193
2287
|
}); }))];
|