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

@borealise/pipeline

v1.0.0-alpha.4

Published

Official realtime pipeline client for Borealise

Downloads

462

Readme

@borealise/pipeline

Official Borealise realtime pipeline client.

This package provides a typed WebSocket client for Borealise pipeline events, including:

  • identify and session bootstrap
  • heartbeat management
  • dispatch event subscriptions
  • reconnect with backoff
  • strongly typed opcodes and payloads

Runtime support

  • Browser: works out of the box using native WebSocket.
  • Node.js: you must provide a WebSocket implementation, usually ws.

Installation

Install the package:

npm install @borealise/pipeline

If you run this in Node.js, install ws too:

npm install ws

Quick start (browser)

import { createPipeline, Events } from '@borealise/pipeline'

const pipeline = createPipeline({
  url: 'wss://prod.borealise.com/ws',
  tokenProvider: () => localStorage.getItem('token'),
  loggerName: 'Pipeline',
})

pipeline.onConnection('onReady', (ready) => {
  console.log('ready session', ready.session_id)
  pipeline.subscribe([Events.USER_UPDATE, Events.ROOM_CHAT_MESSAGE])
})

pipeline.onConnection('onDisconnect', (code, reason) => {
  console.log('disconnected', code, reason)
})

pipeline.connect()

Quick start (Node.js with ws)

Node has no global WebSocket by default. Inject one via webSocketFactory.

import WebSocket from 'ws'
import { createPipeline, Events } from '@borealise/pipeline'

const pipeline = createPipeline({
  url: 'wss://prod.borealise.com/ws',
  tokenProvider: () => process.env.BOREALISE_TOKEN,
  webSocketFactory: (url) => new WebSocket(url) as unknown as WebSocket,
})

pipeline.on(Events.USER_UPDATE, (payload) => {
  console.log('user update', payload)
})

pipeline.connect()

How the pipeline works

1. Connect

When you call connect(), the client opens the WebSocket and moves state to connecting.

2. HELLO handshake

Server sends HELLO with:

  • session_id
  • heartbeat_interval

Client starts heartbeat timer with jitter and resolves auth token from tokenProvider.

3. Identify

If tokenProvider returns a token, the client sends IDENTIFY.

4. READY

On successful auth, server sends READY.

Client:

  • moves state to identified
  • stores user/session metadata
  • resubscribes previous event subscriptions

5. Dispatch

Server emits DISPATCH frames with event code and payload.

Client fan-outs events to:

  • event listeners registered via on(event, listener)
  • connection listener onDispatch
  • optional dispatch bridge set via setDispatchHandler

6. Reconnect behavior

On non-terminal disconnects, client reconnects automatically with backoff:

  • 1000ms
  • 2000ms
  • 5000ms
  • 10000ms
  • 30000ms

Max attempts: 10.

No reconnect for normal/explicit auth close codes.

State model

Possible connection states:

  • disconnected
  • connecting
  • connected
  • reconnecting
  • identified

Useful getters:

  • pipeline.state
  • pipeline.user
  • pipeline.isConnected
  • pipeline.isIdentified

API surface

Connection

  • connect()
  • disconnect()

Authentication and presence

  • identify(token)
  • updatePresence(status, activity?)

Subscriptions

  • subscribe(eventCodes)
  • unsubscribe(eventCodes)

Chat

  • sendChatMessage(roomSlug, content)

Event listeners

  • on(eventCode, listener)
  • off(eventCode, listener)
  • onConnection(eventName, listener)
  • offConnection(eventName, listener)

Connection event names:

  • onConnect
  • onDisconnect
  • onReconnect
  • onStateChange
  • onReady
  • onError
  • onDispatch

Important options

createPipeline options:

  • url: required pipeline endpoint
  • tokenProvider: optional callback returning auth token
  • loggerName: optional logger scope
  • webSocketFactory: required for Node.js and custom environments

Typed constants and helpers

The package exports protocol constants and helper functions:

  • Opcodes
  • Events
  • Presence
  • Activity
  • Roles
  • CloseCodes
  • PipelineErrors
  • getEventName(code)
  • getPipelineErrorName(code)

Dispatch bridge integration

For frameworks with centralized stores, use setDispatchHandler to bridge incoming lifecycle and event actions:

pipeline.setDispatchHandler((action, payload) => {
  // Example: forward to your store dispatcher
  store.dispatch(action, payload)
})

Actions emitted by the client:

  • pipeline/setConnectionState
  • pipeline/setReady
  • pipeline/setInvalidSession
  • pipeline/handleDispatch
  • pipeline/handleServerError

Error handling notes

  • Server-side protocol errors are emitted through onError with numeric code/message.
  • Client parse/listener failures are logged, not thrown, to keep the connection alive.
  • send methods are safe no-ops if socket is not open.

Production recommendations

  • Always use wss in production.
  • Keep tokenProvider fast and side-effect free.
  • Subscribe only to events your UI or worker actually consumes.
  • Register listeners before connect() when you need first-event guarantees.
  • Call disconnect() on app shutdown or teardown.

Local development

Build package:

npm run build

Watch mode:

npm run dev