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

tenancyjs-integration-next

v0.1.2

Published

Fail-closed Next.js App Router integration for TenancyJS.

Readme

tenancyjs-integration-next

Fail-closed tenant context for Next.js 16.2 App Router Route Handlers and Server Actions.

New to TenancyJS? Start with the docs → — install, the tenancyjs-cli CLI, and how this package fits with an adapter + integration.

Install

pnpm add tenancyjs-core tenancyjs-identifiers tenancyjs-integration-next next

Node runtime

import { TenancyManager } from "tenancyjs-core";
import {
  HeaderTenantResolver,
  TenantResolutionChain,
} from "tenancyjs-identifiers";
import { createNextTenancy } from "tenancyjs-integration-next";

const manager = new TenancyManager();
const resolver = new TenantResolutionChain({
  resolvers: [new HeaderTenantResolver()],
  store: tenantStore,
  // Verify the authenticated user belongs to the resolved tenant — resolving a
  // tenant is not authorizing it. Required (or opt out with trustResolution).
  authorize: ({ tenant, principal }) => principal.teamIds.includes(tenant.id),
});
const tenancy = createNextTenancy({
  manager,
  resolver,
  principal: async () => getSessionUser(), // read your session (Node runtime)
});

export const GET = tenancy.withRouteHandler(async () => {
  const tenant = manager.getTenantOrFail();
  return Response.json({ tenantId: tenant.id });
});

Wrap a Server Action with tenancy.withServerAction(action). The wrapper resolves from Next's request headers() in the Node runtime; it never trusts action arguments as tenant identity.

Only work awaited by the wrapped handler or action is inside tenant context. A streamed response body executes after the Route Handler returns and must not perform tenant-scoped database work.

Edge identity handoff

Middleware may copy normalized identity metadata with the Edge-only export:

import { NextResponse } from "next/server";
import { withNextTenantHint } from "tenancyjs-integration-next/edge";

export function middleware(request: Request) {
  return NextResponse.next({
    request: { headers: withNextTenantHint(request) },
  });
}

The hint is untrusted transport metadata. The Node wrapper always passes it through the configured resolver and tenant store. A forged hint therefore cannot create a tenant context by itself.

Security boundary

  • Use only the wrapped Route Handler or Server Action for tenant-scoped work.
  • Missing, invalid, unknown, suspended, and ambiguous identities fail closed with a typed, sanitized NextTenancyResolutionError.
  • Unknown and suspended tenants share the same public message and status.
  • Edge code does not load tenant context, registries, adapters, or database clients.
  • Next cache entries must be tenant-keyed or explicitly uncached. This package does not patch Next cache APIs.