Options
All
  • Public
  • Public/Protected
  • All
Menu

DataSource SDK This SDK handles the connection with SalesForce and provide convenient ways to access Vlocity integration including DataRaptor, Integration Procedure, Apex REST API etc.

How to create a Datasource?

example

Getting an instance of the DataSource

// Obtain a singleton dataSourceService
const dataSourceService = DataSource.getInstance({
  salesforceUrl: "https://www.salesforce.com",
  sessionId: "123",
  create: false,
  userId: "test" //additional data
});
example

Creating a custom datasource at runtime

const newDataSource = {
 oracle: () => {
  return "I'm a Custom implementation";
 },
 siebel: () => {
   return "I'm a Custom implementation";
 }
};

dataSourceService.create(newDataSource, isNewInstance);

// Create function implementation looks like this
// uses prototype to add methods to dataSourceService

DataSource.mixin(DataSource, newDataSource, isNewInstance);
// call
dataSourceService
 .siebel()
 .execute(input)
 .then()
 .catch();
example

Using ApexRest

datasource
 .apexRest(new ApexRestInput({
  method: "get",
  url:
    "/vlocity_cmt/v2/cpq/carts/80137000000WlMP/products?hierarchy=1&pagesize=10&fields=IsActive,Id,Name,UnitPrice,ProductCode,jraju_card__RecurringPrice__c&includeIneligible=true"
 }))
  .execute()
  .then(resp => Logger.log("resp from thenable", resp))
  .catch(error => Logger.log("response from catch thenable", error));
example

Using Rest

const input1: RestInput = new RestInput({ url: "/test.json" });
datasource
  .rest(input1)
  .execute()
  .then(response => {
    Logger.log("call ", response);
  })
  .catch(error => {
    Logger.log("fail", error);
  });
example

Using SOQL

