Skip to content

Commit f1864f3

Browse files
authored
Merge pull request #3 from FeatureProbe/fpuser
feat: FPUser auto generate key
2 parents 2235f77 + b359c21 commit f1864f3

File tree

13 files changed

+124
-238
lines changed

13 files changed

+124
-238
lines changed

README.md

Lines changed: 2 additions & 153 deletions
Original file line numberDiff line numberDiff line change
@@ -16,160 +16,9 @@ Reading the short [Basic Terms](https://github.com/FeatureProbe/FeatureProbe/blo
1616

1717
Reading the short [Doc](https://github.com/FeatureProbe/feature-probe-docs/blob/b8c55a35c771e4223469f1b121f8b78ab3d9bc22/docs/sdk/sdk-introduction.md?plain=1#L13-L34) about core data sturtures. [中文](https://github.com/FeatureProbe/feature-probe-docs/blob/b8c55a35c771e4223469f1b121f8b78ab3d9bc22/i18n/zh-CN/docusaurus-plugin-content-docs/current/sdk/sdk-introduction.md?plain=1#L14-L35)
1818

19-
## Try Out Demo Code
19+
## How to use this SDK
2020

21-
We provide a runnable [demo](https://github.com/FeatureProbe/client-sdk-js/tree/main/example) for you to understand how FeatureProbe SDK is used.
22-
23-
1. Use featureprobe.io online service. [Go to](https://featureprobe.io/login)
24-
25-
Or setup FeatureProbe service with docker composer. [How to](https://github.com/FeatureProbe/FeatureProbe#1-starting-featureprobe-service-with-docker-compose)
26-
27-
2. Download this repo and run the demo program:
28-
```bash
29-
git clone https://github.com/FeatureProbe/client-sdk-js.git
30-
cd client-sdk-js
31-
// open example/index.html in browser
32-
```
33-
34-
3. Find the Demo code [here](https://github.com/FeatureProbe/client-sdk-js/tree/main/example),
35-
do some change and run the program again.
36-
```
37-
// open example/index.html in browser
38-
```
39-
40-
## Step-by-Step Guide
41-
42-
In this guide we explain how to use feature toggles in a JavaScript application using FeatureProbe.
43-
44-
### Step 1. Install the JavaScript SDK
45-
46-
First, install the FeatureProbe SDK as a dependency in your application.
47-
48-
NPM:
49-
50-
```js
51-
npm install featureprobe-client-sdk-js --save
52-
```
53-
54-
Or via CDN:
55-
56-
```js
57-
<script type="text/javascript" src="https://unpkg.com/featureprobe-client-sdk-js@latest/dist/featureprobe-client-sdk-js.min.js"></script>
58-
```
59-
60-
### Step 2. Create a FeatureProbe instance
61-
62-
After you install and import the SDK, create a single, shared instance of the FeatureProbe SDK.
63-
64-
NPM:
65-
66-
```js
67-
import { FeatureProbe, FPUser } from "featureprobe-client-sdk-js";
68-
69-
const userId = /* unique user id in your business logic */;
70-
const user = new FPUser(userId);
71-
user.with("userId", /* userId */);
72-
73-
const remoteUrl = "https://featureprobe.io/server";
74-
// const remoteUrl = "http://localhost:4007"; // for local docker
75-
76-
const fp = new FeatureProbe({
77-
remoteUrl,
78-
clientSdkKey: /* clientSdkKey */,
79-
user
80-
});
81-
82-
fp.start();
83-
```
84-
85-
Or via CDN:
86-
87-
```js
88-
const userId = /* unique user id in your business logic */;
89-
const user = new FPUser(userId);
90-
user.with("userId", /* userId */);
91-
92-
const remoteUrl = "https://featureprobe.io/server";
93-
// const remoteUrl = "http://localhost:4007"; // for local docker
94-
95-
const fp = new featureProbe.FeatureProbe({
96-
remoteUrl,
97-
clientSdkKey: /* clientSdkKey */,
98-
user
99-
});
100-
101-
fp.start();
102-
```
103-
104-
### Step 3. Use the instance to get your setting value
105-
106-
You can use sdk to check which value this user will receive for a given feature flag.
107-
108-
```js
109-
fp.on("ready", function() {
110-
const result = fp.boolValue(/* toggleKey */, false);
111-
if (result) {
112-
// do_some_thing();
113-
} else {
114-
// do_other_thing();
115-
}
116-
const reason = fp.boolDetail(/* toggleKey */, false);
117-
console.log(reason);
118-
})
119-
```
120-
121-
### Step 4. Unit Testing (Optional)
122-
NPM:
123-
124-
```js
125-
test("feature probe unit testing", (done) => {
126-
let fp = FeatureProbe.newForTest({ testToggle: true });
127-
fp.start();
128-
129-
fp.on("ready", function () {
130-
let t = fp.boolValue(/* toggleKey */, false);
131-
expect(t).toBe(true);
132-
done();
133-
});
134-
});
135-
```
136-
137-
Or via CDN:
138-
139-
```js
140-
test("feature probe unit testing", (done) => {
141-
let fp = featureProbe.FeatureProbe.newForTest({ testToggle: true });
142-
fp.start();
143-
144-
fp.on("ready", function () {
145-
let t = fp.boolValue(/* toggleKey */, false);
146-
expect(t).toBe(true);
147-
done();
148-
});
149-
});
150-
```
151-
152-
## Available options
153-
154-
This SDK takes the following options:
155-
156-
| option | required | default | description |
157-
|-------------------|----------------|---------|--------------------------------------------------------------------------------------------------------------------------------------------------|
158-
| user | yes | n/a | The User with attributes like name, age is used when toggle evaluation |
159-
| clientSdkKey | yes | n/a | The Client SDK Key is used to authentification |
160-
| remoteUrl | depends | n/a | The unified URL to get toggles and post events |
161-
| togglesUrl | no | n/a | The specific URL to get toggles, once set, remoteUrl will be ignored |
162-
| eventsUrl | no | n/a | The specific URL to post events, once set, remoteUrl will be ignored |
163-
| refreshInterval | no | 1000 | The SDK check for updated in millisecond |
164-
165-
## Testing
166-
167-
We have unified integration tests for all our SDKs. Integration test cases are added as submodules for each SDK repo. So
168-
be sure to pull submodules first to get the latest integration tests before running tests.
169-
170-
```js
171-
npm run test
172-
```
21+
See [SDK Doc](https://docs.featureprobe.io/sdk/Client-Side%20SDKs/javascript-sdk/) for detail. [中文](https://docs.featureprobe.io/zh-CN/sdk/Client-Side%20SDKs/javascript-sdk)
17322

17423
## Contributing
17524

doc/assets/main.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

doc/assets/search.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)