@featbit/openfeature-provider-node-server 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/workflows/publish-npm.yml +24 -0
- package/LICENSE +21 -0
- package/README.md +60 -0
- package/examples/console-app/README.md +25 -0
- package/examples/console-app/package-lock.json +839 -0
- package/examples/console-app/package.json +21 -0
- package/examples/console-app/src/commonjs.cjs +30 -0
- package/examples/console-app/src/esm.ts +34 -0
- package/jest.config.js +7 -0
- package/package.json +36 -0
- package/src/FbProvider.ts +203 -0
- package/src/SafeLogger.ts +67 -0
- package/src/index.ts +6 -0
- package/src/translateContext.ts +40 -0
- package/src/translateResult.ts +42 -0
- package/tests/FbProvider.test.ts +294 -0
- package/tests/SafeLogger.test.ts +36 -0
- package/tests/TestLogger.ts +26 -0
- package/tests/translateContext.test.ts +102 -0
- package/tests/translateResult.test.ts +51 -0
- package/tsconfig.json +15 -0
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
name: Publish Package to npmjs
|
|
2
|
+
on:
|
|
3
|
+
workflow_dispatch:
|
|
4
|
+
release:
|
|
5
|
+
types: [published]
|
|
6
|
+
jobs:
|
|
7
|
+
build:
|
|
8
|
+
runs-on: ubuntu-latest
|
|
9
|
+
steps:
|
|
10
|
+
- uses: actions/checkout@v4
|
|
11
|
+
|
|
12
|
+
# Setup .npmrc file to publish to npm
|
|
13
|
+
- uses: actions/setup-node@v3
|
|
14
|
+
with:
|
|
15
|
+
node-version: '20.x'
|
|
16
|
+
registry-url: 'https://registry.npmjs.org'
|
|
17
|
+
|
|
18
|
+
- run: npm ci
|
|
19
|
+
|
|
20
|
+
- run: npm test
|
|
21
|
+
|
|
22
|
+
- run: npm publish --access=public
|
|
23
|
+
env:
|
|
24
|
+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 FeatBit
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
# FeatBit OpenFeature provider for Node.js SDK
|
|
2
|
+
|
|
3
|
+
## Introduction
|
|
4
|
+
|
|
5
|
+
This is the OpenFeature provider for the [Node.js Server-Side SDK](https://github.com/featbit/featbit-node-server-sdk) for the 100% open-source feature flags management platform [FeatBit](https://github.com/featbit/featbit).
|
|
6
|
+
|
|
7
|
+
The FeatBit OpenFeature provider is designed primarily for use in multi-user systems such as web servers and applications. It is not intended for use in desktop and embedded systems applications.
|
|
8
|
+
|
|
9
|
+
## Supported Node versions
|
|
10
|
+
|
|
11
|
+
This version of the FeatBit OpenFeature provider is compatible with Node.js versions 16 and above.
|
|
12
|
+
|
|
13
|
+
## Getting started
|
|
14
|
+
|
|
15
|
+
### Installation
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
npm install @openfeature/server-sdk
|
|
19
|
+
npm install @featbit/node-server-sdk
|
|
20
|
+
npm install @featbit/openfeature-provider-node-server
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
### Quick start
|
|
24
|
+
|
|
25
|
+
```js
|
|
26
|
+
import { OpenFeature, ProviderEvents } from '@openfeature/server-sdk';
|
|
27
|
+
import { FbProvider } from '@featbit/openfeature-provider-node-server';
|
|
28
|
+
|
|
29
|
+
const provider = new FbProvider({
|
|
30
|
+
sdkKey: '<your-sdk-key>',
|
|
31
|
+
streamingUri: '<your-streaming-uri>',
|
|
32
|
+
eventsUri: '<your-events-uri>'
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
OpenFeature.setProvider(provider);
|
|
36
|
+
|
|
37
|
+
// If you need access to the FbClient, then you can use provider.getClient()
|
|
38
|
+
|
|
39
|
+
// Evaluations before the provider indicates it is ready may get default values with a
|
|
40
|
+
// CLIENT_NOT_READY reason.
|
|
41
|
+
OpenFeature.addHandler(ProviderEvents.Ready, (eventDetails) => {
|
|
42
|
+
console.log(`Changed ${eventDetails.flagsChanged}`);
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
// The FeatBit provider supports the ProviderEvents.ConfigurationChanged event.
|
|
47
|
+
// The provider will emit this event for any flag key that may have changed (each event will contain
|
|
48
|
+
// a single key in the `flagsChanged` field).
|
|
49
|
+
OpenFeature.addHandler(ProviderEvents.ConfigurationChanged, async (eventDetails) => {
|
|
50
|
+
const client = OpenFeature.getClient();
|
|
51
|
+
const value = await client.getBooleanValue('ff1', false, {targetingKey: 'my-key'});
|
|
52
|
+
console.log({...eventDetails, value});
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
// (async () => {
|
|
56
|
+
// // When the FeatBit provider is closed it will flush the events on the FbClient instance.
|
|
57
|
+
// // This can be useful for short lived processes.
|
|
58
|
+
// await OpenFeature.close();
|
|
59
|
+
// })();
|
|
60
|
+
```
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# Console example for @featbit/openfeature-provider-node-server
|
|
2
|
+
|
|
3
|
+
## Introduction
|
|
4
|
+
The current example APP contains two files in src folder:
|
|
5
|
+
- `esm.ts`: example for using ES module and typescript.
|
|
6
|
+
- `commonjs.cjs`: example for using commonjs.
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
## Get started
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
npm install
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
### ES module
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
npm run esm
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
### CommonJs
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
npm run cjs
|
|
25
|
+
```
|