@medusajs/medusa 1.2.2-dev.56 → 1.3.1-alpha.72
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 +98 -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/batch-job/can-access-batch-job.d.ts +1 -0
- package/dist/api/{routes/admin/discounts/add-valid-product.js → middlewares/batch-job/can-access-batch-job.js} +31 -43
- 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/{routes/admin/products/get-variants.js → middlewares/batch-job/get-requested-batch-job.js} +28 -37
- package/dist/api/middlewares/batch-job/get-requested-batch-job.js.map +1 -0
- package/dist/api/middlewares/error-handler.js +1 -1
- package/dist/api/middlewares/index.d.ts +2 -0
- package/dist/api/middlewares/index.js +5 -0
- package/dist/api/middlewares/index.js.map +1 -1
- package/dist/api/routes/admin/auth/create-session.js +5 -5
- package/dist/api/routes/admin/auth/create-session.js.map +1 -1
- package/dist/api/routes/admin/batch/index.d.ts +13 -0
- package/dist/api/routes/admin/batch/index.js +37 -0
- package/dist/api/routes/admin/batch/index.js.map +1 -0
- package/dist/api/routes/admin/batch/list-batch-jobs.d.ts +47 -0
- package/dist/api/routes/admin/batch/list-batch-jobs.js +245 -0
- package/dist/api/routes/admin/batch/list-batch-jobs.js.map +1 -0
- package/dist/api/routes/admin/customer-groups/list-customer-groups.js +2 -2
- package/dist/api/routes/admin/customer-groups/list-customer-groups.js.map +1 -1
- 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 +14 -4
- package/dist/api/routes/admin/discounts/create-discount.js +72 -16
- package/dist/api/routes/admin/discounts/create-discount.js.map +1 -1
- package/dist/api/routes/admin/discounts/create-dynamic-code.d.ts +1 -0
- package/dist/api/routes/admin/discounts/create-dynamic-code.js +4 -1
- package/dist/api/routes/admin/discounts/create-dynamic-code.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/delete-dynamic-code.js +3 -1
- package/dist/api/routes/admin/discounts/delete-dynamic-code.js.map +1 -1
- package/dist/api/routes/admin/discounts/get-condition.d.ts +31 -0
- package/dist/api/routes/{store/carts/update-payment-method.js → admin/discounts/get-condition.js} +48 -45
- 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/get-discount.d.ts +7 -0
- package/dist/api/routes/admin/discounts/get-discount.js +43 -9
- package/dist/api/routes/admin/discounts/get-discount.js.map +1 -1
- package/dist/api/routes/admin/discounts/index.d.ts +11 -3
- package/dist/api/routes/admin/discounts/index.js +13 -7
- package/dist/api/routes/admin/discounts/index.js.map +1 -1
- package/dist/api/routes/admin/discounts/list-discounts.d.ts +2 -6
- package/dist/api/routes/admin/discounts/list-discounts.js +15 -28
- package/dist/api/routes/admin/discounts/list-discounts.js.map +1 -1
- package/dist/api/routes/admin/discounts/update-condition.d.ts +55 -0
- package/dist/api/routes/admin/discounts/update-condition.js +184 -0
- package/dist/api/routes/admin/discounts/update-condition.js.map +1 -0
- package/dist/api/routes/admin/discounts/update-discount.d.ts +18 -12
- package/dist/api/routes/admin/discounts/update-discount.js +79 -33
- package/dist/api/routes/admin/discounts/update-discount.js.map +1 -1
- package/dist/api/routes/admin/draft-orders/create-draft-order.d.ts +3 -3
- package/dist/api/routes/admin/draft-orders/create-draft-order.js.map +1 -1
- package/dist/api/routes/admin/draft-orders/create-line-item.d.ts +1 -1
- package/dist/api/routes/admin/draft-orders/create-line-item.js.map +1 -1
- package/dist/api/routes/admin/draft-orders/index.js +7 -1
- package/dist/api/routes/admin/draft-orders/index.js.map +1 -1
- package/dist/api/routes/admin/draft-orders/register-payment.js +0 -1
- package/dist/api/routes/admin/draft-orders/register-payment.js.map +1 -1
- package/dist/api/routes/admin/draft-orders/update-line-item.d.ts +1 -1
- package/dist/api/routes/admin/draft-orders/update-line-item.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/notifications/index.js.map +1 -1
- package/dist/api/routes/admin/notifications/list-notifications.js.map +1 -1
- package/dist/api/routes/admin/notifications/resend-notification.js.map +1 -1
- package/dist/api/routes/admin/orders/add-shipping-method.d.ts +1 -1
- package/dist/api/routes/admin/orders/add-shipping-method.js.map +1 -1
- package/dist/api/routes/admin/orders/create-claim.js +6 -0
- package/dist/api/routes/admin/orders/create-claim.js.map +1 -1
- package/dist/api/routes/admin/orders/create-order.js.map +1 -1
- package/dist/api/routes/admin/orders/create-swap.js +7 -3
- package/dist/api/routes/admin/orders/create-swap.js.map +1 -1
- package/dist/api/routes/admin/orders/index.d.ts +1 -1
- package/dist/api/routes/admin/orders/index.js +1 -3
- package/dist/api/routes/admin/orders/index.js.map +1 -1
- package/dist/api/routes/admin/orders/list-orders.js.map +1 -1
- package/dist/api/routes/admin/orders/update-order.js.map +1 -1
- package/dist/api/routes/admin/price-lists/delete-product-prices.d.ts +32 -0
- package/dist/api/routes/admin/{discounts/remove-valid-product.js → price-lists/delete-product-prices.js} +48 -25
- 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 +9 -0
- package/dist/api/routes/admin/price-lists/index.js +6 -1
- 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 +74 -0
- package/dist/api/routes/admin/price-lists/list-price-list-products.js +287 -0
- package/dist/api/routes/admin/price-lists/list-price-list-products.js.map +1 -0
- 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 +4 -4
- 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-products.d.ts +2 -1
- package/dist/api/routes/admin/products/list-products.js +31 -65
- package/dist/api/routes/admin/products/list-products.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/products/update-variant.js +11 -7
- package/dist/api/routes/admin/products/update-variant.js.map +1 -1
- package/dist/api/routes/admin/regions/index.d.ts +1 -1
- 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.map +1 -1
- package/dist/api/routes/admin/swaps/index.js +3 -0
- package/dist/api/routes/admin/swaps/index.js.map +1 -1
- package/dist/api/routes/admin/tax-rates/list-tax-rates.js.map +1 -1
- package/dist/api/routes/admin/tax-rates/utils/get-query-config.d.ts +1 -1
- package/dist/api/routes/admin/tax-rates/utils/get-query-config.js +4 -2
- package/dist/api/routes/admin/tax-rates/utils/get-query-config.js.map +1 -1
- package/dist/api/routes/admin/uploads/index.d.ts +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/auth/create-session.js +4 -5
- package/dist/api/routes/store/auth/create-session.js.map +1 -1
- package/dist/api/routes/store/carts/create-cart.js +8 -5
- package/dist/api/routes/store/carts/create-cart.js.map +1 -1
- package/dist/api/routes/store/carts/create-line-item.d.ts +1 -1
- package/dist/api/routes/store/carts/create-line-item.js +9 -6
- package/dist/api/routes/store/carts/create-line-item.js.map +1 -1
- package/dist/api/routes/store/carts/index.d.ts +0 -1
- package/dist/api/routes/store/carts/index.js +1 -3
- package/dist/api/routes/store/carts/index.js.map +1 -1
- package/dist/api/routes/store/carts/update-cart.js +8 -8
- package/dist/api/routes/store/carts/update-cart.js.map +1 -1
- package/dist/api/routes/store/customers/create-customer.js +3 -4
- package/dist/api/routes/store/customers/create-customer.js.map +1 -1
- package/dist/api/routes/store/orders/index.js +0 -2
- package/dist/api/routes/store/orders/index.js.map +1 -1
- package/dist/api/routes/store/products/get-product.js +17 -5
- package/dist/api/routes/store/products/get-product.js.map +1 -1
- package/dist/api/routes/store/products/index.d.ts +2 -2
- package/dist/api/routes/store/products/list-products.d.ts +2 -1
- package/dist/api/routes/store/products/list-products.js +21 -8
- package/dist/api/routes/store/products/list-products.js.map +1 -1
- package/dist/api/routes/store/products/search.d.ts +1 -1
- package/dist/api/routes/store/products/search.js.map +1 -1
- package/dist/api/routes/store/shipping-options/list-options.js.map +1 -1
- package/dist/api/routes/store/swaps/create-swap.js +7 -3
- package/dist/api/routes/store/swaps/create-swap.js.map +1 -1
- package/dist/api/routes/store/variants/get-variant.js +17 -5
- package/dist/api/routes/store/variants/get-variant.js.map +1 -1
- package/dist/api/routes/store/variants/list-variants.d.ts +2 -1
- package/dist/api/routes/store/variants/list-variants.js +38 -9
- package/dist/api/routes/store/variants/list-variants.js.map +1 -1
- package/dist/commands/develop.js +2 -2
- package/dist/commands/develop.js.map +1 -1
- package/dist/commands/start.js +6 -0
- package/dist/commands/start.js.map +1 -1
- package/dist/controllers/customers/index.d.ts +1 -1
- package/dist/controllers/customers/list-customers.d.ts +1 -1
- package/dist/controllers/customers/list-customers.js +34 -37
- package/dist/controllers/customers/list-customers.js.map +1 -1
- package/dist/controllers/products/admin-list-products.d.ts +16 -0
- package/dist/controllers/products/admin-list-products.js +103 -0
- package/dist/controllers/products/admin-list-products.js.map +1 -0
- package/dist/helpers/test-request.js +26 -17
- package/dist/helpers/test-request.js.map +1 -1
- package/dist/index.d.ts +4 -59
- package/dist/index.js +4 -62
- package/dist/index.js.map +1 -1
- package/dist/interfaces/index.d.ts +3 -0
- package/dist/interfaces/index.js +3 -0
- 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/price-selection-strategy.d.ts +50 -0
- package/dist/interfaces/price-selection-strategy.js +34 -0
- package/dist/interfaces/price-selection-strategy.js.map +1 -0
- package/dist/interfaces/tax-service.d.ts +6 -0
- package/dist/interfaces/tax-service.js +31 -0
- package/dist/interfaces/tax-service.js.map +1 -1
- 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/api.d.ts +9 -5
- package/dist/loaders/api.js +2 -6
- package/dist/loaders/api.js.map +1 -1
- package/dist/loaders/config.d.ts +3 -0
- package/dist/loaders/config.js +47 -0
- package/dist/loaders/config.js.map +1 -0
- package/dist/loaders/database.d.ts +8 -4
- package/dist/loaders/database.js.map +1 -1
- package/dist/loaders/defaults.d.ts +4 -3
- package/dist/loaders/defaults.js +39 -31
- package/dist/loaders/defaults.js.map +1 -1
- package/dist/loaders/express.d.ts +7 -4
- package/dist/loaders/express.js +7 -5
- package/dist/loaders/express.js.map +1 -1
- package/dist/loaders/index.d.ts +13 -8
- package/dist/loaders/index.js +29 -54
- package/dist/loaders/index.js.map +1 -1
- package/dist/loaders/logger.d.ts +1 -0
- package/dist/loaders/logger.js.map +1 -1
- package/dist/loaders/models.d.ts +8 -3
- package/dist/loaders/models.js +19 -17
- package/dist/loaders/models.js.map +1 -1
- package/dist/loaders/passport.d.ts +7 -4
- package/dist/loaders/passport.js +23 -21
- package/dist/loaders/passport.js.map +1 -1
- package/dist/loaders/plugins.d.ts +38 -10
- package/dist/loaders/plugins.js +30 -26
- package/dist/loaders/plugins.js.map +1 -1
- package/dist/loaders/redis.d.ts +8 -5
- package/dist/loaders/redis.js +3 -3
- package/dist/loaders/redis.js.map +1 -1
- package/dist/loaders/repositories.d.ts +7 -3
- package/dist/loaders/repositories.js +1 -1
- package/dist/loaders/repositories.js.map +1 -1
- package/dist/loaders/search-index.d.ts +4 -3
- package/dist/loaders/search-index.js.map +1 -1
- package/dist/loaders/services.d.ts +10 -5
- package/dist/loaders/services.js.map +1 -1
- package/dist/loaders/strategies.d.ts +1 -1
- package/dist/loaders/subscribers.d.ts +7 -3
- package/dist/loaders/subscribers.js.map +1 -1
- package/dist/migrations/1646324713514-discount_conditions.d.ts +6 -0
- package/dist/migrations/1646324713514-discount_conditions.js +335 -0
- package/dist/migrations/1646324713514-discount_conditions.js.map +1 -0
- package/dist/migrations/1648600574750-add_line_item_adjustments.d.ts +6 -0
- package/dist/migrations/1648600574750-add_line_item_adjustments.js +101 -0
- package/dist/migrations/1648600574750-add_line_item_adjustments.js.map +1 -0
- package/dist/migrations/1648641130007-tax_line_constraints.d.ts +6 -0
- package/dist/migrations/1648641130007-tax_line_constraints.js +77 -0
- package/dist/migrations/1648641130007-tax_line_constraints.js.map +1 -0
- package/dist/migrations/1649775522087-add_batch_job_model.d.ts +6 -0
- package/dist/migrations/1649775522087-add_batch_job_model.js +77 -0
- package/dist/migrations/1649775522087-add_batch_job_model.js.map +1 -0
- 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 +55 -0
- package/dist/models/batch-job.js +118 -0
- package/dist/models/batch-job.js.map +1 -0
- 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/country.d.ts +1 -1
- package/dist/models/country.js +1 -1
- package/dist/models/country.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 +26 -26
- 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 +39 -0
- package/dist/models/discount-condition-customer-group.js +84 -0
- package/dist/models/discount-condition-customer-group.js.map +1 -0
- package/dist/models/discount-condition-product-collection.d.ts +39 -0
- package/dist/models/discount-condition-product-collection.js +84 -0
- package/dist/models/discount-condition-product-collection.js.map +1 -0
- package/dist/models/discount-condition-product-tag.d.ts +39 -0
- package/dist/models/discount-condition-product-tag.js +84 -0
- package/dist/models/discount-condition-product-tag.js.map +1 -0
- package/dist/models/discount-condition-product-type.d.ts +39 -0
- package/dist/models/discount-condition-product-type.js +84 -0
- package/dist/models/discount-condition-product-type.js.map +1 -0
- package/dist/models/discount-condition-product.d.ts +39 -0
- package/dist/models/discount-condition-product.js +84 -0
- package/dist/models/discount-condition-product.js.map +1 -0
- package/dist/models/discount-condition.d.ts +65 -0
- package/dist/models/discount-condition.js +209 -0
- package/dist/models/discount-condition.js.map +1 -0
- package/dist/models/discount-rule.d.ts +8 -11
- package/dist/models/discount-rule.js +28 -38
- 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 +3 -5
- package/dist/models/draft-order.js +23 -20
- 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 +67 -0
- package/dist/models/index.js +80 -0
- package/dist/models/index.js.map +1 -0
- 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 +13 -0
- package/dist/models/line-item-adjustment.js +76 -0
- package/dist/models/line-item-adjustment.js.map +1 -0
- package/dist/models/line-item-tax-line.js +4 -6
- package/dist/models/line-item-tax-line.js.map +1 -1
- package/dist/models/line-item.d.ts +5 -5
- package/dist/models/line-item.js +29 -19
- package/dist/models/line-item.js.map +1 -1
- package/dist/models/money-amount.d.ts +2 -5
- package/dist/models/money-amount.js +26 -26
- 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 +30 -28
- 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 +30 -26
- 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 +4 -6
- package/dist/models/shipping-method-tax-line.js.map +1 -1
- package/dist/models/shipping-method.d.ts +1 -1
- package/dist/models/shipping-method.js +2 -5
- 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 +4 -7
- package/dist/models/shipping-option.js +25 -24
- 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 +9 -12
- package/dist/models/swap.js +55 -52
- 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/cart.d.ts +2 -2
- package/dist/repositories/cart.js.map +1 -1
- package/dist/repositories/customer.d.ts +1 -1
- package/dist/repositories/customer.js +7 -9
- package/dist/repositories/customer.js.map +1 -1
- package/dist/repositories/discount-condition.d.ts +38 -0
- package/dist/repositories/discount-condition.js +398 -0
- package/dist/repositories/discount-condition.js.map +1 -0
- package/dist/repositories/line-item-adjustment.d.ts +4 -0
- package/dist/repositories/line-item-adjustment.js +38 -0
- package/dist/repositories/line-item-adjustment.js.map +1 -0
- package/dist/repositories/line-item-tax-line.d.ts +2 -0
- package/dist/repositories/line-item-tax-line.js +80 -0
- package/dist/repositories/line-item-tax-line.js.map +1 -1
- package/dist/repositories/line-item.js +1 -0
- package/dist/repositories/line-item.js.map +1 -1
- package/dist/repositories/money-amount.d.ts +2 -0
- package/dist/repositories/money-amount.js +77 -2
- 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 +2 -0
- package/dist/repositories/product.js +35 -17
- package/dist/repositories/product.js.map +1 -1
- package/dist/repositories/shipping-method-tax-line.d.ts +2 -0
- package/dist/repositories/shipping-method-tax-line.js +80 -0
- package/dist/repositories/shipping-method-tax-line.js.map +1 -1
- package/dist/scripts/discount-rule-migration.d.ts +4 -0
- package/dist/scripts/discount-rule-migration.js +189 -0
- package/dist/scripts/discount-rule-migration.js.map +1 -0
- package/dist/scripts/line-item-adjustment-migration.d.ts +4 -0
- package/dist/scripts/line-item-adjustment-migration.js +173 -0
- package/dist/scripts/line-item-adjustment-migration.js.map +1 -0
- 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 +66 -55
- package/dist/services/cart.js +1301 -1410
- package/dist/services/cart.js.map +1 -1
- package/dist/services/claim.js +62 -19
- package/dist/services/claim.js.map +1 -1
- package/dist/services/customer.d.ts +0 -7
- package/dist/services/customer.js +8 -35
- 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 +50 -59
- package/dist/services/discount.js +272 -174
- package/dist/services/discount.js.map +1 -1
- package/dist/services/draft-order.js +1 -0
- package/dist/services/draft-order.js.map +1 -1
- package/dist/services/fulfillment-provider.js +23 -17
- package/dist/services/fulfillment-provider.js.map +1 -1
- package/dist/services/invite.d.ts +4 -2
- package/dist/services/invite.js +11 -9
- package/dist/services/invite.js.map +1 -1
- package/dist/services/line-item-adjustment.d.ts +87 -0
- package/dist/services/line-item-adjustment.js +434 -0
- package/dist/services/line-item-adjustment.js.map +1 -0
- package/dist/services/line-item.d.ts +48 -40
- package/dist/services/line-item.js +226 -193
- package/dist/services/line-item.js.map +1 -1
- package/dist/services/order.d.ts +0 -13
- package/dist/services/order.js +4 -30
- package/dist/services/order.js.map +1 -1
- package/dist/services/payment-provider.js +23 -17
- package/dist/services/payment-provider.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/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.d.ts +26 -9
- package/dist/services/product-variant.js +223 -77
- package/dist/services/product-variant.js.map +1 -1
- package/dist/services/product.d.ts +24 -5
- package/dist/services/product.js +247 -52
- package/dist/services/product.js.map +1 -1
- package/dist/services/region.js +8 -4
- package/dist/services/region.js.map +1 -1
- package/dist/services/return.js +2 -1
- package/dist/services/return.js.map +1 -1
- package/dist/services/shipping-option.d.ts +2 -2
- package/dist/services/shipping-option.js +7 -4
- package/dist/services/shipping-option.js.map +1 -1
- package/dist/services/swap.d.ts +4 -1
- package/dist/services/swap.js +29 -16
- package/dist/services/swap.js.map +1 -1
- package/dist/services/system-tax.d.ts +2 -3
- package/dist/services/system-tax.js +2 -2
- package/dist/services/system-tax.js.map +1 -1
- package/dist/services/tax-provider.d.ts +2 -0
- package/dist/services/tax-provider.js +96 -7
- package/dist/services/tax-provider.js.map +1 -1
- package/dist/services/tax-rate.d.ts +3 -3
- package/dist/services/tax-rate.js +1 -1
- package/dist/services/tax-rate.js.map +1 -1
- package/dist/services/totals.d.ts +9 -8
- package/dist/services/totals.js +41 -88
- package/dist/services/totals.js.map +1 -1
- package/dist/strategies/cart-completion.js.map +1 -1
- package/dist/strategies/price-selection.d.ts +13 -0
- package/dist/strategies/price-selection.js +185 -0
- package/dist/strategies/price-selection.js.map +1 -0
- package/dist/subscribers/order.js +1 -7
- package/dist/subscribers/order.js.map +1 -1
- package/dist/types/batch-job.d.ts +15 -0
- package/dist/types/batch-job.js +63 -0
- package/dist/types/batch-job.js.map +1 -0
- package/dist/types/cart.d.ts +2 -2
- package/dist/types/common.d.ts +32 -13
- package/dist/types/common.js +1 -0
- package/dist/types/common.js.map +1 -1
- package/dist/types/discount.d.ts +68 -1
- package/dist/types/discount.js +129 -5
- package/dist/types/discount.js.map +1 -1
- package/dist/types/global.d.ts +43 -0
- package/dist/types/global.js +3 -0
- package/dist/types/global.js.map +1 -0
- package/dist/types/line-item-adjustment.d.ts +9 -0
- package/dist/types/line-item-adjustment.js +50 -0
- package/dist/types/line-item-adjustment.js.map +1 -0
- package/dist/types/note.d.ts +1 -1
- package/dist/types/price-list.d.ts +1 -0
- package/dist/types/price-list.js +5 -0
- package/dist/types/price-list.js.map +1 -1
- package/dist/types/price-selection.d.ts +5 -0
- package/dist/types/price-selection.js +35 -0
- package/dist/types/price-selection.js.map +1 -0
- package/dist/types/product-variant.d.ts +6 -0
- package/dist/types/product-variant.js.map +1 -1
- package/dist/types/product.d.ts +18 -0
- package/dist/types/product.js +104 -5
- package/dist/types/product.js.map +1 -1
- package/dist/types/tax-service.d.ts +2 -2
- package/dist/types/user.d.ts +2 -2
- package/dist/types/validators/exactly-one.d.ts +6 -0
- package/dist/types/validators/exactly-one.js +37 -0
- package/dist/types/validators/exactly-one.js.map +1 -0
- 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/date-helpers.d.ts +2 -0
- package/dist/utils/date-helpers.js +15 -0
- package/dist/utils/date-helpers.js.map +1 -0
- 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 +11 -0
- package/dist/utils/get-query-config.js +88 -0
- package/dist/utils/get-query-config.js.map +1 -0
- 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/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 +10 -9
- package/tsconfig.spec.json +10 -0
- package/dist/api/routes/admin/discounts/add-valid-product.d.ts +0 -23
- package/dist/api/routes/admin/discounts/add-valid-product.js.map +0 -1
- package/dist/api/routes/admin/discounts/remove-valid-product.d.ts +0 -23
- package/dist/api/routes/admin/discounts/remove-valid-product.js.map +0 -1
- package/dist/api/routes/admin/products/get-variants.d.ts +0 -24
- package/dist/api/routes/admin/products/get-variants.js.map +0 -1
- package/dist/api/routes/store/carts/update-payment-method.d.ts +0 -38
- package/dist/api/routes/store/carts/update-payment-method.js.map +0 -1
- package/dist/config/index.d.ts +0 -14
- package/dist/config/index.js +0 -40
- package/dist/config/index.js.map +0 -1
- package/yarn-error.log +0 -6769
|
@@ -53,6 +53,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
53
53
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
54
54
|
var medusa_core_utils_1 = require("medusa-core-utils");
|
|
55
55
|
var medusa_interfaces_1 = require("medusa-interfaces");
|
|
56
|
+
var typeorm_1 = require("typeorm");
|
|
56
57
|
/**
|
|
57
58
|
* Provides layer to manipulate products.
|
|
58
59
|
* @extends BaseService
|
|
@@ -138,12 +139,24 @@ var ProductTypeService = /** @class */ (function (_super) {
|
|
|
138
139
|
if (selector === void 0) { selector = {}; }
|
|
139
140
|
if (config === void 0) { config = { skip: 0, take: 20 }; }
|
|
140
141
|
return __awaiter(this, void 0, void 0, function () {
|
|
141
|
-
var typeRepo, query;
|
|
142
|
+
var typeRepo, q, query, where_1;
|
|
142
143
|
return __generator(this, function (_a) {
|
|
143
144
|
switch (_a.label) {
|
|
144
145
|
case 0:
|
|
145
146
|
typeRepo = this.manager_.getCustomRepository(this.typeRepository_);
|
|
147
|
+
q = undefined;
|
|
148
|
+
if ("q" in selector) {
|
|
149
|
+
q = selector.q;
|
|
150
|
+
delete selector.q;
|
|
151
|
+
}
|
|
146
152
|
query = this.buildQuery_(selector, config);
|
|
153
|
+
if (q) {
|
|
154
|
+
where_1 = query.where;
|
|
155
|
+
delete where_1.value;
|
|
156
|
+
query.where = function (qb) {
|
|
157
|
+
qb.where(where_1).andWhere([{ value: (0, typeorm_1.ILike)("%".concat(q, "%")) }]);
|
|
158
|
+
};
|
|
159
|
+
}
|
|
147
160
|
return [4 /*yield*/, typeRepo.findAndCount(query)];
|
|
148
161
|
case 1: return [2 /*return*/, _a.sent()];
|
|
149
162
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"product-type.js","sourceRoot":"","sources":["../../src/services/product-type.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,uDAA+C;AAC/C,uDAA+C;
|
|
1
|
+
{"version":3,"file":"product-type.js","sourceRoot":"","sources":["../../src/services/product-type.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,uDAA+C;AAC/C,uDAA+C;AAC/C,mCAAkE;AAMlE;;;GAGG;AACH;IAAiC,sCAAW;IAG1C,4BAAY,EAAkC;YAAhC,OAAO,aAAA,EAAE,qBAAqB,2BAAA;QAA5C,YACE,iBAAO,SAIR;QAFC,KAAI,CAAC,QAAQ,GAAG,OAAO,CAAA;QACvB,KAAI,CAAC,eAAe,GAAG,qBAAqB,CAAA;;IAC9C,CAAC;IAED,4CAAe,GAAf,UAAgB,kBAAiC;QAC/C,IAAI,CAAC,kBAAkB,EAAE;YACvB,OAAO,IAAI,CAAA;SACZ;QAED,IAAM,MAAM,GAAG,IAAI,kBAAkB,CAAC;YACpC,OAAO,EAAE,kBAAkB;YAC3B,qBAAqB,EAAE,IAAI,CAAC,eAAe;SAC5C,CAAC,CAAA;QAEF,MAAM,CAAC,mBAAmB,GAAG,kBAAkB,CAAA;QAC/C,MAAM,CAAC,QAAQ,GAAG,kBAAkB,CAAA;QAEpC,OAAO,MAAM,CAAA;IACf,CAAC;IAED;;;;;;;OAOG;IACG,qCAAQ,GAAd,UACE,EAAU,EACV,MAAoC;QAApC,uBAAA,EAAA,WAAoC;;;;;;wBAE9B,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC,mBAAmB,CAAC,IAAI,CAAC,eAAe,CAAC,CAAA;wBAElE,KAAK,GAAG,IAAI,CAAC,WAAW,CAAC,EAAE,EAAE,IAAA,EAAE,EAAE,MAAM,CAAC,CAAA;wBACjC,qBAAM,QAAQ,CAAC,OAAO,CAAC,KAAK,CAAC,EAAA;;wBAApC,IAAI,GAAG,SAA6B;wBAE1C,IAAI,CAAC,IAAI,EAAE;4BACT,MAAM,IAAI,+BAAW,CACnB,+BAAW,CAAC,KAAK,CAAC,SAAS,EAC3B,2BAAoB,EAAE,mBAAgB,CACvC,CAAA;yBACF;wBAED,sBAAO,IAAI,EAAA;;;;KACZ;IAED;;;;;OAKG;IACG,iCAAI,GAAV,UACE,QAAyC,EACzC,MAAuD;QADvD,yBAAA,EAAA,aAAyC;QACzC,uBAAA,EAAA,WAAoC,IAAI,EAAE,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE;;;;;;wBAEjD,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC,mBAAmB,CAAC,IAAI,CAAC,eAAe,CAAC,CAAA;wBAElE,KAAK,GAAG,IAAI,CAAC,WAAW,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAA;wBACzC,qBAAM,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,EAAA;4BAAjC,sBAAO,SAA0B,EAAA;;;;KAClC;IAED;;;;;OAKG;IACG,yCAAY,GAAlB,UACE,QAAyC,EACzC,MAAuD;QADvD,yBAAA,EAAA,aAAyC;QACzC,uBAAA,EAAA,WAAoC,IAAI,EAAE,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE;;;;;;wBAEjD,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC,mBAAmB,CAAC,IAAI,CAAC,eAAe,CAAC,CAAA;wBAEpE,CAAC,GAAuB,SAAS,CAAA;wBACrC,IAAI,GAAG,IAAI,QAAQ,EAAE;4BACnB,CAAC,GAAG,QAAQ,CAAC,CAAC,CAAA;4BACd,OAAO,QAAQ,CAAC,CAAC,CAAA;yBAClB;wBAEK,KAAK,GAAG,IAAI,CAAC,WAAW,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAA;wBAEhD,IAAI,CAAC,EAAE;4BACC,UAAQ,KAAK,CAAC,KAAK,CAAA;4BAEzB,OAAO,OAAK,CAAC,KAAK,CAAA;4BAElB,KAAK,CAAC,KAAK,GAAG,UAAC,EAAmC;gCAChD,EAAE,CAAC,KAAK,CAAC,OAAK,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,KAAK,EAAE,IAAA,eAAK,EAAC,WAAI,CAAC,MAAG,CAAC,EAAE,CAAC,CAAC,CAAA;4BACxD,CAAC,CAAA;yBACF;wBAEM,qBAAM,QAAQ,CAAC,YAAY,CAAC,KAAK,CAAC,EAAA;4BAAzC,sBAAO,SAAkC,EAAA;;;;KAC1C;IACH,yBAAC;AAAD,CAAC,AArGD,CAAiC,+BAAW,GAqG3C;AAED,kBAAe,kBAAkB,CAAA"}
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { BaseService } from "medusa-interfaces";
|
|
2
2
|
import { EntityManager, SelectQueryBuilder } from "typeorm";
|
|
3
|
-
import {
|
|
3
|
+
import { PriceSelectionContext } from "../interfaces/price-selection-strategy";
|
|
4
|
+
import { MoneyAmount } from "../models/money-amount";
|
|
4
5
|
import { Product } from "../models/product";
|
|
5
6
|
import { ProductOptionValue } from "../models/product-option-value";
|
|
6
7
|
import { ProductVariant } from "../models/product-variant";
|
|
7
8
|
import { FindWithRelationsOptions, ProductVariantRepository } from "../repositories/product-variant";
|
|
8
9
|
import { FindConfig } from "../types/common";
|
|
9
|
-
import { CreateProductVariantInput, FilterableProductVariantProps, ProductVariantPrice, UpdateProductVariantInput } from "../types/product-variant";
|
|
10
|
+
import { CreateProductVariantInput, FilterableProductVariantProps, GetRegionPriceContext, ProductVariantPrice, UpdateProductVariantInput } from "../types/product-variant";
|
|
10
11
|
/**
|
|
11
12
|
* Provides layer to manipulate product variants.
|
|
12
13
|
* @extends BaseService
|
|
@@ -22,9 +23,11 @@ declare class ProductVariantService extends BaseService {
|
|
|
22
23
|
private productRepository_;
|
|
23
24
|
private eventBus_;
|
|
24
25
|
private regionService_;
|
|
26
|
+
private priceSelectionStrategy_;
|
|
25
27
|
private moneyAmountRepository_;
|
|
26
28
|
private productOptionValueRepository_;
|
|
27
|
-
|
|
29
|
+
private cartRepository_;
|
|
30
|
+
constructor({ manager, productVariantRepository, productRepository, eventBusService, regionService, moneyAmountRepository, productOptionValueRepository, cartRepository, priceSelectionStrategy, }: {
|
|
28
31
|
manager: any;
|
|
29
32
|
productVariantRepository: any;
|
|
30
33
|
productRepository: any;
|
|
@@ -32,6 +35,8 @@ declare class ProductVariantService extends BaseService {
|
|
|
32
35
|
regionService: any;
|
|
33
36
|
moneyAmountRepository: any;
|
|
34
37
|
productOptionValueRepository: any;
|
|
38
|
+
cartRepository: any;
|
|
39
|
+
priceSelectionStrategy: any;
|
|
35
40
|
});
|
|
36
41
|
withTransaction(transactionManager: EntityManager): ProductVariantService;
|
|
37
42
|
/**
|
|
@@ -40,14 +45,14 @@ declare class ProductVariantService extends BaseService {
|
|
|
40
45
|
* @param {FindConfig<ProductVariant>} config - query config object for variant retrieval.
|
|
41
46
|
* @return {Promise<Product>} the product document.
|
|
42
47
|
*/
|
|
43
|
-
retrieve(variantId: string, config?: FindConfig<ProductVariant>): Promise<ProductVariant>;
|
|
48
|
+
retrieve(variantId: string, config?: FindConfig<ProductVariant> & PriceSelectionContext): Promise<ProductVariant>;
|
|
44
49
|
/**
|
|
45
50
|
* Gets a product variant by id.
|
|
46
51
|
* @param {string} sku - The unique stock keeping unit used to identify the product variant.
|
|
47
52
|
* @param {FindConfig<ProductVariant>} config - query config object for variant retrieval.
|
|
48
53
|
* @return {Promise<Product>} the product document.
|
|
49
54
|
*/
|
|
50
|
-
retrieveBySKU(sku: string, config?: FindConfig<ProductVariant>): Promise<ProductVariant>;
|
|
55
|
+
retrieveBySKU(sku: string, config?: FindConfig<ProductVariant> & PriceSelectionContext): Promise<ProductVariant>;
|
|
51
56
|
/**
|
|
52
57
|
* Creates an unpublished product variant. Will validate against parent product
|
|
53
58
|
* to ensure that the variant can in fact be created.
|
|
@@ -62,6 +67,7 @@ declare class ProductVariantService extends BaseService {
|
|
|
62
67
|
* The function will throw, if price updates are attempted.
|
|
63
68
|
* @param {string | ProductVariant} variantOrVariantId - variant or id of a variant.
|
|
64
69
|
* @param {object} update - an object with the update values.
|
|
70
|
+
* @param {object} config - an object with the config values for returning the variant.
|
|
65
71
|
* @return {Promise} resolves to the update result.
|
|
66
72
|
*/
|
|
67
73
|
update(variantOrVariantId: string | Partial<ProductVariant>, update: UpdateProductVariantInput): Promise<ProductVariant>;
|
|
@@ -78,10 +84,10 @@ declare class ProductVariantService extends BaseService {
|
|
|
78
84
|
* exists the function will try to use a currency price. If no default
|
|
79
85
|
* currency price exists the function will throw an error.
|
|
80
86
|
* @param {string} variantId - the id of the variant to get price from
|
|
81
|
-
* @param {
|
|
87
|
+
* @param {GetRegionPriceContext} context - context for getting region price
|
|
82
88
|
* @return {number} the price specific to the region
|
|
83
89
|
*/
|
|
84
|
-
getRegionPrice(variantId: string,
|
|
90
|
+
getRegionPrice(variantId: string, context: GetRegionPriceContext): Promise<number>;
|
|
85
91
|
/**
|
|
86
92
|
* Sets the default price of a specific region
|
|
87
93
|
* @param {string} variantId - the id of the variant to update
|
|
@@ -130,13 +136,13 @@ declare class ProductVariantService extends BaseService {
|
|
|
130
136
|
* @param {FindConfig<ProductVariant>} config - query config object for variant retrieval
|
|
131
137
|
* @return {Promise} the result of the find operation
|
|
132
138
|
*/
|
|
133
|
-
listAndCount(selector: FilterableProductVariantProps, config?: FindConfig<ProductVariant>): Promise<[ProductVariant[], number]>;
|
|
139
|
+
listAndCount(selector: FilterableProductVariantProps, config?: FindConfig<ProductVariant> & PriceSelectionContext): Promise<[ProductVariant[], number]>;
|
|
134
140
|
/**
|
|
135
141
|
* @param {FilterableProductVariantProps} selector - the query object for find
|
|
136
142
|
* @param {FindConfig<ProductVariant>} config - query config object for variant retrieval
|
|
137
143
|
* @return {Promise} the result of the find operation
|
|
138
144
|
*/
|
|
139
|
-
list(selector: FilterableProductVariantProps, config?: FindConfig<ProductVariant>): Promise<ProductVariant[]>;
|
|
145
|
+
list(selector: FilterableProductVariantProps, config?: FindConfig<ProductVariant> & PriceSelectionContext): Promise<ProductVariant[]>;
|
|
140
146
|
/**
|
|
141
147
|
* Deletes variant.
|
|
142
148
|
* Will never fail due to delete being idempotent.
|
|
@@ -174,5 +180,16 @@ declare class ProductVariantService extends BaseService {
|
|
|
174
180
|
* count of products that matches the query as the second element.
|
|
175
181
|
*/
|
|
176
182
|
getFreeTextQueryBuilder_(variantRepo: ProductVariantRepository, query: FindWithRelationsOptions, q?: string): SelectQueryBuilder<ProductVariant>;
|
|
183
|
+
/**
|
|
184
|
+
* Set additional prices on a list of variants.
|
|
185
|
+
* @param {ProductVariant | ProductVariant[] } variant variant on which to set additional prices
|
|
186
|
+
* @param {string} currency_code currency code to fetch prices for
|
|
187
|
+
* @param {string} region_id region to fetch prices for
|
|
188
|
+
* @param {string} cart_id string of cart to use as a basis for getting currency and region
|
|
189
|
+
* @param {string} customer_id id of potentially logged in customer, used to get prices valid for their customer groups
|
|
190
|
+
* @param {boolean} include_discount_prices should result include discount pricing
|
|
191
|
+
* @return {Promise<ProductVariant | ProductVariant[]>} A list of variants with variants decorated with "additional_prices"
|
|
192
|
+
*/
|
|
193
|
+
setAdditionalPrices(variant: any, currency_code: any, region_id: any, cart_id: any, customer_id: any, include_discount_prices?: boolean): Promise<ProductVariant | ProductVariant[]>;
|
|
177
194
|
}
|
|
178
195
|
export default ProductVariantService;
|
|
@@ -72,17 +72,6 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
72
72
|
}
|
|
73
73
|
return t;
|
|
74
74
|
};
|
|
75
|
-
var __values = (this && this.__values) || function(o) {
|
|
76
|
-
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
77
|
-
if (m) return m.call(o);
|
|
78
|
-
if (o && typeof o.length === "number") return {
|
|
79
|
-
next: function () {
|
|
80
|
-
if (o && i >= o.length) o = void 0;
|
|
81
|
-
return { value: o && o[i++], done: !o };
|
|
82
|
-
}
|
|
83
|
-
};
|
|
84
|
-
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
85
|
-
};
|
|
86
75
|
var __read = (this && this.__read) || function (o, n) {
|
|
87
76
|
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
88
77
|
if (!m) return o;
|
|
@@ -99,6 +88,26 @@ var __read = (this && this.__read) || function (o, n) {
|
|
|
99
88
|
}
|
|
100
89
|
return ar;
|
|
101
90
|
};
|
|
91
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
92
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
93
|
+
if (ar || !(i in from)) {
|
|
94
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
95
|
+
ar[i] = from[i];
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
99
|
+
};
|
|
100
|
+
var __values = (this && this.__values) || function(o) {
|
|
101
|
+
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
102
|
+
if (m) return m.call(o);
|
|
103
|
+
if (o && typeof o.length === "number") return {
|
|
104
|
+
next: function () {
|
|
105
|
+
if (o && i >= o.length) o = void 0;
|
|
106
|
+
return { value: o && o[i++], done: !o };
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
110
|
+
};
|
|
102
111
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
103
112
|
var medusa_core_utils_1 = require("medusa-core-utils");
|
|
104
113
|
var medusa_interfaces_1 = require("medusa-interfaces");
|
|
@@ -110,7 +119,7 @@ var typeorm_1 = require("typeorm");
|
|
|
110
119
|
var ProductVariantService = /** @class */ (function (_super) {
|
|
111
120
|
__extends(ProductVariantService, _super);
|
|
112
121
|
function ProductVariantService(_a) {
|
|
113
|
-
var manager = _a.manager, productVariantRepository = _a.productVariantRepository, productRepository = _a.productRepository, eventBusService = _a.eventBusService, regionService = _a.regionService, moneyAmountRepository = _a.moneyAmountRepository, productOptionValueRepository = _a.productOptionValueRepository;
|
|
122
|
+
var manager = _a.manager, productVariantRepository = _a.productVariantRepository, productRepository = _a.productRepository, eventBusService = _a.eventBusService, regionService = _a.regionService, moneyAmountRepository = _a.moneyAmountRepository, productOptionValueRepository = _a.productOptionValueRepository, cartRepository = _a.cartRepository, priceSelectionStrategy = _a.priceSelectionStrategy;
|
|
114
123
|
var _this = _super.call(this) || this;
|
|
115
124
|
/** @private @const {EntityManager} */
|
|
116
125
|
_this.manager_ = manager;
|
|
@@ -124,6 +133,8 @@ var ProductVariantService = /** @class */ (function (_super) {
|
|
|
124
133
|
_this.regionService_ = regionService;
|
|
125
134
|
_this.moneyAmountRepository_ = moneyAmountRepository;
|
|
126
135
|
_this.productOptionValueRepository_ = productOptionValueRepository;
|
|
136
|
+
_this.cartRepository_ = cartRepository;
|
|
137
|
+
_this.priceSelectionStrategy_ = priceSelectionStrategy;
|
|
127
138
|
return _this;
|
|
128
139
|
}
|
|
129
140
|
ProductVariantService.prototype.withTransaction = function (transactionManager) {
|
|
@@ -138,6 +149,8 @@ var ProductVariantService = /** @class */ (function (_super) {
|
|
|
138
149
|
regionService: this.regionService_,
|
|
139
150
|
moneyAmountRepository: this.moneyAmountRepository_,
|
|
140
151
|
productOptionValueRepository: this.productOptionValueRepository_,
|
|
152
|
+
cartRepository: this.cartRepository_,
|
|
153
|
+
priceSelectionStrategy: this.priceSelectionStrategy_,
|
|
141
154
|
});
|
|
142
155
|
cloned.transactionManager_ = transactionManager;
|
|
143
156
|
return cloned;
|
|
@@ -149,22 +162,38 @@ var ProductVariantService = /** @class */ (function (_super) {
|
|
|
149
162
|
* @return {Promise<Product>} the product document.
|
|
150
163
|
*/
|
|
151
164
|
ProductVariantService.prototype.retrieve = function (variantId, config) {
|
|
152
|
-
|
|
165
|
+
var _a, _b;
|
|
166
|
+
if (config === void 0) { config = {
|
|
167
|
+
include_discount_prices: false,
|
|
168
|
+
}; }
|
|
153
169
|
return __awaiter(this, void 0, void 0, function () {
|
|
154
|
-
var variantRepo, validatedId, query, variant;
|
|
155
|
-
return __generator(this, function (
|
|
156
|
-
switch (
|
|
170
|
+
var variantRepo, validatedId, priceIndex, query, variant, _c;
|
|
171
|
+
return __generator(this, function (_d) {
|
|
172
|
+
switch (_d.label) {
|
|
157
173
|
case 0:
|
|
158
174
|
variantRepo = this.manager_.getCustomRepository(this.productVariantRepository_);
|
|
159
175
|
validatedId = this.validateId_(variantId);
|
|
176
|
+
priceIndex = (_b = (_a = config.relations) === null || _a === void 0 ? void 0 : _a.indexOf("prices")) !== null && _b !== void 0 ? _b : -1;
|
|
177
|
+
if (priceIndex >= 0 && config.relations) {
|
|
178
|
+
config.relations = __spreadArray([], __read(config.relations), false);
|
|
179
|
+
config.relations.splice(priceIndex, 1);
|
|
180
|
+
}
|
|
160
181
|
query = this.buildQuery_({ id: validatedId }, config);
|
|
161
182
|
return [4 /*yield*/, variantRepo.findOne(query)];
|
|
162
183
|
case 1:
|
|
163
|
-
variant =
|
|
184
|
+
variant = _d.sent();
|
|
164
185
|
if (!variant) {
|
|
165
186
|
throw new medusa_core_utils_1.MedusaError(medusa_core_utils_1.MedusaError.Types.NOT_FOUND, "Variant with id: ".concat(variantId, " was not found"));
|
|
166
187
|
}
|
|
167
|
-
return [
|
|
188
|
+
if (!(priceIndex >= 0)) return [3 /*break*/, 3];
|
|
189
|
+
return [4 /*yield*/, this.setAdditionalPrices(variant, config.currency_code, config.region_id, config.cart_id, config.customer_id, config.include_discount_prices)];
|
|
190
|
+
case 2:
|
|
191
|
+
_c = (_d.sent());
|
|
192
|
+
return [3 /*break*/, 4];
|
|
193
|
+
case 3:
|
|
194
|
+
_c = variant;
|
|
195
|
+
_d.label = 4;
|
|
196
|
+
case 4: return [2 /*return*/, _c];
|
|
168
197
|
}
|
|
169
198
|
});
|
|
170
199
|
});
|
|
@@ -176,21 +205,37 @@ var ProductVariantService = /** @class */ (function (_super) {
|
|
|
176
205
|
* @return {Promise<Product>} the product document.
|
|
177
206
|
*/
|
|
178
207
|
ProductVariantService.prototype.retrieveBySKU = function (sku, config) {
|
|
179
|
-
|
|
208
|
+
var _a, _b;
|
|
209
|
+
if (config === void 0) { config = {
|
|
210
|
+
include_discount_prices: false,
|
|
211
|
+
}; }
|
|
180
212
|
return __awaiter(this, void 0, void 0, function () {
|
|
181
|
-
var variantRepo, query, variant;
|
|
182
|
-
return __generator(this, function (
|
|
183
|
-
switch (
|
|
213
|
+
var variantRepo, priceIndex, query, variant, _c;
|
|
214
|
+
return __generator(this, function (_d) {
|
|
215
|
+
switch (_d.label) {
|
|
184
216
|
case 0:
|
|
185
217
|
variantRepo = this.manager_.getCustomRepository(this.productVariantRepository_);
|
|
218
|
+
priceIndex = (_b = (_a = config.relations) === null || _a === void 0 ? void 0 : _a.indexOf("prices")) !== null && _b !== void 0 ? _b : -1;
|
|
219
|
+
if (priceIndex >= 0 && config.relations) {
|
|
220
|
+
config.relations = __spreadArray([], __read(config.relations), false);
|
|
221
|
+
config.relations.splice(priceIndex, 1);
|
|
222
|
+
}
|
|
186
223
|
query = this.buildQuery_({ sku: sku }, config);
|
|
187
224
|
return [4 /*yield*/, variantRepo.findOne(query)];
|
|
188
225
|
case 1:
|
|
189
|
-
variant =
|
|
226
|
+
variant = _d.sent();
|
|
190
227
|
if (!variant) {
|
|
191
228
|
throw new medusa_core_utils_1.MedusaError(medusa_core_utils_1.MedusaError.Types.NOT_FOUND, "Variant with sku: ".concat(sku, " was not found"));
|
|
192
229
|
}
|
|
193
|
-
return [
|
|
230
|
+
if (!(priceIndex >= 0)) return [3 /*break*/, 3];
|
|
231
|
+
return [4 /*yield*/, this.setAdditionalPrices(variant, config.currency_code, config.region_id, config.cart_id, config.customer_id, config.include_discount_prices)];
|
|
232
|
+
case 2:
|
|
233
|
+
_c = (_d.sent());
|
|
234
|
+
return [3 /*break*/, 4];
|
|
235
|
+
case 3:
|
|
236
|
+
_c = variant;
|
|
237
|
+
_d.label = 4;
|
|
238
|
+
case 4: return [2 /*return*/, _c];
|
|
194
239
|
}
|
|
195
240
|
});
|
|
196
241
|
});
|
|
@@ -311,6 +356,7 @@ var ProductVariantService = /** @class */ (function (_super) {
|
|
|
311
356
|
* The function will throw, if price updates are attempted.
|
|
312
357
|
* @param {string | ProductVariant} variantOrVariantId - variant or id of a variant.
|
|
313
358
|
* @param {object} update - an object with the update values.
|
|
359
|
+
* @param {object} config - an object with the config values for returning the variant.
|
|
314
360
|
* @return {Promise} resolves to the update result.
|
|
315
361
|
*/
|
|
316
362
|
ProductVariantService.prototype.update = function (variantOrVariantId, update) {
|
|
@@ -318,7 +364,7 @@ var ProductVariantService = /** @class */ (function (_super) {
|
|
|
318
364
|
var _this = this;
|
|
319
365
|
return __generator(this, function (_a) {
|
|
320
366
|
return [2 /*return*/, this.atomicPhase_(function (manager) { return __awaiter(_this, void 0, void 0, function () {
|
|
321
|
-
var variantRepo, variant, prices, options, metadata, inventory_quantity, rest, options_1, options_1_1, option, e_2_1, _a, _b, _c, key, value, result;
|
|
367
|
+
var variantRepo, variant, variantRes, prices, options, metadata, inventory_quantity, rest, options_1, options_1_1, option, e_2_1, _a, _b, _c, key, value, result;
|
|
322
368
|
var e_2, _d, e_3, _e;
|
|
323
369
|
return __generator(this, function (_f) {
|
|
324
370
|
switch (_f.label) {
|
|
@@ -326,9 +372,17 @@ var ProductVariantService = /** @class */ (function (_super) {
|
|
|
326
372
|
variantRepo = manager.getCustomRepository(this.productVariantRepository_);
|
|
327
373
|
variant = variantOrVariantId;
|
|
328
374
|
if (!(typeof variant === "string")) return [3 /*break*/, 2];
|
|
329
|
-
return [4 /*yield*/,
|
|
375
|
+
return [4 /*yield*/, variantRepo.findOne({
|
|
376
|
+
where: { id: variantOrVariantId },
|
|
377
|
+
})];
|
|
330
378
|
case 1:
|
|
331
|
-
|
|
379
|
+
variantRes = _f.sent();
|
|
380
|
+
if (typeof variant === "undefined") {
|
|
381
|
+
throw new medusa_core_utils_1.MedusaError(medusa_core_utils_1.MedusaError.Types.NOT_FOUND, "Variant with id ".concat(variantOrVariantId, " was not found"));
|
|
382
|
+
}
|
|
383
|
+
else {
|
|
384
|
+
variant = variantRes;
|
|
385
|
+
}
|
|
332
386
|
return [3 /*break*/, 3];
|
|
333
387
|
case 2:
|
|
334
388
|
if (!variant.id) {
|
|
@@ -371,7 +425,7 @@ var ProductVariantService = /** @class */ (function (_super) {
|
|
|
371
425
|
finally { if (e_2) throw e_2.error; }
|
|
372
426
|
return [7 /*endfinally*/];
|
|
373
427
|
case 13:
|
|
374
|
-
if (metadata) {
|
|
428
|
+
if (typeof metadata === "object") {
|
|
375
429
|
variant.metadata = this.setMetadata_(variant, metadata);
|
|
376
430
|
}
|
|
377
431
|
if (typeof inventory_quantity === "number") {
|
|
@@ -479,47 +533,34 @@ var ProductVariantService = /** @class */ (function (_super) {
|
|
|
479
533
|
* exists the function will try to use a currency price. If no default
|
|
480
534
|
* currency price exists the function will throw an error.
|
|
481
535
|
* @param {string} variantId - the id of the variant to get price from
|
|
482
|
-
* @param {
|
|
536
|
+
* @param {GetRegionPriceContext} context - context for getting region price
|
|
483
537
|
* @return {number} the price specific to the region
|
|
484
538
|
*/
|
|
485
|
-
ProductVariantService.prototype.getRegionPrice = function (variantId,
|
|
539
|
+
ProductVariantService.prototype.getRegionPrice = function (variantId, context) {
|
|
486
540
|
return __awaiter(this, void 0, void 0, function () {
|
|
487
541
|
var _this = this;
|
|
488
542
|
return __generator(this, function (_a) {
|
|
489
543
|
return [2 /*return*/, this.atomicPhase_(function (manager) { return __awaiter(_this, void 0, void 0, function () {
|
|
490
|
-
var
|
|
544
|
+
var region, prices;
|
|
491
545
|
return __generator(this, function (_a) {
|
|
492
546
|
switch (_a.label) {
|
|
493
|
-
case 0:
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
.withTransaction(manager)
|
|
497
|
-
.retrieve(regionId)
|
|
498
|
-
// Find region price based on region id
|
|
499
|
-
];
|
|
547
|
+
case 0: return [4 /*yield*/, this.regionService_
|
|
548
|
+
.withTransaction(manager)
|
|
549
|
+
.retrieve(context.regionId)];
|
|
500
550
|
case 1:
|
|
501
551
|
region = _a.sent();
|
|
502
|
-
return [4 /*yield*/,
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
if (!!moneyAmount) return [3 /*break*/, 4];
|
|
511
|
-
return [4 /*yield*/, moneyAmountRepo.findOne({
|
|
512
|
-
where: { variant_id: variantId, currency_code: region.currency_code },
|
|
552
|
+
return [4 /*yield*/, this.priceSelectionStrategy_
|
|
553
|
+
.withTransaction(manager)
|
|
554
|
+
.calculateVariantPrice(variantId, {
|
|
555
|
+
region_id: context.regionId,
|
|
556
|
+
currency_code: region.currency_code,
|
|
557
|
+
quantity: context.quantity,
|
|
558
|
+
customer_id: context.customer_id,
|
|
559
|
+
include_discount_prices: !!context.include_discount_prices,
|
|
513
560
|
})];
|
|
514
|
-
case
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
case 4:
|
|
518
|
-
// Still, if no price is found, we throw
|
|
519
|
-
if (!moneyAmount) {
|
|
520
|
-
throw new medusa_core_utils_1.MedusaError(medusa_core_utils_1.MedusaError.Types.NOT_FOUND, "A price for region: ".concat(region.name, " could not be found"));
|
|
521
|
-
}
|
|
522
|
-
return [2 /*return*/, moneyAmount.amount];
|
|
561
|
+
case 2:
|
|
562
|
+
prices = _a.sent();
|
|
563
|
+
return [2 /*return*/, prices.calculatedPrice];
|
|
523
564
|
}
|
|
524
565
|
});
|
|
525
566
|
}); })];
|
|
@@ -704,26 +745,48 @@ var ProductVariantService = /** @class */ (function (_super) {
|
|
|
704
745
|
* @return {Promise} the result of the find operation
|
|
705
746
|
*/
|
|
706
747
|
ProductVariantService.prototype.listAndCount = function (selector, config) {
|
|
707
|
-
var _a;
|
|
708
|
-
if (config === void 0) { config = {
|
|
748
|
+
var _a, _b, _c;
|
|
749
|
+
if (config === void 0) { config = {
|
|
750
|
+
relations: [],
|
|
751
|
+
skip: 0,
|
|
752
|
+
take: 20,
|
|
753
|
+
include_discount_prices: false,
|
|
754
|
+
}; }
|
|
709
755
|
return __awaiter(this, void 0, void 0, function () {
|
|
710
|
-
var variantRepo,
|
|
711
|
-
return __generator(this, function (
|
|
712
|
-
switch (
|
|
756
|
+
var variantRepo, priceIndex, _d, q, query, relations, qb, _e, raw, count_1, variants_1, res, _f, variants, count, res;
|
|
757
|
+
return __generator(this, function (_g) {
|
|
758
|
+
switch (_g.label) {
|
|
713
759
|
case 0:
|
|
714
760
|
variantRepo = this.manager_.getCustomRepository(this.productVariantRepository_);
|
|
715
|
-
_b =
|
|
716
|
-
if (
|
|
761
|
+
priceIndex = (_b = (_a = config.relations) === null || _a === void 0 ? void 0 : _a.indexOf("prices")) !== null && _b !== void 0 ? _b : -1;
|
|
762
|
+
if (priceIndex >= 0 && config.relations) {
|
|
763
|
+
config.relations = __spreadArray([], __read(config.relations), false);
|
|
764
|
+
config.relations.splice(priceIndex, 1);
|
|
765
|
+
}
|
|
766
|
+
_d = this.prepareListQuery_(selector, config), q = _d.q, query = _d.query, relations = _d.relations;
|
|
767
|
+
if (!q) return [3 /*break*/, 5];
|
|
717
768
|
qb = this.getFreeTextQueryBuilder_(variantRepo, query, q);
|
|
718
769
|
return [4 /*yield*/, qb.getManyAndCount()];
|
|
719
770
|
case 1:
|
|
720
|
-
|
|
721
|
-
return [4 /*yield*/, variantRepo.findWithRelations(relations, raw.map(function (i) { return i.id; }), (
|
|
771
|
+
_e = __read.apply(void 0, [_g.sent(), 2]), raw = _e[0], count_1 = _e[1];
|
|
772
|
+
return [4 /*yield*/, variantRepo.findWithRelations(relations, raw.map(function (i) { return i.id; }), (_c = query.withDeleted) !== null && _c !== void 0 ? _c : false)];
|
|
722
773
|
case 2:
|
|
723
|
-
|
|
724
|
-
return [
|
|
725
|
-
|
|
726
|
-
case
|
|
774
|
+
variants_1 = _g.sent();
|
|
775
|
+
if (!(priceIndex >= 0)) return [3 /*break*/, 4];
|
|
776
|
+
return [4 /*yield*/, this.setAdditionalPrices(variants_1, config.currency_code, config.region_id, config.cart_id, config.customer_id, config.include_discount_prices)];
|
|
777
|
+
case 3:
|
|
778
|
+
res = _g.sent();
|
|
779
|
+
return [2 /*return*/, [res, count_1]];
|
|
780
|
+
case 4: return [2 /*return*/, [variants_1, count_1]];
|
|
781
|
+
case 5: return [4 /*yield*/, variantRepo.findWithRelationsAndCount(relations, query)];
|
|
782
|
+
case 6:
|
|
783
|
+
_f = __read.apply(void 0, [_g.sent(), 2]), variants = _f[0], count = _f[1];
|
|
784
|
+
if (!(priceIndex >= 0)) return [3 /*break*/, 8];
|
|
785
|
+
return [4 /*yield*/, this.setAdditionalPrices(variants, config.currency_code, config.region_id, config.cart_id, config.customer_id, config.include_discount_prices)];
|
|
786
|
+
case 7:
|
|
787
|
+
res = _g.sent();
|
|
788
|
+
return [2 /*return*/, [res, count]];
|
|
789
|
+
case 8: return [2 /*return*/, [variants, count]];
|
|
727
790
|
}
|
|
728
791
|
});
|
|
729
792
|
});
|
|
@@ -734,13 +797,23 @@ var ProductVariantService = /** @class */ (function (_super) {
|
|
|
734
797
|
* @return {Promise} the result of the find operation
|
|
735
798
|
*/
|
|
736
799
|
ProductVariantService.prototype.list = function (selector, config) {
|
|
737
|
-
|
|
800
|
+
var _a, _b;
|
|
801
|
+
if (config === void 0) { config = {
|
|
802
|
+
relations: [],
|
|
803
|
+
skip: 0,
|
|
804
|
+
take: 20,
|
|
805
|
+
}; }
|
|
738
806
|
return __awaiter(this, void 0, void 0, function () {
|
|
739
|
-
var productVariantRepo, q, query, where_1;
|
|
740
|
-
return __generator(this, function (
|
|
741
|
-
switch (
|
|
807
|
+
var productVariantRepo, priceIndex, q, query, where_1, variants, _c;
|
|
808
|
+
return __generator(this, function (_d) {
|
|
809
|
+
switch (_d.label) {
|
|
742
810
|
case 0:
|
|
743
811
|
productVariantRepo = this.manager_.getCustomRepository(this.productVariantRepository_);
|
|
812
|
+
priceIndex = (_b = (_a = config.relations) === null || _a === void 0 ? void 0 : _a.indexOf("prices")) !== null && _b !== void 0 ? _b : -1;
|
|
813
|
+
if (priceIndex >= 0 && config.relations) {
|
|
814
|
+
config.relations = __spreadArray([], __read(config.relations), false);
|
|
815
|
+
config.relations.splice(priceIndex, 1);
|
|
816
|
+
}
|
|
744
817
|
if ("q" in selector) {
|
|
745
818
|
q = selector.q;
|
|
746
819
|
delete selector.q;
|
|
@@ -765,7 +838,17 @@ var ProductVariantService = /** @class */ (function (_super) {
|
|
|
765
838
|
};
|
|
766
839
|
}
|
|
767
840
|
return [4 /*yield*/, productVariantRepo.find(query)];
|
|
768
|
-
case 1:
|
|
841
|
+
case 1:
|
|
842
|
+
variants = _d.sent();
|
|
843
|
+
if (!(priceIndex >= 0)) return [3 /*break*/, 3];
|
|
844
|
+
return [4 /*yield*/, this.setAdditionalPrices(variants, config.currency_code, config.region_id, config.cart_id, config.customer_id, config.include_discount_prices)];
|
|
845
|
+
case 2:
|
|
846
|
+
_c = (_d.sent());
|
|
847
|
+
return [3 /*break*/, 4];
|
|
848
|
+
case 3:
|
|
849
|
+
_c = variants;
|
|
850
|
+
_d.label = 4;
|
|
851
|
+
case 4: return [2 /*return*/, _c];
|
|
769
852
|
}
|
|
770
853
|
});
|
|
771
854
|
});
|
|
@@ -789,7 +872,7 @@ var ProductVariantService = /** @class */ (function (_super) {
|
|
|
789
872
|
variantRepo = manager.getCustomRepository(this.productVariantRepository_);
|
|
790
873
|
return [4 /*yield*/, variantRepo.findOne({
|
|
791
874
|
where: { id: variantId },
|
|
792
|
-
relations: ["prices"],
|
|
875
|
+
relations: ["prices", "options"],
|
|
793
876
|
})];
|
|
794
877
|
case 1:
|
|
795
878
|
variant = _a.sent();
|
|
@@ -906,6 +989,69 @@ var ProductVariantService = /** @class */ (function (_super) {
|
|
|
906
989
|
}
|
|
907
990
|
return qb;
|
|
908
991
|
};
|
|
992
|
+
/**
|
|
993
|
+
* Set additional prices on a list of variants.
|
|
994
|
+
* @param {ProductVariant | ProductVariant[] } variant variant on which to set additional prices
|
|
995
|
+
* @param {string} currency_code currency code to fetch prices for
|
|
996
|
+
* @param {string} region_id region to fetch prices for
|
|
997
|
+
* @param {string} cart_id string of cart to use as a basis for getting currency and region
|
|
998
|
+
* @param {string} customer_id id of potentially logged in customer, used to get prices valid for their customer groups
|
|
999
|
+
* @param {boolean} include_discount_prices should result include discount pricing
|
|
1000
|
+
* @return {Promise<ProductVariant | ProductVariant[]>} A list of variants with variants decorated with "additional_prices"
|
|
1001
|
+
*/
|
|
1002
|
+
ProductVariantService.prototype.setAdditionalPrices = function (variant, currency_code, region_id, cart_id, customer_id, include_discount_prices) {
|
|
1003
|
+
if (include_discount_prices === void 0) { include_discount_prices = false; }
|
|
1004
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1005
|
+
var _this = this;
|
|
1006
|
+
return __generator(this, function (_a) {
|
|
1007
|
+
return [2 /*return*/, this.atomicPhase_(function (manager) { return __awaiter(_this, void 0, void 0, function () {
|
|
1008
|
+
var cartRepo, regionId, currencyCode, cart, variantArray, priceSelectionStrategy, variantsWithPrices;
|
|
1009
|
+
var _this = this;
|
|
1010
|
+
return __generator(this, function (_a) {
|
|
1011
|
+
switch (_a.label) {
|
|
1012
|
+
case 0:
|
|
1013
|
+
cartRepo = manager.getCustomRepository(this.cartRepository_);
|
|
1014
|
+
regionId = region_id;
|
|
1015
|
+
currencyCode = currency_code;
|
|
1016
|
+
if (!cart_id) return [3 /*break*/, 2];
|
|
1017
|
+
return [4 /*yield*/, cartRepo.findOne({
|
|
1018
|
+
where: { id: cart_id },
|
|
1019
|
+
relations: ["region"],
|
|
1020
|
+
})];
|
|
1021
|
+
case 1:
|
|
1022
|
+
cart = _a.sent();
|
|
1023
|
+
regionId = cart.region.id;
|
|
1024
|
+
currencyCode = cart.region.currency_code;
|
|
1025
|
+
_a.label = 2;
|
|
1026
|
+
case 2:
|
|
1027
|
+
variantArray = Array.isArray(variant) ? variant : [variant];
|
|
1028
|
+
priceSelectionStrategy = this.priceSelectionStrategy_.withTransaction(manager);
|
|
1029
|
+
return [4 /*yield*/, Promise.all(variantArray.map(function (v) { return __awaiter(_this, void 0, void 0, function () {
|
|
1030
|
+
var prices;
|
|
1031
|
+
return __generator(this, function (_a) {
|
|
1032
|
+
switch (_a.label) {
|
|
1033
|
+
case 0: return [4 /*yield*/, priceSelectionStrategy.calculateVariantPrice(v.id, {
|
|
1034
|
+
region_id: regionId,
|
|
1035
|
+
currency_code: currencyCode,
|
|
1036
|
+
cart_id: cart_id,
|
|
1037
|
+
customer_id: customer_id,
|
|
1038
|
+
include_discount_prices: include_discount_prices,
|
|
1039
|
+
})];
|
|
1040
|
+
case 1:
|
|
1041
|
+
prices = _a.sent();
|
|
1042
|
+
return [2 /*return*/, __assign(__assign({}, v), { prices: prices.prices, original_price: prices.originalPrice, calculated_price: prices.calculatedPrice, calculated_price_type: prices.calculatedPriceType })];
|
|
1043
|
+
}
|
|
1044
|
+
});
|
|
1045
|
+
}); }))];
|
|
1046
|
+
case 3:
|
|
1047
|
+
variantsWithPrices = _a.sent();
|
|
1048
|
+
return [2 /*return*/, Array.isArray(variant) ? variantsWithPrices : variantsWithPrices[0]];
|
|
1049
|
+
}
|
|
1050
|
+
});
|
|
1051
|
+
}); })];
|
|
1052
|
+
});
|
|
1053
|
+
});
|
|
1054
|
+
};
|
|
909
1055
|
ProductVariantService.Events = {
|
|
910
1056
|
UPDATED: "product-variant.updated",
|
|
911
1057
|
CREATED: "product-variant.created",
|