@happyvertical/smrt-features
v0.36.0
Published
Code-first feature flags and tenant-aware overrides for the SMRT framework
Maintainers
Readme
@happyvertical/smrt-features
Code-first feature flags for SMRT applications, with global, app-level, and tenant-hierarchy resolution.
Installation
pnpm add @happyvertical/smrt-featuresQuick start
import {
FeatureDefinition,
FeatureResolver,
FeatureSyncService,
} from '@happyvertical/smrt-features';
// 1. Sync code-defined feature definitions at startup
await FeatureSyncService.syncDefinitions({
manifest: [
{
key: 'commerce.invoice.draft-mode',
description: 'Allow users to save invoices as drafts before sending',
defaultEffect: 'enabled',
allowedScopes: ['global', 'tenant', 'user'],
},
// ...
],
});
// 2. Resolve at runtime
const enabled = await FeatureResolver.isEnabled('commerce.invoice.draft-mode', {
tenantId: currentTenantId,
userId: currentUserId,
});Resolution
Features resolve in this priority order:
- User override (most specific) —
FeatureOverriderow withscopeType: 'user'for the active user - Tenant override —
FeatureOverriderow withscopeType: 'tenant'. Walks the tenant hierarchy if@happyvertical/smrt-usersis installed. - Global override —
FeatureOverriderow withscopeType: 'global' - Code default — registered via
FeatureSyncServicefrom the manifest
The first match wins.
Storage
_smrt_feature_definitions— code-owned feature shape (default effect, allowed scopes, metadata)_smrt_feature_overrides— runtime overrides at any scope level
Documentation
- See
AGENTS.mdfor package-internal patterns - See
docs/standards.mdfor monorepo conventions - See
docs/architecture/for cross-package architecture
