@bleedingdev/modern-js-server-runtime-extensions 3.8.3-ultramodern.1 → 3.8.3-ultramodern.2

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 (82) hide show
  1. package/dist/cjs/backend-federation-security/index.js +415 -0
  2. package/dist/cjs/backend-federation-security/node.js +74 -0
  3. package/dist/cjs/contract-gate-snapshot-store/http-store.js +1 -1
  4. package/dist/cjs/contract-gate-snapshot-store/resolve.js +4 -4
  5. package/dist/cjs/{contractGateAutopilot.js → contractGateSnapshotObserver.js} +14 -17
  6. package/dist/cjs/index.js +45 -13
  7. package/dist/cjs/runtime-fallback-signal/resolver.js +3 -3
  8. package/dist/cjs/runtimeLifecycle.js +129 -0
  9. package/dist/cjs/telemetry/{canaryEvaluation.js → healthEvaluation.js} +11 -13
  10. package/dist/cjs/telemetry/{canary.js → healthMonitor.js} +27 -44
  11. package/dist/cjs/telemetry/{canarySetup.js → healthSetup.js} +35 -39
  12. package/dist/cjs/telemetry/lifecycle.js +14 -14
  13. package/dist/cjs/telemetry/plugin.js +9 -9
  14. package/dist/cjs/telemetry/runtimeEndpoints.js +3 -3
  15. package/dist/cjs/telemetryCore.js +4 -4
  16. package/dist/esm/backend-federation-security/index.mjs +361 -0
  17. package/dist/esm/backend-federation-security/node.mjs +30 -0
  18. package/dist/esm/contract-gate-snapshot-store/http-store.mjs +1 -1
  19. package/dist/esm/contract-gate-snapshot-store/resolve.mjs +4 -4
  20. package/dist/esm/{contractGateAutopilot.mjs → contractGateSnapshotObserver.mjs} +12 -15
  21. package/dist/esm/index.mjs +4 -2
  22. package/dist/esm/runtime-fallback-signal/resolver.mjs +3 -3
  23. package/dist/esm/runtimeLifecycle.mjs +82 -0
  24. package/dist/esm/telemetry/{canaryEvaluation.mjs → healthEvaluation.mjs} +9 -11
  25. package/dist/esm/telemetry/{canary.mjs → healthMonitor.mjs} +25 -42
  26. package/dist/esm/telemetry/healthSetup.mjs +65 -0
  27. package/dist/esm/telemetry/lifecycle.mjs +14 -14
  28. package/dist/esm/telemetry/plugin.mjs +8 -8
  29. package/dist/esm/telemetry/runtimeEndpoints.mjs +3 -3
  30. package/dist/esm/telemetryCore.mjs +1 -1
  31. package/dist/esm-node/backend-federation-security/index.mjs +362 -0
  32. package/dist/esm-node/backend-federation-security/node.mjs +31 -0
  33. package/dist/esm-node/contract-gate-snapshot-store/http-store.mjs +1 -1
  34. package/dist/esm-node/contract-gate-snapshot-store/resolve.mjs +4 -4
  35. package/dist/esm-node/{contractGateAutopilot.mjs → contractGateSnapshotObserver.mjs} +12 -15
  36. package/dist/esm-node/index.mjs +4 -2
  37. package/dist/esm-node/runtime-fallback-signal/resolver.mjs +3 -3
  38. package/dist/esm-node/runtimeLifecycle.mjs +83 -0
  39. package/dist/esm-node/telemetry/{canaryEvaluation.mjs → healthEvaluation.mjs} +9 -11
  40. package/dist/esm-node/telemetry/{canary.mjs → healthMonitor.mjs} +25 -42
  41. package/dist/esm-node/telemetry/healthSetup.mjs +66 -0
  42. package/dist/esm-node/telemetry/lifecycle.mjs +14 -14
  43. package/dist/esm-node/telemetry/plugin.mjs +8 -8
  44. package/dist/esm-node/telemetry/runtimeEndpoints.mjs +3 -3
  45. package/dist/esm-node/telemetryCore.mjs +1 -1
  46. package/dist/types/backend-federation-security/index.d.ts +68 -0
  47. package/dist/types/backend-federation-security/node.d.ts +3 -0
  48. package/dist/types/{contractGateAutopilot.d.ts → contractGateSnapshotObserver.d.ts} +7 -6
  49. package/dist/types/index.d.ts +4 -2
  50. package/dist/types/runtime-fallback-signal/resolver.d.ts +2 -2
  51. package/dist/types/runtimeLifecycle.d.ts +10 -0
  52. package/dist/types/telemetry/healthEvaluation.d.ts +20 -0
  53. package/dist/types/telemetry/{canary.d.ts → healthMonitor.d.ts} +31 -28
  54. package/dist/types/telemetry/{canarySetup.d.ts → healthSetup.d.ts} +6 -6
  55. package/dist/types/telemetry/lifecycle.d.ts +4 -4
  56. package/dist/types/telemetry/plugin.d.ts +1 -1
  57. package/dist/types/telemetry/runtimeEndpoints.d.ts +3 -3
  58. package/dist/types/telemetryCore.d.ts +1 -1
  59. package/package.json +46 -8
  60. package/src/backend-federation-security/index.ts +831 -0
  61. package/src/backend-federation-security/node.ts +51 -0
  62. package/src/contract-gate-snapshot-store/http-store.ts +1 -1
  63. package/src/contract-gate-snapshot-store/resolve.ts +4 -4
  64. package/src/{contractGateAutopilot.ts → contractGateSnapshotObserver.ts} +18 -25
  65. package/src/index.ts +42 -6
  66. package/src/runtime-fallback-signal/resolver.ts +5 -5
  67. package/src/runtimeLifecycle.ts +125 -0
  68. package/src/telemetry/{canaryEvaluation.ts → healthEvaluation.ts} +14 -17
  69. package/src/telemetry/{canary.ts → healthMonitor.ts} +72 -84
  70. package/src/telemetry/{canarySetup.ts → healthSetup.ts} +50 -53
  71. package/src/telemetry/lifecycle.ts +20 -20
  72. package/src/telemetry/plugin.ts +16 -16
  73. package/src/telemetry/runtimeEndpoints.ts +6 -6
  74. package/src/telemetryCore.ts +11 -11
  75. package/tests/backendFederationSecurity.test.ts +416 -0
  76. package/tests/{contractGateAutopilot.test.ts → contractGateSnapshotObserver.test.ts} +59 -62
  77. package/tests/runtimeLifecycle.test.ts +107 -0
  78. package/tests/telemetryHealthMonitor.test.ts +187 -0
  79. package/dist/esm/telemetry/canarySetup.mjs +0 -69
  80. package/dist/esm-node/telemetry/canarySetup.mjs +0 -70
  81. package/dist/types/telemetry/canaryEvaluation.d.ts +0 -20
  82. package/tests/telemetryCanaryOrchestrator.test.ts +0 -365
