vocsel-api
v0.2.40
Published
<img src="https://www.vocsel.com/cube.svg" width="100"> # vocsel.com
Downloads
916
Readme
JavaScript API
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:
- Private (secured access with specified abilities)
- Public (unsecured access with no abilities)
Private authorization
- Using email and password
auth: {
email: <EMAIL>,
password: <PASSWORD>,
}
- Using Bearer JWT-token from https://vocsel.com/auth/login API call
auth: {
token: <TOKEN>
}
- 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);