@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
@@ -217,17 +217,122 @@ export const Secrets: DefinedSecrets<typeof SecretDefinitions> =
217
217
  }),
218
218
  'docs/runbooks/database-credential-rotation.md': `# Database credential rotation
219
219
 
220
- The \`${pascalName}PrimaryDatabaseCredential\` value is generated and rotated
221
- inside AWS by the exact database bootstrap workflow. Never read, copy, pass, or
222
- write this value through an EBK deploy, CI input, SST output, source file, or
223
- operator-secret command.
224
-
225
- To rotate after an authentication failure, run the reviewed database migration
226
- workflow for the exact Slice and stage. The server-only resolver invalidates its
227
- cached value and retries one authentication failure against \`AWSCURRENT\`.
228
- Confirm the bootstrap and migration lifecycle records share their execution
229
- correlation, the runtime secret version is current, and the prior version can be
230
- restored before accepting the rotation.
220
+ The \`${pascalName}PrimaryDatabaseCredential\` value is generated inside AWS by
221
+ the exact database bootstrap workflow. Never read, copy, pass, or write this
222
+ value through an EBK deploy, CI input, SST output, source file, or
223
+ operator-secret command, and never write it or move its version labels by hand.
224
+
225
+ ## How rotation works
226
+
227
+ Each provisioned database identifier has two generated credential containers,
228
+ \`ebk/<stage>/${name}/database/<identifier>/readwrite\` and
229
+ \`ebk/<stage>/${name}/database/<identifier>/readonly\`. Its bootstrap task
230
+ carries a credential generation: the value of
231
+ \`EBK_DATABASE_CREDENTIAL_GENERATION\` when the Slice infrastructure was last
232
+ deployed, or \`aws-bootstrap-v1\` when that variable was unset or empty. When
233
+ that generation differs from the one stored with the current credential, the
234
+ next bootstrap of the identifier generates new passwords for its read/write and
235
+ read-only roles, applies them with \`ALTER ROLE\`, and then publishes a new
236
+ \`AWSCURRENT\` version of each container that stores the new generation. Later
237
+ bootstraps with the same generation do not rotate.
238
+
239
+ A deploy or \`db-migrate\` run with an unchanged generation does not rotate. Its
240
+ bootstrap re-applies the current \`AWSCURRENT\` password to both roles and
241
+ re-converges their grants, which repairs an authentication failure caused by a
242
+ role password or grant changed outside EBK. It writes a new secret version only
243
+ when the stored database host or port changed, and that version carries the same
244
+ password, so a new version alone is not a rotation. The server-only resolver
245
+ invalidates its cached value and retries one authentication failure against
246
+ \`AWSCURRENT\`.
247
+
248
+ ## Rotate
249
+
250
+ 1. Choose a new generation: 1 to 63 lowercase letters, digits, or hyphens,
251
+ starting with a letter or digit, and different from the generation last
252
+ deployed to the stage (\`aws-bootstrap-v1\` if the stage never set one). A
253
+ date such as \`2026-11-02\` works.
254
+ 2. Deploy with the variable set. For a governed local deploy, set it in the
255
+ same shell, for example:
256
+
257
+ \`\`\`bash
258
+ EBK_DATABASE_CREDENTIAL_GENERATION=2026-11-02 ebk deploy development ${name} \\
259
+ --profile=<profile> --expectedRoleArn=<role-arn>
260
+ \`\`\`
261
+
262
+ For a stage deployed by the protected Deploy workflow, set
263
+ \`EBK_DATABASE_CREDENTIAL_GENERATION\` as a variable of that stage's GitHub
264
+ environment, never at repository or organization scope (the GitHub bootstrap
265
+ report refuses those scopes), and run the protected Deploy for the stage
266
+ with \`lifecycle\` \`full\`. The default \`affected\` scope skips a Slice whose
267
+ source is unchanged, so that Slice would not rotate until a later deploy
268
+ reaches it. The workflow refuses a malformed value before it assumes any AWS
269
+ role, and the Slice infrastructure refuses one while SST evaluates the Slice,
270
+ before its product infrastructure registers.
271
+ 3. The deploy runs the migration workflow for the active \`primary\`
272
+ identifier, so its bootstrap rotates that identifier. Every other
273
+ provisioned identifier in \`database/bindings.json\`, such as a replacement
274
+ candidate, rotates the next time its own
275
+ \`db-migrate --database=<identifier>\` runs.
276
+ 4. Accept the rotation with value-free evidence only:
277
+ - the bootstrap and migration lifecycle records share their execution
278
+ correlation and both succeeded;
279
+ - the version list of each rotated container, read without its value (for
280
+ example with \`aws secretsmanager list-secret-version-ids\`, which returns
281
+ each version's stages and \`CreatedDate\`, or by comparing the
282
+ \`VersionIdsToStages\` map that \`aws secretsmanager describe-secret\`
283
+ returns with one you recorded before rotating), shows a new \`AWSCURRENT\`
284
+ version created by that bootstrap and the former version as
285
+ \`AWSPREVIOUS\`, from a deploy that requested a new generation; and
286
+ - the authenticated \`GET /database-health\` route succeeds.
287
+
288
+ The bootstrap applied the new passwords before publishing them, so the
289
+ former passwords no longer authenticate new connections; connections that
290
+ were already open stay open until they close. Nobody holds the former
291
+ password, so do not try to test it.
292
+
293
+ ## Scope and keeping the generation set
294
+
295
+ The variable is not Slice-scoped. Set in a stage's GitHub environment, it
296
+ reaches every Slice the Deploy workflow deploys in that stage; set in a shell,
297
+ it reaches every Slice \`ebk deploy\` deploys from that shell. Every SQL Slice
298
+ it reaches rotates each provisioned identifier as described above. A deploy
299
+ that reaches only some SQL Slices, such as the single-Slice local deploy above
300
+ or an \`affected\` workflow deploy, rotates only those; the stage's other SQL
301
+ Slices keep their prior generation until a deploy with the variable reaches
302
+ them. A push-triggered Deploy also reads the stage's GitHub environment
303
+ variable, so set it there only when you intend to rotate every SQL Slice that
304
+ Deploy reaches.
305
+
306
+ Keep the variable set to the current generation for every later deploy and
307
+ \`db-migrate\` run of each SQL Slice in that stage; \`db-migrate\` deploys the
308
+ Slice infrastructure first. A deploy without it returns the bootstrap task to
309
+ \`aws-bootstrap-v1\`, so the next bootstrap of each identifier finds a different
310
+ stored generation and rotates once more, then converges. Nothing fails, but
311
+ that is an unplanned rotation with the stale window below. Local and workflow
312
+ deploys of one stage must request the same generation.
313
+
314
+ ## Stale window
315
+
316
+ \`ALTER ROLE\` and the \`AWSCURRENT\` update cannot happen atomically. Between
317
+ them, a new connection made with the cached former password fails, and the
318
+ resolver's single retry can still read the former \`AWSCURRENT\` version for
319
+ that short interval. Rotate when a few failed requests are acceptable. Warm
320
+ Lambda and Service processes pick up the new value without a redeploy, when
321
+ their cached value expires or on their next authentication failure.
322
+
323
+ ## Rollback and failure
324
+
325
+ Never move this secret's version labels, for example with
326
+ \`UpdateSecretVersionStage\`. After a rotation the database no longer accepts the
327
+ \`AWSPREVIOUS\` password, so restoring it would break every new connection, and
328
+ the next bootstrap would rotate again because the stored generation would
329
+ differ. To replace a rotated credential, choose another new generation and
330
+ deploy again.
331
+
332
+ If the migration workflow fails during a rotation, new connections can fail
333
+ until a bootstrap with that generation succeeds. Run the same deploy again with
334
+ the same generation: the stored generation still differs, so that bootstrap
335
+ rotates and publishes.
231
336
  `,
