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:

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

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

    note: To obtain the password for the .npmrc file:

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

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

    // To fetch the module you would need to run
    npm 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:

    <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:

    // Instantiate DigitalCommerceConfig for anonymous user
    const digitalCommerceConfig = VlocitySDK.digitalcommerce.createConfigForAnonymousUser();
    
    // Instantiate the SDK itself
    const digitalCommerce = VlocitySDK.digitalcommerce.getInstance(digitalCommerceConfig);
    
    OR
    
    // Instantiate DigitalCommerceConfig for login user
    const digitalCommerceConfig = VlocitySDK.digitalcommerce.createConfigForLoginUser(salesforceUrl, sessionToken);
    
    // Instantiate the SDK itself
    const digitalCommerce = VlocitySDK.digitalcommerce.getInstance(digitalCommerceConfig);
    
    // To override the default namespace with your custom namespace
    this.digitalCommerce.namespace = "vlocity_cmt"; // use your custom namespace
    
    Note:
    digitalCommerce is a Singleton object.  Calling getInstance(digitalCommerceConfig) repeatedly will return the same instance instantiated the first time when getInstance(digitalCommerceConfig) was called.
    
    To instantiate a new instance of digitalCommerce, set create to true in the digitalCommerceConfig object:
    digitalCommerceConfig.create = true;
    digitalCommerce = VlocitySDK.digitalcommerce.getInstance(digitalCommerceConfig);
    
    // To override the anonymous site url with your custom url
    digitalCommerce.apiURL =
      "https://myaws.execute-api.us-west-2.amazonaws.com/prod/dc"; // use your AWS gateway