Skip to content

Commit 23b018b

Browse files
committed
docs: write framework SDK guides for new integrations
1 parent 9f3a0ae commit 23b018b

3 files changed

Lines changed: 41 additions & 50 deletions

File tree

‎packages/browser-sdk/README.md‎

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
# Reflag Browser SDK v2
1+
# Reflag Browser SDK
22

33
Client-side feature flags and JSON values for [Reflag](https://reflag.com).
44

5-
> This is a breaking v2 prerelease. It requires the v2 evaluated-flags/check protocol on the server. Do not switch existing v1 applications or bootstrap consumers without coordinating that upgrade. Nothing in this branch publishes or deploys the SDK/server.
6-
75
## Get started
86

7+
```sh
8+
npm install @reflag/browser-sdk
9+
```
10+
911
```ts
1012
import { ReflagClient } from "@reflag/browser-sdk";
1113

@@ -28,7 +30,7 @@ if (enabled) {
2830

2931
Use only a **publishable** key in a browser. Secret keys belong on your server.
3032

31-
## Direct-value reads
33+
## Read flags
3234

3335
```ts
3436
reflag.getFlag("release"); // boolean; missing/mismatched -> false
@@ -45,11 +47,11 @@ reflag.getFlag("nullable-settings", null); // FlagValue (arbitrary JSON)
4547
- Object fields and array elements are **not schema-validated**. Validate untrusted/nested payloads in your application.
4648
- Values and defaults are returned as independent mutable copies. There are no reserved JSON property names.
4749

48-
`getFlags()` returns a direct-value record (entries may be undefined) and registers checks for its returned roots. `getFlagResults()` returns owned evaluated diagnostics **without checks**; it is intended for tooling, not ordinary application reads. `getFlagsForBootstrap()` serializes protocol-v2 evaluated state without checks.
50+
`getFlags()` returns a direct-value record (entries may be undefined) and registers checks for its returned roots. `getFlagResults()` returns owned evaluated diagnostics **without checks**; it is intended for tooling, not ordinary application reads. `getFlagsForBootstrap()` serializes evaluated state without checks.
4951

5052
## Checks and delivery
5153

52-
Calling a getter registers a requested-root check immediately, even if its return value is ignored. There are no `.isEnabled`, `.config`, `.value` or flag `.track()` wrappers. Delivery remains buffered through `/bulk` and identity-aware rate-limited.
54+
Reading a flag registers an exposure check, even if its return value is ignored. Checks are buffered, sent through `/bulk`, and rate-limited per identity.
5355

5456
A selected check carries the authored selected key as `evalResult`, its `sourceVersionId` and the available snapshot `flagStateVersion`. Payload equality is not identity: equal-valued selections or segment-only snapshot changes remain distinguishable on subsequent reads. Defaults, category mismatches, local overrides and static fallback values do not fabricate authored selections. Diagnostics and bootstrap serialization generate no checks. The server evaluates dependencies; fetching their results does not itself register reads.
5557

@@ -70,7 +72,7 @@ await reflag.refresh();
7072

7173
`setContext()` replaces the context; update methods shallow-merge their section. User/company sections require IDs, including valid numeric zero. Context supports nested JSON and arrays. A context change clears the old context's values while fetching; stale/in-flight responses cannot replace a newer context or snapshot.
7274

73-
Values come from `GET /flags/evaluated`, not legacy `/features/evaluated`. Server evaluation retains the complete internal graph and authorized public roots. The Browser SDK does not cache dependency evaluations of its own.
75+
Values come from `GET /flags/evaluated`. Server evaluation retains the complete internal graph and authorized public roots. The Browser SDK does not cache dependency evaluations of its own.
7476

7577
Constructor options include:
7678

@@ -89,7 +91,7 @@ Constructor options include:
8991
| `trackingQueue` | Buffered-delivery `flushDelayMs` and `maxSize` |
9092
| `logger`, `toolbar`, `feedback` | Logging, Boolean override toolbar and feedback options |
9193

92-
Evaluated cache and override storage use isolated v2 keys. V1 cache entries are never interpreted as v2 values. Malformed refreshes leave known-good state intact. Valid saved v2 selections retain their real provenance on restore. There is no automatic periodic HTTP fallback after an SSE failure; manual refresh/context updates remain available.
94+
Evaluated flags and overrides are cached separately. Malformed refreshes leave known-good state intact. Valid saved selections retain their provenance on restore. There is no automatic periodic HTTP fallback after an SSE failure; manual refresh/context updates remain available.
9395

9496
## Overrides and toolbar
9597

@@ -104,7 +106,7 @@ Overrides apply after server evaluation and do not rewrite authored dependency r
104106

105107
## Server bootstrap
106108

107-
Generate the full payload with **Node SDK v2** on your server:
109+
Generate the payload with the **Node.js SDK** on your server:
108110

109111
```ts
110112
const bootstrappedState = serverClient.getFlagsForBootstrap(context);
@@ -117,7 +119,7 @@ await reflag.initialize();
117119
const enabled = reflag.getFlag("release");
118120
```
119121

120-
The payload includes `protocolVersion: 2`, context, evaluated diagnostics/selections and an optional snapshot version. V1 payloads and the old `bootstrappedFlags` option are rejected. Preserve the entire envelope; do not pass just its `flags` property. A version is required for bootstrapped live updates. Never embed secrets or server-only context in public bootstrap data. Later refreshes use browser-visible context and can differ from server-only evaluation; disable live updates when that is inappropriate.
122+
The payload includes `protocolVersion: 2`, context, evaluated diagnostics/selections and an optional snapshot version. Pass the entire envelope as `bootstrappedState`, including its context and selection metadata. A version is required for bootstrapped live updates. Never embed secrets or server-only context in public bootstrap data. Later refreshes use browser-visible context and can differ from server-only evaluation; disable live updates when that is inappropriate.
121123

122124
## End-user opt-in
123125

@@ -130,19 +132,10 @@ await reflag.setOptIn("huddles", { optedIn: false, scope: "company" });
130132

131133
The list contains presentation/membership metadata (`key`, `name`, `description`, `isEnabled`, `userOptedIn`, `companyOptedIn`, `isOptedIn`); this is not the ordinary flag getter API. User/company grants remain independent. The selected scope requires its ID. Successful mutations wait for versioned evaluation and membership confirmation.
132134

133-
Metadata arrives with ordinary `/flags/evaluated` responses and is cached with the evaluated snapshot. Bootstrapped clients whose snapshot lacks metadata fetch it on demand from the same v2 endpoint, without replacing server-derived values or provenance with browser-context evaluations. Loading settles on success or failure, including an empty list. Opt-in mutations confirm values and membership together in one versioned refresh. `optInFlagsLoadingUpdated` and `flagsUpdated` support UI subscriptions.
135+
Metadata arrives with ordinary `/flags/evaluated` responses and is cached with the evaluated snapshot. Bootstrapped clients whose snapshot lacks metadata fetch it on demand from the same endpoint, without replacing server-derived values or provenance with browser-context evaluations. Loading settles on success or failure, including an empty list. Opt-in mutations confirm values and membership together in one versioned refresh. `optInFlagsLoadingUpdated` and `flagsUpdated` support UI subscriptions.
134136

135137
## Tracking, feedback and events
136138

137139
Use `track(eventName, attributes?)`, `feedback(payload)` and `requestFeedback({ flagKey, ... })` on the client. See [FEEDBACK.md](./FEEDBACK.md) for the feedback UI and prompting configuration.
138140

139141
`on(event, handler)` returns an unsubscribe function. Events include `stateUpdated`, `flagsUpdated` (evaluated diagnostics), `check`, `track`, `user`, `company` and `optInFlagsLoadingUpdated`.
140-
141-
## Migration from v1
142-
143-
- Replace `getFlag(key).isEnabled` with `getFlag(key)`.
144-
- Replace legacy remote config access with a separately authored multivariate flag and a positional default. Legacy config is **not** automatically converted into v2 values.
145-
- Move flag `.track()` / `.requestFeedback()` calls to ordinary client methods.
146-
- Replace wrapper overrides with `setFlagOverride(key, value)`; undefined clears, null is a value.
147-
- `getFlags()` now returns values and registers checks. Tooling should use `getFlagResults()`.
148-
- Upgrade both ends of bootstrap to v2. Old Browser/framework clients remain incompatible with v2 bootstrap.

‎packages/react-sdk/README.md‎

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
# Reflag React SDK v2
1+
# Reflag React SDK
22

3-
Direct-value feature flags for React, backed by [Browser SDK v2](../browser-sdk/README.md).
4-
5-
> Breaking prerelease: requires compatible v2 server endpoints and **Node SDK v2** for bootstrap. The v2 CLI generates direct-value declarations; regenerate legacy wrapper-shaped output when migrating. Useful default-based inference does not require generated declarations. React Native remains on published React/Browser v1 in this repository.
3+
Feature flags and JSON configuration for React, backed by the [Browser SDK](../browser-sdk/README.md).
64

75
## Setup
86

7+
```sh
8+
npm install @reflag/react-sdk
9+
```
10+
911
```tsx
1012
import { ReflagProvider } from "@reflag/react-sdk";
1113

@@ -51,7 +53,7 @@ useFlag("nullable-settings", null); // FlagValue: arbitrary JSON
5153

5254
Non-null defaults enforce only the top-level JSON category (Boolean/number/string/array/object). Mismatches return the default and warn without logging the payload. Explicit null accepts authored null and all other JSON; missing values return null. Accepted false, zero and empty strings are preserved. Nested fields/elements are not schema-validated. Values/defaults are independent mutable copies; readonly defaults are accepted.
5355

54-
`useFlag` never suspends. Its second argument is **payload data**, not `{ suspense: ... }` options; ordinary JSON has no reserved keys. Use the dedicated hook below for suspension. Use `useIsLoading()` or the provider's `loadingComponent` when you need an explicit loading UI.
56+
`useFlag` returns immediately, using the default while flags load. Use `useIsLoading()` or the provider's `loadingComponent` for an explicit loading UI, or `useFlagSuspense()` to wait with React Suspense.
5557

5658
## `useFlagSuspense(key, defaultValue?)`
5759

@@ -71,13 +73,13 @@ function Model() {
7173

7274
This hook has the same Boolean/default-based return types. It waits for initialization before reading. Once initialization settles, missing flags return their default rather than suspending forever. Bootstrap values can render immediately. Suspended attempts do not register a root read before data is ready.
7375

74-
The provider's existing `suspense` prop continues to configure **`useOptInFlags` only**. It does not change `useFlag`; `useFlagSuspense` is explicit.
76+
The provider's `suspense` prop configures **`useOptInFlags` only**. Use `useFlagSuspense` for flag reads with Suspense.
7577

7678
## Checks and usage tracking
7779

7880
A completed getter/hook read registers its requested-root check immediately, even if the value is ignored. Actual delivery remains buffered and identity-aware rate-limited by the Browser SDK. Checks contain selected variant/source/snapshot identity, not payloads. Defaults, category mismatches and local overrides never invent authored selections. Diagnostic/bootstrap inspection registers no checks.
7981

80-
Application usage and feedback remain separate hooks:
82+
Track application usage and collect feedback with these hooks:
8183

8284
```ts
8385
const track = useTrack();
@@ -102,11 +104,11 @@ declare module "@reflag/react-sdk" {
102104
}
103105
```
104106

105-
Registration constrains keys and checks non-null defaults against the registered value schema, including required and nested properties. Named-interface and readonly defaults are supported. Explicit `null` remains an arbitrary-JSON request; bare/`undefined` reads remain Boolean. The positional default still determines the widened return type, and generated declarations do not add nested runtime validation. The same rules apply to `useFlagSuspense`. The v2 CLI generates direct-value declarations from current production-environment variants; regenerate legacy wrapper declarations when migrating.
107+
Registration constrains keys and checks non-null defaults against the registered value schema, including required and nested properties. Named-interface and readonly defaults are supported. Explicit `null` remains an arbitrary-JSON request; bare/`undefined` reads remain Boolean. The positional default still determines the widened return type, and generated declarations do not add nested runtime validation. The same rules apply to `useFlagSuspense`. The Reflag CLI can generate these declarations from current production-environment variants.
106108

107109
## Bootstrap and SSR
108110

109-
On the server, use Node SDK v2:
111+
On the server, use the Node.js SDK:
110112

111113
```ts
112114
const flags = serverClient.getFlagsForBootstrap(context);
@@ -122,9 +124,9 @@ import { ReflagBootstrappedProvider } from "@reflag/react-sdk";
122124
</ReflagBootstrappedProvider>;
123125
```
124126

125-
The envelope includes `protocolVersion: 2`, context, evaluated flag results and optional `flagStateVersion`. V1 bootstrap is rejected. Use a snapshot version for live updates; later refreshes use browser-visible context. Do not send secrets/server-only attributes to the browser. Disable live updates if later browser evaluation must not replace server-only results.
127+
The envelope includes `protocolVersion: 2`, context, evaluated flag results and optional `flagStateVersion`. Use a snapshot version for live updates; later refreshes use browser-visible context. Do not send secrets/server-only attributes to the browser. Disable live updates if later browser evaluation must not replace server-only results.
126128

127-
For a pre-existing Browser v2 client, use `<ReflagClientProvider client={client}>`. The provider does not own its lifecycle; initialize/stop externally, except that a suspending read can start on-demand initialization.
129+
For an existing Browser SDK client, use `<ReflagClientProvider client={client}>`. The provider does not own its lifecycle; initialize/stop externally, except that a suspending read can start on-demand initialization.
128130

129131
## Context, loading and events
130132

@@ -143,10 +145,6 @@ await setOptIn("huddles", { optedIn: true });
143145
await setOptIn("huddles", { optedIn: false, scope: "company" });
144146
```
145147

146-
Metadata arrives with the initial v2 evaluation for regular providers. Bootstrapped providers fetch missing metadata on demand from `/flags/evaluated` without replacing server-derived values. `isLoading` covers initialization and metadata retrieval; it settles on success or failure. Metadata presentation includes `isEnabled` and membership fields, separately from direct flag reads. User/company grants remain independent. Mutations confirm versioned evaluation and membership in a single refresh.
148+
Metadata arrives with the initial evaluation for regular providers. Bootstrapped providers fetch missing metadata on demand from `/flags/evaluated` without replacing server-derived values. `isLoading` covers initialization and metadata retrieval; it settles on success or failure. Metadata presentation includes `isEnabled` and membership fields, separately from direct flag reads. User/company grants remain independent. Mutations confirm versioned evaluation and membership in a single refresh.
147149

148150
`useOptInFlags({ suspense: true | false })` retains its own per-hook loading options and may inherit provider `suspense`. These options are unrelated to the positional payload defaults used by `useFlag` / `useFlagSuspense`.
149-
150-
## Migration from v1
151-
152-
Use `const enabled = useFlag(key)` instead of destructuring `.isEnabled`. Replace wrapper config access with an authored multivariate flag and positional default. Move `.track()` and `.requestFeedback()` to separate hooks. Replace `useFlag(key, { suspense: true })` with `useFlagSuspense(key)`, and use `useIsLoading()` instead of a flag wrapper's loading property. Upgrade Browser/server bootstrap together. Nothing here publishes the prerelease or deploys its required server changes.

0 commit comments

Comments
 (0)