@medusajs/medusa 1.3.0 → 1.3.1-alpha.63
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/CHANGELOG.md +50 -0
- package/dist/api/middlewares/authenticate-customer.d.ts +2 -1
- package/dist/api/middlewares/authenticate-customer.js +1 -2
- package/dist/api/middlewares/authenticate-customer.js.map +1 -1
- package/dist/api/middlewares/authenticate.d.ts +2 -1
- package/dist/api/middlewares/authenticate.js.map +1 -1
- package/dist/api/middlewares/await-middleware.d.ts +3 -1
- package/dist/api/middlewares/await-middleware.js +2 -31
- package/dist/api/middlewares/await-middleware.js.map +1 -1
- package/dist/api/middlewares/batch-job/can-access-batch-job.d.ts +1 -0
- package/dist/api/middlewares/batch-job/can-access-batch-job.js +70 -0
- package/dist/api/middlewares/batch-job/can-access-batch-job.js.map +1 -0
- package/dist/api/middlewares/batch-job/get-requested-batch-job.d.ts +1 -0
- package/dist/api/middlewares/batch-job/get-requested-batch-job.js +67 -0
- package/dist/api/middlewares/batch-job/get-requested-batch-job.js.map +1 -0
- package/dist/api/middlewares/error-handler.d.ts +3 -1
- package/dist/api/middlewares/error-handler.js +3 -3
- package/dist/api/middlewares/error-handler.js.map +1 -1
- package/dist/api/middlewares/index.d.ts +12 -10
- package/dist/api/middlewares/index.js +9 -0
- package/dist/api/middlewares/index.js.map +1 -1
- package/dist/api/middlewares/normalized-query.d.ts +6 -1
- package/dist/api/middlewares/normalized-query.js +5 -2
- package/dist/api/middlewares/normalized-query.js.map +1 -1
- package/dist/api/middlewares/transform-body.d.ts +4 -0
- package/dist/api/middlewares/transform-body.js +66 -0
- package/dist/api/middlewares/transform-body.js.map +1 -0
- package/dist/api/middlewares/transform-query.d.ts +6 -0
- package/dist/api/middlewares/transform-query.js +86 -0
- package/dist/api/middlewares/transform-query.js.map +1 -0
- package/dist/api/routes/admin/batch/index.d.ts +13 -0
- package/dist/api/routes/admin/batch/index.js +50 -0
- package/dist/api/routes/admin/batch/index.js.map +1 -0
- package/dist/api/routes/admin/batch/list-batch-jobs.d.ts +48 -0
- package/dist/api/routes/admin/batch/list-batch-jobs.js +220 -0
- package/dist/api/routes/admin/batch/list-batch-jobs.js.map +1 -0
- package/dist/api/routes/admin/discounts/add-valid-product.d.ts +23 -0
- package/dist/api/routes/admin/discounts/add-valid-product.js +82 -0
- package/dist/api/routes/admin/discounts/add-valid-product.js.map +1 -0
- 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.d.ts +3 -2
- package/dist/api/routes/admin/discounts/create-discount.js +7 -5
- 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/get-discount-by-code.d.ts +4 -0
- package/dist/api/routes/admin/discounts/get-discount-by-code.js +40 -6
- package/dist/api/routes/admin/discounts/get-discount-by-code.js.map +1 -1
- 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/remove-valid-product.d.ts +23 -0
- package/dist/api/routes/admin/discounts/remove-valid-product.js +82 -0
- package/dist/api/routes/admin/discounts/remove-valid-product.js.map +1 -0
- 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/discounts/update-discount.d.ts +6 -10
- package/dist/api/routes/admin/discounts/update-discount.js +9 -18
- package/dist/api/routes/admin/discounts/update-discount.js.map +1 -1
- package/dist/api/routes/admin/draft-orders/index.d.ts +1 -1
- package/dist/api/routes/admin/draft-orders/index.js.map +1 -1
- package/dist/api/routes/admin/draft-orders/list-draft-orders.js +7 -6
- package/dist/api/routes/admin/draft-orders/list-draft-orders.js.map +1 -1
- package/dist/api/routes/admin/index.js +2 -0
- package/dist/api/routes/admin/index.js.map +1 -1
- package/dist/api/routes/admin/orders/create-claim.d.ts +4 -14
- package/dist/api/routes/admin/orders/create-claim.js +9 -14
- package/dist/api/routes/admin/orders/create-claim.js.map +1 -1
- package/dist/api/routes/admin/orders/fulfill-claim.d.ts +1 -1
- package/dist/api/routes/admin/orders/fulfill-claim.js.map +1 -1
- package/dist/api/routes/admin/orders/update-claim.d.ts +1 -1
- package/dist/api/routes/admin/orders/update-claim.js.map +1 -1
- package/dist/api/routes/admin/price-lists/create-price-list.d.ts +2 -1
- package/dist/api/routes/admin/price-lists/create-price-list.js +4 -7
- package/dist/api/routes/admin/price-lists/create-price-list.js.map +1 -1
- package/dist/api/routes/admin/price-lists/delete-product-prices.d.ts +32 -0
- package/dist/api/routes/admin/price-lists/delete-product-prices.js +105 -0
- package/dist/api/routes/admin/price-lists/delete-product-prices.js.map +1 -0
- package/dist/api/routes/admin/price-lists/delete-variant-prices.d.ts +32 -0
- package/dist/api/routes/admin/price-lists/delete-variant-prices.js +105 -0
- package/dist/api/routes/admin/price-lists/delete-variant-prices.js.map +1 -0
- package/dist/api/routes/admin/price-lists/index.d.ts +2 -0
- package/dist/api/routes/admin/price-lists/index.js +28 -7
- package/dist/api/routes/admin/price-lists/index.js.map +1 -1
- package/dist/api/routes/admin/price-lists/list-price-list-products.d.ts +2 -1
- package/dist/api/routes/admin/price-lists/list-price-list-products.js +38 -29
- package/dist/api/routes/admin/price-lists/list-price-list-products.js.map +1 -1
- package/dist/api/routes/admin/price-lists/list-price-lists.d.ts +2 -1
- package/dist/api/routes/admin/price-lists/list-price-lists.js +8 -40
- package/dist/api/routes/admin/price-lists/list-price-lists.js.map +1 -1
- package/dist/api/routes/admin/price-lists/update-price-list.d.ts +2 -2
- package/dist/api/routes/admin/price-lists/update-price-list.js +2 -2
- package/dist/api/routes/admin/price-lists/update-price-list.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/api/routes/admin/store/get-store.js +4 -2
- package/dist/api/routes/admin/store/get-store.js.map +1 -1
- package/dist/api/routes/admin/store/update-store.d.ts +1 -0
- package/dist/api/routes/admin/store/update-store.js +5 -0
- package/dist/api/routes/admin/store/update-store.js.map +1 -1
- package/dist/api/routes/admin/users/update-user.d.ts +1 -1
- package/dist/api/routes/admin/users/update-user.js.map +1 -1
- package/dist/api/routes/store/carts/update-cart.js +1 -1
- package/dist/api/routes/store/carts/update-cart.js.map +1 -1
- package/dist/api/routes/store/carts/update-payment-method.d.ts +38 -0
- package/dist/api/routes/store/carts/update-payment-method.js +122 -0
- package/dist/api/routes/store/carts/update-payment-method.js.map +1 -0
- package/dist/api/routes/store/customers/get-payment-methods.js +6 -7
- package/dist/api/routes/store/customers/get-payment-methods.js.map +1 -1
- package/dist/commands/develop.js +1 -1
- package/dist/commands/develop.js.map +1 -1
- package/dist/commands/migrate.js +17 -6
- package/dist/commands/migrate.js.map +1 -1
- package/dist/commands/start.js +6 -0
- package/dist/commands/start.js.map +1 -1
- package/dist/config/index.d.ts +14 -0
- package/dist/config/index.js +40 -0
- package/dist/config/index.js.map +1 -0
- package/dist/controllers/products/admin-list-products.js +2 -2
- package/dist/controllers/products/admin-list-products.js.map +1 -1
- package/dist/helpers/test-request.js +11 -10
- package/dist/helpers/test-request.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/interfaces/base-service.js +2 -3
- package/dist/interfaces/base-service.js.map +1 -1
- package/dist/interfaces/batch-job-strategy.d.ts +28 -0
- package/dist/interfaces/batch-job-strategy.js +75 -0
- package/dist/interfaces/batch-job-strategy.js.map +1 -0
- package/dist/interfaces/file-service.d.ts +62 -0
- package/dist/interfaces/file-service.js +32 -0
- package/dist/interfaces/file-service.js.map +1 -0
- package/dist/interfaces/index.d.ts +4 -1
- package/dist/interfaces/index.js +4 -1
- package/dist/interfaces/index.js.map +1 -1
- package/dist/interfaces/models/base-entity.d.ts +8 -0
- package/dist/interfaces/models/base-entity.js +36 -0
- package/dist/interfaces/models/base-entity.js.map +1 -0
- package/dist/interfaces/models/soft-deletable-entity.d.ts +4 -0
- package/dist/interfaces/models/soft-deletable-entity.js +43 -0
- package/dist/interfaces/models/soft-deletable-entity.js.map +1 -0
- package/dist/interfaces/transaction-base-service.d.ts +23 -0
- package/dist/interfaces/transaction-base-service.js +200 -0
- package/dist/interfaces/transaction-base-service.js.map +1 -0
- package/dist/loaders/plugins.d.ts +23 -3
- package/dist/loaders/plugins.js +28 -18
- package/dist/loaders/plugins.js.map +1 -1
- package/dist/models/address.d.ts +3 -6
- package/dist/models/address.js +23 -24
- package/dist/models/address.js.map +1 -1
- package/dist/models/batch-job.d.ts +2 -5
- package/dist/models/batch-job.js +22 -23
- package/dist/models/batch-job.js.map +1 -1
- package/dist/models/cart.d.ts +5 -8
- package/dist/models/cart.js +35 -36
- package/dist/models/cart.js.map +1 -1
- package/dist/models/claim-image.d.ts +3 -6
- package/dist/models/claim-image.js +22 -23
- package/dist/models/claim-image.js.map +1 -1
- package/dist/models/claim-item.d.ts +3 -6
- package/dist/models/claim-item.js +25 -24
- package/dist/models/claim-item.js.map +1 -1
- package/dist/models/claim-order.d.ts +4 -4
- package/dist/models/claim-order.js +28 -13
- package/dist/models/claim-order.js.map +1 -1
- package/dist/models/claim-tag.d.ts +3 -6
- package/dist/models/claim-tag.js +22 -23
- package/dist/models/claim-tag.js.map +1 -1
- package/dist/models/custom-shipping-option.d.ts +3 -6
- package/dist/models/custom-shipping-option.js +23 -24
- package/dist/models/custom-shipping-option.js.map +1 -1
- package/dist/models/customer-group.d.ts +3 -6
- package/dist/models/customer-group.js +23 -25
- package/dist/models/customer-group.js.map +1 -1
- package/dist/models/customer.d.ts +3 -6
- package/dist/models/customer.js +23 -25
- package/dist/models/customer.js.map +1 -1
- package/dist/models/discount-condition-customer-group.d.ts +1 -1
- package/dist/models/discount-condition-customer-group.js.map +1 -1
- package/dist/models/discount-condition-product-collection.d.ts +1 -1
- package/dist/models/discount-condition-product-collection.js.map +1 -1
- package/dist/models/discount-condition-product-tag.d.ts +1 -1
- package/dist/models/discount-condition-product-tag.js.map +1 -1
- package/dist/models/discount-condition-product-type.d.ts +1 -1
- package/dist/models/discount-condition-product-type.js.map +1 -1
- package/dist/models/discount-condition-product.d.ts +1 -1
- package/dist/models/discount-condition-product.js.map +1 -1
- package/dist/models/discount-condition.d.ts +3 -6
- package/dist/models/discount-condition.js +22 -21
- package/dist/models/discount-condition.js.map +1 -1
- package/dist/models/discount-rule.d.ts +3 -6
- package/dist/models/discount-rule.js +22 -21
- package/dist/models/discount-rule.js.map +1 -1
- package/dist/models/discount.d.ts +7 -10
- package/dist/models/discount.js +30 -30
- package/dist/models/discount.js.map +1 -1
- package/dist/models/draft-order.d.ts +4 -7
- package/dist/models/draft-order.js +25 -22
- package/dist/models/draft-order.js.map +1 -1
- package/dist/models/fulfillment-item.js.map +1 -1
- package/dist/models/fulfillment-provider.js.map +1 -1
- package/dist/models/fulfillment.d.ts +5 -7
- package/dist/models/fulfillment.js +29 -21
- package/dist/models/fulfillment.js.map +1 -1
- package/dist/models/gift-card-transaction.js +2 -5
- package/dist/models/gift-card-transaction.js.map +1 -1
- package/dist/models/gift-card.d.ts +3 -6
- package/dist/models/gift-card.js +22 -23
- package/dist/models/gift-card.js.map +1 -1
- package/dist/models/idempotency-key.d.ts +2 -2
- package/dist/models/idempotency-key.js +2 -3
- package/dist/models/idempotency-key.js.map +1 -1
- package/dist/models/image.d.ts +3 -6
- package/dist/models/image.js +22 -23
- package/dist/models/image.js.map +1 -1
- package/dist/models/index.d.ts +11 -10
- package/dist/models/index.js +11 -10
- package/dist/models/index.js.map +1 -1
- package/dist/models/invite.d.ts +3 -6
- package/dist/models/invite.js +22 -24
- package/dist/models/invite.js.map +1 -1
- package/dist/models/line-item-adjustment.d.ts +1 -1
- package/dist/models/line-item-adjustment.js +2 -5
- package/dist/models/line-item-adjustment.js.map +1 -1
- package/dist/models/line-item-tax-line.js +2 -5
- package/dist/models/line-item-tax-line.js.map +1 -1
- package/dist/models/line-item.d.ts +3 -5
- package/dist/models/line-item.js +25 -20
- package/dist/models/line-item.js.map +1 -1
- package/dist/models/money-amount.d.ts +2 -5
- package/dist/models/money-amount.js +22 -25
- package/dist/models/money-amount.js.map +1 -1
- package/dist/models/note.d.ts +3 -6
- package/dist/models/note.js +22 -23
- package/dist/models/note.js.map +1 -1
- package/dist/models/notification.d.ts +3 -5
- package/dist/models/notification.js +22 -19
- package/dist/models/notification.js.map +1 -1
- package/dist/models/oauth.d.ts +1 -1
- package/dist/models/oauth.js +2 -5
- package/dist/models/oauth.js.map +1 -1
- package/dist/models/order.d.ts +3 -5
- package/dist/models/order.js +25 -21
- package/dist/models/order.js.map +1 -1
- package/dist/models/payment-provider.js.map +1 -1
- package/dist/models/payment-session.d.ts +3 -5
- package/dist/models/payment-session.js +22 -19
- package/dist/models/payment-session.js.map +1 -1
- package/dist/models/payment.d.ts +4 -6
- package/dist/models/payment.js +22 -19
- package/dist/models/payment.js.map +1 -1
- package/dist/models/price-list.d.ts +4 -7
- package/dist/models/price-list.js +24 -26
- package/dist/models/price-list.js.map +1 -1
- package/dist/models/product-collection.d.ts +4 -7
- package/dist/models/product-collection.js +25 -24
- package/dist/models/product-collection.js.map +1 -1
- package/dist/models/product-option-value.d.ts +3 -6
- package/dist/models/product-option-value.js +24 -26
- package/dist/models/product-option-value.js.map +1 -1
- package/dist/models/product-option.d.ts +3 -6
- package/dist/models/product-option.js +23 -24
- package/dist/models/product-option.js.map +1 -1
- package/dist/models/product-tag.d.ts +3 -6
- package/dist/models/product-tag.js +22 -23
- package/dist/models/product-tag.js.map +1 -1
- package/dist/models/product-tax-rate.d.ts +1 -1
- package/dist/models/product-tax-rate.js.map +1 -1
- package/dist/models/product-type-tax-rate.d.ts +1 -1
- package/dist/models/product-type-tax-rate.js.map +1 -1
- package/dist/models/product-type.d.ts +3 -6
- package/dist/models/product-type.js +22 -23
- package/dist/models/product-type.js.map +1 -1
- package/dist/models/product-variant.d.ts +3 -6
- package/dist/models/product-variant.js +23 -25
- package/dist/models/product-variant.js.map +1 -1
- package/dist/models/product.d.ts +3 -6
- package/dist/models/product.js +25 -22
- package/dist/models/product.js.map +1 -1
- package/dist/models/refund.d.ts +3 -5
- package/dist/models/refund.js +22 -17
- package/dist/models/refund.js.map +1 -1
- package/dist/models/region.d.ts +3 -6
- package/dist/models/region.js +23 -24
- package/dist/models/region.js.map +1 -1
- package/dist/models/return-item.d.ts +1 -1
- package/dist/models/return-item.js.map +1 -1
- package/dist/models/return-reason.d.ts +3 -6
- package/dist/models/return-reason.js +24 -25
- package/dist/models/return-reason.js.map +1 -1
- package/dist/models/return.d.ts +5 -7
- package/dist/models/return.js +29 -21
- package/dist/models/return.js.map +1 -1
- package/dist/models/shipping-method-tax-line.js +2 -5
- package/dist/models/shipping-method-tax-line.js.map +1 -1
- package/dist/models/shipping-method.d.ts +2 -2
- package/dist/models/shipping-method.js +3 -6
- package/dist/models/shipping-method.js.map +1 -1
- package/dist/models/shipping-option-requirement.js +2 -5
- package/dist/models/shipping-option-requirement.js.map +1 -1
- package/dist/models/shipping-option.d.ts +5 -8
- package/dist/models/shipping-option.js +26 -25
- package/dist/models/shipping-option.js.map +1 -1
- package/dist/models/shipping-profile.d.ts +3 -6
- package/dist/models/shipping-profile.js +22 -23
- package/dist/models/shipping-profile.js.map +1 -1
- package/dist/models/shipping-tax-rate.d.ts +1 -1
- package/dist/models/shipping-tax-rate.js.map +1 -1
- package/dist/models/staged-job.d.ts +1 -1
- package/dist/models/staged-job.js +2 -3
- package/dist/models/staged-job.js.map +1 -1
- package/dist/models/store.d.ts +3 -5
- package/dist/models/store.js +22 -17
- package/dist/models/store.js.map +1 -1
- package/dist/models/swap.d.ts +5 -8
- package/dist/models/swap.js +32 -29
- package/dist/models/swap.js.map +1 -1
- package/dist/models/tax-line.d.ts +3 -5
- package/dist/models/tax-line.js +20 -14
- package/dist/models/tax-line.js.map +1 -1
- package/dist/models/tax-rate.d.ts +3 -5
- package/dist/models/tax-rate.js +22 -19
- package/dist/models/tax-rate.js.map +1 -1
- package/dist/models/tracking-link.d.ts +3 -6
- package/dist/models/tracking-link.js +26 -27
- package/dist/models/tracking-link.js.map +1 -1
- package/dist/models/user.d.ts +3 -6
- package/dist/models/user.js +22 -23
- package/dist/models/user.js.map +1 -1
- package/dist/repositories/batch-job.d.ts +4 -0
- package/dist/repositories/batch-job.js +38 -0
- package/dist/repositories/batch-job.js.map +1 -0
- package/dist/repositories/discount-condition.d.ts +4 -0
- package/dist/repositories/discount-condition.js +14 -0
- package/dist/repositories/discount-condition.js.map +1 -1
- package/dist/repositories/line-item-tax-line.js.map +1 -1
- package/dist/repositories/money-amount.d.ts +1 -0
- package/dist/repositories/money-amount.js +34 -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/repositories/product.d.ts +4 -2
- package/dist/repositories/product.js +61 -1
- package/dist/repositories/product.js.map +1 -1
- package/dist/repositories/shipping-method-tax-line.js.map +1 -1
- package/dist/scripts/discount-rule-migration.js +48 -36
- package/dist/scripts/discount-rule-migration.js.map +1 -1
- package/dist/services/batch-job.d.ts +24 -0
- package/dist/services/batch-job.js +126 -0
- package/dist/services/batch-job.js.map +1 -0
- package/dist/services/cart.d.ts +15 -15
- package/dist/services/cart.js +160 -165
- package/dist/services/cart.js.map +1 -1
- package/dist/services/claim-item.d.ts +23 -27
- package/dist/services/claim-item.js +217 -247
- package/dist/services/claim-item.js.map +1 -1
- package/dist/services/claim.d.ts +89 -71
- package/dist/services/claim.js +915 -840
- 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 +232 -0
- package/dist/services/discount-condition.js.map +1 -0
- package/dist/services/discount.d.ts +11 -12
- package/dist/services/discount.js +103 -216
- package/dist/services/discount.js.map +1 -1
- package/dist/services/draft-order.d.ts +69 -66
- package/dist/services/draft-order.js +375 -353
- package/dist/services/draft-order.js.map +1 -1
- package/dist/services/event-bus.d.ts +72 -56
- package/dist/services/event-bus.js +122 -99
- package/dist/services/event-bus.js.map +1 -1
- package/dist/services/file.d.ts +14 -0
- package/dist/services/file.js +43 -0
- package/dist/services/file.js.map +1 -0
- package/dist/services/line-item-adjustment.d.ts +5 -5
- package/dist/services/line-item-adjustment.js +3 -5
- package/dist/services/line-item-adjustment.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 +35 -14
- package/dist/services/price-list.js +327 -56
- package/dist/services/price-list.js.map +1 -1
- package/dist/services/pricing.d.ts +87 -0
- package/dist/services/pricing.js +443 -0
- package/dist/services/pricing.js.map +1 -0
- 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 -9
- package/dist/services/product.js +34 -58
- package/dist/services/product.js.map +1 -1
- package/dist/services/region.js +4 -4
- package/dist/services/region.js.map +1 -1
- package/dist/services/return.js +2 -0
- package/dist/services/return.js.map +1 -1
- package/dist/services/shipping-option.d.ts +43 -108
- package/dist/services/shipping-option.js +305 -352
- package/dist/services/shipping-option.js.map +1 -1
- package/dist/services/store.d.ts +36 -45
- package/dist/services/store.js +207 -217
- package/dist/services/store.js.map +1 -1
- package/dist/strategies/cart-completion.js.map +1 -1
- package/dist/types/batch-job.d.ts +9 -0
- package/dist/types/batch-job.js +53 -1
- package/dist/types/batch-job.js.map +1 -1
- package/dist/types/cart.d.ts +2 -2
- package/dist/types/claim.d.ts +67 -0
- package/dist/types/claim.js +3 -0
- package/dist/types/claim.js.map +1 -0
- package/dist/types/common.d.ts +53 -11
- package/dist/types/common.js +1 -0
- package/dist/types/common.js.map +1 -1
- package/dist/types/discount.d.ts +8 -9
- package/dist/types/global.d.ts +19 -0
- package/dist/types/note.d.ts +1 -1
- package/dist/types/price-list.d.ts +3 -0
- package/dist/types/price-list.js +5 -0
- package/dist/types/price-list.js.map +1 -1
- package/dist/types/pricing.d.ts +25 -0
- package/dist/types/pricing.js +3 -0
- package/dist/types/pricing.js.map +1 -0
- 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/types/shipping-options.d.ts +56 -0
- package/dist/types/shipping-options.js +3 -0
- package/dist/types/shipping-options.js.map +1 -0
- package/dist/types/store.d.ts +9 -0
- package/dist/types/store.js +3 -0
- package/dist/types/store.js.map +1 -0
- package/dist/types/tax-service.d.ts +2 -2
- package/dist/types/user.d.ts +2 -2
- 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/countries.d.ts +3 -2
- package/dist/utils/countries.js.map +1 -1
- package/dist/utils/currencies.d.ts +10 -1899
- package/dist/utils/currencies.js.map +1 -1
- package/dist/utils/format-registration-name.d.ts +4 -4
- package/dist/utils/format-registration-name.js +7 -10
- package/dist/utils/format-registration-name.js.map +1 -1
- package/dist/utils/generate-entity-id.d.ts +6 -0
- package/dist/utils/generate-entity-id.js +19 -0
- package/dist/utils/generate-entity-id.js.map +1 -0
- package/dist/utils/get-query-config.d.ts +4 -6
- package/dist/utils/get-query-config.js +50 -5
- package/dist/utils/get-query-config.js.map +1 -1
- package/dist/utils/index.d.ts +4 -0
- package/dist/utils/index.js +17 -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/sleep.d.ts +1 -0
- package/dist/utils/sleep.js +50 -0
- package/dist/utils/sleep.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/jest.config.js +6 -0
- package/package.json +6 -3
- package/tsconfig.spec.json +10 -0
- package/yarn-error.log +29038 -0
package/dist/services/cart.js
CHANGED
|
@@ -103,8 +103,10 @@ 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 models_1 = require("../models");
|
|
109
|
+
var utils_1 = require("../utils");
|
|
108
110
|
/* Provides layer to manipulate carts.
|
|
109
111
|
* @implements BaseService
|
|
110
112
|
*/
|
|
@@ -112,7 +114,9 @@ var CartService = /** @class */ (function (_super) {
|
|
|
112
114
|
__extends(CartService, _super);
|
|
113
115
|
function CartService(_a) {
|
|
114
116
|
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 =
|
|
117
|
+
var _this =
|
|
118
|
+
// eslint-disable-next-line prefer-rest-params
|
|
119
|
+
_super.call(this, arguments[0]) || this;
|
|
116
120
|
_this.manager_ = manager;
|
|
117
121
|
_this.shippingMethodRepository_ = shippingMethodRepository;
|
|
118
122
|
_this.cartRepository_ = cartRepository;
|
|
@@ -137,37 +141,6 @@ var CartService = /** @class */ (function (_super) {
|
|
|
137
141
|
_this.priceSelectionStrategy_ = priceSelectionStrategy;
|
|
138
142
|
return _this;
|
|
139
143
|
}
|
|
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
144
|
CartService.prototype.transformQueryForTotals_ = function (config) {
|
|
172
145
|
var select = config.select, relations = config.relations;
|
|
173
146
|
if (!select) {
|
|
@@ -303,7 +276,7 @@ var CartService = /** @class */ (function (_super) {
|
|
|
303
276
|
switch (_a.label) {
|
|
304
277
|
case 0:
|
|
305
278
|
cartRepo = transactionManager.getCustomRepository(this.cartRepository_);
|
|
306
|
-
query =
|
|
279
|
+
query = (0, utils_1.buildQuery)(selector, config);
|
|
307
280
|
return [4 /*yield*/, cartRepo.find(query)];
|
|
308
281
|
case 1: return [2 /*return*/, _a.sent()];
|
|
309
282
|
}
|
|
@@ -334,9 +307,9 @@ var CartService = /** @class */ (function (_super) {
|
|
|
334
307
|
switch (_b.label) {
|
|
335
308
|
case 0:
|
|
336
309
|
cartRepo = transactionManager.getCustomRepository(this.cartRepository_);
|
|
337
|
-
validatedId =
|
|
310
|
+
validatedId = (0, utils_1.validateId)(cartId);
|
|
338
311
|
_a = this.transformQueryForTotals_(options), select = _a.select, relations = _a.relations, totalsToSelect = _a.totalsToSelect;
|
|
339
|
-
query =
|
|
312
|
+
query = (0, utils_1.buildQuery)({ id: validatedId }, __assign(__assign({}, options), { select: select, relations: relations }));
|
|
340
313
|
if (relations && relations.length > 0) {
|
|
341
314
|
query.relations = relations;
|
|
342
315
|
}
|
|
@@ -375,10 +348,10 @@ var CartService = /** @class */ (function (_super) {
|
|
|
375
348
|
return __generator(this, function (_a) {
|
|
376
349
|
switch (_a.label) {
|
|
377
350
|
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 (
|
|
351
|
+
var cartRepo, addressRepo, region_id, rawCart, customer, region, regCountries, addr, remainingFields, remainingFields_1, remainingFields_1_1, remainingField, createdCart, cart;
|
|
352
|
+
var e_2, _a;
|
|
353
|
+
return __generator(this, function (_b) {
|
|
354
|
+
switch (_b.label) {
|
|
382
355
|
case 0:
|
|
383
356
|
cartRepo = transactionManager.getCustomRepository(this.cartRepository_);
|
|
384
357
|
addressRepo = transactionManager.getCustomRepository(this.addressRepository_);
|
|
@@ -390,56 +363,47 @@ var CartService = /** @class */ (function (_super) {
|
|
|
390
363
|
if (!data.email) return [3 /*break*/, 2];
|
|
391
364
|
return [4 /*yield*/, this.createOrFetchUserFromEmail_(data.email)];
|
|
392
365
|
case 1:
|
|
393
|
-
customer =
|
|
366
|
+
customer = _b.sent();
|
|
394
367
|
rawCart.customer = customer;
|
|
395
368
|
rawCart.customer_id = customer.id;
|
|
396
369
|
rawCart.email = customer.email;
|
|
397
|
-
|
|
370
|
+
_b.label = 2;
|
|
398
371
|
case 2: return [4 /*yield*/, this.regionService_
|
|
399
372
|
.withTransaction(transactionManager)
|
|
400
373
|
.retrieve(region_id, {
|
|
401
374
|
relations: ["countries"],
|
|
402
375
|
})];
|
|
403
376
|
case 3:
|
|
404
|
-
region =
|
|
377
|
+
region = _b.sent();
|
|
405
378
|
regCountries = region.countries.map(function (_a) {
|
|
406
379
|
var iso_2 = _a.iso_2;
|
|
407
380
|
return iso_2;
|
|
408
381
|
});
|
|
409
382
|
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
|
-
}
|
|
383
|
+
if (!(!data.shipping_address && !data.shipping_address_id)) return [3 /*break*/, 4];
|
|
384
|
+
if (region.countries.length === 1) {
|
|
385
|
+
rawCart.shipping_address = addressRepo.create({
|
|
386
|
+
country_code: regCountries[0],
|
|
387
|
+
});
|
|
436
388
|
}
|
|
437
|
-
|
|
389
|
+
return [3 /*break*/, 6];
|
|
390
|
+
case 4:
|
|
391
|
+
if (data.shipping_address) {
|
|
438
392
|
if (!regCountries.includes(data.shipping_address.country_code)) {
|
|
439
393
|
throw new medusa_core_utils_1.MedusaError(medusa_core_utils_1.MedusaError.Types.NOT_ALLOWED, "Shipping country not in region");
|
|
440
394
|
}
|
|
441
395
|
rawCart.shipping_address = data.shipping_address;
|
|
442
396
|
}
|
|
397
|
+
if (!data.shipping_address_id) return [3 /*break*/, 6];
|
|
398
|
+
return [4 /*yield*/, addressRepo.findOne(data.shipping_address_id)];
|
|
399
|
+
case 5:
|
|
400
|
+
addr = _b.sent();
|
|
401
|
+
if (addr && !regCountries.includes(addr.country_code)) {
|
|
402
|
+
throw new medusa_core_utils_1.MedusaError(medusa_core_utils_1.MedusaError.Types.NOT_ALLOWED, "Shipping country not in region");
|
|
403
|
+
}
|
|
404
|
+
rawCart.shipping_address_id = data.shipping_address_id;
|
|
405
|
+
_b.label = 6;
|
|
406
|
+
case 6:
|
|
443
407
|
remainingFields = [
|
|
444
408
|
"billing_address_id",
|
|
445
409
|
"context",
|
|
@@ -453,6 +417,9 @@ var CartService = /** @class */ (function (_super) {
|
|
|
453
417
|
remainingField = remainingFields_1_1.value;
|
|
454
418
|
if (typeof data[remainingField] !== "undefined" &&
|
|
455
419
|
remainingField !== "object") {
|
|
420
|
+
/* TODO: See how to fix the error TS2590 properly while keeping the DeepPartial type */
|
|
421
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
422
|
+
// @ts-ignore
|
|
456
423
|
rawCart[remainingField] = data[remainingField];
|
|
457
424
|
}
|
|
458
425
|
}
|
|
@@ -460,21 +427,21 @@ var CartService = /** @class */ (function (_super) {
|
|
|
460
427
|
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
461
428
|
finally {
|
|
462
429
|
try {
|
|
463
|
-
if (remainingFields_1_1 && !remainingFields_1_1.done && (
|
|
430
|
+
if (remainingFields_1_1 && !remainingFields_1_1.done && (_a = remainingFields_1.return)) _a.call(remainingFields_1);
|
|
464
431
|
}
|
|
465
432
|
finally { if (e_2) throw e_2.error; }
|
|
466
433
|
}
|
|
467
434
|
createdCart = cartRepo.create(rawCart);
|
|
468
435
|
return [4 /*yield*/, cartRepo.save(createdCart)];
|
|
469
|
-
case
|
|
470
|
-
cart =
|
|
436
|
+
case 7:
|
|
437
|
+
cart = _b.sent();
|
|
471
438
|
return [4 /*yield*/, this.eventBus_
|
|
472
439
|
.withTransaction(transactionManager)
|
|
473
440
|
.emit(CartService.Events.CREATED, {
|
|
474
441
|
id: cart.id,
|
|
475
442
|
})];
|
|
476
|
-
case
|
|
477
|
-
|
|
443
|
+
case 8:
|
|
444
|
+
_b.sent();
|
|
478
445
|
return [2 /*return*/, cart];
|
|
479
446
|
}
|
|
480
447
|
});
|
|
@@ -759,33 +726,55 @@ var CartService = /** @class */ (function (_super) {
|
|
|
759
726
|
* @return void
|
|
760
727
|
*/
|
|
761
728
|
CartService.prototype.adjustFreeShipping_ = function (cart, shouldAdd) {
|
|
762
|
-
var _a;
|
|
729
|
+
var _a, _b;
|
|
763
730
|
return __awaiter(this, void 0, void 0, function () {
|
|
764
|
-
var shippingMethodRepository_1;
|
|
731
|
+
var transactionManager, shippingMethodRepository_1;
|
|
765
732
|
var _this = this;
|
|
766
|
-
return __generator(this, function (
|
|
767
|
-
switch (
|
|
733
|
+
return __generator(this, function (_c) {
|
|
734
|
+
switch (_c.label) {
|
|
768
735
|
case 0:
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
return [
|
|
736
|
+
transactionManager = (_a = this.transactionManager_) !== null && _a !== void 0 ? _a : this.manager_;
|
|
737
|
+
if (!((_b = cart.shipping_methods) === null || _b === void 0 ? void 0 : _b.length)) return [3 /*break*/, 4];
|
|
738
|
+
shippingMethodRepository_1 = transactionManager.getCustomRepository(this.shippingMethodRepository_);
|
|
739
|
+
if (!shouldAdd) return [3 /*break*/, 2];
|
|
740
|
+
return [4 /*yield*/, shippingMethodRepository_1.update({
|
|
773
741
|
id: (0, typeorm_1.In)(cart.shipping_methods.map(function (shippingMethod) { return shippingMethod.id; })),
|
|
774
742
|
}, {
|
|
775
743
|
price: 0,
|
|
776
744
|
})];
|
|
777
|
-
case 1:
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
745
|
+
case 1:
|
|
746
|
+
_c.sent();
|
|
747
|
+
return [3 /*break*/, 4];
|
|
748
|
+
case 2: return [4 /*yield*/, Promise.all(cart.shipping_methods.map(function (shippingMethod) { return __awaiter(_this, void 0, void 0, function () {
|
|
749
|
+
var _a, _b;
|
|
750
|
+
var _c;
|
|
751
|
+
return __generator(this, function (_d) {
|
|
752
|
+
switch (_d.label) {
|
|
753
|
+
case 0:
|
|
754
|
+
// if free shipping discount is removed, we adjust the shipping
|
|
755
|
+
// back to its original amount
|
|
756
|
+
// if shipping option amount is null, we assume the option is calculated
|
|
757
|
+
_a = shippingMethod;
|
|
758
|
+
if (!((_c = shippingMethod.shipping_option.amount) !== null && _c !== void 0)) return [3 /*break*/, 1];
|
|
759
|
+
_b = _c;
|
|
760
|
+
return [3 /*break*/, 3];
|
|
761
|
+
case 1: return [4 /*yield*/, this.shippingOptionService_.getPrice_(shippingMethod.shipping_option, shippingMethod.data, cart)];
|
|
762
|
+
case 2:
|
|
763
|
+
_b = (_d.sent());
|
|
764
|
+
_d.label = 3;
|
|
765
|
+
case 3:
|
|
766
|
+
// if free shipping discount is removed, we adjust the shipping
|
|
767
|
+
// back to its original amount
|
|
768
|
+
// if shipping option amount is null, we assume the option is calculated
|
|
769
|
+
_a.price = _b;
|
|
770
|
+
return [2 /*return*/, shippingMethodRepository_1.save(shippingMethod)];
|
|
771
|
+
}
|
|
783
772
|
});
|
|
784
773
|
}); }))];
|
|
785
|
-
case
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
case
|
|
774
|
+
case 3:
|
|
775
|
+
_c.sent();
|
|
776
|
+
_c.label = 4;
|
|
777
|
+
case 4: return [2 /*return*/];
|
|
789
778
|
}
|
|
790
779
|
});
|
|
791
780
|
});
|
|
@@ -798,9 +787,9 @@ var CartService = /** @class */ (function (_super) {
|
|
|
798
787
|
case 0: return [4 /*yield*/, this.atomicPhase_(function (transactionManager) { return __awaiter(_this, void 0, void 0, function () {
|
|
799
788
|
var cartRepo, cart, customer, countryCode, addrRepo, billingAddress, shippingAddress, previousDiscounts, hasFreeShipping, prevContext, updatedCart;
|
|
800
789
|
var _this = this;
|
|
801
|
-
var _a, _b, _c, _d, _e
|
|
802
|
-
return __generator(this, function (
|
|
803
|
-
switch (
|
|
790
|
+
var _a, _b, _c, _d, _e;
|
|
791
|
+
return __generator(this, function (_f) {
|
|
792
|
+
switch (_f.label) {
|
|
804
793
|
case 0:
|
|
805
794
|
cartRepo = transactionManager.getCustomRepository(this.cartRepository_);
|
|
806
795
|
return [4 /*yield*/, this.retrieve(cartId, {
|
|
@@ -827,52 +816,52 @@ var CartService = /** @class */ (function (_super) {
|
|
|
827
816
|
],
|
|
828
817
|
})];
|
|
829
818
|
case 1:
|
|
830
|
-
cart =
|
|
819
|
+
cart = _f.sent();
|
|
831
820
|
if (!data.customer_id) return [3 /*break*/, 3];
|
|
832
821
|
return [4 /*yield*/, this.updateCustomerId_(cart, data.customer_id)];
|
|
833
822
|
case 2:
|
|
834
|
-
|
|
823
|
+
_f.sent();
|
|
835
824
|
return [3 /*break*/, 5];
|
|
836
825
|
case 3:
|
|
837
826
|
if (!(typeof data.email !== "undefined")) return [3 /*break*/, 5];
|
|
838
827
|
return [4 /*yield*/, this.createOrFetchUserFromEmail_(data.email)];
|
|
839
828
|
case 4:
|
|
840
|
-
customer =
|
|
829
|
+
customer = _f.sent();
|
|
841
830
|
cart.customer = customer;
|
|
842
831
|
cart.customer_id = customer.id;
|
|
843
832
|
cart.email = customer.email;
|
|
844
|
-
|
|
833
|
+
_f.label = 5;
|
|
845
834
|
case 5:
|
|
846
835
|
if (!(typeof data.region_id !== "undefined")) return [3 /*break*/, 7];
|
|
847
836
|
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
837
|
return [4 /*yield*/, this.setRegion_(cart, data.region_id, countryCode)];
|
|
849
838
|
case 6:
|
|
850
|
-
|
|
851
|
-
|
|
839
|
+
_f.sent();
|
|
840
|
+
_f.label = 7;
|
|
852
841
|
case 7:
|
|
853
842
|
if (!(typeof data.customer_id !== "undefined" ||
|
|
854
843
|
typeof data.region_id !== "undefined")) return [3 /*break*/, 9];
|
|
855
844
|
return [4 /*yield*/, this.updateUnitPrices_(cart, data.region_id, data.customer_id)];
|
|
856
845
|
case 8:
|
|
857
|
-
|
|
858
|
-
|
|
846
|
+
_f.sent();
|
|
847
|
+
_f.label = 9;
|
|
859
848
|
case 9:
|
|
860
849
|
addrRepo = transactionManager.getCustomRepository(this.addressRepository_);
|
|
861
850
|
billingAddress = (_c = data.billing_address_id) !== null && _c !== void 0 ? _c : data.billing_address;
|
|
862
851
|
if (!(billingAddress !== undefined)) return [3 /*break*/, 11];
|
|
863
852
|
return [4 /*yield*/, this.updateBillingAddress_(cart, billingAddress, addrRepo)];
|
|
864
853
|
case 10:
|
|
865
|
-
|
|
866
|
-
|
|
854
|
+
_f.sent();
|
|
855
|
+
_f.label = 11;
|
|
867
856
|
case 11:
|
|
868
857
|
shippingAddress = (_d = data.shipping_address_id) !== null && _d !== void 0 ? _d : data.shipping_address;
|
|
869
858
|
if (!(shippingAddress !== undefined)) return [3 /*break*/, 13];
|
|
870
859
|
return [4 /*yield*/, this.updateShippingAddress_(cart, shippingAddress, addrRepo)];
|
|
871
860
|
case 12:
|
|
872
|
-
|
|
873
|
-
|
|
861
|
+
_f.sent();
|
|
862
|
+
_f.label = 13;
|
|
874
863
|
case 13:
|
|
875
|
-
if (!(
|
|
864
|
+
if (!(typeof data.discounts !== "undefined")) return [3 /*break*/, 18];
|
|
876
865
|
previousDiscounts = __spreadArray([], __read(cart.discounts), false);
|
|
877
866
|
cart.discounts.length = 0;
|
|
878
867
|
return [4 /*yield*/, Promise.all(data.discounts.map(function (_a) {
|
|
@@ -880,39 +869,39 @@ var CartService = /** @class */ (function (_super) {
|
|
|
880
869
|
return _this.applyDiscount(cart, code);
|
|
881
870
|
}))];
|
|
882
871
|
case 14:
|
|
883
|
-
|
|
872
|
+
_f.sent();
|
|
884
873
|
hasFreeShipping = cart.discounts.some(function (_a) {
|
|
885
874
|
var rule = _a.rule;
|
|
886
875
|
return (rule === null || rule === void 0 ? void 0 : rule.type) === "free_shipping";
|
|
887
876
|
});
|
|
888
877
|
if (!(previousDiscounts.some(function (_a) {
|
|
889
878
|
var rule = _a.rule;
|
|
890
|
-
return
|
|
879
|
+
return rule.type === "free_shipping";
|
|
891
880
|
}) &&
|
|
892
881
|
!hasFreeShipping)) return [3 /*break*/, 16];
|
|
893
882
|
return [4 /*yield*/, this.adjustFreeShipping_(cart, false)];
|
|
894
883
|
case 15:
|
|
895
|
-
|
|
896
|
-
|
|
884
|
+
_f.sent();
|
|
885
|
+
_f.label = 16;
|
|
897
886
|
case 16:
|
|
898
887
|
if (!hasFreeShipping) return [3 /*break*/, 18];
|
|
899
888
|
return [4 /*yield*/, this.adjustFreeShipping_(cart, true)];
|
|
900
889
|
case 17:
|
|
901
|
-
|
|
902
|
-
|
|
890
|
+
_f.sent();
|
|
891
|
+
_f.label = 18;
|
|
903
892
|
case 18:
|
|
904
893
|
if (!("gift_cards" in data)) return [3 /*break*/, 20];
|
|
905
894
|
cart.gift_cards = [];
|
|
906
|
-
return [4 /*yield*/, Promise.all(((
|
|
895
|
+
return [4 /*yield*/, Promise.all(((_e = data.gift_cards) !== null && _e !== void 0 ? _e : []).map(function (_a) {
|
|
907
896
|
var code = _a.code;
|
|
908
897
|
return _this.applyGiftCard_(cart, code);
|
|
909
898
|
}))];
|
|
910
899
|
case 19:
|
|
911
|
-
|
|
912
|
-
|
|
900
|
+
_f.sent();
|
|
901
|
+
_f.label = 20;
|
|
913
902
|
case 20:
|
|
914
|
-
if (
|
|
915
|
-
cart.metadata =
|
|
903
|
+
if (data === null || data === void 0 ? void 0 : data.metadata) {
|
|
904
|
+
cart.metadata = (0, utils_1.setMetadata)(cart, data.metadata);
|
|
916
905
|
}
|
|
917
906
|
if ("context" in data) {
|
|
918
907
|
prevContext = cart.context || {};
|
|
@@ -926,19 +915,19 @@ var CartService = /** @class */ (function (_super) {
|
|
|
926
915
|
}
|
|
927
916
|
return [4 /*yield*/, cartRepo.save(cart)];
|
|
928
917
|
case 21:
|
|
929
|
-
updatedCart =
|
|
918
|
+
updatedCart = _f.sent();
|
|
930
919
|
if (!("email" in data || "customer_id" in data)) return [3 /*break*/, 23];
|
|
931
920
|
return [4 /*yield*/, this.eventBus_
|
|
932
921
|
.withTransaction(transactionManager)
|
|
933
922
|
.emit(CartService.Events.CUSTOMER_UPDATED, updatedCart.id)];
|
|
934
923
|
case 22:
|
|
935
|
-
|
|
936
|
-
|
|
924
|
+
_f.sent();
|
|
925
|
+
_f.label = 23;
|
|
937
926
|
case 23: return [4 /*yield*/, this.eventBus_
|
|
938
927
|
.withTransaction(transactionManager)
|
|
939
928
|
.emit(CartService.Events.UPDATED, updatedCart)];
|
|
940
929
|
case 24:
|
|
941
|
-
|
|
930
|
+
_f.sent();
|
|
942
931
|
return [2 /*return*/, updatedCart];
|
|
943
932
|
}
|
|
944
933
|
});
|
|
@@ -1168,7 +1157,7 @@ var CartService = /** @class */ (function (_super) {
|
|
|
1168
1157
|
switch (_a.label) {
|
|
1169
1158
|
case 0: return [4 /*yield*/, this.discountService_
|
|
1170
1159
|
.withTransaction(transactionManager)
|
|
1171
|
-
.retrieveByCode(discountCode, ["rule", "regions"])];
|
|
1160
|
+
.retrieveByCode(discountCode, { relations: ["rule", "regions"] })];
|
|
1172
1161
|
case 1:
|
|
1173
1162
|
discount = _a.sent();
|
|
1174
1163
|
return [4 /*yield*/, this.discountService_
|
|
@@ -1189,7 +1178,7 @@ var CartService = /** @class */ (function (_super) {
|
|
|
1189
1178
|
newDiscounts = toParse.map(function (discountToParse) {
|
|
1190
1179
|
var _a;
|
|
1191
1180
|
switch ((_a = discountToParse.rule) === null || _a === void 0 ? void 0 : _a.type) {
|
|
1192
|
-
case
|
|
1181
|
+
case models_1.DiscountRuleType.FREE_SHIPPING:
|
|
1193
1182
|
if (discountToParse.rule.type === rule.type) {
|
|
1194
1183
|
return discount;
|
|
1195
1184
|
}
|
|
@@ -1373,7 +1362,7 @@ var CartService = /** @class */ (function (_super) {
|
|
|
1373
1362
|
session = _b.sent();
|
|
1374
1363
|
return [4 /*yield*/, this.retrieve(cart.id, {
|
|
1375
1364
|
select: ["total"],
|
|
1376
|
-
relations: ["payment_sessions"],
|
|
1365
|
+
relations: ["payment_sessions", "items", "items.adjustments"],
|
|
1377
1366
|
})];
|
|
1378
1367
|
case 3:
|
|
1379
1368
|
freshCart = _b.sent();
|
|
@@ -1510,6 +1499,7 @@ var CartService = /** @class */ (function (_super) {
|
|
|
1510
1499
|
],
|
|
1511
1500
|
relations: [
|
|
1512
1501
|
"items",
|
|
1502
|
+
"items.adjustments",
|
|
1513
1503
|
"discounts",
|
|
1514
1504
|
"discounts.rule",
|
|
1515
1505
|
"gift_cards",
|
|
@@ -1847,28 +1837,29 @@ var CartService = /** @class */ (function (_super) {
|
|
|
1847
1837
|
return customOption;
|
|
1848
1838
|
};
|
|
1849
1839
|
CartService.prototype.updateUnitPrices_ = function (cart, regionId, customer_id) {
|
|
1850
|
-
var _a;
|
|
1840
|
+
var _a, _b;
|
|
1851
1841
|
return __awaiter(this, void 0, void 0, function () {
|
|
1852
|
-
var region_1,
|
|
1842
|
+
var transactionManager, region_1, _c;
|
|
1853
1843
|
var _this = this;
|
|
1854
|
-
return __generator(this, function (
|
|
1855
|
-
switch (
|
|
1844
|
+
return __generator(this, function (_d) {
|
|
1845
|
+
switch (_d.label) {
|
|
1856
1846
|
case 0:
|
|
1857
|
-
|
|
1847
|
+
transactionManager = (_a = this.transactionManager_) !== null && _a !== void 0 ? _a : this.manager_;
|
|
1848
|
+
if (!((_b = cart.items) === null || _b === void 0 ? void 0 : _b.length)) return [3 /*break*/, 3];
|
|
1858
1849
|
return [4 /*yield*/, this.regionService_
|
|
1859
1850
|
.withTransaction(this.transactionManager_)
|
|
1860
1851
|
.retrieve(regionId || cart.region_id, {
|
|
1861
1852
|
relations: ["countries"],
|
|
1862
1853
|
})];
|
|
1863
1854
|
case 1:
|
|
1864
|
-
region_1 =
|
|
1865
|
-
|
|
1855
|
+
region_1 = _d.sent();
|
|
1856
|
+
_c = cart;
|
|
1866
1857
|
return [4 /*yield*/, Promise.all(cart.items.map(function (item) { return __awaiter(_this, void 0, void 0, function () {
|
|
1867
1858
|
var availablePrice;
|
|
1868
1859
|
return __generator(this, function (_a) {
|
|
1869
1860
|
switch (_a.label) {
|
|
1870
1861
|
case 0: return [4 /*yield*/, this.priceSelectionStrategy_
|
|
1871
|
-
.withTransaction(
|
|
1862
|
+
.withTransaction(transactionManager)
|
|
1872
1863
|
.calculateVariantPrice(item.variant_id, {
|
|
1873
1864
|
region_id: region_1.id,
|
|
1874
1865
|
currency_code: region_1.currency_code,
|
|
@@ -1882,13 +1873,13 @@ var CartService = /** @class */ (function (_super) {
|
|
|
1882
1873
|
if (!(availablePrice !== undefined &&
|
|
1883
1874
|
availablePrice.calculatedPrice !== null)) return [3 /*break*/, 2];
|
|
1884
1875
|
return [2 /*return*/, this.lineItemService_
|
|
1885
|
-
.withTransaction(
|
|
1876
|
+
.withTransaction(transactionManager)
|
|
1886
1877
|
.update(item.id, {
|
|
1887
1878
|
has_shipping: false,
|
|
1888
1879
|
unit_price: availablePrice.calculatedPrice,
|
|
1889
1880
|
})];
|
|
1890
1881
|
case 2: return [4 /*yield*/, this.lineItemService_
|
|
1891
|
-
.withTransaction(
|
|
1882
|
+
.withTransaction(transactionManager)
|
|
1892
1883
|
.delete(item.id)];
|
|
1893
1884
|
case 3:
|
|
1894
1885
|
_a.sent();
|
|
@@ -1897,8 +1888,8 @@ var CartService = /** @class */ (function (_super) {
|
|
|
1897
1888
|
});
|
|
1898
1889
|
}); }))];
|
|
1899
1890
|
case 2:
|
|
1900
|
-
|
|
1901
|
-
|
|
1891
|
+
_c.items = (_d.sent()).filter(function (item) { return !!item; });
|
|
1892
|
+
_d.label = 3;
|
|
1902
1893
|
case 3: return [2 /*return*/];
|
|
1903
1894
|
}
|
|
1904
1895
|
});
|
|
@@ -1912,11 +1903,13 @@ var CartService = /** @class */ (function (_super) {
|
|
|
1912
1903
|
* @return the result of the update operation
|
|
1913
1904
|
*/
|
|
1914
1905
|
CartService.prototype.setRegion_ = function (cart, regionId, countryCode) {
|
|
1906
|
+
var _a;
|
|
1915
1907
|
return __awaiter(this, void 0, void 0, function () {
|
|
1916
|
-
var region, addrRepo, shippingAddress, updated, updated, paymentSessionRepo;
|
|
1917
|
-
return __generator(this, function (
|
|
1918
|
-
switch (
|
|
1908
|
+
var transactionManager, region, addrRepo, shippingAddress, updated, updated, paymentSessionRepo;
|
|
1909
|
+
return __generator(this, function (_b) {
|
|
1910
|
+
switch (_b.label) {
|
|
1919
1911
|
case 0:
|
|
1912
|
+
transactionManager = (_a = this.transactionManager_) !== null && _a !== void 0 ? _a : this.manager_;
|
|
1920
1913
|
if (cart.completed_at || cart.payment_authorized_at) {
|
|
1921
1914
|
throw new medusa_core_utils_1.MedusaError(medusa_core_utils_1.MedusaError.Types.NOT_ALLOWED, "Cannot change the region of a completed cart");
|
|
1922
1915
|
}
|
|
@@ -1926,8 +1919,8 @@ var CartService = /** @class */ (function (_super) {
|
|
|
1926
1919
|
relations: ["countries"],
|
|
1927
1920
|
})];
|
|
1928
1921
|
case 1:
|
|
1929
|
-
region =
|
|
1930
|
-
addrRepo =
|
|
1922
|
+
region = _b.sent();
|
|
1923
|
+
addrRepo = transactionManager.getCustomRepository(this.addressRepository_);
|
|
1931
1924
|
cart.region = region;
|
|
1932
1925
|
cart.region_id = region.id;
|
|
1933
1926
|
shippingAddress = {};
|
|
@@ -1936,8 +1929,8 @@ var CartService = /** @class */ (function (_super) {
|
|
|
1936
1929
|
where: { id: cart.shipping_address_id },
|
|
1937
1930
|
})];
|
|
1938
1931
|
case 2:
|
|
1939
|
-
shippingAddress = (
|
|
1940
|
-
|
|
1932
|
+
shippingAddress = (_b.sent());
|
|
1933
|
+
_b.label = 3;
|
|
1941
1934
|
case 3:
|
|
1942
1935
|
if (!(countryCode !== null)) return [3 /*break*/, 5];
|
|
1943
1936
|
if (!region.countries.find(function (_a) {
|
|
@@ -1949,7 +1942,7 @@ var CartService = /** @class */ (function (_super) {
|
|
|
1949
1942
|
updated = __assign(__assign({}, shippingAddress), { country_code: countryCode.toLowerCase() });
|
|
1950
1943
|
return [4 /*yield*/, addrRepo.save(updated)];
|
|
1951
1944
|
case 4:
|
|
1952
|
-
|
|
1945
|
+
_b.sent();
|
|
1953
1946
|
return [3 /*break*/, 7];
|
|
1954
1947
|
case 5:
|
|
1955
1948
|
updated = __assign({}, shippingAddress);
|
|
@@ -1963,16 +1956,16 @@ var CartService = /** @class */ (function (_super) {
|
|
|
1963
1956
|
}
|
|
1964
1957
|
return [4 /*yield*/, this.updateShippingAddress_(cart, updated, addrRepo)];
|
|
1965
1958
|
case 6:
|
|
1966
|
-
|
|
1967
|
-
|
|
1959
|
+
_b.sent();
|
|
1960
|
+
_b.label = 7;
|
|
1968
1961
|
case 7:
|
|
1969
1962
|
if (!(cart.shipping_methods && cart.shipping_methods.length)) return [3 /*break*/, 9];
|
|
1970
1963
|
return [4 /*yield*/, this.shippingOptionService_
|
|
1971
|
-
.withTransaction(
|
|
1964
|
+
.withTransaction(transactionManager)
|
|
1972
1965
|
.deleteShippingMethods(cart.shipping_methods)];
|
|
1973
1966
|
case 8:
|
|
1974
|
-
|
|
1975
|
-
|
|
1967
|
+
_b.sent();
|
|
1968
|
+
_b.label = 9;
|
|
1976
1969
|
case 9:
|
|
1977
1970
|
if (cart.discounts && cart.discounts.length) {
|
|
1978
1971
|
cart.discounts = cart.discounts.filter(function (discount) {
|
|
@@ -1984,15 +1977,15 @@ var CartService = /** @class */ (function (_super) {
|
|
|
1984
1977
|
}
|
|
1985
1978
|
cart.gift_cards = [];
|
|
1986
1979
|
if (!(cart.payment_sessions && cart.payment_sessions.length)) return [3 /*break*/, 11];
|
|
1987
|
-
paymentSessionRepo =
|
|
1980
|
+
paymentSessionRepo = transactionManager.getCustomRepository(this.paymentSessionRepository_);
|
|
1988
1981
|
return [4 /*yield*/, paymentSessionRepo.delete({
|
|
1989
1982
|
id: (0, typeorm_1.In)(cart.payment_sessions.map(function (paymentSession) { return paymentSession.id; })),
|
|
1990
1983
|
})];
|
|
1991
1984
|
case 10:
|
|
1992
|
-
|
|
1985
|
+
_b.sent();
|
|
1993
1986
|
cart.payment_sessions.length = 0;
|
|
1994
1987
|
cart.payment_session = null;
|
|
1995
|
-
|
|
1988
|
+
_b.label = 11;
|
|
1996
1989
|
case 11: return [2 /*return*/];
|
|
1997
1990
|
}
|
|
1998
1991
|
});
|
|
@@ -2059,7 +2052,7 @@ var CartService = /** @class */ (function (_super) {
|
|
|
2059
2052
|
switch (_b.label) {
|
|
2060
2053
|
case 0:
|
|
2061
2054
|
cartRepo = transactionManager.getCustomRepository(this.cartRepository_);
|
|
2062
|
-
validatedId =
|
|
2055
|
+
validatedId = (0, utils_1.validateId)(cartId);
|
|
2063
2056
|
if (typeof key !== "string") {
|
|
2064
2057
|
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
2058
|
}
|
|
@@ -2126,17 +2119,19 @@ var CartService = /** @class */ (function (_super) {
|
|
|
2126
2119
|
});
|
|
2127
2120
|
};
|
|
2128
2121
|
CartService.prototype.refreshAdjustments_ = function (cart) {
|
|
2122
|
+
var _a;
|
|
2129
2123
|
return __awaiter(this, void 0, void 0, function () {
|
|
2130
|
-
var nonReturnLineIDs;
|
|
2131
|
-
return __generator(this, function (
|
|
2132
|
-
switch (
|
|
2124
|
+
var transactionManager, nonReturnLineIDs;
|
|
2125
|
+
return __generator(this, function (_b) {
|
|
2126
|
+
switch (_b.label) {
|
|
2133
2127
|
case 0:
|
|
2128
|
+
transactionManager = (_a = this.transactionManager_) !== null && _a !== void 0 ? _a : this.manager_;
|
|
2134
2129
|
nonReturnLineIDs = cart.items
|
|
2135
2130
|
.filter(function (item) { return !item.is_return; })
|
|
2136
2131
|
.map(function (i) { return i.id; });
|
|
2137
2132
|
// delete all old non return line item adjustments
|
|
2138
2133
|
return [4 /*yield*/, this.lineItemAdjustmentService_
|
|
2139
|
-
.withTransaction(
|
|
2134
|
+
.withTransaction(transactionManager)
|
|
2140
2135
|
.delete({
|
|
2141
2136
|
item_id: nonReturnLineIDs,
|
|
2142
2137
|
})
|
|
@@ -2144,14 +2139,14 @@ var CartService = /** @class */ (function (_super) {
|
|
|
2144
2139
|
];
|
|
2145
2140
|
case 1:
|
|
2146
2141
|
// delete all old non return line item adjustments
|
|
2147
|
-
|
|
2142
|
+
_b.sent();
|
|
2148
2143
|
// potentially create/update line item adjustments
|
|
2149
2144
|
return [4 /*yield*/, this.lineItemAdjustmentService_
|
|
2150
|
-
.withTransaction(
|
|
2145
|
+
.withTransaction(transactionManager)
|
|
2151
2146
|
.createAdjustments(cart)];
|
|
2152
2147
|
case 2:
|
|
2153
2148
|
// potentially create/update line item adjustments
|
|
2154
|
-
|
|
2149
|
+
_b.sent();
|
|
2155
2150
|
return [2 /*return*/];
|
|
2156
2151
|
}
|
|
2157
2152
|
});
|
|
@@ -2174,7 +2169,7 @@ var CartService = /** @class */ (function (_super) {
|
|
|
2174
2169
|
switch (_a.label) {
|
|
2175
2170
|
case 0:
|
|
2176
2171
|
cartRepo = transactionManager.getCustomRepository(this.cartRepository_);
|
|
2177
|
-
validatedId =
|
|
2172
|
+
validatedId = (0, utils_1.validateId)(cartId);
|
|
2178
2173
|
if (typeof key !== "string") {
|
|
2179
2174
|
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
2175
|
}
|
|
@@ -2208,6 +2203,6 @@ var CartService = /** @class */ (function (_super) {
|
|
|
2208
2203
|
UPDATED: "cart.updated",
|
|
2209
2204
|
};
|
|
2210
2205
|
return CartService;
|
|
2211
|
-
}(
|
|
2206
|
+
}(interfaces_1.TransactionBaseService));
|
|
2212
2207
|
exports.default = CartService;
|
|
2213
2208
|
//# sourceMappingURL=cart.js.map
|