@wellth-app/experiments 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (66) hide show
  1. package/README.md +223 -2
  2. package/dist/cjs/index.js +10 -0
  3. package/dist/cjs/index.js.map +1 -0
  4. package/dist/cjs/react.js +317 -0
  5. package/dist/cjs/react.js.map +1 -0
  6. package/dist/cjs/registry-pg5aaOm-.js +537 -0
  7. package/dist/cjs/registry-pg5aaOm-.js.map +1 -0
  8. package/dist/cjs/web.js +87 -0
  9. package/dist/cjs/web.js.map +1 -0
  10. package/dist/esm/index.js +3 -0
  11. package/dist/esm/index.js.map +1 -0
  12. package/dist/esm/react.js +290 -0
  13. package/dist/esm/react.js.map +1 -0
  14. package/dist/esm/registry-B73fwn9J.js +534 -0
  15. package/dist/esm/registry-B73fwn9J.js.map +1 -0
  16. package/dist/esm/web.js +85 -0
  17. package/dist/esm/web.js.map +1 -0
  18. package/dist/events.d.ts +65 -0
  19. package/dist/events.d.ts.map +1 -0
  20. package/dist/index.d.ts +10 -0
  21. package/dist/index.d.ts.map +1 -0
  22. package/dist/react/context.d.ts +37 -0
  23. package/dist/react/context.d.ts.map +1 -0
  24. package/dist/react/guard.d.ts +11 -0
  25. package/dist/react/guard.d.ts.map +1 -0
  26. package/dist/react/index.d.ts +12 -0
  27. package/dist/react/index.d.ts.map +1 -0
  28. package/dist/react/provider.d.ts +38 -0
  29. package/dist/react/provider.d.ts.map +1 -0
  30. package/dist/react/use-analytics.d.ts +12 -0
  31. package/dist/react/use-analytics.d.ts.map +1 -0
  32. package/dist/react/use-experiment-qa.d.ts +14 -0
  33. package/dist/react/use-experiment-qa.d.ts.map +1 -0
  34. package/dist/react/use-experiment.d.ts +30 -0
  35. package/dist/react/use-experiment.d.ts.map +1 -0
  36. package/dist/react/use-feature-flag.d.ts +16 -0
  37. package/dist/react/use-feature-flag.d.ts.map +1 -0
  38. package/dist/react/use-feature-value.d.ts +16 -0
  39. package/dist/react/use-feature-value.d.ts.map +1 -0
  40. package/dist/registry.d.ts +143 -0
  41. package/dist/registry.d.ts.map +1 -0
  42. package/dist/types.d.ts +111 -0
  43. package/dist/types.d.ts.map +1 -0
  44. package/dist/uuid.d.ts +6 -0
  45. package/dist/uuid.d.ts.map +1 -0
  46. package/dist/web/batched-event-sender.d.ts +35 -0
  47. package/dist/web/batched-event-sender.d.ts.map +1 -0
  48. package/dist/web/index.d.ts +7 -0
  49. package/dist/web/index.d.ts.map +1 -0
  50. package/package.json +127 -4
  51. package/src/events.ts +90 -0
  52. package/src/index.ts +37 -0
  53. package/src/react/context.ts +62 -0
  54. package/src/react/guard.ts +25 -0
  55. package/src/react/index.ts +17 -0
  56. package/src/react/provider.tsx +109 -0
  57. package/src/react/use-analytics.ts +17 -0
  58. package/src/react/use-experiment-qa.ts +26 -0
  59. package/src/react/use-experiment.ts +72 -0
  60. package/src/react/use-feature-flag.ts +35 -0
  61. package/src/react/use-feature-value.ts +42 -0
  62. package/src/registry.ts +715 -0
  63. package/src/types.ts +120 -0
  64. package/src/uuid.ts +14 -0
  65. package/src/web/batched-event-sender.ts +111 -0
  66. package/src/web/index.ts +9 -0
