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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@paanj/client

v1.0.5

Published

Core client SDK for Paanj platform - provides authentication and connection management

Readme

@paanj/client

Core client SDK for Paanj platform - provides authentication and connection management

npm version License Node.js

Overview

@paanj/client is the core package that provides:

  • 🔐 Authentication - Anonymous and token-based authentication
  • 🔌 Connection Management - WebSocket and HTTP client infrastructure
  • 🔄 Auto-Reconnection - Built-in reconnection with exponential backoff
  • 🌐 Isomorphic - Works in Node.js and Browser environments
  • 🎯 Base for Feature Packages - Foundation for @paanj/chat-client, etc.

Installation

npm install @paanj/client

Usage

Standalone Usage

import { PaanjClient } from '@paanj/client';

const client = new PaanjClient({
  apiKey: 'pk_live_your_public_key',
  apiUrl: 'https://api.paanj.com',
  wsUrl: 'wss://ws.paanj.com'
});

// Listen for authentication events (same way as listening to messages)
client.on('user.created', ({ userId, accessToken, refreshToken }) => {
  console.log('User created:', userId);
  // Store tokens securely (e.g., localStorage, secure storage)
});

client.on('token.updated', ({ userId, accessToken, refreshToken }) => {
  console.log('Token refreshed');
  // Update stored tokens
});

// Authenticate
await client.authenticateAnonymous({
  name: 'John Doe'
});

// Connect to WebSocket
await client.connect();

// Check connection status
console.log(client.isConnected()); // true

// Disconnect
client.disconnect();

// Refresh token when access token expires
try {
  const newSession = await client.refreshAccessToken();
  console.log('Tokens refreshed:', newSession.accessToken);
} catch (error) {
  console.error('Token refresh failed:', error);
  // Re-authenticate if refresh fails
}

With Feature Packages

The core package is typically used with feature packages:

import { PaanjClient } from '@paanj/client';
import { ChatClient } from '@paanj/chat-client';

const client = new PaanjClient({ apiKey: 'pk_live_key' });
await client.authenticateAnonymous({ name: 'User' });
await client.connect();

// Initialize chat features
const chat = new ChatClient(client);
await chat.messages.send('conv_123', 'Hello!');

API Reference

PaanjClient

Constructor

new PaanjClient(options: ClientOptions)

Options:

  • apiKey: string - Public API key (required)
  • apiUrl?: string - API server URL
  • wsUrl?: string - WebSocket server URL
  • autoReconnect?: boolean - Enable auto-reconnection (default: true)
  • reconnectInterval?: number - Reconnect interval in ms (default: 5000)
  • maxReconnectAttempts?: number - Max reconnect attempts (default: 10)

Methods

authenticateAnonymous(userData, privateData?): Promise<AuthResponse>
Authenticate as a new anonymous user. privateData is optional and not stored but sent to webhooks.

authenticateWithToken(token: string, userId: string | undefined, refreshToken: string): Promise<void>
Authenticate with an existing access token. refreshToken is required for token refresh functionality.

connect(): Promise<void>
Connect to the WebSocket server.

disconnect(): void
Disconnect from the WebSocket server.

isConnected(): boolean
Check if connected to WebSocket.

isAuthenticated(): boolean
Check if authenticated.

getUserId(): string | null
Get the current user ID.

getRefreshToken(): string | null
Get the current refresh token (for token refresh operations).

refreshAccessToken(): Promise<AuthResponse>
Refresh the access token using the stored refresh token. Returns new access and refresh tokens. Automatically emits token.updated event.

on(event: string, callback): Unsubscribe
Register event listener. Works for both WebSocket events (messages, etc.) and authentication events:

  • user.created - Emitted when a user is created via authenticateAnonymous(). Receives { userId, accessToken, refreshToken }
  • token.updated - Emitted when tokens are updated via refreshAccessToken() or authenticateWithToken(). Receives { userId, accessToken, refreshToken }
  • message.create - Emitted when a new message is received (WebSocket event)
  • Other WebSocket events as documented

Security Best Practices

  1. Use Public Keys - Only use public API keys in client-side code
  2. Secure Tokens - Store access tokens securely (e.g., HttpOnly cookies or secure storage)
  3. HTTPS/WSS - Always use secure connections in production

Feature Packages

Build on top of @paanj/client with feature packages:

  • @paanj/chat-client - Chat messaging and conversations
  • @paanj/voice-client - Voice calls (coming soon)
  • @paanj/video-client - Video calls (coming soon)

TypeScript Support

This SDK is written in TypeScript and provides complete type definitions.

License

This project is licensed under a custom license. See the LICENSE file for details.

Support

  • 📧 Email: [email protected]
  • 📖 Documentation: https://docs.paanj.com
  • 🐛 Issues: https://github.com/paanj-cloud/client-js/issues

Made with ❤️ by the Paanj team