@medusajs/core-flows
Documentation | Website
Building blocks for digital commerce
Medusa's built-in commerce workflows and steps: the business flows behind the Medusa API routes, such as creating products, completing carts, and managing orders, returns, and exchanges. Use them in API routes, subscribers, scheduled jobs, or your own workflows to reuse Medusa's logic, or consume their hooks to extend it. Medusa applications import them from @medusajs/medusa/core-flows, which re-exports this package.
At a glance
| Package | @medusajs/core-flows |
| Type | Core library |
| Import from | @medusajs/medusa/core-flows |
Features
- Workflows and steps grouped by commerce domain under
src/<domain>/, such ascart,order,product,payment,fulfillment,inventory,pricing,promotion,customer, andauth. - Each domain has a
workflows/directory and asteps/directory.lockingandnotificationonly have steps. commonholds generic steps used across domains, such asuseQueryGraphStep,createRemoteLinkStep, andemitEventStep.- Naming convention: workflows end in
Workflow(for example,createProductsWorkflow), steps end inStep(for example,createProductsStep), and each has a matching ID constant (for example,createProductsWorkflowId). - Many workflows expose hooks, such as
createProductsWorkflow.hooks.productsCreated, to run custom logic within the workflow.
Installation
No separate installation is needed in a Medusa application. It's installed with @medusajs/medusa.
Usage
Run a workflow by passing it the Medusa container, then calling run:
import type { MedusaRequest, MedusaResponse } from "@medusajs/framework/http"
import { createProductsWorkflow } from "@medusajs/medusa/core-flows"
export async function POST(req: MedusaRequest, res: MedusaResponse) {
const { result } = await createProductsWorkflow(req.scope).run({
input: {
products: [
{
title: "Shirt",
},
],
},
})
res.json({ products: result })
}
Steps, such as useQueryGraphStep, are used inside your own workflows created with createWorkflow from @medusajs/framework/workflows-sdk.