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

Skip to content

Commit 352a462

Browse files
committed
Merge branch 'main' into buc-3198-extend-the-web-sdks-to-expose-the-config
2 parents 7c6c47c + 912ef97 commit 352a462

File tree

5 files changed

+150
-21
lines changed

5 files changed

+150
-21
lines changed

.vscode/settings.json

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,5 @@
3939
"**/*.lock": true
4040
},
4141
"typescript.tsdk": "node_modules/typescript/lib",
42-
"cSpell.words": [
43-
"bucketco",
44-
"openfeature"
45-
]
42+
"cSpell.words": ["bucketco", "openfeature"]
4643
}

packages/browser-sdk/README.md

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,15 +118,26 @@ If you supply `user` or `company` objects, they must include at least the `id` p
118118
In addition to the `id`, you must also supply anything additional that you want to be able to evaluate feature targeting rules against.
119119

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

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

125127
```ts
126128
const bucketClient = new BucketClient({
127129
publishableKey,
128-
user: { id: "user_123", name: "John Doe", email: "[email protected]" },
129-
company: { id: "company_123", name: "Acme, Inc" },
130+
user: {
131+
id: "user_123",
132+
name: "John Doe",
133+
134+
avatar: "https://example.com/images/udsy6363"
135+
},
136+
company: {
137+
id: "company_123",
138+
name: "Acme, Inc",
139+
avatar: "https://example.com/images/31232ds"
140+
},
130141
});
131142
```
132143

packages/browser-sdk/src/client.ts

Lines changed: 93 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,87 +24,162 @@ import { showToolbarToggle } from "./toolbar";
2424
const isMobile = typeof window !== "undefined" && window.innerWidth < 768;
2525
const isNode = typeof document === "undefined"; // deno supports "window" but not "document" according to https://remix.run/docs/en/main/guides/gotchas
2626

27+
/**
28+
* (Internal) User context.
29+
*
30+
* @internal
31+
*/
2732
export type User = {
2833
/**
29-
* Identifier of the user
34+
* Identifier of the user.
3035
*/
3136
userId: string;
3237

3338
/**
34-
* User attributes
39+
* User attributes.
3540
*/
3641
attributes?: {
42+
/**
43+
* Name of the user.
44+
*/
3745
name?: string;
46+
47+
/**
48+
* Email of the user.
49+
*/
50+
email?: string;
51+
52+
/**
53+
* Avatar URL of the user.
54+
*/
55+
avatar?: string;
56+
57+
/**
58+
* Custom attributes of the user.
59+
*/
3860
[key: string]: any;
3961
};
4062

63+
/**
64+
* Custom context of the user.
65+
*/
4166
context?: PayloadContext;
4267
};
4368

69+
/**
70+
* (Internal) Company context.
71+
*
72+
* @internal
73+
*/
4474
export type Company = {
4575
/**
46-
* User identifier
76+
* User identifier.
4777
*/
4878
userId: string;
4979

5080
/**
51-
* Company identifier
81+
* Company identifier.
5282
*/
5383
companyId: string;
5484

5585
/**
56-
* Company attributes
86+
* Company attributes.
5787
*/
5888
attributes?: {
89+
/**
90+
* Name of the company.
91+
*/
5992
name?: string;
93+
94+
/**
95+
* Custom attributes of the company.
96+
*/
6097
[key: string]: any;
6198
};
6299

63100
context?: PayloadContext;
64101
};
65102

103+
/**
104+
* Tracked event.
105+
*/
66106
export type TrackedEvent = {
67107
/**
68-
* Event name
108+
* Event name.
69109
*/
70110
event: string;
71111

72112
/**
73-
* User identifier
113+
* User identifier.
74114
*/
75115
userId: string;
76116

77117
/**
78-
* Company identifier
118+
* Company identifier.
79119
*/
80120
companyId?: string;
81121

82122
/**
83-
* Event attributes
123+
* Event attributes.
84124
*/
85125
attributes?: Record<string, any>;
86126

127+
/**
128+
* Custom context of the event.
129+
*/
87130
context?: PayloadContext;
88131
};
89132

133+
/**
134+
* (Internal) Custom context of the event.
135+
*
136+
* @internal
137+
*/
90138
export type PayloadContext = {
139+
/**
140+
* Whether the company and user associated with the event are active.
141+
*/
91142
active?: boolean;
92143
};
93144

145+
/**
146+
* BucketClient configuration.
147+
*/
94148
interface Config {
149+
/**
150+
* Base URL of Bucket servers.
151+
*/
95152
apiBaseUrl: string;
153+
154+
/**
155+
* Base URL of the Bucket web app.
156+
*/
96157
appBaseUrl: string;
158+
159+
/**
160+
* Base URL of Bucket servers for SSE connections used by AutoFeedback.
161+
*/
97162
sseBaseUrl: string;
163+
164+
/**
165+
* Whether to enable tracking.
166+
*/
98167
enableTracking: boolean;
99168
}
100169

