Using TypeScript
You can implement Relativity extension scripts in TypeScript, which is a typed superset of JavaScript. It compiles to plain JavaScript that runs in the browser or any JavaScript engine. For more information, see TypeScript.
This page contains the following information:
Benefits of TypeScript
Implementing extension scripts in TypeScript has the following benefits:
- Provides IntelliSense for the Review API interfaces, methods, enums, and other programming entities in programming editors, such as Visual Studio Code and others. You can explore the
reviewapi
in the code editor itself without needing to search through the API documentation.
- Provides guidelines for the appropriate use of the Review API by offering feedback when compiling the TypeScript code, such as identifying missing arguments. You can then correct errors in the code before the extension code is run.
Consuming the Review API package
The Review API is available as a npm package. You need to install the reviewapi
package as a development dependency for your extension script project. See the following sections for installation and import instructions.
Install the Review API package
Run the following npm command to install the reviewapi
package and update devDependencies section of the package.json
file:
Copy
npm install --save-dev reviewapi
For more information about npm
commands and packages, see npm Docs.
Import required features from Review API package
You need to import any interfaces or enumerations required by your code from the reviewapi package to your TypeScript file.
The following code sample illustrates how to import and use this package in a file called review.index.exampleextension.ts:
Copy
import { IExtensionConfig, IReviewInterfaceApi } from reviewapi;
export const cardConfig: IExtensionConfig = {
id: "relativity.exampleextension",
name: "TypeScript Example",
lifecycle: {
ready: (api: IReviewInterfaceApi) {
console.log("Application ready event called.");
}
}
}
For more information, see Modules on the TypeScript web site.
Version pinning
A corresponding version of reviewapi
npm package may exist for certain releases of the Relativity Review application. When creating Review extension scripts, we recommend using the matching version of the reviewapi
npm package. Using the same version ensures that you have the appropriate type definitions for the version of document viewer application that you are customizing with your Relativity extension.
The Relativity versioning follows the format: {major-version}.{minor-version}.{build-number}
.
Note: A document viewer application with the version a.b.cd.ef
matches a reviewapi
npm package with the version a.b.cd00ef
.
Updating the reviewapi version
Use the following steps to update the reviewapi version:
-
Specify the package version in package.json
file to update the reviewapi
npm package. For example, the matching version of document viewer application would be 5.0.12.2. See the following example of a package.json file:
Copy
{
"name": "@repository-name/project-name",
"description": "The Relativity Review Extension Application",
"version": "0.1.0",
"repository": {
"type": "",
"url": ""
},
"homepage": "",
"license": "",
"dependencies": {
"reviewapi": "5.0.120002"
}
}
-
To pull the specified version of the package, run the command: npm install
.
-
Build your extension project to confirm that the project compiles without errors.