@@ -38,10 +38,79 @@ back all toggles to their fallback values.
3838
3939## Configuration
4040
41- ### Initialization
42-
4341We recommend maintaining the configuration in a _ version-tracked_ , YAML- or JSON-file, which only changes during
44- deployments. You will need to use the corresponding filepath, in order to initialize the feature toggles instance.
42+ deployments. The configuration is a key-value map describing each individual feature toggle. Here is an example in YAML.
43+
44+ ``` yaml
45+ /srv/util/logger/logLevel :
46+ type : string
47+ fallbackValue : info
48+ appUrl : \.cfapps\.sap\.hana\.ondemand\.com$
49+ validation : ^(?:error|warn|info|verbose|debug)$
50+ ` ` `
51+
52+ The semantics of these properties are as follows.
53+
54+ | property | required | meaning |
55+ | :------------ | :------- | :--------------------------------------------------------------- |
56+ | active | | if this is ` false`, the corresponding feature toggle is inactive |
57+ | type | true | one of the allowed types `boolean`, `number`, `string` |
58+ | fallbackValue | true | see below |
59+ | appUrl | | see below |
60+ | validation | | regex for input validation |
61+ | allowedScopes | | see below |
62+
63+ _fallbackValue_<br>
64+ This value gets set initially when the feature toggle is introduced, and it is also used as a fallback when
65+ communication with Redis is interrupted during startup.
66+
67+ _appUrl_<br>
68+ Regex for activating feature toggle _only_ if the cf app's url matches
69+
70+ - for CANARY landscape `\.cfapps\.sap\.hana\.ondemand\.com$`
71+ - for EU10 landscape `\.cfapps\.eu10\.hana\.ondemand\.com$`
72+ - specific CANARY app `<cf-app-name>\.cfapps\.sap\.hana\.ondemand\.com$`
73+
74+ _allowedScopes_<br>
75+ This is an additional form of change validation. AllowedScopes can be set to a list of strings, for example
76+ `allowedScopes : [tenant, user]`. With this configuration only matching scopes can be used when setting feature toggle
77+ values.
78+
79+ {: .info }
80+ You can use the type `string` to encode more complex data types, like arrays or objects, but need to take care of the
81+ serialization/deserialization yourself. In these cases, make sure to use [external validation](#external-validation)
82+ so that new values can be deserialized correctly.
83+
84+ {: .warn }
85+ When using _active_ or _appUrl_ to block activation of a feature toggle, then user code accessing the
86+ feature toggle value will always get the fallback value.
87+
88+ # # Initialization for CAP Projects
89+
90+ CAP projects, will use the library as a [cds-plugin](https://cap.cloud.sap/docs/node.js/cds-plugins). Their
91+ initialization settings are in `package.json`. For example :
92+
93+ ` ` ` json
94+ {
95+ "cds": {
96+ "featureToggles": {
97+ "configFile": "./srv/feature/features.yaml"
98+ }
99+ }
100+ }
101+ ` ` `
102+
103+ In this example, the path `./srv/feature/feature.yaml` points to the previously discussed configuration file. With
104+ these settings in place, the `singleton` instance of the library will be initialized and is ready for usage at and
105+ after the [bootstrap](https://cap.cloud.sap/cap/docs/node.js/cds-server#bootstrap) event.
106+
107+ {: .info }
108+ Using the feature toggles in CAP projects also enables a [REST service]({{ site.baseurl }}/service/), where toggles can
109+ be read and manipulated.
110+
111+ # # Initialization for Non-CAP Projects
112+
113+ Other projects will need to use the corresponding filepath, in order to initialize the feature toggles instance in code.
45114
46115` ` ` javascript
47116const pathlib = require("path");
@@ -93,54 +162,6 @@ const config = await readConfigFromFile(FEATURES_FILEPATH);
93162await initializeFeatures({ config });
94163` ` `
95164
96- ### Format
97-
98- The configuration is a key-value map describing each individual feature toggle. Here is an example in YAML.
99-
100- ``` yaml
101- /srv/util/logger/logLevel :
102- type : string
103- fallbackValue : info
104- appUrl : \.cfapps\.sap\.hana\.ondemand\.com$
105- validation : ^(?:error|warn|info|verbose|debug)$
106- ` ` `
107-
108- The semantics of these properties are as follows.
109-
110- | property | required | meaning |
111- | :------------ | :------- | :--------------------------------------------------------------- |
112- | active | | if this is ` false`, the corresponding feature toggle is inactive |
113- | type | true | one of the allowed types `boolean`, `number`, `string` |
114- | fallbackValue | true | see below |
115- | appUrl | | see below |
116- | validation | | regex for input validation |
117- | allowedScopes | | see below |
118-
119- _fallbackValue_<br>
120- This value gets set initially when the feature toggle is introduced, and it is also used as a fallback when
121- communication with Redis is blocked during startup.
122-
123- _appUrl_<br>
124- Regex for activating feature toggle _only_ if the cf app's url matches
125-
126- - for CANARY landscape `\.cfapps\.sap\.hana\.ondemand\.com$`
127- - for EU10 landscape `\.cfapps\.eu10\.hana\.ondemand\.com$`
128- - specific CANARY app `<cf-app-name>\.cfapps\.sap\.hana\.ondemand\.com$`
129-
130- _allowedScopes_<br>
131- This is an additional form of change validation. AllowedScopes can be set to a list of strings, for example
132- `allowedScopes : [tenant, user]`. With this configuration only matching scopes can be used when setting feature toggle
133- values.
134-
135- {: .info }
136- You can use the type `string` to encode more complex data types, like arrays or objects, but need to take care of the
137- serialization/deserialization yourself. In these cases, make sure to use [external validation](#external-validation)
138- so that new values can be deserialized correctly.
139-
140- {: .warn }
141- When using active or appUrl to block activation of a feature toggle, then user code accessing the
142- feature toggle value will _always_ get the fallback value.
143-
144165# # Environment Variables
145166
146167The following environment variables can be used to fine-tune the library's behavior :
0 commit comments