forked from launchdarkly/js-client-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest-types.ts
98 lines (82 loc) · 2.66 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
// This file exists only so that we can run the TypeScript compiler in the CI build
// to validate our typings.d.ts file. The code will not actually be run.
import * as ld from 'launchdarkly-js-client-sdk';
var ver: string = ld.version;
var emptyOptions: ld.LDOptions = {};
var logger: ld.LDLogger = ld.createConsoleLogger("info");
var allOptions: ld.LDOptions = {
bootstrap: { },
hash: '',
baseUrl: '',
eventsUrl: '',
streamUrl: '',
streaming: true,
useReport: true,
sendLDHeaders: true,
evaluationReasons: true,
fetchGoals: true,
sendEvents: true,
allAttributesPrivate: true,
privateAttributeNames: [ 'x' ],
allowFrequentDuplicateEvents: true,
sendEventsOnlyForVariation: true,
flushInterval: 1,
samplingInterval: 1,
streamReconnectDelay: 1,
eventUrlTransformer: url => url + 'x',
disableSyncEventPost: true,
logger: logger,
autoAliasingOptOut: true
};
var userWithKeyOnly: ld.LDUser = { key: 'user' };
var anonymousUser: ld.LDUser = { key: 'anon-user', anonymous: true };
var user: ld.LDUser = {
key: 'user',
name: 'name',
firstName: 'first',
lastName: 'last',
email: '[email protected]',
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' ]
};
var client: ld.LDClient = ld.initialize('env', user, allOptions);
client.waitUntilReady().then(() => {});
client.waitForInitialization().then(() => {});
client.waitUntilGoalsReady().then(() => {});
client.identify(user).then(() => {});
client.identify(user, undefined, () => {});
client.identify(user, 'hash').then(() => {});
client.alias(user, anonymousUser);
var user: ld.LDUser = client.getUser();
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 detail: ld.LDEvaluationDetail = client.variationDetail('key', 'default');
var detailValue: ld.LDFlagValue = detail.value;
var detailIndex: number | undefined = detail.variationIndex;
var detailReason: ld.LDEvaluationReason = 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(() => {});