import { FEATURE_FLAGS } from './constants' ; param distinctUserId param featureName returns export async function isFeatureFlagEnabled ( distinctUserId , featureName ) { console . log ( 'isFeatureEnabled' , distinctUserId , featureName ) ; const featureFlagValue = await getFeatureFlagVariant ( distinctUserId , featureName ) ; const featureEnabled = featureFlagValue ? true : false ; console . log ( 'featureEnabled' , featureEnabled ) ; return featureEnabled ; } param distinctUserId param featureName returns export async function getFeatureFlagVariant ( distinctUserId , featureName ) { console . log ( 'getFeatureFlagVariant' , distinctUserId , featureName ) ; const res = await fetch ( `${ process . env . NEXT_PUBLIC_POSTHOG_HOST }/decide?v=2` , { method : 'POST' , body : JSON . stringify ( { api_key : process . env . NEXT_PUBLIC_POSTHOG_PROJECT_API_KEY , distinct_id : distinctUserId , } ) , } ) ; if ( ! res . ok ) { throw new Error ( `Fetch request to retrieve the ${ featureName } flag status failed with: (${ res . status }) ${ res . statusText }` ) ; } const data = await res . json ( ) ; console . log ( data ) ; return data . featureFlags [ featureName ] ; }