@farmart-tech/brave-client-sdk
    Preparing search index...

    Interface 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();
    interface Feature {
        didUserRegisterBeforeFeatureRelease(): Promise<boolean>;
        evalateConditions(): Promise<ConditionEvaluationResult>;
        evaluateConditionWithDetails(
            condition: FeatureCondition,
        ): Promise<ConditionEvaluationResult>;
        evaluateInPlayground(
            options: { cleanupLocalFeatureCache: boolean },
        ): Promise<FeatureEvaluationResult>;
        evaluateWithDetails(): Promise<FeatureEvaluationResult>;
        getIsDeviceLevelEnabled(): boolean | null;
        getIsEnabled(): Promise<boolean>;
        getIsGlobal(): boolean;
        getIsReleaseDatePassed(): boolean;
        getRaw(): FeatureData;
        getRolloutEvaluation(
            isBaselineRollout: boolean,
        ): Promise<
            {
                isEnabled: boolean;
                reason: string;
                rolloutApplied?: {
                    evaluatedValue?: number;
                    matchedStep?: { date: string; percentage: number };
                    type: "percentage" | "step" | null;
                    value: number;
                };
            },
        >;
        hasPercentageOverflow(): boolean;
        updateDeviceContext(deviceContext: Partial<DeviceContext>): void;
        updateUserContext(userContext: Partial<UserContext>): void;
    }

    Implements

    • IFeatureClass
    Index

    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

    • Internal

      Specialized evaluation for the feature playground environment.

      Optionally cleans up local cache before evaluating.

      Parameters

      • options: { cleanupLocalFeatureCache: boolean }

        Playground options

      Returns Promise<FeatureEvaluationResult>

      Evaluation result with details

    • 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');
      }
    • Retrieves the raw feature configuration data.

      Returns FeatureData

      The feature flag data

    • 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 device context for the feature evaluation.

      Parameters

      • deviceContext: Partial<DeviceContext>

        Partial device context to update

      Returns void

      feature.updateDeviceContext({ appVersion: '2.5.0' });
      
    • Updates the user context for the feature evaluation.

      Parameters

      • userContext: Partial<UserContext>

        Partial user context to update

      Returns void

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