1
+ /**
2
+ * Copyright 2018, Optimizely
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ declare module '@optimizely/optimizely-sdk' {
18
+ import enums = require( '@optimizely/optimizely-sdk/lib/utils/enums' ) ;
19
+
20
+ export function createInstance ( config : Config ) : Client ;
21
+
22
+ // The options object given to Optimizely.createInstance.
23
+ export interface Config {
24
+ datafile : object ;
25
+ errorHandler ?: object ;
26
+ eventDispatcher ?: object ;
27
+ logger ?: object ;
28
+ logLevel ?: enums . LOG_LEVEL . DEBUG | enums . LOG_LEVEL . ERROR | enums . LOG_LEVEL . INFO | enums . LOG_LEVEL . NOTSET | enums . LOG_LEVEL . WARNING ;
29
+ skipJSONValidation ?: boolean ;
30
+ jsonSchemaValidator ?: object ;
31
+ userProfileService ?: UserProfileService | null ;
32
+ }
33
+
34
+ export interface Client {
35
+ notificationCenter : NotificationCenter ;
36
+ activate ( experimentKey : string , userId : string , attributes ?: UserAttributes ) : string | null ;
37
+ track ( eventKey : string , userId : string , attributes ?: UserAttributes , eventTags ?: EventTags ) : void ;
38
+ getVariation ( experimentKey : string , userId : string , attributes ?: UserAttributes ) : string | null ;
39
+ setForcedVariation ( experimentKey : string , userId : string , variationKey : string | null ) : boolean ;
40
+ getForcedVariation ( experimentKey : string , userId : string ) : string | null ;
41
+ isFeatureEnabled ( featureKey : string , userId : string , attributes ?: UserAttributes ) : boolean ;
42
+ getEnabledFeatures ( userId : string , attributes ?: UserAttributes ) : string [ ] ;
43
+ getFeatureVariableBoolean ( featureKey : string , variableKey : string , userId : string , attributes ?: UserAttributes ) : boolean | null ;
44
+ getFeatureVariableDouble ( featureKey : string , variableKey : string , userId : string , attributes ?: UserAttributes ) : number | null ;
45
+ getFeatureVariableInteger ( featureKey : string , variableKey : string , userId : string , attributes ?: UserAttributes ) : number | null ;
46
+ getFeatureVariableString ( featureKey : string , variableKey : string , userId : string , attributes ?: UserAttributes ) : string | null ;
47
+ }
48
+
49
+ // An event to be submitted to Optimizely, enabling tracking the reach and impact of
50
+ // tests and feature rollouts.
51
+ export interface Event {
52
+ // URL to which to send the HTTP request.
53
+ url : string ,
54
+ // HTTP method with which to send the event.
55
+ httpVerb : 'POST' ,
56
+ // Value to send in the request body, JSON-serialized.
57
+ params : any ,
58
+ }
59
+
60
+ export interface EventDispatcher {
61
+ /**
62
+ * @param event
63
+ * Event being submitted for eventual dispatch.
64
+ * @param callback
65
+ * After the event has at least been queued for dispatch, call this function to return
66
+ * control back to the Client.
67
+ */
68
+ dispatchEvent : ( event : Event , callback : ( ) => void ) => void ,
69
+ }
70
+
71
+ export interface UserProfileService {
72
+ lookup : ( userId : string ) => UserProfile ,
73
+ save : ( profile : UserProfile ) => void ,
74
+ }
75
+
76
+ // NotificationCenter-related types
77
+ export interface NotificationCenter {
78
+ addNotificationListener < T extends ListenerPayload > ( notificationType : string , callback : NotificationListener < T > ) : number ;
79
+ removeNotificationListener ( listenerId : number ) : boolean ;
80
+ clearAllNotificationListeners ( ) : void ;
81
+ clearNotificationListeners ( notificationType : enums . NOTIFICATION_TYPES ) : void ;
82
+ }
83
+
84
+ export type NotificationListener < T extends ListenerPayload > = ( notificationData : T ) => void ;
85
+
86
+ export interface ListenerPayload {
87
+ userId : string ;
88
+ attributes : UserAttributes ;
89
+ }
90
+
91
+ export interface ActivateListenerPayload extends ListenerPayload {
92
+ experiment : Experiment ;
93
+ variation : Variation ;
94
+ logEvent : Event ;
95
+ }
96
+
97
+ export type UserAttributes = {
98
+ [ name : string ] : string
99
+ } ;
100
+
101
+ export type EventTags = {
102
+ [ key : string ] : string | number | boolean ,
103
+ } ;
104
+
105
+ export interface TrackListenerPayload extends ListenerPayload {
106
+ eventKey : string ;
107
+ eventTags : EventTags ;
108
+ logEvent : Event ;
109
+ }
110
+
111
+ interface Experiment {
112
+ id : string ,
113
+ key : string ,
114
+ status : string ,
115
+ layerId : string ,
116
+ variations : Variation [ ] ,
117
+ trafficAllocation : Array < {
118
+ entityId : string ,
119
+ endOfRange : number ,
120
+ } > ,
121
+ audienceIds : string [ ] ,
122
+ forcedVariations : object ,
123
+ }
124
+
125
+ interface Variation {
126
+ id : string ,
127
+ key : string ,
128
+ }
129
+
130
+ export interface Logger {
131
+ log : ( logLevel : enums . LOG_LEVEL , message : string ) => void ,
132
+ }
133
+
134
+ // Information about past bucketing decisions for a user.
135
+ export interface UserProfile {
136
+ user_id : string ,
137
+ experiment_bucket_map : {
138
+ [ experiment_id : string ] : {
139
+ variation_id : string ,
140
+ } ,
141
+ } ,
142
+ }
143
+ }
144
+
145
+ declare module '@optimizely/optimizely-sdk/lib/utils/enums' {
146
+ export enum LOG_LEVEL {
147
+ NOTSET = 0 ,
148
+ DEBUG = 1 ,
149
+ INFO = 2 ,
150
+ WARNING = 3 ,
151
+ ERROR = 4 ,
152
+ }
153
+ export enum NOTIFICATION_TYPES {
154
+ ACTIVATE = 'ACTIVATE:experiment, user_id, attributes, variation, events' ,
155
+ TRACK = 'TRACK:event_key, user_id, attributes, event_tags, event' ,
156
+ }
157
+ }
158
+
159
+ declare module '@optimizely/optimizely-sdk/lib/plugins/event_dispatcher/index.node.js' {
160
+
161
+ }
162
+
163
+ declare module '@optimizely/optimizely-sdk/lib/utils/json_schema_validator' {
164
+
165
+ }
166
+
167
+ declare module '@optimizely/optimizely-sdk/lib/plugins/error_handler' {
168
+ }
169
+
170
+ declare module '@optimizely/optimizely-sdk/lib/plugins/logger' {
171
+ import * as Optimizely from '@optimizely/optimizely-sdk' ;
172
+ import * as enums from '@optimizely/optimizely-sdk/lib/utils/enums' ;
173
+
174
+ export interface Config {
175
+ logLevel ?: enums . LOG_LEVEL ,
176
+ logToConsole ?: boolean ,
177
+ prefix ?: string ,
178
+ }
179
+ export function createLogger ( config : Config ) : Optimizely . Logger ;
180
+ export function createNoOpLogger ( ) : Optimizely . Logger ;
181
+ }
0 commit comments