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

@computesdk/events

v1.1.0

Published

Events SDK for ComputeSDK - store, retrieve, and subscribe to sandbox events

Readme

@computesdk/events

Events SDK for ComputeSDK - store, retrieve, and subscribe to sandbox events in real-time.

Features

  • HTTP Client - Store and retrieve events via REST API
  • Pub/Sub Client - Real-time event streaming via TCP (Node.js)
  • Auto-reconnect - Automatic reconnection with configurable delays
  • Type-safe - Full TypeScript support

Installation

npm install @computesdk/events

Quick Start

Storing Events (from inside a sandbox)

Use the HTTP client to store events from your sandbox code:

import { createEventsClient } from '@computesdk/events';

const client = createEventsClient({
  accessToken: process.env.COMPUTESDK_ACCESS_TOKEN,
});

// Store an event
const result = await client.storeEvent({
  type: 'execution.completed',
  data: {
    exitCode: 0,
    duration: 1234,
    output: 'Hello, World!',
  },
});

console.log('Event stored:', result.eventId);

Retrieving Events (from your application)

Use your API key to retrieve historical events:

import { createEventsClient } from '@computesdk/events';

const client = createEventsClient({
  apiKey: process.env.COMPUTESDK_API_KEY,
});

// Get all events for a sandbox
const events = await client.getEvents('sandbox-123');

// Filter by type
const execEvents = await client.getEvents('sandbox-123', {
  type: 'execution.completed',
});

// Get events since a timestamp
const recentEvents = await client.getEvents('sandbox-123', {
  since: Date.now() - 3600000, // Last hour
  limit: 50,
});

for (const event of events) {
  console.log(`[${event.type}] ${JSON.stringify(event.data)}`);
}

Real-time Streaming (Node.js)

Subscribe to events in real-time using the Pub/Sub client:

import { createPubSubClient } from '@computesdk/events';

const pubsub = createPubSubClient({
  accessToken: process.env.COMPUTESDK_ACCESS_TOKEN,
  sandboxId: 'sandbox-123',
});

// Listen for events
pubsub.on('event', (event) => {
  console.log(`Received: ${event.type}`, event.data);
});

pubsub.on('connect', () => {
  console.log('Connected to event stream');
});

pubsub.on('disconnect', () => {
  console.log('Disconnected (will auto-reconnect)');
});

pubsub.on('error', (error) => {
  console.error('Connection error:', error);
});

// Connect and start receiving events
await pubsub.connect();

// Keep connection alive with periodic pings
setInterval(() => pubsub.ping(), 30000);

// Disconnect when done
await pubsub.disconnect();

API Reference

EventsClient

HTTP client for storing and retrieving events.

Constructor Options

interface EventsClientConfig {
  /** Gateway base URL (default: "https://events.computesdk.com") */
  gatewayUrl?: string;
  /** ComputeSDK API key (for retrieving events) */
  apiKey?: string;
  /** JWT access token (for storing events from sandbox) */
  accessToken?: string;
  /** Request timeout in milliseconds (default: 30000) */
  timeout?: number;
}

Methods

storeEvent(options) - Store an event (requires access token)
const result = await client.storeEvent({
  type: 'custom.event',
  data: { key: 'value' },
});
// Returns: { eventId, sandboxId, type, timestamp }
getEvents(sandboxId, options?) - Retrieve events (requires API key)
const events = await client.getEvents('sandbox-123', {
  type: 'execution.completed', // Filter by type
  since: Date.now() - 3600000, // Events after timestamp (ms)
  limit: 100,                   // Max events (1-1000)
});
setApiKey(apiKey) - Update the API key
setAccessToken(token) - Update the access token

EventsPubSubClient

TCP client for real-time event streaming (Node.js only).

Constructor Options

interface PubSubClientConfig {
  /** Gateway host (default: "events.computesdk.com") */
  host?: string;
  /** Pub/Sub port (default: 6380) */
  port?: number;
  /** JWT access token for authentication */
  accessToken: string;
  /** Sandbox ID to subscribe to */
  sandboxId: string;
  /** Reconnect on disconnect (default: true) */
  autoReconnect?: boolean;
  /** Reconnect delay in milliseconds (default: 1000) */
  reconnectDelay?: number;
}

Methods

connect() - Connect and subscribe to events
disconnect() - Disconnect from the server
getState() - Get connection state

Returns: 'disconnected' | 'connecting' | 'connected' | 'error'

ping() - Send a keepalive ping

Events

pubsub.on('event', (event: SandboxEvent) => { ... });
pubsub.on('connect', () => { ... });
pubsub.on('disconnect', () => { ... });
pubsub.on('error', (error: Error) => { ... });

Types

SandboxEvent

interface SandboxEvent {
  id: string;
  sandboxId: string;
  workspaceId: number;
  type: string;
  data: Record<string, unknown>;
  timestamp: number; // Unix timestamp in milliseconds
}

Error Handling

The package exports specific error classes:

import {
  EventsError,        // Base error class
  EventsAuthError,    // Authentication failures
  EventsNetworkError, // Network/timeout errors
  EventsPubSubError,  // Pub/Sub specific errors
} from '@computesdk/events';

try {
  await client.getEvents('sandbox-123');
} catch (error) {
  if (error instanceof EventsAuthError) {
    console.error('Check your API key');
  } else if (error instanceof EventsNetworkError) {
    console.error('Network issue:', error.message);
  }
}

Environment Variables

The client automatically reads these environment variables:

| Variable | Description | |----------|-------------| | COMPUTESDK_API_KEY | API key for retrieving events | | COMPUTESDK_ACCESS_TOKEN | Access token for storing events | | COMPUTESDK_GATEWAY_URL | Custom gateway URL | | COMPUTESDK_PUBSUB_HOST | Custom pub/sub host | | COMPUTESDK_PUBSUB_PORT | Custom pub/sub port |

License

MIT