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
- feature: introduce additional_data to the product endpoints by @thetutlage in #8405
- feature: add hooks to customers modules workflows by @thetutlage in #8442
- feat(create-medusa-app, medusa): check Node.js version before installation. by @shahednasser in #8452
- feat(core-flows,order,medusa): exchange endpoints by @carlos-r-l-rodrigues in #8396
- feature: add hooks to campaigns by @thetutlage in #8450
- feat(core-flows,payment,medusa,types): Refund reasons management API by @riqwan in #8436
- feat: add claims/:id endpoint to admin api by @christiananese in #8465
- feature: add create and update cart hooks by @thetutlage in #8481
- feat(core-flows): manage inventory reservation of claims and exchanges by @carlos-r-l-rodrigues in #8448
- feat(dashboard): claims first implementation by @riqwan in #8468
- feat(core-flows,dashboard,medusa): ability to add and remove items to claim inbound by @riqwan in #8480
- feat(adshboard,types,medusa): enable adding notes/return reason to inbound claims by @riqwan in #8488
- feature: add workflows hooks to the order module by @thetutlage in #8496
- feature: share execution context with hook handlers by @thetutlage in #8501
Bugs
- fix(payment): validate total amount when refunding payment by @riqwan in #8437
- fix: Upgrade bullmq and adjust to breaking changes in repeatable jobs by @sradevski in #8446
- fix(order): return migration enum by @carlos-r-l-rodrigues in #8449
- fix(medusa): plus sign to space by @carlos-r-l-rodrigues in #8454
- fix: Use a global reference to distributed transaction and scheduler by @sradevski in #8462
- fix(core-flows): copy line items attribute by @carlos-r-l-rodrigues in #8471
- fix(core-flows): Unsetting reason on return items by @olivermrbl in #8470
- fix(core-flows): Allow return requests with no shipping by @olivermrbl in #8472
- fix(event-bus-redis): Consume job correct in worker by @olivermrbl in #8444
Documentation
- Update page.mdx by @420coupe in #8425
- docs: fix helloWorldLoader function definition by @letalumil in #8429
- docs: fix deployment link by @letalumil in #8431
- docs: fix ModuleRegistrationName import by @letalumil in #8434
- docs: fix node version in create-medusa-app reference by @shahednasser in #8443
- docs: added a chapter on how to emit an event by @shahednasser in #8414
- docs: added a section on sending requests to api routes in admin by @shahednasser in #8412
- docs: fix sidebar not updating when api reference path changes by @shahednasser in #8409
- docs: merge allOf in OAS to show all object types by @shahednasser in #8453
- docs: fixes to notification and file module guides by @shahednasser in #8451
- docs: added a note about admin customizations as arrow functions by @shahednasser in #8387
- docs-util: added workflows typedoc plugin by @shahednasser in #8463
- docs-util: added a namespaces plugin by @shahednasser in #8500
Chores
- chore(core-flows): add TSDocs to the emitEventStep by @shahednasser in #8413
- chore(utils): add missing imports in notification TSDocs by @shahednasser in #8447
- chore: added and updated TSDocs of order module service by @shahednasser in #8246
- chore(medusa,core-flows): cart payment collection link by @carlos-r-l-rodrigues in #8457
- chore: update notifcations drawer design by @christiananese in #8469
- chore(utils): improve to handle util by @carlos-r-l-rodrigues in #8487
- chore(core-flows): util to format inventory input by @carlos-r-l-rodrigues in #8483
- chore: fix actions generating docs by @shahednasser in #8486
- chore: use WithAdditionalData helper everywhere by @thetutlage in #8499
- chore(core-flows): [1] export types and types, add basic TSDocs by @shahednasser in #8504
New Contributors
- @420coupe made their first contribution in #8425
- @letalumil made their first contribution in #8429
- @christiananese made their first contribution in #8465
Full Changelog: v2.0.3-preview...v2.0.4-preview