A feature flag daemon with a Unix philosophy.
npm install @openfeature/web-sdk
npm install @openfeature/flagd-web-provider
The FlagdWebProvider
communicates with flagd via the connect protocol.
Option name | Type | Default | Description |
---|---|---|---|
host | string | sets the host used to connect to the flagd instance | |
pathPrefix | string | "" | sets the path at which the flagd gRPC service is available, for example: /api/flagd (optional) |
port | number | 443 | sets the port used to connect to the flagd instance |
tls | boolean | true | when set to true the provider will attempt to connect to flagd via https |
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. A negative value means no retries. |
maxDelay | number | 60000 | sets the maximum time in ms to wait between reconnect intervals |
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.
The FlagdWebProvider
receives events from flagd with changes. Combined with the event API in the web SDK, this allows for subscription to flag value changes in clients.
client.addHandler(ProviderEvents.Ready, () => {
// do something when the configuration has changed.
});
The FlagdWebProvider
evaluates flags in bulk, taking into account the evaluation context, and then caches them in memory for local evaluation.
The cache is invalidated when flag configuration change events are received.
OpenFeature.setProvider(
new FlagdWebProvider({
host: 'myapp.com',
port: 443,
tls: true,
maxRetries: 10,
maxDelay: 30000,
})
);
Run npx nx package flagd-web
to build the library.
NOTE: Buf must be installed to build locally.
Run npx nx test flagd-web
to execute the unit tests via Jest.