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

@aptly-sdk/brook

v0.0.34

Published

Realtime fault-tolerant realtime (pub/sub) SDK

Downloads

100

Readme

Brook SDK

A realtime fault-tolerant pub/sub SDK for JavaScript and React applications.

Features

  • ✅ Fault-tolerant real-time messaging
  • ✅ Automatic reconnection with exponential backoff
  • ✅ Message replay for missed messages
  • ✅ React hooks for seamless integration
  • ✅ Full TypeScript support
  • ✅ Lightweight and performant

Getting Started

Get Your API Key

Before using the Brook SDK, you'll need to get your API key from the Console

Demo

👾 Live Demo – play around and see it in action.

Installation

npm install @aptly-sdk/brook
# or
pnpm add @aptly-sdk/brook
# or
yarn add @aptly-sdk/brook

Quick Start

JavaScript

import Brook from '@aptly-sdk/brook';

const client = new Brook({ apiKey: 'your-api-key' });
await client.connect();

const channel = client.realtime.channel('my-topic');

channel.stream((message) => {
	console.log('Incoming message', message);
});

React

import Brook from '@aptly-sdk/brook';
import { BrookProvider, useStream, usePublish } from '@aptly-sdk/brook/react';

// 1. Initialize the client
const client = new Brook({ apiKey: 'your-api-key' });

// 2. Wrap your app with the BrookProvider
function App() {
	return (
		<BrookProvider config={client}>
			<Component1 />
			<Component2 />
		</BrookProvider>
	);
}

function Component1() {
	// 3. Subscribe to the topic
	useStream('my-topic', (message, metadata) => {
		console.log(message, metadata);
	});

	// ... rest of your component
}

function Component2() {
	const publish = usePublish('my-topic');

	useEffect(() => {
		// 4. Publish to the topic (Optional)
		publish({
			message: 'Hello from React SDK',
		});
	}, []);
}

React Setup Guide

1. Initialize the Client

import Brook from '@aptly-sdk/brook';

const client = new Brook({ apiKey: 'your-api-key' });

2. Setup the Provider

import { BrookProvider } from '@aptly-sdk/brook/react';

function App() {
	return (
		<BrookProvider config={client}>
			<Component1 />
			<Component2 />
		</BrookProvider>
	);
}

Provider Props

| Prop | Type | Required | Description | | -------- | ------- | -------- | --------------------- | | config | Brook | ✓ | Brook client instance |

3. Subscribe to Topics

import { useStream } from '@aptly-sdk/brook/react';

function Component1() {
	// Automatically subscribes on mount and unsubscribes on unmount
	useStream('my-topic', (message, metadata) => {
		console.log('Received:', message);
		console.log('Metadata:', metadata);
	});
}

Note: useStream automatically subscribes on component mount and unsubscribes on unmount. You typically don't need to use the subscribe and unsubscribe functions from the returned object.

useStream Hook

Parameters

| Parameter | Type | Required | Description | | ---------- | ---------- | -------- | ------------------------------------------------- | | topic | string | ✓ | The topic/channel name to subscribe to | | callback | function | ✓ | Callback function called when messages are received |

Callback signature: (message, metadata) => void

| Parameter | Type | Description | | --------- | -------- | ----------------------------- | | message | any | The message data received | | metadata | object | Message metadata | | metadata.offset | number | Message sequence number | | metadata.timestamp | string | ISO timestamp when message was sent | | metadata.replay | boolean | True if this is a replayed (missed) message | | metadata.channel | string | Channel name |

Returns

| Property | Type | Description | | ------------- | ---------- | ---------------------------------------- | | streaming | boolean | Whether actively streaming | | subscribe | () => void | (Optional) Function to manually subscribe - rarely needed | | unsubscribe | () => void | (Optional) Function to manually unsubscribe - rarely needed |

4. Publish to Topics

import { usePublish } from '@aptly-sdk/brook/react';

function Component2() {
	const publish = usePublish('my-topic');

	useEffect(() => {
		publish({
			message: 'Hello from React SDK',
		});
	}, []);
}

usePublish Hook

Parameters

| Parameter | Type | Required | Description | | --------- | -------- | -------- | ------------------------------------ | | topic | string | ✓ | The topic/channel name to publish to |

Returns

| Property | Type | Description | | --------- | --------------------------------------- | ------------------------------------------- | | publish | (data: any) => Promise<PublishResult> | Function to publish messages to the channel |

publish() Method

Parameters

| Parameter | Type | Required | Description | | --------- | ----- | -------- | --------------------------------------------------- | | data | any | ✓ | Serializable value that will be sent to the channel |

Returns Promise<PublishResult>

| Property | Type | Description | | --------- | ---------------- | ----------------------------- | | error | string \| null | Error message (if any) | | success | boolean | Success indicator | | offset | number | Message offset in the channel |

Additional React Hooks

useConnection

Monitor the connection status.

import { useConnection } from '@aptly-sdk/brook/react';

function Component3() {
	const { status } = useConnection();

	console.log('Connection status', status);
}
Returns

| Property | Type | Description | | -------- | -------- | --------------------- | | status | string | Current connection status: 'disconnected', 'connecting', 'unauthorized', 'authenticating', 'connected', 'reconnecting', or 'failed' |

TypeScript Support

This package includes comprehensive TypeScript declarations. All hooks and client methods are fully typed for an optimal development experience.