v2.0.4-preview

medusajs/medusav2.0.4-previewAug 8, 2024by olivermrbl

AI Summary

This release introduces Domain-specific Workflow Hooks, allowing custom logic injection points in core workflows for various domains like Products and Orders.

Key Highlights

  • Domain-specific Workflow Hooks (Products, Orders, Promotions, Carts, Customers)
  • Hooks implementation example (`createProductsWorkflow.hooks.productCreated`)
  • Exchange endpoints and Claims implementation
  • Refund reasons management API

New Features

  • Introduce additional_data to product endpoints
  • Add hooks to customers modules workflows
  • Exchange endpoints
  • Add hooks to campaigns
  • Refund reasons management API
  • Claims API endpoint

Full Release Notes

<!-- 
![image](https://github.com/user-attachments/assets/4d9de0c0-6b9c-4224-9b8d-8b61715f3257)

# Medusa Preview Release update #4

CMS_BREAK -->

## Highlights

### Domain-specific Workflow Hooks

We [recently introduced Workflow Hooks](https://github.com/medusajs/medusa/releases/tag/v2.0.3-preview), 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:
```ts
// 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:
```ts
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 https://github.com/medusajs/medusa/pull/8405
* feature: add hooks to customers modules workflows by @thetutlage in https://github.com/medusajs/medusa/pull/8442
* feat(create-medusa-app, medusa): check Node.js version before installation. by @shahednasser in https://github.com/medusajs/medusa/pull/8452
* feat(core-flows,order,medusa): exchange endpoints by @carlos-r-l-rodrigues in https://github.com/medusajs/medusa/pull/8396
* feature: add hooks to campaigns by @thetutlage in https://github.com/medusajs/medusa/pull/8450
* feat(core-flows,payment,medusa,types): Refund reasons management API by @riqwan in https://github.com/medusajs/medusa/pull/8436
* feat: add claims/:id endpoint to admin api by @christiananese in https://github.com/medusajs/medusa/pull/8465
* feature: add create and update cart hooks by @thetutlage in https://github.com/medusajs/medusa/pull/8481
* feat(core-flows): manage inventory reservation of claims and exchanges by @carlos-r-l-rodrigues in https://github.com/medusajs/medusa/pull/8448
* feat(dashboard): claims first implementation by @riqwan in https://github.com/medusajs/medusa/pull/8468
* feat(core-flows,dashboard,medusa): ability to add and remove items to claim inbound by @riqwan in https://github.com/medusajs/medusa/pull/8480
* feat(adshboard,types,medusa): enable adding notes/return reason to inbound claims by @riqwan in https://github.com/medusajs/medusa/pull/8488
* feature: add workflows hooks to the order module by @thetutlage in https://github.com/medusajs/medusa/pull/8496
* feature: share execution context with hook handlers by @thetutlage in https://github.com/medusajs/medusa/pull/8501

## Bugs
* fix(payment): validate total amount when refunding payment by @riqwan in https://github.com/medusajs/medusa/pull/8437
* fix: Upgrade bullmq and adjust to breaking changes in repeatable jobs by @sradevski in https://github.com/medusajs/medusa/pull/8446
* fix(order): return migration enum by @carlos-r-l-rodrigues in https://github.com/medusajs/medusa/pull/8449
* fix(medusa): plus sign to space by @carlos-r-l-rodrigues in https://github.com/medusajs/medusa/pull/8454
* fix: Use a global reference to distributed transaction and scheduler by @sradevski in https://github.com/medusajs/medusa/pull/8462
* fix(core-flows): copy line items attribute by @carlos-r-l-rodrigues in https://github.com/medusajs/medusa/pull/8471
* fix(core-flows): Unsetting reason on return items by @olivermrbl in https://github.com/medusajs/medusa/pull/8470
* fix(core-flows): Allow return requests with no shipping by @olivermrbl in https://github.com/medusajs/medusa/pull/8472
* fix(event-bus-redis): Consume job correct in worker by @olivermrbl in https://github.com/medusajs/medusa/pull/8444

## Documentation
* Update page.mdx by @420coupe in https://github.com/medusajs/medusa/pull/8425
* docs: fix helloWorldLoader function definition by @letalumil in https://github.com/medusajs/medusa/pull/8429
* docs: fix deployment link by @letalumil in https://github.com/medusajs/medusa/pull/8431
* docs: fix ModuleRegistrationName import by @letalumil in https://github.com/medusajs/medusa/pull/8434
* docs: fix node version in create-medusa-app reference by @shahednasser in https://github.com/medusajs/medusa/pull/8443
* docs: added a chapter on how to emit an event by @shahednasser in https://github.com/medusajs/medusa/pull/8414
* docs: added a section on sending requests to api routes in admin by @shahednasser in https://github.com/medusajs/medusa/pull/8412
* docs: fix sidebar not updating when api reference path changes by @shahednasser in https://github.com/medusajs/medusa/pull/8409
* docs: merge allOf in OAS to show all object types by @shahednasser in https://github.com/medusajs/medusa/pull/8453
* docs: fixes to notification and file module guides by @shahednasser in https://github.com/medusajs/medusa/pull/8451
* docs: added a note about admin customizations as arrow functions by @shahednasser in https://github.com/medusajs/medusa/pull/8387
* docs-util: added workflows typedoc plugin by @shahednasser in https://github.com/medusajs/medusa/pull/8463
* docs-util: added a namespaces plugin by @shahednasser in https://github.com/medusajs/medusa/pull/8500

### Chores
* chore(core-flows): add TSDocs to the emitEventStep by @shahednasser in https://github.com/medusajs/medusa/pull/8413
* chore(utils): add missing imports in notification TSDocs by @shahednasser in https://github.com/medusajs/medusa/pull/8447
* chore: added and updated TSDocs of order module service by @shahednasser in https://github.com/medusajs/medusa/pull/8246
* chore(medusa,core-flows): cart payment collection link by @carlos-r-l-rodrigues in https://github.com/medusajs/medusa/pull/8457
* chore: update notifcations drawer design by @christiananese in https://github.com/medusajs/medusa/pull/8469
* chore(utils): improve to handle util by @carlos-r-l-rodrigues in https://github.com/medusajs/medusa/pull/8487
* chore(core-flows): util to format inventory input by @carlos-r-l-rodrigues in https://github.com/medusajs/medusa/pull/8483
* chore: fix actions generating docs by @shahednasser in https://github.com/medusajs/medusa/pull/8486
* chore: use WithAdditionalData helper everywhere by @thetutlage in https://github.com/medusajs/medusa/pull/8499
* chore(core-flows): [1] export types and types, add basic TSDocs by @shahednasser in https://github.com/medusajs/medusa/pull/8504

## New Contributors
* @420coupe made their first contribution in https://github.com/medusajs/medusa/pull/8425
* @letalumil made their first contribution in https://github.com/medusajs/medusa/pull/8429
* @christiananese made their first contribution in https://github.com/medusajs/medusa/pull/8465

**Full Changelog**: https://github.com/medusajs/medusa/compare/v2.0.3-preview...v2.0.4-preview