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 🙏

© 2025 – Pkg Stats / Ryan Hefner

devicehive-proxy-message

v1.0.13

Published

DeviceHive proxy messages classes

Downloads

628

Readme

devicehive-proxy-message

DeviceHive proxy messages classes

DeviceHive server entities and plugins should connect to the DeviceHive WebSocket proxy DeviceHive WebSocket proxy has it's own messages formats. This module helps to work with this formats transforms raw proxy messages to JS object with fully named fields.

Module structure

  • Message - Base Proxy Message class
  • MessageUtils - Utility Message class
  • MessageBuilder - Message Builder
  • PayloadNormalizer - Normalizer for Message payload
  • payload:
    • TopicCreatePayload - Payload for topic create request/response
    • TopicListPayload - Payload for topic list request/response
    • TopicSubscribePayload - Payload for topic subscribe request/response
    • TopicUnsubscribePayload - Payload for topic unsubscribe request/response
    • NotificationCreatePayload - Payload for notification create request
    • NotificationPayload - Payload for notification push message
    • PluginAuthenticatePayload - Payload for plugin authentication request
    • HealthPayload - Payload for health check response
    • TokenPayload - Payload for plugin token (plugin authentication response)
    • ErrorPayload - Error response payload

Message

Raw message:

{
    "id": <message id>, 
    "t": <message type>, 
    "a": <message action>, 
    "p": <message payload>, 
    "s": <message status>
}

Message object:

{
    "id": <message id>, 
    "type": <message type>, 
    "action": <message action>, 
    "payload": <message payload>, 
    "status": <message status>
}

Usage example:

const { Message } = require(`devicehive-proxy-message`);

const requestMessage = new Message({
    "id": 1, 
    "type": "topic", 
    "action": "list"
});

const responseMessage = Message.normalize({
    "id": 1, 
    "t": "topic", 
    "a": "list", 
    "p": { "t": ["testTopic"] }, 
    "s": 0
});

MessageUtils

MessageUtils is a class with next static members:

  • MessageUtils.TOPIC_TYPE = "topic"
  • MessageUtils.NOTIFICATION_TYPE = "notif"
  • MessageUtils.HEALTH_CHECK_TYPE = "health"
  • MessageUtils.PLUGIN_TYPE = "plugin"
  • MessageUtils.ACK_TYPE = "ack"
  • MessageUtils.NO_ACTION = undefined
  • MessageUtils.CREATE_ACTION = "create"
  • MessageUtils.LIST_ACTION = "list"
  • MessageUtils.SUBSCRIBE_ACTION = "subscribe"
  • MessageUtils.UNSUBSCRIBE_ACTION = "unsubscribe"
  • MessageUtils.AUTHENTICATE_ACTION = "authenticate"
  • MessageUtils.SUCCESS_STATUS = 0
  • MessageUtils.FAILED_STATUS = 1

Usage example:

const { Message, MessageUtils } = require(`devicehive-proxy-message`);

const requestMessage = new Message({
    "id": 1, 
    "type": MessageUtils.TOPIC_TYPE, 
    "action": MessageUtils.LIST_ACTION
});

MessageBuilder

MessageBuilder is a class with next static members:

  • MessageBuilder.createTopic(payload, id), payload is an object like for TopicCreatePayload constructor, id - message id;
  • MessageBuilder.listTopics(id), id - message id
  • MessageBuilder.subscribeTopic(payload, id), payload is an object like for TopicSubscribePayload constructor, id - message id;
  • MessageBuilder.unsubscribeTopic(payload, id) , payload is an object like for TopicUnsubscribePayload constructor, id - message id;
  • MessageBuilder.createNotification(payload, id) , payload is an object like for NotificationCreatePayload constructor, id - message id;
  • MessageBuilder.authenticatePlugin(payload, id) , payload is an object like for PluginAuthenticatePayload constructor, id - message id;
  • MessageBuilder.health(id), id - message id

Usage example:

const { MessageBuilder } = require(`devicehive-proxy-message`);

const requestMessage = MessageBuilder.listTopics(1);

PayloadNormalizer is used by Message class in normalize method.

Payloads

All fields in payloads objects prefixed by '_' and has corresponding javascript get/set function without '_' prefix

TopicCreatePayload

Raw payload:

{
    "t": <list of topics>
}

TopicCreatePayload object:

{
    "topicList": <list of topics>
}

TopicListPayload

Raw payload:

{
    "t": <list of topics>
}

TopicListPayload object:

{
    "topicList": <list of topics>
}

TopicSubscribePayload

Raw payload:

{
    "sg": <subscription group>,
    "t": <list of topics>
}

TopicSubscribePayload object:

{
    "subscriptionGroup": <subscription group>,
    "topicList": <list of topics>
}

TopicUnsubscribePayload

Raw payload:

{
    "sg": <subscription group>,
    "t": <list of topics>
}

TopicUnsubscribePayload object:

{
    "subscriptionGroup": <subscription group>,
    "topicList": <list of topics>,
}

NotificationCreatePayload

Raw payload:

{
    t: <topic name>,
    m: <notification message>,
    part: <topic partition>
}

NotificationCreatePayload object:

{
    topic: <topic name>,
    message: <notification message>,
    partition: <topic partition>
}

NotificationPayload

Raw payload:

{
    "m": <notification message>
}

NotificationPayload object:

{
    "message": <notification message>
}

PluginAuthenticatePayload

Raw payload:

{
    "token": <plugin access token>
}

PluginAuthenticatePayload object:

{
    "token": <plugin access token>
}

HealthPayload

Raw payload:

{
    prx: <proxy status>,
    mb: <message buffer status>,
    mbfp: <message buffer fill percentage>,
    comm: <internal message broker status>
}

HealthPayload object:

{
    proxy: <proxy status>,
    messageBuffer: <message buffer status>,
    messageBufferFillPercentage: <message buffer fill percentage>,
    communicator: <internal message broker status>
}

TokenPayload

Raw payload:

{
    e: <token expiration date>,
    t: <token type>,
    tpc: <plugin topic>
}

TokenPayload object:

{
    expirationDate: <token expiration date>,
    type: <token type>,
    topic: <plugin topic>
}

ErrorPayload

Raw payload:

{
    m: <error message>,
    c: < error code>
}

TokenPayload object:

{
    message: <error message>,
    code: <error code>
}