0.0.29 • Published 5 months ago
@vtex/openfeature-featurehub-client v0.0.29
FeatureHub Provider for OpenFeature
This project provides a FeatureHub provider for the OpenFeature SDK. It allows you to use FeatureHub as a feature flag management system with OpenFeature.
Getting Started
Prerequisites
- Node.js
- npm or yarn
Installation
- Install the dependencies:
npm install @openfeature/featurehub-provider
- Create a .env file based on the .env.sample file and fill in your FeatureHub Edge URL and API key:
cp .env.sample .env
Usage
To use the FeatureHub provider in your project, you need to import and set it as the provider for OpenFeature:
import { FeaturehubClientProvider } from '@openfeature/featurehub-client-provider'
//or
const { FeaturehubClientProvider } = require('@openfeature/featurehub-client-provider');
const provider = new FeaturehubClientProvider();
You can then use the OpenFeature API to evaluate feature flags:
const context = {
targetingKey: 'mytargetingKey',
country: 'Brazil',
account: 'myaccount'
};
const booleanFlag = await provider.resolveBooleanEvaluation('booleanFlag', true, context);
const stringFlag = await provider.resolveStringEvaluation('stringFlag', 'default', context);
const numberFlag = await provider.resolveNumberEvaluation('numberFlag', 0, context);
const jsonFlag = await provider.resolveObjectEvaluation('jsonFlag', { default: 'value' }, context);
Environment Variables
Add to tag:
<meta name="featurehub-url" content="https://featurehub.url" />
<meta name="featurehub-apiKey" content="apiKey" />
<meta name="featurehub-interval" content="15000" />