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

@alertsamurai/sdk-js

v0.0.6

Published

TypeScript SDK for AlertSamurai metrics and alerting

Readme

@alertsamurai/sdk

TypeScript SDK for AlertSamurai metrics and alerting.

Installation

npm install @alertsamurai/sdk-js

Quick Start

import { AlertSamuraiClient } from "@alertsamurai/sdk-js";

const client = new AlertSamuraiClient({
  dsn: "your-project-dsn",
});

// Send a metric
await client.sendMetric({
  metricType: "photo_upload_speed",
  value: 2.5,
  unit: "MB/s",
  environment: "production",
});

// Send an alert
await client.sendAlert({
  message: "Database connection failed",
  priority: "critical",
  environment: "production",
});

// Convenience methods
await client.critical("Server down!");
await client.error("Failed to process payment");
await client.warning("High memory usage");
await client.info("User signed in");
await client.debug("Cache miss for key: xyz");

Configuration

const client = new AlertSamuraiClient({
  dsn: "your-dsn", // Required - found in project settings
  baseUrl: "https://...", // Optional, default: api.alertsamurai.com
  timeout: 30000, // Optional, default: 30s
  retries: 3, // Optional, default: 3
});

Metrics API

Send custom metrics for tracking and threshold-based alerting.

await client.sendMetric({
  metricType: "photo_upload_speed", // Required - metric name
  value: 2.5, // Required - numeric value
  unit: "MB/s", // Optional - unit of measurement
  environment: "production", // Optional - environment name
  metadata: {
    // Optional - additional context
    userId: "123",
    endpoint: "/api/upload",
  },
  timestamp: new Date(), // Optional - defaults to now
});

Threshold-Based Alerts

Configure metric alerts in your AlertSamurai dashboard. When a metric exceeds a threshold (e.g., photo_upload_speed < 1 MB/s), you'll receive a notification via Telegram.

Alerts API

Send application alerts with priority levels.

await client.sendAlert({
  message: "Database connection failed", // Required - alert message
  priority: "critical", // Required - critical|error|warning|info|debug
  environment: "production", // Optional - environment name
  data: {
    // Optional - additional context
    errorCode: "ECONNREFUSED",
    retryCount: 3,
  },
});

Convenience Methods

// These methods send alerts with the specified priority
await client.critical("Server down!"); // priority: "critical"
await client.error("Failed to process payment"); // priority: "error"
await client.warning("High memory usage"); // priority: "warning"
await client.info("User signed in"); // priority: "info"
await client.debug("Cache miss"); // priority: "debug"

// With additional data
await client.error("Payment failed", {
  orderId: "12345",
  errorCode: "INSUFFICIENT_FUNDS",
});

Error Handling

The SDK provides typed errors for different failure scenarios:

import {
  AlertSamuraiClient,
  AlertSamuraiError,
  AuthenticationError,
  ValidationError,
  NetworkError,
} from "@alertsamurai/sdk";

try {
  await client.sendMetric({ metricType: "test", value: 123 });
} catch (error) {
  if (error instanceof AuthenticationError) {
    // Invalid or missing DSN (401)
    console.error("Authentication failed:", error.message);
  } else if (error instanceof ValidationError) {
    // Invalid request data (400)
    console.error("Validation failed:", error.message);
  } else if (error instanceof NetworkError) {
    // Network failure, timeout, etc.
    console.error("Network error:", error.message);
  } else if (error instanceof AlertSamuraiError) {
    // Other API errors
    console.error("API error:", error.message, error.statusCode);
  }
}

Retry Logic

The SDK automatically retries failed requests with exponential backoff:

  • Default: 3 retries
  • Backoff: 1s, 2s, 4s (capped at 10s)
  • Does not retry on authentication (401) or validation (400) errors

Configure retries:

const client = new AlertSamuraiClient({
  dsn: "your-dsn",
  retries: 5, // More retries
  timeout: 60000, // Longer timeout
});

TypeScript Support

The SDK is written in TypeScript and includes full type definitions:

import type {
  AlertSamuraiConfig,
  SendMetricOptions,
  SendMetricResponse,
  SendAlertOptions,
  SendAlertResponse,
  AlertPriority,
} from "@alertsamurai/sdk-js";

const options: SendMetricOptions = {
  metricType: "api_latency",
  value: 150,
  unit: "ms",
};

const priority: AlertPriority = "warning";

Requirements

  • Node.js 18+ (for native fetch support) or browser environment
  • Or any environment with a global fetch implementation

License

MIT