Skip to content

Commit 8be6c40

Browse files
authored
add Getting Started (#45)
1 parent e102f08 commit 8be6c40

File tree

5 files changed

+100
-3
lines changed

5 files changed

+100
-3
lines changed

README.md

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,55 @@ SAP BTP feature toggle library enables Node.js applications using the SAP Cloud
1313
npm install --save @cap-js-community/feature-toggle-library
1414
```
1515

16+
## Getting Started
17+
18+
- Set up project with `@sap/cds`
19+
- Install library `npm install --save @cap-js-community/feature-toggle-library`
20+
- Write `toggles.yaml` configuration file:
21+
22+
```yaml
23+
# info: check api priority; 0 means access is disabled
24+
/check/priority:
25+
type: number
26+
fallbackValue: 0
27+
validations:
28+
- scopes: [user, tenant]
29+
- regex: '^\d+$'
30+
```
31+
32+
- Add configuration path to package.json
33+
34+
```json
35+
{
36+
"cds": {
37+
"featureToggles": {
38+
"configFile": "./toggles.yaml"
39+
}
40+
}
41+
}
42+
```
43+
44+
- That's it. Write usage code
45+
46+
```javascript
47+
const toggles = require("@cap-js-community/feature-toggle-library");
48+
49+
const priorityHandler = async (context) => {
50+
const user = context.user.id;
51+
const tenant = context.tenant;
52+
const value = toggles.getFeatureValue("/check/priority", { user, tenant });
53+
if (value <= 0) {
54+
return context.reject("blocked");
55+
} else if (value < 10) {
56+
return context.reply("welcome");
57+
} else {
58+
return context.reply("very welcome");
59+
}
60+
};
61+
```
62+
63+
- For details see [Example CAP Server](https://github.com/cap-js-community/feature-toggle-library/blob/main/example-cap-server).
64+
1665
## Features
1766

1867
- Maintain feature toggle states consistently across multiple app instances.

docs/index.md

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,55 @@ SAP BTP feature toggle library enables Node.js applications using the SAP Cloud
1414
npm install --save @cap-js-community/feature-toggle-library
1515
```
1616

17+
## Getting Started
18+
19+
- Set up project with `@sap/cds`
20+
- Install library `npm install --save @cap-js-community/feature-toggle-library`
21+
- Write `toggles.yaml` configuration file:
22+
23+
```yaml
24+
# info: check api priority; 0 means access is disabled
25+
/check/priority:
26+
type: number
27+
fallbackValue: 0
28+
validations:
29+
- scopes: [user, tenant]
30+
- regex: '^\d+$'
31+
```
32+
33+
- Add configuration path to package.json
34+
35+
```json
36+
{
37+
"cds": {
38+
"featureToggles": {
39+
"configFile": "./toggles.yaml"
40+
}
41+
}
42+
}
43+
```
44+
45+
- That's it. Write usage code
46+
47+
```javascript
48+
const toggles = require("@cap-js-community/feature-toggle-library");
49+
50+
const priorityHandler = async (context) => {
51+
const user = context.user.id;
52+
const tenant = context.tenant;
53+
const value = toggles.getFeatureValue("/check/priority", { user, tenant });
54+
if (value <= 0) {
55+
return context.reject("blocked");
56+
} else if (value < 10) {
57+
return context.reply("welcome");
58+
} else {
59+
return context.reply("very welcome");
60+
}
61+
};
62+
```
63+
64+
- For details see [Example CAP Server](https://github.com/cap-js-community/feature-toggle-library/blob/main/example-cap-server).
65+
1766
## Features
1867

1968
- Maintain feature toggle states consistently across multiple app instances.
@@ -34,4 +83,3 @@ npm install --save @cap-js-community/feature-toggle-library
3483
- Configuration and code snippets: [Usage](usage)
3584
- Plugin and REST service for CAP projects: [Plugin and Service](plugin)
3685
- Architecture and related concepts: [Architecture](architecture)
37-
- Example CAP server: [CAP Example](https://github.com/cap-js-community/feature-toggle-library/blob/main/example-cap-server)

example-cap-server/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
"toggles": true
3030
},
3131
"featureToggles": {
32-
"configFile": "./srv/feature/features.yaml",
32+
"configFile": "./srv/feature/toggles.yaml",
3333
"serviceAccessRoles": [
3434
"system-user",
3535
"custom-role"
File renamed without changes.

test/docs.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const { join } = require("path");
55

66
describe("docs", () => {
77
it("documentation README / overview consistency check", async () => {
8-
const headings = ["Install or Upgrade", "Features", "Peers"];
8+
const headings = ["Install or Upgrade", "Getting Started", "Features", "Peers"];
99
const readmeData = readFileSync(join(__dirname, "..", "README.md")).toString();
1010
const overviewData = readFileSync(join(__dirname, "..", "docs", "index.md")).toString();
1111
for (const heading of headings) {

0 commit comments

Comments
 (0)