Split OpenFeature Provider
npm install @splitsoftware/openfeature-js-split-provider``sh`
npm install @splitsoftware/openfeature-js-split-provider
sh
npm install @splitsoftware/splitio
npm install @openfeature/server-sdk
`$3
`js
const OpenFeature = require('@openfeature/server-sdk').OpenFeature;
const OpenFeatureSplitProvider = require('@splitsoftware/openfeature-js-split-provider').OpenFeatureSplitProvider;const authorizationKey = 'your auth key'
const provider = new OpenFeatureSplitProvider(authorizationKey);
OpenFeature.setProvider(provider);
`$3
`js
const OpenFeature = require('@openfeature/server-sdk').OpenFeature;
const SplitFactory = require('@splitsoftware/splitio').SplitFactory;
const OpenFeatureSplitProvider = require('@splitsoftware/openfeature-js-split-provider').OpenFeatureSplitProvider;const authorizationKey = 'your auth key'
const splitFactory = SplitFactory({core: {authorizationKey}});
const provider = new OpenFeatureSplitProvider(splitFactory);
OpenFeature.setProvider(provider);
`$3
`js
const OpenFeature = require('@openfeature/server-sdk').OpenFeature;
const SplitFactory = require('@splitsoftware/splitio').SplitFactory;
const OpenFeatureSplitProvider = require('@splitsoftware/openfeature-js-split-provider').OpenFeatureSplitProvider;const authorizationKey = 'your auth key'
const splitClient = SplitFactory({core: {authorizationKey}}).client();
const provider = new OpenFeatureSplitProvider({splitClient});
OpenFeature.setProvider(provider);
`Use of OpenFeature with Split
After the initial setup you can use OpenFeature according to their documentation.One important note is that the Split Provider requires a targeting key to be set. Often times this should be set when evaluating the value of a flag by setting an EvaluationContext which contains the targeting key. An example flag evaluation is
`js
const client = openFeature.getClient('CLIENT_NAME');const context: EvaluationContext = {
targetingKey: 'TARGETING_KEY',
};
const boolValue = await client.getBooleanValue('boolFlag', false, context);
`
If the same targeting key is used repeatedly, the evaluation context may be set at the client level
`js
const context: EvaluationContext = {
targetingKey: 'TARGETING_KEY',
};
client.setEvaluationContext(context)
`
or at the OpenFeatureAPI level
`js
const context: EvaluationContext = {
targetingKey: 'TARGETING_KEY',
};
OpenFeatureAPI.getInstance().setCtx(context)
`
If the context was set at the client or api level, it is not required to provide it during flag evaluation.Evaluate with details
Use the get*Details(...) APIs to get the value and rich context (variant, reason, error code, metadata). This provider includes the Split treatment config as a raw JSON string under flagMetadata["config"]`js
const booleanTreatment = await client.getBooleanDetails('boolFlag', false, context);const config = booleanTreatment.flagMetadata.config
`Tracking
To use track(eventName, context, details) you must provide:
- A non-blank
eventName.
- A context with:
- targetingKey (non-blank).
- trafficType (string, e.g. "user" or "account").Optional:
- details with:
-
value: numeric event value (defaults to 0).
- properties: map of attributes (prefer primitives: string/number/boolean/null).Example:
`js
const context = { targetingKey: 'user-123', trafficType: 'account' }
const details = { value: 19.99, plan: 'pro', coupon: 'WELCOME10' }client.track('checkout.completed', context, details)
``