Options
All
  • Public
  • Public/Protected
  • All
Menu

Digital Commerce Facade to interact with Vlocity Digital Commercee functionality.

The Digital Commerce SDK is a JavaScript library that abstracts and simplifies the use of Digital Commerce API REST calls.

The SDK provides error checking and validates parameters before submitting them to the Digital Commerce APIs, ensuring that calls to the APIs are well formatted and complete. In some cases, the SDK invokes more than one API to complete a request.

Using the SDK ensures that errors are detected before API calls are made, ensuring that Vlocity data structure rules are enforced and that data is not written incorrectly to the Vlocity cart or to the product database.Using the SDK reduces UI development efforts by consolidating common application and business logic to use the Digital Commerce APIs.

SDK can be shared by different applicationsuser interfaces. SDK, like any Vlocity SDK, can be extended and overrided to customized implementations.

version

109.0.0

Hierarchy

Index

Constructors

Properties

Accessors

Methods

Constructors

constructor

  • Default constructor. Alwyas use getInstance() instead of default contructor to get an instance of the SDK.

    Parameters

    Returns DigitalCommerce

Properties

accountId

accountId: string

This is the account Id once user login in.

Private cartContextKey

cartContextKey: string = null

cartId

cartId: string

Identifier of cart if it exists. This will be populated after addToCart() is called.

Private cartResponse

cartResponse: any

This is addToBasket response.

Private context

context: UserContext

The UserContext used for this SDK.

currentOfferCode

currentOfferCode: string

The offer code of the offer that is being configured at the moment.

Private datasource

datasource: DataSource

The datasource connection used by this SDK.

Private filteredPromotionList

filteredPromotionList: any

This is the filtered list containing promotions and products.

Optional isUserLoggedIn

isUserLoggedIn: boolean = false

Flag to indicate whether user already loggedIn

Private offersInConfiguration

offersInConfiguration: any[]

Map of offers that has been selected for configuration. This map stores the state of the configured offers.

Private offersList

offersList: any = []

This is the offers list containing promotions and products.

Private parsedCartItem

parsedCartItem: any

parsed cart item response.

Optional userEmail

userEmail: string

loggedIn user email

Static Private instance

instance: DigitalCommerce

Private singleton instance of this SDK. There should always be only 1 instance.

Accessors

apiURL

  • set apiURL(apiURL: string): void
  • Customers can override their custom anonymous URL using apiURL

    Parameters

    • apiURL: string

    Returns void

authToken

  • set authToken(authToken: string): void
  • Customers can set the anonymous URL auth token using authToken

    Parameters

    • authToken: string

    Returns void

authTokenExpirationTime

  • set authTokenExpirationTime(tokenExpirationTime: number): void
  • Parameters

    • tokenExpirationTime: number

    Returns void

authTokenType

  • set authTokenType(authTokenType: string): void
  • Parameters

    • authTokenType: string

    Returns void

clientId

  • set clientId(clientId: string): void
  • Parameters

    • clientId: string

    Returns void

clientSecret

  • set clientSecret(clientSecret: string): void
  • Parameters

    • clientSecret: string

    Returns void

namespace

  • get namespace(): string
  • set namespace(customNamespace: string): void
  • getter method for namespace. Provides the salesforce org namespace

    Returns string

  • setter method for namespace. Set custom namespace

    Parameters

    • customNamespace: string

    Returns void

oauth2Url

  • set oauth2Url(oauth2Url: string): void
  • Parameters

    • oauth2Url: string

    Returns void

secureServerRequestCredentials

  • set secureServerRequestCredentials(requestCredentails: RequestCredentials): void
  • Customers can override secureServerRequestCredentials value using secureServerRequestCredentials()

    Parameters

    • requestCredentails: RequestCredentials

    Returns void

secureServerUrl

  • set secureServerUrl(serverUrl: string): void
  • Customers can override their custom checkout node server URL using secureServerUrl()

    Parameters

    • serverUrl: string

    Returns void

Methods

Private addSelectedOffer

  • addSelectedOffer(offer: any): void
  • Cache the selected offer in memory so that user can retrieve it at later point of time for configuration and add to cart. The selected offer JSON and its offer code will be cached by SDK.

    Parameters

    • offer: any

    Returns void

