@@ -20,6 +20,7 @@ type Consumer = {
2020} ;
2121
2222const CONTROL_VALUE_ERROR_MESSAGE = "Received the 'control' value from Split." ;
23+ const CONTROL_TREATMENT = "control" ;
2324
2425export class OpenFeatureSplitProvider implements Provider {
2526 metadata = {
@@ -53,32 +54,15 @@ export class OpenFeatureSplitProvider implements Provider {
5354 this . transformContext ( context )
5455 ) ;
5556
56- let value : boolean ;
57- switch ( details . value as unknown ) {
58- case "on" :
59- value = true ;
60- break ;
61- case "off" :
62- value = false ;
63- break ;
64- case "true" :
65- value = true ;
66- break ;
67- case "false" :
68- value = false ;
69- break ;
70- case true :
71- value = true ;
72- break ;
73- case false :
74- value = false ;
75- break ;
76- case "control" :
77- throw new FlagNotFoundError ( CONTROL_VALUE_ERROR_MESSAGE ) ;
78- default :
79- throw new ParseError ( `Invalid boolean value for ${ details . value } ` ) ;
57+ if ( details . value === "on" || details . value === "true" ) {
58+ return { ...details , value : true } ;
59+ }
60+
61+ if ( details . value === "off" || details . value === "false" ) {
62+ return { ...details , value : false } ;
8063 }
81- return { ...details , value } ;
64+
65+ throw new ParseError ( `Invalid boolean value for ${ details . value } ` ) ;
8266 }
8367
8468 async resolveStringEvaluation (
@@ -90,9 +74,6 @@ export class OpenFeatureSplitProvider implements Provider {
9074 flagKey ,
9175 this . transformContext ( context )
9276 ) ;
93- if ( details . value === "control" ) {
94- throw new FlagNotFoundError ( CONTROL_VALUE_ERROR_MESSAGE ) ;
95- }
9677 return details ;
9778 }
9879
@@ -130,14 +111,19 @@ export class OpenFeatureSplitProvider implements Provider {
130111 ) ;
131112 } else {
132113 await this . initialized ;
133- const value = this . client . getTreatment (
114+ const { treatment : value , config } : SplitIO . TreatmentWithConfig = this . client . getTreatmentWithConfig (
134115 consumer . key ,
135116 flagKey ,
136117 consumer . attributes
137118 ) ;
119+ if ( value === CONTROL_TREATMENT ) {
120+ throw new FlagNotFoundError ( CONTROL_VALUE_ERROR_MESSAGE ) ;
121+ }
122+ const flagMetadata = config ? JSON . parse ( config ) : undefined ;
138123 const details : ResolutionDetails < string > = {
139124 value : value ,
140125 variant : value ,
126+ flagMetadata : flagMetadata ,
141127 reason : StandardResolutionReasons . TARGETING_MATCH ,
142128 } ;
143129 return details ;
0 commit comments