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

@moderyo/sdk

v2.0.7

Published

Official TypeScript/Node.js SDK for Moderyo Content Moderation API

Readme

Moderyo TypeScript/Node.js SDK

Official TypeScript/Node.js client library for the Moderyo Content Moderation API.

npm version TypeScript License: MIT

Installation

npm install @moderyo/sdk
# or
yarn add @moderyo/sdk
# or
pnpm add @moderyo/sdk

Quick Start

import { Moderyo } from '@moderyo/sdk';

const client = new Moderyo({
  apiKey: process.env.MODERYO_API_KEY!,
});

// Moderate content
const result = await client.moderate({
  content: 'Hello, this is a test message',
});

console.log(result.flagged);  // true/false
console.log(result.action);   // 'allow' | 'flag' | 'block'

Features

  • ✅ Full TypeScript support with detailed type definitions
  • ✅ Promise-based async API
  • ✅ Automatic retry with exponential backoff
  • ✅ Rate limiting handling
  • ✅ Batch processing support
  • ✅ Framework integrations (Express, Fastify, etc.)

Configuration

const client = new Moderyo({
  apiKey: process.env.MODERYO_API_KEY!,
  
  // Optional configuration
  baseUrl: 'https://api.moderyo.com',
  timeout: 30000,      // 30 seconds
  maxRetries: 3,
  retryDelay: 1000,    // Base delay for exponential backoff
  
  // Callbacks
  onError: (error) => console.error('Moderyo error:', error),
  onRateLimit: (info) => console.warn('Rate limited:', info),
});

Error Handling

import { 
  Moderyo, 
  ModeryoError,
  AuthenticationError,
  RateLimitError,
  ValidationError,
  APIError 
} from '@moderyo/sdk';

try {
  const result = await client.moderate({ content: text });
} catch (error) {
  if (error instanceof AuthenticationError) {
    console.error('Invalid API key');
  } else if (error instanceof RateLimitError) {
    console.log(`Rate limited. Retry after ${error.retryAfter}ms`);
    await sleep(error.retryAfter);
    // Retry...
  } else if (error instanceof ValidationError) {
    console.error('Invalid request:', error.message);
  } else if (error instanceof APIError) {
    console.error(`API error ${error.statusCode}: ${error.message}`);
  }
}

Batch Processing

const results = await client.moderateBatch([
  { content: 'Message 1' },
  { content: 'Message 2' },
  { content: 'Message 3' },
]);

console.log(`Total: ${results.total}`);
console.log(`Flagged: ${results.flaggedCount}`);
console.log(`Blocked: ${results.blockedCount}`);

for (const result of results.results) {
  console.log(`${result.id}: ${result.action}`);
}

Context & Metadata

const result = await client.moderate({
  content: 'User message here',
  context: {
    userId: 'user_123',
    contentType: 'chat',
    platform: 'mobile',
    language: 'en',
  },
});

Framework Integrations

Express.js Middleware

import express from 'express';
import { createModeryoMiddleware } from '@moderyo/sdk/express';

const app = express();

const moderyo = createModeryoMiddleware({
  apiKey: process.env.MODERYO_API_KEY!,
});

app.post('/api/messages', 
  moderyo.moderate({ field: 'body.content' }),
  (req, res) => {
    if (req.moderation?.action === 'block') {
      return res.status(400).json({ 
        error: 'Content blocked',
        reason: req.moderation.explanation 
      });
    }
    
    // Process the message...
    res.json({ status: 'ok' });
  }
);

Fastify Plugin

import Fastify from 'fastify';
import { moderyoPlugin } from '@moderyo/sdk/fastify';

const fastify = Fastify();

fastify.register(moderyoPlugin, {
  apiKey: process.env.MODERYO_API_KEY!,
});

fastify.post('/api/messages', async (request, reply) => {
  const result = await request.moderyo.moderate({
    content: request.body.content,
  });
  
  if (result.action === 'block') {
    return reply.status(400).send({ error: 'Content blocked' });
  }
  
  return { status: 'ok' };
});

TypeScript Types

import type {
  ModerationResult,
  ModerationRequest,
  Categories,
  CategoryScores,
  Decision,
  ModeryoConfig,
} from '@moderyo/sdk';

// Full type safety
const request: ModerationRequest = {
  content: 'User message',
  context: {
    userId: 'user_123',
  },
};

const result: ModerationResult = await client.moderate(request);

// Access typed properties
const action: Decision = result.action;  // 'allow' | 'flag' | 'block'
const categories: Categories = result.categories;
const scores: CategoryScores = result.scores;

Development

# Clone repository
git clone https://github.com/moderyo/moderyo-js.git
cd moderyo-js

# Install dependencies
npm install

# Build
npm run build

# Run tests
npm test

# Lint
npm run lint

# Type check
npm run typecheck

License

MIT License - see LICENSE for details.