0.0.8 • Published 1 year ago

node-visionect v0.0.8

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

node-visionect CI

A thin node.js Promise based wrapper around the Visionect Server Management API

Installation NPM Package Version

npm add node-visionect

Example

const VisionectApiClient = require('node-joan')

const vss = new VisionectApiClient({
  apiServer: 'https://localhost:8081',
  apiKey: '<apiKey>',
  apiSecret: '<apiSecret>'
})

vss.devices.get()
  .then(res => console.log(res.status, res.headers, res.data))
  .catch(err => console.error(err))

// Update URL
vss.sessions.patch(uuid, {Backend: {Fields: {url: 'https://example.com'}}})

This library is used in production by the Newswall project - feel free to refer to it for further usage examples.

APIs

Devices APIs

vss.devices.get() // get all devices
vss.devices.get(uuid) // get a particular device
vss.devices.get(uuid, from, to = now, group = false) // Get an array of historical statuses; See http://api.vss.com/#device-status-device-status

vss.devices.update(uuid, data) // update a particular device
vss.devices.update(data) // update all devices
vss.devices.patch(uuid, data) // Partial update a device

vss.devices.delete(uuid) // delete a devices

vss.devices.reboot(uuid1, uuid2, /*...*/) // reboot devices

Device Config APIs

vss.devices.config.get(uuid) // Get all config for device
vss.devices.config.get(uuid, [typeId1, typeId2]/*, ...*/) // Get particular configs e.g. vss.devices.config.get(uuid, [65, 67]) to get WiFi info

vss.devices.config.set(uuid, {Type: id1, value: v1}, {Type: id1, value: v2}, /*...*/) // Set configs

// Full list of type ids: https://docs.visionect.com/AppDevelopment/generalJsExtensions.html#tclv-list
// e.g. to disable system screens (the ones that show when charging or no WiFi)
vss.devices.config.set(uuid, {Type: 49, Value: '0'})

Live View APIs

vss.view.device(uuid) // return current image that is displayed on the device
vss.view.server(uuid) // return the server side image for the device
vss.view.set(uuid, img) // Set the image on device; see http://api.vss.com/#backends

//Example: Save the live view image locally
const fs = require('fs')
const fileType = '.png'
vss.view.device(uuid, fileType).then(res => fs.writeFileSync(uuid + fileType, res.data))

Session APIs

vss.sessions.get() // get all sessions
vss.sessions.get(uuid) // get a particular session

vss.sessions.update(uuid, data) // update a particular session
vss.sessions.update(data) // update all sessions
vss.sessions.patch(uuid, data) // Partial update a session

vss.sessions.create(data) // create a session

vss.sessions.restart(uuid1, uuid2, /*...*/) // restart sessions
vss.sessions.clearCache(uuid1, uuid2, /*...*/) // clear session caches

User APIs

vss.users.get() // get all users
vss.users.get(username) // get a particular user

vss.users.update(username, data) // update a particular user
vss.users.update(data) // update all users
vss.users.patch(uuid, data) // Partial update a user

vss.users.create(data) // create a user

Server APIs

vss.server.status() // Get server status
vss.server.config() // Get server config
vss.server.config(data) // Set server config
vss.server.config(data, patch = true) // Partial update server config
vss.server.orphans(all = true) // See http://api.vss.com/#health

Primitive APIs

Directly call any HTTP endpoints using the following low level utils:

vss.http.get(path)
vss.http.post(path, data)
vss.http.put(path, data)
vss.http.patch(path, data)
vss.http.delete(path, data)
vss.http.options(path)

Plugins

You can access the underlying axios HTTP caller via vss.http. This makes it possible to use any axios plugins e.g.

// This will print all API calls as curl commands to console
const curlirize = require('axios-curlirize')
curlirize(vss.http)

Intercept Requests / Responses

Use axios interceptors to intercept requests/response:

// Intercept requests e.g. to block certain calls
vss.http.interceptors.request.use(req => {
  return (process.env.NODE_ENV === 'test' && req.method.toUpperCase() !== 'GET') ?
    Promise.reject(`Cannot make ${req.method} API calls from tests`) : req
})

// Intercept responses e.g. to log the response / request
vss.http.interceptors.response.use(
  res => {
    console.log(res.request.method, res.request.path, res.status, res.headers)
    return res
  },
  err => {
    console.error('Received non-2xx response', err)
    return Promise.reject(err)
  }
)

// 3rd party logger: https://github.com/hg-pyun/axios-logger
vss.http.interceptors.request.use(AxiosLogger.requestLogger)
0.0.8

1 year ago

0.0.7

1 year ago

0.0.6

1 year ago

0.0.5

1 year ago

0.0.4

1 year ago

0.0.3

1 year ago

0.0.2

1 year ago

0.0.1

1 year ago