addToCart

  • Save an offer to the Basket.

    example
    
    // Case a: addToCart with basketAction=AddWithNoConfig MUST have offer as input parameter
    // Instantiate the input object for addToCart to specify parameters
    const input = digitalCommerce.createAddToCartInput();
    input.catalogCode = "Mobiles"; // use your Catalog Code
    input.basketAction = "AddWithNoConfig"; // adding an offer that has not been configured (no change in its json structure from getOfferDetails) to cart
    input.offer = "iPhone8Offer"; // use your Offer Code to be added to basket
    
    // Case b: addToCart with basketAction=AddAfterConfig MUST have productConfig as input parameter
    // Instantiate the input object for addToCart to specify parameters
    const input = digitalCommerce.createAddToCartInput();
    input.catalogCode = "Mobiles"; // use your Catalog Code
    input.basketAction = "AddAfterConfig"; // adding an offer that has been configured (change in its json structure from getOfferDetails) to cart
    input.productConfig = {...};
    
    // Case c: addToCart with basketAction=DeleteFromBasket MUST have actionParams as input parameter
    // Instantiate the input object for addToBasket to specify parameters
    const input = digitalCommerce.createAddToCartInput();
    input.catalogCode = "Mobiles"; // use your Catalog Code
    input.basketAction = "DeleteFromBasket"; // deleting an offer that was added to cart
    input.actionParams = {lineItemKey:'', cartContextKey:'', bundleContextKey:''}
    
    // Invoke cart API via method addToCart()
    digitalCommerce
      .addToCart(input)
     .then(response => {
        Logger.info(
          "Vlocity digital commerce addToCart with basketAction=DeleteFromBasket for anonymous user: " +
            JSON.stringify(response)
        );
      })
      .catch(error => {
        Logger.info(
          "addToCart with basketAction=DeleteFromBasket for anonymous user rest call failed" +
            error
        );
      });
    
    // Case d: addToCart with basketAction=AddChildProduct MUST have actionParams as input parameter
    // Instantiate the input object for addToBasket to specify parameters
    const input = digitalCommerce.createAddToCartInput();
    input.catalogCode = "Mobiles"; // use your Catalog Code
    input.basketAction = "AddChildProduct"; // adding child offerto existing offer in cart.
    input.actionParams = {rootProductCode:'', parentLineKey:'', parentHierarchyPath:'', offer:'', cartContextkey:'', bundleContextKey:''}
    
    // Invoke cart API via method addToCart()
    digitalCommerce
      .addToCart(input)
     .then(response => {
        Logger.info(
          "Vlocity digital commerce addToCart with basketAction=AddChildProduct for anonymous user: " +
            JSON.stringify(response)
        );
      })
      .catch(error => {
        Logger.info(
          "addToCart with basketAction=AddChildProduct for anonymous user rest call failed" +
            error
        );
      });
    
    // Case 3: addToCart with basketAction=DeleteChildProduct MUST have actionParams as input parameter
    // Instantiate the input object for addToBasket to specify parameters
    const input = digitalCommerce.createAddToCartInput();
    input.catalogCode = "Mobiles"; // use your Catalog Code
    input.basketAction = "DeleteChildProduct"; // adding child offerto existing offer in cart.
    input.actionParams = { lineItemKey:'', cartContextkey:'', bundleContextKey:''}
    
    // Invoke cart API via method addToCart()
    digitalCommerce
      .addToCart(input)
     .then(response => {
        Logger.info(
          "Vlocity digital commerce addToCart with basketAction=DeleteChildProduct for anonymous user: " +
            JSON.stringify(response)
        );
      })
      .catch(error => {
        Logger.info(
          "addToCart with basketAction=DeleteChildProduct for anonymous user rest call failed" +
            error
        );
      });
    
    throws

    "AddToCartInput::getAPIPath() must have catalogCode."

    throws

    "AddToCartInput::getAnonymousRestUrl() must have anonymousSiteUrl."

    throws

    "AddToCartInput::getAnonymousSiteRestUrl() must have catalogCode."

    throws

    "AddToCartInput::getRequestPayload() must have basketAction."

    throws

    "AddToCartInput::getRequestPayload() must have offer when basketAction is 'AddWithNoConfig'."

    throws

    "AddToCartInput::getAPIPath() must have catalogCode."

    throws

    "AddToCartInput::getAnonymousRestUrl() must have anonymousSiteUrl."

    throws

    "AddToCartInput::getAnonymousSiteRestUrl() must have catalogCode."

    throws

    "AddToCartInput::getRequestPayload() must have basketAction."

    throws

    "AddToCartInput::getRequestPayload() must have productConfig when basketAction is 'AddAfterConfig'."=

    throws

    "AddToCartInput::getAPIPath() must have catalogCode."

    throws

    "AddToCartInput::getAnonymousRestUrl() must have anonymousSiteUrl."

    throws

    "AddToCartInput::getAnonymousSiteRestUrl() must have catalogCode."

    throws

    "AddToCartInput::getRequestPayload() must have basketAction."

    throws

    "AddToCartInput::getRequestPayload() must have deleteBundleNumber when basketAction is 'DeleteFromBasket'."

    Parameters

    Returns Promise<Cart>

addToCartPostHook

  • addToCartPostHook(addToCartResponse?: any): any
  • addToCart SDK call posthook method.

    example
    
    // How to override addToCartPostHook method
    VlocitySDK.digitalcommerce.override({ addToCartPostHook(offerResponse){
      console.log("addToCartPostHook method is being overridden");
    }});
    

    Parameters

    • Optional addToCartResponse: any

    Returns any

assetToBasket

  • Convert asset to the basket.

    example
    
    // Instantiate the input object for assetToBasket to specify parameters
    const input = digitalCommerce.createAssetToBasketInput();
    input.catalogCode = "Phones"; // use your Catalog Code
    input.basketAction = "assetToBasket";
    input.isLoggedIn = true;
    input.canCreateBasket = false; // optional - default is false
    input.context = '{"accountId":"YOUR ACCOUNT ID"}';
    input.validatePrice = true; // optional - default is true
    input.validateAction = true; // optional - default is true
    input.rootAssetIds = "02i4P000009ion5QAA,02i4P000009ion6QAA";
    input.requestDateTime = "2019-08-10T00:00:000z"; // date or date time in UTC format.
    
    // Invoke assetToBasket API via method assetToBasket()
    digitalCommerce
      .assetToBasket(input)
     .then(response => {
        Logger.info(
          "Vlocity digital commerce assetToBasket: " +
            JSON.stringify(response)
        );
      })
      .catch(error => {
        Logger.info(
          "assetToBasket apexrest call failed" +
            error
        );
      });
    
    throws

    "AssetToBasketInput::getAPIPath() must have catalogCode."

    throws

    "AssetToBasketInput::getAPIPath() must have context."

    throws

    "AssetToBasketInput::getAPIPath() must have set isLoggedIn=true."

    throws

    "AssetToBasketInput::getRequestPayload() must have rootAssetIds."

    throws

    "AssetToBasketInput::getRequestPayload() must have basketAction."

    throws

    "AssetToBasketInput::getRequestPayload() must have valid requestDateTime input."

    Parameters

    Returns Promise<any>

