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

@theshedman/openhim-mediator-utils

v0.3.1

Published

Utilities for creating OpenHIM mediators

Downloads

10

Readme

OpenHIM mediator utils

This package contains a few useful functions to make it easier to develop OpenHIM mediators. When creating a node.js mediator you can make use of it by installing it through NPM as follows:

npm install --save openhim-mediator-utils

You can then use the package as follows:

const utils = require('openhim-mediator-utils');

utils.registerMediator(...);
utils.authenticate(...);
utils.genAuthHeaders(...);
utils.activateHeartbeat(...);
utils.deactivateHearbeat(...);
utils.fetchConfig(...);

Testing

To run the tests, there are a few prerequisite steps. Run the below steps in the order specified to run the tests.

  • npm install
  • npm run openhim:start
  • npm run test

Note: Run the following command post testing to clean your environment

  • npm run openhim:destroy

API details

Mediator Registration

.registerMediator(options, mediatorConfig, callback)

Register this mediator with OpenHIM core using the supplied mediatorConfig. This function takes an options object, the mediator config to register this mediator with and a callback as parameters.

The options object has the following format:

  • options.apiURL - the URL of the OpenHIM core API eg. "https://localhost:8080"
  • options.username - the username of the user to be authenticate with
  • options.password - the password for the user

mediatorConfig is an object that follows the mediatorConfig structure: http://openhim.readthedocs.org/en/latest/dev-guide/mediators.html#mediator-registration

The callback is called with an error object if an error occurs otherwise it is called with nothing.

OpenHIM API Authentication

.authenticate(options, callback)

Fetches authentication detail from the OpenHIM core to use for future communication, options must contain:

  • options.apiURL - the URL of the OpenHIM core API eg. "https://localhost:8080"
  • options.username - the username of the user to be authenticated
  • options.trustSelfSigned - [optional] boolean which defaults to false - if set to true, ignore self signed certificate errors (for non-production use)

callback will be called with an Error object if an error occurs, otherwise the body received from the OpenHIM-core server is returned. This is an object like the following {salt: <userSalt>, ts: <timestampOfServer>}.

.genAuthHeaders(options)

Generates authentication headers to make an authenticated API requests. This can only be used after the .authenticate() function has been called for this user. The username and password of the user must be passed to this function as strings in the options object (eg. {username: '<username>', password: '<password>'}).

The authentication headers are returned as a headers object. eg.

headers = {
 'auth-username': username,
 'auth-ts': ts,
 'auth-salt': salt,
 'auth-token': token
}

If the user has not been authenticated first, then an exception will be thrown

Mediator Heartbeats and Configuration

.activateHeartbeat(options, interval)

Begins sending heartbeats to the OpenHIM-core server (also returns any config changes). This function takes an options object with the following properties:

  • options.apiURL - the URL of the OpenHIM core API eg. "https://localhost:8080"
  • options.username - the username of the user to be authenticated
  • options.password - the password for the user
  • options.urn - the URN of the mediator to send heartbeats for
  • options.trustSelfSigned - [optional] boolean which defaults to false - if set to true, ignore self signed certificate errors (for non-production use)

It also takes an interval parameter which is the interval to send heartbeats in ms. This parameter default to 10s.

This function returns an event emitter which emits a 'config' event with a config object each time the mediator config is changed on the OpenHIM. If an error occurs an 'error' event is emitted with an error object.

.deactivateHeartbeat()

Deactivates the sending of heartbeats.

.fetchConfig(options, callback)

Forces the latest config to be returned from the OpenHIM-core. This is useful when you need to fetch initial config at mediator startup (if you are just interested in the latest config updates use rather .activateHeartbeat(...) above). This function takes an options object with the following properties:

  • options.apiURL - the URL of the OpenHIM core API eg. "https://localhost:8080"
  • options.username - the username of the user to be authenticated
  • options.password - the password for the user
  • options.trustSelfSigned - [optional] boolean which default to false - if set to true, ignore self signed certificate errors (for non-production use)

callback will be called with an Error object if an error occurs, otherwise the config received from the OpenHIM-core server is returned.