-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathtest-types.ts
131 lines (110 loc) · 3.7 KB
/
test-types.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
// This file exists only so that we can run the TypeScript compiler in the CI build
// to validate our typings.d.ts file.
import * as ld from 'launchdarkly-js-sdk-common';
var userWithKeyOnly: ld.LDUser = { key: 'user' };
var anonUserWithNoKey: ld.LDUser = { anonymous: true };
var anonUserWithKey: ld.LDUser = { key: 'anon-user', anonymous: true };
var user: ld.LDContext = {
key: 'user',
name: 'name',
firstName: 'first',
lastName: 'last',
email: 'test@example.com',
avatar: 'http://avatar.url',
ip: '1.1.1.1',
country: 'us',
anonymous: true,
custom: {
'a': 's',
'b': true,
'c': 3,
'd': [ 'x', 'y' ],
'e': [ true, false ],
'f': [ 1, 2 ]
},
privateAttributeNames: [ 'name', 'email' ]
};
const hook: ld.Hook = {
getMetadata: () => ({
name: 'hook',
}),
beforeEvaluation(hookContext: ld.EvaluationSeriesContext, data: ld.EvaluationSeriesData): ld.EvaluationSeriesData {
return data;
},
afterEvaluation(hookContext: ld.EvaluationSeriesContext, data: ld.EvaluationSeriesData, detail: ld.LDEvaluationDetail): ld.EvaluationSeriesData {
return data;
},
beforeIdentify(hookContext: ld.IdentifySeriesContext, data: ld.IdentifySeriesData): ld.IdentifySeriesData {
return data;
},
afterIdentify(hookContext: ld.IdentifySeriesContext, data: ld.IdentifySeriesData, result: ld.IdentifySeriesResult): ld.IdentifySeriesData {
return data;
},
afterTrack(hookContext: ld.TrackSeriesContext): void {
}
};
const plugin: ld.LDPlugin = {
getMetadata: () => ({
name: 'plugin',
}),
register(client: ld.LDClientBase, environmentMetadata: ld.LDPluginEnvironmentMetadata): void {
},
getHooks(metadata: ld.LDPluginEnvironmentMetadata): ld.Hook[] {
return [];
},
};
var logger: ld.LDLogger = ld.commonBasicLogger({ level: 'info' });
var allBaseOptions: ld.LDOptionsBase = {
bootstrap: { },
baseUrl: '',
eventsUrl: '',
streamUrl: '',
streaming: true,
useReport: true,
sendLDHeaders: true,
requestHeaderTransform: (x) => x,
evaluationReasons: true,
sendEvents: true,
allAttributesPrivate: true,
privateAttributes: [ 'x' ],
sendEventsOnlyForVariation: true,
flushInterval: 1,
streamReconnectDelay: 1,
logger: logger,
application: {
version: 'version',
id: 'id'
},
hooks: [ hook ],
plugins: [ plugin ]
};
var client: ld.LDClientBase = {} as ld.LDClientBase; // wouldn't do this in real life, it's just so the following statements will compile
client.waitUntilReady().then(() => {});
client.waitForInitialization(5).then(() => {});
client.identify(user).then(() => {});
client.identify(user, undefined, () => {});
client.identify(user, 'hash').then(() => {});
var user: ld.LDContext = client.getContext();
client.flush(() => {});
client.flush().then(() => {});
var boolFlagValue: ld.LDFlagValue = client.variation('key', false);
var numberFlagValue: ld.LDFlagValue = client.variation('key', 2);
var stringFlagValue: ld.LDFlagValue = client.variation('key', 'default');
var jsonFlagValue: ld.LDFlagValue = client.variation('key', [ 'a', 'b' ]);
var detail: ld.LDEvaluationDetail = client.variationDetail('key', 'default');
var detailValue: ld.LDFlagValue = detail.value;
var detailIndex: number | undefined = detail.variationIndex;
var detailReason: ld.LDEvaluationReason | undefined = detail.reason;
client.setStreaming(true);
client.setStreaming();
function handleEvent() {}
client.on('event', handleEvent);
client.off('event', handleEvent);
client.track('event');
client.track('event', { someData: 'x' });
client.track('event', null, 3.5);
var flagSet: ld.LDFlagSet = client.allFlags();
var flagSetValue: ld.LDFlagValue = flagSet['key'];
client.close(() => {});
client.close().then(() => {});
var contextKeys = ld.getContextKeys(user);