assetToBasketPostHook

  • assetToBasketPostHook(assetToBasketResponse?: any): any
  • assetToBasket SDK call posthook method.

    example
    
    // How to override assetToBasketPostHook method
    VlocitySDK.digitalcommerce.override({ assetToBasketPostHook(offersResponse){
      console.log("assetToBasketPostHook method is being overridden");
    }});
    

    Parameters

    • Optional assetToBasketResponse: any

    Returns any

authenticateUser

  • Authenticate the user.

    example
    
    // Instantiate the input object for authenticateUser to specify parameters
    const input = digitalCommerce.createAuthenticateUserInput();
    input.email = "YOUR EMAIL ID";
    input.password = "YOUR PASSWORD";
    input.phoneNumber = "1234567889";
    input.firstName = "YOUR FIRST NAME";
    input.lastName = "YOUR LAST NAME";
    
    // Invoke authenticateUser API via method authenticateUser()
    digitalCommerce
      .authenticateUser(input)
     .then(response => {
        Logger.info(
          "Vlocity digital commerce authenticateUser: " +
            JSON.stringify(response)
        );
      })
      .catch(error => {
        Logger.info(
          "authenticateUser apexrest call failed" +
            error
        );
      });
    
    throws

    "AuthenticateUserInput::getRequestPayload() must have email."

    throws

    "AuthenticateUserInput::getRequestPayload() must have password."

    throws

    "AuthenticateUserInput::getRequestPayload() must have phoneNumber."

    throws

    "AuthenticateUserInput::getRequestPayload() must have firstName."

    throws

    "AuthenticateUserInput::getRequestPayload() must have lastName."

    Parameters

    Returns Promise<any>

authenticateUserPostHook

  • authenticateUserPostHook(authenticateUserResponse?: any): any
  • authenticateUser SDK call posthook method.

    example
    
    // How to override authenticateUserPostHook method
    VlocitySDK.digitalcommerce.override({ authenticateUserPostHook(offersResponse){
      console.log("authenticateUserPostHook method is being overridden");
    }});
    

    Parameters

    • Optional authenticateUserResponse: any

    Returns any

checkoutCart

  • Checkout the cart items that user has configured in the cart.

    example
    
    // Instantiate the input object for checkoutCart() to specify parameters
    const input = digitalCommerce.checkoutCartInput();
    input.catalogCode = "tv"; // use your Catalog Code
    input.accountId = "001f200001eSlhe"; // use your account id
    input.cartContextKey = "d5ff11cccd19472ca7c21fa80bc93d2a"
    
    
    // Used in Checkout process to persist shopping cart content into SF Database
    digitalCommerce
      .checkoutCart(input)
      .then(result => {
        Logger.info(
          "vlocity checkout cart anonymous user rest call" + JSON.stringify(result)
        );
      })
      .catch(error => {
        Logger.info("Checkout cart for anonymous user rest call failed" + error);
      });
    throws

    Error - needs to be caught

    Parameters

    Returns Promise<any>

checkoutCartInput

  • Create a default CheckoutCartInput object.

    Returns CheckoutCartInput

checkoutCartPostHook

  • checkoutCartPostHook(checkoutResponse?: any): any
  • checkoutCart SDK call posthook method.

    example
    
    // How to override checkoutCartPostHook method
    VlocitySDK.digitalcommerce.override({ checkoutCartPostHook(checkoutResponse){
      console.log("checkoutCartPostHook method is being overridden");
    }});
    

    Parameters

    • Optional checkoutResponse: any

    Returns any

createAddToCartInput

  • Create a default AddToCartInput object.

    Returns AddToCartInput

createAssetToBasketInput

  • Create a default AssetToBasketInput object.

    Returns AssetToBasketInput

createAuthenticateUserInput

  • Create a default AuthenticateUserInput object.

    Returns AuthenticateUserInput

Private createGetAWSTokenInput

  • Create a default GetAWSTokenInput object.

    Returns GetAWSTokenInput

createGetItemsInCartInput

  • Create a default GetItemsInCartInput object.

    Returns GetItemsInCartInput

createGetOfferInput

  • Create a default GetOfferInput object.

    Returns GetOfferInput

createGetOffersInput

  • Create a default createGetOffersInput object.

    Returns GetOffersInput

createSaveCartInput

  • Create a default SaveCartInput object.

    Returns SaveCartInput

createSignOutUserInput

  • Create a default signOutUserPostHook object.

    Returns SignOutUserInput

createSubmitOrderInput

  • Create a default SubmitOrderInput object.

    Returns SubmitOrderInput

createUpdateBillingDetailsInput

  • Create a default UpdateBillingDetailsInput object.

    Returns UpdateBillingDetailsInput

createUpdateItemsInCartInput

  • Create a default UpdateItemsInCartInput object.

    Returns UpdateItemsInCartInput

createValidateOfferInput

  • Create a default ValidateOfferInput object.

    Returns ValidateOfferInput

    ValidateOfferInput default ValidateOfferInput.

deleteSelectedOffer

  • deleteSelectedOffer(offerCode: string): Promise<any>
  • Delete a selected offer from SDK cache. If the offer exists, it will be deleted from SDK cache. Otherwise, it will do nothing.

    Parameters

    • offerCode: string

      to be deleted.

    Returns Promise<any>

Private deleteSeletedOffer

  • deleteSeletedOffer(offerCode: string): any
  • Parameters

    • offerCode: string

    Returns any

