npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@znti/dojot-web

v0.5.11

Published

Helper classes to integrate with [dojot](http://www.dojot.com.br/)'s services.

Downloads

74

Readme

dojot-web library

Helper classes to integrate with dojot's services.

This document describes its supported features, along with a basic usage example for each of those.

A sample of its usage can be found on the CLI tool - which uses this module underneath.

Installing

First of all, make sure to install the project package through npm.

npm install --save @znti/dojot-web

Once installed, simply import it as any other module;

const dojotLibrary = require('@znti/dojot-web');

Now all that is left to do is to initialize it with a valid dojot host address.

Initializing

This module is exported as a class. To use it, instantiate it from the required object.

const dojot = new dojotLibrary();

configure(dojotHost)

Initializes the client and setups a connection with the dojot server located on dojotHost.

let dojotHost = 'http://localhost:8000';
dojot.configure(dojotHost).then(configuredClient => {
	// The client is now pointing to the specified dojot host.
	// All thats left is to provide some credentials.
}).catch(console.error);

Make sure to change your dojotHost location, in case yours is not on localhost:8000

initializeWithCredentials(user, password)

Initializes the client based on its credentials. If left empty, the library assumes the default credentials located at configs.js and tries to authenticate with it.

configuredClient.initializeWithCredentials('admin', 'admin').then(initializedClient => {
	// From here on, you can use the helpers this library has
	let {Templates, Devices} = initializedClient;
}).catch(console.error);

initializeWithToken(authToken)

Initializes the client with a JWT previously generated by the dojot server. If you have a cached JWT, this is the best way to reuse it.

let authToken = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJZcVhJSmhOZ0psZFpOUTRYN3BFQkFCanMwNTJiM0lSTiIsImlhdCI6MTU0ODA4MzI3OSwiZXhwIjoxNTQ4MDgzNjk5LCJuYW1lIjoiQWRtaW4gKHN1cGVydXNlcikiLCJlbWFpbCI6ImFkbWluQG5vZW1haWwuY29tIiwicHJvZmlsZSI6ImFkbWluIiwiZ3JvdXBzIjpbMV0sInVzZXJpZCI6MSwianRpIjoiYjg5ZTQ5YWQ4MmUxOTY1YTNkZDE4OGE5NWQ5ZDQ1YjMiLCJzZXJ2aWNlIjoiYWRtaW4iLCJ1c2VybmFtZSI6ImFkbWluIn0.SnXBMGQWF99nCvmn8tH_mloreHA4NYT-S8hkjSo7-0g';

configuredClient.initializeWithAuthToken(authToken).then(initializedClient => {
	// From here on, you can use the helpers this library has
	let {Templates, Devices} = initializedClient;
}).catch(console.error);

Using the library

This section describes the helpers available and gives an overview of each supported feature they have.

getAuthToken()

Returns the curent jwt used for authentication.

Templates

get()

Lists all templates available at dojot.

Templates.get().then(templates => {
	console.log(`Retrieved ${templates.length} templates`);
}).catch(console.error);

set(templateData)

Creates a new template based on data sent on templateData.

Templates.set({
	"label": "EquipmentName",
	"attrs": [
		{
			"label": "serialCode",
			"type": "dynamic",
			"value_type": "string"
		}
	]
}).then(template => {
	console.log('Created a new template');
}).catch(console.error);

delete(templateData)

Deletes the template identified on templateData.

Templates.delete({
        "label": "EquipmentName",
        "attrs": [
                {
                        "label": "serialCode",
                        "type": "dynamic",
                        "value_type": "string"
                }
        ]
}).then(template => {
        console.log('Removed template', template);
}).catch(console.error);

Devices

get(options)

Lists all devices available at dojot.

Devices.get().then(devices => {
	console.log(`Retrieved ${devices.length} devices`);
}).catch(console.error);

options

It's an object detailing what kind of query must be performed. Currently supported options are:

Get data for a specific device
{
	"deviceId": "abc123"
}
Brings the last n entries for each device's dynamic attribute
{
	"historySize": 5
}
Paginate the devices list
{
	"pageSize": 5,
	"pageNumber": 2
}
Filter by device label name (or partial name)
{
	"labelContains": "TemperatureSensor"
}
Filter by one or more attribute values
{
	"filter": {
		"make": "TexasInstruments",
		"type": "Sensor"
	}
}

set(deviceData)

Creates a new device based on data sent on deviceData

Devices.set({
	"label": "equipamentoDoJoao",
	"templates": [
		"12"
	],
	"attrs": [
		{
			"id": 76,
			"label": "serialCode",
			"static_value": "SC01",
			"template_id": "12",
			"type": "dynamic",
			"value_type": "string"
		}
	]
}).then(device => {
	console.log('Created a new device');
}).catch(console.error);

delete(deviceData)

Deletes the device identified on deviceData.

Devices.delete({
	"label": "equipamentoDoJoao",
	"templates": [
		"12"
	],
	"attrs": [
		{
			"id": 76,
			"label": "serialCode",
			"static_value": "SC01",
			"template_id": "12",
			"type": "dynamic",
			"value_type": "string"
		}
	]
}).then(device => {
	console.log('Removed device', device);
}).catch(console.error);

onDeviceData(function callback(deviceData))

Defines a handler for data sent to devices.

Devices.onDeviceData((data) => {
	console.log('Got device message data:', data);
});

onDeviceChange(function callback(changeData))

Defines a handler for device changes.

Devices.onDeviceChange((data) => {
	console.log('Got device change data:', data);
});

Users

get()

Lists existing users

Users.get().then(users => {
	console.log(`Retrieved ${users.length} users`);
}).catch(console.error);

set(userData)

Created an user based on userData

Users.set({
	"username": "user01",
	"service": "admin",
	"email": "[email protected]",
	"name": "user01",
	"profile": "admin"
}).then(user => {
	console.log('Created user', user);
}).catch(console.error);

Resources