@venturekit-pro/tenancy
Installation
Section titled “Installation”npm install @venturekit-pro/tenancy@devWhat It Provides
Section titled “What It Provides”Tenant Context
Section titled “Tenant Context”import { TenantContext, createTenantContext, getCurrentTenant, resolveTenant } from '@venturekit-pro/tenancy';
const tenant = getCurrentTenant(ctx);// { id: 'acme', slug: 'acme', metadata: { ... } }Middleware
Section titled “Middleware”import { createTenantMiddleware, createQuotaMiddleware } from '@venturekit-pro/tenancy';import type { IsolationConfig } from '@venturekit-pro/tenancy';
// `strategy` selects the **data** isolation model (shared tables vs schema vs// database). `resolution` selects how the tenant is identified per request.const isolation: IsolationConfig = { strategy: 'shared', resolution: 'subdomain' };
// `createTenantMiddleware()` requires `config` (resolution + isolation rules)// and `lookupTenant` (your tenant store). `createQuotaMiddleware()` requires// `quotaKey` and `checkUsage` (returns current usage for the quota).middleware: [ createTenantMiddleware({ config: isolation, lookupTenant: async (id) => loadTenant(id), }), createQuotaMiddleware({ quotaKey: 'apiRequests', checkUsage: async (tenantId) => getMonthlyUsage(tenantId), }),]Error Types
Section titled “Error Types”import { TenantNotFoundError, TenantSuspendedError, TenantInactiveError, QuotaExceededError } from '@venturekit-pro/tenancy';Quota Checking
Section titled “Quota Checking”import { checkQuotas } from '@venturekit-pro/tenancy';
// checkQuotas(tenantId, quotas, checkUsage)// quotas: TenantQuotas — a map of quotaKey → numeric limit// checkUsage: (tenantId, quotaKey) => Promise<number> — current usageawait checkQuotas( tenantId, { apiRequests: 10_000, storage: 5_000_000_000 }, async (id, quotaKey) => loadCurrentUsage(id, quotaKey),);Resolution Strategies
Section titled “Resolution Strategies”| Strategy | Source |
|---|---|
subdomain | acme.app.example.com |
custom_domain | app.acme.com (domain lookup via domainLookup) |
path | /t/acme/api/tasks |
header | X-Tenant-ID: acme (configurable via headerName) |
query | ?tenant=acme (configurable via queryParam) |
jwt | tenant_id claim (configurable via jwtClaim) |
custom | pluggable async resolver via customResolver |
Dependencies
Section titled “Dependencies”@venturekit/core— required
Related
Section titled “Related”- Multi-Tenancy Guide — setup walkthrough
- Middleware — composing with other middleware
- WebSockets — tenant-scoped messaging
- API Reference — full type documentation