@easy-web/core 1.5.0 → 1.7.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.
Files changed (149) hide show
  1. package/README.md +100 -2
  2. package/dist/contracts/capabilities.d.ts +38 -0
  3. package/dist/contracts/capabilities.d.ts.map +1 -1
  4. package/dist/contracts/content-composition.d.ts +144 -0
  5. package/dist/contracts/content-composition.d.ts.map +1 -0
  6. package/dist/contracts/content-composition.js +143 -0
  7. package/dist/contracts/content-composition.js.map +1 -0
  8. package/dist/contracts/index.d.ts +2 -0
  9. package/dist/contracts/index.d.ts.map +1 -1
  10. package/dist/contracts/index.js +2 -0
  11. package/dist/contracts/index.js.map +1 -1
  12. package/dist/contracts/traits.d.ts +98 -0
  13. package/dist/contracts/traits.d.ts.map +1 -0
  14. package/dist/contracts/traits.js +84 -0
  15. package/dist/contracts/traits.js.map +1 -0
  16. package/dist/demo/demo-content.d.ts +37 -0
  17. package/dist/demo/demo-content.d.ts.map +1 -0
  18. package/dist/demo/demo-content.js +171 -0
  19. package/dist/demo/demo-content.js.map +1 -0
  20. package/dist/demo/index.d.ts +3 -0
  21. package/dist/demo/index.d.ts.map +1 -0
  22. package/dist/demo/index.js +3 -0
  23. package/dist/demo/index.js.map +1 -0
  24. package/dist/demo/legal-shells.d.ts +18 -0
  25. package/dist/demo/legal-shells.d.ts.map +1 -0
  26. package/dist/demo/legal-shells.js +40 -0
  27. package/dist/demo/legal-shells.js.map +1 -0
  28. package/dist/i18n/cli-catalogs.d.ts +42 -0
  29. package/dist/i18n/cli-catalogs.d.ts.map +1 -0
  30. package/dist/i18n/cli-catalogs.js +29 -0
  31. package/dist/i18n/cli-catalogs.js.map +1 -0
  32. package/dist/i18n/create-localization.d.ts +37 -0
  33. package/dist/i18n/create-localization.d.ts.map +1 -0
  34. package/dist/i18n/create-localization.js +68 -0
  35. package/dist/i18n/create-localization.js.map +1 -0
  36. package/dist/i18n/explicit-formatters.d.ts +20 -0
  37. package/dist/i18n/explicit-formatters.d.ts.map +1 -0
  38. package/dist/i18n/explicit-formatters.js +18 -0
  39. package/dist/i18n/explicit-formatters.js.map +1 -0
  40. package/dist/i18n/index.d.ts +4 -0
  41. package/dist/i18n/index.d.ts.map +1 -1
  42. package/dist/i18n/index.js +4 -0
  43. package/dist/i18n/index.js.map +1 -1
  44. package/dist/i18n/locale-inputs.d.ts +18 -0
  45. package/dist/i18n/locale-inputs.d.ts.map +1 -0
  46. package/dist/i18n/locale-inputs.js +73 -0
  47. package/dist/i18n/locale-inputs.js.map +1 -0
  48. package/dist/index.d.ts +1 -0
  49. package/dist/index.d.ts.map +1 -1
  50. package/dist/index.js +1 -0
  51. package/dist/index.js.map +1 -1
  52. package/dist/recipes/admission.d.ts +161 -0
  53. package/dist/recipes/admission.d.ts.map +1 -0
  54. package/dist/recipes/admission.js +85 -0
  55. package/dist/recipes/admission.js.map +1 -0
  56. package/dist/recipes/graph.d.ts +101 -0
  57. package/dist/recipes/graph.d.ts.map +1 -0
  58. package/dist/recipes/graph.js +166 -0
  59. package/dist/recipes/graph.js.map +1 -0
  60. package/dist/recipes/index.d.ts +9 -0
  61. package/dist/recipes/index.d.ts.map +1 -0
  62. package/dist/recipes/index.js +9 -0
  63. package/dist/recipes/index.js.map +1 -0
  64. package/dist/recipes/mermaid.d.ts +3 -0
  65. package/dist/recipes/mermaid.d.ts.map +1 -0
  66. package/dist/recipes/mermaid.js +79 -0
  67. package/dist/recipes/mermaid.js.map +1 -0
  68. package/dist/recipes/registry.d.ts +82 -0
  69. package/dist/recipes/registry.d.ts.map +1 -0
  70. package/dist/recipes/registry.js +40 -0
  71. package/dist/recipes/registry.js.map +1 -0
  72. package/dist/recipes/schema.d.ts +129 -0
  73. package/dist/recipes/schema.d.ts.map +1 -0
  74. package/dist/recipes/schema.js +41 -0
  75. package/dist/recipes/schema.js.map +1 -0
  76. package/dist/recipes/serialize.d.ts +20 -0
  77. package/dist/recipes/serialize.d.ts.map +1 -0
  78. package/dist/recipes/serialize.js +56 -0
  79. package/dist/recipes/serialize.js.map +1 -0
  80. package/dist/recipes/shell-recipe.d.ts +59 -0
  81. package/dist/recipes/shell-recipe.d.ts.map +1 -0
  82. package/dist/recipes/shell-recipe.js +145 -0
  83. package/dist/recipes/shell-recipe.js.map +1 -0
  84. package/dist/recipes/types.d.ts +72 -0
  85. package/dist/recipes/types.d.ts.map +1 -0
  86. package/dist/recipes/types.js +13 -0
  87. package/dist/recipes/types.js.map +1 -0
  88. package/dist/schemas/galleries.d.ts +2 -2
  89. package/dist/seo/build-info-manifest.d.ts +45 -0
  90. package/dist/seo/build-info-manifest.d.ts.map +1 -0
  91. package/dist/seo/build-info-manifest.js +39 -0
  92. package/dist/seo/build-info-manifest.js.map +1 -0
  93. package/dist/seo/build-info.d.ts +3 -0
  94. package/dist/seo/build-info.d.ts.map +1 -0
  95. package/dist/seo/build-info.js +45 -0
  96. package/dist/seo/build-info.js.map +1 -0
  97. package/dist/seo/index.d.ts +4 -0
  98. package/dist/seo/index.d.ts.map +1 -1
  99. package/dist/seo/index.js +25 -2
  100. package/dist/seo/index.js.map +1 -1
  101. package/dist/seo/routes/robots-txt.d.ts.map +1 -1
  102. package/dist/seo/routes/robots-txt.js +3 -1
  103. package/dist/seo/routes/robots-txt.js.map +1 -1
  104. package/dist/seo/routes/version-json.d.ts +4 -0
  105. package/dist/seo/routes/version-json.d.ts.map +1 -0
  106. package/dist/seo/routes/version-json.js +11 -0
  107. package/dist/seo/routes/version-json.js.map +1 -0
  108. package/package.json +17 -1
  109. package/src/components/DemoLegalShell.astro +36 -0
  110. package/src/contracts/__tests__/content-composition.test.ts +170 -0
  111. package/src/contracts/capabilities.ts +49 -0
  112. package/src/contracts/content-composition.ts +176 -0
  113. package/src/contracts/index.ts +2 -0
  114. package/src/contracts/traits.ts +107 -0
  115. package/src/demo/__tests__/demo-content.test.ts +107 -0
  116. package/src/demo/demo-content.ts +210 -0
  117. package/src/demo/index.ts +2 -0
  118. package/src/demo/legal-shells.ts +52 -0
  119. package/src/i18n/__tests__/create-localization.test.ts +138 -0
  120. package/src/i18n/__tests__/explicit-formatters.test.ts +82 -0
  121. package/src/i18n/cli-catalogs.ts +44 -0
  122. package/src/i18n/create-localization.ts +67 -0
  123. package/src/i18n/explicit-formatters.ts +36 -0
  124. package/src/i18n/index.ts +4 -0
  125. package/src/i18n/locale-inputs.ts +73 -0
  126. package/src/index.ts +1 -0
  127. package/src/recipes/__tests__/graph.test.ts +139 -0
  128. package/src/recipes/__tests__/protocol.test.ts +180 -0
  129. package/src/recipes/__tests__/serialize.test.ts +128 -0
  130. package/src/recipes/__tests__/shell-recipe.test.ts +75 -0
  131. package/src/recipes/admission.ts +77 -0
  132. package/src/recipes/graph.ts +244 -0
  133. package/src/recipes/index.ts +8 -0
  134. package/src/recipes/mermaid.ts +75 -0
  135. package/src/recipes/registry.ts +48 -0
  136. package/src/recipes/schema.ts +53 -0
  137. package/src/recipes/serialize.ts +77 -0
  138. package/src/recipes/shell-recipe.ts +162 -0
  139. package/src/recipes/types.ts +63 -0
  140. package/src/seo/__tests__/build-info-html.test.ts +19 -0
  141. package/src/seo/__tests__/build-info-integration.test.ts +107 -0
  142. package/src/seo/__tests__/build-info.test.ts +86 -0
  143. package/src/seo/__tests__/robots-txt.test.ts +8 -0
  144. package/src/seo/build-info-manifest.ts +49 -0
  145. package/src/seo/build-info.ts +44 -0
  146. package/src/seo/index.ts +28 -3
  147. package/src/seo/routes/robots-txt.ts +3 -1
  148. package/src/seo/routes/version-json.ts +13 -0
  149. package/src/seo/routes/version.astro +42 -0
