@medusajs/medusa 1.2.2-dev.47 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +48 -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/error-handler.js +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/customer-groups/get-customer-group-customers.d.ts +20 -0
- package/dist/api/routes/admin/customer-groups/get-customer-group-customers.js +76 -0
- package/dist/api/routes/admin/customer-groups/get-customer-group-customers.js.map +1 -0
- package/dist/api/routes/admin/customer-groups/index.js +1 -0
- package/dist/api/routes/admin/customer-groups/index.js.map +1 -1
- 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/customers/index.js +1 -1
- package/dist/api/routes/admin/customers/index.js.map +1 -1
- package/dist/api/routes/admin/customers/list-customers.js +1 -0
- package/dist/api/routes/admin/customers/list-customers.js.map +1 -1
- package/dist/api/routes/admin/discounts/create-discount.d.ts +11 -2
- package/dist/api/routes/admin/discounts/create-discount.js +66 -12
- 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-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-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 +1 -3
- package/dist/api/routes/admin/discounts/index.js +1 -6
- 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-discount.d.ts +12 -2
- package/dist/api/routes/admin/discounts/update-discount.js +70 -15
- 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 +21 -19
- 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-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/add-prices-batch.d.ts +70 -0
- package/dist/api/routes/admin/{orders/receive-swap.js → price-lists/add-prices-batch.js} +77 -78
- package/dist/api/routes/admin/price-lists/add-prices-batch.js.map +1 -0
- package/dist/api/routes/admin/price-lists/create-price-list.d.ts +87 -0
- package/dist/api/routes/admin/price-lists/create-price-list.js +193 -0
- package/dist/api/routes/admin/price-lists/create-price-list.js.map +1 -0
- package/dist/api/routes/admin/price-lists/delete-price-list.d.ts +28 -0
- package/dist/api/routes/admin/{discounts/remove-valid-product.js → price-lists/delete-price-list.js} +27 -25
- package/dist/api/routes/admin/price-lists/delete-price-list.js.map +1 -0
- package/dist/api/routes/admin/price-lists/delete-prices-batch.d.ts +43 -0
- package/dist/api/routes/{store/carts/update-payment-method.js → admin/price-lists/delete-prices-batch.js} +42 -46
- package/dist/api/routes/admin/price-lists/delete-prices-batch.js.map +1 -0
- package/dist/api/routes/admin/price-lists/get-price-list.d.ts +22 -0
- package/dist/api/routes/admin/{discounts/add-valid-product.js → price-lists/get-price-list.js} +20 -24
- package/dist/api/routes/admin/price-lists/get-price-list.js.map +1 -0
- package/dist/api/routes/admin/price-lists/index.d.ts +28 -0
- package/dist/api/routes/admin/price-lists/index.js +55 -0
- package/dist/api/routes/admin/price-lists/index.js.map +1 -0
- 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 +246 -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.d.ts +38 -0
- package/dist/api/routes/admin/price-lists/list-price-lists.js +197 -0
- package/dist/api/routes/admin/price-lists/list-price-lists.js.map +1 -0
- package/dist/api/routes/admin/price-lists/update-price-list.d.ts +92 -0
- package/dist/api/routes/admin/price-lists/update-price-list.js +211 -0
- package/dist/api/routes/admin/price-lists/update-price-list.js.map +1 -0
- package/dist/api/routes/admin/products/create-product.d.ts +2 -7
- package/dist/api/routes/admin/products/create-product.js +2 -24
- package/dist/api/routes/admin/products/create-product.js.map +1 -1
- package/dist/api/routes/admin/products/create-variant.d.ts +7 -9
- package/dist/api/routes/admin/products/create-variant.js +7 -26
- package/dist/api/routes/admin/products/create-variant.js.map +1 -1
- package/dist/api/routes/admin/products/index.d.ts +1 -1
- package/dist/api/routes/admin/products/index.js +7 -1
- 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/update-product.d.ts +2 -7
- package/dist/api/routes/admin/products/update-product.js +2 -24
- package/dist/api/routes/admin/products/update-product.js.map +1 -1
- package/dist/api/routes/admin/products/update-variant.d.ts +10 -9
- package/dist/api/routes/admin/products/update-variant.js +21 -33
- 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/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/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 +7 -7
- package/dist/api/routes/store/carts/update-cart.js.map +1 -1
- package/dist/api/routes/store/collections/list-collections.d.ts +3 -0
- package/dist/api/routes/store/collections/list-collections.js +33 -16
- package/dist/api/routes/store/collections/list-collections.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 +5 -3
- package/dist/api/routes/store/products/list-products.js +60 -18
- 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/regions/list-regions.d.ts +3 -0
- package/dist/api/routes/store/regions/list-regions.js +22 -7
- package/dist/api/routes/store/regions/list-regions.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 +6 -1
- package/dist/api/routes/store/variants/list-variants.js +63 -10
- package/dist/api/routes/store/variants/list-variants.js.map +1 -1
- package/dist/commands/develop.js +1 -1
- package/dist/commands/develop.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 +15 -7
- package/dist/helpers/test-request.js.map +1 -1
- package/dist/index.d.ts +3 -58
- package/dist/index.js +3 -61
- package/dist/index.js.map +1 -1
- package/dist/interfaces/base-service.d.ts +66 -0
- package/dist/interfaces/base-service.js +378 -0
- package/dist/interfaces/base-service.js.map +1 -0
- package/dist/interfaces/index.d.ts +1 -0
- package/dist/interfaces/index.js +1 -0
- package/dist/interfaces/index.js.map +1 -1
- 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/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 +18 -10
- package/dist/loaders/plugins.js +27 -24
- 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/1646915480108-update_money_amount_add_price_list.d.ts +6 -0
- package/dist/migrations/1646915480108-update_money_amount_add_price_list.js +143 -0
- package/dist/migrations/1646915480108-update_money_amount_add_price_list.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/batch-job.d.ts +58 -0
- package/dist/models/batch-job.js +119 -0
- package/dist/models/batch-job.js.map +1 -0
- 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/customer-group.d.ts +3 -1
- package/dist/models/customer-group.js +9 -13
- package/dist/models/customer-group.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 +68 -0
- package/dist/models/discount-condition.js +208 -0
- package/dist/models/discount-condition.js.map +1 -0
- package/dist/models/discount-rule.d.ts +5 -5
- package/dist/models/discount-rule.js +6 -17
- package/dist/models/discount-rule.js.map +1 -1
- package/dist/models/discount.js.map +1 -1
- package/dist/models/index.d.ts +66 -0
- package/dist/models/index.js +79 -0
- package/dist/models/index.js.map +1 -0
- package/dist/models/line-item-adjustment.d.ts +13 -0
- package/dist/models/line-item-adjustment.js +79 -0
- package/dist/models/line-item-adjustment.js.map +1 -0
- package/dist/models/line-item-tax-line.js +2 -1
- package/dist/models/line-item-tax-line.js.map +1 -1
- package/dist/models/line-item.d.ts +2 -0
- package/dist/models/line-item.js +5 -0
- package/dist/models/line-item.js.map +1 -1
- package/dist/models/money-amount.d.ts +10 -3
- package/dist/models/money-amount.js +25 -5
- package/dist/models/money-amount.js.map +1 -1
- package/dist/models/price-list.d.ts +57 -0
- package/dist/models/price-list.js +146 -0
- package/dist/models/price-list.js.map +1 -0
- package/dist/models/product-variant.js +9 -3
- package/dist/models/product-variant.js.map +1 -1
- package/dist/models/shipping-method-tax-line.js +2 -1
- package/dist/models/shipping-method-tax-line.js.map +1 -1
- package/dist/models/swap.d.ts +4 -4
- package/dist/models/swap.js +23 -23
- package/dist/models/swap.js.map +1 -1
- package/dist/repositories/cart.d.ts +2 -2
- package/dist/repositories/cart.js.map +1 -1
- package/dist/repositories/customer.d.ts +1 -0
- package/dist/repositories/customer.js +63 -0
- package/dist/repositories/customer.js.map +1 -1
- package/dist/repositories/discount-condition.d.ts +34 -0
- package/dist/repositories/discount-condition.js +384 -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 +7 -2
- package/dist/repositories/money-amount.js +149 -2
- package/dist/repositories/money-amount.js.map +1 -1
- package/dist/repositories/price-list.d.ts +4 -0
- package/dist/repositories/price-list.js +38 -0
- package/dist/repositories/price-list.js.map +1 -0
- package/dist/repositories/product.d.ts +3 -0
- package/dist/repositories/product.js +41 -19
- 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 +177 -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/cart.d.ts +58 -47
- package/dist/services/cart.js +1306 -1391
- package/dist/services/cart.js.map +1 -1
- package/dist/services/customer.js +18 -18
- package/dist/services/customer.js.map +1 -1
- package/dist/services/discount.d.ts +50 -58
- package/dist/services/discount.js +365 -154
- 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 +436 -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.js +4 -4
- 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 +86 -0
- package/dist/services/price-list.js +469 -0
- package/dist/services/price-list.js.map +1 -0
- package/dist/services/product-variant.d.ts +40 -16
- package/dist/services/product-variant.js +259 -109
- package/dist/services/product-variant.js.map +1 -1
- package/dist/services/product.d.ts +22 -4
- package/dist/services/product.js +239 -49
- 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 +0 -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/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 +6 -0
- package/dist/types/batch-job.js +11 -0
- package/dist/types/batch-job.js.map +1 -0
- package/dist/types/common.d.ts +1 -3
- package/dist/types/customers.d.ts +1 -0
- package/dist/types/customers.js +5 -0
- package/dist/types/customers.js.map +1 -1
- package/dist/types/discount.d.ts +69 -1
- package/dist/types/discount.js +129 -5
- package/dist/types/discount.js.map +1 -1
- package/dist/types/global.d.ts +34 -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/price-list.d.ts +70 -0
- package/dist/types/price-list.js +152 -0
- package/dist/types/price-list.js.map +1 -0
- 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 +26 -3
- package/dist/types/product-variant.js +69 -5
- package/dist/types/product-variant.js.map +1 -1
- package/dist/types/product.d.ts +16 -0
- package/dist/types/product.js +86 -1
- package/dist/types/product.js.map +1 -1
- 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/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/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/package.json +7 -8
- 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/orders/receive-swap.d.ts +0 -46
- package/dist/api/routes/admin/orders/receive-swap.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/dist/controllers/list-customers.d.ts +0 -0
- package/dist/controllers/list-customers.js +0 -1
- package/dist/controllers/list-customers.js.map +0 -1
- package/yarn-error.log +0 -6769
|
@@ -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
|
});
|
|
@@ -268,7 +313,6 @@ var ProductVariantService = /** @class */ (function (_super) {
|
|
|
268
313
|
return [4 /*yield*/, this.setRegionPrice(result.id, {
|
|
269
314
|
amount: price.amount,
|
|
270
315
|
region_id: price.region_id,
|
|
271
|
-
sale_amount: price.sale_amount,
|
|
272
316
|
})];
|
|
273
317
|
case 7:
|
|
274
318
|
_b.sent();
|
|
@@ -312,6 +356,7 @@ var ProductVariantService = /** @class */ (function (_super) {
|
|
|
312
356
|
* The function will throw, if price updates are attempted.
|
|
313
357
|
* @param {string | ProductVariant} variantOrVariantId - variant or id of a variant.
|
|
314
358
|
* @param {object} update - an object with the update values.
|
|
359
|
+
* @param {object} config - an object with the config values for returning the variant.
|
|
315
360
|
* @return {Promise} resolves to the update result.
|
|
316
361
|
*/
|
|
317
362
|
ProductVariantService.prototype.update = function (variantOrVariantId, update) {
|
|
@@ -319,7 +364,7 @@ var ProductVariantService = /** @class */ (function (_super) {
|
|
|
319
364
|
var _this = this;
|
|
320
365
|
return __generator(this, function (_a) {
|
|
321
366
|
return [2 /*return*/, this.atomicPhase_(function (manager) { return __awaiter(_this, void 0, void 0, function () {
|
|
322
|
-
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;
|
|
323
368
|
var e_2, _d, e_3, _e;
|
|
324
369
|
return __generator(this, function (_f) {
|
|
325
370
|
switch (_f.label) {
|
|
@@ -327,9 +372,17 @@ var ProductVariantService = /** @class */ (function (_super) {
|
|
|
327
372
|
variantRepo = manager.getCustomRepository(this.productVariantRepository_);
|
|
328
373
|
variant = variantOrVariantId;
|
|
329
374
|
if (!(typeof variant === "string")) return [3 /*break*/, 2];
|
|
330
|
-
return [4 /*yield*/,
|
|
375
|
+
return [4 /*yield*/, variantRepo.findOne({
|
|
376
|
+
where: { id: variantOrVariantId },
|
|
377
|
+
})];
|
|
331
378
|
case 1:
|
|
332
|
-
|
|
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
|
+
}
|
|
333
386
|
return [3 /*break*/, 3];
|
|
334
387
|
case 2:
|
|
335
388
|
if (!variant.id) {
|
|
@@ -372,7 +425,7 @@ var ProductVariantService = /** @class */ (function (_super) {
|
|
|
372
425
|
finally { if (e_2) throw e_2.error; }
|
|
373
426
|
return [7 /*endfinally*/];
|
|
374
427
|
case 13:
|
|
375
|
-
if (metadata) {
|
|
428
|
+
if (typeof metadata === "object") {
|
|
376
429
|
variant.metadata = this.setMetadata_(variant, metadata);
|
|
377
430
|
}
|
|
378
431
|
if (typeof inventory_quantity === "number") {
|
|
@@ -410,6 +463,13 @@ var ProductVariantService = /** @class */ (function (_super) {
|
|
|
410
463
|
});
|
|
411
464
|
});
|
|
412
465
|
};
|
|
466
|
+
/**
|
|
467
|
+
* Updates a variant's prices.
|
|
468
|
+
* Deletes any prices that are not in the update object, and is not associated with a price list.
|
|
469
|
+
* @param variantId - the id of variant variant
|
|
470
|
+
* @param prices - the update prices
|
|
471
|
+
* @returns {Promise<void>} empty promise
|
|
472
|
+
*/
|
|
413
473
|
ProductVariantService.prototype.updateVariantPrices = function (variantId, prices) {
|
|
414
474
|
return __awaiter(this, void 0, void 0, function () {
|
|
415
475
|
var _this = this;
|
|
@@ -436,7 +496,6 @@ var ProductVariantService = /** @class */ (function (_super) {
|
|
|
436
496
|
return [4 /*yield*/, this.setRegionPrice(variantId, {
|
|
437
497
|
region_id: price.region_id,
|
|
438
498
|
amount: price.amount,
|
|
439
|
-
sale_amount: price.sale_amount || undefined,
|
|
440
499
|
})];
|
|
441
500
|
case 4:
|
|
442
501
|
_b.sent();
|
|
@@ -469,80 +528,39 @@ var ProductVariantService = /** @class */ (function (_super) {
|
|
|
469
528
|
});
|
|
470
529
|
});
|
|
471
530
|
};
|
|
472
|
-
/**
|
|
473
|
-
* Sets the default price for the given currency.
|
|
474
|
-
* @param {string} variantId - the id of the variant to set prices for
|
|
475
|
-
* @param {ProductVariantPrice} price - the price for the variant
|
|
476
|
-
* @return {Promise} the result of the update operation
|
|
477
|
-
*/
|
|
478
|
-
ProductVariantService.prototype.setCurrencyPrice = function (variantId, price) {
|
|
479
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
480
|
-
var _this = this;
|
|
481
|
-
return __generator(this, function (_a) {
|
|
482
|
-
return [2 /*return*/, this.atomicPhase_(function (manager) { return __awaiter(_this, void 0, void 0, function () {
|
|
483
|
-
var moneyAmountRepo;
|
|
484
|
-
return __generator(this, function (_a) {
|
|
485
|
-
switch (_a.label) {
|
|
486
|
-
case 0:
|
|
487
|
-
moneyAmountRepo = manager.getCustomRepository(this.moneyAmountRepository_);
|
|
488
|
-
return [4 /*yield*/, moneyAmountRepo.upsertCurrencyPrice(variantId, price)];
|
|
489
|
-
case 1: return [2 /*return*/, _a.sent()];
|
|
490
|
-
}
|
|
491
|
-
});
|
|
492
|
-
}); })];
|
|
493
|
-
});
|
|
494
|
-
});
|
|
495
|
-
};
|
|
496
531
|
/**
|
|
497
532
|
* Gets the price specific to a region. If no region specific money amount
|
|
498
533
|
* exists the function will try to use a currency price. If no default
|
|
499
534
|
* currency price exists the function will throw an error.
|
|
500
535
|
* @param {string} variantId - the id of the variant to get price from
|
|
501
|
-
* @param {
|
|
536
|
+
* @param {GetRegionPriceContext} context - context for getting region price
|
|
502
537
|
* @return {number} the price specific to the region
|
|
503
538
|
*/
|
|
504
|
-
ProductVariantService.prototype.getRegionPrice = function (variantId,
|
|
539
|
+
ProductVariantService.prototype.getRegionPrice = function (variantId, context) {
|
|
505
540
|
return __awaiter(this, void 0, void 0, function () {
|
|
506
541
|
var _this = this;
|
|
507
542
|
return __generator(this, function (_a) {
|
|
508
543
|
return [2 /*return*/, this.atomicPhase_(function (manager) { return __awaiter(_this, void 0, void 0, function () {
|
|
509
|
-
var
|
|
544
|
+
var region, prices;
|
|
510
545
|
return __generator(this, function (_a) {
|
|
511
546
|
switch (_a.label) {
|
|
512
|
-
case 0:
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
.withTransaction(manager)
|
|
516
|
-
.retrieve(regionId)
|
|
517
|
-
// Find region price based on region id
|
|
518
|
-
];
|
|
547
|
+
case 0: return [4 /*yield*/, this.regionService_
|
|
548
|
+
.withTransaction(manager)
|
|
549
|
+
.retrieve(context.regionId)];
|
|
519
550
|
case 1:
|
|
520
551
|
region = _a.sent();
|
|
521
|
-
return [4 /*yield*/,
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
if (!!moneyAmount) return [3 /*break*/, 4];
|
|
530
|
-
return [4 /*yield*/, moneyAmountRepo.findOne({
|
|
531
|
-
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,
|
|
532
560
|
})];
|
|
533
|
-
case
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
case 4:
|
|
537
|
-
// Still, if no price is found, we throw
|
|
538
|
-
if (!moneyAmount) {
|
|
539
|
-
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"));
|
|
540
|
-
}
|
|
541
|
-
// Always return sale price, if present
|
|
542
|
-
if (moneyAmount.sale_amount) {
|
|
543
|
-
return [2 /*return*/, moneyAmount.sale_amount];
|
|
544
|
-
}
|
|
545
|
-
return [2 /*return*/, moneyAmount.amount];
|
|
561
|
+
case 2:
|
|
562
|
+
prices = _a.sent();
|
|
563
|
+
return [2 /*return*/, prices.calculatedPrice];
|
|
546
564
|
}
|
|
547
565
|
});
|
|
548
566
|
}); })];
|
|
@@ -550,7 +568,7 @@ var ProductVariantService = /** @class */ (function (_super) {
|
|
|
550
568
|
});
|
|
551
569
|
};
|
|
552
570
|
/**
|
|
553
|
-
* Sets the price of a specific region
|
|
571
|
+
* Sets the default price of a specific region
|
|
554
572
|
* @param {string} variantId - the id of the variant to update
|
|
555
573
|
* @param {string} price - the price for the variant.
|
|
556
574
|
* @return {Promise} the result of the update operation
|
|
@@ -569,6 +587,7 @@ var ProductVariantService = /** @class */ (function (_super) {
|
|
|
569
587
|
where: {
|
|
570
588
|
variant_id: variantId,
|
|
571
589
|
region_id: price.region_id,
|
|
590
|
+
price_list_id: null,
|
|
572
591
|
},
|
|
573
592
|
})];
|
|
574
593
|
case 1:
|
|
@@ -578,7 +597,6 @@ var ProductVariantService = /** @class */ (function (_super) {
|
|
|
578
597
|
}
|
|
579
598
|
else {
|
|
580
599
|
moneyAmount.amount = price.amount;
|
|
581
|
-
moneyAmount.sale_amount = price.sale_amount;
|
|
582
600
|
}
|
|
583
601
|
return [4 /*yield*/, moneyAmountRepo.save(moneyAmount)];
|
|
584
602
|
case 2:
|
|
@@ -590,6 +608,30 @@ var ProductVariantService = /** @class */ (function (_super) {
|
|
|
590
608
|
});
|
|
591
609
|
});
|
|
592
610
|
};
|
|
611
|
+
/**
|
|
612
|
+
* Sets the default price for the given currency.
|
|
613
|
+
* @param {string} variantId - the id of the variant to set prices for
|
|
614
|
+
* @param {ProductVariantPrice} price - the price for the variant
|
|
615
|
+
* @return {Promise} the result of the update operation
|
|
616
|
+
*/
|
|
617
|
+
ProductVariantService.prototype.setCurrencyPrice = function (variantId, price) {
|
|
618
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
619
|
+
var _this = this;
|
|
620
|
+
return __generator(this, function (_a) {
|
|
621
|
+
return [2 /*return*/, this.atomicPhase_(function (manager) { return __awaiter(_this, void 0, void 0, function () {
|
|
622
|
+
var moneyAmountRepo;
|
|
623
|
+
return __generator(this, function (_a) {
|
|
624
|
+
switch (_a.label) {
|
|
625
|
+
case 0:
|
|
626
|
+
moneyAmountRepo = manager.getCustomRepository(this.moneyAmountRepository_);
|
|
627
|
+
return [4 /*yield*/, moneyAmountRepo.upsertVariantCurrencyPrice(variantId, price)];
|
|
628
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
629
|
+
}
|
|
630
|
+
});
|
|
631
|
+
}); })];
|
|
632
|
+
});
|
|
633
|
+
});
|
|
634
|
+
};
|
|
593
635
|
/**
|
|
594
636
|
* Updates variant's option value.
|
|
595
637
|
* Option value must be of type string or number.
|
|
@@ -703,26 +745,48 @@ var ProductVariantService = /** @class */ (function (_super) {
|
|
|
703
745
|
* @return {Promise} the result of the find operation
|
|
704
746
|
*/
|
|
705
747
|
ProductVariantService.prototype.listAndCount = function (selector, config) {
|
|
706
|
-
var _a;
|
|
707
|
-
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
|
+
}; }
|
|
708
755
|
return __awaiter(this, void 0, void 0, function () {
|
|
709
|
-
var variantRepo,
|
|
710
|
-
return __generator(this, function (
|
|
711
|
-
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) {
|
|
712
759
|
case 0:
|
|
713
760
|
variantRepo = this.manager_.getCustomRepository(this.productVariantRepository_);
|
|
714
|
-
_b =
|
|
715
|
-
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];
|
|
716
768
|
qb = this.getFreeTextQueryBuilder_(variantRepo, query, q);
|
|
717
769
|
return [4 /*yield*/, qb.getManyAndCount()];
|
|
718
770
|
case 1:
|
|
719
|
-
|
|
720
|
-
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)];
|
|
721
773
|
case 2:
|
|
722
|
-
|
|
723
|
-
return [
|
|
724
|
-
|
|
725
|
-
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]];
|
|
726
790
|
}
|
|
727
791
|
});
|
|
728
792
|
});
|
|
@@ -733,13 +797,23 @@ var ProductVariantService = /** @class */ (function (_super) {
|
|
|
733
797
|
* @return {Promise} the result of the find operation
|
|
734
798
|
*/
|
|
735
799
|
ProductVariantService.prototype.list = function (selector, config) {
|
|
736
|
-
|
|
800
|
+
var _a, _b;
|
|
801
|
+
if (config === void 0) { config = {
|
|
802
|
+
relations: [],
|
|
803
|
+
skip: 0,
|
|
804
|
+
take: 20,
|
|
805
|
+
}; }
|
|
737
806
|
return __awaiter(this, void 0, void 0, function () {
|
|
738
|
-
var productVariantRepo, q, query, where_1;
|
|
739
|
-
return __generator(this, function (
|
|
740
|
-
switch (
|
|
807
|
+
var productVariantRepo, priceIndex, q, query, where_1, variants, _c;
|
|
808
|
+
return __generator(this, function (_d) {
|
|
809
|
+
switch (_d.label) {
|
|
741
810
|
case 0:
|
|
742
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
|
+
}
|
|
743
817
|
if ("q" in selector) {
|
|
744
818
|
q = selector.q;
|
|
745
819
|
delete selector.q;
|
|
@@ -764,7 +838,17 @@ var ProductVariantService = /** @class */ (function (_super) {
|
|
|
764
838
|
};
|
|
765
839
|
}
|
|
766
840
|
return [4 /*yield*/, productVariantRepo.find(query)];
|
|
767
|
-
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];
|
|
768
852
|
}
|
|
769
853
|
});
|
|
770
854
|
});
|
|
@@ -786,7 +870,10 @@ var ProductVariantService = /** @class */ (function (_super) {
|
|
|
786
870
|
switch (_a.label) {
|
|
787
871
|
case 0:
|
|
788
872
|
variantRepo = manager.getCustomRepository(this.productVariantRepository_);
|
|
789
|
-
return [4 /*yield*/, variantRepo.findOne({
|
|
873
|
+
return [4 /*yield*/, variantRepo.findOne({
|
|
874
|
+
where: { id: variantId },
|
|
875
|
+
relations: ["prices"],
|
|
876
|
+
})];
|
|
790
877
|
case 1:
|
|
791
878
|
variant = _a.sent();
|
|
792
879
|
if (!variant) {
|
|
@@ -902,6 +989,69 @@ var ProductVariantService = /** @class */ (function (_super) {
|
|
|
902
989
|
}
|
|
903
990
|
return qb;
|
|
904
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
|
+
};
|
|
905
1055
|
ProductVariantService.Events = {
|
|
906
1056
|
UPDATED: "product-variant.updated",
|
|
907
1057
|
CREATED: "product-variant.created",
|