feat(api): add view configuration API routes (#13177)
* feat: add view_configurations feature flag - Add feature flag provider and hooks to admin dashboard - Add backend API endpoint for feature flags - Create view_configurations feature flag (disabled by default) - Update order list table to use legacy version when flag is disabled - Can be enabled with MEDUSA_FF_VIEW_CONFIGURATIONS=true env var * fix: naming * fix: feature flags unauthenticated * fix: add test * feat: add settings module * fix: deps * fix: cleanup * fix: add more tetsts * fix: rm changelog * fix: deps * fix: add settings module to default modules list * feat(api): add view configuration API routes - Add CRUD endpoints for view configurations - Add active view configuration management endpoints - Add feature flag middleware for view config routes - Add comprehensive integration tests - Add HTTP types for view configuration payloads and responses - Support system defaults and user-specific configurations - Enable setting views as active during create/update operations * fix: test * fix: test * fix: test * fix: change view configuration path * fix: tests * fix: remove manual settings module config from integration tests * fix: container typing * fix: workflows
This commit is contained in:
@@ -25,6 +25,7 @@ export * from "./region"
|
||||
export * from "./reservation"
|
||||
export * from "./return-reason"
|
||||
export * from "./sales-channel"
|
||||
export * from "./settings"
|
||||
export * from "./shipping-options"
|
||||
export * from "./shipping-profile"
|
||||
export * from "./stock-location"
|
||||
|
||||
2
packages/core/core-flows/src/settings/index.ts
Normal file
2
packages/core/core-flows/src/settings/index.ts
Normal file
@@ -0,0 +1,2 @@
|
||||
export * from "./steps"
|
||||
export * from "./workflows"
|
||||
@@ -0,0 +1,27 @@
|
||||
import {
|
||||
CreateViewConfigurationDTO,
|
||||
} from "@medusajs/framework/types"
|
||||
import { Modules } from "@medusajs/framework/utils"
|
||||
import { StepResponse, createStep } from "@medusajs/framework/workflows-sdk"
|
||||
|
||||
export type CreateViewConfigurationStepInput = CreateViewConfigurationDTO
|
||||
|
||||
export const createViewConfigurationStepId = "create-view-configuration"
|
||||
|
||||
export const createViewConfigurationStep = createStep(
|
||||
createViewConfigurationStepId,
|
||||
async (data: CreateViewConfigurationStepInput, { container }) => {
|
||||
const service = container.resolve(Modules.SETTINGS)
|
||||
const created = await service.createViewConfigurations(data)
|
||||
|
||||
return new StepResponse(created, { id: created.id })
|
||||
},
|
||||
async (compensateInput, { container }) => {
|
||||
if (!compensateInput?.id) {
|
||||
return
|
||||
}
|
||||
|
||||
const service = container.resolve(Modules.SETTINGS)
|
||||
await service.deleteViewConfigurations([compensateInput.id])
|
||||
}
|
||||
)
|
||||
3
packages/core/core-flows/src/settings/steps/index.ts
Normal file
3
packages/core/core-flows/src/settings/steps/index.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
export * from "./create-view-configuration"
|
||||
export * from "./update-view-configuration"
|
||||
export * from "./set-active-view-configuration"
|
||||
@@ -0,0 +1,59 @@
|
||||
import { ISettingsModuleService } from "@medusajs/framework/types"
|
||||
import { Modules } from "@medusajs/framework/utils"
|
||||
import { StepResponse, createStep } from "@medusajs/framework/workflows-sdk"
|
||||
|
||||
export type SetActiveViewConfigurationStepInput = {
|
||||
id: string
|
||||
entity: string
|
||||
user_id: string
|
||||
}
|
||||
|
||||
export const setActiveViewConfigurationStepId = "set-active-view-configuration"
|
||||
|
||||
export const setActiveViewConfigurationStep = createStep(
|
||||
setActiveViewConfigurationStepId,
|
||||
async (input: SetActiveViewConfigurationStepInput, { container }) => {
|
||||
const service = container.resolve<ISettingsModuleService>(Modules.SETTINGS)
|
||||
|
||||
// Get the currently active view configuration for rollback
|
||||
const currentActiveView = await service.getActiveViewConfiguration(
|
||||
input.entity,
|
||||
input.user_id
|
||||
)
|
||||
|
||||
// Set the new view as active
|
||||
await service.setActiveViewConfiguration(
|
||||
input.entity,
|
||||
input.user_id,
|
||||
input.id
|
||||
)
|
||||
|
||||
return new StepResponse(input.id, {
|
||||
entity: input.entity,
|
||||
user_id: input.user_id,
|
||||
previousActiveViewId: currentActiveView?.id || null,
|
||||
})
|
||||
},
|
||||
async (compensateInput, { container }) => {
|
||||
if (!compensateInput) {
|
||||
return
|
||||
}
|
||||
|
||||
const service = container.resolve<ISettingsModuleService>(Modules.SETTINGS)
|
||||
|
||||
if (compensateInput.previousActiveViewId) {
|
||||
// Restore the previous active view
|
||||
await service.setActiveViewConfiguration(
|
||||
compensateInput.entity,
|
||||
compensateInput.user_id,
|
||||
compensateInput.previousActiveViewId
|
||||
)
|
||||
} else {
|
||||
// If there was no previous active view, clear the active view
|
||||
await service.clearActiveViewConfiguration(
|
||||
compensateInput.entity,
|
||||
compensateInput.user_id
|
||||
)
|
||||
}
|
||||
}
|
||||
)
|
||||
@@ -0,0 +1,41 @@
|
||||
import {
|
||||
UpdateViewConfigurationDTO,
|
||||
ISettingsModuleService,
|
||||
ViewConfigurationDTO,
|
||||
} from "@medusajs/framework/types"
|
||||
import { Modules } from "@medusajs/framework/utils"
|
||||
import { StepResponse, createStep } from "@medusajs/framework/workflows-sdk"
|
||||
|
||||
export type UpdateViewConfigurationStepInput = {
|
||||
id: string
|
||||
data: UpdateViewConfigurationDTO
|
||||
}
|
||||
|
||||
export const updateViewConfigurationStepId = "update-view-configuration"
|
||||
|
||||
export const updateViewConfigurationStep = createStep(
|
||||
updateViewConfigurationStepId,
|
||||
async (input: UpdateViewConfigurationStepInput, { container }) => {
|
||||
const service = container.resolve<ISettingsModuleService>(Modules.SETTINGS)
|
||||
|
||||
const currentState = await service.retrieveViewConfiguration(input.id)
|
||||
|
||||
const updated = await service.updateViewConfigurations(input.id, input.data)
|
||||
|
||||
return new StepResponse(updated, {
|
||||
id: input.id,
|
||||
previousState: currentState,
|
||||
})
|
||||
},
|
||||
async (compensateInput, { container }) => {
|
||||
if (!compensateInput?.id || !compensateInput?.previousState) {
|
||||
return
|
||||
}
|
||||
|
||||
const service = container.resolve<ISettingsModuleService>(Modules.SETTINGS)
|
||||
|
||||
const { id, created_at, updated_at, ...restoreData } =
|
||||
compensateInput.previousState as ViewConfigurationDTO
|
||||
await service.updateViewConfigurations(compensateInput.id, restoreData)
|
||||
}
|
||||
)
|
||||
@@ -0,0 +1,42 @@
|
||||
import {
|
||||
CreateViewConfigurationDTO,
|
||||
ViewConfigurationDTO,
|
||||
} from "@medusajs/framework/types"
|
||||
import {
|
||||
WorkflowData,
|
||||
WorkflowResponse,
|
||||
createWorkflow,
|
||||
when,
|
||||
} from "@medusajs/framework/workflows-sdk"
|
||||
import {
|
||||
createViewConfigurationStep,
|
||||
setActiveViewConfigurationStep,
|
||||
} from "../steps"
|
||||
|
||||
export type CreateViewConfigurationWorkflowInput =
|
||||
CreateViewConfigurationDTO & {
|
||||
set_active?: boolean
|
||||
}
|
||||
|
||||
export const createViewConfigurationWorkflowId = "create-view-configuration"
|
||||
|
||||
export const createViewConfigurationWorkflow = createWorkflow(
|
||||
createViewConfigurationWorkflowId,
|
||||
(
|
||||
input: WorkflowData<CreateViewConfigurationWorkflowInput>
|
||||
): WorkflowResponse<ViewConfigurationDTO> => {
|
||||
const viewConfig = createViewConfigurationStep(input)
|
||||
|
||||
when({ input, viewConfig }, ({ input }) => {
|
||||
return !!input.set_active && !!input.user_id
|
||||
}).then(() => {
|
||||
setActiveViewConfigurationStep({
|
||||
id: viewConfig.id,
|
||||
entity: viewConfig.entity,
|
||||
user_id: input.user_id as string,
|
||||
})
|
||||
})
|
||||
|
||||
return new WorkflowResponse(viewConfig)
|
||||
}
|
||||
)
|
||||
2
packages/core/core-flows/src/settings/workflows/index.ts
Normal file
2
packages/core/core-flows/src/settings/workflows/index.ts
Normal file
@@ -0,0 +1,2 @@
|
||||
export * from "./create-view-configuration"
|
||||
export * from "./update-view-configuration"
|
||||
@@ -0,0 +1,51 @@
|
||||
import {
|
||||
UpdateViewConfigurationDTO,
|
||||
ViewConfigurationDTO,
|
||||
} from "@medusajs/framework/types"
|
||||
import {
|
||||
WorkflowData,
|
||||
WorkflowResponse,
|
||||
createWorkflow,
|
||||
when,
|
||||
transform,
|
||||
} from "@medusajs/framework/workflows-sdk"
|
||||
import {
|
||||
updateViewConfigurationStep,
|
||||
setActiveViewConfigurationStep,
|
||||
} from "../steps"
|
||||
|
||||
export type UpdateViewConfigurationWorkflowInput = {
|
||||
id: string
|
||||
set_active?: boolean
|
||||
} & UpdateViewConfigurationDTO
|
||||
|
||||
export const updateViewConfigurationWorkflowId = "update-view-configuration"
|
||||
|
||||
export const updateViewConfigurationWorkflow = createWorkflow(
|
||||
updateViewConfigurationWorkflowId,
|
||||
(
|
||||
input: WorkflowData<UpdateViewConfigurationWorkflowInput>
|
||||
): WorkflowResponse<ViewConfigurationDTO> => {
|
||||
const updateData = transform({ input }, ({ input }) => {
|
||||
const { id, set_active, ...data } = input
|
||||
return data
|
||||
})
|
||||
|
||||
const viewConfig = updateViewConfigurationStep({
|
||||
id: input.id,
|
||||
data: updateData,
|
||||
})
|
||||
|
||||
when({ input, viewConfig }, ({ input, viewConfig }) => {
|
||||
return !!input.set_active && !!viewConfig.user_id
|
||||
}).then(() => {
|
||||
setActiveViewConfigurationStep({
|
||||
id: viewConfig.id,
|
||||
entity: viewConfig.entity,
|
||||
user_id: viewConfig.user_id as string,
|
||||
})
|
||||
})
|
||||
|
||||
return new WorkflowResponse(viewConfig)
|
||||
}
|
||||
)
|
||||
Reference in New Issue
Block a user