@empire-builder-kit/nx 1.0.0-rc.45 → 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 (187) 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 +109 -9
  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 +44 -3
  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/github-bootstrap/github-bootstrap.d.ts +3 -0
  22. package/src/executors/github-bootstrap/github-bootstrap.js +28 -0
  23. package/src/executors/github-bootstrap/schema.json +14 -0
  24. package/src/executors/infrastructure-plan/infrastructure-plan.js +10 -3
  25. package/src/executors/local-deploy/local-deploy.d.ts +15 -0
  26. package/src/executors/local-deploy/local-deploy.js +96 -14
  27. package/src/executors/sst-lifecycle/logging-preflight.js +12 -1
  28. package/src/executors/sst-lifecycle/run-sst-command.js +51 -5
  29. package/src/foundation/cost-estimate.js +1 -1
  30. package/src/foundation/identity-domain-parent-ready.d.ts +91 -0
  31. package/src/foundation/identity-domain-parent-ready.js +333 -0
  32. package/src/foundation/identity-domain.d.ts +94 -0
  33. package/src/foundation/identity-domain.js +115 -0
  34. package/src/foundation/index.d.ts +2 -0
  35. package/src/foundation/index.js +7 -0
  36. package/src/foundation/preflight.js +17 -1
  37. package/src/foundation/root-site-readiness.d.ts +27 -0
  38. package/src/foundation/root-site-readiness.js +78 -0
  39. package/src/foundation/root-site.d.ts +81 -0
  40. package/src/foundation/root-site.js +268 -0
  41. package/src/generators/framework-prerequisites.d.ts +2 -0
  42. package/src/generators/framework-prerequisites.js +34 -0
  43. package/src/generators/function/function-registration.d.ts +24 -0
  44. package/src/generators/function/function-registration.js +66 -0
  45. package/src/generators/function/function.d.ts +16 -1
  46. package/src/generators/function/function.js +101 -18
  47. package/src/generators/function/schema.d.ts +1 -0
  48. package/src/generators/function/schema.json +6 -0
  49. package/src/generators/function-access/function-access.d.ts +14 -0
  50. package/src/generators/function-access/function-access.js +141 -0
  51. package/src/generators/function-access/schema.d.ts +6 -0
  52. package/src/generators/function-access/schema.json +25 -0
  53. package/src/generators/post-generation-install.d.ts +1 -1
  54. package/src/generators/post-generation-install.js +1 -1
  55. package/src/generators/preset/dependency-overrides.d.ts +1 -1
  56. package/src/generators/preset/dependency-overrides.js +1 -1
  57. package/src/generators/preset/workspace-files-adopter-skills.js +14 -0
  58. package/src/generators/preset/workspace-files-developer-agent.js +17 -11
  59. package/src/generators/preset/workspace-files-stage-authority.js +58 -1
  60. package/src/generators/preset/workspace-files-thin-deploy.d.ts +11 -0
  61. package/src/generators/preset/workspace-files-thin-deploy.js +52 -5
  62. package/src/generators/preset/workspace-files-thin-docs.js +33 -5
  63. package/src/generators/preset/workspace-files.js +238 -41
  64. package/src/generators/repository-policy/repository-policy.js +2 -1
  65. package/src/generators/repository-policy/schema.d.ts +2 -0
  66. package/src/generators/repository-policy/schema.json +7 -2
  67. package/src/generators/site/built-in-site-documentation-files.d.ts +2 -0
  68. package/src/generators/site/built-in-site-documentation-files.js +92 -0
  69. package/src/generators/site/built-in-site-files.d.ts +8 -0
  70. package/src/generators/site/built-in-site-files.js +40 -0
  71. package/src/generators/site/built-in-site-infrastructure-files.d.ts +2 -0
  72. package/src/generators/site/built-in-site-infrastructure-files.js +275 -0
  73. package/src/generators/site/built-in-site-plan.d.ts +19 -0
  74. package/src/generators/site/built-in-site-plan.js +65 -0
  75. package/src/generators/site/built-in-site-project-files.d.ts +3 -0
  76. package/src/generators/site/built-in-site-project-files.js +258 -0
  77. package/src/generators/site/built-in-site-script-files.d.ts +2 -0
  78. package/src/generators/site/built-in-site-script-files.js +306 -0
  79. package/src/generators/site/built-in-site-shared.d.ts +9 -0
  80. package/src/generators/site/built-in-site-shared.js +21 -0
  81. package/src/generators/site/built-in-site-smoke-files.d.ts +2 -0
  82. package/src/generators/site/built-in-site-smoke-files.js +37 -0
  83. package/src/generators/site/built-in-site-sst-config-files.d.ts +2 -0
  84. package/src/generators/site/built-in-site-sst-config-files.js +39 -0
  85. package/src/generators/site/built-in-site-web-files.d.ts +2 -0
  86. package/src/generators/site/built-in-site-web-files.js +284 -0
  87. package/src/generators/site/schema.d.ts +4 -0
  88. package/src/generators/site/schema.json +20 -0
  89. package/src/generators/site/site.d.ts +13 -0
  90. package/src/generators/site/site.js +221 -0
  91. package/src/generators/slice/built-in-plan-alarm-identity.d.ts +9 -0
  92. package/src/generators/slice/built-in-plan-alarm-identity.js +8 -1
  93. package/src/generators/slice/built-in-plan-api-contract-files.js +18 -0
  94. package/src/generators/slice/built-in-plan-async-work-files.js +18 -0
  95. package/src/generators/slice/built-in-plan-data-files.js +126 -14
  96. package/src/generators/slice/built-in-plan-foundation-files.d.ts +12 -0
  97. package/src/generators/slice/built-in-plan-foundation-files.js +114 -5
  98. package/src/generators/slice/built-in-plan-frontend-files.js +2 -271
  99. package/src/generators/slice/built-in-plan-frontend-header-proof.d.ts +6 -0
  100. package/src/generators/slice/built-in-plan-frontend-header-proof.js +282 -0
  101. package/src/generators/slice/built-in-plan-infrastructure-files.js +151 -237
  102. package/src/generators/slice/built-in-plan-key-value-cleanup.js +4 -3
  103. package/src/generators/slice/built-in-plan-log-group-helpers.d.ts +29 -0
  104. package/src/generators/slice/built-in-plan-log-group-helpers.js +130 -0
  105. package/src/generators/slice/built-in-plan-metadata-files.js +25 -5
  106. package/src/generators/slice/built-in-plan-next-build-authority.d.ts +5 -0
  107. package/src/generators/slice/built-in-plan-next-build-authority.js +124 -0
  108. package/src/generators/slice/built-in-plan-operations-files.d.ts +6 -0
  109. package/src/generators/slice/built-in-plan-operations-files.js +107 -219
  110. package/src/generators/slice/built-in-plan-performance-files.js +6 -1
  111. package/src/generators/slice/built-in-plan-release-files.js +0 -1
  112. package/src/generators/slice/built-in-plan-reliability-files.js +12 -8
  113. package/src/generators/slice/built-in-plan-shared.d.ts +1 -1
  114. package/src/generators/slice/built-in-plan-shared.js +1 -1
  115. package/src/generators/slice/built-in-plan-sst-config.d.ts +49 -0
  116. package/src/generators/slice/built-in-plan-sst-config.js +160 -0
  117. package/src/generators/slice/built-in-plan-testing-files.js +92 -49
  118. package/src/generators/slice/built-in-plan-verification-files.js +15 -5
  119. package/src/generators/slice/built-in-plan-web-files.js +69 -5
  120. package/src/generators/slice/built-in-plan.js +1 -2
  121. package/src/generators/slice/deployed-smoke-diagnostics.d.ts +35 -0
  122. package/src/generators/slice/deployed-smoke-diagnostics.js +189 -0
  123. package/src/generators/slice/deployed-smoke-readiness.d.ts +7 -0
  124. package/src/generators/slice/deployed-smoke-readiness.js +118 -23
  125. package/src/generators/slice/persistence-contract.js +2 -2
  126. package/src/generators/slice/pnpm-launch-script.d.ts +13 -0
  127. package/src/generators/slice/pnpm-launch-script.js +28 -0
  128. package/src/generators/slice/slice.js +27 -0
  129. package/src/generators/upgrade/custom-domain-notice.d.ts +19 -0
  130. package/src/generators/upgrade/custom-domain-notice.js +38 -0
  131. package/src/generators/upgrade/external-blueprint-compositions.d.ts +84 -0
  132. package/src/generators/upgrade/external-blueprint-compositions.js +478 -0
  133. package/src/generators/upgrade/framework-package-upgrade.d.ts +58 -0
  134. package/src/generators/upgrade/framework-package-upgrade.js +78 -0
  135. package/src/generators/upgrade/function-authentication-notice.d.ts +29 -0
  136. package/src/generators/upgrade/function-authentication-notice.js +74 -0
  137. package/src/generators/upgrade/schema.json +2 -2
  138. package/src/generators/upgrade/upgrade-plan.d.ts +52 -0
  139. package/src/generators/upgrade/upgrade-plan.js +406 -0
  140. package/src/generators/upgrade/upgrade.d.ts +1 -35
  141. package/src/generators/upgrade/upgrade.js +347 -595
  142. package/src/generators/workload/reliability-registration.d.ts +1 -1
  143. package/src/generators/workload/reliability-registration.js +9 -9
  144. package/src/generators/workload/workload.d.ts +1 -1
  145. package/src/generators/workload/workload.js +87 -13
  146. package/src/git-policy/github-bootstrap.d.ts +24 -5
  147. package/src/git-policy/github-bootstrap.js +105 -10
  148. package/src/local-dev/fleet-process.d.ts +9 -2
  149. package/src/local-dev/fleet-process.js +27 -7
  150. package/src/local-dev/fleet-session.js +41 -4
  151. package/src/local-dev/fleet-supervisor-daemon.js +1 -5
  152. package/src/local-dev/fleet-supervisor.d.ts +1 -0
  153. package/src/local-dev/fleet-supervisor.js +34 -11
  154. package/src/local-dev/gateway-daemon.d.ts +1 -1
  155. package/src/local-dev/gateway-daemon.js +6 -4
  156. package/src/local-dev/portless.d.ts +5 -0
  157. package/src/local-dev/portless.js +5 -0
  158. package/src/local-dev/process-group.d.ts +10 -0
  159. package/src/local-dev/process-group.js +33 -0
  160. package/src/local-dev/tls.js +31 -2
  161. package/src/local-dev/trust-store.d.ts +42 -0
  162. package/src/local-dev/trust-store.js +87 -0
  163. package/src/ownership/composition.d.ts +7 -0
  164. package/src/ownership/composition.js +64 -56
  165. package/src/ownership/index.d.ts +1 -0
  166. package/src/ownership/index.js +1 -0
  167. package/src/ownership/record.d.ts +19 -0
  168. package/src/ownership/record.js +26 -2
  169. package/src/ownership/site-record.d.ts +18 -0
  170. package/src/ownership/site-record.js +105 -0
  171. package/src/repository-policy/deployment-plan.d.ts +3 -0
  172. package/src/repository-policy/deployment-plan.js +33 -4
  173. package/src/repository-policy/index.d.ts +1 -0
  174. package/src/repository-policy/index.js +1 -0
  175. package/src/repository-policy/policy.d.ts +13 -1
  176. package/src/repository-policy/policy.js +55 -1
  177. package/src/repository-policy/public-dns.d.ts +65 -0
  178. package/src/repository-policy/public-dns.js +168 -0
  179. package/src/schemas/generated-ownership-v2.json +6 -0
  180. package/src/schemas/repository-policy-v1.json +67 -1
  181. package/src/supply-chain/blueprint-trust-git.js +24 -0
  182. package/src/supply-chain/blueprint-verification-authority.js +42 -3
  183. package/src/supply-chain/generated-blueprint-trust-command.js +15 -0
  184. package/src/supply-chain/sbom.js +74 -12
  185. package/src/work-markers/work-markers.js +4 -1
  186. package/src/workspace-deployment/ownership.d.ts +15 -0
  187. package/src/workspace-deployment/ownership.js +19 -3
