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

@vite-hub/rate-limit

v0.0.3

Published

Provider-neutral Rate Limit primitives and Vite deployment integration for ViteHub.

Readme

@vite-hub/rate-limit

@vite-hub/rate-limit provides atomic Rate Limit consumption without coupling policy to a storage provider.

Install

pnpm add @vite-hub/rate-limit

Require a Rate Limit

Declare the Rate Limit beside the server code that consumes it. The stable ID and policy must use static literals so the Vite integration can generate provider infrastructure.

import { requireRateLimit } from "@vite-hub/rate-limit"

export async function handleImageUpload(event): Promise<Response> {
  await requireRateLimit(event, "image-upload", {
    limit: 10,
    window: "1m",
  })
  return new Response("Upload accepted", { status: 202 })
}

requireRateLimit() can live inside any ordinary H3 handler. Its stable ID and provider policy must use static literals so the Vite integration can generate infrastructure; event and an optional dynamic key are runtime inputs. The guard defaults to the request's client address and throws an HTTPError with status 429 when the budget is exhausted. Pass key: authenticatedUser.id when a user or tenant is the correct budget boundary.

A framework may auto-import the canonical requireRateLimit name from this package instead. Discovery recognizes that bare call only when no local runtime binding owns the name.

Provider unavailability follows the declared failure policy: fail-open guards continue, while fail-closed guards throw status 503 and preserve the provider cause. Invalid configuration and provider contract violations still throw normally. Use createRateLimiter() when the application needs a decision for a custom response or another transport.

Add the build integration:

import { hubRateLimit } from "@vite-hub/rate-limit/vite"
import { defineConfig } from "vite"

export default defineConfig({
  plugins: [hubRateLimit({ namespace: "acme-image-service-production" })],
})

hubRateLimit() uses the memory driver during local Vite serve and infers Cloudflare from the production Nitro preset. Cloudflare deployments require a unique namespace for each Worker and environment so counters cannot leak across deployments. Unknown production hosts still require an explicit provider because process-local memory is unsafe for horizontally scaled deployments.

Native Cloudflare enforcement is best-effort and accepts only 10s and 1m windows, so incompatible policies fail during the build.

Custom drivers

Use createRateLimiter() when the application supplies a driver directly and does not need managed provider output:

import { createRateLimiter } from "@vite-hub/rate-limit"
import { memoryRateLimitDriver } from "@vite-hub/rate-limit/drivers/memory"

const limiter = createRateLimiter({
  driver: memoryRateLimitDriver(),
  enforcement: "strict",
  limit: 10,
  window: "1m",
})

const decision = await limiter.consume({ key: authenticatedUser.id })

The memory driver is process-local and intended for development, tests, and single-process hosts. Production drivers must implement atomic consume(); generic KV get() and set() operations are insufficient.

Custom drivers return [null, result] after consuming the counter and [error, undefined] only for expected operational outages that the declared failure policy should govern. Invalid configuration, malformed provider responses, and implementation defects should throw normally.

Every direct limiter exposes its enforcement, counter scope, rejected-attempt behavior, and supported windows. The Vite integration writes those capabilities to .vitehub/rate-limit/manifest.json for agents and tooling to inspect.