npm.io
0.2.40 • Published 2 years ago

vocsel-api

Licence
MIT
Version
0.2.40
Deps
5
Size
152 kB
Vulns
0
Weekly
0
# vocsel.com

JavaScript API

NPM Version NPM Install Size NPM Downloads

Installation

  npm i vocsel-api --save

OR

  yarn add vocsel-api

License

MIT

API

Authorization
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
auth: {
  email: <EMAIL>,
  password: <PASSWORD>,
}
  1. Using Bearer JWT-token from https://vocsel.com/auth/login API call
auth: {
  token: <TOKEN>
}
  1. Using User Public Key
auth: {
  publicKey: <PUBLIC_KEY>
}
Public authorization
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
/**
 * Function that sets key-value
 * @param    {String} key
 * @param    {String} value
 * @return   {Promise<Void>}
 */
await vocselClient.db.set(key, value);
Get
/**
 * 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
/**
* 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
const doc = await vocselClient.db.useDocument("test-document");

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

await doc.insert(data);
Select data from document
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
await api.event.on(eventName, message => {
  expect(message).to.equal(eventMessage);
});
Emit an event
await api.event.emit(eventName, eventMessage);

Keywords