v1.19.0

medusajs/medusav1.19.0Dec 14, 2023by olivermrbl

AI Summary

Delivers performance improvements, introduces retry logic for the client SDK, and changes the cart completion response strategy.

Key Highlights

  • Cart-completion strategy response changes (no longer 409, returns Order/Swap)
  • `node-redis` replaced with `ioredis` for session management
  • Add to cart performance improvements (concurrent request handling)
  • New cluster command added to `@medusajs/medusa-cli`
  • Retry support in `medusa-react` (`maxRetries` prop)

Breaking Changes

  • Cart-completion strategy response no longer returns 409 conflict
  • `node-redis` replaced with `ioredis` for session management

New Features

  • Custom database config in shared mode
  • Order response on completed cart
  • Monorepo support command (`develop`)
  • Korean language support
  • Price List Prices with own rules
  • Product import/export uses workflows

Full Release Notes

<!-- 
![v1-19-0](https://github.com/medusajs/medusa/assets/59018053/3c343695-59c8-409b-a038-3563ef5273e1)

# Version 1.19.0

This version comes with significant performance improvements and improved retry logic in our client SDKs.

CMS_BREAK -->

## Highlights

### Cart-completion strategy response

> 🚧 **Breaking change**

Attempting to complete an already completed cart will no longer return a 409 conflict. Instead, the order or swap associated with the completed cart is returned. 

More specifically, the response will take one of the following two shapes:
```ts
// completing a regular cart
{
  response_code: 200,
  response_body: { data: order, type: "order" },
}

// completing a swap cart
{
  response_code: 200,
  response_body: { data: swap, type: "swap" },
}
```

### `node-redis` replaced with `ioredis` for session management

> 🚧 **Important change**

Our default Express session store has been changed from `node-redis` to `ioredis`. 

This was done in response to a request for higher configurability of the Redis client used for session management. It was decided to not only expose more options but simultaneously change the library to `ioredis` to be consistent with other packages that use Redis, e.g. the Redis Event Bus + Redis Cache.

### Add to cart performance improvements

The add-to-cart endpoint, `POST /store/carts/:id/line-items`, has been refactored, improving performance and transaction management. The latter was done in response to some users experiencing issues with concurrent requests leading to database conflicts. The changes to transaction management in the endpoint should significantly reduce the risk of this issue occurring while improving performance.

Some rough benchmarks show that for 1000 requests (10-20/s), we see approx. 30% of requests fail due to database conflicts in the latest version. With this PR, 0% of requests fail – even under a higher load.

### New cluster command added to `@medusajs/medusa-cli`

A new cluster command has been added to our CLI, `@medusajs/medusa-cli`:

```bash
medusa start-cluster --cpus 3 
```

The command allows you to start Medusa in [cluster mode](https://expressjs.com/en/advanced/best-practice-performance.html#run-your-app-in-a-cluster). By default, cluster mode will try to consume all available CPUs for Medusa instances. You can specify the number of CPUs with a CLI argument `--cpus`.

Running in cluster mode will likely significantly improve performance as the workload and tasks are distributed among all available instances instead of a single one. 

### Retry support in `medusa-react`

> 🚧 **Important change**

You can now specify `maxRetries` as a prop to the `MedusaProvider` from `medusa-react`. This config is passed on to the underlying `medusa-js` client, which means failed requests are retried the amount of times specified by the param. If not provided, the `maxRetries` defaults to 3.

```tsx
import { MedusaProvider as Provider } from "medusa-react"
import { queryClient } from "../constants/query-client"

export const MedusaProvider = ({ children }) => {
  return (
    <Provider
      queryClientProviderProps={{
        client: queryClient,
      }}
      baseUrl={process.env.MEDUSA_BACKEND_URL}
      maxRetries={2}
    >
      {children}
    </Provider>
  )
}

```

## Features
* feat(link-modules, pricing, product, utils): Should be able to set some custom database config even in shared mode by @adrien2p in https://github.com/medusajs/medusa/pull/5755
* feat(medusa): Respond with order when cart is already completed by @olivermrbl in https://github.com/medusajs/medusa/pull/5766
* feat(medusa-cli): add monorepo support command develop by @driver005 in https://github.com/medusajs/medusa/pull/5723
* feat(admin): Add Korean language support by @iweurman in https://github.com/medusajs/medusa/pull/5769
* feat(medusa-payment-klarna): Add language variable by @edinskeja in https://github.com/medusajs/medusa/pull/4483
* feat(medusa): Improve add line item to cart perf and transaction management + clustering start command by @adrien2p in https://github.com/medusajs/medusa/pull/5701
* feat(medusa): Replace Node Redis with ioredis by @pepijn-vanvlaanderen in https://github.com/medusajs/medusa/pull/5656
* feat(core-flows,pricing,medusa,pricing,types,utils): Price List Prices can have their own rules by @riqwan in https://github.com/medusajs/medusa/pull/5752
* feat(medusa): Emit "discount.created" event when discount is created by @Arsenalist in https://github.com/medusajs/medusa/pull/5816
* feat(orchestration,core-flows,medusa,product,types,utils): product import/export uses workflows by @riqwan in https://github.com/medusajs/medusa/pull/5811
* feat(medusa, core-workflows, product): slightly improve create cart workflow by @adrien2p in https://github.com/medusajs/medusa/pull/5725
* feat(admin-ui): metadata for categories in admin ui and refactor to react-hook-form by @luluhoc in https://github.com/medusajs/medusa/pull/5697

## Bugs
* fix(medusa): throw proper error when product doesn't exist w/ key header by @pKorsholm in https://github.com/medusajs/medusa/pull/5745
* fix(modules-sdk): add graphql dependency to modules-sdk by @riqwan in https://github.com/medusajs/medusa/pull/5750
* fix(medusa-react): Allow setting maxRetries on MedusaProvider by @kasperkristensen in https://github.com/medusajs/medusa/pull/5765
* fix(ui): Bump cva and minor type fixes by @kasperkristensen in https://github.com/medusajs/medusa/pull/5818
* fix(admin-ui): Bulk editor default fields by @kasperkristensen in https://github.com/medusajs/medusa/pull/5829
* fix(medusa): Updating note doesn't require loading author relationship by @josetr in https://github.com/medusajs/medusa/pull/5825
* fix(medusa): Product option values in CSV Export by @mortenengel in https://github.com/medusajs/medusa/pull/5781
* fix(medusa): Order edit confirmation conflict line items update by @adrien2p in #5867

## Docs
* docs: fix back link in Workflows API Reference by @shahednasser in https://github.com/medusajs/medusa/pull/5740
* docs: updated user guide for product pricing by @shahednasser in https://github.com/medusajs/medusa/pull/5744
* docs: fix back links for modules references by @shahednasser in https://github.com/medusajs/medusa/pull/5747
* docs: updated next.js starter docs by @shahednasser in https://github.com/medusajs/medusa/pull/5748
* docs: update pricing module docs with the latest changes by @riqwan in https://github.com/medusajs/medusa/pull/5749
* docs: fix typo in onboarding by @shahednasser in https://github.com/medusajs/medusa/pull/5802
* docs: search results template needs the product ids to fetch previews by @chrislaai in https://github.com/medusajs/medusa/pull/5793
* docs: enhance how references are generated by @shahednasser in https://github.com/medusajs/medusa/pull/5805
* docs: update algolia plugin next.js details by @shahednasser in https://github.com/medusajs/medusa/pull/5807
* docs: added examples for modules usage in Medusa by @shahednasser in https://github.com/medusajs/medusa/pull/5753
* docs: diagrams plugin tooling by @shahednasser in https://github.com/medusajs/medusa/pull/5741
* docs: updated Next.js deployment guide by @shahednasser in https://github.com/medusajs/medusa/pull/5756
* docs: TSDoc + reference of fulfillment by @shahednasser in https://github.com/medusajs/medusa/pull/5761
* docs: added "Integrate Your Ecommerce Stack" recipe by @shahednasser in https://github.com/medusajs/medusa/pull/5774
* docs(plugins): puts local-file plugin into correct category in site by @annikorp in https://github.com/medusajs/medusa/pull/5804
* docs: update local events module to fix mistyped reference to redis events module by @ishaqkhattana in https://github.com/medusajs/medusa/pull/5835
* docs: Fix multiple typos in medusa docs by @Sajarin-M in https://github.com/medusajs/medusa/pull/5854
* docs: fixed sidebar in API reference by @shahednasser in https://github.com/medusajs/medusa/pull/5871
* docs: update required Node.js version for Next.js starter by @shahednasser in https://github.com/medusajs/medusa/pull/5859
* docs: generate documentation for UI components by @shahednasser in https://github.com/medusajs/medusa/pull/5849

## Chores
* chore(): Add engines to all package.json if needed by @adrien2p in https://github.com/medusajs/medusa/pull/5812
* chore(medusa): Prefer logger instead of console.log by @adrien2p in #5846

## New Contributors
* @driver005 made their first contribution in https://github.com/medusajs/medusa/pull/5723
* @iweurman made their first contribution in https://github.com/medusajs/medusa/pull/5769
* @chrislaai made their first contribution in https://github.com/medusajs/medusa/pull/5793
* @annikorp made their first contribution in https://github.com/medusajs/medusa/pull/5804
* @luluhoc made their first contribution in https://github.com/medusajs/medusa/pull/5697
* @ishaqkhattana made their first contribution in https://github.com/medusajs/medusa/pull/5835
* @Arsenalist made their first contribution in https://github.com/medusajs/medusa/pull/5816
* @Sajarin-M made their first contribution in https://github.com/medusajs/medusa/pull/5854

**Full Changelog**: https://github.com/medusajs/medusa/compare/v1.18.1...v1.19.0