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

@arraypress/captcha

v2.0.0

Published

Unified CAPTCHA verification — Turnstile, reCAPTCHA, and hCaptcha. Provider selection via settings, optional decryption hook for secrets at rest, fail-open when 'none' is configured, fail-closed on misconfiguration. Zero dependencies.

Readme

@arraypress/captcha

Unified CAPTCHA verification across Cloudflare Turnstile, Google reCAPTCHA v2/v3, and hCaptcha. Settings-driven provider selection, optional decryption hook for secrets at rest, fail-open on 'none' / fail-closed on misconfiguration. Zero dependencies.

v2.0.0 (breaking): @arraypress/turnstile and @arraypress/recaptcha are no longer separate peer packages — the verifier code lives inside this package as internal providers. hCaptcha support added. Drop the turnstile + recaptcha dep lines from your package.json when upgrading; importers continue to work via the verifyTurnstile / verifyRecaptcha re-exports on this package.

Install

npm install @arraypress/captcha

Usage

import { createCaptcha } from '@arraypress/captcha';

const captcha = createCaptcha({
  getSettings: () => getAllSettings(db),
  decrypt:     (stored) => decryptSetting(stored, tokenSecret), // optional
});

// On a protected form endpoint:
app.post('/api/magic-link', async (c) => {
  const body = await c.req.json();
  const ok = await captcha.verify(captcha.extractToken(body), {
    ip: getClientIP(c),
  });
  if (!ok) return c.json({ error: 'Invalid CAPTCHA' }, 400);
  // ...
});

// On the public endpoint the frontend reads to mount its widget:
app.get('/api/public/captcha-config', async (c) => {
  return c.json(await captcha.getPublicConfig());
});

Settings keys read

| Key | Purpose | |---|---| | captcha_provider | 'none' / 'turnstile' / 'recaptcha' / 'hcaptcha' | | turnstile_site_key, turnstile_secret_key | When provider = turnstile | | recaptcha_site_key, recaptcha_secret_key | When provider = recaptcha | | hcaptcha_site_key, hcaptcha_secret_key | When provider = hcaptcha |

Secret keys may be plaintext OR ciphertext — the decrypt hook is applied on every read. Site keys are never sensitive and are never passed through decrypt.

Semantics

| State | verify() | getPublicConfig() | |---|---|---| | captcha_provider = 'none' | true (fail-open — opt-in) | null | | Provider configured, secret blank | false (fail-closed — misconfig) | null if siteKey also blank | | Provider configured, token missing | false | { provider, siteKey } | | Provider rejects the token | false | — | | Provider accepts the token | true | — |

Fail-open on 'none' is intentional: fresh deployments don't require a CAPTCHA. Fail-closed on missing-secret is also intentional: the admin thinks they're protected, so a silent accept is worse than a hard reject.

Token extraction

extractCaptchaToken(body) reads from the first field present, in order:

  1. cf-turnstile-response (Turnstile widget native)
  2. g-recaptcha-response (reCAPTCHA widget native)
  3. h-captcha-response (hCaptcha widget native)
  4. turnstileToken / recaptchaToken / hcaptchaToken / captchaToken (common JSON aliases)

Direct provider verification

If you don't want the settings-driven gateway — for example you only ever use one provider and keep the secret in an env var — the per-provider verify functions are also exported:

import { verifyTurnstile, verifyRecaptcha, verifyHcaptcha } from '@arraypress/captcha';

const ok = await verifyTurnstile(token, env.TURNSTILE_SECRET, { remoteip });

// reCAPTCHA v3 with score threshold:
const ok3 = await verifyRecaptcha(token, env.RECAPTCHA_SECRET, {
  scoreThreshold: 0.7,
  expectedAction: 'checkout',
});

Each provider also has a verify<Provider>Detailed variant that returns the raw siteverify response (useful for logging error codes, score values, etc.).

License

MIT