All Projects → Ilshidur → node-mercure

Ilshidur / node-mercure

Licence: GPL-3.0 License
📳 Mercure Hub & Publisher implemented in node.js.

Programming Languages

javascript
184084 projects - #8 most used programming language
HCL
1544 projects

Projects that are alternatives of or similar to node-mercure

action-mercure
🚀 GitHub Action for Mercure.
Stars: ✭ 14 (-48.15%)
Mutual labels:  subscription, server-sent-events, push, live-updates, mercure
Mercure
Server-sent live updates: protocol and reference implementation
Stars: ✭ 2,608 (+9559.26%)
Mutual labels:  server-sent-events, push, mercure
Pushpin
Proxy server for adding push to your API
Stars: ✭ 3,050 (+11196.3%)
Mutual labels:  server-sent-events, push
Restbed
Corvusoft's Restbed framework brings asynchronous RESTful functionality to C++14 applications.
Stars: ✭ 1,551 (+5644.44%)
Mutual labels:  server-sent-events, push
signalr-client
SignalR client library built on top of @aspnet/signalr. This gives you more features and easier to use.
Stars: ✭ 48 (+77.78%)
Mutual labels:  push
openmessaging.github.io
OpenMessaging homepage
Stars: ✭ 12 (-55.56%)
Mutual labels:  push
gn-api-sdk-node
SDK em NodeJS integrada a API Gerencianet. Esta SDK está preparada para integração à API Pix e API Boletos da Gerencianet, que lhe permite realizar o gerenciamento de cobranças Pix com QR Code e Pix Copia e Cola, boleto/Bolix, carnê, cartão de crédito e muito mais.
Stars: ✭ 33 (+22.22%)
Mutual labels:  subscription
push
基于springboot & netty & kafka 实现的消息推送服务
Stars: ✭ 32 (+18.52%)
Mutual labels:  push
birthday-keeper
一个生日管理APP, UI风格模仿的系统闹钟, 可以添加, 编辑, 删除生日以及本地推送提醒, 项目截图见README.
Stars: ✭ 27 (+0%)
Mutual labels:  push
awesome-ecommerce
Collect and develop Open Source or Free Projects for building ecommerce platform easy and fast and free
Stars: ✭ 39 (+44.44%)
Mutual labels:  subscription
starlette-graphql
The starlette GraphQL implement, which support query, mutate and subscription.
Stars: ✭ 15 (-44.44%)
Mutual labels:  subscription
OneSignal-WordPress-Plugin
OneSignal is a free push notification service for web and mobile apps. This plugin makes it easy to integrate your website with OneSignal Push Notifications. https://onesignal.com
Stars: ✭ 71 (+162.96%)
Mutual labels:  push
go-gin-web-server
Deploy Go Gin on Render
Stars: ✭ 23 (-14.81%)
Mutual labels:  server-sent-events
android-easy-gcm
Use this library to add GCM to your project, only in a few minutes !
Stars: ✭ 50 (+85.19%)
Mutual labels:  push
Stage.js
Stage.js - Single-Page Web Application front-end framework
Stars: ✭ 13 (-51.85%)
Mutual labels:  server-sent-events
wave
Wave - The Software as a Service Starter Kit, designed to help you build the SAAS of your dreams 🚀 💰
Stars: ✭ 3,646 (+13403.7%)
Mutual labels:  subscription
ejabberd mod apns
An ejabberd module to send PUSH messages to iOS devices through APNS
Stars: ✭ 31 (+14.81%)
Mutual labels:  push
easylist-thailand
📃 EasyList filter subscription for 🇹🇭 Thailand.
Stars: ✭ 30 (+11.11%)
Mutual labels:  subscription
PurchaseHelper
Sample app to explain the In-App purchase implementation in Android using Play-billing library
Stars: ✭ 30 (+11.11%)
Mutual labels:  subscription
wxpusher-sdk-java
微信消息实时推送服务[WxPusher]的Java版本sdk,可以通过API实时给个人微信推送消息。wechat pusher.
Stars: ✭ 201 (+644.44%)
Mutual labels:  push

mercure

Mercure Hub & Publisher implemented in Node.js.

stability-beta Build Status

npm version Known Vulnerabilities dependency status devdependency status downloads Code Climate

NPM

Note: this npm package has been transfered for a new project by the initial owner, which serves a totally different purpose. This new version is an implementation of the Mercure protocol. The previous mercure package had 1 release (0.0.1) and served as a file downloader. You can still access it: https://www.npmjs.com/package/mercure/v/0.0.1. Please make sure to lock this version in your package.json file, as the new versions will begin at 0.0.2 and will keep following the semver versioning.

