@@ -74,13 +74,18 @@ const boundClient = bucketClient.bindClient({
74
74
75
75
// get the huddle feature using company, user and custom context to
76
76
// evaluate the targeting.
77
- const { isEnabled, track } = boundClient .getFeature (" huddle" );
77
+ const { isEnabled, track, config } = boundClient .getFeature (" huddle" );
78
78
79
79
if (isEnabled ) {
80
80
// this is your feature gated code ...
81
81
// send an event when the feature is used:
82
82
track ();
83
83
84
+ if (config ?.key === " zoom" ) {
85
+ // this code will run if a given remote configuration
86
+ // is set up.
87
+ }
88
+
84
89
// CAUTION: if you plan to use the event for automated feedback surveys
85
90
// call `flush` immediately after `track`. It can optionally be awaited
86
91
// to guarantee the sent happened.
@@ -108,6 +113,34 @@ to `getFeatures()` (or through `bindClient(..).getFeatures()`). That means the
108
113
` initialize() ` has completed. ` BucketClient ` will continue to periodically
109
114
download the targeting rules from the Bucket servers in the background.
110
115
116
+ ### Remote config
117
+
118
+ Similar to ` isEnabled ` , each feature has a ` config ` property. This configuration is managed from within Bucket.
119
+ It is managed similar to the way access to features is managed, but instead of the binary ` isEnabled ` you can have
120
+ multiple configuration values which are given to different user/companies.
121
+
122
+ ``` ts
123
+ const features = bucketClient .getFeatures ();
124
+ // {
125
+ // huddle: {
126
+ // isEnabled: true,
127
+ // targetingVersion: 42,
128
+ // config: {
129
+ // key: "gpt-3.5",
130
+ // payload: { maxTokens: 10000, model: "gpt-3.5-beta1" }
131
+ // }
132
+ // }
133
+ // }
134
+ ```
135
+
136
+ The ` key ` is always present while the ` payload ` is a optional JSON value for arbitrary configuration needs.
137
+ If feature has no configuration or, no configuration value was matched against the context, the ` config ` object
138
+ will be empty, thus, ` key ` will be ` undefined ` . Make sure to check against this case when trying to use the
139
+ configuration in your application.
140
+
141
+ Just as ` isEnabled ` , accessing ` config ` on the object returned by ` getFeatures ` does not automatically
142
+ generate a ` check ` event, contrary to the ` config ` property on the object returned by ` getFeature ` .
143
+
111
144
## Configuring
112
145
113
146
The Bucket ` Node.js ` SDK can be configured through environment variables,
@@ -136,7 +169,13 @@ Note: BUCKET_FEATURES_ENABLED, BUCKET_FEATURES_DISABLED are comma separated list
136
169
"apiBaseUrl" : " https://proxy.slick-demo.com" ,
137
170
"featureOverrides" : {
138
171
"huddles" : true ,
139
- "voiceChat" : false
172
+ "voiceChat" : false ,
173
+ "aiAssist" : {
174
+ "key" : " gpt-4.0" ,
175
+ "payload" : {
176
+ "maxTokens" : 50000
177
+ }
178
+ }
140
179
}
141
180
}
142
181
```
@@ -162,8 +201,11 @@ import { BucketClient } from "@bucketco/node-sdk";
162
201
declare module " @bucketco/node-sdk" {
163
202
interface Features {
164
203
" show-todos" : boolean ;
165
- " create-todos" : boolean ;
166
- " delete-todos" : boolean ;
204
+ " create-todos" : { isEnabled: boolean };
205
+ " delete-todos" : {
206
+ isEnabled: boolean ,
207
+ config: any
208
+ };
167
209
}
168
210
}
169
211
@@ -173,7 +215,52 @@ bucketClient.initialize().then({
173
215
console.log(" Bucket initialized!" )
174
216
bucketClient.getFeature(" invalid-feature" ) // feature doesn't exist
175
217
})
218
+ ` ` `
219
+
220
+ The following example show how to add strongly typed payloads when using remote configuration:
221
+
222
+ ` ` ` typescript
223
+ import { BucketClient } from " @bucketco/node-sdk" ;
224
+
225
+ type ConfirmationConfig = {
226
+ shouldShowConfirmation: boolean ;
227
+ };
176
228
229
+ declare module " @bucketco/node-sdk" {
230
+ interface Features {
231
+ " delete-todos" : {
232
+ isEnabled: boolean ;
233
+ config : {
234
+ key: string ;
235
+ payload : ConfirmationConfig ;
236
+ };
237
+ };
238
+ }
239
+ }
240
+
241
+ export const bucketClient = new BucketClient ();
242
+
243
+ function deleteTodo(todoId : string ) {
244
+ // get the feature information
245
+ const {
246
+ isEnabled,
247
+ config : { payload : confirmationConfig },
248
+ } = bucketClient .getFeature (" delete-todos" );
249
+
250
+ // check that feature is enabled for user
251
+ if (! isEnabled ) {
252
+ return ;
253
+ }
254
+
255
+ // finally, check if we enabled the "confirmation" dialog for this user and only
256
+ // show it in that case.
257
+ // since we defined `ConfirmationConfig` as the only valid payload for `delete-todos`,
258
+ // we have type-safety helping us with the payload value.
259
+ if (confirmationConfig .shouldShowConfirmation ) {
260
+ showMessage (" Are you really sure you want to delete this item?" );
261
+ // ... rest of the code
262
+ }
263
+ }
177
264
` ` `
178
265
179
266

0 commit comments