MCPcopy Create free account
hub / github.com/Noumena-Network/code / getFeatureValueInternal

Function getFeatureValueInternal

src/services/analytics/growthbook.ts:796–846  ·  view source on GitHub ↗

* Get a feature value with a default fallback - blocks until initialized. * @internal Used by both deprecated and cached functions.

(
  feature: string,
  defaultValue: T,
  logExposure: boolean,
)

Source from the content-addressed store, hash-verified

794 * @internal Used by both deprecated and cached functions.
795 */
796async function getFeatureValueInternal<T>(
797 feature: string,
798 defaultValue: T,
799 logExposure: boolean,
800): Promise<T> {
801 const canonicalFeature = toCanonicalAnalyticsName(feature)
802 // Check env var overrides first (for eval harnesses)
803 const overrides = getEnvOverrides()
804 const override = getLegacyCompatibleValue(overrides ?? undefined, canonicalFeature)
805 if (override !== undefined) {
806 return override as T
807 }
808 const configOverrides = getConfigOverrides()
809 const configOverride = getLegacyCompatibleValue(configOverrides, canonicalFeature)
810 if (configOverride !== undefined) {
811 return configOverride as T
812 }
813
814 if (!isGrowthBookEnabled()) {
815 return defaultValue
816 }
817
818 const growthBookClient = await initializeGrowthBook()
819 if (!growthBookClient) {
820 return defaultValue
821 }
822
823 // Use cached remote eval values if available (workaround for SDK bug)
824 let result: T
825 const resolvedFeatureValue = getLegacyCompatibleValue(
826 Object.fromEntries(resolvedFeatureValues) as Record<string, unknown>,
827 canonicalFeature,
828 )
829 if (resolvedFeatureValue !== undefined) {
830 result = resolvedFeatureValue as T
831 } else {
832 result = growthBookClient.getFeatureValue(canonicalFeature, defaultValue) as T
833 }
834
835 // Log experiment exposure using stored experiment data
836 if (logExposure) {
837 logExposureForFeature(canonicalFeature)
838 }
839
840 if (isInternalBuild()) {
841 logForDebugging(
842 `GrowthBook: getFeatureValue("${canonicalFeature}") = ${jsonStringify(result)}`,
843 )
844 }
845 return result
846}
847
848/**
849 * @deprecated Use getFeatureValue_CACHED_MAY_BE_STALE instead, which is non-blocking.

Callers 2

Calls 9

toCanonicalAnalyticsNameFunction · 0.85
getEnvOverridesFunction · 0.85
getLegacyCompatibleValueFunction · 0.85
getConfigOverridesFunction · 0.85
isGrowthBookEnabledFunction · 0.85
logExposureForFeatureFunction · 0.85
isInternalBuildFunction · 0.85
jsonStringifyFunction · 0.85
logForDebuggingFunction · 0.50

Tested by

no test coverage detected