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

@stackra/csp

v2.0.0

Published

Content-Security-Policy runtime for the Stackra framework — nonce generation, policy header building, feature-scoped source registry with discovery, and React bindings (NonceProvider, useNonce, Script, CspMeta).

Readme

@stackra/csp

Content-Security-Policy management for the Stackra framework — per-request nonce generation, a feature-scoped policy registry with @CspPolicy() auto-discovery, and React bindings (<NonceProvider>, useNonce, <Script>, <CspMeta>). Integrates with @stackra/ssr to stamp the CSP header + nonce onto server-rendered responses.

Subpaths

| Import | Contents | | -------------------- | ------------------------------------------------------------------------------------------------- | | @stackra/csp | Core: CspModule, CspService, NonceGenerator, CspPolicyLoader, CspRegistry, @CspPolicy | | @stackra/csp/react | Web: NonceProvider, NonceContext, useNonce, <Script>, <CspMeta> |

CSP tokens (CSP_SERVICE, CSP_CONFIG, CSP_REGISTRY) and the ICspService / ICspPolicyResult contracts live in @stackra/contracts — import them from there. This lets @stackra/ssr consume the CSP service without depending on this runtime.

Installation

// package.json
"@stackra/csp": "workspace:*"

Quick start

import { Module } from "@stackra/container";
import { CspModule } from "@stackra/csp";

@Module({
  imports: [
    CspModule.forRoot({
      scriptSrc: ["'self'", "'nonce'"],
      styleSrc: ["'self'", "'unsafe-inline'"],
      connectSrc: ["'self'"],
    }),
  ],
})
export class AppModule {}

Feature policies

Each package declares the origins it needs — no monolithic app config. Prefer the decorator (auto-discovered by CspPolicyLoader at bootstrap):

import { Injectable } from "@stackra/container";
import { CspPolicy } from "@stackra/csp";

@CspPolicy({
  name: "stripe",
  scriptSrc: ["https://js.stripe.com"],
  frameSrc: ["https://hooks.stripe.com"],
})
@Injectable()
export class StripeService {}

Or register dynamically:

CspModule.forFeature({
  name: "ga",
  scriptSrc: ["https://www.googletagmanager.com"],
});

forFeature seeds the registry through an inline @Injectable() registrar class implementing OnApplicationBootstrap (per ADR-0052) — no side-effect factories.

SSR integration

@stackra/ssr's renderer optionally injects CSP_SERVICE. When wired, it mints a fresh nonce per request, passes it to renderToReadableStream, and sets the Content-Security-Policy header. For the SPA shell it stamps the <script nonce> and embeds a <meta http-equiv> fallback.

To make useNonce() / <Script> resolve during the server render, wrap the tree in <NonceProvider> via the SSR wrapApp seam (the decoupled equivalent of Shopify Hydrogen's manual entry.server wrapping — SSR never imports CSP):

SsrModule.forRoot({
  // ...
  wrapApp: (app, { nonce }) =>
    createElement(NonceProvider, { nonce: nonce ?? "" }, app),
});

On the client, recover the nonce the server stamped onto the shell's <script nonce> and re-provide it (Hydrogen's entry.client pattern):

import { NonceProvider, readDocumentNonce } from "@stackra/csp/react";

const nonce = readDocumentNonce();
root.render(
  <NonceProvider nonce={nonce}>
    <App />
  </NonceProvider>,
);

React

import { NonceProvider, useNonce, CspMeta } from '@stackra/csp/react';

// SPA meta fallback (React 19 hoists to <head>)
<CspMeta />

// Distribute the nonce to the tree
<NonceProvider nonce={nonce}><App /></NonceProvider>;

// Consume it for an inline script
const nonce = useNonce();

NonceProvider lives in react/providers/, NonceContext in react/contexts/, useNonce in react/hooks/ — the standard layout.

License

MIT © Figentra L.L.C.