npm package: @opentext/otts-module-api
Description: This will include otts_module_api.js file in your project
Author: OpenText
Latest version: 1.0.2

# OTTS Module API

The purpose of this package is to provide application and component developers with convenient JavaScript-based APIs to integrate with OpenText LiveSite Content Services (LSCS) APIs and OpenText TeamSite Module datums (properties).
**Note: This module is only compatible with OpenText TeamSite 23.2 and later.**

## Prerequisites
* Create or clone a JavaScript application/component project workspace (e.g., React, Angular, Vue, Vanilla JS, etc.)
* OpenText TeamSite 23.2 or later

## Installation

To install this package, run the following command in the root of your project:

```bash
> npm install otts-api
```

## Setup

After installation, add the `otts_module_api.js` file to the root folder of your project.
Copy this file to the appropriate third-party source folder. For example, for React projects, this is likely the `/public` folder. For Angular projects, it is likely the `/src` folder.

## Usage

LCSC API values and Module Datum values are retrieved based on the environment in which your application/component is running. While testing in your local development environment, the package will retrieve LSCS content and Component Datum values from `iw_module_stubs.js`.

>Note: `iw_module_config.json` must be present in the same directory as `otts_module_api.js`. Data spec and default values are loaded during bootstrap and before the main app launches.

>Note:
To ensure that local testing functions correctly, You must load this API script into the DOM **AFTER** `iw_module_stubs.js`.

### API
All functions are static and accessible using the global `iw` variable.

**iw.init()**<br>
For applications/components that need control over when to initialize themselves.

**iw.getPropertyValue(moduleId, datumId)**<br>
Retrieves the datum/property value for the provided component and datum.
* **moduleId** : *string* - The generated TeamSite module ID
* **datumId** : *string* - The developer-defined datum/property ID

**iw.queryLscs(api, params, callback, useStagingInAuthoring)**<br>
Retrieves content from LSCS.
* **api** : *string* - The LSCS API to use ("documents" or "documents-meta")
* **params** : *object* - The developer-defined datum/property ID. For additional help, refer to the [LSCS documentation](https://developer.opentext.com/ce/products/teamsite/apis/livesitecontentserviceslscsteamsite).
* **callback** : *function* - The callback function
* **useStagingInAuthoring** : *boolean* - Whether or not to use Staging content in the Authoring environment (default is false)

**iw.getProjects(callback)**<br>
Retrieves the projects, to be used as an input for LSCS queries.
* **callback** : *function* - The callback function

### Sample usage (TypeScript)

```typescript
const iw : any = window['iw'];

/*
 * to get datum/property values
 */

// a potential way of retrieving the module/app ID
const root = document.getElementById('root');
const id = root.dataset['appId'];
   
const myBooleanValue = iw.getPropertyValue(id, 'D001');
const mySelectedCheckBox = iw.getPropertyValue(id, 'D002').value;

/* 
 * to query LSCS
 */

// basic example wildcard query
let params = { 
	q: '*',
	includeDCRContent: true,
	format: 'json'
};
iw.queryLscs(api, params, (data) => {
	// callback function
});

// query with additional filters
let params = {
	q: 'ast_relative_path:*/' + searchQuery,
	project: selectedProject,
	includeDCRContent: true,
	format: 'json'
}
iw.queryLscs('documents', params, (data) => {
	// callback function
});
```