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

@commonpub/infra

v0.5.0

Published

Storage adapters, image processing, email, and security utilities for CommonPub

Readme

@commonpub/infra

Framework-agnostic infrastructure utilities for CommonPub. Storage adapters, image processing, email, and security headers/rate limiting. No domain knowledge, no database dependency.

Installation

pnpm add @commonpub/infra

Modules

Storage (./storage)

File upload storage with two adapter implementations:

  • LocalStorageAdapter -- writes files to disk (./uploads/). For development.
  • S3StorageAdapter -- S3-compatible storage (AWS S3, DigitalOcean Spaces, MinIO, Cloudflare R2). For production.
  • createStorageFromEnv() -- auto-selects adapter from environment variables.
import { createStorageFromEnv, validateUpload, generateStorageKey } from '@commonpub/infra';

const storage = createStorageFromEnv();
const key = generateStorageKey('photo.jpg', 'content');
const url = await storage.upload(key, buffer, 'image/jpeg');

Upload validation with MIME type whitelist and per-purpose size limits (avatar 2MB, banner 5MB, content 10MB, attachment 100MB).

Image Processing (./image)

Automatic image resizing and WebP conversion using sharp:

  • Generates 4 variants: thumb (150px), small (300px), medium (600px), large (1200px)
  • Converts all variants to WebP at quality 80
  • Skips variants larger than the original image
  • getBestVariant() selects the smallest variant that fits a given display width
import { processImage, getBestVariant } from '@commonpub/infra';

const processed = await processImage(buffer, 'photo.jpg', 'content', storage);
const url = getBestVariant(processed, 600); // best variant for 600px display

Email (./email)

Email sending with adapter pattern:

  • SmtpEmailAdapter -- SMTP transport via nodemailer (optional dependency).
  • ConsoleEmailAdapter -- logs emails to console. For development.
  • emailTemplates -- pre-built templates: verification, password reset, notification digest, contest announcement, certificate issued.
import { ConsoleEmailAdapter, emailTemplates } from '@commonpub/infra';

const email = new ConsoleEmailAdapter();
const msg = emailTemplates.verification('MySite', 'https://example.com/verify?token=abc');
await email.send({ ...msg, to: '[email protected]' });

Security (./security)

HTTP security headers and rate limiting:

  • CSP -- buildCspDirectives(nonce?) and buildCspHeader() for Content-Security-Policy with optional nonce-based script/style sources.
  • Security headers -- getSecurityHeaders(isDev) returns X-Content-Type-Options, X-Frame-Options, Referrer-Policy, Permissions-Policy, and HSTS (production only).
  • Rate limiting -- RateLimitStore with in-memory sliding window, 5 default tiers (auth: 5/min, social: 30/min, federation: 60/min, api: 60/min, general: 120/min), and checkRateLimit() for framework-agnostic checking with response headers.
import { RateLimitStore, checkRateLimit, getSecurityHeaders } from '@commonpub/infra';

const store = new RateLimitStore();
const { result, headers } = checkRateLimit(store, clientIp, pathname);

Environment Variables (Storage)

| Variable | Description | Default | |----------|-------------|---------| | S3_BUCKET | Bucket name (enables S3 mode) | -- | | S3_REGION | Region | us-east-1 | | S3_ENDPOINT | Custom endpoint (DO Spaces, MinIO) | -- | | S3_ACCESS_KEY | Access key ID | -- | | S3_SECRET_KEY | Secret access key | -- | | S3_PUBLIC_URL | Public URL prefix (auto-derived if unset) | -- | | S3_FORCE_PATH_STYLE | Set true for MinIO | auto | | UPLOAD_DIR | Local upload directory | ./uploads | | SITE_URL | Base URL for local uploads | http://localhost:3000 |

Dependencies

  • sharp -- image resizing and WebP conversion
  • @aws-sdk/client-s3 -- S3-compatible object storage
  • nodemailer -- optional, required only for SmtpEmailAdapter

Development

pnpm build        # Compile TypeScript
pnpm typecheck    # Type-check without emitting