77 JsonValue ,
88 TargetingKeyMissingError ,
99 StandardResolutionReasons ,
10+ TrackingEventDetails ,
1011} from "@openfeature/server-sdk" ;
1112import type SplitIO from "@splitsoftware/splitio/types/splitio" ;
1213
@@ -53,16 +54,17 @@ export class OpenFeatureSplitProvider implements Provider {
5354 flagKey ,
5455 this . transformContext ( context )
5556 ) ;
57+ const treatment = details . value . toLowerCase ( ) ;
5658
57- if ( details . value === "on" || details . value === "true" ) {
59+ if ( treatment === "on" || treatment === "true" ) {
5860 return { ...details , value : true } ;
5961 }
6062
61- if ( details . value === "off" || details . value === "false" ) {
63+ if ( treatment === "off" || treatment === "false" ) {
6264 return { ...details , value : false } ;
6365 }
6466
65- throw new ParseError ( `Invalid boolean value for ${ details . value } ` ) ;
67+ throw new ParseError ( `Invalid boolean value for ${ treatment } ` ) ;
6668 }
6769
6870 async resolveStringEvaluation (
@@ -119,7 +121,7 @@ export class OpenFeatureSplitProvider implements Provider {
119121 if ( value === CONTROL_TREATMENT ) {
120122 throw new FlagNotFoundError ( CONTROL_VALUE_ERROR_MESSAGE ) ;
121123 }
122- const flagMetadata = config ? JSON . parse ( config ) : undefined ;
124+ const flagMetadata = { config : config ? config : '' } ;
123125 const details : ResolutionDetails < string > = {
124126 value : value ,
125127 variant : value ,
@@ -130,6 +132,44 @@ export class OpenFeatureSplitProvider implements Provider {
130132 }
131133 }
132134
135+ async track (
136+ trackingEventName : string ,
137+ context : EvaluationContext ,
138+ details : TrackingEventDetails
139+ ) : Promise < void > {
140+
141+ // targetingKey is always required
142+ const { targetingKey } = context ;
143+ if ( targetingKey == null || targetingKey === "" )
144+ throw new TargetingKeyMissingError ( ) ;
145+
146+ // eventName is always required
147+ if ( trackingEventName == null || trackingEventName === "" )
148+ throw new ParseError ( "Missing eventName, required to track" ) ;
149+
150+ // trafficType is always required
151+ const ttVal = context [ "trafficType" ] ;
152+ const trafficType =
153+ ttVal != null && typeof ttVal === "string" && ttVal . trim ( ) !== ""
154+ ? ttVal
155+ : null ;
156+ if ( trafficType == null || trafficType === "" )
157+ throw new ParseError ( "Missing trafficType variable, required to track" ) ;
158+
159+ let value ;
160+ let properties : SplitIO . Properties = { } ;
161+ if ( details != null ) {
162+ if ( details . value != null ) {
163+ value = details . value ;
164+ }
165+ if ( details . properties != null ) {
166+ properties = details . properties as SplitIO . Properties ;
167+ }
168+ }
169+
170+ this . client . track ( targetingKey , trafficType , trackingEventName , value , properties ) ;
171+ }
172+
133173 //Transform the context into an object useful for the Split API, an key string with arbitrary Split "Attributes".
134174 private transformContext ( context : EvaluationContext ) : Consumer {
135175 const { targetingKey, ...attributes } = context ;
0 commit comments