Skip to content

Commit a27328c

Browse files
committed
Merge branch 'buc-3227-dogfooding-dont-require-satisfaction-score-when-asking-for' of https://github.com/bucketco/bucket-javascript-sdk into buc-3227-dogfooding-dont-require-satisfaction-score-when-asking-for
2 parents b1ad633 + f1318f6 commit a27328c

2 files changed

Lines changed: 70 additions & 76 deletions

File tree

packages/node-sdk/README.md

Lines changed: 27 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -54,22 +54,6 @@ Other supported languages/frameworks are in the [Supported languages](https://do
5454

5555
You can also [use the HTTP API directly](https://docs.reflag.com/api/http-api)
5656

57-
## Migrating from Bucket SDK
58-
59-
If you have been using the Bucket SDKs, the following list will help you migrate to Reflag SDK:
60-
61-
- `Bucket*` classes, and types have been renamed to `Reflag*` (e.g. `BucketClient` is now `ReflagClient`)
62-
- `Feature*` classes, and types have been renamed to `Feature*` (e.g. `Feature` is now `Flag`, `RawFeatures` is now `RawFlags`)
63-
- When using strongly-typed flags, the new `Flags` interface replaced `Features` interface
64-
- All methods that contained `feature` in the name have been renamed to use the `flag` terminology (e.g. `getFeature` is `getFlag`)
65-
- All environment variables that were prefixed with `BUCKET_` are now prefixed with `REFLAG_`
66-
- The `BUCKET_HOST` environment variable and `host` option have been removed from `ReflagClient` constructor, use `REFLAG_API_BASE_URL` instead
67-
- The `BUCKET_FEATURES_ENABLED` and `BUCKET_FEATURES_DISABLED` have been renamed to `REFLAG_FLAGS_ENABLED` and `REFLAG_FLAGS_DISABLED`
68-
- The default configuration file has been renamed from `bucketConfig.json` to `reflag.config.json`
69-
- The `fallbackFeatures` property in client constructor and configuration files has been renamed to `fallbackFlags`
70-
- `featureKey` has been renamed to `flagKey` in all methods that accepts that argument
71-
- The SDKs will not emit `evaluate` and `evaluate-config` events anymore
72-
7357
## Basic usage
7458

7559
To get started you need to obtain your secret key from the [environment settings](https://app.reflag.com/env-current/settings/app-environments)
@@ -98,9 +82,9 @@ export const reflagClient = new ReflagClient();
9882
// Initialize the client and begin fetching flag targeting definitions.
9983
// You must call this method prior to any calls to `getFlags()`,
10084
// otherwise an empty object will be returned.
101-
reflagClient.initialize().then({
102-
console.log("Reflag initialized!")
103-
})
85+
reflagClient.initialize().then(() => {
86+
console.log("Reflag initialized!");
87+
});
10488
```
10589

10690
Once the client is initialized, you can obtain flags along with the `isEnabled`
@@ -255,7 +239,7 @@ export default {
255239
};
256240
```
257241

258-
See [examples/cloudflare-worker](examples/cloudflare-worker/src/index.ts) for a deployable example.
242+
See [examples/cloudflare-worker](https://github.com/reflagcom/javascript/tree/main/packages/node-sdk/examples/cloudflare-worker/src/index.ts) for a deployable example.
259243

260244
Reflag maintains a cached set of flag definitions in the memory of your worker which it uses to decide which flags to turn on for which users/companies.
261245

@@ -277,14 +261,11 @@ fallback behavior:
277261

278262
```typescript
279263
// Network errors during tracking are logged but don't affect your application
280-
const { track } = client.getFlag("my-flag");
264+
const { isEnabled, track } = client.getFlag("my-flag");
281265
if (isEnabled) {
282-
try {
283-
await track();
284-
} catch (error) {
285-
// The SDK already logged this error
286-
// Your application can continue normally
287-
}
266+
// network errors are caught internally and logged and never bubbled up to your application
267+
// no need to try/catch around "track" or "getFlag"
268+
await track();
288269
}
289270
```
290271

@@ -633,12 +614,12 @@ app.use((req, res, next) => {
633614
// mechanism in a real-world application
634615
const user = {
635616
id: req.user?.id,
636-
name: req.user?.name
617+
name: req.user?.name,
637618
email: req.user?.email
638619
}
639620

640621
const company = {
641-
id: req.user?.companyId
622+
id: req.user?.companyId,
642623
name: req.user?.companyName
643624
}
644625

@@ -655,7 +636,7 @@ app.use((req, res, next) => {
655636

656637
// Now use res.locals.boundReflagClient in your handlers
657638
app.get("/todos", async (_req, res) => {
658-
const { track, isEnabled } = res.locals.reflagUser.getFlag("show-todos");
639+
const { track, isEnabled } = res.locals.boundReflagClient.getFlag("show-todos");
659640

660641
if (!isEnabled) {
661642
res.status(403).send({"error": "flag inaccessible"})
@@ -835,6 +816,22 @@ import { sha256 } from 'crypto-hash';
835816
client.updateUser({ userId: await sha256("john_doe"), ... });
836817
```
837818
819+
## Migrating from Bucket SDK
820+
821+
If you have been using the Bucket SDKs previously, the following list will help you migrate to Reflag SDK:
822+
823+
- `Bucket*` classes, and types have been renamed to `Reflag*` (e.g. `BucketClient` is now `ReflagClient`)
824+
- `Feature*` classes, and types have been renamed to `Flag*` (e.g. `Feature` is now `Flag`, `RawFeatures` is now `RawFlags`)
825+
- When using strongly-typed flags, the new `Flags` interface replaced `Features` interface
826+
- All methods that contained `feature` in the name have been renamed to use the `flag` terminology (e.g. `getFeature` is `getFlag`)
827+
- All environment variables that were prefixed with `BUCKET_` are now prefixed with `REFLAG_`
828+
- The `BUCKET_HOST` environment variable and `host` option have been removed from `ReflagClient` constructor, use `REFLAG_API_BASE_URL` instead
829+
- The `BUCKET_FEATURES_ENABLED` and `BUCKET_FEATURES_DISABLED` have been renamed to `REFLAG_FLAGS_ENABLED` and `REFLAG_FLAGS_DISABLED`
830+
- The default configuration file has been renamed from `bucketConfig.json` to `reflag.config.json`
831+
- The `fallbackFeatures` property in client constructor and configuration files has been renamed to `fallbackFlags`
832+
- `featureKey` has been renamed to `flagKey` in all methods that accepts that argument
833+
- The SDKs will not emit `evaluate` and `evaluate-config` events anymore
834+
838835
## Typescript
839836
840837
Types are bundled together with the library and exposed automatically when importing

packages/react-sdk/README.md

Lines changed: 43 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -14,32 +14,6 @@ Install via npm:
1414
npm i @reflag/react-sdk
1515
```
1616

17-
## Migrating from Bucket SDK
18-
19-
If you have been using the Bucket SDKs, the following list will help you migrate to Reflag SDK:
20-
21-
- `Bucket*` classes, and types have been renamed to `Reflag*` (e.g. `BucketClient` is now `ReflagClient`)
22-
- `Feature*` classes, and types have been renamed to `Feature*` (e.g. `Feature` is now `Flag`, `RawFeatures` is now `RawFlags`)
23-
- When using strongly-typed flags, the new `Flags` interface replaced `Features` interface
24-
- All methods that contained `feature` in the name have been renamed to use the `flag` terminology (e.g. `getFeature` is `getFlag`)
25-
- The `fallbackFeatures` property in client constructor and configuration files has been renamed to `fallbackFlags`
26-
- `featureKey` has been renamed to `flagKey` in all methods that accepts that argument
27-
- The SDKs will not emit `evaluate` and `evaluate-config` events anymore
28-
- The new cookies that are stored in the client's browser are now `reflag-*` prefixed instead og `bucket-*`
29-
- The `featuresUpdated` hook has been renamed to `flagsUpdated`
30-
- The `checkIsEnabled` and `checkConfig` hooks have been removed, use `check` from now on
31-
32-
To ease in transition to Reflag SDK, some of the old methods have been preserved as aliases to the new methods:
33-
34-
- `getFeature` method is an alias for `getFlag`
35-
- `getFeatures` method is an alias for `getFlags`
36-
- `useFeature` method is an alias for `useFlag`
37-
- `featuresUpdated` hook is an alias for `flagsUpdated`
38-
39-
If you are running with strict Content Security Policies active on your website, you will need change them as follows:
40-
41-
- `connect-src https://front.bucket.co` to `connect-src https://front.reflag.com`
42-
4317
## Get started
4418

4519
### 1. Add the `ReflagProvider` context provider
@@ -133,16 +107,16 @@ A number of special attributes exist:
133107
- `avatar` -- the URL for `user`/`company` avatar image.
134108

135109
```tsx
136-
<ReflagProvider
137-
publishableKey={YOUR_PUBLISHABLE_KEY}
138-
user={{ id: "user_123", name: "John Doe", email: "john@acme.com" }}
139-
company={{ id: "company_123", name: "Acme, Inc" }}
140-
otherContext={{ completedSteps: [1, 4, 7] }}
141-
>
142-
<LoadingReflag>
110+
<ReflagProvider
111+
publishableKey={YOUR_PUBLISHABLE_KEY}
112+
user={{ id: "user_123", name: "John Doe", email: "john@acme.com" }}
113+
company={{ id: "company_123", name: "Acme, Inc" }}
114+
otherContext={{ completedSteps: [1, 4, 7] }}
115+
>
116+
<LoadingReflag>
143117
{/* children here are shown when loading finishes */}
144-
</LoadingReflag>
145-
<ReflagProvider>
118+
</LoadingReflag>
119+
</ReflagProvider>
146120
```
147121

148122
To retrieve flags along with their targeting information, use `useFlag(key: string)` hook (described in a section below).
@@ -229,20 +203,20 @@ The `<ReflagProvider>` initializes the Reflag SDK, fetches flags and starts list
229203
230204
```tsx
231205
function LoadingReflag({ children }) {
232-
const { isLoading } = useFlag("myFlag")
206+
const { isLoading } = useFlag("myFlag");
233207
if (isLoading) {
234-
return <Spinner />
208+
return <Spinner />;
235209
}
236210

237-
return children
211+
return children;
238212
}
239213

240214
//-- Initialize the Reflag provider
241215
<ReflagProvider publishableKey={YOUR_PUBLISHABLE_KEY} /*...*/>
242216
<LoadingReflag>
243-
{/* children here are shown when loading finishes */}
217+
{/* children here are shown when loading finishes */}
244218
</LoadingReflag>
245-
<ReflagProvider>
219+
</ReflagProvider>;
246220
```
247221
248222
- `enableTracking`: Set to `false` to stop sending tracking events and user/company updates to Reflag. Useful when you're impersonating a user (defaults to `true`),
@@ -306,13 +280,13 @@ function StartHuddleButton() {
306280
307281
### `useTrack()`
308282
309-
`useTrack()` lets you send custom events to Reflag. Use this whenever a user _uses_ a feature. Create [features](https://docs.reflag.com/introduction/concepts/feature) in Reflag based off of these events to analyze feature usage.
310-
Returns a function to send custom events to Reflag. Use this whenever a user _uses_ a feature. These events can be used to analyze feature usage and create new flags in Reflag.
283+
`useTrack()` lets you send custom events to Reflag. Use this whenever a user _uses_ a feature. These events can be used to analyze feature usage in Reflag.
311284
312285
```tsx
313286
import { useTrack } from "@reflag/react-sdk";
314287

315288
function StartHuddle() {
289+
const { track } = useTrack();
316290
<div>
317291
<button onClick={() => track("Huddle Started", { huddleType: "voice" })}>
318292
Start voice huddle!
@@ -323,10 +297,7 @@ function StartHuddle() {
323297
324298
### `useRequestFeedback()`
325299
326-
Returns a function that lets you open up a dialog to ask for feedback on a specific feature. This is useful for collecting targeted feedback about specific features.
327-
328-
`useRequestFeedback()` returns a function that lets you open up a dialog to ask for feedback on a specific feature.
329-
See [Automated Feedback Surveys](https://docs.reflag.com/product-handbook/live-satisfaction) for how to do this automatically, without code.
300+
`useRequestFeedback()` returns a function that lets you open up a dialog to ask for feedback on a specific feature. This is useful for collecting targeted feedback about specific features as part of roll out. See [Automated Feedback Surveys](https://docs.reflag.com/product-handbook/live-satisfaction) for how to do this automatically, without code.
330301
331302
When using the `useRequestFeedback` you must pass the flag key to `requestFeedback`.
332303
The example below shows how to use `position` to ensure the popover appears next to the "Give feedback!" button.
@@ -454,6 +425,32 @@ function LoggingWrapper({ children }: { children: ReactNode }) {
454425
}
455426
```
456427
428+
## Migrating from Bucket SDK
429+
430+
If you have been using the Bucket SDKs, the following list will help you migrate to Reflag SDK:
431+
432+
- `Bucket*` classes, and types have been renamed to `Reflag*` (e.g. `BucketClient` is now `ReflagClient`)
433+
- `Feature*` classes, and types have been renamed to `Flag*` (e.g. `Feature` is now `Flag`, `RawFeatures` is now `RawFlags`)
434+
- When using strongly-typed flags, the new `Flags` interface replaced `Features` interface
435+
- All methods that contained `feature` in the name have been renamed to use the `flag` terminology (e.g. `getFeature` is `getFlag`)
436+
- The `fallbackFeatures` property in client constructor and configuration files has been renamed to `fallbackFlags`
437+
- `featureKey` has been renamed to `flagKey` in all methods that accepts that argument
438+
- The SDKs will not emit `evaluate` and `evaluate-config` events anymore
439+
- The new cookies that are stored in the client's browser are now `reflag-*` prefixed instead of `bucket-*`
440+
- The `featuresUpdated` hook has been renamed to `flagsUpdated`
441+
- The `checkIsEnabled` and `checkConfig` hooks have been removed, use `check` from now on
442+
443+
To ease in transition to Reflag SDK, some of the old methods have been preserved as aliases to the new methods:
444+
445+
- `getFeature` method is an alias for `getFlag`
446+
- `getFeatures` method is an alias for `getFlags`
447+
- `useFeature` method is an alias for `useFlag`
448+
- `featuresUpdated` hook is an alias for `flagsUpdated`
449+
450+
If you are running with strict Content Security Policies active on your website, you will need change them as follows:
451+
452+
- `connect-src https://front.bucket.co` to `connect-src https://front.reflag.com`
453+
457454
## Content Security Policy (CSP)
458455

459456
See [CSP](https://github.com/reflagcom/javascript/blob/main/packages/browser-sdk/README.md#content-security-policy-csp) for info on using Reflag React SDK with CSP

0 commit comments

Comments
 (0)