@@ -0,0 +1,128 @@
1
+ import { z } from 'astro/zod';
2
+ import { describe, expect, it, vi } from 'vitest';
3
+ import type { ResolvedCapabilityGraph } from '../graph.js';
4
+ import { resolveCapabilityGraph } from '../graph.js';
5
+ import { serializeCapabilityGraphMermaid } from '../mermaid.js';
6
+ import { serializeCapabilityGraphJson, toCapabilityGraphDocument } from '../serialize.js';
7
+ import type { RecipeMetadata, RecipeOutputContribution } from '../types.js';
8
+
9
+ type RecipeFixtureOptions = {
10
+ readonly provides?: readonly string[];
11
+ readonly requires?: readonly string[];
12
+ readonly priority?: number;
13
+ readonly contributions?: readonly RecipeOutputContribution[];
14
+ };
15
+
16
+ function recipe(id: string, options: RecipeFixtureOptions = {}): RecipeMetadata {
17
+ return {
18
+ id,
19
+ version: '1.5.0',
20
+ protocolVersion: 1,
21
+ compatibleCliRange: '^0.1.0',
22
+ compatibleRuntimeRange: '^1.5.0',
23
+ provides: options.provides ?? [id],
24
+ requires: options.requires ?? [],
25
+ conflicts: [],
26
+ order: { priority: options.priority ?? 0, key: id },
27
+ optionsSchema: z.strictObject({}),
28
+ outputContributions: options.contributions ?? [],
29
+ validators: [],
30
+ generate: vi.fn(() => ({ files: [] })),
31
+ };
32
+ }
33
+
34
+ const fixtures = [
35
+ recipe('shell', {
36
+ priority: 10,
37
+ contributions: [
38
+ { kind: 'route', id: 'page.contact', target: '/contact/' },
39
+ { kind: 'file', id: 'shell.layout', target: 'src/layouts/Base.astro' },
40
+ ],
41
+ }),
42
+ recipe('article', {
43
+ provides: ['content.article'],
44
+ requires: ['shell'],
45
+ contributions: [{ kind: 'content', id: 'content.article', target: 'primary' }],
46
+ }),
47
+ recipe('gallery', {
48
+ provides: ['content.gallery'],
49
+ requires: ['content.article'],
50
+ contributions: [{ kind: 'content', id: 'content.gallery', target: 'additional' }],
51
+ }),
52
+ recipe('navigation', {
53
+ contributions: [{ kind: 'binding', id: 'binding.navigation', target: 'page.contact' }],
54
+ }),
55
+ ];
56
+
57
+ function serializeRecipes(recipes: readonly RecipeMetadata[]): string {
58
+ const graph = resolveCapabilityGraph(recipes);
59
+ expect(graph.ok).toBe(true);
60
+ if (!graph.ok) throw new Error(graph.error.code);
61
+ const document = toCapabilityGraphDocument(graph.value);
62
+ expect(document.ok).toBe(true);
63
+ if (!document.ok) throw new Error(document.error.code);
64
+ return serializeCapabilityGraphJson(document.value);
65
+ }
66
+
67
+ function minimalGraph(target: string): ResolvedCapabilityGraph {
68
+ return {
69
+ recipes: [],
70
+ capabilities: [],
71
+ requirements: [],
72
+ contributions: [{
73
+ kind: 'route', id: 'page.contact', target,
74
+ provenance: { contributedBy: 'shell', recipeVersion: '1.5.0', inclusion: { kind: 'direct' } },
75
+ }],
76
+ fixedPages: [],
77
+ contentTypes: { additional: [] },
78
+ adaptations: [],
79
+ };
80
+ }
81
+
82
+ describe('capability graph serialization', () => {
83
+ it('projects a resolved graph into the versioned JSON document shape', () => {
84
+ const parsed = JSON.parse(serializeRecipes(fixtures)) as Record<string, unknown>;
85
+
86
+ expect(Object.keys(parsed)).toEqual([
87
+ 'schemaVersion', 'recipes', 'capabilities', 'requirements',
88
+ 'contentTypes', 'fixedPages', 'bindings', 'adaptations',
89
+ ]);
90
+ expect(parsed.schemaVersion).toBe(1);
91
+ });
92
+
93
+ it('produces byte-identical JSON for shuffled recipe inputs', () => {
94
+ const permutations = [fixtures, [...fixtures].reverse(), [fixtures[2]!, fixtures[0]!, fixtures[3]!, fixtures[1]!]];
95
+
96
+ const serialized = permutations.map(serializeRecipes);
97
+
98
+ expect(serialized[1]).toBe(serialized[0]);
99
+ expect(serialized[2]).toBe(serialized[0]);
100
+ });
101
+
102
+ it('serializes the document as a Mermaid flowchart', () => {
103
+ const graph = resolveCapabilityGraph(fixtures);
104
+ expect(graph.ok).toBe(true);
105
+ if (!graph.ok) return;
106
+ const document = toCapabilityGraphDocument(graph.value);
107
+ expect(document.ok).toBe(true);
108
+ if (!document.ok) return;
109
+
110
+ const mermaid = serializeCapabilityGraphMermaid(document.value);
111
+
112
+ expect(mermaid.startsWith('flowchart TD')).toBe(true);
113
+ expect(mermaid).toContain('-->');
114
+ for (const fixture of fixtures) expect(mermaid).toContain(fixture.id);
115
+ });
116
+
117
+ it('rejects a graph document containing a private value', () => {
118
+ const result = toCapabilityGraphDocument(minimalGraph('someone@example.com'));
119
+
120
+ expect(result).toMatchObject({ ok: false, error: { code: 'private-value-detected' } });
121
+ });
122
+
123
+ it('accepts an ordinary route target', () => {
124
+ const result = toCapabilityGraphDocument(minimalGraph('/contact/'));
125
+
126
+ expect(result.ok).toBe(true);
127
+ });
128
+ });
@@ -0,0 +1,75 @@
1
+ import { describe, expect, it } from 'vitest';
2
+ import corePackage from '../../../package.json' with { type: 'json' };
3
+ import { buildShellFiles, shellRecipe } from '../shell-recipe.js';
4
+
5
+ const CONTRIBUTION_FILE_PATH: Record<string, string> = {
6
+ 'shell.astro-config': 'astro.config.mjs',
7
+ 'shell.dependencies': 'package.json',
8
+ 'shell.pnpm-workspace': 'pnpm-workspace.yaml',
9
+ 'shell.base-layout': 'src/layouts/Base.astro',
10
+ 'shell.home': 'src/pages/index.astro',
11
+ 'shell.404': 'src/pages/404.astro',
12
+ 'shell.localized-paths': 'src/lib/localized-paths.ts',
13
+ 'shell.robots': 'public/robots.txt',
14
+ 'shell.gitignore': '.gitignore',
15
+ };
16
+
17
+ describe('shell recipe', () => {
18
+ it('generates a file for every declared contribution', () => {
19
+ const files = buildShellFiles({});
20
+ const filePaths = new Set(files.map((file) => file.path));
21
+
22
+ for (const contribution of shellRecipe.outputContributions) {
23
+ const expectedPath = CONTRIBUTION_FILE_PATH[contribution.id];
24
+ expect(expectedPath, `missing file-path mapping for ${contribution.id}`).toBeDefined();
25
+ expect(filePaths.has(expectedPath!), `missing generated file for ${contribution.id} at ${expectedPath}`).toBe(true);
26
+ }
27
+ expect(files.length).toBe(shellRecipe.outputContributions.length);
28
+ });
29
+
30
+ it('wires the SEO integration into astro.config.mjs', () => {
31
+ const files = buildShellFiles({});
32
+ const config = files.find((file) => file.path === 'astro.config.mjs')!;
33
+ expect(config.content).toContain('easyWebSeo');
34
+ expect(config.content).toContain('replace-with-your-domain.example');
35
+ });
36
+
37
+ it('sets noIndex true in config when the option is enabled', () => {
38
+ const files = buildShellFiles({ noIndex: true });
39
+ const config = files.find((file) => file.path === 'astro.config.mjs')!;
40
+ expect(config.content).toContain('noIndex: true');
41
+ });
42
+
43
+ it('never emits a real domain', () => {
44
+ const files = buildShellFiles({});
45
+ for (const file of files) {
46
+ expect(file.content).not.toMatch(/ismaili\.de|harleyrentflorida|party200|tv-1927/);
47
+ }
48
+ });
49
+
50
+ it('gitignores node_modules', () => {
51
+ const files = buildShellFiles({});
52
+ const gitignore = files.find((file) => file.path === '.gitignore')!;
53
+ expect(gitignore.content).toContain('node_modules');
54
+ });
55
+
56
+ it('keeps the generated Astro range inside the core peer range', () => {
57
+ const files = buildShellFiles({});
58
+ const manifestFile = files.find((file) => file.path === 'package.json')!;
59
+ const manifest = JSON.parse(manifestFile.content) as { dependencies: { astro: string } };
60
+ const generatedMinimum = Number(/^\^(\d+)\./.exec(manifest.dependencies.astro)?.[1]);
61
+ const peerBounds = /^>=(\d+)\.0\.0 <(\d+)\.0\.0$/.exec(corePackage.peerDependencies.astro);
62
+
63
+ expect(peerBounds, 'core Astro peer range must retain explicit major bounds').not.toBeNull();
64
+ expect(generatedMinimum).toBeGreaterThanOrEqual(Number(peerBounds![1]));
65
+ expect(generatedMinimum).toBeLessThan(Number(peerBounds![2]));
66
+ expect(manifest.dependencies.astro).toBe('^7.3.5');
67
+ });
68
+
69
+ it('allows required dependency builds under pnpm 11', () => {
70
+ const files = buildShellFiles({});
71
+ const workspace = files.find((file) => file.path === 'pnpm-workspace.yaml')!;
72
+
73
+ expect(workspace.content).toBe('allowBuilds:\n esbuild: true\n sharp: true\n');
74
+ });
75
+ });
@@ -0,0 +1,77 @@
1
+ import { z } from 'astro/zod';
2
+ import { recipeArtifactReceiptSchema, recipeRegistryManifestSchema } from './registry.js';
3
+ import { recipeMetadataSchema } from './types.js';
4
+
5
+ export interface RecipeCompatibilityPolicy {
6
+ readonly cliVersion: string;
7
+ readonly runtimeVersion: string;
8
+ /** Return false for invalid semver ranges as well as out-of-range versions. */
9
+ readonly satisfies: (version: string, range: string) => boolean;
10
+ }
11
+
12
+ export const recipeAdmissionInputSchema = z.strictObject({
13
+ registry: recipeRegistryManifestSchema,
14
+ artifacts: z.array(z.strictObject({
15
+ receipt: recipeArtifactReceiptSchema,
16
+ recipe: recipeMetadataSchema,
17
+ }).readonly()).readonly(),
18
+ }).readonly();
19
+
20
+ /**
21
+ * Pure admission only: checks an explicitly selected set, never selects dependencies,
22
+ * sorts recipes, emits a capability graph, imports sources or invokes any hook.
23
+ * Receipts cannot prove byte integrity: the trusted loader must hash BEFORE import.
24
+ */
25
+ export function createRecipeAdmissionSchema(policy: RecipeCompatibilityPolicy) {
26
+ return recipeAdmissionInputSchema.superRefine(({ registry, artifacts }, context) => {
27
+ const fail = (message: string, index: number) => context.addIssue({
28
+ code: 'custom', message, path: ['artifacts', index],
29
+ });
30
+ const providers = new Map<string, number>();
31
+ const ids = new Set<string>();
32
+ for (const [index, { recipe, receipt }] of artifacts.entries()) {
33
+ const pinned = registry.recipes.some((pin) =>
34
+ pin.packageName === receipt.pin.packageName && pin.version === receipt.pin.version &&
35
+ pin.integrity === receipt.pin.integrity && pin.exportPath === receipt.pin.exportPath);
36
+ if (!pinned) fail('source-outside-pinned-set', index);
37
+ if (receipt.verifiedIntegrity !== receipt.pin.integrity) fail('artifact-integrity-mismatch', index);
38
+ if (recipe.version !== receipt.pin.version) fail('recipe-version-mismatch', index);
39
+ if (!policy.satisfies(policy.cliVersion, recipe.compatibleCliRange)) fail('incompatible-cli-range', index);
40
+ if (!policy.satisfies(policy.runtimeVersion, recipe.compatibleRuntimeRange)) fail('incompatible-runtime-range', index);
41
+ if (ids.has(recipe.id)) fail('duplicate-recipe-id', index);
42
+ ids.add(recipe.id);
43
+ for (const capability of recipe.provides) {
44
+ if (providers.has(capability)) fail('duplicate-provider-id', index);
45
+ providers.set(capability, index);
46
+ }
47
+ for (const field of ['requires', 'conflicts'] as const) {
48
+ if (new Set(recipe[field]).size !== recipe[field].length) fail(`duplicate-${field}`, index);
49
+ }
50
+ }
51
+ for (const [index, { recipe }] of artifacts.entries()) {
52
+ for (const requirement of recipe.requires) {
53
+ if (!providers.has(requirement)) fail('missing-requirement', index);
54
+ }
55
+ for (const conflict of recipe.conflicts) {
56
+ if (providers.has(conflict)) fail('conflicting-capability', index);
57
+ }
58
+ }
59
+ // Reachability validation, not topological ordering or a graph resolver.
60
+ const complete = new Set<number>();
61
+ const active = new Set<number>();
62
+ const visit = (index: number): void => {
63
+ if (active.has(index)) { fail('dependency-cycle', index); return; }
64
+ if (complete.has(index)) return;
65
+ const artifact = artifacts[index];
66
+ if (!artifact) return;
67
+ active.add(index);
68
+ for (const requirement of artifact.recipe.requires) {
69
+ const provider = providers.get(requirement);
70
+ if (provider !== undefined) visit(provider);
71
+ }
72
+ active.delete(index);
73
+ complete.add(index);
74
+ };
75
+ for (const index of artifacts.keys()) visit(index);
76
+ });
77
+ }
@@ -0,0 +1,244 @@
1
+ import type { RecipeOutputContribution } from './schema.js';
2
+ import type { RecipeMetadata } from './types.js';
3
+
4
+ export type GraphResult<T, E> =
5
+ | { readonly ok: true; readonly value: T }
6
+ | { readonly ok: false; readonly error: E };
7
+
8
+ export type RecipeInclusion =
9
+ | { readonly kind: 'direct' }
10
+ | { readonly kind: 'transitive'; readonly requiredBy: readonly string[] };
11
+
12
+ export type GraphProvenance = {
13
+ readonly contributedBy: string;
14
+ readonly recipeVersion: string;
15
+ readonly inclusion: RecipeInclusion;
16
+ };
17
+
18
+ export type ResolvedRecipeNode = {
19
+ readonly id: string;
20
+ readonly version: string;
21
+ readonly provides: readonly string[];
22
+ readonly requires: readonly string[];
23
+ readonly conflicts: readonly string[];
24
+ readonly provenance: GraphProvenance;
25
+ };
26
+
27
+ export type ResolvedCapabilityNode = {
28
+ readonly id: string;
29
+ readonly providerRecipeId: string;
30
+ readonly provenance: GraphProvenance;
31
+ };
32
+
33
+ export type ResolvedRequirementEdge = {
34
+ readonly capability: string;
35
+ readonly consumerRecipeId: string;
36
+ readonly providerRecipeId: string;
37
+ };
38
+
39
+ export type ResolvedContributionNode = RecipeOutputContribution & {
40
+ readonly provenance: GraphProvenance;
41
+ };
42
+
43
+ export type ResolvedAdaptationNode = ResolvedContributionNode & {
44
+ readonly kind: 'binding';
45
+ readonly targetContributionId: string;
46
+ };
47
+
48
+ export type ResolvedCapabilityGraph = {
49
+ readonly recipes: readonly ResolvedRecipeNode[];
50
+ readonly capabilities: readonly ResolvedCapabilityNode[];
51
+ readonly requirements: readonly ResolvedRequirementEdge[];
52
+ readonly contributions: readonly ResolvedContributionNode[];
53
+ readonly fixedPages: readonly ResolvedContributionNode[];
54
+ readonly contentTypes: {
55
+ readonly primary?: ResolvedContributionNode;
56
+ readonly additional: readonly ResolvedContributionNode[];
57
+ };
58
+ readonly adaptations: readonly ResolvedAdaptationNode[];
59
+ };
60
+
61
+ export type GraphResolutionError =
62
+ | { readonly code: 'duplicate-recipe-id'; readonly recipeId: string }
63
+ | { readonly code: 'duplicate-provider'; readonly capability: string; readonly recipeIds: readonly string[] }
64
+ | { readonly code: 'missing-requirement'; readonly recipeId: string; readonly capability: string }
65
+ | { readonly code: 'dependency-cycle'; readonly recipeIds: readonly string[] }
66
+ | { readonly code: 'conflicting-capability'; readonly recipeId: string; readonly conflictingRecipeId: string; readonly capability: string }
67
+ | { readonly code: 'duplicate-contribution-id'; readonly contributionId: string; readonly recipeIds: readonly string[] }
68
+ | { readonly code: 'output-conflict'; readonly kind: 'file' | 'route'; readonly target: string; readonly recipeIds: readonly string[] }
69
+ | { readonly code: 'invalid-content-role'; readonly contributionId: string; readonly target: string }
70
+ | { readonly code: 'multiple-primary-content'; readonly contributionIds: readonly string[]; readonly recipeIds: readonly string[] };
71
+
72
+ const compareText = (left: string, right: string): number => left.localeCompare(right, 'en');
73
+ const compareRecipe = (left: RecipeMetadata, right: RecipeMetadata): number =>
74
+ left.order.priority - right.order.priority || compareText(left.order.key, right.order.key) || compareText(left.id, right.id);
75
+ const compareContribution = (left: ResolvedContributionNode, right: ResolvedContributionNode): number =>
76
+ compareText(left.kind, right.kind) || compareText(left.id, right.id) || compareText(left.target, right.target) ||
77
+ compareText(left.provenance.contributedBy, right.provenance.contributedBy);
78
+ const failure = <E extends GraphResolutionError>(error: E): GraphResult<never, E> => ({ ok: false, error });
79
+
80
+ /**
81
+ * Resolves admitted in-memory recipe metadata without executing hooks or observing a target.
82
+ * Route contributions are fixed pages. Content targets are `primary` or `additional`.
83
+ * Binding ids prefixed with `adaptation.` activate only when their target contribution exists.
84
+ */
85
+ export function resolveCapabilityGraph(
86
+ recipes: readonly RecipeMetadata[],
87
+ ): GraphResult<ResolvedCapabilityGraph, GraphResolutionError> {
88
+ const canonical = [...recipes].sort(compareRecipe);
89
+ const recipeById = new Map<string, RecipeMetadata>();
90
+ const providerByCapability = new Map<string, RecipeMetadata>();
91
+
92
+ for (const recipe of canonical) {
93
+ if (recipeById.has(recipe.id)) return failure({ code: 'duplicate-recipe-id', recipeId: recipe.id });
94
+ recipeById.set(recipe.id, recipe);
95
+ for (const capability of [...recipe.provides].sort(compareText)) {
96
+ const provider = providerByCapability.get(capability);
97
+ if (provider) {
98
+ return failure({
99
+ code: 'duplicate-provider', capability,
100
+ recipeIds: [provider.id, recipe.id].sort(compareText),
101
+ });
102
+ }
103
+ providerByCapability.set(capability, recipe);
104
+ }
105
+ }
106
+
107
+ const requirements: ResolvedRequirementEdge[] = [];
108
+ const dependencyIds = new Map<string, Set<string>>();
109
+ const requiredBy = new Map<string, Set<string>>();
110
+ for (const recipe of canonical) {
111
+ const dependencies = new Set<string>();
112
+ for (const capability of [...recipe.requires].sort(compareText)) {
113
+ const provider = providerByCapability.get(capability);
114
+ if (!provider) return failure({ code: 'missing-requirement', recipeId: recipe.id, capability });
115
+ dependencies.add(provider.id);
116
+ const consumers = requiredBy.get(provider.id) ?? new Set<string>();
117
+ consumers.add(recipe.id);
118
+ requiredBy.set(provider.id, consumers);
119
+ requirements.push({ capability, consumerRecipeId: recipe.id, providerRecipeId: provider.id });
120
+ }
121
+ dependencyIds.set(recipe.id, dependencies);
122
+ }
123
+
124
+ const visiting = new Set<string>();
125
+ const visited = new Set<string>();
126
+ const stack: string[] = [];
127
+ const findCycle = (recipeId: string): readonly string[] | undefined => {
128
+ if (visiting.has(recipeId)) {
129
+ const start = stack.indexOf(recipeId);
130
+ return [...stack.slice(start), recipeId];
131
+ }
132
+ if (visited.has(recipeId)) return undefined;
133
+ visiting.add(recipeId);
134
+ stack.push(recipeId);
135
+ const dependencies = [...(dependencyIds.get(recipeId) ?? [])].sort(compareText);
136
+ for (const dependencyId of dependencies) {
137
+ const cycle = findCycle(dependencyId);
138
+ if (cycle) return cycle;
139
+ }
140
+ stack.pop();
141
+ visiting.delete(recipeId);
142
+ visited.add(recipeId);
143
+ return undefined;
144
+ };
145
+ for (const recipe of canonical) {
146
+ const cycle = findCycle(recipe.id);
147
+ if (cycle) return failure({ code: 'dependency-cycle', recipeIds: cycle });
148
+ }
149
+
150
+ for (const recipe of canonical) {
151
+ for (const capability of [...recipe.conflicts].sort(compareText)) {
152
+ const provider = providerByCapability.get(capability);
153
+ if (provider) {
154
+ return failure({
155
+ code: 'conflicting-capability', recipeId: recipe.id,
156
+ conflictingRecipeId: provider.id, capability,
157
+ });
158
+ }
159
+ }
160
+ }
161
+
162
+ const contributionOwners = new Map<string, RecipeMetadata>();
163
+ const outputOwners = new Map<string, RecipeMetadata>();
164
+ for (const recipe of canonical) {
165
+ for (const contribution of [...recipe.outputContributions].sort((left, right) => compareText(left.id, right.id))) {
166
+ const idOwner = contributionOwners.get(contribution.id);
167
+ if (idOwner) {
168
+ return failure({
169
+ code: 'duplicate-contribution-id', contributionId: contribution.id,
170
+ recipeIds: [idOwner.id, recipe.id].sort(compareText),
171
+ });
172
+ }
173
+ contributionOwners.set(contribution.id, recipe);
174
+ if (contribution.kind === 'file' || contribution.kind === 'route') {
175
+ const key = `${contribution.kind}:${contribution.target}`;
176
+ const outputOwner = outputOwners.get(key);
177
+ if (outputOwner) {
178
+ return failure({
179
+ code: 'output-conflict', kind: contribution.kind, target: contribution.target,
180
+ recipeIds: [outputOwner.id, recipe.id].sort(compareText),
181
+ });
182
+ }
183
+ outputOwners.set(key, recipe);
184
+ }
185
+ if (contribution.kind === 'content' && contribution.target !== 'primary' && contribution.target !== 'additional') {
186
+ return failure({ code: 'invalid-content-role', contributionId: contribution.id, target: contribution.target });
187
+ }
188
+ }
189
+ }
190
+
191
+ const ordered: RecipeMetadata[] = [];
192
+ const remainingDependencies = new Map([...dependencyIds].map(([id, values]) => [id, new Set(values)]));
193
+ while (ordered.length < canonical.length) {
194
+ const ready = canonical.filter((recipe) =>
195
+ !ordered.some((item) => item.id === recipe.id) && remainingDependencies.get(recipe.id)?.size === 0);
196
+ const next = ready.sort(compareRecipe)[0];
197
+ if (!next) break;
198
+ ordered.push(next);
199
+ for (const dependencies of remainingDependencies.values()) dependencies.delete(next.id);
200
+ }
201
+
202
+ const provenanceFor = (recipe: RecipeMetadata): GraphProvenance => {
203
+ const consumers = [...(requiredBy.get(recipe.id) ?? [])].sort(compareText);
204
+ return {
205
+ contributedBy: recipe.id,
206
+ recipeVersion: recipe.version,
207
+ inclusion: consumers.length === 0 ? { kind: 'direct' } : { kind: 'transitive', requiredBy: consumers },
208
+ };
209
+ };
210
+ const contributions = ordered.flatMap((recipe) => recipe.outputContributions
211
+ .filter((item) => !item.id.startsWith('adaptation.') || contributionOwners.has(item.target))
212
+ .map((item) => ({ ...item, provenance: provenanceFor(recipe) })))
213
+ .sort(compareContribution);
214
+ const primary = contributions.filter((item) => item.kind === 'content' && item.target === 'primary');
215
+ if (primary.length > 1) {
216
+ return failure({
217
+ code: 'multiple-primary-content',
218
+ contributionIds: primary.map((item) => item.id).sort(compareText),
219
+ recipeIds: primary.map((item) => item.provenance.contributedBy).sort(compareText),
220
+ });
221
+ }
222
+
223
+ return { ok: true, value: {
224
+ recipes: ordered.map((recipe) => ({
225
+ id: recipe.id, version: recipe.version,
226
+ provides: [...recipe.provides].sort(compareText),
227
+ requires: [...recipe.requires].sort(compareText),
228
+ conflicts: [...recipe.conflicts].sort(compareText),
229
+ provenance: provenanceFor(recipe),
230
+ })),
231
+ capabilities: [...providerByCapability].sort(([left], [right]) => compareText(left, right))
232
+ .map(([id, provider]) => ({ id, providerRecipeId: provider.id, provenance: provenanceFor(provider) })),
233
+ requirements: requirements.sort((left, right) => compareText(left.consumerRecipeId, right.consumerRecipeId) || compareText(left.capability, right.capability)),
234
+ contributions,
235
+ fixedPages: contributions.filter((item) => item.kind === 'route'),
236
+ contentTypes: {
237
+ ...(primary[0] ? { primary: primary[0] } : {}),
238
+ additional: contributions.filter((item) => item.kind === 'content' && item.target === 'additional'),
239
+ },
240
+ adaptations: contributions.filter((item): item is ResolvedAdaptationNode =>
241
+ item.kind === 'binding' && item.id.startsWith('adaptation.'))
242
+ .map((item) => ({ ...item, targetContributionId: item.target })),
243
+ } };
244
+ }
@@ -0,0 +1,8 @@
1
+ export * from './schema.js';
2
+ export * from './types.js';
3
+ export * from './registry.js';
4
+ export * from './admission.js';
5
+ export * from './graph.js';
6
+ export * from './serialize.js';
7
+ export * from './mermaid.js';
8
+ export * from './shell-recipe.js';
@@ -0,0 +1,75 @@
1
+ import type { CapabilityGraphDocument } from './serialize.js';
2
+
3
+ function sanitizeId(prefix: string, raw: string, used: Set<string>): string {
4
+ const base = `${prefix}_${raw.replace(/[^A-Za-z0-9_]/g, '_')}`;
5
+ let candidate = base;
6
+ let n = 1;
7
+ while (used.has(candidate)) candidate = `${base}_${n++}`;
8
+ used.add(candidate);
9
+ return candidate;
10
+ }
11
+
12
+ function escapeLabel(text: string): string {
13
+ return text
14
+ .replace(/&/g, '#38;')
15
+ .replace(/"/g, '#34;')
16
+ .replace(/</g, '#60;')
17
+ .replace(/>/g, '#62;');
18
+ }
19
+
20
+ export function serializeCapabilityGraphMermaid(document: CapabilityGraphDocument): string {
21
+ const used = new Set<string>();
22
+ const lines: string[] = ['flowchart TD'];
23
+ const recipeIds = new Map<string, string>();
24
+ const capabilityIds = new Map<string, string>();
25
+
26
+ for (const recipe of document.recipes) {
27
+ const id = sanitizeId('r', recipe.id, used);
28
+ recipeIds.set(recipe.id, id);
29
+ lines.push(` ${id}["${escapeLabel(recipe.id)}@${escapeLabel(recipe.version)}"]`);
30
+ }
31
+ for (const capability of document.capabilities) {
32
+ const id = sanitizeId('c', capability.id, used);
33
+ capabilityIds.set(capability.id, id);
34
+ lines.push(` ${id}(["${escapeLabel(capability.id)}"])`);
35
+ const providerId = recipeIds.get(capability.providerRecipeId);
36
+ if (providerId) lines.push(` ${providerId} -->|provides| ${id}`);
37
+ }
38
+ for (const requirement of document.requirements) {
39
+ const consumerId = recipeIds.get(requirement.consumerRecipeId);
40
+ const capabilityId = capabilityIds.get(requirement.capability);
41
+ if (consumerId && capabilityId) lines.push(` ${consumerId} -.->|requires| ${capabilityId}`);
42
+ }
43
+ for (const page of document.fixedPages) {
44
+ const id = sanitizeId('p', page.id, used);
45
+ lines.push(` ${id}["page: ${escapeLabel(page.target)}"]`);
46
+ const ownerId = recipeIds.get(page.provenance.contributedBy);
47
+ if (ownerId) lines.push(` ${ownerId} -->|fixed page| ${id}`);
48
+ }
49
+ if (document.contentTypes.primary) {
50
+ const content = document.contentTypes.primary;
51
+ const id = sanitizeId('t', content.id, used);
52
+ lines.push(` ${id}["primary content: ${escapeLabel(content.target)}"]`);
53
+ const ownerId = recipeIds.get(content.provenance.contributedBy);
54
+ if (ownerId) lines.push(` ${ownerId} -->|content| ${id}`);
55
+ }
56
+ for (const content of document.contentTypes.additional) {
57
+ const id = sanitizeId('t', content.id, used);
58
+ lines.push(` ${id}["content: ${escapeLabel(content.target)}"]`);
59
+ const ownerId = recipeIds.get(content.provenance.contributedBy);
60
+ if (ownerId) lines.push(` ${ownerId} -->|content| ${id}`);
61
+ }
62
+ for (const binding of document.bindings) {
63
+ const id = sanitizeId('b', binding.id, used);
64
+ lines.push(` ${id}["binding: ${escapeLabel(binding.target)}"]`);
65
+ const ownerId = recipeIds.get(binding.provenance.contributedBy);
66
+ if (ownerId) lines.push(` ${ownerId} -->|binds| ${id}`);
67
+ }
68
+ for (const adaptation of document.adaptations) {
69
+ const id = sanitizeId('a', adaptation.id, used);
70
+ lines.push(` ${id}["adaptation -> ${escapeLabel(adaptation.targetContributionId)}"]`);
71
+ const ownerId = recipeIds.get(adaptation.provenance.contributedBy);
72
+ if (ownerId) lines.push(` ${ownerId} -.->|adapts| ${id}`);
73
+ }
74
+ return `${lines.join('\n')}\n`;
75
+ }
@@ -0,0 +1,48 @@
1
+ import { z } from 'astro/zod';
2
+ import { RECIPE_PROTOCOL_VERSION, recipeVersionSchema } from './schema.js';
3
+
4
+ /** Closed first-party owners, not an open @easy-web/* namespace trust rule. */
5
+ export const recipePackageNameSchema = z.enum([
6
+ '@easy-web/core', '@easy-web/cms-adapters', '@easy-web/swa', '@easy-web/auth', '@easy-web/brand',
7
+ ]);
8
+
9
+ export const recipeIntegritySchema = z.string().regex(/^sha512-[A-Za-z0-9+/]{86}==$/);
10
+ export const recipeExportPathSchema = z.string().regex(/^\.\/[a-zA-Z0-9_-]+(?:\/[a-zA-Z0-9_-]+)*(?:\.[a-zA-Z0-9_-]+)?$/);
11
+
12
+ /**
13
+ * CLI-owned pins are the authority. NEVER load recipes from a generation target's
14
+ * node_modules. Only CLI-pinned or bundled verified artifacts may be imported.
15
+ * This manifest describes a loader contract; it performs no import or I/O.
16
+ */
17
+ export const recipeRegistryPinSchema = z.strictObject({
18
+ packageName: recipePackageNameSchema,
19
+ version: recipeVersionSchema,
20
+ integrity: recipeIntegritySchema,
21
+ exportPath: recipeExportPathSchema,
22
+ }).readonly();
23
+
24
+ export const recipeRegistryManifestSchema = z.strictObject({
25
+ protocolVersion: z.literal(RECIPE_PROTOCOL_VERSION),
26
+ recipes: z.array(recipeRegistryPinSchema).readonly(),
27
+ }).superRefine((manifest, context) => {
28
+ const sources = new Set<string>();
29
+ for (const pin of manifest.recipes) {
30
+ const key = `${pin.packageName}:${pin.exportPath}`;
31
+ if (sources.has(key)) {
32
+ context.addIssue({ code: 'custom', message: 'duplicate-registry-source', path: ['recipes'] });
33
+ }
34
+ sources.add(key);
35
+ }
36
+ }).readonly();
37
+
38
+ /** Receipt supplied by the future loader AFTER hashing artifact bytes, BEFORE import. */
39
+ export const recipeArtifactReceiptSchema = z.strictObject({
40
+ source: z.enum(['cli-pinned', 'bundled']),
41
+ pin: recipeRegistryPinSchema,
42
+ verifiedIntegrity: recipeIntegritySchema,
43
+ }).readonly();
44
+
45
+ export type RecipeRegistryPin = z.infer<typeof recipeRegistryPinSchema>;
46
+ export type RecipeRegistryManifest = z.infer<typeof recipeRegistryManifestSchema>;
47
+ export type RecipeArtifactReceipt = z.infer<typeof recipeArtifactReceiptSchema>;
48
+ export const recipeRegistryJsonSchema = z.toJSONSchema(recipeRegistryManifestSchema);