@dads-framework/feature-flags 0.0.0-stage → 0.2.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.
- package/LICENSE.md +21 -0
- package/README.md +155 -2
- package/dist/contract/feature-flag-definition.schema.d.ts +29 -0
- package/dist/contract/feature-flag-definition.schema.d.ts.map +1 -0
- package/dist/contract/feature-flag-definition.schema.js +66 -0
- package/dist/contract/feature-flag-definition.schema.js.map +1 -0
- package/dist/contract/feature-flag-management.schema.d.ts +179 -0
- package/dist/contract/feature-flag-management.schema.d.ts.map +1 -0
- package/dist/contract/feature-flag-management.schema.js +121 -0
- package/dist/contract/feature-flag-management.schema.js.map +1 -0
- package/dist/contract/feature-state.schema.d.ts +25 -0
- package/dist/contract/feature-state.schema.d.ts.map +1 -0
- package/dist/contract/feature-state.schema.js +34 -0
- package/dist/contract/feature-state.schema.js.map +1 -0
- package/dist/contract/index.d.ts +4 -0
- package/dist/contract/index.d.ts.map +1 -0
- package/dist/contract/index.js +4 -0
- package/dist/contract/index.js.map +1 -0
- package/dist/feature-flags.tsbuildinfo +1 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +15 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/compose-feature-flags.d.ts +40 -0
- package/dist/lib/compose-feature-flags.d.ts.map +1 -0
- package/dist/lib/compose-feature-flags.js +41 -0
- package/dist/lib/compose-feature-flags.js.map +1 -0
- package/dist/lib/feature-flag-evaluator.d.ts +16 -0
- package/dist/lib/feature-flag-evaluator.d.ts.map +1 -0
- package/dist/lib/feature-flag-evaluator.js +16 -0
- package/dist/lib/feature-flag-evaluator.js.map +1 -0
- package/dist/lib/feature-flags-plugin.d.ts +18 -0
- package/dist/lib/feature-flags-plugin.d.ts.map +1 -0
- package/dist/lib/feature-flags-plugin.js +23 -0
- package/dist/lib/feature-flags-plugin.js.map +1 -0
- package/dist/lib/logic/evaluate-feature-flags.d.ts +23 -0
- package/dist/lib/logic/evaluate-feature-flags.d.ts.map +1 -0
- package/dist/lib/logic/evaluate-feature-flags.js +34 -0
- package/dist/lib/logic/evaluate-feature-flags.js.map +1 -0
- package/dist/lib/logic/transition-feature-flag-state.d.ts +18 -0
- package/dist/lib/logic/transition-feature-flag-state.d.ts.map +1 -0
- package/dist/lib/logic/transition-feature-flag-state.js +75 -0
- package/dist/lib/logic/transition-feature-flag-state.js.map +1 -0
- package/dist/lib/mutations/plan-feature-flag-batch.d.ts +22 -0
- package/dist/lib/mutations/plan-feature-flag-batch.d.ts.map +1 -0
- package/dist/lib/mutations/plan-feature-flag-batch.js +58 -0
- package/dist/lib/mutations/plan-feature-flag-batch.js.map +1 -0
- package/dist/lib/mutations/update-feature-flags.d.ts +18 -0
- package/dist/lib/mutations/update-feature-flags.d.ts.map +1 -0
- package/dist/lib/mutations/update-feature-flags.js +45 -0
- package/dist/lib/mutations/update-feature-flags.js.map +1 -0
- package/dist/lib/ports/feature-flag-store.d.ts +28 -0
- package/dist/lib/ports/feature-flag-store.d.ts.map +1 -0
- package/dist/lib/ports/feature-flag-store.js +8 -0
- package/dist/lib/ports/feature-flag-store.js.map +1 -0
- package/dist/lib/ports/tenant-directory.d.ts +15 -0
- package/dist/lib/ports/tenant-directory.d.ts.map +1 -0
- package/dist/lib/ports/tenant-directory.js +8 -0
- package/dist/lib/ports/tenant-directory.js.map +1 -0
- package/dist/lib/queries/get-effective-feature-state.d.ts +16 -0
- package/dist/lib/queries/get-effective-feature-state.d.ts.map +1 -0
- package/dist/lib/queries/get-effective-feature-state.js +36 -0
- package/dist/lib/queries/get-effective-feature-state.js.map +1 -0
- package/dist/lib/queries/get-public-feature-state.d.ts +14 -0
- package/dist/lib/queries/get-public-feature-state.d.ts.map +1 -0
- package/dist/lib/queries/get-public-feature-state.js +24 -0
- package/dist/lib/queries/get-public-feature-state.js.map +1 -0
- package/dist/lib/queries/list-feature-flag-history.d.ts +17 -0
- package/dist/lib/queries/list-feature-flag-history.d.ts.map +1 -0
- package/dist/lib/queries/list-feature-flag-history.js +17 -0
- package/dist/lib/queries/list-feature-flag-history.js.map +1 -0
- package/dist/lib/queries/list-feature-flag-management.d.ts +18 -0
- package/dist/lib/queries/list-feature-flag-management.d.ts.map +1 -0
- package/dist/lib/queries/list-feature-flag-management.js +56 -0
- package/dist/lib/queries/list-feature-flag-management.js.map +1 -0
- package/dist/lib/stores/read-states-once-feature-flag-store.d.ts +24 -0
- package/dist/lib/stores/read-states-once-feature-flag-store.d.ts.map +1 -0
- package/dist/lib/stores/read-states-once-feature-flag-store.js +36 -0
- package/dist/lib/stores/read-states-once-feature-flag-store.js.map +1 -0
- package/dist/testing/fake-tenant-directory.d.ts +13 -0
- package/dist/testing/fake-tenant-directory.d.ts.map +1 -0
- package/dist/testing/fake-tenant-directory.js +23 -0
- package/dist/testing/fake-tenant-directory.js.map +1 -0
- package/dist/testing/feature-flag-definition.factory.d.ts +4 -0
- package/dist/testing/feature-flag-definition.factory.d.ts.map +1 -0
- package/dist/testing/feature-flag-definition.factory.js +16 -0
- package/dist/testing/feature-flag-definition.factory.js.map +1 -0
- package/dist/testing/feature-flag-store-conformance.d.ts +12 -0
- package/dist/testing/feature-flag-store-conformance.d.ts.map +1 -0
- package/dist/testing/feature-flag-store-conformance.js +114 -0
- package/dist/testing/feature-flag-store-conformance.js.map +1 -0
- package/dist/testing/fixed-clock.d.ts +8 -0
- package/dist/testing/fixed-clock.d.ts.map +1 -0
- package/dist/testing/fixed-clock.js +13 -0
- package/dist/testing/fixed-clock.js.map +1 -0
- package/dist/testing/in-memory-feature-flag-store.d.ts +16 -0
- package/dist/testing/in-memory-feature-flag-store.d.ts.map +1 -0
- package/dist/testing/in-memory-feature-flag-store.js +36 -0
- package/dist/testing/in-memory-feature-flag-store.js.map +1 -0
- package/dist/testing/index.d.ts +6 -0
- package/dist/testing/index.d.ts.map +1 -0
- package/dist/testing/index.js +6 -0
- package/dist/testing/index.js.map +1 -0
- package/package.json +49 -4
package/LICENSE.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Bryton Cooper
|
|
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
CHANGED
|
@@ -1,3 +1,156 @@
|
|
|
1
|
-
#
|
|
1
|
+
# `@dads-framework/feature-flags`
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Feature flags defined in code, with a stored audience per flag: off, on for
|
|
4
|
+
the tenants you select, or on for everyone. Every change is revision-checked,
|
|
5
|
+
applied in batches that land together or not at all, and recorded in history.
|
|
6
|
+
The application decides what a tenant is.
|
|
7
|
+
|
|
8
|
+
## What Dad does for you
|
|
9
|
+
|
|
10
|
+
A flag lives in code, so it is reviewed, owned, and deleted like code. Only
|
|
11
|
+
who sees it is stored, and nothing stored can invent a flag the code never
|
|
12
|
+
defined.
|
|
13
|
+
|
|
14
|
+
## Try it
|
|
15
|
+
|
|
16
|
+
Install the flag kit.
|
|
17
|
+
|
|
18
|
+
```sh
|
|
19
|
+
npm install @dads-framework/feature-flags @dads-framework/clock
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
Save as `pilot.mts` and run `node pilot.mts` with Node.js 22.18 or newer.
|
|
23
|
+
The script enables invoice export for one tenant in memory.
|
|
24
|
+
|
|
25
|
+
<!-- dads:check-example -->
|
|
26
|
+
|
|
27
|
+
```ts
|
|
28
|
+
import {
|
|
29
|
+
composeFeatureFlags,
|
|
30
|
+
defineFeatureFlag,
|
|
31
|
+
} from "@dads-framework/feature-flags";
|
|
32
|
+
import {
|
|
33
|
+
InMemoryFeatureFlagStore,
|
|
34
|
+
FakeTenantDirectory,
|
|
35
|
+
} from "@dads-framework/feature-flags/testing";
|
|
36
|
+
import { SystemClock } from "@dads-framework/clock";
|
|
37
|
+
|
|
38
|
+
const bulkExport = defineFeatureFlag({
|
|
39
|
+
slug: "billing.invoices.bulk-export",
|
|
40
|
+
name: "Bulk invoice export",
|
|
41
|
+
description: "Export every invoice in a period as one file.",
|
|
42
|
+
owner: "billing team",
|
|
43
|
+
defaultEnabled: false,
|
|
44
|
+
affectedPages: ["/invoices"],
|
|
45
|
+
affectedApiCapabilities: ["POST /invoices/exports"],
|
|
46
|
+
cleanupTrigger: "Removed after two weeks on for everyone.",
|
|
47
|
+
globalStabilityDays: 14,
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
const flags = composeFeatureFlags({
|
|
51
|
+
definitions: [bulkExport],
|
|
52
|
+
store: new InMemoryFeatureFlagStore(),
|
|
53
|
+
tenants: new FakeTenantDirectory(),
|
|
54
|
+
clock: new SystemClock(),
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
await flags.update.execute({
|
|
58
|
+
actorId: "user-1",
|
|
59
|
+
request: {
|
|
60
|
+
changes: [
|
|
61
|
+
{
|
|
62
|
+
slug: bulkExport.slug,
|
|
63
|
+
expectedRevision: 0,
|
|
64
|
+
mode: "SELECTED_TENANTS",
|
|
65
|
+
tenantIds: ["acme"],
|
|
66
|
+
},
|
|
67
|
+
],
|
|
68
|
+
},
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
console.log(
|
|
72
|
+
await flags.evaluator.isActive({
|
|
73
|
+
slug: bulkExport.slug,
|
|
74
|
+
context: { kind: "tenant", tenantId: "acme" },
|
|
75
|
+
}),
|
|
76
|
+
);
|
|
77
|
+
console.log(
|
|
78
|
+
await flags.evaluator.isActive({
|
|
79
|
+
slug: bulkExport.slug,
|
|
80
|
+
context: { kind: "platform" },
|
|
81
|
+
}),
|
|
82
|
+
);
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
The script prints `true` for Acme and `false` for the platform. The
|
|
86
|
+
selected-tenant rollout leaves the platform audience off.
|
|
87
|
+
|
|
88
|
+
The generated starter defines the note-export flag in
|
|
89
|
+
[`domains/notes/server/flags.ts`](../../../apps/kit-workbench/domains/notes/server/flags.ts) and contributes it from
|
|
90
|
+
[`domains/notes/server/plugin.ts`](../../../apps/kit-workbench/domains/notes/server/plugin.ts). The service in
|
|
91
|
+
[`assembly/services.ts`](../../../apps/kit-workbench/assembly/services.ts) evaluates the API’s declared flags.
|
|
92
|
+
|
|
93
|
+
## Use it
|
|
94
|
+
|
|
95
|
+
- `defineFeatureFlag(definition)` parses a definition where it is declared.
|
|
96
|
+
A definition is off by default and names at least one affected page or API
|
|
97
|
+
capability.
|
|
98
|
+
- `composeFeatureFlags({ definitions, publicSlugs?, store, tenants, clock, readPreview? })`
|
|
99
|
+
returns `management`, `history`, `update`, `effective`, `publicState`,
|
|
100
|
+
`evaluator`, and `evaluatorReadingStatesOncePerRequest`.
|
|
101
|
+
- `readPreview(context)` optionally supplies an authorized request override
|
|
102
|
+
for one defined flag. Effective state and both evaluators include the override.
|
|
103
|
+
The public list, management views, rollout state, and history use stored audiences.
|
|
104
|
+
- `TenantDirectory` is the application's port: `findActiveTenants(ids)`
|
|
105
|
+
answers which ids are active tenants and what they are called.
|
|
106
|
+
- `FeatureFlagStore` is the storage port. `@dads-framework/feature-flags-postgres`
|
|
107
|
+
implements it; `InMemoryFeatureFlagStore` in `/testing` is the in-memory one.
|
|
108
|
+
`verifyFeatureFlagStoreConformance(createStore)` in `/testing` is the suite
|
|
109
|
+
both pass; run it against any store you write.
|
|
110
|
+
- `FeatureFlagContext` is `{ kind: "platform" }` or
|
|
111
|
+
`{ kind: "tenant", tenantId }`. The platform context counts flags that are
|
|
112
|
+
on for everyone only.
|
|
113
|
+
- `@dads-framework/feature-flags/contract` holds the Zod schemas, route paths
|
|
114
|
+
and header names, with no server code, for a client to import.
|
|
115
|
+
- `@dads-framework/feature-flags-http` serves the routes and the per-request
|
|
116
|
+
evaluator; `@dads-framework/client-feature-flags` reads the state in a
|
|
117
|
+
browser.
|
|
118
|
+
|
|
119
|
+
## What it refuses to do
|
|
120
|
+
|
|
121
|
+
- It never stores a definition. A stored row for a slug the code no longer
|
|
122
|
+
defines is never evaluated and never listed.
|
|
123
|
+
- It never applies part of a batch. One stale `expectedRevision` refuses the
|
|
124
|
+
whole batch.
|
|
125
|
+
- It never selects a tenant the `TenantDirectory` does not report as active.
|
|
126
|
+
- It never shows a selected-tenants pilot to the platform context or to the
|
|
127
|
+
public state.
|
|
128
|
+
- It never decides who may manage flags. The HTTP binding asks the
|
|
129
|
+
application's `Authorization` with the permission the application names.
|
|
130
|
+
|
|
131
|
+
## Contract
|
|
132
|
+
|
|
133
|
+
| Shape | Fields |
|
|
134
|
+
| --------------------------- | ---------------------------------------------------------------------------------------------------------- |
|
|
135
|
+
| `FeatureFlagState` | `slug`, `audienceMode`, `rememberedTenants[]`, `revision`, `globalEnabledAt`, `updatedAt`, `updatedBy` |
|
|
136
|
+
| `UpdateFeatureFlagsRequest` | `changes[]`: `{ slug, expectedRevision, mode, note? }`, plus `tenantIds` when `mode` is `SELECTED_TENANTS` |
|
|
137
|
+
| `FeatureFlagHistoryEntry` | `batchId`, `slug`, `revision`, `previousState`, `nextState`, `note?`, `changedAt`, `changedBy` |
|
|
138
|
+
| `EffectiveFeatureState` | `features` (sorted slugs that are on), `stateHash` (SHA-256 of that list) |
|
|
139
|
+
| `PublicFeatureState` | `features` (public-list slugs that are on for everyone) |
|
|
140
|
+
|
|
141
|
+
| Error code | Kind | When |
|
|
142
|
+
| -------------------------------- | ---------- | ----------------------------------------------------------- |
|
|
143
|
+
| `FEATURE_FLAG_STATE_CHANGED` | conflict | an `expectedRevision` is not the stored revision |
|
|
144
|
+
| `FEATURE_FLAG_NOT_FOUND` | not-found | a batch or history read names a slug the code never defined |
|
|
145
|
+
| `FEATURE_FLAG_CHANGE_DUPLICATED` | validation | one batch names the same slug twice |
|
|
146
|
+
| `FEATURE_FLAG_TENANT_NOT_FOUND` | not-found | a selected tenant is not active |
|
|
147
|
+
|
|
148
|
+
`composeFeatureFlags` throws at startup when a slug is defined twice or a
|
|
149
|
+
public slug is not defined.
|
|
150
|
+
|
|
151
|
+
## Install as a plugin
|
|
152
|
+
|
|
153
|
+
`createFeatureFlagsPlugin({ definitions, publicSlugs })` declares the flag
|
|
154
|
+
definitions and offers `featureFlagsService`. The API host supplies the store,
|
|
155
|
+
tenant directory, and clock through `featureFlagDepsService`. The service
|
|
156
|
+
has no HTTP routes. Select a separate route or storage plugin where needed.
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
/**
|
|
3
|
+
* Who sees a flag. `SELECTED_TENANTS` means the tenants the flag lists; what a
|
|
4
|
+
* tenant is (a company, a team, a project) is the application's to say.
|
|
5
|
+
*/
|
|
6
|
+
export declare const FEATURE_FLAG_AUDIENCE_MODES: readonly ["OFF", "SELECTED_TENANTS", "EVERYONE"];
|
|
7
|
+
export declare const featureFlagAudienceModeSchema: z.ZodEnum<{
|
|
8
|
+
EVERYONE: "EVERYONE";
|
|
9
|
+
OFF: "OFF";
|
|
10
|
+
SELECTED_TENANTS: "SELECTED_TENANTS";
|
|
11
|
+
}>;
|
|
12
|
+
export type FeatureFlagAudienceMode = z.infer<typeof featureFlagAudienceModeSchema>;
|
|
13
|
+
export declare const featureFlagSlugSchema: z.ZodString;
|
|
14
|
+
/** A flag that changes nothing cannot be reviewed, rolled out or cleaned up. */
|
|
15
|
+
export declare const featureFlagDefinitionSchema: z.ZodReadonly<z.ZodObject<{
|
|
16
|
+
slug: z.ZodString;
|
|
17
|
+
name: z.ZodString;
|
|
18
|
+
description: z.ZodString;
|
|
19
|
+
owner: z.ZodString;
|
|
20
|
+
defaultEnabled: z.ZodLiteral<false>;
|
|
21
|
+
affectedPages: z.ZodArray<z.ZodString>;
|
|
22
|
+
affectedApiCapabilities: z.ZodArray<z.ZodString>;
|
|
23
|
+
cleanupTrigger: z.ZodString;
|
|
24
|
+
globalStabilityDays: z.ZodNumber;
|
|
25
|
+
}, z.core.$strict>>;
|
|
26
|
+
export type FeatureFlagDefinition = z.infer<typeof featureFlagDefinitionSchema>;
|
|
27
|
+
/** Parses a code-owned definition where it is declared, before anything can compose it. */
|
|
28
|
+
export declare function defineFeatureFlag(definition: FeatureFlagDefinition): FeatureFlagDefinition;
|
|
29
|
+
//# sourceMappingURL=feature-flag-definition.schema.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"feature-flag-definition.schema.d.ts","sourceRoot":"","sources":["../../src/contract/feature-flag-definition.schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB;;;GAGG;AACH,eAAO,MAAM,2BAA2B,YACtC,KAAK,EACL,kBAAkB,EAClB,UAAU,CACF,CAAC;AACX,eAAO,MAAM,6BAA6B;;;;EAEzC,CAAC;AACF,MAAM,MAAM,uBAAuB,GAAG,CAAC,CAAC,KAAK,CAC3C,OAAO,6BAA6B,CACrC,CAAC;AAEF,eAAO,MAAM,qBAAqB,aAM9B,CAAC;AAoCL,gFAAgF;AAChF,eAAO,MAAM,2BAA2B;;;;;;;;;;mBAc3B,CAAC;AACd,MAAM,MAAM,qBAAqB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,2BAA2B,CAAC,CAAC;AAEhF,2FAA2F;AAC3F,wBAAgB,iBAAiB,CAC/B,UAAU,EAAE,qBAAqB,GAChC,qBAAqB,CAEvB"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
/**
|
|
3
|
+
* Who sees a flag. `SELECTED_TENANTS` means the tenants the flag lists; what a
|
|
4
|
+
* tenant is (a company, a team, a project) is the application's to say.
|
|
5
|
+
*/
|
|
6
|
+
export const FEATURE_FLAG_AUDIENCE_MODES = [
|
|
7
|
+
"OFF",
|
|
8
|
+
"SELECTED_TENANTS",
|
|
9
|
+
"EVERYONE",
|
|
10
|
+
];
|
|
11
|
+
export const featureFlagAudienceModeSchema = z.enum(FEATURE_FLAG_AUDIENCE_MODES);
|
|
12
|
+
export const featureFlagSlugSchema = z
|
|
13
|
+
.string()
|
|
14
|
+
.regex(/^[a-z0-9-]+(\.[a-z0-9-]+)*$/)
|
|
15
|
+
.meta({
|
|
16
|
+
description: "Code-owned feature-flag slug: lowercase words and dashes, dot-separated (for example billing.invoices.bulk-export)",
|
|
17
|
+
});
|
|
18
|
+
const featureFlagDefinitionShape = z.strictObject({
|
|
19
|
+
slug: featureFlagSlugSchema,
|
|
20
|
+
name: z
|
|
21
|
+
.string()
|
|
22
|
+
.trim()
|
|
23
|
+
.min(1)
|
|
24
|
+
.meta({ description: "Human-readable flag name" }),
|
|
25
|
+
description: z
|
|
26
|
+
.string()
|
|
27
|
+
.trim()
|
|
28
|
+
.min(1)
|
|
29
|
+
.meta({ description: "What this code-owned flag changes" }),
|
|
30
|
+
owner: z.string().trim().min(1).meta({
|
|
31
|
+
description: "Person or team accountable for rollout and cleanup",
|
|
32
|
+
}),
|
|
33
|
+
defaultEnabled: z.literal(false).meta({
|
|
34
|
+
description: "Code-owned default; every new feature flag starts inactive",
|
|
35
|
+
}),
|
|
36
|
+
affectedPages: z.array(z.string().trim().min(1)).meta({
|
|
37
|
+
description: "Pages this flag changes, as the application names them",
|
|
38
|
+
}),
|
|
39
|
+
affectedApiCapabilities: z.array(z.string().trim().min(1)).meta({
|
|
40
|
+
description: "API capabilities this flag changes",
|
|
41
|
+
}),
|
|
42
|
+
cleanupTrigger: z.string().trim().min(1).meta({
|
|
43
|
+
description: "Concrete condition that begins removal of this flag and its paths",
|
|
44
|
+
}),
|
|
45
|
+
globalStabilityDays: z.number().int().positive().meta({
|
|
46
|
+
description: "Whole days the flag must stay on for everyone before cleanup is due",
|
|
47
|
+
}),
|
|
48
|
+
});
|
|
49
|
+
/** A flag that changes nothing cannot be reviewed, rolled out or cleaned up. */
|
|
50
|
+
export const featureFlagDefinitionSchema = featureFlagDefinitionShape
|
|
51
|
+
.superRefine((definition, context) => {
|
|
52
|
+
if (definition.affectedPages.length === 0 &&
|
|
53
|
+
definition.affectedApiCapabilities.length === 0) {
|
|
54
|
+
context.addIssue({
|
|
55
|
+
code: "custom",
|
|
56
|
+
message: "A feature flag must affect at least one page or API capability.",
|
|
57
|
+
path: ["affectedPages"],
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
})
|
|
61
|
+
.readonly();
|
|
62
|
+
/** Parses a code-owned definition where it is declared, before anything can compose it. */
|
|
63
|
+
export function defineFeatureFlag(definition) {
|
|
64
|
+
return featureFlagDefinitionSchema.parse(definition);
|
|
65
|
+
}
|
|
66
|
+
//# sourceMappingURL=feature-flag-definition.schema.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"feature-flag-definition.schema.js","sourceRoot":"","sources":["../../src/contract/feature-flag-definition.schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB;;;GAGG;AACH,MA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AC,CAAC,IAAI,CAAC;QAC9D,WAAW,EAAE,oCAAoC;KAClD,CAAC;IACF,cAAc,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,IAAI,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;QAC5C,WAAW,EACT,mEAAmE;KACtE,CAAC;IACF,mBAAmB,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC,QAAQ,EAAE,CAAC,IAAI,CAAC;QACpD,WAAW,EACT,qEAAqE;KACxE,CAAC;CACH,CAAC,CAAC;AAEH,gFAAgF;AAChF,MAAM,CAAC,MAAM,2BAA2B,GAAG,0BAA0B;KAClE,WAAW,CAAC,CAAC,UAAU,EAAE,OAAO,EAAE,EAAE;IACnC,IACE,UAAU,CAAC,aAAa,CAAC,MAAM,KAAK,CAAC;QACrC,UAAU,CAAC,uBAAuB,CAAC,MAAM,KAAK,CAAC,EAC/C,CAAC;QACD,OAAO,CAAC,QAAQ,CAAC;YACf,IAAI,EAAE,QAAQ;YACd,OAAO,EACL,iEAAiE;YACnE,IAAI,EAAE,CAAC,eAAe,CAAC;SACxB,CAAC,CAAC;IACL,CAAC;AACH,CAAC,CAAC;KACD,QAAQ,EAAE,CAAC;AAGd,2FAA2F;AAC3F,MAAM,UAAU,iBAAiB,CAC/B,UAAiC;IAEjC,OAAO,2BAA2B,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;AACvD,CAAC"}
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
/** The application's tenant key. The package stores and compares it; it never parses it. */
|
|
3
|
+
export declare const tenantIdSchema: z.ZodString;
|
|
4
|
+
/** Who changed a flag: the authenticated subject's id, as the application issues it. */
|
|
5
|
+
export declare const featureFlagActorIdSchema: z.ZodString;
|
|
6
|
+
/** One management batch; every history entry it wrote carries it. */
|
|
7
|
+
export declare const featureFlagBatchIdSchema: z.core.$ZodBranded<z.ZodUUID, "FeatureFlagBatchId", "out">;
|
|
8
|
+
export type FeatureFlagBatchId = z.infer<typeof featureFlagBatchIdSchema>;
|
|
9
|
+
export declare const featureFlagRevisionSchema: z.ZodNumber;
|
|
10
|
+
export declare const featureFlagRememberedTenantSchema: z.ZodReadonly<z.ZodObject<{
|
|
11
|
+
tenantId: z.ZodString;
|
|
12
|
+
tenantName: z.ZodString;
|
|
13
|
+
enabledAt: z.ZodNullable<z.ZodISODateTime>;
|
|
14
|
+
}, z.core.$strict>>;
|
|
15
|
+
export type FeatureFlagRememberedTenant = z.infer<typeof featureFlagRememberedTenantSchema>;
|
|
16
|
+
/**
|
|
17
|
+
* Durable flag state. A flag with no stored row reads as its default:
|
|
18
|
+
* revision 0, OFF, and null timestamps.
|
|
19
|
+
*/
|
|
20
|
+
export declare const featureFlagStateSchema: z.ZodReadonly<z.ZodObject<{
|
|
21
|
+
slug: z.ZodString;
|
|
22
|
+
audienceMode: z.ZodEnum<{
|
|
23
|
+
EVERYONE: "EVERYONE";
|
|
24
|
+
OFF: "OFF";
|
|
25
|
+
SELECTED_TENANTS: "SELECTED_TENANTS";
|
|
26
|
+
}>;
|
|
27
|
+
rememberedTenants: z.ZodArray<z.ZodReadonly<z.ZodObject<{
|
|
28
|
+
tenantId: z.ZodString;
|
|
29
|
+
tenantName: z.ZodString;
|
|
30
|
+
enabledAt: z.ZodNullable<z.ZodISODateTime>;
|
|
31
|
+
}, z.core.$strict>>>;
|
|
32
|
+
revision: z.ZodNumber;
|
|
33
|
+
globalEnabledAt: z.ZodNullable<z.ZodISODateTime>;
|
|
34
|
+
updatedAt: z.ZodNullable<z.ZodISODateTime>;
|
|
35
|
+
updatedBy: z.ZodNullable<z.ZodString>;
|
|
36
|
+
}, z.core.$strict>>;
|
|
37
|
+
export type FeatureFlagState = z.infer<typeof featureFlagStateSchema>;
|
|
38
|
+
export declare const featureFlagManagementListSchema: z.ZodReadonly<z.ZodObject<{
|
|
39
|
+
flags: z.ZodArray<z.ZodReadonly<z.ZodObject<{
|
|
40
|
+
definition: z.ZodReadonly<z.ZodObject<{
|
|
41
|
+
slug: z.ZodString;
|
|
42
|
+
name: z.ZodString;
|
|
43
|
+
description: z.ZodString;
|
|
44
|
+
owner: z.ZodString;
|
|
45
|
+
defaultEnabled: z.ZodLiteral<false>;
|
|
46
|
+
affectedPages: z.ZodArray<z.ZodString>;
|
|
47
|
+
affectedApiCapabilities: z.ZodArray<z.ZodString>;
|
|
48
|
+
cleanupTrigger: z.ZodString;
|
|
49
|
+
globalStabilityDays: z.ZodNumber;
|
|
50
|
+
}, z.core.$strict>>;
|
|
51
|
+
state: z.ZodReadonly<z.ZodObject<{
|
|
52
|
+
slug: z.ZodString;
|
|
53
|
+
audienceMode: z.ZodEnum<{
|
|
54
|
+
EVERYONE: "EVERYONE";
|
|
55
|
+
OFF: "OFF";
|
|
56
|
+
SELECTED_TENANTS: "SELECTED_TENANTS";
|
|
57
|
+
}>;
|
|
58
|
+
rememberedTenants: z.ZodArray<z.ZodReadonly<z.ZodObject<{
|
|
59
|
+
tenantId: z.ZodString;
|
|
60
|
+
tenantName: z.ZodString;
|
|
61
|
+
enabledAt: z.ZodNullable<z.ZodISODateTime>;
|
|
62
|
+
}, z.core.$strict>>>;
|
|
63
|
+
revision: z.ZodNumber;
|
|
64
|
+
globalEnabledAt: z.ZodNullable<z.ZodISODateTime>;
|
|
65
|
+
updatedAt: z.ZodNullable<z.ZodISODateTime>;
|
|
66
|
+
updatedBy: z.ZodNullable<z.ZodString>;
|
|
67
|
+
}, z.core.$strict>>;
|
|
68
|
+
cleanupReady: z.ZodBoolean;
|
|
69
|
+
}, z.core.$strict>>>;
|
|
70
|
+
}, z.core.$strict>>;
|
|
71
|
+
export type FeatureFlagManagementList = z.infer<typeof featureFlagManagementListSchema>;
|
|
72
|
+
export declare const featureFlagHistoryEntrySchema: z.ZodReadonly<z.ZodObject<{
|
|
73
|
+
batchId: z.core.$ZodBranded<z.ZodUUID, "FeatureFlagBatchId", "out">;
|
|
74
|
+
slug: z.ZodString;
|
|
75
|
+
revision: z.ZodNumber;
|
|
76
|
+
previousState: z.ZodReadonly<z.ZodObject<{
|
|
77
|
+
slug: z.ZodString;
|
|
78
|
+
audienceMode: z.ZodEnum<{
|
|
79
|
+
EVERYONE: "EVERYONE";
|
|
80
|
+
OFF: "OFF";
|
|
81
|
+
SELECTED_TENANTS: "SELECTED_TENANTS";
|
|
82
|
+
}>;
|
|
83
|
+
rememberedTenants: z.ZodArray<z.ZodReadonly<z.ZodObject<{
|
|
84
|
+
tenantId: z.ZodString;
|
|
85
|
+
tenantName: z.ZodString;
|
|
86
|
+
enabledAt: z.ZodNullable<z.ZodISODateTime>;
|
|
87
|
+
}, z.core.$strict>>>;
|
|
88
|
+
revision: z.ZodNumber;
|
|
89
|
+
globalEnabledAt: z.ZodNullable<z.ZodISODateTime>;
|
|
90
|
+
updatedAt: z.ZodNullable<z.ZodISODateTime>;
|
|
91
|
+
updatedBy: z.ZodNullable<z.ZodString>;
|
|
92
|
+
}, z.core.$strict>>;
|
|
93
|
+
nextState: z.ZodReadonly<z.ZodObject<{
|
|
94
|
+
slug: z.ZodString;
|
|
95
|
+
audienceMode: z.ZodEnum<{
|
|
96
|
+
EVERYONE: "EVERYONE";
|
|
97
|
+
OFF: "OFF";
|
|
98
|
+
SELECTED_TENANTS: "SELECTED_TENANTS";
|
|
99
|
+
}>;
|
|
100
|
+
rememberedTenants: z.ZodArray<z.ZodReadonly<z.ZodObject<{
|
|
101
|
+
tenantId: z.ZodString;
|
|
102
|
+
tenantName: z.ZodString;
|
|
103
|
+
enabledAt: z.ZodNullable<z.ZodISODateTime>;
|
|
104
|
+
}, z.core.$strict>>>;
|
|
105
|
+
revision: z.ZodNumber;
|
|
106
|
+
globalEnabledAt: z.ZodNullable<z.ZodISODateTime>;
|
|
107
|
+
updatedAt: z.ZodNullable<z.ZodISODateTime>;
|
|
108
|
+
updatedBy: z.ZodNullable<z.ZodString>;
|
|
109
|
+
}, z.core.$strict>>;
|
|
110
|
+
note: z.ZodOptional<z.ZodString>;
|
|
111
|
+
changedAt: z.ZodISODateTime;
|
|
112
|
+
changedBy: z.ZodString;
|
|
113
|
+
}, z.core.$strict>>;
|
|
114
|
+
export type FeatureFlagHistoryEntry = z.infer<typeof featureFlagHistoryEntrySchema>;
|
|
115
|
+
export declare const featureFlagHistoryParamsSchema: z.ZodReadonly<z.ZodObject<{
|
|
116
|
+
slug: z.ZodString;
|
|
117
|
+
}, z.core.$strict>>;
|
|
118
|
+
export declare const featureFlagHistoryQuerySchema: z.ZodObject<{
|
|
119
|
+
page: z.ZodDefault<z.ZodCoercedNumber<unknown>>;
|
|
120
|
+
perPage: z.ZodDefault<z.ZodCoercedNumber<unknown>>;
|
|
121
|
+
}, z.core.$strict>;
|
|
122
|
+
export declare const updateFeatureFlagInputSchema: z.ZodReadonly<z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
123
|
+
slug: z.ZodString;
|
|
124
|
+
expectedRevision: z.ZodNumber;
|
|
125
|
+
note: z.ZodOptional<z.ZodString>;
|
|
126
|
+
mode: z.ZodLiteral<"OFF">;
|
|
127
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
128
|
+
slug: z.ZodString;
|
|
129
|
+
expectedRevision: z.ZodNumber;
|
|
130
|
+
note: z.ZodOptional<z.ZodString>;
|
|
131
|
+
mode: z.ZodLiteral<"EVERYONE">;
|
|
132
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
133
|
+
slug: z.ZodString;
|
|
134
|
+
expectedRevision: z.ZodNumber;
|
|
135
|
+
note: z.ZodOptional<z.ZodString>;
|
|
136
|
+
mode: z.ZodLiteral<"SELECTED_TENANTS">;
|
|
137
|
+
tenantIds: z.ZodArray<z.ZodString>;
|
|
138
|
+
}, z.core.$strict>], "mode">>;
|
|
139
|
+
export type UpdateFeatureFlagInput = z.infer<typeof updateFeatureFlagInputSchema>;
|
|
140
|
+
export declare const updateFeatureFlagsRequestSchema: z.ZodReadonly<z.ZodObject<{
|
|
141
|
+
changes: z.ZodArray<z.ZodReadonly<z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
142
|
+
slug: z.ZodString;
|
|
143
|
+
expectedRevision: z.ZodNumber;
|
|
144
|
+
note: z.ZodOptional<z.ZodString>;
|
|
145
|
+
mode: z.ZodLiteral<"OFF">;
|
|
146
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
147
|
+
slug: z.ZodString;
|
|
148
|
+
expectedRevision: z.ZodNumber;
|
|
149
|
+
note: z.ZodOptional<z.ZodString>;
|
|
150
|
+
mode: z.ZodLiteral<"EVERYONE">;
|
|
151
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
152
|
+
slug: z.ZodString;
|
|
153
|
+
expectedRevision: z.ZodNumber;
|
|
154
|
+
note: z.ZodOptional<z.ZodString>;
|
|
155
|
+
mode: z.ZodLiteral<"SELECTED_TENANTS">;
|
|
156
|
+
tenantIds: z.ZodArray<z.ZodString>;
|
|
157
|
+
}, z.core.$strict>], "mode">>>;
|
|
158
|
+
}, z.core.$strict>>;
|
|
159
|
+
export type UpdateFeatureFlagsRequest = z.infer<typeof updateFeatureFlagsRequestSchema>;
|
|
160
|
+
export declare const updateFeatureFlagsResponseSchema: z.ZodReadonly<z.ZodObject<{
|
|
161
|
+
states: z.ZodArray<z.ZodReadonly<z.ZodObject<{
|
|
162
|
+
slug: z.ZodString;
|
|
163
|
+
audienceMode: z.ZodEnum<{
|
|
164
|
+
EVERYONE: "EVERYONE";
|
|
165
|
+
OFF: "OFF";
|
|
166
|
+
SELECTED_TENANTS: "SELECTED_TENANTS";
|
|
167
|
+
}>;
|
|
168
|
+
rememberedTenants: z.ZodArray<z.ZodReadonly<z.ZodObject<{
|
|
169
|
+
tenantId: z.ZodString;
|
|
170
|
+
tenantName: z.ZodString;
|
|
171
|
+
enabledAt: z.ZodNullable<z.ZodISODateTime>;
|
|
172
|
+
}, z.core.$strict>>>;
|
|
173
|
+
revision: z.ZodNumber;
|
|
174
|
+
globalEnabledAt: z.ZodNullable<z.ZodISODateTime>;
|
|
175
|
+
updatedAt: z.ZodNullable<z.ZodISODateTime>;
|
|
176
|
+
updatedBy: z.ZodNullable<z.ZodString>;
|
|
177
|
+
}, z.core.$strict>>>;
|
|
178
|
+
}, z.core.$strict>>;
|
|
179
|
+
//# sourceMappingURL=feature-flag-management.schema.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"feature-flag-management.schema.d.ts","sourceRoot":"","sources":["../../src/contract/feature-flag-management.schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAaxB,4FAA4F;AAC5F,eAAO,MAAM,cAAc,aAEzB,CAAC;AAEH,wFAAwF;AACxF,eAAO,MAAM,wBAAwB,aAEnC,CAAC;AAEH,qEAAqE;AACrE,eAAO,MAAM,wBAAwB,4DAGpC,CAAC;AACF,MAAM,MAAM,kBAAkB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,wBAAwB,CAAC,CAAC;AAE1E,eAAO,MAAM,yBAAyB,aAEpC,CAAC;AAEH,eAAO,MAAM,iCAAiC;;;;mBAWjC,CAAC;AACd,MAAM,MAAM,2BAA2B,GAAG,CAAC,CAAC,KAAK,CAC/C,OAAO,iCAAiC,CACzC,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,sBAAsB;;;;;;;;;;;;;;;;mBAgBtB,CAAC;AACd,MAAM,MAAM,gBAAgB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,sBAAsB,CAAC,CAAC;AAEtE,eAAO,MAAM,+BAA+B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;mBAe/B,CAAC;AACd,MAAM,MAAM,yBAAyB,GAAG,CAAC,CAAC,KAAK,CAC7C,OAAO,+BAA+B,CACvC,CAAC;AAEF,eAAO,MAAM,6BAA6B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;mBAe7B,CAAC;AACd,MAAM,MAAM,uBAAuB,GAAG,CAAC,CAAC,KAAK,CAC3C,OAAO,6BAA6B,CACrC,CAAC;AAEF,eAAO,MAAM,8BAA8B;;mBAE9B,CAAC;AACd,eAAO,MAAM,6BAA6B;;;kBAAiC,CAAC;AAsB5E,eAAO,MAAM,4BAA4B;;;;;;;;;;;;;;;;6BAU5B,CAAC;AACd,MAAM,MAAM,sBAAsB,GAAG,CAAC,CAAC,KAAK,CAC1C,OAAO,4BAA4B,CACpC,CAAC;AAEF,eAAO,MAAM,+BAA+B;;;;;;;;;;;;;;;;;;mBAM/B,CAAC;AACd,MAAM,MAAM,yBAAyB,GAAG,CAAC,CAAC,KAAK,CAC7C,OAAO,+BAA+B,CACvC,CAAC;AAEF,eAAO,MAAM,gCAAgC;;;;;;;;;;;;;;;;;;mBAEhC,CAAC"}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { entityIdSchema, paginationQuerySchema, } from "@dads-framework/contract";
|
|
3
|
+
import { featureFlagAudienceModeSchema, featureFlagDefinitionSchema, featureFlagSlugSchema, } from "./feature-flag-definition.schema.js";
|
|
4
|
+
/** The application's tenant key. The package stores and compares it; it never parses it. */
|
|
5
|
+
export const tenantIdSchema = z.string().trim().min(1).meta({
|
|
6
|
+
description: "Application-defined tenant key",
|
|
7
|
+
});
|
|
8
|
+
/** Who changed a flag: the authenticated subject's id, as the application issues it. */
|
|
9
|
+
export const featureFlagActorIdSchema = z.string().trim().min(1).meta({
|
|
10
|
+
description: "Id of the subject that changed the flag",
|
|
11
|
+
});
|
|
12
|
+
/** One management batch; every history entry it wrote carries it. */
|
|
13
|
+
export const featureFlagBatchIdSchema = entityIdSchema("FeatureFlagBatchId", "Atomic feature-flag management batch id");
|
|
14
|
+
export const featureFlagRevisionSchema = z.number().int().nonnegative().meta({
|
|
15
|
+
description: "Monotonic revision for atomic feature-flag management writes",
|
|
16
|
+
});
|
|
17
|
+
export const featureFlagRememberedTenantSchema = z
|
|
18
|
+
.strictObject({
|
|
19
|
+
tenantId: tenantIdSchema,
|
|
20
|
+
tenantName: z.string().trim().min(1).meta({
|
|
21
|
+
description: "Tenant name for management display",
|
|
22
|
+
}),
|
|
23
|
+
enabledAt: z.iso.datetime().nullable().meta({
|
|
24
|
+
description: "Time this tenant was last selected, ISO 8601 UTC; null while it is not selected",
|
|
25
|
+
}),
|
|
26
|
+
})
|
|
27
|
+
.readonly();
|
|
28
|
+
/**
|
|
29
|
+
* Durable flag state. A flag with no stored row reads as its default:
|
|
30
|
+
* revision 0, OFF, and null timestamps.
|
|
31
|
+
*/
|
|
32
|
+
export const featureFlagStateSchema = z
|
|
33
|
+
.strictObject({
|
|
34
|
+
slug: featureFlagSlugSchema,
|
|
35
|
+
audienceMode: featureFlagAudienceModeSchema,
|
|
36
|
+
rememberedTenants: z.array(featureFlagRememberedTenantSchema).meta({
|
|
37
|
+
description: "Pilot tenants kept across OFF and EVERYONE",
|
|
38
|
+
}),
|
|
39
|
+
revision: featureFlagRevisionSchema,
|
|
40
|
+
globalEnabledAt: z.iso.datetime().nullable().meta({
|
|
41
|
+
description: "Time EVERYONE was last turned on, ISO 8601 UTC",
|
|
42
|
+
}),
|
|
43
|
+
updatedAt: z.iso.datetime().nullable().meta({
|
|
44
|
+
description: "Last durable state update time, ISO 8601 UTC",
|
|
45
|
+
}),
|
|
46
|
+
updatedBy: featureFlagActorIdSchema.nullable(),
|
|
47
|
+
})
|
|
48
|
+
.readonly();
|
|
49
|
+
export const featureFlagManagementListSchema = z
|
|
50
|
+
.strictObject({
|
|
51
|
+
flags: z.array(z
|
|
52
|
+
.strictObject({
|
|
53
|
+
definition: featureFlagDefinitionSchema,
|
|
54
|
+
state: featureFlagStateSchema,
|
|
55
|
+
cleanupReady: z.boolean().meta({
|
|
56
|
+
description: "Whether this flag has been on for everyone long enough to remove",
|
|
57
|
+
}),
|
|
58
|
+
})
|
|
59
|
+
.readonly()),
|
|
60
|
+
})
|
|
61
|
+
.readonly();
|
|
62
|
+
export const featureFlagHistoryEntrySchema = z
|
|
63
|
+
.strictObject({
|
|
64
|
+
batchId: featureFlagBatchIdSchema,
|
|
65
|
+
slug: featureFlagSlugSchema,
|
|
66
|
+
revision: featureFlagRevisionSchema,
|
|
67
|
+
previousState: featureFlagStateSchema,
|
|
68
|
+
nextState: featureFlagStateSchema,
|
|
69
|
+
note: z.string().trim().min(1).optional().meta({
|
|
70
|
+
description: "Optional operator note recorded for this revision",
|
|
71
|
+
}),
|
|
72
|
+
changedAt: z.iso
|
|
73
|
+
.datetime()
|
|
74
|
+
.meta({ description: "Change time, ISO 8601 UTC" }),
|
|
75
|
+
changedBy: featureFlagActorIdSchema,
|
|
76
|
+
})
|
|
77
|
+
.readonly();
|
|
78
|
+
export const featureFlagHistoryParamsSchema = z
|
|
79
|
+
.strictObject({ slug: featureFlagSlugSchema })
|
|
80
|
+
.readonly();
|
|
81
|
+
export const featureFlagHistoryQuerySchema = paginationQuerySchema.strict();
|
|
82
|
+
const selectedTenantIdsSchema = z
|
|
83
|
+
.array(tenantIdSchema)
|
|
84
|
+
.min(1)
|
|
85
|
+
.superRefine((tenantIds, context) => {
|
|
86
|
+
if (new Set(tenantIds).size !== tenantIds.length) {
|
|
87
|
+
context.addIssue({
|
|
88
|
+
code: "custom",
|
|
89
|
+
message: "Selected tenant ids must be unique.",
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
const featureFlagUpdateBase = {
|
|
94
|
+
slug: featureFlagSlugSchema,
|
|
95
|
+
expectedRevision: featureFlagRevisionSchema,
|
|
96
|
+
note: z.string().trim().min(1).optional().meta({
|
|
97
|
+
description: "Optional operator note for this flag update",
|
|
98
|
+
}),
|
|
99
|
+
};
|
|
100
|
+
export const updateFeatureFlagInputSchema = z
|
|
101
|
+
.discriminatedUnion("mode", [
|
|
102
|
+
z.strictObject({ ...featureFlagUpdateBase, mode: z.literal("OFF") }),
|
|
103
|
+
z.strictObject({ ...featureFlagUpdateBase, mode: z.literal("EVERYONE") }),
|
|
104
|
+
z.strictObject({
|
|
105
|
+
...featureFlagUpdateBase,
|
|
106
|
+
mode: z.literal("SELECTED_TENANTS"),
|
|
107
|
+
tenantIds: selectedTenantIdsSchema,
|
|
108
|
+
}),
|
|
109
|
+
])
|
|
110
|
+
.readonly();
|
|
111
|
+
export const updateFeatureFlagsRequestSchema = z
|
|
112
|
+
.strictObject({
|
|
113
|
+
changes: z.array(updateFeatureFlagInputSchema).min(1).meta({
|
|
114
|
+
description: "Flag audience updates applied together or not at all",
|
|
115
|
+
}),
|
|
116
|
+
})
|
|
117
|
+
.readonly();
|
|
118
|
+
export const updateFeatureFlagsResponseSchema = z
|
|
119
|
+
.strictObject({ states: z.array(featureFlagStateSchema) })
|
|
120
|
+
.readonly();
|
|
121
|
+
//# sourceMappingURL=feature-flag-management.schema.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"feature-flag-management.schema.js","sourceRoot":"","sources":["../../src/contract/feature-flag-management.schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EACL,cAAc,EACd,qBAAqB,GACtB,MAAM,0BAA0B,CAAC;AAElC,OAAO,EACL,6BAA6B,EAC7B,2BAA2B,EAC3B,qBAAqB,GACtB,MAAM,qCAAqC,CAAC;AAE7C,4FAA4F;AAC5F,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,CAAC,MAAM,EAAE,CAAC,IAAI,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;IAC1D,WAAW,EAAE,gCAAgC;CAC9C,CAAC,CAAC;AAEH,wFAAwF;AACxF,MAAM,CAAC,MAAM,wBAAwB,GAAG,CAAC,CAAC,MAAM,EAAE,CAAC,IAAI,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;IACpE,WAAW,EAAE,yCAAyC;CACvD,CAAC,CAAC;AAEH,qEAAqE;AACrE,MAAM,CAAC,MAAM,wBAAwB,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AKd,MAAM,CAAC,MAAM,gCAAgC,GAAG,CAAC;KAC9C,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC,KAAK,CAAC,sBAAsB,CAAC,EAAE,CAAC;KACzD,QAAQ,EAAE,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
/** Default header names; an application may pick its own and hand them to the HTTP kit. */
|
|
3
|
+
export declare const FEATURE_STATE_HASH_HEADER = "x-feature-state-hash";
|
|
4
|
+
export declare const CLIENT_FEATURE_STATE_HASH_HEADER = "x-client-feature-state-hash";
|
|
5
|
+
export declare const FEATURE_STATE_CONTEXT_HEADER = "x-feature-state-context";
|
|
6
|
+
/** Route paths the HTTP binding serves and a client calls. */
|
|
7
|
+
export declare const FEATURE_FLAGS_PATH = "/feature-flags";
|
|
8
|
+
export declare const FEATURE_FLAG_HISTORY_PATH = "/feature-flags/:slug/history";
|
|
9
|
+
export declare const FEATURE_STATE_PATH = "/feature-state";
|
|
10
|
+
export declare const PUBLIC_FEATURE_STATE_PATH = "/feature-state/public";
|
|
11
|
+
export declare const featureStateHashSchema: z.ZodString;
|
|
12
|
+
export declare const effectiveFeatureStateSchema: z.ZodReadonly<z.ZodObject<{
|
|
13
|
+
features: z.ZodArray<z.ZodString>;
|
|
14
|
+
stateHash: z.ZodString;
|
|
15
|
+
}, z.core.$strict>>;
|
|
16
|
+
export type EffectiveFeatureState = z.infer<typeof effectiveFeatureStateSchema>;
|
|
17
|
+
/**
|
|
18
|
+
* What a signed-out reader may see: flags from the application's declared
|
|
19
|
+
* public list that are on for everyone. No tenant pilot, no hash.
|
|
20
|
+
*/
|
|
21
|
+
export declare const publicFeatureStateSchema: z.ZodReadonly<z.ZodObject<{
|
|
22
|
+
features: z.ZodArray<z.ZodString>;
|
|
23
|
+
}, z.core.$strict>>;
|
|
24
|
+
export type PublicFeatureState = z.infer<typeof publicFeatureStateSchema>;
|
|
25
|
+
//# sourceMappingURL=feature-state.schema.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"feature-state.schema.d.ts","sourceRoot":"","sources":["../../src/contract/feature-state.schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAIxB,2FAA2F;AAC3F,eAAO,MAAM,yBAAyB,yBAAyB,CAAC;AAChE,eAAO,MAAM,gCAAgC,gCAAgC,CAAC;AAC9E,eAAO,MAAM,4BAA4B,4BAA4B,CAAC;AAEtE,8DAA8D;AAC9D,eAAO,MAAM,kBAAkB,mBAAmB,CAAC;AACnD,eAAO,MAAM,yBAAyB,iCAAiC,CAAC;AACxE,eAAO,MAAM,kBAAkB,mBAAmB,CAAC;AACnD,eAAO,MAAM,yBAAyB,0BAA0B,CAAC;AAEjE,eAAO,MAAM,sBAAsB,aAEjC,CAAC;AAEH,eAAO,MAAM,2BAA2B;;;mBAO3B,CAAC;AACd,MAAM,MAAM,qBAAqB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,2BAA2B,CAAC,CAAC;AAEhF;;;GAGG;AACH,eAAO,MAAM,wBAAwB;;mBAOxB,CAAC;AACd,MAAM,MAAM,kBAAkB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,wBAAwB,CAAC,CAAC"}
|