@bleedingdev/modern-js-server-runtime-extensions 3.8.2-ultramodern.9 → 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.
- package/dist/cjs/backend-federation-security/index.js +415 -0
- package/dist/cjs/backend-federation-security/node.js +74 -0
- package/dist/cjs/contract-gate-snapshot-store/http-store.js +1 -1
- package/dist/cjs/contract-gate-snapshot-store/resolve.js +4 -4
- package/dist/cjs/{contractGateAutopilot.js → contractGateSnapshotObserver.js} +14 -17
- package/dist/cjs/index.js +45 -13
- package/dist/cjs/runtime-fallback-signal/resolver.js +3 -3
- package/dist/cjs/runtimeLifecycle.js +129 -0
- package/dist/cjs/telemetry/{canaryEvaluation.js → healthEvaluation.js} +11 -13
- package/dist/cjs/telemetry/{canary.js → healthMonitor.js} +27 -44
- package/dist/cjs/telemetry/{canarySetup.js → healthSetup.js} +35 -39
- package/dist/cjs/telemetry/lifecycle.js +14 -14
- package/dist/cjs/telemetry/plugin.js +9 -9
- package/dist/cjs/telemetry/runtimeEndpoints.js +3 -3
- package/dist/cjs/telemetryCore.js +4 -4
- package/dist/esm/backend-federation-security/index.mjs +361 -0
- package/dist/esm/backend-federation-security/node.mjs +30 -0
- package/dist/esm/contract-gate-snapshot-store/http-store.mjs +1 -1
- package/dist/esm/contract-gate-snapshot-store/resolve.mjs +4 -4
- package/dist/esm/{contractGateAutopilot.mjs → contractGateSnapshotObserver.mjs} +12 -15
- package/dist/esm/index.mjs +4 -2
- package/dist/esm/runtime-fallback-signal/resolver.mjs +3 -3
- package/dist/esm/runtimeLifecycle.mjs +82 -0
- package/dist/esm/telemetry/{canaryEvaluation.mjs → healthEvaluation.mjs} +9 -11
- package/dist/esm/telemetry/{canary.mjs → healthMonitor.mjs} +25 -42
- package/dist/esm/telemetry/healthSetup.mjs +65 -0
- package/dist/esm/telemetry/lifecycle.mjs +14 -14
- package/dist/esm/telemetry/plugin.mjs +8 -8
- package/dist/esm/telemetry/runtimeEndpoints.mjs +3 -3
- package/dist/esm/telemetryCore.mjs +1 -1
- package/dist/esm-node/backend-federation-security/index.mjs +362 -0
- package/dist/esm-node/backend-federation-security/node.mjs +31 -0
- package/dist/esm-node/contract-gate-snapshot-store/http-store.mjs +1 -1
- package/dist/esm-node/contract-gate-snapshot-store/resolve.mjs +4 -4
- package/dist/esm-node/{contractGateAutopilot.mjs → contractGateSnapshotObserver.mjs} +12 -15
- package/dist/esm-node/index.mjs +4 -2
- package/dist/esm-node/runtime-fallback-signal/resolver.mjs +3 -3
- package/dist/esm-node/runtimeLifecycle.mjs +83 -0
- package/dist/esm-node/telemetry/{canaryEvaluation.mjs → healthEvaluation.mjs} +9 -11
- package/dist/esm-node/telemetry/{canary.mjs → healthMonitor.mjs} +25 -42
- package/dist/esm-node/telemetry/healthSetup.mjs +66 -0
- package/dist/esm-node/telemetry/lifecycle.mjs +14 -14
- package/dist/esm-node/telemetry/plugin.mjs +8 -8
- package/dist/esm-node/telemetry/runtimeEndpoints.mjs +3 -3
- package/dist/esm-node/telemetryCore.mjs +1 -1
- package/dist/types/backend-federation-security/index.d.ts +68 -0
- package/dist/types/backend-federation-security/node.d.ts +3 -0
- package/dist/types/{contractGateAutopilot.d.ts → contractGateSnapshotObserver.d.ts} +7 -6
- package/dist/types/index.d.ts +4 -2
- package/dist/types/runtime-fallback-signal/resolver.d.ts +2 -2
- package/dist/types/runtimeLifecycle.d.ts +10 -0
- package/dist/types/telemetry/healthEvaluation.d.ts +20 -0
- package/dist/types/telemetry/{canary.d.ts → healthMonitor.d.ts} +31 -28
- package/dist/types/telemetry/{canarySetup.d.ts → healthSetup.d.ts} +6 -6
- package/dist/types/telemetry/lifecycle.d.ts +4 -4
- package/dist/types/telemetry/plugin.d.ts +1 -1
- package/dist/types/telemetry/runtimeEndpoints.d.ts +3 -3
- package/dist/types/telemetryCore.d.ts +1 -1
- package/package.json +46 -8
- package/src/backend-federation-security/index.ts +831 -0
- package/src/backend-federation-security/node.ts +51 -0
- package/src/contract-gate-snapshot-store/http-store.ts +1 -1
- package/src/contract-gate-snapshot-store/resolve.ts +4 -4
- package/src/{contractGateAutopilot.ts → contractGateSnapshotObserver.ts} +18 -25
- package/src/index.ts +42 -6
- package/src/runtime-fallback-signal/resolver.ts +5 -5
- package/src/runtimeLifecycle.ts +125 -0
- package/src/telemetry/{canaryEvaluation.ts → healthEvaluation.ts} +14 -17
- package/src/telemetry/{canary.ts → healthMonitor.ts} +72 -84
- package/src/telemetry/{canarySetup.ts → healthSetup.ts} +50 -53
- package/src/telemetry/lifecycle.ts +20 -20
- package/src/telemetry/plugin.ts +16 -16
- package/src/telemetry/runtimeEndpoints.ts +6 -6
- package/src/telemetryCore.ts +11 -11
- package/tests/backendFederationSecurity.test.ts +416 -0
- package/tests/{contractGateAutopilot.test.ts → contractGateSnapshotObserver.test.ts} +59 -62
- package/tests/runtimeLifecycle.test.ts +107 -0
- package/tests/telemetryHealthMonitor.test.ts +187 -0
- package/dist/esm/telemetry/canarySetup.mjs +0 -69
- package/dist/esm-node/telemetry/canarySetup.mjs +0 -70
- package/dist/types/telemetry/canaryEvaluation.d.ts +0 -20
- package/tests/telemetryCanaryOrchestrator.test.ts +0 -365
|
@@ -31,7 +31,7 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
31
31
|
registerTelemetryLifecycle: ()=>registerTelemetryLifecycle
|
|
32
32
|
});
|
|
33
33
|
const index_js_namespaceObject = require("../contract-gate-snapshot-store/index.js");
|
|
34
|
-
const
|
|
34
|
+
const external_contractGateSnapshotObserver_js_namespaceObject = require("../contractGateSnapshotObserver.js");
|
|
35
35
|
const external_telemetryCore_js_namespaceObject = require("../telemetryCore.js");
|
|
36
36
|
const activeTelemetryLaneClosers = new Set();
|
|
37
37
|
let telemetryBeforeExitHookInstalled = false;
|
|
@@ -44,15 +44,15 @@ const ensureTelemetryBeforeExitHook = ()=>{
|
|
|
44
44
|
])close();
|
|
45
45
|
});
|
|
46
46
|
};
|
|
47
|
-
const registerTelemetryLifecycle = ({ api, registry, telemetryConfig,
|
|
48
|
-
let
|
|
47
|
+
const registerTelemetryLifecycle = ({ api, registry, telemetryConfig, legacyHealthConfig, healthMonitor, gateSnapshotStorePromise, appDirectory })=>{
|
|
48
|
+
let contractGateSnapshotObserver;
|
|
49
49
|
let telemetryLaneClosed = false;
|
|
50
50
|
const closeTelemetryLane = async ()=>{
|
|
51
51
|
if (telemetryLaneClosed) return;
|
|
52
52
|
telemetryLaneClosed = true;
|
|
53
53
|
activeTelemetryLaneClosers.delete(closeTelemetryLane);
|
|
54
|
-
|
|
55
|
-
|
|
54
|
+
contractGateSnapshotObserver?.stop();
|
|
55
|
+
healthMonitor?.stop();
|
|
56
56
|
await registry.shutdown();
|
|
57
57
|
};
|
|
58
58
|
let prepared = false;
|
|
@@ -73,20 +73,20 @@ const registerTelemetryLifecycle = ({ api, registry, telemetryConfig, canaryConf
|
|
|
73
73
|
await registry.startupHealthCheck({
|
|
74
74
|
failLoud: telemetryConfig.failLoudStartup ?? true
|
|
75
75
|
});
|
|
76
|
-
if (!
|
|
77
|
-
|
|
76
|
+
if (!healthMonitor) return;
|
|
77
|
+
healthMonitor.start();
|
|
78
78
|
if (gateSnapshotStorePromise) {
|
|
79
79
|
const gateSnapshotStore = await gateSnapshotStorePromise;
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
gateSnapshotPath: (0, index_js_namespaceObject.resolveContractGateSnapshotPath)(appDirectory,
|
|
80
|
+
contractGateSnapshotObserver = new external_contractGateSnapshotObserver_js_namespaceObject.ContractGateSnapshotObserver({
|
|
81
|
+
monitor: healthMonitor,
|
|
82
|
+
gateSnapshotPath: (0, index_js_namespaceObject.resolveContractGateSnapshotPath)(appDirectory, legacyHealthConfig?.autopilot?.gateSnapshotPath),
|
|
83
83
|
gateSnapshotStore,
|
|
84
|
-
pollIntervalMs:
|
|
85
|
-
gateStaleAfterMs:
|
|
84
|
+
pollIntervalMs: legacyHealthConfig?.autopilot?.pollIntervalMs,
|
|
85
|
+
gateStaleAfterMs: legacyHealthConfig?.autopilot?.gateStaleAfterMs
|
|
86
86
|
});
|
|
87
87
|
}
|
|
88
|
-
if (
|
|
89
|
-
|
|
88
|
+
if (contractGateSnapshotObserver) await contractGateSnapshotObserver.start();
|
|
89
|
+
healthMonitor.evaluate();
|
|
90
90
|
});
|
|
91
91
|
};
|
|
92
92
|
exports.registerTelemetryLifecycle = __webpack_exports__.registerTelemetryLifecycle;
|
|
@@ -30,7 +30,7 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
30
30
|
__webpack_require__.d(__webpack_exports__, {
|
|
31
31
|
DEFAULT_RUNTIME_FALLBACK_SIGNAL_ENDPOINT: ()=>external_runtimeFallbackSignal_js_namespaceObject.DEFAULT_RUNTIME_FALLBACK_SIGNAL_ENDPOINT,
|
|
32
32
|
DEFAULT_RUNTIME_STATUS_ENDPOINT: ()=>external_runtimeFallbackSignal_js_namespaceObject.DEFAULT_RUNTIME_STATUS_ENDPOINT,
|
|
33
|
-
|
|
33
|
+
TelemetryHealthMonitor: ()=>external_telemetryCore_js_namespaceObject.TelemetryHealthMonitor,
|
|
34
34
|
TelemetryRegistry: ()=>external_telemetryCore_js_namespaceObject.TelemetryRegistry,
|
|
35
35
|
TelemetryStartupHealthError: ()=>external_telemetryCore_js_namespaceObject.TelemetryStartupHealthError,
|
|
36
36
|
createOtlpTelemetryExporter: ()=>external_telemetryCore_js_namespaceObject.createOtlpTelemetryExporter,
|
|
@@ -54,7 +54,7 @@ const server_namespaceObject = require("@modern-js/create-request/server");
|
|
|
54
54
|
const utils_namespaceObject = require("@modern-js/utils");
|
|
55
55
|
const external_env_js_namespaceObject = require("../env.js");
|
|
56
56
|
const external_telemetryCore_js_namespaceObject = require("../telemetryCore.js");
|
|
57
|
-
const
|
|
57
|
+
const external_healthSetup_js_namespaceObject = require("./healthSetup.js");
|
|
58
58
|
const external_lifecycle_js_namespaceObject = require("./lifecycle.js");
|
|
59
59
|
const external_runtimeEndpoints_js_namespaceObject = require("./runtimeEndpoints.js");
|
|
60
60
|
const external_runtimeFallbackSignal_js_namespaceObject = require("../runtimeFallbackSignal.js");
|
|
@@ -89,15 +89,15 @@ const injectTelemetryPlugin = ()=>({
|
|
|
89
89
|
redactionKeys: telemetryConfig.redactionKeys,
|
|
90
90
|
slo: resolveTelemetrySloOptions(telemetryConfig.slo)
|
|
91
91
|
});
|
|
92
|
-
const {
|
|
92
|
+
const { healthMonitor, gateSnapshotStorePromise, runtimeFallbackSignalConfig, runtimeStatusAuthConfig } = (0, external_healthSetup_js_namespaceObject.setupTelemetryHealthMonitoring)({
|
|
93
93
|
registry,
|
|
94
94
|
appDirectory,
|
|
95
|
-
|
|
95
|
+
legacyHealthConfig: telemetryConfig.canary
|
|
96
96
|
});
|
|
97
97
|
if (runtimeFallbackSignalConfig) middlewares.push((0, external_runtimeEndpoints_js_namespaceObject.createRuntimeFallbackSignalMiddleware)(runtimeFallbackSignalConfig));
|
|
98
98
|
middlewares.push((0, external_runtimeEndpoints_js_namespaceObject.createRuntimeStatusMiddleware)({
|
|
99
99
|
registry,
|
|
100
|
-
|
|
100
|
+
healthMonitor,
|
|
101
101
|
runtimeFallbackSignalConfig,
|
|
102
102
|
runtimeStatusAuthConfig
|
|
103
103
|
}));
|
|
@@ -129,8 +129,8 @@ const injectTelemetryPlugin = ()=>({
|
|
|
129
129
|
api,
|
|
130
130
|
registry,
|
|
131
131
|
telemetryConfig,
|
|
132
|
-
|
|
133
|
-
|
|
132
|
+
legacyHealthConfig: telemetryConfig.canary,
|
|
133
|
+
healthMonitor,
|
|
134
134
|
gateSnapshotStorePromise,
|
|
135
135
|
appDirectory
|
|
136
136
|
});
|
|
@@ -138,7 +138,7 @@ const injectTelemetryPlugin = ()=>({
|
|
|
138
138
|
});
|
|
139
139
|
exports.DEFAULT_RUNTIME_FALLBACK_SIGNAL_ENDPOINT = __webpack_exports__.DEFAULT_RUNTIME_FALLBACK_SIGNAL_ENDPOINT;
|
|
140
140
|
exports.DEFAULT_RUNTIME_STATUS_ENDPOINT = __webpack_exports__.DEFAULT_RUNTIME_STATUS_ENDPOINT;
|
|
141
|
-
exports.
|
|
141
|
+
exports.TelemetryHealthMonitor = __webpack_exports__.TelemetryHealthMonitor;
|
|
142
142
|
exports.TelemetryRegistry = __webpack_exports__.TelemetryRegistry;
|
|
143
143
|
exports.TelemetryStartupHealthError = __webpack_exports__.TelemetryStartupHealthError;
|
|
144
144
|
exports.createOtlpTelemetryExporter = __webpack_exports__.createOtlpTelemetryExporter;
|
|
@@ -160,7 +160,7 @@ exports.resolveTelemetrySloOptions = __webpack_exports__.resolveTelemetrySloOpti
|
|
|
160
160
|
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
161
161
|
"DEFAULT_RUNTIME_FALLBACK_SIGNAL_ENDPOINT",
|
|
162
162
|
"DEFAULT_RUNTIME_STATUS_ENDPOINT",
|
|
163
|
-
"
|
|
163
|
+
"TelemetryHealthMonitor",
|
|
164
164
|
"TelemetryRegistry",
|
|
165
165
|
"TelemetryStartupHealthError",
|
|
166
166
|
"createOtlpTelemetryExporter",
|
|
@@ -67,7 +67,7 @@ const createRuntimeFallbackSignalMiddleware = (signalConfig)=>({
|
|
|
67
67
|
}
|
|
68
68
|
}
|
|
69
69
|
});
|
|
70
|
-
const createRuntimeStatusMiddleware = ({ registry,
|
|
70
|
+
const createRuntimeStatusMiddleware = ({ registry, healthMonitor, runtimeFallbackSignalConfig, runtimeStatusAuthConfig })=>({
|
|
71
71
|
name: 'telemetry-runtime-status',
|
|
72
72
|
path: external_runtimeFallbackSignal_js_namespaceObject.DEFAULT_RUNTIME_STATUS_ENDPOINT,
|
|
73
73
|
method: 'get',
|
|
@@ -86,9 +86,9 @@ const createRuntimeStatusMiddleware = ({ registry, canaryOrchestrator, runtimeFa
|
|
|
86
86
|
queueStats: registry.getQueueStats(),
|
|
87
87
|
exporterHealth: registry.getExporterHealth()
|
|
88
88
|
},
|
|
89
|
-
|
|
89
|
+
health: healthMonitor ? {
|
|
90
90
|
enabled: true,
|
|
91
|
-
...
|
|
91
|
+
...healthMonitor.getStatusSnapshot()
|
|
92
92
|
} : {
|
|
93
93
|
enabled: false
|
|
94
94
|
},
|
|
@@ -28,7 +28,7 @@ var __webpack_require__ = {};
|
|
|
28
28
|
var __webpack_exports__ = {};
|
|
29
29
|
__webpack_require__.r(__webpack_exports__);
|
|
30
30
|
__webpack_require__.d(__webpack_exports__, {
|
|
31
|
-
|
|
31
|
+
TelemetryHealthMonitor: ()=>healthMonitor_js_namespaceObject.TelemetryHealthMonitor,
|
|
32
32
|
TelemetryRegistry: ()=>registry_js_namespaceObject.TelemetryRegistry,
|
|
33
33
|
TelemetryStartupHealthError: ()=>registryTypes_js_namespaceObject.TelemetryStartupHealthError,
|
|
34
34
|
createOtlpTelemetryExporter: ()=>exporters_js_namespaceObject.createOtlpTelemetryExporter,
|
|
@@ -37,13 +37,13 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
37
37
|
maybeWarnLegacyOtlpEndpoint: ()=>exporters_js_namespaceObject.maybeWarnLegacyOtlpEndpoint,
|
|
38
38
|
toTelemetryEnvelope: ()=>envelope_js_namespaceObject.toTelemetryEnvelope
|
|
39
39
|
});
|
|
40
|
-
const canary_js_namespaceObject = require("./telemetry/canary.js");
|
|
41
40
|
const envelope_js_namespaceObject = require("./telemetry/envelope.js");
|
|
42
41
|
const exporters_js_namespaceObject = require("./telemetry/exporters.js");
|
|
42
|
+
const healthMonitor_js_namespaceObject = require("./telemetry/healthMonitor.js");
|
|
43
43
|
const metrics_js_namespaceObject = require("./telemetry/metrics.js");
|
|
44
44
|
const registry_js_namespaceObject = require("./telemetry/registry.js");
|
|
45
45
|
const registryTypes_js_namespaceObject = require("./telemetry/registryTypes.js");
|
|
46
|
-
exports.
|
|
46
|
+
exports.TelemetryHealthMonitor = __webpack_exports__.TelemetryHealthMonitor;
|
|
47
47
|
exports.TelemetryRegistry = __webpack_exports__.TelemetryRegistry;
|
|
48
48
|
exports.TelemetryStartupHealthError = __webpack_exports__.TelemetryStartupHealthError;
|
|
49
49
|
exports.createOtlpTelemetryExporter = __webpack_exports__.createOtlpTelemetryExporter;
|
|
@@ -52,7 +52,7 @@ exports.createVictoriaMetricsTelemetryExporter = __webpack_exports__.createVicto
|
|
|
52
52
|
exports.maybeWarnLegacyOtlpEndpoint = __webpack_exports__.maybeWarnLegacyOtlpEndpoint;
|
|
53
53
|
exports.toTelemetryEnvelope = __webpack_exports__.toTelemetryEnvelope;
|
|
54
54
|
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
55
|
-
"
|
|
55
|
+
"TelemetryHealthMonitor",
|
|
56
56
|
"TelemetryRegistry",
|
|
57
57
|
"TelemetryStartupHealthError",
|
|
58
58
|
"createOtlpTelemetryExporter",
|
|
@@ -0,0 +1,361 @@
|
|
|
1
|
+
const DEFAULT_MAX_ENTRY_BYTES = 16777216;
|
|
2
|
+
const DEFAULT_MAX_RESOURCE_BYTES = 1048576;
|
|
3
|
+
const DEFAULT_ENTRY_TIMEOUT_MS = 10000;
|
|
4
|
+
class BackendFederationRemoteEntryError extends Error {
|
|
5
|
+
constructor(code, message, options = {}){
|
|
6
|
+
super(message, void 0 === options.cause ? void 0 : options);
|
|
7
|
+
this.name = 'BackendFederationRemoteEntryError';
|
|
8
|
+
this.code = code;
|
|
9
|
+
this.details = options.details;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
const isRecord = (value)=>'object' == typeof value && null !== value;
|
|
13
|
+
const recordField = (value, key)=>{
|
|
14
|
+
if (!isRecord(value)) return;
|
|
15
|
+
const field = value[key];
|
|
16
|
+
return isRecord(field) ? field : void 0;
|
|
17
|
+
};
|
|
18
|
+
const stringField = (value)=>'string' == typeof value && value.length > 0 ? value : void 0;
|
|
19
|
+
function resolveBackendFederationRemoteEntryVerification(manifest) {
|
|
20
|
+
if (!isRecord(manifest)) return;
|
|
21
|
+
const entry = recordField(manifest, 'entry');
|
|
22
|
+
const sha256 = entry?.sha256;
|
|
23
|
+
const byteLength = entry?.byteLength;
|
|
24
|
+
if (void 0 === sha256 && void 0 === byteLength) return;
|
|
25
|
+
const backendFederation = recordField(manifest, 'backendFederation');
|
|
26
|
+
const boundary = recordField(backendFederation, 'versionBoundary');
|
|
27
|
+
const boundaryDeliveryUnit = recordField(boundary, 'deliveryUnit');
|
|
28
|
+
const deliveryUnit = recordField(backendFederation, 'deliveryUnit');
|
|
29
|
+
const remoteName = stringField(backendFederation?.name) ?? stringField(manifest.name) ?? stringField(manifest.id);
|
|
30
|
+
const entryUrl = stringField(entry?.url);
|
|
31
|
+
const containerEntry = stringField(backendFederation?.containerEntry);
|
|
32
|
+
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.');
|
|
33
|
+
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.', {
|
|
34
|
+
details: {
|
|
35
|
+
containerEntry: redactBackendFederationUrl(containerEntry),
|
|
36
|
+
entryUrl: redactBackendFederationUrl(entryUrl)
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
const buildMarker = stringField(boundaryDeliveryUnit?.buildMarker) ?? stringField(deliveryUnit?.buildMarker);
|
|
40
|
+
const unitId = stringField(boundaryDeliveryUnit?.unitId) ?? stringField(deliveryUnit?.unitId);
|
|
41
|
+
return {
|
|
42
|
+
byteLength,
|
|
43
|
+
entryUrl,
|
|
44
|
+
remoteName,
|
|
45
|
+
sha256,
|
|
46
|
+
...buildMarker ? {
|
|
47
|
+
buildMarker
|
|
48
|
+
} : {},
|
|
49
|
+
...unitId ? {
|
|
50
|
+
unitId
|
|
51
|
+
} : {}
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
const canonicalEntryUrl = (value)=>{
|
|
55
|
+
let url;
|
|
56
|
+
try {
|
|
57
|
+
url = new URL(value);
|
|
58
|
+
} catch (cause) {
|
|
59
|
+
throw new BackendFederationRemoteEntryError('invalid_verification', '[Module Federation] Invalid backend federation URL.', {
|
|
60
|
+
cause
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
if (url.username || url.password) throw new BackendFederationRemoteEntryError('invalid_verification', '[Module Federation] Backend remote entry URLs must not contain credentials.');
|
|
64
|
+
url.hash = '';
|
|
65
|
+
return url;
|
|
66
|
+
};
|
|
67
|
+
function redactBackendFederationUrl(value) {
|
|
68
|
+
try {
|
|
69
|
+
const url = new URL(value);
|
|
70
|
+
url.username = '';
|
|
71
|
+
url.password = '';
|
|
72
|
+
url.search = '';
|
|
73
|
+
url.hash = '';
|
|
74
|
+
return url.href;
|
|
75
|
+
} catch {
|
|
76
|
+
return '[local or invalid reference]';
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
const isLoopback = (hostname)=>'localhost' === hostname || '127.0.0.1' === hostname || '[::1]' === hostname;
|
|
80
|
+
const assertAllowedEntryUrl = (url, allowInsecureHttp)=>{
|
|
81
|
+
if ('https:' === url.protocol) return;
|
|
82
|
+
if ('http:' === url.protocol && (allowInsecureHttp || isLoopback(url.hostname))) return;
|
|
83
|
+
throw new BackendFederationRemoteEntryError('unsupported_entry', `[Module Federation] Backend federation resource ${redactBackendFederationUrl(url.href)} must use HTTPS (loopback HTTP is allowed for local development).`);
|
|
84
|
+
};
|
|
85
|
+
const assertVerification = (remote, verification, expected, allowInsecureHttp)=>{
|
|
86
|
+
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.`);
|
|
87
|
+
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.');
|
|
88
|
+
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.');
|
|
89
|
+
const requestedUrl = canonicalEntryUrl(remote.entry);
|
|
90
|
+
const verifiedUrl = canonicalEntryUrl(verification.entryUrl);
|
|
91
|
+
assertAllowedEntryUrl(requestedUrl, allowInsecureHttp);
|
|
92
|
+
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.', {
|
|
93
|
+
details: {
|
|
94
|
+
requestedEntry: redactBackendFederationUrl(requestedUrl.href),
|
|
95
|
+
requestedName: remote.name,
|
|
96
|
+
verifiedEntry: redactBackendFederationUrl(verifiedUrl.href),
|
|
97
|
+
verifiedName: verification.remoteName
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
for (const key of [
|
|
101
|
+
'buildMarker',
|
|
102
|
+
'byteLength',
|
|
103
|
+
'entryUrl',
|
|
104
|
+
'remoteName',
|
|
105
|
+
'sha256',
|
|
106
|
+
'unitId'
|
|
107
|
+
]){
|
|
108
|
+
const expectedValue = expected[key];
|
|
109
|
+
if (void 0 !== expectedValue && expectedValue !== verification[key]) throw new BackendFederationRemoteEntryError('identity_mismatch', `[Module Federation] Backend remote entry ${key} does not match the trusted expectation.`, {
|
|
110
|
+
details: {
|
|
111
|
+
expected: 'entryUrl' === key && 'string' == typeof expectedValue ? redactBackendFederationUrl(expectedValue) : expectedValue,
|
|
112
|
+
field: key,
|
|
113
|
+
received: 'entryUrl' === key ? redactBackendFederationUrl(verification.entryUrl) : verification[key]
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
return requestedUrl;
|
|
118
|
+
};
|
|
119
|
+
const resolveTrustedVerification = (verification, expected)=>{
|
|
120
|
+
if (verification) return verification;
|
|
121
|
+
if ('number' == typeof expected.byteLength && 'string' == typeof expected.entryUrl && 'string' == typeof expected.remoteName && 'string' == typeof expected.sha256) return expected;
|
|
122
|
+
throw new BackendFederationRemoteEntryError('invalid_verification', '[Module Federation] Verified backend network loading requires trusted entryUrl, remoteName, sha256, and byteLength values.');
|
|
123
|
+
};
|
|
124
|
+
const readWithAbort = (promise, signal)=>new Promise((resolve, reject)=>{
|
|
125
|
+
if (signal.aborted) return void reject(signal.reason);
|
|
126
|
+
const onAbort = ()=>reject(signal.reason);
|
|
127
|
+
signal.addEventListener('abort', onAbort, {
|
|
128
|
+
once: true
|
|
129
|
+
});
|
|
130
|
+
promise.then(resolve, reject).finally(()=>{
|
|
131
|
+
signal.removeEventListener('abort', onAbort);
|
|
132
|
+
});
|
|
133
|
+
});
|
|
134
|
+
const parseContentLength = (value)=>{
|
|
135
|
+
if (null === value || !/^\d+$/u.test(value)) return;
|
|
136
|
+
const parsed = Number(value);
|
|
137
|
+
return Number.isSafeInteger(parsed) ? parsed : void 0;
|
|
138
|
+
};
|
|
139
|
+
const sha256Hex = async (bytes, signal)=>{
|
|
140
|
+
const subtle = globalThis.crypto?.subtle;
|
|
141
|
+
if (void 0 === subtle) throw new BackendFederationRemoteEntryError('unsupported_entry', '[Module Federation] Verified backend remote loading requires Web Crypto SHA-256 support.');
|
|
142
|
+
const digest = new Uint8Array(await readWithAbort(subtle.digest('SHA-256', bytes), signal));
|
|
143
|
+
return Array.from(digest, (byte)=>byte.toString(16).padStart(2, '0')).join('');
|
|
144
|
+
};
|
|
145
|
+
async function loadBoundedBackendFederationResource(resourceUrl, options = {}) {
|
|
146
|
+
const requestedUrl = canonicalEntryUrl(resourceUrl);
|
|
147
|
+
assertAllowedEntryUrl(requestedUrl, true === options.allowInsecureHttp);
|
|
148
|
+
const maxBytes = options.maxBytes ?? DEFAULT_MAX_RESOURCE_BYTES;
|
|
149
|
+
if (!Number.isSafeInteger(maxBytes) || maxBytes <= 0) throw new BackendFederationRemoteEntryError('invalid_verification', '[Module Federation] Backend federation resource maxBytes must be a positive safe integer.');
|
|
150
|
+
const timeoutMs = options.timeoutMs ?? DEFAULT_ENTRY_TIMEOUT_MS;
|
|
151
|
+
if (!Number.isSafeInteger(timeoutMs) || timeoutMs < 0) throw new BackendFederationRemoteEntryError('invalid_verification', '[Module Federation] Backend federation resource timeoutMs must be a non-negative safe integer.');
|
|
152
|
+
const controller = new AbortController();
|
|
153
|
+
let timedOut = false;
|
|
154
|
+
let callerAborted = false;
|
|
155
|
+
const onCallerAbort = ()=>{
|
|
156
|
+
callerAborted = true;
|
|
157
|
+
controller.abort(options.signal?.reason);
|
|
158
|
+
};
|
|
159
|
+
if (options.signal?.aborted) onCallerAbort();
|
|
160
|
+
else options.signal?.addEventListener('abort', onCallerAbort, {
|
|
161
|
+
once: true
|
|
162
|
+
});
|
|
163
|
+
const timeout = timeoutMs > 0 ? setTimeout(()=>{
|
|
164
|
+
timedOut = true;
|
|
165
|
+
controller.abort(new Error(`Backend federation ${options.kind ?? 'manifest'} timed out after ${timeoutMs}ms`));
|
|
166
|
+
}, timeoutMs) : void 0;
|
|
167
|
+
const fetchResource = options.fetch ?? globalThis.fetch;
|
|
168
|
+
let reader;
|
|
169
|
+
const resourceKind = options.kind ?? 'manifest';
|
|
170
|
+
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.`, {
|
|
171
|
+
cause
|
|
172
|
+
});
|
|
173
|
+
try {
|
|
174
|
+
if (controller.signal.aborted) throw cancellationError(controller.signal.reason);
|
|
175
|
+
if ('function' != typeof fetchResource) throw new BackendFederationRemoteEntryError('fetch_failed', `[Module Federation] Backend federation ${resourceKind} loading requires fetch.`);
|
|
176
|
+
let response;
|
|
177
|
+
try {
|
|
178
|
+
response = await readWithAbort(fetchResource(requestedUrl.href, {
|
|
179
|
+
cache: 'no-store',
|
|
180
|
+
redirect: 'error',
|
|
181
|
+
signal: controller.signal
|
|
182
|
+
}), controller.signal);
|
|
183
|
+
} catch (cause) {
|
|
184
|
+
if (controller.signal.aborted) throw cancellationError(cause);
|
|
185
|
+
throw new BackendFederationRemoteEntryError('fetch_failed', `[Module Federation] Failed to fetch backend federation ${resourceKind}.`, {
|
|
186
|
+
cause
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
if (!response.ok) throw new BackendFederationRemoteEntryError('fetch_failed', `[Module Federation] Backend federation ${resourceKind} returned HTTP ${response.status}.`);
|
|
190
|
+
if (response.url) {
|
|
191
|
+
const responseUrl = canonicalEntryUrl(response.url);
|
|
192
|
+
if (responseUrl.href !== requestedUrl.href) throw new BackendFederationRemoteEntryError('redirect_mismatch', `[Module Federation] Backend federation ${resourceKind} redirected outside its trusted URL.`, {
|
|
193
|
+
details: {
|
|
194
|
+
expected: redactBackendFederationUrl(requestedUrl.href),
|
|
195
|
+
received: redactBackendFederationUrl(responseUrl.href)
|
|
196
|
+
}
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
const contentLength = parseContentLength(response.headers?.get('content-length') ?? null);
|
|
200
|
+
if (void 0 !== contentLength && contentLength > maxBytes) {
|
|
201
|
+
controller.abort();
|
|
202
|
+
await response.body?.cancel().catch(()=>void 0);
|
|
203
|
+
throw new BackendFederationRemoteEntryError('entry_too_large', `[Module Federation] Backend federation ${resourceKind} declares ${contentLength} bytes, exceeding its ${maxBytes}-byte policy limit.`);
|
|
204
|
+
}
|
|
205
|
+
const chunks = [];
|
|
206
|
+
let byteLength = 0;
|
|
207
|
+
if (response.body) {
|
|
208
|
+
reader = response.body.getReader();
|
|
209
|
+
while(true){
|
|
210
|
+
const result = await readWithAbort(reader.read(), controller.signal);
|
|
211
|
+
if (result.done) break;
|
|
212
|
+
byteLength += result.value.byteLength;
|
|
213
|
+
if (byteLength > maxBytes) throw new BackendFederationRemoteEntryError('entry_too_large', `[Module Federation] Backend federation ${resourceKind} exceeded its ${maxBytes}-byte limit while streaming.`);
|
|
214
|
+
chunks.push(result.value);
|
|
215
|
+
}
|
|
216
|
+
} else if (response.text) {
|
|
217
|
+
const bytes = new TextEncoder().encode(await readWithAbort(response.text(), controller.signal));
|
|
218
|
+
if (bytes.byteLength > maxBytes) throw new BackendFederationRemoteEntryError('entry_too_large', `[Module Federation] Backend federation ${resourceKind} exceeded its ${maxBytes}-byte limit.`);
|
|
219
|
+
chunks.push(bytes);
|
|
220
|
+
byteLength = bytes.byteLength;
|
|
221
|
+
}
|
|
222
|
+
const bytes = new Uint8Array(byteLength);
|
|
223
|
+
let offset = 0;
|
|
224
|
+
for (const chunk of chunks){
|
|
225
|
+
bytes.set(chunk, offset);
|
|
226
|
+
offset += chunk.byteLength;
|
|
227
|
+
}
|
|
228
|
+
if (controller.signal.aborted) throw cancellationError(controller.signal.reason);
|
|
229
|
+
return bytes;
|
|
230
|
+
} catch (cause) {
|
|
231
|
+
if (!controller.signal.aborted) controller.abort(cause);
|
|
232
|
+
await reader?.cancel(cause).catch(()=>void 0);
|
|
233
|
+
if (cause instanceof BackendFederationRemoteEntryError) throw cause;
|
|
234
|
+
if (timedOut || callerAborted) throw cancellationError(cause);
|
|
235
|
+
throw new BackendFederationRemoteEntryError('fetch_failed', `[Module Federation] Backend federation ${resourceKind} loading failed.`, {
|
|
236
|
+
cause
|
|
237
|
+
});
|
|
238
|
+
} finally{
|
|
239
|
+
if (timeout) clearTimeout(timeout);
|
|
240
|
+
options.signal?.removeEventListener('abort', onCallerAbort);
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
const evaluateBackendFederationCommonJsEntry = (remote, bytes, evaluator)=>{
|
|
244
|
+
let source;
|
|
245
|
+
try {
|
|
246
|
+
source = new TextDecoder('utf-8', {
|
|
247
|
+
fatal: true
|
|
248
|
+
}).decode(bytes);
|
|
249
|
+
} catch (cause) {
|
|
250
|
+
throw new BackendFederationRemoteEntryError('integrity_mismatch', `[Module Federation] Backend remote ${remote.name} is not valid UTF-8 JavaScript.`, {
|
|
251
|
+
cause
|
|
252
|
+
});
|
|
253
|
+
}
|
|
254
|
+
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.`);
|
|
255
|
+
const evaluated = evaluator(source, {
|
|
256
|
+
remote
|
|
257
|
+
});
|
|
258
|
+
const defaultExport = 'object' == typeof evaluated && null !== evaluated && 'default' in evaluated ? evaluated.default : void 0;
|
|
259
|
+
const entry = defaultExport ?? evaluated;
|
|
260
|
+
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.`);
|
|
261
|
+
return entry;
|
|
262
|
+
};
|
|
263
|
+
async function loadVerifiedBackendFederationEntry(options) {
|
|
264
|
+
const verification = resolveTrustedVerification(options.verification, options.expected ?? {});
|
|
265
|
+
const requestedUrl = assertVerification(options.remote, verification, options.expected ?? {}, true === options.allowInsecureHttp);
|
|
266
|
+
const maxBytes = options.maxBytes ?? DEFAULT_MAX_ENTRY_BYTES;
|
|
267
|
+
if (!Number.isSafeInteger(maxBytes) || maxBytes <= 0) throw new BackendFederationRemoteEntryError('invalid_verification', '[Module Federation] Backend remote entry maxBytes must be a positive safe integer.');
|
|
268
|
+
if (verification.byteLength > maxBytes) throw new BackendFederationRemoteEntryError('entry_too_large', `[Module Federation] Backend remote entry exceeds the ${maxBytes}-byte policy limit.`);
|
|
269
|
+
const timeoutMs = options.timeoutMs ?? DEFAULT_ENTRY_TIMEOUT_MS;
|
|
270
|
+
if (!Number.isSafeInteger(timeoutMs) || timeoutMs < 0) throw new BackendFederationRemoteEntryError('invalid_verification', '[Module Federation] Backend remote entry timeoutMs must be a non-negative safe integer.');
|
|
271
|
+
const controller = new AbortController();
|
|
272
|
+
let timedOut = false;
|
|
273
|
+
let callerAborted = false;
|
|
274
|
+
const onCallerAbort = ()=>{
|
|
275
|
+
callerAborted = true;
|
|
276
|
+
controller.abort(options.signal?.reason);
|
|
277
|
+
};
|
|
278
|
+
if (options.signal?.aborted) onCallerAbort();
|
|
279
|
+
else options.signal?.addEventListener('abort', onCallerAbort, {
|
|
280
|
+
once: true
|
|
281
|
+
});
|
|
282
|
+
const timeout = timeoutMs > 0 ? setTimeout(()=>{
|
|
283
|
+
timedOut = true;
|
|
284
|
+
controller.abort(new Error(`Backend remote entry timed out after ${timeoutMs}ms`));
|
|
285
|
+
}, timeoutMs) : void 0;
|
|
286
|
+
const fetchEntry = options.fetch ?? globalThis.fetch;
|
|
287
|
+
let reader;
|
|
288
|
+
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.`, {
|
|
289
|
+
cause
|
|
290
|
+
});
|
|
291
|
+
try {
|
|
292
|
+
if (controller.signal.aborted) throw cancellationError(controller.signal.reason);
|
|
293
|
+
if ('function' != typeof fetchEntry) throw new BackendFederationRemoteEntryError('fetch_failed', '[Module Federation] Backend remote entry loading requires fetch.');
|
|
294
|
+
let response;
|
|
295
|
+
try {
|
|
296
|
+
response = await readWithAbort(fetchEntry(requestedUrl.href, {
|
|
297
|
+
cache: 'no-store',
|
|
298
|
+
redirect: 'error',
|
|
299
|
+
signal: controller.signal
|
|
300
|
+
}), controller.signal);
|
|
301
|
+
} catch (cause) {
|
|
302
|
+
if (controller.signal.aborted) throw cancellationError(cause);
|
|
303
|
+
throw new BackendFederationRemoteEntryError('fetch_failed', `[Module Federation] Failed to fetch backend remote ${options.remote.name}.`, {
|
|
304
|
+
cause
|
|
305
|
+
});
|
|
306
|
+
}
|
|
307
|
+
if (!response.ok) throw new BackendFederationRemoteEntryError('fetch_failed', `[Module Federation] Backend remote ${options.remote.name} returned HTTP ${response.status}.`);
|
|
308
|
+
if (response.url) {
|
|
309
|
+
const responseUrl = canonicalEntryUrl(response.url);
|
|
310
|
+
if (responseUrl.href !== requestedUrl.href) throw new BackendFederationRemoteEntryError('redirect_mismatch', `[Module Federation] Backend remote ${options.remote.name} redirected outside its verified entry URL.`, {
|
|
311
|
+
details: {
|
|
312
|
+
expected: redactBackendFederationUrl(requestedUrl.href),
|
|
313
|
+
received: redactBackendFederationUrl(responseUrl.href)
|
|
314
|
+
}
|
|
315
|
+
});
|
|
316
|
+
}
|
|
317
|
+
const contentLength = parseContentLength(response.headers?.get('content-length') ?? null);
|
|
318
|
+
const byteLimit = Math.min(maxBytes, verification.byteLength);
|
|
319
|
+
if (void 0 !== contentLength && contentLength > maxBytes) {
|
|
320
|
+
controller.abort();
|
|
321
|
+
await response.body?.cancel().catch(()=>void 0);
|
|
322
|
+
throw new BackendFederationRemoteEntryError('entry_too_large', `[Module Federation] Backend remote ${options.remote.name} declares ${contentLength} bytes, exceeding its ${maxBytes}-byte policy limit.`);
|
|
323
|
+
}
|
|
324
|
+
reader = response.body?.getReader();
|
|
325
|
+
const bytes = new Uint8Array(verification.byteLength);
|
|
326
|
+
let byteLength = 0;
|
|
327
|
+
if (reader) while(true){
|
|
328
|
+
const result = await readWithAbort(reader.read(), controller.signal);
|
|
329
|
+
if (result.done) break;
|
|
330
|
+
const nextByteLength = byteLength + result.value.byteLength;
|
|
331
|
+
if (nextByteLength > byteLimit) throw new BackendFederationRemoteEntryError('entry_too_large', `[Module Federation] Backend remote ${options.remote.name} exceeded its ${byteLimit}-byte limit while streaming.`);
|
|
332
|
+
bytes.set(result.value, byteLength);
|
|
333
|
+
byteLength = nextByteLength;
|
|
334
|
+
}
|
|
335
|
+
if (byteLength !== verification.byteLength) throw new BackendFederationRemoteEntryError('byte_length_mismatch', `[Module Federation] Backend remote ${options.remote.name} byte length mismatch.`, {
|
|
336
|
+
details: {
|
|
337
|
+
expected: verification.byteLength,
|
|
338
|
+
received: byteLength
|
|
339
|
+
}
|
|
340
|
+
});
|
|
341
|
+
const actualDigest = await sha256Hex(bytes, controller.signal);
|
|
342
|
+
if (controller.signal.aborted) throw cancellationError(controller.signal.reason);
|
|
343
|
+
if (actualDigest !== verification.sha256) throw new BackendFederationRemoteEntryError('integrity_mismatch', `[Module Federation] Backend remote ${options.remote.name} SHA-256 mismatch.`, {
|
|
344
|
+
details: {
|
|
345
|
+
expected: verification.sha256,
|
|
346
|
+
received: actualDigest
|
|
347
|
+
}
|
|
348
|
+
});
|
|
349
|
+
return evaluateBackendFederationCommonJsEntry(options.remote, bytes, options.evaluateCommonJs);
|
|
350
|
+
} catch (cause) {
|
|
351
|
+
if (!controller.signal.aborted) controller.abort(cause);
|
|
352
|
+
await reader?.cancel(cause).catch(()=>void 0);
|
|
353
|
+
if (cause instanceof BackendFederationRemoteEntryError && !('aborted' === cause.code && timedOut)) throw cause;
|
|
354
|
+
if (controller.signal.aborted && (timedOut || callerAborted)) throw cancellationError(cause);
|
|
355
|
+
throw cause;
|
|
356
|
+
} finally{
|
|
357
|
+
if (timeout) clearTimeout(timeout);
|
|
358
|
+
options.signal?.removeEventListener('abort', onCallerAbort);
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
export { BackendFederationRemoteEntryError, evaluateBackendFederationCommonJsEntry, loadBoundedBackendFederationResource, loadVerifiedBackendFederationEntry, redactBackendFederationUrl, resolveBackendFederationRemoteEntryVerification };
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import { builtinModules, createRequire } from "node:module";
|
|
3
|
+
import { BackendFederationRemoteEntryError } from "./index.mjs";
|
|
4
|
+
const nodeRequire = createRequire(import.meta.url);
|
|
5
|
+
const nodeBuiltins = new Set([
|
|
6
|
+
...builtinModules,
|
|
7
|
+
...builtinModules.map((name)=>`node:${name}`)
|
|
8
|
+
]);
|
|
9
|
+
const toBytes = (value)=>'string' == typeof value ? new TextEncoder().encode(value) : value;
|
|
10
|
+
function createBackendFederationEntryIntegrity(value) {
|
|
11
|
+
const bytes = toBytes(value);
|
|
12
|
+
return {
|
|
13
|
+
byteLength: bytes.byteLength,
|
|
14
|
+
sha256: createHash('sha256').update(bytes).digest('hex')
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
const evaluateNodeBackendFederationCommonJs = (source, { remote })=>{
|
|
18
|
+
const module = {
|
|
19
|
+
exports: {}
|
|
20
|
+
};
|
|
21
|
+
const exports = module.exports;
|
|
22
|
+
const requireBuiltin = (specifier)=>{
|
|
23
|
+
if (!nodeBuiltins.has(specifier)) throw new BackendFederationRemoteEntryError('unsupported_entry', `[Module Federation] Backend remote ${remote.name} attempted to require non-builtin module ${specifier}. Bundle package dependencies into the remote entry.`);
|
|
24
|
+
return nodeRequire(specifier);
|
|
25
|
+
};
|
|
26
|
+
const evaluate = new Function('module', 'exports', 'globalThis', 'require', source);
|
|
27
|
+
evaluate(module, exports, globalThis, requireBuiltin);
|
|
28
|
+
return module.exports;
|
|
29
|
+
};
|
|
30
|
+
export { createBackendFederationEntryIntegrity, evaluateNodeBackendFederationCommonJs };
|
|
@@ -10,7 +10,7 @@ const BUILTIN_HTTP_STATE_STORE_MODULES = new Set([
|
|
|
10
10
|
]);
|
|
11
11
|
const normalizeHttpStoreOptions = (options)=>{
|
|
12
12
|
const endpoint = 'string' == typeof options?.endpoint ? options.endpoint.trim() : '';
|
|
13
|
-
if (!endpoint) throw new Error('[telemetry.
|
|
13
|
+
if (!endpoint) throw new Error('[telemetry.health.snapshot] HTTP stateStore requires options.endpoint');
|
|
14
14
|
const readMethod = 'string' == typeof options?.readMethod && options.readMethod.trim() ? options.readMethod.trim().toUpperCase() : 'GET';
|
|
15
15
|
const writeMethod = 'string' == typeof options?.writeMethod && options.writeMethod.trim() ? options.writeMethod.trim().toUpperCase() : 'PUT';
|
|
16
16
|
const timeoutMsRaw = Number(options?.timeoutMs);
|
|
@@ -45,7 +45,7 @@ const resolveContractGateSnapshotStore = async (input)=>{
|
|
|
45
45
|
stateStore
|
|
46
46
|
});
|
|
47
47
|
if (builtinStore) {
|
|
48
|
-
logger?.info?.(`[telemetry.
|
|
48
|
+
logger?.info?.(`[telemetry.health.snapshot] using built-in contract gate snapshot store "${builtinStore.name}"`);
|
|
49
49
|
return builtinStore;
|
|
50
50
|
}
|
|
51
51
|
const modulePath = resolveStoreModulePath(appDirectory, stateStore.module);
|
|
@@ -53,10 +53,10 @@ const resolveContractGateSnapshotStore = async (input)=>{
|
|
|
53
53
|
try {
|
|
54
54
|
mod = await import(toStoreModuleImportSpecifier(modulePath));
|
|
55
55
|
} catch (error) {
|
|
56
|
-
throw new Error(`[telemetry.
|
|
56
|
+
throw new Error(`[telemetry.health.snapshot] Failed to load stateStore.module "${stateStore.module}" (${modulePath}): ${error instanceof Error ? error.message : String(error)}`);
|
|
57
57
|
}
|
|
58
58
|
const factory = pickStoreFactory(mod);
|
|
59
|
-
if (!factory) throw new Error(`[telemetry.
|
|
59
|
+
if (!factory) throw new Error(`[telemetry.health.snapshot] stateStore.module "${stateStore.module}" does not export createContractGateSnapshotStore()`);
|
|
60
60
|
const store = await factory({
|
|
61
61
|
appDirectory,
|
|
62
62
|
gateSnapshotPath,
|
|
@@ -64,7 +64,7 @@ const resolveContractGateSnapshotStore = async (input)=>{
|
|
|
64
64
|
logger
|
|
65
65
|
});
|
|
66
66
|
ensureStoreShape(store, modulePath);
|
|
67
|
-
logger?.info?.(`[telemetry.
|
|
67
|
+
logger?.info?.(`[telemetry.health.snapshot] using contract gate snapshot store "${store.name || modulePath}"`);
|
|
68
68
|
return store;
|
|
69
69
|
};
|
|
70
70
|
export { isRecord, normalizeSnapshot, resolveContractGateSnapshotStore };
|