Skip to content

Commit b782923

Browse files
authored
feat: Update to work with latest OpenFeature provider release. (#4)
* feat: Update to work with latest OpenFeature provider release. * feat: Update to work with latest OpenFeature provider release.
1 parent ebed9ec commit b782923

File tree

2 files changed

+20
-22
lines changed

2 files changed

+20
-22
lines changed

index.js

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import { OpenFeature } from '@openfeature/js-sdk';
2-
import { init } from 'launchdarkly-node-server-sdk';
1+
import { OpenFeature, ProviderEvents } from '@openfeature/server-sdk';
32
import { LaunchDarklyProvider } from '@launchdarkly/openfeature-node-server';
43

54
// Set sdkKey to your LaunchDarkly SDK key.
@@ -16,20 +15,19 @@ const context = {
1615
kind: 'user'
1716
};
1817

19-
const ldClient = init(sdkKey);
20-
await ldClient.waitForInitialization();
21-
22-
OpenFeature.setProvider(new LaunchDarklyProvider(ldClient));
23-
const client = OpenFeature.getClient();
24-
25-
const flagValue = await client.getBooleanValue(featureFlagKey, false, context);
26-
27-
console.log(`Feature flag '${featureFlagKey}' is ${flagValue} for this context`);
28-
29-
// Here we ensure that the SDK shuts down cleanly and has a chance to deliver analytics
30-
// events to LaunchDarkly before the program exits. If analytics events are not delivered,
31-
// the context properties and flag usage statistics will not appear on your dashboard. In a
32-
// normal long-running application, the SDK would continue running and events would be
33-
// delivered automatically in the background.
34-
await ldClient.flush();
35-
ldClient.close();
18+
OpenFeature.setProvider(new LaunchDarklyProvider(sdkKey));
19+
20+
OpenFeature.addHandler(ProviderEvents.Ready, async (_eventDetails) => {
21+
const client = OpenFeature.getClient();
22+
23+
const flagValue = await client.getBooleanValue(featureFlagKey, false, context);
24+
25+
console.log(`Feature flag '${featureFlagKey}' is ${flagValue} for this context`);
26+
27+
// Here we ensure that the SDK shuts down cleanly and has a chance to deliver analytics
28+
// events to LaunchDarkly before the program exits. If analytics events are not delivered,
29+
// the context properties and flag usage statistics will not appear on your dashboard. In a
30+
// normal long-running application, the SDK would continue running and events would be
31+
// delivered automatically in the background.
32+
await OpenFeature.close();
33+
});

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
"author": "LaunchDarkly <team@launchdarkly.com>",
2020
"license": "Apache-2.0",
2121
"dependencies": {
22-
"@launchdarkly/openfeature-node-server": "0.3.0",
23-
"@openfeature/js-sdk": "^1.x",
24-
"launchdarkly-node-server-sdk": ">= 7.0.1"
22+
"@launchdarkly/openfeature-node-server": "0.5.0",
23+
"@openfeature/server-sdk": "^1.6.3",
24+
"@launchdarkly/node-server-sdk": ">= 9.0.1"
2525
}
2626
}

0 commit comments

Comments
 (0)