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

@affirmfirst/react

v1.0.0

Published

React components for aFFirmFirst secure image delivery. Drop-in replacement for <img> tags with encrypted canvas rendering, watermarking, and right-click protection.

Readme

@affirmfirst/react

React components for aFFirmFirst secure image delivery. Drop-in replacement for <img> tags with encrypted canvas rendering, watermarking, and right-click protection.

Installation

npm install @affirmfirst/react

Quick Start

1. Wrap your app with <AffirmProvider>

// app/layout.tsx (Next.js) or App.tsx (React)
import { AffirmProvider } from '@affirmfirst/react';

export default function Layout({ children }) {
  return (
    <AffirmProvider>
      {children}
    </AffirmProvider>
  );
}

2. Use <SecureImage> anywhere

import { SecureImage } from '@affirmfirst/react';

export function ProductImage({ imageId }) {
  return (
    <SecureImage
      imageId={imageId}
      width={600}
      height={400}
      alt="Product photo"
    />
  );
}

That's it. The image is rendered via encrypted canvas — no <img> tag, no downloadable URL.

Components

<AffirmProvider>

Auto-loads the aFFirmFirst SDK script. Place in your root layout. No configuration needed.

| Prop | Type | Default | Description | |------|------|---------|-------------| | autoLoad | boolean | true | Auto-inject the SDK <script> tag |

<SecureImage>

Renders a single protected image.

| Prop | Type | Default | Description | |------|------|---------|-------------| | imageId | string | required | aFFirmFirst vault image ID | | width | string \| number | '100%' | Container width | | height | string \| number | 'auto' | Container height | | lazy | boolean | true | Lazy load via IntersectionObserver | | className | string | — | CSS class for wrapper | | style | CSSProperties | — | Inline styles for wrapper | | alt | string | — | Accessibility label | | onLoad | () => void | — | Called when image loads | | onError | (error: string) => void | — | Called on load error |

<SecureGallery>

Renders a grid or masonry layout of protected images.

| Prop | Type | Default | Description | |------|------|---------|-------------| | imageIds | string[] | required | Array of vault image IDs | | layout | 'grid' \| 'masonry' | 'grid' | Layout mode | | columns | number | 3 | Number of columns | | gap | number | 8 | Gap between images (px) | | imageHeight | string | '250px' | Image height (grid mode) | | className | string | — | CSS class | | style | CSSProperties | — | Inline styles |

Hooks

useAffirmFirst()

Access the SDK instance for programmatic control.

import { useAffirmFirst } from '@affirmfirst/react';

function MyComponent() {
  const { ready, sdk } = useAffirmFirst();

  const handleEmbed = () => {
    if (ready && sdk) {
      sdk.embed({
        imageId: 'clx123abc',
        container: document.getElementById('my-container'),
        width: '100%',
        height: 'auto',
      });
    }
  };

  return <div id="my-container" />;
}

Next.js Utilities

Import from @affirmfirst/react/next:

affirmImageLoader

Custom image loader for next/image. Uses thumbnail URLs for standard <Image> rendering (previews, admin panels). For maximum protection, use <SecureImage> instead.

// lib/affirm-loader.js
import { affirmImageLoader } from '@affirmfirst/react/next';
export default affirmImageLoader;
// next.config.js
module.exports = {
  images: {
    loader: 'custom',
    loaderFile: './lib/affirm-loader.js',
  },
};

SDK_SCRIPT_URL

Pre-configured SDK script URL. Use with Next.js <Script> if you prefer manual loading over <AffirmProvider>.

import Script from 'next/script';
import { SDK_SCRIPT_URL } from '@affirmfirst/react/next';

<Script src={SDK_SCRIPT_URL} strategy="afterInteractive" />

Usage Examples

Next.js Ecommerce — Product Page

import { SecureImage } from '@affirmfirst/react';

export default function ProductPage({ product }) {
  return (
    <div className="grid grid-cols-2 gap-8">
      <SecureImage
        imageId={product.affirmImageId}
        width="100%"
        height={500}
        alt={product.name}
      />
      <div>
        <h1>{product.name}</h1>
        <p>${product.price}</p>
      </div>
    </div>
  );
}

// SEO: Use signed URL for og:image (crawlers can't run JS)
export async function generateMetadata({ params }) {
  const product = await getProduct(params.id);
  return {
    openGraph: {
      images: [product.signedImageUrl],
    },
  };
}

Product Gallery

import { SecureGallery } from '@affirmfirst/react';

export default function ProductGallery({ imageIds }) {
  return (
    <SecureGallery
      imageIds={imageIds}
      layout="grid"
      columns={4}
      gap={4}
      imageHeight="200px"
    />
  );
}

Portfolio Masonry

import { SecureGallery } from '@affirmfirst/react';

export default function Portfolio({ imageIds }) {
  return (
    <SecureGallery
      imageIds={imageIds}
      layout="masonry"
      columns={3}
      gap={8}
    />
  );
}

How It Works

  1. <AffirmProvider> loads the SDK script (/sdk/affirm.js) into the page
  2. <SecureImage> creates a container div and calls AffirmFirst.embed()
  3. The SDK fetches the image via encrypted streaming (/stream/secure/:imageId)
  4. A Web Worker decrypts the AES-256-CBC encrypted bytes in memory
  5. The decrypted image is painted onto a <canvas> element — no <img> tag exists
  6. Watermark overlay, right-click blocking, and screen capture detection are applied

Security features active on every image:

  • AES-256-CBC encryption in transit
  • Canvas rendering (no downloadable URL)
  • Imperceptible pixel noise (anti-scraping)
  • Right-click and drag protection
  • Watermark overlay
  • Screen capture detection
  • Domain locking (referer validation)

License

MIT