Skip to content

Commit 05e4b2d

Browse files
authored
chore: Add release please. (#38)
feat: Update to OpenFeature SDK 1.14.0. feat: Require node 18 or greater.
1 parent 6b38e5a commit 05e4b2d

File tree

15 files changed

+173
-3926
lines changed

15 files changed

+173
-3926
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
name: Publish Documentation
2+
description: 'Publish documentation to github pages.'
3+
4+
inputs:
5+
github_token:
6+
description: 'The github token to use for committing'
7+
required: true
8+
9+
runs:
10+
using: composite
11+
steps:
12+
- uses: launchdarkly/gh-actions/actions/[email protected]
13+
name: 'Publish to Github pages'
14+
with:
15+
docs_path: docs
16+
github_token: ${{ inputs.github_token }}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name: Publish to NPM
2+
description: Publish an npm package.
3+
inputs:
4+
prerelease:
5+
description: 'Is this a prerelease. If so, then the latest tag will not be updated in npm.'
6+
required: false
7+
dry-run:
8+
description: 'Is this a dry run. If so no package will be published.'
9+
required: false
10+
11+
runs:
12+
using: composite
13+
steps:
14+
- name: Publish
15+
shell: bash
16+
run: |
17+
./scripts/publish-npm.sh
18+
env:
19+
LD_RELEASE_IS_PRERELEASE: ${{ inputs.prerelease }}
20+
LD_RELEASE_IS_DRYRUN: ${{ inputs.dry-run }}

.github/workflows/ci.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616
matrix:
1717
variations: [
1818
{os: ubuntu-latest, node: latest},
19-
{os: ubuntu-latest, node: 16},
19+
{os: ubuntu-latest, node: 18},
2020
{os: windows-latest, node: latest}
2121
]
2222

@@ -29,12 +29,12 @@ jobs:
2929
node-version: ${{ matrix.variations.node }}
3030
registry-url: 'https://registry.npmjs.org'
3131
- name: Install
32-
run: yarn
32+
run: npm install
3333
- name: Build
34-
run: yarn run build
34+
run: npm run build
3535
- name: Test
36-
run: yarn test
36+
run: npm test
3737
env:
3838
JEST_JUNIT_OUTPUT_FILE: "reports/junit/js-test-results.xml"
3939
- name: Lint
40-
run: yarn run lint
40+
run: npm run lint
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
name: Release Please
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
jobs:
9+
release-please:
10+
runs-on: ubuntu-latest
11+
outputs:
12+
release_created: ${{ steps.release.outputs.release_created }}
13+
steps:
14+
- uses: googleapis/release-please-action@v4
15+
id: release
16+
with:
17+
token: ${{secrets.GITHUB_TOKEN}}
18+
19+
publish-package:
20+
runs-on: ubuntu-latest
21+
needs: ['release-please']
22+
permissions:
23+
id-token: write
24+
contents: write
25+
if: ${{ needs.release-please.outputs.release_created == 'true' }}
26+
steps:
27+
- uses: actions/checkout@v4
28+
29+
- uses: actions/setup-node@v4
30+
with:
31+
node-version: 20.x
32+
registry-url: 'https://registry.npmjs.org'
33+
34+
- uses: launchdarkly/gh-actions/actions/[email protected]
35+
name: 'Get NPM token'
36+
with:
37+
aws_assume_role: ${{ vars.AWS_ROLE_ARN }}
38+
ssm_parameter_pairs: '/production/common/releasing/npm/token = NODE_AUTH_TOKEN'
39+
40+
- name: Install Dependencies
41+
run: npm install
42+
# Publishing will build because we have a prepublish script.
43+
44+
- id: publish-npm
45+
name: Publish NPM Package
46+
uses: ./.github/actions/publish-npm
47+
with:
48+
dry-run: 'false'
49+
prerelease: 'false'
50+
51+
- name: Build Documentation
52+
run: npm run doc
53+
54+
- id: publish-docs
55+
name: Publish Documentation
56+
uses: ./.github/actions/publish-docs
57+
with:
58+
github_token: ${{ secrets.GITHUB_TOKEN }}

.ldrelease/config.yml

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

.release-please-manifest.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
".": "0.5.1"
3+
}

