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
fix(browser-sdk,react-sdk): remove featureId option for requestFeedba…
…ck (#309)

Remove legacy `featureId` option when using the `requestFeedback` and
`feedback` methods

The actual feedback payload can still contain the featureId because
bucket's prompting message do not include the feature key.
  • Loading branch information
roncohen authored Feb 13, 2025
commit adf6fe8950616ea34e809b2ca6043e44eb47f3d9
31 changes: 12 additions & 19 deletions packages/browser-sdk/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {
Feedback,
feedback,
FeedbackOptions,
handleDeprecatedFeedbackOptions,
RequestFeedbackData,
RequestFeedbackOptions,
} from "./feedback/feedback";
Expand Down Expand Up @@ -384,11 +383,9 @@ export class BucketClient {
enableTracking: opts?.enableTracking ?? defaultConfig.enableTracking,
};

const feedbackOpts = handleDeprecatedFeedbackOptions(opts?.feedback);

this.requestFeedbackOptions = {
position: feedbackOpts?.ui?.position,
translations: feedbackOpts?.ui?.translations,
position: opts?.feedback?.ui?.position,
translations: opts?.feedback?.ui?.translations,
};

this.httpClient = new HttpClient(this.publishableKey, {
Expand Down Expand Up @@ -416,7 +413,7 @@ export class BucketClient {
if (
this.context?.user &&
!isNode && // do not prompt on server-side
feedbackOpts?.enableAutoFeedback !== false // default to on
opts?.feedback?.enableAutoFeedback !== false // default to on
) {
if (isMobile) {
this.logger.warn(
Expand All @@ -427,18 +424,18 @@ export class BucketClient {
this.config.sseBaseUrl,
this.logger,
this.httpClient,
feedbackOpts?.autoFeedbackHandler,
opts?.feedback?.autoFeedbackHandler,
String(this.context.user?.id),
feedbackOpts?.ui?.position,
feedbackOpts?.ui?.translations,
opts?.feedback?.ui?.position,
opts?.feedback?.ui?.translations,
);
}
}

if (shouldShowToolbar(opts)) {
this.logger.info("opening toolbar toggler");
showToolbarToggle({
bucketClient: this as unknown as BucketClient,
bucketClient: this,
position:
typeof opts.toolbar === "object" ? opts.toolbar.position : undefined,
});
Expand Down Expand Up @@ -621,32 +618,28 @@ export class BucketClient {
return;
}

const featureId = "featureId" in options ? options.featureId : undefined;
const featureKey = "featureKey" in options ? options.featureKey : undefined;

if (!featureId && !featureKey) {
if (!options.featureKey) {
this.logger.error(
"`requestFeedback` call ignored. No `featureId` or `featureKey` provided",
"`requestFeedback` call ignored. No `featureKey` provided",
);
return;
}

const feedbackData = {
featureId,
featureKey,
featureKey: options.featureKey,
companyId:
options.companyId ||
(this.context.company?.id
? String(this.context.company?.id)
: undefined),
source: "widget" as const,
} as Feedback;
} satisfies Feedback;

// Wait a tick before opening the feedback form,
// to prevent the same click from closing it.
setTimeout(() => {
feedbackLib.openFeedbackForm({
key: (featureKey || featureId)!,
key: options.featureKey,
title: options.title,
position: options.position || this.requestFeedbackOptions.position,
translations:
Expand Down
63 changes: 21 additions & 42 deletions packages/browser-sdk/src/feedback/feedback.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,46 +45,8 @@ export type FeedbackOptions = {
*/
translations?: Partial<FeedbackTranslations>;
};

/**
* @deprecated Use `enableAutoFeedback` instead
*/
enableLiveSatisfaction?: boolean;

/**
* @deprecated Use `autoFeedbackHandler` instead
*/
liveSatisfactionHandler?: FeedbackPromptHandler;
};

export function handleDeprecatedFeedbackOptions(
opts?: FeedbackOptions,
): FeedbackOptions {
return {
...opts,
enableAutoFeedback:
opts?.enableAutoFeedback ?? opts?.enableLiveSatisfaction,
autoFeedbackHandler:
opts?.autoFeedbackHandler ?? opts?.liveSatisfactionHandler,
};
}

type FeatureIdentifier =
| {
/**
* Bucket feature ID.
*
* @deprecated use `feedbackId` instead.
*/
featureId: string;
}
| {
/**
* Bucket feature key.
*/
featureKey: string;
};

export type RequestFeedbackData = Omit<
OpenFeedbackFormOptions,
"key" | "onSubmit"
Expand All @@ -105,7 +67,12 @@ export type RequestFeedbackData = Omit<
* @param data.
*/
onAfterSubmit?: (data: FeedbackSubmission) => void;
} & FeatureIdentifier;

/**
* Bucket feature key.
*/
featureKey: string;
};

export type RequestFeedbackOptions = RequestFeedbackData & {
/**
Expand All @@ -115,6 +82,11 @@ export type RequestFeedbackOptions = RequestFeedbackData & {
};

export type UnassignedFeedback = {
/**
* Bucket feature key.
*/
featureKey: string;

/**
* Bucket feedback ID
*/
Expand Down Expand Up @@ -159,7 +131,7 @@ export type UnassignedFeedback = {
* - `sdk` - Feedback submitted via `feedback`
*/
source?: "prompt" | "sdk" | "widget";
} & FeatureIdentifier;
};

export type Feedback = UnassignedFeedback & {
/**
Expand Down Expand Up @@ -242,10 +214,17 @@ export const DEFAULT_FEEDBACK_CONFIG = {
autoFeedbackEnabled: true,
};

// Payload can include featureId or featureKey, but the public API only exposes featureKey
// We use featureId internally because prompting is based on featureId
type FeedbackPayload = Omit<Feedback, "featureKey"> & {
featureId?: string;
featureKey?: string;
};

export async function feedback(
httpClient: HttpClient,
logger: Logger,
payload: Feedback,
payload: FeedbackPayload,
) {
if (!payload.score && !payload.comment) {
logger.error(
Expand Down Expand Up @@ -435,7 +414,7 @@ export class AutoFeedback {
question: reply.question,
promptedQuestion: message.question,
source: "prompt",
} satisfies Feedback;
} satisfies FeedbackPayload;

const response = await feedback(
this.httpClient,
Expand Down
2 changes: 0 additions & 2 deletions packages/browser-sdk/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// import "preact/debug";

export type { Feature, InitOptions, ToolbarOptions } from "./client";
export { BucketClient } from "./client";
export type { BucketContext, CompanyContext, UserContext } from "./context";
Expand Down
10 changes: 5 additions & 5 deletions packages/browser-sdk/test/e2e/feedback-widget.browser.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ async function getOpenedWidgetContainer(
const bucket = new BucketClient({publishableKey: "${KEY}", user: {id: "foo"}, company: {id: "bar"}, ...${JSON.stringify(initOptions ?? {})}});
await bucket.initialize();
await bucket.requestFeedback({
featureId: "featureId1",
featureKey: "feature1",
title: "baz",
});
})()
Expand Down Expand Up @@ -90,7 +90,7 @@ async function getGiveFeedbackPageContainer(
document.querySelector("#give-feedback-button")?.addEventListener("click", () => {
console.log("cliked!");
bucket.requestFeedback({
featureId: "featureId1",
featureKey: "feature1",
title: "baz",
});
});
Expand Down Expand Up @@ -250,7 +250,7 @@ test("Sends a request when choosing a score immediately", async ({ page }) => {
.poll(() => sentJSON)
.toEqual({
companyId: "bar",
featureId: "featureId1",
key: "feature1",
score: expectedScore,
question: "baz",
userId: "foo",
Expand Down Expand Up @@ -309,7 +309,7 @@ test("Updates the score on every change", async ({ page }) => {
.toEqual({
feedbackId: "123",
companyId: "bar",
featureId: "featureId1",
key: "feature1",
question: "baz",
score: 3,
userId: "foo",
Expand Down Expand Up @@ -369,7 +369,7 @@ test("Sends a request with both the score and comment when submitting", async ({
score: expectedScore,
companyId: "bar",
question: "baz",
featureId: "featureId1",
key: "feature1",
feedbackId: "123",
userId: "foo",
source: "widget",
Expand Down
14 changes: 7 additions & 7 deletions packages/browser-sdk/test/mocks/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export const handlers = [
!data["userId"] ||
!data["attributes"]
) {
return new HttpResponse(null, { status: 400 });
return HttpResponse.error();
}

return HttpResponse.json({
Expand All @@ -106,7 +106,7 @@ export const handlers = [
!data["companyId"] ||
!data["attributes"]
) {
return new HttpResponse(null, { status: 400 });
return HttpResponse.error();
}

return HttpResponse.json({
Expand All @@ -118,7 +118,7 @@ export const handlers = [
const data = await request.json();

if (typeof data !== "object" || !data || !data["userId"]) {
return new HttpResponse(null, { status: 400 });
return HttpResponse.error();
}

return HttpResponse.json({
Expand All @@ -130,7 +130,7 @@ export const handlers = [
const data = await request.json();

if (typeof data !== "object" || !data || !data["userId"]) {
return new HttpResponse(null, { status: 400 });
return HttpResponse.error();
}

return HttpResponse.json({
Expand All @@ -145,9 +145,9 @@ export const handlers = [
!data ||
!data["userId"] ||
typeof data["score"] !== "number" ||
(!data["featureId"] && !data["featureKey"])
(!data["featureId"] && !data["key"])
) {
return new HttpResponse(null, { status: 400 });
return HttpResponse.error();
}

return HttpResponse.json({
Expand All @@ -173,7 +173,7 @@ export const handlers = [
async ({ request }) => {
const data = await request.json();
if (typeof data !== "object") {
return new HttpResponse(null, { status: 400 });
return HttpResponse.error();
}

return HttpResponse.json({
Expand Down
2 changes: 1 addition & 1 deletion packages/browser-sdk/test/usage.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ describe("usage", () => {
await bucketInstance.track("baz", { baz: true });

await bucketInstance.feedback({
featureId: "featureId1",
featureKey: "huddles",
score: 5,
comment: "Sunt bine!",
question: "Cum esti?",
Expand Down
4 changes: 2 additions & 2 deletions packages/react-sdk/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ export function useTrack() {
* ```ts
* const requestFeedback = useRequestFeedback();
* bucket.requestFeedback({
* featureId: "bucket-feature-id",
* featureKey: "file-uploads",
* title: "How satisfied are you with file uploads?",
* });
* ```
Expand All @@ -269,7 +269,7 @@ export function useRequestFeedback() {
* ```ts
* const sendFeedback = useSendFeedback();
* sendFeedback({
* featureId: "fe2323223";;
* featureKey: "huddle";
* question: "How did you like the new huddle feature?";
* score: 5;
* comment: "I loved it!";
Expand Down
4 changes: 2 additions & 2 deletions packages/react-sdk/test/usage.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -335,15 +335,15 @@ describe("useRequestFeedback", () => {

await waitFor(async () => {
result.current({
featureId: "123",
featureKey: "huddles",
title: "Test question",
companyId: "456",
});

expect(requestFeedback).toHaveBeenCalledOnce();
expect(requestFeedback).toHaveBeenCalledWith({
featureKey: "huddles",
companyId: "456",
featureId: "123",
title: "Test question",
});
});
Expand Down