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

    Class Feature

    Represents a single feature flag and provides evaluation logic based on context.

    The Feature class is the core component for determining if a feature is enabled for a specific user or device, considering rollout strategies, conditions, and release dates.

    const feature = new Feature(featureData, context);
    const isEnabled = await feature.getIsEnabled();

    Implements

    Index

    Constructors

    Methods

    • Specific check for user registration date relative to feature release date.

      Returns Promise<boolean>

      Promise resolving to true if user registered before the feature release

      const isEarlyAdopter = await feature.didUserRegisterBeforeFeatureRelease();
      
    • Evaluates only the feature conditions.

      Returns Promise<ConditionEvaluationResult>

      Promise resolving to the condition evaluation result

      const result = await feature.evalateConditions();
      if (!result.success) {
      console.log('Failed condition:', result.failedCondition);
      }
    • Internal

      Internal recursive method to evaluate a complex condition.

      Parameters

      Returns Promise<ConditionEvaluationResult>

      Detailed condition evaluation result

    • Provides a full evaluation of the feature with detailed reasoning.

      Use this when you need to know why a feature is enabled or disabled, such as for debugging or in the feature flag playground.

      Returns Promise<FeatureEvaluationResult>

      Detailed evaluation result including reason, condition match status, etc.

      const details = await feature.evaluateWithDetails();
      console.log(`Feature enabled: ${details.isEnabled}. Reason: ${details.reason}`);
    • Internal

      Returns the device-level enabled status if set in local cache.

      Returns boolean | null

      True if enabled, false if disabled, null if not in cache

    • Core evaluation method to check if the feature is enabled for the current context.

      Considers enabled flag, release date, evaluation conditions, and rollout strategy.

      Returns Promise<boolean>

      Promise resolving to the final enabled status

      const isEnabled = await feature.getIsEnabled();
      
    • Internal

      Checks if the feature data came from the global workspace as a fallback.

      Returns boolean

      True if global data

    • Checks if the feature's release date has passed.

      Returns boolean

      True if release date is in the past or not set

      if (!feature.getIsReleaseDatePassed()) {
      console.log('Feature is not yet released');
      }
    • Internal

      Evaluates the rollout strategy specifically.

      Parameters

      • isBaselineRollout: boolean

        Whether to force 100% rollout (used when conditions are met but overflow is present)

      Returns Promise<
          {
              isEnabled: boolean;
              reason: string;
              rolloutApplied?: {
                  evaluatedValue?: number;
                  matchedStep?: { date: string; percentage: number };
                  type: "percentage" | "step" | null;
                  value: number;
              };
          },
      >

      Evaluation result with enabled status and reason

    • Internal

      Determines if the current rollout percentage configuration is invalid (over 100%).

      Returns boolean

      True if percentage exceeds 100

    • Updates the user context for the feature evaluation.

      Parameters

      • userContext: Partial<UserContext>

        Partial user context to update

      Returns void

      feature.updateUserContext({ customAttributes: { tier: 'premium' } });