# cubic-client

> Cubic API client.

Latest version **3.6.5** (published 2022-08-31) · MIT license · 0 weekly downloads

## Install

```sh
npm install cubic-client
pnpm add cubic-client
yarn add cubic-client
bun add cubic-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 | 3.6.5 |
| Published | 2022-08-31 |
| First published | 2018-04-05 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 65.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 16 |
| Author | Kaptard |
| Maintainers | kaptard, nexus-ci |

## Links

- npm: https://www.npmjs.com/package/cubic-client
- Repository: https://github.com/cubic-js/cubic
- Homepage: https://github.com/cubic-js/cubic#readme
- Issues: https://github.com/cubic-js/cubic/issues
- npm.io page: https://npm.io/package/cubic-client

## Dependencies (2)

- [ws](https://npm.io/package/ws.md) ^7.2.3
- [async-mutex](https://npm.io/package/async-mutex.md) ^0.1.4

## Recent versions

- 3.6.5 (latest) — 2022-08-31
- 3.6.4 — 2020-03-29
- 3.6.3 — 2020-03-28
- 3.6.2 — 2020-03-28
- 3.6.1 — 2020-03-27
- 3.6.0 — 2020-03-26
- 3.5.3 — 2020-03-22
- 3.5.2 — 2020-03-22
- 3.5.1 — 2020-03-22
- 3.5.0 — 2020-03-22
- 3.4.3 — 2020-03-22
- 3.4.2 — 2020-03-21
- 3.4.1 — 2020-03-21
- 3.4.0 — 2020-03-21
- 3.3.2 — 2020-03-04
- … 39 more at https://npm.io/package/cubic-client/versions

## README

[![cubic-client](https://i.imgur.com/EBnxQiy.png)](/packages/client)

<p align="center">Connection packages to connect to <a href='/packages/api'>Cubic</a> API nodes. Choose your target platform from the available branches.</p>

##

[![npm](https://img.shields.io/npm/v/cubic-client.svg)](https://npmjs.org/cubic-client)
[![build](https://ci.nexus-stats.com/api/badges/cubic-js/cubic/status.svg)](https://ci.nexus-stats.com/cubic-js/cubic)
[![dependencies](https://david-dm.org/cubic-js/cubic-client.svg)](https://david-dm.org/cubic-js/cubic-client)

<br>
<br>


## Installation
`npm install cubic-client`

<br>

## Usage
```js
const Client = require('cubic-client')
const client = new Client()

cubic.get('/foo').then(res => console.log(res.body)) // bar
```

<br>

## Configuration
```javascript
const Client = require('cubic-client')
const client = new Client({key: value})
```

| Key           | Default         | Description   |
|:------------- |:------------- |:------------- |
| api_url | `'http://localhost:3003/'` | URL of cubic API-Node to connect to |
| auth_url | `'http://localhost:3030/'` | URL of cubic Auth-Node to authenticate with |
| user_key | `null` | User key obtained via Auth-Node registration |
| user_secret | `null` | User secret obtained via Auth-Node 

<br>
<br>

## API

```js
client.awaitConnection()
```
>Returns a promise that resolves once the client is fully connected.

<br>

```js
client.isConnected()
```
>Returns a boolean wether the connection is up or not.

<br>

### RESTful methods
```js
client.query(verb, query)
```
>Sends a GET request to the API-Node

| Argument | Description | Default |
|:------------- |:------------- |:------------- |
| verb | RESTful verb. e.g. `GET`. | None |
| query | Request query, either string or body object. | None |

<br>

```js
client.get(url)
```
>Sends a GET request to the API-Node

| Argument | Description | Default |
|:------------- |:------------- |:------------- |
| url | URL to request, without domain. e.g. `/foo`. | None |

<br>

```js
client.post(url, body)
```
>Sends a POST request to the API-Node

| Argument | Description | Default |
|:------------- |:------------- |:------------- |
| url | URL to request, without domain. e.g. `/foo`. | None |
| body | Data to send to endpoint. Can be any data type. | None |

<br>

```js
client.put(url, body)
```
>Sends a PUT request to the API-Node

| Argument | Description | Default |
|:------------- |:------------- |:------------- |
| url | URL to request, without domain. e.g. `/foo`. | None |
| body | Data to send to endpoint. Can be any data type. | None |

<br>

```js
client.patch(url, body)
```
>Sends a PATCH request to the API-Node

| Argument | Description | Default |
|:------------- |:------------- |:------------- |
| url | URL to request, without domain. e.g. `/foo`. | None |
| body | Data to send to endpoint. Can be any data type. | None |

<br>

```js
client.delete(url, body)
```
>Sends a DELETE request to the API-Node

| Argument | Description | Default |
|:------------- |:------------- |:------------- |
| url | URL to request, without domain. e.g. `/foo`. | None |
| body | Data to send to endpoint. Can be any data type. | None |

<br>

### Pub/Sub

```js
client.subscribe(endpoint, fn)
```
>Subscribe to updates on a specific endpoint.

| Argument | Description | Default |
|:------------- |:------------- |:------------- |
| endpoint | URL to listen for updates on, without domain. e.g. `'/foo'` | None |
| fn | Function to run when updates are received. Takes the new data as argument. | None |

<br>

```js
client.unsubscribe(endpoint)
```
>Unsubscribe to updates on a specific endpoint.

| Argument | Description | Default |
|:------------- |:------------- |:------------- |
| endpoint | URL that you are currently subscribed to, without domain. e.g. `'/foo'` | None |

<br>

### Authentication
```js
client.login(user, secret)
```
>Re-authorizes as a specific user at runtime. Usually users should be logged in
through the constructor options.

| Argument | Description | Default |
|:------------- |:------------- |:------------- |
| user | User id, equal to `user_key` when registering. | None |
| secret | User password, equal to `user_secret` when registering. | None |

<br>

```js
client.setRefreshToken(token)
```
>Manually set the refresh token. This way user credentials needn't be exposed.

| Argument | Description | Default |
|:------------- |:------------- |:------------- |
| token | `refresh_token` to use. | None |

<br>

```js
client.getRefreshToken()
```
>Retrieve current refresh token. Will await any existing authentication
process. Useful if the initial login can be done through user/pass but
the refresh token needs to be stored for subsequent logins.

<br>

```js
client.setAccessToken(token)
```
>Manually set the access token. This will expire on the next refresh.

| Argument | Description | Default |
|:------------- |:------------- |:------------- |
| token | `access_token` to use. | None |

<br>

```js
client.getRefreshToken()
```
>Retrieve current access token. Will await any existing authentication process.

<br>

## License
[MIT](/LICENSE.md)

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