Skip to main content

Package Setup

This library can be used with JavaScript applications in both server and client aspects.

Installation

Add @rechargeapps/storefront-client to your project:

npm install @rechargeapps/storefront-client

Recharge JavaScript SDK is tested for/with Node LTS and Evergreen browsers.

Initialization v1.0.0 Types

To initialize the JavaScript SDK you call initRecharge and pass the following arguments:

  • storeIdentifier - optional when JavaScript SDK is used within Shopify or Recharge hosted environments, required for headless usage. On Shopify this should be your myshopify.com domain.
  • storefrontAccessToken - optional, but required when using the API functions (see API for additional details)
  • loginRetryFn - optional, middleware function that should return a Session, called when API functions return a 401. This function allows your app to refetch a session, store it by whatever means your app uses for future calls, then return it so the call that failed can be retried.
info

Access to the storefront API functions require SDK to be initialized with a Recharge storefrontAccessToken - this token can be created via the merchant-admin where you manage your API tokens. Please make sure that the created token is of type Storefront. You can verify you have created the correct token by double checking it starts with strfnt.

import { initRecharge, loginShopifyAppProxy } from '@rechargeapps/storefront-client';

initRecharge({
storeIdentifier: 'storeIdentifier', // On Shopify this should be your myshopify.com domain
// required for Storefront API access
storefrontAccessToken: 'storefrontAccessToken',
loginRetryFn: async () => {
const session = await loginShopifyAppProxy();
...
// store recharge session
...
return session;
}
});