Files
medusa-store/packages/medusa-js
Adrien de Peretti fc1cbe72c7 feat(medusa-js): Create utils to stringify null values and respect object types (#1748)
### What

At the moment it is not possible to pass explicitly null on a property since the qs.stringify will transform it as `url?property=` which is then interpreted on the backend side as `""` value which is not what we expect.
The actual way to pass null value is to set the property as `{ prop: "null" }` in order to get the stringify method to send it correctly.

### How

I just created a small util that loop through the input object and transform all null values to "null" before being passed to the qs.stringify method.

The new util is only applied on the list batch job since this is for now the only place that require that behaviour.
2022-06-30 09:17:57 +00:00
..
2022-06-19 13:11:05 +02:00
2022-06-19 13:11:05 +02:00

Medusa JS Client

Version

The Medusa JS Client provides easy access to the Medusa API from a client written in Typescript.

Documentation

See our API reference.

Installation

Install the package with:

npm install @medusajs/medusa-js
# or
yarn add @medusajs/medusa-js

Usage

Import Medusa as a default import and initiate it:

import Medusa from "@medusajs/medusa-js"

const medusa = new Medusa()

const { cart } = await medusa.carts.create({})

Authentication

Authentication can be achieved in two ways using the medusa-js client, either by utilizing API keys or by using cookie based authentication, each with their own unique use case.

Using API keys

API keys can only be used for admin functionality in Medusa because only users of the admin system have api keys. To use API keys for authentication the key should be used when medusa-js is initialized with a config object as described below.

Using cookies

Authentication using cookies is done automatically by Axios when authenticating using the auth endpoints. After authentication all subsequent calls will be authenticated.

note: Cookie based authentication cannot be used in plain node.js applications due to the limitations of axios and useCredentials not setting the Cookie request header when set-cookie is present in the response headers. For pure node.js applications use authentication with api keys(see above)

Configuration

Initialize with config object

The package can be initialized with several options:

const medusa = new Medusa({
  maxRetries: 3,
  baseUrl: "https://api.example.com",
})
Option Default Description
maxRetries 0 The amount of times a request is retried.
baseUrl 'http://localhost:9000' The url to which requests are made to.
apiKey '' Optional api key used for authenticating admin requests .