@vllnt/convex-experiments 0.1.0-canary.0b21dd5

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 (71) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +161 -0
  3. package/dist/client/index.d.ts +168 -0
  4. package/dist/client/index.d.ts.map +1 -0
  5. package/dist/client/index.js +154 -0
  6. package/dist/client/index.js.map +1 -0
  7. package/dist/client/types.d.ts +75 -0
  8. package/dist/client/types.d.ts.map +1 -0
  9. package/dist/client/types.js +3 -0
  10. package/dist/client/types.js.map +1 -0
  11. package/dist/component/_generated/api.d.ts +38 -0
  12. package/dist/component/_generated/api.d.ts.map +1 -0
  13. package/dist/component/_generated/api.js +31 -0
  14. package/dist/component/_generated/api.js.map +1 -0
  15. package/dist/component/_generated/component.d.ts +128 -0
  16. package/dist/component/_generated/component.d.ts.map +1 -0
  17. package/dist/component/_generated/component.js +11 -0
  18. package/dist/component/_generated/component.js.map +1 -0
  19. package/dist/component/_generated/dataModel.d.ts +46 -0
  20. package/dist/component/_generated/dataModel.d.ts.map +1 -0
  21. package/dist/component/_generated/dataModel.js +11 -0
  22. package/dist/component/_generated/dataModel.js.map +1 -0
  23. package/dist/component/_generated/server.d.ts +133 -0
  24. package/dist/component/_generated/server.d.ts.map +1 -0
  25. package/dist/component/_generated/server.js +80 -0
  26. package/dist/component/_generated/server.js.map +1 -0
  27. package/dist/component/convex.config.d.ts +3 -0
  28. package/dist/component/convex.config.d.ts.map +1 -0
  29. package/dist/component/convex.config.js +7 -0
  30. package/dist/component/convex.config.js.map +1 -0
  31. package/dist/component/mutations.d.ts +93 -0
  32. package/dist/component/mutations.d.ts.map +1 -0
  33. package/dist/component/mutations.js +359 -0
  34. package/dist/component/mutations.js.map +1 -0
  35. package/dist/component/queries.d.ts +72 -0
  36. package/dist/component/queries.d.ts.map +1 -0
  37. package/dist/component/queries.js +134 -0
  38. package/dist/component/queries.js.map +1 -0
  39. package/dist/component/schema.d.ts +99 -0
  40. package/dist/component/schema.d.ts.map +1 -0
  41. package/dist/component/schema.js +64 -0
  42. package/dist/component/schema.js.map +1 -0
  43. package/dist/component/validators.d.ts +109 -0
  44. package/dist/component/validators.d.ts.map +1 -0
  45. package/dist/component/validators.js +49 -0
  46. package/dist/component/validators.js.map +1 -0
  47. package/dist/react/index.d.ts +57 -0
  48. package/dist/react/index.d.ts.map +1 -0
  49. package/dist/react/index.js +39 -0
  50. package/dist/react/index.js.map +1 -0
  51. package/dist/shared.d.ts +32 -0
  52. package/dist/shared.d.ts.map +1 -0
  53. package/dist/shared.js +52 -0
  54. package/dist/shared.js.map +1 -0
  55. package/package.json +116 -0
  56. package/src/client/index.ts +343 -0
  57. package/src/client/types.ts +78 -0
  58. package/src/component/_generated/api.ts +54 -0
  59. package/src/component/_generated/component.ts +133 -0
  60. package/src/component/_generated/dataModel.ts +60 -0
  61. package/src/component/_generated/server.ts +169 -0
  62. package/src/component/convex.config.ts +9 -0
  63. package/src/component/mutations.ts +414 -0
  64. package/src/component/queries.ts +161 -0
  65. package/src/component/schema.ts +71 -0
  66. package/src/component/validators.ts +65 -0
  67. package/src/react/index.test.tsx +85 -0
  68. package/src/react/index.tsx +68 -0
  69. package/src/shared.ts +69 -0
  70. package/src/test.ts +12 -0
  71. package/src/unit.test.ts +84 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 bntvllnt
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,161 @@
1
+ <!-- Badges -->
2
+ [![convex-component](https://img.shields.io/badge/convex-component-EE342F.svg)](https://www.convex.dev/components)
3
+ [![npm](https://img.shields.io/npm/v/@vllnt/convex-experiments.svg)](https://www.npmjs.com/package/@vllnt/convex-experiments)
4
+ [![CI](https://github.com/vllnt/convex-experiments/actions/workflows/ci.yml/badge.svg)](https://github.com/vllnt/convex-experiments/actions/workflows/ci.yml)
5
+ [![license](https://img.shields.io/npm/l/@vllnt/convex-experiments.svg)](./LICENSE)
6
+
7
+ # @vllnt/convex-experiments
8
+
9
+ Deterministic A/B experimentation — sticky variant assignment and deduped exposure tracking, as a
10
+ Convex component.
11
+
12
+ ```ts
13
+ const experiments = new Experiments(components.experiments);
14
+ await experiments.define(ctx, "checkout_button", {
15
+ variants: [
16
+ { key: "control", weight: 1 },
17
+ { key: "treatment", weight: 1 },
18
+ ],
19
+ });
20
+ const { variant } = await experiments.logExposure(ctx, "checkout_button", userId);
21
+ if (variant === "treatment") showNewButton();
22
+ ```
23
+
24
+ Define an experiment with weighted variants; enroll subjects into a **sticky** variant chosen
25
+ deterministically from `(salt, subjectRef)`; record exposures and read per-variant tallies. Pair it
26
+ with a feature-flag system for kill-switches and measure conversions in your own tables — this
27
+ component handles assignment and exposure. Domain-neutral: any subject, any surface.
28
+
29
+ ## Features
30
+
31
+ - **Deterministic + sticky** — the same subject always lands in the same weighted variant, even before anything is stored.
32
+ - **Weighted variants** — split traffic by relative weights (`1:1`, `90:10`, N-way); equal weights split evenly.
33
+ - **Enrollment lifecycle** — `draft → running → stopped`; only `running` enrolls, and stopping preserves recorded data.
34
+ - **Deduped exposures + O(variants) results** — one tallied row per subject; `results` reads maintained per-variant tallies (`assigned`/`subjects`/`exposures`/`weight`), never scanning the exposure table.
35
+ - **Sample-ratio-ready** — `assigned` + `weight` per variant let you check observed vs expected split (SRM).
36
+ - **`peek`** — a read-only deterministic query returns a subject's sticky variant without writing (SSR / flicker-free first paint).
37
+ - **Immutable once assigned** — `variants`/`salt` are fixed after enrollment (changing them throws); define a new key to re-randomize.
38
+ - **Lifecycle + GDPR** — `listExperiments` to discover, `forgetSubject` to erase one subject, `deleteExperiment` to cascade-delete.
39
+ - **Scopes** — global by default, or namespace per tenant / surface (folded into the hash for independent bucketing).
40
+ - **Fully typed** — variant keys, weights, and outcomes are concrete types end to end; no `any`.
41
+ - **Server-sourced time** — assignment timestamps come from the server, never the caller.
42
+
43
+ ## Installation
44
+
45
+ ```bash
46
+ pnpm add @vllnt/convex-experiments
47
+ ```
48
+
49
+ Peer dependency: `convex@^1.41.0`.
50
+
51
+ ## Usage
52
+
53
+ ```ts
54
+ // convex/convex.config.ts
55
+ import { defineApp } from "convex/server";
56
+ import experiments from "@vllnt/convex-experiments/convex.config";
57
+
58
+ const app = defineApp();
59
+ app.use(experiments);
60
+ export default app;
61
+ ```
62
+
63
+ ```ts
64
+ // convex/checkout.ts — host owns auth; pass an opaque subjectRef in.
65
+ import { components } from "./_generated/api";
66
+ import { mutation } from "./_generated/server";
67
+ import { v } from "convex/values";
68
+ import { Experiments } from "@vllnt/convex-experiments";
69
+
70
+ const experiments = new Experiments(components.experiments);
71
+
72
+ export const view = mutation({
73
+ args: { userId: v.string() },
74
+ handler: async (ctx, { userId }) => {
75
+ const { variant } = await experiments.logExposure(ctx, "checkout_button", userId);
76
+ return { variant }; // "control" | "treatment" | null (not enrolled)
77
+ },
78
+ });
79
+ ```
80
+
81
+ Measure the outcome in your own table, joined on the assigned variant — then read tallies with
82
+ `results(ctx, "checkout_button")`. See [`example/convex/example.ts`](example/convex/example.ts) for a
83
+ host-side conversion recorder.
84
+
85
+ ## API Reference
86
+
87
+ | Method | Kind | Result |
88
+ |--------|------|--------|
89
+ | `define(ctx, key, { variants, scope?, salt?, status? })` | mutation | `{ created: boolean }` |
90
+ | `setStatus(ctx, key, status, scope?)` | mutation | `boolean` |
91
+ | `assign(ctx, key, subjectRef, scope?)` | mutation | `{ variant: null } \| { variant: string; isNew: boolean }` |
92
+ | `logExposure(ctx, key, subjectRef, scope?)` | mutation | `{ variant: string \| null }` |
93
+ | `forgetSubject(ctx, key, subjectRef, scope?)` | mutation | `boolean` (GDPR erasure) |
94
+ | `deleteExperiment(ctx, key, { scope?, batch? })` | mutation | `number` (cascade delete) |
95
+ | `getExperiment(ctx, key, scope?)` | query | `ExperimentDefinition \| null` |
96
+ | `listExperiments(ctx, { scope?, status? })` | query | `ExperimentDefinition[]` |
97
+ | `getAssignment(ctx, key, subjectRef, scope?)` | query | `{ variant, assignedAt } \| null` |
98
+ | `peek(ctx, key, subjectRef, scope?)` | query | `{ variant: string \| null }` (no write) |
99
+ | `results(ctx, key, scope?)` | query | `{ variant, assigned, subjects, exposures, weight }[]` |
100
+
101
+ Full reference: [docs/API.md](docs/API.md).
102
+
103
+ ## React
104
+
105
+ Optional, tree-shakeable hooks via `@vllnt/convex-experiments/react` (`react` is an optional peer
106
+ dep — a backend-only consumer pulls none of it). Each hook wraps `useQuery` over a query reference
107
+ **you re-export** from your app, so the component never owns your `api`.
108
+
109
+ ```tsx
110
+ // convex/experiments.ts — re-export the host-side wrappers (auth gated)
111
+ // export const myVariant = query({ args: { userId: v.string() },
112
+ // handler: (ctx, { userId }) => experiments.peek(ctx, "checkout_button", userId) });
113
+
114
+ import { useVariant } from "@vllnt/convex-experiments/react";
115
+ import { api } from "@/convex/_generated/api";
116
+
117
+ function CheckoutButton({ userId }: { userId: string }) {
118
+ // deterministic first paint via peek → no flash-of-control
119
+ const variant = useVariant(api.experiments.myVariant, { key: "checkout_button", subjectRef: userId });
120
+ return variant === "treatment" ? <OneClick /> : <Classic />;
121
+ }
122
+ ```
123
+
124
+ | Hook | Wraps | Returns |
125
+ |------|-------|---------|
126
+ | `useVariant(peekRef, args)` | `peek` | `string \| null \| undefined` (variant / not-enrolled / loading) |
127
+ | `useAssignment(getAssignmentRef, args)` | `getAssignment` | `Assignment \| null \| undefined` |
128
+ | `useExperimentResults(resultsRef, args)` | `results` | `VariantResult[] \| undefined` |
129
+
130
+ ## Security
131
+
132
+ - Auth-agnostic — the host resolves identity and decides who may define, start, stop, or enroll.
133
+ - Tables sandboxed — reached only through the exported functions; `subjectRef`, variant keys, and `scope` stay opaque.
134
+ - Server-sourced timestamps — a caller cannot supply assignment time.
135
+
136
+ See [docs/API.md](docs/API.md).
137
+
138
+ ## Testing
139
+
140
+ ```bash
141
+ pnpm test # single run
142
+ pnpm test:coverage # enforced 100% on covered files
143
+ ```
144
+
145
+ Tests run against the real component runtime via `convex-test` (`@edge-runtime/vm`), not mocks.
146
+
147
+ ## Contributing
148
+
149
+ See [CONTRIBUTING.md](CONTRIBUTING.md).
150
+
151
+ ## Author
152
+
153
+ Built by [bntvllnt](https://github.com/bntvllnt) · [bntvllnt.com](https://bntvllnt.com) · [X @bntvllnt](https://x.com/bntvllnt)
154
+
155
+ Part of the [@vllnt](https://github.com/vllnt) Convex component fleet — [vllnt.com](https://vllnt.com)
156
+
157
+ If this is useful, [sponsor the work](https://github.com/sponsors/bntvllnt).
158
+
159
+ ## License
160
+
161
+ MIT — see [LICENSE](LICENSE).
@@ -0,0 +1,168 @@
1
+ import type { FunctionArgs, FunctionReference, FunctionReturnType } from "convex/server";
2
+ import type { Assignment, AssignOutcome, DefineOptions, ExperimentDefinition, ExperimentsOptions, ExperimentStatus, ExposureOutcome, Variant, VariantResult } from "./types.js";
3
+ /**
4
+ * The experiments component's function references, as exposed on the host via
5
+ * `components.experiments`. All values are concrete (no opaque host data), so the
6
+ * client is fully typed end to end — there is no generic to narrow.
7
+ */
8
+ export interface ExperimentsComponent {
9
+ mutations: {
10
+ define: FunctionReference<"mutation", "internal", {
11
+ scope: string;
12
+ key: string;
13
+ variants: Variant[];
14
+ salt: string;
15
+ status: ExperimentStatus;
16
+ }, {
17
+ created: boolean;
18
+ }>;
19
+ setStatus: FunctionReference<"mutation", "internal", {
20
+ scope: string;
21
+ key: string;
22
+ status: ExperimentStatus;
23
+ }, boolean>;
24
+ assign: FunctionReference<"mutation", "internal", {
25
+ scope: string;
26
+ key: string;
27
+ subjectRef: string;
28
+ }, AssignOutcome>;
29
+ logExposure: FunctionReference<"mutation", "internal", {
30
+ scope: string;
31
+ key: string;
32
+ subjectRef: string;
33
+ }, ExposureOutcome>;
34
+ forgetSubject: FunctionReference<"mutation", "internal", {
35
+ scope: string;
36
+ key: string;
37
+ subjectRef: string;
38
+ }, boolean>;
39
+ deleteExperiment: FunctionReference<"mutation", "internal", {
40
+ scope: string;
41
+ key: string;
42
+ batch: number;
43
+ }, number>;
44
+ };
45
+ queries: {
46
+ getExperiment: FunctionReference<"query", "internal", {
47
+ scope: string;
48
+ key: string;
49
+ }, ExperimentDefinition | null>;
50
+ listExperiments: FunctionReference<"query", "internal", {
51
+ scope: string;
52
+ status?: ExperimentStatus;
53
+ }, ExperimentDefinition[]>;
54
+ getAssignment: FunctionReference<"query", "internal", {
55
+ scope: string;
56
+ key: string;
57
+ subjectRef: string;
58
+ }, Assignment | null>;
59
+ peek: FunctionReference<"query", "internal", {
60
+ scope: string;
61
+ key: string;
62
+ subjectRef: string;
63
+ }, ExposureOutcome>;
64
+ results: FunctionReference<"query", "internal", {
65
+ scope: string;
66
+ key: string;
67
+ }, VariantResult[]>;
68
+ };
69
+ }
70
+ interface RunQueryCtx {
71
+ runQuery<Q extends FunctionReference<"query", "internal">>(reference: Q, args: FunctionArgs<Q>): Promise<FunctionReturnType<Q>>;
72
+ }
73
+ interface RunMutationCtx {
74
+ runMutation<M extends FunctionReference<"mutation", "internal">>(reference: M, args: FunctionArgs<M>): Promise<FunctionReturnType<M>>;
75
+ }
76
+ /**
77
+ * Consumer-facing client for deterministic A/B experimentation. The host owns
78
+ * meaning and auth; it passes an opaque `subjectRef` and variant keys, and the
79
+ * component answers a sticky, weight-respecting variant plus a deduped exposure
80
+ * tally. Assignment is release-control-free — pair it with a feature-flag
81
+ * component for kill-switches; this layer only assigns and measures.
82
+ *
83
+ * @example
84
+ * ```ts
85
+ * const experiments = new Experiments(components.experiments);
86
+ * await experiments.define(ctx, "checkout_button", {
87
+ * variants: [
88
+ * { key: "control", weight: 1 },
89
+ * { key: "treatment", weight: 1 },
90
+ * ],
91
+ * });
92
+ * const { variant } = await experiments.logExposure(ctx, "checkout_button", userId);
93
+ * if (variant === "treatment") renderNewButton();
94
+ * // later: const tally = await experiments.results(ctx, "checkout_button");
95
+ * ```
96
+ */
97
+ export declare class Experiments {
98
+ private readonly component;
99
+ private readonly defaultScope;
100
+ private readonly defaultStatus;
101
+ constructor(component: ExperimentsComponent, options?: ExperimentsOptions);
102
+ private scopeOf;
103
+ /**
104
+ * Create or update an experiment. `variants` are weighted (equal weights split
105
+ * evenly). `salt` defaults to `key`; `status` to the client default (`running`).
106
+ * Returns `{ created }` — `false` when an existing definition was updated. Status
107
+ * transitions are always allowed; `variants`/`salt` are immutable once a subject
108
+ * is assigned (throws `EXPERIMENT_LOCKED`).
109
+ */
110
+ define(ctx: RunMutationCtx, key: string, opts: DefineOptions & {
111
+ variants: Variant[];
112
+ }): Promise<{
113
+ created: boolean;
114
+ }>;
115
+ /** Move an experiment to a new lifecycle status. Returns `false` if it is absent. */
116
+ setStatus(ctx: RunMutationCtx, key: string, status: ExperimentStatus, scope?: string): Promise<boolean>;
117
+ /**
118
+ * Enroll a subject and return the sticky variant. `{ variant: null }` when the
119
+ * experiment is absent or not running; otherwise `{ variant, isNew }`, `isNew`
120
+ * true only on the first persisting call.
121
+ */
122
+ assign(ctx: RunMutationCtx, key: string, subjectRef: string, scope?: string): Promise<AssignOutcome>;
123
+ /**
124
+ * Record an exposure (enrolling the subject if needed) and return their variant,
125
+ * or `null` if not enrolled. Repeated exposures for one subject are deduped into
126
+ * a single tallied row.
127
+ */
128
+ logExposure(ctx: RunMutationCtx, key: string, subjectRef: string, scope?: string): Promise<ExposureOutcome>;
129
+ /** The experiment definition, or `null` if none exists. */
130
+ getExperiment(ctx: RunQueryCtx, key: string, scope?: string): Promise<ExperimentDefinition | null>;
131
+ /** A subject's sticky assignment, or `null` if not enrolled. */
132
+ getAssignment(ctx: RunQueryCtx, key: string, subjectRef: string, scope?: string): Promise<Assignment | null>;
133
+ /**
134
+ * Read-only deterministic variant for a subject — the sticky variant **without
135
+ * persisting**. Returns the stored assignment if present, else the deterministic
136
+ * pick; `null` when not enrolled. Use for SSR / a flicker-free first paint, then
137
+ * call `logExposure` to enroll + tally.
138
+ */
139
+ peek(ctx: RunQueryCtx, key: string, subjectRef: string, scope?: string): Promise<ExposureOutcome>;
140
+ /** Every experiment in a scope, optionally filtered by `status`. */
141
+ listExperiments(ctx: RunQueryCtx, opts?: {
142
+ scope?: string;
143
+ status?: ExperimentStatus;
144
+ }): Promise<ExperimentDefinition[]>;
145
+ /**
146
+ * Per-variant tallies — `assigned`, distinct `subjects` exposed, total
147
+ * `exposures`, and the configured `weight` (for sample-ratio-mismatch). Reads
148
+ * O(variants), not the exposure table.
149
+ */
150
+ results(ctx: RunQueryCtx, key: string, scope?: string): Promise<VariantResult[]>;
151
+ /**
152
+ * Erase a subject's assignment + exposure in one experiment (GDPR right-to-
153
+ * erasure), decrementing tallies. Returns `true` if anything was deleted. Loop
154
+ * over `listExperiments` to erase a subject across a whole scope.
155
+ */
156
+ forgetSubject(ctx: RunMutationCtx, key: string, subjectRef: string, scope?: string): Promise<boolean>;
157
+ /**
158
+ * Delete an experiment and all of its data (definition, assignments, exposures,
159
+ * tallies). Bounded + self-rescheduling; returns the rows removed this pass.
160
+ * Idempotent and safe on an absent experiment.
161
+ */
162
+ deleteExperiment(ctx: RunMutationCtx, key: string, opts?: {
163
+ scope?: string;
164
+ batch?: number;
165
+ }): Promise<number>;
166
+ }
167
+ export type { Assignment, AssignOutcome, DefineOptions, ExperimentDefinition, ExperimentsOptions, ExperimentStatus, ExposureOutcome, Variant, VariantResult, };
168
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,YAAY,EACZ,iBAAiB,EACjB,kBAAkB,EACnB,MAAM,eAAe,CAAC;AACvB,OAAO,KAAK,EACV,UAAU,EACV,aAAa,EACb,aAAa,EACb,oBAAoB,EACpB,kBAAkB,EAClB,gBAAgB,EAChB,eAAe,EACf,OAAO,EACP,aAAa,EACd,MAAM,YAAY,CAAC;AAGpB;;;;GAIG;AACH,MAAM,WAAW,oBAAoB;IACnC,SAAS,EAAE;QACT,MAAM,EAAE,iBAAiB,CACvB,UAAU,EACV,UAAU,EACV;YACE,KAAK,EAAE,MAAM,CAAC;YACd,GAAG,EAAE,MAAM,CAAC;YACZ,QAAQ,EAAE,OAAO,EAAE,CAAC;YACpB,IAAI,EAAE,MAAM,CAAC;YACb,MAAM,EAAE,gBAAgB,CAAC;SAC1B,EACD;YAAE,OAAO,EAAE,OAAO,CAAA;SAAE,CACrB,CAAC;QACF,SAAS,EAAE,iBAAiB,CAC1B,UAAU,EACV,UAAU,EACV;YAAE,KAAK,EAAE,MAAM,CAAC;YAAC,GAAG,EAAE,MAAM,CAAC;YAAC,MAAM,EAAE,gBAAgB,CAAA;SAAE,EACxD,OAAO,CACR,CAAC;QACF,MAAM,EAAE,iBAAiB,CACvB,UAAU,EACV,UAAU,EACV;YAAE,KAAK,EAAE,MAAM,CAAC;YAAC,GAAG,EAAE,MAAM,CAAC;YAAC,UAAU,EAAE,MAAM,CAAA;SAAE,EAClD,aAAa,CACd,CAAC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AE,MAAM,EACX,UAAU,EAAE,MAAM,EAClB,KAAK,CAAC,EAAE,MAAM,GACb,OAAO,CAAC,OAAO,CAAC,CAMlB;IAED;;;;OAIG;IACH,gBAAgB,CACd,GAAG,EAAE,cAAc,EACnB,GAAG,EAAE,MAAM,EACX,IAAI,GAAE;QAAE,KAAK,CAAC,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAA;KAAO,GAC5C,OAAO,CAAC,MAAM,CAAC,CAMjB;CACF;AAED,YAAY,EACV,UAAU,EACV,aAAa,EACb,aAAa,EACb,oBAAoB,EACpB,kBAAkB,EAClB,gBAAgB,EAChB,eAAe,EACf,OAAO,EACP,aAAa,GACd,CAAC"}
@@ -0,0 +1,154 @@
1
+ import { DEFAULT_DELETE_BATCH, DEFAULT_SCOPE, DEFAULT_STATUS } from "../shared.js";
2
+ /**
3
+ * Consumer-facing client for deterministic A/B experimentation. The host owns
4
+ * meaning and auth; it passes an opaque `subjectRef` and variant keys, and the
5
+ * component answers a sticky, weight-respecting variant plus a deduped exposure
6
+ * tally. Assignment is release-control-free — pair it with a feature-flag
7
+ * component for kill-switches; this layer only assigns and measures.
8
+ *
9
+ * @example
10
+ * ```ts
11
+ * const experiments = new Experiments(components.experiments);
12
+ * await experiments.define(ctx, "checkout_button", {
13
+ * variants: [
14
+ * { key: "control", weight: 1 },
15
+ * { key: "treatment", weight: 1 },
16
+ * ],
17
+ * });
18
+ * const { variant } = await experiments.logExposure(ctx, "checkout_button", userId);
19
+ * if (variant === "treatment") renderNewButton();
20
+ * // later: const tally = await experiments.results(ctx, "checkout_button");
21
+ * ```
22
+ */
23
+ export class Experiments {
24
+ component;
25
+ defaultScope;
26
+ defaultStatus;
27
+ constructor(component, options = {}) {
28
+ this.component = component;
29
+ this.defaultScope = options.defaultScope ?? DEFAULT_SCOPE;
30
+ this.defaultStatus = options.defaultStatus ?? DEFAULT_STATUS;
31
+ }
32
+ scopeOf(scope) {
33
+ return scope ?? this.defaultScope;
34
+ }
35
+ /**
36
+ * Create or update an experiment. `variants` are weighted (equal weights split
37
+ * evenly). `salt` defaults to `key`; `status` to the client default (`running`).
38
+ * Returns `{ created }` — `false` when an existing definition was updated. Status
39
+ * transitions are always allowed; `variants`/`salt` are immutable once a subject
40
+ * is assigned (throws `EXPERIMENT_LOCKED`).
41
+ */
42
+ define(ctx, key, opts) {
43
+ return ctx.runMutation(this.component.mutations.define, {
44
+ scope: this.scopeOf(opts.scope),
45
+ key,
46
+ variants: opts.variants,
47
+ salt: opts.salt ?? key,
48
+ status: opts.status ?? this.defaultStatus,
49
+ });
50
+ }
51
+ /** Move an experiment to a new lifecycle status. Returns `false` if it is absent. */
52
+ setStatus(ctx, key, status, scope) {
53
+ return ctx.runMutation(this.component.mutations.setStatus, {
54
+ scope: this.scopeOf(scope),
55
+ key,
56
+ status,
57
+ });
58
+ }
59
+ /**
60
+ * Enroll a subject and return the sticky variant. `{ variant: null }` when the
61
+ * experiment is absent or not running; otherwise `{ variant, isNew }`, `isNew`
62
+ * true only on the first persisting call.
63
+ */
64
+ assign(ctx, key, subjectRef, scope) {
65
+ return ctx.runMutation(this.component.mutations.assign, {
66
+ scope: this.scopeOf(scope),
67
+ key,
68
+ subjectRef,
69
+ });
70
+ }
71
+ /**
72
+ * Record an exposure (enrolling the subject if needed) and return their variant,
73
+ * or `null` if not enrolled. Repeated exposures for one subject are deduped into
74
+ * a single tallied row.
75
+ */
76
+ logExposure(ctx, key, subjectRef, scope) {
77
+ return ctx.runMutation(this.component.mutations.logExposure, {
78
+ scope: this.scopeOf(scope),
79
+ key,
80
+ subjectRef,
81
+ });
82
+ }
83
+ /** The experiment definition, or `null` if none exists. */
84
+ getExperiment(ctx, key, scope) {
85
+ return ctx.runQuery(this.component.queries.getExperiment, {
86
+ scope: this.scopeOf(scope),
87
+ key,
88
+ });
89
+ }
90
+ /** A subject's sticky assignment, or `null` if not enrolled. */
91
+ getAssignment(ctx, key, subjectRef, scope) {
92
+ return ctx.runQuery(this.component.queries.getAssignment, {
93
+ scope: this.scopeOf(scope),
94
+ key,
95
+ subjectRef,
96
+ });
97
+ }
98
+ /**
99
+ * Read-only deterministic variant for a subject — the sticky variant **without
100
+ * persisting**. Returns the stored assignment if present, else the deterministic
101
+ * pick; `null` when not enrolled. Use for SSR / a flicker-free first paint, then
102
+ * call `logExposure` to enroll + tally.
103
+ */
104
+ peek(ctx, key, subjectRef, scope) {
105
+ return ctx.runQuery(this.component.queries.peek, {
106
+ scope: this.scopeOf(scope),
107
+ key,
108
+ subjectRef,
109
+ });
110
+ }
111
+ /** Every experiment in a scope, optionally filtered by `status`. */
112
+ listExperiments(ctx, opts = {}) {
113
+ return ctx.runQuery(this.component.queries.listExperiments, {
114
+ scope: this.scopeOf(opts.scope),
115
+ status: opts.status,
116
+ });
117
+ }
118
+ /**
119
+ * Per-variant tallies — `assigned`, distinct `subjects` exposed, total
120
+ * `exposures`, and the configured `weight` (for sample-ratio-mismatch). Reads
121
+ * O(variants), not the exposure table.
122
+ */
123
+ results(ctx, key, scope) {
124
+ return ctx.runQuery(this.component.queries.results, {
125
+ scope: this.scopeOf(scope),
126
+ key,
127
+ });
128
+ }
129
+ /**
130
+ * Erase a subject's assignment + exposure in one experiment (GDPR right-to-
131
+ * erasure), decrementing tallies. Returns `true` if anything was deleted. Loop
132
+ * over `listExperiments` to erase a subject across a whole scope.
133
+ */
134
+ forgetSubject(ctx, key, subjectRef, scope) {
135
+ return ctx.runMutation(this.component.mutations.forgetSubject, {
136
+ scope: this.scopeOf(scope),
137
+ key,
138
+ subjectRef,
139
+ });
140
+ }
141
+ /**
142
+ * Delete an experiment and all of its data (definition, assignments, exposures,
143
+ * tallies). Bounded + self-rescheduling; returns the rows removed this pass.
144
+ * Idempotent and safe on an absent experiment.
145
+ */
146
+ deleteExperiment(ctx, key, opts = {}) {
147
+ return ctx.runMutation(this.component.mutations.deleteExperiment, {
148
+ scope: this.scopeOf(opts.scope),
149
+ key,
150
+ batch: opts.batch ?? DEFAULT_DELETE_BATCH,
151
+ });
152
+ }
153
+ }
154
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAE,oBAAoB,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAoGnF;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,OAAO,WAAW;IAKH,SAAS;IAJX,YAAY,CAAS;IACrB,aAAa,CAAmB;IAEjD,YACmB,SAA+B,EAChD,OAAO,GAAuB,EAAE;yBADf,SAAS;QAG1B,IAAI,CAAC,YAAY,GAAG,OAAO,CAAC,YAAY,IAAI,aAAa,CAAC;QAC1D,IAAI,CAAC,aAAa,GAAG,OAAO,CAAC,aAAa,IAAK,cAA4B,CAAC;IAC9E,CAAC;IAEO,OAAO,CAAC,KAAyB;QACvC,OAAO,KAAK,IAAI,IAAI,CAAC,YAAY,CAAC;IACpC,CAAC;IAED;;;;;;OAMG;IACH,MAAM,CACJ,GAAmB,EACnB,GAAW,EACX,IAA6C;QAE7C,OAAO,GAAG,CAAC,WAAW,CAAC,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,MAAM,EAAE;YACtD,KAAK,EAAE,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC;YAC/B,GAAG;YACH,QAAQ,EAAE,IAAI,CAAC,QAAQ;YACvB,IAAI,EAAE,IAAI,CAAC,IAAI,IAAI,GAAG;YACtB,MAAM,EAAE,IAAI,CAAC,MAAM,IAAI,IAAI,CAAC,aAAa;SAC1C,CAAC,CAAC;IACL,CAAC;IAED,qFAAqF;IACrF,SAAS,CACP,GAAmB,EACnB,GAAW,EACX,MAAwB,EACxB,KAAc;QAEd,OAAO,GAAG,CAAC,WAAW,CAAC,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,SAAS,EAAE;YACzD,KAAK,EAAE,IAAI,CAAC,OAAO,CAAC,KAAK,C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,CAAC;CACF"}
@@ -0,0 +1,75 @@
1
+ /** Public TypeScript surface for the experiments client. */
2
+ /** A weighted variant — an opaque variant key and its relative selection weight. */
3
+ export interface Variant {
4
+ /** The host's opaque variant key (e.g. `"control"`, `"treatment"`). */
5
+ key: string;
6
+ /** Relative selection weight; the bucket width is `weight / sum(weights)`. */
7
+ weight: number;
8
+ }
9
+ /** Experiment lifecycle status. `running` is the only status that enrolls subjects. */
10
+ export type ExperimentStatus = "draft" | "running" | "stopped";
11
+ /** Construction options for the {@link Experiments} client. */
12
+ export interface ExperimentsOptions {
13
+ /** Namespace applied when a call omits `scope`. Default `"global"`. */
14
+ defaultScope?: string;
15
+ /** Status applied by `define` when a call omits `status`. Default `"running"`. */
16
+ defaultStatus?: ExperimentStatus;
17
+ }
18
+ /** Per-call overrides for {@link Experiments.define}. */
19
+ export interface DefineOptions {
20
+ /** Namespace for this experiment. Defaults to the client `defaultScope`. */
21
+ scope?: string;
22
+ /**
23
+ * Hash salt for deterministic assignment. Defaults to the experiment `key`.
24
+ * Fixed once any subject is assigned (changing it after enrollment throws
25
+ * `EXPERIMENT_LOCKED`); to re-randomize, define a new experiment key.
26
+ */
27
+ salt?: string;
28
+ /** Initial lifecycle status. Defaults to the client `defaultStatus`. */
29
+ status?: ExperimentStatus;
30
+ }
31
+ /** An experiment definition, as returned by {@link Experiments.getExperiment}. */
32
+ export interface ExperimentDefinition {
33
+ key: string;
34
+ scope: string;
35
+ status: ExperimentStatus;
36
+ variants: Variant[];
37
+ salt: string;
38
+ /** Absolute ms timestamp the experiment was first defined. */
39
+ createdAt: number;
40
+ }
41
+ /** A subject's sticky assignment, as returned by {@link Experiments.getAssignment}. */
42
+ export interface Assignment {
43
+ variant: string;
44
+ /** Absolute ms timestamp the assignment was first persisted. */
45
+ assignedAt: number;
46
+ }
47
+ /**
48
+ * Outcome of {@link Experiments.assign}. `{ variant: null }` — not enrolled
49
+ * (experiment absent or not running). `{ variant, isNew }` — the enrolled variant,
50
+ * with `isNew` true only on the call that first persisted the assignment.
51
+ */
52
+ export type AssignOutcome = {
53
+ variant: null;
54
+ } | {
55
+ variant: string;
56
+ isNew: boolean;
57
+ };
58
+ /** Outcome of {@link Experiments.logExposure}: the variant, or `null` if not enrolled. */
59
+ export type ExposureOutcome = {
60
+ variant: string | null;
61
+ };
62
+ /** A per-variant tally, as returned by {@link Experiments.results}. */
63
+ export interface VariantResult {
64
+ /** The variant key. */
65
+ variant: string;
66
+ /** Subjects assigned to this variant (the realized split, for SRM). */
67
+ assigned: number;
68
+ /** Distinct subjects exposed to this variant (the funnel denominator). */
69
+ subjects: number;
70
+ /** Total exposure events recorded for this variant. */
71
+ exposures: number;
72
+ /** The configured weight from the current definition (0 if the variant is gone). */
73
+ weight: number;
74
+ }
75
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/client/types.ts"],"names":[],"mappings":"AAAA,4DAA4D;AAE5D,oFAAoF;AACpF,MAAM,WAAW,OAAO;IACtB,uEAAuE;IACvE,GAAG,EAAE,MAAM,CAAC;IACZ,8EAA8E;IAC9E,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,uFAAuF;AACvF,MAAM,MAAM,gBAAgB,GAAG,OAAO,GAAG,SAAS,GAAG,SAAS,CAAC;AAE/D,+DAA+D;AAC/D,MAAM,WAAW,kBAAkB;IACjC,uEAAuE;IACvE,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,kFAAkF;IAClF,aAAa,CAAC,EAAE,gBAAgB,CAAC;CAClC;AAED,yDAAyD;AACzD,MAAM,WAAW,aAAa;IAC5B,4EAA4E;IAC5E,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;;;OAIG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,wEAAwE;IACxE,MAAM,CAAC,EAAE,gBAAgB,CAAC;CAC3B;AAED,kFAAkF;AAClF,MAAM,WAAW,oBAAoB;IACnC,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,gBAAgB,CAAC;IACzB,QAAQ,EAAE,OAAO,EAAE,CAAC;IACpB,IAAI,EAAE,MAAM,CAAC;IACb,8DAA8D;IAC9D,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,uFAAuF;AACvF,MAAM,WAAW,UAAU;IACzB,OAAO,EAAE,MAAM,CAAC;IAChB,gEAAgE;IAChE,UAAU,EAAE,MAAM,CAAC;CACpB;AAED;;;;GAIG;AACH,MAAM,MAAM,aAAa,GACrB;IAAE,OAAO,EAAE,IAAI,CAAA;CAAE,GACjB;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,OAAO,CAAA;CAAE,CAAC;AAExC,0FAA0F;AAC1F,MAAM,MAAM,eAAe,GAAG;IAAE,OAAO,EAAE,MAAM,GAAG,IAAI,CAAA;CAAE,CAAC;AAEzD,uEAAuE;AACvE,MAAM,WAAW,aAAa;IAC5B,uBAAuB;IACvB,OAAO,EAAE,MAAM,CAAC;IAChB,uEAAuE;IACvE,QAAQ,EAAE,MAAM,CAAC;IACjB,0EAA0E;IAC1E,QAAQ,EAAE,MAAM,CAAC;IACjB,uDAAuD;IACvD,SAAS,EAAE,MAAM,CAAC;IAClB,oFAAoF;IACpF,MAAM,EAAE,MAAM,CAAC;CAChB"}
@@ -0,0 +1,3 @@
1
+ /** Public TypeScript surface for the experiments client. */
2
+ export {};
3
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/client/types.ts"],"names":[],"mappings":"AAAA,4DAA4D"}
@@ -0,0 +1,38 @@
1
+ /**
2
+ * Generated `api` utility.
3
+ *
4
+ * THIS CODE IS AUTOMATICALLY GENERATED.
5
+ *
6
+ * To regenerate, run `npx convex dev`.
7
+ * @module
8
+ */
9
+ import type * as mutations from "../mutations.js";
10
+ import type * as queries from "../queries.js";
11
+ import type * as validators from "../validators.js";
12
+ import type { ApiFromModules, FilterApi, FunctionReference } from "convex/server";
13
+ declare const fullApi: ApiFromModules<{
14
+ mutations: typeof mutations;
15
+ queries: typeof queries;
16
+ validators: typeof validators;
17
+ }>;
18
+ /**
19
+ * A utility for referencing Convex functions in your app's public API.
20
+ *
21
+ * Usage:
22
+ * ```js
23
+ * const myFunctionReference = api.myModule.myFunction;
24
+ * ```
25
+ */
26
+ export declare const api: FilterApi<typeof fullApi, FunctionReference<any, "public">>;
27
+ /**
28
+ * A utility for referencing Convex functions in your app's internal API.
29
+ *
30
+ * Usage:
31
+ * ```js
32
+ * const myFunctionReference = internal.myModule.myFunction;
33
+ * ```
34
+ */
35
+ export declare const internal: FilterApi<typeof fullApi, FunctionReference<any, "internal">>;
36
+ export declare const components: {};
37
+ export {};
38
+ //# sourceMappingURL=api.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../../../src/component/_generated/api.ts"],"names":[],"mappings":"AACA;;;;;;;GAOG;AAEH,OAAO,KAAK,KAAK,SAAS,MAAM,iBAAiB,CAAC;AAClD,OAAO,KAAK,KAAK,OAAO,MAAM,eAAe,CAAC;AAC9C,OAAO,KAAK,KAAK,UAAU,MAAM,kBAAkB,CAAC;AAEpD,OAAO,KAAK,EACV,cAAc,EACd,SAAS,EACT,iBAAiB,EAClB,MAAM,eAAe,CAAC;AAGvB,QAAA,MAAM,OAAO,EAAE,cAAc,CAAC;IAC5B,SAAS,EAAE,OAAO,SAAS,CAAC;IAC5B,OAAO,EAAE,OAAO,OAAO,CAAC;IACxB,UAAU,EAAE,OAAO,UAAU,CAAC;CAC/B,CAAiB,CAAC;AAEnB;;;;;;;GAOG;AACH,eAAO,MAAM,GAAG,EAAE,SAAS,CACzB,OAAO,OAAO,EACd,iBAAiB,CAAC,GAAG,EAAE,QAAQ,CAAC,CACjB,CAAC;AAElB;;;;;;;GAOG;AACH,eAAO,MAAM,QAAQ,EAAE,SAAS,CAC9B,OAAO,OAAO,EACd,iBAAiB,CAAC,GAAG,EAAE,UAAU,CAAC,CACnB,CAAC;AAElB,eAAO,MAAM,UAAU,EAAqC,EAAE,CAAC"}