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

@livery/next

v0.0.1

Published

Next.js integration for @livery/core - multi-tenant theming for B2B SaaS

Readme

@livery/next

Next.js integration for @livery/core - multi-tenant theming for B2B SaaS applications.

Installation

npm install @livery/next @livery/react @livery/core
# or
pnpm add @livery/next @livery/react @livery/core

Features

  • Middleware - Theme detection from subdomain, path, header, or query
  • App Router - Server-side theme resolution with cache headers
  • Type-safe - Full TypeScript support with inferred types

Quick Start

1. Define Your Schema

// lib/theme.ts
import { createSchema, createResolver, t } from '@livery/core';
import { createDynamicThemeProvider } from '@livery/react';

export const schema = createSchema({
  definition: {
    brand: {
      primary: t.color().default('#3b82f6'),
      secondary: t.color().default('#64748b'),
    },
  },
});

export const resolver = createResolver({
  schema,
  fetcher: async ({ themeId }) => {
    // Fetch theme from your database
    return await db.themes.findByTheme(themeId);
  },
});

export const { DynamicThemeProvider, useTheme, useThemeValue } =
  createDynamicThemeProvider({ schema });

2. Add Middleware

// middleware.ts
import { createLiveryMiddleware } from '@livery/next/middleware';

export const middleware = createLiveryMiddleware({
  strategy: 'subdomain',
  subdomain: {
    baseDomain: 'yourapp.com',
    ignore: ['www', 'app'],
  },
  fallback: '/select-workspace',
});

export const config = {
  matcher: ['/((?!api|_next/static|_next/image|favicon.ico).*)'],
};

3. Set Up App Router Layout

// app/layout.tsx
import { headers } from 'next/headers';
import { getLiveryData, getThemeFromHeaders } from '@livery/next';
import { DynamicThemeProvider, schema, resolver } from '@/lib/theme';

export default async function RootLayout({ children }: { children: React.ReactNode }) {
  const headersList = await headers();
  const themeId = getThemeFromHeaders({ headers: headersList }) ?? 'default';

  const { theme, css } = await getLiveryData({
    themeId,
    schema,
    resolver,
  });

  return (
    <html lang="en">
      <head>
        <style id="livery-critical" dangerouslySetInnerHTML={{ __html: css }} />
      </head>
      <body>
        <DynamicThemeProvider
          themeId={themeId}
          resolver={resolver}
          initialTheme={theme}
          injection="none"
        >
          {children}
        </DynamicThemeProvider>
      </body>
    </html>
  );
}

Middleware Strategies

Subdomain

Extract theme from subdomain (e.g., acme.yourapp.com -> acme).

createLiveryMiddleware({
  strategy: 'subdomain',
  subdomain: {
    baseDomain: 'yourapp.com',
    ignore: ['www', 'app', 'api'],
  },
});

Path

Extract theme from URL path (e.g., /t/acme/dashboard -> acme).

createLiveryMiddleware({
  strategy: 'path',
  path: {
    prefix: '/t/',
    rewrite: true, // Rewrites /t/acme/dashboard -> /dashboard
  },
});

Header

Extract theme from request header.

createLiveryMiddleware({
  strategy: 'header',
  header: {
    name: 'X-Theme-ID',
  },
});

Query

Extract theme from query parameter.

createLiveryMiddleware({
  strategy: 'query',
  query: {
    name: 'theme',
  },
});

Custom

Use a custom extraction function.

createLiveryMiddleware({
  strategy: 'custom',
  getTheme: async ({ request }) => {
    const subdomain = request.headers.get('host')?.split('.')[0];
    return { themeId: subdomain ?? null };
  },
});

Validation

Validate theme exists before allowing access.

createLiveryMiddleware({
  strategy: 'subdomain',
  validate: async ({ themeId }) => {
    return await db.themes.exists(themeId);
  },
  fallback: '/404',
});

Cache Headers

Set appropriate cache headers for theme responses.

// app/api/theme/[themeId]/route.ts
import { getCacheHeaders } from '@livery/next';

export async function GET(request: Request) {
  const theme = await resolver.resolve({ themeId });

  return Response.json(theme, {
    headers: getCacheHeaders({
      maxAge: 300,
      staleWhileRevalidate: 3600,
    }),
  });
}

API Reference

createLiveryMiddleware(options)

Creates a Next.js middleware function for theme detection.

| Option | Type | Description | | ------------- | ------------------------------------------------- | ------------------------------------ | | strategy | 'subdomain' \| 'path' \| 'header' \| 'query' \| 'custom' | Theme extraction strategy | | subdomain | { baseDomain, ignore? } | Subdomain strategy options | | path | { prefix, rewrite? } | Path strategy options | | header | { name } | Header strategy options | | query | { name } | Query strategy options | | getTheme | ({ request }) => { themeId, rewritePath? } | Custom extraction function | | validate | ({ themeId }) => Promise<boolean> | Theme validation function | | fallback | string | Redirect path when theme not found | | themeHeader | string | Header name for theme ID (default: 'x-livery-theme') | | skipPaths | string[] | Paths to skip middleware processing |

getLiveryData({ themeId, schema, resolver, cssOptions? })

Resolves theme data on the server for App Router.

Returns: { theme, css, themeId }

getThemeFromHeaders({ headers, headerName? })

Get the theme ID from request headers set by middleware.

getCacheHeaders(options?)

Generate cache headers for theme responses.

| Option | Type | Default | Description | | ----------------------- | -------- | ------- | ------------------------------ | | maxAge | number | 300 | Cache max-age in seconds | | staleWhileRevalidate | number | 3600 | SWR duration in seconds | | private | boolean| false | Use private cache directive |

License

MIT