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

@spinajs/authz

v3.0.20

Published

Authorization core for SpinaJS: contracts, engine, conditions

Readme

@spinajs/authz

Authorization core for SpinaJS: contracts, engine, conditions, host.

Writing a model

A model is a class that extends AuthorizationModel (RBAC, ABAC, ReBAC, or your own). The engine calls evaluate(req, ctx) and combines the votes. These rules keep the answer correct and safe to cache.

Missing or failed data

  • Throw, or let the call time out. Never vote "no". The engine treats a thrown or timed-out vote as indeterminate (model_error): it fails closed and is never cached. A "no" vote looks like a clean answer, so the engine can cache it.
  • Memoise the promise of a load in ctx.cache, or memoise nothing. Never write a placeholder value before the load settles: a concurrent check reads it as a clean answer the engine cannot see as a fault.

Caches

  • Key every cache you keep (your own or ctx.cache) on everything the answer depends on: principal state, permission, resource, scope, version. A missing part leaks one answer to another request.
  • Do not derive a cacheable vote from principal.identity or env: the L2 key does not hold them. Set cacheable: false on such a vote. Refs to env.* or identity in a residual already make the decision uncacheable.
  • validUntil on a vote caps the life of a cached decision: set it for every expiring grant.
  • denies[] carries one entry per deny source, each with a reason. Set reason.priority (lower wins) so the engine reports the right reason; ties break on sortKey.

Capabilities

capabilities is a promise. The engine and the boot checks rely on it.

  • effects: the vote kinds the model casts (permit, deny).
  • residuals: every filter op a vote may hold. An op left out fails boot or is refused at run time.
  • sync: governs filterNow on type-level requests. after-preload needs a preload method, and filterNow refuses it until preload ran for the principal.
  • fields: true when votes carry fields.
  • needsSubject: true when some answers need the row and cannot be residualised.
  • principalTypes, resourceTypes: narrow the model to the types it can judge; the engine skips it for others.

Lifecycle

  • init(ctx) runs once per model instance, in the first domain that lists it. Register permissions, native filters and relations there (ctx.registerPermissions, ctx.registerNativeFilter, ctx.registerRelation). A child domain sees the registrations of its parent.
  • version(): when the value changes, the engine recompiles the routes and drops the domain's L2 cache.
  • invalidate(tags) receives the AuthzChange tags from every store: drop your own caches for them.
  • dispose(): the host calls it once the last domain that lists the model is disposed, and only if its init ran; DI disposes models that are DI Services itself.

Registration

  • A root model may use @Injectable(AuthorizationModel).

  • A child-domain model is registered on the domain's container, never with @Injectable (DI-2: a decorator registers in root, so the model would leak into every domain):

    const domains = await DI.resolve(AuthzDomains); // needs the Configuration resolved first
    const c = domains.create('fs'); // or domains.create('fs', 'parent')
    // Register before the first domains.service('fs'): a booted domain does not see later registrations.
    c.register(FsModel).as(AuthorizationModel);

Testing

  • Run runModelConformance from @spinajs/authz-testing against the model.
  • Run the B-rules your lane owns with runBehaviour (see the @spinajs/authz-testing README, "Writing a harness" and "DI rules for harness writers").

Host

  • One AuthzService per domain. Resolve the root service with await DI.resolve(AuthzService), any domain with await (await DI.resolve(AuthzDomains)).service(name).
  • authz(domain?) is synchronous and never resolves anything: resolve the service first, or it throws AuthzConfigError.
  • service.runAs(principal, reason, fn) runs fn with principal as the current principal, with its own request cache. It audits the call unless authz.audit.runAs is false.
  • Config lives under authz.*. authz.domains.<name>.* applies to one domain and its children: combine, engine, fields, cache and audit override the parent's, permissions adds to the parent's registry, disable drops ancestor models by name. A model reads its own section, authz.<model.name>.*, through ctx.config(path, default).
  • A package feeds the boot checks by registering an AuthzContributor; its contribute(domain) returns permission, relation and scope refs, join types and scope attribute schemas.