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

@devicechain/client

v0.17.0

Published

DeviceChain client SDK — two-tier auth, typed GraphQL operations, and graphql-ws subscriptions over the client wire.

Readme

@devicechain/client

The DeviceChain client SDK: a small, framework-agnostic core for talking to a DeviceChain instance from the browser. Typed GraphQL over fetch, live subscriptions over graphql-ws, and a token seam your app fills in.

There is no Apollo, no store and no React in here. It owns the wire; your app owns state and UI.

npm install @devicechain/client graphql

graphql is a peer dependency — you almost certainly have it already, since the typed documents this SDK accepts come from GraphQL Code Generator.

Where the requests go

Each DeviceChain functional area serves its own GraphQL endpoint, and the SDK addresses them relative to the page, as /api/<area>/graphql. That is the contract a DeviceChain ingress serves: the SPA at /, each area behind /api/<area>.

So an app served from the same origin as the instance needs no configuration at all. An app served from somewhere else needs a dev-server proxy or a reverse proxy that forwards /api/<area>/... to the instance — the same shape the DeviceChain console's own vite.config.ts uses.

Queries and mutations

import { gql } from '@devicechain/client';
import { DeviceListDocument } from './gql/graphql'; // your generated documents

const { devices } = await gql('device-management', DeviceListDocument, {
  first: 25,
});

The area is the first argument, and it is a checked union — AREAS is exported as a real runtime array, not just a type, so you can enumerate it.

The result and variable types are inferred from the document. If the operation takes no variables, the argument is optional.

Failures arrive as a GraphQLRequestError carrying the HTTP status and the GraphQL error list. isForbiddenError(err) is the one classification worth special-casing, because "you may not do that" is a different thing to show a user than "the request did not arrive".

Authentication

DeviceChain uses two tokens: a tenant access token for ordinary work, and an identity token for instance-scoped admin endpoints. You register a getter for each, and the SDK attaches the right one per request — admin areas are detected from the area name, so a new admin call cannot quietly ride the tenant token.

import { setAuthTokenGetter, setIdentityTokenGetter } from '@devicechain/client';

setAuthTokenGetter(async () => store.accessToken); // refresh inside if near expiry
setIdentityTokenGetter(async () => store.identityToken);

Login and refresh calls run without a token; pass { anonymous: true } for those.

decodeToken, isExpired and hasAuthority are exported for reading claims client-side. They decode, they do not verify — the server is the authority.

Subscriptions

import { subscribe, disposeSubscriptions } from '@devicechain/client';

const unsubscribe = subscribe(
  'event-management',
  MeasurementStreamDocument,
  { deviceToken: 'sensor-01' },
  {
    next: (data) => render(data),
    error: (err) => report(err),
    connected: (wasRetry) => setLive(true, wasRetry),
    closed: () => setLive(false),
  },
);

// on sign-out, drop every area socket so a stale token's connection cannot linger
disposeSubscriptions();

One socket is shared per area and reused across subscriptions. connected and closed are connection-level signals, which is what lets a UI tell "connected but idle" apart from "offline" — a distinction a data-only sink cannot make.

Also in here

  • Basemap resolution (resolveBasemap, renderableBasemap) — the client half of the map-tile cascade, so every surface that draws a map resolves a per-surface override over the tenant default the same way.
  • Token masks (generateToken, conformsToMask, parseMask, …) — the device-token vocabulary, validated client-side before a round trip.

Compatibility

ESM only, built for bundler resolution (Vite, webpack, Rollup, esbuild). The emitted declarations use extensionless specifiers, which resolve under TypeScript's bundler module resolution and not under node16/nodenext.

License

Apache-2.0. See LICENSE.