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

@open-apiary/nuxt

v0.0.8

Published

The Nuxt module for open-apiary. It mounts a package that `apiary build` produced, with one server route for each endpoint.

Readme

@open-apiary/nuxt

The Nuxt module for open-apiary. It mounts a package that apiary build produced, with one server route for each endpoint.

Install

pnpm add @open-apiary/nuxt open-apiary @acme/api

Setup

// nuxt.config.ts
export default defineNuxtConfig({
  modules: ["@open-apiary/nuxt"],
  openApiary: { package: "@acme/api", base: "/api" },
});
  • package names the package that apiary build produced. It exports ./manifest.json, ./openapi.json, and ./routes/*.
  • base is the path the API mounts at. The default is /api.

The app registers no provider. The package holds the classes of the API and of its presets, under its providers/, and the module hands them to the engine.

The module reads the manifest of the package at build time. It makes one Apiary engine for the server, in a virtual module, over the data of the manifest and one dynamic import for each route module of the package. Then it registers:

  • One lazy server handler for each endpoint, under its method and its route: GET /users/{id} is GET <base>/users/:id. The handler is the defineApiaryRoute of @open-apiary/h3 over the engine. Nitro writes one chunk for each endpoint, and the engine loads it at the first request to its route. The handler reads the path parameters, the query, the headers, and the body, and the engine runs the call. An exception that the endpoint declares becomes a response with its status and its problem details object, as application/problem+json. Any other error is a 500.
  • GET <base>/openapi.json, the document of the package.
  • GET <base>/docs, a Scalar page over it.
  • <base>/**, which answers 404 for a request that no endpoint takes. The module leaves it out when the base is the root, where it would take the pages of the app.

When the package has the types of its document, openapi.d.ts beside openapi.json, the module types each route for Nitro from them. $fetch and useFetch then know what a route of the API answers, with no client and no import:

const user = await $fetch("/api/users/123"); // the `User` of the document
const { data } = await useFetch("/api/users"); // `User[] | undefined`

The type is the JSON body of the response with the status of the endpoint, and undefined for an endpoint with no body. Nitro types what a route answers, and not what it takes: for the body, the query, and the path of a request, import the types from <package>/openapi. The package exports them as ./openapi.

When the manifest lists providers, the module also imports <package>/providers and hands the list to the engine, so the classes that the API and its presets ship fill their contracts. The package then exports ./providers. When the manifest lists contracts, the server checks that a class fills each one as it makes the engine, and fails with UnfilledContractsError for those that none does.

The module reads the built package, so run apiary build before the build of the app, and again after a change of the API.

The server file

A config holds no code, so the module takes the code of the server from a file of the app. server names it, and its default export is the options:

// nuxt.config.ts
export default defineNuxtConfig({
  modules: ["@open-apiary/nuxt"],
  openApiary: { package: "@acme/api", server: "~~/server/apiary" },
});
// server/apiary.ts
import type { ServerOptions } from "@open-apiary/nuxt";

export default {
  challenge: "Bearer",
  caller: async (event) => {
    const user = await userOf(event);
    return user === undefined
      ? undefined
      : { scopes: user.scopes, subject: user.id };
  },
  onError: (error, { id }) => report(error, id),
} satisfies ServerOptions;
  • caller builds the caller of a request, or returns undefined for a request with none. It runs for a request that an endpoint takes, and for no other request of the app: a page, an asset, or a route of the app itself does not pay for it.
  • challenge is the WWW-Authenticate of a 401.
  • authorize decides whether a caller may call an endpoint with scopes. The default requires every scope of the endpoint.
  • onError takes each error that the engine answers with a 500 for.

The caller

Without a caller in the server file, each handler reads the caller from event.context.apiary.caller. A server middleware sets it from the request, and runs for every request of the app:

// server/middleware/auth.ts
export default defineEventHandler((event) => {
  const token = getHeader(event, "authorization");
  if (token === undefined) {
    return;
  }
  event.context.apiary = {
    caller: { scopes: scopesOf(token), subject: subjectOf(token) },
  };
});

A request that no middleware describes has no caller, and an endpoint that requires one answers 401. A caller without the scopes of an endpoint gets a 403.