TODOs

  • CORS
  • Hearthbeat mechanism (https://github.com/dunglas/mercure/pull/53)
  • Docker image (iso with official image)
  • Prometheus metrics exporter:
    • Subscribers count
    • Events count / size (in Bytes), per publisher
    • Publishers IPs
    • Instances count
  • hub.on('connect') listeners
  • Events database
  • Export authorization.js mechanism
  • Discovery helpers
  • Handle Forwarded and X-Forwarded-For headers (related issue)
  • Provide a Socket.io adapter (see this thread)
  • Allow the dev to pass an URL in the Publisher contructor
  • Publisher: allow the user to specify a JWT key and the claims instead of a JWT
  • Publisher: getters like get host(), port, protocol...
  • Increase code quality score
  • JSDoc
  • Logging
  • Unit tests
  • Find a way to clear Redis if the process gets interrupted
  • Benchmarks

State

This is a beta version. This has not fully been tested in production yet.

This implementation does not reflect the latest specification since they got changed. I don't recommend to use this module.

Requirements

  • node.js >= 11.7.0
  • Redis (optional)

Features

  • 100% implementation of the protocol
  • Events asymmetric encryption
  • Easy integration to any existing app using http.Server or express
  • Redis-based clustering support
  • Inventory of all open connections stored in Redis, per node process
  • Kill switch

Future improvements

  • Implement as a lambda function ?

Installation

npm install mercure --save

Usage

This library provides 3 components: a Hub, a Server and a Publisher:

Classes preview

Simple hub

-> Documentation

The Hub class is the core component that uses a simple http.Server instance. An existing instance can be provided to the Hub, thus the Hub will use it instead of creating a new one.

Use case: implanting the hub on an existing http.Server app, without the need to handle external publishers (only the app does the publishing).

It handles:

  • the SSE connections
  • the events database
  • the authorization mechanism
  • events related to the Hub activity
const http = require('http');
const { Hub } = require('mercure');

const server = http.createServer((req, res) => {
  res.writeHead(200, { 'Content-Type': 'text/plain' });
  res.end('200');
});

const hub = new Hub(server, {
  jwtKey: '!UnsecureChangeMe!',
  path: '/.well-known/mercure',
});

hub.listen(3000);

Hub server

-> Documentation

The Server is built upon the Hub component. It creates a new Express instance and allows external publishers to POST an event to the hub.

Use case: implanting he hub on an new application that is meant to accept external publishers, with no other HTTP server ... or one listening on a different port.

It handles everything the Hub does, plus:

  • a freshly created Express instance, built upon the Hub's http.Server (middlewares can be applied to enhance security)
  • external publishers (POST requests)
const { Server } = require('mercure');

const server = new Server({
  jwtKey: '!UnsecureChangeMe!',
  path: '/.well-known/mercure',
});

server.listen(3000);

Because the Server leverages Express, it is possible to add middlewares in front of the internal Hub middleware:

const compression = require('compression');

class SecuredHubServer extends Server {
  configure() {
    this.app.use(compression());
  }
}

const server = new SecuredHubServer(...);

Publisher

-> Documentation

It can be created in different ways:

  • using an existing Hub instance (when the app is meant to be THE ONLY publisher)
  • using an existing Server instance (when the app is meant to be a publisher)
  • using configuration: host, port... (when the publisher and the hub are distant)

It handles:

  • Message publication to the Hub
  • Message encryption (optional)
const { Publisher } = require('mercure');

const publisher = new Publisher({
  protocol: 'https', // or 'http', but please don't.
  host: 'example.com',
  port: 3000,
  path: '/.well-known/mercure',
  jwt: 'PUBLISHER_JWT',
});

// Payload to send to the subscribers.
const data = {
  '@id': 'http://localhost:3000/books/666.jsonld',
  hello: 'world',
};

await publisher.publish(
  ['https://example.com:3000/books/666.jsonld'], // Topics.
  JSON.stringify(data),
);

API

API docs can be found in the docs/API.md file.

Encrypting the datas

In certain cases, the Mercure hub can be hosted by a third-party host. You don't really want them to "sniff" all your cleartext messages. To make the Publisher => Hub => Subscriber flow fully encrypted, it is required that the Publisher sends encrypted data.

To achieve this, the Publisher#useEncryption() method will activate messages encryption. Thus, the Hub will not be able to access your private datas:

const crypto = require('crypto');
const util = require('util');

const publisher = new Publisher({
  // ...
});

const data = { message: 'TOP SECRET DATAS' };
const { privateKey } = await util.promisify(crypto.generateKeyPair)('rsa', {
  modulusLength: 4096,
  privateKeyEncoding: {
    type: 'pkcs8',
    format: 'pem',
  },
});

// Start encrypting the events.
await publisher.useEncryption({
  rsaPrivateKey: privateKey,
});

// Will send encrypted datas.
await publisher.publish(
  [...], // Topics.
  JSON.stringify(data),
);

Decrypting:

const jose = require('node-jose');

const encryptedData = 'ENCRYPTED DATA';
const decrypted = await jose.JWE.createDecrypt(publisher.keystore).decrypt(encryptedData);

console.log(decrypted.plaintext.toString());

Kill switch

In case the hub must urgently close all connections (e.g.: in case of compromission of the JWT key), a kill switch is available:

await hub.killSwitch();

The new JWT Key will be output to stdout.

License

GNU GENERAL PUBLIC LICENSE v3.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].