@vllnt/convex-flags 0.1.0 → 0.1.1-canary.824d5e2
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.
- package/CHANGELOG.md +98 -0
- package/README.md +181 -67
- package/dist/component/mutations.d.ts.map +1 -1
- package/dist/component/mutations.js +77 -23
- package/dist/component/mutations.js.map +1 -1
- package/docs/API.md +245 -0
- package/llms.txt +39 -0
- package/package.json +47 -25
- package/src/component/mutations.ts +107 -28
- package/src/react/index.test.ts +0 -52
- package/src/status-backward-compat.test.ts +0 -51
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mutations.js","sourceRoot":"","sources":["../../src/component/mutations.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,eAAe,CAAC;AAClC,OAAO,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAGlD,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAEvE,KAAK,UAAU,SAAS,CAAC,GAAgB,EAAE,GAAW;IACpD,OAAO,MAAM,GAAG,CAAC,EAAE;SAChB,KAAK,CAAC,OAAO,CAAC;SACd,SAAS,CAAC,QAAQ,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;SAC5C,MAAM,EAAE,CAAC;AACd,CAAC;AAED;kDACkD;AAClD,SAAS,YAAY;IACnB,MAAM,IAAI,KAAK,CAAC,gBAAgB,CAAC,CAAC;AACpC,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,MAAM,MAAM,GAAG,QAAQ,CAAC;IAC7B,IAAI,EAAE;QACJ,GAAG,EAAE,CAAC,CAAC,MAAM,EAAE;QACf,KAAK,EAAE,YAAY;QACnB,WAAW,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC;QACnC,QA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AE;aAC1B,KAAK,CAAC,WAAW,CAAC;aAClB,SAAS,CAAC,gBAAgB,EAAE,CAAC,CAAC,EAAE,EAAE,CACjC,CAAC,CAAC,EAAE,CAAC,KAAK,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,YAAY,EAAE,IAAI,CAAC,UAAU,CAAC,CACxD;aACA,MAAM,EAAE,CAAC;QACZ,IAAI,QAAQ,KAAK,IAAI,EAAE,CAAC;YACtB,MAAM,GAAG,CAAC,EAAE,CAAC,MAAM,CAAC,WAAW,EAAE,QAAQ,CAAC,GAAG,CAAC,CAAC;QACjD,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;CACF,CAAC,CAAC"}
|
package/docs/API.md
ADDED
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
# API Reference — @vllnt/convex-flags
|
|
2
|
+
|
|
3
|
+
**Compatibility:** `convex@^1.45.0`. `react@^18 || ^19` is an optional peer,
|
|
4
|
+
needed only for the `./react` entry.
|
|
5
|
+
|
|
6
|
+
This file ships inside the package and describes the installed version.
|
|
7
|
+
|
|
8
|
+
The main surface is the `Flags` client class (`src/client/index.ts`).
|
|
9
|
+
Construct it once with the mounted component reference, then call its methods
|
|
10
|
+
from host queries/mutations/actions. The host owns auth — gate the management
|
|
11
|
+
methods (`define`, `update`, `enable`, `disable`, `archive`, `restore`,
|
|
12
|
+
`remove`, `setOverride`, `clearOverride`) behind your own authorized mutations.
|
|
13
|
+
|
|
14
|
+
```ts
|
|
15
|
+
import { Flags } from "@vllnt/convex-flags";
|
|
16
|
+
import { components } from "./_generated/api";
|
|
17
|
+
|
|
18
|
+
const flags = new Flags(components.flags);
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
A flag value is a typed primitive: `boolean | string | number` (the
|
|
22
|
+
`VariantValue` type). A boolean flag is the two-variant case; string/number
|
|
23
|
+
flags are multivariate.
|
|
24
|
+
|
|
25
|
+
## Entry points
|
|
26
|
+
|
|
27
|
+
| Import path | Exports |
|
|
28
|
+
| ------------------------------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
29
|
+
| `@vllnt/convex-flags` | The `Flags` class, and the types `FlagsComponent`, `EvalContext`, `EvalOptions`, `FlagDefinition`, `FlagDoc`, `FlagEvaluation`, `FlagUpdate`, `Rollout`, `Rule`, `Variant`, `VariantValue` |
|
|
30
|
+
| `@vllnt/convex-flags/convex.config` | The component definition, passed to `app.use(flags)` (also importable as `./convex.config.js`) |
|
|
31
|
+
| `@vllnt/convex-flags/react` | `useFlag`, `useFlags`, and the types `UseFlagOptions`, `EvaluateRef`, `AllRef`, `EvalContext`, `FlagEvaluation`, `VariantValue` (optional; needs `react`) |
|
|
32
|
+
| `@vllnt/convex-flags/test` | `register(t, name = "flags")` — mounts the component in a `convex-test` instance (TypeScript source) |
|
|
33
|
+
| `@vllnt/convex-flags/_generated/component` | The `ComponentApi` type only (also importable as `./_generated/component.js`) |
|
|
34
|
+
|
|
35
|
+
## Mutations
|
|
36
|
+
|
|
37
|
+
| Method | Args | Returns | Notes |
|
|
38
|
+
| ------------------------------------------ | ------------------------------ | ----------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
39
|
+
| `define(ctx, definition)` | `FlagDefinition` | `Promise<string>` | Create a flag, or **fully replace** its definition (value, description, variants, rules, rollout) if the key exists — fields omitted from the definition are cleared. Status is preserved on replace; an unchanged definition writes nothing (`updatedAt` kept). Returns the flag id. |
|
|
40
|
+
| `update(ctx, key, patch)` | `string, FlagUpdate` | `Promise<null>` | **Partially** update a flag: patch only the supplied fields (the opposite of `define`); omitted fields are left untouched. Throws `FLAG_NOT_FOUND`. |
|
|
41
|
+
| `enable(ctx, key)` | `string` | `Promise<null>` | Boolean convenience — set the flag's value to `true`. For multivariate flags use `define`/`update`. Throws `FLAG_NOT_FOUND`. |
|
|
42
|
+
| `disable(ctx, key)` | `string` | `Promise<null>` | Boolean convenience — set the flag's value to `false`. For multivariate flags use `define`/`update`. Throws `FLAG_NOT_FOUND`. |
|
|
43
|
+
| `archive(ctx, key)` | `string` | `Promise<null>` | Reversibly retire a flag. Evaluation skips targeting and serves the base value with reason `disabled`. Throws `FLAG_NOT_FOUND`. |
|
|
44
|
+
| `restore(ctx, key)` | `string` | `Promise<null>` | Return an archived flag to active. Throws `FLAG_NOT_FOUND`. |
|
|
45
|
+
| `remove(ctx, key)` | `string` | `Promise<null>` | Permanently delete a flag and its overrides. Throws `FLAG_NOT_FOUND`. |
|
|
46
|
+
| `setOverride(ctx, key, subjectRef, value)` | `string, string, VariantValue` | `Promise<null>` | Force a flag's value for one subject. Throws `FLAG_NOT_FOUND`. |
|
|
47
|
+
| `clearOverride(ctx, key, subjectRef)` | `string, string` | `Promise<null>` | Remove a subject's override. No-op if none exists. |
|
|
48
|
+
|
|
49
|
+
## Queries
|
|
50
|
+
|
|
51
|
+
| Method | Args | Returns | Notes |
|
|
52
|
+
| ------------------------------- | ---------------------- | ----------------------------------------- | ---------------------------------------------------------------------------------------------- |
|
|
53
|
+
| `get(ctx, key)` | `string` | `Promise<FlagDoc \| null>` | Fetch a single flag definition, or `null`. |
|
|
54
|
+
| `list(ctx)` | — | `Promise<FlagDoc[]>` | Every flag definition. |
|
|
55
|
+
| `evaluate(ctx, key, options?)` | `string, EvalOptions?` | `Promise<FlagEvaluation>` | Resolve a flag against optional context. |
|
|
56
|
+
| `variant(ctx, key, options?)` | `string, EvalOptions?` | `Promise<VariantValue>` | Like `evaluate`, returning just the value. |
|
|
57
|
+
| `isEnabled(ctx, key, context?)` | `string, EvalContext?` | `Promise<boolean>` | `true` when the evaluated value is exactly `true`; `false` otherwise (including unknown keys). |
|
|
58
|
+
| `all(ctx, context?)` | `EvalContext?` | `Promise<Record<string, FlagEvaluation>>` | Evaluate every flag against the same context — the bootstrap payload for a reactive client. |
|
|
59
|
+
|
|
60
|
+
## Evaluation order
|
|
61
|
+
|
|
62
|
+
`evaluate` resolves a flag in this order; the first that applies wins:
|
|
63
|
+
|
|
64
|
+
1. **Override** — a per-subject override for `context.subjectRef` (reason
|
|
65
|
+
`override`).
|
|
66
|
+
2. **Archived** — an archived flag serves its base value (reason `disabled`);
|
|
67
|
+
targeting is skipped. A flag with no `status` (a row written before `status`
|
|
68
|
+
existed) is treated as active, not archived.
|
|
69
|
+
3. **Rules** — targeting rules in order; the first whose conditions all match
|
|
70
|
+
serves its `value` (reason `rule`) or its `rollout` (reason `rollout`).
|
|
71
|
+
4. **Fallthrough rollout** — when no rule matched (reason `rollout`).
|
|
72
|
+
5. **Flag value** — the base value (reason `flag`).
|
|
73
|
+
|
|
74
|
+
An **unknown key** returns the caller `default` (reason `default`) or `false`
|
|
75
|
+
(reason `unknown`). A rollout that cannot bucket (no `subjectRef`/`by`
|
|
76
|
+
attribute, or no positive-weight split) yields no value, so the flag value
|
|
77
|
+
(reason `flag`) is served. When that happens inside a matched rule, evaluation
|
|
78
|
+
stops there: later rules and the flag-level rollout are not tried.
|
|
79
|
+
|
|
80
|
+
## Targeting operators
|
|
81
|
+
|
|
82
|
+
A condition is `{ attribute, op, values }`. A missing attribute never matches,
|
|
83
|
+
including `neq` and `nin`. Equality is strict (no string/number coercion);
|
|
84
|
+
`contains` is case-sensitive. There are no regex or prefix/suffix operators.
|
|
85
|
+
|
|
86
|
+
| Op | Holds when |
|
|
87
|
+
| --------------------------- | --------------------------------------------------------- |
|
|
88
|
+
| `eq` / `neq` | attribute equals / does not equal `values[0]` |
|
|
89
|
+
| `in` / `nin` | attribute is / is not in `values` |
|
|
90
|
+
| `contains` | string attribute contains the string `values[0]` |
|
|
91
|
+
| `gt` / `gte` / `lt` / `lte` | numeric attribute compares against the number `values[0]` |
|
|
92
|
+
|
|
93
|
+
## Rollouts
|
|
94
|
+
|
|
95
|
+
A rollout distributes across weighted splits, bucketed deterministically by a
|
|
96
|
+
stable subject so a given subject always resolves to the same value:
|
|
97
|
+
|
|
98
|
+
```ts
|
|
99
|
+
{ splits: [{ value: "A", weight: 50 }, { value: "B", weight: 50 }], by: "userId" }
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
`by` names the context attribute to bucket by; when omitted,
|
|
103
|
+
`context.subjectRef` is used. Weights are relative: a subject's bucket is its integer
|
|
104
|
+
hash modulo the sum of the positive weights, so use whole-number weights
|
|
105
|
+
(for example percentages). Fractional weights do not split evenly; `0.5` / `0.5`
|
|
106
|
+
sends every subject to the first split.
|
|
107
|
+
|
|
108
|
+
## Types
|
|
109
|
+
|
|
110
|
+
Import these by name from `@vllnt/convex-flags` (see Entry points).
|
|
111
|
+
`AttributeValue`, `EvalReason`, `Condition` and `Split` are shown for reference
|
|
112
|
+
and are not exported by name: derive them with `FlagEvaluation["reason"]`,
|
|
113
|
+
`Rule["conditions"][number]` and `Rollout["splits"][number]`; `AttributeValue`
|
|
114
|
+
is the same union as `VariantValue`. `FlagsComponent` is the constructor
|
|
115
|
+
argument type; `components.flags` satisfies it.
|
|
116
|
+
|
|
117
|
+
```ts
|
|
118
|
+
type VariantValue = boolean | string | number;
|
|
119
|
+
type AttributeValue = boolean | string | number;
|
|
120
|
+
type EvalReason =
|
|
121
|
+
"flag" | "rule" | "rollout" | "override" | "disabled" | "default" | "unknown";
|
|
122
|
+
|
|
123
|
+
interface EvalContext {
|
|
124
|
+
subjectRef?: string;
|
|
125
|
+
attributes?: Record<string, AttributeValue>;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
interface EvalOptions {
|
|
129
|
+
context?: EvalContext;
|
|
130
|
+
default?: VariantValue;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
interface Condition {
|
|
134
|
+
attribute: string;
|
|
135
|
+
op: "eq" | "neq" | "in" | "nin" | "contains" | "gt" | "gte" | "lt" | "lte";
|
|
136
|
+
values: AttributeValue[];
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
interface Split {
|
|
140
|
+
value: VariantValue;
|
|
141
|
+
weight: number;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
interface Rollout {
|
|
145
|
+
splits: Split[];
|
|
146
|
+
by?: string;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
interface Rule {
|
|
150
|
+
conditions: Condition[]; // AND; an empty list is a catch-all
|
|
151
|
+
value?: VariantValue; // wins over `rollout` when both are set
|
|
152
|
+
rollout?: Rollout;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
interface Variant {
|
|
156
|
+
value: VariantValue;
|
|
157
|
+
label?: string;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
interface FlagDefinition {
|
|
161
|
+
key: string;
|
|
162
|
+
value: VariantValue;
|
|
163
|
+
description?: string;
|
|
164
|
+
variants?: Variant[];
|
|
165
|
+
rules?: Rule[];
|
|
166
|
+
rollout?: Rollout;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
interface FlagUpdate {
|
|
170
|
+
// Partial patch for `update` — only supplied fields change; key passed separately.
|
|
171
|
+
value?: VariantValue;
|
|
172
|
+
description?: string;
|
|
173
|
+
variants?: Variant[];
|
|
174
|
+
rules?: Rule[];
|
|
175
|
+
rollout?: Rollout;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
interface FlagDoc {
|
|
179
|
+
_id: string;
|
|
180
|
+
_creationTime: number;
|
|
181
|
+
key: string;
|
|
182
|
+
description?: string;
|
|
183
|
+
value: VariantValue;
|
|
184
|
+
variants?: Variant[];
|
|
185
|
+
rules?: Rule[];
|
|
186
|
+
rollout?: Rollout;
|
|
187
|
+
status: "active" | "archived";
|
|
188
|
+
createdAt: number;
|
|
189
|
+
updatedAt: number;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
interface FlagEvaluation {
|
|
193
|
+
value: VariantValue;
|
|
194
|
+
reason: EvalReason;
|
|
195
|
+
}
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
`EvalOptions` accepts only `context` and `default`; `isEnabled` and `all` take
|
|
199
|
+
the context directly, not an options wrapper. There is no constructor
|
|
200
|
+
configuration or list filter.
|
|
201
|
+
|
|
202
|
+
## Error codes
|
|
203
|
+
|
|
204
|
+
Missing-flag mutations throw a JavaScript `Error("FLAG_NOT_FOUND")`, not a
|
|
205
|
+
structured `ConvexError` payload. Invalid arguments throw a `ConvexError` whose
|
|
206
|
+
`data.code` is `INVALID_ARGUMENT`. Do not depend on client-visible error text in
|
|
207
|
+
production.
|
|
208
|
+
|
|
209
|
+
| Code | Thrown by | Condition |
|
|
210
|
+
| ------------------ | -------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------- |
|
|
211
|
+
| `FLAG_NOT_FOUND` | `update`, `enable`, `disable`, `archive`, `restore`, `remove`, `setOverride` | The flag key does not exist |
|
|
212
|
+
| `INVALID_ARGUMENT` | every mutation (`key`); `setOverride`, `clearOverride` (`subjectRef`); `define`, `update` | `key` or `subjectRef` is empty, or a rollout weight (flag-level or in a rule) is `NaN`, infinite or negative |
|
|
213
|
+
|
|
214
|
+
## React
|
|
215
|
+
|
|
216
|
+
The optional `@vllnt/convex-flags/react` entry ships reactive hooks over
|
|
217
|
+
`convex/react`'s `useQuery`. They take the host's own re-exported `evaluate` /
|
|
218
|
+
`all` query refs. `react` is an optional peer dependency; a backend-only
|
|
219
|
+
consumer never imports this entry.
|
|
220
|
+
|
|
221
|
+
```tsx
|
|
222
|
+
import { useFlag, useFlags } from "@vllnt/convex-flags/react";
|
|
223
|
+
import { api } from "../convex/_generated/api";
|
|
224
|
+
|
|
225
|
+
const checkout = useFlag(api.flags.evaluate, "new-checkout", {
|
|
226
|
+
context: { subjectRef: userId },
|
|
227
|
+
});
|
|
228
|
+
// checkout is `undefined` while loading, then { value, reason }.
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
| Hook | Args | Returns |
|
|
232
|
+
| ------------------------------- | ----------------------------------------- | --------------------------------------------- |
|
|
233
|
+
| `useFlag(query, key, options?)` | evaluate ref, `string`, `UseFlagOptions?` | `FlagEvaluation \| undefined` |
|
|
234
|
+
| `useFlags(query, context?)` | all ref, `EvalContext?` | `Record<string, FlagEvaluation> \| undefined` |
|
|
235
|
+
|
|
236
|
+
```ts
|
|
237
|
+
interface UseFlagOptions {
|
|
238
|
+
context?: EvalContext;
|
|
239
|
+
default?: VariantValue; // served (reason `default`) when the key is unknown
|
|
240
|
+
}
|
|
241
|
+
```
|
|
242
|
+
|
|
243
|
+
`EvaluateRef` and `AllRef` are the types of the host's public `evaluate` and
|
|
244
|
+
`all` query references — queries that take the same args and return the same
|
|
245
|
+
shapes as the component's `evaluate` and `all`.
|
package/llms.txt
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# @vllnt/convex-flags
|
|
2
|
+
|
|
3
|
+
> Feature flags as a Convex component — variants, targeting, percentage rollouts, and per-subject overrides, evaluated on the backend and streamed live to clients.
|
|
4
|
+
|
|
5
|
+
`@vllnt/convex-flags` is a publishable Convex component targeting `convex@^1.45.0`.
|
|
6
|
+
It stores feature flags in its own sandboxed tables, keyed by an opaque host-chosen
|
|
7
|
+
string. A flag value is a typed primitive (`boolean | string | number`) and supports
|
|
8
|
+
attribute-targeting rules, weighted percentage rollouts with stable per-subject
|
|
9
|
+
bucketing, per-subject overrides, and reversible archiving. Flags are evaluated inside
|
|
10
|
+
Convex queries, so changes stream to connected clients over the same reactive
|
|
11
|
+
subscription mechanism as app data. The host owns auth and gates every management call.
|
|
12
|
+
An optional `./react` entry ships `useFlag`/`useFlags` hooks; `react` is an optional peer.
|
|
13
|
+
|
|
14
|
+
## For coding agents
|
|
15
|
+
|
|
16
|
+
The docs are bundled in the package at `node_modules/@vllnt/convex-flags/docs/` (this file,
|
|
17
|
+
`README.md` and `CHANGELOG.md` sit at the package root) and match the installed version. Read
|
|
18
|
+
them before writing code against this package.
|
|
19
|
+
|
|
20
|
+
## Docs
|
|
21
|
+
|
|
22
|
+
- [README](./README.md): Project overview, installation, usage examples, architecture
|
|
23
|
+
- [API Reference](./docs/API.md): Public class methods, return shapes, input validation
|
|
24
|
+
- [Changelog](./CHANGELOG.md): Version history and release notes
|
|
25
|
+
- [License](./LICENSE): MIT license
|
|
26
|
+
|
|
27
|
+
## Ecosystem
|
|
28
|
+
|
|
29
|
+
- [vllnt oss](https://oss.vllnt.com/llms.txt): Index of the other vllnt open-source packages
|
|
30
|
+
|
|
31
|
+
## Optional
|
|
32
|
+
|
|
33
|
+
These files are on GitHub and are not bundled in the package.
|
|
34
|
+
|
|
35
|
+
- [Example component wrapper](https://github.com/vllnt/convex-flags/blob/main/example/convex/example.ts): Host-app wrapper functions
|
|
36
|
+
- [Example tests](https://github.com/vllnt/convex-flags/blob/main/example/convex/example.test.ts): End-to-end usage coverage with `convex-test`
|
|
37
|
+
- [Contributing](https://github.com/vllnt/convex-flags/blob/main/CONTRIBUTING.md): Development setup, validation commands, release workflow
|
|
38
|
+
- [Security Policy](https://github.com/vllnt/convex-flags/blob/main/SECURITY.md): Vulnerability reporting policy
|
|
39
|
+
- [Code of Conduct](https://github.com/vllnt/convex-flags/blob/main/CODE_OF_CONDUCT.md): Community participation guidelines
|
package/package.json
CHANGED
|
@@ -1,13 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vllnt/convex-flags",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1-canary.824d5e2",
|
|
4
4
|
"description": "Feature flags as a Convex component — variants, targeting, percentage rollouts, and per-subject overrides, evaluated on the backend and streamed live to clients.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
7
|
-
"packageManager": "pnpm@
|
|
7
|
+
"packageManager": "pnpm@10.34.8",
|
|
8
8
|
"files": [
|
|
9
9
|
"dist",
|
|
10
|
-
"src"
|
|
10
|
+
"src",
|
|
11
|
+
"docs/API.md",
|
|
12
|
+
"CHANGELOG.md",
|
|
13
|
+
"llms.txt",
|
|
14
|
+
"!src/**/*.test.*",
|
|
15
|
+
"!src/**/*.spec.*"
|
|
11
16
|
],
|
|
12
17
|
"exports": {
|
|
13
18
|
"./package.json": "./package.json",
|
|
@@ -41,17 +46,14 @@
|
|
|
41
46
|
"build": "tsc --project ./tsconfig.build.json",
|
|
42
47
|
"build:codegen": "pnpm codegen && pnpm build",
|
|
43
48
|
"build:clean": "rm -rf dist *.tsbuildinfo && pnpm build:codegen",
|
|
44
|
-
"typecheck": "tsc --noEmit",
|
|
45
|
-
"typecheck:ci": "tsc --noEmit --project tsconfig.ci.json",
|
|
46
|
-
"lint": "pnpm check:agents && eslint .",
|
|
49
|
+
"typecheck": "tsc --noEmit --incremental --tsBuildInfoFile node_modules/.cache/tsc/typecheck.tsbuildinfo",
|
|
50
|
+
"typecheck:ci": "tsc --noEmit --incremental --tsBuildInfoFile node_modules/.cache/tsc/typecheck-ci.tsbuildinfo --project tsconfig.ci.json",
|
|
51
|
+
"lint": "pnpm check:agents && eslint --cache --cache-location node_modules/.cache/eslint/ .",
|
|
47
52
|
"test": "vitest run --passWithNoTests",
|
|
48
53
|
"test:watch": "vitest --typecheck --clearScreen false",
|
|
49
54
|
"test:coverage": "vitest run --coverage --coverage.reporter=text",
|
|
50
|
-
"
|
|
51
|
-
"
|
|
52
|
-
"prepublishOnly": "npm whoami || npm login",
|
|
53
|
-
"alpha": "npm version prerelease --preid alpha && npm publish --tag alpha && git push --follow-tags",
|
|
54
|
-
"release": "npm version patch && npm publish && git push --follow-tags",
|
|
55
|
+
"preversion": "pnpm install --frozen-lockfile && pnpm build && pnpm test:coverage && pnpm typecheck",
|
|
56
|
+
"test:package": "node scripts/test-package.mjs",
|
|
55
57
|
"check:agents": "node -e \"const f=require('node:fs');if(!f.existsSync('AGENTS.md')||f.existsSync('CLAUDE.md')||f.existsSync('.claude'))process.exit(1)\"",
|
|
56
58
|
"codegen": "pnpm convex codegen --component-dir ./src/component"
|
|
57
59
|
},
|
|
@@ -67,24 +69,39 @@
|
|
|
67
69
|
"devDependencies": {
|
|
68
70
|
"@edge-runtime/vm": "^5.0.0",
|
|
69
71
|
"@testing-library/react": "^16.3.3",
|
|
70
|
-
"@types/react": "^19.
|
|
71
|
-
"@types/react-dom": "^19.
|
|
72
|
+
"@types/react": "^19.3.0",
|
|
73
|
+
"@types/react-dom": "^19.3.0",
|
|
72
74
|
"@typescript/native": "npm:typescript@7.0.2",
|
|
73
|
-
"@vitest/coverage-v8": "^
|
|
74
|
-
"@vllnt/eslint-config": "2.
|
|
75
|
+
"@vitest/coverage-v8": "^5.1.0",
|
|
76
|
+
"@vllnt/eslint-config": "2.1.0",
|
|
75
77
|
"@vllnt/typescript": "2.0.0",
|
|
76
|
-
"convex": "^1.
|
|
77
|
-
"convex-test": "^0.0.
|
|
78
|
+
"convex": "^1.50.0",
|
|
79
|
+
"convex-test": "^0.0.71",
|
|
78
80
|
"eslint": "^9.39.5",
|
|
79
|
-
"jsdom": "^
|
|
80
|
-
"prettier": "^3.
|
|
81
|
-
"react": "^19.
|
|
82
|
-
"react-dom": "^19.
|
|
81
|
+
"jsdom": "^30.1.3",
|
|
82
|
+
"prettier": "^3.10.1",
|
|
83
|
+
"react": "^19.3.1",
|
|
84
|
+
"react-dom": "^19.3.1",
|
|
83
85
|
"typescript": "npm:@typescript/typescript6@^6.0.2",
|
|
84
|
-
"vite": "^8.
|
|
85
|
-
"vitest": "^
|
|
86
|
+
"vite": "^8.3.8",
|
|
87
|
+
"vitest": "^5.1.0"
|
|
88
|
+
},
|
|
89
|
+
"pnpm": {
|
|
90
|
+
"minimumReleaseAge": 10080,
|
|
91
|
+
"minimumReleaseAgeExclude": [
|
|
92
|
+
"@vllnt/*"
|
|
93
|
+
],
|
|
94
|
+
"ignoredBuiltDependencies": [
|
|
95
|
+
"esbuild"
|
|
96
|
+
],
|
|
97
|
+
"overrides": {
|
|
98
|
+
"minimatch@>=7.0.0 <11.0.1": "11.0.5",
|
|
99
|
+
"deepmerge-ts@<8.0.0": "8.0.0",
|
|
100
|
+
"esbuild@>=0.27.3 <0.28.1": "0.28.1",
|
|
101
|
+
"handlebars@<4.7.10": "4.7.10"
|
|
102
|
+
}
|
|
86
103
|
},
|
|
87
|
-
"homepage": "https://
|
|
104
|
+
"homepage": "https://oss.vllnt.com/packages/convex-flags",
|
|
88
105
|
"bugs": {
|
|
89
106
|
"url": "https://github.com/vllnt/convex-flags/issues"
|
|
90
107
|
},
|
|
@@ -110,6 +127,11 @@
|
|
|
110
127
|
"keywords": [
|
|
111
128
|
"convex",
|
|
112
129
|
"convex-component",
|
|
113
|
-
"flags"
|
|
130
|
+
"flags",
|
|
131
|
+
"feature-flags",
|
|
132
|
+
"feature-toggles",
|
|
133
|
+
"rollout",
|
|
134
|
+
"targeting",
|
|
135
|
+
"kill-switch"
|
|
114
136
|
]
|
|
115
137
|
}
|
|
@@ -1,9 +1,12 @@
|
|
|
1
|
-
import { v } from "convex/values";
|
|
1
|
+
import { ConvexError, v, type Infer } from "convex/values";
|
|
2
2
|
import { mutation } from "./_generated/server.js";
|
|
3
3
|
import type { Doc } from "./_generated/dataModel.js";
|
|
4
4
|
import type { MutationCtx } from "./_generated/server.js";
|
|
5
5
|
import { rollout, rule, variant, variantValue } from "./validators.js";
|
|
6
6
|
|
|
7
|
+
type Rollout = Infer<typeof rollout>;
|
|
8
|
+
type Rule = Infer<typeof rule>;
|
|
9
|
+
|
|
7
10
|
async function findByKey(ctx: MutationCtx, key: string): Promise<Doc<"flags"> | null> {
|
|
8
11
|
return await ctx.db
|
|
9
12
|
.query("flags")
|
|
@@ -11,6 +14,76 @@ async function findByKey(ctx: MutationCtx, key: string): Promise<Doc<"flags"> |
|
|
|
11
14
|
.unique();
|
|
12
15
|
}
|
|
13
16
|
|
|
17
|
+
function invalidArgument(message: string): never {
|
|
18
|
+
throw new ConvexError({ code: "INVALID_ARGUMENT", message });
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** Reject empty identifiers: an empty key or subject ref can never be targeted
|
|
22
|
+
* meaningfully and would store an unreachable row. */
|
|
23
|
+
function assertNonEmpty(fields: Record<string, string>): void {
|
|
24
|
+
for (const [name, value] of Object.entries(fields)) {
|
|
25
|
+
if (value === "") {
|
|
26
|
+
invalidArgument(`${name} must be non-empty`);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** Reject rollout weights that cannot bucket: NaN, infinite, or negative. Zero
|
|
32
|
+
* is allowed (it excludes a split). */
|
|
33
|
+
function assertRollouts(
|
|
34
|
+
rollouts: Array<Rollout | undefined>,
|
|
35
|
+
rules: Rule[] | undefined,
|
|
36
|
+
): void {
|
|
37
|
+
const all = [...rollouts, ...(rules ?? []).map((r) => r.rollout)];
|
|
38
|
+
for (const r of all) {
|
|
39
|
+
for (const { weight } of r?.splits ?? []) {
|
|
40
|
+
if (!Number.isFinite(weight) || weight < 0) {
|
|
41
|
+
invalidArgument("rollout weights must be finite and non-negative");
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function sameValue(a: unknown, b: unknown): boolean {
|
|
48
|
+
if (Array.isArray(a) && Array.isArray(b)) {
|
|
49
|
+
return a.length === b.length && a.every((item, i) => sameValue(item, b[i]));
|
|
50
|
+
}
|
|
51
|
+
if (isRecord(a) && isRecord(b)) {
|
|
52
|
+
const keys = new Set([...Object.keys(a), ...Object.keys(b)]);
|
|
53
|
+
return [...keys].every((k) => sameValue(a[k], b[k]));
|
|
54
|
+
}
|
|
55
|
+
return Object.is(a, b);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
59
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const FLAG_FIELDS = ["value", "description", "variants", "rules", "rollout"] as const;
|
|
63
|
+
|
|
64
|
+
function changedFields(
|
|
65
|
+
flag: Doc<"flags">,
|
|
66
|
+
fields: Partial<Pick<Doc<"flags">, "value" | "description" | "variants" | "rules" | "rollout">>,
|
|
67
|
+
): Partial<Doc<"flags">> {
|
|
68
|
+
const patch: Partial<Doc<"flags">> = {};
|
|
69
|
+
for (const name of FLAG_FIELDS) {
|
|
70
|
+
if (name in fields && !sameValue(flag[name], fields[name])) {
|
|
71
|
+
Object.assign(patch, { [name]: fields[name] });
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
return patch;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
async function patchIfChanged(
|
|
78
|
+
ctx: MutationCtx,
|
|
79
|
+
flag: Doc<"flags">,
|
|
80
|
+
patch: Partial<Doc<"flags">>,
|
|
81
|
+
): Promise<void> {
|
|
82
|
+
if (Object.keys(patch).length > 0) {
|
|
83
|
+
await ctx.db.patch("flags", flag._id, { ...patch, updatedAt: Date.now() });
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
14
87
|
/** Throws the component's single code-tagged error. Returns `never` so callers
|
|
15
88
|
* narrow the flag to non-null after the guard. */
|
|
16
89
|
function flagNotFound(): never {
|
|
@@ -32,17 +105,22 @@ export const define = mutation({
|
|
|
32
105
|
},
|
|
33
106
|
returns: v.id("flags"),
|
|
34
107
|
handler: async (ctx, args) => {
|
|
108
|
+
assertNonEmpty({ key: args.key });
|
|
109
|
+
assertRollouts([args.rollout], args.rules);
|
|
35
110
|
const now = Date.now();
|
|
36
111
|
const existing = await findByKey(ctx, args.key);
|
|
37
112
|
if (existing !== null) {
|
|
38
|
-
await
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
113
|
+
await patchIfChanged(
|
|
114
|
+
ctx,
|
|
115
|
+
existing,
|
|
116
|
+
changedFields(existing, {
|
|
117
|
+
value: args.value,
|
|
118
|
+
description: args.description,
|
|
119
|
+
variants: args.variants,
|
|
120
|
+
rules: args.rules,
|
|
121
|
+
rollout: args.rollout,
|
|
122
|
+
}),
|
|
123
|
+
);
|
|
46
124
|
return existing._id;
|
|
47
125
|
}
|
|
48
126
|
return await ctx.db.insert("flags", {
|
|
@@ -75,37 +153,30 @@ export const update = mutation({
|
|
|
75
153
|
},
|
|
76
154
|
returns: v.null(),
|
|
77
155
|
handler: async (ctx, args) => {
|
|
156
|
+
assertNonEmpty({ key: args.key });
|
|
157
|
+
assertRollouts([args.rollout], args.rules);
|
|
78
158
|
const flag = await findByKey(ctx, args.key);
|
|
79
159
|
if (flag === null) {
|
|
80
160
|
flagNotFound();
|
|
81
161
|
}
|
|
82
|
-
const
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
patch.description = args.description;
|
|
162
|
+
const fields: Parameters<typeof changedFields>[1] = {};
|
|
163
|
+
for (const name of FLAG_FIELDS) {
|
|
164
|
+
if (args[name] !== undefined) {
|
|
165
|
+
Object.assign(fields, { [name]: args[name] });
|
|
166
|
+
}
|
|
88
167
|
}
|
|
89
|
-
|
|
90
|
-
patch.variants = args.variants;
|
|
91
|
-
}
|
|
92
|
-
if (args.rules !== undefined) {
|
|
93
|
-
patch.rules = args.rules;
|
|
94
|
-
}
|
|
95
|
-
if (args.rollout !== undefined) {
|
|
96
|
-
patch.rollout = args.rollout;
|
|
97
|
-
}
|
|
98
|
-
await ctx.db.patch("flags", flag._id, patch);
|
|
168
|
+
await patchIfChanged(ctx, flag, changedFields(flag, fields));
|
|
99
169
|
return null;
|
|
100
170
|
},
|
|
101
171
|
});
|
|
102
172
|
|
|
103
173
|
async function setValue(ctx: MutationCtx, key: string, value: boolean): Promise<void> {
|
|
174
|
+
assertNonEmpty({ key });
|
|
104
175
|
const flag = await findByKey(ctx, key);
|
|
105
176
|
if (flag === null) {
|
|
106
177
|
flagNotFound();
|
|
107
178
|
}
|
|
108
|
-
await ctx
|
|
179
|
+
await patchIfChanged(ctx, flag, changedFields(flag, { value }));
|
|
109
180
|
}
|
|
110
181
|
|
|
111
182
|
/** Turn a boolean flag on (set its value to `true`). */
|
|
@@ -133,11 +204,14 @@ async function setStatus(
|
|
|
133
204
|
key: string,
|
|
134
205
|
status: "active" | "archived",
|
|
135
206
|
): Promise<void> {
|
|
207
|
+
assertNonEmpty({ key });
|
|
136
208
|
const flag = await findByKey(ctx, key);
|
|
137
209
|
if (flag === null) {
|
|
138
210
|
flagNotFound();
|
|
139
211
|
}
|
|
140
|
-
|
|
212
|
+
if (flag.status !== status) {
|
|
213
|
+
await ctx.db.patch("flags", flag._id, { status, updatedAt: Date.now() });
|
|
214
|
+
}
|
|
141
215
|
}
|
|
142
216
|
|
|
143
217
|
/** Archive a flag: reversible retirement. Evaluation skips targeting and serves
|
|
@@ -166,6 +240,7 @@ export const remove = mutation({
|
|
|
166
240
|
args: { key: v.string() },
|
|
167
241
|
returns: v.null(),
|
|
168
242
|
handler: async (ctx, args) => {
|
|
243
|
+
assertNonEmpty({ key: args.key });
|
|
169
244
|
const flag = await findByKey(ctx, args.key);
|
|
170
245
|
if (flag === null) {
|
|
171
246
|
flagNotFound();
|
|
@@ -187,6 +262,7 @@ export const setOverride = mutation({
|
|
|
187
262
|
args: { key: v.string(), subjectRef: v.string(), value: variantValue },
|
|
188
263
|
returns: v.null(),
|
|
189
264
|
handler: async (ctx, args) => {
|
|
265
|
+
assertNonEmpty({ key: args.key, subjectRef: args.subjectRef });
|
|
190
266
|
const flag = await findByKey(ctx, args.key);
|
|
191
267
|
if (flag === null) {
|
|
192
268
|
flagNotFound();
|
|
@@ -198,7 +274,9 @@ export const setOverride = mutation({
|
|
|
198
274
|
)
|
|
199
275
|
.unique();
|
|
200
276
|
if (existing !== null) {
|
|
201
|
-
|
|
277
|
+
if (!Object.is(existing.value, args.value)) {
|
|
278
|
+
await ctx.db.patch("overrides", existing._id, { value: args.value });
|
|
279
|
+
}
|
|
202
280
|
} else {
|
|
203
281
|
await ctx.db.insert("overrides", {
|
|
204
282
|
key: args.key,
|
|
@@ -216,6 +294,7 @@ export const clearOverride = mutation({
|
|
|
216
294
|
args: { key: v.string(), subjectRef: v.string() },
|
|
217
295
|
returns: v.null(),
|
|
218
296
|
handler: async (ctx, args) => {
|
|
297
|
+
assertNonEmpty({ key: args.key, subjectRef: args.subjectRef });
|
|
219
298
|
const existing = await ctx.db
|
|
220
299
|
.query("overrides")
|
|
221
300
|
.withIndex("by_key_subject", (q) =>
|