# vocsel-api

> # vocsel.com

Latest version **0.2.40** (published 2024-03-17) · MIT license · 0 weekly downloads

## Install

```sh
npm install vocsel-api
pnpm add vocsel-api
yarn add vocsel-api
bun add vocsel-api
```

## Health

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

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.2.40 |
| Published | 2024-03-17 |
| First published | 2022-08-31 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 5 |
| Unpacked size | 152.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Serhii Kovalov |
| Maintainers | moiserge |
| Keywords | vocsel.com |

## Links

- npm: https://www.npmjs.com/package/vocsel-api
- Homepage: https://vocsel.com
- npm.io page: https://npm.io/package/vocsel-api

## Dependencies (5)

- [axios](https://npm.io/package/axios.md) ^1.5.0
- [lodash](https://npm.io/package/lodash.md) ^4.17.21
- [form-data](https://npm.io/package/form-data.md) ^4.0.0
- [hl-digits](https://npm.io/package/hl-digits.md) ^0.1.24
- [socket.io-client](https://npm.io/package/socket.io-client.md) ^4.5.1

## Recent versions

- 0.2.40 (latest) — 2024-03-17
- 0.2.39 — 2024-03-17
- 0.2.38 — 2024-03-17
- 0.2.37 — 2024-03-17
- 0.2.36 — 2024-03-17
- 0.2.35 — 2024-03-17
- 0.2.34 — 2024-03-17
- 0.2.33 — 2024-03-17
- 0.2.32 — 2024-03-15
- 0.2.31 — 2024-03-15
- 0.2.30 — 2024-03-15
- 0.2.28 — 2024-03-15
- 0.2.27 — 2024-03-15
- 0.2.26 — 2024-03-11
- 0.2.25 — 2024-03-09
- … 169 more at https://npm.io/package/vocsel-api/versions

## README

<img src="https://www.vocsel.com/cube.svg" width="100">
# vocsel.com

## JavaScript API

[![NPM Version][npm-version-image]][npm-url]
[![NPM Install Size][npm-install-size-image]][npm-install-size-url]
[![NPM Downloads][npm-downloads-image]][npm-downloads-url]

## Installation

```sh
  npm i vocsel-api --save
```

OR

```sh
  yarn add vocsel-api
```

## License

MIT

## API

### Authorization

```js
import VocselApi from "vocsel-api/dist/Api"

const vocselClient = await VocselApi.auth({
  projectId: <PROJECT_ID>,
  auth: { ... },
})
```

Currently we support following types of authorization:

1. Private (secured access with specified abilities)
2. Public (unsecured access with no abilities)

##### Private authorization

1. Using email and password

```js
auth: {
  email: <EMAIL>,
  password: <PASSWORD>,
}
```

2. Using Bearer JWT-token from https://vocsel.com/auth/login API call

```js
auth: {
  token: <TOKEN>
}
```

3. Using User Public Key

```js
auth: {
  publicKey: <PUBLIC_KEY>
}
```

##### Public authorization

```js
import VocselApi from "vocsel-api/dist/Api"

const vocselClient = await VocselApi.auth({
  projectId: <PROJECT_ID>,
  auth: {
    publicKey: <PUBLIC_KEY> // Optional
  },
})
```

## API

### Database API

#### Key-Value Database

##### Set

```js
/**
 * Function that sets key-value
 * @param    {String} key
 * @param    {String} value
 * @return   {Promise<Void>}
 */
await vocselClient.db.set(key, value);
```

##### Get

```js
/**
 * Function that gets a value by a key
 * @param    {String} key
 * @return   {Promise<String>}
 */
const value = await vocselClient.db.get(key);
```

#### Document Database

Mongodb compatible API

##### Create document

```js
/**
* Function that creates a document model
* @param    {String} name
* @return   {Promise<Document>}
*/
const doc = await vocselClient.db.useDocument(name)

/**
* Function that creates a document
* @param    {Boolean} force  - flushed existing document first (false, by default)
* @return   {Void}
*/
await doc.create({ reset: <Boolean> })
```

##### Insert data into the document

```js
const doc = await vocselClient.db.useDocument("test-document");

const data = {
  userName: "Johny",
  userAge: 48,
};

await doc.insert(data);
```

##### Select data from document

```js
const doc = await vocselClient.db.useDocument("test-document");

const request = {
  userName: "Johny",
};

const users = await doc.findMany(request);
// or
const user = await doc.findOne(request);
```

#### Events

Emit and subscribe on events

##### Subscribe on event

```js
await api.event.on(eventName, message => {
  expect(message).to.equal(eventMessage);
});
```

##### Emit an event

```js
await api.event.emit(eventName, eventMessage);
```

[npm-downloads-image]: https://badgen.net/npm/dm/vocsel-api
[npm-downloads-url]: https://npmcharts.com/compare/vocsel-api?minimal=true
[npm-install-size-image]: https://badgen.net/packagephobia/install/vocsel-api
[npm-install-size-url]: https://packagephobia.com/result?p=vocsel-api
[npm-url]: https://npmjs.org/package/vocsel-api
[npm-version-image]: https://badgen.net/npm/v/vocsel-api

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