prefer-workflow-event-over-module-event - ESLint plugin rules

This rule prefers workflow event enums (*WorkflowEvents) over internal module-level event enums in a subscriber's config.event.

Note: This rule is available since Medusa v2.19.0.

Severity#

warn. This rule is enabled in the recommended preset.

What it Targets#

This rule targets subscriber files in your project. It reports usages of internal module events (such as ProductEvents.PRODUCT_CATEGORY_DELETED) in the event property of the exported config object, and suggests the equivalent workflow event enum instead.

The following code is reported by the rule:

src/subscribers/product-category-deleted.ts
1import { ProductEvents } from "@medusajs/framework/utils"2
3export const config = {4  event: ProductEvents.PRODUCT_CATEGORY_DELETED,5}

Instead, use the workflow event enum:

src/subscribers/product-category-deleted.ts
1import { ProductCategoryWorkflowEvents } from "@medusajs/framework/utils"2
3export const config = {4  event: ProductCategoryWorkflowEvents.DELETED,5}

The rule also flags internal event string literals:

src/subscribers/product-category-deleted.ts
1// non-compliant2export const config = {3  event: "product.product-category.deleted",4}

For events with no workflow-event equivalent, the rule warns that the event is an internal implementation detail and may change in future releases.

Why it's Important#

Internal module events (enums ending in Events, with values in the form {module}.{data-model}.{action}) are implementation details of Medusa's service layer. They can change between releases without a deprecation notice.

Workflow events (*WorkflowEvents enums) are the stable, public API for subscribing to commerce actions. They're also only triggered if the action is successful. Using them ensures your subscribers react to the correct commerce events.

Fixable#

This rule is auto-fixable when a workflow-event equivalent exists. Run the linter with the --fix option to apply the fix automatically. The fix rewrites the event reference and adds the required import.

When a workflow-event equivalent does not exist, the rule warns but provides no automatic fix. Review whether subscribing to an internal event is intentional.

Turn it Off#

To turn off this rule, set it to off in your ESLint configuration:

eslint.config.ts
1import { defineConfig } from "eslint/config"2import medusa from "@medusajs/eslint-plugin"3
4export default defineConfig([5  ...medusa.configs.recommended,6  {7    rules: {8      "@medusajs/prefer-workflow-event-over-module-event": "off",9    },10  },11])

Or disable it for a single line using an inline comment:

Code
1// eslint-disable-next-line @medusajs/prefer-workflow-event-over-module-event2export const config = { event: ProductEvents.PRODUCT_CATEGORY_DELETED }
Was this page helpful?
Ask Bloom
For assistance in your development, use Claude Code Plugins or Docs MCP server in Cursor, VSCode, etc...FAQ
What is Medusa?
How can I create a module?
How can I create a data model?
How do I create a workflow?
How can I extend a data model in the Product Module?
Recipes
How do I build a marketplace with Medusa?
How do I build digital products with Medusa?
How do I build subscription-based purchases with Medusa?
What other recipes are available in the Medusa documentation?
Chat is cleared on refresh
Line break
⇧↵