Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -105,5 +105,5 @@ dist

# Build output
es/
lib/
/lib/
types/
92 changes: 49 additions & 43 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Split OpenFeature Provider for NodeJS
# Split Provider for OpenFeature Web SDK
[![Twitter Follow](https://img.shields.io/twitter/follow/splitsoftware.svg?style=social&label=Follow&maxAge=1529000)](https://twitter.com/intent/follow?screen_name=splitsoftware)

## Overview
Expand All @@ -8,63 +8,70 @@ This Provider is designed to allow the use of OpenFeature with Split, the platfo


## Getting started
Below is a simple example that describes the instantiation of the Split Provider. Please see the [OpenFeature Documentation](https://docs.openfeature.dev/docs/reference/concepts/evaluation-api) for details on how to use the OpenFeature SDK.
Below is a simple example that describes the instantiation of the Split Provider for the OpenFeature Web SDK. Please see the [OpenFeature Documentation](https://openfeature.dev/docs/reference/technologies/client/web) for details on how to use the OpenFeature Web SDK.

### Add the Split provider
### Confirm peer dependencies are installed

```sh
npm install @splitsoftware/openfeature-js-split-provider
npm install @splitsoftware/splitio
npm install @openfeature/web-sdk
```

### Confirm peer dependencies are installed
### Add the Split provider

```sh
npm install @splitsoftware/splitio
npm install @openfeature/server-sdk
npm install @splitsoftware/openfeature-web-split-provider
```

### Register the Split provider with OpenFeature

```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);
import { OpenFeature } from '@openfeature/web-sdk';
import { SplitFactory } from '@splitsoftware/splitio';
import { OpenFeatureSplitProvider } from '@splitsoftware/openfeature-web-split-provider';

const authorizationKey = 'your client-side SDK key';
const targetingKey = 'your-targeting-key';

const splitFactory = SplitFactory({
core: {
authorizationKey,
key: targetingKey
}
});
const provider = new OpenFeatureSplitProvider({splitFactory});

// Wait for the default Split client for 'your-targeting-key' to be ready
await OpenFeature.setProviderAndWait(provider);
```

## Use of OpenFeature with Split
After the initial setup you can use OpenFeature according to their [documentation](https://docs.openfeature.dev/docs/reference/concepts/evaluation-api/).
After the initial setup you can use OpenFeature according to their [documentation for OpenFeature Web SDK](https://openfeature.dev/docs/reference/technologies/client/web).

One important note is that, unlike our [OpenFeature Provider for Node.js](https://github.com/splitio/split-openfeature-provider-js), the SplitFactory **requires a targeting key** to be set, which is provided in the `key` property of the `core` configuration object. This key is then used to evaluate flag values.

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](https://docs.openfeature.dev/docs/reference/concepts/evaluation-context) which contains the targeting key. An example flag evaluation is
```js
const client = openFeature.getClient('CLIENT_NAME');
const client = OpenFeature.getClient();

const context: EvaluationContext = {
targetingKey: 'TARGETING_KEY',
};
const boolValue = await client.getBooleanValue('boolFlag', false, context);
const boolValue = client.getBooleanValue('boolFlag', false);
```
If the same targeting key is used repeatedly, the evaluation context may be set at the client level

If a different targeting key is required, the evaluation context may be set using the `OpenFeature.setContext` method:
```js
const context: EvaluationContext = {
targetingKey: 'TARGETING_KEY',
targetingKey: 'new-targeting-key',
};
client.setEvaluationContext(context)

// Wait for 'new-targeting-key' to be ready. Internally this will replace the current Split client for the provided key
await OpenFeature.setContext(context)

// Evaluate flags for 'new-targeting-key'
const boolValue = client.getBooleanValue('boolFlag', false);
```
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.

## Submitting issues
The Split team monitors all issues submitted to this [issue tracker](https://github.com/splitio/split-openfeature-provider-nodejs/issues). We encourage you to use this issue tracker to submit any bug reports, feedback, and feature enhancements. We'll do our best to respond in a timely manner.

The Split team monitors all issues submitted to this [issue tracker](https://github.com/splitio/split-openfeature-provider-web-js/issues). We encourage you to use this issue tracker to submit any bug reports, feedback, and feature enhancements. We'll do our best to respond in a timely manner.

## Contributing
Please see [Contributors Guide](CONTRIBUTORS-GUIDE.md) to find all you need to submit a Pull Request (PR).
Expand All @@ -73,13 +80,13 @@ Please see [Contributors Guide](CONTRIBUTORS-GUIDE.md) to find all you need to s
Licensed under the Apache License, Version 2.0. See: [Apache License](http://www.apache.org/licenses/).

## About Split

Split is the leading Feature Delivery Platform for engineering teams that want to confidently deploy features as fast as they can develop them. Split’s fine-grained management, real-time monitoring, and data-driven experimentation ensure that new features will improve the customer experience without breaking or degrading performance. Companies like Twilio, Salesforce, GoDaddy and WePay trust Split to power their feature delivery.

To learn more about Split, contact hello@split.io, or get started with feature flags for free at https://www.split.io/signup.

Split has built and maintains SDKs for:

* Java [Github](https://github.com/splitio/java-client) [Docs](https://help.split.io/hc/en-us/articles/360020405151-Java-SDK)
* Javascript [Github](https://github.com/splitio/javascript-client) [Docs](https://help.split.io/hc/en-us/articles/360020448791-JavaScript-SDK)
* Node [Github](https://github.com/splitio/javascript-client) [Docs](https://help.split.io/hc/en-us/articles/360020564931-Node-js-SDK)
Expand All @@ -90,10 +97,9 @@ Split has built and maintains SDKs for:
* GO [Github](https://github.com/splitio/go-client) [Docs](https://help.split.io/hc/en-us/articles/360020093652-Go-SDK)
* Android [Github](https://github.com/splitio/android-client) [Docs](https://help.split.io/hc/en-us/articles/360020343291-Android-SDK)
* iOS [Github](https://github.com/splitio/ios-client) [Docs](https://help.split.io/hc/en-us/articles/360020401491-iOS-SDK)

For a comprehensive list of open source projects visit our [Github page](https://github.com/splitio?utf8=%E2%9C%93&query=%20only%3Apublic%20).

**Learn more about Split:**

Visit [split.io/product](https://www.split.io/product) for an overview of Split, or visit our documentation at [help.split.io](http://help.split.io) for more detailed information.

Visit [split.io/product](https://www.split.io/product) for an overview of Split, or visit our documentation at [help.split.io](http://help.split.io) for more detailed information.
13 changes: 7 additions & 6 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
module.exports = {
displayName: 'js-split-provider',
preset: '../../jest.preset.js',
displayName: 'openfeature-web-split-provider',
testEnvironment: 'jsdom',
testMatch: ['**/web.spec.js', '**/integration/*.test.js', '**/*-unit.test.js'],
globals: {
'ts-jest': {
tsconfig: '<rootDir>/tsconfig.spec.json',
tsconfig: '<rootDir>/tsconfig.json',
},
},
transform: {
'^.+\\.[tj]s$': 'ts-jest',
'^.+\\.[tj]sx?$': 'ts-jest',
},
moduleFileExtensions: ['ts', 'js', 'html'],
coverageDirectory: '../../coverage/packages/js-split-provider',
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'html'],
coverageDirectory: './coverage',
};
Loading