Version checker
The SDK provides a version checker to check the compatibility of the JavaScript SDK version and a Sitecore Content Hub instance version.
In the following code examples, the client variable refers to the ContentHubClient instance. When using the JavaScript SDK, you can choose your own variable name, but it is called client at instantiation in the docs.
Check compatibility of the Content Hub instance with minimum required version
For example, the following snippet checks whether the Content Hub instance runs version 4.0.0:
await client.versionChecker.compatibilityCheckAsync(new FileVersion(4, 0, 0, 0));
The call throws a NotSupportedError if the Content Hub instance does not run version 4.0.0.
Get the compatibility between a Content Hub instance and the SDK
For example, the following snippet gets compatibility between a Content Hub instance and the SDK:
const compatibility = client.versionChecker.getCompatibility(
new FileVersion(3, 0, 0),
new FileVersion(4, 0, 0),
new FileVersion(3, 0, 0)
);
First, we pass the FileVersion of the Content Hub , then the FileVersion of the SDK, and finally, the minimum SDK version as dictated by the Content Hub instance.
The call returns:
-
Compatibility.Okif the Content Hub instance and the SDK are compatible. -
Compatibility.SdkOldif the Content Hub instance has a newer version than the SDK. -
Compatibility.SdkNewif the Content Hub instance has a older version than the SDK.
Check if a Content Hub instance is compatible with a SDK version
The following snippet checks whether a Content Hub instance is compatible with a SDK version:
const isCompatible = await client.versionChecker.isCompatibleAsync(new FileVersion(1, 0, 0, 0));
The FileVersion is the version of the SDK.