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

@smallpict/sdk

v0.0.2

Published

Official TypeScript & Node.js SDK for SmallPict Image Optimization API

Readme

SmallPict Node.js & TypeScript SDK

Official TypeScript and Node.js SDK for the SmallPict Image Optimization API — high-performance next-gen image transcoding (AVIF, WebP), smart compression, Edge CDN delivery, and cache purging.

npm version License: MIT


⚡ Features

  • 🚀 Universal Runtime Support: Compatible with Node.js 18+, Bun, Next.js (App & Pages Router), and Cloudflare Workers with zero external HTTP dependencies (native Web Fetch & Web Crypto).
  • 🛡️ HMAC-SHA256 & Bearer Auth: Secure request signing and tamper protection.
  • ✨ 4 Core Unified Methods: optimize(), getQuota(), purgeCdn(), and validateKey().
  • 🔄 Resilience & Fault Tolerance: Automatic Idempotency-Key injection, 30s request timeouts, and exponential backoff with jitter on HTTP 429/5xx.
  • 🔒 Zero-Leak Privacy: API keys and credentials are automatically redacted from error traces and logs.
  • 📦 Dual ESM & CJS: Full TypeScript definitions and source maps included.

📥 Installation

# npm
npm install @smallpict/sdk

# pnpm
pnpm add @smallpict/sdk

# yarn
yarn add @smallpict/sdk

# bun
bun add @smallpict/sdk

🚀 Quick Start

1. Minimal Example

import { SmallPictClient } from '@smallpict/sdk';
import { readFileSync } from 'node:fs';

const client = new SmallPictClient({
  apiKey: process.env.SMALLPICT_API_KEY!, // or 'sp_sdk_...' / 'sp_test_...'
  secretKey: process.env.SMALLPICT_SECRET_KEY, // Optional HMAC secret key
});

const imageBuffer = readFileSync('./hero-banner.png');

const result = await client.optimize(imageBuffer, {
  format: 'avif',
  quality: 80,
  maxWidth: 1920,
});

console.log(`Optimized CDN URL: ${result.url}`);
console.log(`Original: ${result.originalSize} bytes ➔ Compressed: ${result.compressedSize} bytes`);
console.log(`Saved: ${result.savingsPercentage}% (${result.bytesSaved} bytes)`);

🏭 Production Examples

Next.js Server Action / Route Handler with Fallback Mode

import { SmallPictClient, QuotaExceededError } from '@smallpict/sdk';
import { NextResponse } from 'next/server';

const client = new SmallPictClient({
  apiKey: process.env.SMALLPICT_API_KEY!,
  secretKey: process.env.SMALLPICT_SECRET_KEY,
  // If quota is exhausted, passthrough original image without throwing
  fallbackMode: 'passthrough',
});

export async function POST(req: Request) {
  try {
    const formData = await req.formData();
    const file = formData.get('file') as File;

    if (!file) {
      return NextResponse.json({ error: 'No file uploaded' }, { status: 400 });
    }

    const arrayBuffer = await file.arrayBuffer();
    const result = await client.optimize(arrayBuffer, {
      filename: file.name,
      mimeType: file.type,
      format: 'auto', // Intelligently selects best format (AVIF/WebP)
      quality: 85,
    });

    return NextResponse.json({
      url: result.url,
      format: result.format,
      saved: `${result.savingsPercentage}%`,
    });
  } catch (error) {
    if (error instanceof QuotaExceededError) {
      return NextResponse.json({ error: 'Monthly quota exhausted' }, { status: 402 });
    }
    return NextResponse.json({ error: 'Image optimization failed' }, { status: 500 });
  }
}

Checking Account Quota & Purging CDN Cache

import { SmallPictClient } from '@smallpict/sdk';

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

// 1. Check real-time quota usage
const quota = await client.getQuota();
console.log(`Plan: ${quota.plan}`);
console.log(`Quota Used: ${quota.quotaPercentage}% (${quota.bytesUsed} / ${quota.quotaLimit} bytes)`);

// 2. Invalidate CDN cache for modified images
await client.purgeCdn([
  'https://cdn.smallpict.app/opt/hero-banner.avif',
  'https://cdn.smallpict.app/opt/logo.webp',
]);
console.log('CDN cache purged successfully!');

🧪 Testing

npm run test
npm run typecheck
npm run build

📄 License

MIT © SmallPict Engineering