s-m-r-t
Open the s-m-r-t source on GitHub Switch to dark color scheme
← All packages
Foundation v0.57.40

@happyvertical/smrt-tenancy

Automatic tenant isolation, context propagation, required or optional scope, and tenant-aware query enforcement.

Source ↗

What it gives you

Automatic tenant isolation, context propagation, required or optional scope, and tenant-aware query enforcement.

  1. 01Required, optional, and global data scopes
  2. 02AsyncLocalStorage context propagation
  3. 03Tenant-safe interceptors across lookups, hydration, search, and collection memory
  4. 04Super-admin bypass is a per-class opt-in, off by default

Directory changes can notify other systems

The tenancy interceptor emits directory.<class>.created, updated, and deleted through dispatchBus after save or delete for configured directoryClasses. It is an event hook for directory projections, not a replacement for the request tenant context.

Adapters establish the context for their host

SvelteKit is one adapter. Express applications use createExpressMiddleware and enterTenantContext. CLI work uses createCliContext: run keeps a caller context, runWithTenant selects one tenant, runAsSystem is cross-tenant by explicit system authority, and runAsSuperAdmin is the more privileged explicit path.

Scope covers each read path

Tenant context applies to list and get calls, slug lookups, model hydration, vector search, and collection memory. Required models fail closed without a tenant context. A system context removes the context entirely and skips every check. withSuperAdminBypass keeps the tenant context and lifts enforcement only for classes that set allowSuperAdminBypass to true. The flag defaults to false, and unresolved config fails closed. auditTenantScopedRegistrations reports runtime-only registrations whose natural key omits the tenant column.