Skip to content

v2.0.3-preview

Compare
Choose a tag to compare
@olivermrbl olivermrbl released this 02 Aug 15:57
· 969 commits to develop since this release
4b0119f

Get started with a new project

To get started using the preview release, run the following command:

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

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.

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.

Check out the Digital Products recipe here.

Features

Bugs

Documentation

Chores

New Contributors

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