|
1 | | -# client-sdk-js |
2 | | -FeatureProbe Client Side SDK for JavaScript |
| 1 | +# FeatureProbe Client Side SDK for JavaScript |
| 2 | + |
| 3 | +Feature Probe is an open source feature management service. This SDK is used to control features in JavaScript programs. This |
| 4 | +SDK is designed primarily for use in multi-user systems such as web servers and applications. |
| 5 | + |
| 6 | +## Getting started |
| 7 | + |
| 8 | +In this guide we explain how to use feature toggles in a JavaScript application using FeatureProbe. |
| 9 | + |
| 10 | +### Step 1. Install the JavaScript SDK |
| 11 | + |
| 12 | +First, install the FeatureProbe SDK as a dependency in your application. |
| 13 | + |
| 14 | +```js |
| 15 | +npm install featureprobe-client-sdk-js --save |
| 16 | +``` |
| 17 | + |
| 18 | +Or via CDN: |
| 19 | + |
| 20 | +```js |
| 21 | +<script type="text/javascript" src="https://unpkg.com/featureprobe-client-sdk-js@latest/dist/featureprobe-client-sdk-js.min.js"></script> |
| 22 | +``` |
| 23 | + |
| 24 | + |
| 25 | +### Step 2. Create a FeatureProbe instance |
| 26 | + |
| 27 | +After you install and import the SDK, create a single, shared instance of the FeatureProbe sdk. |
| 28 | + |
| 29 | +```js |
| 30 | +const user = new featureProbe.FPUser("#USER-KEY#"); |
| 31 | +user.with("#ATTR-KEY#", "#ATTR-VALUE#"); |
| 32 | + |
| 33 | +const fp = new featureProbe.FeatureProbe({ |
| 34 | + remoteUrl: "#OPEN-API-URL#", |
| 35 | + togglesUrl: "#YOUR-TOGGLES-URL#", |
| 36 | + eventsUrl: "#YOUR-EVENTS-URL#", |
| 37 | + clientSdkKey: '#YOUR-CLIENT-SDK-KEY#', |
| 38 | + user, |
| 39 | + refreshInterval: 1000, |
| 40 | +}); |
| 41 | +fp.start(); |
| 42 | +``` |
| 43 | + |
| 44 | + |
| 45 | +### Step 3. Use the instance to get your setting value |
| 46 | + |
| 47 | +You can use sdk to check which value this user will receive for a given feature flag. |
| 48 | + |
| 49 | +```js |
| 50 | +fp.on('ready', function() { |
| 51 | + const result = fp.boolValue('ui_demo_toggle', false); |
| 52 | + if (result) { |
| 53 | + do_some_thing(); |
| 54 | + } else { |
| 55 | + do_other_thing(); |
| 56 | + } |
| 57 | + const reason = fp.boolDetail('ui_demo_toggle', false); |
| 58 | + console.log(reason); |
| 59 | +}) |
| 60 | +``` |
| 61 | + |
| 62 | +## Available options |
| 63 | + |
| 64 | +This SDK takes the following options: |
| 65 | + |
| 66 | +| option | required | default | description | |
| 67 | +|-------------------|----------------|---------|--------------------------------------------------------------------------------------------------------------------------------------------------| |
| 68 | +| remoteUrl | it all depends | n/a | The common URL to get toggles and send events. E.g.: `https://featureprobe.com/api` It is required when togglesUrl and eventsUrl are not set | |
| 69 | +| togglesUrl | no | n/a | The specific URL to get toggles, once set, remoteUrl become invalid | |
| 70 | +| eventsUrl | no | n/a | The specific URL to send events, once set, remoteUrl become invalid | |
| 71 | +| clientSdkKey | yes | n/a | The Client SDK Key URL to be used | |
| 72 | +| user | yes | n/a | Pass a valid user context for SDK initialization | |
| 73 | +| refreshInterval | no | 1000 | The SDK check for updated in millisecond | |
| 74 | + |
| 75 | +## Testing |
| 76 | + |
| 77 | +We have unified integration tests for all our SDKs. Integration test cases are added as submodules for each SDK repo. So |
| 78 | +be sure to pull submodules first to get the latest integration tests before running tests. |
| 79 | + |
| 80 | +```js |
| 81 | + npm run test |
| 82 | +``` |
| 83 | + |
| 84 | +## Contributing |
| 85 | +We are working on continue evolving FeatureProbe core, making it flexible and easier to use. |
| 86 | +Development of FeatureProbe happens in the open on GitHub, and we are grateful to the |
| 87 | +community for contributing bugfixes and improvements. |
| 88 | + |
| 89 | +Please read [CONTRIBUTING](https://github.com/FeatureProbe/featureprobe/blob/master/CONTRIBUTING.md) |
| 90 | +for details on our code of conduct, and the process for taking part in improving FeatureProbe. |
| 91 | + |
| 92 | + |
| 93 | +## License |
| 94 | + |
| 95 | +This project is licensed under the Apache 2.0 License - see the [LICENSE](LICENSE) file for details. |
| 96 | + |
0 commit comments