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

es-core

v2.0.0

Published

Endocrine System Core

Downloads

17

Readme

Endocrine System: Edge

This is the Endocrine System Core that connects several Endocrine System Edges with each other. For a better understanding also check out the Readme of the Egde.

The main tasks of the Core are:

  • Exchanging hormones and definitions
  • Access control

At the moment the core depends on MongoDB for clustering purposes. This shall be improved in later versions.

Example

While running this example you should start several instances of the Endocrine System Edge.

"use strict";

const mdns = require( 'es-discovery-mdns' );
const ES = require( './lib/es.js' );

let es = new ES( {
  keyPath: 'server.key',
  certPath: 'server.crt',
  caPath: 'ca.crt',
  mongo: { url: 'mongodb://localhost:27017/es' },
  advertisements: [ mdns.advertisement() ],
  accessControl: {
    in: ( client, name ) => {
      // The hormone name must match with the CN of the client certificate
      let cn = client.subject.CN;
      if( name.substr( 0, cn.length ) == cn ) return Promise.resolve();
      else return Promise.reject();
    },
    out: ( client, name ) => {
      // All hormones are sent to every connected client
      return Promise.resolve();
    }
  }
} );

es.on( 'inRejected', ( client, topic ) => {
  // Notify that we just rejected someone's published message
  let ip = client.connection.stream.remoteAddress;
  console.error( "Publish rejected from " + ip + " on topic " + topic );
} );

API

The Endocrine System Core system can be required as follows. The API description refers to ES.

const ES = require( 'es-core' );

Endocrine System Core

let es = ES( options );

Offers a broker for Endocrine System Edge and returns a broker handle.

options can be:

  • certPath: Path to the PEM client certificate.
  • keyPath: Path to the PEM client key.
  • caPath: Path to the PEM certificate authority that signed the client certificate.
  • port: (optional) Port to listen on. Default: 8883.
  • advertisements: (optional) Array of advertisement services. They will make the Core discoverable.
  • mongo: MongoDB configuration:
    • url: URL to the MongoDB server.
  • accessControl: Callback functions for deciding whether or not a message shall pass. If not specified the core will reject by default.
    • in: Callback method called for every incoming hormone. Interface: ( cert, hormoneName ) => {} expecting a promise.
    • out: Callback method called for every outgoing hormone. Interface: ( cert, hormoneName ) => {} expecting a promise.
    • inOther: Callback method called for every MQTT message not related to the endocrine system. Interface: ( cert, topic ) => {} expecting a promise.
    • outOther: Callback method called for every MQTT message not related to the endocrine system. Interface: ( cert, topic ) => {} expecting a promise.

Class: Endocrine System Core

The connection handle es offers some events and methods:

Event: ready

es.on( 'ready', () => { ... } );

Emitted when the server is able to accept incoming connections.

Event: inRejected

es.on( 'inRejected', ( client, topic ) => { ... } );

Emitted if an incoming message is rejected.

Event: outRejected

es.on( 'outRejected', ( client, topic ) => { ... } );

Emitted if an outgoing message is rejected.

Event: inPassed

es.on( 'inPassed', ( client, topic ) => { ... } );

Emitted if an incoming message passed.

Event: outPassed

es.on( 'outPassed', ( client, topic ) => { ... } );

Emitted if an outgoing message passed.

Method: shutdown

es.shutdown();

Shuts down the endorcine system. A promise is returned, that will be resolved if the system has been successfully shut down.