Skip to content

Commit a9c3f56

Browse files
authored
feat: Update to provider 0.6.3. (#5)
* feat: Update to latest versions. * feat: Use github actions and hello-app format. (#6) * feat: Use github actions and hello-app format. Workflow dispatch. Try PR branch. Repository dispatch. On push Basic Use v4 action. Trick Basic * Update readme. * Number * More readme update.
1 parent b782923 commit a9c3f56

File tree

5 files changed

+52
-54
lines changed

5 files changed

+52
-54
lines changed

.circleci/config.yml

Lines changed: 0 additions & 38 deletions
This file was deleted.

.github/ci.yml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: Build and run
2+
on:
3+
schedule:
4+
# * is a special character in YAML so you have to quote this string
5+
- cron: '0 9 * * *'
6+
push:
7+
branches: [ main, 'feat/**' ]
8+
paths-ignore:
9+
- '**.md' # Do not need to run CI for markdown changes.
10+
pull_request:
11+
branches: [ main, 'feat/**' ]
12+
paths-ignore:
13+
- '**.md'
14+
15+
jobs:
16+
build-and-run:
17+
runs-on: ubuntu-latest
18+
19+
permissions:
20+
id-token: write # Needed if using OIDC to get release secrets.
21+
22+
steps:
23+
- uses: actions/checkout@v4
24+
25+
- uses: actions/setup-node@v4
26+
with:
27+
node-version: 20
28+
registry-url: 'https://registry.npmjs.org'
29+
30+
- name: Install dependencies
31+
run: npm i
32+
33+
- uses: launchdarkly/gh-actions/actions/verify-hello-app@verify-hello-app-v2.0.0
34+
with:
35+
use_server_key: true
36+
role_arn: ${{ vars.AWS_ROLE_ARN }}
37+
command: node index.js

README.md

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,13 @@ This sample is compatible with Node.js versions 14 and above.
1212

1313
1. Install dependencies using `npm install`.
1414

15-
2. Edit `index.js` and set the value of `sdkKey` to your LaunchDarkly SDK key. If there is an existing boolean feature flag in your LaunchDarkly project that you want to evaluate, set `featureFlagKey` to the flag key.
15+
2. Set the environment variable `LAUNCHDARKLY_SDK_KEY` to your LaunchDarkly SDK key. If there is an existing boolean feature flag in your LaunchDarkly project that you want to evaluate, set `LAUNCHDARKLY_FLAG_KEY` to the flag key; otherwise, a boolean flag of `sample-feature` will be assumed.
1616

17-
```
18-
const sdkKey = '1234567890abcdef';
19-
20-
const featureFlagKey = 'my-flag';
21-
```
17+
```bash
18+
export LAUNCHDARKLY_SDK_KEY="1234567890abcdef"
19+
export LAUNCHDARKLY_FLAG_KEY="my-boolean-flag"
20+
```
2221

2322
3. On the command line, run `npm start`
2423

25-
You should receive the message ”Feature flag ‘<flag key>’ is <true/false> for this user”.
24+
You should receive the message ”The ${featureFlagKey} feature flag evaluates to ${flagValue}”.

index.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ import { OpenFeature, ProviderEvents } from '@openfeature/server-sdk';
22
import { LaunchDarklyProvider } from '@launchdarkly/openfeature-node-server';
33

44
// Set sdkKey to your LaunchDarkly SDK key.
5-
const sdkKey = '';
5+
const sdkKey = process.env.LAUNCHDARKLY_SDK_KEY ?? '';
66

77
// Set featureFlagKey to the feature flag key you want to evaluate
8-
const featureFlagKey = 'my-boolean-flag';
8+
const featureFlagKey = process.env.LAUNCHDARKLY_FLAG_KEY ?? 'sample-feature';
99

1010
// Set up the context properties. This context should appear on your LaunchDarkly contexts dashboard
1111
// soon after you run the demo.
@@ -15,15 +15,15 @@ const context = {
1515
kind: 'user'
1616
};
1717

18-
OpenFeature.setProvider(new LaunchDarklyProvider(sdkKey));
18+
await OpenFeature.setProviderAndWait(new LaunchDarklyProvider(sdkKey));
1919

2020
OpenFeature.addHandler(ProviderEvents.Ready, async (_eventDetails) => {
2121
const client = OpenFeature.getClient();
2222

2323
const flagValue = await client.getBooleanValue(featureFlagKey, false, context);
24-
25-
console.log(`Feature flag '${featureFlagKey}' is ${flagValue} for this context`);
26-
24+
25+
console.log(`The ${featureFlagKey} feature flag evaluates to ${flagValue}`);
26+
2727
// Here we ensure that the SDK shuts down cleanly and has a chance to deliver analytics
2828
// events to LaunchDarkly before the program exits. If analytics events are not delivered,
2929
// the context properties and flag usage statistics will not appear on your dashboard. In a

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.5.0",
23-
"@openfeature/server-sdk": "^1.6.3",
24-
"@launchdarkly/node-server-sdk": ">= 9.0.1"
22+
"@launchdarkly/openfeature-node-server": "0.6.3",
23+
"@openfeature/server-sdk": "^1.14.0",
24+
"@launchdarkly/node-server-sdk": ">= 9.4.5"
2525
}
2626
}

0 commit comments

Comments
 (0)