@@ -0,0 +1,333 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.IDENTITY_DOMAIN_PARENT_RESOLVER_OPTIONS = exports.IDENTITY_DOMAIN_PARENT_PROGRESS_INTERVAL_MS = exports.IDENTITY_DOMAIN_PARENT_TRANSPORT_GRACE_MS = exports.IDENTITY_DOMAIN_PARENT_POLL_INTERVAL_MS = exports.IDENTITY_DOMAIN_PARENT_RESOLUTION_BOUND_MS = void 0;
4
+ exports.systemParentResolver = systemParentResolver;
5
+ exports.authoritativeParentResolver = authoritativeParentResolver;
6
+ exports.createParentReadyHook = createParentReadyHook;
7
+ const node_crypto_1 = require("node:crypto");
8
+ const node_dns_1 = require("node:dns");
9
+ const node_perf_hooks_1 = require("node:perf_hooks");
10
+ // The identity domain's wait for `<root>` to answer: its timings, resolvers
11
+ // and the options its specs inject. The
12
+ // `@empire-builder-kit/nx/foundation` subpath does not re-export this
13
+ // module; it exposes the hook through `identityDomainParentReady`
14
+ // (identity-domain.ts), which takes no options.
15
+ /**
16
+ * How long the identity domain's hook waits for `<root>` to answer an A
17
+ * query. It covers CloudFront's deployment of a new Router distribution with
18
+ * room to spare, and the longest negative answer (900 s under Route 53's
19
+ * default SOA) a cache between this machine and the zone could hold. At the
20
+ * bound the hook warns and lets the create go on: Cognito's own check then
21
+ * decides, as it did before the hook existed. Every lookup, poll and pause
22
+ * ends by the bound.
23
+ */
24
+ exports.IDENTITY_DOMAIN_PARENT_RESOLUTION_BOUND_MS = 15 * 60_000;
25
+ /** The pause between two polls, and before the poll that confirms a release. */
26
+ exports.IDENTITY_DOMAIN_PARENT_POLL_INTERVAL_MS = 10_000;
27
+ /**
28
+ * How long every one of the zone's name servers may fail to answer at all,
29
+ * with no definite answer from any of them, before the hook continues
30
+ * through the system resolver.
31
+ */
32
+ exports.IDENTITY_DOMAIN_PARENT_TRANSPORT_GRACE_MS = 60_000;
33
+ /** The least time between two progress lines. */
34
+ exports.IDENTITY_DOMAIN_PARENT_PROGRESS_INTERVAL_MS = 30_000;
35
+ /**
36
+ * The c-ares options of every resolver the hook builds. With c-ares's
37
+ * back-off, one query to a server that never answers takes about 8 to 10 s
38
+ * (measured), not `timeout` times `tries`.
39
+ */
40
+ exports.IDENTITY_DOMAIN_PARENT_RESOLVER_OPTIONS = Object.freeze({ timeout: 3_000, tries: 2 });
41
+ function parentResolver(options, Resolver, servers) {
42
+ const resolver = new Resolver({
43
+ timeout: options.timeout,
44
+ tries: options.tries,
45
+ });
46
+ if (servers)
47
+ resolver.setServers([...servers]);
48
+ return {
49
+ resolveNs: (name) => resolver.resolveNs(name),
50
+ resolve4: (name) => resolver.resolve4(name),
51
+ cancel: () => resolver.cancel(),
52
+ };
53
+ }
54
+ /**
55
+ * A resolver on this machine's configured DNS servers: it looks up the
56
+ * zone's name servers, and carries the poll on when those servers cannot be
57
+ * reached. Exported so a spec can assert the options it passes.
58
+ */
59
+ function systemParentResolver(options = exports.IDENTITY_DOMAIN_PARENT_RESOLVER_OPTIONS, Resolver = node_dns_1.promises.Resolver) {
60
+ return parentResolver(options, Resolver);
61
+ }
62
+ /**
63
+ * A resolver that asks one of the zone's own name servers, by address, and
64
+ * no other server: Node falls through to another server only on a timeout or
65
+ * an error, never on a negative answer, so the poll asks each server itself.
66
+ * Exported so a spec can assert the options and the server it passes.
67
+ */
68
+ function authoritativeParentResolver(address, options = exports.IDENTITY_DOMAIN_PARENT_RESOLVER_OPTIONS, Resolver = node_dns_1.promises.Resolver) {
69
+ return parentResolver(options, Resolver, [address]);
70
+ }
71
+ /** Only the fixed upper-case c-ares and Node codes are ever logged. */
72
+ function errorCode(reason) {
73
+ const code = typeof reason === 'object' && reason !== null && 'code' in reason
74
+ ? reason.code
75
+ : undefined;
76
+ return typeof code === 'string' && /^[A-Z][A-Z0-9_]{0,31}$/u.test(code)
77
+ ? code
78
+ : 'unknown';
79
+ }
80
+ function classify(outcome) {
81
+ if (outcome.status === 'fulfilled') {
82
+ return Array.isArray(outcome.value) && outcome.value.length > 0
83
+ ? { kind: 'addresses' }
84
+ : { kind: 'not-yet', label: 'NODATA' };
85
+ }
86
+ const code = errorCode(outcome.reason);
87
+ if (code === 'ENODATA')
88
+ return { kind: 'not-yet', label: 'NODATA' };
89
+ if (code === 'ENOTFOUND')
90
+ return { kind: 'not-yet', label: 'NXDOMAIN' };
91
+ return { kind: 'transport', code };
92
+ }
93
+ function authoritativePoll(answers) {
94
+ const of = ` of ${answers.length} servers`;
95
+ const addresses = answers.filter(({ kind }) => kind === 'addresses').length;
96
+ const notYet = answers.filter((answer) => answer.kind === 'not-yet');
97
+ const transport = answers.filter((answer) => answer.kind === 'transport');
98
+ const ready = addresses > 0 && notYet.length === 0;
99
+ const text = ready
100
+ ? `addresses at ${addresses}${of}`
101
+ : notYet.length > 0
102
+ ? `${notYet.some(({ label }) => label === 'NODATA') ? 'NODATA' : 'NXDOMAIN'} at ${notYet.length}${of}`
103
+ : `transport at ${transport.length}${of}`;
104
+ return {
105
+ definite: addresses > 0 || notYet.length > 0,
106
+ ready,
107
+ text,
108
+ transport: `last error ${transport[0]?.code ?? 'unknown'} at ${transport.length}${of}`,
109
+ };
110
+ }
111
+ function discoveryFailure(code) {
112
+ return {
113
+ definite: false,
114
+ ready: false,
115
+ text: "transport looking up the zone's name servers",
116
+ transport: `last error ${code} looking up the zone's name servers`,
117
+ };
118
+ }
119
+ /**
120
+ * The hook `identityDomainParentReady` returns, with what this module's
121
+ * specs inject.
122
+ */
123
+ function createParentReadyHook(rootDomain, options = {}) {
124
+ const boundMs = options.boundMs ?? exports.IDENTITY_DOMAIN_PARENT_RESOLUTION_BOUND_MS;
125
+ const intervalMs = options.intervalMs ?? exports.IDENTITY_DOMAIN_PARENT_POLL_INTERVAL_MS;
126
+ const transportGraceMs = options.transportGraceMs ?? exports.IDENTITY_DOMAIN_PARENT_TRANSPORT_GRACE_MS;
127
+ const progressIntervalMs = options.progressIntervalMs ?? exports.IDENTITY_DOMAIN_PARENT_PROGRESS_INTERVAL_MS;
128
+ const systemResolver = options.systemResolver ?? (() => systemParentResolver());
129
+ const authoritativeResolver = options.authoritativeResolver ??
130
+ ((address) => authoritativeParentResolver(address));
131
+ const nonce = options.nonce ?? (() => 'ebk-parent-' + (0, node_crypto_1.randomBytes)(6).toString('hex'));
132
+ const log = options.log ?? ((line) => console.log(line));
133
+ const now = options.now ?? (() => node_perf_hooks_1.performance.now());
134
+ const sleep = options.sleep ??
135
+ ((ms) => new Promise((resolve) => setTimeout(resolve, ms)));
136
+ const timer = options.timer ??
137
+ ((ms, expire) => {
138
+ const handle = setTimeout(expire, ms);
139
+ return () => clearTimeout(handle);
140
+ });
141
+ const seconds = (ms) => Math.round(ms / 1_000);
142
+ const prefix = 'Foundation identity domain: ';
143
+ return async function identityDomainParentReadyHook(args) {
144
+ const domain = args?.newInputs?.['domain'];
145
+ if (typeof domain === 'string' && domain !== 'auth.' + rootDomain) {
146
+ throw new Error('Foundation identity domain hook received a domain other than auth.<root>. Reconcile the pinned SST version.');
147
+ }
148
+ const started = now();
149
+ const elapsed = () => now() - started;
150
+ const remaining = () => Math.max(0, boundMs - elapsed());
151
+ /**
152
+ * Set once the hook stops. A poll cut short at the bound can still be
153
+ * running then; from then on it starts no lookup and builds no resolver.
154
+ */
155
+ let stopped = false;
156
+ /** Starts a lookup, building its resolver if need be, unless stopped. */
157
+ const lookup = async (start) => {
158
+ if (stopped) {
159
+ throw Object.assign(new Error('The identity domain hook stopped.'), {
160
+ code: 'ECANCELLED',
161
+ });
162
+ }
163
+ return start();
164
+ };
165
+ let system;
166
+ const systemOnce = () => (system ??= systemResolver());
167
+ const byAddress = new Map();
168
+ const resolverFor = (address) => {
169
+ let resolver = byAddress.get(address);
170
+ if (!resolver) {
171
+ resolver = authoritativeResolver(address);
172
+ byAddress.set(address, resolver);
173
+ }
174
+ return resolver;
175
+ };
176
+ /** Kept once every name server's address is known. */
177
+ let servers;
178
+ /**
179
+ * The zone's name servers: those of `<root>`, or, when it is below its
180
+ * zone's apex and has none, of the nearest name above it that has them.
181
+ * The walk stops at a name of two labels; it never asks for a top-level
182
+ * domain's servers.
183
+ */
184
+ const zoneNameServers = async () => {
185
+ for (let name = rootDomain;;) {
186
+ let names;
187
+ try {
188
+ names = await lookup(() => systemOnce().resolveNs(name));
189
+ }
190
+ catch (error) {
191
+ const code = errorCode(error);
192
+ if (code !== 'ENODATA')
193
+ return { code };
194
+ names = [];
195
+ }
196
+ if (!Array.isArray(names))
197
+ return { code: 'unknown' };
198
+ if (names.length > 0)
199
+ return { names };
200
+ const parent = name.slice(name.indexOf('.') + 1);
201
+ if (!name.includes('.') || !parent.includes('.')) {
202
+ return { code: 'ENODATA' };
203
+ }
204
+ name = parent;
205
+ }
206
+ };
207
+ const discover = async () => {
208
+ const zone = await zoneNameServers();
209
+ if ('code' in zone)
210
+ return zone;
211
+ const lookups = await Promise.allSettled(zone.names.map((name) => lookup(() => systemOnce().resolve4(String(name)))));
212
+ const addresses = [
213
+ ...new Set(lookups.flatMap((lookup) => lookup.status === 'fulfilled' && Array.isArray(lookup.value)
214
+ ? lookup.value.filter((value) => typeof value === 'string')
215
+ : [])),
216
+ ];
217
+ const failed = lookups.find((lookup) => lookup.status === 'rejected');
218
+ if (addresses.length === 0) {
219
+ return { code: failed ? errorCode(failed.reason) : 'unknown' };
220
+ }
221
+ const complete = lookups.every((lookup) => lookup.status === 'fulfilled' &&
222
+ Array.isArray(lookup.value) &&
223
+ lookup.value.length > 0);
224
+ // A partial list is polled now and looked up again next poll.
225
+ if (complete)
226
+ servers = addresses;
227
+ return { addresses };
228
+ };
229
+ const pollAuthoritative = async () => {
230
+ let addresses = servers;
231
+ if (!addresses) {
232
+ const found = await discover();
233
+ if ('code' in found)
234
+ return discoveryFailure(found.code);
235
+ addresses = found.addresses;
236
+ }
237
+ const outcomes = await Promise.allSettled(addresses.map((address) => lookup(() => resolverFor(address).resolve4(rootDomain))));
238
+ return authoritativePoll(outcomes.map(classify));
239
+ };
240
+ const pollSystem = async () => {
241
+ const name = nonce() + '.' + rootDomain;
242
+ const [outcome] = await Promise.allSettled([
243
+ lookup(() => systemOnce().resolve4(name)),
244
+ ]);
245
+ const answer = classify(outcome);
246
+ const label = answer.kind === 'not-yet'
247
+ ? answer.label
248
+ : answer.kind === 'transport'
249
+ ? 'transport'
250
+ : 'addresses';
251
+ return {
252
+ definite: answer.kind !== 'transport',
253
+ ready: answer.kind === 'addresses',
254
+ text: `system resolver: ${label}`,
255
+ transport: `last error ${answer.kind === 'transport' ? answer.code : 'unknown'} through the system resolver`,
256
+ };
257
+ };
258
+ /** The poll, or undefined once the bound passes before it ends. */
259
+ const withinBound = async (poll) => {
260
+ let cancel = () => undefined;
261
+ const expired = new Promise((resolve) => {
262
+ cancel = timer(remaining(), () => resolve(undefined));
263
+ });
264
+ try {
265
+ return await Promise.race([poll, expired]);
266
+ }
267
+ finally {
268
+ cancel();
269
+ }
270
+ };
271
+ let continuation = false;
272
+ let definiteSeen = false;
273
+ let confirming = false;
274
+ let lastProgress = started;
275
+ let last;
276
+ try {
277
+ for (;;) {
278
+ // The bound is checked before every poll, a confirming one too, and
279
+ // cuts short a poll still in flight when it passes.
280
+ const poll = elapsed() < boundMs
281
+ ? await withinBound(continuation ? pollSystem() : pollAuthoritative())
282
+ : undefined;
283
+ if (!poll) {
284
+ stopped = true;
285
+ const lastText = last
286
+ ? `${last.text}${confirming ? ', unconfirmed' : ''}`
287
+ : 'none';
288
+ log(`${prefix}<root> still answers no address after ${seconds(boundMs)} s (last poll: ${lastText}); creating auth.<root> anyway, so that Cognito's own parent check decides. If Cognito refuses the parent record, rerun the Foundation deploy once \`dig A <root>\` answers; Cognito's resolver may hold a negative answer for up to 15 minutes.`);
289
+ return;
290
+ }
291
+ last = poll;
292
+ if (!continuation && poll.definite)
293
+ definiteSeen = true;
294
+ if (poll.ready) {
295
+ if (confirming) {
296
+ log(continuation
297
+ ? `${prefix}a fresh name under <root> answers an A query through the system resolver after ${seconds(elapsed())} s; creating auth.<root>.`
298
+ : `${prefix}<root> answers an A query at the zone's name servers after ${seconds(elapsed())} s; creating auth.<root>.`);
299
+ return;
300
+ }
301
+ confirming = true;
302
+ }
303
+ else {
304
+ confirming = false;
305
+ }
306
+ if (!continuation && !definiteSeen && elapsed() >= transportGraceMs) {
307
+ log(`${prefix}the zone's name servers could not be queried from this machine for ${seconds(transportGraceMs)} s (${poll.transport}); continuing through the system resolver with a fresh name under <root>.`);
308
+ continuation = true;
309
+ confirming = false;
310
+ lastProgress = now();
311
+ }
312
+ if (now() - lastProgress >= progressIntervalMs) {
313
+ log(continuation
314
+ ? `${prefix}waiting for a fresh name under <root> to answer an A query through the system resolver (last poll: ${poll.text}; ${seconds(elapsed())} s of ${seconds(boundMs)} s). Cognito refuses auth.<root> until its parent resolves.`
315
+ : `${prefix}waiting for <root> to answer an A query at the zone's name servers (last poll: ${poll.text}; ${seconds(elapsed())} s of ${seconds(boundMs)} s). Cognito refuses auth.<root> until its parent resolves.`);
316
+ lastProgress = now();
317
+ }
318
+ const pause = Math.min(intervalMs, remaining());
319
+ if (pause > 0)
320
+ await sleep(pause);
321
+ }
322
+ }
323
+ finally {
324
+ // A poll cut short at the bound leaves lookups in flight. Stopped
325
+ // first, the poll starts none after they are cancelled.
326
+ stopped = true;
327
+ system?.cancel?.();
328
+ for (const resolver of byAddress.values())
329
+ resolver.cancel?.();
330
+ }
331
+ };
332
+ }
333
+ //# sourceMappingURL=identity-domain-parent-ready.js.map
@@ -0,0 +1,94 @@
1
+ import { type IdentityDomainParentReadyHookArgs } from './identity-domain-parent-ready.js';
2
+ export type { IdentityDomainParentReadyHookArgs } from './identity-domain-parent-ready.js';
3
+ /**
4
+ * The part of SST's DNS adapter (`sst.aws.dns()`) the observer needs. Every
5
+ * other member, such as `createRecord`, `createCaa` or `provider`, is passed
6
+ * through unchanged.
7
+ */
8
+ export interface RouterDnsAdapter {
9
+ createAlias(namePrefix: string, record: {
10
+ name: unknown;
11
+ }, opts: unknown): unknown;
12
+ [member: string]: unknown;
13
+ }
14
+ /** A Pulumi Output of the Router's distribution ID, or anything with `apply`. */
15
+ export interface RouterDistributionId {
16
+ apply(callback: (value: unknown) => unknown): unknown;
17
+ }
18
+ export interface RootAliasRecordsObserver<Dns extends RouterDnsAdapter> {
19
+ /** The Router's DNS adapter, with its alias calls observed. */
20
+ readonly dns: Dns;
21
+ /**
22
+ * Settles with the Router's root and wildcard alias records (A and AAAA
23
+ * for each), in that order, as SST's adapter returned them. Rejects with a
24
+ * named error once the distribution ID resolves without both.
25
+ */
26
+ ready(distributionId: RouterDistributionId): Promise<readonly unknown[]>;
27
+ }
28
+ /**
29
+ * Observe the alias records SST creates for a bound Foundation Router, so the
30
+ * Cognito custom domain on `auth.<root>` can wait for them (area 2).
31
+ *
32
+ * Cognito refuses a custom domain whose parent domain has no A record. SST's
33
+ * Cdn writes the Router's root and `*.<root>` alias records only after its
34
+ * distribution exists, so on a fresh stage the identity domain would
35
+ * otherwise be created minutes before `<root>` resolves. Depending on the
36
+ * Router component does not help: Pulumi expands a component to the children
37
+ * registered when the dependent is prepared, and the records are not
38
+ * children yet. The identity domain waits on the wildcard records as well, so
39
+ * a fresh stage creates it in the same shape as an upgrading stage, whose
40
+ * `*.<root>` records are already live.
41
+ *
42
+ * The returned adapter delegates every call unchanged: the Router's records,
43
+ * certificate and logical names keep their arguments, so an existing bound
44
+ * stage sees no diff.
45
+ *
46
+ * Ordering assumption (review P2-4). SST calls `createAlias` inside the Cdn's
47
+ * `domain.apply`, which resolves from plain inputs within microtasks of the
48
+ * Router's construction, before the distribution exists. The Router's
49
+ * distribution ID resolves when CloudFront's create call returns, not after
50
+ * the Cdn's deployment waiter: SST derives it from the waiter's `isDone`,
51
+ * which the waiter never registers as an output, so it settles as soon as the
52
+ * waiter object exists. That is still after `domain.apply`, which is all
53
+ * `ready` needs: it checks one macrotask after the ID resolves, so an alias
54
+ * created in that same turn still counts. If SST ever resolved the ID first,
55
+ * or stopped creating either alias through this adapter, `ready` rejects with
56
+ * a named error instead of leaving the identity domain waiting forever.
57
+ *
58
+ * Records that exist are not yet records that answer: Route 53 reports the
59
+ * aliases in sync while their distribution is still deploying, and answers
60
+ * them with no address until it is. The identity domain therefore also waits,
61
+ * in its `beforeCreate` hook, until `<root>` answers an A query
62
+ * ({@link identityDomainParentReady}).
63
+ */
64
+ export declare function observeRootAliasRecords<Dns extends RouterDnsAdapter>(dns: Dns, rootDomain: string): RootAliasRecordsObserver<Dns>;
65
+ /**
66
+ * The Pulumi `beforeCreate` hook for the bound Foundation's identity domain.
67
+ *
68
+ * Cognito refuses `auth.<root>` unless `<root>` answers an A query when it
69
+ * creates the domain, and the Router's alias records being in sync is not
70
+ * enough: Route 53 answers an alias to a distribution that is still deploying
71
+ * with no address. The hook polls every one of the zone's own name servers,
72
+ * concurrently and each through its own bounded resolver, until one answers
73
+ * with addresses and none answers that there are none, and confirms that once
74
+ * more one interval later. Authoritative servers hold no negative cache, and
75
+ * the poll seeds none. When `<root>` is below its zone's apex, the zone's
76
+ * name servers are those of the nearest name above it that has them.
77
+ *
78
+ * If no server can be queried at all for the transport grace, and none ever
79
+ * answered, the hook carries on through the system resolver, asking for a
80
+ * fresh name under the zone each poll: the wildcard alias has the same target
81
+ * as the apex, and a name never asked before can sit in no cache. At the
82
+ * bound the hook warns and returns, so that Cognito's own check decides; it
83
+ * never fails a deploy that is still progressing. The bound holds for every
84
+ * part of the wait: a poll still in flight then, the confirming poll
85
+ * included, is cut short, its lookups are cancelled and it starts no other,
86
+ * and no pause runs past it. Its only error is the guard against a domain
87
+ * other than `auth.<root>`.
88
+ *
89
+ * Every line it logs is value-free: it names `<root>` and `auth.<root>`
90
+ * literally, and reports only classes, counts, codes and seconds. Building
91
+ * the hook does no work; the returned function polls only when Pulumi runs it
92
+ * before the domain's create, never during a preview.
93
+ */
94
+ export declare function identityDomainParentReady(rootDomain: string): (args: IdentityDomainParentReadyHookArgs) => Promise<void>;
@@ -0,0 +1,115 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.observeRootAliasRecords = observeRootAliasRecords;
4
+ exports.identityDomainParentReady = identityDomainParentReady;
5
+ const identity_domain_parent_ready_js_1 = require("./identity-domain-parent-ready.js");
6
+ /**
7
+ * Observe the alias records SST creates for a bound Foundation Router, so the
8
+ * Cognito custom domain on `auth.<root>` can wait for them (area 2).
9
+ *
10
+ * Cognito refuses a custom domain whose parent domain has no A record. SST's
11
+ * Cdn writes the Router's root and `*.<root>` alias records only after its
12
+ * distribution exists, so on a fresh stage the identity domain would
13
+ * otherwise be created minutes before `<root>` resolves. Depending on the
14
+ * Router component does not help: Pulumi expands a component to the children
15
+ * registered when the dependent is prepared, and the records are not
16
+ * children yet. The identity domain waits on the wildcard records as well, so
17
+ * a fresh stage creates it in the same shape as an upgrading stage, whose
18
+ * `*.<root>` records are already live.
19
+ *
20
+ * The returned adapter delegates every call unchanged: the Router's records,
21
+ * certificate and logical names keep their arguments, so an existing bound
22
+ * stage sees no diff.
23
+ *
24
+ * Ordering assumption (review P2-4). SST calls `createAlias` inside the Cdn's
25
+ * `domain.apply`, which resolves from plain inputs within microtasks of the
26
+ * Router's construction, before the distribution exists. The Router's
27
+ * distribution ID resolves when CloudFront's create call returns, not after
28
+ * the Cdn's deployment waiter: SST derives it from the waiter's `isDone`,
29
+ * which the waiter never registers as an output, so it settles as soon as the
30
+ * waiter object exists. That is still after `domain.apply`, which is all
31
+ * `ready` needs: it checks one macrotask after the ID resolves, so an alias
32
+ * created in that same turn still counts. If SST ever resolved the ID first,
33
+ * or stopped creating either alias through this adapter, `ready` rejects with
34
+ * a named error instead of leaving the identity domain waiting forever.
35
+ *
36
+ * Records that exist are not yet records that answer: Route 53 reports the
37
+ * aliases in sync while their distribution is still deploying, and answers
38
+ * them with no address until it is. The identity domain therefore also waits,
39
+ * in its `beforeCreate` hook, until `<root>` answers an A query
40
+ * ({@link identityDomainParentReady}).
41
+ */
42
+ function observeRootAliasRecords(dns, rootDomain) {
43
+ const names = { root: rootDomain, wildcard: '*.' + rootDomain };
44
+ const created = new Map();
45
+ let settle = () => undefined;
46
+ const records = new Promise((resolve) => {
47
+ settle = resolve;
48
+ });
49
+ const observed = {
50
+ ...dns,
51
+ createAlias(namePrefix, record, opts) {
52
+ const result = dns.createAlias(namePrefix, record, opts);
53
+ const name = record.name;
54
+ if ((name === names.root || name === names.wildcard) &&
55
+ !created.has(name)) {
56
+ created.set(name, [result].flat());
57
+ const root = created.get(names.root);
58
+ const wildcard = created.get(names.wildcard);
59
+ if (root && wildcard)
60
+ settle([...root, ...wildcard]);
61
+ }
62
+ return result;
63
+ },
64
+ };
65
+ return {
66
+ dns: observed,
67
+ ready(distributionId) {
68
+ const missing = new Promise((_resolve, reject) => {
69
+ distributionId.apply(() => {
70
+ setImmediate(() => {
71
+ const absent = ['root', 'wildcard'].filter((kind) => !created.has(names[kind]));
72
+ if (absent.length === 0)
73
+ return;
74
+ reject(new Error(`Foundation Router did not create its ${absent.join(' and ')} alias record${absent.length > 1 ? 's' : ''} through the bound DNS adapter before its distribution ID resolved; the identity domain on auth.<root> waits on the root and wildcard alias records. Reconcile the pinned SST version.`));
75
+ });
76
+ return undefined;
77
+ });
78
+ });
79
+ return Promise.race([records, missing]);
80
+ },
81
+ };
82
+ }
83
+ /**
84
+ * The Pulumi `beforeCreate` hook for the bound Foundation's identity domain.
85
+ *
86
+ * Cognito refuses `auth.<root>` unless `<root>` answers an A query when it
87
+ * creates the domain, and the Router's alias records being in sync is not
88
+ * enough: Route 53 answers an alias to a distribution that is still deploying
89
+ * with no address. The hook polls every one of the zone's own name servers,
90
+ * concurrently and each through its own bounded resolver, until one answers
91
+ * with addresses and none answers that there are none, and confirms that once
92
+ * more one interval later. Authoritative servers hold no negative cache, and
93
+ * the poll seeds none. When `<root>` is below its zone's apex, the zone's
94
+ * name servers are those of the nearest name above it that has them.
95
+ *
96
+ * If no server can be queried at all for the transport grace, and none ever
97
+ * answered, the hook carries on through the system resolver, asking for a
98
+ * fresh name under the zone each poll: the wildcard alias has the same target
99
+ * as the apex, and a name never asked before can sit in no cache. At the
100
+ * bound the hook warns and returns, so that Cognito's own check decides; it
101
+ * never fails a deploy that is still progressing. The bound holds for every
102
+ * part of the wait: a poll still in flight then, the confirming poll
103
+ * included, is cut short, its lookups are cancelled and it starts no other,
104
+ * and no pause runs past it. Its only error is the guard against a domain
105
+ * other than `auth.<root>`.
106
+ *
107
+ * Every line it logs is value-free: it names `<root>` and `auth.<root>`
108
+ * literally, and reports only classes, counts, codes and seconds. Building
109
+ * the hook does no work; the returned function polls only when Pulumi runs it
110
+ * before the domain's create, never during a preview.
111
+ */
112
+ function identityDomainParentReady(rootDomain) {
113
+ return (0, identity_domain_parent_ready_js_1.createParentReadyHook)(rootDomain);
114
+ }
115
+ //# sourceMappingURL=identity-domain.js.map
@@ -1,4 +1,5 @@
1
1
  export * from './discovery.js';
