Customizing Peer Dependencies

Updated 

This section explains which dependencies are mandatory, which can be customized, and how to register or unregister custom implementations for seamless integration. 

Why is Customization required? 

In some cases, your existing codebase may already include specific libraries for functionalities such as SVG rendering, web views, and network information. If the Sprinklr SDK enforces its own versions of these dependencies, it could lead to conflicts and compatibility issues with your setup. 

 

To maintain consistency and avoid disruptions, the Sprinklr SDK allows you to inject custom implementations for certain dependencies. This ensures a seamless integration process, allowing you to: 

 

  • Use your preferred libraries. 

  • Avoid breaking existing functionality. 

  • Leverage the full capabilities of the Sprinklr SDK without replacing core dependencies. 

Types of Peer Dependencies 

The peer dependencies in the Sprinklr SDK are classified into mandatory and customizable dependencies. 

1. Mandatory Peer Dependencies 

These dependencies are required for the Sprinklr SDK to function properly. They cannot be replaced, and their versions must be greater than or equal to the specified ones: 

Dependency

Required Version

>= 4.0.0

>= 0.70.0

>= 8.0.0

>= 18.2.0

>= 1.0.1

2. Customizable Dependencies 

The following dependencies can be overridden with your own implementations. Each dependency is identified by a dependency key and an implementation type provided by Sprinklr. 

Dependency

Implementation Type

Dependency Key

SPRSvg

SVG

SPRWebview

WEBVIEW

SPRNetInfo

NET_INFO

SPRClipboard

CLIPBOARD

SPRStatusBar

STATUS_BAR

SPRCameraRoll

CAMERA_ROLL

SPRPermissions

PERMISSIONS

SPRVectorIcons

VECTOR_ICONS

SPRVideoPlayer

VIDEO_PLAYER

SPRMediaPicker

MEDIA_PICKER

SPRFileManager

FILE_MANAGER

SPRCustomStorage

ASYNC_STORAGE

Registering Custom Implementations 

To provide a custom implementation, follow these steps: 

1. Identify the Dependency Key 

Each dependency corresponds to a dependency key that you will use for registration. 

2. Import the Required Modules 

Import the necessary implementation type and MessengerDependenciesManager from the Sprinklr SDK. 

Example: Importing an Implementation Type 

import { SPRCustomStorage, EXTERNAL_DEPENDENCY } from '@sprinklrjs/chat-native-client'; 

Note: The above import is just an example for SPRCustomStorage and does not represent an actual implementation. 

3. Register Multiple Dependencies 

You can register multiple dependencies at once using registerDependencies(). 

Example: Registering Custom Implementations 

import { EXTERNAL_DEPENDENCY, MessengerDependenciesManager } from '@sprinklrjs/chat-native-client';  MessengerDependenciesManager.getInstance().registerDependencies({   [EXTERNAL_DEPENDENCY.ASYNC_STORAGE]: {     getItem: (key) => Promise.resolve(''),     setItem: (key, value) => Promise.resolve(),     removeItem: (key) => Promise.resolve(),   }, }); 

4. Register a Single Dependency 

If you only need to override a specific dependency, use registerDependency(). 

Example: Registering a Single Dependency 

import { EXTERNAL_DEPENDENCY, MessengerDependenciesManager } from '@sprinklrjs/chat-native-client';  MessengerDependenciesManager.getInstance().registerDependency(EXTERNAL_DEPENDENCY.ASYNC_STORAGE, {   getItem: (key) => Promise.resolve(''),   setItem: (key, value) => Promise.resolve(),   removeItem: (key) => Promise.resolve(), }); ​

Unregistering Custom Implementations 

If you need to remove a custom implementation, you can unregister a specific dependency or all custom dependencies at once. 

1. Unregister a Single Dependency 

import { EXTERNAL_DEPENDENCY, MessengerDependenciesManager } from '@sprinklrjs/chat-native-client';  MessengerDependenciesManager.getInstance().unregisterDependency(EXTERNAL_DEPENDENCY.ASYNC_STORAGE); 

2. Unregister All Custom Dependencies 

MessengerDependenciesManager.getInstance().unregisterDependencies();

Customizing peer dependencies in the Sprinklr SDK helps avoid conflicts, maintain consistency, and enhance flexibility in your integration. By registering or unregistering dependencies as needed, you can ensure a seamless and efficient implementation of the SDK while retaining control over your app’s existing libraries. 

Additional Resources

See All Integration Steps