@bleedingdev/modern-js-server-runtime-extensions 3.8.3-ultramodern.6 → 3.9.0-ultramodern.10
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 +5 -5
- package/dist/cjs/bff-policy/crossProjectPolicy.js +299 -0
- package/dist/cjs/bff-policy/index.js +62 -0
- package/dist/cjs/bff-policy/node.js +69 -0
- package/dist/cjs/bff-policy/operationContracts.js +182 -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/localisedLoaderPlugin.js +62 -0
- package/dist/cjs/mfCache.js +6 -0
- package/dist/cjs/module-federation-css/plugin.js +6 -0
- 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/bff-policy/crossProjectPolicy.mjs +249 -0
- package/dist/esm/bff-policy/index.mjs +1 -0
- package/dist/esm/contract-gate-snapshot-store/http-store.mjs +1 -8
- package/dist/esm/errorResponsePlugin.mjs +19 -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/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/bff-policy/crossProjectPolicy.mjs +250 -0
- package/dist/esm-node/bff-policy/index.mjs +2 -0
- package/dist/esm-node/bff-policy/node.mjs +3 -0
- package/dist/esm-node/bff-policy/operationContracts.mjs +129 -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/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/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 +1 -0
- package/dist/types/bff-policy/node.d.ts +2 -0
- package/dist/types/bff-policy/operationContracts.d.ts +85 -0
- package/dist/types/bff-policy/resolveCrossProjectPolicy.d.ts +39 -0
- package/dist/types/contract-gate-snapshot-normalization.d.ts +1 -1
- package/dist/types/contract-gate-snapshot-store/file-store.d.ts +1 -1
- package/dist/types/contract-gate-snapshot-store/http-store.d.ts +1 -1
- package/dist/types/contract-gate-snapshot-store/index.d.ts +5 -5
- package/dist/types/contract-gate-snapshot-store/resolve.d.ts +1 -1
- package/dist/types/contractGateSnapshotObserver.d.ts +2 -2
- package/dist/types/errorResponsePlugin.d.ts +3 -0
- package/dist/types/index.d.ts +8 -7
- package/dist/types/localisedLoaderPlugin.d.ts +2 -0
- package/dist/types/mfCache.d.ts +2 -3
- package/dist/types/module-federation-css/collector.d.ts +1 -1
- package/dist/types/module-federation-css/index.d.ts +8 -8
- package/dist/types/module-federation-css/plugin.d.ts +2 -3
- package/dist/types/runtime-fallback-signal/index.d.ts +4 -4
- package/dist/types/runtime-fallback-signal/model.d.ts +1 -1
- package/dist/types/runtime-fallback-signal/resolver.d.ts +1 -1
- package/dist/types/runtime-fallback-signal/store.d.ts +1 -1
- package/dist/types/runtimeFallbackSignal.d.ts +1 -1
- 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 +2 -2
- package/dist/types/telemetry/healthEvaluation.d.ts +2 -2
- package/dist/types/telemetry/healthMonitor.d.ts +2 -2
- package/dist/types/telemetry/healthSetup.d.ts +6 -6
- package/dist/types/telemetry/lifecycle.d.ts +6 -6
- package/dist/types/telemetry/metrics.d.ts +1 -1
- package/dist/types/telemetry/plugin.d.ts +5 -4
- package/dist/types/telemetry/registry.d.ts +2 -2
- package/dist/types/telemetry/runtimeEndpoints.d.ts +2 -2
- package/dist/types/telemetry.d.ts +1 -1
- package/dist/types/telemetryCore.d.ts +6 -6
- 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 +1 -0
- package/dist/types-esm/bff-policy/node.d.mts +2 -0
- package/dist/types-esm/bff-policy/operationContracts.d.mts +85 -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/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 +20 -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 +160 -28
- package/rslib.config.mts +36 -2
- package/rstest.config.mts +11 -0
- package/src/bff-policy/crossProjectPolicy.ts +754 -0
- package/src/bff-policy/index.ts +1 -0
- package/src/bff-policy/node.ts +2 -0
- package/src/bff-policy/operationContracts.ts +298 -0
- package/src/bff-policy/resolveCrossProjectPolicy.ts +88 -0
- package/src/contract-gate-snapshot-store/http-store.ts +1 -11
- package/src/errorResponsePlugin.ts +21 -0
- package/src/index.ts +4 -0
- package/src/localisedLoaderPlugin.ts +34 -0
- package/src/mfCache.ts +4 -3
- package/src/module-federation-css/plugin.ts +4 -3
- 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/bff-policy/crossProjectPolicy.matrix.test.ts +450 -0
- package/tests/bff-policy/crossProjectPolicy.test.ts +197 -0
- package/tests/bff-policy/operationContracts.test.ts +221 -0
- package/tests/bff-policy/optionalZodPeer.test.ts +30 -0
- package/tests/bff-policy/resolveCrossProjectPolicy.test.ts +76 -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 +120 -0
- package/tests/mfCache.test.ts +1 -88
- package/tests/moduleFederationCss.test.ts +4 -48
- 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,8 +9,8 @@ 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`,
|
|
@@ -26,7 +26,7 @@ identically:
|
|
|
26
26
|
|
|
27
27
|
- `injectTelemetryPlugin()` — no-op unless `server.telemetry` is configured.
|
|
28
28
|
The runtime-fallback-signal endpoint is opt-in
|
|
29
|
-
(`
|
|
29
|
+
(`health.snapshotObservation.runtimeFallbackSignal.enabled: true`) and requires an
|
|
30
30
|
auth token (`auth.expectedValue` / `auth.expectedValueEnv`); the
|
|
31
31
|
`/_modern/runtime/status` endpoint returns a bare health probe unless the
|
|
32
32
|
caller authenticates with that token.
|
|
@@ -50,7 +50,7 @@ single typed pass by `parseServerRuntimeExtensionsEnv()` in `src/env.ts`:
|
|
|
50
50
|
| --- | --- | --- |
|
|
51
51
|
| `MODERN_ENV` | _unset_ | Deployment environment name (also drives `.env.{MODERN_ENV}` loading in the server bootstrap). First candidate for the telemetry `environment` label. |
|
|
52
52
|
| `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
|
|
53
|
+
| `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
54
|
|
|
55
55
|
Exporter endpoints and the module federation remote manifest timeout are
|
|
56
56
|
configured through `server.telemetry.exporters.*.endpoint` and plugin options
|
|
@@ -62,6 +62,6 @@ read only at config time by `@modern-js/app-tools` (`baseline.ts`), not at
|
|
|
62
62
|
server runtime.
|
|
63
63
|
|
|
64
64
|
One dynamic indirection cannot be statically parsed:
|
|
65
|
-
`server.telemetry.
|
|
65
|
+
`server.telemetry.health.snapshotObservation.runtimeFallbackSignal.auth.expectedValueEnv`
|
|
66
66
|
names an arbitrary environment variable that holds the expected runtime-signal
|
|
67
67
|
auth token; it is read when the auth config is normalized.
|
|
@@ -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
|
+
});
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __webpack_modules__ = {
|
|
3
|
+
"./crossProjectPolicy" (module) {
|
|
4
|
+
module.exports = require("./crossProjectPolicy.js");
|
|
5
|
+
}
|
|
6
|
+
};
|
|
7
|
+
var __webpack_module_cache__ = {};
|
|
8
|
+
function __webpack_require__(moduleId) {
|
|
9
|
+
var cachedModule = __webpack_module_cache__[moduleId];
|
|
10
|
+
if (void 0 !== cachedModule) return cachedModule.exports;
|
|
11
|
+
var module = __webpack_module_cache__[moduleId] = {
|
|
12
|
+
exports: {}
|
|
13
|
+
};
|
|
14
|
+
__webpack_modules__[moduleId](module, module.exports, __webpack_require__);
|
|
15
|
+
return module.exports;
|
|
16
|
+
}
|
|
17
|
+
(()=>{
|
|
18
|
+
__webpack_require__.n = (module)=>{
|
|
19
|
+
var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
|
|
20
|
+
__webpack_require__.d(getter, {
|
|
21
|
+
a: getter
|
|
22
|
+
});
|
|
23
|
+
return getter;
|
|
24
|
+
};
|
|
25
|
+
})();
|
|
26
|
+
(()=>{
|
|
27
|
+
__webpack_require__.d = (exports1, getters, values)=>{
|
|
28
|
+
var define = (defs, kind)=>{
|
|
29
|
+
for(var key in defs)if (__webpack_require__.o(defs, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
30
|
+
enumerable: true,
|
|
31
|
+
[kind]: defs[key]
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
define(getters, "get");
|
|
35
|
+
define(values, "value");
|
|
36
|
+
};
|
|
37
|
+
})();
|
|
38
|
+
(()=>{
|
|
39
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
40
|
+
})();
|
|
41
|
+
(()=>{
|
|
42
|
+
__webpack_require__.r = (exports1)=>{
|
|
43
|
+
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
44
|
+
value: 'Module'
|
|
45
|
+
});
|
|
46
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
47
|
+
value: true
|
|
48
|
+
});
|
|
49
|
+
};
|
|
50
|
+
})();
|
|
51
|
+
var __webpack_exports__ = {};
|
|
52
|
+
(()=>{
|
|
53
|
+
__webpack_require__.r(__webpack_exports__);
|
|
54
|
+
var _crossProjectPolicy__rspack_import_0 = __webpack_require__("./crossProjectPolicy");
|
|
55
|
+
var __rspack_reexport = {};
|
|
56
|
+
for(const __rspack_import_key in _crossProjectPolicy__rspack_import_0)if ("default" !== __rspack_import_key) __rspack_reexport[__rspack_import_key] = ()=>_crossProjectPolicy__rspack_import_0[__rspack_import_key];
|
|
57
|
+
__webpack_require__.d(__webpack_exports__, __rspack_reexport);
|
|
58
|
+
})();
|
|
59
|
+
for(var __rspack_i in __webpack_exports__)exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
60
|
+
Object.defineProperty(exports, '__esModule', {
|
|
61
|
+
value: true
|
|
62
|
+
});
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __webpack_modules__ = {
|
|
3
|
+
"./operationContracts" (module) {
|
|
4
|
+
module.exports = require("./operationContracts.js");
|
|
5
|
+
},
|
|
6
|
+
"./resolveCrossProjectPolicy" (module) {
|
|
7
|
+
module.exports = require("./resolveCrossProjectPolicy.js");
|
|
8
|
+
}
|
|
9
|
+
};
|
|
10
|
+
var __webpack_module_cache__ = {};
|
|
11
|
+
function __webpack_require__(moduleId) {
|
|
12
|
+
var cachedModule = __webpack_module_cache__[moduleId];
|
|
13
|
+
if (void 0 !== cachedModule) return cachedModule.exports;
|
|
14
|
+
var module = __webpack_module_cache__[moduleId] = {
|
|
15
|
+
exports: {}
|
|
16
|
+
};
|
|
17
|
+
__webpack_modules__[moduleId](module, module.exports, __webpack_require__);
|
|
18
|
+
return module.exports;
|
|
19
|
+
}
|
|
20
|
+
(()=>{
|
|
21
|
+
__webpack_require__.n = (module)=>{
|
|
22
|
+
var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
|
|
23
|
+
__webpack_require__.d(getter, {
|
|
24
|
+
a: getter
|
|
25
|
+
});
|
|
26
|
+
return getter;
|
|
27
|
+
};
|
|
28
|
+
})();
|
|
29
|
+
(()=>{
|
|
30
|
+
__webpack_require__.d = (exports1, getters, values)=>{
|
|
31
|
+
var define = (defs, kind)=>{
|
|
32
|
+
for(var key in defs)if (__webpack_require__.o(defs, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
33
|
+
enumerable: true,
|
|
34
|
+
[kind]: defs[key]
|
|
35
|
+
});
|
|
36
|
+
};
|
|
37
|
+
define(getters, "get");
|
|
38
|
+
define(values, "value");
|
|
39
|
+
};
|
|
40
|
+
})();
|
|
41
|
+
(()=>{
|
|
42
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
43
|
+
})();
|
|
44
|
+
(()=>{
|
|
45
|
+
__webpack_require__.r = (exports1)=>{
|
|
46
|
+
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
47
|
+
value: 'Module'
|
|
48
|
+
});
|
|
49
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
50
|
+
value: true
|
|
51
|
+
});
|
|
52
|
+
};
|
|
53
|
+
})();
|
|
54
|
+
var __webpack_exports__ = {};
|
|
55
|
+
(()=>{
|
|
56
|
+
__webpack_require__.r(__webpack_exports__);
|
|
57
|
+
var _operationContracts__rspack_import_0 = __webpack_require__("./operationContracts");
|
|
58
|
+
var __rspack_reexport = {};
|
|
59
|
+
for(const __rspack_import_key in _operationContracts__rspack_import_0)if ("default" !== __rspack_import_key) __rspack_reexport[__rspack_import_key] = ()=>_operationContracts__rspack_import_0[__rspack_import_key];
|
|
60
|
+
__webpack_require__.d(__webpack_exports__, __rspack_reexport);
|
|
61
|
+
var _resolveCrossProjectPolicy__rspack_import_1 = __webpack_require__("./resolveCrossProjectPolicy");
|
|
62
|
+
var __rspack_reexport = {};
|
|
63
|
+
for(const __rspack_import_key in _resolveCrossProjectPolicy__rspack_import_1)if ("default" !== __rspack_import_key) __rspack_reexport[__rspack_import_key] = ()=>_resolveCrossProjectPolicy__rspack_import_1[__rspack_import_key];
|
|
64
|
+
__webpack_require__.d(__webpack_exports__, __rspack_reexport);
|
|
65
|
+
})();
|
|
66
|
+
for(var __rspack_i in __webpack_exports__)exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
67
|
+
Object.defineProperty(exports, '__esModule', {
|
|
68
|
+
value: true
|
|
69
|
+
});
|
|
@@ -0,0 +1,182 @@
|
|
|
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
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
31
|
+
DEFAULT_OPERATION_VERSION: ()=>DEFAULT_OPERATION_VERSION,
|
|
32
|
+
buildOperationContractMap: ()=>buildOperationContractMap,
|
|
33
|
+
createOperationContractHash: ()=>createOperationContractHash,
|
|
34
|
+
createOperationEntries: ()=>createOperationEntries,
|
|
35
|
+
createOperationSchemaHash: ()=>createOperationSchemaHash,
|
|
36
|
+
deriveOperationVersion: ()=>deriveOperationVersion,
|
|
37
|
+
serializeOperationSchemas: ()=>serializeOperationSchemas
|
|
38
|
+
});
|
|
39
|
+
const external_node_module_namespaceObject = require("node:module");
|
|
40
|
+
const external_crypto_namespaceObject = require("crypto");
|
|
41
|
+
require("reflect-metadata");
|
|
42
|
+
const DEFAULT_OPERATION_VERSION = 1;
|
|
43
|
+
const deriveOperationVersion = (packageVersion)=>{
|
|
44
|
+
if ('string' != typeof packageVersion) return DEFAULT_OPERATION_VERSION;
|
|
45
|
+
const match = packageVersion.trim().match(/^v?(\d+)\./);
|
|
46
|
+
if (!match) return DEFAULT_OPERATION_VERSION;
|
|
47
|
+
const major = Number.parseInt(match[1], 10);
|
|
48
|
+
return Number.isInteger(major) && major >= 0 ? major : DEFAULT_OPERATION_VERSION;
|
|
49
|
+
};
|
|
50
|
+
const stableStringify = (value)=>{
|
|
51
|
+
if (Array.isArray(value)) return `[${value.map((item)=>stableStringify(item)).join(',')}]`;
|
|
52
|
+
if (value && 'object' == typeof value) {
|
|
53
|
+
const entries = Object.entries(value).filter(([, entryValue])=>void 0 !== entryValue).sort(([a], [b])=>a.localeCompare(b)).map(([key, entryValue])=>`${JSON.stringify(key)}:${stableStringify(entryValue)}`);
|
|
54
|
+
return `{${entries.join(',')}}`;
|
|
55
|
+
}
|
|
56
|
+
return JSON.stringify(value) ?? 'null';
|
|
57
|
+
};
|
|
58
|
+
const sha256 = (text)=>(0, external_crypto_namespaceObject.createHash)('sha256').update(text).digest('hex');
|
|
59
|
+
let cachedZodToJSONSchema;
|
|
60
|
+
const ZOD_SPECIFIER = "zod";
|
|
61
|
+
const resolveZodToJSONSchema = ()=>{
|
|
62
|
+
if (void 0 !== cachedZodToJSONSchema) return cachedZodToJSONSchema;
|
|
63
|
+
try {
|
|
64
|
+
const load = (0, external_node_module_namespaceObject.createRequire)(__filename);
|
|
65
|
+
const zod = load(ZOD_SPECIFIER);
|
|
66
|
+
const candidate = zod?.toJSONSchema ?? zod?.z?.toJSONSchema;
|
|
67
|
+
cachedZodToJSONSchema = 'function' == typeof candidate ? candidate : null;
|
|
68
|
+
} catch {
|
|
69
|
+
cachedZodToJSONSchema = null;
|
|
70
|
+
}
|
|
71
|
+
return cachedZodToJSONSchema;
|
|
72
|
+
};
|
|
73
|
+
const INPUT_SCHEMA_METADATA_KEYS = [
|
|
74
|
+
'DATA',
|
|
75
|
+
'QUERY',
|
|
76
|
+
'PARAMS',
|
|
77
|
+
'HEADERS',
|
|
78
|
+
'Files'
|
|
79
|
+
];
|
|
80
|
+
const serializeSchema = (schema)=>{
|
|
81
|
+
const toJSONSchema = resolveZodToJSONSchema();
|
|
82
|
+
if (toJSONSchema) try {
|
|
83
|
+
return toJSONSchema(schema, {
|
|
84
|
+
io: 'input',
|
|
85
|
+
unrepresentable: 'any'
|
|
86
|
+
});
|
|
87
|
+
} catch {}
|
|
88
|
+
return {
|
|
89
|
+
__unserializableSchema: true
|
|
90
|
+
};
|
|
91
|
+
};
|
|
92
|
+
const serializeOperationSchemas = (handler)=>{
|
|
93
|
+
if ('function' != typeof handler) return;
|
|
94
|
+
const serialized = {};
|
|
95
|
+
for (const metadataKey of INPUT_SCHEMA_METADATA_KEYS){
|
|
96
|
+
let schema;
|
|
97
|
+
try {
|
|
98
|
+
schema = Reflect.getMetadata(metadataKey, handler);
|
|
99
|
+
} catch {
|
|
100
|
+
schema = void 0;
|
|
101
|
+
}
|
|
102
|
+
if (null != schema) serialized[metadataKey] = serializeSchema(schema);
|
|
103
|
+
}
|
|
104
|
+
return Object.keys(serialized).length > 0 ? serialized : void 0;
|
|
105
|
+
};
|
|
106
|
+
const createOperationContractHash = (operation, requestId)=>sha256(stableStringify({
|
|
107
|
+
httpMethod: String(operation.httpMethod || '').toUpperCase(),
|
|
108
|
+
name: operation.name,
|
|
109
|
+
requestId,
|
|
110
|
+
routePath: operation.routePath,
|
|
111
|
+
...operation.schemas ? {
|
|
112
|
+
schemas: operation.schemas
|
|
113
|
+
} : {}
|
|
114
|
+
}));
|
|
115
|
+
const createOperationEntries = (handlers)=>handlers.map((item)=>({
|
|
116
|
+
name: item.name,
|
|
117
|
+
httpMethod: String(item.httpMethod || '').toUpperCase(),
|
|
118
|
+
routePath: item.routePath
|
|
119
|
+
})).sort((a, b)=>{
|
|
120
|
+
const keyA = `${a.routePath}:${a.httpMethod}:${a.name}`;
|
|
121
|
+
const keyB = `${b.routePath}:${b.httpMethod}:${b.name}`;
|
|
122
|
+
return keyA.localeCompare(keyB);
|
|
123
|
+
});
|
|
124
|
+
const createOperationSchemaHash = (operationEntries, requestId)=>sha256(stableStringify({
|
|
125
|
+
operations: [
|
|
126
|
+
...operationEntries
|
|
127
|
+
].map((item)=>({
|
|
128
|
+
hash: item.schemaHash ?? createOperationContractHash({
|
|
129
|
+
name: item.name,
|
|
130
|
+
httpMethod: item.httpMethod,
|
|
131
|
+
routePath: item.routePath
|
|
132
|
+
}, requestId)
|
|
133
|
+
})).sort((a, b)=>a.hash.localeCompare(b.hash)),
|
|
134
|
+
requestId
|
|
135
|
+
}));
|
|
136
|
+
const buildOperationContractMap = ({ handlers, requestId, operationVersion })=>{
|
|
137
|
+
const normalizedRequestId = 'string' == typeof requestId && requestId.trim().length > 0 ? requestId.trim() : 'default';
|
|
138
|
+
const normalizedOperationVersion = 'number' == typeof operationVersion && Number.isInteger(operationVersion) ? operationVersion : DEFAULT_OPERATION_VERSION;
|
|
139
|
+
const contracts = {};
|
|
140
|
+
handlers.forEach((item)=>{
|
|
141
|
+
const httpMethod = String(item.httpMethod || '').toUpperCase();
|
|
142
|
+
const schemaHash = createOperationContractHash({
|
|
143
|
+
name: item.name,
|
|
144
|
+
httpMethod,
|
|
145
|
+
routePath: item.routePath,
|
|
146
|
+
schemas: serializeOperationSchemas(item.handler)
|
|
147
|
+
}, normalizedRequestId);
|
|
148
|
+
const operationId = `${normalizedRequestId}:${item.name}`;
|
|
149
|
+
const contract = {
|
|
150
|
+
requestId: normalizedRequestId,
|
|
151
|
+
operationVersion: normalizedOperationVersion,
|
|
152
|
+
schemaHash,
|
|
153
|
+
method: httpMethod,
|
|
154
|
+
routePath: item.routePath,
|
|
155
|
+
operationId,
|
|
156
|
+
handlerName: item.name,
|
|
157
|
+
filename: item.filename
|
|
158
|
+
};
|
|
159
|
+
contracts[`${httpMethod}:${item.routePath}`] = contract;
|
|
160
|
+
contracts[`operation:${operationId}`] = contract;
|
|
161
|
+
});
|
|
162
|
+
return contracts;
|
|
163
|
+
};
|
|
164
|
+
exports.DEFAULT_OPERATION_VERSION = __webpack_exports__.DEFAULT_OPERATION_VERSION;
|
|
165
|
+
exports.buildOperationContractMap = __webpack_exports__.buildOperationContractMap;
|
|
166
|
+
exports.createOperationContractHash = __webpack_exports__.createOperationContractHash;
|
|
167
|
+
exports.createOperationEntries = __webpack_exports__.createOperationEntries;
|
|
168
|
+
exports.createOperationSchemaHash = __webpack_exports__.createOperationSchemaHash;
|
|
169
|
+
exports.deriveOperationVersion = __webpack_exports__.deriveOperationVersion;
|
|
170
|
+
exports.serializeOperationSchemas = __webpack_exports__.serializeOperationSchemas;
|
|
171
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
172
|
+
"DEFAULT_OPERATION_VERSION",
|
|
173
|
+
"buildOperationContractMap",
|
|
174
|
+
"createOperationContractHash",
|
|
175
|
+
"createOperationEntries",
|
|
176
|
+
"createOperationSchemaHash",
|
|
177
|
+
"deriveOperationVersion",
|
|
178
|
+
"serializeOperationSchemas"
|
|
179
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
180
|
+
Object.defineProperty(exports, '__esModule', {
|
|
181
|
+
value: true
|
|
182
|
+
});
|