package/README.md CHANGED
@@ -1,3 +1,224 @@
1
- # Temporary Holding Version
1
+ # @wellth-app/experiments
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Wellth's thin experiment client. One module every JavaScript app binds to; the
4
+ evaluation engine behind it (`@growthbook/growthbook`, a plain npm dependency)
5
+ is an implementation detail the app never touches.
6
+
7
+ > The engine dependency resolves to upstream GrowthBook's published package,
8
+ > which is kept stock in our fork. If the fork's `sdk-js` ever diverges from
9
+ > upstream, publish it to the internal registry and repoint the dependency.
10
+
11
+ - **Assignment is computed, not stored.** The config is fetched once from the
12
+ features endpoint (`<sdk-host>/api/features/<clientKey>`), cached, and
13
+ revalidated in the background; every evaluation — targeting conditions,
14
+ namespaces, deterministic-hash bucketing — runs locally. There is no
15
+ assignment service.
16
+ - **The warehouse recomputes assignment in SQL.** The hash contract, shared test
17
+ vectors, and the Redshift implementation live in [`contract/`](contract/).
18
+ - **Exposure is logged on render, not on compute**, exactly once per visible
19
+ assignment, in the warehouse's contract shape.
20
+
21
+ ## Entries
22
+
23
+ | Import | What it is |
24
+ | ---------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------- |
25
+ | `@wellth-app/experiments` (or `/core`) | The core: registry, evaluation, overrides, event contract. No React, no DOM. |
26
+ | `@wellth-app/experiments/react` | `ExperimentProvider`, `useExperiment`, `useFeatureFlag`, `useFeatureValue`, `useAnalytics`, `useExperimentQa`. Works anywhere React runs (web, React Native). |
27
+ | `@wellth-app/experiments/web` | `createBatchedEventSender` — the browser batching transport (fetch/sendBeacon). Other runtimes supply their own `EventStream`. |
28
+
29
+ ## Usage
30
+
31
+ ```tsx
32
+ import { useExperiment } from "@wellth-app/experiments/react";
33
+
34
+ const { variant, params } = useExperiment("brick_wall");
35
+ // variant: the assigned arm key from the experiment config ("control" | "treatment" | …)
36
+ // params: the configured parameter payload for the assigned arm
37
+ ```
38
+
39
+ Feature flags use the same engine, the same local targeting, and the same
40
+ deterministic hash (rollouts bucket the subject id exactly like experiments do):
41
+
42
+ ```tsx
43
+ import { useFeatureFlag, useFeatureValue } from "@wellth-app/experiments/react";
44
+
45
+ const enabled = useFeatureFlag("dark_mode_checkout");
46
+ const headline = useFeatureValue("checkout_headline", "Control headline");
47
+ ```
48
+
49
+ Flags never log exposure. Read an experiment key through the flag path and you
50
+ get the config's default, never the assigned value — that read would render a
51
+ variant with no exposure event and corrupt the experiment's counts. Experiments
52
+ go through `useExperiment`; flags through the flag hooks. **The misuse guard
53
+ enforces this in development**: a flag hook on an experiment key, or
54
+ `useExperiment` on a flag key, throws a clear error at the call site.
55
+ Production builds strip the check and keep the fail-closed reads above.
56
+
57
+ ```tsx
58
+ import { ExperimentProvider } from "@wellth-app/experiments/react";
59
+ import { createBatchedEventSender } from "@wellth-app/experiments/web";
60
+
61
+ <ExperimentProvider
62
+ subjectId={member.id}
63
+ surface="app" // required — the surface exposures are stamped with
64
+ attributes={{ platform: "web", appVersion: version }}
65
+ clientKey={EXPERIMENT_CLIENT_KEY} // unset → control reads, nothing fetched
66
+ apiHost={SDK_HOST}
67
+ events={createBatchedEventSender({
68
+ url: ANALYTICS_INTAKE,
69
+ authorization: `Bearer ${EXPOSURE_INGEST_KEY}`, // per-surface ingest key
70
+ })}
71
+ overrides={migrationOverrides} // optional cutover map, bundled by the app
72
+ cacheStorage={AsyncStorage} // RN: persist the config cache (offline cold starts)
73
+ >
74
+ <App />
75
+ </ExperimentProvider>;
76
+ ```
77
+
78
+ Per-call context overrides the session's:
79
+
80
+ ```ts
81
+ useExperiment("brick_wall", {
82
+ subjectId: member.id,
83
+ attributes: { platform: "ios", program: member.programId, appVersion },
84
+ });
85
+ ```
86
+
87
+ Targeting gates eligibility **before** bucketing; the hash input is always the
88
+ bare `subjectId` — **normalized (trim + lowercase) inside the evaluator**, so
89
+ casing drift at a call site never scrambles cohorts. The warehouse applies the
90
+ same normalization. A member who fails targeting gets the default arm with no
91
+ exposure. A stopped experiment serves control/default with no exposure.
92
+
93
+ On React Native, pass `cacheStorage={AsyncStorage}` so the config cache
94
+ persists across cold starts (evaluate offline from the last fetch), and call
95
+ `registry.refresh()` from an AppState foreground listener to revalidate.
96
+ Experiments can carry a hard time window as a targeting condition on the `date`
97
+ attribute the registry always supplies — outside the window: control, no
98
+ exposure, even from a stale cache. Exclusion lists (staff/test accounts) are a
99
+ saved group plus a `$notInGroup` condition in the config — see
100
+ [`contract/assignment-hash.md`](contract/assignment-hash.md) for both
101
+ conventions.
102
+
103
+ ### Overrides
104
+
105
+ A stopped or unknown experiment always reads control with no exposure —
106
+ **overrides never resurrect it**, even while its rule still rides the payload
107
+ (a remotely stopped rule parses as stopped). For everything running, checked
108
+ before the engine, in order:
109
+
110
+ 1. **QA pins** (`useExperimentQa()`, for the dev menu) — force a variant for the
111
+ current subject and session; **never** emit exposure.
112
+ 2. **Registry overrides** — the bundled map (`{ [experimentKey]: { [subjectId]:
113
+ variantKey | { variant, expiresAt?, kind? } } }`). Used for the cutover import,
114
+ so no member flips arms mid-experiment. Entries may expire (`expiresAt` —
115
+ expired entries fall back to the hash) and carry a `kind`: `migration`
116
+ (default) entries are real assignments and log exposure normally; `qa`
117
+ entries log exposure flagged `override: true` so analysis drops them.
118
+ Overrides beat exclusions — QA can force a staff member in.
119
+ 3. The engine — targeting, then the deterministic hash.
120
+
121
+ The full order, who logs at each step, and the parse guards behind it are the
122
+ contract in [`contract/evaluation-order.md`](contract/evaluation-order.md) —
123
+ other surfaces (notifications dispatch, backend consumers) implement the same.
124
+
125
+ ### Exposure
126
+
127
+ The hook fires exactly one event when the assigned variant is actually rendered
128
+ (post-commit), deduplicated per (experiment, subject, variant) per session — a
129
+ session is a provider lifetime. The emitting surface is declared per app: the
130
+ required `surface` option (`"app" | "web" | "notifications"`, no default —
131
+ Atlas is web). `config_version` is the version the assignment was _evaluated_
132
+ against: captured at evaluation time, so a config refresh between compute and
133
+ render never re-stamps the event. For a call site that evaluates now but
134
+ renders later, use `exposure: "manual"` and fire the returned `markExposed()`
135
+ when the experience renders:
136
+
137
+ ```json
138
+ {
139
+ "event": "experiment_exposed",
140
+ "experiment_id": "<experiment key>",
141
+ "variation_id": "<assigned variant key>",
142
+ "subject": "<member id, normalized>",
143
+ "surface": "app",
144
+ "timestamp": "<epoch ms>",
145
+ "config_version": "<registry version evaluated against>",
146
+ "exposure_id": "<uuid — the idempotency key the dedupe layers key on>"
147
+ }
148
+ ```
149
+
150
+ `override: true` is added only for QA-kind overrides. The frozen field
151
+ contract — every field owned, the never-log list, the exactly-once semantics —
152
+ lives in [`contract/exposure.md`](contract/exposure.md). Exposures originate
153
+ only from the hook path (`useExperiment` / `markExposed`): `trackExposure`
154
+ never reaches the React context, so no component can hand-craft an event around
155
+ the never-log guards. Events batch through the app's own analytics stream (the
156
+ `events` seam). No dedicated events service.
157
+
158
+ ## Design decisions
159
+
160
+ - **Wrap, don't modify.** The engine stays stock so upstream updates flow. All
161
+ custom behavior — the hook shape, the override layer, exposure wiring — lives
162
+ in this package. If the engine is ever replaced, only this package changes.
163
+ - **`GrowthBookClient` (per-call user context), not the classic singleton or the
164
+ vendor's React hooks.** The hook's per-call `{ subjectId, attributes }` shape
165
+ requires per-call evaluation, and the vendor's React SDK would thread vendor
166
+ types into call sites — the coupling this package exists to prevent.
167
+ - **The engine's `trackingCallback` is deliberately never wired.** It fires at
168
+ evaluation time, which in React is every render of every reader — wrong timing
169
+ (compute, not render) and wrong cardinality. Exposure is this package's job.
170
+ - **No assignment/bucketing service, ever.** Assignment must be computable
171
+ offline and reproducible in the warehouse; a network hop per read adds
172
+ latency, an outage mode, and a stored-assignment drift source.
173
+
174
+ ## Surface boundary
175
+
176
+ Exposed: everything the engine evaluates locally — experiments, boolean and
177
+ valued feature flags, targeting conditions, percentage rollouts, namespaces,
178
+ prerequisites, saved groups — plus the override layer, QA pins, and the
179
+ exposure contract.
180
+
181
+ Deliberately not exposed:
182
+
183
+ - **Visual-editor auto-experiments** — DOM mutation/URL-redirect experiments,
184
+ meaningless outside a browser DOM. Use the flag/experiment paths instead.
185
+ - **Remote-eval mode** — server-side evaluation. Antithetical to on-device
186
+ hashing; assignment would no longer be computable offline or reproducible in
187
+ the warehouse.
188
+ - **Sticky buckets** — persisted assignment across identity changes needs
189
+ platform storage. Lands with the pre-login identity-continuity work, not
190
+ before.
191
+ - **Off-contract bucketing** — the hash input is always the bare subject id
192
+ with `hashVersion: 2`. A config naming another hash attribute, a
193
+ sticky-bucket fallback, or a missing/legacy hash version never evaluates:
194
+ the entry parses as stopped with a warning (fail closed, never a wrong
195
+ assignment). See
196
+ [`contract/evaluation-order.md`](contract/evaluation-order.md).
197
+
198
+ ## Example
199
+
200
+ [`examples/demo-app/`](examples/demo-app/) is a minimal storefront consuming the
201
+ built package end to end — seeded config (no network), experiments, flags,
202
+ targeting, migration overrides, QA pins, and a live event log showing exposure
203
+ semantics. `pnpm example:dev` after `pnpm build`.
204
+
205
+ ## Development
206
+
207
+ ```
208
+ pnpm test # jest suites (registry, hooks, sender, hash contract)
209
+ pnpm type-check # tsgo
210
+ pnpm build # dist/ (esm + cjs + types)
211
+ pnpm lint # eslint
212
+ pnpm generate-vectors # regenerate contract/hash-vectors.json + the Redshift validation SQL
213
+ ```
214
+
215
+ ## Releasing
216
+
217
+ The package publishes to the public npm registry (registry.npmjs.org) under the
218
+ `@wellth-app` scope - no auth needed to install. CI is the only publisher:
219
+ merging a `package.json` version bump to `development` triggers the `publish`
220
+ job, which skips versions that are already published. Publishing is keyless -
221
+ the job exchanges a CircleCI OIDC token for a short-lived npm token via npm
222
+ Trusted Publishing; no registry token is stored anywhere. The published tarball
223
+ is code-only (`dist` + `src`); `contract/` stays in this private repo, where
224
+ data engineering and the warehouse twin consume it.
@@ -0,0 +1,10 @@
1
+ 'use strict';
2
+
3
+ var registry = require('./registry-pg5aaOm-.js');
4
+ require('@growthbook/growthbook');
5
+
6
+
7
+
8
+ exports.buildExperimentExposure = registry.buildExperimentExposure;
9
+ exports.createFeatureRegistry = registry.createFeatureRegistry;
10
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;"}
@@ -0,0 +1,317 @@
1
+ 'use strict';
2
+
3
+ var React = require('react');
4
+ var registry = require('./registry-pg5aaOm-.js');
5
+ require('@growthbook/growthbook');
6
+
7
+ function _interopNamespaceDefault(e) {
8
+ var n = Object.create(null);
9
+ if (e) {
10
+ Object.keys(e).forEach(function (k) {
11
+ if (k !== 'default') {
12
+ var d = Object.getOwnPropertyDescriptor(e, k);
13
+ Object.defineProperty(n, k, d.get ? d : {
14
+ enumerable: true,
15
+ get: function () { return e[k]; }
16
+ });
17
+ }
18
+ });
19
+ }
20
+ n.default = e;
21
+ return Object.freeze(n);
22
+ }
23
+
24
+ var React__namespace = /*#__PURE__*/_interopNamespaceDefault(React);
25
+
26
+ /** A product event handed to the stream. The context stamps subject and timestamp. */
27
+
28
+ /**
29
+ * The registry as components see it: the full read/QA surface minus
30
+ * trackExposure. Exposure emission stays inside the package's hooks, so no
31
+ * component can hand-craft an event around the never-log guards.
32
+ */
33
+
34
+ const ExperimentsContext = /*#__PURE__*/React.createContext(null);
35
+
36
+ /**
37
+ * The real registry, trackExposure included — the internal channel the
38
+ * package's own hooks use. Deliberately not re-exported from the React entry,
39
+ * so the surface has no typed path to exposure emission.
40
+ */
41
+ const InternalRegistryContext = /*#__PURE__*/React.createContext(null);
42
+
43
+ /** The mounted experiments context. Throws when no ExperimentProvider is mounted. */
44
+ function useExperiments() {
45
+ const value = React.useContext(ExperimentsContext);
46
+ if (value === null) {
47
+ throw new Error("useExperiments must be used within <ExperimentProvider>");
48
+ }
49
+ return value;
50
+ }
51
+
52
+ /**
53
+ * The real registry for the package's own hooks (useExperiment's exposure
54
+ * emission). Throws when no ExperimentProvider is mounted.
55
+ */
56
+ function useInternalRegistry() {
57
+ const registry = React.useContext(InternalRegistryContext);
58
+ if (registry === null) {
59
+ throw new Error("useInternalRegistry must be used within <ExperimentProvider>");
60
+ }
61
+ return registry;
62
+ }
63
+
64
+ /**
65
+ * Mounts the session's experiment registry once, after auth. A `payload` seeds
66
+ * the registry synchronously at construction, so the first paint already reads
67
+ * the real assignment; the fetch path initializes async and children render
68
+ * immediately against a still-initializing registry, which returns control
69
+ * defaults, so a variant never flashes ahead of the assignment. Without a
70
+ * client key nothing is fetched — the control experience.
71
+ */
72
+ function ExperimentProvider({
73
+ subjectId,
74
+ surface,
75
+ attributes,
76
+ events,
77
+ overrides,
78
+ cacheStorage,
79
+ clientKey,
80
+ apiHost,
81
+ payload,
82
+ children
83
+ }) {
84
+ const [registry$1] = React.useState(() => {
85
+ const created = registry.createFeatureRegistry({
86
+ surface,
87
+ events,
88
+ overrides,
89
+ cacheStorage
90
+ });
91
+ // Seed synchronously when the payload is already available: the first
92
+ // commit reads the real assignment instead of flashing control for a
93
+ // frame. The effect below re-seeds on payload change and on remount
94
+ // (StrictMode's simulated unmount destroys the client).
95
+ if (payload !== undefined) created.initSync({
96
+ payload
97
+ });
98
+ return created;
99
+ });
100
+ React.useEffect(() => {
101
+ if (payload !== undefined) {
102
+ registry$1.initSync({
103
+ payload
104
+ });
105
+ } else {
106
+ void registry$1.init({
107
+ clientKey,
108
+ apiHost
109
+ });
110
+ }
111
+ return () => {
112
+ registry$1.destroy();
113
+ };
114
+ }, [registry$1, clientKey, apiHost, payload]);
115
+ const value = React.useMemo(() => ({
116
+ registry: registry$1,
117
+ subjectId,
118
+ attributes,
119
+ trackEvent(input) {
120
+ const event = {
121
+ ...input,
122
+ subject: input["subject"] ?? subjectId,
123
+ timestamp: Date.now()
124
+ };
125
+ registry$1.sendEvent(event);
126
+ }
127
+ }), [registry$1, subjectId, attributes]);
128
+ return (
129
+ /*#__PURE__*/
130
+ // The internal channel carries the real registry (trackExposure included)
131
+ // to the package's own hooks; the public context carries the facade.
132
+ React__namespace.createElement(InternalRegistryContext.Provider, {
133
+ value: registry$1
134
+ }, /*#__PURE__*/React__namespace.createElement(ExperimentsContext.Provider, {
135
+ value: value
136
+ }, children))
137
+ );
138
+ }
139
+
140
+ /**
141
+ * The session's product-analytics stream — the same stream experiment exposures
142
+ * ride. `track` stamps the subject and timestamp. `ready` is false until the
143
+ * experiment config finishes initializing, so callers can skip events that have
144
+ * no meaningful assignment context yet.
145
+ */
146
+ function useAnalytics() {
147
+ const {
148
+ registry,
149
+ trackEvent
150
+ } = useExperiments();
151
+ React.useSyncExternalStore(registry.subscribe, registry.getVersion);
152
+ return {
153
+ ready: registry.isReady(),
154
+ track: trackEvent
155
+ };
156
+ }
157
+
158
+ /**
159
+ * Read the experiment's assignment for the current subject:
160
+ *
161
+ * ```ts
162
+ * const { variant, params } = useExperiment("brick_wall");
163
+ * // variant: the assigned arm key from the experiment config
164
+ * // params: the configured parameter payload for the assigned arm
165
+ * ```
166
+ *
167
+ * Pass `context` to evaluate for a different subject or with extra targeting
168
+ * attributes; both default to the session's. Targeting gates eligibility before
169
+ * bucketing — a member who fails targeting gets the default arm with no
170
+ * exposure. The hash input is always the subject id.
171
+ *
172
+ * Exactly one exposure is recorded, when the assigned variant is actually
173
+ * rendered (post-commit) — never on compute, and never for a member who was
174
+ * bucketed but not shown the experience. Defaults, stopped experiments,
175
+ * targeting failures, and QA pins never emit exposure.
176
+ *
177
+ * With `exposure: "manual"` the hook instead returns a `markExposed` trigger —
178
+ * for call sites that evaluate now but render the experience later. Call it
179
+ * when the experience actually renders; it no-ops on an unexposed assignment.
180
+ *
181
+ * Misuse guard: calling this on a feature-flag key throws a clear error in
182
+ * development (flags go through useFeatureFlag/useFeatureValue); production
183
+ * reads fail closed to control.
184
+ */
185
+ function useExperiment(experimentKey, context) {
186
+ const {
187
+ subjectId: sessionSubjectId,
188
+ attributes: sessionAttributes
189
+ } = useExperiments();
190
+ // The real registry, trackExposure included — the internal channel, so the
191
+ // context's facade can never emit an exposure outside this hook.
192
+ const registry = useInternalRegistry();
193
+ // Subscribed so a config refresh or pin change re-evaluates this assignment.
194
+ React.useSyncExternalStore(registry.subscribe, registry.getVersion);
195
+ const subjectId = context?.subjectId ?? sessionSubjectId;
196
+ const attributes = context?.attributes ?? sessionAttributes;
197
+ const assignment = registry.evaluateExperiment({
198
+ experimentKey,
199
+ subjectId,
200
+ attributes
201
+ });
202
+ const exposure = assignment.exposure;
203
+ const manual = context?.exposure === "manual";
204
+ React.useEffect(() => {
205
+ if (manual || exposure === null) return;
206
+ registry.trackExposure(exposure);
207
+ }, [registry, exposure, manual]);
208
+ if (!manual) {
209
+ return {
210
+ variant: assignment.variant,
211
+ params: assignment.params
212
+ };
213
+ }
214
+ return {
215
+ variant: assignment.variant,
216
+ params: assignment.params,
217
+ markExposed: () => {
218
+ if (exposure === null) return;
219
+ registry.trackExposure(exposure);
220
+ }
221
+ };
222
+ }
223
+
224
+ /**
225
+ * The QA override surface, for the dev/debug menu: force a variant for the
226
+ * current subject and session. Pinned assignments render the pinned arm but are
227
+ * never recorded as exposure.
228
+ */
229
+ function useExperimentQa() {
230
+ const {
231
+ registry
232
+ } = useExperiments();
233
+ React.useSyncExternalStore(registry.subscribe, registry.getVersion);
234
+ return {
235
+ pins: registry.getPins(),
236
+ pin: pin => {
237
+ registry.pin(pin);
238
+ },
239
+ unpin: input => {
240
+ registry.unpin(input);
241
+ }
242
+ };
243
+ }
244
+
245
+ /**
246
+ * Read a boolean feature flag for the current subject:
247
+ *
248
+ * ```ts
249
+ * const enabled = useFeatureFlag("dark_mode_checkout");
250
+ * ```
251
+ *
252
+ * Targeting conditions and percentage rollouts evaluate locally against the
253
+ * same deterministic hash the experiments use. Flags never log exposure. An
254
+ * unknown flag is off; an experiment key read here throws a clear error in
255
+ * development — experiments go through useExperiment, the exposure-aware path
256
+ * (production reads fail closed to the config's default).
257
+ */
258
+ function useFeatureFlag(featureKey, context) {
259
+ const {
260
+ registry,
261
+ subjectId: sessionSubjectId,
262
+ attributes: sessionAttributes
263
+ } = useExperiments();
264
+ // Subscribed so a config refresh re-evaluates this flag.
265
+ React.useSyncExternalStore(registry.subscribe, registry.getVersion);
266
+ const subjectId = context?.subjectId ?? sessionSubjectId;
267
+ const attributes = context?.attributes ?? sessionAttributes;
268
+ return registry.evaluateFlag({
269
+ featureKey,
270
+ subjectId,
271
+ attributes
272
+ }).on;
273
+ }
274
+
275
+ /**
276
+ * Read a valued feature flag (string/number/JSON remote config) for the current
277
+ * subject, falling back when the flag is unknown or has no value:
278
+ *
279
+ * ```ts
280
+ * const headline = useFeatureValue("checkout_headline", "Control headline");
281
+ * ```
282
+ *
283
+ * The fallback declares the flag's type. Flags never log exposure; an
284
+ * experiment key read here throws a clear error in development — experiments
285
+ * go through useExperiment, the exposure-aware path (production reads fail
286
+ * closed to the config's default).
287
+ */
288
+ function useFeatureValue(featureKey, fallback, context) {
289
+ const {
290
+ registry,
291
+ subjectId: sessionSubjectId,
292
+ attributes: sessionAttributes
293
+ } = useExperiments();
294
+ // Subscribed so a config refresh re-evaluates this flag.
295
+ React.useSyncExternalStore(registry.subscribe, registry.getVersion);
296
+ const subjectId = context?.subjectId ?? sessionSubjectId;
297
+ const attributes = context?.attributes ?? sessionAttributes;
298
+ const {
299
+ value
300
+ } = registry.evaluateFlag({
301
+ featureKey,
302
+ subjectId,
303
+ attributes
304
+ });
305
+ // The engine's value is untyped; the caller's fallback declares the flag's type.
306
+ return value === null || value === undefined ? fallback : value;
307
+ }
308
+
309
+ exports.ExperimentProvider = ExperimentProvider;
310
+ exports.ExperimentsContext = ExperimentsContext;
311
+ exports.useAnalytics = useAnalytics;
312
+ exports.useExperiment = useExperiment;
313
+ exports.useExperimentQa = useExperimentQa;
314
+ exports.useExperiments = useExperiments;
315
+ exports.useFeatureFlag = useFeatureFlag;
316
+ exports.useFeatureValue = useFeatureValue;
317
+ //# sourceMappingURL=react.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"react.js","sources":["../../src/react/context.ts","../../src/react/provider.tsx","../../src/react/use-analytics.ts","../../src/react/use-experiment.ts","../../src/react/use-experiment-qa.ts","../../src/react/use-feature-flag.ts","../../src/react/use-feature-value.ts"],"sourcesContent":["import { createContext, useContext } from \"react\";\nimport type { FeatureRegistry } from \"../registry\";\nimport type { TargetingAttributes } from \"../types\";\n\n/** A product event handed to the stream. The context stamps subject and timestamp. */\nexport interface ProductEventInput {\n event: string;\n [property: string]: unknown;\n}\n\n/**\n * The registry as components see it: the full read/QA surface minus\n * trackExposure. Exposure emission stays inside the package's hooks, so no\n * component can hand-craft an event around the never-log guards.\n */\nexport type ComponentRegistry = Omit<FeatureRegistry, \"trackExposure\">;\n\nexport interface ExperimentsContextValue {\n registry: ComponentRegistry;\n /** The session's subject — the member id assignments hash on. */\n subjectId: string;\n /** The session's targeting attributes; a call-site's context overrides these. */\n attributes?: TargetingAttributes;\n /** Send a product event on the same stream exposures ride. */\n trackEvent: (input: ProductEventInput) => void;\n}\n\nexport const ExperimentsContext = createContext<ExperimentsContextValue | null>(\n null,\n);\n\n/**\n * The real registry, trackExposure included — the internal channel the\n * package's own hooks use. Deliberately not re-exported from the React entry,\n * so the surface has no typed path to exposure emission.\n */\nexport const InternalRegistryContext = createContext<FeatureRegistry | null>(\n null,\n);\n\n/** The mounted experiments context. Throws when no ExperimentProvider is mounted. */\nexport function useExperiments(): ExperimentsContextValue {\n const value = useContext(ExperimentsContext);\n if (value === null) {\n throw new Error(\"useExperiments must be used within <ExperimentProvider>\");\n }\n return value;\n}\n\n/**\n * The real registry for the package's own hooks (useExperiment's exposure\n * emission). Throws when no ExperimentProvider is mounted.\n */\nexport function useInternalRegistry(): FeatureRegistry {\n const registry = useContext(InternalRegistryContext);\n if (registry === null) {\n throw new Error(\n \"useInternalRegistry must be used within <ExperimentProvider>\",\n );\n }\n return registry;\n}\n","import * as React from \"react\";\nimport { useEffect, useMemo, useState, type ReactNode } from \"react\";\nimport type { EventStream, ExposureSurface } from \"../events\";\nimport { createFeatureRegistry, type RegistryPayload } from \"../registry\";\nimport type { KeyValueStorage, Overrides, TargetingAttributes } from \"../types\";\nimport {\n ExperimentsContext,\n InternalRegistryContext,\n type ExperimentsContextValue,\n type ProductEventInput,\n} from \"./context\";\n\nexport interface ExperimentProviderProps {\n /** The session's subject — the member id assignments hash on. */\n subjectId: string;\n /**\n * The surface exposures are stamped with (\"app\" | \"web\" | \"notifications\").\n * Required — each app declares itself.\n */\n surface: ExposureSurface;\n /** Session targeting attributes (platform, program, appVersion, …). */\n attributes?: TargetingAttributes;\n /** The analytics pipeline exposures batch through. Unset = computed but not sent. */\n events?: EventStream;\n /** The assignment override map, bundled by the app. Default: no overrides. */\n overrides?: Overrides;\n /** Where the config cache persists (AsyncStorage on React Native). Default: platform localStorage or memory. */\n cacheStorage?: KeyValueStorage;\n /** Config endpoint credentials. Unset = disabled: control reads, no fetch. */\n clientKey?: string;\n apiHost?: string;\n /** An already-available config payload to seed synchronously instead of fetching. */\n payload?: RegistryPayload;\n children: ReactNode;\n}\n\n/**\n * Mounts the session's experiment registry once, after auth. A `payload` seeds\n * the registry synchronously at construction, so the first paint already reads\n * the real assignment; the fetch path initializes async and children render\n * immediately against a still-initializing registry, which returns control\n * defaults, so a variant never flashes ahead of the assignment. Without a\n * client key nothing is fetched — the control experience.\n */\nexport function ExperimentProvider({\n subjectId,\n surface,\n attributes,\n events,\n overrides,\n cacheStorage,\n clientKey,\n apiHost,\n payload,\n children,\n}: ExperimentProviderProps) {\n const [registry] = useState(() => {\n const created = createFeatureRegistry({\n surface,\n events,\n overrides,\n cacheStorage,\n });\n // Seed synchronously when the payload is already available: the first\n // commit reads the real assignment instead of flashing control for a\n // frame. The effect below re-seeds on payload change and on remount\n // (StrictMode's simulated unmount destroys the client).\n if (payload !== undefined) created.initSync({ payload });\n return created;\n });\n\n useEffect(() => {\n if (payload !== undefined) {\n registry.initSync({ payload });\n } else {\n void registry.init({ clientKey, apiHost });\n }\n return () => {\n registry.destroy();\n };\n }, [registry, clientKey, apiHost, payload]);\n\n const value = useMemo<ExperimentsContextValue>(\n () => ({\n registry,\n subjectId,\n attributes,\n trackEvent(input: ProductEventInput): void {\n const event = {\n ...input,\n subject: input[\"subject\"] ?? subjectId,\n timestamp: Date.now(),\n };\n registry.sendEvent(event);\n },\n }),\n [registry, subjectId, attributes],\n );\n\n return (\n // The internal channel carries the real registry (trackExposure included)\n // to the package's own hooks; the public context carries the facade.\n <InternalRegistryContext.Provider value={registry}>\n <ExperimentsContext.Provider value={value}>\n {children}\n </ExperimentsContext.Provider>\n </InternalRegistryContext.Provider>\n );\n}\n","import { useSyncExternalStore } from \"react\";\nimport { useExperiments, type ProductEventInput } from \"./context\";\n\n/**\n * The session's product-analytics stream — the same stream experiment exposures\n * ride. `track` stamps the subject and timestamp. `ready` is false until the\n * experiment config finishes initializing, so callers can skip events that have\n * no meaningful assignment context yet.\n */\nexport function useAnalytics(): {\n ready: boolean;\n track: (input: ProductEventInput) => void;\n} {\n const { registry, trackEvent } = useExperiments();\n useSyncExternalStore(registry.subscribe, registry.getVersion);\n return { ready: registry.isReady(), track: trackEvent };\n}\n","import { useEffect, useSyncExternalStore } from \"react\";\nimport type { ExperimentAssignment, ExperimentContext } from \"../types\";\nimport { useExperiments, useInternalRegistry } from \"./context\";\nimport { assertHookKeyKind } from \"./guard\";\n\n/**\n * Read the experiment's assignment for the current subject:\n *\n * ```ts\n * const { variant, params } = useExperiment(\"brick_wall\");\n * // variant: the assigned arm key from the experiment config\n * // params: the configured parameter payload for the assigned arm\n * ```\n *\n * Pass `context` to evaluate for a different subject or with extra targeting\n * attributes; both default to the session's. Targeting gates eligibility before\n * bucketing — a member who fails targeting gets the default arm with no\n * exposure. The hash input is always the subject id.\n *\n * Exactly one exposure is recorded, when the assigned variant is actually\n * rendered (post-commit) — never on compute, and never for a member who was\n * bucketed but not shown the experience. Defaults, stopped experiments,\n * targeting failures, and QA pins never emit exposure.\n *\n * With `exposure: \"manual\"` the hook instead returns a `markExposed` trigger —\n * for call sites that evaluate now but render the experience later. Call it\n * when the experience actually renders; it no-ops on an unexposed assignment.\n *\n * Misuse guard: calling this on a feature-flag key throws a clear error in\n * development (flags go through useFeatureFlag/useFeatureValue); production\n * reads fail closed to control.\n */\nexport function useExperiment(\n experimentKey: string,\n context?: ExperimentContext,\n): ExperimentAssignment {\n const { subjectId: sessionSubjectId, attributes: sessionAttributes } =\n useExperiments();\n // The real registry, trackExposure included — the internal channel, so the\n // context's facade can never emit an exposure outside this hook.\n const registry = useInternalRegistry();\n // Dev-only misuse guard: a flag key here throws; production fails closed.\n assertHookKeyKind(registry, experimentKey, \"experiment\", \"useExperiment\");\n // Subscribed so a config refresh or pin change re-evaluates this assignment.\n useSyncExternalStore(registry.subscribe, registry.getVersion);\n const subjectId = context?.subjectId ?? sessionSubjectId;\n const attributes = context?.attributes ?? sessionAttributes;\n const assignment = registry.evaluateExperiment({\n experimentKey,\n subjectId,\n attributes,\n });\n\n const exposure = assignment.exposure;\n const manual = context?.exposure === \"manual\";\n useEffect(() => {\n if (manual || exposure === null) return;\n registry.trackExposure(exposure);\n }, [registry, exposure, manual]);\n\n if (!manual) {\n return { variant: assignment.variant, params: assignment.params };\n }\n return {\n variant: assignment.variant,\n params: assignment.params,\n markExposed: () => {\n if (exposure === null) return;\n registry.trackExposure(exposure);\n },\n };\n}\n","import { useSyncExternalStore } from \"react\";\nimport type { QaPin } from \"../types\";\nimport { useExperiments } from \"./context\";\n\n/**\n * The QA override surface, for the dev/debug menu: force a variant for the\n * current subject and session. Pinned assignments render the pinned arm but are\n * never recorded as exposure.\n */\nexport function useExperimentQa(): {\n pins: readonly QaPin[];\n pin: (pin: QaPin) => void;\n unpin: (input: { experimentKey: string }) => void;\n} {\n const { registry } = useExperiments();\n useSyncExternalStore(registry.subscribe, registry.getVersion);\n return {\n pins: registry.getPins(),\n pin: (pin: QaPin): void => {\n registry.pin(pin);\n },\n unpin: (input: { experimentKey: string }): void => {\n registry.unpin(input);\n },\n };\n}\n","import { useSyncExternalStore } from \"react\";\nimport type { ExperimentContext } from \"../types\";\nimport { useExperiments } from \"./context\";\nimport { assertHookKeyKind } from \"./guard\";\n\n/**\n * Read a boolean feature flag for the current subject:\n *\n * ```ts\n * const enabled = useFeatureFlag(\"dark_mode_checkout\");\n * ```\n *\n * Targeting conditions and percentage rollouts evaluate locally against the\n * same deterministic hash the experiments use. Flags never log exposure. An\n * unknown flag is off; an experiment key read here throws a clear error in\n * development — experiments go through useExperiment, the exposure-aware path\n * (production reads fail closed to the config's default).\n */\nexport function useFeatureFlag(\n featureKey: string,\n context?: ExperimentContext,\n): boolean {\n const {\n registry,\n subjectId: sessionSubjectId,\n attributes: sessionAttributes,\n } = useExperiments();\n // Dev-only misuse guard: an experiment key here throws; production reads the config's default.\n assertHookKeyKind(registry, featureKey, \"flag\", \"useFeatureFlag\");\n // Subscribed so a config refresh re-evaluates this flag.\n useSyncExternalStore(registry.subscribe, registry.getVersion);\n const subjectId = context?.subjectId ?? sessionSubjectId;\n const attributes = context?.attributes ?? sessionAttributes;\n return registry.evaluateFlag({ featureKey, subjectId, attributes }).on;\n}\n","import { useSyncExternalStore } from \"react\";\nimport type { ExperimentContext } from \"../types\";\nimport { useExperiments } from \"./context\";\nimport { assertHookKeyKind } from \"./guard\";\n\n/**\n * Read a valued feature flag (string/number/JSON remote config) for the current\n * subject, falling back when the flag is unknown or has no value:\n *\n * ```ts\n * const headline = useFeatureValue(\"checkout_headline\", \"Control headline\");\n * ```\n *\n * The fallback declares the flag's type. Flags never log exposure; an\n * experiment key read here throws a clear error in development — experiments\n * go through useExperiment, the exposure-aware path (production reads fail\n * closed to the config's default).\n */\nexport function useFeatureValue<T>(\n featureKey: string,\n fallback: T,\n context?: ExperimentContext,\n): T {\n const {\n registry,\n subjectId: sessionSubjectId,\n attributes: sessionAttributes,\n } = useExperiments();\n // Dev-only misuse guard: an experiment key here throws; production reads the config's default.\n assertHookKeyKind(registry, featureKey, \"flag\", \"useFeatureValue\");\n // Subscribed so a config refresh re-evaluates this flag.\n useSyncExternalStore(registry.subscribe, registry.getVersion);\n const subjectId = context?.subjectId ?? sessionSubjectId;\n const attributes = context?.attributes ?? sessionAttributes;\n const { value } = registry.evaluateFlag({\n featureKey,\n subjectId,\n attributes,\n });\n // The engine's value is untyped; the caller's fallback declares the flag's type.\n return value === null || value === undefined ? fallback : (value as T);\n}\n"],"names":["ExperimentsContext","createContext","InternalRegistryContext","useExperiments","value","useContext","Error","useInternalRegistry","registry","ExperimentProvider","subjectId","surface","attributes","events","overrides","cacheStorage","clientKey","apiHost","payload","children","useState","created","createFeatureRegistry","undefined","initSync","useEffect","init","destroy","useMemo","trackEvent","input","event","subject","timestamp","Date","now","sendEvent","React","createElement","Provider","useAnalytics","useSyncExternalStore","subscribe","getVersion","ready","isReady","track","useExperiment","experimentKey","context","sessionSubjectId","sessionAttributes","assignment","evaluateExperiment","exposure","manual","trackExposure","variant","params","markExposed","useExperimentQa","pins","getPins","pin","unpin","useFeatureFlag","featureKey","evaluateFlag","on","useFeatureValue","fallback"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAIA;;AAMA;AACA;AACA;AACA;AACA;;MAaaA,kBAAkB,gBAAGC,mBAAa,CAC7C,IACF;;AAEA;AACA;AACA;AACA;AACA;AACO,MAAMC,uBAAuB,gBAAGD,mBAAa,CAClD,IACF,CAAC;;AAED;AACO,SAASE,cAAcA,GAA4B;AACxD,EAAA,MAAMC,KAAK,GAAGC,gBAAU,CAACL,kBAAkB,CAAC;EAC5C,IAAII,KAAK,KAAK,IAAI,EAAE;AAClB,IAAA,MAAM,IAAIE,KAAK,CAAC,yDAAyD,CAAC;AAC5E,EAAA;AACA,EAAA,OAAOF,KAAK;AACd;;AAEA;AACA;AACA;AACA;AACO,SAASG,mBAAmBA,GAAoB;AACrD,EAAA,MAAMC,QAAQ,GAAGH,gBAAU,CAACH,uBAAuB,CAAC;EACpD,IAAIM,QAAQ,KAAK,IAAI,EAAE;AACrB,IAAA,MAAM,IAAIF,KAAK,CACb,8DACF,CAAC;AACH,EAAA;AACA,EAAA,OAAOE,QAAQ;AACjB;;ACzBA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASC,kBAAkBA,CAAC;EACjCC,SAAS;EACTC,OAAO;EACPC,UAAU;EACVC,MAAM;EACNC,SAAS;EACTC,YAAY;EACZC,SAAS;EACTC,OAAO;EACPC,OAAO;AACPC,EAAAA;AACuB,CAAC,EAAE;AAC1B,EAAA,MAAM,CAACX,UAAQ,CAAC,GAAGY,cAAQ,CAAC,MAAM;IAChC,MAAMC,OAAO,GAAGC,8BAAqB,CAAC;MACpCX,OAAO;MACPE,MAAM;MACNC,SAAS;AACTC,MAAAA;AACF,KAAC,CAAC;AACF;AACA;AACA;AACA;AACA,IAAA,IAAIG,OAAO,KAAKK,SAAS,EAAEF,OAAO,CAACG,QAAQ,CAAC;AAAEN,MAAAA;AAAQ,KAAC,CAAC;AACxD,IAAA,OAAOG,O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