@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
@@ -0,0 +1,87 @@
1
+ 'use strict';
2
+
3
+ /**
4
+ * An EventStream that buffers events and flushes them in batches — the same
5
+ * stream every product event uses. Batches are best-effort: analytics events
6
+ * ride the network's happy path and a failed batch is dropped, never retried
7
+ * into a duplicate.
8
+ *
9
+ * This transport is the web flavor (document visibility + sendBeacon). Other
10
+ * runtimes supply their own transport through the `transport` option or their
11
+ * own EventStream entirely.
12
+ */
13
+ function createBatchedEventSender({
14
+ url,
15
+ authorization,
16
+ batchSize = 20,
17
+ flushIntervalMs = 5000,
18
+ transport = defaultTransport(url, authorization)
19
+ }) {
20
+ let queue = [];
21
+ let inFlight = false;
22
+ const flush = async () => {
23
+ if (inFlight || queue.length === 0) return;
24
+ const batch = queue;
25
+ queue = [];
26
+ inFlight = true;
27
+ try {
28
+ await transport(batch);
29
+ } catch {
30
+ // Best-effort stream: a dropped batch must never break the app.
31
+ } finally {
32
+ inFlight = false;
33
+ }
34
+ };
35
+ const onHide = () => {
36
+ void flush();
37
+ };
38
+ const onVisibilityChange = () => {
39
+ if (document.visibilityState === "hidden") onHide();
40
+ };
41
+ const timer = setInterval(() => {
42
+ void flush();
43
+ }, flushIntervalMs);
44
+ document.addEventListener("visibilitychange", onVisibilityChange);
45
+ window.addEventListener("pagehide", onHide);
46
+ return {
47
+ send(event) {
48
+ queue.push(event);
49
+ if (queue.length >= batchSize) void flush();
50
+ },
51
+ flush,
52
+ destroy() {
53
+ clearInterval(timer);
54
+ document.removeEventListener("visibilitychange", onVisibilityChange);
55
+ window.removeEventListener("pagehide", onHide);
56
+ queue = [];
57
+ },
58
+ pendingCount() {
59
+ return queue.length;
60
+ }
61
+ };
62
+ }
63
+ function defaultTransport(url, authorization) {
64
+ return async batch => {
65
+ const body = JSON.stringify(batch);
66
+ if (!authorization && document.visibilityState === "hidden") {
67
+ if (navigator.sendBeacon?.(url, new Blob([body], {
68
+ type: "application/json"
69
+ }))) {
70
+ return;
71
+ }
72
+ }
73
+ const headers = {
74
+ "Content-Type": "application/json"
75
+ };
76
+ if (authorization) headers.Authorization = authorization;
77
+ await fetch(url, {
78
+ method: "POST",
79
+ body,
80
+ headers,
81
+ keepalive: true
82
+ });
83
+ };
84
+ }
85
+
86
+ exports.createBatchedEventSender = createBatchedEventSender;
87
+ //# sourceMappingURL=web.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"web.js","sources":["../../src/web/batched-event-sender.ts"],"sourcesContent":["import type { EventStream, StreamEvent } from \"../events\";\n\nexport interface BatchedEventSender extends EventStream {\n /** Push every queued event now. Best-effort: a failed batch is dropped. */\n flush(): Promise<void>;\n /** Stop the flush timer and drop anything still queued. */\n destroy(): void;\n /** Events queued but not yet flushed. */\n pendingCount(): number;\n}\n\ninterface BatchedEventSenderOptions {\n url: string;\n authorization?: string;\n /** Flush as soon as this many events are queued. Default 20. */\n batchSize?: number;\n /** Flush interval while the page is alive. Default 5000ms. */\n flushIntervalMs?: number;\n /**\n * Where a serialized batch goes. Defaults to sendBeacon while the page is\n * hidden (a mid-unload fetch can die) and a keepalive POST otherwise.\n */\n transport?: (batch: readonly StreamEvent[]) => Promise<void>;\n}\n\n/**\n * An EventStream that buffers events and flushes them in batches — the same\n * stream every product event uses. Batches are best-effort: analytics events\n * ride the network's happy path and a failed batch is dropped, never retried\n * into a duplicate.\n *\n * This transport is the web flavor (document visibility + sendBeacon). Other\n * runtimes supply their own transport through the `transport` option or their\n * own EventStream entirely.\n */\nexport function createBatchedEventSender({\n url,\n authorization,\n batchSize = 20,\n flushIntervalMs = 5000,\n transport = defaultTransport(url, authorization),\n}: BatchedEventSenderOptions): BatchedEventSender {\n let queue: StreamEvent[] = [];\n let inFlight = false;\n\n const flush = async (): Promise<void> => {\n if (inFlight || queue.length === 0) return;\n const batch = queue;\n queue = [];\n inFlight = true;\n try {\n await transport(batch);\n } catch {\n // Best-effort stream: a dropped batch must never break the app.\n } finally {\n inFlight = false;\n }\n };\n\n const onHide = (): void => {\n void flush();\n };\n const onVisibilityChange = (): void => {\n if (document.visibilityState === \"hidden\") onHide();\n };\n\n const timer = setInterval(() => {\n void flush();\n }, flushIntervalMs);\n document.addEventListener(\"visibilitychange\", onVisibilityChange);\n window.addEventListener(\"pagehide\", onHide);\n\n return {\n send(event: StreamEvent): void {\n queue.push(event);\n if (queue.length >= batchSize) void flush();\n },\n flush,\n destroy(): void {\n clearInterval(timer);\n document.removeEventListener(\"visibilitychange\", onVisibilityChange);\n window.removeEventListener(\"pagehide\", onHide);\n queue = [];\n },\n pendingCount(): number {\n return queue.length;\n },\n };\n}\n\nfunction defaultTransport(\n url: string,\n authorization?: string,\n): (batch: readonly StreamEvent[]) => Promise<void> {\n return async (batch) => {\n const body = JSON.stringify(batch);\n if (!authorization && document.visibilityState === \"hidden\") {\n if (navigator.sendBeacon?.(url, new Blob([body], { type: \"application/json\" }))) {\n return;\n }\n }\n const headers: Record<string, string> = { \"Content-Type\": \"application/json\" };\n if (authorization) headers.Authorization = authorization;\n await fetch(url, {\n method: \"POST\",\n body,\n headers,\n keepalive: true,\n });\n };\n}\n"],"names":["createBatchedEventSender","url","authorization","batchSize","flushIntervalMs","transport","defaultTransport","queue","inFlight","flush","length","batch","onHide","onVisibilityChange","document","visibilityState","timer","setInterval","addEventListener","window","send","event","push","destroy","clearInterval","removeEventListener","pendingCount","body","JSON","stringify","navigator","sendBeacon","Blob","type","headers","Authorization","fetch","method","keepalive"],"mappings":";;AAyBA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASA,wBAAwBA,CAAC;EACvCC,GAAG;EACHC,aAAa;AACbC,EAAAA,SAAS,GAAG,EAAE;AACdC,EAAAA,eAAe,GAAG,IAAI;AACtBC,EAAAA,SAAS,GAAGC,gBAAgB,CAACL,GAAG,EAAEC,aAAa;AACtB,CAAC,EAAsB;EAChD,IAAIK,KAAoB,GAAG,EAAE;EAC7B,IAAIC,QAAQ,GAAG,KAAK;AAEpB,EAAA,MAAMC,KAAK,GAAG,YAA2B;AACvC,IAAA,IAAID,QAAQ,IAAID,KAAK,CAACG,MAAM,KAAK,CAAC,EAAE;IACpC,MAAMC,KAAK,GAAGJ,KAAK;AACnBA,IAAAA,KAAK,GAAG,EAAE;AACVC,IAAAA,QAAQ,GAAG,IAAI;IACf,IAAI;MACF,MAAMH,SAAS,CAACM,KAAK,CAAC;AACxB,IAAA,CAAC,CAAC,MAAM;AACN;AAAA,IAAA,CACD,SAAS;AACRH,MAAAA,QAAQ,GAAG,KAAK;AAClB,IAAA;EACF,CAAC;EAED,MAAMI,MAAM,GAAGA,MAAY;IACzB,KAAKH,KAAK,EAAE;EACd,CAAC;EACD,MAAMI,kBAAkB,GAAGA,MAAY;IACrC,IAAIC,QAAQ,CAACC,eAAe,KAAK,QAAQ,EAAEH,MAAM,EAAE;EACrD,CAAC;AAED,EAAA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B;AAC9E,IAAA,IAAIhC,aAAa,EAAEgC,OAAO,CAACC,aAAa,GAAGjC,aAAa;IACxD,MAAMkC,KAAK,CAACnC,GAAG,EAAE;AACfoC,MAAAA,MAAM,EAAE,MAAM;MACdV,IAAI;MACJO,OAAO;AACPI,MAAAA,SAAS,EAAE;AACb,KAAC,CAAC;EACJ,CAAC;AACH;;"}
@@ -0,0 +1,3 @@
1
+ export { b as buildExperimentExposure, c as createFeatureRegistry } from './registry-B73fwn9J.js';
2
+ import '@growthbook/growthbook';
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";"}
@@ -0,0 +1,290 @@
1
+ import * as React from 'react';
2
+ import { createContext, useContext, useState, useEffect, useMemo, useSyncExternalStore } from 'react';
3
+ import { c as createFeatureRegistry } from './registry-B73fwn9J.js';
4
+ import '@growthbook/growthbook';
5
+
6
+ /** A product event handed to the stream. The context stamps subject and timestamp. */
7
+
8
+ /**
9
+ * The registry as components see it: the full read/QA surface minus
10
+ * trackExposure. Exposure emission stays inside the package's hooks, so no
11
+ * component can hand-craft an event around the never-log guards.
12
+ */
13
+
14
+ const ExperimentsContext = /*#__PURE__*/createContext(null);
15
+
16
+ /**
17
+ * The real registry, trackExposure included — the internal channel the
18
+ * package's own hooks use. Deliberately not re-exported from the React entry,
19
+ * so the surface has no typed path to exposure emission.
20
+ */
21
+ const InternalRegistryContext = /*#__PURE__*/createContext(null);
22
+
23
+ /** The mounted experiments context. Throws when no ExperimentProvider is mounted. */
24
+ function useExperiments() {
25
+ const value = useContext(ExperimentsContext);
26
+ if (value === null) {
27
+ throw new Error("useExperiments must be used within <ExperimentProvider>");
28
+ }
29
+ return value;
30
+ }
31
+
32
+ /**
33
+ * The real registry for the package's own hooks (useExperiment's exposure
34
+ * emission). Throws when no ExperimentProvider is mounted.
35
+ */
36
+ function useInternalRegistry() {
37
+ const registry = useContext(InternalRegistryContext);
38
+ if (registry === null) {
39
+ throw new Error("useInternalRegistry must be used within <ExperimentProvider>");
40
+ }
41
+ return registry;
42
+ }
43
+
44
+ /**
45
+ * Mounts the session's experiment registry once, after auth. A `payload` seeds
46
+ * the registry synchronously at construction, so the first paint already reads
47
+ * the real assignment; the fetch path initializes async and children render
48
+ * immediately against a still-initializing registry, which returns control
49
+ * defaults, so a variant never flashes ahead of the assignment. Without a
50
+ * client key nothing is fetched — the control experience.
51
+ */
52
+ function ExperimentProvider({
53
+ subjectId,
54
+ surface,
55
+ attributes,
56
+ events,
57
+ overrides,
58
+ cacheStorage,
59
+ clientKey,
60
+ apiHost,
61
+ payload,
62
+ children
63
+ }) {
64
+ const [registry] = useState(() => {
65
+ const created = createFeatureRegistry({
66
+ surface,
67
+ events,
68
+ overrides,
69
+ cacheStorage
70
+ });
71
+ // Seed synchronously when the payload is already available: the first
72
+ // commit reads the real assignment instead of flashing control for a
73
+ // frame. The effect below re-seeds on payload change and on remount
74
+ // (StrictMode's simulated unmount destroys the client).
75
+ if (payload !== undefined) created.initSync({
76
+ payload
77
+ });
78
+ return created;
79
+ });
80
+ useEffect(() => {
81
+ if (payload !== undefined) {
82
+ registry.initSync({
83
+ payload
84
+ });
85
+ } else {
86
+ void registry.init({
87
+ clientKey,
88
+ apiHost
89
+ });
90
+ }
91
+ return () => {
92
+ registry.destroy();
93
+ };
94
+ }, [registry, clientKey, apiHost, payload]);
95
+ const value = useMemo(() => ({
96
+ registry,
97
+ subjectId,
98
+ attributes,
99
+ trackEvent(input) {
100
+ const event = {
101
+ ...input,
102
+ subject: input["subject"] ?? subjectId,
103
+ timestamp: Date.now()
104
+ };
105
+ registry.sendEvent(event);
106
+ }
107
+ }), [registry, subjectId, attributes]);
108
+ return (
109
+ /*#__PURE__*/
110
+ // The internal channel carries the real registry (trackExposure included)
111
+ // to the package's own hooks; the public context carries the facade.
112
+ React.createElement(InternalRegistryContext.Provider, {
113
+ value: registry
114
+ }, /*#__PURE__*/React.createElement(ExperimentsContext.Provider, {
115
+ value: value
116
+ }, children))
117
+ );
118
+ }
119
+
120
+ /**
121
+ * The session's product-analytics stream — the same stream experiment exposures
122
+ * ride. `track` stamps the subject and timestamp. `ready` is false until the
123
+ * experiment config finishes initializing, so callers can skip events that have
124
+ * no meaningful assignment context yet.
125
+ */
126
+ function useAnalytics() {
127
+ const {
128
+ registry,
129
+ trackEvent
130
+ } = useExperiments();
131
+ useSyncExternalStore(registry.subscribe, registry.getVersion);
132
+ return {
133
+ ready: registry.isReady(),
134
+ track: trackEvent
135
+ };
136
+ }
137
+
138
+ /**
139
+ * Read the experiment's assignment for the current subject:
140
+ *
141
+ * ```ts
142
+ * const { variant, params } = useExperiment("brick_wall");
143
+ * // variant: the assigned arm key from the experiment config
144
+ * // params: the configured parameter payload for the assigned arm
145
+ * ```
146
+ *
147
+ * Pass `context` to evaluate for a different subject or with extra targeting
148
+ * attributes; both default to the session's. Targeting gates eligibility before
149
+ * bucketing — a member who fails targeting gets the default arm with no
150
+ * exposure. The hash input is always the subject id.
151
+ *
152
+ * Exactly one exposure is recorded, when the assigned variant is actually
153
+ * rendered (post-commit) — never on compute, and never for a member who was
154
+ * bucketed but not shown the experience. Defaults, stopped experiments,
155
+ * targeting failures, and QA pins never emit exposure.
156
+ *
157
+ * With `exposure: "manual"` the hook instead returns a `markExposed` trigger —
158
+ * for call sites that evaluate now but render the experience later. Call it
159
+ * when the experience actually renders; it no-ops on an unexposed assignment.
160
+ *
161
+ * Misuse guard: calling this on a feature-flag key throws a clear error in
162
+ * development (flags go through useFeatureFlag/useFeatureValue); production
163
+ * reads fail closed to control.
164
+ */
165
+ function useExperiment(experimentKey, context) {
166
+ const {
167
+ subjectId: sessionSubjectId,
168
+ attributes: sessionAttributes
169
+ } = useExperiments();
170
+ // The real registry, trackExposure included — the internal channel, so the
171
+ // context's facade can never emit an exposure outside this hook.
172
+ const registry = useInternalRegistry();
173
+ // Subscribed so a config refresh or pin change re-evaluates this assignment.
174
+ useSyncExternalStore(registry.subscribe, registry.getVersion);
175
+ const subjectId = context?.subjectId ?? sessionSubjectId;
176
+ const attributes = context?.attributes ?? sessionAttributes;
177
+ const assignment = registry.evaluateExperiment({
178
+ experimentKey,
179
+ subjectId,
180
+ attributes
181
+ });
182
+ const exposure = assignment.exposure;
183
+ const manual = context?.exposure === "manual";
184
+ useEffect(() => {
185
+ if (manual || exposure === null) return;
186
+ registry.trackExposure(exposure);
187
+ }, [registry, exposure, manual]);
188
+ if (!manual) {
189
+ return {
190
+ variant: assignment.variant,
191
+ params: assignment.params
192
+ };
193
+ }
194
+ return {
195
+ variant: assignment.variant,
196
+ params: assignment.params,
197
+ markExposed: () => {
198
+ if (exposure === null) return;
199
+ registry.trackExposure(exposure);
200
+ }
201
+ };
202
+ }
203
+
204
+ /**
205
+ * The QA override surface, for the dev/debug menu: force a variant for the
206
+ * current subject and session. Pinned assignments render the pinned arm but are
207
+ * never recorded as exposure.
208
+ */
209
+ function useExperimentQa() {
210
+ const {
211
+ registry
212
+ } = useExperiments();
213
+ useSyncExternalStore(registry.subscribe, registry.getVersion);
214
+ return {
215
+ pins: registry.getPins(),
216
+ pin: pin => {
217
+ registry.pin(pin);
218
+ },
219
+ unpin: input => {
220
+ registry.unpin(input);
221
+ }
222
+ };
223
+ }
224
+
225
+ /**
226
+ * Read a boolean feature flag for the current subject:
227
+ *
228
+ * ```ts
229
+ * const enabled = useFeatureFlag("dark_mode_checkout");
230
+ * ```
231
+ *
232
+ * Targeting conditions and percentage rollouts evaluate locally against the
233
+ * same deterministic hash the experiments use. Flags never log exposure. An
234
+ * unknown flag is off; an experiment key read here throws a clear error in
235
+ * development — experiments go through useExperiment, the exposure-aware path
236
+ * (production reads fail closed to the config's default).
237
+ */
238
+ function useFeatureFlag(featureKey, context) {
239
+ const {
240
+ registry,
241
+ subjectId: sessionSubjectId,
242
+ attributes: sessionAttributes
243
+ } = useExperiments();
244
+ // Subscribed so a config refresh re-evaluates this flag.
245
+ useSyncExternalStore(registry.subscribe, registry.getVersion);
246
+ const subjectId = context?.subjectId ?? sessionSubjectId;
247
+ const attributes = context?.attributes ?? sessionAttributes;
248
+ return registry.evaluateFlag({
249
+ featureKey,
250
+ subjectId,
251
+ attributes
252
+ }).on;
253
+ }
254
+
255
+ /**
256
+ * Read a valued feature flag (string/number/JSON remote config) for the current
257
+ * subject, falling back when the flag is unknown or has no value:
258
+ *
259
+ * ```ts
260
+ * const headline = useFeatureValue("checkout_headline", "Control headline");
261
+ * ```
262
+ *
263
+ * The fallback declares the flag's type. Flags never log exposure; an
264
+ * experiment key read here throws a clear error in development — experiments
265
+ * go through useExperiment, the exposure-aware path (production reads fail
266
+ * closed to the config's default).
267
+ */
268
+ function useFeatureValue(featureKey, fallback, context) {
269
+ const {
270
+ registry,
271
+ subjectId: sessionSubjectId,
272
+ attributes: sessionAttributes
273
+ } = useExperiments();
274
+ // Subscribed so a config refresh re-evaluates this flag.
275
+ useSyncExternalStore(registry.subscribe, registry.getVersion);
276
+ const subjectId = context?.subjectId ?? sessionSubjectId;
277
+ const attributes = context?.attributes ?? sessionAttributes;
278
+ const {
279
+ value
280
+ } = registry.evaluateFlag({
281
+ featureKey,
282
+ subjectId,
283
+ attributes
284
+ });
285
+ // The engine's value is untyped; the caller's fallback declares the flag's type.
286
+ return value === null || value === undefined ? fallback : value;
287
+ }
288
+
289
+ export { ExperimentProvider, ExperimentsContext, useAnalytics, useExperiment, useExperimentQa, useExperiments, useFeatureFlag, useFeatureValue };
290
+ //# 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,aAAa,CAC7C,IACF;;AAEA;AACA;AACA;AACA;AACA;AACO,MAAMC,uBAAuB,gBAAGD,aAAa,CAClD,IACF,CAAC;;AAED;AACO,SAASE,cAAcA,GAA4B;AACxD,EAAA,MAAMC,KAAK,GAAGC,UAAU,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,UAAU,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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