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

@elementiallabs/sync-sdk

v1.14.0

Published

Sync SDK for your NodeJS application. This SDK would allow your application to talk to all your registered peers.

Downloads

6

Readme

@elementiallabs/sync-sdk

npm (scoped)

Sync SDK for your NodeJS application. This SDK would allow your application to:

  1. Send transactions to Broker enabling rest of the peers stay up-to-date with latest transactions across all peers of a network.
  2. P2P App to App Communication without getting the broker in the middle (BITM).

Install

$ npm install @elementiallabs/sync-sdk

APIs:

1) writeTX(api_url, payload, (err, resp) => {
    (!err) ? console.log(resp) : console.log(err.state, err.code);
   });
2) readTX(api_url, page, (err, resp) => {
    (!err) ? console.log(resp) : console.log(err.state, err.code);
   })

Usage: Read and Write Transactions

const syncsdk = require('@elementiallabs/sync-sdk');
const config = require('./config');

// First, create a config.json file at app.js/index.js root level
// Second, Config structure to follow:
/*

{
    "peer1": {"alias": "insert your peer name", "ip": "x.x.x.x", "port": "xxxx", "clientid": "insert your client id"},
    "peer2": {"alias": "insert your peer name", "ip": "x.x.x.x", "port": "xxxx", "clientid": "insert your client id"},
    "peer3": {"alias": "insert your peer name", "ip": "x.x.x.x", "port": "xxxx", "clientid": "insert your client id"},
    "peer4": {"alias": "insert your peer name", "ip": "x.x.x.x", "port": "xxxx", "clientid": "insert your client id"},
    "peer5": {"alias": "insert your peer name", "ip": "x.x.x.x", "port": "xxxx", "clientid": "insert your client id"}
}

Refer peer's config file to get alias, ip, port, clientid.

writeTX Payload structure strictly to follow:

const tx = {
    meta: {
        clientid: config.peer1.clientid
    },
    timestamp: Date.now(),
    payload: {
        whatever you want to send ......
    }
}

*/

const { peer1, peer2, peer3, peer4, peer5 ... peerN } = config;

// declare peer variables as much as there are in config.json
const p1 = new syncsdk();
const p2 = new syncsdk();
const p3 = new syncsdk();
const p4 = new syncsdk();
const p5 = new syncsdk();
.
.
.
.
const pN = new syncsdk();

const txPayload = {
    meta: {
        clientid: peer1.clientid
    },
    timestamp: Date.now(),
    payload: {
        xxxxxxx: "xxxxxxxxx",
        body:{
            msg: `Hello ${loremIpsum()}!! Adding new transaction sent from client app!!`
        }
    }
}

p1.writeTX(`http://${peer1.ip}:${peer1.port}/api/sendtxs`, txPayload, (err, resp) => {
    if (!err) {
        console.log(resp);
    } else {
        console.log(err.state, err.code);
    }
});

p2.writeTX(`http://${peer1.ip}:${peer1.port}/api/sendtxs`, txPayload, (err, resp) => {
    if (!err) {
        console.log(resp);
    } else {
        console.log(err.state, err.code);
    }
});

peerName.writeTX(url, payload, (err, resp) => {
    if (!err) {
        console.log(resp);
    } else {
        console.log(err.state, err.code);
    }
});

const page['no'] = 1;

p1.readTX(`http://${peer1.ip}:${peer1.port}/api/fetchtxs`, page.no, (err, resp) => {
    if (!err) {
        console.log(resp);
    } else {
        console.log(err.state, err.code);
    }
});

p2.readTX(`http://${peer1.ip}:${peer1.port}/api/fetchtxs`, page.no, (err, resp) => {
    if (!err) {
        console.log(resp);
    } else {
        console.log(err.state, err.code);
    }
});


peerName.readTX(url, pageNumber, (err, resp) => {
    if (!err) {
        console.log(resp);
    } else {
        console.log(err.state, err.code);
    }
});

Usage: Send and Receive Intra-Peer Messages


Peer 1 Client try to send message to Peer 2

const p1MessageConfig = {
    type: config.peer1.clientid,
    msg: 'Hey there Peer 2 !!!!',
    from: config.peer1.alias
    to: config.peer2.alias
}

p1.sendMessage(p1MessageConfig)
.then(response => {
    console.log(response);
});

p2.listener(config.peer2.clientid, config.peer2.alias)
.then(objct => {
    if(objct.msg) {
        console.log(objct.msg);
        objct.cb(null, 'whatever reply you want to pass');
    }
})