-
Notifications
You must be signed in to change notification settings - Fork 7
feat(node-sdk): support for remote configuration #295
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
pavkam
merged 57 commits into
main
from
buc-3197-extend-the-node-sdk-to-expose-the-configs
Jan 29, 2025
Merged
Changes from all commits
Commits
Show all changes
57 commits
Select commit
Hold shift + click to select a range
4f6ccb6
Add support for feature-specific config payloads
pavkam 7b3a4af
Refactor flag evaluation logic and update SDK version.
pavkam 70f2393
Add feature configuration support and enhance fallback features
pavkam 2e30def
Merge remote-tracking branch 'origin/main' into buc-3198-extend-the-w…
pavkam d2e9de6
Bump version to 0.4.0
pavkam 5af7fd3
Merge branch 'main' into buc-3198-extend-the-web-sdks-to-expose-the-c…
pavkam 340fc9c
feat(browser-sdk): add format script, improve README formatting, and …
pavkam a6c6678
feat(browser-sdk): update feature configuration handling and improve …
pavkam f5f250e
feat(react-sdk): enhance feature handling in useFeature hook
pavkam 66f661a
feat(browser-sdk, react-sdk, openfeature-browser-sdk): enhance featur…
pavkam 38975e1
feat(openfeature-browser-provider): revert changes to openfeature ada…
pavkam f2ba839
chore(browser-sdk, react-sdk): Respond to comments
pavkam f1383e6
fix(browser-sdk): update README to reflect changes in feature configu…
pavkam cd276f4
feat(openfeature-browser-provider): update browser-sdk dependency and…
pavkam e61be44
feat(node-sdk): enhance feature configuration and fallback handling
pavkam 3d12581
docs(node-sdk): update README with remote configuration and type-safe…
pavkam 5f02bb8
Merge branch 'main' into buc-3198-extend-the-web-sdks-to-expose-the-c…
pavkam 295f05d
fix(browser-sdk): update feature remote config type definition
pavkam 0dd5757
chore(react-sdk): remove unused import from index.tsx
pavkam 7173423
feat(browser-sdk): enhance fallback feature configuration handling
pavkam 862df25
test(browser-sdk): remove .only from features test
pavkam 7678334
Merge branch 'buc-3198-extend-the-web-sdks-to-expose-the-config' into…
pavkam bfb4276
test(browser-sdk): update feature test assertions
pavkam e22475b
test(browser-sdk): update feature test expectations
pavkam da09414
Merge branch 'buc-3198-extend-the-web-sdks-to-expose-the-config' into…
pavkam 7d45486
chore: remove artifacts from this PR
pavkam 2e62475
refactor(react-sdk): simplify feature config access and reduce payload
pavkam 34fd9b0
Merge branch 'buc-3198-extend-the-web-sdks-to-expose-the-config' into…
pavkam cedeb14
test(browser-sdk): remove trailing newline in test file
pavkam 2f74252
Merge branch 'main' into buc-3198-extend-the-web-sdks-to-expose-the-c…
pavkam fa735d8
docs(browser-sdk,react-sdk): clarify remote config documentation
pavkam a6eb451
Merge remote-tracking branch 'origin/main' into buc-3198-extend-the-w…
pavkam ff3e85a
Merge remote-tracking branch 'origin/buc-3198-extend-the-web-sdks-to-…
pavkam 441ab2e
feat(node-sdk): update feature override and configuration handling
pavkam a659f05
Merge branch 'buc-3198-extend-the-web-sdks-to-expose-the-config' into…
pavkam a51a495
docs(node-sdk): Update README with detailed remote config explanation…
pavkam f986feb
feat(browser-sdk): export FallbackFeatureOverride type
pavkam 7c6c47c
chore(release): bump browser-sdk and react-sdk to 3.0.0-alpha.1
pavkam 99a9186
Merge branch 'main' into buc-3197-extend-the-node-sdk-to-expose-the-c…
pavkam 7012ae4
Merge branch 'buc-3198-extend-the-web-sdks-to-expose-the-config' into…
pavkam 352a462
Merge branch 'main' into buc-3198-extend-the-web-sdks-to-expose-the-c…
pavkam 941bb42
Merge branch 'buc-3198-extend-the-web-sdks-to-expose-the-config' into…
pavkam 713b0d2
feat(node-sdk): Enhance feature override validation and configuration…
pavkam 5a8fffe
Merge branch 'main' into buc-3198-extend-the-web-sdks-to-expose-the-c…
pavkam f4b6643
Merge branch 'main' into buc-3198-extend-the-web-sdks-to-expose-the-c…
pavkam dde88b5
fix: ensure feature config always has key and payload properties
pavkam bb506b4
refactor: simplify feature config type definition
pavkam 564332a
Merge remote-tracking branch 'origin/buc-3198-extend-the-web-sdks-to-…
pavkam 8a36cf0
Merge branch 'buc-3198-extend-the-web-sdks-to-expose-the-config' into…
pavkam 6e84e64
fix: ensure feature config returns undefined key and payload when no …
pavkam 9351f5b
refactor: remove redundant comment in Feature interface
pavkam 9f5efd7
docs: update README with type-safe feature flag configuration example
pavkam b2328cc
Merge branch 'main' into buc-3197-extend-the-node-sdk-to-expose-the-c…
pavkam 813cde1
feat(node-sdk): extend node SDK to support feature configuration with…
pavkam c452976
feat(node-sdk): add type-safe generics for feature retrieval methods
pavkam 07743eb
fix(node-sdk): improve type safety for feature config getter
pavkam 60a3568
Merge branch 'main' into buc-3197-extend-the-node-sdk-to-expose-the-c…
pavkam File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -74,13 +74,18 @@ const boundClient = bucketClient.bindClient({ | |
|
||
// get the huddle feature using company, user and custom context to | ||
// evaluate the targeting. | ||
const { isEnabled, track } = boundClient.getFeature("huddle"); | ||
const { isEnabled, track, config } = boundClient.getFeature("huddle"); | ||
|
||
if (isEnabled) { | ||
// this is your feature gated code ... | ||
// send an event when the feature is used: | ||
track(); | ||
|
||
if (config?.key === "zoom") { | ||
// this code will run if a given remote configuration | ||
// is set up. | ||
} | ||
|
||
// CAUTION: if you plan to use the event for automated feedback surveys | ||
// call `flush` immediately after `track`. It can optionally be awaited | ||
// to guarantee the sent happened. | ||
|
@@ -108,6 +113,34 @@ to `getFeatures()` (or through `bindClient(..).getFeatures()`). That means the | |
`initialize()` has completed. `BucketClient` will continue to periodically | ||
download the targeting rules from the Bucket servers in the background. | ||
|
||
### Remote config | ||
|
||
Similar to `isEnabled`, each feature has a `config` property. This configuration is managed from within Bucket. | ||
It is managed similar to the way access to features is managed, but instead of the binary `isEnabled` you can have | ||
multiple configuration values which are given to different user/companies. | ||
|
||
```ts | ||
const features = bucketClient.getFeatures(); | ||
// { | ||
// huddle: { | ||
// isEnabled: true, | ||
// targetingVersion: 42, | ||
// config: { | ||
// key: "gpt-3.5", | ||
// payload: { maxTokens: 10000, model: "gpt-3.5-beta1" } | ||
// } | ||
// } | ||
// } | ||
``` | ||
|
||
The `key` is always present while the `payload` is a optional JSON value for arbitrary configuration needs. | ||
If feature has no configuration or, no configuration value was matched against the context, the `config` object | ||
will be empty, thus, `key` will be `undefined`. Make sure to check against this case when trying to use the | ||
configuration in your application. | ||
|
||
Just as `isEnabled`, accessing `config` on the object returned by `getFeatures` does not automatically | ||
generate a `check` event, contrary to the `config` property on the object returned by `getFeature`. | ||
|
||
## Configuring | ||
|
||
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 | |
"apiBaseUrl": "https://proxy.slick-demo.com", | ||
"featureOverrides": { | ||
"huddles": true, | ||
"voiceChat": false | ||
"voiceChat": false, | ||
"aiAssist": { | ||
"key": "gpt-4.0", | ||
"payload": { | ||
"maxTokens": 50000 | ||
} | ||
} | ||
} | ||
} | ||
``` | ||
|
@@ -162,8 +201,11 @@ import { BucketClient } from "@bucketco/node-sdk"; | |
declare module "@bucketco/node-sdk" { | ||
interface Features { | ||
"show-todos": boolean; | ||
"create-todos": boolean; | ||
"delete-todos": boolean; | ||
"create-todos": { isEnabled: boolean }; | ||
"delete-todos": { | ||
isEnabled: boolean, | ||
config: any | ||
}; | ||
} | ||
} | ||
|
||
|
@@ -173,7 +215,52 @@ bucketClient.initialize().then({ | |
console.log("Bucket initialized!") | ||
bucketClient.getFeature("invalid-feature") // feature doesn't exist | ||
}) | ||
``` | ||
|
||
The following example show how to add strongly typed payloads when using remote configuration: | ||
|
||
```typescript | ||
import { BucketClient } from "@bucketco/node-sdk"; | ||
|
||
type ConfirmationConfig = { | ||
shouldShowConfirmation: boolean; | ||
}; | ||
|
||
declare module "@bucketco/node-sdk" { | ||
interface Features { | ||
"delete-todos": { | ||
isEnabled: boolean; | ||
config: { | ||
key: string; | ||
payload: ConfirmationConfig; | ||
}; | ||
}; | ||
} | ||
} | ||
|
||
export const bucketClient = new BucketClient(); | ||
|
||
function deleteTodo(todoId: string) { | ||
// get the feature information | ||
const { | ||
isEnabled, | ||
config: { payload: confirmationConfig }, | ||
} = bucketClient.getFeature("delete-todos"); | ||
|
||
// check that feature is enabled for user | ||
if (!isEnabled) { | ||
return; | ||
} | ||
|
||
// finally, check if we enabled the "confirmation" dialog for this user and only | ||
// show it in that case. | ||
// since we defined `ConfirmationConfig` as the only valid payload for `delete-todos`, | ||
// we have type-safety helping us with the payload value. | ||
if (confirmationConfig.shouldShowConfirmation) { | ||
showMessage("Are you really sure you want to delete this item?"); | ||
// ... rest of the code | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
``` | ||
|
||
 | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"overrides": { | ||
"myFeature": true, | ||
"myFeatureFalse": false | ||
"show-todos": true, | ||
"create-todos": true | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.