2
+ export { identityDomainParentReady, observeRootAliasRecords, type IdentityDomainParentReadyHookArgs, type RootAliasRecordsObserver, type RouterDistributionId, type RouterDnsAdapter, } from './identity-domain.js';
2
3
  export * from './capability-plan.js';
3
4
  export * from './local-database-contract.js';
4
5
  export * from './logging.js';
@@ -9,6 +10,7 @@ export * from './provision-database-bindings.js';
9
10
  export * from './provision-logical-database.js';
10
11
  export * from './requirements.js';
11
12
  export * from './router-origin-proof.js';
13
+ export * from './root-site.js';
12
14
  export * from './router-waf.js';
13
15
  export declare function cleanupGithubPrivateSmoke(...args: Parameters<typeof import('./private-smoke-access.js').cleanupGithubPrivateSmoke>): Promise<void>;
14
16
  export * from './stages.js';
@@ -1,8 +1,14 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.observeRootAliasRecords = exports.identityDomainParentReady = void 0;
3
4
  exports.cleanupGithubPrivateSmoke = cleanupGithubPrivateSmoke;
4
5
  const tslib_1 = require("tslib");
5
6
  tslib_1.__exportStar(require("./discovery.js"), exports);
7
+ // The identity domain's resolver seams, timings and options are internal:
8
+ // only its specs import them, from the module itself.
9
+ var identity_domain_js_1 = require("./identity-domain.js");
10
+ Object.defineProperty(exports, "identityDomainParentReady", { enumerable: true, get: function () { return identity_domain_js_1.identityDomainParentReady; } });
11
+ Object.defineProperty(exports, "observeRootAliasRecords", { enumerable: true, get: function () { return identity_domain_js_1.observeRootAliasRecords; } });
6
12
  tslib_1.__exportStar(require("./capability-plan.js"), exports);
