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

    Class FeatureFlagReader

    Firebase-backed reader for feature flags, segments, and conditions.

    This class provides methods to fetch and subscribe to feature flag data from Firestore. it handles workspace fallbacks (global vs specific) and maintains an internal cache for performance.

    const reader = new FeatureFlagReader({
    db: firestoreInstance,
    workspace: 'production',
    userContext: { userId: 'user-123' }
    });

    const isEnabled = await reader.getFeatureFlag('new_feature').then(f => f?.getIsEnabled());

    Hierarchy (View Summary)

    Index

    Constructors

    Properties

    db: FirestoreDb
    prefetchPromise: Promise<unknown> | null
    Feature: typeof Feature

    Methods

    • Returns Promise<Record<string, FeatureCondition> | null>

    • Returns Promise<Record<string, ISegmentGroupClass> | null>

    • Fetches a named feature condition.

      Parameters

      • conditionName: string

        The name of the condition

      Returns Promise<FeatureCondition | null>

      The feature condition logic, or null if not found

    • Fetches a single feature flag by name.

      Parameters

      • flagName: string

        The unique name of the feature flag

      Returns Promise<Feature | null>

      A Feature instance for evaluation, or null if not found

    • Fetches a single archived feature flag.

      Parameters

      • flagName: string

        The unique name of the archived feature flag

      Returns Promise<Feature | null>

      A Feature instance, or null if not found

    • Fetches all active feature flags in the current workspace.

      Returns Promise<Record<string, Feature> | null>

      A record of flag names to Feature instances

    • Parameters

      • __namedParameters: { useCache: boolean }

      Returns Promise<Record<string, Feature> | null>

    • Fetches a segment group by name.

      Parameters

      • segmentName: string

        The name of the segment

      Returns Promise<SegmentGroup | null>

      A SegmentGroup instance, or null if not found

    • Type Parameters

      • T
      • D

      Parameters

      • collection: string
      • docName: string
      • factory: (key: string, data: D) => T
      • cache: Map<string, D>

      Returns Promise<T | null>

    • Type Parameters

      • T
      • D

      Parameters

      • collection: string
      • factory: (key: string, data: D) => T
      • cache: Map<string, D>
      • allLoaded: boolean
      • OptionaluseCache: boolean

      Returns Promise<Record<string, T> | null>

    • Parameters

      • onChange: (groups: Record<string, FeatureCondition>) => void
      • OptionalonError: (error: Error) => void

      Returns Unsubscribe

    • Parameters

      • onChange: (groups: Record<string, SegmentGroup>) => void
      • OptionalonError: (error: Error) => void

      Returns Unsubscribe

    • Parameters

      • conditionName: string
      • onChange: (conditon: FeatureCondition | null) => void
      • OptionalonError: (error: Error) => void

      Returns Unsubscribe

    • Subscribes to real-time updates for a single feature flag.

      Parameters

      • flagName: string

        Name of the flag to watch

      • onChange: (feature: Feature | null) => void

        Callback triggered when the flag data changes

      • OptionalonError: (error: Error) => void

        Optional error callback

      Returns Unsubscribe

      Unsubscribe function

    • Subscribes to real-time updates for all feature flags in the workspace.

      Parameters

      • onChange: (features: Record<string, Feature>) => void

        Callback triggered when any flag in the collection changes

      • OptionalonError: (error: Error) => void

        Optional error callback

      Returns Unsubscribe

      Unsubscribe function

    • Parameters

      • segmentName: string
      • onChange: (segmentGroup: SegmentGroup | null) => void
      • OptionalonError: (error: Error) => void

      Returns Unsubscribe