232
337
  'docs/runbooks/operator-secret-management.md': `# Operator secret management
233
338
 
@@ -1,3 +1,15 @@
1
1
  import { type FoundationCapability } from '../../foundation/capability-plan.js';
2
2
  /** @internal */
3
3
  export declare function renderSliceFoundationFiles(name: string, pascalName: string, capabilities?: readonly FoundationCapability[]): Readonly<Record<string, string>>;
4
+ /**
5
+ * The deployed web URL of a Router-attached package: the Foundation's
6
+ * published routerUrl with the package's path, after the fail-fast checks
7
+ * that refuse SST's wildcard alias host. Product Slices and the root site
8
+ * render their copies from this one template.
9
+ */
10
+ export declare function renderFoundationRouterWebUrl(input: {
11
+ comment: string;
12
+ functionName: string;
13
+ path: string;
14
+ subject: string;
15
+ }): string;
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.renderSliceFoundationFiles = renderSliceFoundationFiles;
4
+ exports.renderFoundationRouterWebUrl = renderFoundationRouterWebUrl;
4
5
  const capability_plan_js_1 = require("../../foundation/capability-plan.js");
5
6
  /** @internal */
6
7
  function renderSliceFoundationFiles(name, pascalName, capabilities = capability_plan_js_1.LEGACY_STANDARD_FOUNDATION_CAPABILITIES) {
@@ -17,6 +18,11 @@ function renderSliceFoundationFiles(name, pascalName, capabilities = capability_
17
18
  productSliceRetentionPath,
18
19
  resolveFoundationStages,
19
20
  } from '@empire-builder-kit/nx/foundation';
21
+ import {
22
+ parseRepositoryOperatingPolicy,
23
+ repositoryPublicDnsForStage,
24
+ } from '@empire-builder-kit/nx/repository-policy';
25
+ import repositoryPolicy from '../../../ebk.repository-policy.json';
20
26
 
21
27
  const stages = resolveFoundationStages({
22
28
  consumerStage: $app.stage,
@@ -29,6 +35,62 @@ function foundationParameter(name: Parameters<typeof foundationSsmPath>[1]) {
29
35
  }).value;
30
36
  }
31
37
 
38
+ export interface SlicePublicDomain {
39
+ apiDomainName: string;
40
+ hostedZoneId: string;
41
+ rootDomain: string;
42
+ }
43
+
44
+ async function publishedFoundationValue(
45
+ name: Parameters<typeof foundationSsmPath>[1],
46
+ ): Promise<string> {
47
+ const path = foundationSsmPath(stages.foundationStage, name);
48
+ try {
49
+ return (await aws.ssm.getParameter({ name: path })).value;
50
+ } catch (error) {
51
+ throw new Error(
52
+ '${name} could not read Foundation ' +
53
+ stages.foundationStage +
54
+ ' discovery ' +
55
+ path +
56
+ ' before registering any resource. Deploy or upgrade the Foundation first, and remove Slices before their Foundation. Cause: ' +
57
+ (error instanceof Error ? error.message : String(error)),
58
+ );
59
+ }
60
+ }
61
+
62
+ // Whether this Slice serves its API on the Foundation's api.<root>
63
+ // domain is decided once, before any resource registers, from the values the
64
+ // Foundation published; SST cannot switch an API domain through an Output.
65
+ // A Slice deploy, refresh or remove therefore needs no EBK_ROOT_DOMAIN. The
66
+ // committed publicDns binding must name the same root, and supplies the zone.
67
+ // sst dev never binds: personal stages keep their own execute-api endpoint.
68
+ export async function resolveSlicePublicDomain(): Promise<
69
+ SlicePublicDomain | undefined
70
+ > {
71
+ if ($dev) return undefined;
72
+ const [hasPublicDomain, rootDomain] = await Promise.all([
73
+ publishedFoundationValue('hasPublicDomain'),
74
+ publishedFoundationValue('rootDomain'),
75
+ ]);
76
+ if (hasPublicDomain === 'false' && rootDomain === 'none') return undefined;
77
+ const binding = repositoryPublicDnsForStage(
78
+ parseRepositoryOperatingPolicy(JSON.stringify(repositoryPolicy)),
79
+ stages.foundationStage,
80
+ );
81
+ if (hasPublicDomain !== 'true' || binding?.rootDomain !== rootDomain)
82
+ throw new Error(
83
+ 'Foundation ' +
84
+ stages.foundationStage +
85
+ ' publishes a custom domain that differs from the committed publicDns binding; reconcile ebk.repository-policy.json and redeploy the Foundation before deploying ${name}.',
86
+ );
87
+ return {
88
+ apiDomainName: 'api.' + rootDomain,
89
+ hostedZoneId: binding.hostedZoneId,
90
+ rootDomain,
91
+ };
92
+ }
93
+
32
94
  export function getFoundation() {
33
95
  return {
34
96
  accountCostPolicyDigest: foundationParameter('accountCostPolicyDigest'),
@@ -77,6 +139,17 @@ ${network
77
139
  };
78
140
  }
79
141
 
142
+ ${renderFoundationRouterWebUrl({
143
+ comment: `// SST derives a referenced Router's url from the distribution's first alias,
144
+ // which can be the wildcard alias when the Foundation serves a custom domain.
145
+ // Deployed Slice URLs come only from the Foundation's published routerUrl. The
146
+ // host check refuses a '*' and any character outside letters, digits, '.' and
147
+ // '-'; it is not a hostname validator.
148
+ `,
149
+ functionName: 'foundationSliceWebUrl',
150
+ path: `/${name}`,
151
+ subject: name,
152
+ })}
80
153
  export function getFoundationInfrastructure() {
81
154
  const discovery = getFoundation();
82
155
  ${network
@@ -171,15 +244,22 @@ export function registerProductRetention(stateMachineArn: any) {
171
244
  }
172
245
 
173
246
  `,
