@contractspec/lib.feature-flags 3.7.6 → 3.7.10
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/README.md +62 -162
- package/dist/browser/contracts/index.js +1 -1
- package/dist/browser/events.js +1 -1
- package/dist/browser/index.js +2 -2
- package/dist/contracts/index.js +1 -1
- package/dist/events.js +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/node/contracts/index.js +1 -1
- package/dist/node/events.js +1 -1
- package/dist/node/index.js +2 -2
- package/package.json +7 -7
package/README.md
CHANGED
|
@@ -1,173 +1,73 @@
|
|
|
1
1
|
# @contractspec/lib.feature-flags
|
|
2
2
|
|
|
3
|
-
Website: https://contractspec.io
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
Feature flags and experiments module for ContractSpec applications.
|
|
7
|
-
|
|
8
|
-
## Overview
|
|
9
|
-
|
|
10
|
-
This module provides a reusable feature flag and experimentation system that can be used across all ContractSpec applications. It supports:
|
|
11
|
-
|
|
12
|
-
- **Feature Flags**: Toggle features on/off with targeting rules
|
|
13
|
-
- **Gradual Rollouts**: Roll out features to a percentage of users
|
|
14
|
-
- **Targeting Rules**: Target by org, user, plan, segment, or custom attributes
|
|
15
|
-
- **Experiments**: A/B testing with variants and metrics tracking
|
|
16
|
-
- **Evaluation Logging**: Track flag evaluations for analytics
|
|
17
|
-
|
|
18
|
-
## Entities
|
|
19
|
-
|
|
20
|
-
### FeatureFlag
|
|
21
|
-
|
|
22
|
-
Core feature flag definition.
|
|
23
|
-
|
|
24
|
-
| Field | Type | Description |
|
|
25
|
-
|-------|------|-------------|
|
|
26
|
-
| id | string | Unique identifier |
|
|
27
|
-
| key | string | Flag key (e.g., `new_dashboard`) |
|
|
28
|
-
| name | string | Human-readable name |
|
|
29
|
-
| description | string | Description of the flag |
|
|
30
|
-
| status | enum | `off`, `on`, `gradual` |
|
|
31
|
-
| defaultValue | boolean/string | Default value when no rules match |
|
|
32
|
-
| variants | json | Variant definitions for multivariate flags |
|
|
33
|
-
| orgId | string | Organization scope (optional) |
|
|
34
|
-
| createdAt | datetime | Creation timestamp |
|
|
35
|
-
| updatedAt | datetime | Last update timestamp |
|
|
36
|
-
|
|
37
|
-
### FlagTargetingRule
|
|
38
|
-
|
|
39
|
-
Targeting rules for conditional flag evaluation.
|
|
40
|
-
|
|
41
|
-
| Field | Type | Description |
|
|
42
|
-
|-------|------|-------------|
|
|
43
|
-
| id | string | Unique identifier |
|
|
44
|
-
| flagId | string | Parent flag |
|
|
45
|
-
| priority | int | Rule priority (lower = higher priority) |
|
|
46
|
-
| attribute | string | Target attribute (org, user, plan, etc.) |
|
|
47
|
-
| operator | enum | `eq`, `neq`, `in`, `nin`, `contains`, `percentage` |
|
|
48
|
-
| value | json | Target value(s) |
|
|
49
|
-
| rolloutPercentage | int | Percentage for gradual rollout |
|
|
50
|
-
| variant | string | Variant to serve (for multivariate) |
|
|
51
|
-
|
|
52
|
-
### Experiment
|
|
53
|
-
|
|
54
|
-
A/B test configuration.
|
|
55
|
-
|
|
56
|
-
| Field | Type | Description |
|
|
57
|
-
|-------|------|-------------|
|
|
58
|
-
| id | string | Unique identifier |
|
|
59
|
-
| key | string | Experiment key |
|
|
60
|
-
| name | string | Human-readable name |
|
|
61
|
-
| flagId | string | Associated feature flag |
|
|
62
|
-
| status | enum | `draft`, `running`, `paused`, `completed` |
|
|
63
|
-
| variants | json | Variant definitions with split ratios |
|
|
64
|
-
| metrics | json | Metrics to track |
|
|
65
|
-
| startedAt | datetime | Experiment start time |
|
|
66
|
-
| endedAt | datetime | Experiment end time |
|
|
67
|
-
|
|
68
|
-
### FlagEvaluation
|
|
69
|
-
|
|
70
|
-
Evaluation log for debugging and analytics.
|
|
71
|
-
|
|
72
|
-
| Field | Type | Description |
|
|
73
|
-
|-------|------|-------------|
|
|
74
|
-
| id | string | Unique identifier |
|
|
75
|
-
| flagKey | string | Evaluated flag key |
|
|
76
|
-
| subjectType | string | Subject type (user, org) |
|
|
77
|
-
| subjectId | string | Subject identifier |
|
|
78
|
-
| result | json | Evaluation result |
|
|
79
|
-
| matchedRuleId | string | Rule that matched (if any) |
|
|
80
|
-
| evaluatedAt | datetime | Evaluation timestamp |
|
|
81
|
-
|
|
82
|
-
## Contracts
|
|
83
|
-
|
|
84
|
-
### Commands
|
|
85
|
-
|
|
86
|
-
- `flag.create` - Create a new feature flag
|
|
87
|
-
- `flag.update` - Update flag configuration
|
|
88
|
-
- `flag.delete` - Delete a feature flag
|
|
89
|
-
- `flag.toggle` - Toggle flag status
|
|
90
|
-
- `rule.create` - Add targeting rule
|
|
91
|
-
- `rule.delete` - Remove targeting rule
|
|
92
|
-
- `experiment.create` - Create an experiment
|
|
93
|
-
- `experiment.start` - Start an experiment
|
|
94
|
-
- `experiment.stop` - Stop an experiment
|
|
95
|
-
|
|
96
|
-
### Queries
|
|
97
|
-
|
|
98
|
-
- `flag.get` - Get flag by key
|
|
99
|
-
- `flag.list` - List all flags
|
|
100
|
-
- `flag.evaluate` - Evaluate flag for a subject
|
|
101
|
-
- `experiment.get` - Get experiment details
|
|
102
|
-
- `experiment.results` - Get experiment results
|
|
103
|
-
|
|
104
|
-
## Events
|
|
105
|
-
|
|
106
|
-
- `flag.created` - Flag was created
|
|
107
|
-
- `flag.updated` - Flag configuration changed
|
|
108
|
-
- `flag.deleted` - Flag was deleted
|
|
109
|
-
- `flag.toggled` - Flag status changed
|
|
110
|
-
- `experiment.started` - Experiment started
|
|
111
|
-
- `experiment.stopped` - Experiment stopped
|
|
112
|
-
- `flag.evaluated` - Flag was evaluated (for analytics)
|
|
113
|
-
|
|
114
|
-
## Usage
|
|
115
|
-
|
|
116
|
-
```typescript
|
|
117
|
-
import {
|
|
118
|
-
FeatureFlagEntity,
|
|
119
|
-
EvaluateFlagContract,
|
|
120
|
-
FlagEvaluator
|
|
121
|
-
} from '@contractspec/lib.feature-flags';
|
|
122
|
-
|
|
123
|
-
// Create an evaluator
|
|
124
|
-
const evaluator = new FlagEvaluator(flagRepository);
|
|
125
|
-
|
|
126
|
-
// Evaluate a flag
|
|
127
|
-
const result = await evaluator.evaluate('new_dashboard', {
|
|
128
|
-
userId: 'user-123',
|
|
129
|
-
orgId: 'org-456',
|
|
130
|
-
plan: 'pro',
|
|
131
|
-
});
|
|
132
|
-
|
|
133
|
-
if (result.enabled) {
|
|
134
|
-
// Show new dashboard
|
|
135
|
-
}
|
|
136
|
-
```
|
|
137
|
-
|
|
138
|
-
## Integration
|
|
139
|
-
|
|
140
|
-
This module integrates with:
|
|
141
|
-
|
|
142
|
-
- `@contractspec/lib.identity-rbac` - User/org context for targeting
|
|
143
|
-
- `@contractspec/lib.analytics` - Evaluation tracking
|
|
144
|
-
- `@contractspec/module.audit-trail` - Configuration changes
|
|
145
|
-
|
|
146
|
-
## Schema Contribution
|
|
147
|
-
|
|
148
|
-
```typescript
|
|
149
|
-
import { featureFlagsSchemaContribution } from '@contractspec/lib.feature-flags';
|
|
150
|
-
|
|
151
|
-
export const schemaComposition = {
|
|
152
|
-
modules: [
|
|
153
|
-
featureFlagsSchemaContribution,
|
|
154
|
-
// ... other modules
|
|
155
|
-
],
|
|
156
|
-
};
|
|
157
|
-
```
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
3
|
+
Website: https://contractspec.io
|
|
165
4
|
|
|
5
|
+
**Feature flags and experiments module for ContractSpec applications.**
|
|
166
6
|
|
|
7
|
+
## What It Provides
|
|
167
8
|
|
|
9
|
+
- **Layer**: lib.
|
|
10
|
+
- **Consumers**: bundles, apps.
|
|
11
|
+
- `src/contracts/` contains contract specs, operations, entities, and registry exports.
|
|
12
|
+
- `src/docs/` contains docblocks and documentation-facing exports.
|
|
13
|
+
- `src/contracts/` contains contract specs, operations, entities, and registry exports.
|
|
14
|
+
- `src/docs/` contains docblocks and documentation-facing exports.
|
|
168
15
|
|
|
16
|
+
## Installation
|
|
169
17
|
|
|
18
|
+
`npm install @contractspec/lib.feature-flags`
|
|
170
19
|
|
|
20
|
+
or
|
|
171
21
|
|
|
22
|
+
`bun add @contractspec/lib.feature-flags`
|
|
172
23
|
|
|
24
|
+
## Usage
|
|
173
25
|
|
|
26
|
+
Import the root entrypoint from `@contractspec/lib.feature-flags`, or choose a documented subpath when you only need one part of the package surface.
|
|
27
|
+
|
|
28
|
+
## Architecture
|
|
29
|
+
|
|
30
|
+
- `src/contracts/` contains contract specs, operations, entities, and registry exports.
|
|
31
|
+
- `src/docs/` contains docblocks and documentation-facing exports.
|
|
32
|
+
- `src/entities/` contains domain entities and value objects.
|
|
33
|
+
- `src/evaluation` is part of the package's public or composition surface.
|
|
34
|
+
- `src/events.ts` is package-level event definitions.
|
|
35
|
+
- `src/feature-flags.capability.ts` defines a capability surface.
|
|
36
|
+
- `src/feature-flags.feature.ts` defines a feature entrypoint.
|
|
37
|
+
|
|
38
|
+
## Public Entry Points
|
|
39
|
+
|
|
40
|
+
- Export `.` resolves through `./src/index.ts`.
|
|
41
|
+
- Export `./contracts` resolves through `./src/contracts/index.ts`.
|
|
42
|
+
- Export `./docs` resolves through `./src/docs/index.ts`.
|
|
43
|
+
- Export `./docs/feature-flags.docblock` resolves through `./src/docs/feature-flags.docblock.ts`.
|
|
44
|
+
- Export `./entities` resolves through `./src/entities/index.ts`.
|
|
45
|
+
- Export `./evaluation` resolves through `./src/evaluation/index.ts`.
|
|
46
|
+
- Export `./events` resolves through `./src/events.ts`.
|
|
47
|
+
- Export `./feature-flags.capability` resolves through `./src/feature-flags.capability.ts`.
|
|
48
|
+
- Export `./feature-flags.feature` resolves through `./src/feature-flags.feature.ts`.
|
|
49
|
+
|
|
50
|
+
## Local Commands
|
|
51
|
+
|
|
52
|
+
- `bun run dev` — contractspec-bun-build dev
|
|
53
|
+
- `bun run build` — bun run prebuild && bun run build:bundle && bun run build:types
|
|
54
|
+
- `bun run lint` — bun lint:fix
|
|
55
|
+
- `bun run lint:check` — biome check .
|
|
56
|
+
- `bun run lint:fix` — biome check --write --unsafe --only=nursery/useSortedClasses . && biome check --write .
|
|
57
|
+
- `bun run typecheck` — tsc --noEmit
|
|
58
|
+
- `bun run publish:pkg` — bun publish --tolerate-republish --ignore-scripts --verbose
|
|
59
|
+
- `bun run publish:pkg:canary` — bun publish:pkg --tag canary
|
|
60
|
+
- `bun run clean` — rimraf dist .turbo
|
|
61
|
+
- `bun run build:bundle` — contractspec-bun-build transpile
|
|
62
|
+
- `bun run build:types` — contractspec-bun-build types
|
|
63
|
+
- `bun run prebuild` — contractspec-bun-build prebuild
|
|
64
|
+
|
|
65
|
+
## Recent Updates
|
|
66
|
+
|
|
67
|
+
- Replace eslint+prettier by biomejs to optimize speed.
|
|
68
|
+
|
|
69
|
+
## Notes
|
|
70
|
+
|
|
71
|
+
- Flag evaluation logic must be deterministic — same input always produces same output.
|
|
72
|
+
- Capability and feature contracts are public API; changes are breaking.
|
|
73
|
+
- Follow the PostHog naming conventions defined in workspace rules for new flag names.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// src/contracts/index.ts
|
|
2
|
-
import { ScalarTypeEnum, defineSchemaModel } from "@contractspec/lib.schema";
|
|
3
2
|
import { defineCommand, defineQuery } from "@contractspec/lib.contracts-spec";
|
|
3
|
+
import { defineSchemaModel, ScalarTypeEnum } from "@contractspec/lib.schema";
|
|
4
4
|
var OWNERS = ["platform.feature-flags"];
|
|
5
5
|
var FeatureFlagModel = defineSchemaModel({
|
|
6
6
|
name: "FeatureFlag",
|
package/dist/browser/events.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// src/events.ts
|
|
2
|
-
import { ScalarTypeEnum, defineSchemaModel } from "@contractspec/lib.schema";
|
|
3
2
|
import { defineEvent } from "@contractspec/lib.contracts-spec";
|
|
3
|
+
import { defineSchemaModel, ScalarTypeEnum } from "@contractspec/lib.schema";
|
|
4
4
|
var FlagCreatedPayload = defineSchemaModel({
|
|
5
5
|
name: "FlagCreatedEventPayload",
|
|
6
6
|
description: "Payload when a feature flag is created",
|
package/dist/browser/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// src/contracts/index.ts
|
|
2
|
-
import { ScalarTypeEnum, defineSchemaModel } from "@contractspec/lib.schema";
|
|
3
2
|
import { defineCommand, defineQuery } from "@contractspec/lib.contracts-spec";
|
|
3
|
+
import { defineSchemaModel, ScalarTypeEnum } from "@contractspec/lib.schema";
|
|
4
4
|
var OWNERS = ["platform.feature-flags"];
|
|
5
5
|
var FeatureFlagModel = defineSchemaModel({
|
|
6
6
|
name: "FeatureFlag",
|
|
@@ -1200,8 +1200,8 @@ class InMemoryFlagRepository {
|
|
|
1200
1200
|
}
|
|
1201
1201
|
|
|
1202
1202
|
// src/events.ts
|
|
1203
|
-
import { ScalarTypeEnum as ScalarTypeEnum2, defineSchemaModel as defineSchemaModel2 } from "@contractspec/lib.schema";
|
|
1204
1203
|
import { defineEvent } from "@contractspec/lib.contracts-spec";
|
|
1204
|
+
import { defineSchemaModel as defineSchemaModel2, ScalarTypeEnum as ScalarTypeEnum2 } from "@contractspec/lib.schema";
|
|
1205
1205
|
var FlagCreatedPayload = defineSchemaModel2({
|
|
1206
1206
|
name: "FlagCreatedEventPayload",
|
|
1207
1207
|
description: "Payload when a feature flag is created",
|
package/dist/contracts/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// @bun
|
|
2
2
|
// src/contracts/index.ts
|
|
3
|
-
import { ScalarTypeEnum, defineSchemaModel } from "@contractspec/lib.schema";
|
|
4
3
|
import { defineCommand, defineQuery } from "@contractspec/lib.contracts-spec";
|
|
4
|
+
import { defineSchemaModel, ScalarTypeEnum } from "@contractspec/lib.schema";
|
|
5
5
|
var OWNERS = ["platform.feature-flags"];
|
|
6
6
|
var FeatureFlagModel = defineSchemaModel({
|
|
7
7
|
name: "FeatureFlag",
|
package/dist/events.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// @bun
|
|
2
2
|
// src/events.ts
|
|
3
|
-
import { ScalarTypeEnum, defineSchemaModel } from "@contractspec/lib.schema";
|
|
4
3
|
import { defineEvent } from "@contractspec/lib.contracts-spec";
|
|
4
|
+
import { defineSchemaModel, ScalarTypeEnum } from "@contractspec/lib.schema";
|
|
5
5
|
var FlagCreatedPayload = defineSchemaModel({
|
|
6
6
|
name: "FlagCreatedEventPayload",
|
|
7
7
|
description: "Payload when a feature flag is created",
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// @bun
|
|
2
2
|
// src/contracts/index.ts
|
|
3
|
-
import { ScalarTypeEnum, defineSchemaModel } from "@contractspec/lib.schema";
|
|
4
3
|
import { defineCommand, defineQuery } from "@contractspec/lib.contracts-spec";
|
|
4
|
+
import { defineSchemaModel, ScalarTypeEnum } from "@contractspec/lib.schema";
|
|
5
5
|
var OWNERS = ["platform.feature-flags"];
|
|
6
6
|
var FeatureFlagModel = defineSchemaModel({
|
|
7
7
|
name: "FeatureFlag",
|
|
@@ -1201,8 +1201,8 @@ class InMemoryFlagRepository {
|
|
|
1201
1201
|
}
|
|
1202
1202
|
|
|
1203
1203
|
// src/events.ts
|
|
1204
|
-
import { ScalarTypeEnum as ScalarTypeEnum2, defineSchemaModel as defineSchemaModel2 } from "@contractspec/lib.schema";
|
|
1205
1204
|
import { defineEvent } from "@contractspec/lib.contracts-spec";
|
|
1205
|
+
import { defineSchemaModel as defineSchemaModel2, ScalarTypeEnum as ScalarTypeEnum2 } from "@contractspec/lib.schema";
|
|
1206
1206
|
var FlagCreatedPayload = defineSchemaModel2({
|
|
1207
1207
|
name: "FlagCreatedEventPayload",
|
|
1208
1208
|
description: "Payload when a feature flag is created",
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// src/contracts/index.ts
|
|
2
|
-
import { ScalarTypeEnum, defineSchemaModel } from "@contractspec/lib.schema";
|
|
3
2
|
import { defineCommand, defineQuery } from "@contractspec/lib.contracts-spec";
|
|
3
|
+
import { defineSchemaModel, ScalarTypeEnum } from "@contractspec/lib.schema";
|
|
4
4
|
var OWNERS = ["platform.feature-flags"];
|
|
5
5
|
var FeatureFlagModel = defineSchemaModel({
|
|
6
6
|
name: "FeatureFlag",
|
package/dist/node/events.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// src/events.ts
|
|
2
|
-
import { ScalarTypeEnum, defineSchemaModel } from "@contractspec/lib.schema";
|
|
3
2
|
import { defineEvent } from "@contractspec/lib.contracts-spec";
|
|
3
|
+
import { defineSchemaModel, ScalarTypeEnum } from "@contractspec/lib.schema";
|
|
4
4
|
var FlagCreatedPayload = defineSchemaModel({
|
|
5
5
|
name: "FlagCreatedEventPayload",
|
|
6
6
|
description: "Payload when a feature flag is created",
|
package/dist/node/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// src/contracts/index.ts
|
|
2
|
-
import { ScalarTypeEnum, defineSchemaModel } from "@contractspec/lib.schema";
|
|
3
2
|
import { defineCommand, defineQuery } from "@contractspec/lib.contracts-spec";
|
|
3
|
+
import { defineSchemaModel, ScalarTypeEnum } from "@contractspec/lib.schema";
|
|
4
4
|
var OWNERS = ["platform.feature-flags"];
|
|
5
5
|
var FeatureFlagModel = defineSchemaModel({
|
|
6
6
|
name: "FeatureFlag",
|
|
@@ -1200,8 +1200,8 @@ class InMemoryFlagRepository {
|
|
|
1200
1200
|
}
|
|
1201
1201
|
|
|
1202
1202
|
// src/events.ts
|
|
1203
|
-
import { ScalarTypeEnum as ScalarTypeEnum2, defineSchemaModel as defineSchemaModel2 } from "@contractspec/lib.schema";
|
|
1204
1203
|
import { defineEvent } from "@contractspec/lib.contracts-spec";
|
|
1204
|
+
import { defineSchemaModel as defineSchemaModel2, ScalarTypeEnum as ScalarTypeEnum2 } from "@contractspec/lib.schema";
|
|
1205
1205
|
var FlagCreatedPayload = defineSchemaModel2({
|
|
1206
1206
|
name: "FlagCreatedEventPayload",
|
|
1207
1207
|
description: "Payload when a feature flag is created",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contractspec/lib.feature-flags",
|
|
3
|
-
"version": "3.7.
|
|
3
|
+
"version": "3.7.10",
|
|
4
4
|
"description": "Feature flags and experiments module for ContractSpec applications",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"contractspec",
|
|
@@ -20,20 +20,20 @@
|
|
|
20
20
|
"dev": "contractspec-bun-build dev",
|
|
21
21
|
"clean": "rimraf dist .turbo",
|
|
22
22
|
"lint": "bun lint:fix",
|
|
23
|
-
"lint:fix": "
|
|
24
|
-
"lint:check": "
|
|
23
|
+
"lint:fix": "biome check --write --unsafe --only=nursery/useSortedClasses . && biome check --write .",
|
|
24
|
+
"lint:check": "biome check .",
|
|
25
25
|
"prebuild": "contractspec-bun-build prebuild",
|
|
26
26
|
"typecheck": "tsc --noEmit"
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@contractspec/lib.schema": "3.7.
|
|
30
|
-
"@contractspec/lib.contracts-spec": "
|
|
29
|
+
"@contractspec/lib.schema": "3.7.8",
|
|
30
|
+
"@contractspec/lib.contracts-spec": "4.1.2",
|
|
31
31
|
"zod": "^4.3.5"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
|
-
"@contractspec/tool.typescript": "3.7.
|
|
34
|
+
"@contractspec/tool.typescript": "3.7.8",
|
|
35
35
|
"typescript": "^5.9.3",
|
|
36
|
-
"@contractspec/tool.bun": "3.7.
|
|
36
|
+
"@contractspec/tool.bun": "3.7.8"
|
|
37
37
|
},
|
|
38
38
|
"exports": {
|
|
39
39
|
".": {
|