fetchAWSAuthToken

  • fetch AWS authorisation token. developer can call this function to fetch AWS authorisation token.

    example
    
    Example - fetchAWSAuthToken with input parameters
    // Instantiate the input object for GetAWSTokenInput to specify parameters
    const input = digitalCommerce.GetAWSTokenInput();
    input.clientId = "client_id";  // use your App client Id
    input.clientSecret = "client_secret"; / // use your App client secret
    
    
    // Invoke fetchAWSAuthToken API to fetch AWS authorisation token
    digitalCommerce
      .fetchAWSAuthToken(input)
      .then(response => {
        Logger.info(
          "aws cognito reponse" +
            JSON.stringify(response)
        );
      })
      .catch(error => {
        Logger.info(
          "fetch AWS authorisation token failed" + error
        );
      });
    throws

    "GetAWSTokenInput::getAnonymousRestUrl() must have AWS OAuth2 url."

    throws

    "GetAWSTokenInput::getAuthToken() must have clientId and client secret."

    Parameters

    Returns Promise<any>

    a Promise with access_token.

fetchAWSAuthTokenPostHook

  • fetchAWSAuthTokenPostHook(response?: any): any
  • fetchAWSAuthToken SDK call posthook method.

    example
    
    // How to override fetchAWSAuthTokenPostHook method
    VlocitySDK.digitalcommerce.override({ fetchAWSAuthTokenPostHook(awsToken){
      console.log("fetchAWSAuthTokenPostHook method is being overridden");
    }});
    

    Parameters

    • Optional response: any

    Returns any

Private fetchCompleteOffersList

  • Parameters

    Returns Promise<any>

Private findSelectedOfferIndex

  • findSelectedOfferIndex(offerCode: string): number
  • Find the selected offer array index for the given offer code.

    Parameters

    • offerCode: string

      to find the selected offer.

    Returns number

    the index of the offer if existed. Otherwise, returns -1.

fire

  • fire(eventName: any, action: any, payload: any): void
  • Fires an event to listeners.

    example

    firing the event

    this.digitalCommerceSDK.fire("event-name",action,payloadObject);

    Parameters

    • eventName: any

      Name of the event to fire.

    • action: any

      Name of the event to fire.

    • payload: any

      Payload of the event to fire.

    Returns void

getAllSelectedOffers

  • getAllSelectedOffers(): Promise<any>
  • Get all the selected offer from SDK cache.

    Returns Promise<any>

    Promise with all selected offerConfigurations.

getFilteredOffersList

  • Returns a filtered list of products and promotions.

    example
    
    
    // Instantiate the input object for getOffers to specify parameters.
    const input = digitalCommerce.createGetOffersInput();
    input.catalogCode = "Phones"; // use your Catalog Code
    input.returnPromotion = true; //  If undefined return both products and promotions, If true return only promotions, If false return only products
    
    // Invoke GetOffersByCatalog API via method getFilteredOffersList()
    digitalCommerce
      .getFilteredOffersList(input)
      .then(result => {
        Logger.info("vlocity get catalog filtered offers list anonymous user rest call" + result);
      })
      .catch(error => {
        Logger.info("get catalog offers anonymous user rest call failed" + error);
      });
    
    throws

    "GetCatalogOffersInput::getAPIPath() must have catalogCode."

    throws

    "GetCatalogOffersInput::getAnonymousRestUrl() must have anonymousSiteUrl."

    throws

    "GetCatalogOffersInput::getAnonymousRestUrl() must have anonymousSiteUrl."

    throws

    "GetCatalogOffersContainsInput::getAPIPath() should not have both sortBy and contains."

    throws

    "GetCatalogOffersContainsInput::getAnonymousRestUrl() should not have both sortBy and contains."

    Parameters

    Returns Promise<any>

getItemsInCart

  • Get the basket details.

    example
    
    // Instantiate the input object for getItemsInCart to specify parameters
    const input = digitalCommerce.createGetItemsInCartInput();
    input.catalogCode = "Mobiles"; // use your Catalog Code
    input.cartContextKey = "01tf2000007Rb9JAAS"; // use your cart context key
    input.contextKey = "99914b932bd37a50b983c5e7c90ae93b" // Optional string for passing contextKey to DC API
    
    // Invoke Get Basket API via method getItemsInCart()
    digitalCommerce
      .getItemsInCart(input)
     .then(response => {
        Logger.info(
          "Vlocity digital commerce getItemsInCart for anonymous user: " +
            JSON.stringify(response)
        );
      })
      .catch(error => {
        Logger.info(
          "getItemsInCart for anonymous user rest call failed" +
            error
        );
      });
    
    throws

    "GetItemsInCartInput::getAPIPath() must have catalogCode."

    throws

    "GetItemsInCartInput::getAPIPath() must have cartContextKey."

    throws

    "GetItemsInCartInput::getAnonymousRestUrl() must have anonymousSiteUrl."

    throws

    "GetItemsInCartInput::getAnonymousSiteRestUrl() must have catalogCode."

    throws

    "GetItemsInCartInput::getAnonymousSiteRestUrl() must have cartContextKey."

    Parameters

    Returns Promise<any>

getItemsInCartPostHook

  • getItemsInCartPostHook(cartResponse?: any): any
  • getItemsInCart SDK call posthook method.

    example
    
    // How to override getItemsInCartPostHook method
    VlocitySDK.digitalcommerce.override({ getItemsInCartPostHook(cartResponse){
      console.log("getItemsInCartPostHook method is being overridden");
    }});
    

    Parameters

    • Optional cartResponse: any

    Returns any

