@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,78 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ROOT_SITE_SLICE_READINESS_UPGRADE_MESSAGE = exports.SLICE_READINESS_HELPER_PATH = void 0;
4
+ exports.workspaceHasRootSite = workspaceHasRootSite;
5
+ exports.sliceReadinessPredatesRootSite = sliceReadinessPredatesRootSite;
6
+ exports.slicesNeedingRootSiteReadinessUpgrade = slicesNeedingRootSiteReadinessUpgrade;
7
+ exports.formatRootSiteReadinessUpgrade = formatRootSiteReadinessUpgrade;
8
+ const node_path_1 = require("node:path");
9
+ const resolver_js_1 = require("../blueprints/resolver.js");
10
+ const site_record_js_1 = require("../ownership/site-record.js");
11
+ const record_js_1 = require("../ownership/record.js");
12
+ const root_site_js_1 = require("./root-site.js");
13
+ /** The Slice's managed deployed readiness helper, relative to its root. */
14
+ exports.SLICE_READINESS_HELPER_PATH = 'scripts/deployed-smoke-readiness.mjs';
15
+ exports.ROOT_SITE_SLICE_READINESS_UPGRADE_MESSAGE = 'This workspace has a root site; apply the Slice upgrade so deployed readiness recognises root-site fallthrough.';
16
+ /**
17
+ * Whether the workspace has a root site: a site-kind ownership record at
18
+ * packages/site, or any project tagged type:site. Either signal is enough.
19
+ * A record there that is not valid JSON counts as a site, so the guards that
20
+ * ask fail closed.
21
+ */
22
+ function workspaceHasRootSite(readFile, projectTags = []) {
23
+ if (projectTags.some((tags) => tags?.includes('type:site') === true)) {
24
+ return true;
25
+ }
26
+ const source = readFile(node_path_1.posix.join(root_site_js_1.ROOT_SITE_ROOT, '.ebk/ownership.json'));
27
+ if (source === undefined)
28
+ return false;
29
+ try {
30
+ return (0, site_record_js_1.isSiteOwnershipRecord)(JSON.parse(source));
31
+ }
32
+ catch {
33
+ return true;
34
+ }
35
+ }
36
+ /**
37
+ * Whether a Slice's managed readiness would fail a route that falls through to
38
+ * the root site. It applies only to a built-in Slice whose ownership lists the
39
+ * helper as managed; an External Blueprint Slice has no framework helper. The
40
+ * check reads the content, not a digest, because generation formats the
41
+ * helper: any helper without the literal contract token predates the root
42
+ * site. An unreadable or invalid record fails closed.
43
+ */
44
+ function sliceReadinessPredatesRootSite(readFile, sliceRoot) {
45
+ const source = readFile(node_path_1.posix.join(sliceRoot, '.ebk/ownership.json'));
46
+ if (source === undefined)
47
+ return false;
48
+ let value;
49
+ try {
50
+ value = JSON.parse(source);
51
+ }
52
+ catch {
53
+ return true;
54
+ }
55
+ const record = (0, record_js_1.validateGeneratedOwnershipRecord)(value);
56
+ if (!record.valid)
57
+ return true;
58
+ if (record.value.blueprint.name !== resolver_js_1.BUILTIN_BLUEPRINT_NAME)
59
+ return false;
60
+ const entry = record.value.paths.find(({ path }) => path === exports.SLICE_READINESS_HELPER_PATH);
61
+ if (!entry || entry.mode !== 'managed')
62
+ return false;
63
+ const helper = readFile(node_path_1.posix.join(sliceRoot, exports.SLICE_READINESS_HELPER_PATH));
64
+ return (helper === undefined || !helper.includes(root_site_js_1.ROOT_SITE_READINESS_CONTRACT_TOKEN));
65
+ }
66
+ /** The Slices, by name, whose readiness must be upgraded beside a root site. */
67
+ function slicesNeedingRootSiteReadinessUpgrade(readFile, slices) {
68
+ return slices
69
+ .filter(({ root }) => sliceReadinessPredatesRootSite(readFile, root))
70
+ .map(({ name }) => name)
71
+ .sort((left, right) => (left < right ? -1 : left > right ? 1 : 0));
72
+ }
73
+ function formatRootSiteReadinessUpgrade(names) {
74
+ return `${exports.ROOT_SITE_SLICE_READINESS_UPGRADE_MESSAGE} Upgrade first: ${names
75
+ .map((name) => `pnpm nx g @empire-builder-kit/nx:upgrade ${name}`)
76
+ .join('; ')}.`;
77
+ }
78
+ //# sourceMappingURL=root-site-readiness.js.map
@@ -0,0 +1,81 @@
1
+ /**
2
+ * The workspace root site is the fixed `packages/site` project that the
3
+ * Foundation Router serves at `/`. Its name is reserved everywhere a Product
4
+ * Slice name is accepted, so the package directory, the managed log groups,
5
+ * the Foundation registration and the deployment selection stay unambiguous.
6
+ */
7
+ export declare const ROOT_SITE_NAME: "site";
8
+ export declare const ROOT_SITE_ROOT: "packages/site";
9
+ export declare const ROOT_SITE_RESERVED_SLICE_NAME_MESSAGE = "site is reserved for the workspace root site (pnpm nx g @empire-builder-kit/nx:site); choose another Product Slice name.";
10
+ /**
11
+ * A record at packages/site that is not valid JSON could be the root site's,
12
+ * so the root-site reservation checks that read it fail closed instead of skipping.
13
+ */
14
+ export declare const ROOT_SITE_UNREADABLE_RECORD_MESSAGE = "packages/site/.ebk/ownership.json is not valid JSON, and packages/site is reserved for the workspace root site. Restore that ownership record before continuing.";
15
+ export declare const ROOT_SITE_RENAME_GUIDANCE = "Rename that Product Slice before upgrading: generate it under a new name, move its code and its policy entry, deploy it, then remove the old Slice through its supported remove.";
16
+ export declare function isReservedRootSiteName(name: string): boolean;
17
+ /** The framework-owned health route, served at `/__ebk/health`. */
18
+ export declare const ROOT_SITE_HEALTH_PATH: "/__ebk/health";
19
+ /** The managed health route source, relative to the site's `web/`. */
20
+ export declare const ROOT_SITE_HEALTH_ROUTE_SOURCE: "src/app/%5F%5Febk/health/route.ts";
21
+ /**
22
+ * Every response the site's managed proxy handles carries this header, so a
23
+ * Slice route that has not reached a Router edge yet and falls through to the
24
+ * site is recognisable as edge routing, not as a Slice failure.
25
+ */
26
+ export declare const ROOT_SITE_ROUTE_HEADER: "x-ebk-route";
27
+ export declare const ROOT_SITE_ROUTE_HEADER_VALUE: "site";
28
+ /**
29
+ * The classification a Slice's managed deployed readiness records for a
30
+ * response the root site marked. Its literal presence in a Slice's helper is
31
+ * the mixed-version contract: a helper without it predates the root site and
32
+ * fails a new Slice route that falls through to the site.
33
+ */
34
+ export declare const ROOT_SITE_READINESS_CONTRACT_TOKEN: "site-fallthrough";
35
+ /** The site's managed Next.js log components, as for a Slice web. */
36
+ export declare const ROOT_SITE_LOG_COMPONENTS: readonly ["next-image-optimizer", "next-revalidation-seeder", "next-revalidation-subscriber", "next-server"];
37
+ /**
38
+ * The directories below the site's `web/` that can hold a route; the route
39
+ * check reads only these. Build output (`.next`, `.open-next`) and installed
40
+ * packages are never walked.
41
+ */
42
+ export declare const ROOT_SITE_ROUTE_ROOTS: readonly ["app", "pages", "public", "src/app", "src/pages"];
43
+ /** The most directory entries a route check walks below the route roots. */
44
+ export declare const ROOT_SITE_ROUTE_ENTRY_LIMIT = 65536;
45
+ export type RootSiteRouteFindingCode = 'catch-all-route' | 'pages-router' | 'public-directory-prefix' | 'public-html' | 'reserved-segment' | 'slice-collision' | 'unsupported-app-root';
46
+ export interface RootSiteRouteFinding {
47
+ code: RootSiteRouteFindingCode;
48
+ message: string;
49
+ /** The offending source path, relative to the site's `web/`. */
50
+ path: string;
51
+ }
52
+ export interface RootSiteRouteInventory {
53
+ /** Top-level one-segment dynamic routes, which cannot be checked. */
54
+ dynamicRoutes: string[];
55
+ findings: RootSiteRouteFinding[];
56
+ /** Top-level `web/public/` directories the Router serves by prefix. */
57
+ publicDirectories: string[];
58
+ /** Every top-level URL segment the site serves, decoded. */
59
+ segments: string[];
60
+ }
61
+ /**
62
+ * Inventories the top-level URL segments a root site serves and refuses
63
+ * every route that could shadow a Product Slice, the framework subtree or
64
+ * Next.js's own prefix. `files` lists every file below the site's `web/`
65
+ * (posix, relative to `web/`); `sliceNames` lists the workspace's Product
66
+ * Slices. The Router gives every Slice path precedence over the site on every
67
+ * host, so a site route named like a Slice silently stops serving once the
68
+ * Slice deploys, and during a new Slice's edge propagation the site answers
69
+ * that Slice's paths.
70
+ */
71
+ export declare function inspectRootSiteRoutes(input: {
72
+ files: readonly string[];
73
+ sliceNames: readonly string[];
74
+ }): RootSiteRouteInventory;
75
+ /**
76
+ * The reverse route check for a new Product Slice beside a root site: the
77
+ * site already serves the name, or one of its public directories would
78
+ * capture every path of the new Slice.
79
+ */
80
+ export declare function rootSiteSliceNameConflicts(inventory: Pick<RootSiteRouteInventory, 'publicDirectories' | 'segments'>, sliceName: string): string[];
81
+ export declare function formatRootSiteRouteInventory(inventory: RootSiteRouteInventory): string;
@@ -0,0 +1,268 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ROOT_SITE_ROUTE_ENTRY_LIMIT = exports.ROOT_SITE_ROUTE_ROOTS = exports.ROOT_SITE_LOG_COMPONENTS = exports.ROOT_SITE_READINESS_CONTRACT_TOKEN = exports.ROOT_SITE_ROUTE_HEADER_VALUE = exports.ROOT_SITE_ROUTE_HEADER = exports.ROOT_SITE_HEALTH_ROUTE_SOURCE = exports.ROOT_SITE_HEALTH_PATH = exports.ROOT_SITE_RENAME_GUIDANCE = exports.ROOT_SITE_UNREADABLE_RECORD_MESSAGE = exports.ROOT_SITE_RESERVED_SLICE_NAME_MESSAGE = exports.ROOT_SITE_ROOT = exports.ROOT_SITE_NAME = void 0;
4
+ exports.isReservedRootSiteName = isReservedRootSiteName;
5
+ exports.inspectRootSiteRoutes = inspectRootSiteRoutes;
6
+ exports.rootSiteSliceNameConflicts = rootSiteSliceNameConflicts;
7
+ exports.formatRootSiteRouteInventory = formatRootSiteRouteInventory;
8
+ /**
9
+ * The workspace root site is the fixed `packages/site` project that the
10
+ * Foundation Router serves at `/`. Its name is reserved everywhere a Product
11
+ * Slice name is accepted, so the package directory, the managed log groups,
12
+ * the Foundation registration and the deployment selection stay unambiguous.
13
+ */
14
+ exports.ROOT_SITE_NAME = 'site';
15
+ exports.ROOT_SITE_ROOT = 'packages/site';
16
+ exports.ROOT_SITE_RESERVED_SLICE_NAME_MESSAGE = 'site is reserved for the workspace root site (pnpm nx g @empire-builder-kit/nx:site); choose another Product Slice name.';
17
+ /**
18
+ * A record at packages/site that is not valid JSON could be the root site's,
19
+ * so the root-site reservation checks that read it fail closed instead of skipping.
20
+ */
21
+ exports.ROOT_SITE_UNREADABLE_RECORD_MESSAGE = 'packages/site/.ebk/ownership.json is not valid JSON, and packages/site is reserved for the workspace root site. Restore that ownership record before continuing.';
22
+ exports.ROOT_SITE_RENAME_GUIDANCE = 'Rename that Product Slice before upgrading: generate it under a new name, move its code and its policy entry, deploy it, then remove the old Slice through its supported remove.';
23
+ function isReservedRootSiteName(name) {
24
+ return name === exports.ROOT_SITE_NAME;
25
+ }
26
+ /** The framework-owned health route, served at `/__ebk/health`. */
27
+ exports.ROOT_SITE_HEALTH_PATH = '/__ebk/health';
28
+ /** The managed health route source, relative to the site's `web/`. */
29
+ exports.ROOT_SITE_HEALTH_ROUTE_SOURCE = 'src/app/%5F%5Febk/health/route.ts';
30
+ /**
31
+ * Every response the site's managed proxy handles carries this header, so a
32
+ * Slice route that has not reached a Router edge yet and falls through to the
33
+ * site is recognisable as edge routing, not as a Slice failure.
34
+ */
35
+ exports.ROOT_SITE_ROUTE_HEADER = 'x-ebk-route';
36
+ exports.ROOT_SITE_ROUTE_HEADER_VALUE = 'site';
37
+ /**
38
+ * The classification a Slice's managed deployed readiness records for a
39
+ * response the root site marked. Its literal presence in a Slice's helper is
40
+ * the mixed-version contract: a helper without it predates the root site and
41
+ * fails a new Slice route that falls through to the site.
42
+ */
43
+ exports.ROOT_SITE_READINESS_CONTRACT_TOKEN = 'site-fallthrough';
44
+ /** The site's managed Next.js log components, as for a Slice web. */
45
+ exports.ROOT_SITE_LOG_COMPONENTS = [
46
+ 'next-image-optimizer',
47
+ 'next-revalidation-seeder',
48
+ 'next-revalidation-subscriber',
49
+ 'next-server',
50
+ ];
51
+ /**
52
+ * The directories below the site's `web/` that can hold a route; the route
53
+ * check reads only these. Build output (`.next`, `.open-next`) and installed
54
+ * packages are never walked.
55
+ */
56
+ exports.ROOT_SITE_ROUTE_ROOTS = [
57
+ 'app',
58
+ 'pages',
59
+ 'public',
60
+ 'src/app',
61
+ 'src/pages',
62
+ ];
63
+ /** The most directory entries a route check walks below the route roots. */
64
+ exports.ROOT_SITE_ROUTE_ENTRY_LIMIT = 65_536;
65
+ // Next.js's own asset prefix and the framework-owned subtree. No Slice name
66
+ // can start with '_', so neither ever collides with a Slice.
67
+ const RESERVED_SEGMENTS = ['__ebk', '_next'];
68
+ // SST expands these public directories into individual files instead of a
69
+ // prefix route (ssr-site.ts: expandDirs and the Next.js deep route).
70
+ const EXPANDED_PUBLIC_DIRECTORIES = new Set(['.well-known']);
71
+ const CODE_EXTENSIONS = new Set(['js', 'jsx', 'mjs', 'ts', 'tsx']);
72
+ const IMAGE_METADATA = /^(icon|apple-icon|opengraph-image|twitter-image)(\d*)\.([a-z0-9]+)$/i;
73
+ function sortedUnique(values) {
74
+ return [...new Set(values)].sort((left, right) => left < right ? -1 : left > right ? 1 : 0);
75
+ }
76
+ function decodeSegment(segment) {
77
+ return segment.replace(/%5f/gi, '_');
78
+ }
79
+ function isRouteGroup(segment) {
80
+ return /^\([^().]+\)$/.test(segment);
81
+ }
82
+ function isInterceptingRoute(segment) {
83
+ return /^(?:\(\.{1,3}\))+/.test(segment);
84
+ }
85
+ function isParallelSlot(segment) {
86
+ return segment.startsWith('@');
87
+ }
88
+ function isPrivateFolder(segment) {
89
+ return segment.startsWith('_');
90
+ }
91
+ // The URL segments a root-level app file serves (route groups and slots
92
+ // included), from the Next.js metadata file conventions.
93
+ function rootFileSegments(file) {
94
+ const lower = file.toLowerCase();
95
+ const extension = lower.slice(lower.lastIndexOf('.') + 1);
96
+ const base = lower.slice(0, lower.lastIndexOf('.'));
97
+ if (lower === 'favicon.ico')
98
+ return ['favicon.ico'];
99
+ if (base === 'robots')
100
+ return ['robots.txt'];
101
+ if (base === 'sitemap') {
102
+ // A sitemap generator may also serve /sitemap/<id>.xml.
103
+ return CODE_EXTENSIONS.has(extension)
104
+ ? ['sitemap', 'sitemap.xml']
105
+ : ['sitemap.xml'];
106
+ }
107
+ if (base === 'manifest') {
108
+ return CODE_EXTENSIONS.has(extension) ? ['manifest.webmanifest'] : [lower];
109
+ }
110
+ if (lower.endsWith('.alt.txt'))
111
+ return [];
112
+ const image = IMAGE_METADATA.exec(lower);
113
+ if (image) {
114
+ return CODE_EXTENSIONS.has(extension)
115
+ ? [`${image[1]}${image[2]}`]
116
+ : [lower];
117
+ }
118
+ return [];
119
+ }
120
+ function finding(code, path, message) {
121
+ return { code, message, path };
122
+ }
123
+ /**
124
+ * Inventories the top-level URL segments a root site serves and refuses
125
+ * every route that could shadow a Product Slice, the framework subtree or
126
+ * Next.js's own prefix. `files` lists every file below the site's `web/`
127
+ * (posix, relative to `web/`); `sliceNames` lists the workspace's Product
128
+ * Slices. The Router gives every Slice path precedence over the site on every
129
+ * host, so a site route named like a Slice silently stops serving once the
130
+ * Slice deploys, and during a new Slice's edge propagation the site answers
131
+ * that Slice's paths.
132
+ */
133
+ function inspectRootSiteRoutes(input) {
134
+ const findings = [];
135
+ // Segment -> first source path, kept apart because the Router looks up a
136
+ // public file by its exact name before any public directory prefix.
137
+ const appSegments = new Map();
138
+ const publicSegments = new Map();
139
+ const publicDirectories = new Map();
140
+ const dynamicRoutes = new Set();
141
+ const add = (segments, segment, path) => {
142
+ if (!segments.has(segment))
143
+ segments.set(segment, path);
144
+ };
145
+ const reserved = (segment, path) => {
146
+ findings.push(finding('reserved-segment', path, segment === '_next'
147
+ ? 'The /_next path is reserved for Next.js assets; the root site cannot serve it.'
148
+ : 'The /__ebk subtree is framework-owned; only the managed health route may live there.'));
149
+ };
150
+ for (const path of [...input.files].sort()) {
151
+ const parts = path.split('/');
152
+ if ((parts[0] === 'src' && parts[1] === 'pages' && parts.length > 2) ||
153
+ (parts[0] === 'pages' && parts.length > 1)) {
154
+ findings.push(finding('pages-router', path, 'The root site supports only the App Router under web/src/app; Pages Router routes would bypass the route check.'));
155
+ continue;
156
+ }
157
+ if (parts[0] === 'app' && parts.length > 1) {
158
+ findings.push(finding('unsupported-app-root', path, 'The root site app lives under web/src/app; Next.js would ignore it beside a web/app directory.'));
159
+ continue;
160
+ }
161
+ if (parts[0] === 'public' && parts.length > 1) {
162
+ const top = parts[1];
163
+ if (/\.html?$/i.test(path)) {
164
+ findings.push(finding('public-html', path, 'The Router serves public HTML files straight from storage without the managed security headers; render the page from web/src/app instead.'));
165
+ }
166
+ if (RESERVED_SEGMENTS.includes(top)) {
167
+ reserved(top, path);
168
+ }
169
+ add(publicSegments, top, path);
170
+ if (parts.length > 2 && !EXPANDED_PUBLIC_DIRECTORIES.has(top)) {
171
+ add(publicDirectories, top, path);
172
+ }
173
+ continue;
174
+ }
175
+ if (parts[0] !== 'src' || parts[1] !== 'app' || parts.length < 3) {
176
+ continue;
177
+ }
178
+ const route = parts.slice(2);
179
+ let top;
180
+ let routable = true;
181
+ for (const segment of route.slice(0, -1)) {
182
+ if (isInterceptingRoute(segment) || isPrivateFolder(segment)) {
183
+ routable = false;
184
+ break;
185
+ }
186
+ if (isRouteGroup(segment) || isParallelSlot(segment))
187
+ continue;
188
+ top = segment;
189
+ break;
190
+ }
191
+ if (!routable)
192
+ continue;
193
+ if (top === undefined) {
194
+ for (const segment of rootFileSegments(route.at(-1))) {
195
+ add(appSegments, segment, path);
196
+ }
197
+ continue;
198
+ }
199
+ if (/^\[\[?\.\.\..+\]\]?$/.test(top)) {
200
+ findings.push(finding('catch-all-route', path, `A top-level catch-all route (${top}) would answer every future Product Slice path while its route reaches the Router edges; it is not supported for the root site.`));
201
+ continue;
202
+ }
203
+ if (/^\[.+\]$/.test(top)) {
204
+ dynamicRoutes.add(top);
205
+ continue;
206
+ }
207
+ const decoded = decodeSegment(top);
208
+ if ((decoded === '__ebk' && path !== exports.ROOT_SITE_HEALTH_ROUTE_SOURCE) ||
209
+ decoded === '_next') {
210
+ reserved(decoded, path);
211
+ }
212
+ add(appSegments, decoded, path);
213
+ }
214
+ const segments = new Map([...publicSegments, ...appSegments]);
215
+ for (const [segment, path] of [...segments].sort(([left], [right]) => left < right ? -1 : left > right ? 1 : 0)) {
216
+ if (input.sliceNames.includes(segment)) {
217
+ findings.push(finding('slice-collision', appSegments.get(segment) ?? path, `The root site serves /${segment}, which Product Slice ${segment} owns; the Slice route always wins, so rename or move this site route.`));
218
+ }
219
+ }
220
+ for (const [directory, path] of publicDirectories) {
221
+ const captured = sortedUnique([
222
+ ...input.sliceNames.map((name) => ['Product Slice', name]),
223
+ ...RESERVED_SEGMENTS.map((name) => ['reserved path', name]),
224
+ ...[...appSegments.keys()].map((name) => ['site path', name]),
225
+ ]
226
+ .filter(([, name]) => name.startsWith(directory))
227
+ .map(([kind, name]) => `${kind} /${name}`));
228
+ if (captured.length > 0) {
229
+ findings.push(finding('public-directory-prefix', path, `The Router serves web/public/${directory} for every path that starts with /${directory}, so it would capture ${captured.join(', ')}; rename the directory.`));
230
+ }
231
+ }
232
+ return {
233
+ dynamicRoutes: sortedUnique([...dynamicRoutes]),
234
+ findings: findings.sort((left, right) => left.path < right.path
235
+ ? -1
236
+ : left.path > right.path
237
+ ? 1
238
+ : left.code < right.code
239
+ ? -1
240
+ : left.code > right.code
241
+ ? 1
242
+ : 0),
243
+ publicDirectories: sortedUnique([...publicDirectories.keys()]),
244
+ segments: sortedUnique([...segments.keys()]),
245
+ };
246
+ }
247
+ /**
248
+ * The reverse route check for a new Product Slice beside a root site: the
249
+ * site already serves the name, or one of its public directories would
250
+ * capture every path of the new Slice.
251
+ */
252
+ function rootSiteSliceNameConflicts(inventory, sliceName) {
253
+ return [
254
+ ...(inventory.segments.includes(sliceName)
255
+ ? [`the root site already serves /${sliceName}`]
256
+ : []),
257
+ ...inventory.publicDirectories
258
+ .filter((directory) => sliceName.startsWith(directory))
259
+ .map((directory) => `the root site's web/public/${directory} directory would capture every /${sliceName} path`),
260
+ ];
261
+ }
262
+ function formatRootSiteRouteInventory(inventory) {
263
+ return [
264
+ ...inventory.findings.map(({ code, message, path }) => `- ${code}: web/${path}: ${message}`),
265
+ ...inventory.dynamicRoutes.map((route) => `- note: web/src/app/${route} is a top-level dynamic route. Product Slices take precedence for their names, and its responses must be dynamic or no-store, because the Router cache key does not include the origin.`),
266
+ ].join('\n');
267
+ }
268
+ //# sourceMappingURL=root-site.js.map
@@ -0,0 +1,2 @@
1
+ import type { Tree } from '@nx/devkit';
2
+ export declare function requireUpgradePrerequisites(tree: Tree, target: 'foundation' | 'product-slice' | 'site', operation?: 'generating' | 'upgrading'): void;
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.requireUpgradePrerequisites = requireUpgradePrerequisites;
4
+ const index_js_1 = require("../ownership/index.js");
5
+ const observability_policy_js_1 = require("./observability-policy.js");
6
+ const generator_js_1 = require("./preset/generator.js");
7
+ const upgrade_plan_js_1 = require("./upgrade/upgrade-plan.js");
8
+ // The workspace prerequisites a generator that renders a framework package
9
+ // from the installed framework shares with the upgrade of that package: the
10
+ // workspace tooling, and for a Product Slice or the root site the Standard
11
+ // Foundation, must already be recorded at the installed version. The upgrade
12
+ // and the root site generator both check them here, so `nx g site` does not
13
+ // load the upgrade generator.
14
+ function requireUpgradePrerequisites(tree, target, operation = 'upgrading') {
15
+ const installedVersion = (0, generator_js_1.frameworkPackageVersion)();
16
+ const workspaceResult = (0, index_js_1.validateWorkspaceOwnershipRecord)((0, upgrade_plan_js_1.readJson)(tree, '.ebk/ownership.json', 'Workspace ownership metadata'));
17
+ if (!workspaceResult.valid) {
18
+ throw new Error((0, upgrade_plan_js_1.ownershipValidationMessage)('Workspace ownership metadata', workspaceResult.issues));
19
+ }
20
+ if (workspaceResult.value.frameworkVersion !== installedVersion) {
21
+ throw new Error(`Workspace tooling is recorded at ${workspaceResult.value.frameworkVersion}, but the installed @empire-builder-kit/nx version is ${installedVersion}. Report and apply the workspace upgrade before ${operation} the ${target === 'foundation' ? 'Standard Foundation' : target === 'site' ? 'root site' : 'Product Slice'}.`);
22
+ }
23
+ (0, observability_policy_js_1.requireObservabilityPolicyFromTree)(tree);
24
+ if (target === 'foundation')
25
+ return;
26
+ const foundationResult = (0, index_js_1.validateFoundationOwnershipRecord)((0, upgrade_plan_js_1.readJson)(tree, 'packages/foundation/.ebk/ownership.json', 'Standard Foundation ownership metadata'));
27
+ if (!foundationResult.valid) {
28
+ throw new Error((0, upgrade_plan_js_1.ownershipValidationMessage)('Standard Foundation ownership metadata', foundationResult.issues));
29
+ }
30
+ if (foundationResult.value.frameworkVersion !== installedVersion) {
31
+ throw new Error(`Standard Foundation is recorded at ${foundationResult.value.frameworkVersion}, but the installed @empire-builder-kit/nx version is ${installedVersion}. Report and apply the Foundation upgrade before ${operation} ${target === 'site' ? 'the root site' : 'a Product Slice'}.`);
32
+ }
33
+ }
34
+ //# sourceMappingURL=framework-prerequisites.js.map
@@ -0,0 +1,24 @@
1
+ import type { FunctionAuthentication } from './function.js';
2
+ /**
3
+ * Matches one registration argument line, ` <callee>('<argument>'),`, in
4
+ * either quote style and in the Prettier-wrapped form a long argument takes.
5
+ */
6
+ export declare function exactIndentedStringCallMatches(source: string, callee: string, argument: string): RegExpMatchArray[];
7
+ /**
8
+ * Who a Function's registration in the managed `infra/product.ts` lets call
9
+ * it: a signed-in Function passes the Slice's `functionAccess` after its
10
+ * secret links, and an anonymous one passes nothing more. `registration` runs
11
+ * from ` register<Symbol>(\n` through its closing `\n );`.
12
+ */
13
+ export declare function functionRegistrationAccess(registration: string, name: string): FunctionAuthentication;
14
+ /** Rewrites one registration so that it passes the Slice's Function access exactly when signed-in. */
15
+ export declare function setFunctionRegistrationAccess(registration: string, name: string, authentication: FunctionAuthentication): string;
16
+ /**
17
+ * The one registration of a Function in the managed `infra/product.ts`,
18
+ * bounded by its exact start line and the first `\n );` after it.
19
+ */
20
+ export declare function locateFunctionRegistration(source: string, register: string, name: string): {
21
+ end: number;
22
+ registration: string;
23
+ start: number;
24
+ };
@@ -0,0 +1,66 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.exactIndentedStringCallMatches = exactIndentedStringCallMatches;
4
+ exports.functionRegistrationAccess = functionRegistrationAccess;
5
+ exports.setFunctionRegistrationAccess = setFunctionRegistrationAccess;
6
+ exports.locateFunctionRegistration = locateFunctionRegistration;
7
+ function escapeRegularExpression(value) {
8
+ return value.replace(/[.*+?^${}()|[\]\\]/gu, '\\$&');
9
+ }
10
+ /**
11
+ * Matches one registration argument line, ` <callee>('<argument>'),`, in
12
+ * either quote style and in the Prettier-wrapped form a long argument takes.
13
+ */
14
+ function exactIndentedStringCallMatches(source, callee, argument) {
15
+ const pattern = new RegExp(`^ ${escapeRegularExpression(callee)}\\(\\s*(['"])${escapeRegularExpression(argument)}\\1\\s*,?\\s*\\),[ \\t]*$`, 'gmu');
16
+ return [...source.matchAll(pattern)];
17
+ }
18
+ const REGISTRATION_END = '\n );';
19
+ const WITH_ACCESS = `\n functionAccess,${REGISTRATION_END}`;
20
+ const MAX_REGISTRATION_LENGTH = 64 * 1024;
21
+ function accessTailIndex(registration, name) {
22
+ const matches = exactIndentedStringCallMatches(registration, 'secretLinksFor', `${name}-function`);
23
+ const [secretLink] = matches;
24
+ if (matches.length !== 1 || secretLink?.index === undefined) {
25
+ throw new Error(`Retained Function ${name} registration does not expose one exact secret-link argument shape.`);
26
+ }
27
+ return secretLink.index + secretLink[0].length;
28
+ }
29
+ /**
30
+ * Who a Function's registration in the managed `infra/product.ts` lets call
31
+ * it: a signed-in Function passes the Slice's `functionAccess` after its
32
+ * secret links, and an anonymous one passes nothing more. `registration` runs
33
+ * from ` register<Symbol>(\n` through its closing `\n );`.
34
+ */
35
+ function functionRegistrationAccess(registration, name) {
36
+ const tail = registration.slice(accessTailIndex(registration, name));
37
+ if (tail === WITH_ACCESS)
38
+ return 'signed-in';
39
+ if (tail === REGISTRATION_END)
40
+ return 'anonymous';
41
+ throw new Error(`Retained Function ${name} registration does not expose one exact Function access argument shape.`);
42
+ }
43
+ /** Rewrites one registration so that it passes the Slice's Function access exactly when signed-in. */
44
+ function setFunctionRegistrationAccess(registration, name, authentication) {
45
+ functionRegistrationAccess(registration, name);
46
+ return (registration.slice(0, accessTailIndex(registration, name)) +
47
+ (authentication === 'signed-in' ? WITH_ACCESS : REGISTRATION_END));
48
+ }
49
+ /**
50
+ * The one registration of a Function in the managed `infra/product.ts`,
51
+ * bounded by its exact start line and the first `\n );` after it.
52
+ */
53
+ function locateFunctionRegistration(source, register, name) {
54
+ const registrationStart = ` ${register}(\n`;
55
+ const start = source.indexOf(registrationStart);
56
+ if (start < 0 || source.indexOf(registrationStart, start + 1) >= 0) {
57
+ throw new Error(`Function ${name} does not have one exact registration in infra/product.ts.`);
58
+ }
59
+ const close = source.indexOf(REGISTRATION_END, start);
60
+ const end = close + REGISTRATION_END.length;
61
+ if (close < 0 || end - start > MAX_REGISTRATION_LENGTH) {
62
+ throw new Error(`Function ${name} does not have one exact registration in infra/product.ts.`);
63
+ }
64
+ return { end, registration: source.slice(start, end), start };
65
+ }
66
+ //# sourceMappingURL=function-registration.js.map
@@ -1,5 +1,8 @@
1
1
  import { type Tree } from '@nx/devkit';
