New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@pubkeeper/client

Package Overview
Dependencies
Maintainers
4
Versions
35
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@pubkeeper/client

Pubkeeper javascript SDK

  • 1.0.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
4
Weekly downloads
 
Created
Source

PubKeeper JS Client

This is a PubKeeper client that enables web browsers to join, consume, and produce content on the PubKeeper network. At this time, the JS client is only capable of publishing/consuming WebSocket based transports.

Concepts & Terms

  • Brew: the method of delivery - ie. WebSocket / SocketIO
  • Brewer: An object that accepts an input and writes to the respective transport
  • Patron: A consumer of data from a brewer of a respective transport

Crypto / Sec

Communication to the PubKeeper service is conducted over SSL, which allows the service to deliver to clients information, including the AES key of connected brewers.

All data communicated over the PubKeeper network is encrypted with AES-128 encryption. Creating a new brewer will generate an AES key that will be stored with the central PubKeeper service, and distributed to other authenticated clients of the network.

Local Development

npm install

# Build the package
npm run build

# Run the linter
npm run lint

# Run flowtype check
npm run typecheck

# Run unit tests
npm run test

#Compile src flowtyped code to lib
babel src/ -d lib

Basic Syntax

Brewing Setup

To being to produce data into the PubKeeper network you will need to create a bottle in which data can be filled. Then create brewers to produce that bottle of information. The example below will setup a Brewer with the topic of topic.information

import PubkeeperClient from 'pubkeeper-client';
const pc = new PubkeeperClient();

pc.connect({
  socket: {
    host: '127.0.0.1',
    port: 9898,
    room: 'pubkeeper.n.io',
  },
  jwt: 'your jwt',
}).then(successHandler, errorHandler);

const brew = {
  name: 'websocket',
  hostname: 'localhost',
  port: 9555,
};
pc.addBrew(brew);
State Change Callback (Optional)

This callback will be fired upon these events

  • BREWER_NOTIFY
  • BREWER_REMOVED
  • PATRON_NOTIFY
  • PATRON_REMOVED

You will have to import the Packet types and then set the callback

import PubkeeperClient, { Packet } from '@pubkeeper/client';

pc.onStateChange(({ type, obj }) => {
  // the state has changed!
 switch (type) {
    case Packet.BREWER_NOTIFY:
      // BREWER_NOTIFY
      // obj.brewers
      break;
    case Packet.BREWER_REMOVED:
      // BREWER_REMOVED
      // obj.brewers
      break;
    case Packet.PATRON_NOTIFY:
      // PATRON_NOTIFY
      // obj.patrons
      break;
    case Packet.PATRON_REMOVED:
      // PATRON_REMOVED
      // obj.patrons
      break;
    default:
      // Do nothing
      break;
  }
});

Brewer Setup

const brewer = pc.addBrewer('topic.information');

// By default this will send all the brews
// You can tell the brewer to use a specific brew by

const brewer2 = pc.addBrewer({ topic: 'topic.information', brews: ['websocket'] });
Brewer validation

A Brewer cannot have a wildcard topic

It will return an errors array if it did not pass validation which you can display to your users

const brewer = pc.addBrewer('topic.*');
if (brewer.errors) {
  alert('Error!');
  // brewer.errors.forEach(error => console.log(error));
} else {
  this.brewers = [...this.brewers, brewer];
}

Patron Setup

To listen to someone who is brewing information, you need to subscribe to the topic, and configure a callback to occur when there is data available for processing.

const patronConfig = {
        topic: 'weather.*',
      };
const patron = pc.addPatron(patronConfig, function ({ topic, data }) {
        // patron_id: this.id
        // topic
        // data
      });

FAQs

Package last updated on 23 Aug 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc