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

@rollgate/sdk-core

v1.2.1

Published

Core utilities for Rollgate SDKs - cache, circuit breaker, retry, metrics, tracing

Readme

@rollgate/sdk-core

CI License: MIT

Internal core utilities for Rollgate TypeScript SDKs.

Note: This is an internal package. Do not use directly. Use @rollgate/sdk-node for server-side or @rollgate/sdk-browser for client-side applications.

Purpose

This package provides shared utilities used by all Rollgate TypeScript SDKs:

  • Types & Interfaces: Common type definitions for flags, users, and configuration
  • HTTP Client: Base HTTP client with retry logic and circuit breaker
  • Event Emitter: Type-safe event system for SDK events
  • Cache Utilities: Flag caching with ETag support
  • Error Types: Standardized error handling across SDKs
  • Evaluation Logic: Flag evaluation with operators and targeting rules
  • Event Tracking: Conversion event collection for A/B testing

Architecture

sdk-core (this package)
    │
    ├── sdk-node (server-side)
    │
    └── sdk-browser (client-side)
            │
            ├── sdk-react
            ├── sdk-vue
            ├── sdk-angular
            └── sdk-svelte

Exports

| Module | Description | | ---------- | -------------------------------------------- | | types | TypeScript interfaces and types | | errors | RollgateError and error categories | | http | HTTP client with retry/circuit | | cache | In-memory and persistent caching | | evaluate | Flag evaluation engine | | events | Analytics events and EventCollector | | retry | Retry logic with exponential backoff | | metrics | SDK metrics collection and Prometheus export | | tracing | Distributed tracing with W3C Trace Context | | reasons | Evaluation reasons for flag decisions |

Event Tracking (A/B Testing)

The EventCollector class buffers conversion events and sends them to the server in batches. It is used internally by sdk-node and sdk-browser to power the track() method.

EventCollector

import { EventCollector } from "@rollgate/sdk-core";
import type {
  EventCollectorConfig,
  TrackEventOptions,
} from "@rollgate/sdk-core";

const collector = new EventCollector({
  endpoint: "https://api.rollgate.io/api/v1/sdk/events",
  apiKey: "your-api-key",
  flushIntervalMs: 30000, // Flush every 30 seconds (default)
  maxBufferSize: 100, // Force flush at 100 buffered events (default)
  enabled: true, // Enable/disable tracking (default: true)
});

// Start periodic flushing
collector.start();

// Track a conversion event
collector.track({
  flagKey: "checkout-redesign",
  eventName: "purchase",
  userId: "user-123",
  variationId: "variant-b", // optional
  value: 29.99, // optional numeric value (e.g., revenue)
  metadata: { currency: "EUR" }, // optional metadata
});

// Manual flush
await collector.flush();

// Check buffer stats
const stats = collector.getBufferStats();
// => { eventCount: 0 }

// Listen to events
collector.on("flush", (data) => {
  console.log(
    `Sent ${data.eventsSent} events, server received ${data.received}`,
  );
});
collector.on("error", (err) => {
  console.error("Event tracking error:", err);
});

// Stop and flush remaining events
await collector.stop();

TrackEventOptions

| Property | Type | Required | Description | | ------------- | ------------------------- | -------- | ------------------------------------------ | | flagKey | string | Yes | The flag key this event is associated with | | eventName | string | Yes | Event name (e.g., purchase, signup) | | userId | string | Yes | User ID | | variationId | string | No | Variation ID the user was exposed to | | value | number | No | Numeric value (e.g., revenue amount) | | metadata | Record<string, unknown> | No | Additional event metadata |

EventCollectorConfig

| Property | Type | Default | Description | | ----------------- | --------- | ------- | ------------------------------------------ | | endpoint | string | "" | API endpoint for event tracking | | apiKey | string | "" | API key for authentication | | flushIntervalMs | number | 30000 | Flush interval in milliseconds | | maxBufferSize | number | 100 | Max buffered events before forcing a flush | | enabled | boolean | true | Enable/disable event tracking |

Behavior

  • Events are buffered in memory and sent in batches via POST to the configured endpoint.
  • Automatic flush occurs every flushIntervalMs (default: 30 seconds).
  • When the buffer reaches maxBufferSize (default: 100), a flush is triggered immediately.
  • On flush failure, events are placed back into the buffer so they are not lost.
  • The flush timer uses unref() in Node.js so it does not prevent process exit.
  • Events with missing required fields (flagKey, eventName, userId) are silently dropped.

For SDK Developers

If you're building a new Rollgate SDK wrapper:

import {
  RollgateConfig,
  User,
  Flags,
  RollgateError,
  ErrorCategory,
  EventCollector,
  DEFAULT_EVENT_COLLECTOR_CONFIG,
} from "@rollgate/sdk-core";
import type {
  EventCollectorConfig,
  TrackEventOptions,
} from "@rollgate/sdk-core";

To add event tracking to a new SDK:

  1. Create an EventCollector instance in your client constructor, deriving the endpoint from baseUrl.
  2. Call collector.start() during initialization.
  3. Expose track(options), flush(), and getEventStats() on your public client API.
  4. Call collector.stop() in your close()/destroy() method to flush remaining events.

License

MIT