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

@orion-studios/payload-nextjs-utils

v0.1.1

Published

Next.js integration utilities for Payload CMS

Readme

@orion-studios/payload-nextjs-utils

Next.js integration utilities for Payload CMS - page queries, site globals, media resolution, and Payload client management.

Installation

npm install @orion-studios/payload-nextjs-utils

Features

  • Payload Client Singleton: Factory for creating cached Payload client
  • Page Queries: Fetch pages by URL segments with Next.js caching
  • Site Globals: Cached queries for header, footer, and site settings
  • Media Resolution: Convert Payload media references to URLs
  • TypeScript Support: Full type definitions
  • Next.js Integration: Works with App Router and Pages Router

Usage

Setup: Create Payload Client

// src/lib/payload.ts
import config from '@/payload.config'
import { createPayloadClient } from '@orion-studios/payload-nextjs-utils'

export const getPayloadClient = createPayloadClient(config)

Page Queries

// src/lib/pages.ts
import { getPayloadClient } from './payload'
import { createPageQueries } from '@orion-studios/payload-nextjs-utils'

export const { getPageBySegments, listPublishedPagePaths, pathToSegments } =
  createPageQueries(getPayloadClient)
// src/app/[[...slug]]/page.tsx
import { getPageBySegments, listPublishedPagePaths } from '@/lib/pages'

export async function generateStaticParams() {
  const paths = await listPublishedPagePaths()
  return paths.map((path) => ({
    slug: path.split('/').filter(Boolean),
  }))
}

export default async function Page({
  params,
}: {
  params: Promise<{ slug?: string[] }>
}) {
  const { slug } = await params
  const page = await getPageBySegments(slug)

  if (!page) {
    notFound()
  }

  return (
    <div>
      <h1>{page.title}</h1>
      {/* Render page.layout blocks */}
    </div>
  )
}

Site Globals

// src/lib/site.ts
import { getPayloadClient } from './payload'
import { createSiteQueries } from '@orion-studios/payload-nextjs-utils'

export const { getSiteSettings, getHeader, getFooter } =
  createSiteQueries(getPayloadClient)
// src/app/layout.tsx
import { getHeader, getFooter } from '@/lib/site'

export default async function RootLayout({
  children,
}: {
  children: React.ReactNode
}) {
  const header = await getHeader()
  const footer = await getFooter()

  return (
    <html>
      <body>
        <Header navItems={header.navItems} />
        {children}
        <Footer {...footer} />
      </body>
    </html>
  )
}

Media Resolution

import { resolveMedia } from '@orion-studios/payload-nextjs-utils'

// In your component
const media = resolveMedia(block.image)

if (media) {
  return <img src={media.url} alt={media.alt} />
}

API Reference

createPayloadClient(config)

Creates a Payload client singleton factory.

Parameters:

  • config: Your Payload config (from payload.config.ts)

Returns: Function that returns cached Payload client

createPageQueries(getPayloadClient, contentTag?)

Creates page query utilities.

Returns:

  • getPageBySegments(segments?, draft?): Fetch page by URL segments
  • listPublishedPagePaths(): List all published page paths
  • pathToSegments(path): Convert path string to segments array

createSiteQueries(getPayloadClient, contentTag?)

Creates site globals query utilities.

Returns:

  • getSiteSettings(draft?): Fetch site settings global
  • getHeader(draft?): Fetch header global
  • getFooter(draft?): Fetch footer global

resolveMedia(media)

Converts Payload media reference to usable URL object.

Parameters:

  • media: Media ID, object, or null

Returns: { url: string, alt: string } | null

Caching

All queries automatically use Next.js unstable_cache with the tag website-content (customizable via contentTag parameter). This enables:

  • Automatic Revalidation: Cache is invalidated when content changes
  • Optimal Performance: Cached queries are nearly instant
  • ISR Support: Works with Incremental Static Regeneration
// To revalidate cache
revalidateTag('website-content')

Requirements

  • Payload CMS 3.x
  • Next.js 14+ or 15+

License

MIT © Orion Studios