Thanks to visit codestin.com
Credit goes to github.com

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: in use
  • Loading branch information
roncohen committed Feb 17, 2025
commit 121a36e628c75eeafa76899b95373ee6bb0995d4
28 changes: 20 additions & 8 deletions packages/browser-sdk/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,19 @@ export interface Feature {
requestFeedback: (
options: Omit<RequestFeedbackData, "featureKey" | "featureId">,
) => void;

/**
* The current override status of isEnabled for the feature.
*/
isEnabledOverride: boolean | null;

/**
* Set the override status for isEnabled for the feature.
* Set to `null` to remove the override.
*/
setIsEnabledOverride(isEnabled: boolean | null): void;

setInUse(inUse: boolean): void;
}

function shouldShowToolbar(opts: InitOptions) {
Expand Down Expand Up @@ -763,17 +776,16 @@ export class BucketClient {
...options,
});
},
isEnabledOverride: this.featuresClient.getFeatureOverride(key),
setIsEnabledOverride(isEnabled: boolean | null) {
fClient.setFeatureOverride(key, isEnabled);
},
setInUse(inUse: boolean) {
fClient.setInUse(key, inUse);
},
};
}

setFeatureOverride(key: string, isEnabled: boolean | null) {
this.featuresClient.setFeatureOverride(key, isEnabled);
}

getFeatureOverride(key: string): boolean | null {
return this.featuresClient.getFeatureOverride(key);
}

