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

polfan-server-js-client

v0.4.10

Published

JavaScript client library for handling communication with Polfan chat server.

Readme

pserv-js-client-library

TypeScript client library to handle connection with Devana (new Polfan) chat service.

How to use?

(async () => {
    // Get access token by credentials
    const token = await PServ.AuthClient.createToken('login', 'password');
    
    // Create web api client (there is also WebSocket client available)
    const client = new PServ.WebApiChatClient({
        token: token.token, // Pass received token
        url: 'https://pserv-api-address',
    });
    
    // Call `GetSession` command which returns user session data
    const session = await client.send('GetSession');
    
    console.log("My nick:", session.user.nick);
    console.log("The rooms you are in:", session.rooms);
    console.log("The spaces you are in:", session.spaces);
    console.log("The version of server you connected to:", session.serverVersion);
})();

Connection maintenance

WebSocketChatClient keeps the connection alive: after any loss (error, connecting timeout, missing pong, closure with a code other than 1000) it reconnects indefinitely, with an exponential backoff between attempts. The disconnect event tells whether a retry follows. A pending connect() promise resolves once an attempt authenticates, and is rejected by disconnect(), which also stops reconnecting. An invalid token (Bye with AuthenticationException) rejects connect() with the Bye data, emits an error event and stops reconnecting as well.

const wsClient = new PServ.WebSocketChatClient({
    token: 'your-access-token',
    url: 'wss://pserv-websocket-address',
    connectingTimeoutMs: 10000, // Per attempt (default)
    reconnect: {
        minDelayMs: 1000, // Delay before the first retry, doubled on every next one (default)
        maxDelayMs: 30000, // Maximum delay between retries (default)
    },
});

State management

The library provides built-in state management for WebSocket client. To enable it, just pass stateTracking option to the WebSocketChatClient constructor:

const wsClient = new PServ.WebSocketChatClient({
    token: 'your-access-token',
    url: 'wss://pserv-websocket-address',
    stateTracking: true, // Enable state tracking
});

With state tracking enabled, the client will automatically maintain the current state of rooms, users, and messages, by handling incoming events from the server. Reactive data structures are available via ObservableIndexedObjectCollection objects, which allows you to subscribe to changes.

Important note: you can cache these objects for the connection lifetime, but you should refetch them after reconnecting, because some structures are rebuild from scratch on Session event.

Package entitlements

GetEntitlements answers what a space or the current account has. A space package and a user package describe disjoint features, so their keys live in separate enums and are never mixed:

const space = await client.send('GetEntitlements', {spaceId: 'space-id'});
const members = space.data.entitlements[PServ.SpaceFeature.MembersLimit];

if (members !== PServ.NO_LIMIT && memberCount >= members) {
    // the space package is full
}

const me = await client.send('GetEntitlements', {});
const whitelist = space.data.entitlements[PServ.SpaceFeature.AccessWhitelist] === true;

A limit of PServ.NO_LIMIT (-1) means no limit, and a feature the package does not grant is absent. A dictionary feature states its numbers as strings ('250'), and storage is counted in megabytes - use PServ.STORAGE_UNIT_BYTES rather than a literal. The package tells whether a feature exists; who may use it is still decided by role permissions.

The answer to the command also carries what the server knows about the usage, so a client can tell that a file will not fit before it uploads it:

const used = me.data.extras?.storageUsedBytes ?? 0;
const limit = Number(me.data.entitlements[PServ.UserFeature.StorageLimit]) * PServ.STORAGE_UNIT_BYTES;

Whenever a package changes, the server pushes the same Entitlements event on its own - to every member of the space, or to every session of the user (without extras, which is asked for with the command when it is needed):

client.on('Entitlements', entitlements => {
    console.log(entitlements.subject, 'now has', entitlements.planCode);
});

Owners of a space also hear when one of its limits is running out (80%) or is used up (100%):

client.on('EntitlementUsage', usage => {
    console.log(usage.feature, `${usage.usage}/${usage.limit}`);
});

An operation the package does not allow is refused with a single EntitlementException error whose message is the key that stopped it, e.g. space.members.limit.

Access tickets

Services outside the chat server (billing for now) are called by the client directly, with a short-lived signed ticket instead of any shared secret. Ask for it right before the request:

// The space ticket requires the ManageSpace permission; without spaceId the ticket covers the account
const ticket = await client.send('CreateAccessTicket', {audience: 'billing', spaceId: 'space-id'});

const subscription = await fetch(`https://billing-address/spaces/space-id/subscription`, {
    headers: {Authorization: `Bearer ${ticket.data.token}`},
}).then(response => response.json());

The ticket carries the audience, the scope it covers (space:<id> or user:<id>) and its expiresAt; the service rejects it outside that scope, for another audience or after it expires.

Development

The protocol types under src/types are a git submodule (pserv-ts-types). A plain git clone leaves it empty, which is what makes tsc/the build fail with Module '"./types/src"' has no exported member '...' for every command and event - clone with git clone --recurse-submodules, or after a plain clone run:

git submodule update --init --recursive

A submodule's checked-out commit doesn't move on its own when you git pull/git checkout the parent repo, so npm run build (prebuild) runs this for you. Only a bare tsc/webpack call skips it.