@farmart-tech/brave-feature-core
    Preparing search index...

    @farmart-tech/brave-feature-core

    @farmart-tech/brave-feature-core

    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.

    • 🚀 Performance: Ultra-fast evaluation with no external network calls.
    • 🎯 Targeting: Support for complex logical conditions (allOf, anyOf) and custom user attributes.
    • 📈 Rollouts: Consistent hashing-based percentage rollouts and time-based step rollouts.
    • 👥 Segmentation: Evaluate users against predefined segments (user lists, platforms, locations).
    • 🛡️ Type-Safe: Written in TypeScript with full type definitions for all configuration models.
    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