← Hookwire / SDK

@hookwire/sdk

TypeScript SDK for browser and Node.js. Connect, listen, react — zero boilerplate.

Install

npm install @hookwire/sdk

Quick start

import { HookwireClient } from '@hookwire/sdk';

const client = new HookwireClient({
  // Your channel name (the random string)
  channelName: 'abc123def456',
  // Optional — defaults to https://hookwire.dev
  baseUrl: 'http://localhost:8787',
});

// Subscribe to real-time events
client.onEvent(event => {
  console.log('New event #', event.seq);
  console.log(event.body.data);
});

// Connect (fetches history, then opens WebSocket)
await client.connect();

// Later…
client.disconnect();

Constructor options

OptionTypeDefaultDescription
channelNamestringYour channel name (required)
baseUrlstringhttps://hookwire.devAPI base URL
autoReconnectbooleantrueReconnect on disconnect
reconnectDelaynumber1000Initial delay in ms (exponential backoff)

Methods

MethodReturnsDescription
connect()Promise<void>Fetch history + open WebSocket
disconnect()voidClose WebSocket, stop reconnect
onEvent(handler)() => voidSubscribe to events. Returns unsubscribe fn.
getHistory({ limit, afterSeq })Promise<ChannelEvent[]>Fetch event history

ChannelEvent shape

interface ChannelEvent {
  id: string;          // evt_xxx
  seq: number;         // Monotonically increasing
  received_at: string;  // ISO timestamp
  method: string;       // HTTP method
  headers: Record<string, string>;
  body: {
    encoding: 'utf8' | 'base64';
    content_type?: string;
    data: string;
    size: number;
    truncated: boolean;
  };
  summary?: { title: string; subtitle?: string };
}

Server-Sent Events (alternative)

If you prefer SSE over WebSocket, use the standard EventSource API — no SDK needed:

const es = new EventSource('https://hookwire.dev/ch/abc123/sse');

es.onmessage = (event) => {
  const data = JSON.parse(event.data);
  console.log('SSE event #', data.seq);
};

Event Replay

Both WebSocket and SSE support ?since= for replaying missed events:

URLBehavior
/ch/:name/wsReal-time only (no history)
/ch/:name/ws?since=0Full replay + real-time
/ch/:name/ws?since=42Replay from seq 42 + real-time
/ch/:name/sseReal-time only
/ch/:name/sse?since=0Full replay + real-time

The SDK automatically appends ?since= on reconnect — you never miss events that are still in the retention window (100 events / 24 hours).

API Docs · Home · GitHub