@marktiderman/genesis-features 0.3.0 → 0.4.1
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 +40 -0
- package/dist/blocks.js +3 -2
- package/dist/{chunk-EF72JS5S.js → chunk-4Q356635.js} +4 -3
- package/dist/chunk-4Q356635.js.map +1 -0
- package/dist/chunk-B6WRD3WF.js +6 -0
- package/dist/chunk-B6WRD3WF.js.map +1 -0
- package/dist/{chunk-KCUQY5UZ.js → chunk-JMXJZT6O.js} +8 -10
- package/dist/chunk-JMXJZT6O.js.map +1 -0
- package/dist/chunk-LNVWVPWB.js +111 -0
- package/dist/chunk-LNVWVPWB.js.map +1 -0
- package/dist/chunk-OW46SL2G.js +10 -0
- package/dist/chunk-OW46SL2G.js.map +1 -0
- package/dist/{chunk-2ARZER3G.js → chunk-VYUX7VAX.js} +3 -6
- package/dist/chunk-VYUX7VAX.js.map +1 -0
- package/dist/gate-BY352cd0.d.ts +186 -0
- package/dist/gate-react.d.ts +48 -0
- package/dist/gate-react.js +37 -0
- package/dist/gate-react.js.map +1 -0
- package/dist/gate.d.ts +18 -0
- package/dist/gate.js +5 -0
- package/dist/gate.js.map +1 -0
- package/dist/index.d.ts +5 -2
- package/dist/index.js +6 -3
- package/dist/{model-CW3d2gsf.d.ts → model-8dMGbgtM.d.ts} +3 -36
- package/dist/node.d.ts +2 -1
- package/dist/node.js +4 -2
- package/dist/node.js.map +1 -1
- package/dist/react.d.ts +2 -1
- package/dist/react.js +4 -2
- package/dist/react.js.map +1 -1
- package/dist/types-Bd766VxF.d.ts +39 -0
- package/package.json +12 -4
- package/dist/chunk-2ARZER3G.js.map +0 -1
- package/dist/chunk-EF72JS5S.js.map +0 -1
- package/dist/chunk-KCUQY5UZ.js.map +0 -1
package/README.md
CHANGED
|
@@ -120,6 +120,46 @@ The flag scan ignores comments and test files. List the flags runtime itself (th
|
|
|
120
120
|
|
|
121
121
|
The CLI loads TypeScript itself, so the registry needs no build step. Keep its imports to packages, with no path aliases.
|
|
122
122
|
|
|
123
|
+
## The gate
|
|
124
|
+
|
|
125
|
+
`featureOn(registry, context, id)` answers "is this feature on here?" the same way everywhere. Checks
|
|
126
|
+
run in a fixed order and the first "no" wins: **status** (beta, live or deprecated), **platform**, **tenant**
|
|
127
|
+
(switched off), **flag** (each boolean release flag must be exactly `true`) and last **entitlement** (for
|
|
128
|
+
`access: { plan }`), so an upgrade prompt only appears when paying is the one thing missing. The answer
|
|
129
|
+
carries the reason, and for a paid feature the plan that unlocks it.
|
|
130
|
+
|
|
131
|
+
```ts
|
|
132
|
+
import { featureOn, gateSnapshot, isSnapshotStale, requireFeature } from "@marktiderman/genesis-features/gate";
|
|
133
|
+
|
|
134
|
+
const context = { platform: "web", entitlements: ["form-webhook-delivery"], off: ["library"], flags: { "sms.release": true } };
|
|
135
|
+
featureOn({ features, flags }, context, "library"); // { on: false, reason: "tenant" }
|
|
136
|
+
|
|
137
|
+
// Server functions refuse whatever the reason: FeatureOff has status 402 (entitlement) or 403.
|
|
138
|
+
requireFeature({ features, flags }, context, "form-webhook-delivery");
|
|
139
|
+
|
|
140
|
+
// The server hands the client every shipped feature's answer: plain JSON with `at` (and `version`).
|
|
141
|
+
const snapshot = gateSnapshot({ features, flags }, context, { version: buildVersion });
|
|
142
|
+
// A client keeps it, and replaces it when stale, after sign-in or a tenant switch, or after a refusal.
|
|
143
|
+
if (isSnapshotStale(snapshot, 5 * 60_000)) refresh();
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
`/gate` has no zod, React, Node built-ins or DOM globals, so it ships to browsers, extension service workers,
|
|
147
|
+
phones and edge functions. Context id sets are lists, Sets or functions (not iterators or strings). In React (web and React
|
|
148
|
+
Native), `/gate/react` reads the server's snapshot:
|
|
149
|
+
|
|
150
|
+
```tsx
|
|
151
|
+
import { FeatureGate, FeatureGateProvider, useFeature } from "@marktiderman/genesis-features/gate/react";
|
|
152
|
+
|
|
153
|
+
<FeatureGateProvider snapshot={snapshot}>
|
|
154
|
+
<FeatureGate feature="form-webhook-delivery" upsell={({ unlock }) => <Upgrade plan={unlock.plan} />}>
|
|
155
|
+
<WebhookSettings />
|
|
156
|
+
</FeatureGate>
|
|
157
|
+
</FeatureGateProvider>;
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
The gate doesn't check roles: "may this person" stays with roles and row security. Why it works this
|
|
161
|
+
way: [ADR 0001](../../docs/adr/0001-one-feature-gate.md).
|
|
162
|
+
|
|
123
163
|
## Blocks
|
|
124
164
|
|
|
125
165
|
A block is a feature an app adds whole: account, push, observability, support, updates. It is
|
package/dist/blocks.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
export { BlockError, defineBlock, resolveBlocks } from './chunk-
|
|
2
|
-
|
|
1
|
+
export { BlockError, defineBlock, resolveBlocks } from './chunk-4Q356635.js';
|
|
2
|
+
import './chunk-VYUX7VAX.js';
|
|
3
|
+
export { FEATURE_PLATFORMS } from './chunk-B6WRD3WF.js';
|
|
3
4
|
//# sourceMappingURL=blocks.js.map
|
|
4
5
|
//# sourceMappingURL=blocks.js.map
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { requirementProblem, cycleProblems, dependencyOrder
|
|
1
|
+
import { requirementProblem, cycleProblems, dependencyOrder } from './chunk-VYUX7VAX.js';
|
|
2
|
+
import { FEATURE_PLATFORMS } from './chunk-B6WRD3WF.js';
|
|
2
3
|
|
|
3
4
|
// src/blocks.ts
|
|
4
5
|
var BlockError = class extends Error {
|
|
@@ -151,5 +152,5 @@ function resolveBlocks(blocks, enabled, options = {}) {
|
|
|
151
152
|
}
|
|
152
153
|
|
|
153
154
|
export { BlockError, defineBlock, resolveBlocks };
|
|
154
|
-
//# sourceMappingURL=chunk-
|
|
155
|
-
//# sourceMappingURL=chunk-
|
|
155
|
+
//# sourceMappingURL=chunk-4Q356635.js.map
|
|
156
|
+
//# sourceMappingURL=chunk-4Q356635.js.map
|
|
@@ -0,0 +1 @@
|
|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,KAAiB,GAAA,CAAI,GAAA,CAAI,EAAE,CAAA,GAAM,IAAA,CAAK,GAAA,CAAI,EAAE,CAAA,CAAG,WAAA,IAAe,EAAC,GAAuC,MAAA;AAAA,IACxH,GAAA,EAAK,MAAA,CAAO,MAAA,CAAO,OAAA,CAAQ,GAAG,CAAC,CAAA;AAAA,IAC/B,QAAA,EAAU,MAAA,CAAO,MAAA,CAAO,OAAA,CAAQ,QAAQ,CAAC,CAAA;AAAA,IACzC,MAAA,EAAQ,MAAA,CAAO,MAAA,CAAO,MAAM,CAAA;AAAA,IAC5B,KAAA,EAAO,MAAA,CAAO,MAAA,CAAO,KAAK,CAAA;AAAA,IAC1B,UAAA,EAAY,MAAA,CAAO,MAAA,CAAO,UAAU,CAAA;AAAA,IACpC,MAAA,EAAQ,MAAA,CAAO,MAAA,CAAO,MAAM,CAAA;AAAA,IAC5B,OAAA,EAAS,MAAA,CAAO,MAAA,CAAO,OAAO,CAAA;AAAA,IAC9B,OAAA,EAAS,MAAA,CAAO,MAAA,CAAO,OAAO;AAAA,GAC/B,CAAA;AACH","file":"chunk-4Q356635.js","sourcesContent":["/**\n * Blocks: a feature an app adds whole (account, push, observability, support,\n * updates), declared once with what it needs and what it contributes. The app\n * shell, the navigation tree and Settings consume contributions by FeatureId;\n * the app still owns where they go.\n *\n * Platform-neutral and free of zod, so it ships to phones:\n * `@marktiderman/genesis-features/blocks` (also re-exported from the root).\n */\nimport { cycleProblems, dependencyOrder, requirementProblem } from \"./graph\";\nimport { FEATURE_PLATFORMS, type FeaturePlatform } from \"./platforms\";\n\n/**\n * A navigation entry a block offers. The app's nav tree places it (by the\n * block's FeatureId and this id); a block never decides where it goes.\n * `id`, `label` and `path` match genesis-core's `NavigationNode`.\n *\n * @stability Beta\n */\nexport interface BlockNavItem {\n /** Unique across every enabled block. */\n id: string;\n label: string;\n path: string;\n /** An icon name the app's icon set knows. */\n icon?: string;\n /** Lower first. Default 0. */\n order?: number;\n}\n\n/**\n * A Settings row a block offers, placed in the section with id `section`\n * (`\"account\"`, `\"about\"`, or one of the app's own; an unknown id becomes a\n * new section at the end).\n *\n * @stability Beta\n */\nexport interface BlockSettingsRow {\n /** Unique across every enabled block. */\n id: string;\n section: string;\n title: string;\n subtitle?: string;\n /**\n * A hook giving a subtitle that changes (a version, a count). It is called\n * on every render of the Settings screen, in block order, so the set of\n * blocks must not change while the app runs (shells read them once).\n */\n useSubtitle?: () => string | null | undefined;\n /** Where tapping the row goes, as a path. */\n href?: string;\n /** Lower first within its section. Default 0. */\n order?: number;\n testID?: string;\n}\n\n/**\n * A screen a block's feature needs the app to route to. On file-based\n * routers the app owns the route file; this is the declaration a check (or\n * a deep-link allowlist) reads.\n *\n * @stability Beta\n */\nexport interface BlockRoute {\n path: string;\n /** What the screen is for, in a few words. */\n description?: string;\n /** `true` when only a signed-in person can open it. */\n signedIn?: boolean;\n}\n\n/**\n * A SQL migration a block needs, shipped in a package: copy it into the\n * app's `supabase/migrations/` under a timestamped name.\n *\n * @stability Beta\n */\nexport interface BlockMigration {\n /** The npm package that ships it, e.g. `@marktiderman/genesis-supabase`. */\n package: string;\n /** Its path in the package, e.g. `migrations/0002_genesis_app_release_policy.sql`. */\n file: string;\n /** Its pgTAP test in the package, if any. */\n test?: string;\n}\n\n/**\n * One kind of data a block collects, for the App Store privacy label and the\n * Play data safety form.\n *\n * @stability Beta\n */\nexport interface BlockDataUse {\n /** What, in the stores' words: `\"email address\"`, `\"user id\"`, `\"crash data\"`. */\n type: string;\n /** Why: `\"app functionality\"`, `\"analytics\"`, … */\n purposes: readonly string[];\n /** Tied to the person's identity. */\n linked: boolean;\n /** Used to track the person across other companies' apps. */\n tracking: boolean;\n}\n\n/** What a block means for privacy. @stability Beta */\nexport interface BlockPrivacy {\n collects?: readonly BlockDataUse[];\n /** Anything a reviewer or a privacy policy should say, one sentence each. */\n notes?: readonly string[];\n}\n\n/**\n * What a block adds to an app. Every key is optional. `S` is what a slot is\n * filled with on the consuming platform (a React component on native and web).\n *\n * @stability Beta\n */\nexport interface BlockContributions<S = unknown> {\n nav?: readonly BlockNavItem[];\n settings?: readonly BlockSettingsRow[];\n routes?: readonly BlockRoute[];\n /**\n * Fills for the host shell's slots, by slot name (e.g. `fatal` on\n * `GenesisNativeApp`). The app's own `slots` always win over a block's.\n */\n slots?: Readonly<Record<string, S>>;\n migrations?: readonly BlockMigration[];\n /** Agent skills that come with it: repo or package paths to a `SKILL.md`. */\n skills?: readonly string[];\n privacy?: BlockPrivacy;\n}\n\n/**\n * One block. `id` is the block's FeatureId: the same id as its entry in the\n * feature registry.\n *\n * @stability Beta\n */\nexport interface BlockDef<Id extends string = string, S = unknown> {\n readonly id: Id;\n /**\n * What must be on with it: other blocks' ids, or features the app owns that\n * aren't blocks. A requirement that is a block must be enabled (and on this\n * platform); one that isn't a block must be listed in `enabled`. A\n * requirement that is neither is an error, so a forgotten block is loud.\n */\n readonly requires?: readonly string[];\n readonly contributes?: BlockContributions<S>;\n /** Where it runs. Default every platform. */\n readonly platforms?: readonly FeaturePlatform[];\n}\n\n/** Thrown by {@link defineBlock} and {@link resolveBlocks}; lists every problem at once. @stability Beta */\nexport class BlockError extends Error {\n constructor(readonly problems: string[]) {\n super(`Invalid blocks:\\n${problems.map((p) => ` - ${p}`).join(\"\\n\")}`);\n this.name = \"BlockError\";\n }\n}\n\n// The feature registry's id rule (model.ts), repeated so this file stays free of zod.\nconst ID = /^[a-z][a-z0-9]*(?:[-_.][a-z0-9]+)*$/;\n\nconst CONTRIBUTION_KEYS = [\"nav\", \"settings\", \"routes\", \"slots\", \"migrations\", \"skills\", \"privacy\"] as const;\n\nfunction duplicates(values: readonly string[]): string[] {\n const seen = new Set<string>();\n const dup = new Set<string>();\n for (const v of values) (seen.has(v) ? dup : seen).add(v);\n return [...dup];\n}\n\nfunction blockProblems(block: BlockDef<string, unknown>): string[] {\n const { id } = block;\n const problems: string[] = [];\n if (typeof id !== \"string\" || !ID.test(id)) problems.push(`${String(id)}: a block id is a feature id: lowercase letters and digits, joined by -, _ or .`);\n for (const req of block.requires ?? []) {\n if (req === id) problems.push(`${id}.requires: a block can't require itself`);\n else if (!ID.test(req)) problems.push(`${id}.requires: \"${req}\" is not a feature id`);\n }\n for (const p of block.platforms ?? []) {\n if (!(FEATURE_PLATFORMS as readonly string[]).includes(p)) problems.push(`${id}.platforms: \"${p}\" is not one of ${FEATURE_PLATFORMS.join(\", \")}`);\n }\n if (block.platforms && block.platforms.length === 0) problems.push(`${id}.platforms: an empty list runs nowhere; leave it out for every platform`);\n const c = block.contributes ?? {};\n for (const key of Object.keys(c)) {\n if (!(CONTRIBUTION_KEYS as readonly string[]).includes(key)) problems.push(`${id}.contributes.${key}: not a contribution (${CONTRIBUTION_KEYS.join(\", \")})`);\n }\n for (const d of duplicates((c.nav ?? []).map((n) => n.id))) problems.push(`${id}.contributes.nav: \"${d}\" appears twice`);\n for (const d of duplicates((c.settings ?? []).map((r) => r.id))) problems.push(`${id}.contributes.settings: \"${d}\" appears twice`);\n for (const d of duplicates((c.routes ?? []).map((r) => r.path))) problems.push(`${id}.contributes.routes: \"${d}\" appears twice`);\n for (const n of c.nav ?? []) if (!n.id || !n.label || !n.path) problems.push(`${id}.contributes.nav: every entry needs an id, a label and a path`);\n for (const r of c.settings ?? []) if (!r.id || !r.section || !r.title) problems.push(`${id}.contributes.settings: every row needs an id, a section and a title`);\n for (const m of c.migrations ?? []) if (!m.package || !m.file) problems.push(`${id}.contributes.migrations: every migration needs a package and a file`);\n return problems;\n}\n\n/**\n * Declare a block. Validates it (id, requirements, platforms, contribution\n * keys and duplicate ids within the block) and returns it frozen, so a\n * typo fails where the block is written rather than where it is used:\n *\n * ```ts\n * export const supportBlock = defineBlock({\n * id: \"support\",\n * requires: [\"account\"],\n * platforms: [\"web\", \"native\"],\n * contributes: {\n * settings: [{ id: \"contact-support\", section: \"about\", title: \"Contact support\", href: \"/support\" }],\n * routes: [{ path: \"/support\", signedIn: true }],\n * migrations: [{ package: \"@acme/support\", file: \"migrations/0001_support.sql\" }],\n * },\n * });\n * ```\n *\n * To check `id` against the app's registry at compile time, give the\n * FeatureId: `defineBlock<FeatureId>({ … })`. `S` is what slots are filled\n * with, inferred from `contributes.slots` (a component on native and web).\n *\n * @stability Beta\n */\nexport function defineBlock<const Id extends string, S = never>(block: BlockDef<Id, S>): BlockDef<Id, S> {\n const problems = blockProblems(block as BlockDef<string, unknown>);\n if (problems.length) throw new BlockError(problems);\n return Object.freeze(block);\n}\n\n/** Which blocks are on: ids, a predicate, or (left out) every block given. @stability Beta */\nexport type EnabledBlocks = Iterable<string> | ((id: string) => boolean);\n\n/** @stability Beta */\nexport interface ResolveBlocksOptions {\n /** Keep only blocks that run here. A required block that doesn't is a missing requirement. */\n platform?: FeaturePlatform;\n /**\n * The app's feature registry (`features` from `defineFeatures`): every block\n * id and requirement must be one of its ids.\n */\n features?: Readonly<Record<string, unknown>>;\n /**\n * A block whose requirement is off: `throw` (default: a set-up mistake, found\n * at launch) or `drop` it, and every block needing it, listing each in\n * `dropped` (for switches that change at run time, such as a tenant turning\n * a feature off).\n */\n missing?: \"throw\" | \"drop\";\n /**\n * The host's slot names (e.g. `GenesisNativeApp`'s). A block filling any\n * other slot is an error, so a typo doesn't fill nothing silently.\n */\n slots?: readonly string[];\n}\n\n/** A contribution with the FeatureId of the block it came from. @stability Beta */\nexport type Contributed<T, Id extends string = string> = T & { readonly feature: Id };\n\n/** @stability Beta */\nexport interface ResolvedBlocks<B extends BlockDef<string, unknown> = BlockDef> {\n /** The enabled blocks, in dependency order (a block after what it requires). */\n readonly blocks: readonly B[];\n readonly ids: ReadonlySet<B[\"id\"]>;\n has(id: string): boolean;\n /** One block's contributions, or `undefined` when it isn't on. */\n contributionsOf(id: B[\"id\"]): NonNullable<B[\"contributes\"]> | undefined;\n /** Nav entries by `order`, then block order. Place them in the app's tree by `feature` and `id`. */\n readonly nav: readonly Contributed<BlockNavItem, B[\"id\"]>[];\n /** Settings rows by `order`, then block order. */\n readonly settings: readonly Contributed<BlockSettingsRow, B[\"id\"]>[];\n readonly routes: readonly Contributed<BlockRoute, B[\"id\"]>[];\n /** Slot fills by slot name. Two blocks filling one slot is an error. */\n readonly slots: Readonly<Record<string, SlotOf<B>>>;\n readonly migrations: readonly Contributed<BlockMigration, B[\"id\"]>[];\n readonly skills: readonly Contributed<{ path: string }, B[\"id\"]>[];\n readonly privacy: readonly Contributed<BlockPrivacy, B[\"id\"]>[];\n /** With `missing: \"drop\"`: blocks left out, and the requirements that were off. */\n readonly dropped: readonly { id: B[\"id\"]; missing: readonly string[] }[];\n}\n\ntype SlotOf<B> = B extends BlockDef<string, infer S> ? S : never;\n\nfunction enabledPredicate(enabled: EnabledBlocks | undefined): ((id: string) => boolean) | undefined {\n if (enabled === undefined) return undefined;\n if (typeof enabled === \"function\") return enabled;\n const set = new Set(enabled);\n return (id) => set.has(id);\n}\n\nconst byOrder = <T extends { order?: number }>(items: { item: T; at: number }[]) =>\n items.sort((a, b) => (a.item.order ?? 0) - (b.item.order ?? 0) || a.at - b.at).map((x) => x.item);\n\n/**\n * The blocks that are on, checked and merged:\n *\n * - every block is valid ({@link defineBlock}'s checks, for blocks built by hand) and its id is unique;\n * - `requires` has no cycles, and with `features`, names real features;\n * - every enabled block's requirements are on (see {@link ResolveBlocksOptions.missing});\n * - no two enabled blocks contribute the same nav id, settings row id, route path or slot.\n *\n * `enabled` left out means every block given is on (and no app feature that\n * isn't a block). Throws a {@link BlockError} listing every problem at once.\n *\n * @stability Beta\n */\nexport function resolveBlocks<B extends BlockDef<string, unknown>>(\n blocks: readonly B[],\n enabled?: EnabledBlocks,\n options: ResolveBlocksOptions = {},\n): ResolvedBlocks<B> {\n const { platform, features, missing = \"throw\", slots: slotNames } = options;\n const problems: string[] = [];\n const byId = new Map<string, B>();\n for (const block of blocks) {\n problems.push(...blockProblems(block));\n if (byId.has(block.id)) problems.push(`${block.id}: two blocks have this id`);\n else byId.set(block.id, block);\n }\n const isFeature = features ? (id: string) => Object.hasOwn(features, id) : undefined;\n if (isFeature) for (const id of byId.keys()) if (!isFeature(id)) problems.push(`${id}: not a feature in the registry`);\n const graph = Object.fromEntries([...byId].map(([id, b]) => [id, { requires: b.requires }]));\n // Self-requirements are already reported by blockProblems; here, unknown ids and cycles.\n const known = { noun: \"block\", isKnown: (req: string) => byId.has(req) || !isFeature || isFeature(req) };\n for (const [id, node] of Object.entries(graph)) {\n for (const req of node.requires ?? []) {\n if (req !== id && requirementProblem(graph, id, req, known)) problems.push(`${id}.requires: \"${req}\" is neither a block nor a feature in the registry`);\n }\n }\n problems.push(...cycleProblems(graph));\n if (problems.length) throw new BlockError(problems);\n\n const isOn = enabledPredicate(enabled);\n const runsHere = (b: B) => !platform || !b.platforms || b.platforms.includes(platform);\n const active = new Set<string>();\n for (const [id, b] of byId) if ((!isOn || isOn(id)) && runsHere(b)) active.add(id);\n\n // In dependency order, so dropping a block also drops what needs it.\n const order = dependencyOrder(graph);\n const dropped: { id: B[\"id\"]; missing: string[] }[] = [];\n for (const id of order) {\n if (!active.has(id)) continue;\n const off = (byId.get(id)!.requires ?? []).filter((req) => {\n if (byId.has(req)) return !active.has(req);\n return !isOn || !isOn(req);\n });\n if (!off.length) continue;\n if (missing === \"drop\") {\n active.delete(id);\n dropped.push({ id, missing: off });\n continue;\n }\n for (const req of off) {\n const why = !byId.has(req)\n ? isOn\n ? \"is not enabled\"\n : \"is not one of the blocks given (pass it, or list the app feature in enabled)\"\n : !runsHere(byId.get(req)!)\n ? `doesn't run on ${platform}`\n : \"is off\";\n problems.push(`${id}.requires: \"${req}\" ${why}; turn it on or turn ${id} off`);\n }\n }\n if (problems.length) throw new BlockError(problems);\n\n const on = order.filter((id) => active.has(id)).map((id) => byId.get(id)!);\n const nav: { item: Contributed<BlockNavItem, B[\"id\"]>; at: number }[] = [];\n const settings: { item: Contributed<BlockSettingsRow, B[\"id\"]>; at: number }[] = [];\n const routes: Contributed<BlockRoute, B[\"id\"]>[] = [];\n const migrations: Contributed<BlockMigration, B[\"id\"]>[] = [];\n const skills: Contributed<{ path: string }, B[\"id\"]>[] = [];\n const privacy: Contributed<BlockPrivacy, B[\"id\"]>[] = [];\n const slots: Record<string, SlotOf<B>> = {};\n const owner = { nav: new Map<string, string>(), settings: new Map<string, string>(), routes: new Map<string, string>(), slots: new Map<string, string>() };\n const claim = (kind: keyof typeof owner, key: string, id: string, what: string) => {\n const first = owner[kind].get(key);\n if (first !== undefined) problems.push(`${id}.contributes.${kind}: ${what} \"${key}\" is already contributed by ${first}`);\n else owner[kind].set(key, id);\n return first === undefined;\n };\n on.forEach((block, at) => {\n const feature = block.id;\n const c = block.contributes ?? {};\n for (const n of c.nav ?? []) if (claim(\"nav\", n.id, feature, \"the nav entry\")) nav.push({ item: { ...n, feature }, at });\n for (const r of c.settings ?? []) if (claim(\"settings\", r.id, feature, \"the settings row\")) settings.push({ item: { ...r, feature }, at });\n for (const r of c.routes ?? []) if (claim(\"routes\", r.path, feature, \"the route\")) routes.push({ ...r, feature });\n for (const [name, fill] of Object.entries(c.slots ?? {})) {\n if (slotNames && !slotNames.includes(name)) {\n problems.push(`${feature}.contributes.slots: \"${name}\" is not a slot here (${slotNames.join(\", \")})`);\n continue;\n }\n if (claim(\"slots\", name, feature, \"the slot\")) slots[name] = fill as SlotOf<B>;\n }\n for (const m of c.migrations ?? []) migrations.push({ ...m, feature });\n for (const path of c.skills ?? []) skills.push({ path, feature });\n if (c.privacy) privacy.push({ ...c.privacy, feature });\n });\n if (problems.length) throw new BlockError(problems);\n\n const ids = new Set(on.map((b) => b.id)) as ReadonlySet<B[\"id\"]>;\n return Object.freeze({\n blocks: Object.freeze(on),\n ids,\n has: (id: string) => ids.has(id as B[\"id\"]),\n contributionsOf: (id: B[\"id\"]) => (ids.has(id) ? ((byId.get(id)!.contributes ?? {}) as NonNullable<B[\"contributes\"]>) : undefined),\n nav: Object.freeze(byOrder(nav)),\n settings: Object.freeze(byOrder(settings)),\n routes: Object.freeze(routes),\n slots: Object.freeze(slots),\n migrations: Object.freeze(migrations),\n skills: Object.freeze(skills),\n privacy: Object.freeze(privacy),\n dropped: Object.freeze(dropped),\n });\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/platforms.ts"],"names":[],"mappings":";AAKO,IAAM,iBAAA,GAAoB,CAAC,KAAA,EAAO,QAAA,EAAU,UAAU,KAAK","file":"chunk-B6WRD3WF.js","sourcesContent":["/**\n * Where a feature runs. `server` covers Node, edge functions and the database.\n *\n * @stability Beta\n */\nexport const FEATURE_PLATFORMS = [\"web\", \"native\", \"server\", \"cli\"] as const;\n\n/** @stability Beta */\nexport type FeaturePlatform = (typeof FEATURE_PLATFORMS)[number];\n"]}
|
|
@@ -1,10 +1,13 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { requirementProblem, cycleProblems } from './chunk-VYUX7VAX.js';
|
|
2
|
+
import { FEATURE_PLATFORMS } from './chunk-B6WRD3WF.js';
|
|
3
|
+
import { statusOn } from './chunk-OW46SL2G.js';
|
|
2
4
|
import { z } from 'zod';
|
|
3
5
|
|
|
6
|
+
// src/types.ts
|
|
4
7
|
var FEATURE_STATUSES = ["idea", "planned", "building", "beta", "live", "deprecated", "retired"];
|
|
8
|
+
var FLAG_KINDS = ["release", "experiment", "ops", "permission"];
|
|
5
9
|
var FEATURE_HORIZONS = ["now", "next", "later"];
|
|
6
10
|
var FEATURE_LAYERS = ["token", "primitive", "pattern", "layout", "hook", "provider", "block", "service", "tool"];
|
|
7
|
-
var FLAG_KINDS = ["release", "experiment", "ops", "permission"];
|
|
8
11
|
var ID = /^[a-z][a-z0-9]*(?:[-_.][a-z0-9]+)*$/;
|
|
9
12
|
var DAY = /^\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])$/;
|
|
10
13
|
var MONTH_OR_DAY = /^\d{4}-(0[1-9]|1[0-2])(-(0[1-9]|[12]\d|3[01]))?$/;
|
|
@@ -176,11 +179,6 @@ function toRecords(features, flags) {
|
|
|
176
179
|
flags: flagsForFeature(flags, id)
|
|
177
180
|
}));
|
|
178
181
|
}
|
|
179
|
-
function statusOn(def, platform) {
|
|
180
|
-
if (def.platforms) return def.platforms[platform];
|
|
181
|
-
const apps = def.apps.map((a) => a === "node" ? "server" : a);
|
|
182
|
-
return apps.includes(platform) ? def.status : void 0;
|
|
183
|
-
}
|
|
184
182
|
function findFeatures(features, term, flags, options = {}) {
|
|
185
183
|
const needle = term.trim().toLowerCase();
|
|
186
184
|
const filtered = Boolean(options.platform || options.layer || options.status);
|
|
@@ -375,6 +373,6 @@ description: Find, add, change and retire this repo's features in ${source}, and
|
|
|
375
373
|
`;
|
|
376
374
|
}
|
|
377
375
|
|
|
378
|
-
export { AGENTS_BLOCK_END, AGENTS_BLOCK_START, BrokenBlockError, FEATURE_HORIZONS, FEATURE_LAYERS, FEATURE_STATUSES, FLAG_KINDS, FeatureRegistryError, MARKETING_BLOCK_END, MARKETING_BLOCK_START, OPENFEATURE_MANIFEST_SCHEMA, defineFeatures, defineFlags, expiredFlags, featureSchema, findFeatures, flagSchema, flagsForFeature, marketingRecords, readAgentsBlock, readBlock, replaceAgentsBlock, replaceBlock,
|
|
379
|
-
//# sourceMappingURL=chunk-
|
|
380
|
-
//# sourceMappingURL=chunk-
|
|
376
|
+
export { AGENTS_BLOCK_END, AGENTS_BLOCK_START, BrokenBlockError, FEATURE_HORIZONS, FEATURE_LAYERS, FEATURE_STATUSES, FLAG_KINDS, FeatureRegistryError, MARKETING_BLOCK_END, MARKETING_BLOCK_START, OPENFEATURE_MANIFEST_SCHEMA, defineFeatures, defineFlags, expiredFlags, featureSchema, findFeatures, flagSchema, flagsForFeature, marketingRecords, readAgentsBlock, readBlock, replaceAgentsBlock, replaceBlock, toAgentsMarkdown, toJson, toMarketingMarkdown, toOpenFeatureManifest, toRecords, toSkillMarkdown };
|
|
377
|
+
//# sourceMappingURL=chunk-JMXJZT6O.js.map
|
|
378
|
+
//# sourceMappingURL=chunk-JMXJZT6O.js.map
|
|
@@ -0,0 +1 @@
|
|
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AAA,kEAAA,EAE2D,MAAM,CAAA;AAAA;;AAAA,oBAAA,EAGpD,OAAO,CAAA;;AAAA;;AAAA,EAAA,EAIzB,MAAM,CAAA;AAAA,EAAA,EACN,OAAO,CAAA,qCAAA,EAAwC,OAAA,CAAQ,IAAA,CAAK,IAAI,CAAC,CAAA;;AAAA;AAAA,IAAA,EAG/D,OAAO,CAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AAAA;AAAA,qBAAA,EAQU,MAAM,CAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,SAAA,EAkBlB,OAAO,CAAA;AAAA;;AAAA;AAAA;AAAA;AAAA;AAAA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,SAAA,EAcP,OAAO,kBAAkB,OAAO,CAAA;AAAA,CAAA;AAE3C","file":"chunk-JMXJZT6O.js","sourcesContent":["/**\n * The registry's plain types, with no zod: shared by the model and the zod-free\n * gate so `/gate` never pulls zod in, even in its type declarations.\n */\n\n/**\n * Where a feature is in its life. The order is the board's column order.\n * `idea` is captured but not agreed: it is in the list so `find` turns it up\n * before someone builds the same thing twice.\n *\n * @stability Beta\n */\nexport const FEATURE_STATUSES = [\"idea\", \"planned\", \"building\", \"beta\", \"live\", \"deprecated\", \"retired\"] as const;\n\n/** @stability Beta */\nexport type FeatureStatus = (typeof FEATURE_STATUSES)[number];\n\n/**\n * Who gets a feature: everyone, or one paid plan. The feature id doubles as\n * the billing entitlement's lookup key (a Stripe `lookup_key`).\n *\n * @stability Beta\n */\nexport type FeatureAccess = \"all\" | { plan: string };\n\n/**\n * Why a flag exists. `release` and `experiment` flags need `expires`, `ops`\n * flags need a `runbook`, and `permission` flags fail `check`: paid access\n * belongs in entitlements (`access`), not flags.\n *\n * @stability Beta\n */\nexport const FLAG_KINDS = [\"release\", \"experiment\", \"ops\", \"permission\"] as const;\n\n/** @stability Beta */\nexport type FlagKind = (typeof FLAG_KINDS)[number];\n\n/** A flag's default: anything an OpenFeature flag can hold. */\nexport type FlagValue = boolean | string | number | { readonly [key: string]: unknown };\n\n","import { z } from \"zod\";\nimport { cycleProblems, requirementProblem } from \"./graph\";\nimport { FEATURE_PLATFORMS, type FeaturePlatform } from \"./platforms\";\nimport { statusOn } from \"./status\";\nimport { FEATURE_STATUSES, FLAG_KINDS, type FeatureAccess, type FeatureStatus, type FlagKind, type FlagValue } from \"./types\";\n\n// The plain types live in their own zod-free file, shared with the gate.\nexport { FEATURE_STATUSES, FLAG_KINDS, type FeatureAccess, type FeatureStatus, type FlagKind, type FlagValue };\n\n\n\n/**\n * When a planned or building feature is due, without dates: the roadmap's\n * three columns.\n *\n * @stability Beta\n */\nexport const FEATURE_HORIZONS = [\"now\", \"next\", \"later\"] as const;\n\n/** @stability Beta */\nexport type FeatureHorizon = (typeof FEATURE_HORIZONS)[number];\n\n/**\n * Who may see a feature listed. `public` features with a `tagline` go on\n * marketing output; `client:<name>` is one customer's own feature.\n *\n * @stability Beta\n */\nexport type FeatureVisibility = \"internal\" | \"customer\" | \"public\" | `client:${string}`;\n\n\n/**\n * Pointers from a feature to where it lives. `code` paths are relative to the\n * repository root and `genesis features check` fails when one doesn't exist.\n *\n * @stability Beta\n */\nexport interface FeatureLinks {\n /** Files or folders that implement the feature, relative to the repo root. */\n code?: readonly string[];\n /** Docs: a repo-relative path or a URL. */\n docs?: readonly string[];\n /** The tracking issue: a URL, `#123` or `owner/repo#123`. */\n issue?: string;\n}\n\n// Where a feature runs: in its own file so the zod-free blocks entry shares it.\nexport { FEATURE_PLATFORMS, type FeaturePlatform };\n\n/**\n * What kind of thing a feature is, from smallest to largest, so an agent\n * looking for a building block can tell a primitive from a whole block:\n * `token`, `primitive` (one component), `pattern` (a composed component with\n * slots), `layout` (a page or screen shell), `hook`, `provider` (data or\n * context), `block` (a feature an app adds whole: UI, data and server),\n * `service` (server code) and `tool` (CLI, CI, devtools).\n *\n * @stability Beta\n */\nexport const FEATURE_LAYERS = [\"token\", \"primitive\", \"pattern\", \"layout\", \"hook\", \"provider\", \"block\", \"service\", \"tool\"] as const;\n\n/** @stability Beta */\nexport type FeatureLayer = (typeof FEATURE_LAYERS)[number];\n\n/** A picture or video for a marketing page. @stability Beta */\nexport interface FeatureMedia {\n image?: string;\n video?: string;\n alt: string;\n}\n\n/**\n * One feature. The object key in {@link defineFeatures} is its id: permanent,\n * never reused, and renamed only through `aliases`.\n *\n * @stability Beta\n */\nexport interface FeatureDef {\n name: string;\n /** One sentence for the team: what it does for whom. */\n summary: string;\n status: FeatureStatus;\n /** Who answers for it: a person, a team or an agent session's name. */\n owner: string;\n /** Which of the repo's apps or surfaces carry it, e.g. `[\"web\"]`. */\n apps: readonly string[];\n /** Who it is for, e.g. `[\"client\", \"coach\"]`. */\n audience: readonly string[];\n /** Roadmap column. Only on planned (required) or building features. */\n horizon?: FeatureHorizon;\n /** Default `customer`. */\n visibility?: FeatureVisibility;\n /** Default `all`. */\n access?: FeatureAccess;\n /** One testable sentence each. Required on beta and live features. */\n acceptance?: readonly string[];\n /** Ids this feature had before. An old id can't be reused. */\n aliases?: readonly string[];\n /** When someone last checked this entry against the product: `YYYY-MM-DD`. */\n reviewedAt?: string;\n /** Who is building it right now. Only on building features. */\n claimedBy?: string;\n /** When it first shipped or started: `YYYY-MM-DD` or `YYYY-MM`. */\n since?: string;\n links?: FeatureLinks;\n /** One line of benefit, for customers. Needed for marketing output. */\n tagline?: string;\n /** A group on a marketing page. */\n category?: string;\n media?: FeatureMedia;\n /** A hero item on a marketing page. */\n highlight?: boolean;\n /** What kind of thing it is. */\n layer?: FeatureLayer;\n /**\n * Status per platform, when it differs from `status`: `{ web: \"live\", native: \"planned\" }`.\n * A platform left out doesn't have it.\n */\n platforms?: Partial<Record<FeaturePlatform, FeatureStatus>>;\n /** What to import, per platform, e.g. `{ web: \"@marktiderman/genesis-ui/settings-row\" }`. */\n entry?: Partial<Record<FeaturePlatform, string>>;\n /** Other words people use for it, so `find` matches them: `[\"chat\", \"dm\"]`. */\n keywords?: readonly string[];\n /** The feature this one is a variant of. */\n extends?: string;\n /** Features it needs. A beta or live feature can't require an idea, a planned or a retired one. */\n requires?: readonly string[];\n /** What it adds to an app, e.g. `[\"nav item\", \"settings row\", \"table: threads\"]`. */\n contributes?: readonly string[];\n /** The parts an app can replace or drop through `slots`. */\n slots?: readonly string[];\n}\n\n\n\n\n/**\n * One flag. `feature` names the {@link FeatureDef} it belongs to; a feature's\n * flags are found by reverse lookup ({@link flagsForFeature}) and never\n * written on the feature itself.\n *\n * @stability Beta\n */\nexport interface FlagDef<F extends string = string> {\n feature: F;\n kind: FlagKind;\n owner: string;\n default: FlagValue;\n /** Where it can be set, e.g. `[\"platform\", \"practice\", \"user\"]`. */\n scopes: readonly string[];\n description?: string;\n /** `YYYY-MM-DD`. Required on release and experiment flags; `check` fails after it. */\n expires?: string;\n /** What to do when you flip it: a repo path or a URL. Required on ops flags. */\n runbook?: string;\n /**\n * Flags are grouped by feature: one flag per feature by default. Every flag\n * after a feature's first must say why it is a separate flag.\n */\n splitReason?: string;\n}\n\n/** The id type of a features object: `type FeatureId = FeatureIdOf<typeof features>`. */\nexport type FeatureIdOf<T> = Extract<keyof T, string>;\n\n/** A features object as {@link defineFeatures} returns it. */\nexport type Features<Id extends string = string> = { readonly [K in Id]: FeatureDef };\n\n/** A flags object as {@link defineFlags} returns it. */\nexport type Flags<F extends string = string> = { readonly [name: string]: FlagDef<F> };\n\nconst ID = /^[a-z][a-z0-9]*(?:[-_.][a-z0-9]+)*$/;\nconst DAY = /^\\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\\d|3[01])$/;\nconst MONTH_OR_DAY = /^\\d{4}-(0[1-9]|1[0-2])(-(0[1-9]|[12]\\d|3[01]))?$/;\nconst URL_RE = /^https?:\\/\\/\\S+$/;\nconst ISSUE = /^(https?:\\/\\/\\S+|([\\w.-]+\\/[\\w.-]+)?#\\d+)$/;\n\nconst text = z.string().trim().min(1);\nconst day = z.string().regex(DAY, \"must be YYYY-MM-DD\");\n\n/** A repo-relative path that stays inside the repo. */\nconst repoPath = text.refine(\n (p) => !p.startsWith(\"/\") && !/^[a-z]:/i.test(p) && !p.split(/[\\\\/]/).includes(\"..\"),\n { message: \"must be a path relative to the repo root, without ..\" },\n);\nconst pathOrUrl = z.union([z.string().regex(URL_RE), repoPath]);\n\nconst linksSchema = z\n .object({\n code: z.array(repoPath).optional(),\n docs: z.array(pathOrUrl).optional(),\n issue: z.string().regex(ISSUE, \"must be a URL, #123 or owner/repo#123\").optional(),\n })\n .strict();\n\nconst visibilitySchema = z.union([\n z.enum([\"internal\", \"customer\", \"public\"]),\n z.string().regex(/^client:\\S+$/, \"must be internal, customer, public or client:<name>\"),\n]);\n\n/** `{ web?, native?, server?, cli? }`, each holding `value`. (Not `z.partialRecord`, which zod 3 lacks.) */\nconst perPlatform = <T extends z.ZodTypeAny>(value: T) =>\n z.object(Object.fromEntries(FEATURE_PLATFORMS.map((p) => [p, value.optional()])) as Record<FeaturePlatform, z.ZodOptional<T>>).strict();\n\n/** The Zod schema for one {@link FeatureDef}, field by field. Cross-field rules live in {@link featureProblems}. */\nexport const featureSchema = z\n .object({\n name: text,\n summary: text,\n status: z.enum(FEATURE_STATUSES),\n owner: text,\n apps: z.array(text).min(1),\n audience: z.array(text).min(1),\n horizon: z.enum(FEATURE_HORIZONS).optional(),\n visibility: visibilitySchema.optional(),\n access: z.union([z.literal(\"all\"), z.object({ plan: text }).strict()]).optional(),\n acceptance: z.array(text).optional(),\n aliases: z.array(z.string().regex(ID, \"must be a feature id\")).optional(),\n reviewedAt: day.optional(),\n claimedBy: text.optional(),\n since: z.string().regex(MONTH_OR_DAY, \"must be YYYY-MM-DD or YYYY-MM\").optional(),\n links: linksSchema.optional(),\n tagline: text.optional(),\n category: text.optional(),\n media: z\n .object({ image: pathOrUrl.optional(), video: pathOrUrl.optional(), alt: text })\n .strict()\n .optional(),\n highlight: z.boolean().optional(),\n layer: z.enum(FEATURE_LAYERS).optional(),\n platforms: perPlatform(z.enum(FEATURE_STATUSES)).optional(),\n entry: perPlatform(text).optional(),\n keywords: z.array(text).optional(),\n extends: z.string().regex(ID, \"must be a feature id\").optional(),\n requires: z.array(z.string().regex(ID, \"must be a feature id\")).optional(),\n contributes: z.array(text).optional(),\n slots: z.array(text).optional(),\n })\n .strict();\n\nconst flagValue: z.ZodType<FlagValue> = z.union([z.boolean(), z.string(), z.number(), z.record(z.string(), z.unknown())]);\n\n/** The Zod schema for one {@link FlagDef}. Cross-flag rules live in {@link defineFlags}. */\nexport const flagSchema = z\n .object({\n feature: text,\n kind: z.enum(FLAG_KINDS),\n owner: text,\n default: flagValue,\n scopes: z.array(text).min(1),\n description: text.optional(),\n expires: day.optional(),\n runbook: pathOrUrl.optional(),\n splitReason: text.optional(),\n })\n .strict();\n\n/** Thrown by {@link defineFeatures} and {@link defineFlags}; lists every problem at once. */\nexport class FeatureRegistryError extends Error {\n constructor(readonly problems: string[]) {\n super(`Invalid feature registry:\\n${problems.map((p) => ` - ${p}`).join(\"\\n\")}`);\n this.name = \"FeatureRegistryError\";\n }\n}\n\nfunction issues(prefix: string, error: z.ZodError): string[] {\n return error.issues.map((i) => `${[prefix, ...i.path].join(\".\")}: ${i.message}`);\n}\n\n/** The rules between one feature's fields, as problem strings. */\nfunction featureProblems(id: string, def: FeatureDef): string[] {\n const problems: string[] = [];\n const early = def.status === \"planned\" || def.status === \"building\";\n if (def.horizon && !early) problems.push(`${id}.horizon: only planned and building features are on the roadmap`);\n if (def.status === \"planned\" && !def.horizon) problems.push(`${id}.horizon: a planned feature needs now, next or later`);\n if ((def.status === \"beta\" || def.status === \"live\") && !def.acceptance?.length) {\n problems.push(`${id}.acceptance: a ${def.status} feature needs at least one testable sentence`);\n }\n if (def.claimedBy && def.status !== \"building\") problems.push(`${id}.claimedBy: only a building feature can be claimed`);\n if (def.media && !def.media.image && !def.media.video) problems.push(`${id}.media: needs an image or a video`);\n return problems;\n}\n\n/**\n * The one source of truth for a repo's features. Validates every entry and\n * returns the same object, so running code reads it directly and the key type\n * becomes the repo's `FeatureId`:\n *\n * ```ts\n * export const features = defineFeatures({\n * tasks: { name: \"Tasks\", summary: \"…\", status: \"live\", owner: \"mark\", apps: [\"web\"], audience: [\"client\"],\n * acceptance: [\"A client can tick off a task their coach added.\"] },\n * });\n * export type FeatureId = FeatureIdOf<typeof features>;\n * ```\n *\n * @stability Beta\n */\nexport function defineFeatures<const T extends Record<string, FeatureDef>>(features: T): T {\n const problems: string[] = [];\n const invalid = new Set<string>();\n const owners = new Map<string, string>();\n for (const [id, def] of Object.entries(features)) {\n if (!ID.test(id)) problems.push(`${id}: the id must be lowercase letters and digits, joined by -, _ or .`);\n const parsed = featureSchema.safeParse(def);\n if (!parsed.success) {\n problems.push(...issues(id, parsed.error));\n invalid.add(id);\n continue;\n }\n problems.push(...featureProblems(id, def));\n for (const name of [id, ...(def.aliases ?? [])]) {\n const other = owners.get(name);\n if (other !== undefined) problems.push(`${id}: \"${name}\" is already ${other === name ? \"a feature id\" : `an alias of ${other}`}`);\n else owners.set(name, id);\n }\n }\n problems.push(...relationProblems(features, invalid));\n if (problems.length) throw new FeatureRegistryError(problems);\n return Object.freeze(features);\n}\n\nconst UNSHIPPED: readonly FeatureStatus[] = [\"idea\", \"planned\", \"retired\"];\n\n/** `extends` and `requires` name real, distinct features; `requires` has no cycles; shipped features need shipped ones. */\nfunction relationProblems(features: Record<string, FeatureDef>, skip: ReadonlySet<string>): string[] {\n const problems: string[] = [];\n const has = (id: string) => Object.hasOwn(features, id);\n for (const [id, def] of Object.entries(features)) {\n // A schema-invalid entry is already reported; its fields can't be trusted here.\n if (skip.has(id)) continue;\n if (def.extends !== undefined) {\n if (def.extends === id) problems.push(`${id}.extends: a feature can't extend itself`);\n else if (!has(def.extends)) problems.push(`${id}.extends: \"${def.extends}\" is not a feature`);\n }\n // Itself and unknown ids: the same checks `resolveBlocks` runs on blocks.\n for (const req of def.requires ?? []) {\n const problem = requirementProblem(features, id, req, { noun: \"feature\" });\n if (problem) problems.push(problem);\n else if (!skip.has(req) && (def.status === \"beta\" || def.status === \"live\") && UNSHIPPED.includes(features[req]!.status)) {\n problems.push(`${id}.requires: a ${def.status} feature can't require \"${req}\", which is ${features[req]!.status}`);\n }\n }\n }\n problems.push(...cycleProblems(features, skip));\n return problems;\n}\n\n/**\n * Flags, each tied to a feature of `features`. An unknown `feature` is a type\n * error, and at runtime:\n * - every flag needs an `owner`, a `kind`, a `default` and its `scopes`;\n * - `release` and `experiment` flags need an `expires` date, `ops` flags a `runbook`;\n * - a feature's second (third, …) flag needs a `splitReason`, because flags\n * are grouped by feature unless there's a stated reason to split.\n *\n * `permission` flags are accepted here so the app still runs, and refused by\n * `genesis features check`.\n *\n * @stability Beta\n */\nexport function defineFlags<F extends string, const T extends Record<string, FlagDef<NoInfer<F>>>>(\n features: { readonly [K in F]: FeatureDef },\n flags: T,\n): T {\n const problems: string[] = [];\n const seen = new Map<string, string>();\n for (const [name, def] of Object.entries(flags)) {\n const parsed = flagSchema.safeParse(def);\n if (!parsed.success) {\n problems.push(...issues(name, parsed.error));\n continue;\n }\n const flag = parsed.data;\n if (!Object.hasOwn(features, flag.feature)) problems.push(`${name}.feature: \"${flag.feature}\" is not a feature`);\n if ((flag.kind === \"release\" || flag.kind === \"experiment\") && !flag.expires) {\n problems.push(`${name}.expires: a ${flag.kind} flag needs an expiry date`);\n }\n if (flag.kind === \"ops\" && !flag.runbook) problems.push(`${name}.runbook: an ops flag needs a runbook`);\n const first = seen.get(flag.feature);\n if (first === undefined) seen.set(flag.feature, name);\n else if (!flag.splitReason)\n problems.push(`${name}.splitReason: \"${flag.feature}\" already has the flag ${first}; say why this one is separate`);\n }\n if (problems.length) throw new FeatureRegistryError(problems);\n return Object.freeze(flags);\n}\n\n/**\n * The names of the flags that belong to a feature, in declaration order.\n *\n * @stability Beta\n */\nexport function flagsForFeature(flags: Flags | undefined, id: string): string[] {\n if (!flags) return [];\n return Object.entries(flags)\n .filter(([, flag]) => flag.feature === id)\n .map(([name]) => name);\n}\n\n/**\n * Flags whose `expires` date is before `today` (`YYYY-MM-DD`, default today in\n * UTC): remove the code path, then the flag.\n *\n * @stability Beta\n */\nexport function expiredFlags(flags: Flags | undefined, today = new Date().toISOString().slice(0, 10)): string[] {\n if (!flags) return [];\n return Object.entries(flags)\n .filter(([, flag]) => flag.expires !== undefined && flag.expires < today)\n .map(([name]) => name);\n}\n\n/**\n * A feature flattened for a list, a board or JSON: its id, its fields with\n * defaults filled in, and the names of its flags.\n *\n * @stability Beta\n */\nexport interface FeatureRecord extends FeatureDef {\n [key: string]: unknown;\n id: string;\n visibility: FeatureVisibility;\n access: FeatureAccess;\n flags: string[];\n}\n\n/**\n * Features as records, in declaration order, each with its flags attached.\n *\n * @stability Beta\n */\nexport function toRecords(features: Features, flags?: Flags): FeatureRecord[] {\n return Object.entries(features).map(([id, def]) => ({\n id,\n ...def,\n visibility: def.visibility ?? \"customer\",\n access: def.access ?? \"all\",\n flags: flagsForFeature(flags, id),\n }));\n}\n\n/**\n * Narrows {@link findFeatures}: only features on a platform (from `platforms`,\n * or `apps` when a feature has no `platforms`), of a layer, or in a status.\n *\n * @stability Beta\n */\nexport interface FindOptions {\n platform?: FeaturePlatform;\n layer?: FeatureLayer;\n status?: FeatureStatus;\n}\n\n// A feature's status on one platform: in its own zod-free file so the gate shares it.\nexport { statusOn };\n\n/**\n * Features matching `term` in their id, aliases, name, keywords, summary,\n * tagline, category, import paths, slots, contributions or code paths, best\n * matches (id, name and keywords) first. With `options` and an empty `term`,\n * every feature that passes the filters.\n *\n * @stability Beta\n */\nexport function findFeatures(features: Features, term: string, flags?: Flags, options: FindOptions = {}): FeatureRecord[] {\n const needle = term.trim().toLowerCase();\n const filtered = Boolean(options.platform || options.layer || options.status);\n if (!needle && !filtered) return [];\n const keep = (r: FeatureRecord) =>\n (!options.platform || statusOn(r, options.platform) !== undefined) &&\n (!options.layer || r.layer === options.layer) &&\n (!options.status || r.status === options.status);\n const score = (r: FeatureRecord) => {\n if (!needle) return 0;\n if (r.id === needle || r.aliases?.includes(needle)) return 0;\n if (r.id.includes(needle) || r.name.toLowerCase().includes(needle)) return 1;\n if (r.keywords?.some((k) => k.toLowerCase().includes(needle))) return 1;\n if (r.flags.some((f) => f.toLowerCase().includes(needle))) return 2;\n const rest = [\n r.summary,\n r.tagline,\n r.category,\n ...(r.links?.code ?? []),\n ...(r.aliases ?? []),\n ...Object.values(r.entry ?? {}),\n ...(r.slots ?? []),\n ...(r.contributes ?? []),\n ];\n return rest.some((v) => v?.toLowerCase().includes(needle)) ? 3 : -1;\n };\n return toRecords(features, flags)\n .filter(keep)\n .map((r) => [score(r), r] as const)\n .filter(([s]) => s >= 0)\n .sort((a, b) => a[0] - b[0])\n .map(([, r]) => r);\n}\n","import { FEATURE_STATUSES, toRecords, type FeatureRecord, type Features, type Flags, type FlagValue } from \"./model\";\n\n/** Marks the start of the generated block in AGENTS.md. */\nexport const AGENTS_BLOCK_START = \"<!-- genesis-features:start -->\";\n/** Marks the end of the generated block in AGENTS.md. */\nexport const AGENTS_BLOCK_END = \"<!-- genesis-features:end -->\";\n/** Marks the start of the generated marketing block (e.g. in README.md). */\nexport const MARKETING_BLOCK_START = \"<!-- genesis-features:marketing:start -->\";\n/** Marks the end of the generated marketing block. */\nexport const MARKETING_BLOCK_END = \"<!-- genesis-features:marketing:end -->\";\n\nexport interface GenerateOptions {\n /** The file the registry lives in, named in the \"generated from\" notes. Default `src/features.ts`. */\n source?: string;\n /** How agents run the CLI here, e.g. `genesis features` or `bun run features`. Default `genesis features`. */\n command?: string;\n /** Where the skill lives, named in the AGENTS.md pointer. Default `.claude/skills/features/SKILL.md`. */\n skill?: string | false;\n}\n\n/**\n * The registry as JSON, for tools that can't import TypeScript. Stable: no\n * timestamps, features in declaration order, so `check` can compare it. It is\n * also the record of every id ever used, which keeps ids permanent.\n *\n * @stability Beta\n */\nexport function toJson(features: Features, flags?: Flags, options: GenerateOptions = {}): string {\n const doc = {\n generatedFrom: options.source ?? \"src/features.ts\",\n features: toRecords(features, flags),\n flags: flags ?? {},\n };\n return `${JSON.stringify(doc, null, 2)}\\n`;\n}\n\nfunction flagType(value: FlagValue): string {\n if (typeof value === \"boolean\") return \"boolean\";\n if (typeof value === \"string\") return \"string\";\n if (typeof value === \"number\") return Number.isInteger(value) ? \"integer\" : \"float\";\n return \"object\";\n}\n\n/** The schema an OpenFeature CLI flag manifest points at. */\nexport const OPENFEATURE_MANIFEST_SCHEMA =\n \"https://raw.githubusercontent.com/open-feature/cli/refs/heads/main/schema/v0/flag-manifest.json\";\n\n/**\n * The flags as an OpenFeature CLI flag manifest (`flags.json`), so\n * `openfeature generate` can make typed accessors from the same registry.\n *\n * @stability Beta\n */\nexport function toOpenFeatureManifest(flags: Flags, features?: Features): string {\n const manifest = {\n $schema: OPENFEATURE_MANIFEST_SCHEMA,\n flags: Object.fromEntries(\n Object.entries(flags).map(([key, flag]) => [\n key,\n {\n flagType: flagType(flag.default),\n defaultValue: flag.default,\n description: flag.description ?? `${flag.kind} flag for ${features?.[flag.feature]?.name ?? flag.feature}`,\n },\n ]),\n ),\n };\n return `${JSON.stringify(manifest, null, 2)}\\n`;\n}\n\nconst cell = (value: string) => value.replace(/\\|/g, \"\\\\|\").replace(/\\r?\\n/g, \" \");\n\n/**\n * The marker-delimited block for AGENTS.md: deliberately short. It points\n * agents at `find` and the skill and gives counts, never the whole list, so\n * AGENTS.md stays small however many features there are.\n *\n * @stability Beta\n */\nexport function toAgentsMarkdown(features: Features, flags?: Flags, options: GenerateOptions = {}): string {\n const source = options.source ?? \"src/features.ts\";\n const command = options.command ?? \"genesis features\";\n const skill = options.skill === undefined ? \".claude/skills/features/SKILL.md\" : options.skill;\n const records = toRecords(features, flags);\n const counts = FEATURE_STATUSES.map((s) => [s, records.filter((r) => r.status === s).length] as const)\n .filter(([, n]) => n > 0)\n .map(([s, n]) => `${n} ${s}`)\n .join(\", \");\n const flagCount = flags ? Object.keys(flags).length : 0;\n const lines = [\n AGENTS_BLOCK_START,\n \"## Features\",\n \"\",\n `Every feature is in \\`${source}\\`: ${records.length} features (${counts})${flagCount ? `, ${flagCount} flag${flagCount === 1 ? \"\" : \"s\"}` : \"\"}.`,\n \"\",\n `- Before adding UI, routes or flags, run \\`${command} find <term>\\` to see whether a feature already covers it.`,\n `- New work starts as an entry in \\`${source}\\`; then run \\`${command} build\\`. \\`${command} check\\` runs in CI.`,\n ...(skill ? [`- Finding, adding and retiring features: \\`${skill}\\`.`] : []),\n \"\",\n `Generated by \\`${command} build\\`. Don't edit this block.`,\n AGENTS_BLOCK_END,\n ];\n return lines.join(\"\\n\");\n}\n\n/** The public, shipped features a marketing page shows: visibility public, a tagline, live or beta. */\nexport function marketingRecords(features: Features): FeatureRecord[] {\n return toRecords(features)\n .filter((r) => r.visibility === \"public\" && r.tagline && (r.status === \"live\" || r.status === \"beta\"))\n .sort((a, b) => Number(Boolean(b.highlight)) - Number(Boolean(a.highlight)));\n}\n\n/**\n * A benefit-led feature list for a README or a marketing page: public, shipped\n * features with a tagline, highlights first, grouped by category.\n *\n * @stability Beta\n */\nexport function toMarketingMarkdown(features: Features, options: { heading?: string; source?: string } = {}): string {\n const records = marketingRecords(features);\n const lines = [MARKETING_BLOCK_START, `## ${options.heading ?? \"Features\"}`, \"\"];\n const highlights = records.filter((r) => r.highlight);\n for (const r of highlights) lines.push(`- **${cell(r.name)}** — ${cell(r.tagline!)}`);\n if (highlights.length) lines.push(\"\");\n const categories = [...new Set(records.filter((r) => !r.highlight).map((r) => r.category ?? \"More\"))];\n for (const category of categories) {\n lines.push(`### ${category}`, \"\");\n for (const r of records.filter((x) => !x.highlight && (x.category ?? \"More\") === category)) {\n lines.push(`- **${cell(r.name)}**${r.status === \"beta\" ? \" (beta)\" : \"\"} — ${cell(r.tagline!)}`);\n }\n lines.push(\"\");\n }\n lines.push(`<sub>Generated from \\`${options.source ?? \"src/features.ts\"}\\`.</sub>`, MARKETING_BLOCK_END);\n return lines.join(\"\\n\");\n}\n\n/** Thrown when a generated block's markers are broken: one is missing, repeated or out of order. */\nexport class BrokenBlockError extends Error {\n constructor(start: string) {\n super(`The generated block's markers are broken (${start} and its end marker must each appear once, in order). Fix them by hand, or delete both and the block between them.`);\n this.name = \"BrokenBlockError\";\n }\n}\n\nconst count = (doc: string, marker: string) => doc.split(marker).length - 1;\n\n/**\n * The block between `start` and `end` inside `doc`, markers included, or null\n * when there is none. Throws {@link BrokenBlockError} when only one marker is\n * there, or either is repeated or out of order, rather than guess where the\n * block ends and wipe the text after it.\n */\nexport function readBlock(doc: string, start: string, end: string): string | null {\n const starts = count(doc, start);\n const ends = count(doc, end);\n if (starts === 0 && ends === 0) return null;\n const from = doc.indexOf(start);\n const to = doc.indexOf(end);\n if (starts !== 1 || ends !== 1 || to < from) throw new BrokenBlockError(start);\n return doc.slice(from, to + end.length);\n}\n\n/**\n * `doc` with the block between `start` and `end` replaced by `block`, or with\n * `block` appended when it has none yet. Everything outside the markers is\n * left as it was.\n */\nexport function replaceBlock(doc: string, block: string, start: string, end: string): string {\n const current = readBlock(doc, start, end);\n if (current !== null) return doc.replace(current, () => block);\n const base = doc.length === 0 || doc.endsWith(\"\\n\") ? doc : `${doc}\\n`;\n return `${base}${base.length ? \"\\n\" : \"\"}${block}\\n`;\n}\n\n/** The generated AGENTS.md block inside `doc`, or null. */\nexport const readAgentsBlock = (doc: string) => readBlock(doc, AGENTS_BLOCK_START, AGENTS_BLOCK_END);\n\n/**\n * `doc` with its generated AGENTS.md block replaced by `block`, or with\n * `block` appended when it has none yet.\n *\n * @stability Beta\n */\nexport const replaceAgentsBlock = (doc: string, block: string) => replaceBlock(doc, block, AGENTS_BLOCK_START, AGENTS_BLOCK_END);\n\n/**\n * The agent skill for working with the registry, written to\n * `.claude/skills/features/SKILL.md` by `genesis features build`. `outputs`\n * names what the build writes in this repo, so the skill never claims a file\n * the repo turned off.\n *\n * @stability Beta\n */\nexport function toSkillMarkdown(options: GenerateOptions & { outputs?: readonly string[] } = {}): string {\n const source = options.source ?? \"src/features.ts\";\n const command = options.command ?? \"genesis features\";\n const outputs = options.outputs ?? [\"the AGENTS.md block\", \"features.json\", \"this skill\"];\n return `---\nname: features\ndescription: Find, add, change and retire this repo's features in ${source}, and their flags. Use before adding UI, a route, a server function or a flag, when someone asks what the product does, or when shipping, deprecating or removing something.\n---\n\n<!-- Generated by \\`${command} build\\`. Don't edit; it is rewritten. -->\n\n# Features\n\n\\`${source}\\` is the one list of what this product does. Running code imports it, and\n\\`${command} build\\` generates the rest from it: ${outputs.join(\", \")}.\n\n## Find: reuse, then extend, then invent\n- \\`${command} find <term>\\` searches ids, aliases, names, keywords, summaries, import paths, slots\n and code paths; \\`--platform\\`, \\`--layer\\` and \\`--status\\` narrow it (an empty term lists all\n that pass). Run it before building anything new, in this order:\n 1. **Reuse**: a feature already does it. Use it as is, configured through its \\`slots\\`.\n 2. **Extend**: one is close. Fill a slot, or add a variant with \\`extends: <id>\\`.\n 3. **Invent**: nothing is close. Add an entry first (an \\`idea\\` is enough), then build.\n\n## Add\n1. Add an entry to \\`${source}\\`. The key is the id: lowercase, permanent, never reused.\n Required: \\`name\\`, \\`summary\\` (internal, one sentence), \\`status\\`, \\`owner\\`, \\`apps\\`, \\`audience\\`.\n - \\`idea\\`: captured, not agreed. Nothing else is required; add \\`keywords\\` so \\`find\\` matches it.\n - \\`planned\\` needs a \\`horizon\\` (now, next, later). No dates on the roadmap.\n - \\`building\\`: set \\`claimedBy\\` to your name or session while you work on it.\n - \\`beta\\` and \\`live\\` need \\`acceptance\\`: one testable sentence each. Tag the tests that prove\n them with \\`@feat:<id>\\` in a comment or the test name.\n - \\`links.code\\`: the files or folders that implement it. \\`check\\` fails when one is missing.\n - \\`visibility\\` (internal, customer, public, client:<name>) and \\`access\\` (\"all\" or { plan }).\n Paid access is \\`access\\`, never a flag. The id is the billing entitlement's lookup key.\n - For a public page: \\`tagline\\` (the customer benefit), \\`category\\`, \\`media\\`, \\`highlight\\`.\n - For reuse: \\`layer\\` (token, primitive, pattern, layout, hook, provider, block, service, tool),\n \\`platforms\\` (status per platform when it differs), \\`entry\\` (what to import, per platform),\n \\`keywords\\`, \\`slots\\`, \\`extends\\` (the feature this is a variant of), \\`requires\\` (a beta or\n live feature can't require an idea, a planned or a retired one) and \\`contributes\\`.\n2. Flags go in the flags registry with \\`feature: <id>\\`. One flag per feature; a second needs a\n \\`splitReason\\`. \\`release\\` and \\`experiment\\` flags need \\`expires\\`, \\`ops\\` flags a \\`runbook\\`.\n Read flags only through the typed accessor with a literal key, never a computed one.\n3. Run \\`${command} build\\` and commit what it writes. Tag the changeset (a \\`Features: <id>\\` line in\n its body) or the PR (a \\`feature:<id>\\` label).\n\n## Change\n- Move \\`status\\` as it ships: idea, planned, building, beta, live, deprecated, retired. \\`check\\` warns\n when an idea or a planned feature already has shipped work tagged with it (a changeset, or with \\`--prs\\` a merged PR).\n- Set \\`reviewedAt\\` (today) whenever you check an entry against the product; \\`check\\` warns after 90 days.\n- Rename by giving the feature a new id and putting the old one in \\`aliases\\`. Never delete an id.\n\n## Retire\n1. Remove the code first: the UI, routes, server functions and tests.\n2. Then remove its flags from the flags registry (the code that read them is gone, so \\`check\\`\n would flag them as unused).\n3. Set \\`status: \"retired\"\\`, keep the entry, and drop \\`links.code\\` paths that no longer exist.\n4. Run \\`${command} build\\` and \\`${command} check\\`.\n`;\n}\n"]}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { statusOn } from './chunk-OW46SL2G.js';
|
|
2
|
+
|
|
3
|
+
// src/gate.ts
|
|
4
|
+
var SHIPPED_STATUSES = [
|
|
5
|
+
"beta",
|
|
6
|
+
"live",
|
|
7
|
+
"deprecated"
|
|
8
|
+
];
|
|
9
|
+
var GATING_KINDS = ["release", "permission"];
|
|
10
|
+
function toTest(set, name) {
|
|
11
|
+
if (set === void 0) return () => false;
|
|
12
|
+
if (typeof set === "function") return set;
|
|
13
|
+
if (typeof set === "string")
|
|
14
|
+
throw new TypeError(
|
|
15
|
+
`GateContext.${name} must be a list, a Set or a function, not a string`
|
|
16
|
+
);
|
|
17
|
+
if (Array.isArray(set)) {
|
|
18
|
+
const ids = new Set(set);
|
|
19
|
+
return (id) => ids.has(id);
|
|
20
|
+
}
|
|
21
|
+
if (set instanceof Set) return (id) => set.has(id);
|
|
22
|
+
throw new TypeError(
|
|
23
|
+
`GateContext.${name} must be a list, a Set or a function`
|
|
24
|
+
);
|
|
25
|
+
}
|
|
26
|
+
function flagValue(flags, name) {
|
|
27
|
+
if (!flags) return void 0;
|
|
28
|
+
if (typeof flags === "function") return flags(name);
|
|
29
|
+
return Object.hasOwn(flags, name) ? flags[name] : void 0;
|
|
30
|
+
}
|
|
31
|
+
function prepare(registry, context) {
|
|
32
|
+
return {
|
|
33
|
+
registry,
|
|
34
|
+
context,
|
|
35
|
+
entitled: toTest(context.entitlements, "entitlements"),
|
|
36
|
+
off: toTest(context.off, "off")
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
function answer({ registry, context, entitled, off }, id) {
|
|
40
|
+
const def = Object.hasOwn(registry.features, id) ? registry.features[id] : void 0;
|
|
41
|
+
if (!def) return { on: false, reason: "unknown" };
|
|
42
|
+
if (!SHIPPED_STATUSES.includes(def.status))
|
|
43
|
+
return { on: false, reason: "status" };
|
|
44
|
+
const here = statusOn(def, context.platform);
|
|
45
|
+
if (!here || !SHIPPED_STATUSES.includes(here))
|
|
46
|
+
return { on: false, reason: "platform" };
|
|
47
|
+
if (off(id)) return { on: false, reason: "tenant" };
|
|
48
|
+
for (const [name, flag] of Object.entries(registry.flags ?? {})) {
|
|
49
|
+
if (flag.feature !== id || !GATING_KINDS.includes(flag.kind) || typeof flag.default !== "boolean")
|
|
50
|
+
continue;
|
|
51
|
+
if ((flagValue(context.flags, name) ?? flag.default) !== true)
|
|
52
|
+
return { on: false, reason: "flag", flag: name };
|
|
53
|
+
}
|
|
54
|
+
const access = def.access ?? "all";
|
|
55
|
+
if (access !== "all" && !entitled(id))
|
|
56
|
+
return { on: false, reason: "entitlement", unlock: { plan: access.plan } };
|
|
57
|
+
return { on: true };
|
|
58
|
+
}
|
|
59
|
+
function featureOn(registry, context, id) {
|
|
60
|
+
return answer(prepare(registry, context), id);
|
|
61
|
+
}
|
|
62
|
+
function gateSnapshot(registry, context, options = {}) {
|
|
63
|
+
const prepared = prepare(registry, context);
|
|
64
|
+
const ids = options.ids === void 0 ? Object.keys(registry.features).filter(
|
|
65
|
+
(id) => SHIPPED_STATUSES.includes(registry.features[id].status)
|
|
66
|
+
) : Array.from(options.ids);
|
|
67
|
+
const answers = {};
|
|
68
|
+
for (const id of ids) {
|
|
69
|
+
const { flag: _flag, ...rest } = answer(prepared, id);
|
|
70
|
+
answers[id] = rest;
|
|
71
|
+
}
|
|
72
|
+
return {
|
|
73
|
+
answers,
|
|
74
|
+
at: (options.at ?? /* @__PURE__ */ new Date()).toISOString(),
|
|
75
|
+
...options.version === void 0 ? {} : { version: options.version }
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
function isSnapshotStale(snapshot, maxAgeMs, now = /* @__PURE__ */ new Date()) {
|
|
79
|
+
const at = Date.parse(snapshot?.at);
|
|
80
|
+
return Number.isNaN(at) || Math.abs(now.getTime() - at) > maxAgeMs;
|
|
81
|
+
}
|
|
82
|
+
function fromSnapshot(snapshot, id) {
|
|
83
|
+
const answers = snapshot?.answers;
|
|
84
|
+
return (answers && Object.hasOwn(answers, id) ? answers[id] : void 0) ?? { on: false, reason: "unknown" };
|
|
85
|
+
}
|
|
86
|
+
var FeatureOff = class extends Error {
|
|
87
|
+
feature;
|
|
88
|
+
reason;
|
|
89
|
+
unlock;
|
|
90
|
+
constructor(feature, answer2) {
|
|
91
|
+
super(
|
|
92
|
+
answer2.reason === "entitlement" && answer2.unlock ? `${feature} needs the ${answer2.unlock.plan} plan` : `${feature} is off (${answer2.reason ?? "unknown"})`
|
|
93
|
+
);
|
|
94
|
+
this.name = "FeatureOff";
|
|
95
|
+
this.feature = feature;
|
|
96
|
+
this.reason = answer2.reason ?? "unknown";
|
|
97
|
+
if (answer2.unlock) this.unlock = answer2.unlock;
|
|
98
|
+
}
|
|
99
|
+
/** The HTTP status for this refusal: 402 when a plan unlocks it, else 403. */
|
|
100
|
+
get status() {
|
|
101
|
+
return this.reason === "entitlement" ? 402 : 403;
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
function requireFeature(registry, context, id) {
|
|
105
|
+
const result = featureOn(registry, context, id);
|
|
106
|
+
if (!result.on) throw new FeatureOff(id, result);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
export { FeatureOff, SHIPPED_STATUSES, featureOn, fromSnapshot, gateSnapshot, isSnapshotStale, requireFeature };
|
|
110
|
+
//# sourceMappingURL=chunk-LNVWVPWB.js.map
|
|
111
|
+
//# sourceMappingURL=chunk-LNVWVPWB.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/gate.ts"],"names":["answer"],"mappings":";;;AAmCO,IAAM,gBAAA,GAA6C;AAAA,EACxD,MAAA;AAAA,EACA,MAAA;AAAA,EACA;AACF;AA8EA,IAAM,YAAA,GAAoC,CAAC,SAAA,EAAW,YAAY,CAAA;AAIlE,SAAS,MAAA,CAAO,KAAwB,IAAA,EAAoB;AAC1D,EAAA,IAAI,GAAA,KAAQ,MAAA,EAAW,OAAO,MAAM,KAAA;AACpC,EAAA,IAAI,OAAO,GAAA,KAAQ,UAAA,EAAY,OAAO,GAAA;AACtC,EAAA,IAAI,OAAO,GAAA,KAAQ,QAAA;AACjB,IAAA,MAAM,IAAI,SAAA;AAAA,MACR,eAAe,IAAI,CAAA,kDAAA;AAAA,KACrB;AACF,EAAA,IAAI,KAAA,CAAM,OAAA,CAAQ,GAAG,CAAA,EAAG;AACtB,IAAA,MAAM,GAAA,GAAM,IAAI,GAAA,CAAY,GAAG,CAAA;AAC/B,IAAA,OAAO,CAAC,EAAA,KAAO,GAAA,CAAI,GAAA,CAAI,EAAE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er to \"is this feature on here?\" for UI, server\n * code, agents and (for status and entitlement) the database.\n *\n * Checks run in a fixed order and the first \"no\" wins:\n *\n * 1. status the feature has shipped (beta, live or deprecated)\n * 2. platform it has shipped on this platform\n * 3. tenant the tenant has not switched it off\n * 4. flag each of its boolean release or permission flags is true\n * 5. entitlement a paid feature (`access: { plan }`) has an active entitlement\n *\n * Entitlement is last on purpose: an \"upgrade to unlock\" answer is only given\n * when paying is the one thing missing, so an upsell never promises a feature\n * that a switch or a flag would still keep off.\n *\n * The registry comes from code (features.ts and flags.json). Everything that\n * changes at runtime (entitlements, switches, flag values) comes in through\n * {@link GateContext}, read once per request or session on the server. Role\n * and row rights are not the gate's business: \"may this person\" stays with\n * roles and row security.\n *\n * No zod, React, Node built-ins or DOM globals here: this file ships to\n * browsers, extension service workers, phones and edge functions.\n */\nimport type {\n FeatureAccess,\n FeatureStatus,\n FlagKind,\n FlagValue,\n} from \"./types\";\nimport { statusOn } from \"./status\";\nimport type { FeaturePlatform } from \"./platforms\";\n\n/** The statuses in which a feature is on. A deprecated feature still works until it is retired. @stability Beta */\nexport const SHIPPED_STATUSES: readonly FeatureStatus[] = [\n \"beta\",\n \"live\",\n \"deprecated\",\n];\n\n/**\n * Why a feature is off: the first check that said no. `unknown` is an id that\n * isn't in the registry (or not in a snapshot).\n *\n * @stability Beta\n */\nexport type GateReason =\n \"unknown\" | \"status\" | \"platform\" | \"tenant\" | \"flag\" | \"entitlement\";\n\n/**\n * The gate's answer for one feature. `unlock` is set when the reason is\n * `entitlement`: the plan that turns it on, so the UI can show an upgrade\n * instead of hiding the feature.\n *\n * @stability Beta\n */\nexport interface GateAnswer {\n on: boolean;\n reason?: GateReason;\n unlock?: { plan: string };\n /** The flag that turned it off, when the reason is `flag`. Server side only: snapshots leave it out. */\n flag?: string;\n}\n\n/** The fields of a feature the gate reads. A `FeatureDef` fits. @stability Beta */\nexport interface GateFeature {\n status: FeatureStatus;\n apps: readonly string[];\n platforms?: Partial<Record<FeaturePlatform, FeatureStatus>>;\n access?: FeatureAccess;\n}\n\n/** The fields of a flag the gate reads. A `FlagDef` fits. @stability Beta */\nexport interface GateFlag {\n feature: string;\n kind: FlagKind;\n default: FlagValue;\n}\n\n/** What the gate decides from: the registry, as code defines it. @stability Beta */\nexport interface GateRegistry {\n features: { readonly [id: string]: GateFeature };\n flags?: { readonly [name: string]: GateFlag };\n}\n\n/**\n * A set of ids: a list, a Set or a test. Not any iterable: an iterator would\n * be used up by the first feature asked, and a bare string would count as its\n * characters.\n *\n * @stability Beta\n */\nexport type IdSet =\n readonly string[] | ReadonlySet<string> | ((id: string) => boolean);\n\n/**\n * Where and for whom the gate is asked: the platform, plus the tenant's\n * runtime state. Leave out what the app doesn't have: no `entitlements` means\n * no paid feature is on, no `off` means no switch is off, no `flags` means\n * every flag has its default.\n *\n * @stability Beta\n */\nexport interface GateContext {\n platform: FeaturePlatform;\n /** Feature ids the tenant holds an active entitlement for. */\n entitlements?: IdSet;\n /** Feature ids the tenant switched off. */\n off?: IdSet;\n /** Flag values for this tenant, by flag name. A missing flag has its default. */\n flags?:\n | { readonly [name: string]: FlagValue | undefined }\n | ((name: string) => FlagValue | undefined);\n}\n\n/** Flag kinds that can turn a feature off. Experiments and ops flags pick a variant; they don't gate. */\nconst GATING_KINDS: readonly FlagKind[] = [\"release\", \"permission\"];\n\ntype Test = (id: string) => boolean;\n\nfunction toTest(set: IdSet | undefined, name: string): Test {\n if (set === undefined) return () => false;\n if (typeof set === \"function\") return set;\n if (typeof set === \"string\")\n throw new TypeError(\n `GateContext.${name} must be a list, a Set or a function, not a string`,\n );\n if (Array.isArray(set)) {\n const ids = new Set<string>(set);\n return (id) => ids.has(id);\n }\n if (set instanceof Set) return (id) => set.has(id);\n throw new TypeError(\n `GateContext.${name} must be a list, a Set or a function`,\n );\n}\n\nfunction flagValue(\n flags: GateContext[\"flags\"],\n name: string,\n): FlagValue | undefined {\n if (!flags) return undefined;\n if (typeof flags === \"function\") return flags(name);\n return Object.hasOwn(flags, name) ? flags[name] : undefined;\n}\n\ninterface Prepared {\n registry: GateRegistry;\n context: GateContext;\n entitled: Test;\n off: Test;\n}\n\nfunction prepare(registry: GateRegistry, context: GateContext): Prepared {\n return {\n registry,\n context,\n entitled: toTest(context.entitlements, \"entitlements\"),\n off: toTest(context.off, \"off\"),\n };\n}\n\nfunction answer(\n { registry, context, entitled, off }: Prepared,\n id: string,\n): GateAnswer {\n const def = Object.hasOwn(registry.features, id)\n ? registry.features[id]\n : undefined;\n if (!def) return { on: false, reason: \"unknown\" };\n if (!SHIPPED_STATUSES.includes(def.status))\n return { on: false, reason: \"status\" };\n const here = statusOn(def, context.platform);\n if (!here || !SHIPPED_STATUSES.includes(here))\n return { on: false, reason: \"platform\" };\n if (off(id)) return { on: false, reason: \"tenant\" };\n for (const [name, flag] of Object.entries(registry.flags ?? {})) {\n if (\n flag.feature !== id ||\n !GATING_KINDS.includes(flag.kind) ||\n typeof flag.default !== \"boolean\"\n )\n continue;\n // On only when exactly true: a malformed value (\"false\", 0, null) keeps the feature off.\n if ((flagValue(context.flags, name) ?? flag.default) !== true)\n return { on: false, reason: \"flag\", flag: name };\n }\n const access = def.access ?? \"all\";\n if (access !== \"all\" && !entitled(id))\n return { on: false, reason: \"entitlement\", unlock: { plan: access.plan } };\n return { on: true };\n}\n\n/**\n * Is feature `id` on for this context? Returns the first check that said no\n * as `reason`, and for a paid feature the plan that unlocks it. An unknown id\n * is off with reason `unknown`; it never throws for one.\n *\n * ```ts\n * const answer = featureOn({ features, flags }, { platform: \"web\", entitlements, off }, \"form-webhook-delivery\");\n * // { on: false, reason: \"entitlement\", unlock: { plan: \"pro\" } }\n * ```\n *\n * @stability Beta\n */\nexport function featureOn(\n registry: GateRegistry,\n context: GateContext,\n id: string,\n): GateAnswer {\n return answer(prepare(registry, context), id);\n}\n\n/**\n * Every shipped feature's answer for one context: what a server hands a\n * client, so the client never decides on its own. Plain JSON, safe to store\n * (an extension's session storage, a cache) and to compare by `version`.\n *\n * It lists only features that have shipped somewhere (beta, live or\n * deprecated) and leaves out flag names; anything missing reads as off.\n *\n * @stability Beta\n */\nexport interface GateSnapshot {\n /** The answers, by feature id. */\n readonly answers: { readonly [id: string]: GateAnswer };\n /** When the server made it (ISO 8601). Refresh after your own time limit. */\n readonly at: string;\n /** The registry version it was made from, when known (the build's version). */\n readonly version?: string | number;\n}\n\n/** @stability Beta */\nexport interface GateSnapshotOptions {\n /** Answer for these features only. */\n ids?: Iterable<string>;\n /** The registry version, carried into the snapshot. */\n version?: string | number;\n /** The time to stamp (default now). */\n at?: Date;\n}\n\n/** @stability Beta */\nexport function gateSnapshot(\n registry: GateRegistry,\n context: GateContext,\n options: GateSnapshotOptions = {},\n): GateSnapshot {\n const prepared = prepare(registry, context);\n const ids =\n options.ids === undefined\n ? Object.keys(registry.features).filter((id) =>\n SHIPPED_STATUSES.includes(registry.features[id]!.status),\n )\n : Array.from(options.ids);\n const answers: Record<string, GateAnswer> = {};\n for (const id of ids) {\n const { flag: _flag, ...rest } = answer(prepared, id);\n answers[id] = rest;\n }\n return {\n answers,\n at: (options.at ?? new Date()).toISOString(),\n ...(options.version === undefined ? {} : { version: options.version }),\n };\n}\n\n/**\n * Whether a snapshot is older than `maxAgeMs`: refresh it then. A client\n * (an extension worker, a tab left open) keeps a snapshot, replaces it when it\n * is stale, after sign-in or a tenant switch, and right after a refusal.\n *\n * @stability Beta\n */\nexport function isSnapshotStale(snapshot: GateSnapshot, maxAgeMs: number, now: Date = new Date()): boolean {\n const at = Date.parse(snapshot?.at);\n // Too old, unreadable, or dated in the future (a wrong clock or a forged copy): refresh.\n return Number.isNaN(at) || Math.abs(now.getTime() - at) > maxAgeMs;\n}\n\n/** One feature's answer from a snapshot. An id missing from it is off, as an unknown feature. @stability Beta */\nexport function fromSnapshot(snapshot: GateSnapshot, id: string): GateAnswer {\n // A stored snapshot may be from an older shape, or damaged: missing answers mean off.\n const answers: GateSnapshot[\"answers\"] | undefined = snapshot?.answers;\n return (answers && Object.hasOwn(answers, id) ? answers[id] : undefined) ?? { on: false, reason: \"unknown\" };\n}\n\n/**\n * Thrown by {@link requireFeature} when a feature is off. Servers map it to a\n * refusal that carries the reason (HTTP 403, or 402 for `entitlement`).\n *\n * @stability Beta\n */\nexport class FeatureOff extends Error {\n readonly feature: string;\n readonly reason: GateReason;\n readonly unlock?: { plan: string };\n constructor(feature: string, answer: GateAnswer) {\n super(\n answer.reason === \"entitlement\" && answer.unlock\n ? `${feature} needs the ${answer.unlock.plan} plan`\n : `${feature} is off (${answer.reason ?? \"unknown\"})`,\n );\n this.name = \"FeatureOff\";\n this.feature = feature;\n this.reason = answer.reason ?? \"unknown\";\n if (answer.unlock) this.unlock = answer.unlock;\n }\n\n /** The HTTP status for this refusal: 402 when a plan unlocks it, else 403. */\n get status(): 402 | 403 {\n return this.reason === \"entitlement\" ? 402 : 403;\n }\n}\n\n/**\n * Refuse unless the feature is on: call it at the top of every server\n * function and route that belongs to a feature.\n *\n * ```ts\n * requireFeature({ features, flags }, await gateContext(tenant), \"form-webhook-delivery\");\n * ```\n *\n * @stability Beta\n */\nexport function requireFeature(\n registry: GateRegistry,\n context: GateContext,\n id: string,\n): void {\n const result = featureOn(registry, context, id);\n if (!result.on) throw new FeatureOff(id, result);\n}\n"]}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// src/status.ts
|
|
2
|
+
function statusOn(def, platform) {
|
|
3
|
+
if (def.platforms) return def.platforms[platform];
|
|
4
|
+
const apps = def.apps.map((a) => a === "node" ? "server" : a);
|
|
5
|
+
return apps.includes(platform) ? def.status : void 0;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export { statusOn };
|
|
9
|
+
//# sourceMappingURL=chunk-OW46SL2G.js.map
|
|
10
|
+
//# sourceMappingURL=chunk-OW46SL2G.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/status.ts"],"names":[],"mappings":";AASO,SAAS,QAAA,CACd,KAKA,QAAA,EAC2B;AAC3B,EAAA,IAAI,GAAA,CAAI,SAAA,EAAW,OAAO,GAAA,CAAI,UAAU,QAAQ,CAAA;AAEhD,EAAA,MAAM,IAAA,GAAO,IAAI,IAAA,CAAK,GAAA,CAAI,CAAC,CAAA,KAAO,CAAA,KAAM,MAAA,GAAS,QAAA,GAAW,CAAE,CAAA;AAC9D,EAAA,OAAO,IAAA,CAAK,QAAA,CAAS,QAAQ,CAAA,GAAI,IAAI,MAAA,GAAS,MAAA;AAChD","file":"chunk-OW46SL2G.js","sourcesContent":["import type { FeatureStatus } from \"./types\";\nimport type { FeaturePlatform } from \"./platforms\";\n\n/**\n * A feature's status on one platform, or undefined when it isn't there.\n * Zod-free so the gate can use it on phones and in browsers.\n *\n * @stability Beta\n */\nexport function statusOn(\n def: {\n status: FeatureStatus;\n apps: readonly string[];\n platforms?: Partial<Record<FeaturePlatform, FeatureStatus>>;\n },\n platform: FeaturePlatform,\n): FeatureStatus | undefined {\n if (def.platforms) return def.platforms[platform];\n // Registries often call the server \"node\" in `apps`.\n const apps = def.apps.map((a) => (a === \"node\" ? \"server\" : a));\n return apps.includes(platform) ? def.status : undefined;\n}\n"]}
|
|
@@ -47,9 +47,6 @@ function dependencyOrder(nodes) {
|
|
|
47
47
|
return order;
|
|
48
48
|
}
|
|
49
49
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
export { FEATURE_PLATFORMS, cycleProblems, dependencyOrder, requirementProblem, requiresProblems };
|
|
54
|
-
//# sourceMappingURL=chunk-2ARZER3G.js.map
|
|
55
|
-
//# sourceMappingURL=chunk-2ARZER3G.js.map
|
|
50
|
+
export { cycleProblems, dependencyOrder, requirementProblem, requiresProblems };
|
|
51
|
+
//# sourceMappingURL=chunk-VYUX7VAX.js.map
|
|
52
|
+
//# sourceMappingURL=chunk-VYUX7VAX.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/graph.ts"],"names":[],"mappings":";AA6BO,SAAS,gBAAA,CAAiB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F,EAAA,MAAM,QAAkB,EAAC;AACzB,EAAA,MAAM,IAAA,uBAAW,GAAA,EAAY;AAC7B,EAAA,MAAM,KAAA,GAAQ,CAAC,EAAA,KAAe;AAC5B,IAAA,IAAI,IAAA,CAAK,GAAA,CAAI,EAAE,CAAA,EAAG;AAClB,IAAA,IAAA,CAAK,IAAI,EAAE,CAAA;AACX,IAAA,KAAA,MAAW,GAAA,IAAO,KAAA,CAAM,EAAE,CAAA,EAAG,YAAY,EAAC,EAAG,IAAI,MAAA,CAAO,MAAA,CAAO,KAAA,EAAO,GAAG,CAAA,QAAS,GAAG,CAAA;AACrF,IAAA,KAAA,CAAM,KAAK,EAAE,CAAA;AAAA,EACf,CAAA;AACA,EAAA,KAAA,MAAW,MAAM,MAAA,CAAO,IAAA,CAAK,KAAK,CAAA,QAAS,EAAE,CAAA;AAC7C,EAAA,OAAO,KAAA;AACT","file":"chunk-VYUX7VAX.js","sourcesContent":["/**\n * The `requires` graph checks shared by the feature registry\n * (`defineFeatures`) and blocks (`resolveBlocks`). No zod here: blocks import\n * this from a platform-neutral entry that ships to phones.\n */\n\n/** A node with the ids it needs. */\nexport interface RequiresNode {\n readonly requires?: readonly string[];\n}\n\nexport interface RequiresProblemsOptions {\n /** What a node is called in messages: `feature` or `block`. */\n noun: string;\n /** Whether an id may be required. Default: it is a node of the graph. */\n isKnown?: (id: string) => boolean;\n /** The message for a requirement `isKnown` refuses. Default `\"x\" is not a <noun>`. */\n unknown?: (req: string, id: string) => string;\n /** Nodes already reported invalid: their edges can't be trusted, so they are skipped. */\n skip?: ReadonlySet<string>;\n}\n\n/**\n * Self-requirements, unknown requirements and cycles through `requires`, as\n * problem strings (`a.requires: …`). Each cycle is reported once, from where\n * the depth-first search found it: `a.requires: a cycle: a → b → a`.\n *\n * @stability Beta\n */\nexport function requiresProblems(nodes: Readonly<Record<string, RequiresNode>>, options: RequiresProblemsOptions): string[] {\n const { skip = new Set<string>() } = options;\n const problems: string[] = [];\n for (const [id, node] of Object.entries(nodes)) {\n if (skip.has(id)) continue;\n for (const req of node.requires ?? []) {\n const problem = requirementProblem(nodes, id, req, options);\n if (problem) problems.push(problem);\n }\n }\n return [...problems, ...cycleProblems(nodes, skip)];\n}\n\n/** One requirement's problem (itself, or an unknown id), or undefined when it is fine. @stability Beta */\nexport function requirementProblem(\n nodes: Readonly<Record<string, RequiresNode>>,\n id: string,\n req: string,\n options: RequiresProblemsOptions,\n): string | undefined {\n const known = options.isKnown ?? ((r: string) => Object.hasOwn(nodes, r));\n if (req === id) return `${id}.requires: a ${options.noun} can't require itself`;\n if (!known(req)) return `${id}.requires: ${options.unknown ? options.unknown(req, id) : `\"${req}\" is not a ${options.noun}`}`;\n return undefined;\n}\n\n/** Cycles through `requires`, each reported once, from where the depth-first search found it. @stability Beta */\nexport function cycleProblems(nodes: Readonly<Record<string, RequiresNode>>, skip: ReadonlySet<string> = new Set()): string[] {\n const has = (id: string) => Object.hasOwn(nodes, id);\n const problems: string[] = [];\n const state = new Map<string, \"open\" | \"done\">();\n const visit = (id: string, path: string[]): void => {\n state.set(id, \"open\");\n if (skip.has(id)) return;\n for (const req of nodes[id]?.requires ?? []) {\n if (!has(req) || req === id) continue;\n if (state.get(req) === \"open\") problems.push(`${id}.requires: a cycle: ${[...path.slice(path.indexOf(req)), id, req].join(\" → \")}`);\n else if (!state.has(req)) visit(req, [...path, id]);\n }\n state.set(id, \"done\");\n };\n for (const id of Object.keys(nodes)) if (!state.has(id)) visit(id, []);\n return problems;\n}\n\n/**\n * The ids in dependency order (what a node requires comes first), ties kept\n * in the given order. Requirements outside `nodes` are ignored. Assumes no\n * cycles ({@link requiresProblems} reports them).\n */\nexport function dependencyOrder(nodes: Readonly<Record<string, RequiresNode>>): string[] {\n const order: string[] = [];\n const seen = new Set<string>();\n const visit = (id: string) => {\n if (seen.has(id)) return;\n seen.add(id);\n for (const req of nodes[id]?.requires ?? []) if (Object.hasOwn(nodes, req)) visit(req);\n order.push(id);\n };\n for (const id of Object.keys(nodes)) visit(id);\n return order;\n}\n"]}
|