Repository navigation
Add evaluation detail methods, updated providers, update README - #22
Merged
Merged
Conversation
toddbaert
commented
Apr 13, 2022
Comment on lines
+69
to
+82
| * Flagsmith differentiates between flag activity and boolean flag values, so in this provider,`isEnabled` is NOT a proxy to `getBooleanValue`. | ||
| */ | ||
| async isEnabledEvaluation( | ||
| flagKey: string, | ||
| _defaultValue: boolean, | ||
| userId: string | undefined, | ||
| _options?: FlagEvaluationOptions | ||
| ): Promise<boolean> { | ||
| userId: string | undefined | ||
| ): Promise<ProviderEvaluation<boolean>> { | ||
| const value = userId | ||
| ? await flagsmith.hasFeature(flagId, userId) | ||
| : await flagsmith.hasFeature(flagId); | ||
| if (typeof value === 'boolean') { | ||
| return value; | ||
| } else { | ||
| throw new FlagTypeError( | ||
| this.getFlagTypeErrorMessage(flagId, value, 'boolean') | ||
| ); | ||
| } | ||
| ? await flagsmith.hasFeature(flagKey, userId) | ||
| : await flagsmith.hasFeature(flagKey); | ||
| return { | ||
| value, | ||
| reason: Reason.UNKNOWN, | ||
| }; |
Member
Author
There was a problem hiding this comment.
This is an important point generally. Some feature flag systems make a distinction between flag activity ("on" or "off") and flag boolean payloads. In other words, it's entirely possible that it's idiomatic for some providers to treat isEnabled() differently than getBooleanValue().
toddbaert
commented
Apr 13, 2022
toddbaert
commented
Apr 13, 2022
Comment on lines
+181
to
+197
| private mapReason(reason: LDEvaluationReason) { | ||
| switch (reason.kind) { | ||
| case 'OFF': | ||
| return Reason.DISABLED; | ||
| case 'FALLTHROUGH': | ||
| return Reason.DEFAULT; | ||
| case 'TARGET_MATCH': | ||
| return Reason.TARGETING_MATCH; | ||
| case 'RULE_MATCH': | ||
| return Reason.TARGETING_MATCH; | ||
| case 'PREREQUISITE_FAILED': | ||
| return Reason.DEFAULT; | ||
| case 'ERROR': | ||
| return Reason.ERROR; | ||
| default: | ||
| return Reason.UNKNOWN; | ||
| } |
Member
Author
There was a problem hiding this comment.
An attempt to reasonably map LD reasons to OpenFeature reasons. Ideally, later, most providers will support this additional data. For now, only LaunchDarkly provides this additional info in their SDK.
toddbaert
commented
Apr 13, 2022
toddbaert
force-pushed
the
detail-methods
branch
4 times, most recently
from
April 13, 2022 14:59
51975f9 to
8fb9e1c
Compare
toddbaert
force-pushed
the
detail-methods
branch
from
April 14, 2022 13:40
8fb9e1c to
3311e27
Compare
toddbaert
force-pushed
the
detail-methods
branch
from
April 14, 2022 15:10
3311e27 to
ac96261
Compare
justinabrahms
approved these changes
Apr 19, 2022
beeme1mr
approved these changes
Apr 19, 2022
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This is a first pass at an API for getting additional flag evaluation details (see here for the structure of the details and here for an example of one of the new methods).
Some, but not all providers are currently able to provide this additional metadata, so the presence of this data is "best effort". The precise semantics of the various properties are certainly up for discussion (the
errorCodesandreasonsfor example). The idea is to support mapping custom provider codes and errors to well-defined enumerations in OpenFeature (see the the mapping in the LaunchDarkly demo provider for example).Many of the field names in the
FlagEvaluationDetailsschema are also used in the proposed OTel semantics.I've also update the README in the root, which had become somewhat out of date.