JS library for building storefronts and checkouts with Swell ecommerce.
Swell.js is a headless ecommerce storefront SDK that provides a Universal JavaScript client for Swell’s Frontend API. It allows developers to have client-safe access to store and customer data. This SDK can be used in various applications like JAMstack or SSR apps to perform a range of functions such as fetching products, categories, store settings, nav menus, and custom content; creating, recovering, and updating shopping carts; building custom checkout and subscription flows; authenticating customers and allowing them to edit account details, orders, and subscriptions; resolving linked content to dynamically generate page URLs; and formatting prices in the store’s currency. The SDK is designed to be safe to use in any context, as it implements a subset of operations available in Swell’s Backend API and is authorized with a public key + session token. It is recommended to only use the Backend API server-side and store secret keys as environment variables.
To install Swell.js, follow these steps:
npm install @swell-js/swell
or
yarn add @swell-js/swell
import { Swell } from "@swell-js/swell";
const swell = new Swell({
publicKey: "YOUR_PUBLIC_KEY",
sessionToken: "YOUR_SESSION_TOKEN",
});
Swell.js is a versatile SDK for developers to integrate Swell’s ecommerce functionality into their applications. With a range of features, it allows developers to fetch data, manage shopping carts, build checkout and subscription flows, and handle customer authentication and account management. By implementing a subset of operations from Swell’s Backend API and using a public key + session token authorization approach, Swell.js ensures a safe and secure integration. Developers can use this SDK in a variety of application types and easily access store and customer data.