v2.0.3-preview
medusajs/medusav2.0.3-previewAug 2, 2024by olivermrbl
AI Summary
This preview release introduces Workflow Hooks via the `createHook` helper and `WorkflowResponse` class, re-introduces Product Import and Export, and adds Product Tag management UI. It also includes new recipes for Subscriptions and Digital Products.
Key Highlights
- Introduction of Workflow Hooks (`createHook`) and `WorkflowResponse` class for custom logic execution within workflows.
- Re-introduction and redesign of Product Import and Export functionality.
- New Product Tag management UI available in the dashboard.
- New recipes for implementing Subscriptions and Digital Products.
Breaking Changes
- Added `createHook` helper to the workflows-sdk.
- Changed the return value of `createWorkflow` to require the use of the `WorkflowResponse` class.
New Features
- Add stock_location_id filter to providers API
- Allow updating prices through product update workflow
- Skip step functionality in workflows
- Product export support in UI
- Add support for product imports
- Claims client, hooks, and types
- Cart API returns billing_address.province
- Validate shipping options to stock locations
- Product Tag management in dashboard
- Ability to capture payment from order page
- Order Exchange initial workflows
- Support for sorting export headers
- Add `requested_at` + `open` status to return
- hooks to product module's workflows
- Refund payment in order page
- Use tag ids instead of values wherever possible
- Add support for categories in product import and export
Full Release Notes
<!--

