# nodeJS SDK

### About

This package implements LicenseSpring SDK functionality for Javascript and Typescript.

### Installation

The package is published on npmjs.com and can be installed as follows:

{% code title="Install" %}

```bash
npm i --save @licensespring/node-sdk
```

{% endcode %}

### Interface

The SDK provides several classes which are used to interface with LicensenSpring services as well as functionality for local license files:

#### LicenseAPI

This is a wrapper class for interacting with the License API. It provides all the API endpoints as class methods, provides input validation and response signature checks. If you prefer to implement your own logic for working with LicenseSpring data, this class contains all the necessary functionality.

{% code title="LicenseAPI usage" %}

```javascript
const { LicenseAPI } = require('@licensespring/node-sdk');

const licenseAPI = new LicenseAPI({
  apiKey: '12345678-4bfe-4e3a-8737-757004d6294c',
  sharedKey: 'eYuHrlajvIVTiSFIXpxpKhw78f4Ewy-00-12345678',
  appName: 'js-sdk-test-1',
  appVersion: '0.0.1',
});

const licenseActivation = await licenseAPI.activateLicense({ license_key: 'string', product: 'string', hardware_id: 'string' });

const bundleActivation = await licenseAPI.activateBundle({ license_key: 'string', product: 'string', hardware_id: 'string' });

const licenseCheck = await licenseAPI.checkLicense({ license_key: 'string', product: 'string', hardware_id: 'string' });

const bundleCheck = await licenseAPI.checkBundle({ license_key: 'string', product: 'string', hardware_id: 'string' });

const addConsumption = await licenseAPI.addConsumption({ license_key: 'string', product: 'string', hardware_id: 'string', consumptions: 10 });

const addFeatureConsumption = await licenseAPI.addFeatureConsumption({ license_key: 'string', product: 'string', hardware_id: 'string', feature: 'string', consumptions: 10 });

const licenseFeatureCheck = await licenseAPI.checkLicenseFeature({ license_key: 'string', product: 'string', hardware_id: 'string', feature: 'string' });

const trackDeviceVariables = await licenseAPI.trackDeviceVariables({ license_key: 'string', product: 'string', hardware_id: 'string', variables: { key1: 'value1' } });

const getDeviceVariables = await licenseAPI.getDeviceVariables({ license_key: 'string', product: 'string', hardware_id: 'string' });

const licenseDeactivation = await licenseAPI.deactivateLicense({ license_key: 'string', product: 'string', hardware_id: 'string' });

const bundleDeactivation = await licenseAPI.deactivateBundle({ license_key: 'string', product: 'string', hardware_id: 'string' });

/* NOTE: the hardware_id value can be either generated by your app 
 * (eg. using custom-made hardware fingerprinting logic) or you
 * can use the hardware ID module exposed by this class: 
 */
 const hardwareID = licenseAPI.getHardwareID();
```

{% endcode %}

For a more detailed overview of this class see: [**License API**](https://docs.licensespring.com/sdks/tutorials/getting-started/broken-reference)

{% hint style="info" %}
The hardware\_id value can be either generated by your app (for example using custom-made hardware fingerprinting logic) or you can use the hardware ID module exposed by this class: licenseAPI.getHardwareID()
{% endhint %}

#### LicenseManager

This class extends the functionality provided by the LicenseAPI class and provides methods for managing licenses. In addition to encapsulating API calls, this class reads and writes local license files and handles hardware ID generation internally.

{% code title="LicenseManager usage" %}

```javascript
const { LicenseAPI } = require('@licensespring/node-sdk');

const licenseManager = new LicenseManager({
  apiKey: '12345678-4bfe-4e3a-8737-757004d6294c',
  sharedKey: 'eYuHrlajvIVTiSFIXpxpKhw78f4Ewy-00-12345678',
  appName: 'js-sdk-test-1',
  appVersion: '0.0.1',
  productCode: 'myproduct1', // NOTE: each LicenseManager instance is attached to a specific product
});

const licenseActivation = await licenseManager.activateLicense({ license_key: 'string' });

const licenseCheck = await licenseManager.checkLicense({ license_key: 'string' });

const addConsumption = await licenseManager.addConsumption({ license_key: 'string', consumptions: 10 });

const addFeatureConsumption = await licenseManager.addFeatureConsumption({ license_key: 'string', feature: 'string', consumptions: 10 });

const licenseFeatureCheck = await licenseManager.checkLicenseFeature({ license_key: 'string', feature: 'string' });

const trackDeviceVariables = await licenseManager.trackDeviceVariables({ license_key: 'string', variables: { key1: 'value1' } });

const getDeviceVariables = await licenseManager.getDeviceVariables({ license_key: 'string' });

const licenseDeactivation = await licenseManager.deactivateLicense({ license_key: 'string' });

// this loads the license object from the local license file;
const license = licenseManager.loadLicense();

const localCheck = await license.localCheck();

license.addLocalConsumption(10);

license.addLocalFeatureConsumption('feature1', 5);
```

{% endcode %}

For a more detailed overview of this class see: [**License Manager**](https://docs.licensespring.com/sdks/tutorials/getting-started/broken-reference)

{% hint style="info" %}
Each LicenseManager instance is attached to a specific product via the productCode option.
{% endhint %}

#### BundleManager

This class extends the functionality provided by the LicenseAPI class and provides methods for managing license bundles. The behaviour of this class is similar to LicenseManager, the only difference being that this class is used for license **bundles**, as opposed to single licenses.

For a more detailed overview of this class see: [**Bundle Manager**](https://docs.licensespring.com/sdks/tutorials/getting-started/broken-reference)

#### LicenseFile

This class encapsulates the local license file produced by the LicenseManager or BundleManager. This file is used by client applications to track the license state on local storage.

For a more detailed overview of this class see: [**License File**](https://docs.licensespring.com/sdks/tutorials/getting-started/broken-reference)
