open-index/open-npm huggingface dataset:
npm package: @measure-iot/api
Description: Interface to Measure's Mr. Fusion API
Latest version: 2.0.6

# Measure API Node Client

This client generates an interface to access Measure's Mr. Fusion API

## Installation

First install the package with
```
npm install --save @measure-iot/api
```

# Usage examples

## Minimal usage
``` javascript
import { Measure } from '@measure-iot/api';

const measureApi = new Measure();

const user = await measureApi.authenticate('YOUR-USERNAME', 'YOUR-PASSWORD');
const organization = await measureApi.getOrganization(user.organization.id);

// Pretty print json response
console.log(JSON.stringify(organization, null, 2));
```

## Usage with sessions
To manage sessions you can store the token
``` javascript
const token = measureApi.getAuthToken();

storeToken(token);  // Store your session token
```

and reload it instead of logging in again
``` javascript
import { Measure } from '@measure-iot/api';

const MY_AUTH_TOKEN = getStoredToken();  // Get token from storage

const measureApi = new Measure();

let user;

if (MY_AUTH_TOKEN) {
    measureApi.setAuthToken(MY_AUTH_TOKEN);
    user = await measureApi.getMe();
} else {
    user = await measureApi.authenticate('YOUR-USERNAME', 'YOUR-PASSWORD');
}

// Do user stuff...
```

## Cancel requests
You can also cancel a request by passing an instance of `MeasureRequestHandler`
``` javascript
const cancelToken = new MeasureRequestHandler();

// Login...
const { organization } = user;

const organization = await measureApi.getOrganization(organization.id, cancelToken);
```

And you can do
``` javascript
cancelToken.cancel();
```

by cancelling a request, the promise will return `undefined`.