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(browser-sdk,node-sdk): add avatar support for user and company c…
…ontexts (#297)

- Updated README files to document new `avatar` attribute
- Added `avatar` to user and company context types in browser and node
SDKs
- Expanded documentation for special attributes in context objects
- Added type definitions for avatar in relevant type files
  • Loading branch information
pavkam authored and roncohen committed Feb 4, 2025
commit f13880ae6de016e48ad86bbcda08f11e473a4982
5 changes: 4 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,8 @@
"**/node_modules": true,
"**/*.lock": true
},
"typescript.tsdk": "node_modules/typescript/lib"
"typescript.tsdk": "node_modules/typescript/lib",
"cSpell.words": [
"bucketco"
]
}
19 changes: 15 additions & 4 deletions packages/browser-sdk/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,15 +109,26 @@ If you supply `user` or `company` objects, they must include at least the `id` p
In addition to the `id`, you must also supply anything additional that you want to be able to evaluate feature targeting rules against.

Attributes cannot be nested (multiple levels) and must be either strings, integers or booleans.
Some attributes are special and used in Bucket UI:

- `name` is a special attribute and is used to display name for user/company
- for `user`, `email` is also special and will be highlighted in the Bucket UI if available
- `name` is used to display name for `user`/`company`,
- `email` is accepted for `user`s and will be highlighted in the Bucket UI if available,
- `avatar` can be provided for both `user` and `company` and should be an URL to an image.

```ts
const bucketClient = new BucketClient({
publishableKey,
user: { id: "user_123", name: "John Doe", email: "[email protected]" },
company: { id: "company_123", name: "Acme, Inc" },
user: {
id: "user_123",
name: "John Doe",
email: "[email protected]"
avatar: "https://example.com/images/udsy6363"
},
company: {
id: "company_123",
name: "Acme, Inc",
avatar: "https://example.com/images/31232ds"
},
});
```

Expand Down
106 changes: 94 additions & 12 deletions packages/browser-sdk/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,79 +22,149 @@ import { Logger, loggerWithPrefix, quietConsoleLogger } from "./logger";
const isMobile = typeof window !== "undefined" && window.innerWidth < 768;
const isNode = typeof document === "undefined"; // deno supports "window" but not "document" according to https://remix.run/docs/en/main/guides/gotchas

/**
* (Internal) User context.
*
* @internal
*/
export type User = {
/**
* Identifier of the user
* Identifier of the user.
*/
userId: string;

/**
* User attributes
* User attributes.
*/
attributes?: {
/**
* Name of the user.
*/
name?: string;

/**
* Email of the user.
*/
email?: string;

/**
* Avatar URL of the user.
*/
avatar?: string;

/**
* Custom attributes of the user.
*/
[key: string]: any;
};

/**
* Custom context of the user.
*/
context?: PayloadContext;
};

/**
* (Internal) Company context.
*
* @internal
*/
export type Company = {
/**
* User identifier
* User identifier.
*/
userId: string;

/**
* Company identifier
* Company identifier.
*/
companyId: string;

/**
* Company attributes
* Company attributes.
*/
attributes?: {
/**
* Name of the company.
*/
name?: string;

/**
* Custom attributes of the company.
*/
[key: string]: any;
};

context?: PayloadContext;
};

/**
* Tracked event.
*/
export type TrackedEvent = {
/**
* Event name
* Event name.
*/
event: string;

/**
* User identifier
* User identifier.
*/
userId: string;

/**
* Company identifier
* Company identifier.
*/
companyId?: string;

/**
* Event attributes
* Event attributes.
*/
attributes?: Record<string, any>;

/**
* Custom context of the event.
*/
context?: PayloadContext;
};

/**
* (Internal) Custom context of the event.
*
* @internal
*/
export type PayloadContext = {
/**
* Whether the company and user associated with the event are active.
*/
active?: boolean;
};

/**
* BucketClient configuration.
*/
interface Config {
/**
* Base URL of Bucket servers.
*/
apiBaseUrl: string;

/**
* Base URL of Bucket servers for SSE connections used by AutoFeedback.
*/
sseBaseUrl: string;

/**
* Whether to enable tracking.
*/
enableTracking: boolean;
}

