@featurevisor/openfeature-provider-web
v3.8.0
Published
OpenFeature provider for Featurevisor in browsers
Maintainers
Readme
Featurevisor OpenFeature provider for browsers
Use Featurevisor through the OpenFeature Web SDK in browser applications.
Installation
npm install @featurevisor/openfeature-provider-web @openfeature/web-sdkUsage
import { OpenFeature } from '@openfeature/web-sdk'
import { FeaturevisorOpenFeatureProvider } from '@featurevisor/openfeature-provider-web'
const provider = new FeaturevisorOpenFeatureProvider({ datafile })
await OpenFeature.setProviderAndWait(provider)
await OpenFeature.setContext({ targetingKey: 'user-123', country: 'nl' })
const client = OpenFeature.getClient()
const enabled = client.getBooleanValue('checkout', false)OpenFeature keys map to Featurevisor evaluations:
| Key | Evaluation |
| ----------------------- | ------------------------------------ |
| checkout | flag |
| checkout:variation | variation |
| checkout:title | variable named title |
| variable:supportEmail | global variable named supportEmail |
Use the resolver matching the Featurevisor value type. Boolean variables use the boolean resolver with a suffixed key. Arrays, objects, and JSON variables use the object resolver.
The provider maps OpenFeature targetingKey to Featurevisor userId by default. Configure targetingKeyField, keySeparator, variationKey, or globalVariablePrefix when your project needs different names. The global variable prefix defaults to variable.
Featurevisor instance
The provider can create and own a Featurevisor instance, or reuse one created by your application.
Let the provider create the instance
Pass normal Featurevisor options to the provider:
const provider = new FeaturevisorOpenFeatureProvider({
datafile,
modules,
onDiagnostic,
})The provider exposes the created instance as provider.featurevisor. You can use it for datafile updates, events, diagnostics, and other Featurevisor APIs. When OpenFeature closes the provider, the provider closes this instance and releases its resources.
Reuse an existing instance
Pass an instance created with createFeaturevisor() using the featurevisor option:
import { OpenFeature } from '@openfeature/web-sdk'
import { createFeaturevisor } from '@featurevisor/sdk'
import { FeaturevisorOpenFeatureProvider } from '@featurevisor/openfeature-provider-web'
const featurevisor = createFeaturevisor({ datafile })
const provider = new FeaturevisorOpenFeatureProvider({ featurevisor })
await OpenFeature.setProviderAndWait(provider)The same instance is available as provider.featurevisor. Evaluations, datafile updates, modules, diagnostics, and events continue to use that instance.
An instance passed this way remains owned by your application. Closing the OpenFeature provider does not close it, so other consumers can continue using it. Call featurevisor.close() when every consumer is finished.
If featurevisor and Featurevisor construction options such as datafile or modules are supplied together, the existing instance takes precedence and the construction options are ignored. Provider options such as targetingKeyField, keySeparator, variationKey, globalVariablePrefix, and onTrack still apply.
See Featurevisor OpenFeature documentation for reasons, errors, metadata, tracking, lifecycle, and other language providers.
License
MIT © Fahad Heylaal
