@bleedingdev/modern-js-server-runtime-extensions 3.9.0-ultramodern.2 → 3.9.0-ultramodern.20
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/README.md +8 -6
- package/dist/cjs/backend-federation-security/index.js +73 -152
- package/dist/cjs/bff-policy/crossProjectPolicy.js +299 -0
- package/dist/cjs/bff-policy/index.js +69 -0
- package/dist/cjs/bff-policy/node.js +85 -0
- package/dist/cjs/bff-policy/operationContracts.js +197 -0
- package/dist/cjs/bff-policy/operationIdentity.js +81 -0
- package/dist/cjs/bff-policy/producer.js +79 -0
- package/dist/cjs/bff-policy/resolveCrossProjectPolicy.js +65 -0
- package/dist/cjs/contract-gate-snapshot-store/http-store.js +1 -8
- package/dist/cjs/errorResponsePlugin.js +57 -0
- package/dist/cjs/localisedLoader.js +65 -0
- package/dist/cjs/localisedLoaderPlugin.js +62 -0
- package/dist/cjs/mfCache.js +6 -0
- package/dist/cjs/module-federation-css/plugin.js +6 -0
- package/dist/cjs/module-federation-css/remote.js +2 -1
- package/dist/cjs/serverConfig.js +18 -0
- package/dist/cjs/serverPlugin.js +74 -0
- package/dist/cjs/static-serving/plugin.js +57 -0
- package/dist/cjs/static-serving/responders.js +158 -0
- package/dist/cjs/static-serving/staticModuleFederation.js +173 -0
- package/dist/cjs/static-serving/staticPrecompressed.js +152 -0
- package/dist/cjs/telemetry/exporters.js +4 -4
- package/dist/cjs/telemetry/healthSetup.js +14 -14
- package/dist/cjs/telemetry/lifecycle.js +20 -21
- package/dist/cjs/telemetry/plugin.js +10 -4
- package/dist/cjs/telemetry/runtimeEndpoints.js +3 -2
- package/dist/cjs/telemetryCore.js +5 -5
- package/dist/esm/backend-federation-security/index.mjs +73 -152
- package/dist/esm/bff-policy/crossProjectPolicy.mjs +249 -0
- package/dist/esm/bff-policy/index.mjs +2 -0
- package/dist/esm/bff-policy/operationIdentity.mjs +30 -0
- package/dist/esm/bff-policy/producer.mjs +31 -0
- package/dist/esm/contract-gate-snapshot-store/http-store.mjs +1 -8
- package/dist/esm/errorResponsePlugin.mjs +19 -0
- package/dist/esm/localisedLoader.mjs +24 -0
- package/dist/esm/localisedLoaderPlugin.mjs +24 -0
- package/dist/esm/mfCache.mjs +6 -0
- package/dist/esm/module-federation-css/plugin.mjs +6 -0
- package/dist/esm/module-federation-css/remote.mjs +2 -1
- package/dist/esm/serverConfig.mjs +0 -0
- package/dist/esm/serverPlugin.mjs +34 -0
- package/dist/esm/telemetry/exporters.mjs +2 -2
- package/dist/esm/telemetry/healthSetup.mjs +14 -14
- package/dist/esm/telemetry/lifecycle.mjs +21 -22
- package/dist/esm/telemetry/plugin.mjs +9 -3
- package/dist/esm/telemetry/runtimeEndpoints.mjs +3 -2
- package/dist/esm/telemetryCore.mjs +1 -1
- package/dist/esm-node/backend-federation-security/index.mjs +73 -152
- package/dist/esm-node/bff-policy/crossProjectPolicy.mjs +250 -0
- package/dist/esm-node/bff-policy/index.mjs +3 -0
- package/dist/esm-node/bff-policy/node.mjs +4 -0
- package/dist/esm-node/bff-policy/operationContracts.mjs +107 -0
- package/dist/esm-node/bff-policy/operationIdentity.mjs +31 -0
- package/dist/esm-node/bff-policy/producer.mjs +32 -0
- package/dist/esm-node/bff-policy/resolveCrossProjectPolicy.mjs +28 -0
- package/dist/esm-node/contract-gate-snapshot-store/http-store.mjs +1 -8
- package/dist/esm-node/errorResponsePlugin.mjs +20 -0
- package/dist/esm-node/localisedLoader.mjs +25 -0
- package/dist/esm-node/localisedLoaderPlugin.mjs +25 -0
- package/dist/esm-node/mfCache.mjs +6 -0
- package/dist/esm-node/module-federation-css/plugin.mjs +6 -0
- package/dist/esm-node/module-federation-css/remote.mjs +2 -1
- package/dist/esm-node/serverConfig.mjs +1 -0
- package/dist/esm-node/serverPlugin.mjs +35 -0
- package/dist/esm-node/static-serving/plugin.mjs +18 -0
- package/dist/esm-node/static-serving/responders.mjs +111 -0
- package/dist/esm-node/static-serving/staticModuleFederation.mjs +105 -0
- package/dist/esm-node/static-serving/staticPrecompressed.mjs +112 -0
- package/dist/esm-node/telemetry/exporters.mjs +2 -2
- package/dist/esm-node/telemetry/healthSetup.mjs +14 -14
- package/dist/esm-node/telemetry/lifecycle.mjs +21 -22
- package/dist/esm-node/telemetry/plugin.mjs +9 -3
- package/dist/esm-node/telemetry/runtimeEndpoints.mjs +3 -2
- package/dist/esm-node/telemetryCore.mjs +1 -1
- package/dist/types/backend-federation-security/node.d.ts +1 -1
- package/dist/types/bff-policy/crossProjectPolicy.d.ts +101 -0
- package/dist/types/bff-policy/index.d.ts +2 -0
- package/dist/types/bff-policy/node.d.ts +3 -0
- package/dist/types/bff-policy/operationContracts.d.ts +46 -0
- package/dist/types/bff-policy/operationIdentity.d.ts +34 -0
- package/dist/types/bff-policy/producer.d.ts +10 -0
- package/dist/types/bff-policy/resolveCrossProjectPolicy.d.ts +39 -0
- package/dist/types/errorResponsePlugin.d.ts +3 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/localisedLoader.d.ts +15 -0
- package/dist/types/localisedLoaderPlugin.d.ts +2 -0
- package/dist/types/mfCache.d.ts +2 -3
- package/dist/types/module-federation-css/plugin.d.ts +2 -3
- package/dist/types/module-federation-css/remote.d.ts +2 -0
- package/dist/types/serverConfig.d.ts +17 -0
- package/dist/types/serverPlugin.d.ts +5 -0
- package/dist/types/static-serving/plugin.d.ts +3 -0
- package/dist/types/static-serving/responders.d.ts +2 -0
- package/dist/types/static-serving/staticModuleFederation.d.ts +13 -0
- package/dist/types/static-serving/staticPrecompressed.d.ts +13 -0
- package/dist/types/telemetry/exporters.d.ts +1 -1
- package/dist/types/telemetry/healthSetup.d.ts +3 -3
- package/dist/types/telemetry/lifecycle.d.ts +4 -4
- package/dist/types/telemetry/plugin.d.ts +2 -1
- package/dist/types/telemetryCore.d.ts +1 -1
- package/dist/types-esm/backend-federation-security/index.d.mts +68 -0
- package/dist/types-esm/backend-federation-security/node.d.mts +3 -0
- package/dist/types-esm/bff-policy/crossProjectPolicy.d.mts +101 -0
- package/dist/types-esm/bff-policy/index.d.mts +2 -0
- package/dist/types-esm/bff-policy/node.d.mts +3 -0
- package/dist/types-esm/bff-policy/operationContracts.d.mts +46 -0
- package/dist/types-esm/bff-policy/operationIdentity.d.mts +34 -0
- package/dist/types-esm/bff-policy/producer.d.mts +10 -0
- package/dist/types-esm/bff-policy/resolveCrossProjectPolicy.d.mts +39 -0
- package/dist/types-esm/contract-gate-snapshot-normalization.d.mts +15 -0
- package/dist/types-esm/contract-gate-snapshot-store/file-store.d.mts +3 -0
- package/dist/types-esm/contract-gate-snapshot-store/http-store.d.mts +5 -0
- package/dist/types-esm/contract-gate-snapshot-store/index.d.mts +5 -0
- package/dist/types-esm/contract-gate-snapshot-store/resolve.d.mts +9 -0
- package/dist/types-esm/contract-gate-snapshot-store/types.d.mts +47 -0
- package/dist/types-esm/contractGateSnapshotObserver.d.mts +33 -0
- package/dist/types-esm/env.d.mts +40 -0
- package/dist/types-esm/errorResponsePlugin.d.mts +3 -0
- package/dist/types-esm/index.d.mts +8 -0
- package/dist/types-esm/localisedLoader.d.mts +15 -0
- package/dist/types-esm/localisedLoaderPlugin.d.mts +2 -0
- package/dist/types-esm/mfCache.d.mts +26 -0
- package/dist/types-esm/module-federation-css/collector.d.mts +25 -0
- package/dist/types-esm/module-federation-css/index.d.mts +8 -0
- package/dist/types-esm/module-federation-css/manifest.d.mts +28 -0
- package/dist/types-esm/module-federation-css/plugin.d.mts +22 -0
- package/dist/types-esm/module-federation-css/remote.d.mts +22 -0
- package/dist/types-esm/runtime-fallback-signal/index.d.mts +4 -0
- package/dist/types-esm/runtime-fallback-signal/model.d.mts +70 -0
- package/dist/types-esm/runtime-fallback-signal/resolver.d.mts +29 -0
- package/dist/types-esm/runtime-fallback-signal/store.d.mts +4 -0
- package/dist/types-esm/runtimeFallbackSignal.d.mts +1 -0
- package/dist/types-esm/runtimeLifecycle.d.mts +10 -0
- package/dist/types-esm/serverConfig.d.mts +17 -0
- package/dist/types-esm/serverPlugin.d.mts +5 -0
- package/dist/types-esm/static-serving/plugin.d.mts +3 -0
- package/dist/types-esm/static-serving/responders.d.mts +2 -0
- package/dist/types-esm/static-serving/staticModuleFederation.d.mts +13 -0
- package/dist/types-esm/static-serving/staticPrecompressed.d.mts +13 -0
- package/dist/types-esm/telemetry/envelope.d.mts +55 -0
- package/dist/types-esm/telemetry/exporters.d.mts +12 -0
- package/dist/types-esm/telemetry/healthEvaluation.d.mts +20 -0
- package/dist/types-esm/telemetry/healthMonitor.d.mts +88 -0
- package/dist/types-esm/telemetry/healthSetup.d.mts +17 -0
- package/dist/types-esm/telemetry/lifecycle.d.mts +18 -0
- package/dist/types-esm/telemetry/metrics.d.mts +3 -0
- package/dist/types-esm/telemetry/plugin.d.mts +13 -0
- package/dist/types-esm/telemetry/registry.d.mts +69 -0
- package/dist/types-esm/telemetry/registryTypes.d.mts +50 -0
- package/dist/types-esm/telemetry/runtimeEndpoints.d.mts +35 -0
- package/dist/types-esm/telemetry.d.mts +1 -0
- package/dist/types-esm/telemetryCore.d.mts +6 -0
- package/package.json +183 -29
- package/rslib.config.mts +36 -2
- package/rstest.config.mts +11 -0
- package/src/backend-federation-security/index.ts +151 -318
- package/src/backend-federation-security/node.ts +24 -22
- package/src/bff-policy/crossProjectPolicy.ts +754 -0
- package/src/bff-policy/index.ts +2 -0
- package/src/bff-policy/node.ts +3 -0
- package/src/bff-policy/operationContracts.ts +225 -0
- package/src/bff-policy/operationIdentity.ts +90 -0
- package/src/bff-policy/producer.ts +40 -0
- package/src/bff-policy/resolveCrossProjectPolicy.ts +88 -0
- package/src/contract-gate-snapshot-store/http-store.ts +1 -11
- package/src/contract-gate-snapshot-store/resolve.ts +0 -1
- package/src/errorResponsePlugin.ts +21 -0
- package/src/index.ts +4 -0
- package/src/localisedLoader.ts +50 -0
- package/src/localisedLoaderPlugin.ts +33 -0
- package/src/mfCache.ts +4 -3
- package/src/module-federation-css/plugin.ts +4 -3
- package/src/module-federation-css/remote.ts +3 -1
- package/src/serverConfig.ts +32 -0
- package/src/serverPlugin.ts +38 -0
- package/src/static-serving/plugin.ts +16 -0
- package/src/static-serving/responders.ts +208 -0
- package/src/static-serving/staticModuleFederation.ts +255 -0
- package/src/static-serving/staticPrecompressed.ts +193 -0
- package/src/telemetry/exporters.ts +1 -1
- package/src/telemetry/healthSetup.ts +17 -20
- package/src/telemetry/lifecycle.ts +27 -39
- package/src/telemetry/plugin.ts +6 -4
- package/src/telemetry/runtimeEndpoints.ts +3 -2
- package/src/telemetryCore.ts +1 -1
- package/tests/backendFederationSecurity.test.ts +63 -0
- package/tests/bff-policy/crossProjectPolicy.matrix.test.ts +450 -0
- package/tests/bff-policy/crossProjectPolicy.test.ts +197 -0
- package/tests/bff-policy/operationContracts.test.ts +278 -0
- package/tests/bff-policy/optionalZodPeer.test.ts +30 -0
- package/tests/bff-policy/resolveCrossProjectPolicy.test.ts +76 -0
- package/tests/bff-policy/zodEvaluatorProbe.test.ts +49 -0
- package/tests/contractGateSnapshotObserver.test.ts +0 -58
- package/tests/contractGateSnapshotStore.test.ts +0 -51
- package/tests/env.test.ts +45 -64
- package/tests/localisedLoader.test.ts +155 -0
- package/tests/mfCache.test.ts +1 -88
- package/tests/moduleFederationCss.test.ts +98 -41
- package/tests/nativeErrorResponse.test.ts +118 -0
- package/tests/nativeServerAssembly.test.ts +385 -0
- package/tests/runtimeLifecycle.test.ts +69 -17
- package/tests/static-serving/ordering.test.ts +214 -0
- package/tests/static-serving/static.test.ts +411 -0
- package/tests/telemetry.test.ts +35 -198
- package/tests/telemetryHealthMonitor.test.ts +0 -4
- package/tests/telemetryHealthObservation.test.ts +302 -0
- package/tests/telemetryLifecycle.test.ts +7 -303
- package/tests/telemetryRegistryQueueMatrix.test.ts +14 -111
- package/tests/registration.test.ts +0 -112
- package/tests/telemetryAutopilot.test.ts +0 -1134
package/README.md
CHANGED
|
@@ -9,12 +9,14 @@ stays small:
|
|
|
9
9
|
exporters, SLO alerts, telemetry-aware metrics wrapping and the
|
|
10
10
|
`injectTelemetryPlugin()` server plugin (runtime status + runtime fallback
|
|
11
11
|
signal endpoints).
|
|
12
|
-
- **Contract-gate
|
|
13
|
-
`
|
|
12
|
+
- **Contract-gate health observation** — `TelemetryHealthMonitor`,
|
|
13
|
+
`ContractGateSnapshotObserver` and the file/HTTP contract-gate snapshot stores.
|
|
14
14
|
- **Module federation runtime helpers** — remote CSS collection for SSR
|
|
15
15
|
(`collectDirectRemoteModuleFederationCss`, `injectModuleFederationCssPlugin()`)
|
|
16
16
|
and MF asset cache-header policies (`resolveMfAssetCacheHeaders`,
|
|
17
|
-
`injectMfAssetCacheHeadersPlugin()`).
|
|
17
|
+
`injectMfAssetCacheHeadersPlugin()`). Remote entries configure the canonical
|
|
18
|
+
final manifest URL: the native fetch rejects redirects (`redirect: 'error'`),
|
|
19
|
+
and a trusted injected `fetcher` must honor that same option.
|
|
18
20
|
|
|
19
21
|
## Registration
|
|
20
22
|
|
|
@@ -26,7 +28,7 @@ identically:
|
|
|
26
28
|
|
|
27
29
|
- `injectTelemetryPlugin()` — no-op unless `server.telemetry` is configured.
|
|
28
30
|
The runtime-fallback-signal endpoint is opt-in
|
|
29
|
-
(`
|
|
31
|
+
(`health.snapshotObservation.runtimeFallbackSignal.enabled: true`) and requires an
|
|
30
32
|
auth token (`auth.expectedValue` / `auth.expectedValueEnv`); the
|
|
31
33
|
`/_modern/runtime/status` endpoint returns a bare health probe unless the
|
|
32
34
|
caller authenticates with that token.
|
|
@@ -50,7 +52,7 @@ single typed pass by `parseServerRuntimeExtensionsEnv()` in `src/env.ts`:
|
|
|
50
52
|
| --- | --- | --- |
|
|
51
53
|
| `MODERN_ENV` | _unset_ | Deployment environment name (also drives `.env.{MODERN_ENV}` loading in the server bootstrap). First candidate for the telemetry `environment` label. |
|
|
52
54
|
| `NODE_ENV` | _unset_ | Standard Node.js environment name. Second candidate for the telemetry `environment` label; the final fallback is `development`. |
|
|
53
|
-
| `MODERN_CONTRACT_GATES_FILE` | `.modern/contract-gates.json` (resolved against the app directory) | Path of the contract-gate snapshot file used by the
|
|
55
|
+
| `MODERN_CONTRACT_GATES_FILE` | `.modern/contract-gates.json` (resolved against the app directory) | Path of the contract-gate snapshot file used by the health observer and the runtime fallback signal endpoint when `server.telemetry.health.snapshotObservation.gateSnapshotPath` is not configured. |
|
|
54
56
|
|
|
55
57
|
Exporter endpoints and the module federation remote manifest timeout are
|
|
56
58
|
configured through `server.telemetry.exporters.*.endpoint` and plugin options
|
|
@@ -62,6 +64,6 @@ read only at config time by `@modern-js/app-tools` (`baseline.ts`), not at
|
|
|
62
64
|
server runtime.
|
|
63
65
|
|
|
64
66
|
One dynamic indirection cannot be statically parsed:
|
|
65
|
-
`server.telemetry.
|
|
67
|
+
`server.telemetry.health.snapshotObservation.runtimeFallbackSignal.auth.expectedValueEnv`
|
|
66
68
|
names an arbitrary environment variable that holds the expected runtime-signal
|
|
67
69
|
auth token; it is read when the auth config is normalized.
|
|
@@ -171,97 +171,85 @@ const sha256Hex = async (bytes, signal)=>{
|
|
|
171
171
|
const digest = new Uint8Array(await readWithAbort(subtle.digest('SHA-256', bytes), signal));
|
|
172
172
|
return Array.from(digest, (byte)=>byte.toString(16).padStart(2, '0')).join('');
|
|
173
173
|
};
|
|
174
|
-
async function
|
|
175
|
-
const
|
|
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.');
|
|
174
|
+
async function acquireBackendFederationResource(requestedUrl, options, policy) {
|
|
175
|
+
const { label, maxBytes, exactByteLength } = policy;
|
|
179
176
|
const timeoutMs = options.timeoutMs ?? DEFAULT_ENTRY_TIMEOUT_MS;
|
|
180
|
-
if (!Number.isSafeInteger(timeoutMs) || timeoutMs < 0) throw new BackendFederationRemoteEntryError('invalid_verification', '[Module Federation]
|
|
177
|
+
if (!Number.isSafeInteger(maxBytes) || maxBytes <= 0 || !Number.isSafeInteger(timeoutMs) || timeoutMs < 0) throw new BackendFederationRemoteEntryError('invalid_verification', '[Module Federation] Resource maxBytes must be a positive safe integer and timeoutMs a non-negative safe integer.');
|
|
178
|
+
if (void 0 !== exactByteLength && exactByteLength > maxBytes) throw new BackendFederationRemoteEntryError('entry_too_large', `[Module Federation] ${label} exceeds the ${maxBytes}-byte policy limit.`);
|
|
181
179
|
const controller = new AbortController();
|
|
182
180
|
let timedOut = false;
|
|
183
|
-
|
|
184
|
-
const onCallerAbort = ()=>{
|
|
185
|
-
callerAborted = true;
|
|
186
|
-
controller.abort(options.signal?.reason);
|
|
187
|
-
};
|
|
181
|
+
const onCallerAbort = ()=>controller.abort(options.signal?.reason);
|
|
188
182
|
if (options.signal?.aborted) onCallerAbort();
|
|
189
183
|
else options.signal?.addEventListener('abort', onCallerAbort, {
|
|
190
184
|
once: true
|
|
191
185
|
});
|
|
192
186
|
const timeout = timeoutMs > 0 ? setTimeout(()=>{
|
|
193
187
|
timedOut = true;
|
|
194
|
-
controller.abort(new Error(
|
|
188
|
+
controller.abort(new Error(`${label} timed out after ${timeoutMs}ms`));
|
|
195
189
|
}, timeoutMs) : void 0;
|
|
196
|
-
const fetchResource = options.fetch ?? globalThis.fetch;
|
|
197
190
|
let reader;
|
|
198
|
-
|
|
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
|
-
});
|
|
191
|
+
let response;
|
|
202
192
|
try {
|
|
203
|
-
|
|
204
|
-
if (
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
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
|
-
}
|
|
193
|
+
const fetchResource = options.fetch ?? globalThis.fetch;
|
|
194
|
+
if (controller.signal.aborted) throw controller.signal.reason;
|
|
195
|
+
if ('function' != typeof fetchResource) throw new Error('Loading requires fetch.');
|
|
196
|
+
response = await readWithAbort(fetchResource(requestedUrl.href, {
|
|
197
|
+
cache: 'no-store',
|
|
198
|
+
redirect: 'error',
|
|
199
|
+
signal: controller.signal
|
|
200
|
+
}), controller.signal);
|
|
201
|
+
if (!response.ok) throw new BackendFederationRemoteEntryError('fetch_failed', `[Module Federation] ${label} returned HTTP ${response.status}.`);
|
|
202
|
+
if (response.url && canonicalEntryUrl(response.url).href !== requestedUrl.href) throw new BackendFederationRemoteEntryError('redirect_mismatch', `[Module Federation] ${label} redirected outside its trusted URL.`, {
|
|
203
|
+
details: {
|
|
204
|
+
expected: redactBackendFederationUrl(requestedUrl.href),
|
|
205
|
+
received: redactBackendFederationUrl(response.url)
|
|
206
|
+
}
|
|
207
|
+
});
|
|
228
208
|
const contentLength = parseContentLength(response.headers?.get('content-length') ?? null);
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
throw new BackendFederationRemoteEntryError('entry_too_large', `[Module Federation] Backend federation ${resourceKind} declares ${contentLength} bytes, exceeding its ${maxBytes}-byte policy limit.`);
|
|
233
|
-
}
|
|
209
|
+
const byteLimit = exactByteLength ?? maxBytes;
|
|
210
|
+
if (void 0 !== contentLength && contentLength > maxBytes) throw new BackendFederationRemoteEntryError('entry_too_large', `[Module Federation] ${label} declares ${contentLength} bytes, exceeding its ${maxBytes}-byte policy limit.`);
|
|
211
|
+
const exactBytes = void 0 === exactByteLength ? void 0 : new Uint8Array(exactByteLength);
|
|
234
212
|
const chunks = [];
|
|
235
213
|
let byteLength = 0;
|
|
214
|
+
const append = (chunk)=>{
|
|
215
|
+
if (byteLength + chunk.byteLength > byteLimit) throw new BackendFederationRemoteEntryError('entry_too_large', `[Module Federation] ${label} exceeded its ${byteLimit}-byte limit while streaming.`);
|
|
216
|
+
if (exactBytes) exactBytes.set(chunk, byteLength);
|
|
217
|
+
else chunks.push(chunk);
|
|
218
|
+
byteLength += chunk.byteLength;
|
|
219
|
+
};
|
|
236
220
|
if (response.body) {
|
|
237
221
|
reader = response.body.getReader();
|
|
238
222
|
while(true){
|
|
239
223
|
const result = await readWithAbort(reader.read(), controller.signal);
|
|
240
224
|
if (result.done) break;
|
|
241
|
-
|
|
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);
|
|
225
|
+
append(result.value);
|
|
244
226
|
}
|
|
245
|
-
} else if (response.text)
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
227
|
+
} else if (void 0 === exactByteLength && response.text) append(new TextEncoder().encode(await readWithAbort(response.text(), controller.signal)));
|
|
228
|
+
if (void 0 !== exactByteLength && byteLength !== exactByteLength) throw new BackendFederationRemoteEntryError('byte_length_mismatch', `[Module Federation] ${label} byte length mismatch.`, {
|
|
229
|
+
details: {
|
|
230
|
+
expected: exactByteLength,
|
|
231
|
+
received: byteLength
|
|
232
|
+
}
|
|
233
|
+
});
|
|
234
|
+
const bytes = exactBytes ?? new Uint8Array(byteLength);
|
|
252
235
|
let offset = 0;
|
|
253
236
|
for (const chunk of chunks){
|
|
254
237
|
bytes.set(chunk, offset);
|
|
255
238
|
offset += chunk.byteLength;
|
|
256
239
|
}
|
|
257
|
-
if (controller.signal.aborted) throw
|
|
240
|
+
if (controller.signal.aborted) throw controller.signal.reason;
|
|
241
|
+
if (policy.verify) await readWithAbort(policy.verify(bytes, controller.signal), controller.signal);
|
|
258
242
|
return bytes;
|
|
259
243
|
} catch (cause) {
|
|
260
|
-
|
|
261
|
-
|
|
244
|
+
const cancelled = controller.signal.aborted;
|
|
245
|
+
controller.abort(cause);
|
|
246
|
+
if (reader) reader.cancel(cause).catch(()=>void 0);
|
|
247
|
+
else if (response?.body) response.body.cancel(cause).catch(()=>void 0);
|
|
248
|
+
if (cancelled) throw new BackendFederationRemoteEntryError(timedOut ? 'timeout' : 'aborted', timedOut ? `[Module Federation] ${label} timed out after ${timeoutMs}ms.` : `[Module Federation] ${label} loading was aborted.`, {
|
|
249
|
+
cause
|
|
250
|
+
});
|
|
262
251
|
if (cause instanceof BackendFederationRemoteEntryError) throw cause;
|
|
263
|
-
|
|
264
|
-
throw new BackendFederationRemoteEntryError('fetch_failed', `[Module Federation] Backend federation ${resourceKind} loading failed.`, {
|
|
252
|
+
throw new BackendFederationRemoteEntryError('fetch_failed', `[Module Federation] ${label} loading failed.`, {
|
|
265
253
|
cause
|
|
266
254
|
});
|
|
267
255
|
} finally{
|
|
@@ -269,6 +257,14 @@ async function loadBoundedBackendFederationResource(resourceUrl, options = {}) {
|
|
|
269
257
|
options.signal?.removeEventListener('abort', onCallerAbort);
|
|
270
258
|
}
|
|
271
259
|
}
|
|
260
|
+
async function loadBoundedBackendFederationResource(resourceUrl, options = {}) {
|
|
261
|
+
const requestedUrl = canonicalEntryUrl(resourceUrl);
|
|
262
|
+
assertAllowedEntryUrl(requestedUrl, true === options.allowInsecureHttp);
|
|
263
|
+
return acquireBackendFederationResource(requestedUrl, options, {
|
|
264
|
+
label: `Backend federation ${options.kind ?? 'manifest'}`,
|
|
265
|
+
maxBytes: options.maxBytes ?? DEFAULT_MAX_RESOURCE_BYTES
|
|
266
|
+
});
|
|
267
|
+
}
|
|
272
268
|
const evaluateBackendFederationCommonJsEntry = (remote, bytes, evaluator)=>{
|
|
273
269
|
let source;
|
|
274
270
|
try {
|
|
@@ -292,100 +288,25 @@ const evaluateBackendFederationCommonJsEntry = (remote, bytes, evaluator)=>{
|
|
|
292
288
|
async function loadVerifiedBackendFederationEntry(options) {
|
|
293
289
|
const verification = resolveTrustedVerification(options.verification, options.expected ?? {});
|
|
294
290
|
const requestedUrl = assertVerification(options.remote, verification, options.expected ?? {}, true === options.allowInsecureHttp);
|
|
295
|
-
const
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
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.`, {
|
|
291
|
+
const bytes = await acquireBackendFederationResource(requestedUrl, options, {
|
|
292
|
+
label: `Backend remote ${options.remote.name}`,
|
|
293
|
+
maxBytes: options.maxBytes ?? DEFAULT_MAX_ENTRY_BYTES,
|
|
294
|
+
exactByteLength: verification.byteLength,
|
|
295
|
+
async verify (bytes, signal) {
|
|
296
|
+
const actualDigest = await sha256Hex(bytes, signal);
|
|
297
|
+
if (signal.aborted) throw signal.reason;
|
|
298
|
+
if (actualDigest !== verification.sha256) throw new BackendFederationRemoteEntryError('integrity_mismatch', `[Module Federation] Backend remote ${options.remote.name} SHA-256 mismatch.`, {
|
|
340
299
|
details: {
|
|
341
|
-
expected:
|
|
342
|
-
received:
|
|
300
|
+
expected: verification.sha256,
|
|
301
|
+
received: actualDigest
|
|
343
302
|
}
|
|
344
303
|
});
|
|
345
304
|
}
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
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
|
-
}
|
|
305
|
+
});
|
|
306
|
+
if (options.signal?.aborted) throw new BackendFederationRemoteEntryError('aborted', `[Module Federation] Backend remote ${options.remote.name} loading was aborted.`, {
|
|
307
|
+
cause: options.signal.reason
|
|
308
|
+
});
|
|
309
|
+
return evaluateBackendFederationCommonJsEntry(options.remote, bytes, options.evaluateCommonJs);
|
|
389
310
|
}
|
|
390
311
|
__webpack_require__.d(__webpack_exports__, {
|
|
391
312
|
BackendFederationRemoteEntryError: ()=>BackendFederationRemoteEntryError,
|
|
@@ -0,0 +1,299 @@
|
|
|
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 BFF_ENVELOPE_HEADER = 'x-modernjs-bff-envelope';
|
|
31
|
+
const BFF_OPERATION_CONTEXT_HEADER = 'x-operation-id';
|
|
32
|
+
const BFF_OPERATION_CONTEXT_DETAIL_HEADER = 'x-modernjs-bff-operation-context';
|
|
33
|
+
const DEFAULT_DENY_STATUS = 403;
|
|
34
|
+
const NAMESPACE_ALLOWLIST_REQUIRES_VERIFIER_MESSAGE = 'cross-project namespace allowlist requires verifyProducerIdentity';
|
|
35
|
+
const splitRoutePath = (routePath)=>routePath.split('/').filter(Boolean);
|
|
36
|
+
const isDynamicRouteSegment = (segment)=>segment.startsWith(':') || '*' === segment || segment.startsWith('*') || segment.startsWith('{*');
|
|
37
|
+
const hasTrailingSlash = (routePath)=>routePath.length > 1 && routePath.endsWith('/');
|
|
38
|
+
const hasUnsafePathEncoding = (requestPath)=>{
|
|
39
|
+
let decoded = requestPath;
|
|
40
|
+
for(let depth = 0; depth < 8; depth += 1){
|
|
41
|
+
if (/%(?:2f|5c)/i.test(decoded)) return true;
|
|
42
|
+
try {
|
|
43
|
+
const next = decodeURIComponent(decoded);
|
|
44
|
+
if (next === decoded) return false;
|
|
45
|
+
decoded = next;
|
|
46
|
+
} catch {
|
|
47
|
+
return true;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return decoded.includes('%');
|
|
51
|
+
};
|
|
52
|
+
const routeSegmentsMatch = (templateSegments, requestSegments)=>{
|
|
53
|
+
let templateIndex = 0;
|
|
54
|
+
let requestIndex = 0;
|
|
55
|
+
while(templateIndex < templateSegments.length){
|
|
56
|
+
const segment = templateSegments[templateIndex];
|
|
57
|
+
const wildcard = '*' === segment || segment.startsWith('*') || segment.startsWith('{*');
|
|
58
|
+
const optional = segment.startsWith(':') && segment.endsWith('?');
|
|
59
|
+
if (templateIndex < templateSegments.length - 1 && (wildcard || optional)) return false;
|
|
60
|
+
if (wildcard) return true;
|
|
61
|
+
const requestSegment = requestSegments[requestIndex];
|
|
62
|
+
if (void 0 === requestSegment) return optional && templateIndex === templateSegments.length - 1;
|
|
63
|
+
if (!segment.startsWith(':') && segment !== requestSegment) return false;
|
|
64
|
+
templateIndex += 1;
|
|
65
|
+
requestIndex += 1;
|
|
66
|
+
}
|
|
67
|
+
return requestIndex === requestSegments.length;
|
|
68
|
+
};
|
|
69
|
+
const routeTemplateMatchScore = (routePath, requestPath)=>{
|
|
70
|
+
if (hasTrailingSlash(routePath) !== hasTrailingSlash(requestPath)) return;
|
|
71
|
+
const templateSegments = splitRoutePath(routePath);
|
|
72
|
+
const requestSegments = splitRoutePath(requestPath);
|
|
73
|
+
for(let prefixLength = 0; prefixLength <= templateSegments.length; prefixLength += 1){
|
|
74
|
+
const removedPrefix = templateSegments.slice(0, prefixLength);
|
|
75
|
+
if (removedPrefix.some(isDynamicRouteSegment)) break;
|
|
76
|
+
const mountedTemplate = templateSegments.slice(prefixLength);
|
|
77
|
+
if (!routeSegmentsMatch(mountedTemplate, requestSegments)) continue;
|
|
78
|
+
const literalSegments = mountedTemplate.filter((segment)=>!isDynamicRouteSegment(segment)).length;
|
|
79
|
+
const dynamicSegments = mountedTemplate.length - literalSegments;
|
|
80
|
+
return (0 === prefixLength ? 1000000 : 0) + 10000 * literalSegments - 100 * dynamicSegments - prefixLength;
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
const resolveCrossProjectRequestObservation = (request, policy)=>{
|
|
84
|
+
const requestMethod = String(request.method || '').trim().toUpperCase();
|
|
85
|
+
const routePaths = [
|
|
86
|
+
...new Set(Object.keys(policy.expectedOperationContracts ?? {}).flatMap((key)=>{
|
|
87
|
+
if (key.startsWith('operation:')) return [];
|
|
88
|
+
const separator = key.indexOf(':');
|
|
89
|
+
if (-1 === separator || key.slice(0, separator).trim().toUpperCase() !== requestMethod) return [];
|
|
90
|
+
return [
|
|
91
|
+
key.slice(separator + 1)
|
|
92
|
+
];
|
|
93
|
+
}))
|
|
94
|
+
];
|
|
95
|
+
if (0 === routePaths.length) return;
|
|
96
|
+
if (hasUnsafePathEncoding(request.pathname)) return {
|
|
97
|
+
method: request.method,
|
|
98
|
+
routePath: request.pathname
|
|
99
|
+
};
|
|
100
|
+
const matches = routePaths.flatMap((routePath)=>{
|
|
101
|
+
const score = routeTemplateMatchScore(routePath, request.pathname);
|
|
102
|
+
return void 0 === score ? [] : [
|
|
103
|
+
{
|
|
104
|
+
routePath,
|
|
105
|
+
score
|
|
106
|
+
}
|
|
107
|
+
];
|
|
108
|
+
});
|
|
109
|
+
if (0 === matches.length) return {
|
|
110
|
+
method: request.method,
|
|
111
|
+
routePath: request.pathname
|
|
112
|
+
};
|
|
113
|
+
matches.sort((left, right)=>right.score - left.score);
|
|
114
|
+
return {
|
|
115
|
+
method: request.method,
|
|
116
|
+
routePath: matches[1]?.score === matches[0]?.score ? request.pathname : matches[0].routePath
|
|
117
|
+
};
|
|
118
|
+
};
|
|
119
|
+
const normalizeHeaderName = (headerName, fallback)=>(headerName || fallback).trim().toLowerCase();
|
|
120
|
+
const normalizeStatusCode = (statusCode)=>{
|
|
121
|
+
if ('number' == typeof statusCode && Number.isFinite(statusCode) && statusCode >= 400 && statusCode <= 599) return Math.floor(statusCode);
|
|
122
|
+
return DEFAULT_DENY_STATUS;
|
|
123
|
+
};
|
|
124
|
+
const readHeader = (headers, headerName)=>{
|
|
125
|
+
const lowerHeaderName = headerName.toLowerCase();
|
|
126
|
+
for (const [name, value] of Object.entries(headers || {}))if (name.toLowerCase() === lowerHeaderName) {
|
|
127
|
+
if (Array.isArray(value)) return value.length > 0 ? String(value[0]) : void 0;
|
|
128
|
+
if (null == value) return;
|
|
129
|
+
return String(value);
|
|
130
|
+
}
|
|
131
|
+
};
|
|
132
|
+
const extractNamespace = (requestId)=>requestId.split(/[/:.]/)[0]?.trim().toLowerCase();
|
|
133
|
+
const createViolation = (reason, message, status)=>({
|
|
134
|
+
code: 'BFF_CROSS_PROJECT_POLICY_DENIED',
|
|
135
|
+
reason,
|
|
136
|
+
message,
|
|
137
|
+
status
|
|
138
|
+
});
|
|
139
|
+
const createCrossProjectPolicyEvaluationState = (headers, policy, observedRequest)=>({
|
|
140
|
+
headers,
|
|
141
|
+
policy,
|
|
142
|
+
status: normalizeStatusCode(policy.denyStatus),
|
|
143
|
+
requireEnvelope: policy.requireEnvelope ?? true,
|
|
144
|
+
requireOperationContext: policy.requireOperationContext ?? true,
|
|
145
|
+
requireOperationContextDetails: policy.requireOperationContextDetails ?? true,
|
|
146
|
+
requireOperationSchemaHash: policy.requireOperationSchemaHash ?? true,
|
|
147
|
+
requireOperationVersion: policy.requireOperationVersion ?? true,
|
|
148
|
+
allowUnknownOperations: policy.allowUnknownOperations ?? false,
|
|
149
|
+
verifyProducerIdentity: 'function' == typeof policy.verifyProducerIdentity ? policy.verifyProducerIdentity : void 0,
|
|
150
|
+
allowedNamespaces: (policy.allowedNamespaces || []).map((item)=>item.trim().toLowerCase()).filter(Boolean),
|
|
151
|
+
envelopeHeader: normalizeHeaderName(policy.envelopeHeader, BFF_ENVELOPE_HEADER),
|
|
152
|
+
operationContextHeader: normalizeHeaderName(policy.operationContextHeader, BFF_OPERATION_CONTEXT_HEADER),
|
|
153
|
+
operationContextDetailHeader: normalizeHeaderName(policy.operationContextDetailHeader, BFF_OPERATION_CONTEXT_DETAIL_HEADER),
|
|
154
|
+
requestId: '',
|
|
155
|
+
detailSchemaHash: '',
|
|
156
|
+
detailOperationVersion: void 0,
|
|
157
|
+
observedRequest: observedRequest ? {
|
|
158
|
+
method: String(observedRequest.method || '').trim().toUpperCase(),
|
|
159
|
+
routePath: String(observedRequest.routePath || '').trim()
|
|
160
|
+
} : void 0,
|
|
161
|
+
complete: false
|
|
162
|
+
});
|
|
163
|
+
const checkNamespaceAllowlistVerifier = (state)=>{
|
|
164
|
+
if (state.allowedNamespaces.length > 0 && void 0 === state.verifyProducerIdentity) return createViolation('producer_identity_mismatch', NAMESPACE_ALLOWLIST_REQUIRES_VERIFIER_MESSAGE, state.status);
|
|
165
|
+
};
|
|
166
|
+
const checkEnvelopeHeader = (state)=>{
|
|
167
|
+
const envelopeRaw = readHeader(state.headers, state.envelopeHeader);
|
|
168
|
+
if (!envelopeRaw) {
|
|
169
|
+
if (!state.requireEnvelope) {
|
|
170
|
+
state.complete = true;
|
|
171
|
+
return;
|
|
172
|
+
}
|
|
173
|
+
return createViolation('missing_envelope', `Missing cross-project envelope header "${state.envelopeHeader}"`, state.status);
|
|
174
|
+
}
|
|
175
|
+
let envelope;
|
|
176
|
+
try {
|
|
177
|
+
const parsed = JSON.parse(envelopeRaw);
|
|
178
|
+
if (!parsed || 'object' != typeof parsed) throw new Error('invalid envelope object');
|
|
179
|
+
envelope = parsed;
|
|
180
|
+
} catch (_error) {
|
|
181
|
+
return createViolation('invalid_envelope', `Invalid cross-project envelope header "${state.envelopeHeader}"`, state.status);
|
|
182
|
+
}
|
|
183
|
+
const requestId = String(envelope.requestId || '').trim();
|
|
184
|
+
if (!requestId) return createViolation('missing_request_id', 'Cross-project envelope does not include a valid requestId', state.status);
|
|
185
|
+
state.requestId = requestId;
|
|
186
|
+
state.claimedNamespace = extractNamespace(requestId);
|
|
187
|
+
state.effectiveNamespace = state.claimedNamespace;
|
|
188
|
+
};
|
|
189
|
+
const checkProducerIdentity = (state)=>{
|
|
190
|
+
if (!state.verifyProducerIdentity) return;
|
|
191
|
+
const verifiedNamespaceRaw = state.verifyProducerIdentity(state.headers);
|
|
192
|
+
const verifiedNamespace = 'string' == typeof verifiedNamespaceRaw ? verifiedNamespaceRaw.trim().toLowerCase() : void 0;
|
|
193
|
+
if (!verifiedNamespace) return createViolation('producer_identity_mismatch', 'Producer identity could not be verified for request', state.status);
|
|
194
|
+
if (verifiedNamespace !== state.claimedNamespace) return createViolation('producer_identity_mismatch', `Envelope namespace "${state.claimedNamespace || 'unknown'}" does not match verified producer identity "${verifiedNamespace}"`, state.status);
|
|
195
|
+
state.effectiveNamespace = verifiedNamespace;
|
|
196
|
+
};
|
|
197
|
+
const checkNamespaceAllowlist = (state)=>{
|
|
198
|
+
if (state.allowedNamespaces.length > 0) {
|
|
199
|
+
if (!state.effectiveNamespace || !state.allowedNamespaces.includes(state.effectiveNamespace)) return createViolation('namespace_not_allowed', `Producer namespace "${state.effectiveNamespace || 'unknown'}" not allowed`, state.status);
|
|
200
|
+
}
|
|
201
|
+
};
|
|
202
|
+
const checkOperationContext = (state)=>{
|
|
203
|
+
if (!state.requireOperationContext) {
|
|
204
|
+
state.complete = true;
|
|
205
|
+
return;
|
|
206
|
+
}
|
|
207
|
+
const operationContext = readHeader(state.headers, state.operationContextHeader);
|
|
208
|
+
if (!operationContext) return createViolation('missing_operation_context', `Missing operation context header "${state.operationContextHeader}"`, state.status);
|
|
209
|
+
if (!operationContext.startsWith(`${state.requestId}:`)) return createViolation('operation_context_mismatch', `Operation context header "${state.operationContextHeader}" does not match requestId "${state.requestId}"`, state.status);
|
|
210
|
+
state.operationContext = operationContext;
|
|
211
|
+
};
|
|
212
|
+
const checkOperationContextDetails = (state)=>{
|
|
213
|
+
const operationContextDetailsRaw = readHeader(state.headers, state.operationContextDetailHeader);
|
|
214
|
+
if (!operationContextDetailsRaw) {
|
|
215
|
+
if (state.requireOperationContextDetails) return createViolation('missing_operation_context_details', `Missing operation context details header "${state.operationContextDetailHeader}"`, state.status);
|
|
216
|
+
state.complete = true;
|
|
217
|
+
return;
|
|
218
|
+
}
|
|
219
|
+
let operationContextDetails;
|
|
220
|
+
try {
|
|
221
|
+
const parsed = JSON.parse(operationContextDetailsRaw);
|
|
222
|
+
if (!parsed || 'object' != typeof parsed || Array.isArray(parsed)) throw new Error('invalid operation context details object');
|
|
223
|
+
operationContextDetails = parsed;
|
|
224
|
+
} catch (_error) {
|
|
225
|
+
return createViolation('invalid_operation_context_details', `Invalid operation context details header "${state.operationContextDetailHeader}"`, state.status);
|
|
226
|
+
}
|
|
227
|
+
const detailRequestId = String(operationContextDetails.requestId || '').trim();
|
|
228
|
+
if (detailRequestId && detailRequestId !== state.requestId) return createViolation('operation_context_details_request_id_mismatch', `Operation context details requestId "${detailRequestId}" does not match envelope requestId "${state.requestId}"`, state.status);
|
|
229
|
+
const detailOperationId = String(operationContextDetails.operationId || '').trim();
|
|
230
|
+
if (state.operationContext && detailOperationId && detailOperationId !== state.operationContext) return createViolation('operation_context_mismatch', `Operation context details operationId "${detailOperationId}" does not match operation context "${state.operationContext}"`, state.status);
|
|
231
|
+
state.operationContextDetails = operationContextDetails;
|
|
232
|
+
state.detailSchemaHash = String(operationContextDetails.schemaHash || '').trim();
|
|
233
|
+
if (state.requireOperationSchemaHash && !state.detailSchemaHash) return createViolation('missing_operation_schema_hash', `Operation context details header "${state.operationContextDetailHeader}" must include schemaHash`, state.status);
|
|
234
|
+
state.detailOperationVersion = operationContextDetails.operationVersion;
|
|
235
|
+
if (state.requireOperationVersion && 'number' != typeof state.detailOperationVersion) return createViolation('missing_operation_version', `Operation context details header "${state.operationContextDetailHeader}" must include operationVersion`, state.status);
|
|
236
|
+
};
|
|
237
|
+
const checkOperationContract = (state)=>{
|
|
238
|
+
if (!state.operationContextDetails) return;
|
|
239
|
+
const expectedContracts = state.policy.expectedOperationContracts;
|
|
240
|
+
if (expectedContracts && 'object' == typeof expectedContracts) {
|
|
241
|
+
const method = String(state.operationContextDetails.method || '').toUpperCase();
|
|
242
|
+
const routePath = String(state.operationContextDetails.routePath || '').trim();
|
|
243
|
+
const operationId = String(state.operationContextDetails.operationId || '').trim();
|
|
244
|
+
const observedMethod = state.observedRequest?.method;
|
|
245
|
+
const observedRoutePath = state.observedRequest?.routePath;
|
|
246
|
+
if (observedMethod && observedRoutePath && (method !== observedMethod || routePath !== observedRoutePath)) return createViolation('operation_context_mismatch', `Client operation "${operationId || `${method}:${routePath}`}" does not match observed request "${observedMethod}:${observedRoutePath}"`, state.status);
|
|
247
|
+
const contractMethod = observedMethod || method;
|
|
248
|
+
const contractRoutePath = observedRoutePath || routePath;
|
|
249
|
+
const expectedContract = expectedContracts[`${contractMethod}:${contractRoutePath}`] || (state.observedRequest ? void 0 : expectedContracts[`operation:${operationId}`]);
|
|
250
|
+
if (expectedContract) {
|
|
251
|
+
const assertedOperationId = operationId || state.operationContext || '';
|
|
252
|
+
const canonicalRouteOperationId = `${state.requestId}:${contractMethod}:${contractRoutePath}`;
|
|
253
|
+
if (state.observedRequest && assertedOperationId !== expectedContract.operationId && assertedOperationId !== canonicalRouteOperationId) return createViolation('operation_context_mismatch', `Client operation "${assertedOperationId}" does not identify observed contract "${expectedContract.operationId || canonicalRouteOperationId}"`, state.status);
|
|
254
|
+
if (expectedContract.schemaHash && state.detailSchemaHash && expectedContract.schemaHash !== state.detailSchemaHash) return createViolation('operation_schema_hash_mismatch', `Operation schema hash mismatch for "${operationId || `${method}:${routePath}`}"`, state.status);
|
|
255
|
+
if ('number' == typeof expectedContract.operationVersion && 'number' == typeof state.detailOperationVersion && expectedContract.operationVersion !== state.detailOperationVersion) return createViolation('operation_version_mismatch', `Operation version mismatch for "${operationId || `${method}:${routePath}`}"`, state.status);
|
|
256
|
+
} else if (!state.allowUnknownOperations) return createViolation('unknown_operation_contract', `No expected operation contract found for operation "${operationId || `${method}:${routePath}`}"`, state.status);
|
|
257
|
+
}
|
|
258
|
+
};
|
|
259
|
+
const CROSS_PROJECT_POLICY_CHECKS = [
|
|
260
|
+
checkNamespaceAllowlistVerifier,
|
|
261
|
+
checkEnvelopeHeader,
|
|
262
|
+
checkProducerIdentity,
|
|
263
|
+
checkNamespaceAllowlist,
|
|
264
|
+
checkOperationContext,
|
|
265
|
+
checkOperationContextDetails,
|
|
266
|
+
checkOperationContract
|
|
267
|
+
];
|
|
268
|
+
const evaluateCrossProjectPolicy = (headers, policy, observedRequest)=>{
|
|
269
|
+
if (!policy?.enabled) return null;
|
|
270
|
+
const state = createCrossProjectPolicyEvaluationState(headers, policy, observedRequest);
|
|
271
|
+
for (const check of CROSS_PROJECT_POLICY_CHECKS){
|
|
272
|
+
const violation = check(state);
|
|
273
|
+
if (violation) return violation;
|
|
274
|
+
if (state.complete) break;
|
|
275
|
+
}
|
|
276
|
+
return null;
|
|
277
|
+
};
|
|
278
|
+
__webpack_require__.d(__webpack_exports__, {}, {
|
|
279
|
+
BFF_ENVELOPE_HEADER: BFF_ENVELOPE_HEADER,
|
|
280
|
+
BFF_OPERATION_CONTEXT_DETAIL_HEADER: BFF_OPERATION_CONTEXT_DETAIL_HEADER,
|
|
281
|
+
BFF_OPERATION_CONTEXT_HEADER: BFF_OPERATION_CONTEXT_HEADER,
|
|
282
|
+
evaluateCrossProjectPolicy: evaluateCrossProjectPolicy,
|
|
283
|
+
resolveCrossProjectRequestObservation: resolveCrossProjectRequestObservation
|
|
284
|
+
});
|
|
285
|
+
exports.BFF_ENVELOPE_HEADER = __webpack_exports__.BFF_ENVELOPE_HEADER;
|
|
286
|
+
exports.BFF_OPERATION_CONTEXT_DETAIL_HEADER = __webpack_exports__.BFF_OPERATION_CONTEXT_DETAIL_HEADER;
|
|
287
|
+
exports.BFF_OPERATION_CONTEXT_HEADER = __webpack_exports__.BFF_OPERATION_CONTEXT_HEADER;
|
|
288
|
+
exports.evaluateCrossProjectPolicy = __webpack_exports__.evaluateCrossProjectPolicy;
|
|
289
|
+
exports.resolveCrossProjectRequestObservation = __webpack_exports__.resolveCrossProjectRequestObservation;
|
|
290
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
291
|
+
"BFF_ENVELOPE_HEADER",
|
|
292
|
+
"BFF_OPERATION_CONTEXT_DETAIL_HEADER",
|
|
293
|
+
"BFF_OPERATION_CONTEXT_HEADER",
|
|
294
|
+
"evaluateCrossProjectPolicy",
|
|
295
|
+
"resolveCrossProjectRequestObservation"
|
|
296
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
297
|
+
Object.defineProperty(exports, '__esModule', {
|
|
298
|
+
value: true
|
|
299
|
+
});
|