Skip to content

Commit 1127758

Browse files
authored
Update for node SDK 8.0.0 release. (#5)
1 parent 6d742ce commit 1127758

File tree

3 files changed

+16
-15
lines changed

3 files changed

+16
-15
lines changed

.circleci/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,4 @@ jobs:
3737
name: run demo
3838
command: |
3939
npm start | tee output.txt
40-
grep "is true for this user" output.txt || (echo "Flag did not evaluate to expected true value" && exit 1)
40+
grep "is true for this context" output.txt || (echo "Flag did not evaluate to expected true value" && exit 1)

index.ts

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
1-
import * as LaunchDarkly from 'launchdarkly-node-server-sdk';
1+
import * as LaunchDarkly from '@launchdarkly/node-server-sdk';
22

33
// Set sdkKey to your LaunchDarkly SDK key.
44
const sdkKey = "";
55

66
// Set featureFlagKey to the feature flag key you want to evaluate.
77
const featureFlagKey = "my-boolean-flag";
88

9-
// Set up the user properties. This use should appear on your LaunchDarkly
10-
// users dashboard soon after you run the demo.
11-
const user = {
12-
"name": "Sandy",
13-
"key": "example-user-key"
9+
// Set up the context properties. This use should appear on your LaunchDarkly
10+
// contexts dashboard soon after you run the demo.
11+
const context = {
12+
"kind": "user",
13+
"name": "Sandy",
14+
"key": "example-context-key"
1415
};
1516

1617
function showMessage(s: string) {
@@ -20,24 +21,24 @@ function showMessage(s: string) {
2021

2122
const client = LaunchDarkly.init(sdkKey);
2223

23-
client.once('ready', function() {
24+
client.once('ready', function () {
2425
showMessage("SDK successfully initialized!");
25-
client.variation(featureFlagKey, user, false, function(err, showFeature) {
26-
client.track("event-called", user);
26+
client.variation(featureFlagKey, context, false, function (err, showFeature) {
27+
client.track("event-called", context);
2728
if (showFeature) {
2829
// application code to show the feature
29-
showMessage("Feature flag '" + featureFlagKey + "' is true for this user");
30+
showMessage("Feature flag '" + featureFlagKey + "' is true for this context");
3031
} else {
3132
// the code to run if the feature is off
32-
showMessage("Feature flag '" + featureFlagKey + "' is false for this user");
33+
showMessage("Feature flag '" + featureFlagKey + "' is false for this context");
3334
}
3435

3536
// Here we ensure that the SDK shuts down cleanly and has a chance to deliver analytics
3637
// events to LaunchDarkly before the program exits. If analytics events are not delivered,
37-
// the user properties and flag usage statistics will not appear on your dashboard. In a
38+
// the context properties and flag usage statistics will not appear on your dashboard. In a
3839
// normal long-running application, the SDK would continue running and events would be
3940
// delivered automatically in the background.
40-
client.flush(function() {
41+
client.flush(function () {
4142
client.close();
4243
});
4344
});

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@
1414
"typescript": "2.4.1"
1515
},
1616
"dependencies": {
17-
"launchdarkly-node-server-sdk": "5.8.1"
17+
"@launchdarkly/node-server-sdk": ">= 8.0.0"
1818
}
1919
}

0 commit comments

Comments
 (0)