Installation and Deployment

To use the Digital Commerce SDK, you must first import the node_module for it. Follow the steps here:

  1. Add the digitalcommerce-sdk dependency in your package.json, as shown here:

    1"dependencies": {
    2	// Existing dependencies
    3    "@vlocity-cme-sdk/digitalcommerce-sdk" : "^109.0.1"
    4  }
  2. Create an NPM configuration file called .npmrc. The .npmrc file is needed to authenticate with the private npm registry. Here is a sample:

    1email=you@example.com
    2always-auth=true
    3_auth=<password> (see Note, below)
    4registry=https://repo.vlocity.com/repository/npm-public/

    To obtain the password for the .npmrc file:

    • Contact Salesforce Customer Support. Note that you must have purchased a CPQ License.

    Note

    For public access, use the default authorization token mentioned in the above example.

    1// To fetch the module you would need to run
    2npm install

    The artifact can be found in the node_modules folder under the module name @vlocity-cme-sdk/digitalcommerce-sdk

  3. You can access digitalcommerce.sdk.js either from node_modules (inside the above-mentioned folder) or by moving it inside public/static resource of the application that is using it. Following is an example of what it should look like:

    1<script type="text/javascript" src="../digitalcommerce-sdk/digitalcommerce.sdk.js"></script>

    Once the digitalcommerce.sdk.js is added into the application, the following steps can be followed for using it.

  4. Instantiate DigitalCommerceSDK:

    1// Instantiate DigitalCommerceConfig for anonymous user
    2const digitalCommerceConfig = VlocitySDK.digitalcommerce.createConfigForAnonymousUser();
    3
    4// Instantiate the SDK itself
    5const digitalCommerce = VlocitySDK.digitalcommerce.getInstance(digitalCommerceConfig);
    6
    7OR
    8
    9// Instantiate DigitalCommerceConfig for login user
    10const digitalCommerceConfig = VlocitySDK.digitalcommerce.createConfigForLoginUser(salesforceUrl, sessionToken);
    11
    12// Instantiate the SDK itself
    13const digitalCommerce = VlocitySDK.digitalcommerce.getInstance(digitalCommerceConfig);
    14
    15// To override the default namespace with your custom namespace
    16this.digitalCommerce.namespace = "vlocity_cmt"; // use your custom namespace
    17
    18Note:
    19digitalCommerce is a Singleton object.  Calling getInstance(digitalCommerceConfig) repeatedly will return the same instance instantiated the first time when getInstance(digitalCommerceConfig) was called.
    20
    21To instantiate a new instance of digitalCommerce, set create to true in the digitalCommerceConfig object:
    22digitalCommerceConfig.create = true;
    23digitalCommerce = VlocitySDK.digitalcommerce.getInstance(digitalCommerceConfig);
    24
    25// To override the anonymous site url with your custom url
    26digitalCommerce.apiURL =
    27  "https://myaws.execute-api.us-west-2.amazonaws.com/prod/dc"; // use your AWS gateway