2
2
  import type { FunctionGeneratorSchema } from './schema.js';
3
+ export declare function requireName(value: string, label: string): string;
4
+ /** The workspace name a generated Function's managed files carry. */
5
+ export declare function readFunctionWorkspaceName(tree: Tree): string;
3
6
  export interface FunctionFilePlan {
4
7
  files: Readonly<Record<string, string>>;
5
8
  paths: Array<{
@@ -8,6 +11,18 @@ export interface FunctionFilePlan {
8
11
  }>;
9
12
  register: string;
10
13
  }
11
- export declare function createFunctionFilePlan(workspace: string, slice: string, name: string, feature?: string): FunctionFilePlan;
14
+ /** Who may call a generated Function. Signed-in is the default. */
15
+ export type FunctionAuthentication = 'anonymous' | 'signed-in';
16
+ export declare const FUNCTION_AUTHENTICATIONS: readonly FunctionAuthentication[];
17
+ /** The recorded access of a Function composition: absent means signed-in. */
18
+ export declare function functionAuthenticationOf(composition: {
19
+ authentication?: 'anonymous';
20
+ }): FunctionAuthentication;
21
+ /**
22
+ * The managed Slice product text a Function registration relies on: the
23
+ * lazily created API JWT authorizer that signed-in Functions attach to.
24
+ */
25
+ export declare const FUNCTION_ACCESS_FACTORY_MARKERS: readonly ["\n const functionAccess = () => {\n", "\n void functionAccess;"];
26
+ export declare function createFunctionFilePlan(workspace: string, slice: string, name: string, feature?: string, authentication?: FunctionAuthentication): FunctionFilePlan;
12
27
  export declare function functionGenerator(tree: Tree, options: FunctionGeneratorSchema): Promise<void>;
13
28
  export default functionGenerator;