This repository was archived by the owner on Jun 21, 2023. It is now read-only.
forked from optimizely/javascript-sdk
-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathindex.d.ts
271 lines (236 loc) · 7.88 KB
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
/**
* Copyright 2018-2020, Optimizely
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
declare module '@optimizely/optimizely-sdk' {
import { LogHandler, ErrorHandler } from '@optimizely/js-sdk-logging';
import * as enums from '@optimizely/optimizely-sdk/lib/utils/enums';
import * as logging from '@optimizely/optimizely-sdk/lib/plugins/logger';
export { enums, logging };
export function setLogger(logger: LogHandler | null): void;
export function setLogLevel(level: enums.LOG_LEVEL | string): void;
export function createInstance(config: Config): Client;
export const errorHandler: ErrorHandler;
export const eventDispatcher: EventDispatcher;
interface DatafileOptions {
autoUpdate?: boolean;
updateInterval?: number;
urlTemplate?: string;
}
// The options object given to Optimizely.createInstance.
export interface Config {
datafile?: object | string;
datafileOptions?: DatafileOptions;
errorHandler?: ErrorHandler;
eventDispatcher?: EventDispatcher;
logger?: LogHandler;
logLevel?:
| enums.LOG_LEVEL.DEBUG
| enums.LOG_LEVEL.ERROR
| enums.LOG_LEVEL.INFO
| enums.LOG_LEVEL.NOTSET
| enums.LOG_LEVEL.WARNING;
skipJSONValidation?: boolean;
jsonSchemaValidator?: object;
userProfileService?: UserProfileService | null;
eventBatchSize?: number;
eventFlushInterval?: number;
sdkKey?: string;
}
export interface Client {
notificationCenter: NotificationCenter;
activate(experimentKey: string, userId: string, attributes?: UserAttributes): string | null;
track(eventKey: string, userId: string, attributes?: UserAttributes, eventTags?: EventTags): void;
getVariation(experimentKey: string, userId: string, attributes?: UserAttributes): string | null;
setForcedVariation(experimentKey: string, userId: string, variationKey: string | null): boolean;
getForcedVariation(experimentKey: string, userId: string): string | null;
isFeatureEnabled(featureKey: string, userId: string, attributes?: UserAttributes): boolean;
getEnabledFeatures(userId: string, attributes?: UserAttributes): string[];
getFeatureVariableBoolean(
featureKey: string,
variableKey: string,
userId: string,
attributes?: UserAttributes
): boolean | null;
getFeatureVariableDouble(
featureKey: string,
variableKey: string,
userId: string,
attributes?: UserAttributes
): number | null;
getFeatureVariableInteger(
featureKey: string,
variableKey: string,
userId: string,
attributes?: UserAttributes
): number | null;
getFeatureVariableString(
featureKey: string,
variableKey: string,
userId: string,
attributes?: UserAttributes
): string | null;
getOptimizelyConfig(): OptimizelyConfig | null;
onReady(options?: { timeout?: number }): Promise<{ success: boolean; reason?: string }>;
close(): Promise<{ success: boolean; reason?: string }>;
}
// An event to be submitted to Optimizely, enabling tracking the reach and impact of
// tests and feature rollouts.
export interface Event {
// URL to which to send the HTTP request.
url: string;
// HTTP method with which to send the event.
httpVerb: 'POST';
// Value to send in the request body, JSON-serialized.
params: any;
}
export interface EventDispatcher {
/**
* @param event
* Event being submitted for eventual dispatch.
* @param callback
* After the event has at least been queued for dispatch, call this function to return
* control back to the Client.
*/
dispatchEvent: (event: Event, callback: () => void) => void;
}
export interface UserProfileService {
lookup: (userId: string) => UserProfile;
save: (profile: UserProfile) => void;
}
// NotificationCenter-related types
export interface NotificationCenter {
addNotificationListener<T extends ListenerPayload>(
notificationType: string,
callback: NotificationListener<T>
): number;
removeNotificationListener(listenerId: number): boolean;
clearAllNotificationListeners(): void;
clearNotificationListeners(notificationType: enums.NOTIFICATION_TYPES): void;
}
export type NotificationListener<T extends ListenerPayload> = (notificationData: T) => void;
export interface ListenerPayload {
userId: string;
attributes: UserAttributes;
}
export interface ActivateListenerPayload extends ListenerPayload {
experiment: Experiment;
variation: Variation;
logEvent: Event;
}
export type UserAttributes = {
[name: string]: any;
};
export type EventTags = {
[key: string]: string | number | boolean;
};
export interface TrackListenerPayload extends ListenerPayload {
eventKey: string;
eventTags: EventTags;
logEvent: Event;
}
interface Experiment {
id: string;
key: string;
status: string;
layerId: string;
variations: Variation[];
trafficAllocation: Array<{
entityId: string;
endOfRange: number;
}>;
audienceIds: string[];
forcedVariations: object;
}
interface Variation {
id: string;
key: string;
}
// Information about past bucketing decisions for a user.
export interface UserProfile {
user_id: string;
experiment_bucket_map: {
[experiment_id: string]: {
variation_id: string;
};
};
}
/**
* Optimizely Config Entities
*/
export interface OptimizelyVariable {
id: string;
key: string;
type: string;
value: string;
}
export interface OptimizelyVariation {
id: string;
key: string;
featureEnabled?: boolean;
variablesMap: {
[variableKey: string]: OptimizelyVariable;
};
}
export interface OptimizelyExperiment {
id: string;
key: string;
variationsMap: {
[variationKey: string]: OptimizelyVariation;
};
}
export interface OptimizelyFeature {
id: string;
key: string;
experimentsMap: {
[experimentKey: string]: OptimizelyExperiment;
};
variablesMap: {
[variableKey: string]: OptimizelyVariable;
};
}
export interface OptimizelyConfig {
experimentsMap: {
[experimentKey: string]: OptimizelyExperiment;
};
featuresMap: {
[featureKey: string]: OptimizelyFeature;
};
revision: string;
}
}
declare module '@optimizely/optimizely-sdk/lib/utils/enums' {
import { LogLevel } from '@optimizely/js-sdk-logging';
export { LogLevel as LOG_LEVEL };
export enum NOTIFICATION_TYPES {
ACTIVATE = 'ACTIVATE:experiment, user_id,attributes, variation, event',
DECISION = 'DECISION:type, userId, attributes, decisionInfo',
OPTIMIZELY_CONFIG_UPDATE = 'OPTIMIZELY_CONFIG_UPDATE',
TRACK = 'TRACK:event_key, user_id, attributes, event_tags, event',
}
}
declare module '@optimizely/optimizely-sdk/lib/plugins/logger' {
import * as enums from '@optimizely/optimizely-sdk/lib/utils/enums';
import { LogHandler } from '@optimizely/js-sdk-logging';
export interface LoggerConfig {
logLevel?: enums.LOG_LEVEL;
logToConsole?: boolean;
prefix?: string;
}
export function createLogger(config?: LoggerConfig): LogHandler;
export function createNoOpLogger(): LogHandler;
}
declare module '@optimizely/optimizely-sdk/lib/plugins/event_dispatcher' {}
declare module '@optimizely/optimizely-sdk/lib/utils/json_schema_validator' {}
declare module '@optimizely/optimizely-sdk/lib/plugins/error_handler' {}