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

@treblle/next

v1.1.0

Published

Official Treblle SDK for Next.js applications

Downloads

48

Readme

Treblle - API Intelligence Platform

Treblle API Intelligence

WebsiteDocumentationPricing

Treblle is an API intelligence platfom that helps developers, teams and organizations understand their APIs from a single integration point.


Treblle Next.js SDK

Treblle Next.js SDK that supports Pages Router (pages/api) and App Router (app/api) supported

Requirements

  • Node.js: Follows your Next.js version requirements (Node 18+ recommended)
  • Runtimes: Node.js and Edge (see Edge notes)

Installation

npm install @treblle/next
# or
pnpm add @treblle/next
# or
yarn add @treblle/next

Keep keys server-only. Do not expose with NEXT_PUBLIC_.

Get Your Keys

  1. Create a free account: https://treblle.com
  2. Create a project to get:
    • sdkToken
    • apiKey
  3. Add to your .env (server-only):
TREBLLE_SDK_TOKEN=your_sdk_token
TREBLLE_API_KEY=your_api_key

Quick Start

Pick your routing setup:

  • Pages Router: wrap pages/api/* handlers
  • App Router: wrap app/api/* route method exports
  • Middleware (optional): observe all requests at the edge (with body limits)

Pages Router (pages/api)

pages/api/users.ts

import type { NextApiRequest, NextApiResponse } from 'next';
import { withTrebllePages } from '@treblle/next/integrations/nextjs';

const treblle = withTrebllePages({
  sdkToken: process.env.TREBLLE_SDK_TOKEN!,
  apiKey: process.env.TREBLLE_API_KEY!,
  // debug: process.env.NODE_ENV !== 'production',
});

async function handler(req: NextApiRequest, res: NextApiResponse) {
  if (req.method === 'GET') return res.status(200).json({ users: [] });
  return res.status(405).json({ error: 'Method not allowed' });
}

export default treblle(handler);

JavaScript version:

import { withTrebllePages } from '@treblle/next/integrations/nextjs';

const treblle = withTrebllePages({
  sdkToken: process.env.TREBLLE_SDK_TOKEN,
  apiKey: process.env.TREBLLE_API_KEY,
});

async function handler(req, res) {
  if (req.method === 'GET') return res.status(200).json({ users: [] });
  return res.status(405).json({ error: 'Method not allowed' });
}

export default treblle(handler);

App Router (app/api)

app/api/users/route.ts

import { NextResponse } from 'next/server';
import { withTreblle } from '@treblle/next/integrations/nextjs';

const treblle = withTreblle({
  sdkToken: process.env.TREBLLE_SDK_TOKEN!,
  apiKey: process.env.TREBLLE_API_KEY!,
  // debug: process.env.NODE_ENV !== 'production',
});

export const GET = treblle(async () => {
  return NextResponse.json({ users: [] });
});

export const POST = treblle(async (req: Request) => {
  const body = await req.json();
  return NextResponse.json({ success: true, user: body }, { status: 201 });
});

// To run on Edge (optional):
// export const runtime = 'edge';

Optional: Global Middleware (Edge)

Use only if you want coarse-grained visibility on every request. Middleware can’t read bodies for non‑GET methods, so wrap API handlers for full detail.

// middleware.ts
import { NextResponse } from 'next/server';
import { withTreblleMiddleware } from '@treblle/next/integrations/nextjs';

const treblle = withTreblleMiddleware({
  sdkToken: process.env.TREBLLE_SDK_TOKEN!,
  apiKey: process.env.TREBLLE_API_KEY!,
  // blocklistPaths: [/^\/_next\//, 'static', 'images'],
});

export default treblle(async () => NextResponse.next());

// Limit to API routes (optional):
// export const config = { matcher: ['/api/:path*'] };

Configuration

Pass these options to withTreblle, withTrebllePages, or withTreblleMiddleware:

  • sdkToken: Your Treblle SDK token (required)
  • apiKey: Your Treblle API key (required)
  • additionalFieldsToMask: Extra field names to mask (string[])
  • blocklistPaths: Paths to exclude (string prefixes or a RegExp)
  • ignoreDefaultBlockedPaths: Disable default static/noise filters (boolean; default false)
  • debug: Print Treblle errors to console (boolean; default false)

Example:

const treblle = withTreblle({
  sdkToken: process.env.TREBLLE_SDK_TOKEN!,
  apiKey: process.env.TREBLLE_API_KEY!,
  additionalFieldsToMask: ['customSecret', 'internalId'],
  blocklistPaths: ['admin', /^\/api\/v1\/internal/],
  ignoreDefaultBlockedPaths: false,
  debug: process.env.NODE_ENV !== 'production',
});

Production-only enablement:

const maybeTreblle = process.env.NODE_ENV === 'production'
  ? withTreblle({ sdkToken: process.env.TREBLLE_SDK_TOKEN!, apiKey: process.env.TREBLLE_API_KEY! })
  : ((h: any) => h); // no-op passthrough

export const GET = maybeTreblle(async () => NextResponse.json({ ok: true }));

Defaults

Masked Fields

Automatically masked in request/response bodies:

  • password, pwd, secret, password_confirmation, passwordConfirmation
  • cc, card_number, cardNumber, ccv
  • ssn
  • credit_score, creditScore

Add more via additionalFieldsToMask.

Blocked Paths

Ignored by default to reduce noise:

  • Files: favicon.ico, robots.txt, sitemap.xml, manifest.json, sw.js, service-worker.js, browserconfig.xml, crossdomain.xml, ads.txt, apple-touch-icon*
  • Directories: /.well-known/, /static/, /assets/, /public/, /images/, /css/, /js
  • Extensions: .css, .js, .png, .jpg, .jpeg, .gif, .svg, .ico, .woff, .woff2, .ttf, .eot

Override example:

ignoreDefaultBlockedPaths: true,
blocklistPaths: ['favicon.ico'],

Edge Notes

  • App Router handlers can opt into Edge with export const runtime = 'edge'
  • Middleware runs at the edge; bodies of non‑GET requests are not readable there
  • Prefer wrapping route handlers for full body and error detail

API Reference

  • withTreblle(config) -> (handler) => wrappedHandler
    • Wraps App Router route method handlers
  • withTrebllePages(config) -> (handler) => wrappedHandler
    • Wraps Pages Router API handlers
  • withTreblleMiddleware(config) -> (mw) => wrappedMiddleware
    • Wraps middleware.ts for global observation (Edge)

Config type (informal):

type NextTreblleConfig = {
  sdkToken: string;
  apiKey: string;
  additionalFieldsToMask?: string[];
  blocklistPaths?: (string | RegExp)[];
  ignoreDefaultBlockedPaths?: boolean;
  debug?: boolean;
};

Troubleshooting

  • Enable logs: set debug: true and check server output
  • Verify keys: sdkToken and apiKey from your Treblle dashboard
  • Start simple: add a GET /api/health and hit it
  • Check blocking: ensure your route isn’t blocked by defaults or blocklistPaths
  • Edge body missing: use handler wrapping instead of middleware for body capture

Security Notes

  • Store keys in server-only env vars; never use NEXT_PUBLIC_*
  • Avoid logging secrets; use additionalFieldsToMask for custom sensitive fields

License

MIT © Treblle Inc.


Copy‑Paste Templates

Pages Router:

// pages/api/hello.ts
import type { NextApiRequest, NextApiResponse } from 'next';
import { withTrebllePages } from '@treblle/next/integrations/nextjs';

const treblle = withTrebllePages({
  sdkToken: process.env.TREBLLE_SDK_TOKEN!,
  apiKey: process.env.TREBLLE_API_KEY!,
});

async function handler(req: NextApiRequest, res: NextApiResponse) {
  return res.status(200).json({ ok: true });
}

export default treblle(handler);

App Router:

// app/api/hello/route.ts
import { NextResponse } from 'next/server';
import { withTreblle } from '@treblle/next/integrations/nextjs';

const treblle = withTreblle({
  sdkToken: process.env.TREBLLE_SDK_TOKEN!,
  apiKey: process.env.TREBLLE_API_KEY!,
});

export const GET = treblle(async () => NextResponse.json({ ok: true }));

Middleware (optional):

// middleware.ts
import { NextResponse } from 'next/server';
import { withTreblleMiddleware } from '@treblle/next/integrations/nextjs';

const treblle = withTreblleMiddleware({
  sdkToken: process.env.TREBLLE_SDK_TOKEN!,
  apiKey: process.env.TREBLLE_API_KEY!,
});

export default treblle(async () => NextResponse.next());
// export const config = { matcher: ['/api/:path*'] };