datasource
  .soql(new SoqlInput({
   query: "SELECT Id, Name FROM Account LIMIT 10"
  })
  .execute()
  .then(response => {
    Logger.log("soql call ", response.records);
  })
  .catch(error => {
   Logger.log("soql fail", error);
  });
example

SOSL call

datasource
  .sosl(new SoslInput({
   query: "FIND {Un*} IN ALL FIELDS RETURNING Account LIMIT 10"
  }))
  .execute()
  .then(response => {
    Logger.log("sosl call " + response.searchRecords);
  })
 .catch(error => {
    Logger.log("sosl fail" + error);
 });

Hierarchy

Index

Constructors

constructor

  • Create a new DataSource.

    Parameters

    • config: any

    Returns DataSource

Properties

config

Config for this SDK.

connection

connection: any

Private dataSourceDB

dataSourceDB: DataSourceBrowserDB

Static Private instance

instance: DataSource

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

apexRemote

apexRemoteInput

  • creates new apexRemoteInput

    example
    // ApexRemoteInput
    const apexRemoteInput = VlocitySDK.datasource.apexRemoteInput({
    className:"className",
    "methodName":"methodName"
    });

    Parameters

    • parameters: Object

      { cacheable:false retryCount:0, timeoutInMillis:20000, reload:false, className:"className", methodName:"methodName", paramsArray:paramsArray; config:config; }

    Returns ApexRemoteInput

apexRest

apexRestInput

  • creates new apexRestInput

    example
    // ApexRestInput
    const apexRestInput = VlocitySDK.datasource.apexRestInput({
    path:"path",
    method:"methodName"
    });

    Parameters

    • parameters: Object

      { cacheable:false retryCount:0, timeoutInMillis:20000, reload:false, path:"path", method:"method", body:body; }

    Returns ApexRestInput

clearCache

  • clearCache(): Promise<void>
  • clears the cache store

    Returns Promise<void>

dataRaptor

  • Create a new dataRaptor wrapper

    Parameters

    Returns DataRaptor

dataRaptorInput

  • creates new dataRaptorInput

    example
    // DataraptorInput
    const dataRaptorInput = VlocitySDK.datasource.dataRaptorInput({
    bundleName:"name",
    inputParamsString:"name=vlocity&state=ca"
    });

    Parameters

    • parameters: Object

      { inputParamsString:"name=vlocity&state=ca", bundleName:"name" cacheable:false retryCount:0, timeoutInMillis:20000, reload:false, }

    Returns DataRaptorInput

deleteCacheData

  • deleteCacheData(key: any, cacheType?: any): Promise<void>
  • deletes the cached response for the given cache key as generated from input object.

    Parameters

    • key: any

      is the generated from input object. For example, the key for ApexRestInput will be:

      const key = apexRestInput.digest();
    • Optional cacheType: any

      is a optional parameter. It is the type of cache to be used. It will be of the type CacheType Enum. If not specified it will be indexed db

    Returns Promise<void>

dual

  • Create a dual data source that will automatically switch between Apex Rest or Apex Remote (if available).

    Parameters

    Returns IDataSource

    a instance of DualDataSource.

getCacheData

  • getCacheData(key: any, cacheType?: any): Promise<CacheResult>
  • Get the cached response for the given cache key as generated from input object.

    Parameters

    • key: any

      is the generated from input object. For example, the key for ApexRestInput will be:

      const key = apexRestInput.digest();
    • Optional cacheType: any

      is a optional parameter. It is the type of cache to be used. It will be of the type CacheType Enum. If not specified it will be indexed db

    Returns Promise<CacheResult>

getCachedKeys

  • getCachedKeys(): Promise<(string | number | Date | ArrayBufferView | ArrayBuffer | IDBArrayKey)[]>
  • gets all keys for the given DB and store

    Returns Promise<(string | number | Date | ArrayBufferView | ArrayBuffer | IDBArrayKey)[]>

getCachedResults

  • getCachedResults(key: any, type?: any): Promise<any>
  • gets cached Data if current Date time is within expiration time

    Parameters

    • key: any

      is generated from input object. For example, the key for ApexRestInput will be:

      const key = apexRestInput.digest();
    • Optional type: any

      is a optional parameter. It is the type of cache to be used. It will be of the type CacheType Enum. If not specified it will be indexed db

    Returns Promise<any>

integrationProcedure

integrationProcedureInput

  • creates new integrationProcedureInput

    example
    // integrationProcedureInput
    const integrationProcedureInput = VlocitySDK.datasource.integrationProcedureInput({
    input: {},
    optionsMap: {},
    procedureKey: "TEST_SDK"
    });

    Parameters

    • parameters: Object

      { input: {}, optionsMap: {}, procedureKey: "TEST_SDK", cacheable:false retryCount:0, timeoutInMillis:20000, reload:false, }

    Returns IntegrationProcedureInput

rest

  • Create a new Rest wrapper

    Parameters

    Returns RestDataSource

restInput

  • creates new restInput

    example
    // restInput
    const restInput = VlocitySDK.datasource.restInput({
    url: "/test"
    });

    Parameters

    • parameters: Object

      { url: "/test",

      cacheable:false, retryCount:0, timeoutInMillis:20000, reload:false, }

    Returns RestInput

setCacheData

  • setCacheData(key: any, response: any, cacheType?: any): Promise<void>
  • sets the response for the given cache key as generated from input object.

    Parameters

    • key: any

      is the generated from input object. For example, the key for ApexRestInput will be:

      const key = apexRestInput.digest();
    • response: any

      is the data which needs to be cached.

    • Optional cacheType: any

      is a optional parameter. It is the type of cache to be used. It will be of the type CacheType Enum. If not specified it will be indexed db

    Returns Promise<void>

setCachedResults

  • setCachedResults(key: any, value: any, cacheExpiraion: any, type?: any): Promise<void>
  • sets results the cache based on the optional parameter value

    Parameters

    • key: any

      is generated from input object. For example, the key for ApexRestInput will be:

      const key = apexRestInput.digest();
    • value: any

      is the data which needs to be cached

    • cacheExpiraion: any
    • Optional type: any

      is a optional parameter. It is the type of cache to be used. It will be of the type CacheType Enum. If not specified it will be indexed db

    Returns Promise<void>

setRequestTimeout

  • setRequestTimeout(timeout: number): void
  • set a deafault timeout at datasource level

    Parameters

    • timeout: number

    Returns void

setRetryCount

  • setRetryCount(retryCount: number): void
  • set a deafault retry count at datasource level

    Parameters

    • retryCount: number

    Returns void

soql

  • Create a new Soql wrapper

    Parameters

    Returns SoqlDataSource

soqlInput

  • creates new soqlInput

    example
    // soqlInput
    const restInput = VlocitySDK.datasource.soqlInput({
    query: "SELECT id from Account LIMIT 5"
    });

    Parameters

    • parameters: Object

      { query: "SELECT id from Account LIMIT 5", cacheable:false, retryCount:0, timeoutInMillis:20000, reload:false, }

    Returns SoqlInput

sosl

  • Create a new Sosl wrapper

    Parameters

    Returns SoslDataSource

soslInput

  • creates new soslInput

    example
    // soslInput
    const restInput = VlocitySDK.datasource.soslInput({
    query: "FIND{ M1-5} IN ALL FIELDS RETURNING Account(Id, Name)"
    });

    Parameters

    • parameters: Object

      { query: "FIND{ M1-5} IN ALL FIELDS RETURNING Account(Id, Name)", cacheable:false, retryCount:0, timeoutInMillis:20000, reload:false, }

    Returns SoslInput

version

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

    Returns string

    Returns SDK version number as string

Static createConfigForDatasourceUser

  • createConfigForDatasourceUser(salesforceUrl: string, sessionToken: string, inPlatformData?: Promise<Object>): DataSourceSDKConfig
  • Create a DatasourceSDKConfig object.

    example
    
    // Instantiate DatasourceSDKConfig for login user
    const datasourceSDKConfig = VlocitySDK.datasource.createConfigForDatasourceUser(salesforceUrl, sessionToken);
    
    // Instantiate the SDK itself
    const datasource = VlocitySDK.datasource.getInstance(datasourceSDKConfig);

    Parameters

    • salesforceUrl: string
    • sessionToken: string
    • Optional inPlatformData: Promise<Object>

    Returns DataSourceSDKConfig

    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 an instance of DataSource if it exists. Otherwise, create a new one with the given config.

    Parameters

    Returns DataSource

    DataSource 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