170+
/**
171+
* Toolbar options.
172+
*/
101173
export type ToolbarOptions =
102174
| boolean
103175
| {
104176
show?: boolean;
105177
position?: ToolbarPosition;
106178
};
107179

180+
/**
181+
* Feature definitions.
182+
*/
108183
export type FeatureDefinitions = Readonly<Array<string>>;
109184

110185
/**
@@ -117,12 +192,14 @@ export interface InitOptions {
117192
publishableKey: string;
118193

119194
/**
120-
* User related context. If you provide `id` Bucket will enrich the evaluation context with user attributes on Bucket servers.
195+
* User related context. If you provide `id` Bucket will enrich the evaluation context with
196+
* user attributes on Bucket servers.
121197
*/
122198
user?: UserContext;
123199

124200
/**
125-
* Company related context. If you provide `id` Bucket will enrich the evaluation context with company attributes on Bucket servers.
201+
* Company related context. If you provide `id` Bucket will enrich the evaluation context with
202+
* company attributes on Bucket servers.
126203
*/
127204
company?: CompanyContext;
128205

@@ -182,13 +259,18 @@ export interface InitOptions {
182259
* Version of the SDK
183260
*/
184261
sdkVersion?: string;
262+
263+
/**
264+
* Whether to enable tracking. Defaults to `true`.
265+
*/
185266
enableTracking?: boolean;
186267

187268
/**
188269
* Toolbar configuration (alpha)
189270
* @ignore
190271
*/
191272
toolbar?: ToolbarOptions;
273+
192274
/**
193275
* Local-first definition of features (alpha)
194276
* @ignore
@@ -259,7 +341,6 @@ function shouldShowToolbar(opts: InitOptions) {
259341

260342
/**
261343
* BucketClient lets you interact with the Bucket API.
262-
*
263344
*/
264345
export class BucketClient {
265346
private readonly publishableKey: string;

packages/node-sdk/README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,12 @@ const boundClient = bucketClient.bindClient({
6363
id: "john_doe",
6464
name: "John Doe",
6565
66+
avatar: "https://example.com/users/jdoe",
6667
},
6768
company: {
6869
id: "acme_inc",
6970
name: "Acme, Inc.",
71+
avatar: "https://example.com/companies/acme",
7072
},
7173
});
7274

@@ -242,7 +244,7 @@ See [example/app.ts](https://github.com/bucketco/bucket-javascript-sdk/tree/main
242244
## Remote flag evaluation with stored context
243245
244246
If you don't want to provide context each time when evaluating feature flags but
245-
rather you would like to utilise the attributes you sent to Bucket previously
247+
rather you would like to utilize the attributes you sent to Bucket previously
246248
(by calling `updateCompany` and `updateUser`) you can do so by calling `getFeaturesRemote`
247249
(or `getFeatureRemote` for a specific feature) with providing just `userId` and `companyId`.
248250
These methods will call Bucket's servers and feature flags will be evaluated remotely
@@ -368,6 +370,7 @@ to provide for easier navigation:
368370
369371
- `name` -- display name for `user`/`company`,
370372
- `email` -- the email of the user.
373+
- `avatar` -- the URL for `user`/`company` avatar image.
371374
372375
Attributes cannot be nested (multiple levels) and must be either strings,
373376
integers or booleans.

packages/node-sdk/src/types.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,19 +402,56 @@ export type Context = {
402402
* The user context. If no `id` key is set, the whole object is ignored.
403403
*/
404404
user?: {
405+
/**
406+
* The identifier of the user.
407+
*/
405408
id: string | number | undefined;
409+
410+
/**
411+
* The name of the user.
412+
*/
406413
name?: string | undefined;
414+
415+
/**
416+
* The email of the user.
417+
*/
407418
email?: string | undefined;
419+
420+
/**
421+
* The avatar URL of the user.
422+
*/
423+
avatar?: string | undefined;
424+
425+
/**
426+
* Custom attributes of the user.
427+
*/
408428
[k: string]: any;
409429
};
410430
/**
411431
* The company context. If no `id` key is set, the whole object is ignored.
412432
*/
413433
company?: {
434+
/**
435+
* The identifier of the company.
436+
*/
414437
id: string | number | undefined;
438+
439+
/**
440+
* The name of the company.
441+
*/
415442
name?: string | undefined;
443+
444+
/**
445+
* The avatar URL of the company.
446+
*/
447+
avatar?: string | undefined;
448+
449+
/**
450+
* Custom attributes of the company.
451+
*/
416452
[k: string]: any;
417453
};
454+
418455
/**
419456
* The other context. This is used for any additional context that is not related to user or company.
420457
*/

0 commit comments

Comments
 (0)