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

@vicstack/adapters-hono

v0.1.0

Published

Hono middleware adapter for @vicstack/permissions.

Readme

@vicstack/adapters-hono

Hono middleware adapter for @vicstack/permissions.

Install

bun add @vicstack/adapters-hono hono

Usage

Two exports: guard, a middleware factory that guards a whole route behind a permission and responds with a 403 on denial, and authorize, a handler-level helper returning a plain boolean for checks too dynamic to guard declaratively at the route level. Both take the can function returned by createCan() and resolve the current user via c.get("user") by default (override with options.getUser), an optional resource via options.getResource for resource-scoped permissions (e.g. loaded from a route param), and let you override the default 403 JSON body via options.onDenied.

import { Hono } from "hono";
import { createCan, type PermissionsGenerator } from "@vicstack/permissions";
import { guard, authorize } from "@vicstack/adapters-hono";

const roles = ["admin", "moderator", "user"] as const;
const actions = ["create", "read", "update", "delete"] as const;

type User = { id: string; name: string; roles: (typeof roles)[number][] };
type Post = { id: string; authorID: string; body: string; createdAt: Date };
type Resources = { post: { model: Post } };
type Permissions = PermissionsGenerator<User, typeof roles, typeof actions, Resources>;

const permissions = {
  admin: { "post:*": true },
  moderator: { "post:read": true, "post:update": (u, p) => u.id === p.authorID },
  user: { "post:read": true, "post:update": (u, p) => u.id === p.authorID },
} satisfies Permissions;

const can = createCan<User, typeof roles, typeof actions, Resources, typeof permissions>(
  permissions,
);

const app = new Hono();

// an earlier auth middleware is expected to have done c.set("user", ...)
app.get("/posts", guard(can, "post:read"), (c) => c.json(listPosts()));

app.patch(
  "/posts/:id",
  guard(can, "post:update", {
    getResource: async (c) => await findPost(c.req.param("id")),
    // onDenied: (c) => { throw new HTTPException(403, { message: "not your post" }); },
  }),
  (c) => c.json(updatePost(c.req.param("id"))),
);

// too dynamic to express as a route guard: check inside the handler and combine with other logic
app.get("/posts/:id/edit-form", async (c) => {
  const post = await findPost(c.req.param("id"));
  const canEdit = await authorize(c, can, "post:update", { getResource: () => post });
  return c.json({ post, canEdit });
});

A getResource that throws or rejects is not treated as a denial — the error propagates to Hono's own error handling, since a resource-lookup failure is a distinct failure mode from "permission denied." guard always awaits the underlying can() call, so it works the same way whether the specific permission's check is sync or async.

Develop

This package lives in the @vicstack/permissions monorepo, at packages/adapters/hono. See the repo root README for monorepo-wide setup.