-
Notifications
You must be signed in to change notification settings - Fork 1
/
client.js
52 lines (40 loc) · 1.03 KB
/
client.js
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
require('dotenv').config();
const relayHost = process.argv[2];
// Client setup
const LaunchDarkly = require('launchdarkly-node-server-sdk');
const config = {
baseUri: relayHost,
streamUri: relayHost
}
const client = LaunchDarkly.init(process.env.LD_SDK_KEY, config);
// User setup
const ldUser = {
key: 'anon',
anonymous: true
}
const printFlags = async () => {
let allFlags = await client.allFlagsState(ldUser, { withReasons: true });
printDetails(allFlags.allValues());
}
const printDetails = async (flagObj) => {
const keys = Object.keys(flagObj);
for (key of keys) {
let variation = await client.variationDetail(key, ldUser, false);
console.log(key.toUpperCase() + '\n' + JSON.stringify(variation));
}
}
// Listen for flag changes
const main = async () => {
try {
await client.waitForInitialization();
printFlags();
// Print any updates
client.on('update', () => {
console.log('===================');
printFlags();
});
} catch (err) {
console.error(err);
}
}
main();