# @sobol/client

> A JavaScript client library exposing Sobol's RESTful API.

Latest version **2.0.0** (published 2020-01-07) · MIT license · 0 weekly downloads

## Install

```sh
npm install @sobol/client
pnpm add @sobol/client
yarn add @sobol/client
bun add @sobol/client
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.0 |
| Published | 2020-01-07 |
| First published | 2019-10-07 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 4 |
| Unpacked size | 942.4 KB |
| Known vulnerabilities | 0 (+24 in 1 direct dependencies) |
| Install scripts | no |
| Author | Sobol - |
| Maintainers | leifdejong, victor.leipnik, vlad.kutsenko |

## Links

- npm: https://www.npmjs.com/package/@sobol/client
- npm.io page: https://npm.io/package/@sobol/client

## Dependencies (4)

- [axios](https://npm.io/package/axios.md) ^0.18.0
- [dotenv](https://npm.io/package/dotenv.md) ^8.0.0
- [lodash](https://npm.io/package/lodash.md) ^4.17.11
- [jwt-decode](https://npm.io/package/jwt-decode.md) ^2.2.0

## Recent versions

- 2.0.0 (latest) — 2020-01-07
- 1.5.1 — 2019-10-07
- 1.5.0 — 2019-10-07

## README

# @sobol/client

A JavaScript client library exposing Sobol's RESTful API.

## Installation

```bash
npm install @sobol/client
```

The client will be avaliable in two distributions: `Node` and `Browser`.

### Node

To use in node, include the client singleton as follows:

```javascript
const Client = require('@sobol/client');

// ...
```

To use the constructor instead, instantiate the client as follows:

```javascript
const SobolClient = require('@sobol/client/base');
const Client = new SobolClient();

// ...
```

### Browser

To use in browser, include the client constructor as follows:

```html
<!-- include library -->
<script type="text/javascript" src="./node_modules/@sobol/client/browser/sobol-client.js"></script>

<!-- instantiate the client -->
<script type="text/javascript">
  var Client = new SobolClient();

  // ...
</script>
```

## Configuration

The `configure()` function can be called at any time and allows you to pass options such as the `API Key` as follows:

```javascript
Client.configure({
  key: 'eyJhbGciOiJSUzI1NiIsI5cCI6IkpXVCJ9...',
})
  .then(function() {
    console.log('Session' + Client.getSession());
    console.log('Version' + Client.getVersion());

    // ...
  })
  .catch(function(error) {
    console.error(error);
  });
```

### Options

| Option         | Type     | Description     | Default                     |
|----------------|----------|-----------------|-----------------------------|
| `key`          | String   | API Key         | `''`                        |
| `endpoint`     | String   | API Endpoint    | `https://sobol.io/d/api/v1` |
| `headers`      | Object   | Request Headers | `{}`                        |
| `orgId`        | String   | Organization ID | `''`                        |
| `errorHandler` | Function | Error Handler   | `Promise.reject(err)`       |

**Note**: to obtain a key, please go to [Sobol](https://sobol.io/d/login) and navigate to `Settings` -> `Applications`.

## Query

To query the API, refer to the list of endpoints contained within the `Client`:

```javascript
console.log(Client);
```

### Example

```javascript
Client.configure({
  key: 'eyJhbGciOiJSUzI1NiIsI5cCI6IkpXVCJ9...',
})
  .then(function() {
    Client.Users.find()
      .then(function(res) {
        console.log('Sobol has ' + res.data.length + ' users.');
      })
      .catch(function(error) {
        console.error('Network Error: ' + error.response.data);
      });
  })
```
**Note**: this client uses the [Axios Response Schema](https://github.com/axios/axios#response-schema).

To run a few samples, create a `.env` and add `SOBOL_API_KEY=...` in this project's root.  
Then run:
- Node: `npm run start-node`
- Browser: `npm run start-browser`

## Extending the Client

To extend the library, create a subclass as follows:

```javascript
// client.js

const BaseClient = require('@sobol/client/base');

class MyClient extends BaseClient {
  constructor() {
    super();

    this.CustomEndpoints = {
      version: () => this._request.get('version'),
    };
  }
}

module.exports = new MyClient();
```

Then use in:

```javascript
// index.js

const MyClient = require('./client.js');

MyClient.configure({
  key: 'eyJhbGciOiJSUzI1NiIsI5cCI6IkpXVCJ9...',
})
  .then(() => {
    MyClient.CustomEndpoints.version()
      .then((res) => {
        console.log('Sobol Version: ', res.data);
      });
  });
```
**Note**: the browser distribution can not be extended.

## Helper Functions

Use these functions to get information about the current instance as follows:

1. `getSession()` - returns the current session
2. `getKey()` - returns the current key
3. `getOrgId()` - returns the current organization Id
4. `getVersion()` - returns the current version

## Clean Up

The `destroy()` function can be called once to dismantle the current instance as follows:

```javascript
Client.configure({
  key: 'eyJhbGciOiJSUzI1NiIsI5cCI6IkpXVCJ9...',
})
  .then(function() {
    Client.destroy();
  })
```

## Help and Feedback

For help and feedback, please send us an email to team@sobol.io and we will respond as soon as possible.

---
_Source: https://npm.io/package/@sobol/client · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
