@nestarc/feature-flag
DB-backed feature flags for NestJS + Prisma + PostgreSQL -- tenant-aware overrides, percentage rollouts, and zero external dependencies.
Features
- Database-backed -- flags stored in PostgreSQL via Prisma, no external service required
- Tenant / user / environment overrides -- granular control per tenant, user, or deployment environment
- Percentage rollouts -- deterministic hashing (murmurhash3) for consistent per-user bucketing
- Guard decorator --
@FeatureFlag()automatically gates routes and controllers - Bypass decorator --
@BypassFeatureFlag()exempts health checks and public endpoints - Programmatic evaluation --
isEnabled(),evaluateAll(), andfindByKey()for service-layer logic - Pluggable cache --
CacheAdapterinterface with built-inMemoryCacheAdapter(default) andRedisCacheAdapterv0.2.0 - Redis Pub/Sub -- cross-instance cache invalidation for horizontal scaling v0.2.0
- Admin REST API -- opt-in
FeatureFlagAdminModulewith mandatory guard injection v0.2.0 - Repository pattern --
FeatureFlagRepositoryinterface for custom persistence backends v0.2.0 - Tenant context provider -- automatic
@nestarc/tenancyintegration viaTenantContextProviderv0.2.0 - Event system -- optional integration with
@nestjs/event-emitterfor audit and observability - Testing utilities -- drop-in
TestFeatureFlagModulefor unit and integration tests
Installation
bash
npm install @nestarc/feature-flagPeer dependencies
bash
npm install @nestjs/common @nestjs/core @prisma/client rxjs reflect-metadataOptional
bash
# Required only if you enable emitEvents
npm install @nestjs/event-emitter
# Required only if you use RedisCacheAdapter
npm install ioredis