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

@appss/sdk-core

v0.4.8

Published

Core module for APPSS analytics SDK

Downloads

324

Readme

@appss/sdk-core

Core module for APPSS analytics SDK. Provides the abstract client, configuration, batching, retry logic, and platform-agnostic interfaces.

This package is not used directly. Install @appss/sdk-browser or @appss/sdk-node instead.

What's inside

AbstractAppssClient

Base class that browser and node packages extend. Handles the full event lifecycle:

  • init(config) — validate config, create transport/queue/logger, start flush timer
  • track(distinctId, event, properties?) — enrich event with super properties, enqueue, auto-flush on threshold
  • setUserProperty(distinctId, key, value) — send user property to server
  • setUserProperties(distinctId, properties) — send multiple user properties
  • setSuperProperties(properties) — set properties attached to every event automatically
  • resetSuperProperties() — clear all super properties
  • flush() — force send all queued events (deduplicated)
  • destroy() — flush + stop timers + unregister lifecycle handlers

Subclasses must implement:

protected abstract createTransport(config: ResolvedConfig): ITransport;
protected abstract createQueue(config: ResolvedConfig): IEventQueue;
protected abstract createLogger(config: ResolvedConfig): ILogger;
protected abstract registerLifecycleHandlers(): void;
protected abstract unregisterLifecycleHandlers(): void;

Ports (interfaces)

ITransport

interface ITransport {
  send(path: string, body: unknown, headers: Record<string, string>): Promise<TransportResponse>;
}

IEventQueue

interface IEventQueue {
  enqueue(event: AppssEvent): void;
  drain(maxCount: number): AppssEvent[];
  peek(maxCount: number): AppssEvent[];
  size(): number;
  isEmpty(): boolean;
  clear(): void;
}

All methods are synchronous. If your backing store is async, use a local buffer with background sync.

ILogger

interface ILogger {
  debug(message: string, context?: Record<string, unknown>): void;
  info(message: string, context?: Record<string, unknown>): void;
  warn(message: string, context?: Record<string, unknown>): void;
  error(message: string, context?: Record<string, unknown>): void;
}

Configuration

interface AppssConfig {
  apiKey: string;                    // required
  endpoint?: string;                 // default: APPSS production endpoint
  flushInterval?: number;            // ms, default: 10000
  batchSize?: number;                // default: 50
  maxQueueSize?: number;             // default: 10000
  requestTimeout?: number;           // ms, default: 30000
  debug?: boolean;                   // default: false
  retry?: {
    maxRetries?: number;             // default: 5
    baseBackoffMs?: number;          // default: 1000
    maxBackoffMs?: number;           // default: 16000
  };
  logger?: ILogger;                  // custom logger
  queue?: IEventQueue;               // custom queue
  onError?: (error: AppssError) => void;
}

Types

DistinctId

type DistinctId = string | number;

Accepted by track, setUserProperty, setUserProperties. Numbers are converted to strings internally via resolveDistinctId(). NaN, Infinity, and empty strings are silently rejected.

AppssEvent

interface AppssEvent {
  event: string;
  distinctId: string;
  insertId: string;
  timestamp: Date;
  properties?: Record<string, unknown>;
}

Internal event format used by IEventQueue. Generated by buildEvent(), converted to wire format by eventToPayload().

Error handling

All errors extend AppssError:

class AppssError extends Error {
  readonly code: ErrorCode;
  readonly severity: 'warn' | 'error';
  readonly retryable: boolean;
}

Error codes:

| Code | When | |------|------| | NOT_INITIALIZED | Method called before init() | | INVALID_API_KEY | Empty or missing API key | | NETWORK_ERROR | Transport failure or 5xx response | | RATE_LIMITED | 429 response | | API_KEY_REVOKED | 401 response — SDK stops sending | | PROTOCOL_ERROR | 400 or unexpected status | | QUEUE_OVERFLOW | Queue exceeded max size | | MAX_RETRIES_EXCEEDED | All retry attempts failed |

Batching and retry

  • Events are queued and sent in batches (batchSize, default 50)
  • Flush triggers on timer (flushInterval, default 10s) or when batch is full
  • Failed batches are retried with exponential backoff + jitter
  • 413 responses trigger recursive batch splitting
  • 401 response stops all future sends (API key revoked)
  • 429 response respects Retry-After header (clamped to maxBackoffMs)

EventEnricher

Manages super properties that are automatically merged into every tracked event:

class EventEnricher {
  set(key: string, value: unknown): void;
  setAll(properties: Record<string, unknown>): void;
  remove(key: string): void;
  reset(): void;
  enrich(eventProperties?: EventProperties): EventProperties;
}

Super properties override event properties with the same key. Used internally by AbstractAppssClient — platform packages call setSuperProperties() to set $lib and other metadata.

FlushPolicy

Manages the flush timer and flush deduplication:

  • Starts an interval timer that triggers flush
  • flush() ensures only one flush runs at a time (promise deduplication)
  • reset() restarts the timer after a successful flush
  • stop() clears the timer and pending flush

Implementing a new platform

To add support for a new platform (e.g., React Native, Deno):

  1. Create a new package that depends on @appss/sdk-core
  2. Extend AbstractAppssClient
  3. Implement the five abstract methods
  4. Create a constants file with SDK_PLATFORM
  5. Call this.setSuperProperties({ $lib: SDK_PLATFORM }) in init()
import { AbstractAppssClient } from '@appss/sdk-core';

class MyPlatformClient extends AbstractAppssClient {
  override init(config) {
    super.init(config);
    this.setSuperProperties({ $lib: 'my-platform' });
  }

  protected createTransport(config) { /* ... */ }
  protected createQueue(config) { /* ... */ }
  protected createLogger(config) { /* ... */ }
  protected registerLifecycleHandlers() { /* ... */ }
  protected unregisterLifecycleHandlers() { /* ... */ }
}

License

Apache-2.0