7
13
  tslib_1.__exportStar(require("./local-database-contract.js"), exports);
8
14
  tslib_1.__exportStar(require("./logging.js"), exports);
@@ -13,6 +19,7 @@ tslib_1.__exportStar(require("./provision-database-bindings.js"), exports);
13
19
  tslib_1.__exportStar(require("./provision-logical-database.js"), exports);
14
20
  tslib_1.__exportStar(require("./requirements.js"), exports);
15
21
  tslib_1.__exportStar(require("./router-origin-proof.js"), exports);
22
+ tslib_1.__exportStar(require("./root-site.js"), exports);
16
23
  tslib_1.__exportStar(require("./router-waf.js"), exports);
17
24
  // SST bundles this infrastructure entry point. Keep the workflow-only AWS
18
25
  // control plane lazy: its external SDK resolves from the installed package
@@ -8,6 +8,7 @@ const credential_providers_1 = require("@aws-sdk/credential-providers");
8
8
  const discovery_js_1 = require("./discovery.js");
9
9
  const requirements_js_1 = require("./requirements.js");
10
10
  const stages_js_1 = require("./stages.js");
11
+ const public_dns_js_1 = require("../repository-policy/public-dns.js");
11
12
  function chunks(values, size) {
12
13
  const result = [];
13
14
  for (let index = 0; index < values.length; index += size) {
@@ -40,6 +41,16 @@ function isExactCognitoTokenEndpoint(value, region) {
40
41
  return false;
41
42
  }
42
43
  }
44
+ /**
45
+ * A Foundation with a bound domain serves its identity domain on
46
+ * `auth.<rootDomain>` (area 2), so its token endpoint must be exactly that
47
+ * host's, and the Cognito prefix form is refused there. A Foundation without a
48
+ * bound domain keeps the exact prefix-domain predicate.
49
+ */
50
+ function isExactBoundIdentityTokenEndpoint(value, rootDomain) {
51
+ return (public_dns_js_1.PUBLIC_DNS_ROOT_DOMAIN_PATTERN.test(rootDomain) &&
52
+ value === `https://auth.${rootDomain}/oauth2/token`);
53
+ }
43
54
  function createFoundationParameterReader(options) {
44
55
  const profile = options.profile?.trim();
45
56
  const credentials = options.credentials ?? (profile ? (0, credential_providers_1.fromIni)({ profile }) : undefined);
@@ -115,7 +126,12 @@ async function evaluateFoundationPreflight(options) {
115
126
  if (!/^sha256:[a-f0-9]{64}$/.test(value('accountCostPolicyDigest'))) {
116
127
  issues.push('Foundation discovery accountCostPolicyDigest must be an exact SHA-256 digest');
117
128
  }
118
- if (!isExactCognitoTokenEndpoint(value('identityTokenEndpoint'), options.region)) {
129
+ if (value('hasPublicDomain') === 'true') {
130
+ if (!isExactBoundIdentityTokenEndpoint(value('identityTokenEndpoint'), value('rootDomain'))) {
131
+ issues.push('Foundation discovery identityTokenEndpoint must be the bound identity domain HTTPS token endpoint on auth.<rootDomain>; apply the Foundation upgrade and redeploy Foundation');
132
+ }
133
+ }
134
+ else if (!isExactCognitoTokenEndpoint(value('identityTokenEndpoint'), options.region)) {
119
135
  issues.push('Foundation discovery identityTokenEndpoint must be the exact Cognito HTTPS token endpoint for the selected AWS Region');
120
136
  }
121
137
  const compatibility = (0, requirements_js_1.validateFoundationCompatibility)(options.requirement, {
@@ -0,0 +1,27 @@
1
+ /** The Slice's managed deployed readiness helper, relative to its root. */
2
+ export declare const SLICE_READINESS_HELPER_PATH: "scripts/deployed-smoke-readiness.mjs";
3
+ export declare const ROOT_SITE_SLICE_READINESS_UPGRADE_MESSAGE = "This workspace has a root site; apply the Slice upgrade so deployed readiness recognises root-site fallthrough.";
4
+ /** Reads one workspace-relative file; undefined when it does not exist. */
5
+ export type WorkspaceFileReader = (path: string) => string | undefined;
6
+ /**
7
+ * Whether the workspace has a root site: a site-kind ownership record at
8
+ * packages/site, or any project tagged type:site. Either signal is enough.
9
+ * A record there that is not valid JSON counts as a site, so the guards that
10
+ * ask fail closed.
11
+ */
12
+ export declare function workspaceHasRootSite(readFile: WorkspaceFileReader, projectTags?: readonly (readonly string[] | undefined)[]): boolean;
13
+ /**
14
+ * Whether a Slice's managed readiness would fail a route that falls through to
15
+ * the root site. It applies only to a built-in Slice whose ownership lists the
16
+ * helper as managed; an External Blueprint Slice has no framework helper. The
17
+ * check reads the content, not a digest, because generation formats the
18
+ * helper: any helper without the literal contract token predates the root
19
+ * site. An unreadable or invalid record fails closed.
20
+ */
21
+ export declare function sliceReadinessPredatesRootSite(readFile: WorkspaceFileReader, sliceRoot: string): boolean;
22
+ /** The Slices, by name, whose readiness must be upgraded beside a root site. */
23
+ export declare function slicesNeedingRootSiteReadinessUpgrade(readFile: WorkspaceFileReader, slices: readonly {
24
+ name: string;
25
+ root: string;
26
+ }[]): string[];
27
+ export declare function formatRootSiteReadinessUpgrade(names: readonly string[]): string;