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

@pidchashyi/next-cookies

v2.2.0

Published

A utility to get type-safe cookies from Next.js

Readme

@pidchashyi/next-cookies

🍪 Type-safe, configurable cookie management for Next.js server components — with GDPR compliance, backup/recovery, and expiration management.

A comprehensive cookie management solution featuring:

  • Type-safe cookie operations
  • GDPR compliance and consent management
  • Automatic cookie backup and recovery
  • Expiration tracking and management
  • Full Next.js app router compatibility

📦 Installation

npm install @pidchashyi/next-cookies
# or
yarn add @pidchashyi/next-cookies
# or
pnpm install @pidchashyi/next-cookies
# or
bun install @pidchashyi/next-cookies

🚀 Features

Core Features

  • Type-safe cookie operations
  • Automatic value validation
  • Comprehensive error handling
  • Debug logging in development

GDPR Compliance

  • Cookie categorization (Essential, Marketing, etc.)
  • Consent management
  • Automatic policy enforcement
  • Cookie policy generation

Backup & Recovery

  • Automatic backup of critical cookies
  • Corruption detection
  • Multiple backup versions
  • Easy recovery process

Expiration Management

  • Automatic cleanup of expired cookies
  • Expiration monitoring
  • Extension of cookie lifetimes
  • Early expiration warnings

🔧 Usage Examples

Basic Setup with All Features

const cookieClient = createCookieClient(
  {
    // Basic cookie configuration
    theme: ["light", "dark"] as const,
    sessionId: undefined,

    // GDPR configuration
    gdpr: {
      theme: {
        category: CookieCategory.Preferences,
        description: "Stores user's theme preference",
        duration: "1 year",
        provider: "First party",
      },
      sessionId: {
        category: CookieCategory.Essential,
        description: "Maintains user session",
        duration: "Session",
        provider: "First party",
      },
    },

    // Backup configuration
    backup: {
      sessionId: {
        critical: true,
        backupCount: 5,
        validateChecksum: true,
      },
    },
  },
  {
    // Optional global settings
    autoCleanupInterval: 60 * 60 * 1000, // 1 hour
    expiringSoonThreshold: 24 * 60 * 60 * 1000, // 24 hours
    gdpr: {
      defaultConsent: {
        functional: true,
        preferences: true,
      },
    },
    backup: {
      prefix: "__bak_",
      defaultBackupCount: 3,
    },
  }
);

GDPR Compliance

// Get current consent status
const consent = await cookieClient.getConsent();

// Update consent preferences
await cookieClient.updateConsent({
  analytics: true,
  marketing: false,
});

// Get cookie policy information
const policy = cookieClient.getCookiePolicy();
console.log(policy[CookieCategory.Marketing].cookies);

Cookie Backup & Recovery

// Backups are created automatically for critical cookies
await cookieClient.set("sessionId", "abc123");

// Recover a corrupted cookie
const recovery = await cookieClient.recoverCookie("sessionId");
if (recovery.success) {
  console.log("Recovered value:", recovery.value);
}

Expiration Management

// Get soon-to-expire cookies
const expiringSoon = await cookieClient.getExpiringSoonCookies();

// Extend cookie expiration
await cookieClient.extendExpiration("sessionId", { maxAge: 3600 });

// Clean up expired cookies
await cookieClient.cleanupExpiredCookies();

📚 API Reference

Cookie Client Configuration

GDPR Options

type CookieCategory =
  | "essential"
  | "functional"
  | "analytics"
  | "marketing"
  | "preferences";

interface GDPRConfig {
  category: CookieCategory;
  description: string;
  duration?: string;
  provider?: string;
}

Backup Options

interface BackupConfig {
  critical?: boolean;
  backupCount?: number;
  validateChecksum?: boolean;
}

Methods

GDPR Management

  • getConsent(): Get current consent preferences
  • updateConsent(preferences): Update consent settings
  • getCookiePolicy(): Get structured cookie policy information

Backup & Recovery

  • recoverCookie(name): Recover a cookie from backup
  • backupCookie(name): Manually trigger a backup

Expiration Management

  • getExpiredCookies(): Get all expired cookies
  • getExpiringSoonCookies(threshold?): Get cookies nearing expiration
  • extendExpiration(name, extension): Extend cookie lifetime
  • cleanupExpiredCookies(): Remove expired cookies

🔒 Security Features

  • Checksum validation for backups
  • Automatic consent enforcement
  • Critical cookie protection
  • Corruption detection

🛠️ Development Features

  • Comprehensive debug logging
  • Type-safe operations
  • Detailed error messages
  • Performance optimization

👤 Author

Created by Pidchashyi.


📄 License

MIT © LICENSE