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

ham-dex-subscriber

v1.4.12

Published

Subscribe to data, notifications and api from the HAM DEX ESB.

Downloads

82

Readme

ham-dex-subscriber

Subscribe to data, notifications and api from the HAM DEX ESB.

Usage

First, install the package using npm:

npm install ham-dex-subscriber --save

In the options you have to set the parameters given by the HAM DEX provider, i.e.:

options = {
    "subscriber": process.env.HAM_DEX_SUBSCRIBER || "Demo-Subscriber",
    "id": process.env.HAM_DEX_SUBSCRIBER_ID,
    "credentials": {
        "username": process.env.HAM_DEX_USERNAME || "demo-user",
        "password": process.env.HAM_DEX_PASSWORD || "demo-password"
    },
    "esb": {
        "protocol": "https",
        "host": process.env.HAM_DEX_HOST || "ham-dex.local",
        "port": process.env.HAM_DEX_PORT || 3443
    },
    "callback": {
        "protocol": "http",
        // If you leave out "host", HAM DEX Subscriber will determine the current IP address
        // "host": process.env.HOST || "my-dns-name.local",
        "port": process.env.PORT || 3000
    }
};

With that you can instantiate an instance of the ham dex subscriber including the reference to the express app for the notification endpoint:

var subscriber = require("ham-dex-subscriber");
subscriber = subscriber(app, options);

To get the inventory you simply call the getInventoryMethod with the name of the inventory provider:

subscriber.getInventory("Provider name", function(data) {
    // Process data
});

With a third parameter it is possible to extend the inventory call. To get a time span call

var today = new Date();
var tomorrow = new Date();
tomorrow.setDate(today.getDate() + 1);
subscriber.getInventory("Provider name", function(data) {
    // Process data
}, {
    prefix: 'filterprofile',
    from: today,
    to: tomorrow
});

or

var today = new Date();
var tomorrow = new Date();
tomorrow.setDate(today.getDate() + 1);
subscriber.getInventory("Provider name", function(data) {
    // Process data
}, {
    field: 'timestamp',
    between: [today, tomorrow]
});

If you want to get a certain item you can ask for it with its Id

subscriber.getInventory("Provider name", function(data) {
    // Process data
}, {
    id: 123456789
});

Another way to extend the url is to set a suffix.

subscriber.getInventory("Provider name", function(data) {
    // Process data
}, {
    suffix: '/roomEntities'
});

To register an subscription to push notifications you call registerSubscription with the name of the notification provider:

var systemstatusSubscription = subscriber.registerSubscription("systemstatus", function(method, data) {
    // Process data
});

You can also pass additional options to a subscription registration:

var workSubscription = subscriber.registerSubscription("workdata", function(method, data) {
    // Process data
}, {
    from: today,
    to: tomorrow,
    beginningSlash: false
});

Another way to get push notification is via websocket.

var systemstatusSubscription = subscriber.registerWebsocket("systemstatus", function(method, data) {
    // Process data
});

To check if a subscription is still active (returns a Promise):

systemstatusSubscription.isActive().then(isActive => {
    // Do whatever ist needed
});

To end a subscription or websocket afterwards call endSubscription:

systemstatusSubscription.endSubscription();

To change the inventory of a provider there are three CRUD methods. These methods return a Promise to implement a synchronous call.

subscriber.input.put("Provider name", { "data": "Testdata" });
subscriber.input.post("Provider name", { "id": "1234", "data": "Test data" });
subscriber.input.delete("Provider name", "1234");

You can also pass additional options to an input service:

subscriber.input.post("Provider name", {
        "id": "1234",
        "data": "Test data"
    }, {
        prefix: 'filterprofile'
});

To call an api of a provider the callGateway method can be used. These method returns a Promise to implement a synchronous call.

subscriber.callGateway("Provider name", "POST", "path/entity", { "id": "1234", "data": "Testdata" }, function(data) {
    // Process data
    return true;
});

The optional parameter logger enables debug logging.

options = {
    [...],
    "logger": logger
}

License

ISC