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

@agewallet/js-sdk

v1.0.5

Published

The official, zero-dependency JavaScript SDK for integrating AgeWallet Age Verification into modern web applications.

Readme

AgeWallet JavaScript SDK

The official, zero-dependency JavaScript SDK for integrating AgeWallet Age Verification into modern web applications.

Designed for versatility, it supports everything from static landing pages to Single Page Applications (React, Vue, Angular) and Server-Side Node.js environments.

Features

  • Universal Support: Works in all modern browsers and Node.js 19+ (Server-Side Rendering).

  • Secure by Default: Automatically handles OIDC Authorization Code Flow with PKCE (S256) and State verification.

  • Flexible Modes:

    • Overlay Mode: Drop-in age gate for marketing sites.

    • Headless Mode: Full control for SPAs and custom UIs.

    • API Mode: Secure content fetching for premium video/assets.

    • Zero Dependencies: Lightweight and fast.

Installation

Option 1: NPM (Recommended for Bundlers)

npm install @agewallet/js-sdk


import { AgeWallet } from '@agewallet/js-sdk';

Option 2: CDN (Browser Script)

<script src="https://unpkg.com/@agewallet/js-sdk@latest/dist/agewallet.min.js"></script>
<script>
  // Access via global window.AgeWallet
  const aw = new AgeWallet({ ... });
</script>

Quick Start: Standard Overlay

The fastest way to protect a landing page. This renders a fixed-position age gate over your content until the user verifies.

import { AgeWallet } from '@agewallet/js-sdk';

const aw = new AgeWallet({
    clientId: 'YOUR_CLIENT_ID',
    clientSecret: 'YOUR_CLIENT_SECRET', // Only required for Confidential Clients
    mode: 'overlay',
    redirectUri: window.location.origin + '/' // Single callback URL (see note below)
});

aw.init();

⚠️ Important: Single Redirect URI

AgeWallet requires one redirect URI per Client ID. All pages on your site must use the same redirectUri value (typically your homepage or a dedicated /callback route).

The SDK automatically handles deep linking — if a user lands on /shop/product-123 and needs to verify, they will be returned to /shop/product-123 after verification, even though the OAuth callback goes through your single redirect URI.

Configuration

| Option | Type | Default | Description | | :--- | :--- | :--- | :--- | | clientId | string | Required | Your AgeWallet Application ID. | | clientSecret | string | '' | Required for Confidential Clients. Leave empty for Public Clients (SPA). | | redirectUri | string | window.location | The single OAuth callback URL (e.g., window.location.origin + '/'). Must be whitelisted in Dashboard. One per Client ID. | | mode | string | 'overlay' | 'overlay' (Default) or 'api' (Secure Fetch). | | render | boolean | true | Set to false for Headless Mode (no UI injected). | | storage | string | object | 'cookie' | 'cookie', 'local', or a custom object implementing SessionHandlerInterface. | | targetSelector | string | 'body' | CSS selector for the container where the Gate UI will be rendered. | | api | object | {} | Required for api mode. Must contain an endpoint URL. | | environment | string | 'browser' | 'browser' (Default) or 'node' (Server-Side). | | ui | object | {} | Customize text and logo (see below). | | onVerified | function | null | Callback fired when verification succeeds. Receives content (API mode) or null (Overlay mode). | | onUnverified | function | null | Callback fired when verification is required. Receives the authUrl string. |

Advanced Usage

Headless Mode (React / Vue)

For full control over the UI, disable the built-in renderer and use event handlers.

const aw = new AgeWallet({
    clientId: 'YOUR_ID',
    render: false, // Disable SDK UI
    redirectUri: 'https://mysite.com/callback',

    // Called when user needs to verify
    onUnverified: (authUrl) => {
        // Show your own "Verify Age" button linking to authUrl
        setVerifyLink(authUrl);
        setShowGate(true);
    },

    // Called when verification is successful
    onVerified: (content) => {
        // Content is null in overlay mode, or data in API mode
        setShowGate(false);
        setVerified(true);
    }
});

aw.init();

Local Storage (SPA Friendly)

By default, the SDK uses document.cookie for compatibility. For Single Page Apps where you prefer localStorage:

const aw = new AgeWallet({
    // ... credentials ...
    storage: 'local' // Tokens stored in localStorage (Key: aw_verified)
});

Custom Branding

You can customize the look and feel of the built-in age gate by passing a ui object.

const aw = new AgeWallet({
    // ... credentials ...
    ui: {
        title: "Restricted Access",
        description: "Please verify your age to enter the VIP lounge.",
        buttonText: "I am 18+",
        logo: "https://example.com/my-logo.png", // Optional
    }
});

CSS Overrides: The SDK uses BEM-style classes. You can override them in your own CSS:

/* Change the "Agree" button color */
.aw-gate__btn--yes {
    background-color: #ff0055 !important;
}

Server-Side Verification (Node.js)

The SDK works natively in Node.js (v19+) for server-side rendering (SSR) or API protection.

Configuration: Set environment: 'node' to enable server-compatible cryptography.

import { AgeWallet } from '@agewallet/js-sdk';

// 1. Initialize
// You must provide a custom storage handler for the server (e.g., Redis, DB)
const myStorage = {
    get: async (key) => { /* return value from DB */ },
    set: async (key, val) => { /* save value to DB */ },
    remove: async (key) => { /* delete from DB */ }
};

const aw = new AgeWallet({
    clientId: 'YOUR_ID',
    clientSecret: 'YOUR_SECRET',
    redirectUri: 'https://mysite.com/callback',
    environment: 'node', // <--- Crucial for Node.js support
    mode: 'api',
    storage: myStorage
});

// 2. Generate Auth URL (for unverified users)
const authData = await aw.generateAuthUrl();
// Redirect user to: authData.url

// 3. Handle Callback
// Call this when the user returns to your callback URL.
// It might contain ?code=... (Verification) OR ?error=... (Failure)

if (req.query.code) {
    // Handle Standard Verification
    await aw.handleCallback(req.query.code, req.query.state);
}

// 4. Check Status
const token = await aw.storage.getVerificationToken();

if (token) {
   // User is verified
}

Examples & Recipes

This repository includes complete multi-page example sites in the examples/ directory, demonstrating real-world integration patterns with deep link support.

Frontend Examples

Each example is a 3-page mini-site (Home, About, Shop) demonstrating how verification persists across pages and deep links.

  • Overlay Mode: The standard full-screen gate integration with deep link preservation.
  • API Mode: Securely fetching content from a backend only after verification.
  • Headless Mode: Building a completely custom UI (React/Vue style) without the SDK's default styling.
  • Local Storage: Persisting tokens in localStorage for Single Page Apps.
  • Custom Branding: Customizing the default gate's logo, text, and colors via CSS variable overrides.

Backend Examples

  • SSR + Redis: A fully server-rendered Node.js example using Upstash Redis for session management. Demonstrates deep link restoration entirely on the server.
  • Netlify Functions: Serverless token proxy functions for secure client secret handling.