@easy-web/core 1.5.0 → 1.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.
Files changed (120) hide show
  1. package/README.md +42 -1
  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/package.json +17 -1
  90. package/src/components/DemoLegalShell.astro +36 -0
  91. package/src/contracts/__tests__/content-composition.test.ts +170 -0
  92. package/src/contracts/capabilities.ts +49 -0
  93. package/src/contracts/content-composition.ts +176 -0
  94. package/src/contracts/index.ts +2 -0
  95. package/src/contracts/traits.ts +107 -0
  96. package/src/demo/__tests__/demo-content.test.ts +107 -0
  97. package/src/demo/demo-content.ts +210 -0
  98. package/src/demo/index.ts +2 -0
  99. package/src/demo/legal-shells.ts +52 -0
  100. package/src/i18n/__tests__/create-localization.test.ts +138 -0
  101. package/src/i18n/__tests__/explicit-formatters.test.ts +82 -0
  102. package/src/i18n/cli-catalogs.ts +44 -0
  103. package/src/i18n/create-localization.ts +67 -0
  104. package/src/i18n/explicit-formatters.ts +36 -0
  105. package/src/i18n/index.ts +4 -0
  106. package/src/i18n/locale-inputs.ts +73 -0
  107. package/src/index.ts +1 -0
  108. package/src/recipes/__tests__/graph.test.ts +139 -0
  109. package/src/recipes/__tests__/protocol.test.ts +180 -0
  110. package/src/recipes/__tests__/serialize.test.ts +128 -0
  111. package/src/recipes/__tests__/shell-recipe.test.ts +75 -0
  112. package/src/recipes/admission.ts +77 -0
  113. package/src/recipes/graph.ts +244 -0
  114. package/src/recipes/index.ts +8 -0
  115. package/src/recipes/mermaid.ts +75 -0
  116. package/src/recipes/registry.ts +48 -0
  117. package/src/recipes/schema.ts +53 -0
  118. package/src/recipes/serialize.ts +77 -0
  119. package/src/recipes/shell-recipe.ts +162 -0
  120. package/src/recipes/types.ts +63 -0
