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

@product-intelligence-hub/sdk-core

v0.4.2

Published

Core SDK internals for Product Intelligence Hub

Readme

@product-intelligence-hub/sdk-core

Core SDK internals for Product Intelligence Hub. This package provides the base implementation used by platform-specific SDKs.

Overview

This package is not intended for direct use. Instead, use one of the platform-specific SDKs:

Architecture

sdk-core/
├── client.ts       # PIHClient base class
├── identity.ts     # IdentityManager - user/anonymous ID management
├── session.ts      # SessionManager - session tracking
├── transport.ts    # Transport - HTTP communication
├── queue.ts        # EventQueue - batching and retry logic
├── errors.ts       # PIHError - error handling
├── types.ts        # TypeScript interfaces
└── utils.ts        # Utility functions

Core Components

PIHClient

Base client class that platform SDKs extend:

import { PIHClient, StorageAdapter } from "@product-intelligence-hub/sdk-core";

class MyPlatformClient extends PIHClient {
  constructor(config: PIHConfig, storage: StorageAdapter) {
    super(config, storage);
  }

  async initialize(): Promise<void> {
    await super.initialize();
    // Platform-specific initialization
  }

  // Override to auto-collect platform-specific context
  protected getContext(): Record<string, unknown> {
    return {
      screenWidth: ...,
      locale: ...,
      // Platform-specific fields
    };
  }
}

StorageAdapter

Interface for platform-specific storage:

interface StorageAdapter {
  getItem(key: string): Promise<string | null>;
  setItem(key: string, value: string): Promise<void>;
  removeItem(key: string): Promise<void>;
}

IdentityManager

Manages user identity:

  • Anonymous ID generation and persistence
  • User ID tracking after identify()
  • User traits storage

SessionManager

Manages session lifecycle:

  • Session ID generation
  • Automatic session rotation on timeout
  • Session start/end callbacks
  • Session enrichment: sessionNumber (incrementing counter, persisted) and eventIndex (position within session, resets each session)

EventQueue

Handles event batching:

  • Configurable flush interval and batch size
  • Automatic retry with exponential backoff
  • Persistent queue storage

Transport

HTTP transport layer:

  • Track and identify endpoints
  • Feature flag fetch and evaluation endpoints
  • Retry logic
  • Error handling
  • Sends X-SDK-Name / X-SDK-Version headers (from SDKMeta) on every request

Exports

// Types
export type {
  PIHConfig,
  AutocaptureConfig,
  TrackEvent,
  TrackOptions,
  IdentifyPayload,
  TrackResponse,
  IdentifyResponse,
  QueuedEvent,
  StorageAdapter,
  TransportOptions,
  ClientState,
  SDKMeta,
  FeatureFlags,
  FeatureFlagConfig,
} from "./types.js";

// Errors
export { PIHError } from "./errors.js";
export type { PIHErrorCode } from "./errors.js";

// Core classes
export { PIHClient } from "./client.js";
export { IdentityManager } from "./identity.js";
export { SessionManager } from "./session.js";
export { Transport } from "./transport.js";
export { EventQueue } from "./queue.js";

// Utilities
export {
  generateUUID,
  getTimestamp,
  dateToTimestamp,
  getBackoffDelay,
  STORAGE_PREFIX,
  STORAGE_KEYS,
  DEFAULTS,
} from "./utils.js";

AutocaptureConfig

The AutocaptureConfig type defines all autocapture options:

interface AutocaptureConfig {
  pageViews?: boolean;       // default: true
  clicks?: boolean;          // default: false
  clickSelector?: string;    // default: "[data-track]"
  forms?: boolean;           // default: false
  performance?: boolean;     // Web Vitals tracking (default: false)
  engagement?: boolean;      // Time-on-page + scroll depth (default: false)
  errorTracking?: boolean;   // JS error capture (default: false)
}

Extending

To create a new platform SDK:

  1. Create a storage adapter implementing StorageAdapter
  2. Extend PIHClient with platform-specific features
  3. Override initialize() for platform setup
  4. Override getContext() to auto-collect platform-specific device/browser context
  5. Add platform-specific tracking methods

Related