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

@horussw/auth-core

v0.2.0

Published

Core contracts and engines for multi-tenant AuthN/AuthZ.

Readme

@horussw/auth-core

Framework-independent, multi-tenant authorization with exact permissions and attribute policies. Node >=20.

npm install @horussw/auth-core
import { AuthorizationEngine, AttributePolicyEngine } from '@horussw/auth-core';

const engine = new AuthorizationEngine({
  permissionProvider: {
    async loadPermissions({ principal, tenantId }) {
      // Look up active tenant membership and resolve role/direct grants in your database.
      const permissions = await membershipRepository.permissions(principal.subjectId, tenantId);
      return { subjectId: principal.subjectId, tenantId, roles: [], permissions };
    },
  },
  resourceAttributeProvider: {
    async getAttributes(type, id, { tenantId }) {
      if (type !== 'invoice') return null;
      // Return null if absent; returned attributes must include the actual tenantId.
      return invoiceRepository.attributesByTenantAndId(tenantId, id);
    },
  },
  policyEngine: new AttributePolicyEngine({
    policies: {
      draft: ({ resourceAttributes }) => resourceAttributes?.status === 'draft',
    },
  }),
});

const decision = await engine.authorize({
  principal,
  tenantId: principal.tenantId,
  action: 'approve',
  resourceType: 'invoice',
  resourceId: '42',
  policies: ['draft'],
});
if (!decision.allow) throw new Error('Forbidden');

Every required permission must be present; absent requiredPermissions, the key is resourceType:action. Wildcards and role hierarchies are not inferred. All named policies must return exactly true; unknown policies deny. BasicPolicyEngine supports owner and sameTenant and rejects named policies.

Migration from 0.1

  • The provider is authoritative; principal/JWT permissions are no longer merged.
  • Tenant is required by default; subject and tenant must match the snapshot. Identified resources require trusted attributes with a matching tenant. Missing resources never fall back to supplied attributes.
  • Resource providers receive a third argument { principal, tenantId, action }. Query storage by tenant and ID.
  • Cache keys are JSON tuples. Default TTL is 60s, capped at 300s, also bounded by expiresAt. Zero avoids caching. Date objects must survive cache serialization.
  • After committed permission changes, call engine.invalidatePermissions(subjectId, tenantId). Shared deployments require shared deletion; in-flight requests are not cancelled. Disable permission caching when immediate revocation is required.
  • In-memory caching is bounded to 10,000 entries by default. Audit sink failures deny; redact sensitive principal claims in your sink.

The application must filter lists and response fields, validate writable fields, and protect mutable ABAC decisions with transactions/version checks. Custom PolicyEngine implementations are trusted code responsible for their permission semantics. The engine retains snapshot and resource tenant invariants.