0.0.2-alpha.94 • Published 5 years ago

commerce-sdk1 v0.0.2-alpha.94

Weekly downloads
-
License
ISC
Repository
-
Last release
5 years ago

commerce-sdk

The Commerce SDK allows easy interaction with the B2C Commerce platform APIs on the Node.js runtime.

Prerequisites

Node.js - Install Node.js and npm here

Note: We currently only support Node.js version 10. Using a different version of Node.js may lead to unexpected results. If you are currently using a different version of Node.js and would like to continue using it for other projects, you can use nvm to manage multiple versions of Node.js.

Installation

Execute the following command to install the Commerce SDK.

npm install commerce-sdk

Usage

To use an SDK client, an object of that client must be instantiated. The following parameters may be used to configure the client during instantiation.

Note: All the following parameters are optional.

ParameterDescription
baseUriURL of the service the SDK will interact with. If the baseUri is not provided, the default baseUri for the relevant RAML file is used.
clientIdID of the client account created with Salesforce Commerce Cloud.
clientSecretSecret associated with the client ID provided above.

Sample code

/**
 * A sample TypeScript code to show how Commerce SDK can be used to access 
 * Salesforce B2C Commerce platform APIs
 */

// Import the SDK
import { Shop } from 'commerce-sdk';

// Instantiate Shop client object with the configuration details
const shopClient = new Shop({
    baseUri: "https://somewhere.com/v1/shop",
    clientId: 'test-client-id',
    clientSecret: 'test-client-secret'
});

// Get a list of currencies allowed by a merchant
shopClient.getSite()
    .then(response => {
        // Do something with the response
        return response.allowed_currencies;
    })
    .catch(error => {
        // Do something with the error
        throw new Error(`Error fetching allowed currencies: ${error}`);
    });

If you use an IDE, you can use its autocomplete feature to peek at all the available methods and variables defined in that client class.

Autocomplete

You can also see the details of a method or a variable by hovering over them.

Method Details

Documentation

TBA

Contributing

TBA

License

The Commerce SDK is licensed under BSD-3-Clause license. See the license for more details.

References

TBA

0.0.2-alpha.94

5 years ago