/**
* Feature definitions.
*/
export type FeatureDefinitions = Readonly<Array<string>>;

/**
* BucketClient initialization options.
*/
Expand All @@ -105,12 +175,14 @@ export interface InitOptions {
publishableKey: string;

/**
* User related context. If you provide `id` Bucket will enrich the evaluation context with user attributes on Bucket servers.
* User related context. If you provide `id` Bucket will enrich the evaluation context with
* user attributes on Bucket servers.
*/
user?: UserContext;

/**
* Company related context. If you provide `id` Bucket will enrich the evaluation context with company attributes on Bucket servers.
* Company related context. If you provide `id` Bucket will enrich the evaluation context with
* company attributes on Bucket servers.
*/
company?: CompanyContext;

Expand Down Expand Up @@ -165,6 +237,10 @@ export interface InitOptions {
* Version of the SDK
*/
sdkVersion?: string;

/**
* Whether to enable tracking. Defaults to `true`.
*/
enableTracking?: boolean;
}

Expand All @@ -174,6 +250,9 @@ const defaultConfig: Config = {
enableTracking: true,
};

/**
* Represents a feature.
*/
export interface Feature {
/**
* Result of feature flag evaluation
Expand All @@ -185,13 +264,16 @@ export interface Feature {
*
*/
track: () => Promise<Response | undefined>;

/**
* Function to request feedback for this feature.
*/
requestFeedback: (
options: Omit<RequestFeedbackData, "featureKey" | "featureId">,
) => void;
}
/**
* BucketClient lets you interact with the Bucket API.
*
*/
export class BucketClient {
private publishableKey: string;
Expand Down
5 changes: 4 additions & 1 deletion packages/node-sdk/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,12 @@ const boundClient = bucketClient.bindClient({
id: "john_doe",
name: "John Doe",
email: "[email protected]",
avatar: "https://example.com/users/jdoe",
},
company: {
id: "acme_inc",
name: "Acme, Inc.",
avatar: "https://example.com/companies/acme",
},
});

Expand Down Expand Up @@ -242,7 +244,7 @@ See [example/app.ts](https://github.com/bucketco/bucket-javascript-sdk/tree/main
## Remote flag evaluation with stored context

If you don't want to provide context each time when evaluating feature flags but
rather you would like to utilise the attributes you sent to Bucket previously
rather you would like to utilize the attributes you sent to Bucket previously
(by calling `updateCompany` and `updateUser`) you can do so by calling `getFeaturesRemote`
(or `getFeatureRemote` for a specific feature) with providing just `userId` and `companyId`.
These methods will call Bucket's servers and feature flags will be evaluated remotely
Expand Down Expand Up @@ -368,6 +370,7 @@ to provide for easier navigation:

- `name` -- display name for `user`/`company`,
- `email` -- the email of the user.
- `avatar` -- the URL for `user`/`company` avatar image.

Attributes cannot be nested (multiple levels) and must be either strings,
integers or booleans.
Expand Down
37 changes: 37 additions & 0 deletions packages/node-sdk/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -397,19 +397,56 @@ export type Context = {
* The user context. If no `id` key is set, the whole object is ignored.
*/
user?: {
/**
* The identifier of the user.
*/
id: string | number | undefined;

/**
* The name of the user.
*/
name?: string | undefined;

/**
* The email of the user.
*/
email?: string | undefined;

/**
* The avatar URL of the user.
*/
avatar?: string | undefined;

/**
* Custom attributes of the user.
*/
[k: string]: any;
};
/**
* The company context. If no `id` key is set, the whole object is ignored.
*/
company?: {
/**
* The identifier of the company.
*/
id: string | number | undefined;

/**
* The name of the company.
*/
name?: string | undefined;

/**
* The avatar URL of the company.
*/
avatar?: string | undefined;

/**
* Custom attributes of the company.
*/
[k: string]: any;
};

/**
* The other context. This is used for any additional context that is not related to user or company.
*/
Expand Down