Skip to content

Commit bd83124

Browse files
feat: flagd-web provider (open-feature#142)
Signed-off-by: James-Milligan <[email protected]> Co-authored-by: Todd Baert <[email protected]> Signed-off-by: James-Milligan <[email protected]> Co-authored-by: James-Milligan <[email protected]>
1 parent 78dd3ea commit bd83124

37 files changed

+2115
-121
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ jobs:
1212
- uses: actions/checkout@v3
1313
with:
1414
fetch-depth: 0
15+
submodules: recursive
16+
1517
- uses: bufbuild/[email protected]
1618
with:
1719
version: '1.1.1'

.github/workflows/release-please.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ jobs:
2020
- name: Checkout Repository
2121
if: ${{ steps.release.outputs.releases_created }}
2222
uses: actions/checkout@v3
23+
with:
24+
fetch-depth: 0
25+
submodules: recursive
26+
2327
- uses: bufbuild/[email protected]
2428
with:
2529
version: "1.1.1"

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,8 @@ Thumbs.db
4040

4141
# generated files
4242
proto
43+
44+
45+
# yalc stuff
46+
.yalc
47+
yalc.lock

.gitmodules

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
[submodule "libs/providers/flagd/schemas"]
22
path = libs/providers/flagd/schemas
3-
url = https://github.com/open-feature/schemas
3+
url = https://github.com/open-feature/schemas.git
4+
[submodule "libs/providers/flagd-web/schemas"]
5+
path = libs/providers/flagd-web/schemas
6+
url = https://github.com/open-feature/schemas.git

.prettierrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
{
2+
"printWidth": 120,
23
"singleQuote": true
34
}

.release-please-manifest.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"libs/hooks/open-telemetry": "5.0.0",
33
"libs/providers/go-feature-flag": "0.5.0",
4-
"libs/providers/flagd": "0.7.0"
4+
"libs/providers/flagd": "0.7.0",
5+
"libs/providers/flagd-web": "0.1.0"
56
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
"presets": ["minify"]
2+
"presets": [["minify", { "builtIns": false }]]
33
}

libs/providers/flagd-web/.babelrc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"presets": [
3+
[
4+
"@nrwl/web/babel",
5+
{
6+
"useBuiltIns": "usage"
7+
}
8+
]
9+
]
10+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"extends": ["../../../.eslintrc.json"],
3+
"ignorePatterns": ["!**/*"],
4+
"overrides": [
5+
{
6+
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
7+
"rules": {}
8+
},
9+
{
10+
"files": ["*.ts", "*.tsx"],
11+
"rules": {}
12+
},
13+
{
14+
"files": ["*.js", "*.jsx"],
15+
"rules": {}
16+
}
17+
]
18+
}

libs/providers/flagd-web/README.md

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# flagd-web Provider for OpenFeature
2+
3+
![Experimental](https://img.shields.io/badge/experimental-breaking%20changes%20allowed-yellow)
4+
5+
A feature flag daemon with a Unix philosophy.
6+
7+
## Installation
8+
9+
:warning: This provider requires an experimental version of the JS-SDK:
10+
11+
```
12+
npm i @openfeature/js-sdk@1.0.99-experimental-55bf085fbdec8a76753b02b3efee8bec3eac53c0
13+
```
14+
15+
```sh
16+
npm install @openfeature/flagd-web-provider
17+
```
18+
19+
## Usage
20+
21+
The `FlagdWebProvider` communicates with flagd via the [connect protocol](https://buf.build/blog/connect-a-better-grpc).
22+
23+
### Reconnection
24+
25+
If the connection to the flagd instance fails, the provider will attempt to reconnect with an exponential back-off. The `maxDelay` and `maxRetries` can be specified to customize reconnect behavior.
26+
27+
### Event streaming
28+
29+
The `FlagdWebProvider` can be configured to receive events for flag changes. Combined with the event API in the JS SDK, this allows for subscription to flag value changes in clients.
30+
31+
### Caching
32+
33+
The `FlagdWebProvider` will cache resolve flag values based on the associated flag-key and context. Values are cached in localstorage. A TTL for cached values can be specified. If [event-streaming](#event-streaming) is enabled, the cache will be invalidated intelligently when flag configuration change events are received.
34+
35+
### Available options
36+
37+
| Option name | Type | Default | Description |
38+
| -------------- | ------- | --------- | ------------------------------------------------------------------------------------------------------------------ |
39+
| host | string | localhost | sets the host used to connect to the flagd instance |
40+
| port | number | 8013 | sets the port used to connect to the flagd instance |
41+
| tls | boolean | false | when set to true the provider will attempt to connect to flagd via https |
42+
| maxRetries | number | 0 | sets the maximum number of retries for a connection to be made to the flagd instance, a value of 0 means unlimited |
43+
| maxDelay | number | 60000 | sets the maximum time in ms to wait between reconnect intervals |
44+
| caching | boolean | true | when set to true the provider will use client side caching |
45+
| cacheTtl | number | 300 | sets the timeout in ms for items in the cache, a value of 0 disables the ttl |
46+
| eventStreaming | boolean | true | enables or disables streaming and event features. |
47+
48+
## Example
49+
50+
```typescript
51+
OpenFeature.setProvider(
52+
new FlagdWebProvider({
53+
host: 'localhost',
54+
port: 8013,
55+
tls: true,
56+
maxRetries: 10,
57+
maxDelay: 30000,
58+
cache: true,
59+
cacheTTL: 60000,
60+
})
61+
);
62+
```
63+
64+
## Building
65+
66+
Run `npx nx package providers-flagd-web` to build the library.
67+
68+
> NOTE: [Buf](https://docs.buf.build/installation) must be installed to build locally.
69+
70+
## Running unit tests
71+
72+
Run `npx nx test providers-flagd-web` to execute the unit tests via [Jest](https://jestjs.io).

0 commit comments

Comments
 (0)