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

d2jsapi

v27.0.4

Published

D2000 SCADA javascript/typescript client API. https://d2000.ipesoft.com/

Readme

d2jsapi

TypeScript/JavaScript client API of the D2000 SCADA system for web applications served by SmartWeb. It wraps the CometD client and gives real-time object subscriptions, archive and EDA reads, RPC calls (including stateful RPC conversations), object value writes, service messages, password change and WebAuthn passkey management.

npm install d2jsapi
import {D2WebApiClient} from "d2jsapi";

const d2Api = new D2WebApiClient({url: "/api/cometd"});
d2Api.connect(state => console.log("handshaked:", state.handshaked));

d2Api.subscribeObject("M.Temperature", object => console.log(object.unival));
const result = await d2Api.rpc("E.Demo", "Sum", 1, 2, {type: "real", returnAs: "sum"}).call();

The public API is the D2WebApi interface in src/d2Api.ts. User documentation lives in the SmartWeb documentation (section D2JsApi of the SmartWeb Framework guide).

Build and publish

npm install
npm run build          # tsc -> dist/
npm run publish-lib    # build + npm publish

App channel (internal API)

Warning: the app channel is an internal interface between IPESOFT web applications and the D2Connector process. It is not meant for third-party applications, its messages are not publicly documented and its shape may change between versions without notice.

An app channel is a bidirectional connection between a web application and an application registered in the D2Connector process under a channelGroupId, a path such as /d2/eda. It carries JSON text messages whose content is not interpreted by SmartWeb or by the D2000 Java API. The usage mirrors an RPC conversation: the channel has to be opened first, and only after the server confirmed it can messages be sent and received.

openAppChannel(channelGroupId, params) opens a channel. params.handler receives the channel events and the optional params.timeout (milliseconds, default 35 000) bounds the wait for the server confirmation. The returned promise resolves with the channel handle after the server confirmed the channel. Every call opens a new, independent channel, even for the same channelGroupId: two instances of the same component on one page get two channels and two separate states in D2Connector.

The handle (AppChannel) has the attributes channelGroupId, instanceId (sequence number of the channel within the connection), id (the channel group id without its leading /, then /instanceId, e.g. d2/eda/1) and protocolVersion, the method isOpened(), send(json, timeout?) to send one JSON message (a string) and close() to close the channel.

protocolVersion is the protocol version of the channel group in D2Connector, sent with the server confirmation (0 - the group is not versioned, undefined - the server does not send it). The server does not check it: the application compares it with the version it was built for and decides whether it can use the channel.

The handler (AppChannelHandler) implements:

  • onMessage(channel, json) - a message from D2Connector as a string; messages arrive in sending order and never after onClose,
  • onClose(channel, reason) - the channel is closed; reason (AppChannelCloseReasonEnum) is CLOSED after close(), or TERMINATED when the server or D2Connector closed it or the connection was re-established (rehandshake),
  • onError(channel, error) - optional; a server-side error after the channel was opened. error is an AppChannelError with code (AppChannelErrorCodeEnum: NOT_ALLOWED, NOT_SUPPORTED, OPEN_FAILED, INTERNAL).

If opening fails, the promise is rejected with an AppChannelError with the same codes (NOT_ALLOWED - the app is not allowed by the server configuration, NOT_SUPPORTED - the D2000 Java API on the server has no app channel support, OPEN_FAILED - D2Connector refused the channel or the server timed out, INTERNAL), or with a plain Error on a client-side timeout and when the connection is not handshaked.

const channel = await d2Api.openAppChannel("/d2/eda", {
    handler: {
        onMessage(channel, json) {
            const message = JSON.parse(json);
            // handle the message from D2Connector
        },
        onClose(channel, reason) {
            if (reason === AppChannelCloseReasonEnum.TERMINATED) {
                // reopen after the connection is handshaked again
            }
        },
        onError(channel, error) {
            console.error(channel.id, error.code, error.message);
        }
    },
    timeout: 35000
});

// the application's reply arrives through onMessage
await channel.send(JSON.stringify({channel: "/d2/echo", id: 1, type: "request", data: {text: "Hello"}}));

await channel.close();

A channel is bound to the server connection in the same way as an RPC conversation. When the connection is lost for longer than the CometD session timeout on the server (network outage, sleeping computer, SmartWeb restart, logout), the client performs a new handshake (rehandshake) and every open channel gets onClose with AppChannelCloseReasonEnum.TERMINATED. Channels are not restored automatically because their state in D2Connector no longer exists. The application opens a new channel after the connection is back (connection state change to handshaked, see registerStateChangeHandler). Do not open the new channel directly inside onClose: at that moment the connection is not handshaked yet.

On the server the channel group id must be allowed in the SmartWeb configuration list smartweb.application.cometApi.accessFilter.allowedApps. The list holds wildcard patterns matched case-insensitively against the id with its leading / (* matches across / too) and is empty by default, which disables app channels.

smartweb:
  application:
    cometApi:
      accessFilter:
        allowedApps: ["/d2/eda", "/d2/object/*"]