# Medusa Preview Release update #3
CMS_BREAK -->
## Get started with a new project
To get started using the preview release, run the following command:
```bash
npx create-medusa-app@preview
```
This command will create a new Medusa project with our redesigned admin and a 2.0-compatible Next.js storefront. The Medusa application and the Next.js storefront are separate projects in separate folders.
## Highlights
### Workflow Hooks
🚧 **Breaking change**
We have added a new helper, `createHook`, to the `workflows-sdk`. The `createHook` helper exposes a hook from a workflow. Later (after the workflow has been composed), the workflow consumers can bind a handler to the hook to run custom logic.
> [!NOTE]
> As of now, you can only register one hook handler, and the workflow orchestrator ignores the return value.
**Exposing hook via `createHook`**
```ts
import {
createStep,
createHook,
createWorkflow,
WorkflowResponse
} from '@medusajs/workflows-sdk'
const createProductStep = createStep('createProduct', function () {
// business logic for "createProduct"
})
const workflow = createWorkflow('name', function (input) {
createProductStep(input)
const productCreatedHook = createHook('productCreated', { productId: input.id })
return new WorkflowResponse(input, {
hooks: [productCreatedHook]
})
})
```
Points to note
- Unlike the `createStep` function, the `createHook` method is called within the workflow composition callback.
- You must return the created hooks from the composition callback. Returning of hooks is needed for the TypeScript engine to provide intellisense when registering a handler for the hook.
- Hooks are executed in the same position as they are defined within the composition callback
**Registering the hook handler**
The workflow user must register a hook handler to run custom logic within a workflow. They can do that as follows.
```ts
workflow.hooks.productCreated(() => {
// run custom business logic
})
```
Points to note
- The hook handler behaves similarly to a workflow step. It can run async code, will be retried, and can also have compensation behavior (defined as the 2nd parameter)
- There can only be one handler for a hook. If you need multiple handlers, you should create another workflow and register that as the hook handler (not supported yet).
- The return value of the hook handler is ignored in this first iteration.
**Introducing the `WorkflowResponse` class and breaking changes**
The introduction of hooks has changed the return value of the `createWorkflow` composition callback. Now, we must return both the workflow results and the configured hooks.
Instead of manually composing the return value, you can use the `WorkflowResponse` class to construct the current response. The `WorkflowResponse` class accepts the following parameters.
- The first parameter is the result of the workflow.
- The second parameter (optional) is a config object with configured hooks.
### Product Import and Export
We have re-introduced Product Import and Export and simultaneously redesigned the notifications drawer in the dashboard.
Right now, we are polling for new notifications every third second, but we intend to introduce SSE (or a similar tech.) to enable real-time notifications.
### Product Tag management UI
We have added Product Tag management in the dashboard. Find it in "Settings > Product Tags".
### New Recipes: Subscriptions and Digital Products
We have added two new recipes covering how to add support for Subscriptions and Digital Product respectively. They both come with an example repository.
Check out the Subscription recipe [here](https://docs.medusajs.com/v2/resources/recipes/subscriptions).
Check out the Digital Products recipe [here](https://docs.medusajs.com/v2/resources/recipes/digital-products).
## Features
* feat(medusa): add stock_location_id filter to providers api by @riqwan in https://github.com/medusajs/medusa/pull/8319
* Chore/order claims 2 by @carlos-r-l-rodrigues in https://github.com/medusajs/medusa/pull/8312
* feat:Allow updating prices through product update workflow by @sradevski in https://github.com/medusajs/medusa/pull/8316
* feat(orchestration,workflows-sdk): Skip step by @carlos-r-l-rodrigues in https://github.com/medusajs/medusa/pull/8334
* feat: Add support for product export in UI by @sradevski in https://github.com/medusajs/medusa/pull/8281
* feat(dashboard,icons,types,js-sdk): add providers to location UI by @riqwan in https://github.com/medusajs/medusa/pull/8328
* feat: Add support for product imports by @sradevski in https://github.com/medusajs/medusa/pull/8298
* breaking: implement workflow hooks (first iteration) by @thetutlage in https://github.com/medusajs/medusa/pull/8346
* feat: Make product import v1 compatible by @sradevski in https://github.com/medusajs/medusa/pull/8362
* feat(dashboard, types, js-sdk): Claims client, hooks and types by @fPolic in https://github.com/medusajs/medusa/pull/8370
* feat: Cart API should also return billing_address.province by default by @josetr in https://github.com/medusajs/medusa/pull/8293
* feat(core-flows, fulfillment): validate shipping options to stock locations by @riqwan in https://github.com/medusajs/medusa/pull/8291
* feat(core-flows,medusa): add endpoint to add/remove fulfillment providers to location by @riqwan in https://github.com/medusajs/medusa/pull/8299
* feat: update return request by @olivermrbl in https://github.com/medusajs/medusa/pull/8302
* feat(dashboard,medusa,types): Add Product Tag management by @kasperkristensen in https://github.com/medusajs/medusa/pull/8349
* feat(dashboard,js-sdk,types): add ability to capture payment from order page by @riqwan in https://github.com/medusajs/medusa/pull/8368
* chore(core-flows): Order Exchange - initial workflows by @carlos-r-l-rodrigues in https://github.com/medusajs/medusa/pull/8374
* feat: Add support for sorting export headers by @sradevski in https://github.com/medusajs/medusa/pull/8386
* feat: Add `requested_at` + `open` status to return by @olivermrbl in https://github.com/medusajs/medusa/pull/8391
* feat: Show notice on new notifications by @sradevski in https://github.com/medusajs/medusa/pull/8390
* feat: add hooks to product module's workflows by @thetutlage in https://github.com/medusajs/medusa/pull/8389
* feat(dashboard,types,js-sdk,payment): ability to refund payment in order page by @riqwan in https://github.com/medusajs/medusa/pull/8385
* feat(dashboard, js-sdk, types): receive return e2e by @fPolic in https://github.com/medusajs/medusa/pull/8305
* feat: Use tag ids instead of values wherever possible by @sradevski in https://github.com/medusajs/medusa/pull/8394
* feat: Add support for categories in product import and export by @sradevski in https://github.com/medusajs/medusa/pull/8375
## Bugs
* fix: Store private files in the static directory by default by @sradevski in https://github.com/medusajs/medusa/pull/8325
* fix(core-flows,order): update action by @carlos-r-l-rodrigues in https://github.com/medusajs/medusa/pull/8333
* fix(dashboard,types,js-sdk): Cleanup `settings/store` by @kasperkristensen in https://github.com/medusajs/medusa/pull/8336
* fix(core-flows): delete receive return action by @carlos-r-l-rodrigues in https://github.com/medusajs/medusa/pull/8350
* fix: Added more tests and fixed a couple of issues with product import by @sradevski in https://github.com/medusajs/medusa/pull/8341
* fix(dashboard): Fix spacing, media, and missing tip in product create form by @kasperkristensen in https://github.com/medusajs/medusa/pull/8338
* fix: Use region name in product pricing exports by @sradevski in https://github.com/medusajs/medusa/pull/8373
* fix(framework): prepublish script by @adrien2p in https://github.com/medusajs/medusa/pull/8377
* fix(framework): telemetry package version by @adrien2p in https://github.com/medusajs/medusa/pull/8378
* fix: Correctly associate options to variants when variants for multiple products are created by @sradevski in https://github.com/medusajs/medusa/pull/8285
* fix(core-flows): update receive returned item by @carlos-r-l-rodrigues in https://github.com/medusajs/medusa/pull/8295
* fix(dashboard): Fix CountrySelect by @kasperkristensen in https://github.com/medusajs/medusa/pull/8301
* fix(dashboard): Cell behaviour in DataGrid by @kasperkristensen in https://github.com/medusajs/medusa/pull/8183
* fix: Updating product prices removed existing prices by @sradevski in https://github.com/medusajs/medusa/pull/8388
* fix: Pass updatedCollections to the hook and not the step by @thetutlage in https://github.com/medusajs/medusa/pull/8402
* fix(core-flows,utils,medusa): fix bug where payment collection across orders were getting updated by @riqwan in https://github.com/medusajs/medusa/pull/8401
* fix: Check for existence of modules when seeding default data by @sradevski in https://github.com/medusajs/medusa/pull/8406
* fix(framework/config): Properly resolve env variables by @adrien2p in https://github.com/medusajs/medusa/pull/8411
* fix: Don't remove pricing if no variant is passed to update by @sradevski in https://github.com/medusajs/medusa/pull/8416
## Documentation
* docs: added guide on how to get product variant prices by @shahednasser in https://github.com/medusajs/medusa/pull/8282
* docs: remove js client and medusa react references by @shahednasser in https://github.com/medusajs/medusa/pull/8270
* docs: update deployment guides for storefront and admin by @shahednasser in https://github.com/medusajs/medusa/pull/8279
* docs: added a service factory reference by @shahednasser in https://github.com/medusajs/medusa/pull/8292
* docs-util: add docblock generator for models built with DML by @shahednasser in https://github.com/medusajs/medusa/pull/8296
* docs-util: update knowledge base of docblock-generator by @shahednasser in https://github.com/medusajs/medusa/pull/8323
* docs: added typedoc plugin to parse DML json files by @shahednasser in https://github.com/medusajs/medusa/pull/8300
* docs-util: rename docblock-generator to docs-generator by @shahednasser in https://github.com/medusajs/medusa/pull/8331
* docs-util: fix knowledge base for functions by @shahednasser in https://github.com/medusajs/medusa/pull/8337
* docs: added storefront guide on prices with taxes by @shahednasser in https://github.com/medusajs/medusa/pull/8326
* docs: fix local link to infer slug from front matter by @shahednasser in https://github.com/medusajs/medusa/pull/8353
* docs-util: fix how data model name is inferred by @shahednasser in https://github.com/medusajs/medusa/pull/8351
* docs-util: support generating helper steps by @shahednasser in https://github.com/medusajs/medusa/pull/8354
* Update page.mdx by @JayabharathiPalanisamy in https://github.com/medusajs/medusa/pull/8366
* docs: added workflow hooks docs + changed workflow response by @shahednasser in https://github.com/medusajs/medusa/pull/8364
* docs: add sidebar item for helper steps reference + examples fix by @shahednasser in https://github.com/medusajs/medusa/pull/8365
* docs: add a documentation on calculating prices with taxes by @shahednasser in https://github.com/medusajs/medusa/pull/8330
* docs-util: mark type parameters as optional by @shahednasser in https://github.com/medusajs/medusa/pull/8320
* docs: added subscription recipe example by @shahednasser in https://github.com/medusajs/medusa/pull/8148
* docs: added digital product recipe example by @shahednasser in https://github.com/medusajs/medusa/pull/8223
* docs: fix recipes sidebar + homepage cards by @shahednasser in https://github.com/medusajs/medusa/pull/8415
## Chores
* chore: Publish framework package by @olivermrbl in https://github.com/medusajs/medusa/pull/8322
* chore(types): add a note about adding `ssl_mode` option to database URLs by @shahednasser in https://github.com/medusajs/medusa/pull/8324
* chore(framework): Continue to move loaders to framework by @adrien2p in https://github.com/medusajs/medusa/pull/8258
* chore(core-flows): cancel claims by @carlos-r-l-rodrigues in https://github.com/medusajs/medusa/pull/8342
* chore(framework): Move feature flags related resources and cleanup by @adrien2p in https://github.com/medusajs/medusa/pull/8297
* chore(framework): Move and improve subscriber loader by @adrien2p in https://github.com/medusajs/medusa/pull/8347
* chore(core-flows,modules-sdk): add TSDocs to helper steps by @shahednasser in https://github.com/medusajs/medusa/pull/8355
* Chore/framework 6/n by @adrien2p in https://github.com/medusajs/medusa/pull/8356
* chore(framework): Move and improve links loader by @adrien2p in https://github.com/medusajs/medusa/pull/8367
* chore(framework): Move and improve workflows loader by @adrien2p in https://github.com/medusajs/medusa/pull/8363
* chore(core-flows): return fulfillment link by @carlos-r-l-rodrigues in https://github.com/medusajs/medusa/pull/8304
* chore(framework): Move and improve routes loader by @adrien2p in https://github.com/medusajs/medusa/pull/8392
* chore(core-flows): use create order step on complete cart by @carlos-r-l-rodrigues in https://github.com/medusajs/medusa/pull/8397
* chore(framework): medusa app loaders by @adrien2p in https://github.com/medusajs/medusa/pull/8393
* chore(workflows-sdk): add TSDocs related to createHook by @shahednasser in https://github.com/medusajs/medusa/pull/8380
* chore: Update labeler to add type labels automatically by @olivermrbl in https://github.com/medusajs/medusa/pull/8410
* chore(framework): Allow multiple source dir for subcribers loader by @adrien2p in https://github.com/medusajs/medusa/pull/8407
## New Contributors
* @JayabharathiPalanisamy made their first contribution in https://github.com/medusajs/medusa/pull/8366
**Full Changelog**: https://github.com/medusajs/medusa/compare/v2.0.2-preview...v2.0.3-preview