From 4e67d71f2831ff3bb283311b72d954f66973c6bc Mon Sep 17 00:00:00 2001 From: alexcardell <29524087+alexcardell@users.noreply.github.com> Date: Fri, 10 May 2024 16:07:39 +0100 Subject: [PATCH] Add string details client methods --- .../openfeature/EvaluationDetails.scala | 2 +- .../cardell/openfeature/FeatureClient.scala | 46 ++++++++++++++++--- 2 files changed, 41 insertions(+), 7 deletions(-) diff --git a/open-feature/sdk/src/main/scala/io/cardell/openfeature/EvaluationDetails.scala b/open-feature/sdk/src/main/scala/io/cardell/openfeature/EvaluationDetails.scala index abab4b2..9219894 100644 --- a/open-feature/sdk/src/main/scala/io/cardell/openfeature/EvaluationDetails.scala +++ b/open-feature/sdk/src/main/scala/io/cardell/openfeature/EvaluationDetails.scala @@ -23,7 +23,7 @@ object EvaluationDetails { flagKey = flagKey, value = resolution.value, errorCode = resolution.errorCode, - errorMessage = errorMessage.errorMessage, + errorMessage = resolution.errorMessage, reason = resolution.reason, variant = resolution.variant, metadata = resolution.metadata diff --git a/open-feature/sdk/src/main/scala/io/cardell/openfeature/FeatureClient.scala b/open-feature/sdk/src/main/scala/io/cardell/openfeature/FeatureClient.scala index 28e0424..0053f71 100644 --- a/open-feature/sdk/src/main/scala/io/cardell/openfeature/FeatureClient.scala +++ b/open-feature/sdk/src/main/scala/io/cardell/openfeature/FeatureClient.scala @@ -66,6 +66,22 @@ trait FeatureClient[F[_]] { options: EvaluationOptions ): F[String] + def getStringDetails( + flagKey: String, + default: String + ): F[EvaluationDetails[String]] + def getStringDetails( + flagKey: String, + default: String, + context: EvaluationContext + ): F[EvaluationDetails[String]] + def getStringDetails( + flagKey: String, + default: String, + context: EvaluationContext, + options: EvaluationOptions + ): F[EvaluationDetails[String]] + def getIntValue(flagKey: String, default: Int): F[Int] def getIntValue( flagKey: String, @@ -196,14 +212,32 @@ protected final class OpenFeatureClient[F[_]: Monad]( context: EvaluationContext, options: EvaluationOptions ): F[String] = - provider - .resolveStringValue( - flagKey, - default, - clientEvaluationContext ++ context - ) + getStringDetails(flagKey, default, context, EvaluationOptions.Defaults) .map(_.value) + override def getStringDetails( + flagKey: String, + default: String + ): F[EvaluationDetails[String]] = + getStringDetails(flagKey, default, EvaluationContext.empty) + + override def getStringDetails( + flagKey: String, + default: String, + context: EvaluationContext + ): F[EvaluationDetails[String]] = + getStringDetails(flagKey, default, context, EvaluationOptions.Defaults) + + override def getStringDetails( + flagKey: String, + default: String, + context: EvaluationContext, + options: EvaluationOptions + ): F[EvaluationDetails[String]] = + provider + .resolveStringValue(flagKey, default, clientEvaluationContext ++ context) + .map(EvaluationDetails[String](flagKey, _)) + override def getIntValue(flagKey: String, default: Int): F[Int] = getIntValue(flagKey, default, EvaluationContext.empty)