Pure, framework-agnostic feature flag evaluation engine for the Brave Ship system.
@farmart-tech/brave-feature-core is the core domain logic for evaluating feature flags. It handles complex targeting rules, user segmentation, and consistent hashing-based rollouts. It is designed to be lightweight and portable, running in browsers, Node.js, and edge environments.
allOf, anyOf) and custom user attributes.npm install @farmart-tech/brave-feature-core
# or
pnpm add @farmart-tech/brave-feature-core
import { Feature } from '@farmart-tech/brave-feature-core';
// 1. Define feature configuration (usually fetched from Brave Ship API/Firebase)
const featureData = {
enabled: true,
description: 'Enable dark mode',
rolloutStrategy: {
type: 'percentage',
config: { percentage: 50 }
}
};
// 2. Prepare evaluation context
const context = {
deviceContext: {
deviceID: 'unique-device-id',
devicePlatform: 'web',
deviceRegisteredAt: '2024-01-01T00:00:00Z',
environment: 'production'
},
userContext: {
userId: 'user-123',
customAttributes: { tier: 'premium' }
},
localFeatureContext: { /* local storage persistence adapter */ },
segmentContext: { get: async (name) => null },
featureContext: { get: async (name) => null },
conditionContext: { get: async (name) => null }
};
// 3. Evaluate
const feature = new Feature(featureData, context);
const isEnabled = await feature.getIsEnabled();
console.log(`Feature enabled: ${isEnabled}`);
import { FeatureBuilder, ConditionBuilder } from '@farmart-tech/brave-feature-core';
const featureConfig = new FeatureBuilder()
.setFeatureName('premium_dashboard')
.setEnabled(true)
.setCondition(
ConditionBuilder.allOf(
ConditionBuilder.condition('user.attributes.tier', '=', 'premium'),
ConditionBuilder.condition('device.platform', 'in', ['ios', 'android'])
)
)
.build();
Comprehensive API documentation is available at: https://fmt-feature-management.web.app/docs/feature-core/
MIT © FarMart