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

@khanh2k7/shield-cloud-node

v0.1.0

Published

Server-side SDK for Shield Cloud — verify shield-token with site secret_key (Node, Edge, Express, Next.js).

Readme

@khanh2k7/shield-cloud-node

Server-side SDK for Shield Cloud bot protection.

Verifies the browser shield-token (set after JS challenge / PoW) using your site secret key against POST /v1/verify.

The platform HMAC secret never leaves your Shield deployment. This package is a thin, typed API client + middleware helpers.

Install

npm install @khanh2k7/shield-cloud-node
# or
pnpm add @khanh2k7/shield-cloud-node
yarn add @khanh2k7/shield-cloud-node

Requirements: Node.js 18+ (native fetch).

Quick start

import { ShieldClient } from "@khanh2k7/shield-cloud-node";

const shield = new ShieldClient({
  secretKey: process.env.SHIELD_SECRET_KEY!, // sk_live_...
  apiBase: process.env.SHIELD_API_BASE!,     // https://your-shield-app.vercel.app
});

// From cookie / header
const result = await shield.verifyNodeRequest(req);

if (!result.ok) {
  // 401/403 — run JS challenge on the client
  return res.status(result.status).json({ error: result.error });
}

console.log(result.site, result.token.sid, result.token.score);

Environment variables (optional if you pass options explicitly):

| Env | Description | |-----|-------------| | SHIELD_SECRET_KEY | Site secret (sk_live_...) | | SHIELD_API_BASE | Shield API origin (or custom https://token.customer.com) |

Express

import express from "express";
import { shieldMiddleware } from "@khanh2k7/shield-cloud-node";

const app = express();

app.use(
  shieldMiddleware({
    secretKey: process.env.SHIELD_SECRET_KEY!,
    apiBase: process.env.SHIELD_API_BASE!,
  })
);

app.get("/api/me", (req, res) => {
  res.json({ visitor: req.shield });
});

On failure the middleware responds:

{ "ok": false, "code": 1124, "error": "...", "msg": "JS challenge required" }

with header x-shield-action: challenge.

Next.js App Router

// app/api/private/route.ts
import { assertShield, ShieldAuthError } from "@khanh2k7/shield-cloud-node";

export async function GET(req: Request) {
  try {
    const visitor = await assertShield(req, {
      secretKey: process.env.SHIELD_SECRET_KEY!,
      apiBase: process.env.SHIELD_API_BASE!,
    });
    return Response.json({ site: visitor.site, sid: visitor.token.sid });
  } catch (e) {
    if (e instanceof ShieldAuthError) return e.toResponse();
    throw e;
  }
}

Or non-throwing:

import { checkShield } from "@khanh2k7/shield-cloud-node";

const result = await checkShield(req, { secretKey, apiBase });
if (!result.ok) return Response.json(result, { status: result.status });

Cloudflare Worker / Edge

import { extractFromRequest, verifyShieldToken } from "@khanh2k7/shield-cloud-node";

export default {
  async fetch(request, env) {
    const token = extractFromRequest(request);
    const result = await verifyShieldToken({
      secretKey: env.SHIELD_SECRET_KEY,
      apiBase: env.SHIELD_API_BASE,
      token: token || "",
    });
    if (!result.ok) {
      return new Response("challenge", {
        status: 403,
        headers: { "x-shield-action": "challenge" },
      });
    }
    return fetch(env.ORIGIN); // proxy
  },
};

API

new ShieldClient(options)

| Option | Type | Description | |--------|------|-------------| | secretKey | string | Site secret (or SHIELD_SECRET_KEY) | | apiBase | string | API base URL (or SHIELD_API_BASE) | | fetch | typeof fetch | Custom fetch | | timeoutMs | number | Default 10000 |

client.verify({ token, deviceId? })

Returns VerifyResult:

// success
{
  ok: true,
  valid: true,
  site: "example.com",
  site_id: "...",
  site_key: "pk_live_...",
  tenant: "Acme",
  tenant_id: "...",
  plan: "pro",
  token: { sid, device_id, score, exp, iat }
}

// failure
{ ok: false, error: "expired" | "missing_token" | ..., status: 401 }

Helpers

  • extractShieldToken({ cookieHeader, shieldTokenHeader })
  • extractFromRequest(req) — Fetch Request
  • extractFromNodeRequest(req) — Express / Node
  • verifyShieldToken({ token, secretKey, apiBase }) — one-shot
  • shieldMiddleware(opts) — Express
  • assertShield(req, opts) / checkShield(req, opts) — Next / Edge
  • ShieldAuthError — has .toResponse()

Constants

  • SHIELD_TOKEN_COOKIE"shield-token"
  • SHIELD_TOKEN_HEADER"x-shield-token"

Browser side

Keep using the embed script (not this package):

<script src="https://YOUR_SHIELD/v1/challenge.js"
        data-site-key="pk_live_..."
        data-api="https://YOUR_SHIELD"
        data-mode="auto"></script>

Development (monorepo)

cd packages/node
npm install
npm test
npm run build

Publish

# Once: create org https://www.npmjs.com/org/create → shield-cloud
cd packages/node
npm login
npm publish --access public

License

MIT