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

@atlascrew/synapse-api

v0.1.0

Published

TypeScript API client for Synapse - WAF sensor, entity management, and rule evaluation

Readme

synapse-api

TypeScript client for the Synapse (risk-server) API - WAF sensor management, entity tracking, rule evaluation, and actor fingerprinting.

Features

  • Full TypeScript Support - Comprehensive type definitions for all API endpoints
  • Promise-based API - Modern async/await interface with configurable timeouts
  • Rich Error Handling - Custom SynapseError class with semantic helper methods
  • 18 API Methods - Complete coverage of all Synapse endpoints
  • Debug Mode - Optional request/response logging for troubleshooting
  • Zero Dependencies - Uses native fetch API

Installation

# npm
npm install synapse-api

# pnpm
pnpm add synapse-api

# yarn
yarn add synapse-api

Quick Start

import { SynapseClient } from 'synapse-api';

const client = new SynapseClient({
  baseUrl: 'http://localhost:3000'
});

// Check health
const health = await client.health();
console.log(health.status); // "ok"

// Get sensor status
const status = await client.getStatus();
console.log(`Blocked: ${status.blockedRequests}`);

// Evaluate a request (dry-run)
const result = await client.evaluate({
  method: 'GET',
  path: '/api/admin',
  ip: '192.168.1.100'
});
console.log(`Would block: ${result.wouldBlock}`);

Configuration

interface SynapseClientOptions {
  /** Base URL of the Synapse server */
  baseUrl: string;

  /** Request timeout in milliseconds (default: 30000) */
  timeout?: number;

  /** Enable verbose debug logging (default: false) */
  debug?: boolean;
}

API Reference

Categories

| Category | Description | Methods | |----------|-------------|---------| | Health & Status | Server health and metrics | 3 methods | | Entity Management | Tracked entities and blocks | 4 methods | | Configuration | WAF configuration | 2 methods | | WAF Rules | Rule management | 6 methods | | Actor Tracking | Actor fingerprinting | 3 methods |


Health & Status

client.health()

Check server health status.

const health = await client.health();
// { status: 'ok', service: 'synapse', uptime: 3600 }

client.getStatus()

Get sensor status and metrics.

const status = await client.getStatus();
// {
//   totalRequests: 10000,
//   blockedRequests: 150,
//   entities: 523,
//   ...
// }

client.getMetrics()

Get Prometheus-formatted metrics.

const metrics = await client.getMetrics();
// Raw prometheus text format

Entity Management

client.listEntities()

List all tracked entities.

const { entities } = await client.listEntities();
entities.forEach(e => {
  console.log(`${e.ip}: risk ${e.riskScore}`);
});

client.listBlocks()

List all block records.

const { blocks } = await client.listBlocks();
blocks.forEach(b => {
  console.log(`${b.ip}: ${b.reason}`);
});

client.releaseEntity(entityIdOrIp)

Release a blocked entity by ID or IP address.

await client.releaseEntity('192.168.1.100');
// or
await client.releaseEntity('entity-id-abc123');

client.releaseAll()

Release all blocked entities.

const { count } = await client.releaseAll();
console.log(`Released ${count} entities`);

Configuration

client.getConfig()

Get full system configuration.

const config = await client.getConfig();
console.log(config.waf.autoblockThreshold);

client.updateConfig(updates)

Update WAF configuration.

await client.updateConfig({
  autoblockThreshold: 80,
  riskBasedBlockingEnabled: true
});

WAF Rules

client.listRules()

List all WAF rules (static + runtime).

const { rules, stats } = await client.listRules();
console.log(`Total rules: ${stats.total}`);

client.addRule(rule, ttl?)

Add a runtime rule with optional TTL.

await client.addRule({
  description: 'Block /admin access',
  blocking: true,
  matches: [{ type: 'path', match: '/admin' }]
}, 3600); // TTL in seconds

client.removeRule(ruleId)

Remove a runtime rule by ID.

await client.removeRule(123);

client.clearRules()

Clear all runtime rules.

await client.clearRules();

client.reloadRules()

Reload rules from file.

