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 🙏

© 2026 – Pkg Stats / Ryan Hefner

dpsn-client

v2.0.1

Published

DPSN SDK for managing topic subscriptions and publications in web3

Readme

dpsn-client-nodejs

Overview

dpsn-client-nodejs is an SDK for creating, accessing data streams on DPSN infrastructure. It allows you to connect to a DPSN broker, publish messages to topics, and subscribe to topics to receive messages.

For more information, visit:

Installation

npm install dpsn-client

Usage

Prerequisites

  • DPSN URL: Your DPSN broker URL (e.g., betanet.dpsn.org)
  • DPSN Access Token: Your private key for authentication

Import the Library

import {DpsnClient} from 'dpsn-client';

Create Client Instance

// With SSL (mqtts://)
const dpsnClient = new DpsnClient('<dpsn_url>', '<dpsn_access_token>', true);

// Without SSL (mqtt://)
const dpsnClient = new DpsnClient('<dpsn_url>', '<dpsn_access_token>', false);

// Default behavior (client defaults to mqtts://)
const dpsnClient = new DpsnClient('<dpsn_url>', '<dpsn_access_token>');

Understanding DPSN Topics

Topics in DPSN are data distribution channels that enable secure data streams. They function as:

  • Data streams: Publishers push data to topics, and subscribers receive data from topics
  • Authenticated channels: Authentication is provided through cryptographic signatures

Setup Event Handlers

Note: Set up these event handlers before calling init() to properly handle connection events

dpsnClient.on('connect', (res) => {
  console.log(res);
})

dpsnClient.on('publish', (res) => {
  console.log(res);
})

dpsnClient.on('subscription', (res) => {
  console.log("STARTED SUBSCRIPTION:", res)
})

dpsnClient.on('disconnect', (res) => {
  console.log(res);
})

dpsnClient.on('error', (err) => {
  console.log("OPERATION FAILED: ", err);
})

Initialize DPSN Client

await dpsnClient.init()

Publish Data

await dpsnClient.publish('<topic>', <data>);

Subscribing to Topics

To subscribe to a topic and handle incoming messages, use the subscribe method:

await dpsnClient.subscribe('<topic>', (message) => {
  console.log("Received message:", message);
});

Unsubscribing from Topics

To unsubscribe from a topic when you no longer want to receive messages, use the unsubscribe method:

const result = await dpsnClient.unsubscribe('<topic>');
console.log(`Successfully unsubscribed from ${result.topic}: ${result.message}`);

This method returns a response object containing:

  • topic: The topic you unsubscribed from
  • message: A confirmation message ("unsubscribed")

Disconnect

For properly terminating the connection when needed

await dpsnClient.disconnect();

API Reference

Classes

DpsnClient

Constructor
constructor(dpsnUrl: string, dpsn_accestoken: string, ssl?: boolean)

Parameters:

  • dpsnUrl - The DPSN broker URL
  • dpsn_accestoken - Your private key for authentication
  • ssl - Optional. If true, forces mqtts://. If false, forces mqtt://. If not provided, uses the protocol from the URL.
Methods

Types

InitOptions

interface InitOptions {
  connectTimeout?: number;
  retryOptions?: {
    maxRetries?: number;
    initialDelay?: number;
    maxDelay?: number;
    exponentialBackoff?: boolean;
  };
}

DpsnEventType

type DpsnEventType = 'connect' | 'subscription' | 'publish' | 'disconnect' | 'error';

DpsnEventData

type DpsnEventData = {
  connect: string;
  subscription: { topic: string, qos: number };
  publish: { topic: string, messageId?: number };
  disconnect: void;
  error: Error | DPSNError;
};

DPSNError

class DPSNError extends Error {
  code: DPSN_ERROR_CODES;
  status?: 'connected' | 'disconnected';
  
  constructor(options: {
    code: DPSN_ERROR_CODES;
    message: string;
    status?: 'connected' | 'disconnected';
    name?: string;
  });
  
  toJSON(): {
    code: DPSN_ERROR_CODES;
    message: string;
    status?: 'connected' | 'disconnected';
    name: string;
  };
}

Error Codes

  • CONNECTION_ERROR (400): Connection issues with the DPSN broker
  • UNAUTHORIZED (401): Authentication or authorization failure
  • PUBLISH_ERROR (402): Error when publishing to a topic
  • INITIALIZATION_FAILED (403): Client initialization failure
  • CLIENT_NOT_INITIALIZED (404): Operations attempted before initialization
  • CLIENT_NOT_CONNECTED (405): Operations attempted without connection
  • SUBSCRIBE_ERROR (406): General subscription errors
  • SUBSCRIBE_NO_GRANT (407): Permission denied for subscription
  • SUBSCRIBE_SETUP_ERROR (408): Error setting up subscription handlers
  • DISCONNECT_ERROR (409): Error during disconnection
  • INVALID_PRIVATE_KEY (411): Invalid access token/private key
  • MQTT_ERROR (413): MQTT protocol errors

License

This project is licensed under the ISC License.