README.md

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ This provider is a beta version and should not be considered ready for productio
1414

1515
## Supported Node versions
1616

17-
This version of the LaunchDarkly OpenFeature provider is compatible with Node.js versions 16 and above.
17+
This version of the LaunchDarkly OpenFeature provider is compatible with Node.js versions 18 and above.
1818

1919
## Getting started
2020

@@ -31,12 +31,20 @@ npm install @launchdarkly/openfeature-node-server
3131
import { OpenFeature } from '@openfeature/server-sdk';
3232
import { LaunchDarklyProvider } from '@launchdarkly/openfeature-node-server';
3333
34+
// The LaunchDarkly provider will use a 10 second timeout by default when waiting for the SDK
35+
// to initialize. This can be controlled by the optional third parameter to the LaunchDarklyProvider
36+
// constructor.
3437
const ldProvider = new LaunchDarklyProvider('<your-sdk-key>', {/* LDOptions here */});
38+
3539
OpenFeature.setProvider(ldProvider);
3640
41+
// Alternatively await OpenFeature.setProviderAndWait(ldProvider); can be used.
42+
// This eliminated the need to listen for the ready event, but the user should be careful to handle
43+
// any exceptions that are thrown.
44+
3745
// If you need access to the LDClient, then you can use ldProvider.getClient()
3846
39-
// Evaluations before the provider indicates it is ready may get default values with a
47+
// Evaluations before the provider indicates it is ready may get default values with a
4048
// CLIENT_NOT_READY reason.
4149
OpenFeature.addHandler(ProviderEvents.Ready, (eventDetails) => {
4250
const client = OpenFeature.getClient();
@@ -71,7 +79,7 @@ The `kind` attribute should be a string containing only contain ASCII letters, n
7179

7280
The OpenFeature specification allows for an optional targeting key, but LaunchDarkly requires a key for evaluation. A targeting key must be specified for each context being evaluated. It may be specified using either `targetingKey`, as it is in the OpenFeature specification, or `key`, which is the typical LaunchDarkly identifier for the targeting key. If a `targetingKey` and a `key` are specified, then the `targetingKey` will take precedence.
7381

74-
There are several other attributes which have special functionality within a single or multi-context.
82+
There are several other attributes which have special functionality within a single or multi-context.
7583
- A key of `privateAttributes`. Must be an array of string values. [Equivalent to '_meta.privateAttributes' in the SDK.](https://launchdarkly.github.io/node-server-sdk/interfaces/_launchdarkly_node_server_sdk_.LDContextMeta.html#privateAttributes)
7684
- A key of `anonymous`. Must be a boolean value. [Equivalent to 'anonymous' in the SDK.](https://launchdarkly.github.io/node-server-sdk/interfaces/_launchdarkly_node_server_sdk_.LDSingleKindContext.html#anonymous)
7785
- A key of `name`. Must be a string. [Equivalent to 'name' in the SDK.](https://launchdarkly.github.io/node-server-sdk/interfaces/_launchdarkly_node_server_sdk_.LDSingleKindContext.html#name)

__tests__/LaunchDarklyProvider.test.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,11 @@ it('can be initialized', async () => {
1515
const ldProvider = new LaunchDarklyProvider('sdk-key', { offline: true });
1616
await ldProvider.initialize({});
1717

18-
expect(ldProvider.status).toEqual(ProviderStatus.READY);
18+
await OpenFeature.setProviderAndWait(ldProvider);
19+
20+
const ofClient = OpenFeature.getClient();
21+
22+
expect(ofClient.providerStatus).toEqual(ProviderStatus.READY);
1923
await ldProvider.onClose();
2024
});
2125

@@ -30,15 +34,17 @@ it('can fail to initialize client', async () => {
3034
start: () => {
3135
setTimeout(() => errorHandler?.({ code: 401 } as any), 20);
3236
},
37+
close: () => {},
3338
}),
3439
sendEvents: false,
3540
});
3641
try {
37-
await ldProvider.initialize({});
42+
await OpenFeature.setProviderAndWait(ldProvider);
3843
} catch (e) {
3944
expect((e as Error).message).toEqual('Authentication failed. Double check your SDK key.');
4045
}
41-
expect(ldProvider.status).toEqual(ProviderStatus.ERROR);
46+
const ofClient = OpenFeature.getClient();
47+
expect(ofClient.providerStatus).toEqual(ProviderStatus.ERROR);
4248
});
4349

4450
it('emits events for flag changes', async () => {
@@ -66,10 +72,10 @@ describe('given a mock LaunchDarkly client', () => {
6672
let ldProvider: LaunchDarklyProvider;
6773
const logger: TestLogger = new TestLogger();
6874

69-
beforeEach(() => {
75+
beforeEach(async () => {
7076
ldProvider = new LaunchDarklyProvider('sdk-key', { logger, offline: true });
7177
ldClient = ldProvider.getClient();
72-
OpenFeature.setProvider(ldProvider);
78+
await OpenFeature.setProviderAndWait(ldProvider);
7379

7480
ofClient = OpenFeature.getClient();
7581
logger.reset();
@@ -283,7 +289,7 @@ describe('given a mock LaunchDarkly client', () => {
283289
errorKind: ldError,
284290
},
285291
}));
286-
const res = await ofClient.getObjectDetails(testFlagKey, {}, basicContext);
292+
const res = await ofClient.getObjectDetails(testFlagKey, { yes: 'no' }, basicContext);
287293
expect(res).toMatchObject({
288294
flagKey: testFlagKey,
289295
value: { yes: 'no' },

package.json

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
"lint:fix": "npm run lint -- --fix",
1212
"test": "jest",
1313
"coverage": "npm run test -- --coverage",
14-
"prepublishOnly": "npm run build"
14+
"prepublishOnly": "npm run build",
15+
"doc": "typedoc"
1516
},
1617
"keywords": [
1718
"launchdarkly",
@@ -20,11 +21,12 @@
2021
],
2122
"license": "Apache-2.0",
2223
"peerDependencies": {
23-
"@openfeature/server-sdk": "^1.6.3",
24-
"@launchdarkly/node-server-sdk": "9.x"
24+
"@launchdarkly/node-server-sdk": "9.x",
25+
"@openfeature/server-sdk": "^1.14.0"
2526
},
2627
"devDependencies": {
27-
"@openfeature/server-sdk": "^1.6.3",
28+
"@launchdarkly/node-server-sdk": "9.x",
29+
"@openfeature/server-sdk": "^1.14.0",
2830
"@types/jest": "^27.4.1",
2931
"@typescript-eslint/eslint-plugin": "^5.22.0",
3032
"@typescript-eslint/parser": "^5.22.0",
@@ -34,8 +36,8 @@
3436
"eslint-plugin-import": "^2.26.0",
3537
"jest": "^27.5.1",
3638
"jest-junit": "^14.0.1",
37-
"@launchdarkly/node-server-sdk": "9.x",
3839
"ts-jest": "^27.1.4",
40+
"typedoc": "^0.25.13",
3941
"typescript": "^4.7.4"
4042
}
4143
}

release-please-config.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"packages": {
3+
"bootstrap-sha": "6b38e5a3ddb23705fbaec8770e715b4ef5827223",
4+
".": {
5+
"release-type": "node",
6+
"bump-minor-pre-major": true
7+
}
8+
}
9+
}

0 commit comments

Comments
 (0)