Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
78ba573
feat(browser-sdk,react-sdk): extend the web SDKs to support the new `…
pavkam Jan 29, 2025
ecb8a4c
Forward `toolbar` config in react-sdk (#299)
laander Jan 29, 2025
f384857
Bump react + browser SDK to v3.0.0-alpha.2 (#300)
laander Jan 29, 2025
81f5ddc
feat(node-sdk): support for remote configuration (#295)
pavkam Jan 29, 2025
ee38109
chore(node-sdk): bump version (#302)
pavkam Feb 3, 2025
eca331d
chore: allow publishing of non `main` branches` (#304)
roncohen Feb 4, 2025
ca22529
fix: docs ci script (#298)
matus-vacula Jan 28, 2025
2bb5088
chore(deps): bump next from 14.2.15 to 14.2.21 in /packages/react-sdk…
dependabot[bot] Jan 28, 2025
e81ec95
Bump year (#281)
makwarth Jan 28, 2025
f13880a
feat(browser-sdk,node-sdk): add avatar support for user and company c…
pavkam Jan 28, 2025
15119f8
chore(deps): bump nanoid from 3.3.7 to 3.3.8 in /packages/node-sdk/ex…
dependabot[bot] Jan 20, 2025
579eb1c
fix(node-sdk): ensure timers don't keep process alive (#303)
roncohen Feb 3, 2025
d9381e4
chore(browser-sdk,node-sdk): version 2.5.2 (#306)
roncohen Feb 4, 2025
6b1800a
Remove deprecated and flatten options (#308)
roncohen Feb 6, 2025
de93d76
feat(node-sdk): allow passing `meta` to `getFeature(s)` (#312)
pavkam Feb 9, 2025
bae0be7
chore(deps-dev): bump vitest from 2.0.4 to 2.1.9 (#314)
dependabot[bot] Feb 10, 2025
2fcef62
chore(deps-dev): bump vitest from 2.1.4 to 2.1.9 in /packages/node-sd…
dependabot[bot] Feb 10, 2025
f366edb
feat: use remote feature list instead of locally defined list (#315)
roncohen Feb 12, 2025
87e78a5
Merge branch 'main' into browser-react-3.0.alpha
pavkam Feb 12, 2025
28ffa72
chore(deps): upgrade @bucketco/browser-sdk to 3.0.0-alpha.2
pavkam Feb 12, 2025
c463ebf
feat(browser-sdk,react-sdk): check events (#316)
pavkam Feb 12, 2025
f1ef0f7
feat(openfeature-web-provider): improve flag resolution and context h…
pavkam Feb 12, 2025
f4e579c
chore(openfeature-browser-provider): bump version to 0.4.0-alpha.1
pavkam Feb 12, 2025
ab5ba42
refactor(react-sdk): simplify BucketProvider props and improve type d…
pavkam Feb 13, 2025
a92f028
chore(browser-sdk,react-sdk): bump SDK versions to 3.0.0-alpha.4 and …
pavkam Feb 13, 2025
adf6fe8
fix(browser-sdk,react-sdk): remove featureId option for requestFeedba…
roncohen Feb 13, 2025
bff834c
fix(react-sdk): throw error on missing provider (#322)
roncohen Feb 13, 2025
bc0dbde
fix(browser-sdk): remove featureDefinition list (#323)
roncohen Feb 13, 2025
c6fa42a
fix(react-sdk): improve type definitions for useFeature hook (#324)
pavkam Feb 17, 2025
1e21da8
feat(browser-sdk): Event listeners (#325)
roncohen Feb 17, 2025
7340206
feat: hooks
roncohen Feb 15, 2025
672b6c0
more hooks
roncohen Feb 15, 2025
568c5f9
missing files
roncohen Feb 15, 2025
c769a8b
docs
roncohen Feb 15, 2025
f19dd98
update tests
roncohen Feb 15, 2025
b622416
export hook types, better examples etc.
roncohen Feb 16, 2025
f7e2899
refactored hooks system
roncohen Feb 16, 2025
1e3f599
updated hooks
roncohen Feb 16, 2025
b2fb888
missed a type import
roncohen Feb 16, 2025
869c1a1
missed the example index.html
roncohen Feb 16, 2025
fad9666
one more
roncohen Feb 16, 2025
7a84fe4
update react sdk too
roncohen Feb 16, 2025
f6e592c
fix test
roncohen Feb 17, 2025
121a36e
feat: in use
roncohen Feb 15, 2025
9d09ff4
working on tests
roncohen Feb 15, 2025
a5949f2
wip
roncohen Feb 16, 2025
2de4ab2
introduce: in-use API for use with React
roncohen Feb 17, 2025
32cafbf
fix tests
roncohen Feb 17, 2025
e1079a3
Merge branch 'browser-react-3.0.alpha' into in-use
roncohen Feb 17, 2025
7e020bf
fix: docs
roncohen Feb 17, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
feat(node-sdk): support for remote configuration (#295)
This PR adds support for remote configuration to the node-sdk.
  • Loading branch information
pavkam authored Jan 29, 2025
commit 81f5ddc44496e4cbe9273d38d50ced4f3d6e6bc9
95 changes: 91 additions & 4 deletions packages/node-sdk/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
}
}
}
}
```
Expand All @@ -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
};
}
}

Expand All @@ -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
}
}
```

![Type check failed](docs/type-check-failed.png "Type check failed")
Expand Down
10 changes: 9 additions & 1 deletion packages/node-sdk/example/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,18 @@ app.post("/todos", (req, res) => {
return res.status(400).json({ error: "Invalid todo" });
}

const { track, isEnabled } = res.locals.bucketUser.getFeature("create-todos");
const { track, isEnabled, config } =
res.locals.bucketUser.getFeature("create-todos");

// Check if the user has the "create-todos" feature enabled
if (isEnabled) {
// Check if the todo is at least N characters long
if (todo.length < config.payload.minimumLength) {
return res
.status(400)
.json({ error: "Todo must be at least 5 characters long" });
}

// Track the feature usage
track();
todos.push(todo);
Expand Down
27 changes: 24 additions & 3 deletions packages/node-sdk/example/bucket.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,38 @@
import { BucketClient, Context } from "../src";
import { FeatureOverrides } from "../src/types";

type CreateConfig = {
minimumLength: number;
};

// Extending the Features interface to define the available features
declare module "../src/types" {
interface Features {
"show-todos": boolean;
"create-todos": boolean;
"create-todos": {
isEnabled: boolean;
config: {
key: string;
payload: CreateConfig;
};
};
"delete-todos": boolean;
"some-else": {};
}
}

let featureOverrides = (context: Context): FeatureOverrides => {
return { "delete-todos": true }; // feature keys checked at compile time
let featureOverrides = (_: Context): FeatureOverrides => {
return {
"create-todos": {
isEnabled: true,
config: {
key: "short",
payload: {
minimumLength: 10,
},
},
},
}; // feature keys checked at compile time
};

let host = undefined;
Expand Down
4 changes: 2 additions & 2 deletions packages/node-sdk/example/bucketConfig.json
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
}
}
Loading