@@ -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);
@@ -0,0 +1,53 @@
1
+ import { z } from 'astro/zod';
2
+
3
+ /** Increment only for a breaking recipe protocol change, independently of package semver. */
4
+ export const RECIPE_PROTOCOL_VERSION = 1 as const;
5
+
6
+ export const recipeIdSchema = z.string().regex(/^[a-zA-Z][a-zA-Z0-9]*(?:[./:-][a-zA-Z0-9]+)*$/);
7
+ export const recipeVersionSchema = z.string().regex(
8
+ /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*)?(?:\+[0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*)?$/,
9
+ );
10
+ /** Semver range syntax and satisfaction are checked by the resolver's semver policy. */
11
+ export const recipeCompatibilityRangeSchema = z.string().trim().min(1);
12
+
13
+ export const recipeOutputContributionSchema = z.strictObject({
14
+ kind: z.enum(['file', 'dependency', 'route', 'content', 'binding', 'configuration']),
15
+ id: recipeIdSchema,
16
+ /** Logical destination; filesystem path safety belongs to the generation boundary. */
17
+ target: z.string().min(1),
18
+ }).readonly();
19
+
20
+ export const recipeValidatorDescriptorSchema = z.strictObject({
21
+ id: recipeIdSchema,
22
+ phase: z.enum(['options', 'output']),
23
+ }).readonly();
24
+
25
+ export const recipeMetadataFields = {
26
+ id: recipeIdSchema,
27
+ version: recipeVersionSchema,
28
+ protocolVersion: z.literal(RECIPE_PROTOCOL_VERSION),
29
+ compatibleCliRange: recipeCompatibilityRangeSchema,
30
+ compatibleRuntimeRange: recipeCompatibilityRangeSchema,
31
+ // Like HasImage/Linkable, capabilities express traits, not customer/domain identities.
32
+ provides: z.array(recipeIdSchema).min(1).readonly(),
33
+ requires: z.array(recipeIdSchema).readonly(),
34
+ conflicts: z.array(recipeIdSchema).readonly(),
35
+ /** Lower priority first, then key, then recipe id; dependencies precede consumers. */
36
+ order: z.strictObject({ priority: z.number().int(), key: recipeIdSchema }).readonly(),
37
+ outputContributions: z.array(recipeOutputContributionSchema).readonly(),
38
+ };
39
+
40
+ /** Serializable projection: executable hooks and Zod instances are deliberately excluded. */
41
+ export const recipeMetadataDescriptorSchema = z.strictObject({
42
+ ...recipeMetadataFields,
43
+ optionsSchema: z.record(z.string(), z.json()),
44
+ validators: z.array(recipeValidatorDescriptorSchema).readonly(),
45
+ generate: z.literal('direct'),
46
+ }).readonly();
47
+
48
+ export type RecipeMetadataDescriptor = z.infer<typeof recipeMetadataDescriptorSchema>;
49
+ export type RecipeOutputContribution = z.infer<typeof recipeOutputContributionSchema>;
50
+ export type RecipeValidatorDescriptor = z.infer<typeof recipeValidatorDescriptorSchema>;
51
+
52
+ /** Import from @easy-web/core/recipes/schema without evaluating the core barrel. */
53
+ export const recipeMetadataJsonSchema = z.toJSONSchema(recipeMetadataDescriptorSchema);
@@ -0,0 +1,77 @@
1
+ import type { GraphResult, ResolvedCapabilityGraph, ResolvedContributionNode } from './graph.js';
2
+
3
+ export const CAPABILITY_GRAPH_SCHEMA_VERSION = 1 as const;
4
+
5
+ export interface CapabilityGraphDocument {
6
+ readonly schemaVersion: 1;
7
+ readonly recipes: ResolvedCapabilityGraph['recipes'];
8
+ readonly capabilities: ResolvedCapabilityGraph['capabilities'];
9
+ readonly requirements: ResolvedCapabilityGraph['requirements'];
10
+ readonly contentTypes: ResolvedCapabilityGraph['contentTypes'];
11
+ readonly fixedPages: readonly ResolvedContributionNode[];
12
+ readonly bindings: readonly ResolvedContributionNode[];
13
+ readonly adaptations: ResolvedCapabilityGraph['adaptations'];
14
+ }
15
+
16
+ export type GraphSerializationError = { readonly code: 'private-value-detected'; readonly path: string };
17
+
18
+ const PRIVATE_PATTERNS: readonly RegExp[] = [
19
+ /[^\s@]+@[^\s@]+\.[^\s@]+/,
20
+ /[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}/,
21
+ /[a-zA-Z][a-zA-Z0-9+.-]*:\/\//,
22
+ /[A-Za-z0-9]{40,}/,
23
+ ];
24
+
25
+ function scanForPrivateValues(value: unknown, path: string): string | undefined {
26
+ if (typeof value === 'string') {
27
+ for (const pattern of PRIVATE_PATTERNS) if (pattern.test(value)) return path;
28
+ return undefined;
29
+ }
30
+ if (Array.isArray(value)) {
31
+ for (let i = 0; i < value.length; i++) {
32
+ const hit = scanForPrivateValues(value[i], `${path}[${i}]`);
33
+ if (hit) return hit;
34
+ }
35
+ return undefined;
36
+ }
37
+ if (value && typeof value === 'object') {
38
+ for (const [key, val] of Object.entries(value)) {
39
+ const hit = scanForPrivateValues(val, path ? `${path}.${key}` : key);
40
+ if (hit) return hit;
41
+ }
42
+ }
43
+ return undefined;
44
+ }
45
+
46
+ /** Pure projection of a resolved graph into a stable, inspectable document. Excludes file/dependency/configuration contributions. */
47
+ export function toCapabilityGraphDocument(
48
+ graph: ResolvedCapabilityGraph,
49
+ ): GraphResult<CapabilityGraphDocument, GraphSerializationError> {
50
+ const isAdaptationTarget = new Set(graph.adaptations.map((adaptation) => adaptation.id));
51
+ const nonFileContributions = graph.contributions.filter(
52
+ (contribution) => contribution.kind !== 'file' && contribution.kind !== 'dependency' && contribution.kind !== 'configuration',
53
+ );
54
+ const fixedPages = nonFileContributions.filter((contribution) => contribution.kind === 'route');
55
+ const bindings = nonFileContributions.filter(
56
+ (contribution) => contribution.kind === 'binding' && !isAdaptationTarget.has(contribution.id),
57
+ );
58
+
59
+ const document: CapabilityGraphDocument = {
60
+ schemaVersion: CAPABILITY_GRAPH_SCHEMA_VERSION,
61
+ recipes: graph.recipes,
62
+ capabilities: graph.capabilities,
63
+ requirements: graph.requirements,
64
+ contentTypes: graph.contentTypes,
65
+ fixedPages,
66
+ bindings,
67
+ adaptations: graph.adaptations,
68
+ };
69
+
70
+ const hitPath = scanForPrivateValues(document, '');
71
+ if (hitPath) return { ok: false, error: { code: 'private-value-detected', path: hitPath } };
72
+ return { ok: true, value: document };
73
+ }
74
+
75
+ export function serializeCapabilityGraphJson(document: CapabilityGraphDocument): string {
76
+ return JSON.stringify(document, null, 2);
77
+ }
@@ -0,0 +1,162 @@
1
+ import { z } from 'astro/zod';
2
+ import type { RecipeMetadata } from './types.js';
3
+
4
+ export const SHELL_RECIPE_ID = 'site.shell';
5
+
6
+ const shellOptionsSchema = z.strictObject({
7
+ siteName: z.string().min(1).default('Example Site'),
8
+ defaultLocale: z.string().default('en'),
9
+ noIndex: z.boolean().default(false),
10
+ });
11
+
12
+ export type ShellRecipeOptions = z.infer<typeof shellOptionsSchema>;
13
+
14
+ const PLACEHOLDER_SITE_URL = 'https://replace-with-your-domain.example';
15
+
16
+ function astroConfig(options: ShellRecipeOptions): string {
17
+ return `import { defineConfig } from 'astro/config';
18
+ import easyWebSeo from '@easy-web/core/seo';
19
+
20
+ export default defineConfig({
21
+ site: ${JSON.stringify(PLACEHOLDER_SITE_URL)},
22
+ integrations: [
23
+ easyWebSeo({ noIndex: ${options.noIndex ? 'true' : 'false'} }),
24
+ ],
25
+ });
26
+ `;
27
+ }
28
+
29
+ const packageJsonFragment = `${JSON.stringify({
30
+ type: 'module',
31
+ scripts: { dev: 'astro dev', build: 'astro build', preview: 'astro preview' },
32
+ dependencies: { '@easy-web/core': '^1.5.0', astro: '^7.3.5' },
33
+ devDependencies: { typescript: '^5.5.0' },
34
+ }, null, 2)}\n`;
35
+
36
+ const pnpmWorkspace = `allowBuilds:
37
+ esbuild: true
38
+ sharp: true
39
+ `;
40
+
41
+ function baseLayout(options: ShellRecipeOptions): string {
42
+ return `---
43
+ import PageShell from '@easy-web/core/components/PageShell.astro';
44
+ import Header from '@easy-web/core/components/Header.astro';
45
+ import Footer from '@easy-web/core/components/Footer.astro';
46
+
47
+ interface Props {
48
+ title: string;
49
+ }
50
+ const { title } = Astro.props;
51
+ const siteName = ${JSON.stringify(options.siteName)};
52
+ const currentLang = ${JSON.stringify(options.defaultLocale)};
53
+ const navItems = [{ label: 'Home', href: '/' }];
54
+ ---
55
+ <!doctype html>
56
+ <html lang=${JSON.stringify(options.defaultLocale)}>
57
+ <head>
58
+ <meta charset="utf-8" />
59
+ <meta name="viewport" content="width=device-width, initial-scale=1" />
60
+ <title>{title}</title>
61
+ </head>
62
+ <body>
63
+ <PageShell lang={currentLang}>
64
+ <Header
65
+ slot="header"
66
+ lang={currentLang}
67
+ siteName={siteName}
68
+ navItems={navItems}
69
+ currentLang={currentLang}
70
+ pathname={Astro.url.pathname}
71
+ brandHref="/"
72
+ locales={[currentLang]}
73
+ />
74
+ <slot />
75
+ <Footer slot="footer" lang={currentLang} siteName={siteName} legalLinks={[
76
+ { label: 'Imprint (sample)', href: '/imprint' },
77
+ { label: 'Privacy (sample)', href: '/privacy' },
78
+ ]} />
79
+ </PageShell>
80
+ </body>
81
+ </html>
82
+ `;
83
+ }
84
+
85
+ function homePage(options: ShellRecipeOptions): string {
86
+ return `---
87
+ import Base from '../layouts/Base.astro';
88
+ ---
89
+ <Base title=${JSON.stringify(options.siteName)}>
90
+ <h1>Welcome</h1>
91
+ <p>This is a generated placeholder home page. Replace this content before production.</p>
92
+ </Base>
93
+ `;
94
+ }
95
+
96
+ function notFoundPage(options: ShellRecipeOptions): string {
97
+ return `---
98
+ import Base from '../layouts/Base.astro';
99
+ import NotFound from '@easy-web/core/components/NotFound.astro';
100
+ ---
101
+ <Base title="Page not found">
102
+ <NotFound currentLang=${JSON.stringify(options.defaultLocale)} defaultLocale=${JSON.stringify(options.defaultLocale)} />
103
+ </Base>
104
+ `;
105
+ }
106
+
107
+ const localizedPaths = `import type { LocalizedPathGroup } from '@easy-web/core/i18n';
108
+
109
+ export const localizedPaths: readonly LocalizedPathGroup[] = [];
110
+ `;
111
+
112
+ const robotsTxt = `Disallow: /admin/
113
+ Sitemap: ${PLACEHOLDER_SITE_URL}/sitemap-index.xml
114
+ `;
115
+
116
+ const gitignore = `node_modules
117
+ dist
118
+ .astro
119
+ `;
120
+
121
+ export function buildShellFiles(rawOptions: unknown): readonly { path: string; content: string }[] {
122
+ const options = shellOptionsSchema.parse(rawOptions ?? {});
123
+ return [
124
+ { path: 'astro.config.mjs', content: astroConfig(options) },
125
+ { path: 'package.json', content: packageJsonFragment },
126
+ { path: 'pnpm-workspace.yaml', content: pnpmWorkspace },
127
+ { path: 'src/layouts/Base.astro', content: baseLayout(options) },
128
+ { path: 'src/pages/index.astro', content: homePage(options) },
129
+ { path: 'src/pages/404.astro', content: notFoundPage(options) },
130
+ { path: 'src/lib/localized-paths.ts', content: localizedPaths },
131
+ { path: 'public/robots.txt', content: robotsTxt },
132
+ { path: '.gitignore', content: gitignore },
133
+ ];
134
+ }
135
+
136
+ export const shellRecipe = {
137
+ id: SHELL_RECIPE_ID,
138
+ version: '1.5.0',
139
+ protocolVersion: 1,
140
+ compatibleCliRange: '^0.1.0',
141
+ compatibleRuntimeRange: '^1.5.0',
142
+ provides: [SHELL_RECIPE_ID],
143
+ requires: [],
144
+ conflicts: [],
145
+ order: { priority: 0, key: 'shell' },
146
+ optionsSchema: shellOptionsSchema,
147
+ outputContributions: [
148
+ { kind: 'configuration', id: 'shell.astro-config', target: 'astro.config.mjs' },
149
+ { kind: 'dependency', id: 'shell.dependencies', target: 'package.json' },
150
+ { kind: 'configuration', id: 'shell.pnpm-workspace', target: 'pnpm-workspace.yaml' },
151
+ { kind: 'file', id: 'shell.base-layout', target: 'src/layouts/Base.astro' },
152
+ { kind: 'route', id: 'shell.home', target: '/' },
153
+ { kind: 'route', id: 'shell.404', target: '/404' },
154
+ { kind: 'file', id: 'shell.localized-paths', target: 'src/lib/localized-paths.ts' },
155
+ { kind: 'file', id: 'shell.robots', target: 'public/robots.txt' },
156
+ { kind: 'file', id: 'shell.gitignore', target: '.gitignore' },
157
+ ],
158
+ validators: [],
159
+ generate: (context: { options?: unknown }) => ({ files: buildShellFiles(context.options) }),
160
+ } satisfies RecipeMetadata<ShellRecipeOptions>;
161
+
162
+ export default shellRecipe;