getOffer

  • Returns offer and its details.

    example
    
    // Instantiate the input object for getOfferDetails to specify parameters
    const input = digitalCommerce.createGetOfferInput();
    input.catalogCode = "Phones"; // use your Catalog Code
    input.offerCode = "iPhoneXS"; // use your Offer Code
    
    // Invoke GetOfferDetails API via method getOfferDetails()
    digitalCommerce
      .getOffer(input)
      .then(response => {
        Logger.info(
          "vlocity get offer anonymous user rest call" + response
        );
      })
      .catch(error => {
        Logger.info("get offer anonymous user rest call failed" + error);
      });
    throws

    "GetOfferInput::getAPIPath() must have catalogCode."

    throws

    "GetOfferInput::getAPIPath() must have offerCode."

    throws

    "GetOfferInput::getAnonymousRestUrl() must have anonymousSiteUrl."

    Parameters

    Returns Promise<any>

getOfferPostHook

  • getOfferPostHook(offerResponse?: any): any
  • getOffer SDK call posthook method.

    example
    
    // How to override getOfferPostHook method
    VlocitySDK.digitalcommerce.override({ getOfferPostHook(offerResponse){
      console.log("getOfferPostHook method is being overridden");
    }});
    

    Parameters

    • Optional offerResponse: any

    Returns any

getOffers

  • Returns a list of offers.

    example
    
    // getOffers without the contains parameter
    
    // Instantiate the input object for getOffers to specify parameters
    const input = digitalCommerce.createGetOffersInput();
    input.catalogCode = "Phones"; // use your Catalog Code
    input.offset = 0; // use for pagination
    input.pageSize = 5; // use for pagination
    
    // Invoke GetOffersByCatalog API via method getOffers()
    digitalCommerce
      .getOffers(input)
      .then(result => {
        Logger.info("vlocity get catalog offers anonymous user rest call" + result);
      })
      .catch(error => {
        Logger.info("get catalog offers anonymous user rest call failed" + error);
      });
    
    // getOffers without the contains parameter
    
    // Instantiate the input object for getOffers to specify parameters.
    const input = digitalCommerce.createGetOffersInput();
    input.catalogCode = "Phones"; // use your Catalog Code
    input.offset = 0; // use for pagination
    input.pageSize = 5; // use for pagination
    input.contains = "iPhone8"; // find all offers that CONTAIN "iPhone8"
    
    // Invoke GetOffersByCatalog API via method getOffers()
    digitalCommerce
      .getOffers(input)
      .then(result => {
        Logger.info("vlocity get catalog offers anonymous user rest call" + result);
      })
      .catch(error => {
        Logger.info("get catalog offers anonymous user rest call failed" + error);
      });
    throws

    "GetCatalogOffersInput::getAPIPath() must have catalogCode."

    throws

    "GetCatalogOffersInput::getAnonymousRestUrl() must have anonymousSiteUrl."

    throws

    "GetCatalogOffersInput::getAnonymousRestUrl() must have anonymousSiteUrl."

    throws

    "GetCatalogOffersContainsInput::getAPIPath() should not have both sortBy and contains."

    throws

    "GetCatalogOffersContainsInput::getAnonymousRestUrl() should not have both sortBy and contains."

    Parameters

    Returns Promise<OfferList>

getOffersPostHook

  • getOffersPostHook(offersResponse?: any): any
  • getOffers SDK call posthook method.

    example
    
    // How to override getOffersPostHook method
    VlocitySDK.digitalcommerce.override({ getOffersPostHook(offersResponse){
      console.log("getOffersPostHook method is being overridden");
    }});
    

    Parameters

    • Optional offersResponse: any

    Returns any

getPromotions

  • Returns promotions for all products or for an associated to product.

    example
    
    // Instantiate the input object for getOffers to specify parameters.
    const input = digitalCommerce.createGetOffersInput();
    input.catalogCode = "Phones"; // use your Catalog Code
    input.offerCode = "iPhoneX"; //  If offerCode value is passed return all associated promotions for that product.If offerCode not passed return all promotions associated to products.
    
    // Invoke GetOffersByCatalog API via method getPromotions()
    digitalCommerce
      .getPromotions(input)
      .then(result => {
        Logger.info("vlocity get catalog filtered offers list anonymous user rest call" + result);
      })
      .catch(error => {
        Logger.info("get catalog offers anonymous user rest call failed" + error);
      });
    
    throws

    "GetCatalogOffersInput::getAPIPath() must have catalogCode."

    throws

    "GetCatalogOffersInput::getAnonymousRestUrl() must have anonymousSiteUrl."

    throws

    "GetCatalogOffersInput::getAnonymousRestUrl() must have anonymousSiteUrl."

    throws

    "GetCatalogOffersContainsInput::getAPIPath() should not have both sortBy and contains."

    throws

    "GetCatalogOffersContainsInput::getAnonymousRestUrl() should not have both sortBy and contains."

    Parameters

    Returns Promise<any>

Private getSelectedCartOffer

  • getSelectedCartOffer(offerCode: string, Offerlist: any[]): any[]
  • Find the selected offer array index for the given offer code.

    Parameters

    • offerCode: string

      to find the selected offer.

    • Offerlist: any[]

    Returns any[]

    the index of the offer if existed. Otherwise, returns -1.

getSelectedOffer

  • getSelectedOffer(offerCode: string, parseOffer?: boolean, input?: any): any
  • Returns the offer for given code that are being configured. Undefined if offer not exists.

    Parameters

    • offerCode: string

      offer code of the selected offer in memory to be retrieved.

    • Optional parseOffer: boolean

      boolean value to return parsed response or original response

    • Optional input: any

    Returns any

Private handleMultiTransactionResponse

  • handleMultiTransactionResponse(key: string, input: any, transactionType: string): any
  • Parameters

    • key: string
    • input: any
    • transactionType: string

    Returns any