@@ -0,0 +1,415 @@
1
+ "use strict";
2
+ var __webpack_require__ = {};
3
+ (()=>{
4
+ __webpack_require__.d = (exports1, getters, values)=>{
5
+ var define = (defs, kind)=>{
6
+ for(var key in defs)if (__webpack_require__.o(defs, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
7
+ enumerable: true,
8
+ [kind]: defs[key]
9
+ });
10
+ };
11
+ define(getters, "get");
12
+ define(values, "value");
13
+ };
14
+ })();
15
+ (()=>{
16
+ __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
17
+ })();
18
+ (()=>{
19
+ __webpack_require__.r = (exports1)=>{
20
+ if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
21
+ value: 'Module'
22
+ });
23
+ Object.defineProperty(exports1, '__esModule', {
24
+ value: true
25
+ });
26
+ };
27
+ })();
28
+ var __webpack_exports__ = {};
29
+ __webpack_require__.r(__webpack_exports__);
30
+ const DEFAULT_MAX_ENTRY_BYTES = 16777216;
31
+ const DEFAULT_MAX_RESOURCE_BYTES = 1048576;
32
+ const DEFAULT_ENTRY_TIMEOUT_MS = 10000;
33
+ class BackendFederationRemoteEntryError extends Error {
34
+ constructor(code, message, options = {}){
35
+ super(message, void 0 === options.cause ? void 0 : options);
36
+ this.name = 'BackendFederationRemoteEntryError';
37
+ this.code = code;
38
+ this.details = options.details;
39
+ }
40
+ }
41
+ const isRecord = (value)=>'object' == typeof value && null !== value;
42
+ const recordField = (value, key)=>{
43
+ if (!isRecord(value)) return;
44
+ const field = value[key];
45
+ return isRecord(field) ? field : void 0;
46
+ };
47
+ const stringField = (value)=>'string' == typeof value && value.length > 0 ? value : void 0;
48
+ function resolveBackendFederationRemoteEntryVerification(manifest) {
49
+ if (!isRecord(manifest)) return;
50
+ const entry = recordField(manifest, 'entry');
51
+ const sha256 = entry?.sha256;
52
+ const byteLength = entry?.byteLength;
53
+ if (void 0 === sha256 && void 0 === byteLength) return;
54
+ const backendFederation = recordField(manifest, 'backendFederation');
55
+ const boundary = recordField(backendFederation, 'versionBoundary');
56
+ const boundaryDeliveryUnit = recordField(boundary, 'deliveryUnit');
57
+ const deliveryUnit = recordField(backendFederation, 'deliveryUnit');
58
+ const remoteName = stringField(backendFederation?.name) ?? stringField(manifest.name) ?? stringField(manifest.id);
59
+ const entryUrl = stringField(entry?.url);
60
+ const containerEntry = stringField(backendFederation?.containerEntry);
61
+ if ('string' != typeof sha256 || 'number' != typeof byteLength || void 0 === remoteName || void 0 === entryUrl) throw new BackendFederationRemoteEntryError('invalid_verification', '[Module Federation] Backend manifest entry verification requires remote name, entry.url, sha256, and byteLength.');
62
+ if (void 0 !== containerEntry && canonicalEntryUrl(containerEntry).href !== canonicalEntryUrl(entryUrl).href) throw new BackendFederationRemoteEntryError('identity_mismatch', '[Module Federation] Backend manifest containerEntry must match entry.url before remote execution.', {
63
+ details: {
64
+ containerEntry: redactBackendFederationUrl(containerEntry),
65
+ entryUrl: redactBackendFederationUrl(entryUrl)
66
+ }
67
+ });
68
+ const buildMarker = stringField(boundaryDeliveryUnit?.buildMarker) ?? stringField(deliveryUnit?.buildMarker);
69
+ const unitId = stringField(boundaryDeliveryUnit?.unitId) ?? stringField(deliveryUnit?.unitId);
70
+ return {
71
+ byteLength,
72
+ entryUrl,
73
+ remoteName,
74
+ sha256,
75
+ ...buildMarker ? {
76
+ buildMarker
77
+ } : {},
78
+ ...unitId ? {
79
+ unitId
80
+ } : {}
81
+ };
82
+ }
83
+ const canonicalEntryUrl = (value)=>{
84
+ let url;
85
+ try {
86
+ url = new URL(value);
87
+ } catch (cause) {
88
+ throw new BackendFederationRemoteEntryError('invalid_verification', '[Module Federation] Invalid backend federation URL.', {
89
+ cause
90
+ });
91
+ }
92
+ if (url.username || url.password) throw new BackendFederationRemoteEntryError('invalid_verification', '[Module Federation] Backend remote entry URLs must not contain credentials.');
93
+ url.hash = '';
94
+ return url;
95
+ };
96
+ function redactBackendFederationUrl(value) {
97
+ try {
98
+ const url = new URL(value);
99
+ url.username = '';
100
+ url.password = '';
101
+ url.search = '';
102
+ url.hash = '';
103
+ return url.href;
104
+ } catch {
105
+ return '[local or invalid reference]';
106
+ }
107
+ }
108
+ const isLoopback = (hostname)=>'localhost' === hostname || '127.0.0.1' === hostname || '[::1]' === hostname;
109
+ const assertAllowedEntryUrl = (url, allowInsecureHttp)=>{
110
+ if ('https:' === url.protocol) return;
111
+ if ('http:' === url.protocol && (allowInsecureHttp || isLoopback(url.hostname))) return;
112
+ throw new BackendFederationRemoteEntryError('unsupported_entry', `[Module Federation] Backend federation resource ${redactBackendFederationUrl(url.href)} must use HTTPS (loopback HTTP is allowed for local development).`);
113
+ };
114
+ const assertVerification = (remote, verification, expected, allowInsecureHttp)=>{
115
+ if (void 0 !== remote.type && 'commonjs-module' !== remote.type) throw new BackendFederationRemoteEntryError('unsupported_entry', `[Module Federation] Verified backend remote ${remote.name} must be a self-contained CommonJS container.`);
116
+ if (!/^[a-f0-9]{64}$/u.test(verification.sha256)) throw new BackendFederationRemoteEntryError('invalid_verification', '[Module Federation] Backend remote entry SHA-256 must be 64 lowercase hexadecimal characters.');
117
+ if (!Number.isSafeInteger(verification.byteLength) || verification.byteLength < 0) throw new BackendFederationRemoteEntryError('invalid_verification', '[Module Federation] Backend remote entry byteLength must be a non-negative safe integer.');
118
+ const requestedUrl = canonicalEntryUrl(remote.entry);
119
+ const verifiedUrl = canonicalEntryUrl(verification.entryUrl);
120
+ assertAllowedEntryUrl(requestedUrl, allowInsecureHttp);
121
+ if (remote.name !== verification.remoteName || requestedUrl.href !== verifiedUrl.href) throw new BackendFederationRemoteEntryError('identity_mismatch', '[Module Federation] Backend remote name or entry URL does not match its verified identity.', {
122
+ details: {
123
+ requestedEntry: redactBackendFederationUrl(requestedUrl.href),
124
+ requestedName: remote.name,
125
+ verifiedEntry: redactBackendFederationUrl(verifiedUrl.href),
126
+ verifiedName: verification.remoteName
127
+ }
128
+ });
129
+ for (const key of [
130
+ 'buildMarker',
131
+ 'byteLength',
132
+ 'entryUrl',
133
+ 'remoteName',
134
+ 'sha256',
135
+ 'unitId'
136
+ ]){
137
+ const expectedValue = expected[key];
138
+ if (void 0 !== expectedValue && expectedValue !== verification[key]) throw new BackendFederationRemoteEntryError('identity_mismatch', `[Module Federation] Backend remote entry ${key} does not match the trusted expectation.`, {
139
+ details: {
140
+ expected: 'entryUrl' === key && 'string' == typeof expectedValue ? redactBackendFederationUrl(expectedValue) : expectedValue,
141
+ field: key,
142
+ received: 'entryUrl' === key ? redactBackendFederationUrl(verification.entryUrl) : verification[key]
143
+ }
144
+ });
145
+ }
146
+ return requestedUrl;
147
+ };
148
+ const resolveTrustedVerification = (verification, expected)=>{
149
+ if (verification) return verification;
150
+ if ('number' == typeof expected.byteLength && 'string' == typeof expected.entryUrl && 'string' == typeof expected.remoteName && 'string' == typeof expected.sha256) return expected;
151
+ throw new BackendFederationRemoteEntryError('invalid_verification', '[Module Federation] Verified backend network loading requires trusted entryUrl, remoteName, sha256, and byteLength values.');
152
+ };
153
+ const readWithAbort = (promise, signal)=>new Promise((resolve, reject)=>{
154
+ if (signal.aborted) return void reject(signal.reason);
155
+ const onAbort = ()=>reject(signal.reason);
156
+ signal.addEventListener('abort', onAbort, {
157
+ once: true
158
+ });
159
+ promise.then(resolve, reject).finally(()=>{
160
+ signal.removeEventListener('abort', onAbort);
161
+ });
162
+ });
163
+ const parseContentLength = (value)=>{
164
+ if (null === value || !/^\d+$/u.test(value)) return;
165
+ const parsed = Number(value);
166
+ return Number.isSafeInteger(parsed) ? parsed : void 0;
167
+ };
168
+ const sha256Hex = async (bytes, signal)=>{
169
+ const subtle = globalThis.crypto?.subtle;
170
+ if (void 0 === subtle) throw new BackendFederationRemoteEntryError('unsupported_entry', '[Module Federation] Verified backend remote loading requires Web Crypto SHA-256 support.');
171
+ const digest = new Uint8Array(await readWithAbort(subtle.digest('SHA-256', bytes), signal));
172
+ return Array.from(digest, (byte)=>byte.toString(16).padStart(2, '0')).join('');
173
+ };
174
+ async function loadBoundedBackendFederationResource(resourceUrl, options = {}) {
175
+ const requestedUrl = canonicalEntryUrl(resourceUrl);
176
+ assertAllowedEntryUrl(requestedUrl, true === options.allowInsecureHttp);
177
+ const maxBytes = options.maxBytes ?? DEFAULT_MAX_RESOURCE_BYTES;
178
+ if (!Number.isSafeInteger(maxBytes) || maxBytes <= 0) throw new BackendFederationRemoteEntryError('invalid_verification', '[Module Federation] Backend federation resource maxBytes must be a positive safe integer.');
179
+ const timeoutMs = options.timeoutMs ?? DEFAULT_ENTRY_TIMEOUT_MS;
180
+ if (!Number.isSafeInteger(timeoutMs) || timeoutMs < 0) throw new BackendFederationRemoteEntryError('invalid_verification', '[Module Federation] Backend federation resource timeoutMs must be a non-negative safe integer.');
181
+ const controller = new AbortController();
182
+ let timedOut = false;
183
+ let callerAborted = false;
184
+ const onCallerAbort = ()=>{
185
+ callerAborted = true;
186
+ controller.abort(options.signal?.reason);
187
+ };
188
+ if (options.signal?.aborted) onCallerAbort();
189
+ else options.signal?.addEventListener('abort', onCallerAbort, {
190
+ once: true
191
+ });
192
+ const timeout = timeoutMs > 0 ? setTimeout(()=>{
193
+ timedOut = true;
194
+ controller.abort(new Error(`Backend federation ${options.kind ?? 'manifest'} timed out after ${timeoutMs}ms`));
195
+ }, timeoutMs) : void 0;
196
+ const fetchResource = options.fetch ?? globalThis.fetch;
197
+ let reader;
198
+ const resourceKind = options.kind ?? 'manifest';
199
+ const cancellationError = (cause)=>new BackendFederationRemoteEntryError(timedOut ? 'timeout' : 'aborted', timedOut ? `[Module Federation] Backend federation ${resourceKind} timed out after ${timeoutMs}ms.` : `[Module Federation] Backend federation ${resourceKind} loading was aborted.`, {
200
+ cause
201
+ });
202
+ try {
203
+ if (controller.signal.aborted) throw cancellationError(controller.signal.reason);
204
+ if ('function' != typeof fetchResource) throw new BackendFederationRemoteEntryError('fetch_failed', `[Module Federation] Backend federation ${resourceKind} loading requires fetch.`);
205
+ let response;
206
+ try {
207
+ response = await readWithAbort(fetchResource(requestedUrl.href, {
208
+ cache: 'no-store',
209
+ redirect: 'error',
210
+ signal: controller.signal
211
+ }), controller.signal);
212
+ } catch (cause) {
213
+ if (controller.signal.aborted) throw cancellationError(cause);
214
+ throw new BackendFederationRemoteEntryError('fetch_failed', `[Module Federation] Failed to fetch backend federation ${resourceKind}.`, {
215
+ cause
216
+ });
217
+ }
218
+ if (!response.ok) throw new BackendFederationRemoteEntryError('fetch_failed', `[Module Federation] Backend federation ${resourceKind} returned HTTP ${response.status}.`);
219
+ if (response.url) {
220
+ const responseUrl = canonicalEntryUrl(response.url);
221
+ if (responseUrl.href !== requestedUrl.href) throw new BackendFederationRemoteEntryError('redirect_mismatch', `[Module Federation] Backend federation ${resourceKind} redirected outside its trusted URL.`, {
222
+ details: {
223
+ expected: redactBackendFederationUrl(requestedUrl.href),
224
+ received: redactBackendFederationUrl(responseUrl.href)
225
+ }
226
+ });
227
+ }
228
+ const contentLength = parseContentLength(response.headers?.get('content-length') ?? null);
229
+ if (void 0 !== contentLength && contentLength > maxBytes) {
230
+ controller.abort();
231
+ await response.body?.cancel().catch(()=>void 0);
232
+ throw new BackendFederationRemoteEntryError('entry_too_large', `[Module Federation] Backend federation ${resourceKind} declares ${contentLength} bytes, exceeding its ${maxBytes}-byte policy limit.`);
233
+ }
234
+ const chunks = [];
235
+ let byteLength = 0;
236
+ if (response.body) {
237
+ reader = response.body.getReader();
238
+ while(true){
239
+ const result = await readWithAbort(reader.read(), controller.signal);
240
+ if (result.done) break;
241
+ byteLength += result.value.byteLength;
242
+ if (byteLength > maxBytes) throw new BackendFederationRemoteEntryError('entry_too_large', `[Module Federation] Backend federation ${resourceKind} exceeded its ${maxBytes}-byte limit while streaming.`);
243
+ chunks.push(result.value);
244
+ }
245
+ } else if (response.text) {
246
+ const bytes = new TextEncoder().encode(await readWithAbort(response.text(), controller.signal));
247
+ if (bytes.byteLength > maxBytes) throw new BackendFederationRemoteEntryError('entry_too_large', `[Module Federation] Backend federation ${resourceKind} exceeded its ${maxBytes}-byte limit.`);
248
+ chunks.push(bytes);
249
+ byteLength = bytes.byteLength;
250
+ }
251
+ const bytes = new Uint8Array(byteLength);
252
+ let offset = 0;
253
+ for (const chunk of chunks){
254
+ bytes.set(chunk, offset);
255
+ offset += chunk.byteLength;
256
+ }
257
+ if (controller.signal.aborted) throw cancellationError(controller.signal.reason);
258
+ return bytes;
259
+ } catch (cause) {
260
+ if (!controller.signal.aborted) controller.abort(cause);
261
+ await reader?.cancel(cause).catch(()=>void 0);
262
+ if (cause instanceof BackendFederationRemoteEntryError) throw cause;
263
+ if (timedOut || callerAborted) throw cancellationError(cause);
264
+ throw new BackendFederationRemoteEntryError('fetch_failed', `[Module Federation] Backend federation ${resourceKind} loading failed.`, {
265
+ cause
266
+ });
267
+ } finally{
268
+ if (timeout) clearTimeout(timeout);
269
+ options.signal?.removeEventListener('abort', onCallerAbort);
270
+ }
271
+ }
272
+ const evaluateBackendFederationCommonJsEntry = (remote, bytes, evaluator)=>{
273
+ let source;
274
+ try {
275
+ source = new TextDecoder('utf-8', {
276
+ fatal: true
277
+ }).decode(bytes);
278
+ } catch (cause) {
279
+ throw new BackendFederationRemoteEntryError('integrity_mismatch', `[Module Federation] Backend remote ${remote.name} is not valid UTF-8 JavaScript.`, {
280
+ cause
281
+ });
282
+ }
283
+ if (void 0 === evaluator) throw new BackendFederationRemoteEntryError('unsupported_entry', `[Module Federation] Backend remote ${remote.name} requires an explicit runtime evaluator. Node callers should use the Node security subpath; edge callers should use a service binding or native module provider.`);
284
+ const evaluated = evaluator(source, {
285
+ remote
286
+ });
287
+ const defaultExport = 'object' == typeof evaluated && null !== evaluated && 'default' in evaluated ? evaluated.default : void 0;
288
+ const entry = defaultExport ?? evaluated;
289
+ if ('object' != typeof entry || null === entry || 'function' != typeof entry.get) throw new BackendFederationRemoteEntryError('fetch_failed', `[Module Federation] Backend remote ${remote.name} did not evaluate to a container entry.`);
290
+ return entry;
291
+ };
292
+ async function loadVerifiedBackendFederationEntry(options) {
293
+ const verification = resolveTrustedVerification(options.verification, options.expected ?? {});
294
+ const requestedUrl = assertVerification(options.remote, verification, options.expected ?? {}, true === options.allowInsecureHttp);
295
+ const maxBytes = options.maxBytes ?? DEFAULT_MAX_ENTRY_BYTES;
296
+ if (!Number.isSafeInteger(maxBytes) || maxBytes <= 0) throw new BackendFederationRemoteEntryError('invalid_verification', '[Module Federation] Backend remote entry maxBytes must be a positive safe integer.');
297
+ if (verification.byteLength > maxBytes) throw new BackendFederationRemoteEntryError('entry_too_large', `[Module Federation] Backend remote entry exceeds the ${maxBytes}-byte policy limit.`);
298
+ const timeoutMs = options.timeoutMs ?? DEFAULT_ENTRY_TIMEOUT_MS;
299
+ if (!Number.isSafeInteger(timeoutMs) || timeoutMs < 0) throw new BackendFederationRemoteEntryError('invalid_verification', '[Module Federation] Backend remote entry timeoutMs must be a non-negative safe integer.');
300
+ const controller = new AbortController();
301
+ let timedOut = false;
302
+ let callerAborted = false;
303
+ const onCallerAbort = ()=>{
304
+ callerAborted = true;
305
+ controller.abort(options.signal?.reason);
306
+ };
307
+ if (options.signal?.aborted) onCallerAbort();
308
+ else options.signal?.addEventListener('abort', onCallerAbort, {
309
+ once: true
310
+ });
311
+ const timeout = timeoutMs > 0 ? setTimeout(()=>{
312
+ timedOut = true;
313
+ controller.abort(new Error(`Backend remote entry timed out after ${timeoutMs}ms`));
314
+ }, timeoutMs) : void 0;
315
+ const fetchEntry = options.fetch ?? globalThis.fetch;
316
+ let reader;
317
+ const cancellationError = (cause)=>new BackendFederationRemoteEntryError(timedOut ? 'timeout' : 'aborted', timedOut ? `[Module Federation] Backend remote ${options.remote.name} timed out after ${timeoutMs}ms.` : `[Module Federation] Backend remote ${options.remote.name} loading was aborted.`, {
318
+ cause
319
+ });
320
+ try {
321
+ if (controller.signal.aborted) throw cancellationError(controller.signal.reason);
322
+ if ('function' != typeof fetchEntry) throw new BackendFederationRemoteEntryError('fetch_failed', '[Module Federation] Backend remote entry loading requires fetch.');
323
+ let response;
324
+ try {
325
+ response = await readWithAbort(fetchEntry(requestedUrl.href, {
326
+ cache: 'no-store',
327
+ redirect: 'error',
328
+ signal: controller.signal
329
+ }), controller.signal);
330
+ } catch (cause) {
331
+ if (controller.signal.aborted) throw cancellationError(cause);
332
+ throw new BackendFederationRemoteEntryError('fetch_failed', `[Module Federation] Failed to fetch backend remote ${options.remote.name}.`, {
333
+ cause
334
+ });
335
+ }
336
+ if (!response.ok) throw new BackendFederationRemoteEntryError('fetch_failed', `[Module Federation] Backend remote ${options.remote.name} returned HTTP ${response.status}.`);
337
+ if (response.url) {
338
+ const responseUrl = canonicalEntryUrl(response.url);
339
+ if (responseUrl.href !== requestedUrl.href) throw new BackendFederationRemoteEntryError('redirect_mismatch', `[Module Federation] Backend remote ${options.remote.name} redirected outside its verified entry URL.`, {
340
+ details: {
341
+ expected: redactBackendFederationUrl(requestedUrl.href),
342
+ received: redactBackendFederationUrl(responseUrl.href)
343
+ }
344
+ });
345
+ }
346
+ const contentLength = parseContentLength(response.headers?.get('content-length') ?? null);
347
+ const byteLimit = Math.min(maxBytes, verification.byteLength);
348
+ if (void 0 !== contentLength && contentLength > maxBytes) {
349
+ controller.abort();
350
+ await response.body?.cancel().catch(()=>void 0);
351
+ throw new BackendFederationRemoteEntryError('entry_too_large', `[Module Federation] Backend remote ${options.remote.name} declares ${contentLength} bytes, exceeding its ${maxBytes}-byte policy limit.`);
352
+ }
353
+ reader = response.body?.getReader();
354
+ const bytes = new Uint8Array(verification.byteLength);
355
+ let byteLength = 0;
356
+ if (reader) while(true){
357
+ const result = await readWithAbort(reader.read(), controller.signal);
358
+ if (result.done) break;
359
+ const nextByteLength = byteLength + result.value.byteLength;
360
+ if (nextByteLength > byteLimit) throw new BackendFederationRemoteEntryError('entry_too_large', `[Module Federation] Backend remote ${options.remote.name} exceeded its ${byteLimit}-byte limit while streaming.`);
361
+ bytes.set(result.value, byteLength);
362
+ byteLength = nextByteLength;
363
+ }
364
+ if (byteLength !== verification.byteLength) throw new BackendFederationRemoteEntryError('byte_length_mismatch', `[Module Federation] Backend remote ${options.remote.name} byte length mismatch.`, {
365
+ details: {
366
+ expected: verification.byteLength,
367
+ received: byteLength
368
+ }
369
+ });
370
+ const actualDigest = await sha256Hex(bytes, controller.signal);
371
+ if (controller.signal.aborted) throw cancellationError(controller.signal.reason);
372
+ if (actualDigest !== verification.sha256) throw new BackendFederationRemoteEntryError('integrity_mismatch', `[Module Federation] Backend remote ${options.remote.name} SHA-256 mismatch.`, {
373
+ details: {
374
+ expected: verification.sha256,
375
+ received: actualDigest
376
+ }
377
+ });
378
+ return evaluateBackendFederationCommonJsEntry(options.remote, bytes, options.evaluateCommonJs);
379
+ } catch (cause) {
380
+ if (!controller.signal.aborted) controller.abort(cause);
381
+ await reader?.cancel(cause).catch(()=>void 0);
382
+ if (cause instanceof BackendFederationRemoteEntryError && !('aborted' === cause.code && timedOut)) throw cause;
383
+ if (controller.signal.aborted && (timedOut || callerAborted)) throw cancellationError(cause);
384
+ throw cause;
385
+ } finally{
386
+ if (timeout) clearTimeout(timeout);
387
+ options.signal?.removeEventListener('abort', onCallerAbort);
388
+ }
389
+ }
390
+ __webpack_require__.d(__webpack_exports__, {
391
+ BackendFederationRemoteEntryError: ()=>BackendFederationRemoteEntryError,
392
+ loadBoundedBackendFederationResource: ()=>loadBoundedBackendFederationResource,
393
+ loadVerifiedBackendFederationEntry: ()=>loadVerifiedBackendFederationEntry,
394
+ redactBackendFederationUrl: ()=>redactBackendFederationUrl,
395
+ resolveBackendFederationRemoteEntryVerification: ()=>resolveBackendFederationRemoteEntryVerification
396
+ }, {
397
+ evaluateBackendFederationCommonJsEntry: evaluateBackendFederationCommonJsEntry
398
+ });
399
+ exports.BackendFederationRemoteEntryError = __webpack_exports__.BackendFederationRemoteEntryError;
400
+ exports.evaluateBackendFederationCommonJsEntry = __webpack_exports__.evaluateBackendFederationCommonJsEntry;
401
+ exports.loadBoundedBackendFederationResource = __webpack_exports__.loadBoundedBackendFederationResource;
402
+ exports.loadVerifiedBackendFederationEntry = __webpack_exports__.loadVerifiedBackendFederationEntry;
403
+ exports.redactBackendFederationUrl = __webpack_exports__.redactBackendFederationUrl;
404
+ exports.resolveBackendFederationRemoteEntryVerification = __webpack_exports__.resolveBackendFederationRemoteEntryVerification;
405
+ for(var __rspack_i in __webpack_exports__)if (-1 === [
406
+ "BackendFederationRemoteEntryError",
407
+ "evaluateBackendFederationCommonJsEntry",
408
+ "loadBoundedBackendFederationResource",
409
+ "loadVerifiedBackendFederationEntry",
410
+ "redactBackendFederationUrl",
411
+ "resolveBackendFederationRemoteEntryVerification"
412
+ ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
413
+ Object.defineProperty(exports, '__esModule', {
414
+ value: true
415
+ });
@@ -0,0 +1,74 @@
1
+ "use strict";
2
+ const __rslib_import_meta_url__ = /*#__PURE__*/ function() {
3
+ return "u" < typeof document ? new (require('url'.replace('', ''))).URL('file:' + __filename).href : document.currentScript && document.currentScript.src || new URL('main.js', document.baseURI).href;
4
+ }();
5
+ var __webpack_require__ = {};
6
+ (()=>{
7
+ __webpack_require__.d = (exports1, getters, values)=>{
8
+ var define = (defs, kind)=>{
9
+ for(var key in defs)if (__webpack_require__.o(defs, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
10
+ enumerable: true,
11
+ [kind]: defs[key]
12
+ });
13
+ };
14
+ define(getters, "get");
15
+ define(values, "value");
16
+ };
17
+ })();
18
+ (()=>{
19
+ __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
20
+ })();
21
+ (()=>{
22
+ __webpack_require__.r = (exports1)=>{
23
+ if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
24
+ value: 'Module'
25
+ });
26
+ Object.defineProperty(exports1, '__esModule', {
27
+ value: true
28
+ });
29
+ };
30
+ })();
31
+ var __webpack_exports__ = {};
32
+ __webpack_require__.r(__webpack_exports__);
33
+ __webpack_require__.d(__webpack_exports__, {
34
+ createBackendFederationEntryIntegrity: ()=>createBackendFederationEntryIntegrity,
35
+ evaluateNodeBackendFederationCommonJs: ()=>evaluateNodeBackendFederationCommonJs
36
+ });
37
+ const external_node_crypto_namespaceObject = require("node:crypto");
38
+ const external_node_module_namespaceObject = require("node:module");
39
+ const external_index_js_namespaceObject = require("./index.js");
40
+ const nodeRequire = (0, external_node_module_namespaceObject.createRequire)(__rslib_import_meta_url__);
41
+ const nodeBuiltins = new Set([
42
+ ...external_node_module_namespaceObject.builtinModules,
43
+ ...external_node_module_namespaceObject.builtinModules.map((name)=>`node:${name}`)
44
+ ]);
45
+ const toBytes = (value)=>'string' == typeof value ? new TextEncoder().encode(value) : value;
46
+ function createBackendFederationEntryIntegrity(value) {
47
+ const bytes = toBytes(value);
48
+ return {
49
+ byteLength: bytes.byteLength,
50
+ sha256: (0, external_node_crypto_namespaceObject.createHash)('sha256').update(bytes).digest('hex')
51
+ };
52
+ }
53
+ const evaluateNodeBackendFederationCommonJs = (source, { remote })=>{
54
+ const module = {
55
+ exports: {}
56
+ };
57
+ const exports1 = module.exports;
58
+ const requireBuiltin = (specifier)=>{
59
+ if (!nodeBuiltins.has(specifier)) throw new external_index_js_namespaceObject.BackendFederationRemoteEntryError('unsupported_entry', `[Module Federation] Backend remote ${remote.name} attempted to require non-builtin module ${specifier}. Bundle package dependencies into the remote entry.`);
60
+ return nodeRequire(specifier);
61
+ };
62
+ const evaluate = new Function('module', 'exports', 'globalThis', 'require', source);
63
+ evaluate(module, exports1, globalThis, requireBuiltin);
64
+ return module.exports;
65
+ };
66
+ exports.createBackendFederationEntryIntegrity = __webpack_exports__.createBackendFederationEntryIntegrity;
67
+ exports.evaluateNodeBackendFederationCommonJs = __webpack_exports__.evaluateNodeBackendFederationCommonJs;
68
+ for(var __rspack_i in __webpack_exports__)if (-1 === [
69
+ "createBackendFederationEntryIntegrity",
70
+ "evaluateNodeBackendFederationCommonJs"
71
+ ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
72
+ Object.defineProperty(exports, '__esModule', {
73
+ value: true
74
+ });
@@ -43,7 +43,7 @@ const BUILTIN_HTTP_STATE_STORE_MODULES = new Set([
43
43
  ]);
44
44
  const normalizeHttpStoreOptions = (options)=>{
45
45
  const endpoint = 'string' == typeof options?.endpoint ? options.endpoint.trim() : '';
46
- if (!endpoint) throw new Error('[telemetry.canary.autopilot] HTTP stateStore requires options.endpoint');
46
+ if (!endpoint) throw new Error('[telemetry.health.snapshot] HTTP stateStore requires options.endpoint');
47
47
  const readMethod = 'string' == typeof options?.readMethod && options.readMethod.trim() ? options.readMethod.trim().toUpperCase() : 'GET';
48
48
  const writeMethod = 'string' == typeof options?.writeMethod && options.writeMethod.trim() ? options.writeMethod.trim().toUpperCase() : 'PUT';
49
49
  const timeoutMsRaw = Number(options?.timeoutMs);
@@ -89,7 +89,7 @@ const resolveContractGateSnapshotStore = async (input)=>{
89
89
  stateStore
90
90
  });
91
91
  if (builtinStore) {
92
- logger?.info?.(`[telemetry.canary.autopilot] using built-in contract gate snapshot store "${builtinStore.name}"`);
92
+ logger?.info?.(`[telemetry.health.snapshot] using built-in contract gate snapshot store "${builtinStore.name}"`);
93
93
  return builtinStore;
94
94
  }
95
95
  const modulePath = resolveStoreModulePath(appDirectory, stateStore.module);
@@ -97,10 +97,10 @@ const resolveContractGateSnapshotStore = async (input)=>{
97
97
  try {
98
98
  mod = await import(toStoreModuleImportSpecifier(modulePath));
99
99
  } catch (error) {
100
- throw new Error(`[telemetry.canary.autopilot] Failed to load stateStore.module "${stateStore.module}" (${modulePath}): ${error instanceof Error ? error.message : String(error)}`);
100
+ throw new Error(`[telemetry.health.snapshot] Failed to load stateStore.module "${stateStore.module}" (${modulePath}): ${error instanceof Error ? error.message : String(error)}`);
101
101
  }
102
102
  const factory = pickStoreFactory(mod);
103
- if (!factory) throw new Error(`[telemetry.canary.autopilot] stateStore.module "${stateStore.module}" does not export createContractGateSnapshotStore()`);
103
+ if (!factory) throw new Error(`[telemetry.health.snapshot] stateStore.module "${stateStore.module}" does not export createContractGateSnapshotStore()`);
104
104
  const store = await factory({
105
105
  appDirectory,
106
106
  gateSnapshotPath,
@@ -108,7 +108,7 @@ const resolveContractGateSnapshotStore = async (input)=>{
108
108
  logger
109
109
  });
110
110
  ensureStoreShape(store, modulePath);
111
- logger?.info?.(`[telemetry.canary.autopilot] using contract gate snapshot store "${store.name || modulePath}"`);
111
+ logger?.info?.(`[telemetry.health.snapshot] using contract gate snapshot store "${store.name || modulePath}"`);
112
112
  return store;
113
113
  };
114
114
  exports.isRecord = __webpack_exports__.isRecord;
@@ -28,13 +28,13 @@ var __webpack_require__ = {};
28
28
  var __webpack_exports__ = {};
29
29
  __webpack_require__.r(__webpack_exports__);
30
30
  __webpack_require__.d(__webpack_exports__, {
31
- ContractGateAutopilot: ()=>ContractGateAutopilot
31
+ ContractGateSnapshotObserver: ()=>ContractGateSnapshotObserver
32
32
  });
33
33
  const external_contract_gate_snapshot_normalization_js_namespaceObject = require("./contract-gate-snapshot-normalization.js");
34
34
  const file_store_js_namespaceObject = require("./contract-gate-snapshot-store/file-store.js");
35
35
  const DEFAULT_POLL_INTERVAL_MS = 15000;
36
36
  const DEFAULT_GATE_STALE_AFTER_MS = 600000;
37
- class ContractGateAutopilot {
37
+ class ContractGateSnapshotObserver {
38
38
  async start() {
39
39
  await this.syncOnce();
40
40
  if (this.poller) return;
@@ -52,8 +52,7 @@ class ContractGateAutopilot {
52
52
  async syncOnce() {
53
53
  const syncGeneration = ++this.syncGeneration;
54
54
  const snapshot = await this.loadSnapshot();
55
- if (syncGeneration !== this.syncGeneration) return 0;
56
- if (!snapshot) return 0;
55
+ if (syncGeneration !== this.syncGeneration || !snapshot) return 0;
57
56
  const snapshotGateNames = (0, external_contract_gate_snapshot_normalization_js_namespaceObject.getSnapshotGateNames)(snapshot);
58
57
  const gates = (0, external_contract_gate_snapshot_normalization_js_namespaceObject.normalizeSnapshot)(snapshot, {
59
58
  now: Date.now(),
@@ -61,13 +60,13 @@ class ContractGateAutopilot {
61
60
  });
62
61
  let updatedCount = snapshotGateNames ? this.clearOmittedGates(snapshotGateNames) : 0;
63
62
  for (const gate of gates){
64
- this.orchestrator.addRequiredContractGate(gate.name);
63
+ this.monitor.addRequiredContractGate(gate.name);
65
64
  const fingerprint = `${gate.passed ? '1' : '0'}:${gate.reason || ''}`;
66
65
  if (this.appliedGateFingerprints.get(gate.name) !== fingerprint) {
67
- this.orchestrator.setContractGate(gate.name, gate.passed, gate.reason);
66
+ this.monitor.setContractGate(gate.name, gate.passed, gate.reason);
68
67
  this.appliedGateFingerprints.set(gate.name, fingerprint);
69
68
  updatedCount += 1;
70
- this.logger?.info?.(`[telemetry.canary.autopilot] gate=${gate.name} passed=${String(gate.passed)} reason=${gate.reason || 'none'}`);
69
+ this.logger?.info?.(`[telemetry.health.snapshot] gate=${gate.name} passed=${String(gate.passed)} reason=${gate.reason || 'none'}`);
71
70
  }
72
71
  }
73
72
  return updatedCount;
@@ -75,29 +74,27 @@ class ContractGateAutopilot {
75
74
  clearOmittedGates(snapshotGateNames) {
76
75
  let updatedCount = 0;
77
76
  for (const gateName of Array.from(this.appliedGateFingerprints.keys()))if (!snapshotGateNames.has(gateName)) {
78
- this.orchestrator.setContractGate(gateName, true);
77
+ this.monitor.setContractGate(gateName, true);
79
78
  this.appliedGateFingerprints.delete(gateName);
80
79
  updatedCount += 1;
81
- this.logger?.info?.(`[telemetry.canary.autopilot] gate=${gateName} passed=true reason=omitted`);
80
+ this.logger?.info?.(`[telemetry.health.snapshot] gate=${gateName} passed=true reason=omitted`);
82
81
  }
83
82
  return updatedCount;
84
83
  }
85
84
  async loadSnapshot() {
86
85
  try {
87
- const snapshot = await this.gateSnapshotStore.readSnapshot();
88
- if (!snapshot) return;
89
- return snapshot;
86
+ return await this.gateSnapshotStore.readSnapshot() || void 0;
90
87
  } catch (error) {
91
88
  const source = this.gateSnapshotPath || this.gateSnapshotStore.name || 'stateStore';
92
- this.logger?.warn?.(`[telemetry.canary.autopilot] failed to load gate snapshot ${source}: ${error instanceof Error ? error.message : String(error)}`);
89
+ this.logger?.warn?.(`[telemetry.health.snapshot] failed to load gate snapshot ${source}: ${error instanceof Error ? error.message : String(error)}`);
93
90
  return;
94
91
  }
95
92
  }
96
93
  constructor(options){
97
94
  this.syncGeneration = 0;
98
95
  this.appliedGateFingerprints = new Map();
99
- this.orchestrator = options.orchestrator;
100
- if (!options.gateSnapshotStore && !options.gateSnapshotPath) throw new Error('ContractGateAutopilot requires gateSnapshotPath or gateSnapshotStore');
96
+ this.monitor = options.monitor;
97
+ if (!options.gateSnapshotStore && !options.gateSnapshotPath) throw new Error('ContractGateSnapshotObserver requires gateSnapshotPath or gateSnapshotStore');
101
98
  this.gateSnapshotPath = options.gateSnapshotPath;
102
99
  this.gateSnapshotStore = options.gateSnapshotStore || (0, file_store_js_namespaceObject.createFileContractGateSnapshotStore)(options.gateSnapshotPath);
103
100
  this.pollIntervalMs = Math.max(250, options.pollIntervalMs ?? DEFAULT_POLL_INTERVAL_MS);
@@ -105,9 +102,9 @@ class ContractGateAutopilot {
105
102
  this.logger = options.logger;
106
103
  }
107
104
  }
108
- exports.ContractGateAutopilot = __webpack_exports__.ContractGateAutopilot;
105
+ exports.ContractGateSnapshotObserver = __webpack_exports__.ContractGateSnapshotObserver;
109
106
  for(var __rspack_i in __webpack_exports__)if (-1 === [
110
- "ContractGateAutopilot"
107
+ "ContractGateSnapshotObserver"
111
108
  ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
112
109
  Object.defineProperty(exports, '__esModule', {
113
110
  value: true