commerce-sdk-isomorphic
The Salesforce Commerce SDK Isomorphic allows easy interaction with the Salesforce B2C Commerce platform Shopper APIs through a lightweight SDK that works both on browsers and NodeJS applications. For a more robust SDK, which includes our B2C Data APIS and Shopper APIs, see our Node.js Commerce SDK.
Getting Started
Requirements
- Node
^12.x
, ^14.x
, or ^16.x
Installation
npm install commerce-sdk-isomorphic
Usage
Note: These are required parameters.
Parameter | Description |
---|
clientId | ID of the client account created with Salesforce Commerce. |
organizationId | The unique identifier for your Salesforce identity. |
shortCode | Region-specific merchant ID. |
siteId | Name of the site to access data from, for example, RefArch or SiteGenesis. |
import {helpers, ShopperLogin, ShopperSearch} from 'commerce-sdk-isomorphic';
const config = {
proxy: 'https://localhost:3000',
headers: {},
parameters: {
clientId: '<your-client-id>',
organizationId: '<your-org-id>',
shortCode: '<your-short-code>',
siteId: '<your-site-id>',
},
throwOnBadResponse: true,
};
const shopperLogin = new ShopperLogin(config);
const {access_token, refresh_token} = await helpers.loginGuestUser(
shopperLogin,
{redirectURI: `${config.proxy}/callback`}
);
const shopperSearch = new ShopperSearch({
...config,
headers: {authorization: `Bearer ${access_token}`},
});
const searchResult = await shopperSearch.productSearch({
parameters: {q: 'shirt'},
});
Advanced options
Commerce SDK Isomorphic supports Fetch API options for node-fetch on server and whatwg-fetch on browser with a simple configuration.
This sample code shows how to configure HTTP timeout and agent options.
const https = require('https');
const config = {
proxy: 'https://localhost:3000',
headers: {},
parameters: {
clientId: '<your-client-id>',
organizationId: '<your-org-id>',
shortCode: '<your-short-code>',
siteId: '<your-site-id>',
},
fetchOptions: {
timeout: 2000,
agent: new https.agent({
keepAlive: true,
}),
},
};
Additional Config Settings
headers: A collection of key/value string pairs representing additional headers to include with API requests.
throwOnBadResponse: Default value is false. When set to true, the SDK throws an Error on responses with statuses that are not 2xx or 304.
Public Client Shopper Login helpers
A collection of helper functions are available in this SDK to simplify Public
Client Shopper Login OAuth
flows. See sample code above for guest login.
License Information
The Commerce SDK Isomorphic is licensed under BSD-3-Clause license. See the license for details.