Private invokeAPI

  • Returns a API call response.

    throws

    Error - needs to be caught

    Parameters

    Returns Promise<any>

Private invokeAction

  • Invoke an action returning from previous API call.

    example
    
    // Instantiate the input object for getOfferDetails to specify parameters
    const input = digitalCommerce.createGetOfferInput();
    input.apiNamespace = "cacheableapi";
    input.actionObj = {
        client: {
          records: [],
          params: {}
        },
        remote: {
          params: {}
        },
        rest: {
          params: {},
          method: "GET",
          link: "/v3/catalogs/Phones/offers/iPhone6"
        };
    
    // Invoke GetOfferDetails API via method getOfferDetails()
    digitalCommerce
    .invokeAction(input)
    .then(response => {
      Logger.info(
        "vlocity get catalog offers anonymous user rest call" + response
      );
    })
    .catch(error => {
      Logger.info(
        "get catalog offers anonymous user rest call failed" + error
      );
    });

    Parameters

    Returns Promise<any>

invokeIntegrationProcedure

  • Returns a API call response.

    throws

    Error - needs to be caught

    Parameters

    Returns Promise<any>

parseCart

  • parseCart(cartResponse: any, input?: any, isAsset?: boolean): Cart
  • Method to parse cart response

    Parameters

    • cartResponse: any
    • Optional input: any
    • Optional isAsset: boolean

    Returns Cart

parseOffer

  • parseOffer(offerResponse: any, input?: any): Offer
  • Method to parse offer response

    Parameters

    • offerResponse: any
    • Optional input: any

    Returns Offer

parseOfferList

  • parseOfferList(offersResponse: any, input: any): OfferList
  • Method to parse offers response

    Parameters

    • offersResponse: any
    • input: any

    Returns OfferList

Private proccessAssetToBasketResponse

  • proccessAssetToBasketResponse(response: any, input: any): Cart
  • Parameters

    • response: any
    • input: any

    Returns Cart

Private refreshAuthTokenOnExpiration

  • refreshAuthTokenOnExpiration(tokenExpirationTime: number): void
  • Parameters

    • tokenExpirationTime: number

    Returns void

register

  • register(eventName: any, callbackobj: any): void
  • Registers a callback for an event

    example
    example

    registering the event

    this.digitalCommerceSDK.register("event-name",{action: this.callbackFunction.bind(this)});

    Parameters

    • eventName: any

      Name of the event to listen for.

    • callbackobj: any

      Contains callback function.

    Returns void

saveCart

  • Saves the cart by creating an order for the given basket key.

    example
    
    // Instantiate the input object for saveCart to specify parameters
    const input = digitalCommerce.createSaveCartInput();
    input.email = "YOUR EMAIL ID";
    input.catalogCode = "CATALOG CODE";
    input.cartContextKey = "CART CONTEXT KEY";
    
    // Invoke saveCart API via method saveCart()
    digitalCommerce
      .saveCart(input)
     .then(response => {
        Logger.info(
          "Vlocity digital commerce saveCart: " +
            JSON.stringify(response)
        );
      })
      .catch(error => {
        Logger.info(
          "saveCart apexrest call failed" +
            error
        );
      });
    
    throws

    "SaveCartInput::getRequestPayload() must have email."

    throws

    "SaveCartInput::getRequestPayload() must have catalogCode."

    throws

    "SaveCartInput::getRequestPayload() must have cartContextKey."

    Parameters

    Returns Promise<any>

saveCartPostHook

  • saveCartPostHook(saveCartResponse?: any): any
  • saveCart SDK call posthook method.

    example
    
    // How to override saveCartPostHook method
    VlocitySDK.digitalcommerce.override({ saveCartPostHook(offersResponse){
      console.log("saveCartPostHook method is being overridden");
    }});
    

    Parameters

    • Optional saveCartResponse: any

    Returns any

signOutUser

  • SignOut the user from secure server.

    example
    
    // Invoke signOut endpoint of secure server API via method signOutUser()
    digitalCommerce
      .signOutUser(input)
     .then(response => {
        Logger.info(
          "Vlocity digital commerce signOutUser: " +
            JSON.stringify(response)
        );
      })
      .catch(error => {
        Logger.info(
          "signOutUser call failed" +
            error
        );
      });
    
    throws

    "SignOutUserInput::getAnonymousRestUrl() must have secureServerUrl."

    Parameters

    Returns Promise<any>

signOutUserPostHook

  • signOutUserPostHook(signOutUserResponse?: any): any
  • SignOut user SDK call posthook method.

    example
    
    // How to override signOutUserPostHook method
    VlocitySDK.digitalcommerce.override({ signOutUserPostHook(offersResponse){
      console.log("signOutUserPostHook method is being overridden");
    }});
    

    Parameters

    • Optional signOutUserResponse: any

    Returns any

submitOrder

  • Create and submit the order as a final step of the checkout process.

    example
    
    // Instantiate the input object for submitOrder to specify parameters
    const input = digitalCommerce.createSubmitOrderInput();
    input.email = "YOUR EMAIL ID";
    input.catalogCode = "CATALOG CODE";
    input.cartContextKey = "CART CONTEXT KEY";
    input.orderId = "ORDER ID"; // optional parameter
    
    // Invoke submitOrder API via method submitOrder()
    digitalCommerce
      .submitOrder(input)
     .then(response => {
        Logger.info(
          "Vlocity digital commerce submitOrder: " +
            JSON.stringify(response)
        );
      })
      .catch(error => {
        Logger.info(
          "submitOrder apexrest call failed" +
            error
        );
      });
    
    throws

    "SubmitOrderInput::getRequestPayload() must have email."

    throws

    "SubmitOrderInput::getRequestPayload() must have catalogCode."

    throws

    "SubmitOrderInput::getRequestPayload() must have cartContextKey."

    Parameters

    Returns Promise<any>

submitOrderPostHook

  • submitOrderPostHook(submitOrderResponse?: any): any
  • saveCart SDK call posthook method.

    example
    
    // How to override saveCartPostHook method
    VlocitySDK.digitalcommerce.override({ saveCartPostHook(offersResponse){
      console.log("saveCartPostHook method is being overridden");
    }});
    

    Parameters

    • Optional submitOrderResponse: any

    Returns any

unregister

  • unregister(eventName: any, callbackobj: any): void
  • Unregisters a callback for an event

    example

    unregistering the event

    this.digitalCommerceSDK.unregiter("event-name",{action: this.callbackFunction.bind(this)});

    Parameters

    • eventName: any

      Name of the event to unregister from.

    • callbackobj: any

      Contains callback function.

    Returns void

updateBillingDetails

  • Update user account biiling and shipping details.

    example
    
    // Instantiate the input object for updateBillingDetails to specify parameters
    const input = digitalCommerce.createUpdateBillingDetailsInput();
    input.email = "YOUR EMAIL ID";
    input.billingCity = "Bengaluru";
    input.billingState = "KA";
    input.billingAddress = "Vlocity, Cessna Business Tech Park";
    input.billingZipCode = "560103";
    input.shippingCity = "Bengaluru";
    input.shippingState = "KA";
    input.shippingAddress = "Vlocity, Cessna Business Tech Park";
    input.shippingZipCode = "560103";
    
    // Invoke updateBillingDetails API via method updateBillingDetails()
    digitalCommerce
      .updateBillingDetails(input)
     .then(response => {
        Logger.info(
          "Vlocity digital commerce updateBillingDetails: " +
            JSON.stringify(response)
        );
      })
      .catch(error => {
        Logger.info(
          "updateBillingDetails apexrest call failed" +
            error
        );
      });
    
    throws

    "UpdateBillingDetailsInput::getRequestPayload() must have email."

    throws

    "UpdateBillingDetailsInput::getRequestPayload() must have billingCity."

    throws

    "UpdateBillingDetailsInput::getRequestPayload() must have billingState."

    throws

    "UpdateBillingDetailsInput::getRequestPayload() must have billingAddress."

    throws

    "UpdateBillingDetailsInput::getRequestPayload() must have billingZipCode."

    throws

    "UpdateBillingDetailsInput::getRequestPayload() must have shippingCity."

    throws

    "UpdateBillingDetailsInput::getRequestPayload() must have shippingState."

    throws

    "UpdateBillingDetailsInput::getRequestPayload() must have shippingAddress."

    throws

    "UpdateBillingDetailsInput::getRequestPayload() must have shippingZipCode."

    Parameters

    Returns Promise<any>

updateBillingDetailsPostHook

  • updateBillingDetailsPostHook(updateBillingDetailsResponse?: any): any
  • updateBillingDetails SDK call posthook method.

    example
    
    // How to override updateBillingDetailsPostHook method
    VlocitySDK.digitalcommerce.override({ updateBillingDetailsPostHook(offersResponse){
      console.log("updateBillingDetailsPostHook method is being overridden");
    }});
    

    Parameters

    • Optional updateBillingDetailsResponse: any

    Returns any

updateItemsInCart

  • example
    let input = Object.assign(
     this.digitalCommerceSDK.createUpdateItemsInCartInput(),
      {
        catalogCode: 'Phones',
        basketkey: '01tf2000007Rb9JAAS',
        basketAction: "updateBasket",
        bundleContextKey: '',
        lineItemKey: '',
        quantity: 2
      }
    );
    this.digitalCommerceSDK
     .updateItemsInCart(input)
      .then(response => {
        Logger.info(
          "Vlocity digital commerce updateItemsInCart for anonymous user: " +
            JSON.stringify(response)
        );
      })
      .catch(error => {
        Logger.info("updateItemsInCart action failed: ", error);
      });

    Replace the item in cart with the provided offer configurations.

    Parameters

    Returns Promise<any>

updateItemsInCartPostHook

  • updateItemsInCartPostHook(cartResponse?: any): any
  • updateItemsInCart SDK call posthook method.

    example
    
    // How to override updateItemsInCartPostHook method
    VlocitySDK.digitalcommerce.override({ updateItemsInCartPostHook(cartResponse){
      console.log("updateItemsInCartPostHook method is being overridden");
    }});
    

    Parameters

    • Optional cartResponse: any

    Returns any

Private updateSelectedOffer

  • updateSelectedOffer(offer: any): void
  • Parameters

    • offer: any

    Returns void

validateOffer

  • Validate an offer. After configuring the offer by setting attributes' values, adding/removing child product, updating quantity, developer can call this function to validate the offer.

    example
    
    // Instantiate the input object for configureOfferDetails to specify parameters
    const input = digitalCommerce.createConfigureOfferDetailsInput();
    input.catalogCode = "Phones"; // use your Catalog Code
    input.offerCode = "iPhone8Offer"; // use your Offer Code
    
    // use the json structure from getOffer() or the cached offer
    input.offerConfiguration = digitalCommerce.getSelectedOffer(offerCode);
    
    // Invoke ConfigureOfferDetails API to validate offer
    digitalCommerce
      .validateOffer(input)
      .then(response => {
        Logger.info(
          "Validated offer response: " +
            JSON.stringify(response)
        );
      })
      .catch(error => {
        Logger.info(
          "validate offer failed: " + error
        );
      });
    throws

    "ValidateOfferInput::isValid() error in validating the input."

    throws

    "ValidateOfferInput::getAPIPath() must have catalogCode."

    throws

    "ValidateOfferInput::getAPIPath() must have offerCode."

    throws

    "ValidateOfferInput::getAnonymousRestUrl() must have anonymousSiteUrl."

    throws

    "ValidateOfferInput::getRequestPayload() must have offerConfiguration."

    Parameters

    Returns Promise<any>

    a Promise with validated offer JSON.

validateOfferPostHook

  • validateOfferPostHook(validateOfferResponse?: any): any
  • validateOffer SDK call posthook method.

    example
    
    // How to override validateOfferPostHook method
    VlocitySDK.digitalcommerce.override({ validateOfferPostHook(offerResponse){
      console.log("validateOfferPostHook method is being overridden");
    }});
    

    Parameters

    • Optional validateOfferResponse: any

    Returns any

version

  • version(): string
  • Returns the version number of SDK.

    Returns string

    Returns SDK version number as string

Static createConfigForAnonymousUser

  • Create a DigitalCommerceSDKConfig object that consists of a UserContext and a DataSourceService for anonymous user.

    example
    
    // Instantiate DigitalCommerceSDKConfig for anonymous user
    const digitalCommerceSDKConfig = VlocitySDK.digitalcommerce.createConfigForAnonymousUser();
    
    // Instantiate the SDK itself
    const digitalCommerce = VlocitySDK.digitalcommerce.getInstance(digitalCommerceSDKConfig);

    Parameters

    • authToken: string

    Returns DigitalCommerceSDKConfig

    Configuration object to instantiate SDK.

Static createConfigForLoginUser

  • Create a DigitalCommerceSDKConfig object that consists of a UserContext and a DataSourceService for login user.

    example
    
    // Instantiate DigitalCommerceSDKConfig for login user
    const digitalCommerceSDKConfig = VlocitySDK.digitalcommerce.createConfigForLoginUser(salesforceUrl, sessionToken);
    
    // Instantiate the SDK itself
    const digitalCommerce = VlocitySDK.digitalcommerce.getInstance(digitalCommerceSDKConfig);

    Parameters

    • salesforceUrl: string
    • sessionToken: string
    • Optional proxyUrl: string

      optional

    Returns DigitalCommerceSDKConfig

    Configuration object to instantiate SDK.

Static extend

  • extend(extendObj: object): void
  • Adds all the enumerable string keyed function properties of a source object to the sdk prototype. .extend should only be used to add new methods and it won't override the existing methods.

    Note: If the property already exists, it will be not be added.

    Custom functions which are being extended should have proper namespaces to avoid issues during upgrades. When Vlocity releases new changes it won't impact if unique namespaces are used.

    Example: myCompanyOrFeatureMethodName

    example

    How to extend an sdk?

    VlocitySDK.datasource.extend({ myCompanySayHello(){
         console.log("Hello World");
      }, sayTime() {
         console.log(new Date().myCompanyGetTime());
      }});
    
    const dataSource = VlocitySDK.datasource.getInstance({'create':true});
    console.log(daSource.myCompanySayHello())

    Parameters

    • extendObj: object

      The object of functions

    Returns void

Static getInstance

  • Get a singleton instance of this SDK.

    example
    
    // Instantiate DigitalCommerceSDKConfig for anonymous user
    const digitalCommerceSDKConfig = VlocitySDK.digitalcommerce.createConfigForAnonymousUser();
    
    // Instantiate the SDK itself
    const digitalCommerce = VlocitySDK.digitalcommerce.getInstance(digitalCommerceSDKConfig);
    
    OR
    
    // Instantiate DigitalCommerceSDKConfig for login user
    const digitalCommerceSDKConfig = VlocitySDK.digitalcommerce.createConfigForLoginUser(salesforceUrl, sessionToken);
    
    // Instantiate the SDK itself
    const digitalCommerce = VlocitySDK.digitalcommerce.getInstance(digitalCommerceSDKConfig);
    
    Note:
    digitalCommerce is a Singleton object.  Calling getInstance(digitalCommerceSDKConfig) repeatedly will return the same instance instantiated the first time when getInstance(digitalCommerceSDKConfig) was called.
    
    // To instantiate a new instance of digitalCommerce, set create to true in the digitalCommerceSDKConfig object:
    digitalCommerceSDKConfig.create = true;
    digitalCommerce = VlocitySDK.digitalcommerce.getInstance(digitalCommerceSDKConfig);
    throws

    "DigitalCommerce:: getInstance: Config object must be given in argument to create an instance the first time."

    throws

    "DigitalCommerce::constructor: DigitalCommerce cannot be instantiated properly. Both datasource and user context objects have to be in Config object as argument."

    Parameters

    Returns DigitalCommerce

    SDK instance.

Static override

  • override(overrideObj: object): void
  • Adds all the enumerable string keyed function properties of a source object to the sdk prototype.

    .override method should only be used to override the existing methods and should only be used in rare cases. Overriding the existing or default methods may cause unintended consequences and may also impact during upgrades.

    Please be cautious while using this

    example

    How to override methods in an sdk?

    VlocitySDK.datasource.override({ soql(){
         console.log("This code overrides the default soql function");
         // code goes here...
      }, sosl() {
         console.log("This code overrides the default soql function");
         // code goes here...
      }});
    
    const dataSource = VlocitySDK.datasource.getInstance({'create':true});
    console.log(dataSource.soql()); // prints "This code overrides the default soql function"

    Parameters

    • overrideObj: object

      The object of functions

    Returns void

Generated using TypeDoc