@chec.io/commerce

Easy to use JavaScript SDK for managing carts and selling products from your chec.io store


Keywords
commerce, shop, ecommerce, chec, chec.io, sdk, carts, checkout, checkouts, commercejs, headless, jamstack, js, open-source, paypal, razorpay, square, storefront, stripe
License
BSD-3-Clause
Install
npm install @chec.io/commerce@2.0.0-beta4

Documentation

Fast, powerful, and easy to use JavaScript SDK for building and managing carts, checkouts and receipts. Build custom eCommerce experiences to sell physical and digital products from the Chec API.

CircleCI Version Downloads/week License
commercejs.com | @commercejs | Slack

Installation

With NPM

npm install @chec/commerce.js or yarn add @chec/commerce.js

TypeScript

You may also install our TypeScript definitions:

npm install @types/chec__commerce.js or yarn add @types/chec__commerce.js

Note that when using TypeScript, the definitions are always compliant with our latest version of the API. If you specify a custom API version, or your API key uses an older version, you may get type errors.

Documentation

See the documentation webpage.

Our documentation module source code resides in commerce.js/docs

If you would like to make contributions to the Commerce.js documentation source, here is a guide in doing so.

Configuration

The following configuration options are available to be defined as the third argument in the Commerce constructor:

  • disableStorage: Whether to disable persistent storage (e.g. cookies). Enable for use in server-side environments. Default: false.
  • cartLifetime: Number of days that a cart should be stored for (between 1 and 30). Default: 30.
  • timeoutMs: The number of milliseconds before a request will time out. Default: 60000.
  • axiosConfig: An optional object containing configuration options for axios, if used.
    • headers: A list of request headers. Defining headers here will override the defaults.
  • allowSecretKey: Commerce.js will prevent you from using a secret API key for authorization. Use this option to override. Default: false.

Upgrading

Upgrading to 2.4.0

Commerce.js 2.4.0 only supports API version 2021-03-31 when adding products to a cart with variants. Please consider updating your API version, using the changes listed in the API docs as a guide.

Upgrading to 2.0.0

The major change in Commerce.js v2 is that most methods now return a promise that is fulfilled when the HTTP request is completed. Instead of providing callbacks to the methods in this module, you will have to use promise syntax instead.

- Commerce.Cart.retrieve(function (data) {
+ Commerce.cart.retrieve().then(function (data) {
  // ...
});

Additionally, the API for the various features are now lower-cased.

The cart.add() method now separates its arguments:

- Commerce.Cart.add({ productId: 1, quantity: 2, variant: { foo: 'bar'} })
+ Commerce.cart.add(1, 2, {foo: 'bar'})

Contributing

Check out the contributing guide

Get help

Commerce.js is a project by many contributors. Reach us on Slack and Twitter.

Compilation

The lib files are automatically compiled by our continuous integration pipeline. You only need to commit changes to the src files.

Running the tests

You can run the unit tests for this library from your command line using npm run test, or npm run test:watch to watch for changed and re-run the tests automatically.

Code style

We use the Airbnb JavaScript style guide, and Prettier as our linting tool. To lint your code, use npm run lint or npm run lint:fix to automatically fix violations.