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

@zamatica/auth-nestjs

v0.1.1

Published

NestJS Guard, decorators, and helpers for the zamatica fleet-env cert auth scheme. Designed DI-trap-free for safe consumption across bun-link boundaries — see CLAUDE.md / README for the discipline rules.

Readme

@zamatica/auth-nestjs

NestJS-specific bits of the zamatica fleet-env cert auth scheme: the CertAuthGuard, @RequiresPermission and @Public decorators, the per-deploy instance-id helper, the audit log shape, and the startup permission-registry scan.

Pure cryptographic and registry primitives live in @zamatica/auth-core (framework-agnostic). This lib is the NestJS adapter layer.

Install

bun add @zamatica/auth-nestjs @zamatica/auth-core

Peer deps (consumers bring their own): @nestjs/common, @nestjs/core, reflect-metadata.

The bun-link DI discipline (read before consuming!)

This lib is intentionally designed to be safe to consume across the cross-repo bun link boundary, which is the dev-time pattern for @zamatica/* consumers. Bun-link creates two copies of @nestjs/core (one in the lib's tree, one in the consumer's). NestJS DI does class-identity checks (instanceof X), and those checks fail between copies. The trap is documented in the workspace CLAUDE.md (see feedback_bun_link_nestjs_di).

Two rules:

  1. Always register the guard via app.useGlobalGuards(new CertAuthGuard(...)), never via the APP_GUARD token. APP_GUARD goes through NestJS's DI tree and would re-trigger the class-identity trap. useGlobalGuards takes a pre-instantiated instance and just calls canActivate(ctx) — no DI involved at registration time.

  2. Never @Inject() a NestJS framework class (Reflector, ApplicationConfig, HttpAdapterHost, …). This lib reads route metadata via Reflect.getMetadata directly — reflect-metadata is a process-global polyfill, immune to the cross-copy problem. If a future feature genuinely needs framework-internal DI, that's the signal the feature belongs in the consumer repo, not in this lib.

The CRL poller is a plain class with start()/stop() (not @Injectable()) for the same reason.

Quick wiring

import 'reflect-metadata';
import { NestFactory } from '@nestjs/core';
import { CertAuthGuard, scanRoutesForUndeclaredPermissions } from '@zamatica/auth-nestjs';
import { parseTrustBundle } from '@zamatica/auth-core';
import { AppModule } from './app.module.js';

async function bootstrap() {
  const app = await NestFactory.create(AppModule);

  // 1. Validate every @RequiresPermission target is in @zamatica/auth-core's registry.
  // Hard-fail at startup, not at request time.
  const scan = scanRoutesForUndeclaredPermissions(app);
  if (scan.undeclared.length > 0) {
    throw new Error(`Undeclared permissions in @RequiresPermission: ${scan.undeclared.join(', ')}`);
  }

  // 2. Construct and register the guard.
  const trustBundle = parseTrustBundle(/* …read from disk… */).value;
  const guard = new CertAuthGuard({
    trustBundle,
    mode: process.env['MTZ_AUTH_MODE'] === 'open' ? 'open' : 'cert',
    expectedFleetEnv: process.env['MTZ_FLEET_ENV'] ?? 'prod',
    signatureWindowSeconds: 300,
    instanceId: 'auto', // auto-generates a per-process UUID
    audit: { /* sink */ },
  });
  app.useGlobalGuards(guard);

  await app.listen(3000);
}

Decorator inventory

  • @Public() — opt a route out of auth entirely. Use sparingly: /health, /version, anything truly anonymous.
  • @RequiresPermission('domain.action') — declares the permission the route requires. The string must be in @zamatica/auth-core's registry (registered via @PermissionGroup somewhere). Startup scan enforces this.

/api/* routes without @RequiresPermission(): requires any valid cert (authentication only). /admin/* routes without @RequiresPermission(): default-DENY (defense in depth). Adding an /admin/* route without thinking about permissions → 403, not a silent privilege escalation.

Development

bunx nx build auth-nestjs
bunx nx test auth-nestjs