await client.reloadRules();

client.evaluate(request)

Evaluate a request against WAF rules (dry-run).

const result = await client.evaluate({
  method: 'POST',
  path: '/api/login',
  ip: '192.168.1.100',
  headers: { 'Content-Type': 'application/json' },
  body: '{"username":"admin"}'
});

if (result.wouldBlock) {
  console.log(`Would block: ${result.blockReason}`);
  console.log(`Risk score: ${result.riskScore}`);
}

Actor Tracking

client.listActors()

List all tracked actors.

const { actors } = await client.listActors();
actors.forEach(a => {
  console.log(`${a.ip}: fingerprint=${a.fingerprint}`);
});

client.getActorStats()

Get actor tracking statistics.

const stats = await client.getActorStats();
console.log(`Total actors: ${stats.totalActors}`);

client.setActorFingerprint(ip, fingerprint)

Set fingerprint for an actor.

await client.setActorFingerprint('192.168.1.100', 'fp-abc123');

Error Handling

import { SynapseClient, SynapseError } from 'synapse-api';

try {
  await client.getStatus();
} catch (error) {
  if (error instanceof SynapseError) {
    console.log(`Status: ${error.statusCode}`);

    if (error.isClientError()) {
      console.log('Client error (4xx)');
    } else if (error.isServerError()) {
      console.log('Server error (5xx)');
    } else if (error.isNetworkError()) {
      console.log('Network/timeout error');
    }
  }
}

SynapseError Methods

| Method | Description | |--------|-------------| | isStatus(code) | Check for specific HTTP status | | isClientError() | Check if 4xx error | | isServerError() | Check if 5xx error | | isNetworkError() | Check if network/timeout error |


Examples

Health Monitoring

async function monitorHealth(client: SynapseClient) {
  const health = await client.health();
  if (health.status !== 'ok') {
    console.error('Service unhealthy!');
    return false;
  }
  return true;
}

// Poll every 10 seconds
setInterval(() => monitorHealth(client), 10000);

Block Management

async function releaseHighRiskEntities(client: SynapseClient, threshold: number) {
  const { entities } = await client.listEntities();
  const highRisk = entities.filter(e => e.riskScore > threshold && e.blocked);

  for (const entity of highRisk) {
    console.log(`Releasing: ${entity.ip} (risk: ${entity.riskScore})`);
    await client.releaseEntity(entity.ip);
  }

  return highRisk.length;
}

Rule Testing

async function testRule(client: SynapseClient, rule: RuleDefinition) {
  // Add rule temporarily
  const { rule: added } = await client.addRule(rule, 60); // 1 minute TTL

  // Test against sample requests
  const testRequests = [
    { method: 'GET', path: '/api/users', ip: '10.0.0.1' },
    { method: 'POST', path: '/admin', ip: '10.0.0.1' },
  ];

  for (const req of testRequests) {
    const result = await client.evaluate(req);
    console.log(`${req.method} ${req.path}: ${result.wouldBlock ? 'BLOCKED' : 'ALLOWED'}`);
  }

  // Rule auto-expires after TTL
}

TypeScript Types

All types are exported from the main package:

import type {
  SynapseClientOptions,
  HealthResponse,
  SensorStatus,
  Entity,
  Block,
  EntitiesResponse,
  BlocksResponse,
  ReleaseResponse,
  ReleaseAllResponse,
  ConfigResponse,
  ConfigUpdateResponse,
  WafConfig,
  Rule,
  RuleDefinition,
  RulesResponse,
  AddRuleResponse,
  RemoveRuleResponse,
  ClearRulesResponse,
  ReloadRulesResponse,
  EvaluateRequest,
  EvaluateResult,
  Actor,
  ActorsResponse,
  ActorStats,
  SetFingerprintResponse,
} from 'synapse-api';

Development

# Install dependencies
pnpm install

# Build
pnpm build

# Type-check
pnpm type-check

# Run tests
pnpm test

# Watch mode
pnpm test:watch

See Also


License

Licensed under the GNU Affero General Public License v3.0 only. See LICENSE.