Options
All
  • Public
  • Public/Protected
  • All
Menu

Account SDK Facade to to access account related information.

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

The SDK provides error checking and validates parameters before submitting them to the 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 Account APIs.

SDK components can be shared by different user interfaces, such as: Customer custom UI Components (which can be based on any framework), CMT Mobile App Shopping UI, Omniscript that uses Account APIs, and so on.

version

v109.0.0

Hierarchy

Index

Constructors

constructor

Properties

Private cartContextKey

cartContextKey: string = null

Private context

context: UserContext

The UserContext used for this SDK.

Private datasource

datasource: default

The datasource connection used by this SDK.

Static Private instance

instance: default

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

Accessors

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

Methods

createGetAssetsByAccountInput

  • Create a default GetAssetByAccountInput object.

    Returns GetAssetByAccountInput

createGetAssetsInput

  • Create a default GetAssetInput object.

    Returns GetAssetInput

createGetContractsInput

  • Create a default GetContractInput object.

    Returns GetContractInput

createGetOffersInput

  • Create a default GetOfferInput object.

    Returns GetOfferInput

getAssets

  • Returns offer.

    example
    
    // Instantiate the input object for getAssets to specify parameters
    const input = account.createGetAssetsInput();
    input.contractId = "80036000000EjcBAAS"; // use your contract Id
    input.pagesize = 10; // use your desired page size
    
    // Invoke GetAsset API via method getAssets()
    account
      .getAssets(input)
      .then(response => {
        Logger.info(
          "vlocity get asssets rest call" + response
        );
      })
      .catch(error => {
        Logger.info("get assets rest call failed" + error);
      });
    
    throws

    "GetAssetInput::getAPIPath() must have contractId."

    Parameters

    Returns Promise<Result>

getAssetsByAccount

  • Returns offer.

    example
    
    // Instantiate the input object for getAssetsByAccount to specify parameters
    const input = account.createGetAssetsByAccountInput();
    input.accountId = "80036000000EjcBAAS"; // use your accountId
    input.pagesize = 10; // use your desired page size
    
    // Invoke GetAsset API via method getAssetsByAccount()
    account
      .getAssetsByAccount(input)
      .then(response => {
        Logger.info(
          "vlocity get getAssetsByAccount rest call" + response
        );
      })
      .catch(error => {
        Logger.info("get assets rest call failed" + error);
      });
    
    throws

    "GetAssetByAccountInput::getAPIPath() must have accountId."

    Parameters

    Returns Promise<any>

getContracts

  • Returns a list of contracts.

    example
    
    // Instantiate the input object for getContracts to specify parameters
    const input = account.createGetContractsInput();
    input.accountId = "0011t00000DtbShAAJ"; // use your account Id
    input.includeAssets = false; // set true to include assets in the response
    
    // Invoke GetContract API via method getContracts()
    account
      .getContracts(input)
      .then(result => {
        Logger.info("vlocity get contracts rest call" + result);
      })
      .catch(error => {
        Logger.info("get contracts rest call failed" + error);
      });
    
    throws

    "GetContractInput::getAPIPath() must have accountId."

    Parameters

    Returns Promise<any>

getOffers

  • Returns offers.

    example
    
    // Instantiate the input object for getOffers to specify parameters
    const input = account.createGetOffersInput();
    input.contextId = "0013600000QqLUZAA3"; // use your context Id
    input.pageSize = 5; // use your desired page size
    
    // Invoke GetOffer API via method getOffers()
    account
      .getOffers(input)
      .then(response => {
        Logger.info(
          "vlocity get offers rest call" + response
        );
      })
      .catch(error => {
        Logger.info("get offers rest call failed" + error);
      });
    
    throws

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

    Parameters

    Returns Promise<any>

Private invokeAPI

  • Returns the response after successful api call.

    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 getAssets to specify parameters
    const input = account.createGetAssetsInput();
    input.apiNamespace = "vlocity_cmt";
    input.actionObj = {
        client: {
          records: [],
          params: {}
        },
        remote: {
          params: {}
        },
        rest: {
          params: {},
          method: "GET",
          link: "/v2/contracts/80036000000EjcBAAS/assets"
        };
    
    // Invoke GetAsset API via method getAssets()
    account
    .invokeAction(input)
    .then(response => {
      Logger.info(
        "vlocity get assets rest call" + response
      );
    })
    .catch(error => {
      Logger.info(
        "get assets rest call failed" + error
      );
    });
    

    Parameters

    Returns Promise<any>

parseAssets

  • parseAssets(assetResponse: any, input?: any): Assets
  • Method to parse asset response

    Parameters

    • assetResponse: any
    • Optional input: any

    Returns Assets

version

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

    Returns string

    Returns SDK version number as string

Static createConfigForLoginUser

  • createConfigForLoginUser(salesforceUrl: string, sessionToken: string): default
  • Create a AccountSDKConfig object that consists of a UserContext and a DataSourceService for login user.

    example
    
    // Instantiate accountSDKConfig for login user
    const accountSDKConfig = VlocitySDK.account.createConfigForLoginUser(salesforceUrl, sessionToken);
    
    // Instantiate the SDK itself
    const account = VlocitySDK.account.getInstance(accountSDKConfig);
    

    Parameters

    • salesforceUrl: string
    • sessionToken: string

    Returns default

    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 AccountSDKConfig for login user
    const accountSDKConfig = VlocitySDK.account.createConfigForLoginUser(salesforceUrl, sessionToken);
    
    // Instantiate the SDK itself
    const account = VlocitySDK.account.getInstance(accountSDKConfig);
    
    Note:
    account is a Singleton object.  Calling getInstance(accountSDKConfig) repeatedly will return the same instance instantiated the first time when getInstance(accountSDKConfig) was called.
    
    // To instantiate a new instance of account, set create to true in the accountSDKConfig object:
    accountSDKConfig.create = true;
    account = VlocitySDK.account.getInstance(accountSDKConfig);
    
    throws

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

    throws

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

    Parameters

    Returns default

    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