|
| 1 | +# flagd-web Provider for OpenFeature |
| 2 | + |
| 3 | + |
| 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