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

@happyvertical/smrt-tenancy

v0.36.0

Published

Production-ready multi-tenancy framework for SMRT with automatic tenant isolation and enforcement

Readme

@happyvertical/smrt-tenancy

Multi-tenancy for SMRT with AsyncLocalStorage context propagation, automatic query filtering, and tenant ID population.

Installation

pnpm install @happyvertical/smrt-tenancy

Usage

import { enableTenancy, TenantScoped, tenantId, withTenant } from '@happyvertical/smrt-tenancy';
import { smrt, SmrtObject } from '@happyvertical/smrt-core';

// 1. Enable tenancy globally (once at app startup)
enableTenancy();

// 2. Mark classes as tenant-scoped
@smrt()
@TenantScoped({ mode: 'optional' })
class Document extends SmrtObject {
  @tenantId({ nullable: true })
  tenantId: string | null = null;

  title: string = '';
}

// 3. Wrap operations in tenant context
await withTenant({ tenantId: 'tenant-123' }, async () => {
  const docs = await collection.list({ where: { status: 'active' } });
  // Executes: WHERE tenant_id = 'tenant-123' AND status = 'active'
});

API

Decorators

| Export | Description | |--------|-------------| | TenantScoped(options?) | Class decorator. Modes: 'required' (default) or 'optional' | | tenantId(options?) | Property decorator for the tenant ID field |

Context Runners

| Export | Description | |--------|-------------| | withTenant(ctx, fn) | Run code scoped to a tenant | | withTenantSync(ctx, fn) | Synchronous variant | | withSystemContext(fn) | Bypass all tenant checks (admin/migrations) | | withSuperAdminBypass(fn) | Keep tenant context but disable auto-filtering | | enterTenantContext(ctx) | Enter context without callback (for middleware) |

Context Accessors

| Export | Description | |--------|-------------| | getCurrentTenant() | Get current tenant context (may be undefined) | | getTenantId() | Get tenant ID string (may be undefined) | | requireTenant() | Get tenant context or throw | | requireTenantId() | Get tenant ID or throw | | hasTenantContext() | Check if in tenant context | | isSystemContext() | Check if in system context | | isSuperAdminBypass() | Check if super admin bypass is active | | TenantContext | AsyncLocalStorage instance (advanced use) |

Errors

TenantContextError (missing required context), TenantIsolationError (tenant mismatch).

Interceptor

| Export | Description | |--------|-------------| | enableTenancy() | Register tenant interceptor globally | | disableTenancy() | Remove tenant interceptor | | isTenancyEnabled() | Check if tenancy is active | | createTenantInterceptor(options?) | Create interceptor manually |

Framework Adapters

| Export | Description | |--------|-------------| | createSvelteKitHandle(options) | SvelteKit hooks.server.ts handler | | createExpressMiddleware(options) | Express middleware | | createCliContext(options) | CLI context with run(), runWithTenant(), runAsSystem() |

Registry (Advanced)

| Export | Description | |--------|-------------| | isTenantScopedClass(name) | Check if a class is tenant-scoped | | getTenantScopedConfig(name) | Get tenant config for a class | | getAllTenantScopedClasses() | List all registered tenant-scoped classes | | registerTenantScopedClass() | Register a class programmatically | | unregisterTenantScopedClass() | Remove a class from registry | | clearTenantScopedRegistry() | Clear all registrations |

Testing

| Export | Description | |--------|-------------| | setupTestTenancy(options?) | Enable tenancy for tests | | resetTenancy() | Clean up tenancy state between tests | | createTestTenantContext(ctx, fn) | Run test code in tenant context | | testTenantIsolation(tenantIds, fn) | Verify isolation between tenants | | assertTenantContextRequired(fn) | Assert operation requires context | | assertTenantIsolationViolation(fn) | Assert operation violates isolation |

Dependencies

  • @happyvertical/smrt-core -- SmrtObject, SmrtCollection, GlobalInterceptors
  • @happyvertical/sql -- database operations
  • @happyvertical/utils -- utility functions

Optional peers: svelte, @happyvertical/smrt-users, @happyvertical/smrt-svelte

License

MIT