feat(medusa, utils): Allow object feature flags (#4701)
Feature flags can be set as follows:
**Environment variables**
```
MEDUSA_FF_ANALYTICS=true
MEDUSA_FF_WORKFLOWS=createProducts,addShippingMethods
```
**Project config**
```
{
featureFlags: {
analytics: true,
workflows: {
createProducts: true,
addShippingMethods: true,
}
}
}
```
This commit is contained in:
1 parent
03fb0479c0
commit
5c60aad177
17 files changed
+478
-115
No files matched your search
@@ -1,7 +1,3 @@
|
||||
import {
|
||||
CreateProductVariantInput,
|
||||
ProductVariantPricesCreateReq,
|
||||
} from "../../../../types/product-variant"
|
||||
import {
|
||||
IsArray,
|
||||
IsBoolean,
|
||||
@@ -12,6 +8,7 @@ import {
|
||||
IsString,
|
||||
ValidateNested,
|
||||
} from "class-validator"
|
||||
import { defaultAdminProductFields, defaultAdminProductRelations } from "."
|
||||
import {
|
||||
PricingService,
|
||||
ProductService,
|
||||
@@ -26,23 +23,26 @@ import {
|
||||
ProductTagReq,
|
||||
ProductTypeReq,
|
||||
} from "../../../../types/product"
|
||||
import {
|
||||
CreateProductVariantInput,
|
||||
ProductVariantPricesCreateReq,
|
||||
} from "../../../../types/product-variant"
|
||||
import {
|
||||
createVariantsTransaction,
|
||||
revertVariantTransaction,
|
||||
} from "./transaction/create-product-variant"
|
||||
import { defaultAdminProductFields, defaultAdminProductRelations } from "."
|
||||
|
||||
import { DistributedTransaction } from "@medusajs/orchestration"
|
||||
import { EntityManager } from "typeorm"
|
||||
import { FeatureFlagDecorators } from "../../../../utils/feature-flag-decorators"
|
||||
import { FlagRouter } from "../../../../utils/flag-router"
|
||||
import { IInventoryService, WorkflowTypes } from "@medusajs/types"
|
||||
import { Logger } from "../../../../types/global"
|
||||
import { ProductStatus } from "../../../../models"
|
||||
import SalesChannelFeatureFlag from "../../../../loaders/feature-flags/sales-channels"
|
||||
import { FlagRouter } from "@medusajs/utils"
|
||||
import { Workflows, createProducts } from "@medusajs/workflows"
|
||||
import { Type } from "class-transformer"
|
||||
import { EntityManager } from "typeorm"
|
||||
import SalesChannelFeatureFlag from "../../../../loaders/feature-flags/sales-channels"
|
||||
import { ProductStatus } from "../../../../models"
|
||||
import { Logger } from "../../../../types/global"
|
||||
import { validator } from "../../../../utils"
|
||||
import { createProducts } from "@medusajs/workflows"
|
||||
import { FeatureFlagDecorators } from "../../../../utils/feature-flag-decorators"
|
||||
|
||||
/**
|
||||
* @oas [post] /admin/products
|
||||
@@ -132,7 +132,17 @@ export default async (req, res) => {
|
||||
const entityManager: EntityManager = req.scope.resolve("manager")
|
||||
const productModuleService = req.scope.resolve("productModuleService")
|
||||
|
||||
if (productModuleService) {
|
||||
const isWorkflowEnabled = featureFlagRouter.isFeatureEnabled({
|
||||
workflows: Workflows.CreateProducts,
|
||||
})
|
||||
|
||||
if (isWorkflowEnabled && !productModuleService) {
|
||||
logger.warn(
|
||||
`Cannot run ${Workflows.CreateProducts} workflow without '@medusajs/product' installed`
|
||||
)
|
||||
}
|
||||
|
||||
if (isWorkflowEnabled && !!productModuleService) {
|
||||
const createProductWorkflow = createProducts(req.scope)
|
||||
|
||||
const input = {
|
||||
|
||||
Reference in new issue
Block a user