@empire-builder-kit/nx 1.0.0-rc.46 → 1.0.0-rc.47

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 (174) hide show
  1. package/generators.json +11 -1
  2. package/package.json +3 -3
  3. package/src/aws-authority/stage-authority.d.ts +30 -2
  4. package/src/aws-authority/stage-authority.js +220 -25
  5. package/src/developer-agent/generator-planning.js +99 -6
  6. package/src/developer-agent/model.d.ts +7 -3
  7. package/src/developer-agent/model.js +1 -0
  8. package/src/developer-agent/operation-registry.d.ts +1 -0
  9. package/src/developer-agent/operation-registry.js +43 -2
  10. package/src/developer-agent/planning.js +5 -2
  11. package/src/developer-agent/preview-changes.js +10 -0
  12. package/src/developer-agent/validation.js +7 -3
  13. package/src/developer-agent/workspace-inspection.js +51 -4
  14. package/src/executors/deployment-plan/deployment-plan.js +3 -0
  15. package/src/executors/dev-doctor/dev-doctor.d.ts +25 -3
  16. package/src/executors/dev-doctor/dev-doctor.js +136 -49
  17. package/src/executors/dev-setup/dev-setup.d.ts +18 -1
  18. package/src/executors/dev-setup/dev-setup.js +320 -196
  19. package/src/executors/foundation-preflight/foundation-preflight.js +9 -1
  20. package/src/executors/foundation-remove-preflight/foundation-remove-preflight.js +2 -2
  21. package/src/executors/infrastructure-plan/infrastructure-plan.js +10 -3
  22. package/src/executors/local-deploy/local-deploy.d.ts +15 -0
  23. package/src/executors/local-deploy/local-deploy.js +96 -14
  24. package/src/executors/sst-lifecycle/logging-preflight.js +12 -1
  25. package/src/executors/sst-lifecycle/run-sst-command.js +51 -5
  26. package/src/foundation/cost-estimate.js +1 -1
  27. package/src/foundation/identity-domain-parent-ready.d.ts +91 -0
  28. package/src/foundation/identity-domain-parent-ready.js +333 -0
  29. package/src/foundation/identity-domain.d.ts +94 -0
  30. package/src/foundation/identity-domain.js +115 -0
  31. package/src/foundation/index.d.ts +2 -0
  32. package/src/foundation/index.js +7 -0
  33. package/src/foundation/preflight.js +17 -1
  34. package/src/foundation/root-site-readiness.d.ts +27 -0
  35. package/src/foundation/root-site-readiness.js +78 -0
  36. package/src/foundation/root-site.d.ts +81 -0
  37. package/src/foundation/root-site.js +268 -0
  38. package/src/generators/framework-prerequisites.d.ts +2 -0
  39. package/src/generators/framework-prerequisites.js +34 -0
  40. package/src/generators/function/function-registration.d.ts +24 -0
  41. package/src/generators/function/function-registration.js +66 -0
  42. package/src/generators/function/function.d.ts +16 -1
  43. package/src/generators/function/function.js +101 -18
  44. package/src/generators/function/schema.d.ts +1 -0
  45. package/src/generators/function/schema.json +6 -0
  46. package/src/generators/function-access/function-access.d.ts +14 -0
  47. package/src/generators/function-access/function-access.js +141 -0
  48. package/src/generators/function-access/schema.d.ts +6 -0
  49. package/src/generators/function-access/schema.json +25 -0
  50. package/src/generators/post-generation-install.d.ts +1 -1
  51. package/src/generators/post-generation-install.js +1 -1
  52. package/src/generators/preset/dependency-overrides.d.ts +1 -1
  53. package/src/generators/preset/dependency-overrides.js +1 -1
  54. package/src/generators/preset/workspace-files-adopter-skills.js +14 -0
  55. package/src/generators/preset/workspace-files-developer-agent.js +17 -11
  56. package/src/generators/preset/workspace-files-stage-authority.js +58 -1
  57. package/src/generators/preset/workspace-files-thin-deploy.d.ts +11 -0
  58. package/src/generators/preset/workspace-files-thin-deploy.js +47 -4
  59. package/src/generators/preset/workspace-files-thin-docs.js +33 -5
  60. package/src/generators/preset/workspace-files.js +207 -13
  61. package/src/generators/repository-policy/repository-policy.js +2 -1
  62. package/src/generators/repository-policy/schema.d.ts +2 -0
  63. package/src/generators/repository-policy/schema.json +7 -2
  64. package/src/generators/site/built-in-site-documentation-files.d.ts +2 -0
  65. package/src/generators/site/built-in-site-documentation-files.js +92 -0
  66. package/src/generators/site/built-in-site-files.d.ts +8 -0
  67. package/src/generators/site/built-in-site-files.js +40 -0
  68. package/src/generators/site/built-in-site-infrastructure-files.d.ts +2 -0
  69. package/src/generators/site/built-in-site-infrastructure-files.js +275 -0
  70. package/src/generators/site/built-in-site-plan.d.ts +19 -0
  71. package/src/generators/site/built-in-site-plan.js +65 -0
  72. package/src/generators/site/built-in-site-project-files.d.ts +3 -0
  73. package/src/generators/site/built-in-site-project-files.js +258 -0
  74. package/src/generators/site/built-in-site-script-files.d.ts +2 -0
  75. package/src/generators/site/built-in-site-script-files.js +306 -0
  76. package/src/generators/site/built-in-site-shared.d.ts +9 -0
  77. package/src/generators/site/built-in-site-shared.js +21 -0
  78. package/src/generators/site/built-in-site-smoke-files.d.ts +2 -0
  79. package/src/generators/site/built-in-site-smoke-files.js +37 -0
  80. package/src/generators/site/built-in-site-sst-config-files.d.ts +2 -0
  81. package/src/generators/site/built-in-site-sst-config-files.js +39 -0
  82. package/src/generators/site/built-in-site-web-files.d.ts +2 -0
  83. package/src/generators/site/built-in-site-web-files.js +284 -0
  84. package/src/generators/site/schema.d.ts +4 -0
  85. package/src/generators/site/schema.json +20 -0
  86. package/src/generators/site/site.d.ts +13 -0
  87. package/src/generators/site/site.js +221 -0
  88. package/src/generators/slice/built-in-plan-alarm-identity.d.ts +9 -0
  89. package/src/generators/slice/built-in-plan-alarm-identity.js +8 -1
  90. package/src/generators/slice/built-in-plan-api-contract-files.js +18 -0
  91. package/src/generators/slice/built-in-plan-async-work-files.js +18 -0
  92. package/src/generators/slice/built-in-plan-data-files.js +116 -11
  93. package/src/generators/slice/built-in-plan-foundation-files.d.ts +12 -0
  94. package/src/generators/slice/built-in-plan-foundation-files.js +114 -5
  95. package/src/generators/slice/built-in-plan-frontend-files.js +2 -271
  96. package/src/generators/slice/built-in-plan-frontend-header-proof.d.ts +6 -0
  97. package/src/generators/slice/built-in-plan-frontend-header-proof.js +282 -0
  98. package/src/generators/slice/built-in-plan-infrastructure-files.js +151 -237
  99. package/src/generators/slice/built-in-plan-key-value-cleanup.js +4 -3
  100. package/src/generators/slice/built-in-plan-log-group-helpers.d.ts +29 -0
  101. package/src/generators/slice/built-in-plan-log-group-helpers.js +130 -0
  102. package/src/generators/slice/built-in-plan-metadata-files.js +21 -4
  103. package/src/generators/slice/built-in-plan-next-build-authority.d.ts +5 -0
  104. package/src/generators/slice/built-in-plan-next-build-authority.js +124 -0
  105. package/src/generators/slice/built-in-plan-operations-files.d.ts +6 -0
  106. package/src/generators/slice/built-in-plan-operations-files.js +107 -219
  107. package/src/generators/slice/built-in-plan-performance-files.js +6 -1
  108. package/src/generators/slice/built-in-plan-reliability-files.js +12 -8
  109. package/src/generators/slice/built-in-plan-shared.d.ts +1 -1
  110. package/src/generators/slice/built-in-plan-shared.js +1 -1
  111. package/src/generators/slice/built-in-plan-sst-config.d.ts +49 -0
  112. package/src/generators/slice/built-in-plan-sst-config.js +160 -0
  113. package/src/generators/slice/built-in-plan-testing-files.js +92 -49
  114. package/src/generators/slice/built-in-plan-verification-files.js +15 -4
  115. package/src/generators/slice/built-in-plan-web-files.js +65 -0
  116. package/src/generators/slice/deployed-smoke-diagnostics.d.ts +35 -0
  117. package/src/generators/slice/deployed-smoke-diagnostics.js +189 -0
  118. package/src/generators/slice/deployed-smoke-readiness.d.ts +7 -0
  119. package/src/generators/slice/deployed-smoke-readiness.js +118 -23
  120. package/src/generators/slice/persistence-contract.js +2 -2
  121. package/src/generators/slice/pnpm-launch-script.d.ts +13 -0
  122. package/src/generators/slice/pnpm-launch-script.js +28 -0
  123. package/src/generators/slice/slice.js +27 -0
  124. package/src/generators/upgrade/custom-domain-notice.d.ts +19 -0
  125. package/src/generators/upgrade/custom-domain-notice.js +38 -0
  126. package/src/generators/upgrade/external-blueprint-compositions.d.ts +84 -0
  127. package/src/generators/upgrade/external-blueprint-compositions.js +478 -0
  128. package/src/generators/upgrade/framework-package-upgrade.d.ts +58 -0
  129. package/src/generators/upgrade/framework-package-upgrade.js +78 -0
  130. package/src/generators/upgrade/function-authentication-notice.d.ts +29 -0
  131. package/src/generators/upgrade/function-authentication-notice.js +74 -0
  132. package/src/generators/upgrade/schema.json +2 -2
  133. package/src/generators/upgrade/upgrade-plan.d.ts +52 -0
  134. package/src/generators/upgrade/upgrade-plan.js +406 -0
  135. package/src/generators/upgrade/upgrade.d.ts +1 -35
  136. package/src/generators/upgrade/upgrade.js +259 -593
  137. package/src/generators/workload/workload.js +60 -4
  138. package/src/git-policy/github-bootstrap.d.ts +6 -5
  139. package/src/git-policy/github-bootstrap.js +6 -4
  140. package/src/local-dev/fleet-process.d.ts +9 -2
  141. package/src/local-dev/fleet-process.js +27 -7
  142. package/src/local-dev/gateway-daemon.d.ts +1 -1
  143. package/src/local-dev/gateway-daemon.js +6 -4
  144. package/src/local-dev/portless.d.ts +5 -0
  145. package/src/local-dev/portless.js +5 -0
  146. package/src/local-dev/process-group.d.ts +10 -0
  147. package/src/local-dev/process-group.js +33 -0
  148. package/src/local-dev/tls.js +31 -2
  149. package/src/local-dev/trust-store.d.ts +42 -0
  150. package/src/local-dev/trust-store.js +87 -0
  151. package/src/ownership/composition.d.ts +7 -0
  152. package/src/ownership/composition.js +64 -56
  153. package/src/ownership/index.d.ts +1 -0
  154. package/src/ownership/index.js +1 -0
  155. package/src/ownership/record.d.ts +19 -0
  156. package/src/ownership/record.js +26 -2
  157. package/src/ownership/site-record.d.ts +18 -0
  158. package/src/ownership/site-record.js +105 -0
  159. package/src/repository-policy/deployment-plan.d.ts +3 -0
  160. package/src/repository-policy/deployment-plan.js +33 -4
  161. package/src/repository-policy/index.d.ts +1 -0
  162. package/src/repository-policy/index.js +1 -0
  163. package/src/repository-policy/policy.d.ts +13 -1
  164. package/src/repository-policy/policy.js +55 -1
  165. package/src/repository-policy/public-dns.d.ts +65 -0
  166. package/src/repository-policy/public-dns.js +168 -0
  167. package/src/schemas/generated-ownership-v2.json +6 -0
  168. package/src/schemas/repository-policy-v1.json +67 -1
  169. package/src/supply-chain/blueprint-trust-git.js +24 -0
  170. package/src/supply-chain/blueprint-verification-authority.js +21 -3
  171. package/src/supply-chain/generated-blueprint-trust-command.js +15 -0
  172. package/src/work-markers/work-markers.js +4 -1
  173. package/src/workspace-deployment/ownership.d.ts +15 -0
  174. package/src/workspace-deployment/ownership.js +19 -3
