@marktiderman/genesis-features 0.4.1 → 0.6.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/README.md +33 -0
- package/dist/blocks.d.ts +144 -1
- package/dist/blocks.js +1 -1
- package/dist/{chunk-4Q356635.js → chunk-OBVR6AZR.js} +108 -3
- package/dist/chunk-OBVR6AZR.js.map +1 -0
- package/dist/{chunk-LNVWVPWB.js → chunk-U2RFA7VK.js} +14 -4
- package/dist/chunk-U2RFA7VK.js.map +1 -0
- package/dist/{gate-BY352cd0.d.ts → gate-4OB4ddHv.d.ts} +13 -0
- package/dist/gate-react.d.ts +1 -1
- package/dist/gate-react.js +1 -1
- package/dist/gate.d.ts +1 -1
- package/dist/gate.js +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/package.json +3 -3
- package/dist/chunk-4Q356635.js.map +0 -1
- package/dist/chunk-LNVWVPWB.js.map +0 -1
package/README.md
CHANGED
|
@@ -157,6 +157,10 @@ import { FeatureGate, FeatureGateProvider, useFeature } from "@marktiderman/gene
|
|
|
157
157
|
</FeatureGateProvider>;
|
|
158
158
|
```
|
|
159
159
|
|
|
160
|
+
A feature that `requires` other features in the registry (a module's parts) is off while any of them is off,
|
|
161
|
+
with `via` naming the one that said no, so switching a module off or not paying for it turns its parts off
|
|
162
|
+
too. Ids outside the registry don't gate.
|
|
163
|
+
|
|
160
164
|
The gate doesn't check roles: "may this person" stays with roles and row security. Why it works this
|
|
161
165
|
way: [ADR 0001](../../docs/adr/0001-one-feature-gate.md).
|
|
162
166
|
|
|
@@ -215,6 +219,35 @@ Blocks shipped so far: `createUpdates(…)` (`app-updates`, in `@marktiderman/ge
|
|
|
215
219
|
`accountBlock` and `tenantFeaturesBlock` (in `@marktiderman/genesis-supabase`).
|
|
216
220
|
`<GenesisNativeApp blocks={…}>` runs them; see that package's README.
|
|
217
221
|
|
|
222
|
+
## Content packs
|
|
223
|
+
|
|
224
|
+
A content pack is versioned data that fills installed blocks: session types and their agendas, metric
|
|
225
|
+
templates, custom field definitions (genesis-forms fields on a work table), forms, roadmap templates and
|
|
226
|
+
labels. Packs are code: the publishing package exports them, and an installer copies them into a tenant's
|
|
227
|
+
editable rows, keeping each row's source (pack, version, key) so an update can tell what someone changed.
|
|
228
|
+
|
|
229
|
+
```ts
|
|
230
|
+
import { contentPackProblems, defineContentPack } from "@marktiderman/genesis-features/blocks";
|
|
231
|
+
|
|
232
|
+
export const weeklyTeamRhythm = defineContentPack({
|
|
233
|
+
id: "weekly-team-rhythm",
|
|
234
|
+
name: "Weekly team rhythm",
|
|
235
|
+
version: "1.0.0",
|
|
236
|
+
publisher: "@marktiderman/genesis-content",
|
|
237
|
+
requires: ["sessions", "metrics"],
|
|
238
|
+
labels: { "pursuit.quarter": "Rocks" },
|
|
239
|
+
sessionTypes: [{ key: "weekly", kind: "team", name: "Weekly meeting", agenda: [{ key: "check-in", title: "Check in", minutes: 5 }] }],
|
|
240
|
+
metricTemplates: [{ key: "revenue", name: "Revenue", unitType: "currency", cadence: "weekly", goalDirection: "up" }],
|
|
241
|
+
});
|
|
242
|
+
|
|
243
|
+
contentPackProblems(weeklyTeamRhythm, installedBlockIds); // [] when it can be installed
|
|
244
|
+
```
|
|
245
|
+
|
|
246
|
+
`defineContentPack` lists every problem at once: ids, semver versions, keys (unique per section, stable
|
|
247
|
+
across versions), references between roadmap items, field targets, and any section whose block
|
|
248
|
+
`requires` doesn't list (`sessionTypes` → sessions, `metricTemplates` → metrics, `fieldDefinitions` →
|
|
249
|
+
its target's block, `forms` → forms, `roadmapTemplates` → roadmap).
|
|
250
|
+
|
|
218
251
|
## The page
|
|
219
252
|
|
|
220
253
|
```tsx
|
package/dist/blocks.d.ts
CHANGED
|
@@ -232,4 +232,147 @@ type SlotOf<B> = B extends BlockDef<string, infer S> ? S : never;
|
|
|
232
232
|
*/
|
|
233
233
|
declare function resolveBlocks<B extends BlockDef<string, unknown>>(blocks: readonly B[], enabled?: EnabledBlocks, options?: ResolveBlocksOptions): ResolvedBlocks<B>;
|
|
234
234
|
|
|
235
|
-
|
|
235
|
+
/**
|
|
236
|
+
* Content packs: versioned data that fills installed blocks (session types and
|
|
237
|
+
* agendas, metric templates, custom field definitions, forms, roadmap templates,
|
|
238
|
+
* labels). A pack is code, reviewed like any other: the publishing package
|
|
239
|
+
* exports it, and an installer copies it into a tenant's editable rows, keeping
|
|
240
|
+
* each row's source (pack, version, key) so an update can tell what a person
|
|
241
|
+
* changed.
|
|
242
|
+
*
|
|
243
|
+
* `defineContentPack` checks a pack's shape; `contentPackProblems` with the
|
|
244
|
+
* installed blocks also checks that every block it fills is there. Keys, not
|
|
245
|
+
* ids, link things together, and stay the same across versions.
|
|
246
|
+
*
|
|
247
|
+
* No zod here: packs ship to phones with `/blocks`.
|
|
248
|
+
*/
|
|
249
|
+
|
|
250
|
+
/** A content pack's settings for one session type, with its agenda. @stability Beta */
|
|
251
|
+
interface ContentPackSessionType {
|
|
252
|
+
key: string;
|
|
253
|
+
kind: string;
|
|
254
|
+
name: string;
|
|
255
|
+
description?: string;
|
|
256
|
+
defaultMinutes?: number;
|
|
257
|
+
agenda: readonly {
|
|
258
|
+
key: string;
|
|
259
|
+
title: string;
|
|
260
|
+
minutes: number;
|
|
261
|
+
}[];
|
|
262
|
+
}
|
|
263
|
+
/** A metric to start from. @stability Beta */
|
|
264
|
+
interface ContentPackMetricTemplate {
|
|
265
|
+
key: string;
|
|
266
|
+
name: string;
|
|
267
|
+
unitType: string;
|
|
268
|
+
unit?: string;
|
|
269
|
+
cadence: string;
|
|
270
|
+
goalDirection: string;
|
|
271
|
+
goalValue?: number;
|
|
272
|
+
goalMax?: number;
|
|
273
|
+
measureKind?: string;
|
|
274
|
+
rollup?: string;
|
|
275
|
+
}
|
|
276
|
+
/** Where a custom field lives, and the block that owns that table. @stability Beta */
|
|
277
|
+
declare const CONTENT_PACK_FIELD_TARGETS: {
|
|
278
|
+
readonly pursuits: "pursuits";
|
|
279
|
+
readonly work_items: "pursuits";
|
|
280
|
+
readonly metrics: "metrics";
|
|
281
|
+
readonly sessions: "sessions";
|
|
282
|
+
};
|
|
283
|
+
/** @stability Beta */
|
|
284
|
+
type ContentPackFieldTarget = keyof typeof CONTENT_PACK_FIELD_TARGETS;
|
|
285
|
+
/** A custom field: a genesis-forms serializable field, on one of the work tables. @stability Beta */
|
|
286
|
+
interface ContentPackFieldDefinition {
|
|
287
|
+
key: string;
|
|
288
|
+
target: ContentPackFieldTarget;
|
|
289
|
+
label: string;
|
|
290
|
+
/** A genesis-forms serializable field: type, options, validation. */
|
|
291
|
+
field: {
|
|
292
|
+
readonly type: string;
|
|
293
|
+
readonly [key: string]: unknown;
|
|
294
|
+
};
|
|
295
|
+
required?: boolean;
|
|
296
|
+
visibility: "tenant" | "app" | "private";
|
|
297
|
+
}
|
|
298
|
+
/** A worksheet, assessment or form: a genesis-forms definition. @stability Beta */
|
|
299
|
+
interface ContentPackForm {
|
|
300
|
+
key: string;
|
|
301
|
+
kind: "worksheet" | "assessment" | "form";
|
|
302
|
+
title: string;
|
|
303
|
+
definition: {
|
|
304
|
+
readonly [key: string]: unknown;
|
|
305
|
+
};
|
|
306
|
+
scoring?: unknown;
|
|
307
|
+
}
|
|
308
|
+
/** A roadmap to start from: items that release by a rule, linked to each other by key. @stability Beta */
|
|
309
|
+
interface ContentPackRoadmapTemplate {
|
|
310
|
+
key: string;
|
|
311
|
+
name: string;
|
|
312
|
+
items: readonly {
|
|
313
|
+
key: string;
|
|
314
|
+
kind: string;
|
|
315
|
+
title: string;
|
|
316
|
+
/** Another item's key in this template. */
|
|
317
|
+
ref?: string;
|
|
318
|
+
release: {
|
|
319
|
+
rule: string;
|
|
320
|
+
afterDays?: number;
|
|
321
|
+
anchor?: string;
|
|
322
|
+
};
|
|
323
|
+
}[];
|
|
324
|
+
}
|
|
325
|
+
/** One content pack, as its publisher defines it. @stability Beta */
|
|
326
|
+
interface ContentPackDef {
|
|
327
|
+
/** Kebab-case, unique per publisher. */
|
|
328
|
+
id: string;
|
|
329
|
+
name: string;
|
|
330
|
+
description?: string;
|
|
331
|
+
/** Semver. Updates are additive. */
|
|
332
|
+
version: string;
|
|
333
|
+
/** The package that publishes it. */
|
|
334
|
+
publisher: string;
|
|
335
|
+
/** The block ids it fills; installing is refused unless every one is installed. */
|
|
336
|
+
requires: readonly string[];
|
|
337
|
+
/** Taxonomy: label key → display text, e.g. `"pursuit.quarter": "Rocks"`. */
|
|
338
|
+
labels?: Readonly<Record<string, string>>;
|
|
339
|
+
sessionTypes?: readonly ContentPackSessionType[];
|
|
340
|
+
metricTemplates?: readonly ContentPackMetricTemplate[];
|
|
341
|
+
fieldDefinitions?: readonly ContentPackFieldDefinition[];
|
|
342
|
+
forms?: readonly ContentPackForm[];
|
|
343
|
+
roadmapTemplates?: readonly ContentPackRoadmapTemplate[];
|
|
344
|
+
}
|
|
345
|
+
/** Thrown by {@link defineContentPack}; lists every problem at once. @stability Beta */
|
|
346
|
+
declare class ContentPackError extends Error {
|
|
347
|
+
readonly problems: string[];
|
|
348
|
+
constructor(problems: string[]);
|
|
349
|
+
}
|
|
350
|
+
/** The block ids a pack's sections need, whatever it declares. @stability Beta */
|
|
351
|
+
declare function contentPackBlocks(pack: ContentPackDef): string[];
|
|
352
|
+
/**
|
|
353
|
+
* Every problem with a pack: its shape and, given the installed blocks, any
|
|
354
|
+
* block it fills that isn't installed. An empty list means it can be installed.
|
|
355
|
+
*
|
|
356
|
+
* @stability Beta
|
|
357
|
+
*/
|
|
358
|
+
declare function contentPackProblems(pack: ContentPackDef, installed?: EnabledBlocks): string[];
|
|
359
|
+
/**
|
|
360
|
+
* Declare a content pack: returns it unchanged, typed, after checking its
|
|
361
|
+
* shape (throws a {@link ContentPackError} listing every problem). Whether its
|
|
362
|
+
* blocks are installed is checked at install time with
|
|
363
|
+
* {@link contentPackProblems}.
|
|
364
|
+
*
|
|
365
|
+
* ```ts
|
|
366
|
+
* export const weeklyTeamRhythm = defineContentPack({
|
|
367
|
+
* id: "weekly-team-rhythm", name: "Weekly team rhythm", version: "1.0.0",
|
|
368
|
+
* publisher: "@marktiderman/genesis-content", requires: ["sessions", "metrics"],
|
|
369
|
+
* labels: { "pursuit.quarter": "Rocks" },
|
|
370
|
+
* sessionTypes: [{ key: "weekly", kind: "team", name: "Weekly meeting", agenda: [{ key: "check-in", title: "Check in", minutes: 5 }] }],
|
|
371
|
+
* });
|
|
372
|
+
* ```
|
|
373
|
+
*
|
|
374
|
+
* @stability Beta
|
|
375
|
+
*/
|
|
376
|
+
declare function defineContentPack<const T extends ContentPackDef>(pack: T): T;
|
|
377
|
+
|
|
378
|
+
export { type BlockContributions, type BlockDataUse, type BlockDef, BlockError, type BlockMigration, type BlockNavItem, type BlockPrivacy, type BlockRoute, type BlockSettingsRow, CONTENT_PACK_FIELD_TARGETS, type ContentPackDef, ContentPackError, type ContentPackFieldDefinition, type ContentPackFieldTarget, type ContentPackForm, type ContentPackMetricTemplate, type ContentPackRoadmapTemplate, type ContentPackSessionType, type Contributed, type EnabledBlocks, FeaturePlatform, type ResolveBlocksOptions, type ResolvedBlocks, contentPackBlocks, contentPackProblems, defineBlock, defineContentPack, resolveBlocks };
|
package/dist/blocks.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { BlockError, defineBlock, resolveBlocks } from './chunk-
|
|
1
|
+
export { BlockError, CONTENT_PACK_FIELD_TARGETS, ContentPackError, contentPackBlocks, contentPackProblems, defineBlock, defineContentPack, resolveBlocks } from './chunk-OBVR6AZR.js';
|
|
2
2
|
import './chunk-VYUX7VAX.js';
|
|
3
3
|
export { FEATURE_PLATFORMS } from './chunk-B6WRD3WF.js';
|
|
4
4
|
//# sourceMappingURL=blocks.js.map
|
|
@@ -151,6 +151,111 @@ function resolveBlocks(blocks, enabled, options = {}) {
|
|
|
151
151
|
});
|
|
152
152
|
}
|
|
153
153
|
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
154
|
+
// src/content-packs.ts
|
|
155
|
+
var CONTENT_PACK_FIELD_TARGETS = {
|
|
156
|
+
pursuits: "pursuits",
|
|
157
|
+
work_items: "pursuits",
|
|
158
|
+
metrics: "metrics",
|
|
159
|
+
sessions: "sessions"
|
|
160
|
+
};
|
|
161
|
+
var ContentPackError = class extends Error {
|
|
162
|
+
constructor(problems) {
|
|
163
|
+
super(`Invalid content pack:
|
|
164
|
+
${problems.map((p) => ` - ${p}`).join("\n")}`);
|
|
165
|
+
this.problems = problems;
|
|
166
|
+
this.name = "ContentPackError";
|
|
167
|
+
}
|
|
168
|
+
problems;
|
|
169
|
+
};
|
|
170
|
+
var KEBAB = /^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/;
|
|
171
|
+
var KEY = /^[a-z][a-z0-9]*(?:[-_.][a-z0-9]+)*$/;
|
|
172
|
+
var SEMVER = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-[0-9A-Za-z.-]+)?(?:\+[0-9A-Za-z.-]+)?$/;
|
|
173
|
+
var SECTION_BLOCK = { sessionTypes: "sessions", metricTemplates: "metrics", forms: "forms", roadmapTemplates: "roadmap" };
|
|
174
|
+
function keyProblems(where, items) {
|
|
175
|
+
const problems = [];
|
|
176
|
+
const seen = /* @__PURE__ */ new Set();
|
|
177
|
+
for (const [i, item] of (items ?? []).entries()) {
|
|
178
|
+
if (typeof item?.key !== "string" || !KEY.test(item.key)) problems.push(`${where}[${i}].key: "${String(item?.key)}" is not a key (lowercase, dots, dashes or underscores)`);
|
|
179
|
+
else if (seen.has(item.key)) problems.push(`${where}: the key "${item.key}" is used twice`);
|
|
180
|
+
else seen.add(item.key);
|
|
181
|
+
}
|
|
182
|
+
return problems;
|
|
183
|
+
}
|
|
184
|
+
function contentPackBlocks(pack) {
|
|
185
|
+
const needed = /* @__PURE__ */ new Set();
|
|
186
|
+
for (const [section, block] of Object.entries(SECTION_BLOCK)) {
|
|
187
|
+
const items = pack[section];
|
|
188
|
+
if (items && items.length) needed.add(block);
|
|
189
|
+
}
|
|
190
|
+
for (const f of pack.fieldDefinitions ?? []) {
|
|
191
|
+
const block = CONTENT_PACK_FIELD_TARGETS[f.target];
|
|
192
|
+
if (block) needed.add(block);
|
|
193
|
+
}
|
|
194
|
+
return [...needed].sort();
|
|
195
|
+
}
|
|
196
|
+
function test(blocks) {
|
|
197
|
+
if (typeof blocks === "function") return blocks;
|
|
198
|
+
const set = new Set(blocks);
|
|
199
|
+
return (id) => set.has(id);
|
|
200
|
+
}
|
|
201
|
+
function contentPackProblems(pack, installed) {
|
|
202
|
+
const at = `content pack ${typeof pack?.id === "string" ? pack.id : "?"}`;
|
|
203
|
+
const problems = [];
|
|
204
|
+
if (typeof pack?.id !== "string" || !KEBAB.test(pack.id)) problems.push(`${at}: id must be kebab-case`);
|
|
205
|
+
if (typeof pack?.name !== "string" || !pack.name.trim()) problems.push(`${at}: needs a name`);
|
|
206
|
+
if (typeof pack?.version !== "string" || !SEMVER.test(pack.version)) problems.push(`${at}: version "${String(pack?.version)}" isn't semver`);
|
|
207
|
+
if (typeof pack?.publisher !== "string" || !pack.publisher.trim()) problems.push(`${at}: needs a publisher (its package name)`);
|
|
208
|
+
if (!Array.isArray(pack?.requires)) {
|
|
209
|
+
problems.push(`${at}: requires must list the blocks it fills`);
|
|
210
|
+
return problems;
|
|
211
|
+
}
|
|
212
|
+
for (const [label, text] of Object.entries(pack.labels ?? {})) {
|
|
213
|
+
if (!KEY.test(label)) problems.push(`${at}: label key "${label}" is not a key`);
|
|
214
|
+
if (typeof text !== "string" || !text.trim()) problems.push(`${at}: label "${label}" needs display text`);
|
|
215
|
+
}
|
|
216
|
+
problems.push(
|
|
217
|
+
...keyProblems(`${at}.sessionTypes`, pack.sessionTypes),
|
|
218
|
+
...keyProblems(`${at}.metricTemplates`, pack.metricTemplates),
|
|
219
|
+
...keyProblems(`${at}.fieldDefinitions`, pack.fieldDefinitions),
|
|
220
|
+
...keyProblems(`${at}.forms`, pack.forms),
|
|
221
|
+
...keyProblems(`${at}.roadmapTemplates`, pack.roadmapTemplates)
|
|
222
|
+
);
|
|
223
|
+
for (const s of pack.sessionTypes ?? []) {
|
|
224
|
+
problems.push(...keyProblems(`${at}.sessionTypes.${s.key}.agenda`, s.agenda));
|
|
225
|
+
for (const item of s.agenda ?? []) {
|
|
226
|
+
if (!(typeof item.minutes === "number" && item.minutes > 0)) problems.push(`${at}.sessionTypes.${s.key}.agenda.${item.key}: minutes must be more than 0`);
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
for (const f of pack.fieldDefinitions ?? []) {
|
|
230
|
+
if (!Object.hasOwn(CONTENT_PACK_FIELD_TARGETS, f.target)) problems.push(`${at}.fieldDefinitions.${f.key}: target "${String(f.target)}" isn't one of ${Object.keys(CONTENT_PACK_FIELD_TARGETS).join(", ")}`);
|
|
231
|
+
if (typeof f.field?.type !== "string") problems.push(`${at}.fieldDefinitions.${f.key}: field needs a genesis-forms type`);
|
|
232
|
+
if (!["tenant", "app", "private"].includes(f.visibility)) problems.push(`${at}.fieldDefinitions.${f.key}: visibility must be tenant, app or private`);
|
|
233
|
+
}
|
|
234
|
+
for (const r of pack.roadmapTemplates ?? []) {
|
|
235
|
+
problems.push(...keyProblems(`${at}.roadmapTemplates.${r.key}.items`, r.items));
|
|
236
|
+
const keys = new Set((r.items ?? []).map((i) => i.key));
|
|
237
|
+
for (const item of r.items ?? []) {
|
|
238
|
+
if (item.ref !== void 0 && (!keys.has(item.ref) || item.ref === item.key)) {
|
|
239
|
+
problems.push(`${at}.roadmapTemplates.${r.key}.items.${item.key}: ref "${item.ref}" isn't another item in this template`);
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
const declared = new Set(pack.requires);
|
|
244
|
+
for (const block of contentPackBlocks(pack)) {
|
|
245
|
+
if (!declared.has(block)) problems.push(`${at}: fills the ${block} block but doesn't list it in requires`);
|
|
246
|
+
}
|
|
247
|
+
if (installed !== void 0) {
|
|
248
|
+
const has = test(installed);
|
|
249
|
+
for (const block of pack.requires) if (!has(block)) problems.push(`${at}: needs the ${block} block, which isn't installed`);
|
|
250
|
+
}
|
|
251
|
+
return problems;
|
|
252
|
+
}
|
|
253
|
+
function defineContentPack(pack) {
|
|
254
|
+
const problems = contentPackProblems(pack);
|
|
255
|
+
if (problems.length) throw new ContentPackError(problems);
|
|
256
|
+
return pack;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
export { BlockError, CONTENT_PACK_FIELD_TARGETS, ContentPackError, contentPackBlocks, contentPackProblems, defineBlock, defineContentPack, resolveBlocks };
|
|
260
|
+
//# sourceMappingURL=chunk-OBVR6AZR.js.map
|
|
261
|
+
//# sourceMappingURL=chunk-OBVR6AZR.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/blocks.ts","../src/content-packs.ts"],"names":[],"mappings":";;;;AAwJO,IAAM,UAAA,GAAN,cAAyB,KAAA,CAAM;AAAA,EACpC,YAAqB,QAAA,EAAoB;AACvC,IAAA,KAAA,CAAM,CAAA;AAAA,EAAoB,QAAA,CAAS,GAAA,CAAI,CAAC,CAAA,KAAM,CAAA,IAAA,EAAO,CAAC,CAAA,CAAE,CAAA,CAAE,IAAA,CAAK,IAAI,CAAC,CAAA,CAAE,CAAA;AADnD,IAAA,IAAA,CAAA,QAAA,GAAA,QAAA;AAEnB,IAAA,IAAA,CAAK,IAAA,GAAO,YAAA;AAAA,EACd;AAAA,EAHqB,QAAA;AAIvB;AAGA,IAAM,EAAA,GAAK,qCAAA;AAEX,IAAM,iBAAA,GAAoB,CAAC,KAAA,EAAO,UAAA,EAAY,UAAU,OAAA,EAAS,YAAA,EAAc,UAAU,SAAS,CAAA;AAElG,SAAS,WAAW,MAAA,EAAqC;AACvD,EAAA,MAAM,IAAA,uBAAW,GAAA,EAAY;AAC7B,EAAA,MAAM,GAAA,uBAAU,GAAA,EAAY;AAC5B,EAAA,KAAA,MAAW,CAAA,IAAK,MAAA,EAAQ,CAAC,IAA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AQ,CAAA;AACxD,EAAA,OAAO,IAAA;AACT","file":"chunk-OBVR6AZR.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","/**\n * Content packs: versioned data that fills installed blocks (session types and\n * agendas, metric templates, custom field definitions, forms, roadmap templates,\n * labels). A pack is code, reviewed like any other: the publishing package\n * exports it, and an installer copies it into a tenant's editable rows, keeping\n * each row's source (pack, version, key) so an update can tell what a person\n * changed.\n *\n * `defineContentPack` checks a pack's shape; `contentPackProblems` with the\n * installed blocks also checks that every block it fills is there. Keys, not\n * ids, link things together, and stay the same across versions.\n *\n * No zod here: packs ship to phones with `/blocks`.\n */\nimport type { EnabledBlocks } from \"./blocks\";\n\n/** A content pack's settings for one session type, with its agenda. @stability Beta */\nexport interface ContentPackSessionType {\n key: string;\n kind: string;\n name: string;\n description?: string;\n defaultMinutes?: number;\n agenda: readonly { key: string; title: string; minutes: number }[];\n}\n\n/** A metric to start from. @stability Beta */\nexport interface ContentPackMetricTemplate {\n key: string;\n name: string;\n unitType: string;\n unit?: string;\n cadence: string;\n goalDirection: string;\n goalValue?: number;\n goalMax?: number;\n measureKind?: string;\n rollup?: string;\n}\n\n/** Where a custom field lives, and the block that owns that table. @stability Beta */\nexport const CONTENT_PACK_FIELD_TARGETS = {\n pursuits: \"pursuits\",\n work_items: \"pursuits\",\n metrics: \"metrics\",\n sessions: \"sessions\",\n} as const;\n\n/** @stability Beta */\nexport type ContentPackFieldTarget = keyof typeof CONTENT_PACK_FIELD_TARGETS;\n\n/** A custom field: a genesis-forms serializable field, on one of the work tables. @stability Beta */\nexport interface ContentPackFieldDefinition {\n key: string;\n target: ContentPackFieldTarget;\n label: string;\n /** A genesis-forms serializable field: type, options, validation. */\n field: { readonly type: string; readonly [key: string]: unknown };\n required?: boolean;\n visibility: \"tenant\" | \"app\" | \"private\";\n}\n\n/** A worksheet, assessment or form: a genesis-forms definition. @stability Beta */\nexport interface ContentPackForm {\n key: string;\n kind: \"worksheet\" | \"assessment\" | \"form\";\n title: string;\n definition: { readonly [key: string]: unknown };\n scoring?: unknown;\n}\n\n/** A roadmap to start from: items that release by a rule, linked to each other by key. @stability Beta */\nexport interface ContentPackRoadmapTemplate {\n key: string;\n name: string;\n items: readonly {\n key: string;\n kind: string;\n title: string;\n /** Another item's key in this template. */\n ref?: string;\n release: { rule: string; afterDays?: number; anchor?: string };\n }[];\n}\n\n/** One content pack, as its publisher defines it. @stability Beta */\nexport interface ContentPackDef {\n /** Kebab-case, unique per publisher. */\n id: string;\n name: string;\n description?: string;\n /** Semver. Updates are additive. */\n version: string;\n /** The package that publishes it. */\n publisher: string;\n /** The block ids it fills; installing is refused unless every one is installed. */\n requires: readonly string[];\n /** Taxonomy: label key → display text, e.g. `\"pursuit.quarter\": \"Rocks\"`. */\n labels?: Readonly<Record<string, string>>;\n sessionTypes?: readonly ContentPackSessionType[];\n metricTemplates?: readonly ContentPackMetricTemplate[];\n fieldDefinitions?: readonly ContentPackFieldDefinition[];\n forms?: readonly ContentPackForm[];\n roadmapTemplates?: readonly ContentPackRoadmapTemplate[];\n}\n\n/** Thrown by {@link defineContentPack}; lists every problem at once. @stability Beta */\nexport class ContentPackError extends Error {\n constructor(readonly problems: string[]) {\n super(`Invalid content pack:\\n${problems.map((p) => ` - ${p}`).join(\"\\n\")}`);\n this.name = \"ContentPackError\";\n }\n}\n\nconst KEBAB = /^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/;\nconst KEY = /^[a-z][a-z0-9]*(?:[-_.][a-z0-9]+)*$/;\nconst SEMVER = /^(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)(?:-[0-9A-Za-z.-]+)?(?:\\+[0-9A-Za-z.-]+)?$/;\n\n/** The block each section fills. */\nconst SECTION_BLOCK = { sessionTypes: \"sessions\", metricTemplates: \"metrics\", forms: \"forms\", roadmapTemplates: \"roadmap\" } as const;\n\nfunction keyProblems(where: string, items: readonly { key: string }[] | undefined): string[] {\n const problems: string[] = [];\n const seen = new Set<string>();\n for (const [i, item] of (items ?? []).entries()) {\n if (typeof item?.key !== \"string\" || !KEY.test(item.key)) problems.push(`${where}[${i}].key: \"${String(item?.key)}\" is not a key (lowercase, dots, dashes or underscores)`);\n else if (seen.has(item.key)) problems.push(`${where}: the key \"${item.key}\" is used twice`);\n else seen.add(item.key);\n }\n return problems;\n}\n\n/** The block ids a pack's sections need, whatever it declares. @stability Beta */\nexport function contentPackBlocks(pack: ContentPackDef): string[] {\n const needed = new Set<string>();\n for (const [section, block] of Object.entries(SECTION_BLOCK)) {\n const items = pack[section as keyof typeof SECTION_BLOCK];\n if (items && items.length) needed.add(block);\n }\n for (const f of pack.fieldDefinitions ?? []) {\n const block = CONTENT_PACK_FIELD_TARGETS[f.target];\n if (block) needed.add(block);\n }\n return [...needed].sort();\n}\n\nfunction test(blocks: EnabledBlocks): (id: string) => boolean {\n if (typeof blocks === \"function\") return blocks;\n const set = new Set(blocks);\n return (id) => set.has(id);\n}\n\n/**\n * Every problem with a pack: its shape and, given the installed blocks, any\n * block it fills that isn't installed. An empty list means it can be installed.\n *\n * @stability Beta\n */\nexport function contentPackProblems(pack: ContentPackDef, installed?: EnabledBlocks): string[] {\n const at = `content pack ${typeof pack?.id === \"string\" ? pack.id : \"?\"}`;\n const problems: string[] = [];\n if (typeof pack?.id !== \"string\" || !KEBAB.test(pack.id)) problems.push(`${at}: id must be kebab-case`);\n if (typeof pack?.name !== \"string\" || !pack.name.trim()) problems.push(`${at}: needs a name`);\n if (typeof pack?.version !== \"string\" || !SEMVER.test(pack.version)) problems.push(`${at}: version \"${String(pack?.version)}\" isn't semver`);\n if (typeof pack?.publisher !== \"string\" || !pack.publisher.trim()) problems.push(`${at}: needs a publisher (its package name)`);\n if (!Array.isArray(pack?.requires)) {\n problems.push(`${at}: requires must list the blocks it fills`);\n return problems;\n }\n for (const [label, text] of Object.entries(pack.labels ?? {})) {\n if (!KEY.test(label)) problems.push(`${at}: label key \"${label}\" is not a key`);\n if (typeof text !== \"string\" || !text.trim()) problems.push(`${at}: label \"${label}\" needs display text`);\n }\n problems.push(\n ...keyProblems(`${at}.sessionTypes`, pack.sessionTypes),\n ...keyProblems(`${at}.metricTemplates`, pack.metricTemplates),\n ...keyProblems(`${at}.fieldDefinitions`, pack.fieldDefinitions),\n ...keyProblems(`${at}.forms`, pack.forms),\n ...keyProblems(`${at}.roadmapTemplates`, pack.roadmapTemplates),\n );\n for (const s of pack.sessionTypes ?? []) {\n problems.push(...keyProblems(`${at}.sessionTypes.${s.key}.agenda`, s.agenda));\n for (const item of s.agenda ?? []) {\n if (!(typeof item.minutes === \"number\" && item.minutes > 0)) problems.push(`${at}.sessionTypes.${s.key}.agenda.${item.key}: minutes must be more than 0`);\n }\n }\n for (const f of pack.fieldDefinitions ?? []) {\n if (!Object.hasOwn(CONTENT_PACK_FIELD_TARGETS, f.target)) problems.push(`${at}.fieldDefinitions.${f.key}: target \"${String(f.target)}\" isn't one of ${Object.keys(CONTENT_PACK_FIELD_TARGETS).join(\", \")}`);\n if (typeof f.field?.type !== \"string\") problems.push(`${at}.fieldDefinitions.${f.key}: field needs a genesis-forms type`);\n if (![\"tenant\", \"app\", \"private\"].includes(f.visibility)) problems.push(`${at}.fieldDefinitions.${f.key}: visibility must be tenant, app or private`);\n }\n for (const r of pack.roadmapTemplates ?? []) {\n problems.push(...keyProblems(`${at}.roadmapTemplates.${r.key}.items`, r.items));\n const keys = new Set((r.items ?? []).map((i) => i.key));\n for (const item of r.items ?? []) {\n if (item.ref !== undefined && (!keys.has(item.ref) || item.ref === item.key)) {\n problems.push(`${at}.roadmapTemplates.${r.key}.items.${item.key}: ref \"${item.ref}\" isn't another item in this template`);\n }\n }\n }\n // Every block a section fills must be declared, and (when known) installed.\n const declared = new Set(pack.requires);\n for (const block of contentPackBlocks(pack)) {\n if (!declared.has(block)) problems.push(`${at}: fills the ${block} block but doesn't list it in requires`);\n }\n if (installed !== undefined) {\n const has = test(installed);\n for (const block of pack.requires) if (!has(block)) problems.push(`${at}: needs the ${block} block, which isn't installed`);\n }\n return problems;\n}\n\n/**\n * Declare a content pack: returns it unchanged, typed, after checking its\n * shape (throws a {@link ContentPackError} listing every problem). Whether its\n * blocks are installed is checked at install time with\n * {@link contentPackProblems}.\n *\n * ```ts\n * export const weeklyTeamRhythm = defineContentPack({\n * id: \"weekly-team-rhythm\", name: \"Weekly team rhythm\", version: \"1.0.0\",\n * publisher: \"@marktiderman/genesis-content\", requires: [\"sessions\", \"metrics\"],\n * labels: { \"pursuit.quarter\": \"Rocks\" },\n * sessionTypes: [{ key: \"weekly\", kind: \"team\", name: \"Weekly meeting\", agenda: [{ key: \"check-in\", title: \"Check in\", minutes: 5 }] }],\n * });\n * ```\n *\n * @stability Beta\n */\nexport function defineContentPack<const T extends ContentPackDef>(pack: T): T {\n const problems = contentPackProblems(pack);\n if (problems.length) throw new ContentPackError(problems);\n return pack;\n}\n"]}
|
|
@@ -36,7 +36,8 @@ function prepare(registry, context) {
|
|
|
36
36
|
off: toTest(context.off, "off")
|
|
37
37
|
};
|
|
38
38
|
}
|
|
39
|
-
function answer(
|
|
39
|
+
function answer(prepared, id, seen = /* @__PURE__ */ new Set()) {
|
|
40
|
+
const { registry, context, entitled, off } = prepared;
|
|
40
41
|
const def = Object.hasOwn(registry.features, id) ? registry.features[id] : void 0;
|
|
41
42
|
if (!def) return { on: false, reason: "unknown" };
|
|
42
43
|
if (!SHIPPED_STATUSES.includes(def.status))
|
|
@@ -44,6 +45,11 @@ function answer({ registry, context, entitled, off }, id) {
|
|
|
44
45
|
const here = statusOn(def, context.platform);
|
|
45
46
|
if (!here || !SHIPPED_STATUSES.includes(here))
|
|
46
47
|
return { on: false, reason: "platform" };
|
|
48
|
+
for (const need of def.requires ?? []) {
|
|
49
|
+
if (need === id || seen.has(need) || !Object.hasOwn(registry.features, need)) continue;
|
|
50
|
+
const parent = answer(prepared, need, /* @__PURE__ */ new Set([...seen, id]));
|
|
51
|
+
if (!parent.on) return { ...parent, via: parent.via ?? need };
|
|
52
|
+
}
|
|
47
53
|
if (off(id)) return { on: false, reason: "tenant" };
|
|
48
54
|
for (const [name, flag] of Object.entries(registry.flags ?? {})) {
|
|
49
55
|
if (flag.feature !== id || !GATING_KINDS.includes(flag.kind) || typeof flag.default !== "boolean")
|
|
@@ -87,14 +93,18 @@ var FeatureOff = class extends Error {
|
|
|
87
93
|
feature;
|
|
88
94
|
reason;
|
|
89
95
|
unlock;
|
|
96
|
+
/** The required feature that turned it off, when one did. */
|
|
97
|
+
via;
|
|
90
98
|
constructor(feature, answer2) {
|
|
99
|
+
const through = answer2.via ? ` (through ${answer2.via})` : "";
|
|
91
100
|
super(
|
|
92
|
-
answer2.reason === "entitlement" && answer2.unlock ? `${feature} needs the ${answer2.unlock.plan} plan` : `${feature} is off (${answer2.reason ?? "unknown"})`
|
|
101
|
+
answer2.reason === "entitlement" && answer2.unlock ? `${feature} needs the ${answer2.unlock.plan} plan${through}` : `${feature} is off (${answer2.reason ?? "unknown"}${answer2.via ? ` via ${answer2.via}` : ""})`
|
|
93
102
|
);
|
|
94
103
|
this.name = "FeatureOff";
|
|
95
104
|
this.feature = feature;
|
|
96
105
|
this.reason = answer2.reason ?? "unknown";
|
|
97
106
|
if (answer2.unlock) this.unlock = answer2.unlock;
|
|
107
|
+
if (answer2.via) this.via = answer2.via;
|
|
98
108
|
}
|
|
99
109
|
/** The HTTP status for this refusal: 402 when a plan unlocks it, else 403. */
|
|
100
110
|
get status() {
|
|
@@ -107,5 +117,5 @@ function requireFeature(registry, context, id) {
|
|
|
107
117
|
}
|
|
108
118
|
|
|
109
119
|
export { FeatureOff, SHIPPED_STATUSES, featureOn, fromSnapshot, gateSnapshot, isSnapshotStale, requireFeature };
|
|
110
|
-
//# sourceMappingURL=chunk-
|
|
111
|
-
//# sourceMappingURL=chunk-
|
|
120
|
+
//# sourceMappingURL=chunk-U2RFA7VK.js.map
|
|
121
|
+
//# sourceMappingURL=chunk-U2RFA7VK.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/gate.ts"],"names":["answer"],"mappings":";;;AA0CO,IAAM,gBAAA,GAA6C;AAAA,EACxD,MAAA;AAAA,EACA,MAAA;AAAA,EACA;AACF;AAkFA,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,CAA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OAAO,CAAA,CAAA,GACzD,CAAA,EAAG,OAAO,CAAA,SAAA,EAAYA,OAAAA,CAAO,MAAA,IAAU,SAAS,CAAA,EAAGA,OAAAA,CAAO,GAAA,GAAM,CAAA,KAAA,EAAQA,OAAAA,CAAO,GAAG,CAAA,CAAA,GAAK,EAAE,CAAA,CAAA;AAAA,KAC/F;AACA,IAAA,IAAA,CAAK,IAAA,GAAO,YAAA;AACZ,IAAA,IAAA,CAAK,OAAA,GAAU,OAAA;AACf,IAAA,IAAA,CAAK,MAAA,GAASA,QAAO,MAAA,IAAU,SAAA;AAC/B,IAAA,IAAIA,OAAAA,CAAO,MAAA,EAAQ,IAAA,CAAK,MAAA,GAASA,OAAAA,CAAO,MAAA;AACxC,IAAA,IAAIA,OAAAA,CAAO,GAAA,EAAK,IAAA,CAAK,GAAA,GAAMA,OAAAA,CAAO,GAAA;AAAA,EACpC;AAAA;AAAA,EAGA,IAAI,MAAA,GAAoB;AACtB,IAAA,OAAO,IAAA,CAAK,MAAA,KAAW,aAAA,GAAgB,GAAA,GAAM,GAAA;AAAA,EAC/C;AACF;AAYO,SAAS,cAAA,CACd,QAAA,EACA,OAAA,EACA,EAAA,EACM;AACN,EAAA,MAAM,MAAA,GAAS,SAAA,CAAU,QAAA,EAAU,OAAA,EAAS,EAAE,CAAA;AAC9C,EAAA,IAAI,CAAC,MAAA,CAAO,EAAA,QAAU,IAAI,UAAA,CAAW,IAAI,MAAM,CAAA;AACjD","file":"chunk-U2RFA7VK.js","sourcesContent":["/**\n * The feature gate: one answer 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 * A feature that `requires` other features in the registry (a module's parts\n * require the module) is also off while any of them is off: after its own\n * status and platform, each required feature is asked the same way, and the\n * first \"no\" comes back with `via` naming it. So switching a module off, or not\n * paying for it, turns off every part with it, and the upsell names the module's\n * plan.\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 /** The required feature that turned it off (a module its part needs), when the \"no\" came from one. */\n via?: 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 /** Ids this feature needs; those in the registry must be on too. */\n requires?: readonly string[];\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(prepared: Prepared, id: string, seen: ReadonlySet<string> = new Set()): GateAnswer {\n const { registry, context, entitled, off } = prepared;\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 // What it requires must be on too: a module's parts go off with the module.\n // Ids outside the registry (blocks, infrastructure) don't gate; a cycle is cut.\n for (const need of def.requires ?? []) {\n if (need === id || seen.has(need) || !Object.hasOwn(registry.features, need)) continue;\n const parent = answer(prepared, need, new Set([...seen, id]));\n if (!parent.on) return { ...parent, via: parent.via ?? need };\n }\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 /** The required feature that turned it off, when one did. */\n readonly via?: string;\n constructor(feature: string, answer: GateAnswer) {\n const through = answer.via ? ` (through ${answer.via})` : \"\";\n super(\n answer.reason === \"entitlement\" && answer.unlock\n ? `${feature} needs the ${answer.unlock.plan} plan${through}`\n : `${feature} is off (${answer.reason ?? \"unknown\"}${answer.via ? ` via ${answer.via}` : \"\"})`,\n );\n this.name = \"FeatureOff\";\n this.feature = feature;\n this.reason = answer.reason ?? \"unknown\";\n if (answer.unlock) this.unlock = answer.unlock;\n if (answer.via) this.via = answer.via;\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"]}
|
|
@@ -13,6 +13,13 @@ import { F as FeaturePlatform } from './platforms-NR0liM8L.js';
|
|
|
13
13
|
* 4. flag each of its boolean release or permission flags is true
|
|
14
14
|
* 5. entitlement a paid feature (`access: { plan }`) has an active entitlement
|
|
15
15
|
*
|
|
16
|
+
* A feature that `requires` other features in the registry (a module's parts
|
|
17
|
+
* require the module) is also off while any of them is off: after its own
|
|
18
|
+
* status and platform, each required feature is asked the same way, and the
|
|
19
|
+
* first "no" comes back with `via` naming it. So switching a module off, or not
|
|
20
|
+
* paying for it, turns off every part with it, and the upsell names the module's
|
|
21
|
+
* plan.
|
|
22
|
+
*
|
|
16
23
|
* Entitlement is last on purpose: an "upgrade to unlock" answer is only given
|
|
17
24
|
* when paying is the one thing missing, so an upsell never promises a feature
|
|
18
25
|
* that a switch or a flag would still keep off.
|
|
@@ -51,6 +58,8 @@ interface GateAnswer {
|
|
|
51
58
|
};
|
|
52
59
|
/** The flag that turned it off, when the reason is `flag`. Server side only: snapshots leave it out. */
|
|
53
60
|
flag?: string;
|
|
61
|
+
/** The required feature that turned it off (a module its part needs), when the "no" came from one. */
|
|
62
|
+
via?: string;
|
|
54
63
|
}
|
|
55
64
|
/** The fields of a feature the gate reads. A `FeatureDef` fits. @stability Beta */
|
|
56
65
|
interface GateFeature {
|
|
@@ -58,6 +67,8 @@ interface GateFeature {
|
|
|
58
67
|
apps: readonly string[];
|
|
59
68
|
platforms?: Partial<Record<FeaturePlatform, FeatureStatus>>;
|
|
60
69
|
access?: FeatureAccess;
|
|
70
|
+
/** Ids this feature needs; those in the registry must be on too. */
|
|
71
|
+
requires?: readonly string[];
|
|
61
72
|
}
|
|
62
73
|
/** The fields of a flag the gate reads. A `FlagDef` fits. @stability Beta */
|
|
63
74
|
interface GateFlag {
|
|
@@ -167,6 +178,8 @@ declare class FeatureOff extends Error {
|
|
|
167
178
|
readonly unlock?: {
|
|
168
179
|
plan: string;
|
|
169
180
|
};
|
|
181
|
+
/** The required feature that turned it off, when one did. */
|
|
182
|
+
readonly via?: string;
|
|
170
183
|
constructor(feature: string, answer: GateAnswer);
|
|
171
184
|
/** The HTTP status for this refusal: 402 when a plan unlocks it, else 403. */
|
|
172
185
|
get status(): 402 | 403;
|
package/dist/gate-react.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as react from 'react';
|
|
2
2
|
import { ReactNode } from 'react';
|
|
3
|
-
import { G as GateAnswer, a as GateSnapshot } from './gate-
|
|
3
|
+
import { G as GateAnswer, a as GateSnapshot } from './gate-4OB4ddHv.js';
|
|
4
4
|
import './types-Bd766VxF.js';
|
|
5
5
|
import './platforms-NR0liM8L.js';
|
|
6
6
|
|
package/dist/gate-react.js
CHANGED
package/dist/gate.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { F as FeatureOff, G as GateAnswer, b as GateContext, c as GateFeature, d as GateFlag, e as GateReason, f as GateRegistry, a as GateSnapshot, g as GateSnapshotOptions, I as IdSet, S as SHIPPED_STATUSES, h as featureOn, i as fromSnapshot, j as gateSnapshot, k as isSnapshotStale, r as requireFeature } from './gate-
|
|
1
|
+
export { F as FeatureOff, G as GateAnswer, b as GateContext, c as GateFeature, d as GateFlag, e as GateReason, f as GateRegistry, a as GateSnapshot, g as GateSnapshotOptions, I as IdSet, S as SHIPPED_STATUSES, h as featureOn, i as fromSnapshot, j as gateSnapshot, k as isSnapshotStale, r as requireFeature } from './gate-4OB4ddHv.js';
|
|
2
2
|
import { a as FeatureStatus } from './types-Bd766VxF.js';
|
|
3
3
|
import { F as FeaturePlatform } from './platforms-NR0liM8L.js';
|
|
4
4
|
export { a as FEATURE_PLATFORMS } from './platforms-NR0liM8L.js';
|
package/dist/gate.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { FeatureOff, SHIPPED_STATUSES, featureOn, fromSnapshot, gateSnapshot, isSnapshotStale, requireFeature } from './chunk-
|
|
1
|
+
export { FeatureOff, SHIPPED_STATUSES, featureOn, fromSnapshot, gateSnapshot, isSnapshotStale, requireFeature } from './chunk-U2RFA7VK.js';
|
|
2
2
|
export { FEATURE_PLATFORMS } from './chunk-B6WRD3WF.js';
|
|
3
3
|
export { statusOn } from './chunk-OW46SL2G.js';
|
|
4
4
|
//# sourceMappingURL=gate.js.map
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { F as Features, b as FeatureRecord, a as Flags } from './model-8dMGbgtM.js';
|
|
2
2
|
export { c as FEATURE_HORIZONS, d as FEATURE_LAYERS, e as FeatureDef, f as FeatureHorizon, g as FeatureIdOf, h as FeatureLayer, i as FeatureLinks, j as FeatureMedia, k as FeatureRegistryError, l as FeatureVisibility, m as FindOptions, n as FlagDef, o as defineFeatures, p as defineFlags, q as expiredFlags, r as featureSchema, s as findFeatures, t as flagSchema, u as flagsForFeature, v as toRecords } from './model-8dMGbgtM.js';
|
|
3
|
-
export { BlockContributions, BlockDataUse, BlockDef, BlockError, BlockMigration, BlockNavItem, BlockPrivacy, BlockRoute, BlockSettingsRow, Contributed, EnabledBlocks, ResolveBlocksOptions, ResolvedBlocks, defineBlock, resolveBlocks } from './blocks.js';
|
|
4
|
-
export { F as FeatureOff, G as GateAnswer, b as GateContext, c as GateFeature, d as GateFlag, e as GateReason, f as GateRegistry, a as GateSnapshot, g as GateSnapshotOptions, I as IdSet, S as SHIPPED_STATUSES, h as featureOn, i as fromSnapshot, j as gateSnapshot, k as isSnapshotStale, r as requireFeature } from './gate-
|
|
3
|
+
export { BlockContributions, BlockDataUse, BlockDef, BlockError, BlockMigration, BlockNavItem, BlockPrivacy, BlockRoute, BlockSettingsRow, CONTENT_PACK_FIELD_TARGETS, ContentPackDef, ContentPackError, ContentPackFieldDefinition, ContentPackFieldTarget, ContentPackForm, ContentPackMetricTemplate, ContentPackRoadmapTemplate, ContentPackSessionType, Contributed, EnabledBlocks, ResolveBlocksOptions, ResolvedBlocks, contentPackBlocks, contentPackProblems, defineBlock, defineContentPack, resolveBlocks } from './blocks.js';
|
|
4
|
+
export { F as FeatureOff, G as GateAnswer, b as GateContext, c as GateFeature, d as GateFlag, e as GateReason, f as GateRegistry, a as GateSnapshot, g as GateSnapshotOptions, I as IdSet, S as SHIPPED_STATUSES, h as featureOn, i as fromSnapshot, j as gateSnapshot, k as isSnapshotStale, r as requireFeature } from './gate-4OB4ddHv.js';
|
|
5
5
|
export { a as FEATURE_PLATFORMS, F as FeaturePlatform } from './platforms-NR0liM8L.js';
|
|
6
6
|
export { d as FEATURE_STATUSES, e as FLAG_KINDS, b as FeatureAccess, a as FeatureStatus, c as FlagKind, F as FlagValue } from './types-Bd766VxF.js';
|
|
7
7
|
export { statusOn } from './gate.js';
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export { BlockError, defineBlock, resolveBlocks } from './chunk-
|
|
2
|
-
export { FeatureOff, SHIPPED_STATUSES, featureOn, fromSnapshot, gateSnapshot, isSnapshotStale, requireFeature } from './chunk-
|
|
1
|
+
export { BlockError, CONTENT_PACK_FIELD_TARGETS, ContentPackError, contentPackBlocks, contentPackProblems, defineBlock, defineContentPack, resolveBlocks } from './chunk-OBVR6AZR.js';
|
|
2
|
+
export { FeatureOff, SHIPPED_STATUSES, featureOn, fromSnapshot, gateSnapshot, isSnapshotStale, requireFeature } from './chunk-U2RFA7VK.js';
|
|
3
3
|
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, replaceAgentsBlock, toAgentsMarkdown, toJson, toMarketingMarkdown, toOpenFeatureManifest, toRecords, toSkillMarkdown } from './chunk-JMXJZT6O.js';
|
|
4
4
|
export { cycleProblems, dependencyOrder, requirementProblem, requiresProblems } from './chunk-VYUX7VAX.js';
|
|
5
5
|
export { FEATURE_PLATFORMS } from './chunk-B6WRD3WF.js';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@marktiderman/genesis-features",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -69,9 +69,9 @@
|
|
|
69
69
|
}
|
|
70
70
|
},
|
|
71
71
|
"devDependencies": {
|
|
72
|
-
"@marktiderman/genesis-core": "^1.
|
|
72
|
+
"@marktiderman/genesis-core": "^1.12.0",
|
|
73
73
|
"@marktiderman/genesis-design-system": "^1.5.0",
|
|
74
|
-
"@marktiderman/genesis-ui": "^2.
|
|
74
|
+
"@marktiderman/genesis-ui": "^2.17.1",
|
|
75
75
|
"@testing-library/react": "^16.3.2",
|
|
76
76
|
"@types/node": "^22.9.0",
|
|
77
77
|
"@types/react": "^19.2.14",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/blocks.ts"],"names":[],"mappings":";;;;AAwJO,IAAM,UAAA,GAAN,cAAyB,KAAA,CAAM;AAAA,EACpC,YAAqB,QAAA,EAAoB;AACvC,IAAA,KAAA,CAAM,CAAA;AAAA,EAAoB,QAAA,CAAS,GAAA,CAAI,CAAC,CAAA,KAAM,CAAA,IAAA,EAAO,CAAC,CAAA,CAAE,CAAA,CAAE,IAAA,CAAK,IAAI,CAAC,CAAA,CAAE,CAAA;AADnD,IAAA,IAAA,CAAA,QAAA,GAAA,QAAA;AAEnB,IAAA,IAAA,CAAK,IAAA,GAAO,YAAA;AAAA,EACd;AAAA,EAHqB,QAAA;AAIvB;AAGA,IAAM,EAAA,GAAK,qCAAA;AAEX,IAAM,iBAAA,GAAoB,CAAC,KAAA,EAAO,UAAA,EAAY,UAAU,OAAA,EAAS,YAAA,EAAc,UAAU,SAAS,CAAA;AAElG,SAAS,WAAW,MAAA,EAAqC;AACvD,EAAA,MAAM,IAAA,uBAAW,GAAA,EAAY;AAC7B,EAAA,MAAM,GAAA,uBAAU,GAAA,EAAY;A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.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"]}
|
|
@@ -1 +0,0 @@
|
|
|
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,GA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AAW,IAAI,MAAM,CAAA;AACjD","file":"chunk-LNVWVPWB.js","sourcesContent":["/**\n * The feature gate: one answer 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"]}
|