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

guardian-risk

v0.3.1

Published

Configurable risk decision engine using signals, rules, and scoring. Zero runtime dependencies.

Downloads

853

Readme

guardian-risk

Configurable risk decision engine for TypeScript. Evaluate signals against rules and get an explainable risk score.

Production-ready at 0.3.x — zero runtime dependencies, hardened validation, async hooks, and official plugins for Express, Redis, VPN, browser, and logging.

Install

npm install guardian-risk

Usage (core only)

No plugins required — sync analyze() works when no hooks are registered:

import { Guardian } from 'guardian-risk';

const guardian = new Guardian();

const report = guardian
  .signal('postsPerMinute', 50)
  .signal('emailVerified', false)
  .rule({
    name: 'HighPosting',
    when: (s) => (s.postsPerMinute as number) > 20,
    score: 20,
  })
  .rule({
    name: 'UnverifiedEmail',
    when: (s) => s.emailVerified === false,
    score: 15,
  })
  .analyze();

console.log(report.score); // 35
console.log(report.level); // MEDIUM

Official plugins

Install core first, then add only the plugins you need:

| Package | Install | Purpose | |---------|---------|---------| | guardian-risk (this) | npm i guardian-risk | Core engine | | guardian-risk-express | npm i guardian-risk-express | Express middleware + validated IP | | guardian-risk-redis | npm i guardian-risk-redis | Redis session counters + rate limits | | guardian-risk-vpn | npm i guardian-risk-vpn | VPN / proxy / Tor detection | | guardian-risk-browser | npm i guardian-risk-browser | Browser behavioral signals | | guardian-risk-logger | npm i guardian-risk-logger | Audit logging |

npm install guardian-risk guardian-risk-express guardian-risk-redis guardian-risk-vpn guardian-risk-logger
npm install ioredis   # optional, required for Redis in production

Production Express example

import express from 'express';
import { Guardian } from 'guardian-risk';
import { expressPlugin, guardianMiddleware } from 'guardian-risk-express';
import { redisPlugin } from 'guardian-risk-redis';
import { vpnPlugin, StaticIpProvider } from 'guardian-risk-vpn';
import { loggerPlugin } from 'guardian-risk-logger';

const app = express();
app.set('trust proxy', 1);

const template = new Guardian()
  .use(expressPlugin({ trustProxy: true }))
  .use(redisPlugin({ url: process.env.REDIS_URL, allowInMemoryFallback: false }))
  .use(vpnPlugin({ provider: new StaticIpProvider({}), vpnScore: 25 }))
  .use(loggerPlugin({ minScore: 20 }))
  .rule({ name: 'Burst', when: (s) => (s.requestsInWindow as number) > 30, score: 40 });

app.get('/health', (_req, res) => res.json({ ok: true }));

app.use(
  guardianMiddleware(template, {
    blockAboveScore: 80,
    onAnalyzeError: 'block',
    exposeBlockDetails: false,
  }),
);

Use your own IP intelligence provider in production (MaxMind, IPinfo, etc.) — not the dev-only IpApiProvider.

Plugins API

import type { Plugin } from 'guardian-risk';

const myPlugin: Plugin = {
  name: 'my-plugin',
  install(guardian) {
    guardian.beforeAnalyze(async ({ guardian: g }) => {
      g.signal('customSignal', true);
    });
  },
};

await new Guardian().use(myPlugin).analyzeAsync();

Typed signals & presets

import { defineSignals, applyRules, botDetectionRules } from 'guardian-risk';

const bot = defineSignals<{ mouseLinearity: number; headlessUA: boolean }>();

const guardian = applyRules(bot.create(), botDetectionRules)
  .signal('mouseLinearity', 0.95)
  .signal('headlessUA', true);

const report = await guardian.analyzeAsync();

Rule groups

guardian.ruleGroup({
  name: 'login',
  maxScore: 40,
  rules: [
    { name: 'BruteForce', when: (s) => (s.loginAttempts as number) > 5, score: 45 },
  ],
});

API

| Method | Description | |--------|-------------| | guardian.signal(key, value) | Add a signal | | guardian.getSignal(key) | Read a signal without modifying state | | guardian.rule({ name, when, score, reason? }) | Register a rule | | guardian.ruleGroup({ name, maxScore, rules }) | Register capped rule group | | guardian.use(plugin) | Install a plugin (once per name) | | guardian.beforeAnalyze(hook) | Run hook before evaluation (async OK) | | guardian.afterAnalyze(hook) | Run hook after report is built | | guardian.analyze() | Sync analysis (only when no hooks registered) | | guardian.analyzeAsync(context?) | Async analysis with lifecycle hooks | | guardian.fork() | Clone rules/plugins for per-request use | | guardian.reset() | Clear signals (rules + plugins persist) | | guardian.getInstalledPlugins() | List installed plugin names |

Production checklist

  1. One template Guardian at startup; fork() or middleware per request
  2. await analyzeAsync(req) when plugins are installed
  3. app.set('trust proxy', 1) behind load balancers
  4. REDIS_URL set; allowInMemoryFallback: false in production
  5. Your own VPN/IP provider — not default external APIs
  6. onAnalyzeError: 'block' and exposeBlockDetails: false when blocking
  7. Browser/client signals are hints only — never sole auth factor

Full details: SECURITY.md

Security

  • Zero runtime dependencies — minimal supply chain risk
  • No install scripts — nothing runs on npm install
  • String signals capped at 4 KB; NaN/Infinity rejected
  • Prototype pollution protection on signal keys
  • Rule when() errors isolated — engine stays stable
  • Hook timeout (10s); rules/plugins locked during analyzeAsync()
  • Deep-frozen matched rules in reports
  • Score bounds: ±10,000 per rule, ±1,000,000 total

See SECURITY.md for vulnerability reporting.

Links

License

MIT