chore: Remove FlagRouter from core (#4710)
* Allow nested feature flags * clean up * Create loud-wombats-shave.md * add warning * Add more tests * Address PR comments * add back boolean check * Replace core flag router with utils one * lol - actually remove it * Create eleven-doors-roll.md --------- Co-authored-by: carlos-r-l-rodrigues <rodrigolr@gmail.com>
This commit is contained in:
co-authored by
carlos-r-l-rodrigues
parent
281b0746cf
commit
d1e298f5dc
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"@medusajs/medusa": patch
|
||||
---
|
||||
|
||||
chore: Remove FlagRouter from core
|
||||
@@ -1,5 +1,5 @@
|
||||
import { FlagRouter } from "@medusajs/utils"
|
||||
import { NextFunction, Request, Response } from "express"
|
||||
import { FlagRouter } from "../../utils/flag-router"
|
||||
|
||||
export function isFeatureFlagEnabled(
|
||||
flagKey: string
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { FlagRouter } from "@medusajs/utils"
|
||||
import { NextFunction, Request, Response } from "express"
|
||||
import SalesChannelFeatureFlag from "../../loaders/feature-flags/sales-channels"
|
||||
import { SalesChannelService } from "../../services"
|
||||
import { FlagRouter } from "../../utils/flag-router"
|
||||
|
||||
/**
|
||||
* Middleware that includes the default sales channel on the request, if no sales channels present
|
||||
|
||||
@@ -1,81 +1,81 @@
|
||||
import { FlagRouter } from "@medusajs/utils"
|
||||
import { Router } from "express"
|
||||
import "reflect-metadata"
|
||||
import { Order } from "../../../.."
|
||||
import SalesChannelFeatureFlag from "../../../../loaders/feature-flags/sales-channels"
|
||||
import { FindParams, PaginatedResponse } from "../../../../types/common"
|
||||
import { FlagRouter } from "../../../../utils/flag-router"
|
||||
import {
|
||||
defaultAdminOrdersFields,
|
||||
defaultAdminOrdersRelations,
|
||||
} from "../../../../types/orders"
|
||||
import middlewares, {
|
||||
transformBody,
|
||||
transformIncludesOptions,
|
||||
transformQuery,
|
||||
} from "../../../middlewares"
|
||||
import { checkRegisteredModules } from "../../../middlewares/check-registered-modules"
|
||||
import { AdminOrdersOrderLineItemReservationReq } from "./create-reservation-for-line-item"
|
||||
import { AdminGetOrdersOrderReservationsParams } from "./get-reservations"
|
||||
import { AdminGetOrdersParams } from "./list-orders"
|
||||
import {
|
||||
AdminPostOrdersOrderSwapsParams,
|
||||
AdminPostOrdersOrderSwapsReq,
|
||||
} from "./create-swap"
|
||||
import {
|
||||
AdminPostOrdersOrderParams,
|
||||
AdminPostOrdersOrderReq,
|
||||
} from "./update-order"
|
||||
import { AdminPostOrdersOrderCompleteParams } from "./complete-order"
|
||||
import {
|
||||
AdminPostOrdersOrderRefundsParams,
|
||||
AdminPostOrdersOrderRefundsReq,
|
||||
} from "./refund-payment"
|
||||
import { AdminPostOrdersOrderCaptureParams } from "./capture-payment"
|
||||
import {
|
||||
AdminPostOrdersOrderFulfillmentsParams,
|
||||
AdminPostOrdersOrderFulfillmentsReq,
|
||||
} from "./create-fulfillment"
|
||||
import { AdminPostOrdersOrderFulfillementsCancelParams } from "./cancel-fulfillment"
|
||||
import { AdminPostOrdersOrderSwapFulfillementsCancelParams } from "./cancel-fulfillment-swap"
|
||||
import { AdminPostOrdersClaimFulfillmentsCancelParams } from "./cancel-fulfillment-claim"
|
||||
import {
|
||||
AdminPostOrdersOrderShipmentParams,
|
||||
AdminPostOrdersOrderShipmentReq,
|
||||
} from "./create-shipment"
|
||||
import {
|
||||
AdminPostOrdersOrderReturnsParams,
|
||||
AdminPostOrdersOrderReturnsReq,
|
||||
} from "./request-return"
|
||||
import { AdminPostOrdersOrderCancel } from "./cancel-order"
|
||||
import {
|
||||
AdminPostOrdersOrderShippingMethodsParams,
|
||||
AdminPostOrdersOrderShippingMethodsReq,
|
||||
} from "./add-shipping-method"
|
||||
import { AdminPostOrdersOrderArchiveParams } from "./archive-order"
|
||||
import { AdminPostOrdersClaimCancel } from "./cancel-claim"
|
||||
import { AdminPostOrdersOrderFulfillementsCancelParams } from "./cancel-fulfillment"
|
||||
import { AdminPostOrdersClaimFulfillmentsCancelParams } from "./cancel-fulfillment-claim"
|
||||
import { AdminPostOrdersOrderSwapFulfillementsCancelParams } from "./cancel-fulfillment-swap"
|
||||
import { AdminPostOrdersOrderCancel } from "./cancel-order"
|
||||
import { AdminPostOrdersSwapCancelParams } from "./cancel-swap"
|
||||
import { AdminPostOrdersOrderSwapsSwapFulfillmentsParams } from "./fulfill-swap"
|
||||
import {
|
||||
AdminPostOrdersOrderSwapsSwapShipmentsParams,
|
||||
AdminPostOrdersOrderSwapsSwapShipmentsReq,
|
||||
} from "./create-swap-shipment"
|
||||
import { AdminPostOrdersOrderSwapsSwapProcessPaymentParams } from "./process-swap-payment"
|
||||
import { AdminPostOrdersOrderCaptureParams } from "./capture-payment"
|
||||
import { AdminPostOrdersOrderCompleteParams } from "./complete-order"
|
||||
import {
|
||||
AdminPostOrdersOrderClaimsParams,
|
||||
AdminPostOrdersOrderClaimsReq,
|
||||
} from "./create-claim"
|
||||
import { AdminPostOrdersClaimCancel } from "./cancel-claim"
|
||||
import {
|
||||
AdminPostOrdersOrderClaimsClaimParams,
|
||||
AdminPostOrdersOrderClaimsClaimReq,
|
||||
} from "./update-claim"
|
||||
import {
|
||||
AdminPostOrdersOrderClaimsClaimFulfillmentsParams,
|
||||
AdminPostOrdersOrderClaimsClaimFulfillmentsReq,
|
||||
} from "./fulfill-claim"
|
||||
import {
|
||||
AdminPostOrdersOrderClaimsClaimShipmentsParams,
|
||||
AdminPostOrdersOrderClaimsClaimShipmentsReq,
|
||||
} from "./create-claim-shipment"
|
||||
import {
|
||||
defaultAdminOrdersFields,
|
||||
defaultAdminOrdersRelations,
|
||||
} from "../../../../types/orders"
|
||||
AdminPostOrdersOrderFulfillmentsParams,
|
||||
AdminPostOrdersOrderFulfillmentsReq,
|
||||
} from "./create-fulfillment"
|
||||
import { AdminOrdersOrderLineItemReservationReq } from "./create-reservation-for-line-item"
|
||||
import {
|
||||
AdminPostOrdersOrderShipmentParams,
|
||||
AdminPostOrdersOrderShipmentReq,
|
||||
} from "./create-shipment"
|
||||
import {
|
||||
AdminPostOrdersOrderSwapsParams,
|
||||
AdminPostOrdersOrderSwapsReq,
|
||||
} from "./create-swap"
|
||||
import {
|
||||
AdminPostOrdersOrderSwapsSwapShipmentsParams,
|
||||
AdminPostOrdersOrderSwapsSwapShipmentsReq,
|
||||
} from "./create-swap-shipment"
|
||||
import {
|
||||
AdminPostOrdersOrderClaimsClaimFulfillmentsParams,
|
||||
AdminPostOrdersOrderClaimsClaimFulfillmentsReq,
|
||||
} from "./fulfill-claim"
|
||||
import { AdminPostOrdersOrderSwapsSwapFulfillmentsParams } from "./fulfill-swap"
|
||||
import { AdminGetOrdersOrderReservationsParams } from "./get-reservations"
|
||||
import { AdminGetOrdersParams } from "./list-orders"
|
||||
import { AdminPostOrdersOrderSwapsSwapProcessPaymentParams } from "./process-swap-payment"
|
||||
import {
|
||||
AdminPostOrdersOrderRefundsParams,
|
||||
AdminPostOrdersOrderRefundsReq,
|
||||
} from "./refund-payment"
|
||||
import {
|
||||
AdminPostOrdersOrderReturnsParams,
|
||||
AdminPostOrdersOrderReturnsReq,
|
||||
} from "./request-return"
|
||||
import {
|
||||
AdminPostOrdersOrderClaimsClaimParams,
|
||||
AdminPostOrdersOrderClaimsClaimReq,
|
||||
} from "./update-claim"
|
||||
import {
|
||||
AdminPostOrdersOrderParams,
|
||||
AdminPostOrdersOrderReq,
|
||||
} from "./update-order"
|
||||
|
||||
const route = Router()
|
||||
|
||||
@@ -779,3 +779,4 @@ export * from "./refund-payment"
|
||||
export * from "./request-return"
|
||||
export * from "./update-claim"
|
||||
export * from "./update-order"
|
||||
|
||||
|
||||
@@ -1,20 +1,20 @@
|
||||
import { FlagRouter } from "@medusajs/utils"
|
||||
import { Router } from "express"
|
||||
import "reflect-metadata"
|
||||
import { PriceList, Product } from "../../../.."
|
||||
import TaxInclusivePricingFeatureFlag from "../../../../loaders/feature-flags/tax-inclusive-pricing"
|
||||
import { DeleteResponse, PaginatedResponse } from "../../../../types/common"
|
||||
import middlewares, {
|
||||
transformBody,
|
||||
transformQuery,
|
||||
} from "../../../middlewares"
|
||||
import { AdminGetPriceListPaginationParams } from "./list-price-lists"
|
||||
import { AdminGetPriceListsPriceListProductsParams } from "./list-price-list-products"
|
||||
import {
|
||||
defaultAdminProductFields,
|
||||
defaultAdminProductRelations,
|
||||
} from "../products"
|
||||
import { AdminPostPriceListsPriceListReq } from "./create-price-list"
|
||||
import { FlagRouter } from "../../../../utils/flag-router"
|
||||
import TaxInclusivePricingFeatureFlag from "../../../../loaders/feature-flags/tax-inclusive-pricing"
|
||||
import { AdminGetPriceListsPriceListProductsParams } from "./list-price-list-products"
|
||||
import { AdminGetPriceListPaginationParams } from "./list-price-lists"
|
||||
|
||||
const route = Router()
|
||||
|
||||
@@ -280,8 +280,9 @@ export type AdminPriceListsProductsListRes = PaginatedResponse & {
|
||||
export * from "./add-prices-batch"
|
||||
export * from "./create-price-list"
|
||||
export * from "./delete-price-list"
|
||||
export * from "./delete-prices-batch"
|
||||
export * from "./get-price-list"
|
||||
export * from "./list-price-list-products"
|
||||
export * from "./list-price-lists"
|
||||
export * from "./update-price-list"
|
||||
export * from "./delete-prices-batch"
|
||||
export * from "./list-price-list-products"
|
||||
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
import "reflect-metadata"
|
||||
|
||||
import { FindParams, PaginatedResponse } from "../../../../types/common"
|
||||
import { Product, ProductTag, ProductType, ProductVariant } from "../../../.."
|
||||
import { FindParams, PaginatedResponse } from "../../../../types/common"
|
||||
import middlewares, { transformQuery } from "../../../middlewares"
|
||||
|
||||
import { AdminGetProductsParams } from "./list-products"
|
||||
import { FlagRouter } from "../../../../utils/flag-router"
|
||||
import { FlagRouter } from "@medusajs/utils"
|
||||
import { Router } from "express"
|
||||
import { validateSalesChannelsExist } from "../../../middlewares/validators/sales-channel-existence"
|
||||
import { PricedProduct } from "../../../../types/pricing"
|
||||
import { validateSalesChannelsExist } from "../../../middlewares/validators/sales-channel-existence"
|
||||
import { AdminGetProductsParams } from "./list-products"
|
||||
|
||||
const route = Router()
|
||||
|
||||
@@ -407,3 +407,4 @@ export * from "./set-metadata"
|
||||
export * from "./update-option"
|
||||
export * from "./update-product"
|
||||
export * from "./update-variant"
|
||||
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import { FlagRouter } from "@medusajs/utils"
|
||||
import { Router } from "express"
|
||||
import "reflect-metadata"
|
||||
import { Region } from "../../../.."
|
||||
import TaxInclusivePricingFeatureFlag from "../../../../loaders/feature-flags/tax-inclusive-pricing"
|
||||
import { DeleteResponse, PaginatedResponse } from "../../../../types/common"
|
||||
import middlewares from "../../../middlewares"
|
||||
import "reflect-metadata"
|
||||
import { FlagRouter } from "../../../../utils/flag-router"
|
||||
import TaxInclusivePricingFeatureFlag from "../../../../loaders/feature-flags/tax-inclusive-pricing"
|
||||
|
||||
const route = Router()
|
||||
|
||||
@@ -204,9 +204,10 @@ export class AdminGetRegionsRegionFulfillmentOptionsRes {
|
||||
fulfillment_options: FulfillmentOption[]
|
||||
}
|
||||
|
||||
export * from "./add-country"
|
||||
export * from "./add-fulfillment-provider"
|
||||
export * from "./add-payment-provider"
|
||||
export * from "./create-region"
|
||||
export * from "./list-regions"
|
||||
export * from "./update-region"
|
||||
export * from "./create-region"
|
||||
export * from "./add-country"
|
||||
export * from "./add-payment-provider"
|
||||
export * from "./add-fulfillment-provider"
|
||||
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import { FlagRouter } from "@medusajs/utils"
|
||||
import { Router } from "express"
|
||||
import { ShippingOption } from "../../../.."
|
||||
import TaxInclusivePricingFeatureFlag from "../../../../loaders/feature-flags/tax-inclusive-pricing"
|
||||
import { DeleteResponse, PaginatedResponse } from "../../../../types/common"
|
||||
import middlewares from "../../../middlewares"
|
||||
import { FlagRouter } from "../../../../utils/flag-router"
|
||||
import TaxInclusivePricingFeatureFlag from "../../../../loaders/feature-flags/tax-inclusive-pricing"
|
||||
|
||||
const route = Router()
|
||||
|
||||
@@ -139,3 +139,4 @@ export * from "./delete-shipping-option"
|
||||
export * from "./get-shipping-option"
|
||||
export * from "./list-shipping-options"
|
||||
export * from "./update-shipping-option"
|
||||
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
import { ModulesHelper } from "@medusajs/modules-sdk"
|
||||
import { FlagRouter } from "@medusajs/utils"
|
||||
import { defaultRelationsExtended } from "."
|
||||
import {
|
||||
FulfillmentProviderService,
|
||||
PaymentProviderService,
|
||||
StoreService,
|
||||
FulfillmentProviderService,
|
||||
PaymentProviderService,
|
||||
StoreService,
|
||||
} from "../../../../services"
|
||||
import { ExtendedStoreDTO } from "../../../../types/store"
|
||||
import { FlagRouter } from "../../../../utils/flag-router"
|
||||
|
||||
/**
|
||||
* @oas [get] /admin/store
|
||||
|
||||
@@ -17,6 +17,7 @@ import reqIp from "request-ip"
|
||||
import { EntityManager } from "typeorm"
|
||||
|
||||
import { Logger } from "@medusajs/types"
|
||||
import { FlagRouter } from "@medusajs/utils"
|
||||
import { defaultStoreCartFields, defaultStoreCartRelations } from "."
|
||||
import SalesChannelFeatureFlag from "../../../../loaders/feature-flags/sales-channels"
|
||||
import { Cart, LineItem } from "../../../../models"
|
||||
@@ -28,7 +29,6 @@ import {
|
||||
import { CartCreateProps } from "../../../../types/cart"
|
||||
import { cleanResponseData } from "../../../../utils/clean-response-data"
|
||||
import { FeatureFlagDecorators } from "../../../../utils/feature-flag-decorators"
|
||||
import { FlagRouter } from "../../../../utils/flag-router"
|
||||
|
||||
/**
|
||||
* @oas [post] /store/carts
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import { FlagRouter } from "@medusajs/utils"
|
||||
import { AwilixContainer } from "awilix"
|
||||
import { EntityManager } from "typeorm"
|
||||
import { Cart } from "../../../../../../models"
|
||||
import { CartService, LineItemService } from "../../../../../../services"
|
||||
import { WithRequiredProperty } from "../../../../../../types/common"
|
||||
import { IdempotencyCallbackResult } from "../../../../../../types/idempotency-key"
|
||||
import { FlagRouter } from "../../../../../../utils/flag-router"
|
||||
import { defaultStoreCartFields, defaultStoreCartRelations } from "../../index"
|
||||
|
||||
export const CreateLineItemSteps = {
|
||||
|
||||
@@ -2,17 +2,17 @@ import "reflect-metadata"
|
||||
|
||||
import middlewares, { transformStoreQuery } from "../../../middlewares"
|
||||
|
||||
import { FlagRouter } from "../../../../utils/flag-router"
|
||||
import { FlagRouter } from "@medusajs/utils"
|
||||
import { Router } from "express"
|
||||
import { Product } from "../../../.."
|
||||
import { PaginatedResponse } from "../../../../types/common"
|
||||
import { PricedProduct } from "../../../../types/pricing"
|
||||
import { Product } from "../../../.."
|
||||
import { Router } from "express"
|
||||
import { StoreGetProductsParams } from "./list-products"
|
||||
import { StoreGetProductsProductParams } from "./get-product"
|
||||
import { extendRequestParams } from "../../../middlewares/publishable-api-key/extend-request-params"
|
||||
import { validateProductSalesChannelAssociation } from "../../../middlewares/publishable-api-key/validate-product-sales-channel-association"
|
||||
import { validateSalesChannelParam } from "../../../middlewares/publishable-api-key/validate-sales-channel-param"
|
||||
import { withDefaultSalesChannel } from "../../../middlewares/with-default-sales-channel"
|
||||
import { StoreGetProductsProductParams } from "./get-product"
|
||||
import { StoreGetProductsParams } from "./list-products"
|
||||
|
||||
const route = Router()
|
||||
|
||||
|
||||
@@ -1,31 +1,31 @@
|
||||
import {
|
||||
BaseFulfillmentService,
|
||||
BaseNotificationService,
|
||||
BasePaymentService,
|
||||
} from "medusa-interfaces"
|
||||
import { currencies } from "../utils/currencies"
|
||||
import { countries } from "../utils/countries"
|
||||
import { FlagRouter } from "@medusajs/utils"
|
||||
import { AwilixContainer } from "awilix"
|
||||
import { Logger } from "../types/global"
|
||||
import {
|
||||
BaseFulfillmentService,
|
||||
BaseNotificationService,
|
||||
BasePaymentService,
|
||||
} from "medusa-interfaces"
|
||||
import { EntityManager } from "typeorm"
|
||||
import { CountryRepository } from "../repositories/country"
|
||||
import {
|
||||
FulfillmentProviderService,
|
||||
NotificationService,
|
||||
PaymentProviderService,
|
||||
SalesChannelService,
|
||||
ShippingProfileService,
|
||||
StoreService,
|
||||
TaxProviderService,
|
||||
} from "../services"
|
||||
import { CurrencyRepository } from "../repositories/currency"
|
||||
import { FlagRouter } from "../utils/flag-router"
|
||||
import SalesChannelFeatureFlag from "./feature-flags/sales-channels"
|
||||
import {
|
||||
AbstractPaymentProcessor,
|
||||
AbstractPaymentService,
|
||||
AbstractTaxService,
|
||||
AbstractPaymentProcessor,
|
||||
AbstractPaymentService,
|
||||
AbstractTaxService,
|
||||
} from "../interfaces"
|
||||
import { CountryRepository } from "../repositories/country"
|
||||
import { CurrencyRepository } from "../repositories/currency"
|
||||
import {
|
||||
FulfillmentProviderService,
|
||||
NotificationService,
|
||||
PaymentProviderService,
|
||||
SalesChannelService,
|
||||
ShippingProfileService,
|
||||
StoreService,
|
||||
TaxProviderService,
|
||||
} from "../services"
|
||||
import { Logger } from "../types/global"
|
||||
import { countries } from "../utils/countries"
|
||||
import { currencies } from "../utils/currencies"
|
||||
import SalesChannelFeatureFlag from "./feature-flags/sales-channels"
|
||||
|
||||
const silentResolution = <T>(
|
||||
container: AwilixContainer,
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
import { FlagRouter } from "@medusajs/utils"
|
||||
import { asClass, asValue, createContainer } from "awilix"
|
||||
import { IdMap, MockManager } from "medusa-test-utils"
|
||||
import { taxProviderServiceMock } from "../__mocks__/tax-provider"
|
||||
import { FlagRouter } from "../../utils/flag-router"
|
||||
import {
|
||||
GiftCard,
|
||||
LineItem,
|
||||
LineItemTaxLine,
|
||||
ShippingMethod,
|
||||
ShippingMethodTaxLine,
|
||||
GiftCard,
|
||||
LineItem,
|
||||
LineItemTaxLine,
|
||||
ShippingMethod,
|
||||
ShippingMethodTaxLine,
|
||||
} from "../../models"
|
||||
import TaxCalculationStrategy from "../../strategies/tax-calculation"
|
||||
import { taxProviderServiceMock } from "../__mocks__/tax-provider"
|
||||
|
||||
export const defaultContainerMock = createContainer()
|
||||
defaultContainerMock.register("manager", asValue(MockManager))
|
||||
|
||||
@@ -1,18 +1,18 @@
|
||||
import { FlagRouter } from "@medusajs/utils"
|
||||
import { asClass, asFunction, asValue, createContainer } from "awilix"
|
||||
import { MockManager, MockRepository } from "medusa-test-utils"
|
||||
import PaymentProviderService from "../payment-provider"
|
||||
import { PaymentProviderServiceMock } from "../__mocks__/payment-provider"
|
||||
import { CustomerServiceMock } from "../__mocks__/customer"
|
||||
import { FlagRouter } from "../../utils/flag-router"
|
||||
import Logger from "../../loaders/logger"
|
||||
import {
|
||||
AbstractPaymentProcessor,
|
||||
PaymentProcessorContext,
|
||||
PaymentProcessorError,
|
||||
PaymentProcessorSessionResponse,
|
||||
AbstractPaymentProcessor,
|
||||
PaymentProcessorContext,
|
||||
PaymentProcessorError,
|
||||
PaymentProcessorSessionResponse,
|
||||
} from "../../interfaces"
|
||||
import Logger from "../../loaders/logger"
|
||||
import { PaymentSessionStatus } from "../../models"
|
||||
import { CustomerServiceMock } from "../__mocks__/customer"
|
||||
import { PaymentServiceMock } from "../__mocks__/payment"
|
||||
import { PaymentProviderServiceMock } from "../__mocks__/payment-provider"
|
||||
import PaymentProviderService from "../payment-provider"
|
||||
|
||||
export const defaultContainer = createContainer()
|
||||
defaultContainer.register(
|
||||
|
||||
@@ -2,7 +2,7 @@ import _ from "lodash"
|
||||
import { asClass, asValue, createContainer } from "awilix"
|
||||
import { MedusaError } from "medusa-core-utils"
|
||||
import { IdMap, MockManager, MockRepository } from "medusa-test-utils"
|
||||
import { FlagRouter } from "../../utils/flag-router"
|
||||
import { FlagRouter } from "@medusajs/utils"
|
||||
import CartService from "../cart"
|
||||
import { ProductVariantInventoryServiceMock } from "../__mocks__/product-variant-inventory"
|
||||
import { LineItemAdjustmentServiceMock } from "../__mocks__/line-item-adjustment"
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { FlagRouter } from "@medusajs/utils"
|
||||
import { IdMap, MockManager, MockRepository } from "medusa-test-utils"
|
||||
import TaxInclusivePricingFeatureFlag from "../../loaders/feature-flags/tax-inclusive-pricing"
|
||||
import { Currency } from "../../models"
|
||||
import { FlagRouter } from "../../utils/flag-router"
|
||||
import CurrencyService from "../currency"
|
||||
import EventBusService from "../event-bus"
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { IdMap, MockManager, MockRepository } from "medusa-test-utils"
|
||||
import { FlagRouter } from "../../utils/flag-router"
|
||||
import { FlagRouter } from "@medusajs/utils"
|
||||
import DiscountService from "../discount"
|
||||
import { TotalsServiceMock } from "../__mocks__/totals"
|
||||
import { newTotalsServiceMock } from "../__mocks__/new-totals"
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { IdMap, MockManager, MockRepository } from "medusa-test-utils"
|
||||
import { FlagRouter } from "../../utils/flag-router"
|
||||
import { FlagRouter } from "@medusajs/utils"
|
||||
import LineItemService from "../line-item"
|
||||
import { PricingServiceMock } from "../__mocks__/pricing"
|
||||
import { ProductVariantServiceMock } from "../__mocks__/product-variant"
|
||||
|
||||
@@ -1,24 +1,24 @@
|
||||
import { FlagRouter } from "@medusajs/utils"
|
||||
import { asClass, asValue, createContainer } from "awilix"
|
||||
import {
|
||||
defaultContainerMock,
|
||||
giftCards,
|
||||
giftCardsWithTaxRate,
|
||||
lineItems,
|
||||
shippingMethods,
|
||||
} from "../__fixtures__/new-totals"
|
||||
import { NewTotalsService } from "../index"
|
||||
import { TaxCalculationContext } from "../../interfaces"
|
||||
import { taxProviderServiceMock } from "../__mocks__/tax-provider"
|
||||
import {
|
||||
Discount,
|
||||
DiscountRuleType,
|
||||
LineItem,
|
||||
ProductVariant,
|
||||
Region,
|
||||
ShippingMethod,
|
||||
} from "../../models"
|
||||
import { FlagRouter } from "../../utils/flag-router"
|
||||
import TaxInclusivePricingFeatureFlag from "../../loaders/feature-flags/tax-inclusive-pricing"
|
||||
import {
|
||||
Discount,
|
||||
DiscountRuleType,
|
||||
LineItem,
|
||||
ProductVariant,
|
||||
Region,
|
||||
ShippingMethod,
|
||||
} from "../../models"
|
||||
import {
|
||||
defaultContainerMock,
|
||||
giftCards,
|
||||
giftCardsWithTaxRate,
|
||||
lineItems,
|
||||
shippingMethods,
|
||||
} from "../__fixtures__/new-totals"
|
||||
import { taxProviderServiceMock } from "../__mocks__/tax-provider"
|
||||
import { NewTotalsService } from "../index"
|
||||
|
||||
describe("New totals service", () => {
|
||||
describe("Without [MEDUSA_FF_TAX_INCLUSIVE_PRICING]", () => {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { MedusaError } from "medusa-core-utils"
|
||||
import { IdMap, MockManager, MockRepository } from "medusa-test-utils"
|
||||
import { MoneyAmountRepository } from "../../repositories/money-amount"
|
||||
import { FlagRouter } from "../../utils/flag-router"
|
||||
import { FlagRouter } from "@medusajs/utils"
|
||||
import PriceListService from "../price-list"
|
||||
import { RegionServiceMock } from "../__mocks__/region"
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { IdMap, MockManager, MockRepository } from "medusa-test-utils"
|
||||
import ProductService from "../product"
|
||||
import { FlagRouter } from "../../utils/flag-router"
|
||||
import { FlagRouter } from "@medusajs/utils"
|
||||
|
||||
const eventBusService = {
|
||||
emit: jest.fn(),
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import { FlagRouter } from "@medusajs/utils"
|
||||
import { IdMap, MockManager, MockRepository } from "medusa-test-utils"
|
||||
import { CreateRegionInput } from "../../types/region"
|
||||
import { FlagRouter } from "../../utils/flag-router"
|
||||
import EventBusService from "../event-bus"
|
||||
import {
|
||||
FulfillmentProviderService,
|
||||
PaymentProviderService,
|
||||
StoreService,
|
||||
FulfillmentProviderService,
|
||||
PaymentProviderService,
|
||||
StoreService,
|
||||
} from "../index"
|
||||
import RegionService from "../region"
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { IdMap, MockManager, MockRepository } from "medusa-test-utils"
|
||||
import TaxInclusivePricingFeatureFlag from "../../loaders/feature-flags/tax-inclusive-pricing"
|
||||
import { FlagRouter } from "../../utils/flag-router"
|
||||
import { FlagRouter } from "@medusajs/utils"
|
||||
import ShippingOptionService from "../shipping-option"
|
||||
|
||||
describe("ShippingOptionService", () => {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { IdMap } from "medusa-test-utils"
|
||||
import TotalsService from "../totals"
|
||||
import { FlagRouter } from "../../utils/flag-router"
|
||||
import { FlagRouter } from "@medusajs/utils"
|
||||
|
||||
import TaxInclusivePricingFeatureFlag from "../../loaders/feature-flags/tax-inclusive-pricing"
|
||||
import { calculatePriceTaxAmount } from "../../utils"
|
||||
|
||||
@@ -1,41 +1,42 @@
|
||||
import { FlagRouter } from "@medusajs/utils"
|
||||
import { isEmpty, isEqual } from "lodash"
|
||||
import { isDefined, MedusaError } from "medusa-core-utils"
|
||||
import { MedusaError, isDefined } from "medusa-core-utils"
|
||||
import { DeepPartial, EntityManager, In, IsNull, Not } from "typeorm"
|
||||
import {
|
||||
CustomerService,
|
||||
CustomShippingOptionService,
|
||||
DiscountService,
|
||||
EventBusService,
|
||||
GiftCardService,
|
||||
LineItemAdjustmentService,
|
||||
LineItemService,
|
||||
NewTotalsService,
|
||||
PaymentProviderService,
|
||||
ProductService,
|
||||
ProductVariantInventoryService,
|
||||
ProductVariantService,
|
||||
RegionService,
|
||||
SalesChannelService,
|
||||
ShippingOptionService,
|
||||
StoreService,
|
||||
TaxProviderService,
|
||||
TotalsService,
|
||||
CustomShippingOptionService,
|
||||
CustomerService,
|
||||
DiscountService,
|
||||
EventBusService,
|
||||
GiftCardService,
|
||||
LineItemAdjustmentService,
|
||||
LineItemService,
|
||||
NewTotalsService,
|
||||
PaymentProviderService,
|
||||
ProductService,
|
||||
ProductVariantInventoryService,
|
||||
ProductVariantService,
|
||||
RegionService,
|
||||
SalesChannelService,
|
||||
ShippingOptionService,
|
||||
StoreService,
|
||||
TaxProviderService,
|
||||
TotalsService,
|
||||
} from "."
|
||||
import { IPriceSelectionStrategy, TransactionBaseService } from "../interfaces"
|
||||
import SalesChannelFeatureFlag from "../loaders/feature-flags/sales-channels"
|
||||
import {
|
||||
Address,
|
||||
Cart,
|
||||
Customer,
|
||||
CustomShippingOption,
|
||||
Discount,
|
||||
DiscountRule,
|
||||
DiscountRuleType,
|
||||
LineItem,
|
||||
PaymentSession,
|
||||
PaymentSessionStatus,
|
||||
SalesChannel,
|
||||
ShippingMethod,
|
||||
Address,
|
||||
Cart,
|
||||
CustomShippingOption,
|
||||
Customer,
|
||||
Discount,
|
||||
DiscountRule,
|
||||
DiscountRuleType,
|
||||
LineItem,
|
||||
PaymentSession,
|
||||
PaymentSessionStatus,
|
||||
SalesChannel,
|
||||
ShippingMethod,
|
||||
} from "../models"
|
||||
import { AddressRepository } from "../repositories/address"
|
||||
import { CartRepository } from "../repositories/cart"
|
||||
@@ -43,22 +44,21 @@ import { LineItemRepository } from "../repositories/line-item"
|
||||
import { PaymentSessionRepository } from "../repositories/payment-session"
|
||||
import { ShippingMethodRepository } from "../repositories/shipping-method"
|
||||
import {
|
||||
CartCreateProps,
|
||||
CartUpdateProps,
|
||||
FilterableCartProps,
|
||||
isCart,
|
||||
LineItemUpdate,
|
||||
LineItemValidateData,
|
||||
CartCreateProps,
|
||||
CartUpdateProps,
|
||||
FilterableCartProps,
|
||||
LineItemUpdate,
|
||||
LineItemValidateData,
|
||||
isCart,
|
||||
} from "../types/cart"
|
||||
import {
|
||||
AddressPayload,
|
||||
FindConfig,
|
||||
TotalField,
|
||||
WithRequiredProperty,
|
||||
AddressPayload,
|
||||
FindConfig,
|
||||
TotalField,
|
||||
WithRequiredProperty,
|
||||
} from "../types/common"
|
||||
import { PaymentSessionInput } from "../types/payment"
|
||||
import { buildQuery, isString, setMetadata } from "../utils"
|
||||
import { FlagRouter } from "../utils/flag-router"
|
||||
import { validateEmail } from "../utils/is-email"
|
||||
|
||||
type InjectedDependencies = {
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { FlagRouter } from "@medusajs/utils"
|
||||
import { MedusaError } from "medusa-core-utils"
|
||||
import { EntityManager } from "typeorm"
|
||||
import { TransactionBaseService } from "../interfaces"
|
||||
@@ -7,7 +8,6 @@ import { CurrencyRepository } from "../repositories/currency"
|
||||
import { FindConfig, Selector } from "../types/common"
|
||||
import { UpdateCurrencyInput } from "../types/currency"
|
||||
import { buildQuery } from "../utils"
|
||||
import { FlagRouter } from "../utils/flag-router"
|
||||
import EventBusService from "./event-bus"
|
||||
|
||||
type InjectedDependencies = {
|
||||
|
||||
@@ -1,32 +1,33 @@
|
||||
import { FlagRouter } from "@medusajs/utils"
|
||||
import { parse, toSeconds } from "iso8601-duration"
|
||||
import { isEmpty, omit } from "lodash"
|
||||
import { MedusaError, isDefined } from "medusa-core-utils"
|
||||
import {
|
||||
DeepPartial,
|
||||
EntityManager,
|
||||
FindOptionsWhere,
|
||||
ILike,
|
||||
In,
|
||||
DeepPartial,
|
||||
EntityManager,
|
||||
FindOptionsWhere,
|
||||
ILike,
|
||||
In,
|
||||
} from "typeorm"
|
||||
import {
|
||||
NewTotalsService,
|
||||
ProductService,
|
||||
RegionService,
|
||||
TotalsService,
|
||||
NewTotalsService,
|
||||
ProductService,
|
||||
RegionService,
|
||||
TotalsService,
|
||||
} from "."
|
||||
import { TransactionBaseService } from "../interfaces"
|
||||
import TaxInclusivePricingFeatureFlag from "../loaders/feature-flags/tax-inclusive-pricing"
|
||||
import {
|
||||
Cart,
|
||||
Discount,
|
||||
DiscountConditionType,
|
||||
LineItem,
|
||||
Region,
|
||||
Cart,
|
||||
Discount,
|
||||
DiscountConditionType,
|
||||
LineItem,
|
||||
Region,
|
||||
} from "../models"
|
||||
import {
|
||||
AllocationType as DiscountAllocation,
|
||||
DiscountRule,
|
||||
DiscountRuleType,
|
||||
AllocationType as DiscountAllocation,
|
||||
DiscountRule,
|
||||
DiscountRuleType,
|
||||
} from "../models/discount-rule"
|
||||
import { DiscountRepository } from "../repositories/discount"
|
||||
import { DiscountConditionRepository } from "../repositories/discount-condition"
|
||||
@@ -34,17 +35,16 @@ import { DiscountRuleRepository } from "../repositories/discount-rule"
|
||||
import { GiftCardRepository } from "../repositories/gift-card"
|
||||
import { FindConfig, Selector } from "../types/common"
|
||||
import {
|
||||
CreateDiscountInput,
|
||||
CreateDiscountRuleInput,
|
||||
CreateDynamicDiscountInput,
|
||||
FilterableDiscountProps,
|
||||
UpdateDiscountInput,
|
||||
UpdateDiscountRuleInput,
|
||||
CreateDiscountInput,
|
||||
CreateDiscountRuleInput,
|
||||
CreateDynamicDiscountInput,
|
||||
FilterableDiscountProps,
|
||||
UpdateDiscountInput,
|
||||
UpdateDiscountRuleInput,
|
||||
} from "../types/discount"
|
||||
import { CalculationContextData } from "../types/totals"
|
||||
import { buildQuery, setMetadata } from "../utils"
|
||||
import { isFuture, isPast } from "../utils/date-helpers"
|
||||
import { FlagRouter } from "../utils/flag-router"
|
||||
import CustomerService from "./customer"
|
||||
import DiscountConditionService from "./discount-condition"
|
||||
import EventBusService from "./event-bus"
|
||||
|
||||
@@ -2,13 +2,14 @@ import { MedusaError } from "medusa-core-utils"
|
||||
import { EntityManager, In } from "typeorm"
|
||||
import { DeepPartial } from "typeorm/common/DeepPartial"
|
||||
|
||||
import { FlagRouter } from "@medusajs/utils"
|
||||
import { TransactionBaseService } from "../interfaces"
|
||||
import TaxInclusivePricingFeatureFlag from "../loaders/feature-flags/tax-inclusive-pricing"
|
||||
import {
|
||||
LineItem,
|
||||
LineItemAdjustment,
|
||||
LineItemTaxLine,
|
||||
ProductVariant,
|
||||
LineItem,
|
||||
LineItemAdjustment,
|
||||
LineItemTaxLine,
|
||||
ProductVariant,
|
||||
} from "../models"
|
||||
import { CartRepository } from "../repositories/cart"
|
||||
import { LineItemRepository } from "../repositories/line-item"
|
||||
@@ -17,13 +18,12 @@ import { FindConfig, Selector } from "../types/common"
|
||||
import { GenerateInputData, GenerateLineItemContext } from "../types/line-item"
|
||||
import { ProductVariantPricing } from "../types/pricing"
|
||||
import { buildQuery, isString, setMetadata } from "../utils"
|
||||
import { FlagRouter } from "../utils/flag-router"
|
||||
import {
|
||||
PricingService,
|
||||
ProductService,
|
||||
ProductVariantService,
|
||||
RegionService,
|
||||
TaxProviderService,
|
||||
PricingService,
|
||||
ProductService,
|
||||
ProductVariantService,
|
||||
RegionService,
|
||||
TaxProviderService,
|
||||
} from "./index"
|
||||
import LineItemAdjustmentService from "./line-item-adjustment"
|
||||
|
||||
|
||||
@@ -1,25 +1,25 @@
|
||||
import {
|
||||
ITaxCalculationStrategy,
|
||||
TaxCalculationContext,
|
||||
TransactionBaseService,
|
||||
} from "../interfaces"
|
||||
import { FlagRouter } from "@medusajs/utils"
|
||||
import { MedusaError, isDefined } from "medusa-core-utils"
|
||||
import { EntityManager } from "typeorm"
|
||||
import {
|
||||
Discount,
|
||||
DiscountRuleType,
|
||||
GiftCard,
|
||||
LineItem,
|
||||
LineItemTaxLine,
|
||||
Region,
|
||||
ShippingMethod,
|
||||
ShippingMethodTaxLine,
|
||||
} from "../models"
|
||||
import { TaxProviderService } from "./index"
|
||||
import { LineAllocationsMap } from "../types/totals"
|
||||
ITaxCalculationStrategy,
|
||||
TaxCalculationContext,
|
||||
TransactionBaseService,
|
||||
} from "../interfaces"
|
||||
import TaxInclusivePricingFeatureFlag from "../loaders/feature-flags/tax-inclusive-pricing"
|
||||
import { FlagRouter } from "../utils/flag-router"
|
||||
import {
|
||||
Discount,
|
||||
DiscountRuleType,
|
||||
GiftCard,
|
||||
LineItem,
|
||||
LineItemTaxLine,
|
||||
Region,
|
||||
ShippingMethod,
|
||||
ShippingMethodTaxLine,
|
||||
} from "../models"
|
||||
import { LineAllocationsMap } from "../types/totals"
|
||||
import { calculatePriceTaxAmount } from "../utils"
|
||||
import { isDefined, MedusaError } from "medusa-core-utils"
|
||||
import { TaxProviderService } from "./index"
|
||||
|
||||
type LineItemTotals = {
|
||||
unit_price: number
|
||||
|
||||
@@ -1,67 +1,67 @@
|
||||
import { IInventoryService } from "@medusajs/types"
|
||||
import {
|
||||
buildRelations,
|
||||
buildSelects,
|
||||
isDefined,
|
||||
MedusaError,
|
||||
buildRelations,
|
||||
buildSelects,
|
||||
FlagRouter,
|
||||
isDefined,
|
||||
MedusaError,
|
||||
} from "@medusajs/utils"
|
||||
import {
|
||||
EntityManager,
|
||||
FindManyOptions,
|
||||
FindOptionsWhere,
|
||||
ILike,
|
||||
IsNull,
|
||||
Not,
|
||||
Raw,
|
||||
EntityManager,
|
||||
FindManyOptions,
|
||||
FindOptionsWhere,
|
||||
ILike,
|
||||
IsNull,
|
||||
Not,
|
||||
Raw,
|
||||
} from "typeorm"
|
||||
import {
|
||||
CartService,
|
||||
CustomerService,
|
||||
DiscountService,
|
||||
DraftOrderService,
|
||||
FulfillmentProviderService,
|
||||
FulfillmentService,
|
||||
GiftCardService,
|
||||
LineItemService,
|
||||
NewTotalsService,
|
||||
PaymentProviderService,
|
||||
ProductVariantInventoryService,
|
||||
RegionService,
|
||||
ShippingOptionService,
|
||||
ShippingProfileService,
|
||||
TaxProviderService,
|
||||
TotalsService,
|
||||
CartService,
|
||||
CustomerService,
|
||||
DiscountService,
|
||||
DraftOrderService,
|
||||
FulfillmentProviderService,
|
||||
FulfillmentService,
|
||||
GiftCardService,
|
||||
LineItemService,
|
||||
NewTotalsService,
|
||||
PaymentProviderService,
|
||||
ProductVariantInventoryService,
|
||||
RegionService,
|
||||
ShippingOptionService,
|
||||
ShippingProfileService,
|
||||
TaxProviderService,
|
||||
TotalsService,
|
||||
} from "."
|
||||
import { TransactionBaseService } from "../interfaces"
|
||||
import SalesChannelFeatureFlag from "../loaders/feature-flags/sales-channels"
|
||||
import {
|
||||
Address,
|
||||
Cart,
|
||||
ClaimOrder,
|
||||
Fulfillment,
|
||||
FulfillmentItem,
|
||||
FulfillmentStatus,
|
||||
GiftCard,
|
||||
LineItem,
|
||||
Order,
|
||||
OrderStatus,
|
||||
Payment,
|
||||
PaymentStatus,
|
||||
Return,
|
||||
Swap,
|
||||
TrackingLink,
|
||||
Address,
|
||||
Cart,
|
||||
ClaimOrder,
|
||||
Fulfillment,
|
||||
FulfillmentItem,
|
||||
FulfillmentStatus,
|
||||
GiftCard,
|
||||
LineItem,
|
||||
Order,
|
||||
OrderStatus,
|
||||
Payment,
|
||||
PaymentStatus,
|
||||
Return,
|
||||
Swap,
|
||||
TrackingLink,
|
||||
} from "../models"
|
||||
import { TransactionBaseService } from "../interfaces"
|
||||
import { AddressRepository } from "../repositories/address"
|
||||
import { OrderRepository } from "../repositories/order"
|
||||
import { FindConfig, QuerySelector, Selector } from "../types/common"
|
||||
import {
|
||||
CreateFulfillmentOrder,
|
||||
FulFillmentItemType,
|
||||
CreateFulfillmentOrder,
|
||||
FulFillmentItemType,
|
||||
} from "../types/fulfillment"
|
||||
import { TotalsContext, UpdateOrderInput } from "../types/orders"
|
||||
import { CreateShippingMethodDto } from "../types/shipping-options"
|
||||
import { buildQuery, isString, setMetadata } from "../utils"
|
||||
import { FlagRouter } from "../utils/flag-router"
|
||||
import EventBusService from "./event-bus"
|
||||
|
||||
export const ORDER_CART_ALREADY_EXISTS_ERROR = "Order from cart already exists"
|
||||
|
||||
@@ -1,22 +1,24 @@
|
||||
import { FlagRouter } from "@medusajs/utils"
|
||||
import { isDefined, MedusaError } from "medusa-core-utils"
|
||||
import { BasePaymentService } from "medusa-interfaces"
|
||||
import { EOL } from "os"
|
||||
import { EntityManager } from "typeorm"
|
||||
import {
|
||||
AbstractPaymentProcessor,
|
||||
AbstractPaymentService,
|
||||
isPaymentProcessorError,
|
||||
PaymentContext,
|
||||
PaymentProcessorError,
|
||||
PaymentSessionResponse,
|
||||
TransactionBaseService,
|
||||
AbstractPaymentProcessor,
|
||||
AbstractPaymentService,
|
||||
isPaymentProcessorError,
|
||||
PaymentContext,
|
||||
PaymentProcessorError,
|
||||
PaymentSessionResponse,
|
||||
TransactionBaseService,
|
||||
} from "../interfaces"
|
||||
import {
|
||||
Cart,
|
||||
Payment,
|
||||
PaymentProvider,
|
||||
PaymentSession,
|
||||
PaymentSessionStatus,
|
||||
Refund,
|
||||
Cart,
|
||||
Payment,
|
||||
PaymentProvider,
|
||||
PaymentSession,
|
||||
PaymentSessionStatus,
|
||||
Refund,
|
||||
} from "../models"
|
||||
import { PaymentRepository } from "../repositories/payment"
|
||||
import { PaymentProviderRepository } from "../repositories/payment-provider"
|
||||
@@ -26,10 +28,8 @@ import { FindConfig, Selector } from "../types/common"
|
||||
import { Logger } from "../types/global"
|
||||
import { CreatePaymentInput, PaymentSessionInput } from "../types/payment"
|
||||
import { buildQuery, isString } from "../utils"
|
||||
import { FlagRouter } from "../utils/flag-router"
|
||||
import { CustomerService } from "./index"
|
||||
import PaymentService from "./payment"
|
||||
import { EOL } from "os"
|
||||
|
||||
type PaymentProviderKey = `pp_${string}` | "systemPaymentProviderService"
|
||||
type InjectedDependencies = {
|
||||
|
||||
@@ -1,27 +1,27 @@
|
||||
import { FlagRouter } from "@medusajs/utils"
|
||||
import { isDefined, MedusaError } from "medusa-core-utils"
|
||||
import { DeepPartial, EntityManager } from "typeorm"
|
||||
import { CustomerGroupService } from "."
|
||||
import { TransactionBaseService } from "../interfaces"
|
||||
import TaxInclusivePricingFeatureFlag from "../loaders/feature-flags/tax-inclusive-pricing"
|
||||
import { CustomerGroup, PriceList, Product, ProductVariant } from "../models"
|
||||
import { MoneyAmountRepository } from "../repositories/money-amount"
|
||||
import { PriceListRepository } from "../repositories/price-list"
|
||||
import { ProductVariantRepository } from "../repositories/product-variant"
|
||||
import { FindConfig, Selector } from "../types/common"
|
||||
import {
|
||||
CreatePriceListInput,
|
||||
FilterablePriceListProps,
|
||||
PriceListPriceCreateInput,
|
||||
PriceListPriceUpdateInput,
|
||||
UpdatePriceListInput,
|
||||
CreatePriceListInput,
|
||||
FilterablePriceListProps,
|
||||
PriceListPriceCreateInput,
|
||||
PriceListPriceUpdateInput,
|
||||
UpdatePriceListInput,
|
||||
} from "../types/price-list"
|
||||
import ProductService from "./product"
|
||||
import RegionService from "./region"
|
||||
import { TransactionBaseService } from "../interfaces"
|
||||
import { buildQuery } from "../utils"
|
||||
import { FilterableProductProps } from "../types/product"
|
||||
import ProductVariantService from "./product-variant"
|
||||
import { FilterableProductVariantProps } from "../types/product-variant"
|
||||
import { ProductVariantRepository } from "../repositories/product-variant"
|
||||
import { FlagRouter } from "../utils/flag-router"
|
||||
import TaxInclusivePricingFeatureFlag from "../loaders/feature-flags/tax-inclusive-pricing"
|
||||
import { buildQuery } from "../utils"
|
||||
import ProductService from "./product"
|
||||
import ProductVariantService from "./product-variant"
|
||||
import RegionService from "./region"
|
||||
|
||||
type PriceListConstructorProps = {
|
||||
manager: EntityManager
|
||||
|
||||
@@ -1,24 +1,24 @@
|
||||
import { FlagRouter } from "@medusajs/utils"
|
||||
import { MedusaError } from "medusa-core-utils"
|
||||
import { EntityManager } from "typeorm"
|
||||
import { ProductVariantService, RegionService, TaxProviderService } from "."
|
||||
import { TransactionBaseService } from "../interfaces"
|
||||
import {
|
||||
IPriceSelectionStrategy,
|
||||
PriceSelectionContext,
|
||||
IPriceSelectionStrategy,
|
||||
PriceSelectionContext,
|
||||
} from "../interfaces/price-selection-strategy"
|
||||
import TaxInclusivePricingFeatureFlag from "../loaders/feature-flags/tax-inclusive-pricing"
|
||||
import { Product, ProductVariant, Region, ShippingOption } from "../models"
|
||||
import {
|
||||
PricedProduct,
|
||||
PricedShippingOption,
|
||||
PricedVariant,
|
||||
PricingContext,
|
||||
ProductVariantPricing,
|
||||
TaxedPricing,
|
||||
PricedProduct,
|
||||
PricedShippingOption,
|
||||
PricedVariant,
|
||||
PricingContext,
|
||||
ProductVariantPricing,
|
||||
TaxedPricing,
|
||||
} from "../types/pricing"
|
||||
import { TaxServiceRate } from "../types/tax-service"
|
||||
import { calculatePriceTaxAmount } from "../utils"
|
||||
import { FlagRouter } from "../utils/flag-router"
|
||||
|
||||
type InjectedDependencies = {
|
||||
manager: EntityManager
|
||||
|
||||
@@ -1,22 +1,26 @@
|
||||
import {
|
||||
buildRelations,
|
||||
buildSelects, FlagRouter, objectToStringPath
|
||||
} from "@medusajs/utils"
|
||||
import { isDefined, MedusaError } from "medusa-core-utils"
|
||||
import { EntityManager, In } from "typeorm"
|
||||
import { ProductVariantService, SearchService } from "."
|
||||
import { TransactionBaseService } from "../interfaces"
|
||||
import SalesChannelFeatureFlag from "../loaders/feature-flags/sales-channels"
|
||||
import {
|
||||
Product,
|
||||
ProductCategory,
|
||||
ProductOption,
|
||||
ProductTag,
|
||||
ProductType,
|
||||
ProductVariant,
|
||||
SalesChannel,
|
||||
ShippingProfile,
|
||||
Product,
|
||||
ProductCategory,
|
||||
ProductOption,
|
||||
ProductTag,
|
||||
ProductType,
|
||||
ProductVariant,
|
||||
SalesChannel,
|
||||
ShippingProfile,
|
||||
} from "../models"
|
||||
import { ImageRepository } from "../repositories/image"
|
||||
import {
|
||||
FindWithoutRelationsOptions,
|
||||
ProductRepository,
|
||||
FindWithoutRelationsOptions,
|
||||
ProductRepository,
|
||||
} from "../repositories/product"
|
||||
import { ProductCategoryRepository } from "../repositories/product-category"
|
||||
import { ProductOptionRepository } from "../repositories/product-option"
|
||||
@@ -25,21 +29,15 @@ import { ProductTypeRepository } from "../repositories/product-type"
|
||||
import { ProductVariantRepository } from "../repositories/product-variant"
|
||||
import { Selector } from "../types/common"
|
||||
import {
|
||||
CreateProductInput,
|
||||
FilterableProductProps,
|
||||
FindProductConfig,
|
||||
ProductOptionInput,
|
||||
ProductSelector,
|
||||
UpdateProductInput,
|
||||
CreateProductInput,
|
||||
FilterableProductProps,
|
||||
FindProductConfig,
|
||||
ProductOptionInput,
|
||||
ProductSelector,
|
||||
UpdateProductInput,
|
||||
} from "../types/product"
|
||||
import { buildQuery, isString, setMetadata } from "../utils"
|
||||
import { FlagRouter } from "../utils/flag-router"
|
||||
import EventBusService from "./event-bus"
|
||||
import {
|
||||
buildRelations,
|
||||
buildSelects,
|
||||
objectToStringPath,
|
||||
} from "@medusajs/utils"
|
||||
|
||||
type InjectedDependencies = {
|
||||
manager: EntityManager
|
||||
|
||||
@@ -1,24 +1,24 @@
|
||||
import { Country, Currency, Region } from "../models"
|
||||
import { CreateRegionInput, UpdateRegionInput } from "../types/region"
|
||||
import { DeepPartial, EntityManager } from "typeorm"
|
||||
import { FindConfig, Selector } from "../types/common"
|
||||
import { MedusaError, isDefined } from "medusa-core-utils"
|
||||
import { DeepPartial, EntityManager } from "typeorm"
|
||||
import { Country, Currency, Region } from "../models"
|
||||
import { FindConfig, Selector } from "../types/common"
|
||||
import { CreateRegionInput, UpdateRegionInput } from "../types/region"
|
||||
import { buildQuery, setMetadata } from "../utils"
|
||||
|
||||
import { FlagRouter } from "@medusajs/utils"
|
||||
import { TransactionBaseService } from "../interfaces"
|
||||
import TaxInclusivePricingFeatureFlag from "../loaders/feature-flags/tax-inclusive-pricing"
|
||||
import { CountryRepository } from "../repositories/country"
|
||||
import { CurrencyRepository } from "../repositories/currency"
|
||||
import EventBusService from "./event-bus"
|
||||
import { FlagRouter } from "../utils/flag-router"
|
||||
import { FulfillmentProviderRepository } from "../repositories/fulfillment-provider"
|
||||
import FulfillmentProviderService from "./fulfillment-provider"
|
||||
import { PaymentProviderRepository } from "../repositories/payment-provider"
|
||||
import { PaymentProviderService } from "./index"
|
||||
import { RegionRepository } from "../repositories/region"
|
||||
import StoreService from "./store"
|
||||
import TaxInclusivePricingFeatureFlag from "../loaders/feature-flags/tax-inclusive-pricing"
|
||||
import { TaxProviderRepository } from "../repositories/tax-provider"
|
||||
import { TransactionBaseService } from "../interfaces"
|
||||
import { countries } from "../utils/countries"
|
||||
import EventBusService from "./event-bus"
|
||||
import FulfillmentProviderService from "./fulfillment-provider"
|
||||
import { PaymentProviderService } from "./index"
|
||||
import StoreService from "./store"
|
||||
|
||||
type InjectedDependencies = {
|
||||
manager: EntityManager
|
||||
|
||||
@@ -1,28 +1,28 @@
|
||||
import { FlagRouter } from "@medusajs/utils"
|
||||
import { isDefined, MedusaError } from "medusa-core-utils"
|
||||
import { EntityManager } from "typeorm"
|
||||
import { TransactionBaseService } from "../interfaces"
|
||||
import TaxInclusivePricingFeatureFlag from "../loaders/feature-flags/tax-inclusive-pricing"
|
||||
import {
|
||||
Cart,
|
||||
Order,
|
||||
ShippingMethod,
|
||||
ShippingOption,
|
||||
ShippingOptionPriceType,
|
||||
ShippingOptionRequirement,
|
||||
Cart,
|
||||
Order,
|
||||
ShippingMethod,
|
||||
ShippingOption,
|
||||
ShippingOptionPriceType,
|
||||
ShippingOptionRequirement,
|
||||
} from "../models"
|
||||
import { ShippingMethodRepository } from "../repositories/shipping-method"
|
||||
import { ShippingOptionRepository } from "../repositories/shipping-option"
|
||||
import { ShippingOptionRequirementRepository } from "../repositories/shipping-option-requirement"
|
||||
import { FindConfig, Selector } from "../types/common"
|
||||
import {
|
||||
CreateShippingMethodDto,
|
||||
CreateShippingOptionInput,
|
||||
ShippingMethodUpdate,
|
||||
UpdateShippingOptionInput,
|
||||
ValidatePriceTypeAndAmountInput,
|
||||
CreateShippingMethodDto,
|
||||
CreateShippingOptionInput,
|
||||
ShippingMethodUpdate,
|
||||
UpdateShippingOptionInput,
|
||||
ValidatePriceTypeAndAmountInput,
|
||||
} from "../types/shipping-options"
|
||||
import { buildQuery, isString, setMetadata } from "../utils"
|
||||
import { FlagRouter } from "../utils/flag-router"
|
||||
import FulfillmentProviderService from "./fulfillment-provider"
|
||||
import RegionService from "./region"
|
||||
|
||||
|
||||
@@ -1,36 +1,36 @@
|
||||
import { isDefined, MedusaError } from "@medusajs/utils"
|
||||
import { EntityManager } from "typeorm"
|
||||
import {
|
||||
ITaxCalculationStrategy,
|
||||
TaxCalculationContext,
|
||||
TransactionBaseService,
|
||||
ITaxCalculationStrategy,
|
||||
TaxCalculationContext,
|
||||
TransactionBaseService,
|
||||
} from "../interfaces"
|
||||
import {
|
||||
Cart,
|
||||
ClaimOrder,
|
||||
Discount,
|
||||
DiscountRuleType,
|
||||
LineItem,
|
||||
LineItemTaxLine,
|
||||
Order,
|
||||
ShippingMethod,
|
||||
ShippingMethodTaxLine,
|
||||
Swap,
|
||||
Cart,
|
||||
ClaimOrder,
|
||||
Discount,
|
||||
DiscountRuleType,
|
||||
LineItem,
|
||||
LineItemTaxLine,
|
||||
Order,
|
||||
ShippingMethod,
|
||||
ShippingMethodTaxLine,
|
||||
Swap,
|
||||
} from "../models"
|
||||
import { isCart } from "../types/cart"
|
||||
import { isOrder } from "../types/orders"
|
||||
import {
|
||||
CalculationContextData,
|
||||
LineAllocationsMap,
|
||||
LineDiscount,
|
||||
LineDiscountAmount,
|
||||
SubtotalOptions,
|
||||
CalculationContextData,
|
||||
LineAllocationsMap,
|
||||
LineDiscount,
|
||||
LineDiscountAmount,
|
||||
SubtotalOptions,
|
||||
} from "../types/totals"
|
||||
import { NewTotalsService, TaxProviderService } from "./index"
|
||||
|
||||
import { FlagRouter } from "@medusajs/utils"
|
||||
import TaxInclusivePricingFeatureFlag from "../loaders/feature-flags/tax-inclusive-pricing"
|
||||
import { calculatePriceTaxAmount } from "../utils"
|
||||
import { FlagRouter } from "../utils/flag-router"
|
||||
|
||||
type ShippingMethodTotals = {
|
||||
price: number
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { FlagRouter } from "@medusajs/utils"
|
||||
import jwt from "jsonwebtoken"
|
||||
import { isDefined, MedusaError } from "medusa-core-utils"
|
||||
import Scrypt from "scrypt-kdf"
|
||||
@@ -8,12 +9,11 @@ import { User } from "../models"
|
||||
import { UserRepository } from "../repositories/user"
|
||||
import { FindConfig } from "../types/common"
|
||||
import {
|
||||
CreateUserInput,
|
||||
FilterableUserProps,
|
||||
UpdateUserInput,
|
||||
CreateUserInput,
|
||||
FilterableUserProps,
|
||||
UpdateUserInput,
|
||||
} from "../types/user"
|
||||
import { buildQuery, setMetadata } from "../utils"
|
||||
import { FlagRouter } from "../utils/flag-router"
|
||||
import { validateEmail } from "../utils/is-email"
|
||||
import AnalyticsConfigService from "./analytics-config"
|
||||
import EventBusService from "./event-bus"
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import OrderExportStrategy from "../../../batch-jobs/order/export"
|
||||
import { FlagRouter } from "@medusajs/utils"
|
||||
import { IdMap, MockManager } from "medusa-test-utils"
|
||||
import SalesChannelFeatureFlag from "../../../../loaders/feature-flags/sales-channels"
|
||||
import { User } from "../../../../models"
|
||||
import { BatchJobStatus } from "../../../../types/batch-job"
|
||||
import { ordersToExport } from "../../../__fixtures__/order-export-data"
|
||||
import { FlagRouter } from "../../../../utils/flag-router";
|
||||
import SalesChannelFeatureFlag from "../../../../loaders/feature-flags/sales-channels";
|
||||
import OrderExportStrategy from "../../../batch-jobs/order/export"
|
||||
|
||||
const orderServiceMock = {
|
||||
withTransaction: function (): any {
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
import ProductExportStrategy from "../../../batch-jobs/product/export"
|
||||
import { FlagRouter } from "@medusajs/utils"
|
||||
import { Request } from "express"
|
||||
import { IdMap, MockManager } from "medusa-test-utils"
|
||||
import { AdminPostBatchesReq, defaultAdminProductRelations, } from "../../../../api"
|
||||
import SalesChannelFeatureFlag from "../../../../loaders/feature-flags/sales-channels"
|
||||
import { User } from "../../../../models"
|
||||
import { BatchJobStatus } from "../../../../types/batch-job"
|
||||
import { productsToExport } from "../../../__fixtures__/product-export-data"
|
||||
import { AdminPostBatchesReq, defaultAdminProductRelations, } from "../../../../api"
|
||||
import ProductExportStrategy from "../../../batch-jobs/product/export"
|
||||
import { ProductExportBatchJob } from "../../../batch-jobs/product/types"
|
||||
import { Request } from "express"
|
||||
import { FlagRouter } from "../../../../utils/flag-router"
|
||||
import SalesChannelFeatureFlag from "../../../../loaders/feature-flags/sales-channels"
|
||||
|
||||
const productServiceMock = {
|
||||
withTransaction: function () {
|
||||
|
||||
@@ -4,16 +4,16 @@ import { EntityManager } from "typeorm"
|
||||
import { FileService } from "medusa-interfaces"
|
||||
import { IdMap, MockManager } from "medusa-test-utils"
|
||||
|
||||
import { FlagRouter } from "@medusajs/utils"
|
||||
import { User } from "../../../../models"
|
||||
import {
|
||||
BatchJobService,
|
||||
ProductService,
|
||||
ProductVariantService,
|
||||
RegionService,
|
||||
ShippingProfileService,
|
||||
BatchJobService,
|
||||
ProductService,
|
||||
ProductVariantService,
|
||||
RegionService,
|
||||
ShippingProfileService,
|
||||
} from "../../../../services"
|
||||
import { BatchJobStatus } from "../../../../types/batch-job"
|
||||
import { FlagRouter } from "../../../../utils/flag-router"
|
||||
import ProductImportStrategy from "../../../batch-jobs/product/import"
|
||||
import { ProductImportInjectedProps } from "../../../batch-jobs/product/types"
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { FlagRouter } from "../../utils/flag-router"
|
||||
import { FlagRouter } from "@medusajs/utils"
|
||||
import PriceSelectionStrategy from "../price-selection"
|
||||
import { cacheServiceMock } from "../../services/__mocks__/cache"
|
||||
import TaxInclusivePricingFeatureFlag from "../../loaders/feature-flags/tax-inclusive-pricing"
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import TaxCalculationStrategy from "../tax-calculation"
|
||||
import TaxInclusivePricingFeatureFlag from "../../loaders/feature-flags/tax-inclusive-pricing"
|
||||
import { FlagRouter } from "../../utils/flag-router"
|
||||
import { FlagRouter } from "@medusajs/utils"
|
||||
|
||||
const toTest = [
|
||||
[
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
import { FlagRouter } from "@medusajs/utils"
|
||||
import { EntityManager } from "typeorm"
|
||||
import {
|
||||
OrderDescriptor,
|
||||
OrderExportBatchJob,
|
||||
OrderExportBatchJobContext,
|
||||
orderExportPropertiesDescriptors,
|
||||
OrderDescriptor,
|
||||
OrderExportBatchJob,
|
||||
OrderExportBatchJobContext,
|
||||
orderExportPropertiesDescriptors,
|
||||
} from "."
|
||||
import { AdminPostBatchesReq } from "../../../api"
|
||||
import { AbstractBatchJobStrategy, IFileService } from "../../../interfaces"
|
||||
@@ -13,7 +14,6 @@ import { OrderService } from "../../../services"
|
||||
import BatchJobService from "../../../services/batch-job"
|
||||
import { BatchJobStatus } from "../../../types/batch-job"
|
||||
import { FindConfig } from "../../../types/common"
|
||||
import { FlagRouter } from "../../../utils/flag-router"
|
||||
import { prepareListQuery } from "../../../utils/get-query-config"
|
||||
|
||||
type InjectedDependencies = {
|
||||
|
||||
@@ -2,29 +2,29 @@ import { EntityManager } from "typeorm"
|
||||
|
||||
import { humanizeAmount } from "medusa-core-utils"
|
||||
|
||||
import { FlagRouter } from "@medusajs/utils"
|
||||
import { defaultAdminProductRelations } from "../../../api"
|
||||
import { AbstractBatchJobStrategy, IFileService } from "../../../interfaces"
|
||||
import ProductCategoryFeatureFlag from "../../../loaders/feature-flags/product-categories"
|
||||
import SalesChannelFeatureFlag from "../../../loaders/feature-flags/sales-channels"
|
||||
import { Product, ProductVariant } from "../../../models"
|
||||
import { BatchJobService, ProductService } from "../../../services"
|
||||
import { BatchJobStatus, CreateBatchJobInput } from "../../../types/batch-job"
|
||||
import { defaultAdminProductRelations } from "../../../api"
|
||||
import { FindProductConfig } from "../../../types/product"
|
||||
import { csvCellContentFormatter } from "../../../utils"
|
||||
import { prepareListQuery } from "../../../utils/get-query-config"
|
||||
import {
|
||||
DynamicProductExportDescriptor,
|
||||
ProductExportBatchJob,
|
||||
ProductExportBatchJobContext,
|
||||
ProductExportInjectedDependencies,
|
||||
ProductExportPriceData,
|
||||
DynamicProductExportDescriptor,
|
||||
ProductExportBatchJob,
|
||||
ProductExportBatchJobContext,
|
||||
ProductExportInjectedDependencies,
|
||||
ProductExportPriceData,
|
||||
} from "./types"
|
||||
import { FindProductConfig } from "../../../types/product"
|
||||
import { FlagRouter } from "../../../utils/flag-router"
|
||||
import SalesChannelFeatureFlag from "../../../loaders/feature-flags/sales-channels"
|
||||
import { csvCellContentFormatter } from "../../../utils"
|
||||
import {
|
||||
productCategoriesColumnsDefinition,
|
||||
productColumnsDefinition,
|
||||
productSalesChannelColumnsDefinition,
|
||||
productCategoriesColumnsDefinition,
|
||||
productColumnsDefinition,
|
||||
productSalesChannelColumnsDefinition,
|
||||
} from "./types/columns-definition"
|
||||
import ProductCategoryFeatureFlag from "../../../loaders/feature-flags/product-categories"
|
||||
|
||||
export default class ProductExportStrategy extends AbstractBatchJobStrategy {
|
||||
public static identifier = "product-export-strategy"
|
||||
|
||||
@@ -2,38 +2,38 @@
|
||||
import { computerizeAmount, MedusaError } from "medusa-core-utils"
|
||||
import { EntityManager } from "typeorm"
|
||||
|
||||
import { FlagRouter } from "@medusajs/utils"
|
||||
import { AbstractBatchJobStrategy, IFileService } from "../../../interfaces"
|
||||
import ProductCategoryFeatureFlag from "../../../loaders/feature-flags/product-categories"
|
||||
import SalesChannelFeatureFlag from "../../../loaders/feature-flags/sales-channels"
|
||||
import { BatchJob, SalesChannel } from "../../../models"
|
||||
import {
|
||||
BatchJobService,
|
||||
ProductCategoryService,
|
||||
ProductCollectionService,
|
||||
ProductService,
|
||||
ProductVariantService,
|
||||
RegionService,
|
||||
SalesChannelService,
|
||||
ShippingProfileService,
|
||||
BatchJobService,
|
||||
ProductCategoryService,
|
||||
ProductCollectionService,
|
||||
ProductService,
|
||||
ProductVariantService,
|
||||
RegionService,
|
||||
SalesChannelService,
|
||||
ShippingProfileService,
|
||||
} from "../../../services"
|
||||
import CsvParser from "../../../services/csv-parser"
|
||||
import { CreateProductInput } from "../../../types/product"
|
||||
import { CreateProductVariantInput } from "../../../types/product-variant"
|
||||
import { FlagRouter } from "../../../utils/flag-router"
|
||||
import {
|
||||
OperationType,
|
||||
ProductImportBatchJob,
|
||||
ProductImportCsvSchema,
|
||||
ProductImportInjectedProps,
|
||||
ProductImportJobContext,
|
||||
TParsedProductImportRowData,
|
||||
OperationType,
|
||||
ProductImportBatchJob,
|
||||
ProductImportCsvSchema,
|
||||
ProductImportInjectedProps,
|
||||
ProductImportJobContext,
|
||||
TParsedProductImportRowData,
|
||||
} from "./types"
|
||||
import {
|
||||
productImportColumnsDefinition,
|
||||
productImportSalesChannelsColumnsDefinition,
|
||||
productImportProductCategoriesColumnsDefinition,
|
||||
productImportColumnsDefinition,
|
||||
productImportProductCategoriesColumnsDefinition,
|
||||
productImportSalesChannelsColumnsDefinition,
|
||||
} from "./types/columns-definition"
|
||||
import { transformProductData, transformVariantData } from "./utils"
|
||||
import ProductCategoryFeatureFlag from "../../../loaders/feature-flags/product-categories"
|
||||
|
||||
/**
|
||||
* Process this many variant rows before reporting progress.
|
||||
|
||||
@@ -1,20 +1,20 @@
|
||||
import { BatchJob, Product, ProductVariant } from "../../../../models"
|
||||
import { Selector } from "../../../../types/common"
|
||||
import { CsvSchema, CsvSchemaColumn } from "../../../../interfaces/csv-parser"
|
||||
import {
|
||||
BatchJobService,
|
||||
ProductCategoryService,
|
||||
ProductCollectionService,
|
||||
ProductService,
|
||||
ProductVariantService,
|
||||
RegionService,
|
||||
SalesChannelService,
|
||||
ShippingProfileService,
|
||||
} from "../../../../services"
|
||||
import { FlagRouter } from "@medusajs/utils"
|
||||
import { FileService } from "medusa-interfaces"
|
||||
import { FlagRouter } from "../../../../utils/flag-router"
|
||||
import { EntityManager } from "typeorm"
|
||||
import { IFileService } from "../../../../interfaces"
|
||||
import { CsvSchema, CsvSchemaColumn } from "../../../../interfaces/csv-parser"
|
||||
import { BatchJob, Product, ProductVariant } from "../../../../models"
|
||||
import {
|
||||
BatchJobService,
|
||||
ProductCategoryService,
|
||||
ProductCollectionService,
|
||||
ProductService,
|
||||
ProductVariantService,
|
||||
RegionService,
|
||||
SalesChannelService,
|
||||
ShippingProfileService,
|
||||
} from "../../../../services"
|
||||
import { Selector } from "../../../../types/common"
|
||||
|
||||
export type ProductExportInjectedDependencies = {
|
||||
manager: EntityManager
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
import {
|
||||
AbstractPriceSelectionStrategy,
|
||||
PriceSelectionContext,
|
||||
PriceSelectionResult,
|
||||
PriceType,
|
||||
AbstractPriceSelectionStrategy,
|
||||
PriceSelectionContext,
|
||||
PriceSelectionResult,
|
||||
PriceType,
|
||||
} from "../interfaces"
|
||||
|
||||
import { EntityManager } from "typeorm"
|
||||
import { FlagRouter } from "../utils/flag-router"
|
||||
import { ICacheService } from "@medusajs/types"
|
||||
import { MoneyAmountRepository } from "../repositories/money-amount"
|
||||
import TaxInclusivePricingFeatureFlag from "../loaders/feature-flags/tax-inclusive-pricing"
|
||||
import { TaxServiceRate } from "../types/tax-service"
|
||||
import { FlagRouter } from "@medusajs/utils"
|
||||
import { isDefined } from "medusa-core-utils"
|
||||
import { EntityManager } from "typeorm"
|
||||
import TaxInclusivePricingFeatureFlag from "../loaders/feature-flags/tax-inclusive-pricing"
|
||||
import { MoneyAmountRepository } from "../repositories/money-amount"
|
||||
import { TaxServiceRate } from "../types/tax-service"
|
||||
|
||||
class PriceSelectionStrategy extends AbstractPriceSelectionStrategy {
|
||||
protected manager_: EntityManager
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
import {
|
||||
LineItem,
|
||||
LineItemTaxLine,
|
||||
ShippingMethod,
|
||||
ShippingMethodTaxLine,
|
||||
} from "../models"
|
||||
import { FlagRouter } from "@medusajs/utils"
|
||||
import { ITaxCalculationStrategy, TaxCalculationContext } from "../interfaces"
|
||||
import { calculatePriceTaxAmount } from "../utils"
|
||||
import { FlagRouter } from "../utils/flag-router"
|
||||
import TaxInclusivePricingFeatureFlag from "../loaders/feature-flags/tax-inclusive-pricing"
|
||||
import {
|
||||
LineItem,
|
||||
LineItemTaxLine,
|
||||
ShippingMethod,
|
||||
ShippingMethodTaxLine,
|
||||
} from "../models"
|
||||
import { calculatePriceTaxAmount } from "../utils"
|
||||
|
||||
class TaxCalculationStrategy implements ITaxCalculationStrategy {
|
||||
protected readonly featureFlagRouter_: FlagRouter
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
import { IEventBusService, ISearchService } from "@medusajs/types"
|
||||
import { defaultSearchIndexingProductRelations } from "@medusajs/utils"
|
||||
import { FlagRouter, defaultSearchIndexingProductRelations } from "@medusajs/utils"
|
||||
import { indexTypes } from "medusa-core-utils"
|
||||
import ProductCategoryFeatureFlag from "../loaders/feature-flags/product-categories"
|
||||
import { SEARCH_INDEX_EVENT } from "../loaders/search-index"
|
||||
import { Product } from "../models"
|
||||
import ProductService from "../services/product"
|
||||
import { FlagRouter } from "../utils/flag-router"
|
||||
|
||||
type InjectedDependencies = {
|
||||
eventBusService: IEventBusService
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { FlagRouter } from "@medusajs/utils"
|
||||
import { calculatePriceTaxAmount } from "../calculate-price-tax-amount"
|
||||
import { FlagRouter } from "../../utils/flag-router"
|
||||
|
||||
describe("calculatePriceTaxAmount", () => {
|
||||
describe("Calculate taxes from a given price", () => {
|
||||
|
||||
@@ -1,30 +0,0 @@
|
||||
import { FlagRouter } from "../flag-router"
|
||||
|
||||
describe("Flag Router", () => {
|
||||
describe("listFlags", () => {
|
||||
it("should list all feature flags", () => {
|
||||
const flagRouter = new FlagRouter({})
|
||||
|
||||
flagRouter.setFlag("test", false)
|
||||
flagRouter.setFlag("test2", true)
|
||||
flagRouter.setFlag("test3", false)
|
||||
|
||||
const listOfFlags = flagRouter.listFlags()
|
||||
|
||||
expect(listOfFlags).toEqual([
|
||||
{
|
||||
key: "test",
|
||||
value: false,
|
||||
},
|
||||
{
|
||||
key: "test2",
|
||||
value: true,
|
||||
},
|
||||
{
|
||||
key: "test3",
|
||||
value: false,
|
||||
},
|
||||
])
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -1,75 +0,0 @@
|
||||
import { FeatureFlagTypes } from "@medusajs/types"
|
||||
import { isObject, isString } from "@medusajs/utils"
|
||||
|
||||
export class FlagRouter implements FeatureFlagTypes.IFlagRouter {
|
||||
private readonly flags: Record<string, boolean | Record<string, boolean>> = {}
|
||||
|
||||
constructor(flags: Record<string, boolean | Record<string, boolean>>) {
|
||||
this.flags = flags
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a feature flag is enabled.
|
||||
* There are two ways of using this method:
|
||||
* 1. `isFeatureEnabled("myFeatureFlag")`
|
||||
* 2. `isFeatureEnabled({ myNestedFeatureFlag: "someNestedFlag" })`
|
||||
* We use 1. for top-level feature flags and 2. for nested feature flags. Almost all flags are top-level.
|
||||
* An example of a nested flag is workflows. To use it, you would do:
|
||||
* `isFeatureEnabled({ workflows: Workflows.CreateCart })`
|
||||
* @param flag - The flag to check
|
||||
* @return {boolean} - Whether the flag is enabled or not
|
||||
*/
|
||||
public isFeatureEnabled(flag: string | Record<string, string>): boolean {
|
||||
if (isString(flag)) {
|
||||
return !!this.flags[flag]
|
||||
}
|
||||
|
||||
if (isObject(flag)) {
|
||||
const [nestedFlag, value] = Object.entries(flag)[0]
|
||||
|
||||
if (typeof this.flags[nestedFlag] === "boolean") {
|
||||
return this.flags[nestedFlag] as boolean
|
||||
}
|
||||
|
||||
return !!this.flags[nestedFlag]?.[value]
|
||||
}
|
||||
|
||||
throw Error("Flag must be a string or an object")
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a feature flag.
|
||||
* Flags take two shapes:
|
||||
* setFlag("myFeatureFlag", true)
|
||||
* setFlag("myFeatureFlag", { nestedFlag: true })
|
||||
* These shapes are used for top-level and nested flags respectively, as explained in isFeatureEnabled.
|
||||
* @param key - The key of the flag to set.
|
||||
* @param value - The value of the flag to set.
|
||||
* @return {void} - void
|
||||
*/
|
||||
public setFlag(
|
||||
key: string,
|
||||
value: boolean | { [key: string]: boolean }
|
||||
): void {
|
||||
if (isObject(value)) {
|
||||
const existing = this.flags[key]
|
||||
|
||||
if (!existing) {
|
||||
this.flags[key] = value
|
||||
return
|
||||
}
|
||||
|
||||
this.flags[key] = { ...(this.flags[key] as object), ...value }
|
||||
return
|
||||
}
|
||||
|
||||
this.flags[key] = value
|
||||
}
|
||||
|
||||
public listFlags(): FeatureFlagTypes.FeatureFlagsResponse {
|
||||
return Object.entries(this.flags || {}).map(([key, value]) => ({
|
||||
key,
|
||||
value,
|
||||
}))
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user