@@ -23,7 +23,7 @@ import { ErrorHandler, LogHandler, LogLevel, LoggerFacade } from './modules/logg
2323import { EventProcessor } from './modules/event_processor' ;
2424
2525import { NotificationCenter as NotificationCenterImpl } from './core/notification_center' ;
26- import { NOTIFICATION_TYPES } from './utils/enums' ;
26+ import { NOTIFICATION_TYPES , DECISION_NOTIFICATION_TYPES , DECISION_SOURCES } from './utils/enums' ;
2727
2828import { IOptimizelyUserContext as OptimizelyUserContext } from './optimizely_user_context' ;
2929
@@ -120,9 +120,93 @@ export interface ListenerPayload {
120120 attributes ?: UserAttributes ;
121121}
122122
123- export type NotificationListener < T extends ListenerPayload > = ( notificationData : T ) => void ;
123+ export type DecisionNotificationType = typeof DECISION_NOTIFICATION_TYPES [ keyof typeof DECISION_NOTIFICATION_TYPES ] ;
124+
125+ export type DecisionSource = typeof DECISION_SOURCES [ keyof typeof DECISION_SOURCES ] ;
126+
127+ export type DecisionSourceInfo = {
128+ experimentKey ?: string ;
129+ variationKey ?: string ;
130+ } ;
131+
132+ export type VariablesMap = { [ variableKey : string ] : unknown } ;
133+
134+ export type AbTestDecisionInfo = {
135+ experimentKey : string ;
136+ variationKey : string | null ;
137+ } ;
124138
125- // NotificationCenter-related types
139+ export type FeatureDecisionInfo = {
140+ featureKey : string ;
141+ featureEnabled : boolean ;
142+ source : DecisionSource ;
143+ sourceInfo : DecisionSourceInfo ;
144+ } ;
145+
146+ export type FeatureTestDecisionInfo = {
147+ experimentKey : string ;
148+ variationKey : string | null ;
149+ } ;
150+
151+ export type FeatureVariableDecisionInfo = {
152+ featureKey : string ;
153+ featureEnabled : boolean ;
154+ source : DecisionSource ;
155+ variableKey : string ;
156+ variableValue : FeatureVariableValue ;
157+ variableType : VariableType ;
158+ sourceInfo : DecisionSourceInfo ;
159+ } ;
160+
161+ export type AllFeatureVariablesDecisionInfo = {
162+ featureKey : string ;
163+ featureEnabled : boolean ;
164+ source : DecisionSource ;
165+ variableValues : VariablesMap ;
166+ sourceInfo : DecisionSourceInfo ;
167+ } ;
168+
169+ export type FlagDecisionInfo = {
170+ flagKey : string ;
171+ enabled : boolean ;
172+ variationKey : string | null ;
173+ ruleKey : string | null ;
174+ variables : VariablesMap ;
175+ reasons : string [ ] ;
176+ decisionEventDispatched : boolean ;
177+ experimentId ?: string ;
178+ variationId ?: string ;
179+ } ;
180+
181+ export type DecisionInfoMap = {
182+ [ DECISION_NOTIFICATION_TYPES . AB_TEST ] : AbTestDecisionInfo ;
183+ [ DECISION_NOTIFICATION_TYPES . FEATURE ] : FeatureDecisionInfo ;
184+ [ DECISION_NOTIFICATION_TYPES . FEATURE_TEST ] : FeatureTestDecisionInfo ;
185+ [ DECISION_NOTIFICATION_TYPES . FEATURE_VARIABLE ] : FeatureVariableDecisionInfo ;
186+ [ DECISION_NOTIFICATION_TYPES . ALL_FEATURE_VARIABLES ] : AllFeatureVariablesDecisionInfo ;
187+ [ DECISION_NOTIFICATION_TYPES . FLAG ] : FlagDecisionInfo ;
188+ } ;
189+
190+ export type DecisionListenerPayloadForType < T extends DecisionNotificationType > = ListenerPayload & {
191+ type : T ;
192+ decisionInfo : DecisionInfoMap [ T ] ;
193+ } ;
194+
195+ export type DecisionListenerPayload = {
196+ [ T in DecisionNotificationType ] : DecisionListenerPayloadForType < T > ;
197+ } [ DecisionNotificationType ] ;
198+
199+ export type LogEventListenerPayload = Event ;
200+
201+ export type NotificationPayloadMap = {
202+ [ NOTIFICATION_TYPES . ACTIVATE ] : ActivateListenerPayload ;
203+ [ NOTIFICATION_TYPES . DECISION ] : DecisionListenerPayload ;
204+ [ NOTIFICATION_TYPES . TRACK ] : TrackListenerPayload ;
205+ [ NOTIFICATION_TYPES . LOG_EVENT ] : LogEventListenerPayload ;
206+ [ NOTIFICATION_TYPES . OPTIMIZELY_CONFIG_UPDATE ] : undefined ;
207+ } ;
208+
209+ export type NotificationListener < T extends ListenerPayload > = ( notificationData : T ) => void ;
126210export interface NotificationCenter {
127211 addNotificationListener < T extends ListenerPayload > (
128212 notificationType : string ,
0 commit comments