sendCheckEvent(checkEvent: CheckEvent) {
return this.featuresClient.sendCheckEvent(checkEvent, () => {
this.hooks.trigger(checkEvent.action, checkEvent);
Expand Down
23 changes: 23 additions & 0 deletions packages/browser-sdk/src/feature/features.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@ export type RawFeature = FetchedFeature & {
* If not null, the result is being overridden locally
*/
isEnabledOverride: boolean | null;

/**
* If not null, the feature is in use
*/
inUse: boolean;
};

export type RawFeatures = Record<string, RawFeature>;
Expand Down Expand Up @@ -185,6 +190,7 @@ const localStorageFetchedFeaturesKey = `__bucket_fetched_features`;
const localStorageOverridesKey = `__bucket_overrides`;

type OverridesFeatures = Record<string, boolean | null>;
type InUseFeatures = Record<string, boolean | null>;

function setOverridesCache(overrides: OverridesFeatures) {
localStorage.setItem(localStorageOverridesKey, JSON.stringify(overrides));
Expand All @@ -210,6 +216,8 @@ export class FeaturesClient {
private fetchedFeatures: FetchedFeatures;
private featureOverrides: OverridesFeatures = {};

private featureInUse: InUseFeatures = {};

private features: RawFeatures = {};

private config: Config;
Expand Down Expand Up @@ -399,6 +407,16 @@ export class FeaturesClient {
mergedFeatures[key] = {
...fetchedFeature,
isEnabledOverride,
inUse: false,
};
}

for (const key in this.featureInUse) {
const inUse = this.featureInUse[key] ?? false;
mergedFeatures[key] = {
...mergedFeatures[key],
key,
inUse,
};
}

Expand Down Expand Up @@ -532,4 +550,9 @@ export class FeaturesClient {
getFeatureOverride(key: string): boolean | null {
return this.featureOverrides[key] ?? null;
}

setInUse(key: string, value: boolean) {
this.featureInUse[key] = value;
this.triggerFeaturesChanged();
}
}
9 changes: 7 additions & 2 deletions packages/browser-sdk/src/toolbar/Features.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,15 @@ export function FeaturesTable({
if (features.length === 0) {
return <div style={{ color: "var(--gray500)" }}>No features found</div>;
}

const sortedFeatures = [...features].sort((a, b) =>
a.inUse === b.inUse ? 0 : a.inUse ? -1 : 1,
);

return (
<table class="features-table">
<tbody>
{features.map((feature) => (
{sortedFeatures.map((feature) => (
<FeatureRow
feature={feature}
appBaseUrl={appBaseUrl}
Expand All @@ -41,7 +46,7 @@ function FeatureRow({
}) {
return (
<tr key={feature.key}>
<td class="feature-name-cell">
<td class="feature-name-cell in-use">
<a
href={`${appBaseUrl}/envs/current/features/by-key/${feature.key}`}
target="_blank"
Expand Down
4 changes: 4 additions & 0 deletions packages/browser-sdk/src/toolbar/Toolbar.css
Original file line number Diff line number Diff line change
Expand Up @@ -161,3 +161,7 @@
box-shadow: var(--border-color) -1px 1px 1px 0px;
}
}

.in-use-show-all {
cursor: pointer;
}
11 changes: 7 additions & 4 deletions packages/browser-sdk/src/toolbar/Toolbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export type FeatureItem = {
key: string;
localOverride: boolean | null;
isEnabled: boolean;
inUse: boolean;
};
export interface ToolbarPosition {
placement: DialogPlacement;
Expand All @@ -25,6 +26,7 @@ type Feature = {
key: string;
isEnabled: boolean;
localOverride: boolean | null;
inUse: boolean;
};

export default function Toolbar({
Expand All @@ -46,8 +48,9 @@ export default function Toolbar({
(feature) =>
({
key: feature.key,
localOverride: bucketClient.getFeatureOverride(feature?.key),
localOverride: feature.isEnabledOverride,
isEnabled: feature.isEnabled,
inUse: feature.inUse,
}) satisfies FeatureItem,
),
);
Expand Down Expand Up @@ -101,9 +104,9 @@ export default function Toolbar({
<DialogContent>
<FeaturesTable
features={searchedFeatures}
setEnabledOverride={bucketClient.setFeatureOverride.bind(
bucketClient,
)}
setEnabledOverride={(key: string, value: boolean | null) =>
bucketClient.getFeature(key).setIsEnabledOverride(value)
}
appBaseUrl={appBaseUrl}
/>
</DialogContent>
Expand Down
2 changes: 1 addition & 1 deletion packages/browser-sdk/test/client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ describe("BucketClient", () => {
await client.initialize();
expect(featuresResult["featureA"].isEnabled).toBe(true);
expect(client.getFeature("featureA").isEnabled).toBe(true);
client.setFeatureOverride("featureA", false);
client.getFeature("featureA").setIsEnabledOverride(false);
expect(client.getFeature("featureA").isEnabled).toBe(false);
});
});
Expand Down
18 changes: 13 additions & 5 deletions packages/react-sdk/dev/plain/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
// Extending the Features interface to define the available features
declare module "../../src" {
interface Features {
huddles: boolean;
huddles: { optInCopy: string };
}
}

Expand Down Expand Up @@ -185,20 +185,27 @@ function Demos() {
);
}

function FeatureOptIn({
// type KeysOfValue<T, TCondition> = {
// [K in keyof T]: T[K] extends TCondition ? K : never;
// }[keyof T];

// type OptInFeature = KeysOfValue<Features, { optInCopy: any }>;

function FeatureOptIn<TKey extends FeatureKey>({
featureKey,
featureName,
}: {
featureKey: FeatureKey;
featureKey: TKey;
featureName: string;
}) {
const updateUser = useUpdateUser();
const [sendingUpdate, setSendingUpdate] = useState(false);
const { isEnabled } = useFeature(featureKey);
const { isEnabled, config } = useFeature(featureKey);

return (
<div>
<label htmlFor="huddlesOptIn">Opt-in to {featureName} feature</label>
<span>{config.payload?.optInCopy ?? "Hit the checkbox to opt-in"}</span>
<input
disabled={sendingUpdate}
id="huddlesOptIn"
Expand All @@ -222,12 +229,13 @@ export function App() {
<BucketProvider
publishableKey={publishableKey}
feedback={{
enableLiveSatisfaction: true,
enableAutoFeedback: true,
}}
company={initialCompany}
user={initialUser}
otherContext={initialOtherContext}
apiBaseUrl={apiBaseUrl}
// toolbar={true}
>
<Demos />
{}
Expand Down
9 changes: 9 additions & 0 deletions packages/react-sdk/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,15 @@ export function useFeature<TKey extends FeatureKey>(
const requestFeedback = (opts: RequestFeedbackOptions) =>
client?.requestFeedback({ ...opts, featureKey: key });

// mark the feature as in use on the page
useEffect(() => {
client?.getFeature(key).setInUse(true);

return () => {
client?.getFeature(key).setInUse(false);
};
}, [key, client]);

if (isLoading || !client) {
return {
isLoading,
Expand Down