github medusajs/medusa v2.0.4-preview

latest releases: v2.0.4, @medusajs/workflow-engine-redis@2.0.4, @medusajs/workflow-engine-inmemory@2.0.4...
3 months ago

Highlights

Domain-specific Workflow Hooks

We recently introduced Workflow Hooks, allowing you to expose injection points in workflows for the consumer to perform custom logic.

Among Medusa's core workflows, you will find available hooks in the following domains:

  • Products: create, update, and delete
  • Orders: create, cancel, complete, create fulfillment, cancel fulfillment, and create shipment
  • Promotions: create, update, delete, create campaign, update campaign, and delete campaign
  • Carts: create and update
  • Customers: create, update, delete, create address, update address, and delete address

Workflow hooks are consumed by registering a hook handler on the workflow. The hook handlers should be placed and registered in the /workflows/hooks folder of your Medusa project. For example, here's how to use the product-created hook:

// workflows/hooks/product-created.ts
import { createProductsWorkflow } from "@medusajs/core-flows"

createProductsWorkflow.hooks.productCreated(( { products, additional_data }) => {
  // run custom business logic
})

This hook receives the created products and arbitrary additional_data. The latter should be passed to the workflow upon running it:

await createProductsWorkflow(req.scope).run({
  input: { products: [ ... ], additional_data: { ... } },
})

In combination with extending the request payload to receive additional data, you can achieve a range of different use cases with Workflow Hooks, e.g. linking a product with another resource. We will share recipes for many of these cases in the near future.

We will continuously add more Workflow Hooks to our core workflow, e.g. a hook to transform line item data and price before it's added to the cart. Keep an eye out for our preview release updates, as they will contain an overview of the new hooks.

Features

Bugs

Documentation

Chores

New Contributors

Full Changelog: v2.0.3-preview...v2.0.4-preview

Don't miss a new medusa release

NewReleases is sending notifications on new releases.