@@ -0,0 +1,282 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.renderFrontendSecurityHeaderProof = renderFrontendSecurityHeaderProof;
4
+ /**
5
+ * The managed deployed header proof, scripts/frontend-security-headers.mjs.
6
+ * `owner` names what its evidence output must stay inside: a Product Slice
7
+ * or the root site.
8
+ */
9
+ function renderFrontendSecurityHeaderProof(name, owner) {
10
+ return `import { createHash } from 'node:crypto';
11
+ import { mkdirSync, readFileSync, realpathSync, writeFileSync } from 'node:fs';
12
+ import { dirname, relative, resolve, sep } from 'node:path';
13
+ import { fileURLToPath } from 'node:url';
14
+ import {
15
+ inspectFrontendSecurityHeaders as inspectOwnedFrontendSecurityHeaders,
16
+ resolveFrontendSecurityHeaderProfile,
17
+ } from '@empire-builder-kit/nx/frontend-security';
18
+
19
+ const projectRoot = resolve(dirname(fileURLToPath(import.meta.url)), '..');
20
+ const foundationPolicyPath = resolve(
21
+ projectRoot,
22
+ '..',
23
+ 'foundation',
24
+ 'contracts',
25
+ 'frontend-security-headers.json',
26
+ );
27
+ const slicePolicyPath = resolve(
28
+ projectRoot,
29
+ 'frontend',
30
+ 'security-headers.json',
31
+ );
32
+ const readPolicy = (path) => {
33
+ const contents = readFileSync(path);
34
+ return {
35
+ digest: 'sha256:' + createHash('sha256').update(contents).digest('hex'),
36
+ value: JSON.parse(contents),
37
+ };
38
+ };
39
+ const foundationPolicy = readPolicy(foundationPolicyPath);
40
+ const slicePolicy = readPolicy(slicePolicyPath);
41
+ const gitObjectIdPattern = /^(?:[a-f0-9]{40}|[a-f0-9]{64})$/;
42
+ const MAX_FRONTEND_HEADER_FETCH_TIMEOUT_MS = 10_000;
43
+
44
+ function loopback(hostname) {
45
+ return ['127.0.0.1', 'localhost', '::1', '[::1]'].includes(hostname);
46
+ }
47
+
48
+ function safeTarget(value, profile, allowLoopbackTransportProof) {
49
+ const target = new URL(value);
50
+ if (
51
+ (target.protocol !== 'https:' &&
52
+ !(
53
+ loopback(target.hostname) &&
54
+ target.protocol === 'http:' &&
55
+ (profile === 'local-development' || allowLoopbackTransportProof)
56
+ )) ||
57
+ target.username ||
58
+ target.password ||
59
+ target.search ||
60
+ target.hash
61
+ ) {
62
+ throw new Error('Frontend header target must be HTTPS without credentials, query, or fragment.');
63
+ }
64
+ return target;
65
+ }
66
+
67
+ export function inspectFrontendSecurityHeaders({
68
+ allowLoopbackTransportProof = false,
69
+ headers,
70
+ https,
71
+ profile = 'deployed-https',
72
+ }) {
73
+ return inspectOwnedFrontendSecurityHeaders({
74
+ actual: headers,
75
+ allowLoopbackTransportProof,
76
+ foundation: foundationPolicy.value,
77
+ https,
78
+ profile,
79
+ slice: slicePolicy.value,
80
+ sliceName: '${name}',
81
+ });
82
+ }
83
+
84
+ function responseNonce(headers) {
85
+ const policy = new Headers(headers).get('content-security-policy') ?? '';
86
+ const nonces = [
87
+ ...policy.matchAll(/'nonce-([A-Za-z0-9+/_-]{16,128}={0,2})'/g),
88
+ ].map((match) => match[1]);
89
+ const unique = [...new Set(nonces)];
90
+ return unique.length === 1 && nonces.length >= 2 ? unique[0] : undefined;
91
+ }
92
+
93
+ export function inspectFrontendNonceFreshness(firstHeaders, secondHeaders) {
94
+ const first = responseNonce(firstHeaders);
95
+ const second = responseNonce(secondHeaders);
96
+ return {
97
+ firstNoncePresent: first !== undefined,
98
+ fresh: first !== undefined && second !== undefined && first !== second,
99
+ secondNoncePresent: second !== undefined,
100
+ };
101
+ }
102
+
103
+ function outputPath(argument) {
104
+ const output = resolve(
105
+ projectRoot,
106
+ argument?.slice('--output='.length) ??
107
+ '.ebk/evidence/frontend/security-headers.json',
108
+ );
109
+ const fromRoot = relative(projectRoot, output);
110
+ if (fromRoot === '..' || fromRoot.startsWith('..' + sep)) {
111
+ throw new Error('Frontend header evidence must remain inside the ${owner}.');
112
+ }
113
+ return output;
114
+ }
115
+
116
+ function fetchTimeout() {
117
+ const value =
118
+ process.env.EBK_FRONTEND_HEADER_FETCH_TIMEOUT_MS?.trim() ?? '10000';
119
+ if (!/^[1-9]\\d*$/.test(value)) {
120
+ throw new Error(
121
+ 'EBK_FRONTEND_HEADER_FETCH_TIMEOUT_MS must be a positive integer.',
122
+ );
123
+ }
124
+ const milliseconds = Number(value);
125
+ if (milliseconds > MAX_FRONTEND_HEADER_FETCH_TIMEOUT_MS) {
126
+ throw new Error(
127
+ 'EBK_FRONTEND_HEADER_FETCH_TIMEOUT_MS may not exceed ' +
128
+ MAX_FRONTEND_HEADER_FETCH_TIMEOUT_MS +
129
+ ' milliseconds.',
130
+ );
131
+ }
132
+ return milliseconds;
133
+ }
134
+
135
+ export async function fetchFrontendResponse(
136
+ target,
137
+ timeout,
138
+ fetchImplementation = fetch,
139
+ ) {
140
+ const signal = AbortSignal.timeout(timeout);
141
+ try {
142
+ return await fetchImplementation(target, { redirect: 'error', signal });
143
+ } catch (error) {
144
+ if (signal.aborted) {
145
+ throw new Error(
146
+ 'Frontend header request did not complete within ' +
147
+ timeout +
148
+ ' milliseconds.',
149
+ { cause: error },
150
+ );
151
+ }
152
+ throw error;
153
+ }
154
+ }
155
+
156
+ async function main() {
157
+ const arguments_ = process.argv.slice(2);
158
+ const urlArguments = arguments_.filter((value) => value.startsWith('--url='));
159
+ const outputArguments = arguments_.filter((value) =>
160
+ value.startsWith('--output='),
161
+ );
162
+ const allowLoopbackTransportProof = arguments_.includes(
163
+ '--allow-loopback-transport-proof',
164
+ );
165
+ const unsupported = arguments_.filter(
166
+ (value) =>
167
+ !value.startsWith('--url=') &&
168
+ !value.startsWith('--output=') &&
169
+ value !== '--allow-loopback-transport-proof',
170
+ );
171
+ if (
172
+ urlArguments.length > 1 ||
173
+ outputArguments.length > 1 ||
174
+ unsupported.length > 0
175
+ ) {
176
+ throw new Error(
177
+ 'Usage: frontend-security-headers.mjs [--url=<url>] [--output=<path>] [--allow-loopback-transport-proof]',
178
+ );
179
+ }
180
+ const profile = resolveFrontendSecurityHeaderProfile(process.env);
181
+ const target = safeTarget(
182
+ urlArguments[0]?.slice('--url='.length) ??
183
+ process.env.EBK_FRONTEND_URL ??
184
+ '',
185
+ profile,
186
+ allowLoopbackTransportProof,
187
+ );
188
+ const timeout = fetchTimeout();
189
+ const response = await fetchFrontendResponse(target, timeout);
190
+ const hostedTransportVerified =
191
+ profile === 'deployed-https' && target.protocol === 'https:';
192
+ const inspected = inspectFrontendSecurityHeaders({
193
+ allowLoopbackTransportProof,
194
+ headers: response.headers,
195
+ https: target.protocol === 'https:',
196
+ profile,
197
+ });
198
+ const freshnessResponse = hostedTransportVerified
199
+ ? await fetchFrontendResponse(target, timeout)
200
+ : undefined;
201
+ const freshnessInspection = freshnessResponse
202
+ ? inspectFrontendSecurityHeaders({
203
+ allowLoopbackTransportProof,
204
+ headers: freshnessResponse.headers,
205
+ https: true,
206
+ profile,
207
+ })
208
+ : undefined;
209
+ const nonceFreshness = freshnessResponse
210
+ ? inspectFrontendNonceFreshness(response.headers, freshnessResponse.headers)
211
+ : {
212
+ firstNoncePresent: false,
213
+ fresh: false,
214
+ secondNoncePresent: false,
215
+ };
216
+ const nonceFreshnessVerified =
217
+ hostedTransportVerified &&
218
+ freshnessResponse !== undefined &&
219
+ freshnessResponse.status >= 200 &&
220
+ freshnessResponse.status < 400 &&
221
+ freshnessInspection?.findings.length === 0 &&
222
+ nonceFreshness.fresh;
223
+ const sourceCommit =
224
+ process.env.EBK_SOURCE_COMMIT?.trim() ?? 'unresolved-local-source';
225
+ const stage = process.env.EBK_STAGE?.trim() ?? 'development';
226
+ const findings = [
227
+ ...inspected.findings,
228
+ ...(profile === 'deployed-https' && !gitObjectIdPattern.test(sourceCommit)
229
+ ? ['deployed-source-commit-required']
230
+ : []),
231
+ ...(response.status >= 200 && response.status < 400
232
+ ? []
233
+ : ['frontend-response-unsuccessful']),
234
+ ...(hostedTransportVerified && !nonceFreshnessVerified
235
+ ? ['hosted-response-nonce-not-fresh']
236
+ : []),
237
+ ].sort();
238
+ const proofScope =
239
+ profile === 'local-development'
240
+ ? 'local-development'
241
+ : hostedTransportVerified
242
+ ? 'hosted-deployed'
243
+ : 'local-response-composition';
244
+ const result = {
245
+ ...inspected,
246
+ binding: {
247
+ foundationPolicyDigest: foundationPolicy.digest,
248
+ slicePolicyDigest: slicePolicy.digest,
249
+ sourceCommit,
250
+ stage,
251
+ targetOriginDigest:
252
+ 'sha256:' +
253
+ createHash('sha256').update(target.origin, 'utf8').digest('hex'),
254
+ },
255
+ findings,
256
+ hostedTransportVerified,
257
+ nonceFreshnessVerified,
258
+ outcome: findings.length === 0 ? 'passed' : 'failed',
259
+ proofScope,
260
+ response: {
261
+ https: target.protocol === 'https:',
262
+ pathname: target.pathname,
263
+ status: response.status,
264
+ },
265
+ };
266
+ const output = outputPath(outputArguments[0]);
267
+ mkdirSync(dirname(output), { recursive: true, mode: 0o700 });
268
+ writeFileSync(output, JSON.stringify(result, null, 2) + '\\n', { mode: 0o600 });
269
+ process.stdout.write(JSON.stringify(result) + '\\n');
270
+ if (result.outcome !== 'passed') process.exitCode = 1;
271
+ }
272
+
273
+ if (
274
+ process.argv[1] &&
275
+ realpathSync(resolve(process.argv[1])) ===
276
+ realpathSync(fileURLToPath(import.meta.url))
277
+ ) {
278
+ await main();
279
+ }
280
+ `;
281
+ }
282
+ //# sourceMappingURL=built-in-plan-frontend-header-proof.js.map