174
- 'infra/index.ts': `import { getFoundation, registerProductSlice } from './foundation.js';
247
+ 'infra/index.ts': `import {
248
+ getFoundation,
249
+ registerProductSlice,
250
+ resolveSlicePublicDomain,
251
+ } from './foundation.js';
175
252
  import { product } from './product.js';
176
253
 
177
- export function app() {
254
+ export async function app() {
178
255
  const foundation = getFoundation();
256
+ // Settled before the first resource registers.
257
+ const publicDomain = await resolveSlicePublicDomain();
179
258
  const registration = registerProductSlice();
180
- const resources = product();
259
+ const resources = product(publicDomain);
181
260
  return {
182
- apiUrl: resources.api.url,
261
+ apiId: resources.api.nodes.api.id,
262
+ apiUrl: resources.apiUrl,
183
263
  authClientId: resources.authClient.id,
184
264
  authUserPoolId: foundation.identityUserPoolId,
185
265
  configurationApplicationId:
@@ -196,10 +276,39 @@ export function app() {
196
276
  performanceEndpoint: resources.performanceEndpoint ?? 'disabled',
197
277
  registration: registration.name,
198
278
  stage: $app.stage,
199
- webUrl: resources.web.url,
279
+ webUrl: resources.webUrl,
200
280
  };
201
281
  }
202
282
  `,
203
283
  };
204
284
  }
285
+ /**
286
+ * The deployed web URL of a Router-attached package: the Foundation's
287
+ * published routerUrl with the package's path, after the fail-fast checks
288
+ * that refuse SST's wildcard alias host. Product Slices and the root site
289
+ * render their copies from this one template.
290
+ */
291
+ function renderFoundationRouterWebUrl(input) {
292
+ return `${input.comment}export function ${input.functionName}(
293
+ discovery: ReturnType<typeof getFoundation> = getFoundation(),
294
+ ) {
295
+ return $resolve({
296
+ hasPublicDomain: discovery.hasPublicDomain,
297
+ rootDomain: discovery.rootDomain,
298
+ routerUrl: discovery.routerUrl,
299
+ }).apply(({ hasPublicDomain, rootDomain, routerUrl }) => {
300
+ const url = new URL('${input.path}', routerUrl);
301
+ if (
302
+ url.protocol !== 'https:' ||
303
+ !/^[a-z0-9.-]+$/.test(url.hostname) ||
304
+ (hasPublicDomain ? url.hostname !== rootDomain : rootDomain !== undefined)
305
+ )
306
+ throw new Error(
307
+ 'Foundation discovery routerUrl is not the concrete HTTPS Router origin for its published domain; reconcile the Foundation before deploying ${input.subject}.',
308
+ );
309
+ return url.href;
310
+ });
311
+ }
312
+ `;
313
+ }
205
314
  //# sourceMappingURL=built-in-plan-foundation-files.js.map
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.renderProductFrontendFiles = renderProductFrontendFiles;
4
+ const built_in_plan_frontend_header_proof_js_1 = require("./built-in-plan-frontend-header-proof.js");
4
5
  const built_in_plan_shared_js_1 = require("./built-in-plan-shared.js");
5
6
  const index_js_1 = require("../../frontend-security/index.js");
6
7
  /** @internal */
@@ -1461,277 +1462,7 @@ function main() {
1461
1462
 
1462
1463
  main();
1463
1464
  `,
1464
- 'scripts/frontend-security-headers.mjs': `import { createHash } from 'node:crypto';
1465
- import { mkdirSync, readFileSync, realpathSync, writeFileSync } from 'node:fs';
1466
- import { dirname, relative, resolve, sep } from 'node:path';
1467
- import { fileURLToPath } from 'node:url';
1468
- import {
1469
- inspectFrontendSecurityHeaders as inspectOwnedFrontendSecurityHeaders,
1470
- resolveFrontendSecurityHeaderProfile,
1471
- } from '@empire-builder-kit/nx/frontend-security';
1472
-
1473
- const projectRoot = resolve(dirname(fileURLToPath(import.meta.url)), '..');
1474
- const foundationPolicyPath = resolve(
1475
- projectRoot,
1476
- '..',
1477
- 'foundation',
1478
- 'contracts',
1479
- 'frontend-security-headers.json',
1480
- );
1481
- const slicePolicyPath = resolve(
1482
- projectRoot,
1483
- 'frontend',
1484
- 'security-headers.json',
1485
- );
1486
- const readPolicy = (path) => {
1487
- const contents = readFileSync(path);
1488
- return {
1489
- digest: 'sha256:' + createHash('sha256').update(contents).digest('hex'),
1490
- value: JSON.parse(contents),
1491
- };
1492
- };
1493
- const foundationPolicy = readPolicy(foundationPolicyPath);
1494
- const slicePolicy = readPolicy(slicePolicyPath);
1495
- const gitObjectIdPattern = /^(?:[a-f0-9]{40}|[a-f0-9]{64})$/;
1496
- const MAX_FRONTEND_HEADER_FETCH_TIMEOUT_MS = 10_000;
1497
-
1498
- function loopback(hostname) {
1499
- return ['127.0.0.1', 'localhost', '::1', '[::1]'].includes(hostname);
1500
- }
1501
-
1502
- function safeTarget(value, profile, allowLoopbackTransportProof) {
1503
- const target = new URL(value);
1504
- if (
1505
- (target.protocol !== 'https:' &&
1506
- !(
1507
- loopback(target.hostname) &&
1508
- target.protocol === 'http:' &&
1509
- (profile === 'local-development' || allowLoopbackTransportProof)
1510
- )) ||
1511
- target.username ||
1512
- target.password ||
1513
- target.search ||
1514
- target.hash
1515
- ) {
1516
- throw new Error('Frontend header target must be HTTPS without credentials, query, or fragment.');
1517
- }
1518
- return target;
1519
- }
1520
-
1521
- export function inspectFrontendSecurityHeaders({
1522
- allowLoopbackTransportProof = false,
1523
- headers,
1524
- https,
1525
- profile = 'deployed-https',
1526
- }) {
1527
- return inspectOwnedFrontendSecurityHeaders({
1528
- actual: headers,
1529
- allowLoopbackTransportProof,
1530
- foundation: foundationPolicy.value,
1531
- https,
1532
- profile,
1533
- slice: slicePolicy.value,
1534
- sliceName: '${name}',
1535
- });
1536
- }
1537
-
1538
- function responseNonce(headers) {
1539
- const policy = new Headers(headers).get('content-security-policy') ?? '';
1540
- const nonces = [
1541
- ...policy.matchAll(/'nonce-([A-Za-z0-9+/_-]{16,128}={0,2})'/g),
1542
- ].map((match) => match[1]);
1543
- const unique = [...new Set(nonces)];
1544
- return unique.length === 1 && nonces.length >= 2 ? unique[0] : undefined;
1545
- }
1546
-
1547
- export function inspectFrontendNonceFreshness(firstHeaders, secondHeaders) {
1548
- const first = responseNonce(firstHeaders);
1549
- const second = responseNonce(secondHeaders);
1550
- return {
1551
- firstNoncePresent: first !== undefined,
1552
- fresh: first !== undefined && second !== undefined && first !== second,
1553
- secondNoncePresent: second !== undefined,
1554
- };
1555
- }
1556
-
1557
- function outputPath(argument) {
1558
- const output = resolve(
1559
- projectRoot,
1560
- argument?.slice('--output='.length) ??
1561
- '.ebk/evidence/frontend/security-headers.json',
1562
- );
1563
- const fromRoot = relative(projectRoot, output);
1564
- if (fromRoot === '..' || fromRoot.startsWith('..' + sep)) {
1565
- throw new Error('Frontend header evidence must remain inside the Product Slice.');
1566
- }
1567
- return output;
1568
- }
1569
-
1570
- function fetchTimeout() {
1571
- const value =
1572
- process.env.EBK_FRONTEND_HEADER_FETCH_TIMEOUT_MS?.trim() ?? '10000';
1573
- if (!/^[1-9]\\d*$/.test(value)) {
1574
- throw new Error(
1575
- 'EBK_FRONTEND_HEADER_FETCH_TIMEOUT_MS must be a positive integer.',
1576
- );
1577
- }
1578
- const milliseconds = Number(value);
1579
- if (milliseconds > MAX_FRONTEND_HEADER_FETCH_TIMEOUT_MS) {
1580
- throw new Error(
1581
- 'EBK_FRONTEND_HEADER_FETCH_TIMEOUT_MS may not exceed ' +
1582
- MAX_FRONTEND_HEADER_FETCH_TIMEOUT_MS +
1583
- ' milliseconds.',
1584
- );
1585
- }
1586
- return milliseconds;
1587
- }
1588
-
1589
- export async function fetchFrontendResponse(
1590
- target,
1591
- timeout,
1592
- fetchImplementation = fetch,
1593
- ) {
1594
- const signal = AbortSignal.timeout(timeout);
1595
- try {
1596
- return await fetchImplementation(target, { redirect: 'error', signal });
1597
- } catch (error) {
1598
- if (signal.aborted) {
1599
- throw new Error(
1600
- 'Frontend header request did not complete within ' +
1601
- timeout +
1602
- ' milliseconds.',
1603
- { cause: error },
1604
- );
1605
- }
1606
- throw error;
1607
- }
1608
- }
1609
-
1610
- async function main() {
1611
- const arguments_ = process.argv.slice(2);
1612
- const urlArguments = arguments_.filter((value) => value.startsWith('--url='));
1613
- const outputArguments = arguments_.filter((value) =>
1614
- value.startsWith('--output='),
1615
- );
1616
- const allowLoopbackTransportProof = arguments_.includes(
1617
- '--allow-loopback-transport-proof',
1618
- );
1619
- const unsupported = arguments_.filter(
1620
- (value) =>
1621
- !value.startsWith('--url=') &&
1622
- !value.startsWith('--output=') &&
1623
- value !== '--allow-loopback-transport-proof',
1624
- );
1625
- if (
1626
- urlArguments.length > 1 ||
1627
- outputArguments.length > 1 ||
1628
- unsupported.length > 0
1629
- ) {
1630
- throw new Error(
1631
- 'Usage: frontend-security-headers.mjs [--url=<url>] [--output=<path>] [--allow-loopback-transport-proof]',
1632
- );
1633
- }
1634
- const profile = resolveFrontendSecurityHeaderProfile(process.env);
1635
- const target = safeTarget(
1636
- urlArguments[0]?.slice('--url='.length) ??
1637
- process.env.EBK_FRONTEND_URL ??
1638
- '',
1639
- profile,
1640
- allowLoopbackTransportProof,
1641
- );
1642
- const timeout = fetchTimeout();
1643
- const response = await fetchFrontendResponse(target, timeout);
1644
- const hostedTransportVerified =
1645
- profile === 'deployed-https' && target.protocol === 'https:';
1646
- const inspected = inspectFrontendSecurityHeaders({
1647
- allowLoopbackTransportProof,
1648
- headers: response.headers,
1649
- https: target.protocol === 'https:',
1650
- profile,
1651
- });
1652
- const freshnessResponse = hostedTransportVerified
1653
- ? await fetchFrontendResponse(target, timeout)
1654
- : undefined;
1655
- const freshnessInspection = freshnessResponse
1656
- ? inspectFrontendSecurityHeaders({
1657
- allowLoopbackTransportProof,
1658
- headers: freshnessResponse.headers,
1659
- https: true,
1660
- profile,
1661
- })
1662
- : undefined;
1663
- const nonceFreshness = freshnessResponse
1664
- ? inspectFrontendNonceFreshness(response.headers, freshnessResponse.headers)
1665
- : {
1666
- firstNoncePresent: false,
1667
- fresh: false,
1668
- secondNoncePresent: false,
1669
- };
1670
- const nonceFreshnessVerified =
1671
- hostedTransportVerified &&
1672
- freshnessResponse !== undefined &&
1673
- freshnessResponse.status >= 200 &&
1674
- freshnessResponse.status < 400 &&
1675
- freshnessInspection?.findings.length === 0 &&
1676
- nonceFreshness.fresh;
1677
- const sourceCommit =
1678
- process.env.EBK_SOURCE_COMMIT?.trim() ?? 'unresolved-local-source';
1679
- const stage = process.env.EBK_STAGE?.trim() ?? 'development';
1680
- const findings = [
1681
- ...inspected.findings,
1682
- ...(profile === 'deployed-https' && !gitObjectIdPattern.test(sourceCommit)
1683
- ? ['deployed-source-commit-required']
1684
- : []),
1685
- ...(response.status >= 200 && response.status < 400
1686
- ? []
1687
- : ['frontend-response-unsuccessful']),
1688
- ...(hostedTransportVerified && !nonceFreshnessVerified
1689
- ? ['hosted-response-nonce-not-fresh']
1690
- : []),
1691
- ].sort();
1692
- const proofScope =
1693
- profile === 'local-development'
1694
- ? 'local-development'
1695
- : hostedTransportVerified
1696
- ? 'hosted-deployed'
1697
- : 'local-response-composition';
1698
- const result = {
1699
- ...inspected,
1700
- binding: {
1701
- foundationPolicyDigest: foundationPolicy.digest,
1702
- slicePolicyDigest: slicePolicy.digest,
1703
- sourceCommit,
1704
- stage,
1705
- targetOriginDigest:
1706
- 'sha256:' +
1707
- createHash('sha256').update(target.origin, 'utf8').digest('hex'),
1708
- },
1709
- findings,
1710
- hostedTransportVerified,
1711
- nonceFreshnessVerified,
1712
- outcome: findings.length === 0 ? 'passed' : 'failed',
1713
- proofScope,
1714
- response: {
1715
- https: target.protocol === 'https:',
1716
- pathname: target.pathname,
1717
- status: response.status,
1718
- },
1719
- };
1720
- const output = outputPath(outputArguments[0]);
1721
- mkdirSync(dirname(output), { recursive: true, mode: 0o700 });
1722
- writeFileSync(output, JSON.stringify(result, null, 2) + '\\n', { mode: 0o600 });
1723
- process.stdout.write(JSON.stringify(result) + '\\n');
1724
- if (result.outcome !== 'passed') process.exitCode = 1;
1725
- }
1726
-
1727
- if (
1728
- process.argv[1] &&
1729
- realpathSync(resolve(process.argv[1])) ===
1730
- realpathSync(fileURLToPath(import.meta.url))
1731
- ) {
1732
- await main();
1733
- }
1734
- `,
1465
+ 'scripts/frontend-security-headers.mjs': (0, built_in_plan_frontend_header_proof_js_1.renderFrontendSecurityHeaderProof)(name, 'Product Slice'),
1735
1466
  'scripts/frontend-visual-report.mjs': `import { createHash } from 'node:crypto';
1736
1467
  import {
1737
1468
  lstatSync,
@@ -0,0 +1,6 @@
1
+ /**
2
+ * The managed deployed header proof, scripts/frontend-security-headers.mjs.
3
+ * `owner` names what its evidence output must stay inside: a Product Slice
4
+ * or the root site.
5
+ */
6
+ export declare function renderFrontendSecurityHeaderProof(name: string, owner: string): string;